From 82a63228de1984249136d9593405921127346d69 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 22 Nov 2024 20:40:01 +0900 Subject: [PATCH 1/7] Improve handling of multiplayer room status --- .../Multiplayer/TestSceneDrawableRoom.cs | 16 ++++---- .../TestScenePlaylistsRoomSubScreen.cs | 41 ------------------- osu.Game/Graphics/OsuColour.cs | 21 ++++++++++ .../Online/Multiplayer/MultiplayerClient.cs | 10 ++--- osu.Game/Online/Rooms/Room.cs | 21 ++-------- osu.Game/Online/Rooms/RoomStatus.cs | 14 ++----- .../Rooms/RoomStatuses/RoomStatusEnded.cs | 14 ------- .../Rooms/RoomStatuses/RoomStatusOpen.cs | 14 ------- .../RoomStatuses/RoomStatusOpenPrivate.cs | 14 ------- .../Rooms/RoomStatuses/RoomStatusPlaying.cs | 14 ------- .../Components/StatusColouredContainer.cs | 15 +++++-- .../Lounge/Components/RoomStatusPill.cs | 24 +++++++++-- .../Multiplayer/MultiplayerRoomManager.cs | 3 +- 13 files changed, 74 insertions(+), 147 deletions(-) delete mode 100644 osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomSubScreen.cs delete mode 100644 osu.Game/Online/Rooms/RoomStatuses/RoomStatusEnded.cs delete mode 100644 osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpen.cs delete mode 100644 osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpenPrivate.cs delete mode 100644 osu.Game/Online/Rooms/RoomStatuses/RoomStatusPlaying.cs diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs index e5938a796c..abfe613b65 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs @@ -14,7 +14,6 @@ using osu.Game.Graphics.Sprites; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Overlays; using osu.Game.Rulesets.Osu; using osu.Game.Screens.OnlinePlay.Lounge; @@ -76,7 +75,6 @@ namespace osu.Game.Tests.Visual.Multiplayer createLoungeRoom(new Room { Name = "Multiplayer room", - Status = new RoomStatusOpen(), EndDate = DateTimeOffset.Now.AddDays(1), Type = MatchType.HeadToHead, Playlist = [item1], @@ -85,7 +83,6 @@ namespace osu.Game.Tests.Visual.Multiplayer createLoungeRoom(new Room { Name = "Private room", - Status = new RoomStatusOpenPrivate(), Password = "*", EndDate = DateTimeOffset.Now.AddDays(1), Type = MatchType.HeadToHead, @@ -95,27 +92,29 @@ namespace osu.Game.Tests.Visual.Multiplayer createLoungeRoom(new Room { Name = "Playlist room with multiple beatmaps", - Status = new RoomStatusPlaying(), + Status = RoomStatus.Playing, EndDate = DateTimeOffset.Now.AddDays(1), Playlist = [item1, item2], CurrentPlaylistItem = item1 }), createLoungeRoom(new Room { - Name = "Finished room", - Status = new RoomStatusEnded(), + Name = "Closing soon", + EndDate = DateTimeOffset.Now.AddSeconds(5), + }), + createLoungeRoom(new Room + { + Name = "Closed room", EndDate = DateTimeOffset.Now, }), createLoungeRoom(new Room { Name = "Spotlight room", - Status = new RoomStatusOpen(), Category = RoomCategory.Spotlight, }), createLoungeRoom(new Room { Name = "Featured artist room", - Status = new RoomStatusOpen(), Category = RoomCategory.FeaturedArtist, }), } @@ -136,7 +135,6 @@ namespace osu.Game.Tests.Visual.Multiplayer AddStep("create room", () => Child = drawableRoom = createLoungeRoom(room = new Room { Name = "Room with password", - Status = new RoomStatusOpen(), Type = MatchType.HeadToHead, })); diff --git a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomSubScreen.cs b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomSubScreen.cs deleted file mode 100644 index 4306fc1e6a..0000000000 --- a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomSubScreen.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using NUnit.Framework; -using osu.Framework.Screens; -using osu.Game.Online.API.Requests.Responses; -using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; -using osu.Game.Screens.OnlinePlay.Playlists; -using osu.Game.Tests.Visual.OnlinePlay; - -namespace osu.Game.Tests.Visual.Playlists -{ - public partial class TestScenePlaylistsRoomSubScreen : OnlinePlayTestScene - { - protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager; - - [Test] - public void TestStatusUpdateOnEnter() - { - Room room = null!; - PlaylistsRoomSubScreen roomScreen = null!; - - AddStep("create room", () => - { - RoomManager.AddRoom(room = new Room - { - Name = @"Test Room", - Host = new APIUser { Username = @"Host" }, - Category = RoomCategory.Normal, - EndDate = DateTimeOffset.Now.AddMinutes(-1) - }); - }); - - AddStep("push screen", () => LoadScreen(roomScreen = new PlaylistsRoomSubScreen(room))); - AddUntilStep("wait for screen load", () => roomScreen.IsCurrentScreen()); - AddAssert("status is still ended", () => roomScreen.Room.Status, Is.TypeOf); - } - } -} diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index c479d0cfe4..20e65323f8 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -195,6 +195,27 @@ namespace osu.Game.Graphics } } + /// + /// Retrieves the accent colour representing a 's current status. + /// + public Color4 ForRoomStatus(Room room) + { + if (DateTimeOffset.Now >= room.EndDate) + return YellowDarker; + + switch (room.Status) + { + case RoomStatus.Playing: + return Purple; + + default: + if (room.HasPassword) + return GreenDark; + + return GreenLight; + } + } + /// /// Retrieves colour for a . /// See https://www.figma.com/file/YHWhp9wZ089YXgB7pe6L1k/Tier-Colours diff --git a/osu.Game/Online/Multiplayer/MultiplayerClient.cs b/osu.Game/Online/Multiplayer/MultiplayerClient.cs index 998a34931d..4a28124583 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs @@ -18,7 +18,6 @@ using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer.Countdown; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; @@ -395,15 +394,17 @@ namespace osu.Game.Online.Multiplayer switch (state) { case MultiplayerRoomState.Open: - APIRoom.Status = APIRoom.HasPassword ? new RoomStatusOpenPrivate() : new RoomStatusOpen(); + APIRoom.Status = RoomStatus.Idle; break; + case MultiplayerRoomState.WaitingForLoad: case MultiplayerRoomState.Playing: - APIRoom.Status = new RoomStatusPlaying(); + APIRoom.Status = RoomStatus.Playing; break; case MultiplayerRoomState.Closed: - APIRoom.Status = new RoomStatusEnded(); + APIRoom.EndDate = DateTimeOffset.Now; + APIRoom.Status = RoomStatus.Idle; break; } @@ -821,7 +822,6 @@ namespace osu.Game.Online.Multiplayer Room.Settings = settings; APIRoom.Name = Room.Settings.Name; APIRoom.Password = Room.Settings.Password; - APIRoom.Status = string.IsNullOrEmpty(Room.Settings.Password) ? new RoomStatusOpen() : new RoomStatusOpenPrivate(); APIRoom.Type = Room.Settings.MatchType; APIRoom.QueueMode = Room.Settings.QueueMode; APIRoom.AutoStartDuration = Room.Settings.AutoStartDuration; diff --git a/osu.Game/Online/Rooms/Room.cs b/osu.Game/Online/Rooms/Room.cs index e1813c7e4e..6e073bdcd7 100644 --- a/osu.Game/Online/Rooms/Room.cs +++ b/osu.Game/Online/Rooms/Room.cs @@ -6,12 +6,10 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; -using System.Runtime.Serialization; using Newtonsoft.Json; using osu.Game.IO.Serialization.Converters; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer; -using osu.Game.Online.Rooms.RoomStatuses; namespace osu.Game.Online.Rooms { @@ -248,7 +246,7 @@ namespace osu.Game.Online.Rooms } /// - /// The current room status. + /// The current status of the room. /// public RoomStatus Status { @@ -265,18 +263,6 @@ namespace osu.Game.Online.Rooms set => SetField(ref availability, value); } - [OnDeserialized] - private void onDeserialised(StreamingContext context) - { - // API doesn't populate status so let's do it here. - if (EndDate != null && DateTimeOffset.Now >= EndDate) - Status = new RoomStatusEnded(); - else if (HasPassword) - Status = new RoomStatusOpenPrivate(); - else - Status = new RoomStatusOpen(); - } - [JsonProperty("id")] private long? roomId; @@ -349,8 +335,9 @@ namespace osu.Game.Online.Rooms [JsonProperty("channel_id")] private int channelId; - // Not serialised (see: GetRoomsRequest). - private RoomStatus status = new RoomStatusOpen(); + [JsonProperty("status")] + [JsonConverter(typeof(SnakeCaseStringEnumConverter))] + private RoomStatus status; // Not yet serialised (not implemented). private RoomAvailability availability; diff --git a/osu.Game/Online/Rooms/RoomStatus.cs b/osu.Game/Online/Rooms/RoomStatus.cs index 4b890b00b7..d048486f19 100644 --- a/osu.Game/Online/Rooms/RoomStatus.cs +++ b/osu.Game/Online/Rooms/RoomStatus.cs @@ -1,19 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using osu.Game.Graphics; -using osuTK.Graphics; - namespace osu.Game.Online.Rooms { - public abstract class RoomStatus + public enum RoomStatus { - public abstract string Message { get; } - public abstract Color4 GetAppropriateColour(OsuColour colours); - - public override int GetHashCode() => GetType().GetHashCode(); - public override bool Equals(object obj) => GetType() == obj?.GetType(); + Idle, + Playing, } } diff --git a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusEnded.cs b/osu.Game/Online/Rooms/RoomStatuses/RoomStatusEnded.cs deleted file mode 100644 index 0fc27d26b8..0000000000 --- a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusEnded.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Graphics; -using osuTK.Graphics; - -namespace osu.Game.Online.Rooms.RoomStatuses -{ - public class RoomStatusEnded : RoomStatus - { - public override string Message => "Ended"; - public override Color4 GetAppropriateColour(OsuColour colours) => colours.YellowDarker; - } -} diff --git a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpen.cs b/osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpen.cs deleted file mode 100644 index 5cc664cf36..0000000000 --- a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpen.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Graphics; -using osuTK.Graphics; - -namespace osu.Game.Online.Rooms.RoomStatuses -{ - public class RoomStatusOpen : RoomStatus - { - public override string Message => "Open"; - public override Color4 GetAppropriateColour(OsuColour colours) => colours.GreenLight; - } -} diff --git a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpenPrivate.cs b/osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpenPrivate.cs deleted file mode 100644 index d71e706c76..0000000000 --- a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusOpenPrivate.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Graphics; -using osuTK.Graphics; - -namespace osu.Game.Online.Rooms.RoomStatuses -{ - public class RoomStatusOpenPrivate : RoomStatus - { - public override string Message => "Open (Private)"; - public override Color4 GetAppropriateColour(OsuColour colours) => colours.GreenDark; - } -} diff --git a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusPlaying.cs b/osu.Game/Online/Rooms/RoomStatuses/RoomStatusPlaying.cs deleted file mode 100644 index 4d0c93b8ab..0000000000 --- a/osu.Game/Online/Rooms/RoomStatuses/RoomStatusPlaying.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Graphics; -using osuTK.Graphics; - -namespace osu.Game.Online.Rooms.RoomStatuses -{ - public class RoomStatusPlaying : RoomStatus - { - public override string Message => "Playing"; - public override Color4 GetAppropriateColour(OsuColour colours) => colours.Purple; - } -} diff --git a/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs b/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs index 2b1233506f..a811ee3371 100644 --- a/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs +++ b/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs @@ -29,18 +29,27 @@ namespace osu.Game.Screens.OnlinePlay.Components base.LoadComplete(); room.PropertyChanged += onRoomPropertyChanged; + + Scheduler.AddDelayed(updateRoomStatus, 5000, true); updateRoomStatus(); } private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName == nameof(Room.Status)) - updateRoomStatus(); + switch (e.PropertyName) + { + case nameof(Room.Category): + case nameof(Room.Status): + case nameof(Room.EndDate): + case nameof(Room.HasPassword): + updateRoomStatus(); + break; + } } private void updateRoomStatus() { - this.FadeColour(colours.ForRoomCategory(room.Category) ?? room.Status.GetAppropriateColour(colours), transitionDuration); + this.FadeColour(colours.ForRoomCategory(room.Category) ?? colours.ForRoomStatus(room), transitionDuration); } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs index b3dc617fd6..cc495d19d6 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.ComponentModel; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -35,8 +36,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components Pill.Background.Alpha = 1; room.PropertyChanged += onRoomPropertyChanged; - updateDisplay(); + Scheduler.AddDelayed(updateDisplay, 5000, true); + updateDisplay(); FinishTransforms(true); } @@ -46,6 +48,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components { case nameof(Room.Status): case nameof(Room.EndDate): + case nameof(Room.HasPassword): updateDisplay(); break; } @@ -53,8 +56,23 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components private void updateDisplay() { - Pill.Background.FadeColour(room.Status.GetAppropriateColour(colours), 100); - TextFlow.Text = room.Status.Message; + Pill.Background.FadeColour(colours.ForRoomStatus(room), 100); + + if (DateTimeOffset.Now >= room.EndDate) + TextFlow.Text = "Ended"; + else + { + switch (room.Status) + { + case RoomStatus.Playing: + TextFlow.Text = "Playing"; + break; + + default: + TextFlow.Text = room.HasPassword ? "Open (Private)" : "Open"; + break; + } + } } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs index e16582a6e1..b6f4b0e8d9 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs @@ -8,7 +8,6 @@ using osu.Framework.Extensions.ExceptionExtensions; using osu.Framework.Logging; using osu.Game.Online.Multiplayer; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Screens.OnlinePlay.Components; namespace osu.Game.Screens.OnlinePlay.Multiplayer @@ -31,7 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer // this is done here as a pre-check to avoid clicking on already closed rooms in the lounge from triggering a server join. // should probably be done at a higher level, but due to the current structure of things this is the easiest place for now. - if (room.Status is RoomStatusEnded) + if (DateTimeOffset.Now >= room.EndDate) { onError?.Invoke("Cannot join an ended room."); return; From 5ebaab7e9aafcd2c220bbc737c1f5354a217dc11 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 22 Nov 2024 21:04:57 +0900 Subject: [PATCH 2/7] Add localisation --- .../Localisation/RoomStatusPillStrings.cs | 34 +++++++++++++++++++ .../Lounge/Components/RoomStatusPill.cs | 7 ++-- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Localisation/RoomStatusPillStrings.cs diff --git a/osu.Game/Localisation/RoomStatusPillStrings.cs b/osu.Game/Localisation/RoomStatusPillStrings.cs new file mode 100644 index 0000000000..5b4aa776ab --- /dev/null +++ b/osu.Game/Localisation/RoomStatusPillStrings.cs @@ -0,0 +1,34 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Localisation; + +namespace osu.Game.Localisation +{ + public static class RoomStatusPillStrings + { + private const string prefix = @"osu.Game.Resources.Localisation.RoomStatusPill"; + + /// + /// "Ended" + /// + public static LocalisableString Ended => new TranslatableString(getKey(@"ended"), @"Ended"); + + /// + /// "Playing" + /// + public static LocalisableString Playing => new TranslatableString(getKey(@"playing"), @"Playing"); + + /// + /// "Open (Private)" + /// + public static LocalisableString OpenPrivate => new TranslatableString(getKey(@"open_private"), @"Open (Private)"); + + /// + /// "Open" + /// + public static LocalisableString Open => new TranslatableString(getKey(@"open"), @"Open"); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} \ No newline at end of file diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs index cc495d19d6..5d2c4b28e6 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Online.Rooms; +using osu.Game.Localisation; namespace osu.Game.Screens.OnlinePlay.Lounge.Components { @@ -59,17 +60,17 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components Pill.Background.FadeColour(colours.ForRoomStatus(room), 100); if (DateTimeOffset.Now >= room.EndDate) - TextFlow.Text = "Ended"; + TextFlow.Text = RoomStatusPillStrings.Ended; else { switch (room.Status) { case RoomStatus.Playing: - TextFlow.Text = "Playing"; + TextFlow.Text = RoomStatusPillStrings.Playing; break; default: - TextFlow.Text = room.HasPassword ? "Open (Private)" : "Open"; + TextFlow.Text = room.HasPassword ? RoomStatusPillStrings.OpenPrivate : RoomStatusPillStrings.Open; break; } } From 1b8db7cfd6c7fc094c6c1367bd3a2c267f7b4947 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 22 Nov 2024 21:27:44 +0900 Subject: [PATCH 3/7] Fix test --- osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs index abfe613b65..021c0abf1d 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs @@ -121,9 +121,9 @@ namespace osu.Game.Tests.Visual.Multiplayer }; }); - AddUntilStep("wait for panel load", () => rooms.Count == 6); + AddUntilStep("wait for panel load", () => rooms.Count == 7); AddUntilStep("correct status text", () => rooms.ChildrenOfType().Count(s => s.Text.ToString().StartsWith("Currently playing", StringComparison.Ordinal)) == 2); - AddUntilStep("correct status text", () => rooms.ChildrenOfType().Count(s => s.Text.ToString().StartsWith("Ready to play", StringComparison.Ordinal)) == 4); + AddUntilStep("correct status text", () => rooms.ChildrenOfType().Count(s => s.Text.ToString().StartsWith("Ready to play", StringComparison.Ordinal)) == 5); } [Test] From af0c6fc51b7f5faf9f5ff9ba01e692c8b03a5808 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 26 Nov 2024 21:06:08 +0900 Subject: [PATCH 4/7] Add `Room.HasEnded` helper method --- osu.Game/Graphics/OsuColour.cs | 2 +- osu.Game/Online/Rooms/Room.cs | 9 +++++++++ .../OnlinePlay/Lounge/Components/RoomStatusPill.cs | 2 +- .../OnlinePlay/Multiplayer/MultiplayerRoomManager.cs | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index 20e65323f8..2c43876fb2 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -200,7 +200,7 @@ namespace osu.Game.Graphics /// public Color4 ForRoomStatus(Room room) { - if (DateTimeOffset.Now >= room.EndDate) + if (room.HasEnded) return YellowDarker; switch (room.Status) diff --git a/osu.Game/Online/Rooms/Room.cs b/osu.Game/Online/Rooms/Room.cs index 6e073bdcd7..897ba6bd70 100644 --- a/osu.Game/Online/Rooms/Room.cs +++ b/osu.Game/Online/Rooms/Room.cs @@ -374,6 +374,15 @@ namespace osu.Game.Online.Rooms RecentParticipants = other.RecentParticipants; } + /// + /// Whether the room is no longer available. + /// + /// + /// This property does not update in real-time and needs to be queried periodically. + /// Subscribe to to be notified of any immediate changes. + /// + public bool HasEnded => DateTimeOffset.Now >= EndDate; + [JsonObject(MemberSerialization.OptIn)] public class RoomPlaylistItemStats { diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs index 5d2c4b28e6..32d0add5fd 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs @@ -59,7 +59,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components { Pill.Background.FadeColour(colours.ForRoomStatus(room), 100); - if (DateTimeOffset.Now >= room.EndDate) + if (room.HasEnded) TextFlow.Text = RoomStatusPillStrings.Ended; else { diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs index b6f4b0e8d9..7f09c9cbe9 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs @@ -30,7 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer // this is done here as a pre-check to avoid clicking on already closed rooms in the lounge from triggering a server join. // should probably be done at a higher level, but due to the current structure of things this is the easiest place for now. - if (DateTimeOffset.Now >= room.EndDate) + if (room.HasEnded) { onError?.Invoke("Cannot join an ended room."); return; From 4c7976bb9305c1e7b7b1f075ff194449d6e4b3f0 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 26 Nov 2024 21:11:48 +0900 Subject: [PATCH 5/7] Remove unused using --- osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs index 32d0add5fd..6da8f3ecbd 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.ComponentModel; using osu.Framework.Allocation; using osu.Framework.Graphics; From 0aa17a905b45dcc55e7444722b8593e2957b365f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 11 Dec 2024 18:08:34 +0900 Subject: [PATCH 6/7] Increase timed update frequency and add inline comment --- .../Screens/OnlinePlay/Components/StatusColouredContainer.cs | 3 ++- .../Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs b/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs index a811ee3371..7147803412 100644 --- a/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs +++ b/osu.Game/Screens/OnlinePlay/Components/StatusColouredContainer.cs @@ -30,7 +30,8 @@ namespace osu.Game.Screens.OnlinePlay.Components room.PropertyChanged += onRoomPropertyChanged; - Scheduler.AddDelayed(updateRoomStatus, 5000, true); + // Timed update required to track rooms which have hit the end time, see `HasEnded`. + Scheduler.AddDelayed(updateRoomStatus, 1000, true); updateRoomStatus(); } diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs index 6da8f3ecbd..092f17a643 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs @@ -37,7 +37,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components room.PropertyChanged += onRoomPropertyChanged; - Scheduler.AddDelayed(updateDisplay, 5000, true); + // Timed update required to track rooms which have hit the end time, see `HasEnded`. + Scheduler.AddDelayed(updateDisplay, 1000, true); updateDisplay(); FinishTransforms(true); } From e8c0e27cc0e826d18e60abd3b665c56d6d3c2964 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 11 Dec 2024 18:17:59 +0900 Subject: [PATCH 7/7] Adjust in line with upstream changes --- osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs | 3 +-- .../Screens/OnlinePlay/Playlists/PlaylistsRoomFooter.cs | 3 +-- .../Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs | 7 +------ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs b/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs index 7d36cec7ba..0a55472c2d 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/DrawableLoungeRoom.cs @@ -26,7 +26,6 @@ using osu.Game.Input.Bindings; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Overlays; using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Lounge.Components; @@ -168,7 +167,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge }) }; - if (Room.Type == MatchType.Playlists && Room.Host?.Id == api.LocalUser.Value.Id && Room.StartDate?.AddMinutes(5) >= DateTimeOffset.Now && Room.Status is not RoomStatusEnded) + if (Room.Type == MatchType.Playlists && Room.Host?.Id == api.LocalUser.Value.Id && Room.StartDate?.AddMinutes(5) >= DateTimeOffset.Now && !Room.HasEnded) { items.Add(new OsuMenuItem("Close playlist", MenuItemType.Destructive, () => { diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFooter.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFooter.cs index 6089b4734e..f9b1edcd59 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFooter.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFooter.cs @@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; using osuTK; namespace osu.Game.Screens.OnlinePlay.Playlists @@ -99,7 +98,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists if (room.Host?.Id == api.LocalUser.Value.Id) { - if (deletionGracePeriodRemaining > TimeSpan.Zero && room.Status is not RoomStatusEnded) + if (deletionGracePeriodRemaining > TimeSpan.Zero && !room.HasEnded) { closeButton.FadeIn(); using (BeginDelayedSequence(deletionGracePeriodRemaining.Value.TotalMilliseconds)) diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs index 9573155f5a..9b4630ac0b 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs @@ -16,7 +16,6 @@ using osu.Game.Input; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.Rooms; -using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Match; using osu.Game.Screens.OnlinePlay.Match.Components; @@ -286,11 +285,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists DialogOverlay?.Push(new ClosePlaylistDialog(Room, () => { var request = new ClosePlaylistRequest(Room.RoomID!.Value); - request.Success += () => - { - Room.Status = new RoomStatusEnded(); - Room.EndDate = DateTimeOffset.UtcNow; - }; + request.Success += () => Room.EndDate = DateTimeOffset.UtcNow; API.Queue(request); })); }