diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-26 14:37:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-26 14:37:14 +0100 |
commit | 7bb0d39da4333032d9bb9205ed8d2158692035eb (patch) | |
tree | 4994a4947dc25e9a8aaea5908c96e3c8c2685fb8 | |
parent | 6c75e814c3bc019b2f039d5ec1575de36c05d2d9 (diff) | |
parent | e28cc34db89f390106fbb745e296055bcabc237f (diff) |
Merge pull request #46327 from hilfazer/prevent_change_type_on_foreign_nodes
Prevent 'Change Type' on nodes from a foreign scene
-rw-r--r-- | editor/scene_tree_dock.cpp | 35 | ||||
-rw-r--r-- | editor/scene_tree_dock.h | 1 |
2 files changed, 35 insertions, 1 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 48c4d33184..58589467a8 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -514,6 +514,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } + if (!_validate_no_foreign()) { + break; + } + + if (!_validate_no_instance()) { + break; + } + Node *selected = scene_tree->get_selected(); if (!selected && !editor_selection->get_selected_node_list().is_empty()) { selected = editor_selection->get_selected_node_list().front()->get(); @@ -1615,6 +1623,20 @@ bool SceneTreeDock::_validate_no_foreign() { return true; } +bool SceneTreeDock::_validate_no_instance() { + List<Node *> selection = editor_selection->get_selected_node_list(); + + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + if (E->get() != edited_scene && E->get()->get_filename() != "") { + accept->set_text(TTR("This operation can't be done on instanced scenes.")); + accept->popup_centered(); + return false; + } + } + + return true; +} + void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) { Node *new_parent = scene_root->get_node(p_path); ERR_FAIL_COND(!new_parent); @@ -2581,7 +2603,18 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { if (full_selection.size() == 1) { menu->add_icon_shortcut(get_theme_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/rename"), TOOL_RENAME); } - menu->add_icon_shortcut(get_theme_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE); + + bool can_replace = true; + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + if (E->get() != edited_scene && (E->get()->get_owner() != edited_scene || E->get()->get_filename() != "")) { + can_replace = false; + break; + } + } + + if (can_replace) { + menu->add_icon_shortcut(get_theme_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE); + } if (scene_tree->get_selected() != edited_scene) { menu->add_separator(); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index 9bc281c7fb..3779b61c60 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -205,6 +205,7 @@ class SceneTreeDock : public VBoxContainer { void _new_scene_from(String p_file); bool _validate_no_foreign(); + bool _validate_no_instance(); void _selection_changed(); void _update_script_button(); |