diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
index ef6752b7a4..1e824cf33b 100644
--- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
+++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
@@ -81,7 +81,7 @@ namespace osu.Desktop.Tests
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
- RollingDuration = 1000,
+ RollingDuration = 500,
RollingEasing = EasingTypes.Out,
Count = 100.0f,
Position = new Vector2(20, 60),
@@ -133,9 +133,9 @@ namespace osu.Desktop.Tests
AddButton(@"miss...", delegate
{
- standardCombo.Count = 0;
- alternativeCombo.Count = 0;
- catchCombo.Count = 0;
+ standardCombo.RollBack();
+ alternativeCombo.RollBack();
+ catchCombo.RollBack();
accuracyCombo.Denominator++;
});
@@ -152,7 +152,7 @@ namespace osu.Desktop.Tests
catchCombo.StopRolling();
alternativeCombo.StopRolling();
accuracyCombo.StopRolling();
- stars.StopRolling();
+ stars.StopAnimation();
});
}
}
diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs
index d13cd20107..32df57d1f0 100644
--- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs
+++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs
@@ -3,7 +3,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
-using osu.Framework.MathUtils;
using osu.Framework.Timing;
using System;
using System.Collections.Generic;
@@ -16,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface
///
/// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
///
- public class AccuracyCounter : NumericRollingCounter
+ public class AccuracyCounter : RollingCounter
{
protected override Type transformType => typeof(TransformAccuracy);
@@ -73,20 +72,13 @@ namespace osu.Game.Graphics.UserInterface
return count.ToString("0.00") + "%";
}
- protected class TransformAccuracy : Transform
+ protected override ulong getProportionalDuration(float currentValue, float newValue)
{
- public override float CurrentValue
- {
- get
- {
- double time = Time;
- if (time < StartTime) return StartValue;
- if (time >= EndTime) return EndValue;
-
- return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
- }
- }
+ return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration);
+ }
+ protected class TransformAccuracy : TransformFloat
+ {
public override void Apply(Drawable d)
{
base.Apply(d);
diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs
index 2fa82d9db3..27541c12a3 100644
--- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs
+++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs
@@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface
///
/// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
///
- public class AlternativeComboCounter : ULongCounter // btw, I'm terribly bad with names... OUENDAN!
+ public class AlternativeComboCounter : ComboCounter
{
public Color4 OriginalColour;
public Color4 TintColour = Color4.OrangeRed;
@@ -25,16 +25,10 @@ namespace osu.Game.Graphics.UserInterface
public EasingTypes TintEasing = EasingTypes.None;
public bool CanAnimateWhenBackwards = false;
- public AlternativeComboCounter()
- {
- IsRollingContinuous = false;
- }
-
public override void Load(BaseGame game)
{
base.Load(game);
- countSpriteText.Hide();
OriginalColour = Colour;
}
@@ -43,25 +37,6 @@ namespace osu.Game.Graphics.UserInterface
SetCountWithoutRolling(0);
}
- protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
- {
- // Animate rollover only when going backwards
- if (newValue > currentValue)
- {
- updateTransforms(typeof(TransformULongCounter));
- removeTransforms(typeof(TransformULongCounter));
-
- // If was decreasing, stops roll before increasing
- if (currentValue < prevValue)
- VisibleCount = currentValue;
-
- VisibleCount = newValue;
- }
- // Also, animate only if was not rollbacking already
- else if (currentValue > prevValue)
- transformCount(new TransformULongCounter(Clock), visibleValue, newValue);
- }
-
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
{
ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs
index 8fe7ba3404..8200ddaa04 100644
--- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs
+++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs
@@ -25,44 +25,11 @@ namespace osu.Game.Graphics.UserInterface
return count.ToString("#,0");
}
- protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
+ public override void RollBack(ulong newValue = 0)
{
- // Animate rollover only when going backwards
- if (newValue > currentValue)
- {
- updateTransforms(typeof(TransformULongCounter));
- removeTransforms(typeof(TransformULongCounter));
+ popOutSpriteText.Colour = countSpriteText.Colour;
- // If was decreasing, stops roll before increasing
- if (currentValue < prevValue)
- VisibleCount = currentValue;
-
- VisibleCount = newValue;
- }
- // Also, animate only if was not rollbacking already
- else if (currentValue > prevValue)
- {
- // Backwards pop-up animation has no tint colour
- popOutSpriteText.Colour = countSpriteText.Colour;
- transformCount(new TransformULongCounter(Clock), visibleValue, newValue);
- }
- }
-
- protected override void transformCount(ulong currentValue, ulong newValue)
- {
- // Animate rollover only when going backwards
- if (newValue > currentValue)
- {
- updateTransforms(typeof(TransformULongCounter));
- removeTransforms(typeof(TransformULongCounter));
- VisibleCount = newValue;
- }
- else if (currentValue != 0)
- {
- // Backwards pop-up animation has no tint colour
- popOutSpriteText.Colour = countSpriteText.Colour;
- transformCount(new TransformULongCounter(Clock), currentValue, newValue);
- }
+ base.RollBack(newValue);
}
///
@@ -74,10 +41,5 @@ namespace osu.Game.Graphics.UserInterface
popOutSpriteText.Colour = colour;
Count++;
}
-
- public override void ResetCount()
- {
- base.ResetCount();
- }
}
}
diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/Graphics/UserInterface/ComboCounter.cs
new file mode 100644
index 0000000000..07c957257c
--- /dev/null
+++ b/osu.Game/Graphics/UserInterface/ComboCounter.cs
@@ -0,0 +1,273 @@
+//Copyright (c) 2007-2016 ppy Pty Ltd .
+//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
+
+using osu.Framework;
+using osu.Framework.Graphics;
+using osu.Framework.Graphics.Containers;
+using osu.Framework.Graphics.Sprites;
+using osu.Framework.Graphics.Transformations;
+using osu.Framework.MathUtils;
+using osu.Framework.Timing;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace osu.Game.Graphics.UserInterface
+{
+ public abstract class ComboCounter : AutoSizeContainer
+ {
+ protected Type transformType => typeof(TransformCombo);
+
+ private bool rollbacking = false;
+
+ protected ulong rollingTotalDuration = 0;
+
+ ///
+ /// If true, the roll-down duration will be proportional to the counter.
+ ///
+ public bool IsRollingProportional = true;
+
+ ///
+ /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each
+ /// element; else duration in milliseconds for the counter roll-up animation in total.
+ ///
+ public ulong RollingDuration = 0;
+
+ ///
+ /// Easing for the counter rollover animation.
+ ///
+ public EasingTypes RollingEasing = EasingTypes.None;
+
+ protected ulong prevVisibleCount;
+ protected ulong visibleCount;
+
+ ///
+ /// Value shown at the current moment.
+ ///
+ public virtual ulong VisibleCount
+ {
+ get
+ {
+ return visibleCount;
+ }
+ protected set
+ {
+ if (visibleCount.Equals(value))
+ return;
+ prevVisibleCount = visibleCount;
+ visibleCount = value;
+ transformVisibleCount(prevVisibleCount, visibleCount);
+ }
+ }
+
+ protected ulong prevPrevCount;
+ protected ulong prevCount;
+ protected ulong count;
+
+ ///
+ /// Actual value of counter.
+ ///
+ public virtual ulong Count
+ {
+ get
+ {
+ return count;
+ }
+ set
+ {
+ prevPrevCount = prevCount;
+ prevCount = count;
+ count = value;
+ if (IsLoaded)
+ {
+ rollingTotalDuration =
+ IsRollingProportional
+ ? getProportionalDuration(VisibleCount, value)
+ : RollingDuration;
+ transformCount(VisibleCount, prevPrevCount, prevCount, value);
+ }
+ }
+ }
+
+ protected SpriteText countSpriteText;
+
+ protected float textSize = 20.0f;
+ public float TextSize
+ {
+ get { return textSize; }
+ set
+ {
+ textSize = value;
+ updateTextSize();
+ }
+ }
+
+ ///
+ /// Base of all combo counters.
+ ///
+ protected ComboCounter()
+ {
+ Children = new Drawable[]
+ {
+ countSpriteText = new SpriteText
+ {
+ Anchor = this.Anchor,
+ Origin = this.Origin,
+ Alpha = 0,
+ },
+ };
+ }
+
+ public override void Load(BaseGame game)
+ {
+ base.Load(game);
+
+ countSpriteText.Anchor = this.Anchor;
+ countSpriteText.Origin = this.Origin;
+
+ StopRolling();
+ }
+
+ ///
+ /// Sets count value, bypassing rollover animation.
+ ///
+ /// New count value.
+ public virtual void SetCountWithoutRolling(ulong count)
+ {
+ Count = count;
+ StopRolling();
+ }
+
+ ///
+ /// Stops rollover animation, forcing the visible count to be the actual count.
+ ///
+ public virtual void StopRolling()
+ {
+ removeComboTransforms();
+ VisibleCount = Count;
+ }
+
+ ///
+ /// Animates roll-back to an specific value.
+ ///
+ /// Target value.
+ public virtual void RollBack(ulong newValue = 0)
+ {
+ rollbacking = true;
+ Count = newValue;
+ rollbacking = false;
+ }
+
+ ///
+ /// Resets count to default value.
+ ///
+ public virtual void ResetCount()
+ {
+ SetCountWithoutRolling(default(ulong));
+ }
+
+ protected virtual ulong getProportionalDuration(ulong currentValue, ulong newValue)
+ {
+ return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
+ }
+
+ protected abstract void transformVisibleCount(ulong currentValue, ulong newValue);
+
+ protected virtual string formatCount(ulong count)
+ {
+ return count.ToString();
+ }
+
+ private void updateComboTransforms()
+ {
+ foreach (ITransform t in Transforms.AliveItems)
+ if (t.GetType() == typeof(TransformCombo))
+ t.Apply(this);
+ }
+
+ private void removeComboTransforms()
+ {
+ Transforms.RemoveAll(t => t.GetType() == typeof(TransformCombo));
+ }
+
+ protected virtual void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
+ {
+ if (!rollbacking)
+ {
+ updateComboTransforms();
+ removeComboTransforms();
+
+ // If was decreasing, stops roll before increasing
+ if (currentValue < prevValue)
+ VisibleCount = currentValue;
+
+ VisibleCount = newValue;
+ }
+ else
+ {
+ transformCount(new TransformCombo(Clock), visibleValue, newValue);
+ }
+ }
+
+ ///
+ /// Intended to be used by transformCount().
+ ///
+ ///
+ protected void transformCount(TransformCombo transform, ulong currentValue, ulong newValue)
+ {
+ updateComboTransforms();
+ removeComboTransforms();
+
+ if (Clock == null)
+ return;
+
+ if (RollingDuration == 0)
+ {
+ VisibleCount = Count;
+ return;
+ }
+
+ transform.StartTime = Time;
+ transform.EndTime = Time + rollingTotalDuration;
+ transform.StartValue = currentValue;
+ transform.EndValue = newValue;
+ transform.Easing = RollingEasing;
+
+ Transforms.Add(transform);
+ }
+
+ protected virtual void updateTextSize()
+ {
+ countSpriteText.TextSize = TextSize;
+ }
+
+ protected class TransformCombo : Transform
+ {
+ public override ulong CurrentValue
+ {
+ get
+ {
+ double time = Time;
+ 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)
+ {
+ base.Apply(d);
+ (d as ComboCounter).VisibleCount = CurrentValue;
+ }
+
+ public TransformCombo(IClock clock)
+ : base(clock)
+ {
+ }
+ }
+ }
+}
diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs
deleted file mode 100644
index 03b9804e01..0000000000
--- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-//Copyright (c) 2007-2016 ppy Pty Ltd .
-//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
-
-using osu.Framework;
-using osu.Framework.Graphics;
-using osu.Framework.Graphics.Sprites;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace osu.Game.Graphics.UserInterface
-{
- ///
- /// Skeleton for a numeric counter with a simple roll-up animation.
- ///
- /// Type of the actual counter.
- public abstract class NumericRollingCounter : RollingCounter
- {
- protected SpriteText countSpriteText;
-
- protected float textSize = 20.0f;
- public float TextSize
- {
- get { return textSize; }
- set
- {
- textSize = value;
- updateTextSize();
- }
- }
-
- protected NumericRollingCounter()
- {
- Children = new Drawable[]
- {
- countSpriteText = new SpriteText
- {
- TextSize = this.TextSize,
- Anchor = this.Anchor,
- Origin = this.Origin,
- },
- };
- }
-
- public override void Load(BaseGame game)
- {
- base.Load(game);
- countSpriteText.Text = formatCount(count);
- countSpriteText.Anchor = this.Anchor;
- countSpriteText.Origin = this.Origin;
- }
-
- protected override void transformVisibleCount(T currentValue, T newValue)
- {
- countSpriteText.Text = formatCount(newValue);
- }
-
- protected virtual void updateTextSize()
- {
- countSpriteText.TextSize = TextSize;
- }
- }
-}
diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs
index 251ea7dd92..4b7d115ceb 100644
--- a/osu.Game/Graphics/UserInterface/RollingCounter.cs
+++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs
@@ -1,6 +1,10 @@
-using osu.Framework;
+//Copyright (c) 2007-2016 ppy Pty Ltd .
+//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
+
+using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
+using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using System;
using System.Collections.Generic;
@@ -11,14 +15,6 @@ using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
- ///
- /// Skeleton for a counter which value rolls-up in a lapse of time.
- ///
- ///
- /// This class only abstracts the basics to roll-up a value in a lapse of time by using Transforms.
- /// In order to show a value, you must implement a way to display it, i.e., as a numeric counter or a bar.
- ///
- /// Type of the actual counter.
public abstract class RollingCounter : AutoSizeContainer
{
///
@@ -29,13 +25,9 @@ namespace osu.Game.Graphics.UserInterface
///
protected virtual Type transformType => typeof(Transform);
- protected ulong RollingTotalDuration = 0;
+ protected ulong rollingTotalDuration = 0;
- ///
- /// If true, each time the Count is updated, it will roll over from the current visible value.
- /// Else, it will roll up from the current count value.
- ///
- public bool IsRollingContinuous = true;
+ protected SpriteText countSpriteText;
///
/// If true, the roll-up duration will be proportional to the counter.
@@ -67,15 +59,13 @@ namespace osu.Game.Graphics.UserInterface
}
protected set
{
- prevVisibleCount = visibleCount;
if (visibleCount.Equals(value))
return;
visibleCount = value;
- transformVisibleCount(prevVisibleCount, value);
+ countSpriteText.Text = formatCount(value);
}
}
- protected T prevPrevCount;
protected T prevCount;
protected T count;
@@ -90,26 +80,49 @@ namespace osu.Game.Graphics.UserInterface
}
set
{
- prevPrevCount = prevCount;
prevCount = count;
count = value;
if (IsLoaded)
{
- RollingTotalDuration =
+ rollingTotalDuration =
IsRollingProportional
- ? getProportionalDuration(VisibleCount, value)
+ ? getProportionalDuration(visibleCount, value)
: RollingDuration;
- transformCount(visibleCount, prevPrevCount, prevCount, value);
+ transformCount(visibleCount, count);
}
}
}
+ protected float textSize = 20.0f;
+
+ public float TextSize
+ {
+ get { return textSize; }
+ set
+ {
+ textSize = value;
+ countSpriteText.TextSize = value;
+ }
+ }
+
+ ///
+ /// Skeleton of a numeric counter which value rolls over time.
+ ///
protected RollingCounter()
{
Debug.Assert(
transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform),
@"transformType should be a subclass of Transform."
);
+
+ Children = new Drawable[]
+ {
+ countSpriteText = new SpriteText
+ {
+ Anchor = this.Anchor,
+ Origin = this.Origin,
+ },
+ };
}
public override void Load(BaseGame game)
@@ -117,10 +130,12 @@ namespace osu.Game.Graphics.UserInterface
base.Load(game);
removeTransforms(transformType);
-
- if (Count == null)
- ResetCount();
+
VisibleCount = Count;
+
+ countSpriteText.Text = formatCount(count);
+ countSpriteText.Anchor = this.Anchor;
+ countSpriteText.Origin = this.Origin;
}
///
@@ -145,7 +160,10 @@ namespace osu.Game.Graphics.UserInterface
///
/// Resets count to default value.
///
- public abstract void ResetCount();
+ public virtual void ResetCount()
+ {
+ SetCountWithoutRolling(default(T));
+ }
///
/// Calculates the duration of the roll-up animation by using the difference between the current visible value
@@ -185,19 +203,6 @@ namespace osu.Game.Graphics.UserInterface
Transforms.RemoveAll(t => t.GetType() == type);
}
- ///
- /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e.
- /// implement the rollover animation).
- ///
- /// Count value currently visible to user.
- /// Count value before previous modification.
- /// Count value before modification.
- /// Expected count value after modification.
- protected virtual void transformCount(T visibleValue, T prevValue, T currentValue, T newValue)
- {
- transformCount(IsRollingContinuous ? visibleValue : currentValue, newValue);
- }
-
///
/// Called when the count is updated to add a transformer that changes the value of the visible count (i.e.
/// implement the rollover animation).
@@ -239,20 +244,12 @@ namespace osu.Game.Graphics.UserInterface
}
transform.StartTime = Time;
- transform.EndTime = Time + RollingTotalDuration;
+ transform.EndTime = Time + rollingTotalDuration;
transform.StartValue = currentValue;
transform.EndValue = newValue;
transform.Easing = RollingEasing;
Transforms.Add(transform);
}
-
- ///
- /// This procedure is called each time the visible count value is updated.
- /// Override to create custom animations.
- ///
- /// Visible count value before modification.
- /// Expected visible count value after modification-
- protected abstract void transformVisibleCount(T currentValue, T newValue);
}
}
diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs
index faba550bb0..a22a403115 100644
--- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs
+++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs
@@ -2,6 +2,10 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
+using osu.Framework.Graphics;
+using osu.Framework.Graphics.Transformations;
+using osu.Framework.MathUtils;
+using osu.Framework.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -10,8 +14,10 @@ using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
- public class ScoreCounter : ULongCounter
+ public class ScoreCounter : RollingCounter
{
+ protected override Type transformType => typeof(TransformScore);
+
///
/// How many leading zeroes the counter has.
///
@@ -36,9 +42,40 @@ namespace osu.Game.Graphics.UserInterface
base.Load(game);
}
+ protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
+ {
+ return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
+ }
+
protected override string formatCount(ulong count)
{
return count.ToString("D" + LeadingZeroes);
}
+
+ protected class TransformScore : Transform
+ {
+ public override ulong CurrentValue
+ {
+ get
+ {
+ double time = Time;
+ 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)
+ {
+ base.Apply(d);
+ (d as ScoreCounter).VisibleCount = CurrentValue;
+ }
+
+ public TransformScore(IClock clock)
+ : base(clock)
+ {
+ }
+ }
}
}
diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs
index 838db7525f..3053542741 100644
--- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs
+++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs
@@ -18,7 +18,7 @@ namespace osu.Game.Graphics.UserInterface
///
/// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
///
- public class StandardComboCounter : ULongCounter
+ public class StandardComboCounter : ComboCounter
{
protected SpriteText popOutSpriteText;
@@ -45,10 +45,6 @@ namespace osu.Game.Graphics.UserInterface
public StandardComboCounter()
{
- IsRollingContinuous = false;
-
- countSpriteText.Alpha = 0;
-
popOutSpriteText = new SpriteText
{
Origin = this.Origin,
@@ -68,32 +64,6 @@ namespace osu.Game.Graphics.UserInterface
Add(popOutSpriteText);
}
- protected override void updateTextSize()
- {
- base.updateTextSize();
-
- popOutSpriteText.TextSize = this.TextSize;
- }
-
- protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue)
- {
- // Animate rollover only when going backwards
- if (newValue > currentValue)
- {
- updateTransforms(typeof(TransformULongCounter));
- removeTransforms(typeof(TransformULongCounter));
-
- // If was decreasing, stops roll before increasing
- if (currentValue < prevValue)
- VisibleCount = currentValue;
-
- VisibleCount = newValue;
- }
- // Also, animate only if was not rollbacking already
- else if (currentValue > prevValue)
- transformCount(new TransformULongCounter(Clock), visibleValue, newValue);
- }
-
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
{
ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
@@ -161,5 +131,12 @@ namespace osu.Game.Graphics.UserInterface
else
transformNoPopOut(newValue);
}
+
+ protected override void updateTextSize()
+ {
+ base.updateTextSize();
+
+ popOutSpriteText.TextSize = this.TextSize;
+ }
}
}
diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs
index 2a9eb47031..d83a1cf28f 100644
--- a/osu.Game/Graphics/UserInterface/StarCounter.cs
+++ b/osu.Game/Graphics/UserInterface/StarCounter.cs
@@ -10,19 +10,18 @@ using osu.Framework.MathUtils;
using osu.Framework.Timing;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
- public class StarCounter : RollingCounter
+ public class StarCounter : AutoSizeContainer
{
- protected override Type transformType => typeof(TransformStarCounter);
+ private Container starContainer;
+ private List stars = new List();
- protected Container starContainer;
- protected List stars = new List();
+ private double transformStartTime = 0;
///
/// Maximum amount of stars displayed.
@@ -36,13 +35,52 @@ namespace osu.Game.Graphics.UserInterface
protected set;
}
- public ulong StarAnimationDuration = 500;
- public EasingTypes StarAnimationEasing = EasingTypes.OutElasticHalf;
- public ulong FadeDuration = 100;
- public float MinStarSize = 0.3f;
+ public double AnimationDelay = 150;
+
+ public double ScalingDuration = 500;
+ public EasingTypes ScalingEasing = EasingTypes.OutElasticHalf;
+ public float MinStarScale = 0.3f;
+
+ public double FadingDuration = 100;
public float MinStarAlpha = 0.5f;
- public int StarSize = 20;
- public int StarSpacing = 4;
+
+ public float StarSize = 20;
+ public float StarSpacing = 4;
+
+ public float VisibleValue
+ {
+ get
+ {
+ double elapsedTime = Time - transformStartTime;
+ double expectedElapsedTime = Math.Abs(prevCount - count) * AnimationDelay;
+ if (elapsedTime >= expectedElapsedTime)
+ return count;
+ return Interpolation.ValueAt(elapsedTime, prevCount, count, 0, expectedElapsedTime);
+ }
+ }
+
+ private float prevCount;
+ private float count;
+
+ ///
+ /// Amount of stars represented.
+ ///
+ public float Count
+ {
+ get
+ {
+ return count;
+ }
+ set
+ {
+ prevCount = VisibleValue;
+ count = value;
+ if (IsLoaded)
+ {
+ transformCount(prevCount, count);
+ }
+ }
+ }
///
/// Shows a float count as stars. Used as star difficulty display.
@@ -50,10 +88,7 @@ namespace osu.Game.Graphics.UserInterface
/// Maximum amount of stars to display.
public StarCounter(int stars = 10)
{
- IsRollingProportional = true;
- RollingDuration = 150;
-
- MaxStars = stars;
+ MaxStars = Math.Max(stars, 0);
Children = new Drawable[]
{
@@ -65,17 +100,6 @@ namespace osu.Game.Graphics.UserInterface
};
}
- protected override ulong getProportionalDuration(float currentValue, float newValue)
- {
- return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration);
- }
-
- public override void ResetCount()
- {
- Count = 0;
- StopRolling();
- }
-
public override void Load(BaseGame game)
{
base.Load(game);
@@ -91,8 +115,6 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
TextSize = StarSize,
- Scale = new Vector2(MinStarSize),
- Alpha = (i == 0) ? 1.0f : MinStarAlpha,
Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0),
};
@@ -101,118 +123,75 @@ namespace osu.Game.Graphics.UserInterface
starContainer.Add(star);
}
- ResetCount();
+ StopAnimation();
}
- protected override void transformCount(float currentValue, float newValue)
+ public void ResetCount()
{
- transformStar((int)Math.Floor(currentValue), currentValue, currentValue < newValue);
- transformCount(new TransformStarCounter(Clock), currentValue, newValue);
+ Count = 0;
+ StopAnimation();
}
- protected void updateTransformStar(int i)
+ public void StopAnimation()
{
- foreach (ITransform t in stars[i].Transforms.AliveItems)
- if (t.GetType() == typeof(TransformAlpha) || t.GetType() == typeof(TransformScaleVector))
- t.Apply(stars[i]);
+ prevCount = count;
+ transformStartTime = Time;
- stars[i].Transforms.RemoveAll(t =>
- t.GetType() == typeof(TransformScaleVector) || t.GetType() == typeof(TransformAlpha)
- );
- }
-
- protected void transformStarScale(int i, TransformScaleVector transform, bool isIncrement, double startTime)
- {
- transform.StartTime = startTime;
- transform.EndTime = transform.StartTime + StarAnimationDuration;
- transform.StartValue = stars[i].Scale;
- transform.EndValue = new Vector2(
- Interpolation.ValueAt(
- Math.Min(Math.Max(i, Count), i + 1),
- MinStarSize,
- 1.0f,
- i,
- i + 1
- )
- );
- transform.Easing = StarAnimationEasing;
-
- stars[i].Transforms.Add(transform);
- }
-
- protected void transformStarAlpha(int i, TransformAlpha transform, bool isIncrement, double startTime)
- {
- transform.StartTime = startTime;
- transform.EndTime = transform.StartTime + FadeDuration;
- transform.StartValue = stars[i].Alpha;
- transform.EndValue = i < Count ? 1.0f : MinStarAlpha;
-
- stars[i].Transforms.Add(transform);
- }
-
-
- protected void transformStar(int i, float value, bool isIncrement)
- {
- if (i >= MaxStars)
- return;
-
- if (Clock == null)
- return;
-
- // Calculate time where animation should had started
- double startTime = Time;
- // If incrementing, animation should had started when VisibleCount crossed start of star (i)
- if (isIncrement)
- startTime -= i == (int)Math.Floor(prevCount) ?
- getProportionalDuration(prevCount, value) : getProportionalDuration(i, value);
- // If decrementing, animation should had started when VisibleCount crossed end of star (i + 1)
- else
- startTime -= i == (int)Math.Floor(prevCount) ?
- getProportionalDuration(prevCount, value) : getProportionalDuration(i + 1, value);
-
- updateTransformStar(i);
-
- transformStarScale(i, new TransformScaleVector(Clock), isIncrement, startTime);
- transformStarAlpha(i, new TransformAlpha(Clock), isIncrement, startTime);
- }
-
- protected override void transformVisibleCount(float currentValue, float newValue)
- {
- // Detect increment that passes over an integer value
- if (Math.Ceiling(currentValue) <= Math.Floor(newValue))
- for (int i = (int)Math.Ceiling(currentValue); i <= Math.Floor(newValue); i++)
- transformStar(i, newValue, true);
-
- // Detect decrement that passes over an integer value
- if (Math.Floor(currentValue) >= Math.Ceiling(newValue))
- for (int i = (int)Math.Floor(newValue); i < Math.Floor(currentValue); i++)
- transformStar(i, newValue, false);
- }
-
- protected class TransformStarCounter : Transform
- {
- public override float CurrentValue
+ for (int i = 0; i < MaxStars; i++)
{
- get
- {
- double time = Time;
- if (time < StartTime) return StartValue;
- if (time >= EndTime) return EndValue;
+ stars[i].DelayReset();
+ transformStarQuick(i, count);
+ }
+ }
- return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
+ private float getStarScale(int i, float value)
+ {
+ if (value <= i)
+ return MinStarScale;
+ if (i + 1 <= value)
+ return 1.0f;
+ return Interpolation.ValueAt(value, MinStarScale, 1.0f, i, i + 1);
+ }
+
+ private void transformStar(int i, float value)
+ {
+ stars[i].FadeTo(i < value ? 1.0f : MinStarAlpha, FadingDuration);
+ stars[i].ScaleTo(getStarScale(i, value), ScalingDuration, ScalingEasing);
+ }
+
+ private void transformStarQuick(int i, float value)
+ {
+ stars[i].FadeTo(i < value ? 1.0f : MinStarAlpha);
+ stars[i].ScaleTo(getStarScale(i, value));
+ }
+
+ private void transformCount(float currentValue, float newValue)
+ {
+ if (currentValue < newValue)
+ {
+ int currentValueFloor = (int)currentValue;
+ for (int i = 0; i < MaxStars; i++)
+ {
+ stars[i].DelayReset();
+ stars[i].ClearTransformations();
+ if (i > currentValueFloor)
+ stars[i].Delay((i - currentValueFloor) * AnimationDelay);
+ transformStar(i, newValue);
}
}
-
- public override void Apply(Drawable d)
- {
- base.Apply(d);
- (d as StarCounter).VisibleCount = CurrentValue;
- }
-
- public TransformStarCounter(IClock clock)
- : base(clock)
+ else
{
+ int currentValueCeiling = (int)Math.Ceiling(currentValue);
+ for (int i = MaxStars - 1; i >= 0; i--)
+ {
+ stars[i].DelayReset();
+ stars[i].ClearTransformations();
+ if (i < currentValueCeiling)
+ stars[i].Delay((currentValueCeiling - i) * AnimationDelay);
+ transformStar(i, newValue);
+ }
}
+ transformStartTime = Time;
}
}
}
diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs
deleted file mode 100644
index 35df8f5cc8..0000000000
--- a/osu.Game/Graphics/UserInterface/ULongCounter.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-//Copyright (c) 2007-2016 ppy Pty Ltd .
-//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
-
-using osu.Framework.Graphics;
-using osu.Framework.Graphics.Transformations;
-using osu.Framework.MathUtils;
-using osu.Framework.Timing;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace osu.Game.Graphics.UserInterface
-{
- ///
- /// A simple rolling counter that accepts unsigned long values.
- ///
- public class ULongCounter : NumericRollingCounter
- {
- protected override Type transformType => typeof(TransformULongCounter);
-
- public override void ResetCount()
- {
- SetCountWithoutRolling(0);
- }
-
- protected override string formatCount(ulong count)
- {
- return count.ToString("#,0");
- }
-
- protected class TransformULongCounter : Transform
- {
- public override ulong CurrentValue
- {
- get
- {
- double time = Time;
- 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)
- {
- base.Apply(d);
- (d as ULongCounter).VisibleCount = CurrentValue;
- }
-
- public TransformULongCounter(IClock clock)
- : base(clock)
- {
- }
- }
- }
-}
diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj
index bdb852c33f..f05a95f279 100644
--- a/osu.Game/osu.Game.csproj
+++ b/osu.Game/osu.Game.csproj
@@ -106,6 +106,8 @@
+
+
@@ -113,18 +115,15 @@
-
-
-