Browse Source

added selectable and deleteable cables

Jonathan Higgins 3 months ago
parent
commit
b340291911

+ 1 - 0
Global/config_handler.gd

@@ -18,6 +18,7 @@ func _ready():
 	ensure_setting("interface_settings", "theme", 0)
 	ensure_setting("interface_settings", "theme_custom_colour", "#865699")
 	ensure_setting("interface_settings", "invert_theme", false)
+	ensure_setting("interface_settings", "high_contrast_selected_cables", false)
 	ensure_setting("interface_settings", "swap_zoom_and_move", false)
 	ensure_setting("interface_settings", "delete_intermediate", true)
 	ensure_setting("interface_settings", "reuse_output_folder", true)

+ 1 - 0
scenes/main/control.tscn

@@ -577,6 +577,7 @@ text = "Stop Running Thread"
 [connection signal="copy_nodes_request" from="GraphEdit" to="GraphEdit" method="_on_copy_nodes_request"]
 [connection signal="delete_nodes_request" from="GraphEdit" to="GraphEdit" method="_on_graph_edit_delete_nodes_request"]
 [connection signal="disconnection_request" from="GraphEdit" to="GraphEdit" method="_on_graph_edit_disconnection_request"]
+[connection signal="gui_input" from="GraphEdit" to="GraphEdit" method="_on_gui_input"]
 [connection signal="node_deselected" from="GraphEdit" to="GraphEdit" method="_on_graph_edit_node_deselected"]
 [connection signal="node_selected" from="GraphEdit" to="GraphEdit" method="_on_graph_edit_node_selected"]
 [connection signal="paste_nodes_request" from="GraphEdit" to="GraphEdit" method="_on_paste_nodes_request"]

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

@@ -637,9 +637,6 @@ func _on_graph_edit_popup_request(at_position: Vector2) -> void:
 		$SearchMenu/VBoxContainer/ReplaceLabel.hide()
 		$SearchMenu.replace_node = false
 	
-	var closest_connection = graph_edit.get_closest_connection_at_point(effect_position)
-	print("closest_connection")
-	print(closest_connection)
 	#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)
 	var clamped_y = clamp(mouse_screen_pos.y, window_screen_pos.y, window_screen_pos.y + window_size.y - (420 * DisplayServer.screen_get_scale()))

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

@@ -11,6 +11,10 @@ var node_data = {} #stores json with all nodes in it
 var valueslider = preload("res://scenes/Nodes/valueslider.tscn") #slider scene for use in nodes
 var addremoveinlets = preload("res://scenes/Nodes/addremoveinlets.tscn") #add remove inlets scene for use in nodes
 var node_logic = preload("res://scenes/Nodes/node_logic.gd") #load the script logic
+var selected_cables:= [] #used to track which cables are selected for changing colour and for deletion
+var theme_background #used to track if the theme has changed and if so change the cable selection colour
+var theme_custom_background
+var high_contrast_cables
 
 
 # Called when the node enters the scene tree for the first time.
@@ -26,6 +30,12 @@ func _ready() -> void:
 			node_data = result
 		else:
 			push_error("Invalid JSON")
+			
+	var interface_settings = ConfigHandler.load_interface_settings()
+	theme_background = interface_settings.theme
+	theme_custom_background = interface_settings.theme_custom_colour
+	high_contrast_cables = interface_settings.high_contrast_selected_cables
+	set_cable_colour(interface_settings.theme)
 
 func init(main_node: Node, graphedit: GraphEdit, openhelp: Callable, multipleconnections: Window) -> void:
 	control_script = main_node
@@ -638,3 +648,89 @@ func _swap_node(old_node: GraphNode, command: String):
 	
 	
 	
