1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-21 07:33:12 +08:00

Code cleanup for CPS counter

This commit is contained in:
Ryuki 2022-08-21 03:15:30 +02:00
parent 3ac6500423
commit 5cf54a788a
No known key found for this signature in database
GPG Key ID: A353889EAEACBF49

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -19,9 +18,8 @@ namespace osu.Game.Screens.Play.HUD.ClicksPerSecond
{ {
private const float alpha_when_invalid = 0.3f; private const float alpha_when_invalid = 0.3f;
private readonly Bindable<bool> valid = new Bindable<bool>(); [Resolved(canBeNull: false)]
private ClicksPerSecondCalculator calculator { get; set; } = null!;
private ClicksPerSecondCalculator? calculator;
protected override double RollingDuration => 350; protected override double RollingDuration => 350;
@ -33,26 +31,19 @@ namespace osu.Game.Screens.Play.HUD.ClicksPerSecond
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, ClicksPerSecondCalculator calculator) private void load(OsuColour colours)
{ {
this.calculator = calculator;
Colour = colours.BlueLighter; Colour = colours.BlueLighter;
valid.BindValueChanged(e =>
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
} }
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
valid.Value = calculator != null && calculator.Ready; Current.Value = calculator.Ready ? calculator.Value : 0;
Current.Value = calculator != null ? calculator.Ready ? calculator.Value : 0 : 0;
} }
protected override IHasText CreateText() => new TextComponent protected override IHasText CreateText() => new TextComponent();
{
Alpha = alpha_when_invalid
};
private class TextComponent : CompositeDrawable, IHasText private class TextComponent : CompositeDrawable, IHasText
{ {