rnd-20070428-1-src
[rocksndiamonds.git] / src / screens.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * screens.c                                                *
12 ***********************************************************/
13
14 #include "libgame/libgame.h"
15
16 #include "screens.h"
17 #include "events.h"
18 #include "game.h"
19 #include "tools.h"
20 #include "editor.h"
21 #include "files.h"
22 #include "tape.h"
23 #include "cartoons.h"
24 #include "network.h"
25 #include "init.h"
26 #include "config.h"
27
28 /* screens on the info screen */
29 #define INFO_MODE_MAIN                  0
30 #define INFO_MODE_TITLE                 1
31 #define INFO_MODE_ELEMENTS              2
32 #define INFO_MODE_MUSIC                 3
33 #define INFO_MODE_CREDITS               4
34 #define INFO_MODE_PROGRAM               5
35 #define INFO_MODE_VERSION               6
36 #define INFO_MODE_LEVELSET              7
37
38 #define MAX_INFO_MODES                  8
39
40 /* screens on the setup screen */
41 #define SETUP_MODE_MAIN                 0
42 #define SETUP_MODE_GAME                 1
43 #define SETUP_MODE_EDITOR               2
44 #define SETUP_MODE_GRAPHICS             3
45 #define SETUP_MODE_SOUND                4
46 #define SETUP_MODE_ARTWORK              5
47 #define SETUP_MODE_INPUT                6
48 #define SETUP_MODE_SHORTCUTS_1          7
49 #define SETUP_MODE_SHORTCUTS_2          8
50
51 /* sub-screens on the setup screen (generic) */
52 #define SETUP_MODE_CHOOSE_ARTWORK       9
53 #define SETUP_MODE_CHOOSE_OTHER         10
54
55 /* sub-screens on the setup screen (specific) */
56 #define SETUP_MODE_CHOOSE_GAME_SPEED    11
57 #define SETUP_MODE_CHOOSE_SCREEN_MODE   12
58 #define SETUP_MODE_CHOOSE_SCROLL_DELAY  13
59 #define SETUP_MODE_CHOOSE_GRAPHICS      14
60 #define SETUP_MODE_CHOOSE_SOUNDS        15
61 #define SETUP_MODE_CHOOSE_MUSIC         16
62
63 #define MAX_SETUP_MODES                 17
64
65 /* for input setup functions */
66 #define SETUPINPUT_SCREEN_POS_START     0
67 #define SETUPINPUT_SCREEN_POS_END       (SCR_FIELDY - 4)
68 #define SETUPINPUT_SCREEN_POS_EMPTY1    (SETUPINPUT_SCREEN_POS_START + 3)
69 #define SETUPINPUT_SCREEN_POS_EMPTY2    (SETUPINPUT_SCREEN_POS_END - 1)
70
71 /* for various menu stuff  */
72 #define MENU_SCREEN_START_XPOS          1
73 #define MENU_SCREEN_START_YPOS          2
74 #define MENU_SCREEN_VALUE_XPOS          14
75 #define MENU_SCREEN_MAX_XPOS            (SCR_FIELDX - 1)
76 #define MENU_TITLE1_YPOS                8
77 #define MENU_TITLE2_YPOS                46
78 #define MAX_INFO_ELEMENTS_ON_SCREEN     10
79 #define MAX_MENU_ENTRIES_ON_SCREEN      (SCR_FIELDY - MENU_SCREEN_START_YPOS)
80 #define MAX_MENU_TEXT_LENGTH_BIG        (MENU_SCREEN_VALUE_XPOS -       \
81                                          MENU_SCREEN_START_XPOS)
82 #define MAX_MENU_TEXT_LENGTH_MEDIUM     (MAX_MENU_TEXT_LENGTH_BIG * 2)
83
84 /* buttons and scrollbars identifiers */
85 #define SCREEN_CTRL_ID_PREV_LEVEL       0
86 #define SCREEN_CTRL_ID_NEXT_LEVEL       1
87 #define SCREEN_CTRL_ID_PREV_PLAYER      2
88 #define SCREEN_CTRL_ID_NEXT_PLAYER      3
89 #define SCREEN_CTRL_ID_SCROLL_UP        4
90 #define SCREEN_CTRL_ID_SCROLL_DOWN      5
91 #define SCREEN_CTRL_ID_SCROLL_VERTICAL  6
92
93 #define NUM_SCREEN_GADGETS              7
94
95 #define NUM_SCREEN_MENUBUTTONS          4
96 #define NUM_SCREEN_SCROLLBUTTONS        2
97 #define NUM_SCREEN_SCROLLBARS           1
98
99 #define SCREEN_MASK_MAIN                (1 << 0)
100 #define SCREEN_MASK_INPUT               (1 << 1)
101
102 /* graphic position and size values for buttons and scrollbars */
103 #define SC_MENUBUTTON_XSIZE             TILEX
104 #define SC_MENUBUTTON_YSIZE             TILEY
105
106 #define SC_SCROLLBUTTON_XSIZE           TILEX
107 #define SC_SCROLLBUTTON_YSIZE           TILEY
108
109 #define SC_SCROLLBAR_XPOS               (SXSIZE - SC_SCROLLBUTTON_XSIZE)
110
111 #define SC_SCROLL_VERTICAL_XSIZE        SC_SCROLLBUTTON_XSIZE
112 #define SC_SCROLL_VERTICAL_YSIZE        ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
113                                          SC_SCROLLBUTTON_YSIZE)
114
115 #define SC_SCROLL_UP_XPOS               SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_UP_YPOS               (2 * SC_SCROLLBUTTON_YSIZE)
117
118 #define SC_SCROLL_VERTICAL_XPOS         SC_SCROLLBAR_XPOS
119 #define SC_SCROLL_VERTICAL_YPOS         (SC_SCROLL_UP_YPOS + \
120                                          SC_SCROLLBUTTON_YSIZE)
121
122 #define SC_SCROLL_DOWN_XPOS             SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_DOWN_YPOS             (SC_SCROLL_VERTICAL_YPOS + \
124                                          SC_SCROLL_VERTICAL_YSIZE)
125
126 #define SC_BORDER_SIZE                  14
127
128 #if 0
129 /* other useful macro definitions */
130 #define BUTTON_GRAPHIC_ACTIVE(g)                                               \
131         (g == IMG_MENU_BUTTON_LEFT       ? IMG_MENU_BUTTON_LEFT_ACTIVE       : \
132          g == IMG_MENU_BUTTON_RIGHT      ? IMG_MENU_BUTTON_RIGHT_ACTIVE      : \
133          g == IMG_MENU_BUTTON_UP         ? IMG_MENU_BUTTON_UP_ACTIVE         : \
134          g == IMG_MENU_BUTTON_DOWN       ? IMG_MENU_BUTTON_DOWN_ACTIVE       : \
135          g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE : \
136          g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE : \
137          g == IMG_MENU_BUTTON_PREV_LEVEL ? IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE : \
138          g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE : \
139          g == IMG_MENU_BUTTON_NAME       ? IMG_MENU_BUTTON_NAME_ACTIVE       : \
140          g == IMG_MENU_BUTTON_LEVELS     ? IMG_MENU_BUTTON_LEVELS_ACTIVE     : \
141          g == IMG_MENU_BUTTON_SCORES     ? IMG_MENU_BUTTON_SCORES_ACTIVE     : \
142          g == IMG_MENU_BUTTON_EDITOR     ? IMG_MENU_BUTTON_EDITOR_ACTIVE     : \
143          g == IMG_MENU_BUTTON_INFO       ? IMG_MENU_BUTTON_INFO_ACTIVE       : \
144          g == IMG_MENU_BUTTON_GAME       ? IMG_MENU_BUTTON_GAME_ACTIVE       : \
145          g == IMG_MENU_BUTTON_SETUP      ? IMG_MENU_BUTTON_SETUP_ACTIVE      : \
146          g == IMG_MENU_BUTTON_QUIT       ? IMG_MENU_BUTTON_QUIT_ACTIVE       : \
147          IMG_MENU_BUTTON_ACTIVE)
148 #endif
149
150
151 /* forward declarations of internal functions */
152 static void HandleScreenGadgets(struct GadgetInfo *);
153 static void HandleSetupScreen_Generic(int, int, int, int, int);
154 static void HandleSetupScreen_Input(int, int, int, int, int);
155 static void CustomizeKeyboard(int);
156 static void CalibrateJoystick(int);
157 static void execSetupGame(void);
158 static void execSetupGraphics(void);
159 static void execSetupArtwork(void);
160 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
161
162 static void DrawChooseLevel(void);
163 static void DrawInfoScreen(void);
164 static void DrawAndFadeInInfoScreen(int);
165 static void DrawSetupScreen(void);
166
167 static void DrawInfoScreenExt(int, int);
168 static void DrawInfoScreen_NotAvailable(char *, char *);
169 static void DrawInfoScreen_HelpAnim(int, int, boolean);
170 static void DrawInfoScreen_HelpText(int, int, int, int);
171 static void HandleInfoScreen_Main(int, int, int, int, int);
172 static void HandleInfoScreen_TitleScreen(int);
173 static void HandleInfoScreen_Elements(int);
174 static void HandleInfoScreen_Music(int);
175 static void HandleInfoScreen_Credits(int);
176 static void HandleInfoScreen_Program(int);
177 static void HandleInfoScreen_Version(int);
178
179 static void MapScreenMenuGadgets(int);
180 static void MapScreenTreeGadgets(TreeInfo *);
181
182 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
183
184 static int info_mode = INFO_MODE_MAIN;
185 static int setup_mode = SETUP_MODE_MAIN;
186
187 static TreeInfo *screen_modes = NULL;
188 static TreeInfo *screen_mode_current = NULL;
189
190 static TreeInfo *scroll_delays = NULL;
191 static TreeInfo *scroll_delay_current = NULL;
192
193 static TreeInfo *game_speeds = NULL;
194 static TreeInfo *game_speed_current = NULL;
195
196 static struct
197 {
198   int value;
199   char *text;
200 } game_speeds_list[] =
201 {
202 #if 1
203   {     30,     "Very Slow"                     },
204   {     25,     "Slow"                          },
205   {     20,     "Normal"                        },
206   {     15,     "Fast"                          },
207   {     10,     "Very Fast"                     },
208 #else
209   {     1000,   "1/1s (Extremely Slow)"         },
210   {     500,    "1/2s"                          },
211   {     200,    "1/5s"                          },
212   {     100,    "1/10s"                         },
213   {     50,     "1/20s"                         },
214   {     29,     "1/35s (Original Supaplex)"     },
215   {     25,     "1/40s"                         },
216   {     20,     "1/50s (Normal Speed)"          },
217   {     14,     "1/70s (Maximum Supaplex)"      },
218   {     10,     "1/100s"                        },
219   {     5,      "1/200s"                        },
220   {     2,      "1/500s"                        },
221   {     1,      "1/1000s (Extremely Fast)"      },
222 #endif
223
224   {     -1,     NULL                            },
225 };
226
227 static struct
228 {
229   int value;
230   char *text;
231 } scroll_delays_list[] =
232 {
233   {     0,      "0 Tiles (No Scroll Delay)"     },
234   {     1,      "1 Tile"                        },
235   {     2,      "2 Tiles"                       },
236   {     3,      "3 Tiles (Default)"             },
237   {     4,      "4 Tiles"                       },
238   {     5,      "5 Tiles"                       },
239   {     6,      "6 Tiles"                       },
240   {     7,      "7 Tiles"                       },
241   {     8,      "8 Tiles (Maximum Scroll Delay)"},
242
243   {     -1,     NULL                            },
244 };
245
246 #define DRAW_MODE(s)            ((s) >= GAME_MODE_MAIN &&               \
247                                  (s) <= GAME_MODE_SETUP ? (s) :         \
248                                  (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
249                                  GAME_MODE_MAIN : GAME_MODE_DEFAULT)
250
251 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
252 #define DRAW_MODE_INFO(i)       ((i) >= INFO_MODE_ELEMENTS &&           \
253                                  (i) <= INFO_MODE_LEVELSET ? (i) :      \
254                                  INFO_MODE_MAIN)
255
256 #define DRAW_MODE_SETUP(i)      ((i) >= SETUP_MODE_MAIN &&              \
257                                  (i) <= SETUP_MODE_SHORTCUTS_2 ? (i) :  \
258                                  (i) >= SETUP_MODE_CHOOSE_GRAPHICS &&   \
259                                  (i) <= SETUP_MODE_CHOOSE_MUSIC ?       \
260                                  SETUP_MODE_CHOOSE_ARTWORK :            \
261                                  SETUP_MODE_CHOOSE_OTHER)
262
263 #define DRAW_XOFFSET_INFO(i)    (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ?  \
264                                  menu.draw_xoffset[GAME_MODE_INFO] :    \
265                                  menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
266 #define DRAW_YOFFSET_INFO(i)    (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ?  \
267                                  menu.draw_yoffset[GAME_MODE_INFO] :    \
268                                  menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
269
270 #define DRAW_XOFFSET_SETUP(i)   (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
271                                  menu.draw_xoffset[GAME_MODE_SETUP] :   \
272                                  menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
273 #define DRAW_YOFFSET_SETUP(i)   (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
274                                  menu.draw_yoffset[GAME_MODE_SETUP] :   \
275                                  menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
276
277 #define DRAW_XOFFSET(s)         ((s) == GAME_MODE_INFO ?                \
278                                  DRAW_XOFFSET_INFO(info_mode) :         \
279                                  (s) == GAME_MODE_SETUP ?               \
280                                  DRAW_XOFFSET_SETUP(setup_mode) :       \
281                                  menu.draw_xoffset[DRAW_MODE(s)])
282 #define DRAW_YOFFSET(s)         ((s) == GAME_MODE_INFO ?                \
283                                  DRAW_YOFFSET_INFO(info_mode) :         \
284                                  (s) == GAME_MODE_SETUP ?               \
285                                  DRAW_YOFFSET_SETUP(setup_mode) :       \
286                                  menu.draw_yoffset[DRAW_MODE(s)])
287
288 #define mSX                     (SX + DRAW_XOFFSET(game_status))
289 #define mSY                     (SY + DRAW_YOFFSET(game_status))
290
291 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ?   \
292                                     menu.list_size[game_status] :       \
293                                     MAX_MENU_ENTRIES_ON_SCREEN)
294
295 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
296 #define NUM_SCROLLBAR_BITMAPS           2
297 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
298 #endif
299
300
301 /* title display and control definitions */
302
303 #define MAX_NUM_TITLE_SCREENS   (2 * MAX_NUM_TITLE_IMAGES +             \
304                                  2 * MAX_NUM_TITLE_MESSAGES)
305
306 static int num_title_screens = 0;
307
308 struct TitleControlInfo
309 {
310   boolean is_image;
311   boolean initial;
312   int local_nr;
313   int sort_priority;
314 };
315
316 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
317
318 /* main menu display and control definitions */
319
320 #define MAIN_CONTROL_NAME                       0
321 #define MAIN_CONTROL_LEVELS                     1
322 #define MAIN_CONTROL_SCORES                     2
323 #define MAIN_CONTROL_EDITOR                     3
324 #define MAIN_CONTROL_INFO                       4
325 #define MAIN_CONTROL_GAME                       5
326 #define MAIN_CONTROL_SETUP                      6
327 #define MAIN_CONTROL_QUIT                       7
328 #define MAIN_CONTROL_PREV_LEVEL                 8
329 #define MAIN_CONTROL_NEXT_LEVEL                 9
330 #define MAIN_CONTROL_FIRST_LEVEL                10
331 #define MAIN_CONTROL_LAST_LEVEL                 11
332 #define MAIN_CONTROL_LEVEL_NUMBER               12
333 #define MAIN_CONTROL_LEVEL_INFO_1               13
334 #define MAIN_CONTROL_LEVEL_INFO_2               14
335 #define MAIN_CONTROL_LEVEL_NAME                 15
336 #define MAIN_CONTROL_LEVEL_AUTHOR               16
337 #define MAIN_CONTROL_LEVEL_YEAR                 17
338 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM        18
339 #define MAIN_CONTROL_LEVEL_IMPORTED_BY          19
340 #define MAIN_CONTROL_LEVEL_TESTED_BY            20
341 #define MAIN_CONTROL_TITLE_1                    21
342 #define MAIN_CONTROL_TITLE_2                    22
343 #define MAIN_CONTROL_TITLE_3                    23
344
345 static char str_main_text_name[10];
346 static char str_main_text_first_level[10];
347 static char str_main_text_last_level[10];
348 static char str_main_text_level_number[10];
349
350 static char *main_text_name                     = str_main_text_name;
351 static char *main_text_first_level              = str_main_text_first_level;
352 static char *main_text_last_level               = str_main_text_last_level;
353 static char *main_text_level_number             = str_main_text_level_number;
354 static char *main_text_levels                   = "Levelset";
355 static char *main_text_scores                   = "Hall Of Fame";
356 static char *main_text_editor                   = "Level Creator";
357 static char *main_text_info                     = "Info Screen";
358 static char *main_text_game                     = "Start Game";
359 static char *main_text_setup                    = "Setup";
360 static char *main_text_quit                     = "Quit";
361 static char *main_text_level_name               = level.name;
362 static char *main_text_level_author             = level.author;
363 static char *main_text_level_year               = NULL;
364 static char *main_text_level_imported_from      = NULL;
365 static char *main_text_level_imported_by        = NULL;
366 static char *main_text_level_tested_by          = NULL;
367 static char *main_text_title_1                  = PROGRAM_TITLE_STRING;
368 static char *main_text_title_2                  = PROGRAM_COPYRIGHT_STRING;
369 static char *main_text_title_3                  = PROGRAM_GAME_BY_STRING;
370
371 struct MainControlInfo
372 {
373   int nr;
374
375   struct MenuPosInfo *pos_button;
376   int button_graphic;
377
378   struct TextPosInfo *pos_text;
379   char **text;
380
381   struct TextPosInfo *pos_input;
382   char **input;
383 };
384
385 static struct MainControlInfo main_controls[] =
386 {
387   {
388     MAIN_CONTROL_NAME,
389     &menu.main.button.name,             IMG_MENU_BUTTON_NAME,
390     &menu.main.text.name,               &main_text_name,
391     &menu.main.input.name,              &setup.player_name,
392   },
393   {
394     MAIN_CONTROL_LEVELS,
395     &menu.main.button.levels,           IMG_MENU_BUTTON_LEVELS,
396     &menu.main.text.levels,             &main_text_levels,
397     NULL,                               NULL,
398   },
399   {
400     MAIN_CONTROL_SCORES,
401     &menu.main.button.scores,           IMG_MENU_BUTTON_SCORES,
402     &menu.main.text.scores,             &main_text_scores,
403     NULL,                               NULL,
404   },
405   {
406     MAIN_CONTROL_EDITOR,
407     &menu.main.button.editor,           IMG_MENU_BUTTON_EDITOR,
408     &menu.main.text.editor,             &main_text_editor,
409     NULL,                               NULL,
410   },
411   {
412     MAIN_CONTROL_INFO,
413     &menu.main.button.info,             IMG_MENU_BUTTON_INFO,
414     &menu.main.text.info,               &main_text_info,
415     NULL,                               NULL,
416   },
417   {
418     MAIN_CONTROL_GAME,
419     &menu.main.button.game,             IMG_MENU_BUTTON_GAME,
420     &menu.main.text.game,               &main_text_game,
421     NULL,                               NULL,
422   },
423   {
424     MAIN_CONTROL_SETUP,
425     &menu.main.button.setup,            IMG_MENU_BUTTON_SETUP,
426     &menu.main.text.setup,              &main_text_setup,
427     NULL,                               NULL,
428   },
429   {
430     MAIN_CONTROL_QUIT,
431     &menu.main.button.quit,             IMG_MENU_BUTTON_QUIT,
432     &menu.main.text.quit,               &main_text_quit,
433     NULL,                               NULL,
434   },
435 #if 0
436   /* (these two buttons are real gadgets) */
437   {
438     MAIN_CONTROL_PREV_LEVEL,
439     &menu.main.button.prev_level,       IMG_MENU_BUTTON_PREV_LEVEL,
440     NULL,                               NULL,
441     NULL,                               NULL,
442   },
443   {
444     MAIN_CONTROL_NEXT_LEVEL,
445     &menu.main.button.next_level,       IMG_MENU_BUTTON_NEXT_LEVEL,
446     NULL,                               NULL,
447     NULL,                               NULL,
448   },
449 #endif
450   {
451     MAIN_CONTROL_FIRST_LEVEL,
452     NULL,                               -1,
453     &menu.main.text.first_level,        &main_text_first_level,
454     NULL,                               NULL,
455   },
456   {
457     MAIN_CONTROL_LAST_LEVEL,
458     NULL,                               -1,
459     &menu.main.text.last_level,         &main_text_last_level,
460     NULL,                               NULL,
461   },
462   {
463     MAIN_CONTROL_LEVEL_NUMBER,
464     NULL,                               -1,
465     &menu.main.text.level_number,       &main_text_level_number,
466     NULL,                               NULL,
467   },
468   {
469     MAIN_CONTROL_LEVEL_INFO_1,
470     NULL,                               -1,
471     &menu.main.text.level_info_1,       NULL,
472     NULL,                               NULL,
473   },
474   {
475     MAIN_CONTROL_LEVEL_INFO_2,
476     NULL,                               -1,
477     &menu.main.text.level_info_2,       NULL,
478     NULL,                               NULL,
479   },
480   {
481     MAIN_CONTROL_LEVEL_NAME,
482     NULL,                               -1,
483     &menu.main.text.level_name,         &main_text_level_name,
484     NULL,                               NULL,
485   },
486   {
487     MAIN_CONTROL_LEVEL_AUTHOR,
488     NULL,                               -1,
489     &menu.main.text.level_author,       &main_text_level_author,
490     NULL,                               NULL,
491   },
492   {
493     MAIN_CONTROL_LEVEL_YEAR,
494     NULL,                               -1,
495     &menu.main.text.level_year,         &main_text_level_year,
496     NULL,                               NULL,
497   },
498   {
499     MAIN_CONTROL_LEVEL_IMPORTED_FROM,
500     NULL,                               -1,
501     &menu.main.text.level_imported_from, &main_text_level_imported_from,
502     NULL,                               NULL,
503   },
504   {
505     MAIN_CONTROL_LEVEL_IMPORTED_BY,
506     NULL,                               -1,
507     &menu.main.text.level_imported_by,  &main_text_level_imported_by,
508     NULL,                               NULL,
509   },
510   {
511     MAIN_CONTROL_LEVEL_TESTED_BY,
512     NULL,                               -1,
513     &menu.main.text.level_tested_by,    &main_text_level_tested_by,
514     NULL,                               NULL,
515   },
516   {
517     MAIN_CONTROL_TITLE_1,
518     NULL,                               -1,
519     &menu.main.text.title_1,            &main_text_title_1,
520     NULL,                               NULL,
521   },
522   {
523     MAIN_CONTROL_TITLE_2,
524     NULL,                               -1,
525     &menu.main.text.title_2,            &main_text_title_2,
526     NULL,                               NULL,
527   },
528   {
529     MAIN_CONTROL_TITLE_3,
530     NULL,                               -1,
531     &menu.main.text.title_3,            &main_text_title_3,
532     NULL,                               NULL,
533   },
534
535   {
536     -1,
537     NULL,                               -1,
538     NULL,                               NULL,
539     NULL,                               NULL,
540   }
541 };
542
543
544 static int getTitleScreenGraphic(int nr, boolean initial)
545 {
546   return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
547 }
548
549 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
550 {
551   return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
552 }
553
554 #if 0
555 static int getTitleScreenGameMode(boolean initial)
556 {
557   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
558 }
559 #endif
560
561 static int getTitleMessageGameMode(boolean initial)
562 {
563   return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
564 }
565
566 #if 0
567 static int getTitleScreenBackground(boolean initial)
568 {
569   return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
570 }
571 #endif
572
573 #if 0
574 static int getTitleMessageBackground(int nr, boolean initial)
575 {
576   return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
577 }
578 #endif
579
580 static int getTitleBackground(int nr, boolean initial, boolean is_image)
581 {
582   int base = (is_image ?
583               (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
584                          IMG_BACKGROUND_TITLESCREEN_1) :
585               (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
586                          IMG_BACKGROUND_TITLEMESSAGE_1));
587   int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
588                                   IMG_BACKGROUND_TITLE);
589   int graphic_local = base + nr;
590
591   if (graphic_info[graphic_local].bitmap != NULL)
592     return graphic_local;
593
594   if (graphic_info[graphic_global].bitmap != NULL)
595     return graphic_global;
596
597   return IMG_UNDEFINED;
598 }
599
600 static int getTitleSound(struct TitleControlInfo *tci)
601 {
602   boolean is_image = tci->is_image;
603   int initial = tci->initial;
604   int nr = tci->local_nr;
605   int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
606   int base = (is_image ?
607               (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
608                          SND_BACKGROUND_TITLESCREEN_1) :
609               (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
610                          SND_BACKGROUND_TITLEMESSAGE_1));
611   int sound_global = menu.sound[mode];
612   int sound_local = base + nr;
613
614 #if 0
615   printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
616          nr, initial, is_image,
617          sound_global, getSoundListEntry(sound_global)->filename,
618          sound_local, getSoundListEntry(sound_local)->filename);
619 #endif
620
621   if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
622     return sound_local;
623
624   if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
625     return sound_global;
626
627   return SND_UNDEFINED;
628 }
629
630 static int getTitleMusic(struct TitleControlInfo *tci)
631 {
632   boolean is_image = tci->is_image;
633   int initial = tci->initial;
634   int nr = tci->local_nr;
635   int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
636   int base = (is_image ?
637               (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
638                          MUS_BACKGROUND_TITLESCREEN_1) :
639               (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
640                          MUS_BACKGROUND_TITLEMESSAGE_1));
641   int music_global = menu.music[mode];
642   int music_local = base + nr;
643
644 #if 0
645   printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
646          nr, initial, is_image,
647          music_global, getMusicListEntry(music_global)->filename,
648          music_local, getMusicListEntry(music_local)->filename);
649 #endif
650
651   if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
652     return music_local;
653
654   if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
655     return music_global;
656
657   return MUS_UNDEFINED;
658 }
659
660 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
661 {
662   boolean is_image = tci->is_image;
663   int initial = tci->initial;
664   int nr = tci->local_nr;
665   struct TitleFadingInfo ti;
666
667   if (is_image)
668   {
669     int graphic = getTitleScreenGraphic(nr, initial);
670
671     /* initialize fading control values to default title config settings */
672     ti = (initial ? title_initial_default : title_default);
673
674     /* override default settings with image config settings, if defined */
675     if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
676       ti.fade_mode = graphic_info[graphic].fade_mode;
677     if (graphic_info[graphic].fade_delay > -1)
678       ti.fade_delay = graphic_info[graphic].fade_delay;
679     if (graphic_info[graphic].post_delay > -1)
680       ti.post_delay = graphic_info[graphic].post_delay;
681     if (graphic_info[graphic].auto_delay > -1)
682       ti.auto_delay = graphic_info[graphic].auto_delay;
683   }
684   else
685   {
686     if (initial)
687     {
688       ti.fade_mode  = titlemessage_initial[nr].fade_mode;
689       ti.fade_delay = titlemessage_initial[nr].fade_delay;
690       ti.post_delay = titlemessage_initial[nr].post_delay;
691       ti.auto_delay = titlemessage_initial[nr].auto_delay;
692     }
693     else
694     {
695       ti.fade_mode  = titlemessage[nr].fade_mode;
696       ti.fade_delay = titlemessage[nr].fade_delay;
697       ti.post_delay = titlemessage[nr].post_delay;
698       ti.auto_delay = titlemessage[nr].auto_delay;
699     }
700   }
701
702 #if 0
703   if (ti.anim_mode == ANIM_NONE)
704     ti.fade_delay = ti.post_delay = 0;
705 #endif
706
707   return ti;
708 }
709
710 static int compareTitleControlInfo(const void *object1, const void *object2)
711 {
712   const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
713   const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
714   int compare_result;
715
716   if (tci1->initial != tci2->initial)
717     compare_result = (tci1->initial ? -1 : +1);
718   else if (tci1->sort_priority != tci2->sort_priority)
719     compare_result = tci1->sort_priority - tci2->sort_priority;
720   else if (tci1->is_image != tci2->is_image)
721     compare_result = (tci1->is_image ? -1 : +1);
722   else
723     compare_result = tci1->local_nr - tci2->local_nr;
724
725   return compare_result;
726 }
727
728 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
729                                                     boolean initial,
730                                                     int nr, int sort_priority)
731 {
732   title_controls[num_title_screens].is_image = is_image;
733   title_controls[num_title_screens].initial = initial;
734   title_controls[num_title_screens].local_nr = nr;
735   title_controls[num_title_screens].sort_priority = sort_priority;
736
737   num_title_screens++;
738 }
739
740 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
741 {
742   int i;
743
744   for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
745   {
746     int graphic = getTitleScreenGraphic(i, initial);
747     Bitmap *bitmap = graphic_info[graphic].bitmap;
748     int sort_priority = graphic_info[graphic].sort_priority;
749
750     if (bitmap != NULL)
751       InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
752   }
753
754   for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
755   {
756     struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
757     char *filename = getLevelSetTitleMessageFilename(i, initial);
758     int sort_priority = tmi->sort_priority;
759
760     if (filename != NULL)
761       InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
762   }
763 }
764
765 static void InitializeTitleControls(boolean show_title_initial)
766 {
767   num_title_screens = 0;
768
769   if (show_title_initial)
770     InitializeTitleControls_CheckTitleInfo(TRUE);
771
772   InitializeTitleControls_CheckTitleInfo(FALSE);
773
774   /* sort title screens according to sort_priority and title number */
775   qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
776         compareTitleControlInfo);
777 }
778
779 static boolean visibleMenuPos(struct MenuPosInfo *pos)
780 {
781   return (pos != NULL && pos->x != -1 && pos->y != -1);
782 }
783
784 static boolean visibleTextPos(struct TextPosInfo *pos)
785 {
786   return (pos != NULL && pos->x != -1 && pos->y != -1);
787 }
788
789 static void InitializeMainControls()
790 {
791   boolean local_team_mode = (!options.network && setup.team_mode);
792   int i;
793
794   /* set main control text values to dynamically determined values */
795   sprintf(main_text_name,         "%s",   local_team_mode ? "Team:" : "Name:");
796
797   strcpy(main_text_first_level,  int2str(leveldir_current->first_level,
798                                          menu.main.text.first_level.size));
799   strcpy(main_text_last_level,   int2str(leveldir_current->last_level,
800                                          menu.main.text.last_level.size));
801   strcpy(main_text_level_number, int2str(level_nr,
802                                          menu.main.text.level_number.size));
803
804   main_text_level_year          = leveldir_current->year;
805   main_text_level_imported_from = leveldir_current->imported_from;
806   main_text_level_imported_by   = leveldir_current->imported_by;
807   main_text_level_tested_by     = leveldir_current->tested_by;
808
809   /* set main control screen positions to dynamically determined values */
810   for (i = 0; main_controls[i].nr != -1; i++)
811   {
812     struct MainControlInfo *mci = &main_controls[i];
813     int nr                         = mci->nr;
814     struct MenuPosInfo *pos_button = mci->pos_button;
815     struct TextPosInfo *pos_text   = mci->pos_text;
816     struct TextPosInfo *pos_input  = mci->pos_input;
817     char *text                     = (mci->text  ? *mci->text  : NULL);
818     char *input                    = (mci->input ? *mci->input : NULL);
819     int button_graphic             = mci->button_graphic;
820 #if 1
821     int font_text                  = (pos_text  ? pos_text->font  : -1);
822     int font_input                 = (pos_input ? pos_input->font : -1);
823 #else
824     int font_text                  = mci->font_text;
825     int font_input                 = mci->font_input;
826 #endif
827
828     int font_text_width   = (font_text  != -1 ? getFontWidth(font_text)   : 0);
829     int font_text_height  = (font_text  != -1 ? getFontHeight(font_text)  : 0);
830     int font_input_width  = (font_input != -1 ? getFontWidth(font_input)  : 0);
831     int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
832     int text_chars  = (text  != NULL ? strlen(text)  : 0);
833     int input_chars = (input != NULL ? strlen(input) : 0);
834
835     int button_width =
836       (button_graphic != -1 ? graphic_info[button_graphic].width  : 0);
837     int button_height =
838       (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
839     int text_width   = font_text_width * text_chars;
840     int text_height  = font_text_height;
841     int input_width  = font_input_width * input_chars;
842     int input_height = font_input_height;
843
844     if (nr == MAIN_CONTROL_NAME)
845     {
846 #if 0
847       if (menu.main.input.name.x == -1)
848         menu.main.input.name.x = menu.main.text.name.x + text_width;
849       if (menu.main.input.name.y == -1)
850         menu.main.input.name.y = menu.main.text.name.y;
851 #endif
852
853 #if 1
854       menu.main.input.name.width  = input_width;
855       menu.main.input.name.height = input_height;
856 #else
857       menu.main.input.name.width  = font_input_width * MAX_PLAYER_NAME_LEN;
858       menu.main.input.name.height = font_input_height;
859 #endif
860     }
861
862     if (pos_button != NULL)             /* (x/y may be -1/-1 here) */
863     {
864       if (pos_button->width == 0)
865         pos_button->width = button_width;
866       if (pos_button->height == 0)
867         pos_button->height = button_height;
868     }
869
870     if (pos_text != NULL)               /* (x/y may be -1/-1 here) */
871     {
872       /* calculate width for non-clickable text -- needed for text alignment */
873       boolean calculate_text_width = (pos_button == NULL && text != NULL);
874
875       if (visibleMenuPos(pos_button))
876       {
877         if (pos_text->x == -1)
878           pos_text->x = pos_button->x + pos_button->width;
879         if (pos_text->y == -1)
880           pos_text->y = pos_button->y;
881       }
882
883       if (pos_text->width == -1 || calculate_text_width)
884         pos_text->width = text_width;
885       if (pos_text->height == -1)
886         pos_text->height = text_height;
887     }
888
889     if (pos_input != NULL)              /* (x/y may be -1/-1 here) */
890     {
891       if (visibleTextPos(pos_text))
892       {
893         if (pos_input->x == -1)
894           pos_input->x = pos_text->x + pos_text->width;
895         if (pos_input->y == -1)
896           pos_input->y = pos_text->y;
897       }
898
899       if (pos_input->width == -1)
900         pos_input->width = input_width;
901       if (pos_input->height == -1)
902         pos_input->height = input_height;
903     }
904   }
905 }
906
907 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
908                                        boolean active_input)
909 {
910   int i;
911
912   for (i = 0; main_controls[i].nr != -1; i++)
913   {
914     struct MainControlInfo *mci = &main_controls[i];
915
916     if (mci->nr == nr || nr == -1)
917     {
918       struct MenuPosInfo *pos_button = mci->pos_button;
919       struct TextPosInfo *pos_text   = mci->pos_text;
920       struct TextPosInfo *pos_input  = mci->pos_input;
921       char *text                     = (mci->text  ? *mci->text  : NULL);
922       char *input                    = (mci->input ? *mci->input : NULL);
923       int button_graphic             = mci->button_graphic;
924 #if 1
925       int font_text                  = (pos_text  ? pos_text->font  : -1);
926       int font_input                 = (pos_input ? pos_input->font : -1);
927 #else
928       int font_text                  = mci->font_text;
929       int font_input                 = mci->font_input;
930 #endif
931
932       if (active_text)
933       {
934         button_graphic = BUTTON_ACTIVE(button_graphic);
935         font_text = FONT_ACTIVE(font_text);
936       }
937
938       if (active_input)
939       {
940         font_input = FONT_ACTIVE(font_input);
941       }
942
943       if (visibleMenuPos(pos_button))
944       {
945         struct MenuPosInfo *pos = pos_button;
946         int x = mSX + pos->x;
947         int y = mSY + pos->y;
948
949         DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
950         DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
951       }
952
953       if (visibleTextPos(pos_text) && text != NULL)
954       {
955         struct TextPosInfo *pos = pos_text;
956         int x = mSX + ALIGNED_TEXT_XPOS(pos);
957         int y = mSY + ALIGNED_TEXT_YPOS(pos);
958
959 #if 1
960         /* (check why/if this is needed) */
961         DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
962 #endif
963         DrawText(x, y, text, font_text);
964       }
965
966       if (visibleTextPos(pos_input) && input != NULL)
967       {
968         struct TextPosInfo *pos = pos_input;
969         int x = mSX + ALIGNED_TEXT_XPOS(pos);
970         int y = mSY + ALIGNED_TEXT_YPOS(pos);
971
972 #if 1
973         /* (check why/if this is needed) */
974         DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
975 #endif
976         DrawText(x, y, input, font_input);
977       }
978     }
979   }
980 }
981
982 static void DrawCursorAndText_Main(int nr, boolean active_text)
983 {
984   DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
985 }
986
987 #if 0
988 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
989 {
990   DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
991 }
992 #endif
993
994 static struct MainControlInfo *getMainControlInfo(int nr)
995 {
996   int i;
997
998   for (i = 0; main_controls[i].nr != -1; i++)
999     if (main_controls[i].nr == nr)
1000       return &main_controls[i];
1001
1002   return NULL;
1003 }
1004
1005 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1006 {
1007   if (rect == NULL)
1008     return FALSE;
1009
1010   int rect_x = ALIGNED_TEXT_XPOS(rect);
1011   int rect_y = ALIGNED_TEXT_YPOS(rect);
1012
1013   return (x >= rect_x && x < rect_x + rect->width &&
1014           y >= rect_y && y < rect_y + rect->height);
1015 }
1016
1017 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1018 {
1019   if (rect == NULL)
1020     return FALSE;
1021
1022   int rect_x = ALIGNED_TEXT_XPOS(rect);
1023   int rect_y = ALIGNED_TEXT_YPOS(rect);
1024
1025   return (x >= rect_x && x < rect_x + rect->width &&
1026           y >= rect_y && y < rect_y + rect->height);
1027 }
1028
1029 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1030 {
1031   static int cursor_array[SCR_FIELDY];
1032   int x = mSX + TILEX * xpos;
1033   int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1034
1035   if (xpos == 0)
1036   {
1037     if (graphic != -1)
1038       cursor_array[ypos] = graphic;
1039     else
1040       graphic = cursor_array[ypos];
1041   }
1042
1043   if (active)
1044     graphic = BUTTON_ACTIVE(graphic);
1045
1046   DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1047   DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1048 }
1049
1050 static void initCursor(int ypos, int graphic)
1051 {
1052   drawCursorExt(0, ypos, FALSE, graphic);
1053 }
1054
1055 static void drawCursor(int ypos, boolean active)
1056 {
1057   drawCursorExt(0, ypos, active, -1);
1058 }
1059
1060 static void drawCursorXY(int xpos, int ypos, int graphic)
1061 {
1062   drawCursorExt(xpos, ypos, FALSE, graphic);
1063 }
1064
1065 static void drawChooseTreeCursor(int ypos, boolean active)
1066 {
1067   int last_game_status = game_status;   /* save current game status */
1068
1069 #if 0
1070   /* force LEVELS draw offset on artwork setup screen */
1071   game_status = GAME_MODE_LEVELS;
1072 #endif
1073
1074   drawCursorExt(0, ypos, active, -1);
1075
1076   game_status = last_game_status;       /* restore current game status */
1077 }
1078
1079 void DrawHeadline()
1080 {
1081   DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1082   DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1083 }
1084
1085 #if 0
1086 static int getPrevlevelButtonPos()
1087 {
1088   return 10;
1089 }
1090
1091 static int getCurrentLevelTextPos()
1092 {
1093   return (getPrevlevelButtonPos() + 1);
1094 }
1095
1096 static int getNextLevelButtonPos()
1097 {
1098   return getPrevlevelButtonPos() + 3 + 1;
1099 }
1100
1101 static int getLevelRangeTextPos()
1102 {
1103   return getNextLevelButtonPos() + 1;
1104 }
1105 #endif
1106
1107 int effectiveGameStatus()
1108 {
1109   if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1110     return GAME_MODE_TITLE;
1111
1112   return game_status;
1113 }
1114
1115 void DrawTitleScreenImage(int nr, boolean initial)
1116 {
1117   int graphic = getTitleScreenGraphic(nr, initial);
1118   Bitmap *bitmap = graphic_info[graphic].bitmap;
1119 #if 1
1120   int width  = graphic_info[graphic].width;
1121   int height = graphic_info[graphic].height;
1122   int src_x = graphic_info[graphic].src_x;
1123   int src_y = graphic_info[graphic].src_y;
1124 #else
1125   int width  = graphic_info[graphic].src_image_width;
1126   int height = graphic_info[graphic].src_image_height;
1127   int src_x = 0, src_y = 0;
1128 #endif
1129   int dst_x, dst_y;
1130
1131   if (bitmap == NULL)
1132     return;
1133
1134   if (width > WIN_XSIZE)
1135   {
1136     /* image width too large for window => center image horizontally */
1137     src_x = (width - WIN_XSIZE) / 2;
1138     width = WIN_XSIZE;
1139   }
1140
1141   if (height > WIN_YSIZE)
1142   {
1143     /* image height too large for window => center image vertically */
1144     src_y = (height - WIN_YSIZE) / 2;
1145     height = WIN_YSIZE;
1146   }
1147
1148   /* always display title screens centered */
1149   dst_x = (WIN_XSIZE - width) / 2;
1150   dst_y = (WIN_YSIZE - height) / 2;
1151
1152   SetDrawBackgroundMask(REDRAW_ALL);
1153   SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1154
1155   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1156
1157   if (DrawingOnBackground(dst_x, dst_y))
1158     BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1159   else
1160     BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1161
1162   redraw_mask = REDRAW_ALL;
1163
1164   /* reset fading control values to default config settings */
1165 #if 1
1166
1167 #if 0
1168   title = getTitleFading(nr, initial, TRUE);
1169 #endif
1170
1171 #else
1172
1173   title.fade_delay_final = title.fade_delay;
1174   title.post_delay_final = title.post_delay;
1175   title.auto_delay_final = title.auto_delay;
1176
1177   /* override default settings with image config settings, if defined */
1178   if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
1179     title.anim_mode = graphic_info[graphic].anim_mode;
1180   if (graphic_info[graphic].fade_delay > -1)
1181     title.fade_delay = graphic_info[graphic].fade_delay;
1182   if (graphic_info[graphic].post_delay > -1)
1183     title.post_delay = graphic_info[graphic].post_delay;
1184   if (graphic_info[graphic].auto_delay > -1)
1185     title.auto_delay = graphic_info[graphic].auto_delay;
1186 #endif
1187 }
1188
1189 void DrawTitleScreenMessage(int nr, boolean initial)
1190 {
1191   char *filename = getLevelSetTitleMessageFilename(nr, initial);
1192   struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1193 #if 0
1194   int font_nr = FONT_TEXT_1;
1195   int font_width;
1196   int font_height;
1197   int pad_x = 16   + 4;
1198   int pad_y = 32   + 14;
1199   int sx = pad_x;
1200   int sy = pad_y;
1201   int max_chars_per_line;
1202   int max_lines_per_screen;
1203 #endif
1204   int last_game_status = game_status;   /* save current game status */
1205
1206   if (filename == NULL)
1207     return;
1208
1209   /* force TITLE font on title message screen */
1210   game_status = getTitleMessageGameMode(initial);
1211
1212   /* if chars set to "-1", automatically determine by text and font width */
1213   if (tmi->chars == -1)
1214     tmi->chars = tmi->width / getFontWidth(tmi->font);
1215   else
1216     tmi->width = tmi->chars * getFontWidth(tmi->font);
1217
1218   /* if lines set to "-1", automatically determine by text and font height */
1219   if (tmi->lines == -1)
1220     tmi->lines = tmi->height / getFontHeight(tmi->font);
1221   else
1222     tmi->height = tmi->lines * getFontHeight(tmi->font);
1223
1224   SetDrawBackgroundMask(REDRAW_ALL);
1225   SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1226
1227   ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1228
1229 #if 0
1230   font_width = getFontWidth(font_nr);
1231   font_height = getFontHeight(font_nr);
1232   max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1233   max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1234 #endif
1235
1236 #if 1
1237   DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1238                filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1239                tmi->autowrap, tmi->centered, tmi->parse_comments);
1240 #else
1241   DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1242                max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1243                tmi->parse_comments);
1244 #endif
1245
1246   game_status = last_game_status;       /* restore current game status */
1247 }
1248
1249 void DrawTitleScreen()
1250 {
1251   KeyboardAutoRepeatOff();
1252
1253 #if 0
1254   SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1255 #endif
1256
1257   HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1258
1259   StopAnimation();
1260 }
1261
1262 boolean CheckTitleScreen(boolean levelset_has_changed)
1263 {
1264   static boolean show_title_initial = TRUE;
1265   boolean show_titlescreen = FALSE;
1266
1267   /* needed to be able to skip title screen, if no image or message defined */
1268   InitializeTitleControls(show_title_initial);
1269
1270   if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1271     show_titlescreen = TRUE;
1272
1273   /* show initial title images and messages only once at program start */
1274   show_title_initial = FALSE;
1275
1276   return (show_titlescreen && num_title_screens > 0);
1277 }
1278
1279 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1280 {
1281   static LevelDirTree *leveldir_last_valid = NULL;
1282   boolean levelset_has_changed = FALSE;
1283
1284   FadeSetLeaveScreen();
1285
1286   /* (does not work well when changing to editor, which fades out itself) */
1287 #if 0
1288   FadeOut(redraw_mask);
1289 #endif
1290
1291   UnmapAllGadgets();
1292   FadeSoundsAndMusic();
1293
1294   KeyboardAutoRepeatOn();
1295   ActivateJoystick();
1296
1297   SetDrawDeactivationMask(REDRAW_NONE);
1298   SetDrawBackgroundMask(REDRAW_FIELD);
1299
1300   audio.sound_deactivated = FALSE;
1301
1302   GetPlayerConfig();
1303
1304   /* needed if last screen was the playing screen, invoked from level editor */
1305   if (level_editor_test_game)
1306   {
1307     game_status = GAME_MODE_EDITOR;
1308     DrawLevelEd();
1309
1310     return;
1311   }
1312
1313 #if 0
1314   FadeOut(redraw_mask);
1315
1316   /* needed if last screen was the editor screen */
1317   UndrawSpecialEditorDoor();
1318 #endif
1319
1320   /* needed if last screen was the setup screen and fullscreen state changed */
1321   ToggleFullscreenIfNeeded();
1322
1323   /* leveldir_current may be invalid (level group, parent link) */
1324   if (!validLevelSeries(leveldir_current))
1325     leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1326
1327   if (leveldir_current != leveldir_last_valid)
1328     levelset_has_changed = TRUE;
1329
1330   /* store valid level series information */
1331   leveldir_last_valid = leveldir_current;
1332
1333   /* needed if last screen (level choice) changed graphics, sounds or music */
1334   ReloadCustomArtwork(0);
1335
1336 #if 1
1337   printf("::: FadeOut @ DrawMainMenuExt ...\n");
1338   FadeOut(redraw_mask);
1339   printf("::: FadeOut @ DrawMainMenuExt done\n");
1340
1341   /* needed if last screen was the editor screen */
1342   UndrawSpecialEditorDoor();
1343 #endif
1344
1345 #if defined(TARGET_SDL)
1346   SetDrawtoField(DRAW_BACKBUFFER);
1347 #endif
1348
1349   if (CheckTitleScreen(levelset_has_changed))
1350   {
1351     game_status = GAME_MODE_TITLE;
1352
1353     DrawTitleScreen();
1354
1355     return;
1356   }
1357
1358   /* level_nr may have been set to value over handicap with level editor */
1359   if (setup.handicap && level_nr > leveldir_current->handicap_level)
1360     level_nr = leveldir_current->handicap_level;
1361
1362   LoadLevel(level_nr);
1363
1364   SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1365
1366 #if 0
1367   FadeOut(redraw_mask);
1368 #endif
1369
1370 #if 1
1371   if (redraw_mask == REDRAW_ALL)
1372   {
1373     // int door_state = GetDoorState();
1374
1375     RedrawBackground();
1376
1377     // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1378   }
1379 #endif
1380
1381   ClearWindow();
1382
1383   InitializeMainControls();
1384
1385   DrawCursorAndText_Main(-1, FALSE);
1386   DrawPreviewLevel(TRUE);
1387
1388   HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1389
1390   TapeStop();
1391   if (TAPE_IS_EMPTY(tape))
1392     LoadTape(level_nr);
1393   DrawCompleteVideoDisplay();
1394
1395   PlayMenuSound();
1396   PlayMenuMusic();
1397
1398   /* create gadgets for main menu screen */
1399   FreeScreenGadgets();
1400   CreateScreenGadgets();
1401
1402   /* map gadgets for main menu screen */
1403   MapTapeButtons();
1404   MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1405
1406 #if 1
1407   DrawMaskedBorder(REDRAW_ALL);
1408 #endif
1409
1410 #if 1
1411   if (redraw_mask == REDRAW_ALL)
1412   {
1413     int door_state = GetDoorState();
1414
1415     // RedrawBackground();
1416
1417     OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1418   }
1419 #endif
1420
1421   FadeIn(redraw_mask);
1422
1423   FadeSetEnterMenu();
1424
1425   SetMouseCursor(CURSOR_DEFAULT);
1426
1427   InitAnimation();
1428
1429   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1430 }
1431
1432 void DrawAndFadeInMainMenu(int redraw_mask)
1433 {
1434   DrawMainMenuExt(redraw_mask, TRUE);
1435 }
1436
1437 void DrawMainMenu()
1438 {
1439   DrawMainMenuExt(REDRAW_ALL, FALSE);
1440 }
1441
1442 #if 0
1443 static void gotoTopLevelDir()
1444 {
1445   /* move upwards to top level directory */
1446   while (leveldir_current->node_parent)
1447   {
1448     /* write a "path" into level tree for easy navigation to last level */
1449     if (leveldir_current->node_parent->node_group->cl_first == -1)
1450     {
1451       int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1452       int leveldir_pos = posTreeInfo(leveldir_current);
1453       int num_page_entries;
1454       int cl_first, cl_cursor;
1455
1456       if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1457         num_page_entries = num_leveldirs;
1458       else
1459         num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1460
1461       cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1462       cl_cursor = leveldir_pos - cl_first;
1463
1464       leveldir_current->node_parent->node_group->cl_first = cl_first;
1465       leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1466     }
1467
1468     leveldir_current = leveldir_current->node_parent;
1469   }
1470 }
1471 #endif
1472
1473 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1474 {
1475   static unsigned long title_delay = 0;
1476   static int title_screen_nr = 0;
1477   static int last_sound = -1, last_music = -1;
1478   boolean return_to_main_menu = FALSE;
1479   boolean use_fading_main_menu = TRUE;
1480 #if 0
1481 #if 1
1482   boolean use_cross_fading = FALSE;
1483 #else
1484   boolean use_cross_fading = !show_title_initial;               /* default */
1485 #endif
1486 #endif
1487   struct TitleControlInfo *tci;
1488   struct TitleFadingInfo fading_default;
1489   struct TitleFadingInfo fading_last = fading;
1490   struct TitleFadingInfo fading_next;
1491   int sound, music;
1492
1493   if (button == MB_MENU_INITIALIZE)
1494   {
1495 #if 0
1496     boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1497 #endif
1498
1499 #if 0
1500     int last_game_status = game_status; /* save current game status */
1501 #endif
1502
1503     title_delay = 0;
1504     title_screen_nr = 0;
1505     tci = &title_controls[title_screen_nr];
1506
1507     last_sound = SND_UNDEFINED;
1508     last_music = MUS_UNDEFINED;
1509
1510 #if 0
1511     /* determine number of title screens to display (images and messages) */
1512     InitializeTitleControls();
1513 #endif
1514
1515     if (game_status == GAME_MODE_INFO)
1516     {
1517       if (num_title_screens == 0)
1518       {
1519         DrawInfoScreen_NotAvailable("Title screen information:",
1520                                     "No title screen for this level set.");
1521
1522 #if 0
1523         /* use default settings for fading, but always disable auto delay */
1524         fading = title_default;
1525         fading.auto_delay = -1;
1526 #endif
1527
1528         return;
1529       }
1530
1531       FadeSoundsAndMusic();
1532
1533 #if 1
1534       FadeOut(REDRAW_ALL);
1535 #endif
1536     }
1537
1538     if (tci->is_image)
1539       DrawTitleScreenImage(tci->local_nr, tci->initial);
1540     else
1541       DrawTitleScreenMessage(tci->local_nr, tci->initial);
1542
1543     fading_default = (tci->initial ? title_initial_default : title_default);
1544
1545     fading = fading_next = getTitleFading(tci);
1546
1547 #if 1
1548 #if 1
1549     if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1550         fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1551     {
1552       fading.fade_mode = FADE_MODE_FADE;
1553       fading.fade_delay = fading_default.fade_delay;
1554     }
1555 #else
1556     if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1557         fading_next.fade_mode == FADE_MODE_CROSSFADE)
1558       fading.fade_mode = FADE_MODE_FADE;
1559 #endif
1560 #endif
1561
1562 #if 1
1563     sound = getTitleSound(tci);
1564     music = getTitleMusic(tci);
1565
1566     if (sound != last_sound)
1567       PlayMenuSoundExt(sound);
1568     if (music != last_music)
1569       PlayMenuMusicExt(music);
1570
1571     last_sound = sound;
1572     last_music = music;
1573 #endif
1574
1575     SetMouseCursor(CURSOR_NONE);
1576
1577     // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
1578
1579 #if 1
1580     FadeIn(REDRAW_ALL);
1581 #endif
1582
1583     fading = fading_next;
1584
1585     DelayReached(&title_delay, 0);      /* reset delay counter */
1586
1587     return;
1588   }
1589
1590 #if 1
1591   if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1592     button = MB_MENU_CHOICE;
1593 #else
1594   if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1595     button = MB_MENU_CHOICE;
1596 #endif
1597
1598   if (button == MB_MENU_LEAVE)
1599   {
1600     return_to_main_menu = TRUE;
1601     use_fading_main_menu = FALSE;
1602   }
1603   else if (button == MB_MENU_CHOICE)
1604   {
1605 #if 0
1606     boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1607 #endif
1608
1609     if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1610     {
1611 #if 0
1612       FadeOut(REDRAW_FIELD);
1613 #endif
1614
1615       FadeSetEnterScreen();
1616
1617       info_mode = INFO_MODE_MAIN;
1618       DrawAndFadeInInfoScreen(REDRAW_FIELD);
1619
1620       return;
1621     }
1622
1623     title_screen_nr++;
1624     tci = &title_controls[title_screen_nr];
1625
1626     if (title_screen_nr < num_title_screens)
1627     {
1628 #if 1
1629 #if 0
1630       boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1631 #endif
1632 #else
1633       int anim_mode;
1634
1635       if (tci->is_image)
1636         anim_mode =
1637           graphic_info[getTitleScreenGraphic(tci->local_nr,
1638                                              tci->initial)].anim_mode;
1639       else
1640         anim_mode = ANIM_FADE;  /* ??? */
1641
1642       use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1643                           anim_mode == ANIM_CROSSFADE ? TRUE :
1644                           use_cross_fading);
1645 #endif
1646
1647       sound = getTitleSound(tci);
1648       music = getTitleMusic(tci);
1649
1650       if (sound == SND_UNDEFINED || sound != last_sound)
1651         FadeSounds();
1652       if (music == MUS_UNDEFINED || music != last_music)
1653         FadeMusic();
1654
1655 #if 1
1656       FadeOut(REDRAW_ALL);
1657 #endif
1658
1659       if (tci->is_image)
1660         DrawTitleScreenImage(tci->local_nr, tci->initial);
1661       else
1662         DrawTitleScreenMessage(tci->local_nr, tci->initial);
1663
1664       fading_next = getTitleFading(tci);
1665
1666 #if 1
1667       sound = getTitleSound(tci);
1668       music = getTitleMusic(tci);
1669
1670       if (sound != last_sound)
1671         PlayMenuSoundExt(sound);
1672       if (music != last_music)
1673         PlayMenuMusicExt(music);
1674
1675       last_sound = sound;
1676       last_music = music;
1677 #endif
1678
1679 #if 0
1680       printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1681 #endif
1682
1683 #if 1
1684       /* last screen already faded out, next screen has no animation */
1685       if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1686           fading_next.fade_mode == FADE_MODE_NONE)
1687         fading = fading_next;
1688 #else
1689       /* last screen already faded out, next screen has no animation */
1690       if (fading.fade_mode      != FADE_MODE_CROSSFADE &&
1691           fading_next.fade_mode == FADE_MODE_NONE)
1692         fading = fading_next;
1693 #endif
1694
1695 #if 1
1696       FadeIn(REDRAW_ALL);
1697 #endif
1698
1699       fading = fading_next;
1700
1701       DelayReached(&title_delay, 0);    /* reset delay counter */
1702     }
1703     else
1704     {
1705       FadeSoundsAndMusic();
1706
1707 #if 0
1708 #if 1
1709       {
1710 #if 0
1711         boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1712 #endif
1713
1714 #if 1
1715         FadeOut(REDRAW_ALL);
1716 #endif
1717       }
1718 #else
1719       FadeOut(REDRAW_ALL);
1720 #endif
1721 #endif
1722
1723       return_to_main_menu = TRUE;
1724     }
1725   }
1726
1727   if (return_to_main_menu)
1728   {
1729 #if 0
1730     RedrawBackground();
1731 #endif
1732
1733     SetMouseCursor(CURSOR_DEFAULT);
1734
1735     if (game_status == GAME_MODE_INFO)
1736     {
1737 #if 0
1738       OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1739 #endif
1740
1741       info_mode = INFO_MODE_MAIN;
1742       DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1743     }
1744     else        /* default: return to main menu */
1745     {
1746 #if 0
1747       OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1748 #endif
1749
1750       game_status = GAME_MODE_MAIN;
1751       DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1752     }
1753   }
1754 }
1755
1756 void HandleMainMenu_SelectLevel(int step, int direction)
1757 {
1758   int old_level_nr = level_nr;
1759   int new_level_nr;
1760
1761   new_level_nr = old_level_nr + step * direction;
1762   if (new_level_nr < leveldir_current->first_level)
1763     new_level_nr = leveldir_current->first_level;
1764   if (new_level_nr > leveldir_current->last_level)
1765     new_level_nr = leveldir_current->last_level;
1766
1767   if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1768   {
1769     /* skipping levels is only allowed when trying to skip single level */
1770     if (setup.skip_levels && step == 1 &&
1771         Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1772     {
1773       leveldir_current->handicap_level++;
1774       SaveLevelSetup_SeriesInfo();
1775     }
1776
1777     new_level_nr = leveldir_current->handicap_level;
1778   }
1779
1780   if (new_level_nr != old_level_nr)
1781   {
1782     struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1783
1784     PlaySound(SND_MENU_ITEM_SELECTING);
1785
1786     level_nr = new_level_nr;
1787
1788 #if 1
1789     DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1790              int2str(level_nr, menu.main.text.level_number.size),
1791              mci->pos_text->font);
1792 #else
1793     DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1794 #endif
1795
1796     LoadLevel(level_nr);
1797     DrawPreviewLevel(TRUE);
1798
1799     TapeErase();
1800     LoadTape(level_nr);
1801     DrawCompleteVideoDisplay();
1802
1803     /* needed because DrawPreviewLevel() takes some time */
1804     BackToFront();
1805     SyncDisplay();
1806   }
1807 }
1808
1809 #if 1
1810
1811 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1812 {
1813   static int choice = MAIN_CONTROL_GAME;
1814   int pos = choice;
1815   int i;
1816
1817   if (button == MB_MENU_INITIALIZE)
1818   {
1819     DrawCursorAndText_Main(choice, TRUE);
1820
1821     return;
1822   }
1823
1824   if (mx || my)         /* mouse input */
1825   {
1826     pos = -1;
1827
1828     for (i = 0; main_controls[i].nr != -1; i++)
1829     {
1830       if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1831           insideTextPosRect(main_controls[i].pos_text,   mx - mSX, my - mSY) ||
1832           insideTextPosRect(main_controls[i].pos_input,  mx - mSX, my - mSY))
1833       {
1834         pos = main_controls[i].nr;
1835
1836         break;
1837       }
1838     }
1839   }
1840   else if (dx || dy)    /* keyboard input */
1841   {
1842     if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1843                    choice == MAIN_CONTROL_SETUP))
1844       button = MB_MENU_CHOICE;
1845     else if (dy)
1846       pos = choice + dy;
1847   }
1848
1849   if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1850   {
1851     HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1852   }
1853   else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1854   {
1855     if (button)
1856     {
1857       if (pos != choice)
1858       {
1859         PlaySound(SND_MENU_ITEM_ACTIVATING);
1860
1861         DrawCursorAndText_Main(choice, FALSE);
1862         DrawCursorAndText_Main(pos, TRUE);
1863
1864         choice = pos;
1865       }
1866     }
1867     else
1868     {
1869       PlaySound(SND_MENU_ITEM_SELECTING);
1870
1871       if (pos == MAIN_CONTROL_NAME)
1872       {
1873         game_status = GAME_MODE_PSEUDO_TYPENAME;
1874
1875         HandleTypeName(strlen(setup.player_name), 0);
1876       }
1877       else if (pos == MAIN_CONTROL_LEVELS)
1878       {
1879         if (leveldir_first)
1880         {
1881           game_status = GAME_MODE_LEVELS;
1882
1883           SaveLevelSetup_LastSeries();
1884           SaveLevelSetup_SeriesInfo();
1885
1886 #if 0
1887           gotoTopLevelDir();
1888 #endif
1889
1890           DrawChooseLevel();
1891         }
1892       }
1893       else if (pos == MAIN_CONTROL_SCORES)
1894       {
1895         game_status = GAME_MODE_SCORES;
1896
1897         DrawHallOfFame(-1);
1898       }
1899       else if (pos == MAIN_CONTROL_EDITOR)
1900       {
1901         if (leveldir_current->readonly &&
1902             !strEqual(setup.player_name, "Artsoft"))
1903           Request("This level is read only !", REQ_CONFIRM);
1904
1905         game_status = GAME_MODE_EDITOR;
1906
1907         FadeSetEnterScreen();
1908
1909         DrawLevelEd();
1910       }
1911       else if (pos == MAIN_CONTROL_INFO)
1912       {
1913         game_status = GAME_MODE_INFO;
1914         info_mode = INFO_MODE_MAIN;
1915
1916 #if 0
1917         fading = menu.navigation;
1918 #endif
1919
1920         DrawInfoScreen();
1921       }
1922       else if (pos == MAIN_CONTROL_GAME)
1923       {
1924         StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1925       }
1926       else if (pos == MAIN_CONTROL_SETUP)
1927       {
1928         game_status = GAME_MODE_SETUP;
1929         setup_mode = SETUP_MODE_MAIN;
1930
1931         DrawSetupScreen();
1932       }
1933       else if (pos == MAIN_CONTROL_QUIT)
1934       {
1935         SaveLevelSetup_LastSeries();
1936         SaveLevelSetup_SeriesInfo();
1937
1938         if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1939           game_status = GAME_MODE_QUIT;
1940       }
1941     }
1942   }
1943
1944   if (game_status == GAME_MODE_MAIN)
1945   {
1946     DrawPreviewLevel(FALSE);
1947     DoAnimation();
1948   }
1949 }
1950
1951 #else
1952
1953 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1954 {
1955   static int choice = 5;
1956   int x = 0;
1957   int y = choice;
1958
1959   if (button == MB_MENU_INITIALIZE)
1960   {
1961     drawCursor(choice, TRUE);
1962
1963     return;
1964   }
1965
1966   if (mx || my)         /* mouse input */
1967   {
1968     x = (mx - mSX) / 32;
1969     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1970   }
1971   else if (dx || dy)    /* keyboard input */
1972   {
1973     if (dx && choice == 1)
1974       x = (dx < 0 ? 10 : 14);
1975     else if (dx > 0)
1976     {
1977       if (choice == 4 || choice == 6)
1978         button = MB_MENU_CHOICE;
1979     }
1980     else if (dy)
1981       y = choice + dy;
1982   }
1983
1984   if (y == 1 && dx != 0 && button)
1985   {
1986     HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1987   }
1988   else if (IN_VIS_FIELD(x, y) &&
1989            y >= 0 && y <= 7 && (y != 1 || x < 10))
1990   {
1991     if (button)
1992     {
1993       if (y != choice)
1994       {
1995         drawCursor(choice, FALSE);
1996         drawCursor(y, TRUE);
1997
1998         choice = y;
1999       }
2000     }
2001     else
2002     {
2003       if (y == 0)
2004       {
2005         game_status = GAME_MODE_PSEUDO_TYPENAME;
2006         HandleTypeName(strlen(setup.player_name), 0);
2007       }
2008       else if (y == 1)
2009       {
2010         if (leveldir_first)
2011         {
2012           game_status = GAME_MODE_LEVELS;
2013
2014           SaveLevelSetup_LastSeries();
2015           SaveLevelSetup_SeriesInfo();
2016
2017 #if 0
2018           gotoTopLevelDir();
2019 #endif
2020
2021           DrawChooseLevel();
2022         }
2023       }
2024       else if (y == 2)
2025       {
2026         game_status = GAME_MODE_SCORES;
2027         DrawHallOfFame(-1);
2028       }
2029       else if (y == 3)
2030       {
2031         if (leveldir_current->readonly &&
2032             !strEqual(setup.player_name, "Artsoft"))
2033           Request("This level is read only !", REQ_CONFIRM);
2034         game_status = GAME_MODE_EDITOR;
2035         DrawLevelEd();
2036       }
2037       else if (y == 4)
2038       {
2039         game_status = GAME_MODE_INFO;
2040         info_mode = INFO_MODE_MAIN;
2041         DrawInfoScreen();
2042       }
2043       else if (y == 5)
2044       {
2045         StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2046       }
2047       else if (y == 6)
2048       {
2049         game_status = GAME_MODE_SETUP;
2050         setup_mode = SETUP_MODE_MAIN;
2051
2052         DrawSetupScreen();
2053       }
2054       else if (y == 7)
2055       {
2056         SaveLevelSetup_LastSeries();
2057         SaveLevelSetup_SeriesInfo();
2058
2059         if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2060           game_status = GAME_MODE_QUIT;
2061       }
2062     }
2063   }
2064
2065   if (game_status == GAME_MODE_MAIN)
2066   {
2067     DrawPreviewLevel(FALSE);
2068     DoAnimation();
2069   }
2070 }
2071
2072 #endif
2073
2074
2075 /* ========================================================================= */
2076 /* info screen functions                                                     */
2077 /* ========================================================================= */
2078
2079 static struct TokenInfo *info_info;
2080 static int num_info_info;
2081
2082 static void execInfoTitleScreen()
2083 {
2084 #if 0
2085   FadeSetEnterScreen();
2086 #endif
2087
2088   info_mode = INFO_MODE_TITLE;
2089   DrawInfoScreen();
2090 }
2091
2092 static void execInfoElements()
2093 {
2094 #if 0
2095   FadeSetEnterScreen();
2096 #endif
2097
2098   info_mode = INFO_MODE_ELEMENTS;
2099   DrawInfoScreen();
2100 }
2101
2102 static void execInfoMusic()
2103 {
2104 #if 0
2105   FadeSetEnterScreen();
2106 #endif
2107
2108   info_mode = INFO_MODE_MUSIC;
2109   DrawInfoScreen();
2110 }
2111
2112 static void execInfoCredits()
2113 {
2114 #if 0
2115   FadeSetEnterScreen();
2116 #endif
2117
2118   info_mode = INFO_MODE_CREDITS;
2119   DrawInfoScreen();
2120 }
2121
2122 static void execInfoProgram()
2123 {
2124 #if 0
2125   FadeSetEnterScreen();
2126 #endif
2127
2128   info_mode = INFO_MODE_PROGRAM;
2129   DrawInfoScreen();
2130 }
2131
2132 static void execInfoVersion()
2133 {
2134 #if 0
2135   FadeSetEnterScreen();
2136 #endif
2137
2138   info_mode = INFO_MODE_VERSION;
2139   DrawInfoScreen();
2140 }
2141
2142 static void execInfoLevelSet()
2143 {
2144 #if 0
2145   FadeSetEnterScreen();
2146 #endif
2147
2148   info_mode = INFO_MODE_LEVELSET;
2149   DrawInfoScreen();
2150 }
2151
2152 static void execExitInfo()
2153 {
2154 #if 0
2155   FadeSetLeaveMenu();
2156 #endif
2157
2158   game_status = GAME_MODE_MAIN;
2159 #if 1
2160   DrawMainMenuExt(REDRAW_FIELD, FALSE);
2161 #else
2162   DrawMainMenu();
2163 #endif
2164 }
2165
2166 static struct TokenInfo info_info_main[] =
2167 {
2168   { TYPE_ENTER_SCREEN,  execInfoTitleScreen,    "Title Screen"          },
2169   { TYPE_ENTER_SCREEN,  execInfoElements,       "Elements Info"         },
2170   { TYPE_ENTER_SCREEN,  execInfoMusic,          "Music Info"            },
2171   { TYPE_ENTER_SCREEN,  execInfoCredits,        "Credits"               },
2172   { TYPE_ENTER_SCREEN,  execInfoProgram,        "Program Info"          },
2173   { TYPE_ENTER_SCREEN,  execInfoVersion,        "Version Info"          },
2174   { TYPE_ENTER_SCREEN,  execInfoLevelSet,       "Level Set Info"        },
2175   { TYPE_EMPTY,         NULL,                   ""                      },
2176   { TYPE_LEAVE_MENU,    execExitInfo,           "Exit"                  },
2177
2178   { 0,                  NULL,                   NULL                    }
2179 };
2180
2181 static void DrawCursorAndText_Info(int pos, boolean active)
2182 {
2183   int xpos = MENU_SCREEN_START_XPOS;
2184   int ypos = MENU_SCREEN_START_YPOS + pos;
2185   int font_nr = FONT_MENU_1;
2186
2187   if (active)
2188     font_nr = FONT_ACTIVE(font_nr);
2189
2190   DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2191
2192   if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2193     drawCursor(pos, active);
2194 }
2195
2196 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2197 {
2198   int i;
2199
2200   UnmapAllGadgets();
2201   CloseDoor(DOOR_CLOSE_2);
2202
2203   /* (needed after displaying title screens which disable auto repeat) */
2204   KeyboardAutoRepeatOn();
2205
2206   FadeSetLeaveScreen();
2207
2208 #if 1
2209   FadeOut(redraw_mask);
2210 #endif
2211
2212 #if 1
2213   if (redraw_mask == REDRAW_ALL)
2214   {
2215     RedrawBackground();
2216
2217     OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2218   }
2219 #endif
2220
2221   ClearWindow();
2222
2223   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2224
2225   info_info = info_info_main;
2226   num_info_info = 0;
2227
2228   for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2229   {
2230     if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2231       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2232     else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2233       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2234     else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2235       initCursor(i, IMG_MENU_BUTTON);
2236
2237     DrawCursorAndText_Info(i, FALSE);
2238
2239     num_info_info++;
2240   }
2241
2242   HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2243
2244   PlayMenuSound();
2245   PlayMenuMusic();
2246
2247   DrawMaskedBorder(redraw_mask);
2248
2249   FadeIn(redraw_mask);
2250
2251   InitAnimation();
2252 }
2253
2254 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2255 {
2256   static int choice_store[MAX_INFO_MODES];
2257   int choice = choice_store[info_mode];         /* always starts with 0 */
2258   int x = 0;
2259   int y = choice;
2260
2261   if (button == MB_MENU_INITIALIZE)
2262   {
2263     /* advance to first valid menu entry */
2264     while (choice < num_info_info &&
2265            info_info[choice].type & TYPE_SKIP_ENTRY)
2266       choice++;
2267     choice_store[info_mode] = choice;
2268
2269     DrawCursorAndText_Info(choice, TRUE);
2270
2271     return;
2272   }
2273   else if (button == MB_MENU_LEAVE)
2274   {
2275     for (y = 0; y < num_info_info; y++)
2276     {
2277       if (info_info[y].type & TYPE_LEAVE_MENU)
2278       {
2279         void (*menu_callback_function)(void) = info_info[y].value;
2280
2281         FadeSetLeaveMenu();
2282
2283         menu_callback_function();
2284
2285         break;  /* absolutely needed because function changes 'info_info'! */
2286       }
2287     }
2288
2289     return;
2290   }
2291
2292   if (mx || my)         /* mouse input */
2293   {
2294     x = (mx - mSX) / 32;
2295     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2296   }
2297   else if (dx || dy)    /* keyboard input */
2298   {
2299     if (dx)
2300     {
2301       int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2302
2303       if (info_info[choice].type & menu_navigation_type ||
2304           info_info[choice].type & TYPE_ENTER_SCREEN ||
2305           info_info[choice].type & TYPE_BOOLEAN_STYLE)
2306         button = MB_MENU_CHOICE;
2307     }
2308     else if (dy)
2309       y = choice + dy;
2310
2311     /* jump to next non-empty menu entry (up or down) */
2312     while (y > 0 && y < num_info_info - 1 &&
2313            info_info[y].type & TYPE_SKIP_ENTRY)
2314       y += dy;
2315   }
2316
2317   if (IN_VIS_FIELD(x, y) &&
2318       y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2319   {
2320     if (button)
2321     {
2322       if (y != choice)
2323       {
2324         PlaySound(SND_MENU_ITEM_ACTIVATING);
2325
2326         DrawCursorAndText_Info(choice, FALSE);
2327         DrawCursorAndText_Info(y, TRUE);
2328
2329         choice = choice_store[info_mode] = y;
2330       }
2331     }
2332     else if (!(info_info[y].type & TYPE_GHOSTED))
2333     {
2334       PlaySound(SND_MENU_ITEM_SELECTING);
2335
2336       if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2337       {
2338         void (*menu_callback_function)(void) = info_info[choice].value;
2339
2340         FadeSetFromType(info_info[y].type);
2341
2342         menu_callback_function();
2343       }
2344     }
2345   }
2346 }
2347
2348 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2349 {
2350   int ystart1 = mSY - SY + 100;
2351   int ystart2 = mSY - SY + 150;
2352   int ybottom = mSY - SY + SYSIZE - 20;
2353
2354   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2355
2356   FadeOut(REDRAW_FIELD);
2357
2358   ClearWindow();
2359   DrawHeadline();
2360
2361   DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2362   DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2363
2364   DrawTextSCentered(ybottom, FONT_TEXT_4,
2365                     "Press any key or button for info menu");
2366
2367   FadeIn(REDRAW_FIELD);
2368 }
2369
2370 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2371 {
2372   static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2373   static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2374   int xstart = mSX + 16;
2375   int ystart1 = mSY - SY + 100;
2376   int ystart2 = mSY + 64 + 2 * 32;
2377   int ybottom = mSY - SY + SYSIZE - 20;
2378   int ystep = TILEY + 4;
2379   int element, action, direction;
2380   int graphic;
2381   int delay;
2382   int sync_frame;
2383   int i, j;
2384
2385   if (init)
2386   {
2387     for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2388       infoscreen_step[i] = infoscreen_frame[i] = 0;
2389
2390     ClearWindow();
2391     DrawHeadline();
2392
2393     DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2394
2395     DrawTextSCentered(ybottom, FONT_TEXT_4,
2396                       "Press any key or button for next page");
2397
2398     FrameCounter = 0;
2399   }
2400
2401   i = j = 0;
2402   while (helpanim_info[j].element != HELPANIM_LIST_END)
2403   {
2404     if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2405         i >= max_anims)
2406       break;
2407     else if (i < start)
2408     {
2409       while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2410         j++;
2411
2412       j++;
2413       i++;
2414
2415       continue;
2416     }
2417
2418     j += infoscreen_step[i - start];
2419
2420     element = helpanim_info[j].element;
2421     action = helpanim_info[j].action;
2422     direction = helpanim_info[j].direction;
2423
2424     if (element < 0)
2425       element = EL_UNKNOWN;
2426
2427     if (action != -1 && direction != -1)
2428       graphic = el_act_dir2img(element, action, direction);
2429     else if (action != -1)
2430       graphic = el_act2img(element, action);
2431     else if (direction != -1)
2432       graphic = el_dir2img(element, direction);
2433     else
2434       graphic = el2img(element);
2435
2436     delay = helpanim_info[j++].delay;
2437
2438     if (delay == -1)
2439       delay = 1000000;
2440
2441     if (infoscreen_frame[i - start] == 0)
2442     {
2443       sync_frame = 0;
2444       infoscreen_frame[i - start] = delay - 1;
2445     }
2446     else
2447     {
2448       sync_frame = delay - infoscreen_frame[i - start];
2449       infoscreen_frame[i - start]--;
2450     }
2451
2452     if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2453     {
2454       if (!infoscreen_frame[i - start])
2455         infoscreen_step[i - start] = 0;
2456     }
2457     else
2458     {
2459       if (!infoscreen_frame[i - start])
2460         infoscreen_step[i - start]++;
2461       while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2462         j++;
2463     }
2464
2465     j++;
2466
2467     ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2468                                TILEX, TILEY);
2469     DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2470                             graphic, sync_frame, USE_MASKING);
2471
2472     if (init)
2473       DrawInfoScreen_HelpText(element, action, direction, i - start);
2474
2475     i++;
2476   }
2477
2478   redraw_mask |= REDRAW_FIELD;
2479
2480   FrameCounter++;
2481 }
2482
2483 static char *getHelpText(int element, int action, int direction)
2484 {
2485   char token[MAX_LINE_LEN];
2486
2487   strcpy(token, element_info[element].token_name);
2488
2489   if (action != -1)
2490     strcat(token, element_action_info[action].suffix);
2491
2492   if (direction != -1)
2493     strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2494
2495   return getHashEntry(helptext_info, token);
2496 }
2497
2498 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2499 {
2500   int font_nr = FONT_INFO_ELEMENTS;
2501   int font_width = getFontWidth(font_nr);
2502   int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2503   int sy = mSY + 65 + 2 * 32 + 1;
2504   int ystep = TILEY + 4;
2505   int pad_x = sx - SX;
2506   int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2507   int max_lines_per_text = 2;    
2508   char *text = NULL;
2509
2510   if (action != -1 && direction != -1)          /* element.action.direction */
2511     text = getHelpText(element, action, direction);
2512
2513   if (text == NULL && action != -1)             /* element.action */
2514     text = getHelpText(element, action, -1);
2515
2516   if (text == NULL && direction != -1)          /* element.direction */
2517     text = getHelpText(element, -1, direction);
2518
2519   if (text == NULL)                             /* base element */
2520     text = getHelpText(element, -1, -1);
2521
2522   if (text == NULL)                             /* not found */
2523     text = "No description available";
2524
2525   if (strlen(text) <= max_chars_per_line)       /* only one line of text */
2526     sy += getFontHeight(font_nr) / 2;
2527
2528   DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2529                  max_chars_per_line, -1, max_lines_per_text, -1,
2530                  TRUE, FALSE, FALSE);
2531 }
2532
2533 void DrawInfoScreen_TitleScreen()
2534 {
2535   DrawTitleScreen();
2536 }
2537
2538 void HandleInfoScreen_TitleScreen(int button)
2539 {
2540   HandleTitleScreen(0, 0, 0, 0, button);
2541 }
2542
2543 void DrawInfoScreen_Elements()
2544 {
2545   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2546
2547   FadeOut(REDRAW_FIELD);
2548
2549   LoadHelpAnimInfo();
2550   LoadHelpTextInfo();
2551
2552   HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2553
2554   FadeIn(REDRAW_FIELD);
2555
2556   InitAnimation();
2557 }
2558
2559 void HandleInfoScreen_Elements(int button)
2560 {
2561   static unsigned long info_delay = 0;
2562   static int num_anims;
2563   static int num_pages;
2564   static int page;
2565   int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2566   int i;
2567
2568   if (button == MB_MENU_INITIALIZE)
2569   {
2570     boolean new_element = TRUE;
2571
2572     num_anims = 0;
2573
2574     for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2575     {
2576       if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2577         new_element = TRUE;
2578       else if (new_element)
2579       {
2580         num_anims++;
2581         new_element = FALSE;
2582       }
2583     }
2584
2585     num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2586     page = 0;
2587   }
2588
2589   if (button == MB_MENU_LEAVE)
2590   {
2591     PlaySound(SND_MENU_ITEM_SELECTING);
2592
2593     info_mode = INFO_MODE_MAIN;
2594     DrawInfoScreen();
2595
2596     return;
2597   }
2598   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2599   {
2600     if (button != MB_MENU_INITIALIZE)
2601     {
2602       PlaySound(SND_MENU_ITEM_SELECTING);
2603
2604       page++;
2605     }
2606
2607     if (page >= num_pages)
2608     {
2609       FadeSoundsAndMusic();
2610
2611       info_mode = INFO_MODE_MAIN;
2612       DrawAndFadeInInfoScreen(REDRAW_FIELD);
2613
2614       return;
2615     }
2616
2617 #if 1
2618     if (page > 0)
2619       FadeSetNextScreen();
2620 #endif
2621
2622 #if 1
2623     if (button != MB_MENU_INITIALIZE)
2624       FadeOut(REDRAW_FIELD);
2625 #else
2626     if (button != MB_MENU_INITIALIZE)
2627       FadeCrossSaveBackbuffer();
2628 #endif
2629
2630     DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2631
2632 #if 1
2633     if (button != MB_MENU_INITIALIZE)
2634       FadeIn(REDRAW_FIELD);
2635 #else
2636     if (button != MB_MENU_INITIALIZE)
2637       FadeCross(REDRAW_FIELD);
2638 #endif
2639   }
2640   else
2641   {
2642     if (DelayReached(&info_delay, GameFrameDelay))
2643       if (page < num_pages)
2644         DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2645
2646     PlayMenuSoundIfLoop();
2647   }
2648 }
2649
2650 void DrawInfoScreen_Music()
2651 {
2652   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2653
2654 #if 1
2655   FadeOut(REDRAW_FIELD);
2656 #endif
2657
2658   ClearWindow();
2659   DrawHeadline();
2660
2661   LoadMusicInfo();
2662
2663   HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2664
2665 #if 1
2666   FadeIn(REDRAW_FIELD);
2667 #endif
2668 }
2669
2670 void HandleInfoScreen_Music(int button)
2671 {
2672   static struct MusicFileInfo *list = NULL;
2673   int ystart1 = mSY - SY + 100;
2674   int ystart2 = mSY - SY + 150;
2675   int ybottom = mSY - SY + SYSIZE - 20;
2676   int dy = 30;
2677
2678   if (button == MB_MENU_INITIALIZE)
2679   {
2680     list = music_file_info;
2681
2682     if (list == NULL)
2683     {
2684       FadeSoundsAndMusic();
2685
2686       ClearWindow();
2687       DrawHeadline();
2688
2689       DrawTextSCentered(ystart1, FONT_TEXT_1,
2690                         "No music info for this level set.");
2691
2692       DrawTextSCentered(ybottom, FONT_TEXT_4,
2693                         "Press any key or button for info menu");
2694
2695       return;
2696     }
2697   }
2698
2699   if (button == MB_MENU_LEAVE)
2700   {
2701     PlaySound(SND_MENU_ITEM_SELECTING);
2702
2703     FadeSoundsAndMusic();
2704
2705     info_mode = INFO_MODE_MAIN;
2706     DrawInfoScreen();
2707
2708     return;
2709   }
2710   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2711   {
2712     int y = 0;
2713
2714     if (button != MB_MENU_INITIALIZE)
2715     {
2716       PlaySound(SND_MENU_ITEM_SELECTING);
2717
2718       if (list != NULL)
2719         list = list->next;
2720     }
2721
2722     if (list == NULL)
2723     {
2724       FadeSoundsAndMusic();
2725
2726       info_mode = INFO_MODE_MAIN;
2727       DrawAndFadeInInfoScreen(REDRAW_FIELD);
2728
2729       return;
2730     }
2731
2732     FadeSoundsAndMusic();
2733
2734 #if 1
2735     if (list != music_file_info)
2736       FadeSetNextScreen();
2737 #endif
2738
2739 #if 1
2740     if (button != MB_MENU_INITIALIZE)
2741       FadeOut(REDRAW_FIELD);
2742 #else
2743     if (button != MB_MENU_INITIALIZE)
2744       FadeCrossSaveBackbuffer();
2745 #endif
2746
2747     ClearWindow();
2748     DrawHeadline();
2749
2750     if (list->is_sound)
2751     {
2752       int sound = list->music;
2753
2754       if (sound_info[sound].loop)
2755         PlaySoundLoop(sound);
2756       else
2757         PlaySound(sound);
2758
2759       DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2760     }
2761     else
2762     {
2763       PlayMusic(list->music);
2764
2765       DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2766     }
2767
2768     if (!strEqual(list->title, UNKNOWN_NAME))
2769     {
2770       if (!strEqual(list->title_header, UNKNOWN_NAME))
2771         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2772
2773       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2774     }
2775
2776     if (!strEqual(list->artist, UNKNOWN_NAME))
2777     {
2778       if (!strEqual(list->artist_header, UNKNOWN_NAME))
2779         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2780       else
2781         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2782
2783       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2784     }
2785
2786     if (!strEqual(list->album, UNKNOWN_NAME))
2787     {
2788       if (!strEqual(list->album_header, UNKNOWN_NAME))
2789         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2790       else
2791         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2792
2793       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2794     }
2795
2796     if (!strEqual(list->year, UNKNOWN_NAME))
2797     {
2798       if (!strEqual(list->year_header, UNKNOWN_NAME))
2799         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2800       else
2801         DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2802
2803       DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2804     }
2805
2806     DrawTextSCentered(ybottom, FONT_TEXT_4,
2807                       "Press any key or button for next page");
2808
2809 #if 1
2810     if (button != MB_MENU_INITIALIZE)
2811       FadeIn(REDRAW_FIELD);
2812 #else
2813     if (button != MB_MENU_INITIALIZE)
2814       FadeCross(REDRAW_FIELD);
2815 #endif
2816   }
2817
2818   if (list != NULL && list->is_sound && sound_info[list->music].loop)
2819     PlaySoundLoop(list->music);
2820 }
2821
2822 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2823 {
2824   int ystart1 = mSY - SY + 100;
2825   int ystart2 = mSY - SY + 150;
2826   int ybottom = mSY - SY + SYSIZE - 20;
2827   int ystep = 30;
2828
2829   ClearWindow();
2830   DrawHeadline();
2831
2832   DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2833
2834   if (screen_nr == 0)
2835   {
2836     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2837                       "Special thanks to");
2838     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2839                       "Peter Liepa");
2840     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2841                       "for creating");
2842     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2843                       "\"Boulder Dash\"");
2844     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2845                       "in the year");
2846     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2847                       "1984");
2848     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2849                       "published by");
2850     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2851                       "First Star Software");
2852   }
2853   else if (screen_nr == 1)
2854   {
2855     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2856                       "Special thanks to");
2857     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2858                       "Klaus Heinz & Volker Wertich");
2859     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2860                       "for creating");
2861     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2862                       "\"Emerald Mine\"");
2863     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2864                       "in the year");
2865     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2866                       "1987");
2867     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2868                       "published by");
2869     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2870                       "Kingsoft");
2871   }
2872   else if (screen_nr == 2)
2873   {
2874     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2875                       "Special thanks to");
2876     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2877                       "Michael Stopp & Philip Jespersen");
2878     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2879                       "for creating");
2880     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2881                       "\"Supaplex\"");
2882     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2883                       "in the year");
2884     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2885                       "1991");
2886     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2887                       "published by");
2888     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2889                       "Digital Integration");
2890   }
2891   else if (screen_nr == 3)
2892   {
2893     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2894                       "Special thanks to");
2895     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2896                       "Hiroyuki Imabayashi");
2897     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2898                       "for creating");
2899     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2900                       "\"Sokoban\"");
2901     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2902                       "in the year");
2903     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2904                       "1982");
2905     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2906                       "published by");
2907     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2908                       "Thinking Rabbit");
2909   }
2910   else if (screen_nr == 4)
2911   {
2912     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2913                       "Special thanks to");
2914     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2915                       "Alan Bond");
2916     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2917                       "and");
2918     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2919                       "Jürgen Bonhagen");
2920     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2921                       "for the continuous creation");
2922     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2923                       "of outstanding level sets");
2924   }
2925   else if (screen_nr == 5)
2926   {
2927     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2928                       "Thanks to");
2929     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2930                       "Peter Elzner");
2931     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2932                       "for ideas and inspiration by");
2933     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2934                       "Diamond Caves");
2935
2936     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2937                       "Thanks to");
2938     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2939                       "Steffest");
2940     DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2941                       "for ideas and inspiration by");
2942     DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2943                       "DX-Boulderdash");
2944   }
2945   else if (screen_nr == 6)
2946   {
2947     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2948                       "Thanks to");
2949     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2950                       "David Tritscher");
2951     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2952                       "for the new Emerald Mine engine");
2953   }
2954   else if (screen_nr == 7)
2955   {
2956     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2957                       "Thanks to");
2958     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2959                       "Guido Schulz");
2960     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2961                       "for the initial DOS port");
2962
2963     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2964                       "Thanks to");
2965     DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2966                       "Karl Hörnell");
2967     DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2968                       "for some additional toons");
2969   }
2970   else if (screen_nr == 8)
2971   {
2972     DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2973                       "And not to forget:");
2974     DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2975                       "Many thanks to");
2976     DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2977                       "All those who contributed");
2978     DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2979                       "levels to this game");
2980     DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2981                       "since 1995");
2982   }
2983
2984   DrawTextSCentered(ybottom, FONT_TEXT_4,
2985                     "Press any key or button for next page");
2986 }
2987
2988 void DrawInfoScreen_Credits()
2989 {
2990   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2991
2992   FadeSoundsAndMusic();
2993
2994 #if 1
2995   FadeOut(REDRAW_FIELD);
2996 #endif
2997
2998   HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2999
3000 #if 1
3001   FadeIn(REDRAW_FIELD);
3002 #endif
3003 }
3004
3005 void HandleInfoScreen_Credits(int button)
3006 {
3007   static int screen_nr = 0;
3008   int num_screens = 9;
3009
3010   if (button == MB_MENU_INITIALIZE)
3011   {
3012     screen_nr = 0;
3013
3014     // DrawInfoScreen_CreditsScreen(screen_nr);
3015   }
3016
3017   if (button == MB_MENU_LEAVE)
3018   {
3019     PlaySound(SND_MENU_ITEM_SELECTING);
3020
3021     info_mode = INFO_MODE_MAIN;
3022     DrawInfoScreen();
3023
3024     return;
3025   }
3026   else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3027   {
3028     if (button != MB_MENU_INITIALIZE)
3029     {
3030       PlaySound(SND_MENU_ITEM_SELECTING);
3031
3032       screen_nr++;
3033     }
3034
3035     if (screen_nr >= num_screens)
3036     {
3037       FadeSoundsAndMusic();
3038
3039       info_mode = INFO_MODE_MAIN;
3040       DrawAndFadeInInfoScreen(REDRAW_FIELD);
3041
3042       return;
3043     }
3044
3045 #if 1
3046     if (screen_nr > 0)
3047       FadeSetNextScreen();
3048 #endif
3049
3050 #if 1
3051     if (button != MB_MENU_INITIALIZE)
3052       FadeOut(REDRAW_FIELD);
3053 #else
3054     if (button != MB_MENU_INITIALIZE)
3055       FadeCrossSaveBackbuffer();
3056 #endif
3057
3058     DrawInfoScreen_CreditsScreen(screen_nr);
3059
3060 #if 1
3061     if (button != MB_MENU_INITIALIZE)
3062       FadeIn(REDRAW_FIELD);
3063 #else
3064     if (button != MB_MENU_INITIALIZE)
3065       FadeCross(REDRAW_FIELD);
3066 #endif
3067   }
3068   else
3069   {
3070     PlayMenuSoundIfLoop();
3071   }
3072 }
3073
3074 void DrawInfoScreen_Program()
3075 {
3076   int ystart1 = mSY - SY + 100;
3077   int ystart2 = mSY - SY + 150;
3078   int ybottom = mSY - SY + SYSIZE - 20;
3079   int ystep = 30;
3080
3081   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3082
3083 #if 1
3084   FadeOut(REDRAW_FIELD);
3085 #endif
3086
3087   ClearWindow();
3088   DrawHeadline();
3089
3090   DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3091
3092   DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3093                     "This game is Freeware!");
3094   DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3095                     "If you like it, send e-mail to:");
3096   DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3097                     PROGRAM_EMAIL_STRING);
3098   DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3099                     "or SnailMail to:");
3100   DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3101                     "Holger Schemel");
3102   DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3103                     "Detmolder Strasse 189");
3104   DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3105                     "33604 Bielefeld");
3106   DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3107                     "Germany");
3108   DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3109                     "More information and levels:");
3110   DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3111                     PROGRAM_WEBSITE_STRING);
3112   DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3113                     "If you have created new levels,");
3114   DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3115                     "send them to me to include them!");
3116   DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3117                     ":-)");
3118
3119   DrawTextSCentered(ybottom, FONT_TEXT_4,
3120                     "Press any key or button for info menu");
3121
3122 #if 1
3123   FadeIn(REDRAW_FIELD);
3124 #endif
3125 }
3126
3127 void HandleInfoScreen_Program(int button)
3128 {
3129   if (button == MB_MENU_LEAVE)
3130   {
3131     PlaySound(SND_MENU_ITEM_SELECTING);
3132
3133     info_mode = INFO_MODE_MAIN;
3134     DrawInfoScreen();
3135
3136     return;
3137   }
3138   else if (button == MB_MENU_CHOICE)
3139   {
3140     PlaySound(SND_MENU_ITEM_SELECTING);
3141
3142     FadeSoundsAndMusic();
3143
3144 #if 0
3145     FadeOut(REDRAW_FIELD);
3146 #endif
3147
3148     info_mode = INFO_MODE_MAIN;
3149     DrawAndFadeInInfoScreen(REDRAW_FIELD);
3150   }
3151   else
3152   {
3153     PlayMenuSoundIfLoop();
3154   }
3155 }
3156
3157 void DrawInfoScreen_Version()
3158 {
3159   int font_header = FONT_TEXT_3;
3160   int font_text = FONT_TEXT_2;
3161   int xstep = getFontWidth(font_text);
3162   int ystep = getFontHeight(font_text);
3163   int ystart1 = mSY - SY + 100;
3164   int ystart2 = mSY - SY + 150;
3165   int ybottom = mSY - SY + SYSIZE - 20;
3166   int xstart1 = mSX + 2 * xstep;
3167   int xstart2 = mSX + 19 * xstep;
3168 #if defined(TARGET_SDL)
3169   int xstart3 = mSX + 29 * xstep;
3170   SDL_version sdl_version_compiled;
3171   const SDL_version *sdl_version_linked;
3172   int driver_name_len = 8;
3173   char driver_name[driver_name_len];
3174 #endif
3175
3176   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3177
3178 #if 1
3179   FadeOut(REDRAW_FIELD);
3180 #endif
3181
3182   ClearWindow();
3183   DrawHeadline();
3184
3185   DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3186
3187   DrawTextF(xstart1, ystart2, font_header, "Name");
3188   DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3189
3190   ystart2 += ystep;
3191   DrawTextF(xstart1, ystart2, font_header, "Version");
3192   DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3193
3194   ystart2 += ystep;
3195   DrawTextF(xstart1, ystart2, font_header, "Platform");
3196   DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3197
3198   ystart2 += ystep;
3199   DrawTextF(xstart1, ystart2, font_header, "Target");
3200   DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3201
3202   ystart2 += ystep;
3203   DrawTextF(xstart1, ystart2, font_header, "Compile time");
3204   DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3205
3206 #if defined(TARGET_SDL)
3207   ystart2 += 3 * ystep;
3208   DrawTextF(xstart1, ystart2, font_header, "Library");
3209   DrawTextF(xstart2, ystart2, font_header, "compiled");
3210   DrawTextF(xstart3, ystart2, font_header, "linked");
3211
3212   SDL_VERSION(&sdl_version_compiled);
3213   sdl_version_linked = SDL_Linked_Version();
3214
3215   ystart2 += 2 * ystep;
3216   DrawTextF(xstart1, ystart2, font_text, "SDL");
3217   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3218             sdl_version_compiled.major,
3219             sdl_version_compiled.minor,
3220             sdl_version_compiled.patch);
3221   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3222             sdl_version_linked->major,
3223             sdl_version_linked->minor,
3224             sdl_version_linked->patch);
3225
3226   SDL_IMAGE_VERSION(&sdl_version_compiled);
3227   sdl_version_linked = IMG_Linked_Version();
3228
3229   ystart2 += ystep;
3230   DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3231   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3232             sdl_version_compiled.major,
3233             sdl_version_compiled.minor,
3234             sdl_version_compiled.patch);
3235   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3236             sdl_version_linked->major,
3237             sdl_version_linked->minor,
3238             sdl_version_linked->patch);
3239
3240   SDL_MIXER_VERSION(&sdl_version_compiled);
3241   sdl_version_linked = Mix_Linked_Version();
3242
3243   ystart2 += ystep;
3244   DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3245   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3246             sdl_version_compiled.major,
3247             sdl_version_compiled.minor,
3248             sdl_version_compiled.patch);
3249   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3250             sdl_version_linked->major,
3251             sdl_version_linked->minor,
3252             sdl_version_linked->patch);
3253
3254   SDL_NET_VERSION(&sdl_version_compiled);
3255   sdl_version_linked = SDLNet_Linked_Version();
3256
3257   ystart2 += ystep;
3258   DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3259   DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3260             sdl_version_compiled.major,
3261             sdl_version_compiled.minor,
3262             sdl_version_compiled.patch);
3263   DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3264             sdl_version_linked->major,
3265             sdl_version_linked->minor,
3266             sdl_version_linked->patch);
3267
3268   ystart2 += 3 * ystep;
3269   DrawTextF(xstart1, ystart2, font_header, "Driver");
3270   DrawTextF(xstart2, ystart2, font_header, "Requested");
3271   DrawTextF(xstart3, ystart2, font_header, "Used");
3272
3273   SDL_VideoDriverName(driver_name, driver_name_len);
3274
3275   ystart2 += 2 * ystep;
3276   DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3277   DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3278   DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3279
3280   SDL_AudioDriverName(driver_name, driver_name_len);
3281
3282   ystart2 += ystep;
3283   DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3284   DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3285   DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3286 #endif
3287
3288   DrawTextSCentered(ybottom, FONT_TEXT_4,
3289                     "Press any key or button for info menu");
3290
3291 #if 1
3292   FadeIn(REDRAW_FIELD);
3293 #endif
3294 }
3295
3296 void HandleInfoScreen_Version(int button)
3297 {
3298   if (button == MB_MENU_LEAVE)
3299   {
3300     PlaySound(SND_MENU_ITEM_SELECTING);
3301
3302     info_mode = INFO_MODE_MAIN;
3303     DrawInfoScreen();
3304
3305     return;
3306   }
3307   else if (button == MB_MENU_CHOICE)
3308   {
3309     PlaySound(SND_MENU_ITEM_SELECTING);
3310
3311     FadeSoundsAndMusic();
3312
3313 #if 0
3314     FadeOut(REDRAW_FIELD);
3315 #endif
3316
3317     info_mode = INFO_MODE_MAIN;
3318     DrawAndFadeInInfoScreen(REDRAW_FIELD);
3319   }
3320   else
3321   {
3322     PlayMenuSoundIfLoop();
3323   }
3324 }
3325
3326 void DrawInfoScreen_LevelSet()
3327 {
3328   struct TitleMessageInfo *tmi = &readme;
3329   char *filename = getLevelSetInfoFilename();
3330
3331   /* if chars set to "-1", automatically determine by text and font width */
3332   if (tmi->chars == -1)
3333     tmi->chars = tmi->width / getFontWidth(tmi->font);
3334   else
3335     tmi->width = tmi->chars * getFontWidth(tmi->font);
3336
3337   /* if lines set to "-1", automatically determine by text and font height */
3338   if (tmi->lines == -1)
3339     tmi->lines = tmi->height / getFontHeight(tmi->font);
3340   else
3341     tmi->height = tmi->lines * getFontHeight(tmi->font);
3342
3343   SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3344
3345 #if 1
3346   FadeOut(REDRAW_FIELD);
3347 #endif
3348
3349   ClearWindow();
3350   DrawHeadline();
3351
3352   DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3353
3354   if (filename != NULL)
3355     DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3356                  filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3357                  tmi->autowrap, tmi->centered, tmi->parse_comments);
3358   else
3359     DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3360                      "No information for this level set.");
3361
3362   DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3363                    "Press any key or button for info menu");
3364
3365 #if 1
3366   FadeIn(REDRAW_FIELD);
3367 #endif
3368 }
3369
3370 void HandleInfoScreen_LevelSet(int button)
3371 {
3372   if (button == MB_MENU_LEAVE)
3373   {
3374     PlaySound(SND_MENU_ITEM_SELECTING);
3375
3376     info_mode = INFO_MODE_MAIN;
3377     DrawInfoScreen();
3378
3379     return;
3380   }
3381   else if (button == MB_MENU_CHOICE)
3382   {
3383     PlaySound(SND_MENU_ITEM_SELECTING);
3384
3385     FadeSoundsAndMusic();
3386
3387 #if 0
3388     FadeOut(REDRAW_FIELD);
3389 #endif
3390
3391     info_mode = INFO_MODE_MAIN;
3392     DrawAndFadeInInfoScreen(REDRAW_FIELD);
3393   }
3394   else
3395   {
3396     PlayMenuSoundIfLoop();
3397   }
3398 }
3399
3400 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3401 {
3402   SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3403
3404   if (info_mode == INFO_MODE_TITLE)
3405     DrawInfoScreen_TitleScreen();
3406   else if (info_mode == INFO_MODE_ELEMENTS)
3407     DrawInfoScreen_Elements();
3408   else if (info_mode == INFO_MODE_MUSIC)
3409     DrawInfoScreen_Music();
3410   else if (info_mode == INFO_MODE_CREDITS)
3411     DrawInfoScreen_Credits();
3412   else if (info_mode == INFO_MODE_PROGRAM)
3413     DrawInfoScreen_Program();
3414   else if (info_mode == INFO_MODE_VERSION)
3415     DrawInfoScreen_Version();
3416   else if (info_mode == INFO_MODE_LEVELSET)
3417     DrawInfoScreen_LevelSet();
3418   else
3419     DrawInfoScreen_Main(redraw_mask, do_fading);
3420
3421   if (info_mode != INFO_MODE_MAIN &&
3422       info_mode != INFO_MODE_TITLE &&
3423       info_mode != INFO_MODE_MUSIC)
3424   {
3425     PlayMenuSound();
3426     PlayMenuMusic();
3427   }
3428 }
3429
3430 void DrawAndFadeInInfoScreen(int redraw_mask)
3431 {
3432   DrawInfoScreenExt(redraw_mask, TRUE);
3433 }
3434
3435 void DrawInfoScreen()
3436 {
3437   DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3438 }
3439
3440 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3441 {
3442   if (info_mode == INFO_MODE_TITLE)
3443     HandleInfoScreen_TitleScreen(button);
3444   else if (info_mode == INFO_MODE_ELEMENTS)
3445     HandleInfoScreen_Elements(button);
3446   else if (info_mode == INFO_MODE_MUSIC)
3447     HandleInfoScreen_Music(button);
3448   else if (info_mode == INFO_MODE_CREDITS)
3449     HandleInfoScreen_Credits(button);
3450   else if (info_mode == INFO_MODE_PROGRAM)
3451     HandleInfoScreen_Program(button);
3452   else if (info_mode == INFO_MODE_VERSION)
3453     HandleInfoScreen_Version(button);
3454   else if (info_mode == INFO_MODE_LEVELSET)
3455     HandleInfoScreen_LevelSet(button);
3456   else
3457     HandleInfoScreen_Main(mx, my, dx, dy, button);
3458
3459   DoAnimation();
3460 }
3461
3462
3463 /* ========================================================================= */
3464 /* type name functions                                                       */
3465 /* ========================================================================= */
3466
3467 void HandleTypeName(int newxpos, Key key)
3468 {
3469   static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3470   struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3471 #if 1
3472   struct TextPosInfo *pos = mci->pos_input;
3473   int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3474   int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3475 #endif
3476 #if 1
3477   static int xpos = 0;
3478 #else
3479   static int xpos = 0, ypos = 2;
3480 #endif
3481   int font_nr = pos->font;
3482   int font_active_nr = FONT_ACTIVE(font_nr);
3483   int font_width = getFontWidth(font_active_nr);
3484 #if 1
3485 #if 0
3486   int startx = mSX + mci->pos_input->x;
3487   int starty = mSY + mci->pos_input->y;
3488 #endif
3489 #else
3490   int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3491   int startx = mSX + 32 + name_width;
3492   int starty = mSY + ypos * 32;
3493 #endif
3494   char key_char = getValidConfigValueChar(getCharFromKey(key));
3495   boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3496   boolean is_active = TRUE;
3497
3498   DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3499
3500   if (newxpos)
3501   {
3502     strcpy(last_player_name, setup.player_name);
3503
3504     xpos = newxpos;
3505
3506 #if 0
3507     /* add one character width for added cursor character */
3508     pos->width += font_width;
3509     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3510
3511     DrawText(startx, starty, setup.player_name, font_active_nr);
3512     DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3513 #endif
3514   }
3515   else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3516   {
3517     setup.player_name[xpos] = key_char;
3518     setup.player_name[xpos + 1] = 0;
3519
3520     xpos++;
3521
3522 #if 0
3523     /* add one character width for added name text character */
3524     pos->width += font_width;
3525     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3526
3527     DrawText(startx, starty, setup.player_name, font_active_nr);
3528     DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3529 #endif
3530   }
3531   else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3532   {
3533     xpos--;
3534
3535     setup.player_name[xpos] = 0;
3536
3537 #if 0
3538     /* remove one character width for removed name text character */
3539     pos->width -= font_width;
3540     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3541
3542     DrawText(startx, starty, setup.player_name, font_active_nr);
3543     DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3544 #endif
3545   }
3546   else if (key == KSYM_Return && xpos > 0)
3547   {
3548 #if 0
3549     /* remove one character width for removed cursor text character */
3550     pos->width -= font_width;
3551     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3552
3553     DrawText(startx, starty, setup.player_name, font_nr);
3554     DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3555 #endif
3556
3557     SaveSetup();
3558
3559     is_active = FALSE;
3560
3561     game_status = GAME_MODE_MAIN;
3562   }
3563   else if (key == KSYM_Escape)
3564   {
3565     strcpy(setup.player_name, last_player_name);
3566
3567     is_active = FALSE;
3568
3569     game_status = GAME_MODE_MAIN;
3570   }
3571
3572   if (is_active)
3573   {
3574     pos->width = (strlen(setup.player_name) + 1) * font_width;
3575     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3576
3577     DrawText(startx, starty, setup.player_name, font_active_nr);
3578     DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3579   }
3580   else
3581   {
3582     pos->width = strlen(setup.player_name) * font_width;
3583     startx = mSX + ALIGNED_TEXT_XPOS(pos);
3584
3585     DrawText(startx, starty, setup.player_name, font_nr);
3586   }
3587 }
3588
3589
3590 /* ========================================================================= */
3591 /* tree menu functions                                                       */
3592 /* ========================================================================= */
3593
3594 static void DrawChooseTree(TreeInfo **ti_ptr)
3595 {
3596   UnmapAllGadgets();
3597
3598   FreeScreenGadgets();
3599   CreateScreenGadgets();
3600
3601   CloseDoor(DOOR_CLOSE_2);
3602
3603 #if 1
3604   FadeOut(REDRAW_FIELD);
3605 #endif
3606
3607   ClearWindow();
3608
3609   HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3610   MapScreenTreeGadgets(*ti_ptr);
3611
3612 #if 1
3613   FadeIn(REDRAW_FIELD);
3614 #endif
3615
3616   InitAnimation();
3617 }
3618
3619 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3620 {
3621   struct GadgetInfo *gi = screen_gadget[id];
3622   int items_max, items_visible, item_position;
3623
3624   items_max = numTreeInfoInGroup(ti);
3625   items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3626   item_position = first_entry;
3627
3628   if (item_position > items_max - items_visible)
3629     item_position = items_max - items_visible;
3630
3631   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3632                GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3633                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3634 }
3635
3636 static void drawChooseTreeList(int first_entry, int num_page_entries,
3637                                TreeInfo *ti)
3638 {
3639   int i;
3640   char *title_string = NULL;
3641   int yoffset_sets = MENU_TITLE1_YPOS;
3642   int yoffset_setup = 16;
3643   int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3644                  yoffset_setup);
3645   int last_game_status = game_status;   /* save current game status */
3646
3647   title_string = ti->infotext;
3648
3649   DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3650
3651 #if 0
3652   /* force LEVELS font on artwork setup screen */
3653   game_status = GAME_MODE_LEVELS;
3654 #endif
3655
3656 #if 1
3657   /* clear tree list area, but not title or scrollbar */
3658   DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3659                  SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3660                  NUM_MENU_ENTRIES_ON_SCREEN * 32);
3661 #else
3662   /* clear tree list area, but not title or scrollbar */
3663   DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3664                  SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3665                  MAX_MENU_ENTRIES_ON_SCREEN * 32);
3666 #endif
3667
3668   for (i = 0; i < num_page_entries; i++)
3669   {
3670     TreeInfo *node, *node_first;
3671     int entry_pos = first_entry + i;
3672     int xpos = MENU_SCREEN_START_XPOS;
3673     int ypos = MENU_SCREEN_START_YPOS + i;
3674     int startx = mSX + xpos * 32;
3675     int starty = mSY + ypos * 32;
3676     int font_nr = FONT_TEXT_1;
3677     int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3678     int startx_text = startx + font_xoffset;
3679     int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3680     int text_size = startx_scrollbar - startx_text;
3681     int max_buffer_len = text_size / getFontWidth(font_nr);
3682     char buffer[max_buffer_len + 1];
3683
3684     node_first = getTreeInfoFirstGroupEntry(ti);
3685     node = getTreeInfoFromPos(node_first, entry_pos);
3686
3687     strncpy(buffer, node->name, max_buffer_len);
3688     buffer[max_buffer_len] = '\0';
3689
3690     DrawText(startx, starty, buffer, font_nr + node->color);
3691
3692     if (node->parent_link)
3693       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3694     else if (node->level_group)
3695       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3696     else
3697       initCursor(i, IMG_MENU_BUTTON);
3698   }
3699
3700   game_status = last_game_status;       /* restore current game status */
3701
3702   redraw_mask |= REDRAW_FIELD;
3703 }
3704
3705 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3706 {
3707   TreeInfo *node, *node_first;
3708   int x, last_redraw_mask = redraw_mask;
3709   int ypos = MENU_TITLE2_YPOS;
3710   int font_nr = FONT_TITLE_2;
3711
3712   if (ti->type != TREE_TYPE_LEVEL_DIR)
3713     return;
3714
3715   node_first = getTreeInfoFirstGroupEntry(ti);
3716   node = getTreeInfoFromPos(node_first, entry_pos);
3717
3718   DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3719
3720   if (node->parent_link)
3721     DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3722                       node->class_desc);
3723   else if (node->level_group)
3724     DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3725                       node->class_desc);
3726   else if (ti->type == TREE_TYPE_LEVEL_DIR)
3727     DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3728                       node->levels, node->class_desc);
3729
3730   /* let BackToFront() redraw only what is needed */
3731   redraw_mask = last_redraw_mask | REDRAW_TILES;
3732   for (x = 0; x < SCR_FIELDX; x++)
3733     MarkTileDirty(x, 1);
3734 }
3735
3736 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3737                              TreeInfo **ti_ptr)
3738 {
3739   TreeInfo *ti = *ti_ptr;
3740   int x = 0;
3741   int y = ti->cl_cursor;
3742   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3743   int num_entries = numTreeInfoInGroup(ti);
3744   int num_page_entries;
3745   int last_game_status = game_status;   /* save current game status */
3746   boolean position_set_by_scrollbar = (dx == 999);
3747
3748 #if 0
3749   /* force LEVELS draw offset on choose level and artwork setup screen */
3750   game_status = GAME_MODE_LEVELS;
3751 #endif
3752
3753   if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3754     num_page_entries = num_entries;
3755   else
3756     num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3757
3758   game_status = last_game_status;       /* restore current game status */
3759
3760   if (button == MB_MENU_INITIALIZE)
3761   {
3762     int num_entries = numTreeInfoInGroup(ti);
3763     int entry_pos = posTreeInfo(ti);
3764
3765     if (ti->cl_first == -1)
3766     {
3767       /* only on initialization */
3768       ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3769       ti->cl_cursor = entry_pos - ti->cl_first;
3770     }
3771     else if (ti->cl_cursor >= num_page_entries ||
3772              (num_entries > num_page_entries &&
3773               num_entries - ti->cl_first < num_page_entries))
3774     {
3775       /* only after change of list size (by custom graphic configuration) */
3776       ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3777       ti->cl_cursor = entry_pos - ti->cl_first;
3778     }
3779
3780     if (position_set_by_scrollbar)
3781       ti->cl_first = dy;
3782     else
3783       AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3784                                 ti->cl_first, ti);
3785
3786     drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3787     drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3788     drawChooseTreeCursor(ti->cl_cursor, TRUE);
3789
3790     return;
3791   }
3792   else if (button == MB_MENU_LEAVE)
3793   {
3794     FadeSetLeaveMenu();
3795
3796     PlaySound(SND_MENU_ITEM_SELECTING);
3797
3798     if (ti->node_parent)
3799     {
3800       *ti_ptr = ti->node_parent;
3801       DrawChooseTree(ti_ptr);
3802     }
3803     else if (game_status == GAME_MODE_SETUP)
3804     {
3805       if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3806         execSetupGame();
3807       else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3808                setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3809         execSetupGraphics();
3810       else
3811         execSetupArtwork();
3812     }
3813     else
3814     {
3815       game_status = GAME_MODE_MAIN;
3816 #if 1
3817       DrawMainMenuExt(REDRAW_FIELD, FALSE);
3818 #else
3819       DrawMainMenu();
3820 #endif
3821     }
3822
3823     return;
3824   }
3825
3826   if (mx || my)         /* mouse input */
3827   {
3828     int last_game_status = game_status; /* save current game status */
3829
3830 #if 0
3831     /* force LEVELS draw offset on artwork setup screen */
3832     game_status = GAME_MODE_LEVELS;
3833 #endif
3834
3835     x = (mx - mSX) / 32;
3836     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3837
3838     game_status = last_game_status;     /* restore current game status */
3839   }
3840   else if (dx || dy)    /* keyboard or scrollbar/scrollbutton input */
3841   {
3842     /* move cursor instead of scrolling when already at start/end of list */
3843     if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3844       dy = -1;
3845     else if (dy == +1 * SCROLL_LINE &&
3846              ti->cl_first + num_page_entries == num_entries)
3847       dy = 1;
3848
3849     /* handle scrolling screen one line or page */
3850     if (ti->cl_cursor + dy < 0 ||
3851         ti->cl_cursor + dy > num_page_entries - 1)
3852     {
3853       if (ABS(dy) == SCROLL_PAGE)
3854         step = num_page_entries - 1;
3855
3856       if (dy < 0 && ti->cl_first > 0)
3857       {
3858         /* scroll page/line up */
3859
3860         ti->cl_first -= step;
3861         if (ti->cl_first < 0)
3862           ti->cl_first = 0;
3863
3864         drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3865         drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3866         drawChooseTreeCursor(ti->cl_cursor, TRUE);
3867
3868         AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3869                                   ti->cl_first, ti);
3870       }
3871       else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3872       {
3873         /* scroll page/line down */
3874
3875         ti->cl_first += step;
3876         if (ti->cl_first + num_page_entries > num_entries)
3877           ti->cl_first = MAX(0, num_entries - num_page_entries);
3878
3879         drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3880         drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3881         drawChooseTreeCursor(ti->cl_cursor, TRUE);
3882
3883         AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3884                                   ti->cl_first, ti);
3885       }
3886
3887       return;
3888     }
3889
3890     /* handle moving cursor one line */
3891     y = ti->cl_cursor + dy;
3892   }
3893
3894   if (dx == 1)
3895   {
3896     TreeInfo *node_first, *node_cursor;
3897     int entry_pos = ti->cl_first + y;
3898
3899     node_first = getTreeInfoFirstGroupEntry(ti);
3900     node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3901
3902     if (node_cursor->node_group)
3903     {
3904       FadeSetEnterMenu();
3905
3906       PlaySound(SND_MENU_ITEM_SELECTING);
3907
3908       node_cursor->cl_first = ti->cl_first;
3909       node_cursor->cl_cursor = ti->cl_cursor;
3910       *ti_ptr = node_cursor->node_group;
3911       DrawChooseTree(ti_ptr);
3912
3913       return;
3914     }
3915   }
3916   else if (dx == -1 && ti->node_parent)
3917   {
3918     FadeSetLeaveMenu();
3919
3920     PlaySound(SND_MENU_ITEM_SELECTING);
3921
3922     *ti_ptr = ti->node_parent;
3923     DrawChooseTree(ti_ptr);
3924
3925     return;
3926   }
3927
3928   if (!anyScrollbarGadgetActive() &&
3929       IN_VIS_FIELD(x, y) &&
3930       mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3931       y >= 0 && y < num_page_entries)
3932   {
3933     if (button)
3934     {
3935       if (y != ti->cl_cursor)
3936       {
3937         PlaySound(SND_MENU_ITEM_ACTIVATING);
3938
3939         drawChooseTreeCursor(ti->cl_cursor, FALSE);
3940         drawChooseTreeCursor(y, TRUE);
3941         drawChooseTreeInfo(ti->cl_first + y, ti);
3942
3943         ti->cl_cursor = y;
3944       }
3945     }
3946     else
3947     {
3948       TreeInfo *node_first, *node_cursor;
3949       int entry_pos = ti->cl_first + y;
3950
3951       PlaySound(SND_MENU_ITEM_SELECTING);
3952
3953       node_first = getTreeInfoFirstGroupEntry(ti);
3954       node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3955
3956       if (node_cursor->node_group)
3957       {
3958         FadeSetEnterMenu();
3959
3960         node_cursor->cl_first = ti->cl_first;
3961         node_cursor->cl_cursor = ti->cl_cursor;
3962         *ti_ptr = node_cursor->node_group;
3963         DrawChooseTree(ti_ptr);
3964       }
3965       else if (node_cursor->parent_link)
3966       {
3967         FadeSetLeaveMenu();
3968
3969         *ti_ptr = node_cursor->node_parent;
3970         DrawChooseTree(ti_ptr);
3971       }
3972       else
3973       {
3974         FadeSetEnterScreen();
3975
3976         node_cursor->cl_first = ti->cl_first;
3977         node_cursor->cl_cursor = ti->cl_cursor;
3978         *ti_ptr = node_cursor;
3979
3980         if (ti->type == TREE_TYPE_LEVEL_DIR)
3981         {
3982           LoadLevelSetup_SeriesInfo();
3983
3984           SaveLevelSetup_LastSeries();
3985           SaveLevelSetup_SeriesInfo();
3986           TapeErase();
3987         }
3988
3989         if (game_status == GAME_MODE_SETUP)
3990         {
3991           if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3992             execSetupGame();
3993           else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3994                    setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3995             execSetupGraphics();
3996           else
3997             execSetupArtwork();
3998         }
3999         else
4000         {
4001           game_status = GAME_MODE_MAIN;
4002           DrawMainMenu();
4003         }
4004       }
4005     }
4006   }
4007 }
4008
4009 void DrawChooseLevel()
4010 {
4011   SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4012
4013   DrawChooseTree(&leveldir_current);
4014
4015   PlayMenuSound();
4016   PlayMenuMusic();
4017 }
4018
4019 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4020 {
4021   HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4022
4023   DoAnimation();
4024 }
4025
4026 void DrawHallOfFame(int highlight_position)
4027 {
4028   UnmapAllGadgets();
4029   FadeSoundsAndMusic();
4030
4031   /* (this is needed when called from GameEnd() after winning a game) */
4032   KeyboardAutoRepeatOn();
4033   ActivateJoystick();
4034
4035   /* (this is needed when called from GameEnd() after winning a game) */
4036   SetDrawDeactivationMask(REDRAW_NONE);
4037   SetDrawBackgroundMask(REDRAW_FIELD);
4038
4039   CloseDoor(DOOR_CLOSE_2);
4040
4041   if (highlight_position < 0) 
4042     LoadScore(level_nr);
4043
4044   FadeSetEnterScreen();
4045
4046   // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4047
4048 #if 1
4049   FadeOut(REDRAW_FIELD);
4050 #endif
4051
4052   InitAnimation();
4053
4054   PlayMenuSound();
4055   PlayMenuMusic();
4056
4057   HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4058
4059 #if 1
4060   FadeIn(REDRAW_FIELD);
4061 #endif
4062 }
4063
4064 static void drawHallOfFameList(int first_entry, int highlight_position)
4065 {
4066   int i;
4067
4068   SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4069   ClearWindow();
4070
4071   DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4072   DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4073                     "HighScores of Level %d", level_nr);
4074
4075   for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4076   {
4077     int entry = first_entry + i;
4078     boolean active = (entry == highlight_position);
4079     int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4080     int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4081     int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4082     int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4083     int dx1 = 3 * getFontWidth(font_nr1);
4084     int dx2 = dx1 + getFontWidth(font_nr1);
4085     int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4086     int sy = mSY + 64 + i * 32;
4087
4088     DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4089     DrawText(mSX + dx1, sy, ".", font_nr1);
4090     DrawText(mSX + dx2, sy, ".........................", font_nr3);
4091
4092     if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4093       DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4094
4095     DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4096   }
4097
4098   redraw_mask |= REDRAW_FIELD;
4099 }
4100
4101 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4102 {
4103   static int first_entry = 0;
4104   static int highlight_position = 0;
4105   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4106
4107   if (button == MB_MENU_INITIALIZE)
4108   {
4109     first_entry = 0;
4110     highlight_position = mx;
4111     drawHallOfFameList(first_entry, highlight_position);
4112
4113     return;
4114   }
4115
4116   if (ABS(dy) == SCROLL_PAGE)           /* handle scrolling one page */
4117     step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4118
4119   if (dy < 0)
4120   {
4121     if (first_entry > 0)
4122     {
4123       first_entry -= step;
4124       if (first_entry < 0)
4125         first_entry = 0;
4126
4127       drawHallOfFameList(first_entry, highlight_position);
4128     }
4129   }
4130   else if (dy > 0)
4131   {
4132     if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4133     {
4134       first_entry += step;
4135       if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4136         first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4137
4138       drawHallOfFameList(first_entry, highlight_position);
4139     }
4140   }
4141   else if (button == MB_MENU_LEAVE)
4142   {
4143     PlaySound(SND_MENU_ITEM_SELECTING);
4144
4145     FadeSound(SND_BACKGROUND_SCORES);
4146
4147     game_status = GAME_MODE_MAIN;
4148
4149     DrawMainMenu();
4150   }
4151   else if (button == MB_MENU_CHOICE)
4152   {
4153     PlaySound(SND_MENU_ITEM_SELECTING);
4154
4155     FadeSound(SND_BACKGROUND_SCORES);
4156
4157 #if 0
4158     FadeOut(REDRAW_FIELD);
4159 #endif
4160
4161     game_status = GAME_MODE_MAIN;
4162
4163     DrawAndFadeInMainMenu(REDRAW_FIELD);
4164   }
4165
4166   if (game_status == GAME_MODE_SCORES)
4167     PlayMenuSoundIfLoop();
4168
4169   DoAnimation();
4170 }
4171
4172
4173 /* ========================================================================= */
4174 /* setup screen functions                                                    */
4175 /* ========================================================================= */
4176
4177 static struct TokenInfo *setup_info;
4178 static int num_setup_info;
4179
4180 static char *screen_mode_text;
4181 static char *scroll_delay_text;
4182 static char *game_speed_text;
4183 static char *graphics_set_name;
4184 static char *sounds_set_name;
4185 static char *music_set_name;
4186
4187 static void execSetupMain()
4188 {
4189 #if 0
4190   FadeSetLeaveMenu();
4191 #endif
4192
4193   setup_mode = SETUP_MODE_MAIN;
4194   DrawSetupScreen();
4195 }
4196
4197 static void execSetupGame()
4198 {
4199 #if 0
4200   FadeSetEnterMenu();
4201 #endif
4202
4203   if (game_speeds == NULL)
4204   {
4205     int i;
4206
4207     for (i = 0; game_speeds_list[i].value != -1; i++)
4208     {
4209       TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4210       char identifier[32], name[32];
4211       int value = game_speeds_list[i].value;
4212       char *text = game_speeds_list[i].text;
4213
4214       ti->node_top = &game_speeds;
4215       ti->sort_priority = 10000 - value;
4216
4217       sprintf(identifier, "%d", value);
4218       sprintf(name, "%s", text);
4219
4220       setString(&ti->identifier, identifier);
4221       setString(&ti->name, name);
4222       setString(&ti->name_sorting, name);
4223       setString(&ti->infotext, "Game Speed");
4224
4225       pushTreeInfo(&game_speeds, ti);
4226     }
4227
4228     /* sort game speed values to start with slowest game speed */
4229     sortTreeInfo(&game_speeds);
4230
4231     /* set current game speed to configured game speed value */
4232     game_speed_current =
4233       getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4234
4235     /* if that fails, set current game speed to reliable default value */
4236     if (game_speed_current == NULL)
4237       game_speed_current =
4238         getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4239
4240     /* if that also fails, set current game speed to first available speed */
4241     if (game_speed_current == NULL)
4242       game_speed_current = game_speeds;
4243   }
4244
4245   setup.game_frame_delay = atoi(game_speed_current->identifier);
4246
4247   /* needed for displaying game speed text instead of identifier */
4248   game_speed_text = game_speed_current->name;
4249
4250   setup_mode = SETUP_MODE_GAME;
4251   DrawSetupScreen();
4252 }
4253
4254 static void execSetupChooseGameSpeed()
4255 {
4256 #if 0
4257   FadeSetEnterMenu();
4258 #endif
4259
4260   setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4261   DrawSetupScreen();
4262 }
4263
4264 static void execSetupEditor()
4265 {
4266 #if 0
4267   FadeSetEnterMenu();
4268 #endif
4269
4270   setup_mode = SETUP_MODE_EDITOR;
4271   DrawSetupScreen();
4272 }
4273
4274 static void execSetupGraphics()
4275 {
4276 #if 0
4277   FadeSetEnterMenu();
4278 #endif
4279
4280   if (video.fullscreen_available && screen_modes == NULL)
4281   {
4282     int i;
4283
4284     for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4285     {
4286       TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4287       char identifier[32], name[32];
4288       int x = video.fullscreen_modes[i].width;
4289       int y = video.fullscreen_modes[i].height;
4290       int xx, yy;
4291
4292       get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4293
4294       ti->node_top = &screen_modes;
4295       ti->sort_priority = x * 10000 + y;
4296
4297       sprintf(identifier, "%dx%d", x, y);
4298       sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4299
4300       setString(&ti->identifier, identifier);
4301       setString(&ti->name, name);
4302       setString(&ti->name_sorting, name);
4303       setString(&ti->infotext, "Fullscreen Mode");
4304
4305       pushTreeInfo(&screen_modes, ti);
4306     }
4307
4308     /* sort fullscreen modes to start with lowest available screen resolution */
4309     sortTreeInfo(&screen_modes);
4310
4311     /* set current screen mode for fullscreen mode to configured setup value */
4312     screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4313                                                     setup.fullscreen_mode);
4314
4315     /* if that fails, set current screen mode to reliable default value */
4316     if (screen_mode_current == NULL)
4317       screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4318                                                       DEFAULT_FULLSCREEN_MODE);
4319
4320     /* if that also fails, set current screen mode to first available mode */
4321     if (screen_mode_current == NULL)
4322       screen_mode_current = screen_modes;
4323
4324     if (screen_mode_current == NULL)
4325       video.fullscreen_available = FALSE;
4326   }
4327
4328   if (video.fullscreen_available)
4329   {
4330     setup.fullscreen_mode = screen_mode_current->identifier;
4331
4332     /* needed for displaying screen mode name instead of identifier */
4333     screen_mode_text = screen_mode_current->name;
4334   }
4335
4336 #if 1
4337   if (scroll_delays == NULL)
4338   {
4339     int i;
4340
4341     for (i = 0; scroll_delays_list[i].value != -1; i++)
4342     {
4343       TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4344       char identifier[32], name[32];
4345       int value = scroll_delays_list[i].value;
4346       char *text = scroll_delays_list[i].text;
4347
4348       ti->node_top = &scroll_delays;
4349       ti->sort_priority = value;
4350
4351       sprintf(identifier, "%d", value);
4352       sprintf(name, "%s", text);
4353
4354       setString(&ti->identifier, identifier);
4355       setString(&ti->name, name);
4356       setString(&ti->name_sorting, name);
4357       setString(&ti->infotext, "Scroll Delay");
4358
4359       pushTreeInfo(&scroll_delays, ti);
4360     }
4361
4362     /* sort scroll delay values to start with lowest scroll delay value */
4363     sortTreeInfo(&scroll_delays);
4364
4365     /* set current scroll delay value to configured scroll delay value */
4366     scroll_delay_current =
4367       getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4368
4369     /* if that fails, set current scroll delay to reliable default value */
4370     if (scroll_delay_current == NULL)
4371       scroll_delay_current =
4372         getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4373
4374     /* if that also fails, set current scroll delay to first available value */
4375     if (scroll_delay_current == NULL)
4376       scroll_delay_current = scroll_delays;
4377   }
4378
4379   setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4380
4381   /* needed for displaying scroll delay text instead of identifier */
4382   scroll_delay_text = scroll_delay_current->name;
4383 #endif
4384
4385   setup_mode = SETUP_MODE_GRAPHICS;
4386   DrawSetupScreen();
4387 }
4388
4389 static void execSetupChooseScreenMode()
4390 {
4391 #if 0
4392   FadeSetEnterMenu();
4393 #endif
4394
4395   if (!video.fullscreen_available)
4396     return;
4397
4398   setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4399   DrawSetupScreen();
4400 }
4401
4402 static void execSetupChooseScrollDelay()
4403 {
4404 #if 0
4405   FadeSetEnterMenu();
4406 #endif
4407
4408   setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4409   DrawSetupScreen();
4410 }
4411
4412 static void execSetupSound()
4413 {
4414 #if 0
4415   FadeSetEnterMenu();
4416 #endif
4417
4418   setup_mode = SETUP_MODE_SOUND;
4419   DrawSetupScreen();
4420 }
4421
4422 static void execSetupArtwork()
4423 {
4424 #if 0
4425   FadeSetEnterMenu();
4426 #endif
4427
4428   setup.graphics_set = artwork.gfx_current->identifier;
4429   setup.sounds_set = artwork.snd_current->identifier;
4430   setup.music_set = artwork.mus_current->identifier;
4431
4432   /* needed if last screen (setup choice) changed graphics, sounds or music */
4433   ReloadCustomArtwork(0);
4434
4435   /* needed for displaying artwork name instead of artwork identifier */
4436   graphics_set_name = artwork.gfx_current->name;
4437   sounds_set_name = artwork.snd_current->name;
4438   music_set_name = artwork.mus_current->name;
4439
4440   setup_mode = SETUP_MODE_ARTWORK;
4441   DrawSetupScreen();
4442 }
4443
4444 static void execSetupChooseGraphics()
4445 {
4446 #if 0
4447   FadeSetEnterMenu();
4448 #endif
4449
4450   setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4451   DrawSetupScreen();
4452 }
4453
4454 static void execSetupChooseSounds()
4455 {
4456 #if 0
4457   FadeSetEnterMenu();
4458 #endif
4459
4460   setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4461   DrawSetupScreen();
4462 }
4463
4464 static void execSetupChooseMusic()
4465 {
4466 #if 0
4467   FadeSetEnterMenu();
4468 #endif
4469
4470   setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4471   DrawSetupScreen();
4472 }
4473
4474 static void execSetupInput()
4475 {
4476 #if 0
4477   FadeSetEnterMenu();
4478 #endif
4479
4480   setup_mode = SETUP_MODE_INPUT;
4481   DrawSetupScreen();
4482 }
4483
4484 static void execSetupShortcuts1()
4485 {
4486 #if 0
4487   FadeSetEnterMenu();
4488 #endif
4489
4490   setup_mode = SETUP_MODE_SHORTCUTS_1;
4491   DrawSetupScreen();
4492 }
4493
4494 static void execSetupShortcuts2()
4495 {
4496 #if 0
4497   FadeSetEnterMenu();
4498 #endif
4499
4500   setup_mode = SETUP_MODE_SHORTCUTS_2;
4501   DrawSetupScreen();
4502 }
4503
4504 static void execExitSetup()
4505 {
4506 #if 0
4507   FadeSetLeaveMenu();
4508 #endif
4509
4510   game_status = GAME_MODE_MAIN;
4511 #if 1
4512   DrawMainMenuExt(REDRAW_FIELD, FALSE);
4513 #else
4514   DrawMainMenu();
4515 #endif
4516 }
4517
4518 static void execSaveAndExitSetup()
4519 {
4520   SaveSetup();
4521   execExitSetup();
4522 }
4523
4524 static struct TokenInfo setup_info_main[] =
4525 {
4526   { TYPE_ENTER_MENU,    execSetupGame,          "Game & Menu"           },
4527   { TYPE_ENTER_MENU,    execSetupEditor,        "Editor"                },
4528   { TYPE_ENTER_MENU,    execSetupGraphics,      "Graphics"              },
4529   { TYPE_ENTER_MENU,    execSetupSound,         "Sound & Music"         },
4530   { TYPE_ENTER_MENU,    execSetupArtwork,       "Custom Artwork"        },
4531   { TYPE_ENTER_MENU,    execSetupInput,         "Input Devices"         },
4532   { TYPE_ENTER_MENU,    execSetupShortcuts1,    "Key Shortcuts 1"       },
4533   { TYPE_ENTER_MENU,    execSetupShortcuts2,    "Key Shortcuts 2"       },
4534   { TYPE_EMPTY,         NULL,                   ""                      },
4535   { TYPE_LEAVE_MENU,    execExitSetup,          "Exit"                  },
4536   { TYPE_LEAVE_MENU,    execSaveAndExitSetup,   "Save and Exit"         },
4537
4538   { 0,                  NULL,                   NULL                    }
4539 };
4540
4541 static struct TokenInfo setup_info_game[] =
4542 {
4543   { TYPE_SWITCH,        &setup.team_mode,       "Team-Mode (Multi-Player):" },
4544   { TYPE_YES_NO,        &setup.input_on_focus,  "Only Move Focussed Player:" },
4545   { TYPE_SWITCH,        &setup.handicap,        "Handicap:"             },
4546   { TYPE_SWITCH,        &setup.skip_levels,     "Skip Unsolved Levels:" },
4547   { TYPE_SWITCH,        &setup.time_limit,      "Time Limit:"           },
4548   { TYPE_SWITCH,        &setup.autorecord,      "Auto-Record Tapes:"    },
4549   { TYPE_ENTER_LIST,    execSetupChooseGameSpeed, "Game Speed:"         },
4550   { TYPE_STRING,        &game_speed_text,       ""                      },
4551   { TYPE_EMPTY,         NULL,                   ""                      },
4552   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4553
4554   { 0,                  NULL,                   NULL                    }
4555 };
4556
4557 static struct TokenInfo setup_info_editor[] =
4558 {
4559 #if 0
4560   { TYPE_SWITCH,        &setup.editor.el_boulderdash,   "Boulder Dash:" },
4561   { TYPE_SWITCH,        &setup.editor.el_emerald_mine,  "Emerald Mine:" },
4562   { TYPE_SWITCH, &setup.editor.el_emerald_mine_club,    "Emerald Mine Club:" },
4563   { TYPE_SWITCH,        &setup.editor.el_more,          "Rocks'n'Diamonds:" },
4564   { TYPE_SWITCH,        &setup.editor.el_sokoban,       "Sokoban:"      },
4565   { TYPE_SWITCH,        &setup.editor.el_supaplex,      "Supaplex:"     },
4566   { TYPE_SWITCH,        &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4567   { TYPE_SWITCH,        &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4568 #endif
4569   { TYPE_SWITCH,        &setup.editor.el_chars,         "Text Characters:" },
4570   { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4571   { TYPE_SWITCH,        &setup.editor.el_custom,  "Custom & Group Elements:" },
4572 #if 0
4573   { TYPE_SWITCH,        &setup.editor.el_headlines,     "Headlines:"    },
4574 #endif
4575   { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4576   { TYPE_SWITCH,        &setup.editor.el_dynamic,  "Dynamic level elements:" },
4577   { TYPE_EMPTY,         NULL,                   ""                      },
4578 #if 0
4579   { TYPE_SWITCH,        &setup.editor.el_by_game,   "Show elements by game:" },
4580   { TYPE_SWITCH,        &setup.editor.el_by_type,   "Show elements by type:" },
4581   { TYPE_EMPTY,         NULL,                   ""                      },
4582 #endif
4583   { TYPE_SWITCH, &setup.editor.show_element_token,      "Show element token:" },
4584   { TYPE_EMPTY,         NULL,                   ""                      },
4585   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4586
4587   { 0,                  NULL,                   NULL                    }
4588 };
4589
4590 static struct TokenInfo setup_info_graphics[] =
4591 {
4592   { TYPE_SWITCH,        &setup.fullscreen,      "Fullscreen:"           },
4593   { TYPE_ENTER_LIST,    execSetupChooseScreenMode, "Fullscreen Mode:"   },
4594   { TYPE_STRING,        &screen_mode_text,      ""                      },
4595 #if 0
4596   { TYPE_SWITCH,        &setup.scroll_delay,    "Scroll Delay:"         },
4597 #endif
4598   { TYPE_ENTER_LIST,    execSetupChooseScrollDelay, "Scroll Delay Value:" },
4599   { TYPE_STRING,        &scroll_delay_text,     ""                      },
4600 #if 0
4601   { TYPE_SWITCH,        &setup.soft_scrolling,  "Soft Scrolling:"       },
4602   { TYPE_SWITCH,        &setup.double_buffering,"Double-Buffering:"     },
4603 #endif
4604   { TYPE_SWITCH,        &setup.fade_screens,    "Fade Screens:"         },
4605   { TYPE_SWITCH,        &setup.quick_switch,    "Quick Player Focus Switch:" },
4606   { TYPE_SWITCH,        &setup.quick_doors,     "Quick Menu Doors:"     },
4607   { TYPE_SWITCH,        &setup.show_titlescreen,"Show Title Screens:"   },
4608   { TYPE_SWITCH,        &setup.toons,           "Show Toons:"           },
4609   { TYPE_ECS_AGA,       &setup.prefer_aga_graphics,"EMC graphics preference:" },
4610   { TYPE_EMPTY,         NULL,                   ""                      },
4611   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4612
4613   { 0,                  NULL,                   NULL                    }
4614 };
4615
4616 static struct TokenInfo setup_info_sound[] =
4617 {
4618   { TYPE_SWITCH,        &setup.sound_simple,    "Sound Effects (Normal):"  },
4619   { TYPE_SWITCH,        &setup.sound_loops,     "Sound Effects (Looping):" },
4620   { TYPE_SWITCH,        &setup.sound_music,     "Music:"                },
4621   { TYPE_EMPTY,         NULL,                   ""                      },
4622   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4623
4624   { 0,                  NULL,                   NULL                    }
4625 };
4626
4627 static struct TokenInfo setup_info_artwork[] =
4628 {
4629   { TYPE_ENTER_LIST,    execSetupChooseGraphics,"Custom Graphics:"      },
4630   { TYPE_STRING,        &graphics_set_name,     ""                      },
4631   { TYPE_ENTER_LIST,    execSetupChooseSounds,  "Custom Sounds:"        },
4632   { TYPE_STRING,        &sounds_set_name,       ""                      },
4633   { TYPE_ENTER_LIST,    execSetupChooseMusic,   "Custom Music:"         },
4634   { TYPE_STRING,        &music_set_name,        ""                      },
4635   { TYPE_EMPTY,         NULL,                   ""                      },
4636 #if 1
4637   { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4638   { TYPE_YES_NO, &setup.override_level_sounds,  "Override Level Sounds:"   },
4639   { TYPE_YES_NO, &setup.override_level_music,   "Override Level Music:"    },
4640 #else
4641   { TYPE_STRING,        NULL,                   "Override Level Artwork:"},
4642   { TYPE_YES_NO,        &setup.override_level_graphics, "Graphics:"     },
4643   { TYPE_YES_NO,        &setup.override_level_sounds,   "Sounds:"       },
4644   { TYPE_YES_NO,        &setup.override_level_music,    "Music:"        },
4645 #endif
4646   { TYPE_EMPTY,         NULL,                   ""                      },
4647   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4648
4649   { 0,                  NULL,                   NULL                    }
4650 };
4651
4652 static struct TokenInfo setup_info_input[] =
4653 {
4654   { TYPE_SWITCH,        NULL,                   "Player:"               },
4655   { TYPE_SWITCH,        NULL,                   "Device:"               },
4656   { TYPE_ENTER_MENU,    NULL,                   ""                      },
4657   { TYPE_EMPTY,         NULL,                   ""                      },
4658   { TYPE_EMPTY,         NULL,                   ""                      },
4659   { TYPE_EMPTY,         NULL,                   ""                      },
4660   { TYPE_EMPTY,         NULL,                   ""                      },
4661   { TYPE_EMPTY,         NULL,                   ""                      },
4662   { TYPE_EMPTY,         NULL,                   ""                      },
4663   { TYPE_EMPTY,         NULL,                   ""                      },
4664   { TYPE_EMPTY,         NULL,                   ""                      },
4665   { TYPE_EMPTY,         NULL,                   ""                      },
4666   { TYPE_EMPTY,         NULL,                   ""                      },
4667   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4668
4669   { 0,                  NULL,                   NULL                    }
4670 };
4671
4672 static struct TokenInfo setup_info_shortcuts_1[] =
4673 {
4674   { TYPE_KEYTEXT,       NULL,           "Quick Save Game to Tape:",     },
4675   { TYPE_KEY,           &setup.shortcut.save_game, ""                   },
4676   { TYPE_KEYTEXT,       NULL,           "Quick Load Game from Tape:",   },
4677   { TYPE_KEY,           &setup.shortcut.load_game, ""                   },
4678   { TYPE_KEYTEXT,       NULL,           "Start Game & Toggle Pause:",   },
4679   { TYPE_KEY,           &setup.shortcut.toggle_pause, ""                },
4680   { TYPE_EMPTY,         NULL,                   ""                      },
4681   { TYPE_YES_NO,        &setup.ask_on_escape,   "Ask on 'Esc' Key:"     },
4682   { TYPE_YES_NO, &setup.ask_on_escape_editor,   "Ask on 'Esc' Key (Editor):" },
4683   { TYPE_EMPTY,         NULL,                   ""                      },
4684   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4685
4686   { 0,                  NULL,                   NULL                    }
4687 };
4688
4689 static struct TokenInfo setup_info_shortcuts_2[] =
4690 {
4691   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 1:",       },
4692   { TYPE_KEY,           &setup.shortcut.focus_player[0], ""             },
4693   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 2:",       },
4694   { TYPE_KEY,           &setup.shortcut.focus_player[1], ""             },
4695   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 3:",       },
4696   { TYPE_KEY,           &setup.shortcut.focus_player[2], ""             },
4697   { TYPE_KEYTEXT,       NULL,           "Set Focus to Player 4:",       },
4698   { TYPE_KEY,           &setup.shortcut.focus_player[3], ""             },
4699   { TYPE_KEYTEXT,       NULL,           "Set Focus to All Players:",    },
4700   { TYPE_KEY,           &setup.shortcut.focus_player_all, ""            },
4701   { TYPE_EMPTY,         NULL,                   ""                      },
4702   { TYPE_LEAVE_MENU,    execSetupMain,          "Back"                  },
4703
4704   { 0,                  NULL,                   NULL                    }
4705 };
4706
4707 static Key getSetupKey()
4708 {
4709   Key key = KSYM_UNDEFINED;
4710   boolean got_key_event = FALSE;
4711
4712   while (!got_key_event)
4713   {
4714     if (PendingEvent())         /* got event */
4715     {
4716       Event event;
4717
4718       NextEvent(&event);
4719
4720       switch (event.type)
4721       {
4722         case EVENT_KEYPRESS:
4723           {
4724             key = GetEventKey((KeyEvent *)&event, TRUE);
4725
4726             /* press 'Escape' or 'Enter' to keep the existing key binding */
4727             if (key == KSYM_Escape || key == KSYM_Return)
4728               key = KSYM_UNDEFINED;     /* keep old value */
4729
4730             got_key_event = TRUE;
4731           }
4732           break;
4733
4734         case EVENT_KEYRELEASE:
4735           key_joystick_mapping = 0;
4736           break;
4737
4738         default:
4739           HandleOtherEvents(&event);
4740           break;
4741       }
4742     }
4743
4744     DoAnimation();
4745     BackToFront();
4746
4747     /* don't eat all CPU time */
4748     Delay(10);
4749   }
4750
4751   return key;
4752 }
4753
4754 static int getSetupTextFont(int type)
4755 {
4756   if (type & (TYPE_SWITCH |
4757               TYPE_YES_NO |
4758               TYPE_STRING |
4759               TYPE_ECS_AGA |
4760               TYPE_KEYTEXT |
4761               TYPE_ENTER_LIST))
4762     return FONT_MENU_2;
4763   else
4764     return FONT_MENU_1;
4765 }
4766
4767 static int getSetupValueFont(int type, void *value)
4768 {
4769   if (type & TYPE_KEY)
4770     return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4771   else if (type & TYPE_STRING)
4772     return FONT_VALUE_2;
4773   else if (type & TYPE_ECS_AGA)
4774     return FONT_VALUE_1;
4775   else if (type & TYPE_BOOLEAN_STYLE)
4776     return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4777   else
4778     return FONT_VALUE_1;
4779 }
4780
4781 static void drawSetupValue(int pos)
4782 {
4783   boolean font_draw_xoffset_modified = FALSE;
4784   int font_draw_xoffset_old = -1;
4785   int xpos = MENU_SCREEN_VALUE_XPOS;
4786   int ypos = MENU_SCREEN_START_YPOS + pos;
4787   int startx = mSX + xpos * 32;
4788   int starty = mSY + ypos * 32;
4789   int font_nr, font_width;
4790   int type = setup_info[pos].type;
4791   void *value = setup_info[pos].value;
4792   char *value_string = getSetupValue(type, value);
4793   int i;
4794
4795   if (value_string == NULL)
4796     return;
4797
4798   if (type & TYPE_KEY)
4799   {
4800     xpos = MENU_SCREEN_START_XPOS;
4801
4802     if (type & TYPE_QUERY)
4803     {
4804       value_string = "<press key>";
4805     }
4806   }
4807   else if (type & TYPE_STRING)
4808   {
4809     int max_value_len = (SCR_FIELDX - 2) * 2;
4810
4811     xpos = MENU_SCREEN_START_XPOS;
4812
4813     if (strlen(value_string) > max_value_len)
4814       value_string[max_value_len] = '\0';
4815   }
4816
4817   startx = mSX + xpos * 32;
4818   starty = mSY + ypos * 32;
4819   font_nr = getSetupValueFont(type, value);
4820   font_width = getFontWidth(font_nr);
4821
4822   /* downward compatibility correction for Juergen Bonhagen's menu settings */
4823   if (setup_mode != SETUP_MODE_INPUT)
4824   {
4825     int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4826     int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4827     int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4828     int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4829     int text_font_nr = getSetupTextFont(FONT_MENU_2);
4830     int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4831     int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4832     boolean correct_font_draw_xoffset = FALSE;
4833
4834     if (xpos == MENU_SCREEN_START_XPOS &&
4835         startx + font1_xoffset < text_startx + text_font_xoffset)
4836       correct_font_draw_xoffset = TRUE;
4837
4838     if (xpos == MENU_SCREEN_VALUE_XPOS &&
4839         startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4840       correct_font_draw_xoffset = TRUE;
4841
4842     /* check if setup value would overlap with setup text when printed */
4843     /* (this can happen for extreme/wrong values for font draw offset) */
4844     if (correct_font_draw_xoffset)
4845     {
4846       font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4847       font_draw_xoffset_modified = TRUE;
4848
4849       if (type & TYPE_KEY)
4850         getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4851       else if (!(type & TYPE_STRING))
4852         getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4853           MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4854     }
4855   }
4856
4857   for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4858     DrawText(startx + i * font_width, starty, " ", font_nr);
4859
4860   DrawText(startx, starty, value_string, font_nr);
4861
4862   if (font_draw_xoffset_modified)
4863     getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4864 }
4865
4866 static void changeSetupValue(int pos)
4867 {
4868   if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4869   {
4870     *(boolean *)setup_info[pos].value ^= TRUE;
4871   }
4872   else if (setup_info[pos].type & TYPE_KEY)
4873   {
4874     Key key;
4875
4876     setup_info[pos].type |= TYPE_QUERY;
4877     drawSetupValue(pos);
4878     setup_info[pos].type &= ~TYPE_QUERY;
4879
4880     key = getSetupKey();
4881     if (key != KSYM_UNDEFINED)
4882       *(Key *)setup_info[pos].value = key;
4883   }
4884
4885   drawSetupValue(pos);
4886 }
4887
4888 static void DrawCursorAndText_Setup(int pos, boolean active)
4889 {
4890   int xpos = MENU_SCREEN_START_XPOS;
4891   int ypos = MENU_SCREEN_START_YPOS + pos;
4892   int font_nr = getSetupTextFont(setup_info[pos].type);
4893
4894   if (setup_info == setup_info_input)
4895     font_nr = FONT_MENU_1;
4896
4897   if (active)
4898     font_nr = FONT_ACTIVE(font_nr);
4899
4900   DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4901
4902   if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4903     drawCursor(pos, active);
4904 }
4905
4906 static void DrawSetupScreen_Generic()
4907 {
4908   boolean redraw_all = FALSE;
4909   char *title_string = NULL;
4910   int i;
4911
4912   UnmapAllGadgets();
4913   CloseDoor(DOOR_CLOSE_2);
4914
4915   if (redraw_mask & REDRAW_ALL)
4916     redraw_all = TRUE;
4917
4918   printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4919                       redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4920                       int2str(0, redraw_mask)));
4921
4922 #if 1
4923   FadeOut(redraw_mask);
4924 #else
4925   FadeOut(REDRAW_FIELD);
4926 #endif
4927
4928   ClearWindow();
4929
4930   if (setup_mode == SETUP_MODE_MAIN)
4931   {
4932     setup_info = setup_info_main;
4933     title_string = "Setup";
4934   }
4935   else if (setup_mode == SETUP_MODE_GAME)
4936   {
4937     setup_info = setup_info_game;
4938     title_string = "Setup Game";
4939   }
4940   else if (setup_mode == SETUP_MODE_EDITOR)
4941   {
4942     setup_info = setup_info_editor;
4943     title_string = "Setup Editor";
4944   }
4945   else if (setup_mode == SETUP_MODE_GRAPHICS)
4946   {
4947     setup_info = setup_info_graphics;
4948     title_string = "Setup Graphics";
4949   }
4950   else if (setup_mode == SETUP_MODE_SOUND)
4951   {
4952     setup_info = setup_info_sound;
4953     title_string = "Setup Sound";
4954   }
4955   else if (setup_mode == SETUP_MODE_ARTWORK)
4956   {
4957     setup_info = setup_info_artwork;
4958     title_string = "Custom Artwork";
4959   }
4960   else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4961   {
4962     setup_info = setup_info_shortcuts_1;
4963     title_string = "Setup Shortcuts";
4964   }
4965   else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4966   {
4967     setup_info = setup_info_shortcuts_2;
4968     title_string = "Setup Shortcuts";
4969   }
4970
4971   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4972
4973   num_setup_info = 0;
4974   for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4975   {
4976     void *value_ptr = setup_info[i].value;
4977 #if 1
4978 #else
4979     int xpos = MENU_SCREEN_START_XPOS;
4980     int ypos = MENU_SCREEN_START_YPOS + i;
4981     int font_nr;
4982 #endif
4983
4984     /* set some entries to "unchangeable" according to other variables */
4985     if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4986         (value_ptr == &setup.sound_loops  && !audio.loops_available) ||
4987         (value_ptr == &setup.sound_music  && !audio.music_available) ||
4988         (value_ptr == &setup.fullscreen   && !video.fullscreen_available) ||
4989         (value_ptr == &screen_mode_text   && !video.fullscreen_available))
4990       setup_info[i].type |= TYPE_GHOSTED;
4991
4992     if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4993       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4994     else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4995       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4996     else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4997       initCursor(i, IMG_MENU_BUTTON);
4998
4999 #if 1
5000     DrawCursorAndText_Setup(i, FALSE);
5001 #else
5002     font_nr = getSetupTextFont(setup_info[i].type);
5003
5004     DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5005 #endif
5006
5007     if (setup_info[i].type & TYPE_VALUE)
5008       drawSetupValue(i);
5009
5010     num_setup_info++;
5011   }
5012
5013 #if 0
5014   DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5015                     "Joysticks deactivated in setup menu");
5016 #endif
5017
5018 #if 1
5019   HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5020 #endif
5021
5022   if (redraw_all)
5023     redraw_mask = REDRAW_ALL;
5024
5025 #if 1
5026   FadeIn(redraw_mask);
5027 #else
5028   FadeIn(REDRAW_FIELD);
5029 #endif
5030
5031   InitAnimation();
5032 #if 0
5033   HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5034 #endif
5035 }
5036
5037 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5038 {
5039   static int choice_store[MAX_SETUP_MODES];
5040   int choice = choice_store[setup_mode];        /* always starts with 0 */
5041   int x = 0;
5042   int y = choice;
5043
5044   if (button == MB_MENU_INITIALIZE)
5045   {
5046     /* advance to first valid menu entry */
5047     while (choice < num_setup_info &&
5048            setup_info[choice].type & TYPE_SKIP_ENTRY)
5049       choice++;
5050     choice_store[setup_mode] = choice;
5051
5052 #if 1
5053     DrawCursorAndText_Setup(choice, TRUE);
5054 #else
5055     drawCursor(choice, TRUE);
5056 #endif
5057
5058     return;
5059   }
5060   else if (button == MB_MENU_LEAVE)
5061   {
5062     PlaySound(SND_MENU_ITEM_SELECTING);
5063
5064     for (y = 0; y < num_setup_info; y++)
5065     {
5066       if (setup_info[y].type & TYPE_LEAVE_MENU)
5067       {
5068         void (*menu_callback_function)(void) = setup_info[y].value;
5069
5070         FadeSetLeaveMenu();
5071
5072         menu_callback_function();
5073
5074         break;  /* absolutely needed because function changes 'setup_info'! */
5075       }
5076     }
5077
5078     return;
5079   }
5080
5081   if (mx || my)         /* mouse input */
5082   {
5083     x = (mx - mSX) / 32;
5084     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5085   }
5086   else if (dx || dy)    /* keyboard input */
5087   {
5088     if (dx)
5089     {
5090       int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5091
5092       if (setup_info[choice].type & menu_navigation_type ||
5093           setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5094         button = MB_MENU_CHOICE;
5095     }
5096     else if (dy)
5097       y = choice + dy;
5098
5099     /* jump to next non-empty menu entry (up or down) */
5100     while (y > 0 && y < num_setup_info - 1 &&
5101            setup_info[y].type & TYPE_SKIP_ENTRY)
5102       y += dy;
5103   }
5104
5105   if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5106   {
5107     if (button)
5108     {
5109       if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5110       {
5111         PlaySound(SND_MENU_ITEM_ACTIVATING);
5112
5113 #if 1
5114         DrawCursorAndText_Setup(choice, FALSE);
5115         DrawCursorAndText_Setup(y, TRUE);
5116 #else
5117         drawCursor(choice, FALSE);
5118         drawCursor(y, TRUE);
5119 #endif
5120
5121         choice = choice_store[setup_mode] = y;
5122       }
5123     }
5124     else if (!(setup_info[y].type & TYPE_GHOSTED))
5125     {
5126       PlaySound(SND_MENU_ITEM_SELECTING);
5127
5128       /* when selecting key headline, execute function for key value change */
5129       if (setup_info[y].type & TYPE_KEYTEXT &&
5130           setup_info[y + 1].type & TYPE_KEY)
5131         y++;
5132
5133       /* when selecting string value, execute function for list selection */
5134       if (setup_info[y].type & TYPE_STRING && y > 0 &&
5135           setup_info[y - 1].type & TYPE_ENTER_LIST)
5136         y--;
5137
5138       if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5139       {
5140         void (*menu_callback_function)(void) = setup_info[y].value;
5141
5142         FadeSetFromType(setup_info[y].type);
5143
5144         menu_callback_function();
5145       }
5146       else
5147       {
5148         if (setup_info[y].type & TYPE_VALUE)
5149           changeSetupValue(y);
5150       }
5151     }
5152   }
5153 }
5154
5155 void DrawSetupScreen_Input()
5156 {
5157 #if 1
5158   int i;
5159 #endif
5160
5161 #if 1
5162   FadeOut(REDRAW_FIELD);
5163 #endif
5164
5165   ClearWindow();
5166
5167 #if 1
5168   setup_info = setup_info_input;
5169 #endif
5170
5171   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5172
5173 #if 1
5174   for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5175   {
5176     if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5177       initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5178     else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5179       initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5180     else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5181       initCursor(i, IMG_MENU_BUTTON);
5182
5183     DrawCursorAndText_Setup(i, FALSE);
5184   }
5185 #else
5186   initCursor(0,  IMG_MENU_BUTTON);
5187   initCursor(1,  IMG_MENU_BUTTON);
5188   initCursor(2,  IMG_MENU_BUTTON_ENTER_MENU);
5189   initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5190
5191   DrawText(mSX + 32, mSY +  2 * 32, "Player:", FONT_MENU_1);
5192   DrawText(mSX + 32, mSY +  3 * 32, "Device:", FONT_MENU_1);
5193   DrawText(mSX + 32, mSY + 15 * 32, "Back",   FONT_MENU_1);
5194 #endif
5195
5196 #if 0
5197   DeactivateJoystickForCalibration();
5198 #endif
5199 #if 1
5200   DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5201                     "Joysticks deactivated on this screen");
5202 #endif
5203
5204   /* create gadgets for setup input menu screen */
5205   FreeScreenGadgets();
5206   CreateScreenGadgets();
5207
5208   /* map gadgets for setup input menu screen */
5209   MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5210
5211   HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5212
5213 #if 1
5214   FadeIn(REDRAW_FIELD);
5215 #endif
5216
5217   InitAnimation();
5218 }
5219
5220 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5221 {
5222   if (device_name == NULL)
5223     return;
5224
5225   if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5226     device_nr = 0;
5227
5228   if (strlen(device_name) > 1)
5229   {
5230     char c1 = device_name[strlen(device_name) - 1];
5231     char c2 = device_name[strlen(device_name) - 2];
5232
5233     if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5234       device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5235   }
5236   else
5237     strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5238             strlen(device_name));
5239 }
5240
5241 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5242 {
5243   int i;
5244   static struct SetupKeyboardInfo custom_key;
5245   static struct
5246   {
5247     Key *key;
5248     char *text;
5249   } custom[] =
5250   {
5251     { &custom_key.left,  "Joystick Left"  },
5252     { &custom_key.right, "Joystick Right" },
5253     { &custom_key.up,    "Joystick Up"    },
5254     { &custom_key.down,  "Joystick Down"  },
5255     { &custom_key.snap,  "Button 1"       },
5256     { &custom_key.drop,  "Button 2"       }
5257   };
5258   static char *joystick_name[MAX_PLAYERS] =
5259   {
5260     "Joystick1",
5261     "Joystick2",
5262     "Joystick3",
5263     "Joystick4"
5264   };
5265   int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5266
5267   InitJoysticks();
5268
5269   custom_key = setup.input[player_nr].key;
5270
5271   DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5272            FONT_INPUT_1_ACTIVE);
5273
5274   ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5275                              TILEX, TILEY);
5276   DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5277                          PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5278
5279   if (setup.input[player_nr].use_joystick)
5280   {
5281     char *device_name = setup.input[player_nr].joy.device_name;
5282     char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5283     int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5284
5285     DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5286     DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5287   }
5288   else
5289   {
5290     DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5291     DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5292   }
5293
5294   DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5295
5296   drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5297   drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5298   drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5299   drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5300
5301   DrawText(mSX + 2 * 32, mSY +  6 * 32, ":", FONT_VALUE_OLD);
5302   DrawText(mSX + 2 * 32, mSY +  7 * 32, ":", FONT_VALUE_OLD);
5303   DrawText(mSX + 2 * 32, mSY +  8 * 32, ":", FONT_VALUE_OLD);
5304   DrawText(mSX + 2 * 32, mSY +  9 * 32, ":", FONT_VALUE_OLD);
5305   DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5306   DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5307
5308   for (i = 0; i < 6; i++)
5309   {
5310     int ypos = 6 + i + (i > 3 ? i-3 : 0);
5311
5312     DrawText(mSX + 3 * 32, mSY + ypos * 32,
5313              "              ", FONT_VALUE_1);
5314     DrawText(mSX + 3 * 32, mSY + ypos * 32,
5315              (setup.input[player_nr].use_joystick ?
5316               custom[i].text :
5317               getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5318   }
5319 }
5320
5321 static int input_player_nr = 0;
5322
5323 void HandleSetupScreen_Input_Player(int step, int direction)
5324 {
5325   int old_player_nr = input_player_nr;
5326   int new_player_nr;
5327
5328   new_player_nr = old_player_nr + step * direction;
5329   if (new_player_nr < 0)
5330     new_player_nr = 0;
5331   if (new_player_nr > MAX_PLAYERS - 1)
5332     new_player_nr = MAX_PLAYERS - 1;
5333
5334   if (new_player_nr != old_player_nr)
5335   {
5336     input_player_nr = new_player_nr;
5337
5338     drawPlayerSetupInputInfo(input_player_nr, FALSE);
5339   }
5340 }
5341
5342 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5343 {
5344   static int choice = 0;
5345   int x = 0;
5346   int y = choice;
5347   int pos_start  = SETUPINPUT_SCREEN_POS_START;
5348   int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5349   int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5350   int pos_end    = SETUPINPUT_SCREEN_POS_END;
5351
5352   if (button == MB_MENU_INITIALIZE)
5353   {
5354     drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5355
5356 #if 1
5357     DrawCursorAndText_Setup(choice, TRUE);
5358 #else
5359     drawCursor(choice, TRUE);
5360 #endif
5361
5362     return;
5363   }
5364   else if (button == MB_MENU_LEAVE)
5365   {
5366     setup_mode = SETUP_MODE_MAIN;
5367     DrawSetupScreen();
5368     InitJoysticks();
5369
5370     return;
5371   }
5372
5373   if (mx || my)         /* mouse input */
5374   {
5375     x = (mx - mSX) / 32;
5376     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5377   }
5378   else if (dx || dy)    /* keyboard input */
5379   {
5380     if (dx && choice == 0)
5381       x = (dx < 0 ? 10 : 12);
5382     else if ((dx && choice == 1) ||
5383              (dx == +1 && choice == 2) ||
5384              (dx == -1 && choice == pos_end))
5385       button = MB_MENU_CHOICE;
5386     else if (dy)
5387       y = choice + dy;
5388
5389     if (y >= pos_empty1 && y <= pos_empty2)
5390       y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5391   }
5392
5393   if (y == 0 && dx != 0 && button)
5394   {
5395     HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5396   }
5397   else if (IN_VIS_FIELD(x, y) &&
5398            y >= pos_start && y <= pos_end &&
5399            !(y >= pos_empty1 && y <= pos_empty2))
5400   {
5401     if (button)
5402     {
5403       if (y != choice)
5404       {
5405 #if 1
5406         DrawCursorAndText_Setup(choice, FALSE);
5407         DrawCursorAndText_Setup(y, TRUE);
5408
5409         drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5410 #else
5411         drawCursor(choice, FALSE);
5412         drawCursor(y, TRUE);
5413 #endif
5414
5415         choice = y;
5416       }
5417     }
5418     else
5419     {
5420       if (y == 1)
5421       {
5422         char *device_name = setup.input[input_player_nr].joy.device_name;
5423
5424         if (!setup.input[input_player_nr].use_joystick)
5425         {
5426           int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5427
5428           setJoystickDeviceToNr(device_name, new_device_nr);
5429           setup.input[input_player_nr].use_joystick = TRUE;
5430         }
5431         else
5432         {
5433           int device_nr = getJoystickNrFromDeviceName(device_name);
5434           int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5435
5436           if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5437             setup.input[input_player_nr].use_joystick = FALSE;
5438           else
5439             setJoystickDeviceToNr(device_name, new_device_nr);
5440         }
5441
5442         drawPlayerSetupInputInfo(input_player_nr, FALSE);
5443       }
5444       else if (y == 2)
5445       {
5446         if (setup.input[input_player_nr].use_joystick)
5447         {
5448           InitJoysticks();
5449           CalibrateJoystick(input_player_nr);
5450         }
5451         else
5452           CustomizeKeyboard(input_player_nr);
5453       }
5454       else if (y == pos_end)
5455       {
5456         InitJoysticks();
5457
5458         FadeSetLeaveMenu();
5459
5460         setup_mode = SETUP_MODE_MAIN;
5461         DrawSetupScreen();
5462       }
5463     }
5464   }
5465 }
5466
5467 void CustomizeKeyboard(int player_nr)
5468 {
5469   int i;
5470   int step_nr;
5471   boolean finished = FALSE;
5472   static struct SetupKeyboardInfo custom_key;
5473   static struct
5474   {
5475     Key *key;
5476     char *text;
5477   } customize_step[] =
5478   {
5479     { &custom_key.left,  "Move Left"    },
5480     { &custom_key.right, "Move Right"   },
5481     { &custom_key.up,    "Move Up"      },
5482     { &custom_key.down,  "Move Down"    },
5483     { &custom_key.snap,  "Snap Field"   },
5484     { &custom_key.drop,  "Drop Element" }
5485   };
5486
5487   /* read existing key bindings from player setup */
5488   custom_key = setup.input[player_nr].key;
5489
5490   FadeSetEnterMenu();
5491   FadeOut(REDRAW_FIELD);
5492
5493   ClearWindow();
5494
5495   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5496
5497 #if 0
5498   BackToFront();
5499   InitAnimation();
5500 #endif
5501
5502   step_nr = 0;
5503   DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5504            customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5505   DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5506            "Key:", FONT_INPUT_1_ACTIVE);
5507   DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5508            getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5509
5510 #if 1
5511   FadeIn(REDRAW_FIELD);
5512
5513   InitAnimation();
5514 #endif
5515
5516   while (!finished)
5517   {
5518     if (PendingEvent())         /* got event */
5519     {
5520       Event event;
5521
5522       NextEvent(&event);
5523
5524       switch (event.type)
5525       {
5526         case EVENT_KEYPRESS:
5527           {
5528             Key key = GetEventKey((KeyEvent *)&event, FALSE);
5529
5530             if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5531             {
5532               if (key == KSYM_Escape)
5533                 FadeSkipNextFadeIn();
5534
5535               finished = TRUE;
5536               break;
5537             }
5538
5539             /* all keys configured -- wait for "Escape" or "Return" key */
5540             if (step_nr == 6)
5541               break;
5542
5543             /* press 'Enter' to keep the existing key binding */
5544             if (key == KSYM_Return)
5545               key = *customize_step[step_nr].key;
5546
5547             /* check if key already used */
5548             for (i = 0; i < step_nr; i++)
5549               if (*customize_step[i].key == key)
5550                 break;
5551             if (i < step_nr)
5552               break;
5553
5554             /* got new key binding */
5555             *customize_step[step_nr].key = key;
5556             DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5557                      "             ", FONT_VALUE_1);
5558             DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5559                      getKeyNameFromKey(key), FONT_VALUE_1);
5560             step_nr++;
5561
5562             /* un-highlight last query */
5563             DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5564                      customize_step[step_nr - 1].text, FONT_MENU_1);
5565             DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5566                      "Key:", FONT_MENU_1);
5567
5568             /* press 'Enter' to leave */
5569             if (step_nr == 6)
5570             {
5571               DrawText(mSX + 16, mSY + 15 * 32 + 16,
5572                        "Press Enter", FONT_TITLE_1);
5573               break;
5574             }
5575
5576             /* query next key binding */
5577             DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5578                      customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5579             DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5580                      "Key:", FONT_INPUT_1_ACTIVE);
5581             DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5582                      getKeyNameFromKey(*customize_step[step_nr].key),
5583                      FONT_VALUE_OLD);
5584           }
5585           break;
5586
5587         case EVENT_KEYRELEASE:
5588           key_joystick_mapping = 0;
5589           break;
5590
5591         default:
5592           HandleOtherEvents(&event);
5593           break;
5594       }
5595     }
5596
5597     DoAnimation();
5598     BackToFront();
5599
5600     /* don't eat all CPU time */
5601     Delay(10);
5602   }
5603
5604   /* write new key bindings back to player setup */
5605   setup.input[player_nr].key = custom_key;
5606
5607   StopAnimation();
5608   DrawSetupScreen_Input();
5609 }
5610
5611 static boolean CalibrateJoystickMain(int player_nr)
5612 {
5613   int new_joystick_xleft = JOYSTICK_XMIDDLE;
5614   int new_joystick_xright = JOYSTICK_XMIDDLE;
5615   int new_joystick_yupper = JOYSTICK_YMIDDLE;
5616   int new_joystick_ylower = JOYSTICK_YMIDDLE;
5617   int new_joystick_xmiddle, new_joystick_ymiddle;
5618
5619   int joystick_fd = joystick.fd[player_nr];
5620   int x, y, last_x, last_y, xpos = 8, ypos = 3;
5621   boolean check[3][3];
5622   int check_remaining = 3 * 3;
5623   int joy_x, joy_y;
5624   int joy_value;
5625   int result = -1;
5626
5627   if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5628     return FALSE;
5629
5630   if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5631     return FALSE;
5632
5633   FadeSetEnterMenu();
5634   FadeOut(REDRAW_FIELD);
5635
5636   ClearWindow();
5637
5638   for (y = 0; y < 3; y++)
5639   {
5640     for (x = 0; x < 3; x++)
5641     {
5642       DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5643       check[x][y] = FALSE;
5644     }
5645   }
5646
5647   DrawTextSCentered(mSY - SY +  6 * 32, FONT_TITLE_1, "Rotate joystick");
5648   DrawTextSCentered(mSY - SY +  7 * 32, FONT_TITLE_1, "in all directions");
5649   DrawTextSCentered(mSY - SY +  9 * 32, FONT_TITLE_1, "if all balls");
5650   DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5651   DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5652   DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5653   DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5654
5655   joy_value = Joystick(player_nr);
5656   last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5657   last_y = (joy_value & JOY_UP   ? -1 : joy_value & JOY_DOWN  ? +1 : 0);
5658
5659   /* eventually uncalibrated center position (joystick could be uncentered) */
5660   if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5661     return FALSE;
5662
5663   new_joystick_xmiddle = joy_x;
5664   new_joystick_ymiddle = joy_y;
5665
5666   DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5667
5668 #if 1
5669   FadeIn(REDRAW_FIELD);
5670 #else
5671   BackToFront();
5672 #endif
5673
5674   while (Joystick(player_nr) & JOY_BUTTON);     /* wait for released button */
5675   InitAnimation();
5676
5677   while (result < 0)
5678   {
5679     if (PendingEvent())         /* got event */
5680     {
5681       Event event;
5682
5683       NextEvent(&event);
5684
5685       switch (event.type)
5686       {
5687         case EVENT_KEYPRESS:
5688           switch (GetEventKey((KeyEvent *)&event, TRUE))
5689           {
5690             case KSYM_Return:
5691               if (check_remaining == 0)
5692                 result = 1;
5693               break;
5694
5695             case KSYM_Escape:
5696               FadeSkipNextFadeIn();
5697               result = 0;
5698               break;
5699
5700             default:
5701               break;
5702           }
5703           break;
5704
5705         case EVENT_KEYRELEASE:
5706           key_joystick_mapping = 0;
5707           break;
5708
5709         default:
5710           HandleOtherEvents(&event);
5711           break;
5712       }
5713     }
5714
5715     if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5716       return FALSE;
5717
5718     new_joystick_xleft  = MIN(new_joystick_xleft,  joy_x);
5719     new_joystick_xright = MAX(new_joystick_xright, joy_x);
5720     new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5721     new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5722
5723     setup.input[player_nr].joy.xleft = new_joystick_xleft;
5724     setup.input[player_nr].joy.yupper = new_joystick_yupper;
5725     setup.input[player_nr].joy.xright = new_joystick_xright;
5726     setup.input[player_nr].joy.ylower = new_joystick_ylower;
5727     setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5728     setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5729
5730     CheckJoystickData();
5731
5732     joy_value = Joystick(player_nr);
5733
5734     if (joy_value & JOY_BUTTON && check_remaining == 0)
5735       result = 1;
5736
5737     x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5738     y = (joy_value & JOY_UP   ? -1 : joy_value & JOY_DOWN  ? +1 : 0);
5739
5740     if (x != last_x || y != last_y)
5741     {
5742       DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5743       DrawGraphic(xpos + x,      ypos + y,      IMG_MENU_CALIBRATE_RED,    0);
5744
5745       last_x = x;
5746       last_y = y;
5747
5748       if (check_remaining > 0 && !check[x+1][y+1])
5749       {
5750         check[x+1][y+1] = TRUE;
5751         check_remaining--;
5752       }
5753
5754 #if 0
5755 #ifdef DEBUG
5756       printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5757              setup.input[player_nr].joy.xleft,
5758              setup.input[player_nr].joy.xmiddle,
5759              setup.input[player_nr].joy.xright);
5760       printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5761              setup.input[player_nr].joy.yupper,
5762              setup.input[player_nr].joy.ymiddle,
5763              setup.input[player_nr].joy.ylower);
5764 #endif
5765 #endif
5766
5767     }
5768
5769     DoAnimation();
5770     BackToFront();
5771
5772     /* don't eat all CPU time */
5773     Delay(10);
5774   }
5775
5776   /* calibrated center position (joystick should now be centered) */
5777   if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5778     return FALSE;
5779
5780   new_joystick_xmiddle = joy_x;
5781   new_joystick_ymiddle = joy_y;
5782
5783   StopAnimation();
5784
5785 #if 0
5786   DrawSetupScreen_Input();
5787 #endif
5788
5789   /* wait until the last pressed button was released */
5790   while (Joystick(player_nr) & JOY_BUTTON)
5791   {
5792     if (PendingEvent())         /* got event */
5793     {
5794       Event event;
5795
5796       NextEvent(&event);
5797       HandleOtherEvents(&event);
5798
5799       Delay(10);
5800     }
5801   }
5802
5803   return TRUE;
5804 }
5805
5806 void CalibrateJoystick(int player_nr)
5807 {
5808   if (!CalibrateJoystickMain(player_nr))
5809   {
5810     char *device_name = setup.input[player_nr].joy.device_name;
5811     int nr = getJoystickNrFromDeviceName(device_name) + 1;
5812     int xpos = mSX - SX;
5813     int ypos = mSY - SY;
5814
5815     ClearWindow();
5816
5817     DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, "   JOYSTICK %d   ", nr);
5818     DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5819     BackToFront();
5820
5821     Delay(2000);                /* show error message for a short time */
5822
5823     ClearEventQueue();
5824   }
5825
5826 #if 1
5827   DrawSetupScreen_Input();
5828 #endif
5829 }
5830
5831 void DrawSetupScreen()
5832 {
5833   DeactivateJoystick();
5834
5835   SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5836
5837   if (setup_mode == SETUP_MODE_INPUT)
5838     DrawSetupScreen_Input();
5839   else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5840     DrawChooseTree(&game_speed_current);
5841   else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5842     DrawChooseTree(&screen_mode_current);
5843   else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5844     DrawChooseTree(&scroll_delay_current);
5845   else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5846     DrawChooseTree(&artwork.gfx_current);
5847   else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5848     DrawChooseTree(&artwork.snd_current);
5849   else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5850     DrawChooseTree(&artwork.mus_current);
5851   else
5852     DrawSetupScreen_Generic();
5853
5854   PlayMenuSound();
5855   PlayMenuMusic();
5856 }
5857
5858 void RedrawSetupScreenAfterFullscreenToggle()
5859 {
5860   if (setup_mode == SETUP_MODE_GRAPHICS)
5861     DrawSetupScreen();
5862 }
5863
5864 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5865 {
5866   if (setup_mode == SETUP_MODE_INPUT)
5867     HandleSetupScreen_Input(mx, my, dx, dy, button);
5868   else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5869     HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5870   else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5871     HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5872   else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5873     HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5874   else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5875     HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5876   else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5877     HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5878   else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5879     HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5880   else
5881     HandleSetupScreen_Generic(mx, my, dx, dy, button);
5882
5883   DoAnimation();
5884 }
5885
5886 void HandleGameActions()
5887 {
5888   if (game_status != GAME_MODE_PLAYING)
5889     return;
5890
5891   GameActions();        /* main game loop */
5892
5893   if (tape.auto_play && !tape.playing)
5894     AutoPlayTape();     /* continue automatically playing next tape */
5895 }
5896
5897
5898 /* ---------- new screen button stuff -------------------------------------- */
5899
5900 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5901 {
5902   switch (gadget_id)
5903   {
5904 #if 1
5905     case SCREEN_CTRL_ID_PREV_LEVEL:
5906       *x = mSX + menu.main.button.prev_level.x;
5907       *y = mSY + menu.main.button.prev_level.y;
5908       break;
5909
5910     case SCREEN_CTRL_ID_NEXT_LEVEL:
5911       *x = mSX + menu.main.button.next_level.x;
5912       *y = mSY + menu.main.button.next_level.y;
5913       break;
5914 #else
5915     case SCREEN_CTRL_ID_PREV_LEVEL:
5916       *x = mSX + TILEX * getPrevlevelButtonPos();
5917       *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5918       break;
5919
5920     case SCREEN_CTRL_ID_NEXT_LEVEL:
5921       *x = mSX + TILEX * getNextLevelButtonPos();
5922       *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5923       break;
5924 #endif
5925
5926     case SCREEN_CTRL_ID_PREV_PLAYER:
5927       *x = mSX + TILEX * 10;
5928       *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5929       break;
5930
5931     case SCREEN_CTRL_ID_NEXT_PLAYER:
5932       *x = mSX + TILEX * 12;
5933       *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5934       break;
5935
5936     default:
5937       Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5938   }
5939 }
5940
5941 static struct
5942 {
5943   int gfx_unpressed, gfx_pressed;
5944   void (*get_gadget_position)(int *, int *, int);
5945   int gadget_id;
5946   int screen_mask;
5947   char *infotext;
5948 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5949 {
5950   {
5951     IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5952     getScreenMenuButtonPos,
5953     SCREEN_CTRL_ID_PREV_LEVEL,
5954     SCREEN_MASK_MAIN,
5955     "last level"
5956   },
5957   {
5958     IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5959     getScreenMenuButtonPos,
5960     SCREEN_CTRL_ID_NEXT_LEVEL,
5961     SCREEN_MASK_MAIN,
5962     "next level"
5963   },
5964   {
5965     IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5966     getScreenMenuButtonPos,
5967     SCREEN_CTRL_ID_PREV_PLAYER,
5968     SCREEN_MASK_INPUT,
5969     "last player"
5970   },
5971   {
5972     IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5973     getScreenMenuButtonPos,
5974     SCREEN_CTRL_ID_NEXT_PLAYER,
5975     SCREEN_MASK_INPUT,
5976     "next player"
5977   },
5978 };
5979
5980 static struct
5981 {
5982   int gfx_unpressed, gfx_pressed;
5983   int x, y;
5984   int gadget_id;
5985   char *infotext;
5986 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5987 {
5988   {
5989     IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5990     SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5991     SCREEN_CTRL_ID_SCROLL_UP,
5992     "scroll up"
5993   },
5994   {
5995     IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5996     SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5997     SCREEN_CTRL_ID_SCROLL_DOWN,
5998     "scroll down"
5999   }
6000 };
6001
6002 static struct
6003 {
6004 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6005   Bitmap **gfx_unpressed, **gfx_pressed;
6006 #else
6007   int gfx_unpressed, gfx_pressed;
6008 #endif
6009   int x, y;
6010   int width, height;
6011   int type;
6012   int gadget_id;
6013   char *infotext;
6014 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6015 {
6016   {
6017 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6018     &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6019 #else
6020     IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6021 #endif
6022     SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6023     SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6024     GD_TYPE_SCROLLBAR_VERTICAL,
6025     SCREEN_CTRL_ID_SCROLL_VERTICAL,
6026     "scroll level series vertically"
6027   }
6028 };
6029
6030 static void CreateScreenMenubuttons()
6031 {
6032   struct GadgetInfo *gi;
6033   unsigned long event_mask;
6034   int i;
6035
6036   for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6037   {
6038     Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6039     int gfx_unpressed, gfx_pressed;
6040     int x, y, width, height;
6041     int gd_x1, gd_x2, gd_y1, gd_y2;
6042     int id = menubutton_info[i].gadget_id;
6043
6044     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6045
6046     menubutton_info[i].get_gadget_position(&x, &y, id);
6047
6048     width = SC_MENUBUTTON_XSIZE;
6049     height = SC_MENUBUTTON_YSIZE;
6050
6051     gfx_unpressed = menubutton_info[i].gfx_unpressed;
6052     gfx_pressed   = menubutton_info[i].gfx_pressed;
6053     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6054     gd_bitmap_pressed   = graphic_info[gfx_pressed].bitmap;
6055     gd_x1 = graphic_info[gfx_unpressed].src_x;
6056     gd_y1 = graphic_info[gfx_unpressed].src_y;
6057     gd_x2 = graphic_info[gfx_pressed].src_x;
6058     gd_y2 = graphic_info[gfx_pressed].src_y;
6059
6060     gi = CreateGadget(GDI_CUSTOM_ID, id,
6061                       GDI_CUSTOM_TYPE_ID, i,
6062                       GDI_INFO_TEXT, menubutton_info[i].infotext,
6063                       GDI_X, x,
6064                       GDI_Y, y,
6065                       GDI_WIDTH, width,
6066                       GDI_HEIGHT, height,
6067                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6068                       GDI_STATE, GD_BUTTON_UNPRESSED,
6069                       GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6070                       GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6071                       GDI_DIRECT_DRAW, FALSE,
6072                       GDI_EVENT_MASK, event_mask,
6073                       GDI_CALLBACK_ACTION, HandleScreenGadgets,
6074                       GDI_END);
6075
6076     if (gi == NULL)
6077       Error(ERR_EXIT, "cannot create gadget");
6078
6079     screen_gadget[id] = gi;
6080   }
6081 }
6082
6083 static void CreateScreenScrollbuttons()
6084 {
6085   struct GadgetInfo *gi;
6086   unsigned long event_mask;
6087   int i;
6088
6089   for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6090   {
6091     Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6092     int gfx_unpressed, gfx_pressed;
6093     int x, y, width, height;
6094     int gd_x1, gd_x2, gd_y1, gd_y2;
6095     int id = scrollbutton_info[i].gadget_id;
6096
6097     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6098
6099     x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6100     y = mSY + scrollbutton_info[i].y;
6101     width = SC_SCROLLBUTTON_XSIZE;
6102     height = SC_SCROLLBUTTON_YSIZE;
6103
6104     if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6105       y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6106                  (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6107
6108     gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6109     gfx_pressed   = scrollbutton_info[i].gfx_pressed;
6110     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6111     gd_bitmap_pressed   = graphic_info[gfx_pressed].bitmap;
6112     gd_x1 = graphic_info[gfx_unpressed].src_x;
6113     gd_y1 = graphic_info[gfx_unpressed].src_y;
6114     gd_x2 = graphic_info[gfx_pressed].src_x;
6115     gd_y2 = graphic_info[gfx_pressed].src_y;
6116
6117     gi = CreateGadget(GDI_CUSTOM_ID, id,
6118                       GDI_CUSTOM_TYPE_ID, i,
6119                       GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6120                       GDI_X, x,
6121                       GDI_Y, y,
6122                       GDI_WIDTH, width,
6123                       GDI_HEIGHT, height,
6124                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6125                       GDI_STATE, GD_BUTTON_UNPRESSED,
6126                       GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6127                       GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6128                       GDI_DIRECT_DRAW, FALSE,
6129                       GDI_EVENT_MASK, event_mask,
6130                       GDI_CALLBACK_ACTION, HandleScreenGadgets,
6131                       GDI_END);
6132
6133     if (gi == NULL)
6134       Error(ERR_EXIT, "cannot create gadget");
6135
6136     screen_gadget[id] = gi;
6137   }
6138 }
6139
6140 static void CreateScreenScrollbars()
6141 {
6142   int i;
6143
6144   for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6145   {
6146     Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6147 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6148     int gfx_unpressed, gfx_pressed;
6149 #endif
6150     int x, y, width, height;
6151     int gd_x1, gd_x2, gd_y1, gd_y2;
6152     struct GadgetInfo *gi;
6153     int items_max, items_visible, item_position;
6154     unsigned long event_mask;
6155     int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6156     int id = scrollbar_info[i].gadget_id;
6157
6158     event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6159
6160     x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6161     y = mSY + scrollbar_info[i].y;
6162     width  = scrollbar_info[i].width;
6163     height = scrollbar_info[i].height;
6164
6165     if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6166       height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6167
6168     items_max = num_page_entries;
6169     items_visible = num_page_entries;
6170     item_position = 0;
6171
6172 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6173     gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6174     gd_bitmap_pressed   = *scrollbar_info[i].gfx_pressed;
6175     gd_x1 = 0;
6176     gd_y1 = 0;
6177     gd_x2 = 0;
6178     gd_y2 = 0;
6179 #else
6180     gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6181     gfx_pressed   = scrollbar_info[i].gfx_pressed;
6182     gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6183     gd_bitmap_pressed   = graphic_info[gfx_pressed].bitmap;
6184     gd_x1 = graphic_info[gfx_unpressed].src_x;
6185     gd_y1 = graphic_info[gfx_unpressed].src_y;
6186     gd_x2 = graphic_info[gfx_pressed].src_x;
6187     gd_y2 = graphic_info[gfx_pressed].src_y;
6188 #endif
6189
6190     gi = CreateGadget(GDI_CUSTOM_ID, id,
6191                       GDI_CUSTOM_TYPE_ID, i,
6192                       GDI_INFO_TEXT, scrollbar_info[i].infotext,
6193                       GDI_X, x,
6194                       GDI_Y, y,
6195                       GDI_WIDTH, width,
6196                       GDI_HEIGHT, height,
6197                       GDI_TYPE, scrollbar_info[i].type,
6198                       GDI_SCROLLBAR_ITEMS_MAX, items_max,
6199                       GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6200                       GDI_SCROLLBAR_ITEM_POSITION, item_position,
6201 #if 1
6202                       GDI_WHEEL_AREA_X, SX,
6203                       GDI_WHEEL_AREA_Y, SY,
6204                       GDI_WHEEL_AREA_WIDTH, SXSIZE,
6205                       GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6206 #else
6207                       GDI_WHEEL_AREA_X, 0,
6208                       GDI_WHEEL_AREA_Y, 0,
6209                       GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6210                       GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6211 #endif
6212                       GDI_STATE, GD_BUTTON_UNPRESSED,
6213                       GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6214                       GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6215                       GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6216                       GDI_DIRECT_DRAW, FALSE,
6217                       GDI_EVENT_MASK, event_mask,
6218                       GDI_CALLBACK_ACTION, HandleScreenGadgets,
6219                       GDI_END);
6220
6221     if (gi == NULL)
6222       Error(ERR_EXIT, "cannot create gadget");
6223
6224     screen_gadget[id] = gi;
6225   }
6226 }
6227
6228 void CreateScreenGadgets()
6229 {
6230   int last_game_status = game_status;   /* save current game status */
6231
6232 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6233   int i;
6234
6235   for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6236   {
6237     scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6238
6239     /* copy pointers to clip mask and GC */
6240     scrollbar_bitmap[i]->clip_mask =
6241       graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6242     scrollbar_bitmap[i]->stored_clip_gc =
6243       graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6244
6245     BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6246                scrollbar_bitmap[i],
6247                graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6248                graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6249                TILEX, TILEY, 0, 0);
6250   }
6251 #endif
6252
6253   CreateScreenMenubuttons();
6254
6255 #if 0
6256   /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6257   game_status = GAME_MODE_LEVELS;
6258 #endif
6259
6260   CreateScreenScrollbuttons();
6261   CreateScreenScrollbars();
6262
6263   game_status = last_game_status;       /* restore current game status */
6264 }
6265
6266 void FreeScreenGadgets()
6267 {
6268   int i;
6269
6270 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6271   for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6272   {
6273     /* prevent freeing clip mask and GC twice */
6274     scrollbar_bitmap[i]->clip_mask = None;
6275     scrollbar_bitmap[i]->stored_clip_gc = None;
6276
6277     FreeBitmap(scrollbar_bitmap[i]);
6278   }
6279 #endif
6280
6281   for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6282     FreeGadget(screen_gadget[i]);
6283 }
6284
6285 void MapScreenMenuGadgets(int screen_mask)
6286 {
6287   int i;
6288
6289   for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6290     if (screen_mask & menubutton_info[i].screen_mask)
6291       MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6292 }
6293
6294 void MapScreenTreeGadgets(TreeInfo *ti)
6295 {
6296   int num_entries = numTreeInfoInGroup(ti);
6297   int i;
6298
6299   if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6300     return;
6301
6302   for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6303     MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6304
6305   for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6306     MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6307 }
6308
6309 static void HandleScreenGadgets(struct GadgetInfo *gi)
6310 {
6311   int id = gi->custom_id;
6312   int button = gi->event.button;
6313   int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6314
6315   switch (id)
6316   {
6317     case SCREEN_CTRL_ID_PREV_LEVEL:
6318       HandleMainMenu_SelectLevel(step, -1);
6319       break;
6320
6321     case SCREEN_CTRL_ID_NEXT_LEVEL:
6322       HandleMainMenu_SelectLevel(step, +1);
6323       break;
6324
6325     case SCREEN_CTRL_ID_PREV_PLAYER:
6326       HandleSetupScreen_Input_Player(step, -1);
6327       break;
6328
6329     case SCREEN_CTRL_ID_NEXT_PLAYER:
6330       HandleSetupScreen_Input_Player(step, +1);
6331       break;
6332
6333     case SCREEN_CTRL_ID_SCROLL_UP:
6334       if (game_status == GAME_MODE_LEVELS)
6335         HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6336       else if (game_status == GAME_MODE_SETUP)
6337         HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6338       break;
6339
6340     case SCREEN_CTRL_ID_SCROLL_DOWN:
6341       if (game_status == GAME_MODE_LEVELS)
6342         HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6343       else if (game_status == GAME_MODE_SETUP)
6344         HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6345       break;
6346
6347     case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6348       if (game_status == GAME_MODE_LEVELS)
6349         HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6350       else if (game_status == GAME_MODE_SETUP)
6351         HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6352       break;
6353
6354     default:
6355       break;
6356   }
6357 }