Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GraphNode

继承: GraphElement < Container < Control < CanvasItem < Node < Object

带有连接端口的容器,代表 GraphEdit 中的一个节点。

描述

GraphNode 能够在 GraphEdit 图中创建节点,节点会根据其子控件定制内容。GraphNode 派生自 Container,负责将其子节点放置在屏幕上。工作原理类似于 VBoxContainer。而子节点为 GraphNode 提供所谓的插槽,每个插槽的两侧都可以有一个连接端口。

GraphNode 的插槽由其索引定义,一个插槽可以为节点提供最多两个端口:一个在左侧,一个在右侧。根据惯例,左侧端口也被称为输入端口,右侧端口被称为输出端口。每个端口都可以单独启用和配置,使用不同的类型和颜色。类型是你按照自己的需要来定义的任意值。父 GraphEdit 将在每个连接和断开连接请求中收到此信息。

添加至少一个子 Control 后,就可以在“检查器”面板中配置插槽。这些属性在“Slot”部分中按每个插槽的索引进行分组。

注意:虽然 GraphNode 是使用插槽和插槽索引设置的,但连接是在启用的端口之间建立的。因此 GraphEdit 使用端口的索引,而不是插槽的索引。可以使用 get_input_port_slotget_output_port_slot 从端口索引中获取插槽索引。

属性

MouseFilter

mouse_filter

0 (overrides Control)

String

title

""

方法

void

_draw_port ( int slot_index, Vector2i position, bool left, Color color ) virtual

void

clear_all_slots ( )

void

clear_slot ( int slot_index )

Color

get_input_port_color ( int port_idx )

int

get_input_port_count ( )

Vector2

get_input_port_position ( int port_idx )

int

get_input_port_slot ( int port_idx )

int

get_input_port_type ( int port_idx )

Color

get_output_port_color ( int port_idx )

int

get_output_port_count ( )

Vector2

get_output_port_position ( int port_idx )

int

get_output_port_slot ( int port_idx )

int

get_output_port_type ( int port_idx )

Color

get_slot_color_left ( int slot_index ) const

Color

get_slot_color_right ( int slot_index ) const

int

get_slot_type_left ( int slot_index ) const

int

get_slot_type_right ( int slot_index ) const

HBoxContainer

get_titlebar_hbox ( )

bool

is_slot_draw_stylebox ( int slot_index ) const

bool

is_slot_enabled_left ( int slot_index ) const

bool

is_slot_enabled_right ( int slot_index ) const

void

set_slot ( int slot_index, bool enable_left_port, int type_left, Color color_left, bool enable_right_port, int type_right, Color color_right, Texture2D custom_icon_left=null, Texture2D custom_icon_right=null, bool draw_stylebox=true )

void

set_slot_color_left ( int slot_index, Color color )

void

set_slot_color_right ( int slot_index, Color color )

void

set_slot_draw_stylebox ( int slot_index, bool enable )

void

set_slot_enabled_left ( int slot_index, bool enable )

void

set_slot_enabled_right ( int slot_index, bool enable )

void

set_slot_type_left ( int slot_index, int type )

void

set_slot_type_right ( int slot_index, int type )

主题属性

Color

resizer_color

Color(0.875, 0.875, 0.875, 1)

int

port_h_offset

0

int

separation

2

Texture2D

port

StyleBox

panel

StyleBox

panel_selected

StyleBox

slot

StyleBox

titlebar

StyleBox

titlebar_selected


信号

slot_updated ( int slot_index )

当任何图形节点的插槽更新时发出。


属性说明

String title = ""

显示在 GraphNode 标题栏中的文本。


方法说明

void _draw_port ( int slot_index, Vector2i position, bool left, Color color ) virtual

目前没有这个方法的描述。请帮我们贡献一个


void clear_all_slots ( )

禁用 GraphNode 的所有插槽。会移除该 GraphNode 的所有输入/输出端口。


void clear_slot ( int slot_index )

禁用索引为 slot_index 的插槽。会移除该 GraphNode 的对应输入和输出端口。


Color get_input_port_color ( int port_idx )

返回索引为 port_idx 的输入端口的 Color


int get_input_port_count ( )

返回启用了输入端口的插槽数。


Vector2 get_input_port_position ( int port_idx )

返回索引为 port_idx 的输入端口的位置。


int get_input_port_slot ( int port_idx )

返回索引为 port_idx 的输入端口的对应插槽索引。


int get_input_port_type ( int port_idx )

返回索引为 port_idx 的输入端口的类型。


Color get_output_port_color ( int port_idx )

返回索引为 port_idx 的输出端口的 Color


int get_output_port_count ( )

返回启用了输出端口的插槽数。


