1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:43:01 +08:00

Tidying code and restricting methods

This commit is contained in:
Adonais Romero González 2016-10-15 19:07:07 -05:00
parent 84dcb63ad2
commit 862dc1d7c7
11 changed files with 137 additions and 155 deletions

View File

@ -112,6 +112,7 @@ namespace osu.Desktop.Tests
{
score.Count = 0;
standardCombo.Count = 0;
taikoCombo.Count = 0;
maniaCombo.Count = 0;
catchCombo.Count = 0;
numerator = denominator = 0;

View File

@ -26,34 +26,37 @@ namespace osu.Game.GameModes.Play.Catch
return $@"{count:#,0}";
}
private void animateFade()
{
Show();
Delay(FadeOutDelay);
FadeOut(FadeOutDuration);
DelayReset();
}
protected override void OnCountChange(ulong currentValue, ulong newValue)
{
if (newValue != 0)
this.Show();
animateFade();
base.OnCountChange(currentValue, newValue);
}
protected override void OnCountRolling(ulong currentValue, ulong newValue)
{
PopOutSpriteText.Colour = CountSpriteText.Colour;
this.FadeOut(FadeOutDuration);
if (!IsRolling)
{
PopOutSpriteText.Colour = DisplayedCountSpriteText.Colour;
FadeOut(FadeOutDuration);
}
base.OnCountRolling(currentValue, newValue);
}
protected override void OnCountIncrement(ulong currentValue, ulong newValue)
{
this.Show();
animateFade();
base.OnCountIncrement(currentValue, newValue);
}
protected override void transformPopOutSmall(ulong newValue)
{
base.transformPopOutSmall(newValue);
CountSpriteText.Delay(FadeOutDelay);
CountSpriteText.FadeOut(FadeOutDuration);
CountSpriteText.DelayReset();
}
/// <summary>
/// Increaces counter and tints pop-out before animation.
/// </summary>

View File

