1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 20:38:33 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/JudgementCounter/JudgementTally.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2.0 KiB
C#
Raw Normal View History

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;
using osu.Framework.Graphics.Containers;
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>
2022-12-12 05:08:48 +08:00
public partial class JudgementTally : CompositeDrawable
{
[Resolved]
private ScoreProcessor scoreProcessor { get; set; } = null!;
2023-01-17 17:16:46 +08:00
public List<JudgementCount> Results = new List<JudgementCount>();
2022-12-12 05:08:48 +08:00
[BackgroundDependencyLoader]
private void load(IBindable<RulesetInfo> ruleset)
2022-12-12 05:08:48 +08:00
{
foreach (var result in ruleset.Value.CreateInstance().GetHitResults())
2022-12-12 05:08:48 +08:00
{
2023-01-17 17:16:46 +08:00
Results.Add(new JudgementCount
2022-12-12 05:08:48 +08:00
{
Type = result.result,
2022-12-12 06:47:17 +08:00
ResultCount = new BindableInt()
2022-12-12 05:08:48 +08:00
});
}
}
protected override void LoadComplete()
{
base.LoadComplete();
2022-12-17 00:40:39 +08:00
scoreProcessor.NewJudgement += judgement => updateCount(judgement, false);
scoreProcessor.JudgementReverted += judgement => updateCount(judgement, true);
}
2022-12-17 00:40:39 +08:00
private void updateCount(JudgementResult judgement, bool revert)
{
2023-01-17 17:16:46 +08:00
foreach (JudgementCount result in Results.Where(result => result.Type == judgement.Type))
2022-12-17 00:40:39 +08:00
result.ResultCount.Value = revert ? result.ResultCount.Value - 1 : result.ResultCount.Value + 1;
2022-12-12 05:08:48 +08:00
}
2023-01-17 17:16:46 +08:00
public struct JudgementCount
{
public HitResult Type { get; set; }
public BindableInt ResultCount { get; set; }
}
2022-12-12 05:08:48 +08:00
}
}