From 888cde79ef8f6d1b008e86207b41e1fd686c7636 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:00:13 +1100 Subject: feat: middle click objects in the inventory to open their interface makes carrying around shop objects easier might need to restrict the allowed interaction types more, as some may break due to the source entity being the player --- source/frontend/StarInventory.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/frontend/StarInventory.cpp') 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(widget); + InventorySlot inventorySlot = BagSlot(bagType, itemGrid->selectedIndex()); + auto inventory = m_player->inventory(); + if (auto sourceItem = as(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*) { -- cgit v1.2.3