2022-09-09 22:10:55 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-09-13 08:07:13 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-09-09 22:10:55 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-09-13 08:49:53 +00:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Game.Online.Leaderboards;
|
2022-09-09 22:10:55 +00:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-09-13 08:07:13 +00:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Users;
|
2022-09-09 22:10:55 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
|
|
|
public class SoloGameplayLeaderboard : GameplayLeaderboard
|
|
|
|
{
|
2022-09-13 08:07:13 +00:00
|
|
|
private readonly IUser trackingUser;
|
|
|
|
|
2022-09-13 08:49:53 +00:00
|
|
|
private readonly IBindableList<ScoreInfo> scores = new BindableList<ScoreInfo>();
|
|
|
|
|
2022-09-13 08:07:13 +00:00
|
|
|
[Resolved]
|
|
|
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
|
|
|
|
|
|
|
public SoloGameplayLeaderboard(IUser trackingUser)
|
2022-09-09 22:10:55 +00:00
|
|
|
{
|
2022-09-13 08:07:13 +00:00
|
|
|
this.trackingUser = trackingUser;
|
|
|
|
}
|
|
|
|
|
2022-09-13 08:49:53 +00:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(ILeaderboardScoreSource? scoreSource)
|
|
|
|
{
|
|
|
|
if (scoreSource != null)
|
|
|
|
scores.BindTo(scoreSource.Scores);
|
|
|
|
|
|
|
|
scores.BindCollectionChanged((_, __) => Scheduler.AddOnce(showScores, scores), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showScores(IEnumerable<IScoreInfo> scores)
|
2022-09-13 08:07:13 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
if (!scores.Any())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ILeaderboardScore local = Add(trackingUser, true);
|
2022-09-13 07:04:38 +00:00
|
|
|
|
2022-09-13 08:07:13 +00:00
|
|
|
local.TotalScore.BindTarget = scoreProcessor.TotalScore;
|
|
|
|
local.Accuracy.BindTarget = scoreProcessor.Accuracy;
|
|
|
|
local.Combo.BindTarget = scoreProcessor.Combo;
|
2022-09-09 22:10:55 +00:00
|
|
|
|
2022-09-13 08:07:13 +00:00
|
|
|
foreach (var s in scores)
|
2022-09-09 22:10:55 +00:00
|
|
|
{
|
2022-09-13 08:07:13 +00:00
|
|
|
var score = Add(s.User, false);
|
2022-09-09 22:10:55 +00:00
|
|
|
|
2022-09-13 07:04:38 +00:00
|
|
|
score.TotalScore.Value = s.TotalScore;
|
|
|
|
score.Accuracy.Value = s.Accuracy;
|
|
|
|
score.Combo.Value = s.MaxCombo;
|
2022-09-09 22:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|