Skip to content

Commit

Permalink
Merge pull request #88014 from Geometror/new-graph-frame
Browse files Browse the repository at this point in the history
Implement GraphFrame and integrate it in VisualShader
  • Loading branch information
akien-mga committed Apr 4, 2024
2 parents 7a42afb + a81561c commit a144ef5
Show file tree
Hide file tree
Showing 25 changed files with 1,985 additions and 287 deletions.
44 changes: 44 additions & 0 deletions doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
Rearranges selected nodes in a layout with minimum crossings between connections and uniform horizontal and vertical gap between nodes.
</description>
</method>
<method name="attach_graph_element_to_frame">
<return type="void" />
<param index="0" name="element" type="StringName" />
<param index="1" name="frame" type="StringName" />
<description>
Attaches the [param element] [GraphElement] to the [param frame] [GraphFrame].
</description>
</method>
<method name="clear_connections">
<return type="void" />
<description>
Expand All @@ -125,6 +133,13 @@
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.
</description>
</method>
<method name="detach_graph_element_from_frame">
<return type="void" />
<param index="0" name="element" type="StringName" />
<description>
Detaches the [param element] [GraphElement] from the [GraphFrame] it is currently attached to.
</description>
</method>
<method name="disconnect_node">
<return type="void" />
<param index="0" name="from_node" type="StringName" />
Expand All @@ -143,6 +158,13 @@
[b]Note:[/b] This method suppresses any other connection request signals apart from [signal connection_drag_ended].
</description>
</method>
<method name="get_attached_nodes_of_frame">
<return type="StringName[]" />
<param index="0" name="frame" type="StringName" />
<description>
Returns an array of node names that are attached to the [GraphFrame] with the given name.
</description>
</method>
<method name="get_closest_connection_at_point" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="point" type="Vector2" />
Expand Down Expand Up @@ -179,6 +201,13 @@
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].
</description>
</method>
<method name="get_element_frame">
<return type="GraphFrame" />
<param index="0" name="element" type="StringName" />
<description>
Returns the [GraphFrame] that contains the [GraphElement] with the given name.
</description>
</method>
<method name="get_menu_hbox">
<return type="HBoxContainer" />
<description>
Expand Down Expand Up @@ -395,6 +424,21 @@
Emitted at the end of a [GraphElement]'s movement.
</description>
</signal>
<signal name="frame_rect_changed">
<param index="0" name="frame" type="GraphFrame" />
<param index="1" name="new_rect" type="Vector2" />
<description>
Emitted when the [GraphFrame] [param frame] is resized to [param new_rect].
</description>
</signal>
<signal name="graph_elements_linked_to_frame_request">
<param index="0" name="elements" type="Array" />
<param index="1" name="frame" type="StringName" />
<description>
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.
[param elements] is an array of [GraphElement]s to be attached.
</description>
</signal>
<signal name="node_deselected">
<param index="0" name="node" type="Node" />
<description>
Expand Down
10 changes: 8 additions & 2 deletions doc/classes/GraphElement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</member>
<member name="resizable" type="bool" setter="set_resizable" getter="is_resizable" default="false">
If [code]true[/code], the user can resize the GraphElement.
[b]Note:[/b] Dragging the handle will only emit the [signal resize_request] signal, the GraphElement needs to be resized manually.
[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.
</member>
<member name="selectable" type="bool" setter="set_selectable" getter="is_selectable" default="true">
If [code]true[/code], the user can select the GraphElement.
Expand Down Expand Up @@ -59,8 +59,14 @@
Emitted when displaying the GraphElement over other ones is requested. Happens on focusing (clicking into) the GraphElement.
</description>
</signal>
<signal name="resize_end">
<param index="0" name="new_size" type="Vector2" />
<description>
Emitted when releasing the mouse button after dragging the resizer handle (see [member resizable]).
</description>
</signal>
<signal name="resize_request">
<param index="0" name="new_minsize" type="Vector2" />
<param index="0" name="new_size" type="Vector2" />
<description>
Emitted when resizing the GraphElement is requested. Happens on dragging the resizer handle (see [member resizable]).
</description>
Expand Down
66 changes: 66 additions & 0 deletions doc/classes/GraphFrame.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GraphFrame" inherits="GraphElement" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
GraphFrame is a special [GraphElement] that can be used to organize other [GraphElement]s inside a [GraphEdit].
</brief_description>
<description>
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.
A GraphFrame is always kept behind the connection layer and other [GraphElement]s inside a [GraphEdit].
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_titlebar_hbox">
<return type="HBoxContainer" />
<description>
Returns the [HBoxContainer] used for the title bar, only containing a [Label] for displaying the title by default.
This can be used to add custom controls to the title bar such as option or close buttons.
</description>
</method>
</methods>
<members>
<member name="autoshrink_enabled" type="bool" setter="set_autoshrink_enabled" getter="is_autoshrink_enabled" default="true">
If [code]true[/code], the frame's rect will be adjusted automatically to enclose all attached [GraphElement]s.
</member>
<member name="autoshrink_margin" type="int" setter="set_autoshrink_margin" getter="get_autoshrink_margin" default="40">
The margin around the attached nodes that is used to calculate the size of the frame when [member autoshrink_enabled] is [code]true[/code].
</member>
<member name="drag_margin" type="int" setter="set_drag_margin" getter="get_drag_margin" default="16">
The margin inside the frame that can be used to drag the frame.
</member>
<member name="mouse_filter" type="int" setter="set_mouse_filter" getter="get_mouse_filter" overrides="Control" enum="Control.MouseFilter" default="0" />
<member name="tint_color" type="Color" setter="set_tint_color" getter="get_tint_color" default="Color(0.3, 0.3, 0.3, 0.75)">
The color of the frame when [member tint_color_enabled] is [code]true[/code].
</member>
<member name="tint_color_enabled" type="bool" setter="set_tint_color_enabled" getter="is_tint_color_enabled" default="false">
If [code]true[/code], the tint color will be used to tint the frame.
</member>
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;&quot;">
Title of the frame.
</member>
</members>
<signals>
<signal name="autoshrink_changed">
<description>
Emitted when [member autoshrink_enabled] or [member autoshrink_margin] changes.
</description>
</signal>
</signals>
<theme_items>
<theme_item name="resizer_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 1)">
The color modulation applied to the resizer icon.
</theme_item>
<theme_item name="panel" data_type="style" type="StyleBox">
The default [StyleBox] used for the background of the [GraphFrame].
</theme_item>
<theme_item name="panel_selected" data_type="style" type="StyleBox">
The [StyleBox] used for the background of the [GraphFrame] when it is selected.
</theme_item>
<theme_item name="titlebar" data_type="style" type="StyleBox">
The [StyleBox] used for the title bar of the [GraphFrame].
</theme_item>
<theme_item name="titlebar_selected" data_type="style" type="StyleBox">
The [StyleBox] used for the title bar of the [GraphFrame] when it is selected.
</theme_item>
</theme_items>
</class>
17 changes: 17 additions & 0 deletions doc/classes/VisualShader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
Adds a new varying value node to the shader.
</description>
</method>
<method name="attach_node_to_frame">
<return type="void" />
<param index="0" name="type" type="int" enum="VisualShader.Type" />
<param index="1" name="id" type="int" />
<param index="2" name="frame" type="int" />
<description>
Attaches the given node to the given frame.
</description>
</method>
<method name="can_connect_nodes" qualifiers="const">
<return type="bool" />
<param index="0" name="type" type="int" enum="VisualShader.Type" />
Expand Down Expand Up @@ -62,6 +71,14 @@
Connects the specified nodes and ports, even if they can't be connected. Such connection is invalid and will not function properly.
</description>
</method>
<method name="detach_node_from_frame">
<return type="void" />
<param index="0" name="type" type="int" enum="VisualShader.Type" />
<param index="1" name="id" type="int" />
<description>
Detaches the given node from the frame it is attached to.
</description>
</method>
<method name="disconnect_nodes">
<return type="void" />
<param index="0" name="type" type="int" enum="VisualShader.Type" />
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/VisualShaderNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
</method>
</methods>
<members>
<member name="linked_parent_graph_frame" type="int" setter="set_frame" getter="get_frame" default="-1">
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.
</member>
<member name="output_port_for_preview" type="int" setter="set_output_port_for_preview" getter="get_output_port_for_preview" default="-1">
Sets the output port index which will be showed for preview. If set to [code]-1[/code] no port will be open for preview.
</member>
Expand Down
19 changes: 0 additions & 19 deletions doc/classes/VisualShaderNodeComment.xml

This file was deleted.

46 changes: 46 additions & 0 deletions doc/classes/VisualShaderNodeFrame.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="VisualShaderNodeFrame" inherits="VisualShaderNodeResizableBase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A frame other visual shader nodes can be attached to for better organization.
</brief_description>
<description>
A rectangular frame that can be used to group visual shader nodes together to improve organization.
Nodes attached to the frame will move with it when it is dragged and it can automatically resize to enclose all attached nodes.
Its title, description and color can be customized.
</description>
<tutorials>
</tutorials>
<methods>
<method name="add_attached_node">
<return type="void" />
<param index="0" name="node" type="int" />
<description>
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.
</description>
</method>
<method name="remove_attached_node">
<return type="void" />
<param index="0" name="node" type="int" />
<description>
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.
</description>
</method>
</methods>
<members>
<member name="attached_nodes" type="PackedInt32Array" setter="set_attached_nodes" getter="get_attached_nodes" default="PackedInt32Array()">
The list of nodes attached to the frame.
</member>
<member name="autoshrink" type="bool" setter="set_autoshrink_enabled" getter="is_autoshrink_enabled" default="true">
If [code]true[/code], the frame will automatically resize to enclose all attached nodes.
</member>
<member name="tint_color" type="Color" setter="set_tint_color" getter="get_tint_color" default="Color(0.3, 0.3, 0.3, 0.75)">
The color of the frame when [member tint_color_enabled] is [code]true[/code].
</member>
<member name="tint_color_enabled" type="bool" setter="set_tint_color_enabled" getter="is_tint_color_enabled" default="false">
If [code]true[/code], the frame will be tinted with the color specified in [member tint_color].
</member>
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;Title&quot;">
The title of the node.
</member>
</members>
</class>
1 change: 1 addition & 0 deletions editor/icons/GraphFrame.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 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("focus_exited", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out).bind(agnode), CONNECT_DEFERRED);
name->connect("text_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_rename_lineedit_changed), CONNECT_DEFERRED);
base = 1;
agnode->set_closable(true);
agnode->set_deletable(true);

if (!read_only) {
Button *delete_button = memnew(Button);
Expand Down Expand Up @@ -541,15 +541,15 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<String
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
if (gn && gn->is_selected()) {
Ref<AnimationNode> anode = blend_tree->get_node(gn->get_name());
if (anode->is_closable()) {
if (anode->is_deletable()) {
to_erase.push_back(gn->get_name());
}
}
}
} else {
for (int i = 0; i < p_nodes.size(); i++) {
Ref<AnimationNode> anode = blend_tree->get_node(p_nodes[i]);
if (anode->is_closable()) {
if (anode->is_deletable()) {
to_erase.push_back(p_nodes[i]);
}
}
Expand Down
Loading

0 comments on commit a144ef5

Please sign in to comment.