mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 02:30:46 +00:00
Somewhat largish commit with various keyboard tinkering for Mapster.
The main change consist of adding a key press (and release) callback whose only purpose is to be used from m32script as EVENT_KEYPRESS. When entering that event, the RETURN variable will be set to the keystatus code of the key, and whether it was pressed or released can be checked by looking at keystatus[] at that code (ifholdkey and ifhitkey do this). The purpose of this, then, is to be able to remap keys in a more general (and complicated) fashion than is possible with the mapster32.cfg 'remap' option. Various other additions build around this central one: - add an example EVENT_KEYPRESS to a.m32, among other things emulating the keypad arrows with Alt-<normal arrows> for notebook convenience; disabled initially - a.m32: set 'owner' with Alt-KP2: now Alt-Shift-KP2, because of collision with the above - new m32script command: setkey <keycode>, setting keystatus[<keycode>] to 1 (note: may be restricted to use in EVENT_KEYPRESS only in the future) - fix indexing an m32script array with a defined label, there used to be a 'not a gamevar' error instead - add the following constant labels for some key codes: KEY_SCROLL, KEY_F1 .. KEY_F12 git-svn-id: https://svn.eduke32.com/eduke32@2122 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
9a8603d01e
commit
39314586ac
6 changed files with 99 additions and 5 deletions
|
@ -95,6 +95,7 @@ enum GameEvent_t {
|
|||
EVENT_PREKEYS2D,
|
||||
EVENT_PREKEYS3D,
|
||||
EVENT_LINKTAGS,
|
||||
EVENT_KEYPRESS,
|
||||
MAXEVENTS
|
||||
};
|
||||
|
||||
|
|
|
@ -419,6 +419,12 @@ static void reset_default_mapstate(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void m32_keypresscallback(int32_t code, int32_t downp)
|
||||
{
|
||||
g_iReturnVar = code;
|
||||
VM_OnEvent(EVENT_KEYPRESS, -1);
|
||||
}
|
||||
|
||||
#undef STARTUP_SETUP_WINDOW
|
||||
#if defined RENDERTYPEWIN || (defined RENDERTYPESDL && !defined __APPLE__ && defined HAVE_GTK2)
|
||||
# define STARTUP_SETUP_WINDOW
|
||||
|
@ -590,6 +596,8 @@ int32_t app_main(int32_t argc, const char **argv)
|
|||
|
||||
updatesector(pos.x,pos.y,&cursectnum);
|
||||
|
||||
setkeypresscallback(&m32_keypresscallback);
|
||||
|
||||
if (cursectnum == -1)
|
||||
{
|
||||
vid_gamma_3d = vid_gamma;
|
||||
|
|
|
@ -30,6 +30,9 @@ gamevar use_custom_aspect 0 0 // this is now the same as r_usenewaspect
|
|||
gamevar davr 65536 0
|
||||
gamevar dayx 65536 0
|
||||
|
||||
// whether to remap certain widely-available keys to rare ones
|
||||
// (notebook/netbook convenience, see EVENT_KEYPRESS for details)
|
||||
gamevar use_notebook_keys 0 0
|
||||
|
||||
// see end of file for more user settings and examples
|
||||
|
||||
|
@ -300,7 +303,7 @@ defstate fiddlewithlights
|
|||
getnumber256 .yvel "YVEL: " 0
|
||||
getnumber256 .zvel "ZVEL: " 0
|
||||
}
|
||||
else ifhitkey KEY_KP2
|
||||
else ifeithershift ifhitkey KEY_KP2 // alt-kp2 collides with KP* replacement
|
||||
{
|
||||
getnumber256 .owner "OWNER: " 0
|
||||
ifl .owner 0 set .owner -1
|
||||
|
@ -1202,6 +1205,66 @@ defstate userkeys_3d
|
|||
ifholdkey KEY_SEMI ifhitkey KEY_C state chselshade
|
||||
ends
|
||||
|
||||
// convenience rebindings for notebooks:
|
||||
// Alt-F11 --> SCROLL LOCK (set first position)
|
||||
// Alt-arrows --> KP arrows (change pan/repeat in 3D mode)
|
||||
onevent EVENT_KEYPRESS
|
||||
var thekey
|
||||
set thekey RETURN
|
||||
|
||||
ifvare use_notebook_keys 0, return
|
||||
/*
|
||||
ifholdkey thekey
|
||||
qsprintf TQUOTE "pressed %d" thekey
|
||||
else
|
||||
qsprintf TQUOTE "released %d" thekey
|
||||
print TQUOTE
|
||||
*/
|
||||
ifholdkey thekey // if the callback key was pressed (and not released)
|
||||
{
|
||||
ifholdkey KEY_LALT
|
||||
{
|
||||
ifhitkey KEY_F11, setkey KEY_SCROLL
|
||||
|
||||
ifhitkey KEY_UP, setkey KEY_KP8
|
||||
ifhitkey KEY_DOWN, setkey KEY_KP2
|
||||
ifhitkey KEY_LEFT, setkey KEY_KP4
|
||||
ifhitkey KEY_RIGHT, setkey KEY_KP6
|
||||
|
||||
// would be 'cleaner' (only checking cb key) but is too much code for my taste:
|
||||
/*
|
||||
switch (thekey)
|
||||
{
|
||||
case KEY_F11: setkey KEY_SCROLL; resetkey thekey; break;
|
||||
|
||||
// and so on with the rest...
|
||||
}
|
||||
endswitch
|
||||
*/
|
||||
}
|
||||
}
|
||||
else // cb key was released
|
||||
{
|
||||
switch (thekey)
|
||||
{
|
||||
case KEY_LALT:
|
||||
{
|
||||
resetkey KEY_KP8;
|
||||
resetkey KEY_KP2;
|
||||
resetkey KEY_KP4;
|
||||
resetkey KEY_KP6;
|
||||
break;
|
||||
}
|
||||
|
||||
case KEY_UP: resetkey KEY_KP8; break;
|
||||
case KEY_DOWN: resetkey KEY_KP2; break;
|
||||
case KEY_LEFT: resetkey KEY_KP4; break;
|
||||
case KEY_RIGHT: resetkey KEY_KP6; break;
|
||||
}
|
||||
endswitch
|
||||
}
|
||||
endevent
|
||||
|
||||
/*
|
||||
// example for custom labels
|
||||
defstate userdrawlabel
|
||||
|
|
|
@ -304,6 +304,7 @@ const char *keyw[] =
|
|||
|
||||
// BUILD functions
|
||||
"resetkey",
|
||||
"setkey",
|
||||
"insertsprite",
|
||||
"dupsprite",
|
||||
"tdupsprite",
|
||||
|
@ -1253,7 +1254,7 @@ static void C_GetNextVarType(int32_t type)
|
|||
id = GetGamevarID(tlabel, 1);
|
||||
if (id < 0) //gamevar not found
|
||||
{
|
||||
if (!type && !cs.labelsOnly)
|
||||
if (!(type&GV_WRITABLE) && !cs.labelsOnly)
|
||||
{
|
||||
//try looking for a define instead
|
||||
id = hash_find(&h_labels, tlabel);
|
||||
|
@ -3053,6 +3054,7 @@ repeatcase:
|
|||
g_numCompilerWarnings++;
|
||||
}
|
||||
case CON_RESETKEY:
|
||||
case CON_SETKEY:
|
||||
case CON_INSERTSPRITE:
|
||||
case CON_DUPSPRITE:
|
||||
case CON_DELETESPRITE:
|
||||
|
@ -3503,6 +3505,7 @@ static void C_AddDefaultDefinitions(void)
|
|||
C_AddDefinition("EVENT_PREKEYS2D", EVENT_PREKEYS2D, LABEL_EVENT);
|
||||
C_AddDefinition("EVENT_PREKEYS3D", EVENT_PREKEYS3D, LABEL_EVENT);
|
||||
C_AddDefinition("EVENT_LINKTAGS", EVENT_LINKTAGS, LABEL_EVENT);
|
||||
C_AddDefinition("EVENT_KEYPRESS", EVENT_KEYPRESS, LABEL_EVENT);
|
||||
|
||||
C_AddDefinition("CLIPMASK0", CLIPMASK0, LABEL_DEFINE);
|
||||
C_AddDefinition("CLIPMASK1", CLIPMASK1, LABEL_DEFINE);
|
||||
|
@ -3607,6 +3610,8 @@ static void C_AddDefaultDefinitions(void)
|
|||
C_AddDefinition("KEY_gSTAR", KEYSC_gSTAR, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_gUP", KEYSC_gUP, LABEL_DEFINE);
|
||||
|
||||
C_AddDefinition("KEY_SCROLL", KEYSC_SCROLL, LABEL_DEFINE);
|
||||
|
||||
C_AddDefinition("KEY_HOME", KEYSC_HOME, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_UP", KEYSC_UP, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_PGUP", KEYSC_PGUP, LABEL_DEFINE);
|
||||
|
@ -3617,6 +3622,19 @@ static void C_AddDefaultDefinitions(void)
|
|||
C_AddDefinition("KEY_PGDN", KEYSC_PGDN, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_INSERT", KEYSC_INSERT, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_DELETE", KEYSC_DELETE, LABEL_DEFINE);
|
||||
|
||||
C_AddDefinition("KEY_F1", KEYSC_F1, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F2", KEYSC_F2, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F3", KEYSC_F3, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F4", KEYSC_F4, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F5", KEYSC_F5, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F6", KEYSC_F6, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F7", KEYSC_F7, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F8", KEYSC_F8, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F9", KEYSC_F9, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F10", KEYSC_F10, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F11", KEYSC_F11, LABEL_DEFINE);
|
||||
C_AddDefinition("KEY_F12", KEYSC_F12, LABEL_DEFINE);
|
||||
// end keys
|
||||
|
||||
// C_AddDefinition("STR_MAPFILENAME",STR_MAPFILENAME, LABEL_DEFINE);
|
||||
|
|
|
@ -449,8 +449,11 @@ enum ScriptKeywords_t
|
|||
CON_IFAIMINGSECTOR,
|
||||
CON_IFINTERACTIVE,
|
||||
|
||||
// BUILD functions
|
||||
// keyboard
|
||||
CON_RESETKEY,
|
||||
CON_SETKEY,
|
||||
|
||||
// BUILD functions
|
||||
CON_INSERTSPRITE,
|
||||
CON_DUPSPRITE,
|
||||
CON_TDUPSPRITE,
|
||||
|
|
|
@ -1496,6 +1496,7 @@ badindex:
|
|||
case CON_IFHITKEY:
|
||||
case CON_IFHOLDKEY:
|
||||
case CON_RESETKEY:
|
||||
case CON_SETKEY:
|
||||
insptr++;
|
||||
{
|
||||
int32_t key=Gv_GetVarX(*insptr);
|
||||
|
@ -1505,7 +1506,7 @@ badindex:
|
|||
continue;
|
||||
}
|
||||
|
||||
if (tw != CON_RESETKEY)
|
||||
if (tw == CON_IFHITKEY || tw == CON_IFHOLDKEY)
|
||||
VM_DoConditional(keystatus[key]);
|
||||
else
|
||||
insptr++;
|
||||
|
@ -1515,7 +1516,7 @@ badindex:
|
|||
if (!(key==0 || key==KEYSC_ESC || key==KEYSC_TILDE || key==KEYSC_gENTER ||
|
||||
key==KEYSC_LALT || key==KEYSC_RALT || key==KEYSC_LCTRL || key==KEYSC_RCTRL ||
|
||||
key==KEYSC_LSHIFT || key==KEYSC_RSHIFT))
|
||||
keystatus[key] = 0;
|
||||
keystatus[key] = (tw==CON_SETKEY);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue