osu/osu.Game/Overlays/Wiki/WikiSidebar.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.2 KiB
C#
Raw Normal View History

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