1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:17:44 +08:00
osu-lazer/osu.Game/Users/Country.cs

80 lines
2.0 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 17:19:50 +08:00
using System;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Users
{
public class Country
{
/// <summary>
/// The name of this country.
/// </summary>
[JsonProperty(@"name")]
public string FullName;
/// <summary>
/// Two-letter flag acronym (ISO 3166 standard)
/// </summary>
[JsonProperty(@"code")]
public string FlagName;
}
public class DrawableFlag : Container, IHasTooltip
{
private readonly Sprite sprite;
private TextureStore textures;
private Country country;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
public Country Country
{
get => country;
2018-04-13 17:19:50 +08:00
set
{
if (value == country)
return;
country = value;
if (LoadState >= LoadState.Ready)
2018-08-31 06:04:40 +08:00
sprite.Texture = getFlagTexture();
2018-04-13 17:19:50 +08:00
}
}
public string TooltipText => country?.FullName;
public DrawableFlag(Country country = null)
{
this.country = country;
Children = new Drawable[]
{
sprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
},
};
}
[BackgroundDependencyLoader]
2018-08-31 06:04:40 +08:00
private void load(TextureStore ts)
2018-04-13 17:19:50 +08:00
{
if (ts == null)
throw new ArgumentNullException(nameof(ts));
textures = ts;
2018-08-31 06:04:40 +08:00
sprite.Texture = getFlagTexture();
2018-04-13 17:19:50 +08:00
}
2018-08-31 06:04:40 +08:00
private Texture getFlagTexture() => textures.Get($@"Flags/{country?.FlagName ?? @"__"}");
2018-04-13 17:19:50 +08:00
}
}