1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 15:17:30 +08:00
osu-lazer/osu.Game/Graphics/Containers/Markdown/OsuMarkdownLinkText.cs

63 lines
1.9 KiB
C#
Raw Normal View History

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