2022-12-17 03:59:14 +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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-12-17 04:56:32 +08:00
|
|
|
using System.Linq;
|
2022-12-17 03:59:14 +08:00
|
|
|
using Markdig.Extensions.Footnotes;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Localisation;
|
2022-12-17 04:56:32 +08:00
|
|
|
using osu.Framework.Testing;
|
2022-12-17 03:59:14 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers.Markdown.Footnotes
|
|
|
|
{
|
|
|
|
public partial class OsuMarkdownFootnoteLink : OsuHoverContainer, IHasCustomTooltip
|
|
|
|
{
|
2022-12-17 04:56:32 +08:00
|
|
|
public readonly FootnoteLink FootnoteLink;
|
2022-12-17 03:59:14 +08:00
|
|
|
|
|
|
|
private SpriteText spriteText = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IMarkdownTextComponent parentTextComponent { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuMarkdownContainer markdownContainer { get; set; } = null!;
|
|
|
|
|
|
|
|
protected override IEnumerable<Drawable> EffectTargets => spriteText.Yield();
|
|
|
|
|
|
|
|
public OsuMarkdownFootnoteLink(FootnoteLink footnoteLink)
|
|
|
|
{
|
2022-12-17 04:56:32 +08:00
|
|
|
FootnoteLink = footnoteLink;
|
2022-12-17 03:59:14 +08:00
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2022-12-17 04:56:32 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(OsuMarkdownContainer markdownContainer, OverlayScrollContainer? scrollContainer)
|
2022-12-17 03:59:14 +08:00
|
|
|
{
|
|
|
|
IdleColour = colourProvider.Light2;
|
|
|
|
HoverColour = colourProvider.Light1;
|
|
|
|
|
|
|
|
spriteText = parentTextComponent.CreateSpriteText();
|
|
|
|
|
|
|
|
Add(spriteText.With(t =>
|
|
|
|
{
|
|
|
|
float baseSize = t.Font.Size;
|
|
|
|
t.Font = t.Font.With(size: baseSize * 0.58f);
|
|
|
|
t.Margin = new MarginPadding { Bottom = 0.33f * baseSize };
|
2022-12-17 04:56:32 +08:00
|
|
|
t.Text = LocalisableString.Format("[{0}]", FootnoteLink.Index);
|
2022-12-17 03:59:14 +08:00
|
|
|
}));
|
2022-12-17 04:56:32 +08:00
|
|
|
|
|
|
|
if (scrollContainer != null)
|
|
|
|
{
|
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
var footnote = markdownContainer.ChildrenOfType<OsuMarkdownFootnote>().Single(footnote => footnote.Footnote.Label == FootnoteLink.Footnote.Label);
|
|
|
|
scrollContainer.ScrollIntoView(footnote);
|
|
|
|
};
|
|
|
|
}
|
2022-12-17 03:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public object TooltipContent
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2022-12-17 04:56:32 +08:00
|
|
|
var span = FootnoteLink.Footnote.LastChild.Span;
|
2022-12-17 03:59:14 +08:00
|
|
|
return markdownContainer.Text.Substring(span.Start, span.Length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ITooltip GetCustomTooltip() => new OsuMarkdownFootnoteTooltip(colourProvider);
|
|
|
|
}
|
|
|
|
}
|