2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2021-11-04 12:22:44 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2021-11-11 20:21:56 +08:00
|
|
|
|
using System;
|
2021-11-04 12:22:44 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-11-08 09:06:13 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2023-06-23 23:59:36 +08:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2021-11-04 12:22:44 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-11-05 04:27:48 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-11-04 12:22:44 +08: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 12:59:22 +08:00
|
|
|
|
using osuTK;
|
2021-11-04 12:22:44 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
2023-02-15 15:01:26 +08:00
|
|
|
|
public partial class UnstableRateCounter : RollingCounter<int>, ISerialisableDrawable
|
2021-11-04 12:22:44 +08:00
|
|
|
|
{
|
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
|
2024-01-17 17:18:53 +08:00
|
|
|
|
protected override double RollingDuration => 375;
|
2021-11-04 12:22:44 +08:00
|
|
|
|
|
|
|
|
|
private const float alpha_when_invalid = 0.3f;
|
2021-11-08 09:06:13 +08:00
|
|
|
|
private readonly Bindable<bool> valid = new Bindable<bool>();
|
2021-11-04 12:22:44 +08:00
|
|
|
|
|
2021-11-08 08:44:50 +08:00
|
|
|
|
[Resolved]
|
2023-06-23 00:37:25 +08:00
|
|
|
|
private ScoreProcessor scoreProcessor { get; set; } = null!;
|
2021-11-04 12:22:44 +08:00
|
|
|
|
|
|
|
|
|
public UnstableRateCounter()
|
|
|
|
|
{
|
2021-11-08 21:27:25 +08:00
|
|
|
|
Current.Value = 0;
|
2021-11-04 12:22:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 08:06:39 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2021-11-04 12:22:44 +08:00
|
|
|
|
{
|
|
|
|
|
Colour = colours.BlueLighter;
|
2021-11-08 09:06:13 +08:00
|
|
|
|
valid.BindValueChanged(e =>
|
|
|
|
|
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
|
2021-11-04 12:22:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 21:27:25 +08:00
|
|
|
|
private bool changesUnstableRate(JudgementResult judgement)
|
|
|
|
|
=> !(judgement.HitObject.HitWindows is HitWindows.EmptyHitWindows) && judgement.IsHit;
|
2021-11-08 08:44:50 +08:00
|
|
|
|
|
2021-11-04 12:22:44 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2021-11-11 20:09:48 +08:00
|
|
|
|
scoreProcessor.NewJudgement += updateDisplay;
|
|
|
|
|
scoreProcessor.JudgementReverted += updateDisplay;
|
2021-11-08 21:27:25 +08:00
|
|
|
|
updateDisplay();
|
2021-11-04 12:22:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 20:09:48 +08:00
|
|
|
|
private void updateDisplay(JudgementResult _) => Scheduler.AddOnce(updateDisplay);
|
2021-11-05 04:27:48 +08:00
|
|
|
|
|
2021-11-08 21:27:25 +08:00
|
|
|
|
private void updateDisplay()
|
2021-11-05 04:27:48 +08:00
|
|
|
|
{
|
2021-11-11 20:09:48 +08:00
|
|
|
|
double? unstableRate = scoreProcessor.HitEvents.CalculateUnstableRate();
|
|
|
|
|
|
|
|
|
|
valid.Value = unstableRate != null;
|
|
|
|
|
if (unstableRate != null)
|
2021-11-11 20:21:56 +08:00
|
|
|
|
Current.Value = (int)Math.Round(unstableRate.Value);
|
2021-11-04 12:22:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 04:27:48 +08:00
|
|
|
|
protected override IHasText CreateText() => new TextComponent
|
|
|
|
|
{
|
|
|
|
|
Alpha = alpha_when_invalid,
|
|
|
|
|
};
|
2021-11-04 12:22:44 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2023-06-23 23:59:36 +08:00
|
|
|
|
if (scoreProcessor.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
scoreProcessor.NewJudgement -= updateDisplay;
|
|
|
|
|
scoreProcessor.JudgementReverted -= updateDisplay;
|
|
|
|
|
}
|
2021-11-04 12:22:44 +08:00
|
|
|
|
}
|
2021-11-05 04:27:48 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class TextComponent : CompositeDrawable, IHasText
|
2021-11-05 04:27:48 +08:00
|
|
|
|
{
|
|
|
|
|
public LocalisableString Text
|
|
|
|
|
{
|
2021-11-08 21:27:25 +08:00
|
|
|
|
get => text.Text;
|
|
|
|
|
set => text.Text = value;
|
2021-11-05 04:27:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 21:27:25 +08:00
|
|
|
|
private readonly OsuSpriteText text;
|
2021-11-05 04:27:48 +08:00
|
|
|
|
|
|
|
|
|
public TextComponent()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2021-11-12 12:59:22 +08:00
|
|
|
|
Spacing = new Vector2(2),
|
2021-11-05 04:27:48 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-11-08 21:27:25 +08:00
|
|
|
|
text = new OsuSpriteText
|
2021-11-05 04:27:48 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
|
|
|
|
},
|
2021-11-08 21:27:25 +08:00
|
|
|
|
new OsuSpriteText
|
2021-11-05 04:27:48 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Font = OsuFont.Numeric.With(size: 8, fixedWidth: true),
|
2021-11-12 12:59:22 +08:00
|
|
|
|
Text = @"UR",
|
|
|
|
|
Padding = new MarginPadding { Bottom = 1.5f }, // align baseline better
|
2021-11-05 04:27:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-04 12:22:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|