Add node list param to `GraphEdit::delete_nodes_request` signal

This commit is contained in:
Yuri Rubinsky 2022-05-17 13:13:35 +03:00
parent 4379383ccd
commit c84d050980
6 changed files with 44 additions and 18 deletions

View File

@ -296,8 +296,9 @@
</description> </description>
</signal> </signal>
<signal name="delete_nodes_request"> <signal name="delete_nodes_request">
<argument index="0" name="nodes" type="StringName[]" />
<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">

View File

@ -459,9 +459,10 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
undo_redo->commit_action(); undo_redo->commit_action();
} }
void AnimationNodeBlendTreeEditor::_delete_nodes_request() { void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
List<StringName> to_erase; List<StringName> to_erase;
if (p_nodes.is_empty()) {
for (int i = 0; i < graph->get_child_count(); i++) { for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
if (gn) { if (gn) {
@ -470,6 +471,11 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request() {
} }
} }
} }
} else {
for (int i = 0; i < p_nodes.size(); i++) {
to_erase.push_back(p_nodes[i]);
}
}
if (to_erase.is_empty()) { if (to_erase.is_empty()) {
return; return;

View File

@ -103,7 +103,7 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
void _open_in_editor(const String &p_which); void _open_in_editor(const String &p_which);
void _anim_selected(int p_index, Array p_options, const String &p_node); void _anim_selected(int p_index, Array p_options, const String &p_node);
void _delete_request(const String &p_which); void _delete_request(const String &p_which);
void _delete_nodes_request(); void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
bool _update_filters(const Ref<AnimationNode> &anode); bool _update_filters(const Ref<AnimationNode> &anode);
void _edit_filters(const String &p_which); void _edit_filters(const String &p_which);

View File

@ -3409,9 +3409,11 @@ void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
undo_redo->commit_action(); undo_redo->commit_action();
} }
void VisualShaderEditor::_delete_nodes_request() { void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
List<int> to_erase; List<int> to_erase;
if (p_nodes.is_empty()) {
// Called from context menu.
for (int i = 0; i < graph->get_child_count(); i++) { for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
if (gn) { if (gn) {
@ -3420,6 +3422,11 @@ void VisualShaderEditor::_delete_nodes_request() {
} }
} }
} }
} else {
for (int i = 0; i < p_nodes.size(); i++) {
to_erase.push_back(p_nodes[i].operator String().to_int());
}
}
if (to_erase.is_empty()) { if (to_erase.is_empty()) {
return; return;
@ -4411,7 +4418,7 @@ void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
_paste_nodes(true, menu_point); _paste_nodes(true, menu_point);
break; break;
case NodeMenuOptions::DELETE: case NodeMenuOptions::DELETE:
_delete_nodes_request(); _delete_nodes_request(TypedArray<StringName>());
break; break;
case NodeMenuOptions::DUPLICATE: case NodeMenuOptions::DUPLICATE:
_duplicate_nodes(); _duplicate_nodes();

View File

@ -346,7 +346,7 @@ class VisualShaderEditor : public VBoxContainer {
void _delete_nodes(int p_type, const List<int> &p_nodes); void _delete_nodes(int p_type, const List<int> &p_nodes);
void _delete_node_request(int p_type, int p_node); void _delete_node_request(int p_type, int p_node);
void _delete_nodes_request(); void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
void _node_changed(int p_id); void _node_changed(int p_id);

View File

@ -1343,7 +1343,19 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
emit_signal(SNAME("paste_nodes_request")); emit_signal(SNAME("paste_nodes_request"));
accept_event(); accept_event();
} else if (p_ev->is_action("ui_graph_delete")) { } else if (p_ev->is_action("ui_graph_delete")) {
emit_signal(SNAME("delete_nodes_request")); TypedArray<StringName> nodes;
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (!gn) {
continue;
}
if (gn->is_selected() && gn->is_close_button_visible()) {
nodes.push_back(gn->get_name());
}
}
emit_signal(SNAME("delete_nodes_request"), nodes);
accept_event(); accept_event();
} }
} }
@ -2290,7 +2302,7 @@ void GraphEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("node_deselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("node_deselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "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", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
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, "offset"))); ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "offset")));