Vector2 get_output_port_position ( int port_idx )

返回索引为 port_idx 的输出端口的位置。


int get_output_port_slot ( int port_idx )

返回索引为 port_idx 的输出端口的对应插槽索引。


int get_output_port_type ( int port_idx )

返回索引为 port_idx 的输出端口的类型。


Color get_slot_color_left ( int slot_index ) const

返回索引为 slot_index 的插槽左侧(输入)的 Color


Color get_slot_color_right ( int slot_index ) const

返回索引为 slot_index 的插槽右侧(输出)的 Color


int get_slot_type_left ( int slot_index ) const

返回索引为 slot_index 的插槽左侧(输入)的类型。


int get_slot_type_right ( int slot_index ) const

返回索引为 slot_index 的插槽右侧(输出)的类型。


HBoxContainer get_titlebar_hbox ( )

返回标题栏所使用的 HBoxContainer,默认只包含一个 Label,用于显示标题。可用于向标题栏添加自定义控件,例如选项和关闭按钮等。


bool is_slot_draw_stylebox ( int slot_index ) const

如果绘制索引为 slot_index 的插槽的背景 StyleBox,则返回 true。


bool is_slot_enabled_left ( int slot_index ) const

如果启用了索引为 slot_index 的插槽的左侧(输入),则返回 true


bool is_slot_enabled_right ( int slot_index ) const

如果启用了索引为 slot_index 的插槽的右侧(输出),则返回 true


void set_slot ( int slot_index, bool enable_left_port, int type_left, Color color_left, bool enable_right_port, int type_right, Color color_right, Texture2D custom_icon_left=null, Texture2D custom_icon_right=null, bool draw_stylebox=true )

设置索引为 slot_index 的插槽的属性。

如果 enable_left_port/enable_right_porttrue,则将出现一个端口,插槽将能够从这一侧连接。

使用 type_left/type_right 可以为每个端口分配一个任意类型。如果两个端口具有相同的类型,或者如果它们的类型之间的连接在父 GraphEdit 中被允许(参见 GraphEdit.add_valid_connection_type),那么这两个端口就可以被连接。请记住,GraphEdit 在接受连接上拥有最终决定权。类型兼容性只允许发出 GraphEdit.connection_request 信号。

可以使用 color_left/color_rightcustom_icon_left/custom_icon_right 进一步定制端口。颜色参数为图标添加了一个色调。自定义图标可以用来覆盖默认的端口点。

此外,draw_stylebox 可以用来启用或禁用每个插槽的背景样式框的绘制。参见 slot

单个属性也可以使用 set_slot_* 方法之一来设置。

注意:该方法只设置插槽的属性。要创建插槽本身,请将 Control 派生的子节点添加到该 GraphNode。


void set_slot_color_left ( int slot_index, Color color )

将索引为 slot_index 的插槽的左侧(输入)的 Color 设置为 color


void set_slot_color_right ( int slot_index, Color color )

将索引为 slot_index 的插槽的右侧(输出)的 Color 设置为 color


void set_slot_draw_stylebox ( int slot_index, bool enable )

开关索引为 slot_index 的插槽的背景 StyleBox


void set_slot_enabled_left ( int slot_index, bool enable )

切换给定插槽 slot_index 的左侧(输入)端口。如果 enabletrue,则左侧会出现一个端口,并且该插槽可以从这一侧连接。


void set_slot_enabled_right ( int slot_index, bool enable )

切换给定插槽 slot_index 的右侧(输出)端口。如果 enabletrue,则右侧会出现一个端口,并且该插槽可以从这一侧连接。


void set_slot_type_left ( int slot_index, int type )

将给定插槽 slot_index 的左侧(输入)类型设置为 type。如果该值为负,则所有的连接将不允许通过用户输入来创建。


void set_slot_type_right ( int slot_index, int type )

将给定插槽 slot_index 的右侧(输出)类型设置为 type。如果该值为负,则所有的连接将不允许通过用户输入来创建。


主题属性说明

Color resizer_color = Color(0.875, 0.875, 0.875, 1)

应用于调整尺寸大小图标的颜色调制。


int port_h_offset = 0

端口的水平偏移量。


int separation = 2

端口之间的垂直距离。


Texture2D port

该图标用于表示端口。


StyleBox panel

GraphNode 槽区域的默认背景。


StyleBox panel_selected

用于被选中时的插槽区域的 StyleBox


StyleBox slot

用于 GraphNode 的每个插槽的 StyleBox


StyleBox titlebar

用于该 GraphNode 标题栏的 StyleBox


StyleBox titlebar_selected

GraphNode 被选中时,用于其标题栏的 StyleBox