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

@ -189,13 +189,6 @@ function on_inventory_closed(invid: int, playerid: int)
Вызывается при закрытии инвентаря. Вызывается при закрытии инвентаря.
```lua
function on_inventory_interact(invid: int, slot: int, action: int)
```
Вызывается при взаимодействии со слотом игрока.
**action** отвечает за тип взаимодействия (0 - левый клик, 1 - правый клик, 2 - левый клик + шифт)
## События макета ## События макета
@ -237,6 +230,13 @@ function on_hud_close(playerid: int)
Вызывается при выходе из мира, перед его сохранением. Вызывается при выходе из мира, перед его сохранением.
```lua
function on_hud_inventory_interact"(invid: int, slot: int, action: int)
```
Вызывается при взаимодействии со слотом игрока.
**action** отвечает за тип взаимодействия (0 - левый клик, 1 - правый клик, 2 - левый клик + шифт)
## События ECS ## События ECS
События **ECS** описаны [тут](ecs.md#события-компонента) События **ECS** описаны [тут](ecs.md#события-компонента)

View file

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