explore_menu.gd 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. extends Window
  2. var node_data = {} #stores node data for each node to display in help popup
  3. signal make_node(command)
  4. signal open_help(command)
  5. func _ready() -> void:
  6. $"Control/select_effect/Time Domain".show()
  7. $"Control/select_effect/Time Domain/Distort".show()
  8. $"Control/select_effect/Frequency Domain/Convert".show()
  9. #parse json
  10. var file = FileAccess.open("res://scenes/main/process_help.json", FileAccess.READ)
  11. if file:
  12. var result = JSON.parse_string(file.get_as_text())
  13. if typeof(result) == TYPE_DICTIONARY:
  14. node_data = result
  15. else:
  16. push_error("Invalid JSON")
  17. fill_menu()
  18. func fill_menu():
  19. for key in node_data.keys():
  20. var item = node_data[key]
  21. var title = item.get("title", "")
  22. #filter out input and output nodes
  23. if title == "Input File" or title == "Output File":
  24. continue
  25. var category = item.get("category", "")
  26. var subcategory = item.get("subcategory", "")
  27. var short_desc = item.get("short_description", "")
  28. var container
  29. if category == "time":
  30. if subcategory == "distort":
  31. container = $"Control/select_effect/Time Domain/Distort/MarginContainer/ScrollContainer/DistortContainer"
  32. elif subcategory == "extend":
  33. container = $"Control/select_effect/Time Domain/Extend/MarginContainer/ScrollContainer/ExtendContainer"
  34. elif subcategory == "filter":
  35. container = $"Control/select_effect/Time Domain/Filter/MarginContainer/ScrollContainer/FilterContainer"
  36. elif subcategory == "granulate":
  37. container = $"Control/select_effect/Time Domain/Granulate/MarginContainer/ScrollContainer/GranulateContainer"
  38. elif subcategory == "misc":
  39. container = $"Control/select_effect/Time Domain/Misc/MarginContainer/ScrollContainer/MiscContainer"
  40. else:
  41. continue
  42. elif category == "pvoc":
  43. if subcategory == "convert":
  44. container = $"Control/select_effect/Frequency Domain/Convert/MarginContainer/ScrollContainer/PVOCConvertContainer"
  45. elif subcategory == "process":
  46. container = $"Control/select_effect/Frequency Domain/Process/MarginContainer/ScrollContainer/PVOCProcessContainer"
  47. else:
  48. continue
  49. elif category == "utility":
  50. container = $Control/select_effect/Utilities/SoundThread/MarginContainer/ScrollContainer/UtilityContainer
  51. else:
  52. continue
  53. var hbox = HBoxContainer.new()
  54. var label = RichTextLabel.new()
  55. var helpbtn = Button.new()
  56. var makebtn = Button.new()
  57. var margin = MarginContainer.new()
  58. hbox.size.x = container.size.x
  59. label.bbcode_enabled = true
  60. label.text = "[b]%s[/b]\n%s" % [title, short_desc]
  61. label.set_h_size_flags(Control.SIZE_EXPAND_FILL)
  62. label.set_v_size_flags(Control.SIZE_EXPAND_FILL)
  63. label.fit_content = true
  64. helpbtn.text = "?"
  65. helpbtn.tooltip_text = "Open help for " + title
  66. helpbtn.custom_minimum_size = Vector2(40, 40)
  67. helpbtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  68. helpbtn.connect("pressed", Callable(self, "_open_help").bind(key, title)) #pass key (process name) when button is pressed
  69. makebtn.text = "+"
  70. makebtn.tooltip_text = "Add " + title + " to thread"
  71. makebtn.custom_minimum_size = Vector2(40, 40)
  72. makebtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  73. makebtn.connect("pressed", Callable(self, "_make_node").bind(key)) #pass key (process name) when button is pressed
  74. margin.add_theme_constant_override("margin_bottom", 3)
  75. container.add_child(hbox)
  76. hbox.add_child(label)
  77. hbox.add_child(helpbtn)
  78. hbox.add_child(makebtn)
  79. container.add_child(margin)
  80. func _on_about_to_popup() -> void:
  81. fill_search("")
  82. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".clear()
  83. if $Control/select_effect.current_tab == 3:
  84. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".grab_focus()
  85. func fill_search(filter: String):
  86. # Remove all existing items from the VBoxContainer
  87. var container = $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/ScrollContainer/ItemContainer"
  88. for child in container.get_children():
  89. child.queue_free()
  90. for key in node_data.keys():
  91. var item = node_data[key]
  92. var title = item.get("title", "")
  93. #filter out input and output nodes
  94. if title == "Input File" or title == "Output File":
  95. continue
  96. var category = item.get("category", "")
  97. var subcategory = item.get("subcategory", "")
  98. var short_desc = item.get("short_description", "")
  99. # If filter is not empty, skip non-matches populate all other buttons
  100. if filter != "":
  101. var filter_lc = filter.to_lower()
  102. if not (filter_lc in title.to_lower() or filter_lc in short_desc.to_lower() or filter_lc in category.to_lower() or filter_lc in subcategory.to_lower()):
  103. continue
  104. var hbox = HBoxContainer.new()
  105. var label = RichTextLabel.new()
  106. var helpbtn = Button.new()
  107. var makebtn = Button.new()
  108. var margin = MarginContainer.new()
  109. hbox.size.x = container.size.x
  110. label.bbcode_enabled = true
  111. label.text = "[b]%s[/b]\n%s" % [title, short_desc]
  112. label.set_h_size_flags(Control.SIZE_EXPAND_FILL)
  113. label.set_v_size_flags(Control.SIZE_EXPAND_FILL)
  114. label.fit_content = true
  115. helpbtn.text = "?"
  116. helpbtn.tooltip_text = "Open help for " + title
  117. helpbtn.custom_minimum_size = Vector2(40, 40)
  118. helpbtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  119. helpbtn.connect("pressed", Callable(self, "_open_help").bind(key, title)) #pass key (process name) when button is pressed
  120. makebtn.text = "+"
  121. makebtn.tooltip_text = "Add " + title + " to thread"
  122. makebtn.custom_minimum_size = Vector2(40, 40)
  123. makebtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  124. makebtn.connect("pressed", Callable(self, "_make_node").bind(key)) #pass key (process name) when button is pressed
  125. margin.add_theme_constant_override("margin_bottom", 3)
  126. container.add_child(hbox)
  127. hbox.add_child(label)
  128. hbox.add_child(helpbtn)
  129. hbox.add_child(makebtn)
  130. container.add_child(margin)
  131. func _on_search_bar_text_changed(new_text: String) -> void:
  132. fill_search(new_text)
  133. pass
  134. func _make_node(key: String):
  135. make_node.emit(key) # send out signal to main patch
  136. self.hide()
  137. func _open_help(key: String, title: String):
  138. open_help.emit(key, title) # send out signal to main patch
  139. self.hide()
  140. func _on_select_effect_tab_changed(tab: int) -> void:
  141. if tab == 3:
  142. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".grab_focus()