summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2016-05-17 09:14:23 +0200
committerRémi Verschelde <remi@verschelde.fr>2016-05-17 09:14:23 +0200
commit68dc685f1f6182d306fd7a3b31b27ab7c8e10b73 (patch)
tree56e449ec38b9d69654ddb5f05f1918a415e3ede3
parentf93aaa9b7896231e80379a17938b9aca26429dd0 (diff)
parentaee156dc023e8cf4db5c5ee51fe6b2b46c7c1660 (diff)
Merge pull request #4652 from Paulb23/node_duplication_position
Node duplication positions under duplicated node, issue #964
-rw-r--r--scene/main/node.cpp12
-rw-r--r--scene/main/node.h1
-rw-r--r--tools/editor/scene_tree_dock.cpp2
3 files changed, 14 insertions, 1 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index da14fa1111..e85b3698c8 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -749,6 +749,16 @@ void Node::add_child(Node *p_child, bool p_legible_unique_name) {
}
+void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name) {
+ add_child(p_child, p_legible_unique_name);
+
+ if (is_a_parent_of(p_node)) {
+ move_child(p_child, p_node->get_position_in_parent() + 1);
+ } else {
+ WARN_PRINTS("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent")
+ }
+}
+
void Node::_propagate_validate_owner() {
@@ -2012,6 +2022,8 @@ void Node::clear_internal_tree_resource_paths() {
void Node::_bind_methods() {
+ ObjectTypeDB::bind_method(_MD("_add_child_below_node","node:Node","child_node:Node","legible_unique_name"),&Node::add_child_below_node,DEFVAL(false));
+
ObjectTypeDB::bind_method(_MD("set_name","name"),&Node::set_name);
ObjectTypeDB::bind_method(_MD("get_name"),&Node::get_name);
ObjectTypeDB::bind_method(_MD("add_child","node:Node","legible_unique_name"),&Node::add_child,DEFVAL(false));
diff --git a/scene/main/node.h b/scene/main/node.h
index 83086bb0cf..4756909e23 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -190,6 +190,7 @@ public:
void set_name(const String& p_name);
void add_child(Node *p_child,bool p_legible_unique_name=false);
+ void add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name=false);
void remove_child(Node *p_child);
int get_child_count() const;
diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp
index 35a84ae5c1..6d0c21d5f8 100644
--- a/tools/editor/scene_tree_dock.cpp
+++ b/tools/editor/scene_tree_dock.cpp
@@ -442,7 +442,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
dup->set_name(attempt);
- editor_data->get_undo_redo().add_do_method(parent,"add_child",dup);
+ editor_data->get_undo_redo().add_do_method(parent,"_add_child_below_node",node, dup);
for (List<Node*>::Element *F=owned.front();F;F=F->next()) {
if (!duplimap.has(F->get())) {