mirror of
https://github.com/osukey/osukey.git
synced 2025-05-08 07:07:18 +09:00
Fix LinkFlowContainer
not creating user links supporting full IUser
specification
This commit is contained in:
parent
dede0e56ce
commit
6b6dd93e9e
@ -46,7 +46,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
AddText(text[previousLinkEnd..link.Index]);
|
AddText(text[previousLinkEnd..link.Index]);
|
||||||
|
|
||||||
string displayText = text.Substring(link.Index, link.Length);
|
string displayText = text.Substring(link.Index, link.Length);
|
||||||
string linkArgument = link.Argument;
|
object linkArgument = link.Argument;
|
||||||
string tooltip = displayText == link.Url ? null : link.Url;
|
string tooltip = displayText == link.Url ? null : link.Url;
|
||||||
|
|
||||||
AddLink(displayText, link.Action, linkArgument, tooltip);
|
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)
|
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);
|
=> 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);
|
=> 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);
|
createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddUserLink(IUser user, Action<SpriteText> creationParameters = null)
|
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)
|
private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null)
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
game.HandleLink(link);
|
game.HandleLink(link);
|
||||||
// fallback to handle cases where OsuGame is not available, ie. tournament client.
|
// fallback to handle cases where OsuGame is not available, ie. tournament client.
|
||||||
else if (link.Action == LinkAction.External)
|
else if (link.Action == LinkAction.External)
|
||||||
host.OpenUrlExternally(link.Argument);
|
host.OpenUrlExternally(link.Argument.ToString());
|
||||||
};
|
};
|
||||||
|
|
||||||
AddPart(new TextLink(textPart, tooltipText, onClickAction));
|
AddPart(new TextLink(textPart, tooltipText, onClickAction));
|
||||||
|
@ -320,9 +320,9 @@ namespace osu.Game.Online.Chat
|
|||||||
{
|
{
|
||||||
public readonly LinkAction Action;
|
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;
|
Action = action;
|
||||||
Argument = argument;
|
Argument = argument;
|
||||||
@ -351,9 +351,9 @@ namespace osu.Game.Online.Chat
|
|||||||
public int Index;
|
public int Index;
|
||||||
public int Length;
|
public int Length;
|
||||||
public LinkAction Action;
|
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;
|
Url = url;
|
||||||
Index = startIndex;
|
Index = startIndex;
|
||||||
|
@ -289,25 +289,27 @@ namespace osu.Game
|
|||||||
/// <param name="link">The link to load.</param>
|
/// <param name="link">The link to load.</param>
|
||||||
public void HandleLink(LinkDetails link) => Schedule(() =>
|
public void HandleLink(LinkDetails link) => Schedule(() =>
|
||||||
{
|
{
|
||||||
|
string argString = link.Argument.ToString();
|
||||||
|
|
||||||
switch (link.Action)
|
switch (link.Action)
|
||||||
{
|
{
|
||||||
case LinkAction.OpenBeatmap:
|
case LinkAction.OpenBeatmap:
|
||||||
// TODO: proper query params handling
|
// 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);
|
ShowBeatmap(beatmapId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.OpenBeatmapSet:
|
case LinkAction.OpenBeatmapSet:
|
||||||
if (int.TryParse(link.Argument, out int setId))
|
if (int.TryParse(argString, out int setId))
|
||||||
ShowBeatmapSet(setId);
|
ShowBeatmapSet(setId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.OpenChannel:
|
case LinkAction.OpenChannel:
|
||||||
ShowChannel(link.Argument);
|
ShowChannel(argString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.SearchBeatmapSet:
|
case LinkAction.SearchBeatmapSet:
|
||||||
SearchBeatmapSet(link.Argument);
|
SearchBeatmapSet(argString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.OpenEditorTimestamp:
|
case LinkAction.OpenEditorTimestamp:
|
||||||
@ -321,26 +323,31 @@ namespace osu.Game
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.External:
|
case LinkAction.External:
|
||||||
OpenUrlExternally(link.Argument);
|
OpenUrlExternally(argString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.OpenUserProfile:
|
case LinkAction.OpenUserProfile:
|
||||||
ShowUser(int.TryParse(link.Argument, out int userId)
|
if (!(link.Argument is IUser user))
|
||||||
? new APIUser { Id = userId }
|
{
|
||||||
: new APIUser { Username = link.Argument });
|
user = int.TryParse(argString, out int userId)
|
||||||
|
? new APIUser { Id = userId }
|
||||||
|
: new APIUser { Username = argString };
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowUser(user);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.OpenWiki:
|
case LinkAction.OpenWiki:
|
||||||
ShowWiki(link.Argument);
|
ShowWiki(argString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LinkAction.OpenChangelog:
|
case LinkAction.OpenChangelog:
|
||||||
if (string.IsNullOrEmpty(link.Argument))
|
if (string.IsNullOrEmpty(argString))
|
||||||
ShowChangelogListing();
|
ShowChangelogListing();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] changelogArgs = link.Argument.Split("/");
|
string[] changelogArgs = argString.Split("/");
|
||||||
ShowChangelogBuild(changelogArgs[0], changelogArgs[1]);
|
ShowChangelogBuild(changelogArgs[0], changelogArgs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
|
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
|
||||||
|
|
||||||
// remove non-existent channels from the link list
|
// 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.Clear();
|
||||||
ContentFlow.AddLinks(message.DisplayContent, message.Links);
|
ContentFlow.AddLinks(message.DisplayContent, message.Links);
|
||||||
|
@ -216,7 +216,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
|
|||||||
private void addBeatmapsetLink()
|
private void addBeatmapsetLink()
|
||||||
=> content.AddLink(activity.Beatmapset?.Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset?.Url), creationParameters: t => t.Font = getLinkFont());
|
=> 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)
|
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
|
||||||
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);
|
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user