소스 검색

fixed tooltip bug, added functionality for full help files

Jonathan Higgins 7 달 전
부모
커밋
3795042e70
3개의 변경된 파일103개의 추가작업 그리고 23개의 파일을 삭제
  1. 67 23
      scenes/main/control.gd
  2. 23 0
      scenes/main/control.tscn
  3. 13 0
      scenes/main/process_help.json

+ 67 - 23
scenes/main/control.gd

@@ -22,6 +22,7 @@ var outfilename #links to the user name for outputfile field
 var foldertoggle #links to the reuse folder button
 var lastoutputfolder = "none" #tracks last output folder, this can in future be used to replace global.outfile but i cba right now
 var process_successful #tracks if the last run process was successful
+var help_data := {} #stores help data for each node to display in help popup
 
 # Called when the node enters the scene tree for the first time.
 func _ready() -> void:
@@ -77,6 +78,10 @@ func _ready() -> void:
 			load_graph_edit(path)
 			break
 	
+	var file = FileAccess.open("res://scenes/main/process_help.json", FileAccess.READ)
+	if file:
+		help_data = JSON.parse_string(file.get_as_text())
+	
 func new_patch():
 	#clear old patch
 	graph_edit.clear_connections()
@@ -173,6 +178,8 @@ func _input(event):
 		get_viewport().set_input_as_handled()
 
 	elif event.is_action_pressed("paste_node"):
+		simulate_mouse_click() #hacky fix to stop tooltips getting stuck
+		await get_tree().process_frame
 		paste_copied_nodes()
 		get_viewport().set_input_as_handled()
 	elif event.is_action_pressed("undo"):
@@ -185,29 +192,62 @@ func _input(event):
 			$SaveDialog.popup_centered()
 		else:
 			save_graph_edit(currentfile)
+	
+	if event is InputEventMouseButton and event.pressed:
+		if event.button_index == MOUSE_BUTTON_LEFT and event.double_click:
+			var pos = get_viewport().get_mouse_position()
+			var clicked_node = find_graphedit_node_under(pos)
+			if clicked_node:
+				await get_tree().process_frame #wait a frame to stop nodes jumping across graph edit
+				deselect_all_nodes() #deselect nodes to avoid dragging issues
+				show_help_for_node(clicked_node.get_meta("command"), clicked_node.title)
+
+func find_graphedit_node_under(mouse_pos: Vector2) -> GraphNode:
+	#find the node that was double clicked on
+	for node in graph_edit.get_children():
+		if node is GraphNode and node.get_global_rect().has_point(mouse_pos):
+			return node
+	return null
+
+func deselect_all_nodes():
+	for node in $GraphEdit.get_children():
+		if node is GraphNode:
+			node.selected = false
+			selected_nodes[node] = false
+
+func show_help_for_node(node_name: String, node_title: String):
+	if help_data.has(node_name):
+		var info = help_data[node_name]
+		$HelpWindow.title = node_title
+		$HelpWindow/HelpTitle.text = node_title
+		$HelpWindow/HelpText.text = ""
+		$HelpWindow/HelpText.text += info.get("description", "No help available.")
+		$HelpWindow.show()
+	else:
+		$HelpWindow.title = node_title
+		$HelpWindow/HelpTitle.text = node_title
+		$HelpWindow/HelpText.text = ""
+		$HelpWindow/HelpText.text += "No help found."
+		$HelpWindow.show()
+
+
+func simulate_mouse_click():
+	#simulates clicking the middle mouse button in order to hide any visible tooltips
+	var click_pos = get_viewport().get_mouse_position()
+
+	var down_event := InputEventMouseButton.new()
+	down_event.button_index = MOUSE_BUTTON_MIDDLE
+	down_event.pressed = true
+	down_event.position = click_pos
+	Input.parse_input_event(down_event)
+
+	var up_event := InputEventMouseButton.new()
+	up_event.button_index = MOUSE_BUTTON_MIDDLE
+	up_event.pressed = false
+	up_event.position = click_pos
+	Input.parse_input_event(up_event)
+
 
