Use ItemModel for moving items from a container to the world

Fixes owner not resetting when moving an item from a corpse to the world.
deque
scrawl 11 years ago
parent d70306382e
commit 940a434479

@ -354,15 +354,14 @@ namespace MWBase
virtual void update (float duration, bool paused) = 0;
virtual bool placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount) = 0;
virtual MWWorld::Ptr placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount) = 0;
///< copy and place an object into the gameworld at the specified cursor position
/// @param object
/// @param cursor X (relative 0-1)
/// @param cursor Y (relative 0-1)
/// @param number of objects to place
/// @return true if the object was placed, or false if it was rejected because the position is too far away
virtual void dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount) = 0;
virtual MWWorld::Ptr dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount) = 0;
///< copy and place an object into the gameworld at the given actor's position
/// @param actor giving the dropped object position
/// @param object

@ -91,7 +91,8 @@ namespace MWGui
mSourceModel->update();
finish();
targetView->update();
if (targetView)
targetView->update();
// We need to update the view since an other item could be auto-equipped.
mSourceView->update();

@ -17,9 +17,47 @@
#include "itemmodel.hpp"
#include "container.hpp"
#include "itemmodel.hpp"
namespace MWGui
{
/**
* Makes it possible to use ItemModel::moveItem to move an item from an inventory to the world.
*/
class WorldItemModel : public ItemModel
{
public:
WorldItemModel(float left, float top) : mLeft(left), mTop(top) {}
virtual ~WorldItemModel() {}
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
{
MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::Ptr dropped;
if (world->canPlaceObject(mLeft, mTop))
dropped = world->placeObject(item.mBase, mLeft, mTop, count);
else
dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count);
if (setNewOwner)
dropped.getCellRef().mOwner = "";
return dropped;
}
virtual void removeItem (const ItemStack& item, size_t count) { throw std::runtime_error("removeItem not implemented"); }
virtual ModelIndex getIndex (ItemStack item) { throw std::runtime_error("getIndex not implemented"); }
virtual void update() {}
virtual size_t getItemCount() { return 0; }
virtual ItemStack getItem (ModelIndex index) { throw std::runtime_error("getItem not implemented"); }
private:
// Where to drop the item
float mLeft;
float mTop;
};
HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
: Layout("openmw_hud.layout")
, mHealth(NULL)
@ -229,10 +267,6 @@ namespace MWGui
if (mDragAndDrop->mIsOnDragAndDrop)
{
// drop item into the gameworld
MWWorld::Ptr object = mDragAndDrop->mItem.mBase;
MWBase::World* world = MWBase::Environment::get().getWorld();
MWBase::Environment::get().getWorld()->breakInvisibility(
MWBase::Environment::get().getWorld()->getPlayerPtr());
@ -241,20 +275,10 @@ namespace MWGui
float mouseX = cursorPosition.left / float(viewSize.width);
float mouseY = cursorPosition.top / float(viewSize.height);
if (world->canPlaceObject(mouseX, mouseY))
world->placeObject(object, mouseX, mouseY, mDragAndDrop->mDraggedCount);
else
world->dropObjectOnGround(world->getPlayerPtr(), object, mDragAndDrop->mDraggedCount);
WorldItemModel drop (mouseX, mouseY);
mDragAndDrop->drop(&drop, NULL);
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
// remove object from the container it was coming from
mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
mDragAndDrop->finish();
mDragAndDrop->mSourceModel->update();
}
else
{

@ -1567,12 +1567,12 @@ namespace MWWorld
item.getRefData().getLocals().setVarByInt(script, "onpcdrop", 1);
}
bool World::placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount)
MWWorld::Ptr World::placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount)
{
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
if (!result.first)
return false;
return MWWorld::Ptr();
CellStore* cell = getPlayerPtr().getCell();
@ -1593,7 +1593,7 @@ namespace MWWorld
// only the player place items in the world, so no need to check actor
PCDropped(dropped);
return true;
return dropped;
}
bool World::canPlaceObject(float cursorX, float cursorY)
@ -1644,7 +1644,7 @@ namespace MWWorld
return dropped;
}
void World::dropObjectOnGround (const Ptr& actor, const Ptr& object, int amount)
MWWorld::Ptr World::dropObjectOnGround (const Ptr& actor, const Ptr& object, int amount)
{
MWWorld::CellStore* cell = actor.getCell();
@ -1673,6 +1673,7 @@ namespace MWWorld
if(actor == mPlayer->getPlayer()) // Only call if dropped by player
PCDropped(dropped);
return dropped;
}
void World::processChangedSettings(const Settings::CategorySettingVector& settings)

@ -439,15 +439,14 @@ namespace MWWorld
virtual void update (float duration, bool paused);
virtual bool placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount);
virtual MWWorld::Ptr placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount);
///< copy and place an object into the gameworld at the specified cursor position
/// @param object
/// @param cursor X (relative 0-1)
/// @param cursor Y (relative 0-1)
/// @param number of objects to place
/// @return true if the object was placed, or false if it was rejected because the position is too far away
virtual void dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount);
virtual MWWorld::Ptr dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount);
///< copy and place an object into the gameworld at the given actor's position
/// @param actor giving the dropped object position
/// @param object

Loading…
Cancel
Save