mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-14 18:13:06 +00:00
Skip duplicate enchantments on Spell Cycle action
This commit is contained in:
parent
ecc9e8f5cd
commit
0a9c3ce96f
1 changed files with 42 additions and 13 deletions
|
|
@ -242,21 +242,50 @@ namespace MWGui
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer()));
|
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer()));
|
||||||
|
int itemCount = mSpellView->getModel()->getItemCount();
|
||||||
SpellModel::ModelIndex selected = mSpellView->getModel()->getSelectedIndex();
|
if (itemCount == 0)
|
||||||
if (selected < 0)
|
|
||||||
selected = 0;
|
|
||||||
|
|
||||||
selected += next ? 1 : -1;
|
|
||||||
int itemcount = mSpellView->getModel()->getItemCount();
|
|
||||||
if (itemcount == 0)
|
|
||||||
return;
|
return;
|
||||||
selected = (selected + itemcount) % itemcount;
|
|
||||||
|
|
||||||
const Spell& spell = mSpellView->getModel()->getItem(selected);
|
SpellModel::ModelIndex nextIndex;
|
||||||
if (spell.mType == Spell::Type_EnchantedItem)
|
SpellModel::ModelIndex currentIndex = mSpellView->getModel()->getSelectedIndex();
|
||||||
onEnchantedItemSelected(spell.mItem, spell.mActive);
|
|
||||||
|
// If we have a selected index, search for a valid selection in the target direction
|
||||||
|
if (currentIndex >= 0)
|
||||||
|
{
|
||||||
|
MWWorld::ContainerStore store;
|
||||||
|
const Spell& currentSpell = mSpellView->getModel()->getItem(currentIndex);
|
||||||
|
|
||||||
|
nextIndex = currentIndex;
|
||||||
|
for (int i = 0; i < itemCount; i++)
|
||||||
|
{
|
||||||
|
nextIndex += next ? 1 : -1;
|
||||||
|
nextIndex = (nextIndex + itemCount) % itemCount;
|
||||||
|
|
||||||
|
// We can keep this selection if:
|
||||||
|
// * we're not switching off of an enchanted item
|
||||||
|
// * we're not switching to an enchanted item
|
||||||
|
// * the next item wouldn't stack with the current item
|
||||||
|
if (currentSpell.mType != Spell::Type_EnchantedItem)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const Spell& nextSpell = mSpellView->getModel()->getItem(nextIndex);
|
||||||
|
if (nextSpell.mType != Spell::Type_EnchantedItem || !store.stacks(currentSpell.mItem, nextSpell.mItem))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Otherwise, the first selection is always index 0
|
||||||
else
|
else
|
||||||
onSpellSelected(spell.mId);
|
nextIndex = 0;
|
||||||
|
|
||||||
|
// Only trigger the selection event if the selection is actually changing.
|
||||||
|
// The itemCount check earlier ensures we have at least one spell to select.
|
||||||
|
if (nextIndex != currentIndex)
|
||||||
|
{
|
||||||
|
const Spell& selectedSpell = mSpellView->getModel()->getItem(nextIndex);
|
||||||
|
if (selectedSpell.mType == Spell::Type_EnchantedItem)
|
||||||
|
onEnchantedItemSelected(selectedSpell.mItem, selectedSpell.mActive);
|
||||||
|
else
|
||||||
|
onSpellSelected(selectedSpell.mId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue