diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-03-27 16:07:17 +1100 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-03-27 16:07:17 +1100 |
commit | f08ffe2162f9c3298f04174de7303bcbcdaf2a01 (patch) | |
tree | 2a13b67ffdeef540dcbd387b6848b561728ef466 /source/frontend/StarInventory.cpp | |
parent | b50244ade5415f9f84db9d54995faacffe6fd691 (diff) | |
parent | 888cde79ef8f6d1b008e86207b41e1fd686c7636 (diff) |
Merge branch 'light-test'
Diffstat (limited to 'source/frontend/StarInventory.cpp')
-rw-r--r-- | source/frontend/StarInventory.cpp | 24 |
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*) { |