From 6e03d710ba64ad48d30d6248e10f86ea7b041a90 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Sat, 15 Jul 2023 18:19:52 +0200 Subject: [PATCH] Remove ItemModel::copyItem(), it is obsolete. --- apps/openmw/mwgui/companionitemmodel.cpp | 8 -------- apps/openmw/mwgui/companionitemmodel.hpp | 1 - apps/openmw/mwgui/containeritemmodel.cpp | 4 ++-- apps/openmw/mwgui/containeritemmodel.hpp | 2 +- apps/openmw/mwgui/hud.cpp | 16 +++------------- apps/openmw/mwgui/inventoryitemmodel.cpp | 13 ++----------- apps/openmw/mwgui/inventoryitemmodel.hpp | 3 +-- apps/openmw/mwgui/itemmodel.cpp | 14 ++------------ apps/openmw/mwgui/itemmodel.hpp | 6 ++---- apps/openmw/mwgui/tradeitemmodel.cpp | 7 ++----- 10 files changed, 15 insertions(+), 59 deletions(-) diff --git a/apps/openmw/mwgui/companionitemmodel.cpp b/apps/openmw/mwgui/companionitemmodel.cpp index 6bae8aef52..3c017a2856 100644 --- a/apps/openmw/mwgui/companionitemmodel.cpp +++ b/apps/openmw/mwgui/companionitemmodel.cpp @@ -33,14 +33,6 @@ namespace MWGui return InventoryItemModel::addItem(item, count, allowAutoEquip); } - MWWorld::Ptr CompanionItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) - { - if (hasProfit(mActor)) - modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count); - - return InventoryItemModel::copyItem(item, count, allowAutoEquip); - } - void CompanionItemModel::removeItem(const ItemStack& item, size_t count) { if (hasProfit(mActor)) diff --git a/apps/openmw/mwgui/companionitemmodel.hpp b/apps/openmw/mwgui/companionitemmodel.hpp index b9ee500693..49c84fe075 100644 --- a/apps/openmw/mwgui/companionitemmodel.hpp +++ b/apps/openmw/mwgui/companionitemmodel.hpp @@ -14,7 +14,6 @@ namespace MWGui CompanionItemModel(const MWWorld::Ptr& actor); MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; - MWWorld::Ptr copyItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; void removeItem(const ItemStack& item, size_t count) override; bool hasProfit(const MWWorld::Ptr& actor); diff --git a/apps/openmw/mwgui/containeritemmodel.cpp b/apps/openmw/mwgui/containeritemmodel.cpp index b0abe5c733..e072f9974a 100644 --- a/apps/openmw/mwgui/containeritemmodel.cpp +++ b/apps/openmw/mwgui/containeritemmodel.cpp @@ -99,12 +99,12 @@ namespace MWGui return -1; } - MWWorld::Ptr ContainerItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) + MWWorld::Ptr ContainerItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip) { auto& source = mItemSources[0]; MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first); if (item.mBase.getContainerStore() == &store) - throw std::runtime_error("Item to copy needs to be from a different container!"); + throw std::runtime_error("Item needs to be from a different container!"); return *store.add(item.mBase, count, allowAutoEquip); } diff --git a/apps/openmw/mwgui/containeritemmodel.hpp b/apps/openmw/mwgui/containeritemmodel.hpp index 1bdcec90f9..52b1911411 100644 --- a/apps/openmw/mwgui/containeritemmodel.hpp +++ b/apps/openmw/mwgui/containeritemmodel.hpp @@ -32,7 +32,7 @@ namespace MWGui ModelIndex getIndex(const ItemStack& item) override; size_t getItemCount() override; - MWWorld::Ptr copyItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; + MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; void removeItem(const ItemStack& item, size_t count) override; void update() override; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 022840ea5e..b936620895 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -46,30 +46,20 @@ namespace MWGui } virtual ~WorldItemModel() override {} - MWWorld::Ptr dropItemImpl(const ItemStack& item, size_t count, bool copy) + MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool /*allowAutoEquip*/) override { MWBase::World* world = MWBase::Environment::get().getWorld(); MWWorld::Ptr dropped; if (world->canPlaceObject(mLeft, mTop)) - dropped = world->placeObject(item.mBase, mLeft, mTop, count, copy); + dropped = world->placeObject(item.mBase, mLeft, mTop, count, false); else - dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count, copy); + dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count, false); dropped.getCellRef().setOwner(ESM::RefId()); return dropped; } - MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool /*allowAutoEquip*/) override - { - return dropItemImpl(item, count, false); - } - - MWWorld::Ptr copyItem(const ItemStack& item, size_t count, bool /*allowAutoEquip*/) override - { - return dropItemImpl(item, count, true); - } - void removeItem(const ItemStack& item, size_t count) override { throw std::runtime_error("removeItem not implemented"); diff --git a/apps/openmw/mwgui/inventoryitemmodel.cpp b/apps/openmw/mwgui/inventoryitemmodel.cpp index 3620ceaf69..ce4d1fc1d0 100644 --- a/apps/openmw/mwgui/inventoryitemmodel.cpp +++ b/apps/openmw/mwgui/inventoryitemmodel.cpp @@ -53,13 +53,6 @@ namespace MWGui return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, allowAutoEquip); } - MWWorld::Ptr InventoryItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) - { - // TODO: This does not copy the item, but adds it directly. This will duplicate the item's - // refnum and other ref data unless the caller handles that. - return addItem(item, count, allowAutoEquip); - } - MWWorld::Ptr InventoryItemModel::unstackItem(const ItemStack& item, size_t count) { MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor); @@ -99,16 +92,14 @@ namespace MWGui } } - MWWorld::Ptr InventoryItemModel::moveItem(const ItemStack& item, size_t count, ItemModel* otherModel) + MWWorld::Ptr InventoryItemModel::moveItem(const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip) { // Can't move conjured items: This is a general fix that also takes care of issues with taking conjured items // via the 'Take All' button. if (item.mFlags & ItemStack::Flag_Bound) return MWWorld::Ptr(); - MWWorld::Ptr ret = otherModel->copyItem(item, count); - removeItem(item, count); - return ret; + return ItemModel::moveItem(item, count, otherModel, allowAutoEquip); } void InventoryItemModel::update() diff --git a/apps/openmw/mwgui/inventoryitemmodel.hpp b/apps/openmw/mwgui/inventoryitemmodel.hpp index 78cd0a739e..6844291cb6 100644 --- a/apps/openmw/mwgui/inventoryitemmodel.hpp +++ b/apps/openmw/mwgui/inventoryitemmodel.hpp @@ -18,12 +18,11 @@ namespace MWGui bool onTakeItem(const MWWorld::Ptr& item, int count) override; MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; - MWWorld::Ptr copyItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; MWWorld::Ptr unstackItem(const ItemStack& item, size_t count) override; void removeItem(const ItemStack& item, size_t count) override; /// Move items from this model to \a otherModel. - MWWorld::Ptr moveItem(const ItemStack& item, size_t count, ItemModel* otherModel) override; + MWWorld::Ptr moveItem(const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip = true) override; void update() override; diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 12f1b5842d..25b66c28c1 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -55,9 +55,9 @@ namespace MWGui ItemModel::ItemModel() {} - MWWorld::Ptr ItemModel::moveItem(const ItemStack& item, size_t count, ItemModel* otherModel) + MWWorld::Ptr ItemModel::moveItem(const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip) { - MWWorld::Ptr ret = otherModel->addItem(item, count); + MWWorld::Ptr ret = otherModel->addItem(item, count, allowAutoEquip); // Unstacking here ensures that new a refnum is assigned to the leftover stack if there is a leftover. // Otherwise we end up with duplicated instances. unstackItem(item, count); @@ -65,11 +65,6 @@ namespace MWGui return ret; } - MWWorld::Ptr ItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip) - { - return copyItem(item, count, allowAutoEquip); - } - MWWorld::Ptr ItemModel::unstackItem(const ItemStack& item, size_t count) { // By default does nothing @@ -96,11 +91,6 @@ namespace MWGui return mSourceModel->allowedToUseItems(); } - MWWorld::Ptr ProxyItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) - { - return mSourceModel->copyItem(item, count, allowAutoEquip); - } - void ProxyItemModel::removeItem(const ItemStack& item, size_t count) { mSourceModel->removeItem(item, count); diff --git a/apps/openmw/mwgui/itemmodel.hpp b/apps/openmw/mwgui/itemmodel.hpp index 5ea3ce78e3..faf783ea70 100644 --- a/apps/openmw/mwgui/itemmodel.hpp +++ b/apps/openmw/mwgui/itemmodel.hpp @@ -63,14 +63,13 @@ namespace MWGui /// Move items from this model to \a otherModel. /// @note Derived implementations may return an empty Ptr if the move was unsuccessful. - virtual MWWorld::Ptr moveItem(const ItemStack& item, size_t count, ItemModel* otherModel); + virtual MWWorld::Ptr moveItem(const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip = true); /// Unstacks items from this model and returns a ptr to the new remainder stack. /// @note Returns en empty ptr if there is no remainder or the item model does not support unstacking. virtual MWWorld::Ptr unstackItem(const ItemStack& item, size_t count); - virtual MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true); - virtual MWWorld::Ptr copyItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) = 0; + virtual MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) = 0; virtual void removeItem(const ItemStack& item, size_t count) = 0; /// Is the player allowed to use items from this item model? (default true) @@ -102,7 +101,6 @@ namespace MWGui MWWorld::Ptr unstackItem(const ItemStack& item, size_t count) override; MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; - MWWorld::Ptr copyItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; void removeItem(const ItemStack& item, size_t count) override; ModelIndex getIndex(const ItemStack& item) override; diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index f14d7fe72c..50a55f5061 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -139,11 +139,8 @@ namespace MWGui if (i == sourceModel->getItemCount()) throw std::runtime_error("The borrowed item disappeared"); - const ItemStack& item = sourceModel->getItem(i); - // copy the borrowed items to our model - copyItem(item, itemStack.mCount, !Settings::game().mPreventMerchantEquipping); - // then remove them from the source model - sourceModel->removeItem(item, itemStack.mCount); + sourceModel->moveItem( + sourceModel->getItem(i), itemStack.mCount, this, !Settings::game().mPreventMerchantEquipping); } mBorrowedToUs.clear(); mBorrowedFromUs.clear();