mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 18:52:55 +08:00
Refactor ControlItemText to use bindable flow for unread state
This commit is contained in:
parent
b01a809d55
commit
75958bf270
@ -117,13 +117,13 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddStep("Unread Selected", () =>
|
AddStep("Unread Selected", () =>
|
||||||
{
|
{
|
||||||
if (selected.Value != null)
|
if (selected.Value != null)
|
||||||
channelMap[selected.Value].HasUnread = true;
|
channelMap[selected.Value].Unread.Value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("Read Selected", () =>
|
AddStep("Read Selected", () =>
|
||||||
{
|
{
|
||||||
if (selected.Value != null)
|
if (selected.Value != null)
|
||||||
channelMap[selected.Value].HasUnread = false;
|
channelMap[selected.Value].Unread.Value = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("Add Mention Selected", () =>
|
AddStep("Add Mention Selected", () =>
|
||||||
|
@ -23,15 +23,8 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
|||||||
[Cached]
|
[Cached]
|
||||||
public readonly BindableInt Mentions = new BindableInt();
|
public readonly BindableInt Mentions = new BindableInt();
|
||||||
|
|
||||||
public bool HasUnread
|
[Cached]
|
||||||
{
|
public readonly BindableBool Unread = new BindableBool();
|
||||||
get => text?.HasUnread ?? false;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (text != null)
|
|
||||||
text.HasUnread = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Channel channel;
|
private readonly Channel channel;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -14,25 +15,13 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
|||||||
{
|
{
|
||||||
public class ControlItemText : Container
|
public class ControlItemText : Container
|
||||||
{
|
{
|
||||||
private bool hasUnread;
|
|
||||||
|
|
||||||
public bool HasUnread
|
|
||||||
{
|
|
||||||
get => hasUnread;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (hasUnread == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
hasUnread = value;
|
|
||||||
updateText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Channel channel;
|
private readonly Channel channel;
|
||||||
|
|
||||||
private OsuSpriteText? text;
|
private OsuSpriteText? text;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BindableBool unread { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||||
|
|
||||||
@ -58,15 +47,17 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateText()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
if (!IsLoaded)
|
base.LoadComplete();
|
||||||
return;
|
|
||||||
|
|
||||||
if (HasUnread)
|
unread.BindValueChanged(change =>
|
||||||
text!.Colour = colourProvider.Content1;
|
{
|
||||||
else
|
if (change.NewValue)
|
||||||
text!.Colour = colourProvider.Light3;
|
text!.Colour = colourProvider.Content1;
|
||||||
|
else
|
||||||
|
text!.Colour = colourProvider.Light3;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user