From d93548f4ea9a759faa6286e5814d54259f75d709 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 7 Jul 2023 13:10:49 +0900 Subject: [PATCH] Add back "clear all" button for progress notifications but only clear cancelled --- osu.Game/Overlays/INotificationOverlay.cs | 2 +- osu.Game/Overlays/NotificationOverlay.cs | 4 +-- .../Notifications/NotificationSection.cs | 29 +++++++++---------- .../Notifications/ProgressNotification.cs | 2 ++ 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/osu.Game/Overlays/INotificationOverlay.cs b/osu.Game/Overlays/INotificationOverlay.cs index c5ff10c619..7a44fd63ea 100644 --- a/osu.Game/Overlays/INotificationOverlay.cs +++ b/osu.Game/Overlays/INotificationOverlay.cs @@ -44,6 +44,6 @@ namespace osu.Game.Overlays /// /// All ongoing operations (ie. any not in a completed state). /// - public IEnumerable OngoingOperations => AllNotifications.OfType().Where(p => p.State != ProgressNotificationState.Completed && p.State != ProgressNotificationState.Cancelled); + public IEnumerable OngoingOperations => AllNotifications.OfType().Where(p => !p.CompletedOrCancelled); } } diff --git a/osu.Game/Overlays/NotificationOverlay.cs b/osu.Game/Overlays/NotificationOverlay.cs index 5c0427bf03..1ea0e6bb2e 100644 --- a/osu.Game/Overlays/NotificationOverlay.cs +++ b/osu.Game/Overlays/NotificationOverlay.cs @@ -108,8 +108,8 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.X, Children = new[] { - new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }, true), - new NotificationSection(NotificationsStrings.RunningTasks, new[] { typeof(ProgressNotification) }, false), + new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }), + new NotificationSection(NotificationsStrings.RunningTasks, new[] { typeof(ProgressNotification) }), } } } diff --git a/osu.Game/Overlays/Notifications/NotificationSection.cs b/osu.Game/Overlays/Notifications/NotificationSection.cs index 168c6afe27..80bc02a594 100644 --- a/osu.Game/Overlays/Notifications/NotificationSection.cs +++ b/osu.Game/Overlays/Notifications/NotificationSection.cs @@ -41,14 +41,11 @@ namespace osu.Game.Overlays.Notifications private readonly LocalisableString titleText; - private readonly bool allowClear; - - public NotificationSection(LocalisableString title, IEnumerable acceptedNotificationTypes, bool allowClear) + public NotificationSection(LocalisableString title, IEnumerable acceptedNotificationTypes) { AcceptedNotificationTypes = acceptedNotificationTypes.ToArray(); titleText = title; - this.allowClear = allowClear; } [BackgroundDependencyLoader] @@ -72,17 +69,15 @@ namespace osu.Game.Overlays.Notifications { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Children = new[] + Children = new Drawable[] { - allowClear - ? new ClearAllButton - { - Text = NotificationsStrings.ClearAll, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - Action = clearAll - } - : Empty(), + new ClearAllButton + { + Text = NotificationsStrings.ClearAll, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Action = clearAll + }, new FillFlowContainer { Margin = new MarginPadding @@ -118,7 +113,11 @@ namespace osu.Game.Overlays.Notifications }); } - private void clearAll() => notifications.Children.ForEach(c => c.Close(true)); + private void clearAll() => notifications.Children.ForEach(c => + { + if (c is not ProgressNotification p || p.CompletedOrCancelled) + c.Close(true); + }); protected override void Update() { diff --git a/osu.Game/Overlays/Notifications/ProgressNotification.cs b/osu.Game/Overlays/Notifications/ProgressNotification.cs index e6662e2179..5df4c61fd7 100644 --- a/osu.Game/Overlays/Notifications/ProgressNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressNotification.cs @@ -25,6 +25,8 @@ namespace osu.Game.Overlays.Notifications public Func? CancelRequested { get; set; } + public bool CompletedOrCancelled => State == ProgressNotificationState.Completed || State == ProgressNotificationState.Cancelled; + protected override bool AllowFlingDismiss => false; ///