1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-06 13:15:33 +00:00

Fix weapon cycle getting stuck for same item IDs

This commit is contained in:
scrawl 2014-12-15 17:38:32 +01:00
parent 935cccf974
commit c7e1c0b595

View file

@ -615,13 +615,14 @@ namespace MWGui
void InventoryWindow::cycle(bool next)
{
ItemModel::ModelIndex selected = 0;
ItemModel::ModelIndex selected = -1;
// not using mSortFilterModel as we only need sorting, not filtering
SortFilterItemModel model(new InventoryItemModel(MWBase::Environment::get().getWorld()->getPlayerPtr()));
model.setSortByType(false);
model.update();
if (model.getItemCount() == 0)
return;
for (ItemModel::ModelIndex i=0; i<int(model.getItemCount()); ++i)
{
MWWorld::Ptr item = model.getItem(i).mBase;
@ -631,6 +632,9 @@ namespace MWGui
int incr = next ? 1 : -1;
bool found = false;
std::string lastId;
if (selected != -1)
lastId = model.getItem(selected).mBase.getCellRef().getRefId();
ItemModel::ModelIndex cycled = selected;
while (!found)
{
@ -638,11 +642,18 @@ namespace MWGui
cycled = (cycled + model.getItemCount()) % model.getItemCount();
MWWorld::Ptr item = model.getItem(cycled).mBase;
if (item.getClass().getTypeName() == typeid(ESM::Weapon).name() && isRightHandWeapon(item))
found = true;
if (cycled == selected) // we've been through all items, nothing found
return;
// skip different stacks of the same item, or we will get stuck as stacking/unstacking them may change their relative ordering
if (Misc::StringUtils::ciEqual(lastId, item.getCellRef().getRefId()))
continue;
lastId = item.getCellRef().getRefId();
if (item.getClass().getTypeName() == typeid(ESM::Weapon).name() && isRightHandWeapon(item))
found = true;
}
useItem(model.getItem(cycled).mBase);