From a9e5e1948270945bbb16be1219cb61a10ce8ddd8 Mon Sep 17 00:00:00 2001 From: rexelion Date: Tue, 31 Oct 2017 18:16:40 +0000 Subject: [PATCH] OnActivate is triggered when the item is picked up --- apps/openmw/mwgui/inventorywindow.cpp | 26 +++++++------------------- apps/openmw/mwgui/inventorywindow.hpp | 4 ---- apps/openmw/mwgui/windowmanagerimp.cpp | 2 -- apps/openmw/mwworld/actiontake.cpp | 3 +++ 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 5fe644d45..1e9f534d6 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,7 +1,6 @@ #include "inventorywindow.hpp" #include -#include #include #include @@ -150,15 +149,6 @@ namespace MWGui mItemView->setModel(NULL); } - void InventoryWindow::activateItems() - { - for (std::vector::iterator it = mItemsToActivate.begin(); it != mItemsToActivate.end(); it++) - { - it->getRefData().activate(); - } - mItemsToActivate.clear(); - } - void InventoryWindow::setGuiMode(GuiMode mode) { std::string setting = "inventory"; @@ -663,15 +653,6 @@ namespace MWGui if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; - if (object.getRefData().hasSuppressActivate()) // if Flag_SuppressActivate is set, script that contains OnActivate is attached to the item - { - if (std::find(mItemsToActivate.begin(), mItemsToActivate.end(), object) == mItemsToActivate.end()) - { - mItemsToActivate.push_back(object); - } - return; - } - int count = object.getRefData().getCount(); MWWorld::Ptr player = MWMechanics::getPlayer(); @@ -682,6 +663,13 @@ namespace MWGui // add to player inventory // can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object MWWorld::Ptr newObject = *player.getClass().getContainerStore (player).add (object, object.getRefData().getCount(), player); + + if (object.getRefData().hasSuppressActivate()) // if Flag_SuppressActivate is set, script that contains OnActivate is attached to the item + { + newObject.getRefData().onActivate(); // set the flag_SuppressActivate flag for the new item + newObject.getRefData().activate(); + } + // remove from world MWBase::Environment::get().getWorld()->deleteObject (object); diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 3f88d8822..5576b52ed 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -58,8 +58,6 @@ namespace MWGui void clear(); - void activateItems(); - void useItem(const MWWorld::Ptr& ptr); void setGuiMode(GuiMode mode); @@ -72,8 +70,6 @@ namespace MWGui int mSelectedItem; - std::vector mItemsToActivate; - MWWorld::Ptr mPtr; MWGui::ItemView* mItemView; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index e2a10ccc3..ccdd6916c 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1171,8 +1171,6 @@ namespace MWGui mGuiModeStates[mode].update(false); if (!noSound) playSound(mGuiModeStates[mode].mCloseSound); - if (mode == GM_Inventory) - mInventoryWindow->activateItems(); // Activate cursed items when inventory is closed } if (!mGuiModes.empty()) diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index d858859a6..52e30c8ac 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -14,6 +14,9 @@ namespace MWWorld void ActionTake::executeImp (const Ptr& actor) { + //No need to do anything if moving items from the player's inventory back into player's inventory + if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr() && getTarget().getCell() == 0) + return; MWBase::Environment::get().getMechanicsManager()->itemTaken( actor, getTarget(), MWWorld::Ptr(), getTarget().getRefData().getCount()); MWWorld::Ptr newitem = *actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor);