1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:35:05 +08:00

Add some sanity to request/drawable creation logic

This commit is contained in:
Dean Herbert 2017-10-30 19:31:10 +09:00
parent a51e64b2d1
commit 1ae0eff6ad

View File

@ -39,7 +39,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
this.type = type; this.type = type;
this.includeWeight = includeWeight; this.includeWeight = includeWeight;
this.user.BindTo(user); this.user.BindTo(user);
this.user.ValueChanged += user_ValueChanged;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -47,46 +46,56 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuSpriteText new OsuSpriteText
{ {
TextSize = 15, TextSize = 15,
Text = header, Text = header,
Font = "Exo2.0-RegularItalic", Font = "Exo2.0-RegularItalic",
Margin = new MarginPadding { Top = 10, Bottom = 10 }, Margin = new MarginPadding { Top = 10, Bottom = 10 },
}, },
scoreContainer = new FillFlowContainer<DrawableScore> scoreContainer = new FillFlowContainer<DrawableScore>
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
}, },
showMoreButton = new OsuHoverContainer showMoreButton = new OsuHoverContainer
{ {
Alpha = 0, Alpha = 0,
Action = showMore, Action = showMore,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Child = new OsuSpriteText Child = new OsuSpriteText
{
TextSize = 14,
Text = "show more",
}
},
showMoreLoading = new LoadingAnimation
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(14),
},
missing = new OsuSpriteText
{ {
TextSize = 14, TextSize = 14,
Text = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(", Text = "show more",
}, }
},
showMoreLoading = new LoadingAnimation
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(14),
},
missing = new OsuSpriteText
{
TextSize = 14,
Text = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(",
},
}; };
} }
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;
user.ValueChanged += user_ValueChanged;
user.TriggerChange();
}
private void user_ValueChanged(User newUser) private void user_ValueChanged(User newUser)
{ {
visiblePages = 0; visiblePages = 0;
@ -96,13 +105,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
showMore(); showMore();
} }
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;
}
private void showMore() private void showMore()
{ {
var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5); var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5);
@ -118,16 +120,28 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
showMoreButton.FadeTo(scores.Count == 5 ? 1 : 0); showMoreButton.FadeTo(scores.Count == 5 ? 1 : 0);
showMoreLoading.Hide(); showMoreLoading.Hide();
if (scores.Any()) if (!scores.Any()) return;
missing.Hide();
foreach (OnlineScore score in scores)
{ {
missing.Hide(); DrawableScore drawableScore;
foreach (OnlineScore score in scores)
switch (type)
{ {
var drawableScore = type == ScoreType.Recent ? (DrawableScore)new DrawableTotalScore(score) : new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); default:
drawableScore.RelativeSizeAxes = Axes.X; drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null);
drawableScore.Height = 60; break;
scoreContainer.Add(drawableScore); case ScoreType.Recent:
drawableScore = new DrawableTotalScore(score);
break;
} }
drawableScore.RelativeSizeAxes = Axes.X;
drawableScore.Height = 60;
scoreContainer.Add(drawableScore);
} }
}; };