Skip to content

Commit

Permalink
Merge branch 'partialequippingp2' into 'master'
Browse files Browse the repository at this point in the history
Fix partial ammo equipping

See merge request OpenMW/openmw!3434
  • Loading branch information
Capostrophic committed Nov 7, 2023
2 parents 5a0de32 + 3761797 commit 48c1c2c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
36 changes: 22 additions & 14 deletions apps/openmw/mwgui/inventorywindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,20 @@ namespace MWGui
std::unique_ptr<MWWorld::Action> action = ptr.getClass().use(ptr, force);
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())
{
mItemView->update();
Expand All @@ -581,27 +595,21 @@ namespace MWGui
}

// 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)
{
int equippedStackableCount = 0;
MWWorld::InventoryStore& invStore = mPtr.getClass().getInventoryStore(mPtr);
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())
equippedStackableCount = slotIt->getRefData().getCount();

useItem(ptr);
int unequipCount = ptr.getRefData().getCount() - mDragAndDrop->mDraggedCount - equippedStackableCount;
if (unequipCount > 0)
{
invStore.unequipItemQuantity(ptr, unequipCount);
updateItemView();
}
mEquippedStackableCount = slotIt->getRefData().getCount();
else
mEquippedStackableCount = 0;
}
else
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
// item
Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwgui/inventorywindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace MWGui
DragAndDrop* mDragAndDrop;

int mSelectedItem;
std::optional<int> mEquippedStackableCount;

MWWorld::Ptr mPtr;

Expand Down

0 comments on commit 48c1c2c

Please sign in to comment.