1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-17 21:46:38 +00:00

Automatically show Xbox, PS, or Switch button icons

This commit is contained in:
Andy Lanzone 2025-07-04 14:38:55 -07:00
parent b29850f4c6
commit ffec2e8d74
27 changed files with 198 additions and 4 deletions

View file

@ -79,6 +79,8 @@ namespace MWBase
/// @return true if joystick, false otherwise
virtual bool joystickLastUsed() = 0;
virtual void setJoystickLastUsed(bool enabled) = 0;
virtual std::string getControllerButtonIcon(int button) = 0;
virtual std::string getControllerAxisIcon(int axis) = 0;
virtual int countSavedGameRecords() const = 0;
virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) = 0;

View file

@ -1,6 +1,7 @@
#include "controllerbuttonsoverlay.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui
@ -8,50 +9,67 @@ namespace MWGui
ControllerButtonsOverlay::ControllerButtonsOverlay()
: WindowBase("openmw_controllerbuttons.layout")
{
MWBase::InputManager* inputMgr = MWBase::Environment::get().getInputManager();
getWidget(mImageA, "BtnAImage");
getWidget(mTextA, "BtnAText");
setIcon(mImageA, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_A));
getWidget(mImageB, "BtnBImage");
getWidget(mTextB, "BtnBText");
setIcon(mImageB, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_B));
getWidget(mImageDpad, "BtnDpadImage");
getWidget(mTextDpad, "BtnDpadText");
setIcon(mImageDpad, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_DPAD_UP));
getWidget(mImageL1, "BtnL1Image");
getWidget(mTextL1, "BtnL1Text");
setIcon(mImageL1, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
getWidget(mImageL2, "BtnL2Image");
getWidget(mTextL2, "BtnL2Text");
setIcon(mImageL2, inputMgr->getControllerAxisIcon(SDL_CONTROLLER_AXIS_TRIGGERLEFT));
getWidget(mImageL3, "BtnL3Image");
getWidget(mTextL3, "BtnL3Text");
setIcon(mImageL3, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_LEFTSTICK));
getWidget(mImageLStick, "BtnLStickImage");
getWidget(mTextLStick, "BtnLStickText");
setIcon(mImageLStick, inputMgr->getControllerAxisIcon(SDL_CONTROLLER_AXIS_LEFTY));
getWidget(mImageMenu, "BtnMenuImage");
getWidget(mTextMenu, "BtnMenuText");
setIcon(mImageMenu, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_BACK));
getWidget(mImageR1, "BtnR1Image");
getWidget(mTextR1, "BtnR1Text");
setIcon(mImageR1, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
getWidget(mImageR2, "BtnR2Image");
getWidget(mTextR2, "BtnR2Text");
setIcon(mImageR2, inputMgr->getControllerAxisIcon(SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
getWidget(mImageR3, "BtnR3Image");
getWidget(mTextR3, "BtnR3Text");
setIcon(mImageR3, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_RIGHTSTICK));
getWidget(mImageRStick, "BtnRStickImage");
getWidget(mTextRStick, "BtnRStickText");
setIcon(mImageRStick, inputMgr->getControllerAxisIcon(SDL_CONTROLLER_AXIS_RIGHTY));
getWidget(mImageView, "BtnViewImage");
getWidget(mTextView, "BtnViewText");
setIcon(mImageView, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_START));
getWidget(mImageX, "BtnXImage");
getWidget(mTextX, "BtnXText");
setIcon(mImageX, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_X));
getWidget(mImageY, "BtnYImage");
getWidget(mTextY, "BtnYText");
setIcon(mImageY, inputMgr->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_Y));
getWidget(mHBox, "ButtonBox");
}
@ -79,6 +97,12 @@ namespace MWGui
setVisible(buttonCount > 0);
}
void ControllerButtonsOverlay::setIcon(MyGUI::ImageBox* image, const std::string& imagePath)
{
if (imagePath.length() > 0)
image->setImageTexture(imagePath);
}
int ControllerButtonsOverlay::updateButton(
MyGUI::TextBox* text, MyGUI::ImageBox* image, const std::string& buttonStr)
{

View file

@ -65,6 +65,7 @@ namespace MWGui
Gui::HBox* mHBox;
void setIcon(MyGUI::ImageBox* image, const std::string& imagePath);
int updateButton(MyGUI::TextBox* text, MyGUI::ImageBox* image, const std::string& buttonStr);
};
}

View file

