create local link flow container

This commit is contained in:
Gagah Pangeran Rosfatiputra 2021-08-12 20:36:47 +07:00
parent 40db228e91
commit 66ba24e865
No known key found for this signature in database
GPG Key ID: 25F6F17FD29031E2
1 changed files with 40 additions and 6 deletions

View File

@ -1,6 +1,8 @@
// 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;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
@ -12,6 +14,7 @@
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osu.Game.Resources.Localisation.Web;
using osuTK;
using osuTK.Graphics;
@ -25,9 +28,6 @@ public class ChangelogSupporterPromo : CompositeDrawable
private readonly FillFlowContainer textContainer;
private readonly Container imageContainer;
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Pink);
public ChangelogSupporterPromo()
{
RelativeSizeAxes = Axes.X;
@ -93,7 +93,7 @@ public ChangelogSupporterPromo()
[BackgroundDependencyLoader]
private void load(OsuColour colour, TextureStore textures)
{
LinkFlowContainer supportLinkText;
SupporterPromoLinkFlowContainer supportLinkText;
textContainer.Children = new Drawable[]
{
new OsuSpriteText
@ -102,7 +102,7 @@ private void load(OsuColour colour, TextureStore textures)
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Light),
Margin = new MarginPadding { Bottom = 20 },
},
supportLinkText = new LinkFlowContainer(t =>
supportLinkText = new SupporterPromoLinkFlowContainer(t =>
{
t.Font = t.Font.With(size: 14);
t.Colour = colour.PinkLighter;
@ -125,7 +125,7 @@ private void load(OsuColour colour, TextureStore textures)
};
supportLinkText.AddText("Support further development of osu! and ");
supportLinkText.AddLink("become an osu!supporter", "https://osu.ppy.sh/home/support", t => t.Font = t.Font.With(weight: FontWeight.Bold));
supportLinkText.AddLink("become and osu!supporter", "https://osu.ppy.sh/home/support", t => t.Font = t.Font.With(weight: FontWeight.Bold));
supportLinkText.AddText(" today!");
imageContainer.Children = new Drawable[]
@ -149,5 +149,39 @@ private void load(OsuColour colour, TextureStore textures)
},
};
}
private class SupporterPromoLinkFlowContainer : LinkFlowContainer
{
public SupporterPromoLinkFlowContainer(Action<SpriteText> defaultCreationParameters)
: base(defaultCreationParameters)
{
}
public new void AddLink(string text, string url, Action<SpriteText> creationParameters) =>
AddInternal(new SupporterPromoLinkCompiler(AddText(text, creationParameters)) { Url = url });
private class SupporterPromoLinkCompiler : DrawableLinkCompiler
{
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
public string Url;
public SupporterPromoLinkCompiler(IEnumerable<Drawable> parts)
: base(parts)
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
TooltipText = Url;
Action = () => game?.HandleLink(Url);
IdleColour = colour.PinkDark;
HoverColour = Color4.White;
}
}
}
}
}