From 1a466a71a3395aa67bdadf9e4d6a50df3261b5fd Mon Sep 17 00:00:00 2001 From: Summersay415 Date: Sun, 24 Nov 2024 14:18:35 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20(=D0=B2=D0=B0=D1=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- launcher/launcher.gd | 18 ++++++++++++++++++ launcher/launcher.tscn | 7 +++++++ remote_manager/remote_manager.gd | 27 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/launcher/launcher.gd b/launcher/launcher.gd index 6dbed1b..abf86ce 100644 --- a/launcher/launcher.gd +++ b/launcher/launcher.gd @@ -163,6 +163,18 @@ func remove_version(version_code: String) -> void: dd.popup_centered() +func show_update(version_code: String, engine_version: String, beta: bool) -> void: + var ud: ConfirmationDialog = $UpdateDialog + ud.dialog_text = "Доступна новая %sверсия %s! Скачать её?" % [ + "бета-" if beta else "", + ($RemoteManager as RemoteManager).remote_versions.get_value(version_code, "name") + ] + ud.confirmed.connect( + ($Downloader as Downloader).download_version.bind(version_code, engine_version) + ) + ud.popup_centered() + + func get_server_url() -> String: return settings_file.get_value("settings", "server") @@ -429,3 +441,9 @@ func _on_download_pressed() -> void: func _on_delete_dialog_canceled() -> void: ($DeleteDialog as AcceptDialog).confirmed.disconnect(_remove_version) + + +func _on_update_dialog_canceled() -> void: + ($UpdateDialog as AcceptDialog).confirmed.disconnect( + ($Downloader as Downloader).download_version + ) diff --git a/launcher/launcher.tscn b/launcher/launcher.tscn index 018dfb0..943d95b 100644 --- a/launcher/launcher.tscn +++ b/launcher/launcher.tscn @@ -162,6 +162,12 @@ visible = false [node name="Downloader" parent="." instance_placeholder="res://downloader/downloader.tscn"] visible = false +[node name="UpdateDialog" type="ConfirmationDialog" parent="."] +title = "Доступно обновление!" +unresizable = true +ok_button_text = "Скачать" +cancel_button_text = "Отмена" + [connection signal="pressed" from="Main/Actions/Download" to="." method="_on_download_pressed"] [connection signal="pressed" from="Main/Actions/Import" to="MouseBlock" method="show"] [connection signal="pressed" from="Main/Actions/Import" to="ImportFileDialog" method="popup_centered"] @@ -171,3 +177,4 @@ visible = false [connection signal="canceled" from="ImportFileDialog" to="." method="_on_import_file_dialog_canceled"] [connection signal="file_selected" from="ImportFileDialog" to="." method="_import_version"] [connection signal="canceled" from="DeleteDialog" to="." method="_on_delete_dialog_canceled"] +[connection signal="canceled" from="UpdateDialog" to="." method="_on_update_dialog_canceled"] diff --git a/remote_manager/remote_manager.gd b/remote_manager/remote_manager.gd index 7d401a6..f3db223 100644 --- a/remote_manager/remote_manager.gd +++ b/remote_manager/remote_manager.gd @@ -5,6 +5,7 @@ extends Window var remote_versions := ConfigFile.new() var remote_engine_versions := ConfigFile.new() var versions_downloaded := false +var update_showed := false var _remote_version_scene: PackedScene = preload("uid://b2y07vkguxpwu") @@ -22,6 +23,7 @@ func _ready() -> void: func download_remote_configs() -> void: _clear_versions() versions_downloaded = false + update_showed = false _status.show() _status.text = "Скачивание списка версий..." _update_button.disabled = true @@ -54,6 +56,7 @@ func list_remote_versions() -> void: prints("Installed engines:", supported_engines) var version_nodes: Array[Node] + var highest_version: int = -1 for version_code: String in remote_versions.get_sections(): print("Checking version %s (%s)." % [ remote_versions.get_value(version_code, "name"), @@ -72,6 +75,7 @@ func list_remote_versions() -> void: if remote_versions.get_value(version_code, "beta") \ and not _launcher.settings_file.get_value("settings", "betas"): continue + var remote_version_node: PanelContainer = _remote_version_scene.instantiate() remote_version_node.name = StringName(version_code) var version_name: String = "Версия %s" % remote_versions.get_value(version_code, "name") @@ -86,6 +90,12 @@ func list_remote_versions() -> void: (remote_version_node.get_node(^"%Download") as BaseButton).disabled = true (remote_version_node.get_node(^"%Download") as Button).text = "Скачано" version_nodes.append(remote_version_node) + + if int(version_code) > highest_version: + if not remote_versions.get_value(version_code, "beta"): + highest_version = int(version_code) + elif _launcher.settings_file.get_value("settings", "beta_updates"): + highest_version = int(version_code) version_nodes.sort_custom(func(first: Node, second: Node) -> bool: return int(first.name) < int(second.name)) @@ -96,6 +106,23 @@ func list_remote_versions() -> void: %Versions.move_child(node, 0) var newest_label: Label = %Versions.get_child(0).get_node(^"%VersionName") newest_label.text = "Новейшая " + newest_label.text + + var highest_installed_version: int = -1 + for installed_version: String in _launcher.versions_file.get_sections(): + if int(installed_version) > highest_installed_version: + highest_installed_version = int(installed_version) + + print("Highest remote version: %d, highest installed version: %d." % [ + highest_version, + highest_installed_version + ]) + if not update_showed and highest_version > highest_installed_version \ + and _launcher.settings_file.get_value("settings", "updates"): + update_showed = true + var version_code: String = str(highest_version) + var engine_version: String = remote_versions.get_value(version_code, "engine_version") + var beta: bool = remote_versions.get_value(version_code, "beta") + _launcher.show_update(version_code, engine_version, beta) func _clear_versions() -> void: