Allow LinkFlowContainer to still open external URLs when OsuGame is not available

This commit is contained in:
Dean Herbert 2021-07-30 13:21:26 +09:00
parent fc66476107
commit 3a347188a5

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Users; using osu.Game.Users;
@ -25,6 +26,9 @@ namespace osu.Game.Graphics.Containers
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private OsuGame game { get; set; } private OsuGame game { get; set; }
[Resolved]
private GameHost host { get; set; }
public void AddLinks(string text, List<Link> links) public void AddLinks(string text, List<Link> links)
{ {
if (string.IsNullOrEmpty(text) || links == null) if (string.IsNullOrEmpty(text) || links == null)
@ -91,8 +95,11 @@ namespace osu.Game.Graphics.Containers
{ {
if (action != null) if (action != null)
action(); action();
else else if (game != null)
game?.HandleLink(link); 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);
}, },
}); });
} }