2017-03-13 20:33:25 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-11-08 05:50:00 +08:00
|
|
|
|
using System;
|
2017-04-19 15:02:18 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2017-03-13 20:33:25 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-12-30 21:57:57 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-03-13 20:33:25 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Users
|
|
|
|
|
{
|
2017-03-19 11:09:58 +08:00
|
|
|
|
public class Country
|
2017-03-13 20:33:25 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-03-18 05:16:59 +08:00
|
|
|
|
/// The name of this country.
|
2017-03-13 20:33:25 +08:00
|
|
|
|
/// </summary>
|
2017-04-19 15:02:18 +08:00
|
|
|
|
[JsonProperty(@"name")]
|
2017-03-13 20:33:25 +08:00
|
|
|
|
public string FullName;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Two-letter flag acronym (ISO 3166 standard)
|
|
|
|
|
/// </summary>
|
2017-04-19 15:02:18 +08:00
|
|
|
|
[JsonProperty(@"code")]
|
2017-03-13 20:33:25 +08:00
|
|
|
|
public string FlagName;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-30 21:57:57 +08:00
|
|
|
|
public class DrawableFlag : Container, IHasTooltip
|
2017-03-13 20:33:25 +08:00
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Sprite sprite;
|
2017-03-13 20:33:25 +08:00
|
|
|
|
private TextureStore textures;
|
|
|
|
|
|
2017-12-30 21:57:57 +08:00
|
|
|
|
private Country country;
|
|
|
|
|
public Country Country
|
2017-03-13 20:33:25 +08:00
|
|
|
|
{
|
2017-12-30 21:57:57 +08:00
|
|
|
|
get { return country; }
|
2017-03-13 20:33:25 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-12-30 21:57:57 +08:00
|
|
|
|
if (value == country)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
country = value;
|
|
|
|
|
sprite.Texture = getFlagTexture();
|
2017-03-13 20:33:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-30 21:57:57 +08:00
|
|
|
|
public string TooltipText => country?.FullName;
|
2017-03-13 20:33:25 +08:00
|
|
|
|
|
2017-12-30 21:57:57 +08:00
|
|
|
|
public DrawableFlag(Country country = null)
|
2017-03-13 20:33:25 +08:00
|
|
|
|
{
|
2017-12-30 21:57:57 +08:00
|
|
|
|
this.country = country;
|
2017-03-13 20:33:25 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
sprite = new Sprite
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-12-30 21:57:57 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore ts)
|
|
|
|
|
{
|
|
|
|
|
if (ts == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(ts));
|
|
|
|
|
|
|
|
|
|
textures = ts;
|
|
|
|
|
sprite.Texture = getFlagTexture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Texture getFlagTexture() => textures.Get($@"Flags/{country?.FlagName ?? @"__"}");
|
2017-03-13 20:33:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|