now changes button mapping for nintendo controllers automatically

This commit is contained in:
2022-11-27 03:07:19 +01:00
parent dbeac992bd
commit fc678778b8
3 changed files with 31 additions and 8 deletions

View File

@@ -5,21 +5,38 @@ public partial class main : Node2D
{
[Export]
public string currentController = Input.GetJoyName(0);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
//gamepad
//CHANGE INPUT FOR NINTENDO CONTROLLER
currentController = Input.GetJoyName(0);
if (currentController.StartsWith("Nintendo"))
{
InputMap.ActionAddEvent("ui_accept", new InputEventJoypadButton() { ButtonIndex = JoyButton.B});
InputMap.ActionEraseEvent("ui_accept", new InputEventJoypadButton() { ButtonIndex = JoyButton.A });
InputMap.ActionAddEvent("ui_cancel", new InputEventJoypadButton() { ButtonIndex = JoyButton.A });
InputMap.ActionEraseEvent("ui_cancel", new InputEventJoypadButton() { ButtonIndex = JoyButton.B });
}
//fullscreen
else
{
InputMap.ActionAddEvent("ui_accept", new InputEventJoypadButton() { ButtonIndex = JoyButton.A });
InputMap.ActionEraseEvent("ui_accept", new InputEventJoypadButton() { ButtonIndex = JoyButton.B });
InputMap.ActionAddEvent("ui_cancel", new InputEventJoypadButton() { ButtonIndex = JoyButton.B });
InputMap.ActionEraseEvent("ui_cancel", new InputEventJoypadButton() { ButtonIndex = JoyButton.A });
}
if (Input.IsActionJustPressed("ui_accept"))
{
GD.Print(currentController + " accept");
}
if (Input.IsActionJustPressed("ui_cancel"))
{
GD.Print(currentController + " cancel");
}
//FULLSCREEN
if (Input.IsActionJustPressed("hotkey_fullscreen"))
{
if (DisplayServer.WindowGetMode() == DisplayServer.WindowMode.Fullscreen)
@@ -32,5 +49,4 @@ public partial class main : Node2D
}
}
}
}