Save the quiz settings to the config folder
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.
This commit is contained in:
1 parent
b510aa47f2
commit
92e3a66075
15 files changed
+835
-591
No files matched your search
+23
-19
@@ -1,8 +1,10 @@
|
||||
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, statistics, the winning score and the
|
||||
## inspiration list. It does not dim the quiz, so it can be changed during a song.
|
||||
## 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_quiz_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.
|
||||
@@ -26,8 +28,6 @@ const PADDING: Vector2 = Vector2(16, 12)
|
||||
@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 low_played_button: CheckButton = %LowPlayedCheckButton
|
||||
@onready var add_to_database_button: CheckButton = %AddToDatabaseCheckButton
|
||||
@onready var score_label: Label = %ScoreLabel
|
||||
@onready var lower_winning_score_button: Button = %LowerButton
|
||||
@onready var increase_winning_score_button: Button = %IncreaseButton
|
||||
@@ -37,17 +37,12 @@ const PADDING: Vector2 = Vector2(16, 12)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
auto_repeat_button.toggled.connect(func(on: bool) -> void: Settings.auto_repeat_song = on)
|
||||
stop_after_current_button.toggled.connect(
|
||||
func(on: bool) -> void: Settings.stop_after_current = on)
|
||||
hide_next_track_button.toggled.connect(
|
||||
func(on: bool) -> void: Settings.hide_next_track = on)
|
||||
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(func(on: bool) -> void: Settings.hide_length = on)
|
||||
hide_ticks_button.toggled.connect(func(on: bool) -> void: Settings.hide_ticks = on)
|
||||
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)
|
||||
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)
|
||||
@@ -58,8 +53,8 @@ func _ready() -> void:
|
||||
show_settings()
|
||||
|
||||
|
||||
## Shows the current settings. Some change outside this card, e.g. winning turns
|
||||
## statistics off, so this runs every time the card opens.
|
||||
## 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)
|
||||
@@ -67,8 +62,6 @@ func show_settings() -> void:
|
||||
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)
|
||||
low_played_button.set_pressed_no_signal(Settings.use_low_played_mode)
|
||||
add_to_database_button.set_pressed_no_signal(Settings.add_to_stats)
|
||||
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)
|
||||
@@ -88,30 +81,41 @@ func increase_winning_score() -> void:
|
||||
func set_winning_score(new_score: int) -> void:
|
||||
Settings.winning_score = maxi(new_score, 1)
|
||||
score_label.text = str(Settings.winning_score)
|
||||
Settings.save_quiz_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_quiz_settings()
|
||||
|
||||
|
||||
func increase_inspiration_speed() -> void:
|
||||
Settings.inspiration_list_speed += 1
|
||||
inspiration_speed_label.text = str(Settings.inspiration_list_speed)
|
||||
Settings.save_quiz_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_quiz_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_quiz_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_quiz_settings()
|
||||
|
||||
|
||||
func _on_hide_beginning_toggled(on: bool) -> void:
|
||||
Settings.hide_beginning = on
|
||||
_save_toggle(on, &"hide_beginning")
|
||||
hide_for_seconds_row.visible = on
|
||||
_fit_to_rows()
|
||||
|
||||
|
||||
Reference in new issue
Block a user