Make frontend detect controllers again 0.9.24
authorWuzzy <Wuzzy2@mail.ru>
Tue, 24 Jul 2018 18:37:52 +0200
branch0.9.24
changeset 13541 acd5c58258e7
parent 13540 c5201a714b95
child 13542 b89ea5618067
Make frontend detect controllers again
ChangeLog.txt
QTfrontend/util/SDLInteraction.cpp
--- a/ChangeLog.txt	Tue Jul 24 15:44:25 2018 +0200
+++ b/ChangeLog.txt	Tue Jul 24 18:37:52 2018 +0200
@@ -1,8 +1,8 @@
 + features
 * bugfixes
-====================== 0.9.25 ======================
-Lua API:
- + New call: Retreat(time [, respectGetAwayTimeFactor): Force current turn into retreating mode
+====================== 0.9.24.2 ====================
+ * Restore joystick/controller functionality
+ * Fix crash when starting Hedgewars with 2 controllers connected
 
 ====================== 0.9.24.1 ====================
  * Fix crash when portable portal device is fired at reduced graphics quality
--- a/QTfrontend/util/SDLInteraction.cpp	Tue Jul 24 15:44:25 2018 +0200
+++ b/QTfrontend/util/SDLInteraction.cpp	Tue Jul 24 18:37:52 2018 +0200
@@ -105,19 +105,23 @@
     QStringList result;
 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-// TODO or not TODO?
-#else
     int i = 0;
     while(i < 1024 && sdlkeys[i][1][0] != '\0')
         i++;
 
     // Iterate through all game controllers
+    qDebug("Detecting controllers ...");
     for(int jid = 0; jid < SDL_NumJoysticks(); jid++)
     {
         SDL_Joystick* joy = SDL_JoystickOpen(jid);
 
-        // Retrieve the game controller's name and strip "Controller (...)" that's added by some drivers (English only)
-        QString joyname = QString(SDL_JoystickName(jid)).replace(QRegExp("^Controller \\((.*)\\)$"), "\\1");
+        // Retrieve the game controller's name
+        QString joyname = QString(SDL_JoystickNameForIndex(jid));
+
+        // Strip "Controller (...)" that's added by some drivers (English only)
+        joyname.replace(QRegExp("^Controller \\((.*)\\)$"), "\\1");
+
+        qDebug("- Controller no. %d: %s", jid, qPrintable(joyname));
 
         // Connected Xbox 360 controller? Use specific button names then
         // Might be interesting to add 'named' buttons for the most often used gamepads