Godot 4.0 beta1
func _enter_tree() -> void:
# 点击关闭时不允许自动关闭
get_tree().auto_accept_quit = false
func _notification(what: int) -> void:
if what == NOTIFICATION_WM_CLOSE_REQUEST:
# 写保存数据的语句
# 退出游戏
get_tree().quit(0)