Randoloot/scripts/planets/time_engineer_panel.gd
2026-10-20 19:53:03 +02:00

104 lines
5.0 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends RefCounted
const CARD := preload("res://scripts/planets/poi_presentation.gd")
const SERVICE := preload("res://scripts/planets/time_engineer.gd")
const CYAN := Color("9be7ff")
static func build(screen: Control, message: String = "") -> void:
var parent: VBoxContainer = screen._choices
var progress: Resource = screen.progress
var art := TextureRect.new()
art.texture = load("res://assets/planets/props/time_engineer.png")
art.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
art.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
art.custom_minimum_size.y = 125
parent.add_child(art)
CARD.text(parent,"INŻYNIER CHRONALNY",18,CYAN)
CARD.text(parent,"Wybierz przedmiot i konkretny addon. Inżynier ustawi tylko jego wartość na maksimum dla obecnego poziomu przedmiotu.",12)
if not message.is_empty(): CARD.text(parent,message,12,CARD.GOLD)
CARD.text(parent,"Kryształy czasu: %d" % progress.time_crystals,14,CYAN)
CARD.text(parent,"Koszt: 10 kryształów × poziom przedmiotu. Gotowe maksima nie pobierają opłaty.",12)
if not is_instance_valid(screen.flight_ship):
CARD.text(parent,"Brak połączenia z wyposażeniem statku.",12)
_back(parent,screen)
return
var inventory: Node = screen.flight_ship.get_node("ShipInventory")
var items: Array[ItemInstance] = []
var locations: Array[String] = []
for kind in ["weapon","module","extension","cargo"]:
var slots: Array = inventory._get_slots(kind)
for index in slots.size():
var item: ItemInstance = slots[index]
if not inventory.is_slot_unlocked(kind,index) or item == null or item.definition == null or item.additional_modifiers.is_empty() or items.has(item): continue
items.append(item)
locations.append({"weapon":"Broń","module":"Moduł","extension":"Rozszerzenie","cargo":"Ładownia"}[kind])
if items.is_empty():
CARD.text(parent,"Brak przedmiotów z addonami na statku. Zabierz wyposażenie z magazynu fregaty przed lądowaniem.",12,CARD.GOLD)
_back(parent,screen)
return
if not items.has(screen._engineer_item):
screen._engineer_item = items[0]
screen._engineer_addon = 0
CARD.text(parent,"PRZEDMIOT",11,CARD.MUTED)
var choice := _choice(parent,"EngineerItem")
for index in items.size():
var item: ItemInstance = items[index]
choice.add_item("%s · poz. %d · %s" % [item.definition.display_name,item.item_level,locations[index]])
choice.set_item_metadata(index,item)
choice.select(items.find(screen._engineer_item))
choice.item_selected.connect(func(index):
screen._engineer_item = choice.get_item_metadata(index)
screen._engineer_addon = 0
screen._show_poi()
)
var item: ItemInstance = screen._engineer_item
CARD.text(parent,"ADDON DO MAKSYMALIZACJI",11,CARD.MUTED)
var addons := _choice(parent,"EngineerAddon")
var selected := 0
for index in item.additional_modifiers.size():
var modifier: ItemStatModifier = item.additional_modifiers[index]
if modifier == null: continue
var affix := SERVICE.affix_for(item,index)
var suffix := " · brak zakresu" if affix == null else (" · MAX" if not SERVICE.can_maximize(item,index) else "")
addons.add_item(modifier.get_display_text()+suffix)
var option := addons.item_count-1
addons.set_item_metadata(option,index)
if index == screen._engineer_addon: selected = option
if addons.item_count == 0:
CARD.text(parent,"Brak dostępnych addonów.",12)
_back(parent,screen)
return
addons.select(selected)
screen._engineer_addon = int(addons.get_item_metadata(selected))
addons.item_selected.connect(func(index):
screen._engineer_addon = int(addons.get_item_metadata(index))
screen._show_poi()
)
var index: int = screen._engineer_addon
var affix := SERVICE.affix_for(item,index)
if affix != null:
var multiplier := ItemInstance.ENERGY_REGENERATION_BONUS_MULTIPLIER if item.additional_modifiers[index].stat_key == "energy_regeneration" else 1.0
CARD.text(parent,"Obecnie: %.2f %s → maksimum: %.2f %s" % [item.additional_modifiers[index].value*multiplier,affix.unit,SERVICE.maximum(item,index)*multiplier,affix.unit],13,CARD.GOLD)
var cost := SERVICE.cost(item)
var ready := SERVICE.can_maximize(item,index)
var apply := CARD.button(parent,"MAKSYMALIZUJ · %d KRYSZTAŁÓW" % cost,screen._maximize_addon,true)
apply.name = "MaximizeSelectedAddon"
apply.disabled = not ready or progress.time_crystals < cost
if not ready:
CARD.text(parent,"Ten addon ma już maksymalną wartość lub nie posiada zakresu losowania.",12,CARD.MUTED)
elif progress.time_crystals < cost:
CARD.text(parent,"Brakuje %d kryształów czasu." % (cost-progress.time_crystals),12,CARD.GOLD)
_back(parent,screen)
static func _choice(parent: Node, node_name: String) -> OptionButton:
var choice := OptionButton.new()
choice.name = node_name
choice.size_flags_horizontal = Control.SIZE_EXPAND_FILL
choice.fit_to_longest_item = false
choice.add_theme_font_override("font",ThemeDB.fallback_font)
choice.add_theme_font_size_override("font_size",12)
parent.add_child(choice)
return choice
static func _back(parent: Node, screen: Control) -> void:
CARD.button(parent,"Wróć do wyprawy",func(): screen._dialog.hide())