Skip to content

Commit

Permalink
Implement quick spell cycling
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed Dec 14, 2023
1 parent 2661fc2 commit 800e5e9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,33 @@ void SpellBookKeyPressed()
CloseInventory();
}

void CycleSpellHotkeys(bool next)
{
StaticVector<size_t, NumHotkeys> validHotKeyIndexes;
std::optional<size_t> currentIndex;
for (size_t slot = 0; slot < NumHotkeys; slot++) {
if (!IsValidSpeedSpell(slot))
continue;
if (MyPlayer->_pRSpell == MyPlayer->_pSplHotKey[slot] && MyPlayer->_pRSplType == MyPlayer->_pSplTHotKey[slot]) {
// found current
currentIndex = validHotKeyIndexes.size();
}
validHotKeyIndexes.emplace_back(slot);
}
if (validHotKeyIndexes.size() == 0)
return;

size_t newIndex;
if (!currentIndex) {
newIndex = next ? 0 : (validHotKeyIndexes.size() - 1);
} else if (next) {
newIndex = (*currentIndex == validHotKeyIndexes.size() - 1) ? 0 : (*currentIndex + 1);
} else {
newIndex = *currentIndex == 0 ? (validHotKeyIndexes.size() - 1) : (*currentIndex - 1);
}
ToggleSpell(validHotKeyIndexes[newIndex]);
}

bool IsPlayerDead()
{
return MyPlayer->_pmode == PM_DEATH || MyPlayerIsDead;
Expand Down Expand Up @@ -1678,6 +1705,22 @@ void InitKeymapActions()
CanPlayerTakeAction,
i + 1);
}
sgOptions.Keymapper.AddAction(
"QuickSpellPrevious",
N_("Previous quick spell"),
N_("Selects the previous quick spell (cycles)."),
MouseScrollUpButton,
[] { CycleSpellHotkeys(false); },
nullptr,
CanPlayerTakeAction);
sgOptions.Keymapper.AddAction(
"QuickSpellNext",
N_("Next quick spell"),
N_("Selects the next quick spell (cycles)."),
MouseScrollDownButton,
[] { CycleSpellHotkeys(true); },
nullptr,
CanPlayerTakeAction);
sgOptions.Keymapper.AddAction(
"UseHealthPotion",
N_("Use health potion"),
Expand Down

0 comments on commit 800e5e9

Please sign in to comment.