54 lines
1.7 KiB
GDScript
54 lines
1.7 KiB
GDScript
extends CanvasLayer
|
|
|
|
signal research(research: Research)
|
|
|
|
var researches: Array[Research] = []
|
|
var selected_research: Research
|
|
|
|
const GEM_RESEARCH = preload("res://data/research/gem_research.tres")
|
|
|
|
@onready var research_items: ItemList = %ResearchItems
|
|
|
|
@onready var title: Label = %Title
|
|
@onready var description: Label = %Description
|
|
@onready var research_materials: GridContainer = %ResearchMaterials
|
|
@onready var research_buttons_container: HBoxContainer = %ResearchButtonsContainer
|
|
|
|
func _ready() -> void:
|
|
_add_research(GEM_RESEARCH)
|
|
research_items.grab_focus()
|
|
|
|
func _add_research(group: Research) -> void:
|
|
research_items.add_item(group.name, group.atlas_texture)
|
|
researches.append(group)
|
|
|
|
func _on_research_selected(index: int) -> void:
|
|
selected_research = researches[index]
|
|
title.text = selected_research.name
|
|
description.text = selected_research.description
|
|
|
|
for child in research_materials.get_children():
|
|
child.queue_free()
|
|
for res: GameResource in selected_research.cost.keys():
|
|
var image = TextureRect.new()
|
|
var texture = AtlasTexture.new()
|
|
texture.atlas = preload("res://assets/scifi_tilesheet@2.png")
|
|
texture.region = Rect2(64 * res.atlas_location, Vector2(64, 64))
|
|
image.texture = texture
|
|
research_materials.add_child(image)
|
|
var label = Label.new()
|
|
label.text = str(selected_research.cost[res])
|
|
if not ResourceManager.has_amount(res, selected_research.cost[res]):
|
|
label.add_theme_color_override("font_color", Color.RED)
|
|
research_materials.add_child(label)
|
|
|
|
description.show()
|
|
research_materials.show()
|
|
research_buttons_container.show()
|
|
|
|
|
|
func _on_build_button_pressed() -> void:
|
|
if selected_research:
|
|
research.emit(selected_research)
|
|
queue_free()
|