add item dropping outside of inventory

This commit is contained in:
neveix 2026-08-13 20:56:59 +05:00
parent 0cbb740e70
commit 56c4d68c84
8 changed files with 132 additions and 21 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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);