1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 15:32:57 +08:00
osu-lazer/osu.Game/Overlays/Rankings/CountryPill.cs

168 lines
5.6 KiB
C#
Raw Normal View History

2020-01-09 05:27:22 +08: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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-01-09 05:27:22 +08:00
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
2020-01-09 05:27:22 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2020-01-14 14:07:25 +08:00
using osu.Framework.Graphics.UserInterface;
2020-01-09 05:27:22 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Rankings
{
2022-07-18 13:40:34 +08:00
public class CountryPill : CompositeDrawable, IHasCurrentValue<CountryCode>
2020-01-09 05:27:22 +08:00
{
private const int duration = 200;
2022-07-18 13:40:34 +08:00
private readonly BindableWithCurrent<CountryCode> current = new BindableWithCurrent<CountryCode>();
2020-01-14 14:07:25 +08:00
2022-07-18 13:40:34 +08:00
public Bindable<CountryCode> Current
2020-01-14 14:07:25 +08:00
{
get => current.Current;
set => current.Current = value;
}
private readonly Container content;
2020-01-09 05:27:22 +08:00
private readonly Box background;
private readonly UpdateableFlag flag;
private readonly OsuSpriteText countryName;
public CountryPill()
{
2020-01-14 14:07:25 +08:00
AutoSizeAxes = Axes.Both;
InternalChild = content = new CircularContainer
2020-01-09 05:27:22 +08:00
{
Height = 30,
2020-01-14 14:07:25 +08:00
AutoSizeDuration = duration,
AutoSizeEasing = Easing.OutQuint,
Masking = true,
Children = new Drawable[]
2020-01-09 05:27:22 +08:00
{
2020-01-14 14:07:25 +08:00
background = new Box
2020-01-09 05:27:22 +08:00
{
2020-01-14 14:07:25 +08:00
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Margin = new MarginPadding { Horizontal = 15 },
2020-01-14 14:07:25 +08:00
Direction = FillDirection.Horizontal,
Spacing = new Vector2(15, 0),
2020-01-14 14:07:25 +08:00
Children = new Drawable[]
2020-01-09 05:27:22 +08:00
{
2020-01-14 14:07:25 +08:00
new FillFlowContainer
2020-01-09 05:27:22 +08:00
{
2020-01-14 14:07:25 +08:00
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5, 0),
2020-01-14 14:07:25 +08:00
Children = new Drawable[]
2020-01-09 05:27:22 +08:00
{
2020-01-14 14:07:25 +08:00
flag = new UpdateableFlag
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(28, 20)
2020-01-14 14:07:25 +08:00
},
countryName = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 14)
}
2020-01-09 05:27:22 +08:00
}
2020-01-14 14:07:25 +08:00
},
new CloseButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = Current.SetDefault,
2020-01-09 05:27:22 +08:00
}
}
}
}
};
}
[BackgroundDependencyLoader]
2020-02-04 01:32:20 +08:00
private void load(OverlayColourProvider colourProvider)
2020-01-09 05:27:22 +08:00
{
2020-02-04 01:32:20 +08:00
background.Colour = colourProvider.Background5;
2020-01-09 05:27:22 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-01-14 14:07:25 +08:00
Current.BindValueChanged(onCountryChanged, true);
2020-01-09 05:27:22 +08:00
}
public void Expand()
{
2020-01-14 14:07:25 +08:00
content.ClearTransforms();
content.AutoSizeAxes = Axes.X;
2020-01-09 05:27:22 +08:00
this.FadeIn(duration, Easing.OutQuint);
}
public void Collapse()
{
2020-01-14 14:07:25 +08:00
content.ClearTransforms();
content.AutoSizeAxes = Axes.None;
content.ResizeWidthTo(0, duration, Easing.OutQuint);
2020-01-09 05:27:22 +08:00
this.FadeOut(duration, Easing.OutQuint);
}
2022-07-18 13:40:34 +08:00
private void onCountryChanged(ValueChangedEvent<CountryCode> country)
2020-01-09 05:27:22 +08:00
{
if (Current.Value == CountryCode.Unknown)
2020-01-09 05:27:22 +08:00
return;
2022-07-18 13:40:34 +08:00
flag.CountryCode = country.NewValue;
countryName.Text = country.NewValue.GetDescription();
2020-01-09 05:27:22 +08:00
}
private class CloseButton : OsuHoverContainer
{
private readonly SpriteIcon icon;
protected override IEnumerable<Drawable> EffectTargets => new[] { icon };
public CloseButton()
{
AutoSizeAxes = Axes.Both;
Add(icon = new SpriteIcon
{
Size = new Vector2(10),
2020-01-09 05:27:22 +08:00
Icon = FontAwesome.Solid.Times
});
}
[BackgroundDependencyLoader]
2020-02-04 01:32:20 +08:00
private void load(OverlayColourProvider colourProvider)
2020-01-09 05:27:22 +08:00
{
2020-02-04 01:32:20 +08:00
IdleColour = colourProvider.Light2;
2020-01-09 05:27:22 +08:00
HoverColour = Color4.White;
}
}
}
}