From 124f4e8b620da57a58b3a55e9424fe074ccae32c Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sat, 24 Apr 2004 09:32:32 +0000 Subject: [PATCH] Added a new concept to the menu, the ID. Each item can have an ID that can be given, this way there won't be any more hardcoded values for the entries. Anyway, I've made it to be compatible with the current behaviour, in case any ID is given. I've already updated the mainmenu, optionsmenu, leveleditormenu, leveleditorsettingsmenu and worldmapmenu. The definitions are enumerated in the menu.h file. Should we keep each enum splited or merge them all? Feedback is appreciated :) SVN-Revision: 674 --- src/gameloop.cpp | 4 +-- src/leveleditor.cpp | 16 +++++------ src/menu.cpp | 16 ++++++++--- src/menu.h | 45 +++++++++++++++++++++++++++-- src/setup.cpp | 82 +++++++++++++++++++++++++++-------------------------- src/title.cpp | 10 +++---- src/worldmap.cpp | 6 ++-- 7 files changed, 115 insertions(+), 64 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 5d0d51e32..24a5df3b7 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -454,10 +454,10 @@ GameSession::process_menu() { switch (game_menu->check()) { - case 2: + case MNID_CONTINUE: st_pause_ticks_stop(); break; - case 5: + case MNID_ABORTLEVEL: st_pause_ticks_stop(); exit_status = LEVEL_ABORT; break; diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 298489147..f79d877d2 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -219,13 +219,13 @@ int leveleditor(int levelnb) { switch (leveleditor_menu->check()) { - case 2: + case MNID_RETURNLEVELEDITOR: Menu::set_current(0); break; - case 3: + case MNID_SUBSETSETTINGS: update_subset_settings_menu(); break; - case 7: + case MNID_QUITLEVELEDITOR: done = 1; break; } @@ -234,7 +234,7 @@ int leveleditor(int levelnb) { switch (level_settings_menu->check()) { - case 17: + case MNID_SUBSETSETTINGS: apply_level_settings_menu(); Menu::set_current(leveleditor_menu); break; @@ -413,12 +413,12 @@ int le_init() leveleditor_menu->additem(MN_LABEL,"Level Editor Menu",0,0); leveleditor_menu->additem(MN_HL,"",0,0); - leveleditor_menu->additem(MN_ACTION,"Return To Level Editor",0,0); - leveleditor_menu->additem(MN_DEACTIVE,"Level Subset Settings",0,subset_settings_menu); + leveleditor_menu->additem(MN_ACTION,"Return To Level Editor",0,0,MNID_RETURNLEVELEDITOR); + leveleditor_menu->additem(MN_DEACTIVE,"Level Subset Settings",0,subset_settings_menu,MNID_SUBSETSETTINGS); leveleditor_menu->additem(MN_GOTO,"Load Level Subset",0,subset_load_menu); leveleditor_menu->additem(MN_GOTO,"New Level Subset",0,subset_new_menu); leveleditor_menu->additem(MN_HL,"",0,0); - leveleditor_menu->additem(MN_ACTION,"Quit Level Editor",0,0); + leveleditor_menu->additem(MN_ACTION,"Quit Level Editor",0,0,MNID_QUITLEVELEDITOR); Menu::set_current(leveleditor_menu); @@ -466,7 +466,7 @@ int le_init() level_settings_menu->additem(MN_NUMFIELD,"Bottom Green",0,0); level_settings_menu->additem(MN_NUMFIELD,"Bottom Blue",0,0); level_settings_menu->additem(MN_HL,"",0,0); - level_settings_menu->additem(MN_ACTION,"Apply Changes",0,0); + level_settings_menu->additem(MN_ACTION,"Apply Changes",0,0,MNID_APPLY); select_tilegroup_menu->arrange_left = true; select_tilegroup_menu->additem(MN_LABEL,"Select Tilegroup",0,0); diff --git a/src/menu.cpp b/src/menu.cpp index db41fce82..1a76b18a9 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -98,7 +98,7 @@ Menu::set_current(Menu* menu) /* Return a pointer to a new menu item */ MenuItem* -MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_, int* int_p_) +MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_, int id, int* int_p_) { MenuItem *pnew_item = new MenuItem; @@ -123,6 +123,7 @@ MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* else pnew_item->list = NULL; + pnew_item->id = id; pnew_item->int_p = int_p_; return pnew_item; @@ -222,6 +223,7 @@ Menu::Menu() pos_x = screen->w/2; pos_y = screen->h/2; has_backitem = false; + last_id = 0; arrange_left = 0; active_item = 0; effect.init(false); @@ -234,12 +236,18 @@ void Menu::set_pos(int x, int y, float rw, float rh) } void -Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_, int* int_p) +Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_, int id, int* int_p) { if(kind_ == MN_BACK) has_backitem = true; - additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_, int_p)); + if(id == -1 && item.size() == (unsigned)last_id) + { + id = last_id; + last_id++; + } + + additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_, id, int_p)); } /* Add an item to a menu */ @@ -396,7 +404,7 @@ Menu::action() int Menu::check() { - return hit_item; + return item[hit_item].id; /* if (item.size() != 0) { diff --git a/src/menu.h b/src/menu.h index 43aee8596..280a459c6 100644 --- a/src/menu.h +++ b/src/menu.h @@ -27,6 +27,45 @@ #include "type.h" #include "mousecursor.h" +/* IDs for menus */ + +enum MainMenuIDs { + MNID_STARTGAME, + MNID_CONTRIB, + MNID_LEVELEDITOR, + MNID_CREDITS, + MNID_QUITMAINMENU + }; + +enum OptionsMenuIDs { + MNID_OPENGL, + MNID_FULLSCREEN, + MNID_SOUND, + MNID_MUSIC, + MNID_SHOWFPS + }; + +enum GameMenuIDs { + MNID_CONTINUE, + MNID_ABORTLEVEL + }; + +enum WorldMapMenuIDs { + MNID_RETURNWORLDMAP, + MNID_SAVEGAME, + MNID_QUITWORLDMAP + }; + +enum LevelEditorMainMenuIDs { + MNID_RETURNLEVELEDITOR, + MNID_SUBSETSETTINGS, + MNID_QUITLEVELEDITOR + }; + +enum LevelEditorSettingsMenuIDs { + MNID_APPLY + }; + /* Kinds of menu items */ enum MenuItemKind { MN_ACTION, @@ -52,13 +91,14 @@ public: char *text; char *input; int *int_p; // used for setting keys (can be used for more stuff...) + int id; // item id string_list_type* list; Menu* target_menu; void change_text (const char *text); void change_input(const char *text); - static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int* int_p); + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p); }; class Menu @@ -98,6 +138,7 @@ private: int pos_x; int pos_y; bool has_backitem; + int last_id; /** input event for the menu (up, down, left, right, etc.) */ MenuAction menuaction; @@ -117,7 +158,7 @@ public: ~Menu(); void additem(MenuItem* pmenu_item); - void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int *int_p = NULL); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL); void action (); diff --git a/src/setup.cpp b/src/setup.cpp index 88afb0632..3dd909d8b 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -376,32 +376,32 @@ void st_menu(void) worldmap_menu = new Menu(); main_menu->set_pos(screen->w/2, 335); - main_menu->additem(MN_GOTO, "Start Game",0,load_game_menu); - main_menu->additem(MN_GOTO, "Contrib Levels",0,contrib_menu); + main_menu->additem(MN_GOTO, "Start Game",0,load_game_menu, MNID_STARTGAME); + main_menu->additem(MN_GOTO, "Contrib Levels",0,contrib_menu, MNID_CONTRIB); main_menu->additem(MN_GOTO, "Options",0,options_menu); - main_menu->additem(MN_ACTION,"Level editor",0,0); - main_menu->additem(MN_ACTION,"Credits",0,0); - main_menu->additem(MN_ACTION,"Quit",0,0); + main_menu->additem(MN_ACTION,"Level editor",0,0, MNID_LEVELEDITOR); + main_menu->additem(MN_ACTION,"Credits",0,0, MNID_CREDITS); + main_menu->additem(MN_ACTION,"Quit",0,0, MNID_QUITMAINMENU); options_menu->additem(MN_LABEL,"Options",0,0); options_menu->additem(MN_HL,"",0,0); #ifndef NOOPENGL - options_menu->additem(MN_TOGGLE,"OpenGL",use_gl,0); + options_menu->additem(MN_TOGGLE,"OpenGL",use_gl,0, MNID_OPENGL); #else - options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl,0); + options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl,MNID_OPENGL); #endif - options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0); + options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0, MNID_FULLSCREEN); if(audio_device) { - options_menu->additem(MN_TOGGLE,"Sound ",use_sound,0); - options_menu->additem(MN_TOGGLE,"Music ",use_music,0); + options_menu->additem(MN_TOGGLE,"Sound ",use_sound,0, MNID_SOUND); + options_menu->additem(MN_TOGGLE,"Music ",use_music,0, MNID_MUSIC); } else { - options_menu->additem(MN_DEACTIVE,"Sound ",use_sound,0); - options_menu->additem(MN_DEACTIVE,"Music ",use_music,0); + options_menu->additem(MN_DEACTIVE,"Sound ",use_sound,0, MNID_SOUND); + options_menu->additem(MN_DEACTIVE,"Music ",use_music,0, MNID_MUSIC); } - options_menu->additem(MN_TOGGLE,"Show FPS ",show_fps,0); + options_menu->additem(MN_TOGGLE,"Show FPS ",show_fps,0, MNID_SHOWFPS); options_menu->additem(MN_GOTO,"Key Setup",0,options_keys_menu); if(use_joystick) options_menu->additem(MN_GOTO,"Joystick Setup",0,options_joystick_menu); @@ -410,11 +410,11 @@ void st_menu(void) options_keys_menu->additem(MN_LABEL,"Key Setup",0,0); options_keys_menu->additem(MN_HL,"",0,0); - options_keys_menu->additem(MN_CONTROLFIELD,"Left move", 0,0, &keymap.left); - options_keys_menu->additem(MN_CONTROLFIELD,"Right move", 0,0, &keymap.right); - options_keys_menu->additem(MN_CONTROLFIELD,"Jump", 0,0, &keymap.jump); - options_keys_menu->additem(MN_CONTROLFIELD,"Duck", 0,0, &keymap.duck); - options_keys_menu->additem(MN_CONTROLFIELD,"Power", 0,0, &keymap.fire); + options_keys_menu->additem(MN_CONTROLFIELD,"Left move", 0,0, 0,&keymap.left); + options_keys_menu->additem(MN_CONTROLFIELD,"Right move", 0,0, 0,&keymap.right); + options_keys_menu->additem(MN_CONTROLFIELD,"Jump", 0,0, 0,&keymap.jump); + options_keys_menu->additem(MN_CONTROLFIELD,"Duck", 0,0, 0,&keymap.duck); + options_keys_menu->additem(MN_CONTROLFIELD,"Power", 0,0, 0,&keymap.fire); options_keys_menu->additem(MN_HL,"",0,0); options_keys_menu->additem(MN_BACK,"Back",0,0); @@ -422,12 +422,12 @@ void st_menu(void) { options_joystick_menu->additem(MN_LABEL,"Joystick Setup",0,0); options_joystick_menu->additem(MN_HL,"",0,0); - options_joystick_menu->additem(MN_CONTROLFIELD,"X axis", 0,0, &joystick_keymap.x_axis); - options_joystick_menu->additem(MN_CONTROLFIELD,"Y axis", 0,0, &joystick_keymap.y_axis); - options_joystick_menu->additem(MN_CONTROLFIELD,"A button", 0,0, &joystick_keymap.a_button); - options_joystick_menu->additem(MN_CONTROLFIELD,"B button", 0,0, &joystick_keymap.b_button); - options_joystick_menu->additem(MN_CONTROLFIELD,"Start", 0,0, &joystick_keymap.start_button); - options_joystick_menu->additem(MN_CONTROLFIELD,"DeadZone", 0,0, &joystick_keymap.dead_zone); + options_joystick_menu->additem(MN_CONTROLFIELD,"X axis", 0,0, 0,&joystick_keymap.x_axis); + options_joystick_menu->additem(MN_CONTROLFIELD,"Y axis", 0,0, 0,&joystick_keymap.y_axis); + options_joystick_menu->additem(MN_CONTROLFIELD,"A button", 0,0, 0,&joystick_keymap.a_button); + options_joystick_menu->additem(MN_CONTROLFIELD,"B button", 0,0, 0,&joystick_keymap.b_button); + options_joystick_menu->additem(MN_CONTROLFIELD,"Start", 0,0, 0,&joystick_keymap.start_button); + options_joystick_menu->additem(MN_CONTROLFIELD,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone); options_joystick_menu->additem(MN_HL,"",0,0); options_joystick_menu->additem(MN_BACK,"Back",0,0); } @@ -454,18 +454,18 @@ void st_menu(void) game_menu->additem(MN_LABEL,"Pause",0,0); game_menu->additem(MN_HL,"",0,0); - game_menu->additem(MN_ACTION,"Continue",0,0); + game_menu->additem(MN_ACTION,"Continue",0,0,MNID_CONTINUE); game_menu->additem(MN_GOTO,"Options",0,options_menu); game_menu->additem(MN_HL,"",0,0); - game_menu->additem(MN_ACTION,"Abort Level",0,0); + game_menu->additem(MN_ACTION,"Abort Level",0,0,MNID_ABORTLEVEL); worldmap_menu->additem(MN_LABEL,"Pause",0,0); worldmap_menu->additem(MN_HL,"",0,0); - worldmap_menu->additem(MN_ACTION,"Continue",0,0); - worldmap_menu->additem(MN_ACTION,"Save",0,0); + worldmap_menu->additem(MN_ACTION,"Continue",0,0,MNID_RETURNWORLDMAP); + worldmap_menu->additem(MN_ACTION,"Save",0,0,MNID_SAVEGAME); worldmap_menu->additem(MN_GOTO,"Options",0,options_menu); worldmap_menu->additem(MN_HL,"",0,0); - worldmap_menu->additem(MN_ACTION,"Quit Game",0,0); + worldmap_menu->additem(MN_ACTION,"Quit Game",0,0,MNID_QUITWORLDMAP); highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0); } @@ -514,34 +514,36 @@ void process_options_menu(void) { switch (options_menu->check()) { - case 2: + case MNID_OPENGL: #ifndef NOOPENGL - if(use_gl != options_menu->item[2].toggled) + if(use_gl != options_menu->item[MNID_OPENGL].toggled) { use_gl = !use_gl; st_video_setup(); } +#else + options_menu->item[MNID_OPENGL].toggled = false; #endif break; - case 3: - if(use_fullscreen != options_menu->item[3].toggled) + case MNID_FULLSCREEN: + if(use_fullscreen != options_menu->item[MNID_FULLSCREEN].toggled) { use_fullscreen = !use_fullscreen; st_video_setup(); } break; - case 4: - if(use_sound != options_menu->item[4].toggled) + case MNID_SOUND: + if(use_sound != options_menu->item[MNID_SOUND].toggled) use_sound = !use_sound; break; - case 5: - if(use_music != options_menu->item[5].toggled) + case MNID_MUSIC: + if(use_music != options_menu->item[MNID_MUSIC].toggled) { - enable_music(options_menu->item[5].toggled); + enable_music(options_menu->item[MNID_MUSIC].toggled); } break; - case 6: - if(show_fps != options_menu->item[6].toggled) + case MNID_SHOWFPS: + if(show_fps != options_menu->item[MNID_SHOWFPS].toggled) show_fps = !show_fps; break; } diff --git a/src/title.cpp b/src/title.cpp index ac89c3503..62469d6c5 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -298,25 +298,25 @@ void title(void) { switch (main_menu->check()) { - case 0: + case MNID_STARTGAME: // Start Game, ie. goto the slots menu update_load_save_game_menu(load_game_menu); break; - case 1: + case MNID_CONTRIB: // Contrib Menu puts("Entering contrib menu"); generate_contrib_menu(); break; - case 3: + case MNID_LEVELEDITOR: halt_music(); leveleditor(1); Menu::set_current(main_menu); break; - case 4: + case MNID_CREDITS: display_credits(); Menu::set_current(main_menu); break; - case 6: + case MNID_QUITMAINMENU: Menu::set_current(0); break; } diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 1b073543e..95a4c6475 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -610,14 +610,14 @@ WorldMap::update() { switch (worldmap_menu->check()) { - case 2: // Return to game + case MNID_RETURNWORLDMAP: // Return to game break; - case 3: + case MNID_SAVEGAME: if (!savegame_file.empty()) savegame(savegame_file); break; - case 6: // Quit Worldmap + case MNID_QUITWORLDMAP: // Quit Worldmap quit = true; break; } -- 2.11.0