node connecting works

This commit is contained in:
The 64th Gamer 2025-04-07 05:49:21 -06:00
parent 04311758b6
commit ea1bff6ec6
3 changed files with 71 additions and 24 deletions

View file

@ -4,12 +4,11 @@
[node name="Node Row" type="HBoxContainer"]
[node name="Input" type="Button" parent="."]
[node name="Input" type="Button" parent="." groups=["Outputs"]]
layout_mode = 2
mouse_default_cursor_shape = 2
text = "◉"
script = ExtResource("1_fygh4")
isOutput = true
[node name="Label" type="Label" parent="."]
layout_mode = 2
@ -18,12 +17,12 @@ mouse_filter = 1
text = "Testtesttesttesttest"
clip_text = true
[node name="Output" type="Button" parent="."]
[node name="Output" type="Button" parent="." groups=["Outputs"]]
layout_mode = 2
mouse_default_cursor_shape = 2
text = "◉"
script = ExtResource("1_fygh4")
isOutput = true
[connection signal="pressed" from="Input" to="Input" method="_start_drag"]
[connection signal="pressed" from="Output" to="Output" method="_start_drag"]
[connection signal="mouse_entered" from="Input" to="Input" method="mouse_enter"]
[connection signal="mouse_exited" from="Input" to="Input" method="mouse_exit"]
[connection signal="button_down" from="Output" to="Output" method="_start_drag"]

View file

@ -33,8 +33,12 @@ func _update_visuals():
var nodeRow = load("res://Scenes/Nodes/Node Row.tscn").instantiate()
holder.add_child(nodeRow)
(nodeRow.get_node("Label") as Label).text = str(key)
(nodeRow.get_node("Input") as GL_Node_Point).valueName = str(key)
(nodeRow.get_node("Output") as GL_Node_Point).valueName = str(key)
var input = nodeRow.get_node("Input") as GL_Node_Point
var output = nodeRow.get_node("Output") as GL_Node_Point
input.valueName = str(key)
input.mainNode = self
output.valueName = str(key)
output.mainNode = self
_set_inout_type(nodeRow.get_node("Input") as Button,rows[key]["input"])
_set_inout_type(nodeRow.get_node("Output") as Button,rows[key]["output"])
@ -56,7 +60,7 @@ func _set_title(name:String):
(get_node("Holder").get_node("Title") as Label).text = name
func _create_row(name:String,input,output):
rows[name] = {"input": input, "output": output}
rows[name] = {"input": input, "output": output, "connections": []}
_update_visuals()
func _recieve_input(inputName:String,value):
@ -74,6 +78,34 @@ func _send_input(output_name: String, value):
if target and input_name:
target._recieve_input(input_name, value)
func _create_connection(target:GL_Node,input_name:String,output_name:String):
if not rows.has(output_name):
return
var item = target.rows.get(input_name, null)
if item == null:
return
if typeof(rows[output_name].get("output", null)) != typeof(target.rows[input_name].get("input",null)):
print("Type mismatch: cannot connect " + output_name + " to " + target.name)
return
var thenew = {
"target": target,
"input_name": input_name
}
var connections = rows[output_name].get("connections",[])
for connection in connections:
if connection.target == thenew.target and connection.input_name == thenew.input_name:
print("Connection already exists: " + output_name + " to " + target.name)
return
connections.append(thenew)
rows[output_name]["connections"] = connections
func mouse_enter():
canDrag = true
func mouse_exit():

View file

@ -2,40 +2,56 @@ extends Button
class_name GL_Node_Point
var mainNode : GL_Node
@export var isOutput:bool
var valueName:String
var dragging:bool
var previewLine:Line2D = null
func _ready():
set_process(true)
var mouseInside:bool
var lastToDrag:bool
func _process(delta):
if dragging:
if previewLine == null:
previewLine = Line2D.new()
previewLine.width = 10
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] = position
previewLine.points[1] = get_viewport().get_mouse_position()
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
func _input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if !event.pressed:
_finish_drag()
if event.pressed && !dragging:
lastToDrag = false
func _start_drag():
if (not isOutput):
return
dragging = true
lastToDrag = true
func mouse_enter():
mouseInside = true
func mouse_exit():
mouseInside = false
func _finish_drag():
if not dragging:
return
if dragging:
previewLine.queue_free()
dragging = false
elif mouseInside:
print("YESSS")
for node in get_tree().get_nodes_in_group("Outputs"):
if node is GL_Node_Point:
node._node_connect(mainNode,valueName)
func _node_connect(node:GL_Node,inputValue:String):
if not lastToDrag:
return
mainNode._create_connection(node,inputValue,valueName)