diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index d7ce54ad46..0fac933dc0 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -93,23 +93,24 @@ namespace osu.Desktop.Tests }; Add(accuracyCombo); - SpriteText starsLabel = new SpriteText - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 190), - Text = @"- unset -", - }; - Add(starsLabel); - StarCounter stars = new StarCounter { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Position = new Vector2(20, 160), + Count = 5, }; Add(stars); + SpriteText starsLabel = new SpriteText + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Position = new Vector2(20, 190), + Text = stars.Count.ToString("0.00"), + }; + Add(starsLabel); + AddButton(@"Reset all", delegate { score.Count = 0; diff --git a/osu.Game/GameModes/Play/ComboCounter.cs b/osu.Game/GameModes/Play/ComboCounter.cs index f0ab9107c8..cd3dac77aa 100644 --- a/osu.Game/GameModes/Play/ComboCounter.cs +++ b/osu.Game/GameModes/Play/ComboCounter.cs @@ -26,7 +26,7 @@ namespace osu.Game.GameModes.Play protected SpriteText PopOutSpriteText; - protected virtual ulong PopOutDuration => 150; + protected virtual double PopOutDuration => 150; protected virtual float PopOutScale => 2.0f; protected virtual EasingTypes PopOutEasing => EasingTypes.None; protected virtual float PopOutInitialAlpha => 0.75f; @@ -41,7 +41,6 @@ namespace osu.Game.GameModes.Play /// protected EasingTypes RollingEasing => EasingTypes.None; - private ulong prevDisplayedCount; private ulong displayedCount; /// @@ -102,8 +101,6 @@ namespace osu.Game.GameModes.Play { DisplayedCountSpriteText = new SpriteText { - Anchor = this.Anchor, - Origin = this.Origin, Alpha = 0, }, PopOutSpriteText = new SpriteText @@ -132,11 +129,19 @@ namespace osu.Game.GameModes.Play updateCount(Count); } + /// + /// Animates roll-back to 0. + /// + public void Roll() + { + Roll(0); + } + /// /// Animates roll-up/roll-back to an specific value. /// /// Target value. - public virtual void Roll(ulong newValue = 0) + public virtual void Roll(ulong newValue) { updateCount(newValue, true); } @@ -173,13 +178,12 @@ namespace osu.Game.GameModes.Play private double getProportionalDuration(ulong currentValue, ulong newValue) { - double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue; return difference * RollingDuration; } private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling) { - prevDisplayedCount = currentValue; displayedCount = newValue; if (rolling) OnDisplayedCountRolling(currentValue, newValue); @@ -218,7 +222,7 @@ namespace osu.Game.GameModes.Play if (Clock == null) return; - if (RollingDuration == 0) + if (RollingDuration < 1) { DisplayedCount = Count; return; diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs index 454c6a810d..58fd92c73b 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -29,7 +29,7 @@ namespace osu.Game.GameModes.Play.Mania protected Color4 PopOutColor => Color4.Red; protected override float PopOutInitialAlpha => 1.0f; - protected override ulong PopOutDuration => 300; + protected override double PopOutDuration => 300; public override void Load(BaseGame game) { diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index bbad689643..253d1c7f8e 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -48,7 +48,7 @@ namespace osu.Game.GameModes.Play.Osu return $@"{count}x"; } - protected virtual void transformPopOut(ulong newValue) + protected virtual void TransformPopOut(ulong newValue) { PopOutSpriteText.Text = FormatCount(newValue); @@ -61,26 +61,26 @@ namespace osu.Game.GameModes.Play.Osu PopOutSpriteText.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing); } - protected virtual void transformPopOutRolling(ulong newValue) + protected virtual void TransformPopOutRolling(ulong newValue) { - transformPopOut(newValue); - transformPopOutSmall(newValue); + TransformPopOut(newValue); + TransformPopOutSmall(newValue); } - protected virtual void transformNoPopOut(ulong newValue) + protected virtual void TransformNoPopOut(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(1); } - protected virtual void transformPopOutSmall(ulong newValue) + protected virtual void TransformPopOutSmall(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(PopOutSmallScale); DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } - protected virtual void scheduledPopOutSmall(uint id) + protected virtual void ScheduledPopOutSmall(uint id) { // Too late; scheduled task invalidated if (id != ScheduledPopOutCurrentId) @@ -104,12 +104,12 @@ namespace osu.Game.GameModes.Play.Osu DisplayedCountSpriteText.Show(); - transformPopOut(newValue); + TransformPopOut(newValue); uint newTaskId = ScheduledPopOutCurrentId; Scheduler.AddDelayed(delegate { - scheduledPopOutSmall(newTaskId); + ScheduledPopOutSmall(newTaskId); }, PopOutDuration); } @@ -127,23 +127,23 @@ namespace osu.Game.GameModes.Play.Osu DisplayedCountSpriteText.Show(); if (CanPopOutWhileRolling) - transformPopOutRolling(newValue); + TransformPopOutRolling(newValue); else - transformNoPopOut(newValue); + TransformNoPopOut(newValue); } protected override void OnDisplayedCountChange(ulong newValue) { DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); - transformNoPopOut(newValue); + TransformNoPopOut(newValue); } protected override void OnDisplayedCountIncrement(ulong newValue) { DisplayedCountSpriteText.Show(); - transformPopOutSmall(newValue); + TransformPopOutSmall(newValue); } } } diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs index 97f050b3e1..bd12d35315 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -27,14 +27,14 @@ namespace osu.Game.GameModes.Play.Taiko DisplayedCountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre; } - protected virtual void transformAnimate(ulong newValue) + protected virtual void TransformAnimate(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); DisplayedCountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing); } - protected virtual void transformNotAnimate(ulong newValue) + protected virtual void TransformNotAnimate(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(1); @@ -47,21 +47,21 @@ namespace osu.Game.GameModes.Play.Taiko else DisplayedCountSpriteText.Show(); - transformNotAnimate(newValue); + TransformNotAnimate(newValue); } protected override void OnDisplayedCountChange(ulong newValue) { DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); - transformNotAnimate(newValue); + TransformNotAnimate(newValue); } protected override void OnDisplayedCountIncrement(ulong newValue) { DisplayedCountSpriteText.Show(); - transformAnimate(newValue); + TransformAnimate(newValue); } } } diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 8a0e03ad24..e04a3b92b3 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -43,7 +43,6 @@ namespace osu.Game.Graphics.UserInterface /// public virtual EasingTypes RollingEasing => EasingTypes.None; - private T prevDisplayedCount; private T displayedCount; /// @@ -104,18 +103,9 @@ namespace osu.Game.Graphics.UserInterface /// protected RollingCounter() { - Debug.Assert( - TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), - @"transformType should be a subclass of Transform." - ); - Children = new Drawable[] { - DisplayedCountSpriteText = new SpriteText - { - Anchor = this.Anchor, - Origin = this.Origin, - }, + DisplayedCountSpriteText = new SpriteText(), }; } @@ -195,6 +185,12 @@ namespace osu.Game.Graphics.UserInterface protected virtual void TransformCount(T currentValue, T newValue) { object[] parameters = { Clock }; + + Debug.Assert( + TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), + @"transformType should be a subclass of Transform." + ); + TransformCount((Transform)Activator.CreateInstance(TransformType, parameters), currentValue, newValue); } @@ -210,7 +206,7 @@ namespace osu.Game.Graphics.UserInterface if (Clock == null) return; - if (RollingDuration == 0) + if (RollingDuration < 1) { DisplayedCount = Count; return; diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 732c882540..381347a401 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -17,8 +17,8 @@ namespace osu.Game.Graphics.UserInterface { public class StarCounter : AutoSizeContainer { - private Container starContainer; - private List stars = new List(); + private readonly Container starContainer; + private readonly List stars = new List(); private double transformStartTime = 0; @@ -81,11 +81,17 @@ namespace osu.Game.Graphics.UserInterface } } + /// + /// Shows a float count as stars (up to 10). Used as star difficulty display. + /// + public StarCounter() : this(10) { + } + /// /// Shows a float count as stars. Used as star difficulty display. /// /// Maximum amount of stars to display. - public StarCounter(int maxstars = 10) + public StarCounter(int maxstars) { MaxStars = Math.Max(maxstars, 0); @@ -114,6 +120,8 @@ namespace osu.Game.Graphics.UserInterface Anchor = Anchor.CentreLeft, Origin = Anchor.Centre, TextSize = StarSize, + Scale = new Vector2(minStarScale), + Alpha = minStarAlpha, Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0), }; @@ -122,8 +130,8 @@ namespace osu.Game.Graphics.UserInterface starContainer.Add(star); } - // Used to recreate initial state. - StopAnimation(); + // Animate initial state from zero. + transformCount(0, Count); } public void ResetCount()