@ -1,6 +1,9 @@
#include "inventorytabsoverlay.hpp"
#include <MyGUI_ImageBox.h>
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui
@ -25,6 +28,15 @@ namespace MWGui
getWidget(tab, "TabStats");
tab->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryTabsOverlay::onTabClicked);
mTabs.push_back(tab);
MyGUI::ImageBox* image;
getWidget(image, "BtnL2Image");
image->setImageTexture(
MWBase::Environment::get().getInputManager()->getControllerAxisIcon(SDL_CONTROLLER_AXIS_TRIGGERLEFT));
getWidget(image, "BtnR2Image");
image->setImageTexture(
MWBase::Environment::get().getInputManager()->getControllerAxisIcon(SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
}
void InventoryTabsOverlay::onTabClicked(MyGUI::Widget* sender)

View file

@ -19,6 +19,7 @@
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
@ -133,14 +134,18 @@ namespace MWGui
if (Settings::gui().mControllerMenus)
{
// Show L1 and R1 buttons next to tabs
MyGUI::Widget* image;
MyGUI::ImageBox* image;
getWidget(image, "BtnL1Image");
image->setVisible(true);
image->setUserString("Hidden", "false");
image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
getWidget(image, "BtnR1Image");
image->setVisible(true);
image->setUserString("Hidden", "false");
image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
mControllerButtons.r3 = "#{sInfo}";
}

View file

@ -3,6 +3,7 @@
#include <MyGUI_Button.h>
#include <MyGUI_ControllerManager.h>
#include <MyGUI_ControllerRepeatClick.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_InputManager.h>
#include <components/misc/rng.hpp>
@ -11,6 +12,7 @@
#include "../mwbase/dialoguemanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
@ -172,14 +174,18 @@ namespace MWGui
if (Settings::gui().mControllerMenus)
{
// Show L1 and R1 buttons next to tabs
MyGUI::Widget* image;
MyGUI::ImageBox* image;
getWidget(image, "BtnL1Image");
image->setVisible(true);
image->setUserString("Hidden", "false");
image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
getWidget(image, "BtnR1Image");
image->setVisible(true);
image->setUserString("Hidden", "false");
image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
mControllerButtons.a = "#{sBuy}";
mControllerButtons.b = "#{sCancel}";

View file

@ -465,6 +465,120 @@ namespace MWInput
return std::array<float, 3>({ gyro[0], gyro[1], gyro[2] });
}
int ControllerManager::getControllerType()
{
int type = 0;
#if SDL_VERSION_ATLEAST(2, 0, 12)
SDL_GameController* cntrl = mBindingsManager->getControllerOrNull();
if (cntrl)
type = SDL_GameControllerGetType(cntrl);
#endif
return type;
}
std::string ControllerManager::getControllerButtonIcon(int button)
{
int controllerType = ControllerManager::getControllerType();
bool isXbox = false;
bool isPsx = false;
bool isSwitch = false;
#if SDL_VERSION_ATLEAST(2, 0, 12)
isXbox = controllerType == SDL_CONTROLLER_TYPE_XBOX360 || controllerType == SDL_CONTROLLER_TYPE_XBOXONE;
isPsx = controllerType == SDL_CONTROLLER_TYPE_PS3 || controllerType == SDL_CONTROLLER_TYPE_PS4
|| controllerType == SDL_CONTROLLER_TYPE_PS5;
isSwitch = controllerType == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
#endif
switch (button)
{
case SDL_CONTROLLER_BUTTON_A:
if (isPsx)
return "textures/omw_psx_button_x.dds";
return "textures/omw_steam_button_a.dds";
case SDL_CONTROLLER_BUTTON_B:
if (isPsx)
return "textures/omw_psx_button_circle.dds";
return "textures/omw_steam_button_b.dds";
case SDL_CONTROLLER_BUTTON_BACK:
return "textures/omw_steam_button_view.dds";
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
case SDL_CONTROLLER_BUTTON_DPAD_UP:
if (isPsx)
return "textures/omw_psx_button_dpad.dds";
return "textures/omw_steam_button_dpad.dds";
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
if (isXbox)
return "textures/omw_xbox_button_lb.dds";
else if (isSwitch)
return "textures/omw_switch_button_l.dds";
return "textures/omw_steam_button_l1.dds";
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
return "textures/omw_steam_button_l3.dds";
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
if (isXbox)
return "textures/omw_xbox_button_rb.dds";
else if (isSwitch)
return "textures/omw_switch_button_r.dds";
return "textures/omw_steam_button_r1.dds";
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
return "textures/omw_steam_button_r3.dds";
case SDL_CONTROLLER_BUTTON_START:
return "textures/omw_steam_button_menu.dds";
case SDL_CONTROLLER_BUTTON_X:
if (isPsx)
return "textures/omw_psx_button_square.dds";
return "textures/omw_steam_button_x.dds";
case SDL_CONTROLLER_BUTTON_Y:
if (isPsx)
return "textures/omw_psx_button_triangle.dds";
return "textures/omw_steam_button_y.dds";
case SDL_CONTROLLER_BUTTON_GUIDE:
default:
return "";
}
}
std::string ControllerManager::getControllerAxisIcon(int axis)
{
int controllerType = ControllerManager::getControllerType();
bool isXbox = false;
bool isSwitch = false;
#if SDL_VERSION_ATLEAST(2, 0, 12)
isXbox = controllerType == SDL_CONTROLLER_TYPE_XBOX360 || controllerType == SDL_CONTROLLER_TYPE_XBOXONE;
isSwitch = controllerType == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
#endif
switch (axis)
{
case SDL_CONTROLLER_AXIS_LEFTX:
case SDL_CONTROLLER_AXIS_LEFTY:
return "textures/omw_steam_button_lstick.dds";
case SDL_CONTROLLER_AXIS_RIGHTX:
case SDL_CONTROLLER_AXIS_RIGHTY:
return "textures/omw_steam_button_rstick.dds";
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
if (isXbox)
return "textures/omw_xbox_button_lt.dds";
else if (isSwitch)
return "textures/omw_switch_button_zl.dds";
return "textures/omw_steam_button_l2.dds";
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
if (isXbox)
return "textures/omw_xbox_button_rt.dds";
else if (isSwitch)
return "textures/omw_switch_button_zr.dds";
return "textures/omw_steam_button_r2.dds";
default:
return "";
}
}
void ControllerManager::touchpadMoved(int deviceId, const SDLUtil::TouchEvent& arg)
{
MWBase::Environment::get().getLuaManager()->inputEvent({ MWBase::LuaManager::InputEvent::TouchMoved, arg });

View file

@ -48,6 +48,9 @@ namespace MWInput
bool isGyroAvailable() const;
std::array<float, 3> getGyroValues() const;
std::string getControllerButtonIcon(int button);
std::string getControllerAxisIcon(int axis);
private:
// Return true if GUI consumes input.
bool gamepadToGuiControl(const SDL_ControllerButtonEvent& arg);
@ -55,6 +58,8 @@ namespace MWInput
void enableGyroSensor();
int getControllerType();
BindingsManager* mBindingsManager;
MouseManager* mMouseManager;

View file

@ -249,6 +249,16 @@ namespace MWInput
return mControllerManager->joystickLastUsed();
}
std::string InputManager::getControllerButtonIcon(int button)
{
return mControllerManager->getControllerButtonIcon(button);
}
std::string InputManager::getControllerAxisIcon(int axis)
{
return mControllerManager->getControllerAxisIcon(axis);
}
void InputManager::executeAction(int action)
{
mActionManager->executeAction(action);

View file

@ -92,6 +92,8 @@ namespace MWInput
void setJoystickLastUsed(bool enabled) override;
bool joystickLastUsed() override;
std::string getControllerButtonIcon(int button) override;
std::string getControllerAxisIcon(int axis) override;
int countSavedGameRecords() const override;
void write(ESM::ESMWriter& writer, Loading::Listener& progress) override;

View file

@ -10,6 +10,11 @@ set(BUILTIN_DATA_FILES
textures/omw_menu_scroll_center_h.dds
textures/omw_menu_scroll_center_v.dds
textures/omw_menu_icon_active.dds
textures/omw_psx_button_circle.dds
textures/omw_psx_button_dpad.dds
textures/omw_psx_button_square.dds
textures/omw_psx_button_triangle.dds
textures/omw_psx_button_x.dds
textures/omw_steam_button_a.dds
textures/omw_steam_button_b.dds
textures/omw_steam_button_dpad.dds
@ -25,6 +30,14 @@ set(BUILTIN_DATA_FILES
textures/omw_steam_button_view.dds
textures/omw_steam_button_x.dds
textures/omw_steam_button_y.dds
textures/omw_switch_button_l.dds
textures/omw_switch_button_r.dds
textures/omw_switch_button_zl.dds
textures/omw_switch_button_zr.dds
textures/omw_xbox_button_lb.dds
textures/omw_xbox_button_lt.dds
textures/omw_xbox_button_rb.dds
textures/omw_xbox_button_rt.dds
textures/omw/water_nm.png
fonts/DejaVuFontLicense.txt

View file

@ -10,7 +10,7 @@
<Widget type="Spacer"/>
<Widget type="ImageBox" skin="ImageBox" align="Stretch" position="0 0 24 24">
<Widget type="ImageBox" skin="ImageBox" align="Stretch" position="0 0 24 24" name="BtnL2Image">
<Property key="ImageTexture" value="textures\omw_steam_button_l2.dds"/>
<Property key="Colour" value="#ccb589"/>
<Property key="Alpha" value="0.7"/>
@ -39,7 +39,7 @@
<Property key="TextShadow" value="true"/>
<Property key="TextShadowColour" value="0 0 0"/>
</Widget>
<Widget type="ImageBox" skin="ImageBox" align="Stretch" position="0 0 24 24">
<Widget type="ImageBox" skin="ImageBox" align="Stretch" position="0 0 24 24" name="BtnR2Image">
<Property key="ImageTexture" value="textures\omw_steam_button_r2.dds"/>
<Property key="Colour" value="#ccb589"/>
<Property key="Alpha" value="0.7"/>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.