mirror of
https://github.com/ppy/osu.git
synced 2025-02-07 19:43:20 +08:00
Add transient flag for notifications which shouldn't linger in history
This commit is contained in:
parent
8f8246278a
commit
fde2b22bbc
@ -83,6 +83,40 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
waitForCompletion();
|
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]
|
[Test]
|
||||||
public void TestForwardWithFlingRight()
|
public void TestForwardWithFlingRight()
|
||||||
{
|
{
|
||||||
|
@ -169,6 +169,7 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
notifications.Post(new SimpleNotification
|
notifications.Post(new SimpleNotification
|
||||||
{
|
{
|
||||||
|
Transient = true,
|
||||||
Icon = FontAwesome.Solid.UserPlus,
|
Icon = FontAwesome.Solid.UserPlus,
|
||||||
Text = $"Online: {string.Join(@", ", onlineAlertQueue.Select(u => u.Username))}",
|
Text = $"Online: {string.Join(@", ", onlineAlertQueue.Select(u => u.Username))}",
|
||||||
IconColour = colours.Green,
|
IconColour = colours.Green,
|
||||||
@ -204,6 +205,7 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
notifications.Post(new SimpleNotification
|
notifications.Post(new SimpleNotification
|
||||||
{
|
{
|
||||||
|
Transient = true,
|
||||||
Icon = FontAwesome.Solid.UserMinus,
|
Icon = FontAwesome.Solid.UserMinus,
|
||||||
Text = $"Offline: {string.Join(@", ", offlineAlertQueue.Select(u => u.Username))}",
|
Text = $"Offline: {string.Join(@", ", offlineAlertQueue.Select(u => u.Username))}",
|
||||||
IconColour = colours.Red
|
IconColour = colours.Red
|
||||||
|
@ -41,7 +41,7 @@ namespace osu.Game.Overlays
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
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);
|
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.MoveToOffset(new Vector2(400, 0), NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ =>
|
notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ =>
|
||||||
{
|
{
|
||||||
|
if (notification.Transient)
|
||||||
|
{
|
||||||
|
notification.IsInToastTray = false;
|
||||||
|
notification.Close(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RemoveInternal(notification, false);
|
RemoveInternal(notification, false);
|
||||||
ForwardNotificationToPermanentStore?.Invoke(notification);
|
ForwardNotificationToPermanentStore(notification);
|
||||||
|
|
||||||
notification.FadeIn(300, Easing.OutQuint);
|
notification.FadeIn(300, Easing.OutQuint);
|
||||||
});
|
});
|
||||||
|
@ -34,10 +34,16 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
public abstract LocalisableString Text { get; set; }
|
public abstract LocalisableString Text { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public virtual bool IsImportant => true;
|
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>
|
/// <summary>
|
||||||
/// Run on user activating the notification. Return true to close.
|
/// Run on user activating the notification. Return true to close.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user