mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 04:21:50 +00:00
add item dropping outside of inventory
This commit is contained in:
parent
0cbb740e70
commit
56c4d68c84
8 changed files with 132 additions and 21 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "InventoryView.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -19,6 +21,7 @@
|
|||
#include "items/Inventories.hpp"
|
||||
#include "items/Inventory.hpp"
|
||||
#include "items/ItemDef.hpp"
|
||||
#include "items/ItemStack.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "maths/voxmaths.hpp"
|
||||
#include "objects/Player.hpp"
|
||||
|
|
@ -610,6 +613,33 @@ void InventoryView::setPos(const glm::vec2& pos) {
|
|||
Container::setPos(pos - origin);
|
||||
}
|
||||
|
||||
void InventoryView::clickedOutside(Mousecode button) {
|
||||
// root is the id of the main inventory
|
||||
if (getId() != "root") {
|
||||
return;
|
||||
}
|
||||
int mode;
|
||||
if (button == Mousecode::BUTTON_1) {
|
||||
mode = 0;
|
||||
} else if (button == Mousecode::BUTTON_2) {
|
||||
mode = 1;
|
||||
} else if (button == Mousecode::BUTTON_3) {
|
||||
mode = 2;
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
auto exchangeSlot = std::dynamic_pointer_cast<SlotView>(
|
||||
gui.get(SlotView::EXCHANGE_SLOT_NAME));
|
||||
if (exchangeSlot == nullptr) {
|
||||
return;
|
||||
}
|
||||
ItemStack& grabbed = exchangeSlot->getStack();
|
||||
if (grabbed.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
scripting::on_inventory_clicked_outside(exchangeSlot->getInventoryId(), 0, mode);
|
||||
}
|
||||
|
||||
void InventoryView::setOrigin(const glm::vec2& origin) {
|
||||
this->origin = origin;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ namespace gui {
|
|||
|
||||
void setSelected(int index);
|
||||
|
||||
void clickedOutside(Mousecode button) override;
|
||||
|
||||
void bind(
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
|
|
|
|||
|
|
@ -207,6 +207,9 @@ namespace gui {
|
|||
virtual void onFocus();
|
||||
virtual void doubleClick(int x, int y);
|
||||
virtual void click(int x, int y);
|
||||
virtual void clickedOutside(Mousecode button) {
|
||||
// Empty for all UINodes, except InventoryView
|
||||
}
|
||||
virtual void clicked(Mousecode button);
|
||||
virtual void mouseMove(int x, int y) {};
|
||||
virtual void mouseRelease(int x, int y);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue