summaryrefslogtreecommitdiff
path: root/scripts/ui_panel.gd
blob: e32115c1b812e941a15020a4175270a046f3a72d (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
extends Panel

@onready var util = preload("res://scripts/util.gd")

@export var desc: String
@export var cost: int
@export var is_valid : bool
@export var sprite_atlas : Vector2i

func _ready():
	var texture = util.get_tile_texture(sprite_atlas)
	$HBoxContainer/Texture.texture = texture
	$HBoxContainer/Texture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
	$HBoxContainer/VBoxContainer/Label.text = desc
	$HBoxContainer/VBoxContainer/Label2.text = str(cost) if is_valid else "-"
	$ColorRect.color = get_theme_stylebox("panel").bg_color
	$ColorRect.modulate.a = 0.0

	GameData.connect("life_changed", Callable(self, "_update_affordability"))
	_update_affordability()

func _update_affordability():
	if (GameData.get_life() >= cost && is_valid):
		$ColorRect.modulate.a = 0.0
	else:
		$ColorRect.modulate.a = 0.75