fix: connect Background gui_input to close overlay on outside click

This commit is contained in:
2026-04-26 22:04:43 -07:00
parent 652d1e5fdc
commit 82c5aa0bfa
3 changed files with 44 additions and 25 deletions

View File

@@ -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] [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_right = 70.0
offset_bottom = 70.0 grow_vertical = 0
script = ExtResource("1") script = ExtResource("1")
[node name="BackpackIcon" type="ColorRect" parent="." unique_id=1000000002] [node name="BackpackIcon" type="ColorRect" parent="." unique_id=1000000002]
layout_mode = 0 layout_mode = 0
offset_left = 0.0
offset_top = 0.0
offset_right = 60.0 offset_right = 60.0
offset_bottom = 60.0 offset_bottom = 60.0
mouse_filter = 1
color = Color(0.4, 0.6, 0.9, 1) color = Color(0.4, 0.6, 0.9, 1)
[node name="FloatingItem" type="ColorRect" parent="." unique_id=1000000003] [node name="FloatingItem" type="ColorRect" parent="." unique_id=1000000003]
visible = false
layout_mode = 0 layout_mode = 0
offset_left = 20.0 offset_left = 20.0
offset_top = -30.0 offset_top = -30.0
offset_right = 50.0 offset_right = 50.0
offset_bottom = 0.0
color = Color(1, 0.6, 0.2, 1) color = Color(1, 0.6, 0.2, 1)
visible = false
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1000000004] [node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1000000004]

View File

@@ -176,16 +176,25 @@ func _update_hover_label() -> void:
else: else:
hover_label.text = "" 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: func _gui_input(event: InputEvent) -> void:
print("HI")
if not _is_visible: if not _is_visible:
return return
if event is InputEventMouseButton: if event is InputEventMouseButton:
print("CLOSE")
if event.button_index == 1 and event.pressed: if event.button_index == 1 and event.pressed:
_clear_selection()
hide_overlay()
close_requested.emit()
if not _is_dragging: if not _is_dragging:
hide_overlay() pass
close_requested.emit()
return
elif event.button_index == 1 and not event.pressed: elif event.button_index == 1 and not event.pressed:
if _is_dragging: if _is_dragging:
if _hovered_slot == null: if _hovered_slot == null:

View File

@@ -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"] [sub_resource type="LabelSettings" id="LabelSettings_inv"]
font_size = 20 font_size = 20
outline_size = 3 outline_size = 3
outline_color = Color(0, 0, 0, 1) 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 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1") script = ExtResource("1")
[node name="Background" type="ColorRect" parent="." unique_id=3000000002] [node name="Background" type="ColorRect" parent="." unique_id=-1294967294]
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 0
color = Color(0, 0, 0, 0.7) 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 layout_mode = 1
anchors_preset = 7 anchors_preset = 8
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
@@ -35,29 +40,32 @@ offset_bottom = 150.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 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 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.15, 0.15, 0.2, 1) 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 layout_mode = 1
anchors_preset = 0
offset_left = 10.0 offset_left = 10.0
offset_top = 10.0 offset_top = 10.0
offset_right = -10.0 offset_right = -10.0
offset_bottom = -50.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 layout_mode = 1
anchors_preset = 8 anchors_preset = 12
anchor_left = 0.0
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_bottom = -10.0 offset_bottom = -10.0
grow_horizontal = 2 grow_horizontal = 2
horizontal_alignment = 1 grow_vertical = 2
label_settings = SubResource("LabelSettings_inv") label_settings = SubResource("LabelSettings_inv")
horizontal_alignment = 1
[connection signal="gui_input" from="Background" to="." method="_on_background_gui_input"]