Randoloot/scripts/planets/laboratory_panel.gd
2026-10-31 16:08:17 +01:00

58 lines
2.4 KiB
GDScript

extends VBoxContainer
const LAB := preload("res://scripts/planets/laboratory.gd")
const MENU := preload("res://scripts/planets/freighter_menu.gd")
var captain: Resource
var _signature := ""
var _buttons: Dictionary = {}
func _ready() -> void:
LAB.ensure_offers(captain.expedition)
_build()
func _state() -> String:
return str(captain.expedition.laboratory_unlocks)+str(captain.expedition.laboratory_offers)
func _process(_delta: float) -> void:
if _signature != _state(): _build()
for id in _buttons:
if is_instance_valid(_buttons[id]): _buttons[id].disabled = not LAB.can_start(captain,id)
func _build() -> void:
LAB.ensure_offers(captain.expedition)
for child in get_children():
remove_child(child)
child.queue_free()
_buttons.clear()
_signature = _state()
var progress: Resource = captain.expedition
MENU.label(self,"PROJEKTY BRONI I ROZSZERZEŃ",15,MENU.GOLD)
MENU.label(self,"Odkryj projekt za surowce — od razu trafi do puli łupów.",12,MENU.MUTED)
for id in progress.laboratory_offers:
var item := LAB.definition(id)
var card := MENU.card(self)
var row := MENU.row(card)
MENU.icon(row,item.icon,64)
MENU.label(row,item.display_name,15,MENU.GOLD).size_flags_horizontal = Control.SIZE_EXPAND_FILL
MENU.label(card,item.description,12)
var names := preload("res://scripts/items/crafting_recipes.gd").NAMES.duplicate()
names.merge(preload("res://scripts/planets/planet_profiles.gd").MATERIAL_NAMES)
var costs: Array[String] = []
for key in LAB.COSTS[id]: costs.append("%s: %d / %d" % [names[key],int(captain.minerals.get(key,0)),int(LAB.COSTS[id][key])])
MENU.label(card,"KOSZT · posiadasz / wymagane\n"+" · ".join(costs),12,MENU.MUTED)
var button := MENU.button(card,"ODKRYJ PROJEKT",_start.bind(id),true)
button.name = "Research_"+id
button.disabled = not LAB.can_start(captain,id)
_buttons[id] = button
if progress.laboratory_offers.is_empty(): MENU.label(self,"Wszystkie dostępne projekty zostały wynalezione.",14,MENU.GOLD)
if not progress.laboratory_unlocks.is_empty():
MENU.label(self,"ODKRYTE · DOSTĘPNE W ŁUPACH",13,MENU.GOLD)
for id in LAB.IDS:
if not progress.laboratory_unlocks.get(id,false): continue
var item := LAB.definition(id)
var row := MENU.row(self)
MENU.icon(row,item.icon,32)
MENU.label(row,item.display_name,13).size_flags_horizontal = Control.SIZE_EXPAND_FILL
func _start(id: String) -> void:
if LAB.start(captain,id): _build()