From 9a663715cdb2fc5fee9e163b1d42ab8acfaf14e7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 20 Jun 2019 19:05:33 +0900 Subject: [PATCH] Make get methods of ProgressNotification return correct values immediately Previously they were only updated after the resultant schedule ran. This would not bode well when the overlay containing them is not present. --- .../Notifications/ProgressNotification.cs | 87 ++++++++++--------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/osu.Game/Overlays/Notifications/ProgressNotification.cs b/osu.Game/Overlays/Notifications/ProgressNotification.cs index c8e081d29f..99836705c4 100644 --- a/osu.Game/Overlays/Notifications/ProgressNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressNotification.cs @@ -23,10 +23,16 @@ namespace osu.Game.Overlays.Notifications public string CompletionText { get; set; } = "Task has completed!"; + private float progress; + public float Progress { - get => progressBar.Progress; - set => Schedule(() => progressBar.Progress = value); + get => progress; + set + { + progress = value; + Scheduler.AddOnce(() => progressBar.Progress = progress); + } } protected override void LoadComplete() @@ -34,59 +40,56 @@ namespace osu.Game.Overlays.Notifications base.LoadComplete(); //we may have received changes before we were displayed. - State = state; + updateState(); } private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); public CancellationToken CancellationToken => cancellationTokenSource.Token; - public virtual ProgressNotificationState State + public ProgressNotificationState State { get => state; - set => - Schedule(() => - { - bool stateChanged = state != value; - state = value; + set + { + if (state == value) return; - if (IsLoaded) - { - switch (state) - { - case ProgressNotificationState.Queued: - Light.Colour = colourQueued; - Light.Pulsate = false; - progressBar.Active = false; - break; + state = value; - case ProgressNotificationState.Active: - Light.Colour = colourActive; - Light.Pulsate = true; - progressBar.Active = true; - break; + if (IsLoaded) + Schedule(updateState); + } + } - case ProgressNotificationState.Cancelled: - cancellationTokenSource.Cancel(); + private void updateState() + { + switch (state) + { + case ProgressNotificationState.Queued: + Light.Colour = colourQueued; + Light.Pulsate = false; + progressBar.Active = false; + break; - Light.Colour = colourCancelled; - Light.Pulsate = false; - progressBar.Active = false; - break; - } - } + case ProgressNotificationState.Active: + Light.Colour = colourActive; + Light.Pulsate = true; + progressBar.Active = true; + break; - if (stateChanged) - { - switch (state) - { - case ProgressNotificationState.Completed: - NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint); - this.FadeOut(200).Finally(d => Completed()); - break; - } - } - }); + case ProgressNotificationState.Cancelled: + cancellationTokenSource.Cancel(); + + Light.Colour = colourCancelled; + Light.Pulsate = false; + progressBar.Active = false; + break; + + case ProgressNotificationState.Completed: + NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint); + this.FadeOut(200).Finally(d => Completed()); + break; + } } private ProgressNotificationState state;