Merge branch 'master' into terencehill/translated_keys
authorterencehill <piuntn@gmail.com>
Sun, 21 Apr 2019 15:44:04 +0000 (17:44 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 21 Apr 2019 15:44:04 +0000 (17:44 +0200)
qcsrc/client/main.qc
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/menu/xonotic/keybinder.qc

index 6cee9df..c22f0d4 100644 (file)
@@ -1261,6 +1261,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 74e337f..9c9896e 100644 (file)
@@ -1438,6 +1438,148 @@ float get_model_parameters(string m, float sk)
        return 1;
 }
 
+string translate_key(string key)
+{
+       if (prvm_language == "en") return 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 f20cbd5..2033aa9 100644 (file)
@@ -156,6 +156,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 200834e..ec7792c 100644 (file)
@@ -390,6 +390,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;
@@ -459,7 +460,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)));
                        }
                }
        }