mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:02:57 +08:00
Merge pull request #20032 from peppy/toast-notification-tray
Add toast notification tray
This commit is contained in:
commit
6cadcc206b
@ -14,11 +14,10 @@ using osu.Framework.Audio;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Framework.Utils;
|
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
@ -30,7 +29,6 @@ using osu.Game.Screens.Play;
|
|||||||
using osu.Game.Screens.Play.PlayerSettings;
|
using osu.Game.Screens.Play.PlayerSettings;
|
||||||
using osu.Game.Utils;
|
using osu.Game.Utils;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using SkipOverlay = osu.Game.Screens.Play.SkipOverlay;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Gameplay
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
{
|
{
|
||||||
@ -83,6 +81,20 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup() => Schedule(() => player = null);
|
public void Setup() => Schedule(() => player = null);
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public override void SetUpSteps()
|
||||||
|
{
|
||||||
|
base.SetUpSteps();
|
||||||
|
|
||||||
|
AddStep("read all notifications", () =>
|
||||||
|
{
|
||||||
|
notificationOverlay.Show();
|
||||||
|
notificationOverlay.Hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for no notifications", () => notificationOverlay.UnreadCount.Value, () => Is.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the input manager child to a new test player loader container instance.
|
/// Sets the input manager child to a new test player loader container instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -287,16 +299,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
saveVolumes();
|
saveVolumes();
|
||||||
|
|
||||||
AddAssert("check for notification", () => notificationOverlay.UnreadCount.Value == 1);
|
AddAssert("check for notification", () => notificationOverlay.UnreadCount.Value, () => Is.EqualTo(1));
|
||||||
AddStep("click notification", () =>
|
|
||||||
{
|
|
||||||
var scrollContainer = (OsuScrollContainer)notificationOverlay.Children.Last();
|
|
||||||
var flowContainer = scrollContainer.Children.OfType<FillFlowContainer<NotificationSection>>().First();
|
|
||||||
var notification = flowContainer.First();
|
|
||||||
|
|
||||||
InputManager.MoveMouseTo(notification);
|
clickNotificationIfAny();
|
||||||
InputManager.Click(MouseButton.Left);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddAssert("check " + volumeName, assert);
|
AddAssert("check " + volumeName, assert);
|
||||||
|
|
||||||
@ -366,15 +371,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
}));
|
}));
|
||||||
AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready);
|
AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready);
|
||||||
AddAssert($"notification {(shouldWarn ? "triggered" : "not triggered")}", () => notificationOverlay.UnreadCount.Value == (shouldWarn ? 1 : 0));
|
AddAssert($"notification {(shouldWarn ? "triggered" : "not triggered")}", () => notificationOverlay.UnreadCount.Value == (shouldWarn ? 1 : 0));
|
||||||
AddStep("click notification", () =>
|
clickNotificationIfAny();
|
||||||
{
|
|
||||||
var scrollContainer = (OsuScrollContainer)notificationOverlay.Children.Last();
|
|
||||||
var flowContainer = scrollContainer.Children.OfType<FillFlowContainer<NotificationSection>>().First();
|
|
||||||
var notification = flowContainer.First();
|
|
||||||
|
|
||||||
InputManager.MoveMouseTo(notification);
|
|
||||||
InputManager.Click(MouseButton.Left);
|
|
||||||
});
|
|
||||||
AddUntilStep("wait for player load", () => player.IsLoaded);
|
AddUntilStep("wait for player load", () => player.IsLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,6 +436,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddUntilStep("skip button not visible", () => !checkSkipButtonVisible());
|
AddUntilStep("skip button not visible", () => !checkSkipButtonVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clickNotificationIfAny()
|
||||||
|
{
|
||||||
|
AddStep("click notification", () => notificationOverlay.ChildrenOfType<Notification>().FirstOrDefault()?.TriggerClick());
|
||||||
|
}
|
||||||
|
|
||||||
private EpilepsyWarning getWarning() => loader.ChildrenOfType<EpilepsyWarning>().SingleOrDefault();
|
private EpilepsyWarning getWarning() => loader.ChildrenOfType<EpilepsyWarning>().SingleOrDefault();
|
||||||
|
|
||||||
private class TestPlayerLoader : PlayerLoader
|
private class TestPlayerLoader : PlayerLoader
|
||||||
|
@ -52,6 +52,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
},
|
},
|
||||||
notifications = new NotificationOverlay
|
notifications = new NotificationOverlay
|
||||||
{
|
{
|
||||||
|
Depth = float.MinValue,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
}
|
}
|
||||||
@ -82,7 +83,14 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
[Test]
|
[Test]
|
||||||
public virtual void TestPlayIntroWithFailingAudioDevice()
|
public virtual void TestPlayIntroWithFailingAudioDevice()
|
||||||
{
|
{
|
||||||
AddStep("hide notifications", () => notifications.Hide());
|
AddStep("reset notifications", () =>
|
||||||
|
{
|
||||||
|
notifications.Show();
|
||||||
|
notifications.Hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for no notifications", () => notifications.UnreadCount.Value, () => Is.EqualTo(0));
|
||||||
|
|
||||||
AddStep("restart sequence", () =>
|
AddStep("restart sequence", () =>
|
||||||
{
|
{
|
||||||
logo.FinishTransforms();
|
logo.FinishTransforms();
|
||||||
|
@ -26,16 +26,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
public void TestImportantNotificationDoesntInterruptSetup()
|
public void TestImportantNotificationDoesntInterruptSetup()
|
||||||
{
|
{
|
||||||
AddStep("post important notification", () => Game.Notifications.Post(new SimpleNotification { Text = "Important notification" }));
|
AddStep("post important notification", () => Game.Notifications.Post(new SimpleNotification { Text = "Important notification" }));
|
||||||
AddAssert("no notification posted", () => Game.Notifications.UnreadCount.Value == 0);
|
|
||||||
AddAssert("first-run setup still visible", () => Game.FirstRunOverlay.State.Value == Visibility.Visible);
|
AddAssert("first-run setup still visible", () => Game.FirstRunOverlay.State.Value == Visibility.Visible);
|
||||||
|
|
||||||
AddUntilStep("finish first-run setup", () =>
|
|
||||||
{
|
|
||||||
Game.FirstRunOverlay.NextButton.TriggerClick();
|
|
||||||
return Game.FirstRunOverlay.State.Value == Visibility.Hidden;
|
|
||||||
});
|
|
||||||
AddWaitStep("wait for post delay", 5);
|
|
||||||
AddAssert("notifications shown", () => Game.Notifications.State.Value == Visibility.Visible);
|
|
||||||
AddAssert("notification posted", () => Game.Notifications.UnreadCount.Value == 1);
|
AddAssert("notification posted", () => Game.Notifications.UnreadCount.Value == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
AddStep(@"simple #1", sendHelloNotification);
|
AddStep(@"simple #1", sendHelloNotification);
|
||||||
|
|
||||||
AddAssert("Is visible", () => notificationOverlay.State.Value == Visibility.Visible);
|
AddAssert("toast displayed", () => notificationOverlay.ToastCount == 1);
|
||||||
|
AddAssert("is not visible", () => notificationOverlay.State.Value == Visibility.Hidden);
|
||||||
|
|
||||||
checkDisplayedCount(1);
|
checkDisplayedCount(1);
|
||||||
|
|
||||||
@ -183,7 +184,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkDisplayedCount(int expected) =>
|
private void checkDisplayedCount(int expected) =>
|
||||||
AddAssert($"Displayed count is {expected}", () => notificationOverlay.UnreadCount.Value == expected);
|
AddUntilStep($"Displayed count is {expected}", () => notificationOverlay.UnreadCount.Value == expected);
|
||||||
|
|
||||||
private void sendDownloadProgress()
|
private void sendDownloadProgress()
|
||||||
{
|
{
|
||||||
|
@ -804,8 +804,8 @@ namespace osu.Game
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||||
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
|
||||||
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||||
|
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||||
|
@ -15,6 +15,7 @@ using osu.Framework.Threading;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
using osuTK;
|
||||||
using NotificationsStrings = osu.Game.Localisation.NotificationsStrings;
|
using NotificationsStrings = osu.Game.Localisation.NotificationsStrings;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
@ -37,10 +38,25 @@ namespace osu.Game.Overlays
|
|||||||
[Cached]
|
[Cached]
|
||||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||||
|
|
||||||
private readonly IBindable<Visibility> firstRunSetupVisibility = new Bindable<Visibility>();
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
||||||
|
{
|
||||||
|
if (State.Value == Visibility.Visible)
|
||||||
|
return base.ReceivePositionalInputAt(screenSpacePos);
|
||||||
|
|
||||||
|
if (toastTray.IsDisplayingToasts)
|
||||||
|
return toastTray.ReceivePositionalInputAt(screenSpacePos);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool PropagatePositionalInputSubTree => base.PropagatePositionalInputSubTree || toastTray.IsDisplayingToasts;
|
||||||
|
|
||||||
|
private NotificationOverlayToastTray toastTray = null!;
|
||||||
|
|
||||||
|
private Container mainContent = null!;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(FirstRunSetupOverlay? firstRunSetup)
|
private void load()
|
||||||
{
|
{
|
||||||
X = WIDTH;
|
X = WIDTH;
|
||||||
Width = WIDTH;
|
Width = WIDTH;
|
||||||
@ -48,47 +64,57 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
toastTray = new NotificationOverlayToastTray
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
ForwardNotificationToPermanentStore = addPermanently,
|
||||||
Colour = colourProvider.Background4,
|
Origin = Anchor.TopRight,
|
||||||
},
|
},
|
||||||
new OsuScrollContainer
|
mainContent = new Container
|
||||||
{
|
{
|
||||||
Masking = true,
|
AlwaysPresent = true,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
sections = new FillFlowContainer<NotificationSection>
|
new Box
|
||||||
{
|
{
|
||||||
Direction = FillDirection.Vertical,
|
RelativeSizeAxes = Axes.Both,
|
||||||
AutoSizeAxes = Axes.Y,
|
Colour = colourProvider.Background4,
|
||||||
RelativeSizeAxes = Axes.X,
|
},
|
||||||
|
new OsuScrollContainer
|
||||||
|
{
|
||||||
|
Masking = true,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }, "Clear All"),
|
sections = new FillFlowContainer<NotificationSection>
|
||||||
new NotificationSection(@"Running Tasks", new[] { typeof(ProgressNotification) }, @"Cancel All"),
|
{
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }, "Clear All"),
|
||||||
|
new NotificationSection(@"Running Tasks", new[] { typeof(ProgressNotification) }, @"Cancel All"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (firstRunSetup != null)
|
|
||||||
firstRunSetupVisibility.BindTo(firstRunSetup.State);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate? notificationsEnabler;
|
private ScheduledDelegate? notificationsEnabler;
|
||||||
|
|
||||||
private void updateProcessingMode()
|
private void updateProcessingMode()
|
||||||
{
|
{
|
||||||
bool enabled = (OverlayActivationMode.Value == OverlayActivation.All && firstRunSetupVisibility.Value != Visibility.Visible) || State.Value == Visibility.Visible;
|
bool enabled = OverlayActivationMode.Value == OverlayActivation.All || State.Value == Visibility.Visible;
|
||||||
|
|
||||||
notificationsEnabler?.Cancel();
|
notificationsEnabler?.Cancel();
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
// we want a slight delay before toggling notifications on to avoid the user becoming overwhelmed.
|
// we want a slight delay before toggling notifications on to avoid the user becoming overwhelmed.
|
||||||
notificationsEnabler = Scheduler.AddDelayed(() => processingPosts = true, State.Value == Visibility.Visible ? 0 : 1000);
|
notificationsEnabler = Scheduler.AddDelayed(() => processingPosts = true, State.Value == Visibility.Visible ? 0 : 100);
|
||||||
else
|
else
|
||||||
processingPosts = false;
|
processingPosts = false;
|
||||||
}
|
}
|
||||||
@ -98,12 +124,13 @@ namespace osu.Game.Overlays
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
State.BindValueChanged(_ => updateProcessingMode());
|
State.BindValueChanged(_ => updateProcessingMode());
|
||||||
firstRunSetupVisibility.BindValueChanged(_ => updateProcessingMode());
|
|
||||||
OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true);
|
OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBindable<int> UnreadCount => unreadCount;
|
public IBindable<int> UnreadCount => unreadCount;
|
||||||
|
|
||||||
|
public int ToastCount => toastTray.UnreadCount;
|
||||||
|
|
||||||
private readonly BindableInt unreadCount = new BindableInt();
|
private readonly BindableInt unreadCount = new BindableInt();
|
||||||
|
|
||||||
private int runningDepth;
|
private int runningDepth;
|
||||||
@ -127,18 +154,28 @@ namespace osu.Game.Overlays
|
|||||||
if (notification is IHasCompletionTarget hasCompletionTarget)
|
if (notification is IHasCompletionTarget hasCompletionTarget)
|
||||||
hasCompletionTarget.CompletionTarget = Post;
|
hasCompletionTarget.CompletionTarget = Post;
|
||||||
|
|
||||||
var ourType = notification.GetType();
|
playDebouncedSample(notification.PopInSampleName);
|
||||||
|
|
||||||
var section = sections.Children.FirstOrDefault(s => s.AcceptedNotificationTypes.Any(accept => accept.IsAssignableFrom(ourType)));
|
if (State.Value == Visibility.Hidden)
|
||||||
section?.Add(notification, notification.DisplayOnTop ? -runningDepth : runningDepth);
|
toastTray.Post(notification);
|
||||||
|
else
|
||||||
if (notification.IsImportant)
|
addPermanently(notification);
|
||||||
Show();
|
|
||||||
|
|
||||||
updateCounts();
|
updateCounts();
|
||||||
playDebouncedSample(notification.PopInSampleName);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
private void addPermanently(Notification notification)
|
||||||
|
{
|
||||||
|
var ourType = notification.GetType();
|
||||||
|
int depth = notification.DisplayOnTop ? -runningDepth : runningDepth;
|
||||||
|
|
||||||
|
var section = sections.Children.First(s => s.AcceptedNotificationTypes.Any(accept => accept.IsAssignableFrom(ourType)));
|
||||||
|
|
||||||
|
section.Add(notification, depth);
|
||||||
|
|
||||||
|
updateCounts();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
@ -152,7 +189,9 @@ namespace osu.Game.Overlays
|
|||||||
base.PopIn();
|
base.PopIn();
|
||||||
|
|
||||||
this.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
|
this.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
this.FadeTo(1, TRANSITION_LENGTH, Easing.OutQuint);
|
mainContent.FadeTo(1, TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
|
|
||||||
|
toastTray.FlushAllToasts();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PopOut()
|
protected override void PopOut()
|
||||||
@ -162,7 +201,7 @@ namespace osu.Game.Overlays
|
|||||||
markAllRead();
|
markAllRead();
|
||||||
|
|
||||||
this.MoveToX(WIDTH, TRANSITION_LENGTH, Easing.OutQuint);
|
this.MoveToX(WIDTH, TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
mainContent.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notificationClosed()
|
private void notificationClosed()
|
||||||
@ -183,16 +222,16 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCounts()
|
|
||||||
{
|
|
||||||
unreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void markAllRead()
|
private void markAllRead()
|
||||||
{
|
{
|
||||||
sections.Children.ForEach(s => s.MarkAllRead());
|
sections.Children.ForEach(s => s.MarkAllRead());
|
||||||
|
toastTray.MarkAllRead();
|
||||||
updateCounts();
|
updateCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateCounts()
|
||||||
|
{
|
||||||
|
unreadCount.Value = sections.Select(c => c.UnreadCount).Sum() + toastTray.UnreadCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
153
osu.Game/Overlays/NotificationOverlayToastTray.cs
Normal file
153
osu.Game/Overlays/NotificationOverlayToastTray.cs
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Colour;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Effects;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A tray which attaches to the left of <see cref="NotificationOverlay"/> to show temporary toasts.
|
||||||
|
/// </summary>
|
||||||
|
public class NotificationOverlayToastTray : CompositeDrawable
|
||||||
|
{
|
||||||
|
public bool IsDisplayingToasts => toastFlow.Count > 0;
|
||||||
|
|
||||||
|
private FillFlowContainer<Notification> toastFlow = null!;
|
||||||
|
private BufferedContainer toastContentBackground = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||||
|
|
||||||
|
public Action<Notification>? ForwardNotificationToPermanentStore { get; set; }
|
||||||
|
|
||||||
|
public int UnreadCount => toastFlow.Count(n => !n.WasClosed && !n.Read)
|
||||||
|
+ InternalChildren.OfType<Notification>().Count(n => !n.WasClosed && !n.Read);
|
||||||
|
|
||||||
|
private int runningDepth;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
Padding = new MarginPadding(20);
|
||||||
|
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
toastContentBackground = (new Box
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
Colour = ColourInfo.GradientVertical(
|
||||||
|
colourProvider.Background6.Opacity(0.7f),
|
||||||
|
colourProvider.Background6.Opacity(0.5f)),
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
}.WithEffect(new BlurEffect
|
||||||
|
{
|
||||||
|
PadExtent = true,
|
||||||
|
Sigma = new Vector2(20),
|
||||||
|
}).With(postEffectDrawable =>
|
||||||
|
{
|
||||||
|
postEffectDrawable.Scale = new Vector2(1.5f, 1);
|
||||||
|
postEffectDrawable.Position += new Vector2(70, -50);
|
||||||
|
postEffectDrawable.AutoSizeAxes = Axes.None;
|
||||||
|
postEffectDrawable.RelativeSizeAxes = Axes.X;
|
||||||
|
})),
|
||||||
|
toastFlow = new AlwaysUpdateFillFlowContainer<Notification>
|
||||||
|
{
|
||||||
|
LayoutDuration = 150,
|
||||||
|
LayoutEasing = Easing.OutQuart,
|
||||||
|
Spacing = new Vector2(3),
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MarkAllRead()
|
||||||
|
{
|
||||||
|
toastFlow.Children.ForEach(n => n.Read = true);
|
||||||
|
InternalChildren.OfType<Notification>().ForEach(n => n.Read = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FlushAllToasts()
|
||||||
|
{
|
||||||
|
foreach (var notification in toastFlow.ToArray())
|
||||||
|
forwardNotification(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Post(Notification notification)
|
||||||
|
{
|
||||||
|
++runningDepth;
|
||||||
|
|
||||||
|
int depth = notification.DisplayOnTop ? -runningDepth : runningDepth;
|
||||||
|
|
||||||
|
toastFlow.Insert(depth, notification);
|
||||||
|
|
||||||
|
scheduleDismissal();
|
||||||
|
|
||||||
|
void scheduleDismissal() => Scheduler.AddDelayed(() =>
|
||||||
|
{
|
||||||
|
// Notification dismissed by user.
|
||||||
|
if (notification.WasClosed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Notification forwarded away.
|
||||||
|
if (notification.Parent != toastFlow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Notification hovered; delay dismissal.
|
||||||
|
if (notification.IsHovered)
|
||||||
|
{
|
||||||
|
scheduleDismissal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// All looks good, forward away!
|
||||||
|
forwardNotification(notification);
|
||||||
|
}, notification.IsImportant ? 12000 : 2500);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void forwardNotification(Notification notification)
|
||||||
|
{
|
||||||
|
Debug.Assert(notification.Parent == toastFlow);
|
||||||
|
|
||||||
|
// Temporarily remove from flow so we can animate the position off to the right.
|
||||||
|
toastFlow.Remove(notification);
|
||||||
|
AddInternal(notification);
|
||||||
|
|
||||||
|
notification.MoveToOffset(new Vector2(400, 0), NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
|
notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ =>
|
||||||
|
{
|
||||||
|
RemoveInternal(notification);
|
||||||
|
ForwardNotificationToPermanentStore?.Invoke(notification);
|
||||||
|
|
||||||
|
notification.FadeIn(300, Easing.OutQuint);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
float height = toastFlow.DrawHeight + 120;
|
||||||
|
float alpha = IsDisplayingToasts ? MathHelper.Clamp(toastFlow.DrawHeight / 40, 0, 1) * toastFlow.Children.Max(n => n.Alpha) : 0;
|
||||||
|
|
||||||
|
toastContentBackground.Height = (float)Interpolation.DampContinuously(toastContentBackground.Height, height, 10, Clock.ElapsedFrameTime);
|
||||||
|
toastContentBackground.Alpha = (float)Interpolation.DampContinuously(toastContentBackground.Alpha, alpha, 10, Clock.ElapsedFrameTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,8 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||||
|
|
||||||
|
private readonly Box initialFlash;
|
||||||
|
|
||||||
private Box background = null!;
|
private Box background = null!;
|
||||||
|
|
||||||
protected Notification()
|
protected Notification()
|
||||||
@ -134,6 +136,12 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
initialFlash = new Box
|
||||||
|
{
|
||||||
|
Colour = Color4.White.Opacity(0.8f),
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Blending = BlendingParameters.Additive,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -178,6 +186,8 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
|
|
||||||
MainContent.MoveToX(DrawSize.X);
|
MainContent.MoveToX(DrawSize.X);
|
||||||
MainContent.MoveToX(0, 500, Easing.OutQuint);
|
MainContent.MoveToX(0, 500, Easing.OutQuint);
|
||||||
|
|
||||||
|
initialFlash.FadeOutFromOne(2000, Easing.OutQuart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WasClosed;
|
public bool WasClosed;
|
||||||
|
Loading…
Reference in New Issue
Block a user