X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fmenu%2Fxonotic%2Fkeybinder.c;h=d16e8bb26ede658e06ded51df4cf0fe5ddce36d5;hb=387861a0bee1121b0869bfaf8cff5b703ffc1ad2;hp=3117c65e4800af30675dc597c3a97863d73b1d4e;hpb=ee1bc52fd8269edac22ce73ddecc88583fa1d623;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/keybinder.c b/qcsrc/menu/xonotic/keybinder.c index 3117c65e4..d16e8bb26 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 @@ -47,7 +48,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))) @@ -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,6 +138,8 @@ void XonoticKeyBinder_keyGrabbed(entity me, float key, float ascii) string func; me.keyGrabButton.forcePressed = 0; + me.clearButton.disabled = 0; + if(key == K_ESCAPE) return; @@ -118,7 +147,7 @@ void XonoticKeyBinder_keyGrabbed(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) { @@ -137,6 +166,8 @@ 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) { @@ -144,11 +175,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; @@ -165,11 +196,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; @@ -189,7 +220,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)); @@ -197,7 +228,8 @@ void KeyBinder_Bind_Clear(entity btn, entity me) //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 + cvar_set("_hud_showbinds_reload", "1"); } void XonoticKeyBinder_clickListBoxItem(entity me, float i, vector where) { @@ -307,7 +339,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) {