Fix Import/Export dropdowns not dismissing

They only closed via their own trigger button or a menu item -
clicking outside, pressing Escape, or opening the other dropdown
while one was open left it stuck on screen (confirmed opening both
stacked on top of each other). Add a shared invisible backdrop
(mirroring main.gd's drawer-backdrop pattern) that closes whichever
dropdown is open on outside click or Escape, and have opening one
close the other first.
This commit is contained in:
hz
2026-07-21 17:37:51 -05:00
parent 15e9f9779e
commit b00b321d6f
+34 -3
View File
@@ -35,6 +35,7 @@ var editor_error_label: Label
var export_menu: PanelContainer
var import_menu: PanelContainer
var dropdown_backdrop: Control
var import_overlay: Control
var import_panel: PanelContainer
@@ -53,6 +54,7 @@ func _ready() -> void:
size_flags_horizontal = Control.SIZE_EXPAND_FILL
size_flags_vertical = Control.SIZE_EXPAND_FILL
add_theme_constant_override("separation", 14)
_build_dropdown_backdrop()
_build_toolbar()
_build_filters()
status_label = Label.new()
@@ -149,6 +151,18 @@ func _build_toolbar() -> void:
])
func _build_dropdown_backdrop() -> void:
dropdown_backdrop = Control.new()
dropdown_backdrop.visible = false
dropdown_backdrop.top_level = true
dropdown_backdrop.mouse_filter = Control.MOUSE_FILTER_STOP
dropdown_backdrop.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
dropdown_backdrop.gui_input.connect(func(event: InputEvent):
if event is InputEventMouseButton and event.pressed:
_close_dropdowns())
add_child(dropdown_backdrop)
func _build_dropdown(items: Array) -> PanelContainer:
var menu := PanelContainer.new()
menu.visible = false
@@ -165,20 +179,37 @@ func _build_dropdown(items: Array) -> PanelContainer:
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
var action: Callable = item[1]
button.pressed.connect(func():
menu.visible = false
_close_dropdowns()
action.call())
list.add_child(button)
return menu
func _toggle_dropdown(menu: PanelContainer, anchor: Control) -> void:
if menu.visible:
menu.visible = false
var was_visible := menu.visible
_close_dropdowns()
if was_visible:
return
menu.visible = true
dropdown_backdrop.visible = true
menu.position = anchor.get_global_position() + Vector2(0, anchor.size.y + 4)
func _close_dropdowns() -> void:
if export_menu != null:
export_menu.visible = false
if import_menu != null:
import_menu.visible = false
if dropdown_backdrop != null:
dropdown_backdrop.visible = false
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and dropdown_backdrop != null and dropdown_backdrop.visible:
_close_dropdowns()
get_viewport().set_input_as_handled()
func _build_filters() -> void:
var row := HFlowContainer.new()
row.add_theme_constant_override("separation", 10)