-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphNode.gd
More file actions
103 lines (82 loc) · 3.39 KB
/
GraphNode.gd
File metadata and controls
103 lines (82 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
extends PanelContainer
class_name ScriptingGraphNode
@onready var graph_node_parameter = preload("res://GraphNodeParameter.tscn")
@onready var node_name_label: Label = %NodeName
@onready var input_container: VBoxContainer = %InputContainer
@onready var output_container: VBoxContainer = %OutputContainer
var sig := ""
var _mouse_entered := false
var _selected := false
var _dragging := false
var _dragging_offset := Vector2.ZERO
func _input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_RIGHT:
Global.graph.update_selected_node(null)
if event is InputEventMouseButton and event.is_pressed() and _mouse_entered:
if event.button_index == MOUSE_BUTTON_LEFT:
select_node()
_dragging = true
_dragging_offset = global_position - get_global_mouse_position()
if event is InputEventMouseButton and event.is_released() and _dragging:
if event.button_index == MOUSE_BUTTON_LEFT:
_dragging = false
func _unhandled_input(event):
if event is InputEventMouseButton and event.is_pressed() and _selected:
if event.button_index == MOUSE_BUTTON_LEFT:
Global.graph.update_selected_node(null)
func init(graph_node_data: GraphNodeData, node_sig: String):
node_name_label.text = graph_node_data.name
sig = node_sig
if graph_node_data.is_executable:
add_parameter("Exec", false, true)
if graph_node_data.can_execute:
add_parameter("Exec", true, true)
for i in graph_node_data.inputs:
if not graph_node_data.is_executable && not graph_node_data.can_execute:
add_parameter(i, false, false, true)
else:
add_parameter(i)
for i in graph_node_data.outputs:
if graph_node_data.parameter_name != "":
add_parameter(i, true, false, false, graph_node_data.parameter_name)
else:
add_parameter(i, true)
func _ready():
for child in input_container.get_children():
input_container.remove_child(child)
child.queue_free()
for child in output_container.get_children():
output_container.remove_child(child)
child.queue_free()
mouse_entered.connect(func(): _on_mouse_entered())
mouse_exited.connect(func(): _mouse_entered = false)
func _physics_process(_delta):
if _dragging:
global_position = get_global_mouse_position() + _dragging_offset
func select_node():
if _selected:
return
_selected = true
_set_panel_border_width(1)
Global.graph.update_selected_node(self)
func deselect_node():
_selected = false
_set_panel_border_width(0)
func _set_panel_border_width(width: int):
var panel: StyleBoxFlat = get_theme_stylebox('panel')
panel.border_width_top = width
panel.border_width_bottom = width
panel.border_width_right = width
panel.border_width_left = width
func _on_mouse_entered():
_mouse_entered = true
func add_parameter(param_name: String, output = false, is_exec = false, hardcoded = false, parameter_name = ""):
var param = graph_node_parameter.instantiate()
if output:
output_container.add_child(param)
param.move_child(param.get_children()[2], 0)
param.alignment = 2
param.init(param_name, sig, is_exec, hardcoded, parameter_name)
else:
input_container.add_child(param)
param.init(param_name, sig, is_exec, hardcoded)