Make ComboCounter count a bindable, and properly bind it to the processor.

This commit is contained in:
smoogipooo
2017-03-10 12:55:10 +09:00
parent 617ceb8001
commit 4cc032e1d7
6 changed files with 99 additions and 110 deletions

View File

@ -45,7 +45,6 @@ namespace osu.Desktop.VisualTests.Tests
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Margin = new MarginPadding(10), Margin = new MarginPadding(10),
Count = 0,
TextSize = 40, TextSize = 40,
}; };
Add(comboCounter); Add(comboCounter);
@ -79,7 +78,7 @@ namespace osu.Desktop.VisualTests.Tests
AddButton(@"Reset all", delegate AddButton(@"Reset all", delegate
{ {
score.Count = 0; score.Count = 0;
comboCounter.Count = 0; comboCounter.Current.Value = 0;
numerator = denominator = 0; numerator = denominator = 0;
accuracyCounter.SetFraction(0, 0); accuracyCounter.SetFraction(0, 0);
stars.Count = 0; stars.Count = 0;
@ -88,8 +87,8 @@ namespace osu.Desktop.VisualTests.Tests
AddButton(@"Hit! :D", delegate AddButton(@"Hit! :D", delegate
{ {
score.Count += 300 + (ulong)(300.0 * (comboCounter.Count > 0 ? comboCounter.Count - 1 : 0) / 25.0); score.Count += 300 + (ulong)(300.0 * (comboCounter.Current > 0 ? comboCounter.Current - 1 : 0) / 25.0);
comboCounter.Count++; comboCounter.Increment();
numerator++; denominator++; numerator++; denominator++;
accuracyCounter.SetFraction(numerator, denominator); accuracyCounter.SetFraction(numerator, denominator);
}); });

View File

@ -9,9 +9,9 @@ namespace osu.Game.Modes
{ {
public double TotalScore { get; set; } public double TotalScore { get; set; }
public double Accuracy { get; set; } public double Accuracy { get; set; }
public double Combo { get; set; }
public double MaxCombo { get; set; }
public double Health { get; set; } public double Health { get; set; }
public long Combo { get; set; }
public long MaxCombo { get; set; }
public Replay Replay; public Replay Replay;
public BeatmapInfo Beatmap; public BeatmapInfo Beatmap;

View File

@ -1,10 +1,10 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // 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.Framework.Configuration;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using System;
using System.Collections.Generic;
namespace osu.Game.Modes namespace osu.Game.Modes
{ {
@ -25,7 +25,7 @@ namespace osu.Game.Modes
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 }; public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
public readonly BindableInt Combo = new BindableInt(); public readonly BindableLong Combo = new BindableLong();
/// <summary> /// <summary>
/// Are we allowed to fail? /// Are we allowed to fail?
@ -43,7 +43,7 @@ namespace osu.Game.Modes
/// Keeps track of the highest combo ever achieved in this play. /// Keeps track of the highest combo ever achieved in this play.
/// This is handled automatically by ScoreProcessor. /// This is handled automatically by ScoreProcessor.
/// </summary> /// </summary>
public readonly BindableInt HighestCombo = new BindableInt(); public readonly BindableLong HighestCombo = new BindableLong();
public readonly List<JudgementInfo> Judgements; public readonly List<JudgementInfo> Judgements;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // 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;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
@ -13,10 +14,12 @@ namespace osu.Game.Modes.UI
{ {
public abstract class ComboCounter : Container 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; protected SpriteText PopOutCount;
@ -37,60 +40,9 @@ namespace osu.Game.Modes.UI
/// </summary> /// </summary>
protected EasingTypes RollingEasing => EasingTypes.None; protected EasingTypes RollingEasing => EasingTypes.None;
private ulong displayedCount;
/// <summary>
/// Value shown at the current moment.
/// </summary>
public virtual ulong DisplayedCount
{
get
{
return displayedCount;
}
protected set
{
if (displayedCount.Equals(value))
return;
updateDisplayedCount(displayedCount, value, IsRolling);
}
}
private ulong count;
/// <summary>
/// Actual value of counter.
/// </summary>
public virtual ulong Count
{
get
{
return count;
}
set
{
updateCount(value);
}
}
public void Increment(ulong amount = 1)
{
Count = Count + amount;
}
protected SpriteText DisplayedCountSpriteText; protected SpriteText DisplayedCountSpriteText;
private float textSize; private long previousValue;
public float TextSize
{
get { return textSize; }
set
{
textSize = value;
DisplayedCountSpriteText.TextSize = TextSize;
PopOutCount.TextSize = TextSize;
}
}
/// <summary> /// <summary>
/// Base of all combo counters. /// Base of all combo counters.
@ -113,32 +65,78 @@ namespace osu.Game.Modes.UI
}; };
TextSize = 80; 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() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
DisplayedCountSpriteText.Text = FormatCount(Count); DisplayedCountSpriteText.Text = FormatCount(Current);
DisplayedCountSpriteText.Anchor = Anchor; DisplayedCountSpriteText.Anchor = Anchor;
DisplayedCountSpriteText.Origin = Origin; DisplayedCountSpriteText.Origin = Origin;
StopRolling(); StopRolling();
} }
private long displayedCount;
/// <summary>
/// Value shown at the current moment.
/// </summary>
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;
}
}
/// <summary>
/// Increments the combo by an amount.
/// </summary>
/// <param name="amount"></param>
public void Increment(long amount = 1)
{
Current.Value = Current + amount;
}
/// <summary> /// <summary>
/// Stops rollover animation, forcing the displayed count to be the actual count. /// Stops rollover animation, forcing the displayed count to be the actual count.
/// </summary> /// </summary>
public void StopRolling() public void StopRolling()
{ {
updateCount(Count); updateCount(Current);
} }
/// <summary> /// <summary>
/// Animates roll-up/roll-back to an specific value. /// Animates roll-up/roll-back to an specific value.
/// </summary> /// </summary>
/// <param name="newValue">Target value.</param> /// <param name="newValue">Target value.</param>
public virtual void Roll(ulong newValue = 0) public virtual void Roll(long newValue = 0)
{ {
updateCount(newValue, true); updateCount(newValue, true);
} }
@ -151,37 +149,33 @@ namespace osu.Game.Modes.UI
updateCount(0); updateCount(0);
} }
protected virtual string FormatCount(ulong count) protected virtual string FormatCount(long count)
{ {
return count.ToString(); return count.ToString();
} }
protected abstract void OnDisplayedCountRolling(ulong currentValue, ulong newValue); protected virtual void OnCountRolling(long currentValue, long newValue)
protected abstract void OnDisplayedCountIncrement(ulong newValue);
protected abstract void OnDisplayedCountChange(ulong newValue);
protected virtual void OnCountRolling(ulong currentValue, ulong newValue)
{ {
transformRoll(new TransformComboRoll(), currentValue, newValue); transformRoll(new TransformComboRoll(), currentValue, newValue);
} }
protected virtual void OnCountIncrement(ulong currentValue, ulong newValue) protected virtual void OnCountIncrement(long currentValue, long newValue)
{ {
DisplayedCount = newValue; DisplayedCount = newValue;
} }
protected virtual void OnCountChange(ulong currentValue, ulong newValue) protected virtual void OnCountChange(long currentValue, long newValue)
{ {
DisplayedCount = 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; double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue;
return difference * RollingDuration; return difference * RollingDuration;
} }
private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling) private void updateDisplayedCount(long currentValue, long newValue, bool rolling)
{ {
displayedCount = newValue; displayedCount = newValue;
if (rolling) if (rolling)
@ -192,10 +186,10 @@ namespace osu.Game.Modes.UI
OnDisplayedCountChange(newValue); OnDisplayedCountChange(newValue);
} }
private void updateCount(ulong value, bool rolling = false) private void updateCount(long value, bool rolling = false)
{ {
ulong prevCount = count; long prev = previousValue;
count = value; previousValue = Current.Value;
if (!IsLoaded) if (!IsLoaded)
return; return;
@ -204,27 +198,27 @@ namespace osu.Game.Modes.UI
{ {
Flush(false, typeof(TransformComboRoll)); Flush(false, typeof(TransformComboRoll));
IsRolling = false; IsRolling = false;
DisplayedCount = prevCount; DisplayedCount = prev;
if (prevCount + 1 == count) if (prev + 1 == Current)
OnCountIncrement(prevCount, count); OnCountIncrement(prev, Current);
else else
OnCountChange(prevCount, count); OnCountChange(prev, Current);
} }
else else
{ {
OnCountRolling(displayedCount, count); OnCountRolling(displayedCount, Current);
IsRolling = true; IsRolling = true;
} }
} }
private void transformRoll(TransformComboRoll transform, ulong currentValue, ulong newValue) private void transformRoll(TransformComboRoll transform, long currentValue, long newValue)
{ {
Flush(false, typeof(TransformComboRoll)); Flush(false, typeof(TransformComboRoll));
if (RollingDuration < 1) if (RollingDuration < 1)
{ {
DisplayedCount = Count; DisplayedCount = Current;
return; return;
} }
@ -237,9 +231,9 @@ namespace osu.Game.Modes.UI
Transforms.Add(transform); Transforms.Add(transform);
} }
protected class TransformComboRoll : Transform<ulong> protected class TransformComboRoll : Transform<long>
{ {
protected override ulong CurrentValue protected override long CurrentValue
{ {
get get
{ {
@ -247,7 +241,7 @@ namespace osu.Game.Modes.UI
if (time < StartTime) return StartValue; if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue; 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) protected abstract void OnDisplayedCountRolling(long currentValue, long newValue);
{ protected abstract void OnDisplayedCountIncrement(long newValue);
if (value == 0) protected abstract void OnDisplayedCountChange(long newValue);
Roll();
else
Count = value;
}
} }
} }

View File

@ -78,7 +78,7 @@ namespace osu.Game.Modes.UI
//TODO: these should be bindable binds, not events! //TODO: these should be bindable binds, not events!
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); }; processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.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); HealthDisplay?.Current.BindTo(processor.Health);
} }