@ -32,13 +32,7 @@ namespace osu.Game.GameModes.Play
protected virtual float PopOutInitialAlpha => 0.75f;
/// <summary>
/// If true, the roll-down duration will be proportional to the counter.
/// </summary>
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.
/// Duration in milliseconds for the counter roll-up animation for each element.
/// </summary>
protected virtual double RollingDuration => 20;
@ -47,25 +41,23 @@ namespace osu.Game.GameModes.Play
/// </summary>
protected EasingTypes RollingEasing => EasingTypes.None;
private ulong prevVisibleCount;
private ulong visibleCount;
private ulong prevDisplayedCount;
private ulong displayedCount;
/// <summary>
/// Value shown at the current moment.
/// </summary>
public virtual ulong VisibleCount
public virtual ulong DisplayedCount
{
get
{
return visibleCount;
return displayedCount;
}
protected set
{
if (visibleCount.Equals(value))
if (displayedCount.Equals(value))
return;
prevVisibleCount = visibleCount;
visibleCount = value;
transformVisibleCount(prevVisibleCount, visibleCount, IsRolling);
updateDisplayedCount(displayedCount, value, IsRolling);
}
}
@ -83,21 +75,11 @@ namespace osu.Game.GameModes.Play
}
set
{
setCount(value);
updateCount(value);
}
}
private void setCount(ulong value, bool rolling = false)
{
prevCount = count;
count = value;
if (IsLoaded)
{
transformCount(VisibleCount, prevCount, value, rolling);
}
}
protected SpriteText CountSpriteText;
protected SpriteText DisplayedCountSpriteText;
private float textSize = 20.0f;
public float TextSize
@ -106,7 +88,7 @@ namespace osu.Game.GameModes.Play
set
{
textSize = value;
CountSpriteText.TextSize = TextSize;
DisplayedCountSpriteText.TextSize = TextSize;
PopOutSpriteText.TextSize = TextSize;
}
}
@ -118,7 +100,7 @@ namespace osu.Game.GameModes.Play
{
Children = new Drawable[]
{
CountSpriteText = new SpriteText
DisplayedCountSpriteText = new SpriteText
{
Anchor = this.Anchor,
Origin = this.Origin,
@ -135,19 +117,19 @@ namespace osu.Game.GameModes.Play
{
base.Load(game);
CountSpriteText.Text = FormatCount(Count);
CountSpriteText.Anchor = this.Anchor;
CountSpriteText.Origin = this.Origin;
DisplayedCountSpriteText.Text = FormatCount(Count);
DisplayedCountSpriteText.Anchor = this.Anchor;
DisplayedCountSpriteText.Origin = this.Origin;
StopRolling();
}
/// <summary>
/// Stops rollover animation, forcing the visible count to be the actual count.
/// Stops rollover animation, forcing the displayed count to be the actual count.
/// </summary>
public void StopRolling()
{
setCount(Count);
updateCount(Count);
}
/// <summary>
@ -156,7 +138,7 @@ namespace osu.Game.GameModes.Play
/// <param name="newValue">Target value.</param>
public virtual void Roll(ulong newValue = 0)
{
setCount(newValue, true);
updateCount(newValue, true);
}
/// <summary>
@ -164,13 +146,7 @@ namespace osu.Game.GameModes.Play
/// </summary>
public virtual void ResetCount()
{
Count = default(ulong);
}
protected double GetProportionalDuration(ulong currentValue, ulong newValue)
{
double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
return difference * RollingDuration;
updateCount(0);
}
protected virtual string FormatCount(ulong count)
@ -178,76 +154,78 @@ namespace osu.Game.GameModes.Play
return count.ToString();
}
protected abstract void OnVisibleCountRolling(ulong currentValue, ulong newValue);
protected abstract void OnVisibleCountIncrement(ulong newValue);
protected abstract void OnVisibleCountChange(ulong newValue);
private void transformVisibleCount(ulong currentValue, ulong newValue, bool rolling)
{
if (rolling)
OnVisibleCountRolling(currentValue, newValue);
else if (currentValue + 1 == newValue)
OnVisibleCountIncrement(newValue);
else
OnVisibleCountChange(newValue);
}
protected abstract void OnDisplayedCountRolling(ulong currentValue, ulong newValue);
protected abstract void OnDisplayedCountIncrement(ulong newValue);
protected abstract void OnDisplayedCountChange(ulong newValue);
protected virtual void OnCountRolling(ulong currentValue, ulong newValue)
{
IsRolling = true;
transformRoll(new TransformCombo(Clock), currentValue, newValue);
transformRoll(new TransformComboRoll(Clock), currentValue, newValue);
}
protected virtual void OnCountIncrement(ulong currentValue, ulong newValue) {
VisibleCount = currentValue;
VisibleCount = newValue;
DisplayedCount = newValue;
}
protected virtual void OnCountChange(ulong currentValue, ulong newValue) {
VisibleCount = currentValue;
VisibleCount = newValue;
DisplayedCount = newValue;
}
private void transformCount(
ulong visibleValue,
ulong currentValue,
ulong newValue,
bool rolling)
private double getProportionalDuration(ulong currentValue, ulong newValue)
{
double difference = currentValue > newValue ? currentValue - newValue : currentValue - newValue;
return difference * RollingDuration;
}
private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling)
{
prevDisplayedCount = currentValue;
displayedCount = newValue;
if (rolling)
OnDisplayedCountRolling(currentValue, newValue);
else if (currentValue + 1 == newValue)
OnDisplayedCountIncrement(newValue);
else
OnDisplayedCountChange(newValue);
}
private void updateCount(ulong value, bool rolling = false)
{
prevCount = count;
count = value;
if (!rolling)
{
Flush(false, typeof(TransformCombo));
Flush(false, typeof(TransformComboRoll));
IsRolling = false;
DisplayedCount = prevCount;
if (currentValue + 1 == newValue)
OnCountIncrement(currentValue, newValue);
if (prevCount + 1 == count)
OnCountIncrement(prevCount, count);
else
OnCountChange(currentValue, newValue);
OnCountChange(prevCount, count);
}
else
OnCountRolling(visibleCount, newValue);
}
private void transformRoll(TransformCombo transform, ulong currentValue, ulong newValue)
{
Flush(false, typeof(TransformCombo));
OnCountRolling(displayedCount, count);
IsRolling = true;
}
}
private void transformRoll(TransformComboRoll transform, ulong currentValue, ulong newValue)
{
Flush(false, typeof(TransformComboRoll));
if (Clock == null)
return;
if (RollingDuration == 0)
{
VisibleCount = Count;
DisplayedCount = Count;
return;
}
double rollingTotalDuration =
IsRollingProportional
? GetProportionalDuration(currentValue, newValue)
: RollingDuration;
transform.StartTime = Time;
transform.EndTime = Time + rollingTotalDuration;
transform.EndTime = Time + getProportionalDuration(currentValue, newValue);
transform.StartValue = currentValue;
transform.EndValue = newValue;
transform.Easing = RollingEasing;
@ -255,7 +233,7 @@ namespace osu.Game.GameModes.Play
Transforms.Add(transform);
}
protected class TransformCombo : Transform<ulong>
protected class TransformComboRoll : Transform<ulong>
{
public override ulong CurrentValue
{
@ -272,10 +250,10 @@ namespace osu.Game.GameModes.Play
public override void Apply(Drawable d)
{
base.Apply(d);
(d as ComboCounter).VisibleCount = CurrentValue;
(d as ComboCounter).DisplayedCount = CurrentValue;
}
public TransformCombo(IClock clock)
public TransformComboRoll(IClock clock)
: base(clock)
{
}

View File

@ -51,7 +51,7 @@ namespace osu.Game.GameModes.Play.UserInterface
public override void Apply(Drawable d)
{
base.Apply(d);
(d as ComboResultCounter).VisibleCount = CurrentValue;
(d as ComboResultCounter).DisplayedCount = CurrentValue;
}
public TransformComboResult(IClock clock)

View File

@ -54,8 +54,8 @@ namespace osu.Game.GameModes.Play.Mania
protected override void transformAnimate(ulong newValue)
{
base.transformAnimate(newValue);
CountSpriteText.FadeColour(TintColour, 0);
CountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing);
DisplayedCountSpriteText.FadeColour(TintColour, 0);
DisplayedCountSpriteText.FadeColour(OriginalColour, AnimationDuration, AnimationEasing);
}
}
}

