diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index 15861ed4a16..15be8b1d002 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -310,19 +310,19 @@ bool ScriptDebuggerRemote::_parse_live_edit(const Array& cmd) { return false; - print_line(Variant(cmd).get_construct_string()); + //print_line(Variant(cmd).get_construct_string()); if (cmdstr=="live_set_root") { if (!live_edit_funcs->root_func) return true; - print_line("root: "+Variant(cmd).get_construct_string()); + //print_line("root: "+Variant(cmd).get_construct_string()); live_edit_funcs->root_func(live_edit_funcs->udata,cmd[1],cmd[2]); } else if (cmdstr=="live_node_path") { if (!live_edit_funcs->node_path_func) return true; - print_line("path: "+Variant(cmd).get_construct_string()); + //print_line("path: "+Variant(cmd).get_construct_string()); live_edit_funcs->node_path_func(live_edit_funcs->udata,cmd[1],cmd[2]); @@ -392,7 +392,7 @@ bool ScriptDebuggerRemote::_parse_live_edit(const Array& cmd) { live_edit_funcs->tree_duplicate_node_func(live_edit_funcs->udata,cmd[1],cmd[2]); } else if (cmdstr=="live_reparent_node") { - live_edit_funcs->tree_reparent_node_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3]); + live_edit_funcs->tree_reparent_node_func(live_edit_funcs->udata,cmd[1],cmd[2],cmd[3],cmd[4]); } else { diff --git a/core/script_language.h b/core/script_language.h index 8b0ed2c33b8..d5fb83deb16 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -258,7 +258,7 @@ public: void (*tree_remove_and_keep_node_func)(void*,const NodePath& p_at,ObjectID p_keep_id); void (*tree_restore_node_func)(void*,ObjectID p_id,const NodePath& p_at,int p_at_pos); void (*tree_duplicate_node_func)(void*,const NodePath& p_at,const String& p_new_name); - void (*tree_reparent_node_func)(void*,const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name); + void (*tree_reparent_node_func)(void*,const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos); }; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5e0faae0a27..8336ce35f60 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -224,6 +224,15 @@ void Node::_propagate_exit_tree() { data.tree->live_scene_edit_cache.erase(E); } } + + Map >::Element *F=data.tree->live_edit_remove_list.find(this); + if (F) { + for (Map::Element*G=F->get().front();G;G=G->next()) { + + memdelete(G->get()); + } + data.tree->live_edit_remove_list.erase(F); + } } #endif data.blocked++; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 9a05d6d4d0a..45e3d92ece1 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -1203,7 +1203,7 @@ void SceneTree::_live_edit_create_node_func(const NodePath& p_parent,const Strin void SceneTree::_live_edit_instance_node_func(const NodePath& p_parent,const String& p_path,const String& p_name){ Ref ps = ResourceLoader::load(p_path); - print_line("instance node?"); + if (!ps.is_valid()) return; @@ -1265,11 +1265,81 @@ void SceneTree::_live_edit_remove_node_func(const NodePath& p_at){ } void SceneTree::_live_edit_remove_and_keep_node_func(const NodePath& p_at,ObjectID p_keep_id){ + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + Map >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + + for(Set::Element *F=E->get().front();F;) { + + Set::Element *N=F->next(); + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + + Node *n2 = n->get_node(p_at); + + n2->get_parent()->remove_child(n2); + + live_edit_remove_list[n][p_keep_id]=n2; + + F=N; + + } } void SceneTree::_live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at,int p_at_pos){ + Node *base = NULL; + if (root->has_node(live_edit_root)) + base = root->get_node(live_edit_root); + + Map >::Element *E=live_scene_edit_cache.find(live_edit_scene); + if (!E) + return; //scene not editable + + for(Set::Element *F=E->get().front();F;) { + + Set::Element *N=F->next(); + + Node *n=F->get(); + + if (base && !base->is_a_parent_of(n)) + continue; + + if (!n->has_node(p_at)) + continue; + Node *n2 = n->get_node(p_at); + + Map >::Element *EN=live_edit_remove_list.find(n); + + if (!EN) + continue; + + Map::Element *FN=EN->get().find(p_id); + + if (!FN) + continue; + n2->add_child(FN->get()); + + EN->get().erase(FN); + + if (EN->get().size()==0) { + live_edit_remove_list.erase(EN); + } + + F=N; + + } } void SceneTree::_live_edit_duplicate_node_func(const NodePath& p_at,const String& p_new_name){ @@ -1298,12 +1368,11 @@ void SceneTree::_live_edit_duplicate_node_func(const NodePath& p_at,const String continue; dup->set_name(p_new_name); - n2->get_parent()->add_child(dup); } } -void SceneTree::_live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name){ +void SceneTree::_live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos){ Node *base = NULL; if (root->has_node(live_edit_root)) @@ -1332,6 +1401,8 @@ void SceneTree::_live_edit_reparent_node_func(const NodePath& p_at,const NodePat nfrom->set_name(p_new_name); nto->add_child(nfrom); + if (p_at_pos>=0) + nto->move_child(nfrom,p_at_pos); } } diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index 94d0abe50f2..1f09d9c546c 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -173,6 +173,7 @@ friend class Viewport; String live_edit_scene; Map > live_scene_edit_cache; + Map > live_edit_remove_list; ScriptDebugger::LiveEditFuncs live_edit_funcs; @@ -193,7 +194,7 @@ friend class Viewport; void _live_edit_remove_and_keep_node_func(const NodePath& p_at,ObjectID p_keep_id); void _live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at,int p_at_pos); void _live_edit_duplicate_node_func(const NodePath& p_at,const String& p_new_name); - void _live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name); + void _live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos); static void _live_edit_node_path_funcs(void *self,const NodePath &p_path,int p_id) { reinterpret_cast(self)->_live_edit_node_path_func(p_path,p_id); } static void _live_edit_res_path_funcs(void *self,const String &p_path,int p_id) { reinterpret_cast(self)->_live_edit_res_path_func(p_path,p_id); } @@ -212,7 +213,7 @@ friend class Viewport; static void _live_edit_remove_and_keep_node_funcs(void* self,const NodePath& p_at,ObjectID p_keep_id) { reinterpret_cast(self)->_live_edit_remove_and_keep_node_func(p_at,p_keep_id); } static void _live_edit_restore_node_funcs(void* self,ObjectID p_id,const NodePath& p_at,int p_at_pos) { reinterpret_cast(self)->_live_edit_restore_node_func(p_id,p_at,p_at_pos); } static void _live_edit_duplicate_node_funcs(void* self,const NodePath& p_at,const String& p_new_name) { reinterpret_cast(self)->_live_edit_duplicate_node_func(p_at,p_new_name); } - static void _live_edit_reparent_node_funcs(void* self,const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name) { reinterpret_cast(self)->_live_edit_reparent_node_func(p_at,p_new_place,p_new_name); } + static void _live_edit_reparent_node_funcs(void* self,const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos) { reinterpret_cast(self)->_live_edit_reparent_node_func(p_at,p_new_place,p_new_name,p_at_pos); } #endif protected: diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 111d307b8e9..ae0b58a6653 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -402,7 +402,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); - editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),edited_scene->get_path_to(parent),attempt); + editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),attempt); editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+attempt)); //parent->add_child(dup); @@ -919,8 +919,8 @@ void SceneTreeDock::_node_reparent(NodePath p_path,bool p_node_only) { ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); String new_name = new_parent->validate_child_name(node->get_name()); - 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); - editor_data->get_undo_redo().add_undo_method(sed,"live_debug_reparent_node",NodePath(String(edited_scene->get_path_to(new_parent))+"/"+new_name),node->get_parent(),node->get_name()); + 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()); editor_data->get_undo_redo().add_do_method(this,"_set_owners",edited_scene,owners); diff --git a/tools/editor/script_editor_debugger.cpp b/tools/editor/script_editor_debugger.cpp index a0ff55e8455..a4bd8f3bd7b 100644 --- a/tools/editor/script_editor_debugger.cpp +++ b/tools/editor/script_editor_debugger.cpp @@ -927,7 +927,7 @@ void ScriptEditorDebugger::update_live_edit_root() { void ScriptEditorDebugger::live_debug_create_node(const NodePath& p_parent,const String& p_type,const String& p_name) { - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; msg.push_back("live_create_node"); msg.push_back(p_parent); @@ -939,7 +939,7 @@ void ScriptEditorDebugger::live_debug_create_node(const NodePath& p_parent,const void ScriptEditorDebugger::live_debug_instance_node(const NodePath& p_parent,const String& p_path,const String& p_name){ - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; msg.push_back("live_instance_node"); msg.push_back(p_parent); @@ -951,7 +951,7 @@ void ScriptEditorDebugger::live_debug_instance_node(const NodePath& p_parent,con } void ScriptEditorDebugger::live_debug_remove_node(const NodePath& p_at){ - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; msg.push_back("live_remove_node"); msg.push_back(p_at); @@ -961,9 +961,9 @@ void ScriptEditorDebugger::live_debug_remove_node(const NodePath& p_at){ } void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath& p_at,ObjectID p_keep_id) { - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; - msg.push_back("live_remove_and_keep_mode"); + msg.push_back("live_remove_and_keep_node"); msg.push_back(p_at); msg.push_back(p_keep_id); ppeer->put_var(msg); @@ -972,7 +972,7 @@ void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath& p_at, } void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath& p_at, int p_at_pos){ - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; msg.push_back("live_restore_node"); msg.push_back(p_id); @@ -984,7 +984,7 @@ void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath } void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath& p_at,const String& p_new_name){ - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; msg.push_back("live_duplicate_node"); msg.push_back(p_at); @@ -993,14 +993,15 @@ void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath& p_at,const } } -void ScriptEditorDebugger::live_debug_reparent_node(const NodePath& p_at, const NodePath& p_new_place, const String &p_new_name){ +void ScriptEditorDebugger::live_debug_reparent_node(const NodePath& p_at, const NodePath& p_new_place, const String &p_new_name, int p_at_pos){ - if (connection.is_valid()) { + if (live_debug && connection.is_valid()) { Array msg; msg.push_back("live_reparent_node"); msg.push_back(p_at); msg.push_back(p_new_place); msg.push_back(p_new_name); + msg.push_back(p_at_pos); ppeer->put_var(msg); } diff --git a/tools/editor/script_editor_debugger.h b/tools/editor/script_editor_debugger.h index e8ac0fddb33..cad41ce8a7c 100644 --- a/tools/editor/script_editor_debugger.h +++ b/tools/editor/script_editor_debugger.h @@ -159,7 +159,7 @@ public: void live_debug_remove_and_keep_node(const NodePath& p_at,ObjectID p_keep_id); void live_debug_restore_node(ObjectID p_id,const NodePath& p_at,int p_at_pos); void live_debug_duplicate_node(const NodePath& p_at,const String& p_new_name); - void live_debug_reparent_node(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name); + void live_debug_reparent_node(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos); void update_live_edit_root();