소스 검색

fully implemented add/remove inlet ui

Jonathan Higgins 3 달 전
부모
커밋
446eba1418
5개의 변경된 파일46개의 추가작업 그리고 7개의 파일을 삭제
  1. 23 0
      scenes/Nodes/addremoveinlets.gd
  2. 2 0
      scenes/Nodes/addremoveinlets.tscn
  3. 12 0
      scenes/Nodes/node_logic.gd
  4. 3 3
      scenes/main/process_help.json
  5. 6 4
      scenes/main/scripts/graph_edit.gd

+ 23 - 0
scenes/Nodes/addremoveinlets.gd

@@ -2,12 +2,35 @@ extends Control
 
 signal add_inlet
 signal remove_inlet
+var minimum_inlet_count
+var maximum_inlet_count
+var current_inlet_count
 
+func _ready() -> void:
+	minimum_inlet_count = get_meta("min")
+	maximum_inlet_count = get_meta("max")
+	current_inlet_count = get_meta("default")
+	check_buttons()
 
 
 func _on_add_inlet_button_button_down() -> void:
 	add_inlet.emit()
+	current_inlet_count += 1
+	check_buttons()
 
 
 func _on_remove_inlet_button_button_down() -> void:
 	remove_inlet.emit()
+	current_inlet_count -= 1
+	check_buttons()
+
+func check_buttons():
+	if current_inlet_count == maximum_inlet_count:
+		$VBoxContainer/HBoxContainer/AddInletButton.disabled = true
+	else:
+		$VBoxContainer/HBoxContainer/AddInletButton.disabled = false
+		
+	if current_inlet_count == minimum_inlet_count:
+		$VBoxContainer/HBoxContainer/RemoveInletButton.disabled = true
+	else:
+		$VBoxContainer/HBoxContainer/RemoveInletButton.disabled = false

+ 2 - 0
scenes/Nodes/addremoveinlets.tscn

@@ -30,11 +30,13 @@ layout_mode = 2
 [node name="AddInletButton" type="Button" parent="VBoxContainer/HBoxContainer"]
 layout_mode = 2
 size_flags_horizontal = 3
+tooltip_text = "Add new inlet to node"
 text = "+"
 
 [node name="RemoveInletButton" type="Button" parent="VBoxContainer/HBoxContainer"]
 layout_mode = 2
 size_flags_horizontal = 3
+tooltip_text = "Remove last inlet from node"
 text = "-"
 
 [connection signal="button_down" from="VBoxContainer/HBoxContainer/AddInletButton" to="." method="_on_add_inlet_button_button_down"]

+ 12 - 0
scenes/Nodes/node_logic.gd

@@ -68,27 +68,39 @@ func _open_help():
 	open_help.emit(self.get_meta("command"), self.title)
 
 func add_inlet_to_node():
+	#called when the + button is pressed on an addremoveinlets node in the graphnode
 	var inlet_count = self.get_input_port_count()
 	var child_count = self.get_child_count()
 	
+	#check if the number of children is less than the new inlet count
 	if child_count < inlet_count + 1:
+		#if so add a new control node for the inlet to connect to
 		var control = Control.new()
 		control.custom_minimum_size.y = 57
+		#give it this meta so it can be found and removed later if needed
 		control.set_meta("dummynode", true)
 		add_child(control)
+		#move the ui for adding/removing inlets to the bottom of the node
 		move_child(get_node("addremoveinlets"), get_child_count() - 1)
 	
+	#add the inlet using the same parameters as the first inlet
 	set_slot(inlet_count, true, get_input_port_type(0), get_input_port_color(0), false, 0, get_input_port_color(0))
 	
 func remove_inlet_from_node():
 	var inlet_count = self.get_input_port_count()
 	var child_count = self.get_child_count()
 	
+	#emit a signal to the graphedit script to remove any connections to this inlet
 	inlet_removed.emit(self.get_name(), child_count - 1)
+	#remove the inlet note inlet idx starts at 0 hence inlet_count -1
 	set_slot(inlet_count - 1, false, get_input_port_type(0), get_input_port_color(0), false, 0, get_input_port_color(0))
 	
+	#check if a dummy control node has been added to make this inlet -2 because bottom node is the ui for adding removing inlets and idx starts at 0
 	if get_child(child_count - 2).has_meta("dummynode"):
+		#remove the dummy node
 		get_child(child_count - 2).queue_free()
+		#wait a frame for it to be removed
 		await get_tree().process_frame
+		#update the size of the graphnode to shrink to fit smaller ui
 		update_minimum_size()
 		size.y = get_combined_minimum_size().y

+ 3 - 3
scenes/main/process_help.json

@@ -2620,8 +2620,8 @@
 	"outputtype": "[0]",
 	"parameters": {
 	  "param1": {
-		"paramname": "",
-		"paramdescription": "",
+		"paramname": "Add/Remove Inlets",
+		"paramdescription": "Adds or removes inlets on the node to allow for more input files",
 		"automatable": false,
 		"outputduration": false,
 		"time": false,
@@ -2631,7 +2631,7 @@
 		"minrange": 2.0,
 		"maxrange": -1.0,
 		"step": "",
-		"value": "",
+		"value": 2.0,
 		"exponential": false,
 		"uitype": "addremoveinlets"
 	  }

+ 6 - 4
scenes/main/scripts/graph_edit.gd

@@ -238,12 +238,14 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 						addremove.name = "addremoveinlets"
 						
 						#get parameters
-						var minrange = param_data.get("minrange", 0)
-						var maxrange = param_data.get("maxrange", 10)
+						var min_inlets = param_data.get("minrange", 0)
+						var max_inlets = param_data.get("maxrange", 10)
+						var default_inlets = param_data.get("value", 1)
 						
 						#set meta
-						addremove.set_meta("min", minrange)
-						addremove.set_meta("max", maxrange)
+						addremove.set_meta("min", min_inlets)
+						addremove.set_meta("max", max_inlets)
+						addremove.set_meta("default", default_inlets)
 						
 						graphnode.add_child(addremove)