konami code

This commit is contained in:
2023-02-24 17:42:55 +01:00
parent 8132530da3
commit 294abe6b6f
2 changed files with 30 additions and 4 deletions

View File

@@ -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]

View File

@@ -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<LineEdit>("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<Timer>("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)
{