explore_menu.gd 7.3 KB

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