1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 19:18:03 +08:00
osu-lazer/osu.Game/GameModes/Play/Osu/OsuComboCounter.cs

159 lines
4.9 KiB
C#
Raw Normal View History

2016-10-15 07:23:27 +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 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;
2016-10-16 03:01:11 +08:00
protected virtual bool CanPopOutWhileRolling => false;
2016-10-15 07:23:27 +08:00
public Vector2 InnerCountPosition
{
get
{
2016-10-16 08:07:07 +08:00
return DisplayedCountSpriteText.Position;
2016-10-15 07:23:27 +08:00
}
set
{
2016-10-16 08:07:07 +08:00
DisplayedCountSpriteText.Position = value;
2016-10-15 07:23:27 +08:00
}
}
2016-11-01 22:24:14 +08:00
protected override void Load(BaseGame game)
2016-10-15 07:23:27 +08:00
{
base.Load(game);
PopOutSpriteText.Origin = this.Origin;
PopOutSpriteText.Anchor = this.Anchor;
Add(PopOutSpriteText);
}
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
{
PopOutSpriteText.Text = FormatCount(newValue);
PopOutSpriteText.ScaleTo(PopOutScale);
PopOutSpriteText.FadeTo(PopOutInitialAlpha);
PopOutSpriteText.MoveTo(Vector2.Zero);
PopOutSpriteText.ScaleTo(1, PopOutDuration, PopOutEasing);
PopOutSpriteText.FadeOut(PopOutDuration, PopOutEasing);
2016-10-16 08:07:07 +08:00
PopOutSpriteText.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
}
}
}