1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-07 17:13:24 +08:00

Add transient flag for notifications which shouldn't linger in history

This commit is contained in:
Dean Herbert 2025-01-22 16:29:50 +09:00
parent 8f8246278a
commit fde2b22bbc
No known key found for this signature in database
4 changed files with 52 additions and 3 deletions

View File

@ -83,6 +83,40 @@ namespace osu.Game.Tests.Visual.UserInterface
waitForCompletion();
}
[Test]
public void TestNormalDoesForwardToOverlay()
{
SimpleNotification notification = null!;
AddStep(@"simple #1", () => notificationOverlay.Post(notification = new SimpleNotification
{
Text = @"This shouldn't annoy you too much",
Transient = false,
}));
AddAssert("notification in toast tray", () => notification.IsInToastTray, () => Is.True);
AddUntilStep("wait for dismissed", () => notification.IsInToastTray, () => Is.False);
checkDisplayedCount(1);
}
[Test]
public void TestTransientDoesNotForwardToOverlay()
{
SimpleNotification notification = null!;
AddStep(@"simple #1", () => notificationOverlay.Post(notification = new SimpleNotification
{
Text = @"This shouldn't annoy you too much",
Transient = true,
}));
AddAssert("notification in toast tray", () => notification.IsInToastTray, () => Is.True);
AddUntilStep("wait for dismissed", () => notification.IsInToastTray, () => Is.False);
checkDisplayedCount(0);
}
[Test]
public void TestForwardWithFlingRight()
{

View File

@ -169,6 +169,7 @@ namespace osu.Game.Online
notifications.Post(new SimpleNotification
{
Transient = true,
Icon = FontAwesome.Solid.UserPlus,
Text = $"Online: {string.Join(@", ", onlineAlertQueue.Select(u => u.Username))}",
IconColour = colours.Green,
@ -204,6 +205,7 @@ namespace osu.Game.Online
notifications.Post(new SimpleNotification
{
Transient = true,
Icon = FontAwesome.Solid.UserMinus,
Text = $"Offline: {string.Join(@", ", offlineAlertQueue.Select(u => u.Username))}",
IconColour = colours.Red

View File

@ -41,7 +41,7 @@ namespace osu.Game.Overlays
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
public Action<Notification>? ForwardNotificationToPermanentStore { get; set; }
public required Action<Notification> ForwardNotificationToPermanentStore { get; init; }
public int UnreadCount => Notifications.Count(n => !n.WasClosed && !n.Read);
@ -142,8 +142,15 @@ namespace osu.Game.Overlays
notification.MoveToOffset(new Vector2(400, 0), NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint);
notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ =>
{
if (notification.Transient)
{
notification.IsInToastTray = false;
notification.Close(false);
return;
}
RemoveInternal(notification, false);
ForwardNotificationToPermanentStore?.Invoke(notification);
ForwardNotificationToPermanentStore(notification);
notification.FadeIn(300, Easing.OutQuint);
});

View File

@ -34,10 +34,16 @@ namespace osu.Game.Overlays.Notifications
public abstract LocalisableString Text { get; set; }
/// <summary>
/// Whether this notification should forcefully display itself.
/// Important notifications display for longer, and announce themselves at an OS level (ie flashing the taskbar).
/// This defaults to <c>true</c>.
/// </summary>
public virtual bool IsImportant => true;
/// <summary>
/// Transient notifications only show as a toast, and do not linger in notification history.
/// </summary>
public bool Transient { get; init; }
/// <summary>
/// Run on user activating the notification. Return true to close.
/// </summary>