1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 16:37:24 +08:00
osu-lazer/osu.Game/Overlays/Wiki/WikiSidebar.cs

67 lines
2.0 KiB
C#
Raw Normal View History

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