osu/osu.Game/Online/Leaderboards/DrawableRank.cs

67 lines
1.7 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2018-11-28 07:12:57 +00:00
using osu.Game.Scoring;
using System;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Online.Leaderboards
2018-04-13 09:19:50 +00:00
{
public class DrawableRank : ModelBackedDrawable<ScoreRank>
2018-04-13 09:19:50 +00:00
{
private TextureStore textures;
public ScoreRank Rank
{
get => Model;
set => Model = value;
}
private ScoreRank rank;
2018-04-13 09:19:50 +00:00
public DrawableRank(ScoreRank rank)
{
this.rank = rank;
2018-04-13 09:19:50 +00:00
}
[BackgroundDependencyLoader]
private void load(TextureStore ts)
2018-04-13 09:19:50 +00:00
{
textures = ts ?? throw new ArgumentNullException(nameof(ts));
Rank = rank;
2018-04-13 09:19:50 +00:00
}
protected override Drawable CreateDrawable(ScoreRank rank)
2018-08-30 22:04:40 +00:00
{
return new Sprite
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit,
Texture = textures.Get($"Grades/{getTextureName()}"),
};
}
2019-05-07 06:09:03 +00:00
private string getTextureName()
{
2019-04-22 00:57:33 +00:00
switch (Rank)
{
default:
return Rank.GetDescription();
2019-05-07 06:09:03 +00:00
2019-04-22 00:57:33 +00:00
case ScoreRank.SH:
return "SPlus";
2019-05-07 06:09:03 +00:00
2019-04-22 00:57:33 +00:00
case ScoreRank.XH:
return "SSPlus";
2019-04-22 00:57:33 +00:00
}
2018-04-13 09:19:50 +00:00
}
}
}