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

Expose unread notification count

This commit is contained in:
Dean Herbert 2017-12-26 01:50:05 +09:00
parent bb33d0211a
commit 1fc240f6c5
3 changed files with 37 additions and 16 deletions

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
@ -25,6 +26,12 @@ namespace osu.Game.Tests.Visual
Origin = Anchor.TopRight
});
SpriteText displayedCount = new SpriteText();
Content.Add(displayedCount);
manager.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count}"; };
AddStep(@"toggle", manager.ToggleVisibility);
AddStep(@"simple #1", sendHelloNotification);
AddStep(@"simple #2", sendAmazingNotification);

View File

@ -11,6 +11,7 @@ using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using System;
using osu.Framework.Configuration;
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 void notificationClosed()
{
// hide ourselves if all notifications have been dismissed.
if (sections.Select(c => c.DisplayedCount).Sum() == 0)
if (totalCount == 0)
State = Visibility.Hidden;
updateCounts();
}
public void Post(Notification notification)
public void Post(Notification notification) => Schedule(() =>
{
Schedule(() =>
{
State = Visibility.Visible;
++runningDepth;
notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth;
@ -101,8 +105,9 @@ namespace osu.Game.Overlays
var ourType = notification.GetType();
sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification);
updateCounts();
});
}
protected override void PopIn()
{
@ -122,9 +127,16 @@ namespace osu.Game.Overlays
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
}
private void updateCounts()
{
UnreadCount.Value = unreadCount;
}
private void markAllRead()
{
sections.Children.ForEach(s => s.MarkAllRead());
updateCounts();
}
protected override void UpdateAfterChildren()

View File

@ -26,6 +26,8 @@ namespace osu.Game.Overlays.Notifications
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 IEnumerable<Type> AcceptTypes;