2021-05-23 18:56:27 +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-05-23 22:42:58 +08:00
|
|
|
using System;
|
2021-05-23 19:07:27 +08:00
|
|
|
using Markdig.Syntax;
|
2021-05-23 18:56:27 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-23 19:07:27 +08:00
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
2021-05-23 18:56:27 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-05-23 19:10:56 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-05-23 19:07:27 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers.Markdown;
|
2021-06-01 12:32:52 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-05-23 18:56:27 +08:00
|
|
|
using osu.Game.Overlays.Wiki.Markdown;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Wiki
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class WikiPanelContainer : Container
|
2021-05-23 18:56:27 +08:00
|
|
|
{
|
2021-05-23 22:42:58 +08:00
|
|
|
private WikiPanelMarkdownContainer panelContainer;
|
|
|
|
|
2021-05-27 13:04:50 +08:00
|
|
|
private readonly string text;
|
2021-05-23 18:56:27 +08:00
|
|
|
|
2021-05-27 13:04:50 +08:00
|
|
|
private readonly bool isFullWidth;
|
2021-05-23 19:03:38 +08:00
|
|
|
|
2021-05-27 13:04:50 +08:00
|
|
|
public WikiPanelContainer(string text, bool isFullWidth = false)
|
2021-05-23 22:31:49 +08:00
|
|
|
{
|
2021-05-27 13:04:50 +08:00
|
|
|
this.text = text;
|
|
|
|
this.isFullWidth = isFullWidth;
|
|
|
|
|
2021-05-23 22:31:49 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Padding = new MarginPadding(3);
|
|
|
|
}
|
|
|
|
|
2021-05-23 18:56:27 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2021-06-01 12:32:52 +08:00
|
|
|
private void load(OverlayColourProvider colourProvider, IAPIProvider api)
|
2021-05-23 18:56:27 +08:00
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 4,
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Colour = Color4.Black.Opacity(25),
|
|
|
|
Offset = new Vector2(0, 1),
|
|
|
|
Radius = 3,
|
|
|
|
},
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
Colour = colourProvider.Background4,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
},
|
2021-05-27 13:04:50 +08:00
|
|
|
panelContainer = new WikiPanelMarkdownContainer(isFullWidth)
|
2021-05-23 18:56:27 +08:00
|
|
|
{
|
2021-06-01 12:32:52 +08:00
|
|
|
CurrentPath = $@"{api.WebsiteRootUrl}/wiki/",
|
2021-05-27 13:04:50 +08:00
|
|
|
Text = text,
|
2021-05-23 18:56:27 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-05-23 19:00:54 +08:00
|
|
|
|
2021-05-23 22:42:58 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
2023-10-17 16:40:44 +08:00
|
|
|
Height = Math.Max(panelContainer.Height, Parent!.DrawHeight);
|
2021-05-23 22:42:58 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class WikiPanelMarkdownContainer : WikiMarkdownContainer
|
2021-05-23 19:00:54 +08:00
|
|
|
{
|
2021-05-27 13:04:50 +08:00
|
|
|
private readonly bool isFullWidth;
|
2021-05-23 19:03:38 +08:00
|
|
|
|
2021-05-27 13:04:50 +08:00
|
|
|
public WikiPanelMarkdownContainer(bool isFullWidth)
|
2021-05-23 19:00:54 +08:00
|
|
|
{
|
2021-05-27 13:04:50 +08:00
|
|
|
this.isFullWidth = isFullWidth;
|
|
|
|
|
2021-05-23 19:00:54 +08:00
|
|
|
LineSpacing = 0;
|
|
|
|
DocumentPadding = new MarginPadding(30);
|
|
|
|
DocumentMargin = new MarginPadding(0);
|
|
|
|
}
|
2021-05-23 19:07:27 +08:00
|
|
|
|
2021-08-03 23:17:45 +08:00
|
|
|
public override SpriteText CreateSpriteText() => base.CreateSpriteText().With(t => t.Font = t.Font.With(Typeface.Torus, weight: FontWeight.Bold));
|
2021-05-23 19:10:56 +08:00
|
|
|
|
2023-11-16 11:43:25 +08:00
|
|
|
public override OsuMarkdownTextFlowContainer CreateTextFlow() => base.CreateTextFlow().With(f => f.TextAnchor = Anchor.TopCentre);
|
2021-05-23 19:09:09 +08:00
|
|
|
|
2021-05-23 19:11:54 +08:00
|
|
|
protected override MarkdownParagraph CreateParagraph(ParagraphBlock paragraphBlock, int level)
|
|
|
|
=> base.CreateParagraph(paragraphBlock, level).With(p => p.Margin = new MarginPadding { Bottom = 10 });
|
|
|
|
|
2021-05-23 19:07:27 +08:00
|
|
|
protected override MarkdownHeading CreateHeading(HeadingBlock headingBlock) => new WikiPanelHeading(headingBlock)
|
|
|
|
{
|
2021-05-27 13:04:50 +08:00
|
|
|
IsFullWidth = isFullWidth,
|
2021-05-23 19:07:27 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class WikiPanelHeading : OsuMarkdownHeading
|
2021-05-23 19:07:27 +08:00
|
|
|
{
|
|
|
|
public bool IsFullWidth;
|
|
|
|
|
|
|
|
public WikiPanelHeading(HeadingBlock headingBlock)
|
|
|
|
: base(headingBlock)
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding { Bottom = 40 };
|
|
|
|
}
|
|
|
|
|
|
|
|
public override MarkdownTextFlowContainer CreateTextFlow() => base.CreateTextFlow().With(f =>
|
|
|
|
{
|
|
|
|
f.Anchor = Anchor.TopCentre;
|
|
|
|
f.Origin = Anchor.TopCentre;
|
|
|
|
f.TextAnchor = Anchor.TopCentre;
|
|
|
|
});
|
|
|
|
|
2021-05-23 22:46:41 +08:00
|
|
|
protected override FontWeight GetFontWeightByLevel(int level) => FontWeight.Light;
|
2021-05-23 19:07:27 +08:00
|
|
|
|
|
|
|
protected override float GetFontSizeByLevel(int level) => base.GetFontSizeByLevel(IsFullWidth ? level : 3);
|
2021-05-23 19:00:54 +08:00
|
|
|
}
|
2021-05-23 18:56:27 +08:00
|
|
|
}
|
|
|
|
}
|