add 'slotIndex' ui slot property

This commit is contained in:
MihailRis 2025-12-10 21:58:08 +03:00
parent 1ef174f204
commit dfa9656871
4 changed files with 23 additions and 3 deletions

View file

@ -452,10 +452,11 @@ const std::wstring& SlotView::getTooltip() const {
}
void SlotView::bind(
int64_t inventoryid, ItemStack& stack, const Content* content
int64_t inventoryid, ItemStack& stack, size_t index, const Content* content
) {
this->inventoryId = inventoryid;
bound = &stack;
this->index = index;
this->content = content;
}
@ -471,6 +472,10 @@ int64_t SlotView::getInventoryId() const {
return inventoryId;
}
size_t SlotView::getIndex() const {
return index;
}
InventoryView::InventoryView(GUI& gui) : Container(gui, glm::vec2()) {
setColor(glm::vec4(0, 0, 0, 0.0f));
}
@ -514,9 +519,11 @@ void InventoryView::bind(
this->inventory = inventory;
this->content = content;
for (auto slot : slots) {
const auto& layout = slot->getLayout();
slot->bind(
inventory->getId(),
inventory->getSlot(slot->getLayout().index),
inventory->getSlot(layout.index),
layout.index,
content
);
}

View file

@ -63,6 +63,7 @@ namespace gui {
int64_t inventoryId = 0;
ItemStack* bound = nullptr;
size_t index = 0;
void performLeftClick(ItemStack& stack, ItemStack& grabbed);
void performRightClick(ItemStack& stack, ItemStack& grabbed);
@ -100,12 +101,14 @@ namespace gui {
void bind(
int64_t inventoryid,
ItemStack& stack,
size_t index,
const Content* content
);
ItemStack& getStack();
const SlotLayout& getLayout() const;
int64_t getInventoryId() const;
size_t getIndex() const;
static inline std::string EXCHANGE_SLOT_NAME = "exchange-slot";
};