Browse Source

implemented for adding removing inlets to nodes

Jonathan Higgins 2 months ago
parent
commit
4221580e8f

+ 13 - 0
scenes/Nodes/addremoveinlets.gd

@@ -2,6 +2,7 @@ extends Control
 
 signal add_inlet
 signal remove_inlet
+var undo_redo: UndoRedo
 var minimum_inlet_count
 var maximum_inlet_count
 var current_inlet_count
@@ -14,6 +15,12 @@ func _ready() -> void:
 
 
 func _on_add_inlet_button_button_down() -> void:
+	undo_redo.create_action("Add Inlet")
+	undo_redo.add_do_method(add_new)
+	undo_redo.add_undo_method(remove)
+	undo_redo.commit_action()
+	
+func add_new() -> void:
 	add_inlet.emit()
 	current_inlet_count += 1
 	set_meta("inlet_count", current_inlet_count)
@@ -21,6 +28,12 @@ func _on_add_inlet_button_button_down() -> void:
 
 
 func _on_remove_inlet_button_button_down() -> void:
+	undo_redo.create_action("Remove Inlet")
+	undo_redo.add_do_method(remove)
+	undo_redo.add_undo_method(add_new)
+	undo_redo.commit_action()
+	
+func remove() -> void:
 	remove_inlet.emit()
 	current_inlet_count -= 1
 	set_meta("inlet_count", current_inlet_count)

+ 3 - 1
scenes/main/scripts/control.gd

@@ -54,7 +54,7 @@ func _ready() -> void:
 	$LoadDialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
 	$LoadDialog.filters = ["*.thd"]
 	
-	undo_redo.max_steps = 20
+	undo_redo.max_steps = 40
 	
 	get_tree().set_auto_accept_quit(false) #disable closing the app with the x and instead handle it internally
 	
@@ -149,6 +149,7 @@ func new_patch():
 	effect.connect("open_help", Callable(open_help, "show_help_for_node"))
 	if effect.has_signal("node_moved"):
 		effect.node_moved.connect(graph_edit._auto_link_nodes)
+	effect.dragged.connect(graph_edit.node_position_changed.bind(effect))
 	effect.position_offset = Vector2(20,80)
 	default_input_node = effect #store a reference to this node to allow for loading into it directly if software launched with a wav file argument
 	
@@ -159,6 +160,7 @@ func new_patch():
 	effect.connect("open_help", Callable(open_help, "show_help_for_node"))
 	if effect.has_signal("node_moved"):
 		effect.node_moved.connect(graph_edit._auto_link_nodes)
+	effect.dragged.connect(graph_edit.node_position_changed.bind(effect))
 	effect.position_offset = Vector2((DisplayServer.screen_get_size().x - 480) / uiscale, 80)
 	graph_edit._register_node_movement() #link nodes for tracking position changes for changes tracking
 	

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

@@ -66,6 +66,7 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 			effect.connect("open_help", open_help)
 			if effect.has_signal("node_moved"):
 				effect.node_moved.connect(_auto_link_nodes)
+			effect.dragged.connect(node_position_changed.bind(effect))
 			effect.set_position_offset((control_script.effect_position + graph_edit.scroll_offset) / graph_edit.zoom) #set node to current mouse position in graph edit
 			_register_inputs_in_node(effect) #link sliders for changes tracking
 			_register_node_movement() #link nodes for tracking position changes for changes tracking
@@ -260,6 +261,7 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 					elif param_data.get("uitype", "") == "addremoveinlets":
 						var addremove = addremoveinlets.instantiate()
 						addremove.name = "addremoveinlets"
+						addremove.undo_redo = control_script.undo_redo #link to main undo redo
 						
 						#get parameters
 						var min_inlets = param_data.get("minrange", 0)
@@ -318,6 +320,7 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 			control_script.undo_redo.add_do_reference(graphnode)
 			control_script.undo_redo.add_undo_method(delete_node.bind(graphnode))
 			control_script.undo_redo.commit_action()
+			#graphnode.undo_redo = control_script.undo_redo
 			graphnode.connect("open_help", open_help)
 			graphnode.connect("inlet_removed", Callable(self, "on_inlet_removed"))
 			graphnode.node_moved.connect(_auto_link_nodes)