Finally!!
[supertux.git] / src / leveleditor.cpp
index 1db3721..3173e9a 100644 (file)
@@ -24,7 +24,6 @@
 #include <SDL_image.h>
 #include "leveleditor.h"
 
-#include "world.h"
 #include "screen.h"
 #include "defines.h"
 #include "globals.h"
@@ -41,7 +40,6 @@
 /* definitions to aid development */
 #define DONE_LEVELEDITOR 1
 #define DONE_QUIT        2
-#define DONE_CHANGELEVEL 3
 
 /* definitions that affect gameplay */
 #define KEY_CURSOR_SPEED 32
@@ -79,13 +77,41 @@ void apply_level_settings_menu();
 void update_subset_settings_menu();
 void save_subset_settings_menu();
 
+static Level* le_current_level;
+
+struct LevelEditorWorld
+{
+  std::vector<BadGuy> bad_guys;
+  void arrays_free(void)
+  {
+    bad_guys.clear();
+  }
+
+  void add_bad_guy(float x, float y, BadGuyKind kind)
+  {
+    bad_guys.push_back(BadGuy());
+    BadGuy& new_bad_guy = bad_guys.back();
+  
+    new_bad_guy.init(x,y,kind);
+  }
+
+  void activate_bad_guys()
+  {
+    for (std::vector<BadGuyData>::iterator i = le_current_level->badguy_data.begin();
+         i != le_current_level->badguy_data.end();
+         ++i)
+      {
+        add_bad_guy(i->x, i->y, i->kind);
+      }
+  }
+};
+
 /* leveleditor internals */
 static string_list_type level_subsets;
 static bool le_level_changed;  /* if changes, ask for saving, when quiting*/
 static int pos_x, cursor_x, cursor_y, fire;
 static int le_level;
-static Level* le_current_level;
-static World le_world;
+static LevelEditorWorld le_world;
 static st_subset le_level_subset;
 static int le_show_grid;
 static int le_frame;
@@ -313,12 +339,6 @@ int leveleditor(int levelnb)
           return 0;
         }
 
-      if(done == DONE_QUIT)
-        {
-          le_quit();
-          return 1;
-        }
-
       ++global_frame_counter;
        
       SDL_Delay(25);
@@ -671,16 +691,16 @@ void le_drawinterface()
       le_tilemap_panel->draw();
 
       sprintf(str, "%d/%d", le_level,le_level_subset.levels);
-      text_drawf(&white_text, str, -10, 16, A_RIGHT, A_TOP, 0);
+      white_text->drawf(str, -10, 16, A_RIGHT, A_TOP, 0);
 
-      text_draw(&white_small_text, "F1 for Help", 10, 430, 1);
+      white_small_text->draw("F1 for Help", 10, 430, 1);
     }
   else
     {
       if(show_menu == false)
-        text_draw(&white_small_text, "No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1);
+        white_small_text->draw("No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1);
       else
-        text_draw(&white_small_text, "No Level Subset loaded", 10, 430, 1);
+        white_small_text->draw("No Level Subset loaded", 10, 430, 1);
     }
 
 }
@@ -764,9 +784,8 @@ void le_checkevents()
 
   while(SDL_PollEvent(&event))
     {
-      if(show_menu)
-        current_menu->event(event);
-      else
+      current_menu->event(event);
+      if(!show_menu)
         mouse_cursor->set_state(MC_NORMAL);
 
       /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
@@ -777,23 +796,8 @@ void le_checkevents()
             {
             case SDL_KEYDOWN:  // key pressed
               key = event.key.keysym.sym;
-              if(show_menu)
-                {
-                  if(key == SDLK_ESCAPE)
-                    {
-                      show_menu = false;
-                      Menu::set_current(leveleditor_menu);
-                    }
-                  break;
-                }
               switch(key)
                 {
-                case SDLK_ESCAPE:
-                  if(!show_menu)
-                    show_menu = true;
-                  else
-                    show_menu = false;
-                  break;
                 case SDLK_LEFT:
                   if(fire == DOWN)
                     cursor_x -= KEY_CURSOR_SPEED;
@@ -949,9 +953,9 @@ void le_checkevents()
                           char str[1024];
                           int d = 0;
                           sprintf(str,"Level %d doesn't exist.",le_level+1);
-                          text_drawf(&white_text,str,0,-18,A_HMIDDLE,A_VMIDDLE,2);
-                          text_drawf(&white_text,"Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2);
-                          text_drawf(&red_text,"(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2);
+                          white_text->drawf(str,0,-18,A_HMIDDLE,A_VMIDDLE,2);
+                          white_text->drawf("Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2);
+                          red_text->drawf("(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2);
                           flipscreen();
                           while(d == 0)
                             {
@@ -1246,12 +1250,12 @@ void le_showhelp()
                  };
 
 
-  text_drawf(&blue_text, "- Help -", 0, 30, A_HMIDDLE, A_TOP, 2);
+  blue_text->drawf("- Help -", 0, 30, A_HMIDDLE, A_TOP, 2);
 
   for(i = 0; i < sizeof(text)/sizeof(char *); i++)
-    text_draw(&white_text, text[i], 5, 80+(i*18), 1);
+    white_text->draw(text[i], 5, 80+(i*18), 1);
 
-  text_drawf(&gold_text, "Press Any Key to Continue", 0, 440, A_HMIDDLE, A_TOP, 1);
+  gold_text->drawf("Press Any Key to Continue", 0, 440, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();