newlon/scripts/gui/FastForwardButton.cs
2025-07-20 22:11:23 +05:00

57 lines
1.2 KiB
C#

using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.GUI;
public partial class FastForwardButton : Button
{
[Export] private Texture2D firstSpeed;
[Export] private Texture2D secondSpeed;
[Export] private Texture2D thirdSpeed;
[Export] private AnimationPlayer flashAnimator;
private int speed = 1;
public override void _Ready()
{
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
}
private void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state == RuntimeLevelData.LevelStates.Game) return;
speed = 1;
Update();
}
public void OnPressed()
{
if (RuntimeLevelData.Instance.GetLevelState() != RuntimeLevelData.LevelStates.Game) return;
speed = Mathf.Wrap(speed + 1, 1, 4);
flashAnimator.Play("flash");
Update();
}
private void Update()
{
switch (speed)
{
case 1:
Icon = firstSpeed;
break;
case 2:
Icon = secondSpeed;
break;
case 3:
Icon = thirdSpeed;
break;
}
Engine.TimeScale = speed;
}
}