Clean up judgement checks and clean up setter/getter for UR counter Text

This commit is contained in:
Chinmay Patil 2021-11-07 17:44:50 -07:00
parent 77e853ce25
commit cc0bcf6b2c
1 changed files with 18 additions and 34 deletions

View File

@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -30,9 +30,7 @@ public class UnstableRateCounter : RollingCounter<double>, ISkinnableDrawable
private readonly List<double> hitOffsets = new List<double>();
//May be able to remove the CanBeNull as ScoreProcessor should exist everywhere, for example, in the skin editor it is cached.
[CanBeNull]
[Resolved(CanBeNull = true)]
[Resolved]
private ScoreProcessor scoreProcessor { get; set; }
public UnstableRateCounter()
@ -46,12 +44,15 @@ private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
Colour = colours.BlueLighter;
}
private bool isUrInvalid(JudgementResult judgement)
{
return judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows || !judgement.IsHit;
}
protected override void LoadComplete()
{
base.LoadComplete();
if (scoreProcessor == null) return;
scoreProcessor.NewJudgement += onJudgementAdded;
scoreProcessor.JudgementReverted += onJudgementReverted;
}
@ -68,23 +69,15 @@ private void setValid(bool valid)
private void onJudgementAdded(JudgementResult judgement)
{
if (!(judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows) && judgement.IsHit)
{
hitOffsets.Add(judgement.TimeOffset);
}
if (isUrInvalid(judgement)) return;
hitOffsets.Add(judgement.TimeOffset);
updateUr();
}
// If a judgement was reverted successfully, remove the item from the hitOffsets list.
private void onJudgementReverted(JudgementResult judgement)
{
//Score Processor Conditions to revert
if (judgement.FailedAtJudgement || !judgement.Type.IsScorable())
return;
//UR Conditions to Revert
if (judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows || !judgement.IsHit)
return;
if (judgement.FailedAtJudgement || isUrInvalid(judgement)) return;
hitOffsets.RemoveAt(hitOffsets.Count - 1);
updateUr();
@ -109,7 +102,7 @@ private void updateUr()
protected override LocalisableString FormatCount(double count)
{
return count.ToString("0.00 UR");
return count.ToString("0.00");
}
protected override IHasText CreateText() => new TextComponent
@ -121,8 +114,6 @@ protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (scoreProcessor == null) return;
scoreProcessor.NewJudgement -= onJudgementAdded;
scoreProcessor.JudgementReverted -= onJudgementReverted;
}
@ -131,17 +122,18 @@ private class TextComponent : CompositeDrawable, IHasText
{
public LocalisableString Text
{
get => intPart.Text;
get => fullValue.ToLocalisableString("0.00 UR");
set
{
//Not too sure about this, is there a better way to go about doing this?
splitValue = value.ToString().Split('.');
intPart.Text = splitValue[0];
decimalPart.Text = splitValue[1];
fullValue = Convert.ToDouble(value.ToString());
intPart.Text = fullValue.ToLocalisableString("0");
decimalPart.Text = (fullValue - Math.Truncate(fullValue))
.ToLocalisableString(".00 UR");
}
}
private string[] splitValue;
private double fullValue;
private readonly OsuSpriteText intPart;
private readonly OsuSpriteText decimalPart;
@ -160,14 +152,6 @@ public TextComponent()
Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
},
new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric.With(size: 8, fixedWidth: true),
Text = ".",
Padding = new MarginPadding { Bottom = 1.5f },
},
decimalPart = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,