mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Move onDropItem() check to item models
This commit is contained in:
parent
3604b73d60
commit
ac33ff9482
@ -100,28 +100,10 @@ namespace MWGui
|
||||
|
||||
void ContainerWindow::dropItem()
|
||||
{
|
||||
if (mPtr.getTypeName() == typeid(ESM::Container).name())
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
bool success = mModel->onDropItem(mDragAndDrop->mItem.mBase, mDragAndDrop->mDraggedCount);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
mDragAndDrop->drop(mModel, mItemView);
|
||||
if (success)
|
||||
mDragAndDrop->drop(mModel, mItemView);
|
||||
}
|
||||
|
||||
void ContainerWindow::onBackgroundSelected()
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/world.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())
|
||||
return false;
|
||||
@ -196,7 +226,7 @@ bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
|
||||
// Looting a dead corpse is considered OK
|
||||
if (target.getClass().isActor() && target.getClass().getCreatureStats(target).isDead())
|
||||
return true;
|
||||
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item, target, count);
|
||||
|
||||
|
@ -18,6 +18,10 @@ namespace MWGui
|
||||
ContainerItemModel (const MWWorld::Ptr& source);
|
||||
|
||||
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 ModelIndex getIndex (ItemStack item);
|
||||
virtual size_t getItemCount();
|
||||
@ -26,7 +30,6 @@ namespace MWGui
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
|
||||
virtual void update();
|
||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
|
||||
|
||||
private:
|
||||
std::vector<MWWorld::Ptr> mItemSources;
|
||||
|
@ -124,7 +124,7 @@ bool InventoryItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
|
||||
// Looting a dead corpse is considered OK
|
||||
if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead())
|
||||
return true;
|
||||
|
||||
|
||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item, mActor, count);
|
||||
|
||||
|
@ -15,6 +15,8 @@ namespace MWGui
|
||||
virtual ModelIndex getIndex (ItemStack item);
|
||||
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 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 void update();
|
||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
|
||||
|
||||
protected:
|
||||
MWWorld::Ptr mActor;
|
||||
|
@ -129,7 +129,12 @@ namespace MWGui
|
||||
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;
|
||||
}
|
||||
@ -203,7 +208,12 @@ namespace MWGui
|
||||
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);
|
||||
}
|
||||
|
@ -75,7 +75,8 @@ namespace MWGui
|
||||
|
||||
/// Is the player allowed to insert items into this model? (default true)
|
||||
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:
|
||||
ItemModel(const ItemModel&);
|
||||
@ -92,10 +93,12 @@ 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 MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
virtual ModelIndex getIndex (ItemStack item);
|
||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
|
||||
|
||||
/// @note Takes ownership of the passed pointer.
|
||||
void setSourceModel(ItemModel* sourceModel);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <components/esm/loadskil.hpp>
|
||||
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/pickpocket.hpp"
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
@ -80,12 +81,21 @@ namespace MWGui
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
MWMechanics::Pickpocket pickpocket(player, mActor);
|
||||
if (pickpocket.pick(item, count))
|
||||
|
@ -18,6 +18,7 @@ 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;
|
||||
|
||||
protected:
|
||||
|
@ -311,7 +311,12 @@ namespace MWGui
|
||||
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);
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ namespace MWGui
|
||||
/// Use ItemStack::Type for sorting?
|
||||
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_Apparel = (1<<2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user