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