147 lines
4.5 KiB
GDScript
147 lines
4.5 KiB
GDScript
extends Control
|
|
|
|
|
|
const WINDOW_FACTOR = "window_factor"
|
|
|
|
|
|
signal back
|
|
|
|
|
|
@onready var fullscreen_button : CheckButton = $%FullscreenCheckButton
|
|
@onready var window_factor_buttons : HBoxContainer = $%WindowFactorContainer
|
|
@onready var back_button : Button = $%BackButton
|
|
@onready var master_slider : Slider = $%MasterSlider
|
|
@onready var ui_slider : Slider = $%UISlider
|
|
@onready var sfx_slider : Slider = $%SFXSlider
|
|
@onready var music_slider : Slider = $%MusicSlider
|
|
|
|
|
|
func _ready() -> void:
|
|
_connect_window_factor_buttons()
|
|
_load_current_settings()
|
|
_init_focus()
|
|
_setup_neighbors()
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("ui_up") and not fullscreen_button.has_focus():
|
|
SoundManager.play_ui_stream(SoundManager.ui_stream_previous)
|
|
if event.is_action_pressed("ui_down") and not back_button.has_focus():
|
|
SoundManager.play_ui_stream(SoundManager.ui_stream_next)
|
|
if event.is_action_pressed("ui_left") and _play_left_sound():
|
|
SoundManager.play_ui_stream(SoundManager.ui_stream_previous)
|
|
if event.is_action_pressed("ui_right") and _play_right_sound():
|
|
SoundManager.play_ui_stream(SoundManager.ui_stream_next)
|
|
|
|
|
|
func _play_left_sound() -> bool:
|
|
return _play_side_sound(1, 0)
|
|
|
|
|
|
func _play_right_sound() -> bool:
|
|
return _play_side_sound(0, 1)
|
|
|
|
|
|
func _play_side_sound(offset_begin: int, offset_end: int) -> bool:
|
|
for i in range(offset_begin, window_factor_buttons.get_child_count() - offset_end):
|
|
var child := window_factor_buttons.get_child(i)
|
|
if child is Button and child.has_focus():
|
|
return true
|
|
return false
|
|
|
|
|
|
func _connect_window_factor_buttons() -> void:
|
|
for child in window_factor_buttons.get_children():
|
|
if child is Button:
|
|
var button : Button = child
|
|
button.pressed.connect(_on_window_factor_button_pressed.bind(button))
|
|
|
|
|
|
func _on_visibility_changed() -> void:
|
|
if not is_node_ready(): return
|
|
if not visible: return
|
|
|
|
_load_current_settings()
|
|
_init_focus()
|
|
_setup_neighbors()
|
|
|
|
|
|
func _init_focus() -> void:
|
|
fullscreen_button.grab_focus()
|
|
|
|
|
|
func _setup_neighbors() -> void:
|
|
music_slider.focus_neighbor_bottom = back_button.get_path()
|
|
|
|
|
|
func _load_current_settings() -> void:
|
|
fullscreen_button.button_pressed = SettingsManager.fullscreen
|
|
for child in window_factor_buttons.get_children():
|
|
if child is Button:
|
|
var button : Button = child
|
|
var window_factor : int = button.get_meta(WINDOW_FACTOR, 0)
|
|
if window_factor == SettingsManager.window_factor:
|
|
button.button_pressed = true
|
|
_update_window_factor_disabled()
|
|
|
|
master_slider.value = SettingsManager.master_volume
|
|
ui_slider.value = SettingsManager.ui_volume
|
|
sfx_slider.value = SettingsManager.sfx_volume
|
|
music_slider.value = SettingsManager.music_volume
|
|
|
|
|
|
func _update_window_factor_disabled() -> void:
|
|
for child in window_factor_buttons.get_children():
|
|
if not child is Button: continue
|
|
child.disabled = SettingsManager.fullscreen
|
|
child.focus_mode = Control.FOCUS_NONE if SettingsManager.fullscreen else Control.FOCUS_ALL
|
|
|
|
|
|
func _on_fullscreen_check_button_toggled(toggled: bool) -> void:
|
|
if visible: SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
|
SettingsManager.fullscreen = toggled
|
|
_update_window_factor_disabled()
|
|
|
|
|
|
func _on_back_button_pressed() -> void:
|
|
SoundManager.play_ui_stream(SoundManager.ui_stream_decline)
|
|
back.emit()
|
|
|
|
|
|
func _on_window_factor_button_pressed(button: Button) -> void:
|
|
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
|
var window_factor : int = button.get_meta(WINDOW_FACTOR, 0)
|
|
if window_factor > 0:
|
|
SettingsManager.window_factor = window_factor
|
|
|
|
|
|
func _on_master_volume_changed(value: float) -> void:
|
|
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
|
SoundManager.play_ui_stream(stream)
|
|
SettingsManager.master_volume = floor(value)
|
|
|
|
|
|
func _on_ui_volume_changed(value: float) -> void:
|
|
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
|
SoundManager.play_ui_stream(stream)
|
|
SettingsManager.ui_volume = floor(value)
|
|
|
|
|
|
func _on_sfx_volume_changed(value: float) -> void:
|
|
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
|
SoundManager.play_sfx_stream(stream, SettingsManager.window_base_size/2)
|
|
SettingsManager.sfx_volume = floor(value)
|
|
|
|
|
|
func _on_music_volume_changed(value: float) -> void:
|
|
var stream := _get_slider_sound(SettingsManager.master_volume, value)
|
|
SoundManager.play_music_stream(stream)
|
|
SettingsManager.music_volume = floor(value)
|
|
|
|
|
|
func _get_slider_sound(old_value: float, new_value: float) -> AudioStream:
|
|
if old_value < new_value:
|
|
return SoundManager.ui_stream_next
|
|
else:
|
|
return SoundManager.ui_stream_previous
|