1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 17:45:32 +00:00

dropping items works

This commit is contained in:
scrawl 2012-05-14 17:41:17 +02:00
parent 6c9f75b322
commit d3e162ec83
7 changed files with 119 additions and 49 deletions

View file

@ -184,6 +184,8 @@ void ContainerBase::drawItems()
MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label"));
text->setTextAlign(MyGUI::Align::Right);
text->setNeedMouseFocus(false);
text->setTextShadow(true);
text->setTextShadowColour(MyGUI::Colour(0,0,0));
y += 42;
if (y > maxHeight)

View file

@ -41,7 +41,6 @@ namespace MWGui
MyGUI::Widget* mDraggedWidget;
MyGUI::Widget* mDragAndDropWidget;
MWWorld::ContainerStore mStore;
MWWorld::Ptr mItem;
};
class ContainerBase

View file

@ -7,6 +7,10 @@
#include <boost/lexical_cast.hpp>
#include "../mwbase/environment.hpp"
#include "../mwsound/soundmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/world.hpp"
#include "../mwworld/player.hpp"
#include "window_manager.hpp"
#include "container.hpp"
@ -255,7 +259,21 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender)
if (mDragAndDrop->mIsOnDragAndDrop)
{
// drop item into the gameworld
MWWorld::Ptr object = *mDragAndDrop->mStore.begin();
float* playerPos;
playerPos = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getRefData().getPosition().pos;
MWWorld::Ptr::CellStore* cell = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell(); /// \todo this might be a different cell
ESM::Position& pos = object.getRefData().getPosition();
pos.pos[0] = playerPos[0];
pos.pos[1] = playerPos[1];
pos.pos[2] = playerPos[2];
MWBase::Environment::get().getWorld()->insertObject(object, cell);
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
mDragAndDrop->mStore.clear();
mDragAndDrop->mIsOnDragAndDrop = false;

View file

@ -15,39 +15,40 @@
#include "cellfunctors.hpp"
namespace {
template<typename T>
void insertCellRefList(MWRender::RenderingManager& rendering,
T& cellRefList, ESMS::CellStore<MWWorld::RefData> &cell, MWWorld::PhysicsSystem& physics)
namespace
{
if (!cellRefList.list.empty())
template<typename T>
void insertCellRefList(MWRender::RenderingManager& rendering,
T& cellRefList, ESMS::CellStore<MWWorld::RefData> &cell, MWWorld::PhysicsSystem& physics)
{
const MWWorld::Class& class_ =
MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell));
for (typename T::List::iterator it = cellRefList.list.begin();
it != cellRefList.list.end(); it++)
if (!cellRefList.list.empty())
{
if (it->mData.getCount() || it->mData.isEnabled())
{
MWWorld::Ptr ptr (&*it, &cell);
const MWWorld::Class& class_ =
MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell));
try
for (typename T::List::iterator it = cellRefList.list.begin();
it != cellRefList.list.end(); it++)
{
if (it->mData.getCount() || it->mData.isEnabled())
{
rendering.addObject(ptr);
class_.insertObject(ptr, physics);
class_.enable (ptr);
}
catch (const std::exception& e)
{
std::string error ("error during rendering: ");
std::cerr << error + e.what() << std::endl;
MWWorld::Ptr ptr (&*it, &cell);
try
{
rendering.addObject(ptr);
class_.insertObject(ptr, physics);
class_.enable (ptr);
}
catch (const std::exception& e)
{
std::string error ("error during rendering: ");
std::cerr << error + e.what() << std::endl;
}
}
}
}
}
}
}
@ -300,30 +301,68 @@ namespace MWWorld
mCellChanged = false;
}
void Scene::insertCell(ESMS::CellStore<MWWorld::RefData> &cell)
{
// Loop through all references in the cell
insertCellRefList(mRendering, cell.activators, cell, *mPhysics);
insertCellRefList(mRendering, cell.potions, cell, *mPhysics);
insertCellRefList(mRendering, cell.appas, cell, *mPhysics);
insertCellRefList(mRendering, cell.armors, cell, *mPhysics);
insertCellRefList(mRendering, cell.books, cell, *mPhysics);
insertCellRefList(mRendering, cell.clothes, cell, *mPhysics);
insertCellRefList(mRendering, cell.containers, cell, *mPhysics);
insertCellRefList(mRendering, cell.creatures, cell, *mPhysics);
insertCellRefList(mRendering, cell.doors, cell, *mPhysics);
insertCellRefList(mRendering, cell.ingreds, cell, *mPhysics);
insertCellRefList(mRendering, cell.creatureLists, cell, *mPhysics);
insertCellRefList(mRendering, cell.itemLists, cell, *mPhysics);
insertCellRefList(mRendering, cell.lights, cell, *mPhysics);
insertCellRefList(mRendering, cell.lockpicks, cell, *mPhysics);
insertCellRefList(mRendering, cell.miscItems, cell, *mPhysics);
insertCellRefList(mRendering, cell.npcs, cell, *mPhysics);
insertCellRefList(mRendering, cell.probes, cell, *mPhysics);
insertCellRefList(mRendering, cell.repairs, cell, *mPhysics);
insertCellRefList(mRendering, cell.statics, cell, *mPhysics);
insertCellRefList(mRendering, cell.weapons, cell, *mPhysics);
}
void Scene::insertCell(ESMS::CellStore<MWWorld::RefData> &cell)
{
// Loop through all references in the cell
insertCellRefList(mRendering, cell.activators, cell, *mPhysics);
insertCellRefList(mRendering, cell.potions, cell, *mPhysics);
insertCellRefList(mRendering, cell.appas, cell, *mPhysics);
insertCellRefList(mRendering, cell.armors, cell, *mPhysics);
insertCellRefList(mRendering, cell.books, cell, *mPhysics);
insertCellRefList(mRendering, cell.clothes, cell, *mPhysics);
insertCellRefList(mRendering, cell.containers, cell, *mPhysics);
insertCellRefList(mRendering, cell.creatures, cell, *mPhysics);
insertCellRefList(mRendering, cell.doors, cell, *mPhysics);
insertCellRefList(mRendering, cell.ingreds, cell, *mPhysics);
insertCellRefList(mRendering, cell.creatureLists, cell, *mPhysics);
insertCellRefList(mRendering, cell.itemLists, cell, *mPhysics);
insertCellRefList(mRendering, cell.lights, cell, *mPhysics);
insertCellRefList(mRendering, cell.lockpicks, cell, *mPhysics);
insertCellRefList(mRendering, cell.miscItems, cell, *mPhysics);
insertCellRefList(mRendering, cell.npcs, cell, *mPhysics);
insertCellRefList(mRendering, cell.probes, cell, *mPhysics);
insertCellRefList(mRendering, cell.repairs, cell, *mPhysics);
insertCellRefList(mRendering, cell.statics, cell, *mPhysics);
insertCellRefList(mRendering, cell.weapons, cell, *mPhysics);
}
void Scene::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell)
{
ptr.mCell = cell;
mRendering.addObject(ptr);
MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics);
MWWorld::Class::get(ptr).enable(ptr);
std::string type = ptr.getTypeName();
// insert into the correct CellRefList
if (type == typeid(ESM::Potion).name())
cell->potions.list.push_back( *ptr.get<ESM::Potion>() );
else if (type == typeid(ESM::Apparatus).name())
cell->appas.list.push_back( *ptr.get<ESM::Apparatus>() );
else if (type == typeid(ESM::Armor).name())
cell->armors.list.push_back( *ptr.get<ESM::Armor>() );
else if (type == typeid(ESM::Book).name())
cell->books.list.push_back( *ptr.get<ESM::Book>() );
else if (type == typeid(ESM::Clothing).name())
cell->clothes.list.push_back( *ptr.get<ESM::Clothing>() );
else if (type == typeid(ESM::Ingredient).name())
cell->ingreds.list.push_back( *ptr.get<ESM::Ingredient>() );
else if (type == typeid(ESM::Light).name())
cell->lights.list.push_back( *ptr.get<ESM::Light>() );
else if (type == typeid(ESM::Tool).name())
cell->lockpicks.list.push_back( *ptr.get<ESM::Tool>() );
else if (type == typeid(ESM::Repair).name())
cell->repairs.list.push_back( *ptr.get<ESM::Repair>() );
else if (type == typeid(ESM::Probe).name())
cell->probes.list.push_back( *ptr.get<ESM::Probe>() );
else if (type == typeid(ESM::Weapon).name())
cell->weapons.list.push_back( *ptr.get<ESM::Weapon>() );
else if (type == typeid(ESM::Miscellaneous).name())
cell->miscItems.list.push_back( *ptr.get<ESM::Miscellaneous>() );
else
throw std::runtime_error("Trying to insert object of unhandled type");
}
}

View file

@ -100,6 +100,10 @@ namespace MWWorld
void insertCell(ESMS::CellStore<MWWorld::RefData> &cell);
/// this method is only meant for dropping objects into the gameworld from a container
/// and thus only handles object types that can be placed in a container
void insertObject(MWWorld::Ptr object, Ptr::CellStore* cell);
void update (float duration);
};
}

View file

@ -948,4 +948,9 @@ namespace MWWorld
mRendering->toggleWater();
}
void World::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell)
{
mWorldScene->insertObject(ptr, cell);
}
}

View file

@ -263,6 +263,9 @@ namespace MWWorld
void update (float duration);
void insertObject (MWWorld::Ptr ptr, Ptr::CellStore* cell);
///< insert object in a given cell
/// \note this method is only meant for dropping items into the gameworld from a container
};
}