]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow key translation
authorterencehill <piuntn@gmail.com>
Sun, 8 Apr 2018 14:46:08 +0000 (16:46 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 8 Apr 2018 14:46:08 +0000 (16:46 +0200)
qcsrc/client/main.qc
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/menu/xonotic/keybinder.qc

index 37027d25cd35570419c819179b207311580f157e..935f2b66753eed85925f4463884cc3b9136988f0 100644 (file)
@@ -1247,6 +1247,8 @@ string _getcommandkey(string cmd_name, string command, bool forcename)
                                if(!joy_active && substring(key, 0, 3) == "JOY")
                                        continue;
 
+                               key = translate_key(key);
+
                                if (keys == "")
                                        keys = key;
                                else
index 35ec9b2c58f96de0ac3aba803b52641394ada62c..cb06ed9ead14dc4e04a359eebf0739d577828260 100644 (file)
@@ -1306,6 +1306,146 @@ float get_model_parameters(string m, float sk)
        return 1;
 }
 
+string translate_key(string key)
+{
+       switch(key)
+       {
+               case "TAB":                             return _("TAB");
+               case "ENTER":                   return _("ENTER");
+               case "ESCAPE":                  return _("ESCAPE");
+               case "SPACE":                   return _("SPACE");
+
+               case "BACKSPACE":               return _("BACKSPACE");
+               case "UPARROW":                 return _("UPARROW");
+               case "DOWNARROW":               return _("DOWNARROW");
+               case "LEFTARROW":               return _("LEFTARROW");
+               case "RIGHTARROW":              return _("RIGHTARROW");
+
+               case "ALT":                             return _("ALT");
+               case "CTRL":                    return _("CTRL");
+               case "SHIFT":                   return _("SHIFT");
+
+               case "F1":                              return _("F1");
+               case "F2":                              return _("F2");
+               case "F3":                              return _("F3");
+               case "F4":                              return _("F4");
+               case "F5":                              return _("F5");
+               case "F6":                              return _("F6");
+               case "F7":                              return _("F7");
+               case "F8":                              return _("F8");
+               case "F9":                              return _("F9");
+               case "F10":                             return _("F10");
+               case "F11":                             return _("F11");
+               case "F12":                             return _("F12");
+
+               case "INS":                             return _("INS");
+               case "DEL":                             return _("DEL");
+               case "PGDN":                    return _("PGDN");
+               case "PGUP":                    return _("PGUP");
+               case "HOME":                    return _("HOME");
+               case "END":                             return _("END");
+
+               case "PAUSE":                   return _("PAUSE");
+
+               case "NUMLOCK":                 return _("NUMLOCK");
+               case "CAPSLOCK":                return _("CAPSLOCK");
+               case "SCROLLOCK":               return _("SCROLLOCK");
+       }
+
+       if (substring(key, 0, 3) == "KP_")
+       {
+               string subkey = substring(key, 3, -1);
+               if (IS_DIGIT(substring(key, 3, 1))) // check only first digit
+               {
+                       return sprintf(_("KP_%d"), stof(subkey));
+               }
+
+               switch(subkey)
+               {
+                       case "INS":                             return sprintf(_("KP_%s"), _("INS"));
+                       case "END":                             return sprintf(_("KP_%s"), _("END"));
+                       case "DOWNARROW":               return sprintf(_("KP_%s"), _("DOWNARROW"));
+                       case "PGDN":                    return sprintf(_("KP_%s"), _("PGDN"));
+                       case "LEFTARROW":               return sprintf(_("KP_%s"), _("LEFTARROW"));
+                       case "RIGHTARROW":              return sprintf(_("KP_%s"), _("RIGHTARROW"));
+                       case "HOME":                    return sprintf(_("KP_%s"), _("HOME"));
+                       case "UPARROW":                 return sprintf(_("KP_%s"), _("UPARROW"));
+                       case "PGUP":                    return sprintf(_("KP_%s"), _("PGUP"));
+                       case "PERIOD":                  return sprintf(_("KP_%s"), _("PERIOD"));
+                       case "DEL":                             return sprintf(_("KP_%s"), _("DEL"));
+                       case "DIVIDE":                  return sprintf(_("KP_%s"), _("DIVIDE"));
+                       case "SLASH":                   return sprintf(_("KP_%s"), _("SLASH"));
+                       case "MULTIPLY":                return sprintf(_("KP_%s"), _("MULTIPLY"));
+                       case "MINUS":                   return sprintf(_("KP_%s"), _("MINUS"));
+                       case "PLUS":                    return sprintf(_("KP_%s"), _("PLUS"));
+                       case "ENTER":                   return sprintf(_("KP_%s"), _("ENTER"));
+                       case "EQUALS":                  return sprintf(_("KP_%s"), _("EQUALS"));
+                       default:                                return key;
+               }
+       }
+
+       if (key == "PRINTSCREEN") return _("PRINTSCREEN");
+
+       if (substring(key, 0, 5) == "MOUSE")
+               return sprintf(_("MOUSE%d"), stof(substring(key, 5, -1)));
+
+       if (key == "MWHEELUP") return _("MWHEELUP");
+       if (key == "MWHEELDOWN") return _("MWHEELDOWN");
+
+       if (substring(key, 0,3) == "JOY")
+               return sprintf(_("JOY%d"), stof(substring(key, 3, -1)));
+
+       if (substring(key, 0,3) == "AUX")
+               return sprintf(_("AUX%d"), stof(substring(key, 3, -1)));
+
+       if (substring(key, 0, 4) == "X360_")
+       {
+               string subkey = substring(key, 4, -1);
+               switch(subkey)
+               {
+                       case "DPAD_UP":                                 return sprintf(_("X360_%s"), _("DPAD_UP"));
+                       case "DPAD_DOWN":                               return sprintf(_("X360_%s"), _("DPAD_DOWN"));
+                       case "DPAD_LEFT":                               return sprintf(_("X360_%s"), _("DPAD_LEFT"));
+                       case "DPAD_RIGHT":                              return sprintf(_("X360_%s"), _("DPAD_RIGHT"));
+                       case "START":                                   return sprintf(_("X360_%s"), _("START"));
+                       case "BACK":                                    return sprintf(_("X360_%s"), _("BACK"));
+                       case "LEFT_THUMB":                              return sprintf(_("X360_%s"), _("LEFT_THUMB"));
+                       case "RIGHT_THUMB":                             return sprintf(_("X360_%s"), _("RIGHT_THUMB"));
+                       case "LEFT_SHOULDER":                   return sprintf(_("X360_%s"), _("LEFT_SHOULDER"));
+                       case "RIGHT_SHOULDER":                  return sprintf(_("X360_%s"), _("RIGHT_SHOULDER"));
+                       case "LEFT_TRIGGER":                    return sprintf(_("X360_%s"), _("LEFT_TRIGGER"));
+                       case "RIGHT_TRIGGER":                   return sprintf(_("X360_%s"), _("RIGHT_TRIGGER"));
+                       case "LEFT_THUMB_UP":                   return sprintf(_("X360_%s"), _("LEFT_THUMB_UP"));
+                       case "LEFT_THUMB_DOWN":                 return sprintf(_("X360_%s"), _("LEFT_THUMB_DOWN"));
+                       case "LEFT_THUMB_LEFT":                 return sprintf(_("X360_%s"), _("LEFT_THUMB_LEFT"));
+                       case "LEFT_THUMB_RIGHT":                return sprintf(_("X360_%s"), _("LEFT_THUMB_RIGHT"));
+                       case "RIGHT_THUMB_UP":                  return sprintf(_("X360_%s"), _("RIGHT_THUMB_UP"));
+                       case "RIGHT_THUMB_DOWN":                return sprintf(_("X360_%s"), _("RIGHT_THUMB_DOWN"));
+                       case "RIGHT_THUMB_LEFT":                return sprintf(_("X360_%s"), _("RIGHT_THUMB_LEFT"));
+                       case "RIGHT_THUMB_RIGHT":               return sprintf(_("X360_%s"), _("RIGHT_THUMB_RIGHT"));
+                       default:                                                return key;
+               }
+       }
+
+       if (substring(key, 0, 4) == "JOY_")
+       {
+               string subkey = substring(key, 4, -1);
+               switch(subkey)
+               {
+                       case "UP":                      return sprintf(_("JOY_%s"), _("UP"));
+                       case "DOWN":            return sprintf(_("JOY_%s"), _("DOWN"));
+                       case "LEFT":            return sprintf(_("JOY_%s"), _("LEFT"));
+                       case "RIGHT":           return sprintf(_("JOY_%s"), _("RIGHT"));
+                       default:                        return key;
+               }
+       }
+
+       if (substring(key, 0, 8) == "MIDINOTE")
+               return sprintf(_("MIDINOTE%d"), stof(substring(key, 8, -1)));
+
+       return key;
+}
+
 // x-encoding (encoding as zero length invisible string)
 const string XENCODE_2  = "xX";
 const string XENCODE_22 = "0123456789abcdefABCDEF";
