properly implement invisible blocks
[supertux.git] / src / leveleditor.cpp
index f25cd23..81f0bfb 100644 (file)
@@ -15,6 +15,8 @@
  *                                                                         *
  ***************************************************************************/
 
+#include <config.h>
+
 #include <stdlib.h>
 #include <algorithm>
 
 #include "sector.h"
 #include "background.h"
 #include "gameloop.h"
-#include "badguy.h"
 #include "gameobjs.h"
-#include "door.h"
 #include "camera.h"
 
 LevelEditor::LevelEditor()
 {
-show_grid = true;
-
-selection.clear();
-global_frame_counter = 0;
-frame_timer.init(true);
-level_name_timer.init(true);
-selection_end = selection_ini = Vector(0,0);
-left_button = middle_button = mouse_moved =  false;
-
-cur_layer = LAYER_TILES;
-level_changed = false;
-
-sector = 0;
-zoom = 1.0;
-
-/* Creating menus */
-level_subsets = FileSystem::dsubdirs("/levels", "info");
-subset_menu = new Menu();
-subset_menu->additem(MN_LABEL,_("Load Subset"),0,0);
-subset_menu->additem(MN_HL,"",0,0);
-int i = 0;
-for(std::set<std::string>::iterator it = level_subsets.begin(); it != level_subsets.end(); ++it, ++i)
-{
-std::cerr << "adding entry level subset " << i << " entry: " << (*it) << std::endl;
-  subset_menu->additem(MN_ACTION, (*it),0,0,i);
-}
-subset_menu->additem(MN_HL,"",0,0);
-subset_menu->additem(MN_BACK,_("Back"),0,0);
-
-create_subset_menu = new Menu();
-create_subset_menu->additem(MN_LABEL,_("New Level Subset"),0,0);
-create_subset_menu->additem(MN_HL,"",0,0);
-create_subset_menu->additem(MN_TEXTFIELD,_("Filename   "),0,0,MN_ID_FILENAME_SUBSET);
-create_subset_menu->additem(MN_TEXTFIELD,_("Title      "),0,0,MN_ID_TITLE_SUBSET);
-create_subset_menu->additem(MN_TEXTFIELD,_("Description"),0,0,MN_ID_DESCRIPTION_SUBSET);
-create_subset_menu->additem(MN_ACTION,_("Create"),0,0, MN_ID_CREATE_SUBSET);
-create_subset_menu->additem(MN_HL,"",0,0);
-create_subset_menu->additem(MN_BACK,_("Back"),0,0);
-
-main_menu = new Menu();
-main_menu->additem(MN_LABEL,_("Level Editor Menu"),0,0);
-main_menu->additem(MN_HL,"",0,0);
-main_menu->additem(MN_ACTION,_("Return to Level Editor"),0,0,MN_ID_RETURN);
-main_menu->additem(MN_GOTO,_("Create Level Subset"),0,create_subset_menu);
-main_menu->additem(MN_GOTO,_("Load Level Subset"),0,subset_menu);
-main_menu->additem(MN_HL,"",0,0);
-main_menu->additem(MN_ACTION,_("Quit Level Editor"),0,0,MN_ID_QUIT);
-
-settings_menu = new Menu();
-settings_menu->additem(MN_LABEL,_("Level Settings"),0,0);
-settings_menu->additem(MN_HL,"",0,0);
-settings_menu->additem(MN_TEXTFIELD,_("Name    "),0,0,MN_ID_NAME);
-settings_menu->additem(MN_TEXTFIELD,_("Author  "),0,0,MN_ID_AUTHOR);
-settings_menu->additem(MN_NUMFIELD, _("Width   "),0,0,MN_ID_WIDTH);
-settings_menu->additem(MN_NUMFIELD, _("Height  "),0,0,MN_ID_HEIGHT);
-settings_menu->additem(MN_HL,"",0,0);
-settings_menu->additem(MN_ACTION,_("Apply"),0,0,MN_ID_APPLY_SETTINGS);
-
-/* Creating button groups */
-load_buttons_gfx();
-
-tiles_board = new ButtonGroup(Vector(screen->w - 140, 100),
-          Vector(32,32), Vector(4,8));
-
-TileManager* tilemanager = TileManager::instance();
-
-tiles_board->add_button(Button(img_rubber_bt, _("Eraser"), SDLKey(SDLK_DELETE)), 0);
-for(unsigned int id = 1; id < tilemanager->total_ids(); id++)
-  {
-  Tile* tile = tilemanager->get(id);
-  if(!tile)
-    continue;
+  show_grid = true;
+
+  selection.clear();
+  global_frame_counter = 0;
+  selection_end = selection_ini = Vector(0,0);
+  left_button = middle_button = mouse_moved =  false;
+  level = 0;
+  level_subset = 0;
+
+  cur_layer = LAYER_TILES;
+  level_changed = false;
+
+  sector = 0;
+  zoom = 1.0;
+
+  /* Creating menus */
+  level_subsets = FileSystem::dsubdirs("/levels", "info");
+  subset_menu = new Menu();
+  subset_menu->additem(MN_LABEL,_("Load Subset"),0,0);
+  subset_menu->additem(MN_HL,"",0,0);
+  int i = 0;
+  for(std::set<std::string>::iterator it = level_subsets.begin(); it != level_subsets.end(); ++it, ++i)
+    subset_menu->additem(MN_ACTION, (*it),0,0,i);
+  subset_menu->additem(MN_HL,"",0,0);
+  subset_menu->additem(MN_BACK,_("Back"),0,0);
+
+  create_subset_menu = new Menu();
+  create_subset_menu->additem(MN_LABEL,_("New Level Subset"),0,0);
+  create_subset_menu->additem(MN_HL,"",0,0);
+  create_subset_menu->additem(MN_TEXTFIELD,_("Filename   "),0,0,MN_ID_FILENAME_SUBSET);
+  create_subset_menu->additem(MN_TEXTFIELD,_("Title      "),0,0,MN_ID_TITLE_SUBSET);
+  create_subset_menu->additem(MN_TEXTFIELD,_("Description"),0,0,MN_ID_DESCRIPTION_SUBSET);
+  create_subset_menu->additem(MN_ACTION,_("Create"),0,0, MN_ID_CREATE_SUBSET);
+  create_subset_menu->additem(MN_HL,"",0,0);
+  create_subset_menu->additem(MN_BACK,_("Back"),0,0);
+
+  main_menu = new Menu();
+  main_menu->additem(MN_LABEL,_("Level Editor Menu"),0,0);
+  main_menu->additem(MN_HL,"",0,0);
+  main_menu->additem(MN_ACTION,_("Return to Level Editor"),0,0,MN_ID_RETURN);
+  main_menu->additem(MN_GOTO,_("Create Level Subset"),0,create_subset_menu);
+  main_menu->additem(MN_GOTO,_("Load Level Subset"),0,subset_menu);
+  main_menu->additem(MN_HL,"",0,0);
+  main_menu->additem(MN_ACTION,_("Quit Level Editor"),0,0,MN_ID_QUIT);
+
+  settings_menu = new Menu();
+  settings_menu->additem(MN_LABEL,_("Level Settings"),0,0);
+  settings_menu->additem(MN_HL,"",0,0);
+  settings_menu->additem(MN_TEXTFIELD,_("Name    "),0,0,MN_ID_NAME);
+  settings_menu->additem(MN_TEXTFIELD,_("Author  "),0,0,MN_ID_AUTHOR);
+  settings_menu->additem(MN_NUMFIELD, _("Width   "),0,0,MN_ID_WIDTH);
+  settings_menu->additem(MN_NUMFIELD, _("Height  "),0,0,MN_ID_HEIGHT);
+  settings_menu->additem(MN_HL,"",0,0);
+  settings_menu->additem(MN_ACTION,_("Apply"),0,0,MN_ID_APPLY_SETTINGS);
+
+  /* Creating button groups */
+  load_buttons_gfx();
+
+  tiles_board = new ButtonGroup(Vector(screen->w - 140, 100),
+            Vector(32,32), Vector(4,8));
+
+  TileManager* tilemanager = TileManager::instance();
+
+  tiles_board->add_button(Button(img_rubber_bt, _("Eraser"), SDLKey(SDLK_DELETE)), 0);
+  for(unsigned int id = 1; id < tilemanager->get_max_tileid(); id++)
+    {
+    const Tile* tile = tilemanager->get(id);
+    if(!tile)
+      continue;
+
+    Surface* surface;
+    if(tile->editor_images.size())
+      surface = tile->editor_images[0];
+    else if(tile->images.size())
+      surface = tile->images[0];
+    else
+      continue;
 
-  Surface* surface;
-  if(tile->editor_images.size())
-    surface = tile->editor_images[0];
-  else if(tile->images.size())
-    surface = tile->images[0];
-  else
-    continue;
+    Button button = Button(surface, "", SDLKey(0));
+    tiles_board->add_button(button, id);
+    }
 
-  Button button = Button(surface, "", SDLKey(0));
-  tiles_board->add_button(button, id);
-  }
-for(int i = 0; i < NUM_BadGuyKinds; i++)
-  {
-  BadGuyKind kind = BadGuyKind(i);
-  BadGuy badguy(kind, 0,0);
-  badguy.activate(LEFT);
+  #if 0
+  for(int i = 0; i < NUM_BadGuyKinds; i++)
+    {
+    // filter bomb, since it is only for internal use, not for levels
+    if(i == BAD_BOMB)
+      continue;
 
-  Surface *img = badguy.get_image();
-  tiles_board->add_button(Button(img, "", SDLKey(SDLK_1+i)), -(i+1));
-  }
+    BadGuyKind kind = BadGuyKind(i);
+    BadGuy badguy(kind, 0,0);
+    badguy.activate(LEFT);
 
-tiles_board->add_button(Button(img_trampoline[0].get_frame(0), _("Trampoline"), SDLKey(0)), OBJ_TRAMPOLINE);
-tiles_board->add_button(Button(img_flying_platform->get_frame(0), _("Flying Platform"), SDLKey(0)), OBJ_FLYING_PLATFORM);
-tiles_board->add_button(Button(door->get_frame(0), _("Door"), SDLKey(0)), OBJ_DOOR);
-
-tiles_layer = new ButtonGroup(Vector(12, screen->h-64), Vector(80,20), Vector(1,3));
-tiles_layer->add_button(Button(img_foreground_bt, _("Edtit foreground tiles"),
-                       SDLK_F10), LAYER_FOREGROUNDTILES);
-tiles_layer->add_button(Button(img_interactive_bt, _("Edit interactive tiles"),
-                       SDLK_F11), LAYER_TILES, true);
-tiles_layer->add_button(Button(img_background_bt, _("Edit background tiles"),
-                       SDLK_F12), LAYER_BACKGROUNDTILES);
-
-level_options = new ButtonGroup(Vector(screen->w-164, screen->h-36), Vector(32,32), Vector(5,1));
-level_options->add_pair_of_buttons(Button(img_next_sector_bt, _("Next sector"), SDLKey(0)), BT_NEXT_SECTOR,
-               Button(img_previous_sector_bt, _("Prevous sector"), SDLKey(0)), BT_PREVIOUS_SECTOR);
-level_options->add_pair_of_buttons(Button(img_next_level_bt, _("Next level"), SDLKey(0)), BT_NEXT_LEVEL,
-               Button(img_previous_level_bt, _("Prevous level"), SDLKey(0)), BT_PREVIOUS_LEVEL);
-level_options->add_button(Button(img_save_level_bt, _("Save level"), SDLK_F5), BT_LEVEL_SAVE);
-level_options->add_button(Button(img_test_level_bt, _("Test level"), SDLK_F6), BT_LEVEL_TEST);
-level_options->add_button(Button(img_setup_level_bt, _("Setup level"), SDLK_F7), BT_LEVEL_SETUP);
+    Surface *img = badguy.get_image();
+    tiles_board->add_button(Button(img, "", SDLKey(SDLK_1+i)), -(i+1));
+    }
+  #endif
+
+  #if 0
+  tiles_board->add_button(Button(img_trampoline[0].get_frame(0), _("Trampoline"), SDLKey(0)), OBJ_TRAMPOLINE);
+  tiles_board->add_button(Button(img_flying_platform->get_frame(0), _("Flying Platform"), SDLKey(0)), OBJ_FLYING_PLATFORM);
+  #endif
+
+  tiles_layer = new ButtonGroup(Vector(12, screen->h-64), Vector(80,20), Vector(1,3));
+  tiles_layer->add_button(Button(img_foreground_bt, _("Edtit foreground tiles"),
+                         SDLK_F10), LAYER_FOREGROUNDTILES);
+  tiles_layer->add_button(Button(img_interactive_bt, _("Edit interactive tiles"),
+                         SDLK_F11), LAYER_TILES, true);
+  tiles_layer->add_button(Button(img_background_bt, _("Edit background tiles"),
+                         SDLK_F12), LAYER_BACKGROUNDTILES);
+
+  level_options = new ButtonGroup(Vector(screen->w-164, screen->h-36), Vector(32,32), Vector(5,1));
+  level_options->add_pair_of_buttons(Button(img_next_sector_bt, _("Next sector"), SDLKey(0)), BT_NEXT_SECTOR,
+                 Button(img_previous_sector_bt, _("Prevous sector"), SDLKey(0)), BT_PREVIOUS_SECTOR);
+  level_options->add_pair_of_buttons(Button(img_next_level_bt, _("Next level"), SDLKey(0)), BT_NEXT_LEVEL,
+                 Button(img_previous_level_bt, _("Prevous level"), SDLKey(0)), BT_PREVIOUS_LEVEL);
+  level_options->add_button(Button(img_save_level_bt, _("Save level"), SDLK_F5), BT_LEVEL_SAVE);
+  level_options->add_button(Button(img_test_level_bt, _("Test level"), SDLK_F6), BT_LEVEL_TEST);
+  level_options->add_button(Button(img_setup_level_bt, _("Setup level"), SDLK_F7), BT_LEVEL_SETUP);
 }
 
 LevelEditor::~LevelEditor()
