mirror of
https://github.com/osukey/osukey.git
synced 2025-06-30 07:38:04 +09:00
use drawable link compiler in markdown link
This commit is contained in:
parent
774611f142
commit
02cdd0b2de
@ -1,48 +1,62 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using Markdig.Syntax.Inlines;
|
using Markdig.Syntax.Inlines;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers.Markdown;
|
using osu.Framework.Graphics.Containers.Markdown;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Game.Online.Chat;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers.Markdown
|
namespace osu.Game.Graphics.Containers.Markdown
|
||||||
{
|
{
|
||||||
public class OsuMarkdownLinkText : MarkdownLinkText
|
public class OsuMarkdownLinkText : MarkdownLinkText
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved(canBeNull: true)]
|
||||||
private OverlayColourProvider colourProvider { get; set; }
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
private SpriteText spriteText;
|
protected string Text;
|
||||||
|
protected string Title;
|
||||||
|
|
||||||
public OsuMarkdownLinkText(string text, LinkInline linkInline)
|
public OsuMarkdownLinkText(string text, LinkInline linkInline)
|
||||||
: base(text, linkInline)
|
: base(text, linkInline)
|
||||||
{
|
{
|
||||||
|
Text = text;
|
||||||
|
Title = linkInline.Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
spriteText.Colour = colourProvider.Light2;
|
var text = CreateSpriteText().With(t => t.Text = Text);
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
text,
|
||||||
|
new OsuMarkdownLinkCompiler(new[] { text })
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Action = OnLinkPressed,
|
||||||
|
TooltipText = Title ?? Url,
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override SpriteText CreateSpriteText()
|
protected override void OnLinkPressed() => game?.HandleLink(Url);
|
||||||
|
|
||||||
|
private class OsuMarkdownLinkCompiler : DrawableLinkCompiler
|
||||||
|
{
|
||||||
|
public OsuMarkdownLinkCompiler(IEnumerable<Drawable> parts)
|
||||||
|
: base(parts)
|
||||||
{
|
{
|
||||||
return spriteText = base.CreateSpriteText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
spriteText.Colour = colourProvider.Light1;
|
IdleColour = colourProvider.Light2;
|
||||||
return base.OnHover(e);
|
HoverColour = colourProvider.Light1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
|
||||||
{
|
|
||||||
spriteText.Colour = colourProvider.Light2;
|
|
||||||
base.OnHoverLost(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user