Skip to content

Commit

Permalink
Make belt_item_type in to an enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo committed Sep 18, 2024
1 parent 6396af1 commit 974f517
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,10 +1587,10 @@ void ProcessGameAction(const GameAction &action)
case GameActionType_SEND_KEY:
break;
case GameActionType_USE_HEALTH_POTION:
UseBeltItem(BLT_HEALING);
UseBeltItem(BeltItemType::Healing);
break;
case GameActionType_USE_MANA_POTION:
UseBeltItem(BLT_MANA);
UseBeltItem(BeltItemType::Mana);
break;
case GameActionType_PRIMARY_ACTION:
PerformPrimaryAction();
Expand Down Expand Up @@ -1782,7 +1782,7 @@ void plrctrls_after_game_logic()
Movement(*MyPlayer);
}

void UseBeltItem(int type)
void UseBeltItem(BeltItemType type)
{
for (int i = 0; i < MaxBeltItems; i++) {
Item &item = MyPlayer->SpdList[i];
Expand All @@ -1794,7 +1794,7 @@ void UseBeltItem(int type)
bool isHealing = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_HEAL, IMISC_FULLHEAL) || item.isScrollOf(SpellID::Healing);
bool isMana = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_MANA, IMISC_FULLMANA);

if ((type == BLT_HEALING && isHealing) || (type == BLT_MANA && isMana)) {
if ((type == BeltItemType::Healing && isHealing) || (type == BeltItemType::Mana && isMana)) {
UseInvItem(INVITEM_BELT_FIRST + i);
break;
}
Expand Down
10 changes: 5 additions & 5 deletions Source/controls/plrctrls.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace devilution {

typedef enum belt_item_type : uint8_t {
BLT_HEALING,
BLT_MANA,
} belt_item_type;
enum class BeltItemType : uint8_t {
Healing,
Mana,
};

enum class ControlTypes : uint8_t {
None,
Expand Down Expand Up @@ -68,7 +68,7 @@ bool IsMovementHandlerActive();
void DetectInputMethod(const SDL_Event &event, const ControllerButtonEvent &gamepadEvent);
void ProcessGameAction(const GameAction &action);

void UseBeltItem(int type);
void UseBeltItem(BeltItemType type);

// Talk to towners, click on inv items, attack, etc.
void PerformPrimaryAction();
Expand Down
4 changes: 2 additions & 2 deletions Source/controls/touch/renderers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ std::optional<VirtualGamepadPotionType> PotionButtonRenderer::GetPotionType()
continue;
}

if (potionType == BLT_HEALING) {
if (potionType == BeltItemType::Healing) {
if (item._iMiscId == IMISC_HEAL)
return GAMEPAD_HEALING;
if (item._iMiscId == IMISC_FULLHEAL)
Expand All @@ -391,7 +391,7 @@ std::optional<VirtualGamepadPotionType> PotionButtonRenderer::GetPotionType()
return GAMEPAD_SCROLL_OF_HEALING;
}

if (potionType == BLT_MANA) {
if (potionType == BeltItemType::Mana) {
if (item._iMiscId == IMISC_MANA)
return GAMEPAD_MANA;
if (item._iMiscId == IMISC_FULLMANA)
Expand Down
8 changes: 4 additions & 4 deletions Source/controls/touch/renderers.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class CancelButtonRenderer : public VirtualPadButtonRenderer {

class PotionButtonRenderer : public VirtualPadButtonRenderer {
public:
PotionButtonRenderer(VirtualPadButton *potionButton, belt_item_type potionType)
PotionButtonRenderer(VirtualPadButton *potionButton, BeltItemType potionType)
: VirtualPadButtonRenderer(potionButton)
, potionType(potionType)
{
Expand All @@ -192,7 +192,7 @@ class PotionButtonRenderer : public VirtualPadButtonRenderer {
void RenderPotion(RenderFunction renderFunction, const ButtonTexture &potionArt);

private:
belt_item_type potionType;
BeltItemType potionType;

VirtualGamepadButtonType GetButtonType();
std::optional<VirtualGamepadPotionType> GetPotionType();
Expand All @@ -208,8 +208,8 @@ class VirtualGamepadRenderer {
, secondaryActionButtonRenderer(&virtualGamepad->secondaryActionButton)
, spellActionButtonRenderer(&virtualGamepad->spellActionButton)
, cancelButtonRenderer(&virtualGamepad->cancelButton)
, healthButtonRenderer(&virtualGamepad->healthButton, BLT_HEALING)
, manaButtonRenderer(&virtualGamepad->manaButton, BLT_MANA)
, healthButtonRenderer(&virtualGamepad->healthButton, BeltItemType::Healing)
, manaButtonRenderer(&virtualGamepad->manaButton, BeltItemType::Mana)
{
}

Expand Down
8 changes: 4 additions & 4 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,15 +1727,15 @@ void InitKeymapActions()
N_("Use health potion"),
N_("Use health potions from belt."),
SDLK_UNKNOWN,
[] { UseBeltItem(BLT_HEALING); },
[] { UseBeltItem(BeltItemType::Healing); },
nullptr,
CanPlayerTakeAction);
sgOptions.Keymapper.AddAction(
"UseManaPotion",
N_("Use mana potion"),
N_("Use mana potions from belt."),
SDLK_UNKNOWN,
[] { UseBeltItem(BLT_MANA); },
[] { UseBeltItem(BeltItemType::Mana); },
nullptr,
CanPlayerTakeAction);
sgOptions.Keymapper.AddAction(
Expand Down Expand Up @@ -2131,15 +2131,15 @@ void InitPadmapActions()
N_("Use health potion"),
N_("Use health potions from belt."),
ControllerButton_BUTTON_LEFTSHOULDER,
[] { UseBeltItem(BLT_HEALING); },
[] { UseBeltItem(BeltItemType::Healing); },
nullptr,
CanPlayerTakeAction);
sgOptions.Padmapper.AddAction(
"UseManaPotion",
N_("Use mana potion"),
N_("Use mana potions from belt."),
ControllerButton_BUTTON_RIGHTSHOULDER,
[] { UseBeltItem(BLT_MANA); },
[] { UseBeltItem(BeltItemType::Mana); },
nullptr,
CanPlayerTakeAction);
sgOptions.Padmapper.AddAction(
Expand Down

0 comments on commit 974f517

Please sign in to comment.