mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 06:12:56 +08:00
Improved code
This commit is contained in:
parent
1d8d2fa9c9
commit
ce07a45456
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
|
||||
/// </summary>
|
||||
public class AccuracyCounter : NumericRollingCounter<float>
|
||||
public class AccuracyCounter : RollingCounter<float>
|
||||
{
|
||||
protected override Type transformType => typeof(TransformAccuracy);
|
||||
|
||||
@ -73,20 +72,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
return count.ToString("0.00") + "%";
|
||||
}
|
||||
|
||||
protected class TransformAccuracy : Transform<float>
|
||||
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);
|
||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <summary>
|
||||
/// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
|
||||
/// </summary>
|
||||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -74,10 +41,5 @@ namespace osu.Game.Graphics.UserInterface
|
||||
popOutSpriteText.Colour = colour;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public override void ResetCount()
|
||||
{
|
||||
base.ResetCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
273
osu.Game/Graphics/UserInterface/ComboCounter.cs
Normal file
273
osu.Game/Graphics/UserInterface/ComboCounter.cs
Normal file
@ -0,0 +1,273 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the roll-down duration will be proportional to the counter.
|
||||
/// </summary>
|
||||
public bool IsRollingProportional = true;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public ulong RollingDuration = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Easing for the counter rollover animation.
|
||||
/// </summary>
|
||||
public EasingTypes RollingEasing = EasingTypes.None;
|
||||
|
||||
protected ulong prevVisibleCount;
|
||||
protected ulong visibleCount;
|
||||
|
||||
/// <summary>
|
||||
/// Value shown at the current moment.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Actual value of counter.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base of all combo counters.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets count value, bypassing rollover animation.
|
||||
/// </summary>
|
||||
/// <param name="count">New count value.</param>
|
||||
public virtual void SetCountWithoutRolling(ulong count)
|
||||
{
|
||||
Count = count;
|
||||
StopRolling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops rollover animation, forcing the visible count to be the actual count.
|
||||
/// </summary>
|
||||
public virtual void StopRolling()
|
||||
{
|
||||
removeComboTransforms();
|
||||
VisibleCount = Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animates roll-back to an specific value.
|
||||
/// </summary>
|
||||
/// <param name="newValue">Target value.</param>
|
||||
public virtual void RollBack(ulong newValue = 0)
|
||||
{
|
||||
rollbacking = true;
|
||||
Count = newValue;
|
||||
rollbacking = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets count to default value.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intended to be used by transformCount().
|
||||
/// </summary>
|
||||
/// <see cref="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<ulong>
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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
|
||||
{
|
||||
/// <summary>
|
||||
/// Skeleton for a numeric counter with a simple roll-up animation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the actual counter.</typeparam>
|
||||
public abstract class NumericRollingCounter<T> : RollingCounter<T>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
using osu.Framework;
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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
|
||||
{
|
||||
/// <summary>
|
||||
/// Skeleton for a counter which value rolls-up in a lapse of time.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">Type of the actual counter.</typeparam>
|
||||
public abstract class RollingCounter<T> : AutoSizeContainer
|
||||
{
|
||||
/// <summary>
|
||||
@ -29,13 +25,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </remarks>
|
||||
protected virtual Type transformType => typeof(Transform<T>);
|
||||
|
||||
protected ulong RollingTotalDuration = 0;
|
||||
protected ulong rollingTotalDuration = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public bool IsRollingContinuous = true;
|
||||
protected SpriteText countSpriteText;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skeleton of a numeric counter which value rolls over time.
|
||||
/// </summary>
|
||||
protected RollingCounter()
|
||||
{
|
||||
Debug.Assert(
|
||||
transformType.IsSubclassOf(typeof(Transform<T>)) || transformType == typeof(Transform<T>),
|
||||
@"transformType should be a subclass of Transform<T>."
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -145,7 +160,10 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <summary>
|
||||
/// Resets count to default value.
|
||||
/// </summary>
|
||||
public abstract void ResetCount();
|
||||
public virtual void ResetCount()
|
||||
{
|
||||
SetCountWithoutRolling(default(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the count is updated to add a transformer that changes the value of the visible count (i.e.
|
||||
/// implement the rollover animation).
|
||||
/// </summary>
|
||||
/// <param name="visibleValue">Count value currently visible to user.</param>
|
||||
/// <param name="currentValue">Count value before previous modification.</param>
|
||||
/// <param name="currentValue">Count value before modification.</param>
|
||||
/// <param name="newValue">Expected count value after modification.</param>
|
||||
protected virtual void transformCount(T visibleValue, T prevValue, T currentValue, T newValue)
|
||||
{
|
||||
transformCount(IsRollingContinuous ? visibleValue : currentValue, newValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This procedure is called each time the visible count value is updated.
|
||||
/// Override to create custom animations.
|
||||
/// </summary>
|
||||
/// <param name="currentValue">Visible count value before modification.</param>
|
||||
/// <param name="newValue">Expected visible count value after modification-</param>
|
||||
protected abstract void transformVisibleCount(T currentValue, T newValue);
|
||||
}
|
||||
}
|
||||
|
@ -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<ulong>
|
||||
{
|
||||
protected override Type transformType => typeof(TransformScore);
|
||||
|
||||
/// <summary>
|
||||
/// How many leading zeroes the counter has.
|
||||
/// </summary>
|
||||
@ -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<ulong>
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <summary>
|
||||
/// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<float>
|
||||
public class StarCounter : AutoSizeContainer
|
||||
{
|
||||
protected override Type transformType => typeof(TransformStarCounter);
|
||||
private Container starContainer;
|
||||
private List<TextAwesome> stars = new List<TextAwesome>();
|
||||
|
||||
protected Container starContainer;
|
||||
protected List<TextAwesome> stars = new List<TextAwesome>();
|
||||
private double transformStartTime = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
/// <summary>
|
||||
/// Amount of stars represented.
|
||||
/// </summary>
|
||||
public float Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
}
|
||||
set
|
||||
{
|
||||
prevCount = VisibleValue;
|
||||
count = value;
|
||||
if (IsLoaded)
|
||||
{
|
||||
transformCount(prevCount, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a float count as stars. Used as star difficulty display.
|
||||
@ -50,10 +88,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <param name="stars">Maximum amount of stars to display.</param>
|
||||
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<float>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple rolling counter that accepts unsigned long values.
|
||||
/// </summary>
|
||||
public class ULongCounter : NumericRollingCounter<ulong>
|
||||
{
|
||||
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<ulong>
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -106,6 +106,8 @@
|
||||
<Compile Include="GameModes\Play\Taiko\TaikoHitRenderer.cs" />
|
||||
<Compile Include="GameModes\Play\Taiko\TaikoPlayfield.cs" />
|
||||
<Compile Include="GameModes\Edit\EditSongSelect.cs" />
|
||||
<Compile Include="Graphics\UserInterface\ComboCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\RollingCounter.cs" />
|
||||
<Compile Include="Input\GlobalHotkeys.cs" />
|
||||
<Compile Include="Graphics\Background\Background.cs" />
|
||||
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
|
||||
@ -113,18 +115,15 @@
|
||||
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
|
||||
<Compile Include="Graphics\TextAwesome.cs" />
|
||||
<Compile Include="Graphics\UserInterface\AlternativeComboCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\RollingCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\KeyCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\KeyCounterKeyboard.cs" />
|
||||
<Compile Include="Graphics\UserInterface\KeyCounterCollection.cs" />
|
||||
<Compile Include="Graphics\UserInterface\KeyCounterMouse.cs" />
|
||||
<Compile Include="Graphics\UserInterface\AccuracyCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\NumericRollingCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\CatchComboCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\StandardComboCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\StarCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\ULongCounter.cs" />
|
||||
<Compile Include="Online\API\APIAccess.cs" />
|
||||
<Compile Include="Online\API\APIRequest.cs" />
|
||||
<Compile Include="Online\API\OAuth.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user