Skip to content

Commit bc07aba

Browse files
authored
Merge pull request #33858 from frenzibyte/multiplayer-match-link
Add external link button to multiplayer/playlists room panels
2 parents 548b442 + 3ac5579 commit bc07aba

File tree

4 files changed

+163
-13
lines changed

4 files changed

+163
-13
lines changed

osu.Game.Tests/Visual/Multiplayer/TestSceneRoomPanel.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,73 @@ public void TestMultiplayerRooms()
165165
Name = "A host-only room",
166166
QueueMode = QueueMode.HostOnly,
167167
Type = MatchType.HeadToHead,
168+
RoomID = 1337,
168169
}),
169170
new MultiplayerRoomPanel(new Room
170171
{
171172
Name = "An all-players, team-versus room",
172173
QueueMode = QueueMode.AllPlayers,
173-
Type = MatchType.TeamVersus
174+
Type = MatchType.TeamVersus,
175+
RoomID = 1338,
174176
}),
175177
new MultiplayerRoomPanel(new Room
176178
{
177179
Name = "A round-robin room",
178180
QueueMode = QueueMode.AllPlayersRoundRobin,
179-
Type = MatchType.HeadToHead
181+
Type = MatchType.HeadToHead,
182+
RoomID = 1339,
183+
}),
184+
}
185+
});
186+
}
187+
188+
[Test]
189+
public void TestRoomWithLongTitle()
190+
{
191+
AddStep("create rooms", () => Child = new FillFlowContainer
192+
{
193+
AutoSizeAxes = Axes.Y,
194+
RelativeSizeAxes = Axes.X,
195+
Direction = FillDirection.Vertical,
196+
Spacing = new Vector2(5),
197+
Children = new[]
198+
{
199+
new MultiplayerRoomPanel(new Room
200+
{
201+
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.",
202+
QueueMode = QueueMode.HostOnly,
203+
Type = MatchType.HeadToHead,
204+
RoomID = 1337,
205+
}),
206+
}
207+
});
208+
}
209+
210+
[Test]
211+
public void TestRoomWithUpdatedRoomID()
212+
{
213+
Room room = null!;
214+
215+
AddStep("create rooms", () => Child = new FillFlowContainer
216+
{
217+
AutoSizeAxes = Axes.Y,
218+
RelativeSizeAxes = Axes.X,
219+
Direction = FillDirection.Vertical,
220+
Spacing = new Vector2(5),
221+
Children = new[]
222+
{
223+
new MultiplayerRoomPanel(room = new Room
224+
{
225+
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.",
226+
QueueMode = QueueMode.HostOnly,
227+
Type = MatchType.HeadToHead,
180228
}),
181229
}
182230
});
231+
AddWaitStep("wait", 3);
232+
AddStep("set room ID", () => room.RoomID = 1337);
233+
AddWaitStep("wait", 3);
234+
AddStep("clear room ID", () => room.RoomID = null);
183235
}
184236

185237
private RoomPanel createLoungeRoom(Room room)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using osu.Game.Online.API;
5+
6+
namespace osu.Game.Online.Rooms
7+
{
8+
public static class RoomExtensions
9+
{
10+
/// <summary>
11+
/// Get the room page URL, or <c>null</c> if unavailable.
12+
/// </summary>
13+
public static string? GetOnlineURL(this Room room, IAPIProvider api)
14+
{
15+
if (!room.RoomID.HasValue)
16+
return null;
17+
18+
return $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{room.RoomID.Value}";
19+
}
20+
}
21+
}

osu.Game/Screens/OnlinePlay/Lounge/Components/RoomPanel.cs

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using osu.Framework.Graphics.Shapes;
1818
using osu.Framework.Graphics.Sprites;
1919
using osu.Framework.Graphics.UserInterface;
20+
using osu.Framework.Localisation;
2021
using osu.Game.Beatmaps;
2122
using osu.Game.Beatmaps.Drawables;
2223
using osu.Game.Database;
@@ -54,11 +55,13 @@ public abstract partial class RoomPanel : CompositeDrawable, IHasContextMenu
5455
protected readonly Bindable<PlaylistItem?> SelectedItem = new Bindable<PlaylistItem?>();
5556
protected Container ButtonsContainer { get; private set; } = null!;
5657

58+
protected bool ShowExternalLink { get; init; } = true;
59+
5760
private DrawableRoomParticipantsList? drawableRoomParticipantsList;
5861
private RoomSpecialCategoryPill? specialCategoryPill;
5962
private PasswordProtectedIcon? passwordIcon;
6063
private EndDateInfo? endDateInfo;
61-
private SpriteText? roomName;
64+
private RoomNameLine? roomName;
6265
private DelayedLoadWrapper wrapper = null!;
6366
private CancellationTokenSource? beatmapLookupCancellation;
6467

