27 lines
878 B
GDScript
27 lines
878 B
GDScript
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
|
|
|
|
func _ready() -> void:
|
|
close_button.pressed.connect(func() -> void: hide())
|
|
_inventory = get_tree().get_first_node_in_group("ship_inventory") as ShipInventory
|
|
if _inventory:
|
|
_inventory.inventory_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:
|
|
if _inventory:
|
|
title_label.text = "MAGAZYN (%d / %d)" % [_inventory.get_cargo_used(), CARGO_SIZE]
|