index 3304d0e7a455453b02615f44a5664bfaafe8cbdb..3900349e34058201cae76c9491a459ef977c58ee 100644 (file)
@@ -133,6 +133,9 @@ float get_model_parameters_fixbone;
 string get_model_parameters_desc;
 float get_model_parameters(string mod, float skn); // call with string_null to clear; skin -1 means mod is the filename of the txt file and is to be split
 
+ERASEABLE
+string translate_key(string key);
+
 // x-encoding (encoding as zero length invisible string)
 // encodes approx. 14 bits into 5 bytes of color code string
 const float XENCODE_MAX = 21295; // 2*22*22*22-1
index cde80d693d422a6a44b1664cd06f29fa7ceee87d..36b134478cf0a8317c5e928f3fa29ee8eef071cc 100644 (file)
@@ -373,6 +373,7 @@ float XonoticKeyBinder_keyDown(entity me, int key, bool ascii, float shift)
        }
        return r;
 }
+
 void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
 {
        string s;
@@ -437,7 +438,7 @@ void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isS
                        {
                                if(s != "")
                                        s = strcat(s, ", ");
-                               s = strcat(s, keynumtostring(k));
+                               s = strcat(s, translate_key(keynumtostring(k)));
                        }
                }
                s = draw_TextShortenToWidth(s, me.columnKeysSize, 0, me.realFontSize);