extends PanelContainer const SLOT_SCENE := preload("res://scenes/ui/inventory_slot_view.tscn") const CARGO_SIZE := 20 @onready var cargo_grid: GridContainer = $Contents/CargoGrid @onready var close_button: Button = $Contents/Header/CloseButton @onready var title_label: Label = $Contents/Header/Title var _inventory: ShipInventory var _drawer_open := false var _slide_tween: Tween var _resource_cards: Dictionary = {} var _planet_resources: Label var drawer_width := 560.0 func _ready() -> void: close_button.pressed.connect(close_drawer) preload("res://scripts/ui/hud_button_style.gd").apply(close_button, Color("91dbea")) close_button.add_theme_font_size_override("font_size", 10) _create_resource_section() _inventory = get_tree().get_first_node_in_group("ship_inventory") as ShipInventory if _inventory: _inventory.inventory_changed.connect(_refresh_title) _inventory.ammunition_changed.connect(_refresh_title) GameState.captain.changed.connect(_refresh_title) for index in CARGO_SIZE: var slot := SLOT_SCENE.instantiate() slot.name = "Cargo%d" % (index + 1) slot.set("slot_kind", "cargo") slot.set("slot_index", index) cargo_grid.add_child(slot) _refresh_title() func _refresh_title() -> void: if is_instance_valid(_planet_resources): var stock := {} for key in preload("res://scripts/planets/planet_profiles.gd").MATERIALS: stock[key] = GameState.captain.minerals.get(key,0) _planet_resources.text = "Z PLANET: " + preload("res://scripts/planets/expedition_ui.gd").material_text(stock) for key in ["iron", "titanium", "aluminium", "uranium", "sulfur"]: _resource_cards[key].set_amount(float(GameState.captain.minerals.get(key, 0))) _resource_cards["parts"].set_amount(GameState.captain.parts) if _inventory: title_label.text = "MAGAZYN · %d / %d" % [_inventory.get_cargo_used(), _inventory.get_cargo_capacity()] _resource_cards["ammunition"].set_amount(_inventory.ammunition) _resource_cards["irradiated_ammunition"].set_amount(_inventory.irradiated_ammunition) _resource_cards["missile"].set_amount(_inventory.get_missile_count()) _resource_cards["energy_bank"].set_amount(_inventory.get_energy_bank_count()) func _create_resource_section() -> void: var frame := PanelContainer.new() frame.name = "ResourceSection" var style := StyleBoxFlat.new() style.bg_color = Color("101e2d47") style.border_color = Color("2d4c60") style.set_border_width_all(1) style.set_corner_radius_all(5) style.set_content_margin_all(8) frame.add_theme_stylebox_override("panel", style) $Contents.add_child(frame) $Contents.move_child(frame, cargo_grid.get_index()) var section := VBoxContainer.new() section.name = "Resources" section.add_theme_constant_override("separation", 6) frame.add_child(section) var minerals := _resource_row(section, "SUROWCE", Color("d4b58a")) for data in [ ["iron", "Żelazo", "Surowiec pozyskiwany z asteroid.", Color("c5b5a0")], ["titanium", "Tytan", "Surowiec pozyskiwany z asteroid.", Color("9ecbe9")], ["aluminium", "Aluminium", "Surowiec pozyskiwany z asteroid.", Color("dce8ef")], ["uranium", "Uran", "Surowiec z asteroid. Do produkcji napromieniowanej amunicji.", Color("a9ef83")], ["sulfur", "Siarka", "Surowiec z asteroid. Do produkcji amunicji i rakiet.", Color("f4d466")], ]: _add_resource_card(minerals, data) var ammunition := _resource_row(section, "ZAPASY", Color("91dbea")) for data in [ ["parts", "Części", "Wytwarzane z minerałów, odzyskiwane z przedmiotów i wraków. Do napraw.", Color("efb568")], ["ammunition", "Zwykła amunicja", "Pociski do działka maszynowego. Obrażenia kinetyczne.", Color("efb568")], ["irradiated_ammunition", "Napromieniowana amunicja", "Kapsuły do działka gamma. Obrażenia radiacyjne.", Color("a9ef83")], ["energy_bank", "Powerbanki", "Przywracają 10% maksymalnej energii. Użyj klawiszem R.", Color("70f5df")], ["missile", "Rakiety", "Amunicja do wyrzutni rakiet. Obrażenia kinetyczne.", Color("ffac8b")], ]: _add_resource_card(ammunition, data) _planet_resources = Label.new() _planet_resources.custom_minimum_size.x = 440 _planet_resources.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART _planet_resources.add_theme_font_size_override("font_size",10) _planet_resources.add_theme_color_override("font_color",Color("a5c8c6")) section.add_child(_planet_resources) var cargo_title := Label.new() cargo_title.text = "PRZEDMIOTY" cargo_title.add_theme_font_size_override("font_size", 10) cargo_title.add_theme_color_override("font_color", Color("91dbea")) $Contents.add_child(cargo_title) $Contents.move_child(cargo_title, cargo_grid.get_index()) func _resource_row(section: VBoxContainer, caption: String, color: Color) -> HBoxContainer: var title := Label.new() title.text = caption title.add_theme_font_size_override("font_size", 10) title.add_theme_color_override("font_color", color) section.add_child(title) var row := HBoxContainer.new() row.add_theme_constant_override("separation", 5) section.add_child(row) return row func _add_resource_card(row: HBoxContainer, data: Array) -> void: var card := PanelContainer.new() card.set_script(preload("res://scripts/ui/inventory_resource_card.gd")) card.name = str(data[0]).to_pascal_case() card.set("resource_name", data[1]) card.set("description", data[2]) card.set("accent", data[3]) card.set("icon_texture", preload("res://scripts/items/crafting_recipes.gd").icon(data[0])) row.add_child(card) _resource_cards[data[0]] = card func toggle_drawer() -> void: _set_drawer_open(not _drawer_open) func close_drawer(_immediately: bool = false) -> void: _set_drawer_open(false) func _set_drawer_open(value: bool) -> void: if _slide_tween != null and _slide_tween.is_running(): _slide_tween.kill() _drawer_open = value GameState.hud_panel_state["inventory_open"] = value position = Vector2.ZERO visible = value if value: var manager := get_parent().get_parent().get_node_or_null("FloatingWindows") if manager != null: manager.call("focus_window", get_parent())