mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 16:15:36 +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:
parent
37e91a278e
commit
4fcf427e1f
2 changed files with 30 additions and 24 deletions
|
@ -145,10 +145,38 @@ namespace MWGui
|
||||||
|
|
||||||
const ItemStack& item = mTradeModel->getItem(index);
|
const ItemStack& item = mTradeModel->getItem(index);
|
||||||
|
|
||||||
unequipItem(item.mBase);
|
|
||||||
|
|
||||||
MWWorld::Ptr object = item.mBase;
|
MWWorld::Ptr object = item.mBase;
|
||||||
int count = item.mCount;
|
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();
|
bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
|
||||||
if (MyGUI::InputManager::getInstance().isControlPressed())
|
if (MyGUI::InputManager::getInstance().isControlPressed())
|
||||||
count = 1;
|
count = 1;
|
||||||
|
@ -375,27 +403,6 @@ namespace MWGui
|
||||||
return MWWorld::Ptr();
|
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()
|
void InventoryWindow::updateEncumbranceBar()
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
|
|
@ -103,7 +103,6 @@ namespace MWGui
|
||||||
void onAvatarClicked(MyGUI::Widget* _sender);
|
void onAvatarClicked(MyGUI::Widget* _sender);
|
||||||
void onPinToggled();
|
void onPinToggled();
|
||||||
|
|
||||||
void unequipItem(const MWWorld::Ptr& item);
|
|
||||||
void updateEncumbranceBar();
|
void updateEncumbranceBar();
|
||||||
void notifyContentChanged();
|
void notifyContentChanged();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue