open_help.gd 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. extends Node
  2. var control_script
  3. var help_data := {} #stores help data for each node to display in help popup
  4. var HelpWindowScene = preload("res://scenes/main/help_window.tscn")
  5. func _ready() -> void:
  6. var file = FileAccess.open("res://scenes/main/process_help.json", FileAccess.READ)
  7. if file:
  8. help_data = JSON.parse_string(file.get_as_text())
  9. func init(main_node: Node) -> void:
  10. control_script = main_node
  11. func show_help_for_node(node_name: String, node_title: String):
  12. #check if there is already a help window open for this node and pop it up instead of making a new one
  13. for child in get_tree().current_scene.get_children():
  14. if child is Window and child.title == "Help - " + node_title:
  15. # Found existing window, bring it to front
  16. if child.is_visible():
  17. child.hide()
  18. child.popup()
  19. else:
  20. child.popup()
  21. return
  22. if help_data.has(node_name):
  23. #looks up the help data from the json and stores it in info
  24. var info = help_data[node_name]
  25. #makes an instance of the help_window scene
  26. var help_window = HelpWindowScene.instantiate()
  27. help_window.title = "Help - " + node_title
  28. help_window.get_node("HelpTitle").text = node_title
  29. var output = ""
  30. output += info.get("short_description", "") + "\n\n"
  31. var parameters = info.get("parameters", {})
  32. #checks if there are parameters and if there are places them in a table
  33. if parameters.size() > 0:
  34. output += "[table=3]\n"
  35. output += "[cell][b]Parameter Name[/b][/cell][cell][b]Description[/b][/cell][cell][b]Automatable[/b][/cell]\n"
  36. for key in parameters.keys(): #scans through all parameters
  37. var param = parameters[key]
  38. var name = param.get("paramname", "")
  39. var desc = param.get("paramdescription", "")
  40. var automatable = param.get("automatable", false)
  41. var autom_text = "[center]✓[/center]" if automatable else "[center]𐄂[/center]" #replaces true and false with ticks and crosses
  42. output += "[cell]%s[/cell][cell]%s[/cell][cell]%s[/cell]\n" % [name, desc, autom_text] #places each param detail into cells of the table
  43. output += "[/table]\n\n" #ends the table
  44. output += "[b]Functionality[/b]\n"
  45. var description_text = info.get("description", "")
  46. output += description_text.strip_edges()
  47. #check if this is a cdp process or a utility and display the cdp process if it is one
  48. var category = info.get("category", "")
  49. if category != "utility":
  50. output += "\n\n[b]CDP Process[/b]\nThis node runs the CDP Process: " + node_name.replace("_", " ")
  51. help_window.get_node("HelpText").bbcode_text = output
  52. help_window.get_node("HelpText").scroll_to_line(0) #scrolls to the first line of the help file just incase
  53. # Add to the current scene tree to show it
  54. get_tree().current_scene.add_child(help_window)
  55. if help_window.content_scale_factor < control_script.uiscale:
  56. help_window.size = help_window.size * control_script.uiscale
  57. help_window.content_scale_factor = control_script.uiscale
  58. help_window.popup()
  59. else:
  60. # If no help available, even though there always should be, show a window saying no help found
  61. var help_window = HelpWindowScene.instance()
  62. help_window.title = "Help - " + node_title
  63. help_window.get_node("HelpTitle").text = node_title
  64. help_window.get_node("HelpText").bbcode_text = "No help found."
  65. get_tree().current_scene.add_child(help_window)
  66. help_window.popup()