1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-06 02:23:21 +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.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -27,6 +28,7 @@ namespace osu.Game.Screens.Play.HUD
protected override double RollingDuration => 750; protected override double RollingDuration => 750;
private const float alpha_when_invalid = 0.3f; private const float alpha_when_invalid = 0.3f;
private readonly Bindable<bool> valid = new Bindable<bool>();
private readonly List<double> hitOffsets = new List<double>(); 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) private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
{ {
Colour = colours.BlueLighter; Colour = colours.BlueLighter;
valid.BindValueChanged(e =>
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
} }
private bool isUrInvalid(JudgementResult judgement) private bool isUrInvalid(JudgementResult judgement)
@ -57,16 +61,6 @@ namespace osu.Game.Screens.Play.HUD
scoreProcessor.JudgementReverted += onJudgementReverted; 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) private void onJudgementAdded(JudgementResult judgement)
{ {
if (isUrInvalid(judgement)) return; if (isUrInvalid(judgement)) return;
@ -91,12 +85,12 @@ namespace osu.Game.Screens.Play.HUD
double mean = hitOffsets.Average(); double mean = hitOffsets.Average();
double squares = hitOffsets.Select(offset => Math.Pow(offset - mean, 2)).Sum(); double squares = hitOffsets.Select(offset => Math.Pow(offset - mean, 2)).Sum();
Current.Value = Math.Sqrt(squares / hitOffsets.Count) * 10; Current.Value = Math.Sqrt(squares / hitOffsets.Count) * 10;
setValid(true); valid.Value = true;
} }
else else
{ {
Current.Value = 0; Current.Value = 0;
setValid(false); valid.Value = false;
} }
} }