-Started to move stuff from library back to main game
[supertux.git] / src / leveleditor.h
index 6598994..16ac9da 100644 (file)
@@ -1,8 +1,7 @@
 //  $Id$
 // 
 //  SuperTux
-//  Copyright (C) 2003 Ricardo Cruz <rick2@aeiou.pt>
-//  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
+//  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License
 // 
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/* leveleditor.h - A built-in level editor for SuperTux */
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+//  02111-1307, USA.
 
 #ifndef SUPERTUX_LEVELEDITOR_H
 #define SUPERTUX_LEVELEDITOR_H
 
-#include "screen/drawing_context.h"
-#include "game_object.h"
-#include "screen/texture.h"
+#include <set>
+#include <string>
+
+#include "video/drawing_context.h"
+#include "timer.h"
 #include "level.h"
-#include "button.h"
-#include "menu.h"
+#include "level_subset.h"
+
+using namespace SuperTux;
+
+namespace SuperTux {
+class ButtonGroup;
+}
+
+class Menu;
+class Sector;
+class TileMap;
+class Surface;
+
+enum {
+  MN_ID_RETURN,
+  MN_ID_LOAD_SUBSET,
+  MN_ID_QUIT,
+
+  // settings menu ids:
+  MN_ID_NAME,
+  MN_ID_AUTHOR,
+  MN_ID_WIDTH,
+  MN_ID_HEIGHT,
+  MN_ID_APPLY_SETTINGS,
+  
+  // creating subset menu ids:
+  MN_ID_FILENAME_SUBSET,
+  MN_ID_TITLE_SUBSET,
+  MN_ID_DESCRIPTION_SUBSET,
+  MN_ID_CREATE_SUBSET
+  };
+
+enum {
+  BT_LEVEL_SAVE,
+  BT_LEVEL_TEST,
+  BT_LEVEL_SETUP,
+
+  BT_NEXT_LEVEL,
+  BT_PREVIOUS_LEVEL,
+  BT_NEXT_SECTOR,
+  BT_PREVIOUS_SECTOR
+  };
+
+enum {
+  OBJ_TRAMPOLINE = -100,
+  OBJ_FLYING_PLATFORM = -101,
+  OBJ_DOOR = -102
+  };
 
 class LevelEditor
 {
@@ -36,126 +82,71 @@ public:
   LevelEditor();
   ~LevelEditor();
 
-  int run(char* filename = NULL);
+  void run(const std::string filename = "");
 
 private:
+  void events();
+  void action();
+  void draw(DrawingContext& context);
 
-// Functions
-void newlevel(void);
-void selectlevel(void);
-void savelevel();
-void editlevel(void);
-void testlevel(void);
-void checkevents(void);
-void unload_level();
-
-/* own declerations */
-/* crutial ones (main loop) */
-void init_menus();
-int load_level_subset(char *filename);
-void drawlevel(DrawingContext& context);
-void drawinterface(DrawingContext& context);
-void change(float x, float y, int tm, unsigned int c);
-void showhelp();
-void set_defaults(void);
-void activate_bad_guys(void);
-void goto_level(int levelnb);
-void highlight_selection();
-
-void drawminimap();
-
-void apply_level_settings_menu();
-void update_subset_settings_menu();
-void save_subset_settings_menu();
-void update_level_settings_menu();
-void change_object_properties(GameObject *pobj);
-
-// structs
-struct TileOrObject
-{
-  TileOrObject() : tile(0), obj(NULL) { is_tile = true; };
+  void load_level_subset(std::string filename);
+  void load_level(std::string filename);
+  void load_level(int nb);
+  void load_sector(size_t num);
 
-  void Tile(unsigned int set_to) { tile = set_to; is_tile = true; }
-  void Object(GameObject* pobj) { obj = pobj; is_tile = false; }
-  //Returns true for a tile
-  bool IsTile() { return is_tile; };
-  //Returns true for a GameObject
-  bool IsObject() { return !is_tile; };
+  void save_level();
+  void test_level();
+  void setup_level();
 
+  void show_help();
 
-  void Init() { tile = 0; obj = NULL; is_tile = true; };
+  void change(int x, int y, int newtile, int layer);
 
-  bool is_tile; //true for tile (false for object)
-  unsigned int tile;
-  GameObject* obj;
-};
+  void load_buttons_gfx();
+  void free_buttons_gfx();
 
-struct square
-{
-  int x1, y1, x2, y2;
-};
+  Level* level;
+  std::string level_filename;
+
+  size_t sectornum; // number of current sector
+  Sector* sector;  // current sector
+  TileMap *solids, *foregrounds, *backgrounds;
+  std::string sector_name;
+
+  std::set<std::string> level_subsets;
+  LevelSubset* level_subset;
+  int level_nb;
+
+  Menu* main_menu;
+  Menu* subset_menu;
+  Menu* create_subset_menu;
+  Menu* settings_menu;
 
-/* selection modes */
-enum SelectionMode { CURSOR, SQUARE, NONE };
-
-// variables
-/* leveleditor internals */
-string_list_type level_subsets;
-bool le_level_changed;  /* if changes, ask for saving, when quiting*/
-bool show_minimap;
-bool show_selections;
-bool le_help_shown;
-int pos_x, pos_y, cursor_x, cursor_y;
-int le_levelnb;
-Level* le_level;
-LevelSubset* le_level_subset;
-int le_show_grid;
-int le_frame;
-Surface* le_selection;
-int done;
-TileOrObject le_current;
-bool le_mouse_pressed[2];
-bool le_mouse_clicked[2];
-Button* le_save_level_bt;
-Button* le_exit_bt;
-Button* le_test_level_bt;
-Button* le_next_level_bt;
-Button* le_previous_level_bt;
-Button* le_move_right_bt;
-Button* le_move_left_bt;
-Button* le_move_up_bt;
-Button* le_move_down_bt;
-Button* le_rubber_bt;
-Button* le_select_mode_one_bt;
-Button* le_select_mode_two_bt;
-Button* le_settings_bt;
-Button* le_tilegroup_bt;
-Button* le_objects_bt;
-Button* le_object_select_bt;
-Button* le_object_properties_bt;
-ButtonPanel* le_tilemap_panel;
-int active_tm;
-Menu* leveleditor_menu;
-Menu* subset_load_menu;
-Menu* subset_new_menu;
-Menu* subset_settings_menu;
-Menu* level_settings_menu;
-Menu* select_tilegroup_menu;
-Menu* select_objects_menu;
-Timer select_tilegroup_menu_effect;
-Timer select_objects_menu_effect;
-Timer display_level_info;
-typedef std::map<std::string, ButtonPanel*> ButtonPanelMap;
-ButtonPanelMap tilegroups_map;
-ButtonPanelMap objects_map;
-std::string cur_tilegroup;
-std::string cur_objects;
-MouseCursor* mouse_select_object;
-MovingObject* selected_game_object;
-
-square selection;
-SelectionMode le_selection_mode;
-SDL_Event event;
+  bool left_button, middle_button, mouse_moved;
+  int mouse_x, mouse_y;
+  bool done;
+  bool show_grid;
+
+  Vector scroll;
+  float zoom;
+
+  Timer2 level_name_timer;
+
+  Surface *img_background_bt, *img_foreground_bt, *img_interactive_bt;
+  Surface *img_save_level_bt, *img_setup_level_bt, *img_test_level_bt;
+  Surface *img_rubber_bt;
+  Surface *img_previous_level_bt, *img_next_level_bt, *img_previous_sector_bt, *img_next_sector_bt;
+
+  ButtonGroup *tiles_board, *tiles_layer, *level_options;
+  int gameobjs_first_id, cur_layer;
+
+  std::vector <std::vector <int> > selection;
+  Vector selection_ini, selection_end;
+
+  bool level_changed;
+
+private:
+  Sector* create_sector(const std::string& name, size_t width, size_t height);
 };
 
-#endif /*SUPERTUX_LEVELEDITOR_H*/
+#endif