init
This commit is contained in:
43
scripts/upgrades_menu.gd
Normal file
43
scripts/upgrades_menu.gd
Normal file
@@ -0,0 +1,43 @@
|
||||
extends Control
|
||||
|
||||
const COST_CONTAINER = preload("res://scenes/cost_container.tscn")
|
||||
|
||||
@onready var upgrades_list = %UpgradesList
|
||||
@onready var upgrade_title_label = %UpgradeTitleLabel
|
||||
@onready var desciption_label = %DesciptionLabel
|
||||
@onready var cost_container = %CostContainer
|
||||
@onready var buy_button = %BuyButton
|
||||
|
||||
var available_upgrades: Array[Upgrade]
|
||||
|
||||
func _ready():
|
||||
upgrade_title_label.text = "<- Select an Upgrade"
|
||||
desciption_label.text = ""
|
||||
for child in cost_container.get_children():
|
||||
cost_container.remove_child(child)
|
||||
buy_button.disabled = true
|
||||
upgrades_list.clear()
|
||||
available_upgrades = DataHandler.get_available_upgrades()
|
||||
for upgd in available_upgrades:
|
||||
upgrades_list.add_item(upgd.name)
|
||||
|
||||
|
||||
func _on_upgrades_list_item_selected(index):
|
||||
var upgd: Upgrade = available_upgrades[index]
|
||||
upgrade_title_label.text = upgd.name
|
||||
desciption_label.text = upgd.description
|
||||
for child in cost_container.get_children():
|
||||
cost_container.remove_child(child)
|
||||
for cost in upgd.cost:
|
||||
var cost_row: CostContainer = COST_CONTAINER.instantiate()
|
||||
cost_container.add_child(cost_row)
|
||||
cost_row.set_data(DataHandler.type_to_texture(cost), upgd.cost[cost])
|
||||
if DataHandler.has_upgrade_cost(upgd):
|
||||
buy_button.disabled = false
|
||||
|
||||
|
||||
func _on_buy_button_pressed():
|
||||
var selected = upgrades_list.get_selected_items()[0]
|
||||
var upgd: Upgrade = available_upgrades[selected]
|
||||
if upgd.activate_upgrade():
|
||||
_ready()
|
||||
Reference in New Issue
Block a user