- updated TODO
[supertux.git] / src / leveleditor.cpp
index 543bbc3..cb8f714 100644 (file)
@@ -19,6 +19,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <map>
+#include <typeinfo>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -30,7 +31,7 @@
 #include <algorithm>
 #include "leveleditor.h"
 
-#include "screen.h"
+#include "screen/screen.h"
 #include "defines.h"
 #include "globals.h"
 #include "setup.h"
 #include "button.h"
 #include "tile.h"
 #include "resources.h"
-#include "music_manager.h"
 #include "background.h"
-#include "display_manager.h"
+
+// TODO
+#if 0
 
 /* definitions to aid development */
 
@@ -471,29 +473,18 @@ void le_init_menus()
       for(std::vector<int>::const_iterator sit = (*it).tiles.begin();
           sit != (*it).tiles.end(); ++sit, ++i)
       {
-        std::string imagefile = "/images/tilesets/" ;
-        bool only_editor_image = false;
-        if(!TileManager::instance()->get(*sit)->filenames.empty())
-        {
-          imagefile += TileManager::instance()->get(*sit)->filenames[0];
-        }
-        else if(!TileManager::instance()->get(*sit)->editor_filenames.empty())
-        {
-          imagefile += TileManager::instance()->get(*sit)->editor_filenames[0];
-          only_editor_image = true;
-        }
+        Tile& tile = *(TileManager::instance()->get(*sit));
+        Surface* image;
+        if(tile.editor_images.size() > 0)
+          image = tile.editor_images[0];
+        else if(tile.images.size() > 0)
+          image = tile.images[0];
         else
-        {
-          imagefile += "notile.png";
-        }
-        Button* button = new Button(imagefile, it->name, SDLKey(SDLK_a + i),
+          // TODO use some notile image...
+          image = 0;
+
+        Button* button = new Button(image, it->name, SDLKey(SDLK_a + i),
                                     0, 0, 32, 32);
-        if(!only_editor_image)
-          if(!TileManager::instance()->get(*sit)->editor_filenames.empty())
-          {
-            imagefile = "/images/tilesets/" + TileManager::instance()->get(*sit)->editor_filenames[0];
-            button->add_icon(imagefile,32,32);
-          }
         tilegroups_map[it->name]->additem(button, *sit);
       }
     }
@@ -510,7 +501,7 @@ void le_init_menus()
   for(int i = 0; i < NUM_BadGuyKinds; ++i)
   {
     BadGuy bad_tmp(dummy, BadGuyKind(i), 0, 0);
-    objects_map["BadGuys"]->additem(new Button("", "BadGuy",(SDLKey)(i+'a'),0,0,32,32),1000000+i);
+    objects_map["BadGuys"]->additem(new Button(0, "BadGuy",(SDLKey)(i+'a'),0,0,32,32),1000000+i);
     objects_map["BadGuys"]->manipulate_button(i)->set_drawable(new
         BadGuy(dummy,
           BadGuyKind(i),
@@ -784,9 +775,9 @@ void le_drawminimap()
   int left_offset = (screen->w - 64 - le_world->get_level()->width*mini_tile_width) / 2;
 
   int mini_tile_height;
-  if(screen->h - 64 > le_world->get_level()->height * 4)
+  if(screen->h > le_world->get_level()->height * 4)
     mini_tile_height = 4;
-  else if(screen->h - 64 > le_world->get_level()->height * 2)
+  else if(screen->h > le_world->get_level()->height * 2)
     mini_tile_height = 2;
   else
     mini_tile_height = 1;
@@ -796,24 +787,33 @@ void le_drawminimap()
     for (int x = 0; x < le_world->get_level()->width; ++x)
     {
 
-      Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4,
-          mini_tile_width , 4, level->bg_tiles[y * level->width + x]);
+      Tile::draw_stretched(left_offset + mini_tile_width*x, y * mini_tile_height,
+          mini_tile_width , mini_tile_height, level->bg_tiles[y * level->width + x]);
 
-      Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4,
-          mini_tile_width , 4, level->ia_tiles[y * level->width + x]);
+      Tile::draw_stretched(left_offset + mini_tile_width*x, y * mini_tile_height,
+          mini_tile_width , mini_tile_height, level->ia_tiles[y * level->width + x]);
 
-      Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4,
-          mini_tile_width , 4, level->fg_tiles[y + level->width + x]);
+      Tile::draw_stretched(left_offset + mini_tile_width*x, y * mini_tile_height,
+          mini_tile_width , mini_tile_height, level->fg_tiles[y + level->width + x]);
 
     }
 