View File

@ -25,11 +25,11 @@ namespace osu.Game.GameModes.Play.Osu
{
get
{
return CountSpriteText.Position;
return DisplayedCountSpriteText.Position;
}
set
{
CountSpriteText.Position = value;
DisplayedCountSpriteText.Position = value;
}
}
@ -58,7 +58,7 @@ namespace osu.Game.GameModes.Play.Osu
PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
PopOutSpriteText.MoveTo(CountSpriteText.Position, PopOutDuration, PopOutEasing);
PopOutSpriteText.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing);
}
protected virtual void transformPopOutRolling(ulong newValue)
@ -69,15 +69,15 @@ namespace osu.Game.GameModes.Play.Osu
protected virtual void transformNoPopOut(ulong newValue)
{
CountSpriteText.Text = FormatCount(newValue);
CountSpriteText.ScaleTo(1);
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(1);
}
protected virtual void transformPopOutSmall(ulong newValue)
{
CountSpriteText.Text = FormatCount(newValue);
CountSpriteText.ScaleTo(PopOutSmallScale);
CountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(PopOutSmallScale);
DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
}
protected virtual void scheduledPopOutSmall(uint id)
@ -86,7 +86,7 @@ namespace osu.Game.GameModes.Play.Osu
if (id != ScheduledPopOutCurrentId)
return;
VisibleCount++;
DisplayedCount++;
}
protected override void OnCountRolling(ulong currentValue, ulong newValue)
@ -97,10 +97,10 @@ namespace osu.Game.GameModes.Play.Osu
protected override void OnCountIncrement(ulong currentValue, ulong newValue)
{
if (VisibleCount != currentValue)
VisibleCount++;
while (DisplayedCount != currentValue)
DisplayedCount++;
CountSpriteText.Show();
DisplayedCountSpriteText.Show();
transformPopOut(newValue);
@ -118,12 +118,12 @@ namespace osu.Game.GameModes.Play.Osu
base.OnCountChange(currentValue, newValue);
}
protected override void OnVisibleCountRolling(ulong currentValue, ulong newValue)
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue)
{
if (newValue == 0)
CountSpriteText.FadeOut(PopOutDuration);
DisplayedCountSpriteText.FadeOut(PopOutDuration);
else
CountSpriteText.Show();
DisplayedCountSpriteText.Show();
if (CanPopOutWhileRolling)
transformPopOutRolling(newValue);
@ -131,16 +131,16 @@ namespace osu.Game.GameModes.Play.Osu
transformNoPopOut(newValue);
}
protected override void OnVisibleCountChange(ulong newValue)
protected override void OnDisplayedCountChange(ulong newValue)
{
CountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
transformNoPopOut(newValue);
}
protected override void OnVisibleCountIncrement(ulong newValue)
protected override void OnDisplayedCountIncrement(ulong newValue)
{
CountSpriteText.Show();
DisplayedCountSpriteText.Show();
transformPopOutSmall(newValue);
}

View File

@ -23,43 +23,43 @@ namespace osu.Game.GameModes.Play.Taiko
public TaikoComboCounter()
{
CountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre;
CountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre;
DisplayedCountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre;
DisplayedCountSpriteText.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);
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
DisplayedCountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing);
}
protected virtual void transformNotAnimate(ulong newValue)
{
CountSpriteText.Text = FormatCount(newValue);
CountSpriteText.ScaleTo(1);
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(1);
}
protected override void OnVisibleCountRolling(ulong currentValue, ulong newValue)
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue)
{
if (newValue == 0)
CountSpriteText.FadeOut(AnimationDuration);
DisplayedCountSpriteText.FadeOut(AnimationDuration);
else
CountSpriteText.Show();
DisplayedCountSpriteText.Show();
transformNotAnimate(newValue);
}
protected override void OnVisibleCountChange(ulong newValue)
protected override void OnDisplayedCountChange(ulong newValue)
{
CountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
transformNotAnimate(newValue);
}
protected override void OnVisibleCountIncrement(ulong newValue)
protected override void OnDisplayedCountIncrement(ulong newValue)
{
CountSpriteText.Show();
DisplayedCountSpriteText.Show();
transformAnimate(newValue);
}

