1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:47:51 +08:00

Merge pull request #17865 from peppy/i-notification-overlay

This commit is contained in:
Salman Ahmed 2022-04-19 08:45:41 +03:00 committed by GitHub
commit 864d13a083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 82 additions and 44 deletions

View File

@ -19,7 +19,7 @@ namespace osu.Desktop.Security
public class ElevatedPrivilegesChecker : Component public class ElevatedPrivilegesChecker : Component
{ {
[Resolved] [Resolved]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
private bool elevated; private bool elevated;

View File

@ -25,7 +25,7 @@ namespace osu.Desktop.Updater
public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager
{ {
private UpdateManager updateManager; private UpdateManager updateManager;
private NotificationOverlay notificationOverlay; private INotificationOverlay notificationOverlay;
public Task PrepareUpdateAsync() => UpdateManager.RestartAppWhenExited(); public Task PrepareUpdateAsync() => UpdateManager.RestartAppWhenExited();
@ -39,9 +39,9 @@ namespace osu.Desktop.Updater
private readonly SquirrelLogger squirrelLogger = new SquirrelLogger(); private readonly SquirrelLogger squirrelLogger = new SquirrelLogger();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(NotificationOverlay notification) private void load(INotificationOverlay notifications)
{ {
notificationOverlay = notification; notificationOverlay = notifications;
SquirrelLocator.CurrentMutable.Register(() => squirrelLogger, typeof(ILogger)); SquirrelLocator.CurrentMutable.Register(() => squirrelLogger, typeof(ILogger));
} }

View File

@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Resolved] [Resolved]
private SessionStatics sessionStatics { get; set; } private SessionStatics sessionStatics { get; set; }
[Cached] [Cached(typeof(INotificationOverlay))]
private readonly NotificationOverlay notificationOverlay; private readonly NotificationOverlay notificationOverlay;
[Cached] [Cached]

View File

@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual.Menus
private IntroScreen intro; private IntroScreen intro;
[Cached] [Cached(typeof(INotificationOverlay))]
private NotificationOverlay notifications; private NotificationOverlay notifications;
private ScheduledDelegate trackResetDelegate; private ScheduledDelegate trackResetDelegate;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using Moq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -22,6 +23,17 @@ namespace osu.Game.Tests.Visual.Menus
[Resolved] [Resolved]
private IRulesetStore rulesets { get; set; } 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] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
@ -31,10 +43,6 @@ namespace osu.Game.Tests.Visual.Menus
[Test] [Test]
public void TestNotificationCounter() public void TestNotificationCounter()
{ {
ToolbarNotificationButton notificationButton = null;
AddStep("retrieve notification button", () => notificationButton = toolbar.ChildrenOfType<ToolbarNotificationButton>().Single());
setNotifications(1); setNotifications(1);
setNotifications(2); setNotifications(2);
setNotifications(3); setNotifications(3);
@ -43,7 +51,7 @@ namespace osu.Game.Tests.Visual.Menus
void setNotifications(int count) void setNotifications(int count)
=> AddStep($"set notification count to {count}", => AddStep($"set notification count to {count}",
() => notificationButton.NotificationCount.Value = count); () => unreadNotificationCount.Value = count);
} }
[TestCase(false)] [TestCase(false)]

View File

@ -37,7 +37,7 @@ namespace osu.Game.Tests.Visual.Navigation
typeof(OsuLogo), typeof(OsuLogo),
typeof(IdleTracker), typeof(IdleTracker),
typeof(OnScreenDisplay), typeof(OnScreenDisplay),
typeof(NotificationOverlay), typeof(INotificationOverlay),
typeof(BeatmapListingOverlay), typeof(BeatmapListingOverlay),
typeof(DashboardOverlay), typeof(DashboardOverlay),
typeof(NewsOverlay), typeof(NewsOverlay),

View File

@ -200,7 +200,7 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
public ChannelManager ChannelManager { get; } = new ChannelManager(); public ChannelManager ChannelManager { get; } = new ChannelManager();
[Cached] [Cached(typeof(INotificationOverlay))]
public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,

View File

@ -14,7 +14,7 @@ namespace osu.Game.Tests.Visual.Settings
{ {
public class TestSceneMigrationScreens : ScreenTestScene public class TestSceneMigrationScreens : ScreenTestScene
{ {
[Cached] [Cached(typeof(INotificationOverlay))]
private readonly NotificationOverlay notifications; private readonly NotificationOverlay notifications;
public TestSceneMigrationScreens() public TestSceneMigrationScreens()

View File

@ -52,7 +52,7 @@ namespace osu.Game.Database
private OsuConfigManager config { get; set; } = null!; private OsuConfigManager config { get; set; } = null!;
[Resolved] [Resolved]
private NotificationOverlay notificationOverlay { get; set; } = null!; private INotificationOverlay notificationOverlay { get; set; } = null!;
[Resolved] [Resolved]
private OsuGame game { get; set; } = null!; private OsuGame game { get; set; } = null!;

View File

@ -43,7 +43,7 @@ namespace osu.Game.Graphics
private Storage storage; private Storage storage;
[Resolved] [Resolved]
private NotificationOverlay notificationOverlay { get; set; } private INotificationOverlay notificationOverlay { get; set; }
private Sample shutter; private Sample shutter;

View File

@ -24,7 +24,7 @@ namespace osu.Game.Online.Chat
public class MessageNotifier : Component public class MessageNotifier : Component
{ {
[Resolved] [Resolved]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
[Resolved] [Resolved]
private ChatOverlay chatOverlay { get; set; } private ChatOverlay chatOverlay { get; set; }
@ -170,7 +170,7 @@ namespace osu.Game.Online.Chat
public override bool IsImportant => false; public override bool IsImportant => false;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverlay notificationOverlay) private void load(OsuColour colours, ChatOverlay chatOverlay, INotificationOverlay notificationOverlay)
{ {
IconBackground.Colour = colours.PurpleDark; IconBackground.Colour = colours.PurpleDark;

View File

@ -772,7 +772,7 @@ namespace osu.Game
loadComponentSingleFile(onScreenDisplay, Add, true); loadComponentSingleFile(onScreenDisplay, Add, true);
loadComponentSingleFile(Notifications.With(d => loadComponentSingleFile<INotificationOverlay>(Notifications.With(d =>
{ {
d.Anchor = Anchor.TopRight; d.Anchor = Anchor.TopRight;
d.Origin = Anchor.TopRight; d.Origin = Anchor.TopRight;

View File

@ -41,7 +41,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(IAPIProvider api, NotificationOverlay notifications) private void load(IAPIProvider api, INotificationOverlay notifications)
{ {
SpriteIcon icon; SpriteIcon icon;

View File

@ -0,0 +1,32 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// 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
{
/// <summary>
/// An overlay which is capable of showing notifications to the user.
/// </summary>
[Cached]
public interface INotificationOverlay
{
/// <summary>
/// Post a new notification for display.
/// </summary>
/// <param name="notification">The notification to display.</param>
void Post(Notification notification);
/// <summary>
/// Hide the overlay, if it is currently visible.
/// </summary>
void Hide();
/// <summary>
/// Current number of unread notifications.
/// </summary>
IBindable<int> UnreadCount { get; }
}
}

View File

@ -19,7 +19,7 @@ using osu.Game.Localisation;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class NotificationOverlay : OsuFocusedOverlayContainer, INamedOverlayComponent public class NotificationOverlay : OsuFocusedOverlayContainer, INamedOverlayComponent, INotificationOverlay
{ {
public string IconTexture => "Icons/Hexacons/notification"; public string IconTexture => "Icons/Hexacons/notification";
public LocalisableString Title => NotificationsStrings.HeaderTitle; public LocalisableString Title => NotificationsStrings.HeaderTitle;
@ -99,7 +99,9 @@ namespace osu.Game.Overlays
OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true); OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true);
} }
public readonly BindableInt UnreadCount = new BindableInt(); public IBindable<int> UnreadCount => unreadCount;
private readonly BindableInt unreadCount = new BindableInt();
private int runningDepth; private int runningDepth;
@ -111,10 +113,6 @@ namespace osu.Game.Overlays
private double? lastSamplePlayback; private double? lastSamplePlayback;
/// <summary>
/// Post a new notification for display.
/// </summary>
/// <param name="notification">The notification to display.</param>
public void Post(Notification notification) => postScheduler.Add(() => public void Post(Notification notification) => postScheduler.Add(() =>
{ {
++runningDepth; ++runningDepth;
@ -184,7 +182,7 @@ namespace osu.Game.Overlays
private void updateCounts() private void updateCounts()
{ {
UnreadCount.Value = sections.Select(c => c.UnreadCount).Sum(); unreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
} }
private void markAllRead() private void markAllRead()

View File

@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
private SettingsButton checkForUpdatesButton; private SettingsButton checkForUpdatesButton;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(Storage storage, OsuConfigManager config, OsuGame game) private void load(Storage storage, OsuConfigManager config, OsuGame game)

View File

@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
private OsuGame game { get; set; } private OsuGame game { get; set; }
[Resolved] [Resolved]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
[Resolved] [Resolved]
private Storage storage { get; set; } private Storage storage { get; set; }

View File

@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Toolbar
{ {
protected override Anchor TooltipAnchor => Anchor.TopRight; protected override Anchor TooltipAnchor => Anchor.TopRight;
public BindableInt NotificationCount = new BindableInt(); public IBindable<int> NotificationCount = new BindableInt();
private readonly CountCircle countDisplay; private readonly CountCircle countDisplay;
@ -36,10 +36,10 @@ namespace osu.Game.Overlays.Toolbar
}); });
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader]
private void load(NotificationOverlay notificationOverlay) private void load(INotificationOverlay notificationOverlay)
{ {
StateContainer = notificationOverlay; StateContainer = notificationOverlay as NotificationOverlay;
if (notificationOverlay != null) if (notificationOverlay != null)
NotificationCount.BindTo(notificationOverlay.UnreadCount); NotificationCount.BindTo(notificationOverlay.UnreadCount);

View File

@ -23,7 +23,7 @@ namespace osu.Game
private readonly Func<IScreen> getCurrentScreen; private readonly Func<IScreen> getCurrentScreen;
[Resolved] [Resolved]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
[Resolved] [Resolved]
private IDialogOverlay dialogOverlay { get; set; } private IDialogOverlay dialogOverlay { get; set; }

View File

@ -87,7 +87,7 @@ namespace osu.Game.Screens.Edit
private IDialogOverlay dialogOverlay { get; set; } private IDialogOverlay dialogOverlay { get; set; }
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
public readonly Bindable<EditorScreenMode> Mode = new Bindable<EditorScreenMode>(); public readonly Bindable<EditorScreenMode> Mode = new Bindable<EditorScreenMode>();

View File

@ -118,7 +118,7 @@ namespace osu.Game.Screens.Menu
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private LoginOverlay loginOverlay { get; set; } private LoginOverlay loginOverlay { get; set; }

View File

@ -171,7 +171,7 @@ namespace osu.Game.Screens.Menu
} }
[Resolved] [Resolved]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
private void ensureEventuallyArrivingAtMenu() private void ensureEventuallyArrivingAtMenu()
{ {

View File

@ -119,7 +119,7 @@ namespace osu.Game.Screens.Play
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuConfigManager config, NotificationOverlay notificationOverlay) private void load(OsuConfigManager config, INotificationOverlay notificationOverlay)
{ {
if (drawableRuleset != null) if (drawableRuleset != null)
{ {

View File

@ -124,7 +124,7 @@ namespace osu.Game.Screens.Play
private EpilepsyWarning? epilepsyWarning; private EpilepsyWarning? epilepsyWarning;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private NotificationOverlay? notificationOverlay { get; set; } private INotificationOverlay? notificationOverlay { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private VolumeOverlay? volumeOverlay { get; set; } private VolumeOverlay? volumeOverlay { get; set; }
@ -515,7 +515,7 @@ namespace osu.Game.Screens.Play
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, AudioManager audioManager, NotificationOverlay notificationOverlay, VolumeOverlay volumeOverlay) private void load(OsuColour colours, AudioManager audioManager, INotificationOverlay notificationOverlay, VolumeOverlay volumeOverlay)
{ {
Icon = FontAwesome.Solid.VolumeMute; Icon = FontAwesome.Solid.VolumeMute;
IconBackground.Colour = colours.RedDark; IconBackground.Colour = colours.RedDark;
@ -567,7 +567,7 @@ namespace osu.Game.Screens.Play
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, NotificationOverlay notificationOverlay) private void load(OsuColour colours, INotificationOverlay notificationOverlay)
{ {
Icon = FontAwesome.Solid.BatteryQuarter; Icon = FontAwesome.Solid.BatteryQuarter;
IconBackground.Colour = colours.RedDark; IconBackground.Colour = colours.RedDark;

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.Select
private OsuScreen playerLoader; private OsuScreen playerLoader;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private NotificationOverlay notifications { get; set; } private INotificationOverlay notifications { get; set; }
public override bool AllowExternalScreenChange => true; public override bool AllowExternalScreenChange => true;

View File

@ -31,7 +31,7 @@ namespace osu.Game.Updater
private OsuGameBase game { get; set; } private OsuGameBase game { get; set; }
[Resolved] [Resolved]
protected NotificationOverlay Notifications { get; private set; } protected INotificationOverlay Notifications { get; private set; }
protected override void LoadComplete() protected override void LoadComplete()
{ {
@ -94,7 +94,7 @@ namespace osu.Game.Updater
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, ChangelogOverlay changelog, NotificationOverlay notificationOverlay) private void load(OsuColour colours, ChangelogOverlay changelog, INotificationOverlay notificationOverlay)
{ {
Icon = FontAwesome.Solid.CheckSquare; Icon = FontAwesome.Solid.CheckSquare;
IconBackground.Colour = colours.BlueDark; IconBackground.Colour = colours.BlueDark;