At start and after switching server, the game asks the server for the newest MusicPlayer release and shows "Version X is available" in the top bar when it is newer than this one.
67 lines
2.7 KiB
GDScript
67 lines
2.7 KiB
GDScript
class_name TopBar
|
|
extends Control
|
|
## The bar along the top of the main window, with the title, the Quiz and Statistics tabs
|
|
## and the buttons for things that are not part of a quiz.
|
|
|
|
signal sync_pressed
|
|
signal settings_pressed
|
|
signal shortcuts_pressed
|
|
signal about_pressed
|
|
signal qr_pressed
|
|
## Emitted when a tab is chosen: [code]&"quiz"[/code] or [code]&"statistics"[/code].
|
|
signal tab_selected(tab: StringName)
|
|
|
|
@onready var sync_button: Button = $SyncButton
|
|
@onready var debug_label: Label = $DebugLabel
|
|
@onready var update_label: Label = $UpdateLabel
|
|
@onready var quiz_tab: Button = $QuizTab
|
|
@onready var statistics_tab: Button = $StatisticsTab
|
|
|
|
|
|
func _ready() -> void:
|
|
# Debug builds use the local server, see Settings
|
|
debug_label.visible = Settings.is_debug
|
|
sync_button.pressed.connect(sync_pressed.emit)
|
|
$SettingsButton.pressed.connect(settings_pressed.emit)
|
|
$ShortcutsButton.pressed.connect(shortcuts_pressed.emit)
|
|
$AboutButton.pressed.connect(about_pressed.emit)
|
|
$QRButton.pressed.connect(qr_pressed.emit)
|
|
quiz_tab.pressed.connect(tab_selected.emit.bind(&"quiz"))
|
|
statistics_tab.pressed.connect(tab_selected.emit.bind(&"statistics"))
|
|
check_for_update()
|
|
|
|
|
|
## Asks the server for the newest MusicPlayer release and tells the user when it is newer
|
|
## than this one.
|
|
func check_for_update() -> void:
|
|
MusicServerClient.fetch_latest_client_version(show_latest_version)
|
|
|
|
|
|
## Shows that [param latest] is available when it is newer than this version, and hides
|
|
## the message otherwise.
|
|
func show_latest_version(latest: Variant) -> void:
|
|
var newer: bool = latest is String && is_newer_version(latest, Settings.version)
|
|
update_label.visible = newer
|
|
if newer:
|
|
update_label.text = "Version %s is available" % latest
|
|
update_label.tooltip_text = "You have %s" % Settings.version
|
|
|
|
|
|
## Whether version [param latest] is newer than [param current], comparing numbers such as
|
|
## [code]1.10.0[/code] part by part. A leading "v" is ignored, and missing parts count as 0.
|
|
static func is_newer_version(latest: String, current: String) -> bool:
|
|
var latest_parts: PackedStringArray = latest.strip_edges().trim_prefix("v").split(".")
|
|
var current_parts: PackedStringArray = current.strip_edges().trim_prefix("v").split(".")
|
|
for i: int in maxi(latest_parts.size(), current_parts.size()):
|
|
var a: int = latest_parts[i].to_int() if i < latest_parts.size() else 0
|
|
var b: int = current_parts[i].to_int() if i < current_parts.size() else 0
|
|
if a != b:
|
|
return a > b
|
|
return false
|
|
|
|
|
|
## Shows [param tab] as the chosen tab, without emitting [signal tab_selected].
|
|
func select_tab(tab: StringName) -> void:
|
|
quiz_tab.set_pressed_no_signal(tab == &"quiz")
|
|
statistics_tab.set_pressed_no_signal(tab == &"statistics")
|