extends Control signal next_level_requested signal closed @onready var next_button: Button = $Center/Panel/Contents/NextButton @onready var close_button: Button = $Center/Panel/Contents/CloseButton @onready var buy_ammunition_button: Button = $Center/Panel/Contents/BuyAmmunitionButton @onready var services_label: Label = $Center/Panel/Contents/Services var _inventory: ShipInventory func _ready() -> void: next_button.pressed.connect(func() -> void: next_level_requested.emit()) close_button.pressed.connect(_close) buy_ammunition_button.pressed.connect(_buy_ammunition) _inventory = get_tree().get_first_node_in_group("ship_inventory") as ShipInventory if _inventory: _inventory.ammunition_changed.connect(_refresh_ammunition_service) GameState.captain.changed.connect(_refresh_ammunition_service) _refresh_ammunition_service() func show_services(at_level_cap: bool) -> void: _refresh_ammunition_service() next_button.disabled = at_level_cap next_button.text = "OSIĄGNIĘTO OSTATNI UKŁAD" if at_level_cap else "PRZEJDŹ DO NASTĘPNEGO UKŁADU" show() func _refresh_ammunition_service() -> void: buy_ammunition_button.disabled = _inventory == null or not _inventory.can_buy_ammunition() if _inventory: buy_ammunition_button.text = "KUP %d AMUNICJI — %d KREDYTÓW" % [ShipInventory.AMMUNITION_BUY_AMOUNT, _inventory.get_ammunition_buy_cost()] services_label.text = "Amunicja: %d • Kredyty: %d\nCena: 100 kredytów × poziom układu (%d)" % [_inventory.ammunition, GameState.captain.credits, GameState.system_level] func _buy_ammunition() -> void: if visible and _inventory: _inventory.buy_ammunition() func _close() -> void: hide() closed.emit() func _unhandled_key_input(event: InputEvent) -> void: if visible and event.is_action_pressed("ui_cancel"): _close() get_viewport().set_input_as_handled()