From 763f64741255147501b63c94424195d8a996764a Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 5 Mar 2016 19:53:24 +0100 Subject: [PATCH] Add ItemModel::allowedToInsertItems --- apps/openmw/mwgui/container.cpp | 4 ++-- apps/openmw/mwgui/itemmodel.cpp | 5 +++++ apps/openmw/mwgui/itemmodel.hpp | 3 +++ apps/openmw/mwgui/pickpocketitemmodel.cpp | 6 ++++++ apps/openmw/mwgui/pickpocketitemmodel.hpp | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 5d71fc445..e1b5c120a 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -57,7 +57,7 @@ namespace MWGui { if (mDragAndDrop->mIsOnDragAndDrop) { - if (!dynamic_cast(mModel)) + if (mModel && mModel->allowedToInsertItems()) dropItem(); return; } @@ -126,7 +126,7 @@ namespace MWGui void ContainerWindow::onBackgroundSelected() { - if (mDragAndDrop->mIsOnDragAndDrop && !dynamic_cast(mModel)) + if (mDragAndDrop->mIsOnDragAndDrop && mModel && mModel->allowedToInsertItems()) dropItem(); } diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 2c382f3cf..390bb0586 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -119,6 +119,11 @@ namespace MWGui return ret; } + bool ItemModel::allowedToInsertItems() const + { + return true; + } + ProxyItemModel::ProxyItemModel() : mSourceModel(NULL) diff --git a/apps/openmw/mwgui/itemmodel.hpp b/apps/openmw/mwgui/itemmodel.hpp index 2019c1042..20955b206 100644 --- a/apps/openmw/mwgui/itemmodel.hpp +++ b/apps/openmw/mwgui/itemmodel.hpp @@ -70,6 +70,9 @@ namespace MWGui virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0; virtual void removeItem (const ItemStack& item, size_t count) = 0; + /// Is the player allowed to insert items into this model? (default true) + virtual bool allowedToInsertItems() const; + private: ItemModel(const ItemModel&); ItemModel& operator=(const ItemModel&); diff --git a/apps/openmw/mwgui/pickpocketitemmodel.cpp b/apps/openmw/mwgui/pickpocketitemmodel.cpp index ab0d02f95..238fb5913 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.cpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.cpp @@ -64,4 +64,10 @@ namespace MWGui /// \todo check if player is detected } + bool PickpocketItemModel::allowedToInsertItems() const + { + // don't allow "reverse pickpocket" (yet) + return false; + } + } diff --git a/apps/openmw/mwgui/pickpocketitemmodel.hpp b/apps/openmw/mwgui/pickpocketitemmodel.hpp index af72119c8..61f0569b5 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.hpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.hpp @@ -15,6 +15,7 @@ namespace MWGui virtual size_t getItemCount(); virtual void update(); virtual void removeItem (const ItemStack& item, size_t count); + virtual bool allowedToInsertItems() const; private: std::vector mHiddenItems;