From ef2683418ef85b3f54421c830d9f9926889544d0 Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 30 Jun 2008 09:00:33 +0000 Subject: [PATCH] Keyboard configuration menu <-> binds git-svn-id: https://svn.eduke32.com/eduke32@822 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/config.c | 41 +++++++++++++++++++++++--- polymer/eduke32/source/config.h | 2 ++ polymer/eduke32/source/jmact/control.h | 1 + polymer/eduke32/source/menus.c | 11 +++++-- polymer/eduke32/source/osdcmds.c | 4 +-- 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 52dfbefcc..b8c696ca3 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -150,7 +150,8 @@ void CONFIG_SetDefaultKeys(int type) { int32 i,f; - memset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys)); + Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys)); + Bmemset(&boundkeys,0,sizeof(boundkeys)); if (type == 1) { @@ -162,7 +163,7 @@ void CONFIG_SetDefaultKeys(int type) ud.config.KeyboardKeys[f][1] = KB_StringToScanCode((char *)oldkeydefaults[i+2]); if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]); - else CONTROL_MapKey(f, ud.config.KeyboardKeys[f][0], ud.config.KeyboardKeys[f][1]); + else MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0); } return; } @@ -175,7 +176,7 @@ void CONFIG_SetDefaultKeys(int type) ud.config.KeyboardKeys[f][1] = KB_StringToScanCode(keydefaults[i+2]); if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]); - else CONTROL_MapKey(f, ud.config.KeyboardKeys[f][0], ud.config.KeyboardKeys[f][1]); + else MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0); } } @@ -420,10 +421,42 @@ void CONFIG_ReadKeys(void) if (i == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[i][0]); else - CONTROL_MapKey(i, ud.config.KeyboardKeys[i][0], ud.config.KeyboardKeys[i][1]); + MapKey(i, ud.config.KeyboardKeys[i][0], 0, ud.config.KeyboardKeys[i][1], 0); } } +void MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2) +{ + int j; + + CONTROL_MapKey(which, key1, key2); + if (key1) + { + boundkeys[key1].repeat = 1; + for (j=0;keynames[j].name;j++) + if (key1 == keynames[j].id) + break; + if (keynames[j].name) + boundkeys[key1].key=Bstrdup(keynames[j].name); + Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(which)); + Bstrncpy(boundkeys[key1].name,tempbuf, MAXBINDSTRINGLENGTH-1); + } + if (key2) + { + boundkeys[key2].repeat = 1; + for (j=0;keynames[j].name;j++) + if (key2 == keynames[j].id) + break; + if (keynames[j].name) + boundkeys[key2].key=Bstrdup(keynames[j].name); + Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(which)); + Bstrncpy(boundkeys[key2].name,tempbuf, MAXBINDSTRINGLENGTH-1); + } + if (!key1 && oldkey1) + boundkeys[oldkey1].name[0] = 0; + if (!key2 && oldkey2) + boundkeys[oldkey2].name[0] = 0; +} /* =================== diff --git a/polymer/eduke32/source/config.h b/polymer/eduke32/source/config.h index d9ed3a9f7..2f9d2cf7e 100644 --- a/polymer/eduke32/source/config.h +++ b/polymer/eduke32/source/config.h @@ -37,4 +37,6 @@ void CONFIG_SetDefaultKeys(int type); int32 CONFIG_GetMapBestTime(char *mapname); int32 CONFIG_SetMapBestTime(char *mapname, int32 tm); +void MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2); + #endif diff --git a/polymer/eduke32/source/jmact/control.h b/polymer/eduke32/source/jmact/control.h index 8c799b735..be58f39b2 100644 --- a/polymer/eduke32/source/jmact/control.h +++ b/polymer/eduke32/source/jmact/control.h @@ -227,6 +227,7 @@ extern keybind boundkeys[MAXBOUNDKEYS]; void CONTROL_ProcessBinds(void); #define CONTROL_NUM_FLAGS 64 +extern int extinput[CONTROL_NUM_FLAGS]; #ifdef __cplusplus }; diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 9e3c9788f..339099346 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -3350,8 +3350,11 @@ cheat_for_port_credits: } else if (KB_KeyPressed(sc_Delete)) { + char key[2]; + key[0] = ud.config.KeyboardKeys[probey][0]; + key[1] = ud.config.KeyboardKeys[probey][1]; ud.config.KeyboardKeys[probey][currentlist] = 0; - CONTROL_MapKey(probey, ud.config.KeyboardKeys[probey][0], ud.config.KeyboardKeys[probey][1]); + MapKey(probey, ud.config.KeyboardKeys[probey][0], key[0], ud.config.KeyboardKeys[probey][1], key[1]); sound(KICK_HIT); KB_ClearKeyDown(sc_Delete); } @@ -3406,13 +3409,17 @@ cheat_for_port_credits: } else { + char key[2]; + key[0] = ud.config.KeyboardKeys[function][0]; + key[1] = ud.config.KeyboardKeys[function][1]; + sound(PISTOL_BODYHIT); ud.config.KeyboardKeys[function][whichkey] = KB_GetLastScanCode(); if (function == gamefunc_Show_Console) OSD_CaptureKey(KB_GetLastScanCode()); else - CONTROL_MapKey(function, ud.config.KeyboardKeys[function][0], ud.config.KeyboardKeys[function][1]); + MapKey(function, ud.config.KeyboardKeys[function][0], key[0], ud.config.KeyboardKeys[function][1], key[1]); } cmenu(204); diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index d007d1d92..c9643a35a 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -918,12 +918,10 @@ static int osdcmd_name(const osdfuncparm_t *parm) return OSDCMD_OK; } -extern int extinput[CONTROL_NUM_FLAGS]; - static int osdcmd_button(const osdfuncparm_t *parm) { char *p = (char *)parm->name+9; // skip "gamefunc_" - extinput[CONFIG_FunctionNameToNum(p)] = 1; + extinput[CONFIG_FunctionNameToNum(p)] = 1; // FIXME return OSDCMD_OK; }