Highlight mentions in chat

This commit is contained in:
Dean Herbert 2024-08-07 01:18:45 +09:00
parent 1aea8e911c
commit a61bf670d8
No known key found for this signature in database
1 changed files with 17 additions and 3 deletions

View File

@ -18,6 +18,7 @@
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osuTK;
@ -104,6 +105,8 @@ public bool AlternatingBackground
}
}
private bool isMention;
/// <summary>
/// The colour used to paint the author's username.
/// </summary>
@ -255,12 +258,21 @@ public void Highlight()
private void styleMessageContent(SpriteText text)
{
text.Shadow = false;
text.Font = text.Font.With(size: FontSize, italics: Message.IsAction);
text.Font = text.Font.With(size: FontSize, italics: Message.IsAction, weight: isMention ? FontWeight.SemiBold : FontWeight.Medium);
bool messageHasColour = Message.IsAction && !string.IsNullOrEmpty(message.Sender.Colour);
text.Colour = messageHasColour ? Color4Extensions.FromHex(message.Sender.Colour) : colourProvider?.Content1 ?? Colour4.White;
Color4 messageColour = colourProvider?.Content1 ?? Colour4.White;
if (isMention)
messageColour = colourProvider?.Highlight1 ?? Color4.Orange;
else if (Message.IsAction && !string.IsNullOrEmpty(message.Sender.Colour))
messageColour = Color4Extensions.FromHex(message.Sender.Colour);
text.Colour = messageColour;
}
[Resolved]
private IAPIProvider api { get; set; } = null!;
private void updateMessageContent()
{
this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint);
@ -280,6 +292,8 @@ private void updateMessageContent()
// remove non-existent channels from the link list
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true);
isMention = MessageNotifier.CheckContainsUsername(message.DisplayContent, api.LocalUser.Value.Username);
drawableContentFlow.Clear();
drawableContentFlow.AddLinks(message.DisplayContent, message.Links);
}