2022-09-10 06:10:55 +08: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 16:07:13 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-09-10 06:10:55 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-09-13 16:49:53 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Game.Online.Leaderboards;
|
2022-09-10 06:10:55 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-09-13 16:07:13 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Users;
|
2022-09-10 06:10:55 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
|
|
|
public class SoloGameplayLeaderboard : GameplayLeaderboard
|
|
|
|
{
|
2022-09-13 16:07:13 +08:00
|
|
|
private readonly IUser trackingUser;
|
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
private readonly IBindableList<ScoreInfo> scores = new BindableList<ScoreInfo>();
|
|
|
|
|
2022-09-14 13:02:35 +08:00
|
|
|
// hold references to ensure bindables are updated.
|
|
|
|
private readonly List<Bindable<long>> scoreBindables = new List<Bindable<long>>();
|
|
|
|
|
2022-09-13 16:07:13 +08:00
|
|
|
[Resolved]
|
|
|
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
|
|
|
|
2022-09-14 13:02:35 +08:00
|
|
|
[Resolved]
|
|
|
|
private ScoreManager scoreManager { get; set; } = null!;
|
|
|
|
|
2022-09-13 16:07:13 +08:00
|
|
|
public SoloGameplayLeaderboard(IUser trackingUser)
|
2022-09-10 06:10:55 +08:00
|
|
|
{
|
2022-09-13 16:07:13 +08:00
|
|
|
this.trackingUser = trackingUser;
|
|
|
|
}
|
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(ILeaderboardScoreSource? scoreSource)
|
|
|
|
{
|
|
|
|
if (scoreSource != null)
|
|
|
|
scores.BindTo(scoreSource.Scores);
|
|
|
|
|
2022-09-14 13:02:35 +08:00
|
|
|
scores.BindCollectionChanged((_, _) => Scheduler.AddOnce(showScores), true);
|
2022-09-13 16:49:53 +08:00
|
|
|
}
|
|
|
|
|
2022-09-14 13:02:35 +08:00
|
|
|
private void showScores()
|
2022-09-13 16:07:13 +08:00
|
|
|
{
|
|
|
|
Clear();
|
2022-09-14 13:02:35 +08:00
|
|
|
scoreBindables.Clear();
|
2022-09-13 16:07:13 +08:00
|
|
|
|
|
|
|
if (!scores.Any())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ILeaderboardScore local = Add(trackingUser, true);
|
2022-09-13 15:04:38 +08:00
|
|
|
|
2022-09-13 16:07:13 +08:00
|
|
|
local.TotalScore.BindTarget = scoreProcessor.TotalScore;
|
|
|
|
local.Accuracy.BindTarget = scoreProcessor.Accuracy;
|
|
|
|
local.Combo.BindTarget = scoreProcessor.Combo;
|
2022-09-10 06:10:55 +08:00
|
|
|
|
2022-09-14 13:18:12 +08:00
|
|
|
// Local score should always show lower than any existing scores in cases of ties.
|
|
|
|
local.DisplayOrder.Value = long.MaxValue;
|
|
|
|
|
2022-09-13 16:07:13 +08:00
|
|
|
foreach (var s in scores)
|
2022-09-10 06:10:55 +08:00
|
|
|
{
|
2022-09-13 16:07:13 +08:00
|
|
|
var score = Add(s.User, false);
|
2022-09-10 06:10:55 +08:00
|
|
|
|
2022-09-14 13:02:35 +08:00
|
|
|
var bindableTotal = scoreManager.GetBindableTotalScore(s);
|
|
|
|
|
|
|
|
// Direct binding not possible due to differing types (see https://github.com/ppy/osu/issues/20298).
|
|
|
|
bindableTotal.BindValueChanged(total => score.TotalScore.Value = total.NewValue, true);
|
|
|
|
scoreBindables.Add(bindableTotal);
|
|
|
|
|
2022-09-13 15:04:38 +08:00
|
|
|
score.Accuracy.Value = s.Accuracy;
|
|
|
|
score.Combo.Value = s.MaxCombo;
|
2022-09-14 13:18:12 +08:00
|
|
|
score.DisplayOrder.Value = s.OnlineID > 0 ? s.OnlineID : s.Date.ToUnixTimeSeconds();
|
2022-09-10 06:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|