- A Quiz settings button under the player bar opens a small card above it with the quiz settings, including Auto repeat, which moves there from under the player bar. The card does not dim the quiz, so it can be changed during a song, and grows to fit its rows. - A Settings button in the top bar opens the application settings: server, fullscreen and songs to download ahead. Quick sync is gone, as the server no longer has it, and the server list is in Settings. - Labels use sentence case, and seconds to hide show as whole numbers. - Debug builds switch to the local server and a low winning score in the Settings autoload, before any scene asks the server for anything. The DEBUG label moves to the top bar, so it shows on every tab. - Search moves from the top bar back to the quiz toolbar, as the Statistics tab has its own search.
122 lines
3.9 KiB
GDScript
122 lines
3.9 KiB
GDScript
class_name MainWindow
|
|
extends Control
|
|
## The main window: the top bar, the popups opened from it, and below it the quiz or the
|
|
## statistics, depending on the chosen tab.
|
|
##
|
|
## Everything that is not part of a quiz lives here.
|
|
|
|
## Dims the window behind an open popup and keeps clicks from reaching the buttons under it.
|
|
var popup_backdrop: PopupBackdrop
|
|
|
|
@onready var top_bar: TopBar = $TopBar
|
|
@onready var quiz: Quiz = $Quiz
|
|
@onready var search_popup: SearchPopup = $SearchPopup
|
|
@onready var sync_popup: SyncPopup = %SyncPopup
|
|
@onready var shortcuts_popup: ShortcutsPopup = %ShortcutsPopup
|
|
@onready var qr_popup: QRPopup = %QRPopup
|
|
@onready var about_popup: AboutPopup = %AboutPopup
|
|
@onready var log_popup: LogPopup = %LogPopup
|
|
@onready var settings_popup: SettingsPopup = %SettingsPopup
|
|
@onready var statistics_view: StatisticsView = $StatisticsView
|
|
@onready var soundtrack_stats_popup: SoundtrackStatsPopup = $SoundtrackStatsPopup
|
|
|
|
|
|
func _ready() -> void:
|
|
popup_backdrop = PopupBackdrop.add_to(self, _popups())
|
|
if OS.has_feature("macos"):
|
|
GameLog.debug("is_mac")
|
|
quiz.search_pressed.connect(show_search)
|
|
top_bar.sync_pressed.connect(sync_soundtracks)
|
|
top_bar.tab_selected.connect(show_tab)
|
|
top_bar.shortcuts_pressed.connect(show_shortcuts)
|
|
top_bar.about_pressed.connect(show_about)
|
|
top_bar.qr_pressed.connect(show_qr)
|
|
top_bar.settings_pressed.connect(settings_popup.open)
|
|
settings_popup.server_changed.connect(quiz.on_server_changed)
|
|
settings_popup.visibility_changed.connect(_on_settings_popup_visibility_changed)
|
|
|
|
sync_popup.sync_started.connect(_on_sync_started)
|
|
sync_popup.sync_finished.connect(_on_sync_finished)
|
|
quiz.server_changed.connect(search_popup.get_list_of_soundtracks)
|
|
quiz.event_logged.connect(log_popup.add_log_row)
|
|
statistics_view.soundtrack_selected.connect(soundtrack_stats_popup.show_soundtrack)
|
|
|
|
search_popup.get_list_of_soundtracks()
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event is InputEventKey and event.pressed:
|
|
if event.alt_pressed && event.keycode == KEY_ENTER:
|
|
GameLog.debug("Alt + Enter pressed")
|
|
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)
|
|
if event.alt_pressed && event.keycode == KEY_K:
|
|
shortcuts_popup.toggle()
|
|
if event.alt_pressed && event.keycode == KEY_L:
|
|
log_popup.toggle()
|
|
|
|
|
|
func _popups() -> Array[BasePopup]:
|
|
return [search_popup, sync_popup, qr_popup, shortcuts_popup, about_popup, log_popup,
|
|
soundtrack_stats_popup, settings_popup]
|
|
|
|
|
|
# How many songs to download ahead can be changed in the settings. Waiting until the
|
|
# settings are closed avoids starting downloads while the number is clicked up and down.
|
|
func _on_settings_popup_visibility_changed() -> void:
|
|
if !settings_popup.visible:
|
|
quiz.song_loader.fill_cache()
|
|
|
|
|
|
func show_search() -> void:
|
|
GameLog.debug("show_search")
|
|
search_popup.toggle()
|
|
|
|
|
|
func show_about() -> void:
|
|
GameLog.debug("show_about")
|
|
about_popup.open()
|
|
|
|
|
|
func show_shortcuts() -> void:
|
|
GameLog.debug("show_shortcuts")
|
|
shortcuts_popup.open()
|
|
|
|
|
|
func show_qr() -> void:
|
|
GameLog.debug("show_qr")
|
|
qr_popup.open()
|
|
|
|
|
|
## Shows the quiz for [code]&"quiz"[/code] or the statistics for [code]&"statistics"[/code].
|
|
## A hidden quiz keeps playing its song.
|
|
func show_tab(tab: StringName) -> void:
|
|
GameLog.debug("show_tab ", tab)
|
|
top_bar.select_tab(tab)
|
|
statistics_view.visible = tab == &"statistics"
|
|
quiz.visible = !statistics_view.visible
|
|
if statistics_view.visible:
|
|
statistics_view.refresh()
|
|
|
|
|
|
func sync_soundtracks() -> void:
|
|
GameLog.debug("sync_soundtracks")
|
|
sync_popup.start_sync()
|
|
|
|
|
|
func _on_sync_started() -> void:
|
|
GameLog.debug("_on_sync_started")
|
|
top_bar.sync_button.disabled = false
|
|
quiz.lock_for_sync()
|
|
|
|
|
|
func _on_sync_finished() -> void:
|
|
GameLog.debug("_on_sync_finished")
|
|
search_popup.get_list_of_soundtracks()
|
|
quiz.on_sync_finished()
|
|
if statistics_view.visible:
|
|
statistics_view.refresh()
|