1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 07:33:15 +08:00

Improve message highlight handling in DrawableChannel

This commit is contained in:
Salman Ahmed 2022-03-10 23:06:58 +03:00
parent a31611bdec
commit d07e3101ea

View File

@ -87,28 +87,30 @@ namespace osu.Game.Overlays.Chat
base.LoadComplete(); base.LoadComplete();
highlightedMessage = Channel.HighlightedMessage.GetBoundCopy(); highlightedMessage = Channel.HighlightedMessage.GetBoundCopy();
highlightedMessage.BindValueChanged(m => highlightedMessage.BindValueChanged(_ => processMessageHighlighting(), true);
}
/// <summary>
/// Processes any pending message in <see cref="highlightedMessage"/>.
/// </summary>
/// <remarks>
/// <see cref="CompositeDrawable.ScheduleAfterChildren"/> is for ensuring the scroll flow has updated with any new chat lines.
/// </remarks>
private void processMessageHighlighting() => ScheduleAfterChildren(() =>
{ {
if (m.NewValue == null) if (highlightedMessage.Value == null)
return; return;
// schedule highlight to ensure it performs after any pending "newMessagesArrived" calls. var chatLine = chatLines.SingleOrDefault(c => c.Message.Equals(highlightedMessage.Value));
// also schedule after children to ensure the scroll flow is updated with any new chat lines. if (chatLine == null)
ScheduleAfterChildren(() => return;
{
var chatLine = chatLines.SingleOrDefault(c => c.Message.Equals(m.NewValue));
if (chatLine != null)
{
float center = scroll.GetChildPosInContent(chatLine, chatLine.DrawSize / 2) - scroll.DisplayableContent / 2; float center = scroll.GetChildPosInContent(chatLine, chatLine.DrawSize / 2) - scroll.DisplayableContent / 2;
scroll.ScrollTo(Math.Clamp(center, 0, scroll.ScrollableExtent)); scroll.ScrollTo(Math.Clamp(center, 0, scroll.ScrollableExtent));
chatLine.Highlight(); chatLine.Highlight();
}
highlightedMessage.Value = null; highlightedMessage.Value = null;
}); });
}, true);
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
@ -179,6 +181,8 @@ namespace osu.Game.Overlays.Chat
// to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling. // to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling.
if (newMessages.Any(m => m is LocalMessage)) if (newMessages.Any(m => m is LocalMessage))
scroll.ScrollToEnd(); scroll.ScrollToEnd();
processMessageHighlighting();
}); });
private void pendingMessageResolved(Message existing, Message updated) => Schedule(() => private void pendingMessageResolved(Message existing, Message updated) => Schedule(() =>