mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 09:03:50 +09:00
Use ModelBackedDrawable in DrawableRank
This commit is contained in:
@ -8,67 +8,59 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Online.Leaderboards
|
namespace osu.Game.Online.Leaderboards
|
||||||
{
|
{
|
||||||
public class DrawableRank : Container
|
public class DrawableRank : ModelBackedDrawable<ScoreRank>
|
||||||
{
|
{
|
||||||
private readonly Sprite rankSprite;
|
|
||||||
private TextureStore textures;
|
private TextureStore textures;
|
||||||
|
|
||||||
public ScoreRank Rank { get; private set; }
|
public ScoreRank Rank
|
||||||
|
{
|
||||||
|
get => Model;
|
||||||
|
set => Model = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoreRank rank;
|
||||||
|
|
||||||
public DrawableRank(ScoreRank rank)
|
public DrawableRank(ScoreRank rank)
|
||||||
{
|
{
|
||||||
Rank = rank;
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
Children = new Drawable[]
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore ts)
|
||||||
{
|
{
|
||||||
rankSprite = new Sprite
|
textures = ts ?? throw new ArgumentNullException(nameof(ts));
|
||||||
|
Rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable CreateDrawable(ScoreRank rank)
|
||||||
|
{
|
||||||
|
return new Sprite
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
FillMode = FillMode.Fit
|
FillMode = FillMode.Fit,
|
||||||
},
|
Texture = textures.Get($"Grades/{getTextureName()}"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
private string getTextureName()
|
||||||
private void load(TextureStore textures)
|
|
||||||
{
|
{
|
||||||
this.textures = textures;
|
|
||||||
updateTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTexture()
|
|
||||||
{
|
|
||||||
string textureName;
|
|
||||||
|
|
||||||
switch (Rank)
|
switch (Rank)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
textureName = Rank.GetDescription();
|
return Rank.GetDescription();
|
||||||
break;
|
|
||||||
|
|
||||||
case ScoreRank.SH:
|
case ScoreRank.SH:
|
||||||
textureName = "SPlus";
|
return "SPlus";
|
||||||
break;
|
|
||||||
|
|
||||||
case ScoreRank.XH:
|
case ScoreRank.XH:
|
||||||
textureName = "SSPlus";
|
return "SSPlus";
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
rankSprite.Texture = textures.Get($@"Grades/{textureName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateRank(ScoreRank newRank)
|
|
||||||
{
|
|
||||||
Rank = newRank;
|
|
||||||
|
|
||||||
if (LoadState >= LoadState.Ready)
|
|
||||||
updateTexture();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user