1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 03:52:54 +08:00

Better handle the passing of Beatmap and updating of scores.

PresentScores was dangerous as it could potentially bring up unsafe threading scenarios. This ensures everything will work well in all cases.
This commit is contained in:
Dean Herbert 2017-03-23 16:31:08 +09:00
parent a561611125
commit 3ae7d0cb98
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
2 changed files with 31 additions and 8 deletions

View File

@ -21,10 +21,18 @@ namespace osu.Game.Screens.Select
private OsuGame game; private OsuGame game;
[BackgroundDependencyLoader(permitNulls: true)] private WorkingBeatmap beatmap;
private void load(OsuGame game) public WorkingBeatmap Beatmap
{ {
this.game = game; get
{
return beatmap;
}
set
{
beatmap = value;
if (IsLoaded) Schedule(updateScores);
}
} }
public BeatmapDetailArea() public BeatmapDetailArea()
@ -47,6 +55,9 @@ namespace osu.Game.Screens.Select
Leaderboard.Show(); Leaderboard.Show();
break; break;
} }
//for now let's always update scores.
updateScores();
}, },
}, },
content = new Container content = new Container
@ -69,15 +80,27 @@ namespace osu.Game.Screens.Select
}); });
} }
private GetScoresRequest getScoresRequest; protected override void LoadComplete()
public void PresentScores(WorkingBeatmap beatmap)
{ {
if (game == null) return; base.LoadComplete();
updateScores();
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game)
{
this.game = game;
}
private GetScoresRequest getScoresRequest;
private void updateScores()
{
if (game == null || !IsLoaded) return;
Leaderboard.Scores = null; Leaderboard.Scores = null;
getScoresRequest?.Cancel(); getScoresRequest?.Cancel();
if (beatmap?.BeatmapInfo == null) return; if (beatmap?.BeatmapInfo == null || !Leaderboard.IsPresent) return;
getScoresRequest = new GetScoresRequest(beatmap.BeatmapInfo); getScoresRequest = new GetScoresRequest(beatmap.BeatmapInfo);
getScoresRequest.Success += r => Leaderboard.Scores = r.Scores; getScoresRequest.Success += r => Leaderboard.Scores = r.Scores;

View File

@ -55,7 +55,7 @@ namespace osu.Game.Screens.Select
{ {
beatmap?.Mods.BindTo(modSelect.SelectedMods); beatmap?.Mods.BindTo(modSelect.SelectedMods);
beatmapDetails.PresentScores(beatmap); beatmapDetails.Beatmap = beatmap;
base.OnBeatmapChanged(beatmap); base.OnBeatmapChanged(beatmap);
} }