diff --git a/Globals/FunkEngineNameSpace.cs b/Globals/FunkEngineNameSpace.cs index b2eb208f..9aa475ae 100644 --- a/Globals/FunkEngineNameSpace.cs +++ b/Globals/FunkEngineNameSpace.cs @@ -60,6 +60,7 @@ public enum Stages Boss, Quit, Map, + Controls, } public class MapGrid diff --git a/Globals/StageProducer.cs b/Globals/StageProducer.cs index d0403ae5..21b49376 100644 --- a/Globals/StageProducer.cs +++ b/Globals/StageProducer.cs @@ -59,6 +59,9 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1) Config = MakeConfig(nextStage, nextRoomIdx); GetTree().ChangeSceneToFile("res://scenes/BattleDirector/test_battle_scene.tscn"); break; + case Stages.Controls: + GetTree().ChangeSceneToFile("res://scenes/Remapping/Remap.tscn"); + break; case Stages.Chest: Config = MakeConfig(nextStage, nextRoomIdx); GetTree().ChangeSceneToFile("res://scenes/ChestScene/ChestScene.tscn"); diff --git a/project.godot b/project.godot index a677fd5d..a8bca8a9 100644 --- a/project.godot +++ b/project.godot @@ -10,7 +10,6 @@ config_version=5 [application] -config/name="Funk Engine" run/main_scene="res://scenes/SceneTransitions/TitleScreen.tscn" config/features=PackedStringArray("4.3", "C#", "Forward Plus") config/icon="res://scenes/BattleDirector/assets/Character1.png" @@ -32,6 +31,10 @@ window/stretch/scale_mode="integer" project/assembly_name="Funk Engine" +[game] + +input_scheme="ARROWS" + [input] arrowUp={ @@ -39,6 +42,7 @@ arrowUp={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) ] } arrowDown={ @@ -46,6 +50,7 @@ arrowDown={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) ] } arrowLeft={ @@ -53,6 +58,7 @@ arrowLeft={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null) ] } arrowRight={ @@ -60,6 +66,7 @@ arrowRight={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) ] } Pause={ diff --git a/scenes/NoteManager/scripts/InputHandler.cs b/scenes/NoteManager/scripts/InputHandler.cs index b1961d4d..7ca5a689 100644 --- a/scenes/NoteManager/scripts/InputHandler.cs +++ b/scenes/NoteManager/scripts/InputHandler.cs @@ -56,6 +56,33 @@ private void InitializeArrowCheckers() public override void _Ready() { InitializeArrowCheckers(); + LoadControlScheme(); + } + + private void LoadControlScheme() + { + string scheme = ProjectSettings.HasSetting("game/input_scheme") + ? (string)ProjectSettings.GetSetting("game/input_scheme") + : "ARROWS"; + foreach (var arrow in Arrows) + { + var events = InputMap.ActionGetEvents(arrow.Key); + foreach (var inputEvent in events) + { + InputMap.ActionEraseEvent(arrow.Key, inputEvent); + } + } + + var selectedScheme = ControlSchemes.Schemes[scheme]; + foreach (var arrow in Arrows) + { + if (selectedScheme.ContainsKey(arrow.Key)) + { + InputEventKey eventKey = new InputEventKey(); + eventKey.Keycode = (Key)Enum.Parse(typeof(Key), selectedScheme[arrow.Key]); + InputMap.ActionAddEvent(arrow.Key, eventKey); + } + } } public override void _Process(double delta) diff --git a/scenes/Remapping/ControlSchemes.cs b/scenes/Remapping/ControlSchemes.cs new file mode 100644 index 00000000..44e35bfe --- /dev/null +++ b/scenes/Remapping/ControlSchemes.cs @@ -0,0 +1,79 @@ +using System.Collections.Generic; +using Godot; + +public static class ControlSchemes +{ + public static Dictionary> Schemes = new Dictionary< + string, + Dictionary + >() + { + { + "WASD", + new Dictionary() + { + { "arrowUp", "W" }, + { "arrowDown", "S" }, + { "arrowLeft", "A" }, + { "arrowRight", "D" }, + } + }, + { + "ARROWS", + new Dictionary() + { + { "arrowUp", "Up" }, + { "arrowDown", "Down" }, + { "arrowLeft", "Left" }, + { "arrowRight", "Right" }, + } + }, + { + "QWERT", + new Dictionary() + { + { "arrowUp", "E" }, + { "arrowDown", "W" }, + { "arrowLeft", "Q" }, + { "arrowRight", "R" }, + } + }, + }; + + public static Dictionary> SpriteMappings = new Dictionary< + string, + Dictionary + >() + { + { + "WASD", + new Dictionary() + { + { "left", "res://scenes/Remapping/assets/A_Key_Light.png" }, + { "right", "res://scenes/Remapping/assets/D_Key_Light.png" }, + { "up", "res://scenes/Remapping/assets/W_Key_Light.png" }, + { "down", "res://scenes/Remapping/assets/S_Key_Light.png" }, + } + }, + { + "ARROWS", + new Dictionary() + { + { "left", "res://scenes/Remapping/assets/Arrow_Left_Key_Light.png" }, + { "right", "res://scenes/Remapping/assets/Arrow_Right_Key_Light.png" }, + { "up", "res://scenes/Remapping/assets/Arrow_Up_Key_Light.png" }, + { "down", "res://scenes/Remapping/assets/Arrow_Down_Key_Light.png" }, + } + }, + { + "QWERT", + new Dictionary() + { + { "left", "res://scenes/Remapping/assets/Q_Key_Light.png" }, + { "right", "res://scenes/Remapping/assets/R_Key_Light.png" }, + { "up", "res://scenes/Remapping/assets/E_Key_Light.png" }, + { "down", "res://scenes/Remapping/assets/W_Key_Light.png" }, + } + }, + }; +} diff --git a/scenes/Remapping/ControlSettings.cs b/scenes/Remapping/ControlSettings.cs new file mode 100644 index 00000000..764a61ab --- /dev/null +++ b/scenes/Remapping/ControlSettings.cs @@ -0,0 +1,65 @@ +using System; +using Godot; + +public partial class ControlSettings : Node2D +{ + [Export] + public Sprite2D leftKey; + + [Export] + public Sprite2D rightKey; + + [Export] + public Sprite2D upKey; + + [Export] + public Sprite2D downKey; + + public override void _Ready() + { + GetNode