From 89c009b10558d42bc67773f08f3fda00fbcce2e2 Mon Sep 17 00:00:00 2001 From: Giganzo <158825920+Giganzo@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:43:37 +0200 Subject: [PATCH] Add ConfirmationDialog when clicking on % button in SceneTree --- editor/gui/scene_tree_editor.cpp | 49 ++++++++++++++++++++++++++++---- editor/gui/scene_tree_editor.h | 9 ++++++ editor/scene_tree_dock.cpp | 1 + 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index a3e62c298f7..2a2a7a2e757 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -174,15 +174,40 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i EditorDockManager::get_singleton()->focus_dock(NodeDock::get_singleton()); NodeDock::get_singleton()->show_groups(); } else if (p_id == BUTTON_UNIQUE) { - undo_redo->create_action(TTR("Disable Scene Unique Name")); - undo_redo->add_do_method(n, "set_unique_name_in_owner", false); - undo_redo->add_undo_method(n, "set_unique_name_in_owner", true); - undo_redo->add_do_method(this, "_update_tree"); - undo_redo->add_undo_method(this, "_update_tree"); - undo_redo->commit_action(); + bool ask_before_revoking_unique_name = EDITOR_GET("docks/scene_tree/ask_before_revoking_unique_name"); + revoke_node = n; + if (ask_before_revoking_unique_name) { + String msg = vformat(TTR("Revoke unique name for node \"%s\"?"), n->get_name()); + ask_before_revoke_checkbox->set_pressed(false); + revoke_dialog_label->set_text(msg); + revoke_dialog->reset_size(); + revoke_dialog->popup_centered(); + } else { + _revoke_unique_name(); + } } } +void SceneTreeEditor::_update_ask_before_revoking_unique_name() { + if (ask_before_revoke_checkbox->is_pressed()) { + EditorSettings::get_singleton()->set("docks/scene_tree/ask_before_revoking_unique_name", false); + ask_before_revoke_checkbox->set_pressed(false); + } + + _revoke_unique_name(); +} + +void SceneTreeEditor::_revoke_unique_name() { + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + + undo_redo->create_action(TTR("Disable Scene Unique Name")); + undo_redo->add_do_method(revoke_node, "set_unique_name_in_owner", false); + undo_redo->add_undo_method(revoke_node, "set_unique_name_in_owner", true); + undo_redo->add_do_method(this, "_update_tree"); + undo_redo->add_undo_method(this, "_update_tree"); + undo_redo->commit_action(); +} + void SceneTreeEditor::_toggle_visible(Node *p_node) { if (p_node->has_method("is_visible") && p_node->has_method("set_visible")) { bool v = bool(p_node->call("is_visible")); @@ -1602,6 +1627,18 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope update_node_tooltip_delay->set_one_shot(true); add_child(update_node_tooltip_delay); + revoke_dialog = memnew(ConfirmationDialog); + revoke_dialog->set_ok_button_text(TTR("Revoke")); + add_child(revoke_dialog); + revoke_dialog->connect(SceneStringName(confirmed), callable_mp(this, &SceneTreeEditor::_update_ask_before_revoking_unique_name)); + VBoxContainer *vb = memnew(VBoxContainer); + revoke_dialog->add_child(vb); + revoke_dialog_label = memnew(Label); + vb->add_child(revoke_dialog_label); + ask_before_revoke_checkbox = memnew(CheckBox(TTR("Don't Ask Again"))); + ask_before_revoke_checkbox->set_tooltip_text(TTR("This dialog can also be enabled/disabled in the Editor Settings: Docks > Scene Tree > Ask Before Revoking Unique Name.")); + vb->add_child(ask_before_revoke_checkbox); + script_types = memnew(List); ClassDB::get_inheriters_from_class("Script", script_types); } diff --git a/editor/gui/scene_tree_editor.h b/editor/gui/scene_tree_editor.h index b4d9644f167..9633993b8b8 100644 --- a/editor/gui/scene_tree_editor.h +++ b/editor/gui/scene_tree_editor.h @@ -31,6 +31,7 @@ #ifndef SCENE_TREE_EDITOR_H #define SCENE_TREE_EDITOR_H +#include "scene/gui/check_box.h" #include "scene/gui/check_button.h" #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" @@ -68,6 +69,11 @@ class SceneTreeEditor : public Control { AcceptDialog *error = nullptr; AcceptDialog *warning = nullptr; + ConfirmationDialog *revoke_dialog = nullptr; + Label *revoke_dialog_label = nullptr; + CheckBox *ask_before_revoke_checkbox = nullptr; + Node *revoke_node = nullptr; + bool auto_expand_selected = true; bool connect_to_script_mode = false; bool connecting_signal = false; @@ -144,6 +150,9 @@ class SceneTreeEditor : public Control { Vector valid_types; + void _update_ask_before_revoking_unique_name(); + void _revoke_unique_name(); + public: // Public for use with callable_mp. void _update_tree(bool p_scroll_to_selected = false); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 56924fc1fe7..f7870f579f3 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -4619,6 +4619,7 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec EDITOR_DEF("interface/editors/show_scene_tree_root_selection", true); EDITOR_DEF("interface/editors/derive_script_globals_by_name", true); EDITOR_DEF("docks/scene_tree/ask_before_deleting_related_animation_tracks", true); + EDITOR_DEF("docks/scene_tree/ask_before_revoking_unique_name", true); EDITOR_DEF("_use_favorites_root_selection", false); Resource::_update_configuration_warning = _update_configuration_warning;