Browse Source

added shift right click on a node to connect a new node to the one that was clicked

Jonathan Higgins 3 months ago
parent
commit
89f2145877
3 changed files with 31 additions and 6 deletions
  1. 16 6
      scenes/main/scripts/control.gd
  2. 10 0
      scenes/main/scripts/graph_edit.gd
  3. 5 0
      scenes/menu/search_menu.gd

+ 16 - 6
scenes/main/scripts/control.gd

@@ -83,6 +83,7 @@ func load_scripts():
 func make_signal_connections():
 	get_node("SearchMenu").make_node.connect(graph_edit._make_node)
 	get_node("SearchMenu").swap_node.connect(graph_edit._swap_node)
+	get_node("SearchMenu").connect_to_clicked_node.connect(graph_edit._connect_to_clicked_node)
 	get_node("mainmenu").make_node.connect(graph_edit._make_node)
 	get_node("mainmenu").open_help.connect(open_help.show_help_for_node)
 	get_node("Settings").open_cdp_location.connect(show_cdp_location)
@@ -372,7 +373,7 @@ func _on_file_dialog_dir_selected(dir: String) -> void:
 	var check_characters = Global.outfile.get_basename().split("/")
 	var invalid_chars:= []
 	var regex = RegEx.new()
-	regex.compile("[^a-zA-Z0-9\\-_ :]")
+	regex.compile("[^a-zA-Z0-9\\-_ :+]")
 	for string in check_characters:
 		if string != "":
 			var result = regex.search_all(string)
@@ -390,7 +391,7 @@ func _on_file_dialog_dir_selected(dir: String) -> void:
 		run_thread.run_thread_with_branches()
 	else:
 		run_thread.log_console("[color=#9c2828][b]Error:[/b][/color] Chosen file name or folder path " + Global.outfile.get_basename() + " contains invalid characters.", true)
-		run_thread.log_console("File names and paths can only contain A-Z a-z 0-9 - _ and space.", true)
+		run_thread.log_console("File names and paths can only contain A-Z a-z 0-9 - _ + and space.", true)
 		run_thread.log_console("Chosen file name/path contains the following invalid characters: " + invalid_string, true)
 		if $ProgressWindow.visible:
 			$ProgressWindow.hide()
@@ -680,13 +681,22 @@ func _on_graph_edit_popup_request(at_position: Vector2) -> void:
 	
 	if clicked_node and clicked_node.get_meta("command") != "outputfile":
 		var title = clicked_node.title
-		$SearchMenu/VBoxContainer/ReplaceLabel.text = "Replace " + title
-		$SearchMenu/VBoxContainer/ReplaceLabel.show()
-		$SearchMenu.replace_node = true
-		$SearchMenu.node_to_replace = clicked_node
+		if Input.is_action_pressed("auto_link_nodes"):
+			$SearchMenu/VBoxContainer/ReplaceLabel.text = "Connect to " + title
+			$SearchMenu/VBoxContainer/ReplaceLabel.show()
+			$SearchMenu.replace_node = false
+			$SearchMenu.connect_to_node = true
+			$SearchMenu.node_to_connect_to = clicked_node
+		else:
+			$SearchMenu/VBoxContainer/ReplaceLabel.text = "Replace " + title
+			$SearchMenu/VBoxContainer/ReplaceLabel.show()
+			$SearchMenu.replace_node = true
+			$SearchMenu.connect_to_node = false
+			$SearchMenu.node_to_replace = clicked_node
 	else:
 		$SearchMenu/VBoxContainer/ReplaceLabel.hide()
 		$SearchMenu.replace_node = false
+		$SearchMenu.connect_to_node = false
 	
 	#calculate the xy position of the mouse clamped to the size of the window and menu so it doesn't go off the screen
 	var clamped_x = clamp(mouse_screen_pos.x, window_screen_pos.x, window_screen_pos.x + window_size.x - $SearchMenu.size.x)

+ 10 - 0
scenes/main/scripts/graph_edit.gd

@@ -654,8 +654,18 @@ func _swap_node(old_node: GraphNode, command: String):
 			if _same_port_type(from, from_port, to, to_port):
 				_on_connection_request(from, from_port, to, to_port)
 	
+func _connect_to_clicked_node(clicked_node: GraphNode, command: String):
+	var new_node_position = clicked_node.position_offset + Vector2(clicked_node.size.x + 50, 0)
+	#make the new node and reposition it to right of the node to connect to
+	var new_node = _make_node(command)
+	new_node.position_offset = new_node_position
 	
+	var clicked_node_has_outputs = clicked_node.get_output_port_count() > 0
+	var new_node_has_inputs = new_node.get_input_port_count() > 0
 	
+	if clicked_node_has_outputs and new_node_has_inputs:
+		if _same_port_type(clicked_node.name, 0, new_node.name, 0):
+			_on_connection_request(clicked_node.name, 0, new_node.name, 0)
 
 
 func _on_gui_input(event: InputEvent) -> void:

+ 5 - 0
scenes/menu/search_menu.gd

@@ -6,8 +6,11 @@ extends PopupPanel
 var node_data = {} #stores node data for each node to display in help popup
 var replace_node = false
 var node_to_replace
+var connect_to_node = false
+var node_to_connect_to
 signal make_node(command)
 signal swap_node(node_to_replace, command)
+signal connect_to_clicked_node(node_to_connect_to, command)
 
 
 func _ready() -> void:
@@ -106,6 +109,8 @@ func _on_item_selected(key: String):
 	self.hide()
 	if replace_node == true:
 		swap_node.emit(node_to_replace, key)
+	elif connect_to_node == true:
+		connect_to_clicked_node.emit(node_to_connect_to, key)
 	else:
 		make_node.emit(key) # send out signal to main patch