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 @onready var ammunition_label: Label = $Contents/Ammunition/Count @onready var craft_button: Button = $Contents/Ammunition/CraftButton var _inventory: ShipInventory var _drawer_open := false var _slide_tween: Tween var _missile_button: Button var drawer_width := 780.0 func _ready() -> void: close_button.pressed.connect(close_drawer) craft_button.pressed.connect(_craft_ammunition) craft_button.text = "TWÓRZ +%d AMUNICJI (%.0f części)" % [ShipInventory.AMMUNITION_CRAFT_AMOUNT, ShipInventory.AMMUNITION_CRAFT_PARTS_COST] var missile_row := HBoxContainer.new() $Contents.add_child(missile_row) $Contents.move_child(missile_row, $Contents/CargoGrid.get_index()) _missile_button = Button.new() _missile_button.text = "TWÓRZ +1 RAKIETĘ (%.0f części)" % ShipInventory.MISSILE_CRAFT_PARTS_COST _missile_button.tooltip_text = "Amunicja do obu typów wyrzutni rakiet. Wyrzutnie zdobywasz jako loot." _missile_button.add_theme_font_size_override("font_size", 11) _missile_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL _missile_button.pressed.connect(func() -> void: _inventory.craft_missile()) missile_row.add_child(_missile_button) _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.set("slot_kind", "cargo") slot.set("slot_index", index) cargo_grid.add_child(slot) _refresh_title() func _refresh_title() -> void: craft_button.disabled = _inventory == null or not _inventory.can_craft_ammunition() _missile_button.disabled = _inventory == null or not _inventory.can_craft_missile() if _inventory: title_label.text = "MAGAZYN (%d/%d) · Części: %.1f" % [_inventory.get_cargo_used(), CARGO_SIZE, GameState.captain.parts] ammunition_label.text = "AMUNICJA: %d · RAKIETY: %d" % [_inventory.ammunition, _inventory.get_missile_count()] func _craft_ammunition() -> void: if _inventory: _inventory.craft_ammunition() func toggle_drawer() -> void: _set_drawer_open(not _drawer_open) func close_drawer(immediately: bool = false) -> void: if immediately: if _slide_tween != null and _slide_tween.is_running(): _slide_tween.kill() _drawer_open = false position.x = drawer_width hide() return _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 if value and not visible: position = Vector2(drawer_width, 0) show() _slide_tween = create_tween() _slide_tween.tween_property(self, "position:x", 0.0 if value else drawer_width, 0.25).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT if value else Tween.EASE_IN) if not value: _slide_tween.tween_callback(hide)