osu/osu.Game/Overlays/Profile/Header/SupporterIcon.cs

86 lines
2.6 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.
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
2018-04-15 21:44:59 +00:00
namespace osu.Game.Overlays.Profile.Header
2018-04-13 09:19:50 +00:00
{
public class SupporterIcon : CircularContainer, IHasTooltip
{
private readonly Box background;
2018-12-22 15:51:24 +00:00
private readonly FillFlowContainer iconContainer;
2018-04-13 09:19:50 +00:00
public string TooltipText => "osu!supporter";
2018-12-22 15:51:24 +00:00
public int SupporterLevel
2018-04-13 09:19:50 +00:00
{
2018-12-22 15:51:24 +00:00
set
2018-04-13 09:19:50 +00:00
{
2018-12-22 15:51:24 +00:00
if (value == 0)
{
Hide();
}
else
{
Show();
iconContainer.Clear();
for (int i = 0; i < value; i++)
2018-04-13 09:19:50 +00:00
{
2018-12-22 15:51:24 +00:00
iconContainer.Add(new SpriteIcon
2018-04-13 09:19:50 +00:00
{
2018-12-22 15:51:24 +00:00
Width = 12,
RelativeSizeAxes = Axes.Y,
Icon = FontAwesome.fa_heart,
});
2018-04-13 09:19:50 +00:00
}
2018-12-22 15:51:24 +00:00
}
}
}
public SupporterIcon()
{
Masking = true;
AutoSizeAxes = Axes.X;
Hide();
Children = new Drawable[]
{
background = new Box { RelativeSizeAxes = Axes.Both },
iconContainer = new FillFlowContainer
{
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Height = 0.6f,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
2018-04-13 09:19:50 +00:00
};
}
2018-12-22 15:51:24 +00:00
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
{
bool invalid = base.Invalidate(invalidation, source, shallPropagate);
if ((invalidation & Invalidation.DrawSize) != 0)
{
iconContainer.Padding = new MarginPadding { Horizontal = DrawHeight / 2 };
}
return invalid;
}
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Pink;
2018-12-22 15:51:24 +00:00
iconContainer.Colour = colours.CommunityUserGrayGreenDark;
2018-04-13 09:19:50 +00:00
}
}
}