From 569780d37b0b664d1281ae40354cc6d5430f233f Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Sun, 12 Nov 2017 07:05:50 +0300 Subject: [PATCH] Move Api request outside the scores container itself --- .../BeatmapSet/Scores/ClickableUsername.cs | 3 +- .../BeatmapSet/Scores/ScoresContainer.cs | 84 ++++++++----------- osu.Game/Overlays/BeatmapSetOverlay.cs | 28 ++++++- 3 files changed, 60 insertions(+), 55 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ClickableUsername.cs b/osu.Game/Overlays/BeatmapSet/Scores/ClickableUsername.cs index 762e3f0105..bc5595587b 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ClickableUsername.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ClickableUsername.cs @@ -14,7 +14,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores public class ClickableUsername : OsuHoverContainer { private readonly OsuSpriteText text; - private Action clickAction; private UserProfileOverlay profile; private User user; @@ -57,7 +56,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores protected override bool OnClick(InputState state) { - profile.ShowUser(user); + profile?.ShowUser(user); return base.OnClick(state); } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs index 1134d43f53..41773cf18d 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs @@ -3,15 +3,13 @@ using OpenTK; using OpenTK.Graphics; -using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Game.Beatmaps; using osu.Game.Graphics.UserInterface; -using osu.Game.Online.API; using osu.Game.Online.API.Requests; +using System.Collections.Generic; using System.Linq; namespace osu.Game.Overlays.BeatmapSet.Scores @@ -25,29 +23,36 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly DrawableTopScore topScore; private readonly LoadingAnimation loadingAnimation; private readonly Box foreground; - private GetScoresRequest request; - private APIAccess api; - private bool isLoading + private bool isLoading; + public bool IsLoading { set { - foreground.FadeTo(value ? 1 : 0, fade_duration); - loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); + if (isLoading == value) return; + isLoading = value; + + foreground.FadeTo(isLoading ? 1 : 0, fade_duration); + loadingAnimation.FadeTo(isLoading ? 1 : 0, fade_duration); } + get { return isLoading; } } - private BeatmapInfo beatmap; - public BeatmapInfo Beatmap + private IEnumerable scores; + public IEnumerable Scores { set { - if (beatmap == value) return; - beatmap = value; + if (scores == value) + { + IsLoading = false; + return; + } + scores = value; updateScores(); } - get { return beatmap; } + get { return scores; } } public ScoresContainer() @@ -95,58 +100,37 @@ namespace osu.Game.Overlays.BeatmapSet.Scores }; } - [BackgroundDependencyLoader] - private void load(APIAccess api) - { - this.api = api; - } - private void updateScores() { - request?.Cancel(); - - if (!beatmap?.OnlineBeatmapID.HasValue ?? true) + var scoresAmount = scores.Count(); + if (scoresAmount == 0) { - clearAllScores(); + CleanAllScores(); return; } - isLoading = true; + topScore.Score = scores.FirstOrDefault(); + topScore.Show(); - request = new GetScoresRequest(beatmap); - request.Success += scores => + flow.Clear(); + + if (scoresAmount < 2) { - var scoresAmount = scores.Scores.Count(); - if (scoresAmount == 0) - { - clearAllScores(); - return; - } + IsLoading = false; + return; + } - topScore.Score = scores.Scores.FirstOrDefault(); - topScore.Show(); + for (int i = 1; i < scoresAmount; i++) + flow.Add(new DrawableScore(i, scores.ElementAt(i))); - flow.Clear(); - - if (scoresAmount < 2) - { - isLoading = false; - return; - } - - for (int i = 1; i < scoresAmount; i++) - flow.Add(new DrawableScore(i, scores.Scores.ElementAt(i))); - - isLoading = false; - }; - api.Queue(request); + IsLoading = false; } - private void clearAllScores() + public void CleanAllScores() { topScore.Hide(); flow.Clear(); - isLoading = false; + IsLoading = false; } } } diff --git a/osu.Game/Overlays/BeatmapSetOverlay.cs b/osu.Game/Overlays/BeatmapSetOverlay.cs index db01d02c79..480808ee54 100644 --- a/osu.Game/Overlays/BeatmapSetOverlay.cs +++ b/osu.Game/Overlays/BeatmapSetOverlay.cs @@ -27,17 +27,17 @@ namespace osu.Game.Overlays private readonly Header header; private readonly Info info; + private readonly ScoresContainer scores; private APIAccess api; private RulesetStore rulesets; + private GetScoresRequest getScoresRequest; // receive input outside our bounds so we can trigger a close event on ourselves. public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true; public BeatmapSetOverlay() { - ScoresContainer scores; - FirstWaveColour = OsuColour.Gray(0.4f); SecondWaveColour = OsuColour.Gray(0.3f); ThirdWaveColour = OsuColour.Gray(0.2f); @@ -83,7 +83,29 @@ namespace osu.Game.Overlays }, }; - header.Picker.Beatmap.ValueChanged += b => info.Beatmap = scores.Beatmap = b; + header.Picker.Beatmap.ValueChanged += b => + { + info.Beatmap = b; + updateScores(b); + }; + } + + private void updateScores(BeatmapInfo beatmap) + { + scores.IsLoading = true; + + getScoresRequest?.Cancel(); + + if (!beatmap.OnlineBeatmapID.HasValue) + { + scores.CleanAllScores(); + return; + } + + getScoresRequest = new GetScoresRequest(beatmap); + getScoresRequest.Success += r => scores.Scores = r.Scores; + + api.Queue(getScoresRequest); } [BackgroundDependencyLoader]