diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-11-20 08:59:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-20 08:59:40 +0100 |
commit | 49a73182d322f258b0fab76077a41b3f68a62bb1 (patch) | |
tree | 1e98d294ffdfbb7c444dd88d6242af3e97e6d0df /editor | |
parent | b1f037eeb94ce4e3977ffde32c5f7a1cc96cf81b (diff) | |
parent | 5a0be858f4d52b374112f33245be16299a23e300 (diff) |
Merge pull request #13041 from RandomShaper/unify-node-duplicate
Let SceneTreeDock duplicate nodes via Node::duplicate()
Diffstat (limited to 'editor')
-rw-r--r-- | editor/scene_tree_dock.cpp | 80 | ||||
-rw-r--r-- | editor/scene_tree_dock.h | 1 |
2 files changed, 2 insertions, 79 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 21ac27dc4e..f866a158f3 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -443,8 +443,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); - Map<Node *, Node *> duplimap; - Node *dup = _duplicate(node, duplimap); + Map<const Node *, Node *> duplimap; + Node *dup = node->duplicate_from_editor(duplimap); ERR_CONTINUE(!dup); @@ -821,82 +821,6 @@ void SceneTreeDock::_node_renamed() { _node_selected(); } -Node *SceneTreeDock::_duplicate(Node *p_node, Map<Node *, Node *> &duplimap) { - - Node *node = NULL; - - if (p_node->get_filename() != "") { //an instance - - Ref<PackedScene> sd = ResourceLoader::load(p_node->get_filename()); - ERR_FAIL_COND_V(!sd.is_valid(), NULL); - node = sd->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, NULL); - node->set_scene_instance_load_placeholder(p_node->get_scene_instance_load_placeholder()); - } else { - Object *obj = ClassDB::instance(p_node->get_class()); - ERR_FAIL_COND_V(!obj, NULL); - node = Object::cast_to<Node>(obj); - if (!node) - memdelete(obj); - ERR_FAIL_COND_V(!node, NULL); - } - - List<PropertyInfo> plist; - - p_node->get_property_list(&plist); - - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) - continue; - String name = E->get().name; - Variant value = p_node->get(name); - // Duplicate dictionaries and arrays, mainly needed for __meta__ - if (value.get_type() == Variant::DICTIONARY) { - value = Dictionary(value).copy(); - } else if (value.get_type() == Variant::ARRAY) { - value = Array(value).duplicate(); - } - node->set(name, value); - } - - List<Connection> conns; - p_node->get_all_signal_connections(&conns); - for (List<Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().flags & CONNECT_PERSIST) { - node->connect(E->get().signal, E->get().target, E->get().method, E->get().binds, E->get().flags); - } - } - - List<Node::GroupInfo> group_info; - p_node->get_groups(&group_info); - for (List<Node::GroupInfo>::Element *E = group_info.front(); E; E = E->next()) { - - if (E->get().persistent) - node->add_to_group(E->get().name, true); - } - - node->set_name(p_node->get_name()); - duplimap[p_node] = node; - - for (int i = 0; i < p_node->get_child_count(); i++) { - - Node *child = p_node->get_child(i); - if (p_node->get_owner() != child->get_owner()) - continue; //don't bother with not in-scene nodes. - - Node *dup = _duplicate(child, duplimap); - if (!dup) { - memdelete(node); - return NULL; - } - - node->add_child(dup); - } - - return node; -} - void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) { for (int i = 0; i < p_nodes.size(); i++) { diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index 97d3c4748a..7848052241 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -130,7 +130,6 @@ class SceneTreeDock : public VBoxContainer { void _add_children_to_popup(Object *p_obj, int p_depth); - Node *_duplicate(Node *p_node, Map<Node *, Node *> &duplimap); void _node_reparent(NodePath p_path, bool p_keep_global_xform); void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform); |