From ffbe68bd26f8e4dbe154037ad47c15e972699676 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sun, 11 Dec 2022 22:08:48 +0100 Subject: [PATCH] Add judgementTally to HUD overlay --- .../HUD/JudgementCounter/JudgementTally.cs | 56 +++++++++++++++++++ osu.Game/Screens/Play/HUDOverlay.cs | 5 ++ 2 files changed, 61 insertions(+) create mode 100644 osu.Game/Screens/Play/HUD/JudgementCounter/JudgementTally.cs diff --git a/osu.Game/Screens/Play/HUD/JudgementCounter/JudgementTally.cs b/osu.Game/Screens/Play/HUD/JudgementCounter/JudgementTally.cs new file mode 100644 index 0000000000..2bc89aeea1 --- /dev/null +++ b/osu.Game/Screens/Play/HUD/JudgementCounter/JudgementTally.cs @@ -0,0 +1,56 @@ + + + +// Copyright (c) ppy Pty Ltd . 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; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; + +namespace osu.Game.Screens.Play.HUD.JudgementCounter +{ + public partial class JudgementTally : CompositeDrawable + { + [Resolved] + private ScoreProcessor scoreProcessor { get; set; } = null!; + + public List Results = new List(); + + [BackgroundDependencyLoader] + private void load(DrawableRuleset ruleset) + { + foreach (var result in ruleset.Ruleset.GetHitResults()) + { + Results.Add(new JudgementCounterInfo + { + ResultInfo = (result.result, result.displayName), + ResultCount = new BindableInt(), + }); + } + } + + protected override void LoadComplete() + { + base.LoadComplete(); + scoreProcessor.NewJudgement += judgement => + { + foreach (JudgementCounterInfo result in Results.Where(result => result.ResultInfo.Type == judgement.Type)) + { + result.ResultCount.Value++; + } + }; + scoreProcessor.JudgementReverted += judgement => + { + foreach (JudgementCounterInfo result in Results.Where(result => result.ResultInfo.Type == judgement.Type)) + { + result.ResultCount.Value--; + } + }; + } + } +} diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index 4c2483a0e6..816b8b2543 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -24,6 +24,7 @@ using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD.ClicksPerSecond; using osu.Game.Skinning; using osuTK; +using JudgementTally = osu.Game.Screens.Play.HUD.JudgementCounter.JudgementTally; namespace osu.Game.Screens.Play { @@ -58,6 +59,9 @@ namespace osu.Game.Screens.Play [Cached] private readonly ClicksPerSecondCalculator clicksPerSecondCalculator; + [Cached] + private readonly JudgementTally tally; + public Bindable ShowHealthBar = new Bindable(true); private readonly DrawableRuleset drawableRuleset; @@ -146,6 +150,7 @@ namespace osu.Game.Screens.Play Spacing = new Vector2(5) }, clicksPerSecondCalculator = new ClicksPerSecondCalculator(), + tally = new JudgementTally() }; hideTargets = new List { mainComponents, KeyCounter, topRightElements };