mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
De-duplicate copy-pasted input/render code in menus
This removes duplicate code that came about as a result of various possible permutations of menu options, depending on being M&P, having no custom level support, having no editor support, and having MMMMMM. The menus with such permutations are the following: - main menu - "start game" is gone in MAKEANDPLAY - "player levels" is gone in NO_CUSTOM_LEVELS - "view credits" is gone in MAKEANDPLAY - "game options" - "unlock play data" is gone in MAKEANDPLAY - "soundtrack" is gone if you don't have an mmmmmm.vvv file - "player levels" - "level editor" is gone in NO_EDITOR I achieve this de-duplication by clever use of calculating offsets, which I feel is the best way to de-duplicate the code with the least amount of work, if a little brittle. The other options are to (1) put function pointers on each MenuOption object, which is pretty verbose and would inflate Game::createmenu() by a lot, (2) switch all game.currentmenuoption checks to instead check for the text of the currently-selected menu option, which is very error-prone because if you make a typo it won't be caught at compile-time, (3) add a unique ID to each MenuOption object that represents a text but will error at compile-time if you make a typo, however this just duplicates all the menu option text, which is more code than was duplicated previously. So I just went with this one.
This commit is contained in:
@@ -66,61 +66,38 @@ void menurender()
|
||||
}
|
||||
else if (game.currentmenuname == "options")
|
||||
{
|
||||
|
||||
#if defined(MAKEANDPLAY)
|
||||
#define OFFSET -1
|
||||
#else
|
||||
#define OFFSET 0
|
||||
#endif
|
||||
|
||||
if (game.currentmenuoption == 0)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Accessibility", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Disable screen effects, enable", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "slowdown modes or invincibility", tr, tg, tb, true);
|
||||
}
|
||||
else if (game.currentmenuoption == 1)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Game Pad Options", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Rebind your controller's buttons", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "and adjust sensitivity", tr, tg, tb, true);
|
||||
}
|
||||
else if (game.currentmenuoption == 2)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Clear Data", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Delete your save data", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "and unlocked play modes", tr, tg, tb, true);
|
||||
}else if (game.currentmenuoption == 3){
|
||||
if(music.mmmmmm){
|
||||
graphics.bigprint( -1, 30, "Soundtrack", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Toggle between MMMMMM and PPPPPP", tr, tg, tb, true);
|
||||
if(music.usingmmmmmm){
|
||||
graphics.Print( -1, 85, "Current soundtrack: MMMMMM", tr, tg, tb, true);
|
||||
}else{
|
||||
graphics.Print( -1, 85, "Current soundtrack: PPPPPP", tr, tg, tb, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif !defined(MAKEANDPLAY)
|
||||
if (game.currentmenuoption == 0)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Accessibility", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Disable screen effects, enable", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "slowdown modes or invincibility", tr, tg, tb, true);
|
||||
}
|
||||
#if !defined(MAKEANDPLAY)
|
||||
else if (game.currentmenuoption == 1)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Unlock Play Modes", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Unlock parts of the game normally", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "unlocked as you progress", tr, tg, tb, true);
|
||||
}
|
||||
else if (game.currentmenuoption == 2)
|
||||
#endif
|
||||
else if (game.currentmenuoption == OFFSET+2)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Game Pad Options", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Rebind your controller's buttons", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "and adjust sensitivity", tr, tg, tb, true);
|
||||
}
|
||||
else if (game.currentmenuoption == 3)
|
||||
else if (game.currentmenuoption == OFFSET+3)
|
||||
{
|
||||
graphics.bigprint( -1, 30, "Clear Data", tr, tg, tb, true);
|
||||
graphics.Print( -1, 65, "Delete your save data", tr, tg, tb, true);
|
||||
graphics.Print( -1, 75, "and unlocked play modes", tr, tg, tb, true);
|
||||
}else if (game.currentmenuoption == 4)
|
||||
}else if (game.currentmenuoption == OFFSET+4)
|
||||
{
|
||||
if(music.mmmmmm){
|
||||
graphics.bigprint( -1, 30, "Soundtrack", tr, tg, tb, true);
|
||||
@@ -132,7 +109,7 @@ void menurender()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#undef OFFSET
|
||||
}
|
||||
else if (game.currentmenuname == "graphicoptions")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user