mirror of https://github.com/ppy/osu
Remove decimal part of UR Counter and rename methods
This commit is contained in:
parent
a8c9ad73c1
commit
d5ad776c33
|
@ -6,7 +6,6 @@
|
|||
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;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
|
@ -21,7 +20,7 @@
|
|||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public class UnstableRateCounter : RollingCounter<double>, ISkinnableDrawable
|
||||
public class UnstableRateCounter : RollingCounter<int>, ISkinnableDrawable
|
||||
{
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
|
@ -37,7 +36,7 @@ public class UnstableRateCounter : RollingCounter<double>, ISkinnableDrawable
|
|||
|
||||
public UnstableRateCounter()
|
||||
{
|
||||
Current.Value = 0.0;
|
||||
Current.Value = 0;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -48,10 +47,8 @@ private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
|||
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
|
||||
}
|
||||
|
||||
private bool isUrInvalid(JudgementResult judgement)
|
||||
{
|
||||
return judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows || !judgement.IsHit;
|
||||
}
|
||||
private bool changesUnstableRate(JudgementResult judgement)
|
||||
=> !(judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows) && judgement.IsHit;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
|
@ -63,28 +60,28 @@ protected override void LoadComplete()
|
|||
|
||||
private void onJudgementAdded(JudgementResult judgement)
|
||||
{
|
||||
if (isUrInvalid(judgement)) return;
|
||||
if (!changesUnstableRate(judgement)) return;
|
||||
|
||||
hitOffsets.Add(judgement.TimeOffset);
|
||||
updateUr();
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
private void onJudgementReverted(JudgementResult judgement)
|
||||
{
|
||||
if (judgement.FailedAtJudgement || isUrInvalid(judgement)) return;
|
||||
if (judgement.FailedAtJudgement || !changesUnstableRate(judgement)) return;
|
||||
|
||||
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.
|
||||
if (hitOffsets.Count > 0)
|
||||
{
|
||||
double mean = hitOffsets.Average();
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
@ -94,11 +91,6 @@ private void updateUr()
|
|||
}
|
||||
}
|
||||
|
||||
protected override LocalisableString FormatCount(double count)
|
||||
{
|
||||
return count.ToString("0.00");
|
||||
}
|
||||
|
||||
protected override IHasText CreateText() => new TextComponent
|
||||
{
|
||||
Alpha = alpha_when_invalid,
|
||||
|
@ -108,6 +100,8 @@ protected override void Dispose(bool isDisposing)
|
|||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (scoreProcessor == null) return;
|
||||
|
||||
scoreProcessor.NewJudgement -= onJudgementAdded;
|
||||
scoreProcessor.JudgementReverted -= onJudgementReverted;
|
||||
}
|
||||
|
@ -116,20 +110,11 @@ private class TextComponent : CompositeDrawable, IHasText
|
|||
{
|
||||
public LocalisableString Text
|
||||
{
|
||||
get => fullValue.ToLocalisableString("0.00 UR");
|
||||
set
|
||||
{
|
||||
fullValue = Convert.ToDouble(value.ToString());
|
||||
intPart.Text = fullValue.ToLocalisableString("0");
|
||||
decimalPart.Text = (fullValue - Math.Truncate(fullValue))
|
||||
.ToLocalisableString(".00 UR");
|
||||
}
|
||||
get => text.Text;
|
||||
set => text.Text = value;
|
||||
}
|
||||
|
||||
private double fullValue;
|
||||
|
||||
private readonly OsuSpriteText intPart;
|
||||
private readonly OsuSpriteText decimalPart;
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
public TextComponent()
|
||||
{
|
||||
|
@ -140,17 +125,18 @@ public TextComponent()
|
|||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
intPart = new OsuSpriteText
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
||||
},
|
||||
decimalPart = new OsuSpriteText
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Font = OsuFont.Numeric.With(size: 8, fixedWidth: true),
|
||||
Text = "UR",
|
||||
Padding = new MarginPadding { Bottom = 1.5f },
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue