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 std::map<std::string, const char *> 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,36 @@ static const std::map<std::string, const char*> ICON_PATH_MAP {
2929 { " select" , " :/help/button_select.svg" }
3030};
3131
32+ static const std::map<std::string, const char *> XBOX_ICON_PATH_MAP {
33+ { " up/down" , " :/help/dpad_updown.svg" },
34+ { " left/right" , " :/help/dpad_leftright.svg" },
35+ { " up/down/left/right" , " :/help/dpad_all.svg" },
36+ { " a" , " :/help/button_b.svg" },
37+ { " b" , " :/help/button_a.svg" },
38+ { " x" , " :/help/button_y.svg" },
39+ { " y" , " :/help/button_x.svg" },
40+ { " l" , " :/help/button_l.svg" },
41+ { " r" , " :/help/button_r.svg" },
42+ { " lr" , " :/help/button_lr.svg" },
43+ { " start" , " :/help/button_start.svg" },
44+ { " select" , " :/help/button_select.svg" }
45+ };
46+
47+ static const std::map<std::string, const char *> PLAYSTATION_ICON_PATH_MAP {
48+ { " up/down" , " :/help/dpad_updown.svg" },
49+ { " left/right" , " :/help/dpad_leftright.svg" },
50+ { " up/down/left/right" , " :/help/dpad_all.svg" },
51+ { " a" , " :/help/button_circle.svg" },
52+ { " b" , " :/help/button_x.svg" },
53+ { " x" , " :/help/button_triangle.svg" },
54+ { " y" , " :/help/button_square.svg" },
55+ { " l" , " :/help/button_l.svg" },
56+ { " r" , " :/help/button_r.svg" },
57+ { " lr" , " :/help/button_lr.svg" },
58+ { " start" , " :/help/button_start.svg" },
59+ { " select" , " :/help/button_select.svg" }
60+ };
61+
3262HelpComponent::HelpComponent (Window* window) : GuiComponent(window)
3363{
3464}
@@ -67,12 +97,14 @@ void HelpComponent::updateGrid()
6797 std::vector< std::shared_ptr<ImageComponent> > icons;
6898 std::vector< std::shared_ptr<TextComponent> > labels;
6999
100+ const auto & iconPathMap = getIconPathMap (InputManager::getInstance ()->getInputConfigForLastUsedDevice ());
101+
70102 float width = 0 ;
71103 const float height = Math::round (font->getLetterHeight () * 1 .25f );
72104 for (auto it = mPrompts .cbegin (); it != mPrompts .cend (); it++)
73105 {
74106 auto icon = std::make_shared<ImageComponent>(mWindow );
75- icon->setImage (getIconTexture (it->first .c_str ()));
107+ icon->setImage (getIconTexture (it->first .c_str (), iconPathMap ));
76108 icon->setColorShift (mStyle .iconColor );
77109 icon->setResize (0 , height);
78110 icons.push_back (icon);
@@ -100,26 +132,42 @@ void HelpComponent::updateGrid()
100132 mGrid ->setOrigin (mStyle .origin );
101133}
102134
103- std::shared_ptr<TextureResource> HelpComponent::getIconTexture ( const char * name )
135+ const std::map<std::string, const char *>& HelpComponent::getIconPathMap (InputConfig* inputConfig )
104136{
105- auto it = mIconCache .find (name);
106- if (it != mIconCache .cend ())
107- return it->second ;
137+ if (!inputConfig)
138+ return DEFAULT_ICON_PATH_MAP;
139+
140+ const auto & deviceName = inputConfig->getDeviceName ();
141+ if (strcasestr (deviceName.c_str (), " xbox" ))
142+ return XBOX_ICON_PATH_MAP;
108143
109- auto pathLookup = ICON_PATH_MAP.find (name);
110- if (pathLookup == ICON_PATH_MAP.cend ())
144+ if (strcasestr (deviceName.c_str (), " sony" ) || strcasestr (deviceName.c_str (), " playstation" ))
145+ return PLAYSTATION_ICON_PATH_MAP;
146+
147+ return DEFAULT_ICON_PATH_MAP;
148+ }
149+
150+ std::shared_ptr<TextureResource> HelpComponent::getIconTexture (const char * name, const std::map<std::string, const char *>& iconPathMap)
151+ {
152+ auto pathLookup = iconPathMap.find (name);
153+ if (pathLookup == iconPathMap.cend ())
111154 {
112155 LOG (LogError) << " Unknown help icon \" " << name << " \" !" ;
113156 return nullptr ;
114157 }
158+
159+ auto it = mIconCache .find (pathLookup->second );
160+ if (it != mIconCache .cend ())
161+ return it->second ;
162+
115163 if (!ResourceManager::getInstance ()->fileExists (pathLookup->second ))
116164 {
117- LOG (LogError) << " Help icon \" " << name << " \" - corresponding image file \" " << pathLookup->second << " \" misisng !" ;
165+ LOG (LogError) << " Help icon \" " << name << " \" - corresponding image file \" " << pathLookup->second << " \" missing !" ;
118166 return nullptr ;
119167 }
120168
121169 std::shared_ptr<TextureResource> tex = TextureResource::get (pathLookup->second );
122- mIconCache [std::string (name )] = tex;
170+ mIconCache [std::string (pathLookup-> second )] = tex;
123171 return tex;
124172}
125173
0 commit comments