From 271740a2bc7b9eceea3dc444598dc88f0ef34fba Mon Sep 17 00:00:00 2001 From: staphen Date: Sat, 25 Sep 2021 19:22:11 -0400 Subject: [PATCH] Fix case for blank virtual gamepad potion buttons --- Source/controls/touch/renderers.cpp | 11 ++++++++--- Source/controls/touch/renderers.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 7bb51d34b..884a785e2 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -253,8 +253,11 @@ void VirtualPadButtonRenderer::Render(RenderFunction renderFunction, Art &button void PotionButtonRenderer::RenderPotion(RenderFunction renderFunction, Art &potionArt) { - VirtualGamepadPotionType potionType = GetPotionType(); - int frame = potionType; + std::optional potionType = GetPotionType(); + if (potionType == std::nullopt) + return; + + int frame = *potionType; int offset = potionArt.h() * frame; auto center = virtualPadButton->area.position; @@ -271,7 +274,7 @@ void PotionButtonRenderer::RenderPotion(RenderFunction renderFunction, Art &poti renderFunction(potionArt, &src, &dst); } -VirtualGamepadPotionType PotionButtonRenderer::GetPotionType() +std::optional PotionButtonRenderer::GetPotionType() { for (int i = 0; i < MAXBELTITEMS; i++) { auto &myPlayer = Players[MyPlayerId]; @@ -302,6 +305,8 @@ VirtualGamepadPotionType PotionButtonRenderer::GetPotionType() if (id == IMISC_FULLREJUV) return GAMEPAD_FULL_REJUVENATION; } + + return std::nullopt; } VirtualGamepadButtonType PrimaryActionButtonRenderer::GetButtonType() diff --git a/Source/controls/touch/renderers.h b/Source/controls/touch/renderers.h index c9200774c..8af22142f 100644 --- a/Source/controls/touch/renderers.h +++ b/Source/controls/touch/renderers.h @@ -135,7 +135,7 @@ private: belt_item_type potionType; VirtualGamepadButtonType GetButtonType(); - VirtualGamepadPotionType GetPotionType(); + std::optional GetPotionType(); }; class VirtualGamepadRenderer {