From a8c9ad73c1bc1bcf9da155b5a14b09c5146803fe Mon Sep 17 00:00:00 2001 From: Chinmay Patil Date: Sun, 7 Nov 2021 18:06:13 -0700 Subject: [PATCH] Make UR Counter isValid into a bindable boolean --- .../Screens/Play/HUD/UnstableRateCounter.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/UnstableRateCounter.cs b/osu.Game/Screens/Play/HUD/UnstableRateCounter.cs index a9d6066e09..f7263b29e9 100644 --- a/osu.Game/Screens/Play/HUD/UnstableRateCounter.cs +++ b/osu.Game/Screens/Play/HUD/UnstableRateCounter.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -27,6 +28,7 @@ namespace osu.Game.Screens.Play.HUD protected override double RollingDuration => 750; private const float alpha_when_invalid = 0.3f; + private readonly Bindable valid = new Bindable(); private readonly List hitOffsets = new List(); @@ -42,6 +44,8 @@ namespace osu.Game.Screens.Play.HUD private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache) { Colour = colours.BlueLighter; + valid.BindValueChanged(e => + DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint)); } private bool isUrInvalid(JudgementResult judgement) @@ -57,16 +61,6 @@ namespace osu.Game.Screens.Play.HUD scoreProcessor.JudgementReverted += onJudgementReverted; } - private bool isValid; - - private void setValid(bool valid) - { - if (isValid == valid) return; - - DrawableCount.FadeTo(valid ? 1 : alpha_when_invalid, 1000, Easing.OutQuint); - isValid = valid; - } - private void onJudgementAdded(JudgementResult judgement) { if (isUrInvalid(judgement)) return; @@ -91,12 +85,12 @@ namespace osu.Game.Screens.Play.HUD double mean = hitOffsets.Average(); double squares = hitOffsets.Select(offset => Math.Pow(offset - mean, 2)).Sum(); Current.Value = Math.Sqrt(squares / hitOffsets.Count) * 10; - setValid(true); + valid.Value = true; } else { Current.Value = 0; - setValid(false); + valid.Value = false; } }