mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Merge pull request #20026 from peppy/notifications-nrt
Apply NRT to notification classes
This commit is contained in:
commit
0e68620f70
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -19,11 +17,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneNotificationOverlay : OsuTestScene
|
public class TestSceneNotificationOverlay : OsuTestScene
|
||||||
{
|
{
|
||||||
private NotificationOverlay notificationOverlay;
|
private NotificationOverlay notificationOverlay = null!;
|
||||||
|
|
||||||
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
|
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
|
||||||
|
|
||||||
private SpriteText displayedCount;
|
private SpriteText displayedCount = null!;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() =>
|
||||||
@ -46,7 +44,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestCompleteProgress()
|
public void TestCompleteProgress()
|
||||||
{
|
{
|
||||||
ProgressNotification notification = null;
|
ProgressNotification notification = null!;
|
||||||
AddStep("add progress notification", () =>
|
AddStep("add progress notification", () =>
|
||||||
{
|
{
|
||||||
notification = new ProgressNotification
|
notification = new ProgressNotification
|
||||||
@ -64,7 +62,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestCancelProgress()
|
public void TestCancelProgress()
|
||||||
{
|
{
|
||||||
ProgressNotification notification = null;
|
ProgressNotification notification = null!;
|
||||||
AddStep("add progress notification", () =>
|
AddStep("add progress notification", () =>
|
||||||
{
|
{
|
||||||
notification = new ProgressNotification
|
notification = new ProgressNotification
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
|
@ -64,14 +64,8 @@ namespace osu.Game.Overlays
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new NotificationSection(AccountsStrings.NotificationsTitle, "Clear All")
|
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }, "Clear All"),
|
||||||
{
|
new NotificationSection(@"Running Tasks", new[] { typeof(ProgressNotification) }, @"Cancel All"),
|
||||||
AcceptTypes = new[] { typeof(SimpleNotification) }
|
|
||||||
},
|
|
||||||
new NotificationSection(@"Running Tasks", @"Cancel All")
|
|
||||||
{
|
|
||||||
AcceptTypes = new[] { typeof(ProgressNotification) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +127,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
var ourType = notification.GetType();
|
var ourType = notification.GetType();
|
||||||
|
|
||||||
var section = sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)));
|
var section = sections.Children.FirstOrDefault(s => s.AcceptedNotificationTypes.Any(accept => accept.IsAssignableFrom(ourType)));
|
||||||
section?.Add(notification, notification.DisplayOnTop ? -runningDepth : runningDepth);
|
section?.Add(notification, notification.DisplayOnTop ? -runningDepth : runningDepth);
|
||||||
|
|
||||||
if (notification.IsImportant)
|
if (notification.IsImportant)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
@ -26,7 +24,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// User requested close.
|
/// User requested close.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action Closed;
|
public event Action? Closed;
|
||||||
|
|
||||||
public abstract LocalisableString Text { get; set; }
|
public abstract LocalisableString Text { get; set; }
|
||||||
|
|
||||||
@ -38,7 +36,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run on user activating the notification. Return true to close.
|
/// Run on user activating the notification. Return true to close.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<bool> Activated;
|
public Func<bool>? Activated;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should we show at the top of our section on display?
|
/// Should we show at the top of our section on display?
|
||||||
@ -212,7 +210,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
public class NotificationLight : Container
|
public class NotificationLight : Container
|
||||||
{
|
{
|
||||||
private bool pulsate;
|
private bool pulsate;
|
||||||
private Container pulsateLayer;
|
private Container pulsateLayer = null!;
|
||||||
|
|
||||||
public bool Pulsate
|
public bool Pulsate
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -21,9 +19,9 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
{
|
{
|
||||||
public class NotificationSection : AlwaysUpdateFillFlowContainer<Drawable>
|
public class NotificationSection : AlwaysUpdateFillFlowContainer<Drawable>
|
||||||
{
|
{
|
||||||
private OsuSpriteText countDrawable;
|
private OsuSpriteText countDrawable = null!;
|
||||||
|
|
||||||
private FlowContainer<Notification> notifications;
|
private FlowContainer<Notification> notifications = null!;
|
||||||
|
|
||||||
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
||||||
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
||||||
@ -33,14 +31,16 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
notifications.Insert((int)position, notification);
|
notifications.Insert((int)position, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Type> AcceptTypes;
|
public IEnumerable<Type> AcceptedNotificationTypes { get; }
|
||||||
|
|
||||||
private readonly string clearButtonText;
|
private readonly string clearButtonText;
|
||||||
|
|
||||||
private readonly LocalisableString titleText;
|
private readonly LocalisableString titleText;
|
||||||
|
|
||||||
public NotificationSection(LocalisableString title, string clearButtonText)
|
public NotificationSection(LocalisableString title, IEnumerable<Type> acceptedNotificationTypes, string clearButtonText)
|
||||||
{
|
{
|
||||||
|
AcceptedNotificationTypes = acceptedNotificationTypes.ToArray();
|
||||||
|
|
||||||
this.clearButtonText = clearButtonText.ToUpperInvariant();
|
this.clearButtonText = clearButtonText.ToUpperInvariant();
|
||||||
titleText = title;
|
titleText = title;
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
|
|
||||||
public void MarkAllRead()
|
public void MarkAllRead()
|
||||||
{
|
{
|
||||||
notifications?.Children.ForEach(n => n.Read = true);
|
notifications.Children.ForEach(n => n.Read = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -25,6 +23,18 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
{
|
{
|
||||||
private const float loading_spinner_size = 22;
|
private const float loading_spinner_size = 22;
|
||||||
|
|
||||||
|
public Func<bool>? CancelRequested { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The function to post completion notifications back to.
|
||||||
|
/// </summary>
|
||||||
|
public Action<Notification>? CompletionTarget { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An action to complete when the completion notification is clicked. Return true to close.
|
||||||
|
/// </summary>
|
||||||
|
public Func<bool>? CompletionClickAction { get; set; }
|
||||||
|
|
||||||
private LocalisableString text;
|
private LocalisableString text;
|
||||||
|
|
||||||
public override LocalisableString Text
|
public override LocalisableString Text
|
||||||
@ -142,7 +152,7 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
Text = CompletionText
|
Text = CompletionText
|
||||||
};
|
};
|
||||||
|
|
||||||
protected virtual void Completed()
|
protected void Completed()
|
||||||
{
|
{
|
||||||
CompletionTarget?.Invoke(CreateCompletionNotification());
|
CompletionTarget?.Invoke(CreateCompletionNotification());
|
||||||
base.Close();
|
base.Close();
|
||||||
@ -155,8 +165,8 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
private Color4 colourActive;
|
private Color4 colourActive;
|
||||||
private Color4 colourCancelled;
|
private Color4 colourCancelled;
|
||||||
|
|
||||||
private Box iconBackground;
|
private Box iconBackground = null!;
|
||||||
private LoadingSpinner loadingSpinner;
|
private LoadingSpinner loadingSpinner = null!;
|
||||||
|
|
||||||
private readonly TextFlowContainer textDrawable;
|
private readonly TextFlowContainer textDrawable;
|
||||||
|
|
||||||
@ -222,18 +232,6 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Func<bool> CancelRequested { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The function to post completion notifications back to.
|
|
||||||
/// </summary>
|
|
||||||
public Action<Notification> CompletionTarget { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// An action to complete when the completion notification is clicked. Return true to close.
|
|
||||||
/// </summary>
|
|
||||||
public Func<bool> CompletionClickAction;
|
|
||||||
|
|
||||||
private class ProgressBar : Container
|
private class ProgressBar : Container
|
||||||
{
|
{
|
||||||
private readonly Box box;
|
private readonly Box box;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
|
Loading…
Reference in New Issue
Block a user