Browse Source

Fix case for blank virtual gamepad potion buttons

pull/2951/head
staphen 5 years ago committed by Anders Jenbo
parent
commit
271740a2bc
  1. 11
      Source/controls/touch/renderers.cpp
  2. 2
      Source/controls/touch/renderers.h

11
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<VirtualGamepadPotionType> 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<VirtualGamepadPotionType> 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()

2
Source/controls/touch/renderers.h

@ -135,7 +135,7 @@ private:
belt_item_type potionType;
VirtualGamepadButtonType GetButtonType();
VirtualGamepadPotionType GetPotionType();
std::optional<VirtualGamepadPotionType> GetPotionType();
};
class VirtualGamepadRenderer {

Loading…
Cancel
Save