-#logic for making, connecting, disconnecting, copy pasting and deleteing nodes and connections in GraphEdit
-#mostly taken from https://gdscript.com/solutions/godot-graphnode-and-graphedit-tutorial/
-#func showmenu():
-	##check for mouse input and if menu is already open and then open or close the menu
-	##stores mouse position at time of right click to later place a node in that location
-	#if Input.is_action_just_pressed("open_menu"):
-		#if mainmenu_visible == false:
-			#effect_position = graph_edit.get_local_mouse_position()
-			##$mainmenu.position.x = min(effect_position.x, get_viewport().get_visible_rect().size.x - $mainmenu.size.x)
-			##$mainmenu.position.y = min(effect_position.y, get_viewport().get_visible_rect().size.y - $mainmenu.size.y)
-			#$mainmenu.position.x = clamp(get_viewport().get_mouse_position().x, $mainmenu/select_effect.size.x / 2, get_viewport().get_visible_rect().size.x - ($mainmenu/select_effect.size.x / 2))
-			#$mainmenu.position.y = clamp(get_viewport().get_mouse_position().y, ($mainmenu/select_effect.size.y / 2) + $ColorRect.size.y, get_viewport().get_visible_rect().size.y - ($mainmenu/select_effect.size.y / 2))
-			#print($GraphEdit.scroll_offset)
-			##print(DisplayServer.window_get_size()) #actual window size
-			##print(get_viewport().get_visible_rect().size) # window size asjusted for retina scaling
-			#$mainmenu.show()
-			#mainmenu_visible = true
-		#else:
-			#$mainmenu.hide()
-			#mainmenu_visible = false
-
-# creates nodes from menu
 func _on_button_pressed(button: Button):
 	#close menu
 	$mainmenu.hide()
@@ -220,7 +260,7 @@ func _on_button_pressed(button: Button):
 	effect.set_position_offset((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
-
+	
 	changesmade = true
 
 
@@ -1574,3 +1614,7 @@ func _on_graph_edit_popup_request(at_position: Vector2) -> void:
 	else:
 		$mainmenu.hide()
 		mainmenu_visible = false
+
+
+func _on_help_window_close_requested() -> void:
+	$HelpWindow.hide()

+ 23 - 0
scenes/main/control.tscn

@@ -31,6 +31,7 @@ access = 2
 use_native_dialog = true
 
 [node name="mainmenu" parent="." instance=ExtResource("3_dtf4o")]
+visible = false
 layout_mode = 0
 anchors_preset = 0
 anchor_right = 0.0
@@ -313,6 +314,27 @@ offset_right = 351.0
 offset_bottom = 101.0
 text = "Don't Save"
 
+[node name="HelpWindow" type="Window" parent="."]
+initial_position = 2
+size = Vector2i(600, 400)
+visible = false
+always_on_top = true
+
+[node name="HelpTitle" type="Label" parent="HelpWindow"]
+offset_left = 12.0
+offset_top = 8.0
+offset_right = 588.0
+offset_bottom = 27.0
+theme_override_font_sizes/font_size = 25
+text = "Node Name goes here"
+
+[node name="HelpText" type="RichTextLabel" parent="HelpWindow"]
+offset_left = 12.0
+offset_top = 48.0
+offset_right = 588.0
+offset_bottom = 392.0
+text = "Help Text goes in here"
+
 [connection signal="connection_request" from="GraphEdit" to="." method="_on_graph_edit_connection_request"]
 [connection signal="delete_nodes_request" from="GraphEdit" to="." method="_on_graph_edit_delete_nodes_request"]
 [connection signal="disconnection_request" from="GraphEdit" to="." method="_on_graph_edit_disconnection_request"]
@@ -335,3 +357,4 @@ text = "Don't Save"
 [connection signal="file_selected" from="LoadDialog" to="." method="_on_load_dialog_file_selected"]
 [connection signal="button_down" from="SaveChangesPopup/SaveChanges" to="." method="_on_save_changes_button_down"]
 [connection signal="button_down" from="SaveChangesPopup/DontSaveChanges" to="." method="_on_dont_save_changes_button_down"]
+[connection signal="close_requested" from="HelpWindow" to="." method="_on_help_window_close_requested"]

+ 13 - 0
scenes/main/process_help.json

@@ -0,0 +1,13 @@
+{
+  "inputfile": {
+	"description": 
+"Allows you to load and play a file for processing.
+Here I am testing multiple lines.
+I do not know if this will work.",
+  },
+  "outputfile": {
+	"title": "Output File",
+	"description": "Controls running your thread and plays the output file from the thread.",
+	"category": "Shader"
+  }
+}