mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 07:02:54 +08:00
Move static method to Game class
This commit is contained in:
parent
0fe6585975
commit
411916d4a3
@ -85,7 +85,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
TooltipText = tooltipText ?? (url != text ? url : string.Empty),
|
TooltipText = tooltipText ?? (url != text ? url : string.Empty),
|
||||||
Action = action ?? (() => LinkUtils.HandleLink(url, linkType, linkArgument, game, channelManager, showNotImplementedError)),
|
Action = action ?? (() => game.HandleLink(url, linkType, linkArgument)),
|
||||||
});
|
});
|
||||||
|
|
||||||
return drawables;
|
return drawables;
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using osu.Framework.Logging;
|
|
||||||
|
|
||||||
namespace osu.Game.Online.Chat
|
namespace osu.Game.Online.Chat
|
||||||
{
|
{
|
||||||
@ -290,54 +288,4 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
public int CompareTo(Link otherLink) => Index > otherLink.Index ? 1 : -1;
|
public int CompareTo(Link otherLink) => Index > otherLink.Index ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LinkUtils
|
|
||||||
{
|
|
||||||
public static void HandleLink(string url, LinkAction linkType, string linkArgument, OsuGame game, ChannelManager channelManager = null, Action showNotImplementedError = null)
|
|
||||||
{
|
|
||||||
switch (linkType)
|
|
||||||
{
|
|
||||||
case LinkAction.OpenBeatmap:
|
|
||||||
// TODO: proper query params handling
|
|
||||||
if (linkArgument != null && int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
|
|
||||||
game?.ShowBeatmap(beatmapId);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LinkAction.OpenBeatmapSet:
|
|
||||||
if (int.TryParse(linkArgument, out int setId))
|
|
||||||
game?.ShowBeatmapSet(setId);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LinkAction.OpenChannel:
|
|
||||||
try
|
|
||||||
{
|
|
||||||
channelManager?.OpenChannel(linkArgument);
|
|
||||||
}
|
|
||||||
catch (ChannelNotFoundException)
|
|
||||||
{
|
|
||||||
Logger.Log($"The requested channel \"{linkArgument}\" does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LinkAction.OpenEditorTimestamp:
|
|
||||||
case LinkAction.JoinMultiplayerMatch:
|
|
||||||
case LinkAction.Spectate:
|
|
||||||
showNotImplementedError?.Invoke();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LinkAction.External:
|
|
||||||
game?.OpenUrlExternally(url);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LinkAction.OpenUserProfile:
|
|
||||||
if (long.TryParse(linkArgument, out long userId))
|
|
||||||
game?.ShowUser(userId);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -195,19 +195,66 @@ namespace osu.Game
|
|||||||
|
|
||||||
private ExternalLinkOpener externalLinkOpener;
|
private ExternalLinkOpener externalLinkOpener;
|
||||||
|
|
||||||
public void HandleUrl(string url)
|
public void HandleLink(string url, LinkAction linkType, string linkArgument)
|
||||||
{
|
{
|
||||||
Logger.Log($"Request to handle url: {url}");
|
|
||||||
|
|
||||||
Action showNotImplementedError = () => notifications?.Post(new SimpleNotification
|
Action showNotImplementedError = () => notifications?.Post(new SimpleNotification
|
||||||
{
|
{
|
||||||
Text = @"This link type is not yet supported!",
|
Text = @"This link type is not yet supported!",
|
||||||
Icon = FontAwesome.Solid.LifeRing,
|
Icon = FontAwesome.Solid.LifeRing,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
switch (linkType)
|
||||||
|
{
|
||||||
|
case LinkAction.OpenBeatmap:
|
||||||
|
// TODO: proper query params handling
|
||||||
|
if (linkArgument != null && int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
|
||||||
|
ShowBeatmap(beatmapId);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LinkAction.OpenBeatmapSet:
|
||||||
|
if (int.TryParse(linkArgument, out int setId))
|
||||||
|
ShowBeatmapSet(setId);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LinkAction.OpenChannel:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
channelManager.OpenChannel(linkArgument);
|
||||||
|
}
|
||||||
|
catch (ChannelNotFoundException)
|
||||||
|
{
|
||||||
|
Logger.Log($"The requested channel \"{linkArgument}\" does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LinkAction.OpenEditorTimestamp:
|
||||||
|
case LinkAction.JoinMultiplayerMatch:
|
||||||
|
case LinkAction.Spectate:
|
||||||
|
showNotImplementedError?.Invoke();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LinkAction.External:
|
||||||
|
OpenUrlExternally(url);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LinkAction.OpenUserProfile:
|
||||||
|
if (long.TryParse(linkArgument, out long userId))
|
||||||
|
ShowUser(userId);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleUrl(string url)
|
||||||
|
{
|
||||||
|
Logger.Log($"Request to handle url: {url}");
|
||||||
|
|
||||||
LinkDetails linkDetails = GetLinkDetails(url);
|
LinkDetails linkDetails = GetLinkDetails(url);
|
||||||
|
|
||||||
Schedule(() => LinkUtils.HandleLink(url, linkDetails.Action, linkDetails.Argument, this, channelManager, showNotImplementedError));
|
Schedule(() => HandleLink(url, linkDetails.Action, linkDetails.Argument));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenUrlExternally(string url)
|
public void OpenUrlExternally(string url)
|
||||||
|
Loading…
Reference in New Issue
Block a user