Move onClose() check to item models

pull/1549/head
Andrei Kortunov 7 years ago
parent ac33ff9482
commit 3694b6ec90

@ -12,9 +12,7 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/pickpocket.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "countdialog.hpp" #include "countdialog.hpp"
#include "inventorywindow.hpp" #include "inventorywindow.hpp"
@ -33,7 +31,6 @@ namespace MWGui
ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop) ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop)
: WindowBase("openmw_container_window.layout") : WindowBase("openmw_container_window.layout")
, mDragAndDrop(dragAndDrop) , mDragAndDrop(dragAndDrop)
, mPickpocketDetected(false)
, mSortModel(NULL) , mSortModel(NULL)
, mModel(NULL) , mModel(NULL)
, mSelectedItem(-1) , mSelectedItem(-1)
@ -114,7 +111,6 @@ namespace MWGui
void ContainerWindow::setPtr(const MWWorld::Ptr& container) void ContainerWindow::setPtr(const MWWorld::Ptr& container)
{ {
mPickpocketDetected = false;
mPtr = container; mPtr = container;
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead(); bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
@ -159,24 +155,7 @@ namespace MWGui
{ {
WindowBase::onClose(); WindowBase::onClose();
if (dynamic_cast<PickpocketItemModel*>(mModel) mModel->onClose();
// Make sure we were actually closed, rather than just temporarily hidden (e.g. console or main menu opened)
&& !MWBase::Environment::get().getWindowManager()->containsMode(GM_Container)
// If it was already detected while taking an item, no need to check now
&& !mPickpocketDetected
)
{
MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::Pickpocket pickpocket(player, mPtr);
if (pickpocket.finish())
{
MWBase::Environment::get().getMechanicsManager()->commitCrime(
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
mPickpocketDetected = true;
return;
}
}
} }
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
@ -252,7 +231,6 @@ namespace MWGui
bool ContainerWindow::onTakeItem(const ItemStack &item, int count) bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
{ {
// TODO: mPickpocketDetected = true;
return mModel->onTakeItem(item.mBase, count); return mModel->onTakeItem(item.mBase, count);
} }

@ -44,8 +44,6 @@ namespace MWGui
private: private:
DragAndDrop* mDragAndDrop; DragAndDrop* mDragAndDrop;
bool mPickpocketDetected;
MWGui::ItemView* mItemView; MWGui::ItemView* mItemView;
SortFilterItemModel* mSortModel; SortFilterItemModel* mSortModel;
ItemModel* mModel; ItemModel* mModel;

@ -186,7 +186,7 @@ void ContainerItemModel::update()
} }
} }
} }
bool ContainerItemModel::onDropItem(const MWWorld::Ptr &item, int count) const bool ContainerItemModel::onDropItem(const MWWorld::Ptr &item, int count)
{ {
if (mItemSources.empty()) if (mItemSources.empty())
return false; return false;
@ -216,7 +216,7 @@ bool ContainerItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
return true; return true;
} }
bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{ {
if (mItemSources.empty()) if (mItemSources.empty())
return false; return false;

@ -19,8 +19,8 @@ namespace MWGui
virtual bool allowedToUseItems() const; virtual bool allowedToUseItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const; virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const; virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
virtual ItemStack getItem (ModelIndex index); virtual ItemStack getItem (ModelIndex index);
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);

@ -119,7 +119,7 @@ void InventoryItemModel::update()
} }
} }
bool InventoryItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const bool InventoryItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{ {
// Looting a dead corpse is considered OK // Looting a dead corpse is considered OK
if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead()) if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead())

@ -15,7 +15,7 @@ namespace MWGui
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);
virtual size_t getItemCount(); virtual size_t getItemCount();
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const; virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
virtual MWWorld::Ptr 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);

@ -129,12 +129,12 @@ namespace MWGui
return true; return true;
} }
bool ItemModel::onDropItem(const MWWorld::Ptr &item, int count) const bool ItemModel::onDropItem(const MWWorld::Ptr &item, int count)
{ {
return true; return true;
} }
bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{ {
return true; return true;
} }
@ -208,13 +208,18 @@ namespace MWGui
mSourceModel = sourceModel; mSourceModel = sourceModel;
} }
bool ProxyItemModel::onDropItem(const MWWorld::Ptr &item, int count) const void ProxyItemModel::onClose()
{ {
return mSourceModel->onDropItem (item, count); mSourceModel->onClose();
} }
bool ProxyItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const bool ProxyItemModel::onDropItem(const MWWorld::Ptr &item, int count)
{ {
return mSourceModel->onTakeItem (item, count); return mSourceModel->onDropItem(item, count);
}
bool ProxyItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
return mSourceModel->onTakeItem(item, count);
} }
} }

