Class GraphNode
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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 input port and the right port is referred to as the output port. 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.
Note: 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 GetInputPortSlot(int) and GetOutputPortSlot(int) to get the slot index from the port index.
public class GraphNode : GraphElement, IDisposable
- Inheritance
-
GraphNode
- Implements
- Inherited Members
Constructors
GraphNode()
public GraphNode()
Properties
Title
The text displayed in the GraphNode's title bar.
public string Title { get; set; }
Property Value
Methods
ClearAllSlots()
Disables all slots of the GraphNode. This will remove all input/output ports from the GraphNode.
public void ClearAllSlots()
ClearSlot(int)
Disables the slot with the given slotIndex
. This will remove the corresponding input and output port from the GraphNode.
public void ClearSlot(int slotIndex)
Parameters
slotIndex
int
GetInputPortColor(int)
Returns the Color of the input port with the given portIdx
.
public Color GetInputPortColor(int portIdx)
Parameters
portIdx
int
Returns
GetInputPortCount()
Returns the number of slots with an enabled input port.
public int GetInputPortCount()
Returns
GetInputPortPosition(int)
Returns the position of the input port with the given portIdx
.
public Vector2 GetInputPortPosition(int portIdx)
Parameters
portIdx
int
Returns
GetInputPortSlot(int)
Returns the corresponding slot index of the input port with the given portIdx
.
public int GetInputPortSlot(int portIdx)
Parameters
portIdx
int
Returns
GetInputPortType(int)
Returns the type of the input port with the given portIdx
.
public int GetInputPortType(int portIdx)
Parameters
portIdx
int
Returns
GetOutputPortColor(int)
Returns the Color of the output port with the given portIdx
.
public Color GetOutputPortColor(int portIdx)
Parameters
portIdx
int
Returns
GetOutputPortCount()
Returns the number of slots with an enabled output port.
public int GetOutputPortCount()
Returns
GetOutputPortPosition(int)
Returns the position of the output port with the given portIdx
.
public Vector2 GetOutputPortPosition(int portIdx)
Parameters
portIdx
int
Returns
GetOutputPortSlot(int)
Returns the corresponding slot index of the output port with the given portIdx
.
public int GetOutputPortSlot(int portIdx)
Parameters
portIdx
int
Returns
GetOutputPortType(int)
Returns the type of the output port with the given portIdx
.
public int GetOutputPortType(int portIdx)
Parameters
portIdx
int
Returns
GetSlotColorLeft(int)
Returns the left (input) Color of the slot with the given slotIndex
.
public Color GetSlotColorLeft(int slotIndex)
Parameters
slotIndex
int
Returns
GetSlotColorRight(int)
Returns the right (output) Color of the slot with the given slotIndex
.
public Color GetSlotColorRight(int slotIndex)
Parameters
slotIndex
int
Returns
GetSlotTypeLeft(int)
Returns the left (input) type of the slot with the given slotIndex
.
public int GetSlotTypeLeft(int slotIndex)
Parameters
slotIndex
int
Returns
GetSlotTypeRight(int)
Returns the right (output) type of the slot with the given slotIndex
.
public int GetSlotTypeRight(int slotIndex)
Parameters
slotIndex
int
Returns
GetTitlebarHBox()
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.
public HBoxContainer GetTitlebarHBox()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsSlotDrawStylebox(int)
Returns true if the background StyleBox of the slot with the given slotIndex
is drawn.
public bool IsSlotDrawStylebox(int slotIndex)
Parameters
slotIndex
int
Returns
IsSlotEnabledLeft(int)
Returns true
if left (input) side of the slot with the given slotIndex
is enabled.
public bool IsSlotEnabledLeft(int slotIndex)
Parameters
slotIndex
int
Returns
IsSlotEnabledRight(int)
Returns true
if right (output) side of the slot with the given slotIndex
is enabled.
public bool IsSlotEnabledRight(int slotIndex)
Parameters
slotIndex
int
Returns
SetSlot(int, bool, int, Color, bool, int, Color, Texture2D, Texture2D, bool)
Sets properties of the slot with the given slotIndex
.
If enableLeftPort
/enableRightPort
is true
, a port will appear and the slot will be able to be connected from this side.
With typeLeft
/typeRight
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 AddValidConnectionType(int, int)). Keep in mind that the GraphEdit has the final say in accepting the connection. Type compatibility simply allows the ConnectionRequest signal to be emitted.
Ports can be further customized using colorLeft
/colorRight
and customIconLeft
/customIconRight
. The color parameter adds a tint to the icon. The custom icon can be used to override the default port dot.
Additionally, drawStylebox
can be used to enable or disable drawing of the background stylebox for each slot. See slot
.
Individual properties can also be set using one of the set_slot_*
methods.
Note: This method only sets properties of the slot. To create the slot itself, add a Control-derived child to the GraphNode.
public void SetSlot(int slotIndex, bool enableLeftPort, int typeLeft, Color colorLeft, bool enableRightPort, int typeRight, Color colorRight, Texture2D customIconLeft = null, Texture2D customIconRight = null, bool drawStylebox = true)
Parameters
slotIndex
intenableLeftPort
booltypeLeft
intcolorLeft
ColorenableRightPort
booltypeRight
intcolorRight
ColorcustomIconLeft
Texture2DcustomIconRight
Texture2DdrawStylebox
bool
SetSlotColorLeft(int, Color)
Sets the Color of the left (input) side of the slot with the given slotIndex
to color
.
public void SetSlotColorLeft(int slotIndex, Color color)
Parameters
SetSlotColorRight(int, Color)
Sets the Color of the right (output) side of the slot with the given slotIndex
to color
.
public void SetSlotColorRight(int slotIndex, Color color)
Parameters
SetSlotDrawStylebox(int, bool)
Toggles the background StyleBox of the slot with the given slotIndex
.
public void SetSlotDrawStylebox(int slotIndex, bool enable)
Parameters
SetSlotEnabledLeft(int, bool)
Toggles the left (input) side of the slot with the given slotIndex
. If enable
is true
, a port will appear on the left side and the slot will be able to be connected from this side.
public void SetSlotEnabledLeft(int slotIndex, bool enable)
Parameters
SetSlotEnabledRight(int, bool)
Toggles the right (output) side of the slot with the given slotIndex
. If enable
is true
, a port will appear on the right side and the slot will be able to be connected from this side.
public void SetSlotEnabledRight(int slotIndex, bool enable)
Parameters
SetSlotTypeLeft(int, int)
Sets the left (input) type of the slot with the given slotIndex
to type
. If the value is negative, all connections will be disallowed to be created via user inputs.
public void SetSlotTypeLeft(int slotIndex, int type)
Parameters
SetSlotTypeRight(int, int)
Sets the right (output) type of the slot with the given slotIndex
to type
. If the value is negative, all connections will be disallowed to be created via user inputs.
public void SetSlotTypeRight(int slotIndex, int type)
Parameters
_DrawPort(int, Vector2I, bool, Color)
public virtual void _DrawPort(int slotIndex, Vector2I position, bool left, Color color)
Parameters
Events
SlotUpdated
Emitted when any GraphNode's slot is updated.
public event GraphNode.SlotUpdatedEventHandler SlotUpdated