Skip to content

Commit a144ef5

Browse files
committed
Merge pull request godotengine#88014 from Geometror/new-graph-frame
Implement GraphFrame and integrate it in VisualShader
2 parents 7a42afb + a81561c commit a144ef5

25 files changed

+1985
-287
lines changed

doc/classes/GraphEdit.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@
109109
Rearranges selected nodes in a layout with minimum crossings between connections and uniform horizontal and vertical gap between nodes.
110110
</description>
111111
</method>
112+
<method name="attach_graph_element_to_frame">
113+
<return type="void" />
114+
<param index="0" name="element" type="StringName" />
115+
<param index="1" name="frame" type="StringName" />
116+
<description>
117+
Attaches the [param element] [GraphElement] to the [param frame] [GraphFrame].
118+
</description>
119+
</method>
112120
<method name="clear_connections">
113121
<return type="void" />
114122
<description>
@@ -125,6 +133,13 @@
125133
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.
126134
</description>
127135
</method>
136+
<method name="detach_graph_element_from_frame">
137+
<return type="void" />
138+
<param index="0" name="element" type="StringName" />
139+
<description>
140+
Detaches the [param element] [GraphElement] from the [GraphFrame] it is currently attached to.
141+
</description>
142+
</method>
128143
<method name="disconnect_node">
129144
<return type="void" />
130145
<param index="0" name="from_node" type="StringName" />
@@ -143,6 +158,13 @@
143158
[b]Note:[/b] This method suppresses any other connection request signals apart from [signal connection_drag_ended].
144159
</description>
145160
</method>
161+
<method name="get_attached_nodes_of_frame">
162+
<return type="StringName[]" />
163+
<param index="0" name="frame" type="StringName" />
164+
<description>
165+
Returns an array of node names that are attached to the [GraphFrame] with the given name.
166+
</description>
167+
</method>
146168
<method name="get_closest_connection_at_point" qualifiers="const">
147169
<return type="Dictionary" />
148170
<param index="0" name="point" type="Vector2" />
@@ -179,6 +201,13 @@
179201
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].
180202
</description>
181203
</method>
204+
<method name="get_element_frame">
205+
<return type="GraphFrame" />
206+
<param index="0" name="element" type="StringName" />
207+
<description>
208+
Returns the [GraphFrame] that contains the [GraphElement] with the given name.
209+
</description>
210+
</method>
182211
<method name="get_menu_hbox">
183212
<return type="HBoxContainer" />
184213
<description>
@@ -395,6 +424,21 @@
395424
Emitted at the end of a [GraphElement]'s movement.
396425
</description>
397426
</signal>
427+
<signal name="frame_rect_changed">
428+
<param index="0" name="frame" type="GraphFrame" />
429+
<param index="1" name="new_rect" type="Vector2" />
430+
<description>
431+
Emitted when the [GraphFrame] [param frame] is resized to [param new_rect].
432+
</description>
433+
</signal>
434+
<signal name="graph_elements_linked_to_frame_request">
435+
<param index="0" name="elements" type="Array" />
436+
<param index="1" name="frame" type="StringName" />
437+
<description>
438+
Emitted when one or more [GraphElement]s are dropped onto the [GraphFrame] named [param frame], when they were not previously attached to any other one.
439+
[param elements] is an array of [GraphElement]s to be attached.
440+
</description>
441+
</signal>
398442
<signal name="node_deselected">
399443
<param index="0" name="node" type="Node" />
400444
<description>

doc/classes/GraphElement.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</member>
1818
<member name="resizable" type="bool" setter="set_resizable" getter="is_resizable" default="false">
1919
If [code]true[/code], the user can resize the GraphElement.
20-
[b]Note:[/b] Dragging the handle will only emit the [signal resize_request] signal, the GraphElement needs to be resized manually.
20+
[b]Note:[/b] Dragging the handle will only emit the [signal resize_request] and [signal resize_end] signals, the GraphElement needs to be resized manually.
2121
</member>
2222
<member name="selectable" type="bool" setter="set_selectable" getter="is_selectable" default="true">
2323
If [code]true[/code], the user can select the GraphElement.
@@ -59,8 +59,14 @@
5959
Emitted when displaying the GraphElement over other ones is requested. Happens on focusing (clicking into) the GraphElement.
6060
</description>
6161
</signal>
62+
<signal name="resize_end">
63+
<param index="0" name="new_size" type="Vector2" />
64+
<description>
65+
Emitted when releasing the mouse button after dragging the resizer handle (see [member resizable]).
66+
</description>
67+
</signal>
6268
<signal name="resize_request">
63-
<param index="0" name="new_minsize" type="Vector2" />
69+
<param index="0" name="new_size" type="Vector2" />
6470
<description>
6571
Emitted when resizing the GraphElement is requested. Happens on dragging the resizer handle (see [member resizable]).
6672
</description>

