osu/osu.Game/Overlays/Changelog/ChangelogSupporterPromo.cs

201 lines
7.5 KiB
C#
Raw Normal View History

// 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.
2021-08-12 13:36:47 +00:00
using System;
using System.Collections.Generic;
2021-08-10 06:21:23 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-08-10 05:11:21 +00:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
2021-08-10 06:21:23 +00:00
using osu.Framework.Graphics.Sprites;
2021-08-10 07:07:20 +00:00
using osu.Framework.Graphics.Textures;
2021-08-10 06:21:23 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2021-08-12 13:36:47 +00:00
using osu.Game.Online.Chat;
2021-08-10 06:21:23 +00:00
using osu.Game.Resources.Localisation.Web;
2021-08-10 05:11:21 +00:00
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogSupporterPromo : CompositeDrawable
{
2021-08-10 07:07:20 +00:00
private const float image_container_width = 164;
private const float heart_size = 75;
2021-08-10 06:53:06 +00:00
2021-08-11 05:49:22 +00:00
private readonly FillFlowContainer textContainer;
2021-08-10 07:07:20 +00:00
private readonly Container imageContainer;
2021-08-10 06:21:23 +00:00
public ChangelogSupporterPromo()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding
{
Vertical = 20,
Horizontal = 50,
};
2021-08-10 06:21:23 +00:00
InternalChildren = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2021-08-10 05:11:21 +00:00
Masking = true,
CornerRadius = 6,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Offset = new Vector2(0, 1),
Radius = 3,
},
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.3f),
},
2021-08-10 06:53:06 +00:00
new Container
{
RelativeSizeAxes = Axes.X,
Height = 200,
2021-08-10 06:21:23 +00:00
Padding = new MarginPadding { Horizontal = 75 },
Children = new Drawable[]
{
2021-08-11 05:49:22 +00:00
textContainer = new FillFlowContainer
2021-08-10 06:21:23 +00:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2021-08-10 07:07:20 +00:00
Padding = new MarginPadding { Right = 50 + image_container_width },
2021-08-10 06:21:23 +00:00
},
2021-08-10 07:07:20 +00:00
imageContainer = new Container
2021-08-10 06:53:06 +00:00
{
RelativeSizeAxes = Axes.Y,
2021-08-10 07:07:20 +00:00
Width = image_container_width,
2021-08-10 06:53:06 +00:00
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
2021-08-10 06:21:23 +00:00
}
},
}
},
};
}
2021-08-10 06:21:23 +00:00
[BackgroundDependencyLoader]
2021-08-10 07:07:20 +00:00
private void load(OsuColour colour, TextureStore textures)
2021-08-10 06:21:23 +00:00
{
2021-08-12 13:36:47 +00:00
SupporterPromoLinkFlowContainer supportLinkText;
2021-08-11 05:49:22 +00:00
textContainer.Children = new Drawable[]
{
new OsuSpriteText
{
Text = ChangelogStrings.SupportHeading,
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Light),
Margin = new MarginPadding { Bottom = 20 },
},
2021-08-12 13:36:47 +00:00
supportLinkText = new SupporterPromoLinkFlowContainer(t =>
2021-08-11 05:49:22 +00:00
{
t.Font = t.Font.With(size: 14);
t.Colour = colour.PinkLighter;
})
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
2021-08-12 12:34:44 +00:00
new OsuTextFlowContainer(t =>
2021-08-11 05:49:22 +00:00
{
t.Font = t.Font.With(size: 12);
t.Colour = colour.PinkLighter;
})
{
Text = ChangelogStrings.SupportText2.ToString(),
2021-08-11 05:49:22 +00:00
Margin = new MarginPadding { Top = 10 },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
};
2021-08-10 06:21:23 +00:00
2021-08-11 05:49:22 +00:00
supportLinkText.AddText("Support further development of osu! and ");
2021-08-12 13:36:47 +00:00
supportLinkText.AddLink("become and osu!supporter", "https://osu.ppy.sh/home/support", t => t.Font = t.Font.With(weight: FontWeight.Bold));
2021-08-11 05:49:22 +00:00
supportLinkText.AddText(" today!");
2021-08-10 07:07:20 +00:00
imageContainer.Children = new Drawable[]
{
new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Bottom = 28 },
2021-08-10 07:07:20 +00:00
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
Texture = textures.Get(@"Online/supporter-pippi"),
},
new Container
2021-08-10 07:07:20 +00:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2021-08-16 14:38:13 +00:00
Size = new Vector2(heart_size),
Margin = new MarginPadding { Top = 70 },
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = colour.Pink,
Radius = 10,
Roundness = heart_size / 2,
},
Child = new Sprite
{
2021-08-16 14:38:13 +00:00
Size = new Vector2(heart_size),
Texture = textures.Get(@"Online/supporter-heart"),
},
2021-08-10 07:07:20 +00:00
},
};
2021-08-10 06:21:23 +00:00
}
2021-08-12 13:36:47 +00:00
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;
}
}
}
}
}