1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 09:27:34 +08:00

Support SpriteText for LinkFlowContainer

This commit is contained in:
PercyDan54 2021-04-18 20:58:08 +08:00
parent 38a7c590c4
commit 488001d570
No known key found for this signature in database
GPG Key ID: 6AEA7C525131BAF3
3 changed files with 29 additions and 1 deletions

View File

@ -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<SpriteText> 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.

View File

@ -31,6 +31,11 @@ namespace osu.Game.Online.Chat
Parts = parts.ToList();
}
public DrawableLinkCompiler(Drawable part)
{
Parts = new List<Drawable> { part };
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{

View File

@ -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<SpriteText> { 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();