1
0
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:
Jai Sharma 2022-03-14 21:32:30 +00:00
parent b01a809d55
commit 75958bf270
3 changed files with 17 additions and 33 deletions

View File

@ -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", () =>

View File

@ -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;

View File

@ -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);
}
}
}