From 5afe78bd9c7e619ebc2dd2fb43d549d16382b51d Mon Sep 17 00:00:00 2001 From: Hendrik Brucker Date: Wed, 9 Aug 2023 18:31:15 +0200 Subject: [PATCH] Clean up/refactor GraphNode and make it more flexible Split GraphNode into GraphElement and GraphNode, add custom titlebar, and adjust theming. --- doc/classes/GraphEdit.xml | 18 +- doc/classes/GraphElement.xml | 69 + doc/classes/GraphNode.xml | 251 +--- editor/editor_themes.cpp | 111 +- editor/icons/GraphEdit.svg | 2 +- editor/icons/GraphElement.svg | 1 + editor/icons/GraphNode.svg | 2 +- editor/icons/GuiCloseCustomizable.svg | 1 - .../animation_blend_tree_editor_plugin.cpp | 24 +- .../animation_blend_tree_editor_plugin.h | 4 +- .../plugins/visual_shader_editor_plugin.cpp | 419 +++--- editor/plugins/visual_shader_editor_plugin.h | 22 +- .../4.1-stable.expected | 53 + scene/animation/animation_tree.cpp | 8 + scene/animation/animation_tree.h | 5 + scene/gui/graph_edit.cpp | 304 ++-- scene/gui/graph_edit.h | 18 +- scene/gui/graph_edit_arranger.cpp | 12 +- scene/gui/graph_element.cpp | 244 ++++ scene/gui/graph_element.h | 93 ++ scene/gui/graph_node.cpp | 1217 +++++++---------- scene/gui/graph_node.h | 195 +-- scene/register_scene_types.cpp | 1 + scene/resources/visual_shader.cpp | 8 + scene/resources/visual_shader.h | 4 + scene/theme/default_theme.cpp | 51 +- 26 files changed, 1600 insertions(+), 1537 deletions(-) create mode 100644 doc/classes/GraphElement.xml create mode 100644 editor/icons/GraphElement.svg delete mode 100644 editor/icons/GuiCloseCustomizable.svg create mode 100644 scene/gui/graph_element.cpp create mode 100644 scene/gui/graph_element.h diff --git a/doc/classes/GraphEdit.xml b/doc/classes/GraphEdit.xml index 0aea0c57278..baa591fd66b 100644 --- a/doc/classes/GraphEdit.xml +++ b/doc/classes/GraphEdit.xml @@ -26,12 +26,12 @@ Returns whether the [param mouse_position] is in the input hot zone. - By default, a hot zone is a [Rect2] positioned such that its center is at [param in_node].[method GraphNode.get_connection_input_position]([param in_port]) (For output's case, call [method GraphNode.get_connection_output_position] instead). The hot zone's width is twice the Theme Property [code]port_grab_distance_horizontal[/code], and its height is twice the [code]port_grab_distance_vertical[/code]. + By default, a hot zone is a [Rect2] positioned such that its center is at [param in_node].[method GraphNode.get_input_port_position]([param in_port]) (For output's case, call [method GraphNode.get_output_port_position] instead). The hot zone's width is twice the Theme Property [code]port_grab_distance_horizontal[/code], and its height is twice the [code]port_grab_distance_vertical[/code]. Below is a sample code to help get started: [codeblock] func _is_in_input_hotzone(in_node, in_port, mouse_position): var port_size: Vector2 = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical")) - var port_pos: Vector2 = in_node.get_position() + in_node.get_connection_input_position(in_port) - port_size / 2 + var port_pos: Vector2 = in_node.get_position() + in_node.get_input_port_position(in_port) - port_size / 2 var rect = Rect2(port_pos, port_size) return rect.has_point(mouse_position) @@ -49,7 +49,7 @@ [codeblock] func _is_in_output_hotzone(in_node, in_port, mouse_position): var port_size: Vector2 = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical")) - var port_pos: Vector2 = in_node.get_position() + in_node.get_connection_output_position(in_port) - port_size / 2 + var port_pos: Vector2 = in_node.get_position() + in_node.get_output_port_position(in_port) - port_size / 2 var rect = Rect2(port_pos, port_size) return rect.has_point(mouse_position) @@ -289,6 +289,12 @@ Emitted at the beginning of a GraphNode movement. + + + + 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). + + Emitted at the end of a connection drag. @@ -332,12 +338,6 @@ Emitted when the user presses [kbd]Ctrl + C[/kbd]. - - - - 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). - - diff --git a/doc/classes/GraphElement.xml b/doc/classes/GraphElement.xml new file mode 100644 index 00000000000..6c3b6b727a9 --- /dev/null +++ b/doc/classes/GraphElement.xml @@ -0,0 +1,69 @@ + + + + A container that represents a basic element that can be placed inside a [GraphEdit] control. + + + [GraphElement] allows to create custom elements for a [GraphEdit] graph. By default such elements can be selected, resized, and repositioned, but they cannot be connected. For a graph element that allows for connections see [GraphNode]. + + + + + + If [code]true[/code], the user can drag the GraphElement. + + + The offset of the GraphElement, relative to the scroll offset of the [GraphEdit]. + + + 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. + + + If [code]true[/code], the user can select the GraphElement. + + + If [code]true[/code], the GraphElement is selected. + + + + + + Emitted when closing the GraphElement is requested. + + + + + + + Emitted when the GraphElement is dragged. + + + + + Emitted when the GraphElement is deselected. + + + + + Emitted when the GraphElement is selected. + + + + + Emitted when the GraphElement is moved. + + + + + Emitted when displaying the GraphElement over other ones is requested. Happens on focusing (clicking into) the GraphElement. + + + + + + Emitted when resizing the GraphElement is requested. Happens on dragging the resizer handle (see [member resizable]). + + + + diff --git a/doc/classes/GraphNode.xml b/doc/classes/GraphNode.xml index d1601418426..5d52ea17e24 100644 --- a/doc/classes/GraphNode.xml +++ b/doc/classes/GraphNode.xml @@ -1,5 +1,5 @@ - + A container with connection ports, representing a node in a [GraphEdit]. @@ -7,153 +7,154 @@ [GraphNode] allows to create nodes for a [GraphEdit] graph with customizable content based on its child controls. [GraphNode] is derived from [Container] and it is responsible for placing its children on screen. This works similar to [VBoxContainer]. Children, in turn, provide [GraphNode] with so-called slots, each of which can have a connection port on either side. Each [GraphNode] slot is defined by its index and can provide the node with up to two ports: one on the left, and one on the right. By convention the left port is also referred to as the [b]input port[/b] and the right port is referred to as the [b]output port[/b]. Each port can be enabled and configured individually, using different type and color. The type is an arbitrary value that you can define using your own considerations. The parent [GraphEdit] will receive this information on each connect and disconnect request. Slots can be configured in the Inspector dock once you add at least one child [Control]. The properties are grouped by each slot's index in the "Slot" section. - [b]Note:[/b] While GraphNode is set up using slots and slot indices, connections are made between the ports which are enabled. Because of that, [GraphEdit] uses the port's index and not the slot's index. You can use [method get_connection_input_slot] and [method get_connection_output_slot] to get the slot index from the port index. + [b]Note:[/b] While GraphNode is set up using slots and slot indices, connections are made between the ports which are enabled. Because of that [GraphEdit] uses the port's index and not the slot's index. You can use [method get_input_port_slot] and [method get_output_port_slot] to get the slot index from the port index. + + + + + + + + + - Disables all input and output slots of the GraphNode. + Disables all slots of the GraphNode. This will remove all input/output ports from the GraphNode. - Disables input and output slot whose index is [param slot_index]. + Disables the slot with the given [param slot_index]. This will remove the corresponding input and output port from the GraphNode. - + - + - Returns the [Color] of the input connection [param port]. + Returns the [Color] of the input port with the given [param port_idx]. - + - Returns the number of enabled input slots (connections) to the GraphNode. + Returns the number of slots with an enabled input port. - - - - - Returns the height of the input connection [param port]. - - - + - + - Returns the position of the input connection [param port]. + Returns the position of the input port with the given [param port_idx]. - + - + - Returns the corresponding slot index of the input connection [param port]. + Returns the corresponding slot index of the input port with the given [param port_idx]. - + - + - Returns the type of the input connection [param port]. + Returns the type of the input port with the given [param port_idx]. - + - + - Returns the [Color] of the output connection [param port]. + Returns the [Color] of the output port with the given [param port_idx]. - + - Returns the number of enabled output slots (connections) of the GraphNode. + Returns the number of slots with an enabled output port. - - - - - Returns the height of the output connection [param port]. - - - + - + - Returns the position of the output connection [param port]. + Returns the position of the output port with the given [param port_idx]. - + - + - Returns the corresponding slot index of the output connection [param port]. + Returns the corresponding slot index of the output port with the given [param port_idx]. - + - + - Returns the type of the output connection [param port]. + Returns the type of the output port with the given [param port_idx]. - Returns the left (input) [Color] of the slot [param slot_index]. + Returns the left (input) [Color] of the slot with the given [param slot_index]. - Returns the right (output) [Color] of the slot [param slot_index]. + Returns the right (output) [Color] of the slot with the given [param slot_index]. - Returns the left (input) type of the slot [param slot_index]. + Returns the left (input) type of the slot with the given [param slot_index]. - Returns the right (output) type of the slot [param slot_index]. + Returns the right (output) type of the slot with the given [param slot_index]. + + + + + + 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. - Returns true if the background [StyleBox] of the slot [param slot_index] is drawn. + Returns true if the background [StyleBox] of the slot with the given [param slot_index] is drawn. - Returns [code]true[/code] if left (input) side of the slot [param slot_index] is enabled. + Returns [code]true[/code] if left (input) side of the slot with the given [param slot_index] is enabled. - Returns [code]true[/code] if right (output) side of the slot [param slot_index] is enabled. + Returns [code]true[/code] if right (output) side of the slot with the given [param slot_index] is enabled. @@ -169,7 +170,7 @@ - Sets properties of the slot with the [param slot_index] index. + Sets properties of the slot with the given [param slot_index]. If [param enable_left_port]/[param enable_right_port] is [code]true[/code], a port will appear and the slot will be able to be connected from this side. With [param type_left]/[param type_right] an arbitrary type can be assigned to each port. Two ports can be connected if they share the same type, or if the connection between their types is allowed in the parent [GraphEdit] (see [method GraphEdit.add_valid_connection_type]). Keep in mind that the [GraphEdit] has the final say in accepting the connection. Type compatibility simply allows the [signal GraphEdit.connection_request] signal to be emitted. Ports can be further customized using [param color_left]/[param color_right] and [param custom_icon_left]/[param custom_icon_right]. The color parameter adds a tint to the icon. The custom icon can be used to override the default port dot. @@ -183,7 +184,7 @@ - Sets the [Color] of the left (input) side of the slot [param slot_index] to [param color]. + Sets the [Color] of the left (input) side of the slot with the given [param slot_index] to [param color]. @@ -191,7 +192,7 @@ - Sets the [Color] of the right (output) side of the slot [param slot_index] to [param color]. + Sets the [Color] of the right (output) side of the slot with the given [param slot_index] to [param color]. @@ -199,7 +200,7 @@ - Toggles the background [StyleBox] of the slot [param slot_index]. + Toggles the background [StyleBox] of the slot with the given [param slot_index]. @@ -207,7 +208,7 @@ - Toggles the left (input) side of the slot [param slot_index]. If [param enable] is [code]true[/code], a port will appear on the left side and the slot will be able to be connected from this side. + Toggles the left (input) side of the slot with the given [param slot_index]. If [param enable] is [code]true[/code], a port will appear on the left side and the slot will be able to be connected from this side. @@ -215,7 +216,7 @@ - Toggles the right (output) side of the slot [param slot_index]. If [param enable] is [code]true[/code], a port will appear on the right side and the slot will be able to be connected from this side. + Toggles the right (output) side of the slot with the given [param slot_index]. If [param enable] is [code]true[/code], a port will appear on the right side and the slot will be able to be connected from this side. @@ -223,7 +224,7 @@ - Sets the left (input) type of the slot [param slot_index] to [param type]. If the value is negative, all connections will be disallowed to be created via user inputs. + Sets the left (input) type of the slot with the given [param slot_index] to [param type]. If the value is negative, all connections will be disallowed to be created via user inputs. @@ -231,156 +232,54 @@ - Sets the right (output) type of the slot [param slot_index] to [param type]. If the value is negative, all connections will be disallowed to be created via user inputs. + Sets the right (output) type of the slot with the given [param slot_index] to [param type]. If the value is negative, all connections will be disallowed to be created via user inputs. - - If [code]true[/code], the user can drag the GraphNode. - - - Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. - - - Sets the overlay shown above the GraphNode. See [enum Overlay]. - - - The offset of the GraphNode, relative to the scroll offset of the [GraphEdit]. - [b]Note:[/b] You cannot use position offset directly, as [GraphEdit] is a [Container]. - - - If [code]true[/code], the user can resize the GraphNode. - [b]Note:[/b] Dragging the handle will only emit the [signal resize_request] signal, the GraphNode needs to be resized manually. - - - If [code]true[/code], the user can select the GraphNode. - - - If [code]true[/code], the GraphNode is selected. - - - If [code]true[/code], the close button will be visible. - [b]Note:[/b] Pressing it will only emit the [signal close_request] signal, the GraphNode needs to be removed manually. - - - Base text writing direction. - The text displayed in the GraphNode's title bar. - - - Emitted when the GraphNode is requested to be closed. Happens on clicking the close button (see [member show_close]). - - - - - - - Emitted when the GraphNode is dragged. - - - - - Emitted when the GraphNode is deselected. - - - - - Emitted when the GraphNode is selected. - - - - - Emitted when the GraphNode is moved. - - - - - Emitted when the GraphNode is requested to be displayed over other ones. Happens on focusing (clicking into) the GraphNode. - - - - - - Emitted when the GraphNode is requested to be resized. Happens on dragging the resizer handle (see [member resizable]). - - - + Emitted when any GraphNode's slot is updated. - - - No overlay is shown. - - - Show overlay set in the [theme_item breakpoint] theme property. - - - Show overlay set in the [theme_item position] theme property. - - - - The color modulation applied to the close button icon. - The color modulation applied to the resizer icon. - - Color of the title text. - - - - - The vertical offset of the close button. - - + Horizontal offset for the ports. The vertical distance between ports. - - Horizontal offset of the title text. - - - Vertical offset of the title text. - - - Font used for the title text. - - - The icon for the close button, visible when [member show_close] is enabled. - The icon used for representing ports. - The icon used for resizer, visible when [member resizable] is enabled. + The icon used for the resizer, visible when [member GraphElement.resizable] is enabled. - - The background used when [member overlay] is set to [constant OVERLAY_BREAKPOINT]. + + The default background for the slot area of the [GraphNode]. - - The default background for [GraphNode]. - - - The background used when [member overlay] is set to [constant OVERLAY_POSITION]. - - - The background used when the [GraphNode] is selected. + + The [StyleBox] used for the slot area when selected. The [StyleBox] used for each slot of the [GraphNode]. + + The [StyleBox] used for the title bar of the [GraphNode]. + + + The [StyleBox] used for the title bar of the [GraphNode] when it is selected. + diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index f605c44dd0e..311e532e637 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -1830,8 +1830,8 @@ Ref create_editor_theme(const Ref p_theme) { // GraphEdit theme->set_stylebox("panel", "GraphEdit", style_tree_bg); if (dark_theme) { - theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.15)); - theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.07)); + theme->set_color("grid_major", "GraphEdit", Color(1.0, 1.0, 1.0, 0.1)); + theme->set_color("grid_minor", "GraphEdit", Color(1.0, 1.0, 1.0, 0.05)); } else { theme->set_color("grid_major", "GraphEdit", Color(0.0, 0.0, 0.0, 0.15)); theme->set_color("grid_minor", "GraphEdit", Color(0.0, 0.0, 0.0, 0.07)); @@ -1866,6 +1866,7 @@ Ref create_editor_theme(const Ref p_theme) { style_minimap_node = make_flat_stylebox(Color(0, 0, 0), 0, 0, 0, 0); } style_minimap_camera->set_border_width_all(1); + style_minimap_node->set_anti_aliased(false); theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera); theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node); @@ -1879,38 +1880,43 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color); // GraphNode + + const int gn_margin_top = 2; const int gn_margin_side = 2; const int gn_margin_bottom = 2; - // StateMachine - const int sm_margin_side = 10; - Color graphnode_bg = dark_color_3; if (!dark_theme) { graphnode_bg = prop_section_color; } + const Color graph_node_selected_border_color = graphnode_bg.lerp(accent_color, 0.275); - Ref graphsb = make_flat_stylebox(graphnode_bg.lerp(style_tree_bg->get_bg_color(), 0.3), gn_margin_side, 24, gn_margin_side, gn_margin_bottom, corner_width); - graphsb->set_border_width_all(border_width); - graphsb->set_border_color(graphnode_bg); - Ref graphsbselected = make_flat_stylebox(graphnode_bg * Color(1, 1, 1, 1), gn_margin_side, 24, gn_margin_side, gn_margin_bottom, corner_width); - graphsbselected->set_border_width_all(2 * EDSCALE + border_width); - graphsbselected->set_border_color(Color(accent_color.r, accent_color.g, accent_color.b, 0.6)); - Ref graphsbcomment = make_flat_stylebox(graphnode_bg * Color(1, 1, 1, 0.3), gn_margin_side, 24, gn_margin_side, gn_margin_bottom, corner_width); - graphsbcomment->set_border_width_all(border_width); - graphsbcomment->set_border_color(graphnode_bg); - Ref graphsbcommentselected = make_flat_stylebox(graphnode_bg * Color(1, 1, 1, 0.4), gn_margin_side, 24, gn_margin_side, gn_margin_bottom, corner_width); - graphsbcommentselected->set_border_width_all(border_width); - graphsbcommentselected->set_border_color(graphnode_bg); - Ref graphsbbreakpoint = graphsbselected->duplicate(); - graphsbbreakpoint->set_draw_center(false); - graphsbbreakpoint->set_border_color(warning_color); - graphsbbreakpoint->set_shadow_color(warning_color * Color(1.0, 1.0, 1.0, 0.1)); - Ref graphsbposition = graphsbselected->duplicate(); - graphsbposition->set_draw_center(false); - graphsbposition->set_border_color(error_color); - graphsbposition->set_shadow_color(error_color * Color(1.0, 1.0, 1.0, 0.2)); - Ref graphsbslot = make_empty_stylebox(12, 0, 12, 0); + const Color graphnode_frame_bg = graphnode_bg.lerp(style_tree_bg->get_bg_color(), 0.3); + + Ref graphn_sb_panel = make_flat_stylebox(graphnode_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, corner_width); + graphn_sb_panel->set_border_width_all(border_width); + graphn_sb_panel->set_border_color(graphnode_bg); + graphn_sb_panel->set_corner_radius_individual(0, 0, corner_radius * EDSCALE, corner_radius * EDSCALE); + graphn_sb_panel->set_expand_margin(SIDE_TOP, 17 * EDSCALE); + + Ref graphn_sb_panel_selected = make_flat_stylebox(graphnode_frame_bg, gn_margin_side, gn_margin_top, gn_margin_side, gn_margin_bottom, corner_width); + graphn_sb_panel_selected->set_border_width_all(2 * EDSCALE + border_width); + graphn_sb_panel_selected->set_border_color(graph_node_selected_border_color); + graphn_sb_panel_selected->set_corner_radius_individual(0, 0, corner_radius * EDSCALE, corner_radius * EDSCALE); + graphn_sb_panel_selected->set_expand_margin(SIDE_TOP, 17 * EDSCALE); + + const int gn_titlebar_margin_side = 12; + Ref graphn_sb_titlebar = make_flat_stylebox(graphnode_bg, gn_titlebar_margin_side, gn_margin_top, gn_titlebar_margin_side, 0, corner_width); + graphn_sb_titlebar->set_expand_margin(SIDE_TOP, 2 * EDSCALE); + graphn_sb_titlebar->set_corner_radius_individual(corner_radius * EDSCALE, corner_radius * EDSCALE, 0, 0); + + Ref graphn_sb_titlebar_selected = make_flat_stylebox(graph_node_selected_border_color, gn_titlebar_margin_side, gn_margin_top, gn_titlebar_margin_side, 0, corner_width); + graphn_sb_titlebar_selected->set_corner_radius_individual(corner_radius * EDSCALE, corner_radius * EDSCALE, 0, 0); + graphn_sb_titlebar_selected->set_expand_margin(SIDE_TOP, 2 * EDSCALE); + Ref graphn_sb_slot = make_empty_stylebox(12, 0, 12, 0); + + // StateMachine. + const int sm_margin_side = 10; Ref smgraphsb = make_flat_stylebox(dark_color_3 * Color(1, 1, 1, 0.7), sm_margin_side, 24, sm_margin_side, gn_margin_bottom, corner_width); smgraphsb->set_border_width_all(border_width); smgraphsb->set_border_color(graphnode_bg); @@ -1920,45 +1926,42 @@ Ref create_editor_theme(const Ref p_theme) { smgraphsbselected->set_shadow_size(8 * EDSCALE); smgraphsbselected->set_shadow_color(shadow_color); - graphsb->set_border_width(SIDE_TOP, 24 * EDSCALE); - graphsbselected->set_border_width(SIDE_TOP, 24 * EDSCALE); - graphsbcomment->set_border_width(SIDE_TOP, 24 * EDSCALE); - graphsbcommentselected->set_border_width(SIDE_TOP, 24 * EDSCALE); + theme->set_stylebox("panel", "GraphElement", graphn_sb_panel); + theme->set_stylebox("panel_selected", "GraphElement", graphn_sb_panel_selected); + theme->set_stylebox("titlebar", "GraphElement", graphn_sb_titlebar); + theme->set_stylebox("titlebar_selected", "GraphElement", graphn_sb_titlebar_selected); - graphsb->set_corner_detail(corner_radius * EDSCALE); - graphsbselected->set_corner_detail(corner_radius * EDSCALE); - graphsbcomment->set_corner_detail(corner_radius * EDSCALE); - graphsbcommentselected->set_corner_detail(corner_radius * EDSCALE); + // GraphNode's title Label. + theme->set_type_variation("GraphNodeTitleLabel", "Label"); - theme->set_stylebox("frame", "GraphNode", graphsb); - theme->set_stylebox("selected_frame", "GraphNode", graphsbselected); - theme->set_stylebox("breakpoint", "GraphNode", graphsbbreakpoint); - theme->set_stylebox("position", "GraphNode", graphsbposition); - theme->set_stylebox("slot", "GraphNode", graphsbslot); - theme->set_stylebox("state_machine_frame", "GraphNode", smgraphsb); - theme->set_stylebox("state_machine_selected_frame", "GraphNode", smgraphsbselected); + theme->set_stylebox("normal", "GraphNodeTitleLabel", make_empty_stylebox(0, 0, 0, 0)); + theme->set_color("font_color", "GraphNodeTitleLabel", font_color); + theme->set_constant("line_spacing", "GraphNodeTitleLabel", 3 * EDSCALE); - Color node_decoration_color = dark_color_1.inverted(); - theme->set_color("title_color", "GraphNode", node_decoration_color); - node_decoration_color.a = 0.7; - theme->set_color("close_color", "GraphNode", node_decoration_color); - theme->set_color("resizer_color", "GraphNode", node_decoration_color); + Color graphnode_decoration_color = dark_color_1.inverted(); - theme->set_constant("port_offset", "GraphNode", 0); - theme->set_constant("title_h_offset", "GraphNode", 12 * EDSCALE); - theme->set_constant("title_offset", "GraphNode", 21 * EDSCALE); - theme->set_constant("close_h_offset", "GraphNode", -2 * EDSCALE); - theme->set_constant("close_offset", "GraphNode", 20 * EDSCALE); + theme->set_color("resizer_color", "GraphElement", graphnode_decoration_color); + theme->set_icon("resizer", "GraphElement", theme->get_icon(SNAME("GuiResizer"), EditorStringName(EditorIcons))); + + // GraphNode. + theme->set_stylebox("panel", "GraphNode", graphn_sb_panel); + theme->set_stylebox("panel_selected", "GraphNode", graphn_sb_panel_selected); + theme->set_stylebox("titlebar", "GraphNode", graphn_sb_titlebar); + theme->set_stylebox("titlebar_selected", "GraphNode", graphn_sb_titlebar_selected); + theme->set_stylebox("slot", "GraphNode", graphn_sb_slot); + + theme->set_color("resizer_color", "GraphNode", graphnode_decoration_color); + + theme->set_constant("port_h_offset", "GraphNode", 0); theme->set_constant("separation", "GraphNode", 1 * EDSCALE); - theme->set_icon("close", "GraphNode", theme->get_icon(SNAME("GuiCloseCustomizable"), EditorStringName(EditorIcons))); - theme->set_icon("resizer", "GraphNode", theme->get_icon(SNAME("GuiResizer"), EditorStringName(EditorIcons))); Ref port_icon = theme->get_icon(SNAME("GuiGraphNodePort"), EditorStringName(EditorIcons)); // The true size is 24x24 This is necessary for sharp port icons at high zoom levels in GraphEdit (up to ~200%). port_icon->set_size_override(Size2(12, 12)); theme->set_icon("port", "GraphNode", port_icon); - theme->set_font("title_font", "GraphNode", theme->get_font(SNAME("main_bold_msdf"), EditorStringName(EditorFonts))); + theme->set_stylebox("state_machine_frame", "GraphNode", smgraphsb); + theme->set_stylebox("state_machine_selected_frame", "GraphNode", smgraphsbselected); // GridContainer theme->set_constant("v_separation", "GridContainer", Math::round(widget_default_margin.y - 2 * EDSCALE)); diff --git a/editor/icons/GraphEdit.svg b/editor/icons/GraphEdit.svg index b5b21a084e6..fd633a4662b 100644 --- a/editor/icons/GraphEdit.svg +++ b/editor/icons/GraphEdit.svg @@ -1 +1 @@ - + diff --git a/editor/icons/GraphElement.svg b/editor/icons/GraphElement.svg new file mode 100644 index 00000000000..5629993c255 --- /dev/null +++ b/editor/icons/GraphElement.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/GraphNode.svg b/editor/icons/GraphNode.svg index 31316ea32c2..9bef701ffdf 100644 --- a/editor/icons/GraphNode.svg +++ b/editor/icons/GraphNode.svg @@ -1 +1 @@ - + diff --git a/editor/icons/GuiCloseCustomizable.svg b/editor/icons/GuiCloseCustomizable.svg deleted file mode 100644 index 81822a3aaf7..00000000000 --- a/editor/icons/GuiCloseCustomizable.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index f45b160944c..ac3be4ba847 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -169,8 +169,8 @@ 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; - node->set_show_close_button(true); - node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_request).bind(E), CONNECT_DEFERRED); + agnode->set_closable(true); + node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_close_request).bind(E), CONNECT_DEFERRED); } for (int i = 0; i < agnode->get_input_count(); i++) { @@ -263,7 +263,7 @@ void AnimationNodeBlendTreeEditor::update_graph() { mb->get_popup()->connect("index_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected).bind(options, E), CONNECT_DEFERRED); } - Ref sb = node->get_theme_stylebox(SNAME("frame"), SNAME("GraphNode")); + Ref sb = node->get_theme_stylebox(SNAME("panel"), SNAME("GraphNode")); Color c = sb->get_border_color(); Color mono_color = ((c.r + c.g + c.b) / 3) < 0.7 ? Color(1.0, 1.0, 1.0) : Color(0.0, 0.0, 0.0); mono_color.a = 0.85; @@ -498,7 +498,7 @@ void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options, undo_redo->commit_action(); } -void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) { +void AnimationNodeBlendTreeEditor::_close_request(const String &p_which) { if (read_only) { return; } @@ -522,7 +522,7 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) { undo_redo->commit_action(); } -void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray &p_nodes) { +void AnimationNodeBlendTreeEditor::_close_nodes_request(const TypedArray &p_nodes) { if (read_only) { return; } @@ -532,15 +532,19 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArrayget_child_count(); i++) { GraphNode *gn = Object::cast_to(graph->get_child(i)); - if (gn) { - if (gn->is_selected() && gn->is_close_button_visible()) { + if (gn && gn->is_selected()) { + Ref anode = blend_tree->get_node(gn->get_name()); + if (anode->is_closable()) { to_erase.push_back(gn->get_name()); } } } } else { for (int i = 0; i < p_nodes.size(); i++) { - to_erase.push_back(p_nodes[i]); + Ref anode = blend_tree->get_node(p_nodes[i]); + if (anode->is_closable()) { + to_erase.push_back(p_nodes[i]); + } } } @@ -552,7 +556,7 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArraycreate_action(TTR("Delete Node(s)")); for (const StringName &F : to_erase) { - _delete_request(F); + _close_request(F); } undo_redo->commit_action(); @@ -1083,7 +1087,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("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request)); + graph->connect("close_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_close_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)); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index 90fb42cd7ac..49c8d951efc 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -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 _delete_request(const String &p_which); - void _delete_nodes_request(const TypedArray &p_nodes); + void _close_request(const String &p_which); + void _close_nodes_request(const TypedArray &p_nodes); bool _update_filters(const Ref &anode); void _inspect_filters(const String &p_which); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index b6330bdf753..8e1862d88b1 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -144,22 +144,26 @@ void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p bool is_dirty = link.preview_pos < 0; if (!is_dirty && link.preview_visible && link.preview_box != nullptr) { - link.graph_node->remove_child(link.preview_box); + link.graph_element->remove_child(link.preview_box); memdelete(link.preview_box); link.preview_box = nullptr; - link.graph_node->reset_size(); + link.graph_element->reset_size(); link.preview_visible = false; } if (p_port_id != -1 && link.output_ports[p_port_id].preview_button != nullptr) { if (is_dirty) { - link.preview_pos = link.graph_node->get_child_count(); + link.preview_pos = link.graph_element->get_child_count(); } VBoxContainer *vbox = memnew(VBoxContainer); - link.graph_node->add_child(vbox); - link.graph_node->move_child(vbox, link.preview_pos); - link.graph_node->set_slot_draw_stylebox(vbox->get_index(), false); + link.graph_element->add_child(vbox); + link.graph_element->move_child(vbox, link.preview_pos); + + GraphNode *graph_node = Object::cast_to(link.graph_element); + if (graph_node) { + graph_node->set_slot_draw_stylebox(vbox->get_index(false), false); + } Control *offset = memnew(Control); offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE)); @@ -293,7 +297,7 @@ void VisualShaderGraphPlugin::update_node_size(int p_node_id) { if (!links.has(p_node_id)) { return; } - links[p_node_id].graph_node->reset_size(); + links[p_node_id].graph_element->reset_size(); } void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p_port_id, Button *p_button) { @@ -324,7 +328,7 @@ VisualShader::Type VisualShaderGraphPlugin::get_shader_type() const { void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) { if (visual_shader->get_shader_type() == p_type && links.has(p_id)) { - links[p_id].graph_node->set_position_offset(p_position); + links[p_id].graph_element->set_position_offset(p_position); } } @@ -336,8 +340,8 @@ void VisualShaderGraphPlugin::clear_links() { links.clear(); } -void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) { - links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, HashMap(), HashMap(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); +void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphElement *p_graph_element) { + links.insert(p_id, { p_type, p_visual_node, p_graph_element, p_visual_node->get_output_port_for_preview() != -1, -1, HashMap(), HashMap(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); } void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) { @@ -415,42 +419,49 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool // Visual shader specific theme for MSDF font. Ref vstheme; vstheme.instantiate(); - Ref label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", EditorStringName(EditorFonts)); + Ref label_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_msdf", EditorStringName(EditorIcons)); + Ref label_bold_font = EditorNode::get_singleton()->get_editor_theme()->get_font("main_bold_msdf", EditorStringName(EditorIcons)); vstheme->set_font("font", "Label", label_font); + vstheme->set_font("font", "GraphNodeTitleLabel", label_bold_font); vstheme->set_font("font", "LineEdit", label_font); vstheme->set_font("font", "Button", label_font); Ref vsnode = visual_shader->get_node(p_type, p_id); - Ref resizable_node = Object::cast_to(vsnode.ptr()); - bool is_resizable = !resizable_node.is_null(); + Ref resizable_node = vsnode; + bool is_resizable = resizable_node.is_valid(); Size2 size = Size2(0, 0); - Ref group_node = Object::cast_to(vsnode.ptr()); - bool is_group = !group_node.is_null(); + Ref group_node = vsnode; + bool is_group = group_node.is_valid(); - Ref comment_node = Object::cast_to(vsnode.ptr()); + Ref comment_node = vsnode; bool is_comment = comment_node.is_valid(); - Ref expression_node = Object::cast_to(group_node.ptr()); - bool is_expression = !expression_node.is_null(); + Ref expression_node = group_node; + bool is_expression = expression_node.is_valid(); String expression = ""; - VisualShaderNodeCustom *custom_node = Object::cast_to(vsnode.ptr()); - if (custom_node) { + Ref custom_node = vsnode; + if (custom_node.is_valid()) { custom_node->_set_initialized(true); } - // Create graph node. GraphNode *node = memnew(GraphNode); + node->set_title(vsnode->get_caption()); + + // 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); + } graph->add_child(node); node->set_theme(vstheme); - editor->_update_created_node(node); if (p_just_update) { Link &link = links[p_id]; - link.graph_node = node; + link.graph_element = node; link.preview_box = nullptr; link.preview_pos = -1; link.output_ports.clear(); @@ -474,19 +485,18 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool } node->set_position_offset(visual_shader->get_node_position(p_type, p_id)); - node->set_title(vsnode->get_caption()); - node->set_name(itos(p_id)); - if (p_id >= 2) { - node->set_show_close_button(true); - node->connect("close_request", callable_mp(editor, &VisualShaderEditor::_delete_node_request).bind(p_type, p_id), CONNECT_DEFERRED); - } + node->set_name(itos(p_id)); node->connect("dragged", callable_mp(editor, &VisualShaderEditor::_node_dragged).bind(p_id)); Control *custom_editor = nullptr; int port_offset = 1; + if (is_resizable) { + editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size); + } + Control *content_offset = memnew(Control); content_offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE)); node->add_child(content_offset); @@ -495,10 +505,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool port_offset += 1; } - if (is_resizable) { - editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size); - } - Ref emit = vsnode; if (emit.is_valid()) { node->set_custom_minimum_size(Size2(200 * EDSCALE, 0)); @@ -608,7 +614,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool if (custom_editor) { if (is_curve || (hb == nullptr && !vsnode->is_use_prop_slots() && (vsnode->get_output_port_count() == 0 || vsnode->get_output_port_name(0) == "") && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == ""))) { - //will be embedded in first port + // Will be embedded in first port. } else { port_offset++; node->add_child(custom_editor); @@ -896,93 +902,97 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool if (!is_first_hbox) { idx = i + port_offset; } - node->set_slot(idx, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]); + if (!is_comment) { + GraphNode *graph_node = Object::cast_to(node); - if (vsnode->_is_output_port_expanded(i)) { - switch (vsnode->get_output_port_type(i)) { - case VisualShaderNode::PORT_TYPE_VECTOR_2D: { - port_offset++; - valid_left = (i + 1) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 1); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); - port_offset++; + graph_node->set_slot(idx, valid_left, port_left, type_color[port_left], valid_right, port_right, type_color[port_right]); - valid_left = (i + 2) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 2); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); + if (vsnode->_is_output_port_expanded(i)) { + switch (vsnode->get_output_port_type(i)) { + case VisualShaderNode::PORT_TYPE_VECTOR_2D: { + port_offset++; + valid_left = (i + 1) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 1); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); + port_offset++; - expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_2D; - } break; - case VisualShaderNode::PORT_TYPE_VECTOR_3D: { - port_offset++; - valid_left = (i + 1) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 1); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); - port_offset++; + valid_left = (i + 2) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 2); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); - valid_left = (i + 2) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 2); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); - port_offset++; + expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_2D; + } break; + case VisualShaderNode::PORT_TYPE_VECTOR_3D: { + port_offset++; + valid_left = (i + 1) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 1); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); + port_offset++; - valid_left = (i + 3) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 3); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]); + valid_left = (i + 2) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 2); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); + port_offset++; - expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_3D; - } break; - case VisualShaderNode::PORT_TYPE_VECTOR_4D: { - port_offset++; - valid_left = (i + 1) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 1); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); - port_offset++; + valid_left = (i + 3) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 3); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]); - valid_left = (i + 2) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 2); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); - port_offset++; + expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_3D; + } break; + case VisualShaderNode::PORT_TYPE_VECTOR_4D: { + port_offset++; + valid_left = (i + 1) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 1); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[0]); + port_offset++; - valid_left = (i + 3) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 3); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]); - port_offset++; + valid_left = (i + 2) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 2); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[1]); + port_offset++; - valid_left = (i + 4) < vsnode->get_input_port_count(); - port_left = VisualShaderNode::PORT_TYPE_SCALAR; - if (valid_left) { - port_left = vsnode->get_input_port_type(i + 4); - } - node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[3]); + valid_left = (i + 3) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 3); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[2]); + port_offset++; - expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_4D; - } break; - default: - break; + valid_left = (i + 4) < vsnode->get_input_port_count(); + port_left = VisualShaderNode::PORT_TYPE_SCALAR; + if (valid_left) { + port_left = vsnode->get_input_port_type(i + 4); + } + graph_node->set_slot(i + port_offset, valid_left, port_left, type_color[port_left], true, VisualShaderNode::PORT_TYPE_SCALAR, vector_expanded_color[3]); + + expanded_type = VisualShaderNode::PORT_TYPE_VECTOR_4D; + } break; + default: + break; + } } } } @@ -1005,6 +1015,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool Label *error_label = memnew(Label); error_label->add_theme_color_override("font_color", editor->get_theme_color(SNAME("error_color"), EditorStringName(Editor))); error_label->set_text(error); + error_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD); node->add_child(error_label); } @@ -1061,16 +1072,13 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool expression_box->connect("focus_exited", callable_mp(editor, &VisualShaderEditor::_expression_focus_out).bind(expression_box, p_id)); } - - if (is_comment) { - graph->move_child(node, 0); // to prevents a bug where comment node overlaps its content - } } void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id, bool p_just_update) { if (visual_shader->get_shader_type() == p_type && links.has(p_id)) { - links[p_id].graph_node->get_parent()->remove_child(links[p_id].graph_node); - memdelete(links[p_id].graph_node); + Node *graph_edit_node = links[p_id].graph_element->get_parent(); + graph_edit_node->remove_child(links[p_id].graph_element); + memdelete(links[p_id].graph_element); if (!p_just_update) { links.erase(p_id); } @@ -1374,7 +1382,7 @@ void VisualShaderEditor::_update_custom_script(const Ref