From e9f9cfd051056e661f0e003d9b7ae8dc1dc8bf24 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 17 Jun 2023 13:30:03 +0100 Subject: [PATCH] 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. --- src/k_menu.h | 1 + src/menus/extras-addons.c | 3 ++- src/menus/play-local-race-time-attack.c | 1 - src/menus/transient/message-box.c | 31 +++++++++---------------- src/menus/transient/pause-game.c | 4 +++- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/k_menu.h b/src/k_menu.h index bca035b59..4b10d0eac 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -533,6 +533,7 @@ extern struct menumessage_s void (*routine)(INT32 choice); // Normal routine //void (*eroutine)(event_t *ev); // Event routine (MM_EVENTHANDLER) + INT32 answer; const char *defaultstr; const char *confirmstr; diff --git a/src/menus/extras-addons.c b/src/menus/extras-addons.c index dfa21b876..8610992d3 100644 --- a/src/menus/extras-addons.c +++ b/src/menus/extras-addons.c @@ -101,11 +101,12 @@ static boolean prevmajormods = false; static void M_AddonsClearName(INT32 choice) { + (void)choice; + if (!majormods || prevmajormods) { CLEARNAME; } - M_StopMessage(choice); } // Handles messages for addon errors. diff --git a/src/menus/play-local-race-time-attack.c b/src/menus/play-local-race-time-attack.c index 454080573..ed5990587 100644 --- a/src/menus/play-local-race-time-attack.c +++ b/src/menus/play-local-race-time-attack.c @@ -414,7 +414,6 @@ static void M_WriteGuestReplay(INT32 ch) if (FIL_FileExists(rguest)) { - //M_StopMessage(0); remove(rguest); } diff --git a/src/menus/transient/message-box.c b/src/menus/transient/message-box.c index ec34a68a1..5f88dd832 100644 --- a/src/menus/transient/message-box.c +++ b/src/menus/transient/message-box.c @@ -71,6 +71,7 @@ void M_StartMessage(const char *header, const char *string, void (*routine)(INT3 menumessage.header = header; menumessage.flags = itemtype; menumessage.routine = routine; + menumessage.answer = MA_NONE; menumessage.fadetimer = 1; menumessage.timer = 0; menumessage.closing = false; @@ -82,7 +83,6 @@ void M_StartMessage(const char *header, const char *string, void (*routine)(INT3 if (!routine) { menumessage.flags = MM_NOTHING; - menumessage.routine = M_StopMessage; } if (menumessage.flags == MM_YESNO && !defaultstr) @@ -156,6 +156,11 @@ boolean M_MenuMessageTick(void) if (menumessage.fadetimer == 0) { menumessage.active = false; + + if (menumessage.routine) + { + menumessage.routine(menumessage.answer); + } } return false; @@ -183,38 +188,24 @@ void M_HandleMenuMessage(void) 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. case MM_YESNO: { - INT32 answer = MA_NONE; if (btok) - answer = MA_YES; + menumessage.answer = MA_YES; else if (btnok) - answer = MA_NO; - - // send 1 if btok is pressed, 2 if nok is pressed, 0 otherwise. - if (answer) - { - menumessage.routine(answer); - M_StopMessage(0); - } + menumessage.answer = MA_NO; break; } - // MM_EVENTHANDLER: In M_Responder to allow full event compat. default: break; } // if we detect any keypress, don't forget to set the menu delay regardless. if (btok || btnok) + { + M_StopMessage(0); M_SetMenuDelay(pid); + } } diff --git a/src/menus/transient/pause-game.c b/src/menus/transient/pause-game.c index 3f638aebd..c3b640ea8 100644 --- a/src/menus/transient/pause-game.c +++ b/src/menus/transient/pause-game.c @@ -358,6 +358,8 @@ void M_ConfirmEnterGame(INT32 choice) static void M_ExitGameResponse(INT32 ch) { + const UINT8 pid = 0; + if (ch != MA_YES) return; @@ -368,7 +370,7 @@ static void M_ExitGameResponse(INT32 ch) else { G_SetExitGameFlag(); - M_ClearMenus(true); + M_SetMenuDelay(pid); // prevent another input } }