View File

@ -25,12 +25,12 @@ namespace osu.Game.Modes.UI
PopOutCount.Anchor = Anchor; PopOutCount.Anchor = Anchor;
} }
protected override string FormatCount(ulong count) protected override string FormatCount(long count)
{ {
return $@"{count}x"; return $@"{count}x";
} }
protected virtual void TransformPopOut(ulong newValue) protected virtual void TransformPopOut(long newValue)
{ {
PopOutCount.Text = FormatCount(newValue); PopOutCount.Text = FormatCount(newValue);
@ -43,19 +43,19 @@ namespace osu.Game.Modes.UI
PopOutCount.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing); PopOutCount.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing);
} }
protected virtual void TransformPopOutRolling(ulong newValue) protected virtual void TransformPopOutRolling(long newValue)
{ {
TransformPopOut(newValue); TransformPopOut(newValue);
TransformPopOutSmall(newValue); TransformPopOutSmall(newValue);
} }
protected virtual void TransformNoPopOut(ulong newValue) protected virtual void TransformNoPopOut(long newValue)
{ {
DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(1); DisplayedCountSpriteText.ScaleTo(1);
} }
protected virtual void TransformPopOutSmall(ulong newValue) protected virtual void TransformPopOutSmall(long newValue)
{ {
DisplayedCountSpriteText.Text = FormatCount(newValue); DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(PopOutSmallScale); DisplayedCountSpriteText.ScaleTo(PopOutSmallScale);
@ -71,7 +71,7 @@ namespace osu.Game.Modes.UI
DisplayedCount++; DisplayedCount++;
} }
protected override void OnCountRolling(ulong currentValue, ulong newValue) protected override void OnCountRolling(long currentValue, long newValue)
{ {
ScheduledPopOutCurrentId++; ScheduledPopOutCurrentId++;
@ -82,7 +82,7 @@ namespace osu.Game.Modes.UI
base.OnCountRolling(currentValue, newValue); base.OnCountRolling(currentValue, newValue);
} }
protected override void OnCountIncrement(ulong currentValue, ulong newValue) protected override void OnCountIncrement(long currentValue, long newValue)
{ {
ScheduledPopOutCurrentId++; ScheduledPopOutCurrentId++;
@ -100,7 +100,7 @@ namespace osu.Game.Modes.UI
}, PopOutDuration); }, PopOutDuration);
} }
protected override void OnCountChange(ulong currentValue, ulong newValue) protected override void OnCountChange(long currentValue, long newValue)
{ {
ScheduledPopOutCurrentId++; ScheduledPopOutCurrentId++;
@ -110,7 +110,7 @@ namespace osu.Game.Modes.UI
base.OnCountChange(currentValue, newValue); base.OnCountChange(currentValue, newValue);
} }
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue) protected override void OnDisplayedCountRolling(long currentValue, long newValue)
{ {
if (newValue == 0) if (newValue == 0)
DisplayedCountSpriteText.FadeOut(FadeOutDuration); DisplayedCountSpriteText.FadeOut(FadeOutDuration);
@ -123,14 +123,14 @@ namespace osu.Game.Modes.UI
TransformNoPopOut(newValue); TransformNoPopOut(newValue);
} }
protected override void OnDisplayedCountChange(ulong newValue) protected override void OnDisplayedCountChange(long newValue)
{ {
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1); DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
TransformNoPopOut(newValue); TransformNoPopOut(newValue);
} }
protected override void OnDisplayedCountIncrement(ulong newValue) protected override void OnDisplayedCountIncrement(long newValue)
{ {
DisplayedCountSpriteText.Show(); DisplayedCountSpriteText.Show();