Files
MusicPlayer/quiz/quiz_settings_card.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

135 lines
5.6 KiB
GDScript

class_name QuizSettingsCard
extends BasePopup
## The quiz settings, in a small card that opens above the Quiz settings button by the
## music player: how songs are played and hidden, the winning score and the inspiration
## list. It does not dim the quiz, so it can be changed during a song.
##
## Every change is saved at once with [method Settings.save_settings].
##
## The card's bottom edge is where the card is placed, just above the player bar, and
## it grows upward to fit its rows.
##
## The application settings, such as the server, are in [SettingsPopup].
## The most seconds of a song's beginning that can be hidden.
const MAX_HIDE_SECONDS: float = 10.0
## Space between the rows and the card's edges.
const PADDING: Vector2 = Vector2(16, 12)
@onready var card_panel: Panel = %CardPanel
@onready var rows: VBoxContainer = %VBox
@onready var auto_repeat_button: CheckButton = %AutoRepeatCheckButton
@onready var stop_after_current_button: CheckButton = %StopAfterCurrentCheckButton
@onready var hide_next_track_button: CheckButton = %HideNextTrackCheckButton
@onready var hide_beginning_button: CheckButton = %HideBeginningCheckButton
@onready var hide_for_seconds_row: HBoxContainer = %HideForSecondsRow
@onready var hide_for_seconds_label: Label = %HideForSecondsLabel
@onready var lower_hide_for_seconds_button: Button = %LowerHideForSecondsButton
@onready var increase_hide_for_seconds_button: Button = %IncreaseHideForSecondsButton
@onready var hide_length_button: CheckButton = %HideLengthCheckButton
@onready var hide_ticks_button: CheckButton = %HideTicksCheckButton
@onready var score_label: Label = %ScoreLabel
@onready var lower_winning_score_button: Button = %LowerButton
@onready var increase_winning_score_button: Button = %IncreaseButton
@onready var inspiration_speed_label: Label = %InspirationListSpeedLabel
@onready var lower_inspiration_speed_button: Button = %LowerInspirationSpeedButton
@onready var increase_inspiration_speed_button: Button = %IncreaseInspirationSpeedButton
func _ready() -> void:
auto_repeat_button.toggled.connect(_save_toggle.bind(&"auto_repeat_song"))
stop_after_current_button.toggled.connect(_save_toggle.bind(&"stop_after_current"))
hide_next_track_button.toggled.connect(_save_toggle.bind(&"hide_next_track"))
hide_beginning_button.toggled.connect(_on_hide_beginning_toggled)
hide_length_button.toggled.connect(_save_toggle.bind(&"hide_length"))
hide_ticks_button.toggled.connect(_save_toggle.bind(&"hide_ticks"))
lower_winning_score_button.pressed.connect(lower_winning_score)
increase_winning_score_button.pressed.connect(increase_winning_score)
lower_inspiration_speed_button.pressed.connect(lower_inspiration_speed)
increase_inspiration_speed_button.pressed.connect(increase_inspiration_speed)
lower_hide_for_seconds_button.pressed.connect(lower_hide_for_seconds)
increase_hide_for_seconds_button.pressed.connect(increase_hide_for_seconds)
visibility_changed.connect(_on_visibility_changed)
show_settings()
## Shows the current settings. This runs every time the card opens, in case a setting
## was changed somewhere else.
func show_settings() -> void:
auto_repeat_button.set_pressed_no_signal(Settings.auto_repeat_song)
stop_after_current_button.set_pressed_no_signal(Settings.stop_after_current)
hide_next_track_button.set_pressed_no_signal(Settings.hide_next_track)
hide_beginning_button.set_pressed_no_signal(Settings.hide_beginning)
hide_length_button.set_pressed_no_signal(Settings.hide_length)
hide_ticks_button.set_pressed_no_signal(Settings.hide_ticks)
hide_for_seconds_row.visible = Settings.hide_beginning
hide_for_seconds_label.text = "%d" % Settings.hide_for_seconds
score_label.text = str(Settings.winning_score)
inspiration_speed_label.text = str(Settings.inspiration_list_speed)
_fit_to_rows()
func lower_winning_score() -> void:
set_winning_score(Settings.winning_score - 1)
func increase_winning_score() -> void:
set_winning_score(Settings.winning_score + 1)
## Sets the winning score, never below 1.
func set_winning_score(new_score: int) -> void:
Settings.winning_score = maxi(new_score, 1)
score_label.text = str(Settings.winning_score)
Settings.save_settings()
func lower_inspiration_speed() -> void:
Settings.inspiration_list_speed = maxi(Settings.inspiration_list_speed - 1, 1)
inspiration_speed_label.text = str(Settings.inspiration_list_speed)
Settings.save_settings()
func increase_inspiration_speed() -> void:
Settings.inspiration_list_speed += 1
inspiration_speed_label.text = str(Settings.inspiration_list_speed)
Settings.save_settings()
func lower_hide_for_seconds() -> void:
Settings.hide_for_seconds = maxf(Settings.hide_for_seconds - 1.0, 0.0)
hide_for_seconds_label.text = "%d" % Settings.hide_for_seconds
Settings.save_settings()
func increase_hide_for_seconds() -> void:
Settings.hide_for_seconds = minf(Settings.hide_for_seconds + 1.0, MAX_HIDE_SECONDS)
hide_for_seconds_label.text = "%d" % Settings.hide_for_seconds
Settings.save_settings()
# Sets the on/off quiz setting named [param setting] and saves the quiz settings
func _save_toggle(on: bool, setting: StringName) -> void:
Settings.set(setting, on)
Settings.save_settings()
func _on_hide_beginning_toggled(on: bool) -> void:
_save_toggle(on, &"hide_beginning")
hide_for_seconds_row.visible = on
_fit_to_rows()
# Grows or shrinks the card upward, keeping its bottom edge in place
func _fit_to_rows() -> void:
var height: float = rows.get_combined_minimum_size().y + PADDING.y * 2
card_panel.position.y = -height
card_panel.size.y = height
rows.position = PADDING
rows.size = Vector2(card_panel.size.x - PADDING.x * 2, height - PADDING.y * 2)
func _on_visibility_changed() -> void:
if visible:
show_settings()