Merge pull request #61145 from Chaosus/graph_edit_delete_nodes_param_3.x

This commit is contained in:
Rémi Verschelde 2022-05-18 14:10:15 +02:00 committed by GitHub
commit 894088203d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 19 deletions

View file

@ -212,8 +212,9 @@
</description>
</signal>
<signal name="delete_nodes_request">
<argument index="0" name="nodes" type="Array" />
<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>
</signal>
<signal name="disconnection_request">

View file

@ -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
}
void VisualShaderEditor::_on_nodes_delete() {
void VisualShaderEditor::_on_nodes_delete(const Array &p_nodes) {
VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
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()) {

View file

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

View file

@ -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
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()) {
@ -4253,7 +4259,7 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_
void VisualScriptEditor::_menu_option(int p_what) {
switch (p_what) {
case EDIT_DELETE_NODES: {
_on_nodes_delete();
_on_nodes_delete(Array());
} break;
case EDIT_TOGGLE_BREAKPOINT: {
List<String> reselect;
@ -4288,7 +4294,7 @@ void VisualScriptEditor::_menu_option(int p_what) {
} break;
case EDIT_CUT_NODES: {
_on_nodes_copy();
_on_nodes_delete();
_on_nodes_delete(Array());
} break;
case EDIT_PASTE_NODES: {
_on_nodes_paste();

View file

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

View file

@ -1370,7 +1370,18 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
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();
}
}
@ -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("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("delete_nodes_request"));
ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes")));
ADD_SIGNAL(MethodInfo("_begin_node_move"));
ADD_SIGNAL(MethodInfo("_end_node_move"));
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "ofs")));