From 0d9cff487b2cc6f1bb2ffb99bd83c3e3869a6a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 7 Apr 2025 12:47:24 +0200 Subject: [PATCH] Terminate scrolling immediately on unhovering --- osu.Game/Overlays/MarqueeContainer.cs | 40 ++++++++++----------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/osu.Game/Overlays/MarqueeContainer.cs b/osu.Game/Overlays/MarqueeContainer.cs index 8540f5edd9..69ac5f7d06 100644 --- a/osu.Game/Overlays/MarqueeContainer.cs +++ b/osu.Game/Overlays/MarqueeContainer.cs @@ -6,8 +6,6 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Transforms; -using osu.Framework.Threading; using osuTK; namespace osu.Game.Overlays @@ -16,7 +14,7 @@ namespace osu.Game.Overlays { /// /// Whether the marquee should be allowed to scroll the content if it overflows. - /// Note that upon changing the value of this, any existing scrolls will be allowed to complete their current loop if they're mid-scroll. + /// Note that upon changing the value of this, any existing scrolls will be terminated instantly. /// public Bindable AllowScrolling { get; } = new BindableBool(true); @@ -59,24 +57,18 @@ namespace osu.Game.Overlays { base.LoadComplete(); - AllowScrolling.BindValueChanged(_ => ScheduleAfterChildren(() => updateScrolling(instant: false))); + AllowScrolling.BindValueChanged(_ => ScheduleAfterChildren(updateScrolling)); CreateContent.BindValueChanged(_ => { flow.Clear(); flow.Add(mainContent = CreateContent.Value.Invoke()); flow.Add(fillerContent = CreateContent.Value.Invoke().With(d => d.Alpha = 0)); - ScheduleAfterChildren(() => updateScrolling(instant: true)); + ScheduleAfterChildren(updateScrolling); }, true); } - private TransformSequence? scrollSequence; - private ScheduledDelegate? scheduledScrollCancel; - - private void updateScrolling(bool instant) + private void updateScrolling() { - scheduledScrollCancel?.Cancel(); - scheduledScrollCancel = null; - float overflowWidth = mainContent.DrawWidth + padding - DrawWidth; if (overflowWidth > 0 && AllowScrolling.Value) @@ -87,22 +79,18 @@ namespace osu.Game.Overlays float targetX = mainContent.DrawWidth + padding; - scrollSequence ??= flow.MoveToX(0) - .Delay(initial_move_delay) - .MoveToX(-targetX, targetX * 1000 / pixels_per_second) - .Loop(); + flow.MoveToX(0) + .Delay(initial_move_delay) + .MoveToX(-targetX, targetX * 1000 / pixels_per_second) + .Loop(); } - else if (scrollSequence != null) + else { - scheduledScrollCancel = Scheduler.AddDelayed(() => - { - fillerContent.Alpha = 0; - flow.ClearTransforms(); - flow.X = 0; - flow.Anchor = NonOverflowingContentAnchor; - flow.Origin = NonOverflowingContentAnchor; - scrollSequence = null; - }, instant ? 0 : flow.LatestTransformEndTime - Time.Current); + fillerContent.Alpha = 0; + flow.ClearTransforms(); + flow.X = 0; + flow.Anchor = NonOverflowingContentAnchor; + flow.Origin = NonOverflowingContentAnchor; } } }