forked from teamnwah/openmw-tes3coop
Fixes #1334: Only unequip item if the sell/drag action is actually successful
This commit is contained in:
parent
510b7f8505
commit
6f03694d50
2 changed files with 36 additions and 29 deletions
|
@ -176,35 +176,6 @@ namespace MWGui
|
|||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -247,13 +218,46 @@ namespace MWGui
|
|||
notifyContentChanged();
|
||||
}
|
||||
|
||||
void InventoryWindow::ensureSelectedItemUnequipped()
|
||||
{
|
||||
const ItemStack& item = mTradeModel->getItem(mSelectedItem);
|
||||
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");
|
||||
|
||||
mSelectedItem = newIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryWindow::dragItem(MyGUI::Widget* sender, int count)
|
||||
{
|
||||
ensureSelectedItemUnequipped();
|
||||
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mTradeModel, mItemView, count);
|
||||
}
|
||||
|
||||
void InventoryWindow::sellItem(MyGUI::Widget* sender, int count)
|
||||
{
|
||||
ensureSelectedItemUnequipped();
|
||||
const ItemStack& item = mTradeModel->getItem(mSelectedItem);
|
||||
std::string sound = MWWorld::Class::get(item.mBase).getDownSoundId(item.mBase);
|
||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||
|
|
|
@ -102,6 +102,9 @@ namespace MWGui
|
|||
void notifyContentChanged();
|
||||
|
||||
void adjustPanes();
|
||||
|
||||
/// Unequips mSelectedItem, if it is equipped, and then updates mSelectedItem in case it was re-stacked
|
||||
void ensureSelectedItemUnequipped();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue