mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:52:55 +08:00
Move Api request outside the scores container itself
This commit is contained in:
parent
bc45843def
commit
569780d37b
@ -14,7 +14,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
public class ClickableUsername : OsuHoverContainer
|
public class ClickableUsername : OsuHoverContainer
|
||||||
{
|
{
|
||||||
private readonly OsuSpriteText text;
|
private readonly OsuSpriteText text;
|
||||||
private Action clickAction;
|
|
||||||
private UserProfileOverlay profile;
|
private UserProfileOverlay profile;
|
||||||
|
|
||||||
private User user;
|
private User user;
|
||||||
@ -57,7 +56,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
profile.ShowUser(user);
|
profile?.ShowUser(user);
|
||||||
return base.OnClick(state);
|
return base.OnClick(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,13 @@
|
|||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapSet.Scores
|
namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||||
@ -25,29 +23,36 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
private readonly DrawableTopScore topScore;
|
private readonly DrawableTopScore topScore;
|
||||||
private readonly LoadingAnimation loadingAnimation;
|
private readonly LoadingAnimation loadingAnimation;
|
||||||
private readonly Box foreground;
|
private readonly Box foreground;
|
||||||
private GetScoresRequest request;
|
|
||||||
private APIAccess api;
|
|
||||||
|
|
||||||
private bool isLoading
|
private bool isLoading;
|
||||||
|
public bool IsLoading
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
foreground.FadeTo(value ? 1 : 0, fade_duration);
|
if (isLoading == value) return;
|
||||||
loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
|
isLoading = value;
|
||||||
|
|
||||||
|
foreground.FadeTo(isLoading ? 1 : 0, fade_duration);
|
||||||
|
loadingAnimation.FadeTo(isLoading ? 1 : 0, fade_duration);
|
||||||
}
|
}
|
||||||
|
get { return isLoading; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeatmapInfo beatmap;
|
private IEnumerable<OnlineScore> scores;
|
||||||
public BeatmapInfo Beatmap
|
public IEnumerable<OnlineScore> Scores
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (beatmap == value) return;
|
if (scores == value)
|
||||||
beatmap = value;
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scores = value;
|
||||||
|
|
||||||
updateScores();
|
updateScores();
|
||||||
}
|
}
|
||||||
get { return beatmap; }
|
get { return scores; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScoresContainer()
|
public ScoresContainer()
|
||||||
@ -95,58 +100,37 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(APIAccess api)
|
|
||||||
{
|
|
||||||
this.api = api;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateScores()
|
private void updateScores()
|
||||||
{
|
{
|
||||||
request?.Cancel();
|
var scoresAmount = scores.Count();
|
||||||
|
if (scoresAmount == 0)
|
||||||
if (!beatmap?.OnlineBeatmapID.HasValue ?? true)
|
|
||||||
{
|
{
|
||||||
clearAllScores();
|
CleanAllScores();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoading = true;
|
topScore.Score = scores.FirstOrDefault();
|
||||||
|
topScore.Show();
|
||||||
|
|
||||||
request = new GetScoresRequest(beatmap);
|
flow.Clear();
|
||||||
request.Success += scores =>
|
|
||||||
|
if (scoresAmount < 2)
|
||||||
{
|
{
|
||||||
var scoresAmount = scores.Scores.Count();
|
IsLoading = false;
|
||||||
if (scoresAmount == 0)
|
return;
|
||||||
{
|
}
|
||||||
clearAllScores();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
topScore.Score = scores.Scores.FirstOrDefault();
|
for (int i = 1; i < scoresAmount; i++)
|
||||||
topScore.Show();
|
flow.Add(new DrawableScore(i, scores.ElementAt(i)));
|
||||||
|
|
||||||
flow.Clear();
|
IsLoading = false;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearAllScores()
|
public void CleanAllScores()
|
||||||
{
|
{
|
||||||
topScore.Hide();
|
topScore.Hide();
|
||||||
flow.Clear();
|
flow.Clear();
|
||||||
isLoading = false;
|
IsLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,17 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private readonly Header header;
|
private readonly Header header;
|
||||||
private readonly Info info;
|
private readonly Info info;
|
||||||
|
private readonly ScoresContainer scores;
|
||||||
|
|
||||||
private APIAccess api;
|
private APIAccess api;
|
||||||
private RulesetStore rulesets;
|
private RulesetStore rulesets;
|
||||||
|
private GetScoresRequest getScoresRequest;
|
||||||
|
|
||||||
// receive input outside our bounds so we can trigger a close event on ourselves.
|
// receive input outside our bounds so we can trigger a close event on ourselves.
|
||||||
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
public BeatmapSetOverlay()
|
public BeatmapSetOverlay()
|
||||||
{
|
{
|
||||||
ScoresContainer scores;
|
|
||||||
|
|
||||||
FirstWaveColour = OsuColour.Gray(0.4f);
|
FirstWaveColour = OsuColour.Gray(0.4f);
|
||||||
SecondWaveColour = OsuColour.Gray(0.3f);
|
SecondWaveColour = OsuColour.Gray(0.3f);
|
||||||
ThirdWaveColour = OsuColour.Gray(0.2f);
|
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]
|
[BackgroundDependencyLoader]
|
||||||
|
Loading…
Reference in New Issue
Block a user