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

Merge branch '8551-orang-kk' into 'master'

Fix loss of quick key bindings for temporary or missing items

See merge request OpenMW/openmw!4780
This commit is contained in:
psi29a 2025-08-15 06:49:51 +00:00
commit 8622dacaea
3 changed files with 36 additions and 14 deletions

View file

@ -74,6 +74,8 @@ namespace MWGui
{
unassign(&mKey[i]);
}
mTemp.clear();
}
inline void QuickKeysMenu::validate(int index)
@ -397,11 +399,9 @@ namespace MWGui
if (*it == item)
break;
}
if (it == store.end())
item = nullptr;
// check the quickkey item is available
if (item.isEmpty() || item.getCellRef().getCount() < 1)
// Is the quickkey item not in the inventory?
if (it == store.end())
{
MWBase::Environment::get().getWindowManager()->messageBox("#{sQuickMenu5} " + key->name);
return;
@ -626,6 +626,13 @@ namespace MWGui
MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
auto assign = [this](auto type, MWWorld::Ptr item) {
if (type == ESM::QuickKeys::Type::Item)
assignItem(item);
else // if (quickKey.mType == ESM::QuickKeys::Type::MagicItem)
onAssignMagicItem(item);
};
int i = 0;
for (ESM::QuickKeys::QuickKey& quickKey : keys.mKeys)
{
@ -646,16 +653,25 @@ namespace MWGui
{
// Find the item by id
MWWorld::Ptr item = store.findReplacement(quickKey.mId);
if (item.isEmpty())
unassign(mSelected);
else
{
if (quickKey.mType == ESM::QuickKeys::Type::Item)
assignItem(item);
else // if (quickKey.mType == ESM::QuickKeys::Type::MagicItem)
onAssignMagicItem(item);
unassign(mSelected);
if (!quickKey.mId.empty())
{
// Fallback to a temporary object for UI display purposes
if (MWBase::Environment::get().getESMStore()->find(quickKey.mId) != 0)
{
// Tie temporary item lifetime to this window
mTemp.emplace_back(*MWBase::Environment::get().getESMStore(), quickKey.mId, 0);
assign(quickKey.mType, mTemp.back().getPtr());
}
else
Log(Debug::Warning) << "Failed to load quick key " << (i + 1)
<< ": could not find object " << quickKey.mId;
}
}
else
assign(quickKey.mType, item);
break;
}

View file

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

View file

@ -15,13 +15,16 @@ namespace MWWorld
std::any mRef;
Ptr mPtr;
ManualRef(const ManualRef&);
ManualRef& operator=(const ManualRef&);
public:
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 ManualRef&) = delete;
ManualRef& operator=(const ManualRef&) = delete;
ManualRef(ManualRef&&) noexcept = default;
ManualRef& operator=(ManualRef&&) noexcept = default;
const Ptr& getPtr() const { return mPtr; }
};
}