Make UR Counter isValid into a bindable boolean

This commit is contained in:
Chinmay Patil 2021-11-07 18:06:13 -07:00
parent cc0bcf6b2c
commit a8c9ad73c1
1 changed files with 6 additions and 12 deletions

View File

@ -5,6 +5,7 @@
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 @@ public class UnstableRateCounter : RollingCounter<double>, ISkinnableDrawable
protected override double RollingDuration => 750;
private const float alpha_when_invalid = 0.3f;
private readonly Bindable<bool> valid = new Bindable<bool>();
private readonly List<double> hitOffsets = new List<double>();
@ -42,6 +44,8 @@ public UnstableRateCounter()
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 @@ protected override void LoadComplete()
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 @@ private void updateUr()
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;
}
}