From 00cfc5100409ab3917e5c3e65b5ef637a4a64e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Fri, 7 Oct 2016 02:05:02 -0500 Subject: [PATCH 01/26] Rolling counters (initial) --- .../Tests/TestCaseScoreCounter.cs | 193 ++++++++++++++ .../osu.Desktop.VisualTests.csproj | 1 + .../Graphics/UserInterface/AccuracyCounter.cs | 102 ++++++++ .../UserInterface/AlternativeComboCounter.cs | 86 +++++++ .../UserInterface/CatchComboCounter.cs | 56 ++++ .../Graphics/UserInterface/RollingCounter.cs | 239 ++++++++++++++++++ .../Graphics/UserInterface/ScoreCounter.cs | 21 ++ .../UserInterface/StandardComboCounter.cs | 110 ++++++++ .../Graphics/UserInterface/ULongCounter.cs | 59 +++++ osu.Game/osu.Game.csproj | 7 + 10 files changed, 874 insertions(+) create mode 100644 osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/AccuracyCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/CatchComboCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/RollingCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/ScoreCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/StandardComboCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/ULongCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs new file mode 100644 index 0000000000..c97fd369ea --- /dev/null +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -0,0 +1,193 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using OpenTK.Input; +using osu.Framework.GameModes.Testing; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Graphics.Transformations; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.MathUtils; + +namespace osu.Desktop.Tests +{ + class TestCaseScoreCounter : TestCase + { + public override string Name => @"ScoreCounter"; + + public override string Description => @"Tests multiple counters"; + + public override void Reset() + { + base.Reset(); + + Random rnd = new Random(); + + ScoreCounter uc = new ScoreCounter + { + Origin = Anchor.TopRight, + Anchor = Anchor.TopRight, + TextSize = 40, + RollingDuration = 1000, + RollingEasing = EasingTypes.Out, + Count = 0, + Position = new Vector2(20, 20), + LeadingZeroes = 7, + }; + Add(uc); + + StandardComboCounter sc = new StandardComboCounter + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Position = new Vector2(20, 20), + IsRollingProportional = true, + RollingDuration = 20, + PopOutDuration = 250, + Count = 0, + TextSize = 40, + }; + Add(sc); + + CatchComboCounter cc = new CatchComboCounter + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + IsRollingProportional = true, + RollingDuration = 20, + PopOutDuration = 250, + Count = 0, + TextSize = 40, + }; + Add(cc); + + AlternativeComboCounter ac = new AlternativeComboCounter + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Position = new Vector2(20, 80), + IsRollingProportional = true, + RollingDuration = 20, + ScaleFactor = 2, + Count = 0, + TextSize = 40, + }; + Add(ac); + + + AccuracyCounter pc = new AccuracyCounter + { + Origin = Anchor.TopRight, + Anchor = Anchor.TopRight, + RollingDuration = 1000, + RollingEasing = EasingTypes.Out, + Count = 100.0f, + Position = new Vector2(20, 60), + }; + Add(pc); + + Button resetButton = new Button + { + Origin = Anchor.TopLeft, + Anchor = Anchor.TopLeft, + Text = @"Reset all", + Width = 100, + Height = 20, + Position = new Vector2(0, 0), + }; + resetButton.Action += delegate + { + uc.Count = 0; + sc.Count = 0; + ac.Count = 0; + cc.Count = 0; + pc.SetCount(0, 0); + }; + Add(resetButton); + + Button hitButton = new Button + { + Origin = Anchor.TopLeft, + Anchor = Anchor.TopLeft, + Text = @"Hit! :D", + Width = 100, + Height = 20, + Position = new Vector2(0, 20), + }; + hitButton.Action += delegate + { + uc.Count += 300 + (ulong)(300.0 * (sc.Count > 0 ? sc.Count - 1 : 0) / 25.0); + sc.Count++; + ac.Count++; + cc.CatchFruit(new Color4( + Math.Max(0.5f, RNG.NextSingle()), + Math.Max(0.5f, RNG.NextSingle()), + Math.Max(0.5f, RNG.NextSingle()), + 1) + ); + pc.Numerator++; + pc.Denominator++; + }; + Add(hitButton); + + Button missButton = new Button + { + Origin = Anchor.TopLeft, + Anchor = Anchor.TopLeft, + Text = @"miss...", + Width = 100, + Height = 20, + Position = new Vector2(0, 40), + }; + missButton.Action += delegate + { + sc.Count = 0; + ac.Count = 0; + cc.Count = 0; + pc.Denominator++; + }; + Add(missButton); + + Button forceResetButton = new Button + { + Origin = Anchor.TopLeft, + Anchor = Anchor.TopLeft, + Text = @"Force reset", + Width = 100, + Height = 20, + Position = new Vector2(0, 60), + }; + forceResetButton.Action += delegate + { + uc.ResetCount(); + sc.ResetCount(); + ac.ResetCount(); + pc.ResetCount(); + cc.ResetCount(); + }; + Add(forceResetButton); + + Button stopButton = new Button + { + Origin = Anchor.TopLeft, + Anchor = Anchor.TopLeft, + Text = @"STOP!", + Width = 100, + Height = 20, + Position = new Vector2(0, 80), + }; + stopButton.Action += delegate + { + uc.StopRolling(); + sc.StopRolling(); + cc.StopRolling(); + ac.StopRolling(); + pc.StopRolling(); + }; + Add(stopButton); + } + } +} diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index b731d53b4b..fdbd878a87 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -152,6 +152,7 @@ + diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs new file mode 100644 index 0000000000..da04d9d7f7 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs @@ -0,0 +1,102 @@ +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 +{ + /// + /// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction. + /// + public class AccuracyCounter : RollingCounter + { + 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 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 void transformCount(float currentValue, float newValue) + { + transformCount(new TransformAccuracy(Clock), currentValue, newValue); + } + + protected class TransformAccuracy : Transform + { + 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); + } + } + + 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 new file mode 100644 index 0000000000..edcad7f13c --- /dev/null +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -0,0 +1,86 @@ +using OpenTK; +using OpenTK.Graphics; +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 by osu!taiko and osu!mania. + /// + public class AlternativeComboCounter : ULongCounter // btw, I'm terribly bad with names... OUENDAN! + { + public Color4 OriginalColour; + public Color4 TintColour = Color4.OrangeRed; + public int TintDuration = 500; + public float ScaleFactor = 1; + public EasingTypes TintEasing = EasingTypes.None; + public bool CanAnimateWhenBackwards = false; + + public AlternativeComboCounter() + { + IsRollingContinuous = false; + } + + public override void Load() + { + base.Load(); + countSpriteText.Hide(); + OriginalColour = Colour; + } + + public override void ResetCount() + { + SetCountWithoutRolling(0); + } + + protected override void transformCount(ulong currentValue, ulong newValue) + { + // Animate rollover only when going backwards + if (newValue > currentValue) + { + updateTransforms(typeof(TranformULongCounter)); + removeTransforms(typeof(TranformULongCounter)); + VisibleCount = newValue; + } + else + transformCount(new TranformULongCounter(Clock), currentValue, newValue); + } + + protected override ulong GetProportionalDuration(ulong currentValue, ulong newValue) + { + ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + return difference * RollingDuration; + } + + protected virtual void transformAnimate() + { + countSpriteText.Colour = TintColour; + 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) + { + if (countSpriteText != null) + { + countSpriteText.Text = newValue.ToString(@"#,0"); + if (newValue == 0) + { + countSpriteText.FadeOut(TintDuration); + return; + } + countSpriteText.Show(); + if (newValue > currentValue || CanAnimateWhenBackwards) + { + transformAnimate(); + } + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs new file mode 100644 index 0000000000..07ac925bcd --- /dev/null +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -0,0 +1,56 @@ +using OpenTK.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Graphics.UserInterface +{ + /// + /// Similar to Standard, but without the 'x' and has colour shadows. Used by osu!catch. + /// + public class CatchComboCounter : StandardComboCounter + { + public CatchComboCounter() + { + CanPopOutWhenBackwards = true; + } + + protected override string formatCount(ulong count) + { + return count.ToString("#,0"); + } + + protected override void transformCount(ulong currentValue, ulong newValue) + { + // Animate rollover only when going backwards + if (newValue > currentValue) + { + updateTransforms(typeof(TranformULongCounter)); + removeTransforms(typeof(TranformULongCounter)); + VisibleCount = newValue; + } + else + { + popOutSpriteText.Colour = countSpriteText.Colour; + transformCount(new TranformULongCounter(Clock), currentValue, newValue); + } + } + + /// + /// Tints pop-out before animation. Intended to use the last grabbed fruit colour. + /// + /// + public void CatchFruit(Color4 colour) + { + popOutSpriteText.Colour = colour; + Count++; + } + + public override void ResetCount() + { + base.ResetCount(); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs new file mode 100644 index 0000000000..0e714e07c6 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -0,0 +1,239 @@ +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; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Graphics.UserInterface +{ + /// + /// Skeleton for a counter with a simple rollover animation. + /// + /// Type of the actual counter. + public abstract class RollingCounter : Container + { + protected SpriteText countSpriteText; + protected ulong RollingTotalDuration = 0; + + protected float textSize = 20.0f; + public float TextSize + { + get { return textSize; } + set + { + textSize = value; + updateTextSize(); + } + } + + /// + /// If true, each time the Count is updated, it will roll over from the current visible value. + /// Else, it will roll over from the current count value. + /// + public bool IsRollingContinuous = true; + + /// + /// If true, the rollover duration will be proportional to the counter. + /// + public bool IsRollingProportional = false; + + /// + /// If IsRollingProportional = false, duration in milliseconds for the counter rollover animation for each element. + /// If IsRollingProportional = true, duration in milliseconds for the counter rollover animation in total. + /// + public ulong RollingDuration = 0; + + /// + /// Easing for the counter rollover animation. + /// + public EasingTypes RollingEasing = EasingTypes.None; + + protected T visibleCount; + + /// + /// Value shown at the current moment. + /// + public virtual T VisibleCount + { + get + { + return visibleCount; + } + protected set + { + if (visibleCount.Equals(value)) + return; + transformVisibleCount(visibleCount, value); + visibleCount = value; + } + } + + protected T count; + + /// + /// Actual value of counter. + /// + public virtual T Count + { + get + { + return count; + } + set + { + if (Clock != null) + { + RollingTotalDuration = IsRollingProportional ? GetProportionalDuration(VisibleCount, value) : RollingDuration; + transformCount(IsRollingContinuous ? VisibleCount : count, value); + } + count = value; + } + } + + public override void Load() + { + base.Load(); + removeTransforms(typeof(Transform)); + if (Count == null) + ResetCount(); + VisibleCount = Count; + Children = new Drawable[] + { + countSpriteText = new SpriteText + { + Text = formatCount(Count), + TextSize = this.TextSize, + Anchor = this.Anchor, + Origin = this.Origin, + }, + }; + } + + /// + /// Calculates the duration of the rollover animation by using the difference between the current visible value and the new final value. + /// + /// + /// Intended to be used in conjunction with IsRolloverProportional = true. + /// If you're sure your superclass won't never need to be proportional, then it is not necessary to override this function. + /// + /// Current visible value. + /// New final value. + /// Calculated rollover duration in milliseconds. + protected virtual ulong GetProportionalDuration(T currentValue, T newValue) + { + return RollingDuration; + } + + /// + /// Used to format counts. + /// + /// Count to format. + /// Count formatted as a string. + protected virtual string formatCount(T count) + { + return count.ToString(); + } + + /// + /// Sets count value, bypassing rollover animation. + /// + /// New count value. + public virtual void SetCountWithoutRolling(T count) + { + Count = count; + StopRolling(); + } + + /// + /// Stops rollover animation, forcing the visible count to be the actual count. + /// + public virtual void StopRolling() + { + removeTransforms(typeof(Transform)); + VisibleCount = Count; + } + + /// + /// Resets count to default value. + /// + public abstract void ResetCount(); + + protected void updateTransforms(Type type) + { + foreach (ITransform t in Transforms.AliveItems) + if (t.GetType().IsAssignableFrom(type)) + t.Apply(this); + } + + protected void removeTransforms(Type type) + { + Transforms.RemoveAll(t => t.GetType().IsSubclassOf(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- + /// + /// Unless you need to set a custom animation according to the current or new value of the count, the recommended approach is to call + /// transformCount(CustomTransformer(Clock), currentValue, newValue), where CustomTransformer is a custom Transformer related to the + /// type T of the RolloverCounter. + /// By using this approach, there is no need to check if the Clock is not null; this validation is done before adding the transformer. + /// + protected abstract void transformCount(T currentValue, T newValue); + + /// + /// Intended to be used by transformCount(). + /// + /// + protected void transformCount(Transform transform, T currentValue, T newValue) + { + Type type = transform.GetType(); + + updateTransforms(type); + removeTransforms(type); + + 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); + } + + /// + /// 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 virtual void transformVisibleCount(T currentValue, T newValue) + { + if (countSpriteText != null) + { + countSpriteText.Text = formatCount(newValue); + } + } + + protected virtual void updateTextSize() + { + if (countSpriteText != null) + countSpriteText.TextSize = TextSize; + } + } +} diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs new file mode 100644 index 0000000000..08892f3d38 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Graphics.UserInterface +{ + public class ScoreCounter : ULongCounter + { + /// + /// How many leading zeroes the counter will have. + /// + public uint LeadingZeroes = 0; + + 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 new file mode 100644 index 0000000000..15404fd2e5 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -0,0 +1,110 @@ +using osu.Framework.Graphics.Sprites; +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 +{ + /// + /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used by osu! standard. + /// + public class StandardComboCounter : ULongCounter + { + public SpriteText popOutSpriteText; + + public ulong PopOutDuration = 0; + public float PopOutBigScale = 2.0f; + public float PopOutSmallScale = 1.2f; + public EasingTypes PopOutEasing = EasingTypes.None; + public bool CanPopOutWhenBackwards = false; + public float PopOutInitialAlpha = 1.0f; + + public StandardComboCounter() + { + IsRollingContinuous = false; + } + + public override void Load() + { + base.Load(); + countSpriteText.Alpha = 0; + Add(popOutSpriteText = new SpriteText + { + Text = formatCount(Count), + Origin = this.Origin, + Anchor = this.Anchor, + TextSize = this.TextSize, + Alpha = 0, + }); + } + + public override void ResetCount() + { + SetCountWithoutRolling(0); + } + + protected override void updateTextSize() + { + base.updateTextSize(); + if (popOutSpriteText != null) + popOutSpriteText.TextSize = this.TextSize; + } + + + protected override void transformCount(ulong currentValue, ulong newValue) + { + // Animate rollover only when going backwards + if (newValue > currentValue) + { + updateTransforms(typeof(TranformULongCounter)); + removeTransforms(typeof(TranformULongCounter)); + VisibleCount = newValue; + } + else + transformCount(new TranformULongCounter(Clock), currentValue, newValue); + } + + protected override ulong GetProportionalDuration(ulong currentValue, ulong newValue) + { + ulong 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() + { + countSpriteText.ScaleTo(PopOutSmallScale); + countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); + + popOutSpriteText.ScaleTo(PopOutBigScale); + popOutSpriteText.FadeTo(PopOutInitialAlpha); + popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); + popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); + } + + protected override void transformVisibleCount(ulong currentValue, ulong newValue) + { + if (countSpriteText != null && popOutSpriteText != null) + { + countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue); + if (newValue == 0) + { + countSpriteText.FadeOut(PopOutDuration); + } + else + { + countSpriteText.Show(); + if (newValue > currentValue || CanPopOutWhenBackwards) + transformPopOut(); + } + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs new file mode 100644 index 0000000000..01ab357518 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/ULongCounter.cs @@ -0,0 +1,59 @@ +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 rollover counter that accepts unsigned long values. + /// + public class ULongCounter : RollingCounter + { + protected override void transformCount(ulong currentValue, ulong newValue) + { + transformCount(new TranformULongCounter(Clock), currentValue, newValue); + } + + public override void ResetCount() + { + SetCountWithoutRolling(0); + } + + protected override string formatCount(ulong count) + { + return count.ToString("#,0"); + } + + protected class TranformULongCounter : 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 TranformULongCounter(IClock clock) + : base(clock) + { + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 8ef0f07fa7..ae45d04592 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -101,10 +101,17 @@ + + + + + + + From 35325fab95261673e447ccf21bd0ba45dc910a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Fri, 7 Oct 2016 02:24:46 -0500 Subject: [PATCH 02/26] Licence added --- osu.Game/Graphics/UserInterface/AccuracyCounter.cs | 5 ++++- osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs | 5 ++++- osu.Game/Graphics/UserInterface/CatchComboCounter.cs | 5 ++++- osu.Game/Graphics/UserInterface/RollingCounter.cs | 5 ++++- osu.Game/Graphics/UserInterface/ScoreCounter.cs | 5 ++++- osu.Game/Graphics/UserInterface/StandardComboCounter.cs | 5 ++++- osu.Game/Graphics/UserInterface/ULongCounter.cs | 5 ++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs index da04d9d7f7..2ca6d602c7 100644 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs @@ -1,4 +1,7 @@ -using osu.Framework.Graphics; +//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; diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index edcad7f13c..3bd63ad641 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -1,4 +1,7 @@ -using OpenTK; +//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.Graphics.Transformations; using System; diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 07ac925bcd..d68c163fa6 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -1,4 +1,7 @@ -using OpenTK.Graphics; +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK.Graphics; using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 0e714e07c6..4e7e3ad6f3 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -1,4 +1,7 @@ -using osu.Framework.Graphics; +//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.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index 08892f3d38..a23e7b5803 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -1,4 +1,7 @@ -using System; +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 15404fd2e5..437c4f011f 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -1,4 +1,7 @@ -using osu.Framework.Graphics.Sprites; +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; using System; using System.Collections.Generic; diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs index 01ab357518..c01c4208c0 100644 --- a/osu.Game/Graphics/UserInterface/ULongCounter.cs +++ b/osu.Game/Graphics/UserInterface/ULongCounter.cs @@ -1,4 +1,7 @@ -using osu.Framework.Graphics; +//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; From 965e542eaf295a86ad2f2ead62cfc764f8fab683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Fri, 7 Oct 2016 16:14:35 -0500 Subject: [PATCH 03/26] Line wrapping --- .../UserInterface/AlternativeComboCounter.cs | 6 ++-- .../UserInterface/CatchComboCounter.cs | 3 +- .../Graphics/UserInterface/RollingCounter.cs | 34 +++++++++++-------- .../UserInterface/StandardComboCounter.cs | 7 +--- .../Graphics/UserInterface/ULongCounter.cs | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 3bd63ad641..5afe23fce7 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -13,14 +13,14 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { /// - /// Allows tint and vertical scaling animation. Used by osu!taiko and osu!mania. + /// 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 Color4 OriginalColour; public Color4 TintColour = Color4.OrangeRed; public int TintDuration = 500; - public float ScaleFactor = 1; + public float ScaleFactor = 2; public EasingTypes TintEasing = EasingTypes.None; public bool CanAnimateWhenBackwards = false; @@ -72,7 +72,7 @@ namespace osu.Game.Graphics.UserInterface { if (countSpriteText != null) { - countSpriteText.Text = newValue.ToString(@"#,0"); + countSpriteText.Text = newValue.ToString("#,0"); if (newValue == 0) { countSpriteText.FadeOut(TintDuration); diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index d68c163fa6..6f6d586cb8 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { /// - /// Similar to Standard, but without the 'x' and has colour shadows. Used by osu!catch. + /// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch. /// public class CatchComboCounter : StandardComboCounter { @@ -36,6 +36,7 @@ namespace osu.Game.Graphics.UserInterface } else { + // Backwards pop-up animation has no tint colour popOutSpriteText.Colour = countSpriteText.Colour; transformCount(new TranformULongCounter(Clock), currentValue, newValue); } diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 4e7e3ad6f3..780c747e96 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -14,7 +14,7 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { /// - /// Skeleton for a counter with a simple rollover animation. + /// Skeleton for a counter with a simple roll-up animation. /// /// Type of the actual counter. public abstract class RollingCounter : Container @@ -35,18 +35,18 @@ namespace osu.Game.Graphics.UserInterface /// /// If true, each time the Count is updated, it will roll over from the current visible value. - /// Else, it will roll over from the current count value. + /// Else, it will roll up from the current count value. /// public bool IsRollingContinuous = true; /// - /// If true, the rollover duration will be proportional to the counter. + /// If true, the roll-up duration will be proportional to the counter. /// public bool IsRollingProportional = false; /// - /// If IsRollingProportional = false, duration in milliseconds for the counter rollover animation for each element. - /// If IsRollingProportional = true, duration in milliseconds for the counter rollover animation in total. + /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each element. + /// If IsRollingProportional = true, duration in milliseconds for the counter roll-up animation in total. /// public ulong RollingDuration = 0; @@ -90,7 +90,10 @@ namespace osu.Game.Graphics.UserInterface { if (Clock != null) { - RollingTotalDuration = IsRollingProportional ? GetProportionalDuration(VisibleCount, value) : RollingDuration; + RollingTotalDuration = + IsRollingProportional + ? GetProportionalDuration(VisibleCount, value) + : RollingDuration; transformCount(IsRollingContinuous ? VisibleCount : count, value); } count = value; @@ -117,11 +120,12 @@ namespace osu.Game.Graphics.UserInterface } /// - /// Calculates the duration of the rollover animation by using the difference between the current visible value and the new final value. + /// Calculates the duration of the roll-up animation by using the difference between the current visible value + /// and the new final value. /// /// - /// Intended to be used in conjunction with IsRolloverProportional = true. - /// If you're sure your superclass won't never need to be proportional, then it is not necessary to override this function. + /// Intended to be used in conjunction with IsRollingProportional = true. + /// Unless a derived class needs to have a proportional rolling, it is not necessary to override this function. /// /// Current visible value. /// New final value. @@ -178,15 +182,17 @@ namespace osu.Game.Graphics.UserInterface } /// - /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. implement the rollover animation). + /// 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- /// - /// Unless you need to set a custom animation according to the current or new value of the count, the recommended approach is to call - /// transformCount(CustomTransformer(Clock), currentValue, newValue), where CustomTransformer is a custom Transformer related to the - /// type T of the RolloverCounter. - /// By using this approach, there is no need to check if the Clock is not null; this validation is done before adding the transformer. + /// Unless you need to set a custom animation according to the current or new value of the count, the + /// recommended approach is to call transformCount(CustomTransformer(Clock), currentValue, newValue), where + /// CustomTransformer is a custom Transformer related to the type T of the RolloverCounter. + /// By using this approach, there is no need to check if the Clock is not null; this validation is done before + /// adding the transformer. /// protected abstract void transformCount(T currentValue, T newValue); diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 437c4f011f..e0555c952e 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { /// - /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used by osu! standard. + /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard. /// public class StandardComboCounter : ULongCounter { @@ -44,11 +44,6 @@ namespace osu.Game.Graphics.UserInterface }); } - public override void ResetCount() - { - SetCountWithoutRolling(0); - } - protected override void updateTextSize() { base.updateTextSize(); diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs index c01c4208c0..434607be4c 100644 --- a/osu.Game/Graphics/UserInterface/ULongCounter.cs +++ b/osu.Game/Graphics/UserInterface/ULongCounter.cs @@ -14,7 +14,7 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { /// - /// A simple rollover counter that accepts unsigned long values. + /// A simple rolling counter that accepts unsigned long values. /// public class ULongCounter : RollingCounter { From 7277cf5af14013073a27cf12e81f4340d94a7d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Fri, 7 Oct 2016 16:59:52 -0500 Subject: [PATCH 04/26] Reflection to simplify transforms + some refactoring --- .../Graphics/UserInterface/AccuracyCounter.cs | 7 +- .../UserInterface/AlternativeComboCounter.cs | 10 +-- .../UserInterface/CatchComboCounter.cs | 8 +- .../Graphics/UserInterface/RollingCounter.cs | 87 +++++++++++-------- .../UserInterface/StandardComboCounter.cs | 10 +-- .../Graphics/UserInterface/ULongCounter.cs | 9 +- 6 files changed, 72 insertions(+), 59 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs index 2ca6d602c7..d00eda80b2 100644 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs @@ -18,6 +18,8 @@ namespace osu.Game.Graphics.UserInterface /// public class AccuracyCounter : RollingCounter { + protected override Type transformType => typeof(TransformAccuracy); + private long numerator = 0; public long Numerator { @@ -71,11 +73,6 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("0.00") + "%"; } - protected override void transformCount(float currentValue, float newValue) - { - transformCount(new TransformAccuracy(Clock), currentValue, newValue); - } - protected class TransformAccuracy : Transform { public override float CurrentValue diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 5afe23fce7..c361f96644 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -24,7 +24,7 @@ namespace osu.Game.Graphics.UserInterface public EasingTypes TintEasing = EasingTypes.None; public bool CanAnimateWhenBackwards = false; - public AlternativeComboCounter() + public AlternativeComboCounter() : base() { IsRollingContinuous = false; } @@ -46,15 +46,15 @@ namespace osu.Game.Graphics.UserInterface // Animate rollover only when going backwards if (newValue > currentValue) { - updateTransforms(typeof(TranformULongCounter)); - removeTransforms(typeof(TranformULongCounter)); + updateTransforms(typeof(TransformULongCounter)); + removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } else - transformCount(new TranformULongCounter(Clock), currentValue, newValue); + transformCount(new TransformULongCounter(Clock), currentValue, newValue); } - protected override ulong GetProportionalDuration(ulong currentValue, ulong newValue) + protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) { ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; return difference * RollingDuration; diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 6f6d586cb8..fae46de9bf 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface /// public class CatchComboCounter : StandardComboCounter { - public CatchComboCounter() + public CatchComboCounter() : base() { CanPopOutWhenBackwards = true; } @@ -30,15 +30,15 @@ namespace osu.Game.Graphics.UserInterface // Animate rollover only when going backwards if (newValue > currentValue) { - updateTransforms(typeof(TranformULongCounter)); - removeTransforms(typeof(TranformULongCounter)); + updateTransforms(typeof(TransformULongCounter)); + removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } else { // Backwards pop-up animation has no tint colour popOutSpriteText.Colour = countSpriteText.Colour; - transformCount(new TranformULongCounter(Clock), currentValue, newValue); + transformCount(new TransformULongCounter(Clock), currentValue, newValue); } } diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 780c747e96..fa8fb64efa 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,6 +20,14 @@ namespace osu.Game.Graphics.UserInterface /// Type of the actual counter. public abstract class RollingCounter : Container { + /// + /// Type of the Transform to use. + /// + /// + /// Must be a subclass of Transform + /// + protected virtual Type transformType => typeof(Transform); + protected SpriteText countSpriteText; protected ulong RollingTotalDuration = 0; @@ -92,7 +101,7 @@ namespace osu.Game.Graphics.UserInterface { RollingTotalDuration = IsRollingProportional - ? GetProportionalDuration(VisibleCount, value) + ? getProportionalDuration(VisibleCount, value) : RollingDuration; transformCount(IsRollingContinuous ? VisibleCount : count, value); } @@ -100,10 +109,15 @@ namespace osu.Game.Graphics.UserInterface } } + protected RollingCounter() + { + Debug.Assert(transformType.IsSubclassOf(typeof(Transform)), @"transformType should be a subclass of Transform."); + } + public override void Load() { base.Load(); - removeTransforms(typeof(Transform)); + removeTransforms(transformType); if (Count == null) ResetCount(); VisibleCount = Count; @@ -119,32 +133,6 @@ namespace osu.Game.Graphics.UserInterface }; } - /// - /// Calculates the duration of the roll-up animation by using the difference between the current visible value - /// and the new final value. - /// - /// - /// Intended to be used in conjunction with IsRollingProportional = true. - /// Unless a derived class needs to have a proportional rolling, it is not necessary to override this function. - /// - /// Current visible value. - /// New final value. - /// Calculated rollover duration in milliseconds. - protected virtual ulong GetProportionalDuration(T currentValue, T newValue) - { - return RollingDuration; - } - - /// - /// Used to format counts. - /// - /// Count to format. - /// Count formatted as a string. - protected virtual string formatCount(T count) - { - return count.ToString(); - } - /// /// Sets count value, bypassing rollover animation. /// @@ -160,7 +148,7 @@ namespace osu.Game.Graphics.UserInterface /// public virtual void StopRolling() { - removeTransforms(typeof(Transform)); + removeTransforms(transformType); VisibleCount = Count; } @@ -169,16 +157,42 @@ namespace osu.Game.Graphics.UserInterface /// public abstract void ResetCount(); + /// + /// Calculates the duration of the roll-up animation by using the difference between the current visible value + /// and the new final value. + /// + /// + /// To be used in conjunction with IsRollingProportional = true. + /// Unless a derived class needs to have a proportional rolling, it is not necessary to override this function. + /// + /// Current visible value. + /// New final value. + /// Calculated rollover duration in milliseconds. + protected virtual ulong getProportionalDuration(T currentValue, T newValue) + { + return RollingDuration; + } + + /// + /// Used to format counts. + /// + /// Count to format. + /// Count formatted as a string. + protected virtual string formatCount(T count) + { + return count.ToString(); + } + protected void updateTransforms(Type type) { foreach (ITransform t in Transforms.AliveItems) - if (t.GetType().IsAssignableFrom(type)) + if (t.GetType() == type) t.Apply(this); } protected void removeTransforms(Type type) { - Transforms.RemoveAll(t => t.GetType().IsSubclassOf(type)); + Transforms.RemoveAll(t => t.GetType() == type); } /// @@ -190,11 +204,16 @@ namespace osu.Game.Graphics.UserInterface /// /// Unless you need to set a custom animation according to the current or new value of the count, the /// recommended approach is to call transformCount(CustomTransformer(Clock), currentValue, newValue), where - /// CustomTransformer is a custom Transformer related to the type T of the RolloverCounter. + /// CustomTransformer is of type transformerType. /// By using this approach, there is no need to check if the Clock is not null; this validation is done before /// adding the transformer. /// - protected abstract 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); + } /// /// Intended to be used by transformCount(). @@ -239,7 +258,7 @@ namespace osu.Game.Graphics.UserInterface } } - protected virtual void updateTextSize() + protected void updateTextSize() { if (countSpriteText != null) countSpriteText.TextSize = TextSize; diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index e0555c952e..7b8587ac94 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -25,7 +25,7 @@ namespace osu.Game.Graphics.UserInterface public bool CanPopOutWhenBackwards = false; public float PopOutInitialAlpha = 1.0f; - public StandardComboCounter() + public StandardComboCounter() : base() { IsRollingContinuous = false; } @@ -57,15 +57,15 @@ namespace osu.Game.Graphics.UserInterface // Animate rollover only when going backwards if (newValue > currentValue) { - updateTransforms(typeof(TranformULongCounter)); - removeTransforms(typeof(TranformULongCounter)); + updateTransforms(typeof(TransformULongCounter)); + removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } else - transformCount(new TranformULongCounter(Clock), currentValue, newValue); + transformCount(new TransformULongCounter(Clock), currentValue, newValue); } - protected override ulong GetProportionalDuration(ulong currentValue, ulong newValue) + protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) { ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; return difference * RollingDuration; diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs index 434607be4c..ef61cf7879 100644 --- a/osu.Game/Graphics/UserInterface/ULongCounter.cs +++ b/osu.Game/Graphics/UserInterface/ULongCounter.cs @@ -18,10 +18,7 @@ namespace osu.Game.Graphics.UserInterface /// public class ULongCounter : RollingCounter { - protected override void transformCount(ulong currentValue, ulong newValue) - { - transformCount(new TranformULongCounter(Clock), currentValue, newValue); - } + protected override Type transformType => typeof(TransformULongCounter); public override void ResetCount() { @@ -33,7 +30,7 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("#,0"); } - protected class TranformULongCounter : Transform + protected class TransformULongCounter : Transform { public override ulong CurrentValue { @@ -53,7 +50,7 @@ namespace osu.Game.Graphics.UserInterface (d as ULongCounter).VisibleCount = CurrentValue; } - public TranformULongCounter(IClock clock) + public TransformULongCounter(IClock clock) : base(clock) { } From a3b4a34a1addd5782ec1a7c27d6d646dd466b3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Fri, 7 Oct 2016 17:15:36 -0500 Subject: [PATCH 05/26] TestCase buttons + minor fixes --- .../Tests/TestCaseScoreCounter.cs | 77 ++----------------- .../UserInterface/CatchComboCounter.cs | 4 +- .../Graphics/UserInterface/RollingCounter.cs | 2 +- 3 files changed, 11 insertions(+), 72 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index c97fd369ea..eedb0bf5b5 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -24,8 +24,6 @@ namespace osu.Desktop.Tests { base.Reset(); - Random rnd = new Random(); - ScoreCounter uc = new ScoreCounter { Origin = Anchor.TopRight, @@ -89,35 +87,16 @@ namespace osu.Desktop.Tests }; Add(pc); - Button resetButton = new Button - { - Origin = Anchor.TopLeft, - Anchor = Anchor.TopLeft, - Text = @"Reset all", - Width = 100, - Height = 20, - Position = new Vector2(0, 0), - }; - resetButton.Action += delegate + AddButton(@"Reset all", delegate { uc.Count = 0; sc.Count = 0; ac.Count = 0; cc.Count = 0; pc.SetCount(0, 0); - }; - Add(resetButton); + }); - Button hitButton = new Button - { - Origin = Anchor.TopLeft, - Anchor = Anchor.TopLeft, - Text = @"Hit! :D", - Width = 100, - Height = 20, - Position = new Vector2(0, 20), - }; - hitButton.Action += delegate + AddButton(@"Hit! :D", delegate { uc.Count += 300 + (ulong)(300.0 * (sc.Count > 0 ? sc.Count - 1 : 0) / 25.0); sc.Count++; @@ -130,64 +109,24 @@ namespace osu.Desktop.Tests ); pc.Numerator++; pc.Denominator++; - }; - Add(hitButton); + }); - Button missButton = new Button - { - Origin = Anchor.TopLeft, - Anchor = Anchor.TopLeft, - Text = @"miss...", - Width = 100, - Height = 20, - Position = new Vector2(0, 40), - }; - missButton.Action += delegate + AddButton(@"miss...", delegate { sc.Count = 0; ac.Count = 0; cc.Count = 0; pc.Denominator++; - }; - Add(missButton); + }); - Button forceResetButton = new Button - { - Origin = Anchor.TopLeft, - Anchor = Anchor.TopLeft, - Text = @"Force reset", - Width = 100, - Height = 20, - Position = new Vector2(0, 60), - }; - forceResetButton.Action += delegate - { - uc.ResetCount(); - sc.ResetCount(); - ac.ResetCount(); - pc.ResetCount(); - cc.ResetCount(); - }; - Add(forceResetButton); - - Button stopButton = new Button - { - Origin = Anchor.TopLeft, - Anchor = Anchor.TopLeft, - Text = @"STOP!", - Width = 100, - Height = 20, - Position = new Vector2(0, 80), - }; - stopButton.Action += delegate + AddButton(@"Stop counters", delegate { uc.StopRolling(); sc.StopRolling(); cc.StopRolling(); ac.StopRolling(); pc.StopRolling(); - }; - Add(stopButton); + }); } } } diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index fae46de9bf..9fb8caa07a 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -43,9 +43,9 @@ namespace osu.Game.Graphics.UserInterface } /// - /// Tints pop-out before animation. Intended to use the last grabbed fruit colour. + /// Increaces counter and tints pop-out before animation. /// - /// + /// Last grabbed fruit colour. public void CatchFruit(Color4 colour) { popOutSpriteText.Colour = colour; diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index fa8fb64efa..44a160c83e 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -258,7 +258,7 @@ namespace osu.Game.Graphics.UserInterface } } - protected void updateTextSize() + protected virtual void updateTextSize() { if (countSpriteText != null) countSpriteText.TextSize = TextSize; From eb7486f1094e0c75f00f69044181fa2e54f15ea7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 8 Oct 2016 10:26:35 -0400 Subject: [PATCH 06/26] Update osu-framework and specify game name --- osu-framework | 2 +- osu.Desktop.VisualTests/Program.cs | 2 +- osu.Desktop/Program.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu-framework b/osu-framework index 6b884e1b80..a191e86dba 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 6b884e1b80444c5249754634a4b5529c50b52934 +Subproject commit a191e86dbae40c4530ed3ff4b291732696e3a2b0 diff --git a/osu.Desktop.VisualTests/Program.cs b/osu.Desktop.VisualTests/Program.cs index 1cfa440dd9..966b6d00b1 100644 --- a/osu.Desktop.VisualTests/Program.cs +++ b/osu.Desktop.VisualTests/Program.cs @@ -12,7 +12,7 @@ namespace osu.Framework.VisualTests [STAThread] public static void Main(string[] args) { - BasicGameHost host = Host.GetSuitableHost(); + BasicGameHost host = Host.GetSuitableHost(@"visual-tests"); host.Add(new VisualTestGame()); host.Run(); } diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index fe7423924c..1421086054 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -13,7 +13,7 @@ namespace osu.Desktop [STAThread] public static void Main() { - BasicGameHost host = Host.GetSuitableHost(); + BasicGameHost host = Host.GetSuitableHost(@"osu"); host.Add(new OsuGame()); host.Run(); } From 5ebb2fc289320099e966ba6e3daa7ca8e1219c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 8 Oct 2016 19:11:01 -0500 Subject: [PATCH 07/26] Refactor + Stars Counter (initial) Moved a few things to allow using common transforms for a star counter. This implementation is basic and hacky, but good enough as proof of concept. --- .../Tests/TestCaseScoreCounter.cs | 14 +++ .../Graphics/UserInterface/AccuracyCounter.cs | 2 +- .../UserInterface/AlternativeComboCounter.cs | 2 +- .../UserInterface/NumericRollingCounter.cs | 64 ++++++++++ .../Graphics/UserInterface/RollingCounter.cs | 48 ++----- .../Graphics/UserInterface/StarCounter.cs | 119 ++++++++++++++++++ .../Graphics/UserInterface/ULongCounter.cs | 2 +- osu.Game/osu.Game.csproj | 4 +- 8 files changed, 210 insertions(+), 45 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/NumericRollingCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/StarCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index eedb0bf5b5..0587ccea63 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -87,6 +87,14 @@ namespace osu.Desktop.Tests }; Add(pc); + StarCounter tc = new StarCounter + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Position = new Vector2(20, 160), + }; + Add(tc); + AddButton(@"Reset all", delegate { uc.Count = 0; @@ -119,6 +127,11 @@ namespace osu.Desktop.Tests pc.Denominator++; }); + AddButton(@"Alter stars", delegate + { + tc.Count = RNG.NextSingle() * tc.MaxStars; + }); + AddButton(@"Stop counters", delegate { uc.StopRolling(); @@ -126,6 +139,7 @@ namespace osu.Desktop.Tests cc.StopRolling(); ac.StopRolling(); pc.StopRolling(); + tc.StopRolling(); }); } } diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs index d00eda80b2..d13cd20107 100644 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface /// /// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction. /// - public class AccuracyCounter : RollingCounter + public class AccuracyCounter : NumericRollingCounter { protected override Type transformType => typeof(TransformAccuracy); diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index c361f96644..4a343737f1 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -19,7 +19,7 @@ namespace osu.Game.Graphics.UserInterface { public Color4 OriginalColour; public Color4 TintColour = Color4.OrangeRed; - public int TintDuration = 500; + public int TintDuration = 250; public float ScaleFactor = 2; public EasingTypes TintEasing = EasingTypes.None; public bool CanAnimateWhenBackwards = false; diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs new file mode 100644 index 0000000000..22f14838f6 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs @@ -0,0 +1,64 @@ +//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.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(); + } + } + + public override void Load() + { + + base.Load(); + Children = new Drawable[] + { + countSpriteText = new SpriteText + { + Text = formatCount(Count), + TextSize = this.TextSize, + Anchor = this.Anchor, + Origin = this.Origin, + }, + }; + } + + protected override void transformVisibleCount(T currentValue, T newValue) + { + if (countSpriteText != null) + { + countSpriteText.Text = formatCount(newValue); + } + } + + protected virtual void updateTextSize() + { + if (countSpriteText != null) + countSpriteText.TextSize = TextSize; + } + } +} diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 44a160c83e..54d269079d 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -1,9 +1,5 @@ -//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; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; using System; using System.Collections.Generic; @@ -15,8 +11,12 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { /// - /// Skeleton for a counter with a simple roll-up animation. + /// 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 : Container { @@ -28,20 +28,8 @@ namespace osu.Game.Graphics.UserInterface /// protected virtual Type transformType => typeof(Transform); - protected SpriteText countSpriteText; protected ulong RollingTotalDuration = 0; - protected float textSize = 20.0f; - public float TextSize - { - get { return textSize; } - set - { - textSize = value; - updateTextSize(); - } - } - /// /// 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. @@ -121,16 +109,6 @@ namespace osu.Game.Graphics.UserInterface if (Count == null) ResetCount(); VisibleCount = Count; - Children = new Drawable[] - { - countSpriteText = new SpriteText - { - Text = formatCount(Count), - TextSize = this.TextSize, - Anchor = this.Anchor, - Origin = this.Origin, - }, - }; } /// @@ -250,18 +228,6 @@ namespace osu.Game.Graphics.UserInterface /// /// Visible count value before modification. /// Expected visible count value after modification- - protected virtual void transformVisibleCount(T currentValue, T newValue) - { - if (countSpriteText != null) - { - countSpriteText.Text = formatCount(newValue); - } - } - - protected virtual void updateTextSize() - { - if (countSpriteText != null) - countSpriteText.TextSize = TextSize; - } + protected abstract void transformVisibleCount(T currentValue, T newValue); } } diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs new file mode 100644 index 0000000000..a322a5ec36 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -0,0 +1,119 @@ +//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.Containers; +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 +{ + /// + /// Shows a float count as stars. Used as star difficulty display. + /// + public class StarCounter : RollingCounter + { + protected override Type transformType => typeof(TransformStar); + + protected float MinStarSize = 0.001f; + + protected FlowContainer starContainer; + protected List stars = new List(); + + public int MaxStars = 10; + + public StarCounter() : base() + { + RollingDuration = 5000; + } + + public override void ResetCount() + { + Count = 0; + StopRolling(); + } + + public override void Load() + { + base.Load(); + + Children = new Drawable[] + { + starContainer = new FlowContainer + { + Direction = FlowDirection.HorizontalOnly, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + } + }; + + for (int i = 0; i < MaxStars; i++) + { + TextAwesome star = new TextAwesome + { + Icon = FontAwesome.star, + Origin = Anchor.Centre, + TextSize = 20, + }; + stars.Add(star); + starContainer.Add(star); + } + + // HACK: To mantain container height constant + starContainer.Add(new TextAwesome + { + Icon = FontAwesome.star, + Origin = Anchor.Centre, + TextSize = 20, + Alpha = 0.002f, + }); + + ResetCount(); + } + + protected override void transformVisibleCount(float currentValue, float newValue) + { + for (int i = 0; i < MaxStars; i++) + { + if (newValue < i) + stars[i].ScaleTo(MinStarSize); + else if (newValue > (i + 1)) + stars[i].ScaleTo(1f); + else + stars[i].ScaleTo(Interpolation.ValueAt(newValue, MinStarSize, 1f, i, i + 1, EasingTypes.None)); + } + } + + protected class TransformStar : Transform + { + 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); + } + } + + public override void Apply(Drawable d) + { + base.Apply(d); + (d as StarCounter).VisibleCount = CurrentValue; + } + + public TransformStar(IClock clock) + : base(clock) + { + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs index ef61cf7879..35df8f5cc8 100644 --- a/osu.Game/Graphics/UserInterface/ULongCounter.cs +++ b/osu.Game/Graphics/UserInterface/ULongCounter.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface /// /// A simple rolling counter that accepts unsigned long values. /// - public class ULongCounter : RollingCounter + public class ULongCounter : NumericRollingCounter { protected override Type transformType => typeof(TransformULongCounter); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index ae45d04592..127548c519 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -102,15 +102,17 @@ + - + + From 0d18680eeb871c11f62beba4836c670773c769af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 8 Oct 2016 21:45:01 -0500 Subject: [PATCH 08/26] StarCounter styling using absolute positioning. --- .../Graphics/UserInterface/StarCounter.cs | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index a322a5ec36..3e56eb51eb 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -1,6 +1,7 @@ //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; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Transformations; @@ -21,16 +22,28 @@ namespace osu.Game.Graphics.UserInterface { protected override Type transformType => typeof(TransformStar); - protected float MinStarSize = 0.001f; + protected float MinStarSize = 0.3f; - protected FlowContainer starContainer; + protected Container starContainer; protected List stars = new List(); + public float MinStarAlpha = 0.5f; + public int MaxStars = 10; + public int StarSize = 20; + + public int StarSpacing = 2; + public StarCounter() : base() { - RollingDuration = 5000; + IsRollingProportional = true; + RollingDuration = 100; + } + + protected override ulong getProportionalDuration(float currentValue, float newValue) + { + return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration); } public override void ResetCount() @@ -45,11 +58,12 @@ namespace osu.Game.Graphics.UserInterface Children = new Drawable[] { - starContainer = new FlowContainer + starContainer = new Container { - Direction = FlowDirection.HorizontalOnly, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, + Width = MaxStars * StarSize, + Height = StarSize, } }; @@ -58,22 +72,17 @@ namespace osu.Game.Graphics.UserInterface TextAwesome star = new TextAwesome { Icon = FontAwesome.star, + Anchor = Anchor.CentreLeft, Origin = Anchor.Centre, - TextSize = 20, + TextSize = StarSize, + Scale = new Vector2(MinStarSize), + Alpha = MinStarAlpha, + Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0), }; stars.Add(star); starContainer.Add(star); } - // HACK: To mantain container height constant - starContainer.Add(new TextAwesome - { - Icon = FontAwesome.star, - Origin = Anchor.Centre, - TextSize = 20, - Alpha = 0.002f, - }); - ResetCount(); } @@ -82,11 +91,18 @@ namespace osu.Game.Graphics.UserInterface for (int i = 0; i < MaxStars; i++) { if (newValue < i) + { + stars[i].Alpha = MinStarAlpha; stars[i].ScaleTo(MinStarSize); - else if (newValue > (i + 1)) - stars[i].ScaleTo(1f); + } else - stars[i].ScaleTo(Interpolation.ValueAt(newValue, MinStarSize, 1f, i, i + 1, EasingTypes.None)); + { + stars[i].Alpha = 1; + if (newValue > (i + 1)) + stars[i].ScaleTo(1f); + else + stars[i].ScaleTo(Interpolation.ValueAt(newValue, MinStarSize, 1f, i, i + 1, EasingTypes.None)); + } } } From accf365fd1b267966a367603a01e057c9cd2e773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 8 Oct 2016 21:58:53 -0500 Subject: [PATCH 09/26] More styling. --- osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs | 1 + osu.Game/Graphics/UserInterface/NumericRollingCounter.cs | 1 - osu.Game/Graphics/UserInterface/ScoreCounter.cs | 6 ++++++ osu.Game/Graphics/UserInterface/StarCounter.cs | 5 +++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 0587ccea63..36218fa813 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -102,6 +102,7 @@ namespace osu.Desktop.Tests ac.Count = 0; cc.Count = 0; pc.SetCount(0, 0); + tc.Count = 0; }); AddButton(@"Hit! :D", delegate diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs index 22f14838f6..ce0efb6450 100644 --- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs @@ -33,7 +33,6 @@ namespace osu.Game.Graphics.UserInterface public override void Load() { - base.Load(); Children = new Drawable[] { diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index a23e7b5803..cdf22eaea1 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -16,6 +16,12 @@ namespace osu.Game.Graphics.UserInterface /// public uint LeadingZeroes = 0; + public override void Load() + { + base.Load(); + countSpriteText.FixedWidth = true; + } + protected override string formatCount(ulong count) { return count.ToString("D" + LeadingZeroes); diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 3e56eb51eb..13300f1d4b 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -33,12 +33,13 @@ namespace osu.Game.Graphics.UserInterface public int StarSize = 20; - public int StarSpacing = 2; + public int StarSpacing = 4; public StarCounter() : base() { IsRollingProportional = true; - RollingDuration = 100; + RollingDuration = 150; + RollingEasing = EasingTypes.Out; } protected override ulong getProportionalDuration(float currentValue, float newValue) From 67d3d772f61fa3740d84b0780e3efaff7b8b1c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 8 Oct 2016 22:15:25 -0500 Subject: [PATCH 10/26] Minor fix with StarCounter width --- osu.Game/Graphics/UserInterface/StarCounter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 13300f1d4b..5c355d06d6 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -63,7 +63,7 @@ namespace osu.Game.Graphics.UserInterface { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Width = MaxStars * StarSize, + Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing, Height = StarSize, } }; From c997e16cfb2e16a93bc58419f801795779e3c299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 11:55:11 +0200 Subject: [PATCH 11/26] Update Framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index c3a7ebd979..c57055dffe 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit c3a7ebd979c9a6b19871dc84337905f97c56a6aa +Subproject commit c57055dffeb068c701f195602f472cc8626c32a3 From 916bb742da3a3b038b3f223ce7a8ac7ad99ca1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 11:55:38 +0200 Subject: [PATCH 12/26] Don't call Container.Add within KeyCounterCollection.Reset. --- .../Tests/TestCaseKeyCounter.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs index 87642f3004..7be7d24860 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs @@ -19,17 +19,22 @@ namespace osu.Desktop.Tests { base.Reset(); - KeyCounterCollection kc = new KeyCounterCollection + Children = new[] { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - IsCounting = true + new KeyCounterCollection + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + IsCounting = true, + Counters = new KeyCounter[] + { + new KeyCounterKeyboard(@"Z", Key.Z), + new KeyCounterKeyboard(@"X", Key.X), + new KeyCounterMouse(@"M1", MouseButton.Left), + new KeyCounterMouse(@"M2", MouseButton.Right), + }, + }, }; - Add(kc); - kc.AddKey(new KeyCounterKeyboard(@"Z", Key.Z)); - kc.AddKey(new KeyCounterKeyboard(@"X", Key.X)); - kc.AddKey(new KeyCounterMouse(@"M1", MouseButton.Left)); - kc.AddKey(new KeyCounterMouse(@"M2", MouseButton.Right)); } } } From 99c8f618af1c19ef46b03a7ca95e1825ce49c459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 11:55:52 +0200 Subject: [PATCH 13/26] Don't rely on return value of Container.Add. --- osu.Game/GameModes/Menu/ButtonSystem.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/osu.Game/GameModes/Menu/ButtonSystem.cs b/osu.Game/GameModes/Menu/ButtonSystem.cs index 87a78c335d..93701e6c18 100644 --- a/osu.Game/GameModes/Menu/ButtonSystem.cs +++ b/osu.Game/GameModes/Menu/ButtonSystem.cs @@ -113,14 +113,17 @@ namespace osu.Game.GameModes.Menu buttonFlow.Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0); - buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"solo", @"freeplay", FontAwesome.user, new Color4(102, 68, 204, 255), OnSolo, wedge_width, Key.P))); - buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"multi", @"multiplayer", FontAwesome.users, new Color4(94, 63, 186, 255), OnMulti, 0, Key.M))); - buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), OnChart))); + buttonsPlay.Add(new Button(@"solo", @"freeplay", FontAwesome.user, new Color4(102, 68, 204, 255), OnSolo, wedge_width, Key.P)); + buttonsPlay.Add(new Button(@"multi", @"multiplayer", FontAwesome.users, new Color4(94, 63, 186, 255), OnMulti, 0, Key.M)); + buttonsPlay.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), OnChart)); - buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"play", @"play", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), onPlay, wedge_width, Key.P))); - buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), OnEdit, 0, Key.E))); - buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), OnDirect, 0, Key.D))); - buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"exit", @"exit", FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), onExit, 0, Key.Q))); + buttonsTopLevel.Add(new Button(@"play", @"play", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), onPlay, wedge_width, Key.P)); + buttonsTopLevel.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), OnEdit, 0, Key.E)); + buttonsTopLevel.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), OnDirect, 0, Key.D)); + buttonsTopLevel.Add(new Button(@"exit", @"exit", FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), onExit, 0, Key.Q)); + + buttonFlow.Add(buttonsPlay); + buttonFlow.Add(buttonsTopLevel); } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) From d9486e790a1ca77e83d7c3aa6cc4b8b20011d3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 11:56:41 +0200 Subject: [PATCH 14/26] Use AddInternal instead of AddTopLevel. --- osu.Game/GameModes/OsuGameMode.cs | 3 +-- .../Graphics/Containers/ParallaxContainer.cs | 16 ++++++++-------- .../UserInterface/KeyCounterCollection.cs | 15 ++++++++------- osu.Game/OsuGameBase.cs | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/osu.Game/GameModes/OsuGameMode.cs b/osu.Game/GameModes/OsuGameMode.cs index d81d30f0d5..b0928d8214 100644 --- a/osu.Game/GameModes/OsuGameMode.cs +++ b/osu.Game/GameModes/OsuGameMode.cs @@ -41,7 +41,7 @@ namespace osu.Game.GameModes } else if (bg != null) { - AddTopLevel(new ParallaxContainer + AddInternal(new ParallaxContainer { Depth = float.MinValue, Children = new[] @@ -51,7 +51,6 @@ namespace osu.Game.GameModes }); } - base.OnEntering(last); } diff --git a/osu.Game/Graphics/Containers/ParallaxContainer.cs b/osu.Game/Graphics/Containers/ParallaxContainer.cs index 3c6cb18162..183b0c054a 100644 --- a/osu.Game/Graphics/Containers/ParallaxContainer.cs +++ b/osu.Game/Graphics/Containers/ParallaxContainer.cs @@ -14,21 +14,21 @@ namespace osu.Game.Graphics.Containers public ParallaxContainer() { RelativeSizeAxes = Axes.Both; + AddInternal(content = new Container() + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }); } - private Container content = new Container() - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre - }; + private Container content; - protected override Container AddTarget => content; + protected override Container Content => content; public override void Load() { base.Load(); - Add(content); } protected override bool OnMouseMove(InputState state) diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs index 288d1e2018..c9d22d2f06 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -22,18 +22,19 @@ namespace osu.Game.Graphics.UserInterface set { foreach (var k in value) - AddKey(k); + addKey(k); + + Children = value; } } - public void AddKey(KeyCounter key) + private void addKey(KeyCounter key) { counters.Add(key); - key.IsCounting = this.IsCounting; - key.FadeTime = this.FadeTime; - key.KeyDownTextColor = this.KeyDownTextColor; - key.KeyUpTextColor = this.KeyUpTextColor; - base.Add(key); + key.IsCounting = IsCounting; + key.FadeTime = FadeTime; + key.KeyDownTextColor = KeyDownTextColor; + key.KeyUpTextColor = KeyUpTextColor; } public void ResetCount() diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 0f0a9116a0..bd3990d5ef 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -21,7 +21,7 @@ namespace osu.Game public Options Options; public APIAccess API; - protected override Container AddTarget => ratioContainer?.IsLoaded == true ? ratioContainer : base.AddTarget; + protected override Container Content => ratioContainer?.IsLoaded == true ? ratioContainer : base.Content; private RatioAdjust ratioContainer; From 934523e347044f1478b82687d7ac82e358bfae19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 13:31:16 +0200 Subject: [PATCH 15/26] Update framework version. --- osu-framework | 2 +- osu.Game/OsuGame.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu-framework b/osu-framework index c57055dffe..1f770847b2 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit c57055dffeb068c701f195602f472cc8626c32a3 +Subproject commit 1f770847b245e6d250e63e60c24e9e84131d15e7 diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index a524a4f925..fd0c92eabe 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -49,7 +49,7 @@ namespace osu.Game OnHome = delegate { MainMenu?.MakeCurrent(); }, OnSettings = delegate { Options.PoppedOut = !Options.PoppedOut; }, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, - Alpha = 0.001f //fixes invalidation fuckup + Alpha = 0.001f, }, new VolumeControl { From 9ed0748d73e4fe4ea92e4c4ad5e7dee64074a3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 15:40:32 +0200 Subject: [PATCH 16/26] No need to enforce scheduling of task anymore. --- osu-framework | 2 +- osu.Game/GameModes/Menu/Intro.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu-framework b/osu-framework index 1f770847b2..3f66bf6f8e 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 1f770847b245e6d250e63e60c24e9e84131d15e7 +Subproject commit 3f66bf6f8e2ef8c4970f9ddf81b97748d5423e19 diff --git a/osu.Game/GameModes/Menu/Intro.cs b/osu.Game/GameModes/Menu/Intro.cs index 78e0d15b0e..e70b2639cf 100644 --- a/osu.Game/GameModes/Menu/Intro.cs +++ b/osu.Game/GameModes/Menu/Intro.cs @@ -47,8 +47,7 @@ namespace osu.Game.GameModes.Menu Scheduler.Add(delegate { welcome.Play(); - }, true); - + }); Scheduler.AddDelayed(delegate { From 5861e782e5c9af96287b171aae354ccf6999942d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sun, 9 Oct 2016 16:02:25 +0200 Subject: [PATCH 17/26] Update Framework version. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 3f66bf6f8e..aaa35586b9 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3f66bf6f8e2ef8c4970f9ddf81b97748d5423e19 +Subproject commit aaa35586b9e3243f90d17657c91a0371296483e3 From 707effb591edb33cbef8d1e2c45a1c00c55b0722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 9 Oct 2016 14:02:44 -0500 Subject: [PATCH 18/26] Completed StarCounter More complex than the other counters, but hopefully functional. I subestimated you and your silly bouncing animations. >.> --- .../Tests/TestCaseScoreCounter.cs | 12 ++ .../Graphics/UserInterface/RollingCounter.cs | 10 +- .../Graphics/UserInterface/StarCounter.cs | 106 +++++++++++++----- 3 files changed, 97 insertions(+), 31 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 36218fa813..2ad177a6be 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.Transformations; using OpenTK; using OpenTK.Graphics; using osu.Framework.MathUtils; +using osu.Framework.Graphics.Sprites; namespace osu.Desktop.Tests { @@ -87,6 +88,15 @@ namespace osu.Desktop.Tests }; Add(pc); + SpriteText text = new SpriteText + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Position = new Vector2(20, 190), + Text = @"- unset -", + }; + Add(text); + StarCounter tc = new StarCounter { Origin = Anchor.BottomLeft, @@ -103,6 +113,7 @@ namespace osu.Desktop.Tests cc.Count = 0; pc.SetCount(0, 0); tc.Count = 0; + text.Text = tc.Count.ToString("0.00"); }); AddButton(@"Hit! :D", delegate @@ -131,6 +142,7 @@ namespace osu.Desktop.Tests AddButton(@"Alter stars", delegate { tc.Count = RNG.NextSingle() * tc.MaxStars; + text.Text = tc.Count.ToString("0.00"); }); AddButton(@"Stop counters", delegate diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 54d269079d..1c7d024d85 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -52,6 +52,7 @@ namespace osu.Game.Graphics.UserInterface /// public EasingTypes RollingEasing = EasingTypes.None; + protected T prevVisibleCount; protected T visibleCount; /// @@ -65,13 +66,15 @@ namespace osu.Game.Graphics.UserInterface } protected set { + prevVisibleCount = visibleCount; if (visibleCount.Equals(value)) return; - transformVisibleCount(visibleCount, value); visibleCount = value; + transformVisibleCount(prevVisibleCount, value); } } + protected T prevCount; protected T count; /// @@ -85,6 +88,8 @@ namespace osu.Game.Graphics.UserInterface } set { + prevCount = count; + count = value; if (Clock != null) { RollingTotalDuration = @@ -93,13 +98,12 @@ namespace osu.Game.Graphics.UserInterface : RollingDuration; transformCount(IsRollingContinuous ? VisibleCount : count, value); } - count = value; } } protected RollingCounter() { - Debug.Assert(transformType.IsSubclassOf(typeof(Transform)), @"transformType should be a subclass of Transform."); + Debug.Assert(transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), @"transformType should be a subclass of Transform."); } public override void Load() diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 5c355d06d6..d4eeb202fb 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -9,6 +9,7 @@ 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; @@ -20,26 +21,23 @@ namespace osu.Game.Graphics.UserInterface /// public class StarCounter : RollingCounter { - protected override Type transformType => typeof(TransformStar); - - protected float MinStarSize = 0.3f; + protected override Type transformType => typeof(TransformStarCounter); protected Container starContainer; protected List stars = new List(); + public ulong StarAnimationDuration = 500; + public ulong FadeDuration = 100; + public float MinStarSize = 0.3f; public float MinStarAlpha = 0.5f; - public int MaxStars = 10; - public int StarSize = 20; - public int StarSpacing = 4; public StarCounter() : base() { IsRollingProportional = true; RollingDuration = 150; - RollingEasing = EasingTypes.Out; } protected override ulong getProportionalDuration(float currentValue, float newValue) @@ -77,7 +75,7 @@ namespace osu.Game.Graphics.UserInterface Origin = Anchor.Centre, TextSize = StarSize, Scale = new Vector2(MinStarSize), - Alpha = MinStarAlpha, + Alpha = (i == 0) ? 1.0f : MinStarAlpha, Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0), }; stars.Add(star); @@ -87,27 +85,79 @@ namespace osu.Game.Graphics.UserInterface ResetCount(); } - protected override void transformVisibleCount(float currentValue, float newValue) + protected override void transformCount(float currentValue, float newValue) { - for (int i = 0; i < MaxStars; i++) - { - if (newValue < i) - { - stars[i].Alpha = MinStarAlpha; - stars[i].ScaleTo(MinStarSize); - } - else - { - stars[i].Alpha = 1; - if (newValue > (i + 1)) - stars[i].ScaleTo(1f); - else - stars[i].ScaleTo(Interpolation.ValueAt(newValue, MinStarSize, 1f, i, i + 1, EasingTypes.None)); - } - } + transformStar((int)Math.Floor(currentValue), currentValue < newValue); + transformCount(new TransformStarCounter(Clock), currentValue, newValue); } - protected class TransformStar : Transform + protected void updateTransformStar(int i) + { + foreach (ITransform t in stars[i].Transforms.AliveItems) + if (t.GetType() == typeof(TransformAlpha) || t.GetType() == typeof(TransformScaleVector)) + t.Apply(stars[i]); + + 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((isIncrement ? Math.Min(i + 1, Count) : Math.Max(i, Count)), MinStarSize, 1.0f, i, i + 1)); + transform.Easing = EasingTypes.OutElasticHalf; + + stars[i].Transforms.Add(transform); + } + + protected void transformStarAlpha(int i, TransformAlpha transform, bool isIncrement, double startTime) + { + transform.StartTime = startTime; + //if (!isIncrement) + //transform.StartTime += StarAnimationDuration - FadeDuration; + 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, bool isIncrement) + { + 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, VisibleCount) : getProportionalDuration(i, VisibleCount); + // If decrementing, animation should had started when VisibleCount crossed end of star (i + 1) + else + startTime -= i == (int)Math.Floor(prevCount) ? getProportionalDuration(prevCount, VisibleCount) : getProportionalDuration(i + 1, VisibleCount); + + 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, 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, false); + } + + protected class TransformStarCounter : Transform { public override float CurrentValue { @@ -127,8 +177,8 @@ namespace osu.Game.Graphics.UserInterface (d as StarCounter).VisibleCount = CurrentValue; } - public TransformStar(IClock clock) - : base(clock) + public TransformStarCounter(IClock clock) + : base(clock) { } } From 841707b61f7798b49dc9defb5e30389d81fd0864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 9 Oct 2016 14:09:07 -0500 Subject: [PATCH 19/26] Not animate stars over MaxStars --- osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs | 2 +- osu.Game/Graphics/UserInterface/StarCounter.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 2ad177a6be..144adf9098 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -141,7 +141,7 @@ namespace osu.Desktop.Tests AddButton(@"Alter stars", delegate { - tc.Count = RNG.NextSingle() * tc.MaxStars; + tc.Count = RNG.NextSingle() * (tc.MaxStars + 1); text.Text = tc.Count.ToString("0.00"); }); diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index d4eeb202fb..b4576e6104 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -126,6 +126,9 @@ namespace osu.Game.Graphics.UserInterface protected void transformStar(int i, bool isIncrement) { + if (i >= MaxStars) + return; + if (Clock == null) return; From 01da3ca4748ba65f2b29c248a08039053e064332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 9 Oct 2016 14:48:24 -0500 Subject: [PATCH 20/26] More line wrapping --- .../Graphics/UserInterface/RollingCounter.cs | 9 ++++++--- .../Graphics/UserInterface/StarCounter.cs | 20 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 1c7d024d85..6b6c82b76b 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -42,8 +42,8 @@ namespace osu.Game.Graphics.UserInterface public bool IsRollingProportional = false; /// - /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each element. - /// If IsRollingProportional = true, duration in milliseconds for the counter roll-up animation in total. + /// 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; @@ -103,7 +103,10 @@ namespace osu.Game.Graphics.UserInterface protected RollingCounter() { - Debug.Assert(transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), @"transformType should be a subclass of Transform."); + Debug.Assert( + transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), + @"transformType should be a subclass of Transform." + ); } public override void Load() diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index b4576e6104..dad3bbd05a 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -97,7 +97,9 @@ namespace osu.Game.Graphics.UserInterface if (t.GetType() == typeof(TransformAlpha) || t.GetType() == typeof(TransformScaleVector)) t.Apply(stars[i]); - stars[i].Transforms.RemoveAll(t => t.GetType() == typeof(TransformScaleVector) || t.GetType() == typeof(TransformAlpha)); + stars[i].Transforms.RemoveAll(t => + t.GetType() == typeof(TransformScaleVector) || t.GetType() == typeof(TransformAlpha) + ); } protected void transformStarScale(int i, TransformScaleVector transform, bool isIncrement, double startTime) @@ -105,7 +107,15 @@ namespace osu.Game.Graphics.UserInterface transform.StartTime = startTime; transform.EndTime = transform.StartTime + StarAnimationDuration; transform.StartValue = stars[i].Scale; - transform.EndValue = new Vector2(Interpolation.ValueAt((isIncrement ? Math.Min(i + 1, Count) : Math.Max(i, Count)), MinStarSize, 1.0f, i, i + 1)); + transform.EndValue = new Vector2( + Interpolation.ValueAt( + (isIncrement ? Math.Min(i + 1, Count) : Math.Max(i, Count)), + MinStarSize, + 1.0f, + i, + i + 1 + ) + ); transform.Easing = EasingTypes.OutElasticHalf; stars[i].Transforms.Add(transform); @@ -136,10 +146,12 @@ namespace osu.Game.Graphics.UserInterface 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, VisibleCount) : getProportionalDuration(i, VisibleCount); + startTime -= i == (int)Math.Floor(prevCount) ? + getProportionalDuration(prevCount, VisibleCount) : getProportionalDuration(i, VisibleCount); // If decrementing, animation should had started when VisibleCount crossed end of star (i + 1) else - startTime -= i == (int)Math.Floor(prevCount) ? getProportionalDuration(prevCount, VisibleCount) : getProportionalDuration(i + 1, VisibleCount); + startTime -= i == (int)Math.Floor(prevCount) ? + getProportionalDuration(prevCount, VisibleCount) : getProportionalDuration(i + 1, VisibleCount); updateTransformStar(i); From fd1cbfd8fa851a0838e5dc82210347a0a312eaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 9 Oct 2016 14:53:06 -0500 Subject: [PATCH 21/26] Hide VisibleCount from transformStar --- osu.Game/Graphics/UserInterface/StarCounter.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index dad3bbd05a..523527dcce 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -87,7 +87,7 @@ namespace osu.Game.Graphics.UserInterface protected override void transformCount(float currentValue, float newValue) { - transformStar((int)Math.Floor(currentValue), currentValue < newValue); + transformStar((int)Math.Floor(currentValue), currentValue, currentValue < newValue); transformCount(new TransformStarCounter(Clock), currentValue, newValue); } @@ -134,7 +134,7 @@ namespace osu.Game.Graphics.UserInterface } - protected void transformStar(int i, bool isIncrement) + protected void transformStar(int i, float value, bool isIncrement) { if (i >= MaxStars) return; @@ -147,11 +147,11 @@ namespace osu.Game.Graphics.UserInterface // If incrementing, animation should had started when VisibleCount crossed start of star (i) if (isIncrement) startTime -= i == (int)Math.Floor(prevCount) ? - getProportionalDuration(prevCount, VisibleCount) : getProportionalDuration(i, VisibleCount); + 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, VisibleCount) : getProportionalDuration(i + 1, VisibleCount); + getProportionalDuration(prevCount, value) : getProportionalDuration(i + 1, value); updateTransformStar(i); @@ -164,12 +164,12 @@ namespace osu.Game.Graphics.UserInterface // 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, true); + 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, false); + transformStar(i, newValue, false); } protected class TransformStarCounter : Transform From 4d0c8ed441cae1f4b4132b9c359c9307292e4b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 9 Oct 2016 14:55:50 -0500 Subject: [PATCH 22/26] StarAnimationEasing --- osu.Game/Graphics/UserInterface/StarCounter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 523527dcce..67f2a2ae0c 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -27,6 +27,7 @@ namespace osu.Game.Graphics.UserInterface protected List stars = new List(); public ulong StarAnimationDuration = 500; + public EasingTypes StarAnimationEasing = EasingTypes.OutElasticHalf; public ulong FadeDuration = 100; public float MinStarSize = 0.3f; public float MinStarAlpha = 0.5f; @@ -116,7 +117,7 @@ namespace osu.Game.Graphics.UserInterface i + 1 ) ); - transform.Easing = EasingTypes.OutElasticHalf; + transform.Easing = StarAnimationEasing; stars[i].Transforms.Add(transform); } From 2954c1934519990f296d30130ac9ad185a1188ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 9 Oct 2016 15:19:35 -0500 Subject: [PATCH 23/26] Misc. fixes --- osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs | 2 +- osu.Game/Graphics/UserInterface/RollingCounter.cs | 2 +- osu.Game/Graphics/UserInterface/StandardComboCounter.cs | 2 +- osu.Game/Graphics/UserInterface/StarCounter.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 4a343737f1..8c5510eca4 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -62,7 +62,7 @@ namespace osu.Game.Graphics.UserInterface protected virtual void transformAnimate() { - countSpriteText.Colour = TintColour; + countSpriteText.FadeColour(TintColour, 0); countSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); countSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing); countSpriteText.ScaleTo(new Vector2(1, 1), TintDuration, TintEasing); diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 6b6c82b76b..b0f757a378 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -96,7 +96,7 @@ namespace osu.Game.Graphics.UserInterface IsRollingProportional ? getProportionalDuration(VisibleCount, value) : RollingDuration; - transformCount(IsRollingContinuous ? VisibleCount : count, value); + transformCount(IsRollingContinuous ? VisibleCount : prevCount, value); } } } diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 7b8587ac94..b3af78b78e 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -23,7 +23,7 @@ namespace osu.Game.Graphics.UserInterface public float PopOutSmallScale = 1.2f; public EasingTypes PopOutEasing = EasingTypes.None; public bool CanPopOutWhenBackwards = false; - public float PopOutInitialAlpha = 1.0f; + public float PopOutInitialAlpha = 0.75f; public StandardComboCounter() : base() { diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 67f2a2ae0c..3ee67a38d6 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -110,7 +110,7 @@ namespace osu.Game.Graphics.UserInterface transform.StartValue = stars[i].Scale; transform.EndValue = new Vector2( Interpolation.ValueAt( - (isIncrement ? Math.Min(i + 1, Count) : Math.Max(i, Count)), + Math.Min(Math.Max(i, Count), i + 1), MinStarSize, 1.0f, i, From 0b08c8ba15052a42e887d8dc6395ad05a744b85a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 10 Oct 2016 14:18:06 +0900 Subject: [PATCH 24/26] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index aaa35586b9..19252f6177 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit aaa35586b9e3243f90d17657c91a0371296483e3 +Subproject commit 19252f6177622908cfbbf3caed7ceca42e5832d6 From 3f83ffcb996083e49576145416dc431133e55919 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 10 Oct 2016 14:36:27 +0900 Subject: [PATCH 25/26] Bring framework up-to-date with upstream master. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index a191e86dba..857a472d57 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit a191e86dbae40c4530ed3ff4b291732696e3a2b0 +Subproject commit 857a472d570227937de549d50fa8bd672022afbf From 4ac2c9ad901eeee08b4568d721f1b7b439a0a143 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 10 Oct 2016 15:12:21 +0900 Subject: [PATCH 26/26] Update framework to fix draw order. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 857a472d57..c610557427 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 857a472d570227937de549d50fa8bd672022afbf +Subproject commit c6105574275ac3bed45a45feb77b34bedda925a8