mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Add unread count to INotificationOverlay
and fix toolbar button DI logic
This commit is contained in:
parent
94335c2938
commit
83e89b3e80
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -22,6 +23,17 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
[Resolved]
|
||||
private IRulesetStore rulesets { get; set; }
|
||||
|
||||
private readonly Mock<INotificationOverlay> notifications = new Mock<INotificationOverlay>();
|
||||
|
||||
private readonly BindableInt unreadNotificationCount = new BindableInt();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Dependencies.CacheAs(notifications.Object);
|
||||
notifications.SetupGet(n => n.UnreadCount).Returns(unreadNotificationCount);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
@ -31,10 +43,6 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
[Test]
|
||||
public void TestNotificationCounter()
|
||||
{
|
||||
ToolbarNotificationButton notificationButton = null;
|
||||
|
||||
AddStep("retrieve notification button", () => notificationButton = toolbar.ChildrenOfType<ToolbarNotificationButton>().Single());
|
||||
|
||||
setNotifications(1);
|
||||
setNotifications(2);
|
||||
setNotifications(3);
|
||||
@ -43,7 +51,7 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
|
||||
void setNotifications(int count)
|
||||
=> AddStep($"set notification count to {count}",
|
||||
() => notificationButton.NotificationCount.Value = count);
|
||||
() => unreadNotificationCount.Value = count);
|
||||
}
|
||||
|
||||
[TestCase(false)]
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
@ -22,5 +23,10 @@ namespace osu.Game.Overlays
|
||||
/// Hide the overlay, if it is currently visible.
|
||||
/// </summary>
|
||||
void Hide();
|
||||
|
||||
/// <summary>
|
||||
/// Current number of unread notifications.
|
||||
/// </summary>
|
||||
IBindable<int> UnreadCount { get; }
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,9 @@ namespace osu.Game.Overlays
|
||||
OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true);
|
||||
}
|
||||
|
||||
public readonly BindableInt UnreadCount = new BindableInt();
|
||||
public IBindable<int> UnreadCount => unreadCount;
|
||||
|
||||
private readonly BindableInt unreadCount = new BindableInt();
|
||||
|
||||
private int runningDepth;
|
||||
|
||||
@ -180,7 +182,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
private void updateCounts()
|
||||
{
|
||||
UnreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
|
||||
unreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
|
||||
}
|
||||
|
||||
private void markAllRead()
|
||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
protected override Anchor TooltipAnchor => Anchor.TopRight;
|
||||
|
||||
public BindableInt NotificationCount = new BindableInt();
|
||||
public IBindable<int> NotificationCount = new BindableInt();
|
||||
|
||||
private readonly CountCircle countDisplay;
|
||||
|
||||
@ -36,10 +36,10 @@ namespace osu.Game.Overlays.Toolbar
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(NotificationOverlay notificationOverlay)
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(INotificationOverlay notificationOverlay)
|
||||
{
|
||||
StateContainer = notificationOverlay;
|
||||
StateContainer = notificationOverlay as NotificationOverlay;
|
||||
|
||||
if (notificationOverlay != null)
|
||||
NotificationCount.BindTo(notificationOverlay.UnreadCount);
|
||||
|
Loading…
Reference in New Issue
Block a user