@@ -204,11 +207,7 @@ private void load(OverlayColourProvider colours)
204207
Direction = FillDirection.Vertical,
205208
Children = new Drawable[]
206209
{
207-
roomName = new TruncatingSpriteText
208-
{
209-
RelativeSizeAxes = Axes.X,
210-
Font = OsuFont.GetFont(size: 28)
211-
},
210+
roomName = new RoomNameLine(),
212211
new RoomStatusText(Room)
213212
{
214213
Beatmap = { BindTarget = currentBeatmap }
@@ -279,6 +278,7 @@ protected override void LoadComplete()
279278

280279
wrapper.FadeInFromZero(200);
281280

281+
updateRoomID();
282282
updateRoomName();
283283
updateRoomCategory();
284284
updateRoomType();
@@ -292,6 +292,10 @@ private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
292292
{
293293
switch (e.PropertyName)
294294
{
295+
case nameof(Room.RoomID):
296+
updateRoomID();
297+
break;
298+
295299
case nameof(Room.Name):
296300
updateRoomName();
297301
break;
@@ -335,6 +339,12 @@ private void onSelectedItemChanged(ValueChangedEvent<PlaylistItem?> item)
335339
}), cancellationSource.Token);
336340
}
337341

342+
private void updateRoomID()
343+
{
344+
if (roomName != null && ShowExternalLink)
345+
roomName.Link = Room.GetOnlineURL(api);
346+
}
347+
338348
private void updateRoomName()
339349
{
340350
if (roomName != null)
@@ -381,17 +391,17 @@ public virtual MenuItem[] ContextMenuItems
381391
{
382392
var items = new List<MenuItem>();
383393

384-
if (Room.RoomID.HasValue)
394+
string? url = Room.GetOnlineURL(api);
395+
396+
if (url != null)
385397
{
386398
items.AddRange([
387-
new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(formatRoomUrl(Room.RoomID.Value))),
388-
new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyToClipboard(formatRoomUrl(Room.RoomID.Value)))
399+
new OsuMenuItem("View in browser", MenuItemType.Standard, () => game?.OpenUrlExternally(url)),
400+
new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyToClipboard(url))
389401
]);
390402
}
391403

392404
return items.ToArray();
393-
394-
string formatRoomUrl(long id) => $@"{api.Endpoints.WebsiteUrl}/multiplayer/rooms/{id}";
395405
}
396406
}
397407

@@ -556,5 +566,71 @@ private void load(OsuColour colours)
556566
};
557567
}
558568
}
569+
570+
public partial class RoomNameLine : FillFlowContainer
571+
{
572+
private TruncatingSpriteText spriteText = null!;
573+
private ExternalLinkButton linkButton = null!;
574+
575+
public LocalisableString Text
576+
{
577+
get => spriteText.Text;
578+
set => spriteText.Text = value;
579+
}
580+
581+
private string? link;
582+
583+
public string? Link
584+
{
585+
get => link;
586+
set
587+
{
588+
link = value;
589+
updateLink();
590+
}
591+
}
592+
593+
[BackgroundDependencyLoader]
594+
private void load()
595+
{
596+
RelativeSizeAxes = Axes.X;
597+
AutoSizeAxes = Axes.Y;
598+
Direction = FillDirection.Horizontal;
599+
600+
Children = new Drawable[]
601+
{
602+
spriteText = new TruncatingSpriteText
603+
{
604+
Anchor = Anchor.BottomLeft,
605+
Origin = Anchor.BottomLeft,
606+
Font = OsuFont.GetFont(size: 28),
607+
},
608+
linkButton = new ExternalLinkButton
609+
{
610+
Anchor = Anchor.BottomLeft,
611+
Origin = Anchor.BottomLeft,
612+
Margin = new MarginPadding { Horizontal = 6, Bottom = 4 },
613+
Alpha = 0f,
614+
},
615+
};
616+
}
617+
618+
private void updateLink()
619+
{
620+
if (link == null)
621+
linkButton.Hide();
622+
else
623+
{
624+
linkButton.Show();
625+
linkButton.Link = link;
626+
}
627+
}
628+
629+
protected override void Update()
630+
{
631+
base.Update();
632+
spriteText.MaxWidth = DrawWidth - linkButton.LayoutSize.X;
633+
}
634+
}
559635
}
560636
}

osu.Game/Screens/OnlinePlay/Lounge/LoungeRoomPanel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public required Bindable<Room?> SelectedRoom
6767
public LoungeRoomPanel(Room room)
6868
: base(room)
6969
{
70+
ShowExternalLink = false;
7071
}
7172

7273
[BackgroundDependencyLoader]

0 commit comments

Comments
 (0)