1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Changes according to review + Refactor

This commit is contained in:
Adonais Romero González 2016-10-14 18:23:27 -05:00
parent 53cd698b3a
commit 6bd3eaf37d
14 changed files with 459 additions and 455 deletions

View File

@ -12,6 +12,10 @@ using OpenTK;
using OpenTK.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Graphics.Sprites;
using osu.Game.GameModes.Play.Catch;
using osu.Game.GameModes.Play.Mania;
using osu.Game.GameModes.Play.Osu;
using osu.Game.GameModes.Play.Taiko;
namespace osu.Desktop.Tests
{
@ -25,6 +29,8 @@ namespace osu.Desktop.Tests
{
base.Reset();
int numerator = 0, denominator = 0;
ScoreCounter score = new ScoreCounter(7)
{
Origin = Anchor.TopRight,
@ -35,7 +41,7 @@ namespace osu.Desktop.Tests
};
Add(score);
StandardComboCounter standardCombo = new StandardComboCounter
ComboCounter standardCombo = new OsuComboCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
@ -55,18 +61,28 @@ namespace osu.Desktop.Tests
};
Add(catchCombo);
AlternativeComboCounter alternativeCombo = new AlternativeComboCounter
ComboCounter taikoCombo = new TaikoComboCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Position = new Vector2(20, 80),
Origin = Anchor.BottomCentre,
Anchor = Anchor.Centre,
Position = new Vector2(0, -160),
Count = 0,
TextSize = 40,
};
Add(alternativeCombo);
Add(taikoCombo);
ComboCounter maniaCombo = new ManiaComboCounter
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Position = new Vector2(0, -80),
Count = 0,
TextSize = 40,
};
Add(maniaCombo);
AccuracyCounter accuracyCombo = new AccuracyCounter
PercentageCounter accuracyCombo = new PercentageCounter
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
@ -95,9 +111,10 @@ namespace osu.Desktop.Tests
{
score.Count = 0;
standardCombo.Count = 0;
alternativeCombo.Count = 0;
maniaCombo.Count = 0;
catchCombo.Count = 0;
accuracyCombo.SetCount(0, 0);
numerator = denominator = 0;
accuracyCombo.SetFraction(0, 0);
stars.Count = 0;
starsLabel.Text = stars.Count.ToString("0.00");
});
@ -106,23 +123,26 @@ namespace osu.Desktop.Tests
{
score.Count += 300 + (ulong)(300.0 * (standardCombo.Count > 0 ? standardCombo.Count - 1 : 0) / 25.0);
standardCombo.Count++;
alternativeCombo.Count++;
taikoCombo.Count++;
maniaCombo.Count++;
catchCombo.CatchFruit(new Color4(
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
1)
);
accuracyCombo.Numerator++;
accuracyCombo.Denominator++;
numerator++; denominator++;
accuracyCombo.SetFraction(numerator, denominator);
});
AddButton(@"miss...", delegate
{
standardCombo.Roll();
alternativeCombo.Roll();
taikoCombo.Roll();
maniaCombo.Roll();
catchCombo.Roll();
accuracyCombo.Denominator++;
denominator++;
accuracyCombo.SetFraction(numerator, denominator);
});
AddButton(@"Alter stars", delegate
@ -136,7 +156,8 @@ namespace osu.Desktop.Tests
score.StopRolling();
standardCombo.StopRolling();
catchCombo.StopRolling();
alternativeCombo.StopRolling();
taikoCombo.StopRolling();
maniaCombo.StopRolling();
accuracyCombo.StopRolling();
stars.StopAnimation();
});

View File

@ -2,32 +2,30 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Game.GameModes.Play.Osu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.UserInterface
namespace osu.Game.GameModes.Play.Catch
{
/// <summary>
/// Similar to Standard, but without the 'x' and has tinted pop-ups. Used in osu!catch.
/// </summary>
public class CatchComboCounter : StandardComboCounter
public class CatchComboCounter : OsuComboCounter
{
public CatchComboCounter()
{
CanPopOutWhenBackwards = true;
}
protected override bool CanPopOutWhenBackwards => true;
protected override string formatCount(ulong count)
protected override string FormatCount(ulong count)
{
return count.ToString("#,0");
}
public override void Roll(ulong newValue = 0)
{
popOutSpriteText.Colour = countSpriteText.Colour;
PopOutSpriteText.Colour = CountSpriteText.Colour;
base.Roll(newValue);
}
@ -38,7 +36,7 @@ namespace osu.Game.Graphics.UserInterface
/// <param name="colour">Last grabbed fruit colour.</param>
public void CatchFruit(Color4 colour)
{
popOutSpriteText.Colour = colour;
PopOutSpriteText.Colour = colour;
Count++;
}
}

View File

@ -0,0 +1,61 @@
//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 osu.Framework;
using osu.Framework.Graphics;
using osu.Game.GameModes.Play.Taiko;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play.Mania
{
/// <summary>
/// Allows tint and vertical scaling animation. Used in osu!taiko and osu!mania.
/// </summary>
public class ManiaComboCounter : TaikoComboCounter
{
protected Color4 OriginalColour;
protected Color4 TintColour => Color4.OrangeRed;
protected Color4 PopOutColor => Color4.Red;
protected override float PopOutInitialAlpha => 1.0f;
protected override ulong PopOutDuration => 300;
public override void Load(BaseGame game)
{
base.Load(game);
PopOutSpriteText.Anchor = Anchor.BottomCentre;
PopOutSpriteText.Origin = Anchor.Centre;
PopOutSpriteText.FadeColour(PopOutColor, 0);
OriginalColour = Colour;
}
public override void Roll(ulong newValue = 0)
{
if (!IsRolling)
{
PopOutSpriteText.Text = FormatCount(VisibleCount);
PopOutSpriteText.FadeTo(PopOutInitialAlpha);
PopOutSpriteText.ScaleTo(1.0f);
PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
PopOutSpriteText.ScaleTo(PopOutScale, PopOutDuration, PopOutEasing);
}
base.Roll(newValue);
}
protected override void transformAnimate(ulong newValue)
{
base.transformAnimate(newValue);
CountSpriteText.FadeColour(TintColour, 0);
CountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing);
}
}
}

