-New reparent option "keep global transform" on reparent dialog. It is enabled by default. Closes #2284

This commit is contained in:
Juan Linietsky 2016-01-02 11:57:47 -03:00
parent d069c44a7f
commit 84f96eb523
4 changed files with 52 additions and 9 deletions

View file

@ -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");
}

View file

@ -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);

View file

@ -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<Node2D>())
editor_data->get_undo_redo().add_do_method(node,"set_global_transform",node->cast_to<Node2D>()->get_global_transform());
if (node->cast_to<Spatial>())
editor_data->get_undo_redo().add_do_method(node,"set_global_transform",node->cast_to<Spatial>()->get_global_transform());
if (node->cast_to<Control>()) {
bool can_do_it=false;
Control *c=node->cast_to<Control>();
if (c->get_parent()->cast_to<Container>())
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<Control>()->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<Node2D>())
editor_data->get_undo_redo().add_undo_method(node,"set_transform",node->cast_to<Node2D>()->get_transform());
if (node->cast_to<Spatial>())
editor_data->get_undo_redo().add_undo_method(node,"set_transform",node->cast_to<Spatial>()->get_transform());
if (node->cast_to<Control>()) {
bool can_do_it=false;
Control *c=node->cast_to<Control>();
if (c->get_parent()->cast_to<Container>())
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<Control>()->get_pos());
}
}
}
perform_node_renames(NULL,&path_renames);

View file

@ -99,7 +99,7 @@ class SceneTreeDock : public VBoxContainer {
EditorNode *editor;
Node *_duplicate(Node *p_node, Map<Node*,Node*> &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<Script>& p_script);