LevelEditor bug-fixes, improvements and fine-tuning.
authorTobias Gläßer <tobi.web@gmx.de>
Tue, 4 May 2004 22:16:11 +0000 (22:16 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Tue, 4 May 2004 22:16:11 +0000 (22:16 +0000)
SVN-Revision: 984

src/button.cpp
src/button.h
src/leveleditor.cpp
src/menu.h

index b34b24c..d83ad5e 100644 (file)
@@ -31,26 +31,7 @@ Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x
 {
   popup_timer.init(false);
 
-  char filename[1024];
-
-  if(!icon_file.empty())
-  {
-    snprintf(filename, 1024, "%s/%s", datadir.c_str(), icon_file.c_str());
-    if(!faccessible(filename))
-      snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str());
-  }
-  else
-  {
-    snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str());
-  }
-
-  if(mw != -1 || mh != -1)
-  {
-    icon = new Surface(filename,USE_ALPHA);
-    icon->resize(mw,mh);
-  }
-  else
-    icon = new Surface(filename,USE_ALPHA);
+  add_icon(icon_file,mw,mh);
 
   info = ninfo;
 
@@ -58,16 +39,15 @@ Button::Button(std::string icon_file, std::string ninfo, SDLKey nshortcut, int x
 
   rect.x = x;
   rect.y = y;
-  rect.w = icon->w;
-  rect.h = icon->h;
+  rect.w = icon[0]->w;
+  rect.h = icon[0]->h;
   tag = -1;
   state = BUTTON_NONE;
   show_info = false;
-  bkgd = NULL;
   game_object = NULL;
 }
 
-void Button::change_icon(std::string icon_file, int /*mw*/, int /*mh*/)
+void Button::add_icon(std::string icon_file, int mw, int mh)
 {
   char filename[1024];
 
@@ -82,8 +62,14 @@ void Button::change_icon(std::string icon_file, int /*mw*/, int /*mh*/)
     snprintf(filename, 1024, "%s/images/icons/default-icon.png", datadir.c_str());
   }
 
-  delete icon;
-  icon = new Surface(filename,USE_ALPHA);
+  if(mw != -1 || mh != -1)
+  {
+    icon.push_back(new Surface(filename,USE_ALPHA));
+    icon.back()->resize(mw,mh);
+  }
+  else
+    icon.push_back(new Surface(filename,USE_ALPHA));
+    
 }
 
 void Button::draw()
@@ -94,11 +80,10 @@ void Button::draw()
 
   fillrect(rect.x,rect.y,rect.w,rect.h,75,75,75,200);
   fillrect(rect.x+1,rect.y+1,rect.w-2,rect.h-2,175,175,175,200);
