1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:57:29 +08:00
osu-lazer/osu.Game.Modes.Osu/UI/OsuComboCounter.cs

143 lines
4.5 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-15 07:23:27 +08:00
2016-11-14 17:54:24 +08:00
using osu.Game.Modes.UI;
2016-10-15 07:23:27 +08:00
using OpenTK;
using osu.Framework.Graphics.Primitives;
2016-10-15 07:23:27 +08:00
2016-11-14 17:54:24 +08:00
namespace osu.Game.Modes.Osu.UI
2016-10-15 07:23:27 +08: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-16 03:01:11 +08:00
protected virtual bool CanPopOutWhileRolling => false;
2017-02-09 21:18:08 +08:00
public new Vector2 PopOutScale = new Vector2(1.6f);
protected override void LoadComplete()
2016-10-15 07:23:27 +08:00
{
base.LoadComplete();
2016-10-15 07:23:27 +08:00
PopOutCount.Origin = Origin;
PopOutCount.Anchor = Anchor;
2016-10-15 07:23:27 +08:00
}
protected override string FormatCount(ulong count)
{
return $@"{count}x";
2016-10-15 07:23:27 +08:00
}
2016-10-17 07:30:25 +08:00
protected virtual void TransformPopOut(ulong newValue)
2016-10-15 07:23:27 +08:00
{
PopOutCount.Text = FormatCount(newValue);
2016-10-15 07:23:27 +08:00
PopOutCount.ScaleTo(PopOutScale);
PopOutCount.FadeTo(PopOutInitialAlpha);
PopOutCount.MoveTo(Vector2.Zero);
2016-10-15 07:23:27 +08:00
PopOutCount.ScaleTo(1, PopOutDuration, PopOutEasing);
PopOutCount.FadeOut(PopOutDuration, PopOutEasing);
PopOutCount.MoveTo(DisplayedCountSpriteText.Position, PopOutDuration, PopOutEasing);
}
2016-10-15 07:23:27 +08:00
2016-10-17 07:30:25 +08:00
protected virtual void TransformPopOutRolling(ulong newValue)
{
2016-10-17 07:30:25 +08:00
TransformPopOut(newValue);
TransformPopOutSmall(newValue);
2016-10-15 07:23:27 +08:00
}
2016-10-17 07:30:25 +08:00
protected virtual void TransformNoPopOut(ulong newValue)
2016-10-15 07:23:27 +08:00
{
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(1);
2016-10-15 07:23:27 +08:00
}
2016-10-17 07:30:25 +08:00
protected virtual void TransformPopOutSmall(ulong newValue)
2016-10-15 07:23:27 +08:00
{
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.Text = FormatCount(newValue);
DisplayedCountSpriteText.ScaleTo(PopOutSmallScale);
DisplayedCountSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
2016-10-15 07:23:27 +08:00
}
2016-10-17 07:30:25 +08:00
protected virtual void ScheduledPopOutSmall(uint id)
2016-10-15 07:23:27 +08:00
{
// Too late; scheduled task invalidated
if (id != ScheduledPopOutCurrentId)
return;
2016-10-16 08:07:07 +08:00
DisplayedCount++;
2016-10-15 07:23:27 +08:00
}
protected override void OnCountRolling(ulong currentValue, ulong newValue)
{
ScheduledPopOutCurrentId++;
2016-10-30 07:26:12 +08: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-17 06:10:08 +08:00
ScheduledPopOutCurrentId++;
if (DisplayedCount < currentValue)
2016-10-16 08:07:07 +08:00
DisplayedCount++;
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.Show();
2016-10-17 07:30:25 +08:00
TransformPopOut(newValue);
2016-10-17 06:10:08 +08:00
uint newTaskId = ScheduledPopOutCurrentId;
Scheduler.AddDelayed(delegate
{
2016-10-17 07:30:25 +08:00
ScheduledPopOutSmall(newTaskId);
}, PopOutDuration);
}
protected override void OnCountChange(ulong currentValue, ulong newValue)
{
ScheduledPopOutCurrentId++;
2016-10-30 07:26:12 +08:00
if (newValue == 0)
DisplayedCountSpriteText.FadeOut();
base.OnCountChange(currentValue, newValue);
}
2016-10-16 08:07:07 +08:00
protected override void OnDisplayedCountRolling(ulong currentValue, ulong newValue)
2016-10-15 07:23:27 +08:00
{
if (newValue == 0)
2016-10-30 07:26:12 +08:00
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
2016-10-15 07:23:27 +08:00
else
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.Show();
2016-10-15 07:23:27 +08:00
2016-10-16 03:01:11 +08:00
if (CanPopOutWhileRolling)
2016-10-17 07:30:25 +08:00
TransformPopOutRolling(newValue);
2016-10-15 07:23:27 +08:00
else
2016-10-17 07:30:25 +08:00
TransformNoPopOut(newValue);
2016-10-15 07:23:27 +08:00
}
2016-10-16 08:07:07 +08:00
protected override void OnDisplayedCountChange(ulong newValue)
2016-10-15 07:23:27 +08:00
{
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
2016-10-15 07:23:27 +08:00
2016-10-17 07:30:25 +08:00
TransformNoPopOut(newValue);
2016-10-15 07:23:27 +08:00
}
2016-10-16 08:07:07 +08:00
protected override void OnDisplayedCountIncrement(ulong newValue)
2016-10-15 07:23:27 +08:00
{
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.Show();
2016-10-15 07:23:27 +08:00
2016-10-17 07:30:25 +08:00
TransformPopOutSmall(newValue);
2016-10-15 07:23:27 +08:00
}
}
}