Instantiate highlight background container on animation

Also removes the necessity of scheduling as it actually never worked as
intended, `Scheduler` will still update even when the chat line is
masked away, and the animation will never be held anyways.

The new duration of the animation should be enough for long scrolls
either way.
This commit is contained in:
Salman Ahmed 2022-03-10 03:47:48 +03:00
parent d4de435eb2
commit b25c37ce62
2 changed files with 22 additions and 17 deletions

View File

@ -42,8 +42,6 @@ public class ChatLine : CompositeDrawable
protected virtual float TextSize => 20;
private Container lineHighlightBackground;
private Color4 usernameColour;
private OsuSpriteText timestamp;
@ -146,15 +144,6 @@ private void load()
InternalChildren = new Drawable[]
{
lineHighlightBackground = new Container
{
Alpha = 0f,
RelativeSizeAxes = Axes.Both,
Colour = usernameColour.Darken(1f),
CornerRadius = 2f,
Masking = true,
Child = new Box { RelativeSizeAxes = Axes.Both }
},
new Container
{
Size = new Vector2(MessagePadding, TextSize),
@ -214,13 +203,29 @@ protected override void LoadComplete()
FinishTransforms(true);
}
private Container highlight;
/// <summary>
/// Schedules a message highlight animation.
/// Performs a highlight animation on this <see cref="ChatLine"/>.
/// </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(() => lineHighlightBackground.FadeTo(0.5f).FadeOut(1500, Easing.InQuint));
public void Highlight()
{
if (highlight?.IsAlive != true)
{
AddInternal(highlight = new Container
{
CornerRadius = 2f,
Masking = true,
RelativeSizeAxes = Axes.Both,
Colour = usernameColour.Darken(1f),
Depth = float.MaxValue,
Child = new Box { RelativeSizeAxes = Axes.Both }
});
}
highlight.FadeTo(0.5f).FadeOut(1500, Easing.InQuint);
highlight.Expire();
}
private void updateMessageContent()
{

View File

@ -102,7 +102,7 @@ protected override void LoadComplete()
{
float center = scroll.GetChildPosInContent(chatLine, chatLine.DrawSize / 2) - scroll.DisplayableContent / 2;
scroll.ScrollTo(Math.Clamp(center, 0, scroll.ScrollableExtent));
chatLine.ScheduleHighlight();
chatLine.Highlight();
}
highlightedMessage.Value = null;