From 50ee75e997f65a291b038f9d777d97955f5af42e Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 8 May 2025 22:18:05 -0500 Subject: [PATCH] Overworld map loading --- project.godot | 1 + scenes/Overworld.tscn | 5 ++--- scenes/Singletons/Load.tscn | 3 +++ scenes/UI/DebugMenu.tscn | 4 ++-- scenes/UI/QuestMenu.tscn | 4 ++-- scenes/UI/VNTextbox.tscn | 2 +- scripts/Scene/OverworldScene.gd | 24 ++++++++++++++++++++++++ scripts/Singleton/Load.gd | 1 + scripts/Singleton/Load.gd.uid | 1 + scripts/Singleton/Overworld.gd | 13 ++++++++----- scripts/UI/DebugMenu.gd | 8 ++++++++ scripts/UI/QuestMenu.gd | 5 +++++ ui/UI Theme.tres | 22 ++++++++++++++-------- 13 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 scenes/Singletons/Load.tscn create mode 100644 scripts/Singleton/Load.gd create mode 100644 scripts/Singleton/Load.gd.uid diff --git a/project.godot b/project.godot index 2c246dc..813bff6 100644 --- a/project.godot +++ b/project.godot @@ -26,6 +26,7 @@ QUEST="*res://scenes/Singletons/Quest.tscn" SCENE_MANAGER="*res://scripts/Singleton/SceneManager.gd" UI="*res://scenes/Singletons/UI.tscn" VN="*res://scripts/Singleton/VN.gd" +LOAD="*res://scenes/Singletons/Load.tscn" [display] diff --git a/scenes/Overworld.tscn b/scenes/Overworld.tscn index ebfec14..96e6786 100644 --- a/scenes/Overworld.tscn +++ b/scenes/Overworld.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://tmbx2kit0jyq"] +[gd_scene load_steps=2 format=3 uid="uid://tmbx2kit0jyq"] [ext_resource type="Script" uid="uid://pcncoc6wum4q" path="res://scripts/Scene/OverworldScene.gd" id="1_rfscu"] -[ext_resource type="PackedScene" uid="uid://dx6fv8n4jl5ku" path="res://scenes/Maps/TestMap/TestMap.tscn" id="2_puia7"] [node name="Overworld" type="Node3D"] script = ExtResource("1_rfscu") -[node name="Some-map" parent="." instance=ExtResource("2_puia7")] +[node name="Map" type="Node3D" parent="."] diff --git a/scenes/Singletons/Load.tscn b/scenes/Singletons/Load.tscn new file mode 100644 index 0000000..17795a8 --- /dev/null +++ b/scenes/Singletons/Load.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://dr2o6ymwbwxm1"] + +[node name="Load" type="Node"] diff --git a/scenes/UI/DebugMenu.tscn b/scenes/UI/DebugMenu.tscn index 9e41dea..18b19ce 100644 --- a/scenes/UI/DebugMenu.tscn +++ b/scenes/UI/DebugMenu.tscn @@ -11,11 +11,10 @@ script = ExtResource("1_pcsq6") [node name="MainMenu" type="Button" parent="."] layout_mode = 2 -text = "Prototype Main Menub" +text = "Prototype Main Menu" [node name="OverworldOption" type="HBoxContainer" parent="."] layout_mode = 2 -size_flags_horizontal = 0 size_flags_vertical = 0 [node name="Overworld" type="Button" parent="OverworldOption"] @@ -24,6 +23,7 @@ text = "Prototype Overworld" [node name="MapDropdown" type="OptionButton" parent="OverworldOption"] layout_mode = 2 +size_flags_horizontal = 3 [node name="Quests" type="Button" parent="."] layout_mode = 2 diff --git a/scenes/UI/QuestMenu.tscn b/scenes/UI/QuestMenu.tscn index f345032..0f227d9 100644 --- a/scenes/UI/QuestMenu.tscn +++ b/scenes/UI/QuestMenu.tscn @@ -41,7 +41,7 @@ layout_mode = 2 size_flags_vertical = 3 [node name="QuestList" type="ItemList" parent="VBoxContainer/HBoxContainer"] -custom_minimum_size = Vector2(250, 0) +custom_minimum_size = Vector2(100, 0) layout_mode = 2 size_flags_horizontal = 0 size_flags_vertical = 3 @@ -70,7 +70,7 @@ layout_mode = 2 size_flags_vertical = 3 [node name="QuestObjectiveList" type="ItemList" parent="VBoxContainer/HBoxContainer/Control/VBoxContainer/HBoxContainer"] -custom_minimum_size = Vector2(150, 0) +custom_minimum_size = Vector2(110, 0) layout_mode = 2 item_count = 2 item_0/text = "Quest Objective 1" diff --git a/scenes/UI/VNTextbox.tscn b/scenes/UI/VNTextbox.tscn index 7580bf7..dcfa7de 100644 --- a/scenes/UI/VNTextbox.tscn +++ b/scenes/UI/VNTextbox.tscn @@ -8,7 +8,7 @@ anchors_preset = 12 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_top = -140.0 +offset_top = -60.0 grow_horizontal = 2 grow_vertical = 0 theme = ExtResource("1_wx4lp") diff --git a/scripts/Scene/OverworldScene.gd b/scripts/Scene/OverworldScene.gd index 3352a46..ac1acc4 100644 --- a/scripts/Scene/OverworldScene.gd +++ b/scripts/Scene/OverworldScene.gd @@ -1 +1,25 @@ class_name OverworldScene extends Node3D + +func _ready() -> void: + _updateMap() + + OVERWORLD.mapChanged.connect(_onMapChanged) + +func _exit_tree() -> void: + OVERWORLD.mapChanged.disconnect(_onMapChanged) + +func _updateMap() -> void: + # Remove all children + for child in $Map.get_children(): + child.queue_free() + $Map.remove_child(child) + + # Load the new map + if not OVERWORLD.MAPS.has(OVERWORLD.currentMap): + return + var map = load(OVERWORLD.MAPS[OVERWORLD.currentMap]) + var mapInstance = map.instantiate() + $Map.add_child(mapInstance) + +func _onMapChanged(mapHandle:String, mapScene:String) -> void: + _updateMap() diff --git a/scripts/Singleton/Load.gd b/scripts/Singleton/Load.gd new file mode 100644 index 0000000..8243788 --- /dev/null +++ b/scripts/Singleton/Load.gd @@ -0,0 +1 @@ +class_name LoadManager extends Node \ No newline at end of file diff --git a/scripts/Singleton/Load.gd.uid b/scripts/Singleton/Load.gd.uid new file mode 100644 index 0000000..3324715 --- /dev/null +++ b/scripts/Singleton/Load.gd.uid @@ -0,0 +1 @@ +uid://whqkvjhckgb0 diff --git a/scripts/Singleton/Overworld.gd b/scripts/Singleton/Overworld.gd index 97c8e13..fdd8300 100644 --- a/scripts/Singleton/Overworld.gd +++ b/scripts/Singleton/Overworld.gd @@ -1,13 +1,16 @@ extends Node const MAPS:Dictionary[String, String] = { - "TestMap": "res://scenes/Maps/TestMap.tscn" + "TestMap": "res://scenes/Maps/TestMap/TestMap.tscn" }; var currentMap:String = ""; +signal mapChanged(mapHandle:String, mapScene:String); + func setMap(map:String) -> void: - if MAPS.has(map): - currentMap = map - else: - push_error("Map not found: " + map) \ No newline at end of file + assert(MAPS.has(map), "Map not found: " + map) + if currentMap == map: + return + currentMap = map + mapChanged.emit(map, MAPS[map]) \ No newline at end of file diff --git a/scripts/UI/DebugMenu.gd b/scripts/UI/DebugMenu.gd index 0724240..ab0e4b5 100644 --- a/scripts/UI/DebugMenu.gd +++ b/scripts/UI/DebugMenu.gd @@ -16,6 +16,14 @@ func _ready() -> void: $OverworldOption/MapDropdown.add_item(map, i); i = i + 1; +func _exit_tree() -> void: + $MainMenu.disconnect("pressed", _on_MainMenu_pressed); + $OverworldOption/Overworld.disconnect("pressed", _on_Overworld_pressed); + $Quests.disconnect("pressed", _on_Quests_pressed); + $Cutscene.disconnect("pressed", _on_Custscene_pressed); + $Cooking.disconnect("pressed", _on_Cooking_pressed); + $Battle.disconnect("pressed", _on_Battle_pressed); + func _process(delta: float) -> void: if Input.is_action_just_pressed("debug"): print("Debug key pressed") diff --git a/scripts/UI/QuestMenu.gd b/scripts/UI/QuestMenu.gd index 1e648f2..834f1b3 100644 --- a/scripts/UI/QuestMenu.gd +++ b/scripts/UI/QuestMenu.gd @@ -23,6 +23,11 @@ func _ready() -> void: questObjectiveList.item_selected.connect(_onQuestObjectiveSelected) QUEST.questUpdated.connect(_onQuestUpdated) +func _exit_tree() -> void: + questList.item_selected.disconnect(_onQuestSelected) + closeButton.pressed.disconnect(_onCloseClicked) + questObjectiveList.item_selected.disconnect(_onQuestObjectiveSelected) + QUEST.questUpdated.disconnect(_onQuestUpdated) func setQuest(questKey = null): if questKey == null || questKey == -1: diff --git a/ui/UI Theme.tres b/ui/UI Theme.tres index 7eb6d49..05c67a9 100644 --- a/ui/UI Theme.tres +++ b/ui/UI Theme.tres @@ -1,19 +1,25 @@ [gd_resource type="Theme" load_steps=2 format=3 uid="uid://dm7ee4aqjr2dl"] [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_linbi"] -texture_margin_left = 14.0 -texture_margin_top = 14.0 -texture_margin_right = 14.0 -texture_margin_bottom = 14.0 +texture_margin_left = 2.0 +texture_margin_top = 2.0 +texture_margin_right = 2.0 +texture_margin_bottom = 2.0 axis_stretch_horizontal = 1 axis_stretch_vertical = 1 [resource] Button/font_sizes/font_size = 12 +ItemList/font_sizes/font_size = 12 Label/constants/shadow_offset_y = 1 Label/font_sizes/font_size = 12 -MarginContainer/constants/margin_bottom = 8 -MarginContainer/constants/margin_left = 8 -MarginContainer/constants/margin_right = 8 -MarginContainer/constants/margin_top = 8 +MarginContainer/constants/margin_bottom = 2 +MarginContainer/constants/margin_left = 2 +MarginContainer/constants/margin_right = 2 +MarginContainer/constants/margin_top = 2 PanelContainer/styles/panel = SubResource("StyleBoxTexture_linbi") +RichTextLabel/font_sizes/bold_font_size = 12 +RichTextLabel/font_sizes/bold_italics_font_size = 12 +RichTextLabel/font_sizes/italics_font_size = 12 +RichTextLabel/font_sizes/mono_font_size = 12 +RichTextLabel/font_sizes/normal_font_size = 12