-  fillrect(left_offset, 0, le_world->get_level()->width*mini_tile_width, le_world->get_level()->height*mini_tile_height, 200, 200, 200, 128);
-
-  fillrect(left_offset + (pos_x/32)*mini_tile_width, 0, 19*mini_tile_width, 2, 200, 200, 200, 200);
-  fillrect(left_offset + (pos_x/32)*mini_tile_width, 0, 2, le_world->get_level()->height*mini_tile_height, 200, 200, 200, 200);
-  fillrect(left_offset + (pos_x/32)*mini_tile_width + 19*mini_tile_width - 2, 0, 2, le_world->get_level()->height*mini_tile_height, 200, 200, 200, 200);
-  fillrect(left_offset + (pos_x/32)*mini_tile_width, le_world->get_level()->height*mini_tile_height-2, 19*mini_tile_width, 2, 200, 200, 200, 200);
-
+  fillrect(left_offset, 0,
+             le_world->get_level()->width*mini_tile_width, le_world->get_level()->height*mini_tile_height,
+             200, 200, 200, 96);
+
+  fillrect(left_offset + (pos_x/32)*mini_tile_width, (pos_y/32)*mini_tile_height,
+             (VISIBLE_TILES_X-3)*mini_tile_width, 2,
+             200, 200, 200, 200);
+  fillrect(left_offset + (pos_x/32)*mini_tile_width, (pos_y/32)*mini_tile_height,
+             2, (VISIBLE_TILES_Y-1)*mini_tile_height,
+             200, 200, 200, 200);
+  fillrect(left_offset + (pos_x/32)*mini_tile_width + (VISIBLE_TILES_X-3)*mini_tile_width - 2, (pos_y/32)*mini_tile_height,
+             2, (VISIBLE_TILES_Y-1)*mini_tile_height,
+             200, 200, 200, 200);
+  fillrect(left_offset + (pos_x/32)*mini_tile_width, (pos_y/32)*mini_tile_height + (VISIBLE_TILES_Y-1)*mini_tile_height - 2,
+             (VISIBLE_TILES_X-3)*mini_tile_width, 2,
+             200, 200, 200, 200);
 }
 
 void le_drawinterface()
@@ -942,8 +942,7 @@ void le_drawlevel()
   Uint8 a;
 
   /* Draw the real background */
-  le_world->background->draw(le_world->displaymanager.get_viewport(),
-      LAYER_BACKGROUND0);
+  le_world->background->draw(*le_world->camera, LAYER_BACKGROUND0);
 
   if(le_current.IsTile())
   {
@@ -1012,7 +1011,7 @@ void le_drawlevel()
       continue;
     
     /* to support frames: img_bsod_left[(frame / 5) % 4] */
-    ViewPort viewport;
+    Camera viewport;
     viewport.set_translation(Vector(pos_x, pos_y));
     badguy->draw(viewport, 0);
   }
@@ -1024,11 +1023,13 @@ void le_drawlevel()
 
 void le_change_object_properties(GameObject *pobj)
 {
-  Surface* cap_screen = Surface::CaptureScreen();
+  //Surface* cap_screen = Surface::CaptureScreen();
+    
   Menu* object_properties_menu = new Menu();
   bool loop = true;
 
-  object_properties_menu->additem(MN_LABEL,pobj->type() + " Properties",0,0);
+  std::string type = typeid(pobj).name();
+  object_properties_menu->additem(MN_LABEL, type + " Properties",0,0);
   object_properties_menu->additem(MN_HL,"",0,0);
 
   BadGuy* pbad = dynamic_cast<BadGuy*>(pobj);
@@ -1059,7 +1060,7 @@ void le_change_object_properties(GameObject *pobj)
       object_properties_menu->event(event);
     }
 
-    cap_screen->draw(0,0);
+    //cap_screen->draw(0,0);
 
     object_properties_menu->draw();
     object_properties_menu->action();
@@ -1089,7 +1090,7 @@ void le_change_object_properties(GameObject *pobj)
     SDL_Delay(25);
   }
 
-  delete cap_screen;
+  //delete cap_screen;
   Menu::set_current(0);
   delete object_properties_menu;
 }
