Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend/StarInventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/frontend/StarInventory.cpp')
-rw-r--r--source/frontend/StarInventory.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/frontend/StarInventory.cpp b/source/frontend/StarInventory.cpp
index 390558c..650d2e3 100644
--- a/source/frontend/StarInventory.cpp
+++ b/source/frontend/StarInventory.cpp
@@ -20,6 +20,8 @@
#include "StarJsonExtra.hpp"
#include "StarStatistics.hpp"
#include "StarAugmentItem.hpp"
+#include "StarObjectItem.hpp"
+#include "StarInteractionTypes.hpp"
namespace Star {
@@ -94,6 +96,27 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI
rightClickCallback(slot);
};
+ auto middleClickCallback = [this](String const& bagType, Widget* widget) {
+ if (!m_player->inWorld())
+ return;
+
+ auto itemGrid = convert<ItemGridWidget>(widget);
+ InventorySlot inventorySlot = BagSlot(bagType, itemGrid->selectedIndex());
+ auto inventory = m_player->inventory();
+ if (auto sourceItem = as<ObjectItem>(itemGrid->selectedItem())) {
+ if (auto actionTypeName = sourceItem->instanceValue("interactAction")) {
+ auto actionType = InteractActionTypeNames.getLeft(actionTypeName.toString());
+ if (actionType >= InteractActionType::OpenCraftingInterface && actionType <= InteractActionType::ScriptPane) {
+ auto actionData = sourceItem->instanceValue("interactData", Json());
+ if (actionData.isType(Json::Type::Object))
+ actionData = actionData.set("openWithInventory", false);
+ InteractAction action(actionType, m_player->entityId(), actionData);
+ m_player->interact(action);
+ }
+ }
+ }
+ };
+
Json itemBagConfig = config.get("bagConfig");
auto bagOrder = itemBagConfig.toObject().keys().sorted([&itemBagConfig](String const& a, String const& b) {
return itemBagConfig.get(a).getInt("order", 0) < itemBagConfig.get(b).getInt("order", 0);
@@ -102,6 +125,7 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI
auto itemGrid = itemBagConfig.get(name).getString("itemGrid");
invWindowReader.registerCallback(itemGrid, bind(leftClickCallback, name, _1));
invWindowReader.registerCallback(strf("{}.right", itemGrid), bind(bagGridCallback, name, _1));
+ invWindowReader.registerCallback(strf("{}.middle", itemGrid), bind(middleClickCallback, name, _1));
}
invWindowReader.registerCallback("close", [=](Widget*) {