The quiz card's settings are saved to quiz_settings.cfg in OS.get_config_dir() on every change and loaded at start. Debug builds use their own file, and MUSICPLAYER_CONFIG_DIR moves the file elsewhere so tests never touch it. Count plays in statistics and Prefer less played soundtracks are not saved and move from the quiz card to the Settings popup.
94 lines
3.4 KiB
GDScript
94 lines
3.4 KiB
GDScript
class_name SettingsPopup
|
|
extends BasePopup
|
|
## The application settings: which MusicServer to use, fullscreen, how many songs to
|
|
## download ahead, whether to prefer less played soundtracks and whether plays count in
|
|
## the statistics. Opened from the Settings button in the top bar.
|
|
##
|
|
## The quiz settings, such as the winning score, are in [QuizSettingsCard].
|
|
|
|
## Emitted when another MusicServer is picked.
|
|
signal server_changed
|
|
|
|
@onready var settings_panel: Panel = %SettingsPanel
|
|
@onready var select_server_button: OptionButton = %SelectServerButton
|
|
@onready var fullscreen_button: CheckButton = %FullscreenButton
|
|
@onready var cache_label: Label = %CacheLabel
|
|
@onready var lower_cache_button: Button = %LowerCacheButton
|
|
@onready var increase_cache_button: Button = %IncreaseCacheButton
|
|
@onready var low_played_button: CheckButton = %LowPlayedCheckButton
|
|
@onready var add_to_database_button: CheckButton = %AddToDatabaseCheckButton
|
|
@onready var local_button: CheckButton = %LocalButton
|
|
|
|
|
|
func _ready() -> void:
|
|
for server: String in Settings.SERVERS:
|
|
select_server_button.add_item(server)
|
|
fullscreen_button.button_pressed = Settings.fullscreen
|
|
select_server_button.select(Settings.selected_server)
|
|
cache_label.text = str(Playlist.number_of_tracks_to_preload)
|
|
|
|
fullscreen_button.pressed.connect(fullscreen)
|
|
local_button.pressed.connect(local_play)
|
|
lower_cache_button.pressed.connect(lower_cache)
|
|
increase_cache_button.pressed.connect(increase_cache)
|
|
select_server_button.item_selected.connect(select_server)
|
|
low_played_button.toggled.connect(
|
|
func(on: bool) -> void: Settings.use_low_played_mode = on)
|
|
add_to_database_button.toggled.connect(func(on: bool) -> void: Settings.add_to_stats = on)
|
|
visibility_changed.connect(_on_visibility_changed)
|
|
# Alt+Enter switches fullscreen from the main window, which resizes the window
|
|
get_window().size_changed.connect(_update_fullscreen_button)
|
|
|
|
|
|
func fullscreen() -> void:
|
|
Settings.fullscreen = !Settings.fullscreen
|
|
if Settings.fullscreen:
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
|
if !Settings.fullscreen:
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
|
|
|
|
|
func local_play() -> void:
|
|
Settings.play_local = !Settings.play_local
|
|
|
|
|
|
func lower_cache() -> void:
|
|
Playlist.number_of_tracks_to_preload = maxi(Playlist.number_of_tracks_to_preload - 1, 1)
|
|
cache_label.text = str(Playlist.number_of_tracks_to_preload)
|
|
|
|
|
|
func increase_cache() -> void:
|
|
Playlist.number_of_tracks_to_preload += 1
|
|
cache_label.text = str(Playlist.number_of_tracks_to_preload)
|
|
|
|
|
|
func select_server(new_server: int) -> void:
|
|
GameLog.debug("select_server")
|
|
_use_server(new_server)
|
|
|
|
|
|
## Picks [param new_server] in the list and uses it.
|
|
func set_selected_server(new_server: int) -> void:
|
|
GameLog.debug("set_selected_server")
|
|
select_server_button.select(new_server)
|
|
_use_server(new_server)
|
|
|
|
|
|
func _use_server(new_server: int) -> void:
|
|
Settings.default_path = Settings.SERVERS[new_server]
|
|
Settings.selected_server = new_server
|
|
GameLog.debug("Settings.default_path: " + Settings.default_path)
|
|
server_changed.emit()
|
|
|
|
|
|
# Winning a game turns statistics off, so the toggles are refreshed every time this opens
|
|
func _on_visibility_changed() -> void:
|
|
if visible:
|
|
_update_fullscreen_button()
|
|
low_played_button.set_pressed_no_signal(Settings.use_low_played_mode)
|
|
add_to_database_button.set_pressed_no_signal(Settings.add_to_stats)
|
|
|
|
|
|
func _update_fullscreen_button() -> void:
|
|
fullscreen_button.set_pressed_no_signal(Settings.fullscreen)
|