Split project
This commit is contained in:
46
Manual/ModuleKeyValueParameterSetter.cs
Normal file
46
Manual/ModuleKeyValueParameterSetter.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
|
||||
namespace Enigmos.Manual;
|
||||
|
||||
public partial class ModuleKeyValueParameterSetter : ModuleParameterSetter
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user