## SettingsMenu — overlay panel for audio volume and game reset.
class_name SettingsMenu extends CanvasLayer


func _ready() -> void:
	visible = false


func show_menu() -> void:
	var music_slider: HSlider = get_node_or_null("Panel/MusicSlider") as HSlider
	var sfx_slider: HSlider = get_node_or_null("Panel/SfxSlider") as HSlider
	if music_slider != null:
		music_slider.set_value_no_signal(GameState.music_volume)
	if sfx_slider != null:
		sfx_slider.set_value_no_signal(GameState.sfx_volume)
	visible = true


func hide_menu() -> void:
	visible = false


func _on_music_slider_value_changed(value: float) -> void:
	AudioManager.set_music_volume(value)
	GameState.music_volume = value


func _on_sfx_slider_value_changed(value: float) -> void:
	AudioManager.set_sfx_volume(value)
	GameState.sfx_volume = value


func _on_reset_button_pressed() -> void:
	var dialog: ConfirmationDialog = get_node_or_null("Panel/ResetConfirmDialog") as ConfirmationDialog
	if dialog != null:
		dialog.popup_centered()


func _on_reset_confirmed() -> void:
	SaveManager.reset_game()
	get_tree().reload_current_scene()


func _on_close_button_pressed() -> void:
	hide_menu()
