mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
add 'inventory' property to slot ui element
This commit is contained in:
parent
2668b8e17b
commit
4d99508ca1
3 changed files with 10 additions and 3 deletions
|
|
@ -382,7 +382,7 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
||||||
|
|
||||||
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
||||||
if (layout.rightClick) {
|
if (layout.rightClick) {
|
||||||
layout.rightClick(inventoryid, stack);
|
layout.rightClick(inventoryId, stack);
|
||||||
if (layout.updateFunc) {
|
if (layout.updateFunc) {
|
||||||
layout.updateFunc(layout.index, stack);
|
layout.updateFunc(layout.index, stack);
|
||||||
}
|
}
|
||||||
|
|
@ -454,7 +454,7 @@ const std::wstring& SlotView::getTooltip() const {
|
||||||
void SlotView::bind(
|
void SlotView::bind(
|
||||||
int64_t inventoryid, ItemStack& stack, const Content* content
|
int64_t inventoryid, ItemStack& stack, const Content* content
|
||||||
) {
|
) {
|
||||||
this->inventoryid = inventoryid;
|
this->inventoryId = inventoryid;
|
||||||
bound = &stack;
|
bound = &stack;
|
||||||
this->content = content;
|
this->content = content;
|
||||||
}
|
}
|
||||||
|
|
@ -467,6 +467,10 @@ ItemStack& SlotView::getStack() {
|
||||||
return *bound;
|
return *bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t SlotView::getInventoryId() const {
|
||||||
|
return inventoryId;
|
||||||
|
}
|
||||||
|
|
||||||
InventoryView::InventoryView(GUI& gui) : Container(gui, glm::vec2()) {
|
InventoryView::InventoryView(GUI& gui) : Container(gui, glm::vec2()) {
|
||||||
setColor(glm::vec4(0, 0, 0, 0.0f));
|
setColor(glm::vec4(0, 0, 0, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace gui {
|
||||||
SlotLayout layout;
|
SlotLayout layout;
|
||||||
bool highlighted = false;
|
bool highlighted = false;
|
||||||
|
|
||||||
int64_t inventoryid = 0;
|
int64_t inventoryId = 0;
|
||||||
ItemStack* bound = nullptr;
|
ItemStack* bound = nullptr;
|
||||||
|
|
||||||
void performLeftClick(ItemStack& stack, ItemStack& grabbed);
|
void performLeftClick(ItemStack& stack, ItemStack& grabbed);
|
||||||
|
|
@ -105,6 +105,7 @@ namespace gui {
|
||||||
|
|
||||||
ItemStack& getStack();
|
ItemStack& getStack();
|
||||||
const SlotLayout& getLayout() const;
|
const SlotLayout& getLayout() const;
|
||||||
|
int64_t getInventoryId() const;
|
||||||
|
|
||||||
static inline std::string EXCHANGE_SLOT_NAME = "exchange-slot";
|
static inline std::string EXCHANGE_SLOT_NAME = "exchange-slot";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,8 @@ static int p_get_inventory(UINode* node, lua::State* L) {
|
||||||
if (auto inventory = dynamic_cast<InventoryView*>(node)) {
|
if (auto inventory = dynamic_cast<InventoryView*>(node)) {
|
||||||
auto inv = inventory->getInventory();
|
auto inv = inventory->getInventory();
|
||||||
return lua::pushinteger(L, inv ? inv->getId() : 0);
|
return lua::pushinteger(L, inv ? inv->getId() : 0);
|
||||||
|
} else if (auto slot = dynamic_cast<SlotView*>(node)) {
|
||||||
|
return lua::pushinteger(L, slot->getInventoryId());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue