osu/osu.Game/Overlays/Wiki/WikiPanelContainer.cs

125 lines
4.1 KiB
C#
Raw Normal View History

2021-05-23 10:56:27 +00: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 System;
2021-05-23 11:07:27 +00:00
using Markdig.Syntax;
2021-05-23 10:56:27 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-05-23 11:07:27 +00:00
using osu.Framework.Graphics.Containers.Markdown;
2021-05-23 10:56:27 +00:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
2021-05-23 11:10:56 +00:00
using osu.Framework.Graphics.Sprites;
2021-05-23 11:07:27 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers.Markdown;
2021-05-23 10:56:27 +00:00
using osu.Game.Overlays.Wiki.Markdown;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Wiki
{
public class WikiPanelContainer : Container
{
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private WikiPanelMarkdownContainer panelContainer;
2021-05-23 10:56:27 +00:00
public string Text;
2021-05-23 11:03:38 +00:00
public bool IsFullWidth;
2021-05-23 14:31:49 +00:00
public WikiPanelContainer()
{
RelativeSizeAxes = Axes.X;
Padding = new MarginPadding(3);
}
2021-05-23 10:56:27 +00:00
[BackgroundDependencyLoader]
private void load()
{
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,
},
},
panelContainer = new WikiPanelMarkdownContainer
2021-05-23 10:56:27 +00:00
{
Text = Text,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2021-05-23 11:03:38 +00:00
IsFullWidth = IsFullWidth,
2021-05-23 10:56:27 +00:00
}
};
}
2021-05-23 11:00:54 +00:00
protected override void Update()
{
base.Update();
Height = Math.Max(panelContainer.Height, Parent.DrawHeight);
}
2021-05-23 11:00:54 +00:00
private class WikiPanelMarkdownContainer : WikiMarkdownContainer
{
2021-05-23 11:03:38 +00:00
public bool IsFullWidth;
2021-05-23 11:00:54 +00:00
public WikiPanelMarkdownContainer()
{
LineSpacing = 0;
DocumentPadding = new MarginPadding(30);
DocumentMargin = new MarginPadding(0);
}
2021-05-23 11:07:27 +00:00
2021-05-23 11:10:56 +00:00
public override SpriteText CreateSpriteText() => base.CreateSpriteText().With(t => t.Font = t.Font.With(weight: FontWeight.Bold));
2021-05-23 11:09:09 +00:00
public override MarkdownTextFlowContainer CreateTextFlow() => base.CreateTextFlow().With(f => f.TextAnchor = Anchor.TopCentre);
2021-05-23 11:11:54 +00:00
protected override MarkdownParagraph CreateParagraph(ParagraphBlock paragraphBlock, int level)
=> base.CreateParagraph(paragraphBlock, level).With(p => p.Margin = new MarginPadding { Bottom = 10 });
2021-05-23 11:07:27 +00:00
protected override MarkdownHeading CreateHeading(HeadingBlock headingBlock) => new WikiPanelHeading(headingBlock)
{
IsFullWidth = IsFullWidth,
};
}
private class WikiPanelHeading : OsuMarkdownHeading
{
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 14:46:41 +00:00
protected override FontWeight GetFontWeightByLevel(int level) => FontWeight.Light;
2021-05-23 11:07:27 +00:00
protected override float GetFontSizeByLevel(int level) => base.GetFontSizeByLevel(IsFullWidth ? level : 3);
2021-05-23 11:00:54 +00:00
}
2021-05-23 10:56:27 +00:00
}
}