1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:47:28 +08:00

create WikiMarkdownImageBlock

This commit is contained in:
Gagah Pangeran Rosfatiputra 2021-05-26 19:22:21 +07:00
parent fbfbd99223
commit 62fb09774a
No known key found for this signature in database
GPG Key ID: 25F6F17FD29031E2
2 changed files with 49 additions and 40 deletions

View File

@ -0,0 +1,49 @@
// 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.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
using osuTK;
namespace osu.Game.Overlays.Wiki.Markdown
{
public class WikiMarkdownImageBlock : FillFlowContainer
{
[Resolved]
private IMarkdownTextComponent parentTextComponent { get; set; }
private readonly LinkInline linkInline;
public WikiMarkdownImageBlock(LinkInline linkInline)
{
this.linkInline = linkInline;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
Spacing = new Vector2(0, 3);
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new WikiMarkdownImage(linkInline)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
parentTextComponent.CreateSpriteText().With(t =>
{
t.Text = linkInline.Title;
t.Anchor = Anchor.TopCentre;
t.Origin = Anchor.TopCentre;
}),
};
}
}
}

View File

@ -1,40 +0,0 @@
// 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.Linq;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers.Markdown;
using osuTK;
namespace osu.Game.Overlays.Wiki.Markdown
{
public class WikiMarkdownParagraph : MarkdownParagraph
{
private readonly ParagraphBlock paragraphBlock;
public WikiMarkdownParagraph(ParagraphBlock paragraphBlock)
: base(paragraphBlock)
{
this.paragraphBlock = paragraphBlock;
}
[BackgroundDependencyLoader]
private void load()
{
MarkdownTextFlowContainer textFlow;
InternalChild = textFlow = CreateTextFlow();
textFlow.AddInlineText(paragraphBlock.Inline);
// Check if paragraph only contains an image.
if (paragraphBlock.Inline.Count() == 1 && paragraphBlock.Inline.FirstChild is LinkInline { IsImage: true } linkInline)
{
textFlow.TextAnchor = Anchor.TopCentre;
textFlow.Spacing = new Vector2(0, 5);
textFlow.AddText($"\n{linkInline.Title}");
}
}
}
}