mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-28 14:53:58 +00:00
Fixes #1334: Only unequip item if the sell/drag action is actually successful
This commit is contained in:
parent
510b7f8505
commit
6f03694d50
@ -176,35 +176,6 @@ namespace MWGui
|
|||||||
return;
|
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();
|
bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
|
||||||
if (MyGUI::InputManager::getInstance().isControlPressed())
|
if (MyGUI::InputManager::getInstance().isControlPressed())
|
||||||
count = 1;
|
count = 1;
|
||||||
@ -247,13 +218,46 @@ namespace MWGui
|
|||||||
notifyContentChanged();
|
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)
|
void InventoryWindow::dragItem(MyGUI::Widget* sender, int count)
|
||||||
{
|
{
|
||||||
|
ensureSelectedItemUnequipped();
|
||||||
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mTradeModel, mItemView, count);
|
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mTradeModel, mItemView, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryWindow::sellItem(MyGUI::Widget* sender, int count)
|
void InventoryWindow::sellItem(MyGUI::Widget* sender, int count)
|
||||||
{
|
{
|
||||||
|
ensureSelectedItemUnequipped();
|
||||||
const ItemStack& item = mTradeModel->getItem(mSelectedItem);
|
const ItemStack& item = mTradeModel->getItem(mSelectedItem);
|
||||||
std::string sound = MWWorld::Class::get(item.mBase).getDownSoundId(item.mBase);
|
std::string sound = MWWorld::Class::get(item.mBase).getDownSoundId(item.mBase);
|
||||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||||
|
@ -102,6 +102,9 @@ namespace MWGui
|
|||||||
void notifyContentChanged();
|
void notifyContentChanged();
|
||||||
|
|
||||||
void adjustPanes();
|
void adjustPanes();
|
||||||
|
|
||||||
|
/// Unequips mSelectedItem, if it is equipped, and then updates mSelectedItem in case it was re-stacked
|
||||||
|
void ensureSelectedItemUnequipped();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user