Files
owniverse/ui/main_menu/main_menu.gd
Kirill e48d4bbe88 Add comprehensive tests and optimizations for simulation and UI performance
- Introduced a new benchmark save script to create a stress test scenario with extreme values for simulation performance.
- Added a full UI benchmark script to measure frame rates and performance metrics during UI interactions.
- Implemented tests for coarse generations to ensure population transitions are handled correctly.
- Created tests for extra parameters to validate the loading and application of configuration settings.
- Developed simulation optimization tests to verify the efficiency of population drift and rounding mechanisms.
- Added split optimization tests to ensure accurate allocation and rounding behavior in population management.
- Included startup parameter tests to confirm the correct initialization of global parameters before scene readiness.
- Enhanced the audit rounding ledger to compare selective and full rounding results for consistency.
2026-10-05 22:16:59 +03:00

82 lines
3.0 KiB
GDScript

extends VBoxContainer
const MIN_VOLUME_DB := -50.0
const SILENT_VOLUME_DB := -80.0
@onready var sound_button: TextureButton = $Media/Sound
@onready var music_button: TextureButton = $Media/Music
@onready var sound_volume: HSlider = $Volume/SoundVolume
@onready var music_volume: HSlider = $Volume/MusicVolume
@onready var english_button: TextureButton = $Language/English
@onready var russian_button: TextureButton = $Language/Russian
@onready var effects_player: OwniverseEffectsPlayer = $"../../FXPlayer"
@onready var music_player: OwniverseMusicPlayer = $"../../MusicPlayer"
func _ready() -> void:
SaveManager.load_settings()
sound_button.set_pressed_no_signal(bool(Global.Settings.sound_enabled))
music_button.set_pressed_no_signal(bool(Global.Settings.music_enabled))
sound_volume.set_value_no_signal(float(Global.Settings.sound_volume) * sound_volume.max_value)
music_volume.set_value_no_signal(float(Global.Settings.music_volume) * music_volume.max_value)
_update_locale_buttons()
_apply_sound_settings()
_apply_music_settings()
func _on_sound_pressed() -> void:
Global.Settings.sound_enabled = sound_button.button_pressed
_apply_sound_settings()
SaveManager.save_settings()
func _on_music_pressed() -> void:
Global.Settings.music_enabled = music_button.button_pressed
_apply_music_settings()
SaveManager.save_settings()
func _on_sound_volume_value_changed(value: float) -> void:
Global.Settings.sound_volume = value / sound_volume.max_value
_apply_bus_volume("FX", float(Global.Settings.sound_volume))
SaveManager.save_settings()
func _on_music_volume_value_changed(value: float) -> void:
Global.Settings.music_volume = value / music_volume.max_value
_apply_bus_volume("Music", float(Global.Settings.music_volume))
SaveManager.save_settings()
func _apply_sound_settings() -> void:
var bus_index: int = AudioServer.get_bus_index("FX")
AudioServer.set_bus_mute(bus_index, not bool(Global.Settings.sound_enabled))
effects_player.set_enabled(bool(Global.Settings.sound_enabled))
_apply_bus_volume("FX", float(Global.Settings.sound_volume))
func _apply_music_settings() -> void:
music_player.set_enabled(bool(Global.Settings.music_enabled))
_apply_bus_volume("Music", float(Global.Settings.music_volume))
func _apply_bus_volume(bus_name: String, value: float) -> void:
var bus_index: int = AudioServer.get_bus_index(bus_name)
if bus_index < 0:
push_warning("Missing audio bus: " + bus_name)
return
var normalized: float = clampf(value, 0.0, 1.0)
var volume_db: float = SILENT_VOLUME_DB if is_zero_approx(normalized) else lerpf(MIN_VOLUME_DB, 0.0, normalized)
AudioServer.set_bus_volume_db(bus_index, volume_db)
func _on_change_locale_pressed(locale: String) -> void:
Global.set_locale(locale)
_update_locale_buttons()
SaveManager.save_settings()
func _update_locale_buttons() -> void:
english_button.set_pressed_no_signal(Global.Locale == "en")
russian_button.set_pressed_no_signal(Global.Locale == "ru")