2022-12-12 05:08:48 +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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2023-06-27 15:38:15 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-12-12 18:53:07 +08:00
|
|
|
using osu.Game.Rulesets;
|
2022-12-17 00:40:39 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2022-12-12 05:08:48 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD.JudgementCounter
|
|
|
|
{
|
2023-01-17 17:16:46 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Keeps track of judgements for a current play session, exposing bindable counts which can
|
|
|
|
/// be used for display purposes.
|
|
|
|
/// </summary>
|
2023-06-27 15:38:15 +08:00
|
|
|
public partial class JudgementCountController : Component
|
2022-12-12 05:08:48 +08:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
|
|
|
|
2024-01-15 14:54:00 +08:00
|
|
|
private readonly Dictionary<HitResult, JudgementCount> results = new Dictionary<HitResult, JudgementCount>();
|
|
|
|
|
|
|
|
public IEnumerable<JudgementCount> Counters => counters;
|
|
|
|
|
|
|
|
private readonly List<JudgementCount> counters = new List<JudgementCount>();
|
2022-12-12 05:08:48 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-12-12 22:10:10 +08:00
|
|
|
private void load(IBindable<RulesetInfo> ruleset)
|
2022-12-12 05:08:48 +08:00
|
|
|
{
|
2024-01-15 14:54:00 +08:00
|
|
|
// Due to weirdness in judgements, some results have the same name and should be aggregated for display purposes.
|
|
|
|
// There's only one case of this right now ("slider end").
|
|
|
|
foreach (var group in ruleset.Value.CreateInstance().GetHitResults().GroupBy(r => r.displayName))
|
2022-12-12 05:08:48 +08:00
|
|
|
{
|
2024-01-15 14:54:00 +08:00
|
|
|
var judgementCount = new JudgementCount
|
2022-12-12 05:08:48 +08:00
|
|
|
{
|
2024-01-15 14:54:00 +08:00
|
|
|
DisplayName = group.Key,
|
|
|
|
Types = group.Select(r => r.result).ToArray(),
|
2022-12-12 06:47:17 +08:00
|
|
|
ResultCount = new BindableInt()
|
2024-01-15 14:54:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
counters.Add(judgementCount);
|
|
|
|
|
|
|
|
foreach (var r in group)
|
|
|
|
results[r.result] = judgementCount;
|
2022-12-12 05:08:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-12-15 06:00:34 +08:00
|
|
|
|
2024-09-27 15:56:22 +08:00
|
|
|
scoreProcessor.OnResetFromReplayFrame += updateAllCountsFromReplayFrame;
|
2022-12-17 00:40:39 +08:00
|
|
|
scoreProcessor.NewJudgement += judgement => updateCount(judgement, false);
|
|
|
|
scoreProcessor.JudgementReverted += judgement => updateCount(judgement, true);
|
2024-09-18 13:35:44 +08:00
|
|
|
}
|
|
|
|
|
2024-09-27 15:56:22 +08:00
|
|
|
private bool hasUpdatedCountsFromReplayFrame;
|
2024-09-19 18:23:14 +08:00
|
|
|
|
2024-09-27 15:56:22 +08:00
|
|
|
private void updateAllCountsFromReplayFrame()
|
2024-09-18 13:35:44 +08:00
|
|
|
{
|
2024-09-27 15:56:22 +08:00
|
|
|
if (hasUpdatedCountsFromReplayFrame)
|
2024-09-18 13:35:44 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (var kvp in scoreProcessor.Statistics)
|
|
|
|
{
|
|
|
|
if (!results.TryGetValue(kvp.Key, out var count))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count.ResultCount.Value = kvp.Value;
|
|
|
|
}
|
2024-09-19 18:23:14 +08:00
|
|
|
|
2024-09-27 15:56:22 +08:00
|
|
|
hasUpdatedCountsFromReplayFrame = true;
|
2022-12-17 00:40:39 +08:00
|
|
|
}
|
2022-12-15 06:00:34 +08:00
|
|
|
|
2022-12-17 00:40:39 +08:00
|
|
|
private void updateCount(JudgementResult judgement, bool revert)
|
|
|
|
{
|
2024-01-15 14:54:00 +08:00
|
|
|
if (!results.TryGetValue(judgement.Type, out var count))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (revert)
|
|
|
|
count.ResultCount.Value--;
|
|
|
|
else
|
|
|
|
count.ResultCount.Value++;
|
2022-12-12 05:08:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|