@@ -1510,15 +1511,17 @@ void le_checkevents()
             if(le_current.IsObject())
             {
               le_level_changed  = true;
-              std::string type = le_current.obj->type();
+              BadGuy* pbadguy = dynamic_cast<BadGuy*>(le_current.obj);
 
-              if(type == "BadGuy")
+              if(pbadguy)
               {
-                ViewPort viewport(le_world->displaymanager.get_viewport());
+                Camera& camera = *le_world->camera;
                 DisplayManager dummy;
-                BadGuy* pbadguy = dynamic_cast<BadGuy*>(le_current.obj);
 
-                le_world->bad_guys.push_back(new BadGuy(dummy, pbadguy->kind, cursor_x + viewport.get_translation().x, cursor_y + viewport.get_translation().y));
+                le_world->bad_guys.push_back(
+                    new BadGuy(dummy, pbadguy->kind,
+                      cursor_x + camera.get_translation().x,
+                      cursor_y + camera.get_translation().y));
                 le_world->gameobjects.push_back(le_world->bad_guys.back());
               }
             }
@@ -1535,6 +1538,9 @@ void le_checkevents()
   {
     show_minimap = false;
 
+    if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_TAB)
+      show_minimap = true;
+
     le_move_left_bt->event(event);
     le_move_right_bt->event(event);
     le_move_up_bt->event(event);
@@ -1607,19 +1613,17 @@ void le_checkevents()
       break;
     }
 
-      /* checking if pos_x and pos_y is within the limits... */
-      if(pos_x > (le_world->get_level()->width * 32 + 32*2) - screen->w)
-        pos_x = (le_world->get_level()->width * 32 + 32*2) - screen->w;
-      if(pos_x < 0)
-        pos_x = 0;
-
-      if(pos_y > (le_world->get_level()->height * 32) - screen->h)
-        pos_y = (le_world->get_level()->height * 32) - screen->h;
-      if(pos_y < 0)
-        pos_y = 0;
+    /* checking if pos_x and pos_y is within the limits... */
+    if(pos_x > (le_world->get_level()->width * 32 + 32*2) - screen->w)
+      pos_x = (le_world->get_level()->width * 32 + 32*2) - screen->w;
+    if(pos_x < 0)
+      pos_x = 0;
 
+    if(pos_y > (le_world->get_level()->height * 32) - screen->h)
+      pos_y = (le_world->get_level()->height * 32) - screen->h;
+    if(pos_y < 0)
+      pos_y = 0;
   }
-
 }
 
 void le_highlight_selection()
@@ -1678,11 +1682,11 @@ void le_change(float x, float y, int tm, unsigned int c)
       /* if there is a bad guy over there, remove it */
       // XXX TODO
       for(std::vector<GameObject*>::iterator it = le_world->gameobjects.begin();
-            it != le_world->gameobjects.end(); ++it)
-        if ((*it)->type() == "BadGuy")
+            it != le_world->gameobjects.end(); ++it) {
+        BadGuy* badguy = dynamic_cast<BadGuy*>((*it));
+        if (badguy)
         {
-          BadGuy* pbadguy = dynamic_cast<BadGuy*>((*it));
-          if(rectcollision(cursor_base, pbadguy->base))
+          if(rectcollision(cursor_base, badguy->base))
           {
             delete (*it);
             //le_world->bad_guys.erase(it);
@@ -1690,6 +1694,7 @@ void le_change(float x, float y, int tm, unsigned int c)
             break;
           }
         }
+      }
 
       break;
     case SQUARE:
@@ -1724,9 +1729,9 @@ void le_change(float x, float y, int tm, unsigned int c)
       for(std::vector<GameObject*>::iterator it = le_world->gameobjects.begin();
           it != le_world->gameobjects.end(); ++it /* will be at end of loop */)
       {
-        if ((*it)->type() == "BadGuy")
+        MovingObject* pmobject = dynamic_cast<MovingObject*> (*it);       
+        if (pmobject)
         {
-          MovingObject* pmobject = dynamic_cast<MovingObject*> (*it);
           if(pmobject->base.x/32 >= x1 && pmobject->base.x/32 <= x2
               && pmobject->base.y/32 >= y1 && pmobject->base.y/32 <= y2)
           {
@@ -1921,3 +1926,5 @@ void le_showhelp()
   le_selection_mode = temp_le_selection_mode;
   le_help_shown = false;
 }
+
+#endif