Add and use ILinkHandler interface

This commit is contained in:
Bartłomiej Dach
2022-06-20 20:04:21 +02:00
parent 3f288c69a3
commit 34f1c80b7c
4 changed files with 39 additions and 6 deletions

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Online;
using osu.Game.Users;
namespace osu.Game.Graphics.Containers
@ -25,7 +26,7 @@ namespace osu.Game.Graphics.Containers
}
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
private ILinkHandler linkHandler { get; set; }
[Resolved]
private GameHost host { get; set; }
@ -81,8 +82,8 @@ namespace osu.Game.Graphics.Containers
{
if (action != null)
action();
else if (game != null)
game.HandleLink(link);
else if (linkHandler != null)
linkHandler.HandleLink(link);
// fallback to handle cases where OsuGame is not available, ie. tournament client.
else if (link.Action == LinkAction.External)
host.OpenUrlExternally(link.Argument.ToString());

View File

@ -8,6 +8,7 @@ using Markdig.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers.Markdown;
using osu.Game.Online;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
@ -16,7 +17,7 @@ namespace osu.Game.Graphics.Containers.Markdown
public class OsuMarkdownLinkText : MarkdownLinkText
{
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }
private ILinkHandler linkHandler { get; set; }
private readonly string text;
private readonly string title;
@ -51,7 +52,7 @@ namespace osu.Game.Graphics.Containers.Markdown
};
}
protected override void OnLinkPressed() => game?.HandleLink(Url);
protected override void OnLinkPressed() => linkHandler?.HandleLink(Url);
private class OsuMarkdownLinkCompiler : DrawableLinkCompiler
{