Godot Version
Godot Engine v4.5.1.stable.official.f62fdbde1
Question
I created a dialog scene, and set it autoload. I want this dialog to show when I click the close button of right-top corner of window. I want to implement this feature by connecting the close_requested signal with a function.
But the code I wrote was not working. when I clicked the close button, the program was quit. I didn’t wrote any code to exit in the function.
This is my script:
extends Control
@onready var dialog: ConfirmationDialog = $ConfirmationDialog
func _ready() -> void:
dialog.confirmed.connect(_handle_confirm)
dialog.canceled.connect(_handle_cancel)
get_tree().root.close_requested.connect(_handle_main_window_close)
func _handle_confirm() -> void:
get_tree().quit()
func _handle_cancel() -> void:
dialog.hide()
func _handle_main_window_close() -> void:
print("handle_main_close")
func show_dialog() -> void:
dialog.show()