2021-04-27 15:15:19 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-05-24 20:10:37 +08:00
|
|
|
using System.Collections.Generic;
|
2021-04-27 15:15:19 +08:00
|
|
|
using Markdig.Syntax.Inlines;
|
|
|
|
using osu.Framework.Allocation;
|
2021-05-24 20:10:37 +08:00
|
|
|
using osu.Framework.Graphics;
|
2021-04-27 15:15:19 +08:00
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
2021-05-24 20:10:37 +08:00
|
|
|
using osu.Game.Online.Chat;
|
2021-04-27 15:15:19 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers.Markdown
|
|
|
|
{
|
|
|
|
public class OsuMarkdownLinkText : MarkdownLinkText
|
|
|
|
{
|
2021-05-24 20:10:37 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private OsuGame game { get; set; }
|
2021-05-02 23:41:11 +08:00
|
|
|
|
2021-05-24 20:10:37 +08:00
|
|
|
protected string Text;
|
|
|
|
protected string Title;
|
2021-04-27 15:15:19 +08:00
|
|
|
|
|
|
|
public OsuMarkdownLinkText(string text, LinkInline linkInline)
|
|
|
|
: base(text, linkInline)
|
|
|
|
{
|
2021-05-24 20:10:37 +08:00
|
|
|
Text = text;
|
|
|
|
Title = linkInline.Title;
|
2021-04-27 15:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-05-24 20:10:37 +08:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2021-04-27 15:15:19 +08:00
|
|
|
{
|
2021-05-24 20:10:37 +08:00
|
|
|
var text = CreateSpriteText().With(t => t.Text = Text);
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
text,
|
|
|
|
new OsuMarkdownLinkCompiler(new[] { text })
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Action = OnLinkPressed,
|
|
|
|
TooltipText = Title ?? Url,
|
|
|
|
}
|
|
|
|
};
|
2021-04-27 15:15:19 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 20:10:37 +08:00
|
|
|
protected override void OnLinkPressed() => game?.HandleLink(Url);
|
2021-05-02 23:41:11 +08:00
|
|
|
|
2021-05-24 20:10:37 +08:00
|
|
|
private class OsuMarkdownLinkCompiler : DrawableLinkCompiler
|
2021-05-02 23:41:11 +08:00
|
|
|
{
|
2021-05-24 20:10:37 +08:00
|
|
|
public OsuMarkdownLinkCompiler(IEnumerable<Drawable> parts)
|
|
|
|
: base(parts)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
IdleColour = colourProvider.Light2;
|
|
|
|
HoverColour = colourProvider.Light1;
|
|
|
|
}
|
2021-05-02 23:41:11 +08:00
|
|
|
}
|
2021-04-27 15:15:19 +08:00
|
|
|
}
|
|
|
|
}
|