From 3087099b32b6d79bee36f126ebbbad09279d8e35 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Mon, 17 Jun 2019 07:34:35 +0300 Subject: [PATCH] Use ModelBackedDrawable in DrawableRank --- osu.Game/Online/Leaderboards/DrawableRank.cs | 64 +++++++++----------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/osu.Game/Online/Leaderboards/DrawableRank.cs b/osu.Game/Online/Leaderboards/DrawableRank.cs index ce64395dde..b7beb4ffb0 100644 --- a/osu.Game/Online/Leaderboards/DrawableRank.cs +++ b/osu.Game/Online/Leaderboards/DrawableRank.cs @@ -8,67 +8,59 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Game.Scoring; +using System; namespace osu.Game.Online.Leaderboards { - public class DrawableRank : Container + public class DrawableRank : ModelBackedDrawable { - private readonly Sprite rankSprite; private TextureStore textures; - public ScoreRank Rank { get; private set; } + public ScoreRank Rank + { + get => Model; + set => Model = value; + } + + private ScoreRank rank; public DrawableRank(ScoreRank rank) { - Rank = rank; - - Children = new Drawable[] - { - rankSprite = new Sprite - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fit - }, - }; + this.rank = rank; } [BackgroundDependencyLoader] - private void load(TextureStore textures) + private void load(TextureStore ts) { - this.textures = textures; - updateTexture(); + textures = ts ?? throw new ArgumentNullException(nameof(ts)); + Rank = rank; } - private void updateTexture() + protected override Drawable CreateDrawable(ScoreRank rank) { - string textureName; + return new Sprite + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fit, + Texture = textures.Get($"Grades/{getTextureName()}"), + }; + } + private string getTextureName() + { switch (Rank) { default: - textureName = Rank.GetDescription(); - break; + return Rank.GetDescription(); case ScoreRank.SH: - textureName = "SPlus"; - break; + return "SPlus"; case ScoreRank.XH: - textureName = "SSPlus"; - break; + return "SSPlus"; } - - rankSprite.Texture = textures.Get($@"Grades/{textureName}"); - } - - public void UpdateRank(ScoreRank newRank) - { - Rank = newRank; - - if (LoadState >= LoadState.Ready) - updateTexture(); } } }