1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 18:42:56 +08:00
osu-lazer/osu.Game/Graphics/Containers/Markdown/OsuMarkdownLinkText.cs

73 lines
2.1 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using Markdig.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers.Markdown;
2022-06-21 02:04:21 +08:00
using osu.Game.Online;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
namespace osu.Game.Graphics.Containers.Markdown
{
public class OsuMarkdownLinkText : MarkdownLinkText
{
[Resolved(canBeNull: true)]
2022-06-21 02:04:21 +08:00
private ILinkHandler linkHandler { get; set; }
2021-05-26 13:13:00 +08:00
private readonly string text;
private readonly string title;
public OsuMarkdownLinkText(string text, LinkInline linkInline)
: base(text, linkInline)
{
2021-05-26 13:13:00 +08:00
this.text = text;
title = linkInline.Title;
}
2021-07-10 18:57:33 +08:00
public OsuMarkdownLinkText(AutolinkInline autolinkInline)
: base(autolinkInline)
{
text = autolinkInline.Url;
}
[BackgroundDependencyLoader]
2021-05-26 14:57:35 +08:00
private void load()
{
2021-05-26 13:13:00 +08:00
var textDrawable = CreateSpriteText().With(t => t.Text = text);
InternalChildren = new Drawable[]
{
2021-05-26 13:13:00 +08:00
textDrawable,
new OsuMarkdownLinkCompiler(new[] { textDrawable })
{
RelativeSizeAxes = Axes.Both,
Action = OnLinkPressed,
2021-05-26 13:13:00 +08:00
TooltipText = title ?? Url,
}
};
}
2022-06-21 02:04:21 +08:00
protected override void OnLinkPressed() => linkHandler?.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;
}
}
}
}