doc/classes/GraphFrame.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="GraphFrame" inherits="GraphElement" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
GraphFrame is a special [GraphElement] that can be used to organize other [GraphElement]s inside a [GraphEdit].
5+
</brief_description>
6+
<description>
7+
GraphFrame is a special [GraphElement] to which other [GraphElement]s can be attached. It can be configured to automatically resize to enclose all attached [GraphElement]s. If the frame is moved, all the attached [GraphElement]s inside it will be moved as well.
8+
A GraphFrame is always kept behind the connection layer and other [GraphElement]s inside a [GraphEdit].
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
<methods>
13+
<method name="get_titlebar_hbox">
14+
<return type="HBoxContainer" />
15+
<description>
16+
Returns the [HBoxContainer] used for the title bar, only containing a [Label] for displaying the title by default.
17+
This can be used to add custom controls to the title bar such as option or close buttons.
18+
</description>
19+
</method>
20+
</methods>
21+
<members>
22+
<member name="autoshrink_enabled" type="bool" setter="set_autoshrink_enabled" getter="is_autoshrink_enabled" default="true">
23+
If [code]true[/code], the frame's rect will be adjusted automatically to enclose all attached [GraphElement]s.
24+
</member>
25+
<member name="autoshrink_margin" type="int" setter="set_autoshrink_margin" getter="get_autoshrink_margin" default="40">
26+
The margin around the attached nodes that is used to calculate the size of the frame when [member autoshrink_enabled] is [code]true[/code].
27+
</member>
28+
<member name="drag_margin" type="int" setter="set_drag_margin" getter="get_drag_margin" default="16">
29+
The margin inside the frame that can be used to drag the frame.
30+
</member>
31+
<member name="mouse_filter" type="int" setter="set_mouse_filter" getter="get_mouse_filter" overrides="Control" enum="Control.MouseFilter" default="0" />
32+
<member name="tint_color" type="Color" setter="set_tint_color" getter="get_tint_color" default="Color(0.3, 0.3, 0.3, 0.75)">
33+
The color of the frame when [member tint_color_enabled] is [code]true[/code].
34+
</member>
35+
<member name="tint_color_enabled" type="bool" setter="set_tint_color_enabled" getter="is_tint_color_enabled" default="false">
36+
If [code]true[/code], the tint color will be used to tint the frame.
37+
</member>
38+
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;&quot;">
39+
Title of the frame.
40+
</member>
41+
</members>
42+
<signals>
43+
<signal name="autoshrink_changed">
44+
<description>
45+
Emitted when [member autoshrink_enabled] or [member autoshrink_margin] changes.
46+
</description>
47+
</signal>
48+
</signals>
49+
<theme_items>
50+
<theme_item name="resizer_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 1)">
51+
The color modulation applied to the resizer icon.
52+
</theme_item>
53+
<theme_item name="panel" data_type="style" type="StyleBox">
54+
The default [StyleBox] used for the background of the [GraphFrame].
55+
</theme_item>
56+
<theme_item name="panel_selected" data_type="style" type="StyleBox">
57+
The [StyleBox] used for the background of the [GraphFrame] when it is selected.
58+
</theme_item>
59+
<theme_item name="titlebar" data_type="style" type="StyleBox">
60+
The [StyleBox] used for the title bar of the [GraphFrame].
61+
</theme_item>
62+
<theme_item name="titlebar_selected" data_type="style" type="StyleBox">
63+
The [StyleBox] used for the title bar of the [GraphFrame] when it is selected.
64+
</theme_item>
65+
</theme_items>
66+
</class>

doc/classes/VisualShader.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
Adds a new varying value node to the shader.
3030
</description>
3131
</method>
32+
<method name="attach_node_to_frame">
33+
<return type="void" />
34+
<param index="0" name="type" type="int" enum="VisualShader.Type" />
35+
<param index="1" name="id" type="int" />
36+
<param index="2" name="frame" type="int" />
37+
<description>
38+
Attaches the given node to the given frame.
39+
</description>
40+
</method>
3241
<method name="can_connect_nodes" qualifiers="const">
3342
<return type="bool" />
3443
<param index="0" name="type" type="int" enum="VisualShader.Type" />
@@ -62,6 +71,14 @@
6271
Connects the specified nodes and ports, even if they can't be connected. Such connection is invalid and will not function properly.
6372
</description>
6473
</method>
74+
<method name="detach_node_from_frame">
75+
<return type="void" />
76+
<param index="0" name="type" type="int" enum="VisualShader.Type" />
77+
<param index="1" name="id" type="int" />
78+
<description>
79+
Detaches the given node from the frame it is attached to.
80+
</description>
81+
</method>
6582
<method name="disconnect_nodes">
6683
<return type="void" />
6784
<param index="0" name="type" type="int" enum="VisualShader.Type" />

