Clean up counter script
This commit is contained in:
parent
d994deb90f
commit
2ca7fe9d40
2 changed files with 12 additions and 43 deletions
10
ui/UI.tscn
10
ui/UI.tscn
|
@ -57,7 +57,6 @@ texture = ExtResource("4_7fjj4")
|
|||
expand_mode = 2
|
||||
|
||||
[node name="StoneCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_right = 55.0
|
||||
offset_bottom = 24.0
|
||||
|
@ -66,9 +65,9 @@ text = "000"
|
|||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("2_ei01o")
|
||||
key = "stone"
|
||||
|
||||
[node name="WoodCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 55.0
|
||||
offset_right = 110.0
|
||||
|
@ -78,9 +77,9 @@ text = "000"
|
|||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("2_ei01o")
|
||||
key = "wood"
|
||||
|
||||
[node name="EssenceCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 110.0
|
||||
offset_right = 165.0
|
||||
|
@ -90,6 +89,7 @@ text = "000"
|
|||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("2_ei01o")
|
||||
key = "essence"
|
||||
|
||||
[node name="RightCounters" type="VBoxContainer" parent="HBoxContainer"]
|
||||
layout_direction = 2
|
||||
|
@ -119,7 +119,6 @@ offset_bottom = 24.0
|
|||
expand_mode = 2
|
||||
|
||||
[node name="PopulationCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_right = 55.0
|
||||
offset_bottom = 24.0
|
||||
|
@ -128,9 +127,9 @@ text = "000"
|
|||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("2_ei01o")
|
||||
key = "population"
|
||||
|
||||
[node name="FloodLevelCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 55.0
|
||||
offset_right = 110.0
|
||||
|
@ -140,3 +139,4 @@ text = "000"
|
|||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("2_ei01o")
|
||||
key = "flood_level"
|
||||
|
|
|
@ -1,42 +1,11 @@
|
|||
extends Label
|
||||
|
||||
@onready var stone_count_label: Label = %StoneCountLabel
|
||||
@onready var wood_count_label: Label = %WoodCountLabel
|
||||
@onready var essence_count_label: Label = %EssenceCountLabel
|
||||
@onready var population_count_label: Label = %PopulationCountLabel
|
||||
@onready var flood_level_count_label: Label = %FloodLevelCountLabel
|
||||
@export var key: String
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
var stone_count = 1
|
||||
var wood_count = 2
|
||||
var essence_count = 3
|
||||
var population_count = 4
|
||||
var flood_count = Persister.get_value("flood_level")
|
||||
|
||||
if stone_count:
|
||||
stone_count_label.set_text(str(stone_count))
|
||||
else:
|
||||
stone_count_label.set_text(str(0))
|
||||
|
||||
if wood_count:
|
||||
wood_count_label.set_text(str(wood_count))
|
||||
else:
|
||||
wood_count_label.set_text(str(0))
|
||||
|
||||
if essence_count:
|
||||
essence_count_label.set_text(str(essence_count))
|
||||
else:
|
||||
essence_count_label.set_text(str(0))
|
||||
|
||||
if population_count:
|
||||
population_count_label.set_text(str(population_count))
|
||||
else:
|
||||
population_count_label.set_text(str(0))
|
||||
|
||||
if flood_count:
|
||||
flood_level_count_label.set_text(str(flood_count))
|
||||
else:
|
||||
flood_level_count_label.set_text(str(0))
|
||||
|
||||
func _ready() -> void:
|
||||
Triggerer.listen(key, _on_value_change)
|
||||
|
||||
|
||||
func _on_value_change(data):
|
||||
text = data.value
|
||||
|
|
Loading…
Reference in a new issue