Files
MusicPlayer/MainWindow.gd
T
Sansan 3c7b4e5c9d Split the main window into TopBar and Quiz scenes
The quiz (song, playlist, players, music player and the popups opened from
it) moves into Quiz.tscn and the top panel into TopBar.tscn. The main window
keeps only the top bar, the quiz and the popups opened from the top bar, so
other views can be added next to the quiz later. Every node keeps its place
on screen.

Screenshots of every UI state before and after are pixel-identical, and a
layout test checks each node against a baseline taken before the split.
2026-10-06 10:02:22 +02:00

115 lines
2.8 KiB
GDScript

extends Control
## The main window: the top bar, the popups opened from it and the quiz below it.
##
## Everything that is not part of a quiz lives here, so other views can be added next
## to the quiz later.
@onready
var top_bar: TopBar = $TopBar
@onready
var quiz: Quiz = $Quiz
@onready
var search_view: Control = $Search
@onready
var sync_window: Control = %SyncWindow
@onready
var shortcuts_window: Control = %ShortcutsWindow
@onready
var qr_window: Control = %QRWindow
@onready
var about_window: Control = %AboutWindow
@onready
var statistic_popup: PopupPanel = $StatisticsPopupPanel
@onready
var statistic_label: Label = $StatisticsPopupPanel/StatisticsLabel
## Dims the window behind an open popup and keeps clicks from reaching the buttons under it.
var popup_backdrop: PopupBackdrop
func _ready() -> void:
popup_backdrop = PopupBackdrop.add_to(self, _popups())
if OS.has_feature("macos"):
print("is_mac")
top_bar.search_pressed.connect(show_search)
top_bar.sync_pressed.connect(sync_soundtracks)
top_bar.statistics_pressed.connect(get_statistics)
top_bar.shortcuts_pressed.connect(show_shortcuts)
top_bar.about_pressed.connect(show_about)
top_bar.qr_pressed.connect(show_qr)
sync_window.connect("sync_started", _on_sync_started)
sync_window.connect("sync_finished", _on_sync_finished)
quiz.server_changed.connect(search_view.get_list_of_soundtracks)
search_view.get_list_of_soundtracks()
func _input(event: InputEvent) -> void:
if event is InputEventKey and event.pressed:
if event.alt_pressed && event.keycode == KEY_ENTER:
print("Alt + Enter pressed")
Settings.fullscreen = !Settings.fullscreen
if Settings.fullscreen == true:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
if Settings.fullscreen == false:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
if event.alt_pressed && event.keycode == KEY_K:
shortcuts_window.toggle()
func _popups() -> Array[PopupWindow]:
return [search_view, sync_window, qr_window, shortcuts_window, about_window]
func show_search() -> void:
print("show_search")
search_view.toggle()
func show_about() -> void:
print("show_about")
about_window.open()
func show_shortcuts() -> void:
print("show_shortcuts")
shortcuts_window.open()
func show_qr() -> void:
print("show_qr")
qr_window.open()
func get_statistics() -> void:
print("get_statistics")
statistic_popup.visible = true
statistic_label.text = "Total amount of soundtracks in the playlist: " \
+ str(search_view.soundtracks.size())
func sync_soundtracks() -> void:
print("sync_soundtracks")
sync_window.start_sync()
func _on_sync_started() -> void:
print("_on_sync_started")
top_bar.sync_button.disabled = false
quiz.lock_for_sync()
func _on_sync_finished() -> void:
print("_on_sync_finished")
search_view.get_list_of_soundtracks()
quiz.on_sync_finished()