1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 18:27:31 +08:00
osu-lazer/osu.Game/Overlays/Wiki/Markdown/WikiNoticeContainer.cs

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

115 lines
3.6 KiB
C#
Raw Normal View History

2021-05-21 17:04:08 +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.
using Markdig.Extensions.Yaml;
2021-05-21 17:06:43 +08:00
using osu.Framework.Allocation;
2021-05-21 17:04:08 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-05-21 17:06:43 +08:00
using osu.Framework.Graphics.Containers.Markdown;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
2021-05-21 17:06:43 +08:00
using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web;
using osuTK;
2021-05-21 17:04:08 +08:00
namespace osu.Game.Overlays.Wiki.Markdown
{
public partial class WikiNoticeContainer : FillFlowContainer
{
2021-05-21 17:05:37 +08:00
private readonly bool isOutdated;
private readonly bool needsCleanup;
private readonly bool isStub;
2021-05-21 17:05:37 +08:00
2021-05-21 17:04:08 +08:00
public WikiNoticeContainer(YamlFrontMatterBlock yamlFrontMatterBlock)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
Spacing = new Vector2(10);
2021-05-21 17:05:37 +08:00
foreach (object line in yamlFrontMatterBlock.Lines)
2021-05-21 17:05:37 +08:00
{
switch (line.ToString())
{
2023-03-12 13:35:52 +08:00
case @"outdated: true":
2021-05-21 17:05:37 +08:00
isOutdated = true;
break;
2023-03-12 13:35:52 +08:00
case @"needs_cleanup: true":
2021-05-21 17:05:37 +08:00
needsCleanup = true;
break;
case @"stub: true":
isStub = true;
break;
2021-05-21 17:05:37 +08:00
}
}
2021-05-21 17:04:08 +08:00
}
2021-05-21 17:06:43 +08:00
2021-05-21 17:08:30 +08:00
[BackgroundDependencyLoader]
private void load()
{
// Reference : https://github.com/ppy/osu-web/blob/master/resources/views/wiki/_notice.blade.php and https://github.com/ppy/osu-web/blob/master/resources/lang/en/wiki.php
// TODO : add notice box for fallback translation, legal translation and outdated translation after implement wiki locale in the future.
if (isOutdated)
{
Add(new NoticeBox
{
Text = WikiStrings.ShowIncompleteOrOutdated,
2021-05-21 17:08:30 +08:00
});
}
else if (needsCleanup)
{
Add(new NoticeBox
{
Text = WikiStrings.ShowNeedsCleanupOrRewrite,
2021-05-21 17:08:30 +08:00
});
}
if (isStub)
{
Add(new NoticeBox
{
Text = WikiStrings.ShowStub,
});
}
2021-05-21 17:08:30 +08:00
}
2021-05-21 17:06:43 +08:00
private partial class NoticeBox : Container
{
[Resolved]
private IMarkdownTextFlowComponent parentFlowComponent { get; set; } = null!;
public LocalisableString Text { get; set; }
2021-05-21 17:06:43 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OsuColour colour)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
MarkdownTextFlowContainer textFlow;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
},
textFlow = parentFlowComponent.CreateTextFlow().With(t =>
{
t.Colour = colour.Orange1;
t.Padding = new MarginPadding
{
Vertical = 10,
Horizontal = 15,
};
})
};
textFlow.AddText(Text);
}
}
2021-05-21 17:04:08 +08:00
}
}