class_name SongControls extends Control ## The buttons for the song that is playing: show the answer, and go to the next song. signal show_answer_pressed signal next_pressed ## Emitted when Next is pressed at the end of a prepared quiz, where it reads ## "Show winner". signal show_winner_pressed const NEXT_TEXT: String = "Next song" const SHOW_WINNER_TEXT: String = "Show winner" ## True while Next reads "Show winner", after the last song of a prepared quiz. var shows_winner: bool = false @onready var show_answer_button: Button = $ShowAnswerButton @onready var next_button: Button = $NextButton func _ready() -> void: show_answer_button.pressed.connect(show_answer_pressed.emit) next_button.pressed.connect(_on_next_button_pressed) ## Enables Next while there is a downloaded song to play next. func set_next_enabled(enabled: bool) -> void: _set_shows_winner(false) next_button.disabled = !enabled ## Turns Next into "Show winner", for when the last song of a prepared quiz has played. func show_winner_button() -> void: _set_shows_winner(true) next_button.disabled = false ## Disables both buttons, e.g. while the server syncs the song list. Unlocking enables ## Show answer again; Next comes back when the next song has been downloaded. func set_locked(locked: bool) -> void: show_answer_button.disabled = locked if locked: next_button.disabled = true func _set_shows_winner(on: bool) -> void: shows_winner = on next_button.text = SHOW_WINNER_TEXT if on else NEXT_TEXT func _on_next_button_pressed() -> void: if shows_winner: show_winner_pressed.emit() else: next_pressed.emit()