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

Move request inside the ScoresContainer again

This commit is contained in:
Andrei Zavatski 2019-07-10 19:40:29 +03:00
parent a041421e0d
commit 953d32366c
3 changed files with 68 additions and 42 deletions

View File

@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Online
public TestSceneScoresContainer()
{
ScoresContainer scoresContainer;
TestScoresContainer scoresContainer;
Child = new Container
{
@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Online
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
scoresContainer = new ScoresContainer(),
scoresContainer = new TestScoresContainer(),
}
};
@ -245,5 +245,13 @@ namespace osu.Game.Tests.Visual.Online
scoresContainer.Scores = allScores;
});
}
private class TestScoresContainer : ScoresContainer
{
public new APILegacyScores Scores
{
set => base.Scores = value;
}
}
}
}

View File

@ -11,6 +11,9 @@ using osuTK;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
namespace osu.Game.Overlays.BeatmapSet.Scores
{
@ -24,6 +27,40 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private readonly FillFlowContainer topScoresContainer;
private readonly LoadingAnimation loadingAnimation;
[Resolved]
private IAPIProvider api { get; set; }
private GetScoresRequest getScoresRequest;
private APILegacyScores scores;
protected APILegacyScores Scores
{
get => scores;
set
{
scores = value;
updateDisplay();
}
}
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
get => beatmap;
set
{
if (beatmap == value)
return;
beatmap = value;
getScores(beatmap);
}
}
public ScoresContainer()
{
RelativeSizeAxes = Axes.X;
@ -75,7 +112,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
updateDisplay();
}
public bool Loading
private bool loading
{
set
{
@ -86,17 +123,26 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
}
}
private APILegacyScores scores;
public APILegacyScores Scores
private void getScores(BeatmapInfo beatmap)
{
get => scores;
set
{
scores = value;
getScoresRequest?.Cancel();
getScoresRequest = null;
updateDisplay();
if (beatmap?.OnlineBeatmapID.HasValue != true)
{
Scores = null;
return;
}
loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += scores => Schedule(() =>
{
Scores = scores;
loading = false;
});
api.Queue(getScoresRequest);
}
private void updateDisplay()

View File

@ -11,7 +11,6 @@ using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Overlays.BeatmapSet.Scores;
@ -29,15 +28,8 @@ namespace osu.Game.Overlays
private RulesetStore rulesets;
private readonly ScoresContainer scoreContainer;
private GetScoresRequest getScoresRequest;
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
[Resolved]
private IAPIProvider api { get; set; }
// receive input outside our bounds so we can trigger a close event on ourselves.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
@ -45,6 +37,8 @@ namespace osu.Game.Overlays
{
OsuScrollContainer scroll;
Info info;
ScoresContainer scoreContainer;
Children = new Drawable[]
{
new Box
@ -77,34 +71,12 @@ namespace osu.Game.Overlays
Header.Picker.Beatmap.ValueChanged += b =>
{
info.Beatmap = b.NewValue;
getScores(b.NewValue);
scoreContainer.Beatmap = b.NewValue;
scroll.ScrollToStart();
};
}
private void getScores(BeatmapInfo beatmap)
{
getScoresRequest?.Cancel();
getScoresRequest = null;
if (beatmap?.OnlineBeatmapID.HasValue != true)
{
scoreContainer.Scores = null;
return;
}
scoreContainer.Loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += scores => Schedule(() =>
{
scoreContainer.Scores = scores;
scoreContainer.Loading = false;
});
api.Queue(getScoresRequest);
}
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
{