mirror of
https://github.com/ppy/osu
synced 2024-12-17 04:15:37 +00:00
commit
ee463dc65c
180
osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
Normal file
180
osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs
Normal file
@ -0,0 +1,180 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.GameModes.Testing;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
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;
|
||||
using osu.Game.GameModes.Play;
|
||||
|
||||
namespace osu.Desktop.Tests
|
||||
{
|
||||
class TestCaseScoreCounter : TestCase
|
||||
{
|
||||
public override string Name => @"ScoreCounter";
|
||||
|
||||
public override string Description => @"Tests multiple counters";
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
|
||||
int numerator = 0, denominator = 0;
|
||||
|
||||
bool maniaHold = false;
|
||||
|
||||
ScoreCounter score = new ScoreCounter(7)
|
||||
{
|
||||
Origin = Anchor.TopRight,
|
||||
Anchor = Anchor.TopRight,
|
||||
TextSize = 40,
|
||||
Count = 0,
|
||||
Position = new Vector2(20, 20),
|
||||
};
|
||||
Add(score);
|
||||
|
||||
ComboCounter standardCombo = new OsuComboCounter
|
||||
{
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Position = new Vector2(10, 10),
|
||||
InnerCountPosition = new Vector2(10, 10),
|
||||
Count = 0,
|
||||
TextSize = 40,
|
||||
};
|
||||
Add(standardCombo);
|
||||
|
||||
CatchComboCounter catchCombo = new CatchComboCounter
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
Count = 0,
|
||||
TextSize = 40,
|
||||
};
|
||||
Add(catchCombo);
|
||||
|
||||
ComboCounter taikoCombo = new TaikoComboCounter
|
||||
{
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.Centre,
|
||||
Position = new Vector2(0, -160),
|
||||
Count = 0,
|
||||
TextSize = 40,
|
||||
};
|
||||
Add(taikoCombo);
|
||||
|
||||
ManiaComboCounter maniaCombo = new ManiaComboCounter
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
Position = new Vector2(0, -80),
|
||||
Count = 0,
|
||||
TextSize = 40,
|
||||
};
|
||||
Add(maniaCombo);
|
||||
|
||||
|
||||
PercentageCounter accuracyCombo = new PercentageCounter
|
||||
{
|
||||
Origin = Anchor.TopRight,
|
||||
Anchor = Anchor.TopRight,
|
||||
Position = new Vector2(20, 60),
|
||||
};
|
||||
Add(accuracyCombo);
|
||||
|
||||
StarCounter stars = new StarCounter
|
||||
{
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Position = new Vector2(20, 160),
|
||||
Count = 5,
|
||||
};
|
||||
Add(stars);
|
||||
|
||||
SpriteText starsLabel = new SpriteText
|
||||
{
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Position = new Vector2(20, 190),
|
||||
Text = stars.Count.ToString("0.00"),
|
||||
};
|
||||
Add(starsLabel);
|
||||
|
||||
AddButton(@"Reset all", delegate
|
||||
{
|
||||
score.Count = 0;
|
||||
standardCombo.Count = 0;
|
||||
taikoCombo.Count = 0;
|
||||
maniaCombo.Count = 0;
|
||||
catchCombo.Count = 0;
|
||||
numerator = denominator = 0;
|
||||
accuracyCombo.SetFraction(0, 0);
|
||||
stars.Count = 0;
|
||||
starsLabel.Text = stars.Count.ToString("0.00");
|
||||
});
|
||||
|
||||
AddButton(@"Hit! :D", delegate
|
||||
{
|
||||
score.Count += 300 + (ulong)(300.0 * (standardCombo.Count > 0 ? standardCombo.Count - 1 : 0) / 25.0);
|
||||
standardCombo.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)
|
||||
);
|
||||
numerator++; denominator++;
|
||||
accuracyCombo.SetFraction(numerator, denominator);
|
||||
});
|
||||
|
||||
AddButton(@"miss...", delegate
|
||||
{
|
||||
standardCombo.Roll();
|
||||
taikoCombo.Roll();
|
||||
maniaCombo.Roll();
|
||||
catchCombo.Roll();
|
||||
denominator++;
|
||||
accuracyCombo.SetFraction(numerator, denominator);
|
||||
});
|
||||
|
||||
AddButton(@"mania hold", delegate
|
||||
{
|
||||
if (!maniaHold)
|
||||
maniaCombo.HoldStart();
|
||||
else
|
||||
maniaCombo.HoldEnd();
|
||||
maniaHold = !maniaHold;
|
||||
});
|
||||
|
||||
AddButton(@"Alter stars", delegate
|
||||
{
|
||||
stars.Count = RNG.NextSingle() * (stars.MaxStars + 1);
|
||||
starsLabel.Text = stars.Count.ToString("0.00");
|
||||
});
|
||||
|
||||
AddButton(@"Stop counters", delegate
|
||||
{
|
||||
score.StopRolling();
|
||||
standardCombo.StopRolling();
|
||||
catchCombo.StopRolling();
|
||||
taikoCombo.StopRolling();
|
||||
maniaCombo.StopRolling();
|
||||
accuracyCombo.StopRolling();
|
||||
stars.StopAnimation();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -142,6 +142,7 @@
|
||||
<Compile Include="Tests\TestCaseGamefield.cs" />
|
||||
<Compile Include="Tests\TestCaseKeyCounter.cs" />
|
||||
<Compile Include="Tests\TestCaseMenuButtonSystem.cs" />
|
||||
<Compile Include="Tests\TestCaseScoreCounter.cs" />
|
||||
<Compile Include="Tests\TestCaseTextAwesome.cs" />
|
||||
<Compile Include="VisualTestGame.cs" />
|
||||
</ItemGroup>
|
||||
|
70
osu.Game/GameModes/Play/Catch/CatchComboCounter.cs
Normal file
70
osu.Game/GameModes/Play/Catch/CatchComboCounter.cs
Normal file
@ -0,0 +1,70 @@
|
||||
//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.Game.GameModes.Play.Osu;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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 : OsuComboCounter
|
||||
{
|
||||
protected override bool CanPopOutWhileRolling => true;
|
||||
|
||||
protected virtual double FadeOutDelay => 1000;
|
||||
protected virtual double FadeOutDuration => 300;
|
||||
|
||||
protected override string FormatCount(ulong count)
|
||||
{
|
||||
return $@"{count:#,0}";
|
||||
}
|
||||
|
||||
private void animateFade()
|
||||
{
|
||||
Show();
|
||||
Delay(FadeOutDelay);
|
||||
FadeOut(FadeOutDuration);
|
||||
DelayReset();
|
||||
}
|
||||
|
||||
protected override void OnCountChange(ulong currentValue, ulong newValue)
|
||||
{
|
||||
if (newValue != 0)
|
||||
animateFade();
|
||||
base.OnCountChange(currentValue, newValue);
|
||||
}
|
||||
|
||||
protected override void OnCountRolling(ulong currentValue, ulong newValue)
|
||||
{
|
||||
if (!IsRolling)
|
||||
{
|
||||
PopOutSpriteText.Colour = DisplayedCountSpriteText.Colour;
|
||||
FadeOut(FadeOutDuration);
|
||||
}
|
||||
base.OnCountRolling(currentValue, newValue);
|
||||
}
|
||||
|
||||
protected override void OnCountIncrement(ulong currentValue, ulong newValue)
|
||||
{
|
||||
animateFade();
|
||||
base.OnCountIncrement(currentValue, 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++;
|
||||
}
|
||||
}
|
||||
}
|
266
osu.Game/GameModes/Play/ComboCounter.cs
Normal file
266
osu.Game/GameModes/Play/ComboCounter.cs
Normal file
@ -0,0 +1,266 @@
|
||||
//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.GameModes.Play
|
||||
{
|
||||
public abstract class ComboCounter : Container
|
||||
{
|
||||
public bool IsRolling
|
||||
{
|
||||
get; protected set;
|
||||
}
|
||||
|
||||
protected SpriteText PopOutSpriteText;
|
||||
|
||||
protected virtual double PopOutDuration => 150;
|
||||
protected virtual float PopOutScale => 2.0f;
|
||||
protected virtual EasingTypes PopOutEasing => EasingTypes.None;
|
||||
protected virtual float PopOutInitialAlpha => 0.75f;
|
||||
|
||||
/// <summary>
|
||||
/// Duration in milliseconds for the counter roll-up animation for each element.
|
||||
/// </summary>
|
||||
protected virtual double RollingDuration => 20;
|
||||
|
||||
/// <summary>
|
||||
/// Easing for the counter rollover animation.
|
||||
/// </summary>
|
||||
protected EasingTypes RollingEasing => EasingTypes.None;
|
||||
|
||||
private ulong displayedCount;
|
||||
|
||||
/// <summary>
|
||||
/// Value shown at the current moment.
|
||||
/// </summary>
|
||||
public virtual ulong DisplayedCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return displayedCount;
|
||||
}
|
||||
protected set
|
||||
{
|
||||
if (displayedCount.Equals(value))
|
||||
return;
|
||||
updateDisplayedCount(displayedCount, value, IsRolling);
|
||||
}
|
||||
}
|
||||
|
||||
protected ulong prevCount;
|
||||
protected ulong count;
|
||||
|
||||
/// <summary>
|
||||
/// Actual value of counter.
|
||||
/// </summary>
|
||||
public virtual ulong Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
}
|
||||
set
|
||||
{
|
||||
updateCount(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected SpriteText DisplayedCountSpriteText;
|
||||
|
||||
private float textSize = 20.0f;
|
||||
public float TextSize
|
||||
{
|
||||
get { return textSize; }
|
||||
set
|
||||
{
|
||||
textSize = value;
|
||||
DisplayedCountSpriteText.TextSize = TextSize;
|
||||
PopOutSpriteText.TextSize = TextSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base of all combo counters.
|
||||
/// </summary>
|
||||
protected ComboCounter()
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
DisplayedCountSpriteText = new SpriteText
|
||||
{
|
||||
Alpha = 0,
|
||||
},
|
||||
PopOutSpriteText = new SpriteText
|
||||
{
|
||||
Alpha = 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
DisplayedCountSpriteText.Text = FormatCount(Count);
|
||||
DisplayedCountSpriteText.Anchor = this.Anchor;
|
||||
DisplayedCountSpriteText.Origin = this.Origin;
|
||||
|
||||
StopRolling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops rollover animation, forcing the displayed count to be the actual count.
|
||||
/// </summary>
|
||||
public void StopRolling()
|
||||
{
|
||||
updateCount(Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animates roll-back to 0.
|
||||
/// </summary>
|
||||
public void Roll()
|
||||
{
|
||||
Roll(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animates roll-up/roll-back to an specific value.
|
||||
/// </summary>
|
||||
/// <param name="newValue">Target value.</param>
|
||||
public virtual void Roll(ulong newValue)
|
||||
{
|
||||
updateCount(newValue, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets count to default value.
|
||||
/// </summary>
|
||||
public virtual void ResetCount()
|
||||
{
|
||||
updateCount(0);
|
||||
}
|
||||
|
||||
protected virtual string FormatCount(ulong count)
|
||||
{
|
||||
return count.ToString();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
transformRoll(new TransformComboRoll(Clock), currentValue, newValue);
|
||||
}
|
||||
|
||||
protected virtual void OnCountIncrement(ulong currentValue, ulong newValue) {
|
||||
DisplayedCount = newValue;
|
||||
}
|
||||
|
||||
protected virtual void OnCountChange(ulong currentValue, ulong newValue) {
|
||||
DisplayedCount = newValue;
|
||||
}
|
||||
|
||||
private double getProportionalDuration(ulong currentValue, ulong newValue)
|
||||
{
|
||||
double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
return difference * RollingDuration;
|
||||
}
|
||||
|
||||
private void updateDisplayedCount(ulong currentValue, ulong newValue, bool rolling)
|
||||
{
|
||||
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(TransformComboRoll));
|
||||
IsRolling = false;
|
||||
DisplayedCount = prevCount;
|
||||
|
||||
if (prevCount + 1 == count)
|
||||
OnCountIncrement(prevCount, count);
|
||||
else
|
||||
OnCountChange(prevCount, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnCountRolling(displayedCount, count);
|
||||
IsRolling = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void transformRoll(TransformComboRoll transform, ulong currentValue, ulong newValue)
|
||||
{
|
||||
Flush(false, typeof(TransformComboRoll));
|
||||
|
||||
if (Clock == null)
|
||||
return;
|
||||
|
||||
if (RollingDuration < 1)
|
||||
{
|
||||
DisplayedCount = Count;
|
||||
return;
|
||||
}
|
||||
|
||||
transform.StartTime = Time;
|
||||
transform.EndTime = Time + getProportionalDuration(currentValue, newValue);
|
||||
transform.StartValue = currentValue;
|
||||
transform.EndValue = newValue;
|
||||
transform.Easing = RollingEasing;
|
||||
|
||||
Transforms.Add(transform);
|
||||
}
|
||||
|
||||
protected class TransformComboRoll : 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).DisplayedCount = CurrentValue;
|
||||
}
|
||||
|
||||
public TransformComboRoll(IClock clock)
|
||||
: base(clock)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
osu.Game/GameModes/Play/ComboResultCounter.cs
Normal file
63
osu.Game/GameModes/Play/ComboResultCounter.cs
Normal file
@ -0,0 +1,63 @@
|
||||
//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 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to display combo with a roll-up animation in results screen.
|
||||
/// </summary>
|
||||
public class ComboResultCounter : RollingCounter<ulong>
|
||||
{
|
||||
protected override Type TransformType => typeof(TransformComboResult);
|
||||
|
||||
protected override double RollingDuration => 500;
|
||||
protected override EasingTypes RollingEasing => EasingTypes.Out;
|
||||
|
||||
protected override double GetProportionalDuration(ulong currentValue, ulong newValue)
|
||||
{
|
||||
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||
}
|
||||
|
||||
protected override string FormatCount(ulong count)
|
||||
{
|
||||
return $@"{count}x";
|
||||
}
|
||||
|
||||
protected class TransformComboResult : 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 ComboResultCounter).DisplayedCount = CurrentValue;
|
||||
}
|
||||
|
||||
public TransformComboResult(IClock clock)
|
||||
: base(clock)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
84
osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs
Normal file
84
osu.Game/GameModes/Play/Mania/ManiaComboCounter.cs
Normal file
@ -0,0 +1,84 @@
|
||||
//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.Framework.Graphics.Transformations;
|
||||
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>
|
||||
/// Similar to osu!taiko, with a pop-out animation when failing (rolling). Used in osu!mania.
|
||||
/// </summary>
|
||||
public class ManiaComboCounter : TaikoComboCounter
|
||||
{
|
||||
protected ushort KeysHeld = 0;
|
||||
|
||||
protected Color4 OriginalColour;
|
||||
|
||||
protected Color4 TintColour => Color4.Orange;
|
||||
protected EasingTypes TintEasing => EasingTypes.None;
|
||||
protected int TintDuration => 500;
|
||||
|
||||
protected Color4 PopOutColor => Color4.Red;
|
||||
protected override float PopOutInitialAlpha => 1.0f;
|
||||
protected override double PopOutDuration => 300;
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
PopOutSpriteText.Anchor = Anchor.BottomCentre;
|
||||
PopOutSpriteText.Origin = Anchor.Centre;
|
||||
PopOutSpriteText.FadeColour(PopOutColor, 0);
|
||||
OriginalColour = DisplayedCountSpriteText.Colour;
|
||||
}
|
||||
|
||||
protected override void OnCountRolling(ulong currentValue, ulong newValue)
|
||||
{
|
||||
if (!IsRolling && newValue < currentValue)
|
||||
{
|
||||
PopOutSpriteText.Text = FormatCount(currentValue);
|
||||
|
||||
PopOutSpriteText.FadeTo(PopOutInitialAlpha);
|
||||
PopOutSpriteText.ScaleTo(1.0f);
|
||||
|
||||
PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
|
||||
PopOutSpriteText.ScaleTo(PopOutScale, PopOutDuration, PopOutEasing);
|
||||
}
|
||||
|
||||
base.OnCountRolling(currentValue, newValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tints text while holding a key.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Does not alter combo. This has to be done depending of the scoring system.
|
||||
/// (i.e. v1 = each period of time; v2 = when starting and ending a key hold)
|
||||
/// </remarks>
|
||||
public void HoldStart()
|
||||
{
|
||||
if (KeysHeld == 0)
|
||||
DisplayedCountSpriteText.FadeColour(TintColour, TintDuration, TintEasing);
|
||||
KeysHeld++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends tinting.
|
||||
/// </summary>
|
||||
public void HoldEnd()
|
||||
{
|
||||
KeysHeld--;
|
||||
if (KeysHeld == 0)
|
||||
DisplayedCountSpriteText.FadeColour(OriginalColour, TintDuration, TintEasing);
|
||||
}
|
||||
}
|
||||
}
|
149
osu.Game/GameModes/Play/Osu/OsuComboCounter.cs
Normal file
149
osu.Game/GameModes/Play/Osu/OsuComboCounter.cs
Normal file
@ -0,0 +1,149 @@
|
||||
//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 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 CanPopOutWhileRolling => false;
|
||||
|
||||
public Vector2 InnerCountPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return DisplayedCountSpriteText.Position;
|
||||
}
|
||||
set
|
||||
{
|
||||
DisplayedCountSpriteText.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}x";
|
||||
}
|
||||
|
||||
protected virtual void TransformPopOut(ulong newValue)
|
||||
{
|
||||
PopOutSpriteText.Text = FormatCount(newValue);
|
||||
|
||||
PopOutSpriteText.ScaleTo(PopOutScale);
|
||||
PopOutSpriteText.FadeTo(PopOutInitialAlpha);
|
||||
PopOutSpriteText.MoveTo(Vector2.Zero);
|
||||
|
||||
PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
|
||||
PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
|
||||
PopOutSpriteText.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing);
|
||||
}
|
||||
|
||||
protected virtual void TransformPopOutRolling(ulong newValue)
|
||||
{
|
||||
TransformPopOut(newValue);
|
||||
TransformPopOutSmall(newValue);
|
||||
}
|
||||
|
||||
protected virtual void TransformNoPopOut(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.Text = FormatCount(newValue);
|
||||
DisplayedCountSpriteText.ScaleTo(1);
|
||||
}
|
||||
|
||||
protected virtual void TransformPopOutSmall(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.Text = FormatCount(newValue);
|
||||
DisplayedCountSpriteText.ScaleTo(PopOutSmallScale);
|
||||
DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
|
||||
}
|
||||
|
||||
protected virtual void ScheduledPopOutSmall(uint id)
|
||||
{
|
||||
// Too late; scheduled task invalidated
|
||||
if (id != ScheduledPopOutCurrentId)
|
||||
return;
|
||||
|
||||
DisplayedCount++;
|
||||
}
|
||||
|
||||
protected override void OnCountRolling(ulong currentValue, ulong newValue)
|
||||
{
|
||||
ScheduledPopOutCurrentId++;
|
||||
base.OnCountRolling(currentValue, newValue);
|
||||
}
|
||||
|
||||
protected override void OnCountIncrement(ulong currentValue, ulong newValue)
|
||||
{
|
||||
ScheduledPopOutCurrentId++;
|
||||
|
||||
if (DisplayedCount < currentValue)
|
||||
DisplayedCount++;
|
||||
|
||||
DisplayedCountSpriteText.Show();
|
||||
|
||||
TransformPopOut(newValue);
|
||||
|
||||
uint newTaskId = ScheduledPopOutCurrentId;
|
||||
Scheduler.AddDelayed(delegate
|
||||
{
|
||||
ScheduledPopOutSmall(newTaskId);
|
||||
}, PopOutDuration);
|
||||
}
|
||||
|
||||
protected override void OnCountChange(ulong currentValue, ulong newValue)
|
||||
{
|
||||
ScheduledPopOutCurrentId++;
|
||||
base.OnCountChange(currentValue, newValue);
|
||||
}
|
||||
|
||||
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue)
|
||||
{
|
||||
if (newValue == 0)
|
||||
DisplayedCountSpriteText.FadeOut(PopOutDuration);
|
||||
else
|
||||
DisplayedCountSpriteText.Show();
|
||||
|
||||
if (CanPopOutWhileRolling)
|
||||
TransformPopOutRolling(newValue);
|
||||
else
|
||||
TransformNoPopOut(newValue);
|
||||
}
|
||||
|
||||
protected override void OnDisplayedCountChange(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
|
||||
|
||||
TransformNoPopOut(newValue);
|
||||
}
|
||||
|
||||
protected override void OnDisplayedCountIncrement(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.Show();
|
||||
|
||||
TransformPopOutSmall(newValue);
|
||||
}
|
||||
}
|
||||
}
|
67
osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs
Normal file
67
osu.Game/GameModes/Play/Taiko/TaikoComboCounter.cs
Normal file
@ -0,0 +1,67 @@
|
||||
//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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.GameModes.Play.Taiko
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows tint and scaling animations. Used in osu!taiko.
|
||||
/// </summary>
|
||||
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()
|
||||
{
|
||||
DisplayedCountSpriteText.Origin = Framework.Graphics.Anchor.BottomCentre;
|
||||
DisplayedCountSpriteText.Anchor = Framework.Graphics.Anchor.BottomCentre;
|
||||
}
|
||||
|
||||
protected virtual void TransformAnimate(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.Text = FormatCount(newValue);
|
||||
DisplayedCountSpriteText.ScaleTo(new Vector2(1, ScaleFactor));
|
||||
DisplayedCountSpriteText.ScaleTo(new Vector2(1, 1), AnimationDuration, AnimationEasing);
|
||||
}
|
||||
|
||||
protected virtual void TransformNotAnimate(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.Text = FormatCount(newValue);
|
||||
DisplayedCountSpriteText.ScaleTo(1);
|
||||
}
|
||||
|
||||
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue)
|
||||
{
|
||||
if (newValue == 0)
|
||||
DisplayedCountSpriteText.FadeOut(AnimationDuration);
|
||||
else
|
||||
DisplayedCountSpriteText.Show();
|
||||
|
||||
TransformNotAnimate(newValue);
|
||||
}
|
||||
|
||||
protected override void OnDisplayedCountChange(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
|
||||
|
||||
TransformNotAnimate(newValue);
|
||||
}
|
||||
|
||||
protected override void OnDisplayedCountIncrement(ulong newValue)
|
||||
{
|
||||
DisplayedCountSpriteText.Show();
|
||||
|
||||
TransformAnimate(newValue);
|
||||
}
|
||||
}
|
||||
}
|
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);
|
||||
|
||||
protected override double RollingDuration => 20;
|
||||
protected override bool IsRollingProportional => true;
|
||||
|
||||
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).DisplayedCount = CurrentValue;
|
||||
}
|
||||
|
||||
public TransformAccuracy(IClock clock)
|
||||
: base(clock)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
229
osu.Game/Graphics/UserInterface/RollingCounter.cs
Normal file
229
osu.Game/Graphics/UserInterface/RollingCounter.cs
Normal file
@ -0,0 +1,229 @@
|
||||
//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;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public abstract class RollingCounter<T> : AutoSizeContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Type of the Transform to use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be a subclass of Transform<T>
|
||||
/// </remarks>
|
||||
protected virtual Type TransformType => typeof(Transform<T>);
|
||||
|
||||
protected SpriteText DisplayedCountSpriteText;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the roll-up duration will be proportional to change in value.
|
||||
/// </summary>
|
||||
protected virtual bool IsRollingProportional => false;
|
||||
|
||||
/// <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>
|
||||
protected virtual double RollingDuration => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Easing for the counter rollover animation.
|
||||
/// </summary>
|
||||
protected virtual EasingTypes RollingEasing => EasingTypes.None;
|
||||
|
||||
private T displayedCount;
|
||||
|
||||
/// <summary>
|
||||
/// Value shown at the current moment.
|
||||
/// </summary>
|
||||
public virtual T DisplayedCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return displayedCount;
|
||||
}
|
||||
protected set
|
||||
{
|
||||
if (displayedCount.Equals(value))
|
||||
return;
|
||||
displayedCount = value;
|
||||
DisplayedCountSpriteText.Text = FormatCount(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected T prevCount;
|
||||
protected T count;
|
||||
|
||||
/// <summary>
|
||||
/// Actual value of counter.
|
||||
/// </summary>
|
||||
public virtual T Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
}
|
||||
set
|
||||
{
|
||||
prevCount = count;
|
||||
count = value;
|
||||
if (IsLoaded)
|
||||
{
|
||||
TransformCount(displayedCount, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected float textSize = 20.0f;
|
||||
|
||||
public float TextSize
|
||||
{
|
||||
get { return textSize; }
|
||||
set
|
||||
{
|
||||
textSize = value;
|
||||
DisplayedCountSpriteText.TextSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skeleton of a numeric counter which value rolls over time.
|
||||
/// </summary>
|
||||
protected RollingCounter()
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
DisplayedCountSpriteText = new SpriteText(),
|
||||
};
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
Flush(false, TransformType);
|
||||
|
||||
DisplayedCount = Count;
|
||||
|
||||
DisplayedCountSpriteText.Text = FormatCount(count);
|
||||
DisplayedCountSpriteText.Anchor = this.Anchor;
|
||||
DisplayedCountSpriteText.Origin = this.Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets count value, bypassing rollover animation.
|
||||
/// </summary>
|
||||
/// <param name="count">New count value.</param>
|
||||
public virtual void SetCountWithoutRolling(T count)
|
||||
{
|
||||
Count = count;
|
||||
StopRolling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops rollover animation, forcing the displayed count to be the actual count.
|
||||
/// </summary>
|
||||
public virtual void StopRolling()
|
||||
{
|
||||
Flush(false, TransformType);
|
||||
DisplayedCount = Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets count to default value.
|
||||
/// </summary>
|
||||
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
|
||||
/// and the new final value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To be used in conjunction with IsRollingProportional = true.
|
||||
/// Unless a derived class needs to have a proportional rolling, it is not necessary to override this function.
|
||||
/// </remarks>
|
||||
/// <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)
|
||||
{
|
||||
return RollingDuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to format counts.
|
||||
/// </summary>
|
||||
/// <param name="count">Count to format.</param>
|
||||
/// <returns>Count formatted as a string.</returns>
|
||||
protected virtual string FormatCount(T count)
|
||||
{
|
||||
return count.ToString();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
object[] parameters = { Clock };
|
||||
|
||||
Debug.Assert(
|
||||
TransformType.IsSubclassOf(typeof(Transform<T>)) || TransformType == typeof(Transform<T>),
|
||||
@"transformType should be a subclass of Transform<T>."
|
||||
);
|
||||
|
||||
TransformCount((Transform<T>)Activator.CreateInstance(TransformType, parameters), currentValue, newValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intended to be used by TransformCount(T currentValue, T newValue).
|
||||
/// </summary>
|
||||
protected void TransformCount(Transform<T> transform, T currentValue, T newValue)
|
||||
{
|
||||
Type type = transform.GetType();
|
||||
|
||||
Flush(false, type);
|
||||
|
||||
if (Clock == null)
|
||||
return;
|
||||
|
||||
if (RollingDuration < 1)
|
||||
{
|
||||
DisplayedCount = Count;
|
||||
return;
|
||||
}
|
||||
|
||||
double rollingTotalDuration =
|
||||
IsRollingProportional
|
||||
? GetProportionalDuration(currentValue, newValue)
|
||||
: RollingDuration;
|
||||
|
||||
transform.StartTime = Time;
|
||||
transform.EndTime = Time + rollingTotalDuration;
|
||||
transform.StartValue = currentValue;
|
||||
transform.EndValue = newValue;
|
||||
transform.Easing = RollingEasing;
|
||||
|
||||
Transforms.Add(transform);
|
||||
}
|
||||
}
|
||||
}
|
78
osu.Game/Graphics/UserInterface/ScoreCounter.cs
Normal file
78
osu.Game/Graphics/UserInterface/ScoreCounter.cs
Normal file
@ -0,0 +1,78 @@
|
||||
//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
|
||||
{
|
||||
public class ScoreCounter : RollingCounter<ulong>
|
||||
{
|
||||
protected override Type TransformType => typeof(TransformScore);
|
||||
|
||||
protected override double RollingDuration => 1000;
|
||||
protected override EasingTypes RollingEasing => EasingTypes.Out;
|
||||
|
||||
/// <summary>
|
||||
/// How many leading zeroes the counter has.
|
||||
/// </summary>
|
||||
public uint LeadingZeroes
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays score.
|
||||
/// </summary>
|
||||
/// <param name="leading">How many leading zeroes the counter will have.</param>
|
||||
public ScoreCounter(uint leading = 0)
|
||||
{
|
||||
DisplayedCountSpriteText.FixedWidth = true;
|
||||
LeadingZeroes = leading;
|
||||
}
|
||||
|
||||
protected override double 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).DisplayedCount = CurrentValue;
|
||||
}
|
||||
|
||||
public TransformScore(IClock clock)
|
||||
: base(clock)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
188
osu.Game/Graphics/UserInterface/StarCounter.cs
Normal file
188
osu.Game/Graphics/UserInterface/StarCounter.cs
Normal file
@ -0,0 +1,188 @@
|
||||
//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.Containers;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.MathUtils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class StarCounter : AutoSizeContainer
|
||||
{
|
||||
private readonly Container starContainer;
|
||||
private readonly List<TextAwesome> stars = new List<TextAwesome>();
|
||||
|
||||
private double transformStartTime = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum amount of stars displayed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does not limit the counter value, but the amount of stars displayed.
|
||||
/// </remarks>
|
||||
public int MaxStars
|
||||
{
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
private double animationDelay => 150;
|
||||
|
||||
private double scalingDuration => 500;
|
||||
private EasingTypes scalingEasing => EasingTypes.OutElasticHalf;
|
||||
private float minStarScale => 0.3f;
|
||||
|
||||
private double fadingDuration => 100;
|
||||
private float minStarAlpha => 0.5f;
|
||||
|
||||
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 (up to 10). Used as star difficulty display.
|
||||
/// </summary>
|
||||
public StarCounter() : this(10) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a float count as stars. Used as star difficulty display.
|
||||
/// </summary>
|
||||
/// <param name="maxstars">Maximum amount of stars to display.</param>
|
||||
public StarCounter(int maxstars)
|
||||
{
|
||||
MaxStars = Math.Max(maxstars, 0);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
starContainer = new Container
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
starContainer.Width = MaxStars * StarSize + Math.Max(MaxStars - 1, 0) * StarSpacing;
|
||||
starContainer.Height = StarSize;
|
||||
|
||||
for (int i = 0; i < MaxStars; i++)
|
||||
{
|
||||
TextAwesome star = new TextAwesome
|
||||
{
|
||||
Icon = FontAwesome.star,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.Centre,
|
||||
TextSize = StarSize,
|
||||
Scale = new Vector2(minStarScale),
|
||||
Alpha = minStarAlpha,
|
||||
Position = new Vector2((StarSize + StarSpacing) * i + (StarSize + StarSpacing) / 2, 0),
|
||||
};
|
||||
|
||||
//todo: user Container<T> once we have it.
|
||||
stars.Add(star);
|
||||
starContainer.Add(star);
|
||||
}
|
||||
|
||||
// Animate initial state from zero.
|
||||
transformCount(0, Count);
|
||||
}
|
||||
|
||||
public void ResetCount()
|
||||
{
|
||||
Count = 0;
|
||||
StopAnimation();
|
||||
}
|
||||
|
||||
public void StopAnimation()
|
||||
{
|
||||
prevCount = count;
|
||||
transformStartTime = Time;
|
||||
|
||||
for (int i = 0; i < MaxStars; i++)
|
||||
transformStarQuick(i, count);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
for (int i = 0; i < MaxStars; i++)
|
||||
{
|
||||
stars[i].ClearTransformations();
|
||||
if (currentValue <= newValue)
|
||||
stars[i].Delay(Math.Max(i - currentValue, 0) * animationDelay);
|
||||
else
|
||||
stars[i].Delay(Math.Max(currentValue - 1 - i, 0) * animationDelay);
|
||||
transformStar(i, newValue);
|
||||
stars[i].DelayReset();
|
||||
}
|
||||
transformStartTime = Time;
|
||||
}
|
||||
}
|
||||
}
|
@ -128,16 +128,26 @@
|
||||
<Compile Include="GameModes\Play\Taiko\TaikoHitRenderer.cs" />
|
||||
<Compile Include="GameModes\Play\Taiko\TaikoPlayfield.cs" />
|
||||
<Compile Include="GameModes\Edit\EditSongSelect.cs" />
|
||||
<Compile Include="GameModes\Play\ComboCounter.cs" />
|
||||
<Compile Include="GameModes\Play\ComboResultCounter.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="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\PercentageCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\ScoreCounter.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" />
|
||||
<Compile Include="Online\API\OAuth.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user