75 lines
3.3 KiB
GDScript
75 lines
3.3 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 _timer: Label
|
|
var _bar: ProgressBar
|
|
var _buttons: Dictionary = {}
|
|
|
|
func _ready() -> void:
|
|
LAB.ensure_offers(captain.expedition)
|
|
_build()
|
|
|
|
func _state() -> String:
|
|
return str(captain.expedition.laboratory_project)+str(captain.expedition.laboratory_unlocks)+str(captain.get_skill_rank("scientist"))
|
|
|
|
func _process(_delta: float) -> void:
|
|
if _signature != _state(): _build()
|
|
if is_instance_valid(_timer):
|
|
_timer.text = "Pozostało: %d s gry" % ceili(captain.expedition.laboratory_remaining)
|
|
_bar.value = captain.expedition.laboratory_duration-captain.expedition.laboratory_remaining
|
|
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()
|
|
_timer = null
|
|
_buttons.clear()
|
|
_signature = _state()
|
|
var progress: Resource = captain.expedition
|
|
MENU.label(self,"PROJEKTY BRONI I ROZSZERZEŃ",15,MENU.GOLD)
|
|
MENU.label(self,"Wybierz projekt. Nowe badanie trwa %d sekund gry. Odkryta broń lub rozszerzenie zacznie pojawiać się w łupach. Od początku dostępne jest działko plazmowe." % roundi(LAB.research_duration(captain)),12,MENU.MUTED)
|
|
if not progress.laboratory_project.is_empty():
|
|
var item := LAB.definition(progress.laboratory_project)
|
|
var row := MENU.row(self)
|
|
MENU.icon(row,item.icon,64)
|
|
MENU.label(row,item.display_name,16,MENU.GOLD).size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
_timer = MENU.label(self,"",14)
|
|
_bar = ProgressBar.new()
|
|
_bar.max_value = progress.laboratory_duration
|
|
_bar.custom_minimum_size.y = 18
|
|
add_child(_bar)
|
|
else:
|
|
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,"ROZPOCZNIJ BADANIE · %d s" % roundi(LAB.research_duration(captain)),_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()
|