1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-17 18:46:35 +00:00

save lifetime of temporary quickkey items

This commit is contained in:
Kuyondo 2025-08-14 15:03:43 +08:00
parent 8ea5448112
commit 4749ddf586
3 changed files with 17 additions and 18 deletions

View file

@ -16,9 +16,7 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwworld/manualref.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
@ -400,11 +398,9 @@ namespace MWGui
if (*it == item) if (*it == item)
break; break;
} }
if (it == store.end())
item = nullptr;
// check the quickkey item is available // Is the quickkey item not in the inventory?
if (item.isEmpty() || item.getCellRef().getCount() < 1) if (it == store.end())
{ {
MWBase::Environment::get().getWindowManager()->messageBox("#{sQuickMenu5} " + key->name); MWBase::Environment::get().getWindowManager()->messageBox("#{sQuickMenu5} " + key->name);
return; return;
@ -629,11 +625,10 @@ namespace MWGui
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
MWWorld::CellStore& draftCell = MWBase::Environment::get().getWorldModel()->getDraftCell();
auto assignItem = [this](auto type, MWWorld::Ptr item) { auto assign = [this](auto type, MWWorld::Ptr item) {
if (type == ESM::QuickKeys::Type::Item) if (type == ESM::QuickKeys::Type::Item)
onAssignItem(item); assignItem(item);
else // if (quickKey.mType == ESM::QuickKeys::Type::MagicItem) else // if (quickKey.mType == ESM::QuickKeys::Type::MagicItem)
onAssignMagicItem(item); onAssignMagicItem(item);
}; };
@ -666,16 +661,14 @@ namespace MWGui
// Fallback to a temporary object for UI display purposes // Fallback to a temporary object for UI display purposes
if (MWBase::Environment::get().getESMStore()->find(quickKey.mId) != 0) if (MWBase::Environment::get().getESMStore()->find(quickKey.mId) != 0)
{ {
MWWorld::ManualRef mref(*MWBase::Environment::get().getESMStore(), quickKey.mId); // Tie temporary item lifetime to this window
item = mref.getPtr().getClass().copyToCell(mref.getPtr(), draftCell, 1); mTemp.emplace_back(*MWBase::Environment::get().getESMStore(), quickKey.mId, 0);
assignItem(quickKey.mType, item); assign(quickKey.mType, mTemp.back().getPtr());
MWBase::Environment::get().getWorld()->disable(item);
MWBase::Environment::get().getWorld()->deleteObject(item);
} }
} }
} }
else else
assignItem(quickKey.mType, item); assign(quickKey.mType, item);
break; break;
} }

View file

@ -5,6 +5,8 @@
#include "components/esm3/quickkeys.hpp" #include "components/esm3/quickkeys.hpp"
#include "../mwworld/manualref.hpp"
#include "itemselection.hpp" #include "itemselection.hpp"
#include "spellmodel.hpp" #include "spellmodel.hpp"
#include "windowbase.hpp" #include "windowbase.hpp"
@ -57,6 +59,7 @@ namespace MWGui
}; };
std::vector<keyData> mKey; std::vector<keyData> mKey;
std::vector<MWWorld::ManualRef> mTemp;
keyData* mSelected; keyData* mSelected;
keyData* mActivated; keyData* mActivated;

View file

@ -15,13 +15,16 @@ namespace MWWorld
std::any mRef; std::any mRef;
Ptr mPtr; Ptr mPtr;
ManualRef(const ManualRef&);
ManualRef& operator=(const ManualRef&);
public: public:
ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count = 1); ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count = 1);
ManualRef(const MWWorld::ESMStore& store, const MWWorld::Ptr& template_, const int count = 1); ManualRef(const MWWorld::ESMStore& store, const MWWorld::Ptr& template_, const int count = 1);
ManualRef(const ManualRef&) = delete;
ManualRef& operator=(const ManualRef&) = delete;
ManualRef(ManualRef&&) noexcept = default;
ManualRef& operator=(ManualRef&&) noexcept = default;
const Ptr& getPtr() const { return mPtr; } const Ptr& getPtr() const { return mPtr; }
}; };
} }