1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 09:32:55 +08:00

Merge pull request #1171 from peppy/zero-notifications-closes

Allow the notification overlay to close when all notifications are dismissed
This commit is contained in:
Dean Herbert 2017-08-22 22:56:40 +09:00 committed by GitHub
commit 354e6c1297
3 changed files with 14 additions and 3 deletions

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays
private ScrollContainer scrollContainer; private ScrollContainer scrollContainer;
private FlowContainer<NotificationSection> sections; private FlowContainer<NotificationSection> sections;
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Width = width; Width = width;
@ -72,6 +72,13 @@ namespace osu.Game.Overlays
private int runningDepth; private int runningDepth;
private void notificationClosed()
{
// hide ourselves if all notifications have been dismissed.
if (sections.Select(c => c.DisplayedCount).Sum() > 0)
State = Visibility.Hidden;
}
public void Post(Notification notification) public void Post(Notification notification)
{ {
Schedule(() => Schedule(() =>
@ -81,6 +88,8 @@ namespace osu.Game.Overlays
++runningDepth; ++runningDepth;
notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth; notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth;
notification.Closed += notificationClosed;
var hasCompletionTarget = notification as IHasCompletionTarget; var hasCompletionTarget = notification as IHasCompletionTarget;
if (hasCompletionTarget != null) if (hasCompletionTarget != null)
hasCompletionTarget.CompletionTarget = Post; hasCompletionTarget.CompletionTarget = Post;

View File

@ -19,9 +19,9 @@ namespace osu.Game.Overlays.Notifications
public abstract class Notification : Container public abstract class Notification : Container
{ {
/// <summary> /// <summary>
/// Use requested close. /// User requested close.
/// </summary> /// </summary>
public Action Closed; public event Action Closed;
/// <summary> /// <summary>
/// Run on user activating the notification. Return true to close. /// Run on user activating the notification. Return true to close.

View File

@ -24,6 +24,8 @@ namespace osu.Game.Overlays.Notifications
private FlowContainer<Notification> notifications; private FlowContainer<Notification> notifications;
public int DisplayedCount => notifications.Count;
public void Add(Notification notification) public void Add(Notification notification)
{ {
notifications.Add(notification); notifications.Add(notification);