1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Use less dodgy method of specifying allowable notification types

This commit is contained in:
Bartłomiej Dach 2023-10-13 10:31:00 +02:00
parent 79cec7707d
commit e04a57d67f
No known key found for this signature in database
2 changed files with 10 additions and 5 deletions

View File

@ -114,7 +114,7 @@ namespace osu.Game.Overlays
Children = new[]
{
// The main section adds as a catch-all for notifications which don't group into other sections.
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(Notification) }),
new NotificationSection(AccountsStrings.NotificationsTitle),
new NotificationSection(NotificationsStrings.RunningTasks, new[] { typeof(ProgressNotification) }),
}
}
@ -206,7 +206,8 @@ namespace osu.Game.Overlays
var ourType = notification.GetType();
int depth = notification.DisplayOnTop ? -runningDepth : runningDepth;
var section = sections.Children.Last(s => s.AcceptedNotificationTypes.Any(accept => accept.IsAssignableFrom(ourType)));
var section = sections.Children.FirstOrDefault(s => s.AcceptedNotificationTypes?.Any(accept => accept.IsAssignableFrom(ourType)) == true)
?? sections.First();
section.Add(notification, depth);

View File

@ -37,13 +37,17 @@ namespace osu.Game.Overlays.Notifications
notifications.Insert((int)position, notification);
}
public IEnumerable<Type> AcceptedNotificationTypes { get; }
/// <summary>
/// Enumerable of notification types accepted in this section.
/// If <see langword="null"/>, the section accepts any and all notifications.
/// </summary>
public IEnumerable<Type>? AcceptedNotificationTypes { get; }
private readonly LocalisableString titleText;
public NotificationSection(LocalisableString title, IEnumerable<Type> acceptedNotificationTypes)
public NotificationSection(LocalisableString title, IEnumerable<Type>? acceptedNotificationTypes = null)
{
AcceptedNotificationTypes = acceptedNotificationTypes.ToArray();
AcceptedNotificationTypes = acceptedNotificationTypes?.ToArray();
titleText = title;
}