2025-03-22 19:16:52 -06:00
|
|
|
extends MarginContainer
|
|
|
|
## Menu allowing the user to adjust game configuration.
|
|
|
|
|
|
|
|
const SETTINGS_GROUP := "Settings"
|
|
|
|
const VOLUME_GROUP := "VolumeSliders"
|
|
|
|
const BINDINGS_GROUP := "ControlBindings"
|
|
|
|
|
|
|
|
@export var volume_slider_scene: PackedScene
|
|
|
|
@export var control_binding_scene: PackedScene
|
|
|
|
|
|
|
|
@onready var bus_mixer_list: HBoxContainer = %BusMixerList
|
|
|
|
@onready var control_binding_list: VBoxContainer = %ControlBindingList
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
populate_volume_mixers()
|
|
|
|
populate_control_bindings()
|
|
|
|
|
|
|
|
|
|
|
|
func _get_settings_elements() -> Array[Setting]:
|
|
|
|
var elements: Array[Setting] = []
|
|
|
|
elements.assign(get_tree().get_nodes_in_group(SETTINGS_GROUP))
|
|
|
|
return elements
|
|
|
|
|
|
|
|
|
|
|
|
func _get_volume_sliders() -> Array[VolumeSlider]:
|
|
|
|
var elements: Array[VolumeSlider] = []
|
|
|
|
elements.assign(get_tree().get_nodes_in_group(VOLUME_GROUP))
|
|
|
|
return elements
|
|
|
|
|
|
|
|
|
|
|
|
func _get_control_bindings() -> Array[ControlBinding]:
|
|
|
|
var elements: Array[ControlBinding] = []
|
|
|
|
elements.assign(get_tree().get_nodes_in_group(BINDINGS_GROUP))
|
|
|
|
return elements
|
|
|
|
|
|
|
|
|
|
|
|
func populate_control_bindings() -> void:
|
|
|
|
for action: StringName in InputMap.get_actions():
|
|
|
|
if not action.begins_with("ui_"):
|
|
|
|
var binding: ControlBinding = control_binding_scene.instantiate()
|
|
|
|
binding.key = action
|
|
|
|
control_binding_list.add_child(binding)
|
|
|
|
|
|
|
|
|
|
|
|
func populate_volume_mixers() -> void:
|
|
|
|
for idx: int in range(AudioServer.bus_count):
|
|
|
|
var slider: VolumeSlider = volume_slider_scene.instantiate()
|
|
|
|
slider.bus_idx = idx
|
|
|
|
bus_mixer_list.add_child(slider)
|
|
|
|
|
|
|
|
|
|
|
|
## Close menu without applying settings.
|
|
|
|
func cancel() -> void:
|
2025-08-15 15:51:11 -06:00
|
|
|
GlobalSFXManager.cancel.play()
|
2025-03-22 19:16:52 -06:00
|
|
|
queue_free()
|
|
|
|
|
|
|
|
|
|
|
|
## Apply all settings.
|
|
|
|
func apply() -> void:
|
|
|
|
for setting: Setting in _get_settings_elements():
|
|
|
|
setting.apply()
|
|
|
|
for mixer: VolumeSlider in _get_volume_sliders():
|
|
|
|
mixer.apply()
|
|
|
|
for binding: ControlBinding in _get_control_bindings():
|
|
|
|
binding.apply()
|
|
|
|
|
|
|
|
|
|
|
|
## Write all applied settings to disk.
|
|
|
|
func save_settings() -> void:
|
|
|
|
Game.settings.write()
|
|
|
|
|
|
|
|
|
|
|
|
## Apply settings and close menu.
|
|
|
|
func accept() -> void:
|
2025-08-15 15:51:11 -06:00
|
|
|
GlobalSFXManager.confirm.play()
|
2025-03-22 19:16:52 -06:00
|
|
|
apply()
|
|
|
|
save_settings()
|
|
|
|
queue_free()
|