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