1717using osu . Framework . Graphics . Shapes ;
1818using osu . Framework . Graphics . Sprites ;
1919using osu . Framework . Graphics . UserInterface ;
20+ using osu . Framework . Localisation ;
2021using osu . Game . Beatmaps ;
2122using osu . Game . Beatmaps . Drawables ;
2223using 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}
0 commit comments