From 488001d5701b51db7405e5ebd7c3ab4174e9a699 Mon Sep 17 00:00:00 2001 From: PercyDan54 <50285552+PercyDan54@users.noreply.github.com> Date: Sun, 18 Apr 2021 20:58:08 +0800 Subject: [PATCH] Support SpriteText for LinkFlowContainer --- .../Graphics/Containers/LinkFlowContainer.cs | 23 +++++++++++++++++++ osu.Game/Online/Chat/DrawableLinkCompiler.cs | 5 ++++ .../OnlinePlay/DrawableRoomPlaylistItem.cs | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/LinkFlowContainer.cs b/osu.Game/Graphics/Containers/LinkFlowContainer.cs index 914c8ff78d..32efcce80c 100644 --- a/osu.Game/Graphics/Containers/LinkFlowContainer.cs +++ b/osu.Game/Graphics/Containers/LinkFlowContainer.cs @@ -67,6 +67,13 @@ namespace osu.Game.Graphics.Containers createLink(text, new LinkDetails(action, linkArgument), tooltipText); } + public void AddLink(SpriteText text, LinkAction action = LinkAction.External, string linkArgument = null, string tooltipText = null) + { + AddArbitraryDrawable(text); + + createLink(text, new LinkDetails(action, linkArgument), tooltipText); + } + public void AddUserLink(User user, Action creationParameters = null) => createLink(AddText(user.Username, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); @@ -86,6 +93,22 @@ namespace osu.Game.Graphics.Containers }); } + private void createLink(Drawable drawable, LinkDetails link, string tooltipText, Action action = null) + { + AddInternal(new DrawableLinkCompiler(drawable) + { + RelativeSizeAxes = Axes.Both, + TooltipText = tooltipText, + Action = () => + { + if (action != null) + action(); + else + game?.HandleLink(link); + }, + }); + } + // We want the compilers to always be visible no matter where they are, so RelativeSizeAxes is used. // However due to https://github.com/ppy/osu-framework/issues/2073, it's possible for the compilers to be relative size in the flow's auto-size axes - an unsupported operation. // Since the compilers don't display any content and don't affect the layout, it's simplest to exclude them from the flow. diff --git a/osu.Game/Online/Chat/DrawableLinkCompiler.cs b/osu.Game/Online/Chat/DrawableLinkCompiler.cs index d27a3fbffe..7675eab4c0 100644 --- a/osu.Game/Online/Chat/DrawableLinkCompiler.cs +++ b/osu.Game/Online/Chat/DrawableLinkCompiler.cs @@ -31,6 +31,11 @@ namespace osu.Game.Online.Chat Parts = parts.ToList(); } + public DrawableLinkCompiler(Drawable part) + { + Parts = new List { part }; + } + [BackgroundDependencyLoader] private void load(OsuColour colours) { diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index fe5876e732..a92ca610f3 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -109,7 +109,7 @@ namespace osu.Game.Screens.OnlinePlay difficultyIconContainer.Child = new DifficultyIcon(beatmap.Value, ruleset.Value, requiredMods) { Size = new Vector2(32) }; beatmapText.Clear(); - beatmapText.AddLink(new List { new OsuSpriteText { Text = Item.Beatmap.Value.ToRomanisableString() } }, + beatmapText.AddLink(new OsuSpriteText { Text = Item.Beatmap.Value.ToRomanisableString() }, LinkAction.OpenBeatmap, Item.Beatmap.Value.OnlineBeatmapID.ToString()); authorText.Clear();