Use ModelBackedDrawable in DrawableFlag

This commit is contained in:
iiSaLMaN
2019-06-17 06:44:24 +03:00
committed by GitHub
parent 9a5d0695e9
commit 98f8b1d59a

View File

@ -27,53 +27,39 @@ namespace osu.Game.Users
public string FlagName; public string FlagName;
} }
public class DrawableFlag : Container, IHasTooltip public class DrawableFlag : ModelBackedDrawable<Country>, IHasTooltip
{ {
private readonly Sprite sprite;
private TextureStore textures; private TextureStore textures;
private Country country; private readonly Country country;
public Country Country public Country Country
{ {
get => country; get => Model;
set set => Model = value;
{
if (value == country)
return;
country = value;
if (LoadState >= LoadState.Ready)
sprite.Texture = getFlagTexture();
}
} }
public string TooltipText => country?.FullName; public string TooltipText => Country?.FullName;
public DrawableFlag(Country country = null) public DrawableFlag(Country country = null)
{ {
this.country = country; this.country = country;
Children = new Drawable[]
{
sprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
},
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore ts) private void load(TextureStore ts)
{ {
if (ts == null) textures = ts ?? throw new ArgumentNullException(nameof(ts));
throw new ArgumentNullException(nameof(ts)); Country = country;
textures = ts;
sprite.Texture = getFlagTexture();
} }
private Texture getFlagTexture() => textures.Get($@"Flags/{country?.FlagName ?? @"__"}"); protected override Drawable CreateDrawable(Country country)
{
return new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = textures.Get($@"Flags/{country?.FlagName ?? @"__"}"),
};
}
} }
} }