Track local `Player.Score`'s user rather than using `APIProvider`

This commit is contained in:
Dean Herbert 2022-09-13 16:04:38 +09:00
parent fed9a47866
commit 4c669e2bce
2 changed files with 12 additions and 17 deletions

View File

@ -1,11 +1,8 @@
// 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.Linq;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Extensions.Color4Extensions;
@ -31,7 +28,7 @@ public class GameplayLeaderboard : CompositeDrawable
private bool requiresScroll;
private readonly OsuScrollContainer scroll;
private GameplayLeaderboardScore trackedScore;
private GameplayLeaderboardScore? trackedScore;
/// <summary>
/// Create a new leaderboard.
@ -77,7 +74,7 @@ protected override void LoadComplete()
/// Whether the player should be tracked on the leaderboard.
/// Set to <c>true</c> for the local player or a player whose replay is currently being played.
/// </param>
public ILeaderboardScore Add([CanBeNull] APIUser user, bool isTracked)
public ILeaderboardScore Add(APIUser? user, bool isTracked)
{
var drawable = CreateLeaderboardScoreDrawable(user, isTracked);
@ -108,7 +105,7 @@ public void Clear()
scroll.ScrollToStart(false);
}
protected virtual GameplayLeaderboardScore CreateLeaderboardScoreDrawable(APIUser user, bool isTracked) =>
protected virtual GameplayLeaderboardScore CreateLeaderboardScoreDrawable(APIUser? user, bool isTracked) =>
new GameplayLeaderboardScore(user, isTracked);
protected override void Update()

View File

@ -1,10 +1,7 @@
// 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 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;
@ -14,25 +11,26 @@ namespace osu.Game.Screens.Play.HUD
public class SoloGameplayLeaderboard : GameplayLeaderboard
{
[BackgroundDependencyLoader]
private void load(IAPIProvider api, ScoreProcessor processor, ILeaderboard leaderboard)
private void load(Player player, ScoreProcessor processor, ILeaderboard leaderboard)
{
var local = Add(api.LocalUser.Value, true);
ILeaderboardScore local = Add(player.Score.ScoreInfo.User, true);
local.TotalScore.BindTarget = processor.TotalScore;
local.Accuracy.BindTarget = processor.Accuracy;
local.Combo.BindTarget = processor.Combo;
foreach (var player in leaderboard.Scores)
foreach (var s in leaderboard.Scores)
{
// todo: APIUser is pain for IScoreInfo.
var score = Add(new APIUser
{
Id = player.User.OnlineID,
Username = player.User.Username,
Id = s.User.OnlineID,
Username = s.User.Username,
}, false);
score.TotalScore.Value = player.TotalScore;
score.Accuracy.Value = player.Accuracy;
score.Combo.Value = player.MaxCombo;
score.TotalScore.Value = s.TotalScore;
score.Accuracy.Value = s.Accuracy;
score.Combo.Value = s.MaxCombo;
}
}
}