diff --git a/README.md b/README.md index 5b70b4d..a105003 100644 --- a/README.md +++ b/README.md @@ -14,27 +14,27 @@ game/ - project.godot - icon.svg - assets/ - - fonts/ - - AlibabaPuHuiTi-3-65-Medium.ttf # 阿里巴巴普惠体 - - pics/ + - fonts/ + - AlibabaPuHuiTi-3-65-Medium.ttf # 阿里巴巴普惠体 + - pics/ - scenes - - main_menu.tscn - - game.tscn - - settings.tscn + - main_menu.tscn + - game.tscn + - settings.tscn - scripts/ - - autoload/ - - GameManager.gd # 游戏管理 - - DownloadManager.gd # 下载管理 - - MultiGame.gd # 多人游戏功能 - - SceneManager.gd # 场景管理 - - main_menu/ - - main_menu.gd - - join_game_ui.gd - - create_game_ui.gd - - game/ - - game.gd - - settings/ - - settings.gd + - autoload/ + - GameManager.gd # 游戏管理 + - DownloadManager.gd # 下载管理 + - MultiGame.gd # 多人游戏功能 + - SceneManager.gd # 场景管理 + - main_menu/ + - main_menu.gd + - join_game_ui.gd + - create_game_ui.gd + - game/ + - game.gd + - settings/ + - settings.gd ``` ## 如何运行 diff --git a/scenes/settings.tscn b/scenes/settings.tscn index 3373d21..33c5fb3 100644 --- a/scenes/settings.tscn +++ b/scenes/settings.tscn @@ -76,19 +76,19 @@ theme_override_fonts/font = ExtResource("2_6wm04") theme_override_font_sizes/font_size = 24 [node name="SaveButton" type="Button" parent="."] -offset_left = 89.0 -offset_top = 902.0 -offset_right = 253.0 -offset_bottom = 979.0 +offset_left = 93.0 +offset_top = 913.0 +offset_right = 257.0 +offset_bottom = 990.0 theme_override_fonts/font = ExtResource("2_6wm04") theme_override_font_sizes/font_size = 30 text = "保存设置" [node name="DownloadButton" type="Button" parent="."] -offset_left = 495.0 -offset_top = 912.0 -offset_right = 671.0 -offset_bottom = 1001.0 +offset_left = 493.0 +offset_top = 905.0 +offset_right = 669.0 +offset_bottom = 994.0 theme_override_fonts/font = ExtResource("2_6wm04") theme_override_font_sizes/font_size = 30 text = "下载文件" @@ -102,6 +102,12 @@ theme_override_fonts/font = ExtResource("2_6wm04") theme_override_font_sizes/font_size = 30 text = "取消" +[node name="Tips" type="Label" parent="."] +offset_left = 711.0 +offset_top = 913.0 +offset_right = 1738.0 +offset_bottom = 966.0 + [connection signal="pressed" from="SaveButton" to="." method="_on_save_button_pressed"] [connection signal="pressed" from="DownloadButton" to="." method="_on_download_button_pressed"] [connection signal="pressed" from="CancelButton" to="." method="_on_cancel_button_pressed"] diff --git a/scripts/autoload/DownloadManager.gd b/scripts/autoload/DownloadManager.gd index 71d903a..b8b3211 100644 --- a/scripts/autoload/DownloadManager.gd +++ b/scripts/autoload/DownloadManager.gd @@ -1,53 +1,19 @@ extends Node -@onready var http_request = $HTTPRequest +func download_file(server_path: String, local_path: String) -> void: + var http = HTTPRequest.new() + http.download_file = local_path + http.request(server_path) -# 下载文件 -func download_file(url: String, filename: String): - # 构建保存路径 - var save_path = "user://" + filename - print("开始下载: ", url) - print("保存到: ", save_path) - - # 发送请求 - var error = http_request.request(url) - if error != OK: - push_error("请求发送失败: " + str(error)) - return false - - # 连接信号(一次性) - if http_request.is_connected("request_completed", _on_request_completed): - http_request.request_completed.disconnect(_on_request_completed) - - http_request.request_completed.connect(_on_request_completed.bind(save_path), CONNECT_ONE_SHOT) - - return true +func download_from_origin() -> int: + var origin = GameManager.data_origin -# 请求完成回调 -func _on_request_completed(result, response_code, headers, body, save_path): - if result != HTTPRequest.RESULT_SUCCESS: - push_error("下载失败,错误代码: " + str(result)) - return + if origin.substr(0, 4) != "http": + return 1 - if response_code != 200: - push_error("HTTP错误: " + str(response_code)) - return - # 保存文件 - var file = FileAccess.open(save_path, FileAccess.WRITE) - if file == null: - push_error("无法创建文件: " + save_path) - push_error("错误: " + str(FileAccess.get_open_error())) - return - - file.store_buffer(body) - file.close() - - print("文件保存成功: " + save_path) - print("文件大小: " + str(body.size()) + " 字节") -func download_from_origin() -> void: - if GameManager.data_origin.substr(0, 4) != "http": - return - - + return 0 + +func load_resource(): + pass diff --git a/scripts/settings/settings.gd b/scripts/settings/settings.gd index b69f0a2..5ffcd18 100644 --- a/scripts/settings/settings.gd +++ b/scripts/settings/settings.gd @@ -17,4 +17,11 @@ func _on_cancel_button_pressed() -> void: func _on_download_button_pressed() -> void: - pass # Replace with function body. + $Tips.text = "提示:已开始下载,请勿关闭设置页面" + var result: int = DownloadManager.download_from_origin() + if result == 1: + $Tips.text = "提示:下载失败。数据源路径错误" + $Tips.text = "提示:正在加载资源,请勿关闭设置页面" + DownloadManager.load_resource() + $Tips.text = "提示:完成加载" + \ No newline at end of file