1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 08:32:54 +08:00
osu-lazer/osu.Game/Overlays/Wiki/WikiTableOfContents.cs

94 lines
3.0 KiB
C#
Raw Normal View History

2021-06-05 20:46:46 +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-05 20:46:46 +08:00
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Wiki
{
2022-11-24 13:32:20 +08:00
public partial class WikiTableOfContents : CompositeDrawable
2021-06-05 20:46:46 +08:00
{
private readonly FillFlowContainer content;
private TableOfContentsEntry lastMainTitle;
2021-06-05 20:46:46 +08:00
private TableOfContentsEntry lastSubTitle;
2021-06-05 20:46:46 +08:00
public WikiTableOfContents()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = content = new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
};
}
public void AddEntry(string title, MarkdownHeading target, bool subtitle = false)
{
var entry = new TableOfContentsEntry(title, target, subtitle);
if (subtitle)
{
lastMainTitle.Margin = new MarginPadding(0);
if (lastSubTitle != null)
lastSubTitle.Margin = new MarginPadding(0);
content.Add(lastSubTitle = entry.With(d => d.Margin = new MarginPadding { Bottom = 10 }));
2021-06-05 20:46:46 +08:00
return;
}
lastSubTitle = null;
2021-06-05 20:46:46 +08:00
content.Add(lastMainTitle = entry.With(d => d.Margin = new MarginPadding { Bottom = 5 }));
2021-06-05 20:46:46 +08:00
}
2022-11-24 13:32:20 +08:00
private partial class TableOfContentsEntry : OsuHoverContainer
2021-06-05 20:46:46 +08:00
{
private readonly MarkdownHeading target;
private readonly OsuTextFlowContainer textFlow;
public TableOfContentsEntry(string text, MarkdownHeading target, bool subtitle = false)
{
this.target = target;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Child = textFlow = new OsuTextFlowContainer(t =>
{
t.Font = OsuFont.GetFont(size: subtitle ? 12 : 15);
}).With(f =>
{
f.AddText(text);
f.RelativeSizeAxes = Axes.X;
f.AutoSizeAxes = Axes.Y;
f.Margin = new MarginPadding { Bottom = 2 };
2021-06-05 20:46:46 +08:00
});
Padding = new MarginPadding { Left = subtitle ? 10 : 0 };
2021-06-05 20:46:46 +08:00
}
protected override IEnumerable<Drawable> EffectTargets => new Drawable[] { textFlow };
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OverlayScrollContainer scrollContainer)
2021-06-05 20:46:46 +08:00
{
IdleColour = colourProvider.Light2;
HoverColour = colourProvider.Light1;
Action = () => scrollContainer.ScrollTo(target);
}
}
}
}