Clean up all exit paths to the menu to use common code

There are multiple different exit paths to the main menu. In 2.2, they
all had a bunch of copy-pasted code. In 2.3 currently, most of them use
game.quittomenu(), but there are some stragglers that still use
hand-copied code.

This is a bit of a problem, because all exit paths should consistently
have FILESYSTEM_unmountassets(), as part of the 2.3 feature of per-level
custom assets. Furthermore, most (but not all) of the paths call
script.hardreset() too, and some of the stragglers don't. So there could
be something persisting through to the title screen (like a really long
flash/shake timer) that could only persist if exiting to the title
screen through those paths.

But, actually, it seems like there's a good reason for some of those to
not call script.hardreset() - namely, dying or completing No Death Mode
and completing a Time Trial presents some information onscreen that
would get reset by script.hardreset(), so I'll fix that in a later
commit.

So what I've done for this commit is found every exit path that didn't
already use game.quittomenu(), and made them use game.quittomenu(). As
well, some of them had special handling that existed on top of them
already having a corresponding entry in game.quittomenu() (but the path
would take the special handling because it never did game.quittomenu()),
so I removed that special handling as well (e.g. exiting from a custom
level used returntomenu(Menu::levellist) when quittomenu() already had
that same returntomenu()).

The menu that exiting from the level editor returns to is now handled in
game.quittomenu() as well, where the map.custommode branch now also
checks for map.custommodeforreal. Unfortunately, it seems like entering
the level editor doesn't properly initialize map.custommode, so entering
the level editor now initializes map.custommode, too.

I've also taken the music.play(6) out of game.quittomenu(), because not
all exit paths immediately play Presenting VVVVVV, so all exit paths
that DO immediately play Presenting VVVVVV now have music.play(6)
special-cased for them, which is fine enough for me.

Here is the list of all exit paths to the menu:
- Exiting through the pause menu (without glitchrunner mode)
- Exiting through the pause menu (with glitchrunner mode)
- Completing a custom level
- Completing a Time Trial
- Dying in No Death Mode
- Completing No Death Mode
- Completing an Intermission replay
- Exiting from the level editor
- Completing the main game
This commit is contained in:
Misa 2021-01-07 14:20:37 -08:00 committed by Ethan Lee
parent 07cc5f68ac
commit ee0ba8a723
5 changed files with 24 additions and 42 deletions

View File

@ -1288,6 +1288,7 @@ void Game::updatestate()
break;
case 81:
quittomenu();
music.play(6); //should be after quittomenu()
state = 0;
break;
@ -1341,11 +1342,7 @@ void Game::updatestate()
if(graphics.fademode == 1) state++;
break;
case 84:
graphics.flipmode = false;
gamestate = TITLEMODE;
graphics.fademode = 4;
graphics.backgrounddrawn = true;
graphics.titlebg.tdrawback = true;
quittomenu();
createmenu(Menu::timetrialcomplete);
state = 0;
break;
@ -1871,7 +1868,6 @@ void Game::updatestate()
if(!muted && ed.levmusic>0) music.fadeMusicVolumeIn(3000);
}
graphics.showcutscenebars = false;
returntomenu(Menu::levellist);
break;
#endif
case 1014:
@ -1896,6 +1892,7 @@ void Game::updatestate()
}
#endif
quittomenu();
music.play(6); //should be after quittomenu()
state = 0;
break;
@ -2852,7 +2849,6 @@ void Game::updatestate()
{
graphics.fademode = 2;
companion = 0;
returnmenu();
state=3100;
}
else
@ -2883,7 +2879,6 @@ void Game::updatestate()
state++;
graphics.fademode = 2;
music.fadeout();
returnmenu();
state=3100;
}
else
@ -2909,12 +2904,8 @@ void Game::updatestate()
if(graphics.fademode == 1) state++;
break;
case 3101:
graphics.flipmode = false;
gamestate = TITLEMODE;
graphics.fademode = 4;
graphics.backgrounddrawn = true;
graphics.titlebg.tdrawback = true;
music.play(6);
quittomenu();
music.play(6); //should be after quittomenu();
state = 0;
break;
@ -3218,11 +3209,7 @@ void Game::updatestate()
if(graphics.fademode == 1) state++;
break;
case 3522:
graphics.flipmode = false;
gamestate = TITLEMODE;
graphics.fademode = 4;
graphics.backgrounddrawn = true;
graphics.titlebg.tdrawback = true;
quittomenu();
createmenu(Menu::nodeathmodecomplete);
state = 0;
break;
@ -6972,9 +6959,7 @@ void Game::quittomenu()
{
gamestate = TITLEMODE;
graphics.fademode = 4;
FILESYSTEM_unmountassets(); // should be before music.play(6)
music.play(6);
graphics.backgrounddrawn = false;
FILESYSTEM_unmountassets();
graphics.titlebg.tdrawback = true;
graphics.flipmode = false;
//Don't be stuck on the summary screen,
@ -6995,7 +6980,15 @@ void Game::quittomenu()
}
else if (map.custommode)
{
returntomenu(Menu::levellist);
if (map.custommodeforreal)
{
returntomenu(Menu::levellist);
}
else
{
//Returning from editor
returntomenu(Menu::playerworlds);
}
}
else if (save_exists() || anything_unlocked())
{

View File

@ -2117,6 +2117,7 @@ void mapinput()
else
{
game.quittomenu();
music.play(6); //should be after game.quittomenu()
game.fadetomenu = false;
}
}

View File

@ -113,13 +113,9 @@ void gamecompletelogic2()
game.savetele();
music.currentsong=tmp;
//Return to game
graphics.titlebg.colstate = 10;
game.gamestate = TITLEMODE;
graphics.fademode = 4;
FILESYSTEM_unmountassets(); // should be before music.playef(18)
music.playef(18);
game.returntomenu(Menu::play);
game.quittomenu();
game.createmenu(Menu::gamecompletecontinue);
graphics.titlebg.colstate = 10;
map.nexttowercolour();
}
}

View File

@ -2627,11 +2627,8 @@ void scriptclass::run()
void scriptclass::resetgametomenu()
{
game.gamestate = TITLEMODE;
graphics.flipmode = false;
obj.entities.clear();
graphics.fademode = 4;
graphics.titlebg.tdrawback = true;
game.quittomenu();
game.createmenu(Menu::gameover);
}
@ -3262,6 +3259,8 @@ void scriptclass::startgamemode( int t )
hardreset();
ed.reset();
music.fadeout();
map.custommode = true;
map.custommodeforreal = false;
game.gamestate = EDITORMODE;
game.jumpheld = true;

View File

@ -3627,18 +3627,11 @@ void editorlogic()
if (graphics.fademode == 1)
{
//Return to game
map.nexttowercolour();
graphics.titlebg.colstate = 10;
game.gamestate = TITLEMODE;
script.hardreset();
graphics.fademode = 4;
music.haltdasmusik();
FILESYSTEM_unmountassets(); // should be before music.play(6)
music.play(6);
map.nexttowercolour();
game.quittomenu();
music.play(6); //should be before game.quittomenu()
ed.settingsmod=false;
graphics.backgrounddrawn=false;
game.returntomenu(Menu::playerworlds);
}
}