Files
MusicPlayer/popups/settings_popup.gd
T
Sansan d21b3e2ce0
Build / test (push) Successful in 45s
Build / build (push) Successful in 1m12s
Save fullscreen and read server, password and debug from config.ini
The settings the game saves itself, the quiz settings and now fullscreen, move
to settings.cfg (settings_debug.cfg in debug mode).

config.ini in the same folder is edited by hand: the server to start with, the
API password and debug mode. The game writes it with everything commented out
when it is missing and never changes it after that. IniFile reads it: plain
key = value lines, whole-line # or ; comments and optional quotes.
2026-10-07 20:12:59 +02:00

90 lines
3.3 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.set_fullscreen(!Settings.fullscreen)
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)