doc/classes/VisualShaderNode.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
</method>
6262
</methods>
6363
<members>
64+
<member name="linked_parent_graph_frame" type="int" setter="set_frame" getter="get_frame" default="-1">
65+
Represents the index of the frame this node is linked to. If set to [code]-1[/code] the node is not linked to any frame.
66+
</member>
6467
<member name="output_port_for_preview" type="int" setter="set_output_port_for_preview" getter="get_output_port_for_preview" default="-1">
6568
Sets the output port index which will be showed for preview. If set to [code]-1[/code] no port will be open for preview.
6669
</member>

doc/classes/VisualShaderNodeComment.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="VisualShaderNodeFrame" inherits="VisualShaderNodeResizableBase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
A frame other visual shader nodes can be attached to for better organization.
5+
</brief_description>
6+
<description>
7+
A rectangular frame that can be used to group visual shader nodes together to improve organization.
8+
Nodes attached to the frame will move with it when it is dragged and it can automatically resize to enclose all attached nodes.
9+
Its title, description and color can be customized.
10+
</description>
11+
<tutorials>
12+
</tutorials>
13+
<methods>
14+
<method name="add_attached_node">
15+
<return type="void" />
16+
<param index="0" name="node" type="int" />
17+
<description>
18+
Adds a node to the list of nodes attached to the frame. Should not be called directly, use the [method VisualShader.attach_node_to_frame] method instead.
19+
</description>
20+
</method>
21+
<method name="remove_attached_node">
22+
<return type="void" />
23+
<param index="0" name="node" type="int" />
24+
<description>
25+
Removes a node from the list of nodes attached to the frame. Should not be called directly, use the [method VisualShader.detach_node_from_frame] method instead.
26+
</description>
27+
</method>
28+
</methods>
29+
<members>
30+
<member name="attached_nodes" type="PackedInt32Array" setter="set_attached_nodes" getter="get_attached_nodes" default="PackedInt32Array()">
31+
The list of nodes attached to the frame.
32+
</member>
33+
<member name="autoshrink" type="bool" setter="set_autoshrink_enabled" getter="is_autoshrink_enabled" default="true">
34+
If [code]true[/code], the frame will automatically resize to enclose all attached nodes.
35+
</member>
36+
<member name="tint_color" type="Color" setter="set_tint_color" getter="get_tint_color" default="Color(0.3, 0.3, 0.3, 0.75)">
37+
The color of the frame when [member tint_color_enabled] is [code]true[/code].
38+
</member>
39+
<member name="tint_color_enabled" type="bool" setter="set_tint_color_enabled" getter="is_tint_color_enabled" default="false">
40+
If [code]true[/code], the frame will be tinted with the color specified in [member tint_color].
41+
</member>
42+
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;Title&quot;">
43+
The title of the node.
44+
</member>
45+
</members>
46+
</class>

editor/icons/GraphFrame.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/plugins/animation_blend_tree_editor_plugin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void AnimationNodeBlendTreeEditor::update_graph() {
170170
name->connect("focus_exited", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out).bind(agnode), CONNECT_DEFERRED);
171171
name->connect("text_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_rename_lineedit_changed), CONNECT_DEFERRED);
172172
base = 1;
173-
agnode->set_closable(true);
173+
agnode->set_deletable(true);
174174

175175
if (!read_only) {
176176
Button *delete_button = memnew(Button);
@@ -541,15 +541,15 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<String
541541
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
542542
if (gn && gn->is_selected()) {
543543
Ref<AnimationNode> anode = blend_tree->get_node(gn->get_name());
544-
if (anode->is_closable()) {
544+
if (anode->is_deletable()) {
545545
to_erase.push_back(gn->get_name());
546546
}
547547
}
548548
}
549549
} else {
550550
for (int i = 0; i < p_nodes.size(); i++) {
551551
Ref<AnimationNode> anode = blend_tree->get_node(p_nodes[i]);
552-
if (anode->is_closable()) {
552+
if (anode->is_deletable()) {
553553
to_erase.push_back(p_nodes[i]);
554554
}
555555
}

0 commit comments

Comments
 (0)