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

Apply NRT to base Leaderboard classes

This commit is contained in:
Dean Herbert 2022-09-26 16:12:47 +09:00
parent 32d56fe3a9
commit a1297af441
3 changed files with 19 additions and 28 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -36,10 +34,9 @@ namespace osu.Game.Tests.Visual.SongSelect
[Cached(typeof(IDialogOverlay))] [Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay; private readonly DialogOverlay dialogOverlay;
private ScoreManager scoreManager; private ScoreManager scoreManager = null!;
private RulesetStore rulesetStore = null!;
private RulesetStore rulesetStore; private BeatmapManager beatmapManager = null!;
private BeatmapManager beatmapManager;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
@ -74,7 +71,7 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestLocalScoresDisplay() public void TestLocalScoresDisplay()
{ {
BeatmapInfo beatmapInfo = null; BeatmapInfo beatmapInfo = null!;
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local); AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
@ -387,7 +384,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private class FailableLeaderboard : BeatmapLeaderboard private class FailableLeaderboard : BeatmapLeaderboard
{ {
public new void SetErrorState(LeaderboardState state) => base.SetErrorState(state); public new void SetErrorState(LeaderboardState state) => base.SetErrorState(state);
public new void SetScores(IEnumerable<ScoreInfo> scores, ScoreInfo userScore = default) => base.SetScores(scores, userScore); public new void SetScores(IEnumerable<ScoreInfo>? scores, ScoreInfo? userScore = null) => base.SetScores(scores, userScore);
} }
} }
} }

View File

@ -1,14 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Development; using osu.Framework.Development;
@ -54,23 +51,23 @@ namespace osu.Game.Online.Leaderboards
private readonly Container placeholderContainer; private readonly Container placeholderContainer;
private readonly UserTopScoreContainer<TScoreInfo> userScoreContainer; private readonly UserTopScoreContainer<TScoreInfo> userScoreContainer;
private FillFlowContainer<LeaderboardScore> scoreFlowContainer; private FillFlowContainer<LeaderboardScore>? scoreFlowContainer;
private readonly LoadingSpinner loading; private readonly LoadingSpinner loading;
private CancellationTokenSource currentFetchCancellationSource; private CancellationTokenSource? currentFetchCancellationSource;
private CancellationTokenSource currentScoresAsyncLoadCancellationSource; private CancellationTokenSource? currentScoresAsyncLoadCancellationSource;
private APIRequest fetchScoresRequest; private APIRequest? fetchScoresRequest;
private LeaderboardState state; private LeaderboardState state;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private IAPIProvider api { get; set; } private IAPIProvider? api { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>(); private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private TScope scope; private TScope scope = default!;
public TScope Scope public TScope Scope
{ {
@ -179,7 +176,7 @@ namespace osu.Game.Online.Leaderboards
/// </summary> /// </summary>
/// <param name="scores">The scores to display.</param> /// <param name="scores">The scores to display.</param>
/// <param name="userScore">The user top score, if any.</param> /// <param name="userScore">The user top score, if any.</param>
protected void SetScores(IEnumerable<TScoreInfo> scores, TScoreInfo userScore = default) protected void SetScores(IEnumerable<TScoreInfo>? scores, TScoreInfo? userScore = default)
{ {
this.scores.Clear(); this.scores.Clear();
if (scores != null) if (scores != null)
@ -213,8 +210,7 @@ namespace osu.Game.Online.Leaderboards
/// </summary> /// </summary>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns> /// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns>
[CanBeNull] protected abstract APIRequest? FetchScores(CancellationToken cancellationToken);
protected abstract APIRequest FetchScores(CancellationToken cancellationToken);
protected abstract LeaderboardScore CreateDrawableScore(TScoreInfo model, int index); protected abstract LeaderboardScore CreateDrawableScore(TScoreInfo model, int index);
@ -298,7 +294,7 @@ namespace osu.Game.Online.Leaderboards
#region Placeholder handling #region Placeholder handling
private Placeholder placeholder; private Placeholder? placeholder;
private void setState(LeaderboardState state) private void setState(LeaderboardState state)
{ {
@ -325,7 +321,7 @@ namespace osu.Game.Online.Leaderboards
placeholder.FadeInFromZero(fade_duration, Easing.OutQuint); placeholder.FadeInFromZero(fade_duration, Easing.OutQuint);
} }
private Placeholder getPlaceholderFor(LeaderboardState state) private Placeholder? getPlaceholderFor(LeaderboardState state)
{ {
switch (state) switch (state)
{ {

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Threading; using System.Threading;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -18,13 +16,15 @@ namespace osu.Game.Online.Leaderboards
{ {
private const int duration = 500; private const int duration = 500;
public Bindable<TScoreInfo> Score = new Bindable<TScoreInfo>(); public Bindable<TScoreInfo?> Score = new Bindable<TScoreInfo?>();
private readonly Container scoreContainer; private readonly Container scoreContainer;
private readonly Func<TScoreInfo, LeaderboardScore> createScoreDelegate; private readonly Func<TScoreInfo, LeaderboardScore> createScoreDelegate;
protected override bool StartHidden => true; protected override bool StartHidden => true;
private CancellationTokenSource? loadScoreCancellation;
public UserTopScoreContainer(Func<TScoreInfo, LeaderboardScore> createScoreDelegate) public UserTopScoreContainer(Func<TScoreInfo, LeaderboardScore> createScoreDelegate)
{ {
this.createScoreDelegate = createScoreDelegate; this.createScoreDelegate = createScoreDelegate;
@ -65,9 +65,7 @@ namespace osu.Game.Online.Leaderboards
Score.BindValueChanged(onScoreChanged); Score.BindValueChanged(onScoreChanged);
} }
private CancellationTokenSource loadScoreCancellation; private void onScoreChanged(ValueChangedEvent<TScoreInfo?> score)
private void onScoreChanged(ValueChangedEvent<TScoreInfo> score)
{ {
var newScore = score.NewValue; var newScore = score.NewValue;