1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-22 22:17:46 +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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -36,10 +34,9 @@ namespace osu.Game.Tests.Visual.SongSelect
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay;
private ScoreManager scoreManager;
private RulesetStore rulesetStore;
private BeatmapManager beatmapManager;
private ScoreManager scoreManager = null!;
private RulesetStore rulesetStore = null!;
private BeatmapManager beatmapManager = null!;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
@ -74,7 +71,7 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test]
public void TestLocalScoresDisplay()
{
BeatmapInfo beatmapInfo = null;
BeatmapInfo beatmapInfo = null!;
AddStep(@"Set scope", () => leaderboard.Scope = BeatmapLeaderboardScope.Local);
@ -387,7 +384,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private class FailableLeaderboard : BeatmapLeaderboard
{
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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Development;
@ -54,23 +51,23 @@ namespace osu.Game.Online.Leaderboards
private readonly Container placeholderContainer;
private readonly UserTopScoreContainer<TScoreInfo> userScoreContainer;
private FillFlowContainer<LeaderboardScore> scoreFlowContainer;
private FillFlowContainer<LeaderboardScore>? scoreFlowContainer;
private readonly LoadingSpinner loading;
private CancellationTokenSource currentFetchCancellationSource;
private CancellationTokenSource currentScoresAsyncLoadCancellationSource;
private CancellationTokenSource? currentFetchCancellationSource;
private CancellationTokenSource? currentScoresAsyncLoadCancellationSource;
private APIRequest fetchScoresRequest;
private APIRequest? fetchScoresRequest;
private LeaderboardState state;
[Resolved(CanBeNull = true)]
private IAPIProvider api { get; set; }
private IAPIProvider? api { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private TScope scope;
private TScope scope = default!;
public TScope Scope
{
@ -179,7 +176,7 @@ namespace osu.Game.Online.Leaderboards
/// </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)
protected void SetScores(IEnumerable<TScoreInfo>? scores, TScoreInfo? userScore = default)
{
this.scores.Clear();
if (scores != null)
@ -213,8 +210,7 @@ namespace osu.Game.Online.Leaderboards
/// </summary>
/// <param name="cancellationToken"></param>
/// <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);
@ -298,7 +294,7 @@ namespace osu.Game.Online.Leaderboards
#region Placeholder handling
private Placeholder placeholder;
private Placeholder? placeholder;
private void setState(LeaderboardState state)
{
@ -325,7 +321,7 @@ namespace osu.Game.Online.Leaderboards
placeholder.FadeInFromZero(fade_duration, Easing.OutQuint);
}
private Placeholder getPlaceholderFor(LeaderboardState state)
private Placeholder? getPlaceholderFor(LeaderboardState state)
{
switch (state)
{

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Threading;
using osu.Framework.Bindables;
@ -18,13 +16,15 @@ namespace osu.Game.Online.Leaderboards
{
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 Func<TScoreInfo, LeaderboardScore> createScoreDelegate;
protected override bool StartHidden => true;
private CancellationTokenSource? loadScoreCancellation;
public UserTopScoreContainer(Func<TScoreInfo, LeaderboardScore> createScoreDelegate)
{
this.createScoreDelegate = createScoreDelegate;
@ -65,9 +65,7 @@ namespace osu.Game.Online.Leaderboards
Score.BindValueChanged(onScoreChanged);
}
private CancellationTokenSource loadScoreCancellation;
private void onScoreChanged(ValueChangedEvent<TScoreInfo> score)
private void onScoreChanged(ValueChangedEvent<TScoreInfo?> score)
{
var newScore = score.NewValue;