SettingsMenu.gd 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. extends Control
  2. @onready var current_container: Control = $PanelContainer/MarginContainer/VBoxContainer/Video
  3. @export var containers: Array[Control]
  4. @export var disabled_containers: Array[Control]
  5. var category_select_active := false
  6. var category_index := 0
  7. signal closed
  8. var can_move := true
  9. var active = false
  10. signal opened
  11. func _process(_delta: float) -> void:
  12. category_select_active = current_container.selected_index == -1 and active
  13. %Category.text = tr(current_container.category_name)
  14. %Icon.region_rect.position.x = category_index * 24
  15. for i in [%LeftArrow, %RightArrow]:
  16. i.modulate.a = int(current_container.selected_index == -1)
  17. for i in containers.size():
  18. containers[i].active = category_index == i and active
  19. if SelectableInputOption.rebinding_input == false:
  20. containers[i].can_input = can_move
  21. for i in disabled_containers:
  22. i.active = false
  23. if category_select_active and active and can_move:
  24. handle_inputs()
  25. if Input.is_action_just_pressed("ui_back") and active and current_container.can_input and can_move:
  26. close()
  27. func handle_inputs() -> void:
  28. var direction := 0
  29. if Input.is_action_just_pressed("ui_left"):
  30. category_index -= 1
  31. direction = -1
  32. if Settings.file.audio.extra_sfx == 1:
  33. AudioManager.play_global_sfx("menu_move")
  34. if Input.is_action_just_pressed("ui_right"):
  35. category_index += 1
  36. direction += 1
  37. if Settings.file.audio.extra_sfx == 1:
  38. AudioManager.play_global_sfx("menu_move")
  39. category_index = wrap(category_index, 0, containers.size())
  40. current_container = containers[category_index]
  41. if disabled_containers.has(current_container):
  42. category_index = wrap(category_index + direction, 0, containers.size())
  43. func open_pack_config_menu(pack: ResourcePackContainer) -> void:
  44. $ResourcePackConfigMenu.config_json = pack.config
  45. $ResourcePackConfigMenu.json_path = pack.config_path
  46. $ResourcePackConfigMenu.open()
  47. can_move = false
  48. await $ResourcePackConfigMenu.closed
  49. can_move = true
  50. func open() -> void:
  51. process_mode = Node.PROCESS_MODE_ALWAYS
  52. opened.emit()
  53. update_all_starting()
  54. $PanelContainer/MarginContainer/VBoxContainer/KeyboardControls.selected_index = -1
  55. $PanelContainer/MarginContainer/VBoxContainer/Controller.selected_index = -1
  56. show()
  57. update_minimum_size()
  58. current_container.show()
  59. current_container.active = true
  60. await get_tree().process_frame
  61. active = true
  62. func update_all_starting() -> void:
  63. get_tree().call_group("Options", "update_starting_values")
  64. %Flag.region_rect.position.x = Global.lang_codes.find(TranslationServer.get_locale()) * 16
  65. $PanelContainer/MarginContainer/VBoxContainer/Video/Language.selected_index = Global.lang_codes.find(Settings.file.game.lang)
  66. func close() -> void:
  67. hide()
  68. active = false
  69. closed.emit()
  70. await get_tree().process_frame
  71. Settings.save_settings()
  72. process_mode = Node.PROCESS_MODE_DISABLED