mirror of
https://github.com/osukey/osukey.git
synced 2025-07-07 11:19:54 +09:00
Use ModelBackedDrawable in DrawableFlag
This commit is contained in:
@ -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 ?? @"__"}"),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user