diff --git a/scenes/game/maps/entities/player.tscn b/scenes/game/maps/entities/player.tscn index f81e8e4..962f038 100644 --- a/scenes/game/maps/entities/player.tscn +++ b/scenes/game/maps/entities/player.tscn @@ -3,8 +3,9 @@ [ext_resource type="PackedScene" uid="uid://d3e5mg0gk8u7r" path="res://scenes/game/maps/entities/mob.tscn" id="1_7y2qh"] [ext_resource type="Script" uid="uid://dsguwthn2datq" path="res://scripts/game/maps/entities/Player.gd" id="2_us7jc"] -[node name="Player" instance=ExtResource("1_7y2qh")] +[node name="Player" node_paths=PackedStringArray("camera") instance=ExtResource("1_7y2qh")] script = ExtResource("2_us7jc") +camera = NodePath("Camera2D") [node name="Camera2D" type="Camera2D" parent="." index="3"] zoom = Vector2(1.5, 1.5) diff --git a/scenes/game_screen.tscn b/scenes/game_screen.tscn index f1bd7a9..bf19557 100644 --- a/scenes/game_screen.tscn +++ b/scenes/game_screen.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://c0b5w48jk67qd"] +[gd_scene load_steps=12 format=3 uid="uid://c0b5w48jk67qd"] [ext_resource type="Script" uid="uid://c0uvlwmkm3r8o" path="res://scripts/game/game_screen.gd" id="1_dthvl"] [ext_resource type="Script" uid="uid://dcqqr8b42tn0x" path="res://scripts/game/CommandProcessor.gd" id="2_r01d7"] @@ -7,6 +7,11 @@ [ext_resource type="Texture2D" uid="uid://ccxs3ctob15es" path="res://gfx/ui/main_frame.png" id="5_mjl5p"] [ext_resource type="FontFile" uid="uid://1u28cjgctsn7" path="res://fonts/alagard_by_pix3m-d6awiwp.ttf" id="6_2yu03"] [ext_resource type="Script" uid="uid://dv3fd112uj8o1" path="res://scripts/ui/Message Console.gd" id="7_5vo8s"] +[ext_resource type="Script" uid="uid://ba05sgen1geyk" path="res://scripts/ui/LoadingPanel.gd" id="8_4m8lb"] +[ext_resource type="Theme" uid="uid://dnxny0n7ti7eq" path="res://themes/default_theme.tres" id="9_mjl5p"] +[ext_resource type="PackedScene" uid="uid://bpsrg5d3gncnd" path="res://scenes/game/maps/entities/player.tscn" id="10_2yu03"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5vo8s"] [node name="Game" type="Node" node_paths=PackedStringArray("map")] script = ExtResource("1_dthvl") @@ -95,6 +100,39 @@ render_target_update_mode = 4 [node name="MapContainer" type="Node" parent="UI/Map View/SubViewport"] script = ExtResource("3_vnpv3") +[node name="LoadingPanel" type="MarginContainer" parent="UI" node_paths=PackedStringArray("player")] +visible = false +layout_mode = 0 +offset_left = 134.0 +offset_top = 15.0 +offset_right = 627.0 +offset_bottom = 250.0 +script = ExtResource("8_4m8lb") +player = NodePath("CenterContainer/VBoxContainer/PanelContainer/Player") + +[node name="ColorRect" type="ColorRect" parent="UI/LoadingPanel"] +layout_mode = 2 +color = Color(0, 0, 0, 1) + +[node name="CenterContainer" type="CenterContainer" parent="UI/LoadingPanel"] +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="UI/LoadingPanel/CenterContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="UI/LoadingPanel/CenterContainer/VBoxContainer"] +layout_mode = 2 +theme = ExtResource("9_mjl5p") +text = "Loading..." + +[node name="PanelContainer" type="PanelContainer" parent="UI/LoadingPanel/CenterContainer/VBoxContainer"] +custom_minimum_size = Vector2(0, 16) +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxEmpty_5vo8s") + +[node name="Player" parent="UI/LoadingPanel/CenterContainer/VBoxContainer/PanelContainer" instance=ExtResource("10_2yu03")] +position = Vector2(26, 0) + [connection signal="BROADCAST_COMMAND" from="Command Processor" to="UI/Message Console" method="_on_command"] [connection signal="timeout" from="Command Processor" to="Command Processor" method="_on_timeout"] [connection signal="pressed" from="UI/Left Display/Contents/Command Menu/Pass Button" to="UI" method="_on_pass_button_pressed"] diff --git a/scripts/game/commands/CommandDispatcher.gd b/scripts/game/commands/CommandDispatcher.gd index af2eecc..7a637e2 100644 --- a/scripts/game/commands/CommandDispatcher.gd +++ b/scripts/game/commands/CommandDispatcher.gd @@ -14,3 +14,4 @@ signal DISPLAY_COMMAND_PROMPT signal DISPLAY_CLEAR signal LOAD_MAP(currentMap, newMapPath, spawnpoint, facing) +signal LOAD_COMPLETE diff --git a/scripts/game/game_screen.gd b/scripts/game/game_screen.gd index 12081b8..eaaa3d8 100644 --- a/scripts/game/game_screen.gd +++ b/scripts/game/game_screen.gd @@ -5,4 +5,4 @@ class_name GameScreen @export var map:Node func _ready(): - CommandDispatcher.LOAD_MAP.emit(GameManager.startMap, null, Map.Direction.North) + CommandDispatcher.LOAD_MAP.emit(GameManager.currentMap, null, Map.Direction.North) diff --git a/scripts/game/maps/MapContainer.gd b/scripts/game/maps/MapContainer.gd index 2bcfbe3..55a69c0 100644 --- a/scripts/game/maps/MapContainer.gd +++ b/scripts/game/maps/MapContainer.gd @@ -1,6 +1,9 @@ extends Node var map:Map +var loading: bool +var newSpawnpoint +var newFacing func _ready(): CommandDispatcher.LOAD_MAP.connect(loadMap) @@ -8,21 +11,31 @@ func _ready(): func loadMap(newMapPath, spawnpoint, facing): var newMap:Map - + CommandDispatcher.PAUSE_PROCESSOR.emit() + loading = true + if (map != null): map.queue_free() - - map = load(newMapPath).instantiate() - - add_child(map) - - map.get_node("Entities").add_child(map.spawnPlayerAtPosition(spawnpoint, facing)) - + GameManager.currentMap = newMapPath - CommandDispatcher.WAIT_FOR_COMMAND.emit() + ResourceLoader.load_threaded_request(GameManager.currentMap) + + newSpawnpoint = spawnpoint + newFacing = facing + + + #map = load(newMapPath).instantiate() + # + #add_child(map) + # + #map.get_node("Entities").add_child(map.spawnPlayerAtPosition(spawnpoint, facing)) + # + #GameManager.currentMap = newMapPath + # + #CommandDispatcher.WAIT_FOR_COMMAND.emit() func _unhandled_key_input(event): @@ -42,3 +55,18 @@ func _unhandled_key_input(event): if (direction != null): CommandDispatcher.PROCESS_COMMAND.emit(MoveCommand.new(direction)) + + +func _process(delta: float) -> void: + if(loading): + if(ResourceLoader.load_threaded_get_status(GameManager.currentMap) == ResourceLoader.THREAD_LOAD_LOADED): + loading = false + + map = ResourceLoader.load_threaded_get(GameManager.currentMap).instantiate() + + call_deferred("add_child", map) + + map.spawnPlayerAtPosition(newSpawnpoint, newSpawnpoint) + + CommandDispatcher.LOAD_COMPLETE.emit() + CommandDispatcher.WAIT_FOR_COMMAND.emit() diff --git a/scripts/game/maps/entities/Player.gd b/scripts/game/maps/entities/Player.gd index 442531e..dd70e43 100644 --- a/scripts/game/maps/entities/Player.gd +++ b/scripts/game/maps/entities/Player.gd @@ -1 +1,5 @@ extends Mob + +class_name Player + +@export var camera:Camera2D diff --git a/scripts/ui/LoadingPanel.gd b/scripts/ui/LoadingPanel.gd new file mode 100644 index 0000000..c7ec240 --- /dev/null +++ b/scripts/ui/LoadingPanel.gd @@ -0,0 +1,22 @@ +extends MarginContainer + +class_name LoadingPanel + +@export var player:Player + +func _ready() -> void: + CommandDispatcher.LOAD_MAP.connect(onLoadMap) + CommandDispatcher.LOAD_COMPLETE.connect(onMapLoaded) + + player.camera.enabled = false + player.animator.sprite_frames.set_animation_loop("Walk Down", true) + +func onLoadMap(map, spawnpoint, facing): + player.animator.play("Walk down") + show() + + +func onMapLoaded(): + player.animator.stop() + hide() + diff --git a/scripts/ui/LoadingPanel.gd.uid b/scripts/ui/LoadingPanel.gd.uid new file mode 100644 index 0000000..8f1e56e --- /dev/null +++ b/scripts/ui/LoadingPanel.gd.uid @@ -0,0 +1 @@ +uid://ba05sgen1geyk