mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Add and use ILinkHandler
interface
This commit is contained in:
parent
3f288c69a3
commit
34f1c80b7c
@ -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());
|
||||
|
@ -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
|
||||
{
|
||||
|
30
osu.Game/Online/ILinkHandler.cs
Normal file
30
osu.Game/Online/ILinkHandler.cs
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Online
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle an arbitrary URL. Displays via in-game overlays where possible.
|
||||
/// Methods can be called from a non-thread-safe non-game-loaded state.
|
||||
/// </summary>
|
||||
[Cached]
|
||||
public interface ILinkHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle an arbitrary URL. Displays via in-game overlays where possible.
|
||||
/// This can be called from a non-thread-safe non-game-loaded state.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to load.</param>
|
||||
void HandleLink(string url);
|
||||
|
||||
/// <summary>
|
||||
/// Handle a specific <see cref="LinkDetails"/>.
|
||||
/// This can be called from a non-thread-safe non-game-loaded state.
|
||||
/// </summary>
|
||||
/// <param name="link">The link to load.</param>
|
||||
void HandleLink(LinkDetails link);
|
||||
}
|
||||
}
|
@ -39,6 +39,7 @@ using osu.Game.Input;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays;
|
||||
@ -69,7 +70,7 @@ namespace osu.Game
|
||||
/// The full osu! experience. Builds on top of <see cref="OsuGameBase"/> to add menus and binding logic
|
||||
/// for initial components that are generally retrieved via DI.
|
||||
/// </summary>
|
||||
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUserPlayInfo, IPerformFromScreenRunner, IOverlayManager
|
||||
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUserPlayInfo, IPerformFromScreenRunner, IOverlayManager, ILinkHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of global offset to apply when a left/right anchored overlay is displayed (ie. settings or notifications).
|
||||
|
Loading…
Reference in New Issue
Block a user