extends PanelContainer @export var slot_kind: String = "cargo" @export var slot_index: int = 0 @onready var slot_label: Label = $SlotLabel var _inventory: ShipInventory func _ready() -> void: _inventory = get_tree().get_first_node_in_group("ship_inventory") as ShipInventory if _inventory: _inventory.inventory_changed.connect(_refresh) match slot_kind: "weapon": custom_minimum_size = Vector2(90, 38) "module": custom_minimum_size = Vector2(72, 44) _: custom_minimum_size = Vector2(72, 48) _refresh() func _refresh() -> void: if not is_node_ready() or not _inventory: return var item: ItemInstance = _inventory.get_item(slot_kind, slot_index) if item == null or item.definition == null: slot_label.text = _empty_slot_text() return var definition := item.definition var category_name := _category_name(definition.category) var value_text := _stat_text(item) var slot_title := category_name if slot_kind == "weapon": var weapon_binding := "LPM" if slot_index == 0 else "PPM" slot_title = "BROŃ %d [%s]" % [slot_index + 1, weapon_binding] elif slot_kind == "module": slot_title = "MODUŁ %d [%d]" % [slot_index + 1, slot_index + 1] slot_label.text = "%s\n%s\n%s" % [slot_title, definition.display_name, value_text] func _get_drag_data(_at_position: Vector2) -> Variant: if not _inventory: return null var item: ItemInstance = _inventory.get_item(slot_kind, slot_index) if item == null: return null var preview := Label.new() preview.text = item.definition.display_name preview.add_theme_color_override("font_color", Color(0.85, 0.94, 1.0)) set_drag_preview(preview) return {"from_kind": slot_kind, "from_index": slot_index} func _can_drop_data(_at_position: Vector2, data: Variant) -> bool: return ( _inventory != null and data is Dictionary and _inventory.can_move_item( str(data.get("from_kind", "")), int(data.get("from_index", -1)), slot_kind, slot_index ) ) func _drop_data(_at_position: Vector2, data: Variant) -> void: _inventory.move_item( str(data.get("from_kind", "")), int(data.get("from_index", -1)), slot_kind, slot_index ) func _empty_slot_text() -> String: if slot_kind == "weapon": var weapon_binding := "LPM" if slot_index == 0 else "PPM" return "BROŃ %d [%s]\nPUSTY" % [slot_index + 1, weapon_binding] if slot_kind == "module": return "MODUŁ %d [%d]\nPUSTY" % [slot_index + 1, slot_index + 1] return "PUSTY" func _category_name(category: int) -> String: match category: ItemDefinition.Category.WEAPON: return "BROŃ" ItemDefinition.Category.SHIELD: return "TARCZA" ItemDefinition.Category.HULL: return "KADŁUB" ItemDefinition.Category.GENERATOR: return "GENERATOR" ItemDefinition.Category.EXTENSION: return "ROZSZERZENIE" return "PRZEDMIOT" func _stat_text(item: ItemInstance) -> String: var definition := item.definition if definition.primary_stat.is_empty(): return "Poz. %d" % item.item_level var total_value := item.get_stat_total(definition.primary_stat) var sign_text := "+" if total_value >= 0.0 else "" return "%s%.0f%s · Poz. %d" % [sign_text, total_value, definition.stat_suffix, item.item_level]