]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/keybinder.c
Merge remote branch 'origin/terencehill/incompatible_mutators'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / keybinder.c
index 6b490be23115a380ece36e67930e7551b0f73f32..1107e60abc6b3296e77dd9582bbe6613a267ef32 100644 (file)
@@ -33,6 +33,8 @@ void KeyBinder_Bind_Edit(entity btn, entity me);
 
 #ifdef IMPLEMENTATION
 
+string KEY_NOT_BOUND_CMD = "// not bound";
+
 #define MAX_KEYS_PER_FUNCTION 2
 #define MAX_KEYBINDS 256
 string Xonotic_KeyBinds_Functions[MAX_KEYBINDS];
@@ -45,7 +47,7 @@ void Xonotic_KeyBinds_Read()
        string s;
 
        Xonotic_KeyBinds_Count = 0;
-       fh = fopen("keybinds.txt", FILE_READ);
+       fh = fopen(language_filename("keybinds.txt"), FILE_READ);
        if(fh < 0)
                return;
        while((s = fgets(fh)))
@@ -68,17 +70,40 @@ entity makeXonoticKeyBinder()
        me.configureXonoticKeyBinder(me);
        return me;
 }
-void configureXonoticKeyBinderXonoticKeyBinder(entity me)
+void replace_bind(string from, string to)
+{
+       float n, j, k;
+       n = tokenize(findkeysforcommand(from, 0)); // uses '...' strings
+       for(j = 0; j < n; ++j)
+       {
+               k = stof(argv(j));
+               if(k != -1)
+                       localcmd("\nbind \"", keynumtostring(k), "\" \"", to, "\"\n");
+       }
+}
+void XonoticKeyBinder_configureXonoticKeyBinder(entity me)
 {
        me.configureXonoticListBox(me);
        if(Xonotic_KeyBinds_Count < 0)
                Xonotic_KeyBinds_Read();
        me.nItems = Xonotic_KeyBinds_Count;
        me.setSelected(me, 0);
+
+       // TEMP: Xonotic 0.1 to later
+       replace_bind("impulse 1", "weapon_group_1");
+       replace_bind("impulse 2", "weapon_group_2");
+       replace_bind("impulse 3", "weapon_group_3");
+       replace_bind("impulse 4", "weapon_group_4");
+       replace_bind("impulse 5", "weapon_group_5");
+       replace_bind("impulse 6", "weapon_group_6");
+       replace_bind("impulse 7", "weapon_group_7");
+       replace_bind("impulse 8", "weapon_group_8");
+       replace_bind("impulse 9", "weapon_group_9");
+       replace_bind("impulse 14", "weapon_group_0");
 }
-void resizeNotifyXonoticKeyBinder(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
+void XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 {
-       resizeNotifyXonoticListBox(me, relOrigin, relSize, absOrigin, absSize);
+       SUPER(XonoticKeyBinder).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
 
        me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
        me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
@@ -103,7 +128,7 @@ void KeyBinder_Bind_Change(entity btn, entity me)
        me.keyGrabButton.forcePressed = 1;
        keyGrabber = me;
 }
-void keyGrabbedXonoticKeyBinder(entity me, float key, float ascii)
+void XonoticKeyBinder_keyGrabbed(entity me, float key, float ascii)
 {
        float n, j, k, nvalid;
        string func;
@@ -116,7 +141,7 @@ void keyGrabbedXonoticKeyBinder(entity me, float key, float ascii)
        if(func == "")
                return;
 
-       n = tokenize(findkeysforcommand(func)); // uses '...' strings
+       n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
        nvalid = 0;
        for(j = 0; j < n; ++j)
        {
@@ -130,12 +155,14 @@ void keyGrabbedXonoticKeyBinder(entity me, float key, float ascii)
                {
                        k = stof(argv(j));
                        if(k != -1)
-                               localcmd("\nunbind \"", keynumtostring(k), "\"\n");
+                               //localcmd("\nunbind \"", keynumtostring(k), "\"\n");
+                               localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n");
                }
        }
        localcmd("\nbind \"", keynumtostring(key), "\" \"", func, "\"\n");
+       localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
 }
-void editUserbindXonoticKeyBinder(entity me, string theName, string theCommandPress, string theCommandRelease)
+void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandPress, string theCommandRelease)
 {
        string func, descr;
 
@@ -186,16 +213,17 @@ void KeyBinder_Bind_Clear(entity btn, entity me)
        if(func == "")
                return;
 
-       n = tokenize(findkeysforcommand(func)); // uses '...' strings
+       n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
        for(j = 0; j < n; ++j)
        {
                k = stof(argv(j));
                if(k != -1)
-                       localcmd("\nunbind \"", keynumtostring(k), "\"\n");
+                       //localcmd("\nunbind \"", keynumtostring(k), "\"\n");
+                       localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n");
        }
-
+       localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
 }
-void clickListBoxItemXonoticKeyBinder(entity me, float i, vector where)
+void XonoticKeyBinder_clickListBoxItem(entity me, float i, vector where)
 {
        if(i == me.lastClickedServer)
                if(time < me.lastClickedTime + 0.3)
@@ -206,7 +234,7 @@ void clickListBoxItemXonoticKeyBinder(entity me, float i, vector where)
        me.lastClickedServer = i;
        me.lastClickedTime = time;
 }
-void setSelectedXonoticKeyBinder(entity me, float i)
+void XonoticKeyBinder_setSelected(entity me, float i)
 {
        // handling of "unselectable" items
        i = floor(0.5 + bound(0, i, me.nItems - 1));
@@ -231,29 +259,31 @@ void setSelectedXonoticKeyBinder(entity me, float i)
                me.previouslySelected = i;
        if(me.userbindEditButton)
                me.userbindEditButton.disabled = (substring(Xonotic_KeyBinds_Descriptions[i], 0, 1) != "$");
-       setSelectedListBox(me, i);
+       SUPER(XonoticKeyBinder).setSelected(me, i);
 }
-float keyDownXonoticKeyBinder(entity me, float key, float ascii, float shift)
+float XonoticKeyBinder_keyDown(entity me, float key, float ascii, float shift)
 {
        float r;
        r = 1;
        switch(key)
        {
                case K_ENTER:
+               case K_KP_ENTER:
                case K_SPACE:
                        KeyBinder_Bind_Change(me, me);
                        break;
                case K_DEL:
+               case K_KP_DEL:
                case K_BACKSPACE:
                        KeyBinder_Bind_Clear(me, me);
                        break;
                default:
-                       r = keyDownListBox(me, key, ascii, shift);
+                       r = SUPER(XonoticKeyBinder).keyDown(me, key, ascii, shift);
                        break;
        }
        return r;
 }
-void drawListBoxItemXonoticKeyBinder(entity me, float i, vector absSize, float isSelected)
+void XonoticKeyBinder_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
 {
        string s;
        float j, k, n;
@@ -297,10 +327,11 @@ void drawListBoxItemXonoticKeyBinder(entity me, float i, vector absSize, float i
                                theAlpha *= SKINALPHA_DISABLED;
        }
 
-       draw_Text(me.realUpperMargin * eY + extraMargin * eX, descr, me.realFontSize, theColor, theAlpha, 0);
+       s = draw_TextShortenToWidth(descr, me.columnFunctionSize, 0, me.realFontSize);
+       draw_Text(me.realUpperMargin * eY + extraMargin * eX, s, me.realFontSize, theColor, theAlpha, 0);
        if(func != "")
        {
-               n = tokenize(findkeysforcommand(func)); // uses '...' strings
+               n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
                s = "";
                for(j = 0; j < n; ++j)
                {