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.
This commit is contained in:
Dean Herbert 2019-06-20 19:05:33 +09:00
parent 35ce032be1
commit 9a663715cd

View File

@ -23,10 +23,16 @@ namespace osu.Game.Overlays.Notifications
public string CompletionText { get; set; } = "Task has completed!"; public string CompletionText { get; set; } = "Task has completed!";
private float progress;
public float Progress public float Progress
{ {
get => progressBar.Progress; get => progress;
set => Schedule(() => progressBar.Progress = value); set
{
progress = value;
Scheduler.AddOnce(() => progressBar.Progress = progress);
}
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -34,59 +40,56 @@ namespace osu.Game.Overlays.Notifications
base.LoadComplete(); base.LoadComplete();
//we may have received changes before we were displayed. //we may have received changes before we were displayed.
State = state; updateState();
} }
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
public CancellationToken CancellationToken => cancellationTokenSource.Token; public CancellationToken CancellationToken => cancellationTokenSource.Token;
public virtual ProgressNotificationState State public ProgressNotificationState State
{ {
get => state; get => state;
set => set
Schedule(() => {
{ if (state == value) return;
bool stateChanged = state != value;
state = value;
if (IsLoaded) state = value;
{
switch (state)
{
case ProgressNotificationState.Queued:
Light.Colour = colourQueued;
Light.Pulsate = false;
progressBar.Active = false;
break;
case ProgressNotificationState.Active: if (IsLoaded)
Light.Colour = colourActive; Schedule(updateState);
Light.Pulsate = true; }
progressBar.Active = true; }
break;
case ProgressNotificationState.Cancelled: private void updateState()
cancellationTokenSource.Cancel(); {
switch (state)
{
case ProgressNotificationState.Queued:
Light.Colour = colourQueued;
Light.Pulsate = false;
progressBar.Active = false;
break;
Light.Colour = colourCancelled; case ProgressNotificationState.Active:
Light.Pulsate = false; Light.Colour = colourActive;
progressBar.Active = false; Light.Pulsate = true;
break; progressBar.Active = true;
} break;
}
if (stateChanged) case ProgressNotificationState.Cancelled:
{ cancellationTokenSource.Cancel();
switch (state)
{ Light.Colour = colourCancelled;
case ProgressNotificationState.Completed: Light.Pulsate = false;
NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint); progressBar.Active = false;
this.FadeOut(200).Finally(d => Completed()); break;
break;
} case ProgressNotificationState.Completed:
} NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint);
}); this.FadeOut(200).Finally(d => Completed());
break;
}
} }
private ProgressNotificationState state; private ProgressNotificationState state;