X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fkeybinder.c;h=66c3486a3a91c22747a646153d64d181f4f14302;hb=d159d68eea046ca027b7260634c63ba40f943633;hp=f4a6c5a3e3dc40adbefdaf5d4eb1f7a75b94be4a;hpb=a2aac26e6d660e5e70e65d7639a669bced3de9e2;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/keybinder.c b/qcsrc/menu/xonotic/keybinder.c index f4a6c5a3e..66c3486a3 100644 --- a/qcsrc/menu/xonotic/keybinder.c +++ b/qcsrc/menu/xonotic/keybinder.c @@ -22,6 +22,7 @@ CLASS(XonoticKeyBinder) EXTENDS(XonoticListBox) ATTRIB(XonoticKeyBinder, inMouseHandler, float, 0) ATTRIB(XonoticKeyBinder, userbindEditButton, entity, NULL) ATTRIB(XonoticKeyBinder, keyGrabButton, entity, NULL) + ATTRIB(XonoticKeyBinder, clearButton, entity, NULL) ATTRIB(XonoticKeyBinder, userbindEditDialog, entity, NULL) METHOD(XonoticKeyBinder, editUserbind, void(entity, string, string, string)) ENDCLASS(XonoticKeyBinder) @@ -33,7 +34,7 @@ void KeyBinder_Bind_Edit(entity btn, entity me); #ifdef IMPLEMENTATION -string KEY_NOT_BOUND_CMD = "// not bound"; +const string KEY_NOT_BOUND_CMD = "// not bound"; #define MAX_KEYS_PER_FUNCTION 2 #define MAX_KEYBINDS 256 @@ -70,6 +71,19 @@ entity makeXonoticKeyBinder() me.configureXonoticKeyBinder(me); return 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"); + } + if(n) + cvar_set("_hud_showbinds_reload", "1"); +} void XonoticKeyBinder_configureXonoticKeyBinder(entity me) { me.configureXonoticListBox(me); @@ -77,6 +91,18 @@ void XonoticKeyBinder_configureXonoticKeyBinder(entity me) 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 XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { @@ -103,6 +129,7 @@ void KeyBinder_Bind_Change(entity btn, entity me) return; me.keyGrabButton.forcePressed = 1; + me.clearButton.disabled = 1; keyGrabber = me; } void XonoticKeyBinder_keyGrabbed(entity me, float key, float ascii) @@ -111,14 +138,23 @@ void XonoticKeyBinder_keyGrabbed(entity me, float key, float ascii) string func; me.keyGrabButton.forcePressed = 0; + me.clearButton.disabled = 0; + if(key == K_ESCAPE) return; + // forbid these keys from being bound in the menu + if(key == K_CAPSLOCK || key == K_NUMLOCK) + { + KeyBinder_Bind_Change(me, me); + return; + } + func = Xonotic_KeyBinds_Functions[me.selectedItem]; if(func == "") return; - n = tokenize(findkeysforcommand(func)); // uses '...' strings + n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings nvalid = 0; for(j = 0; j < n; ++j) { @@ -138,6 +174,7 @@ void XonoticKeyBinder_keyGrabbed(entity me, float key, float ascii) } localcmd("\nbind \"", keynumtostring(key), "\" \"", func, "\"\n"); localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state + cvar_set("_hud_showbinds_reload", "1"); } void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandPress, string theCommandRelease) { @@ -145,11 +182,11 @@ void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandP if(!me.userbindEditDialog) return; - + func = Xonotic_KeyBinds_Functions[me.selectedItem]; if(func == "") return; - + descr = Xonotic_KeyBinds_Descriptions[me.selectedItem]; if(substring(descr, 0, 1) != "$") return; @@ -166,11 +203,11 @@ void KeyBinder_Bind_Edit(entity btn, entity me) if(!me.userbindEditDialog) return; - + func = Xonotic_KeyBinds_Functions[me.selectedItem]; if(func == "") return; - + descr = Xonotic_KeyBinds_Descriptions[me.selectedItem]; if(substring(descr, 0, 1) != "$") return; @@ -190,7 +227,7 @@ 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)); @@ -199,6 +236,7 @@ void KeyBinder_Bind_Clear(entity btn, entity me) localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n"); } localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state + cvar_set("_hud_showbinds_reload", "1"); } void XonoticKeyBinder_clickListBoxItem(entity me, float i, vector where) { @@ -308,7 +346,7 @@ void XonoticKeyBinder_drawListBoxItem(entity me, float i, vector absSize, float 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) {