Make typing submenu into a struct

This commit is contained in:
SinnamonLat 2022-02-26 17:15:45 +01:00
parent ed5005cb05
commit f5bd0dc3e4
3 changed files with 63 additions and 66 deletions

View file

@ -361,20 +361,23 @@ extern INT16 skullAnimCounter; // skull animation counter
extern INT32 menuKey; // keyboard key pressed for menu extern INT32 menuKey; // keyboard key pressed for menu
extern boolean menutyping; // Typing sub-menu
extern boolean menutypingclose; // if true, we're closing the menu.
extern boolean keyboardtyping; // If true, all keystrokes are treated as typing (ignores MBT_A etc). This is unset if you try moving the cursor on the virtual keyboard or use your controller
extern SINT8 menutypingfade; // Fade-in and out for typing sub-menu. (in 10 tics)
// While typing, we'll have a fade strongly darken the screen to overlay the typing menu instead
extern INT16 virtualKeyboard[5][13]; extern INT16 virtualKeyboard[5][13];
extern INT16 shift_virtualKeyboard[5][13]; extern INT16 shift_virtualKeyboard[5][13];
// cursor position on the virtual keyboard grid extern struct menutyping_s
extern SINT8 keyboardx; {
extern SINT8 keyboardy; boolean active; // Active
extern boolean keyboardcapslock; boolean menutypingclose; // Closing
extern boolean keyboardshift; boolean keyboardtyping; // If true, all keystrokes are treated as typing (ignores MBT_A etc). This is unset if you try moving the cursor on the virtual keyboard or use your controller
SINT8 menutypingfade; // fade in and out
SINT8 keyboardx;
SINT8 keyboardy;
boolean keyboardcapslock;
boolean keyboardshift;
} menutyping;
// While typing, we'll have a fade strongly darken the screen to overlay the typing menu instead
#define MENUDELAYTIME 7 #define MENUDELAYTIME 7

View file

@ -230,14 +230,14 @@ static void M_DrawMenuTyping(void)
INT32 i, j; INT32 i, j;
INT32 x = 60; INT32 x = 60;
INT32 y = 100 + (9-menutypingfade)*8; INT32 y = 100 + (9-menutyping.menutypingfade)*8;
INT32 tflag = (9 - menutypingfade)<<V_ALPHASHIFT; INT32 tflag = (9 - menutyping.menutypingfade)<<V_ALPHASHIFT;
consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction;
char buf[8]; // We write there to use drawstring for convenience. char buf[8]; // We write there to use drawstring for convenience.
V_DrawFadeScreen(31, menutypingfade); V_DrawFadeScreen(31, menutyping.menutypingfade);
// Draw the string we're editing at the top. // Draw the string we're editing at the top.
V_DrawString(x, y-48 + 12, V_ALLOWLOWERCASE|tflag, cv->string); V_DrawString(x, y-48 + 12, V_ALLOWLOWERCASE|tflag, cv->string);
@ -245,7 +245,7 @@ static void M_DrawMenuTyping(void)
V_DrawCharacter(x + V_StringWidth(cv->string, 0), y - 35, '_' | 0x80, false); V_DrawCharacter(x + V_StringWidth(cv->string, 0), y - 35, '_' | 0x80, false);
// Some contextual stuff // Some contextual stuff
if (keyboardtyping) if (menutyping.keyboardtyping)
V_DrawThinString(10, 175, V_ALLOWLOWERCASE|tflag|V_GRAYMAP, "Type using your keyboard. Press Enter to confirm & exit.\nUse your controller or any directional input to use the Virtual Keyboard.\n"); V_DrawThinString(10, 175, V_ALLOWLOWERCASE|tflag|V_GRAYMAP, "Type using your keyboard. Press Enter to confirm & exit.\nUse your controller or any directional input to use the Virtual Keyboard.\n");
else else
V_DrawThinString(10, 175, V_ALLOWLOWERCASE|tflag|V_GRAYMAP, "Type using the Virtual Keyboard. Use the \'OK\' button to confirm & exit.\nPress any keyboard key not bound to a control to use it."); V_DrawThinString(10, 175, V_ALLOWLOWERCASE|tflag|V_GRAYMAP, "Type using the Virtual Keyboard. Use the \'OK\' button to confirm & exit.\nPress any keyboard key not bound to a control to use it.");
@ -258,7 +258,7 @@ static void M_DrawMenuTyping(void)
{ {
INT32 mflag = 0; INT32 mflag = 0;
INT16 c = virtualKeyboard[i][j]; INT16 c = virtualKeyboard[i][j];
if (keyboardshift ^ keyboardcapslock) if (menutyping.keyboardshift ^ menutyping.keyboardcapslock)
c = shift_virtualKeyboard[i][j]; c = shift_virtualKeyboard[i][j];
@ -284,9 +284,9 @@ static void M_DrawMenuTyping(void)
} }
// highlight: // highlight:
if (keyboardx == j && keyboardy == i && !keyboardtyping) if (menutyping.keyboardx == j && menutyping.keyboardy == i && !menutyping.keyboardtyping)
mflag |= highlightflags; mflag |= highlightflags;
else if (keyboardtyping) else if (menutyping.keyboardtyping)
mflag |= V_TRANSLUCENT; // grey it out if we can't use it. mflag |= V_TRANSLUCENT; // grey it out if we can't use it.
V_DrawString(x, y, V_ALLOWLOWERCASE|tflag|mflag, buf); V_DrawString(x, y, V_ALLOWLOWERCASE|tflag|mflag, buf);
@ -353,7 +353,7 @@ void M_Drawer(void)
} }
// Draw typing overlay when needed, above all other menu elements. // Draw typing overlay when needed, above all other menu elements.
if (menutyping) if (menutyping.active)
M_DrawMenuTyping(); M_DrawMenuTyping();
} }

