diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
index 445e4aff78..5bcfc489d9 100644
--- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
+++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
@@ -12,6 +12,10 @@ using OpenTK;
using OpenTK.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Graphics.Sprites;
+using osu.Game.GameModes.Play.Catch;
+using osu.Game.GameModes.Play.Mania;
+using osu.Game.GameModes.Play.Osu;
+using osu.Game.GameModes.Play.Taiko;
namespace osu.Desktop.Tests
{
@@ -25,6 +29,8 @@ namespace osu.Desktop.Tests
{
base.Reset();
+ int numerator = 0, denominator = 0;
+
ScoreCounter score = new ScoreCounter(7)
{
Origin = Anchor.TopRight,
@@ -35,7 +41,7 @@ namespace osu.Desktop.Tests
};
Add(score);
- StandardComboCounter standardCombo = new StandardComboCounter
+ ComboCounter standardCombo = new OsuComboCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
@@ -55,18 +61,28 @@ namespace osu.Desktop.Tests
};
Add(catchCombo);
- AlternativeComboCounter alternativeCombo = new AlternativeComboCounter
+ ComboCounter taikoCombo = new TaikoComboCounter
{
- Origin = Anchor.BottomLeft,
- Anchor = Anchor.BottomLeft,
- Position = new Vector2(20, 80),
+ Origin = Anchor.BottomCentre,
+ Anchor = Anchor.Centre,
+ Position = new Vector2(0, -160),
Count = 0,
TextSize = 40,
};
- Add(alternativeCombo);
+ Add(taikoCombo);
+
+ ComboCounter maniaCombo = new ManiaComboCounter
+ {
+ Origin = Anchor.Centre,
+ Anchor = Anchor.Centre,
+ Position = new Vector2(0, -80),
+ Count = 0,
+ TextSize = 40,
+ };
+ Add(maniaCombo);
- AccuracyCounter accuracyCombo = new AccuracyCounter
+ PercentageCounter accuracyCombo = new PercentageCounter
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
@@ -95,9 +111,10 @@ namespace osu.Desktop.Tests
{
score.Count = 0;
standardCombo.Count = 0;
- alternativeCombo.Count = 0;
+ maniaCombo.Count = 0;
catchCombo.Count = 0;
- accuracyCombo.SetCount(0, 0);
+ numerator = denominator = 0;
+ accuracyCombo.SetFraction(0, 0);
stars.Count = 0;
starsLabel.Text = stars.Count.ToString("0.00");
});
@@ -106,23 +123,26 @@ namespace osu.Desktop.Tests
{
score.Count += 300 + (ulong)(300.0 * (standardCombo.Count > 0 ? standardCombo.Count - 1 : 0) / 25.0);
standardCombo.Count++;
- alternativeCombo.Count++;
+ taikoCombo.Count++;
+ maniaCombo.Count++;
catchCombo.CatchFruit(new Color4(
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
1)
);
- accuracyCombo.Numerator++;
- accuracyCombo.Denominator++;
+ numerator++; denominator++;
+ accuracyCombo.SetFraction(numerator, denominator);
});
AddButton(@"miss...", delegate
{
standardCombo.Roll();
- alternativeCombo.Roll();
+ taikoCombo.Roll();
+ maniaCombo.Roll();
catchCombo.Roll();
- accuracyCombo.Denominator++;
+ denominator++;
+ accuracyCombo.SetFraction(numerator, denominator);
});
AddButton(@"Alter stars", delegate
@@ -136,7 +156,8 @@ namespace osu.Desktop.Tests
score.StopRolling();
standardCombo.StopRolling();
catchCombo.StopRolling();
- alternativeCombo.StopRolling();
+ taikoCombo.StopRolling();
+ maniaCombo.StopRolling();
accuracyCombo.StopRolling();
stars.StopAnimation();
});
diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs
similarity index 68%
rename from osu.Game/Graphics/UserInterface/CatchComboCounter.cs
rename to osu.Game/GameModes/Play/Catch/CatchComboCounter.cs
index b1231585cf..078a856bce 100644
--- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs
+++ b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs
@@ -2,32 +2,30 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
+using osu.Game.GameModes.Play.Osu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace osu.Game.Graphics.UserInterface
+namespace osu.Game.GameModes.Play.Catch
{
///
/// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch.
///
- public class CatchComboCounter : StandardComboCounter
+ public class CatchComboCounter : OsuComboCounter
{
- public CatchComboCounter()
- {
- CanPopOutWhenBackwards = true;
- }
+ protected override bool CanPopOutWhenBackwards => true;
- protected override string formatCount(ulong count)
+ protected override string FormatCount(ulong count)
{
return count.ToString("#,0");
}
public override void Roll(ulong newValue = 0)
{
- popOutSpriteText.Colour = countSpriteText.Colour;
+ PopOutSpriteText.Colour = CountSpriteText.Colour;
base.Roll(newValue);
}
@@ -38,7 +36,7 @@ namespace osu.Game.Graphics.UserInterface
/// Last grabbed fruit colour.
public void CatchFruit(Color4 colour)
{
- popOutSpriteText.Colour = colour;
+ PopOutSpriteText.Colour = colour;
Count++;
}
}
diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs
new file mode 100644
index 0000000000..d32900532f
--- /dev/null
+++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs
@@ -0,0 +1,61 @@
+//Copyright (c) 2007-2016 ppy Pty Ltd .
+//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
+
+using OpenTK.Graphics;
+using osu.Framework;
+using osu.Framework.Graphics;
+using osu.Game.GameModes.Play.Taiko;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace osu.Game.GameModes.Play.Mania
+{
+ ///
+ /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
+ ///
+ public class ManiaComboCounter : TaikoComboCounter
+ {
+ protected Color4 OriginalColour;
+
+ protected Color4 TintColour => Color4.OrangeRed;
+ protected Color4 PopOutColor => Color4.Red;
+ protected override float PopOutInitialAlpha => 1.0f;
+ protected override ulong PopOutDuration => 300;
+
+ public override void Load(BaseGame game)
+ {
+ base.Load(game);
+
+ PopOutSpriteText.Anchor = Anchor.BottomCentre;
+ PopOutSpriteText.Origin = Anchor.Centre;
+ PopOutSpriteText.FadeColour(PopOutColor, 0);
+ OriginalColour = Colour;
+ }
+
+ public override void Roll(ulong newValue = 0)
+ {
+ if (!IsRolling)
+ {
+ PopOutSpriteText.Text = FormatCount(VisibleCount);
+
+ PopOutSpriteText.FadeTo(PopOutInitialAlpha);
+ PopOutSpriteText.ScaleTo(1.0f);
+
+ PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
+ PopOutSpriteText.ScaleTo(PopOutScale, PopOutDuration, PopOutEasing);
+ }
+
+ base.Roll(newValue);
+ }
+
+ protected override void transformAnimate(ulong newValue)
+ {
+ base.transformAnimate(newValue);
+ CountSpriteText.FadeColour(TintColour, 0);
+ CountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing);
+ }
+ }
+}
diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs
new file mode 100644
index 0000000000..ef47569582
--- /dev/null
+++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs
@@ -0,0 +1,124 @@
+//Copyright (c) 2007-2016 ppy Pty Ltd .
+//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
+
+using OpenTK;
+using osu.Framework;
+using osu.Game.Graphics.UserInterface;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace osu.Game.GameModes.Play.Osu
+{
+ ///
+ /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
+ ///
+ public class OsuComboCounter : ComboCounter
+ {
+ protected uint ScheduledPopOutCurrentId = 0;
+
+ protected virtual float PopOutSmallScale => 1.1f;
+ protected virtual bool CanPopOutWhenBackwards => false;
+
+
+ public Vector2 InnerCountPosition
+ {
+ get
+ {
+ return CountSpriteText.Position;
+ }
+ set
+ {
+ CountSpriteText.Position = value;
+ }
+ }
+
+ public override void Load(BaseGame game)
+ {
+ base.Load(game);
+
+ PopOutSpriteText.Origin = this.Origin;
+ PopOutSpriteText.Anchor = this.Anchor;
+
+ Add(PopOutSpriteText);
+ }
+
+ protected override string FormatCount(ulong count)
+ {
+ return count.ToString("#,0") + "x";
+ }
+
+ protected virtual void transformPopOut(ulong currentValue, ulong newValue)
+ {
+ PopOutSpriteText.Text = FormatCount(newValue);
+ CountSpriteText.Text = FormatCount(currentValue);
+
+ PopOutSpriteText.ScaleTo(PopOutScale);
+ PopOutSpriteText.FadeTo(PopOutInitialAlpha);
+ PopOutSpriteText.MoveTo(Vector2.Zero);
+
+ PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
+ PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
+ PopOutSpriteText.MoveTo(CountSpriteText.Position, PopOutDuration, PopOutEasing);
+
+ ScheduledPopOutCurrentId++;
+ uint newTaskId = ScheduledPopOutCurrentId;
+ Scheduler.AddDelayed(delegate
+ {
+ scheduledPopOutSmall(newTaskId, newValue);
+ }, PopOutDuration);
+ }
+
+ protected virtual void transformNoPopOut(ulong newValue)
+ {
+ ScheduledPopOutCurrentId++;
+ CountSpriteText.Text = FormatCount(newValue);
+ CountSpriteText.ScaleTo(1);
+ }
+
+ protected virtual void transformPopOutSmall(ulong newValue)
+ {
+ CountSpriteText.Text = FormatCount(newValue);
+ CountSpriteText.ScaleTo(PopOutSmallScale);
+ CountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
+ }
+
+ protected virtual void scheduledPopOutSmall(uint id, ulong newValue)
+ {
+ // Too late; scheduled task invalidated
+ if (id != ScheduledPopOutCurrentId)
+ return;
+
+ transformPopOutSmall(newValue);
+ }
+
+ protected override void OnCountRolling(ulong currentValue, ulong newValue)
+ {
+ if (newValue == 0)
+ CountSpriteText.FadeOut(PopOutDuration);
+ else
+ CountSpriteText.Show();
+
+ if (CanPopOutWhenBackwards)
+ transformPopOut(currentValue, newValue);
+ else
+ transformNoPopOut(newValue);
+ }
+
+ protected override void OnCountChange(ulong newValue)
+ {
+ CountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
+
+ transformNoPopOut(newValue);
+ }
+
+ protected override void OnCountIncrement(ulong newValue)
+ {
+ CountSpriteText.Show();
+
+ transformPopOut(newValue - 1, newValue);
+ }
+ }
+}
diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs
new file mode 100644
index 0000000000..677be076cd
--- /dev/null
+++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs
@@ -0,0 +1,65 @@
+//Copyright (c) 2007-2016 ppy Pty Ltd .
+//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
+
+using OpenTK;
+using osu.Framework.Graphics.Transformations;
+using osu.Game.Graphics.UserInterface;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace osu.Game.GameModes.Play.Taiko
+{
+ public class TaikoComboCounter : ComboCounter
+ {
+ protected virtual int AnimationDuration => 300;
+ protected virtual float ScaleFactor => 2;
+ protected virtual EasingTypes AnimationEasing => EasingTypes.None;
+ protected virtual bool CanAnimateWhenBackwards => false;
+
+ public TaikoComboCounter()
+ {
+ CountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre;
+ CountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre;
+ }
+
+ protected virtual void transformAnimate(ulong newValue)
+ {
+ CountSpriteText.Text = FormatCount(newValue);
+ CountSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
+ CountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing);
+ }
+
+ protected virtual void transformNotAnimate(ulong newValue)
+ {
+ CountSpriteText.Text = FormatCount(newValue);
+ CountSpriteText.ScaleTo(1);
+ }
+
+ protected override void OnCountRolling(ulong currentValue, ulong newValue)
+ {
+ if (newValue == 0)
+ CountSpriteText.FadeOut(AnimationDuration);
+ else
+ CountSpriteText.Show();
+
+ transformNotAnimate(newValue);
+ }
+
+ protected override void OnCountChange(ulong newValue)
+ {
+ CountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
+
+ transformNotAnimate(newValue);
+ }
+
+ protected override void OnCountIncrement(ulong newValue)
+ {
+ CountSpriteText.Show();
+
+ transformAnimate(newValue);
+ }
+ }
+}
diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs
deleted file mode 100644
index 0d7fcb39c0..0000000000
--- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs
+++ /dev/null
@@ -1,109 +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.Transformations;
-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
-{
- ///
- /// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
- ///
- public class AccuracyCounter : RollingCounter
- {
- protected override Type transformType => typeof(TransformAccuracy);
-
- private long numerator = 0;
- public long Numerator
- {
- get
- {
- return numerator;
- }
- set
- {
- numerator = value;
- updateCount();
- }
- }
-
- private ulong denominator = 0;
- public ulong Denominator
- {
- get
- {
- return denominator;
- }
- set
- {
- denominator = value;
- updateCount();
- }
- }
-
- public AccuracyCounter()
- {
- RollingDuration = 500;
- RollingEasing = EasingTypes.Out;
- }
-
- public override void Load(BaseGame game)
- {
- base.Load(game);
-
- updateCount();
- StopRolling();
- }
-
- public void SetCount(long num, ulong den)
- {
- numerator = num;
- denominator = den;
- updateCount();
- }
-
- private void updateCount()
- {
- Count = Denominator == 0 ? 100.0f : (Numerator * 100.0f) / Denominator;
- }
-
- public override void ResetCount()
- {
- numerator = 0;
- denominator = 0;
- updateCount();
- StopRolling();
- }
-
- protected override string formatCount(float count)
- {
- return count.ToString("0.00") + "%";
- }
-
- protected override double getProportionalDuration(float currentValue, float newValue)
- {
- return Math.Abs(currentValue - newValue) * RollingDuration;
- }
-
- protected class TransformAccuracy : TransformFloat
- {
- public override void Apply(Drawable d)
- {
- base.Apply(d);
- (d as AccuracyCounter).VisibleCount = CurrentValue;
- }
-
- public TransformAccuracy(IClock clock)
- : base(clock)
- {
- }
- }
- }
-}
diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs
deleted file mode 100644
index 114092384b..0000000000
--- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-//Copyright (c) 2007-2016 ppy Pty Ltd .
-//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
-
-using OpenTK;
-using OpenTK.Graphics;
-using osu.Framework;
-using osu.Framework.Graphics.Transformations;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace osu.Game.Graphics.UserInterface
-{
- ///
- /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
- ///
- public class AlternativeComboCounter : ComboCounter
- {
- public Color4 OriginalColour;
- public Color4 TintColour = Color4.OrangeRed;
- public int TintDuration = 300;
- public float ScaleFactor = 2;
- public EasingTypes TintEasing = EasingTypes.None;
- public bool CanAnimateWhenBackwards = false;
-
- public override void Load(BaseGame game)
- {
- base.Load(game);
-
- OriginalColour = Colour;
- }
-
- protected override double getProportionalDuration(ulong currentValue, ulong newValue)
- {
- double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
- return difference * RollingDuration;
- }
-
- protected virtual void transformAnimate(ulong newValue)
- {
- countSpriteText.FadeColour(TintColour, 0);
- countSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
- countSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing);
- countSpriteText.ScaleTo(new Vector2(1, 1), TintDuration, TintEasing);
- }
-
- protected override void transformVisibleCount(ulong currentValue, ulong newValue)
- {
- countSpriteText.Text = formatCount(newValue);
-
- if (newValue == 0)
- countSpriteText.FadeOut(TintDuration);
- else
- countSpriteText.Show();
-
- if (newValue > currentValue || CanAnimateWhenBackwards)
- transformAnimate(newValue);
- }
- }
-}
diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/Graphics/UserInterface/ComboCounter.cs
index d5c019e644..f5c0c382b8 100644
--- a/osu.Game/Graphics/UserInterface/ComboCounter.cs
+++ b/osu.Game/Graphics/UserInterface/ComboCounter.cs
@@ -17,28 +17,37 @@ using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
{
- public abstract class ComboCounter : AutoSizeContainer
+ public abstract class ComboCounter : Container
{
protected Type transformType => typeof(TransformCombo);
+ protected bool IsRolling = false;
+
+ protected SpriteText PopOutSpriteText;
+
+ protected virtual ulong PopOutDuration => 150;
+ protected virtual float PopOutScale => 2.0f;
+ protected virtual EasingTypes PopOutEasing => EasingTypes.None;
+ protected virtual float PopOutInitialAlpha => 0.75f;
+
///
/// If true, the roll-down duration will be proportional to the counter.
///
- public bool IsRollingProportional = true;
+ protected virtual 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 double RollingDuration = 20;
+ protected virtual double RollingDuration => 20;
///
/// Easing for the counter rollover animation.
///
- public EasingTypes RollingEasing = EasingTypes.None;
+ protected EasingTypes RollingEasing => EasingTypes.None;
- protected ulong prevVisibleCount;
- protected ulong visibleCount;
+ private ulong prevVisibleCount;
+ private ulong visibleCount;
///
/// Value shown at the current moment.
@@ -55,11 +64,10 @@ namespace osu.Game.Graphics.UserInterface
return;
prevVisibleCount = visibleCount;
visibleCount = value;
- transformVisibleCount(prevVisibleCount, visibleCount);
+ transformVisibleCount(prevVisibleCount, visibleCount, IsRolling);
}
}
- protected ulong prevPrevCount;
protected ulong prevCount;
protected ulong count;
@@ -80,25 +88,25 @@ namespace osu.Game.Graphics.UserInterface
private void setCount(ulong value, bool rolling = false)
{
- prevPrevCount = prevCount;
prevCount = count;
count = value;
if (IsLoaded)
{
- transformCount(VisibleCount, prevPrevCount, prevCount, value, rolling);
+ transformCount(VisibleCount, prevCount, value, rolling);
}
}
- protected SpriteText countSpriteText;
+ protected SpriteText CountSpriteText;
- protected float textSize = 20.0f;
+ private float textSize = 20.0f;
public float TextSize
{
get { return textSize; }
set
{
textSize = value;
- updateTextSize();
+ CountSpriteText.TextSize = TextSize;
+ PopOutSpriteText.TextSize = TextSize;
}
}
@@ -109,12 +117,16 @@ namespace osu.Game.Graphics.UserInterface
{
Children = new Drawable[]
{
- countSpriteText = new SpriteText
+ CountSpriteText = new SpriteText
{
Anchor = this.Anchor,
Origin = this.Origin,
Alpha = 0,
},
+ PopOutSpriteText = new SpriteText
+ {
+ Alpha = 0,
+ }
};
}
@@ -122,8 +134,8 @@ namespace osu.Game.Graphics.UserInterface
{
base.Load(game);
- countSpriteText.Anchor = this.Anchor;
- countSpriteText.Origin = this.Origin;
+ CountSpriteText.Anchor = this.Anchor;
+ CountSpriteText.Origin = this.Origin;
StopRolling();
}
@@ -133,7 +145,7 @@ namespace osu.Game.Graphics.UserInterface
///
public virtual void StopRolling()
{
- removeComboTransforms();
+ Flush(false, typeof(TransformCombo));
VisibleCount = Count;
}
@@ -154,62 +166,55 @@ namespace osu.Game.Graphics.UserInterface
Count = default(ulong);
}
- protected virtual double getProportionalDuration(ulong currentValue, ulong newValue)
+ protected double GetProportionalDuration(ulong currentValue, ulong newValue)
{
- return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
+ double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
+ return difference * RollingDuration;
}
- protected abstract void transformVisibleCount(ulong currentValue, ulong newValue);
-
- protected virtual string formatCount(ulong count)
+ protected virtual string FormatCount(ulong count)
{
return count.ToString();
}
- private void updateComboTransforms()
+ protected abstract void OnCountRolling(ulong currentValue, ulong newValue);
+ protected abstract void OnCountIncrement(ulong newValue);
+ protected abstract void OnCountChange(ulong newValue);
+
+ private void transformVisibleCount(ulong currentValue, ulong newValue, bool rolling)
{
- foreach (ITransform t in Transforms.AliveItems)
- if (t.GetType() == typeof(TransformCombo))
- t.Apply(this);
+ if (rolling)
+ OnCountRolling(currentValue, newValue);
+ else if (currentValue + 1 == newValue)
+ OnCountIncrement(newValue);
+ else
+ OnCountChange(newValue);
}
- private void removeComboTransforms()
- {
- Transforms.RemoveAll(t => t.GetType() == typeof(TransformCombo));
- }
-
- protected virtual void transformCount(
+ private void transformCount(
ulong visibleValue,
- ulong prevValue,
ulong currentValue,
ulong newValue,
bool rolling)
{
if (!rolling)
{
- updateComboTransforms();
- removeComboTransforms();
-
- // If was decreasing, stops roll before increasing
- if (currentValue < prevValue)
- VisibleCount = currentValue;
+ Flush(false, typeof(TransformCombo));
+ IsRolling = false;
+ VisibleCount = currentValue;
VisibleCount = newValue;
}
else
{
- transformCount(new TransformCombo(Clock), visibleValue, newValue);
+ IsRolling = true;
+ transformRoll(new TransformCombo(Clock), visibleValue, newValue);
}
}
- ///
- /// Intended to be used by transformCount().
- ///
- ///
- protected void transformCount(TransformCombo transform, ulong currentValue, ulong newValue)
+ private void transformRoll(TransformCombo transform, ulong currentValue, ulong newValue)
{
- updateComboTransforms();
- removeComboTransforms();
+ Flush(false, typeof(TransformCombo));
if (Clock == null)
return;
@@ -222,7 +227,7 @@ namespace osu.Game.Graphics.UserInterface
double rollingTotalDuration =
IsRollingProportional
- ? getProportionalDuration(currentValue, newValue)
+ ? GetProportionalDuration(currentValue, newValue)
: RollingDuration;
transform.StartTime = Time;
@@ -234,11 +239,6 @@ namespace osu.Game.Graphics.UserInterface
Transforms.Add(transform);
}
- protected virtual void updateTextSize()
- {
- countSpriteText.TextSize = TextSize;
- }
-
protected class TransformCombo : Transform
{
public override ulong CurrentValue
diff --git a/osu.Game/Graphics/UserInterface/PercentageCounter.cs b/osu.Game/Graphics/UserInterface/PercentageCounter.cs
new file mode 100644
index 0000000000..844afaa00e
--- /dev/null
+++ b/osu.Game/Graphics/UserInterface/PercentageCounter.cs
@@ -0,0 +1,62 @@
+//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.Transformations;
+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
+{
+ ///
+ /// Used as an accuracy counter. Represented visually as a percentage.
+ ///
+ public class PercentageCounter : RollingCounter
+ {
+ protected override Type TransformType => typeof(TransformAccuracy);
+
+ public override double RollingDuration => 500;
+ public override EasingTypes RollingEasing => EasingTypes.Out;
+
+ private float epsilon => 1e-10f;
+
+ public void SetFraction(float numerator, float denominator)
+ {
+ Count = Math.Abs(denominator) < epsilon ? 1.0f : numerator / denominator;
+ }
+
+ public PercentageCounter()
+ {
+ Count = 1.0f;
+ }
+
+ protected override string FormatCount(float count)
+ {
+ return $@"{count:P2}";
+ }
+
+ protected override double GetProportionalDuration(float currentValue, float newValue)
+ {
+ return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
+ }
+
+ protected class TransformAccuracy : TransformFloat
+ {
+ public override void Apply(Drawable d)
+ {
+ base.Apply(d);
+ (d as PercentageCounter).VisibleCount = CurrentValue;
+ }
+
+ public TransformAccuracy(IClock clock)
+ : base(clock)
+ {
+ }
+ }
+ }
+}
diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs
index 10a8085726..968b5abfa8 100644
--- a/osu.Game/Graphics/UserInterface/RollingCounter.cs
+++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs
@@ -23,9 +23,9 @@ namespace osu.Game.Graphics.UserInterface
///
/// Must be a subclass of Transform
///
- protected virtual Type transformType => typeof(Transform);
+ protected virtual Type TransformType => typeof(Transform);
- protected SpriteText countSpriteText;
+ protected SpriteText CountSpriteText;
///
/// If true, the roll-up duration will be proportional to change in value.
@@ -36,15 +36,15 @@ namespace osu.Game.Graphics.UserInterface
/// 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 double RollingDuration = 0;
+ public virtual double RollingDuration => 0;
///
/// Easing for the counter rollover animation.
///
- public EasingTypes RollingEasing = EasingTypes.None;
+ public virtual EasingTypes RollingEasing => EasingTypes.None;
- protected T prevVisibleCount;
- protected T visibleCount;
+ private T prevVisibleCount;
+ private T visibleCount;
///
/// Value shown at the current moment.
@@ -60,7 +60,7 @@ namespace osu.Game.Graphics.UserInterface
if (visibleCount.Equals(value))
return;
visibleCount = value;
- countSpriteText.Text = formatCount(value);
+ CountSpriteText.Text = FormatCount(value);
}
}
@@ -82,7 +82,7 @@ namespace osu.Game.Graphics.UserInterface
count = value;
if (IsLoaded)
{
- transformCount(visibleCount, count);
+ TransformCount(visibleCount, count);
}
}
}
@@ -95,7 +95,7 @@ namespace osu.Game.Graphics.UserInterface
set
{
textSize = value;
- countSpriteText.TextSize = value;
+ CountSpriteText.TextSize = value;
}
}
@@ -105,13 +105,13 @@ namespace osu.Game.Graphics.UserInterface
protected RollingCounter()
{
Debug.Assert(
- transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform),
+ TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform),
@"transformType should be a subclass of Transform."
);
Children = new Drawable[]
{
- countSpriteText = new SpriteText
+ CountSpriteText = new SpriteText
{
Anchor = this.Anchor,
Origin = this.Origin,
@@ -123,13 +123,13 @@ namespace osu.Game.Graphics.UserInterface
{
base.Load(game);
- removeTransforms(transformType);
+ Flush(false, TransformType);
VisibleCount = Count;
- countSpriteText.Text = formatCount(count);
- countSpriteText.Anchor = this.Anchor;
- countSpriteText.Origin = this.Origin;
+ CountSpriteText.Text = FormatCount(count);
+ CountSpriteText.Anchor = this.Anchor;
+ CountSpriteText.Origin = this.Origin;
}
///
@@ -147,7 +147,7 @@ namespace osu.Game.Graphics.UserInterface
///
public virtual void StopRolling()
{
- removeTransforms(transformType);
+ Flush(false, TransformType);
VisibleCount = Count;
}
@@ -170,7 +170,7 @@ namespace osu.Game.Graphics.UserInterface
/// Current visible value.
/// New final value.
/// Calculated rollover duration in milliseconds.
- protected virtual double getProportionalDuration(T currentValue, T newValue)
+ protected virtual double GetProportionalDuration(T currentValue, T newValue)
{
return RollingDuration;
}
@@ -180,46 +180,32 @@ namespace osu.Game.Graphics.UserInterface
///
/// Count to format.
/// Count formatted as a string.
- protected virtual string formatCount(T count)
+ protected virtual string FormatCount(T count)
{
return count.ToString();
}
- protected void updateTransforms(Type type)
- {
- foreach (ITransform t in Transforms.AliveItems)
- if (t.GetType() == type)
- t.Apply(this);
- }
-
- protected void removeTransforms(Type type)
- {
- 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 before modification.
/// Expected count value after modification-
- ///
- protected virtual void transformCount(T currentValue, T newValue)
+ ///
+ protected virtual void TransformCount(T currentValue, T newValue)
{
object[] parameters = { Clock };
- transformCount((Transform)Activator.CreateInstance(transformType, parameters), currentValue, newValue);
+ TransformCount((Transform)Activator.CreateInstance(TransformType, parameters), currentValue, newValue);
}
///
- /// Intended to be used by transformCount().
+ /// Intended to be used by TransformCount(T currentValue, T newValue).
///
- ///
- protected void transformCount(Transform transform, T currentValue, T newValue)
+ protected void TransformCount(Transform transform, T currentValue, T newValue)
{
Type type = transform.GetType();
- updateTransforms(type);
- removeTransforms(type);
+ Flush(false, type);
if (Clock == null)
return;
@@ -232,7 +218,7 @@ namespace osu.Game.Graphics.UserInterface
double rollingTotalDuration =
IsRollingProportional
- ? getProportionalDuration(currentValue, newValue)
+ ? GetProportionalDuration(currentValue, newValue)
: RollingDuration;
transform.StartTime = Time;
diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs
index 5617570243..e65953c265 100644
--- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs
+++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs
@@ -16,7 +16,10 @@ namespace osu.Game.Graphics.UserInterface
{
public class ScoreCounter : RollingCounter
{
- protected override Type transformType => typeof(TransformScore);
+ protected override Type TransformType => typeof(TransformScore);
+
+ public override double RollingDuration => 1000;
+ public override EasingTypes RollingEasing => EasingTypes.Out;
///
/// How many leading zeroes the counter has.
@@ -33,11 +36,8 @@ namespace osu.Game.Graphics.UserInterface
/// How many leading zeroes the counter will have.
public ScoreCounter(uint leading = 0)
{
- countSpriteText.FixedWidth = true;
+ CountSpriteText.FixedWidth = true;
LeadingZeroes = leading;
-
- RollingDuration = 1000;
- RollingEasing = EasingTypes.Out;
}
public override void Load(BaseGame game)
@@ -45,12 +45,12 @@ namespace osu.Game.Graphics.UserInterface
base.Load(game);
}
- protected override double getProportionalDuration(ulong currentValue, ulong newValue)
+ protected override double GetProportionalDuration(ulong currentValue, ulong newValue)
{
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
}
- protected override string formatCount(ulong count)
+ protected override string FormatCount(ulong count)
{
return count.ToString("D" + LeadingZeroes);
}
diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs
deleted file mode 100644
index 8d8fb4acab..0000000000
--- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-//Copyright (c) 2007-2016 ppy Pty Ltd .
-//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
-
-using OpenTK;
-using osu.Framework;
-using osu.Framework.Graphics;
-using osu.Framework.Graphics.Sprites;
-using osu.Framework.Graphics.Transformations;
-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
-{
- ///
- /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
- ///
- public class StandardComboCounter : ComboCounter
- {
- protected SpriteText popOutSpriteText;
-
- protected uint scheduledPopOutCurrentId = 0;
-
- public ulong PopOutDuration = 150;
- public float PopOutBigScale = 2.0f;
- public float PopOutSmallScale = 1.1f;
- public EasingTypes PopOutEasing = EasingTypes.None;
- public bool CanPopOutWhenBackwards = false;
- public float PopOutInitialAlpha = 0.75f;
-
- public Vector2 InnerCountPosition
- {
- get
- {
- return countSpriteText.Position;
- }
- set
- {
- countSpriteText.Position = value;
- }
- }
-
- public StandardComboCounter()
- {
- popOutSpriteText = new SpriteText
- {
- Origin = this.Origin,
- Anchor = this.Anchor,
- TextSize = this.TextSize,
- Alpha = 0,
- };
- }
-
- public override void Load(BaseGame game)
- {
- base.Load(game);
-
- popOutSpriteText.Origin = this.Origin;
- popOutSpriteText.Anchor = this.Anchor;
-
- Add(popOutSpriteText);
- }
-
- protected override double getProportionalDuration(ulong currentValue, ulong newValue)
- {
- double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
- return difference * RollingDuration;
- }
-
- protected override string formatCount(ulong count)
- {
- return count.ToString("#,0") + "x";
- }
-
- protected virtual void transformPopOut(ulong currentValue, ulong newValue)
- {
- popOutSpriteText.Text = formatCount(newValue);
- countSpriteText.Text = formatCount(currentValue);
-
- popOutSpriteText.ScaleTo(PopOutBigScale);
- popOutSpriteText.FadeTo(PopOutInitialAlpha);
- popOutSpriteText.MoveTo(Vector2.Zero);
-
- popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
- popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
- popOutSpriteText.MoveTo(countSpriteText.Position, PopOutDuration, PopOutEasing);
-
- scheduledPopOutCurrentId++;
- uint newTaskId = scheduledPopOutCurrentId;
- Scheduler.AddDelayed(delegate
- {
- scheduledPopOutSmall(newTaskId, newValue);
- }, PopOutDuration);
- }
-
- protected virtual void transformNoPopOut(ulong newValue)
- {
- scheduledPopOutCurrentId++;
- countSpriteText.Text = formatCount(newValue);
- countSpriteText.ScaleTo(1);
- }
-
- protected virtual void transformPopOutSmall(ulong newValue)
- {
- countSpriteText.Text = formatCount(newValue);
- countSpriteText.ScaleTo(PopOutSmallScale);
- countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
- }
-
- protected virtual void scheduledPopOutSmall(uint id, ulong newValue)
- {
- // Too late; scheduled task invalidated
- if (id != scheduledPopOutCurrentId)
- return;
-
- transformPopOutSmall(newValue);
- }
-
- protected override void transformVisibleCount(ulong currentValue, ulong newValue)
- {
- if (newValue == 0)
- countSpriteText.FadeOut(PopOutDuration);
- else
- countSpriteText.Show();
-
- if (newValue > currentValue || CanPopOutWhenBackwards)
- transformPopOut(currentValue, newValue);
- 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 3592bbb140..a352bdfb9f 100644
--- a/osu.Game/Graphics/UserInterface/StarCounter.cs
+++ b/osu.Game/Graphics/UserInterface/StarCounter.cs
@@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Framework.MathUtils;
-using osu.Framework.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -35,14 +34,14 @@ namespace osu.Game.Graphics.UserInterface
protected set;
}
- public double AnimationDelay = 150;
+ private double animationDelay => 150;
- public double ScalingDuration = 500;
- public EasingTypes ScalingEasing = EasingTypes.OutElasticHalf;
- public float MinStarScale = 0.3f;
+ private double scalingDuration => 500;
+ private EasingTypes scalingEasing => EasingTypes.OutElasticHalf;
+ private float minStarScale => 0.3f;
- public double FadingDuration = 100;
- public float MinStarAlpha = 0.5f;
+ private double fadingDuration => 100;
+ private float minStarAlpha => 0.5f;
public float StarSize = 20;
public float StarSpacing = 4;
@@ -52,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface
get
{
double elapsedTime = Time - transformStartTime;
- double expectedElapsedTime = Math.Abs(prevCount - count) * AnimationDelay;
+ double expectedElapsedTime = Math.Abs(prevCount - count) * animationDelay;
if (elapsedTime >= expectedElapsedTime)
return count;
return Interpolation.ValueAt(elapsedTime, prevCount, count, 0, expectedElapsedTime);
@@ -147,21 +146,21 @@ namespace osu.Game.Graphics.UserInterface
private float getStarScale(int i, float value)
{
if (value <= i)
- return MinStarScale;
+ return minStarScale;
if (i + 1 <= value)
return 1.0f;
- return Interpolation.ValueAt(value, MinStarScale, 1.0f, i, i + 1);
+ 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);
+ 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].FadeTo(i < value ? 1.0f : minStarAlpha);
stars[i].ScaleTo(getStarScale(i, value));
}
@@ -172,9 +171,9 @@ namespace osu.Game.Graphics.UserInterface
stars[i].DelayReset();
stars[i].ClearTransformations();
if (currentValue <= newValue)
- stars[i].Delay(Math.Max(i - currentValue, 0) * AnimationDelay);
+ stars[i].Delay(Math.Max(i - currentValue, 0) * animationDelay);
else
- stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * AnimationDelay);
+ stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * animationDelay);
transformStar(i, newValue);
}
transformStartTime = Time;
diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj
index d638868d73..9948c7066c 100644
--- a/osu.Game/osu.Game.csproj
+++ b/osu.Game/osu.Game.csproj
@@ -132,21 +132,22 @@
+
-
+
-
+
-
-
+
+