47 lines
1.0 KiB
C#
47 lines
1.0 KiB
C#
using Godot;
|
|
using Nocturnis;
|
|
using Nocturnis.DataStructures.ConfigurableParameters;
|
|
|
|
namespace Enigmos.Manual;
|
|
|
|
public partial class ModuleKeyValueParameterSetter : ModuleParameterSetter, ISceneConcept
|
|
{
|
|
public new IKeyParameter UnderlyingParameter
|
|
{
|
|
get => (base.UnderlyingParameter as IKeyParameter)!;
|
|
set => base.UnderlyingParameter = value;
|
|
}
|
|
|
|
private Button Binding { get; set; }
|
|
private bool ReadyToBind { get; set; }
|
|
|
|
public void Init(IKeyParameter parameter)
|
|
{
|
|
UnderlyingParameter = parameter;
|
|
ReadyToBind = false;
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
Binding = GetNode<Button>("Binding");
|
|
}
|
|
|
|
private void StartBind()
|
|
{
|
|
Binding.Text = "Press a Key";
|
|
InputMap.ActionEraseEvents(UnderlyingParameter.ParameterValue);
|
|
ReadyToBind = true;
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (ReadyToBind && @event is InputEventKey keyEvent)
|
|
{
|
|
InputMap.ActionAddEvent(UnderlyingParameter.ParameterValue, keyEvent);
|
|
Binding.Text = keyEvent.AsTextKeyLabel();
|
|
ReadyToBind = false;
|
|
}
|
|
|
|
base._Input(@event);
|
|
}
|
|
} |