1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

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

View File

@ -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<bool> valid = new Bindable<bool>();
private readonly List<double> hitOffsets = new List<double>();
@ -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;
}
}