Пример #1
0
        private IEnumerable <Drawable> createLink(IEnumerable <Drawable> drawables, string text, string url = null, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null, Action action = null)
        {
            AddInternal(new DrawableLinkCompiler(drawables.OfType <SpriteText>().ToList())
            {
                RelativeSizeAxes = Axes.Both,
                TooltipText      = tooltipText ?? (url != text ? url : string.Empty),
                Action           = action ?? (() =>
                {
                    switch (linkType)
                    {
                    case LinkAction.OpenBeatmap:
                        // TODO: proper query params handling
                        if (linkArgument != null && int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
                        {
                            game?.ShowBeatmap(beatmapId);
                        }
                        break;

                    case LinkAction.OpenBeatmapSet:
                        if (int.TryParse(linkArgument, out int setId))
                        {
                            game?.ShowBeatmapSet(setId);
                        }
                        break;

                    case LinkAction.OpenChannel:
                        try
                        {
                            channelManager?.OpenChannel(linkArgument);
                        }
                        catch (ChannelNotFoundException)
                        {
                            Logger.Log($"The requested channel \"{linkArgument}\" does not exist");
                        }

                        break;

                    case LinkAction.OpenEditorTimestamp:
                    case LinkAction.JoinMultiplayerMatch:
                    case LinkAction.Spectate:
                        showNotImplementedError?.Invoke();
                        break;

                    case LinkAction.External:
                        game?.OpenUrlExternally(url);
                        break;

                    case LinkAction.OpenUserProfile:
                        if (long.TryParse(linkArgument, out long userId))
                        {
                            game?.ShowUser(userId);
                        }
                        break;

                    default:
                        throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
                    }
                }),
            });
Пример #2
0
        public void AddLink(string text, string url, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null, Action <SpriteText> creationParameters = null)
        {
            AddInternal(new DrawableLinkCompiler(AddText(text, creationParameters).ToList())
            {
                TooltipText = tooltipText ?? (url != text ? url : string.Empty),
                Action      = () =>
                {
                    switch (linkType)
                    {
                    case LinkAction.OpenBeatmap:
                        // TODO: proper query params handling
                        if (linkArgument != null && int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
                        {
                            game?.ShowBeatmap(beatmapId);
                        }
                        break;

                    case LinkAction.OpenBeatmapSet:
                        if (int.TryParse(linkArgument, out int setId))
                        {
                            game?.ShowBeatmapSet(setId);
                        }
                        break;

                    case LinkAction.OpenChannel:
                        game?.OpenChannel(linkArgument);
                        break;

                    case LinkAction.OpenEditorTimestamp:
                    case LinkAction.JoinMultiplayerMatch:
                    case LinkAction.Spectate:
                        showNotImplementedError?.Invoke();
                        break;

                    case LinkAction.External:
                        host.OpenUrlExternally(url);
                        break;

                    case LinkAction.OpenUserProfile:
                        if (long.TryParse(linkArgument, out long userId))
                        {
                            game?.ShowUser(userId);
                        }
                        break;

                    default:
                        throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
                    }
                },
            });
Пример #3
0
        public void AddLink(string text, string url, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null)
        {
            AddInternal(new DrawableLinkCompiler(AddText(text).ToList())
            {
                TooltipText = tooltipText ?? (url != text ? url : string.Empty),
                Action      = () =>
                {
                    switch (linkType)
                    {
                    case LinkAction.OpenBeatmap:
                        // todo: replace this with overlay.ShowBeatmap(id) once an appropriate API call is implemented.
                        if (int.TryParse(linkArgument, out int beatmapId))
                        {
                            Process.Start($"https://osu.ppy.sh/b/{beatmapId}");
                        }
                        break;

                    case LinkAction.OpenBeatmapSet:
                        if (int.TryParse(linkArgument, out int setId))
                        {
                            game?.ShowBeatmapSet(setId);
                        }
                        break;

                    case LinkAction.OpenChannel:
                        game?.OpenChannel(linkArgument);
                        break;

                    case LinkAction.OpenEditorTimestamp:
                    case LinkAction.JoinMultiplayerMatch:
                    case LinkAction.Spectate:
                        showNotImplementedError?.Invoke();
                        break;

                    case LinkAction.External:
                        Process.Start(url);
                        break;

                    case LinkAction.OpenUserProfile:
                        if (long.TryParse(linkArgument, out long userId))
                        {
                            game?.ShowUser(userId);
                        }
                        break;

                    default:
                        throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
                    }
                },
            });