mirror of
https://github.com/ppy/osu.git
synced 2024-11-12 04:49:40 +08:00
110 lines
3.4 KiB
C#
110 lines
3.4 KiB
C#
// 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;
|
|
using System.Linq;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using HtmlAgilityPack;
|
|
using osu.Framework.Allocation;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
namespace osu.Game.Overlays.Wiki
|
|
{
|
|
public class WikiMainPage : FillFlowContainer
|
|
{
|
|
public string Markdown;
|
|
|
|
public WikiMainPage()
|
|
{
|
|
RelativeSizeAxes = Axes.X;
|
|
AutoSizeAxes = Axes.Y;
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
var html = new HtmlDocument();
|
|
html.LoadHtml(Markdown);
|
|
|
|
Children = new Drawable[]
|
|
{
|
|
createBlurb(html),
|
|
new GridContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
},
|
|
};
|
|
}
|
|
|
|
private Container createBlurb(HtmlDocument html)
|
|
{
|
|
var blurbNode = html.DocumentNode.SelectNodes("//div[contains(@class, 'wiki-main-page__blurb')]").First();
|
|
|
|
return new Container
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Padding = new MarginPadding
|
|
{
|
|
Vertical = 30,
|
|
},
|
|
Child = new OsuSpriteText
|
|
{
|
|
Text = blurbNode.InnerText,
|
|
Font = OsuFont.GetFont(size: 12),
|
|
Anchor = Anchor.TopCentre,
|
|
Origin = Anchor.TopCentre,
|
|
}
|
|
};
|
|
}
|
|
|
|
private IEnumerable<Drawable[]> createPanels(HtmlDocument html)
|
|
{
|
|
var panelsNode = html.DocumentNode.SelectNodes("//div[contains(@class, 'wiki-main-page-panel')]").ToArray();
|
|
|
|
for (var i = 0; i < panelsNode.Length; i++)
|
|
{
|
|
var isFullWidth = panelsNode[i].HasClass("wiki-main-page-panel--full");
|
|
|
|
if (isFullWidth)
|
|
{
|
|
yield return new Drawable[]
|
|
{
|
|
new WikiPanelContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Text = panelsNode[i].InnerText,
|
|
IsFullWidth = true,
|
|
Width = 2,
|
|
},
|
|
null,
|
|
};
|
|
}
|
|
|
|
if (i % 2 == 1)
|
|
{
|
|
yield return new Drawable[]
|
|
{
|
|
new WikiPanelContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Text = panelsNode[i].InnerText,
|
|
},
|
|
new WikiPanelContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Text = panelsNode[i + 1].InnerText,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|