View File

@ -0,0 +1,124 @@
//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.Game.Graphics.UserInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play.Osu
{
/// <summary>
/// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
/// </summary>
public class OsuComboCounter : ComboCounter
{
protected uint ScheduledPopOutCurrentId = 0;
protected virtual float PopOutSmallScale => 1.1f;
protected virtual bool CanPopOutWhenBackwards => false;
public Vector2 InnerCountPosition
{
get
{
return CountSpriteText.Position;
}
set
{
CountSpriteText.Position = value;
}
}
public override void Load(BaseGame game)
{
base.Load(game);
PopOutSpriteText.Origin = this.Origin;
PopOutSpriteText.Anchor = this.Anchor;
Add(PopOutSpriteText);
}
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(PopOutScale);
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 OnCountRolling(ulong currentValue, ulong newValue)
{
if (newValue == 0)
CountSpriteText.FadeOut(PopOutDuration);
else
CountSpriteText.Show();
if (CanPopOutWhenBackwards)
transformPopOut(currentValue, newValue);
else
transformNoPopOut(newValue);
}
protected override void OnCountChange(ulong newValue)
{
CountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
transformNoPopOut(newValue);
}
protected override void OnCountIncrement(ulong newValue)
{
CountSpriteText.Show();
transformPopOut(newValue - 1, newValue);
}
}
}

View File

@ -0,0 +1,65 @@
//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.Graphics.Transformations;
using osu.Game.Graphics.UserInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play.Taiko
{
public class TaikoComboCounter : ComboCounter
{
protected virtual int AnimationDuration => 300;
protected virtual float ScaleFactor => 2;
protected virtual EasingTypes AnimationEasing => EasingTypes.None;
protected virtual bool CanAnimateWhenBackwards => false;
public TaikoComboCounter()
{
CountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre;
CountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre;
}
protected virtual void transformAnimate(ulong newValue)
{
CountSpriteText.Text = FormatCount(newValue);
CountSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
CountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing);
}
protected virtual void transformNotAnimate(ulong newValue)
{
CountSpriteText.Text = FormatCount(newValue);
CountSpriteText.ScaleTo(1);
}
protected override void OnCountRolling(ulong currentValue, ulong newValue)
{
if (newValue == 0)
CountSpriteText.FadeOut(AnimationDuration);
else
CountSpriteText.Show();
transformNotAnimate(newValue);
}
protected override void OnCountChange(ulong newValue)
{
CountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
transformNotAnimate(newValue);
}
protected override void OnCountIncrement(ulong newValue)
{
CountSpriteText.Show();
transformAnimate(newValue);
}
}
}

View File

@ -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)
{
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -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

View 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)
{
}
}
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -132,21 +132,22 @@
<Compile Include="GameModes\Edit\EditSongSelect.cs" />
<Compile Include="Graphics\UserInterface\ComboCounter.cs" />
<Compile Include="Graphics\UserInterface\RollingCounter.cs" />
<Compile Include="GameModes\Play\Taiko\TaikoComboCounter.cs" />
<Compile Include="Input\GlobalHotkeys.cs" />
<Compile Include="Graphics\Background\Background.cs" />
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
<Compile Include="Graphics\Cursor\OsuCursorContainer.cs" />
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
<Compile Include="Graphics\TextAwesome.cs" />
<Compile Include="Graphics\UserInterface\AlternativeComboCounter.cs" />
<Compile Include="GameModes\Play\Mania\ManiaComboCounter.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\PercentageCounter.cs" />
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
<Compile Include="Graphics\UserInterface\CatchComboCounter.cs" />
<Compile Include="Graphics\UserInterface\StandardComboCounter.cs" />
<Compile Include="GameModes\Play\Catch\CatchComboCounter.cs" />
<Compile Include="GameModes\Play\Osu\OsuComboCounter.cs" />
<Compile Include="Graphics\UserInterface\StarCounter.cs" />
<Compile Include="Online\API\APIAccess.cs" />
<Compile Include="Online\API\APIRequest.cs" />