changed lisp_free to an iterative algorithm
[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 "screen/drawing_context.h"
27 #include "game_object.h"
28 #include "screen/surface.h"
29 #include "level.h"
30 #include "level_subset.h"
31 #include "moving_object.h"
32 #include "button.h"
33 #include "menu.h"
34
35 class LevelEditor
36 {
37 public:
38   LevelEditor();
39   ~LevelEditor();
40
41   int run(char* filename = NULL);
42
43 private:
44
45 // Functions
46 void newlevel(void);
47 void selectlevel(void);
48 void savelevel();
49 void editlevel(void);
50 void testlevel(void);
51 void checkevents(void);
52 void unload_level();
53
54 /* own declerations */
55 /* crutial ones (main loop) */
56 void init_menus();
57 int load_level_subset(char *filename);
58 void drawlevel(DrawingContext& context);
59 void drawinterface(DrawingContext& context);
60 void change(float x, float y, int tm, unsigned int c);
61 void showhelp();
62 void set_defaults(void);
63 void activate_bad_guys(void);
64 void goto_level(int levelnb);
65 void highlight_selection();
66
67 void drawminimap();
68
69 void apply_level_settings_menu();
70 void update_subset_settings_menu();
71 void save_subset_settings_menu();
72 void update_level_settings_menu();
73 void change_object_properties(GameObject *pobj);
74
75 // structs
76 struct TileOrObject
77 {
78   TileOrObject() : tile(0), obj(NULL) { is_tile = true; };
79
80   void Tile(unsigned int set_to) { tile = set_to; is_tile = true; }
81   void Object(GameObject* pobj) { obj = pobj; is_tile = false; }
82   //Returns true for a tile
83   bool IsTile() { return is_tile; };
84   //Returns true for a GameObject
85   bool IsObject() { return !is_tile; };
86
87
88   void Init() { tile = 0; obj = NULL; is_tile = true; };
89
90   bool is_tile; //true for tile (false for object)
91   unsigned int tile;
92   GameObject* obj;
93 };
94
95 struct square
96 {
97   int x1, y1, x2, y2;
98 };
99
100 /* selection modes */
101 enum SelectionMode { CURSOR, SQUARE, NONE };
102
103 // variables
104 /* leveleditor internals */
105 string_list_type level_subsets;
106 bool le_level_changed;  /* if changes, ask for saving, when quiting*/
107 bool show_minimap;
108 bool show_selections;
109 bool le_help_shown;
110 int pos_x, pos_y, cursor_x, cursor_y;
111 int le_levelnb;
112 Level* le_level;
113 LevelSubset* le_level_subset;
114 int le_show_grid;
115 int le_frame;
116 Surface* le_selection;
117 int done;
118 TileOrObject le_current;
119 bool le_mouse_pressed[2];
120 bool le_mouse_clicked[2];
121 Button* le_save_level_bt;
122 Button* le_exit_bt;
123 Button* le_test_level_bt;
124 Button* le_next_level_bt;
125 Button* le_previous_level_bt;
126 Button* le_move_right_bt;
127 Button* le_move_left_bt;
128 Button* le_move_up_bt;
129 Button* le_move_down_bt;
130 Button* le_rubber_bt;
131 Button* le_select_mode_one_bt;
132 Button* le_select_mode_two_bt;
133 Button* le_settings_bt;
134 Button* le_tilegroup_bt;
135 Button* le_objects_bt;
136 Button* le_object_select_bt;
137 Button* le_object_properties_bt;
138 ButtonPanel* le_tilemap_panel;
139 int active_tm;
140 Menu* leveleditor_menu;
141 Menu* subset_load_menu;
142 Menu* subset_new_menu;
143 Menu* subset_settings_menu;
144 Menu* level_settings_menu;
145 Menu* select_tilegroup_menu;
146 Menu* select_objects_menu;
147 Timer select_tilegroup_menu_effect;
148 Timer select_objects_menu_effect;
149 Timer display_level_info;
150 typedef std::map<std::string, ButtonPanel*> ButtonPanelMap;
151 ButtonPanelMap tilegroups_map;
152 ButtonPanelMap objects_map;
153 std::string cur_tilegroup;
154 std::string cur_objects;
155 MouseCursor* mouse_select_object;
156 MovingObject* selected_game_object;
157
158 square selection;
159 SelectionMode le_selection_mode;
160 SDL_Event event;
161 };
162
163 #endif /*SUPERTUX_LEVELEDITOR_H*/