explore_menu.gd 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 == "amppitch":
  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. for key in node_data.keys():
  101. var item = node_data[key]
  102. var title = item.get("title", "")
  103. #filter out output node
  104. if title == "Output File":
  105. continue
  106. var category = item.get("category", "")
  107. var subcategory = item.get("subcategory", "")
  108. var short_desc = item.get("short_description", "")
  109. # If filter is not empty, skip non-matches populate all other buttons
  110. if filter != "":
  111. var filter_lc = filter.to_lower()
  112. 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()):
  113. continue
  114. var hbox = HBoxContainer.new()
  115. var label = RichTextLabel.new()
  116. var helpbtn = Button.new()
  117. var makebtn = Button.new()
  118. var margin = MarginContainer.new()
  119. hbox.size.x = container.size.x
  120. label.bbcode_enabled = true
  121. label.text = "[b]%s[/b]\n%s" % [title, short_desc]
  122. label.set_h_size_flags(Control.SIZE_EXPAND_FILL)
  123. label.set_v_size_flags(Control.SIZE_EXPAND_FILL)
  124. label.fit_content = true
  125. helpbtn.text = "?"
  126. helpbtn.tooltip_text = "Open help for " + title
  127. helpbtn.custom_minimum_size = Vector2(40, 40)
  128. helpbtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  129. helpbtn.connect("pressed", Callable(self, "_open_help").bind(key, title)) #pass key (process name) when button is pressed
  130. makebtn.text = "+"
  131. makebtn.tooltip_text = "Add " + title + " to thread"
  132. makebtn.custom_minimum_size = Vector2(40, 40)
  133. makebtn.set_h_size_flags(Control.SIZE_SHRINK_CENTER)
  134. makebtn.connect("pressed", Callable(self, "_make_node").bind(key)) #pass key (process name) when button is pressed
  135. margin.add_theme_constant_override("margin_bottom", 3)
  136. container.add_child(hbox)
  137. hbox.add_child(label)
  138. hbox.add_child(helpbtn)
  139. hbox.add_child(makebtn)
  140. container.add_child(margin)
  141. func _on_search_bar_text_changed(new_text: String) -> void:
  142. fill_search(new_text)
  143. pass
  144. func _make_node(key: String):
  145. make_node.emit(key) # send out signal to main patch
  146. self.hide()
  147. func _open_help(key: String, title: String):
  148. open_help.emit(key, title) # send out signal to main patch
  149. self.hide()
  150. func _on_select_effect_tab_changed(tab: int) -> void:
  151. if tab == 3:
  152. $"Control/select_effect/Search/Search for a process in SoundThread/MarginContainer/VBoxContainer/SearchBar".grab_focus()