-  if(bkgd != NULL)
-  {
-    bkgd->draw(rect.x,rect.y);
-  }
-  icon->draw(rect.x,rect.y);
+
+  for(std::vector<Surface*>::iterator it = icon.begin(); it != icon.end(); ++it)
+  (*it)->draw(rect.x,rect.y);
+  
   if(game_object != NULL)
   {
     game_object->draw_on_screen();
@@ -125,7 +110,9 @@ void Button::draw()
 
 Button::~Button()
 {
-  delete icon;
+  for(std::vector<Surface*>::iterator it = icon.begin(); it != icon.end(); ++it)
+  delete (*it);
+  icon.clear();
   delete game_object;
 }
 
index 552fd22..213fe71 100644 (file)
@@ -43,7 +43,7 @@ public:
   void event(SDL_Event& event);
   void draw();
   int get_state();
-  void change_icon(std::string icon_file, int mw, int mh);
+  void add_icon(std::string icon_file, int mw, int mh);
   SDL_Rect get_pos() { return rect; }
   int get_tag(){return tag; }
   void set_game_object(GameObject* game_object_) { game_object = game_object_; }
@@ -52,8 +52,7 @@ public:
 private:
   static Timer popup_timer;
   GameObject* game_object;
-  Surface* icon;
-  Surface* bkgd;
+  std::vector<Surface*> icon;
   std::string info;
   SDLKey shortcut;
   SDL_Rect rect;
index 8199a53..49eb83b 100644 (file)
@@ -117,6 +117,7 @@ struct TileOrObject
   bool IsTile() { return is_tile; };
   //Returns true for a GameObject
   bool IsObject() { return !is_tile; };
+  void Init() { tile = 0; obj = NULL; is_tile = true; };
 
   bool is_tile; //true for tile (false for object)
   unsigned int tile;
@@ -375,14 +376,14 @@ int leveleditor(int levelnb)
       }
       else if(menu == subset_settings_menu)
       {
-        if(le_level_subset->title.compare(subset_settings_menu->get_item_by_id(MNID_TITLE).input) == 0 && le_level_subset->description.compare(subset_settings_menu->get_item_by_id(MNID_DESCRIPTION).input) == 0  )
-          subset_settings_menu->get_item_by_id(MNID_SAVE_CHANGES).kind = MN_DEACTIVE;
+        if(le_level_subset->title.compare(subset_settings_menu->get_item_by_id(MNID_SUBSETTITLE).input) == 0 && le_level_subset->description.compare(subset_settings_menu->get_item_by_id(MNID_SUBSETDESCRIPTION).input) == 0  )
+          subset_settings_menu->get_item_by_id(MNID_SUBSETSAVECHANGES).kind = MN_DEACTIVE;
         else
-          subset_settings_menu->get_item_by_id(MNID_SAVE_CHANGES).kind = MN_ACTION;
+          subset_settings_menu->get_item_by_id(MNID_SUBSETSAVECHANGES).kind = MN_ACTION;
 
         switch (i = subset_settings_menu->check())
         {
-        case MNID_SAVE_CHANGES:
+        case MNID_SUBSETSAVECHANGES:
           save_subset_settings_menu();
           //FIXME:show_menu = true;
           Menu::set_current(leveleditor_menu);
@@ -455,10 +456,10 @@ void le_init_menus()
 
   subset_settings_menu->additem(MN_LABEL,"Level Subset Settings",0,0);
   subset_settings_menu->additem(MN_HL,"",0,0);
-  subset_settings_menu->additem(MN_TEXTFIELD,"Title",0,0);
-  subset_settings_menu->additem(MN_TEXTFIELD,"Description",0,0);
+  subset_settings_menu->additem(MN_TEXTFIELD,"Title",0,0,MNID_SUBSETTITLE);
+  subset_settings_menu->additem(MN_TEXTFIELD,"Description",0,0,MNID_SUBSETDESCRIPTION);
   subset_settings_menu->additem(MN_HL,"",0,0);
-  subset_settings_menu->additem(MN_ACTION,"Save Changes",0,0);
+  subset_settings_menu->additem(MN_ACTION,"Save Changes",0,0,MNID_SUBSETSAVECHANGES);
   subset_settings_menu->additem(MN_HL,"",0,0);
   subset_settings_menu->additem(MN_BACK,"Back",0,0);
 
@@ -500,6 +501,7 @@ void le_init_menus()
         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];
@@ -507,6 +509,7 @@ void le_init_menus()
       else if(!TileManager::instance()->get(*sit)->editor_filenames.empty())
       {
         imagefile += TileManager::instance()->get(*sit)->editor_filenames[0];
+       only_editor_image = true;
       }
       else
       {
@@ -514,6 +517,12 @@ void le_init_menus()
       }
       Button* button = new Button(imagefile, 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);
     }
   }
@@ -539,14 +548,12 @@ void le_init_menus()
 int le_init()
 {
   level_subsets = dsubdirs("/levels", "info");
-
   le_level_subset = new LevelSubset;
 
   active_tm = TM_IA;
-
   le_show_grid = true;
+  scroll_x = 0;
 
-  /*  level_changed = NO;*/
   fire = DOWN;
   done = 0;
   le_frame = 0;        /* support for frames in some tiles, like waves and bad guys */
@@ -581,7 +588,9 @@ int le_init()
   le_tilemap_panel->additem(new Button("/images/icons/bkgrd.png","Background",SDLK_F4,0,0),TM_BG);
   le_tilemap_panel->additem(new Button("/images/icons/intact.png","Interactive",SDLK_F4,0,0),TM_IA);
   le_tilemap_panel->additem(new Button("/images/icons/frgrd.png","Foreground",SDLK_F4,0,0),TM_FG);
-
+    
+  le_current.Init();
+  
   le_init_menus();
 
   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
@@ -1398,7 +1407,7 @@ void le_testlevel()
 
   music_manager->halt_music();
 
-  Menu::set_current(leveleditor_menu);
+  Menu::set_current(NULL);
   le_world.arrays_free();
   le_current_level->load_gfx();
   le_world.activate_bad_guys();
index 7afe076..1ffefcb 100644 (file)
@@ -64,9 +64,9 @@ enum LevelEditorMainMenuIDs {
   };
   
 enum LevelEditorSubsetSettingsIDs {
-  MNID_TITLE,
-  MNID_DESCRIPTION,
-  MNID_SAVE_CHANGES
+  MNID_SUBSETTITLE,
+  MNID_SUBSETDESCRIPTION,
+  MNID_SUBSETSAVECHANGES
   };
   
 enum LevelEditorSubsetNewIDs {