diff --git a/osu.Game.Tournament.Tests/Components/TestSceneTournamentMatchChatDisplay.cs b/osu.Game.Tournament.Tests/Components/TestSceneTournamentMatchChatDisplay.cs index fada340cf7..71d8cbeea7 100644 --- a/osu.Game.Tournament.Tests/Components/TestSceneTournamentMatchChatDisplay.cs +++ b/osu.Game.Tournament.Tests/Components/TestSceneTournamentMatchChatDisplay.cs @@ -90,7 +90,7 @@ namespace osu.Game.Tournament.Tests.Components })); AddUntilStep("message from team red is red color", () => - this.ChildrenOfType().Any(s => s.AccentColour == TournamentGame.COLOUR_RED)); + this.ChildrenOfType().Any(s => s.AccentColour.Value == TournamentGame.COLOUR_RED)); AddStep("message from team red", () => testChannel.AddNewMessages(new Message(nextMessageId()) { @@ -105,7 +105,7 @@ namespace osu.Game.Tournament.Tests.Components })); AddUntilStep("message from team blue is blue color", () => - this.ChildrenOfType().Any(s => s.AccentColour == TournamentGame.COLOUR_BLUE)); + this.ChildrenOfType().Any(s => s.AccentColour.Value == TournamentGame.COLOUR_BLUE)); AddStep("message from admin", () => testChannel.AddNewMessages(new Message(nextMessageId()) { diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index 3e484d962b..2931685239 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -21,6 +21,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; using osuTK.Graphics; +using Message = osu.Game.Online.Chat.Message; namespace osu.Game.Overlays.Chat { @@ -69,9 +70,9 @@ namespace osu.Game.Overlays.Chat private Container? highlight; /// - /// if set, it will override or . + /// if set, it will override or . /// - public Color4? UsernameColour { get; init; } + public Color4 UsernameColour { get; init; } public ChatLine(Message message) { @@ -79,6 +80,11 @@ namespace osu.Game.Overlays.Chat RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + + // If we have custom value, this value will be override. + UsernameColour = !string.IsNullOrEmpty(message.Sender.Colour) + ? Color4Extensions.FromHex(message.Sender.Colour) + : default_colours[message.SenderId % default_colours.Length]; } [BackgroundDependencyLoader] @@ -87,27 +93,18 @@ namespace osu.Game.Overlays.Chat configManager.BindWith(OsuSetting.Prefer24HourTime, prefer24HourTime); prefer24HourTime.BindValueChanged(_ => updateTimestamp()); - if (UsernameColour != null) + drawableUsername = new DrawableChatUsername(message.Sender) { - drawableUsername = new DrawableChatUsername(message.Sender) - { - AccentColour = UsernameColour.Value - }; - } - else - { - drawableUsername = new DrawableChatUsername(message.Sender); - } + Width = UsernameWidth, + FontSize = FontSize, + AutoSizeAxes = Axes.Y, + Origin = Anchor.TopRight, + Anchor = Anchor.TopRight, + Margin = new MarginPadding { Horizontal = Spacing }, + Inverted = !string.IsNullOrEmpty(message.Sender.Colour), + }; - drawableUsername.With(u => - { - u.Width = UsernameWidth; - u.FontSize = FontSize; - u.AutoSizeAxes = Axes.Y; - u.Origin = Anchor.TopRight; - u.Anchor = Anchor.TopRight; - u.Margin = new MarginPadding { Horizontal = Spacing }; - }); + drawableUsername.AccentColour.Value = UsernameColour; InternalChild = new GridContainer { @@ -178,7 +175,7 @@ namespace osu.Game.Overlays.Chat CornerRadius = 2f, Masking = true, RelativeSizeAxes = Axes.Both, - Colour = drawableUsername.AccentColour.Darken(1f), + Colour = drawableUsername.AccentColour.Value.Darken(1f), Depth = float.MaxValue, Child = new Box { RelativeSizeAxes = Axes.Both } }); @@ -216,5 +213,44 @@ namespace osu.Game.Overlays.Chat { drawableTimestamp.Text = message.Timestamp.LocalDateTime.ToLocalisableString(prefer24HourTime.Value ? @"HH:mm:ss" : @"hh:mm:ss tt"); } + + private static readonly Color4[] default_colours = + { + Color4Extensions.FromHex("588c7e"), + Color4Extensions.FromHex("b2a367"), + Color4Extensions.FromHex("c98f65"), + Color4Extensions.FromHex("bc5151"), + Color4Extensions.FromHex("5c8bd6"), + Color4Extensions.FromHex("7f6ab7"), + Color4Extensions.FromHex("a368ad"), + Color4Extensions.FromHex("aa6880"), + + Color4Extensions.FromHex("6fad9b"), + Color4Extensions.FromHex("f2e394"), + Color4Extensions.FromHex("f2ae72"), + Color4Extensions.FromHex("f98f8a"), + Color4Extensions.FromHex("7daef4"), + Color4Extensions.FromHex("a691f2"), + Color4Extensions.FromHex("c894d3"), + Color4Extensions.FromHex("d895b0"), + + Color4Extensions.FromHex("53c4a1"), + Color4Extensions.FromHex("eace5c"), + Color4Extensions.FromHex("ea8c47"), + Color4Extensions.FromHex("fc4f4f"), + Color4Extensions.FromHex("3d94ea"), + Color4Extensions.FromHex("7760ea"), + Color4Extensions.FromHex("af52c6"), + Color4Extensions.FromHex("e25696"), + + Color4Extensions.FromHex("677c66"), + Color4Extensions.FromHex("9b8732"), + Color4Extensions.FromHex("8c5129"), + Color4Extensions.FromHex("8c3030"), + Color4Extensions.FromHex("1f5d91"), + Color4Extensions.FromHex("4335a5"), + Color4Extensions.FromHex("812a96"), + Color4Extensions.FromHex("992861"), + }; } } diff --git a/osu.Game/Overlays/Chat/DrawableChatUsername.cs b/osu.Game/Overlays/Chat/DrawableChatUsername.cs index 9b802a8070..05772051da 100644 --- a/osu.Game/Overlays/Chat/DrawableChatUsername.cs +++ b/osu.Game/Overlays/Chat/DrawableChatUsername.cs @@ -33,7 +33,9 @@ namespace osu.Game.Overlays.Chat { public Action? ReportRequested; - public Color4 AccentColour { get; init; } + public Bindable AccentColour { get; } = new Bindable(); + + public bool Inverted { get; init; } public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => colouredDrawable.ReceivePositionalInputAt(screenSpacePos); @@ -75,7 +77,7 @@ namespace osu.Game.Overlays.Chat private readonly APIUser user; private readonly OsuSpriteText drawableText; - private readonly Drawable colouredDrawable; + private Drawable colouredDrawable = null!; public DrawableChatUsername(APIUser user) { @@ -91,17 +93,17 @@ namespace osu.Game.Overlays.Chat Anchor = Anchor.TopRight, Origin = Anchor.TopRight, }; + } - if (string.IsNullOrWhiteSpace(user.Colour)) + [BackgroundDependencyLoader] + private void load() + { + if (!Inverted) { - AccentColour = default_colours[user.Id % default_colours.Length]; - Add(colouredDrawable = drawableText); } else { - AccentColour = Color4Extensions.FromHex(user.Colour); - Add(new Container { Anchor = Anchor.TopRight, @@ -143,9 +145,12 @@ namespace osu.Game.Overlays.Chat protected override void LoadComplete() { base.LoadComplete(); - drawableText.Colour = colours.ChatBlue; - colouredDrawable.Colour = AccentColour; + + AccentColour.BindValueChanged(c => + { + colouredDrawable.Colour = c.NewValue; + }, true); } public MenuItem[] ContextMenuItems @@ -191,7 +196,7 @@ namespace osu.Game.Overlays.Chat protected override bool OnHover(HoverEvent e) { - colouredDrawable.FadeColour(AccentColour.Lighten(0.6f), 30, Easing.OutQuint); + colouredDrawable.FadeColour(AccentColour.Value.Lighten(0.6f), 30, Easing.OutQuint); return base.OnHover(e); } @@ -200,46 +205,7 @@ namespace osu.Game.Overlays.Chat { base.OnHoverLost(e); - colouredDrawable.FadeColour(AccentColour, 800, Easing.OutQuint); + colouredDrawable.FadeColour(AccentColour.Value, 800, Easing.OutQuint); } - - private static readonly Color4[] default_colours = - { - Color4Extensions.FromHex("588c7e"), - Color4Extensions.FromHex("b2a367"), - Color4Extensions.FromHex("c98f65"), - Color4Extensions.FromHex("bc5151"), - Color4Extensions.FromHex("5c8bd6"), - Color4Extensions.FromHex("7f6ab7"), - Color4Extensions.FromHex("a368ad"), - Color4Extensions.FromHex("aa6880"), - - Color4Extensions.FromHex("6fad9b"), - Color4Extensions.FromHex("f2e394"), - Color4Extensions.FromHex("f2ae72"), - Color4Extensions.FromHex("f98f8a"), - Color4Extensions.FromHex("7daef4"), - Color4Extensions.FromHex("a691f2"), - Color4Extensions.FromHex("c894d3"), - Color4Extensions.FromHex("d895b0"), - - Color4Extensions.FromHex("53c4a1"), - Color4Extensions.FromHex("eace5c"), - Color4Extensions.FromHex("ea8c47"), - Color4Extensions.FromHex("fc4f4f"), - Color4Extensions.FromHex("3d94ea"), - Color4Extensions.FromHex("7760ea"), - Color4Extensions.FromHex("af52c6"), - Color4Extensions.FromHex("e25696"), - - Color4Extensions.FromHex("677c66"), - Color4Extensions.FromHex("9b8732"), - Color4Extensions.FromHex("8c5129"), - Color4Extensions.FromHex("8c3030"), - Color4Extensions.FromHex("1f5d91"), - Color4Extensions.FromHex("4335a5"), - Color4Extensions.FromHex("812a96"), - Color4Extensions.FromHex("992861"), - }; } }