1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 06:53:53 +00:00

InventoryWindow: call InventoryStore::unequipItem() when an equipped item is dragged

The unequipped item is also re-stacked if needed.
This commit is contained in:
Emanuel Guevel 2013-11-01 00:20:33 +01:00
parent 37e91a278e
commit 4fcf427e1f
2 changed files with 30 additions and 24 deletions

View file

@ -145,10 +145,38 @@ namespace MWGui
const ItemStack& item = mTradeModel->getItem(index);
unequipItem(item.mBase);
MWWorld::Ptr object = item.mBase;
int count = item.mCount;
if (item.mType == ItemStack::Type_Equipped)
{
MWWorld::InventoryStore& invStore = MWWorld::Class::get(mPtr).getInventoryStore(mPtr);
MWWorld::Ptr newStack = *invStore.unequipItem(item.mBase, mPtr);
// The unequipped item was re-stacked. We have to update the index
// since the item pointed does not exist anymore.
if (item.mBase != newStack)
{
// newIndex will store the index of the ItemStack the item was stacked on
int newIndex = -1;
for (size_t i=0; i < mTradeModel->getItemCount(); ++i)
{
if (mTradeModel->getItem(i).mBase == newStack)
{
newIndex = i;
break;
}
}
if (newIndex == -1)
throw std::runtime_error("Can't find restacked item");
index = newIndex;
object = mTradeModel->getItem(index).mBase;
}
}
bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
if (MyGUI::InputManager::getInstance().isControlPressed())
count = 1;
@ -375,27 +403,6 @@ namespace MWGui
return MWWorld::Ptr();
}
void InventoryWindow::unequipItem(const MWWorld::Ptr& item)
{
MWWorld::InventoryStore& invStore = MWWorld::Class::get(mPtr).getInventoryStore(mPtr);
for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
if (it != invStore.end() && *it == item)
{
invStore.equip(slot, invStore.end(), mPtr);
std::string script = MWWorld::Class::get(*it).getScript(*it);
// Unset OnPCEquip Variable on item's script, if it has a script with that variable declared
if(script != "")
(*it).getRefData().getLocals().setVarByInt(script, "onpcequip", 0);
return;
}
}
}
void InventoryWindow::updateEncumbranceBar()
{
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();

View file

@ -103,7 +103,6 @@ namespace MWGui
void onAvatarClicked(MyGUI::Widget* _sender);
void onPinToggled();
void unequipItem(const MWWorld::Ptr& item);
void updateEncumbranceBar();
void notifyContentChanged();
};