mirror of
https://github.com/ppy/osu
synced 2025-01-27 08:13:06 +00:00
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:
parent
35ce032be1
commit
9a663715cd
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user