Refactor storage of joystick SDL key names
authorWuzzy <Wuzzy2@mail.ru>
Fri, 20 Jul 2018 02:22:12 +0200
changeset 13520 c5365f05d4de
parent 13519 31d0b0911cba
child 13521 d44ca1f04bbe
Refactor storage of joystick SDL key names
QTfrontend/CMakeLists.txt
QTfrontend/sdlkeys.cpp
QTfrontend/sdlkeys.h
QTfrontend/util/SDLInteraction.cpp
--- a/QTfrontend/CMakeLists.txt	Thu Jul 19 22:19:44 2018 +0200
+++ b/QTfrontend/CMakeLists.txt	Fri Jul 20 02:22:12 2018 +0200
@@ -94,6 +94,7 @@
     campaign.cpp
     ui_hwform.cpp
     ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp
+    ${CMAKE_CURRENT_BINARY_DIR}/sdlkeys.cpp
     )
 
 if(MINGW)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/sdlkeys.cpp	Fri Jul 20 02:22:12 2018 +0200
@@ -0,0 +1,199 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "sdlkeys.h"
+
+#include <QtGlobal>
+
+char sdlkeys[1024][2][128] =
+{
+    {"mousel", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Left button")},
+    {"mousem", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Middle button")},
+    {"mouser", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Right button")},
+    {"wheelup", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Wheel up")},
+    {"wheeldown", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Wheel down")},
+    {"backspace", QT_TRANSLATE_NOOP("binds (keys)", "Backspace")},
+    {"tab", QT_TRANSLATE_NOOP("binds (keys)", "Tab")},
+    {"clear", QT_TRANSLATE_NOOP("binds (keys)", "Clear")},
+    {"return", QT_TRANSLATE_NOOP("binds (keys)", "Return")},
+    {"pause", QT_TRANSLATE_NOOP("binds (keys)", "Pause")},
+    {"escape", QT_TRANSLATE_NOOP("binds (keys)", "Escape")},
+    {"space", QT_TRANSLATE_NOOP("binds (keys)", "Space")},
+    {"!", "!"},
+    {"\"", "\""},
+    {"#", "#"},
+    {"$", "$"},
+    {"&", "&"},
+    {"'", "'"},
+    {"(", "("},
+    {")", ")"},
+    {"*", "*"},
+    {"+", "+"},
+    {",", ","},
+    {"-", "-"},
+    {".", "."},
+    {"/", "/"},
+    {"0", "0"},
+    {"1", "1"},
+    {"2", "2"},
+    {"3", "3"},
+    {"4", "4"},
+    {"5", "5"},
+    {"6", "6"},
+    {"7", "7"},
+    {"8", "8"},
+    {"9", "9"},
+    {":", ":"},
+    {";", ";"},
+    {"<", "<"},
+    {"=", "="},
+    {">", ">"},
+    {"?", "?"},
+    {"@", "@"},
+    {"[", "["},
+    {"\\", "\\"},
+    {"]", "]"},
+    {"^", "^"},
+    {"_", "_"},
+    {"`", "`"},
+    {"a", "A"},
+    {"b", "B"},
+    {"c", "C"},
+    {"d", "D"},
+    {"e", "E"},
+    {"f", "F"},
+    {"g", "G"},
+    {"h", "H"},
+    {"i", "I"},
+    {"j", "J"},
+    {"k", "K"},
+    {"l", "L"},
+    {"m", "M"},
+    {"n", "N"},
+    {"o", "O"},
+    {"p", "P"},
+    {"q", "Q"},
+    {"r", "R"},
+    {"s", "S"},
+    {"t", "T"},
+    {"u", "U"},
+    {"v", "V"},
+    {"w", "W"},
+    {"x", "X"},
+    {"y", "Y"},
+    {"z", "Z"},
+    {"delete", QT_TRANSLATE_NOOP("binds (keys)", "Delete")},
+    {"keypad_0", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 0")},
+    {"keypad_1", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 1")},
+    {"keypad_2", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 2")},
+    {"keypad_3", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 3")},
+    {"keypad_4", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 4")},
+    {"keypad_5", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 5")},
+    {"keypad_6", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 6")},
+    {"keypad_7", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 7")},
+    {"keypad_8", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 8")},
+    {"keypad_9", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 9")},
+    {"keypad_.", QT_TRANSLATE_NOOP("binds (keys)", "Numpad .")},
+    {"keypad_/", QT_TRANSLATE_NOOP("binds (keys)", "Numpad /")},
+    {"keypad_*", QT_TRANSLATE_NOOP("binds (keys)", "Numpad *")},
+    {"keypad_-", QT_TRANSLATE_NOOP("binds (keys)", "Numpad -")},
+    {"keypad_+", QT_TRANSLATE_NOOP("binds (keys)", "Numpad +")},
+    {"enter", QT_TRANSLATE_NOOP("binds (keys)", "Enter")},
+    {"equals", QT_TRANSLATE_NOOP("binds (keys)", "Equals")},
+    {"up", QT_TRANSLATE_NOOP("binds (keys)", "Up")},
+    {"down", QT_TRANSLATE_NOOP("binds (keys)", "Down")},
+    {"right", QT_TRANSLATE_NOOP("binds (keys)", "Right")},
+    {"left", QT_TRANSLATE_NOOP("binds (keys)", "Left")},
+    {"insert", QT_TRANSLATE_NOOP("binds (keys)", "Insert")},
+    {"home", QT_TRANSLATE_NOOP("binds (keys)", "Home")},
+    {"end", QT_TRANSLATE_NOOP("binds (keys)", "End")},
+    {"page_up", QT_TRANSLATE_NOOP("binds (keys)", "Page up")},
+    {"page_down", QT_TRANSLATE_NOOP("binds (keys)", "Page down")},
+    {"f1", "F1"},
+    {"f2", "F2"},
+    {"f3", "F3"},
+    {"f4", "F4"},
+    {"f5", "F5"},
+    {"f6", "F6"},
+    {"f7", "F7"},
+    {"f8", "F8"},
+    {"f9", "F9"},
+    {"f10", "F10"},
+    {"f11", "F11"},
+    {"f12", "F12"},
+    {"f13", "F13"},
+    {"f14", "F14"},
+    {"f15", "F15"},
+    {"numlock", QT_TRANSLATE_NOOP("binds (keys)", "Num lock")},
+    {"caps_lock", QT_TRANSLATE_NOOP("binds (keys)", "Caps lock")},
+    {"scroll_lock", QT_TRANSLATE_NOOP("binds (keys)", "Scroll lock")},
+    {"right_shift", QT_TRANSLATE_NOOP("binds (keys)", "Right shift")},
+    {"left_shift", QT_TRANSLATE_NOOP("binds (keys)", "Left shift")},
+    {"right_ctrl", QT_TRANSLATE_NOOP("binds (keys)", "Right ctrl")},
+    {"left_ctrl", QT_TRANSLATE_NOOP("binds (keys)", "Left ctrl")},
+    {"right_alt", QT_TRANSLATE_NOOP("binds (keys)", "Right alt")},
+    {"left_alt", QT_TRANSLATE_NOOP("binds (keys)", "Left alt")},
+    {"right_meta", QT_TRANSLATE_NOOP("binds (keys)", "Right meta")},
+    {"left_meta", QT_TRANSLATE_NOOP("binds (keys)", "Left meta")}
+};
+
+// button name definitions for Microsoft's XBox360 controller
+// don't modify button order!
+char xb360buttons[10][128] =
+{
+    QT_TRANSLATE_NOOP("binds (keys)", "A button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "B button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "X button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Y button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "LB button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "RB button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Back button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Start button"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Left stick"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Right stick")
+};
+
+// axis name definitions for Microsoft's XBox360 controller
+// don't modify axis order!
+char xbox360axes[][128] =
+{
+    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Right)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Left)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Down)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Up)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Left trigger"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Right trigger"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Down)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Up)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Right)"),
+    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Left)"),
+};
+char xb360dpad[128] = QT_TRANSLATE_NOOP("binds (keys)", "D-pad");
+
+// Generic controller binding names
+//: Game controller axis direction. %1 = axis number, %2 = direction
+char controlleraxis[128] = QT_TRANSLATE_NOOP("binds (keys)", "Axis %1 %2");
+//: Game controller button. %1 = button number
+char controllerbutton[128] = QT_TRANSLATE_NOOP("binds (keys)", "Button %1");
+//: Game controller D-pad button. %1 = D-pad number, %2 = direction
+char controllerhat[128] = QT_TRANSLATE_NOOP("binds (keys)", "D-pad %1 %2");
+char controllerup[128] = QT_TRANSLATE_NOOP("binds (keys)", "Up");
+char controllerdown[128] = QT_TRANSLATE_NOOP("binds (keys)", "Down");
+char controllerleft[128] = QT_TRANSLATE_NOOP("binds (keys)", "Left");
+char controllerright[128] = QT_TRANSLATE_NOOP("binds (keys)", "Right");
+
--- a/QTfrontend/sdlkeys.h	Thu Jul 19 22:19:44 2018 +0200
+++ b/QTfrontend/sdlkeys.h	Fri Jul 20 02:22:12 2018 +0200
@@ -16,167 +16,19 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-char sdlkeys[1024][2][128] =
-{
-    {"mousel", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Left button")},
-    {"mousem", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Middle button")},
-    {"mouser", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Right button")},
-    {"wheelup", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Wheel up")},
-    {"wheeldown", QT_TRANSLATE_NOOP("binds (keys)", "Mouse: Wheel down")},
-    {"backspace", QT_TRANSLATE_NOOP("binds (keys)", "Backspace")},
-    {"tab", QT_TRANSLATE_NOOP("binds (keys)", "Tab")},
-    {"clear", QT_TRANSLATE_NOOP("binds (keys)", "Clear")},
-    {"return", QT_TRANSLATE_NOOP("binds (keys)", "Return")},
-    {"pause", QT_TRANSLATE_NOOP("binds (keys)", "Pause")},
-    {"escape", QT_TRANSLATE_NOOP("binds (keys)", "Escape")},
-    {"space", QT_TRANSLATE_NOOP("binds (keys)", "Space")},
-    {"!", "!"},
-    {"\"", "\""},
-    {"#", "#"},
-    {"$", "$"},
-    {"&", "&"},
-    {"'", "'"},
-    {"(", "("},
-    {")", ")"},
-    {"*", "*"},
-    {"+", "+"},
-    {",", ","},
-    {"-", "-"},
-    {".", "."},
-    {"/", "/"},
-    {"0", "0"},
-    {"1", "1"},
-    {"2", "2"},
-    {"3", "3"},
-    {"4", "4"},
-    {"5", "5"},
-    {"6", "6"},
-    {"7", "7"},
-    {"8", "8"},
-    {"9", "9"},
-    {":", ":"},
-    {";", ";"},
-    {"<", "<"},
-    {"=", "="},
-    {">", ">"},
-    {"?", "?"},
-    {"@", "@"},
-    {"[", "["},
-    {"\\", "\\"},
-    {"]", "]"},
-    {"^", "^"},
-    {"_", "_"},
-    {"`", "`"},
-    {"a", "A"},
-    {"b", "B"},
-    {"c", "C"},
-    {"d", "D"},
-    {"e", "E"},
-    {"f", "F"},
-    {"g", "G"},
-    {"h", "H"},
-    {"i", "I"},
-    {"j", "J"},
-    {"k", "K"},
-    {"l", "L"},
-    {"m", "M"},
-    {"n", "N"},
-    {"o", "O"},
-    {"p", "P"},
-    {"q", "Q"},
-    {"r", "R"},
-    {"s", "S"},
-    {"t", "T"},
-    {"u", "U"},
-    {"v", "V"},
-    {"w", "W"},
-    {"x", "X"},
-    {"y", "Y"},
-    {"z", "Z"},
-    {"delete", QT_TRANSLATE_NOOP("binds (keys)", "Delete")},
-    {"keypad_0", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 0")},
-    {"keypad_1", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 1")},
-    {"keypad_2", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 2")},
-    {"keypad_3", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 3")},
-    {"keypad_4", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 4")},
-    {"keypad_5", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 5")},
-    {"keypad_6", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 6")},
-    {"keypad_7", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 7")},
-    {"keypad_8", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 8")},
-    {"keypad_9", QT_TRANSLATE_NOOP("binds (keys)", "Numpad 9")},
-    {"keypad_.", QT_TRANSLATE_NOOP("binds (keys)", "Numpad .")},
-    {"keypad_/", QT_TRANSLATE_NOOP("binds (keys)", "Numpad /")},
-    {"keypad_*", QT_TRANSLATE_NOOP("binds (keys)", "Numpad *")},
-    {"keypad_-", QT_TRANSLATE_NOOP("binds (keys)", "Numpad -")},
-    {"keypad_+", QT_TRANSLATE_NOOP("binds (keys)", "Numpad +")},
-    {"enter", QT_TRANSLATE_NOOP("binds (keys)", "Enter")},
-    {"equals", QT_TRANSLATE_NOOP("binds (keys)", "Equals")},
-    {"up", QT_TRANSLATE_NOOP("binds (keys)", "Up")},
-    {"down", QT_TRANSLATE_NOOP("binds (keys)", "Down")},
-    {"right", QT_TRANSLATE_NOOP("binds (keys)", "Right")},
-    {"left", QT_TRANSLATE_NOOP("binds (keys)", "Left")},
-    {"insert", QT_TRANSLATE_NOOP("binds (keys)", "Insert")},
-    {"home", QT_TRANSLATE_NOOP("binds (keys)", "Home")},
-    {"end", QT_TRANSLATE_NOOP("binds (keys)", "End")},
-    {"page_up", QT_TRANSLATE_NOOP("binds (keys)", "Page up")},
-    {"page_down", QT_TRANSLATE_NOOP("binds (keys)", "Page down")},
-    {"f1", "F1"},
-    {"f2", "F2"},
-    {"f3", "F3"},
-    {"f4", "F4"},
-    {"f5", "F5"},
-    {"f6", "F6"},
-    {"f7", "F7"},
-    {"f8", "F8"},
-    {"f9", "F9"},
-    {"f10", "F10"},
-    {"f11", "F11"},
-    {"f12", "F12"},
-    {"f13", "F13"},
-    {"f14", "F14"},
-    {"f15", "F15"},
-    {"numlock", QT_TRANSLATE_NOOP("binds (keys)", "Num lock")},
-    {"caps_lock", QT_TRANSLATE_NOOP("binds (keys)", "Caps lock")},
-    {"scroll_lock", QT_TRANSLATE_NOOP("binds (keys)", "Scroll lock")},
-    {"right_shift", QT_TRANSLATE_NOOP("binds (keys)", "Right shift")},
-    {"left_shift", QT_TRANSLATE_NOOP("binds (keys)", "Left shift")},
-    {"right_ctrl", QT_TRANSLATE_NOOP("binds (keys)", "Right ctrl")},
-    {"left_ctrl", QT_TRANSLATE_NOOP("binds (keys)", "Left ctrl")},
-    {"right_alt", QT_TRANSLATE_NOOP("binds (keys)", "Right alt")},
-    {"left_alt", QT_TRANSLATE_NOOP("binds (keys)", "Left alt")},
-    {"right_meta", QT_TRANSLATE_NOOP("binds (keys)", "Right meta")},
-    {"left_meta", QT_TRANSLATE_NOOP("binds (keys)", "Left meta")}
-};
+#ifndef SDLKEYS_H
+#define SDLKEYS_H
 
-// button name definitions for Microsoft's XBox360 controller
-// don't modify button order!
-char xb360buttons[][128] =
-{
-    QT_TRANSLATE_NOOP("binds (keys)", "A button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "B button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "X button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Y button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "LB button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "RB button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Back button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Start button"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Left stick"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Right stick")
-};
+extern char sdlkeys[1024][2][128];
+extern char xb360buttons[10][128];
+extern char xbox360axes[10][128];
+extern char xb360dpad[128];
+extern char controlleraxis[128];
+extern char controllerbutton[128];
+extern char controllerhat[128];
+extern char controllerup[128];
+extern char controllerdown[128];
+extern char controllerleft[128];
+extern char controllerright[128];
 
-// axis name definitions for Microsoft's XBox360 controller
-// don't modify axis order!
-char xbox360axes[][128] =
-{
-    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Right)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Left)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Down)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Left stick (Up)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Left trigger"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Right trigger"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Down)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Up)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Right)"),
-    QT_TRANSLATE_NOOP("binds (keys)", "Right stick (Left)"),
-};
-char xb360dpad[128] = QT_TRANSLATE_NOOP("binds (keys)", "DPad");
+#endif
--- a/QTfrontend/util/SDLInteraction.cpp	Thu Jul 19 22:19:44 2018 +0200
+++ b/QTfrontend/util/SDLInteraction.cpp	Fri Jul 20 02:22:12 2018 +0200
@@ -25,6 +25,7 @@
 #include "SDL_mixer.h"
 
 #include "HWApplication.h"
+#include "sdlkeys.h"
 #include "hwform.h" /* you know, we could just put a config singleton lookup function in gameuiconfig or something... */
 #include "gameuiconfig.h"
 
@@ -32,12 +33,6 @@
 
 #include "physfsrwops.h"
 
-extern char sdlkeys[1024][2][128];
-extern char xb360buttons[][128];
-extern char xb360dpad[128];
-extern char xbox360axes[][128];
-
-
 SDLInteraction & SDLInteraction::instance()
 {
     static SDLInteraction instance;
@@ -133,39 +128,38 @@
         // Register entries for missing axes not assigned to sticks of this joystick/gamepad
         for(int aid = 0; aid < SDL_JoystickNumAxes(joy) && i < 1021; aid++)
         {
-            // Again store the part of the string not changing for multiple uses
-            QString axis = prefix + HWApplication::translate("binds (keys)", "Axis") + QString(" %1 ").arg(aid + 1);
+            QString axis = prefix + HWApplication::translate("binds (keys)", controlleraxis).arg(aid + 1);
 
             // Entry for "Axis Up"
             sprintf(sdlkeys[i][0], "j%da%du", jid, aid);
-            sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + HWApplication::translate("binds (keys)", xbox360axes[aid * 2])) : axis + HWApplication::translate("binds (keys)", "(Up)")).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + HWApplication::translate("binds (keys)", xbox360axes[aid * 2])) : (axis.arg(HWApplication::translate("binds (keys)", controllerup)))).toUtf8().constData());
 
             // Entry for "Axis Down"
             sprintf(sdlkeys[i][0], "j%da%dd", jid, aid);
-            sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + HWApplication::translate("binds (keys)", xbox360axes[aid * 2 + 1])) : axis + HWApplication::translate("binds (keys)", "(Down)")).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", ((isxb && aid < 5) ? (prefix + HWApplication::translate("binds (keys)", xbox360axes[aid * 2 + 1])) : (axis.arg(HWApplication::translate("binds (keys)", controllerdown)))).toUtf8().constData());
         }
 
         // Register entries for all coolie hats of this joystick/gamepad
         for(int hid = 0; hid < SDL_JoystickNumHats(joy) && i < 1019; hid++)
         {
             // Again store the part of the string not changing for multiple uses
-            QString hat = prefix + (isxb ? (HWApplication::translate("binds (keys)", xb360dpad) + QString(" ")) : HWApplication::translate("binds (keys)", "Hat") + QString(" %1 ").arg(hid + 1));
+            QString hat = prefix + (isxb ? (HWApplication::translate("binds (keys)", xb360dpad) + QString(" ")) : HWApplication::translate("binds (keys)", controllerhat).arg(hid + 1));
 
             // Entry for "Hat Up"
             sprintf(sdlkeys[i][0], "j%dh%du", jid, hid);
-            sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Up)")).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", hat.arg(HWApplication::translate("binds (keys)", controllerup)).toUtf8().constData());
 
             // Entry for "Hat Down"
             sprintf(sdlkeys[i][0], "j%dh%dd", jid, hid);
-            sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Down)")).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", hat.arg(HWApplication::translate("binds (keys)", controllerdown)).toUtf8().constData());
 
             // Entry for "Hat Left"
             sprintf(sdlkeys[i][0], "j%dh%dl", jid, hid);
-            sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Left)")).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", hat.arg(HWApplication::translate("binds (keys)", controllerleft)).toUtf8().constData());
 
             // Entry for "Hat Right"
             sprintf(sdlkeys[i][0], "j%dh%dr", jid, hid);
-            sprintf(sdlkeys[i++][1], "%s", (hat + HWApplication::translate("binds (keys)", "(Right)")).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", hat.arg(HWApplication::translate("binds (keys)", controllerright)).toUtf8().constData());
         }
 
         // Register entries for all buttons of this joystick/gamepad
@@ -173,7 +167,7 @@
         {
             // Buttons
             sprintf(sdlkeys[i][0], "j%db%d", jid, bid);
-            sprintf(sdlkeys[i++][1], "%s", (prefix + ((isxb && bid < 10) ? (HWApplication::translate("binds (keys)", xb360buttons[bid]) + QString(" ")) : HWApplication::translate("binds (keys)", "Button") + QString(" %1").arg(bid + 1))).toUtf8().constData());
+            sprintf(sdlkeys[i++][1], "%s", (prefix + ((isxb && bid < 10) ? (HWApplication::translate("binds (keys)", xb360buttons[bid]) + QString(" ")) : HWApplication::translate("binds (keys)", controllerbutton).arg(bid + 1))).toUtf8().constData());
         }
         // Close the game controller as we no longer need it
         SDL_JoystickClose(joy);