From ac6c323f93ef73786845e3384675c91a664e1fb0 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 2 Oct 2017 00:44:57 +0300 Subject: [PATCH] Clear all tasks and transforms when resetting Breaks --- .../Play/BreaksOverlay/BreakOverlay.cs | 36 +++++++++++++++---- osu.Game/Tests/Visual/TestCaseBreakOverlay.cs | 4 --- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Play/BreaksOverlay/BreakOverlay.cs b/osu.Game/Screens/Play/BreaksOverlay/BreakOverlay.cs index 90321df9d6..fe4d5ea424 100644 --- a/osu.Game/Screens/Play/BreaksOverlay/BreakOverlay.cs +++ b/osu.Game/Screens/Play/BreaksOverlay/BreakOverlay.cs @@ -5,9 +5,11 @@ using OpenTK; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Threading; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Scoring; using System.Collections.Generic; +using System.Linq; namespace osu.Game.Screens.Play.BreaksOverlay { @@ -17,7 +19,21 @@ namespace osu.Game.Screens.Play.BreaksOverlay private const float remaining_time_container_max_size = 0.3f; private const int vertical_margin = 25; - public List Breaks; + private List breaks; + public List Breaks + { + set + { + breaks = value; + initializeBreaks(); + } + get + { + return breaks; + } + } + + private readonly List tasks = new List(); private readonly bool letterboxing; private readonly LetterboxOverlay letterboxOverlay; @@ -71,15 +87,21 @@ namespace osu.Game.Screens.Play.BreaksOverlay protected override void LoadComplete() { base.LoadComplete(); - InitializeBreaks(); + initializeBreaks(); } - public void InitializeBreaks() + private void initializeBreaks() { - if (Breaks == null) + FinishTransforms(true); + + foreach (var t in tasks) + t.Cancel(); + tasks.Clear(); + + if (breaks == null) return; - foreach (var b in Breaks) + foreach (var b in breaks) { if (!b.HasEffect) continue; @@ -104,7 +126,9 @@ namespace osu.Game.Screens.Play.BreaksOverlay .Then() .ResizeWidthTo(0, b.Duration - fade_duration); - Scheduler.AddDelayed(() => remainingTimeCounter.StartCounting(b.EndTime), b.StartTime - Clock.CurrentTime); + tasks.Add(new ScheduledDelegate(() => remainingTimeCounter.StartCounting(b.EndTime), b.StartTime)); + Scheduler.Add(tasks.Last()); + remainingTimeCounter.FadeIn(fade_duration); info.FadeIn(fade_duration); diff --git a/osu.Game/Tests/Visual/TestCaseBreakOverlay.cs b/osu.Game/Tests/Visual/TestCaseBreakOverlay.cs index 055a2bc5c4..074aa16934 100644 --- a/osu.Game/Tests/Visual/TestCaseBreakOverlay.cs +++ b/osu.Game/Tests/Visual/TestCaseBreakOverlay.cs @@ -37,8 +37,6 @@ namespace osu.Game.Tests.Visual EndTime = Clock.CurrentTime + duration, } }; - - breakOverlay.InitializeBreaks(); } private void startMultipleBreaks() @@ -58,8 +56,6 @@ namespace osu.Game.Tests.Visual EndTime = currentTime + 6000, } }; - - breakOverlay.InitializeBreaks(); } } } \ No newline at end of file