@ -75,8 +75,11 @@ namespace MWGui
/// Is the player allowed to insert items into this model? (default true) /// Is the player allowed to insert items into this model? (default true)
virtual bool allowedToInsertItems() const; virtual bool allowedToInsertItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const; virtual void onClose()
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const; {
}
virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
private: private:
ItemModel(const ItemModel&); ItemModel(const ItemModel&);
@ -93,8 +96,9 @@ namespace MWGui
bool allowedToUseItems() const; bool allowedToUseItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const; virtual void onClose();
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const; virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
virtual MWWorld::Ptr 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);

@ -17,7 +17,7 @@ namespace MWGui
{ {
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, ItemModel *sourceModel, bool hideItems) PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, ItemModel *sourceModel, bool hideItems)
: mActor(actor) : mActor(actor), mPickpocketDetected(false)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
mSourceModel = sourceModel; mSourceModel = sourceModel;
@ -91,11 +91,35 @@ namespace MWGui
return false; return false;
} }
bool PickpocketItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const void PickpocketItemModel::onClose()
{
// Make sure we were actually closed, rather than just temporarily hidden (e.g. console or main menu opened)
if (MWBase::Environment::get().getWindowManager()->containsMode(GM_Container)
// If it was already detected while taking an item, no need to check now
|| mPickpocketDetected)
return;
MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::Pickpocket pickpocket(player, mActor);
if (pickpocket.finish())
{
MWBase::Environment::get().getMechanicsManager()->commitCrime(
player, mActor, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
mPickpocketDetected = true;
}
}
bool PickpocketItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{ {
if (mActor.getClass().getCreatureStats(mActor).getKnockedDown()) if (mActor.getClass().getCreatureStats(mActor).getKnockedDown())
return mSourceModel->onTakeItem(item, count); return mSourceModel->onTakeItem(item, count);
return stealItem(item, count);
}
bool PickpocketItemModel::stealItem(const MWWorld::Ptr &item, int count)
{
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::Pickpocket pickpocket(player, mActor); MWMechanics::Pickpocket pickpocket(player, mActor);
if (pickpocket.pick(item, count)) if (pickpocket.pick(item, count))
@ -103,6 +127,7 @@ namespace MWGui
MWBase::Environment::get().getMechanicsManager()->commitCrime( MWBase::Environment::get().getMechanicsManager()->commitCrime(
player, mActor, MWBase::MechanicsManager::OT_Pickpocket, 0, true); player, mActor, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container); MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
mPickpocketDetected = true;
return false; return false;
} }
else else

@ -18,11 +18,14 @@ namespace MWGui
virtual void update(); virtual void update();
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
virtual bool allowedToInsertItems() const; virtual bool allowedToInsertItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const; virtual void onClose();
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const; virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
protected: protected:
MWWorld::Ptr mActor; MWWorld::Ptr mActor;
bool mPickpocketDetected;
bool stealItem(const MWWorld::Ptr &item, int count);
private: private:
std::vector<ItemStack> mHiddenItems; std::vector<ItemStack> mHiddenItems;

@ -311,13 +311,18 @@ namespace MWGui
std::sort(mItems.begin(), mItems.end(), cmp); std::sort(mItems.begin(), mItems.end(), cmp);
} }
bool SortFilterItemModel::onDropItem(const MWWorld::Ptr &item, int count) const void SortFilterItemModel::onClose()
{ {
return mSourceModel->onDropItem (item, count); mSourceModel->onClose();
} }
bool SortFilterItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const bool SortFilterItemModel::onDropItem(const MWWorld::Ptr &item, int count)
{ {
return mSourceModel->onTakeItem (item, count); return mSourceModel->onDropItem(item, count);
}
bool SortFilterItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
return mSourceModel->onTakeItem(item, count);
} }
} }

@ -29,8 +29,9 @@ namespace MWGui
/// Use ItemStack::Type for sorting? /// Use ItemStack::Type for sorting?
void setSortByType(bool sort) { mSortByType = sort; } void setSortByType(bool sort) { mSortByType = sort; }
bool onDropItem(const MWWorld::Ptr &item, int count) const; void onClose();
bool onTakeItem(const MWWorld::Ptr &item, int count) const; bool onDropItem(const MWWorld::Ptr &item, int count);
bool onTakeItem(const MWWorld::Ptr &item, int count);
static const int Category_Weapon = (1<<1); static const int Category_Weapon = (1<<1);
static const int Category_Apparel = (1<<2); static const int Category_Apparel = (1<<2);

Loading…
Cancel
Save