mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Expose unread notification count
This commit is contained in:
@ -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,34 +76,38 @@ 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;
|
||||
|
||||
++runningDepth;
|
||||
notification.Depth = notification.DisplayOnTop ? runningDepth : -runningDepth;
|
||||
notification.Closed += notificationClosed;
|
||||
|
||||
notification.Closed += notificationClosed;
|
||||
var hasCompletionTarget = notification as IHasCompletionTarget;
|
||||
if (hasCompletionTarget != null)
|
||||
hasCompletionTarget.CompletionTarget = Post;
|
||||
|
||||
var hasCompletionTarget = notification as IHasCompletionTarget;
|
||||
if (hasCompletionTarget != null)
|
||||
hasCompletionTarget.CompletionTarget = Post;
|
||||
var ourType = notification.GetType();
|
||||
sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification);
|
||||
|
||||
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()
|
||||
|
Reference in New Issue
Block a user