diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 1f6b6fdeb5..acc1dd6068 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -550,7 +550,7 @@ namespace MWGui } std::unique_ptr action = ptr.getClass().use(ptr, force); - action->execute(player); + action->execute(player, !canEquip); // Handles partial equipping (final part) if (mEquippedStackableCount.has_value()) @@ -581,11 +581,11 @@ namespace MWGui { MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase; - auto canEquip = ptr.getClass().canBeEquipped(ptr, mPtr); - if (canEquip.first == 0) // cannot equip + auto [canEquipRes, canEquipMsg] = ptr.getClass().canBeEquipped(ptr, mPtr); + if (canEquipRes == 0) // cannot equip { mDragAndDrop->drop(mTradeModel, mItemView); // also plays down sound - MWBase::Environment::get().getWindowManager()->messageBox(canEquip.second); + MWBase::Environment::get().getWindowManager()->messageBox(canEquipMsg); return; } diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 5f3cd17732..191a2d8b3a 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -388,26 +388,9 @@ namespace MWGui return; } - // check the quickkey item is not broken - if (item.getClass().hasItemHealth(item) && item.getClass().getItemHealth(item) <= 0) - { - const std::vector& equipmentSlots = item.getClass().getEquipmentSlots(item).first; - if (!equipmentSlots.empty()) - { - const auto& itSlot = store.getSlot(equipmentSlots.front()); - // Morrowind.exe behavior: - // Only display the "item is broken" message if: - // - There is no item in the target equipment slot, or - // - The quickkey item is broken and the currently equipped item has a different ID - if (itSlot == store.end() || (item.getCellRef().getRefId() != itSlot->getCellRef().getRefId())) - MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage1}"); - } - return; - } - if (key->type == ESM::QuickKeys::Type::Item) { - if (!store.isEquipped(item)) + if (!store.isEquipped(item.getCellRef().getRefId())) MWBase::Environment::get().getWindowManager()->useItem(item); MWWorld::ConstContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index f48f4e6e31..9143777531 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -754,6 +754,16 @@ bool MWWorld::InventoryStore::isEquipped(const MWWorld::ConstPtr& item) return false; } +bool MWWorld::InventoryStore::isEquipped(const ESM::RefId& id) +{ + for (int i = 0; i < MWWorld::InventoryStore::Slots; ++i) + { + if (getSlot(i) != end() && getSlot(i)->getCellRef().getRefId() == id) + return true; + } + return false; +} + bool MWWorld::InventoryStore::isFirstEquip() { bool first = mFirstAutoEquip; diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 0af6ee2b28..d0839dd1ed 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -118,6 +118,7 @@ namespace MWWorld ///< \warning \a iterator can not be an end()-iterator, use unequip function instead bool isEquipped(const MWWorld::ConstPtr& item); + bool isEquipped(const ESM::RefId& id); ///< Utility function, returns true if the given item is equipped in any slot void setSelectedEnchantItem(const ContainerStoreIterator& iterator);