mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +08:00
Make ComboCounter count a bindable, and properly bind it to the processor.
This commit is contained in:
parent
617ceb8001
commit
4cc032e1d7
@ -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);
|
||||
});
|
||||
|
@ -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;
|
||||
|
@ -1,10 +1,10 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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();
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public readonly BindableInt HighestCombo = new BindableInt();
|
||||
public readonly BindableLong HighestCombo = new BindableLong();
|
||||
|
||||
public readonly List<JudgementInfo> Judgements;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
private float textSize;
|
||||
public float TextSize
|
||||
{
|
||||
get { return textSize; }
|
||||
set
|
||||
{
|
||||
textSize = value;
|
||||
DisplayedCountSpriteText.TextSize = TextSize;
|
||||
PopOutCount.TextSize = TextSize;
|
||||
}
|
||||
}
|
||||
private long previousValue;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
/// <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>
|
||||
/// Stops rollover animation, forcing the displayed count to be the actual count.
|
||||
/// </summary>
|
||||
public void StopRolling()
|
||||
{
|
||||
updateCount(Count);
|
||||
updateCount(Current);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animates roll-up/roll-back to an specific value.
|
||||
/// </summary>
|
||||
/// <param name="newValue">Target value.</param>
|
||||
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<ulong>
|
||||
protected class TransformComboRoll : Transform<long>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user