Skip to content

Commit

Permalink
Merge pull request #82370 from YuriSizov/graphs-request-rename-close-…
Browse files Browse the repository at this point in the history
…delete-please

Rename close requests to delete requests in `GraphEdit`
  • Loading branch information
akien-mga committed Oct 2, 2023
2 parents 0d03444 + 378ab38 commit bc118b3
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 35 deletions.
14 changes: 7 additions & 7 deletions doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</brief_description>
<description>
[GraphEdit] provides tools for creation, manipulation, and display of various graphs. Its main purpose in the engine is to power the visual programming systems, such as visual shaders, but it is also available for use in user projects.
[GraphEdit] by itself is only an empty container, representing an infinite grid where [GraphNode]s can be placed. Each [GraphNode] represents a node in the graph, a single unit of data in the connected scheme. [GraphEdit], in turn, helps to control various interactions with nodes and between nodes. When the user attempts to connect, disconnect, or close a [GraphNode], a signal is emitted in the [GraphEdit], but no action is taken by default. It is the responsibility of the programmer utilizing this control to implement the necessary logic to determine how each request should be handled.
[GraphEdit] by itself is only an empty container, representing an infinite grid where [GraphNode]s can be placed. Each [GraphNode] represents a node in the graph, a single unit of data in the connected scheme. [GraphEdit], in turn, helps to control various interactions with nodes and between nodes. When the user attempts to connect, disconnect, or delete a [GraphNode], a signal is emitted in the [GraphEdit], but no action is taken by default. It is the responsibility of the programmer utilizing this control to implement the necessary logic to determine how each request should be handled.
[b]Performance:[/b] It is greatly advised to enable low-processor usage mode (see [member OS.low_processor_usage_mode]) when using GraphEdits.
</description>
<tutorials>
Expand Down Expand Up @@ -289,12 +289,6 @@
Emitted at the beginning of a GraphNode movement.
</description>
</signal>
<signal name="close_nodes_request">
<param index="0" name="nodes" type="StringName[]" />
<description>
Emitted when attempting to remove a GraphNode from the GraphEdit. Provides a list of node names to be removed (all selected nodes, excluding nodes without closing button).
</description>
</signal>
<signal name="connection_drag_ended">
<description>
Emitted at the end of a connection drag.
Expand Down Expand Up @@ -338,6 +332,12 @@
Emitted when the user presses [kbd]Ctrl + C[/kbd].
</description>
</signal>
<signal name="delete_nodes_request">
<param index="0" name="nodes" type="StringName[]" />
<description>
Emitted when attempting to remove a GraphNode 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">
<param index="0" name="from_node" type="StringName" />
<param index="1" name="from_port" type="int" />
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/GraphElement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
</member>
</members>
<signals>
<signal name="close_request">
<signal name="delete_request">
<description>
Emitted when closing the GraphElement is requested.
Emitted when removing the GraphElement is requested.
</description>
</signal>
<signal name="dragged">
Expand Down
10 changes: 5 additions & 5 deletions editor/plugins/animation_blend_tree_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void AnimationNodeBlendTreeEditor::update_graph() {
name->connect("text_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_rename_lineedit_changed), CONNECT_DEFERRED);
base = 1;
agnode->set_closable(true);
node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_close_request).bind(E), CONNECT_DEFERRED);
node->connect("delete_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_node_request).bind(E), CONNECT_DEFERRED);
}

for (int i = 0; i < agnode->get_input_count(); i++) {
Expand Down Expand Up @@ -494,7 +494,7 @@ void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options,
undo_redo->commit_action();
}

void AnimationNodeBlendTreeEditor::_close_request(const String &p_which) {
void AnimationNodeBlendTreeEditor::_delete_node_request(const String &p_which) {
if (read_only) {
return;
}
Expand All @@ -518,7 +518,7 @@ void AnimationNodeBlendTreeEditor::_close_request(const String &p_which) {
undo_redo->commit_action();
}

void AnimationNodeBlendTreeEditor::_close_nodes_request(const TypedArray<StringName> &p_nodes) {
void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
if (read_only) {
return;
}
Expand Down Expand Up @@ -552,7 +552,7 @@ void AnimationNodeBlendTreeEditor::_close_nodes_request(const TypedArray<StringN
undo_redo->create_action(TTR("Delete Node(s)"));

for (const StringName &F : to_erase) {
_close_request(F);
_delete_node_request(F);
}

undo_redo->commit_action();
Expand Down Expand Up @@ -1057,7 +1057,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
graph->connect("disconnection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_disconnection_request), CONNECT_DEFERRED);
graph->connect("node_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_selected));
graph->connect("scroll_offset_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_scroll_changed));
graph->connect("close_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_close_nodes_request));
graph->connect("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request));
graph->connect("popup_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_popup_request));
graph->connect("connection_to_empty", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_to_empty));
graph->connect("connection_from_empty", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_from_empty));
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/animation_blend_tree_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
void _node_selected(Object *p_node);
void _open_in_editor(const String &p_which);
void _anim_selected(int p_index, Array p_options, const String &p_node);
void _close_request(const String &p_which);
void _close_nodes_request(const TypedArray<StringName> &p_nodes);
void _delete_node_request(const String &p_which);
void _delete_nodes_request(const TypedArray<StringName> &p_nodes);

bool _update_filters(const Ref<AnimationNode> &anode);
void _inspect_filters(const String &p_which);
Expand Down
10 changes: 5 additions & 5 deletions editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
// All nodes are closable except the output node.
if (p_id >= 2) {
vsnode->set_closable(true);
node->connect("close_request", callable_mp(editor, &VisualShaderEditor::_close_node_request).bind(p_type, p_id), CONNECT_DEFERRED);
node->connect("delete_request", callable_mp(editor, &VisualShaderEditor::_delete_node_request).bind(p_type, p_id), CONNECT_DEFERRED);
}
graph->add_child(node);
node->set_theme(vstheme);
Expand Down Expand Up @@ -3852,7 +3852,7 @@ void VisualShaderEditor::_convert_constants_to_parameters(bool p_vice_versa) {
undo_redo->commit_action();
}

void VisualShaderEditor::_close_node_request(int p_type, int p_node) {
void VisualShaderEditor::_delete_node_request(int p_type, int p_node) {
Ref<VisualShaderNode> node = visual_shader->get_node((VisualShader::Type)p_type, p_node);
if (!node->is_closable()) {
return;
Expand All @@ -3867,7 +3867,7 @@ void VisualShaderEditor::_close_node_request(int p_type, int p_node) {
undo_redo->commit_action();
}

void VisualShaderEditor::_close_nodes_request(const TypedArray<StringName> &p_nodes) {
void VisualShaderEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
List<int> to_erase;

if (p_nodes.is_empty()) {
Expand Down Expand Up @@ -4898,7 +4898,7 @@ void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
_paste_nodes(true, menu_point);
break;
case NodeMenuOptions::DELETE:
_close_nodes_request(TypedArray<StringName>());
_delete_nodes_request(TypedArray<StringName>());
break;
case NodeMenuOptions::DUPLICATE:
_duplicate_nodes();
Expand Down Expand Up @@ -5198,7 +5198,7 @@ VisualShaderEditor::VisualShaderEditor() {
graph->connect("duplicate_nodes_request", callable_mp(this, &VisualShaderEditor::_duplicate_nodes));
graph->connect("copy_nodes_request", callable_mp(this, &VisualShaderEditor::_copy_nodes).bind(false));
graph->connect("paste_nodes_request", callable_mp(this, &VisualShaderEditor::_paste_nodes).bind(false, Point2()));
graph->connect("close_nodes_request", callable_mp(this, &VisualShaderEditor::_close_nodes_request));
graph->connect("delete_nodes_request", callable_mp(this, &VisualShaderEditor::_delete_nodes_request));
graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input));
graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/visual_shader_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ class VisualShaderEditor : public VBoxContainer {
void _node_selected(Object *p_node);

void _delete_nodes(int p_type, const List<int> &p_nodes);
void _close_node_request(int p_type, int p_node);
void _close_nodes_request(const TypedArray<StringName> &p_nodes);
void _delete_node_request(int p_type, int p_node);
void _delete_nodes_request(const TypedArray<StringName> &p_nodes);

void _node_changed(int p_id);

Expand Down
1 change: 0 additions & 1 deletion misc/extension_api_validation/4.1-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ Excluded unexposed classes from extension_api.json.
GH-79311
--------

Validate extension JSON: API was removed: classes/GraphEdit/signals/delete_nodes_request
Validate extension JSON: API was removed: classes/GraphNode/methods/get_connection_input_color
Validate extension JSON: API was removed: classes/GraphNode/methods/get_connection_input_count
Validate extension JSON: API was removed: classes/GraphNode/methods/get_connection_input_height
Expand Down
20 changes: 12 additions & 8 deletions scene/gui/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
}
}

emit_signal(SNAME("close_nodes_request"), nodes);
emit_signal(SNAME("delete_nodes_request"), nodes);
accept_event();
}
}
Expand Down Expand Up @@ -1890,20 +1890,24 @@ void GraphEdit::_bind_methods() {

ADD_SIGNAL(MethodInfo("connection_request", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port")));
ADD_SIGNAL(MethodInfo("disconnection_request", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port")));
ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "position")));
ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_drag_started", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::BOOL, "is_output")));
ADD_SIGNAL(MethodInfo("connection_drag_ended"));

ADD_SIGNAL(MethodInfo("copy_nodes_request"));
ADD_SIGNAL(MethodInfo("paste_nodes_request"));
ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));

ADD_SIGNAL(MethodInfo("node_selected", 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_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to_node"), PropertyInfo(Variant::INT, "to_port"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("close_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));

ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "position")));

ADD_SIGNAL(MethodInfo("begin_node_move"));
ADD_SIGNAL(MethodInfo("end_node_move"));
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "offset")));
ADD_SIGNAL(MethodInfo("connection_drag_started", PropertyInfo(Variant::STRING_NAME, "from_node"), PropertyInfo(Variant::INT, "from_port"), PropertyInfo(Variant::BOOL, "is_output")));
ADD_SIGNAL(MethodInfo("connection_drag_ended"));

BIND_ENUM_CONSTANT(SCROLL_ZOOMS);
BIND_ENUM_CONSTANT(SCROLL_PANS);
Expand Down
8 changes: 5 additions & 3 deletions scene/gui/graph_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ void GraphElement::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selected"), "set_selected", "is_selected");

ADD_SIGNAL(MethodInfo("position_offset_changed"));
ADD_SIGNAL(MethodInfo("node_selected"));
ADD_SIGNAL(MethodInfo("node_deselected"));
ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));

ADD_SIGNAL(MethodInfo("raise_request"));
ADD_SIGNAL(MethodInfo("close_request"));
ADD_SIGNAL(MethodInfo("delete_request"));
ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize")));

ADD_SIGNAL(MethodInfo("dragged", PropertyInfo(Variant::VECTOR2, "from"), PropertyInfo(Variant::VECTOR2, "to")));
ADD_SIGNAL(MethodInfo("position_offset_changed"));

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, GraphElement, resizer);
}

0 comments on commit bc118b3

Please sign in to comment.