16ac9dafa7b6bf619adac38d6ca25a933379d273
[supertux.git] / src / leveleditor.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #ifndef SUPERTUX_LEVELEDITOR_H
22 #define SUPERTUX_LEVELEDITOR_H
23
24 #include <set>
25 #include <string>
26
27 #include "video/drawing_context.h"
28 #include "timer.h"
29 #include "level.h"
30 #include "level_subset.h"
31
32 using namespace SuperTux;
33
34 namespace SuperTux {
35 class ButtonGroup;
36 }
37
38 class Menu;
39 class Sector;
40 class TileMap;
41 class Surface;
42
43 enum {
44   MN_ID_RETURN,
45   MN_ID_LOAD_SUBSET,
46   MN_ID_QUIT,
47
48   // settings menu ids:
49   MN_ID_NAME,
50   MN_ID_AUTHOR,
51   MN_ID_WIDTH,
52   MN_ID_HEIGHT,
53   MN_ID_APPLY_SETTINGS,
54   
55   // creating subset menu ids:
56   MN_ID_FILENAME_SUBSET,
57   MN_ID_TITLE_SUBSET,
58   MN_ID_DESCRIPTION_SUBSET,
59   MN_ID_CREATE_SUBSET
60   };
61
62 enum {
63   BT_LEVEL_SAVE,
64   BT_LEVEL_TEST,
65   BT_LEVEL_SETUP,
66
67   BT_NEXT_LEVEL,
68   BT_PREVIOUS_LEVEL,
69   BT_NEXT_SECTOR,
70   BT_PREVIOUS_SECTOR
71   };
72
73 enum {
74   OBJ_TRAMPOLINE = -100,
75   OBJ_FLYING_PLATFORM = -101,
76   OBJ_DOOR = -102
77   };
78
79 class LevelEditor
80 {
81 public:
82   LevelEditor();
83   ~LevelEditor();
84
85   void run(const std::string filename = "");
86
87 private:
88   void events();
89   void action();
90   void draw(DrawingContext& context);
91
92   void load_level_subset(std::string filename);
93   void load_level(std::string filename);
94   void load_level(int nb);
95   void load_sector(size_t num);
96
97   void save_level();
98   void test_level();
99   void setup_level();
100
101   void show_help();
102
103   void change(int x, int y, int newtile, int layer);
104
105   void load_buttons_gfx();
106   void free_buttons_gfx();
107
108   Level* level;
109   std::string level_filename;
110
111   size_t sectornum; // number of current sector
112   Sector* sector;  // current sector
113   TileMap *solids, *foregrounds, *backgrounds;
114   std::string sector_name;
115
116   std::set<std::string> level_subsets;
117   LevelSubset* level_subset;
118   int level_nb;
119
120   Menu* main_menu;
121   Menu* subset_menu;
122   Menu* create_subset_menu;
123   Menu* settings_menu;
124
125   bool left_button, middle_button, mouse_moved;
126   int mouse_x, mouse_y;
127   bool done;
128   bool show_grid;
129
130   Vector scroll;
131   float zoom;
132
133   Timer2 level_name_timer;
134
135   Surface *img_background_bt, *img_foreground_bt, *img_interactive_bt;
136   Surface *img_save_level_bt, *img_setup_level_bt, *img_test_level_bt;
137   Surface *img_rubber_bt;
138   Surface *img_previous_level_bt, *img_next_level_bt, *img_previous_sector_bt, *img_next_sector_bt;
139
140   ButtonGroup *tiles_board, *tiles_layer, *level_options;
141   int gameobjs_first_id, cur_layer;
142
143   std::vector <std::vector <int> > selection;
144   Vector selection_ini, selection_end;
145
146   bool level_changed;
147
148 private:
149   Sector* create_sector(const std::string& name, size_t width, size_t height);
150 };
151
152 #endif