From 4cc032e1d73c2bc07fe060d82d5a82f2de637769 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 10 Mar 2017 12:55:10 +0900 Subject: [PATCH] Make ComboCounter count a bindable, and properly bind it to the processor. --- .../Tests/TestCaseScoreCounter.cs | 7 +- osu.Game/Modes/Score.cs | 4 +- osu.Game/Modes/ScoreProcesssor.cs | 8 +- osu.Game/Modes/UI/ComboCounter.cs | 166 ++++++++---------- osu.Game/Modes/UI/HUDOverlay.cs | 2 +- osu.Game/Modes/UI/StandardComboCounter.cs | 22 +-- 6 files changed, 99 insertions(+), 110 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 59517beaf2..b21aee29d7 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -45,7 +45,6 @@ namespace osu.Desktop.VisualTests.Tests Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Margin = new MarginPadding(10), - Count = 0, TextSize = 40, }; Add(comboCounter); @@ -79,7 +78,7 @@ namespace osu.Desktop.VisualTests.Tests AddButton(@"Reset all", delegate { score.Count = 0; - comboCounter.Count = 0; + comboCounter.Current.Value = 0; numerator = denominator = 0; accuracyCounter.SetFraction(0, 0); stars.Count = 0; @@ -88,8 +87,8 @@ namespace osu.Desktop.VisualTests.Tests AddButton(@"Hit! :D", delegate { - score.Count += 300 + (ulong)(300.0 * (comboCounter.Count > 0 ? comboCounter.Count - 1 : 0) / 25.0); - comboCounter.Count++; + score.Count += 300 + (ulong)(300.0 * (comboCounter.Current > 0 ? comboCounter.Current - 1 : 0) / 25.0); + comboCounter.Increment(); numerator++; denominator++; accuracyCounter.SetFraction(numerator, denominator); }); diff --git a/osu.Game/Modes/Score.cs b/osu.Game/Modes/Score.cs index 1a761bea5d..8a06e8a60b 100644 --- a/osu.Game/Modes/Score.cs +++ b/osu.Game/Modes/Score.cs @@ -9,9 +9,9 @@ namespace osu.Game.Modes { public double TotalScore { get; set; } public double Accuracy { get; set; } - public double Combo { get; set; } - public double MaxCombo { get; set; } public double Health { get; set; } + public long Combo { get; set; } + public long MaxCombo { get; set; } public Replay Replay; public BeatmapInfo Beatmap; diff --git a/osu.Game/Modes/ScoreProcesssor.cs b/osu.Game/Modes/ScoreProcesssor.cs index 0433df66a9..ffae81fa82 100644 --- a/osu.Game/Modes/ScoreProcesssor.cs +++ b/osu.Game/Modes/ScoreProcesssor.cs @@ -1,10 +1,10 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; using osu.Framework.Configuration; using osu.Game.Modes.Objects.Drawables; +using System; +using System.Collections.Generic; namespace osu.Game.Modes { @@ -25,7 +25,7 @@ namespace osu.Game.Modes public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 }; - public readonly BindableInt Combo = new BindableInt(); + public readonly BindableLong Combo = new BindableLong(); /// /// Are we allowed to fail? @@ -43,7 +43,7 @@ namespace osu.Game.Modes /// Keeps track of the highest combo ever achieved in this play. /// This is handled automatically by ScoreProcessor. /// - public readonly BindableInt HighestCombo = new BindableInt(); + public readonly BindableLong HighestCombo = new BindableLong(); public readonly List Judgements; diff --git a/osu.Game/Modes/UI/ComboCounter.cs b/osu.Game/Modes/UI/ComboCounter.cs index b68489e37b..a276da3e5a 100644 --- a/osu.Game/Modes/UI/ComboCounter.cs +++ b/osu.Game/Modes/UI/ComboCounter.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; @@ -13,10 +14,12 @@ namespace osu.Game.Modes.UI { public abstract class ComboCounter : Container { - public bool IsRolling + public BindableLong Current = new BindableLong { - get; protected set; - } + MinValue = 0, + }; + + public bool IsRolling { get; protected set; } protected SpriteText PopOutCount; @@ -37,60 +40,9 @@ namespace osu.Game.Modes.UI /// protected EasingTypes RollingEasing => EasingTypes.None; - private ulong displayedCount; - - /// - /// Value shown at the current moment. - /// - public virtual ulong DisplayedCount - { - get - { - return displayedCount; - } - protected set - { - if (displayedCount.Equals(value)) - return; - updateDisplayedCount(displayedCount, value, IsRolling); - } - } - - private ulong count; - - /// - /// Actual value of counter. - /// - public virtual ulong Count - { - get - { - return count; - } - set - { - updateCount(value); - } - } - - public void Increment(ulong amount = 1) - { - Count = Count + amount; - } - protected SpriteText DisplayedCountSpriteText; - private float textSize; - public float TextSize - { - get { return textSize; } - set - { - textSize = value; - DisplayedCountSpriteText.TextSize = TextSize; - PopOutCount.TextSize = TextSize; - } - } + private long previousValue; /// /// Base of all combo counters. @@ -113,32 +65,78 @@ namespace osu.Game.Modes.UI }; TextSize = 80; + + Current.ValueChanged += comboChanged; + } + + private void comboChanged(object sender, System.EventArgs e) + { + if (Current.Value == 0) + Roll(); + else + updateCount(Current); } protected override void LoadComplete() { base.LoadComplete(); - DisplayedCountSpriteText.Text = FormatCount(Count); + DisplayedCountSpriteText.Text = FormatCount(Current); DisplayedCountSpriteText.Anchor = Anchor; DisplayedCountSpriteText.Origin = Origin; StopRolling(); } + private long displayedCount; + /// + /// Value shown at the current moment. + /// + public virtual long DisplayedCount + { + get { return displayedCount; } + protected set + { + if (displayedCount.Equals(value)) + return; + updateDisplayedCount(displayedCount, value, IsRolling); + } + } + + private float textSize; + public float TextSize + { + get { return textSize; } + set + { + textSize = value; + DisplayedCountSpriteText.TextSize = TextSize; + PopOutCount.TextSize = TextSize; + } + } + + /// + /// Increments the combo by an amount. + /// + /// + public void Increment(long amount = 1) + { + Current.Value = Current + amount; + } + /// /// Stops rollover animation, forcing the displayed count to be the actual count. /// public void StopRolling() { - updateCount(Count); + updateCount(Current); } /// /// Animates roll-up/roll-back to an specific value. /// /// Target value. - public virtual void Roll(ulong newValue = 0) + public virtual void Roll(long newValue = 0) { updateCount(newValue, true); } @@ -151,37 +149,33 @@ namespace osu.Game.Modes.UI updateCount(0); } - protected virtual string FormatCount(ulong count) + protected virtual string FormatCount(long count) { return count.ToString(); } - 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) + protected virtual void OnCountRolling(long currentValue, long newValue) { transformRoll(new TransformComboRoll(), currentValue, newValue); } - protected virtual void OnCountIncrement(ulong currentValue, ulong newValue) + protected virtual void OnCountIncrement(long currentValue, long newValue) { DisplayedCount = newValue; } - protected virtual void OnCountChange(ulong currentValue, ulong newValue) + protected virtual void OnCountChange(long currentValue, long newValue) { DisplayedCount = newValue; } - private double getProportionalDuration(ulong currentValue, ulong newValue) + private double getProportionalDuration(long currentValue, long newValue) { double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue; return difference * RollingDuration; } - private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling) + private void updateDisplayedCount(long currentValue, long newValue, bool rolling) { displayedCount = newValue; if (rolling) @@ -192,10 +186,10 @@ namespace osu.Game.Modes.UI OnDisplayedCountChange(newValue); } - private void updateCount(ulong value, bool rolling = false) + private void updateCount(long value, bool rolling = false) { - ulong prevCount = count; - count = value; + long prev = previousValue; + previousValue = Current.Value; if (!IsLoaded) return; @@ -204,27 +198,27 @@ namespace osu.Game.Modes.UI { Flush(false, typeof(TransformComboRoll)); IsRolling = false; - DisplayedCount = prevCount; + DisplayedCount = prev; - if (prevCount + 1 == count) - OnCountIncrement(prevCount, count); + if (prev + 1 == Current) + OnCountIncrement(prev, Current); else - OnCountChange(prevCount, count); + OnCountChange(prev, Current); } else { - OnCountRolling(displayedCount, count); + OnCountRolling(displayedCount, Current); IsRolling = true; } } - private void transformRoll(TransformComboRoll transform, ulong currentValue, ulong newValue) + private void transformRoll(TransformComboRoll transform, long currentValue, long newValue) { Flush(false, typeof(TransformComboRoll)); if (RollingDuration < 1) { - DisplayedCount = Count; + DisplayedCount = Current; return; } @@ -237,9 +231,9 @@ namespace osu.Game.Modes.UI Transforms.Add(transform); } - protected class TransformComboRoll : Transform + protected class TransformComboRoll : Transform { - protected override ulong CurrentValue + protected override long CurrentValue { get { @@ -247,7 +241,7 @@ namespace osu.Game.Modes.UI if (time < StartTime) return StartValue; if (time >= EndTime) return EndValue; - return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + return (long)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); } } @@ -258,12 +252,8 @@ namespace osu.Game.Modes.UI } } - public void Set(ulong value) - { - if (value == 0) - Roll(); - else - Count = value; - } + protected abstract void OnDisplayedCountRolling(long currentValue, long newValue); + protected abstract void OnDisplayedCountIncrement(long newValue); + protected abstract void OnDisplayedCountChange(long newValue); } } diff --git a/osu.Game/Modes/UI/HUDOverlay.cs b/osu.Game/Modes/UI/HUDOverlay.cs index 241afea55c..23c4690ace 100644 --- a/osu.Game/Modes/UI/HUDOverlay.cs +++ b/osu.Game/Modes/UI/HUDOverlay.cs @@ -78,7 +78,7 @@ namespace osu.Game.Modes.UI //TODO: these should be bindable binds, not events! processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); }; processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); }; - processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); }; + ComboCounter?.Current.BindTo(processor.Combo); HealthDisplay?.Current.BindTo(processor.Health); } diff --git a/osu.Game/Modes/UI/StandardComboCounter.cs b/osu.Game/Modes/UI/StandardComboCounter.cs index 488ab40d42..86b689fa89 100644 --- a/osu.Game/Modes/UI/StandardComboCounter.cs +++ b/osu.Game/Modes/UI/StandardComboCounter.cs @@ -25,12 +25,12 @@ namespace osu.Game.Modes.UI PopOutCount.Anchor = Anchor; } - protected override string FormatCount(ulong count) + protected override string FormatCount(long count) { return $@"{count}x"; } - protected virtual void TransformPopOut(ulong newValue) + protected virtual void TransformPopOut(long newValue) { PopOutCount.Text = FormatCount(newValue); @@ -43,19 +43,19 @@ namespace osu.Game.Modes.UI PopOutCount.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing); } - protected virtual void TransformPopOutRolling(ulong newValue) + protected virtual void TransformPopOutRolling(long newValue) { TransformPopOut(newValue); TransformPopOutSmall(newValue); } - protected virtual void TransformNoPopOut(ulong newValue) + protected virtual void TransformNoPopOut(long newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(1); } - protected virtual void TransformPopOutSmall(ulong newValue) + protected virtual void TransformPopOutSmall(long newValue) { DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.ScaleTo(PopOutSmallScale); @@ -71,7 +71,7 @@ namespace osu.Game.Modes.UI DisplayedCount++; } - protected override void OnCountRolling(ulong currentValue, ulong newValue) + protected override void OnCountRolling(long currentValue, long newValue) { ScheduledPopOutCurrentId++; @@ -82,7 +82,7 @@ namespace osu.Game.Modes.UI base.OnCountRolling(currentValue, newValue); } - protected override void OnCountIncrement(ulong currentValue, ulong newValue) + protected override void OnCountIncrement(long currentValue, long newValue) { ScheduledPopOutCurrentId++; @@ -100,7 +100,7 @@ namespace osu.Game.Modes.UI }, PopOutDuration); } - protected override void OnCountChange(ulong currentValue, ulong newValue) + protected override void OnCountChange(long currentValue, long newValue) { ScheduledPopOutCurrentId++; @@ -110,7 +110,7 @@ namespace osu.Game.Modes.UI base.OnCountChange(currentValue, newValue); } - protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue) + protected override void OnDisplayedCountRolling(long currentValue, long newValue) { if (newValue == 0) DisplayedCountSpriteText.FadeOut(FadeOutDuration); @@ -123,14 +123,14 @@ namespace osu.Game.Modes.UI TransformNoPopOut(newValue); } - protected override void OnDisplayedCountChange(ulong newValue) + protected override void OnDisplayedCountChange(long newValue) { DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); TransformNoPopOut(newValue); } - protected override void OnDisplayedCountIncrement(ulong newValue) + protected override void OnDisplayedCountIncrement(long newValue) { DisplayedCountSpriteText.Show();