hurrmmm/godot/UI/TAS UI/AdvanceButton.cs

49 lines
1.0 KiB
C#

using Godot;
using System;
public partial class AdvanceButton : Button
{
TAS_System TAS;
bool isButtonPressed = false;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
TAS = GetNode<TAS_System>("/root/TAS_System");
AudioStreamPlayer buttonSound = this.GetNode<AudioStreamPlayer>("../../ButtonSound");
bool playSound = true;
this.Pressed += () => {
TAS.Advance(1);
if (playSound) buttonSound.Play();
playSound = false;
};
this.ButtonDown += () => { this.isButtonPressed = true; };
this.ButtonUp += () => { this.isButtonPressed = false; TAS.ResetSpeedup(); playSound = true; };
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (TAS.AdvancedFramesRemaining == 0)
{
this.Disabled = true;
TAS.ResetSpeedup();
this.isButtonPressed = false;
}
else
{
this.Disabled = false;
if (this.isButtonPressed)
{
TAS.AdvanceWithSpeedup(delta);
}
}
}
}