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