From 798e7241d837e6e6d08bd779bf3d5de706d5e6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 14:33:04 -0500 Subject: [PATCH 01/30] Make counters work again --- .../Graphics/UserInterface/NumericRollingCounter.cs | 13 +++++++++---- osu.Game/Graphics/UserInterface/RollingCounter.cs | 8 +++++--- osu.Game/Graphics/UserInterface/ScoreCounter.cs | 7 +++++-- osu.Game/Graphics/UserInterface/StarCounter.cs | 2 -- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs index e1cb9ddbb4..1710ce9515 100644 --- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs @@ -32,15 +32,12 @@ namespace osu.Game.Graphics.UserInterface } } - public override void Load(BaseGame game) + protected NumericRollingCounter() : base() { - base.Load(game); - Children = new Drawable[] { countSpriteText = new SpriteText { - Text = formatCount(Count), TextSize = this.TextSize, Anchor = this.Anchor, Origin = this.Origin, @@ -48,6 +45,14 @@ namespace osu.Game.Graphics.UserInterface }; } + public override void Load(BaseGame game) + { + base.Load(game); + countSpriteText.Text = formatCount(count); + countSpriteText.Anchor = this.Anchor; + countSpriteText.Origin = this.Origin; + } + protected override void transformVisibleCount(T currentValue, T newValue) { if (countSpriteText != null) diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index b0686ca0cb..b26c810497 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -19,7 +19,7 @@ namespace osu.Game.Graphics.UserInterface /// 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 + public abstract class RollingCounter : AutoSizeContainer { /// /// Type of the Transform to use. @@ -91,7 +91,7 @@ namespace osu.Game.Graphics.UserInterface { prevCount = count; count = value; - if (Clock != null) + if (IsLoaded) { RollingTotalDuration = IsRollingProportional @@ -102,7 +102,7 @@ namespace osu.Game.Graphics.UserInterface } } - protected RollingCounter() + protected RollingCounter() : base() { Debug.Assert( transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), @@ -113,7 +113,9 @@ namespace osu.Game.Graphics.UserInterface public override void Load(BaseGame game) { base.Load(game); + removeTransforms(transformType); + if (Count == null) ResetCount(); VisibleCount = Count; diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index d5b9edf73d..802d2b9883 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -17,11 +17,14 @@ namespace osu.Game.Graphics.UserInterface /// public uint LeadingZeroes = 0; + public ScoreCounter() : base() + { + countSpriteText.FixedWidth = true; + } + public override void Load(BaseGame game) { base.Load(game); - - countSpriteText.FixedWidth = true; } protected override string formatCount(ulong count) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 790e0ddcc8..a8eb18b565 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -128,8 +128,6 @@ namespace osu.Game.Graphics.UserInterface 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; From 11e0429fd3f037186fe47df46f680078babb33a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 14:38:48 -0500 Subject: [PATCH 02/30] Children creation off-load to ctors --- .../UserInterface/NumericRollingCounter.cs | 8 +--- .../UserInterface/StandardComboCounter.cs | 48 ++++++++++--------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs index 1710ce9515..aa9aee3919 100644 --- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs @@ -55,16 +55,12 @@ namespace osu.Game.Graphics.UserInterface protected override void transformVisibleCount(T currentValue, T newValue) { - if (countSpriteText != null) - { - countSpriteText.Text = formatCount(newValue); - } + countSpriteText.Text = formatCount(newValue); } protected virtual void updateTextSize() { - if (countSpriteText != null) - countSpriteText.TextSize = TextSize; + countSpriteText.TextSize = TextSize; } } } diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 676e3672d2..f4f36f1e21 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -29,28 +29,33 @@ namespace osu.Game.Graphics.UserInterface public StandardComboCounter() : base() { IsRollingContinuous = false; + + countSpriteText.Alpha = 0; + + popOutSpriteText = new SpriteText + { + Origin = this.Origin, + Anchor = this.Anchor, + TextSize = this.TextSize, + Alpha = 0, + }; } public override void Load(BaseGame game) { base.Load(game); - countSpriteText.Alpha = 0; - Add(popOutSpriteText = new SpriteText - { - Text = formatCount(Count), - Origin = this.Origin, - Anchor = this.Anchor, - TextSize = this.TextSize, - Alpha = 0, - }); + popOutSpriteText.Origin = this.Origin; + popOutSpriteText.Anchor = this.Anchor; + + Add(popOutSpriteText); } protected override void updateTextSize() { base.updateTextSize(); - if (popOutSpriteText != null) - popOutSpriteText.TextSize = this.TextSize; + + popOutSpriteText.TextSize = this.TextSize; } @@ -91,19 +96,16 @@ namespace osu.Game.Graphics.UserInterface protected override void transformVisibleCount(ulong currentValue, ulong newValue) { - if (countSpriteText != null && popOutSpriteText != null) + countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue); + if (newValue == 0) { - countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue); - if (newValue == 0) - { - countSpriteText.FadeOut(PopOutDuration); - } - else - { - countSpriteText.Show(); - if (newValue > currentValue || CanPopOutWhenBackwards) - transformPopOut(); - } + countSpriteText.FadeOut(PopOutDuration); + } + else + { + countSpriteText.Show(); + if (newValue > currentValue || CanPopOutWhenBackwards) + transformPopOut(); } } } From fa67ab86edf7d44878d15452c56f6e278517f500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 15:28:24 -0500 Subject: [PATCH 03/30] Adjusted Combo Counter animation --- .../Tests/TestCaseScoreCounter.cs | 5 +- .../UserInterface/StandardComboCounter.cs | 55 ++++++++++++++++--- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 144adf9098..5f381da0b9 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -43,9 +43,10 @@ namespace osu.Desktop.Tests Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Position = new Vector2(20, 20), + InnerCountPosition = new Vector2(10, 10), IsRollingProportional = true, RollingDuration = 20, - PopOutDuration = 250, + PopOutDuration = 3000, Count = 0, TextSize = 40, }; @@ -57,7 +58,7 @@ namespace osu.Desktop.Tests Anchor = Anchor.Centre, IsRollingProportional = true, RollingDuration = 20, - PopOutDuration = 250, + PopOutDuration = 100, Count = 0, TextSize = 40, }; diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index f4f36f1e21..bfb8031ef3 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -1,9 +1,12 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK; using osu.Framework; +using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; +using osu.Framework.Timing; using System; using System.Collections.Generic; using System.Linq; @@ -21,11 +24,23 @@ namespace osu.Game.Graphics.UserInterface public ulong PopOutDuration = 0; public float PopOutBigScale = 2.0f; - public float PopOutSmallScale = 1.2f; + public float PopOutSmallScale = 1.1f; public EasingTypes PopOutEasing = EasingTypes.None; public bool CanPopOutWhenBackwards = false; public float PopOutInitialAlpha = 0.75f; + public Vector2 InnerCountPosition + { + get + { + return countSpriteText.Position; + } + set + { + countSpriteText.Position = value; + } + } + public StandardComboCounter() : base() { IsRollingContinuous = false; @@ -58,7 +73,6 @@ namespace osu.Game.Graphics.UserInterface popOutSpriteText.TextSize = this.TextSize; } - protected override void transformCount(ulong currentValue, ulong newValue) { // Animate rollover only when going backwards @@ -83,20 +97,45 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("#,0") + "x"; } - protected virtual void transformPopOut() + protected virtual void transformPopOut(ulong newValue) { - countSpriteText.ScaleTo(PopOutSmallScale); - countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); - popOutSpriteText.ScaleTo(PopOutBigScale); popOutSpriteText.FadeTo(PopOutInitialAlpha); + popOutSpriteText.Position = Vector2.Zero; + popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); + popOutSpriteText.MoveTo(countSpriteText.Position, PopOutDuration, PopOutEasing); + + Scheduler.AddDelayed(delegate + { + transformPopOutNew(newValue); + }, PopOutDuration); + } + + protected virtual void transformPopOutNew(ulong newValue) + { + // Too late; scheduled task invalidated + if (newValue != VisibleCount) + return; + + countSpriteText.Text = formatCount(newValue); + countSpriteText.ScaleTo(PopOutSmallScale); + countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } protected override void transformVisibleCount(ulong currentValue, ulong newValue) { - countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue); + popOutSpriteText.Text = formatCount(newValue); + if (newValue > currentValue) + { + countSpriteText.Text = formatCount(newValue - 1); + + } + else + { + countSpriteText.Text = formatCount(newValue); + } if (newValue == 0) { countSpriteText.FadeOut(PopOutDuration); @@ -105,7 +144,7 @@ namespace osu.Game.Graphics.UserInterface { countSpriteText.Show(); if (newValue > currentValue || CanPopOutWhenBackwards) - transformPopOut(); + transformPopOut(newValue); } } } From e9a38f0c4d21585074973e8509a3abb2bd95675a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 17:24:06 -0500 Subject: [PATCH 04/30] Fixed some animations --- .../Tests/TestCaseScoreCounter.cs | 4 +- .../UserInterface/AlternativeComboCounter.cs | 25 ++++---- .../UserInterface/CatchComboCounter.cs | 2 +- .../UserInterface/StandardComboCounter.cs | 60 +++++++++++-------- 4 files changed, 47 insertions(+), 44 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 5f381da0b9..bea2639512 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -42,11 +42,11 @@ namespace osu.Desktop.Tests { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 20), + Position = new Vector2(10, 10), InnerCountPosition = new Vector2(10, 10), IsRollingProportional = true, RollingDuration = 20, - PopOutDuration = 3000, + PopOutDuration = 100, Count = 0, TextSize = 40, }; diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 9b710174ea..ba41854255 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -52,7 +52,7 @@ namespace osu.Game.Graphics.UserInterface removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } - else + else if (currentValue != 0) transformCount(new TransformULongCounter(Clock), currentValue, newValue); } @@ -62,7 +62,7 @@ namespace osu.Game.Graphics.UserInterface return difference * RollingDuration; } - protected virtual void transformAnimate() + protected virtual void transformAnimate(ulong newValue) { countSpriteText.FadeColour(TintColour, 0); countSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); @@ -72,20 +72,15 @@ namespace osu.Game.Graphics.UserInterface protected override void transformVisibleCount(ulong currentValue, ulong newValue) { - if (countSpriteText != null) - { - countSpriteText.Text = newValue.ToString("#,0"); - if (newValue == 0) - { - countSpriteText.FadeOut(TintDuration); - return; - } + countSpriteText.Text = formatCount(newValue); + + if (newValue == 0) + countSpriteText.FadeOut(TintDuration); + else countSpriteText.Show(); - if (newValue > currentValue || CanAnimateWhenBackwards) - { - transformAnimate(); - } - } + + if (newValue > currentValue || CanAnimateWhenBackwards) + transformAnimate(newValue); } } } diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 9fb8caa07a..96249be355 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -34,7 +34,7 @@ namespace osu.Game.Graphics.UserInterface removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } - else + else if (currentValue != 0) { // Backwards pop-up animation has no tint colour popOutSpriteText.Colour = countSpriteText.Colour; diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index bfb8031ef3..b22fda1070 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -20,7 +20,9 @@ namespace osu.Game.Graphics.UserInterface /// public class StandardComboCounter : ULongCounter { - public SpriteText popOutSpriteText; + protected SpriteText popOutSpriteText; + + protected volatile int scheduledPopOutCurrentId = 0; public ulong PopOutDuration = 0; public float PopOutBigScale = 2.0f; @@ -82,7 +84,7 @@ namespace osu.Game.Graphics.UserInterface removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } - else + else if (currentValue != 0) transformCount(new TransformULongCounter(Clock), currentValue, newValue); } @@ -97,55 +99,61 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("#,0") + "x"; } - protected virtual void transformPopOut(ulong newValue) + protected virtual void transformPopOut(ulong currentValue, ulong newValue) { + popOutSpriteText.Text = formatCount(newValue); + countSpriteText.Text = formatCount(currentValue); + popOutSpriteText.ScaleTo(PopOutBigScale); popOutSpriteText.FadeTo(PopOutInitialAlpha); - popOutSpriteText.Position = Vector2.Zero; + popOutSpriteText.MoveTo(Vector2.Zero); popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); popOutSpriteText.MoveTo(countSpriteText.Position, PopOutDuration, PopOutEasing); + scheduledPopOutCurrentId++; + int newTaskId = scheduledPopOutCurrentId; Scheduler.AddDelayed(delegate { - transformPopOutNew(newValue); + scheduledPopOutSmall(newTaskId, newValue); }, PopOutDuration); } - protected virtual void transformPopOutNew(ulong newValue) - { - // Too late; scheduled task invalidated - if (newValue != VisibleCount) - return; + protected virtual void transformNoPopOut(ulong newValue) + { + scheduledPopOutCurrentId++; + countSpriteText.Text = formatCount(newValue); + countSpriteText.ScaleTo(1); + } + protected virtual void transformPopOutSmall(ulong newValue) + { countSpriteText.Text = formatCount(newValue); countSpriteText.ScaleTo(PopOutSmallScale); countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } + protected virtual void scheduledPopOutSmall(int id, ulong newValue) + { + // Too late; scheduled task invalidated + if (id != scheduledPopOutCurrentId) + return; + + transformPopOutSmall(newValue); + } + protected override void transformVisibleCount(ulong currentValue, ulong newValue) { - popOutSpriteText.Text = formatCount(newValue); - if (newValue > currentValue) - { - countSpriteText.Text = formatCount(newValue - 1); - - } - else - { - countSpriteText.Text = formatCount(newValue); - } if (newValue == 0) - { countSpriteText.FadeOut(PopOutDuration); - } else - { countSpriteText.Show(); - if (newValue > currentValue || CanPopOutWhenBackwards) - transformPopOut(newValue); - } + + if (newValue > currentValue || CanPopOutWhenBackwards) + transformPopOut(currentValue, newValue); + else + transformNoPopOut(newValue); } } } From 73e4359e9d0799243e93a5b0c367d6e2995488e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 20:51:50 -0500 Subject: [PATCH 05/30] Adjusted StarCounter ctor --- .../Graphics/UserInterface/StarCounter.cs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index a8eb18b565..4f038764e7 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -27,19 +27,35 @@ namespace osu.Game.Graphics.UserInterface protected Container starContainer; protected List stars = new List(); + public int MaxStars + { + get; + protected set; + } + public ulong StarAnimationDuration = 500; public EasingTypes StarAnimationEasing = EasingTypes.OutElasticHalf; 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() + public StarCounter(int stars = 10) : base() { IsRollingProportional = true; RollingDuration = 150; + + MaxStars = stars; + + Children = new Drawable[] + { + starContainer = new Container + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + } + }; } protected override ulong getProportionalDuration(float currentValue, float newValue) @@ -57,16 +73,8 @@ namespace osu.Game.Graphics.UserInterface { base.Load(game); - Children = new Drawable[] - { - starContainer = new Container - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing, - Height = StarSize, - } - }; + starContainer.Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing; + starContainer.Height = StarSize; for (int i = 0; i < MaxStars; i++) { From 71d7de5326ebe5105ea0d684c7171bf4d7bc349f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 20:57:06 -0500 Subject: [PATCH 06/30] Leading zeroes now part of ScoreCounter ctor --- .../Tests/TestCaseScoreCounter.cs | 3 +-- .../Graphics/UserInterface/ScoreCounter.cs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index bea2639512..0dcf289e39 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -25,7 +25,7 @@ namespace osu.Desktop.Tests { base.Reset(); - ScoreCounter uc = new ScoreCounter + ScoreCounter uc = new ScoreCounter(7) { Origin = Anchor.TopRight, Anchor = Anchor.TopRight, @@ -34,7 +34,6 @@ namespace osu.Desktop.Tests RollingEasing = EasingTypes.Out, Count = 0, Position = new Vector2(20, 20), - LeadingZeroes = 7, }; Add(uc); diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index 802d2b9883..1fce361a0e 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -13,13 +13,22 @@ namespace osu.Game.Graphics.UserInterface public class ScoreCounter : ULongCounter { /// - /// How many leading zeroes the counter will have. + /// How many leading zeroes the counter has. /// - public uint LeadingZeroes = 0; - - public ScoreCounter() : base() + public uint LeadingZeroes { - countSpriteText.FixedWidth = true; + get; + protected set; + } + + /// + /// Displays score. + /// + /// How many leading zeroes the counter will have. + public ScoreCounter(uint leading = 0) : base() + { + countSpriteText.FixedWidth = true; + LeadingZeroes = leading; } public override void Load(BaseGame game) From cd7884f00e9a7a512525d5a890f44c7854bc0740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 20:58:43 -0500 Subject: [PATCH 07/30] More descriptive var names in test --- .../Tests/TestCaseScoreCounter.cs | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 0dcf289e39..ef6752b7a4 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -25,7 +25,7 @@ namespace osu.Desktop.Tests { base.Reset(); - ScoreCounter uc = new ScoreCounter(7) + ScoreCounter score = new ScoreCounter(7) { Origin = Anchor.TopRight, Anchor = Anchor.TopRight, @@ -35,9 +35,9 @@ namespace osu.Desktop.Tests Count = 0, Position = new Vector2(20, 20), }; - Add(uc); + Add(score); - StandardComboCounter sc = new StandardComboCounter + StandardComboCounter standardCombo = new StandardComboCounter { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, @@ -49,9 +49,9 @@ namespace osu.Desktop.Tests Count = 0, TextSize = 40, }; - Add(sc); + Add(standardCombo); - CatchComboCounter cc = new CatchComboCounter + CatchComboCounter catchCombo = new CatchComboCounter { Origin = Anchor.Centre, Anchor = Anchor.Centre, @@ -61,9 +61,9 @@ namespace osu.Desktop.Tests Count = 0, TextSize = 40, }; - Add(cc); + Add(catchCombo); - AlternativeComboCounter ac = new AlternativeComboCounter + AlternativeComboCounter alternativeCombo = new AlternativeComboCounter { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, @@ -74,10 +74,10 @@ namespace osu.Desktop.Tests Count = 0, TextSize = 40, }; - Add(ac); + Add(alternativeCombo); - AccuracyCounter pc = new AccuracyCounter + AccuracyCounter accuracyCombo = new AccuracyCounter { Origin = Anchor.TopRight, Anchor = Anchor.TopRight, @@ -86,73 +86,73 @@ namespace osu.Desktop.Tests Count = 100.0f, Position = new Vector2(20, 60), }; - Add(pc); + Add(accuracyCombo); - SpriteText text = new SpriteText + SpriteText starsLabel = new SpriteText { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Position = new Vector2(20, 190), Text = @"- unset -", }; - Add(text); + Add(starsLabel); - StarCounter tc = new StarCounter + StarCounter stars = new StarCounter { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Position = new Vector2(20, 160), }; - Add(tc); + Add(stars); AddButton(@"Reset all", delegate { - uc.Count = 0; - sc.Count = 0; - ac.Count = 0; - cc.Count = 0; - pc.SetCount(0, 0); - tc.Count = 0; - text.Text = tc.Count.ToString("0.00"); + score.Count = 0; + standardCombo.Count = 0; + alternativeCombo.Count = 0; + catchCombo.Count = 0; + accuracyCombo.SetCount(0, 0); + stars.Count = 0; + starsLabel.Text = stars.Count.ToString("0.00"); }); AddButton(@"Hit! :D", delegate { - uc.Count += 300 + (ulong)(300.0 * (sc.Count > 0 ? sc.Count - 1 : 0) / 25.0); - sc.Count++; - ac.Count++; - cc.CatchFruit(new Color4( + score.Count += 300 + (ulong)(300.0 * (standardCombo.Count > 0 ? standardCombo.Count - 1 : 0) / 25.0); + standardCombo.Count++; + alternativeCombo.Count++; + catchCombo.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++; + accuracyCombo.Numerator++; + accuracyCombo.Denominator++; }); AddButton(@"miss...", delegate { - sc.Count = 0; - ac.Count = 0; - cc.Count = 0; - pc.Denominator++; + standardCombo.Count = 0; + alternativeCombo.Count = 0; + catchCombo.Count = 0; + accuracyCombo.Denominator++; }); AddButton(@"Alter stars", delegate { - tc.Count = RNG.NextSingle() * (tc.MaxStars + 1); - text.Text = tc.Count.ToString("0.00"); + stars.Count = RNG.NextSingle() * (stars.MaxStars + 1); + starsLabel.Text = stars.Count.ToString("0.00"); }); AddButton(@"Stop counters", delegate { - uc.StopRolling(); - sc.StopRolling(); - cc.StopRolling(); - ac.StopRolling(); - pc.StopRolling(); - tc.StopRolling(); + score.StopRolling(); + standardCombo.StopRolling(); + catchCombo.StopRolling(); + alternativeCombo.StopRolling(); + accuracyCombo.StopRolling(); + stars.StopRolling(); }); } } From bf832ebe71932fa404bbf38b3b6df855c1a02e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 21:03:41 -0500 Subject: [PATCH 08/30] uint for ids --- osu.Game/Graphics/UserInterface/StandardComboCounter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index b22fda1070..36afcea79c 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -22,7 +22,7 @@ namespace osu.Game.Graphics.UserInterface { protected SpriteText popOutSpriteText; - protected volatile int scheduledPopOutCurrentId = 0; + protected uint scheduledPopOutCurrentId = 0; public ulong PopOutDuration = 0; public float PopOutBigScale = 2.0f; @@ -84,6 +84,7 @@ namespace osu.Game.Graphics.UserInterface removeTransforms(typeof(TransformULongCounter)); VisibleCount = newValue; } + // Also, ignore rollback if already rollbacking else if (currentValue != 0) transformCount(new TransformULongCounter(Clock), currentValue, newValue); } @@ -113,7 +114,7 @@ namespace osu.Game.Graphics.UserInterface popOutSpriteText.MoveTo(countSpriteText.Position, PopOutDuration, PopOutEasing); scheduledPopOutCurrentId++; - int newTaskId = scheduledPopOutCurrentId; + uint newTaskId = scheduledPopOutCurrentId; Scheduler.AddDelayed(delegate { scheduledPopOutSmall(newTaskId, newValue); @@ -134,7 +135,7 @@ namespace osu.Game.Graphics.UserInterface countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } - protected virtual void scheduledPopOutSmall(int id, ulong newValue) + protected virtual void scheduledPopOutSmall(uint id, ulong newValue) { // Too late; scheduled task invalidated if (id != scheduledPopOutCurrentId) From 55420d43569a72e77d28cc28a858b959b26684e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 21:33:55 -0500 Subject: [PATCH 09/30] Improvements in transformCount handling --- .../UserInterface/AlternativeComboCounter.cs | 12 +++++++--- .../UserInterface/CatchComboCounter.cs | 23 +++++++++++++++++++ .../Graphics/UserInterface/RollingCounter.cs | 17 +++++++++++++- .../UserInterface/StandardComboCounter.cs | 13 +++++++---- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index ba41854255..13dc146a55 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -43,17 +43,23 @@ namespace osu.Game.Graphics.UserInterface SetCountWithoutRolling(0); } - protected override void transformCount(ulong currentValue, ulong newValue) + protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) { // Animate rollover only when going backwards if (newValue > currentValue) { updateTransforms(typeof(TransformULongCounter)); removeTransforms(typeof(TransformULongCounter)); + + // If was decreasing, stops roll before increasing + if (currentValue < prevValue) + VisibleCount = currentValue; + VisibleCount = newValue; } - else if (currentValue != 0) - transformCount(new TransformULongCounter(Clock), currentValue, newValue); + // Also, animate only if was not rollbacking already + else if (currentValue > prevValue) + transformCount(new TransformULongCounter(Clock), visibleValue, newValue); } protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 96249be355..6f85df9c75 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -25,6 +25,29 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("#,0"); } + protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) + { + // Animate rollover only when going backwards + if (newValue > currentValue) + { + updateTransforms(typeof(TransformULongCounter)); + removeTransforms(typeof(TransformULongCounter)); + + // If was decreasing, stops roll before increasing + if (currentValue < prevValue) + VisibleCount = currentValue; + + VisibleCount = newValue; + } + // Also, animate only if was not rollbacking already + else if (currentValue > prevValue) + { + // Backwards pop-up animation has no tint colour + popOutSpriteText.Colour = countSpriteText.Colour; + transformCount(new TransformULongCounter(Clock), visibleValue, newValue); + } + } + protected override void transformCount(ulong currentValue, ulong newValue) { // Animate rollover only when going backwards diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index b26c810497..18826506ca 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -75,6 +75,7 @@ namespace osu.Game.Graphics.UserInterface } } + protected T prevPrevCount; protected T prevCount; protected T count; @@ -89,6 +90,7 @@ namespace osu.Game.Graphics.UserInterface } set { + prevPrevCount = prevCount; prevCount = count; count = value; if (IsLoaded) @@ -97,7 +99,7 @@ namespace osu.Game.Graphics.UserInterface IsRollingProportional ? getProportionalDuration(VisibleCount, value) : RollingDuration; - transformCount(IsRollingContinuous ? VisibleCount : prevCount, value); + transformCount(visibleCount, prevPrevCount, prevCount, value); } } } @@ -183,6 +185,19 @@ namespace osu.Game.Graphics.UserInterface Transforms.RemoveAll(t => t.GetType() == type); } + /// + /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. + /// implement the rollover animation). + /// + /// Count value currently visible to user. + /// Count value before previous modification. + /// Count value before modification. + /// Expected count value after modification. + protected virtual void transformCount(T visibleValue, T prevValue, T currentValue, T newValue) + { + transformCount(IsRollingContinuous ? visibleValue : currentValue, newValue); + } + /// /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. /// implement the rollover animation). diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 36afcea79c..8632535728 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -75,18 +75,23 @@ namespace osu.Game.Graphics.UserInterface popOutSpriteText.TextSize = this.TextSize; } - protected override void transformCount(ulong currentValue, ulong newValue) + protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) { // Animate rollover only when going backwards if (newValue > currentValue) { updateTransforms(typeof(TransformULongCounter)); removeTransforms(typeof(TransformULongCounter)); + + // If was decreasing, stops roll before increasing + if (currentValue < prevValue) + VisibleCount = currentValue; + VisibleCount = newValue; } - // Also, ignore rollback if already rollbacking - else if (currentValue != 0) - transformCount(new TransformULongCounter(Clock), currentValue, newValue); + // Also, animate only if was not rollbacking already + else if (currentValue > prevValue) + transformCount(new TransformULongCounter(Clock), visibleValue, newValue); } protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) From 8f0093f1338656182d81f7a8e14089ccf9c9df4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 21:36:52 -0500 Subject: [PATCH 10/30] Comments in StarCounter --- osu.Game/Graphics/UserInterface/StarCounter.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 4f038764e7..9335e31142 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -17,9 +17,6 @@ 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(TransformStarCounter); @@ -27,6 +24,12 @@ namespace osu.Game.Graphics.UserInterface protected Container starContainer; protected List stars = new List(); + /// + /// Maximum amount of stars displayed. + /// + /// + /// This does not limit the counter value, but the amount of stars displayed. + /// public int MaxStars { get; @@ -41,6 +44,10 @@ namespace osu.Game.Graphics.UserInterface public int StarSize = 20; public int StarSpacing = 4; + /// + /// Shows a float count as stars. Used as star difficulty display. + /// + /// Maximum amount of stars to display. public StarCounter(int stars = 10) : base() { IsRollingProportional = true; From 1d8d2fa9c90f5da232d843c09a3bafde598a6603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Wed, 12 Oct 2016 21:46:51 -0500 Subject: [PATCH 11/30] Implicit base() --- osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs | 2 +- osu.Game/Graphics/UserInterface/CatchComboCounter.cs | 2 +- osu.Game/Graphics/UserInterface/NumericRollingCounter.cs | 2 +- osu.Game/Graphics/UserInterface/RollingCounter.cs | 2 +- osu.Game/Graphics/UserInterface/ScoreCounter.cs | 2 +- osu.Game/Graphics/UserInterface/StandardComboCounter.cs | 2 +- osu.Game/Graphics/UserInterface/StarCounter.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 13dc146a55..2fa82d9db3 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -25,7 +25,7 @@ namespace osu.Game.Graphics.UserInterface public EasingTypes TintEasing = EasingTypes.None; public bool CanAnimateWhenBackwards = false; - public AlternativeComboCounter() : base() + public AlternativeComboCounter() { IsRollingContinuous = false; } diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 6f85df9c75..8fe7ba3404 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() : base() + public CatchComboCounter() { CanPopOutWhenBackwards = true; } diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs index aa9aee3919..03b9804e01 100644 --- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs @@ -32,7 +32,7 @@ namespace osu.Game.Graphics.UserInterface } } - protected NumericRollingCounter() : base() + protected NumericRollingCounter() { Children = new Drawable[] { diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 18826506ca..251ea7dd92 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -104,7 +104,7 @@ namespace osu.Game.Graphics.UserInterface } } - protected RollingCounter() : base() + protected RollingCounter() { Debug.Assert( transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index 1fce361a0e..faba550bb0 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -25,7 +25,7 @@ namespace osu.Game.Graphics.UserInterface /// Displays score. /// /// How many leading zeroes the counter will have. - public ScoreCounter(uint leading = 0) : base() + public ScoreCounter(uint leading = 0) { countSpriteText.FixedWidth = true; LeadingZeroes = leading; diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 8632535728..838db7525f 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -43,7 +43,7 @@ namespace osu.Game.Graphics.UserInterface } } - public StandardComboCounter() : base() + public StandardComboCounter() { IsRollingContinuous = false; diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 9335e31142..2a9eb47031 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -48,7 +48,7 @@ namespace osu.Game.Graphics.UserInterface /// Shows a float count as stars. Used as star difficulty display. /// /// Maximum amount of stars to display. - public StarCounter(int stars = 10) : base() + public StarCounter(int stars = 10) { IsRollingProportional = true; RollingDuration = 150; From ce07a45456c48d20b8e31f90e16f4f56e9775b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 13 Oct 2016 17:13:20 -0500 Subject: [PATCH 12/30] Improved code --- .../Tests/TestCaseScoreCounter.cs | 10 +- .../Graphics/UserInterface/AccuracyCounter.cs | 20 +- .../UserInterface/AlternativeComboCounter.cs | 27 +- .../UserInterface/CatchComboCounter.cs | 44 +-- .../Graphics/UserInterface/ComboCounter.cs | 273 ++++++++++++++++++ .../UserInterface/NumericRollingCounter.cs | 66 ----- .../Graphics/UserInterface/RollingCounter.cs | 93 +++--- .../Graphics/UserInterface/ScoreCounter.cs | 39 ++- .../UserInterface/StandardComboCounter.cs | 39 +-- .../Graphics/UserInterface/StarCounter.cs | 233 +++++++-------- .../Graphics/UserInterface/ULongCounter.cs | 59 ---- osu.Game/osu.Game.csproj | 5 +- 12 files changed, 487 insertions(+), 421 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/ComboCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/NumericRollingCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/ULongCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index ef6752b7a4..1e824cf33b 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -81,7 +81,7 @@ namespace osu.Desktop.Tests { Origin = Anchor.TopRight, Anchor = Anchor.TopRight, - RollingDuration = 1000, + RollingDuration = 500, RollingEasing = EasingTypes.Out, Count = 100.0f, Position = new Vector2(20, 60), @@ -133,9 +133,9 @@ namespace osu.Desktop.Tests AddButton(@"miss...", delegate { - standardCombo.Count = 0; - alternativeCombo.Count = 0; - catchCombo.Count = 0; + standardCombo.RollBack(); + alternativeCombo.RollBack(); + catchCombo.RollBack(); accuracyCombo.Denominator++; }); @@ -152,7 +152,7 @@ namespace osu.Desktop.Tests catchCombo.StopRolling(); alternativeCombo.StopRolling(); accuracyCombo.StopRolling(); - stars.StopRolling(); + stars.StopAnimation(); }); } } diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs index d13cd20107..32df57d1f0 100644 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs @@ -3,7 +3,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; -using osu.Framework.MathUtils; using osu.Framework.Timing; using System; using System.Collections.Generic; @@ -16,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface /// /// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction. /// - public class AccuracyCounter : NumericRollingCounter + public class AccuracyCounter : RollingCounter { protected override Type transformType => typeof(TransformAccuracy); @@ -73,20 +72,13 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("0.00") + "%"; } - protected class TransformAccuracy : Transform + protected override ulong getProportionalDuration(float currentValue, float newValue) { - public override float CurrentValue - { - get - { - double time = Time; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } + return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration); + } + protected class TransformAccuracy : TransformFloat + { public override void Apply(Drawable d) { base.Apply(d); diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 2fa82d9db3..27541c12a3 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface /// /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania. /// - public class AlternativeComboCounter : ULongCounter // btw, I'm terribly bad with names... OUENDAN! + public class AlternativeComboCounter : ComboCounter { public Color4 OriginalColour; public Color4 TintColour = Color4.OrangeRed; @@ -25,16 +25,10 @@ namespace osu.Game.Graphics.UserInterface public EasingTypes TintEasing = EasingTypes.None; public bool CanAnimateWhenBackwards = false; - public AlternativeComboCounter() - { - IsRollingContinuous = false; - } - public override void Load(BaseGame game) { base.Load(game); - countSpriteText.Hide(); OriginalColour = Colour; } @@ -43,25 +37,6 @@ namespace osu.Game.Graphics.UserInterface SetCountWithoutRolling(0); } - protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) - { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); - - // If was decreasing, stops roll before increasing - if (currentValue < prevValue) - VisibleCount = currentValue; - - VisibleCount = newValue; - } - // Also, animate only if was not rollbacking already - else if (currentValue > prevValue) - transformCount(new TransformULongCounter(Clock), visibleValue, newValue); - } - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) { ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 8fe7ba3404..8200ddaa04 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -25,44 +25,11 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("#,0"); } - protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) + public override void RollBack(ulong newValue = 0) { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); + popOutSpriteText.Colour = countSpriteText.Colour; - // If was decreasing, stops roll before increasing - if (currentValue < prevValue) - VisibleCount = currentValue; - - VisibleCount = newValue; - } - // Also, animate only if was not rollbacking already - else if (currentValue > prevValue) - { - // Backwards pop-up animation has no tint colour - popOutSpriteText.Colour = countSpriteText.Colour; - transformCount(new TransformULongCounter(Clock), visibleValue, newValue); - } - } - - protected override void transformCount(ulong currentValue, ulong newValue) - { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); - VisibleCount = newValue; - } - else if (currentValue != 0) - { - // Backwards pop-up animation has no tint colour - popOutSpriteText.Colour = countSpriteText.Colour; - transformCount(new TransformULongCounter(Clock), currentValue, newValue); - } + base.RollBack(newValue); } /// @@ -74,10 +41,5 @@ namespace osu.Game.Graphics.UserInterface popOutSpriteText.Colour = colour; Count++; } - - public override void ResetCount() - { - base.ResetCount(); - } } } diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/Graphics/UserInterface/ComboCounter.cs new file mode 100644 index 0000000000..07c957257c --- /dev/null +++ b/osu.Game/Graphics/UserInterface/ComboCounter.cs @@ -0,0 +1,273 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Framework.MathUtils; +using osu.Framework.Timing; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Graphics.UserInterface +{ + public abstract class ComboCounter : AutoSizeContainer + { + protected Type transformType => typeof(TransformCombo); + + private bool rollbacking = false; + + protected ulong rollingTotalDuration = 0; + + /// + /// If true, the roll-down duration will be proportional to the counter. + /// + public bool IsRollingProportional = true; + + /// + /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each + /// element; else duration in milliseconds for the counter roll-up animation in total. + /// + public ulong RollingDuration = 0; + + /// + /// Easing for the counter rollover animation. + /// + public EasingTypes RollingEasing = EasingTypes.None; + + protected ulong prevVisibleCount; + protected ulong visibleCount; + + /// + /// Value shown at the current moment. + /// + public virtual ulong VisibleCount + { + get + { + return visibleCount; + } + protected set + { + if (visibleCount.Equals(value)) + return; + prevVisibleCount = visibleCount; + visibleCount = value; + transformVisibleCount(prevVisibleCount, visibleCount); + } + } + + protected ulong prevPrevCount; + protected ulong prevCount; + protected ulong count; + + /// + /// Actual value of counter. + /// + public virtual ulong Count + { + get + { + return count; + } + set + { + prevPrevCount = prevCount; + prevCount = count; + count = value; + if (IsLoaded) + { + rollingTotalDuration = + IsRollingProportional + ? getProportionalDuration(VisibleCount, value) + : RollingDuration; + transformCount(VisibleCount, prevPrevCount, prevCount, value); + } + } + } + + protected SpriteText countSpriteText; + + protected float textSize = 20.0f; + public float TextSize + { + get { return textSize; } + set + { + textSize = value; + updateTextSize(); + } + } + + /// + /// Base of all combo counters. + /// + protected ComboCounter() + { + Children = new Drawable[] + { + countSpriteText = new SpriteText + { + Anchor = this.Anchor, + Origin = this.Origin, + Alpha = 0, + }, + }; + } + + public override void Load(BaseGame game) + { + base.Load(game); + + countSpriteText.Anchor = this.Anchor; + countSpriteText.Origin = this.Origin; + + StopRolling(); + } + + /// + /// Sets count value, bypassing rollover animation. + /// + /// New count value. + public virtual void SetCountWithoutRolling(ulong count) + { + Count = count; + StopRolling(); + } + + /// + /// Stops rollover animation, forcing the visible count to be the actual count. + /// + public virtual void StopRolling() + { + removeComboTransforms(); + VisibleCount = Count; + } + + /// + /// Animates roll-back to an specific value. + /// + /// Target value. + public virtual void RollBack(ulong newValue = 0) + { + rollbacking = true; + Count = newValue; + rollbacking = false; + } + + /// + /// Resets count to default value. + /// + public virtual void ResetCount() + { + SetCountWithoutRolling(default(ulong)); + } + + protected virtual ulong getProportionalDuration(ulong currentValue, ulong newValue) + { + return currentValue > newValue ? currentValue - newValue : newValue - currentValue; + } + + protected abstract void transformVisibleCount(ulong currentValue, ulong newValue); + + protected virtual string formatCount(ulong count) + { + return count.ToString(); + } + + private void updateComboTransforms() + { + foreach (ITransform t in Transforms.AliveItems) + if (t.GetType() == typeof(TransformCombo)) + t.Apply(this); + } + + private void removeComboTransforms() + { + Transforms.RemoveAll(t => t.GetType() == typeof(TransformCombo)); + } + + protected virtual void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) + { + if (!rollbacking) + { + updateComboTransforms(); + removeComboTransforms(); + + // If was decreasing, stops roll before increasing + if (currentValue < prevValue) + VisibleCount = currentValue; + + VisibleCount = newValue; + } + else + { + transformCount(new TransformCombo(Clock), visibleValue, newValue); + } + } + + /// + /// Intended to be used by transformCount(). + /// + /// + protected void transformCount(TransformCombo transform, ulong currentValue, ulong newValue) + { + updateComboTransforms(); + removeComboTransforms(); + + if (Clock == null) + return; + + if (RollingDuration == 0) + { + VisibleCount = Count; + return; + } + + transform.StartTime = Time; + transform.EndTime = Time + rollingTotalDuration; + transform.StartValue = currentValue; + transform.EndValue = newValue; + transform.Easing = RollingEasing; + + Transforms.Add(transform); + } + + protected virtual void updateTextSize() + { + countSpriteText.TextSize = TextSize; + } + + protected class TransformCombo : Transform + { + public override ulong CurrentValue + { + get + { + double time = Time; + if (time < StartTime) return StartValue; + if (time >= EndTime) return EndValue; + + return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + } + } + + public override void Apply(Drawable d) + { + base.Apply(d); + (d as ComboCounter).VisibleCount = CurrentValue; + } + + public TransformCombo(IClock clock) + : base(clock) + { + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs b/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs deleted file mode 100644 index 03b9804e01..0000000000 --- a/osu.Game/Graphics/UserInterface/NumericRollingCounter.cs +++ /dev/null @@ -1,66 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Skeleton for a numeric counter with a simple roll-up animation. - /// - /// Type of the actual counter. - public abstract class NumericRollingCounter : RollingCounter - { - protected SpriteText countSpriteText; - - protected float textSize = 20.0f; - public float TextSize - { - get { return textSize; } - set - { - textSize = value; - updateTextSize(); - } - } - - protected NumericRollingCounter() - { - Children = new Drawable[] - { - countSpriteText = new SpriteText - { - TextSize = this.TextSize, - Anchor = this.Anchor, - Origin = this.Origin, - }, - }; - } - - public override void Load(BaseGame game) - { - base.Load(game); - countSpriteText.Text = formatCount(count); - countSpriteText.Anchor = this.Anchor; - countSpriteText.Origin = this.Origin; - } - - protected override void transformVisibleCount(T currentValue, T newValue) - { - countSpriteText.Text = formatCount(newValue); - } - - protected virtual void updateTextSize() - { - countSpriteText.TextSize = TextSize; - } - } -} diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 251ea7dd92..4b7d115ceb 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -1,6 +1,10 @@ -using osu.Framework; +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; using System; using System.Collections.Generic; @@ -11,14 +15,6 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { - /// - /// Skeleton for a counter which value rolls-up in a lapse of time. - /// - /// - /// This class only abstracts the basics to roll-up a value in a lapse of time by using Transforms. - /// In order to show a value, you must implement a way to display it, i.e., as a numeric counter or a bar. - /// - /// Type of the actual counter. public abstract class RollingCounter : AutoSizeContainer { /// @@ -29,13 +25,9 @@ namespace osu.Game.Graphics.UserInterface /// protected virtual Type transformType => typeof(Transform); - protected ulong RollingTotalDuration = 0; + protected ulong rollingTotalDuration = 0; - /// - /// If true, each time the Count is updated, it will roll over from the current visible value. - /// Else, it will roll up from the current count value. - /// - public bool IsRollingContinuous = true; + protected SpriteText countSpriteText; /// /// If true, the roll-up duration will be proportional to the counter. @@ -67,15 +59,13 @@ namespace osu.Game.Graphics.UserInterface } protected set { - prevVisibleCount = visibleCount; if (visibleCount.Equals(value)) return; visibleCount = value; - transformVisibleCount(prevVisibleCount, value); + countSpriteText.Text = formatCount(value); } } - protected T prevPrevCount; protected T prevCount; protected T count; @@ -90,26 +80,49 @@ namespace osu.Game.Graphics.UserInterface } set { - prevPrevCount = prevCount; prevCount = count; count = value; if (IsLoaded) { - RollingTotalDuration = + rollingTotalDuration = IsRollingProportional - ? getProportionalDuration(VisibleCount, value) + ? getProportionalDuration(visibleCount, value) : RollingDuration; - transformCount(visibleCount, prevPrevCount, prevCount, value); + transformCount(visibleCount, count); } } } + protected float textSize = 20.0f; + + public float TextSize + { + get { return textSize; } + set + { + textSize = value; + countSpriteText.TextSize = value; + } + } + + /// + /// Skeleton of a numeric counter which value rolls over time. + /// protected RollingCounter() { Debug.Assert( transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), @"transformType should be a subclass of Transform." ); + + Children = new Drawable[] + { + countSpriteText = new SpriteText + { + Anchor = this.Anchor, + Origin = this.Origin, + }, + }; } public override void Load(BaseGame game) @@ -117,10 +130,12 @@ namespace osu.Game.Graphics.UserInterface base.Load(game); removeTransforms(transformType); - - if (Count == null) - ResetCount(); + VisibleCount = Count; + + countSpriteText.Text = formatCount(count); + countSpriteText.Anchor = this.Anchor; + countSpriteText.Origin = this.Origin; } /// @@ -145,7 +160,10 @@ namespace osu.Game.Graphics.UserInterface /// /// Resets count to default value. /// - public abstract void ResetCount(); + public virtual void ResetCount() + { + SetCountWithoutRolling(default(T)); + } /// /// Calculates the duration of the roll-up animation by using the difference between the current visible value @@ -185,19 +203,6 @@ namespace osu.Game.Graphics.UserInterface Transforms.RemoveAll(t => t.GetType() == type); } - /// - /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. - /// implement the rollover animation). - /// - /// Count value currently visible to user. - /// Count value before previous modification. - /// Count value before modification. - /// Expected count value after modification. - protected virtual void transformCount(T visibleValue, T prevValue, T currentValue, T newValue) - { - transformCount(IsRollingContinuous ? visibleValue : currentValue, newValue); - } - /// /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. /// implement the rollover animation). @@ -239,20 +244,12 @@ namespace osu.Game.Graphics.UserInterface } transform.StartTime = Time; - transform.EndTime = Time + RollingTotalDuration; + transform.EndTime = Time + rollingTotalDuration; transform.StartValue = currentValue; transform.EndValue = newValue; transform.Easing = RollingEasing; Transforms.Add(transform); } - - /// - /// This procedure is called each time the visible count value is updated. - /// Override to create custom animations. - /// - /// Visible count value before modification. - /// Expected visible count value after modification- - protected abstract void transformVisibleCount(T currentValue, T newValue); } } diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index faba550bb0..a22a403115 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -2,6 +2,10 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transformations; +using osu.Framework.MathUtils; +using osu.Framework.Timing; using System; using System.Collections.Generic; using System.Linq; @@ -10,8 +14,10 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { - public class ScoreCounter : ULongCounter + public class ScoreCounter : RollingCounter { + protected override Type transformType => typeof(TransformScore); + /// /// How many leading zeroes the counter has. /// @@ -36,9 +42,40 @@ namespace osu.Game.Graphics.UserInterface base.Load(game); } + protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) + { + return currentValue > newValue ? currentValue - newValue : newValue - currentValue; + } + protected override string formatCount(ulong count) { return count.ToString("D" + LeadingZeroes); } + + protected class TransformScore : Transform + { + public override ulong CurrentValue + { + get + { + double time = Time; + if (time < StartTime) return StartValue; + if (time >= EndTime) return EndValue; + + return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + } + } + + public override void Apply(Drawable d) + { + base.Apply(d); + (d as ScoreCounter).VisibleCount = CurrentValue; + } + + public TransformScore(IClock clock) + : base(clock) + { + } + } } } diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 838db7525f..3053542741 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -18,7 +18,7 @@ namespace osu.Game.Graphics.UserInterface /// /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard. /// - public class StandardComboCounter : ULongCounter + public class StandardComboCounter : ComboCounter { protected SpriteText popOutSpriteText; @@ -45,10 +45,6 @@ namespace osu.Game.Graphics.UserInterface public StandardComboCounter() { - IsRollingContinuous = false; - - countSpriteText.Alpha = 0; - popOutSpriteText = new SpriteText { Origin = this.Origin, @@ -68,32 +64,6 @@ namespace osu.Game.Graphics.UserInterface Add(popOutSpriteText); } - protected override void updateTextSize() - { - base.updateTextSize(); - - popOutSpriteText.TextSize = this.TextSize; - } - - protected override void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) - { - // Animate rollover only when going backwards - if (newValue > currentValue) - { - updateTransforms(typeof(TransformULongCounter)); - removeTransforms(typeof(TransformULongCounter)); - - // If was decreasing, stops roll before increasing - if (currentValue < prevValue) - VisibleCount = currentValue; - - VisibleCount = newValue; - } - // Also, animate only if was not rollbacking already - else if (currentValue > prevValue) - transformCount(new TransformULongCounter(Clock), visibleValue, newValue); - } - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) { ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; @@ -161,5 +131,12 @@ namespace osu.Game.Graphics.UserInterface else transformNoPopOut(newValue); } + + protected override void updateTextSize() + { + base.updateTextSize(); + + popOutSpriteText.TextSize = this.TextSize; + } } } diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 2a9eb47031..d83a1cf28f 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -10,19 +10,18 @@ using osu.Framework.MathUtils; using osu.Framework.Timing; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { - public class StarCounter : RollingCounter + public class StarCounter : AutoSizeContainer { - protected override Type transformType => typeof(TransformStarCounter); + private Container starContainer; + private List stars = new List(); - protected Container starContainer; - protected List stars = new List(); + private double transformStartTime = 0; /// /// Maximum amount of stars displayed. @@ -36,13 +35,52 @@ namespace osu.Game.Graphics.UserInterface protected set; } - public ulong StarAnimationDuration = 500; - public EasingTypes StarAnimationEasing = EasingTypes.OutElasticHalf; - public ulong FadeDuration = 100; - public float MinStarSize = 0.3f; + public double AnimationDelay = 150; + + public double ScalingDuration = 500; + public EasingTypes ScalingEasing = EasingTypes.OutElasticHalf; + public float MinStarScale = 0.3f; + + public double FadingDuration = 100; public float MinStarAlpha = 0.5f; - public int StarSize = 20; - public int StarSpacing = 4; + + public float StarSize = 20; + public float StarSpacing = 4; + + public float VisibleValue + { + get + { + double elapsedTime = Time - transformStartTime; + double expectedElapsedTime = Math.Abs(prevCount - count) * AnimationDelay; + if (elapsedTime >= expectedElapsedTime) + return count; + return Interpolation.ValueAt(elapsedTime, prevCount, count, 0, expectedElapsedTime); + } + } + + private float prevCount; + private float count; + + /// + /// Amount of stars represented. + /// + public float Count + { + get + { + return count; + } + set + { + prevCount = VisibleValue; + count = value; + if (IsLoaded) + { + transformCount(prevCount, count); + } + } + } /// /// Shows a float count as stars. Used as star difficulty display. @@ -50,10 +88,7 @@ namespace osu.Game.Graphics.UserInterface /// Maximum amount of stars to display. public StarCounter(int stars = 10) { - IsRollingProportional = true; - RollingDuration = 150; - - MaxStars = stars; + MaxStars = Math.Max(stars, 0); Children = new Drawable[] { @@ -65,17 +100,6 @@ namespace osu.Game.Graphics.UserInterface }; } - protected override ulong getProportionalDuration(float currentValue, float newValue) - { - return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration); - } - - public override void ResetCount() - { - Count = 0; - StopRolling(); - } - public override void Load(BaseGame game) { base.Load(game); @@ -91,8 +115,6 @@ namespace osu.Game.Graphics.UserInterface Anchor = Anchor.CentreLeft, Origin = Anchor.Centre, TextSize = StarSize, - Scale = new Vector2(MinStarSize), - Alpha = (i == 0) ? 1.0f : MinStarAlpha, Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0), }; @@ -101,118 +123,75 @@ namespace osu.Game.Graphics.UserInterface starContainer.Add(star); } - ResetCount(); + StopAnimation(); } - protected override void transformCount(float currentValue, float newValue) + public void ResetCount() { - transformStar((int)Math.Floor(currentValue), currentValue, currentValue < newValue); - transformCount(new TransformStarCounter(Clock), currentValue, newValue); + Count = 0; + StopAnimation(); } - protected void updateTransformStar(int i) + public void StopAnimation() { - foreach (ITransform t in stars[i].Transforms.AliveItems) - if (t.GetType() == typeof(TransformAlpha) || t.GetType() == typeof(TransformScaleVector)) - t.Apply(stars[i]); + prevCount = count; + transformStartTime = Time; - stars[i].Transforms.RemoveAll(t => - t.GetType() == typeof(TransformScaleVector) || t.GetType() == typeof(TransformAlpha) - ); - } - - protected void transformStarScale(int i, TransformScaleVector transform, bool isIncrement, double startTime) - { - transform.StartTime = startTime; - transform.EndTime = transform.StartTime + StarAnimationDuration; - transform.StartValue = stars[i].Scale; - transform.EndValue = new Vector2( - Interpolation.ValueAt( - Math.Min(Math.Max(i, Count), i + 1), - MinStarSize, - 1.0f, - i, - i + 1 - ) - ); - transform.Easing = StarAnimationEasing; - - stars[i].Transforms.Add(transform); - } - - protected void transformStarAlpha(int i, TransformAlpha transform, bool isIncrement, double startTime) - { - transform.StartTime = startTime; - transform.EndTime = transform.StartTime + FadeDuration; - transform.StartValue = stars[i].Alpha; - transform.EndValue = i < Count ? 1.0f : MinStarAlpha; - - stars[i].Transforms.Add(transform); - } - - - protected void transformStar(int i, float value, bool isIncrement) - { - if (i >= MaxStars) - return; - - if (Clock == null) - return; - - // Calculate time where animation should had started - double startTime = Time; - // If incrementing, animation should had started when VisibleCount crossed start of star (i) - if (isIncrement) - startTime -= i == (int)Math.Floor(prevCount) ? - getProportionalDuration(prevCount, value) : getProportionalDuration(i, value); - // If decrementing, animation should had started when VisibleCount crossed end of star (i + 1) - else - startTime -= i == (int)Math.Floor(prevCount) ? - getProportionalDuration(prevCount, value) : getProportionalDuration(i + 1, value); - - updateTransformStar(i); - - transformStarScale(i, new TransformScaleVector(Clock), isIncrement, startTime); - transformStarAlpha(i, new TransformAlpha(Clock), isIncrement, startTime); - } - - protected override void transformVisibleCount(float currentValue, float newValue) - { - // Detect increment that passes over an integer value - if (Math.Ceiling(currentValue) <= Math.Floor(newValue)) - for (int i = (int)Math.Ceiling(currentValue); i <= Math.Floor(newValue); i++) - transformStar(i, newValue, true); - - // Detect decrement that passes over an integer value - if (Math.Floor(currentValue) >= Math.Ceiling(newValue)) - for (int i = (int)Math.Floor(newValue); i < Math.Floor(currentValue); i++) - transformStar(i, newValue, false); - } - - protected class TransformStarCounter : Transform - { - public override float CurrentValue + for (int i = 0; i < MaxStars; i++) { - get - { - double time = Time; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; + stars[i].DelayReset(); + transformStarQuick(i, count); + } + } - return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + private float getStarScale(int i, float value) + { + if (value <= i) + return MinStarScale; + if (i + 1 <= value) + return 1.0f; + return Interpolation.ValueAt(value, MinStarScale, 1.0f, i, i + 1); + } + + private void transformStar(int i, float value) + { + stars[i].FadeTo(i < value ? 1.0f : MinStarAlpha, FadingDuration); + stars[i].ScaleTo(getStarScale(i, value), ScalingDuration, ScalingEasing); + } + + private void transformStarQuick(int i, float value) + { + stars[i].FadeTo(i < value ? 1.0f : MinStarAlpha); + stars[i].ScaleTo(getStarScale(i, value)); + } + + private void transformCount(float currentValue, float newValue) + { + if (currentValue < newValue) + { + int currentValueFloor = (int)currentValue; + for (int i = 0; i < MaxStars; i++) + { + stars[i].DelayReset(); + stars[i].ClearTransformations(); + if (i > currentValueFloor) + stars[i].Delay((i - currentValueFloor) * AnimationDelay); + transformStar(i, newValue); } } - - public override void Apply(Drawable d) - { - base.Apply(d); - (d as StarCounter).VisibleCount = CurrentValue; - } - - public TransformStarCounter(IClock clock) - : base(clock) + else { + int currentValueCeiling = (int)Math.Ceiling(currentValue); + for (int i = MaxStars - 1; i >= 0; i--) + { + stars[i].DelayReset(); + stars[i].ClearTransformations(); + if (i < currentValueCeiling) + stars[i].Delay((currentValueCeiling - i) * AnimationDelay); + transformStar(i, newValue); + } } + transformStartTime = Time; } } } diff --git a/osu.Game/Graphics/UserInterface/ULongCounter.cs b/osu.Game/Graphics/UserInterface/ULongCounter.cs deleted file mode 100644 index 35df8f5cc8..0000000000 --- a/osu.Game/Graphics/UserInterface/ULongCounter.cs +++ /dev/null @@ -1,59 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; -using osu.Framework.MathUtils; -using osu.Framework.Timing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// A simple rolling counter that accepts unsigned long values. - /// - public class ULongCounter : NumericRollingCounter - { - protected override Type transformType => typeof(TransformULongCounter); - - public override void ResetCount() - { - SetCountWithoutRolling(0); - } - - protected override string formatCount(ulong count) - { - return count.ToString("#,0"); - } - - protected class TransformULongCounter : Transform - { - public override ulong CurrentValue - { - get - { - double time = Time; - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - } - - public override void Apply(Drawable d) - { - base.Apply(d); - (d as ULongCounter).VisibleCount = CurrentValue; - } - - public TransformULongCounter(IClock clock) - : base(clock) - { - } - } - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index bdb852c33f..f05a95f279 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -106,6 +106,8 @@ + + @@ -113,18 +115,15 @@ - - - From c48e3a74f8fd9299dd2c838fef651a6735416120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 13 Oct 2016 17:33:26 -0500 Subject: [PATCH 13/30] Add score counter test again --- osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index c54140b267..4b248d4167 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -142,6 +142,7 @@ + From 69621eb6d384bb294ebb10f81eb412df4a8cf7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 13 Oct 2016 18:00:36 -0500 Subject: [PATCH 14/30] Star animation delay micro fix --- osu.Game/Graphics/UserInterface/StarCounter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index d83a1cf28f..843338e572 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -175,7 +175,7 @@ namespace osu.Game.Graphics.UserInterface stars[i].DelayReset(); stars[i].ClearTransformations(); if (i > currentValueFloor) - stars[i].Delay((i - currentValueFloor) * AnimationDelay); + stars[i].Delay((i - currentValue) * AnimationDelay); transformStar(i, newValue); } } @@ -187,7 +187,7 @@ namespace osu.Game.Graphics.UserInterface stars[i].DelayReset(); stars[i].ClearTransformations(); if (i < currentValueCeiling) - stars[i].Delay((currentValueCeiling - i) * AnimationDelay); + stars[i].Delay((currentValue - i) * AnimationDelay); transformStar(i, newValue); } } From 0deb5b4e227d0ea4b916cafefb93032361216339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 13 Oct 2016 18:07:06 -0500 Subject: [PATCH 15/30] Removed unneeded vars --- osu.Game/Graphics/UserInterface/StarCounter.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 843338e572..fcf283d9c1 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -169,25 +169,23 @@ namespace osu.Game.Graphics.UserInterface { if (currentValue < newValue) { - int currentValueFloor = (int)currentValue; for (int i = 0; i < MaxStars; i++) { stars[i].DelayReset(); stars[i].ClearTransformations(); - if (i > currentValueFloor) + if (i > currentValue) stars[i].Delay((i - currentValue) * AnimationDelay); transformStar(i, newValue); } } else { - int currentValueCeiling = (int)Math.Ceiling(currentValue); for (int i = MaxStars - 1; i >= 0; i--) { stars[i].DelayReset(); stars[i].ClearTransformations(); - if (i < currentValueCeiling) - stars[i].Delay((currentValue - i) * AnimationDelay); + if (i < (currentValue - 1)) + stars[i].Delay((currentValue - 1 - i) * AnimationDelay); transformStar(i, newValue); } } From 9ccff6ec489c12e6b631a099d0f3317d609114c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 13 Oct 2016 19:50:06 -0500 Subject: [PATCH 16/30] Tidying up --- .../Tests/TestCaseScoreCounter.cs | 20 ++----------- .../Graphics/UserInterface/AccuracyCounter.cs | 19 +++++++++++-- .../UserInterface/AlternativeComboCounter.cs | 7 +---- .../UserInterface/CatchComboCounter.cs | 4 +-- .../Graphics/UserInterface/ComboCounter.cs | 28 ++++++------------- .../Graphics/UserInterface/RollingCounter.cs | 15 +++------- .../Graphics/UserInterface/ScoreCounter.cs | 5 +++- .../UserInterface/StandardComboCounter.cs | 2 +- .../Graphics/UserInterface/StarCounter.cs | 28 ++++++------------- 9 files changed, 49 insertions(+), 79 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 1e824cf33b..445e4aff78 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -30,8 +30,6 @@ namespace osu.Desktop.Tests Origin = Anchor.TopRight, Anchor = Anchor.TopRight, TextSize = 40, - RollingDuration = 1000, - RollingEasing = EasingTypes.Out, Count = 0, Position = new Vector2(20, 20), }; @@ -43,9 +41,6 @@ namespace osu.Desktop.Tests Anchor = Anchor.BottomLeft, Position = new Vector2(10, 10), InnerCountPosition = new Vector2(10, 10), - IsRollingProportional = true, - RollingDuration = 20, - PopOutDuration = 100, Count = 0, TextSize = 40, }; @@ -55,9 +50,6 @@ namespace osu.Desktop.Tests { Origin = Anchor.Centre, Anchor = Anchor.Centre, - IsRollingProportional = true, - RollingDuration = 20, - PopOutDuration = 100, Count = 0, TextSize = 40, }; @@ -68,9 +60,6 @@ namespace osu.Desktop.Tests Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Position = new Vector2(20, 80), - IsRollingProportional = true, - RollingDuration = 20, - ScaleFactor = 2, Count = 0, TextSize = 40, }; @@ -81,9 +70,6 @@ namespace osu.Desktop.Tests { Origin = Anchor.TopRight, Anchor = Anchor.TopRight, - RollingDuration = 500, - RollingEasing = EasingTypes.Out, - Count = 100.0f, Position = new Vector2(20, 60), }; Add(accuracyCombo); @@ -133,9 +119,9 @@ namespace osu.Desktop.Tests AddButton(@"miss...", delegate { - standardCombo.RollBack(); - alternativeCombo.RollBack(); - catchCombo.RollBack(); + standardCombo.Roll(); + alternativeCombo.Roll(); + catchCombo.Roll(); accuracyCombo.Denominator++; }); diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs index 32df57d1f0..0d7fcb39c0 100644 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ b/osu.Game/Graphics/UserInterface/AccuracyCounter.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 osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; using osu.Framework.Timing; @@ -47,6 +48,20 @@ namespace osu.Game.Graphics.UserInterface } } + public AccuracyCounter() + { + RollingDuration = 500; + RollingEasing = EasingTypes.Out; + } + + public override void Load(BaseGame game) + { + base.Load(game); + + updateCount(); + StopRolling(); + } + public void SetCount(long num, ulong den) { numerator = num; @@ -72,9 +87,9 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("0.00") + "%"; } - protected override ulong getProportionalDuration(float currentValue, float newValue) + protected override double getProportionalDuration(float currentValue, float newValue) { - return (ulong)(Math.Abs(currentValue - newValue) * RollingDuration); + return Math.Abs(currentValue - newValue) * RollingDuration; } protected class TransformAccuracy : TransformFloat diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 27541c12a3..6e292cdd9d 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -20,7 +20,7 @@ namespace osu.Game.Graphics.UserInterface { public Color4 OriginalColour; public Color4 TintColour = Color4.OrangeRed; - public int TintDuration = 250; + public int TintDuration = 300; public float ScaleFactor = 2; public EasingTypes TintEasing = EasingTypes.None; public bool CanAnimateWhenBackwards = false; @@ -32,11 +32,6 @@ namespace osu.Game.Graphics.UserInterface OriginalColour = Colour; } - public override void ResetCount() - { - SetCountWithoutRolling(0); - } - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) { ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs index 8200ddaa04..b1231585cf 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/CatchComboCounter.cs @@ -25,11 +25,11 @@ namespace osu.Game.Graphics.UserInterface return count.ToString("#,0"); } - public override void RollBack(ulong newValue = 0) + public override void Roll(ulong newValue = 0) { popOutSpriteText.Colour = countSpriteText.Colour; - base.RollBack(newValue); + base.Roll(newValue); } /// diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/Graphics/UserInterface/ComboCounter.cs index 07c957257c..c510f02808 100644 --- a/osu.Game/Graphics/UserInterface/ComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/ComboCounter.cs @@ -21,9 +21,9 @@ namespace osu.Game.Graphics.UserInterface { protected Type transformType => typeof(TransformCombo); - private bool rollbacking = false; + private bool rolling = false; - protected ulong rollingTotalDuration = 0; + protected ulong rollingTotalDuration; /// /// If true, the roll-down duration will be proportional to the counter. @@ -34,7 +34,7 @@ namespace osu.Game.Graphics.UserInterface /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each /// element; else duration in milliseconds for the counter roll-up animation in total. /// - public ulong RollingDuration = 0; + public ulong RollingDuration = 20; /// /// Easing for the counter rollover animation. @@ -131,16 +131,6 @@ namespace osu.Game.Graphics.UserInterface StopRolling(); } - /// - /// Sets count value, bypassing rollover animation. - /// - /// New count value. - public virtual void SetCountWithoutRolling(ulong count) - { - Count = count; - StopRolling(); - } - /// /// Stops rollover animation, forcing the visible count to be the actual count. /// @@ -151,14 +141,14 @@ namespace osu.Game.Graphics.UserInterface } /// - /// Animates roll-back to an specific value. + /// Animates roll-up/roll-back to an specific value. /// /// Target value. - public virtual void RollBack(ulong newValue = 0) + public virtual void Roll(ulong newValue = 0) { - rollbacking = true; + rolling = true; Count = newValue; - rollbacking = false; + rolling = false; } /// @@ -166,7 +156,7 @@ namespace osu.Game.Graphics.UserInterface /// public virtual void ResetCount() { - SetCountWithoutRolling(default(ulong)); + Count = default(ulong); } protected virtual ulong getProportionalDuration(ulong currentValue, ulong newValue) @@ -195,7 +185,7 @@ namespace osu.Game.Graphics.UserInterface protected virtual void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) { - if (!rollbacking) + if (!rolling) { updateComboTransforms(); removeComboTransforms(); diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 4b7d115ceb..d5054c4d3d 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -25,12 +25,12 @@ namespace osu.Game.Graphics.UserInterface /// protected virtual Type transformType => typeof(Transform); - protected ulong rollingTotalDuration = 0; + protected double rollingTotalDuration = 0; protected SpriteText countSpriteText; /// - /// If true, the roll-up duration will be proportional to the counter. + /// If true, the roll-up duration will be proportional to change in value. /// public bool IsRollingProportional = false; @@ -38,7 +38,7 @@ namespace osu.Game.Graphics.UserInterface /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each /// element; else duration in milliseconds for the counter roll-up animation in total. /// - public ulong RollingDuration = 0; + public double RollingDuration = 0; /// /// Easing for the counter rollover animation. @@ -176,7 +176,7 @@ namespace osu.Game.Graphics.UserInterface /// Current visible value. /// New final value. /// Calculated rollover duration in milliseconds. - protected virtual ulong getProportionalDuration(T currentValue, T newValue) + protected virtual double getProportionalDuration(T currentValue, T newValue) { return RollingDuration; } @@ -209,13 +209,6 @@ namespace osu.Game.Graphics.UserInterface /// /// 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 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 virtual void transformCount(T currentValue, T newValue) { diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index a22a403115..5617570243 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -35,6 +35,9 @@ namespace osu.Game.Graphics.UserInterface { countSpriteText.FixedWidth = true; LeadingZeroes = leading; + + RollingDuration = 1000; + RollingEasing = EasingTypes.Out; } public override void Load(BaseGame game) @@ -42,7 +45,7 @@ namespace osu.Game.Graphics.UserInterface base.Load(game); } - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) + protected override double getProportionalDuration(ulong currentValue, ulong newValue) { return currentValue > newValue ? currentValue - newValue : newValue - currentValue; } diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 3053542741..30f6bd4b3b 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -24,7 +24,7 @@ namespace osu.Game.Graphics.UserInterface protected uint scheduledPopOutCurrentId = 0; - public ulong PopOutDuration = 0; + public ulong PopOutDuration = 150; public float PopOutBigScale = 2.0f; public float PopOutSmallScale = 1.1f; public EasingTypes PopOutEasing = EasingTypes.None; diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index fcf283d9c1..3592bbb140 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -167,27 +167,15 @@ namespace osu.Game.Graphics.UserInterface private void transformCount(float currentValue, float newValue) { - if (currentValue < newValue) + for (int i = 0; i < MaxStars; i++) { - for (int i = 0; i < MaxStars; i++) - { - stars[i].DelayReset(); - stars[i].ClearTransformations(); - if (i > currentValue) - stars[i].Delay((i - currentValue) * AnimationDelay); - transformStar(i, newValue); - } - } - else - { - for (int i = MaxStars - 1; i >= 0; i--) - { - stars[i].DelayReset(); - stars[i].ClearTransformations(); - if (i < (currentValue - 1)) - stars[i].Delay((currentValue - 1 - i) * AnimationDelay); - transformStar(i, newValue); - } + stars[i].DelayReset(); + stars[i].ClearTransformations(); + if (currentValue <= newValue) + stars[i].Delay(Math.Max(i - currentValue, 0) * AnimationDelay); + else + stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * AnimationDelay); + transformStar(i, newValue); } transformStartTime = Time; } From edbbe8daefd06d4631faf3912f50bca1b0c64079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 13 Oct 2016 22:54:02 -0500 Subject: [PATCH 17/30] Delete unnecessary class attributes --- .../UserInterface/AlternativeComboCounter.cs | 4 +- .../Graphics/UserInterface/ComboCounter.cs | 47 ++++++++++--------- .../Graphics/UserInterface/RollingCounter.cs | 11 ++--- .../UserInterface/StandardComboCounter.cs | 4 +- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs index 6e292cdd9d..114092384b 100644 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs @@ -32,9 +32,9 @@ namespace osu.Game.Graphics.UserInterface OriginalColour = Colour; } - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) + protected override double getProportionalDuration(ulong currentValue, ulong newValue) { - ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; return difference * RollingDuration; } diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/Graphics/UserInterface/ComboCounter.cs index c510f02808..d5c019e644 100644 --- a/osu.Game/Graphics/UserInterface/ComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/ComboCounter.cs @@ -21,10 +21,6 @@ namespace osu.Game.Graphics.UserInterface { protected Type transformType => typeof(TransformCombo); - private bool rolling = false; - - protected ulong rollingTotalDuration; - /// /// If true, the roll-down duration will be proportional to the counter. /// @@ -34,7 +30,7 @@ namespace osu.Game.Graphics.UserInterface /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each /// element; else duration in milliseconds for the counter roll-up animation in total. /// - public ulong RollingDuration = 20; + public double RollingDuration = 20; /// /// Easing for the counter rollover animation. @@ -78,17 +74,18 @@ namespace osu.Game.Graphics.UserInterface } set { - prevPrevCount = prevCount; - prevCount = count; - count = value; - if (IsLoaded) - { - rollingTotalDuration = - IsRollingProportional - ? getProportionalDuration(VisibleCount, value) - : RollingDuration; - transformCount(VisibleCount, prevPrevCount, prevCount, value); - } + setCount(value); + } + } + + private void setCount(ulong value, bool rolling = false) + { + prevPrevCount = prevCount; + prevCount = count; + count = value; + if (IsLoaded) + { + transformCount(VisibleCount, prevPrevCount, prevCount, value, rolling); } } @@ -146,9 +143,7 @@ namespace osu.Game.Graphics.UserInterface /// Target value. public virtual void Roll(ulong newValue = 0) { - rolling = true; - Count = newValue; - rolling = false; + setCount(newValue, true); } /// @@ -159,7 +154,7 @@ namespace osu.Game.Graphics.UserInterface Count = default(ulong); } - protected virtual ulong getProportionalDuration(ulong currentValue, ulong newValue) + protected virtual double getProportionalDuration(ulong currentValue, ulong newValue) { return currentValue > newValue ? currentValue - newValue : newValue - currentValue; } @@ -183,7 +178,12 @@ namespace osu.Game.Graphics.UserInterface Transforms.RemoveAll(t => t.GetType() == typeof(TransformCombo)); } - protected virtual void transformCount(ulong visibleValue, ulong prevValue, ulong currentValue, ulong newValue) + protected virtual void transformCount( + ulong visibleValue, + ulong prevValue, + ulong currentValue, + ulong newValue, + bool rolling) { if (!rolling) { @@ -220,6 +220,11 @@ namespace osu.Game.Graphics.UserInterface return; } + double rollingTotalDuration = + IsRollingProportional + ? getProportionalDuration(currentValue, newValue) + : RollingDuration; + transform.StartTime = Time; transform.EndTime = Time + rollingTotalDuration; transform.StartValue = currentValue; diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index d5054c4d3d..10a8085726 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -25,8 +25,6 @@ namespace osu.Game.Graphics.UserInterface /// protected virtual Type transformType => typeof(Transform); - protected double rollingTotalDuration = 0; - protected SpriteText countSpriteText; /// @@ -84,10 +82,6 @@ namespace osu.Game.Graphics.UserInterface count = value; if (IsLoaded) { - rollingTotalDuration = - IsRollingProportional - ? getProportionalDuration(visibleCount, value) - : RollingDuration; transformCount(visibleCount, count); } } @@ -236,6 +230,11 @@ namespace osu.Game.Graphics.UserInterface return; } + double rollingTotalDuration = + IsRollingProportional + ? getProportionalDuration(currentValue, newValue) + : RollingDuration; + transform.StartTime = Time; transform.EndTime = Time + rollingTotalDuration; transform.StartValue = currentValue; diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs index 30f6bd4b3b..8d8fb4acab 100644 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs @@ -64,9 +64,9 @@ namespace osu.Game.Graphics.UserInterface Add(popOutSpriteText); } - protected override ulong getProportionalDuration(ulong currentValue, ulong newValue) + protected override double getProportionalDuration(ulong currentValue, ulong newValue) { - ulong difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; return difference * RollingDuration; } From 6bd3eaf37da14e994e5b8c9d9c15562e16dafd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Fri, 14 Oct 2016 18:23:27 -0500 Subject: [PATCH 18/30] Changes according to review + Refactor --- .../Tests/TestCaseScoreCounter.cs | 51 +++++-- .../Play/Catch}/CatchComboCounter.cs | 16 +- .../GameModes/Play/Mania/ManiaComboCounter.cs | 61 ++++++++ .../GameModes/Play/Osu/OsuComboCounter.cs | 124 +++++++++++++++ .../GameModes/Play/Taiko/TaikoComboCounter.cs | 65 ++++++++ .../Graphics/UserInterface/AccuracyCounter.cs | 109 -------------- .../UserInterface/AlternativeComboCounter.cs | 62 -------- .../Graphics/UserInterface/ComboCounter.cs | 106 ++++++------- .../UserInterface/PercentageCounter.cs | 62 ++++++++ .../Graphics/UserInterface/RollingCounter.cs | 64 +++----- .../Graphics/UserInterface/ScoreCounter.cs | 14 +- .../UserInterface/StandardComboCounter.cs | 142 ------------------ .../Graphics/UserInterface/StarCounter.cs | 29 ++-- osu.Game/osu.Game.csproj | 9 +- 14 files changed, 459 insertions(+), 455 deletions(-) rename osu.Game/{Graphics/UserInterface => GameModes/Play/Catch}/CatchComboCounter.cs (68%) create mode 100644 osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs create mode 100644 osu.Game/GameModes/Play/Osu/OsuComboCounter.cs create mode 100644 osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/AccuracyCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs create mode 100644 osu.Game/Graphics/UserInterface/PercentageCounter.cs delete mode 100644 osu.Game/Graphics/UserInterface/StandardComboCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 445e4aff78..5bcfc489d9 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -12,6 +12,10 @@ using OpenTK; using OpenTK.Graphics; using osu.Framework.MathUtils; using osu.Framework.Graphics.Sprites; +using osu.Game.GameModes.Play.Catch; +using osu.Game.GameModes.Play.Mania; +using osu.Game.GameModes.Play.Osu; +using osu.Game.GameModes.Play.Taiko; namespace osu.Desktop.Tests { @@ -25,6 +29,8 @@ namespace osu.Desktop.Tests { base.Reset(); + int numerator = 0, denominator = 0; + ScoreCounter score = new ScoreCounter(7) { Origin = Anchor.TopRight, @@ -35,7 +41,7 @@ namespace osu.Desktop.Tests }; Add(score); - StandardComboCounter standardCombo = new StandardComboCounter + ComboCounter standardCombo = new OsuComboCounter { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, @@ -55,18 +61,28 @@ namespace osu.Desktop.Tests }; Add(catchCombo); - AlternativeComboCounter alternativeCombo = new AlternativeComboCounter + ComboCounter taikoCombo = new TaikoComboCounter { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 80), + Origin = Anchor.BottomCentre, + Anchor = Anchor.Centre, + Position = new Vector2(0, -160), Count = 0, TextSize = 40, }; - Add(alternativeCombo); + Add(taikoCombo); + + ComboCounter maniaCombo = new ManiaComboCounter + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Position = new Vector2(0, -80), + Count = 0, + TextSize = 40, + }; + Add(maniaCombo); - AccuracyCounter accuracyCombo = new AccuracyCounter + PercentageCounter accuracyCombo = new PercentageCounter { Origin = Anchor.TopRight, Anchor = Anchor.TopRight, @@ -95,9 +111,10 @@ namespace osu.Desktop.Tests { score.Count = 0; standardCombo.Count = 0; - alternativeCombo.Count = 0; + maniaCombo.Count = 0; catchCombo.Count = 0; - accuracyCombo.SetCount(0, 0); + numerator = denominator = 0; + accuracyCombo.SetFraction(0, 0); stars.Count = 0; starsLabel.Text = stars.Count.ToString("0.00"); }); @@ -106,23 +123,26 @@ namespace osu.Desktop.Tests { score.Count += 300 + (ulong)(300.0 * (standardCombo.Count > 0 ? standardCombo.Count - 1 : 0) / 25.0); standardCombo.Count++; - alternativeCombo.Count++; + taikoCombo.Count++; + maniaCombo.Count++; catchCombo.CatchFruit(new Color4( Math.Max(0.5f, RNG.NextSingle()), Math.Max(0.5f, RNG.NextSingle()), Math.Max(0.5f, RNG.NextSingle()), 1) ); - accuracyCombo.Numerator++; - accuracyCombo.Denominator++; + numerator++; denominator++; + accuracyCombo.SetFraction(numerator, denominator); }); AddButton(@"miss...", delegate { standardCombo.Roll(); - alternativeCombo.Roll(); + taikoCombo.Roll(); + maniaCombo.Roll(); catchCombo.Roll(); - accuracyCombo.Denominator++; + denominator++; + accuracyCombo.SetFraction(numerator, denominator); }); AddButton(@"Alter stars", delegate @@ -136,7 +156,8 @@ namespace osu.Desktop.Tests score.StopRolling(); standardCombo.StopRolling(); catchCombo.StopRolling(); - alternativeCombo.StopRolling(); + taikoCombo.StopRolling(); + maniaCombo.StopRolling(); accuracyCombo.StopRolling(); stars.StopAnimation(); }); diff --git a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs similarity index 68% rename from osu.Game/Graphics/UserInterface/CatchComboCounter.cs rename to osu.Game/GameModes/Play/Catch/CatchComboCounter.cs index b1231585cf..078a856bce 100644 --- a/osu.Game/Graphics/UserInterface/CatchComboCounter.cs +++ b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs @@ -2,32 +2,30 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK.Graphics; +using osu.Game.GameModes.Play.Osu; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace osu.Game.Graphics.UserInterface +namespace osu.Game.GameModes.Play.Catch { /// /// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch. /// - public class CatchComboCounter : StandardComboCounter + public class CatchComboCounter : OsuComboCounter { - public CatchComboCounter() - { - CanPopOutWhenBackwards = true; - } + protected override bool CanPopOutWhenBackwards => true; - protected override string formatCount(ulong count) + protected override string FormatCount(ulong count) { return count.ToString("#,0"); } public override void Roll(ulong newValue = 0) { - popOutSpriteText.Colour = countSpriteText.Colour; + PopOutSpriteText.Colour = CountSpriteText.Colour; base.Roll(newValue); } @@ -38,7 +36,7 @@ namespace osu.Game.Graphics.UserInterface /// Last grabbed fruit colour. public void CatchFruit(Color4 colour) { - popOutSpriteText.Colour = colour; + PopOutSpriteText.Colour = colour; Count++; } } diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs new file mode 100644 index 0000000000..d32900532f --- /dev/null +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -0,0 +1,61 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK.Graphics; +using osu.Framework; +using osu.Framework.Graphics; +using osu.Game.GameModes.Play.Taiko; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.GameModes.Play.Mania +{ + /// + /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania. + /// + public class ManiaComboCounter : TaikoComboCounter + { + protected Color4 OriginalColour; + + protected Color4 TintColour => Color4.OrangeRed; + protected Color4 PopOutColor => Color4.Red; + protected override float PopOutInitialAlpha => 1.0f; + protected override ulong PopOutDuration => 300; + + public override void Load(BaseGame game) + { + base.Load(game); + + PopOutSpriteText.Anchor = Anchor.BottomCentre; + PopOutSpriteText.Origin = Anchor.Centre; + PopOutSpriteText.FadeColour(PopOutColor, 0); + OriginalColour = Colour; + } + + public override void Roll(ulong newValue = 0) + { + if (!IsRolling) + { + PopOutSpriteText.Text = FormatCount(VisibleCount); + + PopOutSpriteText.FadeTo(PopOutInitialAlpha); + PopOutSpriteText.ScaleTo(1.0f); + + PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); + PopOutSpriteText.ScaleTo(PopOutScale, PopOutDuration, PopOutEasing); + } + + base.Roll(newValue); + } + + protected override void transformAnimate(ulong newValue) + { + base.transformAnimate(newValue); + CountSpriteText.FadeColour(TintColour, 0); + CountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing); + } + } +} diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs new file mode 100644 index 0000000000..ef47569582 --- /dev/null +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -0,0 +1,124 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework; +using osu.Game.Graphics.UserInterface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.GameModes.Play.Osu +{ + /// + /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard. + /// + public class OsuComboCounter : ComboCounter + { + protected uint ScheduledPopOutCurrentId = 0; + + protected virtual float PopOutSmallScale => 1.1f; + protected virtual bool CanPopOutWhenBackwards => false; + + + public Vector2 InnerCountPosition + { + get + { + return CountSpriteText.Position; + } + set + { + CountSpriteText.Position = value; + } + } + + public override void Load(BaseGame game) + { + base.Load(game); + + PopOutSpriteText.Origin = this.Origin; + PopOutSpriteText.Anchor = this.Anchor; + + Add(PopOutSpriteText); + } + + protected override string FormatCount(ulong count) + { + return count.ToString("#,0") + "x"; + } + + protected virtual void transformPopOut(ulong currentValue, ulong newValue) + { + PopOutSpriteText.Text = FormatCount(newValue); + CountSpriteText.Text = FormatCount(currentValue); + + PopOutSpriteText.ScaleTo(PopOutScale); + PopOutSpriteText.FadeTo(PopOutInitialAlpha); + PopOutSpriteText.MoveTo(Vector2.Zero); + + PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); + PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); + PopOutSpriteText.MoveTo(CountSpriteText.Position, PopOutDuration, PopOutEasing); + + ScheduledPopOutCurrentId++; + uint newTaskId = ScheduledPopOutCurrentId; + Scheduler.AddDelayed(delegate + { + scheduledPopOutSmall(newTaskId, newValue); + }, PopOutDuration); + } + + protected virtual void transformNoPopOut(ulong newValue) + { + ScheduledPopOutCurrentId++; + CountSpriteText.Text = FormatCount(newValue); + CountSpriteText.ScaleTo(1); + } + + protected virtual void transformPopOutSmall(ulong newValue) + { + CountSpriteText.Text = FormatCount(newValue); + CountSpriteText.ScaleTo(PopOutSmallScale); + CountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); + } + + protected virtual void scheduledPopOutSmall(uint id, ulong newValue) + { + // Too late; scheduled task invalidated + if (id != ScheduledPopOutCurrentId) + return; + + transformPopOutSmall(newValue); + } + + protected override void OnCountRolling(ulong currentValue, ulong newValue) + { + if (newValue == 0) + CountSpriteText.FadeOut(PopOutDuration); + else + CountSpriteText.Show(); + + if (CanPopOutWhenBackwards) + transformPopOut(currentValue, newValue); + else + transformNoPopOut(newValue); + } + + protected override void OnCountChange(ulong newValue) + { + CountSpriteText.FadeTo(newValue == 0 ? 0 : 1); + + transformNoPopOut(newValue); + } + + protected override void OnCountIncrement(ulong newValue) + { + CountSpriteText.Show(); + + transformPopOut(newValue - 1, newValue); + } + } +} diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs new file mode 100644 index 0000000000..677be076cd --- /dev/null +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -0,0 +1,65 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework.Graphics.Transformations; +using osu.Game.Graphics.UserInterface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.GameModes.Play.Taiko +{ + public class TaikoComboCounter : ComboCounter + { + protected virtual int AnimationDuration => 300; + protected virtual float ScaleFactor => 2; + protected virtual EasingTypes AnimationEasing => EasingTypes.None; + protected virtual bool CanAnimateWhenBackwards => false; + + public TaikoComboCounter() + { + CountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre; + CountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre; + } + + protected virtual void transformAnimate(ulong newValue) + { + CountSpriteText.Text = FormatCount(newValue); + CountSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); + CountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing); + } + + protected virtual void transformNotAnimate(ulong newValue) + { + CountSpriteText.Text = FormatCount(newValue); + CountSpriteText.ScaleTo(1); + } + + protected override void OnCountRolling(ulong currentValue, ulong newValue) + { + if (newValue == 0) + CountSpriteText.FadeOut(AnimationDuration); + else + CountSpriteText.Show(); + + transformNotAnimate(newValue); + } + + protected override void OnCountChange(ulong newValue) + { + CountSpriteText.FadeTo(newValue == 0 ? 0 : 1); + + transformNotAnimate(newValue); + } + + protected override void OnCountIncrement(ulong newValue) + { + CountSpriteText.Show(); + + transformAnimate(newValue); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs b/osu.Game/Graphics/UserInterface/AccuracyCounter.cs deleted file mode 100644 index 0d7fcb39c0..0000000000 --- a/osu.Game/Graphics/UserInterface/AccuracyCounter.cs +++ /dev/null @@ -1,109 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Transformations; -using osu.Framework.Timing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction. - /// - public class AccuracyCounter : RollingCounter - { - protected override Type transformType => typeof(TransformAccuracy); - - private long numerator = 0; - public long Numerator - { - get - { - return numerator; - } - set - { - numerator = value; - updateCount(); - } - } - - private ulong denominator = 0; - public ulong Denominator - { - get - { - return denominator; - } - set - { - denominator = value; - updateCount(); - } - } - - public AccuracyCounter() - { - RollingDuration = 500; - RollingEasing = EasingTypes.Out; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - updateCount(); - StopRolling(); - } - - public void SetCount(long num, ulong den) - { - numerator = num; - denominator = den; - updateCount(); - } - - private void updateCount() - { - Count = Denominator == 0 ? 100.0f : (Numerator * 100.0f) / Denominator; - } - - public override void ResetCount() - { - numerator = 0; - denominator = 0; - updateCount(); - StopRolling(); - } - - protected override string formatCount(float count) - { - return count.ToString("0.00") + "%"; - } - - protected override double getProportionalDuration(float currentValue, float newValue) - { - return Math.Abs(currentValue - newValue) * RollingDuration; - } - - protected class TransformAccuracy : TransformFloat - { - public override void Apply(Drawable d) - { - base.Apply(d); - (d as AccuracyCounter).VisibleCount = CurrentValue; - } - - public TransformAccuracy(IClock clock) - : base(clock) - { - } - } - } -} diff --git a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs b/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs deleted file mode 100644 index 114092384b..0000000000 --- a/osu.Game/Graphics/UserInterface/AlternativeComboCounter.cs +++ /dev/null @@ -1,62 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK; -using OpenTK.Graphics; -using osu.Framework; -using osu.Framework.Graphics.Transformations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania. - /// - public class AlternativeComboCounter : ComboCounter - { - public Color4 OriginalColour; - public Color4 TintColour = Color4.OrangeRed; - public int TintDuration = 300; - public float ScaleFactor = 2; - public EasingTypes TintEasing = EasingTypes.None; - public bool CanAnimateWhenBackwards = false; - - public override void Load(BaseGame game) - { - base.Load(game); - - OriginalColour = Colour; - } - - protected override double getProportionalDuration(ulong currentValue, ulong newValue) - { - double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; - return difference * RollingDuration; - } - - protected virtual void transformAnimate(ulong newValue) - { - countSpriteText.FadeColour(TintColour, 0); - countSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); - countSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing); - countSpriteText.ScaleTo(new Vector2(1, 1), TintDuration, TintEasing); - } - - protected override void transformVisibleCount(ulong currentValue, ulong newValue) - { - countSpriteText.Text = formatCount(newValue); - - if (newValue == 0) - countSpriteText.FadeOut(TintDuration); - else - countSpriteText.Show(); - - if (newValue > currentValue || CanAnimateWhenBackwards) - transformAnimate(newValue); - } - } -} diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/Graphics/UserInterface/ComboCounter.cs index d5c019e644..f5c0c382b8 100644 --- a/osu.Game/Graphics/UserInterface/ComboCounter.cs +++ b/osu.Game/Graphics/UserInterface/ComboCounter.cs @@ -17,28 +17,37 @@ using System.Threading.Tasks; namespace osu.Game.Graphics.UserInterface { - public abstract class ComboCounter : AutoSizeContainer + public abstract class ComboCounter : Container { protected Type transformType => typeof(TransformCombo); + protected bool IsRolling = false; + + protected SpriteText PopOutSpriteText; + + protected virtual ulong PopOutDuration => 150; + protected virtual float PopOutScale => 2.0f; + protected virtual EasingTypes PopOutEasing => EasingTypes.None; + protected virtual float PopOutInitialAlpha => 0.75f; + /// /// If true, the roll-down duration will be proportional to the counter. /// - public bool IsRollingProportional = true; + protected virtual bool IsRollingProportional => true; /// /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each /// element; else duration in milliseconds for the counter roll-up animation in total. /// - public double RollingDuration = 20; + protected virtual double RollingDuration => 20; /// /// Easing for the counter rollover animation. /// - public EasingTypes RollingEasing = EasingTypes.None; + protected EasingTypes RollingEasing => EasingTypes.None; - protected ulong prevVisibleCount; - protected ulong visibleCount; + private ulong prevVisibleCount; + private ulong visibleCount; /// /// Value shown at the current moment. @@ -55,11 +64,10 @@ namespace osu.Game.Graphics.UserInterface return; prevVisibleCount = visibleCount; visibleCount = value; - transformVisibleCount(prevVisibleCount, visibleCount); + transformVisibleCount(prevVisibleCount, visibleCount, IsRolling); } } - protected ulong prevPrevCount; protected ulong prevCount; protected ulong count; @@ -80,25 +88,25 @@ namespace osu.Game.Graphics.UserInterface private void setCount(ulong value, bool rolling = false) { - prevPrevCount = prevCount; prevCount = count; count = value; if (IsLoaded) { - transformCount(VisibleCount, prevPrevCount, prevCount, value, rolling); + transformCount(VisibleCount, prevCount, value, rolling); } } - protected SpriteText countSpriteText; + protected SpriteText CountSpriteText; - protected float textSize = 20.0f; + private float textSize = 20.0f; public float TextSize { get { return textSize; } set { textSize = value; - updateTextSize(); + CountSpriteText.TextSize = TextSize; + PopOutSpriteText.TextSize = TextSize; } } @@ -109,12 +117,16 @@ namespace osu.Game.Graphics.UserInterface { Children = new Drawable[] { - countSpriteText = new SpriteText + CountSpriteText = new SpriteText { Anchor = this.Anchor, Origin = this.Origin, Alpha = 0, }, + PopOutSpriteText = new SpriteText + { + Alpha = 0, + } }; } @@ -122,8 +134,8 @@ namespace osu.Game.Graphics.UserInterface { base.Load(game); - countSpriteText.Anchor = this.Anchor; - countSpriteText.Origin = this.Origin; + CountSpriteText.Anchor = this.Anchor; + CountSpriteText.Origin = this.Origin; StopRolling(); } @@ -133,7 +145,7 @@ namespace osu.Game.Graphics.UserInterface /// public virtual void StopRolling() { - removeComboTransforms(); + Flush(false, typeof(TransformCombo)); VisibleCount = Count; } @@ -154,62 +166,55 @@ namespace osu.Game.Graphics.UserInterface Count = default(ulong); } - protected virtual double getProportionalDuration(ulong currentValue, ulong newValue) + protected double GetProportionalDuration(ulong currentValue, ulong newValue) { - return currentValue > newValue ? currentValue - newValue : newValue - currentValue; + double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + return difference * RollingDuration; } - protected abstract void transformVisibleCount(ulong currentValue, ulong newValue); - - protected virtual string formatCount(ulong count) + protected virtual string FormatCount(ulong count) { return count.ToString(); } - private void updateComboTransforms() + protected abstract void OnCountRolling(ulong currentValue, ulong newValue); + protected abstract void OnCountIncrement(ulong newValue); + protected abstract void OnCountChange(ulong newValue); + + private void transformVisibleCount(ulong currentValue, ulong newValue, bool rolling) { - foreach (ITransform t in Transforms.AliveItems) - if (t.GetType() == typeof(TransformCombo)) - t.Apply(this); + if (rolling) + OnCountRolling(currentValue, newValue); + else if (currentValue + 1 == newValue) + OnCountIncrement(newValue); + else + OnCountChange(newValue); } - private void removeComboTransforms() - { - Transforms.RemoveAll(t => t.GetType() == typeof(TransformCombo)); - } - - protected virtual void transformCount( + private void transformCount( ulong visibleValue, - ulong prevValue, ulong currentValue, ulong newValue, bool rolling) { if (!rolling) { - updateComboTransforms(); - removeComboTransforms(); - - // If was decreasing, stops roll before increasing - if (currentValue < prevValue) - VisibleCount = currentValue; + Flush(false, typeof(TransformCombo)); + IsRolling = false; + VisibleCount = currentValue; VisibleCount = newValue; } else { - transformCount(new TransformCombo(Clock), visibleValue, newValue); + IsRolling = true; + transformRoll(new TransformCombo(Clock), visibleValue, newValue); } } - /// - /// Intended to be used by transformCount(). - /// - /// - protected void transformCount(TransformCombo transform, ulong currentValue, ulong newValue) + private void transformRoll(TransformCombo transform, ulong currentValue, ulong newValue) { - updateComboTransforms(); - removeComboTransforms(); + Flush(false, typeof(TransformCombo)); if (Clock == null) return; @@ -222,7 +227,7 @@ namespace osu.Game.Graphics.UserInterface double rollingTotalDuration = IsRollingProportional - ? getProportionalDuration(currentValue, newValue) + ? GetProportionalDuration(currentValue, newValue) : RollingDuration; transform.StartTime = Time; @@ -234,11 +239,6 @@ namespace osu.Game.Graphics.UserInterface Transforms.Add(transform); } - protected virtual void updateTextSize() - { - countSpriteText.TextSize = TextSize; - } - protected class TransformCombo : Transform { public override ulong CurrentValue diff --git a/osu.Game/Graphics/UserInterface/PercentageCounter.cs b/osu.Game/Graphics/UserInterface/PercentageCounter.cs new file mode 100644 index 0000000000..844afaa00e --- /dev/null +++ b/osu.Game/Graphics/UserInterface/PercentageCounter.cs @@ -0,0 +1,62 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transformations; +using osu.Framework.Timing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Graphics.UserInterface +{ + /// + /// Used as an accuracy counter. Represented visually as a percentage. + /// + public class PercentageCounter : RollingCounter + { + protected override Type TransformType => typeof(TransformAccuracy); + + public override double RollingDuration => 500; + public override EasingTypes RollingEasing => EasingTypes.Out; + + private float epsilon => 1e-10f; + + public void SetFraction(float numerator, float denominator) + { + Count = Math.Abs(denominator) < epsilon ? 1.0f : numerator / denominator; + } + + public PercentageCounter() + { + Count = 1.0f; + } + + protected override string FormatCount(float count) + { + return $@"{count:P2}"; + } + + protected override double GetProportionalDuration(float currentValue, float newValue) + { + return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f; + } + + protected class TransformAccuracy : TransformFloat + { + public override void Apply(Drawable d) + { + base.Apply(d); + (d as PercentageCounter).VisibleCount = CurrentValue; + } + + public TransformAccuracy(IClock clock) + : base(clock) + { + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 10a8085726..968b5abfa8 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -23,9 +23,9 @@ namespace osu.Game.Graphics.UserInterface /// /// Must be a subclass of Transform /// - protected virtual Type transformType => typeof(Transform); + protected virtual Type TransformType => typeof(Transform); - protected SpriteText countSpriteText; + protected SpriteText CountSpriteText; /// /// If true, the roll-up duration will be proportional to change in value. @@ -36,15 +36,15 @@ namespace osu.Game.Graphics.UserInterface /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each /// element; else duration in milliseconds for the counter roll-up animation in total. /// - public double RollingDuration = 0; + public virtual double RollingDuration => 0; /// /// Easing for the counter rollover animation. /// - public EasingTypes RollingEasing = EasingTypes.None; + public virtual EasingTypes RollingEasing => EasingTypes.None; - protected T prevVisibleCount; - protected T visibleCount; + private T prevVisibleCount; + private T visibleCount; /// /// Value shown at the current moment. @@ -60,7 +60,7 @@ namespace osu.Game.Graphics.UserInterface if (visibleCount.Equals(value)) return; visibleCount = value; - countSpriteText.Text = formatCount(value); + CountSpriteText.Text = FormatCount(value); } } @@ -82,7 +82,7 @@ namespace osu.Game.Graphics.UserInterface count = value; if (IsLoaded) { - transformCount(visibleCount, count); + TransformCount(visibleCount, count); } } } @@ -95,7 +95,7 @@ namespace osu.Game.Graphics.UserInterface set { textSize = value; - countSpriteText.TextSize = value; + CountSpriteText.TextSize = value; } } @@ -105,13 +105,13 @@ namespace osu.Game.Graphics.UserInterface protected RollingCounter() { Debug.Assert( - transformType.IsSubclassOf(typeof(Transform)) || transformType == typeof(Transform), + TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), @"transformType should be a subclass of Transform." ); Children = new Drawable[] { - countSpriteText = new SpriteText + CountSpriteText = new SpriteText { Anchor = this.Anchor, Origin = this.Origin, @@ -123,13 +123,13 @@ namespace osu.Game.Graphics.UserInterface { base.Load(game); - removeTransforms(transformType); + Flush(false, TransformType); VisibleCount = Count; - countSpriteText.Text = formatCount(count); - countSpriteText.Anchor = this.Anchor; - countSpriteText.Origin = this.Origin; + CountSpriteText.Text = FormatCount(count); + CountSpriteText.Anchor = this.Anchor; + CountSpriteText.Origin = this.Origin; } /// @@ -147,7 +147,7 @@ namespace osu.Game.Graphics.UserInterface /// public virtual void StopRolling() { - removeTransforms(transformType); + Flush(false, TransformType); VisibleCount = Count; } @@ -170,7 +170,7 @@ namespace osu.Game.Graphics.UserInterface /// Current visible value. /// New final value. /// Calculated rollover duration in milliseconds. - protected virtual double getProportionalDuration(T currentValue, T newValue) + protected virtual double GetProportionalDuration(T currentValue, T newValue) { return RollingDuration; } @@ -180,46 +180,32 @@ namespace osu.Game.Graphics.UserInterface /// /// Count to format. /// Count formatted as a string. - protected virtual string formatCount(T count) + protected virtual string FormatCount(T count) { return count.ToString(); } - protected void updateTransforms(Type type) - { - foreach (ITransform t in Transforms.AliveItems) - if (t.GetType() == type) - t.Apply(this); - } - - protected void removeTransforms(Type type) - { - Transforms.RemoveAll(t => t.GetType() == type); - } - /// /// Called when the count is updated to add a transformer that changes the value of the visible count (i.e. /// implement the rollover animation). /// /// Count value before modification. /// Expected count value after modification- - /// - protected virtual void transformCount(T currentValue, T newValue) + /// + protected virtual void TransformCount(T currentValue, T newValue) { object[] parameters = { Clock }; - transformCount((Transform)Activator.CreateInstance(transformType, parameters), currentValue, newValue); + TransformCount((Transform)Activator.CreateInstance(TransformType, parameters), currentValue, newValue); } /// - /// Intended to be used by transformCount(). + /// Intended to be used by TransformCount(T currentValue, T newValue). /// - /// - protected void transformCount(Transform transform, T currentValue, T newValue) + protected void TransformCount(Transform transform, T currentValue, T newValue) { Type type = transform.GetType(); - updateTransforms(type); - removeTransforms(type); + Flush(false, type); if (Clock == null) return; @@ -232,7 +218,7 @@ namespace osu.Game.Graphics.UserInterface double rollingTotalDuration = IsRollingProportional - ? getProportionalDuration(currentValue, newValue) + ? GetProportionalDuration(currentValue, newValue) : RollingDuration; transform.StartTime = Time; diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index 5617570243..e65953c265 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -16,7 +16,10 @@ namespace osu.Game.Graphics.UserInterface { public class ScoreCounter : RollingCounter { - protected override Type transformType => typeof(TransformScore); + protected override Type TransformType => typeof(TransformScore); + + public override double RollingDuration => 1000; + public override EasingTypes RollingEasing => EasingTypes.Out; /// /// How many leading zeroes the counter has. @@ -33,11 +36,8 @@ namespace osu.Game.Graphics.UserInterface /// How many leading zeroes the counter will have. public ScoreCounter(uint leading = 0) { - countSpriteText.FixedWidth = true; + CountSpriteText.FixedWidth = true; LeadingZeroes = leading; - - RollingDuration = 1000; - RollingEasing = EasingTypes.Out; } public override void Load(BaseGame game) @@ -45,12 +45,12 @@ namespace osu.Game.Graphics.UserInterface base.Load(game); } - protected override double getProportionalDuration(ulong currentValue, ulong newValue) + protected override double GetProportionalDuration(ulong currentValue, ulong newValue) { return currentValue > newValue ? currentValue - newValue : newValue - currentValue; } - protected override string formatCount(ulong count) + protected override string FormatCount(ulong count) { return count.ToString("D" + LeadingZeroes); } diff --git a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs b/osu.Game/Graphics/UserInterface/StandardComboCounter.cs deleted file mode 100644 index 8d8fb4acab..0000000000 --- a/osu.Game/Graphics/UserInterface/StandardComboCounter.cs +++ /dev/null @@ -1,142 +0,0 @@ -//Copyright (c) 2007-2016 ppy Pty Ltd . -//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK; -using osu.Framework; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Transformations; -using osu.Framework.Timing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace osu.Game.Graphics.UserInterface -{ - /// - /// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard. - /// - public class StandardComboCounter : ComboCounter - { - protected SpriteText popOutSpriteText; - - protected uint scheduledPopOutCurrentId = 0; - - public ulong PopOutDuration = 150; - public float PopOutBigScale = 2.0f; - public float PopOutSmallScale = 1.1f; - public EasingTypes PopOutEasing = EasingTypes.None; - public bool CanPopOutWhenBackwards = false; - public float PopOutInitialAlpha = 0.75f; - - public Vector2 InnerCountPosition - { - get - { - return countSpriteText.Position; - } - set - { - countSpriteText.Position = value; - } - } - - public StandardComboCounter() - { - popOutSpriteText = new SpriteText - { - Origin = this.Origin, - Anchor = this.Anchor, - TextSize = this.TextSize, - Alpha = 0, - }; - } - - public override void Load(BaseGame game) - { - base.Load(game); - - popOutSpriteText.Origin = this.Origin; - popOutSpriteText.Anchor = this.Anchor; - - Add(popOutSpriteText); - } - - protected override double getProportionalDuration(ulong currentValue, ulong newValue) - { - double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; - return difference * RollingDuration; - } - - protected override string formatCount(ulong count) - { - return count.ToString("#,0") + "x"; - } - - protected virtual void transformPopOut(ulong currentValue, ulong newValue) - { - popOutSpriteText.Text = formatCount(newValue); - countSpriteText.Text = formatCount(currentValue); - - popOutSpriteText.ScaleTo(PopOutBigScale); - popOutSpriteText.FadeTo(PopOutInitialAlpha); - popOutSpriteText.MoveTo(Vector2.Zero); - - popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); - popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); - popOutSpriteText.MoveTo(countSpriteText.Position, PopOutDuration, PopOutEasing); - - scheduledPopOutCurrentId++; - uint newTaskId = scheduledPopOutCurrentId; - Scheduler.AddDelayed(delegate - { - scheduledPopOutSmall(newTaskId, newValue); - }, PopOutDuration); - } - - protected virtual void transformNoPopOut(ulong newValue) - { - scheduledPopOutCurrentId++; - countSpriteText.Text = formatCount(newValue); - countSpriteText.ScaleTo(1); - } - - protected virtual void transformPopOutSmall(ulong newValue) - { - countSpriteText.Text = formatCount(newValue); - countSpriteText.ScaleTo(PopOutSmallScale); - countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); - } - - protected virtual void scheduledPopOutSmall(uint id, ulong newValue) - { - // Too late; scheduled task invalidated - if (id != scheduledPopOutCurrentId) - return; - - transformPopOutSmall(newValue); - } - - protected override void transformVisibleCount(ulong currentValue, ulong newValue) - { - if (newValue == 0) - countSpriteText.FadeOut(PopOutDuration); - else - countSpriteText.Show(); - - if (newValue > currentValue || CanPopOutWhenBackwards) - transformPopOut(currentValue, newValue); - else - transformNoPopOut(newValue); - } - - protected override void updateTextSize() - { - base.updateTextSize(); - - popOutSpriteText.TextSize = this.TextSize; - } - } -} diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 3592bbb140..a352bdfb9f 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -7,7 +7,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Transformations; using osu.Framework.MathUtils; -using osu.Framework.Timing; using System; using System.Collections.Generic; using System.Linq; @@ -35,14 +34,14 @@ namespace osu.Game.Graphics.UserInterface protected set; } - public double AnimationDelay = 150; + private double animationDelay => 150; - public double ScalingDuration = 500; - public EasingTypes ScalingEasing = EasingTypes.OutElasticHalf; - public float MinStarScale = 0.3f; + private double scalingDuration => 500; + private EasingTypes scalingEasing => EasingTypes.OutElasticHalf; + private float minStarScale => 0.3f; - public double FadingDuration = 100; - public float MinStarAlpha = 0.5f; + private double fadingDuration => 100; + private float minStarAlpha => 0.5f; public float StarSize = 20; public float StarSpacing = 4; @@ -52,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface get { double elapsedTime = Time - transformStartTime; - double expectedElapsedTime = Math.Abs(prevCount - count) * AnimationDelay; + double expectedElapsedTime = Math.Abs(prevCount - count) * animationDelay; if (elapsedTime >= expectedElapsedTime) return count; return Interpolation.ValueAt(elapsedTime, prevCount, count, 0, expectedElapsedTime); @@ -147,21 +146,21 @@ namespace osu.Game.Graphics.UserInterface private float getStarScale(int i, float value) { if (value <= i) - return MinStarScale; + return minStarScale; if (i + 1 <= value) return 1.0f; - return Interpolation.ValueAt(value, MinStarScale, 1.0f, i, i + 1); + return Interpolation.ValueAt(value, minStarScale, 1.0f, i, i + 1); } private void transformStar(int i, float value) { - stars[i].FadeTo(i < value ? 1.0f : MinStarAlpha, FadingDuration); - stars[i].ScaleTo(getStarScale(i, value), ScalingDuration, ScalingEasing); + stars[i].FadeTo(i < value ? 1.0f : minStarAlpha, fadingDuration); + stars[i].ScaleTo(getStarScale(i, value), scalingDuration, scalingEasing); } private void transformStarQuick(int i, float value) { - stars[i].FadeTo(i < value ? 1.0f : MinStarAlpha); + stars[i].FadeTo(i < value ? 1.0f : minStarAlpha); stars[i].ScaleTo(getStarScale(i, value)); } @@ -172,9 +171,9 @@ namespace osu.Game.Graphics.UserInterface stars[i].DelayReset(); stars[i].ClearTransformations(); if (currentValue <= newValue) - stars[i].Delay(Math.Max(i - currentValue, 0) * AnimationDelay); + stars[i].Delay(Math.Max(i - currentValue, 0) * animationDelay); else - stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * AnimationDelay); + stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * animationDelay); transformStar(i, newValue); } transformStartTime = Time; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d638868d73..9948c7066c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -132,21 +132,22 @@ + - + - + - - + + From 2625d065539f27ce3b982bc8235b03dfbd11fc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 13:53:39 -0500 Subject: [PATCH 19/30] Why calling StopAnimation() on StarCounter's ctor()? --- osu.Game/Graphics/UserInterface/StarCounter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index a352bdfb9f..bfcd807962 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -122,6 +122,7 @@ namespace osu.Game.Graphics.UserInterface starContainer.Add(star); } + // Used to recreate initial state. StopAnimation(); } From c268500f898bbf0fb5c233c9c5404985d4270263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 14:01:11 -0500 Subject: [PATCH 20/30] Minor variable change --- osu.Game/GameModes/Play/Catch/CatchComboCounter.cs | 2 +- osu.Game/GameModes/Play/Osu/OsuComboCounter.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs index 078a856bce..240fa5cd07 100644 --- a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs +++ b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs @@ -16,7 +16,7 @@ namespace osu.Game.GameModes.Play.Catch /// public class CatchComboCounter : OsuComboCounter { - protected override bool CanPopOutWhenBackwards => true; + protected override bool CanPopOutWhileRolling => true; protected override string FormatCount(ulong count) { diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index ef47569582..8d4f9b4e67 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -20,7 +20,7 @@ namespace osu.Game.GameModes.Play.Osu protected uint ScheduledPopOutCurrentId = 0; protected virtual float PopOutSmallScale => 1.1f; - protected virtual bool CanPopOutWhenBackwards => false; + protected virtual bool CanPopOutWhileRolling => false; public Vector2 InnerCountPosition @@ -101,7 +101,7 @@ namespace osu.Game.GameModes.Play.Osu else CountSpriteText.Show(); - if (CanPopOutWhenBackwards) + if (CanPopOutWhileRolling) transformPopOut(currentValue, newValue); else transformNoPopOut(newValue); From a15f4cda448b37971c1e903c48492e271d014b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 15:03:51 -0500 Subject: [PATCH 21/30] Tidying --- osu.Game/GameModes/Play/Catch/CatchComboCounter.cs | 2 +- osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs | 2 +- osu.Game/GameModes/Play/Osu/OsuComboCounter.cs | 2 +- osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs | 3 +++ osu.Game/Graphics/UserInterface/ScoreCounter.cs | 6 ------ 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs index 240fa5cd07..cbd2c27add 100644 --- a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs +++ b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs @@ -20,7 +20,7 @@ namespace osu.Game.GameModes.Play.Catch protected override string FormatCount(ulong count) { - return count.ToString("#,0"); + return $@"{count:#,0}x"; } public override void Roll(ulong newValue = 0) diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs index d32900532f..ba37e65647 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -14,7 +14,7 @@ using System.Threading.Tasks; namespace osu.Game.GameModes.Play.Mania { /// - /// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania. + /// Similar to osu!taiko, with a pop-out animation when failing (rolling). Used in osu!mania. /// public class ManiaComboCounter : TaikoComboCounter { diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index 8d4f9b4e67..209fae57b7 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -47,7 +47,7 @@ namespace osu.Game.GameModes.Play.Osu protected override string FormatCount(ulong count) { - return count.ToString("#,0") + "x"; + return $@"{count:#,0}x"; } protected virtual void transformPopOut(ulong currentValue, ulong newValue) diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs index 677be076cd..84019739ea 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -12,6 +12,9 @@ using System.Threading.Tasks; namespace osu.Game.GameModes.Play.Taiko { + /// + /// Allows tint and scaling animations. Used in osu!taiko. + /// public class TaikoComboCounter : ComboCounter { protected virtual int AnimationDuration => 300; diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index e65953c265..a47aca738e 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -1,7 +1,6 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; using osu.Framework.MathUtils; @@ -40,11 +39,6 @@ namespace osu.Game.Graphics.UserInterface LeadingZeroes = leading; } - public override void Load(BaseGame game) - { - base.Load(game); - } - protected override double GetProportionalDuration(ulong currentValue, ulong newValue) { return currentValue > newValue ? currentValue - newValue : newValue - currentValue; From 0ceb72ba427ca36bf978317fc3011e3a42a025f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 15:16:02 -0500 Subject: [PATCH 22/30] More refactoring --- .../Tests/TestCaseScoreCounter.cs | 1 + .../Play}/ComboCounter.cs | 2 +- osu.Game/GameModes/Play/ComboResultCounter.cs | 63 +++++++++++++++++++ .../GameModes/Play/Osu/OsuComboCounter.cs | 1 - .../GameModes/Play/Taiko/TaikoComboCounter.cs | 1 - osu.Game/osu.Game.csproj | 3 +- 6 files changed, 67 insertions(+), 4 deletions(-) rename osu.Game/{Graphics/UserInterface => GameModes/Play}/ComboCounter.cs (96%) create mode 100644 osu.Game/GameModes/Play/ComboResultCounter.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 5bcfc489d9..3cfd220beb 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -16,6 +16,7 @@ using osu.Game.GameModes.Play.Catch; using osu.Game.GameModes.Play.Mania; using osu.Game.GameModes.Play.Osu; using osu.Game.GameModes.Play.Taiko; +using osu.Game.GameModes.Play; namespace osu.Desktop.Tests { diff --git a/osu.Game/Graphics/UserInterface/ComboCounter.cs b/osu.Game/GameModes/Play/ComboCounter.cs similarity index 96% rename from osu.Game/Graphics/UserInterface/ComboCounter.cs rename to osu.Game/GameModes/Play/ComboCounter.cs index f5c0c382b8..6cd166a300 100644 --- a/osu.Game/Graphics/UserInterface/ComboCounter.cs +++ b/osu.Game/GameModes/Play/ComboCounter.cs @@ -15,7 +15,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace osu.Game.Graphics.UserInterface +namespace osu.Game.GameModes.Play { public abstract class ComboCounter : Container { diff --git a/osu.Game/GameModes/Play/ComboResultCounter.cs b/osu.Game/GameModes/Play/ComboResultCounter.cs new file mode 100644 index 0000000000..c01edc180d --- /dev/null +++ b/osu.Game/GameModes/Play/ComboResultCounter.cs @@ -0,0 +1,63 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transformations; +using osu.Framework.MathUtils; +using osu.Framework.Timing; +using osu.Game.Graphics.UserInterface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.GameModes.Play.UserInterface +{ + /// + /// Used to display combo with a roll-up animation in results screen. + /// + public class ComboResultCounter : RollingCounter + { + protected override Type TransformType => typeof(TransformComboResult); + + public override double RollingDuration => 500; + public override EasingTypes RollingEasing => EasingTypes.Out; + + protected override double GetProportionalDuration(ulong currentValue, ulong newValue) + { + return currentValue > newValue ? currentValue - newValue : newValue - currentValue; + } + + protected override string FormatCount(ulong count) + { + return $@"{count}x"; + } + + protected class TransformComboResult : 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 ComboResultCounter).VisibleCount = CurrentValue; + } + + public TransformComboResult(IClock clock) + : base(clock) + { + } + } + } +} diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index 209fae57b7..07b7fa7934 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -3,7 +3,6 @@ using OpenTK; using osu.Framework; -using osu.Game.Graphics.UserInterface; using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs index 84019739ea..2e1923ceb5 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -3,7 +3,6 @@ using OpenTK; using osu.Framework.Graphics.Transformations; -using osu.Game.Graphics.UserInterface; using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 0e51cd2452..82e98606c6 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -130,7 +130,8 @@ - + + From 10b47859c3a3de82de5ebd420bab05cee2facc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 18:04:00 -0500 Subject: [PATCH 23/30] Delay order on StarCounter changed --- osu.Game/Graphics/UserInterface/StarCounter.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index bfcd807962..e6874d7b9b 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -138,10 +138,7 @@ namespace osu.Game.Graphics.UserInterface transformStartTime = Time; for (int i = 0; i < MaxStars; i++) - { - stars[i].DelayReset(); transformStarQuick(i, count); - } } private float getStarScale(int i, float value) @@ -169,13 +166,13 @@ namespace osu.Game.Graphics.UserInterface { for (int i = 0; i < MaxStars; i++) { - stars[i].DelayReset(); stars[i].ClearTransformations(); if (currentValue <= newValue) stars[i].Delay(Math.Max(i - currentValue, 0) * animationDelay); else stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * animationDelay); transformStar(i, newValue); + stars[i].DelayReset(); } transformStartTime = Time; } From 84dcb63ad2d850f1c881a50a51e95282e5b9ac97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 18:06:31 -0500 Subject: [PATCH 24/30] Changed ComboCounter format... ...to improve value management. --- .../GameModes/Play/Catch/CatchComboCounter.cs | 30 +++++++++- osu.Game/GameModes/Play/ComboCounter.cs | 52 ++++++++++------ .../GameModes/Play/Mania/ManiaComboCounter.cs | 8 +-- .../GameModes/Play/Osu/OsuComboCounter.cs | 59 +++++++++++++------ .../GameModes/Play/Taiko/TaikoComboCounter.cs | 6 +- 5 files changed, 110 insertions(+), 45 deletions(-) diff --git a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs index cbd2c27add..1fe70b4dd8 100644 --- a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs +++ b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs @@ -18,16 +18,40 @@ namespace osu.Game.GameModes.Play.Catch { protected override bool CanPopOutWhileRolling => true; + protected virtual double FadeOutDelay => 1000; + protected virtual double FadeOutDuration => 300; + protected override string FormatCount(ulong count) { - return $@"{count:#,0}x"; + return $@"{count:#,0}"; } - public override void Roll(ulong newValue = 0) + protected override void OnCountChange(ulong currentValue, ulong newValue) + { + if (newValue != 0) + this.Show(); + base.OnCountChange(currentValue, newValue); + } + + protected override void OnCountRolling(ulong currentValue, ulong newValue) { PopOutSpriteText.Colour = CountSpriteText.Colour; + this.FadeOut(FadeOutDuration); + base.OnCountRolling(currentValue, newValue); + } - base.Roll(newValue); + protected override void OnCountIncrement(ulong currentValue, ulong newValue) + { + this.Show(); + base.OnCountIncrement(currentValue, newValue); + } + + protected override void transformPopOutSmall(ulong newValue) + { + base.transformPopOutSmall(newValue); + CountSpriteText.Delay(FadeOutDelay); + CountSpriteText.FadeOut(FadeOutDuration); + CountSpriteText.DelayReset(); } /// diff --git a/osu.Game/GameModes/Play/ComboCounter.cs b/osu.Game/GameModes/Play/ComboCounter.cs index 6cd166a300..1da5a920cc 100644 --- a/osu.Game/GameModes/Play/ComboCounter.cs +++ b/osu.Game/GameModes/Play/ComboCounter.cs @@ -19,9 +19,10 @@ namespace osu.Game.GameModes.Play { public abstract class ComboCounter : Container { - protected Type transformType => typeof(TransformCombo); - - protected bool IsRolling = false; + public bool IsRolling + { + get; protected set; + } protected SpriteText PopOutSpriteText; @@ -134,6 +135,7 @@ namespace osu.Game.GameModes.Play { base.Load(game); + CountSpriteText.Text = FormatCount(Count); CountSpriteText.Anchor = this.Anchor; CountSpriteText.Origin = this.Origin; @@ -143,10 +145,9 @@ namespace osu.Game.GameModes.Play /// /// Stops rollover animation, forcing the visible count to be the actual count. /// - public virtual void StopRolling() + public void StopRolling() { - Flush(false, typeof(TransformCombo)); - VisibleCount = Count; + setCount(Count); } /// @@ -177,18 +178,34 @@ namespace osu.Game.GameModes.Play return count.ToString(); } - protected abstract void OnCountRolling(ulong currentValue, ulong newValue); - protected abstract void OnCountIncrement(ulong newValue); - protected abstract void OnCountChange(ulong newValue); + protected abstract void OnVisibleCountRolling(ulong currentValue, ulong newValue); + protected abstract void OnVisibleCountIncrement(ulong newValue); + protected abstract void OnVisibleCountChange(ulong newValue); private void transformVisibleCount(ulong currentValue, ulong newValue, bool rolling) { if (rolling) - OnCountRolling(currentValue, newValue); + OnVisibleCountRolling(currentValue, newValue); else if (currentValue + 1 == newValue) - OnCountIncrement(newValue); + OnVisibleCountIncrement(newValue); else - OnCountChange(newValue); + OnVisibleCountChange(newValue); + } + + protected virtual void OnCountRolling(ulong currentValue, ulong newValue) + { + IsRolling = true; + transformRoll(new TransformCombo(Clock), currentValue, newValue); + } + + protected virtual void OnCountIncrement(ulong currentValue, ulong newValue) { + VisibleCount = currentValue; + VisibleCount = newValue; + } + + protected virtual void OnCountChange(ulong currentValue, ulong newValue) { + VisibleCount = currentValue; + VisibleCount = newValue; } private void transformCount( @@ -202,14 +219,13 @@ namespace osu.Game.GameModes.Play Flush(false, typeof(TransformCombo)); IsRolling = false; - VisibleCount = currentValue; - VisibleCount = newValue; + if (currentValue + 1 == newValue) + OnCountIncrement(currentValue, newValue); + else + OnCountChange(currentValue, newValue); } else - { - IsRolling = true; - transformRoll(new TransformCombo(Clock), visibleValue, newValue); - } + OnCountRolling(visibleCount, newValue); } private void transformRoll(TransformCombo transform, ulong currentValue, ulong newValue) diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs index ba37e65647..ee5d7da8b9 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -35,11 +35,11 @@ namespace osu.Game.GameModes.Play.Mania OriginalColour = Colour; } - public override void Roll(ulong newValue = 0) + protected override void OnCountRolling(ulong currentValue, ulong newValue) { - if (!IsRolling) + if (!IsRolling && newValue < currentValue) { - PopOutSpriteText.Text = FormatCount(VisibleCount); + PopOutSpriteText.Text = FormatCount(currentValue); PopOutSpriteText.FadeTo(PopOutInitialAlpha); PopOutSpriteText.ScaleTo(1.0f); @@ -48,7 +48,7 @@ namespace osu.Game.GameModes.Play.Mania PopOutSpriteText.ScaleTo(PopOutScale, PopOutDuration, PopOutEasing); } - base.Roll(newValue); + base.OnCountRolling(currentValue, newValue); } protected override void transformAnimate(ulong newValue) diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index 07b7fa7934..2c28cde552 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -21,7 +21,6 @@ namespace osu.Game.GameModes.Play.Osu protected virtual float PopOutSmallScale => 1.1f; protected virtual bool CanPopOutWhileRolling => false; - public Vector2 InnerCountPosition { get @@ -46,13 +45,12 @@ namespace osu.Game.GameModes.Play.Osu protected override string FormatCount(ulong count) { - return $@"{count:#,0}x"; + return $@"{count}x"; } - protected virtual void transformPopOut(ulong currentValue, ulong newValue) + protected virtual void transformPopOut(ulong newValue) { PopOutSpriteText.Text = FormatCount(newValue); - CountSpriteText.Text = FormatCount(currentValue); PopOutSpriteText.ScaleTo(PopOutScale); PopOutSpriteText.FadeTo(PopOutInitialAlpha); @@ -61,18 +59,16 @@ namespace osu.Game.GameModes.Play.Osu PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); PopOutSpriteText.MoveTo(CountSpriteText.Position, PopOutDuration, PopOutEasing); + } - ScheduledPopOutCurrentId++; - uint newTaskId = ScheduledPopOutCurrentId; - Scheduler.AddDelayed(delegate - { - scheduledPopOutSmall(newTaskId, newValue); - }, PopOutDuration); + protected virtual void transformPopOutRolling(ulong newValue) + { + transformPopOut(newValue); + transformPopOutSmall(newValue); } protected virtual void transformNoPopOut(ulong newValue) { - ScheduledPopOutCurrentId++; CountSpriteText.Text = FormatCount(newValue); CountSpriteText.ScaleTo(1); } @@ -84,16 +80,45 @@ namespace osu.Game.GameModes.Play.Osu CountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } - protected virtual void scheduledPopOutSmall(uint id, ulong newValue) + protected virtual void scheduledPopOutSmall(uint id) { // Too late; scheduled task invalidated if (id != ScheduledPopOutCurrentId) return; - transformPopOutSmall(newValue); + VisibleCount++; } protected override void OnCountRolling(ulong currentValue, ulong newValue) + { + ScheduledPopOutCurrentId++; + base.OnCountRolling(currentValue, newValue); + } + + protected override void OnCountIncrement(ulong currentValue, ulong newValue) + { + if (VisibleCount != currentValue) + VisibleCount++; + + CountSpriteText.Show(); + + transformPopOut(newValue); + + ScheduledPopOutCurrentId++; + uint newTaskId = ScheduledPopOutCurrentId; + Scheduler.AddDelayed(delegate + { + scheduledPopOutSmall(newTaskId); + }, PopOutDuration); + } + + protected override void OnCountChange(ulong currentValue, ulong newValue) + { + ScheduledPopOutCurrentId++; + base.OnCountChange(currentValue, newValue); + } + + protected override void OnVisibleCountRolling(ulong currentValue, ulong newValue) { if (newValue == 0) CountSpriteText.FadeOut(PopOutDuration); @@ -101,23 +126,23 @@ namespace osu.Game.GameModes.Play.Osu CountSpriteText.Show(); if (CanPopOutWhileRolling) - transformPopOut(currentValue, newValue); + transformPopOutRolling(newValue); else transformNoPopOut(newValue); } - protected override void OnCountChange(ulong newValue) + protected override void OnVisibleCountChange(ulong newValue) { CountSpriteText.FadeTo(newValue == 0 ? 0 : 1); transformNoPopOut(newValue); } - protected override void OnCountIncrement(ulong newValue) + protected override void OnVisibleCountIncrement(ulong newValue) { CountSpriteText.Show(); - transformPopOut(newValue - 1, newValue); + transformPopOutSmall(newValue); } } } diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs index 2e1923ceb5..8614762f95 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -40,7 +40,7 @@ namespace osu.Game.GameModes.Play.Taiko CountSpriteText.ScaleTo(1); } - protected override void OnCountRolling(ulong currentValue, ulong newValue) + protected override void OnVisibleCountRolling(ulong currentValue, ulong newValue) { if (newValue == 0) CountSpriteText.FadeOut(AnimationDuration); @@ -50,14 +50,14 @@ namespace osu.Game.GameModes.Play.Taiko transformNotAnimate(newValue); } - protected override void OnCountChange(ulong newValue) + protected override void OnVisibleCountChange(ulong newValue) { CountSpriteText.FadeTo(newValue == 0 ? 0 : 1); transformNotAnimate(newValue); } - protected override void OnCountIncrement(ulong newValue) + protected override void OnVisibleCountIncrement(ulong newValue) { CountSpriteText.Show(); From 862dc1d7c7a2c409e324cacd027cc7fdeb2bc14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 19:07:07 -0500 Subject: [PATCH 25/30] Tidying code and restricting methods --- .../Tests/TestCaseScoreCounter.cs | 1 + .../GameModes/Play/Catch/CatchComboCounter.cs | 27 ++-- osu.Game/GameModes/Play/ComboCounter.cs | 144 ++++++++---------- osu.Game/GameModes/Play/ComboResultCounter.cs | 2 +- .../GameModes/Play/Mania/ManiaComboCounter.cs | 4 +- .../GameModes/Play/Osu/OsuComboCounter.cs | 38 ++--- .../GameModes/Play/Taiko/TaikoComboCounter.cs | 28 ++-- .../UserInterface/PercentageCounter.cs | 2 +- .../Graphics/UserInterface/RollingCounter.cs | 36 ++--- .../Graphics/UserInterface/ScoreCounter.cs | 4 +- .../Graphics/UserInterface/StarCounter.cs | 6 +- 11 files changed, 137 insertions(+), 155 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 3cfd220beb..f1f9e449fd 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -112,6 +112,7 @@ namespace osu.Desktop.Tests { score.Count = 0; standardCombo.Count = 0; + taikoCombo.Count = 0; maniaCombo.Count = 0; catchCombo.Count = 0; numerator = denominator = 0; diff --git a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs index 1fe70b4dd8..dc87e65eec 100644 --- a/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs +++ b/osu.Game/GameModes/Play/Catch/CatchComboCounter.cs @@ -26,34 +26,37 @@ namespace osu.Game.GameModes.Play.Catch return $@"{count:#,0}"; } + private void animateFade() + { + Show(); + Delay(FadeOutDelay); + FadeOut(FadeOutDuration); + DelayReset(); + } + protected override void OnCountChange(ulong currentValue, ulong newValue) { if (newValue != 0) - this.Show(); + animateFade(); base.OnCountChange(currentValue, newValue); } protected override void OnCountRolling(ulong currentValue, ulong newValue) { - PopOutSpriteText.Colour = CountSpriteText.Colour; - this.FadeOut(FadeOutDuration); + if (!IsRolling) + { + PopOutSpriteText.Colour = DisplayedCountSpriteText.Colour; + FadeOut(FadeOutDuration); + } base.OnCountRolling(currentValue, newValue); } protected override void OnCountIncrement(ulong currentValue, ulong newValue) { - this.Show(); + animateFade(); base.OnCountIncrement(currentValue, newValue); } - protected override void transformPopOutSmall(ulong newValue) - { - base.transformPopOutSmall(newValue); - CountSpriteText.Delay(FadeOutDelay); - CountSpriteText.FadeOut(FadeOutDuration); - CountSpriteText.DelayReset(); - } - /// /// Increaces counter and tints pop-out before animation. /// diff --git a/osu.Game/GameModes/Play/ComboCounter.cs b/osu.Game/GameModes/Play/ComboCounter.cs index 1da5a920cc..f0ab9107c8 100644 --- a/osu.Game/GameModes/Play/ComboCounter.cs +++ b/osu.Game/GameModes/Play/ComboCounter.cs @@ -32,13 +32,7 @@ namespace osu.Game.GameModes.Play protected virtual float PopOutInitialAlpha => 0.75f; /// - /// If true, the roll-down duration will be proportional to the counter. - /// - protected virtual bool IsRollingProportional => true; - - /// - /// If IsRollingProportional = false, duration in milliseconds for the counter roll-up animation for each - /// element; else duration in milliseconds for the counter roll-up animation in total. + /// Duration in milliseconds for the counter roll-up animation for each element. /// protected virtual double RollingDuration => 20; @@ -47,25 +41,23 @@ namespace osu.Game.GameModes.Play /// protected EasingTypes RollingEasing => EasingTypes.None; - private ulong prevVisibleCount; - private ulong visibleCount; + private ulong prevDisplayedCount; + private ulong displayedCount; /// /// Value shown at the current moment. /// - public virtual ulong VisibleCount + public virtual ulong DisplayedCount { get { - return visibleCount; + return displayedCount; } protected set { - if (visibleCount.Equals(value)) + if (displayedCount.Equals(value)) return; - prevVisibleCount = visibleCount; - visibleCount = value; - transformVisibleCount(prevVisibleCount, visibleCount, IsRolling); + updateDisplayedCount(displayedCount, value, IsRolling); } } @@ -83,21 +75,11 @@ namespace osu.Game.GameModes.Play } set { - setCount(value); + updateCount(value); } } - private void setCount(ulong value, bool rolling = false) - { - prevCount = count; - count = value; - if (IsLoaded) - { - transformCount(VisibleCount, prevCount, value, rolling); - } - } - - protected SpriteText CountSpriteText; + protected SpriteText DisplayedCountSpriteText; private float textSize = 20.0f; public float TextSize @@ -106,7 +88,7 @@ namespace osu.Game.GameModes.Play set { textSize = value; - CountSpriteText.TextSize = TextSize; + DisplayedCountSpriteText.TextSize = TextSize; PopOutSpriteText.TextSize = TextSize; } } @@ -118,7 +100,7 @@ namespace osu.Game.GameModes.Play { Children = new Drawable[] { - CountSpriteText = new SpriteText + DisplayedCountSpriteText = new SpriteText { Anchor = this.Anchor, Origin = this.Origin, @@ -135,19 +117,19 @@ namespace osu.Game.GameModes.Play { base.Load(game); - CountSpriteText.Text = FormatCount(Count); - CountSpriteText.Anchor = this.Anchor; - CountSpriteText.Origin = this.Origin; + DisplayedCountSpriteText.Text = FormatCount(Count); + DisplayedCountSpriteText.Anchor = this.Anchor; + DisplayedCountSpriteText.Origin = this.Origin; StopRolling(); } /// - /// Stops rollover animation, forcing the visible count to be the actual count. + /// Stops rollover animation, forcing the displayed count to be the actual count. /// public void StopRolling() { - setCount(Count); + updateCount(Count); } /// @@ -156,7 +138,7 @@ namespace osu.Game.GameModes.Play /// Target value. public virtual void Roll(ulong newValue = 0) { - setCount(newValue, true); + updateCount(newValue, true); } /// @@ -164,13 +146,7 @@ namespace osu.Game.GameModes.Play /// public virtual void ResetCount() { - Count = default(ulong); - } - - protected double GetProportionalDuration(ulong currentValue, ulong newValue) - { - double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; - return difference * RollingDuration; + updateCount(0); } protected virtual string FormatCount(ulong count) @@ -178,76 +154,78 @@ namespace osu.Game.GameModes.Play return count.ToString(); } - protected abstract void OnVisibleCountRolling(ulong currentValue, ulong newValue); - protected abstract void OnVisibleCountIncrement(ulong newValue); - protected abstract void OnVisibleCountChange(ulong newValue); - - private void transformVisibleCount(ulong currentValue, ulong newValue, bool rolling) - { - if (rolling) - OnVisibleCountRolling(currentValue, newValue); - else if (currentValue + 1 == newValue) - OnVisibleCountIncrement(newValue); - else - OnVisibleCountChange(newValue); - } + protected abstract void OnDisplayedCountRolling(ulong currentValue, ulong newValue); + protected abstract void OnDisplayedCountIncrement(ulong newValue); + protected abstract void OnDisplayedCountChange(ulong newValue); protected virtual void OnCountRolling(ulong currentValue, ulong newValue) { - IsRolling = true; - transformRoll(new TransformCombo(Clock), currentValue, newValue); + transformRoll(new TransformComboRoll(Clock), currentValue, newValue); } protected virtual void OnCountIncrement(ulong currentValue, ulong newValue) { - VisibleCount = currentValue; - VisibleCount = newValue; + DisplayedCount = newValue; } protected virtual void OnCountChange(ulong currentValue, ulong newValue) { - VisibleCount = currentValue; - VisibleCount = newValue; + DisplayedCount = newValue; } - private void transformCount( - ulong visibleValue, - ulong currentValue, - ulong newValue, - bool rolling) + private double getProportionalDuration(ulong currentValue, ulong newValue) { + double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + return difference * RollingDuration; + } + + private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling) + { + prevDisplayedCount = currentValue; + displayedCount = newValue; + if (rolling) + OnDisplayedCountRolling(currentValue, newValue); + else if (currentValue + 1 == newValue) + OnDisplayedCountIncrement(newValue); + else + OnDisplayedCountChange(newValue); + } + + private void updateCount(ulong value, bool rolling = false) + { + prevCount = count; + count = value; if (!rolling) { - Flush(false, typeof(TransformCombo)); + Flush(false, typeof(TransformComboRoll)); IsRolling = false; + DisplayedCount = prevCount; - if (currentValue + 1 == newValue) - OnCountIncrement(currentValue, newValue); + if (prevCount + 1 == count) + OnCountIncrement(prevCount, count); else - OnCountChange(currentValue, newValue); + OnCountChange(prevCount, count); } else - OnCountRolling(visibleCount, newValue); + { + OnCountRolling(displayedCount, count); + IsRolling = true; + } } - private void transformRoll(TransformCombo transform, ulong currentValue, ulong newValue) + private void transformRoll(TransformComboRoll transform, ulong currentValue, ulong newValue) { - Flush(false, typeof(TransformCombo)); + Flush(false, typeof(TransformComboRoll)); if (Clock == null) return; if (RollingDuration == 0) { - VisibleCount = Count; + DisplayedCount = Count; return; } - double rollingTotalDuration = - IsRollingProportional - ? GetProportionalDuration(currentValue, newValue) - : RollingDuration; - transform.StartTime = Time; - transform.EndTime = Time + rollingTotalDuration; + transform.EndTime = Time + getProportionalDuration(currentValue, newValue); transform.StartValue = currentValue; transform.EndValue = newValue; transform.Easing = RollingEasing; @@ -255,7 +233,7 @@ namespace osu.Game.GameModes.Play Transforms.Add(transform); } - protected class TransformCombo : Transform + protected class TransformComboRoll : Transform { public override ulong CurrentValue { @@ -272,10 +250,10 @@ namespace osu.Game.GameModes.Play public override void Apply(Drawable d) { base.Apply(d); - (d as ComboCounter).VisibleCount = CurrentValue; + (d as ComboCounter).DisplayedCount = CurrentValue; } - public TransformCombo(IClock clock) + public TransformComboRoll(IClock clock) : base(clock) { } diff --git a/osu.Game/GameModes/Play/ComboResultCounter.cs b/osu.Game/GameModes/Play/ComboResultCounter.cs index c01edc180d..90e40e3077 100644 --- a/osu.Game/GameModes/Play/ComboResultCounter.cs +++ b/osu.Game/GameModes/Play/ComboResultCounter.cs @@ -51,7 +51,7 @@ namespace osu.Game.GameModes.Play.UserInterface public override void Apply(Drawable d) { base.Apply(d); - (d as ComboResultCounter).VisibleCount = CurrentValue; + (d as ComboResultCounter).DisplayedCount = CurrentValue; } public TransformComboResult(IClock clock) diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs index ee5d7da8b9..86349115e9 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -54,8 +54,8 @@ namespace osu.Game.GameModes.Play.Mania protected override void transformAnimate(ulong newValue) { base.transformAnimate(newValue); - CountSpriteText.FadeColour(TintColour, 0); - CountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing); + DisplayedCountSpriteText.FadeColour(TintColour, 0); + DisplayedCountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing); } } } diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index 2c28cde552..946d672655 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -25,11 +25,11 @@ namespace osu.Game.GameModes.Play.Osu { get { - return CountSpriteText.Position; + return DisplayedCountSpriteText.Position; } set { - CountSpriteText.Position = value; + DisplayedCountSpriteText.Position = value; } } @@ -58,7 +58,7 @@ namespace osu.Game.GameModes.Play.Osu PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing); - PopOutSpriteText.MoveTo(CountSpriteText.Position, PopOutDuration, PopOutEasing); + PopOutSpriteText.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing); } protected virtual void transformPopOutRolling(ulong newValue) @@ -69,15 +69,15 @@ namespace osu.Game.GameModes.Play.Osu protected virtual void transformNoPopOut(ulong newValue) { - CountSpriteText.Text = FormatCount(newValue); - CountSpriteText.ScaleTo(1); + DisplayedCountSpriteText.Text = FormatCount(newValue); + DisplayedCountSpriteText.ScaleTo(1); } protected virtual void transformPopOutSmall(ulong newValue) { - CountSpriteText.Text = FormatCount(newValue); - CountSpriteText.ScaleTo(PopOutSmallScale); - CountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); + DisplayedCountSpriteText.Text = FormatCount(newValue); + DisplayedCountSpriteText.ScaleTo(PopOutSmallScale); + DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } protected virtual void scheduledPopOutSmall(uint id) @@ -86,7 +86,7 @@ namespace osu.Game.GameModes.Play.Osu if (id != ScheduledPopOutCurrentId) return; - VisibleCount++; + DisplayedCount++; } protected override void OnCountRolling(ulong currentValue, ulong newValue) @@ -97,10 +97,10 @@ namespace osu.Game.GameModes.Play.Osu protected override void OnCountIncrement(ulong currentValue, ulong newValue) { - if (VisibleCount != currentValue) - VisibleCount++; + while (DisplayedCount != currentValue) + DisplayedCount++; - CountSpriteText.Show(); + DisplayedCountSpriteText.Show(); transformPopOut(newValue); @@ -118,12 +118,12 @@ namespace osu.Game.GameModes.Play.Osu base.OnCountChange(currentValue, newValue); } - protected override void OnVisibleCountRolling(ulong currentValue, ulong newValue) + protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue) { if (newValue == 0) - CountSpriteText.FadeOut(PopOutDuration); + DisplayedCountSpriteText.FadeOut(PopOutDuration); else - CountSpriteText.Show(); + DisplayedCountSpriteText.Show(); if (CanPopOutWhileRolling) transformPopOutRolling(newValue); @@ -131,16 +131,16 @@ namespace osu.Game.GameModes.Play.Osu transformNoPopOut(newValue); } - protected override void OnVisibleCountChange(ulong newValue) + protected override void OnDisplayedCountChange(ulong newValue) { - CountSpriteText.FadeTo(newValue == 0 ? 0 : 1); + DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); transformNoPopOut(newValue); } - protected override void OnVisibleCountIncrement(ulong newValue) + protected override void OnDisplayedCountIncrement(ulong newValue) { - CountSpriteText.Show(); + DisplayedCountSpriteText.Show(); transformPopOutSmall(newValue); } diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs index 8614762f95..97f050b3e1 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -23,43 +23,43 @@ namespace osu.Game.GameModes.Play.Taiko public TaikoComboCounter() { - CountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre; - CountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre; + DisplayedCountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre; + DisplayedCountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre; } protected virtual void transformAnimate(ulong newValue) { - CountSpriteText.Text = FormatCount(newValue); - CountSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); - CountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing); + DisplayedCountSpriteText.Text = FormatCount(newValue); + DisplayedCountSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); + DisplayedCountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing); } protected virtual void transformNotAnimate(ulong newValue) { - CountSpriteText.Text = FormatCount(newValue); - CountSpriteText.ScaleTo(1); + DisplayedCountSpriteText.Text = FormatCount(newValue); + DisplayedCountSpriteText.ScaleTo(1); } - protected override void OnVisibleCountRolling(ulong currentValue, ulong newValue) + protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue) { if (newValue == 0) - CountSpriteText.FadeOut(AnimationDuration); + DisplayedCountSpriteText.FadeOut(AnimationDuration); else - CountSpriteText.Show(); + DisplayedCountSpriteText.Show(); transformNotAnimate(newValue); } - protected override void OnVisibleCountChange(ulong newValue) + protected override void OnDisplayedCountChange(ulong newValue) { - CountSpriteText.FadeTo(newValue == 0 ? 0 : 1); + DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); transformNotAnimate(newValue); } - protected override void OnVisibleCountIncrement(ulong newValue) + protected override void OnDisplayedCountIncrement(ulong newValue) { - CountSpriteText.Show(); + DisplayedCountSpriteText.Show(); transformAnimate(newValue); } diff --git a/osu.Game/Graphics/UserInterface/PercentageCounter.cs b/osu.Game/Graphics/UserInterface/PercentageCounter.cs index 844afaa00e..fe2a5024eb 100644 --- a/osu.Game/Graphics/UserInterface/PercentageCounter.cs +++ b/osu.Game/Graphics/UserInterface/PercentageCounter.cs @@ -50,7 +50,7 @@ namespace osu.Game.Graphics.UserInterface public override void Apply(Drawable d) { base.Apply(d); - (d as PercentageCounter).VisibleCount = CurrentValue; + (d as PercentageCounter).DisplayedCount = CurrentValue; } public TransformAccuracy(IClock clock) diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 968b5abfa8..8a0e03ad24 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -25,7 +25,7 @@ namespace osu.Game.Graphics.UserInterface /// protected virtual Type TransformType => typeof(Transform); - protected SpriteText CountSpriteText; + protected SpriteText DisplayedCountSpriteText; /// /// If true, the roll-up duration will be proportional to change in value. @@ -43,24 +43,24 @@ namespace osu.Game.Graphics.UserInterface /// public virtual EasingTypes RollingEasing => EasingTypes.None; - private T prevVisibleCount; - private T visibleCount; + private T prevDisplayedCount; + private T displayedCount; /// /// Value shown at the current moment. /// - public virtual T VisibleCount + public virtual T DisplayedCount { get { - return visibleCount; + return displayedCount; } protected set { - if (visibleCount.Equals(value)) + if (displayedCount.Equals(value)) return; - visibleCount = value; - CountSpriteText.Text = FormatCount(value); + displayedCount = value; + DisplayedCountSpriteText.Text = FormatCount(value); } } @@ -82,7 +82,7 @@ namespace osu.Game.Graphics.UserInterface count = value; if (IsLoaded) { - TransformCount(visibleCount, count); + TransformCount(displayedCount, count); } } } @@ -95,7 +95,7 @@ namespace osu.Game.Graphics.UserInterface set { textSize = value; - CountSpriteText.TextSize = value; + DisplayedCountSpriteText.TextSize = value; } } @@ -111,7 +111,7 @@ namespace osu.Game.Graphics.UserInterface Children = new Drawable[] { - CountSpriteText = new SpriteText + DisplayedCountSpriteText = new SpriteText { Anchor = this.Anchor, Origin = this.Origin, @@ -125,11 +125,11 @@ namespace osu.Game.Graphics.UserInterface Flush(false, TransformType); - VisibleCount = Count; + DisplayedCount = Count; - CountSpriteText.Text = FormatCount(count); - CountSpriteText.Anchor = this.Anchor; - CountSpriteText.Origin = this.Origin; + DisplayedCountSpriteText.Text = FormatCount(count); + DisplayedCountSpriteText.Anchor = this.Anchor; + DisplayedCountSpriteText.Origin = this.Origin; } /// @@ -143,12 +143,12 @@ namespace osu.Game.Graphics.UserInterface } /// - /// Stops rollover animation, forcing the visible count to be the actual count. + /// Stops rollover animation, forcing the displayed count to be the actual count. /// public virtual void StopRolling() { Flush(false, TransformType); - VisibleCount = Count; + DisplayedCount = Count; } /// @@ -212,7 +212,7 @@ namespace osu.Game.Graphics.UserInterface if (RollingDuration == 0) { - VisibleCount = Count; + DisplayedCount = Count; return; } diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index a47aca738e..b565107f55 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -35,7 +35,7 @@ namespace osu.Game.Graphics.UserInterface /// How many leading zeroes the counter will have. public ScoreCounter(uint leading = 0) { - CountSpriteText.FixedWidth = true; + DisplayedCountSpriteText.FixedWidth = true; LeadingZeroes = leading; } @@ -66,7 +66,7 @@ namespace osu.Game.Graphics.UserInterface public override void Apply(Drawable d) { base.Apply(d); - (d as ScoreCounter).VisibleCount = CurrentValue; + (d as ScoreCounter).DisplayedCount = CurrentValue; } public TransformScore(IClock clock) diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index e6874d7b9b..732c882540 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -84,10 +84,10 @@ namespace osu.Game.Graphics.UserInterface /// /// Shows a float count as stars. Used as star difficulty display. /// - /// Maximum amount of stars to display. - public StarCounter(int stars = 10) + /// Maximum amount of stars to display. + public StarCounter(int maxstars = 10) { - MaxStars = Math.Max(stars, 0); + MaxStars = Math.Max(maxstars, 0); Children = new Drawable[] { From 15c6a563be8a09fa165f0935dfb0870a22f14240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sat, 15 Oct 2016 22:24:03 -0500 Subject: [PATCH 26/30] Moved ComboResultCounter to right namespace --- osu.Game/GameModes/Play/ComboResultCounter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/GameModes/Play/ComboResultCounter.cs b/osu.Game/GameModes/Play/ComboResultCounter.cs index 90e40e3077..10f167465f 100644 --- a/osu.Game/GameModes/Play/ComboResultCounter.cs +++ b/osu.Game/GameModes/Play/ComboResultCounter.cs @@ -12,7 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace osu.Game.GameModes.Play.UserInterface +namespace osu.Game.GameModes.Play { /// /// Used to display combo with a roll-up animation in results screen. From 2c06764b799871686408b1fed6f4334e77015b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 16 Oct 2016 17:10:08 -0500 Subject: [PATCH 27/30] Better safe than sorry --- osu.Game/GameModes/Play/Osu/OsuComboCounter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index 946d672655..bbad689643 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -97,14 +97,15 @@ namespace osu.Game.GameModes.Play.Osu protected override void OnCountIncrement(ulong currentValue, ulong newValue) { - while (DisplayedCount != currentValue) + ScheduledPopOutCurrentId++; + + if (DisplayedCount < currentValue) DisplayedCount++; DisplayedCountSpriteText.Show(); transformPopOut(newValue); - - ScheduledPopOutCurrentId++; + uint newTaskId = ScheduledPopOutCurrentId; Scheduler.AddDelayed(delegate { From a671765a4f918cb6745c6e94733133d41186d219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 16 Oct 2016 17:45:37 -0500 Subject: [PATCH 28/30] Modified ManiaComboCounter behavior This to match more with the current behavior in osu!mania. --- .../Tests/TestCaseScoreCounter.cs | 13 ++++++- .../GameModes/Play/Mania/ManiaComboCounter.cs | 35 +++++++++++++++---- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index f1f9e449fd..d7ce54ad46 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -32,6 +32,8 @@ namespace osu.Desktop.Tests int numerator = 0, denominator = 0; + bool maniaHold = false; + ScoreCounter score = new ScoreCounter(7) { Origin = Anchor.TopRight, @@ -72,7 +74,7 @@ namespace osu.Desktop.Tests }; Add(taikoCombo); - ComboCounter maniaCombo = new ManiaComboCounter + ManiaComboCounter maniaCombo = new ManiaComboCounter { Origin = Anchor.Centre, Anchor = Anchor.Centre, @@ -147,6 +149,15 @@ namespace osu.Desktop.Tests accuracyCombo.SetFraction(numerator, denominator); }); + AddButton(@"mania hold", delegate + { + if (!maniaHold) + maniaCombo.HoldStart(); + else + maniaCombo.HoldEnd(); + maniaHold = !maniaHold; + }); + AddButton(@"Alter stars", delegate { stars.Count = RNG.NextSingle() * (stars.MaxStars + 1); diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs index 86349115e9..454c6a810d 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -4,6 +4,7 @@ using OpenTK.Graphics; using osu.Framework; using osu.Framework.Graphics; +using osu.Framework.Graphics.Transformations; using osu.Game.GameModes.Play.Taiko; using System; using System.Collections.Generic; @@ -18,9 +19,14 @@ namespace osu.Game.GameModes.Play.Mania /// public class ManiaComboCounter : TaikoComboCounter { + protected ushort KeysHeld = 0; + protected Color4 OriginalColour; - protected Color4 TintColour => Color4.OrangeRed; + protected Color4 TintColour => Color4.Orange; + protected EasingTypes TintEasing => EasingTypes.None; + protected int TintDuration => 500; + protected Color4 PopOutColor => Color4.Red; protected override float PopOutInitialAlpha => 1.0f; protected override ulong PopOutDuration => 300; @@ -32,7 +38,7 @@ namespace osu.Game.GameModes.Play.Mania PopOutSpriteText.Anchor = Anchor.BottomCentre; PopOutSpriteText.Origin = Anchor.Centre; PopOutSpriteText.FadeColour(PopOutColor, 0); - OriginalColour = Colour; + OriginalColour = DisplayedCountSpriteText.Colour; } protected override void OnCountRolling(ulong currentValue, ulong newValue) @@ -51,11 +57,28 @@ namespace osu.Game.GameModes.Play.Mania base.OnCountRolling(currentValue, newValue); } - protected override void transformAnimate(ulong newValue) + /// + /// Tints text while holding a key. + /// + /// + /// Does not alter combo. This has to be done depending of the scoring system. + /// (i.e. v1 = each period of time; v2 = when starting and ending a key hold) + /// + public void HoldStart() { - base.transformAnimate(newValue); - DisplayedCountSpriteText.FadeColour(TintColour, 0); - DisplayedCountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing); + if (KeysHeld == 0) + DisplayedCountSpriteText.FadeColour(TintColour, TintDuration, TintEasing); + KeysHeld++; + } + + /// + /// Ends tinting. + /// + public void HoldEnd() + { + KeysHeld--; + if (KeysHeld == 0) + DisplayedCountSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing); } } } From 72c4dc344ef1b83dc879cf273384379a4592576b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Sun, 16 Oct 2016 18:30:25 -0500 Subject: [PATCH 29/30] Misc. fixes and improvements --- .../Tests/TestCaseScoreCounter.cs | 19 +++++++------- osu.Game/GameModes/Play/ComboCounter.cs | 20 ++++++++------ .../GameModes/Play/Mania/ManiaComboCounter.cs | 2 +- .../GameModes/Play/Osu/OsuComboCounter.cs | 26 +++++++++---------- .../GameModes/Play/Taiko/TaikoComboCounter.cs | 10 +++---- .../Graphics/UserInterface/RollingCounter.cs | 20 ++++++-------- .../Graphics/UserInterface/StarCounter.cs | 18 +++++++++---- 7 files changed, 62 insertions(+), 53 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index d7ce54ad46..0fac933dc0 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -93,23 +93,24 @@ namespace osu.Desktop.Tests }; Add(accuracyCombo); - SpriteText starsLabel = new SpriteText - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Position = new Vector2(20, 190), - Text = @"- unset -", - }; - Add(starsLabel); - StarCounter stars = new StarCounter { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Position = new Vector2(20, 160), + Count = 5, }; Add(stars); + SpriteText starsLabel = new SpriteText + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Position = new Vector2(20, 190), + Text = stars.Count.ToString("0.00"), + }; + Add(starsLabel); + AddButton(@"Reset all", delegate { score.Count = 0; diff --git a/osu.Game/GameModes/Play/ComboCounter.cs b/osu.Game/GameModes/Play/ComboCounter.cs index f0ab9107c8..cd3dac77aa 100644 --- a/osu.Game/GameModes/Play/ComboCounter.cs +++ b/osu.Game/GameModes/Play/ComboCounter.cs @@ -26,7 +26,7 @@ namespace osu.Game.GameModes.Play protected SpriteText PopOutSpriteText; - protected virtual ulong PopOutDuration => 150; + protected virtual double PopOutDuration => 150; protected virtual float PopOutScale => 2.0f; protected virtual EasingTypes PopOutEasing => EasingTypes.None; protected virtual float PopOutInitialAlpha => 0.75f; @@ -41,7 +41,6 @@ namespace osu.Game.GameModes.Play /// protected EasingTypes RollingEasing => EasingTypes.None; - private ulong prevDisplayedCount; private ulong displayedCount; /// @@ -102,8 +101,6 @@ namespace osu.Game.GameModes.Play { DisplayedCountSpriteText = new SpriteText { - Anchor = this.Anchor, - Origin = this.Origin, Alpha = 0, }, PopOutSpriteText = new SpriteText @@ -132,11 +129,19 @@ namespace osu.Game.GameModes.Play updateCount(Count); } + /// + /// Animates roll-back to 0. + /// + public void Roll() + { + Roll(0); + } + /// /// Animates roll-up/roll-back to an specific value. /// /// Target value. - public virtual void Roll(ulong newValue = 0) + public virtual void Roll(ulong newValue) { updateCount(newValue, true); } @@ -173,13 +178,12 @@ namespace osu.Game.GameModes.Play private double getProportionalDuration(ulong currentValue, ulong newValue) { - double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue; + double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue; return difference * RollingDuration; } private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling) { - prevDisplayedCount = currentValue; displayedCount = newValue; if (rolling) OnDisplayedCountRolling(currentValue, newValue); @@ -218,7 +222,7 @@ namespace osu.Game.GameModes.Play if (Clock == null) return; - if (RollingDuration == 0) + if (RollingDuration < 1) { DisplayedCount = Count; return; diff --git a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs index 454c6a810d..58fd92c73b 100644 --- a/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs +++ b/osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs @@ -29,7 +29,7 @@ namespace osu.Game.GameModes.Play.Mania protected Color4 PopOutColor => Color4.Red; protected override float PopOutInitialAlpha => 1.0f; - protected override ulong PopOutDuration => 300; + protected override double PopOutDuration => 300; public override void Load(BaseGame game) { diff --git a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs index bbad689643..253d1c7f8e 100644 --- a/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs +++ b/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs @@ -48,7 +48,7 @@ namespace osu.Game.GameModes.Play.Osu return $@"{count}x"; } - protected virtual void transformPopOut(ulong newValue) + protected virtual void TransformPopOut(ulong newValue) { PopOutSpriteText.Text = FormatCount(newValue); @@ -61,26 +61,26 @@ namespace osu.Game.GameModes.Play.Osu PopOutSpriteText.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing); } - protected virtual void transformPopOutRolling(ulong newValue) + protected virtual void TransformPopOutRolling(ulong newValue) { - transformPopOut(newValue); - transformPopOutSmall(newValue); + TransformPopOut(newValue); + TransformPopOutSmall(newValue); } - protected virtual void transformNoPopOut(ulong newValue) + protected virtual void TransformNoPopOut(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(1); } - protected virtual void transformPopOutSmall(ulong newValue) + protected virtual void TransformPopOutSmall(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(PopOutSmallScale); DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing); } - protected virtual void scheduledPopOutSmall(uint id) + protected virtual void ScheduledPopOutSmall(uint id) { // Too late; scheduled task invalidated if (id != ScheduledPopOutCurrentId) @@ -104,12 +104,12 @@ namespace osu.Game.GameModes.Play.Osu DisplayedCountSpriteText.Show(); - transformPopOut(newValue); + TransformPopOut(newValue); uint newTaskId = ScheduledPopOutCurrentId; Scheduler.AddDelayed(delegate { - scheduledPopOutSmall(newTaskId); + ScheduledPopOutSmall(newTaskId); }, PopOutDuration); } @@ -127,23 +127,23 @@ namespace osu.Game.GameModes.Play.Osu DisplayedCountSpriteText.Show(); if (CanPopOutWhileRolling) - transformPopOutRolling(newValue); + TransformPopOutRolling(newValue); else - transformNoPopOut(newValue); + TransformNoPopOut(newValue); } protected override void OnDisplayedCountChange(ulong newValue) { DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); - transformNoPopOut(newValue); + TransformNoPopOut(newValue); } protected override void OnDisplayedCountIncrement(ulong newValue) { DisplayedCountSpriteText.Show(); - transformPopOutSmall(newValue); + TransformPopOutSmall(newValue); } } } diff --git a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs index 97f050b3e1..bd12d35315 100644 --- a/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs +++ b/osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs @@ -27,14 +27,14 @@ namespace osu.Game.GameModes.Play.Taiko DisplayedCountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre; } - protected virtual void transformAnimate(ulong newValue) + protected virtual void TransformAnimate(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(new Vector2(1, ScaleFactor)); DisplayedCountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing); } - protected virtual void transformNotAnimate(ulong newValue) + protected virtual void TransformNotAnimate(ulong newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(1); @@ -47,21 +47,21 @@ namespace osu.Game.GameModes.Play.Taiko else DisplayedCountSpriteText.Show(); - transformNotAnimate(newValue); + TransformNotAnimate(newValue); } protected override void OnDisplayedCountChange(ulong newValue) { DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); - transformNotAnimate(newValue); + TransformNotAnimate(newValue); } protected override void OnDisplayedCountIncrement(ulong newValue) { DisplayedCountSpriteText.Show(); - transformAnimate(newValue); + TransformAnimate(newValue); } } } diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index 8a0e03ad24..e04a3b92b3 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -43,7 +43,6 @@ namespace osu.Game.Graphics.UserInterface /// public virtual EasingTypes RollingEasing => EasingTypes.None; - private T prevDisplayedCount; private T displayedCount; /// @@ -104,18 +103,9 @@ namespace osu.Game.Graphics.UserInterface /// protected RollingCounter() { - Debug.Assert( - TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), - @"transformType should be a subclass of Transform." - ); - Children = new Drawable[] { - DisplayedCountSpriteText = new SpriteText - { - Anchor = this.Anchor, - Origin = this.Origin, - }, + DisplayedCountSpriteText = new SpriteText(), }; } @@ -195,6 +185,12 @@ namespace osu.Game.Graphics.UserInterface protected virtual void TransformCount(T currentValue, T newValue) { object[] parameters = { Clock }; + + Debug.Assert( + TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), + @"transformType should be a subclass of Transform." + ); + TransformCount((Transform)Activator.CreateInstance(TransformType, parameters), currentValue, newValue); } @@ -210,7 +206,7 @@ namespace osu.Game.Graphics.UserInterface if (Clock == null) return; - if (RollingDuration == 0) + if (RollingDuration < 1) { DisplayedCount = Count; return; diff --git a/osu.Game/Graphics/UserInterface/StarCounter.cs b/osu.Game/Graphics/UserInterface/StarCounter.cs index 732c882540..381347a401 100644 --- a/osu.Game/Graphics/UserInterface/StarCounter.cs +++ b/osu.Game/Graphics/UserInterface/StarCounter.cs @@ -17,8 +17,8 @@ namespace osu.Game.Graphics.UserInterface { public class StarCounter : AutoSizeContainer { - private Container starContainer; - private List stars = new List(); + private readonly Container starContainer; + private readonly List stars = new List(); private double transformStartTime = 0; @@ -81,11 +81,17 @@ namespace osu.Game.Graphics.UserInterface } } + /// + /// Shows a float count as stars (up to 10). Used as star difficulty display. + /// + public StarCounter() : this(10) { + } + /// /// Shows a float count as stars. Used as star difficulty display. /// /// Maximum amount of stars to display. - public StarCounter(int maxstars = 10) + public StarCounter(int maxstars) { MaxStars = Math.Max(maxstars, 0); @@ -114,6 +120,8 @@ namespace osu.Game.Graphics.UserInterface Anchor = Anchor.CentreLeft, Origin = Anchor.Centre, TextSize = StarSize, + Scale = new Vector2(minStarScale), + Alpha = minStarAlpha, Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0), }; @@ -122,8 +130,8 @@ namespace osu.Game.Graphics.UserInterface starContainer.Add(star); } - // Used to recreate initial state. - StopAnimation(); + // Animate initial state from zero. + transformCount(0, Count); } public void ResetCount() From eeacd85073dbf75db620f31fa41dd60d245e793f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Mon, 17 Oct 2016 21:40:50 -0500 Subject: [PATCH 30/30] Protect RollingCounter props --- osu.Game/GameModes/Play/ComboResultCounter.cs | 4 ++-- osu.Game/Graphics/UserInterface/PercentageCounter.cs | 4 ++-- osu.Game/Graphics/UserInterface/RollingCounter.cs | 6 +++--- osu.Game/Graphics/UserInterface/ScoreCounter.cs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game/GameModes/Play/ComboResultCounter.cs b/osu.Game/GameModes/Play/ComboResultCounter.cs index 10f167465f..e86a845375 100644 --- a/osu.Game/GameModes/Play/ComboResultCounter.cs +++ b/osu.Game/GameModes/Play/ComboResultCounter.cs @@ -21,8 +21,8 @@ namespace osu.Game.GameModes.Play { protected override Type TransformType => typeof(TransformComboResult); - public override double RollingDuration => 500; - public override EasingTypes RollingEasing => EasingTypes.Out; + protected override double RollingDuration => 500; + protected override EasingTypes RollingEasing => EasingTypes.Out; protected override double GetProportionalDuration(ulong currentValue, ulong newValue) { diff --git a/osu.Game/Graphics/UserInterface/PercentageCounter.cs b/osu.Game/Graphics/UserInterface/PercentageCounter.cs index fe2a5024eb..d405a756c6 100644 --- a/osu.Game/Graphics/UserInterface/PercentageCounter.cs +++ b/osu.Game/Graphics/UserInterface/PercentageCounter.cs @@ -20,8 +20,8 @@ namespace osu.Game.Graphics.UserInterface { protected override Type TransformType => typeof(TransformAccuracy); - public override double RollingDuration => 500; - public override EasingTypes RollingEasing => EasingTypes.Out; + protected override double RollingDuration => 20; + protected override bool IsRollingProportional => true; private float epsilon => 1e-10f; diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index e04a3b92b3..8c887ba9ae 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -30,18 +30,18 @@ namespace osu.Game.Graphics.UserInterface /// /// If true, the roll-up duration will be proportional to change in value. /// - public bool IsRollingProportional = false; + protected virtual bool IsRollingProportional => false; /// /// 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 virtual double RollingDuration => 0; + protected virtual double RollingDuration => 0; /// /// Easing for the counter rollover animation. /// - public virtual EasingTypes RollingEasing => EasingTypes.None; + protected virtual EasingTypes RollingEasing => EasingTypes.None; private T displayedCount; diff --git a/osu.Game/Graphics/UserInterface/ScoreCounter.cs b/osu.Game/Graphics/UserInterface/ScoreCounter.cs index b565107f55..28e6b36fd1 100644 --- a/osu.Game/Graphics/UserInterface/ScoreCounter.cs +++ b/osu.Game/Graphics/UserInterface/ScoreCounter.cs @@ -17,8 +17,8 @@ namespace osu.Game.Graphics.UserInterface { protected override Type TransformType => typeof(TransformScore); - public override double RollingDuration => 1000; - public override EasingTypes RollingEasing => EasingTypes.Out; + protected override double RollingDuration => 1000; + protected override EasingTypes RollingEasing => EasingTypes.Out; /// /// How many leading zeroes the counter has.