+
+
+func _on_gui_input(event: InputEvent) -> void:
+	#check if this is an unhandled mouse click
+	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
+		
+		#get dictionary of a cable if nearby
+		var closest_connection = get_closest_connection_at_point(get_local_mouse_position())
+		
+		#check if there is anything in that dictionary
+		if closest_connection.size() > 0:
+			#check if the background has changed colour for highlighted cable colour
+			var interface_settings = ConfigHandler.load_interface_settings()
+			if interface_settings.theme != theme_background or interface_settings.theme_custom_colour != theme_custom_background or interface_settings.high_contrast_selected_cables != high_contrast_cables:
+				#if bg has changed colour since last cable highlight reset to new bg and change cable colour
+				theme_background = interface_settings.theme
+				theme_custom_background = interface_settings.theme_custom_colour
+				high_contrast_cables = interface_settings.high_contrast_selected_cables
+				set_cable_colour(interface_settings.theme)
+				
+			#get details of nearby cable
+			var from_node = closest_connection.from_node
+			var from_port = closest_connection.from_port
+			var to_node = closest_connection.to_node
+			var to_port = closest_connection.to_port
+			
+			#check if user was holding shift and if so allow for multiple cables to be selected
+			if event.shift_pressed:
+				selected_cables.append(closest_connection)
+				set_connection_activity(from_node, from_port, to_node, to_port, 1)
+			
+			#if user double clicked unselect all cables and delete the nearest cable
+			elif event.double_click:
+					for conn in selected_cables:
+						set_connection_activity(conn.from_node, conn.from_port, conn.to_node, conn.to_port, 0)
+					_on_graph_edit_disconnection_request(from_node, from_port, to_node, to_port)
+					
+			#else just a single click, unselect any previously selected cables and select just the nearest
+			else:
+				for conn in selected_cables:
+					set_connection_activity(conn.from_node, conn.from_port, conn.to_node, conn.to_port, 0)
+				selected_cables = []
+				selected_cables.append(closest_connection)
+				set_connection_activity(from_node, from_port, to_node, to_port, 1)
+		
+		#user didnt click on a cable unselect all cables
+		else:
+			for conn in selected_cables:
+				set_connection_activity(conn.from_node, conn.from_port, conn.to_node, conn.to_port, 0)
+			selected_cables = []
+			
+	#if this is an unhandled delete check if there are any cables selected and deleted them
+	if event is InputEventKey and event.pressed:
+		if (event.keycode == KEY_BACKSPACE or event.keycode == KEY_DELETE) and selected_cables.size() > 0:
+			for conn in selected_cables:
+				_on_graph_edit_disconnection_request(conn.from_node, conn.from_port, conn.to_node, conn.to_port)
+				selected_cables = []
+	
+func set_cable_colour(theme_colour: int):
+	var background_colour
+	var cable_colour
+	var interface_settings = ConfigHandler.load_interface_settings()
+	match theme_colour:
+		0:
+			background_colour = Color("#2f4f4e")
+		1:
+			background_colour = Color("#000807")
+		2:
+			background_colour = Color("#98d4d2")
+		3:
+			background_colour = Color(interface_settings.theme_custom_colour)
+			
+	if interface_settings.high_contrast_selected_cables:
+		#180 colour shift from background and up sv
+		cable_colour = Color.from_hsv(fposmod(background_colour.h + 0.5, 1.0), clamp(background_colour.s + 0.2, 0, 1), clamp(background_colour.v + 0.2, 0, 1))
+		var luminance = 0.299 * background_colour.r + 0.587 * background_colour.g + 0.114 * background_colour.b
+		if luminance > 0.5 and cable_colour.get_luminance() > 0.5:
+			cable_colour = cable_colour.darkened(0.4)
+		elif luminance <= 0.5 and cable_colour.get_luminance() < 0.5:
+			#increase s and v again
+			cable_colour = Color.from_hsv(cable_colour.h, clamp(cable_colour.s + 0.2, 0, 0.8), clamp(cable_colour.v + 0.2, 0, 0.8))
+	else:
+		#keep hue but up saturation and variance
+		cable_colour = Color.from_hsv(background_colour.h, clamp(background_colour.s + 0.2, 0, 1), clamp(background_colour.v + 0.2, 0, 1))
+	#overide theme for cable highlight
+	add_theme_color_override("activity", cable_colour)

+ 5 - 0
scenes/main/scripts/settings.gd

@@ -29,6 +29,7 @@ func _on_about_to_popup() -> void:
 	$VBoxContainer/HBoxContainer5/ThemeList.select(interface_settings.theme, true)
 	$VBoxContainer/HBoxContainer/CustomColourPicker.color = Color(interface_settings.theme_custom_colour)
 	$VBoxContainer/invert_ui_container/InvertUI.button_pressed = interface_settings.invert_theme
