From 79df094f17b65c5276d317bc84563d0afbe21e67 Mon Sep 17 00:00:00 2001 From: Jamie Taylor Date: Fri, 24 Jan 2025 23:20:04 +0900 Subject: [PATCH 1/4] Add unique samples for friend online/offline notifications --- osu.Game/Online/FriendPresenceNotifier.cs | 4 ++-- .../Notifications/FriendOfflineNotification.cs | 10 ++++++++++ .../Overlays/Notifications/FriendOnlineNotification.cs | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 osu.Game/Overlays/Notifications/FriendOfflineNotification.cs create mode 100644 osu.Game/Overlays/Notifications/FriendOnlineNotification.cs diff --git a/osu.Game/Online/FriendPresenceNotifier.cs b/osu.Game/Online/FriendPresenceNotifier.cs index 75b487384a..229ad4f734 100644 --- a/osu.Game/Online/FriendPresenceNotifier.cs +++ b/osu.Game/Online/FriendPresenceNotifier.cs @@ -167,7 +167,7 @@ namespace osu.Game.Online APIUser? singleUser = onlineAlertQueue.Count == 1 ? onlineAlertQueue.Single() : null; - notifications.Post(new SimpleNotification + notifications.Post(new FriendOnlineNotification { Transient = true, IsImportant = false, @@ -204,7 +204,7 @@ namespace osu.Game.Online return; } - notifications.Post(new SimpleNotification + notifications.Post(new FriendOfflineNotification { Transient = true, IsImportant = false, diff --git a/osu.Game/Overlays/Notifications/FriendOfflineNotification.cs b/osu.Game/Overlays/Notifications/FriendOfflineNotification.cs new file mode 100644 index 0000000000..147fd4ba6f --- /dev/null +++ b/osu.Game/Overlays/Notifications/FriendOfflineNotification.cs @@ -0,0 +1,10 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Overlays.Notifications +{ + public partial class FriendOfflineNotification : SimpleNotification + { + public override string PopInSampleName => "UI/notification-friend-offline"; + } +} diff --git a/osu.Game/Overlays/Notifications/FriendOnlineNotification.cs b/osu.Game/Overlays/Notifications/FriendOnlineNotification.cs new file mode 100644 index 0000000000..6a5cf3b517 --- /dev/null +++ b/osu.Game/Overlays/Notifications/FriendOnlineNotification.cs @@ -0,0 +1,10 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Overlays.Notifications +{ + public partial class FriendOnlineNotification : SimpleNotification + { + public override string PopInSampleName => "UI/notification-friend-online"; + } +} From 4c83ef83eeb9b372fdbc31a624a6688f0428dca2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Jan 2025 17:34:03 +0900 Subject: [PATCH 2/4] Update resources --- osu.Game/osu.Game.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index bfb6e51f93..bc4c42484d 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ - + From bf40f071eb0d17fa54957ac9c3436afe12749506 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Jan 2025 17:40:52 +0900 Subject: [PATCH 3/4] Code quality pass --- osu.Game/Online/FriendPresenceNotifier.cs | 89 +++++++++++-------- .../FriendOfflineNotification.cs | 10 --- .../Notifications/FriendOnlineNotification.cs | 10 --- 3 files changed, 52 insertions(+), 57 deletions(-) delete mode 100644 osu.Game/Overlays/Notifications/FriendOfflineNotification.cs delete mode 100644 osu.Game/Overlays/Notifications/FriendOnlineNotification.cs diff --git a/osu.Game/Online/FriendPresenceNotifier.cs b/osu.Game/Online/FriendPresenceNotifier.cs index 229ad4f734..70d532dfeb 100644 --- a/osu.Game/Online/FriendPresenceNotifier.cs +++ b/osu.Game/Online/FriendPresenceNotifier.cs @@ -31,15 +31,6 @@ namespace osu.Game.Online [Resolved] private MetadataClient metadataClient { get; set; } = null!; - [Resolved] - private ChannelManager channelManager { get; set; } = null!; - - [Resolved] - private ChatOverlay chatOverlay { get; set; } = null!; - - [Resolved] - private OsuColour colours { get; set; } = null!; - [Resolved] private OsuConfigManager config { get; set; } = null!; @@ -165,26 +156,7 @@ namespace osu.Game.Online return; } - APIUser? singleUser = onlineAlertQueue.Count == 1 ? onlineAlertQueue.Single() : null; - - notifications.Post(new FriendOnlineNotification - { - Transient = true, - IsImportant = false, - Icon = FontAwesome.Solid.UserPlus, - Text = $"Online: {string.Join(@", ", onlineAlertQueue.Select(u => u.Username))}", - IconColour = colours.Green, - Activated = () => - { - if (singleUser != null) - { - channelManager.OpenPrivateChannel(singleUser); - chatOverlay.Show(); - } - - return true; - } - }); + notifications.Post(new FriendOnlineNotification(onlineAlertQueue)); onlineAlertQueue.Clear(); lastOnlineAlertTime = null; @@ -204,17 +176,60 @@ namespace osu.Game.Online return; } - notifications.Post(new FriendOfflineNotification - { - Transient = true, - IsImportant = false, - Icon = FontAwesome.Solid.UserMinus, - Text = $"Offline: {string.Join(@", ", offlineAlertQueue.Select(u => u.Username))}", - IconColour = colours.Red - }); + notifications.Post(new FriendOfflineNotification(offlineAlertQueue)); offlineAlertQueue.Clear(); lastOfflineAlertTime = null; } + + public partial class FriendOnlineNotification : SimpleNotification + { + private readonly ICollection users; + + public FriendOnlineNotification(ICollection users) + { + this.users = users; + Transient = true; + IsImportant = false; + Icon = FontAwesome.Solid.User; + Text = $"Online: {string.Join(@", ", users.Select(u => u.Username))}"; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours, ChannelManager channelManager, ChatOverlay chatOverlay) + { + IconColour = colours.GrayD; + Activated = () => + { + APIUser? singleUser = users.Count == 1 ? users.Single() : null; + + if (singleUser != null) + { + channelManager.OpenPrivateChannel(singleUser); + chatOverlay.Show(); + } + + return true; + }; + } + + public override string PopInSampleName => "UI/notification-friend-online"; + } + + private partial class FriendOfflineNotification : SimpleNotification + { + public FriendOfflineNotification(ICollection users) + { + Transient = true; + IsImportant = false; + Icon = FontAwesome.Solid.UserSlash; + Text = $"Offline: {string.Join(@", ", users.Select(u => u.Username))}"; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) => IconColour = colours.Gray3; + + public override string PopInSampleName => "UI/notification-friend-offline"; + } } } diff --git a/osu.Game/Overlays/Notifications/FriendOfflineNotification.cs b/osu.Game/Overlays/Notifications/FriendOfflineNotification.cs deleted file mode 100644 index 147fd4ba6f..0000000000 --- a/osu.Game/Overlays/Notifications/FriendOfflineNotification.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -namespace osu.Game.Overlays.Notifications -{ - public partial class FriendOfflineNotification : SimpleNotification - { - public override string PopInSampleName => "UI/notification-friend-offline"; - } -} diff --git a/osu.Game/Overlays/Notifications/FriendOnlineNotification.cs b/osu.Game/Overlays/Notifications/FriendOnlineNotification.cs deleted file mode 100644 index 6a5cf3b517..0000000000 --- a/osu.Game/Overlays/Notifications/FriendOnlineNotification.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -namespace osu.Game.Overlays.Notifications -{ - public partial class FriendOnlineNotification : SimpleNotification - { - public override string PopInSampleName => "UI/notification-friend-online"; - } -} From facc9a4dc3d2e0d8b3741cddd0536e7775817d86 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 29 Jan 2025 19:15:28 +0900 Subject: [PATCH 4/4] Fix reference hashsets getting emptied before used --- osu.Game/Online/FriendPresenceNotifier.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/FriendPresenceNotifier.cs b/osu.Game/Online/FriendPresenceNotifier.cs index 70d532dfeb..a73c705d76 100644 --- a/osu.Game/Online/FriendPresenceNotifier.cs +++ b/osu.Game/Online/FriendPresenceNotifier.cs @@ -156,7 +156,7 @@ namespace osu.Game.Online return; } - notifications.Post(new FriendOnlineNotification(onlineAlertQueue)); + notifications.Post(new FriendOnlineNotification(onlineAlertQueue.ToArray())); onlineAlertQueue.Clear(); lastOnlineAlertTime = null; @@ -176,7 +176,7 @@ namespace osu.Game.Online return; } - notifications.Post(new FriendOfflineNotification(offlineAlertQueue)); + notifications.Post(new FriendOfflineNotification(offlineAlertQueue.ToArray())); offlineAlertQueue.Clear(); lastOfflineAlertTime = null;