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