Turn game.currentmenuname "else-if"s into case-switches

Much more stylistic, you don't need to repeat "game.currentmenuname" for
each case, and you don't need to deal with the dangling first "if" that
doesn't have an "else".
This commit is contained in:
Misa
2020-04-16 15:19:17 -07:00
committed by Ethan Lee
parent ceb8d3f3d8
commit 9e99246e02
4 changed files with 280 additions and 356 deletions

View File

@@ -20,8 +20,9 @@ void menurender()
{
int temp = 50;
if(game.currentmenuname==Menu::mainmenu)
switch (game.currentmenuname)
{
case Menu::mainmenu:
graphics.drawsprite((160 - 96) + 0 * 32, temp, 23, tr, tg, tb);
graphics.drawsprite((160 - 96) + 1 * 32, temp, 23, tr, tg, tb);
graphics.drawsprite((160 - 96) + 2 * 32, temp, 23, tr, tg, tb);
@@ -36,9 +37,9 @@ void menurender()
if(music.mmmmmm){
graphics.Print( 10, 230, "[MMMMMM Mod Installed]", tr/2, tg/2, tb/2);
}
}
break;
#if !defined(NO_CUSTOM_LEVELS)
else if (game.currentmenuname == Menu::levellist)
case Menu::levellist:
{
if(ed.ListOfMetaData.size()==0){
graphics.Print( -1, 100, "ERROR: No levels found.", tr, tg, tb, true);
@@ -57,15 +58,14 @@ void menurender()
graphics.Print( -1, 90, ed.ListOfMetaData[tmp].Desc3, tr, tg, tb, true);
}
}
break;
}
#endif
else if (game.currentmenuname == Menu::errornostart)
{
case Menu::errornostart:
graphics.Print( -1, 65, "ERROR: This level has", tr, tg, tb, true);
graphics.Print( -1, 75, "no start point!", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::options)
{
break;
case Menu::options:
#if defined(MAKEANDPLAY)
#define OFFSET -1
#else
@@ -109,9 +109,8 @@ void menurender()
break;
}
#undef OFFSET
}
else if (game.currentmenuname == Menu::graphicoptions)
{
break;
case Menu::graphicoptions:
switch (game.currentmenuoption)
{
case 0:
@@ -166,9 +165,8 @@ void menurender()
}
break;
}
}
else if (game.currentmenuname == Menu::credits)
{
break;
case Menu::credits:
graphics.Print( -1, 50, "VVVVVV is a game by", tr, tg, tb, true);
graphics.bigprint( 40, 65, "Terry Cavanagh", tr, tg, tb, true, 2);
@@ -177,25 +175,23 @@ void menurender()
graphics.Print( -1, 120, "and features music by", tr, tg, tb, true);
graphics.bigprint( 40, 135, "Magnus P~lsson", tr, tg, tb, true, 2);
graphics.drawimagecol(8, -1, 156, tr *0.75, tg *0.75, tb *0.75, true);
}
else if (game.currentmenuname == Menu::credits2)
{
break;
case Menu::credits2:
graphics.Print( -1, 50, "Roomnames are by", tr, tg, tb, true);
graphics.bigprint( 40, 65, "Bennett Foddy", tr, tg, tb, true);
graphics.drawimagecol(9, -1, 86, tr*0.75, tg *0.75, tb *0.75, true);
graphics.Print( -1, 110, "C++ version by", tr, tg, tb, true);
graphics.bigprint( 40, 125, "Simon Roth", tr, tg, tb, true);
graphics.bigprint( 40, 145, "Ethan Lee", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::credits25)
{
break;
case Menu::credits25:
graphics.Print( -1, 40, "Beta Testing by", tr, tg, tb, true);
graphics.bigprint( 40, 55, "Sam Kaplan", tr, tg, tb, true);
graphics.bigprint( 40, 75, "Pauli Kohberger", tr, tg, tb, true);
graphics.Print( -1, 130, "Ending Picture by", tr, tg, tb, true);
graphics.bigprint( 40, 145, "Pauli Kohberger", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::credits3)
break;
case Menu::credits3:
{
graphics.Print( -1, 20, "VVVVVV is supported by", tr, tg, tb, true);
graphics.Print( 40, 30, "the following patrons", tr, tg, tb, true);
@@ -212,8 +208,9 @@ void menurender()
xofs += 4;
yofs += 14;
}
break;
}
else if (game.currentmenuname == Menu::credits4)
case Menu::credits4:
{
graphics.Print( -1, 20, "and also by", tr, tg, tb, true);
@@ -231,8 +228,9 @@ void menurender()
graphics.Print(80, yofs, game.patrons[i], tr, tg, tb);
yofs += 10;
}
break;
}
else if (game.currentmenuname == Menu::credits5)
case Menu::credits5:
{
graphics.Print( -1, 20, "With contributions on", tr, tg, tb, true);
graphics.Print( 40, 30, "GitHub from", tr, tg, tb, true);
@@ -253,9 +251,9 @@ void menurender()
xofs += 4;
yofs += 14;
}
break;
}
else if (game.currentmenuname == Menu::credits6)
{
case Menu::credits6:
graphics.Print( -1, 20, "and thanks also to:", tr, tg, tb, true);
graphics.bigprint(80, 60, "You!", tr, tg, tb, true);
@@ -266,21 +264,18 @@ void menurender()
graphics.Print( 80, 130, "and into the future.", tr, tg, tb, true);
graphics.Print( 80, 150,"Thank you!", tr, tg, tb,true);
}
else if (game.currentmenuname == Menu::setinvincibility)
{
break;
case Menu::setinvincibility:
graphics.Print( -1, 100, "Are you sure you want to ", tr, tg, tb, true);
graphics.Print( -1, 110, "enable invincibility?", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::setslowdown1)
{
break;
case Menu::setslowdown1:
graphics.Print( -1, 90, "Warning! Changing the game speed", tr, tg, tb, true);
graphics.Print( -1, 100, "requires a game restart, and will", tr, tg, tb, true);
graphics.Print( -1, 110, "delete your current saves.", tr, tg, tb, true);
graphics.Print( -1, 120, "Is this ok?", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::setslowdown2)
{
break;
case Menu::setslowdown2:
graphics.bigprint( -1, 40, "Game Speed", tr, tg, tb, true);
graphics.Print( -1, 75, "Select a new game speed below.", tr, tg, tb, true);
switch (game.gameframerate)
@@ -298,26 +293,22 @@ void menurender()
graphics.Print( -1, 105, "Game speed is at 40%", tr, tg, tb, true);
break;
}
}
else if (game.currentmenuname == Menu::newgamewarning)
{
break;
case Menu::newgamewarning:
graphics.Print( -1, 100, "Are you sure? This will", tr, tg, tb, true);
graphics.Print( -1, 110, "delete your current saves...", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::cleardatamenu)
{
break;
case Menu::cleardatamenu:
graphics.Print( -1, 100, "Are you sure you want to", tr, tg, tb, true);
graphics.Print( -1, 110, "delete all your saved data?", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::startnodeathmode)
{
break;
case Menu::startnodeathmode:
graphics.Print( -1, 45, "Good luck!", tr, tg, tb, true);
graphics.Print( -1, 80, "You cannot save in this mode.", tr, tg, tb, true);
graphics.Print( -1, 100, "Would you like to disable the", tr, tg, tb, true);
graphics.Print( -1, 112, "cutscenes during the game?", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::controller)
{
break;
case Menu::controller:
graphics.bigprint( -1, 30, "Game Pad", tr, tg, tb, true);
graphics.Print( -1, 55, "Change controller options.", tr, tg, tb, true);
switch (game.currentmenuoption)
@@ -357,9 +348,8 @@ void menurender()
}
}
else if (game.currentmenuname == Menu::accessibility)
{
break;
case Menu::accessibility:
switch (game.currentmenuoption)
{
case 0:
@@ -449,14 +439,13 @@ void menurender()
graphics.Print(-1, 105, "Room name background is OPAQUE", tr, tg, tb, true);
break;
}
}
else if (game.currentmenuname == Menu::playint1 || game.currentmenuname == Menu::playint2)
{
break;
case Menu::playint1:
case Menu::playint2:
graphics.Print( -1, 65, "Who do you want to play", tr, tg, tb, true);
graphics.Print( -1, 75, "the level with?", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::playmodes)
{
break;
case Menu::playmodes:
switch (game.currentmenuoption)
{
case 0:
@@ -518,13 +507,11 @@ void menurender()
}
break;
}
}
else if (game.currentmenuname == Menu::youwannaquit)
{
break;
case Menu::youwannaquit:
graphics.Print( -1, 75, "Are you sure you want to quit?", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::continuemenu)
{
break;
case Menu::continuemenu:
graphics.crewframedelay--;
if (graphics.crewframedelay <= 0)
{
@@ -566,8 +553,9 @@ void menurender()
graphics.drawspritesetcol(175, 126-20, 22, 18);
break;
}
}
else if (game.currentmenuname == Menu::gameover || game.currentmenuname == Menu::gameover2)
break;
case Menu::gameover:
case Menu::gameover2:
{
graphics.bigprint( -1, 25, "GAME OVER", tr, tg, tb, true, 3);
@@ -615,8 +603,10 @@ void menurender()
}
graphics.Print(0, 190, tempstring, tr, tg, tb, true);
break;
}
else if (game.currentmenuname == Menu::nodeathmodecomplete || game.currentmenuname == Menu::nodeathmodecomplete2)
case Menu::nodeathmodecomplete:
case Menu::nodeathmodecomplete2:
{
graphics.bigprint( -1, 8, "WOW", tr, tg, tb, true, 4);
@@ -639,9 +629,11 @@ void menurender()
graphics.Print(0, 160, "A new trophy has been awarded and", tr, tg, tb, true);
graphics.Print(0, 170, "placed in the secret lab to", tr, tg, tb, true);
graphics.Print(0, 180, "acknowledge your achievement!", tr, tg, tb, true);
break;
}
else if (game.currentmenuname == Menu::timetrialcomplete || game.currentmenuname == Menu::timetrialcomplete2
|| game.currentmenuname == Menu::timetrialcomplete3)
case Menu::timetrialcomplete:
case Menu::timetrialcomplete2:
case Menu::timetrialcomplete3:
{
graphics.bigprint( -1, 20, "Results", tr, tg, tb, true, 3);
@@ -696,15 +688,14 @@ void menurender()
break;
}
}
break;
}
else if (game.currentmenuname == Menu::unlockmenutrials)
{
case Menu::unlockmenutrials:
graphics.bigprint( -1, 30, "Unlock Time Trials", tr, tg, tb, true);
graphics.Print( -1, 65, "You can unlock each time", tr, tg, tb, true);
graphics.Print( -1, 75, "trial separately.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::timetrials)
{
break;
case Menu::timetrials:
switch (game.currentmenuoption)
{
case 0:
@@ -984,9 +975,8 @@ void menurender()
}
break;
}
}
else if (game.currentmenuname == Menu::gamecompletecontinue)
{
break;
case Menu::gamecompletecontinue:
graphics.bigprint( -1, 25, "Congratulations!", tr, tg, tb, true, 2);
graphics.Print( -1, 45, "Your save files have been updated.", tr, tg, tb, true);
@@ -994,50 +984,45 @@ void menurender()
graphics.Print( -1, 110, "If you want to keep exploring", tr, tg, tb, true);
graphics.Print( -1, 120, "the game, select CONTINUE", tr, tg, tb, true);
graphics.Print( -1, 130, "from the play menu.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::unlockmenu)
{
break;
case Menu::unlockmenu:
graphics.bigprint( -1, 25, "Unlock Play Modes", tr, tg, tb, true, 2);
graphics.Print( -1, 55, "From here, you may unlock parts", tr, tg, tb, true);
graphics.Print( -1, 65, "of the game that are normally", tr, tg, tb, true);
graphics.Print( -1, 75, "unlocked as you play.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::unlocktimetrial)
{
break;
case Menu::unlocktimetrial:
graphics.bigprint( -1, 45, "Congratulations!", tr, tg, tb, true, 2);
graphics.Print( -1, 125, "You have unlocked", tr, tg, tb, true);
graphics.Print( -1, 135, "a new Time Trial.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::unlocktimetrials)
{
break;
case Menu::unlocktimetrials:
graphics.bigprint( -1, 45, "Congratulations!", tr, tg, tb, true, 2);
graphics.Print( -1, 125, "You have unlocked some", tr, tg, tb, true);
graphics.Print( -1, 135, "new Time Trials.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::unlocknodeathmode)
{
break;
case Menu::unlocknodeathmode:
graphics.bigprint( -1, 45, "Congratulations!", tr, tg, tb, true, 2);
graphics.Print( -1, 125, "You have unlocked", tr, tg, tb, true);
graphics.Print( -1, 135, "No Death Mode.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::unlockflipmode)
{
break;
case Menu::unlockflipmode:
graphics.bigprint( -1, 45, "Congratulations!", tr, tg, tb, true, 2);
graphics.Print( -1, 125, "You have unlocked", tr, tg, tb, true);
graphics.Print( -1, 135, "Flip Mode.", tr, tg, tb, true);
}
else if (game.currentmenuname == Menu::unlockintermission)
{
break;
case Menu::unlockintermission:
graphics.bigprint( -1, 45, "Congratulations!", tr, tg, tb, true, 2);
graphics.Print( -1, 125, "You have unlocked", tr, tg, tb, true);
graphics.Print( -1, 135, "the intermission levels.", tr, tg, tb, true);
}else if (game.currentmenuname == Menu::playerworlds)
break;
case Menu::playerworlds:
{
std::string tempstring = FILESYSTEM_getUserLevelDirectory();
if(tempstring.length()>80){
@@ -1056,6 +1041,10 @@ void menurender()
graphics.Print( -1, 190, "the .vvvvvv files to this folder:", tr, tg, tb, true);
graphics.Print( 320-(tempstring.length()*8), 210, tempstring, tr, tg, tb);
}
break;
}
default:
break;
}
}