From fc678778b8cfb17ad31af8b1801fdaff07e5d3cc Mon Sep 17 00:00:00 2001 From: vaporvee Date: Sun, 27 Nov 2022 03:07:19 +0100 Subject: [PATCH] now changes button mapping for nintendo controllers automatically --- RPG Test gd4.csproj | 2 +- RPG Test gd4.csproj.old | 7 +++++++ src/main.cs | 30 +++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 RPG Test gd4.csproj.old diff --git a/RPG Test gd4.csproj b/RPG Test gd4.csproj index 870b6b9..6247938 100644 --- a/RPG Test gd4.csproj +++ b/RPG Test gd4.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/RPG Test gd4.csproj.old b/RPG Test gd4.csproj.old new file mode 100644 index 0000000..870b6b9 --- /dev/null +++ b/RPG Test gd4.csproj.old @@ -0,0 +1,7 @@ + + + net6.0 + true + RPGTestgd4 + + \ No newline at end of file diff --git a/src/main.cs b/src/main.cs index 48c3655..06d555f 100644 --- a/src/main.cs +++ b/src/main.cs @@ -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 } } } - }