1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 16:17:52 +08:00
osu-lazer/osu.Game/Overlays/Wiki/WikiSidebar.cs

71 lines
2.2 KiB
C#
Raw Normal View History

2021-06-04 10:28:31 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-06-04 16:21:44 +08:00
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using osu.Framework.Extensions.LocalisationExtensions;
2021-06-04 11:16:49 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-06-04 11:17:38 +08:00
using osu.Framework.Graphics.Containers.Markdown;
2021-06-04 11:16:49 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Resources.Localisation.Web;
2021-06-04 11:16:49 +08:00
2021-06-04 10:28:31 +08:00
namespace osu.Game.Overlays.Wiki
{
2022-11-24 13:32:20 +08:00
public partial class WikiSidebar : OverlaySidebar
2021-06-04 10:28:31 +08:00
{
2021-06-05 20:47:00 +08:00
private WikiTableOfContents tableOfContents;
2021-06-04 11:16:49 +08:00
protected override Drawable CreateContent() => new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = WikiStrings.ShowToc.ToUpper(),
2021-06-04 11:16:49 +08:00
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
2021-06-05 20:47:00 +08:00
Margin = new MarginPadding { Bottom = 5 },
2021-06-04 11:16:49 +08:00
},
2021-06-05 20:47:00 +08:00
tableOfContents = new WikiTableOfContents(),
2021-06-04 11:16:49 +08:00
},
};
2021-06-04 11:17:38 +08:00
2021-06-05 00:32:42 +08:00
public void AddEntry(HeadingBlock headingBlock, MarkdownHeading heading)
2021-06-04 11:17:38 +08:00
{
2021-06-04 16:21:44 +08:00
switch (headingBlock.Level)
2021-06-04 11:17:38 +08:00
{
case 2:
2021-06-04 12:12:42 +08:00
case 3:
2021-06-05 20:47:00 +08:00
tableOfContents.AddEntry(getTitle(headingBlock.Inline), heading, headingBlock.Level == 3);
2021-06-04 12:12:42 +08:00
break;
2021-06-04 11:17:38 +08:00
}
}
2021-06-04 12:09:20 +08:00
2021-06-04 16:21:44 +08:00
private string getTitle(ContainerInline containerInline)
{
foreach (var inline in containerInline)
{
switch (inline)
{
case LiteralInline literalInline:
return literalInline.Content.ToString();
2021-06-05 19:26:03 +08:00
case LinkInline linkInline:
if (!linkInline.IsImage)
return getTitle(linkInline);
break;
2021-06-04 16:21:44 +08:00
}
}
return string.Empty;
}
2021-06-04 10:28:31 +08:00
}
}