open_help.gd 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. extends Node
  2. var control_script
  3. var help_data := {} #stores help data for each node to display in help popup
  4. var shortcuts_data:= {}
  5. var HelpWindowScene = preload("res://scenes/main/help_window.tscn")
  6. func _ready() -> void:
  7. var file = FileAccess.open("res://scenes/main/process_help.json", FileAccess.READ)
  8. if file:
  9. help_data = JSON.parse_string(file.get_as_text())
  10. var shortcuts_file = FileAccess.open("res://scenes/main/shortcuts.json", FileAccess.READ)
  11. if shortcuts_file:
  12. shortcuts_data = JSON.parse_string(shortcuts_file.get_as_text())
  13. func init(main_node: Node) -> void:
  14. control_script = main_node
  15. func show_help_for_node(node_name: String, node_title: String):
  16. #check if there is already a help window open for this node and pop it up instead of making a new one
  17. if is_help_open(node_title):
  18. return
  19. if help_data.has(node_name):
  20. #looks up the help data from the json and stores it in info
  21. var info = help_data[node_name]
  22. #makes an instance of the help_window scene
  23. var help_window = HelpWindowScene.instantiate()
  24. help_window.title = "Help - " + node_title
  25. help_window.get_node("HelpTitle").text = node_title
  26. var output = ""
  27. output += info.get("short_description", "") + "\n\n"
  28. var parameters = info.get("parameters", {})
  29. #checks if there are parameters and if there are places them in a table
  30. if parameters.size() > 0:
  31. output += "[table=3]\n"
  32. output += "[cell][b]Parameter Name[/b][/cell][cell][b]Description[/b][/cell][cell][b]Automatable[/b][/cell]\n"
  33. for key in parameters.keys(): #scans through all parameters
  34. var param = parameters[key]
  35. var paramname = param.get("paramname", "")
  36. var desc = param.get("paramdescription", "")
  37. var automatable = param.get("automatable", false)
  38. var autom_text = "[center]✓[/center]" if automatable else "[center]𐄂[/center]" #replaces true and false with ticks and crosses
  39. output += "[cell]%s[/cell][cell]%s[/cell][cell]%s[/cell]\n" % [paramname, desc, autom_text] #places each param detail into cells of the table
  40. output += "[/table]\n\n" #ends the table
  41. output += "[b]Functionality[/b]\n"
  42. var description_text = info.get("description", "")
  43. output += description_text.strip_edges()
  44. #check if this is a cdp process or a utility and display the cdp process if it is one
  45. var category = info.get("category", "")
  46. if category != "utility":
  47. output += "\n\n[b]CDP Process[/b]\nThis node runs the CDP Process: " + node_name.replace("_", " ")
  48. help_window.get_node("HelpText").bbcode_text = output
  49. help_window.get_node("HelpText").scroll_to_line(0) #scrolls to the first line of the help file just incase
  50. # Add to the current scene tree to show it
  51. get_tree().current_scene.add_child(help_window)
  52. if help_window.content_scale_factor < control_script.uiscale:
  53. help_window.size = help_window.size * control_script.uiscale
  54. help_window.content_scale_factor = control_script.uiscale
  55. help_window.popup()
  56. else:
  57. # If no help available, even though there always should be, show a window saying no help found
  58. var help_window = HelpWindowScene.instance()
  59. help_window.title = "Help - " + node_title
  60. help_window.get_node("HelpTitle").text = node_title
  61. help_window.get_node("HelpText").bbcode_text = "No help found."
  62. get_tree().current_scene.add_child(help_window)
  63. help_window.popup()
  64. func open_keyboard_shortcuts_help():
  65. var title = "Keyboard/Mouse Shortcuts"
  66. #check if there is already a help window open for this node and pop it up instead of making a new one
  67. if is_help_open(title):
  68. return
  69. var help_window = HelpWindowScene.instantiate()
  70. help_window.title = "Help - " + title
  71. help_window.get_node("HelpTitle").text = title
  72. var help_text = "The main shortcuts available in SoundThread\n\n"
  73. help_text += "[table=2]"
  74. for section in shortcuts_data.keys():
  75. help_text += "[cell][b]" + section + "[/b][/cell][cell][/cell]"
  76. var shortcuts = shortcuts_data.get(section, {})
  77. for action in shortcuts.keys():
  78. var shortcut = shortcuts[action]
  79. help_text += "[cell]%s[/cell][cell]%s[/cell]" % [action, shortcut]
  80. help_text += "[cell] [/cell][cell][/cell]"
  81. help_text += "[/table]\n\n"
  82. help_text += "Note: controls for navigating a thread can be swapped in the settings."
  83. if OS.get_name() == "macOS":
  84. help_text = help_text.replace("Ctrl", "Cmd")
  85. help_window.get_node("HelpText").bbcode_text = help_text
  86. help_window.get_node("HelpText").scroll_to_line(0) #scrolls to the first line of the help file just incase
  87. # Add to the current scene tree to show it
  88. get_tree().current_scene.add_child(help_window)
  89. if help_window.content_scale_factor < control_script.uiscale:
  90. help_window.size = help_window.size * control_script.uiscale
  91. help_window.content_scale_factor = control_script.uiscale
  92. help_window.popup()
  93. func is_help_open(node_title: String) -> bool:
  94. for child in get_tree().current_scene.get_children():
  95. if child is Window and child.title == "Help - " + node_title:
  96. # Found existing window, bring it to front
  97. if child.is_visible():
  98. child.hide()
  99. child.popup()
  100. else:
  101. child.popup()
  102. return true
  103. return false