mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +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;
|
action = InteractionAction::PUT;
|
||||||
stack.move(grabbed, indices);
|
stack.move(grabbed, indices);
|
||||||
} else {
|
} 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 (layout.itemSource) {
|
||||||
if (grabbed.isEmpty()) {
|
if (grabbed.isEmpty()) {
|
||||||
action = InteractionAction::TAKE;
|
action = InteractionAction::TAKE;
|
||||||
|
|
@ -379,7 +395,6 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
||||||
grabbed.maximizeCount(*content->getIndices());
|
grabbed.maximizeCount(*content->getIndices());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: refactor to reduce nesting
|
|
||||||
if (grabbed.accepts(stack)) {
|
if (grabbed.accepts(stack)) {
|
||||||
auto& def = indices.items.require(stack.getItemId());
|
auto& def = indices.items.require(stack.getItemId());
|
||||||
if (grabbed.getCount() < def.stackSize) {
|
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) {
|
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
||||||
if (layout.rightClick) {
|
if (layout.rightClick) {
|
||||||
layout.rightClick(inventoryId, stack);
|
layout.rightClick(inventoryId, stack);
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,8 @@ namespace gui {
|
||||||
SHARE = 2,
|
SHARE = 2,
|
||||||
UNDEFINED,
|
UNDEFINED,
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
|
void actIfCannotPut(ItemStack& stack, ItemStack& grabbed, InteractionAction& action);
|
||||||
};
|
};
|
||||||
|
|
||||||
class InventoryView final : public gui::Container {
|
class InventoryView final : public gui::Container {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
#include "items/Inventories.hpp"
|
#include "items/Inventories.hpp"
|
||||||
#include "items/ItemStack.hpp"
|
#include "items/ItemStack.hpp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue