diff --git a/osu.Game/Graphics/UserInterface/PercentageCounter.cs b/osu.Game/Graphics/UserInterface/PercentageCounter.cs index b51dd2287b..4065978de8 100644 --- a/osu.Game/Graphics/UserInterface/PercentageCounter.cs +++ b/osu.Game/Graphics/UserInterface/PercentageCounter.cs @@ -13,8 +13,6 @@ namespace osu.Game.Graphics.UserInterface /// public class PercentageCounter : RollingCounter { - protected override Type TransformType => typeof(TransformAccuracy); - protected override double RollingDuration => 750; private float epsilon => 1e-10f; @@ -44,23 +42,5 @@ namespace osu.Game.Graphics.UserInterface { Current.Value = Current + amount; } - - protected class TransformAccuracy : Transform - { - public virtual double CurrentValue - { - get - { - double time = Time?.Current ?? 0; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return Interpolation.ValueAt(time, (float)StartValue, (float)EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) => ((PercentageCounter)d).DisplayedCount = CurrentValue; - public override void ReadIntoStartValue(Drawable d) => StartValue = ((PercentageCounter)d).DisplayedCount; - } } } diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 2afa4da058..ac4e877ae1 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using OpenTK.Graphics; +using osu.Framework.MathUtils; namespace osu.Game.Graphics.UserInterface { @@ -22,14 +23,6 @@ namespace osu.Game.Graphics.UserInterface /// public Bindable Current = new Bindable(); - /// - /// Type of the Transform to use. - /// - /// - /// Must be a subclass of Transform(T) - /// - protected virtual Type TransformType => typeof(Transform); - protected SpriteText DisplayedCountSpriteText; /// @@ -59,7 +52,8 @@ namespace osu.Game.Graphics.UserInterface { return displayedCount; } - protected set + + set { if (EqualityComparer.Default.Equals(displayedCount, value)) return; @@ -134,7 +128,7 @@ namespace osu.Game.Graphics.UserInterface /// public virtual void StopRolling() { - Flush(false, TransformType); + Flush(false, typeof(TransformRollingCounter)); DisplayedCount = Current; } @@ -181,25 +175,43 @@ namespace osu.Game.Graphics.UserInterface /// protected virtual void TransformCount(T currentValue, T newValue) { - Debug.Assert( - typeof(Transform).IsAssignableFrom(TransformType), - @"transformType should be a subclass of Transform." - ); - - TransformCount((Transform)Activator.CreateInstance(TransformType), currentValue, newValue); + TransformCount(new TransformRollingCounter(this), currentValue, newValue); } /// /// Intended to be used by TransformCount(T currentValue, T newValue). /// - protected void TransformCount(Transform transform, T currentValue, T newValue) + protected void TransformCount(TransformRollingCounter transform, T currentValue, T newValue) { double rollingTotalDuration = IsRollingProportional ? GetProportionalDuration(currentValue, newValue) : RollingDuration; - TransformTo(newValue, rollingTotalDuration, RollingEasing, transform); + this.TransformTo(newValue, rollingTotalDuration, RollingEasing, transform); + } + + protected class TransformRollingCounter : Transform> + { + public TransformRollingCounter(RollingCounter target) : base(target) + { + } + + public T CurrentValue + { + get + { + double time = Time?.Current ?? 0; + if (time < StartTime) return StartValue; + if (time >= EndTime) return EndValue; + + double result = Interpolation.ValueAt(time, Convert.ToDouble(StartValue), Convert.ToDouble(EndValue), StartTime, EndTime, Easing); + return (T)Convert.ChangeType(result, typeof(T), null); + } + } + + public override void Apply(RollingCounter d) => d.DisplayedCount = CurrentValue; + public override void ReadIntoStartValue(RollingCounter d) => StartValue = d.DisplayedCount; } } } diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index 6fe43e1fcc..604185d930 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -10,8 +10,6 @@ namespace osu.Game.Graphics.UserInterface { public class ScoreCounter : RollingCounter { - protected override Type TransformType => typeof(TransformScore); - protected override double RollingDuration => 1000; protected override EasingTypes RollingEasing => EasingTypes.Out; @@ -55,23 +53,5 @@ namespace osu.Game.Graphics.UserInterface { Current.Value = Current + amount; } - - protected class TransformScore : Transform - { - public virtual double CurrentValue - { - get - { - double time = Time?.Current ?? 0; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return Interpolation.ValueAt(time, (float)StartValue, (float)EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) => ((ScoreCounter)d).DisplayedCount = CurrentValue; - public override void ReadIntoStartValue(Drawable d) => StartValue = ((ScoreCounter)d).DisplayedCount; - } } } diff --git a/osu.Game/Graphics/UserInterface/SimpleComboCounter.cs b/osu.Game/Graphics/UserInterface/SimpleComboCounter.cs index 7664eeee40..16ba8c6d76 100644 --- a/osu.Game/Graphics/UserInterface/SimpleComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/SimpleComboCounter.cs @@ -13,8 +13,6 @@ namespace osu.Game.Graphics.UserInterface /// public class SimpleComboCounter : RollingCounter { - protected override Type TransformType => typeof(TransformCounterCount); - protected override double RollingDuration => 750; public SimpleComboCounter() @@ -36,23 +34,5 @@ namespace osu.Game.Graphics.UserInterface { Current.Value = Current + amount; } - - private class TransformCounterCount : Transform - { - public int CurrentValue - { - get - { - double time = Time?.Current ?? 0; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return (int)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) => ((SimpleComboCounter)d).DisplayedCount = CurrentValue; - public override void ReadIntoStartValue(Drawable d) => StartValue = ((SimpleComboCounter)d).DisplayedCount; - } } } \ No newline at end of file diff --git a/osu.Game/Screens/Play/HUD/ComboResultCounter.cs b/osu.Game/Screens/Play/HUD/ComboResultCounter.cs index c280702390..e658658306 100644 --- a/osu.Game/Screens/Play/HUD/ComboResultCounter.cs +++ b/osu.Game/Screens/Play/HUD/ComboResultCounter.cs @@ -12,44 +12,24 @@ namespace osu.Game.Screens.Play.HUD /// /// Used to display combo with a roll-up animation in results screen. /// - public class ComboResultCounter : RollingCounter + public class ComboResultCounter : RollingCounter { - protected override Type TransformType => typeof(TransformComboResult); - protected override double RollingDuration => 500; protected override EasingTypes RollingEasing => EasingTypes.Out; - protected override double GetProportionalDuration(ulong currentValue, ulong newValue) + protected override double GetProportionalDuration(long currentValue, long newValue) { return currentValue > newValue ? currentValue - newValue : newValue - currentValue; } - protected override string FormatCount(ulong count) + protected override string FormatCount(long count) { return $@"{count}x"; } - public override void Increment(ulong amount) + public override void Increment(long amount) { Current.Value = Current + amount; } - - protected class TransformComboResult : Transform - { - public virtual ulong CurrentValue - { - get - { - double time = Time?.Current ?? 0; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) => ((ComboResultCounter)d).DisplayedCount = CurrentValue; - public override void ReadIntoStartValue(Drawable d) => StartValue = ((ComboResultCounter)d).DisplayedCount; - } } }