- reorganized menu flow as descripted in the todo, this breaks returning from the...
authorIngo Ruhnke <grumbel@gmx.de>
Sat, 10 Apr 2004 18:56:17 +0000 (18:56 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sat, 10 Apr 2004 18:56:17 +0000 (18:56 +0000)
SVN-Revision: 451

src/gameloop.cpp
src/gameloop.h
src/menu.cpp
src/menu.h
src/setup.cpp
src/setup.h
src/title.cpp
src/worldmap.cpp

index b4b4c81..cf433cf 100644 (file)
@@ -701,11 +701,11 @@ int gameloop(const char * subset, int levelnb, int mode)
             }
           else if(current_menu == save_game_menu )
             {
-              process_save_load_game_menu(true);
+              process_save_game_menu();
             }
           else if(current_menu == load_game_menu )
             {
-              process_save_load_game_menu(false);
+              process_load_game_menu();
             }
         }
 
@@ -1619,7 +1619,7 @@ void loadgame(int slot)
 
 }
 
-void slotinfo(char **pinfo, int slot)
+std::string slotinfo(int slot)
 {
   FILE* fi;
   char slotfile[1024];
@@ -1648,7 +1648,6 @@ void slotinfo(char **pinfo, int slot)
       fclose(fi);
     }
 
-  *pinfo = (char*) malloc(sizeof(char) * (strlen(tmp)+1));
-  strcpy(*pinfo,tmp);
+  return tmp;
 }
 
index 2f37215..3c92465 100644 (file)
@@ -35,7 +35,7 @@ void activate_bad_guys(st_level* plevel);
 int gameloop(const char * subset, int levelnb, int mode);
 void savegame(int slot);
 void loadgame(int slot);
-void slotinfo(char **pinfo, int slot);
+std::string slotinfo(int slot);
 bool issolid(float x, float y);
 bool isbrick(float x, float y);
 bool isice(float x, float y);
index f8bfbf1..3ea2943 100644 (file)
@@ -43,6 +43,7 @@ Menu* options_controls_menu   = 0;
 Menu* highscore_menu = 0;
 Menu* load_game_menu = 0;
 Menu* save_game_menu = 0;
+Menu* contrib_menu   = 0;
 
 Menu* current_menu = 0;
 
index e8a3f40..b0058d4 100644 (file)
@@ -64,7 +64,6 @@ private:
   int width();
   int height();
   
-  
 public:
   timer_type effect;
   int arrange_left;
@@ -106,6 +105,7 @@ extern bool show_menu;
 extern bool menu_change;
 extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right;
 
+extern Menu* contrib_menu;
 extern Menu* main_menu;
 extern Menu* game_menu;
 extern Menu* options_menu;
index 8350bdf..82e5d56 100644 (file)
@@ -11,6 +11,7 @@
 */
 
 #include <assert.h>
+#include <iostream>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -358,15 +359,24 @@ void st_menu(void)
   save_game_menu = new Menu();
   game_menu      = new Menu();
   highscore_menu = new Menu();
+  contrib_menu   = new Menu();
 
   main_menu->set_pos(screen->w/2, 335);
-  main_menu->additem(MN_ACTION,"Start Game",0,0);
-  main_menu->additem(MN_GOTO,"Load Game",0,load_game_menu);
-  main_menu->additem(MN_GOTO,"Options",0,options_menu);
+  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, "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);
 
+  contrib_menu->additem(MN_LABEL,"Contrib Levels",0,0);
+  contrib_menu->additem(MN_HL,"",0,0);
+  contrib_menu->additem(MN_ACTION, "Some Levelset", 0, 0);
+  contrib_menu->additem(MN_ACTION, "Someother Levelset", 0, 0);
+  contrib_menu->additem(MN_ACTION, "Yet another Levelset", 0, 0);
+  contrib_menu->additem(MN_HL,"",0,0);
+  contrib_menu->additem(MN_BACK,"Back",0,0);
+
   options_menu->additem(MN_LABEL,"Options",0,0);
   options_menu->additem(MN_HL,"",0,0);
   options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0);
@@ -391,7 +401,7 @@ void st_menu(void)
   options_controls_menu->additem(MN_HL,"",0,0);
   options_controls_menu->additem(MN_BACK,"Back",0,0);
 
-  load_game_menu->additem(MN_LABEL,"Load Game",0,0);
+  load_game_menu->additem(MN_LABEL,"Start Game",0,0);
   load_game_menu->additem(MN_HL,"",0,0);
   load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0);
   load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0);
@@ -427,43 +437,59 @@ void update_load_save_game_menu(Menu* pmenu, int load)
 {
   for(int i = 2; i < 7; ++i)
     {
-      char *tmp;
-      slotinfo(&tmp,i-1);
-      if(load && strlen(tmp) == strlen("Slot X - Free") )
-        pmenu->item[i].kind = MN_DEACTIVE;
+      // FIXME: Insert a real savegame struct/class here instead of
+      // doing string vodoo
+      std::string tmp = slotinfo(i-1);
+
+      if(load && tmp.length() == strlen("Slot X - Free"))
+        pmenu->item[i].kind = MN_ACTION;
       else
         pmenu->item[i].kind = MN_ACTION;
-      menu_item_change_text(&pmenu->item[i],tmp);
-      free(tmp);
+      menu_item_change_text(&pmenu->item[i], tmp.c_str());
     }
 }
 
