1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-18 15:16:40 +00:00

Merge branch 'partialequippingp2' into 'master'

Fix partial ammo equipping

See merge request OpenMW/openmw!3434
This commit is contained in:
Alexei Kotov 2023-11-07 03:55:58 +00:00
commit 48c1c2cf08
2 changed files with 23 additions and 14 deletions

View file

@ -556,6 +556,20 @@ namespace MWGui
std::unique_ptr<MWWorld::Action> action = ptr.getClass().use(ptr, force); std::unique_ptr<MWWorld::Action> action = ptr.getClass().use(ptr, force);
action->execute(player); action->execute(player);
// Handles partial equipping (final part)
if (mEquippedStackableCount.has_value())
{
// the count to unequip
int count = ptr.getRefData().getCount() - mDragAndDrop->mDraggedCount - mEquippedStackableCount.value();
if (count > 0)
{
MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr);
invStore.unequipItemQuantity(ptr, count);
updateItemView();
mEquippedStackableCount.reset();
}
}
if (isVisible()) if (isVisible())
{ {
mItemView->update(); mItemView->update();
@ -581,26 +595,20 @@ namespace MWGui
} }
// Handles partial equipping // Handles partial equipping
const std::pair<std::vector<int>, bool> slots = ptr.getClass().getEquipmentSlots(ptr); mEquippedStackableCount.reset();
const auto slots = ptr.getClass().getEquipmentSlots(ptr);
if (!slots.first.empty() && slots.second) if (!slots.first.empty() && slots.second)
{ {
int equippedStackableCount = 0;
MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr); MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ConstContainerStoreIterator slotIt = invStore.getSlot(slots.first.front()); MWWorld::ConstContainerStoreIterator slotIt = invStore.getSlot(slots.first.front());
// Get the count before useItem() // Save the currently equipped count before useItem()
if (slotIt != invStore.end() && slotIt->getCellRef().getRefId() == ptr.getCellRef().getRefId()) if (slotIt != invStore.end() && slotIt->getCellRef().getRefId() == ptr.getCellRef().getRefId())
equippedStackableCount = slotIt->getRefData().getCount(); mEquippedStackableCount = slotIt->getRefData().getCount();
useItem(ptr);
int unequipCount = ptr.getRefData().getCount() - mDragAndDrop->mDraggedCount - equippedStackableCount;
if (unequipCount > 0)
{
invStore.unequipItemQuantity(ptr, unequipCount);
updateItemView();
}
}
else else
mEquippedStackableCount = 0;
}
MWBase::Environment::get().getLuaManager()->useItem(ptr, MWMechanics::getPlayer(), false); MWBase::Environment::get().getLuaManager()->useItem(ptr, MWMechanics::getPlayer(), false);
// If item is ingredient or potion don't stop drag and drop to simplify action of taking more than one 1 // If item is ingredient or potion don't stop drag and drop to simplify action of taking more than one 1

View file

@ -74,6 +74,7 @@ namespace MWGui
DragAndDrop* mDragAndDrop; DragAndDrop* mDragAndDrop;
int mSelectedItem; int mSelectedItem;
std::optional<int> mEquippedStackableCount;
MWWorld::Ptr mPtr; MWWorld::Ptr mPtr;