mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:43:21 +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", () =>
|
||||
{
|
||||
if (selected.Value != null)
|
||||
channelMap[selected.Value].HasUnread = true;
|
||||
channelMap[selected.Value].Unread.Value = true;
|
||||
});
|
||||
|
||||
AddStep("Read Selected", () =>
|
||||
{
|
||||
if (selected.Value != null)
|
||||
channelMap[selected.Value].HasUnread = false;
|
||||
channelMap[selected.Value].Unread.Value = false;
|
||||
});
|
||||
|
||||
AddStep("Add Mention Selected", () =>
|
||||
|
@ -23,15 +23,8 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
||||
[Cached]
|
||||
public readonly BindableInt Mentions = new BindableInt();
|
||||
|
||||
public bool HasUnread
|
||||
{
|
||||
get => text?.HasUnread ?? false;
|
||||
set
|
||||
{
|
||||
if (text != null)
|
||||
text.HasUnread = value;
|
||||
}
|
||||
}
|
||||
[Cached]
|
||||
public readonly BindableBool Unread = new BindableBool();
|
||||
|
||||
private readonly Channel channel;
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#nullable enable
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
@ -14,25 +15,13 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
||||
{
|
||||
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 OsuSpriteText? text;
|
||||
|
||||
[Resolved]
|
||||
private BindableBool unread { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
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)
|
||||
return;
|
||||
base.LoadComplete();
|
||||
|
||||
if (HasUnread)
|
||||
text!.Colour = colourProvider.Content1;
|
||||
else
|
||||
text!.Colour = colourProvider.Light3;
|
||||
unread.BindValueChanged(change =>
|
||||
{
|
||||
if (change.NewValue)
|
||||
text!.Colour = colourProvider.Content1;
|
||||
else
|
||||
text!.Colour = colourProvider.Light3;
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user