View file

@ -97,16 +97,10 @@ INT32 menuKey = -1; // keyboard key pressed for menu
menucmd_t menucmd[MAXSPLITSCREENPLAYERS]; menucmd_t menucmd[MAXSPLITSCREENPLAYERS];
// Typing "sub"-menu // Typing "sub"-menu
boolean menutyping = false;
boolean menutypingclose = false;
SINT8 menutypingfade = 0;
boolean keyboardtyping = false;
SINT8 keyboardx = 0; struct menutyping_s menutyping;
SINT8 keyboardy = 0;
boolean keyboardcapslock = false;
boolean keyboardshift = false;
// keyboard layouts
INT16 virtualKeyboard[5][13] = { INT16 virtualKeyboard[5][13] = {
{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0}, {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0},
@ -922,7 +916,7 @@ boolean M_Responder(event_t *ev)
} }
// Typing for CV_IT_STRING // Typing for CV_IT_STRING
if (menutyping && !menutypingclose && keyboardtyping) if (menutyping.active && !menutyping.menutypingclose && menutyping.keyboardtyping)
{ {
M_ChangeStringCvar(menuKey); M_ChangeStringCvar(menuKey);
} }
@ -1194,8 +1188,8 @@ boolean M_MenuButtonPressed(UINT8 pid, UINT32 bt)
static void M_UpdateKeyboardX(void) static void M_UpdateKeyboardX(void)
{ {
// 0s are only at the rightmost edges of the keyboard table, so just go backwards until we get something. // 0s are only at the rightmost edges of the keyboard table, so just go backwards until we get something.
while (!virtualKeyboard[keyboardy][keyboardx]) while (!virtualKeyboard[menutyping.keyboardy][menutyping.keyboardx])
keyboardx--; menutyping.keyboardx--;
} }
static boolean M_IsTypingKey(INT32 key) static boolean M_IsTypingKey(INT32 key)
@ -1211,25 +1205,25 @@ static void M_MenuTypingInput(INT32 key)
// Fade-in // Fade-in
if (menutypingclose) // closing if (menutyping.menutypingclose) // closing
{ {
menutypingfade--; menutyping.menutypingfade--;
if (!menutypingfade) if (!menutyping.menutypingfade)
menutyping = false; menutyping.active = false;
return; // prevent inputs while closing the menu. return; // prevent inputs while closing the menu.
} }
else // opening else // opening
{ {
menutypingfade++; menutyping.menutypingfade++;
if (menutypingfade > 9) // Don't fade all the way, but have it VERY strong to be readable if (menutyping.menutypingfade > 9) // Don't fade all the way, but have it VERY strong to be readable
menutypingfade = 9; menutyping.menutypingfade = 9;
else if (menutypingfade < 9) else if (menutyping.menutypingfade < 9)
return; // Don't allow typing until it's fully opened. return; // Don't allow typing until it's fully opened.
} }
// Determine when to check for keyboard inputs or controller inputs using menuKey, which is the key passed here as argument. // Determine when to check for keyboard inputs or controller inputs using menuKey, which is the key passed here as argument.
if (!keyboardtyping) // controller inputs if (!menutyping.keyboardtyping) // controller inputs
{ {
// we pressed a keyboard input that's not any of our buttons // we pressed a keyboard input that's not any of our buttons
if (M_IsTypingKey(key) && menucmd[pid].dpad_lr == 0 && menucmd[pid].dpad_ud == 0 if (M_IsTypingKey(key) && menucmd[pid].dpad_lr == 0 && menucmd[pid].dpad_ud == 0
@ -1240,7 +1234,7 @@ static void M_MenuTypingInput(INT32 key)
&& !(menucmd[pid].buttons & MBT_Y) && !(menucmd[pid].buttons & MBT_Y)
&& !(menucmd[pid].buttons & MBT_Z)) && !(menucmd[pid].buttons & MBT_Z))
{ {
keyboardtyping = true; menutyping.keyboardtyping = true;
} }
} }
else // Keyboard inputs. else // Keyboard inputs.
@ -1257,26 +1251,26 @@ static void M_MenuTypingInput(INT32 key)
|| menucmd[pid].dpad_ud != 0 || menucmd[pid].dpad_ud != 0
)) ))
{ {
keyboardtyping = false; menutyping.keyboardtyping = false;
return; return;
} }
// OTHERWISE, process keyboard inputs for typing! // OTHERWISE, process keyboard inputs for typing!
if (key == KEY_ENTER) if (key == KEY_ENTER)
{ {
menutypingclose = true; // close menu. menutyping.menutypingclose = true; // close menu.
return; return;
} }
} }
if (menucmd[pid].delay == 0 && !keyboardtyping) // We must check for this here because we bypass the normal delay check to allow for normal keyboard inputs if (menucmd[pid].delay == 0 && !menutyping.keyboardtyping) // We must check for this here because we bypass the normal delay check to allow for normal keyboard inputs
{ {
if (menucmd[pid].dpad_ud > 0) // down if (menucmd[pid].dpad_ud > 0) // down
{ {
keyboardy++; menutyping.keyboardy++;
if (keyboardy > 4) if (menutyping.keyboardy > 4)
keyboardy = 0; menutyping.keyboardy = 0;
M_UpdateKeyboardX(); M_UpdateKeyboardX();
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
@ -1284,9 +1278,9 @@ static void M_MenuTypingInput(INT32 key)
} }
else if (menucmd[pid].dpad_ud < 0) // up else if (menucmd[pid].dpad_ud < 0) // up
{ {
keyboardy--; menutyping.keyboardy--;
if (keyboardy < 0) if (menutyping.keyboardy < 0)
keyboardy = 4; menutyping.keyboardy = 4;
M_UpdateKeyboardX(); M_UpdateKeyboardX();
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
@ -1294,19 +1288,19 @@ static void M_MenuTypingInput(INT32 key)
} }
else if (menucmd[pid].dpad_lr > 0) // right else if (menucmd[pid].dpad_lr > 0) // right
{ {
keyboardx++; menutyping.keyboardx++;
if (!virtualKeyboard[keyboardy][keyboardx]) if (!virtualKeyboard[menutyping.keyboardy][menutyping.keyboardx])
keyboardx = 0; menutyping.keyboardx = 0;
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
S_StartSound(NULL, sfx_menu1); S_StartSound(NULL, sfx_menu1);
} }
else if (menucmd[pid].dpad_lr < 0) // left else if (menucmd[pid].dpad_lr < 0) // left
{ {
keyboardx--; menutyping.keyboardx--;
if (keyboardx < 0) if (menutyping.keyboardx < 0)
{ {
keyboardx = 12; menutyping.keyboardx = 12;
M_UpdateKeyboardX(); M_UpdateKeyboardX();
} }
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
@ -1315,23 +1309,23 @@ static void M_MenuTypingInput(INT32 key)
else if (M_MenuButtonPressed(pid, MBT_A) || M_MenuButtonPressed(pid, MBT_X)) else if (M_MenuButtonPressed(pid, MBT_A) || M_MenuButtonPressed(pid, MBT_X))
{ {
// Add the character. First though, check what we're pressing.... // Add the character. First though, check what we're pressing....
INT16 c = virtualKeyboard[keyboardy][keyboardx]; INT16 c = virtualKeyboard[menutyping.keyboardy][menutyping.keyboardx];
if (keyboardshift ^ keyboardcapslock) if (menutyping.keyboardshift ^ menutyping.keyboardcapslock)
c = shift_virtualKeyboard[keyboardy][keyboardx]; c = shift_virtualKeyboard[menutyping.keyboardy][menutyping.keyboardx];
if (c == KEY_RSHIFT) if (c == KEY_RSHIFT)
keyboardshift = !keyboardshift; menutyping.keyboardshift = !menutyping.keyboardshift;
else if (c == KEY_CAPSLOCK) else if (c == KEY_CAPSLOCK)
keyboardcapslock = !keyboardcapslock; menutyping.keyboardcapslock = !menutyping.keyboardcapslock;
else if (c == KEY_ENTER) else if (c == KEY_ENTER)
{ {
menutypingclose = true; // close menu. menutyping.menutypingclose = true; // close menu.
return; return;
} }
else else
{ {
M_ChangeStringCvar((INT32)c); // Write! M_ChangeStringCvar((INT32)c); // Write!
keyboardshift = false; // undo shift if it had been pressed menutyping.keyboardshift = false; // undo shift if it had been pressed
} }
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
@ -1353,7 +1347,7 @@ static void M_HandleMenuInput(void)
} }
// Typing for CV_IT_STRING // Typing for CV_IT_STRING
if (menutyping) if (menutyping.active)
{ {
M_MenuTypingInput(menuKey); M_MenuTypingInput(menuKey);
return; return;
@ -1427,9 +1421,9 @@ static void M_HandleMenuInput(void)
// If we're hovering over a IT_CV_STRING option, pressing A/X opens the typing submenu // If we're hovering over a IT_CV_STRING option, pressing A/X opens the typing submenu
if (M_MenuButtonPressed(pid, MBT_A) || M_MenuButtonPressed(pid, MBT_X)) if (M_MenuButtonPressed(pid, MBT_A) || M_MenuButtonPressed(pid, MBT_X))
{ {
keyboardtyping = menuKey != 0 ? true : false; // If we entered this menu by pressing a menu Key, default to keyboard typing, otherwise use controller. menutyping.keyboardtyping = menuKey != 0 ? true : false; // If we entered this menu by pressing a menu Key, default to keyboard typing, otherwise use controller.
menutyping = true; menutyping.active = true;
menutypingclose = false; menutyping.menutypingclose = false;
return; return;
} }