From 974f517fd946c5671df4234761c7f3ea0a928f63 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 27 Mar 2022 22:01:10 +0200 Subject: [PATCH] Make belt_item_type in to an enum class --- Source/controls/plrctrls.cpp | 8 ++++---- Source/controls/plrctrls.h | 10 +++++----- Source/controls/touch/renderers.cpp | 4 ++-- Source/controls/touch/renderers.h | 8 ++++---- Source/diablo.cpp | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 6bc065c21cd..1f586ffca1d 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -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(); @@ -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]; @@ -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; } diff --git a/Source/controls/plrctrls.h b/Source/controls/plrctrls.h index b433d12d17e..bc220c2e8bd 100644 --- a/Source/controls/plrctrls.h +++ b/Source/controls/plrctrls.h @@ -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, @@ -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(); diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 24a87cb3c20..5790a299ecf 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -382,7 +382,7 @@ std::optional PotionButtonRenderer::GetPotionType() continue; } - if (potionType == BLT_HEALING) { + if (potionType == BeltItemType::Healing) { if (item._iMiscId == IMISC_HEAL) return GAMEPAD_HEALING; if (item._iMiscId == IMISC_FULLHEAL) @@ -391,7 +391,7 @@ std::optional 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) diff --git a/Source/controls/touch/renderers.h b/Source/controls/touch/renderers.h index 8b8ccd4adb1..0cfb54aef43 100644 --- a/Source/controls/touch/renderers.h +++ b/Source/controls/touch/renderers.h @@ -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) { @@ -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 GetPotionType(); @@ -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) { } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 8e483b27afb..ee39fa8b4aa 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1727,7 +1727,7 @@ 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( @@ -1735,7 +1735,7 @@ void InitKeymapActions() N_("Use mana potion"), N_("Use mana potions from belt."), SDLK_UNKNOWN, - [] { UseBeltItem(BLT_MANA); }, + [] { UseBeltItem(BeltItemType::Mana); }, nullptr, CanPlayerTakeAction); sgOptions.Keymapper.AddAction( @@ -2131,7 +2131,7 @@ 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( @@ -2139,7 +2139,7 @@ void InitPadmapActions() N_("Use mana potion"), N_("Use mana potions from belt."), ControllerButton_BUTTON_RIGHTSHOULDER, - [] { UseBeltItem(BLT_MANA); }, + [] { UseBeltItem(BeltItemType::Mana); }, nullptr, CanPlayerTakeAction); sgOptions.Padmapper.AddAction(