mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:02:55 +08:00
Merge pull request #15517 from peppy/fix-beatmap-wedge-user-display
Fix `LinkFlowContainer` not creating user links supporting full `IUser` specification
This commit is contained in:
commit
b5a6fd3f00
@ -46,7 +46,7 @@ namespace osu.Game.Graphics.Containers
|
||||
AddText(text[previousLinkEnd..link.Index]);
|
||||
|
||||
string displayText = text.Substring(link.Index, link.Length);
|
||||
string linkArgument = link.Argument;
|
||||
object linkArgument = link.Argument;
|
||||
string tooltip = displayText == link.Url ? null : link.Url;
|
||||
|
||||
AddLink(displayText, link.Action, linkArgument, tooltip);
|
||||
@ -62,16 +62,16 @@ namespace osu.Game.Graphics.Containers
|
||||
public void AddLink(LocalisableString text, Action action, string tooltipText = null, Action<SpriteText> creationParameters = null)
|
||||
=> createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.Custom, string.Empty), tooltipText, action);
|
||||
|
||||
public void AddLink(LocalisableString text, LinkAction action, string argument, string tooltipText = null, Action<SpriteText> creationParameters = null)
|
||||
public void AddLink(LocalisableString text, LinkAction action, object argument, string tooltipText = null, Action<SpriteText> creationParameters = null)
|
||||
=> createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(action, argument), tooltipText);
|
||||
|
||||
public void AddLink(IEnumerable<SpriteText> text, LinkAction action, string linkArgument, string tooltipText = null)
|
||||
public void AddLink(IEnumerable<SpriteText> text, LinkAction action, object linkArgument, string tooltipText = null)
|
||||
{
|
||||
createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText);
|
||||
}
|
||||
|
||||
public void AddUserLink(IUser user, Action<SpriteText> creationParameters = null)
|
||||
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.OnlineID.ToString()), "view profile");
|
||||
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user), "view profile");
|
||||
|
||||
private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null)
|
||||
{
|
||||
@ -83,7 +83,7 @@ namespace osu.Game.Graphics.Containers
|
||||
game.HandleLink(link);
|
||||
// fallback to handle cases where OsuGame is not available, ie. tournament client.
|
||||
else if (link.Action == LinkAction.External)
|
||||
host.OpenUrlExternally(link.Argument);
|
||||
host.OpenUrlExternally(link.Argument.ToString());
|
||||
};
|
||||
|
||||
AddPart(new TextLink(textPart, tooltipText, onClickAction));
|
||||
|
@ -320,9 +320,9 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
public readonly LinkAction Action;
|
||||
|
||||
public readonly string Argument;
|
||||
public readonly object Argument;
|
||||
|
||||
public LinkDetails(LinkAction action, string argument)
|
||||
public LinkDetails(LinkAction action, object argument)
|
||||
{
|
||||
Action = action;
|
||||
Argument = argument;
|
||||
@ -351,9 +351,9 @@ namespace osu.Game.Online.Chat
|
||||
public int Index;
|
||||
public int Length;
|
||||
public LinkAction Action;
|
||||
public string Argument;
|
||||
public object Argument;
|
||||
|
||||
public Link(string url, int startIndex, int length, LinkAction action, string argument)
|
||||
public Link(string url, int startIndex, int length, LinkAction action, object argument)
|
||||
{
|
||||
Url = url;
|
||||
Index = startIndex;
|
||||
|
@ -289,25 +289,27 @@ namespace osu.Game
|
||||
/// <param name="link">The link to load.</param>
|
||||
public void HandleLink(LinkDetails link) => Schedule(() =>
|
||||
{
|
||||
string argString = link.Argument.ToString();
|
||||
|
||||
switch (link.Action)
|
||||
{
|
||||
case LinkAction.OpenBeatmap:
|
||||
// TODO: proper query params handling
|
||||
if (int.TryParse(link.Argument.Contains('?') ? link.Argument.Split('?')[0] : link.Argument, out int beatmapId))
|
||||
if (int.TryParse(argString.Contains('?') ? argString.Split('?')[0] : argString, out int beatmapId))
|
||||
ShowBeatmap(beatmapId);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenBeatmapSet:
|
||||
if (int.TryParse(link.Argument, out int setId))
|
||||
if (int.TryParse(argString, out int setId))
|
||||
ShowBeatmapSet(setId);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenChannel:
|
||||
ShowChannel(link.Argument);
|
||||
ShowChannel(argString);
|
||||
break;
|
||||
|
||||
case LinkAction.SearchBeatmapSet:
|
||||
SearchBeatmapSet(link.Argument);
|
||||
SearchBeatmapSet(argString);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenEditorTimestamp:
|
||||
@ -321,26 +323,31 @@ namespace osu.Game
|
||||
break;
|
||||
|
||||
case LinkAction.External:
|
||||
OpenUrlExternally(link.Argument);
|
||||
OpenUrlExternally(argString);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenUserProfile:
|
||||
ShowUser(int.TryParse(link.Argument, out int userId)
|
||||
? new APIUser { Id = userId }
|
||||
: new APIUser { Username = link.Argument });
|
||||
if (!(link.Argument is IUser user))
|
||||
{
|
||||
user = int.TryParse(argString, out int userId)
|
||||
? new APIUser { Id = userId }
|
||||
: new APIUser { Username = argString };
|
||||
}
|
||||
|
||||
ShowUser(user);
|
||||
|
||||
break;
|
||||
|
||||
case LinkAction.OpenWiki:
|
||||
ShowWiki(link.Argument);
|
||||
ShowWiki(argString);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenChangelog:
|
||||
if (string.IsNullOrEmpty(link.Argument))
|
||||
if (string.IsNullOrEmpty(argString))
|
||||
ShowChangelogListing();
|
||||
else
|
||||
{
|
||||
string[] changelogArgs = link.Argument.Split("/");
|
||||
string[] changelogArgs = argString.Split("/");
|
||||
ShowChangelogBuild(changelogArgs[0], changelogArgs[1]);
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ namespace osu.Game.Overlays.Chat
|
||||
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
|
||||
|
||||
// remove non-existent channels from the link list
|
||||
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument) != true);
|
||||
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true);
|
||||
|
||||
ContentFlow.Clear();
|
||||
ContentFlow.AddLinks(message.DisplayContent, message.Links);
|
||||
|
@ -216,7 +216,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
|
||||
private void addBeatmapsetLink()
|
||||
=> content.AddLink(activity.Beatmapset?.Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset?.Url), creationParameters: t => t.Font = getLinkFont());
|
||||
|
||||
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.APIEndpointUrl}{url}").Argument;
|
||||
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.APIEndpointUrl}{url}").Argument.ToString();
|
||||
|
||||
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
|
||||
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);
|
||||
|
Loading…
Reference in New Issue
Block a user