A Minecraft style clone in Godot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

40 lines
1.0 KiB

class_name QuickSlotsSlot
extends Panel
@export var amount_label: Label
@export var slot_texture: TextureRect
var slot_index: int = 0
func _ready() -> void:
InventoryManager.inventory_slot_updated.connect(_on_inventory_slot_updated)
func init(_slot_index: int) -> void:
slot_index = _slot_index
refresh()
func clear() -> void:
slot_texture.texture = null
amount_label.text = ""
slot_texture.tooltip_text = ""
func refresh() -> void:
if InventoryManager.inventory.size() < 1:
return clear()
elif not InventoryManager.inventory.get(slot_index):
return clear()
elif InventoryManager.inventory[slot_index] == null:
return clear()
slot_texture.texture = load(InventoryManager.inventory[slot_index].item_texture)
amount_label.text = "x" + str(InventoryManager.inventory[slot_index].amount)
slot_texture.tooltip_text = InventoryManager.inventory[slot_index].name + "\n" + InventoryManager.inventory[slot_index].description
func _on_inventory_slot_updated(_slot_index: int) -> void:
if _slot_index != slot_index: return
refresh()