osu/osu.Game.Modes.Osu/UI/OsuComboCounter.cs

142 lines
4.4 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-10-14 23:23:27 +00:00
2016-11-14 09:54:24 +00:00
using osu.Game.Modes.UI;
2016-10-14 23:23:27 +00:00
using OpenTK;
2016-11-14 09:54:24 +00:00
namespace osu.Game.Modes.Osu.UI
2016-10-14 23:23:27 +00:00
{
/// <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;
2016-10-15 19:01:11 +00:00
protected virtual bool CanPopOutWhileRolling => false;
2017-02-09 13:18:08 +00:00
public new Vector2 PopOutScale = new Vector2(1.6f);
protected override void LoadComplete()
2016-10-14 23:23:27 +00:00
{
base.LoadComplete();
2016-10-14 23:23:27 +00:00
PopOutCount.Origin = Origin;
PopOutCount.Anchor = Anchor;
2016-10-14 23:23:27 +00:00
}
protected override string FormatCount(ulong count)
{
return $@"{count}x";
2016-10-14 23:23:27 +00:00
}
2016-10-16 23:30:25 +00:00
protected virtual void TransformPopOut(ulong newValue)
2016-10-14 23:23:27 +00:00
{
PopOutCount.Text = FormatCount(newValue);
2016-10-14 23:23:27 +00:00
PopOutCount.ScaleTo(PopOutScale);
PopOutCount.FadeTo(PopOutInitialAlpha);
PopOutCount.MoveTo(Vector2.Zero);
2016-10-14 23:23:27 +00:00
PopOutCount.ScaleTo(1, PopOutDuration, PopOutEasing);
PopOutCount.FadeOut(PopOutDuration, PopOutEasing);
PopOutCount.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing);
}
2016-10-14 23:23:27 +00:00
2016-10-16 23:30:25 +00:00
protected virtual void TransformPopOutRolling(ulong newValue)
{
2016-10-16 23:30:25 +00:00
TransformPopOut(newValue);
TransformPopOutSmall(newValue);
2016-10-14 23:23:27 +00:00
}
2016-10-16 23:30:25 +00:00
protected virtual void TransformNoPopOut(ulong newValue)
2016-10-14 23:23:27 +00:00
{
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(1);
2016-10-14 23:23:27 +00:00
}
2016-10-16 23:30:25 +00:00
protected virtual void TransformPopOutSmall(ulong newValue)
2016-10-14 23:23:27 +00:00
{
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(PopOutSmallScale);
DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
2016-10-14 23:23:27 +00:00
}
2016-10-16 23:30:25 +00:00
protected virtual void ScheduledPopOutSmall(uint id)
2016-10-14 23:23:27 +00:00
{
// Too late; scheduled task invalidated
if (id != ScheduledPopOutCurrentId)
return;
2016-10-16 00:07:07 +00:00
DisplayedCount++;
2016-10-14 23:23:27 +00:00
}
protected override void OnCountRolling(ulong currentValue, ulong newValue)
{
ScheduledPopOutCurrentId++;
2016-10-29 23:26:12 +00:00
// Hides displayed count if was increasing from 0 to 1 but didn't finish
if (currentValue == 0 && newValue == 0)
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
base.OnCountRolling(currentValue, newValue);
}
protected override void OnCountIncrement(ulong currentValue, ulong newValue)
{
2016-10-16 22:10:08 +00:00
ScheduledPopOutCurrentId++;
if (DisplayedCount < currentValue)
2016-10-16 00:07:07 +00:00
DisplayedCount++;
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.Show();
2016-10-16 23:30:25 +00:00
TransformPopOut(newValue);
2016-10-16 22:10:08 +00:00
uint newTaskId = ScheduledPopOutCurrentId;
Scheduler.AddDelayed(delegate
{
2016-10-16 23:30:25 +00:00
ScheduledPopOutSmall(newTaskId);
}, PopOutDuration);
}
protected override void OnCountChange(ulong currentValue, ulong newValue)
{
ScheduledPopOutCurrentId++;
2016-10-29 23:26:12 +00:00
if (newValue == 0)
DisplayedCountSpriteText.FadeOut();
base.OnCountChange(currentValue, newValue);
}
2016-10-16 00:07:07 +00:00
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue)
2016-10-14 23:23:27 +00:00
{
if (newValue == 0)
2016-10-29 23:26:12 +00:00
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
2016-10-14 23:23:27 +00:00
else
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.Show();
2016-10-14 23:23:27 +00:00
2016-10-15 19:01:11 +00:00
if (CanPopOutWhileRolling)
2016-10-16 23:30:25 +00:00
TransformPopOutRolling(newValue);
2016-10-14 23:23:27 +00:00
else
2016-10-16 23:30:25 +00:00
TransformNoPopOut(newValue);
2016-10-14 23:23:27 +00:00
}
2016-10-16 00:07:07 +00:00
protected override void OnDisplayedCountChange(ulong newValue)
2016-10-14 23:23:27 +00:00
{
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
2016-10-14 23:23:27 +00:00
2016-10-16 23:30:25 +00:00
TransformNoPopOut(newValue);
2016-10-14 23:23:27 +00:00
}
2016-10-16 00:07:07 +00:00
protected override void OnDisplayedCountIncrement(ulong newValue)
2016-10-14 23:23:27 +00:00
{
2016-10-16 00:07:07 +00:00
DisplayedCountSpriteText.Show();
2016-10-14 23:23:27 +00:00
2016-10-16 23:30:25 +00:00
TransformPopOutSmall(newValue);
2016-10-14 23:23:27 +00:00
}
}
}