mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 12:17:46 +08:00
Refactor ControlItemMention to use bindable flow
This commit is contained in:
parent
1f0f6990f0
commit
b01a809d55
@ -129,19 +129,19 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddStep("Add Mention Selected", () =>
|
AddStep("Add Mention Selected", () =>
|
||||||
{
|
{
|
||||||
if (selected.Value != null)
|
if (selected.Value != null)
|
||||||
channelMap[selected.Value].MentionCount++;
|
channelMap[selected.Value].Mentions.Value++;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("Add 98 Mentions Selected", () =>
|
AddStep("Add 98 Mentions Selected", () =>
|
||||||
{
|
{
|
||||||
if (selected.Value != null)
|
if (selected.Value != null)
|
||||||
channelMap[selected.Value].MentionCount += 98;
|
channelMap[selected.Value].Mentions.Value += 98;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("Clear Mentions Selected", () =>
|
AddStep("Clear Mentions Selected", () =>
|
||||||
{
|
{
|
||||||
if (selected.Value != null)
|
if (selected.Value != null)
|
||||||
channelMap[selected.Value].MentionCount = 0;
|
channelMap[selected.Value].Mentions.Value = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,15 +20,8 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
|||||||
public event Action<Channel>? OnRequestSelect;
|
public event Action<Channel>? OnRequestSelect;
|
||||||
public event Action<Channel>? OnRequestLeave;
|
public event Action<Channel>? OnRequestLeave;
|
||||||
|
|
||||||
public int MentionCount
|
[Cached]
|
||||||
{
|
public readonly BindableInt Mentions = new BindableInt();
|
||||||
get => mention?.MentionCount ?? 0;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (mention != null)
|
|
||||||
mention.MentionCount = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasUnread
|
public bool HasUnread
|
||||||
{
|
{
|
||||||
|
@ -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.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
@ -15,23 +16,11 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
|||||||
{
|
{
|
||||||
public class ControlItemMention : CircularContainer
|
public class ControlItemMention : CircularContainer
|
||||||
{
|
{
|
||||||
private int mentionCount;
|
|
||||||
|
|
||||||
public int MentionCount
|
|
||||||
{
|
|
||||||
get => mentionCount;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == mentionCount)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mentionCount = value;
|
|
||||||
updateText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private OsuSpriteText? countText;
|
private OsuSpriteText? countText;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BindableInt mentions { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour osuColour { get; set; } = null!;
|
private OsuColour osuColour { get; set; } = null!;
|
||||||
|
|
||||||
@ -61,18 +50,24 @@ namespace osu.Game.Overlays.Chat.ChannelControl
|
|||||||
Colour = colourProvider.Background5,
|
Colour = colourProvider.Background5,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
updateText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateText()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
countText!.Text = MentionCount > 99 ? "99+" : MentionCount.ToString();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
mentions.BindValueChanged(change =>
|
||||||
|
{
|
||||||
|
int mentionCount = change.NewValue;
|
||||||
|
|
||||||
|
countText!.Text = mentionCount > 99 ? "99+" : mentionCount.ToString();
|
||||||
|
|
||||||
if (mentionCount > 0)
|
if (mentionCount > 0)
|
||||||
Show();
|
Show();
|
||||||
else
|
else
|
||||||
Hide();
|
Hide();
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user