1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-03 21:15:38 +00:00

Fix item owner not resetting when dragging an item from a corpse to the player avatar

This commit is contained in:
scrawl 2014-05-15 04:41:31 +02:00
parent bac4d875df
commit eb40032bde
9 changed files with 27 additions and 32 deletions

View file

@ -10,23 +10,23 @@ namespace MWGui
{ {
} }
void CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
{ {
if (mActor.getClass().isNpc()) if (mActor.getClass().isNpc())
{ {
MWMechanics::NpcStats& stats = MWWorld::Class::get(mActor).getNpcStats(mActor); MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats(mActor);
stats.modifyProfit(MWWorld::Class::get(item.mBase).getValue(item.mBase) * count); stats.modifyProfit(item.mBase.getClass().getValue(item.mBase) * count);
} }
InventoryItemModel::copyItem(item, count, setNewOwner); return InventoryItemModel::copyItem(item, count, setNewOwner);
} }
void CompanionItemModel::removeItem (const ItemStack& item, size_t count) void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
{ {
if (mActor.getClass().isNpc()) if (mActor.getClass().isNpc())
{ {
MWMechanics::NpcStats& stats = MWWorld::Class::get(mActor).getNpcStats(mActor); MWMechanics::NpcStats& stats = mActor.getClass().getNpcStats(mActor);
stats.modifyProfit(-MWWorld::Class::get(item.mBase).getValue(item.mBase) * count); stats.modifyProfit(-item.mBase.getClass().getValue(item.mBase) * count);
} }
InventoryItemModel::removeItem(item, count); InventoryItemModel::removeItem(item, count);

View file

@ -13,7 +13,7 @@ namespace MWGui
public: public:
CompanionItemModel (const MWWorld::Ptr& actor); CompanionItemModel (const MWWorld::Ptr& actor);
virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner); virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
}; };

View file

@ -71,12 +71,12 @@ ItemModel::ModelIndex ContainerItemModel::getIndex (ItemStack item)
return -1; return -1;
} }
void ContainerItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner) MWWorld::Ptr ContainerItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{ {
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1]; const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source)) if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source))
throw std::runtime_error("Item to copy needs to be from a different container!"); throw std::runtime_error("Item to copy needs to be from a different container!");
source.getClass().getContainerStore(source).add(item.mBase, count, source); return *source.getClass().getContainerStore(source).add(item.mBase, count, source);
} }
void ContainerItemModel::removeItem (const ItemStack& item, size_t count) void ContainerItemModel::removeItem (const ItemStack& item, size_t count)

View file

@ -21,7 +21,7 @@ namespace MWGui
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);
virtual size_t getItemCount(); virtual size_t getItemCount();
virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false); virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
virtual void update(); virtual void update();

View file

@ -40,11 +40,11 @@ ItemModel::ModelIndex InventoryItemModel::getIndex (ItemStack item)
return -1; return -1;
} }
void InventoryItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner) MWWorld::Ptr InventoryItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{ {
if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor)) if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
throw std::runtime_error("Item to copy needs to be from a different container!"); throw std::runtime_error("Item to copy needs to be from a different container!");
mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor, setNewOwner); return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor, setNewOwner);
} }
@ -59,7 +59,7 @@ void InventoryItemModel::removeItem (const ItemStack& item, size_t count)
throw std::runtime_error("Not enough items in the stack to remove"); throw std::runtime_error("Not enough items in the stack to remove");
} }
void InventoryItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel) MWWorld::Ptr InventoryItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)
{ {
bool setNewOwner = false; bool setNewOwner = false;
@ -70,8 +70,9 @@ void InventoryItemModel::moveItem(const ItemStack &item, size_t count, ItemModel
&& Misc::StringUtils::ciEqual(item.mBase.getCellRef().mOwner, mActor.getCellRef().mRefID)) && Misc::StringUtils::ciEqual(item.mBase.getCellRef().mOwner, mActor.getCellRef().mRefID))
setNewOwner = true; setNewOwner = true;
otherModel->copyItem(item, count, setNewOwner); MWWorld::Ptr ret = otherModel->copyItem(item, count, setNewOwner);
removeItem(item, count); removeItem(item, count);
return ret;
} }
void InventoryItemModel::update() void InventoryItemModel::update()

View file

@ -15,11 +15,11 @@ namespace MWGui
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);
virtual size_t getItemCount(); virtual size_t getItemCount();
virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false); virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
/// Move items from this model to \a otherModel. /// Move items from this model to \a otherModel.
virtual void moveItem (const ItemStack& item, size_t count, ItemModel* otherModel); virtual MWWorld::Ptr moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
virtual void update(); virtual void update();

View file

@ -408,14 +408,8 @@ namespace MWGui
if (mDragAndDrop->mSourceModel != mTradeModel) if (mDragAndDrop->mSourceModel != mTradeModel)
{ {
// add item to the player's inventory // Move item to the player's inventory
MWWorld::ContainerStore& invStore = MWWorld::Class::get(mPtr).getContainerStore(mPtr); ptr = mDragAndDrop->mSourceModel->moveItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount, mTradeModel);
MWWorld::ContainerStoreIterator it = invStore.begin();
it = invStore.add(ptr, mDragAndDrop->mDraggedCount, mPtr);
mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
ptr = *it;
} }
useItem(ptr); useItem(ptr);
} }

View file

@ -71,10 +71,11 @@ namespace MWGui
{ {
} }
void ItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel) MWWorld::Ptr ItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)
{ {
otherModel->copyItem(item, count); MWWorld::Ptr ret = otherModel->copyItem(item, count);
removeItem(item, count); removeItem(item, count);
return ret;
} }
@ -83,10 +84,9 @@ namespace MWGui
delete mSourceModel; delete mSourceModel;
} }
void ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner) MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{ {
// no need to use mapToSource since itemIndex refers to an index in the sourceModel return mSourceModel->copyItem (item, count, setNewOwner);
mSourceModel->copyItem (item, count, setNewOwner);
} }
void ProxyItemModel::removeItem (const ItemStack& item, size_t count) void ProxyItemModel::removeItem (const ItemStack& item, size_t count)

View file

@ -56,10 +56,10 @@ namespace MWGui
virtual void update() = 0; virtual void update() = 0;
/// Move items from this model to \a otherModel. /// Move items from this model to \a otherModel.
virtual void moveItem (const ItemStack& item, size_t count, ItemModel* otherModel); virtual MWWorld::Ptr moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
/// @param setNewOwner Set the copied item's owner to the actor we are copying to, or keep the original owner? /// @param setNewOwner Set the copied item's owner to the actor we are copying to, or keep the original owner?
virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0; virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0;
virtual void removeItem (const ItemStack& item, size_t count) = 0; virtual void removeItem (const ItemStack& item, size_t count) = 0;
private: private:
@ -73,7 +73,7 @@ namespace MWGui
{ {
public: public:
virtual ~ProxyItemModel(); virtual ~ProxyItemModel();
virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false); virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);