From b7710e14227d944d960a441dba3c24434c0a750b Mon Sep 17 00:00:00 2001 From: blinry Date: Wed, 18 Nov 2020 19:21:10 +0100 Subject: [PATCH] Either world or terminal has focus --- scenes/file_browser.gd | 45 +++++++++++++++++++--------------------- scenes/file_browser.tscn | 4 ++++ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 52ec381..6a660cb 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -28,29 +28,31 @@ func _ready(): _set_title(title) $PopupMenu.add_item("New file", 1) #player.file_browser = self - + func _input(event): if event.is_action_pressed("save"): if text_edit.visible: save() - var speed = 30 - if event.is_action_pressed("down", true): - player.move(Vector2(0,speed)) - if event.is_action_pressed("up", true): - player.move(Vector2(0,-speed)) - if event.is_action_pressed("right", true): - player.move(Vector2(speed, 0)) - if event.is_action_pressed("left", true): - player.move(Vector2(-speed,0)) - if event.is_action_pressed("pickup"): - if player.held: - player.held = null - else: - for item in world.get_children(): - if item != player: - if item.position.distance_to(player.position) < 50: - player.held = item - print("player picked up item " + item.label) + + if has_focus(): + var speed = 30 + if event.is_action_pressed("down", true): + player.move(Vector2(0,speed)) + if event.is_action_pressed("up", true): + player.move(Vector2(0,-speed)) + if event.is_action_pressed("right", true): + player.move(Vector2(speed, 0)) + if event.is_action_pressed("left", true): + player.move(Vector2(-speed,0)) + if event.is_action_pressed("pickup"): + if player.held: + player.held = null + else: + for item in world.get_children(): + if item != player: + if item.position.distance_to(player.position) < 50: + player.held = item + print("player picked up item " + item.label) func clear(): pass @@ -237,11 +239,6 @@ func _set_title(new_title): title = new_title if title_label: title_label.text = new_title - -func _gui_input(event): - if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_RIGHT: - $PopupMenu.set_position(get_global_mouse_position()) - $PopupMenu.popup() func very_best_sort(a,b): if a[0] == "." and b[0] != ".": diff --git a/scenes/file_browser.tscn b/scenes/file_browser.tscn index 69da164..af66858 100644 --- a/scenes/file_browser.tscn +++ b/scenes/file_browser.tscn @@ -10,6 +10,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 rect_min_size = Vector2( 0, 142 ) +focus_mode = 2 theme = ExtResource( 3 ) script = ExtResource( 1 ) __meta__ = { @@ -19,6 +20,7 @@ __meta__ = { [node name="Panel" type="Panel" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 +mouse_filter = 1 __meta__ = { "_edit_use_anchors_": false } @@ -26,6 +28,7 @@ __meta__ = { [node name="Margin" type="MarginContainer" parent="Panel"] anchor_right = 1.0 anchor_bottom = 1.0 +mouse_filter = 1 custom_constants/margin_right = 8 custom_constants/margin_top = 8 custom_constants/margin_left = 8 @@ -73,6 +76,7 @@ text = "dir" margin_top = 29.0 margin_right = 1904.0 margin_bottom = 1064.0 +mouse_filter = 1 size_flags_horizontal = 3 size_flags_vertical = 3