1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 10:49:57 +00:00
openmw-tes3mp/apps/openmw/mwgui/itemmodel.cpp
Emanuel Guevel 1e4a854433 Remove static method MWWorld::Class::get(&Ptr)
It was just adding a level of indirection to Ptr.getClass().
All the call were replaced by that instead. The number of lines changed
is important, but the change itself is trivial, so everything should be
fine. :)
2014-05-22 20:50:00 +02:00

126 lines
3.7 KiB
C++

#include "itemmodel.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
namespace MWGui
{
ItemStack::ItemStack(const MWWorld::Ptr &base, ItemModel *creator, size_t count)
: mCreator(creator)
, mCount(count)
, mFlags(0)
, mType(Type_Normal)
, mBase(base)
{
if (base.getClass().getEnchantment(base) != "")
mFlags |= Flag_Enchanted;
}
ItemStack::ItemStack()
: mCreator(NULL)
, mCount(0)
, mFlags(0)
, mType(Type_Normal)
{
}
bool ItemStack::stacks(const ItemStack &other)
{
if(mBase == other.mBase)
return true;
// If one of the items is in an inventory and currently equipped, we need to check stacking both ways to be sure
if (mBase.getContainerStore() && other.mBase.getContainerStore())
return mBase.getContainerStore()->stacks(mBase, other.mBase)
&& other.mBase.getContainerStore()->stacks(mBase, other.mBase);
if (mBase.getContainerStore())
return mBase.getContainerStore()->stacks(mBase, other.mBase);
if (other.mBase.getContainerStore())
return other.mBase.getContainerStore()->stacks(mBase, other.mBase);
MWWorld::ContainerStore store;
return store.stacks(mBase, other.mBase);
}
bool operator == (const ItemStack& left, const ItemStack& right)
{
if (left.mType != right.mType)
return false;
if(left.mBase == right.mBase)
return true;
// If one of the items is in an inventory and currently equipped, we need to check stacking both ways to be sure
if (left.mBase.getContainerStore() && right.mBase.getContainerStore())
return left.mBase.getContainerStore()->stacks(left.mBase, right.mBase)
&& right.mBase.getContainerStore()->stacks(left.mBase, right.mBase);
if (left.mBase.getContainerStore())
return left.mBase.getContainerStore()->stacks(left.mBase, right.mBase);
if (right.mBase.getContainerStore())
return right.mBase.getContainerStore()->stacks(left.mBase, right.mBase);
MWWorld::ContainerStore store;
return store.stacks(left.mBase, right.mBase);
}
ItemModel::ItemModel()
{
}
MWWorld::Ptr ItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)
{
MWWorld::Ptr ret = otherModel->copyItem(item, count);
removeItem(item, count);
return ret;
}
ProxyItemModel::~ProxyItemModel()
{
delete mSourceModel;
}
MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{
return mSourceModel->copyItem (item, count, setNewOwner);
}
void ProxyItemModel::removeItem (const ItemStack& item, size_t count)
{
mSourceModel->removeItem (item, count);
}
ItemModel::ModelIndex ProxyItemModel::mapToSource (ModelIndex index)
{
const ItemStack& itemToSearch = getItem(index);
for (size_t i=0; i<mSourceModel->getItemCount(); ++i)
{
const ItemStack& item = mSourceModel->getItem(i);
if (item == itemToSearch)
return i;
}
return -1;
}
ItemModel::ModelIndex ProxyItemModel::mapFromSource (ModelIndex index)
{
const ItemStack& itemToSearch = mSourceModel->getItem(index);
for (size_t i=0; i<getItemCount(); ++i)
{
const ItemStack& item = getItem(i);
if (item == itemToSearch)
return i;
}
return -1;
}
ItemModel::ModelIndex ProxyItemModel::getIndex (ItemStack item)
{
return mSourceModel->getIndex(item);
}
}