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;