Show in the top bar when a newer version is available
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.
This commit is contained in:
1 parent
240c331ab2
commit
41974ea5e3
9 files changed
+4012
-1
No files matched your search
@@ -39,6 +39,20 @@ theme_type_variation = &"HighlightLarge"
|
||||
text = "DEBUG"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="UpdateLabel" type="Label" parent="." unique_id=1959221258]
|
||||
visible = false
|
||||
layout_mode = 0
|
||||
offset_left = 1096.0
|
||||
offset_top = 12.0
|
||||
offset_right = 1432.0
|
||||
offset_bottom = 50.0
|
||||
mouse_filter = 1
|
||||
theme_type_variation = &"HighlightMedium"
|
||||
text = "Version 0.0.0 is available"
|
||||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
text_overrun_behavior = 3
|
||||
|
||||
[node name="SyncButton" type="Button" parent="." unique_id=1228313556]
|
||||
layout_mode = 0
|
||||
offset_left = 1450.0
|
||||
|
||||
@@ -38,6 +38,7 @@ func _ready() -> void:
|
||||
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.server_changed.connect(top_bar.check_for_update)
|
||||
quiz.event_logged.connect(log_popup.add_log_row)
|
||||
statistics_view.soundtrack_selected.connect(soundtrack_stats_popup.show_soundtrack)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ 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
|
||||
|
||||
@@ -27,6 +28,36 @@ func _ready() -> void:
|
||||
$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].
|
||||
|
||||
Reference in new issue
Block a user