From 58650af0628afc93db9945aea9be2cad8dbc9871 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sat, 14 May 2022 18:24:43 +0800 Subject: [PATCH] Make auto_accept_quit and quit_on_go_back properties --- doc/classes/SceneTree.xml | 24 ++++++++---------------- scene/main/scene_tree.cpp | 12 ++++++++++++ scene/main/scene_tree.h | 2 ++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/doc/classes/SceneTree.xml b/doc/classes/SceneTree.xml index c78beab7e70..b04cdce6914 100644 --- a/doc/classes/SceneTree.xml +++ b/doc/classes/SceneTree.xml @@ -186,14 +186,6 @@ Returns [constant OK] on success, [constant ERR_UNCONFIGURED] if no [member current_scene] was defined yet, [constant ERR_CANT_OPEN] if [member current_scene] cannot be loaded into a [PackedScene], or [constant ERR_CANT_CREATE] if the scene cannot be instantiated. - - - - - If [code]true[/code], the application automatically accepts quitting. Enabled by default. - For mobile platforms, see [method set_quit_on_go_back]. - - @@ -219,14 +211,6 @@ Marks the most recent [InputEvent] as handled. - - - - - If [code]true[/code], the application quits automatically on going back (e.g. on Android). Enabled by default. - To handle 'Go Back' button when this option is disabled, use [constant MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST]. - - @@ -239,6 +223,10 @@ + + If [code]true[/code], the application automatically accepts quitting. + For mobile platforms, see [member quit_on_go_back]. + The current scene. @@ -269,6 +257,10 @@ Although physics interpolation would normally be globally turned on and off using [member ProjectSettings.physics/common/physics_interpolation], this property allows control over interpolation at runtime. + + If [code]true[/code], the application quits automatically on going back (e.g. on Android). + To handle 'Go Back' button when this option is disabled, use [constant MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST]. + If [code]true[/code], the [SceneTree]'s [member network_peer] refuses new incoming connections. diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 6de9cfacdb6..3f3794600d3 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -823,10 +823,18 @@ void SceneTree::_notification(int p_notification) { }; }; +bool SceneTree::is_auto_accept_quit() const { + return accept_quit; +} + void SceneTree::set_auto_accept_quit(bool p_enable) { accept_quit = p_enable; } +bool SceneTree::is_quit_on_go_back() const { + return quit_on_go_back; +} + void SceneTree::set_quit_on_go_back(bool p_enable) { quit_on_go_back = p_enable; } @@ -1937,7 +1945,9 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_root"), &SceneTree::get_root); ClassDB::bind_method(D_METHOD("has_group", "name"), &SceneTree::has_group); + ClassDB::bind_method(D_METHOD("is_auto_accept_quit"), &SceneTree::is_auto_accept_quit); ClassDB::bind_method(D_METHOD("set_auto_accept_quit", "enabled"), &SceneTree::set_auto_accept_quit); + ClassDB::bind_method(D_METHOD("is_quit_on_go_back"), &SceneTree::is_quit_on_go_back); ClassDB::bind_method(D_METHOD("set_quit_on_go_back", "enabled"), &SceneTree::set_quit_on_go_back); ClassDB::bind_method(D_METHOD("set_debug_collisions_hint", "enable"), &SceneTree::set_debug_collisions_hint); @@ -2023,6 +2033,8 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &SceneTree::set_use_font_oversampling); ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &SceneTree::is_using_font_oversampling); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_accept_quit"), "set_auto_accept_quit", "is_auto_accept_quit"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "quit_on_go_back"), "set_quit_on_go_back", "is_quit_on_go_back"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_collisions_hint"), "set_debug_collisions_hint", "is_debugging_collisions_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_navigation_hint"), "set_debug_navigation_hint", "is_debugging_navigation_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_pause", "is_paused"); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index e1f93af924e..6ec06c4ffbd 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -311,7 +311,9 @@ public: virtual void finish(); + bool is_auto_accept_quit() const; void set_auto_accept_quit(bool p_enable); + bool is_quit_on_go_back() const; void set_quit_on_go_back(bool p_enable); void quit(int p_exit_code = -1);