+	$VBoxContainer/high_contrast_cables_container/HighContrastCablesToggle.button_pressed = interface_settings.high_contrast_selected_cables
 	$VBoxContainer/HBoxContainer8/SwapZoomAndMoveToggle.button_pressed = interface_settings.swap_zoom_and_move
 	$VBoxContainer/HBoxContainer2/PvocWarning.button_pressed = interface_settings.disable_pvoc_warning
 	$VBoxContainer/HBoxContainer6/ProgressBar.button_pressed = interface_settings.disable_progress_bar
@@ -83,3 +84,7 @@ func _on_invert_ui_toggled(toggled_on: bool) -> void:
 func _on_swap_zoom_and_move_toggle_toggled(toggled_on: bool) -> void:
 	ConfigHandler.save_interface_settings("swap_zoom_and_move", toggled_on)
 	swap_zoom_and_move.emit(toggled_on)
+
+
+func _on_high_contrast_cables_toggle_toggled(toggled_on: bool) -> void:
+	ConfigHandler.save_interface_settings("high_contrast_selected_cables", toggled_on)

+ 14 - 2
scenes/main/settings.tscn

@@ -7,7 +7,7 @@
 auto_translate_mode = 1
 title = "SoundThread Settings"
 initial_position = 2
-size = Vector2i(500, 516)
+size = Vector2i(500, 545)
 transient = true
 unresizable = true
 always_on_top = true
@@ -15,7 +15,7 @@ script = ExtResource("1_uey6c")
 
 [node name="ColorRect" type="ColorRect" parent="." groups=["invertable_background"]]
 offset_right = 506.0
-offset_bottom = 522.0
+offset_bottom = 550.0
 color = Color(0.101961, 0.101961, 0.101961, 0.6)
 script = ExtResource("2_bym2s")
 
@@ -107,6 +107,17 @@ text = "Invert UI colours:"
 layout_mode = 2
 size_flags_horizontal = 3
 
+[node name="high_contrast_cables_container" type="HBoxContainer" parent="VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="VBoxContainer/high_contrast_cables_container"]
+layout_mode = 2
+text = "High Contrast Selected Cables:"
+
+[node name="HighContrastCablesToggle" type="CheckButton" parent="VBoxContainer/high_contrast_cables_container"]
+layout_mode = 2
+size_flags_horizontal = 3
+
 [node name="Controls" type="Label" parent="VBoxContainer"]
 layout_mode = 2
 theme_override_font_sizes/font_size = 18
@@ -179,6 +190,7 @@ size_flags_horizontal = 3
 [connection signal="item_selected" from="VBoxContainer/HBoxContainer5/ThemeList" to="." method="_on_theme_list_item_selected"]
 [connection signal="color_changed" from="VBoxContainer/HBoxContainer/CustomColourPicker" to="." method="_on_custom_colour_picker_color_changed"]
 [connection signal="toggled" from="VBoxContainer/invert_ui_container/InvertUI" to="." method="_on_invert_ui_toggled"]
+[connection signal="toggled" from="VBoxContainer/high_contrast_cables_container/HighContrastCablesToggle" to="." method="_on_high_contrast_cables_toggle_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer8/SwapZoomAndMoveToggle" to="." method="_on_swap_zoom_and_move_toggle_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer2/PvocWarning" to="." method="_on_pvoc_warning_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer6/ProgressBar" to="." method="_on_progress_bar_toggled"]

+ 1 - 1
theme/main_theme.tres

@@ -1223,7 +1223,7 @@ CodeEdit/styles/completion = SubResource("StyleBoxFlat_py0i1")
 CodeEdit/styles/focus = SubResource("StyleBoxFlat_sxwih")
 CodeEdit/styles/normal = SubResource("StyleBoxFlat_rt4o7")
 CodeEdit/styles/read_only = SubResource("StyleBoxFlat_qnold")
-GraphEdit/colors/activity = Color(1, 1, 1, 0.54902)
+GraphEdit/colors/activity = Color(0.366594, 0.366595, 0.366595, 1)
 GraphEdit/colors/connection_hover_tint_color = Color(0, 0, 0, 0.3)
 GraphEdit/colors/connection_rim_color = Color(0.1, 0.1, 0.1, 0.6)
 GraphEdit/colors/connection_valid_target_tint_color = Color(1, 1, 1, 0.4)