1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 14:07:52 +08:00
osu-lazer/osu.Game/Overlays/Rankings/HeaderTitle.cs

99 lines
3.1 KiB
C#
Raw Normal View History

2019-09-12 10:26:10 +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.
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Users;
using osu.Framework.Graphics;
using osuTK;
using osu.Game.Graphics;
using osu.Framework.Allocation;
namespace osu.Game.Overlays.Rankings
{
public class HeaderTitle : CompositeDrawable
{
private const int spacing = 10;
private const int flag_margin = 5;
private const int text_size = 40;
public readonly Bindable<RankingsScope> Scope = new Bindable<RankingsScope>();
public readonly Bindable<Country> Country = new Bindable<Country>();
private readonly SpriteText scopeText;
2019-09-13 00:34:58 +08:00
private readonly DismissableFlag flag;
2019-09-12 10:26:10 +08:00
public HeaderTitle()
{
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(spacing, 0),
Children = new Drawable[]
{
2019-09-13 15:25:25 +08:00
flag = new DismissableFlag
2019-09-12 10:26:10 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Bottom = flag_margin },
2019-09-13 15:25:25 +08:00
Size = new Vector2(30, 20),
2019-09-12 10:26:10 +08:00
},
scopeText = new SpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Light)
},
new SpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Light),
Text = @"Ranking"
}
}
};
flag.Action += () => Country.Value = null;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
scopeText.Colour = colours.Lime;
}
protected override void LoadComplete()
{
2019-09-13 15:03:44 +08:00
Scope.BindValueChanged(onScopeChanged, true);
2019-09-12 10:26:10 +08:00
Country.BindValueChanged(onCountryChanged, true);
base.LoadComplete();
}
2019-09-13 15:03:44 +08:00
private void onScopeChanged(ValueChangedEvent<RankingsScope> scope)
2019-09-12 10:26:10 +08:00
{
2019-09-13 15:03:44 +08:00
scopeText.Text = scope.NewValue.ToString();
2019-09-12 10:26:10 +08:00
2019-09-13 15:03:44 +08:00
if (scope.NewValue != RankingsScope.Performance)
2019-09-12 10:26:10 +08:00
Country.Value = null;
}
private void onCountryChanged(ValueChangedEvent<Country> country)
{
if (country.NewValue == null)
{
2019-09-13 15:25:25 +08:00
flag.Hide();
2019-09-12 10:26:10 +08:00
return;
}
Scope.Value = RankingsScope.Performance;
flag.Country = country.NewValue;
2019-09-13 15:45:01 +08:00
flag.Show();
2019-09-12 10:26:10 +08:00
}
}
}