Made use of small tux.
[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 using namespace SuperTux;
36
37 enum LevelEditorMainMenuIDs {
38   MNID_RETURNLEVELEDITOR,
39   MNID_SUBSETSETTINGS,
40   MNID_QUITLEVELEDITOR
41   };
42   
43 enum LevelEditorSubsetSettingsIDs {
44   MNID_SUBSETTITLE,
45   MNID_SUBSETDESCRIPTION,
46   MNID_SUBSETSAVECHANGES
47   };
48   
49 enum LevelEditorSubsetNewIDs {
50  MNID_SUBSETNAME,
51  MNID_CREATESUBSET
52 };
53
54 enum LevelEditorSettingsMenuIDs {
55   MNID_NAME,
56   MNID_AUTHOR,
57   MNID_SONG,
58   MNID_BGIMG,
59   MNID_PARTICLE,
60   MNID_LENGTH,
61   MNID_HEIGHT,
62   MNID_TIME,
63   MNID_GRAVITY,
64   MNID_BGSPEED,
65   MNID_TopRed,
66   MNID_TopGreen,
67   MNID_TopBlue,
68   MNID_BottomRed,
69   MNID_BottomGreen,
70   MNID_BottomBlue,
71   MNID_APPLY
72   };
73
74   
75 class LevelEditor
76 {
77 public:
78   LevelEditor();
79   ~LevelEditor();
80
81   int run(char* filename = NULL);
82
83 private:
84
85 // Functions
86 void newlevel(void);
87 void selectlevel(void);
88 void savelevel();
89 void editlevel(void);
90 void testlevel(void);
91 void checkevents(void);
92 void unload_level();
93
94 /* own declerations */
95 /* crutial ones (main loop) */
96 void init_menus();
97 int load_level_subset(const char *filename);
98 void drawlevel(DrawingContext& context);
99 void drawinterface(DrawingContext& context);
100 void change(float x, float y, int tm, unsigned int c);
101 void showhelp();
102 void set_defaults(void);
103 void activate_bad_guys(void);
104 void goto_level(int levelnb);
105 void highlight_selection();
106
107 void drawminimap();
108
109 void apply_level_settings_menu();
110 void update_subset_settings_menu();
111 void save_subset_settings_menu();
112 void update_level_settings_menu();
113 void change_object_properties(GameObject *pobj);
114
115 // structs
116 struct TileOrObject
117 {
118   TileOrObject() : tile(0), obj(NULL) { is_tile = true; };
119
120   void Tile(unsigned int set_to) { tile = set_to; is_tile = true; }
121   void Object(GameObject* pobj) { obj = pobj; is_tile = false; }
122   //Returns true for a tile
123   bool IsTile() { return is_tile; };
124   //Returns true for a GameObject
125   bool IsObject() { return !is_tile; };
126
127
128   void Init() { tile = 0; obj = NULL; is_tile = true; };
129
130   bool is_tile; //true for tile (false for object)
131   unsigned int tile;
132   GameObject* obj;
133 };
134
135 struct square
136 {
137   int x1, y1, x2, y2;
138 };
139
140 /* selection modes */
141 enum SelectionMode { CURSOR, SQUARE, NONE };
142
143 // variables
144 /* leveleditor internals */
145 std::set<std::string> level_subsets;
146 bool le_level_changed;  /* if changes, ask for saving, when quiting*/
147 bool show_minimap;
148 bool show_selections;
149 bool le_help_shown;
150 int pos_x, pos_y, cursor_x, cursor_y;
151 int le_levelnb;
152 Level* le_level;
153 LevelSubset* le_level_subset;
154 int le_show_grid;
155 int le_frame;
156 Surface* le_selection;
157 int done;
158 TileOrObject le_current;
159 bool le_mouse_pressed[2];
160 bool le_mouse_clicked[2];
161 Button* le_save_level_bt;
162 Button* le_exit_bt;
163 Button* le_test_level_bt;
164 Button* le_next_level_bt;
165 Button* le_previous_level_bt;
166 Button* le_move_right_bt;
167 Button* le_move_left_bt;
168 Button* le_move_up_bt;
169 Button* le_move_down_bt;
170 Button* le_rubber_bt;
171 Button* le_select_mode_one_bt;
172 Button* le_select_mode_two_bt;
173 Button* le_settings_bt;
174 Button* le_tilegroup_bt;
175 Button* le_objects_bt;
176 Button* le_object_select_bt;
177 Button* le_object_properties_bt;
178 ButtonPanel* le_tilemap_panel;
179 int active_tm;
180 Menu* leveleditor_menu;
181 Menu* subset_load_menu;
182 Menu* subset_new_menu;
183 Menu* subset_settings_menu;
184 Menu* level_settings_menu;
185 Menu* select_tilegroup_menu;
186 Menu* select_objects_menu;
187 Timer select_tilegroup_menu_effect;
188 Timer select_objects_menu_effect;
189 Timer display_level_info;
190 typedef std::map<std::string, ButtonPanel*> ButtonPanelMap;
191 ButtonPanelMap tilegroups_map;
192 ButtonPanelMap objects_map;
193 std::string cur_tilegroup;
194 std::string cur_objects;
195 MouseCursor* mouse_select_object;
196 MovingObject* selected_game_object;
197
198 square selection;
199 SelectionMode le_selection_mode;
200 SDL_Event event;
201 };
202
203 #endif /*SUPERTUX_LEVELEDITOR_H*/