fixes based on comments by ptmikheev

revert-6246b479
Mads Buvik Sandvei 1 year ago
parent e22eec0585
commit b8a9fcad68

@ -53,15 +53,6 @@ namespace MWGui
return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, allowAutoEquip);
}
MWWorld::Ptr InventoryItemModel::unstackItem(const ItemStack& item, size_t count)
{
MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor);
auto it = store.unstack(item.mBase, count);
if (it != store.end())
return *it;
return MWWorld::Ptr();
}
void InventoryItemModel::removeItem(const ItemStack& item, size_t count)
{
int removed = 0;

@ -18,7 +18,6 @@ namespace MWGui
bool onTakeItem(const MWWorld::Ptr& item, int count) override;
MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override;
MWWorld::Ptr unstackItem(const ItemStack& item, size_t count) override;
void removeItem(const ItemStack& item, size_t count) override;
/// Move items from this model to \a otherModel.

@ -67,16 +67,11 @@ namespace MWGui
ret.getCellRef().unsetRefNum();
ret.getRefData().setLuaScripts(nullptr);
MWBase::Environment::get().getWorldModel()->registerPtr(ret);
MWBase::Environment::get().getWorldModel()->registerPtr(item.mBase);
}
return ret;
}
MWWorld::Ptr ItemModel::unstackItem(const ItemStack& item, size_t count)
{
// By default does nothing
return MWWorld::Ptr();
}
bool ItemModel::allowedToUseItems() const
{
return true;
@ -151,11 +146,6 @@ namespace MWGui
return mSourceModel->onTakeItem(item, count);
}
MWWorld::Ptr ProxyItemModel::unstackItem(const ItemStack& item, size_t count)
{
return mSourceModel->unstackItem(item, count);
}
MWWorld::Ptr ProxyItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip)
{
return mSourceModel->addItem(item, count, allowAutoEquip);

@ -66,10 +66,6 @@ namespace MWGui
virtual MWWorld::Ptr moveItem(
const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip = true);
/// Unstacks items from this model and returns a ptr to the new remainder stack.
/// @note Returns en empty ptr if there is no remainder or the item model does not support unstacking.
virtual MWWorld::Ptr unstackItem(const ItemStack& item, size_t count);
virtual MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) = 0;
virtual void removeItem(const ItemStack& item, size_t count) = 0;
@ -100,7 +96,6 @@ namespace MWGui
bool onDropItem(const MWWorld::Ptr& item, int count) override;
bool onTakeItem(const MWWorld::Ptr& item, int count) override;
MWWorld::Ptr unstackItem(const ItemStack& item, size_t count) override;
MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override;
void removeItem(const ItemStack& item, size_t count) override;
ModelIndex getIndex(const ItemStack& item) override;

@ -391,10 +391,20 @@ namespace MWWorld
return newPtr;
}
Ptr Class::moveToCell(const Ptr& ptr, CellStore& cell, const ESM::Position& pos, int count) const
{
Ptr newPtr = moveToCell(ptr, cell);
newPtr.getRefData().setPosition(pos);
newPtr.getCellRef().setPosition(pos);
newPtr.getRefData().setCount(count);
return newPtr;
}
MWWorld::Ptr Class::copyToCell(const ConstPtr& ptr, CellStore& cell, const ESM::Position& pos, int count) const
{
Ptr newPtr = copyToCell(ptr, cell, count);
newPtr.getRefData().setPosition(pos);
newPtr.getCellRef().setPosition(pos);
return newPtr;
}

@ -317,6 +317,7 @@ namespace MWWorld
// The original is expected to be removed after calling this function,
// but this function itself doesn't remove the original.
virtual Ptr moveToCell(const Ptr& ptr, CellStore& cell) const;
Ptr moveToCell(const Ptr& ptr, CellStore& cell, const ESM::Position& pos, int count) const;
Ptr copyToCell(const ConstPtr& ptr, CellStore& cell, const ESM::Position& pos, int count) const;

@ -2063,7 +2063,7 @@ namespace MWWorld
MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count);
addObjectToCell(dropped, cell, pos, adjustPos);
initObjectInCell(dropped, *cell, adjustPos);
return dropped;
}
@ -2079,30 +2079,16 @@ namespace MWWorld
cell = &mWorldModel.getExterior(index);
}
MWWorld::Ptr dropped = object.getClass().moveToCell(object, *cell);
dropped.getRefData().setCount(count);
dropped.getRefData().setPosition(pos);
MWWorld::Ptr dropped = object.getClass().moveToCell(object, *cell, pos, count);
addObjectToCell(dropped, cell, pos, adjustPos);
initObjectInCell(dropped, *cell, adjustPos);
return dropped;
}
void World::addObjectToCell(const Ptr& object, CellStore* cell, ESM::Position pos, bool adjustPos)
void World::initObjectInCell(const Ptr& object, CellStore& cell, bool adjustPos)
{
if (!cell)
throw std::runtime_error("addObjectToCell(): cannot add object to null cell");
if (cell->isExterior())
{
const ESM::ExteriorCellLocation index
= ESM::positionToExteriorCellLocation(pos.pos[0], pos.pos[1], cell->getCell()->getWorldSpace());
cell = &mWorldModel.getExterior(index);
}
// Reset some position values that could be uninitialized if this item came from a container
object.getCellRef().setPosition(pos);
if (mWorldScene->isCellActive(*cell))
if (mWorldScene->isCellActive(cell))
{
if (object.getRefData().isEnabled())
{
@ -2113,7 +2099,7 @@ namespace MWWorld
{
mLocalScripts.add(script, object);
}
addContainerScripts(object, cell);
addContainerScripts(object, &cell);
}
if (!object.getClass().isActor() && adjustPos && object.getRefData().getBaseNode())
@ -2125,6 +2111,7 @@ namespace MWWorld
osg::BoundingBox bounds = computeBounds.getBoundingBox();
if (bounds.valid())
{
ESM::Position pos = object.getRefData().getPosition();
bounds.set(bounds._min - pos.asVec3(), bounds._max - pos.asVec3());
osg::Vec3f adjust(

@ -143,7 +143,7 @@ namespace MWWorld
void updateWeather(float duration, bool paused = false);
void addObjectToCell(const Ptr& ptr, CellStore* cell, ESM::Position pos, bool adjustPos);
void initObjectInCell(const Ptr& ptr, CellStore& cell, bool adjustPos);
Ptr moveObjectToCell(const Ptr& ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos);
Ptr copyObjectToCell(const ConstPtr& ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos);

Loading…
Cancel
Save