1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:07:23 +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
{
[Resolved]
private NotificationOverlay notifications { get; set; }
private INotificationOverlay notifications { get; set; }
private bool elevated;

View File

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

View File

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

View File

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

View File

@ -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)]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
}
[BackgroundDependencyLoader(true)]
private void load(IAPIProvider api, NotificationOverlay notifications)
private void load(IAPIProvider api, INotificationOverlay notifications)
{
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
{
public class NotificationOverlay : OsuFocusedOverlayContainer, INamedOverlayComponent
public class NotificationOverlay : OsuFocusedOverlayContainer, INamedOverlayComponent, INotificationOverlay
{
public string IconTexture => "Icons/Hexacons/notification";
public LocalisableString Title => NotificationsStrings.HeaderTitle;
@ -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;
@ -111,10 +113,6 @@ namespace osu.Game.Overlays
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(() =>
{
++runningDepth;
@ -184,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()

View File

@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
private SettingsButton checkForUpdatesButton;
[Resolved(CanBeNull = true)]
private NotificationOverlay notifications { get; set; }
private INotificationOverlay notifications { get; set; }
[BackgroundDependencyLoader(true)]
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; }
[Resolved]
private NotificationOverlay notifications { get; set; }
private INotificationOverlay notifications { get; set; }
[Resolved]
private Storage storage { get; set; }

View File

@ -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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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