forked from teamnwah/openmw-tes3coop
Fix an item duplication glitch
This commit is contained in:
parent
7aee1da5c6
commit
c6d2d1999a
3 changed files with 15 additions and 12 deletions
|
@ -88,8 +88,13 @@ namespace MWGui
|
||||||
|
|
||||||
mDragAndDropWidget->setVisible(false);
|
mDragAndDropWidget->setVisible(false);
|
||||||
|
|
||||||
targetModel->copyItem(mItem, mDraggedCount);
|
// If item is dropped where it was taken from, we don't need to do anything -
|
||||||
mSourceModel->removeItem(mItem, mDraggedCount);
|
// otherwise, do the transfer
|
||||||
|
if (targetModel != mSourceModel)
|
||||||
|
{
|
||||||
|
targetModel->copyItem(mItem, mDraggedCount);
|
||||||
|
mSourceModel->removeItem(mItem, mDraggedCount);
|
||||||
|
}
|
||||||
|
|
||||||
mSourceModel->update();
|
mSourceModel->update();
|
||||||
|
|
||||||
|
|
|
@ -74,13 +74,12 @@ ItemModel::ModelIndex ContainerItemModel::getIndex (ItemStack item)
|
||||||
void ContainerItemModel::copyItem (const ItemStack& item, size_t count)
|
void ContainerItemModel::copyItem (const ItemStack& item, size_t count)
|
||||||
{
|
{
|
||||||
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
|
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
|
||||||
|
if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source))
|
||||||
|
throw std::runtime_error("Item to copy needs to be from a different container!");
|
||||||
int origCount = item.mBase.getRefData().getCount();
|
int origCount = item.mBase.getRefData().getCount();
|
||||||
item.mBase.getRefData().setCount(count);
|
item.mBase.getRefData().setCount(count);
|
||||||
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase, source);
|
source.getClass().getContainerStore(source).add(item.mBase, source);
|
||||||
if (*it != item.mBase)
|
item.mBase.getRefData().setCount(origCount);
|
||||||
item.mBase.getRefData().setCount(origCount);
|
|
||||||
else
|
|
||||||
item.mBase.getRefData().setCount(origCount + count); // item copied onto itself
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContainerItemModel::removeItem (const ItemStack& item, size_t count)
|
void ContainerItemModel::removeItem (const ItemStack& item, size_t count)
|
||||||
|
|
|
@ -40,13 +40,12 @@ ItemModel::ModelIndex InventoryItemModel::getIndex (ItemStack item)
|
||||||
|
|
||||||
void InventoryItemModel::copyItem (const ItemStack& item, size_t count)
|
void InventoryItemModel::copyItem (const ItemStack& item, size_t count)
|
||||||
{
|
{
|
||||||
|
if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
|
||||||
|
throw std::runtime_error("Item to copy needs to be from a different container!");
|
||||||
int origCount = item.mBase.getRefData().getCount();
|
int origCount = item.mBase.getRefData().getCount();
|
||||||
item.mBase.getRefData().setCount(count);
|
item.mBase.getRefData().setCount(count);
|
||||||
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase, mActor);
|
mActor.getClass().getContainerStore(mActor).add(item.mBase, mActor);
|
||||||
if (*it != item.mBase)
|
item.mBase.getRefData().setCount(origCount);
|
||||||
item.mBase.getRefData().setCount(origCount);
|
|
||||||
else
|
|
||||||
item.mBase.getRefData().setCount(origCount + count); // item copied onto itself
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue