Skip to content

Commit

Permalink
[GraphEdit] Make connections a property
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometror committed Dec 16, 2024
1 parent b9437c3 commit e5be03a
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 102 deletions.
45 changes: 37 additions & 8 deletions doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@
<param index="1" name="from_port" type="int" />
<param index="2" name="to_node" type="StringName" />
<param index="3" name="to_port" type="int" />
<param index="4" name="keep_alive" type="bool" default="false" />
<description>
Create a connection between the [param from_port] of the [param from_node] [GraphNode] and the [param to_port] of the [param to_node] [GraphNode]. If the connection already exists, no connection is created.
Connections with [param keep_alive] set to [code]false[/code] may be deleted automatically if invalid during a redraw.
</description>
</method>
<method name="detach_graph_element_from_frame">
Expand Down Expand Up @@ -172,7 +174,16 @@
<param index="1" name="max_distance" type="float" default="4.0" />
<description>
Returns the closest connection to the given point in screen space. If no connection is found within [param max_distance] pixels, an empty [Dictionary] is returned.
A connection consists in a structure of the form [code]{ from_port: 0, from_node: "GraphNode name 0", to_port: 1, to_node: "GraphNode name 1" }[/code].
A connection is represented as a [Dictionary] in the form of:
[codeblock]
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
[/codeblock]
For example, getting a connection at a given mouse position can be achieved like this:
[codeblocks]
[gdscript]
Expand All @@ -197,17 +208,21 @@
Returns the points which would make up a connection between [param from_node] and [param to_node].
</description>
</method>
<method name="get_connection_list" qualifiers="const">
<return type="Dictionary[]" />
<description>
Returns an [Array] containing the list of connections. A connection consists in a structure of the form [code]{ from_port: 0, from_node: "GraphNode name 0", to_port: 1, to_node: "GraphNode name 1" }[/code].
</description>
</method>
<method name="get_connections_intersecting_with_rect" qualifiers="const">
<return type="Dictionary[]" />
<param index="0" name="rect" type="Rect2" />
<description>
Returns an [Array] containing the list of connections that intersect with the given [Rect2]. A connection consists in a structure of the form [code]{ from_port: 0, from_node: "GraphNode name 0", to_port: 1, to_node: "GraphNode name 1" }[/code].
Returns an [Array] containing the list of connections that intersect with the given [Rect2].
A connection is represented as a [Dictionary] in the form of:
[codeblock]
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
[/codeblock]
</description>
</method>
<method name="get_element_frame">
Expand Down Expand Up @@ -296,6 +311,20 @@
<member name="connection_lines_thickness" type="float" setter="set_connection_lines_thickness" getter="get_connection_lines_thickness" default="4.0">
The thickness of the lines between the nodes.
</member>
<member name="connections" type="Dictionary[]" setter="set_connections" getter="get_connection_list" default="[]">
The connections between [GraphNode]s.
A connection is represented as a [Dictionary] in the form of:
[codeblock]
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}
[/codeblock]
Connections with [code]keep_alive[/code] set to [code]false[/code] may be deleted automatically if invalid during a redraw.
</member>
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" overrides="Control" enum="Control.FocusMode" default="2" />
<member name="grid_pattern" type="int" setter="set_grid_pattern" getter="get_grid_pattern" enum="GraphEdit.GridPattern" default="0">
The pattern used for drawing the grid.
Expand Down
7 changes: 7 additions & 0 deletions misc/extension_api_validation/4.3-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,10 @@ Validate extension JSON: Error: Field 'classes/EditorInterface/methods/open_scen

Added optional argument to open_scene_from_path to create a new inherited scene.
Compatibility method registered.


GH-97449
--------
Validate extension JSON: Error: Field 'classes/GraphEdit/methods/connect_node/arguments': size changed value in new API, from 4 to 5.

Added optional argument to connect_node to specify whether the connection should be automatically deleted if invalid. Compatibility method registered.
5 changes: 5 additions & 0 deletions scene/gui/graph_edit.compat.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ PackedVector2Array GraphEdit::_get_connection_line_bind_compat_86158(const Vecto
return get_connection_line(p_from, p_to);
}

Error GraphEdit::_connect_node_bind_compat_97449(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
return connect_node(p_from, p_from_port, p_to, p_to_port);
}

void GraphEdit::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("is_arrange_nodes_button_hidden"), &GraphEdit::_is_arrange_nodes_button_hidden_bind_compat_81582);
ClassDB::bind_compatibility_method(D_METHOD("set_arrange_nodes_button_hidden", "enable"), &GraphEdit::_set_arrange_nodes_button_hidden_bind_compat_81582);
ClassDB::bind_compatibility_method(D_METHOD("get_connection_line", "from_node", "to_node"), &GraphEdit::_get_connection_line_bind_compat_86158);
ClassDB::bind_compatibility_method(D_METHOD("connect_node", "from_node", "from_port", "to_node", "to_port"), &GraphEdit::_connect_node_bind_compat_97449);
}

#endif
Loading

0 comments on commit e5be03a

Please sign in to comment.