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:
@@ -35,6 +35,7 @@ var editor_error_label: Label
|
|||||||
|
|
||||||
var export_menu: PanelContainer
|
var export_menu: PanelContainer
|
||||||
var import_menu: PanelContainer
|
var import_menu: PanelContainer
|
||||||
|
var dropdown_backdrop: Control
|
||||||
|
|
||||||
var import_overlay: Control
|
var import_overlay: Control
|
||||||
var import_panel: PanelContainer
|
var import_panel: PanelContainer
|
||||||
@@ -53,6 +54,7 @@ func _ready() -> void:
|
|||||||
size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
size_flags_vertical = Control.SIZE_EXPAND_FILL
|
size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||||
add_theme_constant_override("separation", 14)
|
add_theme_constant_override("separation", 14)
|
||||||
|
_build_dropdown_backdrop()
|
||||||
_build_toolbar()
|
_build_toolbar()
|
||||||
_build_filters()
|
_build_filters()
|
||||||
status_label = Label.new()
|
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:
|
func _build_dropdown(items: Array) -> PanelContainer:
|
||||||
var menu := PanelContainer.new()
|
var menu := PanelContainer.new()
|
||||||
menu.visible = false
|
menu.visible = false
|
||||||
@@ -165,20 +179,37 @@ func _build_dropdown(items: Array) -> PanelContainer:
|
|||||||
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||||
var action: Callable = item[1]
|
var action: Callable = item[1]
|
||||||
button.pressed.connect(func():
|
button.pressed.connect(func():
|
||||||
menu.visible = false
|
_close_dropdowns()
|
||||||
action.call())
|
action.call())
|
||||||
list.add_child(button)
|
list.add_child(button)
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
|
|
||||||
func _toggle_dropdown(menu: PanelContainer, anchor: Control) -> void:
|
func _toggle_dropdown(menu: PanelContainer, anchor: Control) -> void:
|
||||||
if menu.visible:
|
var was_visible := menu.visible
|
||||||
menu.visible = false
|
_close_dropdowns()
|
||||||
|
if was_visible:
|
||||||
return
|
return
|
||||||
menu.visible = true
|
menu.visible = true
|
||||||
|
dropdown_backdrop.visible = true
|
||||||
menu.position = anchor.get_global_position() + Vector2(0, anchor.size.y + 4)
|
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:
|
func _build_filters() -> void:
|
||||||
var row := HFlowContainer.new()
|
var row := HFlowContainer.new()
|
||||||
row.add_theme_constant_override("separation", 10)
|
row.add_theme_constant_override("separation", 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user