mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-18 05:46:38 +00:00
Merge branch 'partialequippingp2' into 'master'
Fix partial ammo equipping See merge request OpenMW/openmw!3434
This commit is contained in:
commit
48c1c2cf08
2 changed files with 23 additions and 14 deletions
|
@ -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,27 +595,21 @@ 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();
|
||||||
|
else
|
||||||
useItem(ptr);
|
mEquippedStackableCount = 0;
|
||||||
int unequipCount = ptr.getRefData().getCount() - mDragAndDrop->mDraggedCount - equippedStackableCount;
|
|
||||||
if (unequipCount > 0)
|
|
||||||
{
|
|
||||||
invStore.unequipItemQuantity(ptr, unequipCount);
|
|
||||||
updateItemView();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
// If item is ingredient or potion don't stop drag and drop to simplify action of taking more than one 1
|
||||||
// item
|
// item
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace MWGui
|
||||||
DragAndDrop* mDragAndDrop;
|
DragAndDrop* mDragAndDrop;
|
||||||
|
|
||||||
int mSelectedItem;
|
int mSelectedItem;
|
||||||
|
std::optional<int> mEquippedStackableCount;
|
||||||
|
|
||||||
MWWorld::Ptr mPtr;
|
MWWorld::Ptr mPtr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue