mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
small refactor
This commit is contained in:
parent
54e90a25fe
commit
e76b5b0dcd
3 changed files with 36 additions and 31 deletions
|
|
@ -371,35 +371,7 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
|||
action = InteractionAction::PUT;
|
||||
stack.move(grabbed, indices);
|
||||
} else {
|
||||
if (layout.itemSource) {
|
||||
if (grabbed.isEmpty()) {
|
||||
action = InteractionAction::TAKE;
|
||||
grabbed.set(stack);
|
||||
if (input.pressed(Keycode::LEFT_CONTROL)) {
|
||||
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) {
|
||||
action = InteractionAction::TAKE;
|
||||
grabbed.setCount(grabbed.getCount() + 1);
|
||||
}
|
||||
} else {
|
||||
action = InteractionAction::PUT;
|
||||
grabbed.clear();
|
||||
}
|
||||
}
|
||||
} else if (grabbed.isEmpty()) {
|
||||
if (layout.taking) {
|
||||
action = InteractionAction::TAKE;
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
} else if (layout.taking && layout.placing) {
|
||||
action = InteractionAction::PUT;
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
actIfCannotPut(stack, grabbed, action);
|
||||
}
|
||||
|
||||
if (action != InteractionAction::UNDEFINED) {
|
||||
|
|
@ -412,6 +384,39 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
grabbed.set(stack);
|
||||
if (input.pressed(Keycode::LEFT_CONTROL)) {
|
||||
grabbed.maximizeCount(*content->getIndices());
|
||||
}
|
||||
} else {
|
||||
if (grabbed.accepts(stack)) {
|
||||
auto& def = indices.items.require(stack.getItemId());
|
||||
if (grabbed.getCount() < def.stackSize) {
|
||||
action = InteractionAction::TAKE;
|
||||
grabbed.setCount(grabbed.getCount() + 1);
|
||||
}
|
||||
} else {
|
||||
action = InteractionAction::PUT;
|
||||
grabbed.clear();
|
||||
}
|
||||
}
|
||||
} else if (grabbed.isEmpty()) {
|
||||
if (layout.taking) {
|
||||
action = InteractionAction::TAKE;
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
} else if (layout.taking && layout.placing) {
|
||||
action = InteractionAction::PUT;
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
}
|
||||
|
||||
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