mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Merge pull request #20485 from peppy/leaderboard-nrt
Apply NRT to leaderboard hierarchy
This commit is contained in:
commit
836da6a5e6
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
InputManager.PressButton(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for fetch", () => leaderboard.Scores != null);
|
||||
AddUntilStep("wait for fetch", () => leaderboard.Scores.Any());
|
||||
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != scoreBeingDeleted.OnlineID));
|
||||
|
||||
// "Clean up"
|
||||
@ -174,7 +174,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public void TestDeleteViaDatabase()
|
||||
{
|
||||
AddStep("delete top score", () => scoreManager.Delete(importedScores[0]));
|
||||
AddUntilStep("wait for fetch", () => leaderboard.Scores != null);
|
||||
AddUntilStep("wait for fetch", () => leaderboard.Scores.Any());
|
||||
AddUntilStep("score removed from leaderboard", () => leaderboard.Scores.All(s => s.OnlineID != importedScores[0].OnlineID));
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -16,7 +14,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
|
||||
{
|
||||
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
||||
private Bindable<long?> roomId { get; set; }
|
||||
private Bindable<long?> roomId { get; set; } = null!;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -33,7 +31,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
|
||||
protected override bool IsOnlineScope => true;
|
||||
|
||||
protected override APIRequest FetchScores(CancellationToken cancellationToken)
|
||||
protected override APIRequest? FetchScores(CancellationToken cancellationToken)
|
||||
{
|
||||
if (roomId.Value == null)
|
||||
return null;
|
||||
|
@ -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.Diagnostics;
|
||||
@ -25,11 +23,11 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
{
|
||||
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
|
||||
{
|
||||
public Action<ScoreInfo> ScoreSelected;
|
||||
public Action<ScoreInfo>? ScoreSelected;
|
||||
|
||||
private BeatmapInfo beatmapInfo;
|
||||
private BeatmapInfo? beatmapInfo;
|
||||
|
||||
public BeatmapInfo BeatmapInfo
|
||||
public BeatmapInfo? BeatmapInfo
|
||||
{
|
||||
get => beatmapInfo;
|
||||
set
|
||||
@ -70,26 +68,26 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private ScoreManager scoreManager { get; set; }
|
||||
private ScoreManager scoreManager { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
|
||||
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
private RulesetStore rulesets { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private RealmAccess realm { get; set; }
|
||||
private RealmAccess realm { get; set; } = null!;
|
||||
|
||||
private IDisposable scoreSubscription;
|
||||
private IDisposable? scoreSubscription;
|
||||
|
||||
private GetScoresRequest scoreRetrievalRequest;
|
||||
private GetScoresRequest? scoreRetrievalRequest;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -104,10 +102,9 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
|
||||
protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
|
||||
|
||||
protected override APIRequest FetchScores(CancellationToken cancellationToken)
|
||||
protected override APIRequest? FetchScores(CancellationToken cancellationToken)
|
||||
{
|
||||
var fetchBeatmapInfo = BeatmapInfo;
|
||||
var fetchRuleset = ruleset.Value ?? fetchBeatmapInfo.Ruleset;
|
||||
|
||||
if (fetchBeatmapInfo == null)
|
||||
{
|
||||
@ -115,13 +112,15 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
return null;
|
||||
}
|
||||
|
||||
var fetchRuleset = ruleset.Value ?? fetchBeatmapInfo.Ruleset;
|
||||
|
||||
if (Scope == BeatmapLeaderboardScope.Local)
|
||||
{
|
||||
subscribeToLocalScores(fetchBeatmapInfo, cancellationToken);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (api?.IsLoggedIn != true)
|
||||
if (!api.IsLoggedIn)
|
||||
{
|
||||
SetErrorState(LeaderboardState.NotLoggedIn);
|
||||
return null;
|
||||
@ -145,7 +144,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
return null;
|
||||
}
|
||||
|
||||
IReadOnlyList<Mod> requestMods = null;
|
||||
IReadOnlyList<Mod>? requestMods = null;
|
||||
|
||||
if (filterMods && !mods.Value.Any())
|
||||
// add nomod for the request
|
||||
@ -186,7 +185,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
+ $" AND {nameof(ScoreInfo.DeletePending)} == false"
|
||||
, beatmapInfo.ID, ruleset.Value.ShortName), localScoresChanged);
|
||||
|
||||
void localScoresChanged(IRealmCollection<ScoreInfo> sender, ChangeSet changes, Exception exception)
|
||||
void localScoresChanged(IRealmCollection<ScoreInfo> sender, ChangeSet? changes, Exception exception)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user