explore_menu.gd 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 output nodes
  23. if 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. elif subcategory == "reverb":
  41. container = $"Control/select_effect/Time Domain/Reverb and Delay/MarginContainer/ScrollContainer/ReverbContainer"
  42. elif subcategory == "synthesis":
  43. container = $"Control/select_effect/Time Domain/Synthesis/MarginContainer/ScrollContainer/SynthesisContainer"
  44. else:
  45. continue
  46. elif category == "pvoc":
  47. if subcategory == "convert":
  48. container = $"Control/select_effect/Frequency Domain/Convert/MarginContainer/ScrollContainer/PVOCConvertContainer"
  49. elif subcategory == "amplitude" or subcategory == "pitch":
  50. container = $"Control/select_effect/Frequency Domain/Amplitude and Pitch/MarginContainer/ScrollContainer/PVOCAmplitudePitchContainer"
  51. elif subcategory == "combine":
  52. container = $"Control/select_effect/Frequency Domain/Combine/MarginContainer/ScrollContainer/PVOCCombineContainer"
  53. elif subcategory == "formants":
  54. container = $"Control/select_effect/Frequency Domain/Formants/MarginContainer/ScrollContainer/PVOCFormantsContainer"
  55. elif subcategory == "time":
  56. container = $"Control/select_effect/Frequency Domain/Time/MarginContainer/ScrollContainer/PVOCTimeContainer"
  57. elif subcategory == "spectrum":
  58. container = $"Control/select_effect/Frequency Domain/Spectrum/MarginContainer/ScrollContainer/PVOCSpectrumContainer"
  59. else:
  60. continue
  61. elif category == "utility":
  62. container = $Control/select_effect/Utilities/SoundThread/MarginContainer/ScrollContainer/UtilityContainer
  63. else:
  64. continue
  65. var hbox = HBoxContainer.new()
  66. var label = RichTextLabel.new()
  67. var helpbtn = Button.new()
  68. var makebtn = Button.new()
  69. var margin = MarginContainer.new()
  70. hbox.size.x = container.size.x
  71. label.bbcode_enabled = true
  72. label.text = "[b]%s[/b]\n%s" % [title, short_desc]
  73. label.set_h_size_flags(Control.SIZE_EXPAND_FILL)
  74. label.set_v_size_flags(Control.SIZE_EXPAND_FILL)
  75. label.fit_content = true
  76. helpbtn.text = "?"
  77. helpbtn.tooltip_text = "Open help for " + title
  78. helpbtn.custom_minimum_size = Vector2(40, 40)
  79. helpbtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  80. helpbtn.connect("pressed", Callable(self, "_open_help").bind(key, title)) #pass key (process name) when button is pressed
  81. makebtn.text = "+"
  82. makebtn.tooltip_text = "Add " + title + " to thread"
  83. makebtn.custom_minimum_size = Vector2(40, 40)
  84. makebtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  85. makebtn.connect("pressed", Callable(self, "_make_node").bind(key)) #pass key (process name) when button is pressed
  86. margin.add_theme_constant_override("margin_bottom", 3)
  87. container.add_child(hbox)
  88. hbox.add_child(label)
  89. hbox.add_child(helpbtn)
  90. hbox.add_child(makebtn)
  91. container.add_child(margin)
  92. func _on_about_to_popup() -> void:
  93. fill_search("")
  94. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".clear()
  95. if $Control/select_effect.current_tab == 3:
  96. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".grab_focus()
  97. func fill_search(filter: String):
  98. # Remove all existing items from the VBoxContainer
  99. var container = $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/ScrollContainer/ItemContainer"
  100. for child in container.get_children():
  101. child.queue_free()
  102. var filters = filter.to_lower().split(" ", false)
  103. for key in node_data.keys():
  104. var item = node_data[key]
  105. var title = item.get("title", "")
  106. #filter out output node
  107. if title == "Output File":
  108. continue
  109. var category = item.get("category", "")
  110. var subcategory = item.get("subcategory", "")
  111. var short_desc = item.get("short_description", "")
  112. var command = key.replace("_", " ")
  113. # Combine all searchable text into one lowercase string
  114. var searchable_text = "%s %s %s %s %s" % [title, short_desc, category, subcategory, key]
  115. searchable_text = searchable_text.to_lower()
  116. # If filter is not empty, skip non-matches populate all other buttons
  117. if filter != "":
  118. var match_all_words = true
  119. for word in filters:
  120. if word != "" and not searchable_text.findn(word) != -1:
  121. match_all_words = false
  122. break
  123. if not match_all_words:
  124. continue
  125. var hbox = HBoxContainer.new()
  126. var label = RichTextLabel.new()
  127. var helpbtn = Button.new()
  128. var makebtn = Button.new()
  129. var margin = MarginContainer.new()
  130. hbox.size.x = container.size.x
  131. label.bbcode_enabled = true
  132. label.text = "[b]%s[/b]\n%s" % [title, short_desc]
  133. label.set_h_size_flags(Control.SIZE_EXPAND_FILL)
  134. label.set_v_size_flags(Control.SIZE_EXPAND_FILL)
  135. label.fit_content = true
  136. helpbtn.text = "?"
  137. helpbtn.tooltip_text = "Open help for " + title
  138. helpbtn.custom_minimum_size = Vector2(40, 40)
  139. helpbtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  140. helpbtn.connect("pressed", Callable(self, "_open_help").bind(key, title)) #pass key (process name) when button is pressed
  141. makebtn.text = "+"
  142. makebtn.tooltip_text = "Add " + title + " to thread"
  143. makebtn.custom_minimum_size = Vector2(40, 40)
  144. makebtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  145. makebtn.connect("pressed", Callable(self, "_make_node").bind(key)) #pass key (process name) when button is pressed
  146. margin.add_theme_constant_override("margin_bottom", 3)
  147. container.add_child(hbox)
  148. hbox.add_child(label)
  149. hbox.add_child(helpbtn)
  150. hbox.add_child(makebtn)
  151. container.add_child(margin)
  152. func _on_search_bar_text_changed(new_text: String) -> void:
  153. fill_search(new_text)
  154. pass
  155. func _make_node(key: String):
  156. make_node.emit(key) # send out signal to main patch
  157. self.hide()
  158. func _open_help(key: String, title: String):
  159. open_help.emit(key, title) # send out signal to main patch
  160. self.hide()
  161. func _on_select_effect_tab_changed(tab: int) -> void:
  162. if tab == 3:
  163. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".grab_focus()