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

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

@export var desc: String
@export var cost: int
@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)
	$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):
		$ColorRect.modulate.a = 0.0
	else:
		$ColorRect.modulate.a = 0.75