Duplicate levellist data for menu restoration

- More consistent and graceful recovery from gametype change
- Fix a potential bug with restoring the menu from Tutorial stages
- Store the calling menu in this struct
    - Permits removing the Match Race restoreMenu hack
This commit is contained in:
toaster 2024-01-17 15:01:50 +00:00
parent 1d8999923c
commit af01ae7bc5
3 changed files with 42 additions and 37 deletions

View file

@ -824,7 +824,7 @@ typedef struct levelsearch_s {
#define M_LEVELLIST_SLIDETIME 4 #define M_LEVELLIST_SLIDETIME 4
extern struct levellist_s { typedef struct levellist_s {
SINT8 cursor; SINT8 cursor;
menu_anim_t slide; menu_anim_t slide;
UINT16 y; UINT16 y;
@ -834,7 +834,11 @@ extern struct levellist_s {
UINT8 guessgt; UINT8 guessgt;
levelsearch_t levelsearch; levelsearch_t levelsearch;
boolean netgame; // Start the game in an actual server boolean netgame; // Start the game in an actual server
} levellist; menu_t *backMenu;
} levellist_t;
extern levellist_t levellist;
extern levellist_t restorelevellist;
extern cupheader_t dummy_lostandfound; extern cupheader_t dummy_lostandfound;

View file

@ -533,8 +533,17 @@ menu_t *M_SpecificMenuRestore(menu_t *torestore)
|| torestore == &PLAY_TimeAttackDef) || torestore == &PLAY_TimeAttackDef)
{ {
// Handle unlock restrictions // Handle unlock restrictions
levellist = restorelevellist;
cupheader_t *currentcup = levellist.levelsearch.cup; cupheader_t *currentcup = levellist.levelsearch.cup;
if (levellist.levelsearch.tutorial)
{
M_InitExtras(-1);
}
else
{
M_SetupGametypeMenu(-1); M_SetupGametypeMenu(-1);
if (levellist.newgametype == GT_RACE) if (levellist.newgametype == GT_RACE)
@ -542,17 +551,11 @@ menu_t *M_SpecificMenuRestore(menu_t *torestore)
M_SetupRaceMenu(-1); M_SetupRaceMenu(-1);
M_SetupDifficultyOptions((cupgrid.grandprix == false)); M_SetupDifficultyOptions((cupgrid.grandprix == false));
} }
}
if (!M_LevelListFromGametype(-1)) if (!M_LevelListFromGametype(-1))
{ {
if (PLAY_LevelSelectDef.prevMenu == &PLAY_CupSelectDef) torestore = levellist.backMenu;
{
torestore = PLAY_CupSelectDef.prevMenu;
}
else
{
torestore = PLAY_LevelSelectDef.prevMenu;
}
} }
else else
{ {
@ -560,19 +563,12 @@ menu_t *M_SpecificMenuRestore(menu_t *torestore)
{ {
torestore = &PLAY_CupSelectDef; torestore = &PLAY_CupSelectDef;
} }
else if (torestore == &PLAY_TimeAttackDef) else if (levellist.levelsearch.timeattack)
{ {
M_PrepareTimeAttack(0); M_PrepareTimeAttack(0);
} }
} }
} }
else if (torestore == &PLAY_RaceDifficultyDef)
{
// Handle a much smaller subset of unlock restrictions
M_SetupGametypeMenu(-1);
M_SetupRaceMenu(-1);
M_SetupDifficultyOptions((cupgrid.grandprix == false));
}
else if (torestore == &PLAY_MP_OptSelectDef) else if (torestore == &PLAY_MP_OptSelectDef)
{ {
// Ticker init // Ticker init

View file

@ -37,7 +37,8 @@ menu_t PLAY_LevelSelectDef = {
NULL NULL
}; };
struct levellist_s levellist; levellist_t levellist;
levellist_t restorelevellist;
// //
// M_CanShowLevelInList // M_CanShowLevelInList
@ -278,6 +279,8 @@ boolean M_LevelListFromGametype(INT16 gt)
CV_SetValue(&cv_dummyspbattack, 0); CV_SetValue(&cv_dummyspbattack, 0);
} }
levellist.backMenu = currentMenu;
if (gamestate == GS_MENU) if (gamestate == GS_MENU)
{ {
const char *music; const char *music;
@ -290,8 +293,8 @@ boolean M_LevelListFromGametype(INT16 gt)
} }
else else
{ {
music = currentMenu->music; music = levellist.backMenu->music;
bgroutine = currentMenu->bgroutine; bgroutine = levellist.backMenu->bgroutine;
} }
menu_t *remap_menus[] = { menu_t *remap_menus[] = {
@ -548,10 +551,11 @@ boolean M_LevelListFromGametype(INT16 gt)
cupgrid.pageno = 0; cupgrid.pageno = 0;
} }
PLAY_CupSelectDef.prevMenu = levellist.backMenu;
PLAY_LevelSelectDef.prevMenu = &PLAY_CupSelectDef;
if (gt != -1) if (gt != -1)
{ {
PLAY_CupSelectDef.prevMenu = currentMenu;
PLAY_LevelSelectDef.prevMenu = &PLAY_CupSelectDef;
M_SetupNextMenu(&PLAY_CupSelectDef, false); M_SetupNextMenu(&PLAY_CupSelectDef, false);
} }
@ -597,6 +601,8 @@ boolean M_LevelListFromGametype(INT16 gt)
M_LevelSelectScrollDest(); M_LevelSelectScrollDest();
levellist.slide.start = 0; levellist.slide.start = 0;
PLAY_LevelSelectDef.prevMenu = levellist.backMenu;
if (gt != -1) if (gt != -1)
{ {
if (levellist.levelsearch.tutorial && levellist.mapcount == 1) if (levellist.levelsearch.tutorial && levellist.mapcount == 1)
@ -605,7 +611,6 @@ boolean M_LevelListFromGametype(INT16 gt)
} }
else else
{ {
PLAY_LevelSelectDef.prevMenu = currentMenu;
M_SetupNextMenu(&PLAY_LevelSelectDef, false); M_SetupNextMenu(&PLAY_LevelSelectDef, false);
} }
} }
@ -687,6 +692,8 @@ void M_LevelSelected(INT16 add)
{ {
S_StartSound(NULL, sfx_s3k63); S_StartSound(NULL, sfx_s3k63);
restorelevellist = levellist;
M_PrepareTimeAttack(0); M_PrepareTimeAttack(0);
PLAY_TimeAttackDef.lastOn = ta_start; PLAY_TimeAttackDef.lastOn = ta_start;
@ -744,19 +751,17 @@ void M_LevelSelected(INT16 add)
D_MapChange(levellist.choosemap+1, levellist.newgametype, (cv_kartencore.value == 1), 1, 1, false, false); D_MapChange(levellist.choosemap+1, levellist.newgametype, (cv_kartencore.value == 1), 1, 1, false, false);
if (!M_GameTrulyStarted() || if (levellist.netgame == true)
levellist.levelsearch.tutorial)
{
restoreMenu = currentMenu;
}
else if (levellist.netgame == true)
{ {
restoreMenu = &PLAY_MP_OptSelectDef; restoreMenu = &PLAY_MP_OptSelectDef;
} }
else else /*if (!M_GameTrulyStarted() ||
levellist.levelsearch.tutorial)*/
{ {
restoreMenu = &PLAY_RaceDifficultyDef; restoreMenu = currentMenu;
} }
restorelevellist = levellist;
} }
else else
{ {