@@ -169,6 +174,9 @@ delete subset_menu;
 delete create_subset_menu;
 delete main_menu;
 delete settings_menu;
+
+delete level;
+delete level_subset;
 }
 
 void LevelEditor::load_buttons_gfx()
@@ -224,6 +232,7 @@ else
 
 mouse_cursor->set_state(MC_NORMAL);
 
+frame_timer.start(.25, true);
 done = false;
 while(!done)
   {
@@ -262,17 +271,29 @@ while(SDL_PollEvent(&event))
       }
     else if(menu == create_subset_menu)
       {
+      // activate or deactivate Create button if any filename as been specified
       if(create_subset_menu->get_item_by_id(MN_ID_FILENAME_SUBSET).input[0] == '\0')
         create_subset_menu->get_item_by_id(MN_ID_CREATE_SUBSET).kind = MN_DEACTIVE;
-      else if(create_subset_menu->check() == MN_ID_CREATE_SUBSET)
-        {   // applying settings:
-        LevelSubset::create(create_subset_menu->get_item_by_id(MN_ID_FILENAME_SUBSET).input);
-        level_subset.load(create_subset_menu->get_item_by_id(MN_ID_FILENAME_SUBSET).input);
-
-        level_subset.title = create_subset_menu->item[MN_ID_TITLE_SUBSET].input;
-        level_subset.description = create_subset_menu->item[MN_ID_DESCRIPTION_SUBSET].input;
+      else
+        create_subset_menu->get_item_by_id(MN_ID_CREATE_SUBSET).kind = MN_ACTION;
 
-        load_level(1);
+      if(create_subset_menu->check() == MN_ID_CREATE_SUBSET)
+        {   // applying settings:
+        std::string subset_name = create_subset_menu->get_item_by_id(MN_ID_FILENAME_SUBSET).input;
+        LevelSubset::create(subset_name);
+
+        delete level_subset;
+        level_subset = new LevelSubset();
+        level_subset->load(create_subset_menu->get_item_by_id(MN_ID_FILENAME_SUBSET).input);
+
+        level_subset->title = create_subset_menu->get_item_by_id(MN_ID_TITLE_SUBSET).input;
+        level_subset->description = create_subset_menu->get_item_by_id(MN_ID_DESCRIPTION_SUBSET).input;
+        //FIXME: generate better level filenames
+        level_subset->add_level(subset_name+'/'+"new_level.stl");
+        Level::create(level_subset->get_level_filename(0));
+        level_subset->save();
+        
+        load_level(0);
 
         create_subset_menu->get_item_by_id(MN_ID_FILENAME_SUBSET).change_input("");
         create_subset_menu->get_item_by_id(MN_ID_TITLE_SUBSET).change_input("");
@@ -287,7 +308,6 @@ while(SDL_PollEvent(&event))
         std::set<std::string>::iterator it = level_subsets.begin();
         for(int t = 0; t < i; t++)
           it++;
-std::cerr << "load subset level_subsets " << i << ": " << (*it) << std::endl;
         load_level_subset(*it);
         Menu::set_current(0);
         }
@@ -298,8 +318,8 @@ std::cerr << "load subset level_subsets " << i << ": " << (*it) << std::endl;
         {   // applying settings:
         level_changed = true;
 
-        level.name = settings_menu->get_item_by_id(MN_ID_NAME).input;
-        level.author = settings_menu->get_item_by_id(MN_ID_AUTHOR).input;
+        level->name = settings_menu->get_item_by_id(MN_ID_NAME).input;
+        level->author = settings_menu->get_item_by_id(MN_ID_AUTHOR).input;
 
         solids->resize(atoi(settings_menu->get_item_by_id(MN_ID_WIDTH).input.c_str()),
               atoi(settings_menu->get_item_by_id(MN_ID_HEIGHT).input.c_str()));
@@ -341,33 +361,33 @@ std::cerr << "load subset level_subsets " << i << ": " << (*it) << std::endl;
         Menu::set_current(settings_menu);
         break;
       case BT_NEXT_LEVEL:
-        if(level_nb+1 < level_subset.get_num_levels())
+        if(level_nb + 1 < level_subset->get_num_levels())
           load_level(level_nb + 1);
         else
           {
-          Level new_lev;
           char str[1024];
-          sprintf(str,_("Level %d doesn't exist. Create it?"), level_nb + 1);
+          sprintf(str,_("Level %d doesn't exist. Create it?"), level_nb + 2);
           if(confirm_dialog(NULL, str))
             {
-            level_subset.add_level("new_level.stl");
-            new_lev.save(level_subset.get_level_filename(level_nb + 1));
-            load_level(level_nb);
+            level_subset->add_level("new_level.stl");
+            Level::create(level_subset->get_level_filename(level_nb + 1));
+            level_subset->save();
+            load_level(level_nb + 1);
             }
           }
         break;
       case BT_PREVIOUS_LEVEL:
-        if(level_nb-1 > 0)
+        if(level_nb - 1 >= 0)
           load_level(level_nb - 1);
         break;
       case BT_NEXT_SECTOR:
 std::cerr << "next sector.\n";
-std::cerr << "total sectors: " << level.get_total_sectors() << std::endl;
-        load_sector(level.get_next_sector(sector));
+std::cerr << "total sectors: " << level->get_total_sectors() << std::endl;
+        load_sector(level->get_next_sector(sector));
         break;
       case BT_PREVIOUS_SECTOR:
 std::cerr << "previous sector.\n";
-        load_sector(level.get_previous_sector(sector));
+        load_sector(level->get_previous_sector(sector));
         break;
       }
     level_options->set_unselected();
@@ -514,10 +534,8 @@ if(tiles_board->is_hover() || tiles_layer->is_hover() || level_options->is_hover
 
 if(sector)
   {
-  if(!frame_timer.check())
-    {
-    frame_timer.start(25);
-    ++global_frame_counter;
+    if(frame_timer.check()) {
+      ++global_frame_counter;
     }
 
   // don't scroll before the start or after the level's end
@@ -545,7 +563,7 @@ if(sector)
   }
 }
 
-#define FADING_TIME 600
+#define FADING_TIME .6
 
 void LevelEditor::draw(DrawingContext& context)
 {
@@ -558,14 +576,14 @@ context.draw_filled_rect(Vector(0,0), Vector(screen->w,screen->h), Color(60,60,6
 if(level_name_timer.check())
   {
   context.push_transform();
-  if(level_name_timer.get_left() < FADING_TIME)
-    context.set_alpha(level_name_timer.get_left() * 255 / FADING_TIME);
+  if(level_name_timer.get_timeleft() < FADING_TIME)
+    context.set_alpha(int(level_name_timer.get_timeleft() * 255 / FADING_TIME));
 
-  context.draw_text(gold_text, level.name, Vector(screen->w/2, 30), CENTER_ALLIGN, LAYER_GUI);
+  context.draw_text(gold_text, level->name, Vector(screen->w/2, 30), CENTER_ALLIGN, LAYER_GUI);
   if(level_nb != -1)
     {
     char str[128];
-    sprintf(str, "%i/%i", level_nb+1, level_subset.get_num_levels());
+    sprintf(str, "%i/%i", level_nb+1, level_subset->get_num_levels());
     context.draw_text(gold_text, str, Vector(screen->w/2, 50), CENTER_ALLIGN, LAYER_GUI);
     }
 
@@ -602,17 +620,22 @@ if(sector)
         {
         int id = selection[0][0];
 
+#if 0
         if(id == OBJ_TRAMPOLINE)
           context.draw_surface(img_trampoline[0].get_frame(0), Vector(event.button.x - 8,
           event.button.y - 8), LAYER_GUI-2);
         else if(id == OBJ_FLYING_PLATFORM)
           context.draw_surface(img_flying_platform->get_frame(0), Vector(event.button.x - 8,
           event.button.y - 8), LAYER_GUI-2);
-        else if(id == OBJ_DOOR)
-          context.draw_surface(door->get_frame(0), Vector(event.button.x - 8,
-          event.button.y - 8), LAYER_GUI-2);
+        else
+#endif
+        if(id == OBJ_DOOR)
+          /*context.draw_surface(door->get_frame(0), Vector(event.button.x - 8,
+          event.button.y - 8), LAYER_GUI-2);*/
+          ;
         else
           {
+#if 0
           BadGuyKind kind = BadGuyKind((-id)-1);
           BadGuy badguy(kind, 0,0);
           badguy.activate(LEFT);
@@ -620,16 +643,19 @@ if(sector)
 
           context.draw_surface(img, Vector(event.button.x - 8,
           event.button.y - 8), LAYER_GUI-2);
+#endif
           }
         }
       else
         {
         TileManager* tilemanager = TileManager::instance();
         for(unsigned int x = 0; x < selection.size(); x++)
-          for(unsigned int y = 0; y < selection[x].size(); y++)
-            tilemanager->draw_tile(context, selection[x][y],
+          for(unsigned int y = 0; y < selection[x].size(); y++) {
+            const Tile* tile = tilemanager->get(selection[x][y]);
+            tile->draw(context,
                 Vector(event.button.x + x*32 - 8, event.button.y + y*32 - 8),
                 LAYER_GUI-2);
+          }
         }
       }
     context.set_drawing_effect(NONE_EFFECT);
@@ -673,12 +699,12 @@ if(sector)
       (*i)->draw(context);
 
       context.pop_transform();
+      continue;
       }
     Background* background = dynamic_cast<Background*> (*i);
     if(background)
       {  // don't resize background
       context.push_transform();
-      context.set_translation(scroll);
       context.set_zooming(1.0);
       (*i)->draw(context);
       context.pop_transform();
@@ -697,10 +723,10 @@ context.do_drawing();
 
 void LevelEditor::load_level_subset(std::string filename)
 {
-std::cerr << "loading subset...\n";
-std::cerr << "filename: " << filename << std::endl;
-level_subset.load(filename.c_str());
-load_level(1);
+delete level_subset;
+level_subset = new LevelSubset();
+level_subset->load(filename.c_str());
+load_level(0);
 }
 
 void LevelEditor::load_level(std::string filename)
@@ -714,15 +740,18 @@ if(level_changed)
   }
 
 level_filename = filename;
-level.load(filename);
+
+delete level;
+level = new Level();
+level->load(filename);
 
 load_sector("main");
 level_name_timer.start(3000);
 scroll.x = scroll.y = 0;
 level_changed = false;
 
-settings_menu->get_item_by_id(MN_ID_NAME).change_input(level.name.c_str());
-settings_menu->get_item_by_id(MN_ID_AUTHOR).change_input(level.author.c_str());
+settings_menu->get_item_by_id(MN_ID_NAME).change_input(level->name.c_str());
+settings_menu->get_item_by_id(MN_ID_AUTHOR).change_input(level->author.c_str());
 }
 
 void LevelEditor::load_level(int nb)
@@ -736,9 +765,7 @@ if(level_changed)
   }
 
 level_nb = nb;
-std::cerr << "level_nb: " << level_nb << std::endl;
-std::cerr << "level_subset.get_level_filename(level_nb): " << level_subset.get_level_filename(level_nb) << std::endl;
-level_filename = level_subset.get_level_filename(level_nb);
+level_filename = level_subset->get_level_filename(level_nb);
 
 load_level(level_filename);
 }
@@ -746,7 +773,7 @@ load_level(level_filename);
 void LevelEditor::load_sector(std::string name)
 {
 sector_name = name;
-sector = level.get_sector(sector_name);
+sector = level->get_sector(sector_name);
 if(!sector)
   Termination::abort("Level has no " + sector_name + " sector.", "");
 
@@ -755,15 +782,12 @@ load_sector(sector);
 
 void LevelEditor::load_sector(Sector* sector_)
 {
-if(sector == NULL)
+if(sector_ == NULL)
   {
-  if(confirm_dialog(NULL, _("No more sectors exist. Create another?")))
-    {
-    Sector* nsector = new Sector();
-    level.add_sector(nsector);
-    sector = nsector;
-    }
-  return;
+  if(!confirm_dialog(NULL, _("No more sectors exist. Create another?")))
+    return;
+  sector_ = Sector::create("new_sector",25,19);
+  level->add_sector(sector_);
   }
 
 sector = sector_;
@@ -776,9 +800,11 @@ foregrounds = solids = backgrounds = 0;
 /* Point foregrounds, backgrounds, solids to its layer */
 for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); i++)
   {
+#if 0
   BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
   if(badguy)
     badguy->activate(LEFT);
+#endif
 
   TileMap* tilemap = dynamic_cast<TileMap*> (*i);
   if(tilemap)
@@ -814,89 +840,94 @@ settings_menu->get_item_by_id(MN_ID_HEIGHT).change_input(str);
 
 void LevelEditor::save_level()
 {
-std::cerr << "saving level...\n";
-level.save(level_filename);
+level->save(level_filename);
 level_changed = false;
 }
 
 void LevelEditor::test_level()
 {
-if(level_changed)
-  {
-  if(confirm_dialog(NULL, _("Level not saved. Wanna to?")))
-    save_level();
-  else
-    return;
+  if(level_changed) {
+    if(confirm_dialog(NULL, _("Level not saved. Wanna to?")))
+      save_level();
+    else
+      return;
   }
 
-GameSession session(level_filename, ST_GL_TEST);
-session.run();
-//  player_status.reset();
-sound_manager->halt_music();
+  GameSession session(level_filename, ST_GL_TEST);
+  session.run();
+  //  player_status.reset();
+  SoundManager::get()->halt_music();
 }
 
 void LevelEditor::change(int x, int y, int newtile, int layer)
-{  // find the tilemap of the current layer, and then change the tile
-if(x < 0 || (unsigned int)x > sector->solids->get_width()*32 ||
-   y < 0 || (unsigned int)y > sector->solids->get_height()*32)
-  return;
-
-level_changed = true;
+{  
+  // find the tilemap of the current layer, and then change the tile
+  if(x < 0 || (unsigned int)x >= sector->solids->get_width()*32 ||
+      y < 0 || (unsigned int)y >= sector->solids->get_height()*32)
+    return;
 
-if(zoom != 1)
+  level_changed = true;
+  
+  if(zoom != 1)
   {  // no need to do this for normal view (no zoom)
-  x = (int)(x * (zoom*32) / 32);
-  y = (int)(y * (zoom*32) / 32);
+    x = (int)(x * (zoom*32) / 32);
+    y = (int)(y * (zoom*32) / 32);
   }
 
-if(newtile < 0)  // add object
+  if(newtile < 0)  // add object
   {
-  // remove an active tile or object that might be there
-  change(x, y, 0, LAYER_TILES);
-
-  if(newtile == OBJ_TRAMPOLINE)
-    sector->add_object(new Trampoline(x, y));
-  else if(newtile == OBJ_FLYING_PLATFORM)
-    sector->add_object(new FlyingPlatform(x, y));
-  else if(newtile == OBJ_DOOR)
-    sector->add_object(new Door(x, y));
-  else
-    sector->add_object(new BadGuy(BadGuyKind((-newtile)-1), x, y));
-
-  sector->update_game_objects();
-  }
-else if(cur_layer == LAYER_FOREGROUNDTILES)
-  foregrounds->change(x/32, y/32, newtile);
-else if(cur_layer == LAYER_TILES)
-  {
-  // remove a bad guy if it's there
-  // we /32 in order to round numbers
-  for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i < sector->gameobjects.end(); i++)
-    {
-    BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
-    if(badguy)
-      if((int)badguy->base.x/32 == x/32 && (int)badguy->base.y/32 == y/32)
-        sector->gameobjects.erase(i);
-    Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
-    if(trampoline)
-    {
-      if((int)trampoline->base.x/32 == x/32 && (int)trampoline->base.y/32 == y/32)
-        sector->gameobjects.erase(i);
-        }
-    FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
-    if(flying_platform)
-      if((int)flying_platform->base.x/32 == x/32 && (int)flying_platform->base.y/32 == y/32)
-        sector->gameobjects.erase(i);
-    Door* door = dynamic_cast<Door*> (*i);
-    if(door)
-      if((int)door->get_area().x/32 == x/32 && (int)door->get_area().y/32 == y/32)
-        sector->gameobjects.erase(i);
+    // remove an active tile or object that might be there
+    change(x, y, 0, LAYER_TILES);
+
+#if 0
+    if(newtile == OBJ_TRAMPOLINE)
+      sector->add_object(new Trampoline(x, y));
+    else if(newtile == OBJ_FLYING_PLATFORM)
+      sector->add_object(new FlyingPlatform(x, y));
+    else
+      if(newtile == OBJ_DOOR)
+        sector->add_object(new Door(x, y));
+      else
+        sector->add_bad_guy(x, y, BadGuyKind((-newtile)-1), true);
+#endif
+
+    sector->update_game_objects();
+  } else if(cur_layer == LAYER_FOREGROUNDTILES) {
+    foregrounds->change(x/32, y/32, newtile);
+  } else if(cur_layer == LAYER_TILES) {
+    // remove a bad guy if it's there
+    // we /32 in order to round numbers
+    for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
+        i < sector->gameobjects.end(); i++) {
+#if 0
+      BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
+      if(badguy)
+        if((int)badguy->base.x/32 == x/32 && (int)badguy->base.y/32 == y/32)
+          sector->gameobjects.erase(i);
+#endif
+#if 0
+      Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
+      if(trampoline)
+      {
+        if((int)trampoline->base.x/32 == x/32 && (int)trampoline->base.y/32 == y/32)
+          sector->gameobjects.erase(i);
+      }
+      FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
+      if(flying_platform)
+        if((int)flying_platform->base.x/32 == x/32 && (int)flying_platform->base.y/32 == y/32)
+          sector->gameobjects.erase(i);
+#endif
+#if 0
+      Door* door = dynamic_cast<Door*> (*i);
+      if(door)
+        if((int)door->get_area().x/32 == x/32 && (int)door->get_area().y/32 == y/32)
+          sector->gameobjects.erase(i);
+#endif
     }
-  sector->update_game_objects();
-  solids->change(x/32, y/32, newtile);
-  }
-else if(cur_layer == LAYER_BACKGROUNDTILES)
-  backgrounds->change(x/32, y/32, newtile);
+    sector->update_game_objects();
+    solids->change(x/32, y/32, newtile);
+  } else if(cur_layer == LAYER_BACKGROUNDTILES)
+    backgrounds->change(x/32, y/32, newtile);
 }
 
 void LevelEditor::show_help()
@@ -910,8 +941,8 @@ mouse_cursor->set_state(MC_HIDE);
 
 char str[1024];
 char *text1[] = {
-         _("This is the built-in level editor. It's aim is to be intuitive\n"
-         "and simple to use, so it should be pretty straight forward.\n"
+         _("This is the built-in level editor. Its aim is to be intuitive\n"
+         "and simple to use, so it should be pretty straightforward.\n"
          "\n"
          "To open a level, first you'll have to select a level subset from\n"
          "the menu (or create your own).\n"
@@ -920,24 +951,24 @@ char *text1[] = {
          "\n"
          "To access the menu from the level editor, just press Esc.\n"
          "\n"
-         "You are currently looking to the level, to scroll it, just\n"
+         "You are currently looking at the level. To scroll it, just\n"
          "press the right mouse button and drag the mouse. It will move like\n"
          "a strategy game.\n"
          "You can also use the arrow keys and Page Up/Down.\n"
          "\n"
-         "'+' and '-' keys can be used to zoom in/out the level.\n"
+         "'+' and '-' keys can be used to zoom the level in/out.\n"
          "\n"
-         "You probably already noticed those floating group of buttons.\n"
+         "You probably already noticed those floating groups of buttons.\n"
          "Each one serves a different purpose. To select a certain button\n"
          "just press the Left mouse button on it. A few buttons have key\n"
-         "shortcuts, you can know it by pressing the Right mouse button on\n"
-         "it. That will also show what that button does.\n"
-         "Group of buttons can also be move around by just dragging them,\n"
+         "shortcuts. You can find them by pressing the Right mouse button on\n"
+         "a button. That will also show what that button does.\n"
+         "Groups of buttons can also be moved around by just dragging them,\n"
          "while pressing the Left mouse button.\n"
          "\n"
-         "Let's learn a bit of what each group of buttons do, shall we?\n"
+         "Let's learn a bit of what each group of buttons does, shall we?\n"
          "\n"
-         "To starting putting tiles and objects around use the bigger gropup\n"
+         "To starting putting tiles and objects around use the bigger group\n"
          "of buttons. Each button is a different tile. To put it on the level,\n"
          "just press it and then left click in the level.\n"
          "You can also copy tiles from the level by using the middle mouse button.\n"
@@ -947,15 +978,15 @@ char *text1[] = {
 
 char *text2[] = {
          _("The Foreground/Interactive/Background buttons may be used to\n"
-         "see and edit the respective layer. Level's have three tiles layers:\n"
-         "Foreground - tiles are drawn in top of everything and have no contact\n"
+         "see and edit the respective layer. Levels have three tiles layers:\n"
+         "Foreground - tiles are drawn on top of everything and have no contact\n"
          "with the player.\n"
          "Interactive - these are the tiles that have contact with the player.\n"
-         "Background - tiles are drawn in bottom of everything and have no contact\n"
+         "Background - tiles are drawn underneath everything and have no contact\n"
          "with the player.\n"
          "The unselected layers will be drawn semi-transparently.\n"
          "\n"
-         "At last, but not least, the group of buttons that's left serves\n"
+         "Last, but not least, the group of buttons that's left serves\n"
          "to do related actions with the level.\n"
          "From left to right:\n"
          "Mini arrows - can be used to choose other sectors.\n"
@@ -963,7 +994,7 @@ char *text2[] = {
          "Big arrows - choose other level in the same level subset.\n"
          "Diskette - save the level\n"
          "Tux - test the level\n"
-         "Tools - set a few settings for the level, incluiding resizing it.\n"
+         "Tools - set a few settings for the level, including resizing it.\n"
          "\n"
          "We have reached the end of this Howto.\n"
          "\n"
@@ -972,8 +1003,8 @@ char *text2[] = {
          "Enjoy,\n"
          "  SuperTux development team\n"
          "\n"
-         "ps: If you are looking for something more powerfull, you can give it a\n"
-         "try to FlexLay. FlexLay is a level editor that supports several games,\n"
+         "PS: If you are looking for something more powerful, you might like to\n"
+         "try FlexLay. FlexLay is a level editor that supports several games,\n"
          "including SuperTux. It is an independent project.\n"
          "Webpage: http://pingus.seul.org/~grumbel/flexlay/")
                 };