mirror of
https://github.com/osukey/osukey.git
synced 2025-05-14 01:57:22 +09:00
Adds new component `ChannelControlItem` and it's child components to be used as the clickable control in the new chat sidebar for joined channels. Has public properties `HasUnread` and `MentionCount` to control the display of the channel having unread messages or mentions of the user. Channel select/join requests are exposed via `OnRequestSelect` and `OnRequestLeave` events respectively which should be handled by a parent component. Requires a cached `Bindable<Channel>` instance to be managed by a parent component. Requires a cached `OveralayColourScheme` instance to be provided by a parent component.
72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
// 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.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osu.Game.Online.Chat;
|
|
|
|
namespace osu.Game.Overlays.Chat.ChannelControl
|
|
{
|
|
public class ControlItemText : Container
|
|
{
|
|
public bool HasUnread
|
|
{
|
|
get => hasUnread;
|
|
set
|
|
{
|
|
if (hasUnread == value)
|
|
return;
|
|
|
|
hasUnread = value;
|
|
updateText();
|
|
}
|
|
}
|
|
|
|
private bool hasUnread = false;
|
|
private OsuSpriteText? text;
|
|
|
|
[Resolved]
|
|
private OverlayColourProvider? colourProvider { get; set; }
|
|
|
|
private readonly Channel channel;
|
|
|
|
public ControlItemText(Channel channel)
|
|
{
|
|
this.channel = channel;
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
Child = text = new OsuSpriteText
|
|
{
|
|
Anchor = Anchor.CentreLeft,
|
|
Origin = Anchor.CentreLeft,
|
|
Text = channel.Type == ChannelType.Public ? $"# {channel.Name.Substring(1)}" : channel.Name,
|
|
Font = OsuFont.Torus.With(size: 17, weight: FontWeight.SemiBold),
|
|
Colour = colourProvider!.Light3,
|
|
Margin = new MarginPadding { Bottom = 2 },
|
|
RelativeSizeAxes = Axes.X,
|
|
Truncate = true,
|
|
};
|
|
}
|
|
|
|
private void updateText()
|
|
{
|
|
if (!IsLoaded)
|
|
return;
|
|
|
|
if (HasUnread)
|
|
text!.Colour = Colour4.White;
|
|
else
|
|
text!.Colour = colourProvider!.Light3;
|
|
}
|
|
}
|
|
}
|