From f251423f62dff3bf6addda4052784a1a16fd2f18 Mon Sep 17 00:00:00 2001 From: Rijad Zuzo Date: Fri, 19 Jun 2026 12:08:48 +0200 Subject: [PATCH] feat: add ui labels to display village state --- main.tscn | 23 ++++++++++++++++++++++- world/ui/ui.gd | 35 +++++++++++++++++++++++++++++++++++ world/ui/ui.gd.uid | 1 + 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 world/ui/ui.gd create mode 100644 world/ui/ui.gd.uid diff --git a/main.tscn b/main.tscn index a665fb1..256d08c 100644 --- a/main.tscn +++ b/main.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=14 format=3 uid="uid://rs3hv73svbpa"] +[gd_scene load_steps=15 format=3 uid="uid://rs3hv73svbpa"] [ext_resource type="Script" uid="uid://4mg67crlim53" path="res://player/player.gd" id="1_h2yge"] [ext_resource type="Script" uid="uid://ii8ai801jur2" path="res://player/camera_rig.gd" id="2_1bvp3"] [ext_resource type="Script" uid="uid://dbb25ttlyogqr" path="res://simulation/SimulationManager.gd" id="3_lquwl"] [ext_resource type="Script" uid="uid://c1f3b26n4yntf" path="res://world/world_view_manager.gd" id="4_1bvp3"] [ext_resource type="PackedScene" uid="uid://dhxxyprqflotq" path="res://player/npc/NpcVisual.tscn" id="5_lquwl"] +[ext_resource type="Script" uid="uid://cjvbgqx8rao0t" path="res://world/ui/ui.gd" id="6_7mycd"] [sub_resource type="NavigationMesh" id="NavigationMesh_lquwl"] vertices = PackedVector3Array(-14.5, 0.5, 0, -1, 0.5, 0, -1, 0.5, -0.75, 0, 0.5, -1, 0, 0.5, -14.5, -14.5, 0.5, -14.5, 0.75, 0.5, -1, 0.75, 0.75, -0.5, 14.5, 0.5, -0.5, 14.5, 0.5, -14.5, 0.75, 0.75, 0, 0, 1, 0, 0, 0.75, 0.75, -0.5, 0.75, 0.75, -0.5, 0.5, 14.5, 14.5, 0.5, 14.5, -1, 0.5, 0.75, -14.5, 0.5, 14.5) @@ -126,3 +127,23 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 0, 5) [node name="FoodZone" type="Marker3D" parent="TaskZone"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -8) + +[node name="UI" type="CanvasLayer" parent="." node_paths=PackedStringArray("simulation_manager")] +script = ExtResource("6_7mycd") +simulation_manager = NodePath("../SimulationManager") + +[node name="VillagePanel" type="PanelContainer" parent="UI"] +offset_left = 20.0 +offset_top = 20.0 +offset_right = 280.0 +offset_bottom = 140.0 + +[node name="MarginContainer" type="MarginContainer" parent="UI/VillagePanel"] +layout_mode = 2 +theme_override_constants/margin_left = 12 +theme_override_constants/margin_top = 12 +theme_override_constants/margin_right = 12 +theme_override_constants/margin_bottom = 12 + +[node name="VillageStatsLabel" type="Label" parent="UI/VillagePanel/MarginContainer"] +layout_mode = 2 diff --git a/world/ui/ui.gd b/world/ui/ui.gd new file mode 100644 index 0000000..8659ba1 --- /dev/null +++ b/world/ui/ui.gd @@ -0,0 +1,35 @@ +extends CanvasLayer + +const DEBUG_LOGS := false + +@export var simulation_manager: Node + +@onready var village_stats_label: Label = $VillagePanel/MarginContainer/VillageStatsLabel + +func _ready() -> void: + if simulation_manager == null: + push_error("VillageUI: simulation_manager missing") + return + + if simulation_manager.has_signal("village_changed"): + simulation_manager.village_changed.connect(_on_village_changed) + else: + push_error("VillageUI: SimulationManager has no village_changed signal") + + if "village" in simulation_manager: + _on_village_changed(simulation_manager.village) + +func _on_village_changed(village: SimVillage) -> void: + village_stats_label.text = """ +Village + +Food: %s +Wood: %s +Safety: %s +Knowledge: %s +""" % [ + round(village.food), + round(village.wood), + round(village.safety), + round(village.knowledge) + ] diff --git a/world/ui/ui.gd.uid b/world/ui/ui.gd.uid new file mode 100644 index 0000000..aaf00cc --- /dev/null +++ b/world/ui/ui.gd.uid @@ -0,0 +1 @@ +uid://cjvbgqx8rao0t