From e882e0e5fdd1522c0a0be1116ab9496087e1c432 Mon Sep 17 00:00:00 2001 From: Penelope Date: Sat, 5 Apr 2025 13:32:57 -0300 Subject: [PATCH] End of Chapter 3. Loading scene and new game button working! --- project.godot | 6 +++++- scenes/game.tscn | 25 +++++++++++++++++++++ scenes/ui/loading_screen.tscn | 7 ++++-- scenes/ui/title_screen.tscn | 6 +++++- scripts/loader.gd | 36 +++++++++++++++++++++++++++++++ scripts/loader.gd.uid | 1 + scripts/title/title_screen.gd | 15 +++++++++++++ scripts/title/title_screen.gd.uid | 1 + scripts/ui/loading_screen.gd | 16 ++++++++++++++ scripts/ui/loading_screen.gd.uid | 1 + 10 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 scenes/game.tscn create mode 100644 scripts/loader.gd create mode 100644 scripts/loader.gd.uid create mode 100644 scripts/title/title_screen.gd create mode 100644 scripts/title/title_screen.gd.uid create mode 100644 scripts/ui/loading_screen.gd create mode 100644 scripts/ui/loading_screen.gd.uid diff --git a/project.godot b/project.godot index bb94746..8bc694c 100644 --- a/project.godot +++ b/project.godot @@ -11,11 +11,15 @@ config_version=5 [application] config/name="Legacy of the Ancient Questor" -config/version="prototype 1" +config/version="prototype 2" run/main_scene="uid://dm8aun68tgprd" config/features=PackedStringArray("4.4", "GL Compatibility") config/icon="res://icon.svg" +[autoload] + +Loader="*res://scripts/loader.gd" + [display] window/size/viewport_width=640 diff --git a/scenes/game.tscn b/scenes/game.tscn new file mode 100644 index 0000000..533a3a5 --- /dev/null +++ b/scenes/game.tscn @@ -0,0 +1,25 @@ +[gd_scene format=3 uid="uid://c0b5w48jk67qd"] + +[node name="Game" type="Node2D"] + +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = 640.0 +offset_bottom = 360.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="CenterContainer" type="CenterContainer" parent="Control"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Label" type="Label" parent="Control/CenterContainer"] +layout_mode = 2 +text = "Game!" diff --git a/scenes/ui/loading_screen.tscn b/scenes/ui/loading_screen.tscn index 25226a2..2e5e0e5 100644 --- a/scenes/ui/loading_screen.tscn +++ b/scenes/ui/loading_screen.tscn @@ -1,16 +1,19 @@ -[gd_scene load_steps=4 format=3 uid="uid://c8fyt7v0ksdyc"] +[gd_scene load_steps=5 format=3 uid="uid://c8fyt7v0ksdyc"] [ext_resource type="Theme" uid="uid://dnxny0n7ti7eq" path="res://themes/default_theme.tres" id="1_5fj0j"] +[ext_resource type="Script" uid="uid://d1ag1ag2bbhtx" path="res://scripts/ui/loading_screen.gd" id="1_s2kth"] [ext_resource type="Texture2D" uid="uid://cyw8i4rnh8x5x" path="res://gfx/ui/loading_frame.png" id="2_s2kth"] [ext_resource type="Texture2D" uid="uid://df4gfyht0d2r3" path="res://gfx/ui/loading_bar.png" id="3_s41fs"] -[node name="Loading Screen" type="Control"] +[node name="Loading Screen" type="Control" node_paths=PackedStringArray("loadingBar")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("1_s2kth") +loadingBar = NodePath("CenterContainer/VBoxContainer/Loading Progress") [node name="Background" type="ColorRect" parent="."] layout_mode = 1 diff --git a/scenes/ui/title_screen.tscn b/scenes/ui/title_screen.tscn index fdb8b64..f749074 100644 --- a/scenes/ui/title_screen.tscn +++ b/scenes/ui/title_screen.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=7 format=3 uid="uid://dm8aun68tgprd"] +[gd_scene load_steps=8 format=3 uid="uid://dm8aun68tgprd"] [ext_resource type="Texture2D" uid="uid://cm8lciwc0iuq" path="res://gfx/title/tree-3094982_1280.jpg" id="1_eb34j"] +[ext_resource type="Script" uid="uid://bklj1ua1qok02" path="res://scripts/title/title_screen.gd" id="1_r23qo"] [ext_resource type="FontFile" uid="uid://1u28cjgctsn7" path="res://fonts/alagard_by_pix3m-d6awiwp.ttf" id="2_aqpy5"] [ext_resource type="Theme" uid="uid://dnxny0n7ti7eq" path="res://themes/default_theme.tres" id="3_w8uqo"] [ext_resource type="Script" uid="uid://bfc7ybsw6riri" path="res://scripts/title/version_number.gd" id="4_a4ium"] @@ -25,6 +26,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("1_r23qo") [node name="Background Image" type="TextureRect" parent="."] layout_mode = 1 @@ -109,3 +111,5 @@ text = "Version: " label_settings = SubResource("LabelSettings_r23qo") vertical_alignment = 1 script = ExtResource("4_a4ium") + +[connection signal="pressed" from="Content/VBoxContainer/HBoxContainer/Button Menu/New Game Button" to="." method="_on_new_game_button_pressed"] diff --git a/scripts/loader.gd b/scripts/loader.gd new file mode 100644 index 0000000..55846f5 --- /dev/null +++ b/scripts/loader.gd @@ -0,0 +1,36 @@ +extends Node + +signal LOADING_PROGRESS_UPDATED +@export var loadingScene: Node = preload("res://scenes/ui/loading_screen.tscn").instantiate() + +var scenePath: String + +func loadScene(caller: Node, path: String): + scenePath = path + + get_tree().root.add_child(loadingScene) + + ResourceLoader.load_threaded_request(scenePath) + print(scenePath) + caller.queue_free() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + if scenePath: + var progress: Array = [] + var loaderStatus: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(scenePath, progress) + + if loaderStatus == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED: + var loadedScene = ResourceLoader.load_threaded_get(scenePath).instantiate() + get_tree().root.remove_child(loadingScene) + get_tree().root.add_child(loadedScene) + scenePath = "" + + elif loaderStatus == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS: + LOADING_PROGRESS_UPDATED.emit(progress[0]) + else: + pass + + + diff --git a/scripts/loader.gd.uid b/scripts/loader.gd.uid new file mode 100644 index 0000000..c8049e2 --- /dev/null +++ b/scripts/loader.gd.uid @@ -0,0 +1 @@ +uid://b406e4rlci4u3 diff --git a/scripts/title/title_screen.gd b/scripts/title/title_screen.gd new file mode 100644 index 0000000..8b2e1bf --- /dev/null +++ b/scripts/title/title_screen.gd @@ -0,0 +1,15 @@ +extends Control + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_new_game_button_pressed() -> void: + Loader.loadScene(self, "res://scenes/game.tscn") diff --git a/scripts/title/title_screen.gd.uid b/scripts/title/title_screen.gd.uid new file mode 100644 index 0000000..e52058b --- /dev/null +++ b/scripts/title/title_screen.gd.uid @@ -0,0 +1 @@ +uid://bklj1ua1qok02 diff --git a/scripts/ui/loading_screen.gd b/scripts/ui/loading_screen.gd new file mode 100644 index 0000000..378c543 --- /dev/null +++ b/scripts/ui/loading_screen.gd @@ -0,0 +1,16 @@ +extends Control + +@export var loadingBar: TextureProgressBar + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + Loader.LOADING_PROGRESS_UPDATED.connect(_on_progress_updated) + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_progress_updated(percentage: float) -> void: + loadingBar.value = percentage diff --git a/scripts/ui/loading_screen.gd.uid b/scripts/ui/loading_screen.gd.uid new file mode 100644 index 0000000..9d349b7 --- /dev/null +++ b/scripts/ui/loading_screen.gd.uid @@ -0,0 +1 @@ +uid://d1ag1ag2bbhtx