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

View file

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