33#include " components/ComponentGrid.h"
44#include " components/ImageComponent.h"
55#include " components/TextComponent.h"
6- #include " resources/TextureResource.h"
76#include " utils/StringUtil.h"
87#include " Log.h"
98#include " Settings.h"
9+ #include " InputManager.h"
1010
1111#define OFFSET_X 12 // move the entire thing right by this amount (px)
1212#define OFFSET_Y 12 // move the entire thing up by this amount (px)
1313
1414#define ICON_TEXT_SPACING 8 // space between [icon] and [text] (px)
1515#define ENTRY_SPACING 16 // space between [text] and next [icon] (px)
1616
17- static const std::map<std::string, const char *> ICON_PATH_MAP {
17+ static const HelpComponent::IconPathMap DEFAULT_ICON_PATH_MAP {
1818 { " up/down" , " :/help/dpad_updown.svg" },
1919 { " left/right" , " :/help/dpad_leftright.svg" },
2020 { " up/down/left/right" , " :/help/dpad_all.svg" },
@@ -29,6 +29,20 @@ static const std::map<std::string, const char*> ICON_PATH_MAP {
2929 { " select" , " :/help/button_select.svg" }
3030};
3131
32+ static const HelpComponent::IconPathMap NO_ICON_OVERRIDES {};
33+ static const HelpComponent::IconPathMap XBOX_ICON_OVERRIDES {
34+ { " a" , " :/help/button_b.svg" },
35+ { " b" , " :/help/button_a.svg" },
36+ { " x" , " :/help/button_y.svg" },
37+ { " y" , " :/help/button_x.svg" },
38+ };
39+ static const HelpComponent::IconPathMap PLAYSTATION_ICON_OVERRIDES {
40+ { " a" , " :/help/button_circle.svg" },
41+ { " b" , " :/help/button_x.svg" },
42+ { " x" , " :/help/button_triangle.svg" },
43+ { " y" , " :/help/button_square.svg" },
44+ };
45+
3246HelpComponent::HelpComponent (Window* window) : GuiComponent(window)
3347{
3448}
@@ -67,12 +81,15 @@ void HelpComponent::updateGrid()
6781 std::vector< std::shared_ptr<ImageComponent> > icons;
6882 std::vector< std::shared_ptr<TextComponent> > labels;
6983
84+ const auto & iconOverrides =
85+ getIconOverridesForInput (InputManager::getInstance ()->getInputConfigForLastUsedDevice ());
86+
7087 float width = 0 ;
7188 const float height = Math::round (font->getLetterHeight () * 1 .25f );
7289 for (auto it = mPrompts .cbegin (); it != mPrompts .cend (); it++)
7390 {
7491 auto icon = std::make_shared<ImageComponent>(mWindow );
75- icon->setImage (getIconTexture (it->first . c_str () ));
92+ icon->setImage (getIconTexture (it->first , iconOverrides ));
7693 icon->setColorShift (mStyle .iconColor );
7794 icon->setResize (0 , height);
7895 icons.push_back (icon);
@@ -100,26 +117,46 @@ void HelpComponent::updateGrid()
100117 mGrid ->setOrigin (mStyle .origin );
101118}
102119
103- std::shared_ptr<TextureResource> HelpComponent::getIconTexture ( const char * name )
120+ const HelpComponent::IconPathMap& HelpComponent::getIconOverridesForInput (InputConfig* inputConfig )
104121{
105- auto it = mIconCache .find (name);
106- if (it != mIconCache .cend ())
107- return it->second ;
122+ if (!inputConfig)
123+ return NO_ICON_OVERRIDES;
124+
125+ const auto & deviceName = inputConfig->getDeviceName ();
126+ if (strcasestr (deviceName.c_str (), " xbox" ))
127+ return XBOX_ICON_OVERRIDES;
128+
129+ if (strcasestr (deviceName.c_str (), " sony" ) || strcasestr (deviceName.c_str (), " playstation" ))
130+ return PLAYSTATION_ICON_OVERRIDES;
108131
109- auto pathLookup = ICON_PATH_MAP.find (name);
110- if (pathLookup == ICON_PATH_MAP.cend ())
132+ return NO_ICON_OVERRIDES;
133+ }
134+
135+ std::shared_ptr<TextureResource> HelpComponent::getIconTexture (const std::string& name, const IconPathMap& iconOverrides)
136+ {
137+ auto pathLookup = iconOverrides.find (name);
138+ if (pathLookup == iconOverrides.cend ())
111139 {
112- LOG (LogError) << " Unknown help icon \" " << name << " \" !" ;
113- return nullptr ;
140+ pathLookup = DEFAULT_ICON_PATH_MAP.find (name);
141+ if (pathLookup == DEFAULT_ICON_PATH_MAP.cend ())
142+ {
143+ LOG (LogError) << " Unknown help icon \" " << name << " \" !" ;
144+ return nullptr ;
145+ }
114146 }
147+
148+ auto it = mIconCache .find (pathLookup->second );
149+ if (it != mIconCache .cend ())
150+ return it->second ;
151+
115152 if (!ResourceManager::getInstance ()->fileExists (pathLookup->second ))
116153 {
117- LOG (LogError) << " Help icon \" " << name << " \" - corresponding image file \" " << pathLookup->second << " \" misisng !" ;
154+ LOG (LogError) << " Help icon \" " << name << " \" - corresponding image file \" " << pathLookup->second << " \" missing !" ;
118155 return nullptr ;
119156 }
120157
121158 std::shared_ptr<TextureResource> tex = TextureResource::get (pathLookup->second );
122- mIconCache [std::string (name) ] = tex;
159+ mIconCache [pathLookup-> second ] = tex;
123160 return tex;
124161}
125162
0 commit comments