mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
equipping items in the inventorywindow (there is no visual indication yet)
This commit is contained in:
parent
ab6336b745
commit
765881a61d
@ -144,24 +144,49 @@ namespace MWGui
|
|||||||
{
|
{
|
||||||
MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin();
|
MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin();
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action = MWWorld::Class::get(ptr).use(ptr);
|
// can the object be equipped?
|
||||||
|
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr);
|
||||||
// execute action and script
|
if (slots.first.empty())
|
||||||
MWBase::Environment::get().getWorld()->executeActionScript(ptr, action);
|
|
||||||
|
|
||||||
// this is necessary for books/scrolls: if they are already in the player's inventory,
|
|
||||||
// the "Take" button should not be visible.
|
|
||||||
// NOTE: the take button is "reset" when the window opens, so we can safely do the following
|
|
||||||
// without screwing up future book windows
|
|
||||||
if (mDragAndDrop->mWasInInventory)
|
|
||||||
{
|
{
|
||||||
mWindowManager.getBookWindow()->setTakeButtonShow(false);
|
// can't be equipped, try to use instead
|
||||||
mWindowManager.getScrollWindow()->setTakeButtonShow(false);
|
boost::shared_ptr<MWWorld::Action> action = MWWorld::Class::get(ptr).use(ptr);
|
||||||
|
|
||||||
|
// execute action and script
|
||||||
|
MWBase::Environment::get().getWorld()->executeActionScript(ptr, action);
|
||||||
|
|
||||||
|
// this is necessary for books/scrolls: if they are already in the player's inventory,
|
||||||
|
// the "Take" button should not be visible.
|
||||||
|
// NOTE: the take button is "reset" when the window opens, so we can safely do the following
|
||||||
|
// without screwing up future book windows
|
||||||
|
if (mDragAndDrop->mWasInInventory)
|
||||||
|
{
|
||||||
|
mWindowManager.getBookWindow()->setTakeButtonShow(false);
|
||||||
|
mWindowManager.getScrollWindow()->setTakeButtonShow(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// put back in inventory
|
||||||
|
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// put back in inventory
|
|
||||||
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
|
||||||
containerStore.add(ptr);
|
|
||||||
drawItems();
|
drawItems();
|
||||||
|
|
||||||
mDragAndDrop->mStore.clear();
|
mDragAndDrop->mStore.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user