From 6d9dcc66913d1118b5070ce0b973d95e78bbea79 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Sat, 2 Dec 2017 09:48:55 +0100 Subject: [PATCH] Added all files to the .csproj and also introduced basic action filtering when you set the URL on an OsuLinkSpriteText object --- .../Graphics/Sprites/OsuLinkSpriteText.cs | 45 ++++++++++++++++++- osu.Game/osu.Game.csproj | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs b/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs index 111ba6a49a..f41bca62ec 100644 --- a/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs +++ b/osu.Game/Graphics/Sprites/OsuLinkSpriteText.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; using osu.Game.Graphics.Containers; +using osu.Game.Overlays; using System; using System.Collections.Generic; using System.Diagnostics; @@ -20,6 +21,8 @@ namespace osu.Game.Graphics.Sprites { private readonly OsuHoverContainer content; + private BeatmapSetOverlay beatmapSetOverlay; + public override bool HandleInput => content.Action != null; protected override Container Content => content ?? (Container)this; @@ -39,7 +42,7 @@ namespace osu.Game.Graphics.Sprites if (value != null) { url = value; - content.Action = () => Process.Start(value); + loadAction(); } } } @@ -51,5 +54,45 @@ namespace osu.Game.Graphics.Sprites AutoSizeAxes = Axes.Both, }); } + + [BackgroundDependencyLoader] + private void load(BeatmapSetOverlay beatmapSetOverlay) + { + this.beatmapSetOverlay = beatmapSetOverlay; + } + + private void loadAction() + { + if (Url == null || String.IsNullOrEmpty(Url)) + return; + + var url = Url; + + if (url.StartsWith("https://")) url = url.Substring(8); + else if (url.StartsWith("http://")) url = url.Substring(7); + else content.Action = () => Process.Start(Url); + + if (url.StartsWith("osu.ppy.sh/")) + { + url = url.Substring(11); + if (url.StartsWith("s") || url.StartsWith("beatmapsets")) + content.Action = () => beatmapSetOverlay.ShowBeatmapSet(getIdFromUrl(url)); + else if (url.StartsWith("b") || url.StartsWith("beatmaps")) + content.Action = () => beatmapSetOverlay.ShowBeatmap(getIdFromUrl(url)); + // else if (url.StartsWith("d")) Maybe later + } + } + + private int getIdFromUrl(string url) + { + var lastSlashIndex = url.LastIndexOf('/'); + if (lastSlashIndex == url.Length) + { + url = url.Substring(url.Length - 1); + lastSlashIndex = url.LastIndexOf('/'); + } + + return int.Parse(url.Substring(lastSlashIndex + 1)); + } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index a2d8a4bbe4..24ca01a3ad 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -286,6 +286,7 @@ 20171119065731_AddBeatmapOnlineIDUniqueConstraint.cs +