Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply NRT to notification classes #20026

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
Expand All @@ -19,11 +17,11 @@ namespace osu.Game.Tests.Visual.UserInterface
[TestFixture]
public class TestSceneNotificationOverlay : OsuTestScene
{
private NotificationOverlay notificationOverlay;
private NotificationOverlay notificationOverlay = null!;

private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();

private SpriteText displayedCount;
private SpriteText displayedCount = null!;

[SetUp]
public void SetUp() => Schedule(() =>
Expand All @@ -46,7 +44,7 @@ public void SetUp() => Schedule(() =>
[Test]
public void TestCompleteProgress()
{
ProgressNotification notification = null;
ProgressNotification notification = null!;
AddStep("add progress notification", () =>
{
notification = new ProgressNotification
Expand All @@ -64,7 +62,7 @@ public void TestCompleteProgress()
[Test]
public void TestCancelProgress()
{
ProgressNotification notification = null;
ProgressNotification notification = null!;
AddStep("add progress notification", () =>
{
notification = new ProgressNotification
Expand Down
2 changes: 0 additions & 2 deletions osu.Game/Database/ImportProgressNotification.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using osu.Game.Overlays.Notifications;

namespace osu.Game.Database
Expand Down
12 changes: 3 additions & 9 deletions osu.Game/Overlays/NotificationOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,8 @@ private void load(FirstRunSetupOverlay? firstRunSetup)
RelativeSizeAxes = Axes.X,
Children = new[]
{
new NotificationSection(AccountsStrings.NotificationsTitle, "Clear All")
{
AcceptTypes = new[] { typeof(SimpleNotification) }
},
new NotificationSection(@"Running Tasks", @"Cancel All")
{
AcceptTypes = new[] { typeof(ProgressNotification) }
}
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }, "Clear All"),
new NotificationSection(@"Running Tasks", new[] { typeof(ProgressNotification) }, @"Cancel All"),
}
}
}
Expand Down Expand Up @@ -133,7 +127,7 @@ public void Post(Notification notification) => postScheduler.Add(() =>

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

if (notification.IsImportant)
Expand Down
8 changes: 3 additions & 5 deletions osu.Game/Overlays/Notifications/Notification.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
Expand All @@ -26,7 +24,7 @@ public abstract class Notification : Container
/// <summary>
/// User requested close.
/// </summary>
public event Action Closed;
public event Action? Closed;

public abstract LocalisableString Text { get; set; }

Expand All @@ -38,7 +36,7 @@ public abstract class Notification : Container
/// <summary>
/// Run on user activating the notification. Return true to close.
/// </summary>
public Func<bool> Activated;
public Func<bool>? Activated;

/// <summary>
/// Should we show at the top of our section on display?
Expand Down Expand Up @@ -212,7 +210,7 @@ protected override void OnHoverLost(HoverLostEvent e)
public class NotificationLight : Container
{
private bool pulsate;
private Container pulsateLayer;
private Container pulsateLayer = null!;

public bool Pulsate
{
Expand Down
14 changes: 7 additions & 7 deletions osu.Game/Overlays/Notifications/NotificationSection.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -21,9 +19,9 @@ namespace osu.Game.Overlays.Notifications
{
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 UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
Expand All @@ -33,14 +31,16 @@ public void Add(Notification notification, float position)
notifications.Insert((int)position, notification);
}

public IEnumerable<Type> AcceptTypes;
public IEnumerable<Type> AcceptedNotificationTypes { get; }

private readonly string clearButtonText;

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();
titleText = title;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public LocalisableString Text

public void MarkAllRead()
{
notifications?.Children.ForEach(n => n.Read = true);
notifications.Children.ForEach(n => n.Read = true);
}
}

Expand Down
32 changes: 15 additions & 17 deletions osu.Game/Overlays/Notifications/ProgressNotification.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using System.Threading;
using osu.Framework.Allocation;
Expand All @@ -25,6 +23,18 @@ public class ProgressNotification : Notification, IHasCompletionTarget
{
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;

public override LocalisableString Text
Expand Down Expand Up @@ -142,7 +152,7 @@ private void updateState()
Text = CompletionText
};

protected virtual void Completed()
protected void Completed()
{
CompletionTarget?.Invoke(CreateCompletionNotification());
base.Close();
Expand All @@ -155,8 +165,8 @@ protected virtual void Completed()
private Color4 colourActive;
private Color4 colourCancelled;

private Box iconBackground;
private LoadingSpinner loadingSpinner;
private Box iconBackground = null!;
private LoadingSpinner loadingSpinner = null!;

private readonly TextFlowContainer textDrawable;

Expand Down Expand Up @@ -222,18 +232,6 @@ public override void Close()
}
}

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 readonly Box box;
Expand Down
2 changes: 0 additions & 2 deletions osu.Game/Overlays/Notifications/SimpleNotification.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
Expand Down