mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Consolidate flows of Set
operations, either result or error
This commit is contained in:
parent
c401629dd8
commit
acc1199add
@ -101,7 +101,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
public void TestGlobalScoresDisplay()
|
||||
{
|
||||
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Global);
|
||||
AddStep(@"New Scores", () => leaderboard.Scores = generateSampleScores(new BeatmapInfo()));
|
||||
AddStep(@"New Scores", () => leaderboard.SetScores(generateSampleScores(new BeatmapInfo())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -124,7 +124,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
|
||||
private void showPersonalBestWithNullPosition()
|
||||
{
|
||||
leaderboard.TopScore = new ScoreInfo
|
||||
leaderboard.SetScores(leaderboard.Scores, new ScoreInfo
|
||||
{
|
||||
Rank = ScoreRank.XH,
|
||||
Accuracy = 1,
|
||||
@ -142,12 +142,12 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
FlagName = @"ES",
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void showPersonalBest()
|
||||
{
|
||||
leaderboard.TopScore = new ScoreInfo
|
||||
leaderboard.SetScores(leaderboard.Scores, new ScoreInfo
|
||||
{
|
||||
Position = 999,
|
||||
Rank = ScoreRank.XH,
|
||||
@ -166,7 +166,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
FlagName = @"ES",
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private void loadMoreScores(Func<BeatmapInfo> beatmapInfo)
|
||||
@ -404,12 +404,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
private class FailableLeaderboard : BeatmapLeaderboard
|
||||
{
|
||||
public new void SetErrorState(LeaderboardErrorState errorState) => base.SetErrorState(errorState);
|
||||
|
||||
public new ICollection<ScoreInfo> Scores
|
||||
{
|
||||
get => base.Scores;
|
||||
set => base.Scores = value;
|
||||
}
|
||||
public new void SetScores(IEnumerable<ScoreInfo> scores, ScoreInfo userScore = default) => base.SetScores(scores, userScore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ namespace osu.Game.Online.Leaderboards
|
||||
/// <typeparam name="TScoreInfo">The score model class.</typeparam>
|
||||
public abstract class Leaderboard<TScope, TScoreInfo> : CompositeDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The currently displayed scores.
|
||||
/// </summary>
|
||||
public IEnumerable<TScoreInfo> Scores => scores;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current scope should refetch in response to changes in API connectivity state.
|
||||
/// </summary>
|
||||
@ -42,7 +47,7 @@ namespace osu.Game.Online.Leaderboards
|
||||
|
||||
private readonly OsuScrollContainer scrollContainer;
|
||||
private readonly Container placeholderContainer;
|
||||
private readonly UserTopScoreContainer<TScoreInfo> topScoreContainer;
|
||||
private readonly UserTopScoreContainer<TScoreInfo> userScoreContainer;
|
||||
|
||||
private FillFlowContainer<LeaderboardScore> scoreFlowContainer;
|
||||
|
||||
@ -62,30 +67,6 @@ namespace osu.Game.Online.Leaderboards
|
||||
|
||||
private ICollection<TScoreInfo> scores;
|
||||
|
||||
public ICollection<TScoreInfo> Scores
|
||||
{
|
||||
get => scores;
|
||||
protected set
|
||||
{
|
||||
scores = value;
|
||||
Scheduler.Add(updateScoresDrawables, false);
|
||||
}
|
||||
}
|
||||
|
||||
public TScoreInfo TopScore
|
||||
{
|
||||
get => topScoreContainer.Score.Value;
|
||||
set
|
||||
{
|
||||
topScoreContainer.Score.Value = value;
|
||||
|
||||
if (value == null)
|
||||
topScoreContainer.Hide();
|
||||
else
|
||||
topScoreContainer.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private TScope scope;
|
||||
|
||||
public TScope Scope
|
||||
@ -133,7 +114,7 @@ namespace osu.Game.Online.Leaderboards
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Child = topScoreContainer = new UserTopScoreContainer<TScoreInfo>(CreateDrawableTopScore)
|
||||
Child = userScoreContainer = new UserTopScoreContainer<TScoreInfo>(CreateDrawableTopScore)
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -176,15 +157,6 @@ namespace osu.Game.Online.Leaderboards
|
||||
/// </summary>
|
||||
public void RefetchScores() => Scheduler.AddOnce(refetchScores);
|
||||
|
||||
/// <summary>
|
||||
/// Reset the leaderboard into an empty state.
|
||||
/// </summary>
|
||||
protected virtual void Reset()
|
||||
{
|
||||
cancelPendingWork();
|
||||
Scores = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call when a retrieval or display failure happened to show a relevant message to the user.
|
||||
/// </summary>
|
||||
@ -202,6 +174,24 @@ namespace osu.Game.Online.Leaderboards
|
||||
setErrorState(errorState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call when score retrieval is ready to be displayed.
|
||||
/// </summary>
|
||||
/// <param name="scores">The scores to display.</param>
|
||||
/// <param name="userScore">The user top score, if any.</param>
|
||||
protected void SetScores(IEnumerable<TScoreInfo> scores, TScoreInfo userScore = default)
|
||||
{
|
||||
this.scores = scores?.ToList();
|
||||
userScoreContainer.Score.Value = userScore;
|
||||
|
||||
if (userScore == null)
|
||||
userScoreContainer.Hide();
|
||||
else
|
||||
userScoreContainer.Show();
|
||||
|
||||
Scheduler.Add(updateScoresDrawables, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a fetch/refresh of scores to be displayed.
|
||||
/// </summary>
|
||||
@ -218,7 +208,8 @@ namespace osu.Game.Online.Leaderboards
|
||||
{
|
||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||
|
||||
Reset();
|
||||
cancelPendingWork();
|
||||
SetScores(null);
|
||||
|
||||
setErrorState(LeaderboardErrorState.NoError);
|
||||
loading.Show();
|
||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
if (id.NewValue == null)
|
||||
return;
|
||||
|
||||
Scores = null;
|
||||
SetScores(null);
|
||||
RefetchScores();
|
||||
}, true);
|
||||
}
|
||||
@ -43,8 +43,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
Scores = r.Leaderboard;
|
||||
TopScore = r.UserScore;
|
||||
SetScores(r.Leaderboard, r.UserScore);
|
||||
};
|
||||
|
||||
return req;
|
||||
|
@ -93,12 +93,6 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
TopScore = null;
|
||||
}
|
||||
|
||||
protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
|
||||
|
||||
protected override APIRequest FetchScores(CancellationToken cancellationToken)
|
||||
@ -153,8 +147,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
Scores = task.GetResultSafely();
|
||||
TopScore = r.UserScore?.CreateScoreInfo(rulesets, fetchBeatmapInfo);
|
||||
SetScores(task.GetResultSafely(), r.UserScore?.CreateScoreInfo(rulesets, fetchBeatmapInfo));
|
||||
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
};
|
||||
|
||||
@ -210,7 +203,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
scoreManager.OrderByTotalScoreAsync(scores.ToArray(), cancellationToken)
|
||||
.ContinueWith(ordered =>
|
||||
{
|
||||
Scores = ordered.GetResultSafely();
|
||||
SetScores(ordered.GetResultSafely());
|
||||
}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user