ref: f6d6e5fc7b00c79382416a99d7e7548d7dd71185
parent: c5a4f04bc21825a0bdd59bef804229389a7a4ce1
author: Simon Howard <fraggle@gmail.com>
date: Fri Mar 9 07:56:45 EST 2007
Pay closer attention to keyboard mappings. In the menu code, distinguish between keys pressed and characters typed, so that, for example, when the menu prompts "press 'y' to continue", it responds to the _character_ y being typed, not the key that is 'y' on an american keyboard being pressed. Do the same when reading cheats. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 847
--- a/src/am_map.c
+++ b/src/am_map.c
@@ -706,7 +706,7 @@
cheatstate=0;
rc = false;
}
- if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
+ if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data2))
{
rc = false;
cheating = (cheating+1) % 3;
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -1397,6 +1397,7 @@
boolean M_Responder (event_t* ev)
{
int ch;
+ int key;
int i;
static int joywait = 0;
static int mousewait = 0;
@@ -1405,40 +1406,50 @@
static int mousex = 0;
static int lastx = 0;
- ch = -1;
+ // There is a distinction here between the typed character and the key
+ // pressed. 'key' is the key code, while 'ch' is the actual character
+ // typed. For an example, on a German QWERTZ keyboard, if 'z' is
+ // pressed, ch='z' but key='y' (the position it occupies on the
+ // "standard" american keyboard)
+ //
+ // When dealing with actual keys pressed, we must use key, but any time
+ // we want the actual character typed, we use ch.
+
+ key = -1;
+ ch = 0;
if (ev->type == ev_joystick && joywait < I_GetTime())
{
if (ev->data3 == -1)
{
- ch = KEY_UPARROW;
+ key = KEY_UPARROW;
joywait = I_GetTime() + 5;
}
else if (ev->data3 == 1)
{
- ch = KEY_DOWNARROW;
+ key = KEY_DOWNARROW;
joywait = I_GetTime() + 5;
}
if (ev->data2 == -1)
{
- ch = KEY_LEFTARROW;
+ key = KEY_LEFTARROW;
joywait = I_GetTime() + 2;
}
else if (ev->data2 == 1)
{
- ch = KEY_RIGHTARROW;
+ key = KEY_RIGHTARROW;
joywait = I_GetTime() + 2;
}
if (ev->data1&1)
{
- ch = KEY_ENTER;
+ key = KEY_ENTER;
joywait = I_GetTime() + 5;
}
if (ev->data1&2)
{
- ch = KEY_BACKSPACE;
+ key = KEY_BACKSPACE;
joywait = I_GetTime() + 5;
}
}
@@ -1449,13 +1460,13 @@
mousey += ev->data3;
if (mousey < lasty-30)
{
- ch = KEY_DOWNARROW;
+ key = KEY_DOWNARROW;
mousewait = I_GetTime() + 5;
mousey = lasty -= 30;
}
else if (mousey > lasty+30)
{
- ch = KEY_UPARROW;
+ key = KEY_UPARROW;
mousewait = I_GetTime() + 5;
mousey = lasty += 30;
}
@@ -1463,13 +1474,13 @@
mousex += ev->data2;
if (mousex < lastx-30)
{
- ch = KEY_LEFTARROW;
+ key = KEY_LEFTARROW;
mousewait = I_GetTime() + 5;
mousex = lastx -= 30;
}
else if (mousex > lastx+30)
{
- ch = KEY_RIGHTARROW;
+ key = KEY_RIGHTARROW;
mousewait = I_GetTime() + 5;
mousex = lastx += 30;
}
@@ -1476,13 +1487,13 @@
if (ev->data1&1)
{
- ch = KEY_ENTER;
+ key = KEY_ENTER;
mousewait = I_GetTime() + 15;
}
if (ev->data1&2)
{
- ch = KEY_BACKSPACE;
+ key = KEY_BACKSPACE;
mousewait = I_GetTime() + 15;
}
}
@@ -1489,11 +1500,12 @@
else
if (ev->type == ev_keydown)
{
- ch = ev->data1;
+ key = ev->data1;
+ ch = ev->data2;
}
}
- if (ch == -1)
+ if (key == -1)
return false;
// In testcontrols mode, none of the function keys should do anything
@@ -1501,7 +1513,7 @@
if (testcontrols)
{
- if (ch == KEY_ESCAPE || ch == KEY_F10)
+ if (key == KEY_ESCAPE || key == KEY_F10)
{
I_Quit();
return true;
@@ -1513,7 +1525,7 @@
// Save Game string input
if (saveStringEnter)
{
- switch(ch)
+ switch(key)
{
case KEY_BACKSPACE:
if (saveCharIndex > 0)
@@ -1536,9 +1548,12 @@
default:
ch = toupper(ch);
- if (ch != 32)
+ if (ch != ' ')
+ {
if (ch-HU_FONTSTART < 0 || ch-HU_FONTSTART >= HU_FONTSIZE)
break;
+ }
+
if (ch >= 32 && ch <= 127 &&
saveCharIndex < SAVESTRINGSIZE-1 &&
M_StringWidth(savegamestrings[saveSlot]) <
@@ -1545,7 +1560,7 @@
(SAVESTRINGSIZE-2)*8)
{
savegamestrings[saveSlot][saveCharIndex++] = ch;
- savegamestrings[saveSlot][saveCharIndex] = 0;
+ savegamestrings[saveSlot][saveCharIndex] = '\0';
}
break;
}
@@ -1556,7 +1571,7 @@
if (messageToPrint)
{
if (messageNeedsInput == true &&
- !(ch == ' ' || ch == 'n' || ch == 'y' || ch == KEY_ESCAPE))
+ !(ch == ' ' || ch == 'n' || ch == 'y' || key == KEY_ESCAPE))
return false;
menuactive = messageLastMenuActive;
@@ -1569,7 +1584,7 @@
return true;
}
- if (devparm && ch == KEY_F1)
+ if (devparm && key == KEY_F1)
{
G_ScreenShot ();
return true;
@@ -1578,7 +1593,7 @@
// F-Keys
if (!menuactive)
- switch(ch)
+ switch(key)
{
case KEY_MINUS: // Screen size down
if (automapactive || chat_on)
@@ -1669,7 +1684,7 @@
// Pop-up menu?
if (!menuactive)
{
- if (ch == KEY_ESCAPE)
+ if (key == KEY_ESCAPE)
{
M_StartControlPanel ();
S_StartSound(NULL,sfx_swtchn);
@@ -1680,7 +1695,7 @@
// Keys usable within menu
- switch (ch)
+ switch (key)
{
case KEY_DOWNARROW:
do
--- a/src/st_stuff.c
+++ b/src/st_stuff.c
@@ -474,7 +474,7 @@
if (!netgame && gameskill != sk_nightmare)
{
// 'dqd' cheat for toggleable god mode
- if (cht_CheckCheat(&cheat_god, ev->data1))
+ if (cht_CheckCheat(&cheat_god, ev->data2))
{
plyr->cheats ^= CF_GODMODE;
if (plyr->cheats & CF_GODMODE)
@@ -489,7 +489,7 @@
plyr->message = DEH_String(STSTR_DQDOFF);
}
// 'fa' cheat for killer fucking arsenal
- else if (cht_CheckCheat(&cheat_ammonokey, ev->data1))
+ else if (cht_CheckCheat(&cheat_ammonokey, ev->data2))
{
plyr->armorpoints = deh_idfa_armor;
plyr->armortype = deh_idfa_armor_class;
@@ -503,7 +503,7 @@
plyr->message = DEH_String(STSTR_FAADDED);
}
// 'kfa' cheat for key full ammo
- else if (cht_CheckCheat(&cheat_ammo, ev->data1))
+ else if (cht_CheckCheat(&cheat_ammo, ev->data2))
{
plyr->armorpoints = deh_idkfa_armor;
plyr->armortype = deh_idkfa_armor_class;
@@ -520,7 +520,7 @@
plyr->message = DEH_String(STSTR_KFAADDED);
}
// 'mus' cheat for changing music
- else if (cht_CheckCheat(&cheat_mus, ev->data1))
+ else if (cht_CheckCheat(&cheat_mus, ev->data2))
{
char buf[3];
@@ -549,9 +549,9 @@
}
}
else if ( (gamemission == doom
- && cht_CheckCheat(&cheat_noclip, ev->data1))
+ && cht_CheckCheat(&cheat_noclip, ev->data2))
|| (gamemission != doom
- && cht_CheckCheat(&cheat_commercial_noclip,ev->data1)))
+ && cht_CheckCheat(&cheat_commercial_noclip,ev->data2)))
{
// Noclip cheat.
// For Doom 1, use the idspipsopd cheat; for all others, use
@@ -567,7 +567,7 @@
// 'behold?' power-up cheats
for (i=0;i<6;i++)
{
- if (cht_CheckCheat(&cheat_powerup[i], ev->data1))
+ if (cht_CheckCheat(&cheat_powerup[i], ev->data2))
{
if (!plyr->powers[i])
P_GivePower( plyr, i);
@@ -581,12 +581,12 @@
}
// 'behold' power-up menu
- if (cht_CheckCheat(&cheat_powerup[6], ev->data1))
+ if (cht_CheckCheat(&cheat_powerup[6], ev->data2))
{
plyr->message = DEH_String(STSTR_BEHOLD);
}
// 'choppers' invulnerability & chainsaw
- else if (cht_CheckCheat(&cheat_choppers, ev->data1))
+ else if (cht_CheckCheat(&cheat_choppers, ev->data2))
{
plyr->weaponowned[wp_chainsaw] = true;
plyr->powers[pw_invulnerability] = true;
@@ -593,7 +593,7 @@
plyr->message = DEH_String(STSTR_CHOPPERS);
}
// 'mypos' for player position
- else if (cht_CheckCheat(&cheat_mypos, ev->data1))
+ else if (cht_CheckCheat(&cheat_mypos, ev->data2))
{
static char buf[ST_MSGWIDTH];
sprintf(buf, "ang=0x%x;x,y=(0x%x,0x%x)",
@@ -605,7 +605,7 @@
}
// 'clev' change-level cheat
- if (cht_CheckCheat(&cheat_clev, ev->data1))
+ if (cht_CheckCheat(&cheat_clev, ev->data2))
{
char buf[3];
int epsd;