[Super-tux-commit] supertux/src gameloop.cpp,1.97,1.98 leveleditor.cpp,1.62,1.63 menu.cpp,1.51,1.52
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-04-24 09:32:45
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv803/src Modified Files: gameloop.cpp leveleditor.cpp menu.cpp menu.h setup.cpp title.cpp worldmap.cpp Log Message: 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 :) Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- menu.cpp 23 Apr 2004 11:12:43 -0000 1.51 +++ menu.cpp 24 Apr 2004 09:32:31 -0000 1.52 @@ -98,7 +98,7 @@ /* 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 @@ else pnew_item->list = NULL; + pnew_item->id = id; pnew_item->int_p = int_p_; return pnew_item; @@ -222,6 +223,7 @@ 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::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 @@ int Menu::check() { - return hit_item; + return item[hit_item].id; /* if (item.size() != 0) { Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- setup.cpp 23 Apr 2004 11:42:18 -0000 1.51 +++ setup.cpp 24 Apr 2004 09:32:32 -0000 1.52 @@ -376,32 +376,32 @@ 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 @@ 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 @@ { 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 @@ 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 @@ { 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; } Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- menu.h 23 Apr 2004 11:12:43 -0000 1.44 +++ menu.h 24 Apr 2004 09:32:31 -0000 1.45 @@ -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 @@ 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 @@ 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 @@ ~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 (); Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.62 retrieving revision 1.63 diff -u -d -r1.62 -r1.63 --- leveleditor.cpp 22 Apr 2004 19:15:22 -0000 1.62 +++ leveleditor.cpp 24 Apr 2004 09:32:31 -0000 1.63 @@ -219,13 +219,13 @@ { 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 @@ { switch (level_settings_menu->check()) { - case 17: + case MNID_SUBSETSETTINGS: apply_level_settings_menu(); Menu::set_current(leveleditor_menu); break; @@ -413,12 +413,12 @@ 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 @@ 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); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- title.cpp 22 Apr 2004 11:30:53 -0000 1.57 +++ title.cpp 24 Apr 2004 09:32:32 -0000 1.58 @@ -298,25 +298,25 @@ { 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; } Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- worldmap.cpp 22 Apr 2004 20:41:40 -0000 1.44 +++ worldmap.cpp 24 Apr 2004 09:32:32 -0000 1.45 @@ -610,14 +610,14 @@ { 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; } Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.97 retrieving revision 1.98 diff -u -d -r1.97 -r1.98 --- gameloop.cpp 24 Apr 2004 08:38:01 -0000 1.97 +++ gameloop.cpp 24 Apr 2004 09:32:31 -0000 1.98 @@ -454,10 +454,10 @@ { 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; |