2021-05-21 11:04:45 +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.
|
|
|
|
|
2021-05-23 18:56:27 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-05-21 11:04:45 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-21 11:04:45 +08:00
|
|
|
using HtmlAgilityPack;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-05-21 11:04:45 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Wiki
|
|
|
|
{
|
|
|
|
public class WikiMainPage : FillFlowContainer
|
|
|
|
{
|
2021-05-21 11:04:45 +08:00
|
|
|
public string Markdown;
|
|
|
|
|
2021-05-21 11:04:45 +08:00
|
|
|
public WikiMainPage()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
}
|
2021-05-21 11:04:45 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
var html = new HtmlDocument();
|
|
|
|
html.LoadHtml(Markdown);
|
|
|
|
|
2021-05-23 20:07:22 +08:00
|
|
|
var panels = createPanels(html).ToArray();
|
|
|
|
|
2021-05-21 11:04:45 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-05-23 19:52:20 +08:00
|
|
|
createBlurb(html),
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-05-23 20:07:22 +08:00
|
|
|
RowDimensions = Enumerable.Repeat(new Dimension(GridSizeMode.AutoSize), panels.Length).ToArray(),
|
|
|
|
Content = panels,
|
2021-05-23 19:52:20 +08:00
|
|
|
},
|
2021-05-21 11:04:45 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-05-23 18:49:26 +08:00
|
|
|
|
2021-05-23 20:07:10 +08:00
|
|
|
private IEnumerable<Drawable[]> createPanels(HtmlDocument html)
|
2021-05-23 18:49:26 +08:00
|
|
|
{
|
2021-05-23 20:07:10 +08:00
|
|
|
var panelsNode = html.DocumentNode.SelectNodes("//div[contains(@class, 'wiki-main-page-panel')]").ToArray();
|
2021-05-23 18:49:26 +08:00
|
|
|
|
2021-05-23 20:07:10 +08:00
|
|
|
for (var i = 0; i < panelsNode.Length; i++)
|
2021-05-23 18:49:26 +08:00
|
|
|
{
|
2021-05-23 20:07:10 +08:00
|
|
|
var isFullWidth = panelsNode[i].HasClass("wiki-main-page-panel--full");
|
2021-05-23 18:49:26 +08:00
|
|
|
|
2021-05-23 20:07:10 +08:00
|
|
|
if (isFullWidth)
|
2021-05-23 18:49:26 +08:00
|
|
|
{
|
2021-05-23 20:07:10 +08:00
|
|
|
yield return new Drawable[]
|
|
|
|
{
|
|
|
|
new WikiPanelContainer
|
|
|
|
{
|
|
|
|
Text = panelsNode[i].InnerText,
|
|
|
|
IsFullWidth = true,
|
|
|
|
Width = 2,
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i % 2 == 1)
|
|
|
|
{
|
|
|
|
yield return new Drawable[]
|
|
|
|
{
|
|
|
|
new WikiPanelContainer
|
|
|
|
{
|
|
|
|
Text = panelsNode[i].InnerText,
|
|
|
|
},
|
|
|
|
new WikiPanelContainer
|
|
|
|
{
|
|
|
|
Text = panelsNode[i + 1].InnerText,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-05-23 18:49:26 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-21 11:04:45 +08:00
|
|
|
}
|
|
|
|
}
|