d4bf7f5c874e4b8c06198d639e79f8f051ffc1d6
[supertux.git] / src / leveleditor.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2003 Ricardo Cruz <rick2@aeiou.pt>
5 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 // 
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /* leveleditor.h - A built-in level editor for SuperTux */
22
23 #ifndef SUPERTUX_LEVELEDITOR_H
24 #define SUPERTUX_LEVELEDITOR_H
25
26 #include "video/drawing_context.h"
27 #include "special/game_object.h"
28 #include "video/surface.h"
29 #include "level.h"
30 #include "level_subset.h"
31 #include "special/moving_object.h"
32 #include "gui/button.h"
33 #include "gui/menu.h"
34
35 enum LevelEditorMainMenuIDs {
36   MNID_RETURNLEVELEDITOR,
37   MNID_SUBSETSETTINGS,
38   MNID_QUITLEVELEDITOR
39   };
40   
41 enum LevelEditorSubsetSettingsIDs {
42   MNID_SUBSETTITLE,
43   MNID_SUBSETDESCRIPTION,
44   MNID_SUBSETSAVECHANGES
45   };
46   
47 enum LevelEditorSubsetNewIDs {
48  MNID_SUBSETNAME,
49  MNID_CREATESUBSET
50 };
51
52 enum LevelEditorSettingsMenuIDs {
53   MNID_NAME,
54   MNID_AUTHOR,
55   MNID_SONG,
56   MNID_BGIMG,
57   MNID_PARTICLE,
58   MNID_LENGTH,
59   MNID_HEIGHT,
60   MNID_TIME,
61   MNID_GRAVITY,
62   MNID_BGSPEED,
63   MNID_TopRed,
64   MNID_TopGreen,
65   MNID_TopBlue,
66   MNID_BottomRed,
67   MNID_BottomGreen,
68   MNID_BottomBlue,
69   MNID_APPLY
70   };
71
72   
73 class LevelEditor
74 {
75 public:
76   LevelEditor();
77   ~LevelEditor();
78
79   int run(char* filename = NULL);
80
81 private:
82
83 // Functions
84 void newlevel(void);
85 void selectlevel(void);
86 void savelevel();
87 void editlevel(void);
88 void testlevel(void);
89 void checkevents(void);
90 void unload_level();
91
92 /* own declerations */
93 /* crutial ones (main loop) */
94 void init_menus();
95 int load_level_subset(char *filename);
96 void drawlevel(DrawingContext& context);
97 void drawinterface(DrawingContext& context);
98 void change(float x, float y, int tm, unsigned int c);
99 void showhelp();
100 void set_defaults(void);
101 void activate_bad_guys(void);
102 void goto_level(int levelnb);
103 void highlight_selection();
104
105 void drawminimap();
106
107 void apply_level_settings_menu();
108 void update_subset_settings_menu();
109 void save_subset_settings_menu();
110 void update_level_settings_menu();
111 void change_object_properties(GameObject *pobj);
112
113 // structs
114 struct TileOrObject
115 {
116   TileOrObject() : tile(0), obj(NULL) { is_tile = true; };
117
118   void Tile(unsigned int set_to) { tile = set_to; is_tile = true; }
119   void Object(GameObject* pobj) { obj = pobj; is_tile = false; }
120   //Returns true for a tile
121   bool IsTile() { return is_tile; };
122   //Returns true for a GameObject
123   bool IsObject() { return !is_tile; };
124
125
126   void Init() { tile = 0; obj = NULL; is_tile = true; };
127
128   bool is_tile; //true for tile (false for object)
129   unsigned int tile;
130   GameObject* obj;
131 };
132
133 struct square
134 {
135   int x1, y1, x2, y2;
136 };
137
138 /* selection modes */
139 enum SelectionMode { CURSOR, SQUARE, NONE };
140
141 // variables
142 /* leveleditor internals */
143 string_list_type level_subsets;
144 bool le_level_changed;  /* if changes, ask for saving, when quiting*/
145 bool show_minimap;
146 bool show_selections;
147 bool le_help_shown;
148 int pos_x, pos_y, cursor_x, cursor_y;
149 int le_levelnb;
150 Level* le_level;
151 LevelSubset* le_level_subset;
152 int le_show_grid;
153 int le_frame;
154 Surface* le_selection;
155 int done;
156 TileOrObject le_current;
157 bool le_mouse_pressed[2];
158 bool le_mouse_clicked[2];
159 Button* le_save_level_bt;
160 Button* le_exit_bt;
161 Button* le_test_level_bt;
162 Button* le_next_level_bt;
163 Button* le_previous_level_bt;
164 Button* le_move_right_bt;
165 Button* le_move_left_bt;
166 Button* le_move_up_bt;
167 Button* le_move_down_bt;
168 Button* le_rubber_bt;
169 Button* le_select_mode_one_bt;
170 Button* le_select_mode_two_bt;
171 Button* le_settings_bt;
172 Button* le_tilegroup_bt;
173 Button* le_objects_bt;
174 Button* le_object_select_bt;
175 Button* le_object_properties_bt;
176 ButtonPanel* le_tilemap_panel;
177 int active_tm;
178 Menu* leveleditor_menu;
179 Menu* subset_load_menu;
180 Menu* subset_new_menu;
181 Menu* subset_settings_menu;
182 Menu* level_settings_menu;
183 Menu* select_tilegroup_menu;
184 Menu* select_objects_menu;
185 Timer select_tilegroup_menu_effect;
186 Timer select_objects_menu_effect;
187 Timer display_level_info;
188 typedef std::map<std::string, ButtonPanel*> ButtonPanelMap;
189 ButtonPanelMap tilegroups_map;
190 ButtonPanelMap objects_map;
191 std::string cur_tilegroup;
192 std::string cur_objects;
193 MouseCursor* mouse_select_object;
194 MovingObject* selected_game_object;
195
196 square selection;
197 SelectionMode le_selection_mode;
198 SDL_Event event;
199 };
200
201 #endif /*SUPERTUX_LEVELEDITOR_H*/