1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 20:33:37 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/StandardComboCounter.cs

111 lines
3.7 KiB
C#
Raw Normal View History

2016-10-07 15:24:46 +08:00
//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;
2016-10-07 15:24:46 +08:00
using osu.Framework.Graphics.Sprites;
2016-10-07 15:05:02 +08:00
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>
2016-10-08 05:14:35 +08:00
/// Uses the 'x' symbol and has a pop-out effect while rolling over. Used in osu! standard.
2016-10-07 15:05:02 +08:00
/// </summary>
public class StandardComboCounter : ULongCounter
{
public SpriteText popOutSpriteText;
public ulong PopOutDuration = 0;
public float PopOutBigScale = 2.0f;
public float PopOutSmallScale = 1.2f;
public EasingTypes PopOutEasing = EasingTypes.None;
public bool CanPopOutWhenBackwards = false;
2016-10-10 04:19:35 +08:00
public float PopOutInitialAlpha = 0.75f;
2016-10-07 15:05:02 +08:00
public StandardComboCounter() : base()
2016-10-07 15:05:02 +08:00
{
IsRollingContinuous = false;
}
public override void Load(BaseGame game)
2016-10-07 15:05:02 +08:00
{
base.Load(game);
2016-10-07 15:05:02 +08:00
countSpriteText.Alpha = 0;
Add(popOutSpriteText = new SpriteText
{
Text = formatCount(Count),
Origin = this.Origin,
Anchor = this.Anchor,
TextSize = this.TextSize,
Alpha = 0,
});
}
protected override void updateTextSize()
{
base.updateTextSize();
if (popOutSpriteText != null)
popOutSpriteText.TextSize = this.TextSize;
}
protected override void transformCount(ulong currentValue, ulong newValue)
{
// Animate rollover only when going backwards
if (newValue > currentValue)
{
updateTransforms(typeof(TransformULongCounter));
removeTransforms(typeof(TransformULongCounter));
2016-10-07 15:05:02 +08:00
VisibleCount = newValue;
}
else
transformCount(new TransformULongCounter(Clock), currentValue, newValue);
2016-10-07 15:05:02 +08:00
}
protected override ulong getProportionalDuration(ulong currentValue, ulong newValue)
2016-10-07 15:05:02 +08:00
{
ulong 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()
{
countSpriteText.ScaleTo(PopOutSmallScale);
countSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
popOutSpriteText.ScaleTo(PopOutBigScale);
popOutSpriteText.FadeTo(PopOutInitialAlpha);
popOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
popOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
}
protected override void transformVisibleCount(ulong currentValue, ulong newValue)
{
if (countSpriteText != null && popOutSpriteText != null)
{
countSpriteText.Text = popOutSpriteText.Text = formatCount(newValue);
if (newValue == 0)
{
countSpriteText.FadeOut(PopOutDuration);
}
else
{
countSpriteText.Show();
if (newValue > currentValue || CanPopOutWhenBackwards)
transformPopOut();
}
}
}
}
}