1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-24 11:56:36 +00:00

Remove uses of std::variant and std::holds_alternative because they're not supported on Ubuntu

This commit is contained in:
Andrew Lanzone 2025-07-31 22:22:21 -07:00
parent 666f154082
commit f453ce27a0
2 changed files with 50 additions and 34 deletions

View file

@ -9,30 +9,36 @@
namespace MWGui
{
static constexpr ControllerButtonsOverlay::ButtonDefinition sButtonDefs[] = {
{ ControllerButtonsOverlay::Button::Button_A, "A", SDL_CONTROLLER_BUTTON_A, &ControllerButtons::mA },
{ ControllerButtonsOverlay::Button::Button_B, "B", SDL_CONTROLLER_BUTTON_B, &ControllerButtons::mB },
{ ControllerButtonsOverlay::Button::Button_Dpad, "Dpad", SDL_CONTROLLER_BUTTON_DPAD_UP,
&ControllerButtons::mDpad },
{ ControllerButtonsOverlay::Button::Button_L1, "L1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
&ControllerButtons::mL1 },
{ ControllerButtonsOverlay::Button::Button_L2, "L2", SDL_CONTROLLER_AXIS_TRIGGERLEFT, &ControllerButtons::mL2 },
{ ControllerButtonsOverlay::Button::Button_L3, "L3", SDL_CONTROLLER_BUTTON_LEFTSTICK, &ControllerButtons::mL3 },
{ ControllerButtonsOverlay::Button::Button_LStick, "LStick", SDL_CONTROLLER_AXIS_LEFTY,
&ControllerButtons::mLStick },
{ ControllerButtonsOverlay::Button::Button_Menu, "Menu", SDL_CONTROLLER_BUTTON_BACK,
&ControllerButtons::mMenu },
{ ControllerButtonsOverlay::Button::Button_R1, "R1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
&ControllerButtons::mR1 },
{ ControllerButtonsOverlay::Button::Button_R2, "R2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
&ControllerButtons::mR2 },
{ ControllerButtonsOverlay::Button::Button_R3, "R3", SDL_CONTROLLER_BUTTON_RIGHTSTICK,
&ControllerButtons::mR3 },
{ ControllerButtonsOverlay::Button::Button_RStick, "RStick", SDL_CONTROLLER_AXIS_RIGHTY,
&ControllerButtons::mRStick },
{ ControllerButtonsOverlay::Button::Button_View, "View", SDL_CONTROLLER_BUTTON_START,
&ControllerButtons::mView },
{ ControllerButtonsOverlay::Button::Button_X, "X", SDL_CONTROLLER_BUTTON_X, &ControllerButtons::mX },
{ ControllerButtonsOverlay::Button::Button_Y, "Y", SDL_CONTROLLER_BUTTON_Y, &ControllerButtons::mY },
{ ControllerButtonsOverlay::Button::Button_A, "A", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_A }, &ControllerButtons::mA },
{ ControllerButtonsOverlay::Button::Button_B, "B", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_B }, &ControllerButtons::mB },
{ ControllerButtonsOverlay::Button::Button_Dpad, "Dpad", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_DPAD_UP }, &ControllerButtons::mDpad },
{ ControllerButtonsOverlay::Button::Button_L1, "L1", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER }, &ControllerButtons::mL1 },
{ ControllerButtonsOverlay::Button::Button_L2, "L2", ControllerButtonsOverlay::InputType_Axis,
{ .mAxis = SDL_CONTROLLER_AXIS_TRIGGERLEFT }, &ControllerButtons::mL2 },
{ ControllerButtonsOverlay::Button::Button_L3, "L3", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_LEFTSTICK }, &ControllerButtons::mL3 },
{ ControllerButtonsOverlay::Button::Button_LStick, "LStick", ControllerButtonsOverlay::InputType_Axis,
{ .mAxis = SDL_CONTROLLER_AXIS_LEFTY }, &ControllerButtons::mLStick },
{ ControllerButtonsOverlay::Button::Button_Menu, "Menu", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_BACK }, &ControllerButtons::mMenu },
{ ControllerButtonsOverlay::Button::Button_R1, "R1", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER }, &ControllerButtons::mR1 },
{ ControllerButtonsOverlay::Button::Button_R2, "R2", ControllerButtonsOverlay::InputType_Axis,
{ .mAxis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT }, &ControllerButtons::mR2 },
{ ControllerButtonsOverlay::Button::Button_R3, "R3", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_RIGHTSTICK }, &ControllerButtons::mR3 },
{ ControllerButtonsOverlay::Button::Button_RStick, "RStick", ControllerButtonsOverlay::InputType_Axis,
{ .mAxis = SDL_CONTROLLER_AXIS_RIGHTY }, &ControllerButtons::mRStick },
{ ControllerButtonsOverlay::Button::Button_View, "View", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_START }, &ControllerButtons::mView },
{ ControllerButtonsOverlay::Button::Button_X, "X", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_X }, &ControllerButtons::mX },
{ ControllerButtonsOverlay::Button::Button_Y, "Y", ControllerButtonsOverlay::InputType_Button,
{ .mButton = SDL_CONTROLLER_BUTTON_Y }, &ControllerButtons::mY },
};
ControllerButtonsOverlay::ControllerButtonsOverlay()
@ -45,12 +51,11 @@ namespace MWGui
getWidget(mButtons[i].mImage, "Btn" + sButtonDefs[i].mName + "Image");
getWidget(mButtons[i].mText, "Btn" + sButtonDefs[i].mName + "Text");
getWidget(mButtons[i].mHBox, "Btn" + sButtonDefs[i].mName);
if (std::holds_alternative<SDL_GameControllerAxis>(sButtonDefs[i].mId))
setIcon(mButtons[i].mImage,
inputMgr->getControllerAxisIcon(std::get<SDL_GameControllerAxis>(sButtonDefs[i].mId)));
if (sButtonDefs[i].mInputType == InputType_Axis)
setIcon(mButtons[i].mImage, inputMgr->getControllerAxisIcon(sButtonDefs[i].mId.mAxis));
else
setIcon(mButtons[i].mImage,
inputMgr->getControllerButtonIcon(std::get<SDL_GameControllerButton>(sButtonDefs[i].mId)));
setIcon(mButtons[i].mImage, inputMgr->getControllerButtonIcon(sButtonDefs[i].mId.mButton));
}
getWidget(mHBox, "ButtonBox");

View file

@ -38,24 +38,35 @@ namespace MWGui
Button_Max,
};
enum InputType
{
InputType_Button,
InputType_Axis
};
struct ButtonDefinition
{
Button mButton;
std::string mName;
std::variant<SDL_GameControllerButton, SDL_GameControllerAxis> mId;
InputType mInputType;
union {
SDL_GameControllerButton mButton;
SDL_GameControllerAxis mAxis;
} mId;
std::string MWGui::ControllerButtons::*mField;
};
private:
struct ButtonWidgets
{
MyGUI::ImageBox* mImage = nullptr;
MyGUI::TextBox* mText = nullptr;
Gui::HBox* mHBox = nullptr;
MyGUI::ImageBox* mImage;
MyGUI::TextBox* mText;
Gui::HBox* mHBox;
ButtonWidgets() : mImage(nullptr), mText(nullptr), mHBox(nullptr) {}
};
std::array<ButtonWidgets, Button::Button_Max> mButtons;
Gui::HBox* mHBox;
void setIcon(MyGUI::ImageBox* image, const std::string& imagePath);