mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Fix potential crash due to stale index
This commit is contained in:
parent
1548c0dc25
commit
37feedae7a
@ -30,7 +30,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
||||
private readonly OsuSpriteText placeholder;
|
||||
|
||||
private KeyValuePair<int, int>[] ranks;
|
||||
private int dayIndex;
|
||||
private int hoveredIndex = -1;
|
||||
public readonly Bindable<UserStatistics> Statistics = new Bindable<UserStatistics>();
|
||||
|
||||
public RankGraph()
|
||||
@ -55,7 +55,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
||||
}
|
||||
};
|
||||
|
||||
graph.OnBallMove += i => dayIndex = i;
|
||||
graph.OnBallMove += i => hoveredIndex = i;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -74,6 +74,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
||||
private void updateStatistics(UserStatistics statistics)
|
||||
{
|
||||
placeholder.FadeIn(fade_duration, Easing.Out);
|
||||
hoveredIndex = -1;
|
||||
|
||||
if (statistics?.Ranks.Global == null)
|
||||
{
|
||||
@ -201,14 +202,14 @@ namespace osu.Game.Overlays.Profile.Header.Components
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Statistics.Value?.Ranks.Global == null)
|
||||
if (ranks == null || hoveredIndex == -1)
|
||||
return null;
|
||||
|
||||
var days = ranked_days - ranks[dayIndex].Key + 1;
|
||||
var days = ranked_days - ranks[hoveredIndex].Key + 1;
|
||||
|
||||
return new TooltipDisplayContent
|
||||
{
|
||||
Rank = $"#{ranks[dayIndex].Value:#,##0}",
|
||||
Rank = $"#{ranks[hoveredIndex].Value:#,##0}",
|
||||
Time = days == 0 ? "now" : $"{days} days ago"
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user