From 3490b160563b74ab4a227d1f3a1885d233ab16da Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 10 Sep 2022 01:10:55 +0300 Subject: [PATCH] Add simplified `SoloGameplayLeaderboard` implementation Note that this doesn't support waiting until leaderboard finishes fetching scores. --- .../Play/HUD/SoloGameplayLeaderboard.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs diff --git a/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs b/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs new file mode 100644 index 0000000000..20af036ec9 --- /dev/null +++ b/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs @@ -0,0 +1,39 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using osu.Framework.Allocation; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Leaderboards; +using osu.Game.Rulesets.Scoring; + +namespace osu.Game.Screens.Play.HUD +{ + public class SoloGameplayLeaderboard : GameplayLeaderboard + { + [BackgroundDependencyLoader] + private void load(IAPIProvider api, ScoreProcessor processor, ILeaderboard leaderboard) + { + var local = Add(api.LocalUser.Value, true); + local.TotalScore.BindTarget = processor.TotalScore; + local.Accuracy.BindTarget = processor.Accuracy; + local.Combo.BindTarget = processor.Combo; + + foreach (var player in leaderboard.Scores) + { + // todo: APIUser is pain for IScoreInfo. + var score = Add(new APIUser + { + Id = player.User.OnlineID, + Username = player.User.Username, + }, false); + + score.TotalScore.Value = player.TotalScore; + score.Accuracy.Value = player.Accuracy; + score.Combo.Value = player.MaxCombo; + } + } + } +}