View File

@ -50,7 +50,7 @@ namespace osu.Game.Graphics.UserInterface
public override void Apply(Drawable d)
{
base.Apply(d);
(d as PercentageCounter).VisibleCount = CurrentValue;
(d as PercentageCounter).DisplayedCount = CurrentValue;
}
public TransformAccuracy(IClock clock)

View File

@ -25,7 +25,7 @@ namespace osu.Game.Graphics.UserInterface
/// </remarks>
protected virtual Type TransformType => typeof(Transform<T>);
protected SpriteText CountSpriteText;
protected SpriteText DisplayedCountSpriteText;
/// <summary>
/// If true, the roll-up duration will be proportional to change in value.
@ -43,24 +43,24 @@ namespace osu.Game.Graphics.UserInterface
/// </summary>
public virtual EasingTypes RollingEasing => EasingTypes.None;
private T prevVisibleCount;
private T visibleCount;
private T prevDisplayedCount;
private T displayedCount;
/// <summary>
/// Value shown at the current moment.
/// </summary>
public virtual T VisibleCount
public virtual T DisplayedCount
{
get
{
return visibleCount;
return displayedCount;
}
protected set
{
if (visibleCount.Equals(value))
if (displayedCount.Equals(value))
return;
visibleCount = value;
CountSpriteText.Text = FormatCount(value);
displayedCount = value;
DisplayedCountSpriteText.Text = FormatCount(value);
}
}
@ -82,7 +82,7 @@ namespace osu.Game.Graphics.UserInterface
count = value;
if (IsLoaded)
{
TransformCount(visibleCount, count);
TransformCount(displayedCount, count);
}
}
}
@ -95,7 +95,7 @@ namespace osu.Game.Graphics.UserInterface
set
{
textSize = value;
CountSpriteText.TextSize = value;
DisplayedCountSpriteText.TextSize = value;
}
}
@ -111,7 +111,7 @@ namespace osu.Game.Graphics.UserInterface
Children = new Drawable[]
{
CountSpriteText = new SpriteText
DisplayedCountSpriteText = new SpriteText
{
Anchor = this.Anchor,
Origin = this.Origin,
@ -125,11 +125,11 @@ namespace osu.Game.Graphics.UserInterface
Flush(false, TransformType);
VisibleCount = Count;
DisplayedCount = Count;
CountSpriteText.Text = FormatCount(count);
CountSpriteText.Anchor = this.Anchor;
CountSpriteText.Origin = this.Origin;
DisplayedCountSpriteText.Text = FormatCount(count);
DisplayedCountSpriteText.Anchor = this.Anchor;
DisplayedCountSpriteText.Origin = this.Origin;
}
/// <summary>
@ -143,12 +143,12 @@ namespace osu.Game.Graphics.UserInterface
}
/// <summary>
/// Stops rollover animation, forcing the visible count to be the actual count.
/// Stops rollover animation, forcing the displayed count to be the actual count.
/// </summary>
public virtual void StopRolling()
{
Flush(false, TransformType);
VisibleCount = Count;
DisplayedCount = Count;
}
/// <summary>
@ -212,7 +212,7 @@ namespace osu.Game.Graphics.UserInterface
if (RollingDuration == 0)
{
VisibleCount = Count;
DisplayedCount = Count;
return;
}

View File

@ -35,7 +35,7 @@ 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;
DisplayedCountSpriteText.FixedWidth = true;
LeadingZeroes = leading;
}
@ -66,7 +66,7 @@ namespace osu.Game.Graphics.UserInterface
public override void Apply(Drawable d)
{
base.Apply(d);
(d as ScoreCounter).VisibleCount = CurrentValue;
(d as ScoreCounter).DisplayedCount = CurrentValue;
}
public TransformScore(IClock clock)

View File

@ -84,10 +84,10 @@ namespace osu.Game.Graphics.UserInterface
/// <summary>
/// Shows a float count as stars. Used as star difficulty display.
/// </summary>
/// <param name="stars">Maximum amount of stars to display.</param>
public StarCounter(int stars = 10)
/// <param name="maxstars">Maximum amount of stars to display.</param>
public StarCounter(int maxstars = 10)
{
MaxStars = Math.Max(stars, 0);
MaxStars = Math.Max(maxstars, 0);
Children = new Drawable[]
{