1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-22 10:30:00 +08:00

convert UnstableRateCounter to an abstract class and move triangles implementation to its own component

This commit is contained in:
Hivie
2025-08-09 22:33:07 +01:00
Unverified
parent 44d2dc93b1
commit 5616be09a0
2 changed files with 89 additions and 66 deletions
@@ -3,31 +3,18 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
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;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
public partial class UnstableRateCounter : RollingCounter<int>, ISerialisableDrawable
public abstract partial class UnstableRateCounter : RollingCounter<int>
{
public bool UsesFixedAnchor { get; set; }
protected override double RollingDuration => 375;
private const float alpha_when_invalid = 0.3f;
private readonly Bindable<bool> valid = new Bindable<bool>();
private HitEventExtensions.UnstableRateCalculationResult? unstableRateResult;
[Resolved]
@@ -38,13 +25,7 @@ namespace osu.Game.Screens.Play.HUD
Current.Value = 0;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.BlueLighter;
valid.BindValueChanged(e =>
DrawableCount.FadeTo(e.NewValue ? 1 : alpha_when_invalid, 1000, Easing.OutQuint));
}
public virtual bool IsValid { get; set; }
protected override void LoadComplete()
{
@@ -67,65 +48,22 @@ namespace osu.Game.Screens.Play.HUD
double? unstableRate = unstableRateResult?.Result;
valid.Value = unstableRate != null;
IsValid = unstableRate != null;
if (unstableRate != null)
Current.Value = (int)Math.Round(unstableRate.Value);
}
protected override IHasText CreateText() => new TextComponent
{
Alpha = alpha_when_invalid,
};
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (scoreProcessor.IsNotNull())
if (scoreProcessor != null)
{
scoreProcessor.NewJudgement -= updateDisplay;
scoreProcessor.JudgementReverted -= updateDisplay;
}
}
private partial class TextComponent : CompositeDrawable, IHasText
{
public LocalisableString Text
{
get => text.Text;
set => text.Text = value;
}
private readonly OsuSpriteText text;
public TextComponent()
{
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(2),
Children = new Drawable[]
{
text = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
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 = @"UR",
Padding = new MarginPadding { Bottom = 1.5f }, // align baseline better
}
}
};
}
}
}
}
@@ -0,0 +1,85 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Skinning.Triangles
{
public partial class TrianglesUnstableRateCounter : UnstableRateCounter, ISerialisableDrawable
{
private const float alpha_when_invalid = 0.3f;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.BlueLighter;
}
public override bool IsValid
{
get => base.IsValid;
set
{
if (value == IsValid)
return;
base.IsValid = value;
DrawableCount.FadeTo(value ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
}
}
protected override LocalisableString FormatCount(int count) => count.ToString(@"D");
protected override IHasText CreateText() => new TextComponent
{
Alpha = alpha_when_invalid
};
private partial class TextComponent : CompositeDrawable, IHasText
{
public LocalisableString Text
{
get => text.Text;
set => text.Text = value;
}
private readonly OsuSpriteText text;
public TextComponent()
{
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(2),
Children = new Drawable[]
{
text = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
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 = @"UR",
Padding = new MarginPadding { Bottom = 1.5f },
}
}
};
}
}
}
}