From ec0f8142c26e9937380f43a2ab9ee456ba37f3da Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 19 Mar 2025 15:22:13 +0900 Subject: [PATCH] Add playlists/multiplayer versions of `RoomPanel` --- .../TestSceneMultiplayerMatchSubScreen.cs | 4 +- .../Visual/Multiplayer/TestSceneRoomPanel.cs | 22 ++--- .../OnlinePlay/Match/MatchRoomPanel.cs | 92 ------------------- .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 9 +- .../Multiplayer/MultiplayerRoomPanel.cs | 78 ++++++++++++++++ .../Playlists/PlaylistsRoomPanel.cs | 36 ++++++++ .../Playlists/PlaylistsRoomSubScreen.cs | 3 +- 7 files changed, 126 insertions(+), 118 deletions(-) delete mode 100644 osu.Game/Screens/OnlinePlay/Match/MatchRoomPanel.cs create mode 100644 osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomPanel.cs create mode 100644 osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPanel.cs diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs index 514d53f5ce..2c0ca1a926 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerMatchSubScreen.cs @@ -330,10 +330,10 @@ namespace osu.Game.Tests.Visual.Multiplayer AddUntilStep("wait for join", () => RoomJoined); - AddUntilStep("button visible", () => this.ChildrenOfType().Single().ChangeSettingsButton?.Alpha, () => Is.GreaterThan(0)); + AddUntilStep("button visible", () => this.ChildrenOfType().Single().ChangeSettingsButton?.Alpha, () => Is.GreaterThan(0)); AddStep("join other user", void () => MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID })); AddStep("make other user host", () => MultiplayerClient.TransferHost(PLAYER_1_ID)); - AddAssert("button hidden", () => this.ChildrenOfType().Single().ChangeSettingsButton?.Alpha, () => Is.EqualTo(0)); + AddAssert("button hidden", () => this.ChildrenOfType().Single().ChangeSettingsButton?.Alpha, () => Is.EqualTo(0)); } private partial class TestMultiplayerMatchSubScreen : MultiplayerMatchSubScreen diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs index 9c8f9e3574..fee5e62958 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs @@ -18,6 +18,7 @@ using osu.Game.Overlays; using osu.Game.Rulesets.Osu; using osu.Game.Screens.OnlinePlay.Lounge; using osu.Game.Screens.OnlinePlay.Lounge.Components; +using osu.Game.Screens.OnlinePlay.Multiplayer; using osu.Game.Tests.Beatmaps; using osuTK; @@ -159,33 +160,24 @@ namespace osu.Game.Tests.Visual.Multiplayer Spacing = new Vector2(5), Children = new[] { - new MatchRoomPanel(new Room + new MultiplayerRoomPanel(new Room { Name = "A host-only room", QueueMode = QueueMode.HostOnly, Type = MatchType.HeadToHead, - }) - { - SelectedItem = new Bindable() - }, - new MatchRoomPanel(new Room + }), + new MultiplayerRoomPanel(new Room { Name = "An all-players, team-versus room", QueueMode = QueueMode.AllPlayers, Type = MatchType.TeamVersus - }) - { - SelectedItem = new Bindable() - }, - new MatchRoomPanel(new Room + }), + new MultiplayerRoomPanel(new Room { Name = "A round-robin room", QueueMode = QueueMode.AllPlayersRoundRobin, Type = MatchType.HeadToHead - }) - { - SelectedItem = new Bindable() - }, + }), } }); } diff --git a/osu.Game/Screens/OnlinePlay/Match/MatchRoomPanel.cs b/osu.Game/Screens/OnlinePlay/Match/MatchRoomPanel.cs deleted file mode 100644 index 861cccde7b..0000000000 --- a/osu.Game/Screens/OnlinePlay/Match/MatchRoomPanel.cs +++ /dev/null @@ -1,92 +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 System.ComponentModel; -using osu.Framework.Allocation; -using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Game.Beatmaps.Drawables; -using osu.Game.Online.API; -using osu.Game.Online.Rooms; -using osu.Game.Screens.OnlinePlay.Lounge.Components; -using osu.Game.Screens.OnlinePlay.Match.Components; -using osuTK; - -namespace osu.Game.Screens.OnlinePlay.Match -{ - public partial class MatchRoomPanel : RoomPanel - { - public Action? OnEdit; - - public new required Bindable SelectedItem - { - get => selectedItem; - set => selectedItem.Current = value; - } - - public Drawable? ChangeSettingsButton { get; private set; } - - [Resolved] - private IAPIProvider api { get; set; } = null!; - - private readonly BindableWithCurrent selectedItem = new BindableWithCurrent(); - private readonly bool allowEdit; - - public MatchRoomPanel(Room room, bool allowEdit = true) - : base(room) - { - this.allowEdit = allowEdit; - - base.SelectedItem.BindTo(SelectedItem); - } - - [BackgroundDependencyLoader] - private void load() - { - if (allowEdit) - { - ButtonsContainer.Add(ChangeSettingsButton = new PurpleRoundedButton - { - RelativeSizeAxes = Axes.Y, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(120, 0.7f), - Text = "Change settings", - Action = () => OnEdit?.Invoke() - }); - } - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - Room.PropertyChanged += onRoomPropertyChanged; - updateRoomHost(); - } - - private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(Room.Host)) - updateRoomHost(); - } - - private void updateRoomHost() - { - if (ChangeSettingsButton != null) - ChangeSettingsButton.Alpha = Room.Host?.Equals(api.LocalUser.Value) == true ? 1 : 0; - } - - protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d => - { - d.BackgroundLoadDelay = 0; - }); - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - Room.PropertyChanged -= onRoomPropertyChanged; - } - } -} diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index 6603cd5692..c9248449d3 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -100,7 +100,6 @@ namespace osu.Game.Screens.OnlinePlay.Match protected IBindable BeatmapAvailability => beatmapAvailabilityTracker.Availability; public readonly Room Room; - private readonly bool allowEdit; internal ModSelectOverlay UserModsSelectOverlay { get; private set; } = null!; @@ -112,12 +111,9 @@ namespace osu.Game.Screens.OnlinePlay.Match /// Creates a new . /// /// The . - /// Whether to allow editing room settings post-creation. - protected RoomSubScreen(Room room, bool allowEdit = true) + protected RoomSubScreen(Room room) { Room = room; - this.allowEdit = allowEdit; - Padding = new MarginPadding { Top = Header.HEIGHT }; } @@ -172,10 +168,9 @@ namespace osu.Game.Screens.OnlinePlay.Match { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Child = new MatchRoomPanel(Room, allowEdit) + Child = new MultiplayerRoomPanel(Room) { OnEdit = () => settingsOverlay.Show(), - SelectedItem = SelectedItem } } }, diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomPanel.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomPanel.cs new file mode 100644 index 0000000000..e52133b46b --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomPanel.cs @@ -0,0 +1,78 @@ +// 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 osu.Framework.Allocation; +using osu.Framework.Extensions.ObjectExtensions; +using osu.Framework.Graphics; +using osu.Game.Beatmaps.Drawables; +using osu.Game.Online.Multiplayer; +using osu.Game.Online.Rooms; +using osu.Game.Screens.OnlinePlay.Lounge.Components; +using osu.Game.Screens.OnlinePlay.Match.Components; +using osuTK; + +namespace osu.Game.Screens.OnlinePlay.Multiplayer +{ + /// + /// A to be displayed in a multiplayer lobby. + /// + public partial class MultiplayerRoomPanel : RoomPanel + { + public Action? OnEdit { get; set; } + + public Drawable ChangeSettingsButton { get; private set; } = null!; + + [Resolved] + private MultiplayerClient client { get; set; } = null!; + + public MultiplayerRoomPanel(Room room) + : base(room) + { + } + + [BackgroundDependencyLoader] + private void load() + { + ButtonsContainer.Add(ChangeSettingsButton = new PurpleRoundedButton + { + RelativeSizeAxes = Axes.Y, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(120, 0.7f), + Text = "Change settings", + Action = () => OnEdit?.Invoke() + }); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + client.RoomUpdated += onRoomUpdated; + onRoomUpdated(); + } + + private void onRoomUpdated() => Scheduler.AddOnce(() => + { + if (client.Room == null || client.LocalUser == null) + return; + + ChangeSettingsButton.Alpha = client.IsHost ? 1 : 0; + SelectedItem.Value = new PlaylistItem(client.Room.CurrentPlaylistItem); + }); + + protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d => + { + d.BackgroundLoadDelay = 0; + }); + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (client.IsNotNull()) + client.RoomUpdated -= onRoomUpdated; + } + } +} diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPanel.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPanel.cs new file mode 100644 index 0000000000..d6c0f4dcbc --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomPanel.cs @@ -0,0 +1,36 @@ +// 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.Bindables; +using osu.Framework.Graphics; +using osu.Game.Beatmaps.Drawables; +using osu.Game.Online.Rooms; +using osu.Game.Screens.OnlinePlay.Lounge.Components; + +namespace osu.Game.Screens.OnlinePlay.Playlists +{ + /// + /// A to be displayed in a playlists lobby. + /// + public partial class PlaylistsRoomPanel : RoomPanel + { + public new required Bindable SelectedItem + { + get => selectedItem.Current; + set => selectedItem.Current = value; + } + + private readonly BindableWithCurrent selectedItem = new BindableWithCurrent(); + + public PlaylistsRoomPanel(Room room) + : base(room) + { + base.SelectedItem.BindTo(SelectedItem); + } + + protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d => + { + d.BackgroundLoadDelay = 0; + }); + } +} diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs index d69c6edff3..c7b4d686dd 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs @@ -186,9 +186,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists { new Drawable[] { - new MatchRoomPanel(room, false) + new PlaylistsRoomPanel(room) { - OnEdit = () => settingsOverlay.Show(), SelectedItem = SelectedItem } },