- added 1up to tileset
[supertux.git] / src / setup.cpp
index 8350bdf..ffd9e3f 100644 (file)
@@ -11,6 +11,7 @@
 */
 
 #include <assert.h>
+#include <iostream>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -358,17 +359,25 @@ void st_menu(void)
   save_game_menu = new Menu();
   game_menu      = new Menu();
   highscore_menu = new Menu();
+  contrib_menu   = new Menu();
+  contrib_subset_menu   = new Menu();
+  worldmap_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);
 
   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);
+#else
+  options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl,0);
+#endif
   options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0);
   if(audio_device)
     {
@@ -387,11 +396,11 @@ void st_menu(void)
   
   options_controls_menu->additem(MN_LABEL,"Controls",0,0);
   options_controls_menu->additem(MN_HL,"",0,0);
-  options_controls_menu->additem(MN_CONTROLFIELD,"Move Right",tux.keymap.right,0);
+  //FIXME:options_controls_menu->additem(MN_CONTROLFIELD,"Move Right", tux.keymap.right,0);
   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);
@@ -420,6 +429,13 @@ void st_menu(void)
   game_menu->additem(MN_HL,"",0,0);
   game_menu->additem(MN_ACTION,"Quit Game",0,0);
 
+  worldmap_menu->additem(MN_LABEL,"Worldmap Menu",0,0);
+  worldmap_menu->additem(MN_HL,"",0,0);
+  worldmap_menu->additem(MN_ACTION,"Return To Game",0,0);
+  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);
+
   highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0);
 }
 
@@ -427,43 +443,68 @@ 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);
+      pmenu->item[i].change_text(tmp.c_str());
     }
 }
 
-void process_save_load_game_menu(int save)
+void process_save_game_menu()
 {
-  int slot;
-  switch (slot = (save ? save_game_menu->check() : load_game_menu->check()))
+  int slot = save_game_menu->check();
+  if (slot != -1)
+    GameSession::current()->savegame(slot - 1);
+}
+
+bool process_load_game_menu()
+{
+  int slot = load_game_menu->check();
+
+  if(slot != -1)
     {
-    default:
-      if(slot != -1)
-        {
-          if(save)
+      // 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"))
+        { // Slot is free, so start a new game
+          GameSession session("default", 1, ST_GL_PLAY);
+          session.run();
+
+          show_menu = true;
+          Menu::set_current(main_menu);
+        }
+      else
+        { 
+          puts("Warning: Loading games isn't supported at the moment");
+#if 0
+          // Slot contains a level, so load it
+          if (game_started)
             {
-              savegame(slot - 1);
+              GameSession session("default",slot - 1,ST_GL_LOAD_GAME);
+              session.run();
+
+              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();
+#endif
         }
-      break;
+      st_pause_ticks_stop();
+      return true;
+    }
+  else
+    {
+      return false;
     }
 }
 
@@ -473,18 +514,27 @@ void process_options_menu(void)
   switch (options_menu->check())
     {
     case 2:
-      if(use_fullscreen != options_menu->item[2].toggled)
+#ifndef NOOPENGL
+      if(use_gl != options_menu->item[2].toggled)
         {
-          use_fullscreen = !use_fullscreen;
+          use_gl = !use_gl;
           st_video_setup();
         }
+#endif
       break;
     case 3:
-      if(use_sound != options_menu->item[3].toggled)
-        use_sound = !use_sound;
+      if(use_fullscreen != options_menu->item[3].toggled)
+        {
+          use_fullscreen = !use_fullscreen;
+          st_video_setup();
+        }
       break;
     case 4:
-      if(use_music != options_menu->item[4].toggled)
+      if(use_sound != options_menu->item[4].toggled)
+        use_sound = !use_sound;
+      break;
+    case 5:
+      if(use_music != options_menu->item[5].toggled)
         {
           if(use_music)
             {
@@ -504,8 +554,8 @@ void process_options_menu(void)
             }
         }
       break;
-    case 5:
-      if(show_fps != options_menu->item[5].toggled)
+    case 6:
+      if(show_fps != options_menu->item[6].toggled)
         show_fps = !show_fps;
       break;
     }
@@ -527,21 +577,21 @@ void st_general_setup(void)
 
   /* Load global images: */
 
-  text_load(&black_text, datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18);
-  text_load(&gold_text,datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
-  text_load(&blue_text,datadir + "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
-  text_load(&red_text,datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18);
-  text_load(&white_text,datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18);
-  text_load(&white_small_text,datadir + "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
-  text_load(&white_big_text,datadir + "/images/status/letters-white-big.png", TEXT_TEXT, 20,23);
-  text_load(&yellow_nums,datadir + "/images/status/numbers.png", TEXT_NUM, 32,32);
+  black_text  = new Text(datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18);
+  gold_text   = new Text(datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
+  blue_text   = new Text(datadir + "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
+  red_text    = new Text(datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18);
+  white_text  = new Text(datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18);
+  white_small_text = new Text(datadir + "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
+  white_big_text   = new Text(datadir + "/images/status/letters-white-big.png", TEXT_TEXT, 20,23);
+  yellow_nums = new Text(datadir + "/images/status/numbers.png", TEXT_NUM, 32,32);
 
   /* Load GUI/menu images: */
-  texture_load(&checkbox, datadir + "/images/status/checkbox.png", USE_ALPHA);
-  texture_load(&checkbox_checked, datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
-  texture_load(&back, datadir + "/images/status/back.png", USE_ALPHA);
-  texture_load(&arrow_left, datadir + "/images/icons/left.png", USE_ALPHA);
-  texture_load(&arrow_right, datadir + "/images/icons/right.png", USE_ALPHA);
+  checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA);
+  checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
+  back = new Surface(datadir + "/images/status/back.png", USE_ALPHA);
+  arrow_left = new Surface(datadir + "/images/icons/left.png", USE_ALPHA);
+  arrow_right = new Surface(datadir + "/images/icons/right.png", USE_ALPHA);
 
   /* Load the mouse-cursor */
   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
@@ -553,20 +603,20 @@ void st_general_free(void)
 
   /* Free global images: */
 
-  text_free(&black_text);
-  text_free(&gold_text);
-  text_free(&white_text);
-  text_free(&blue_text);
-  text_free(&red_text);
-  text_free(&white_small_text);
-  text_free(&white_big_text);
+  delete black_text;
+  delete gold_text;
+  delete white_text;
+  delete blue_text;
+  delete red_text;
+  delete white_small_text;
+  delete white_big_text;
 
   /* Free GUI/menu images: */
-  texture_free(&checkbox);
-  texture_free(&checkbox_checked);
-  texture_free(&back);
-  texture_free(&arrow_left);
-  texture_free(&arrow_right);
+  delete checkbox;
+  delete checkbox_checked;
+  delete back;
+  delete arrow_left;
+  delete arrow_right;
 
   /* Free mouse-cursor */
   delete mouse_cursor;
@@ -582,7 +632,6 @@ void st_general_free(void)
 
 void st_video_setup(void)
 {
-
   if(screen != NULL)
     SDL_FreeSurface(screen);
 
@@ -598,18 +647,15 @@ void st_video_setup(void)
     }
 
   /* Open display: */
-
   if(use_gl)
     st_video_setup_gl();
   else
     st_video_setup_sdl();
 
-  texture_setup();
+  Surface::reload_all();
 
   /* Set window manager stuff: */
-
-  SDL_WM_SetCaption("Super Tux", "Super Tux");
-
+  SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
 }
 
 void st_video_setup_sdl(void)
@@ -941,8 +987,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)