From 61325b7a9732574baffa823643328647db17eb87 Mon Sep 17 00:00:00 2001 From: blinry Date: Wed, 18 Nov 2020 20:12:15 +0100 Subject: [PATCH] Restrict movement to arrow keys, switch to terminal by typing letters --- project.godot | 12 ++++++------ scenes/file_browser.gd | 5 ++++- scenes/main.gd | 9 +++++++++ scenes/terminal.gd | 6 ++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/project.godot b/project.godot index 35676e9..409d497 100644 --- a/project.godot +++ b/project.godot @@ -79,25 +79,21 @@ window/stretch/aspect="keep" left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) ] } right={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) ] } up={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) ] } down={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) ] } click={ @@ -142,8 +138,12 @@ clear={ } pickup={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) + ] +} +tab={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"unicode":0,"echo":false,"script":null) ] } diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index ebaabaf..462c737 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -34,7 +34,7 @@ func _input(event): if text_edit.visible: save() if has_focus(): - if Input.is_action_pressed("pickup"): + if event.is_action_pressed("pickup"): if player.held: player.held = null else: @@ -43,6 +43,9 @@ func _input(event): if item.position.distance_to(player.position) < 150: player.held = item + if event.is_action_pressed("up") or event.is_action_pressed("down") or event.is_action_pressed("left") or event.is_action_pressed("right"): + get_tree().set_input_as_handled() + func clear(): pass for item in world.get_children(): diff --git a/scenes/main.gd b/scenes/main.gd index 50bd067..f18f441 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -45,6 +45,14 @@ func _ready(): # Load first chapter. load_chapter(current_chapter) input.grab_focus() + +func _input(event): + if event.is_action_pressed("tab"): + print("ha") + if file_browser.has_focus(): + terminal.grab_focus() + else: + file_browser.grab_focus() func load_chapter(id): current_chapter = id @@ -144,6 +152,7 @@ func update_repos(): repo.update_everything() file_browser.update() #index.update() + file_browser.grab_focus() if levels.chapters[current_chapter].levels[current_level].check_win(): show_win_status() diff --git a/scenes/terminal.gd b/scenes/terminal.gd index 76aa7a3..981c7d2 100644 --- a/scenes/terminal.gd +++ b/scenes/terminal.gd @@ -32,6 +32,12 @@ func _ready(): history_position = game.state["history"].size() func _input(event): + if not $TextEditor.visible: + if event is InputEventKey: + var u = event.unicode + if u >= 97 && u <= 122: + input.grab_focus() + if not input.has_focus(): return