2021-11-04 04:22:44 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-11-11 12:21:56 +00:00
|
|
|
using System;
|
2021-11-04 04:22:44 +00:00
|
|
|
using osu.Framework.Allocation;
|
2021-11-08 01:06:13 +00:00
|
|
|
using osu.Framework.Bindables;
|
2021-11-04 04:22:44 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-11-04 20:27:48 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-11-04 04:22:44 +00:00
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Skinning;
|
2021-11-12 04:59:22 +00:00
|
|
|
using osuTK;
|
2021-11-04 04:22:44 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
2021-11-08 13:27:25 +00:00
|
|
|
public class UnstableRateCounter : RollingCounter<int>, ISkinnableDrawable
|
2021-11-04 04:22:44 +00:00
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
|
|
|
protected override double RollingDuration => 750;
|
|
|
|
|
|
|
|
private const float alpha_when_invalid = 0.3f;
|
2021-11-08 01:06:13 +00:00
|
|
|
private readonly Bindable<bool> valid = new Bindable<bool>();
|
2021-11-04 04:22:44 +00:00
|
|
|
|
2021-11-08 00:44:50 +00:00
|
|
|
[Resolved]
|
2021-11-04 04:22:44 +00:00
|
|
|
private ScoreProcessor scoreProcessor { get; set; }
|
|
|
|
|
|
|
|
public UnstableRateCounter()
|
|
|
|
{
|
2021-11-08 13:27:25 +00:00
|
|
|
Current.Value = 0;
|
2021-11-04 04:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 00:06:39 +00:00
|
|
|
private void load(OsuColour colours)
|
2021-11-04 04:22:44 +00:00
|
|
|
{
|
|
|
|
Colour = colours.BlueLighter;
|
2021-11-08 01:06:13 +00:00
|
|
|
valid.BindValueChanged(e =>
|
|
|
|
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
|
2021-11-04 04:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 13:27:25 +00:00
|
|
|
private bool changesUnstableRate(JudgementResult judgement)
|
|
|
|
=> !(judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows) && judgement.IsHit;
|
2021-11-08 00:44:50 +00:00
|
|
|
|
2021-11-04 04:22:44 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-11-11 12:09:48 +00:00
|
|
|
scoreProcessor.NewJudgement += updateDisplay;
|
|
|
|
scoreProcessor.JudgementReverted += updateDisplay;
|
2021-11-08 13:27:25 +00:00
|
|
|
updateDisplay();
|
2021-11-04 04:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 12:09:48 +00:00
|
|
|
private void updateDisplay(JudgementResult _) => Scheduler.AddOnce(updateDisplay);
|
2021-11-04 20:27:48 +00:00
|
|
|
|
2021-11-08 13:27:25 +00:00
|
|
|
private void updateDisplay()
|
2021-11-04 20:27:48 +00:00
|
|
|
{
|
2021-11-11 12:09:48 +00:00
|
|
|
double? unstableRate = scoreProcessor.HitEvents.CalculateUnstableRate();
|
|
|
|
|
|
|
|
valid.Value = unstableRate != null;
|
|
|
|
if (unstableRate != null)
|
2021-11-11 12:21:56 +00:00
|
|
|
Current.Value = (int)Math.Round(unstableRate.Value);
|
2021-11-04 04:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 20:27:48 +00:00
|
|
|
protected override IHasText CreateText() => new TextComponent
|
|
|
|
{
|
|
|
|
Alpha = alpha_when_invalid,
|
|
|
|
};
|
2021-11-04 04:22:44 +00:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2021-11-08 13:27:25 +00:00
|
|
|
if (scoreProcessor == null) return;
|
|
|
|
|
2021-11-11 12:09:48 +00:00
|
|
|
scoreProcessor.NewJudgement -= updateDisplay;
|
|
|
|
scoreProcessor.JudgementReverted -= updateDisplay;
|
2021-11-04 04:22:44 +00:00
|
|
|
}
|
2021-11-04 20:27:48 +00:00
|
|
|
|
|
|
|
private class TextComponent : CompositeDrawable, IHasText
|
|
|
|
{
|
|
|
|
public LocalisableString Text
|
|
|
|
{
|
2021-11-08 13:27:25 +00:00
|
|
|
get => text.Text;
|
|
|
|
set => text.Text = value;
|
2021-11-04 20:27:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 13:27:25 +00:00
|
|
|
private readonly OsuSpriteText text;
|
2021-11-04 20:27:48 +00:00
|
|
|
|
|
|
|
public TextComponent()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2021-11-12 04:59:22 +00:00
|
|
|
Spacing = new Vector2(2),
|
2021-11-04 20:27:48 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-11-08 13:27:25 +00:00
|
|
|
text = new OsuSpriteText
|
2021-11-04 20:27:48 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
|
|
|
},
|
2021-11-08 13:27:25 +00:00
|
|
|
new OsuSpriteText
|
2021-11-04 20:27:48 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Font = OsuFont.Numeric.With(size: 8, fixedWidth: true),
|
2021-11-12 04:59:22 +00:00
|
|
|
Text = @"UR",
|
|
|
|
Padding = new MarginPadding { Bottom = 1.5f }, // align baseline better
|
2021-11-04 20:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 04:22:44 +00:00
|
|
|
}
|
|
|
|
}
|