mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Removed Unnessicary class in the Test file, and optimized UR counter
This commit is contained in:
@ -1,11 +1,16 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
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;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
@ -13,8 +18,10 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Ranking.Statistics;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
@ -28,19 +35,16 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private const float alpha_when_invalid = 0.3f;
|
||||
|
||||
private List<double> hitList = new List<double>();
|
||||
|
||||
[CanBeNull]
|
||||
[Resolved(CanBeNull = true)]
|
||||
private ScoreProcessor scoreProcessor { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
[CanBeNull]
|
||||
private GameplayState gameplayState { get; set; }
|
||||
|
||||
private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource();
|
||||
|
||||
public UnstableRateCounter()
|
||||
{
|
||||
Current.Value = DisplayedCount = 0.0;
|
||||
Current.Value = 0.0;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -55,63 +59,118 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
if (scoreProcessor != null)
|
||||
{
|
||||
scoreProcessor.NewJudgement += onJudgementChanged;
|
||||
scoreProcessor.NewJudgement += onJudgementAdded;
|
||||
scoreProcessor.JudgementReverted += onJudgementChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isValid;
|
||||
|
||||
protected bool IsValid
|
||||
private void setValid(bool valid)
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == isValid)
|
||||
return;
|
||||
|
||||
isValid = value;
|
||||
DrawableCount.FadeTo(isValid ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
|
||||
}
|
||||
isValid = valid;
|
||||
DrawableCount.FadeTo(isValid ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private void onJudgementAdded(JudgementResult judgement)
|
||||
{
|
||||
if (!(judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows) && judgement.IsHit)
|
||||
{
|
||||
hitList.Add(judgement.TimeOffset);
|
||||
}
|
||||
updateUR();
|
||||
}
|
||||
|
||||
// Only populate via the score if the user has moved the current location.
|
||||
private void onJudgementChanged(JudgementResult judgement)
|
||||
{
|
||||
if (gameplayState == null)
|
||||
{
|
||||
isValid = false;
|
||||
return;
|
||||
}
|
||||
ScoreInfo currentScore = new ScoreInfo();
|
||||
scoreProcessor.PopulateScore(currentScore);
|
||||
hitList = currentScore.HitEvents.Where(e => !(e.HitObject.HitWindows is HitWindows.EmptyHitWindows) && e.Result.IsHit())
|
||||
.Select(ev => ev.TimeOffset).ToList<double>();
|
||||
updateUR();
|
||||
}
|
||||
|
||||
double ur = new UnstableRate(gameplayState.Score.ScoreInfo.HitEvents).Value;
|
||||
if (double.IsNaN(ur)) // Error handling: If the user misses the first few notes, the UR is NaN.
|
||||
private void updateUR()
|
||||
{
|
||||
if (hitList.Count > 0)
|
||||
{
|
||||
isValid = false;
|
||||
return;
|
||||
double mean = hitList.Average();
|
||||
double squares = hitList.Select(offset => Math.Pow(offset - mean, 2)).Sum();
|
||||
Current.Value = Math.Sqrt(squares / hitList.Count) * 10;
|
||||
setValid(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
setValid(false);
|
||||
}
|
||||
Current.Value = ur;
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
protected override LocalisableString FormatCount(double count)
|
||||
{
|
||||
return count.ToLocalisableString("0.00 UR");
|
||||
return count.ToString("0.00");
|
||||
}
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText()
|
||||
=> base.CreateSpriteText().With(s =>
|
||||
{
|
||||
s.Font = s.Font.With(size: 12f, fixedWidth: true);
|
||||
s.Alpha = alpha_when_invalid;
|
||||
});
|
||||
protected override IHasText CreateText() => new TextComponent
|
||||
{
|
||||
Alpha = alpha_when_invalid,
|
||||
};
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (scoreProcessor != null)
|
||||
scoreProcessor.NewJudgement -= onJudgementChanged;
|
||||
|
||||
{
|
||||
scoreProcessor.NewJudgement -= onJudgementAdded;
|
||||
scoreProcessor.JudgementReverted -= onJudgementChanged;
|
||||
}
|
||||
loadCancellationSource?.Cancel();
|
||||
}
|
||||
|
||||
private class TextComponent : CompositeDrawable, IHasText
|
||||
{
|
||||
public LocalisableString Text
|
||||
{
|
||||
get => intPart.Text;
|
||||
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]} UR";
|
||||
}
|
||||
}
|
||||
|
||||
private string[] splitValue;
|
||||
private readonly OsuSpriteText intPart;
|
||||
private readonly OsuSpriteText decimalPart;
|
||||
|
||||
public TextComponent()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
//Spacing = new Vector2(2),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
intPart = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
||||
},
|
||||
decimalPart = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Text = @" UR",
|
||||
Font = OsuFont.Numeric.With(size: 8, fixedWidth: true),
|
||||
Padding = new MarginPadding { Bottom = 1.5f },
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user