Files
Corupture/scripts/gui.gd
Eric 84de7fa6f1 #2 Collects resources
#8 Generates resources based on resource data
#10 Shows total resources and adjusts for new resources
2024-02-07 09:24:56 -06:00

38 lines
1.3 KiB
GDScript

extends Control
@onready var resource_container: GridContainer = $ResourceContainer/VBoxContainer/GridContainer
const SCIFI_TILESHEET = preload("res://assets/scifi_tilesheet@2.png")
var _resource_displays := {}
func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> void:
for resource: GameResource in changed.changed_resources.keys():
if not _resource_displays.has(resource):
var atlas_tex := AtlasTexture.new()
atlas_tex.atlas = SCIFI_TILESHEET
atlas_tex.region = Rect2(128 * resource.atlas_location.x, 128 * resource.atlas_location.y, 128, 128)
var img := TextureRect.new()
img.texture = atlas_tex
img.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
resource_container.add_child(img)
var label = Label.new()
label.text = str(changed.changed_resources[resource])
resource_container.add_child(label)
var data = ResourceData.new()
data.image = img
data.label = label
data.value = changed.changed_resources[resource]
_resource_displays[resource] = data
else:
var data: ResourceData = _resource_displays[resource]
data.value += changed.changed_resources[resource]
data.label.text = str(data.value)
class ResourceData:
var image: TextureRect
var label: Label
var value: int