We have our own mouse-cursor now! (graphics by Settra Gaia)
[supertux.git] / src / leveleditor.cpp
index d69edd3..0484439 100644 (file)
@@ -66,7 +66,7 @@ void le_quit();
 void le_drawlevel();
 void le_drawinterface();
 void le_checkevents();
-void le_change(float x, float y, unsigned char c);
+void le_change(float x, float y, int tm, unsigned int c);
 void le_testlevel();
 void le_showhelp();
 void le_set_defaults(void);
@@ -90,7 +90,7 @@ static int le_show_grid;
 static int le_frame;
 static texture_type le_selection;
 static int done;
-static char le_current_tile;
+static unsigned int le_current_tile;
 static bool le_mouse_pressed[2];
 static button_type le_save_level_bt;
 static button_type le_test_level_bt;
@@ -118,21 +118,6 @@ static square selection;
 static int le_selection_mode;
 static SDL_Event event;
 
-void le_activate_bad_guys(void)
-{
-  int x,y;
-
-  /* Activate bad guys: */
-
-  /* as oposed to the gameloop.c func, this one doesn't remove
-  the badguys from tiles                                    */
-
-  for (y = 0; y < 15; ++y)
-    for (x = 0; x < le_current_level->width; ++x)
-      if (le_current_level->tiles[y][x] >= '0' && le_current_level->tiles[y][x] <= '9')
-        add_bad_guy(x * 32, y * 32, static_cast<BadGuyKind>(le_current_level->tiles[y][x] - '0'));
-}
-
 void le_set_defaults()
 {
   if(le_current_level != NULL)
@@ -238,7 +223,6 @@ int leveleditor(int levelnb)
                      le_update_buttons(le_current_level->theme.c_str());
                       le_set_defaults();
                       level_load_gfx(le_current_level);
-                      le_activate_bad_guys();
                       show_menu = true;
                     }
                   break;
@@ -270,7 +254,6 @@ int leveleditor(int levelnb)
                      le_update_buttons(le_current_level->theme.c_str());
                       le_set_defaults();
                       level_load_gfx(le_current_level);
-                      le_activate_bad_guys();
                       menu_item_change_input(&subset_new_menu->item[2],"");
                       show_menu = true;
                       break;
@@ -292,6 +275,7 @@ int leveleditor(int levelnb)
                   break;
                 }
             }
+           mouse_cursor->draw();
         }
 
       if(done)
@@ -379,7 +363,7 @@ int le_init()
   le_level_changed = false;
   le_current_level = NULL;
 
-  le_current_tile = '.';
+  le_current_tile = 0;
   le_mouse_pressed[LEFT] = false;
   le_mouse_pressed[RIGHT] = false;
 
@@ -594,7 +578,7 @@ void update_subset_settings_menu()
 
 void apply_level_settings_menu()
 {
-  int i,y,j;
+  int i;
   i = false;
 
   le_current_level->name = level_settings_menu->item[2].input;
@@ -612,7 +596,7 @@ void apply_level_settings_menu()
       i = true;
     }
 
-  if(i == true)
+  if(i)
     {
       level_free_gfx();
       level_load_gfx(le_current_level);
@@ -620,28 +604,7 @@ void apply_level_settings_menu()
 
   le_current_level->song_title = string_list_active(level_settings_menu->item[4].list);
 
-  i = le_current_level->width;
-  le_current_level->width = atoi(level_settings_menu->item[6].input);
-  if(le_current_level->width < i)
-    {
-      if(le_current_level->width < 21)
-        le_current_level->width = 21;
-      for(y = 0; y < 15; ++y)
-        {
-          le_current_level->tiles[y] = (unsigned int*) realloc(le_current_level->tiles[y],(le_current_level->width+1)*sizeof(unsigned int));
-          le_current_level->tiles[y][le_current_level->width] = (unsigned int) '\0';
-        }
-    }
-  else if(le_current_level->width > i)
-    {
-      for(y = 0; y < 15; ++y)
-        {
-          le_current_level->tiles[y] = (unsigned int*) realloc(le_current_level->tiles[y],(le_current_level->width+1)*sizeof(unsigned int));
-          for(j = 0; j < le_current_level->width - i; ++j)
-            le_current_level->tiles[y][i+j] = (unsigned int) '.';
-          le_current_level->tiles[y][le_current_level->width] = (unsigned int) '\0';
-        }
-    }
+  level_change_size(le_current_level, atoi(level_settings_menu->item[6].input));
   le_current_level->time_left = atoi(level_settings_menu->item[7].input);
   le_current_level->gravity = atof(level_settings_menu->item[8].input);
   le_current_level->bkgd_red = atoi(level_settings_menu->item[9].input);
@@ -677,8 +640,6 @@ void le_goto_level(int levelnb)
 
   level_free_gfx();
   level_load_gfx(le_current_level);
-
-  le_activate_bad_guys();
 }
 
 void le_quit(void)
@@ -838,12 +799,11 @@ void le_drawlevel()
   for (y = 0; y < 15; ++y)
     for (x = 0; x < 20; ++x)
       {
-        drawshape(x * 32 - ((int)pos_x % 32), y * 32,
-                  le_current_level->tiles[y][x + (int)(pos_x / 32)]);
+        drawshape(x * 32 - ((int)pos_x % 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)]);
 
         /* draw whats inside stuff when cursor is selecting those */
         /* (draw them all the time - is this the right behaviour?) */
