1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-21 06:42:54 +08:00

Remove decimal part of UR Counter and rename methods

This commit is contained in:
Chinmay Patil 2021-11-08 06:27:25 -07:00
parent a8c9ad73c1
commit d5ad776c33

View File

@ -6,7 +6,6 @@ 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.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
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;
@ -21,7 +20,7 @@ using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD namespace osu.Game.Screens.Play.HUD
{ {
public class UnstableRateCounter : RollingCounter<double>, ISkinnableDrawable public class UnstableRateCounter : RollingCounter<int>, ISkinnableDrawable
{ {
public bool UsesFixedAnchor { get; set; } public bool UsesFixedAnchor { get; set; }
@ -37,7 +36,7 @@ namespace osu.Game.Screens.Play.HUD
public UnstableRateCounter() public UnstableRateCounter()
{ {
Current.Value = 0.0; Current.Value = 0;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -48,10 +47,8 @@ namespace osu.Game.Screens.Play.HUD
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint)); DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
} }
private bool isUrInvalid(JudgementResult judgement) private bool changesUnstableRate(JudgementResult judgement)
{ => !(judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows) && judgement.IsHit;
return judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows || !judgement.IsHit;
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
@ -63,28 +60,28 @@ namespace osu.Game.Screens.Play.HUD
private void onJudgementAdded(JudgementResult judgement) private void onJudgementAdded(JudgementResult judgement)
{ {
if (isUrInvalid(judgement)) return; if (!changesUnstableRate(judgement)) return;
hitOffsets.Add(judgement.TimeOffset); hitOffsets.Add(judgement.TimeOffset);
updateUr(); updateDisplay();
} }
private void onJudgementReverted(JudgementResult judgement) private void onJudgementReverted(JudgementResult judgement)
{ {
if (judgement.FailedAtJudgement || isUrInvalid(judgement)) return; if (judgement.FailedAtJudgement || !changesUnstableRate(judgement)) return;
hitOffsets.RemoveAt(hitOffsets.Count - 1); hitOffsets.RemoveAt(hitOffsets.Count - 1);
updateUr(); updateDisplay();
} }
private void updateUr() private void updateDisplay()
{ {
// At Count = 0, we get NaN, While we are allowing count = 1, it will be 0 since average = offset. // At Count = 0, we get NaN, While we are allowing count = 1, it will be 0 since average = offset.
if (hitOffsets.Count > 0) if (hitOffsets.Count > 0)
{ {
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 = (int)(Math.Sqrt(squares / hitOffsets.Count) * 10);
valid.Value = true; valid.Value = true;
} }
else else
@ -94,11 +91,6 @@ namespace osu.Game.Screens.Play.HUD
} }
} }
protected override LocalisableString FormatCount(double count)
{
return count.ToString("0.00");
}
protected override IHasText CreateText() => new TextComponent protected override IHasText CreateText() => new TextComponent
{ {
Alpha = alpha_when_invalid, Alpha = alpha_when_invalid,
@ -108,6 +100,8 @@ namespace osu.Game.Screens.Play.HUD
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (scoreProcessor == null) return;
scoreProcessor.NewJudgement -= onJudgementAdded; scoreProcessor.NewJudgement -= onJudgementAdded;
scoreProcessor.JudgementReverted -= onJudgementReverted; scoreProcessor.JudgementReverted -= onJudgementReverted;
} }
@ -116,20 +110,11 @@ namespace osu.Game.Screens.Play.HUD
{ {
public LocalisableString Text public LocalisableString Text
{ {
get => fullValue.ToLocalisableString("0.00 UR"); get => text.Text;
set set => text.Text = value;
{
fullValue = Convert.ToDouble(value.ToString());
intPart.Text = fullValue.ToLocalisableString("0");
decimalPart.Text = (fullValue - Math.Truncate(fullValue))
.ToLocalisableString(".00 UR");
}
} }
private double fullValue; private readonly OsuSpriteText text;
private readonly OsuSpriteText intPart;
private readonly OsuSpriteText decimalPart;
public TextComponent() public TextComponent()
{ {
@ -140,17 +125,18 @@ namespace osu.Game.Screens.Play.HUD
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
intPart = new OsuSpriteText text = new OsuSpriteText
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true) Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
}, },
decimalPart = new OsuSpriteText new OsuSpriteText
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 8, fixedWidth: true), Font = OsuFont.Numeric.With(size: 8, fixedWidth: true),
Text = "UR",
Padding = new MarginPadding { Bottom = 1.5f }, Padding = new MarginPadding { Bottom = 1.5f },
} }
} }