Просмотр исходного кода

Add node list param to GraphEdit::delete_nodes_request signal

Yuri Rubinsky 3 лет назад
Родитель
Сommit
32b9818965

+ 2 - 1
doc/classes/GraphEdit.xml

@@ -212,8 +212,9 @@
 			</description>
 			</description>
 		</signal>
 		</signal>
 		<signal name="delete_nodes_request">
 		<signal name="delete_nodes_request">
+			<argument index="0" name="nodes" type="Array" />
 			<description>
 			<description>
-				Emitted when a GraphNode is attempted to be removed from the GraphEdit.
+				Emitted when a GraphNode is attempted to be removed from the GraphEdit. Provides a list of node names to be removed (all selected nodes, excluding nodes without closing button).
 			</description>
 			</description>
 		</signal>
 		</signal>
 		<signal name="disconnection_request">
 		<signal name="disconnection_request">

+ 12 - 6
editor/plugins/visual_shader_editor_plugin.cpp

@@ -1950,17 +1950,23 @@ void VisualShaderEditor::_paste_nodes() {
 	_dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste
 	_dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste
 }
 }
 
 
-void VisualShaderEditor::_on_nodes_delete() {
+void VisualShaderEditor::_on_nodes_delete(const Array &p_nodes) {
 	VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
 	VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
 	List<int> to_erase;
 	List<int> to_erase;
 
 
-	for (int i = 0; i < graph->get_child_count(); i++) {
-		GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
-		if (gn) {
-			if (gn->is_selected() && gn->is_close_button_visible()) {
-				to_erase.push_back(gn->get_name().operator String().to_int());
+	if (p_nodes.empty()) {
+		for (int i = 0; i < graph->get_child_count(); i++) {
+			GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
+			if (gn) {
+				if (gn->is_selected() && gn->is_close_button_visible()) {
+					to_erase.push_back(gn->get_name().operator String().to_int());
+				}
 			}
 			}
 		}
 		}
+	} else {
+		for (int i = 0; i < p_nodes.size(); i++) {
+			to_erase.push_back(p_nodes[i].operator String().to_int());
+		}
 	}
 	}
 
 
 	if (to_erase.empty()) {
 	if (to_erase.empty()) {

+ 1 - 1
editor/plugins/visual_shader_editor_plugin.h

@@ -183,7 +183,7 @@ class VisualShaderEditor : public VBoxContainer {
 	void _node_selected(Object *p_node);
 	void _node_selected(Object *p_node);
 
 
 	void _delete_request(int);
 	void _delete_request(int);
-	void _on_nodes_delete();
+	void _on_nodes_delete(const Array &p_nodes);
 
 
 	void _node_changed(int p_id);
 	void _node_changed(int p_id);
 
 

+ 14 - 8
modules/visual_script/visual_script_editor.cpp

@@ -1831,18 +1831,24 @@ void VisualScriptEditor::_on_nodes_paste() {
 	}
 	}
 }
 }
 
 
-void VisualScriptEditor::_on_nodes_delete() {
+void VisualScriptEditor::_on_nodes_delete(const Array &p_nodes) {
 	// delete all the selected nodes
 	// delete all the selected nodes
 
 
 	List<int> to_erase;
 	List<int> to_erase;
 
 
-	for (int i = 0; i < graph->get_child_count(); i++) {
-		GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
-		if (gn) {
-			if (gn->is_selected() && gn->is_close_button_visible()) {
-				to_erase.push_back(gn->get_name().operator String().to_int());
+	if (p_nodes.empty()) {
+		for (int i = 0; i < graph->get_child_count(); i++) {
+			GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
+			if (gn) {
+				if (gn->is_selected() && gn->is_close_button_visible()) {
+					to_erase.push_back(gn->get_name().operator String().to_int());
+				}
 			}
 			}
 		}
 		}
+	} else {
+		for (int i = 0; i < graph->get_child_count(); i++) {
+			to_erase.push_back(p_nodes[i].operator String().to_int());
+		}
 	}
 	}
 
 
 	if (to_erase.empty()) {
 	if (to_erase.empty()) {
@@ -4253,7 +4259,7 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_
 void VisualScriptEditor::_menu_option(int p_what) {
 void VisualScriptEditor::_menu_option(int p_what) {
 	switch (p_what) {
 	switch (p_what) {
 		case EDIT_DELETE_NODES: {
 		case EDIT_DELETE_NODES: {
-			_on_nodes_delete();
+			_on_nodes_delete(Array());
 		} break;
 		} break;
 		case EDIT_TOGGLE_BREAKPOINT: {
 		case EDIT_TOGGLE_BREAKPOINT: {
 			List<String> reselect;
 			List<String> reselect;
@@ -4288,7 +4294,7 @@ void VisualScriptEditor::_menu_option(int p_what) {
 		} break;
 		} break;
 		case EDIT_CUT_NODES: {
 		case EDIT_CUT_NODES: {
 			_on_nodes_copy();
 			_on_nodes_copy();
-			_on_nodes_delete();
+			_on_nodes_delete(Array());
 		} break;
 		} break;
 		case EDIT_PASTE_NODES: {
 		case EDIT_PASTE_NODES: {
 			_on_nodes_paste();
 			_on_nodes_paste();

+ 1 - 1
modules/visual_script/visual_script_editor.h

@@ -257,7 +257,7 @@ class VisualScriptEditor : public ScriptEditorBase {
 
 
 	void _on_nodes_copy();
 	void _on_nodes_copy();
 	void _on_nodes_paste();
 	void _on_nodes_paste();
-	void _on_nodes_delete();
+	void _on_nodes_delete(const Array &p_nodes);
 	void _on_nodes_duplicate();
 	void _on_nodes_duplicate();
 
 
 	Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
 	Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);

+ 13 - 2
scene/gui/graph_edit.cpp

@@ -1370,7 +1370,18 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
 		}
 		}
 
 
 		if (k->get_scancode() == KEY_DELETE && k->is_pressed()) {
 		if (k->get_scancode() == KEY_DELETE && k->is_pressed()) {
-			emit_signal("delete_nodes_request");
+			Array nodes;
+
+			for (int i = 0; i < get_child_count(); i++) {
+				GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
+				if (gn) {
+					if (gn->is_selected() && gn->is_close_button_visible()) {
+						nodes.push_back(gn->get_name());
+					}
+				}
+			}
+
+			emit_signal("delete_nodes_request", nodes);
 			accept_event();
 			accept_event();
 		}
 		}
 	}
 	}
@@ -1746,7 +1757,7 @@ void GraphEdit::_bind_methods() {
 	ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
 	ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
 	ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
 	ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
 	ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
 	ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
-	ADD_SIGNAL(MethodInfo("delete_nodes_request"));
+	ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes")));
 	ADD_SIGNAL(MethodInfo("_begin_node_move"));
 	ADD_SIGNAL(MethodInfo("_begin_node_move"));
 	ADD_SIGNAL(MethodInfo("_end_node_move"));
 	ADD_SIGNAL(MethodInfo("_end_node_move"));
 	ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "ofs")));
 	ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "ofs")));