From dc3a2d45fe15aa1c8be2bda54797d7ce69eef17b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 11 Apr 2017 13:48:43 +0900 Subject: [PATCH] Move API lookup from BeatmapDetailArea to Leaderboard. --- osu.Game/Screens/Select/BeatmapDetailArea.cs | 38 +----------------- .../Select/Leaderboards/Leaderboard.cs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/osu.Game/Screens/Select/BeatmapDetailArea.cs b/osu.Game/Screens/Select/BeatmapDetailArea.cs index dae909f2b7..186739c3cb 100644 --- a/osu.Game/Screens/Select/BeatmapDetailArea.cs +++ b/osu.Game/Screens/Select/BeatmapDetailArea.cs @@ -1,13 +1,10 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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); - } } } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 12ff096d16..315611a60c 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -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();