1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

equipping items in the inventorywindow (there is no visual indication yet)

This commit is contained in:
scrawl 2012-05-15 18:20:32 +02:00
parent ab6336b745
commit 765881a61d

View File

@ -144,6 +144,11 @@ namespace MWGui
{ {
MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin(); MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin();
// can the object be equipped?
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr);
if (slots.first.empty())
{
// can't be equipped, try to use instead
boost::shared_ptr<MWWorld::Action> action = MWWorld::Class::get(ptr).use(ptr); boost::shared_ptr<MWWorld::Action> action = MWWorld::Class::get(ptr).use(ptr);
// execute action and script // execute action and script
@ -162,6 +167,26 @@ namespace MWGui
// put back in inventory // put back in inventory
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
containerStore.add(ptr); containerStore.add(ptr);
}
else
{
// put back in inventory
MWWorld::InventoryStore& invStore = static_cast<MWWorld::InventoryStore&>(MWWorld::Class::get(mContainer).getContainerStore(mContainer));
invStore.add(ptr);
// get a ContainerStoreIterator to the item we just re-added into the inventory
MWWorld::ContainerStoreIterator it = invStore.begin();
MWWorld::ContainerStoreIterator nextIt = ++it;
while (nextIt != invStore.end())
{
++it;
++nextIt;
}
// equip the item in the first available slot
invStore.equip(slots.first.front(), it);
}
drawItems(); drawItems();
mDragAndDrop->mStore.clear(); mDragAndDrop->mStore.clear();