1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
16 #include "libgame/libgame.h"
28 -----------------------------------------------------------------------------
29 screen and artwork graphic pixel position definitions
30 -----------------------------------------------------------------------------
33 /* positions in the level editor */
34 #define ED_WIN_MB_LEFT_XPOS 6
35 #define ED_WIN_MB_LEFT_YPOS 258
36 #define ED_WIN_MB_MIDDLE_XPOS 42
37 #define ED_WIN_MB_MIDDLE_YPOS ED_WIN_MB_LEFT_YPOS
38 #define ED_WIN_MB_RIGHT_XPOS 78
39 #define ED_WIN_MB_RIGHT_YPOS ED_WIN_MB_LEFT_YPOS
41 /* values for the control window */
42 #define ED_CTRL_BUTTONS_GFX_YPOS 236
43 #define ED_CTRL_BUTTONS_ALT_GFX_YPOS 142
45 #define ED_CTRL1_BUTTONS_HORIZ 4
46 #define ED_CTRL1_BUTTONS_VERT 4
47 #define ED_CTRL1_BUTTON_XSIZE 22
48 #define ED_CTRL1_BUTTON_YSIZE 22
49 #define ED_CTRL1_BUTTONS_XPOS 6
50 #define ED_CTRL1_BUTTONS_YPOS 6
51 #define ED_CTRL2_BUTTONS_HORIZ 3
52 #define ED_CTRL2_BUTTONS_VERT 2
53 #define ED_CTRL2_BUTTON_XSIZE 30
54 #define ED_CTRL2_BUTTON_YSIZE 20
55 #define ED_CTRL2_BUTTONS_XPOS 5
56 #define ED_CTRL2_BUTTONS_YPOS 99
57 #define ED_NUM_CTRL1_BUTTONS (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT)
58 #define ED_NUM_CTRL2_BUTTONS (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT)
59 #define ED_NUM_CTRL_BUTTONS (ED_NUM_CTRL1_BUTTONS + ED_NUM_CTRL2_BUTTONS)
61 /* values for the element list */
62 #define ED_ELEMENTLIST_XPOS 5
63 #define ED_ELEMENTLIST_YPOS 30
64 #define ED_ELEMENTLIST_XSIZE 20
65 #define ED_ELEMENTLIST_YSIZE 20
66 #define ED_ELEMENTLIST_BUTTONS_HORIZ 4
67 #define ED_ELEMENTLIST_BUTTONS_VERT 11
68 #define ED_NUM_ELEMENTLIST_BUTTONS (ED_ELEMENTLIST_BUTTONS_HORIZ * \
69 ED_ELEMENTLIST_BUTTONS_VERT)
71 /* standard distances */
72 #define ED_BORDER_SIZE 3
73 #define ED_BORDER_TEXT_XSIZE 5
74 #define ED_BORDER_AREA_YSIZE 1
76 #define ED_GADGET_DISTANCE 2
77 #define ED_GADGET_TEXT_DISTANCE (2 * ED_GADGET_DISTANCE)
78 #define ED_DRAWINGAREA_TEXT_DISTANCE (ED_GADGET_TEXT_DISTANCE + \
81 /* values for the setting windows */
82 #define ED_SETTINGS_XSTART (3 * MINI_TILEX / 2)
83 #define ED_SETTINGS_YSTART (MINI_TILEY * 10)
85 #define ED_XOFFSET_CHECKBOX (ED_CHECKBUTTON_XSIZE + \
86 2 * ED_GADGET_DISTANCE)
88 #define ED_SETTINGS_XOFFSET ED_XOFFSET_CHECKBOX
89 #define ED_SETTINGS_YOFFSET (3 * MINI_TILEY / 2)
91 #define ED_SETTINGS_XPOS(n) (ED_SETTINGS_XSTART + \
92 n * ED_SETTINGS_XOFFSET)
93 #define ED_SETTINGS_YPOS(n) (ED_SETTINGS_YSTART + \
94 n * ED_SETTINGS_YOFFSET)
96 #define ED_SETTINGS1_YPOS MINI_TILEY
97 #define ED_SETTINGS2_XPOS MINI_TILEX
98 #define ED_SETTINGS2_YPOS (ED_SETTINGS1_YPOS + 12 * TILEY - 2)
100 /* values for counter gadgets */
101 #define ED_COUNT_PUSH_DELAY_RND_XPOS (ED_SETTINGS_XPOS(1) + 16 * MINI_TILEX)
102 #define ED_COUNT_MOVE_DELAY_RND_XPOS ED_COUNT_PUSH_DELAY_RND_XPOS
103 #define ED_COUNT_CHANGE_DELAY_RND_XPOS (ED_SETTINGS_XPOS(1) + 13 * MINI_TILEX)
105 #define ED_COUNTER_YSTART (ED_SETTINGS1_YPOS + 2 * TILEY)
106 #define ED_COUNTER_YDISTANCE (3 * MINI_TILEY)
107 #define ED_COUNTER_YPOS(n) (ED_COUNTER_YSTART + \
108 n * ED_COUNTER_YDISTANCE)
109 #define ED_COUNTER2_YPOS(n) (ED_COUNTER_YSTART + \
110 n * ED_COUNTER_YDISTANCE - 2)
112 /* values for element content drawing areas */
114 #define ED_AREA_ELEM_CONTENT_XPOS ( 2 * MINI_TILEX)
115 #define ED_AREA_ELEM_CONTENT_YPOS (22 * MINI_TILEY)
118 #define ED_AREA_YAMYAM_CONTENT_XPOS(n) (ED_AREA_ELEM_CONTENT_XPOS + \
119 5 * (n % 4) * MINI_TILEX)
120 #define ED_AREA_YAMYAM_CONTENT_YPOS(n) (ED_AREA_ELEM_CONTENT_YPOS + \
121 6 * (n / 4) * MINI_TILEY)
123 /* custom change target */
124 #define ED_AREA_ELEM_CONTENT2_XPOS (20 * MINI_TILEX)
125 #define ED_AREA_ELEM_CONTENT2_YPOS (ED_SETTINGS_YPOS(2) + \
127 /* optional custom graphic */
128 #define ED_AREA_ELEM_CONTENT3_XPOS (24 * MINI_TILEX)
129 #define ED_AREA_ELEM_CONTENT3_YPOS (ED_SETTINGS_YPOS(1) + \
131 /* custom element content */
132 #define ED_AREA_ELEM_CONTENT4_XPOS (29 * MINI_TILEX)
133 #define ED_AREA_ELEM_CONTENT4_YPOS (ED_SETTINGS_YPOS(12) + \
134 ED_GADGET_DISTANCE - MINI_TILEY)
135 /* custom change trigger element */
136 #define ED_AREA_ELEM_CONTENT5_XPOS (28 * MINI_TILEX)
137 #define ED_AREA_ELEM_CONTENT5_YPOS (ED_SETTINGS_YPOS(7) + \
139 /* extended custom change target */
140 #define ED_AREA_ELEM_CONTENT6_XPOS (29 * MINI_TILEX)
141 #define ED_AREA_ELEM_CONTENT6_YPOS (ED_SETTINGS_YPOS(10) + \
142 ED_GADGET_DISTANCE - MINI_TILEY)
144 /* values for random placement background drawing area */
145 #define ED_AREA_RANDOM_BACKGROUND_XPOS (29 * MINI_TILEX)
146 #define ED_AREA_RANDOM_BACKGROUND_YPOS (31 * MINI_TILEY)
148 /* values for scrolling gadgets for drawing area */
149 #define ED_SCROLLBUTTON_XPOS 24
150 #define ED_SCROLLBUTTON_YPOS 0
151 #define ED_SCROLLBAR_XPOS 24
152 #define ED_SCROLLBAR_YPOS 64
154 #define ED_SCROLLBUTTON_XSIZE 16
155 #define ED_SCROLLBUTTON_YSIZE 16
157 #define ED_SCROLL_UP_XPOS (SXSIZE - ED_SCROLLBUTTON_XSIZE)
158 #define ED_SCROLL_UP_YPOS (0)
159 #define ED_SCROLL_DOWN_XPOS ED_SCROLL_UP_XPOS
160 #define ED_SCROLL_DOWN_YPOS (SYSIZE - 3 * ED_SCROLLBUTTON_YSIZE)
161 #define ED_SCROLL_LEFT_XPOS (0)
162 #define ED_SCROLL_LEFT_YPOS (SYSIZE - 2 * ED_SCROLLBUTTON_YSIZE)
163 #define ED_SCROLL_RIGHT_XPOS (SXSIZE - 2 * ED_SCROLLBUTTON_XSIZE)
164 #define ED_SCROLL_RIGHT_YPOS ED_SCROLL_LEFT_YPOS
165 #define ED_SCROLL_HORIZONTAL_XPOS (ED_SCROLL_LEFT_XPOS + ED_SCROLLBUTTON_XSIZE)
166 #define ED_SCROLL_HORIZONTAL_YPOS ED_SCROLL_LEFT_YPOS
167 #define ED_SCROLL_HORIZONTAL_XSIZE (SXSIZE - 3 * ED_SCROLLBUTTON_XSIZE)
168 #define ED_SCROLL_HORIZONTAL_YSIZE ED_SCROLLBUTTON_YSIZE
169 #define ED_SCROLL_VERTICAL_XPOS ED_SCROLL_UP_XPOS
170 #define ED_SCROLL_VERTICAL_YPOS (ED_SCROLL_UP_YPOS + ED_SCROLLBUTTON_YSIZE)
171 #define ED_SCROLL_VERTICAL_XSIZE ED_SCROLLBUTTON_XSIZE
172 #define ED_SCROLL_VERTICAL_YSIZE (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE)
174 /* values for scrolling gadgets for element list */
175 #define ED_SCROLLBUTTON2_XPOS 50
176 #define ED_SCROLLBUTTON2_YPOS 0
177 #define ED_SCROLLBAR2_XPOS 50
178 #define ED_SCROLLBAR2_YPOS 20
180 #define ED_SCROLLBUTTON2_XSIZE 10
181 #define ED_SCROLLBUTTON2_YSIZE 10
183 #define ED_SCROLL2_UP_XPOS 85
184 #define ED_SCROLL2_UP_YPOS 30
185 #define ED_SCROLL2_DOWN_XPOS ED_SCROLL2_UP_XPOS
186 #define ED_SCROLL2_DOWN_YPOS (ED_SCROLL2_UP_YPOS + \
187 ED_ELEMENTLIST_BUTTONS_VERT * \
188 ED_ELEMENTLIST_YSIZE - \
189 ED_SCROLLBUTTON2_YSIZE)
190 #define ED_SCROLL2_VERTICAL_XPOS ED_SCROLL2_UP_XPOS
191 #define ED_SCROLL2_VERTICAL_YPOS (ED_SCROLL2_UP_YPOS + \
192 ED_SCROLLBUTTON2_YSIZE)
193 #define ED_SCROLL2_VERTICAL_XSIZE ED_SCROLLBUTTON2_XSIZE
194 #define ED_SCROLL2_VERTICAL_YSIZE (ED_ELEMENTLIST_BUTTONS_VERT * \
195 ED_ELEMENTLIST_YSIZE - \
196 2 * ED_SCROLLBUTTON2_YSIZE)
198 /* values for checkbutton gadgets */
199 #define ED_CHECKBUTTON_XSIZE ED_BUTTON_COUNT_XSIZE
200 #define ED_CHECKBUTTON_YSIZE ED_BUTTON_COUNT_YSIZE
201 #define ED_CHECKBUTTON_UNCHECKED_XPOS ED_BUTTON_MINUS_XPOS
202 #define ED_CHECKBUTTON_CHECKED_XPOS ED_BUTTON_PLUS_XPOS
203 #define ED_CHECKBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 22)
204 #define ED_RADIOBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 44)
205 #define ED_STICKYBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 66)
207 /* some positions in the editor control window */
208 #define ED_BUTTON_ELEM_XPOS 6
209 #define ED_BUTTON_ELEM_YPOS 30
210 #define ED_BUTTON_ELEM_XSIZE 22
211 #define ED_BUTTON_ELEM_YSIZE 22
213 /* some values for text input, selectbox and counter gadgets */
214 #define ED_BUTTON_COUNT_YPOS 60
215 #define ED_BUTTON_COUNT_XSIZE 20
216 #define ED_BUTTON_COUNT_YSIZE 20
217 #define ED_WIN_COUNT_XPOS (2 + ED_BUTTON_COUNT_XSIZE + 2)
218 #define ED_WIN_COUNT_YPOS ED_BUTTON_COUNT_YPOS
219 #define ED_WIN_COUNT_XSIZE 52
220 #define ED_WIN_COUNT_YSIZE ED_BUTTON_COUNT_YSIZE
221 #define ED_WIN_COUNT2_XPOS 27
222 #define ED_WIN_COUNT2_YPOS 3
223 #define ED_WIN_COUNT2_XSIZE 46
224 #define ED_WIN_COUNT2_YSIZE ED_BUTTON_COUNT_YSIZE
226 #define ED_BUTTON_MINUS_XPOS 2
227 #define ED_BUTTON_MINUS_YPOS ED_BUTTON_COUNT_YPOS
228 #define ED_BUTTON_MINUS_XSIZE ED_BUTTON_COUNT_XSIZE
229 #define ED_BUTTON_MINUS_YSIZE ED_BUTTON_COUNT_YSIZE
230 #define ED_BUTTON_PLUS_XPOS (ED_WIN_COUNT_XPOS + \
231 ED_WIN_COUNT_XSIZE + 2)
232 #define ED_BUTTON_PLUS_YPOS ED_BUTTON_COUNT_YPOS
233 #define ED_BUTTON_PLUS_XSIZE ED_BUTTON_COUNT_XSIZE
234 #define ED_BUTTON_PLUS_YSIZE ED_BUTTON_COUNT_YSIZE
236 #define ED_SELECTBOX_XPOS ED_WIN_COUNT_XPOS
237 #define ED_SELECTBOX_YPOS (ED_WIN_COUNT_YPOS + \
238 2 + ED_WIN_COUNT_YSIZE)
239 #define ED_SELECTBOX_XSIZE ED_WIN_COUNT_XSIZE
240 #define ED_SELECTBOX_YSIZE ED_WIN_COUNT_YSIZE
242 #define ED_SELECTBOX_BUTTON_XSIZE 14
244 #define ED_TEXTBUTTON_XPOS ED_WIN_COUNT_XPOS
245 #define ED_TEXTBUTTON_YPOS (ED_WIN_COUNT_YPOS + \
246 4 * (2 + ED_WIN_COUNT_YSIZE))
247 #define ED_TEXTBUTTON_INACTIVE_YPOS ED_TEXTBUTTON_YPOS
249 #define ED_TEXTBUTTON_TAB_XPOS ED_WIN_COUNT_XPOS
250 #define ED_TEXTBUTTON_TAB_YPOS (ED_WIN_COUNT_YPOS + \
251 2 * (2 + ED_WIN_COUNT_YSIZE))
252 #define ED_TEXTBUTTON_TAB_INACTIVE_YPOS (ED_WIN_COUNT_YPOS + \
253 3 * (2 + ED_WIN_COUNT_YSIZE))
255 #define ED_TEXTBUTTON_XSIZE ED_WIN_COUNT_XSIZE
256 #define ED_TEXTBUTTON_YSIZE ED_WIN_COUNT_YSIZE
258 /* values for ClearEditorGadgetInfoText() and HandleGadgetInfoText() */
259 #define INFOTEXT_XPOS SX
260 #define INFOTEXT_YPOS (SY + SYSIZE - MINI_TILEX + 2)
261 #define INFOTEXT_XSIZE SXSIZE
262 #define INFOTEXT_YSIZE MINI_TILEX
266 -----------------------------------------------------------------------------
267 editor gadget definitions
268 -----------------------------------------------------------------------------
271 /* drawing toolbox buttons */
272 #define GADGET_ID_NONE -1
273 #define GADGET_ID_TOOLBOX_FIRST 0
275 #define GADGET_ID_SINGLE_ITEMS (GADGET_ID_TOOLBOX_FIRST + 0)
276 #define GADGET_ID_CONNECTED_ITEMS (GADGET_ID_TOOLBOX_FIRST + 1)
277 #define GADGET_ID_LINE (GADGET_ID_TOOLBOX_FIRST + 2)
278 #define GADGET_ID_ARC (GADGET_ID_TOOLBOX_FIRST + 3)
279 #define GADGET_ID_RECTANGLE (GADGET_ID_TOOLBOX_FIRST + 4)
280 #define GADGET_ID_FILLED_BOX (GADGET_ID_TOOLBOX_FIRST + 5)
281 #define GADGET_ID_WRAP_UP (GADGET_ID_TOOLBOX_FIRST + 6)
282 #define GADGET_ID_TEXT (GADGET_ID_TOOLBOX_FIRST + 7)
283 #define GADGET_ID_FLOOD_FILL (GADGET_ID_TOOLBOX_FIRST + 8)
284 #define GADGET_ID_WRAP_LEFT (GADGET_ID_TOOLBOX_FIRST + 9)
285 #define GADGET_ID_PROPERTIES (GADGET_ID_TOOLBOX_FIRST + 10)
286 #define GADGET_ID_WRAP_RIGHT (GADGET_ID_TOOLBOX_FIRST + 11)
287 #define GADGET_ID_RANDOM_PLACEMENT (GADGET_ID_TOOLBOX_FIRST + 12)
288 #define GADGET_ID_GRAB_BRUSH (GADGET_ID_TOOLBOX_FIRST + 13)
289 #define GADGET_ID_WRAP_DOWN (GADGET_ID_TOOLBOX_FIRST + 14)
290 #define GADGET_ID_PICK_ELEMENT (GADGET_ID_TOOLBOX_FIRST + 15)
291 #define GADGET_ID_UNDO (GADGET_ID_TOOLBOX_FIRST + 16)
292 #define GADGET_ID_INFO (GADGET_ID_TOOLBOX_FIRST + 17)
293 #define GADGET_ID_SAVE (GADGET_ID_TOOLBOX_FIRST + 18)
294 #define GADGET_ID_CLEAR (GADGET_ID_TOOLBOX_FIRST + 19)
295 #define GADGET_ID_TEST (GADGET_ID_TOOLBOX_FIRST + 20)
296 #define GADGET_ID_EXIT (GADGET_ID_TOOLBOX_FIRST + 21)
298 /* counter button identifiers */
299 #define GADGET_ID_COUNTER_FIRST (GADGET_ID_TOOLBOX_FIRST + 22)
301 #define GADGET_ID_SELECT_LEVEL_DOWN (GADGET_ID_COUNTER_FIRST + 0)
302 #define GADGET_ID_SELECT_LEVEL_TEXT (GADGET_ID_COUNTER_FIRST + 1)
303 #define GADGET_ID_SELECT_LEVEL_UP (GADGET_ID_COUNTER_FIRST + 2)
304 #define GADGET_ID_LEVEL_XSIZE_DOWN (GADGET_ID_COUNTER_FIRST + 3)
305 #define GADGET_ID_LEVEL_XSIZE_TEXT (GADGET_ID_COUNTER_FIRST + 4)
306 #define GADGET_ID_LEVEL_XSIZE_UP (GADGET_ID_COUNTER_FIRST + 5)
307 #define GADGET_ID_LEVEL_YSIZE_DOWN (GADGET_ID_COUNTER_FIRST + 6)
308 #define GADGET_ID_LEVEL_YSIZE_TEXT (GADGET_ID_COUNTER_FIRST + 7)
309 #define GADGET_ID_LEVEL_YSIZE_UP (GADGET_ID_COUNTER_FIRST + 8)
310 #define GADGET_ID_LEVEL_RANDOM_DOWN (GADGET_ID_COUNTER_FIRST + 9)
311 #define GADGET_ID_LEVEL_RANDOM_TEXT (GADGET_ID_COUNTER_FIRST + 10)
312 #define GADGET_ID_LEVEL_RANDOM_UP (GADGET_ID_COUNTER_FIRST + 11)
313 #define GADGET_ID_LEVEL_GEMSLIMIT_DOWN (GADGET_ID_COUNTER_FIRST + 12)
314 #define GADGET_ID_LEVEL_GEMSLIMIT_TEXT (GADGET_ID_COUNTER_FIRST + 13)
315 #define GADGET_ID_LEVEL_GEMSLIMIT_UP (GADGET_ID_COUNTER_FIRST + 14)
316 #define GADGET_ID_LEVEL_TIMELIMIT_DOWN (GADGET_ID_COUNTER_FIRST + 15)
317 #define GADGET_ID_LEVEL_TIMELIMIT_TEXT (GADGET_ID_COUNTER_FIRST + 16)
318 #define GADGET_ID_LEVEL_TIMELIMIT_UP (GADGET_ID_COUNTER_FIRST + 17)
319 #define GADGET_ID_LEVEL_TIMESCORE_DOWN (GADGET_ID_COUNTER_FIRST + 18)
320 #define GADGET_ID_LEVEL_TIMESCORE_TEXT (GADGET_ID_COUNTER_FIRST + 19)
321 #define GADGET_ID_LEVEL_TIMESCORE_UP (GADGET_ID_COUNTER_FIRST + 20)
322 #define GADGET_ID_ELEMENT_SCORE_DOWN (GADGET_ID_COUNTER_FIRST + 21)
323 #define GADGET_ID_ELEMENT_SCORE_TEXT (GADGET_ID_COUNTER_FIRST + 22)
324 #define GADGET_ID_ELEMENT_SCORE_UP (GADGET_ID_COUNTER_FIRST + 23)
325 #define GADGET_ID_ELEMENT_CONTENT_DOWN (GADGET_ID_COUNTER_FIRST + 24)
326 #define GADGET_ID_ELEMENT_CONTENT_TEXT (GADGET_ID_COUNTER_FIRST + 25)
327 #define GADGET_ID_ELEMENT_CONTENT_UP (GADGET_ID_COUNTER_FIRST + 26)
328 #define GADGET_ID_CUSTOM_SCORE_DOWN (GADGET_ID_COUNTER_FIRST + 27)
329 #define GADGET_ID_CUSTOM_SCORE_TEXT (GADGET_ID_COUNTER_FIRST + 28)
330 #define GADGET_ID_CUSTOM_SCORE_UP (GADGET_ID_COUNTER_FIRST + 29)
331 #define GADGET_ID_CUSTOM_GEMCOUNT_DOWN (GADGET_ID_COUNTER_FIRST + 30)
332 #define GADGET_ID_CUSTOM_GEMCOUNT_TEXT (GADGET_ID_COUNTER_FIRST + 31)
333 #define GADGET_ID_CUSTOM_GEMCOUNT_UP (GADGET_ID_COUNTER_FIRST + 32)
334 #define GADGET_ID_PUSH_DELAY_FIX_DOWN (GADGET_ID_COUNTER_FIRST + 33)
335 #define GADGET_ID_PUSH_DELAY_FIX_TEXT (GADGET_ID_COUNTER_FIRST + 34)
336 #define GADGET_ID_PUSH_DELAY_FIX_UP (GADGET_ID_COUNTER_FIRST + 35)
337 #define GADGET_ID_PUSH_DELAY_RND_DOWN (GADGET_ID_COUNTER_FIRST + 36)
338 #define GADGET_ID_PUSH_DELAY_RND_TEXT (GADGET_ID_COUNTER_FIRST + 37)
339 #define GADGET_ID_PUSH_DELAY_RND_UP (GADGET_ID_COUNTER_FIRST + 38)
340 #define GADGET_ID_MOVE_DELAY_FIX_DOWN (GADGET_ID_COUNTER_FIRST + 39)
341 #define GADGET_ID_MOVE_DELAY_FIX_TEXT (GADGET_ID_COUNTER_FIRST + 40)
342 #define GADGET_ID_MOVE_DELAY_FIX_UP (GADGET_ID_COUNTER_FIRST + 41)
343 #define GADGET_ID_MOVE_DELAY_RND_DOWN (GADGET_ID_COUNTER_FIRST + 42)
344 #define GADGET_ID_MOVE_DELAY_RND_TEXT (GADGET_ID_COUNTER_FIRST + 43)
345 #define GADGET_ID_MOVE_DELAY_RND_UP (GADGET_ID_COUNTER_FIRST + 44)
346 #define GADGET_ID_CHANGE_DELAY_FIX_DOWN (GADGET_ID_COUNTER_FIRST + 45)
347 #define GADGET_ID_CHANGE_DELAY_FIX_TEXT (GADGET_ID_COUNTER_FIRST + 46)
348 #define GADGET_ID_CHANGE_DELAY_FIX_UP (GADGET_ID_COUNTER_FIRST + 47)
349 #define GADGET_ID_CHANGE_DELAY_RND_DOWN (GADGET_ID_COUNTER_FIRST + 48)
350 #define GADGET_ID_CHANGE_DELAY_RND_TEXT (GADGET_ID_COUNTER_FIRST + 49)
351 #define GADGET_ID_CHANGE_DELAY_RND_UP (GADGET_ID_COUNTER_FIRST + 50)
352 #define GADGET_ID_CHANGE_CONT_RND_DOWN (GADGET_ID_COUNTER_FIRST + 51)
353 #define GADGET_ID_CHANGE_CONT_RND_TEXT (GADGET_ID_COUNTER_FIRST + 52)
354 #define GADGET_ID_CHANGE_CONT_RND_UP (GADGET_ID_COUNTER_FIRST + 53)
356 /* drawing area identifiers */
357 #define GADGET_ID_DRAWING_AREA_FIRST (GADGET_ID_COUNTER_FIRST + 54)
359 #define GADGET_ID_DRAWING_LEVEL (GADGET_ID_DRAWING_AREA_FIRST + 0)
360 #define GADGET_ID_ELEMENT_CONTENT_0 (GADGET_ID_DRAWING_AREA_FIRST + 1)
361 #define GADGET_ID_ELEMENT_CONTENT_1 (GADGET_ID_DRAWING_AREA_FIRST + 2)
362 #define GADGET_ID_ELEMENT_CONTENT_2 (GADGET_ID_DRAWING_AREA_FIRST + 3)
363 #define GADGET_ID_ELEMENT_CONTENT_3 (GADGET_ID_DRAWING_AREA_FIRST + 4)
364 #define GADGET_ID_ELEMENT_CONTENT_4 (GADGET_ID_DRAWING_AREA_FIRST + 5)
365 #define GADGET_ID_ELEMENT_CONTENT_5 (GADGET_ID_DRAWING_AREA_FIRST + 6)
366 #define GADGET_ID_ELEMENT_CONTENT_6 (GADGET_ID_DRAWING_AREA_FIRST + 7)
367 #define GADGET_ID_ELEMENT_CONTENT_7 (GADGET_ID_DRAWING_AREA_FIRST + 8)
368 #define GADGET_ID_AMOEBA_CONTENT (GADGET_ID_DRAWING_AREA_FIRST + 9)
369 #define GADGET_ID_CUSTOM_GRAPHIC (GADGET_ID_DRAWING_AREA_FIRST + 10)
370 #define GADGET_ID_CUSTOM_CONTENT (GADGET_ID_DRAWING_AREA_FIRST + 11)
371 #define GADGET_ID_CUSTOM_CHANGE_TARGET (GADGET_ID_DRAWING_AREA_FIRST + 12)
372 #define GADGET_ID_CUSTOM_CHANGE_CONTENT (GADGET_ID_DRAWING_AREA_FIRST + 13)
373 #define GADGET_ID_CUSTOM_CHANGE_TRIGGER (GADGET_ID_DRAWING_AREA_FIRST + 14)
374 #define GADGET_ID_RANDOM_BACKGROUND (GADGET_ID_DRAWING_AREA_FIRST + 15)
376 /* text input identifiers */
377 #define GADGET_ID_TEXT_INPUT_FIRST (GADGET_ID_DRAWING_AREA_FIRST + 16)
379 #define GADGET_ID_LEVEL_NAME (GADGET_ID_TEXT_INPUT_FIRST + 0)
380 #define GADGET_ID_LEVEL_AUTHOR (GADGET_ID_TEXT_INPUT_FIRST + 1)
381 #define GADGET_ID_ELEMENT_NAME (GADGET_ID_TEXT_INPUT_FIRST + 2)
383 /* selectbox identifiers */
384 #define GADGET_ID_SELECTBOX_FIRST (GADGET_ID_TEXT_INPUT_FIRST + 3)
386 #define GADGET_ID_CUSTOM_WALK_TO_ACTION (GADGET_ID_SELECTBOX_FIRST + 0)
387 #define GADGET_ID_CUSTOM_CONSISTENCY (GADGET_ID_SELECTBOX_FIRST + 1)
388 #define GADGET_ID_CUSTOM_DEADLINESS (GADGET_ID_SELECTBOX_FIRST + 2)
389 #define GADGET_ID_CUSTOM_MOVE_PATTERN (GADGET_ID_SELECTBOX_FIRST + 3)
390 #define GADGET_ID_CUSTOM_MOVE_DIRECTION (GADGET_ID_SELECTBOX_FIRST + 4)
391 #define GADGET_ID_CUSTOM_MOVE_STEPSIZE (GADGET_ID_SELECTBOX_FIRST + 5)
392 #define GADGET_ID_CUSTOM_SMASH_TARGETS (GADGET_ID_SELECTBOX_FIRST + 6)
393 #define GADGET_ID_CUSTOM_SLIPPERY_TYPE (GADGET_ID_SELECTBOX_FIRST + 7)
394 #define GADGET_ID_CUSTOM_ACCESS_TYPE (GADGET_ID_SELECTBOX_FIRST + 8)
395 #define GADGET_ID_CUSTOM_ACCESS_LAYER (GADGET_ID_SELECTBOX_FIRST + 9)
396 #define GADGET_ID_CHANGE_TIME_UNITS (GADGET_ID_SELECTBOX_FIRST + 10)
397 #define GADGET_ID_CHANGE_PLAYER_ACTION (GADGET_ID_SELECTBOX_FIRST + 11)
398 #define GADGET_ID_CHANGE_COLLIDE_ACTION (GADGET_ID_SELECTBOX_FIRST + 12)
399 #define GADGET_ID_CHANGE_OTHER_ACTION (GADGET_ID_SELECTBOX_FIRST + 13)
400 #define GADGET_ID_CHANGE_POWER (GADGET_ID_SELECTBOX_FIRST + 14)
402 /* textbutton identifiers */
403 #define GADGET_ID_TEXTBUTTON_FIRST (GADGET_ID_SELECTBOX_FIRST + 15)
405 #define GADGET_ID_PROPERTIES_INFO (GADGET_ID_TEXTBUTTON_FIRST + 0)
406 #define GADGET_ID_PROPERTIES_CONFIG (GADGET_ID_TEXTBUTTON_FIRST + 1)
407 #define GADGET_ID_PROPERTIES_ADVANCED (GADGET_ID_TEXTBUTTON_FIRST + 2)
408 #define GADGET_ID_SAVE_AS_TEMPLATE (GADGET_ID_TEXTBUTTON_FIRST + 3)
410 /* gadgets for scrolling of drawing area */
411 #define GADGET_ID_SCROLLING_FIRST (GADGET_ID_TEXTBUTTON_FIRST + 4)
413 #define GADGET_ID_SCROLL_UP (GADGET_ID_SCROLLING_FIRST + 0)
414 #define GADGET_ID_SCROLL_DOWN (GADGET_ID_SCROLLING_FIRST + 1)
415 #define GADGET_ID_SCROLL_LEFT (GADGET_ID_SCROLLING_FIRST + 2)
416 #define GADGET_ID_SCROLL_RIGHT (GADGET_ID_SCROLLING_FIRST + 3)
417 #define GADGET_ID_SCROLL_HORIZONTAL (GADGET_ID_SCROLLING_FIRST + 4)
418 #define GADGET_ID_SCROLL_VERTICAL (GADGET_ID_SCROLLING_FIRST + 5)
420 /* gadgets for scrolling element list */
421 #define GADGET_ID_SCROLLING_LIST_FIRST (GADGET_ID_SCROLLING_FIRST + 6)
423 #define GADGET_ID_SCROLL_LIST_UP (GADGET_ID_SCROLLING_LIST_FIRST + 0)
424 #define GADGET_ID_SCROLL_LIST_DOWN (GADGET_ID_SCROLLING_LIST_FIRST + 1)
425 #define GADGET_ID_SCROLL_LIST_VERTICAL (GADGET_ID_SCROLLING_LIST_FIRST + 2)
427 /* checkbuttons for level/element properties */
428 #define GADGET_ID_CHECKBUTTON_FIRST (GADGET_ID_SCROLLING_LIST_FIRST + 3)
430 #define GADGET_ID_RANDOM_PERCENTAGE (GADGET_ID_CHECKBUTTON_FIRST + 0)
431 #define GADGET_ID_RANDOM_QUANTITY (GADGET_ID_CHECKBUTTON_FIRST + 1)
432 #define GADGET_ID_RANDOM_RESTRICTED (GADGET_ID_CHECKBUTTON_FIRST + 2)
433 #define GADGET_ID_DOUBLE_SPEED (GADGET_ID_CHECKBUTTON_FIRST + 3)
434 #define GADGET_ID_GRAVITY (GADGET_ID_CHECKBUTTON_FIRST + 4)
435 #define GADGET_ID_STICK_ELEMENT (GADGET_ID_CHECKBUTTON_FIRST + 5)
436 #define GADGET_ID_EM_SLIPPERY_GEMS (GADGET_ID_CHECKBUTTON_FIRST + 6)
437 #define GADGET_ID_CUSTOM_EXPLODE_RESULT (GADGET_ID_CHECKBUTTON_FIRST + 7)
438 #define GADGET_ID_CUSTOM_EXPLODE_FIRE (GADGET_ID_CHECKBUTTON_FIRST + 8)
439 #define GADGET_ID_CUSTOM_EXPLODE_SMASH (GADGET_ID_CHECKBUTTON_FIRST + 9)
440 #define GADGET_ID_CUSTOM_EXPLODE_IMPACT (GADGET_ID_CHECKBUTTON_FIRST + 10)
441 #define GADGET_ID_CUSTOM_WALK_TO_OBJECT (GADGET_ID_CHECKBUTTON_FIRST + 11)
442 #define GADGET_ID_CUSTOM_DEADLY (GADGET_ID_CHECKBUTTON_FIRST + 12)
443 #define GADGET_ID_CUSTOM_CAN_MOVE (GADGET_ID_CHECKBUTTON_FIRST + 13)
444 #define GADGET_ID_CUSTOM_CAN_FALL (GADGET_ID_CHECKBUTTON_FIRST + 14)
445 #define GADGET_ID_CUSTOM_CAN_SMASH (GADGET_ID_CHECKBUTTON_FIRST + 15)
446 #define GADGET_ID_CUSTOM_SLIPPERY (GADGET_ID_CHECKBUTTON_FIRST + 16)
447 #define GADGET_ID_CUSTOM_ACCESSIBLE (GADGET_ID_CHECKBUTTON_FIRST + 17)
448 #define GADGET_ID_CUSTOM_USE_GRAPHIC (GADGET_ID_CHECKBUTTON_FIRST + 18)
449 #define GADGET_ID_CUSTOM_USE_TEMPLATE (GADGET_ID_CHECKBUTTON_FIRST + 19)
450 #define GADGET_ID_CUSTOM_CAN_CHANGE (GADGET_ID_CHECKBUTTON_FIRST + 20)
451 #define GADGET_ID_CHANGE_USE_CONTENT (GADGET_ID_CHECKBUTTON_FIRST + 21)
452 #define GADGET_ID_CHANGE_USE_EXPLOSION (GADGET_ID_CHECKBUTTON_FIRST + 22)
453 #define GADGET_ID_CHANGE_ONLY_COMPLETE (GADGET_ID_CHECKBUTTON_FIRST + 23)
454 #define GADGET_ID_CHANGE_USE_RANDOM (GADGET_ID_CHECKBUTTON_FIRST + 24)
455 #define GADGET_ID_CHANGE_DELAY (GADGET_ID_CHECKBUTTON_FIRST + 25)
456 #define GADGET_ID_CHANGE_BY_PLAYER (GADGET_ID_CHECKBUTTON_FIRST + 26)
457 #define GADGET_ID_CHANGE_BY_COLLISION (GADGET_ID_CHECKBUTTON_FIRST + 27)
458 #define GADGET_ID_CHANGE_BY_OTHER (GADGET_ID_CHECKBUTTON_FIRST + 28)
460 /* gadgets for buttons in element list */
461 #define GADGET_ID_ELEMENTLIST_FIRST (GADGET_ID_CHECKBUTTON_FIRST + 29)
462 #define GADGET_ID_ELEMENTLIST_LAST (GADGET_ID_ELEMENTLIST_FIRST + \
463 ED_NUM_ELEMENTLIST_BUTTONS - 1)
465 #define NUM_EDITOR_GADGETS (GADGET_ID_ELEMENTLIST_LAST + 1)
467 /* radio button numbers */
468 #define RADIO_NR_NONE 0
469 #define RADIO_NR_DRAWING_TOOLBOX 1
470 #define RADIO_NR_RANDOM_ELEMENTS 2
472 /* values for counter gadgets */
473 #define ED_COUNTER_ID_SELECT_LEVEL 0
474 #define ED_COUNTER_ID_LEVEL_XSIZE 1
475 #define ED_COUNTER_ID_LEVEL_YSIZE 2
476 #define ED_COUNTER_ID_LEVEL_GEMSLIMIT 3
477 #define ED_COUNTER_ID_LEVEL_TIMELIMIT 4
478 #define ED_COUNTER_ID_LEVEL_TIMESCORE 5
479 #define ED_COUNTER_ID_LEVEL_RANDOM 6
480 #define ED_COUNTER_ID_ELEMENT_SCORE 7
481 #define ED_COUNTER_ID_ELEMENT_CONTENT 8
482 #define ED_COUNTER_ID_CUSTOM_SCORE 9
483 #define ED_COUNTER_ID_CUSTOM_GEMCOUNT 10
484 #define ED_COUNTER_ID_PUSH_DELAY_FIX 11
485 #define ED_COUNTER_ID_PUSH_DELAY_RND 12
486 #define ED_COUNTER_ID_MOVE_DELAY_FIX 13
487 #define ED_COUNTER_ID_MOVE_DELAY_RND 14
488 #define ED_COUNTER_ID_CHANGE_DELAY_FIX 15
489 #define ED_COUNTER_ID_CHANGE_DELAY_RND 16
490 #define ED_COUNTER_ID_CHANGE_CONT_RND 17
492 #define ED_NUM_COUNTERBUTTONS 18
494 #define ED_COUNTER_ID_LEVEL_FIRST ED_COUNTER_ID_LEVEL_XSIZE
495 #define ED_COUNTER_ID_LEVEL_LAST ED_COUNTER_ID_LEVEL_RANDOM
497 #define ED_COUNTER_ID_CUSTOM_FIRST ED_COUNTER_ID_CUSTOM_SCORE
498 #define ED_COUNTER_ID_CUSTOM_LAST ED_COUNTER_ID_MOVE_DELAY_RND
500 #define ED_COUNTER_ID_CHANGE_FIRST ED_COUNTER_ID_CHANGE_DELAY_FIX
501 #define ED_COUNTER_ID_CHANGE_LAST ED_COUNTER_ID_CHANGE_CONT_RND
503 /* values for scrollbutton gadgets */
504 #define ED_SCROLLBUTTON_ID_AREA_UP 0
505 #define ED_SCROLLBUTTON_ID_AREA_DOWN 1
506 #define ED_SCROLLBUTTON_ID_AREA_LEFT 2
507 #define ED_SCROLLBUTTON_ID_AREA_RIGHT 3
508 #define ED_SCROLLBUTTON_ID_LIST_UP 4
509 #define ED_SCROLLBUTTON_ID_LIST_DOWN 5
511 #define ED_NUM_SCROLLBUTTONS 6
513 #define ED_SCROLLBUTTON_ID_AREA_FIRST ED_SCROLLBUTTON_ID_AREA_UP
514 #define ED_SCROLLBUTTON_ID_AREA_LAST ED_SCROLLBUTTON_ID_AREA_RIGHT
516 /* values for scrollbar gadgets */
517 #define ED_SCROLLBAR_ID_AREA_HORIZONTAL 0
518 #define ED_SCROLLBAR_ID_AREA_VERTICAL 1
519 #define ED_SCROLLBAR_ID_LIST_VERTICAL 2
521 #define ED_NUM_SCROLLBARS 3
523 #define ED_SCROLLBAR_ID_AREA_FIRST ED_SCROLLBAR_ID_AREA_HORIZONTAL
524 #define ED_SCROLLBAR_ID_AREA_LAST ED_SCROLLBAR_ID_AREA_VERTICAL
526 /* values for text input gadgets */
527 #define ED_TEXTINPUT_ID_LEVEL_NAME 0
528 #define ED_TEXTINPUT_ID_LEVEL_AUTHOR 1
529 #define ED_TEXTINPUT_ID_ELEMENT_NAME 2
531 #define ED_NUM_TEXTINPUT 3
533 #define ED_TEXTINPUT_ID_LEVEL_FIRST ED_TEXTINPUT_ID_LEVEL_NAME
534 #define ED_TEXTINPUT_ID_LEVEL_LAST ED_TEXTINPUT_ID_LEVEL_AUTHOR
536 /* values for selectbox gadgets */
537 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE 0
538 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_LAYER 1
539 #define ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION 2
540 #define ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN 3
541 #define ED_SELECTBOX_ID_CUSTOM_MOVE_DIRECTION 4
542 #define ED_SELECTBOX_ID_CUSTOM_MOVE_STEPSIZE 5
543 #define ED_SELECTBOX_ID_CUSTOM_SMASH_TARGETS 6
544 #define ED_SELECTBOX_ID_CUSTOM_SLIPPERY_TYPE 7
545 #define ED_SELECTBOX_ID_CUSTOM_DEADLINESS 8
546 #define ED_SELECTBOX_ID_CUSTOM_CONSISTENCY 9
547 #define ED_SELECTBOX_ID_CHANGE_TIME_UNITS 10
548 #define ED_SELECTBOX_ID_CHANGE_PLAYER_ACTION 11
549 #define ED_SELECTBOX_ID_CHANGE_COLLIDE_ACTION 12
550 #define ED_SELECTBOX_ID_CHANGE_OTHER_ACTION 13
551 #define ED_SELECTBOX_ID_CHANGE_POWER 14
553 #define ED_NUM_SELECTBOX 15
555 #define ED_SELECTBOX_ID_CUSTOM_FIRST ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE
556 #define ED_SELECTBOX_ID_CUSTOM_LAST ED_SELECTBOX_ID_CUSTOM_CONSISTENCY
558 #define ED_SELECTBOX_ID_CHANGE_FIRST ED_SELECTBOX_ID_CHANGE_TIME_UNITS
559 #define ED_SELECTBOX_ID_CHANGE_LAST ED_SELECTBOX_ID_CHANGE_POWER
561 /* values for textbutton gadgets */
562 #define ED_TEXTBUTTON_ID_PROPERTIES_INFO 0
563 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG 1
564 #define ED_TEXTBUTTON_ID_PROPERTIES_ADVANCED 2
565 #define ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE 3
567 #define ED_NUM_TEXTBUTTON 4
569 /* values for checkbutton gadgets */
570 #define ED_CHECKBUTTON_ID_DOUBLE_SPEED 0
571 #define ED_CHECKBUTTON_ID_GRAVITY 1
572 #define ED_CHECKBUTTON_ID_RANDOM_RESTRICTED 2
573 #define ED_CHECKBUTTON_ID_STICK_ELEMENT 3
574 #define ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS 4
575 #define ED_CHECKBUTTON_ID_CUSTOM_ACCESSIBLE 5
576 #define ED_CHECKBUTTON_ID_CUSTOM_WALK_TO_OBJECT 6
577 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE 7
578 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_FALL 8
579 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_SMASH 9
580 #define ED_CHECKBUTTON_ID_CUSTOM_SLIPPERY 10
581 #define ED_CHECKBUTTON_ID_CUSTOM_DEADLY 11
582 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_RESULT 12
583 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_FIRE 13
584 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_SMASH 14
585 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT 15
586 #define ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC 16
587 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE 17
588 #define ED_CHECKBUTTON_ID_CHANGE_DELAY 18
589 #define ED_CHECKBUTTON_ID_CHANGE_BY_PLAYER 19
590 #define ED_CHECKBUTTON_ID_CHANGE_BY_COLLISION 20
591 #define ED_CHECKBUTTON_ID_CHANGE_BY_OTHER 21
592 #define ED_CHECKBUTTON_ID_CHANGE_USE_EXPLOSION 22
593 #define ED_CHECKBUTTON_ID_CHANGE_USE_CONTENT 23
594 #define ED_CHECKBUTTON_ID_CHANGE_ONLY_COMPLETE 24
595 #define ED_CHECKBUTTON_ID_CHANGE_USE_RANDOM 25
596 #define ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE 26
598 #define ED_NUM_CHECKBUTTONS 27
600 #define ED_CHECKBUTTON_ID_LEVEL_FIRST ED_CHECKBUTTON_ID_DOUBLE_SPEED
601 #define ED_CHECKBUTTON_ID_LEVEL_LAST ED_CHECKBUTTON_ID_RANDOM_RESTRICTED
603 #define ED_CHECKBUTTON_ID_CUSTOM_FIRST ED_CHECKBUTTON_ID_CUSTOM_ACCESSIBLE
604 #define ED_CHECKBUTTON_ID_CUSTOM_LAST ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT
606 #define ED_CHECKBUTTON_ID_CHANGE_FIRST ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC
607 #define ED_CHECKBUTTON_ID_CHANGE_LAST ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE
609 /* values for radiobutton gadgets */
610 #define ED_RADIOBUTTON_ID_PERCENTAGE 0
611 #define ED_RADIOBUTTON_ID_QUANTITY 1
613 #define ED_NUM_RADIOBUTTONS 2
615 #define ED_RADIOBUTTON_ID_LEVEL_FIRST ED_RADIOBUTTON_ID_PERCENTAGE
616 #define ED_RADIOBUTTON_ID_LEVEL_LAST ED_RADIOBUTTON_ID_QUANTITY
618 /* values for drawing area gadgets */
619 #define ED_DRAWING_ID_DRAWING_LEVEL 0
620 #define ED_DRAWING_ID_ELEMENT_CONTENT_0 1
621 #define ED_DRAWING_ID_ELEMENT_CONTENT_1 2
622 #define ED_DRAWING_ID_ELEMENT_CONTENT_2 3
623 #define ED_DRAWING_ID_ELEMENT_CONTENT_3 4
624 #define ED_DRAWING_ID_ELEMENT_CONTENT_4 5
625 #define ED_DRAWING_ID_ELEMENT_CONTENT_5 6
626 #define ED_DRAWING_ID_ELEMENT_CONTENT_6 7
627 #define ED_DRAWING_ID_ELEMENT_CONTENT_7 8
628 #define ED_DRAWING_ID_AMOEBA_CONTENT 9
629 #define ED_DRAWING_ID_CUSTOM_GRAPHIC 10
630 #define ED_DRAWING_ID_CUSTOM_CONTENT 11
631 #define ED_DRAWING_ID_CUSTOM_CHANGE_TARGET 12
632 #define ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT 13
633 #define ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER 14
634 #define ED_DRAWING_ID_RANDOM_BACKGROUND 15
636 #define ED_NUM_DRAWING_AREAS 16
640 -----------------------------------------------------------------------------
641 some internally used definitions
642 -----------------------------------------------------------------------------
645 /* values for CopyLevelToUndoBuffer() */
646 #define UNDO_IMMEDIATE 0
647 #define UNDO_ACCUMULATE 1
649 /* values for scrollbars */
650 #define ED_SCROLL_NO 0
651 #define ED_SCROLL_LEFT 1
652 #define ED_SCROLL_RIGHT 2
653 #define ED_SCROLL_UP 4
654 #define ED_SCROLL_DOWN 8
656 /* screens in the level editor */
657 #define ED_MODE_DRAWING 0
658 #define ED_MODE_INFO 1
659 #define ED_MODE_PROPERTIES 2
661 /* sub-screens in the element properties section */
662 #define ED_MODE_PROPERTIES_INFO ED_TEXTBUTTON_ID_PROPERTIES_INFO
663 #define ED_MODE_PROPERTIES_CONFIG ED_TEXTBUTTON_ID_PROPERTIES_CONFIG
664 #define ED_MODE_PROPERTIES_ADVANCED ED_TEXTBUTTON_ID_PROPERTIES_ADVANCED
666 /* how many steps can be cancelled */
667 #define NUM_UNDO_STEPS (10 + 1)
669 /* values for elements with score for certain actions */
671 #define MAX_SCORE 255
673 /* values for elements with count for collecting */
674 #define MIN_COLLECT_COUNT 0
675 #define MAX_COLLECT_COUNT 100
677 /* values for random placement */
678 #define RANDOM_USE_PERCENTAGE 0
679 #define RANDOM_USE_QUANTITY 1
681 /* maximal size of level editor drawing area */
682 #define MAX_ED_FIELDX (2 * SCR_FIELDX)
683 #define MAX_ED_FIELDY (2 * SCR_FIELDY - 1)
687 -----------------------------------------------------------------------------
688 some internally used data structure definitions
689 -----------------------------------------------------------------------------
696 } control_info[ED_NUM_CTRL_BUTTONS] =
698 { 's', "draw single items" },
699 { 'd', "draw connected items" },
700 { 'l', "draw lines" },
701 { 'a', "draw arcs" },
702 { 'r', "draw outline rectangles" },
703 { 'R', "draw filled rectangles" },
704 { '\0', "wrap (rotate) level up" },
705 { 't', "enter text elements" },
706 { 'f', "flood fill" },
707 { '\0', "wrap (rotate) level left" },
708 { '?', "properties of drawing element" },
709 { '\0', "wrap (rotate) level right" },
710 { '\0', "random element placement" },
711 { 'b', "grab brush" },
712 { '\0', "wrap (rotate) level down" },
713 { ',', "pick drawing element" },
714 { 'U', "undo last operation" },
715 { 'I', "level properties" },
716 { 'S', "save level" },
717 { 'C', "clear level" },
718 { 'T', "test level" },
719 { 'E', "exit level editor" }
722 static int random_placement_value = 10;
723 static int random_placement_method = RANDOM_USE_QUANTITY;
724 static int random_placement_background_element = EL_SAND;
725 static boolean random_placement_background_restricted = FALSE;
726 static boolean stick_element_properties_window = FALSE;
727 static boolean custom_element_properties[NUM_ELEMENT_PROPERTIES];
728 static boolean custom_element_change_events[NUM_CHANGE_EVENTS];
729 static struct ElementInfo custom_element;
734 int min_value, max_value;
735 int gadget_id_down, gadget_id_up;
739 char *text_above, *text_left, *text_right;
740 } counterbutton_info[ED_NUM_COUNTERBUTTONS] =
742 /* ---------- level and editor settings ---------------------------------- */
745 DX + 5 - SX, DY + 3 - SY,
747 GADGET_ID_SELECT_LEVEL_DOWN, GADGET_ID_SELECT_LEVEL_UP,
748 GADGET_ID_SELECT_LEVEL_TEXT, GADGET_ID_NONE,
753 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(2),
754 MIN_LEV_FIELDX, MAX_LEV_FIELDX,
755 GADGET_ID_LEVEL_XSIZE_DOWN, GADGET_ID_LEVEL_XSIZE_UP,
756 GADGET_ID_LEVEL_XSIZE_TEXT, GADGET_ID_NONE,
758 "playfield size:", NULL, "width",
761 ED_SETTINGS_XPOS(0) + 2 * DXSIZE, ED_COUNTER_YPOS(2),
762 MIN_LEV_FIELDY, MAX_LEV_FIELDY,
763 GADGET_ID_LEVEL_YSIZE_DOWN, GADGET_ID_LEVEL_YSIZE_UP,
764 GADGET_ID_LEVEL_YSIZE_TEXT, GADGET_ID_LEVEL_XSIZE_UP,
769 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(3),
771 GADGET_ID_LEVEL_GEMSLIMIT_DOWN, GADGET_ID_LEVEL_GEMSLIMIT_UP,
772 GADGET_ID_LEVEL_GEMSLIMIT_TEXT, GADGET_ID_NONE,
774 "number of emeralds to collect:", NULL, NULL
777 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(4),
779 GADGET_ID_LEVEL_TIMELIMIT_DOWN, GADGET_ID_LEVEL_TIMELIMIT_UP,
780 GADGET_ID_LEVEL_TIMELIMIT_TEXT, GADGET_ID_NONE,
782 "time available to solve level:", NULL, "(0 => no time limit)"
785 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(5),
787 GADGET_ID_LEVEL_TIMESCORE_DOWN, GADGET_ID_LEVEL_TIMESCORE_UP,
788 GADGET_ID_LEVEL_TIMESCORE_TEXT, GADGET_ID_NONE,
789 &level.score[SC_TIME_BONUS],
790 "score for each 10 seconds left:", NULL, NULL
793 ED_SETTINGS_XPOS(0), ED_COUNTER2_YPOS(8),
795 GADGET_ID_LEVEL_RANDOM_DOWN, GADGET_ID_LEVEL_RANDOM_UP,
796 GADGET_ID_LEVEL_RANDOM_TEXT, GADGET_ID_NONE,
797 &random_placement_value,
798 "random element placement:", NULL, "in"
801 /* ---------- element settings: configure (various elements) ------------- */
804 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(0),
805 MIN_SCORE, MAX_SCORE,
806 GADGET_ID_ELEMENT_SCORE_DOWN, GADGET_ID_ELEMENT_SCORE_UP,
807 GADGET_ID_ELEMENT_SCORE_TEXT, GADGET_ID_NONE,
808 NULL, /* will be set when used */
812 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(6),
813 MIN_ELEMENT_CONTENTS, MAX_ELEMENT_CONTENTS,
814 GADGET_ID_ELEMENT_CONTENT_DOWN, GADGET_ID_ELEMENT_CONTENT_UP,
815 GADGET_ID_ELEMENT_CONTENT_TEXT, GADGET_ID_NONE,
816 &level.num_yamyam_contents,
817 NULL, NULL, "number of content areas"
820 /* ---------- element settings: configure (custom elements) ------------- */
823 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(3),
824 MIN_SCORE, MAX_SCORE,
825 GADGET_ID_CUSTOM_SCORE_DOWN, GADGET_ID_CUSTOM_SCORE_UP,
826 GADGET_ID_CUSTOM_SCORE_TEXT, GADGET_ID_NONE,
827 &custom_element.collect_score,
831 ED_SETTINGS_XPOS(13) + 10, ED_SETTINGS_YPOS(3),
832 MIN_COLLECT_COUNT, MAX_COLLECT_COUNT,
833 GADGET_ID_CUSTOM_GEMCOUNT_DOWN, GADGET_ID_CUSTOM_GEMCOUNT_UP,
834 GADGET_ID_CUSTOM_GEMCOUNT_TEXT, GADGET_ID_CUSTOM_SCORE_UP,
835 &custom_element.collect_count,
839 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(4),
841 GADGET_ID_PUSH_DELAY_FIX_DOWN, GADGET_ID_PUSH_DELAY_FIX_UP,
842 GADGET_ID_PUSH_DELAY_FIX_TEXT, GADGET_ID_NONE,
843 &custom_element.push_delay_fixed,
844 NULL, "push delay", NULL
847 ED_COUNT_PUSH_DELAY_RND_XPOS, ED_SETTINGS_YPOS(4),
849 GADGET_ID_PUSH_DELAY_RND_DOWN, GADGET_ID_PUSH_DELAY_RND_UP,
850 GADGET_ID_PUSH_DELAY_RND_TEXT, GADGET_ID_PUSH_DELAY_FIX_UP,
851 &custom_element.push_delay_random,
852 NULL, "+random", NULL
855 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(7),
857 GADGET_ID_MOVE_DELAY_FIX_DOWN, GADGET_ID_MOVE_DELAY_FIX_UP,
858 GADGET_ID_MOVE_DELAY_FIX_TEXT, GADGET_ID_NONE,
859 &custom_element.move_delay_fixed,
860 NULL, "move delay", NULL
863 ED_COUNT_MOVE_DELAY_RND_XPOS, ED_SETTINGS_YPOS(7),
865 GADGET_ID_MOVE_DELAY_RND_DOWN, GADGET_ID_MOVE_DELAY_RND_UP,
866 GADGET_ID_MOVE_DELAY_RND_TEXT, GADGET_ID_MOVE_DELAY_FIX_UP,
867 &custom_element.move_delay_random,
868 NULL, "+random", NULL
871 /* ---------- element settings: advanced (custom elements) --------------- */
874 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(3),
876 GADGET_ID_CHANGE_DELAY_FIX_DOWN, GADGET_ID_CHANGE_DELAY_FIX_UP,
877 GADGET_ID_CHANGE_DELAY_FIX_TEXT, GADGET_ID_NONE,
878 &custom_element.change.delay_fixed,
882 ED_COUNT_CHANGE_DELAY_RND_XPOS+20, ED_SETTINGS_YPOS(3),
884 GADGET_ID_CHANGE_DELAY_RND_DOWN, GADGET_ID_CHANGE_DELAY_RND_UP,
885 GADGET_ID_CHANGE_DELAY_RND_TEXT, GADGET_ID_CHANGE_DELAY_FIX_UP,
886 &custom_element.change.delay_random,
887 NULL, "+random", NULL
890 ED_SETTINGS_XPOS(3), ED_SETTINGS_YPOS(12),
892 GADGET_ID_CHANGE_CONT_RND_DOWN, GADGET_ID_CHANGE_CONT_RND_UP,
893 GADGET_ID_CHANGE_CONT_RND_TEXT, GADGET_ID_NONE,
894 &custom_element.change.random,
895 NULL, "use random change:", "(%)"
906 } textinput_info[ED_NUM_TEXTINPUT] =
909 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(0),
910 GADGET_ID_LEVEL_NAME,
916 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(1),
917 GADGET_ID_LEVEL_AUTHOR,
918 MAX_LEVEL_AUTHOR_LEN,
923 5 * MINI_TILEX, 5 * MINI_TILEY - ED_BORDER_SIZE,
924 GADGET_ID_ELEMENT_NAME,
925 MAX_ELEMENT_NAME_LEN - 2, /* currently 2 chars less editable */
926 custom_element.description,
931 static struct ValueTextInfo options_access_type[] =
933 { EP_WALKABLE, "walk" },
934 { EP_PASSABLE, "pass" },
938 static struct ValueTextInfo options_access_layer[] =
940 { EP_ACCESSIBLE_OVER, "over" },
941 { EP_ACCESSIBLE_INSIDE, "inside" },
942 { EP_ACCESSIBLE_UNDER, "under" },
946 static struct ValueTextInfo options_walk_to_action[] =
948 { EP_DIGGABLE, "diggable" },
949 { EP_COLLECTIBLE_ONLY, "collectible" },
950 { EP_DROPPABLE, "collectible & droppable" },
951 { EP_PUSHABLE, "pushable" },
955 static struct ValueTextInfo options_move_pattern[] =
958 { MV_RIGHT, "right" },
961 { MV_HORIZONTAL, "horizontal" },
962 { MV_VERTICAL, "vertical" },
963 { MV_ALL_DIRECTIONS, "all directions" },
964 { MV_TOWARDS_PLAYER, "towards player" },
965 { MV_AWAY_FROM_PLAYER, "away from player" },
966 { MV_ALONG_LEFT_SIDE, "along left side" },
967 { MV_ALONG_RIGHT_SIDE, "along right side" },
968 { MV_TURNING_LEFT, "turning left" },
969 { MV_TURNING_RIGHT, "turning right" },
973 static struct ValueTextInfo options_move_direction[] =
975 { MV_NO_MOVING, "automatic" },
977 { MV_RIGHT, "right" },
983 static struct ValueTextInfo options_move_stepsize[] =
993 static struct ValueTextInfo options_smash_targets[] =
995 { EP_CAN_SMASH_PLAYER, "player" },
997 { EP_CAN_SMASH_ENEMIES, "enemies" },
999 { EP_CAN_SMASH_EVERYTHING, "everything" },
1003 static struct ValueTextInfo options_slippery_type[] =
1005 { SLIPPERY_ANY_RANDOM, "random" },
1006 { SLIPPERY_ANY_LEFT_RIGHT, "left, right" },
1007 { SLIPPERY_ANY_RIGHT_LEFT, "right, left" },
1008 { SLIPPERY_ONLY_LEFT, "only left" },
1009 { SLIPPERY_ONLY_RIGHT, "only right" },
1013 static struct ValueTextInfo options_deadliness[] =
1015 { EP_DONT_RUN_INTO, "running into" },
1016 { EP_DONT_COLLIDE_WITH, "colliding with" },
1017 { EP_DONT_TOUCH, "touching" },
1021 static struct ValueTextInfo options_consistency[] =
1023 { EP_CAN_EXPLODE_3X3, "can explode 3x3" },
1024 { EP_CAN_EXPLODE_1X1, "can explode 1x1" },
1025 { EP_INDESTRUCTIBLE, "indestructible" },
1029 static struct ValueTextInfo options_time_units[] =
1036 static struct ValueTextInfo options_change_player_action[] =
1038 { CE_TOUCHED_BY_PLAYER, "touched" },
1039 { CE_PRESSED_BY_PLAYER, "pressed" },
1040 { CE_PUSHED_BY_PLAYER, "pushed" },
1041 { CE_DROPPED_BY_PLAYER, "dropped" },
1045 static struct ValueTextInfo options_change_collide_action[] =
1047 { CE_COLLISION, "on collision" },
1048 { CE_IMPACT, "on impact" },
1049 { CE_SMASHED, "when smashed" },
1053 static struct ValueTextInfo options_change_other_action[] =
1055 { CE_OTHER_IS_TOUCHING, "touching" },
1056 { CE_OTHER_IS_CHANGING, "change of" },
1057 { CE_OTHER_IS_EXPLODING, "explosion of" },
1058 { CE_OTHER_GETS_TOUCHED, "player touches" },
1059 { CE_OTHER_GETS_PRESSED, "player presses" },
1060 { CE_OTHER_GETS_PUSHED, "player pushes" },
1061 { CE_OTHER_GETS_COLLECTED, "player collects" },
1062 { CE_OTHER_GETS_DROPPED, "player drops" },
1066 static struct ValueTextInfo options_change_power[] =
1068 { CP_NON_DESTRUCTIVE, "non-destructive" },
1069 { CP_HALF_DESTRUCTIVE, "half-destructive" },
1070 { CP_FULL_DESTRUCTIVE, "full-destructive" },
1078 int gadget_id_align;
1079 int size; /* char size of selectbox or '-1' (dynamically determined) */
1080 struct ValueTextInfo *options;
1082 char *text_left, *text_right, *infotext;
1083 } selectbox_info[ED_NUM_SELECTBOX] =
1085 /* ---------- element settings: configure (custom elements) ------------- */
1088 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(1),
1089 GADGET_ID_CUSTOM_ACCESS_TYPE, GADGET_ID_NONE,
1091 options_access_type,
1092 &custom_element.access_type,
1093 "player can", NULL, "type of access to this field"
1096 ED_SETTINGS_XPOS(11), ED_SETTINGS_YPOS(1),
1097 GADGET_ID_CUSTOM_ACCESS_LAYER, GADGET_ID_CUSTOM_ACCESS_TYPE,
1099 options_access_layer,
1100 &custom_element.access_layer,
1101 NULL, NULL, "layer of access for this field"
1104 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(2),
1105 GADGET_ID_CUSTOM_WALK_TO_ACTION, GADGET_ID_NONE,
1107 options_walk_to_action,
1108 &custom_element.walk_to_action,
1109 NULL, NULL, "diggable/collectible/pushable"
1112 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(5),
1113 GADGET_ID_CUSTOM_MOVE_PATTERN, GADGET_ID_NONE,
1115 options_move_pattern,
1116 &custom_element.move_pattern,
1117 "can move", NULL, "element move direction"
1120 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(6),
1121 GADGET_ID_CUSTOM_MOVE_DIRECTION, GADGET_ID_NONE,
1123 options_move_direction,
1124 &custom_element.move_direction_initial,
1125 "starts moving", NULL, "initial element move direction"
1128 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(8),
1129 GADGET_ID_CUSTOM_MOVE_STEPSIZE, GADGET_ID_NONE,
1131 options_move_stepsize,
1132 &custom_element.move_stepsize,
1133 "move/fall speed", NULL, "speed of element movement"
1136 ED_SETTINGS_XPOS(7), ED_SETTINGS_YPOS(9),
1137 GADGET_ID_CUSTOM_SMASH_TARGETS, GADGET_ID_CUSTOM_CAN_SMASH,
1139 options_smash_targets,
1140 &custom_element.smash_targets,
1141 "can smash", NULL, "elements that can be smashed"
1144 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(10),
1145 GADGET_ID_CUSTOM_SLIPPERY_TYPE, GADGET_ID_NONE,
1147 options_slippery_type,
1148 &custom_element.slippery_type,
1149 "slippery", NULL, "where other elements fall down"
1152 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(11),
1153 GADGET_ID_CUSTOM_DEADLINESS, GADGET_ID_NONE,
1156 &custom_element.deadliness,
1157 "deadly when", NULL, "deadliness of element"
1160 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(12),
1161 GADGET_ID_CUSTOM_CONSISTENCY, GADGET_ID_NONE,
1163 options_consistency,
1164 &custom_element.consistency,
1165 NULL, NULL, "consistency/destructibility"
1168 /* ---------- element settings: advanced (custom elements) --------------- */
1171 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(4),
1172 GADGET_ID_CHANGE_TIME_UNITS, GADGET_ID_NONE,
1175 &custom_element.change.delay_frames,
1176 "delay time given in", NULL, "delay time units for change"
1179 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(5),
1180 GADGET_ID_CHANGE_PLAYER_ACTION, GADGET_ID_NONE,
1182 options_change_player_action,
1183 &custom_element.change_player_action,
1184 NULL, "by player", "type of player contact"
1187 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(6),
1188 GADGET_ID_CHANGE_COLLIDE_ACTION, GADGET_ID_NONE,
1190 options_change_collide_action,
1191 &custom_element.change_collide_action,
1192 NULL, NULL, "change after impact or smash"
1195 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(7),
1196 GADGET_ID_CHANGE_OTHER_ACTION, GADGET_ID_NONE,
1198 options_change_other_action,
1199 &custom_element.change_other_action,
1200 NULL, "element:", "type of other element action"
1203 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(10),
1204 GADGET_ID_CHANGE_POWER, GADGET_ID_NONE,
1206 options_change_power,
1207 &custom_element.change.power,
1208 "power:", NULL, "power of extended change"
1216 int gadget_id_align;
1218 char *text, *infotext;
1219 } textbutton_info[ED_NUM_TEXTBUTTON] =
1222 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(1),
1223 GADGET_ID_PROPERTIES_INFO, GADGET_ID_NONE,
1224 11, "Information", "Show information about element"
1227 ED_SETTINGS_XPOS(0) + 166, ED_COUNTER_YPOS(1),
1228 GADGET_ID_PROPERTIES_CONFIG, GADGET_ID_NONE,
1229 11, "Configure", "Configure element properties"
1232 ED_SETTINGS_XPOS(0) + 332, ED_COUNTER_YPOS(1),
1233 GADGET_ID_PROPERTIES_ADVANCED, GADGET_ID_NONE,
1234 11, "Advanced", "Advanced element configuration"
1237 ED_SETTINGS_XPOS(0) + 262, ED_SETTINGS_YPOS(13),
1238 GADGET_ID_SAVE_AS_TEMPLATE, GADGET_ID_CUSTOM_USE_TEMPLATE,
1239 -1, "Save as template", "Save current settings as new template"
1249 } scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
1252 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE,
1253 ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS,
1254 GADGET_ID_SCROLL_UP,
1255 "scroll level editing area up"
1258 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE,
1259 ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS,
1260 GADGET_ID_SCROLL_DOWN,
1261 "scroll level editing area down"
1264 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE,
1265 ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS,
1266 GADGET_ID_SCROLL_LEFT,
1267 "scroll level editing area left"
1270 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE,
1271 ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS,
1272 GADGET_ID_SCROLL_RIGHT,
1273 "scroll level editing area right"
1276 ED_SCROLLBUTTON2_XPOS, ED_SCROLLBUTTON2_YPOS + 0 * ED_SCROLLBUTTON2_YSIZE,
1277 ED_SCROLL2_UP_XPOS, ED_SCROLL2_UP_YPOS,
1278 GADGET_ID_SCROLL_LIST_UP,
1279 "scroll element list up ('Page Up')"
1282 ED_SCROLLBUTTON2_XPOS, ED_SCROLLBUTTON2_YPOS + 1 * ED_SCROLLBUTTON2_YSIZE,
1283 ED_SCROLL2_DOWN_XPOS, ED_SCROLL2_DOWN_YPOS,
1284 GADGET_ID_SCROLL_LIST_DOWN,
1285 "scroll element list down ('Page Down')"
1297 } scrollbar_info[ED_NUM_SCROLLBARS] =
1300 ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
1301 SX + ED_SCROLL_HORIZONTAL_XPOS, SY + ED_SCROLL_HORIZONTAL_YPOS,
1302 ED_SCROLL_HORIZONTAL_XSIZE, ED_SCROLL_HORIZONTAL_YSIZE,
1303 GD_TYPE_SCROLLBAR_HORIZONTAL,
1304 GADGET_ID_SCROLL_HORIZONTAL,
1305 "scroll level editing area horizontally"
1308 ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
1309 SX + ED_SCROLL_VERTICAL_XPOS, SY + ED_SCROLL_VERTICAL_YPOS,
1310 ED_SCROLL_VERTICAL_XSIZE, ED_SCROLL_VERTICAL_YSIZE,
1311 GD_TYPE_SCROLLBAR_VERTICAL,
1312 GADGET_ID_SCROLL_VERTICAL,
1313 "scroll level editing area vertically"
1316 ED_SCROLLBAR2_XPOS, ED_SCROLLBAR2_YPOS,
1317 DX + ED_SCROLL2_VERTICAL_XPOS, DY + ED_SCROLL2_VERTICAL_YPOS,
1318 ED_SCROLL2_VERTICAL_XSIZE, ED_SCROLL2_VERTICAL_YSIZE,
1319 GD_TYPE_SCROLLBAR_VERTICAL,
1320 GADGET_ID_SCROLL_LIST_VERTICAL,
1321 "scroll element list vertically"
1329 int gadget_id_align;
1330 int radio_button_nr;
1333 char *text_left, *text_right, *infotext;
1334 } radiobutton_info[ED_NUM_RADIOBUTTONS] =
1337 ED_SETTINGS_XPOS(0) + 160, ED_COUNTER2_YPOS(8),
1338 GADGET_ID_RANDOM_PERCENTAGE, GADGET_ID_LEVEL_RANDOM_UP,
1339 RADIO_NR_RANDOM_ELEMENTS,
1340 &random_placement_method, RANDOM_USE_PERCENTAGE,
1341 " ", "percentage", "use percentage for random elements"
1344 ED_SETTINGS_XPOS(0) + 340, ED_COUNTER2_YPOS(8),
1345 GADGET_ID_RANDOM_QUANTITY, GADGET_ID_RANDOM_PERCENTAGE,
1346 RADIO_NR_RANDOM_ELEMENTS,
1347 &random_placement_method, RANDOM_USE_QUANTITY,
1348 " ", "quantity", "use quantity for random elements"
1356 int gadget_id_align;
1358 char *text_left, *text_right, *infotext;
1359 } checkbutton_info[ED_NUM_CHECKBUTTONS] =
1361 /* ---------- level and editor settings ---------------------------------- */
1364 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(6) - MINI_TILEY,
1365 GADGET_ID_DOUBLE_SPEED, GADGET_ID_NONE,
1366 &level.double_speed,
1367 NULL, "double speed movement", "set movement speed of player"
1370 ED_SETTINGS_XPOS(0) + 340, ED_COUNTER_YPOS(6) - MINI_TILEY,
1371 GADGET_ID_GRAVITY, GADGET_ID_DOUBLE_SPEED,
1373 " ", "gravity", "set level gravity"
1376 ED_SETTINGS_XPOS(0), ED_COUNTER2_YPOS(9) - MINI_TILEY,
1377 GADGET_ID_RANDOM_RESTRICTED, GADGET_ID_NONE,
1378 &random_placement_background_restricted,
1380 "restrict random placement to:", "set random placement restriction"
1383 /* ---------- element settings: configure (various elements) ------------- */
1386 ED_SETTINGS_XPOS(0), 0, /* set at runtime */
1387 GADGET_ID_STICK_ELEMENT, GADGET_ID_NONE,
1388 &stick_element_properties_window,
1390 "stick this screen to edit content","stick this screen to edit content"
1393 ED_SETTINGS_XPOS(0), ED_COUNTER_YPOS(4),
1394 GADGET_ID_EM_SLIPPERY_GEMS, GADGET_ID_NONE,
1395 &level.em_slippery_gems,
1397 "slip down from certain flat walls","use EM style slipping behaviour"
1400 /* ---------- element settings: configure (custom elements) ------------- */
1403 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(1),
1404 GADGET_ID_CUSTOM_ACCESSIBLE, GADGET_ID_NONE,
1405 &custom_element_properties[EP_ACCESSIBLE],
1406 NULL, NULL, "player can walk to or pass this field"
1409 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(2),
1410 GADGET_ID_CUSTOM_WALK_TO_OBJECT, GADGET_ID_NONE,
1411 &custom_element_properties[EP_WALK_TO_OBJECT],
1412 NULL, NULL, "player can dig/collect/push element"
1415 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(5),
1416 GADGET_ID_CUSTOM_CAN_MOVE, GADGET_ID_NONE,
1417 &custom_element_properties[EP_CAN_MOVE],
1418 NULL, NULL, "element can move in some direction"
1421 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(9),
1422 GADGET_ID_CUSTOM_CAN_FALL, GADGET_ID_NONE,
1423 &custom_element_properties[EP_CAN_FALL],
1424 NULL, "can fall", "element can fall down"
1427 ED_SETTINGS_XPOS(6), ED_SETTINGS_YPOS(9),
1428 GADGET_ID_CUSTOM_CAN_SMASH, GADGET_ID_CUSTOM_CAN_FALL,
1429 &custom_element_properties[EP_CAN_SMASH],
1430 " ", NULL, "element can smash other elements"
1433 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(10),
1434 GADGET_ID_CUSTOM_SLIPPERY, GADGET_ID_NONE,
1435 &custom_element_properties[EP_SLIPPERY],
1436 NULL, NULL, "other elements can fall down from it"
1439 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(11),
1440 GADGET_ID_CUSTOM_DEADLY, GADGET_ID_NONE,
1441 &custom_element_properties[EP_DEADLY],
1442 NULL, NULL, "element can kill the player"
1445 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(12),
1446 GADGET_ID_CUSTOM_EXPLODE_RESULT, GADGET_ID_NONE,
1447 &custom_element_properties[EP_EXPLODE_RESULT],
1448 NULL, NULL, "set consistency/destructibility"
1451 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(13),
1452 GADGET_ID_CUSTOM_EXPLODE_FIRE, GADGET_ID_NONE,
1453 &custom_element.can_explode_by_fire,
1454 NULL, "by fire", "element can explode by fire/explosion"
1457 ED_SETTINGS_XPOS(7), ED_SETTINGS_YPOS(13),
1458 GADGET_ID_CUSTOM_EXPLODE_SMASH, GADGET_ID_CUSTOM_EXPLODE_FIRE,
1459 &custom_element.can_explode_smashed,
1460 " ", "smashed", "element can explode when smashed"
1463 ED_SETTINGS_XPOS(13), ED_SETTINGS_YPOS(13),
1464 GADGET_ID_CUSTOM_EXPLODE_IMPACT, GADGET_ID_CUSTOM_EXPLODE_SMASH,
1465 &custom_element.can_explode_impact,
1466 " ", "impact", "element can explode on impact"
1469 /* ---------- element settings: advanced (custom elements) --------------- */
1472 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(1),
1473 GADGET_ID_CUSTOM_USE_GRAPHIC, GADGET_ID_NONE,
1474 &custom_element.use_gfx_element,
1475 NULL, "use graphic of element:", "use graphic for custom element"
1478 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(2),
1479 GADGET_ID_CUSTOM_CAN_CHANGE, GADGET_ID_NONE,
1480 &custom_element_properties[EP_CAN_CHANGE],
1481 NULL, "element changes to:", "element can change to other element"
1484 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(3),
1485 GADGET_ID_CHANGE_DELAY, GADGET_ID_NONE,
1486 &custom_element_change_events[CE_DELAY],
1487 NULL, NULL, "element changes after delay"
1490 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(5),
1491 GADGET_ID_CHANGE_BY_PLAYER, GADGET_ID_NONE,
1492 &custom_element_change_events[CE_BY_PLAYER],
1493 NULL, NULL, "element changes by player contact"
1496 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(6),
1497 GADGET_ID_CHANGE_BY_COLLISION, GADGET_ID_NONE,
1498 &custom_element_change_events[CE_BY_COLLISION],
1499 NULL, NULL, "element changes by impact or smash"
1502 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(7),
1503 GADGET_ID_CHANGE_BY_OTHER, GADGET_ID_NONE,
1504 &custom_element_change_events[CE_BY_OTHER],
1505 NULL, NULL, "element changes by other element"
1508 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(8),
1509 GADGET_ID_CHANGE_USE_EXPLOSION, GADGET_ID_NONE,
1510 &custom_element.change.explode,
1511 NULL, "explode instead of change", "element explodes instead of change"
1514 ED_SETTINGS_XPOS(1), ED_SETTINGS_YPOS(9),
1515 GADGET_ID_CHANGE_USE_CONTENT, GADGET_ID_NONE,
1516 &custom_element.change.use_content,
1517 NULL, "use extended change target:","element changes to more elements"
1520 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(11),
1521 GADGET_ID_CHANGE_ONLY_COMPLETE, GADGET_ID_NONE,
1522 &custom_element.change.only_complete,
1523 NULL, "only use complete change", "only use complete extended content"
1526 ED_SETTINGS_XPOS(2), ED_SETTINGS_YPOS(12),
1527 GADGET_ID_CHANGE_USE_RANDOM, GADGET_ID_NONE,
1528 &custom_element.change.use_random_change,
1529 NULL, NULL, "use random value for new content"
1532 ED_SETTINGS_XPOS(0), ED_SETTINGS_YPOS(13),
1533 GADGET_ID_CUSTOM_USE_TEMPLATE, GADGET_ID_NONE,
1534 &level.use_custom_template,
1535 NULL, "use template", "use template for custom properties"
1542 int area_xsize, area_ysize;
1544 int gadget_id_align;
1545 char *text_left, *text_right, *text_below;
1546 } drawingarea_info[ED_NUM_DRAWING_AREAS] =
1548 /* ---------- level playfield content ------------------------------------ */
1552 MAX_ED_FIELDX, MAX_ED_FIELDY,
1553 GADGET_ID_DRAWING_LEVEL, GADGET_ID_NONE,
1557 /* ---------- yam yam content -------------------------------------------- */
1560 ED_AREA_YAMYAM_CONTENT_XPOS(0), ED_AREA_YAMYAM_CONTENT_YPOS(0),
1562 GADGET_ID_ELEMENT_CONTENT_0, GADGET_ID_NONE,
1566 ED_AREA_YAMYAM_CONTENT_XPOS(1), ED_AREA_YAMYAM_CONTENT_YPOS(1),
1568 GADGET_ID_ELEMENT_CONTENT_1, GADGET_ID_NONE,
1572 ED_AREA_YAMYAM_CONTENT_XPOS(2), ED_AREA_YAMYAM_CONTENT_YPOS(2),
1574 GADGET_ID_ELEMENT_CONTENT_2, GADGET_ID_NONE,
1578 ED_AREA_YAMYAM_CONTENT_XPOS(3), ED_AREA_YAMYAM_CONTENT_YPOS(3),
1580 GADGET_ID_ELEMENT_CONTENT_3, GADGET_ID_NONE,
1584 ED_AREA_YAMYAM_CONTENT_XPOS(4), ED_AREA_YAMYAM_CONTENT_YPOS(4),
1586 GADGET_ID_ELEMENT_CONTENT_4, GADGET_ID_NONE,
1590 ED_AREA_YAMYAM_CONTENT_XPOS(5), ED_AREA_YAMYAM_CONTENT_YPOS(5),
1592 GADGET_ID_ELEMENT_CONTENT_5, GADGET_ID_NONE,
1596 ED_AREA_YAMYAM_CONTENT_XPOS(6), ED_AREA_YAMYAM_CONTENT_YPOS(6),
1598 GADGET_ID_ELEMENT_CONTENT_6, GADGET_ID_NONE,
1602 ED_AREA_YAMYAM_CONTENT_XPOS(7), ED_AREA_YAMYAM_CONTENT_YPOS(7),
1604 GADGET_ID_ELEMENT_CONTENT_7, GADGET_ID_NONE,
1608 /* ---------- amoeba content --------------------------------------------- */
1611 ED_AREA_ELEM_CONTENT_XPOS, ED_AREA_ELEM_CONTENT_YPOS,
1613 GADGET_ID_AMOEBA_CONTENT, GADGET_ID_NONE,
1614 NULL, "content of amoeba", NULL
1617 /* ---------- custom graphic --------------------------------------------- */
1620 ED_AREA_ELEM_CONTENT3_XPOS, ED_AREA_ELEM_CONTENT3_YPOS,
1622 GADGET_ID_CUSTOM_GRAPHIC, GADGET_ID_CUSTOM_USE_GRAPHIC,
1626 /* ---------- custom content (when exploding) ---------------------------- */
1629 ED_AREA_ELEM_CONTENT4_XPOS, ED_AREA_ELEM_CONTENT4_YPOS,
1631 GADGET_ID_CUSTOM_CONTENT, GADGET_ID_NONE, /* align three rows */
1632 "content:", NULL, NULL
1635 /* ---------- custom change target --------------------------------------- */
1638 ED_AREA_ELEM_CONTENT2_XPOS, ED_AREA_ELEM_CONTENT2_YPOS,
1640 GADGET_ID_CUSTOM_CHANGE_TARGET, GADGET_ID_CUSTOM_CAN_CHANGE,
1641 NULL, "after/when:", NULL
1644 /* ---------- custom change content (extended change target) ------------- */
1647 ED_AREA_ELEM_CONTENT6_XPOS, ED_AREA_ELEM_CONTENT6_YPOS,
1649 GADGET_ID_CUSTOM_CHANGE_CONTENT, GADGET_ID_NONE, /* align three rows */
1653 /* ---------- custom change trigger (element causing change) ------------- */
1656 ED_AREA_ELEM_CONTENT5_XPOS, ED_AREA_ELEM_CONTENT5_YPOS,
1658 GADGET_ID_CUSTOM_CHANGE_TRIGGER, GADGET_ID_CHANGE_OTHER_ACTION,
1662 /* ---------- random background (for random painting) -------------------- */
1665 ED_AREA_RANDOM_BACKGROUND_XPOS, ED_AREA_RANDOM_BACKGROUND_YPOS,
1667 GADGET_ID_RANDOM_BACKGROUND, GADGET_ID_RANDOM_RESTRICTED,
1674 -----------------------------------------------------------------------------
1675 some internally used variables
1676 -----------------------------------------------------------------------------
1679 /* actual size of level editor drawing area */
1680 static int ed_fieldx = MAX_ED_FIELDX - 1, ed_fieldy = MAX_ED_FIELDY - 1;
1682 /* actual position of level editor drawing area in level playfield */
1683 static int level_xpos = -1, level_ypos = -1;
1685 #define IN_ED_FIELD(x,y) ((x)>=0 && (x)<ed_fieldx && (y)>=0 &&(y)<ed_fieldy)
1687 /* drawing elements on the three mouse buttons */
1688 static int new_element1 = EL_WALL;
1689 static int new_element2 = EL_EMPTY;
1690 static int new_element3 = EL_SAND;
1692 #define BUTTON_ELEMENT(button) ((button) == 1 ? new_element1 : \
1693 (button) == 2 ? new_element2 : \
1694 (button) == 3 ? new_element3 : EL_EMPTY)
1695 #define BUTTON_STEPSIZE(button) ((button) == 1 ? 1 : (button) == 2 ? 5 : 10)
1697 /* forward declaration for internal use */
1698 static void ModifyEditorCounter(int, int);
1699 static void ModifyEditorCounterLimits(int, int, int);
1700 static void ModifyEditorSelectbox(int, int);
1701 static void ModifyEditorElementList();
1702 static void RedrawDrawingElements();
1703 static void DrawDrawingWindow();
1704 static void DrawLevelInfoWindow();
1705 static void DrawPropertiesWindow();
1706 static boolean checkPropertiesConfig();
1707 static void CopyLevelToUndoBuffer(int);
1708 static void HandleDrawingAreas(struct GadgetInfo *);
1709 static void HandleCounterButtons(struct GadgetInfo *);
1710 static void HandleTextInputGadgets(struct GadgetInfo *);
1711 static void HandleSelectboxGadgets(struct GadgetInfo *);
1712 static void HandleTextbuttonGadgets(struct GadgetInfo *);
1713 static void HandleRadiobuttons(struct GadgetInfo *);
1714 static void HandleCheckbuttons(struct GadgetInfo *);
1715 static void HandleControlButtons(struct GadgetInfo *);
1716 static void HandleDrawingAreaInfo(struct GadgetInfo *);
1718 static struct GadgetInfo *level_editor_gadget[NUM_EDITOR_GADGETS];
1719 static int right_gadget_border[NUM_EDITOR_GADGETS];
1721 static int drawing_function = GADGET_ID_SINGLE_ITEMS;
1722 static int last_drawing_function = GADGET_ID_SINGLE_ITEMS;
1723 static boolean draw_with_brush = FALSE;
1724 static int properties_element = 0;
1726 static short FieldBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
1727 static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY];
1728 static int undo_buffer_position = 0;
1729 static int undo_buffer_steps = 0;
1731 static int edit_mode;
1732 static int edit_mode_properties;
1734 static int element_shift = 0;
1736 static int editor_el_boulderdash[] =
1768 EL_BD_BUTTERFLY_LEFT,
1770 EL_BD_BUTTERFLY_RIGHT,
1771 EL_BD_FIREFLY_RIGHT,
1774 EL_BD_BUTTERFLY_DOWN,
1778 static int num_editor_el_boulderdash = SIZEOF_ARRAY_INT(editor_el_boulderdash);
1780 static int editor_el_emerald_mine[] =
1842 EL_ACID_POOL_TOPLEFT,
1844 EL_ACID_POOL_TOPRIGHT,
1847 EL_ACID_POOL_BOTTOMLEFT,
1848 EL_ACID_POOL_BOTTOM,
1849 EL_ACID_POOL_BOTTOMRIGHT,
1872 static int num_editor_el_emerald_mine = SIZEOF_ARRAY_INT(editor_el_emerald_mine);
1874 static int editor_el_more[] =
1907 EL_WALL_EMERALD_YELLOW,
1908 EL_WALL_EMERALD_RED,
1909 EL_WALL_EMERALD_PURPLE,
1926 EL_DYNABOMB_INCREASE_NUMBER,
1927 EL_DYNABOMB_INCREASE_SIZE,
1928 EL_DYNABOMB_INCREASE_POWER,
1949 EL_BALLOON_SWITCH_ANY,
1951 EL_BALLOON_SWITCH_LEFT,
1952 EL_BALLOON_SWITCH_RIGHT,
1953 EL_BALLOON_SWITCH_UP,
1954 EL_BALLOON_SWITCH_DOWN,
1957 EL_EXPANDABLE_WALL_HORIZONTAL,
1958 EL_EXPANDABLE_WALL_VERTICAL,
1959 EL_EXPANDABLE_WALL_ANY,
1961 EL_INVISIBLE_STEELWALL,
1976 static int num_editor_el_more = SIZEOF_ARRAY_INT(editor_el_more);
1978 static int editor_el_sokoban[] =
1991 EL_SOKOBAN_FIELD_EMPTY,
1992 EL_SOKOBAN_FIELD_FULL,
1995 static int num_editor_el_sokoban = SIZEOF_ARRAY_INT(editor_el_sokoban);
1997 static int editor_el_supaplex[] =
2016 EL_SP_HARDWARE_GRAY,
2025 EL_SP_GRAVITY_PORT_RIGHT,
2026 EL_SP_GRAVITY_PORT_DOWN,
2027 EL_SP_GRAVITY_PORT_LEFT,
2029 EL_SP_GRAVITY_PORT_UP,
2035 EL_SP_PORT_VERTICAL,
2036 EL_SP_PORT_HORIZONTAL,
2044 EL_SP_HARDWARE_BASE_1,
2045 EL_SP_HARDWARE_GREEN,
2046 EL_SP_HARDWARE_BLUE,
2049 EL_SP_HARDWARE_YELLOW,
2050 EL_SP_HARDWARE_BASE_2,
2051 EL_SP_HARDWARE_BASE_3,
2052 EL_SP_HARDWARE_BASE_4,
2054 EL_SP_HARDWARE_BASE_5,
2055 EL_SP_HARDWARE_BASE_6,
2059 static int num_editor_el_supaplex = SIZEOF_ARRAY_INT(editor_el_supaplex);
2061 static int editor_el_diamond_caves[] =
2088 EL_CONVEYOR_BELT_1_LEFT,
2089 EL_CONVEYOR_BELT_1_MIDDLE,
2090 EL_CONVEYOR_BELT_1_RIGHT,
2091 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2093 EL_CONVEYOR_BELT_2_LEFT,
2094 EL_CONVEYOR_BELT_2_MIDDLE,
2095 EL_CONVEYOR_BELT_2_RIGHT,
2096 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2098 EL_CONVEYOR_BELT_3_LEFT,
2099 EL_CONVEYOR_BELT_3_MIDDLE,
2100 EL_CONVEYOR_BELT_3_RIGHT,
2101 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2103 EL_CONVEYOR_BELT_4_LEFT,
2104 EL_CONVEYOR_BELT_4_MIDDLE,
2105 EL_CONVEYOR_BELT_4_RIGHT,
2106 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2108 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2109 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2110 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2111 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2113 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2114 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2115 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2116 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2119 EL_SWITCHGATE_CLOSED,
2120 EL_SWITCHGATE_SWITCH_UP,
2130 EL_STEELWALL_SLIPPERY,
2133 EL_SIGN_EXCLAMATION,
2136 EL_LIGHT_SWITCH_ACTIVE,
2143 static int num_editor_el_diamond_caves = SIZEOF_ARRAY_INT(editor_el_diamond_caves);
2145 static int editor_el_dx_boulderdash[] =
2169 EL_TUBE_HORIZONTAL_DOWN,
2173 EL_TUBE_VERTICAL_RIGHT,
2175 EL_TUBE_VERTICAL_LEFT,
2179 EL_TUBE_HORIZONTAL_UP,
2187 static int num_editor_el_dx_boulderdash = SIZEOF_ARRAY_INT(editor_el_dx_boulderdash);
2189 static int editor_el_chars[] =
2283 EL_CHAR(FONT_ASCII_CURSOR),
2286 static int num_editor_el_chars = SIZEOF_ARRAY_INT(editor_el_chars);
2288 static int editor_el_custom[] =
2310 EL_CUSTOM_START + 0,
2311 EL_CUSTOM_START + 1,
2312 EL_CUSTOM_START + 2,
2313 EL_CUSTOM_START + 3,
2315 EL_CUSTOM_START + 4,
2316 EL_CUSTOM_START + 5,
2317 EL_CUSTOM_START + 6,
2318 EL_CUSTOM_START + 7,
2320 EL_CUSTOM_START + 8,
2321 EL_CUSTOM_START + 9,
2322 EL_CUSTOM_START + 10,
2323 EL_CUSTOM_START + 11,
2325 EL_CUSTOM_START + 12,
2326 EL_CUSTOM_START + 13,
2327 EL_CUSTOM_START + 14,
2328 EL_CUSTOM_START + 15,
2330 EL_CUSTOM_START + 16,
2331 EL_CUSTOM_START + 17,
2332 EL_CUSTOM_START + 18,
2333 EL_CUSTOM_START + 19,
2335 EL_CUSTOM_START + 20,
2336 EL_CUSTOM_START + 21,
2337 EL_CUSTOM_START + 22,
2338 EL_CUSTOM_START + 23,
2340 EL_CUSTOM_START + 24,
2341 EL_CUSTOM_START + 25,
2342 EL_CUSTOM_START + 26,
2343 EL_CUSTOM_START + 27,
2345 EL_CUSTOM_START + 28,
2346 EL_CUSTOM_START + 29,
2347 EL_CUSTOM_START + 30,
2348 EL_CUSTOM_START + 31,
2350 EL_CUSTOM_START + 32,
2351 EL_CUSTOM_START + 33,
2352 EL_CUSTOM_START + 34,
2353 EL_CUSTOM_START + 35,
2355 EL_CUSTOM_START + 36,
2356 EL_CUSTOM_START + 37,
2357 EL_CUSTOM_START + 38,
2358 EL_CUSTOM_START + 39,
2360 EL_CUSTOM_START + 40,
2361 EL_CUSTOM_START + 41,
2362 EL_CUSTOM_START + 42,
2363 EL_CUSTOM_START + 43,
2365 EL_CUSTOM_START + 44,
2366 EL_CUSTOM_START + 45,
2367 EL_CUSTOM_START + 46,
2368 EL_CUSTOM_START + 47,
2370 EL_CUSTOM_START + 48,
2371 EL_CUSTOM_START + 49,
2372 EL_CUSTOM_START + 50,
2373 EL_CUSTOM_START + 51,
2375 EL_CUSTOM_START + 52,
2376 EL_CUSTOM_START + 53,
2377 EL_CUSTOM_START + 54,
2378 EL_CUSTOM_START + 55,
2380 EL_CUSTOM_START + 56,
2381 EL_CUSTOM_START + 57,
2382 EL_CUSTOM_START + 58,
2383 EL_CUSTOM_START + 59,
2385 EL_CUSTOM_START + 60,
2386 EL_CUSTOM_START + 61,
2387 EL_CUSTOM_START + 62,
2388 EL_CUSTOM_START + 63,
2390 EL_CUSTOM_START + 64,
2391 EL_CUSTOM_START + 65,
2392 EL_CUSTOM_START + 66,
2393 EL_CUSTOM_START + 67,
2395 EL_CUSTOM_START + 68,
2396 EL_CUSTOM_START + 69,
2397 EL_CUSTOM_START + 70,
2398 EL_CUSTOM_START + 71,
2400 EL_CUSTOM_START + 72,
2401 EL_CUSTOM_START + 73,
2402 EL_CUSTOM_START + 74,
2403 EL_CUSTOM_START + 75,
2405 EL_CUSTOM_START + 76,
2406 EL_CUSTOM_START + 77,
2407 EL_CUSTOM_START + 78,
2408 EL_CUSTOM_START + 79,
2410 EL_CUSTOM_START + 80,
2411 EL_CUSTOM_START + 81,
2412 EL_CUSTOM_START + 82,
2413 EL_CUSTOM_START + 83,
2415 EL_CUSTOM_START + 84,
2416 EL_CUSTOM_START + 85,
2417 EL_CUSTOM_START + 86,
2418 EL_CUSTOM_START + 87,
2420 EL_CUSTOM_START + 88,
2421 EL_CUSTOM_START + 89,
2422 EL_CUSTOM_START + 90,
2423 EL_CUSTOM_START + 91,
2425 EL_CUSTOM_START + 92,
2426 EL_CUSTOM_START + 93,
2427 EL_CUSTOM_START + 94,
2428 EL_CUSTOM_START + 95,
2430 EL_CUSTOM_START + 96,
2431 EL_CUSTOM_START + 97,
2432 EL_CUSTOM_START + 98,
2433 EL_CUSTOM_START + 99,
2435 EL_CUSTOM_START + 100,
2436 EL_CUSTOM_START + 101,
2437 EL_CUSTOM_START + 102,
2438 EL_CUSTOM_START + 103,
2440 EL_CUSTOM_START + 104,
2441 EL_CUSTOM_START + 105,
2442 EL_CUSTOM_START + 106,
2443 EL_CUSTOM_START + 107,
2445 EL_CUSTOM_START + 108,
2446 EL_CUSTOM_START + 109,
2447 EL_CUSTOM_START + 110,
2448 EL_CUSTOM_START + 111,
2450 EL_CUSTOM_START + 112,
2451 EL_CUSTOM_START + 113,
2452 EL_CUSTOM_START + 114,
2453 EL_CUSTOM_START + 115,
2455 EL_CUSTOM_START + 116,
2456 EL_CUSTOM_START + 117,
2457 EL_CUSTOM_START + 118,
2458 EL_CUSTOM_START + 119,
2460 EL_CUSTOM_START + 120,
2461 EL_CUSTOM_START + 121,
2462 EL_CUSTOM_START + 122,
2463 EL_CUSTOM_START + 123,
2465 EL_CUSTOM_START + 124,
2466 EL_CUSTOM_START + 125,
2467 EL_CUSTOM_START + 126,
2468 EL_CUSTOM_START + 127
2470 static int num_editor_el_custom = SIZEOF_ARRAY_INT(editor_el_custom);
2472 static int editor_el_custom_more[] =
2474 EL_CUSTOM_START + 128,
2475 EL_CUSTOM_START + 129,
2476 EL_CUSTOM_START + 130,
2477 EL_CUSTOM_START + 131,
2479 EL_CUSTOM_START + 132,
2480 EL_CUSTOM_START + 133,
2481 EL_CUSTOM_START + 134,
2482 EL_CUSTOM_START + 135,
2484 EL_CUSTOM_START + 136,
2485 EL_CUSTOM_START + 137,
2486 EL_CUSTOM_START + 138,
2487 EL_CUSTOM_START + 139,
2489 EL_CUSTOM_START + 140,
2490 EL_CUSTOM_START + 141,
2491 EL_CUSTOM_START + 142,
2492 EL_CUSTOM_START + 143,
2494 EL_CUSTOM_START + 144,
2495 EL_CUSTOM_START + 145,
2496 EL_CUSTOM_START + 146,
2497 EL_CUSTOM_START + 147,
2499 EL_CUSTOM_START + 148,
2500 EL_CUSTOM_START + 149,
2501 EL_CUSTOM_START + 150,
2502 EL_CUSTOM_START + 151,
2504 EL_CUSTOM_START + 152,
2505 EL_CUSTOM_START + 153,
2506 EL_CUSTOM_START + 154,
2507 EL_CUSTOM_START + 155,
2509 EL_CUSTOM_START + 156,
2510 EL_CUSTOM_START + 157,
2511 EL_CUSTOM_START + 158,
2512 EL_CUSTOM_START + 159,
2514 EL_CUSTOM_START + 160,
2515 EL_CUSTOM_START + 161,
2516 EL_CUSTOM_START + 162,
2517 EL_CUSTOM_START + 163,
2519 EL_CUSTOM_START + 164,
2520 EL_CUSTOM_START + 165,
2521 EL_CUSTOM_START + 166,
2522 EL_CUSTOM_START + 167,
2524 EL_CUSTOM_START + 168,
2525 EL_CUSTOM_START + 169,
2526 EL_CUSTOM_START + 170,
2527 EL_CUSTOM_START + 171,
2529 EL_CUSTOM_START + 172,
2530 EL_CUSTOM_START + 173,
2531 EL_CUSTOM_START + 174,
2532 EL_CUSTOM_START + 175,
2534 EL_CUSTOM_START + 176,
2535 EL_CUSTOM_START + 177,
2536 EL_CUSTOM_START + 178,
2537 EL_CUSTOM_START + 179,
2539 EL_CUSTOM_START + 180,
2540 EL_CUSTOM_START + 181,
2541 EL_CUSTOM_START + 182,
2542 EL_CUSTOM_START + 183,
2544 EL_CUSTOM_START + 184,
2545 EL_CUSTOM_START + 185,
2546 EL_CUSTOM_START + 186,
2547 EL_CUSTOM_START + 187,
2549 EL_CUSTOM_START + 188,
2550 EL_CUSTOM_START + 189,
2551 EL_CUSTOM_START + 190,
2552 EL_CUSTOM_START + 191,
2554 EL_CUSTOM_START + 192,
2555 EL_CUSTOM_START + 193,
2556 EL_CUSTOM_START + 194,
2557 EL_CUSTOM_START + 195,
2559 EL_CUSTOM_START + 196,
2560 EL_CUSTOM_START + 197,
2561 EL_CUSTOM_START + 198,
2562 EL_CUSTOM_START + 199,
2564 EL_CUSTOM_START + 200,
2565 EL_CUSTOM_START + 201,
2566 EL_CUSTOM_START + 202,
2567 EL_CUSTOM_START + 203,
2569 EL_CUSTOM_START + 204,
2570 EL_CUSTOM_START + 205,
2571 EL_CUSTOM_START + 206,
2572 EL_CUSTOM_START + 207,
2574 EL_CUSTOM_START + 208,
2575 EL_CUSTOM_START + 209,
2576 EL_CUSTOM_START + 210,
2577 EL_CUSTOM_START + 211,
2579 EL_CUSTOM_START + 212,
2580 EL_CUSTOM_START + 213,
2581 EL_CUSTOM_START + 214,
2582 EL_CUSTOM_START + 215,
2584 EL_CUSTOM_START + 216,
2585 EL_CUSTOM_START + 217,
2586 EL_CUSTOM_START + 218,
2587 EL_CUSTOM_START + 219,
2589 EL_CUSTOM_START + 220,
2590 EL_CUSTOM_START + 221,
2591 EL_CUSTOM_START + 222,
2592 EL_CUSTOM_START + 223,
2594 EL_CUSTOM_START + 224,
2595 EL_CUSTOM_START + 225,
2596 EL_CUSTOM_START + 226,
2597 EL_CUSTOM_START + 227,
2599 EL_CUSTOM_START + 228,
2600 EL_CUSTOM_START + 229,
2601 EL_CUSTOM_START + 230,
2602 EL_CUSTOM_START + 231,
2604 EL_CUSTOM_START + 232,
2605 EL_CUSTOM_START + 233,
2606 EL_CUSTOM_START + 234,
2607 EL_CUSTOM_START + 235,
2609 EL_CUSTOM_START + 236,
2610 EL_CUSTOM_START + 237,
2611 EL_CUSTOM_START + 238,
2612 EL_CUSTOM_START + 239,
2614 EL_CUSTOM_START + 240,
2615 EL_CUSTOM_START + 241,
2616 EL_CUSTOM_START + 242,
2617 EL_CUSTOM_START + 243,
2619 EL_CUSTOM_START + 244,
2620 EL_CUSTOM_START + 245,
2621 EL_CUSTOM_START + 246,
2622 EL_CUSTOM_START + 247,
2624 EL_CUSTOM_START + 248,
2625 EL_CUSTOM_START + 249,
2626 EL_CUSTOM_START + 250,
2627 EL_CUSTOM_START + 251,
2629 EL_CUSTOM_START + 252,
2630 EL_CUSTOM_START + 253,
2631 EL_CUSTOM_START + 254,
2632 EL_CUSTOM_START + 255
2634 static int num_editor_el_custom_more = SIZEOF_ARRAY_INT(editor_el_custom_more);
2636 static int *editor_elements = NULL; /* dynamically allocated */
2637 static int num_editor_elements = 0; /* dynamically determined */
2641 boolean *setup_value;
2643 int *element_list_size;
2645 boolean last_setup_value;
2647 editor_elements_info[] =
2649 { &setup.editor.el_boulderdash, editor_el_boulderdash,
2650 &num_editor_el_boulderdash },
2651 { &setup.editor.el_emerald_mine, editor_el_emerald_mine,
2652 &num_editor_el_emerald_mine },
2653 { &setup.editor.el_more, editor_el_more,
2654 &num_editor_el_more },
2655 { &setup.editor.el_sokoban, editor_el_sokoban,
2656 &num_editor_el_sokoban },
2657 { &setup.editor.el_supaplex, editor_el_supaplex,
2658 &num_editor_el_supaplex },
2659 { &setup.editor.el_diamond_caves, editor_el_diamond_caves,
2660 &num_editor_el_diamond_caves },
2661 { &setup.editor.el_dx_boulderdash, editor_el_dx_boulderdash,
2662 &num_editor_el_dx_boulderdash },
2663 { &setup.editor.el_chars, editor_el_chars,
2664 &num_editor_el_chars },
2665 { &setup.editor.el_custom, editor_el_custom,
2666 &num_editor_el_custom },
2667 { &setup.editor.el_custom_more, editor_el_custom_more,
2668 &num_editor_el_custom_more },
2675 -----------------------------------------------------------------------------
2677 -----------------------------------------------------------------------------
2680 static void ReinitializeElementList()
2685 if (editor_elements != NULL)
2686 free(editor_elements);
2688 num_editor_elements = 0;
2690 /* determine size of element list */
2691 for (i=0; editor_elements_info[i].setup_value != NULL; i++)
2692 if (*editor_elements_info[i].setup_value)
2693 num_editor_elements += *editor_elements_info[i].element_list_size;
2695 if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS)
2697 /* workaround: offer at least as many elements as element buttons exist */
2698 int list_nr = 1; /* see above: editor_elements_info for Emerald Mine */
2700 *editor_elements_info[list_nr].setup_value = TRUE;
2701 num_editor_elements += *editor_elements_info[list_nr].element_list_size;
2704 editor_elements = checked_malloc(num_editor_elements * sizeof(int));
2706 /* fill element list */
2707 for (i=0; editor_elements_info[i].setup_value != NULL; i++)
2708 if (*editor_elements_info[i].setup_value)
2709 for (j=0; j<*editor_elements_info[i].element_list_size; j++)
2710 editor_elements[pos++] = editor_elements_info[i].element_list[j];
2712 /* correct position of element list scrollbar */
2713 if (element_shift < 0)
2715 if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
2716 element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
2719 static void ReinitializeElementListButtons()
2721 static boolean initialization_needed = TRUE;
2724 if (!initialization_needed) /* check if editor element setup has changed */
2725 for (i=0; editor_elements_info[i].setup_value != NULL; i++)
2726 if (editor_elements_info[i].last_setup_value !=
2727 *editor_elements_info[i].setup_value)
2728 initialization_needed = TRUE;
2730 if (!initialization_needed)
2733 FreeLevelEditorGadgets();
2734 CreateLevelEditorGadgets();
2736 /* store current setup values for next invocation of this function */
2737 for (i=0; editor_elements_info[i].setup_value != NULL; i++)
2738 editor_elements_info[i].last_setup_value =
2739 *editor_elements_info[i].setup_value;
2741 initialization_needed = FALSE;
2744 static int getMaxInfoTextLength()
2746 return (SXSIZE / getFontWidth(FONT_TEXT_2));
2749 static int getTextWidthForGadget(char *text)
2754 return (getTextWidth(text, FONT_TEXT_1) + ED_GADGET_TEXT_DISTANCE);
2757 static int getTextWidthForDrawingArea(char *text)
2762 return (getTextWidth(text, FONT_TEXT_1) + ED_DRAWINGAREA_TEXT_DISTANCE);
2765 static int getRightGadgetBorder(struct GadgetInfo *gi, char *text)
2767 return (gi->x + gi->width + getTextWidthForGadget(text));
2770 static char *getElementInfoText(int element)
2772 char *info_text = NULL;
2774 if (element < NUM_FILE_ELEMENTS)
2776 if (strlen(element_info[element].description) > 0)
2777 info_text = element_info[element].description;
2778 else if (element_info[element].custom_description != NULL)
2779 info_text = element_info[element].custom_description;
2780 else if (element_info[element].editor_description != NULL)
2781 info_text = element_info[element].editor_description;
2784 if (info_text == NULL)
2786 info_text = "unknown";
2788 Error(ERR_WARN, "no element description for element %d", element);
2794 static void DrawElementBorder(int dest_x, int dest_y, int width, int height,
2797 int border_graphic =
2798 (input ? IMG_EDITOR_ELEMENT_BORDER_INPUT : IMG_EDITOR_ELEMENT_BORDER);
2801 int num_mini_tilex = width / MINI_TILEX + 1;
2802 int num_mini_tiley = width / MINI_TILEY + 1;
2805 getMiniGraphicSource(border_graphic, &src_bitmap, &src_x, &src_y);
2807 for (y=0; y < num_mini_tiley; y++)
2808 for (x=0; x < num_mini_tilex; x++)
2809 BlitBitmap(src_bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
2810 dest_x - MINI_TILEX / 2 + x * MINI_TILEX,
2811 dest_y - MINI_TILEY / 2 + y * MINI_TILEY);
2813 ClearRectangle(drawto, dest_x - 1, dest_y - 1, width + 2, height + 2);
2816 static void DrawDrawingArea(int id)
2818 struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
2821 if (id == ED_DRAWING_ID_RANDOM_BACKGROUND)
2822 DrawMiniGraphicExt(drawto, gi->x, gi->y,
2823 el2edimg(random_placement_background_element));
2824 else if (id == ED_DRAWING_ID_AMOEBA_CONTENT)
2825 DrawMiniGraphicExt(drawto, gi->x, gi->y, el2edimg(level.amoeba_content));
2826 else if (id == ED_DRAWING_ID_CUSTOM_GRAPHIC)
2827 DrawMiniGraphicExt(drawto, gi->x, gi->y,
2828 el2edimg(custom_element.gfx_element));
2829 else if (id == ED_DRAWING_ID_CUSTOM_CONTENT)
2832 DrawMiniGraphicExt(drawto,
2833 gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
2834 el2edimg(custom_element.content[x][y]));
2835 else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_TARGET)
2836 DrawMiniGraphicExt(drawto, gi->x, gi->y,
2837 el2edimg(custom_element.change.target_element));
2838 else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT)
2839 for (y=0; y < 3; y++)
2840 for (x=0; x < 3; x++)
2841 DrawMiniGraphicExt(drawto,
2842 gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
2843 el2edimg(custom_element.change.content[x][y]));
2844 else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER)
2845 DrawMiniGraphicExt(drawto, gi->x, gi->y,
2846 el2edimg(custom_element.change.trigger_element));
2847 else if (id >= ED_DRAWING_ID_ELEMENT_CONTENT_0 &&
2848 id <= ED_DRAWING_ID_ELEMENT_CONTENT_7)
2850 int nr = id - ED_DRAWING_ID_ELEMENT_CONTENT_0;
2852 for (y=0; y < 3; y++)
2853 for (x=0; x < 3; x++)
2854 DrawMiniGraphicExt(drawto,
2855 gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
2856 el2edimg(level.yamyam_content[nr][x][y]));
2860 static void ScrollMiniLevel(int from_x, int from_y, int scroll)
2863 int dx = (scroll == ED_SCROLL_LEFT ? -1 : scroll == ED_SCROLL_RIGHT ? 1 : 0);
2864 int dy = (scroll == ED_SCROLL_UP ? -1 : scroll == ED_SCROLL_DOWN ? 1 : 0);
2866 BlitBitmap(drawto, drawto,
2867 SX + (dx == -1 ? MINI_TILEX : 0),
2868 SY + (dy == -1 ? MINI_TILEY : 0),
2869 (ed_fieldx * MINI_TILEX) - (dx != 0 ? MINI_TILEX : 0),
2870 (ed_fieldy * MINI_TILEY) - (dy != 0 ? MINI_TILEY : 0),
2871 SX + (dx == +1 ? MINI_TILEX : 0),
2872 SY + (dy == +1 ? MINI_TILEY : 0));
2875 x = (dx == 1 ? 0 : ed_fieldx - 1);
2876 for(y=0; y<ed_fieldy; y++)
2877 DrawMiniElementOrWall(x, y, from_x, from_y);
2881 y = (dy == 1 ? 0 : ed_fieldy - 1);
2882 for(x=0; x<ed_fieldx; x++)
2883 DrawMiniElementOrWall(x, y, from_x, from_y);
2886 redraw_mask |= REDRAW_FIELD;
2890 static void CreateControlButtons()
2892 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
2893 struct GadgetInfo *gi;
2894 unsigned long event_mask;
2897 /* create toolbox buttons */
2898 for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
2902 int gd_xoffset, gd_yoffset;
2903 int gd_x1, gd_x2, gd_y1, gd_y2;
2905 int radio_button_nr;
2908 if (id == GADGET_ID_SINGLE_ITEMS ||
2909 id == GADGET_ID_CONNECTED_ITEMS ||
2910 id == GADGET_ID_LINE ||
2911 id == GADGET_ID_ARC ||
2912 id == GADGET_ID_TEXT ||
2913 id == GADGET_ID_RECTANGLE ||
2914 id == GADGET_ID_FILLED_BOX ||
2915 id == GADGET_ID_FLOOD_FILL ||
2916 id == GADGET_ID_GRAB_BRUSH ||
2917 id == GADGET_ID_PICK_ELEMENT)
2919 button_type = GD_TYPE_RADIO_BUTTON;
2920 radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
2921 checked = (id == drawing_function ? TRUE : FALSE);
2922 event_mask = GD_EVENT_PRESSED;
2926 button_type = GD_TYPE_NORMAL_BUTTON;
2927 radio_button_nr = RADIO_NR_NONE;
2930 if (id == GADGET_ID_WRAP_LEFT ||
2931 id == GADGET_ID_WRAP_RIGHT ||
2932 id == GADGET_ID_WRAP_UP ||
2933 id == GADGET_ID_WRAP_DOWN)
2934 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
2936 event_mask = GD_EVENT_RELEASED;
2939 if (id < ED_NUM_CTRL1_BUTTONS)
2941 int x = i % ED_CTRL1_BUTTONS_HORIZ;
2942 int y = i / ED_CTRL1_BUTTONS_HORIZ;
2944 gd_xoffset = ED_CTRL1_BUTTONS_XPOS + x * ED_CTRL1_BUTTON_XSIZE;
2945 gd_yoffset = ED_CTRL1_BUTTONS_YPOS + y * ED_CTRL1_BUTTON_YSIZE;
2946 width = ED_CTRL1_BUTTON_XSIZE;
2947 height = ED_CTRL1_BUTTON_YSIZE;
2951 int x = (i - ED_NUM_CTRL1_BUTTONS) % ED_CTRL2_BUTTONS_HORIZ;
2952 int y = (i - ED_NUM_CTRL1_BUTTONS) / ED_CTRL2_BUTTONS_HORIZ;
2954 gd_xoffset = ED_CTRL2_BUTTONS_XPOS + x * ED_CTRL2_BUTTON_XSIZE;
2955 gd_yoffset = ED_CTRL2_BUTTONS_YPOS + y * ED_CTRL2_BUTTON_YSIZE;
2956 width = ED_CTRL2_BUTTON_XSIZE;
2957 height = ED_CTRL2_BUTTON_YSIZE;
2960 gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
2961 gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
2962 gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_GFX_YPOS + gd_yoffset;
2963 gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
2965 gi = CreateGadget(GDI_CUSTOM_ID, id,
2966 GDI_CUSTOM_TYPE_ID, i,
2967 GDI_INFO_TEXT, control_info[i].text,
2968 GDI_X, EX + gd_xoffset,
2969 GDI_Y, EY + gd_yoffset,
2972 GDI_TYPE, button_type,
2973 GDI_STATE, GD_BUTTON_UNPRESSED,
2974 GDI_RADIO_NR, radio_button_nr,
2975 GDI_CHECKED, checked,
2976 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
2977 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
2978 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
2979 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
2980 GDI_EVENT_MASK, event_mask,
2981 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
2982 GDI_CALLBACK_ACTION, HandleControlButtons,
2986 Error(ERR_EXIT, "cannot create gadget");
2988 level_editor_gadget[id] = gi;
2991 /* create buttons for scrolling of drawing area and element list */
2992 for (i=0; i<ED_NUM_SCROLLBUTTONS; i++)
2994 int id = scrollbutton_info[i].gadget_id;
2995 int x, y, width, height;
2996 int gd_x1, gd_x2, gd_y1, gd_y2;
2998 x = scrollbutton_info[i].x;
2999 y = scrollbutton_info[i].y;
3001 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3003 if (id == GADGET_ID_SCROLL_LIST_UP ||
3004 id == GADGET_ID_SCROLL_LIST_DOWN)
3008 width = ED_SCROLLBUTTON2_XSIZE;
3009 height = ED_SCROLLBUTTON2_YSIZE;
3010 gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
3011 gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
3012 gd_x2 = gd_x1 - ED_SCROLLBUTTON2_XSIZE;
3019 width = ED_SCROLLBUTTON_XSIZE;
3020 height = ED_SCROLLBUTTON_YSIZE;
3021 gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
3022 gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
3023 gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
3027 gi = CreateGadget(GDI_CUSTOM_ID, id,
3028 GDI_CUSTOM_TYPE_ID, i,
3029 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
3034 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3035 GDI_STATE, GD_BUTTON_UNPRESSED,
3036 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
3037 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
3038 GDI_EVENT_MASK, event_mask,
3039 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3040 GDI_CALLBACK_ACTION, HandleControlButtons,
3044 Error(ERR_EXIT, "cannot create gadget");
3046 level_editor_gadget[id] = gi;
3049 /* create buttons for element list */
3050 for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
3052 Bitmap *deco_bitmap;
3053 int deco_x, deco_y, deco_xpos, deco_ypos;
3054 int gd_xoffset, gd_yoffset;
3055 int gd_x1, gd_x2, gd_y;
3056 int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
3057 int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
3058 int id = GADGET_ID_ELEMENTLIST_FIRST + i;
3059 int element = editor_elements[i];
3061 event_mask = GD_EVENT_RELEASED;
3063 gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE;
3064 gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE;
3066 gd_x1 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS + ED_ELEMENTLIST_XSIZE;
3067 gd_x2 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS;
3068 gd_y = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_YPOS;
3070 getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y);
3071 deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2;
3072 deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2;
3074 gi = CreateGadget(GDI_CUSTOM_ID, id,
3075 GDI_CUSTOM_TYPE_ID, i,
3076 GDI_INFO_TEXT, getElementInfoText(element),
3077 GDI_X, DX + gd_xoffset,
3078 GDI_Y, DY + gd_yoffset,
3079 GDI_WIDTH, ED_ELEMENTLIST_XSIZE,
3080 GDI_HEIGHT, ED_ELEMENTLIST_YSIZE,
3081 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3082 GDI_STATE, GD_BUTTON_UNPRESSED,
3083 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
3084 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
3085 GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
3086 GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
3087 GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
3088 GDI_DECORATION_SHIFTING, 1, 1,
3089 GDI_EVENT_MASK, event_mask,
3090 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3091 GDI_CALLBACK_ACTION, HandleControlButtons,
3095 Error(ERR_EXIT, "cannot create gadget");
3097 level_editor_gadget[id] = gi;
3101 static void CreateCounterButtons()
3103 int max_infotext_len = getMaxInfoTextLength();
3106 for (i=0; i<ED_NUM_COUNTERBUTTONS; i++)
3109 int x = SX + counterbutton_info[i].x; /* down count button */
3110 int y = SY + counterbutton_info[i].y;
3112 /* determine horizontal position to the right of specified gadget */
3113 if (counterbutton_info[i].gadget_id_align != GADGET_ID_NONE)
3114 x = (right_gadget_border[counterbutton_info[i].gadget_id_align] +
3115 ED_GADGET_TEXT_DISTANCE);
3117 /* determine horizontal offset for leading text */
3118 if (counterbutton_info[i].text_left != NULL)
3119 x += getTextWidthForGadget(counterbutton_info[i].text_left);
3123 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3124 struct GadgetInfo *gi;
3126 counterbutton_info[i].gadget_id_down :
3127 counterbutton_info[i].gadget_id_up);
3129 int gd_x, gd_x1, gd_x2, gd_y;
3131 unsigned long event_mask;
3132 char infotext[max_infotext_len + 1];
3134 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
3136 if (i == ED_COUNTER_ID_SELECT_LEVEL)
3139 ED_SCROLLBUTTON_ID_AREA_LEFT :
3140 ED_SCROLLBUTTON_ID_AREA_RIGHT);
3142 event_mask |= GD_EVENT_RELEASED;
3145 x += 2 * ED_GADGET_DISTANCE;
3146 y += ED_GADGET_DISTANCE;
3148 gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[sid].gd_x;
3149 gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
3150 gd_y = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].gd_y;
3151 x_size = ED_SCROLLBUTTON_XSIZE;
3152 y_size = ED_SCROLLBUTTON_YSIZE;
3156 gd_xoffset = (j == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS);
3157 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
3158 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
3159 gd_y = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS;
3160 x_size = ED_BUTTON_COUNT_XSIZE;
3161 y_size = ED_BUTTON_COUNT_YSIZE;
3164 sprintf(infotext, "%s counter value by 1, 5 or 10",
3165 (j == 0 ? "decrease" : "increase"));
3167 gi = CreateGadget(GDI_CUSTOM_ID, id,
3168 GDI_CUSTOM_TYPE_ID, i,
3169 GDI_INFO_TEXT, infotext,
3174 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
3175 GDI_STATE, GD_BUTTON_UNPRESSED,
3176 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
3177 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
3178 GDI_EVENT_MASK, event_mask,
3179 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3180 GDI_CALLBACK_ACTION, HandleCounterButtons,
3184 Error(ERR_EXIT, "cannot create gadget");
3186 level_editor_gadget[id] = gi;
3187 right_gadget_border[id] =
3188 getRightGadgetBorder(gi, counterbutton_info[i].text_right);
3190 x += gi->width + ED_GADGET_DISTANCE; /* text count button */
3194 int font_type = FONT_INPUT_1;
3195 int font_type_active = FONT_INPUT_1_ACTIVE;
3196 int gd_width = ED_WIN_COUNT_XSIZE;
3198 id = counterbutton_info[i].gadget_id_text;
3199 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
3201 if (i == ED_COUNTER_ID_SELECT_LEVEL)
3203 font_type = FONT_LEVEL_NUMBER;
3204 font_type_active = FONT_LEVEL_NUMBER;
3206 x += 2 * ED_GADGET_DISTANCE;
3207 y -= ED_GADGET_DISTANCE;
3209 gd_x = DOOR_GFX_PAGEX6 + ED_WIN_COUNT2_XPOS;
3210 gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT2_YPOS;
3211 gd_width = ED_WIN_COUNT2_XSIZE;
3215 gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
3216 gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
3219 gi = CreateGadget(GDI_CUSTOM_ID, id,
3220 GDI_CUSTOM_TYPE_ID, i,
3221 GDI_INFO_TEXT, "enter counter value",
3224 GDI_TYPE, GD_TYPE_TEXTINPUT_NUMERIC,
3225 GDI_NUMBER_VALUE, 0,
3226 GDI_NUMBER_MIN, counterbutton_info[i].min_value,
3227 GDI_NUMBER_MAX, counterbutton_info[i].max_value,
3229 GDI_TEXT_FONT, font_type,
3230 GDI_TEXT_FONT_ACTIVE, font_type_active,
3231 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
3232 GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
3233 GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
3234 GDI_DESIGN_WIDTH, gd_width,
3235 GDI_EVENT_MASK, event_mask,
3236 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3237 GDI_CALLBACK_ACTION, HandleCounterButtons,
3241 Error(ERR_EXIT, "cannot create gadget");
3243 level_editor_gadget[id] = gi;
3244 right_gadget_border[id] =
3245 getRightGadgetBorder(gi, counterbutton_info[i].text_right);
3247 x += gi->width + ED_GADGET_DISTANCE; /* up count button */
3253 static void CreateDrawingAreas()
3257 for (i=0; i<ED_NUM_DRAWING_AREAS; i++)
3259 struct GadgetInfo *gi;
3260 unsigned long event_mask;
3261 int id = drawingarea_info[i].gadget_id;
3262 int x = SX + drawingarea_info[i].x;
3263 int y = SY + drawingarea_info[i].y;
3264 int area_xsize = drawingarea_info[i].area_xsize;
3265 int area_ysize = drawingarea_info[i].area_ysize;
3268 GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
3269 GD_EVENT_OFF_BORDERS;
3271 /* determine horizontal position to the right of specified gadget */
3272 if (drawingarea_info[i].gadget_id_align != GADGET_ID_NONE)
3273 x = (right_gadget_border[drawingarea_info[i].gadget_id_align] +
3274 ED_DRAWINGAREA_TEXT_DISTANCE);
3276 /* determine horizontal offset for leading text */
3277 if (drawingarea_info[i].text_left != NULL)
3278 x += getTextWidthForDrawingArea(drawingarea_info[i].text_left);
3280 gi = CreateGadget(GDI_CUSTOM_ID, id,
3281 GDI_CUSTOM_TYPE_ID, i,
3284 GDI_TYPE, GD_TYPE_DRAWING_AREA,
3285 GDI_AREA_SIZE, area_xsize, area_ysize,
3286 GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
3287 GDI_EVENT_MASK, event_mask,
3288 GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
3289 GDI_CALLBACK_ACTION, HandleDrawingAreas,
3293 Error(ERR_EXIT, "cannot create gadget");
3295 level_editor_gadget[id] = gi;
3296 right_gadget_border[id] =
3297 getRightGadgetBorder(gi, drawingarea_info[i].text_right);
3301 static void CreateTextInputGadgets()
3303 int max_infotext_len = getMaxInfoTextLength();
3306 for (i=0; i<ED_NUM_TEXTINPUT; i++)
3308 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3310 struct GadgetInfo *gi;
3311 unsigned long event_mask;
3312 char infotext[MAX_OUTPUT_LINESIZE + 1];
3313 int id = textinput_info[i].gadget_id;
3315 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
3317 gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
3318 gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
3320 sprintf(infotext, "Enter %s", textinput_info[i].infotext);
3321 infotext[max_infotext_len] = '\0';
3323 gi = CreateGadget(GDI_CUSTOM_ID, id,
3324 GDI_CUSTOM_TYPE_ID, i,
3325 GDI_INFO_TEXT, infotext,
3326 GDI_X, SX + textinput_info[i].x,
3327 GDI_Y, SY + textinput_info[i].y,
3328 GDI_TYPE, GD_TYPE_TEXTINPUT_ALPHANUMERIC,
3329 GDI_TEXT_VALUE, textinput_info[i].value,
3330 GDI_TEXT_SIZE, textinput_info[i].size,
3331 GDI_TEXT_FONT, FONT_INPUT_1,
3332 GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
3333 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
3334 GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
3335 GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
3336 GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
3337 GDI_EVENT_MASK, event_mask,
3338 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3339 GDI_CALLBACK_ACTION, HandleTextInputGadgets,
3343 Error(ERR_EXIT, "cannot create gadget");
3345 level_editor_gadget[id] = gi;
3349 static void CreateSelectboxGadgets()
3351 int max_infotext_len = getMaxInfoTextLength();
3354 for (i=0; i<ED_NUM_SELECTBOX; i++)
3356 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3358 struct GadgetInfo *gi;
3359 unsigned long event_mask;
3360 char infotext[MAX_OUTPUT_LINESIZE + 1];
3361 int id = selectbox_info[i].gadget_id;
3362 int x = SX + selectbox_info[i].x;
3363 int y = SY + selectbox_info[i].y;
3365 if (selectbox_info[i].size == -1) /* dynamically determine size */
3367 /* (we cannot use -1 for uninitialized values if we directly compare
3368 with results from strlen(), because the '<' and '>' operation will
3369 implicitely cast -1 to an unsigned integer value!) */
3370 selectbox_info[i].size = 0;
3372 for (j=0; selectbox_info[i].options[j].text != NULL; j++)
3373 if (strlen(selectbox_info[i].options[j].text) > selectbox_info[i].size)
3374 selectbox_info[i].size = strlen(selectbox_info[i].options[j].text);
3376 selectbox_info[i].size++; /* add one character empty space */
3379 event_mask = GD_EVENT_RELEASED |
3380 GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
3382 gd_x = DOOR_GFX_PAGEX4 + ED_SELECTBOX_XPOS;
3383 gd_y = DOOR_GFX_PAGEY1 + ED_SELECTBOX_YPOS;
3385 /* determine horizontal position to the right of specified gadget */
3386 if (selectbox_info[i].gadget_id_align != GADGET_ID_NONE)
3387 x = (right_gadget_border[selectbox_info[i].gadget_id_align] +
3388 ED_GADGET_TEXT_DISTANCE);
3390 /* determine horizontal offset for leading text */
3391 if (selectbox_info[i].text_left != NULL)
3392 x += getTextWidthForGadget(selectbox_info[i].text_left);
3394 sprintf(infotext, "Select %s", selectbox_info[i].infotext);
3395 infotext[max_infotext_len] = '\0';
3397 gi = CreateGadget(GDI_CUSTOM_ID, id,
3398 GDI_CUSTOM_TYPE_ID, i,
3399 GDI_INFO_TEXT, infotext,
3402 GDI_TYPE, GD_TYPE_SELECTBOX,
3403 GDI_SELECTBOX_OPTIONS, selectbox_info[i].options,
3404 GDI_TEXT_SIZE, selectbox_info[i].size,
3405 GDI_TEXT_FONT, FONT_INPUT_1,
3406 GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
3407 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
3408 GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
3409 GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
3410 GDI_BORDER_SIZE_SELECTBUTTON, ED_SELECTBOX_BUTTON_XSIZE,
3411 GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
3412 GDI_EVENT_MASK, event_mask,
3413 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3414 GDI_CALLBACK_ACTION, HandleSelectboxGadgets,
3418 Error(ERR_EXIT, "cannot create gadget");
3420 level_editor_gadget[id] = gi;
3421 right_gadget_border[id] =
3422 getRightGadgetBorder(gi, selectbox_info[i].text_right);
3426 static void CreateTextbuttonGadgets()
3428 int max_infotext_len = getMaxInfoTextLength();
3431 for (i=0; i<ED_NUM_TEXTBUTTON; i++)
3433 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3434 int gd_x1, gd_x2, gd_y1, gd_y2;
3435 struct GadgetInfo *gi;
3436 unsigned long event_mask;
3437 char infotext[MAX_OUTPUT_LINESIZE + 1];
3438 int id = textbutton_info[i].gadget_id;
3439 int x = SX + textbutton_info[i].x;
3440 int y = SY + textbutton_info[i].y;
3442 if (textbutton_info[i].size == -1) /* dynamically determine size */
3443 textbutton_info[i].size = strlen(textbutton_info[i].text);
3445 event_mask = GD_EVENT_RELEASED;
3447 if (id >= GADGET_ID_PROPERTIES_INFO && id <= GADGET_ID_PROPERTIES_ADVANCED)
3449 gd_x1 = DOOR_GFX_PAGEX4 + ED_TEXTBUTTON_TAB_XPOS;
3450 gd_x2 = DOOR_GFX_PAGEX3 + ED_TEXTBUTTON_TAB_XPOS;
3451 gd_y1 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_TAB_YPOS;
3452 gd_y2 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_TAB_INACTIVE_YPOS;
3456 gd_x1 = DOOR_GFX_PAGEX4 + ED_TEXTBUTTON_XPOS;
3457 gd_x2 = DOOR_GFX_PAGEX3 + ED_TEXTBUTTON_XPOS;
3458 gd_y1 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_YPOS;
3459 gd_y2 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_INACTIVE_YPOS;
3462 sprintf(infotext, "%s", textbutton_info[i].infotext);
3463 infotext[max_infotext_len] = '\0';
3465 /* determine horizontal position to the right of specified gadget */
3466 if (textbutton_info[i].gadget_id_align != GADGET_ID_NONE)
3467 x = (right_gadget_border[textbutton_info[i].gadget_id_align] +
3468 ED_GADGET_TEXT_DISTANCE);
3470 gi = CreateGadget(GDI_CUSTOM_ID, id,
3471 GDI_CUSTOM_TYPE_ID, i,
3472 GDI_INFO_TEXT, infotext,
3475 GDI_TYPE, GD_TYPE_TEXT_BUTTON,
3476 GDI_TEXT_VALUE, textbutton_info[i].text,
3477 GDI_TEXT_SIZE, textbutton_info[i].size,
3478 GDI_TEXT_FONT, FONT_INPUT_2_ACTIVE,
3479 GDI_TEXT_FONT_ACTIVE, FONT_INPUT_2,
3480 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
3481 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
3482 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
3483 GDI_BORDER_SIZE, ED_BORDER_TEXT_XSIZE, ED_BORDER_SIZE,
3484 GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
3485 GDI_DECORATION_SHIFTING, 1, 1,
3486 GDI_EVENT_MASK, event_mask,
3487 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3488 GDI_CALLBACK_ACTION, HandleTextbuttonGadgets,
3492 Error(ERR_EXIT, "cannot create gadget");
3494 level_editor_gadget[id] = gi;
3498 static void CreateScrollbarGadgets()
3502 for (i=0; i<ED_NUM_SCROLLBARS; i++)
3504 int id = scrollbar_info[i].gadget_id;
3505 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3506 int gd_x1, gd_x2, gd_y1, gd_y2;
3507 struct GadgetInfo *gi;
3508 int items_max, items_visible, item_position;
3509 unsigned long event_mask;
3511 if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
3513 items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
3514 items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
3515 item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
3517 else /* drawing area scrollbars */
3519 if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
3521 items_max = MAX(lev_fieldx + 2, ed_fieldx);
3522 items_visible = ed_fieldx;
3527 items_max = MAX(lev_fieldy + 2, ed_fieldy);
3528 items_visible = ed_fieldy;
3533 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
3535 gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].gd_x;
3536 gd_x2 = (gd_x1 - (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL ?
3537 scrollbar_info[i].height : scrollbar_info[i].width));
3538 gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
3539 gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
3541 gi = CreateGadget(GDI_CUSTOM_ID, id,
3542 GDI_CUSTOM_TYPE_ID, i,
3543 GDI_INFO_TEXT, scrollbar_info[i].infotext,
3544 GDI_X, scrollbar_info[i].x,
3545 GDI_Y, scrollbar_info[i].y,
3546 GDI_WIDTH, scrollbar_info[i].width,
3547 GDI_HEIGHT, scrollbar_info[i].height,
3548 GDI_TYPE, scrollbar_info[i].type,
3549 GDI_SCROLLBAR_ITEMS_MAX, items_max,
3550 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3551 GDI_SCROLLBAR_ITEM_POSITION, item_position,
3552 GDI_STATE, GD_BUTTON_UNPRESSED,
3553 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
3554 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
3555 GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
3556 GDI_EVENT_MASK, event_mask,
3557 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3558 GDI_CALLBACK_ACTION, HandleControlButtons,
3562 Error(ERR_EXIT, "cannot create gadget");
3564 level_editor_gadget[id] = gi;
3568 static void CreateCheckbuttonGadgets()
3570 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3571 struct GadgetInfo *gi;
3572 unsigned long event_mask;
3573 int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
3576 event_mask = GD_EVENT_PRESSED;
3578 gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
3579 gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
3580 gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
3581 gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
3582 gd_y = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
3584 for (i=0; i<ED_NUM_CHECKBUTTONS; i++)
3586 int id = checkbutton_info[i].gadget_id;
3587 int x = SX + checkbutton_info[i].x;
3588 int y = SY + checkbutton_info[i].y;
3590 if (id == GADGET_ID_STICK_ELEMENT)
3591 gd_y = DOOR_GFX_PAGEY1 + ED_STICKYBUTTON_YPOS;
3593 gd_y = DOOR_GFX_PAGEY1 + ED_CHECKBUTTON_YPOS;
3595 /* determine horizontal position to the right of specified gadget */
3596 if (checkbutton_info[i].gadget_id_align != GADGET_ID_NONE)
3597 x = (right_gadget_border[checkbutton_info[i].gadget_id_align] +
3598 ED_GADGET_TEXT_DISTANCE);
3600 /* determine horizontal offset for leading text */
3601 if (checkbutton_info[i].text_left != NULL)
3602 x += getTextWidthForGadget(checkbutton_info[i].text_left);
3604 gi = CreateGadget(GDI_CUSTOM_ID, id,
3605 GDI_CUSTOM_TYPE_ID, i,
3606 GDI_INFO_TEXT, checkbutton_info[i].infotext,
3609 GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
3610 GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
3611 GDI_TYPE, GD_TYPE_CHECK_BUTTON,
3612 GDI_CHECKED, *checkbutton_info[i].value,
3613 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
3614 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
3615 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
3616 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
3617 GDI_EVENT_MASK, event_mask,
3618 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3619 GDI_CALLBACK_ACTION, HandleCheckbuttons,
3623 Error(ERR_EXIT, "cannot create gadget");
3625 level_editor_gadget[id] = gi;
3626 right_gadget_border[id] =
3627 getRightGadgetBorder(gi, checkbutton_info[i].text_right);
3631 static void CreateRadiobuttonGadgets()
3633 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
3634 struct GadgetInfo *gi;
3635 unsigned long event_mask;
3636 int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
3639 event_mask = GD_EVENT_PRESSED;
3641 gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
3642 gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
3643 gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
3644 gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
3645 gd_y = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
3647 for (i=0; i<ED_NUM_RADIOBUTTONS; i++)
3649 int id = radiobutton_info[i].gadget_id;
3650 int x = SX + radiobutton_info[i].x;
3651 int y = SY + radiobutton_info[i].y;
3654 (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
3656 /* determine horizontal position to the right of specified gadget */
3657 if (radiobutton_info[i].gadget_id_align != GADGET_ID_NONE)
3658 x = (right_gadget_border[radiobutton_info[i].gadget_id_align] +
3659 ED_GADGET_TEXT_DISTANCE);
3661 /* determine horizontal offset for leading text */
3662 if (radiobutton_info[i].text_left != NULL)
3663 x += getTextWidthForGadget(radiobutton_info[i].text_left);
3665 gi = CreateGadget(GDI_CUSTOM_ID, id,
3666 GDI_CUSTOM_TYPE_ID, i,
3667 GDI_INFO_TEXT, radiobutton_info[i].infotext,
3670 GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
3671 GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
3672 GDI_TYPE, GD_TYPE_RADIO_BUTTON,
3673 GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
3674 GDI_CHECKED, checked,
3675 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
3676 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
3677 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
3678 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
3679 GDI_EVENT_MASK, event_mask,
3680 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
3681 GDI_CALLBACK_ACTION, HandleRadiobuttons,
3685 Error(ERR_EXIT, "cannot create gadget");
3687 level_editor_gadget[id] = gi;
3688 right_gadget_border[id] =
3689 getRightGadgetBorder(gi, radiobutton_info[i].text_right);
3693 void CreateLevelEditorGadgets()
3695 int old_game_status = game_status;
3697 /* setting 'game_status' is needed to get the right fonts for the editor */
3698 game_status = GAME_MODE_EDITOR;
3700 ReinitializeElementList();
3702 CreateControlButtons();
3703 CreateScrollbarGadgets();
3705 /* order of function calls is important because of cross-references */
3706 CreateCheckbuttonGadgets();
3707 CreateCounterButtons();
3708 CreateRadiobuttonGadgets();
3709 CreateTextInputGadgets();
3710 CreateTextbuttonGadgets();
3711 CreateSelectboxGadgets();
3712 CreateDrawingAreas();
3714 game_status = old_game_status;
3717 void FreeLevelEditorGadgets()
3721 for (i=0; i<NUM_EDITOR_GADGETS; i++)
3722 FreeGadget(level_editor_gadget[i]);
3725 static void MapCounterButtons(int id)
3727 int gadget_id_down = counterbutton_info[id].gadget_id_down;
3728 int gadget_id_up = counterbutton_info[id].gadget_id_up;
3729 struct GadgetInfo *gi_down = level_editor_gadget[gadget_id_down];
3730 struct GadgetInfo *gi_up = level_editor_gadget[gadget_id_up];
3732 char infotext[MAX_OUTPUT_LINESIZE + 1];
3733 int max_infotext_len = getMaxInfoTextLength();
3734 int xoffset_left = 0;
3735 int yoffset_left = ED_BORDER_SIZE;
3736 int xoffset_right = getCounterGadgetWidth();
3737 int yoffset_right = ED_BORDER_SIZE;
3739 int xoffset_left = getTextWidthForGadget(counterbutton_info[id].text_left);
3740 int xoffset_right = ED_GADGET_TEXT_DISTANCE;
3741 int yoffset_above = MINI_TILEX + ED_GADGET_DISTANCE;
3742 int yoffset = ED_BORDER_SIZE;
3743 int x_left = gi_down->x - xoffset_left;
3744 int x_right = gi_up->x + gi_up->width + xoffset_right;
3745 int y_above = gi_down->y - yoffset_above;
3747 int y = gi_up->y + yoffset;
3750 if (counterbutton_info[id].text_above)
3751 DrawText(x, y_above, counterbutton_info[id].text_above, FONT_TEXT_1);
3753 if (counterbutton_info[id].text_left)
3754 DrawText(x_left, y, counterbutton_info[id].text_left, FONT_TEXT_1);
3756 if (counterbutton_info[id].text_right)
3757 DrawText(x_right, y, counterbutton_info[id].text_right, FONT_TEXT_1);
3759 ModifyEditorCounter(id, *counterbutton_info[id].value);
3761 MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_down]);
3762 MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_text]);
3763 MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_up]);
3766 static void MapControlButtons()
3771 /* map toolbox buttons */
3772 for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
3773 MapGadget(level_editor_gadget[i]);
3775 /* map buttons to select elements */
3776 for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
3777 MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
3778 MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
3779 MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
3780 MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
3782 /* map buttons to select level */
3783 counter_id = ED_COUNTER_ID_SELECT_LEVEL;
3784 ModifyEditorCounterLimits(counter_id,
3785 leveldir_current->first_level,
3786 leveldir_current->last_level);
3787 MapCounterButtons(counter_id);
3790 static void MapDrawingArea(int id)
3792 struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
3793 int area_xsize = gi->drawing.area_xsize;
3794 int area_ysize = gi->drawing.area_ysize;
3795 int xoffset_left= getTextWidthForDrawingArea(drawingarea_info[id].text_left);
3796 int xoffset_below= getTextWidth(drawingarea_info[id].text_below,FONT_TEXT_1);
3797 int x_left = gi->x - xoffset_left;
3798 int x_right = gi->x + gi->width + ED_DRAWINGAREA_TEXT_DISTANCE;
3799 int x_below = gi->x + (gi->width - xoffset_below) / 2;
3800 int y_side = gi->y + (gi->height - getFontHeight(FONT_TEXT_1)) / 2;
3801 int y_below = gi->y + gi->height + ED_DRAWINGAREA_TEXT_DISTANCE;
3803 if (drawingarea_info[id].text_left)
3804 DrawText(x_left, y_side, drawingarea_info[id].text_left, FONT_TEXT_1);
3806 if (drawingarea_info[id].text_right)
3807 DrawText(x_right, y_side, drawingarea_info[id].text_right, FONT_TEXT_1);
3809 if (drawingarea_info[id].text_below)
3810 DrawText(x_below, y_below, drawingarea_info[id].text_below, FONT_TEXT_1);
3812 if (id != ED_DRAWING_ID_DRAWING_LEVEL)
3814 DrawElementBorder(gi->x, gi->y,
3815 area_xsize * MINI_TILEX, area_ysize * MINI_TILEY, TRUE);
3817 DrawDrawingArea(id);
3823 static void MapTextInputGadget(int id)
3825 struct GadgetInfo *gi = level_editor_gadget[textinput_info[id].gadget_id];
3826 char infotext[MAX_OUTPUT_LINESIZE + 1];
3827 int max_infotext_len = getMaxInfoTextLength();
3828 int xoffset_above = 0;
3829 int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
3830 int x = textinput_info[id].x + xoffset_above;
3831 int y = textinput_info[id].y + yoffset_above;
3833 if (textinput_info[id].infotext)
3835 sprintf(infotext, "%s:", textinput_info[id].infotext);
3836 infotext[max_infotext_len] = '\0';
3837 DrawTextF(x, y, FONT_TEXT_1, infotext);
3840 ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
3845 static void MapSelectboxGadget(int id)
3847 struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
3848 int xoffset_left = getTextWidthForGadget(selectbox_info[id].text_left);
3849 int xoffset_right = ED_GADGET_TEXT_DISTANCE;
3850 int yoffset = ED_BORDER_SIZE;
3851 int x_left = gi->x - xoffset_left;
3852 int x_right = gi->x + gi->width + xoffset_right;
3853 int y = gi->y + yoffset;
3855 if (selectbox_info[id].text_left)
3856 DrawText(x_left, y, selectbox_info[id].text_left, FONT_TEXT_1);
3858 if (selectbox_info[id].text_right)
3859 DrawText(x_right, y, selectbox_info[id].text_right, FONT_TEXT_1);
3861 ModifyEditorSelectbox(id, *selectbox_info[id].value);
3866 static void MapTextbuttonGadget(int id)
3868 struct GadgetInfo *gi = level_editor_gadget[textbutton_info[id].gadget_id];
3873 static void MapRadiobuttonGadget(int id)
3875 struct GadgetInfo *gi = level_editor_gadget[radiobutton_info[id].gadget_id];
3877 int xoffset_right = ED_XOFFSET_CHECKBOX;
3878 int yoffset_right = ED_BORDER_SIZE;
3879 int x = radiobutton_info[id].x + xoffset_right;
3880 int y = radiobutton_info[id].y + yoffset_right;
3882 int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
3883 int xoffset_right = ED_GADGET_TEXT_DISTANCE;
3884 int yoffset = ED_BORDER_SIZE;
3885 int x_left = gi->x - xoffset_left;
3886 int x_right = gi->x + gi->width + xoffset_right;
3887 int y = gi->y + yoffset;
3890 (*radiobutton_info[id].value == radiobutton_info[id].checked_value);
3892 if (radiobutton_info[id].text_left)
3893 DrawText(x_left, y, radiobutton_info[id].text_left, FONT_TEXT_1);
3895 if (radiobutton_info[id].text_right)
3896 DrawText(x_right, y, radiobutton_info[id].text_right, FONT_TEXT_1);
3898 ModifyGadget(gi, GDI_CHECKED, checked, GDI_END);
3903 static void MapCheckbuttonGadget(int id)
3905 struct GadgetInfo *gi = level_editor_gadget[checkbutton_info[id].gadget_id];
3907 int xoffset_right = ED_XOFFSET_CHECKBOX;
3908 int yoffset_right = ED_BORDER_SIZE;
3909 int x = checkbutton_info[id].x + xoffset_right;
3910 int y = checkbutton_info[id].y + yoffset_right;
3912 int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
3913 int xoffset_right = ED_GADGET_TEXT_DISTANCE;
3914 int yoffset = ED_BORDER_SIZE;
3915 int x_left = gi->x - xoffset_left;
3916 int x_right = gi->x + gi->width + xoffset_right;
3917 int y = gi->y + yoffset;
3920 /* special case needed for "sticky" gadget */
3921 ModifyGadget(gi, GDI_CHECKED, *checkbutton_info[id].value,
3922 GDI_Y, SY + checkbutton_info[id].y, GDI_END);
3923 y = gi->y + yoffset;
3925 if (checkbutton_info[id].text_left)
3926 DrawText(x_left, y, checkbutton_info[id].text_left, FONT_TEXT_1);
3928 if (checkbutton_info[id].text_right)
3929 DrawText(x_right, y, checkbutton_info[id].text_right, FONT_TEXT_1);
3934 static void MapMainDrawingArea()
3936 boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
3937 boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
3940 for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i<=ED_SCROLLBUTTON_ID_AREA_LAST; i++)
3942 if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
3943 i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
3944 no_horizontal_scrollbar) ||
3945 ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
3946 i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
3947 no_vertical_scrollbar))
3950 MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
3953 for (i=ED_SCROLLBAR_ID_AREA_FIRST; i<=ED_SCROLLBAR_ID_AREA_LAST; i++)
3955 if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
3956 (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
3959 MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
3962 MapDrawingArea(ED_DRAWING_ID_DRAWING_LEVEL);
3965 static void UnmapDrawingArea(int id)
3967 UnmapGadget(level_editor_gadget[id]);
3970 void UnmapLevelEditorWindowGadgets()
3974 for (i=0; i<NUM_EDITOR_GADGETS; i++)
3975 if (level_editor_gadget[i]->x < SX + SXSIZE)
3976 UnmapGadget(level_editor_gadget[i]);
3979 void UnmapLevelEditorGadgets()
3983 for (i=0; i<NUM_EDITOR_GADGETS; i++)
3984 UnmapGadget(level_editor_gadget[i]);
3987 static void ResetUndoBuffer()
3989 undo_buffer_position = -1;
3990 undo_buffer_steps = -1;
3991 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3994 static void DrawEditModeWindow()
3996 ModifyEditorElementList();
3997 RedrawDrawingElements();
3999 if (edit_mode == ED_MODE_INFO)
4000 DrawLevelInfoWindow();
4001 else if (edit_mode == ED_MODE_PROPERTIES)
4002 DrawPropertiesWindow();
4003 else /* edit_mode == ED_MODE_DRAWING */
4004 DrawDrawingWindow();
4007 static boolean LevelChanged()
4009 boolean level_changed = FALSE;
4012 for(y=0; y<lev_fieldy; y++)
4013 for(x=0; x<lev_fieldx; x++)
4014 if (Feld[x][y] != level.field[x][y])
4015 level_changed = TRUE;
4017 return level_changed;
4020 static boolean LevelContainsPlayer()
4022 boolean player_found = FALSE;
4025 for(y=0; y<lev_fieldy; y++)
4026 for(x=0; x<lev_fieldx; x++)
4027 if (Feld[x][y] == EL_PLAYER_1 ||
4028 Feld[x][y] == EL_SP_MURPHY)
4029 player_found = TRUE;
4031 return player_found;
4034 static void CopyPlayfield(short src[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
4035 short dst[MAX_LEV_FIELDX][MAX_LEV_FIELDY])
4039 for(x=0; x<lev_fieldx; x++)
4040 for(y=0; y<lev_fieldy; y++)
4041 dst[x][y] = src[x][y];
4044 static int SetSelectboxValue(int selectbox_id, int new_value)
4046 int new_index_value = 0;
4049 for(i=0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
4050 if (selectbox_info[selectbox_id].options[i].value == new_value)
4051 new_index_value = i;
4053 *selectbox_info[selectbox_id].value =
4054 selectbox_info[selectbox_id].options[new_index_value].value;
4056 return new_index_value;
4059 static void CopyCustomElementPropertiesToEditor(int element)
4063 /* needed here to initialize combined element properties */
4064 InitElementPropertiesEngine(level.game_version);
4066 custom_element = element_info[element];
4068 /* needed to initially set selectbox value variables to reliable defaults */
4069 for (i=0; i < ED_NUM_SELECTBOX; i++)
4070 SetSelectboxValue(i, *selectbox_info[i].value);
4072 for (i=0; i < NUM_ELEMENT_PROPERTIES; i++)
4073 custom_element_properties[i] = HAS_PROPERTY(element, i);
4075 for (i=0; i < NUM_CHANGE_EVENTS; i++)
4076 custom_element_change_events[i] = HAS_CHANGE_EVENT(element, i);
4078 /* ---------- element settings: configure (custom elements) ------------- */
4080 /* set accessible layer selectbox help value */
4081 custom_element.access_type =
4082 (IS_WALKABLE(element) ? EP_WALKABLE :
4083 IS_PASSABLE(element) ? EP_PASSABLE :
4084 custom_element.access_type);
4085 custom_element.access_layer =
4086 (IS_ACCESSIBLE_OVER(element) ? EP_ACCESSIBLE_OVER :
4087 IS_ACCESSIBLE_INSIDE(element) ? EP_ACCESSIBLE_INSIDE :
4088 IS_ACCESSIBLE_UNDER(element) ? EP_ACCESSIBLE_UNDER :
4089 custom_element.access_layer);
4090 custom_element_properties[EP_ACCESSIBLE] =
4091 (IS_ACCESSIBLE_OVER(element) ||
4092 IS_ACCESSIBLE_INSIDE(element) ||
4093 IS_ACCESSIBLE_UNDER(element));
4095 /* set walk-to-object action selectbox help value */
4096 custom_element.walk_to_action =
4097 (IS_DIGGABLE(element) ? EP_DIGGABLE :
4098 IS_COLLECTIBLE_ONLY(element) ? EP_COLLECTIBLE_ONLY :
4099 IS_DROPPABLE(element) ? EP_DROPPABLE :
4100 IS_PUSHABLE(element) ? EP_PUSHABLE :
4101 custom_element.walk_to_action);
4102 custom_element_properties[EP_WALK_TO_OBJECT] =
4103 (IS_DIGGABLE(element) ||
4104 IS_COLLECTIBLE_ONLY(element) ||
4105 IS_DROPPABLE(element) ||
4106 IS_PUSHABLE(element));
4108 /* set smash targets selectbox help value */
4109 custom_element.smash_targets =
4110 (CAN_SMASH_EVERYTHING(element) ? EP_CAN_SMASH_EVERYTHING :
4111 CAN_SMASH_ENEMIES(element) ? EP_CAN_SMASH_ENEMIES :
4112 CAN_SMASH_PLAYER(element) ? EP_CAN_SMASH_PLAYER :
4113 custom_element.smash_targets);
4114 custom_element_properties[EP_CAN_SMASH] =
4115 (CAN_SMASH_EVERYTHING(element) ||
4116 CAN_SMASH_ENEMIES(element) ||
4117 CAN_SMASH_PLAYER(element));
4119 /* set deadliness selectbox help value */
4120 custom_element.deadliness =
4121 (DONT_TOUCH(element) ? EP_DONT_TOUCH :
4122 DONT_COLLIDE_WITH(element) ? EP_DONT_COLLIDE_WITH :
4123 DONT_RUN_INTO(element) ? EP_DONT_RUN_INTO :
4124 custom_element.deadliness);
4125 custom_element_properties[EP_DEADLY] =
4126 (DONT_TOUCH(element) ||
4127 DONT_COLLIDE_WITH(element) ||
4128 DONT_RUN_INTO(element));
4130 /* set consistency selectbox help value */
4131 custom_element.consistency =
4132 (IS_INDESTRUCTIBLE(element) ? EP_INDESTRUCTIBLE :
4133 CAN_EXPLODE_1X1(element) ? EP_CAN_EXPLODE_1X1 :
4134 CAN_EXPLODE_3X3(element) ? EP_CAN_EXPLODE_3X3 :
4135 custom_element.consistency);
4136 custom_element_properties[EP_EXPLODE_RESULT] =
4137 (IS_INDESTRUCTIBLE(element) ||
4138 CAN_EXPLODE_1X1(element) ||
4139 CAN_EXPLODE_3X3(element));
4141 /* special case: sub-settings dependent from main setting */
4142 if (CAN_EXPLODE_BY_FIRE(element))
4143 custom_element.can_explode_by_fire = TRUE;
4144 if (CAN_EXPLODE_SMASHED(element))
4145 custom_element.can_explode_smashed = TRUE;
4146 if (CAN_EXPLODE_IMPACT(element))
4147 custom_element.can_explode_impact = TRUE;
4149 /* ---------- element settings: advanced (custom elements) --------------- */
4151 /* set change by player selectbox help value */
4152 custom_element.change_player_action =
4153 (HAS_CHANGE_EVENT(element, CE_DROPPED_BY_PLAYER) ? CE_DROPPED_BY_PLAYER :
4154 HAS_CHANGE_EVENT(element, CE_PUSHED_BY_PLAYER) ? CE_PUSHED_BY_PLAYER :
4155 HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
4156 HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
4157 custom_element.change_player_action);
4159 /* set change by collision selectbox help value */
4160 custom_element.change_collide_action =
4161 (HAS_CHANGE_EVENT(element, CE_SMASHED) ? CE_SMASHED :
4162 HAS_CHANGE_EVENT(element, CE_IMPACT) ? CE_IMPACT :
4163 HAS_CHANGE_EVENT(element, CE_COLLISION) ? CE_COLLISION :
4164 custom_element.change_collide_action);
4166 /* set change by other element action selectbox help value */
4167 custom_element.change_other_action =
4168 (HAS_CHANGE_EVENT(element, CE_OTHER_GETS_DROPPED) ? CE_OTHER_GETS_DROPPED :
4169 HAS_CHANGE_EVENT(element, CE_OTHER_GETS_COLLECTED) ? CE_OTHER_GETS_COLLECTED :
4170 HAS_CHANGE_EVENT(element, CE_OTHER_GETS_PUSHED) ? CE_OTHER_GETS_PUSHED :
4171 HAS_CHANGE_EVENT(element, CE_OTHER_GETS_PRESSED) ? CE_OTHER_GETS_PRESSED :
4172 HAS_CHANGE_EVENT(element, CE_OTHER_GETS_TOUCHED) ? CE_OTHER_GETS_TOUCHED :
4173 HAS_CHANGE_EVENT(element, CE_OTHER_IS_EXPLODING) ? CE_OTHER_IS_EXPLODING :
4174 HAS_CHANGE_EVENT(element, CE_OTHER_IS_CHANGING) ? CE_OTHER_IS_CHANGING :
4175 HAS_CHANGE_EVENT(element, CE_OTHER_IS_TOUCHING) ? CE_OTHER_IS_TOUCHING :
4176 custom_element.change_other_action);
4179 static void CopyCustomElementPropertiesToGame(int element)
4182 int access_type_and_layer;
4184 /* mark that this custom element has been modified */
4185 custom_element.modified_settings = TRUE;
4187 if (level.use_custom_template)
4189 if (Request("Copy and modify level tem- plate ?", REQ_ASK))
4191 level.use_custom_template = FALSE;
4192 ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE],
4193 GDI_CHECKED, FALSE, GDI_END);
4197 LoadLevelTemplate(-1); /* this resets all element modifications ... */
4199 DrawEditModeWindow(); /* ... and copies them to 'custom_element' */
4203 element_info[element] = custom_element;
4205 /* ---------- element settings: configure (custom elements) ------------- */
4207 /* set accessible property from checkbox and selectbox */
4208 custom_element_properties[EP_WALKABLE_OVER] = FALSE;
4209 custom_element_properties[EP_WALKABLE_INSIDE] = FALSE;
4210 custom_element_properties[EP_WALKABLE_UNDER] = FALSE;
4211 custom_element_properties[EP_PASSABLE_OVER] = FALSE;
4212 custom_element_properties[EP_PASSABLE_INSIDE] = FALSE;
4213 custom_element_properties[EP_PASSABLE_UNDER] = FALSE;
4214 access_type_and_layer = ((custom_element.access_type == EP_WALKABLE ?
4215 EP_WALKABLE_OVER : EP_PASSABLE_OVER) +
4216 (custom_element.access_layer - EP_ACCESSIBLE_OVER));
4217 custom_element_properties[access_type_and_layer] =
4218 custom_element_properties[EP_ACCESSIBLE];
4220 /* set walk-to-object property from checkbox and selectbox */
4221 custom_element_properties[EP_DIGGABLE] = FALSE;
4222 custom_element_properties[EP_COLLECTIBLE_ONLY] = FALSE;
4223 custom_element_properties[EP_DROPPABLE] = FALSE;
4224 custom_element_properties[EP_PUSHABLE] = FALSE;
4225 custom_element_properties[custom_element.walk_to_action] =
4226 custom_element_properties[EP_WALK_TO_OBJECT];
4228 /* set smash property from checkbox and selectbox */
4229 custom_element_properties[EP_CAN_SMASH_PLAYER] = FALSE;
4230 custom_element_properties[EP_CAN_SMASH_ENEMIES] = FALSE;
4231 custom_element_properties[EP_CAN_SMASH_EVERYTHING] = FALSE;
4232 custom_element_properties[custom_element.smash_targets] =
4233 custom_element_properties[EP_CAN_SMASH];
4235 /* set deadliness property from checkbox and selectbox */
4236 custom_element_properties[EP_DONT_RUN_INTO] = FALSE;
4237 custom_element_properties[EP_DONT_COLLIDE_WITH] = FALSE;
4238 custom_element_properties[EP_DONT_TOUCH] = FALSE;
4239 custom_element_properties[custom_element.deadliness] =
4240 custom_element_properties[EP_DEADLY];
4242 /* set consistency property from checkbox and selectbox */
4243 custom_element_properties[EP_INDESTRUCTIBLE] = FALSE;
4244 custom_element_properties[EP_CAN_EXPLODE_1X1] = FALSE;
4245 custom_element_properties[EP_CAN_EXPLODE_3X3] = FALSE;
4246 custom_element_properties[EP_CAN_EXPLODE_BY_FIRE] = FALSE;
4247 custom_element_properties[EP_CAN_EXPLODE_SMASHED] = FALSE;
4248 custom_element_properties[EP_CAN_EXPLODE_IMPACT] = FALSE;
4249 custom_element_properties[custom_element.consistency] =
4250 custom_element_properties[EP_EXPLODE_RESULT];
4252 /* special case: sub-settings dependent from main setting */
4253 if (custom_element_properties[EP_CAN_EXPLODE_3X3] ||
4254 custom_element_properties[EP_CAN_EXPLODE_1X1])
4256 custom_element_properties[EP_CAN_EXPLODE_BY_FIRE] =
4257 custom_element.can_explode_by_fire;
4258 custom_element_properties[EP_CAN_EXPLODE_SMASHED] =
4259 custom_element.can_explode_smashed;
4260 custom_element_properties[EP_CAN_EXPLODE_IMPACT] =
4261 custom_element.can_explode_impact;
4264 /* ---------- element settings: advanced (custom elements) --------------- */
4266 /* set player change event from checkbox and selectbox */
4267 custom_element_change_events[CE_TOUCHED_BY_PLAYER] = FALSE;
4268 custom_element_change_events[CE_PRESSED_BY_PLAYER] = FALSE;
4269 custom_element_change_events[CE_PUSHED_BY_PLAYER] = FALSE;
4270 custom_element_change_events[CE_DROPPED_BY_PLAYER] = FALSE;
4271 custom_element_change_events[custom_element.change_player_action] =
4272 custom_element_change_events[CE_BY_PLAYER];
4274 /* set collision change event from checkbox and selectbox */
4275 custom_element_change_events[CE_COLLISION] = FALSE;
4276 custom_element_change_events[CE_IMPACT] = FALSE;
4277 custom_element_change_events[CE_SMASHED] = FALSE;
4278 custom_element_change_events[custom_element.change_collide_action] =
4279 custom_element_change_events[CE_BY_COLLISION];
4281 /* set other element action change event from checkbox and selectbox */
4282 custom_element_change_events[CE_OTHER_IS_TOUCHING] = FALSE;
4283 custom_element_change_events[CE_OTHER_IS_CHANGING] = FALSE;
4284 custom_element_change_events[CE_OTHER_IS_EXPLODING] = FALSE;
4285 custom_element_change_events[CE_OTHER_GETS_TOUCHED] = FALSE;
4286 custom_element_change_events[CE_OTHER_GETS_PRESSED] = FALSE;
4287 custom_element_change_events[CE_OTHER_GETS_PUSHED] = FALSE;
4288 custom_element_change_events[CE_OTHER_GETS_COLLECTED] = FALSE;
4289 custom_element_change_events[CE_OTHER_GETS_DROPPED] = FALSE;
4290 custom_element_change_events[custom_element.change_other_action] =
4291 custom_element_change_events[CE_BY_OTHER];
4293 for (i=0; i < NUM_ELEMENT_PROPERTIES; i++)
4294 SET_PROPERTY(element, i, custom_element_properties[i]);
4296 for (i=0; i < NUM_CHANGE_EVENTS; i++)
4297 SET_CHANGE_EVENT(element, i, custom_element_change_events[i]);
4299 /* copy change events also to special level editor variable */
4300 custom_element = element_info[element];
4305 CloseDoor(DOOR_CLOSE_ALL);
4306 OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY);
4308 if (level_editor_test_game)
4310 CopyPlayfield(level.field, Feld);
4311 CopyPlayfield(FieldBackup, level.field);
4313 level_editor_test_game = FALSE;
4317 edit_mode = ED_MODE_DRAWING;
4318 edit_mode_properties = ED_MODE_PROPERTIES_INFO;
4326 /* copy default editor door content to main double buffer */
4327 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
4328 DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
4331 /* draw mouse button brush elements */
4332 RedrawDrawingElements();
4335 /* draw bigger door */
4336 DrawSpecialEditorDoor();
4338 /* draw new control window */
4339 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
4340 DOOR_GFX_PAGEX8, 236, EXSIZE, EYSIZE, EX, EY);
4342 redraw_mask |= REDRAW_ALL;
4344 ReinitializeElementListButtons(); /* only needed after setup changes */
4346 ModifyEditorElementList(); /* may be needed for custom elements */
4350 MapControlButtons();
4352 DrawEditModeWindow();
4354 /* copy actual editor door content to door double buffer for OpenDoor() */
4355 BlitBitmap(drawto, bitmap_db_door,
4356 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
4358 OpenDoor(DOOR_OPEN_1);
4361 static void AdjustDrawingAreaGadgets()
4363 int ed_xsize = lev_fieldx + 2;
4364 int ed_ysize = lev_fieldy + 2;
4365 int max_ed_fieldx = MAX_ED_FIELDX;
4366 int max_ed_fieldy = MAX_ED_FIELDY;
4367 boolean horizontal_scrollbar_needed;
4368 boolean vertical_scrollbar_needed;
4369 int x, y, width, height;
4370 int xoffset, yoffset;
4372 /* check if we need any scrollbars */
4373 horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
4374 vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
4376 /* check if we have a smaller editor field because of scrollbars */
4377 if (horizontal_scrollbar_needed)
4378 max_ed_fieldy = MAX_ED_FIELDY - 1;
4379 if (vertical_scrollbar_needed)
4380 max_ed_fieldx = MAX_ED_FIELDX - 1;
4382 /* check again if we now need more scrollbars because of less space */
4383 horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
4384 vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
4386 /* check if editor field gets even smaller after adding new scrollbars */
4387 if (horizontal_scrollbar_needed)
4388 max_ed_fieldy = MAX_ED_FIELDY - 1;
4389 if (vertical_scrollbar_needed)
4390 max_ed_fieldx = MAX_ED_FIELDX - 1;
4392 ed_fieldx = (ed_xsize < MAX_ED_FIELDX ? ed_xsize : max_ed_fieldx);
4393 ed_fieldy = (ed_ysize < MAX_ED_FIELDY ? ed_ysize : max_ed_fieldy);
4395 ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
4396 GDI_WIDTH, ed_fieldx * MINI_TILEX,
4397 GDI_HEIGHT, ed_fieldy * MINI_TILEY,
4398 GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
4401 xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0);
4402 yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0);
4404 x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
4405 y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
4407 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT], GDI_X, x, GDI_END);
4408 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN], GDI_Y, y, GDI_END);
4410 width = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
4411 height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
4413 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
4415 GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
4417 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
4419 GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
4423 static void AdjustLevelScrollPosition()
4425 if (level_xpos < -1)
4427 if (level_xpos > lev_fieldx - ed_fieldx + 1)
4428 level_xpos = lev_fieldx - ed_fieldx + 1;
4429 if (lev_fieldx < ed_fieldx - 2)
4432 if (level_ypos < -1)
4434 if (level_ypos > lev_fieldy - ed_fieldy + 1)
4435 level_ypos = lev_fieldy - ed_fieldy + 1;
4436 if (lev_fieldy < ed_fieldy - 2)
4440 static void AdjustEditorScrollbar(int id)
4442 struct GadgetInfo *gi = level_editor_gadget[id];
4443 int items_max, items_visible, item_position;
4445 if (id == GADGET_ID_SCROLL_HORIZONTAL)
4447 items_max = MAX(lev_fieldx + 2, ed_fieldx);
4448 items_visible = ed_fieldx;
4449 item_position = level_xpos + 1;
4453 items_max = MAX(lev_fieldy + 2, ed_fieldy);
4454 items_visible = ed_fieldy;
4455 item_position = level_ypos + 1;
4458 if (item_position > items_max - items_visible)
4459 item_position = items_max - items_visible;
4461 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
4462 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
4465 static void ModifyEditorCounter(int counter_id, int new_value)
4467 int *counter_value = counterbutton_info[counter_id].value;
4468 int gadget_id = counterbutton_info[counter_id].gadget_id_text;
4469 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
4471 ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
4473 if (counter_value != NULL)
4474 *counter_value = gi->text.number_value;
4477 static void ModifyEditorCounterLimits(int counter_id, int min, int max)
4479 int gadget_id = counterbutton_info[counter_id].gadget_id_text;
4480 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
4482 ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
4485 static void ModifyEditorSelectbox(int selectbox_id, int new_value)
4487 int gadget_id = selectbox_info[selectbox_id].gadget_id;
4488 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
4489 int new_index_value = SetSelectboxValue(selectbox_id, new_value);
4491 ModifyGadget(gi, GDI_SELECTBOX_INDEX, new_index_value, GDI_END);
4494 static void ModifyEditorElementList()
4498 for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
4500 int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
4501 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
4502 struct GadgetDesign *gd = &gi->deco.design;
4503 int element = editor_elements[element_shift + i];
4506 getMiniGraphicSource(el2edimg(element), &gd->bitmap, &gd->x, &gd->y);
4507 ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
4512 static void PickDrawingElement(int button, int element)
4514 if (button < 1 || button > 3)
4519 new_element1 = element;
4520 DrawMiniGraphicExt(drawto,
4521 DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
4522 el2edimg(new_element1));
4524 else if (button == 2)
4526 new_element2 = element;
4527 DrawMiniGraphicExt(drawto,
4528 DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
4529 el2edimg(new_element2));
4533 new_element3 = element;
4534 DrawMiniGraphicExt(drawto,
4535 DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
4536 el2edimg(new_element3));
4539 redraw_mask |= REDRAW_DOOR_1;
4542 static void RedrawDrawingElements()
4544 PickDrawingElement(1, new_element1);
4545 PickDrawingElement(2, new_element2);
4546 PickDrawingElement(3, new_element3);
4549 static void DrawDrawingWindow()
4551 stick_element_properties_window = FALSE;
4553 SetMainBackgroundImage(IMG_UNDEFINED);
4555 UnmapLevelEditorWindowGadgets();
4557 AdjustDrawingAreaGadgets();
4558 AdjustLevelScrollPosition();
4559 AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
4560 AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
4562 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
4563 MapMainDrawingArea();
4566 static void DrawLevelInfoWindow()
4570 stick_element_properties_window = FALSE;
4572 SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
4574 UnmapLevelEditorWindowGadgets();
4576 DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS,
4577 "Level Settings", FONT_TITLE_1);
4578 DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS2_YPOS,
4579 "Editor Settings", FONT_TITLE_1);
4581 /* draw counter gadgets */
4582 for (i=ED_COUNTER_ID_LEVEL_FIRST; i<=ED_COUNTER_ID_LEVEL_LAST; i++)
4583 MapCounterButtons(i);
4585 /* draw checkbutton gadgets */
4586 for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i<=ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
4587 MapCheckbuttonGadget(i);
4589 /* draw radiobutton gadgets */
4590 for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i<=ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
4591 MapRadiobuttonGadget(i);
4593 /* draw text input gadgets */
4594 for (i=ED_TEXTINPUT_ID_LEVEL_FIRST; i<=ED_TEXTINPUT_ID_LEVEL_LAST; i++)
4595 MapTextInputGadget(i);
4597 /* draw drawing area */
4598 MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
4601 static void DrawCustomContentArea()
4603 int id = ED_DRAWING_ID_CUSTOM_CONTENT;
4604 struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
4605 int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
4606 int x2 = right_gadget_border[GADGET_ID_CUSTOM_CONSISTENCY];
4607 int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
4608 int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
4610 /* add distance for potential left text (without drawing area border) */
4611 x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
4613 ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
4615 MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
4618 static void DrawCustomChangeContentArea()
4620 int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
4621 struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
4622 int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
4623 int x2 = right_gadget_border[GADGET_ID_CHANGE_POWER];
4624 int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
4625 int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
4627 ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
4632 static void DrawElementContentAreas()
4634 int x = SX + ED_AREA_YAMYAM_CONTENT_XPOS(3) + 4 * MINI_TILEX;
4635 int y = SY + ED_AREA_YAMYAM_CONTENT_YPOS(0) + ED_BORDER_AREA_YSIZE;
4638 /* display counter to choose number of element content areas */
4639 MapCounterButtons(ED_COUNTER_ID_ELEMENT_CONTENT);
4641 for (i=0; i < MAX_ELEMENT_CONTENTS; i++)
4643 int id = ED_DRAWING_ID_ELEMENT_CONTENT_0 + i;
4644 int font_height = getFontHeight(FONT_TEXT_1);
4646 if (i < level.num_yamyam_contents)
4650 UnmapDrawingArea(id);
4652 /* delete content areas in case of reducing number of them */
4653 DrawBackground(SX + drawingarea_info[id].x - MINI_TILEX / 2,
4654 SY + drawingarea_info[id].y - MINI_TILEY / 2,
4656 4 * MINI_TILEX + ED_GADGET_TEXT_DISTANCE + font_height);
4660 DrawText(x, y + 0 * MINI_TILEY, "content", FONT_TEXT_1);
4661 DrawText(x, y + 1 * MINI_TILEY, "when", FONT_TEXT_1);
4662 DrawText(x, y + 2 * MINI_TILEY, "smashed", FONT_TEXT_1);
4665 char *getElementDescriptionFilename(int element)
4667 char *docs_dir = options.docs_directory;
4668 char *elements_subdir = "elements";
4669 static char *filename = NULL;
4670 char basename[MAX_FILENAME_LEN];
4672 if (filename != NULL)
4675 /* 1st try: look for element description file for exactly this element */
4676 sprintf(basename, "%s.txt", element_info[element].token_name);
4677 filename = getPath3(docs_dir, elements_subdir, basename);
4678 if (fileExists(filename))
4683 /* 2nd try: look for element description file for this element's class */
4684 sprintf(basename, "%s.txt", element_info[element].class_name);
4685 filename = getPath3(docs_dir, elements_subdir, basename);
4686 if (fileExists(filename))
4692 static boolean PrintInfoText(char *text, int font_nr, int screen_line)
4694 int font_height = getFontHeight(font_nr);
4695 int pad_x = ED_SETTINGS_XPOS(0);
4696 int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
4697 int sx = SX + pad_x;
4698 int sy = SY + pad_y;
4699 int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
4701 if (screen_line >= max_lines_per_screen)
4704 DrawText(sx, sy + screen_line * font_height, text, font_nr);
4709 static int PrintElementDescriptionFromFile(char *filename, int screen_line)
4711 int font_nr = FONT_TEXT_2;
4712 int font_width = getFontWidth(font_nr);
4713 int pad_x = ED_SETTINGS_XPOS(0);
4714 int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
4715 char line[MAX_LINE_LEN];
4716 char buffer[max_chars_per_line + 1];
4718 int lines_printed = 0;
4721 if (filename == NULL)
4724 if (!(file = fopen(filename, MODE_READ)))
4732 char *line_ptr, *word_ptr;
4733 boolean last_line_was_empty = TRUE;
4735 /* read next line of input file */
4736 if (!fgets(line, MAX_LINE_LEN, file))
4739 /* skip comments (lines directly beginning with '#') */
4743 /* cut trailing newline from input line */
4744 for (line_ptr = line; *line_ptr; line_ptr++)
4746 if (*line_ptr == '\n' || *line_ptr == '\r')
4753 if (strlen(line) == 0) /* special case: force empty line */
4760 boolean print_buffer = FALSE;
4763 /* skip leading whitespaces */
4764 while (*word_ptr == ' ' || *word_ptr == '\t')
4767 line_ptr = word_ptr;
4770 /* look for end of next word */
4771 while (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
4781 else if (*word_ptr == '\n') /* special case: force empty line */
4783 if (buffer_len == 0)
4786 /* prevent printing of multiple empty lines */
4787 if (buffer_len > 0 || !last_line_was_empty)
4788 print_buffer = TRUE;
4790 else if (word_len < max_chars_per_line - buffer_len)
4792 /* word fits into text buffer -- add word */
4795 buffer[buffer_len++] = ' ';
4797 strncpy(&buffer[buffer_len], word_ptr, word_len);
4798 buffer_len += word_len;
4799 buffer[buffer_len] = '\0';
4800 word_ptr += word_len;
4802 else if (buffer_len > 0)
4804 /* not enough space left for word in text buffer -- print buffer */
4806 print_buffer = TRUE;
4810 /* word does not fit at all into empty text buffer -- cut word */
4812 strncpy(buffer, word_ptr, max_chars_per_line);
4813 buffer[max_chars_per_line] = '\0';
4814 word_ptr += max_chars_per_line;
4815 print_buffer = TRUE;
4820 if (!PrintInfoText(buffer, font_nr, screen_line + lines_printed))
4821 return lines_printed;
4823 last_line_was_empty = (buffer_len == 0);
4828 print_buffer = FALSE;
4836 if (PrintInfoText(buffer, font_nr, screen_line + lines_printed))
4839 return lines_printed;
4842 static void DrawPropertiesTabulatorGadgets()
4844 struct GadgetInfo *gd_gi = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
4845 struct GadgetDesign *gd = &gd_gi->alt_design[GD_BUTTON_UNPRESSED];
4846 int gd_x = gd->x + gd_gi->border.width / 2;
4847 int gd_y = gd->y + gd_gi->height - 1;
4848 Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
4849 int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
4850 int id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
4853 /* draw additional "advanced" tabulator for custom elements */
4854 if (IS_CUSTOM_ELEMENT(properties_element))
4855 id_last = ED_TEXTBUTTON_ID_PROPERTIES_ADVANCED;
4857 for (i=id_first; i <= id_last; i++)
4859 int gadget_id = textbutton_info[i].gadget_id;
4860 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
4861 boolean active = (i != edit_mode_properties);
4863 /* draw background line below tabulator button */
4864 ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width,1);
4866 /* draw solid line below inactive tabulator buttons */
4867 if (!active && tab_color != BLACK_PIXEL) /* black => transparent */
4868 FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,1, tab_color);
4870 ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
4871 MapTextbuttonGadget(i);
4874 /* draw little border line below tabulator buttons */
4875 if (tab_color != BLACK_PIXEL) /* black => transparent */
4876 FillRectangle(drawto, gd_gi->x, gd_gi->y + gd_gi->height + 1,
4877 3 * gd_gi->width + 2 * ED_GADGET_DISTANCE,
4878 ED_GADGET_DISTANCE, tab_color);
4881 static void DrawPropertiesInfo()
4890 /* configurable properties */
4892 { EP_WALKABLE_OVER, "- player can walk over it" },
4893 { EP_WALKABLE_INSIDE, "- player can walk inside it" },
4894 { EP_WALKABLE_UNDER, "- player can walk under it" },
4895 { EP_PASSABLE_OVER, "- player can pass over it" },
4896 { EP_PASSABLE_INSIDE, "- player can pass through it" },
4897 { EP_PASSABLE_UNDER, "- player can pass under it" },
4899 { EP_DIGGABLE, "- can be digged away" },
4900 { EP_COLLECTIBLE, "- can be collected" },
4901 { EP_DROPPABLE, "- can be dropped after collecting" },
4902 { EP_PUSHABLE, "- can be pushed" },
4904 { EP_CAN_MOVE, "- can move" },
4905 { EP_CAN_FALL, "- can fall" },
4907 { EP_CAN_SMASH_PLAYER, "- can smash player" },
4909 { EP_CAN_SMASH_ENEMIES, "- can smash good and bad guys" },
4911 { EP_CAN_SMASH_EVERYTHING, "- can smash everything smashable" },
4913 { EP_SLIPPERY, "- slippery for falling objects" },
4914 { EP_EM_SLIPPERY_WALL, "- slippery for some gems (EM style)" },
4916 { EP_DONT_RUN_INTO, "- deadly when running into" },
4917 { EP_DONT_COLLIDE_WITH, "- deadly when colliding with" },
4918 { EP_DONT_TOUCH, "- deadly when touching" },
4920 { EP_INDESTRUCTIBLE, "- undestructible" },
4922 { EP_CAN_EXPLODE_BY_FIRE, "- can explode by fire or explosions" },
4923 { EP_CAN_EXPLODE_SMASHED, "- can explode when smashed" },
4924 { EP_CAN_EXPLODE_IMPACT, "- can explode on impact" },
4926 { EP_CAN_CHANGE, "- can change to other element" },
4928 /* pre-defined properties */
4929 { EP_CAN_PASS_MAGIC_WALL, "- can pass magic walls" },
4930 { EP_HAS_CONTENT, "- can contain other elements" },
4934 char *filename = getElementDescriptionFilename(properties_element);
4935 char *percentage_text = "In this level:";
4936 char *properties_text = "Standard properties:";
4938 int num_elements_in_level;
4939 int num_standard_properties = 0;
4940 int font1_nr = FONT_TEXT_1;
4941 int font2_nr = FONT_TEXT_2;
4942 int font1_width = getFontWidth(font1_nr);
4943 int font2_height = getFontHeight(font2_nr);
4944 int pad_x = ED_SETTINGS_XPOS(0);
4945 int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
4946 int screen_line = 0;
4949 /* ----- print number of elements / percentage of this element in level */
4951 num_elements_in_level = 0;
4952 for (y=0; y<lev_fieldy; y++)
4953 for (x=0; x<lev_fieldx; x++)
4954 if (Feld[x][y] == properties_element)
4955 num_elements_in_level++;
4956 percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
4958 DrawTextF(pad_x, pad_y + screen_line * font2_height, font1_nr,
4960 DrawTextF(pad_x + strlen(percentage_text) * font1_width,
4961 pad_y + screen_line++ * font2_height, font2_nr,
4962 "%d (%.2f%%)", num_elements_in_level, percentage);
4966 /* ----- print standard properties of this element */
4968 DrawTextF(pad_x, pad_y + screen_line++ * font2_height, font1_nr,
4971 for (i=0; properties[i].value != -1; i++)
4973 if (!HAS_PROPERTY(properties_element, properties[i].value))
4976 DrawTextF(pad_x, pad_y + screen_line++ * font2_height, font2_nr,
4977 properties[i].text);
4978 num_standard_properties++;
4981 if (num_standard_properties == 0)
4982 DrawTextF(pad_x + strlen(properties_text) * font1_width,
4983 pad_y + (screen_line - 1) * font2_height, font2_nr, "none");
4987 /* ----- print special description of this element */
4989 PrintInfoText("Description:", FONT_TEXT_1, screen_line);
4990 if (PrintElementDescriptionFromFile(filename, screen_line + 1) == 0)
4991 PrintInfoText("No description available.", FONT_TEXT_1, screen_line);
4994 #define TEXT_COLLECTING "Score for collecting"
4995 #define TEXT_SMASHING "Score for smashing"
4996 #define TEXT_CRACKING "Score for cracking"
4997 #define TEXT_SPEED "Speed of amoeba growth"
4998 #define TEXT_DURATION "Duration when activated"
5005 } elements_with_counter[] =
5007 { EL_EMERALD, &level.score[SC_EMERALD], TEXT_COLLECTING },
5008 { EL_BD_DIAMOND, &level.score[SC_EMERALD], TEXT_COLLECTING },
5009 { EL_EMERALD_YELLOW, &level.score[SC_EMERALD], TEXT_COLLECTING },
5010 { EL_EMERALD_RED, &level.score[SC_EMERALD], TEXT_COLLECTING },
5011 { EL_EMERALD_PURPLE, &level.score[SC_EMERALD], TEXT_COLLECTING },
5012 { EL_SP_INFOTRON, &level.score[SC_EMERALD], TEXT_COLLECTING },
5013 { EL_DIAMOND, &level.score[SC_DIAMOND], TEXT_COLLECTING },
5014 { EL_CRYSTAL, &level.score[SC_CRYSTAL], TEXT_COLLECTING },
5015 { EL_PEARL, &level.score[SC_PEARL], TEXT_COLLECTING },
5016 { EL_BUG_RIGHT, &level.score[SC_BUG], TEXT_SMASHING },
5017 { EL_BUG_UP, &level.score[SC_BUG], TEXT_SMASHING },
5018 { EL_BUG_LEFT, &level.score[SC_BUG], TEXT_SMASHING },
5019 { EL_BUG_DOWN, &level.score[SC_BUG], TEXT_SMASHING },
5020 { EL_BD_BUTTERFLY_RIGHT,&level.score[SC_BUG], TEXT_SMASHING },
5021 { EL_BD_BUTTERFLY_UP, &level.score[SC_BUG], TEXT_SMASHING },
5022 { EL_BD_BUTTERFLY_LEFT, &level.score[SC_BUG], TEXT_SMASHING },
5023 { EL_BD_BUTTERFLY_DOWN, &level.score[SC_BUG], TEXT_SMASHING },
5024 { EL_SP_ELECTRON, &level.score[SC_BUG], TEXT_SMASHING },
5025 { EL_SPACESHIP_RIGHT, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5026 { EL_SPACESHIP_UP, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5027 { EL_SPACESHIP_LEFT, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5028 { EL_SPACESHIP_DOWN, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5029 { EL_BD_FIREFLY_RIGHT,&level.score[SC_SPACESHIP], TEXT_SMASHING },
5030 { EL_BD_FIREFLY_UP, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5031 { EL_BD_FIREFLY_LEFT, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5032 { EL_BD_FIREFLY_DOWN, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5033 { EL_SP_SNIKSNAK, &level.score[SC_SPACESHIP], TEXT_SMASHING },
5034 { EL_YAMYAM, &level.score[SC_YAMYAM], TEXT_SMASHING },
5035 { EL_DARK_YAMYAM, &level.score[SC_YAMYAM], TEXT_SMASHING },
5036 { EL_ROBOT, &level.score[SC_ROBOT], TEXT_SMASHING },
5037 { EL_PACMAN_RIGHT, &level.score[SC_PACMAN], TEXT_SMASHING },
5038 { EL_PACMAN_UP, &level.score[SC_PACMAN], TEXT_SMASHING },
5039 { EL_PACMAN_LEFT, &level.score[SC_PACMAN], TEXT_SMASHING },
5040 { EL_PACMAN_DOWN, &level.score[SC_PACMAN], TEXT_SMASHING },
5041 { EL_NUT, &level.score[SC_NUT], TEXT_CRACKING },
5042 { EL_DYNAMITE, &level.score[SC_DYNAMITE], TEXT_COLLECTING },
5043 { EL_DYNABOMB_INCREASE_NUMBER,&level.score[SC_DYNAMITE],TEXT_COLLECTING },
5044 { EL_DYNABOMB_INCREASE_SIZE, &level.score[SC_DYNAMITE],TEXT_COLLECTING },
5045 { EL_DYNABOMB_INCREASE_POWER, &level.score[SC_DYNAMITE],TEXT_COLLECTING },
5046 { EL_SHIELD_NORMAL, &level.score[SC_SHIELD], TEXT_COLLECTING },
5047 { EL_SHIELD_DEADLY, &level.score[SC_SHIELD], TEXT_COLLECTING },
5048 { EL_EXTRA_TIME, &level.score[SC_TIME_BONUS], TEXT_COLLECTING },
5049 { EL_KEY_1, &level.score[SC_KEY], TEXT_COLLECTING },
5050 { EL_KEY_2, &level.score[SC_KEY], TEXT_COLLECTING },
5051 { EL_KEY_3, &level.score[SC_KEY], TEXT_COLLECTING },
5052 { EL_KEY_4, &level.score[SC_KEY], TEXT_COLLECTING },
5053 { EL_EM_KEY_1_FILE, &level.score[SC_KEY], TEXT_COLLECTING },
5054 { EL_EM_KEY_2_FILE, &level.score[SC_KEY], TEXT_COLLECTING },
5055 { EL_EM_KEY_3_FILE, &level.score[SC_KEY], TEXT_COLLECTING },
5056 { EL_EM_KEY_4_FILE, &level.score[SC_KEY], TEXT_COLLECTING },
5057 { EL_AMOEBA_WET, &level.amoeba_speed, TEXT_SPEED },
5058 { EL_AMOEBA_DRY, &level.amoeba_speed, TEXT_SPEED },
5059 { EL_AMOEBA_FULL, &level.amoeba_speed, TEXT_SPEED },
5060 { EL_BD_AMOEBA, &level.amoeba_speed, TEXT_SPEED },
5061 { EL_MAGIC_WALL, &level.time_magic_wall, TEXT_DURATION },
5062 { EL_ROBOT_WHEEL, &level.time_wheel, TEXT_DURATION },
5066 static boolean checkPropertiesConfig()
5070 if (IS_GEM(properties_element) ||
5071 IS_CUSTOM_ELEMENT(properties_element) ||
5072 HAS_CONTENT(properties_element))
5075 for (i=0; elements_with_counter[i].element != -1; i++)
5076 if (elements_with_counter[i].element == properties_element)
5082 static void DrawPropertiesConfig()
5086 if (!checkPropertiesConfig())
5088 PrintInfoText("No configuration options available.", FONT_TEXT_1, 0);
5093 /* check if there are elements where a score can be chosen for */
5094 for (i=0; elements_with_counter[i].element != -1; i++)
5096 if (elements_with_counter[i].element == properties_element)
5098 int counter_id = ED_COUNTER_ID_ELEMENT_SCORE;
5100 counterbutton_info[counter_id].value = elements_with_counter[i].value;
5101 counterbutton_info[counter_id].text_right= elements_with_counter[i].text;
5102 MapCounterButtons(counter_id);
5108 if (HAS_CONTENT(properties_element))
5110 /* draw stickybutton gadget */
5111 i = ED_CHECKBUTTON_ID_STICK_ELEMENT;
5112 checkbutton_info[i].y = ED_COUNTER_YPOS(4);
5113 MapCheckbuttonGadget(i);
5115 if (IS_AMOEBOID(properties_element))
5116 MapDrawingArea(ED_DRAWING_ID_AMOEBA_CONTENT);
5118 DrawElementContentAreas();
5121 if (IS_GEM(properties_element))
5122 MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
5124 if (IS_CUSTOM_ELEMENT(properties_element))
5126 /* draw stickybutton gadget */
5127 i = ED_CHECKBUTTON_ID_STICK_ELEMENT;
5128 checkbutton_info[i].y = ED_SETTINGS_YPOS(0);
5129 MapCheckbuttonGadget(i);
5131 /* draw checkbutton gadgets */
5132 for (i = ED_CHECKBUTTON_ID_CUSTOM_FIRST;
5133 i <= ED_CHECKBUTTON_ID_CUSTOM_LAST; i++)
5134 MapCheckbuttonGadget(i);
5136 /* draw counter gadgets */
5137 for (i=ED_COUNTER_ID_CUSTOM_FIRST; i<=ED_COUNTER_ID_CUSTOM_LAST; i++)
5138 MapCounterButtons(i);
5140 /* draw selectbox gadgets */
5141 for (i=ED_SELECTBOX_ID_CUSTOM_FIRST; i <= ED_SELECTBOX_ID_CUSTOM_LAST; i++)
5142 MapSelectboxGadget(i);
5144 /* draw drawing area gadgets */
5145 DrawCustomContentArea();
5147 /* draw text input gadgets */
5148 MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
5152 static void DrawPropertiesAdvancedDrawingAreas()
5154 MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
5155 MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
5156 MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
5158 DrawCustomChangeContentArea();
5160 redraw_mask |= REDRAW_FIELD;
5163 static void DrawPropertiesAdvanced()
5167 /* draw stickybutton gadget */
5168 i = ED_CHECKBUTTON_ID_STICK_ELEMENT;
5169 checkbutton_info[i].y = ED_SETTINGS_YPOS(0);
5170 MapCheckbuttonGadget(i);
5172 /* draw checkbutton gadgets */
5173 for (i = ED_CHECKBUTTON_ID_CHANGE_FIRST;
5174 i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
5175 MapCheckbuttonGadget(i);
5177 /* draw counter gadgets */
5178 for (i=ED_COUNTER_ID_CHANGE_FIRST; i<=ED_COUNTER_ID_CHANGE_LAST; i++)
5179 MapCounterButtons(i);
5181 /* draw selectbox gadgets */
5182 for (i=ED_SELECTBOX_ID_CHANGE_FIRST; i<=ED_SELECTBOX_ID_CHANGE_LAST; i++)
5183 MapSelectboxGadget(i);
5185 /* draw textbutton gadgets */
5186 MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE);
5188 /* draw drawing area gadgets */
5189 DrawPropertiesAdvancedDrawingAreas();
5192 static void DrawElementName(int x, int y, int element)
5194 char *element_name = getElementInfoText(element);
5195 int font_nr = FONT_TEXT_1;
5196 int font_width = getFontWidth(font_nr);
5197 int font_height = getFontHeight(font_nr);
5198 int max_text_width = SXSIZE - x - ED_SETTINGS_XPOS(0);
5199 int max_chars_per_line = max_text_width / font_width;
5200 char buffer[max_chars_per_line + 1];
5202 if (strlen(element_name) <= max_chars_per_line)
5203 DrawTextF(x, y, font_nr, element_name);
5206 int next_pos = max_chars_per_line;
5208 strncpy(buffer, element_name, max_chars_per_line);
5209 buffer[max_chars_per_line] = '\0';
5211 if (element_name[max_chars_per_line] == ' ')
5217 for (i = max_chars_per_line - 1; i >= 0; i--)
5218 if (buffer[i] == ' ')
5221 if (strlen(&element_name[i + 1]) <= max_chars_per_line)
5228 DrawTextF(x, y - font_height / 2, font_nr, buffer);
5230 strncpy(buffer, &element_name[next_pos], max_chars_per_line);
5231 buffer[max_chars_per_line] = '\0';
5233 DrawTextF(x, y + font_height / 2, font_nr, buffer);
5237 static void DrawPropertiesWindow()
5242 stick_element_properties_window = FALSE;
5244 /* make sure that previous properties edit mode exists for this element */
5245 if (edit_mode_properties == ED_MODE_PROPERTIES_ADVANCED &&
5246 !IS_CUSTOM_ELEMENT(properties_element))
5247 edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
5249 if (IS_CUSTOM_ELEMENT(properties_element))
5250 CopyCustomElementPropertiesToEditor(properties_element);
5252 UnmapLevelEditorWindowGadgets();
5254 SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
5257 DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS,
5258 "Element Settings", FONT_TITLE_1);
5260 DrawElementBorder(SX + xstart * MINI_TILEX,
5261 SY + ystart * MINI_TILEY + MINI_TILEY / 2,
5262 TILEX, TILEY, FALSE);
5263 DrawGraphicAnimationExt(drawto,
5264 SX + xstart * MINI_TILEX,
5265 SY + ystart * MINI_TILEY + MINI_TILEY / 2,
5266 el2img(properties_element), -1, NO_MASKING);
5268 FrameCounter = 0; /* restart animation frame counter */
5270 DrawElementName((xstart + 3) * MINI_TILEX, (ystart + 1) * MINI_TILEY,
5271 properties_element);
5273 DrawPropertiesTabulatorGadgets();
5275 if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
5276 DrawPropertiesInfo();
5277 else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG)
5278 DrawPropertiesConfig();
5279 else /* edit_mode_properties == ED_MODE_PROPERTIES_ADVANCED */
5280 DrawPropertiesAdvanced();
5283 static void UpdateCustomElementGraphicGadgets()
5285 ModifyEditorElementList();
5286 RedrawDrawingElements();
5288 if (edit_mode == ED_MODE_PROPERTIES &&
5289 edit_mode_properties == ED_MODE_PROPERTIES_ADVANCED)
5290 DrawPropertiesAdvancedDrawingAreas();
5293 static void DrawLineElement(int sx, int sy, int element, boolean change_level)
5295 int lx = sx + level_xpos;
5296 int ly = sy + level_ypos;
5298 DrawMiniElement(sx, sy, (element < 0 ? Feld[lx][ly] : element));
5301 Feld[lx][ly] = element;
5304 static void DrawLine(int from_x, int from_y, int to_x, int to_y,
5305 int element, boolean change_level)
5307 if (from_y == to_y) /* horizontal line */
5313 swap_numbers(&from_x, &to_x);
5315 for (x=from_x; x<=to_x; x++)
5316 DrawLineElement(x, y, element, change_level);
5318 else if (from_x == to_x) /* vertical line */
5324 swap_numbers(&from_y, &to_y);
5326 for (y=from_y; y<=to_y; y++)
5327 DrawLineElement(x, y, element, change_level);
5329 else /* diagonal line */
5331 int len_x = ABS(to_x - from_x);
5332 int len_y = ABS(to_y - from_y);
5335 if (len_y < len_x) /* a < 1 */
5337 float a = (float)len_y / (float)len_x;
5340 swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
5342 for (x=0; x<=len_x; x++)
5344 y = (int)(a * x + 0.5) * (to_y < from_y ? -1 : +1);
5345 DrawLineElement(from_x + x, from_y + y, element, change_level);
5350 float a = (float)len_x / (float)len_y;
5353 swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
5355 for (y=0; y<=len_y; y++)
5357 x = (int)(a * y + 0.5) * (to_x < from_x ? -1 : +1);
5358 DrawLineElement(from_x + x, from_y + y, element, change_level);
5364 static void DrawBox(int from_x, int from_y, int to_x, int to_y,
5365 int element, boolean change_level)
5367 DrawLine(from_x, from_y, from_x, to_y, element, change_level);
5368 DrawLine(from_x, to_y, to_x, to_y, element, change_level);
5369 DrawLine(to_x, to_y, to_x, from_y, element, change_level);
5370 DrawLine(to_x, from_y, from_x, from_y, element, change_level);
5373 static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
5374 int element, boolean change_level)
5379 swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
5381 for (y=from_y; y<=to_y; y++)
5382 DrawLine(from_x, y, to_x, y, element, change_level);
5385 static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
5386 int element, boolean change_level)
5388 int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
5389 int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
5390 int len_x = ABS(to_x - from_x);
5391 int len_y = ABS(to_y - from_y);
5394 radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
5396 /* not optimal (some points get drawn twice) but simple,
5397 and fast enough for the few points we are drawing */
5399 for (x=0; x<=radius; x++)
5403 y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
5405 sx = from_x + x * (from_x < to_x2 ? +1 : -1);
5406 sy = from_y + y * (from_y < to_y2 ? +1 : -1);
5407 lx = sx + level_xpos;
5408 ly = sy + level_ypos;
5410 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
5411 DrawLineElement(sx, sy, element, change_level);
5414 for (y=0; y<=radius; y++)
5418 x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
5420 sx = from_x + x * (from_x < to_x2 ? +1 : -1);
5421 sy = from_y + y * (from_y < to_y2 ? +1 : -1);
5422 lx = sx + level_xpos;
5423 ly = sy + level_ypos;
5425 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
5426 DrawLineElement(sx, sy, element, change_level);
5430 static void DrawArc(int from_x, int from_y, int to_x, int to_y,
5431 int element, boolean change_level)
5433 int to_x2 = to_x + (to_x < from_x ? -1 : +1);
5434 int to_y2 = to_y + (to_y > from_y ? +1 : -1);
5436 DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
5439 #define DRAW_CIRCLES_BUTTON_AVAILABLE 0
5440 #if DRAW_CIRCLES_BUTTON_AVAILABLE
5441 static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
5442 int element, boolean change_level)
5444 int to_x2 = to_x + (to_x < from_x ? -1 : +1);
5445 int to_y2 = to_y + (to_y > from_y ? +1 : -1);
5446 int mirror_to_x2 = from_x - (to_x2 - from_x);
5447 int mirror_to_y2 = from_y - (to_y2 - from_y);
5449 DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
5450 DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
5451 DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
5452 DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element,change_level);
5456 static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
5458 int from_sx, from_sy;
5462 swap_numbers(&from_x, &to_x);
5465 swap_numbers(&from_y, &to_y);
5467 from_sx = SX + from_x * MINI_TILEX;
5468 from_sy = SY + from_y * MINI_TILEY;
5469 to_sx = SX + to_x * MINI_TILEX + MINI_TILEX - 1;
5470 to_sy = SY + to_y * MINI_TILEY + MINI_TILEY - 1;
5472 DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx, from_sy);
5473 DrawSimpleWhiteLine(drawto, to_sx, from_sy, to_sx, to_sy);
5474 DrawSimpleWhiteLine(drawto, to_sx, to_sy, from_sx, to_sy);
5475 DrawSimpleWhiteLine(drawto, from_sx, to_sy, from_sx, from_sy);
5477 if (from_x == to_x && from_y == to_y)
5478 MarkTileDirty(from_x/2, from_y/2);
5480 redraw_mask |= REDRAW_FIELD;
5483 static void SelectArea(int from_x, int from_y, int to_x, int to_y,
5484 int element, boolean change_level)
5486 if (element == -1 || change_level)
5487 DrawBox(from_x, from_y, to_x, to_y, -1, FALSE);
5489 DrawAreaBorder(from_x, from_y, to_x, to_y);
5492 /* values for CopyBrushExt() */
5493 #define CB_AREA_TO_BRUSH 0
5494 #define CB_BRUSH_TO_CURSOR 1
5495 #define CB_BRUSH_TO_LEVEL 2
5496 #define CB_DELETE_OLD_CURSOR 3
5498 static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
5499 int button, int mode)
5501 static short brush_buffer[MAX_ED_FIELDX][MAX_ED_FIELDY];
5502 static int brush_width, brush_height;
5503 static int last_cursor_x = -1, last_cursor_y = -1;
5504 static boolean delete_old_brush;
5505 int new_element = BUTTON_ELEMENT(button);
5508 if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
5511 if (mode == CB_AREA_TO_BRUSH)
5513 int from_lx, from_ly;
5516 swap_numbers(&from_x, &to_x);
5519 swap_numbers(&from_y, &to_y);
5521 brush_width = to_x - from_x + 1;
5522 brush_height = to_y - from_y + 1;
5524 from_lx = from_x + level_xpos;
5525 from_ly = from_y + level_ypos;
5527 for (y=0; y<brush_height; y++)
5529 for (x=0; x<brush_width; x++)
5531 brush_buffer[x][y] = Feld[from_lx + x][from_ly + y];
5534 DrawLineElement(from_x + x, from_y + y, new_element, TRUE);
5539 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
5541 delete_old_brush = FALSE;
5543 else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
5544 mode == CB_BRUSH_TO_LEVEL)
5546 int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
5547 int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
5548 int cursor_from_x = cursor_x - brush_width / 2;
5549 int cursor_from_y = cursor_y - brush_height / 2;
5550 int border_from_x = cursor_x, border_from_y = cursor_y;
5551 int border_to_x = cursor_x, border_to_y = cursor_y;
5553 if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
5554 CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
5556 if (!IN_ED_FIELD(cursor_x, cursor_y) ||
5557 !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
5559 delete_old_brush = FALSE;
5563 for (y=0; y<brush_height; y++)
5565 for (x=0; x<brush_width; x++)
5567 int sx = cursor_from_x + x;
5568 int sy = cursor_from_y + y;
5569 int lx = sx + level_xpos;
5570 int ly = sy + level_ypos;
5571 boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
5572 int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
5573 mode == CB_BRUSH_TO_CURSOR || button == 1 ?
5574 brush_buffer[x][y] : new_element);
5576 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
5578 if (sx < border_from_x)
5580 else if (sx > border_to_x)
5582 if (sy < border_from_y)
5584 else if (sy > border_to_y)
5587 DrawLineElement(sx, sy, element, change_level);
5592 if (mode != CB_DELETE_OLD_CURSOR)
5593 DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
5595 last_cursor_x = cursor_x;
5596 last_cursor_y = cursor_y;
5597 delete_old_brush = TRUE;
5601 static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
5604 CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
5607 static void CopyBrushToLevel(int x, int y, int button)
5609 CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
5612 static void CopyBrushToCursor(int x, int y)
5614 CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
5617 static void DeleteBrushFromCursor()
5619 CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
5622 static void FloodFill(int from_x, int from_y, int fill_element)
5626 static int check[4][2] = { {-1,0}, {0,-1}, {1,0}, {0,1} };
5627 static int safety = 0;
5629 /* check if starting field still has the desired content */
5630 if (Feld[from_x][from_y] == fill_element)
5635 if (safety > lev_fieldx*lev_fieldy)
5636 Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug.");
5638 old_element = Feld[from_x][from_y];
5639 Feld[from_x][from_y] = fill_element;
5643 x = from_x + check[i][0];
5644 y = from_y + check[i][1];
5646 if (IN_LEV_FIELD(x,y) && Feld[x][y] == old_element)
5647 FloodFill(x, y, fill_element);
5653 /* values for DrawLevelText() modes */
5655 #define TEXT_SETCURSOR 1
5656 #define TEXT_WRITECHAR 2
5657 #define TEXT_BACKSPACE 3
5658 #define TEXT_NEWLINE 4
5660 #define TEXT_QUERY_TYPING 6
5662 static int DrawLevelText(int sx, int sy, char letter, int mode)
5664 static short delete_buffer[MAX_LEV_FIELDX];
5665 static int start_sx, start_sy;
5666 static int last_sx, last_sy;
5667 static boolean typing = FALSE;
5668 int letter_element = EL_CHAR_ASCII0 + letter;
5671 /* map lower case letters to upper case and convert special characters */
5672 if (letter >= 'a' && letter <= 'z')
5673 letter_element = EL_CHAR_ASCII0 + letter + (int)('A' - 'a');
5674 else if (letter == 'ä' || letter == 'Ä')
5675 letter_element = EL_CHAR_AUMLAUT;
5676 else if (letter == 'ö' || letter == 'Ö')
5677 letter_element = EL_CHAR_OUMLAUT;
5678 else if (letter == 'ü' || letter == 'Ü')
5679 letter_element = EL_CHAR_UUMLAUT;
5680 else if (letter == '^')
5681 letter_element = EL_CHAR_COPYRIGHT;
5683 letter_element = EL_CHAR_ASCII0 + letter;
5685 if (mode != TEXT_INIT)
5690 if (mode != TEXT_SETCURSOR)
5696 lx = last_sx + level_xpos;
5697 ly = last_sy + level_ypos;
5704 DrawLevelText(0, 0, 0, TEXT_END);
5707 start_sx = last_sx = sx;
5708 start_sy = last_sy = sy;
5709 DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
5712 case TEXT_SETCURSOR:
5713 DrawMiniElement(last_sx, last_sy, Feld[lx][ly]);
5714 DrawAreaBorder(sx, sy, sx, sy);
5719 case TEXT_WRITECHAR:
5720 if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END)
5722 delete_buffer[sx - start_sx] = Feld[lx][ly];
5723 Feld[lx][ly] = letter_element;
5725 if (sx + 1 < ed_fieldx && lx + 1 < lev_fieldx)
5726 DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR);
5727 else if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
5728 DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
5730 DrawLevelText(0, 0, 0, TEXT_END);
5734 case TEXT_BACKSPACE:
5737 Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1];
5738 DrawMiniElement(sx - 1, sy, Feld[lx - 1][ly]);
5739 DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR);
5744 if (sy + 1 < ed_fieldy - 1 && ly + 1 < lev_fieldy - 1)
5745 DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
5747 DrawLevelText(0, 0, 0, TEXT_END);
5751 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
5752 DrawMiniElement(sx, sy, Feld[lx][ly]);
5756 case TEXT_QUERY_TYPING:
5766 static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy,
5767 int element, boolean change_level)
5769 int lx = sx + level_xpos;
5770 int ly = sy + level_ypos;
5773 DrawMiniElement(sx, sy, Feld[lx][ly]);
5775 DrawAreaBorder(sx, sy, sx, sy);
5778 static void CopyLevelToUndoBuffer(int mode)
5780 static boolean accumulated_undo = FALSE;
5781 boolean new_undo_buffer_position = TRUE;
5782 int last_border_element;
5787 case UNDO_IMMEDIATE:
5788 accumulated_undo = FALSE;
5791 case UNDO_ACCUMULATE:
5792 if (accumulated_undo)
5793 new_undo_buffer_position = FALSE;
5794 accumulated_undo = TRUE;
5801 if (new_undo_buffer_position)
5803 /* new position in undo buffer ring */
5804 undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
5806 if (undo_buffer_steps < NUM_UNDO_STEPS - 1)
5807 undo_buffer_steps++;
5810 for(x=0; x<lev_fieldx; x++)
5811 for(y=0; y<lev_fieldy; y++)
5812 UndoBuffer[undo_buffer_position][x][y] = Feld[x][y];
5814 /* check if drawing operation forces change of border style */
5815 last_border_element = BorderElement;
5817 if (BorderElement != last_border_element)
5818 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
5821 static void RandomPlacement(int new_element)
5823 static boolean free_position[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
5824 int num_free_positions;
5829 /* determine number of free positions for the new elements */
5830 /* (maybe this statement should be formatted a bit more readable...) */
5831 num_free_positions = 0;
5832 for (x=0; x<lev_fieldx; x++)
5833 for (y=0; y<lev_fieldy; y++)
5834 if ((free_position[x][y] =
5835 ((random_placement_background_restricted &&
5836 Feld[x][y] == random_placement_background_element) ||
5837 (!random_placement_background_restricted &&
5838 Feld[x][y] != new_element))) == TRUE)
5839 num_free_positions++;
5841 /* determine number of new elements to place there */
5842 num_percentage = num_free_positions * random_placement_value / 100;
5843 num_elements = (random_placement_method == RANDOM_USE_PERCENTAGE ?
5844 num_percentage : random_placement_value);
5846 /* if not more free positions than elements to place, fill whole level */
5847 if (num_elements >= num_free_positions)
5849 for (x=0; x<lev_fieldx; x++)
5850 for (y=0; y<lev_fieldy; y++)
5851 Feld[x][y] = new_element;
5853 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
5854 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
5858 while (num_elements > 0)
5860 x = RND(lev_fieldx);
5861 y = RND(lev_fieldy);
5863 /* don't place element at the same position twice */
5864 if (free_position[x][y])
5866 free_position[x][y] = FALSE;
5867 Feld[x][y] = new_element;
5872 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
5873 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
5876 void WrapLevel(int dx, int dy)
5878 int wrap_dx = lev_fieldx - dx;
5879 int wrap_dy = lev_fieldy - dy;
5882 for(x=0; x<lev_fieldx; x++)
5883 for(y=0; y<lev_fieldy; y++)
5884 FieldBackup[x][y] = Feld[x][y];
5886 for(x=0; x<lev_fieldx; x++)
5887 for(y=0; y<lev_fieldy; y++)
5889 FieldBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
5891 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
5892 CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
5895 static void HandleDrawingAreas(struct GadgetInfo *gi)
5897 static boolean started_inside_drawing_area = FALSE;
5898 int id = gi->custom_id;
5899 boolean button_press_event;
5900 boolean button_release_event;
5901 boolean inside_drawing_area = !gi->event.off_borders;
5902 boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL);
5903 int actual_drawing_function;
5904 int button = gi->event.button;
5905 int new_element = BUTTON_ELEMENT(button);
5906 int sx = gi->event.x, sy = gi->event.y;
5907 int min_sx = 0, min_sy = 0;
5908 int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1;
5909 int item_xsize = gi->drawing.item_xsize, item_ysize = gi->drawing.item_ysize;
5911 int min_lx = 0, min_ly = 0;
5912 int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
5915 /* handle info callback for each invocation of action callback */
5916 gi->callback_info(gi);
5918 button_press_event = (gi->event.type == GD_EVENT_PRESSED);
5919 button_release_event = (gi->event.type == GD_EVENT_RELEASED);
5921 /* make sure to stay inside drawing area boundaries */
5922 sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
5923 sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
5927 /* get positions inside level field */
5928 lx = sx + level_xpos;
5929 ly = sy + level_ypos;
5931 if (!IN_LEV_FIELD(lx, ly))
5932 inside_drawing_area = FALSE;
5934 /* make sure to stay inside level field boundaries */
5935 lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
5936 ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
5938 /* correct drawing area positions accordingly */
5939 sx = lx - level_xpos;
5940 sy = ly - level_ypos;
5943 if (button_press_event)
5944 started_inside_drawing_area = inside_drawing_area;
5946 if (!started_inside_drawing_area)
5949 if (!button && !button_release_event)
5952 /* automatically switch to 'single item' drawing mode, if needed */
5953 actual_drawing_function =
5954 (draw_level || drawing_function == GADGET_ID_PICK_ELEMENT ?
5955 drawing_function : GADGET_ID_SINGLE_ITEMS);
5957 /* clicking into drawing area with pressed Control key picks element */
5958 if (GetKeyModState() & KMOD_Control)
5959 actual_drawing_function = GADGET_ID_PICK_ELEMENT;
5961 switch (actual_drawing_function)
5963 case GADGET_ID_SINGLE_ITEMS:
5966 if (button_release_event)
5968 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
5970 if (edit_mode == ED_MODE_DRAWING && draw_with_brush &&
5971 !inside_drawing_area)
5972 DeleteBrushFromCursor();
5978 if (draw_with_brush)
5980 if (!button_release_event)
5981 CopyBrushToLevel(sx, sy, button);
5983 else if (new_element != Feld[lx][ly])
5985 if (new_element == EL_PLAYER_1)
5987 /* remove player at old position */
5988 for(y=0; y<lev_fieldy; y++)
5990 for(x=0; x<lev_fieldx; x++)
5992 if (Feld[x][y] == EL_PLAYER_1)
5994 Feld[x][y] = EL_EMPTY;
5995 if (x - level_xpos >= 0 && x - level_xpos < ed_fieldx &&
5996 y - level_ypos >= 0 && y - level_ypos < ed_fieldy)
5997 DrawMiniElement(x - level_xpos, y - level_ypos,
6004 Feld[lx][ly] = new_element;
6005 DrawMiniElement(sx, sy, new_element);
6010 if (item_xsize == MINI_TILEX && item_ysize == MINI_TILEY)
6011 DrawMiniGraphicExt(drawto,
6012 gi->x + sx * MINI_TILEX,
6013 gi->y + sy * MINI_TILEY,
6014 el2edimg(new_element));
6016 DrawGraphicExt(drawto,
6019 el2img(new_element), 0);
6021 if (id == GADGET_ID_AMOEBA_CONTENT)
6022 level.amoeba_content = new_element;
6023 else if (id == GADGET_ID_CUSTOM_GRAPHIC)
6025 new_element = GFX_ELEMENT(new_element);
6026 custom_element.gfx_element = new_element;
6028 CopyCustomElementPropertiesToGame(properties_element);
6030 UpdateCustomElementGraphicGadgets();
6032 FrameCounter = 0; /* restart animation frame counter */
6034 else if (id == GADGET_ID_CUSTOM_CONTENT)
6036 custom_element.content[sx][sy] = new_element;
6038 CopyCustomElementPropertiesToGame(properties_element);
6040 else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
6042 custom_element.change.target_element = new_element;
6044 CopyCustomElementPropertiesToGame(properties_element);
6046 else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
6048 custom_element.change.content[sx][sy] = new_element;
6050 CopyCustomElementPropertiesToGame(properties_element);
6052 else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
6054 custom_element.change.trigger_element = new_element;
6056 CopyCustomElementPropertiesToGame(properties_element);
6058 else if (id == GADGET_ID_RANDOM_BACKGROUND)
6059 random_placement_background_element = new_element;
6060 else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
6061 id <= GADGET_ID_ELEMENT_CONTENT_7)
6062 level.yamyam_content[id - GADGET_ID_ELEMENT_CONTENT_0][sx][sy] =
6067 case GADGET_ID_CONNECTED_ITEMS:
6069 static int last_sx = -1;
6070 static int last_sy = -1;
6072 if (button_release_event)
6073 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
6077 if (!button_press_event)
6078 DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE);
6086 case GADGET_ID_LINE:
6088 case GADGET_ID_RECTANGLE:
6089 case GADGET_ID_FILLED_BOX:
6090 case GADGET_ID_GRAB_BRUSH:
6091 case GADGET_ID_TEXT:
6093 static int last_sx = -1;
6094 static int last_sy = -1;
6095 static int start_sx = -1;
6096 static int start_sy = -1;
6097 void (*draw_func)(int, int, int, int, int, boolean);
6099 if (drawing_function == GADGET_ID_LINE)
6100 draw_func = DrawLine;
6101 else if (drawing_function == GADGET_ID_ARC)
6102 draw_func = DrawArc;
6103 else if (drawing_function == GADGET_ID_RECTANGLE)
6104 draw_func = DrawBox;
6105 else if (drawing_function == GADGET_ID_FILLED_BOX)
6106 draw_func = DrawFilledBox;
6107 else if (drawing_function == GADGET_ID_GRAB_BRUSH)
6108 draw_func = SelectArea;
6109 else /* (drawing_function == GADGET_ID_TEXT) */
6110 draw_func = SetTextCursor;
6112 if (button_press_event)
6114 draw_func(sx, sy, sx, sy, new_element, FALSE);
6115 start_sx = last_sx = sx;
6116 start_sy = last_sy = sy;
6118 if (drawing_function == GADGET_ID_TEXT)
6119 DrawLevelText(0, 0, 0, TEXT_END);
6121 else if (button_release_event)
6123 draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
6124 if (drawing_function == GADGET_ID_GRAB_BRUSH)
6126 CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
6127 CopyBrushToCursor(sx, sy);
6128 ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
6130 draw_with_brush = TRUE;
6132 else if (drawing_function == GADGET_ID_TEXT)
6133 DrawLevelText(sx, sy, 0, TEXT_INIT);
6135 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
6137 else if (last_sx != sx || last_sy != sy)
6139 draw_func(start_sx, start_sy, last_sx, last_sy, -1, FALSE);
6140 draw_func(start_sx, start_sy, sx, sy, new_element, FALSE);
6147 case GADGET_ID_FLOOD_FILL:
6148 if (button_press_event && Feld[lx][ly] != new_element)
6150 FloodFill(lx, ly, new_element);
6151 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6152 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
6156 case GADGET_ID_PICK_ELEMENT:
6157 if (button_release_event)
6158 ClickOnGadget(level_editor_gadget[last_drawing_function],
6160 else if (draw_level)
6161 PickDrawingElement(button, Feld[lx][ly]);
6162 else if (id == GADGET_ID_AMOEBA_CONTENT)
6163 PickDrawingElement(button, level.amoeba_content);
6164 else if (id == GADGET_ID_CUSTOM_GRAPHIC)
6165 PickDrawingElement(button, custom_element.gfx_element);
6166 else if (id == GADGET_ID_CUSTOM_CONTENT)
6167 PickDrawingElement(button, custom_element.content[sx][sy]);
6168 else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
6169 PickDrawingElement(button, custom_element.change.target_element);
6170 else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
6171 PickDrawingElement(button, custom_element.change.content[sx][sy]);
6172 else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
6173 PickDrawingElement(button, custom_element.change.trigger_element);
6174 else if (id == GADGET_ID_RANDOM_BACKGROUND)
6175 PickDrawingElement(button, random_placement_background_element);
6176 else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
6177 id <= GADGET_ID_ELEMENT_CONTENT_7)
6179 int i = id - GADGET_ID_ELEMENT_CONTENT_0;
6181 PickDrawingElement(button, level.yamyam_content[i][sx][sy]);
6191 static void HandleCounterButtons(struct GadgetInfo *gi)
6193 int gadget_id = gi->custom_id;
6194 int counter_id = gi->custom_type_id;
6195 int button = gi->event.button;
6196 int *counter_value = counterbutton_info[counter_id].value;
6197 int step = BUTTON_STEPSIZE(button) *
6198 (gadget_id == counterbutton_info[counter_id].gadget_id_down ? -1 : +1);
6200 if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
6202 boolean pressed = (gi->event.type == GD_EVENT_PRESSED);
6203 boolean released = (gi->event.type == GD_EVENT_RELEASED);
6204 boolean level_changed = LevelChanged();
6206 if ((level_changed && pressed) || (!level_changed && released))
6209 if (level_changed && !Request("Level has changed! Discard changes ?",
6212 if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
6213 ModifyEditorCounter(counter_id, *counter_value);
6218 if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
6219 *counter_value = gi->text.number_value;
6221 ModifyEditorCounter(counter_id, *counter_value + step);
6225 case ED_COUNTER_ID_ELEMENT_CONTENT:
6226 DrawElementContentAreas();
6229 case ED_COUNTER_ID_LEVEL_XSIZE:
6230 case ED_COUNTER_ID_LEVEL_YSIZE:
6231 lev_fieldx = level.fieldx;
6232 lev_fieldy = level.fieldy;
6235 case ED_COUNTER_ID_SELECT_LEVEL:
6236 LoadLevel(level_nr);
6239 DrawEditModeWindow();
6246 if ((counter_id >= ED_COUNTER_ID_CUSTOM_FIRST &&
6247 counter_id <= ED_COUNTER_ID_CUSTOM_LAST) ||
6248 (counter_id >= ED_COUNTER_ID_CHANGE_FIRST &&
6249 counter_id <= ED_COUNTER_ID_CHANGE_LAST))
6250 CopyCustomElementPropertiesToGame(properties_element);
6253 static void HandleTextInputGadgets(struct GadgetInfo *gi)
6255 int type_id = gi->custom_type_id;
6257 strcpy(textinput_info[type_id].value, gi->text.value);
6259 if (type_id == ED_TEXTINPUT_ID_ELEMENT_NAME)
6261 CopyCustomElementPropertiesToGame(properties_element);
6263 ModifyEditorElementList(); /* update changed button info text */
6267 static void HandleSelectboxGadgets(struct GadgetInfo *gi)
6269 int type_id = gi->custom_type_id;
6271 *selectbox_info[type_id].value =
6272 selectbox_info[type_id].options[gi->selectbox.index].value;
6274 if ((type_id >= ED_SELECTBOX_ID_CUSTOM_FIRST &&
6275 type_id <= ED_SELECTBOX_ID_CUSTOM_LAST) ||
6276 (type_id >= ED_SELECTBOX_ID_CHANGE_FIRST &&
6277 type_id <= ED_SELECTBOX_ID_CHANGE_LAST))
6278 CopyCustomElementPropertiesToGame(properties_element);
6281 static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
6283 int type_id = gi->custom_type_id;
6285 if (type_id >= ED_TEXTBUTTON_ID_PROPERTIES_INFO &&
6286 type_id <= ED_TEXTBUTTON_ID_PROPERTIES_ADVANCED)
6288 edit_mode_properties = gi->custom_type_id;
6290 DrawPropertiesWindow();
6292 else if (type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE)
6294 boolean new_template = (!LevelFileExists(-1));
6297 Request("Save this tem- plate and kill the old ?", REQ_ASK))
6298 SaveLevelTemplate();
6301 Request("Tem- plate saved !", REQ_CONFIRM);
6305 static void HandleRadiobuttons(struct GadgetInfo *gi)
6307 *radiobutton_info[gi->custom_type_id].value =
6308 radiobutton_info[gi->custom_type_id].checked_value;
6311 static void HandleCheckbuttons(struct GadgetInfo *gi)
6313 int type_id = gi->custom_type_id;
6315 *checkbutton_info[type_id].value ^= TRUE;
6317 if ((type_id >= ED_CHECKBUTTON_ID_CUSTOM_FIRST &&
6318 type_id <= ED_CHECKBUTTON_ID_CUSTOM_LAST) ||
6319 (type_id >= ED_CHECKBUTTON_ID_CHANGE_FIRST &&
6320 type_id <= ED_CHECKBUTTON_ID_CHANGE_LAST &&
6321 type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE))
6323 CopyCustomElementPropertiesToGame(properties_element);
6326 if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC)
6328 UpdateCustomElementGraphicGadgets();
6330 else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE)
6332 if (level.use_custom_template && !LevelFileExists(-1))
6334 Request("No level tem- plate found !", REQ_CONFIRM);
6336 level.use_custom_template = FALSE;
6337 ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
6342 LoadLevelTemplate(level.use_custom_template ? -1 : level_nr);
6344 DrawEditModeWindow();
6348 static void HandleControlButtons(struct GadgetInfo *gi)
6350 int id = gi->custom_id;
6351 int button = gi->event.button;
6352 int step = BUTTON_STEPSIZE(button);
6353 int new_element = BUTTON_ELEMENT(button);
6356 if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
6357 DrawLevelText(0, 0, 0, TEXT_END);
6359 if (id < ED_NUM_CTRL1_BUTTONS && id != GADGET_ID_PROPERTIES &&
6360 id != GADGET_ID_PICK_ELEMENT && edit_mode != ED_MODE_DRAWING &&
6361 drawing_function != GADGET_ID_PICK_ELEMENT &&
6362 !(GetKeyModState() & KMOD_Control))
6364 DrawDrawingWindow();
6365 edit_mode = ED_MODE_DRAWING;
6370 case GADGET_ID_SCROLL_LEFT:
6371 if (level_xpos >= 0)
6373 if (lev_fieldx < ed_fieldx - 2)
6377 if (level_xpos < -1)
6380 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
6382 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6384 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
6385 GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
6389 case GADGET_ID_SCROLL_RIGHT:
6390 if (level_xpos <= lev_fieldx - ed_fieldx)
6392 if (lev_fieldx < ed_fieldx - 2)
6396 if (level_xpos > lev_fieldx - ed_fieldx + 1)
6397 level_xpos = lev_fieldx - ed_fieldx + 1;
6399 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
6401 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6403 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
6404 GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
6408 case GADGET_ID_SCROLL_UP:
6409 if (level_ypos >= 0)
6411 if (lev_fieldy < ed_fieldy - 2)
6415 if (level_ypos < -1)
6418 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
6420 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6422 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
6423 GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
6427 case GADGET_ID_SCROLL_DOWN:
6428 if (level_ypos <= lev_fieldy - ed_fieldy)
6430 if (lev_fieldy < ed_fieldy - 2)
6434 if (level_ypos > lev_fieldy - ed_fieldy + 1)
6435 level_ypos = lev_fieldy - ed_fieldy + 1;
6437 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP);
6439 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6441 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
6442 GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
6446 case GADGET_ID_SCROLL_HORIZONTAL:
6447 level_xpos = gi->event.item_position - 1;
6448 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6451 case GADGET_ID_SCROLL_VERTICAL:
6452 level_ypos = gi->event.item_position - 1;
6453 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6456 case GADGET_ID_SCROLL_LIST_UP:
6457 case GADGET_ID_SCROLL_LIST_DOWN:
6458 case GADGET_ID_SCROLL_LIST_VERTICAL:
6459 if (id == GADGET_ID_SCROLL_LIST_VERTICAL)
6460 element_shift = gi->event.item_position * ED_ELEMENTLIST_BUTTONS_HORIZ;
6463 step *= (id == GADGET_ID_SCROLL_LIST_UP ? -1 : +1);
6464 element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
6466 if (element_shift < 0)
6468 if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
6469 element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
6471 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
6472 GDI_SCROLLBAR_ITEM_POSITION,
6473 element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
6476 ModifyEditorElementList();
6480 case GADGET_ID_WRAP_LEFT:
6481 WrapLevel(-step, 0);
6484 case GADGET_ID_WRAP_RIGHT:
6488 case GADGET_ID_WRAP_UP:
6489 WrapLevel(0, -step);
6492 case GADGET_ID_WRAP_DOWN:
6496 case GADGET_ID_SINGLE_ITEMS:
6497 case GADGET_ID_CONNECTED_ITEMS:
6498 case GADGET_ID_LINE:
6500 case GADGET_ID_TEXT:
6501 case GADGET_ID_RECTANGLE:
6502 case GADGET_ID_FILLED_BOX:
6503 case GADGET_ID_FLOOD_FILL:
6504 case GADGET_ID_GRAB_BRUSH:
6505 case GADGET_ID_PICK_ELEMENT:
6506 if (drawing_function != GADGET_ID_PICK_ELEMENT)
6507 last_drawing_function = drawing_function;
6508 drawing_function = id;
6509 draw_with_brush = FALSE;
6512 case GADGET_ID_RANDOM_PLACEMENT:
6513 RandomPlacement(new_element);
6516 case GADGET_ID_PROPERTIES:
6517 if (edit_mode != ED_MODE_PROPERTIES)
6519 properties_element = new_element;
6520 DrawPropertiesWindow();
6521 edit_mode = ED_MODE_PROPERTIES;
6525 DrawDrawingWindow();
6526 edit_mode = ED_MODE_DRAWING;
6530 case GADGET_ID_UNDO:
6531 if (undo_buffer_steps == 0)
6533 Request("Undo buffer empty !", REQ_CONFIRM);
6537 if (edit_mode != ED_MODE_DRAWING)
6539 DrawDrawingWindow();
6540 edit_mode = ED_MODE_DRAWING;
6543 undo_buffer_position =
6544 (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
6545 undo_buffer_steps--;
6547 for(x=0; x<lev_fieldx; x++)
6548 for(y=0; y<lev_fieldy; y++)
6549 Feld[x][y] = UndoBuffer[undo_buffer_position][x][y];
6550 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos,level_ypos);
6553 case GADGET_ID_INFO:
6554 if (edit_mode != ED_MODE_INFO)
6556 DrawLevelInfoWindow();
6557 edit_mode = ED_MODE_INFO;
6561 DrawDrawingWindow();
6562 edit_mode = ED_MODE_DRAWING;
6566 case GADGET_ID_CLEAR:
6567 if (edit_mode != ED_MODE_DRAWING)
6569 DrawDrawingWindow();
6570 edit_mode = ED_MODE_DRAWING;
6573 for(x=0; x<MAX_LEV_FIELDX; x++)
6574 for(y=0; y<MAX_LEV_FIELDY; y++)
6575 Feld[x][y] = (button == 1 ? EL_EMPTY : new_element);
6576 CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
6578 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6581 case GADGET_ID_SAVE:
6582 if (leveldir_current->readonly)
6584 Request("This level is read only !", REQ_CONFIRM);
6588 if (!LevelContainsPlayer)
6589 Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
6592 boolean new_level = (!LevelFileExists(level_nr));
6595 Request("Save this level and kill the old ?", REQ_ASK))
6597 CopyPlayfield(Feld, level.field);
6599 SaveLevel(level_nr);
6603 Request("Level saved !", REQ_CONFIRM);
6607 case GADGET_ID_TEST:
6608 if (!LevelContainsPlayer)
6609 Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
6613 level.game_version = GAME_VERSION_ACTUAL;
6615 CopyPlayfield(level.field, FieldBackup);
6616 CopyPlayfield(Feld, level.field);
6618 UnmapLevelEditorGadgets();
6619 UndrawSpecialEditorDoor();
6621 CloseDoor(DOOR_CLOSE_ALL);
6623 DrawCompleteVideoDisplay();
6625 if (setup.autorecord)
6626 TapeStartRecording();
6628 level_editor_test_game = TRUE;
6629 game_status = GAME_MODE_PLAYING;
6635 case GADGET_ID_EXIT:
6636 RequestExitLevelEditor(TRUE); /* if level has changed, ask user */
6640 if (id >= GADGET_ID_ELEMENTLIST_FIRST &&
6641 id <= GADGET_ID_ELEMENTLIST_LAST)
6643 int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
6644 int new_element = editor_elements[element_position + element_shift];
6646 PickDrawingElement(button, new_element);
6648 if (!stick_element_properties_window &&
6649 drawing_function != GADGET_ID_PICK_ELEMENT &&
6650 !(GetKeyModState() & KMOD_Control))
6652 properties_element = new_element;
6653 if (edit_mode == ED_MODE_PROPERTIES)
6654 DrawPropertiesWindow();
6657 if (drawing_function == GADGET_ID_PICK_ELEMENT)
6658 ClickOnGadget(level_editor_gadget[last_drawing_function],
6662 else if (gi->event.type == GD_EVENT_PRESSED)
6663 printf("default: HandleControlButtons: GD_EVENT_PRESSED(%d)\n", id);
6664 else if (gi->event.type == GD_EVENT_RELEASED)
6665 printf("default: HandleControlButtons: GD_EVENT_RELEASED(%d)\n", id);
6666 else if (gi->event.type == GD_EVENT_MOVING)
6667 printf("default: HandleControlButtons: GD_EVENT_MOVING(%d)\n", id);
6669 printf("default: HandleControlButtons: ? (id == %d)\n", id);
6675 void HandleLevelEditorKeyInput(Key key)
6677 char letter = getCharFromKey(key);
6678 int button = MB_LEFTBUTTON;
6680 if (drawing_function == GADGET_ID_TEXT &&
6681 DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE)
6684 DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
6685 else if (key == KSYM_Delete || key == KSYM_BackSpace)
6686 DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
6687 else if (key == KSYM_Return)
6688 DrawLevelText(0, 0, 0, TEXT_NEWLINE);
6689 else if (key == KSYM_Escape)
6690 DrawLevelText(0, 0, 0, TEXT_END);
6692 else if (button_status == MB_RELEASED)
6694 int i, id = GADGET_ID_NONE;
6699 id = GADGET_ID_SCROLL_LEFT;
6702 id = GADGET_ID_SCROLL_RIGHT;
6705 id = GADGET_ID_SCROLL_UP;
6708 id = GADGET_ID_SCROLL_DOWN;
6711 id = GADGET_ID_SCROLL_LIST_UP;
6712 button = MB_RIGHTBUTTON;
6714 case KSYM_Page_Down:
6715 id = GADGET_ID_SCROLL_LIST_DOWN;
6716 button = MB_RIGHTBUTTON;
6720 if (edit_mode == ED_MODE_DRAWING)
6722 RequestExitLevelEditor(setup.ask_on_escape);
6726 DrawDrawingWindow();
6727 edit_mode = ED_MODE_DRAWING;
6735 if (id != GADGET_ID_NONE)
6736 ClickOnGadget(level_editor_gadget[id], button);
6737 else if (letter == '.')
6738 ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], button);
6739 else if (key == KSYM_Return || key == setup.shortcut.toggle_pause)
6740 ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
6742 for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
6743 if (letter && letter == control_info[i].shortcut)
6744 if (!anyTextGadgetActive())
6745 ClickOnGadget(level_editor_gadget[i], button);
6749 void HandleLevelEditorIdle()
6751 static unsigned long action_delay = 0;
6752 unsigned long action_delay_value = GameFrameDelay;
6753 int xpos = 1, ypos = 2;
6755 if (edit_mode != ED_MODE_PROPERTIES)
6758 if (!DelayReached(&action_delay, action_delay_value))
6761 DrawGraphicAnimationExt(drawto,
6763 SY + ypos * TILEY + MINI_TILEY / 2,
6764 el2img(properties_element), -1, NO_MASKING);
6766 MarkTileDirty(xpos, ypos);
6767 MarkTileDirty(xpos, ypos + 1);
6769 FrameCounter++; /* increase animation frame counter */
6772 void ClearEditorGadgetInfoText()
6774 DrawBackground(INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
6777 void HandleEditorGadgetInfoText(void *ptr)
6779 struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
6780 char infotext[MAX_OUTPUT_LINESIZE + 1];
6781 char shortcut[MAX_OUTPUT_LINESIZE + 1];
6782 int max_infotext_len = getMaxInfoTextLength();
6784 if (game_status != GAME_MODE_EDITOR)
6787 ClearEditorGadgetInfoText();
6789 if (gi->event.type == GD_EVENT_INFO_LEAVING)
6792 /* misuse this function to delete brush cursor, if needed */
6793 if (edit_mode == ED_MODE_DRAWING && draw_with_brush)
6794 DeleteBrushFromCursor();
6796 if (gi == NULL || gi->info_text == NULL)
6799 strncpy(infotext, gi->info_text, max_infotext_len);
6800 infotext[max_infotext_len] = '\0';
6802 if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
6804 int key = control_info[gi->custom_id].shortcut;
6808 if (gi->custom_id == GADGET_ID_SINGLE_ITEMS) /* special case 1 */
6809 sprintf(shortcut, " ('.' or '%c')", key);
6810 else if (gi->custom_id == GADGET_ID_PICK_ELEMENT) /* special case 2 */
6811 sprintf(shortcut, " ('%c' or 'Ctrl')", key);
6812 else if (gi->custom_id == GADGET_ID_TEST) /* special case 3 */
6813 sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
6814 else /* normal case */
6815 sprintf(shortcut, " ('%s%c')",
6816 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
6818 if (strlen(infotext) + strlen(shortcut) <= max_infotext_len)
6819 strcat(infotext, shortcut);
6823 DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FONT_TEXT_2);
6826 static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
6828 static int start_lx, start_ly;
6830 int id = gi->custom_id;
6831 int sx = gi->event.x;
6832 int sy = gi->event.y;
6833 int lx = sx + level_xpos;
6834 int ly = sy + level_ypos;
6835 int min_sx = 0, min_sy = 0;
6836 int max_sx = gi->drawing.area_xsize - 1;
6837 int max_sy = gi->drawing.area_ysize - 1;
6838 int actual_drawing_function = drawing_function;
6840 /* pressed Control key: simulate picking element */
6841 if (GetKeyModState() & KMOD_Control)
6842 actual_drawing_function = GADGET_ID_PICK_ELEMENT;
6844 ClearEditorGadgetInfoText();
6846 if (gi->event.type == GD_EVENT_INFO_LEAVING)
6849 /* make sure to stay inside drawing area boundaries */
6850 sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
6851 sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
6853 if (id == GADGET_ID_DRAWING_LEVEL)
6857 int min_lx = 0, min_ly = 0;
6858 int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
6860 /* get positions inside level field */
6861 lx = sx + level_xpos;
6862 ly = sy + level_ypos;
6864 /* make sure to stay inside level field boundaries */
6865 lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
6866 ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
6868 /* correct drawing area positions accordingly */
6869 sx = lx - level_xpos;
6870 sy = ly - level_ypos;
6873 if (IN_ED_FIELD(sx,sy) && IN_LEV_FIELD(lx, ly))
6875 if (button_status) /* if (gi->state == GD_BUTTON_PRESSED) */
6877 if (gi->event.type == GD_EVENT_PRESSED)
6883 switch (actual_drawing_function)
6885 case GADGET_ID_SINGLE_ITEMS:
6886 infotext = "Drawing single items";
6888 case GADGET_ID_CONNECTED_ITEMS:
6889 infotext = "Drawing connected items";
6891 case GADGET_ID_LINE:
6892 infotext = "Drawing line";
6895 infotext = "Drawing arc";
6897 case GADGET_ID_TEXT:
6898 infotext = "Setting text cursor";
6900 case GADGET_ID_RECTANGLE:
6901 infotext = "Drawing rectangle";
6903 case GADGET_ID_FILLED_BOX:
6904 infotext = "Drawing filled box";
6906 case GADGET_ID_FLOOD_FILL:
6907 infotext = "Flood fill";
6909 case GADGET_ID_GRAB_BRUSH:
6910 infotext = "Grabbing brush";
6912 case GADGET_ID_PICK_ELEMENT:
6913 infotext = "Picking element";
6917 infotext = "Drawing position";
6921 if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
6922 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6923 "%s: %d, %d", infotext, lx, ly);
6925 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6926 "%s: %d, %d", infotext,
6927 ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
6929 else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
6930 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6931 "%s", getElementInfoText(Feld[lx][ly]));
6933 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6934 "Level position: %d, %d", lx, ly);
6937 /* misuse this function to draw brush cursor, if needed */
6938 if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status)
6940 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
6941 CopyBrushToCursor(sx, sy);
6943 DeleteBrushFromCursor();
6946 else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
6948 if (id == GADGET_ID_AMOEBA_CONTENT)
6949 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6950 getElementInfoText(level.amoeba_content));
6951 else if (id == GADGET_ID_CUSTOM_GRAPHIC)
6952 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6953 getElementInfoText(custom_element.gfx_element));
6954 else if (id == GADGET_ID_CUSTOM_CONTENT)
6955 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6956 getElementInfoText(custom_element.content[sx][sy]));
6957 else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
6958 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6959 getElementInfoText(custom_element.change.target_element));
6960 else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
6961 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6962 getElementInfoText(custom_element.change.content[sx][sy]));
6963 else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
6964 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6965 getElementInfoText(custom_element.change.trigger_element));
6966 else if (id == GADGET_ID_RANDOM_BACKGROUND)
6967 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6968 getElementInfoText(random_placement_background_element));
6969 else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
6970 id <= GADGET_ID_ELEMENT_CONTENT_7)
6972 int i = id - GADGET_ID_ELEMENT_CONTENT_0;
6974 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, "%s",
6975 getElementInfoText(level.yamyam_content[i][sx][sy]));
6980 if (id == GADGET_ID_AMOEBA_CONTENT)
6981 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6983 else if (id == GADGET_ID_CUSTOM_GRAPHIC)
6984 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6985 "Custom graphic element");
6986 else if (id == GADGET_ID_CUSTOM_CONTENT)
6987 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6988 "Custom element content position: %d, %d", sx, sy);
6989 else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
6990 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6991 "New element after change");
6992 else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
6993 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6994 "New extended elements after change");
6995 else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
6996 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
6997 "Other element triggering change");
6998 else if (id == GADGET_ID_RANDOM_BACKGROUND)
6999 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
7000 "Random placement background");
7001 else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
7002 id <= GADGET_ID_ELEMENT_CONTENT_7)
7003 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
7004 "Content area %d position: %d, %d",
7005 id - GADGET_ID_ELEMENT_CONTENT_0 + 1, sx, sy);
7009 void RequestExitLevelEditor(boolean ask_if_level_has_changed)
7011 if (!ask_if_level_has_changed ||
7013 Request("Level has changed! Exit without saving ?",
7014 REQ_ASK | REQ_STAY_OPEN))
7016 CloseDoor(DOOR_CLOSE_1);
7018 CloseDoor(DOOR_CLOSE_ALL);
7020 game_status = GAME_MODE_MAIN;
7025 CloseDoor(DOOR_CLOSE_1);
7026 BlitBitmap(bitmap_db_door, bitmap_db_door,
7027 DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1, DXSIZE,DYSIZE,
7028 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
7029 OpenDoor(DOOR_OPEN_1);