summaryrefslogtreecommitdiff
path: root/scripts/ui.gd
blob: e45058106e246ef4e20a5d9df85d6cfe6b80b09a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
extends PanelContainer

@onready var morale : Label = $MarginContainer/HBoxContainer/VBoxContainer/Life
@onready var life : Label = $MarginContainer/HBoxContainer/VBoxContainer/Morale
@onready var options_container : HBoxContainer = $MarginContainer/HBoxContainer/HBoxContainer

var ui_option = preload("res://scenes/ui_option.tscn")

func _ready():
	var player = get_node("../Player")
	player.connect("curr_tile", Callable(self, "_update_options"))

	GameData.connect("morale_changed", Callable(self, "_update_morale"))
	GameData.connect("life_changed", Callable(self, "_update_life"))
	_update_morale()
	_update_life()

func _update_morale() -> void:
	morale.text = "Morale:" + str(GameData.get_morale())

func _update_life() -> void:
	life.text = "Life:" + str(GameData.get_life())

func _update_options(data):
	for i in options_container.get_children():
		i.queue_free()

	if data != null:
		for i in data:
			var option = ui_option.instantiate()
			option.desc = i["desc"]
			option.cost = i["cost"]
			option.is_valid = i["is_valid"]
			option.sprite_atlas = i["sprite_panel"]
			options_container.add_child(option)