summaryrefslogtreecommitdiff
path: root/editor/scene_tree_dock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r--editor/scene_tree_dock.cpp99
1 files changed, 65 insertions, 34 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 16f1575757..df6b23c167 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -250,22 +250,37 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base)
return;
}
+ UndoRedo *undo_redo = editor->get_undo_redo();
+ undo_redo->create_action(TTR("Replace with Branch Scene"));
+
Node *parent = base->get_parent();
int pos = base->get_index();
- parent->remove_child(base);
- parent->add_child(instanced_scene);
- parent->move_child(instanced_scene, pos);
- instanced_scene->set_owner(edited_scene);
- editor_selection->clear();
- editor_selection->add_node(instanced_scene);
- scene_tree->set_selected(instanced_scene);
-
- // Delete the node as late as possible because before another one is selected
- // an editor plugin could be referencing it to do something with it before
- // switching to another (or to none); and since some steps of changing the
- // editor state are deferred, the safest thing is to do this is as the last
- // step of this function and also by enqueing instead of memdelete()-ing it here
- base->queue_delete();
+ undo_redo->add_do_method(parent, "remove_child", base);
+ undo_redo->add_undo_method(parent, "remove_child", instanced_scene);
+ undo_redo->add_do_method(parent, "add_child", instanced_scene);
+ undo_redo->add_undo_method(parent, "add_child", base);
+ undo_redo->add_do_method(parent, "move_child", instanced_scene, pos);
+ undo_redo->add_undo_method(parent, "move_child", base, pos);
+
+ List<Node *> owned;
+ base->get_owned_by(base->get_owner(), &owned);
+ Array owners;
+ for (List<Node *>::Element *F = owned.front(); F; F = F->next()) {
+ owners.push_back(F->get());
+ }
+ undo_redo->add_do_method(instanced_scene, "set_owner", edited_scene);
+ undo_redo->add_undo_method(this, "_set_owners", edited_scene, owners);
+
+ undo_redo->add_do_method(editor_selection, "clear");
+ undo_redo->add_undo_method(editor_selection, "clear");
+ undo_redo->add_do_method(editor_selection, "add_node", instanced_scene);
+ undo_redo->add_undo_method(editor_selection, "add_node", base);
+ undo_redo->add_do_property(scene_tree, "set_selected", instanced_scene);
+ undo_redo->add_undo_property(scene_tree, "set_selected", base);
+
+ undo_redo->add_do_reference(instanced_scene);
+ undo_redo->add_undo_reference(base);
+ undo_redo->commit_action();
}
bool SceneTreeDock::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) {
@@ -759,8 +774,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
_delete_confirm();
} else {
- if (remove_list.size() > 1) {
+ if (remove_list.size() >= 2) {
delete_dialog->set_text(vformat(TTR("Delete %d nodes?"), remove_list.size()));
+ } else if (remove_list.size() == 1 && remove_list[0] == editor_data->get_edited_scene_root()) {
+ delete_dialog->set_text(vformat(TTR("Delete the root node \"%s\"?"), remove_list[0]->get_name()));
+ } else if (remove_list.size() == 1 && remove_list[0]->get_filename() == "" && remove_list[0]->get_child_count() >= 1) {
+ // Display this message only for non-instanced scenes
+ delete_dialog->set_text(vformat(TTR("Delete node \"%s\" and its children?"), remove_list[0]->get_name()));
} else {
delete_dialog->set_text(vformat(TTR("Delete node \"%s\"?"), remove_list[0]->get_name()));
}
@@ -1504,7 +1524,7 @@ bool SceneTreeDock::_validate_no_foreign() {
// When edited_scene inherits from another one the root Node will be the parent Scene,
// we don't want to consider that Node a foreign one otherwise we would not be able to
- // delete it
+ // delete it.
if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene == E->get()) {
continue;
}
@@ -1528,7 +1548,7 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
List<Node *> selection = editor_selection->get_selected_node_list();
if (selection.empty())
- return; //nothing to reparent
+ return; // Nothing to reparent.
Vector<Node *> nodes;
@@ -1544,18 +1564,32 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
Node *new_parent = p_new_parent;
ERR_FAIL_COND(!new_parent);
+ if (p_nodes.size() == 0)
+ return; // Nothing to reparent.
+
+ p_nodes.sort_custom<Node::Comparator>(); //Makes result reliable.
+
+ bool no_change = true;
+ for (int ni = 0; ni < p_nodes.size(); ni++) {
+
+ if (p_nodes[ni] == p_new_parent)
+ return; // Attempt to reparent to itself.
+
+ if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_position_in_parent())
+ no_change = false;
+ }
+
+ if (no_change)
+ return; // Position and parent didn't change.
+
Node *validate = new_parent;
while (validate) {
- ERR_FAIL_COND_MSG(p_nodes.find(validate) != -1, "Selection changed at some point.. can't reparent.");
+ ERR_FAIL_COND_MSG(p_nodes.find(validate) != -1, "Selection changed at some point. Can't reparent.");
validate = validate->get_parent();
}
- //ok all valid
- if (p_nodes.size() == 0)
- return; //nothing to reparent
-
- //sort by tree order, so re-adding is easy
+ // Sort by tree order, so re-adding is easy.
p_nodes.sort_custom<Node::Comparator>();
editor_data->get_undo_redo().create_action(TTR("Reparent Node"));
@@ -1567,7 +1601,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
for (int ni = 0; ni < p_nodes.size(); ni++) {
- //no undo for now, sorry
+ // No undo implemented for this yet.
Node *node = p_nodes[ni];
fill_path_renames(node, new_parent, &path_renames);
@@ -1577,14 +1611,11 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
node->get_owned_by(node->get_owner(), &owned);
Array owners;
for (List<Node *>::Element *E = owned.front(); E; E = E->next()) {
-
owners.push_back(E->get());
}
- if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) {
- //if child will generate a gap when moved, adjust
- inc--;
- }
+ if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni)
+ inc--; // If the child will generate a gap when moved, adjust.
editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node);
editor_data->get_undo_redo().add_do_method(new_parent, "add_child", node);
@@ -1596,17 +1627,17 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
String old_name = former_names[ni];
String new_name = new_parent->validate_child_name(node);
- // name was modified, fix the path renames
+ // Name was modified, fix the path renames.
if (old_name.casecmp_to(new_name) != 0) {
- // Fix the to name to have the new name
+ // Fix the to name to have the new name.
NodePath old_new_name = path_renames[ni].second;
NodePath new_path;
Vector<StringName> unfixed_new_names = old_new_name.get_names();
Vector<StringName> fixed_new_names;
- // Get last name and replace with fixed new name
+ // Get last name and replace with fixed new name.
for (int a = 0; a < (unfixed_new_names.size() - 1); a++) {
fixed_new_names.push_back(unfixed_new_names[a]);
}
@@ -1640,8 +1671,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
inc++;
}
- //add and move in a second step.. (so old order is preserved)
-
+ // Add and move in a second step (so old order is preserved).
for (int ni = 0; ni < p_nodes.size(); ni++) {
Node *node = p_nodes[ni];
@@ -2903,5 +2933,6 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
profile_allow_script_editing = true;
EDITOR_DEF("interface/editors/show_scene_tree_root_selection", true);
+ EDITOR_DEF("interface/editors/derive_script_globals_by_name", true);
EDITOR_DEF("_use_favorites_root_selection", false);
}