1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:02:55 +08:00

Improve state reset flow

This commit is contained in:
Dean Herbert 2019-09-19 15:23:33 +09:00
parent 4967ffd8e5
commit 098e89cb66
3 changed files with 42 additions and 29 deletions

View File

@ -120,9 +120,7 @@ namespace osu.Game.Online.Leaderboards
{
if (value != PlaceholderState.Successful)
{
getScoresRequest?.Cancel();
getScoresRequest = null;
Scores = null;
Reset();
}
if (value == placeholderState)
@ -166,7 +164,7 @@ namespace osu.Game.Online.Leaderboards
protected Leaderboard()
{
Children = new Drawable[]
InternalChildren = new Drawable[]
{
new GridContainer
{
@ -204,6 +202,13 @@ namespace osu.Game.Online.Leaderboards
};
}
protected virtual void Reset()
{
getScoresRequest?.Cancel();
getScoresRequest = null;
Scores = null;
}
private IAPIProvider api;
private ScheduledDelegate pendingUpdateScores;

View File

@ -17,9 +17,8 @@ namespace osu.Game.Screens.Select.Details
public class UserTopScoreContainer : VisibilityContainer
{
private const int height = 90;
private const int duration = 800;
private const int duration = 500;
private readonly Container contentContainer;
private readonly Container scoreContainer;
public Bindable<APILegacyUserTopScoreInfo> Score = new Bindable<APILegacyUserTopScoreInfo>();
@ -38,7 +37,7 @@ namespace osu.Game.Screens.Select.Details
Children = new Drawable[]
{
contentContainer = new Container
new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
@ -74,15 +73,12 @@ namespace osu.Game.Screens.Select.Details
{
var newScore = score.NewValue;
if (newScore == null)
{
Hide();
return;
}
scoreContainer.Clear();
loadScoreCancellation?.Cancel();
if (newScore == null)
return;
LoadComponentAsync(new LeaderboardScore(newScore.Score, newScore.Position)
{
Action = () => ScoreSelected?.Invoke(newScore.Score)
@ -93,12 +89,14 @@ namespace osu.Game.Screens.Select.Details
}, (loadScoreCancellation = new CancellationTokenSource()).Token);
}
protected override void PopIn() => this.ResizeHeightTo(height, duration / 4f, Easing.OutQuint).OnComplete(_ => contentContainer.FadeIn(duration, Easing.OutQuint));
protected override void PopIn()
{
this.FadeIn(duration, Easing.OutQuint);
}
protected override void PopOut()
{
this.ResizeHeightTo(0);
contentContainer.FadeOut(duration / 4f, Easing.OutQuint);
this.FadeOut(duration, Easing.OutQuint);
}
}
}

View File

@ -14,13 +14,12 @@ using osu.Game.Online.Leaderboards;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Select.Details;
namespace osu.Game.Screens.Select.Leaderboards
{
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
{
public Bindable<APILegacyUserTopScoreInfo> TopScore = new Bindable<APILegacyUserTopScoreInfo>();
public Action<ScoreInfo> ScoreSelected;
private BeatmapInfo beatmap;
@ -40,8 +39,25 @@ namespace osu.Game.Screens.Select.Leaderboards
}
}
public APILegacyUserTopScoreInfo TopScore
{
get => topScoreContainer.Score.Value;
set
{
if (value == null)
topScoreContainer.Hide();
else
{
topScoreContainer.Show();
topScoreContainer.Score.Value = value;
}
}
}
private bool filterMods;
private UserTopScoreContainer topScoreContainer;
/// <summary>
/// Whether to apply the game's currently selected mods as a filter when retrieving scores.
/// </summary>
@ -81,25 +97,19 @@ namespace osu.Game.Screens.Select.Leaderboards
UpdateScores();
};
TopScore.BindValueChanged(newTopScore);
Content.Add(topScoreContainer = new UserTopScoreContainer());
}
private void newTopScore(ValueChangedEvent<APILegacyUserTopScoreInfo> score)
protected override void Reset()
{
Content.Clear();
if (score.NewValue != null)
{
}
base.Reset();
TopScore = null;
}
protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
TopScore.Value = null;
if (Beatmap == null)
{
PlaceholderState = PlaceholderState.NoneSelected;
@ -161,7 +171,7 @@ namespace osu.Game.Screens.Select.Leaderboards
req.Success += r =>
{
scoresCallback?.Invoke(r.Scores);
TopScore.Value = r.UserScore;
TopScore = r.UserScore;
};
return req;