1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00

Add ability to highlight chat lines

This commit is contained in:
Salman Ahmed 2022-03-04 23:21:29 +03:00
parent d9be65ea39
commit 30b38345aa
2 changed files with 54 additions and 11 deletions

View File

@ -42,7 +42,9 @@ namespace osu.Game.Overlays.Chat
protected virtual float TextSize => 20; protected virtual float TextSize => 20;
private Color4 customUsernameColour; private Container lineBackground;
private Color4 usernameColour;
private OsuSpriteText timestamp; private OsuSpriteText timestamp;
@ -78,19 +80,22 @@ namespace osu.Game.Overlays.Chat
} }
} }
private bool senderHasBackground => !string.IsNullOrEmpty(message.Sender.Colour); private bool senderHasColour => !string.IsNullOrEmpty(message.Sender.Colour);
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
customUsernameColour = colours.ChatBlue; usernameColour = senderHasColour
? Color4Extensions.FromHex(message.Sender.Colour)
bool hasBackground = senderHasBackground; : username_colours[message.Sender.Id % username_colours.Length];
Drawable effectedUsername = username = new OsuSpriteText Drawable effectedUsername = username = new OsuSpriteText
{ {
Shadow = false, Shadow = false,
Colour = hasBackground ? customUsernameColour : username_colours[message.Sender.Id % username_colours.Length], Colour = senderHasColour ? colours.ChatBlue : usernameColour,
Truncate = true, Truncate = true,
EllipsisString = "… :", EllipsisString = "… :",
Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true), Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true),
@ -99,7 +104,7 @@ namespace osu.Game.Overlays.Chat
MaxWidth = MessagePadding - TimestampPadding MaxWidth = MessagePadding - TimestampPadding
}; };
if (hasBackground) if (senderHasColour)
{ {
// Background effect // Background effect
effectedUsername = new Container effectedUsername = new Container
@ -126,7 +131,7 @@ namespace osu.Game.Overlays.Chat
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(message.Sender.Colour), Colour = usernameColour,
}, },
new Container new Container
{ {
@ -141,6 +146,14 @@ namespace osu.Game.Overlays.Chat
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
lineBackground = new Container
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.0f),
CornerRadius = 2f,
Masking = true,
Child = new Box { RelativeSizeAxes = Axes.Both }
},
new Container new Container
{ {
Size = new Vector2(MessagePadding, TextSize), Size = new Vector2(MessagePadding, TextSize),
@ -177,7 +190,7 @@ namespace osu.Game.Overlays.Chat
{ {
t.Font = OsuFont.GetFont(italics: true); t.Font = OsuFont.GetFont(italics: true);
if (senderHasBackground) if (senderHasColour)
t.Colour = Color4Extensions.FromHex(message.Sender.Colour); t.Colour = Color4Extensions.FromHex(message.Sender.Colour);
} }
@ -200,13 +213,21 @@ namespace osu.Game.Overlays.Chat
FinishTransforms(true); FinishTransforms(true);
} }
/// <summary>
/// Schedules a message highlight animation.
/// </summary>
/// <remarks>
/// Scheduling is required to ensure the animation doesn't play until the chat line is in view and not scrolled away.
/// </remarks>
public void ScheduleHighlight() => Schedule(() => lineBackground.FlashColour(usernameColour.Darken(1f).Opacity(0.5f), 1000, Easing.InQuint));
private void updateMessageContent() private void updateMessageContent()
{ {
this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint); this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint);
timestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint); timestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint);
timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}"; timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}";
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":"); username.Text = $@"{message.Sender.Username}" + (senderHasColour || message.IsAction ? "" : ":");
// remove non-existent channels from the link list // 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); message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true);

View File

@ -79,6 +79,28 @@ namespace osu.Game.Overlays.Chat
Channel.PendingMessageResolved += pendingMessageResolved; Channel.PendingMessageResolved += pendingMessageResolved;
} }
/// <summary>
/// Highlights a specific message in this drawable channel.
/// </summary>
/// <param name="message">The message to highlight.</param>
public void HighlightMessage(Message message)
{
if (IsLoaded)
highlightMessage(message);
else
Schedule(highlightMessage, message);
}
private void highlightMessage(Message message)
{
var chatLine = chatLines.SingleOrDefault(c => c.Message == message);
if (chatLine == null)
return;
scroll.ScrollIntoView(chatLine);
chatLine.ScheduleHighlight();
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);