Fire Notification.Closed immediately to ensure off-screen notifications are closed

This commit is contained in:
Dean Herbert 2022-09-16 16:36:56 +09:00
parent 0ff4e343f8
commit 0d24fda4b9
3 changed files with 19 additions and 13 deletions

View File

@ -210,14 +210,14 @@ namespace osu.Game.Overlays
mainContent.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint); mainContent.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
} }
private void notificationClosed() private void notificationClosed() => Schedule(() =>
{ {
updateCounts(); updateCounts();
// this debounce is currently shared between popin/popout sounds, which means one could potentially not play when the user is expecting it. // this debounce is currently shared between popin/popout sounds, which means one could potentially not play when the user is expecting it.
// popout is constant across all notification types, and should therefore be handled using playback concurrency instead, but seems broken at the moment. // popout is constant across all notification types, and should therefore be handled using playback concurrency instead, but seems broken at the moment.
playDebouncedSample("UI/overlay-pop-out"); playDebouncedSample("UI/overlay-pop-out");
} });
private void playDebouncedSample(string sampleName) private void playDebouncedSample(string sampleName)
{ {

View File

@ -26,7 +26,8 @@ namespace osu.Game.Overlays.Notifications
public abstract class Notification : Container public abstract class Notification : Container
{ {
/// <summary> /// <summary>
/// User requested close. /// Notification was closed, either by user or otherwise.
/// Importantly, this event may be fired from a non-update thread.
/// </summary> /// </summary>
public event Action? Closed; public event Action? Closed;
@ -55,6 +56,8 @@ namespace osu.Game.Overlays.Notifications
protected Container IconContent; protected Container IconContent;
public bool WasClosed { get; private set; }
private readonly Container content; private readonly Container content;
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
@ -245,21 +248,23 @@ namespace osu.Game.Overlays.Notifications
initialFlash.FadeOutFromOne(2000, Easing.OutQuart); initialFlash.FadeOutFromOne(2000, Easing.OutQuart);
} }
public bool WasClosed;
public virtual void Close(bool runFlingAnimation) public virtual void Close(bool runFlingAnimation)
{ {
if (WasClosed) return; if (WasClosed) return;
WasClosed = true; WasClosed = true;
Closed?.Invoke();
Schedule(() =>
{
if (runFlingAnimation && dragContainer.FlingLeft()) if (runFlingAnimation && dragContainer.FlingLeft())
this.FadeOut(600, Easing.In); this.FadeOut(600, Easing.In);
else else
this.FadeOut(100); this.FadeOut(100);
Closed?.Invoke();
Expire(); Expire();
});
} }
private class DragContainer : Container private class DragContainer : Container

View File

@ -141,8 +141,6 @@ namespace osu.Game.Overlays.Notifications
case ProgressNotificationState.Completed: case ProgressNotificationState.Completed:
loadingSpinner.Hide(); loadingSpinner.Hide();
attemptPostCompletion();
base.Close(false);
break; break;
} }
} }
@ -166,6 +164,8 @@ namespace osu.Game.Overlays.Notifications
CompletionTarget.Invoke(CreateCompletionNotification()); CompletionTarget.Invoke(CreateCompletionNotification());
completionSent = true; completionSent = true;
Close(false);
} }
private ProgressNotificationState state; private ProgressNotificationState state;
@ -239,6 +239,7 @@ namespace osu.Game.Overlays.Notifications
{ {
switch (State) switch (State)
{ {
case ProgressNotificationState.Completed:
case ProgressNotificationState.Cancelled: case ProgressNotificationState.Cancelled:
base.Close(runFlingAnimation); base.Close(runFlingAnimation);
break; break;