Added a new concept to the menu, the ID.
authorRicardo Cruz <rick2@aeiou.pt>
Sat, 24 Apr 2004 09:32:32 +0000 (09:32 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Sat, 24 Apr 2004 09:32:32 +0000 (09:32 +0000)
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
src/leveleditor.cpp
src/menu.cpp
src/menu.h
src/setup.cpp
src/title.cpp
src/worldmap.cpp

index 5d0d51e..24a5df3 100644 (file)
@@ -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;
index 2984891..f79d877 100644 (file)
@@ -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);
index db41fce..1a76b18 100644 (file)
@@ -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)
     {
index 43aee85..280a459 100644 (file)
 #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 ();
   
index 88afb06..3dd909d 100644 (file)
@@ -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;
     }
index ac89c35..62469d6 100644 (file)
@@ -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;
                 }
index 1b07354..95a4c64 100644 (file)
@@ -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;
             }