mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Input remapping
This commit is contained in:
parent
1a1a191923
commit
82edd196b0
5 changed files with 104 additions and 10 deletions
|
|
@ -12,18 +12,40 @@ public partial class KeyRemappingItem : HBoxContainer
|
|||
[Export] public Label InputLabel { get; private set; }
|
||||
|
||||
private bool _active = false;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
NameLabel.Text = KeyName;
|
||||
var actions = InputMap.GetActions();
|
||||
|
||||
|
||||
var action = actions.FirstOrDefault(x => x == KeyId);
|
||||
var events = InputMap.ActionGetEvents(action);
|
||||
|
||||
InputLabel.Text = string.Join(",", events.Select(x => x.AsText()));
|
||||
|
||||
foreach (var e in events)
|
||||
{
|
||||
var button = new Button();
|
||||
|
||||
button.Text = e switch
|
||||
{
|
||||
InputEventKey key => key.PhysicalKeycode.ToString(),
|
||||
InputEventJoypadButton jButton => $"Joypad {jButton.ButtonIndex}",
|
||||
InputEventMouseButton mouseButton => $"Mouse {mouseButton.ButtonIndex}",
|
||||
_ => e.AsText()
|
||||
};
|
||||
button.Pressed += () => { BeginRemap(button, action, e); };
|
||||
this.AddChild(button);
|
||||
}
|
||||
|
||||
|
||||
//InputLabel.Text = string.Join(",", events.Select(x => x.AsText()));
|
||||
}
|
||||
|
||||
|
||||
private void BeginRemap(Button button, StringName action, InputEvent e)
|
||||
{
|
||||
button.Text = "Remapping...";
|
||||
_active = true;
|
||||
}
|
||||
|
||||
public void StartRemap()
|
||||
{
|
||||
_active = true;
|
||||
|
|
@ -32,11 +54,12 @@ public partial class KeyRemappingItem : HBoxContainer
|
|||
public override void _Input(InputEvent e)
|
||||
{
|
||||
if (!_active) return;
|
||||
|
||||
|
||||
if (e is InputEventKey keyEvent && keyEvent.Pressed)
|
||||
{
|
||||
GD.Print(keyEvent.Keycode);
|
||||
InputLabel.Text = keyEvent.Keycode.ToString();
|
||||
//InputLabel.Text = keyEvent.Keycode.ToString();
|
||||
|
||||
_active = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue