1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:52:57 +08:00

Seperate UpdateableRank from DrawableRank and use it

This commit is contained in:
KingLuigi4932 2019-06-17 20:04:09 +03:00
parent 0c299d651f
commit 794ba17a2f
8 changed files with 30 additions and 32 deletions

View File

@ -12,48 +12,46 @@ using System;
namespace osu.Game.Online.Leaderboards
{
public class DrawableRank : ModelBackedDrawable<ScoreRank>
public class UpdateableRank : ModelBackedDrawable<ScoreRank>
{
private TextureStore textures;
public ScoreRank Rank
{
get => Model;
set => Model = value;
}
public UpdateableRank(ScoreRank rank) => Rank = rank;
protected override Drawable CreateDrawable(ScoreRank rank) => new DrawableRank(rank)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit,
};
}
public class DrawableRank : Sprite
{
private ScoreRank rank;
public DrawableRank(ScoreRank rank)
{
this.rank = rank;
}
public DrawableRank(ScoreRank rank) => this.rank = rank;
[BackgroundDependencyLoader]
[BackgroundDependencyLoader(true)]
private void load(TextureStore ts)
{
textures = ts ?? throw new ArgumentNullException(nameof(ts));
Rank = rank;
}
if (ts == null)
throw new ArgumentNullException(nameof(ts));
protected override Drawable CreateDrawable(ScoreRank rank)
{
return new Sprite
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit,
Texture = textures.Get($"Grades/{getTextureName()}"),
};
Texture = ts.Get($@"Grades/{getTextureName()}");
}
private string getTextureName()
{
switch (Rank)
switch (rank)
{
default:
return Rank.GetDescription();
return rank.GetDescription();
case ScoreRank.SH:
return "SPlus";

View File

@ -193,7 +193,7 @@ namespace osu.Game.Online.Leaderboards
Size = new Vector2(40f, 20f),
Children = new[]
{
scoreRank = new DrawableRank(score.Rank)
scoreRank = new UpdateableRank(score.Rank)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -103,7 +103,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Text = $"#{index + 1}",
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
},
new DrawableRank(score.Rank)
new UpdateableRank(score.Rank)
{
Size = new Vector2(30, 20)
},

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
public class TopScoreUserSection : CompositeDrawable
{
private readonly SpriteText rankText;
private readonly DrawableRank rank;
private readonly UpdateableRank rank;
private readonly UpdateableAvatar avatar;
private readonly LinkFlowContainer usernameText;
private readonly SpriteText date;
@ -46,7 +46,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Text = "#1",
Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true)
},
rank = new DrawableRank(ScoreRank.D)
rank = new UpdateableRank(ScoreRank.D)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -121,7 +121,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
usernameText.Clear();
usernameText.AddUserLink(value.User);
rank.UpdateRank(value.Rank);
rank.Rank = value.Rank;
}
}
}

View File

@ -200,7 +200,7 @@ namespace osu.Game.Overlays.Profile.Header
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new DrawableRank(rank)
new UpdateableRank(rank)
{
RelativeSizeAxes = Axes.X,
Height = 30,

View File

@ -59,7 +59,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) });
}
protected override Drawable CreateLeftVisual() => new DrawableRank(Score.Rank)
protected override Drawable CreateLeftVisual() => new UpdateableRank(Score.Rank)
{
RelativeSizeAxes = Axes.Y,
Width = 60,

View File

@ -58,7 +58,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
switch (activity.Type)
{
case RecentActivityType.Rank:
return new DrawableRank(activity.ScoreRank)
return new UpdateableRank(activity.ScoreRank)
{
RelativeSizeAxes = Axes.Y,
Width = 60,

View File

@ -74,7 +74,7 @@ namespace osu.Game.Screens.Ranking.Pages
RelativeSizeAxes = Axes.X,
Height = user_header_height,
},
new DrawableRank(Score.Rank)
new UpdateableRank(Score.Rank)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,