update InventoryView

This commit is contained in:
Xertis 2026-03-07 00:09:37 +03:00
parent 3d301f13d7
commit f2684edf1f
2 changed files with 26 additions and 16 deletions

View file

@ -350,6 +350,8 @@ bool SlotView::isHighlighted() const {
void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
const auto& input = gui.getInput();
const int action = 0;
if (layout.taking && input.pressed(Keycode::LEFT_SHIFT)) {
if (layout.shareFunc) {
layout.shareFunc(layout.index, stack);
@ -357,6 +359,7 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
scripting::on_inventory_interact(inventoryId, layout.index, action | 2);
return;
}
if (!layout.itemSource && stack.accepts(grabbed) && layout.placing) {
@ -376,17 +379,26 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
std::swap(grabbed, stack);
}
}
scripting::on_inventory_interact(inventoryId, layout.index, action);
}
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
const auto& input = gui.getInput();
const int action = 1;
if (layout.rightClick) {
layout.rightClick(inventoryId, stack);
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
scripting::on_inventory_interact(inventoryId, layout.index, action);
return;
}
if (layout.itemSource) {
scripting::on_inventory_interact(inventoryId, layout.index, action);
return;
}
if (layout.itemSource) return;
if (grabbed.isEmpty()) {
if (!stack.isEmpty() && layout.taking) {
grabbed.set(std::move(stack));
@ -399,10 +411,14 @@ void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
stack = ItemStack(0, 0);
}
}
scripting::on_inventory_interact(inventoryId, layout.index, action);
return;
}
auto& stackDef = content->getIndices()->items.require(stack.getItemId());
if (!layout.placing) {
scripting::on_inventory_interact(inventoryId, layout.index, action);
return;
}
if (stack.isEmpty()) {
@ -419,6 +435,8 @@ void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
stack.setCount(stack.getCount() + 1);
grabbed.setCount(grabbed.getCount() - 1);
}
scripting::on_inventory_interact(inventoryId, layout.index, action);
}
void SlotView::clicked(Mousecode button) {
@ -431,23 +449,15 @@ void SlotView::clicked(Mousecode button) {
ItemStack& grabbed = exchangeSlot->getStack();
ItemStack& stack = *bound;
int action = -1;
if (button == Mousecode::BUTTON_1) {
performLeftClick(stack, grabbed);
action = 0;
} else if (button == Mousecode::BUTTON_2) {
performRightClick(stack, grabbed);
action = 1;
}
if (layout.updateFunc) {
layout.updateFunc(layout.index, stack);
}
const auto& input = gui.getInput();
action = action | (input.pressed(Keycode::LEFT_SHIFT) ? 2 : 0);
scripting::on_inventory_interact(inventoryId, layout.index, action);
}
void SlotView::onFocus() {