extends PanelContainer const RECIPES := preload("res://scripts/items/crafting_recipes.gd") @export var standalone := false var _inventory: ShipInventory var _resource_cards: Dictionary = {} var _recipe_buttons: Dictionary = {} var _status: Label func _ready() -> void: add_theme_stylebox_override("panel", StyleBoxEmpty.new()) _inventory = get_tree().get_first_node_in_group("ship_inventory") as ShipInventory var contents := VBoxContainer.new() contents.add_theme_constant_override("separation", 14) add_child(contents) contents.add_child(_heading("SUROWCE Z ASTEROID", Color("8faabc"))) var minerals := HBoxContainer.new() minerals.name = "Minerals" minerals.add_theme_constant_override("separation", 10) contents.add_child(minerals) for mineral in RECIPES.MINERALS: var card := PanelContainer.new() card.set_script(preload("res://scripts/ui/inventory_resource_card.gd")) card.name = mineral.to_pascal_case() card.set("resource_name", RECIPES.NAMES[mineral]) card.set("description", "Wydobywany z asteroid. Składnik receptur warsztatu.") card.set("accent", RECIPES.COLORS[mineral]) card.set("icon_texture", RECIPES.icon(mineral)) minerals.add_child(card) card.custom_minimum_size = Vector2(120, 52) _resource_cards[mineral] = card contents.add_child(HSeparator.new()) var heading := HBoxContainer.new() contents.add_child(heading) var title := _heading("PRODUKCJA", Color("efc681")) title.size_flags_horizontal = Control.SIZE_EXPAND_FILL heading.add_child(title) heading.add_child(_heading("NAJEDŹ NA IKONĘ, ABY ZOBACZYĆ KOSZT", Color("7893a6"), 9)) var recipes := HBoxContainer.new() recipes.name = "Recipes" recipes.add_theme_constant_override("separation", 10) contents.add_child(recipes) for id in RECIPES.IDS: var button := Button.new() button.set_script(preload("res://scripts/ui/crafting_recipe_button.gd")) button.name = id.to_pascal_case() button.set("recipe_id", id) button.set("inventory", _inventory) recipes.add_child(button) button.pressed.connect(_craft.bind(id)) _recipe_buttons[id] = button _status = _heading("1 KLIKNIĘCIE = 1 RECEPTURA • PRODUKCJA BEZPOŚREDNIO Z MINERAŁÓW", Color("7893a6"), 9) _status.custom_minimum_size.y = 24 contents.add_child(_status) _inventory.inventory_changed.connect(_refresh) _inventory.ammunition_changed.connect(_refresh) GameState.captain.changed.connect(_refresh) _refresh() func _heading(caption: String, color: Color, font_size: int = 11) -> Label: var label := Label.new() label.text = caption label.add_theme_font_size_override("font_size", font_size) label.add_theme_color_override("font_color", color) return label func _craft(id: String) -> void: if _inventory.craft(id): _status.text = "WYTWORZONO: %s ×%d" % [RECIPES.DATA[id]["name"], RECIPES.DATA[id]["amount"]] _status.add_theme_color_override("font_color", Color("85deb1")) else: _status.text = "BRAKUJE SUROWCÓW — NAJEDŹ NA RECEPTURĘ, ABY SPRAWDZIĆ KOSZT" _status.add_theme_color_override("font_color", Color("f08087")) func _refresh() -> void: for mineral in _resource_cards: _resource_cards[mineral].call("set_amount", float(GameState.captain.minerals.get(mineral, 0))) for button in _recipe_buttons.values(): button.call("refresh")