2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 03:55:10 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-03-10 03:26:46 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2016-11-14 09:54:24 +00:00
|
|
|
|
namespace osu.Game.Modes.UI
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-10 03:26:46 +00:00
|
|
|
|
public abstract class ComboCounter : Container
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-10 07:05:05 +00:00
|
|
|
|
public BindableInt Current = new BindableInt
|
2017-03-10 03:26:46 +00:00
|
|
|
|
{
|
2017-03-10 03:55:10 +00:00
|
|
|
|
MinValue = 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public bool IsRolling { get; protected set; }
|
2016-10-14 23:23:27 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
protected SpriteText PopOutCount;
|
2016-10-29 23:26:12 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
protected virtual double PopOutDuration => 150;
|
|
|
|
|
protected virtual float PopOutScale => 2.0f;
|
|
|
|
|
protected virtual EasingTypes PopOutEasing => EasingTypes.None;
|
|
|
|
|
protected virtual float PopOutInitialAlpha => 0.75f;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
protected virtual double FadeOutDuration => 100;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Duration in milliseconds for the counter roll-up animation for each element.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual double RollingDuration => 20;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Easing for the counter rollover animation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected EasingTypes RollingEasing => EasingTypes.None;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
protected SpriteText DisplayedCountSpriteText;
|
2016-10-22 08:50:42 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
private int previousValue;
|
2016-11-19 07:19:54 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base of all combo counters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected ComboCounter()
|
2016-11-19 07:19:54 +00:00
|
|
|
|
{
|
2017-03-10 03:26:46 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
DisplayedCountSpriteText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
PopOutCount = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Margin = new MarginPadding(0.05f),
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TextSize = 80;
|
2017-03-10 03:55:10 +00:00
|
|
|
|
|
|
|
|
|
Current.ValueChanged += comboChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboChanged(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2017-03-10 05:34:08 +00:00
|
|
|
|
updateCount(Current.Value == 0);
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
protected override void LoadComplete()
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-10 03:26:46 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2017-03-10 03:55:10 +00:00
|
|
|
|
DisplayedCountSpriteText.Text = FormatCount(Current);
|
2017-03-10 03:26:46 +00:00
|
|
|
|
DisplayedCountSpriteText.Anchor = Anchor;
|
|
|
|
|
DisplayedCountSpriteText.Origin = Origin;
|
|
|
|
|
|
|
|
|
|
StopRolling();
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
private int displayedCount;
|
2017-03-10 03:55:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Value shown at the current moment.
|
|
|
|
|
/// </summary>
|
2017-03-10 07:05:05 +00:00
|
|
|
|
public virtual int DisplayedCount
|
2017-03-10 03:55:10 +00:00
|
|
|
|
{
|
|
|
|
|
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>
|
2017-03-10 07:05:05 +00:00
|
|
|
|
public void Increment(int amount = 1)
|
2017-03-10 03:55:10 +00:00
|
|
|
|
{
|
|
|
|
|
Current.Value = Current + amount;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stops rollover animation, forcing the displayed count to be the actual count.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void StopRolling()
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-10 05:34:08 +00:00
|
|
|
|
updateCount(false);
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
protected virtual string FormatCount(int count)
|
2016-10-15 23:06:31 +00:00
|
|
|
|
{
|
2017-03-10 03:26:46 +00:00
|
|
|
|
return count.ToString();
|
|
|
|
|
}
|
2016-10-15 23:06:31 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
protected virtual void OnCountRolling(int currentValue, int newValue)
|
2017-03-10 03:26:46 +00:00
|
|
|
|
{
|
|
|
|
|
transformRoll(new TransformComboRoll(), currentValue, newValue);
|
2016-10-16 00:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
protected virtual void OnCountIncrement(int currentValue, int newValue)
|
2016-10-16 00:07:07 +00:00
|
|
|
|
{
|
2017-03-10 03:26:46 +00:00
|
|
|
|
DisplayedCount = newValue;
|
|
|
|
|
}
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
protected virtual void OnCountChange(int currentValue, int newValue)
|
2017-03-10 03:26:46 +00:00
|
|
|
|
{
|
|
|
|
|
DisplayedCount = newValue;
|
|
|
|
|
}
|
2016-11-06 10:13:52 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
private double getProportionalDuration(int currentValue, int newValue)
|
2017-03-10 03:26:46 +00:00
|
|
|
|
{
|
|
|
|
|
double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
|
|
|
|
return difference * RollingDuration;
|
|
|
|
|
}
|
2016-11-06 10:13:52 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
private void updateDisplayedCount(int currentValue, int newValue, bool rolling)
|
2017-03-10 03:26:46 +00:00
|
|
|
|
{
|
|
|
|
|
displayedCount = newValue;
|
|
|
|
|
if (rolling)
|
|
|
|
|
OnDisplayedCountRolling(currentValue, newValue);
|
|
|
|
|
else if (currentValue + 1 == newValue)
|
|
|
|
|
OnDisplayedCountIncrement(newValue);
|
|
|
|
|
else
|
|
|
|
|
OnDisplayedCountChange(newValue);
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 05:34:08 +00:00
|
|
|
|
private void updateCount(bool rolling)
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-10 07:05:05 +00:00
|
|
|
|
int prev = previousValue;
|
2017-03-10 05:34:08 +00:00
|
|
|
|
previousValue = Current;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
if (!rolling)
|
|
|
|
|
{
|
|
|
|
|
Flush(false, typeof(TransformComboRoll));
|
|
|
|
|
IsRolling = false;
|
2017-03-10 03:55:10 +00:00
|
|
|
|
DisplayedCount = prev;
|
2017-03-10 03:26:46 +00:00
|
|
|
|
|
2017-03-10 03:55:10 +00:00
|
|
|
|
if (prev + 1 == Current)
|
|
|
|
|
OnCountIncrement(prev, Current);
|
2017-03-10 03:26:46 +00:00
|
|
|
|
else
|
2017-03-10 03:55:10 +00:00
|
|
|
|
OnCountChange(prev, Current);
|
2017-03-10 03:26:46 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-03-10 03:55:10 +00:00
|
|
|
|
OnCountRolling(displayedCount, Current);
|
2017-03-10 03:26:46 +00:00
|
|
|
|
IsRolling = true;
|
|
|
|
|
}
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
private void transformRoll(TransformComboRoll transform, int currentValue, int newValue)
|
2016-10-13 22:13:20 +00:00
|
|
|
|
{
|
2017-03-10 03:26:46 +00:00
|
|
|
|
Flush(false, typeof(TransformComboRoll));
|
2017-03-10 02:59:08 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
if (RollingDuration < 1)
|
|
|
|
|
{
|
2017-03-10 03:55:10 +00:00
|
|
|
|
DisplayedCount = Current;
|
2017-03-10 03:26:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transform.StartTime = Time.Current;
|
|
|
|
|
transform.EndTime = Time.Current + getProportionalDuration(currentValue, newValue);
|
|
|
|
|
transform.StartValue = currentValue;
|
|
|
|
|
transform.EndValue = newValue;
|
|
|
|
|
transform.Easing = RollingEasing;
|
|
|
|
|
|
|
|
|
|
Transforms.Add(transform);
|
2017-03-10 02:59:08 +00:00
|
|
|
|
}
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
protected class TransformComboRoll : Transform<int>
|
2017-03-10 02:59:08 +00:00
|
|
|
|
{
|
2017-03-31 03:58:54 +00:00
|
|
|
|
public override int CurrentValue
|
2017-03-10 03:26:46 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
double time = Time?.Current ?? 0;
|
|
|
|
|
if (time < StartTime) return StartValue;
|
|
|
|
|
if (time >= EndTime) return EndValue;
|
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
return (int)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
|
2017-03-10 03:26:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-13 22:13:20 +00:00
|
|
|
|
|
2017-03-10 03:26:46 +00:00
|
|
|
|
public override void Apply(Drawable d)
|
|
|
|
|
{
|
|
|
|
|
base.Apply(d);
|
|
|
|
|
((ComboCounter)d).DisplayedCount = CurrentValue;
|
|
|
|
|
}
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
2016-11-29 12:28:43 +00:00
|
|
|
|
|
2017-03-10 07:05:05 +00:00
|
|
|
|
protected abstract void OnDisplayedCountRolling(int currentValue, int newValue);
|
|
|
|
|
protected abstract void OnDisplayedCountIncrement(int newValue);
|
|
|
|
|
protected abstract void OnDisplayedCountChange(int newValue);
|
2016-10-13 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|