1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 08:07:26 +08:00
osu-lazer/osu.Game/Overlays/Chat/ChannelControl/ControlItemMention.cs

73 lines
2.0 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Overlays.Chat.ChannelControl
{
public class ControlItemMention : CircularContainer
{
private OsuSpriteText? countText;
[Resolved]
private BindableInt mentions { get; set; } = null!;
[Resolved]
private OsuColour osuColour { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
Masking = true;
Size = new Vector2(20, 12);
Alpha = 0f;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = osuColour.Orange1,
},
countText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Torus.With(size: 11, weight: FontWeight.Bold),
Margin = new MarginPadding { Bottom = 1 },
Colour = colourProvider.Background5,
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
mentions.BindValueChanged(change =>
{
int mentionCount = change.NewValue;
countText!.Text = mentionCount > 99 ? "99+" : mentionCount.ToString();
if (mentionCount > 0)
Show();
else
Hide();
}, true);
}
}
}