mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Changes according to review + Refactor
This commit is contained in:
@ -1,109 +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.Transformations;
|
||||
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>
|
||||
/// Used as an accuracy counter. Represented visually as a percentage, internally as a fraction.
|
||||
/// </summary>
|
||||
public class AccuracyCounter : RollingCounter<float>
|
||||
{
|
||||
protected override Type transformType => typeof(TransformAccuracy);
|
||||
|
||||
private long numerator = 0;
|
||||
public long Numerator
|
||||
{
|
||||
get
|
||||
{
|
||||
return numerator;
|
||||
}
|
||||
set
|
||||
{
|
||||
numerator = value;
|
||||
updateCount();
|
||||
}
|
||||
}
|
||||
|
||||
private ulong denominator = 0;
|
||||
public ulong Denominator
|
||||
{
|
||||
get
|
||||
{
|
||||
return denominator;
|
||||
}
|
||||
set
|
||||
{
|
||||
denominator = value;
|
||||
updateCount();
|
||||
}
|
||||
}
|
||||
|
||||
public AccuracyCounter()
|
||||
{
|
||||
RollingDuration = 500;
|
||||
RollingEasing = EasingTypes.Out;
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
updateCount();
|
||||
StopRolling();
|
||||
}
|
||||
|
||||
public void SetCount(long num, ulong den)
|
||||
{
|
||||
numerator = num;
|
||||
denominator = den;
|
||||
updateCount();
|
||||
}
|
||||
|
||||
private void updateCount()
|
||||
{
|
||||
Count = Denominator == 0 ? 100.0f : (Numerator * 100.0f) / Denominator;
|
||||
}
|
||||
|
||||
public override void ResetCount()
|
||||
{
|
||||
numerator = 0;
|
||||
denominator = 0;
|
||||
updateCount();
|
||||
StopRolling();
|
||||
}
|
||||
|
||||
protected override string formatCount(float count)
|
||||
{
|
||||
return count.ToString("0.00") + "%";
|
||||
}
|
||||
|
||||
protected override double getProportionalDuration(float currentValue, float newValue)
|
||||
{
|
||||
return Math.Abs(currentValue - newValue) * RollingDuration;
|
||||
}
|
||||
|
||||
protected class TransformAccuracy : TransformFloat
|
||||
{
|
||||
public override void Apply(Drawable d)
|
||||
{
|
||||
base.Apply(d);
|
||||
(d as AccuracyCounter).VisibleCount = CurrentValue;
|
||||
}
|
||||
|
||||
public TransformAccuracy(IClock clock)
|
||||
: base(clock)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +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 OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
|
||||
/// </summary>
|
||||
public class AlternativeComboCounter : ComboCounter
|
||||
{
|
||||
public Color4 OriginalColour;
|
||||
public Color4 TintColour = Color4.OrangeRed;
|
||||
public int TintDuration = 300;
|
||||
public float ScaleFactor = 2;
|
||||
public EasingTypes TintEasing = EasingTypes.None;
|
||||
public bool CanAnimateWhenBackwards = false;
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
OriginalColour = Colour;
|
||||
}
|
||||
|
||||
protected override double getProportionalDuration(ulong currentValue, ulong newValue)
|
||||
{
|
||||
double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
|
||||
return difference * RollingDuration;
|
||||
}
|
||||
|
||||
protected virtual void transformAnimate(ulong newValue)
|
||||
{
|
||||
countSpriteText.FadeColour(TintColour, 0);
|
||||
countSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
|
||||
countSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing);
|
||||
countSpriteText.ScaleTo(new Vector2(1, 1), TintDuration, TintEasing);
|
||||
}
|
||||
|
||||
protected override void transformVisibleCount(ulong currentValue, ulong newValue)
|
||||
{
|
||||
countSpriteText.Text = formatCount(newValue);
|
||||
|
||||
if (newValue == 0)
|
||||
countSpriteText.FadeOut(TintDuration);
|
||||
else
|
||||
countSpriteText.Show();
|
||||
|
||||
if (newValue > currentValue || CanAnimateWhenBackwards)
|
||||
transformAnimate(newValue);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +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 OpenTK.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch.
|
||||
/// </summary>
|
||||
public class CatchComboCounter : StandardComboCounter
|
||||
{
|
||||
public CatchComboCounter()
|
||||
{
|
||||
CanPopOutWhenBackwards = true;
|
||||
}
|
||||
|
||||
protected override string formatCount(ulong count)
|
||||
{
|
||||
return count.ToString("#,0");
|
||||
}
|
||||
|
||||
public override void Roll(ulong newValue = 0)
|
||||
{
|
||||
popOutSpriteText.Colour = countSpriteText.Colour;
|
||||
|
||||
base.Roll(newValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increaces counter and tints pop-out before animation.
|
||||
/// </summary>
|
||||
/// <param name="colour">Last grabbed fruit colour.</param>
|
||||
public void CatchFruit(Color4 colour)
|
||||
{
|
||||
popOutSpriteText.Colour = colour;
|
||||
Count++;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,28 +17,37 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public abstract class ComboCounter : AutoSizeContainer
|
||||
public abstract class ComboCounter : Container
|
||||
{
|
||||
protected Type transformType => typeof(TransformCombo);
|
||||
|
||||
protected bool IsRolling = false;
|
||||
|
||||
protected SpriteText PopOutSpriteText;
|
||||
|
||||
protected virtual ulong PopOutDuration => 150;
|
||||
protected virtual float PopOutScale => 2.0f;
|
||||
protected virtual EasingTypes PopOutEasing => EasingTypes.None;
|
||||
protected virtual float PopOutInitialAlpha => 0.75f;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the roll-down duration will be proportional to the counter.
|
||||
/// </summary>
|
||||
public bool IsRollingProportional = true;
|
||||
protected virtual 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 double RollingDuration = 20;
|
||||
protected virtual double RollingDuration => 20;
|
||||
|
||||
/// <summary>
|
||||
/// Easing for the counter rollover animation.
|
||||
/// </summary>
|
||||
public EasingTypes RollingEasing = EasingTypes.None;
|
||||
protected EasingTypes RollingEasing => EasingTypes.None;
|
||||
|
||||
protected ulong prevVisibleCount;
|
||||
protected ulong visibleCount;
|
||||
private ulong prevVisibleCount;
|
||||
private ulong visibleCount;
|
||||
|
||||
/// <summary>
|
||||
/// Value shown at the current moment.
|
||||
@ -55,11 +64,10 @@ namespace osu.Game.Graphics.UserInterface
|
||||
return;
|
||||
prevVisibleCount = visibleCount;
|
||||
visibleCount = value;
|
||||
transformVisibleCount(prevVisibleCount, visibleCount);
|
||||
transformVisibleCount(prevVisibleCount, visibleCount, IsRolling);
|
||||
}
|
||||
}
|
||||
|
||||
protected ulong prevPrevCount;
|
||||
protected ulong prevCount;
|
||||
protected ulong count;
|
||||
|
||||
@ -80,25 +88,25 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
private void setCount(ulong value, bool rolling = false)
|
||||
{
|
||||
prevPrevCount = prevCount;
|
||||
prevCount = count;
|
||||
count = value;
|
||||
if (IsLoaded)
|
||||
{
|
||||
transformCount(VisibleCount, prevPrevCount, prevCount, value, rolling);
|
||||
transformCount(VisibleCount, prevCount, value, rolling);
|
||||
}
|
||||
}
|
||||
|
||||
protected SpriteText countSpriteText;
|
||||
protected SpriteText CountSpriteText;
|
||||
|
||||
protected float textSize = 20.0f;
|
||||
private float textSize = 20.0f;
|
||||
public float TextSize
|
||||
{
|
||||
get { return textSize; }
|
||||
set
|
||||
{
|
||||
textSize = value;
|
||||
updateTextSize();
|
||||
CountSpriteText.TextSize = TextSize;
|
||||
PopOutSpriteText.TextSize = TextSize;
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,12 +117,16 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
countSpriteText = new SpriteText
|
||||
CountSpriteText = new SpriteText
|
||||
{
|
||||
Anchor = this.Anchor,
|
||||
Origin = this.Origin,
|
||||
Alpha = 0,
|
||||
},
|
||||
PopOutSpriteText = new SpriteText
|
||||
{
|
||||
Alpha = 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -122,8 +134,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
countSpriteText.Anchor = this.Anchor;
|
||||
countSpriteText.Origin = this.Origin;
|
||||
CountSpriteText.Anchor = this.Anchor;
|
||||
CountSpriteText.Origin = this.Origin;
|
||||
|
||||
StopRolling();
|
||||
}
|
||||
@ -133,7 +145,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public virtual void StopRolling()
|
||||
{
|
||||
removeComboTransforms();
|
||||
Flush(false, typeof(TransformCombo));
|
||||
VisibleCount = Count;
|
||||
}
|
||||
|
||||
@ -154,62 +166,55 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Count = default(ulong);
|
||||
}
|
||||
|
||||
protected virtual double getProportionalDuration(ulong currentValue, ulong newValue)
|
||||
protected double GetProportionalDuration(ulong currentValue, ulong newValue)
|
||||
{
|
||||
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
|
||||
return difference * RollingDuration;
|
||||
}
|
||||
|
||||
protected abstract void transformVisibleCount(ulong currentValue, ulong newValue);
|
||||
|
||||
protected virtual string formatCount(ulong count)
|
||||
protected virtual string FormatCount(ulong count)
|
||||
{
|
||||
return count.ToString();
|
||||
}
|
||||
|
||||
private void updateComboTransforms()
|
||||
protected abstract void OnCountRolling(ulong currentValue, ulong newValue);
|
||||
protected abstract void OnCountIncrement(ulong newValue);
|
||||
protected abstract void OnCountChange(ulong newValue);
|
||||
|
||||
private void transformVisibleCount(ulong currentValue, ulong newValue, bool rolling)
|
||||
{
|
||||
foreach (ITransform t in Transforms.AliveItems)
|
||||
if (t.GetType() == typeof(TransformCombo))
|
||||
t.Apply(this);
|
||||
if (rolling)
|
||||
OnCountRolling(currentValue, newValue);
|
||||
else if (currentValue + 1 == newValue)
|
||||
OnCountIncrement(newValue);
|
||||
else
|
||||
OnCountChange(newValue);
|
||||
}
|
||||
|
||||
private void removeComboTransforms()
|
||||
{
|
||||
Transforms.RemoveAll(t => t.GetType() == typeof(TransformCombo));
|
||||
}
|
||||
|
||||
protected virtual void transformCount(
|
||||
private void transformCount(
|
||||
ulong visibleValue,
|
||||
ulong prevValue,
|
||||
ulong currentValue,
|
||||
ulong newValue,
|
||||
bool rolling)
|
||||
{
|
||||
if (!rolling)
|
||||
{
|
||||
updateComboTransforms();
|
||||
removeComboTransforms();
|
||||
|
||||
// If was decreasing, stops roll before increasing
|
||||
if (currentValue < prevValue)
|
||||
VisibleCount = currentValue;
|
||||
Flush(false, typeof(TransformCombo));
|
||||
IsRolling = false;
|
||||
|
||||
VisibleCount = currentValue;
|
||||
VisibleCount = newValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
transformCount(new TransformCombo(Clock), visibleValue, newValue);
|
||||
IsRolling = true;
|
||||
transformRoll(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)
|
||||
private void transformRoll(TransformCombo transform, ulong currentValue, ulong newValue)
|
||||
{
|
||||
updateComboTransforms();
|
||||
removeComboTransforms();
|
||||
Flush(false, typeof(TransformCombo));
|
||||
|
||||
if (Clock == null)
|
||||
return;
|
||||
@ -222,7 +227,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
double rollingTotalDuration =
|
||||
IsRollingProportional
|
||||
? getProportionalDuration(currentValue, newValue)
|
||||
? GetProportionalDuration(currentValue, newValue)
|
||||
: RollingDuration;
|
||||
|
||||
transform.StartTime = Time;
|
||||
@ -234,11 +239,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Transforms.Add(transform);
|
||||
}
|
||||
|
||||
protected virtual void updateTextSize()
|
||||
{
|
||||
countSpriteText.TextSize = TextSize;
|
||||
}
|
||||
|
||||
protected class TransformCombo : Transform<ulong>
|
||||
{
|
||||
public override ulong CurrentValue
|
||||
|
62
osu.Game/Graphics/UserInterface/PercentageCounter.cs
Normal file
62
osu.Game/Graphics/UserInterface/PercentageCounter.cs
Normal file
@ -0,0 +1,62 @@
|
||||
//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.Transformations;
|
||||
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>
|
||||
/// Used as an accuracy counter. Represented visually as a percentage.
|
||||
/// </summary>
|
||||
public class PercentageCounter : RollingCounter<float>
|
||||
{
|
||||
protected override Type TransformType => typeof(TransformAccuracy);
|
||||
|
||||
public override double RollingDuration => 500;
|
||||
public override EasingTypes RollingEasing => EasingTypes.Out;
|
||||
|
||||
private float epsilon => 1e-10f;
|
||||
|
||||
public void SetFraction(float numerator, float denominator)
|
||||
{
|
||||
Count = Math.Abs(denominator) < epsilon ? 1.0f : numerator / denominator;
|
||||
}
|
||||
|
||||
public PercentageCounter()
|
||||
{
|
||||
Count = 1.0f;
|
||||
}
|
||||
|
||||
protected override string FormatCount(float count)
|
||||
{
|
||||
return $@"{count:P2}";
|
||||
}
|
||||
|
||||
protected override double GetProportionalDuration(float currentValue, float newValue)
|
||||
{
|
||||
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
|
||||
}
|
||||
|
||||
protected class TransformAccuracy : TransformFloat
|
||||
{
|
||||
public override void Apply(Drawable d)
|
||||
{
|
||||
base.Apply(d);
|
||||
(d as PercentageCounter).VisibleCount = CurrentValue;
|
||||
}
|
||||
|
||||
public TransformAccuracy(IClock clock)
|
||||
: base(clock)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,9 +23,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <remarks>
|
||||
/// Must be a subclass of Transform<T>
|
||||
/// </remarks>
|
||||
protected virtual Type transformType => typeof(Transform<T>);
|
||||
protected virtual Type TransformType => typeof(Transform<T>);
|
||||
|
||||
protected SpriteText countSpriteText;
|
||||
protected SpriteText CountSpriteText;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the roll-up duration will be proportional to change in value.
|
||||
@ -36,15 +36,15 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// 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 double RollingDuration = 0;
|
||||
public virtual double RollingDuration => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Easing for the counter rollover animation.
|
||||
/// </summary>
|
||||
public EasingTypes RollingEasing = EasingTypes.None;
|
||||
public virtual EasingTypes RollingEasing => EasingTypes.None;
|
||||
|
||||
protected T prevVisibleCount;
|
||||
protected T visibleCount;
|
||||
private T prevVisibleCount;
|
||||
private T visibleCount;
|
||||
|
||||
/// <summary>
|
||||
/// Value shown at the current moment.
|
||||
@ -60,7 +60,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (visibleCount.Equals(value))
|
||||
return;
|
||||
visibleCount = value;
|
||||
countSpriteText.Text = formatCount(value);
|
||||
CountSpriteText.Text = FormatCount(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
count = value;
|
||||
if (IsLoaded)
|
||||
{
|
||||
transformCount(visibleCount, count);
|
||||
TransformCount(visibleCount, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
set
|
||||
{
|
||||
textSize = value;
|
||||
countSpriteText.TextSize = value;
|
||||
CountSpriteText.TextSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,13 +105,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected RollingCounter()
|
||||
{
|
||||
Debug.Assert(
|
||||
transformType.IsSubclassOf(typeof(Transform<T>)) || transformType == typeof(Transform<T>),
|
||||
TransformType.IsSubclassOf(typeof(Transform<T>)) || TransformType == typeof(Transform<T>),
|
||||
@"transformType should be a subclass of Transform<T>."
|
||||
);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
countSpriteText = new SpriteText
|
||||
CountSpriteText = new SpriteText
|
||||
{
|
||||
Anchor = this.Anchor,
|
||||
Origin = this.Origin,
|
||||
@ -123,13 +123,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
removeTransforms(transformType);
|
||||
Flush(false, TransformType);
|
||||
|
||||
VisibleCount = Count;
|
||||
|
||||
countSpriteText.Text = formatCount(count);
|
||||
countSpriteText.Anchor = this.Anchor;
|
||||
countSpriteText.Origin = this.Origin;
|
||||
CountSpriteText.Text = FormatCount(count);
|
||||
CountSpriteText.Anchor = this.Anchor;
|
||||
CountSpriteText.Origin = this.Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -147,7 +147,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public virtual void StopRolling()
|
||||
{
|
||||
removeTransforms(transformType);
|
||||
Flush(false, TransformType);
|
||||
VisibleCount = Count;
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <param name="currentValue">Current visible value.</param>
|
||||
/// <param name="newValue">New final value.</param>
|
||||
/// <returns>Calculated rollover duration in milliseconds.</returns>
|
||||
protected virtual double getProportionalDuration(T currentValue, T newValue)
|
||||
protected virtual double GetProportionalDuration(T currentValue, T newValue)
|
||||
{
|
||||
return RollingDuration;
|
||||
}
|
||||
@ -180,46 +180,32 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
/// <param name="count">Count to format.</param>
|
||||
/// <returns>Count formatted as a string.</returns>
|
||||
protected virtual string formatCount(T count)
|
||||
protected virtual string FormatCount(T count)
|
||||
{
|
||||
return count.ToString();
|
||||
}
|
||||
|
||||
protected void updateTransforms(Type type)
|
||||
{
|
||||
foreach (ITransform t in Transforms.AliveItems)
|
||||
if (t.GetType() == type)
|
||||
t.Apply(this);
|
||||
}
|
||||
|
||||
protected void removeTransforms(Type type)
|
||||
{
|
||||
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="currentValue">Count value before modification.</param>
|
||||
/// <param name="newValue">Expected count value after modification-</param>
|
||||
/// <seealso cref="transformType"/>
|
||||
protected virtual void transformCount(T currentValue, T newValue)
|
||||
/// <seealso cref="TransformType"/>
|
||||
protected virtual void TransformCount(T currentValue, T newValue)
|
||||
{
|
||||
object[] parameters = { Clock };
|
||||
transformCount((Transform<T>)Activator.CreateInstance(transformType, parameters), currentValue, newValue);
|
||||
TransformCount((Transform<T>)Activator.CreateInstance(TransformType, parameters), currentValue, newValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intended to be used by transformCount().
|
||||
/// Intended to be used by TransformCount(T currentValue, T newValue).
|
||||
/// </summary>
|
||||
/// <see cref="transformCount"/>
|
||||
protected void transformCount(Transform<T> transform, T currentValue, T newValue)
|
||||
protected void TransformCount(Transform<T> transform, T currentValue, T newValue)
|
||||
{
|
||||
Type type = transform.GetType();
|
||||
|
||||
updateTransforms(type);
|
||||
removeTransforms(type);
|
||||
Flush(false, type);
|
||||
|
||||
if (Clock == null)
|
||||
return;
|
||||
@ -232,7 +218,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
double rollingTotalDuration =
|
||||
IsRollingProportional
|
||||
? getProportionalDuration(currentValue, newValue)
|
||||
? GetProportionalDuration(currentValue, newValue)
|
||||
: RollingDuration;
|
||||
|
||||
transform.StartTime = Time;
|
||||
|
@ -16,7 +16,10 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class ScoreCounter : RollingCounter<ulong>
|
||||
{
|
||||
protected override Type transformType => typeof(TransformScore);
|
||||
protected override Type TransformType => typeof(TransformScore);
|
||||
|
||||
public override double RollingDuration => 1000;
|
||||
public override EasingTypes RollingEasing => EasingTypes.Out;
|
||||
|
||||
/// <summary>
|
||||
/// How many leading zeroes the counter has.
|
||||
@ -33,11 +36,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <param name="leading">How many leading zeroes the counter will have.</param>
|
||||
public ScoreCounter(uint leading = 0)
|
||||
{
|
||||
countSpriteText.FixedWidth = true;
|
||||
CountSpriteText.FixedWidth = true;
|
||||
LeadingZeroes = leading;
|
||||
|
||||
RollingDuration = 1000;
|
||||
RollingEasing = EasingTypes.Out;
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
@ -45,12 +45,12 @@ namespace osu.Game.Graphics.UserInterface
|
||||
base.Load(game);
|
||||
}
|
||||
|
||||
protected override double getProportionalDuration(ulong currentValue, ulong newValue)
|
||||
protected override double GetProportionalDuration(ulong currentValue, ulong newValue)
|
||||
{
|
||||
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
}
|
||||
|
||||
protected override string formatCount(ulong count)
|
||||
protected override string FormatCount(ulong count)
|
||||
{
|
||||
return count.ToString("D" + LeadingZeroes);
|
||||
}
|
||||
|
@ -1,142 +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 OpenTK;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
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>
|
||||
/// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
|
||||
/// </summary>
|
||||
public class StandardComboCounter : ComboCounter
|
||||
{
|
||||
protected SpriteText popOutSpriteText;
|
||||
|
||||
protected uint scheduledPopOutCurrentId = 0;
|
||||
|
||||
public ulong PopOutDuration = 150;
|
||||
public float PopOutBigScale = 2.0f;
|
||||
public float PopOutSmallScale = 1.1f;
|
||||
public EasingTypes PopOutEasing = EasingTypes.None;
|
||||
public bool CanPopOutWhenBackwards = false;
|
||||
public float PopOutInitialAlpha = 0.75f;
|
||||
|
||||
public Vector2 InnerCountPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return countSpriteText.Position;
|
||||
}
|
||||
set
|
||||
{
|
||||
countSpriteText.Position = value;
|
||||
}
|
||||
}
|
||||
|
||||
public StandardComboCounter()
|
||||
{
|
||||
popOutSpriteText = new SpriteText
|
||||
{
|
||||
Origin = this.Origin,
|
||||
Anchor = this.Anchor,
|
||||
TextSize = this.TextSize,
|
||||
Alpha = 0,
|
||||
};
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
popOutSpriteText.Origin = this.Origin;
|
||||
popOutSpriteText.Anchor = this.Anchor;
|
||||
|
||||
Add(popOutSpriteText);
|
||||
}
|
||||
|
||||
protected override double getProportionalDuration(ulong currentValue, ulong newValue)
|
||||
{
|
||||
double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
|
||||
return difference * RollingDuration;
|
||||
}
|
||||
|
||||
protected override string formatCount(ulong count)
|
||||
{
|
||||
return count.ToString("#,0") + "x";
|
||||
}
|
||||
|
||||
protected virtual void transformPopOut(ulong currentValue, ulong newValue)
|
||||
{
|
||||
popOutSpriteText.Text = formatCount(newValue);
|
||||
countSpriteText.Text = formatCount(currentValue);
|
||||
|
||||
popOutSpriteText.ScaleTo(PopOutBigScale);
|
||||
popOutSpriteText.FadeTo(PopOutInitialAlpha);
|
||||
popOutSpriteText.MoveTo(Vector2.Zero);
|
||||
|
||||
popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
|
||||
popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
|
||||
popOutSpriteText.MoveTo(countSpriteText.Position, PopOutDuration, PopOutEasing);
|
||||
|
||||
scheduledPopOutCurrentId++;
|
||||
uint newTaskId = scheduledPopOutCurrentId;
|
||||
Scheduler.AddDelayed(delegate
|
||||
{
|
||||
scheduledPopOutSmall(newTaskId, newValue);
|
||||
}, PopOutDuration);
|
||||
}
|
||||
|
||||
protected virtual void transformNoPopOut(ulong newValue)
|
||||
{
|
||||
scheduledPopOutCurrentId++;
|
||||
countSpriteText.Text = formatCount(newValue);
|
||||
countSpriteText.ScaleTo(1);
|
||||
}
|
||||
|
||||
protected virtual void transformPopOutSmall(ulong newValue)
|
||||
{
|
||||
countSpriteText.Text = formatCount(newValue);
|
||||
countSpriteText.ScaleTo(PopOutSmallScale);
|
||||
countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
|
||||
}
|
||||
|
||||
protected virtual void scheduledPopOutSmall(uint id, ulong newValue)
|
||||
{
|
||||
// Too late; scheduled task invalidated
|
||||
if (id != scheduledPopOutCurrentId)
|
||||
return;
|
||||
|
||||
transformPopOutSmall(newValue);
|
||||
}
|
||||
|
||||
protected override void transformVisibleCount(ulong currentValue, ulong newValue)
|
||||
{
|
||||
if (newValue == 0)
|
||||
countSpriteText.FadeOut(PopOutDuration);
|
||||
else
|
||||
countSpriteText.Show();
|
||||
|
||||
if (newValue > currentValue || CanPopOutWhenBackwards)
|
||||
transformPopOut(currentValue, newValue);
|
||||
else
|
||||
transformNoPopOut(newValue);
|
||||
}
|
||||
|
||||
protected override void updateTextSize()
|
||||
{
|
||||
base.updateTextSize();
|
||||
|
||||
popOutSpriteText.TextSize = this.TextSize;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Timing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -35,14 +34,14 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected set;
|
||||
}
|
||||
|
||||
public double AnimationDelay = 150;
|
||||
private double animationDelay => 150;
|
||||
|
||||
public double ScalingDuration = 500;
|
||||
public EasingTypes ScalingEasing = EasingTypes.OutElasticHalf;
|
||||
public float MinStarScale = 0.3f;
|
||||
private double scalingDuration => 500;
|
||||
private EasingTypes scalingEasing => EasingTypes.OutElasticHalf;
|
||||
private float minStarScale => 0.3f;
|
||||
|
||||
public double FadingDuration = 100;
|
||||
public float MinStarAlpha = 0.5f;
|
||||
private double fadingDuration => 100;
|
||||
private float minStarAlpha => 0.5f;
|
||||
|
||||
public float StarSize = 20;
|
||||
public float StarSpacing = 4;
|
||||
@ -52,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
get
|
||||
{
|
||||
double elapsedTime = Time - transformStartTime;
|
||||
double expectedElapsedTime = Math.Abs(prevCount - count) * AnimationDelay;
|
||||
double expectedElapsedTime = Math.Abs(prevCount - count) * animationDelay;
|
||||
if (elapsedTime >= expectedElapsedTime)
|
||||
return count;
|
||||
return Interpolation.ValueAt(elapsedTime, prevCount, count, 0, expectedElapsedTime);
|
||||
@ -147,21 +146,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private float getStarScale(int i, float value)
|
||||
{
|
||||
if (value <= i)
|
||||
return MinStarScale;
|
||||
return minStarScale;
|
||||
if (i + 1 <= value)
|
||||
return 1.0f;
|
||||
return Interpolation.ValueAt(value, MinStarScale, 1.0f, i, i + 1);
|
||||
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);
|
||||
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].FadeTo(i < value ? 1.0f : minStarAlpha);
|
||||
stars[i].ScaleTo(getStarScale(i, value));
|
||||
}
|
||||
|
||||
@ -172,9 +171,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
stars[i].DelayReset();
|
||||
stars[i].ClearTransformations();
|
||||
if (currentValue <= newValue)
|
||||
stars[i].Delay(Math.Max(i - currentValue, 0) * AnimationDelay);
|
||||
stars[i].Delay(Math.Max(i - currentValue, 0) * animationDelay);
|
||||
else
|
||||
stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * AnimationDelay);
|
||||
stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * animationDelay);
|
||||
transformStar(i, newValue);
|
||||
}
|
||||
transformStartTime = Time;
|
||||
|
Reference in New Issue
Block a user