From 54c2d4207fae1bb50d373f686130d40321dd459e Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Tue, 24 Jun 2025 14:11:27 +0300 Subject: [PATCH 1/5] Add link button to multiplayer/playlists room panels --- .../OnlinePlay/Lounge/Components/RoomPanel.cs | 37 +++++++++++++++++-- .../OnlinePlay/Lounge/LoungeRoomPanel.cs | 1 + 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs index acbf5d8462..b94cfb8de7 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs @@ -54,11 +54,15 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components protected readonly Bindable SelectedItem = new Bindable(); protected Container ButtonsContainer { get; private set; } = null!; + protected bool ShowExternalLink { get; init; } = true; + private DrawableRoomParticipantsList? drawableRoomParticipantsList; private RoomSpecialCategoryPill? specialCategoryPill; private PasswordProtectedIcon? passwordIcon; private EndDateInfo? endDateInfo; + private FillFlowContainer? roomNameFlow; private SpriteText? roomName; + private ExternalLinkButton? linkButton; private DelayedLoadWrapper wrapper = null!; private CancellationTokenSource? beatmapLookupCancellation; @@ -204,10 +208,27 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components Direction = FillDirection.Vertical, Children = new Drawable[] { - roomName = new TruncatingSpriteText + roomNameFlow = new FillFlowContainer { RelativeSizeAxes = Axes.X, - Font = OsuFont.GetFont(size: 28) + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Horizontal, + Children = new Drawable[] + { + roomName = new TruncatingSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Font = OsuFont.GetFont(size: 28), + }, + linkButton = new ExternalLinkButton(formatRoomUrl(Room.RoomID ?? 0)) + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Horizontal = 6, Bottom = 4 }, + Alpha = ShowExternalLink && Room.RoomID.HasValue ? 1 : 0, + }, + }, }, new RoomStatusText(Room) { @@ -288,6 +309,14 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components SelectedItem.BindValueChanged(onSelectedItemChanged, true); } + protected override void Update() + { + base.Update(); + + if (roomName != null) + roomName.MaxWidth = (roomNameFlow?.DrawWidth ?? 0) - (linkButton?.LayoutSize.X ?? 0); + } + private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) @@ -390,11 +419,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components } return items.ToArray(); - - string formatRoomUrl(long id) => $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{id}"; } } + private string formatRoomUrl(long id) => $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{id}"; + protected virtual UpdateableBeatmapBackgroundSprite CreateBackground() => new UpdateableBeatmapBackgroundSprite(); protected virtual IEnumerable CreateBottomDetails() diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeRoomPanel.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeRoomPanel.cs index 3ff27a14bb..12b38a9677 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/LoungeRoomPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeRoomPanel.cs @@ -67,6 +67,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge public LoungeRoomPanel(Room room) : base(room) { + ShowExternalLink = false; } [BackgroundDependencyLoader] From d888572f7f9bab6fdcfe7708b8a66ae469e59f0d Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Wed, 25 Jun 2025 08:23:47 +0300 Subject: [PATCH 2/5] Move room name line to own component Fixes test failure caused by accessing components loaded asynchronously, see https://github.com/ppy/osu/actions/runs/15848940420/job/44677458262?pr=33858. --- .../OnlinePlay/Lounge/Components/RoomPanel.cs | 94 ++++++++++++------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs index b94cfb8de7..7a4279ef98 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs @@ -17,6 +17,7 @@ using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; using osu.Game.Database; @@ -60,9 +61,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components private RoomSpecialCategoryPill? specialCategoryPill; private PasswordProtectedIcon? passwordIcon; private EndDateInfo? endDateInfo; - private FillFlowContainer? roomNameFlow; - private SpriteText? roomName; - private ExternalLinkButton? linkButton; + private RoomNameLine? roomName; private DelayedLoadWrapper wrapper = null!; private CancellationTokenSource? beatmapLookupCancellation; @@ -208,28 +207,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components Direction = FillDirection.Vertical, Children = new Drawable[] { - roomNameFlow = new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Horizontal, - Children = new Drawable[] - { - roomName = new TruncatingSpriteText - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Font = OsuFont.GetFont(size: 28), - }, - linkButton = new ExternalLinkButton(formatRoomUrl(Room.RoomID ?? 0)) - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Margin = new MarginPadding { Horizontal = 6, Bottom = 4 }, - Alpha = ShowExternalLink && Room.RoomID.HasValue ? 1 : 0, - }, - }, - }, + roomName = new RoomNameLine(getRoomUrl(), ShowExternalLink), new RoomStatusText(Room) { Beatmap = { BindTarget = currentBeatmap } @@ -309,14 +287,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components SelectedItem.BindValueChanged(onSelectedItemChanged, true); } - protected override void Update() - { - base.Update(); - - if (roomName != null) - roomName.MaxWidth = (roomNameFlow?.DrawWidth ?? 0) - (linkButton?.LayoutSize.X ?? 0); - } - private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) @@ -413,8 +383,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components if (Room.RoomID.HasValue) { items.AddRange([ - new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(formatRoomUrl(Room.RoomID.Value))), - new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyToClipboard(formatRoomUrl(Room.RoomID.Value))) + new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(getRoomUrl())), + new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyToClipboard(getRoomUrl())) ]); } @@ -422,7 +392,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components } } - private string formatRoomUrl(long id) => $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{id}"; + private string? getRoomUrl() => !Room.RoomID.HasValue ? null : $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{Room.RoomID.Value}"; protected virtual UpdateableBeatmapBackgroundSprite CreateBackground() => new UpdateableBeatmapBackgroundSprite(); @@ -585,5 +555,57 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components }; } } + + public partial class RoomNameLine : FillFlowContainer + { + private readonly string? roomUrl; + private readonly bool showExternalLink; + + private TruncatingSpriteText spriteText = null!; + private ExternalLinkButton link = null!; + + public LocalisableString Text + { + get => spriteText.Text; + set => spriteText.Text = value; + } + + public RoomNameLine(string? roomUrl, bool showExternalLink) + { + this.roomUrl = roomUrl; + this.showExternalLink = showExternalLink; + } + + [BackgroundDependencyLoader] + private void load() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + Direction = FillDirection.Horizontal; + + Children = new Drawable[] + { + spriteText = new TruncatingSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Font = OsuFont.GetFont(size: 28), + }, + link = new ExternalLinkButton(roomUrl) + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Horizontal = 6, Bottom = 4 }, + Alpha = showExternalLink ? 1 : 0, + }, + }; + } + + protected override void Update() + { + base.Update(); + spriteText.MaxWidth = DrawWidth - link.LayoutSize.X; + } + } } } From 75a3cdcfe2ed730be99f576275d42541cb60206e Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Thu, 26 Jun 2025 02:56:43 +0300 Subject: [PATCH 3/5] Move room URL formatting to extension method --- osu.Game/Online/Rooms/RoomExtensions.cs | 21 +++++++++++++++++++ .../OnlinePlay/Lounge/Components/RoomPanel.cs | 10 ++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 osu.Game/Online/Rooms/RoomExtensions.cs diff --git a/osu.Game/Online/Rooms/RoomExtensions.cs b/osu.Game/Online/Rooms/RoomExtensions.cs new file mode 100644 index 0000000000..b7348e8997 --- /dev/null +++ b/osu.Game/Online/Rooms/RoomExtensions.cs @@ -0,0 +1,21 @@ +// 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.Online.API; + +namespace osu.Game.Online.Rooms +{ + public static class RoomExtensions + { + /// + /// Get the room page URL, or null if unavailable. + /// + public static string? GetOnlineURL(this Room room, IAPIProvider api) + { + if (!room.RoomID.HasValue) + return null; + + return $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{room.RoomID.Value}"; + } + } +} diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs index 7a4279ef98..ae593cd3cb 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs @@ -380,11 +380,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components { var items = new List(); - if (Room.RoomID.HasValue) + string? url = Room.GetOnlineURL(api); + + if (url != null) { items.AddRange([ - new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(getRoomUrl())), - new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyToClipboard(getRoomUrl())) + new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(url)), + new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyToClipboard(url)) ]); } @@ -392,8 +394,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components } } - private string? getRoomUrl() => !Room.RoomID.HasValue ? null : $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{Room.RoomID.Value}"; - protected virtual UpdateableBeatmapBackgroundSprite CreateBackground() => new UpdateableBeatmapBackgroundSprite(); protected virtual IEnumerable CreateBottomDetails() From 8b67747735347a21867ecac7c9e5fe8d7459fb8b Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Thu, 26 Jun 2025 02:57:18 +0300 Subject: [PATCH 4/5] Simplify code and fix link not updating on changes to room ID --- .../OnlinePlay/Lounge/Components/RoomPanel.cs | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs index ae593cd3cb..b9f84b4fa4 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs @@ -207,7 +207,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components Direction = FillDirection.Vertical, Children = new Drawable[] { - roomName = new RoomNameLine(getRoomUrl(), ShowExternalLink), + roomName = new RoomNameLine(), new RoomStatusText(Room) { Beatmap = { BindTarget = currentBeatmap } @@ -278,6 +278,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components wrapper.FadeInFromZero(200); + updateRoomID(); updateRoomName(); updateRoomCategory(); updateRoomType(); @@ -291,6 +292,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components { switch (e.PropertyName) { + case nameof(Room.RoomID): + updateRoomID(); + break; + case nameof(Room.Name): updateRoomName(); break; @@ -334,6 +339,12 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components }), cancellationSource.Token); } + private void updateRoomID() + { + if (roomName != null && ShowExternalLink) + roomName.Link = Room.GetOnlineURL(api); + } + private void updateRoomName() { if (roomName != null) @@ -558,11 +569,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components public partial class RoomNameLine : FillFlowContainer { - private readonly string? roomUrl; - private readonly bool showExternalLink; - private TruncatingSpriteText spriteText = null!; - private ExternalLinkButton link = null!; + private ExternalLinkButton linkButton = null!; public LocalisableString Text { @@ -570,10 +578,16 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components set => spriteText.Text = value; } - public RoomNameLine(string? roomUrl, bool showExternalLink) + private string? link; + + public string? Link { - this.roomUrl = roomUrl; - this.showExternalLink = showExternalLink; + get => link; + set + { + link = value; + updateLink(); + } } [BackgroundDependencyLoader] @@ -591,20 +605,31 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components Origin = Anchor.BottomLeft, Font = OsuFont.GetFont(size: 28), }, - link = new ExternalLinkButton(roomUrl) + linkButton = new ExternalLinkButton { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Margin = new MarginPadding { Horizontal = 6, Bottom = 4 }, - Alpha = showExternalLink ? 1 : 0, + Alpha = 0f, }, }; } + private void updateLink() + { + if (link == null) + linkButton.Hide(); + else + { + linkButton.Show(); + linkButton.Link = link; + } + } + protected override void Update() { base.Update(); - spriteText.MaxWidth = DrawWidth - link.LayoutSize.X; + spriteText.MaxWidth = DrawWidth - linkButton.LayoutSize.X; } } } From 3ac557907e4d2d280043109e7083dacee59b3621 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Thu, 26 Jun 2025 02:58:55 +0300 Subject: [PATCH 5/5] Add test coverage --- .../Visual/Multiplayer/TestSceneRoomPanel.cs | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs index fee5e62958..037c5faae3 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs @@ -165,23 +165,75 @@ namespace osu.Game.Tests.Visual.Multiplayer Name = "A host-only room", QueueMode = QueueMode.HostOnly, Type = MatchType.HeadToHead, + RoomID = 1337, }), new MultiplayerRoomPanel(new Room { Name = "An all-players, team-versus room", QueueMode = QueueMode.AllPlayers, - Type = MatchType.TeamVersus + Type = MatchType.TeamVersus, + RoomID = 1338, }), new MultiplayerRoomPanel(new Room { Name = "A round-robin room", QueueMode = QueueMode.AllPlayersRoundRobin, - Type = MatchType.HeadToHead + Type = MatchType.HeadToHead, + RoomID = 1339, }), } }); } + [Test] + public void TestRoomWithLongTitle() + { + AddStep("create rooms", () => Child = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Spacing = new Vector2(5), + Children = new[] + { + new MultiplayerRoomPanel(new Room + { + Name = "This room has a very very long title enough to make the external link button reach the participants list on the right side unless the test window is very wide, at which point I don't know, hi.", + QueueMode = QueueMode.HostOnly, + Type = MatchType.HeadToHead, + RoomID = 1337, + }), + } + }); + } + + [Test] + public void TestRoomWithUpdatedRoomID() + { + Room room = null!; + + AddStep("create rooms", () => Child = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Spacing = new Vector2(5), + Children = new[] + { + new MultiplayerRoomPanel(room = new Room + { + Name = "This room has a very very long title enough to make the external link button reach the participants list on the right side unless the test window is very wide, at which point I don't know, hi.", + QueueMode = QueueMode.HostOnly, + Type = MatchType.HeadToHead, + }), + } + }); + AddWaitStep("wait", 3); + AddStep("set room ID", () => room.RoomID = 1337); + AddWaitStep("wait", 3); + AddStep("clear room ID", () => room.RoomID = null); + } + private RoomPanel createLoungeRoom(Room room) { room.Host ??= new APIUser { Username = "peppy", Id = 2 };