Menu Messages: Call the routine after it closes, not the moment you press the button

Slicker, prevents the issue where a transition after pressing accept on a prompt would be instant.
Also guarantees M_StopMessage is called even for MM_NOTHING, even with a custom routine.
This commit is contained in:
toaster 2023-06-17 13:30:03 +01:00
parent 3b272ddb97
commit e9f9cfd051
5 changed files with 17 additions and 23 deletions

View file

@ -533,6 +533,7 @@ extern struct menumessage_s
void (*routine)(INT32 choice); // Normal routine void (*routine)(INT32 choice); // Normal routine
//void (*eroutine)(event_t *ev); // Event routine (MM_EVENTHANDLER) //void (*eroutine)(event_t *ev); // Event routine (MM_EVENTHANDLER)
INT32 answer;
const char *defaultstr; const char *defaultstr;
const char *confirmstr; const char *confirmstr;

View file

@ -101,11 +101,12 @@ static boolean prevmajormods = false;
static void M_AddonsClearName(INT32 choice) static void M_AddonsClearName(INT32 choice)
{ {
(void)choice;
if (!majormods || prevmajormods) if (!majormods || prevmajormods)
{ {
CLEARNAME; CLEARNAME;
} }
M_StopMessage(choice);
} }
// Handles messages for addon errors. // Handles messages for addon errors.

View file

@ -414,7 +414,6 @@ static void M_WriteGuestReplay(INT32 ch)
if (FIL_FileExists(rguest)) if (FIL_FileExists(rguest))
{ {
//M_StopMessage(0);
remove(rguest); remove(rguest);
} }

View file

@ -71,6 +71,7 @@ void M_StartMessage(const char *header, const char *string, void (*routine)(INT3
menumessage.header = header; menumessage.header = header;
menumessage.flags = itemtype; menumessage.flags = itemtype;
menumessage.routine = routine; menumessage.routine = routine;
menumessage.answer = MA_NONE;
menumessage.fadetimer = 1; menumessage.fadetimer = 1;
menumessage.timer = 0; menumessage.timer = 0;
menumessage.closing = false; menumessage.closing = false;
@ -82,7 +83,6 @@ void M_StartMessage(const char *header, const char *string, void (*routine)(INT3
if (!routine) if (!routine)
{ {
menumessage.flags = MM_NOTHING; menumessage.flags = MM_NOTHING;
menumessage.routine = M_StopMessage;
} }
if (menumessage.flags == MM_YESNO && !defaultstr) if (menumessage.flags == MM_YESNO && !defaultstr)
@ -156,6 +156,11 @@ boolean M_MenuMessageTick(void)
if (menumessage.fadetimer == 0) if (menumessage.fadetimer == 0)
{ {
menumessage.active = false; menumessage.active = false;
if (menumessage.routine)
{
menumessage.routine(menumessage.answer);
}
} }
return false; return false;
@ -183,38 +188,24 @@ void M_HandleMenuMessage(void)
switch (menumessage.flags) switch (menumessage.flags)
{ {
// Send 1 to the routine if we're pressing A/B/X
case MM_NOTHING:
{
if (btok || btnok)
menumessage.routine(0);
break;
}
// Send 1 to the routine if we're pressing A, 2 if B/X, 0 otherwise. // Send 1 to the routine if we're pressing A, 2 if B/X, 0 otherwise.
case MM_YESNO: case MM_YESNO:
{ {
INT32 answer = MA_NONE;
if (btok) if (btok)
answer = MA_YES; menumessage.answer = MA_YES;
else if (btnok) else if (btnok)
answer = MA_NO; menumessage.answer = MA_NO;
// send 1 if btok is pressed, 2 if nok is pressed, 0 otherwise.
if (answer)
{
menumessage.routine(answer);
M_StopMessage(0);
}
break; break;
} }
// MM_EVENTHANDLER: In M_Responder to allow full event compat.
default: default:
break; break;
} }
// if we detect any keypress, don't forget to set the menu delay regardless. // if we detect any keypress, don't forget to set the menu delay regardless.
if (btok || btnok) if (btok || btnok)
{
M_StopMessage(0);
M_SetMenuDelay(pid); M_SetMenuDelay(pid);
}
} }

View file

@ -358,6 +358,8 @@ void M_ConfirmEnterGame(INT32 choice)
static void M_ExitGameResponse(INT32 ch) static void M_ExitGameResponse(INT32 ch)
{ {
const UINT8 pid = 0;
if (ch != MA_YES) if (ch != MA_YES)
return; return;
@ -368,7 +370,7 @@ static void M_ExitGameResponse(INT32 ch)
else else
{ {
G_SetExitGameFlag(); G_SetExitGameFlag();
M_ClearMenus(true); M_SetMenuDelay(pid); // prevent another input
} }
} }