control.gd 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. extends Control
  2. var mainmenu_visible : bool = false #used to test if mainmenu is open
  3. var effect_position = Vector2(40,40) #tracks mouse position for node placement offset
  4. @onready var graph_edit = $GraphEdit
  5. var cdpprogs_location #stores the cdp programs location from user prefs for easy access
  6. var delete_intermediate_outputs # tracks state of delete intermediate outputs toggle
  7. @onready var console_output: RichTextLabel = $Console/ConsoleOutput
  8. var undo_redo := UndoRedo.new()
  9. var output_audio_player #tracks the node that is the current output player for linking
  10. var input_audio_player #tracks node that is the current input player for linking
  11. var currentfile = "none" #tracks dir of currently loaded file for saving
  12. var changesmade = false #tracks if user has made changes to the currently loaded save file
  13. var savestate # tracks what the user is trying to do when savechangespopup is called
  14. var helpfile #tracks which help file the user was trying to load when savechangespopup is called
  15. var outfilename #links to the user name for outputfile field
  16. var foldertoggle #links to the reuse folder button
  17. var lastoutputfolder = "none" #tracks last output folder, this can in future be used to replace global.outfile but i cba right now
  18. var uiscale = 1.0 #tracks scaling for retina screens
  19. var use_anyway #used to store the folder selected for cdprogs when it appears the wrong folder is selected but the user wants to use it anyway
  20. #scripts
  21. var open_help
  22. var run_thread
  23. var save_load
  24. # Called when the node enters the scene tree for the first time.
  25. func _ready() -> void:
  26. Nodes.hide()
  27. $mainmenu.hide()
  28. $NoLocationPopup.hide()
  29. $Console.hide()
  30. $NoInputPopup.hide()
  31. $MultipleConnectionsPopup.hide()
  32. $AudioSettings.hide()
  33. $AudioDevicePopup.hide()
  34. $SearchMenu.hide()
  35. $Settings.hide()
  36. $ProgressWindow.hide()
  37. $WrongFolderPopup.hide()
  38. $SaveChangesPopup.hide()
  39. $SaveDialog.access = FileDialog.ACCESS_FILESYSTEM
  40. $SaveDialog.file_mode = FileDialog.FILE_MODE_SAVE_FILE
  41. $SaveDialog.filters = ["*.thd"]
  42. $LoadDialog.access = FileDialog.ACCESS_FILESYSTEM
  43. $LoadDialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
  44. $LoadDialog.filters = ["*.thd"]
  45. get_tree().set_auto_accept_quit(false) #disable closing the app with the x and instead handle it internally
  46. load_scripts()
  47. make_signal_connections()
  48. check_user_preferences()
  49. hidpi_adjustment()
  50. new_patch()
  51. load_from_filesystem()
  52. check_cdp_location_set()
  53. func load_scripts():
  54. #load and initialise scripts
  55. open_help = preload("res://scenes/main/scripts/open_help.gd").new()
  56. open_help.init(self)
  57. add_child(open_help)
  58. run_thread = preload("res://scenes/main/scripts/run_thread.gd").new()
  59. run_thread.init(self, $ProgressWindow, $ProgressWindow/ProgressLabel, $ProgressWindow/ProgressBar, $GraphEdit, $Console, $Console/ConsoleOutput)
  60. add_child(run_thread)
  61. graph_edit.init(self, $GraphEdit, Callable(open_help, "show_help_for_node"), $MultipleConnectionsPopup)
  62. save_load = preload("res://scenes/main/scripts/save_load.gd").new()
  63. save_load.init(self, $GraphEdit, Callable(open_help, "show_help_for_node"), Callable(graph_edit, "_register_node_movement"), Callable(graph_edit, "_register_inputs_in_node"), Callable(self, "link_output"))
  64. add_child(save_load)
  65. func make_signal_connections():
  66. get_node("SearchMenu").make_node.connect(graph_edit._make_node)
  67. get_node("mainmenu").make_node.connect(graph_edit._make_node)
  68. get_node("mainmenu").open_help.connect(open_help.show_help_for_node)
  69. get_node("Settings").open_cdp_location.connect(show_cdp_location)
  70. get_node("Settings").console_on_top.connect(change_console_settings)
  71. func hidpi_adjustment():
  72. #checks if display is hidpi and scales ui accordingly hidpi - 144
  73. if DisplayServer.screen_get_dpi(0) >= 144:
  74. uiscale = 2.0
  75. get_window().content_scale_factor = uiscale
  76. #goes through popup_windows group and scales all popups and resizes them
  77. for window in get_tree().get_nodes_in_group("popup_windows"):
  78. window.size = window.size * uiscale
  79. window.content_scale_factor = uiscale
  80. func load_from_filesystem():
  81. #checks if user has opened a file from the system file menu and loads it
  82. var args = OS.get_cmdline_args()
  83. for arg in args:
  84. var path = arg.strip_edges()
  85. if FileAccess.file_exists(path) and path.get_extension().to_lower() == "thd":
  86. save_load.load_graph_edit(path)
  87. break
  88. func new_patch():
  89. #clear old patch
  90. graph_edit.clear_connections()
  91. for node in graph_edit.get_children():
  92. if node is GraphNode:
  93. node.queue_free()
  94. await get_tree().process_frame # Wait for nodes to actually be removed
  95. graph_edit.scroll_offset = Vector2(0, 0)
  96. #Generate input and output nodes
  97. var effect: GraphNode = Nodes.get_node(NodePath("inputfile")).duplicate()
  98. effect.name = "inputfile"
  99. get_node("GraphEdit").add_child(effect, true)
  100. effect.connect("open_help", Callable(open_help, "show_help_for_node"))
  101. effect.position_offset = Vector2(20,80)
  102. effect = Nodes.get_node(NodePath("outputfile")).duplicate()
  103. effect.name = "outputfile"
  104. get_node("GraphEdit").add_child(effect, true)
  105. effect.init() #initialise ui from user prefs
  106. effect.connect("open_help", Callable(open_help, "show_help_for_node"))
  107. effect.position_offset = Vector2((DisplayServer.screen_get_size().x - 480) / uiscale, 80)
  108. graph_edit._register_node_movement() #link nodes for tracking position changes for changes tracking
  109. changesmade = false #so it stops trying to save unchanged empty files
  110. get_window().title = "SoundThread"
  111. link_output()
  112. func link_output():
  113. #links various buttons and function in the input nodes - this is called after they are created so that it still works on new and loading files
  114. for control in get_tree().get_nodes_in_group("outputnode"): #check all items in outputnode group
  115. if control.get_meta("outputfunction") == "deleteintermediate": #link delete intermediate files toggle to script
  116. control.toggled.connect(_toggle_delete)
  117. _toggle_delete(control.button_pressed)
  118. #control.button_pressed = interface_settings.get("delete_intermediate", true)
  119. elif control.get_meta("outputfunction") == "runprocess": #link runprocess button
  120. control.button_down.connect(_run_process)
  121. elif control.get_meta("outputfunction") == "audioplayer": #link output audio player
  122. output_audio_player = control
  123. elif control.get_meta("outputfunction") == "filename":
  124. control.text = "outfile"
  125. outfilename = control
  126. elif control.get_meta("outputfunction") == "reusefolder":
  127. foldertoggle = control
  128. #foldertoggle.button_pressed = interface_settings.get("reuse_output_folder", true)
  129. elif control.get_meta("outputfunction") == "openfolder":
  130. control.button_down.connect(_open_output_folder)
  131. #for control in get_tree().get_nodes_in_group("inputnode"):
  132. #if control.get_meta("inputfunction") == "audioplayer": #link input for recycle function
  133. #print("input player found")
  134. #input_audio_player = control
  135. func check_user_preferences():
  136. var interface_settings = ConfigHandler.load_interface_settings()
  137. var audio_settings = ConfigHandler.load_audio_settings()
  138. var audio_devices = AudioServer.get_output_device_list()
  139. $Console.always_on_top = interface_settings.console_on_top
  140. if audio_devices.has(audio_settings.device):
  141. AudioServer.set_output_device(audio_settings.device)
  142. else:
  143. $AudioDevicePopup.popup_centered()
  144. match interface_settings.theme:
  145. 0:
  146. RenderingServer.set_default_clear_color(Color("#2f4f4e"))
  147. 1:
  148. RenderingServer.set_default_clear_color(Color("#000807"))
  149. 2:
  150. RenderingServer.set_default_clear_color(Color("#98d4d2"))
  151. 3:
  152. RenderingServer.set_default_clear_color(Color(interface_settings.theme_custom_colour))
  153. func show_cdp_location():
  154. $CdpLocationDialog.show()
  155. func check_cdp_location_set():
  156. #checks if the location has been set and prompts user to set it
  157. var cdpprogs_settings = ConfigHandler.load_cdpprogs_settings()
  158. if cdpprogs_settings.location == "no_location":
  159. $NoLocationPopup.popup_centered()
  160. else:
  161. #if location is set, stores it in a variable
  162. cdpprogs_location = str(cdpprogs_settings.location)
  163. print(cdpprogs_location)
  164. func _on_ok_button_button_down() -> void:
  165. #after user has read dialog on where to find cdp progs this loads the file browser
  166. $NoLocationPopup.hide()
  167. if OS.get_name() == "Windows":
  168. $CdpLocationDialog.current_dir = "C:/"
  169. else:
  170. $CdpLocationDialog.current_dir = OS.get_environment("HOME")
  171. $CdpLocationDialog.show()
  172. func _on_cdp_location_dialog_dir_selected(dir: String) -> void:
  173. var is_windows = OS.get_name() == "Windows"
  174. var cdprogs_correct
  175. #check if the selected folder contains the hilite program as it has a reasonably unique name and will indicate that the CDP processes do exist in that folder
  176. if is_windows:
  177. cdprogs_correct = FileAccess.file_exists(dir + "/distort.exe")
  178. else:
  179. cdprogs_correct = FileAccess.file_exists(dir + "/distort")
  180. if cdprogs_correct:
  181. #if this location does seem to contain cdp programs
  182. #saves default location for cdp programs in config file
  183. ConfigHandler.save_cdpprogs_settings(dir)
  184. cdpprogs_location = dir
  185. else:
  186. #if it doesn't seem to contain the programs then try and extrapolate the correct folder from the one selected
  187. var selected_folder = dir.get_slice("/", (dir.get_slice_count("/") - 1))
  188. print(selected_folder)
  189. if selected_folder.to_lower() == "cdpr8":
  190. dir = dir + "/_cdp/_cdprogs"
  191. #run this function recursively to check if the programs do exist
  192. _on_cdp_location_dialog_dir_selected(dir)
  193. elif selected_folder.to_lower() == "_cdp":
  194. dir = dir + "/_cdprogs"
  195. #run this function recursively to check if the programs do exist
  196. _on_cdp_location_dialog_dir_selected(dir)
  197. else:
  198. #can't find them
  199. use_anyway = dir
  200. $WrongFolderPopup.popup_centered()
  201. func _on_cdp_location_dialog_canceled() -> void:
  202. #cycles around the set location prompt if user cancels the file dialog
  203. check_cdp_location_set()
  204. func _on_select_folder_button_button_down() -> void:
  205. $WrongFolderPopup.hide()
  206. _on_ok_button_button_down()
  207. func _on_use_anyway_button_button_down() -> void:
  208. $WrongFolderPopup.hide()
  209. ConfigHandler.save_cdpprogs_settings(use_anyway)
  210. cdpprogs_location = use_anyway
  211. func _input(event):
  212. if event.is_action_pressed("undo"):
  213. simulate_mouse_click()
  214. await get_tree().process_frame
  215. undo_redo.undo()
  216. elif event.is_action_pressed("redo"):
  217. undo_redo.redo()
  218. elif event.is_action_pressed("save"):
  219. if currentfile == "none":
  220. savestate = "saveas"
  221. $SaveDialog.popup_centered()
  222. else:
  223. save_load.save_graph_edit(currentfile)
  224. elif event.is_action_pressed("open_explore"):
  225. open_explore()
  226. elif event.is_action_pressed("search"):
  227. var pos = graph_edit.get_local_mouse_position()
  228. _on_graph_edit_popup_request(pos)
  229. elif event.is_action_pressed("run_thread"):
  230. _run_process()
  231. elif event.is_action_pressed("new"):
  232. if changesmade == true:
  233. savestate = "newfile"
  234. $SaveChangesPopup.popup_centered()
  235. else:
  236. new_patch()
  237. currentfile = "none" #reset current file to none for save tracking
  238. elif event.is_action_pressed("save_as"):
  239. savestate = "saveas"
  240. $SaveDialog.popup_centered()
  241. func simulate_mouse_click():
  242. #simulates clicking the middle mouse button in order to hide any visible tooltips
  243. var click_pos = get_viewport().get_mouse_position()
  244. var down_event := InputEventMouseButton.new()
  245. down_event.button_index = MOUSE_BUTTON_MIDDLE
  246. down_event.pressed = true
  247. down_event.position = click_pos
  248. Input.parse_input_event(down_event)
  249. var up_event := InputEventMouseButton.new()
  250. up_event.button_index = MOUSE_BUTTON_MIDDLE
  251. up_event.pressed = false
  252. up_event.position = click_pos
  253. Input.parse_input_event(up_event)
  254. func _run_process() -> void:
  255. #check if any of the inputfile nodes don't have files loaded
  256. for node in graph_edit.get_children():
  257. if node.get_meta("command") == "inputfile" and node.get_node("AudioPlayer").has_meta("inputfile") == false:
  258. $NoInputPopup.popup_centered()
  259. return
  260. #check if the reuse folder toggle is set and a folder has been previously chosen
  261. if foldertoggle.button_pressed == true and lastoutputfolder != "none":
  262. _on_file_dialog_dir_selected(lastoutputfolder)
  263. else:
  264. $FileDialog.show()
  265. func _on_file_dialog_dir_selected(dir: String) -> void:
  266. lastoutputfolder = dir
  267. console_output.clear()
  268. var interface_settings = ConfigHandler.load_interface_settings()
  269. if interface_settings.disable_progress_bar == false:
  270. $ProgressWindow.show()
  271. else:
  272. if $Console.is_visible():
  273. $Console.hide()
  274. await get_tree().process_frame # Wait a frame to allow hide to complete
  275. $Console.popup_centered()
  276. else:
  277. $Console.popup_centered()
  278. await get_tree().process_frame
  279. run_thread.log_console("Generating processing queue", true)
  280. await get_tree().process_frame
  281. #get the current time in hh-mm-ss format as default : causes file name issues
  282. var time_dict = Time.get_time_dict_from_system()
  283. # Pad with zeros to ensure two digits for hour, minute, second
  284. var hour = str(time_dict.hour).pad_zeros(2)
  285. var minute = str(time_dict.minute).pad_zeros(2)
  286. var second = str(time_dict.second).pad_zeros(2)
  287. var time_str = hour + "-" + minute + "-" + second
  288. Global.outfile = dir + "/" + outfilename.text.get_basename() + "_" + Time.get_date_string_from_system() + "_" + time_str
  289. run_thread.log_console("Output directory and file name(s):" + Global.outfile, true)
  290. await get_tree().process_frame
  291. run_thread.run_thread_with_branches()
  292. func _toggle_delete(toggled_on: bool):
  293. delete_intermediate_outputs = toggled_on
  294. print(toggled_on)
  295. func _on_console_close_requested() -> void:
  296. $Console.hide()
  297. func _on_console_open_folder_button_down() -> void:
  298. $Console.hide()
  299. OS.shell_open(Global.outfile.get_base_dir())
  300. func _on_ok_button_2_button_down() -> void:
  301. $NoInputPopup.hide()
  302. func _on_ok_button_3_button_down() -> void:
  303. $MultipleConnectionsPopup.hide()
  304. func _on_settings_button_index_pressed(index: int) -> void:
  305. var interface_settings = ConfigHandler.load_interface_settings()
  306. match index:
  307. 0:
  308. $Settings.popup_centered()
  309. 1:
  310. $AudioSettings.popup_centered()
  311. 2:
  312. if $Console.is_visible():
  313. $Console.hide()
  314. await get_tree().process_frame # Wait a frame to allow hide to complete
  315. $Console.popup_centered()
  316. else:
  317. $Console.popup_centered()
  318. func _on_file_button_index_pressed(index: int) -> void:
  319. match index:
  320. 0:
  321. if changesmade == true:
  322. savestate = "newfile"
  323. $SaveChangesPopup.popup_centered()
  324. else:
  325. new_patch()
  326. currentfile = "none" #reset current file to none for save tracking
  327. 1:
  328. if currentfile == "none":
  329. savestate = "saveas"
  330. $SaveDialog.popup_centered()
  331. else:
  332. save_load.save_graph_edit(currentfile)
  333. print("save pressed, changes made =")
  334. print(changesmade)
  335. print("current file =")
  336. print(currentfile)
  337. 2:
  338. savestate = "saveas"
  339. $SaveDialog.popup_centered()
  340. 3:
  341. if changesmade == true:
  342. savestate = "load"
  343. $SaveChangesPopup.popup_centered()
  344. else:
  345. $LoadDialog.popup_centered()
  346. func _on_save_dialog_file_selected(path: String) -> void:
  347. save_load.save_graph_edit(path) #save file
  348. #check what the user was trying to do before save and do that action
  349. if savestate == "newfile":
  350. new_patch()
  351. currentfile = "none" #reset current file to none for save tracking
  352. elif savestate == "load":
  353. $LoadDialog.popup_centered()
  354. elif savestate == "helpfile":
  355. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  356. save_load.load_graph_edit(helpfile)
  357. elif savestate == "quit":
  358. await get_tree().create_timer(0.25).timeout #little pause so that it feels like it actually saved even though it did
  359. get_tree().quit()
  360. elif savestate == "saveas":
  361. currentfile = path
  362. savestate = "none" #reset save state, not really needed but feels good
  363. func _on_load_dialog_file_selected(path: String) -> void:
  364. currentfile = path #tracking path here only means "save" only saves patches the user has loaded rather than overwriting help files
  365. save_load.load_graph_edit(path)
  366. func _on_help_button_index_pressed(index: int) -> void:
  367. match index:
  368. 0:
  369. pass
  370. 1:
  371. if changesmade == true:
  372. savestate = "helpfile"
  373. helpfile = "res://examples/getting_started.thd"
  374. $SaveChangesPopup.popup_centered()
  375. else:
  376. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  377. save_load.load_graph_edit("res://examples/getting_started.thd")
  378. 2:
  379. if changesmade == true:
  380. savestate = "helpfile"
  381. helpfile = "res://examples/navigating.thd"
  382. $SaveChangesPopup.popup_centered()
  383. else:
  384. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  385. save_load.load_graph_edit("res://examples/navigating.thd")
  386. 3:
  387. if changesmade == true:
  388. savestate = "helpfile"
  389. helpfile = "res://examples/building_a_thread.thd"
  390. $SaveChangesPopup.popup_centered()
  391. else:
  392. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  393. save_load.load_graph_edit("res://examples/building_a_thread.thd")
  394. 4:
  395. if changesmade == true:
  396. savestate = "helpfile"
  397. helpfile = "res://examples/frequency_domain.thd"
  398. $SaveChangesPopup.popup_centered()
  399. else:
  400. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  401. save_load.load_graph_edit("res://examples/frequency_domain.thd")
  402. 5:
  403. if changesmade == true:
  404. savestate = "helpfile"
  405. helpfile = "res://examples/automation.thd"
  406. $SaveChangesPopup.popup_centered()
  407. else:
  408. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  409. save_load.load_graph_edit("res://examples/automation.thd")
  410. 6:
  411. if changesmade == true:
  412. savestate = "helpfile"
  413. helpfile = "res://examples/trimming.thd"
  414. $SaveChangesPopup.popup_centered()
  415. else:
  416. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  417. save_load.load_graph_edit("res://examples/trimming.thd")
  418. 7:
  419. if changesmade == true:
  420. savestate = "helpfile"
  421. helpfile = "res://examples/multiple_inputs.thd"
  422. $SaveChangesPopup.popup_centered()
  423. else:
  424. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  425. save_load.load_graph_edit("res://examples/multiple_inputs.thd")
  426. 8:
  427. if changesmade == true:
  428. savestate = "helpfile"
  429. helpfile = "res://examples/preview_nodes.thd"
  430. $SaveChangesPopup.popup_centered()
  431. else:
  432. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  433. save_load.load_graph_edit("res://examples/preview_nodes.thd")
  434. 9:
  435. pass
  436. 10:
  437. if changesmade == true:
  438. savestate = "helpfile"
  439. helpfile = "res://examples/wetdry.thd"
  440. $SaveChangesPopup.popup_centered()
  441. else:
  442. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  443. save_load.load_graph_edit("res://examples/wetdry.thd")
  444. 11:
  445. if changesmade == true:
  446. savestate = "helpfile"
  447. helpfile = "res://examples/resonant_filters.thd"
  448. $SaveChangesPopup.popup_centered()
  449. else:
  450. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  451. save_load.load_graph_edit("res://examples/resonant_filters.thd")
  452. 12:
  453. pass
  454. 13:
  455. OS.shell_open("https://www.composersdesktop.com/docs/html/ccdpndex.htm")
  456. 14:
  457. OS.shell_open("https://github.com/j-p-higgins/SoundThread/issues")
  458. #func _recycle_outfile():
  459. #if outfile != "no file":
  460. #input_audio_player.recycle_outfile(outfile)
  461. func _on_save_changes_button_down() -> void:
  462. $SaveChangesPopup.hide()
  463. if currentfile == "none":
  464. $SaveDialog.show()
  465. else:
  466. save_load.save_graph_edit(currentfile)
  467. if savestate == "newfile":
  468. new_patch()
  469. currentfile = "none" #reset current file to none for save tracking
  470. elif savestate == "load":
  471. $LoadDialog.popup_centered()
  472. elif savestate == "helpfile":
  473. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  474. save_load.load_graph_edit(helpfile)
  475. elif savestate == "quit":
  476. await get_tree().create_timer(0.25).timeout #little pause so that it feels like it actually saved even though it did
  477. get_tree().quit()
  478. savestate = "none"
  479. func _on_dont_save_changes_button_down() -> void:
  480. $SaveChangesPopup.hide()
  481. if savestate == "newfile":
  482. new_patch()
  483. currentfile = "none" #reset current file to none for save tracking
  484. elif savestate == "load":
  485. $LoadDialog.popup_centered()
  486. elif savestate == "helpfile":
  487. currentfile = "none" #reset current file to none for save tracking so user cant save over help file
  488. save_load.load_graph_edit(helpfile)
  489. elif savestate == "quit":
  490. get_tree().quit()
  491. savestate = "none"
  492. func _on_cancel_changes_button_down() -> void:
  493. $SaveChangesPopup.hide()
  494. savestate = "none"
  495. func _notification(what):
  496. if what == NOTIFICATION_WM_CLOSE_REQUEST:
  497. run_thread._on_kill_process_button_down()
  498. $Console.hide()
  499. if changesmade == true:
  500. savestate = "quit"
  501. $SaveChangesPopup.popup_centered()
  502. #$HelpWindow.hide()
  503. else:
  504. get_tree().quit() # default behavior
  505. func _open_output_folder():
  506. if lastoutputfolder != "none":
  507. OS.shell_open(lastoutputfolder)
  508. func _on_rich_text_label_meta_clicked(meta: Variant) -> void:
  509. print(str(meta))
  510. OS.shell_open(str(meta))
  511. func _on_graph_edit_popup_request(at_position: Vector2) -> void:
  512. effect_position = graph_edit.get_local_mouse_position()
  513. #get the mouse position in screen coordinates
  514. var mouse_screen_pos = DisplayServer.mouse_get_position()
  515. #get the window position in screen coordinates
  516. var window_screen_pos = get_window().position
  517. #get the window size relative to its scaling for retina displays
  518. var window_size = get_window().size * DisplayServer.screen_get_scale()
  519. #calculate the xy position of the mouse clamped to the size of the window and menu so it doesn't go off the screen
  520. var clamped_x = clamp(mouse_screen_pos.x, window_screen_pos.x, window_screen_pos.x + window_size.x - $SearchMenu.size.x)
  521. var clamped_y = clamp(mouse_screen_pos.y, window_screen_pos.y, window_screen_pos.y + window_size.y - (420 * DisplayServer.screen_get_scale()))
  522. #position and show the menu
  523. $SearchMenu.position = Vector2(clamped_x, clamped_y)
  524. $SearchMenu.popup()
  525. func _on_audio_settings_close_requested() -> void:
  526. $AudioSettings.hide()
  527. func _on_open_audio_settings_button_down() -> void:
  528. $AudioDevicePopup.hide()
  529. $AudioSettings.popup_centered()
  530. func _on_audio_device_popup_close_requested() -> void:
  531. $AudioDevicePopup.hide()
  532. func _on_mainmenu_close_requested() -> void:
  533. #closes menu if click is anywhere other than the menu as it is a window with popup set to true
  534. $mainmenu.hide()
  535. func open_explore():
  536. effect_position = graph_edit.get_local_mouse_position()
  537. #get the mouse position in screen coordinates
  538. var mouse_screen_pos = DisplayServer.mouse_get_position()
  539. #get the window position in screen coordinates
  540. var window_screen_pos = get_window().position
  541. #get the window size relative to its scaling for retina displays
  542. var window_size = get_window().size * DisplayServer.screen_get_scale()
  543. #get the size of the popup menu
  544. var popup_size = $mainmenu.size
  545. #calculate the xy position of the mouse clamped to the size of the window and menu so it doesn't go off the screen
  546. var clamped_x = clamp(mouse_screen_pos.x, window_screen_pos.x, window_screen_pos.x + window_size.x - popup_size.x)
  547. var clamped_y = clamp(mouse_screen_pos.y, window_screen_pos.y, window_screen_pos.y + window_size.y - popup_size.y)
  548. #position and show the menu
  549. $mainmenu.position = Vector2(clamped_x, clamped_y)
  550. $mainmenu.popup()
  551. func change_console_settings(toggled: bool):
  552. $Console.always_on_top = toggled
  553. func _on_kill_process_button_down() -> void:
  554. run_thread._on_kill_process_button_down()