From 82c5aa0bfad5d6be49d1e0b8b0bc2237fa61b127 Mon Sep 17 00:00:00 2001 From: Bryce Date: Sun, 26 Apr 2026 22:04:43 -0700 Subject: [PATCH] fix: connect Background gui_input to close overlay on outside click --- .../inventory_backpack/InventoryBackpack.tscn | 18 +++++----- .../inventory_overlay/InventoryOverlay.gd | 17 +++++++--- .../inventory_overlay/InventoryOverlay.tscn | 34 ++++++++++++------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/inventory/inventory_backpack/InventoryBackpack.tscn b/inventory/inventory_backpack/InventoryBackpack.tscn index 2380fa8..fdfb316 100644 --- a/inventory/inventory_backpack/InventoryBackpack.tscn +++ b/inventory/inventory_backpack/InventoryBackpack.tscn @@ -1,28 +1,30 @@ -[gd_scene format=3 uid="uid://1406xmcnkygw0"] +[gd_scene format=3 uid="uid://dxkyfas46q7ef"] -[ext_resource type="Script" uid="uid://2x3g0ethsdcgo" path="res://inventory/inventory_backpack/InventoryBackpack.gd" id="1"] +[ext_resource type="Script" uid="uid://v8du0eptw65c" path="res://inventory/inventory_backpack/InventoryBackpack.gd" id="1"] [node name="InventoryBackpack" type="Control" unique_id=1000000001] -layout_mode = 0 +layout_mode = 3 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -70.0 offset_right = 70.0 -offset_bottom = 70.0 +grow_vertical = 0 script = ExtResource("1") [node name="BackpackIcon" type="ColorRect" parent="." unique_id=1000000002] layout_mode = 0 -offset_left = 0.0 -offset_top = 0.0 offset_right = 60.0 offset_bottom = 60.0 +mouse_filter = 1 color = Color(0.4, 0.6, 0.9, 1) [node name="FloatingItem" type="ColorRect" parent="." unique_id=1000000003] +visible = false layout_mode = 0 offset_left = 20.0 offset_top = -30.0 offset_right = 50.0 -offset_bottom = 0.0 color = Color(1, 0.6, 0.2, 1) -visible = false [node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1000000004] diff --git a/inventory/inventory_overlay/InventoryOverlay.gd b/inventory/inventory_overlay/InventoryOverlay.gd index 26e2e32..e160bbc 100644 --- a/inventory/inventory_overlay/InventoryOverlay.gd +++ b/inventory/inventory_overlay/InventoryOverlay.gd @@ -176,16 +176,25 @@ func _update_hover_label() -> void: else: hover_label.text = "" +func _on_background_gui_input(event: InputEvent) -> void: + if event is InputEventMouseButton and event.button_index == 1 and event.pressed: + hide_overlay() + close_requested.emit() + func _gui_input(event: InputEvent) -> void: + print("HI") if not _is_visible: return - if event is InputEventMouseButton: + if event is InputEventMouseButton: + print("CLOSE") if event.button_index == 1 and event.pressed: + + _clear_selection() + hide_overlay() + close_requested.emit() if not _is_dragging: - hide_overlay() - close_requested.emit() - return + pass elif event.button_index == 1 and not event.pressed: if _is_dragging: if _hovered_slot == null: diff --git a/inventory/inventory_overlay/InventoryOverlay.tscn b/inventory/inventory_overlay/InventoryOverlay.tscn index a2cc18b..e7ecbf3 100644 --- a/inventory/inventory_overlay/InventoryOverlay.tscn +++ b/inventory/inventory_overlay/InventoryOverlay.tscn @@ -1,29 +1,34 @@ -[gd_scene format=3 uid="uid://1p46uzngsih9o"] +[gd_scene format=3 uid="uid://djoycn4xfa8p3"] -[ext_resource type="Script" uid="uid://3mkdj9s1oe1jz" path="res://inventory/inventory_overlay/InventoryOverlay.gd" id="1"] +[ext_resource type="Script" uid="uid://bkpafveapyv8n" path="res://inventory/inventory_overlay/InventoryOverlay.gd" id="1"] [sub_resource type="LabelSettings" id="LabelSettings_inv"] font_size = 20 outline_size = 3 outline_color = Color(0, 0, 0, 1) -[node name="InventoryOverlay" type="Control" unique_id=3000000001] +[node name="InventoryOverlay" type="Control" unique_id=-1294967295] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1") -[node name="Background" type="ColorRect" parent="." unique_id=3000000002] +[node name="Background" type="ColorRect" parent="." unique_id=-1294967294] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 0 color = Color(0, 0, 0, 0.7) -[node name="InventoryPanel" type="Control" parent="." unique_id=3000000003] +[node name="InventoryPanel" type="Control" parent="." unique_id=-1294967293] layout_mode = 1 -anchors_preset = 7 +anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 @@ -35,29 +40,32 @@ offset_bottom = 150.0 grow_horizontal = 2 grow_vertical = 2 -[node name="Frame" type="ColorRect" parent="InventoryPanel" unique_id=3000000004] +[node name="Frame" type="ColorRect" parent="InventoryPanel" unique_id=-1294967292] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 color = Color(0.15, 0.15, 0.2, 1) -[node name="ItemGrid" type="GridContainer" parent="InventoryPanel" unique_id=3000000005] +[node name="ItemGrid" type="GridContainer" parent="InventoryPanel" unique_id=-1294967291] layout_mode = 1 -anchors_preset = 0 offset_left = 10.0 offset_top = 10.0 offset_right = -10.0 offset_bottom = -50.0 -[node name="HoverLabel" type="Label" parent="InventoryPanel" unique_id=3000000006] +[node name="HoverLabel" type="Label" parent="InventoryPanel" unique_id=-1294967290] layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.0 +anchors_preset = 12 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 offset_bottom = -10.0 grow_horizontal = 2 -horizontal_alignment = 1 +grow_vertical = 2 label_settings = SubResource("LabelSettings_inv") +horizontal_alignment = 1 + +[connection signal="gui_input" from="Background" to="." method="_on_background_gui_input"]