From 291f4e7e0d906deed312e73ff96afbb85b5bb1fa Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 28 Oct 2022 16:00:37 -0500 Subject: [PATCH] Added ProgressBar for showing update progress (Real data\!) --- Main_menu.gd | 6 +++++- Main_menu.tscn | 27 ++++++++++++++++++++++++--- ProgressBar.gd | 8 ++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 ProgressBar.gd diff --git a/Main_menu.gd b/Main_menu.gd index c16f995..1214060 100644 --- a/Main_menu.gd +++ b/Main_menu.gd @@ -104,6 +104,8 @@ func _download_request_completed(_result, _response_code, _headers, body): # Enable (Un-disable?) the Play_button $Panel/Play_button.disabled = false + $Panel/ProgressBar.hide() + $Panel/ProgressBar.value = 0 # When the play button is pressed, func _on_Play_button_pressed(): @@ -130,6 +132,8 @@ func _on_Play_button_pressed(): # Send an HTTP request to the url var error = download.request(url) + $Panel/ProgressBar.show() + $Panel/ProgressBar.request = download # If the request was *created* successfully (Not neccessarily saying the server responded positively), if error == OK: @@ -138,7 +142,7 @@ func _on_Play_button_pressed(): # If not, else: # Debug message! - print("Failed to send HTTP request to server! Error: "+error) + notice("Failed to send HTTP request to server! Error: "+error, "") # If not, # Play the game diff --git a/Main_menu.tscn b/Main_menu.tscn index 3b51491..7e10dd5 100644 --- a/Main_menu.tscn +++ b/Main_menu.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://textures/backgrounds/background1.png" type="Texture" id=1] [ext_resource path="res://fonts/SPACEBAR.ttf" type="DynamicFontData" id=2] [ext_resource path="res://Main_menu.gd" type="Script" id=3] [ext_resource path="res://fonts/Title-font.tres" type="DynamicFont" id=4] [ext_resource path="res://themes/Base_theme.tres" type="Theme" id=5] +[ext_resource path="res://fonts/SPACE.tres" type="DynamicFont" id=6] +[ext_resource path="res://ProgressBar.gd" type="Script" id=7] [sub_resource type="Theme" id=1] default_font = ExtResource( 4 ) @@ -28,6 +30,14 @@ corner_detail = 16 size = 32 font_data = ExtResource( 2 ) +[sub_resource type="StyleBoxFlat" id=6] +bg_color = Color( 0.0509804, 0.0666667, 0.227451, 1 ) +border_color = Color( 0.219608, 0.211765, 0.227451, 1 ) +corner_radius_top_left = 8 +corner_radius_top_right = 8 +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 + [node name="Main_menu" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 @@ -64,13 +74,24 @@ custom_styles/panel = SubResource( 4 ) [node name="Play_button" type="Button" parent="Panel"] margin_left = 288.0 -margin_top = 32.0 +margin_top = 16.0 margin_right = 621.0 -margin_bottom = 85.0 +margin_bottom = 69.0 rect_scale = Vector2( 0.962016, 0.91427 ) custom_fonts/font = SubResource( 5 ) text = "play" +[node name="ProgressBar" type="ProgressBar" parent="Panel"] +visible = false +margin_left = 296.0 +margin_top = 72.0 +margin_right = 600.0 +margin_bottom = 97.0 +custom_fonts/font = ExtResource( 6 ) +custom_styles/fg = SubResource( 6 ) +value = 20.0 +script = ExtResource( 7 ) + [node name="Notices" type="VBoxContainer" parent="."] margin_top = 80.0 margin_right = 192.0 diff --git a/ProgressBar.gd b/ProgressBar.gd new file mode 100644 index 0000000..73d0b21 --- /dev/null +++ b/ProgressBar.gd @@ -0,0 +1,8 @@ +extends ProgressBar + +var request + +func _process(delta): + if request: + max_value = request.get_body_size() + value = request.get_downloaded_bytes()