mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 21:12:55 +08:00
Expose unread notification count
This commit is contained in:
parent
bb33d0211a
commit
1fc240f6c5
@ -4,6 +4,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
@ -25,6 +26,12 @@ namespace osu.Game.Tests.Visual
|
|||||||
Origin = Anchor.TopRight
|
Origin = Anchor.TopRight
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SpriteText displayedCount = new SpriteText();
|
||||||
|
|
||||||
|
Content.Add(displayedCount);
|
||||||
|
|
||||||
|
manager.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count}"; };
|
||||||
|
|
||||||
AddStep(@"toggle", manager.ToggleVisibility);
|
AddStep(@"toggle", manager.ToggleVisibility);
|
||||||
AddStep(@"simple #1", sendHelloNotification);
|
AddStep(@"simple #1", sendHelloNotification);
|
||||||
AddStep(@"simple #2", sendAmazingNotification);
|
AddStep(@"simple #2", sendAmazingNotification);
|
||||||
|
@ -11,6 +11,7 @@ using OpenTK.Graphics;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using System;
|
using System;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -75,21 +76,24 @@ namespace osu.Game.Overlays
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int totalCount => sections.Select(c => c.DisplayedCount).Sum();
|
||||||
|
private int unreadCount => sections.Select(c => c.UnreadCount).Sum();
|
||||||
|
|
||||||
|
public readonly BindableInt UnreadCount = new BindableInt();
|
||||||
|
|
||||||
private int runningDepth;
|
private int runningDepth;
|
||||||
|
|
||||||
private void notificationClosed()
|
private void notificationClosed()
|
||||||
{
|
{
|
||||||
// hide ourselves if all notifications have been dismissed.
|
// hide ourselves if all notifications have been dismissed.
|
||||||
if (sections.Select(c => c.DisplayedCount).Sum() == 0)
|
if (totalCount == 0)
|
||||||
State = Visibility.Hidden;
|
State = Visibility.Hidden;
|
||||||
|
|
||||||
|
updateCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Post(Notification notification)
|
public void Post(Notification notification) => Schedule(() =>
|
||||||
{
|
{
|
||||||
Schedule(() =>
|
|
||||||
{
|
|
||||||
State = Visibility.Visible;
|
|
||||||
|
|
||||||
++runningDepth;
|
++runningDepth;
|
||||||
notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth;
|
notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth;
|
||||||
|
|
||||||
@ -101,8 +105,9 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
var ourType = notification.GetType();
|
var ourType = notification.GetType();
|
||||||
sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification);
|
sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification);
|
||||||
|
|
||||||
|
updateCounts();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
@ -122,9 +127,16 @@ namespace osu.Game.Overlays
|
|||||||
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateCounts()
|
||||||
|
{
|
||||||
|
UnreadCount.Value = unreadCount;
|
||||||
|
}
|
||||||
|
|
||||||
private void markAllRead()
|
private void markAllRead()
|
||||||
{
|
{
|
||||||
sections.Children.ForEach(s => s.MarkAllRead());
|
sections.Children.ForEach(s => s.MarkAllRead());
|
||||||
|
|
||||||
|
updateCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
|
@ -26,6 +26,8 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
|
|
||||||
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
||||||
|
|
||||||
|
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
||||||
|
|
||||||
public void Add(Notification notification) => notifications.Add(notification);
|
public void Add(Notification notification) => notifications.Add(notification);
|
||||||
|
|
||||||
public IEnumerable<Type> AcceptTypes;
|
public IEnumerable<Type> AcceptTypes;
|
||||||
|
Loading…
Reference in New Issue
Block a user