1010#include " editor/editor_file_system.h"
1111#include " editor/editor_interface.h"
1212#include " editor/editor_main_screen.h"
13+ #include " editor/editor_undo_redo_manager.h"
1314#include " editor/gui/scene_tree_editor.h"
1415#include " editor/plugins/script_editor_plugin.h"
1516#include " editor/scene_tree_dock.h"
@@ -32,6 +33,7 @@ void MultiGodot::_bind_methods() {
3233 ClassDB::bind_method (D_METHOD (" _on_lobby_chat_update" , " this_lobby_id" , " change_id" , " making_change_id" , " chat_state" ), &MultiGodot::_on_lobby_chat_update);
3334 ClassDB::bind_method (D_METHOD (" _on_p2p_session_request" , " remote_id" ), &MultiGodot::_on_p2p_session_request);
3435 ClassDB::bind_method (D_METHOD (" _on_p2p_session_connect_fail" , " steam_id" , " session_error" ), &MultiGodot::_on_p2p_session_connect_fail);
36+ ClassDB::bind_method (D_METHOD (" _on_nodes_reparented" , " nodes" , " new_parent" ), &MultiGodot::_on_nodes_reparented);
3537
3638 // Remote Callables
3739
@@ -49,7 +51,7 @@ void MultiGodot::_bind_methods() {
4951 ClassDB::bind_method (D_METHOD (" _set_as_script_owner" , " path" ), &MultiGodot::_set_as_script_owner);
5052 ClassDB::bind_method (D_METHOD (" _apply_action" ), &MultiGodot::_apply_action);
5153 ClassDB::bind_method (D_METHOD (" _instantiate_resource" , " node_path" , " resource_path" , " type" ), &MultiGodot::_instantiate_resource);
52- ClassDB::bind_method (D_METHOD (" _move_node " , " old" , " new" ), &MultiGodot::_move_node );
54+ ClassDB::bind_method (D_METHOD (" _reparent_nodes " , " old" , " new" ), &MultiGodot::_reparent_nodes );
5355
5456 // Button signals
5557
@@ -116,6 +118,7 @@ void MultiGodot::_ready() {
116118
117119 filesystem_scanner.start (_threaded_filesystem_scanner, this );
118120
121+ SceneTreeDock::get_singleton ()->connect (" nodes_reparented" , Callable (this , " _on_nodes_reparented" ));
119122 button_notifier->connect (" editor_tab_changed" , Callable (this , " _on_editor_tab_changed" ));
120123 button_notifier->connect (" current_script_path_changed" , Callable (this , " _on_current_script_path_changed" ));
121124 steam->connect (" lobby_created" , Callable (this , " _on_lobby_created" ));
@@ -1109,25 +1112,25 @@ void MultiGodot::_instantiate_resource(String node_path, String resource_path, S
11091112
11101113}
11111114
1112- void MultiGodot::_move_node (String current_path , String new_parent_path) {
1115+ void MultiGodot::_reparent_nodes (Array paths , String new_parent_path) {
11131116 SceneTreeEditor *scene_tree_editor = SceneTreeDock::get_singleton ()->get_tree_editor ();
11141117 Node *root = EditorNode::get_singleton ()->get_edited_scene ();
11151118
1116- Node *moved = root->get_node (current_path);
1117- if (!moved) {
1118- print_error (" Request to move node but the node at path " + current_path + " does not exist. Was it moved?" );
1119- return ;
1120- }
1121-
11221119 Node *parent = root->get_node (new_parent_path);
11231120 if (!parent) {
1124- print_error (" Request to move a node (that exists) to a parent that doesn't exist at path " + new_parent_path + " . No parents? " );
1121+ print_error (" Remote requested to reparent some nodes to a parent at path " + new_parent_path + " but it doesn't exist. " );
11251122 return ;
11261123 }
11271124
1128- // Remove the child and give it to new parents.
1129- moved->get_parent ()->remove_child (moved);
1130- parent->add_child (moved);
1125+ for (int i = 0 ; i < paths.size (); i++) {
1126+ String path = paths[i];
1127+ Node *node = root->get_node (path);
1128+ if (!node) {
1129+ print_error (" Remote requested to reparent a node at path " + path + " but it doesn't exist." );
1130+ continue ;
1131+ }
1132+ node->reparent (parent);
1133+ }
11311134}
11321135
11331136// SIGNALS
@@ -1286,6 +1289,15 @@ void MultiGodot::_on_current_script_path_changed(String path) {
12861289 _set_user_data_for_everyone (" current_spectating_script" , " " );
12871290}
12881291
1292+ void MultiGodot::_on_nodes_reparented (Array nodes, NodePath new_parent) {
1293+ if (recently_reparented_by_remote.has (new_parent)) {
1294+ recently_reparented_by_remote.remove_at (recently_reparented_by_remote.find (new_parent));
1295+ return ;
1296+ }
1297+
1298+ _call_func (this , " _reparent_nodes" , {nodes, new_parent});
1299+ }
1300+
12891301// PLUGIN
12901302
12911303MultiGodotPlugin::MultiGodotPlugin () {
0 commit comments