mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 23:41:50 +00:00
small refactor
This commit is contained in:
parent
54e90a25fe
commit
e76b5b0dcd
3 changed files with 36 additions and 31 deletions
|
|
@ -371,6 +371,22 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
|||
action = InteractionAction::PUT;
|
||||
stack.move(grabbed, indices);
|
||||
} else {
|
||||
actIfCannotPut(stack, grabbed, action);
|
||||
}
|
||||
|
||||
if (action != InteractionAction::UNDEFINED) {
|
||||
scripting::on_inventory_interact(
|
||||
inventoryId,
|
||||
layout.index,
|
||||
static_cast<int>(action),
|
||||
static_cast<int>(mode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void SlotView::actIfCannotPut(ItemStack& stack, ItemStack& grabbed, InteractionAction& action) {
|
||||
const auto& input = gui.getInput();
|
||||
auto indices = *content->getIndices();
|
||||
if (layout.itemSource) {
|
||||
if (grabbed.isEmpty()) {
|
||||
action = InteractionAction::TAKE;
|
||||
|
|
@ -379,7 +395,6 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
|||
grabbed.maximizeCount(*content->getIndices());
|
||||
}
|
||||
} else {
|
||||
// TODO: refactor to reduce nesting
|
||||
if (grabbed.accepts(stack)) {
|
||||
auto& def = indices.items.require(stack.getItemId());
|
||||
if (grabbed.getCount() < def.stackSize) {
|
||||
|
|
@ -402,16 +417,6 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
|||
}
|
||||
}
|
||||
|
||||
if (action != InteractionAction::UNDEFINED) {
|
||||
scripting::on_inventory_interact(
|
||||
inventoryId,
|
||||
layout.index,
|
||||
static_cast<int>(action),
|
||||
static_cast<int>(mode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
||||
if (layout.rightClick) {
|
||||
layout.rightClick(inventoryId, stack);
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ namespace gui {
|
|||
SHARE = 2,
|
||||
UNDEFINED,
|
||||
};
|
||||
private:
|
||||
void actIfCannotPut(ItemStack& stack, ItemStack& grabbed, InteractionAction& action);
|
||||
};
|
||||
|
||||
class InventoryView final : public gui::Container {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "content/Content.hpp"
|
||||
#include "items/Inventories.hpp"
|
||||
#include "items/ItemStack.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue