2023-06-12 17:32:36 +02:00
|
|
|
extends GraphNode
|
|
|
|
class_name DeckNodeRendererGraphNode
|
|
|
|
|
2023-11-25 11:40:43 +01:00
|
|
|
## [GraphNode] based renderer of [DeckNode]
|
2023-06-12 17:32:36 +02:00
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Stores the data container [DeckNode] that the visuals of this [DeckNodeRendererGraphNode]
|
2023-11-25 11:40:43 +01:00
|
|
|
## are based off.
|
|
|
|
var node: DeckNode
|
2023-06-12 17:32:36 +02:00
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Setups up all the properties based off [member node]. Including looping through
|
2023-11-25 11:40:43 +01:00
|
|
|
## [method DeckNode.get_all_ports()] and setting up all the descriptors.
|
2023-06-12 17:32:36 +02:00
|
|
|
func _ready() -> void:
|
|
|
|
title = node.name
|
2023-11-22 05:26:11 +01:00
|
|
|
node.position_updated.connect(_on_node_position_updated)
|
|
|
|
#node.port_added.connect(_on_node_port_added)
|
|
|
|
#node.port_removed.connect(_on_node_port_removed)
|
|
|
|
node.ports_updated.connect(_on_node_ports_updated)
|
2023-06-12 17:32:36 +02:00
|
|
|
for port in node.get_all_ports():
|
2023-11-27 10:21:43 +01:00
|
|
|
update_port(port)
|
2023-11-29 06:54:36 +01:00
|
|
|
position_offset_changed.connect(_on_position_offset_changed)
|
2023-06-24 05:39:50 +02:00
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Connected to [signal GraphElement.position_offset_updated] and updates the
|
2023-11-25 11:40:43 +01:00
|
|
|
## [member node]s properties
|
2023-06-24 05:39:50 +02:00
|
|
|
func _on_position_offset_changed() -> void:
|
2023-11-22 05:26:11 +01:00
|
|
|
node.position.x = position_offset.x
|
|
|
|
node.position.y = position_offset.y
|
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Connected to [member node]s [signal position_updated] to keep parity with the
|
2023-11-25 11:40:43 +01:00
|
|
|
## data position.
|
2023-11-22 05:26:11 +01:00
|
|
|
func _on_node_position_updated(new_position: Dictionary) -> void:
|
2023-11-29 06:54:36 +01:00
|
|
|
position_offset_changed.disconnect(_on_position_offset_changed)
|
2023-11-22 05:26:11 +01:00
|
|
|
position_offset.x = new_position.x
|
|
|
|
position_offset.y = new_position.y
|
2023-11-29 06:54:36 +01:00
|
|
|
position_offset_changed.connect(_on_position_offset_changed)
|
|
|
|
print("PO: ", position_offset)
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 12:01:17 +01:00
|
|
|
## Connected to [member node]s [signal port_added] handles setting up the specified
|
|
|
|
## [member Port.descriptor] with it's required nodes/signals etc. + adding the port
|
2023-11-25 11:40:43 +01:00
|
|
|
## using [method GraphNode.set_slot]
|
2023-11-22 05:26:11 +01:00
|
|
|
func _on_node_port_added(port_idx: int) -> void:
|
|
|
|
var port := node.get_all_ports()[port_idx]
|
2023-11-27 10:21:43 +01:00
|
|
|
update_port(port)
|
|
|
|
|
|
|
|
|
|
|
|
## Connected to [member node]s [signal port_removed], queue_frees the [Node]
|
|
|
|
## used for the descriptor, as well as using [method GraphNode.set_slot] to remove the slot.
|
|
|
|
func _on_node_port_removed(port_idx: int) -> void:
|
|
|
|
set_slot(
|
|
|
|
port_idx,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
Color.WHITE,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
Color.WHITE,
|
|
|
|
)
|
|
|
|
|
|
|
|
get_child(port_idx).queue_free()
|
|
|
|
|
|
|
|
## Connected to [member node]s [signal ports_updated]. Remakes all of the ports
|
|
|
|
## + their descriptors whenever this is received to allow keeping the Renderers ports up to date.
|
|
|
|
func _on_node_ports_updated() -> void:
|
|
|
|
clear_all_slots()
|
|
|
|
for c in get_children():
|
|
|
|
c.queue_free()
|
|
|
|
|
|
|
|
for port in node.get_all_ports():
|
|
|
|
update_port(port)
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-27 10:21:43 +01:00
|
|
|
func update_port(port: Port) -> void:
|
2023-11-22 05:26:11 +01:00
|
|
|
var descriptor_split := port.descriptor.split(":")
|
|
|
|
match descriptor_split[0]:
|
|
|
|
"button":
|
|
|
|
var button := Button.new()
|
|
|
|
add_child(button)
|
|
|
|
button.text = port.label
|
|
|
|
if port.port_type == DeckNode.PortType.OUTPUT:
|
|
|
|
button.pressed.connect(
|
|
|
|
func():
|
2023-11-26 23:07:15 +01:00
|
|
|
node.send(port.index_of_type, true)
|
2023-11-22 05:26:11 +01:00
|
|
|
)
|
2023-11-27 10:21:43 +01:00
|
|
|
#elif port.port_type == DeckNode.PortType.INPUT:
|
|
|
|
else:
|
2023-11-22 05:26:11 +01:00
|
|
|
button.pressed.connect(
|
|
|
|
func():
|
2023-11-26 23:07:15 +01:00
|
|
|
node._receive(port.index_of_type, true)
|
2023-11-22 05:26:11 +01:00
|
|
|
)
|
|
|
|
"field":
|
|
|
|
var line_edit := LineEdit.new()
|
|
|
|
add_child(line_edit)
|
|
|
|
if port.value:
|
|
|
|
line_edit.text = str(port.value)
|
|
|
|
line_edit.placeholder_text = port.label
|
|
|
|
port.value_callback = line_edit.get_text
|
|
|
|
line_edit.text_changed.connect(port.set_value)
|
2023-11-27 10:21:43 +01:00
|
|
|
"singlechoice":
|
|
|
|
var box := OptionButton.new()
|
2023-11-28 09:13:18 +01:00
|
|
|
if descriptor_split.slice(1).is_empty():
|
|
|
|
if port.value:
|
|
|
|
box.add_item(port.value)
|
|
|
|
else:
|
|
|
|
box.add_item(port.label)
|
|
|
|
else:
|
|
|
|
for item in descriptor_split.slice(1):
|
|
|
|
box.add_item(item)
|
2023-11-27 10:21:43 +01:00
|
|
|
add_child(box)
|
|
|
|
port.value_callback = func(): return box.get_item_text(box.get_selected_id())
|
|
|
|
if port.type == DeckType.Types.STRING:
|
|
|
|
box.item_selected.connect(
|
|
|
|
func(id: int):
|
|
|
|
port.set_value.call(box.get_item_text(box.get_selected_id()))
|
|
|
|
)
|
|
|
|
"codeblock":
|
|
|
|
var code_edit = CodeEdit.new()
|
|
|
|
add_child(code_edit)
|
|
|
|
if port.value:
|
|
|
|
code_edit.text = str(port.value)
|
|
|
|
code_edit.placeholder_text = port.label
|
|
|
|
port.value_callback = code_edit.get_text
|
|
|
|
code_edit.text_changed.connect(port.set_value.bind(code_edit.get_text))
|
|
|
|
code_edit.custom_minimum_size = Vector2(200, 100)
|
|
|
|
code_edit.size_flags_vertical = SIZE_EXPAND_FILL
|
2023-12-01 10:30:35 +01:00
|
|
|
"checkbox":
|
|
|
|
var cb := CheckBox.new()
|
|
|
|
add_child(cb)
|
|
|
|
if descriptor_split.size() > 1:
|
|
|
|
cb.button_pressed = true
|
|
|
|
if port.value is bool:
|
|
|
|
cb.button_pressed = port.value
|
|
|
|
cb.text = port.label
|
|
|
|
port.value_callback = cb.is_pressed
|
|
|
|
cb.toggled.connect(port.set_value)
|
2023-11-22 05:26:11 +01:00
|
|
|
_:
|
|
|
|
var label := Label.new()
|
|
|
|
add_child(label)
|
|
|
|
label.text = port.label
|
2023-12-04 14:59:09 +01:00
|
|
|
if port.port_type == DeckNode.PortType.OUTPUT:
|
|
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
set_slot(
|
|
|
|
port.index,
|
|
|
|
port.port_type == DeckNode.PortType.INPUT,
|
2023-11-26 23:07:15 +01:00
|
|
|
port.type,
|
2023-11-22 05:26:11 +01:00
|
|
|
Color.WHITE,
|
|
|
|
port.port_type == DeckNode.PortType.OUTPUT,
|
2023-11-26 23:07:15 +01:00
|
|
|
port.type,
|
2023-11-22 05:26:11 +01:00
|
|
|
Color.WHITE,
|
|
|
|
)
|