Added ability to open other channels from chat links.

This commit is contained in:
FreezyLemon 2017-12-03 20:45:30 +01:00
parent c574cc4308
commit 2d270a1cfe
2 changed files with 34 additions and 2 deletions

View File

@ -20,6 +20,8 @@ namespace osu.Game.Graphics.Sprites
{
public class OsuLinkSpriteText : OsuSpriteText
{
private ChatOverlay chat;
private readonly OsuHoverContainer content;
private BeatmapSetOverlay beatmapSetOverlay;
@ -57,9 +59,10 @@ public OsuLinkSpriteText()
}
[BackgroundDependencyLoader]
private void load(BeatmapSetOverlay beatmapSetOverlay)
private void load(BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat)
{
this.beatmapSetOverlay = beatmapSetOverlay;
this.chat = chat;
}
private void loadAction()
@ -69,7 +72,31 @@ private void loadAction()
var url = Url;
if (url.StartsWith("http://") || url.StartsWith("https://"))
// Client-internal stuff
if (url.StartsWith("osu://"))
{
var firstPath = url.Substring(6, 5);
url = url.Substring(11);
if (firstPath == "chan/")
{
var nextSlashIndex = url.IndexOf('/');
var channelName = url.Substring(0, nextSlashIndex != -1 ? nextSlashIndex - 1 : url.Length - 1);
var foundChannel = chat.AvailableChannels.Find(channel => channel.Name == channelName);
if (foundChannel != null)
chat.OpenChannel(foundChannel);
}
else if (firstPath == "edit/")
{
// Open editor here, then goto specified time
// how to push new screen from here? we'll see
}
else
throw new ArgumentException($"Unknown osu:// link at {nameof(OsuLinkSpriteText)} ({firstPath}).");
}
else if (url.StartsWith("http://") || url.StartsWith("https://"))
{
var osuUrlIndex = url.IndexOf("osu.ppy.sh/");
if (osuUrlIndex == -1)

View File

@ -60,6 +60,7 @@ public class ChatOverlay : OsuFocusedOverlayContainer, IOnlineComponent
public Bindable<double> ChatHeight { get; set; }
public List<Channel> AvailableChannels { get; private set; }
private readonly Container channelSelectionContainer;
private readonly ChannelSelectionOverlay channelSelection;
@ -190,6 +191,8 @@ public ChatOverlay()
private double startDragChatHeight;
private bool isDragging;
public void OpenChannel(Channel channel) => addChannel(channel);
protected override bool OnDragStart(InputState state)
{
isDragging = tabsArea.IsHovered;
@ -300,6 +303,8 @@ private void initializeChannels()
ListChannelsRequest req = new ListChannelsRequest();
req.Success += delegate (List<Channel> channels)
{
AvailableChannels = channels;
Scheduler.Add(delegate
{
addChannel(channels.Find(c => c.Name == @"#lazer"));