forked from teamnwah/openmw-tes3coop
Move onDropItem() check to item models
This commit is contained in:
parent
3604b73d60
commit
ac33ff9482
11 changed files with 79 additions and 33 deletions
|
@ -100,27 +100,9 @@ namespace MWGui
|
||||||
|
|
||||||
void ContainerWindow::dropItem()
|
void ContainerWindow::dropItem()
|
||||||
{
|
{
|
||||||
if (mPtr.getTypeName() == typeid(ESM::Container).name())
|
bool success = mModel->onDropItem(mDragAndDrop->mItem.mBase, mDragAndDrop->mDraggedCount);
|
||||||
{
|
|
||||||
// check container organic flag
|
|
||||||
MWWorld::LiveCellRef<ESM::Container>* ref = mPtr.get<ESM::Container>();
|
|
||||||
if (ref->mBase->mFlags & ESM::Container::Organic)
|
|
||||||
{
|
|
||||||
MWBase::Environment::get().getWindowManager()->
|
|
||||||
messageBox("#{sContentsMessage2}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that we don't exceed container capacity
|
|
||||||
MWWorld::Ptr item = mDragAndDrop->mItem.mBase;
|
|
||||||
float weight = item.getClass().getWeight(item) * mDragAndDrop->mDraggedCount;
|
|
||||||
if (mPtr.getClass().getCapacity(mPtr) < mPtr.getClass().getEncumbrance(mPtr) + weight)
|
|
||||||
{
|
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sContentsMessage3}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (success)
|
||||||
mDragAndDrop->drop(mModel, mItemView);
|
mDragAndDrop->drop(mModel, mItemView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/mechanicsmanager.hpp"
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/actorutil.hpp"
|
#include "../mwmechanics/actorutil.hpp"
|
||||||
|
@ -185,8 +186,37 @@ void ContainerItemModel::update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool ContainerItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
|
||||||
|
{
|
||||||
|
if (mItemSources.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
|
MWWorld::Ptr target = mItemSources[0];
|
||||||
|
|
||||||
|
if (target.getTypeName() != typeid(ESM::Container).name())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// check container organic flag
|
||||||
|
MWWorld::LiveCellRef<ESM::Container>* ref = target.get<ESM::Container>();
|
||||||
|
if (ref->mBase->mFlags & ESM::Container::Organic)
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->
|
||||||
|
messageBox("#{sContentsMessage2}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that we don't exceed container capacity
|
||||||
|
float weight = item.getClass().getWeight(item) * count;
|
||||||
|
if (target.getClass().getCapacity(target) < target.getClass().getEncumbrance(target) + weight)
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sContentsMessage3}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
||||||
{
|
{
|
||||||
if (mItemSources.empty())
|
if (mItemSources.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -18,6 +18,10 @@ namespace MWGui
|
||||||
ContainerItemModel (const MWWorld::Ptr& source);
|
ContainerItemModel (const MWWorld::Ptr& source);
|
||||||
|
|
||||||
virtual bool allowedToUseItems() const;
|
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 ItemStack getItem (ModelIndex index);
|
virtual ItemStack getItem (ModelIndex index);
|
||||||
virtual ModelIndex getIndex (ItemStack item);
|
virtual ModelIndex getIndex (ItemStack item);
|
||||||
virtual size_t getItemCount();
|
virtual size_t getItemCount();
|
||||||
|
@ -26,7 +30,6 @@ namespace MWGui
|
||||||
virtual void removeItem (const ItemStack& item, size_t count);
|
virtual void removeItem (const ItemStack& item, size_t count);
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<MWWorld::Ptr> mItemSources;
|
std::vector<MWWorld::Ptr> mItemSources;
|
||||||
|
|
|
@ -15,6 +15,8 @@ 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 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);
|
||||||
|
|
||||||
|
@ -22,7 +24,6 @@ namespace MWGui
|
||||||
virtual MWWorld::Ptr 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();
|
||||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MWWorld::Ptr mActor;
|
MWWorld::Ptr mActor;
|
||||||
|
|
|
@ -129,7 +129,12 @@ namespace MWGui
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
|
bool ItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +208,12 @@ namespace MWGui
|
||||||
mSourceModel = sourceModel;
|
mSourceModel = sourceModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProxyItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
|
bool ProxyItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
|
||||||
|
{
|
||||||
|
return mSourceModel->onDropItem (item, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProxyItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
||||||
{
|
{
|
||||||
return mSourceModel->onTakeItem (item, count);
|
return mSourceModel->onTakeItem (item, count);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,8 @@ 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 onTakeItem(const MWWorld::Ptr &item, int count);
|
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ItemModel(const ItemModel&);
|
ItemModel(const ItemModel&);
|
||||||
|
@ -92,10 +93,12 @@ namespace MWGui
|
||||||
|
|
||||||
bool allowedToUseItems() const;
|
bool allowedToUseItems() const;
|
||||||
|
|
||||||
|
virtual bool onDropItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
|
||||||
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);
|
||||||
virtual ModelIndex getIndex (ItemStack item);
|
virtual ModelIndex getIndex (ItemStack item);
|
||||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
|
|
||||||
|
|
||||||
/// @note Takes ownership of the passed pointer.
|
/// @note Takes ownership of the passed pointer.
|
||||||
void setSourceModel(ItemModel* sourceModel);
|
void setSourceModel(ItemModel* sourceModel);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <components/esm/loadskil.hpp>
|
#include <components/esm/loadskil.hpp>
|
||||||
|
|
||||||
#include "../mwmechanics/actorutil.hpp"
|
#include "../mwmechanics/actorutil.hpp"
|
||||||
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
#include "../mwmechanics/pickpocket.hpp"
|
#include "../mwmechanics/pickpocket.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
@ -80,12 +81,21 @@ namespace MWGui
|
||||||
|
|
||||||
bool PickpocketItemModel::allowedToInsertItems() const
|
bool PickpocketItemModel::allowedToInsertItems() const
|
||||||
{
|
{
|
||||||
// don't allow "reverse pickpocket" (yet)
|
// don't allow "reverse pickpocket" (it will be handled by scripts after 1.0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PickpocketItemModel::onDropItem(const MWWorld::Ptr &item, int count)
|
||||||
|
{
|
||||||
|
// don't allow "reverse pickpocket" (it will be handled by scripts after 1.0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PickpocketItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
bool PickpocketItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
||||||
{
|
{
|
||||||
|
if (mActor.getClass().getCreatureStats(mActor).getKnockedDown())
|
||||||
|
return mSourceModel->onTakeItem(item, 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))
|
||||||
|
|
|
@ -18,6 +18,7 @@ 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 bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -311,7 +311,12 @@ namespace MWGui
|
||||||
std::sort(mItems.begin(), mItems.end(), cmp);
|
std::sort(mItems.begin(), mItems.end(), cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SortFilterItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
|
bool SortFilterItemModel::onDropItem(const MWWorld::Ptr &item, int count) const
|
||||||
|
{
|
||||||
|
return mSourceModel->onDropItem (item, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SortFilterItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
||||||
{
|
{
|
||||||
return mSourceModel->onTakeItem (item, count);
|
return mSourceModel->onTakeItem (item, count);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@ 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 onTakeItem(const MWWorld::Ptr &item, int count);
|
bool onDropItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
||||||
|
|
||||||
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…
Reference in a new issue