From 84f96eb523fd13329b2c7bfac952f955aed6ca62 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 2 Jan 2016 11:57:47 -0300 Subject: [PATCH] -New reparent option "keep global transform" on reparent dialog. It is enabled by default. Closes #2284 --- tools/editor/reparent_dialog.cpp | 13 +++++++---- tools/editor/reparent_dialog.h | 7 ++++-- tools/editor/scene_tree_dock.cpp | 39 +++++++++++++++++++++++++++++++- tools/editor/scene_tree_dock.h | 2 +- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/tools/editor/reparent_dialog.cpp b/tools/editor/reparent_dialog.cpp index 0bbf461029f..97b27603b2e 100644 --- a/tools/editor/reparent_dialog.cpp +++ b/tools/editor/reparent_dialog.cpp @@ -62,7 +62,7 @@ void ReparentDialog::_reparent() { if (tree->get_selected()) { - emit_signal("reparent",tree->get_selected()->get_path(),node_only->is_pressed()); + emit_signal("reparent",tree->get_selected()->get_path(),keep_transform->is_pressed()); hide(); } } @@ -78,7 +78,7 @@ void ReparentDialog::_bind_methods() { ObjectTypeDB::bind_method("_reparent",&ReparentDialog::_reparent); ObjectTypeDB::bind_method("_cancel",&ReparentDialog::_cancel); - ADD_SIGNAL( MethodInfo("reparent",PropertyInfo(Variant::NODE_PATH,"path"),PropertyInfo(Variant::BOOL,"only_node"))); + ADD_SIGNAL( MethodInfo("reparent",PropertyInfo(Variant::NODE_PATH,"path"),PropertyInfo(Variant::BOOL,"keep_global_xform"))); } @@ -101,15 +101,18 @@ ReparentDialog::ReparentDialog() { //label->set_pos( Point2( 15,8) ); //label->set_text("Reparent Location (Select new Parent):"); - node_only = memnew( CheckButton ); - add_child(node_only); - node_only->hide(); + keep_transform = memnew( CheckBox ); + keep_transform->set_text("Keep Global Transform"); + keep_transform->set_pressed(true); + vbc->add_child(keep_transform); + //vbc->add_margin_child("Options:",node_only);; //cancel->connect("pressed", this,"_cancel"); get_ok()->set_text("Reparent"); + } diff --git a/tools/editor/reparent_dialog.h b/tools/editor/reparent_dialog.h index a55be57c167..296102e4b9c 100644 --- a/tools/editor/reparent_dialog.h +++ b/tools/editor/reparent_dialog.h @@ -32,6 +32,7 @@ #include "scene/gui/dialogs.h" #include "scene/gui/button.h" #include "scene/gui/check_button.h" +#include "scene/gui/check_box.h" #include "tools/editor/scene_tree_editor.h" #include "scene/gui/line_edit.h" /** @@ -42,12 +43,14 @@ class ReparentDialog : public ConfirmationDialog { OBJ_TYPE( ReparentDialog, ConfirmationDialog ); SceneTreeEditor *tree; - CheckButton *node_only; + CheckBox *keep_transform; + void update_tree(); void _reparent(); void _cancel(); - + + protected: void _notification(int p_what); diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 35219a7c63d..75f1597b20a 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -889,7 +889,7 @@ bool SceneTreeDock::_validate_no_foreign() { return true; } -void SceneTreeDock::_node_reparent(NodePath p_path,bool p_node_only) { +void SceneTreeDock::_node_reparent(NodePath p_path,bool p_keep_global_xform) { Node *node = scene_tree->get_selected(); @@ -948,6 +948,23 @@ void SceneTreeDock::_node_reparent(NodePath p_path,bool p_node_only) { editor_data->get_undo_redo().add_do_method(sed,"live_debug_reparent_node",edited_scene->get_path_to(node),edited_scene->get_path_to(new_parent),new_name,-1); editor_data->get_undo_redo().add_undo_method(sed,"live_debug_reparent_node",NodePath(String(edited_scene->get_path_to(new_parent))+"/"+new_name),edited_scene->get_path_to(node->get_parent()),node->get_name(),node->get_index()); + if (p_keep_global_xform) { + if (node->cast_to()) + editor_data->get_undo_redo().add_do_method(node,"set_global_transform",node->cast_to()->get_global_transform()); + if (node->cast_to()) + editor_data->get_undo_redo().add_do_method(node,"set_global_transform",node->cast_to()->get_global_transform()); + if (node->cast_to()) { + bool can_do_it=false; + Control *c=node->cast_to(); + if (c->get_parent()->cast_to()) + can_do_it=false; + for(int i=0;i<4;i++) { + if (c->get_anchor(Margin(i))!=ANCHOR_BEGIN) + can_do_it=false; + } + editor_data->get_undo_redo().add_do_method(node,"set_global_pos",node->cast_to()->get_global_pos()); + } + } editor_data->get_undo_redo().add_do_method(this,"_set_owners",edited_scene,owners); @@ -982,6 +999,26 @@ void SceneTreeDock::_node_reparent(NodePath p_path,bool p_node_only) { if (editor->get_animation_editor()->get_root()==node) editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",node); + if (p_keep_global_xform) { + if (node->cast_to()) + editor_data->get_undo_redo().add_undo_method(node,"set_transform",node->cast_to()->get_transform()); + if (node->cast_to()) + editor_data->get_undo_redo().add_undo_method(node,"set_transform",node->cast_to()->get_transform()); + if (node->cast_to()) { + bool can_do_it=false; + Control *c=node->cast_to(); + if (c->get_parent()->cast_to()) + can_do_it=false; + for(int i=0;i<4;i++) { + if (c->get_anchor(Margin(i))!=ANCHOR_BEGIN) + can_do_it=false; + } + editor_data->get_undo_redo().add_undo_method(node,"set_pos",node->cast_to()->get_pos()); + } + } + + + } perform_node_renames(NULL,&path_renames); diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h index b7e96be5c7b..aad12a23401 100644 --- a/tools/editor/scene_tree_dock.h +++ b/tools/editor/scene_tree_dock.h @@ -99,7 +99,7 @@ class SceneTreeDock : public VBoxContainer { EditorNode *editor; Node *_duplicate(Node *p_node, Map &duplimap); - void _node_reparent(NodePath p_path,bool p_node_only); + void _node_reparent(NodePath p_path, bool p_keep_global_xform); void _set_owners(Node *p_owner, const Array& p_nodes); void _load_request(const String& p_path); void _script_open_request(const Ref