Skip to content

Commit cd28da0

Browse files
committed
Deleting nodes
1 parent 882e52e commit cd28da0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

editor/scene_tree_dock.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,16 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
27952795
if (remove_list.is_empty()) {
27962796
return;
27972797
}
2798+
2799+
Vector<Node *> nodes;
2800+
for (Node *n : remove_list) {
2801+
nodes.append(n);
2802+
}
2803+
Node *root = EditorNode::get_singleton()->get_edited_scene();
2804+
Vector<String> paths;
2805+
for (int i = 0; i < nodes.size(); i++) {
2806+
paths.append(root->get_path_to(nodes.get(i)));
2807+
}
27982808

27992809
bool entire_scene = false;
28002810

@@ -2882,6 +2892,8 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
28822892
InspectorDock::get_singleton()->call("_prepare_history");
28832893
InspectorDock::get_singleton()->update(nullptr);
28842894
NodeDock::get_singleton()->set_node(nullptr);
2895+
2896+
emit_signal("nodes_deleted", paths);
28852897
}
28862898

28872899
void SceneTreeDock::_update_script_button() {
@@ -4679,6 +4691,7 @@ void SceneTreeDock::_bind_methods() {
46794691
ADD_SIGNAL(MethodInfo("nodes_reparented", PropertyInfo(Variant::ARRAY, "nodes"), PropertyInfo(Variant::NODE_PATH, "new_parent")));
46804692
ADD_SIGNAL(MethodInfo("node_created_type", PropertyInfo(Variant::OBJECT, "nodes"), PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::BOOL, "is_custom_type"), PropertyInfo(Variant::STRING, "weird_type")));
46814693
ADD_SIGNAL(MethodInfo("scenes_instantiated", PropertyInfo(Variant::OBJECT, "parent"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "paths"), PropertyInfo(Variant::INT, "index")));
4694+
ADD_SIGNAL(MethodInfo("nodes_deleted", PropertyInfo(Variant::PACKED_STRING_ARRAY, "paths")));
46824695
}
46834696

46844697
SceneTreeDock *SceneTreeDock::singleton = nullptr;

modules/multi_godot/multi_godot.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void MultiGodot::_bind_methods() {
3636
ClassDB::bind_method(D_METHOD("_on_nodes_reparented", "nodes", "new_parent"), &MultiGodot::_on_nodes_reparented);
3737
ClassDB::bind_method(D_METHOD("_on_node_created", "node", "type", "is_custom_type", "weird_type"), &MultiGodot::_on_node_created);
3838
ClassDB::bind_method(D_METHOD("_on_scenes_instantiated", "parent", "paths", "index"), &MultiGodot::_on_scenes_instantiated);
39+
ClassDB::bind_method(D_METHOD("_on_nodes_deleted", "nodes"), &MultiGodot::_on_nodes_deleted);
3940

4041
// Remote Callables
4142

@@ -56,6 +57,7 @@ void MultiGodot::_bind_methods() {
5657
ClassDB::bind_method(D_METHOD("_reparent_nodes", "old", "new"), &MultiGodot::_reparent_nodes);
5758
ClassDB::bind_method(D_METHOD("_create_node", "parent_path", "type", "is_custom_type", "weird_type"), &MultiGodot::_create_node);
5859
ClassDB::bind_method(D_METHOD("_instantiate_scenes", "parent_path", "paths", "index"), &MultiGodot::_instantiate_scenes);
60+
ClassDB::bind_method(D_METHOD("_delete_nodes", "paths"), &MultiGodot::_delete_nodes);
5961

6062
// Button signals
6163

@@ -127,6 +129,7 @@ void MultiGodot::_ready() {
127129
scene_tree_dock->connect("nodes_reparented", Callable(this, "_on_nodes_reparented"));
128130
scene_tree_dock->connect("node_created_type", Callable(this, "_on_node_created"));
129131
scene_tree_dock->connect("scenes_instantiated", Callable(this, "_on_scenes_instantiated"));
132+
scene_tree_dock->connect("nodes_deleted", Callable(this, "_on_nodes_deleted"));
130133
button_notifier->connect("editor_tab_changed", Callable(this, "_on_editor_tab_changed"));
131134
button_notifier->connect("current_script_path_changed", Callable(this, "_on_current_script_path_changed"));
132135
steam->connect("lobby_created", Callable(this, "_on_lobby_created"));
@@ -1164,6 +1167,13 @@ void MultiGodot::_instantiate_scenes(String parent_path, Vector<String> paths, i
11641167
SceneTreeDock::get_singleton()->_perform_instantiate_scenes(paths, root->get_node(parent_path), index, false);
11651168
}
11661169

1170+
void MultiGodot::_delete_nodes(Vector<String> paths) {
1171+
Node *root = EditorNode::get_singleton()->get_edited_scene();
1172+
for (int i = 0; i < paths.size(); i++) {
1173+
root->get_node(paths.get(i))->queue_free();
1174+
}
1175+
}
1176+
11671177
// SIGNALS
11681178

11691179
void MultiGodot::_on_lobby_created(int connect, uint64_t this_lobby_id) {
@@ -1345,6 +1355,13 @@ void MultiGodot::_on_scenes_instantiated(Node *parent, Vector<String> paths, int
13451355
_call_func(this, "_instantiate_scenes", {root->get_path_to(parent), paths, index});
13461356
}
13471357

1358+
void MultiGodot::_on_nodes_deleted(Vector<String> paths) {
1359+
if (VERBOSE_DEBUG) {
1360+
print_line("Some scenes were deleted");
1361+
}
1362+
_call_func(this, "_delete_nodes", {paths});
1363+
}
1364+
13481365
// PLUGIN
13491366

13501367
MultiGodotPlugin::MultiGodotPlugin() {

modules/multi_godot/multi_godot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class MultiGodot : public Node2D {
133133
void _reparent_nodes(Array paths, String new_path);
134134
void _create_node(String parent_path, String type, bool is_custom_type, String weird_type);
135135
void _instantiate_scenes(String parent_path, Vector<String> paths, int index);
136+
void _delete_nodes(Vector<String> paths);
136137

137138
// SIGNALS
138139

@@ -147,6 +148,7 @@ class MultiGodot : public Node2D {
147148
void _on_nodes_reparented(Array nodes, NodePath new_parent);
148149
void _on_node_created(Node *node, String type, bool is_custom_type, String weird_type);
149150
void _on_scenes_instantiated(Node *parent, Vector<String> paths, int index);
151+
void _on_nodes_deleted(Vector<String> paths);
150152

151153
public:
152154
MultiGodot();

0 commit comments

Comments
 (0)