1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 16:47:26 +08:00

Merge pull request #20339 from peppy/fix-notification-count

Fix notification count not always updating when it should
This commit is contained in:
Salman Ahmed 2022-09-19 02:43:56 +03:00 committed by GitHub
commit 5ccffe86bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 13 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Game.Tests.Visual.UserInterface
displayedCount = new OsuSpriteText()
};
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"unread count: {count.NewValue}"; };
});
[Test]
@ -270,6 +270,8 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait completion", () => notification.State == ProgressNotificationState.Completed);
AddAssert("Completion toast shown", () => notificationOverlay.ToastCount == 1);
AddUntilStep("wait forwarded", () => notificationOverlay.ToastCount == 0);
AddAssert("only one unread", () => notificationOverlay.UnreadCount.Value == 1);
}
[Test]

View File

@ -210,14 +210,14 @@ namespace osu.Game.Overlays
mainContent.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
}
private void notificationClosed()
private void notificationClosed() => Schedule(() =>
{
updateCounts();
// 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.
playDebouncedSample("UI/overlay-pop-out");
}
});
private void playDebouncedSample(string sampleName)
{

View File

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

View File

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