Convert menu names to be an enum instead of being stringly-typed

Stringly-typed things are bad, because if you make a typo when typing
out a string, it's not caught at compile-time. And in the case of this
menu system, you'd have to do an excessive amount of testing to uncover
any bugs caused by a typo. Why do that when you can just use an enum and
catch compile-time errors instead?

Also, you can't use switch-case statements on stringly-typed variables.

So every menu name is now in the enum Menu::MenuName, but you can simply
refer to a menu name by just prefixing it with Menu::.

Unfortunately, I've had to change the "continue" menu name to be
"continuemenu", because "continue" is a keyword in C and C++. Also, it
looks like "timetrialcomplete4" is an unused menu name, even though it
was referenced in Render.cpp.
This commit is contained in:
Misa
2020-04-15 21:53:36 -07:00
committed by Ethan Lee
parent 83ca75a831
commit e8a07f9c3d
7 changed files with 324 additions and 269 deletions

View File

@@ -14,6 +14,63 @@ struct MenuOption
bool active;
};
//Menu IDs
namespace Menu
{
enum MenuName
{
mainmenu,
playerworlds,
levellist,
quickloadlevel,
youwannaquit,
errornostart,
graphicoptions,
ed_settings,
ed_desc,
ed_music,
ed_quit,
options,
accessibility,
controller,
cleardatamenu,
setinvincibility,
setslowdown1,
setslowdown2,
unlockmenu,
credits,
credits2,
credits25,
credits3,
credits4,
credits5,
credits6,
play,
unlocktimetrial,
unlocktimetrials,
unlocknodeathmode,
unlockintermission,
unlockflipmode,
newgamewarning,
playmodes,
intermissionmenu,
playint1,
playint2,
continuemenu,
startnodeathmode,
gameover,
gameover2,
unlockmenutrials,
timetrials,
nodeathmodecomplete,
nodeathmodecomplete2,
timetrialcomplete,
timetrialcomplete2,
timetrialcomplete3,
gamecompletecontinue,
};
};
class Game
{
@@ -53,7 +110,7 @@ public:
std::string timetstring(int t);
void createmenu(std::string t);
void createmenu(enum Menu::MenuName t);
void lifesequence();
@@ -164,7 +221,8 @@ public:
//Main Menu Variables
std::vector<MenuOption> menuoptions;
int currentmenuoption ;
std::string menuselection, currentmenuname, previousmenuname;
std::string menuselection;
enum Menu::MenuName currentmenuname, previousmenuname;
int current_credits_list_index;
int menuxoff, menuyoff;
@@ -177,7 +235,7 @@ public:
}
int menucountdown;
std::string menudest;
enum Menu::MenuName menudest;
int creditposx, creditposy, creditposdelay;