1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:12:56 +08:00

Move Api request outside the scores container itself

This commit is contained in:
EVAST9919 2017-11-12 07:05:50 +03:00
parent bc45843def
commit 569780d37b
3 changed files with 60 additions and 55 deletions

View File

@ -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);
}
}

View File

@ -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<OnlineScore> scores;
public IEnumerable<OnlineScore> 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;
}
}
}

View File

@ -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]