extends Control signal next_level_requested @onready var next_button: Button = $Center/Panel/Contents/NextButton @onready var buy_ammunition_button: Button = $Center/Panel/Contents/BuyAmmunitionButton @onready var reset_skills_button: Button = $Center/Panel/Contents/ResetSkillsButton @onready var services_label: Label = $Center/Panel/Contents/Services @onready var status_label: Label = $Center/Panel/Contents/Status @onready var panel: PanelContainer = $Center/Panel var _inventory: ShipInventory var planet: Node2D var _open_tween: Tween var _missile_button: Button var _gamma_buy: Button func _ready() -> void: get_parent().get_node("FloatingWindows").call("register_window", self, panel, $Center/Panel/Contents/Title) _gamma_buy = Button.new() _gamma_buy.name = "BuyIrradiatedAmmunition" _gamma_buy.custom_minimum_size.y = 36 _gamma_buy.add_theme_font_size_override("font_size", 12) _gamma_buy.focus_mode = Control.FOCUS_NONE $Center/Panel/Contents.add_child(_gamma_buy) _gamma_buy.pressed.connect(func() -> void: _inventory.buy_irradiated_ammunition()) next_button.pressed.connect(func() -> void: next_level_requested.emit()) buy_ammunition_button.pressed.connect(_buy_ammunition) reset_skills_button.hide() _missile_button = Button.new() _missile_button.custom_minimum_size.y = 36 _missile_button.add_theme_font_size_override("font_size", 12) _missile_button.focus_mode = Control.FOCUS_NONE _missile_button.tooltip_text = "Jedna sztuka amunicji rakietowej do dowolnej wyrzutni." _missile_button.pressed.connect(func() -> void: if visible and _inventory: _inventory.buy_missile() ) $Center/Panel/Contents.add_child(_missile_button) $Center/Panel/Contents.move_child(_missile_button, reset_skills_button.get_index()) _inventory = get_tree().get_first_node_in_group("ship_inventory") as ShipInventory if _inventory: _inventory.ammunition_changed.connect(_refresh_ammunition_service) _inventory.inventory_changed.connect(_refresh_ammunition_service) GameState.captain.changed.connect(_refresh_ammunition_service) _refresh_ammunition_service() func show_services(at_level_cap: bool, portal_open: bool = false) -> void: _refresh_ammunition_service() next_button.disabled = at_level_cap or portal_open next_button.text = "OSIĄGNIĘTO OSTATNI UKŁAD" if at_level_cap else ("WORMHOLE OTWARTY" if portal_open else "IDŹ DO NASTĘPNEGO POZIOMU") status_label.text = "Wleć w wormhole, aby przejść dalej." if portal_open else "Układ bezpieczny. Usługi dostępne." if visible: return show() _position_at_planet() scale = Vector2(0.05, 1.0) _open_tween = create_tween() _open_tween.tween_property(self, "scale:x", 1.0, 0.2).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT) func hide_services() -> void: if _open_tween != null and _open_tween.is_running(): _open_tween.kill() hide() scale = Vector2.ONE func _process(_delta: float) -> void: if visible: _position_at_planet() func _position_at_planet() -> void: if has_meta("floating_window_dragged"): get_parent().get_node("FloatingWindows").call("clamp_window", self) return if not is_instance_valid(planet): return var canvas := get_viewport().get_canvas_transform() var planet_screen := canvas * planet.global_position var planet_radius := float(planet.get("radius")) * canvas.x.length() size = panel.get_combined_minimum_size() var viewport_size := get_viewport_rect().size var sidebar := get_parent().get_node_or_null("ShipDrawer") as Control var screen_right := viewport_size.x - (sidebar.size.x + 8.0 if sidebar != null and sidebar.visible else 8.0) var target := planet_screen + Vector2(planet_radius + 24.0, -size.y * 0.5) if target.x + size.x > screen_right: target.x = planet_screen.x - planet_radius - 24.0 - size.x position = Vector2(clampf(target.x, 8.0, maxf(8.0, screen_right - size.x)), clampf(target.y, 8.0, maxf(8.0, viewport_size.y - size.y - 150.0))) func _refresh_ammunition_service() -> void: if _gamma_buy != null: _gamma_buy.text = "KUP 10 NAPROMIENIOWANEJ — %d KREDYTÓW" % (_inventory.get_irradiated_ammunition_buy_cost() if _inventory else 15 * maxi(1, GameState.system_level)) _gamma_buy.disabled = _inventory == null or not _inventory.can_buy_irradiated_ammunition() _missile_button.disabled = _inventory == null or not _inventory.can_buy_missile() _missile_button.text = "KUP +1 RAKIETĘ — %d KREDYTÓW" % (_inventory.get_missile_buy_cost() if _inventory else ShipInventory.MISSILE_BUY_BASE_COST) reset_skills_button.disabled = not GameState.captain.can_reset_skills() reset_skills_button.text = "RESET SKILLI — %d KREDYTÓW" % GameState.captain.get_skill_reset_cost() reset_skills_button.tooltip_text = "Zwraca wszystkie %d wydanych punktów nauki. Koszt: 100 kredytów × poziom kapitana." % GameState.captain.get_spent_learning_points() 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\nRekin biznesu: −%d%% ceny zakupów" % [_inventory.ammunition, GameState.captain.credits, roundi(GameState.captain.get_skill_bonus("business_shark") * 100)] func _buy_ammunition() -> void: if visible and _inventory: _inventory.buy_ammunition() func _reset_skills() -> void: if visible: GameState.captain.reset_skills()