- fixed some crashes where there was an invalid tile number
[supertux.git] / src / setup.cpp
index 5118cfd..dbec4db 100644 (file)
@@ -42,8 +42,8 @@
 #include "defines.h"
 #include "globals.h"
 #include "setup.h"
-#include "screen.h"
-#include "texture.h"
+#include "screen/screen.h"
+#include "screen/texture.h"
 #include "menu.h"
 #include "gameloop.h"
 #include "configfile.h"
@@ -51,7 +51,7 @@
 #include "worldmap.h"
 #include "resources.h"
 #include "intro.h"
-#include "music_manager.h"
+#include "sound_manager.h"
 
 #include "player.h"
 
 #define DATA_PREFIX "./data/"
 #endif
 
+/* Screen proprities: */
+/* Don't use this to test for the actual screen sizes. Use screen->w/h instead! */
+#define SCREEN_W 800
+#define SCREEN_H 600
+
 /* Local function prototypes: */
 
 void seticon(void);
@@ -407,19 +412,21 @@ void st_menu(void)
   options_menu->additem(MN_TOGGLE,"Show FPS  ",show_fps,0, MNID_SHOWFPS);
   options_menu->additem(MN_GOTO,"Keyboard Setup",0,options_keys_menu);
 
-  //if(use_joystick)
-  //  options_menu->additem(MN_GOTO,"Joystick Setup",0,options_joystick_menu);
+  if(use_joystick)
+    options_menu->additem(MN_GOTO,"Joystick Setup",0,options_joystick_menu);
 
   options_menu->additem(MN_HL,"",0,0);
   options_menu->additem(MN_BACK,"Back",0,0);
   
   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, 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/Run", 0,0, 0,&keymap.fire);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Left move", 0,0, 0,&keymap.left);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Right move", 0,0, 0,&keymap.right);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Jump", 0,0, 0,&keymap.jump);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Duck", 0,0, 0,&keymap.duck);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Activate", 0, 0, 0,
+          &keymap.activate);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Power/Run", 0,0, 0,&keymap.fire);
   options_keys_menu->additem(MN_HL,"",0,0);
   options_keys_menu->additem(MN_BACK,"Back",0,0);
 
@@ -427,12 +434,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, 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_CONTROLFIELD_JS,"X axis", 0,0, 0,&joystick_keymap.x_axis);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
+    options_joystick_menu->additem(MN_CONTROLFIELD_JS,"A button", 0,0, 0,&joystick_keymap.a_button);
+    options_joystick_menu->additem(MN_CONTROLFIELD_JS,"B button", 0,0, 0,&joystick_keymap.b_button);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Start", 0,0, 0,&joystick_keymap.start_button);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"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);
     }
@@ -500,7 +507,8 @@ bool process_load_game_menu()
           draw_intro();
         }
 
-      fadeout();
+      // shrink_fade(Point((screen->w/2),(screen->h/2)), 1000);
+      fadeout(256);
       WorldMapNS::WorldMap worldmap;
      
       // Load the game or at least set the savegame_file variable
@@ -550,7 +558,7 @@ void process_options_menu(void)
       if(use_music != options_menu->isToggled(MNID_MUSIC))
         {
           use_music = !use_music;
-          music_manager->enable_music(use_music);
+          sound_manager->enable_music(use_music);
         }
       break;
     case MNID_SHOWFPS:
@@ -576,14 +584,19 @@ void st_general_setup(void)
 
   /* Load global images: */
 
-  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);
+  black_text  = new Font(datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18);
+  gold_text   = new Font(datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
+  silver_text = new Font(datadir + "/images/status/letters-silver.png", TEXT_TEXT, 16,18);
+  blue_text   = new Font(datadir + "/images/status/letters-blue.png", TEXT_TEXT,
+      16,18, 3);
+  red_text    = new Font(datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18);
+  green_text  = new Font(datadir + "/images/status/letters-green.png", TEXT_TEXT, 16,18);
+  white_text  = new Font(datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18);
+  white_small_text = new Font(datadir +
+      "/images/status/letters-white-small.png", TEXT_TEXT, 8,9, 1);
+  white_big_text   = new Font(datadir + "/images/status/letters-white-big.png",
+      TEXT_TEXT, 20,22, 3);
+  yellow_nums = new Font(datadir + "/images/status/numbers.png", TEXT_NUM, 32,32);
 
   /* Load GUI/menu images: */
   checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA);
@@ -594,6 +607,7 @@ void st_general_setup(void)
 
   /* Load the mouse-cursor */
   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
+  MouseCursor::set_current(mouse_cursor);
   
 }
 
@@ -603,9 +617,11 @@ void st_general_free(void)
   /* Free global images: */
   delete black_text;
   delete gold_text;
+  delete silver_text;
   delete white_text;
   delete blue_text;
   delete red_text;
+  delete green_text;
   delete white_small_text;
   delete white_big_text;
   delete yellow_nums;
@@ -631,11 +647,7 @@ void st_general_free(void)
 
 void st_video_setup(void)
 {
-  if(screen != NULL)
-    SDL_FreeSurface(screen);
-
   /* Init SDL Video: */
-
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
     {
       fprintf(stderr,
@@ -659,8 +671,6 @@ void st_video_setup(void)
 
 void st_video_setup_sdl(void)
 {
-  SDL_FreeSurface(screen);
-
   if (use_fullscreen)
     {
       screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
@@ -891,13 +901,13 @@ void seticon(void)
 
   /* Load icon into a surface: */
 
-  icon = IMG_Load((datadir + "/images/icon.xpm").c_str());
+  icon = IMG_Load((datadir + "/images/supertux.xpm").c_str());
   if (icon == NULL)
     {
       fprintf(stderr,
               "\nError: I could not load the icon image: %s%s\n"
               "The Simple DirectMedia error that occured was:\n"
-              "%s\n\n", datadir.c_str(), "/images/icon.xpm", SDL_GetError());
+              "%s\n\n", datadir.c_str(), "/images/supertux.xpm", SDL_GetError());
       exit(1);
     }
 
@@ -1047,8 +1057,8 @@ void parseargs(int argc, char * argv[])
                "Misc Options:\n"
                "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
                "  --joymap XAXIS:YAXIS:A:B:START\n"
-               "  --leveleditor       Opens the leveleditor in a file. (Only works when a file is provided.)\n"
                "                      Define how joystick buttons and axis should be mapped\n"
+               "  --leveleditor       Opens the leveleditor in a file. (Only works when a file is provided.)\n"
                "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
                "  --debug-mode        Enables the debug-mode, which is useful for developers.\n"
                "  --help              Display a help message summarizing command-line\n"
@@ -1089,7 +1099,7 @@ void usage(char * prog, int ret)
 
   /* Display the usage message: */
 
-  fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version] [--worldmap] FILENAME\n",
+  fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version] [--leveleditor] FILENAME\n",
           prog);