Move onClose() check to item models

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

@ -12,9 +12,7 @@
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/pickpocket.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "countdialog.hpp"
#include "inventorywindow.hpp"
@ -33,7 +31,6 @@ namespace MWGui
ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop)
: WindowBase("openmw_container_window.layout")
, mDragAndDrop(dragAndDrop)
, mPickpocketDetected(false)
, mSortModel(NULL)
, mModel(NULL)
, mSelectedItem(-1)
@ -114,7 +111,6 @@ namespace MWGui
void ContainerWindow::setPtr(const MWWorld::Ptr& container)
{
mPickpocketDetected = false;
mPtr = container;
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
@ -159,24 +155,7 @@ namespace MWGui
{
WindowBase::onClose();
if (dynamic_cast<PickpocketItemModel*>(mModel)
// 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;
}
}
mModel->onClose();
}
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
@ -252,7 +231,6 @@ namespace MWGui
bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
{
// TODO: mPickpocketDetected = true;
return mModel->onTakeItem(item.mBase, count);
}

@ -44,8 +44,6 @@ namespace MWGui
private:
DragAndDrop* mDragAndDrop;
bool mPickpocketDetected;
MWGui::ItemView* mItemView;
SortFilterItemModel* mSortModel;
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())
return false;
@ -216,7 +216,7 @@ bool ContainerItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
return true;
}
bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
if (mItemSources.empty())
return false;

@ -19,8 +19,8 @@ namespace MWGui
virtual bool allowedToUseItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const;
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 ItemStack getItem (ModelIndex index);
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
if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead())

@ -15,7 +15,7 @@ namespace MWGui
virtual ModelIndex getIndex (ItemStack item);
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 void removeItem (const ItemStack& item, size_t count);

@ -129,12 +129,12 @@ namespace MWGui
return true;
}
bool ItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
bool ItemModel::onDropItem(const MWWorld::Ptr &item, int count)
{
return true;
}
bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
return true;
}
@ -208,13 +208,18 @@ namespace MWGui
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)
virtual bool allowedToInsertItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const;
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
virtual void onClose()
{
}
virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
private:
ItemModel(const ItemModel&);
@ -93,8 +96,9 @@ namespace MWGui
bool allowedToUseItems() const;
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const;
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
virtual void onClose();
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 void removeItem (const ItemStack& item, size_t count);

@ -17,7 +17,7 @@ namespace MWGui
{
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, ItemModel *sourceModel, bool hideItems)
: mActor(actor)
: mActor(actor), mPickpocketDetected(false)
{
MWWorld::Ptr player = MWMechanics::getPlayer();
mSourceModel = sourceModel;
@ -91,11 +91,35 @@ namespace MWGui
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())
return mSourceModel->onTakeItem(item, count);
return stealItem(item, count);
}
bool PickpocketItemModel::stealItem(const MWWorld::Ptr &item, int count)
{
MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::Pickpocket pickpocket(player, mActor);
if (pickpocket.pick(item, count))
@ -103,6 +127,7 @@ namespace MWGui
MWBase::Environment::get().getMechanicsManager()->commitCrime(
player, mActor, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
mPickpocketDetected = true;
return false;
}
else

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

@ -311,13 +311,18 @@ namespace MWGui
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?
void setSortByType(bool sort) { mSortByType = sort; }
bool onDropItem(const MWWorld::Ptr &item, int count) const;
bool onTakeItem(const MWWorld::Ptr &item, int count) const;
void onClose();
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_Apparel = (1<<2);

Loading…
Cancel
Save