-        switch(le_current_level->tiles[y][x + (int)(pos_x/32)])
+        switch(le_current_level->ia_tiles[y][x + (int)(pos_x/32)])
           {
           case 'B':
             texture_draw(&img_mints, x * 32 - ((int)pos_x % 32), y*32);
@@ -854,7 +814,7 @@ void le_drawlevel()
           case 'x':
           case 'y':
           case 'A':
-            texture_draw(&img_distro[(frame / 5) % 4], x * 32 - ((int)pos_x % 32), y*32);
+            texture_draw(&img_distro[(global_frame_counter / 5) % 4], x * 32 - ((int)pos_x % 32), y*32);
             break;
           default:
             break;
@@ -876,7 +836,7 @@ void le_drawlevel()
 
   /* Draw the player: */
   /* for now, the position is fixed at (0, 240) */
-  texture_draw(&tux_right[(frame / 5) % 3], 0 - pos_x, 240);
+  texture_draw(&tux_right[(global_frame_counter / 5) % 3], 0 - pos_x, 240);
 }
 
 void le_checkevents()
@@ -890,18 +850,19 @@ void le_checkevents()
 
   while(SDL_PollEvent(&event))
     {
+     if(show_menu)
+      menu_event(event);
+    
       /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
       if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > 0 && event.motion.x < screen->w - 64 &&
                                        event.motion.y > 0 && event.motion.y < screen->h)))
         {
-
           switch(event.type)
             {
             case SDL_KEYDOWN:  // key pressed
               key = event.key.keysym.sym;
               if(show_menu)
                 {
-                  menu_event(&event.key.keysym);
                   if(key == SDLK_ESCAPE)
                     {
                       show_menu = false;
@@ -1014,13 +975,13 @@ void le_checkevents()
                   cursor_x = ((int)(pos_x + x) / 32) * 32;
                   cursor_y = ((int) y / 32) * 32;
 
-                  if(le_mouse_pressed[LEFT] == true)
+                  if(le_mouse_pressed[LEFT])
                     {
                       selection.x2 = x + pos_x;
                       selection.y2 = y;
                     }
 
-                  if(le_mouse_pressed[RIGHT] == true)
+                  if(le_mouse_pressed[RIGHT])
                     {
                       pos_x += -1 * event.motion.xrel;
                     }
@@ -1105,7 +1066,7 @@ void le_checkevents()
                     }
                   button_event(&le_rubber_bt,&event);
                   if(button_get_state(&le_rubber_bt) == BUTTON_CLICKED)
-                    le_current_tile = '.';
+                    le_current_tile = 0;
                   button_event(&le_select_mode_one_bt,&event);
                   if(button_get_state(&le_select_mode_one_bt) == BUTTON_CLICKED)
                     le_selection_mode = CURSOR;
@@ -1250,7 +1211,7 @@ void le_checkevents()
 
               if(le_mouse_pressed[LEFT])
                 {
-                  le_change(cursor_x, cursor_y, le_current_tile);
+                  le_change(cursor_x, cursor_y, TM_IA, le_current_tile);
                 }
             }
         }
@@ -1311,7 +1272,7 @@ void le_highlight_selection()
   fillrect(x1*32-pos_x, y1*32,32* (x2 - x1 + 1),32 * (y2 - y1 + 1),173,234,177,103);
 }
 
-void le_change(float x, float y, unsigned char c)
+void le_change(float x, float y, int tm, unsigned int c)
 {
   if(le_current_level != NULL)
     {
@@ -1324,7 +1285,7 @@ void le_change(float x, float y, unsigned char c)
       switch(le_selection_mode)
         {
         case CURSOR:
-          level_change(le_current_level,x,y,c);
+          level_change(le_current_level,x,y,tm,c);
 
           yy = ((int)y / 32);
           xx = ((int)x / 32);
@@ -1332,7 +1293,7 @@ void le_change(float x, float y, unsigned char c)
           /* if there is a bad guy over there, remove it */
           for(i = 0; i < bad_guys.size(); ++i)
               if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32)
-                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(&bad_guys[i]));
+                  bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(&bad_guys[i]));
 
           if(c == '0')  /* if it's a bad guy */
             add_bad_guy(xx*32, yy*32, BAD_BSOD);
@@ -1373,12 +1334,12 @@ void le_change(float x, float y, unsigned char c)
           for(i = 0; i < bad_guys.size(); ++i)
               if(bad_guys[i].base.x/32 >= x1 && bad_guys[i].base.x/32 <= x2
                   && bad_guys[i].base.y/32 >= y1 && bad_guys[i].base.y/32 <= y2)
-                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(&bad_guys[i]));
+                  bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(&bad_guys[i]));
 
           for(xx = x1; xx <= x2; xx++)
             for(yy = y1; yy <= y2; yy++)
               {
-                level_change(le_current_level, xx*32, yy*32, c);
+                level_change(le_current_level, xx*32, yy*32, tm, c);
 
                 if(c == '0')  // if it's a bad guy
                   add_bad_guy(xx*32, yy*32, BAD_BSOD);
@@ -1402,7 +1363,6 @@ void le_testlevel()
   arrays_init();
   level_load_gfx(le_current_level);
   loadshared();
-  le_activate_bad_guys();
 }
 
 void le_showhelp()