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.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;
|
2022-09-26 21:11:38 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Configuration;
|
2022-11-18 14:47:31 +08:00
|
|
|
using osu.Game.Online.API.Requests;
|
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;
|
2023-05-18 17:53:43 +08:00
|
|
|
using osu.Game.Scoring.Legacy;
|
2022-11-17 19:12:36 +08:00
|
|
|
using osu.Game.Screens.Select;
|
2022-09-13 16:07:13 +08:00
|
|
|
using osu.Game.Users;
|
2022-09-10 06:10:55 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class SoloGameplayLeaderboard : GameplayLeaderboard
|
2022-09-10 06:10:55 +08:00
|
|
|
{
|
2022-09-26 21:11:38 +08:00
|
|
|
private const int duration = 100;
|
|
|
|
|
|
|
|
private readonly Bindable<bool> configVisibility = new Bindable<bool>();
|
2022-11-18 14:50:41 +08:00
|
|
|
|
|
|
|
private readonly Bindable<PlayBeatmapDetailArea.TabType> scoreSource = new Bindable<PlayBeatmapDetailArea.TabType>();
|
|
|
|
|
2022-09-13 16:07:13 +08:00
|
|
|
private readonly IUser trackingUser;
|
|
|
|
|
2022-09-16 17:15:17 +08:00
|
|
|
public readonly IBindableList<ScoreInfo> Scores = new BindableList<ScoreInfo>();
|
2022-09-13 16:49:53 +08:00
|
|
|
|
2022-09-13 16:07:13 +08:00
|
|
|
[Resolved]
|
|
|
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
|
|
|
|
2022-09-27 13:43:08 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the leaderboard should be visible regardless of the configuration value.
|
|
|
|
/// This is true by default, but can be changed.
|
|
|
|
/// </summary>
|
|
|
|
public readonly Bindable<bool> AlwaysVisible = new Bindable<bool>(true);
|
|
|
|
|
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-26 21:11:38 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
config.BindWith(OsuSetting.GameplayLeaderboard, configVisibility);
|
2022-11-18 14:50:41 +08:00
|
|
|
config.BindWith(OsuSetting.BeatmapDetailTab, scoreSource);
|
2022-09-26 21:11:38 +08:00
|
|
|
}
|
|
|
|
|
2022-09-16 17:15:17 +08:00
|
|
|
protected override void LoadComplete()
|
2022-09-13 16:49:53 +08:00
|
|
|
{
|
2022-09-16 17:15:17 +08:00
|
|
|
base.LoadComplete();
|
2022-11-18 14:50:41 +08:00
|
|
|
|
2022-09-16 17:15:17 +08:00
|
|
|
Scores.BindCollectionChanged((_, _) => Scheduler.AddOnce(showScores), true);
|
2022-09-26 21:11:38 +08:00
|
|
|
|
2022-09-27 16:25:24 +08:00
|
|
|
// Alpha will be updated via `updateVisibility` below.
|
|
|
|
Alpha = 0;
|
|
|
|
|
2022-09-27 13:43:08 +08:00
|
|
|
AlwaysVisible.BindValueChanged(_ => updateVisibility());
|
2022-09-26 21:11:38 +08:00
|
|
|
configVisibility.BindValueChanged(_ => updateVisibility(), 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-16 17:15:17 +08:00
|
|
|
if (!Scores.Any())
|
2022-09-13 16:07:13 +08:00
|
|
|
return;
|
|
|
|
|
2022-09-16 17:15:17 +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
|
|
|
|
2023-05-18 17:53:43 +08:00
|
|
|
score.GetDisplayScore = s.GetDisplayScore;
|
|
|
|
score.TotalScore.Value = s.TotalScore;
|
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
|
|
|
}
|
2022-09-21 12:38:40 +08:00
|
|
|
|
|
|
|
ILeaderboardScore local = Add(trackingUser, true);
|
|
|
|
|
2023-05-18 17:53:43 +08:00
|
|
|
local.GetDisplayScore = scoreProcessor.GetDisplayScore;
|
2022-09-21 12:38:40 +08:00
|
|
|
local.TotalScore.BindTarget = scoreProcessor.TotalScore;
|
|
|
|
local.Accuracy.BindTarget = scoreProcessor.Accuracy;
|
2022-10-02 18:40:31 +08:00
|
|
|
local.Combo.BindTarget = scoreProcessor.HighestCombo;
|
2022-09-21 12:38:40 +08:00
|
|
|
|
|
|
|
// Local score should always show lower than any existing scores in cases of ties.
|
|
|
|
local.DisplayOrder.Value = long.MaxValue;
|
2022-09-10 06:10:55 +08:00
|
|
|
}
|
2022-09-26 21:11:38 +08:00
|
|
|
|
2023-01-06 16:58:38 +08:00
|
|
|
protected override bool CheckValidScorePosition(GameplayLeaderboardScore score, int position)
|
2022-11-17 19:12:36 +08:00
|
|
|
{
|
2022-11-18 14:50:41 +08:00
|
|
|
// change displayed position to '-' when there are 50 already submitted scores and tracked score is last
|
2023-01-06 16:58:38 +08:00
|
|
|
if (score.Tracked && scoreSource.Value != PlayBeatmapDetailArea.TabType.Local)
|
2022-11-17 19:12:36 +08:00
|
|
|
{
|
2023-01-06 16:58:38 +08:00
|
|
|
if (position == Flow.Count && Flow.Count > GetScoresRequest.MAX_SCORES_PER_REQUEST)
|
2022-11-18 14:52:39 +08:00
|
|
|
return false;
|
2022-11-17 19:12:36 +08:00
|
|
|
}
|
2022-11-18 14:52:39 +08:00
|
|
|
|
2023-01-06 16:58:38 +08:00
|
|
|
return base.CheckValidScorePosition(score, position);
|
2022-11-17 19:12:36 +08:00
|
|
|
}
|
|
|
|
|
2022-09-26 21:11:38 +08:00
|
|
|
private void updateVisibility() =>
|
2022-09-27 13:43:08 +08:00
|
|
|
this.FadeTo(AlwaysVisible.Value || configVisibility.Value ? 1 : 0, duration);
|
2022-09-10 06:10:55 +08:00
|
|
|
}
|
|
|
|
}
|