Deduplicate character shifting code

This commit is contained in:
fickleheart 2019-03-10 18:09:15 -05:00
parent c0ea785900
commit c65ff70faf
4 changed files with 20 additions and 29 deletions

View file

@ -544,6 +544,22 @@ static void CON_MoveConsole(void)
}
}
INT32 CON_ShiftChar(INT32 ch)
{
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
if (shiftdown ^ capslock)
ch = shiftxform[ch];
}
else // if we're holding shift we should still shift non letter symbols
{
if (shiftdown)
ch = shiftxform[ch];
}
return ch;
}
// Clear time of console heads up messages
//
void CON_ClearHUD(void)

View file

@ -44,6 +44,8 @@ extern UINT8 *yellowmap, *purplemap, *greenmap, *bluemap, *graymap, *redmap, *or
// Console bg color (auto updated to match)
extern UINT8 *consolebgmap;
INT32 CON_ShiftChar(INT32 ch);
void CON_SetupBackColormap(void);
void CON_ClearHUD(void); // clear heads up messages

View file

@ -2228,24 +2228,8 @@ boolean CL_Responder(event_t *ev)
len = strlen(cl_challengepassword);
if (len < 64)
{
// shifting code stolen from lat by fickle, thx :)
// I know this looks very messy but this works. If it ain't broke, don't fix it!
// shift LETTERS to uppercase if we have capslock or are holding shift
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
if (shiftdown ^ capslock)
ch = shiftxform[ch];
}
else // if we're holding shift we should still shift non letter symbols
{
if (shiftdown)
ch = shiftxform[ch];
}
cl_challengepassword[len+1] = 0;
cl_challengepassword[len] = ch;
cl_challengepassword[len] = CON_ShiftChar(ch);
}
cl_challengeattempted = 0;

View file

@ -1293,18 +1293,7 @@ boolean HU_Responder(event_t *ev)
&& ev->data1 != gamecontrol[gc_talkkey][1]))
return false;
// I know this looks very messy but this works. If it ain't broke, don't fix it!
// shift LETTERS to uppercase if we have capslock or are holding shift
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
if (shiftdown ^ capslock)
c = shiftxform[c];
}
else // if we're holding shift we should still shift non letter symbols
{
if (shiftdown)
c = shiftxform[c];
}
c = CON_ShiftChar(c);
// pasting. pasting is cool. chat is a bit limited, though :(
if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE)