mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:25:39 +08:00
Move API lookup from BeatmapDetailArea to Leaderboard.
This commit is contained in:
parent
ecfe68d6fb
commit
dc3a2d45fe
@ -1,13 +1,10 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Screens.Select.Leaderboards;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
@ -20,8 +17,6 @@ namespace osu.Game.Screens.Select
|
||||
public readonly Container Details; //todo: replace with a real details view when added
|
||||
public readonly Leaderboard Leaderboard;
|
||||
|
||||
private APIAccess api;
|
||||
|
||||
private WorkingBeatmap beatmap;
|
||||
public WorkingBeatmap Beatmap
|
||||
{
|
||||
@ -32,7 +27,7 @@ namespace osu.Game.Screens.Select
|
||||
set
|
||||
{
|
||||
beatmap = value;
|
||||
if (IsLoaded) Schedule(updateScores);
|
||||
Leaderboard.Beatmap = beatmap?.BeatmapInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,9 +51,6 @@ namespace osu.Game.Screens.Select
|
||||
Leaderboard.Show();
|
||||
break;
|
||||
}
|
||||
|
||||
//for now let's always update scores.
|
||||
updateScores();
|
||||
},
|
||||
},
|
||||
content = new Container
|
||||
@ -77,35 +69,9 @@ namespace osu.Game.Screens.Select
|
||||
Leaderboard = new Leaderboard
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
updateScores();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(APIAccess api)
|
||||
{
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
private GetScoresRequest getScoresRequest;
|
||||
private void updateScores()
|
||||
{
|
||||
if (!IsLoaded) return;
|
||||
|
||||
Leaderboard.Scores = null;
|
||||
getScoresRequest?.Cancel();
|
||||
|
||||
if (api == null || beatmap?.BeatmapInfo == null || !Leaderboard.IsPresent) return;
|
||||
|
||||
getScoresRequest = new GetScoresRequest(beatmap.BeatmapInfo);
|
||||
getScoresRequest.Success += r => Leaderboard.Scores = r.Scores;
|
||||
api.Queue(getScoresRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Modes.Scoring;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
|
||||
namespace osu.Game.Screens.Select.Leaderboards
|
||||
{
|
||||
@ -26,6 +30,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
set
|
||||
{
|
||||
scores = value;
|
||||
getScoresRequest?.Cancel();
|
||||
|
||||
int i = 150;
|
||||
if (scores == null)
|
||||
@ -81,6 +86,41 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
};
|
||||
}
|
||||
|
||||
private APIAccess api;
|
||||
|
||||
private BeatmapInfo beatmap;
|
||||
|
||||
public BeatmapInfo Beatmap
|
||||
{
|
||||
get { return beatmap; }
|
||||
set
|
||||
{
|
||||
beatmap = value;
|
||||
Schedule(updateScores);
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(APIAccess api)
|
||||
{
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
private GetScoresRequest getScoresRequest;
|
||||
private void updateScores()
|
||||
{
|
||||
if (!IsLoaded) return;
|
||||
|
||||
Scores = null;
|
||||
getScoresRequest?.Cancel();
|
||||
|
||||
if (api == null || Beatmap == null) return;
|
||||
|
||||
getScoresRequest = new GetScoresRequest(Beatmap);
|
||||
getScoresRequest.Success += r => Scores = r.Scores;
|
||||
api.Queue(getScoresRequest);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
Loading…
Reference in New Issue
Block a user