Nodes visually connect and send signals
This commit is contained in:
parent
ea1bff6ec6
commit
d06e9b0355
3 changed files with 64 additions and 27 deletions
|
@ -29,18 +29,26 @@ func _update_visuals():
|
||||||
if child.name != "Title":
|
if child.name != "Title":
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
for key in rows:
|
for key in rows:
|
||||||
if rows[key].get("type","default") == "default":
|
var nodeRow = load("res://Scenes/Nodes/Node Row.tscn").instantiate()
|
||||||
var nodeRow = load("res://Scenes/Nodes/Node Row.tscn").instantiate()
|
holder.add_child(nodeRow)
|
||||||
holder.add_child(nodeRow)
|
nodeRow.name = str(key)
|
||||||
(nodeRow.get_node("Label") as Label).text = str(key)
|
(nodeRow.get_node("Label") as Label).text = str(key)
|
||||||
var input = nodeRow.get_node("Input") as GL_Node_Point
|
var input = nodeRow.get_node("Input") as GL_Node_Point
|
||||||
var output = nodeRow.get_node("Output") as GL_Node_Point
|
var output = nodeRow.get_node("Output") as GL_Node_Point
|
||||||
input.valueName = str(key)
|
input.valueName = str(key)
|
||||||
input.mainNode = self
|
input.mainNode = self
|
||||||
output.valueName = str(key)
|
output.valueName = str(key)
|
||||||
output.mainNode = self
|
output.mainNode = self
|
||||||
_set_inout_type(nodeRow.get_node("Input") as Button,rows[key]["input"])
|
_set_inout_type(nodeRow.get_node("Input") as Button,rows[key]["input"])
|
||||||
_set_inout_type(nodeRow.get_node("Output") as Button,rows[key]["output"])
|
_set_inout_type(nodeRow.get_node("Output") as Button,rows[key]["output"])
|
||||||
|
|
||||||
|
func give_input_point_pos(name:String) -> Vector2:
|
||||||
|
var holder = get_node("Holder").get_node(name)
|
||||||
|
if holder == null:
|
||||||
|
return global_position
|
||||||
|
else:
|
||||||
|
holder = holder.get_node("Input") as GL_Node_Point
|
||||||
|
return holder.global_position + Vector2(holder.size.x/2,holder.size.y/2)
|
||||||
|
|
||||||
func _set_inout_type(label:Button, value):
|
func _set_inout_type(label:Button, value):
|
||||||
match typeof(value):
|
match typeof(value):
|
||||||
|
@ -67,7 +75,7 @@ func _recieve_input(inputName:String,value):
|
||||||
if rows.has(inputName):
|
if rows.has(inputName):
|
||||||
rows[inputName]["input"] = value
|
rows[inputName]["input"] = value
|
||||||
|
|
||||||
func _send_input(output_name: String, value):
|
func _send_input(output_name: String):
|
||||||
if not rows.has(output_name):
|
if not rows.has(output_name):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -76,7 +84,7 @@ func _send_input(output_name: String, value):
|
||||||
var target = conn.get("target", null)
|
var target = conn.get("target", null)
|
||||||
var input_name = conn.get("input_name", null)
|
var input_name = conn.get("input_name", null)
|
||||||
if target and input_name:
|
if target and input_name:
|
||||||
target._recieve_input(input_name, value)
|
target._recieve_input(input_name, rows[output_name]["output"])
|
||||||
|
|
||||||
func _create_connection(target:GL_Node,input_name:String,output_name:String):
|
func _create_connection(target:GL_Node,input_name:String,output_name:String):
|
||||||
if not rows.has(output_name):
|
if not rows.has(output_name):
|
||||||
|
|
|
@ -7,22 +7,51 @@ var dragging:bool
|
||||||
var previewLine:Line2D = null
|
var previewLine:Line2D = null
|
||||||
var mouseInside:bool
|
var mouseInside:bool
|
||||||
var lastToDrag:bool
|
var lastToDrag:bool
|
||||||
|
var allLines: Array
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if dragging:
|
if dragging:
|
||||||
if previewLine == null:
|
if previewLine == null:
|
||||||
previewLine = Line2D.new()
|
previewLine = _create_line()
|
||||||
previewLine.position = Vector2.ZERO
|
|
||||||
add_child(previewLine)
|
|
||||||
previewLine.width = 5
|
|
||||||
previewLine.default_color = Color.WHITE
|
|
||||||
previewLine.add_point(Vector2.ZERO)
|
|
||||||
previewLine.add_point(Vector2.ZERO)
|
|
||||||
previewLine.points[0] = Vector2(size.x / 2, size.y / 2)
|
|
||||||
previewLine.begin_cap_mode = Line2D.LINE_CAP_ROUND
|
|
||||||
previewLine.end_cap_mode = Line2D.LINE_CAP_ROUND
|
|
||||||
previewLine.points[1] = get_viewport().get_mouse_position() - previewLine.global_position
|
previewLine.points[1] = get_viewport().get_mouse_position() - previewLine.global_position
|
||||||
|
|
||||||
|
var connections = mainNode.rows[valueName].get("connections",[])
|
||||||
|
if connections != []:
|
||||||
|
var iter = 0
|
||||||
|
for child:Line2D in allLines:
|
||||||
|
var output = mainNode.rows[valueName]["output"]
|
||||||
|
match typeof(output):
|
||||||
|
TYPE_FLOAT:
|
||||||
|
child.default_color = Color(0.254902 * output, 0.411765 * output, 0.882353 * output, 1)
|
||||||
|
TYPE_BOOL:
|
||||||
|
if output:
|
||||||
|
child.default_color = Color.ORANGE
|
||||||
|
else:
|
||||||
|
child.default_color = Color.BLACK
|
||||||
|
TYPE_COLOR:
|
||||||
|
child.default_color = output
|
||||||
|
child.points[1] = (connections[iter]["target"] as GL_Node).give_input_point_pos(connections[iter]["input_name"]) - child.global_position
|
||||||
|
iter += 1
|
||||||
|
|
||||||
|
func _create_line() -> Line2D:
|
||||||
|
var previewLine = Line2D.new()
|
||||||
|
previewLine.position = Vector2.ZERO
|
||||||
|
previewLine.width = 5
|
||||||
|
previewLine.default_color = Color.WHITE
|
||||||
|
previewLine.add_point(Vector2.ZERO)
|
||||||
|
previewLine.add_point(Vector2.ZERO)
|
||||||
|
previewLine.points[0] = Vector2(size.x / 2, size.y / 2)
|
||||||
|
previewLine.begin_cap_mode = Line2D.LINE_CAP_ROUND
|
||||||
|
previewLine.end_cap_mode = Line2D.LINE_CAP_ROUND
|
||||||
|
add_child(previewLine)
|
||||||
|
return previewLine
|
||||||
|
|
||||||
|
func update_lines():
|
||||||
|
for child in allLines:
|
||||||
|
child.queue_free()
|
||||||
|
allLines = []
|
||||||
|
for child in mainNode.rows[valueName].get("connections",[]):
|
||||||
|
allLines.append(_create_line())
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
|
@ -46,7 +75,6 @@ func _finish_drag():
|
||||||
previewLine.queue_free()
|
previewLine.queue_free()
|
||||||
dragging = false
|
dragging = false
|
||||||
elif mouseInside:
|
elif mouseInside:
|
||||||
print("YESSS")
|
|
||||||
for node in get_tree().get_nodes_in_group("Outputs"):
|
for node in get_tree().get_nodes_in_group("Outputs"):
|
||||||
if node is GL_Node_Point:
|
if node is GL_Node_Point:
|
||||||
node._node_connect(mainNode,valueName)
|
node._node_connect(mainNode,valueName)
|
||||||
|
@ -55,3 +83,4 @@ func _node_connect(node:GL_Node,inputValue:String):
|
||||||
if not lastToDrag:
|
if not lastToDrag:
|
||||||
return
|
return
|
||||||
mainNode._create_connection(node,inputValue,valueName)
|
mainNode._create_connection(node,inputValue,valueName)
|
||||||
|
update_lines()
|
||||||
|
|
|
@ -3,10 +3,10 @@ extends GL_Node
|
||||||
func _ready():
|
func _ready():
|
||||||
_set_title("Sine")
|
_set_title("Sine")
|
||||||
_create_row("Output",null,0.0)
|
_create_row("Output",null,0.0)
|
||||||
_create_row("Length",1.0,null)
|
_create_row("Length",0.01,null)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
super._process(delta)
|
super._process(delta)
|
||||||
rows["Output"]["output"] = sin(Time.get_ticks_msec() * rows["Length"].get("input",1))
|
rows["Output"]["output"] = sin(Time.get_ticks_msec() * rows["Length"].get("input",1))
|
||||||
pass
|
_send_input("Output")
|
||||||
|
|
Loading…
Add table
Reference in a new issue