From 294abe6b6ff8039078b041fe599ea64a4e82ffc1 Mon Sep 17 00:00:00 2001 From: cmod31 Date: Fri, 24 Feb 2023 17:42:55 +0100 Subject: [PATCH] konami code --- project.godot | 5 +++++ src/scene-scripts/console/console.cs | 29 ++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/project.godot b/project.godot index 67d2ea4..42929b2 100644 --- a/project.godot +++ b/project.godot @@ -127,6 +127,11 @@ console={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194334,"key_label":0,"unicode":0,"echo":false,"script":null) ] } +cheat_start={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":6,"pressure":0.0,"pressed":true,"script":null) +] +} [internationalization] diff --git a/src/scene-scripts/console/console.cs b/src/scene-scripts/console/console.cs index b63eb41..524a94e 100644 --- a/src/scene-scripts/console/console.cs +++ b/src/scene-scripts/console/console.cs @@ -3,6 +3,9 @@ using Godot.Collections; public partial class console : PopupPanel { + private string[] gamepadCheatcode = { "ui_up", "ui_up", "ui_down", "ui_down", "ui_left", "ui_right", "ui_left", "ui_right", "ui_cancel", "ui_accept", "cheat_start" }; + private int gpCcIndexer = 0; + private InputEvent inputEvent; private static RichTextLabel textblock; private LineEdit line; private Dictionary commandDict; @@ -16,17 +19,35 @@ public partial class console : PopupPanel line = GetNode("v_box_container/line_edit"); commandDict = Json.ParseString(FileAccess.GetFileAsString("res://src/scene-scripts/console/commands.json").ToString()).AsGodotDictionary(); } + public override void _Process(double delta) { - if (Input.IsActionJustPressed("console")) + //Cheatcode + if (Input.IsActionJustPressed(gamepadCheatcode[gpCcIndexer])) { - Visible = !Visible; - player.allowMovement = !Visible; - line.GrabFocus(); + gpCcIndexer++; + GetNode("cheatcode_timer").Start(); + if (gpCcIndexer == gamepadCheatcode.Length) + { + gpCcIndexer = 0; + ToggleVisible(); + } } + if (Input.IsActionJustPressed("ui_cancel")) + + //Normal keyboard hotkey + if (Input.IsActionJustPressed("console")) + ToggleVisible(); + //OS console /*if (OS.ReadStringFromStdIn() != "") //not tested yet OnLineEditTextSubmitted(OS.ReadStringFromStdIn());*/ } + private void ToggleVisible() + { + Visible = !Visible; + player.allowMovement = !Visible; + line.GrabFocus(); + } private void OnPopupHide() { if (dialog_bubble.isTalking == false) player.allowMovement = true; } private void OnLineEditTextSubmitted(string command) {