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!";
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;