feat: add ui labels to display village state

This commit is contained in:
Rijad Zuzo
2026-06-19 12:08:48 +02:00
parent d7022b3f27
commit f251423f62
3 changed files with 58 additions and 1 deletions
+22 -1
View File
@@ -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://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://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://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="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="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"] [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) 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"] [node name="FoodZone" type="Marker3D" parent="TaskZone"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -8) 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
+35
View File
@@ -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)
]
+1
View File
@@ -0,0 +1 @@
uid://cjvbgqx8rao0t