64 lines
1.1 KiB
C#
64 lines
1.1 KiB
C#
|
|
|
||
|
|
using Godot;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
using Rokojori.Extensions;
|
||
|
|
namespace Rokojori
|
||
|
|
{
|
||
|
|
public enum ActivationMode
|
||
|
|
{
|
||
|
|
Hold,
|
||
|
|
Toggle
|
||
|
|
}
|
||
|
|
|
||
|
|
[Tool]
|
||
|
|
[GlobalClass]
|
||
|
|
public partial class ActivationModeSensor : Sensor
|
||
|
|
{
|
||
|
|
[Export]
|
||
|
|
public Sensor button;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public ActivationMode mode = ActivationMode.Hold;
|
||
|
|
|
||
|
|
bool _toggledOn = false;
|
||
|
|
|
||
|
|
public override bool IsSensor( InputEvent ie )
|
||
|
|
{
|
||
|
|
return button != null && button.IsSensor( ie );
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Release()
|
||
|
|
{
|
||
|
|
_toggledOn = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void UpdateValue()
|
||
|
|
{
|
||
|
|
if ( button == null )
|
||
|
|
{
|
||
|
|
SetBoolValue( false );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ( mode == ActivationMode.Hold )
|
||
|
|
{
|
||
|
|
SetFloatValue( button.value );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ( button.isDown )
|
||
|
|
{
|
||
|
|
_toggledOn = ! _toggledOn;
|
||
|
|
}
|
||
|
|
|
||
|
|
SetBoolValue( _toggledOn );
|
||
|
|
}
|
||
|
|
|
||
|
|
public override List<InputIcon> GetInputIcons()
|
||
|
|
{
|
||
|
|
return button == null ? new List<InputIcon>() : button.GetInputIcons();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|