More bind shit

git-svn-id: https://svn.eduke32.com/eduke32@834 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-07-03 07:37:41 +00:00
parent c5d1978aa2
commit 13d4b6fb14
9 changed files with 101 additions and 62 deletions

View file

@ -174,10 +174,10 @@ static int osdcmd_vars(const osdfuncparm_t *parm)
{
int showval = (parm->numparms < 1);
if (!Bstrcasecmp(parm->name, "r_captureformat"))
if (!Bstrcasecmp(parm->name, "r_scrcaptureformat"))
{
const char *fmts[] = {"TGA", "PCX"};
if (showval) { OSD_Printf("r_captureformat is %s\n", fmts[captureformat]); }
if (showval) { OSD_Printf("r_scrcaptureformat is %s\n", fmts[captureformat]); }
else
{
int j;
@ -218,7 +218,7 @@ int baselayer_init(void)
,
osdfunc_setrendermode);
#endif
OSD_RegisterFunction("r_captureformat","screencaptureformat: sets the output format for screenshots (TGA or PCX)",osdcmd_vars);
OSD_RegisterFunction("r_scrcaptureformat","r_scrcaptureformat: sets the output format for screenshots (TGA or PCX)",osdcmd_vars);
#ifdef SUPERBUILD
OSD_RegisterFunction("r_novoxmips","novoxmips: turn off/on the use of mipmaps when rendering 8-bit voxels",osdcmd_vars);
OSD_RegisterFunction("r_voxels","usevoxels: enable/disable automatic sprite->voxel rendering",osdcmd_vars);

View file

@ -725,7 +725,7 @@ int OSD_HandleChars(void)
OSD_Printf("Completions for '%s':\n",osdedittmp);
maxwidth += 3;
symb = tabc;
// OSD_Printf(" ");
OSD_Printf(" ");
while (symb && symb != lastmatch)
{
tabc = symb;
@ -737,8 +737,8 @@ int OSD_HandleChars(void)
{
x = 0;
OSD_Printf("\n");
// if (symb && symb != lastmatch)
// OSD_Printf(" ");
if (symb && symb != lastmatch)
OSD_Printf(" ");
}
}
if (x)

View file

@ -383,14 +383,14 @@ void CONFIG_ReadKeys(void)
boundkeys[key1].key=Bstrdup(keynames[j].name);
else boundkeys[key1].key=Bstrdup(keyname1);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(function));
if (!boundkeys[key1].name[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].name))
if (!boundkeys[key1].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].cmd))
{
Bstrncpy(boundkeys[key1].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncpy(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
else
{
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(function));
Bstrncat(boundkeys[key1].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncat(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
}
if (key2 != 0xff && keyname2[0])
@ -403,14 +403,14 @@ void CONFIG_ReadKeys(void)
boundkeys[key2].key=Bstrdup(keynames[j].name);
else boundkeys[key2].key=Bstrdup(keyname2);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(function));
if (!boundkeys[key2].name[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].name))
if (!boundkeys[key2].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].cmd))
{
Bstrncpy(boundkeys[key2].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncpy(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
else
{
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(function));
Bstrncat(boundkeys[key2].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncat(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
}
}
@ -440,14 +440,14 @@ void MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2
boundkeys[key1].key=Bstrdup(keynames[j].name);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(which));
if (!boundkeys[key1].name[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].name))
if (!boundkeys[key1].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].cmd))
{
Bstrncpy(boundkeys[key1].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncpy(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
else
{
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(which));
Bstrncat(boundkeys[key1].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncat(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
}
if (key2 && key2 != 0xff)
@ -460,20 +460,20 @@ void MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2
boundkeys[key2].key=Bstrdup(keynames[j].name);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(which));
if (!boundkeys[key2].name[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].name))
if (!boundkeys[key2].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].cmd))
{
Bstrncpy(boundkeys[key2].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncpy(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
else
{
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(which));
Bstrncat(boundkeys[key2].name,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncat(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
}
if ((!key1 || key1 == 0xff) && oldkey1)
boundkeys[oldkey1].name[0] = 0;
boundkeys[oldkey1].cmd[0] = 0;
if ((!key2 || key2 == 0xff) && oldkey2)
boundkeys[oldkey2].name[0] = 0;
boundkeys[oldkey2].cmd[0] = 0;
}
/*
@ -851,12 +851,12 @@ void CONFIG_WriteBinds(void) // save binds and aliases to disk
symbol_t *symb;
fprintf(fp,"// this file automatically generated by EDuke32\n// do not modify if you lack common sense\n");
for (i=0;i<MAXBOUNDKEYS;i++)
if (boundkeys[i].key && *boundkeys[i].name)
fprintf(fp,"bind %s%s \"%s\"\n",boundkeys[i].key,boundkeys[i].repeat?"":" norepeat",boundkeys[i].name);
if (boundkeys[i].key && *boundkeys[i].cmd)
fprintf(fp,"bind %s%s \"%s\"\n",boundkeys[i].key,boundkeys[i].repeat?"":" norepeat",boundkeys[i].cmd);
for (i=0;i<MAXMOUSEBUTTONS;i++)
if (mousebind[i].key && *mousebind[i].name)
fprintf(fp,"bind %s%s \"%s\"\n",mousebind[i].key,mousebind[i].repeat?"":" norepeat",mousebind[i].name);
if (mousebind[i].key && *mousebind[i].cmd)
fprintf(fp,"bind %s%s \"%s\"\n",mousebind[i].key,mousebind[i].repeat?"":" norepeat",mousebind[i].cmd);
for (symb=symbols; symb!=NULL; symb=symb->next)
if (symb->func == (void *)OSD_ALIAS)

View file

@ -54,7 +54,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windows.h>
#include <shellapi.h>
extern int getversionfromwebsite(char *buffer);
#define BUILDDATE 20080612
#define BUILDDATE 20080702
#define UPDATEINTERVAL 604800 // 1w
#endif
@ -594,7 +594,7 @@ void getpackets(void)
sampletimer();
AudioUpdate();
CONTROL_ProcessBinds();
// CONTROL_ProcessBinds();
if (ALT_IS_PRESSED && KB_KeyPressed(sc_Enter))
{
@ -10718,6 +10718,9 @@ MAIN_LOOP_RESTART:
AudioUpdate();
// only allow binds to function if the player is actually in a game (not in a menu, typing, et cetera) or demo
bindsenabled = (g_player[myconnectindex].ps->gm == MODE_GAME || g_player[myconnectindex].ps->gm == MODE_DEMO);
OSD_DispatchQueued();
if (ud.recstat == 2 || ud.multimode > 1 || (ud.show_help == 0 && (g_player[myconnectindex].ps->gm&MODE_MENU) != MODE_MENU))

View file

@ -56,8 +56,8 @@ static int32 ticrate;
static int32 CONTROL_DoubleClickSpeed;
int extinput[CONTROL_NUM_FLAGS];
keybind boundkeys[MAXBOUNDKEYS];
keybind mousebind[MAXMOUSEBUTTONS];
keybind boundkeys[MAXBOUNDKEYS], mousebind[MAXMOUSEBUTTONS];
int bindsenabled = 0;
void CONTROL_GetMouseDelta(void)
{
@ -168,10 +168,10 @@ boolean CONTROL_KeyboardFunctionPressed(int32 which)
if (!CONTROL_Flags[which].used) return false;
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !boundkeys[CONTROL_KeyMapping[which].key1].name[0])
if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !boundkeys[CONTROL_KeyMapping[which].key1].cmd[0])
key1 = KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] ? true : false;
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !boundkeys[CONTROL_KeyMapping[which].key1].name[0])
if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !boundkeys[CONTROL_KeyMapping[which].key1].cmd[0])
key2 = KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] ? true : false;
return (key1 | key2);
@ -733,16 +733,19 @@ void CONTROL_ButtonFunctionState(int32 *p1)
for (i=0; i<CONTROL_NumMouseButtons; i++)
{
if (mousebind[i].name[0] && CONTROL_MouseButtonState[i])
if (bindsenabled)
{
if (mousebind[i].repeat || (mousebind[i].laststate == 0))
OSD_Dispatch(mousebind[i].name);
// if (!boundkeys[i].repeat)
// KB_ClearKeyDown(i);
if (mousebind[i].cmd[0] && CONTROL_MouseButtonState[i])
{
if (mousebind[i].repeat || (mousebind[i].laststate == 0))
OSD_Dispatch(mousebind[i].cmd);
// if (!boundkeys[i].repeat)
// KB_ClearKeyDown(i);
}
mousebind[i].laststate = CONTROL_MouseButtonState[i];
}
mousebind[i].laststate = CONTROL_MouseButtonState[i];
if (!mousebind[i].name[0])
if (!mousebind[i].cmd[0])
{
j = CONTROL_MouseButtonMapping[i].doubleclicked;
if (j != KEYUNDEFINED)
@ -863,12 +866,14 @@ void CONTROL_ProcessBinds(void)
{
int i;
for (i=0;i<256;i++)
if (!bindsenabled) return;
for (i=0;i<MAXBOUNDKEYS;i++)
{
if (boundkeys[i].name[0] && KB_KeyPressed(i))
if (boundkeys[i].cmd[0] && KB_KeyPressed(i))
{
if (boundkeys[i].repeat || (boundkeys[i].laststate == 0))
OSD_Dispatch(boundkeys[i].name);
OSD_Dispatch(boundkeys[i].cmd);
// if (!boundkeys[i].repeat)
// KB_ClearKeyDown(i);
}

View file

@ -217,13 +217,15 @@ void CONTROL_PrintAxes( void );
typedef struct binding {
char *key;
char name[MAXBINDSTRINGLENGTH];
char cmd[MAXBINDSTRINGLENGTH];
char repeat;
char laststate;
} keybind;
extern keybind boundkeys[MAXBOUNDKEYS];
extern keybind mousebind[6]; // FIXME
#define MAXMOUSEBUTTONS 6
extern keybind boundkeys[MAXBOUNDKEYS], mousebind[MAXMOUSEBUTTONS];
extern int bindsenabled;
void CONTROL_ProcessBinds(void);

View file

@ -199,7 +199,7 @@ extern kb_scancode KB_LastScan;
#define KB_ClearKeyDown( scan ) { keystatus[ ( scan ) ] = FALSE; }
#define KB_UnBoundKeyPressed( scan ) ( keystatus[ ( scan ) ] != 0 && !boundkeys[scan].name[0])
#define KB_UnBoundKeyPressed( scan ) ( keystatus[ ( scan ) ] != 0 && !boundkeys[scan].cmd[0])
/*
=============================================================================

View file

@ -3594,13 +3594,13 @@ cheat_for_port_credits:
{
ud.config.MouseFunctions[whichkey>>1][whichkey&1] = x;
CONTROL_MapButton(x, whichkey>>1, whichkey&1, controldevice_mouse);
mousebind[whichkey>>1].name[0] = 0;
mousebind[whichkey>>1].cmd[0] = 0; // kill the bind when changing the button in the menu
}
else
{
ud.config.MouseFunctions[whichkey-(MAXMOUSEBUTTONS-2)][0] = x;
CONTROL_MapButton(x, whichkey-(MAXMOUSEBUTTONS-2), 0, controldevice_mouse);
mousebind[whichkey-(MAXMOUSEBUTTONS-2)].name[0] = 0;
mousebind[whichkey-(MAXMOUSEBUTTONS-2)].cmd[0] = 0;
}
cmenu(205);
probey = whichkey;

View file

@ -922,6 +922,7 @@ static int osdcmd_name(const osdfuncparm_t *parm)
static int osdcmd_button(const osdfuncparm_t *parm)
{
char *p = (char *)parm->name+9; // skip "gamefunc_"
// if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game
extinput[CONFIG_FunctionNameToNum(p)] = 1; // FIXME
return OSDCMD_OK;
}
@ -943,16 +944,16 @@ static int osdcmd_bind(const osdfuncparm_t *parm)
OSD_Printf("Current key bindings:\n");
for (i=0;i<MAXBOUNDKEYS;i++)
if (*boundkeys[i].name)
if (boundkeys[i].cmd[0])
{
j++;
OSD_Printf("%-11s = %s\n",boundkeys[i].key,boundkeys[i].name);
OSD_Printf("%-11s = %s\n",boundkeys[i].key,boundkeys[i].cmd);
}
for (i=0;i<MAXMOUSEBUTTONS;i++)
if (*mousebind[i].name)
if (mousebind[i].cmd[0])
{
j++;
OSD_Printf("%-11s = %s\n",mousebind[i].key,mousebind[i].name);
OSD_Printf("%-11s = %s\n",mousebind[i].key,mousebind[i].cmd);
}
if (j == 0)
@ -975,18 +976,27 @@ static int osdcmd_bind(const osdfuncparm_t *parm)
if (parm->numparms < 2)
{
OSD_Printf("%-11s = %s\n",mousenames[i], mousebind[i].name);
OSD_Printf("%-11s = %s\n",mousenames[i], mousebind[i].cmd);
return OSDCMD_OK;
}
j = 1;
mousebind[i].repeat = 1;
if (parm->numparms >= 2 && !Bstrcasecmp(parm->parms[j],"norepeat"))
{
mousebind[i].repeat = 0;
j++;
}
else mousebind[i].repeat = 1;
Bstrncpy(mousebind[i].name,parm->parms[j], MAXBINDSTRINGLENGTH-1);
Bstrcpy(tempbuf,parm->parms[j++]);
for (;j<parm->numparms;j++)
{
Bstrcat(tempbuf," ");
Bstrcat(tempbuf,parm->parms[j++]);
}
Bstrncpy(mousebind[i].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
mousebind[i].key=mousenames[i];
if (!osdexecscript)
OSD_Printf("%s\n",parm->raw);
@ -995,18 +1005,27 @@ static int osdcmd_bind(const osdfuncparm_t *parm)
if (parm->numparms < 2)
{
OSD_Printf("%-11s = %s\n",keynames[i].name, boundkeys[keynames[i].id].name);
OSD_Printf("%-11s = %s\n",keynames[i].name, boundkeys[keynames[i].id].cmd);
return OSDCMD_OK;
}
j = 1;
boundkeys[keynames[i].id].repeat = 1;
if (parm->numparms >= 2 && !Bstrcasecmp(parm->parms[j],"norepeat"))
{
boundkeys[keynames[i].id].repeat = 0;
j++;
}
else boundkeys[keynames[i].id].repeat = 1;
Bstrncpy(boundkeys[keynames[i].id].name,parm->parms[j], MAXBINDSTRINGLENGTH-1);
Bstrcpy(tempbuf,parm->parms[j++]);
for (;j<parm->numparms;j++)
{
Bstrcat(tempbuf," ");
Bstrcat(tempbuf,parm->parms[j++]);
}
Bstrncpy(boundkeys[keynames[i].id].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
boundkeys[keynames[i].id].key=keynames[i].name;
if (!osdexecscript)
OSD_Printf("%s\n",parm->raw);
@ -1020,11 +1039,11 @@ static int osdcmd_unbindall(const osdfuncparm_t *parm)
UNREFERENCED_PARAMETER(parm);
for (i=0;i<MAXBOUNDKEYS;i++)
if (*boundkeys[i].name)
boundkeys[i].name[0] = 0;
if (boundkeys[i].cmd[0])
boundkeys[i].cmd[0] = 0;
for (i=0;i<MAXMOUSEBUTTONS;i++)
if (*mousebind[i].name)
mousebind[i].name[0] = 0;
if (mousebind[i].cmd[0])
mousebind[i].cmd[0] = 0;
OSD_Printf("unbound all keys\n");
return OSDCMD_OK;
}
@ -1045,12 +1064,12 @@ static int osdcmd_unbind(const osdfuncparm_t *parm)
if (i >= MAXMOUSEBUTTONS)
return OSDCMD_SHOWHELP;
mousebind[i].repeat = 0;
mousebind[i].name[0] = 0;
mousebind[i].cmd[0] = 0;
OSD_Printf("unbound %s\n",mousenames[i]);
return OSDCMD_OK;
}
boundkeys[keynames[i].id].repeat = 0;
boundkeys[keynames[i].id].name[0] = 0;
boundkeys[keynames[i].id].cmd[0] = 0;
OSD_Printf("unbound key %s\n",keynames[i].name);
return OSDCMD_OK;
}
@ -1073,6 +1092,14 @@ static int osdcmd_quickload(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
static int osdcmd_screenshot(const osdfuncparm_t *parm)
{
UNREFERENCED_PARAMETER(parm);
KB_ClearKeysDown();
screencapture("duke0000.tga",0);
return OSDCMD_OK;
}
int registerosdcommands(void)
{
unsigned int i;
@ -1135,6 +1162,8 @@ int registerosdcommands(void)
OSD_RegisterFunction("setvar","setvar <gamevar> <value>: sets the value of a gamevar", osdcmd_setvar);
OSD_RegisterFunction("setvarvar","setvar <gamevar> <gamevar>: sets the value of a gamevar", osdcmd_setvar);
OSD_RegisterFunction("setactorvar","setactorvar <actorID> <gamevar> <value>: sets the value of a gamevar", osdcmd_setactorvar);
OSD_RegisterFunction("screenshot","screenshot: takes a screenshot. See r_scrcaptureformat.", osdcmd_screenshot);
OSD_RegisterFunction("spawn","spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",osdcmd_spawn);
OSD_RegisterFunction("unbind","unbind <key>: unbinds a key.", osdcmd_unbind);