From 81d54a9f32ad3f2eb04d360b6078ab78aa2f03ec Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Fri, 18 Apr 2025 05:43:47 -0400 Subject: [PATCH] Implement score fetch functionality Copied logic from `BeatmapLeaderboard`. --- .../TestSceneBeatmapLeaderboardWedge.cs | 4 --- .../SelectV2/BeatmapLeaderboardWedge.cs | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapLeaderboardWedge.cs b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapLeaderboardWedge.cs index 060f2ad956..f034049476 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapLeaderboardWedge.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapLeaderboardWedge.cs @@ -182,8 +182,6 @@ namespace osu.Game.Tests.Visual.SongSelectV2 } [Test] - [Ignore("Pending implementation")] - // todo: add score fetch functionality to BeatmapLeaderboardWedge public void TestLocalScoresDisplay() { BeatmapInfo beatmapInfo = null!; @@ -212,8 +210,6 @@ namespace osu.Game.Tests.Visual.SongSelectV2 } [Test] - [Ignore("Pending implementation")] - // todo: add score fetch functionality to BeatmapLeaderboardWedge public void TestLocalScoresDisplayOnBeatmapEdit() { BeatmapInfo beatmapInfo = null!; diff --git a/osu.Game/Screens/SelectV2/BeatmapLeaderboardWedge.cs b/osu.Game/Screens/SelectV2/BeatmapLeaderboardWedge.cs index d15927a67f..66e799c93e 100644 --- a/osu.Game/Screens/SelectV2/BeatmapLeaderboardWedge.cs +++ b/osu.Game/Screens/SelectV2/BeatmapLeaderboardWedge.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Threading; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -43,6 +42,9 @@ namespace osu.Game.Screens.SelectV2 private Container placeholderContainer = null!; private Placeholder? placeholder; + [Resolved] + private LeaderboardManager leaderboardManager { get; set; } = null!; + [Resolved] private IBindable beatmap { get; set; } = null!; @@ -66,6 +68,8 @@ namespace osu.Game.Screens.SelectV2 private CancellationTokenSource? cancellationTokenSource; + private readonly Bindable fetchedScores = new Bindable(); + [BackgroundDependencyLoader] private void load() { @@ -142,6 +146,8 @@ namespace osu.Game.Screens.SelectV2 loading = new LoadingLayer(), } }; + + ((IBindable)fetchedScores).BindTo(leaderboardManager.Scores); } protected override void LoadComplete() @@ -217,8 +223,22 @@ namespace osu.Game.Screens.SelectV2 return; } - // todo: missing implementation - SetScores(Array.Empty(), null); + leaderboardManager.FetchWithCriteriaAsync(new LeaderboardCriteria(fetchBeatmapInfo, fetchRuleset, Scope.Value, FilterBySelectedMods.Value ? mods.Value.ToArray() : null)) + .ContinueWith(t => + { + if (t.Exception != null && !t.IsCanceled) + { + Schedule(() => SetState(LeaderboardState.NetworkFailure)); + return; + } + + fetchedScores.UnbindEvents(); + fetchedScores.BindValueChanged(scores => + { + if (scores.NewValue != null) + Schedule(() => SetScores(scores.NewValue.TopScores, scores.NewValue.UserScore)); + }, true); + }); } protected void SetScores(IEnumerable scores, ScoreInfo? userScore)