-void process_save_load_game_menu(int save)
+void process_save_game_menu()
+{
+  int slot = save_game_menu->check();
+  if (slot != -1)
+    savegame(slot - 1);
+}
+
+bool process_load_game_menu()
 {
-  int slot;
-  switch (slot = (save ? save_game_menu->check() : load_game_menu->check()))
+  int slot = load_game_menu->check();
+
+  if(slot != -1)
     {
-    default:
-      if(slot != -1)
+      // FIXME: Insert a real savegame struct/class here instead of
+      // doing string vodoo
+      std::string tmp = slotinfo(slot-1);
+      if (tmp.length() == strlen("Slot X - Free"))
+        {
+          gameloop("default", 1, ST_GL_PLAY);
+          show_menu = true;
+          Menu::set_current(main_menu);
+        }
+      else
         {
-          if(save)
+          if (game_started)
             {
-              savegame(slot - 1);
+              gameloop("default",slot - 1,ST_GL_LOAD_GAME);
+              show_menu = true;
+              Menu::set_current(main_menu);
             }
           else
             {
-              if (game_started)
-                {
-                  gameloop("default",slot - 1,ST_GL_LOAD_GAME);
-                  show_menu = true;
-                  Menu::set_current(main_menu);
-                }
-              else
-                loadgame(slot - 1);
+              loadgame(slot - 1);
             }
-          st_pause_ticks_stop();
         }
-      break;
+      st_pause_ticks_stop();
+      return true;
+    }
+  else
+    {
+      return false;
     }
 }
 
@@ -608,7 +634,7 @@ void st_video_setup(void)
 
   /* Set window manager stuff: */
 
-  SDL_WM_SetCaption("Super Tux", "Super Tux");
+  SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
 
 }
 
@@ -941,8 +967,7 @@ void parseargs(int argc, char * argv[])
       else if (strcmp(argv[i], "--version") == 0)
         {
           /* Show version: */
-
-          printf("Super Tux - version " VERSION "\n");
+          printf("SuperTux " VERSION "\n");
           exit(0);
         }
       else if (strcmp(argv[i], "--disable-sound") == 0)
index a688ccc..6e1b165 100644 (file)
@@ -35,7 +35,12 @@ void st_shutdown(void);
 void st_menu(void);
 void st_abort(const std::string& reason, const std::string& details);
 void process_options_menu(void);
-void process_save_load_game_menu(int save);
+
+void process_save_game_menu();
+
+/** Return true if the gameloop() was entered, false otherwise */
+bool process_load_game_menu();
+
 void update_load_save_game_menu(Menu* pmenu, int load);
 void parseargs(int argc, char * argv[]);
 
index 8bc8fa8..729851b 100644 (file)
@@ -190,7 +190,7 @@ int title(void)
 
       while (SDL_PollEvent(&event))
         {
-       menu_event(event);
+          menu_event(event);
           if (event.type == SDL_QUIT)
             {
               /* Quit event - quit: */
@@ -231,10 +231,10 @@ int title(void)
 
       /* Draw the high score: */
       /*
-      sprintf(str, "High score: %d", hs_score);
-      text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1);
-      sprintf(str, "by %s", hs_name);
-      text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1);
+        sprintf(str, "High score: %d", hs_score);
+        text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1);
+        sprintf(str, "by %s", hs_name);
+        text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1);
       */
 
       /* Don't draw menu, if quit is true */
@@ -245,7 +245,10 @@ int title(void)
         {
           switch (main_menu->check())
             {
+#if 0
             case 0:
+              // Quick Play
+              // FIXME: obsolete
               done = 0;
               i = 0;
               if(level_subsets.num_items != 0)
@@ -278,8 +281,7 @@ int title(void)
                               quit = 1;
                               break;
                             case SDL_KEYDOWN:          // key pressed
-                              /* Keypress... */
-
+                              // Keypress...
                               key = event.key.keysym.sym;
 
                               if(key == SDLK_LEFT)
@@ -322,9 +324,14 @@ int title(void)
               titletux.level_begin();
               update_time = st_get_ticks();
               break;
-            case 1:
+#endif
+            case 0:
+              // Start Game, ie. goto the slots menu
               update_load_save_game_menu(load_game_menu, true);
               break;
+            case 1:
+              // Contrib Menu
+              break;
             case 3:
               done = 1;
               quit = leveleditor(1);
@@ -343,7 +350,17 @@ int title(void)
         }
       else if(current_menu == load_game_menu)
         {
-          process_save_load_game_menu(false);
+          if (process_load_game_menu())
+            {
+              // reset tux
+              scroll_x = 0;
+              titletux.level_begin();
+              update_time = st_get_ticks();
+            }
+        }
+      else if(current_menu == contrib_menu)
+        {
+          
         }
 
       mouse_cursor->draw();
index f873c96..6c8d918 100644 (file)
@@ -105,8 +105,8 @@ Tux::Tux(WorldMap* worldmap_)
   texture_load(&sprite, datadir +  "/images/worldmap/tux.png", USE_ALPHA);
   offset = 0;
   moving = false;
-  tile_pos.x = 0;
-  tile_pos.y = 0;
+  tile_pos.x = 5;
+  tile_pos.y = 5;
   direction = NONE;
   input_direction = NONE;
 }