1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
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
38 #define MAX_INFO_MODES 8
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
57 /* sub-screens on the setup screen (generic) */
58 #define SETUP_MODE_CHOOSE_ARTWORK 13
59 #define SETUP_MODE_CHOOSE_OTHER 14
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
74 #define MAX_SETUP_MODES 26
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)
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 - \
97 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
99 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
100 MENU_SCREEN_INFO_YSTEP, \
101 MAX_INFO_ELEMENTS_ON_SCREEN)
103 #define NUM_INFO_ELEMENTS_ON_SCREEN 10
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)
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
119 #define NUM_SCREEN_GADGETS 7
121 #define NUM_SCREEN_MENUBUTTONS 4
122 #define NUM_SCREEN_SCROLLBUTTONS 2
123 #define NUM_SCREEN_SCROLLBARS 1
125 #define SCREEN_MASK_MAIN (1 << 0)
126 #define SCREEN_MASK_INPUT (1 << 1)
128 /* graphic position and size values for buttons and scrollbars */
129 #define SC_MENUBUTTON_XSIZE TILEX
130 #define SC_MENUBUTTON_YSIZE TILEY
132 #define SC_SCROLLBUTTON_XSIZE TILEX
133 #define SC_SCROLLBUTTON_YSIZE TILEY
135 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
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)
141 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
142 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
144 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
145 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
146 SC_SCROLLBUTTON_YSIZE)
148 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
149 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
150 SC_SCROLL_VERTICAL_YSIZE)
152 #define SC_BORDER_SIZE 14
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 **);
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);
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);
185 static void MapScreenMenuGadgets(int);
186 static void MapScreenTreeGadgets(TreeInfo *);
188 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
190 static int info_mode = INFO_MODE_MAIN;
191 static int setup_mode = SETUP_MODE_MAIN;
193 static TreeInfo *screen_modes = NULL;
194 static TreeInfo *screen_mode_current = NULL;
196 static TreeInfo *window_sizes = NULL;
197 static TreeInfo *window_size_current = NULL;
199 static TreeInfo *scaling_types = NULL;
200 static TreeInfo *scaling_type_current = NULL;
202 static TreeInfo *scroll_delays = NULL;
203 static TreeInfo *scroll_delay_current = NULL;
205 static TreeInfo *game_speeds = NULL;
206 static TreeInfo *game_speed_current = NULL;
208 static TreeInfo *volumes_simple = NULL;
209 static TreeInfo *volume_simple_current = NULL;
211 static TreeInfo *volumes_loops = NULL;
212 static TreeInfo *volume_loops_current = NULL;
214 static TreeInfo *volumes_music = NULL;
215 static TreeInfo *volume_music_current = NULL;
217 static TreeInfo *level_number = NULL;
218 static TreeInfo *level_number_current = NULL;
224 } window_sizes_list[] =
229 { 100, "100 % (Default)" },
246 } scaling_types_list[] =
248 { SCALING_QUALITY_NEAREST, "None" },
249 { SCALING_QUALITY_LINEAR, "Linear" },
250 { SCALING_QUALITY_BEST, "Anisotropic" },
259 } game_speeds_list[] =
268 { 1000, "1/1s (Extremely Slow)" },
273 { 29, "1/35s (Original Supaplex)" },
275 { 20, "1/50s (Normal Speed)" },
276 { 14, "1/70s (Maximum Supaplex)" },
280 { 1, "1/1000s (Extremely Fast)" },
290 } scroll_delays_list[] =
292 { 0, "0 Tiles (No Scroll Delay)" },
295 { 3, "3 Tiles (Default)" },
300 { 8, "8 Tiles (Maximum Scroll Delay)"},
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)
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) : \
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)
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)])
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)])
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)])
368 #define mSX (SX + DRAW_XOFFSET(game_status))
369 #define mSY (SY + DRAW_YOFFSET(game_status))
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)
375 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
376 #define NUM_SCROLLBAR_BITMAPS 2
377 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
381 /* title display and control definitions */
383 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
384 2 * MAX_NUM_TITLE_MESSAGES)
386 static int num_title_screens = 0;
388 struct TitleControlInfo
396 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
398 /* main menu display and control definitions */
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
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];
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;
451 struct MainControlInfo
455 struct MenuPosInfo *pos_button;
458 struct TextPosInfo *pos_text;
461 struct TextPosInfo *pos_input;
465 static struct MainControlInfo main_controls[] =
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,
475 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
476 &menu.main.text.levels, &main_text_levels,
481 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
482 &menu.main.text.scores, &main_text_scores,
487 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
488 &menu.main.text.editor, &main_text_editor,
493 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
494 &menu.main.text.info, &main_text_info,
499 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
500 &menu.main.text.game, &main_text_game,
505 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
506 &menu.main.text.setup, &main_text_setup,
511 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
512 &menu.main.text.quit, &main_text_quit,
516 /* (these two buttons are real gadgets) */
518 MAIN_CONTROL_PREV_LEVEL,
519 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
524 MAIN_CONTROL_NEXT_LEVEL,
525 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
531 MAIN_CONTROL_FIRST_LEVEL,
533 &menu.main.text.first_level, &main_text_first_level,
537 MAIN_CONTROL_LAST_LEVEL,
539 &menu.main.text.last_level, &main_text_last_level,
543 MAIN_CONTROL_LEVEL_NUMBER,
545 &menu.main.text.level_number, &main_text_level_number,
549 MAIN_CONTROL_LEVEL_INFO_1,
551 &menu.main.text.level_info_1, NULL,
555 MAIN_CONTROL_LEVEL_INFO_2,
557 &menu.main.text.level_info_2, NULL,
561 MAIN_CONTROL_LEVEL_NAME,
563 &menu.main.text.level_name, &main_text_level_name,
567 MAIN_CONTROL_LEVEL_AUTHOR,
569 &menu.main.text.level_author, &main_text_level_author,
573 MAIN_CONTROL_LEVEL_YEAR,
575 &menu.main.text.level_year, &main_text_level_year,
579 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
581 &menu.main.text.level_imported_from, &main_text_level_imported_from,
585 MAIN_CONTROL_LEVEL_IMPORTED_BY,
587 &menu.main.text.level_imported_by, &main_text_level_imported_by,
591 MAIN_CONTROL_LEVEL_TESTED_BY,
593 &menu.main.text.level_tested_by, &main_text_level_tested_by,
597 MAIN_CONTROL_TITLE_1,
599 &menu.main.text.title_1, &main_text_title_1,
603 MAIN_CONTROL_TITLE_2,
605 &menu.main.text.title_2, &main_text_title_2,
609 MAIN_CONTROL_TITLE_3,
611 &menu.main.text.title_3, &main_text_title_3,
624 static int getTitleScreenGraphic(int nr, boolean initial)
626 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
629 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
631 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
635 static int getTitleScreenGameMode(boolean initial)
637 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
641 static int getTitleMessageGameMode(boolean initial)
643 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
647 static int getTitleScreenBackground(boolean initial)
649 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
654 static int getTitleMessageBackground(int nr, boolean initial)
656 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
660 static int getTitleBackground(int nr, boolean initial, boolean is_image)
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;
671 if (graphic_info[graphic_local].bitmap != NULL)
672 return graphic_local;
674 if (graphic_info[graphic_global].bitmap != NULL)
675 return graphic_global;
677 return IMG_UNDEFINED;
680 static int getTitleSound(struct TitleControlInfo *tci)
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;
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);
701 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
704 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
707 return SND_UNDEFINED;
710 static int getTitleMusic(struct TitleControlInfo *tci)
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;
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);
731 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
734 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
737 return MUS_UNDEFINED;
740 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
742 boolean is_image = tci->is_image;
743 int initial = tci->initial;
744 int nr = tci->local_nr;
745 struct TitleFadingInfo ti;
749 int graphic = getTitleScreenGraphic(nr, initial);
751 /* initialize fading control values to default title config settings */
752 ti = (initial ? title_initial_default : title_default);
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;
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;
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;
783 if (ti.anim_mode == ANIM_NONE)
784 ti.fade_delay = ti.post_delay = 0;
790 static int compareTitleControlInfo(const void *object1, const void *object2)
792 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
793 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
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);
803 compare_result = tci1->local_nr - tci2->local_nr;
805 return compare_result;
808 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
810 int nr, int sort_priority)
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;
820 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
824 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
826 int graphic = getTitleScreenGraphic(i, initial);
827 Bitmap *bitmap = graphic_info[graphic].bitmap;
828 int sort_priority = graphic_info[graphic].sort_priority;
831 /* skip images and messages (fonts!) when using forced custom graphics */
832 if (setup.override_level_graphics && !initial)
837 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
840 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
842 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
843 char *filename = getLevelSetTitleMessageFilename(i, initial);
844 int sort_priority = tmi->sort_priority;
847 /* skip images and messages (fonts!) when using forced custom graphics */
848 if (setup.override_level_graphics)
852 if (filename != NULL)
853 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
857 static void InitializeTitleControls(boolean show_title_initial)
859 num_title_screens = 0;
862 /* 1st step: initialize title screens for game start (only when starting) */
863 if (show_title_initial)
864 InitializeTitleControls_CheckTitleInfo(TRUE);
867 /* 2nd step: initialize title screens for current level set */
868 InitializeTitleControls_CheckTitleInfo(FALSE);
870 /* sort title screens according to sort_priority and title number */
871 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
872 compareTitleControlInfo);
875 static boolean visibleMenuPos(struct MenuPosInfo *pos)
877 return (pos != NULL && pos->x != -1 && pos->y != -1);
880 static boolean visibleTextPos(struct TextPosInfo *pos)
882 return (pos != NULL && pos->x != -1 && pos->y != -1);
885 static void InitializeMainControls()
887 boolean local_team_mode = (!options.network && setup.team_mode);
890 /* set main control text values to dynamically determined values */
891 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
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));
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;
905 /* set main control screen positions to dynamically determined values */
906 for (i = 0; main_controls[i].nr != -1; i++)
908 struct MainControlInfo *mci = &main_controls[i];
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;
917 int font_text = (pos_text ? pos_text->font : -1);
918 int font_input = (pos_input ? pos_input->font : -1);
920 int font_text = mci->font_text;
921 int font_input = mci->font_input;
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);
932 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
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;
940 if (nr == MAIN_CONTROL_NAME)
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;
950 menu.main.input.name.width = input_width;
951 menu.main.input.name.height = input_height;
953 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
954 menu.main.input.name.height = font_input_height;
958 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
960 if (pos_button->width == 0)
961 pos_button->width = button_width;
962 if (pos_button->height == 0)
963 pos_button->height = button_height;
966 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
969 /* calculate size for non-clickable text -- needed for text alignment */
970 boolean calculate_text_size = (pos_button == NULL && text != NULL);
972 /* calculate width for non-clickable text -- needed for text alignment */
973 boolean calculate_text_width = (pos_button == NULL && text != NULL);
976 if (visibleMenuPos(pos_button))
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;
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;
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;
997 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
999 if (visibleTextPos(pos_text))
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;
1007 if (pos_input->width == -1)
1008 pos_input->width = input_width;
1009 if (pos_input->height == -1)
1010 pos_input->height = input_height;
1015 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1016 boolean active_input)
1020 for (i = 0; main_controls[i].nr != -1; i++)
1022 struct MainControlInfo *mci = &main_controls[i];
1024 if (mci->nr == nr || nr == -1)
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;
1033 int font_text = (pos_text ? pos_text->font : -1);
1034 int font_input = (pos_input ? pos_input->font : -1);
1036 int font_text = mci->font_text;
1037 int font_input = mci->font_input;
1042 button_graphic = BUTTON_ACTIVE(button_graphic);
1043 font_text = FONT_ACTIVE(font_text);
1048 font_input = FONT_ACTIVE(font_input);
1051 if (visibleMenuPos(pos_button))
1053 struct MenuPosInfo *pos = pos_button;
1054 int x = mSX + pos->x;
1055 int y = mSY + pos->y;
1057 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1058 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1061 if (visibleTextPos(pos_text) && text != NULL)
1063 struct TextPosInfo *pos = pos_text;
1064 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1065 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1068 /* (check why/if this is needed) */
1069 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1071 DrawText(x, y, text, font_text);
1074 if (visibleTextPos(pos_input) && input != NULL)
1076 struct TextPosInfo *pos = pos_input;
1077 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1078 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1081 /* (check why/if this is needed) */
1082 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1084 DrawText(x, y, input, font_input);
1090 static void DrawCursorAndText_Main(int nr, boolean active_text)
1092 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1096 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1098 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1102 static struct MainControlInfo *getMainControlInfo(int nr)
1106 for (i = 0; main_controls[i].nr != -1; i++)
1107 if (main_controls[i].nr == nr)
1108 return &main_controls[i];
1113 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1118 int rect_x = ALIGNED_TEXT_XPOS(rect);
1119 int rect_y = ALIGNED_TEXT_YPOS(rect);
1121 return (x >= rect_x && x < rect_x + rect->width &&
1122 y >= rect_y && y < rect_y + rect->height);
1125 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1130 int rect_x = ALIGNED_TEXT_XPOS(rect);
1131 int rect_y = ALIGNED_TEXT_YPOS(rect);
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));
1140 return (x >= rect_x && x < rect_x + rect->width &&
1141 y >= rect_y && y < rect_y + rect->height);
1144 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1147 static int cursor_array[MAX_LEV_FIELDY];
1149 static int cursor_array[SCR_FIELDY];
1151 int x = mSX + TILEX * xpos;
1152 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1157 cursor_array[ypos] = graphic;
1159 graphic = cursor_array[ypos];
1163 graphic = BUTTON_ACTIVE(graphic);
1165 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1166 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1169 static void initCursor(int ypos, int graphic)
1171 drawCursorExt(0, ypos, FALSE, graphic);
1174 static void drawCursor(int ypos, boolean active)
1176 drawCursorExt(0, ypos, active, -1);
1179 static void drawCursorXY(int xpos, int ypos, int graphic)
1181 drawCursorExt(xpos, ypos, FALSE, graphic);
1184 static void drawChooseTreeCursor(int ypos, boolean active)
1186 int last_game_status = game_status; /* save current game status */
1189 /* force LEVELS draw offset on artwork setup screen */
1190 game_status = GAME_MODE_LEVELS;
1193 drawCursorExt(0, ypos, active, -1);
1195 game_status = last_game_status; /* restore current game status */
1200 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1201 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1205 static int getPrevlevelButtonPos()
1210 static int getCurrentLevelTextPos()
1212 return (getPrevlevelButtonPos() + 1);
1215 static int getNextLevelButtonPos()
1217 return getPrevlevelButtonPos() + 3 + 1;
1220 static int getLevelRangeTextPos()
1222 return getNextLevelButtonPos() + 1;
1226 int effectiveGameStatus()
1228 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1229 return GAME_MODE_TITLE;
1234 void DrawTitleScreenImage(int nr, boolean initial)
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;
1247 if (width > WIN_XSIZE)
1249 /* image width too large for window => center image horizontally */
1250 src_x = (width - WIN_XSIZE) / 2;
1254 if (height > WIN_YSIZE)
1256 /* image height too large for window => center image vertically */
1257 src_y = (height - WIN_YSIZE) / 2;
1261 /* always display title screens centered */
1262 dst_x = (WIN_XSIZE - width) / 2;
1263 dst_y = (WIN_YSIZE - height) / 2;
1265 SetDrawBackgroundMask(REDRAW_ALL);
1266 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1268 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1270 if (DrawingOnBackground(dst_x, dst_y))
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);
1276 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1278 redraw_mask = REDRAW_ALL;
1281 void DrawTitleScreenMessage(int nr, boolean initial)
1283 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1284 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1285 int last_game_status = game_status; /* save current game status */
1287 if (filename == NULL)
1290 /* force TITLE font on title message screen */
1291 game_status = getTitleMessageGameMode(initial);
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);
1297 tmi->width = tmi->chars * getFontWidth(tmi->font);
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);
1303 tmi->height = tmi->lines * getFontHeight(tmi->font);
1305 SetDrawBackgroundMask(REDRAW_ALL);
1306 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1308 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
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);
1314 game_status = last_game_status; /* restore current game status */
1317 void DrawTitleScreen()
1319 KeyboardAutoRepeatOff();
1322 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1325 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1330 boolean CheckTitleScreen(boolean levelset_has_changed)
1332 static boolean show_title_initial = TRUE;
1333 boolean show_titlescreen = FALSE;
1335 /* needed to be able to skip title screen, if no image or message defined */
1336 InitializeTitleControls(show_title_initial);
1338 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1339 show_titlescreen = TRUE;
1341 /* show initial title images and messages only once at program start */
1342 show_title_initial = FALSE;
1344 return (show_titlescreen && num_title_screens > 0);
1347 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1349 static LevelDirTree *leveldir_last_valid = NULL;
1350 boolean levelset_has_changed = FALSE;
1352 LimitScreenUpdates(FALSE);
1354 FadeSetLeaveScreen();
1356 /* do not fade out here -- function may continue and fade on editor screen */
1359 FadeSoundsAndMusic();
1361 KeyboardAutoRepeatOn();
1364 SetDrawDeactivationMask(REDRAW_NONE);
1365 SetDrawBackgroundMask(REDRAW_FIELD);
1367 audio.sound_deactivated = FALSE;
1371 /* needed if last screen was the playing screen, invoked from level editor */
1372 if (level_editor_test_game)
1374 game_status = GAME_MODE_EDITOR;
1380 /* needed if last screen was the setup screen and fullscreen state changed */
1381 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1382 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1384 /* leveldir_current may be invalid (level group, parent link) */
1385 if (!validLevelSeries(leveldir_current))
1386 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1388 if (leveldir_current != leveldir_last_valid)
1389 levelset_has_changed = TRUE;
1391 /* store valid level series information */
1392 leveldir_last_valid = leveldir_current;
1394 init_last = init; /* switch to new busy animation */
1396 /* needed if last screen (level choice) changed graphics, sounds or music */
1397 ReloadCustomArtwork(0);
1399 if (redraw_mask & REDRAW_ALL)
1400 fade_mask = REDRAW_ALL;
1406 /* needed if last screen was the editor screen */
1407 UndrawSpecialEditorDoor();
1411 if (fade_mask == REDRAW_FIELD)
1417 /* needed if different viewport properties defined for menues */
1418 ChangeViewportPropertiesIfNeeded();
1422 /* needed if last screen was the editor screen */
1423 UndrawSpecialEditorDoor();
1426 #if defined(TARGET_SDL)
1427 SetDrawtoField(DRAW_BACKBUFFER);
1430 if (CheckTitleScreen(levelset_has_changed))
1432 game_status = GAME_MODE_TITLE;
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;
1443 LoadLevel(level_nr);
1444 LoadScore(level_nr);
1446 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1449 if (fade_mask == REDRAW_ALL)
1451 // int door_state = GetDoorState();
1455 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1461 InitializeMainControls();
1463 DrawCursorAndText_Main(-1, FALSE);
1464 DrawPreviewLevelInitial();
1466 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1469 if (TAPE_IS_EMPTY(tape))
1471 DrawCompleteVideoDisplay();
1476 /* create gadgets for main menu screen */
1477 FreeScreenGadgets();
1478 CreateScreenGadgets();
1480 /* map gadgets for main menu screen */
1482 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
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);
1490 if (fade_mask == REDRAW_ALL)
1492 int door_state = GetDoorState();
1494 // RedrawBackground();
1496 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1500 DrawMaskedBorder(REDRAW_ALL);
1506 /* update screen area with special editor door */
1507 redraw_mask |= REDRAW_ALL;
1511 SetMouseCursor(CURSOR_DEFAULT);
1515 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1518 void DrawAndFadeInMainMenu(int fade_mask)
1520 DrawMainMenuExt(fade_mask, TRUE);
1525 DrawMainMenuExt(REDRAW_ALL, FALSE);
1528 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1529 static void gotoTopLevelDir()
1531 /* move upwards to top level directory */
1532 while (leveldir_current->node_parent)
1534 /* write a "path" into level tree for easy navigation to last level */
1535 if (leveldir_current->node_parent->node_group->cl_first == -1)
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;
1542 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1543 num_page_entries = num_leveldirs;
1545 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1547 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1548 cl_cursor = leveldir_pos - cl_first;
1550 leveldir_current->node_parent->node_group->cl_first = cl_first;
1551 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1554 leveldir_current = leveldir_current->node_parent;
1559 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
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;
1572 if (button == MB_MENU_INITIALIZE)
1575 title_screen_nr = 0;
1576 tci = &title_controls[title_screen_nr];
1578 last_sound = SND_UNDEFINED;
1579 last_music = MUS_UNDEFINED;
1581 if (game_status == GAME_MODE_INFO)
1583 if (num_title_screens == 0)
1585 DrawInfoScreen_NotAvailable("Title screen information:",
1586 "No title screen for this level set.");
1591 FadeSoundsAndMusic();
1594 FadeOut(REDRAW_ALL);
1599 DrawTitleScreenImage(tci->local_nr, tci->initial);
1601 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1603 fading_default = (tci->initial ? title_initial_default : title_default);
1605 fading = fading_next = getTitleFading(tci);
1609 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1610 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1612 fading.fade_mode = FADE_MODE_FADE;
1613 fading.fade_delay = fading_default.fade_delay;
1616 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1617 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1618 fading.fade_mode = FADE_MODE_FADE;
1623 sound = getTitleSound(tci);
1624 music = getTitleMusic(tci);
1626 if (sound != last_sound)
1627 PlayMenuSoundExt(sound);
1628 if (music != last_music)
1629 PlayMenuMusicExt(music);
1635 SetMouseCursor(CURSOR_NONE);
1641 fading = fading_next;
1643 DelayReached(&title_delay, 0); /* reset delay counter */
1649 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1650 button = MB_MENU_CHOICE;
1652 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1653 button = MB_MENU_CHOICE;
1656 if (button == MB_MENU_LEAVE)
1658 return_to_main_menu = TRUE;
1659 use_fading_main_menu = FALSE;
1661 else if (button == MB_MENU_CHOICE)
1663 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1666 FadeOut(REDRAW_FIELD);
1669 FadeSetEnterScreen();
1671 info_mode = INFO_MODE_MAIN;
1672 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1678 tci = &title_controls[title_screen_nr];
1680 if (title_screen_nr < num_title_screens)
1682 sound = getTitleSound(tci);
1683 music = getTitleMusic(tci);
1685 if (sound == SND_UNDEFINED || sound != last_sound)
1687 if (music == MUS_UNDEFINED || music != last_music)
1691 FadeOut(REDRAW_ALL);
1695 DrawTitleScreenImage(tci->local_nr, tci->initial);
1697 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1699 fading_next = getTitleFading(tci);
1702 sound = getTitleSound(tci);
1703 music = getTitleMusic(tci);
1705 if (sound != last_sound)
1706 PlayMenuSoundExt(sound);
1707 if (music != last_music)
1708 PlayMenuMusicExt(music);
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;
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;
1730 fading = fading_next;
1732 DelayReached(&title_delay, 0); /* reset delay counter */
1736 FadeSoundsAndMusic();
1738 return_to_main_menu = TRUE;
1742 if (return_to_main_menu)
1748 SetMouseCursor(CURSOR_DEFAULT);
1750 if (game_status == GAME_MODE_INFO)
1753 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1756 info_mode = INFO_MODE_MAIN;
1757 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1759 else /* default: return to main menu */
1762 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1765 game_status = GAME_MODE_MAIN;
1766 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1771 void HandleMainMenu_SelectLevel(int step, int direction)
1773 int old_level_nr = level_nr;
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;
1782 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
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))
1788 leveldir_current->handicap_level++;
1789 SaveLevelSetup_SeriesInfo();
1792 new_level_nr = leveldir_current->handicap_level;
1795 if (new_level_nr != old_level_nr)
1797 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1799 PlaySound(SND_MENU_ITEM_SELECTING);
1801 level_nr = new_level_nr;
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);
1807 LoadLevel(level_nr);
1808 DrawPreviewLevelInitial();
1812 DrawCompleteVideoDisplay();
1814 /* needed because DrawPreviewLevelInitial() takes some time */
1820 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1822 static int choice = MAIN_CONTROL_GAME;
1826 if (button == MB_MENU_INITIALIZE)
1828 DrawCursorAndText_Main(choice, TRUE);
1833 if (mx || my) /* mouse input */
1837 for (i = 0; main_controls[i].nr != -1; i++)
1840 printf("::: check click (%d, %d) for %d [%d] ...\n",
1841 mx - mSX, my - mSY, i, main_controls[i].nr);
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))
1849 printf("::: inside %d\n", i);
1852 pos = main_controls[i].nr;
1858 else if (dx || dy) /* keyboard input */
1860 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1861 choice == MAIN_CONTROL_SETUP))
1862 button = MB_MENU_CHOICE;
1867 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1869 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1871 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1873 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1875 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1877 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1879 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1881 game_status = GAME_MODE_LEVELNR;
1884 ChangeViewportPropertiesIfNeeded();
1887 DrawChooseLevelNr();
1889 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1895 PlaySound(SND_MENU_ITEM_ACTIVATING);
1897 DrawCursorAndText_Main(choice, FALSE);
1898 DrawCursorAndText_Main(pos, TRUE);
1905 PlaySound(SND_MENU_ITEM_SELECTING);
1907 if (pos == MAIN_CONTROL_NAME)
1909 game_status = GAME_MODE_PSEUDO_TYPENAME;
1911 HandleTypeName(strlen(setup.player_name), 0);
1913 else if (pos == MAIN_CONTROL_LEVELS)
1917 game_status = GAME_MODE_LEVELS;
1919 SaveLevelSetup_LastSeries();
1920 SaveLevelSetup_SeriesInfo();
1922 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1927 ChangeViewportPropertiesIfNeeded();
1930 DrawChooseLevelSet();
1933 else if (pos == MAIN_CONTROL_SCORES)
1935 game_status = GAME_MODE_SCORES;
1938 ChangeViewportPropertiesIfNeeded();
1943 else if (pos == MAIN_CONTROL_EDITOR)
1945 if (leveldir_current->readonly &&
1946 !strEqual(setup.player_name, "Artsoft"))
1947 Request("This level is read only!", REQ_CONFIRM);
1949 CloseDoor(DOOR_CLOSE_2);
1951 game_status = GAME_MODE_EDITOR;
1953 FadeSetEnterScreen();
1956 /* needed if different viewport properties defined for editor */
1957 ChangeViewportPropertiesIfNeeded();
1962 else if (pos == MAIN_CONTROL_INFO)
1964 game_status = GAME_MODE_INFO;
1965 info_mode = INFO_MODE_MAIN;
1968 ChangeViewportPropertiesIfNeeded();
1973 else if (pos == MAIN_CONTROL_GAME)
1975 StartGameActions(options.network, setup.autorecord, level.random_seed);
1977 else if (pos == MAIN_CONTROL_SETUP)
1979 game_status = GAME_MODE_SETUP;
1980 setup_mode = SETUP_MODE_MAIN;
1983 ChangeViewportPropertiesIfNeeded();
1988 else if (pos == MAIN_CONTROL_QUIT)
1990 SaveLevelSetup_LastSeries();
1991 SaveLevelSetup_SeriesInfo();
1993 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1994 game_status = GAME_MODE_QUIT;
2000 if (game_status == GAME_MODE_MAIN)
2002 DrawPreviewLevelAnimation();
2009 /* ========================================================================= */
2010 /* info screen functions */
2011 /* ========================================================================= */
2013 static struct TokenInfo *info_info;
2014 static int num_info_info;
2016 static void execInfoTitleScreen()
2018 info_mode = INFO_MODE_TITLE;
2023 static void execInfoElements()
2025 info_mode = INFO_MODE_ELEMENTS;
2030 static void execInfoMusic()
2032 info_mode = INFO_MODE_MUSIC;
2037 static void execInfoCredits()
2039 info_mode = INFO_MODE_CREDITS;
2044 static void execInfoProgram()
2046 info_mode = INFO_MODE_PROGRAM;
2051 static void execInfoVersion()
2053 info_mode = INFO_MODE_VERSION;
2058 static void execInfoLevelSet()
2060 info_mode = INFO_MODE_LEVELSET;
2065 static void execExitInfo()
2067 game_status = GAME_MODE_MAIN;
2069 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2072 static struct TokenInfo info_info_main[] =
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" },
2087 static void DrawCursorAndText_Info(int pos, boolean active)
2089 int xpos = MENU_SCREEN_START_XPOS;
2090 int ypos = MENU_SCREEN_START_YPOS + pos;
2091 int font_nr = FONT_MENU_1;
2094 font_nr = FONT_ACTIVE(font_nr);
2096 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2098 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2099 drawCursor(pos, active);
2102 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2107 CloseDoor(DOOR_CLOSE_2);
2109 /* (needed after displaying title screens which disable auto repeat) */
2110 KeyboardAutoRepeatOn();
2112 FadeSetLeaveScreen();
2119 if (fade_mask == REDRAW_ALL)
2123 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2129 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2131 info_info = info_info_main;
2135 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2137 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
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);
2147 DrawCursorAndText_Info(i, FALSE);
2152 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2157 DrawMaskedBorder(fade_mask);
2164 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2166 static int choice_store[MAX_INFO_MODES];
2167 int choice = choice_store[info_mode]; /* always starts with 0 */
2171 if (button == MB_MENU_INITIALIZE)
2173 /* advance to first valid menu entry */
2174 while (choice < num_info_info &&
2175 info_info[choice].type & TYPE_SKIP_ENTRY)
2177 choice_store[info_mode] = choice;
2179 DrawCursorAndText_Info(choice, TRUE);
2183 else if (button == MB_MENU_LEAVE)
2185 for (y = 0; y < num_info_info; y++)
2187 if (info_info[y].type & TYPE_LEAVE_MENU)
2189 void (*menu_callback_function)(void) = info_info[y].value;
2193 menu_callback_function();
2195 break; /* absolutely needed because function changes 'info_info'! */
2202 if (mx || my) /* mouse input */
2204 x = (mx - mSX) / 32;
2205 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2207 else if (dx || dy) /* keyboard input */
2211 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
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;
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)
2228 if (IN_VIS_FIELD(x, y) &&
2229 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2235 PlaySound(SND_MENU_ITEM_ACTIVATING);
2237 DrawCursorAndText_Info(choice, FALSE);
2238 DrawCursorAndText_Info(y, TRUE);
2240 choice = choice_store[info_mode] = y;
2243 else if (!(info_info[y].type & TYPE_GHOSTED))
2245 PlaySound(SND_MENU_ITEM_SELECTING);
2247 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2249 void (*menu_callback_function)(void) = info_info[choice].value;
2251 FadeSetFromType(info_info[y].type);
2253 menu_callback_function();
2259 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2261 int ystart1 = mSY - SY + 100;
2262 int ystart2 = mSY - SY + 150;
2263 int ybottom = mSY - SY + SYSIZE - 20;
2265 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2267 FadeOut(REDRAW_FIELD);
2272 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2273 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2275 DrawTextSCentered(ybottom, FONT_TEXT_4,
2276 "Press any key or button for info menu");
2278 FadeIn(REDRAW_FIELD);
2281 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
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;
2298 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2299 infoscreen_step[i] = infoscreen_frame[i] = 0;
2304 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2306 DrawTextSCentered(ybottom, FONT_TEXT_4,
2307 "Press any key or button for next page");
2313 while (helpanim_info[j].element != HELPANIM_LIST_END)
2315 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2320 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2329 j += infoscreen_step[i - start];
2331 element = helpanim_info[j].element;
2332 action = helpanim_info[j].action;
2333 direction = helpanim_info[j].direction;
2336 element = EL_UNKNOWN;
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);
2345 graphic = el2img(element);
2347 delay = helpanim_info[j++].delay;
2352 if (infoscreen_frame[i - start] == 0)
2355 infoscreen_frame[i - start] = delay - 1;
2359 sync_frame = delay - infoscreen_frame[i - start];
2360 infoscreen_frame[i - start]--;
2363 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2365 if (!infoscreen_frame[i - start])
2366 infoscreen_step[i - start] = 0;
2370 if (!infoscreen_frame[i - start])
2371 infoscreen_step[i - start]++;
2372 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2378 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2380 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2381 graphic, sync_frame, USE_MASKING);
2384 DrawInfoScreen_HelpText(element, action, direction, i - start);
2389 redraw_mask |= REDRAW_FIELD;
2394 static char *getHelpText(int element, int action, int direction)
2396 char token[MAX_LINE_LEN];
2398 strcpy(token, element_info[element].token_name);
2401 strcat(token, element_action_info[action].suffix);
2403 if (direction != -1)
2404 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2406 return getHashEntry(helptext_info, token);
2409 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
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;
2421 if (action != -1 && direction != -1) /* element.action.direction */
2422 text = getHelpText(element, action, direction);
2424 if (text == NULL && action != -1) /* element.action */
2425 text = getHelpText(element, action, -1);
2427 if (text == NULL && direction != -1) /* element.direction */
2428 text = getHelpText(element, -1, direction);
2430 if (text == NULL) /* base element */
2431 text = getHelpText(element, -1, -1);
2433 if (text == NULL) /* not found */
2434 text = "No description available";
2436 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2437 sy += getFontHeight(font_nr) / 2;
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);
2444 void DrawInfoScreen_TitleScreen()
2449 void HandleInfoScreen_TitleScreen(int button)
2451 HandleTitleScreen(0, 0, 0, 0, button);
2454 void DrawInfoScreen_Elements()
2456 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2458 FadeOut(REDRAW_FIELD);
2463 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2465 FadeIn(REDRAW_FIELD);
2470 void HandleInfoScreen_Elements(int button)
2472 static unsigned int info_delay = 0;
2473 static int num_anims;
2474 static int num_pages;
2476 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2479 if (button == MB_MENU_INITIALIZE)
2481 boolean new_element = TRUE;
2485 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2487 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2489 else if (new_element)
2492 new_element = FALSE;
2496 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2500 if (button == MB_MENU_LEAVE)
2502 PlaySound(SND_MENU_ITEM_SELECTING);
2504 info_mode = INFO_MODE_MAIN;
2509 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2511 if (button != MB_MENU_INITIALIZE)
2513 PlaySound(SND_MENU_ITEM_SELECTING);
2518 if (page >= num_pages)
2520 FadeSoundsAndMusic();
2522 info_mode = INFO_MODE_MAIN;
2523 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2530 FadeSetNextScreen();
2533 if (button != MB_MENU_INITIALIZE)
2534 FadeOut(REDRAW_FIELD);
2536 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2538 if (button != MB_MENU_INITIALIZE)
2539 FadeIn(REDRAW_FIELD);
2543 if (DelayReached(&info_delay, GameFrameDelay))
2544 if (page < num_pages)
2545 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2547 PlayMenuSoundIfLoop();
2551 void DrawInfoScreen_Music()
2553 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2556 FadeOut(REDRAW_FIELD);
2564 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2567 FadeIn(REDRAW_FIELD);
2571 void HandleInfoScreen_Music(int button)
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;
2579 if (button == MB_MENU_INITIALIZE)
2581 list = music_file_info;
2585 FadeSoundsAndMusic();
2590 DrawTextSCentered(ystart1, FONT_TEXT_1,
2591 "No music info for this level set.");
2593 DrawTextSCentered(ybottom, FONT_TEXT_4,
2594 "Press any key or button for info menu");
2600 if (button == MB_MENU_LEAVE)
2602 PlaySound(SND_MENU_ITEM_SELECTING);
2604 FadeSoundsAndMusic();
2606 info_mode = INFO_MODE_MAIN;
2611 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2615 if (button != MB_MENU_INITIALIZE)
2617 PlaySound(SND_MENU_ITEM_SELECTING);
2625 FadeSoundsAndMusic();
2627 info_mode = INFO_MODE_MAIN;
2628 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2633 FadeSoundsAndMusic();
2636 if (list != music_file_info)
2637 FadeSetNextScreen();
2640 if (button != MB_MENU_INITIALIZE)
2641 FadeOut(REDRAW_FIELD);
2648 int sound = list->music;
2650 if (sound_info[sound].loop)
2651 PlaySoundLoop(sound);
2655 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2659 PlayMusic(list->music);
2661 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2664 if (!strEqual(list->title, UNKNOWN_NAME))
2666 if (!strEqual(list->title_header, UNKNOWN_NAME))
2667 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2669 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2672 if (!strEqual(list->artist, UNKNOWN_NAME))
2674 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2675 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2677 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2679 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2682 if (!strEqual(list->album, UNKNOWN_NAME))
2684 if (!strEqual(list->album_header, UNKNOWN_NAME))
2685 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2687 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2689 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2692 if (!strEqual(list->year, UNKNOWN_NAME))
2694 if (!strEqual(list->year_header, UNKNOWN_NAME))
2695 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2697 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2699 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2702 DrawTextSCentered(ybottom, FONT_TEXT_4,
2703 "Press any key or button for next page");
2705 if (button != MB_MENU_INITIALIZE)
2706 FadeIn(REDRAW_FIELD);
2709 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2710 PlaySoundLoop(list->music);
2713 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2715 int ystart1 = mSY - SY + 100;
2716 int ystart2 = mSY - SY + 150;
2717 int ybottom = mSY - SY + SYSIZE - 20;
2723 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2727 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2728 "Special thanks to");
2729 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2731 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2733 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2734 "\"Boulder Dash\"");
2735 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2737 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2739 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2741 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2742 "First Star Software");
2744 else if (screen_nr == 1)
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,
2752 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2753 "\"Emerald Mine\"");
2754 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2756 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2758 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2760 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2763 else if (screen_nr == 2)
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,
2771 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2773 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2775 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2777 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2779 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2780 "Digital Integration");
2782 else if (screen_nr == 3)
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,
2790 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2792 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2794 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2796 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2798 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2801 else if (screen_nr == 4)
2803 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2804 "Special thanks to");
2805 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2807 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
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");
2816 else if (screen_nr == 5)
2818 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2820 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2822 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2823 "for ideas and inspiration by");
2824 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2827 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2829 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2831 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2832 "for ideas and inspiration by");
2833 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2836 else if (screen_nr == 6)
2838 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2840 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
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");
2848 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2849 "for the new Emerald Mine engine");
2852 else if (screen_nr == 7)
2854 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2856 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2858 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2859 "for the initial DOS port");
2861 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2863 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2865 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2866 "for some additional toons");
2868 else if (screen_nr == 8)
2870 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2871 "And not to forget:");
2872 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
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,
2882 DrawTextSCentered(ybottom, FONT_TEXT_4,
2883 "Press any key or button for next page");
2886 void DrawInfoScreen_Credits()
2888 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2890 FadeSoundsAndMusic();
2893 FadeOut(REDRAW_FIELD);
2896 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2899 FadeIn(REDRAW_FIELD);
2903 void HandleInfoScreen_Credits(int button)
2905 static int screen_nr = 0;
2906 int num_screens = 9;
2908 if (button == MB_MENU_INITIALIZE)
2912 // DrawInfoScreen_CreditsScreen(screen_nr);
2915 if (button == MB_MENU_LEAVE)
2917 PlaySound(SND_MENU_ITEM_SELECTING);
2919 info_mode = INFO_MODE_MAIN;
2924 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2926 if (button != MB_MENU_INITIALIZE)
2928 PlaySound(SND_MENU_ITEM_SELECTING);
2933 if (screen_nr >= num_screens)
2935 FadeSoundsAndMusic();
2937 info_mode = INFO_MODE_MAIN;
2938 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2945 FadeSetNextScreen();
2948 if (button != MB_MENU_INITIALIZE)
2949 FadeOut(REDRAW_FIELD);
2951 DrawInfoScreen_CreditsScreen(screen_nr);
2953 if (button != MB_MENU_INITIALIZE)
2954 FadeIn(REDRAW_FIELD);
2958 PlayMenuSoundIfLoop();
2962 void DrawInfoScreen_Program()
2964 int ystart1 = mSY - SY + 100;
2965 int ystart2 = mSY - SY + 150;
2966 int ybottom = mSY - SY + SYSIZE - 20;
2969 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2972 FadeOut(REDRAW_FIELD);
2978 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
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);
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,
2998 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2999 "or SnailMail to:");
3000 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3002 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3003 "Detmolder Strasse 189");
3004 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3006 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
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,
3020 DrawTextSCentered(ybottom, FONT_TEXT_4,
3021 "Press any key or button for info menu");
3024 FadeIn(REDRAW_FIELD);
3028 void HandleInfoScreen_Program(int button)
3030 if (button == MB_MENU_LEAVE)
3032 PlaySound(SND_MENU_ITEM_SELECTING);
3034 info_mode = INFO_MODE_MAIN;
3039 else if (button == MB_MENU_CHOICE)
3041 PlaySound(SND_MENU_ITEM_SELECTING);
3043 FadeSoundsAndMusic();
3046 FadeOut(REDRAW_FIELD);
3049 info_mode = INFO_MODE_MAIN;
3050 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3054 PlayMenuSoundIfLoop();
3058 void DrawInfoScreen_Version()
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;
3078 char driver_name[driver_name_len];
3082 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3085 FadeOut(REDRAW_FIELD);
3091 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3093 DrawTextF(xstart1, ystart2, font_header, "Name");
3094 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3097 DrawTextF(xstart1, ystart2, font_header, "Version");
3098 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3101 DrawTextF(xstart1, ystart2, font_header, "Platform");
3102 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3105 DrawTextF(xstart1, ystart2, font_header, "Target");
3106 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3109 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3110 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
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");
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;
3123 sdl_version_linked = SDL_Linked_Version();
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);
3137 SDL_IMAGE_VERSION(&sdl_version_compiled);
3138 sdl_version_linked = IMG_Linked_Version();
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);
3151 SDL_MIXER_VERSION(&sdl_version_compiled);
3152 sdl_version_linked = Mix_Linked_Version();
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);
3165 SDL_NET_VERSION(&sdl_version_compiled);
3166 sdl_version_linked = SDLNet_Linked_Version();
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);
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");
3184 #if defined(TARGET_SDL2)
3185 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3187 SDL_VideoDriverName(driver_name, driver_name_len);
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);
3195 #if defined(TARGET_SDL2)
3196 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3198 SDL_AudioDriverName(driver_name, driver_name_len);
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);
3207 DrawTextSCentered(ybottom, FONT_TEXT_4,
3208 "Press any key or button for info menu");
3211 FadeIn(REDRAW_FIELD);
3215 void HandleInfoScreen_Version(int button)
3217 if (button == MB_MENU_LEAVE)
3219 PlaySound(SND_MENU_ITEM_SELECTING);
3221 info_mode = INFO_MODE_MAIN;
3226 else if (button == MB_MENU_CHOICE)
3228 PlaySound(SND_MENU_ITEM_SELECTING);
3230 FadeSoundsAndMusic();
3233 FadeOut(REDRAW_FIELD);
3236 info_mode = INFO_MODE_MAIN;
3237 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3241 PlayMenuSoundIfLoop();
3245 void DrawInfoScreen_LevelSet()
3247 struct TitleMessageInfo *tmi = &readme;
3248 char *filename = getLevelSetInfoFilename();
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);
3254 tmi->width = tmi->chars * getFontWidth(tmi->font);
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);
3260 tmi->height = tmi->lines * getFontHeight(tmi->font);
3262 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3265 FadeOut(REDRAW_FIELD);
3271 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
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);
3278 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3279 "No information for this level set.");
3281 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3282 "Press any key or button for info menu");
3285 FadeIn(REDRAW_FIELD);
3289 void HandleInfoScreen_LevelSet(int button)
3291 if (button == MB_MENU_LEAVE)
3293 PlaySound(SND_MENU_ITEM_SELECTING);
3295 info_mode = INFO_MODE_MAIN;
3300 else if (button == MB_MENU_CHOICE)
3302 PlaySound(SND_MENU_ITEM_SELECTING);
3304 FadeSoundsAndMusic();
3307 FadeOut(REDRAW_FIELD);
3310 info_mode = INFO_MODE_MAIN;
3311 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3315 PlayMenuSoundIfLoop();
3319 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3321 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
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();
3338 DrawInfoScreen_Main(fade_mask, do_fading);
3340 if (info_mode != INFO_MODE_MAIN &&
3341 info_mode != INFO_MODE_TITLE &&
3342 info_mode != INFO_MODE_MUSIC)
3349 void DrawAndFadeInInfoScreen(int fade_mask)
3351 DrawInfoScreenExt(fade_mask, TRUE);
3354 void DrawInfoScreen()
3356 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3359 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
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);
3376 HandleInfoScreen_Main(mx, my, dx, dy, button);
3384 /* ========================================================================= */
3385 /* type name functions */
3386 /* ========================================================================= */
3388 void HandleTypeName(int newxpos, Key key)
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;
3403 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3407 strcpy(last_player_name, setup.player_name);
3411 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3413 setup.player_name[xpos] = key_char;
3414 setup.player_name[xpos + 1] = 0;
3418 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3422 setup.player_name[xpos] = 0;
3424 else if (key == KSYM_Return && xpos > 0)
3430 game_status = GAME_MODE_MAIN;
3432 else if (key == KSYM_Escape)
3434 strcpy(setup.player_name, last_player_name);
3438 game_status = GAME_MODE_MAIN;
3443 pos->width = (strlen(setup.player_name) + 1) * font_width;
3444 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3446 DrawText(startx, starty, setup.player_name, font_active_nr);
3447 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3451 pos->width = strlen(setup.player_name) * font_width;
3452 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3454 DrawText(startx, starty, setup.player_name, font_nr);
3459 /* ========================================================================= */
3460 /* tree menu functions */
3461 /* ========================================================================= */
3463 static void DrawChooseTree(TreeInfo **ti_ptr)
3467 FreeScreenGadgets();
3468 CreateScreenGadgets();
3470 CloseDoor(DOOR_CLOSE_2);
3473 FadeOut(REDRAW_FIELD);
3478 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3479 MapScreenTreeGadgets(*ti_ptr);
3482 FadeIn(REDRAW_FIELD);
3488 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3490 struct GadgetInfo *gi = screen_gadget[id];
3491 int items_max, items_visible, item_position;
3493 items_max = numTreeInfoInGroup(ti);
3494 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3495 item_position = first_entry;
3497 if (item_position > items_max - items_visible)
3498 item_position = items_max - items_visible;
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);
3505 static void drawChooseTreeList(int first_entry, int num_page_entries,
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 */
3516 title_string = ti->infotext;
3518 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3521 /* force LEVELS font on artwork setup screen */
3522 game_status = GAME_MODE_LEVELS;
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);
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);
3537 for (i = 0; i < num_page_entries; i++)
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];
3553 node_first = getTreeInfoFirstGroupEntry(ti);
3554 node = getTreeInfoFromPos(node_first, entry_pos);
3556 strncpy(buffer, node->name, max_buffer_len);
3557 buffer[max_buffer_len] = '\0';
3559 DrawText(startx, starty, buffer, font_nr + node->color);
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);
3566 initCursor(i, IMG_MENU_BUTTON);
3569 game_status = last_game_status; /* restore current game status */
3571 redraw_mask |= REDRAW_FIELD;
3574 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
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;
3581 if (ti->type == TREE_TYPE_LEVEL_NR)
3582 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3584 if (ti->type != TREE_TYPE_LEVEL_DIR)
3587 node_first = getTreeInfoFirstGroupEntry(ti);
3588 node = getTreeInfoFromPos(node_first, entry_pos);
3590 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
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\"",
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"),
3604 if (node->parent_link)
3605 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3607 else if (node->level_group)
3608 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3610 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3611 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3612 node->levels, node->class_desc);
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);
3621 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3624 TreeInfo *ti = *ti_ptr;
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);
3634 /* force LEVELS draw offset on choose level and artwork setup screen */
3635 game_status = GAME_MODE_LEVELS;
3638 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3639 num_page_entries = num_entries;
3641 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3643 game_status = last_game_status; /* restore current game status */
3645 if (button == MB_MENU_INITIALIZE)
3647 int num_entries = numTreeInfoInGroup(ti);
3648 int entry_pos = posTreeInfo(ti);
3650 if (ti->cl_first == -1)
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;
3656 else if (ti->cl_cursor >= num_page_entries ||
3657 (num_entries > num_page_entries &&
3658 num_entries - ti->cl_first < num_page_entries))
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;
3665 if (position_set_by_scrollbar)
3668 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3671 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3672 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3673 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3677 else if (button == MB_MENU_LEAVE)
3681 PlaySound(SND_MENU_ITEM_SELECTING);
3683 if (ti->node_parent)
3685 *ti_ptr = ti->node_parent;
3686 DrawChooseTree(ti_ptr);
3688 else if (game_status == GAME_MODE_SETUP)
3690 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3691 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
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)
3706 if (game_status == GAME_MODE_LEVELNR)
3707 level_nr = atoi(level_number_current->identifier);
3709 game_status = GAME_MODE_MAIN;
3711 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3717 if (mx || my) /* mouse input */
3719 int last_game_status = game_status; /* save current game status */
3722 /* force LEVELS draw offset on artwork setup screen */
3723 game_status = GAME_MODE_LEVELS;
3726 x = (mx - mSX) / 32;
3727 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3729 game_status = last_game_status; /* restore current game status */
3731 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3733 /* move cursor instead of scrolling when already at start/end of list */
3734 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3736 else if (dy == +1 * SCROLL_LINE &&
3737 ti->cl_first + num_page_entries == num_entries)
3740 /* handle scrolling screen one line or page */
3741 if (ti->cl_cursor + dy < 0 ||
3742 ti->cl_cursor + dy > num_page_entries - 1)
3744 if (ABS(dy) == SCROLL_PAGE)
3745 step = num_page_entries - 1;
3747 if (dy < 0 && ti->cl_first > 0)
3749 /* scroll page/line up */
3751 ti->cl_first -= step;
3752 if (ti->cl_first < 0)
3755 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3756 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3757 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3759 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3762 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3764 /* scroll page/line down */
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);
3770 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3771 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3772 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3774 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3781 /* handle moving cursor one line */
3782 y = ti->cl_cursor + dy;
3787 TreeInfo *node_first, *node_cursor;
3788 int entry_pos = ti->cl_first + y;
3790 node_first = getTreeInfoFirstGroupEntry(ti);
3791 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3793 if (node_cursor->node_group)
3797 PlaySound(SND_MENU_ITEM_SELECTING);
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);
3807 else if (dx == -1 && ti->node_parent)
3811 PlaySound(SND_MENU_ITEM_SELECTING);
3813 *ti_ptr = ti->node_parent;
3814 DrawChooseTree(ti_ptr);
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)
3826 if (y != ti->cl_cursor)
3828 PlaySound(SND_MENU_ITEM_ACTIVATING);
3830 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3831 drawChooseTreeCursor(y, TRUE);
3832 drawChooseTreeInfo(ti->cl_first + y, ti);
3839 TreeInfo *node_first, *node_cursor;
3840 int entry_pos = ti->cl_first + y;
3842 PlaySound(SND_MENU_ITEM_SELECTING);
3844 node_first = getTreeInfoFirstGroupEntry(ti);
3845 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3847 if (node_cursor->node_group)
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);
3856 else if (node_cursor->parent_link)
3860 *ti_ptr = node_cursor->node_parent;
3861 DrawChooseTree(ti_ptr);
3868 FadeSetEnterScreen();
3871 node_cursor->cl_first = ti->cl_first;
3872 node_cursor->cl_cursor = ti->cl_cursor;
3873 *ti_ptr = node_cursor;
3875 if (ti->type == TREE_TYPE_LEVEL_DIR)
3877 LoadLevelSetup_SeriesInfo();
3879 SaveLevelSetup_LastSeries();
3880 SaveLevelSetup_SeriesInfo();
3884 if (game_status == GAME_MODE_SETUP)
3886 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3887 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
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)
3902 if (game_status == GAME_MODE_LEVELNR)
3903 level_nr = atoi(level_number_current->identifier);
3905 game_status = GAME_MODE_MAIN;
3914 void DrawChooseLevelSet()
3916 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3918 DrawChooseTree(&leveldir_current);
3924 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3926 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3933 void DrawChooseLevelNr()
3937 if (level_number != NULL)
3939 freeTreeInfo(level_number);
3941 level_number = NULL;
3944 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3946 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3947 char identifier[32], name[32];
3950 /* temporarily load level info to get level name */
3951 LoadLevelInfoOnly(i);
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);
3959 sprintf(identifier, "%d", value);
3960 sprintf(name, "%03d: %s", value,
3961 (level.no_valid_file ? "(no file)" : level.name));
3963 setString(&ti->identifier, identifier);
3964 setString(&ti->name, name);
3965 setString(&ti->name_sorting, name);
3967 pushTreeInfo(&level_number, ti);
3970 /* sort level number values to start with lowest level number */
3971 sortTreeInfo(&level_number);
3973 /* set current level number to current level number */
3974 level_number_current =
3975 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
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;
3981 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3984 DrawChooseTree(&level_number_current);
3986 DrawChooseTree(&leveldir_current);
3993 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3996 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3998 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4006 void DrawHallOfFame(int highlight_position)
4009 FadeSoundsAndMusic();
4011 /* (this is needed when called from GameEnd() after winning a game) */
4012 KeyboardAutoRepeatOn();
4015 /* (this is needed when called from GameEnd() after winning a game) */
4016 SetDrawDeactivationMask(REDRAW_NONE);
4017 SetDrawBackgroundMask(REDRAW_FIELD);
4019 CloseDoor(DOOR_CLOSE_2);
4021 if (highlight_position < 0)
4022 LoadScore(level_nr);
4024 FadeSetEnterScreen();
4026 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4029 FadeOut(REDRAW_FIELD);
4037 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4040 FadeIn(REDRAW_FIELD);
4044 static void drawHallOfFameList(int first_entry, int highlight_position)
4048 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
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);
4055 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
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);
4066 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
4067 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4069 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4071 int sy = mSY + 64 + i * 32;
4073 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4074 DrawText(mSX + dx1, sy, ".", font_nr1);
4076 for (j = 0; j < num_dots; j++)
4077 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4079 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4082 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4083 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4085 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4088 redraw_mask |= REDRAW_FIELD;
4091 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4093 static int first_entry = 0;
4094 static int highlight_position = 0;
4095 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4097 if (button == MB_MENU_INITIALIZE)
4100 highlight_position = mx;
4101 drawHallOfFameList(first_entry, highlight_position);
4106 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4107 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4111 if (first_entry > 0)
4113 first_entry -= step;
4114 if (first_entry < 0)
4117 drawHallOfFameList(first_entry, highlight_position);
4122 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
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);
4128 drawHallOfFameList(first_entry, highlight_position);
4131 else if (button == MB_MENU_LEAVE)
4133 PlaySound(SND_MENU_ITEM_SELECTING);
4135 FadeSound(SND_BACKGROUND_SCORES);
4137 game_status = GAME_MODE_MAIN;
4141 else if (button == MB_MENU_CHOICE)
4143 PlaySound(SND_MENU_ITEM_SELECTING);
4145 FadeSound(SND_BACKGROUND_SCORES);
4148 FadeOut(REDRAW_FIELD);
4151 game_status = GAME_MODE_MAIN;
4153 DrawAndFadeInMainMenu(REDRAW_FIELD);
4156 if (game_status == GAME_MODE_SCORES)
4157 PlayMenuSoundIfLoop();
4165 /* ========================================================================= */
4166 /* setup screen functions */
4167 /* ========================================================================= */
4169 static struct TokenInfo *setup_info;
4170 static int num_setup_info;
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;
4184 static void execSetupMain()
4186 setup_mode = SETUP_MODE_MAIN;
4191 static void execSetupGame_setGameSpeeds()
4193 if (game_speeds == NULL)
4197 for (i = 0; game_speeds_list[i].value != -1; i++)
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;
4204 ti->node_top = &game_speeds;
4205 ti->sort_priority = 10000 - value;
4207 sprintf(identifier, "%d", value);
4208 sprintf(name, "%s", text);
4210 setString(&ti->identifier, identifier);
4211 setString(&ti->name, name);
4212 setString(&ti->name_sorting, name);
4213 setString(&ti->infotext, "Game Speed");
4215 pushTreeInfo(&game_speeds, ti);
4218 /* sort game speed values to start with slowest game speed */
4219 sortTreeInfo(&game_speeds);
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));
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));
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;
4235 setup.game_frame_delay = atoi(game_speed_current->identifier);
4237 /* needed for displaying game speed text instead of identifier */
4238 game_speed_text = game_speed_current->name;
4241 static void execSetupGame_setScrollDelays()
4243 if (scroll_delays == NULL)
4247 for (i = 0; scroll_delays_list[i].value != -1; i++)
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;
4254 ti->node_top = &scroll_delays;
4255 ti->sort_priority = value;
4257 sprintf(identifier, "%d", value);
4258 sprintf(name, "%s", text);
4260 setString(&ti->identifier, identifier);
4261 setString(&ti->name, name);
4262 setString(&ti->name_sorting, name);
4263 setString(&ti->infotext, "Scaling Type");
4265 pushTreeInfo(&scroll_delays, ti);
4268 /* sort scaling type values to start with lowest scaling type value */
4269 sortTreeInfo(&scroll_delays);
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));
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));
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;
4285 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4287 /* needed for displaying scaling type text instead of identifier */
4288 scroll_delay_text = scroll_delay_current->name;
4291 static void execSetupGame()
4293 execSetupGame_setGameSpeeds();
4294 execSetupGame_setScrollDelays();
4296 setup_mode = SETUP_MODE_GAME;
4301 static void execSetupChooseGameSpeed()
4303 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4308 static void execSetupChooseScrollDelay()
4310 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4315 static void execSetupEditor()
4317 setup_mode = SETUP_MODE_EDITOR;
4322 static void execSetupGraphics_setWindowSizes(boolean update_list)
4324 if (window_sizes != NULL && update_list)
4326 freeTreeInfo(window_sizes);
4328 window_sizes = NULL;
4331 if (window_sizes == NULL)
4333 boolean current_window_size_found = FALSE;
4336 for (i = 0; window_sizes_list[i].value != -1; i++)
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;
4343 ti->node_top = &window_sizes;
4344 ti->sort_priority = value;
4346 sprintf(identifier, "%d", value);
4347 sprintf(name, "%s", text);
4349 setString(&ti->identifier, identifier);
4350 setString(&ti->name, name);
4351 setString(&ti->name_sorting, name);
4352 setString(&ti->infotext, "Window Scaling");
4354 pushTreeInfo(&window_sizes, ti);
4356 if (value == setup.window_scaling_percent)
4357 current_window_size_found = TRUE;
4360 if (!current_window_size_found)
4362 // add entry for non-preset window scaling value
4364 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4365 char identifier[32], name[32];
4366 int value = setup.window_scaling_percent;
4368 ti->node_top = &window_sizes;
4369 ti->sort_priority = value;
4371 sprintf(identifier, "%d", value);
4372 sprintf(name, "%d %% (Current)", value);
4374 setString(&ti->identifier, identifier);
4375 setString(&ti->name, name);
4376 setString(&ti->name_sorting, name);
4377 setString(&ti->infotext, "Window Scaling");
4379 pushTreeInfo(&window_sizes, ti);
4382 /* sort window size values to start with lowest window size value */
4383 sortTreeInfo(&window_sizes);
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));
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));
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;
4401 setup.window_scaling_percent = atoi(window_size_current->identifier);
4403 /* needed for displaying window size text instead of identifier */
4404 window_size_text = window_size_current->name;
4407 static void execSetupGraphics_setScalingTypes()
4409 if (scaling_types == NULL)
4413 for (i = 0; scaling_types_list[i].value != NULL; i++)
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;
4420 ti->node_top = &scaling_types;
4421 ti->sort_priority = i;
4423 sprintf(identifier, "%s", value);
4424 sprintf(name, "%s", text);
4426 setString(&ti->identifier, identifier);
4427 setString(&ti->name, name);
4428 setString(&ti->name_sorting, name);
4429 setString(&ti->infotext, "Anti-Aliasing");
4431 pushTreeInfo(&scaling_types, ti);
4434 /* sort scaling type values to start with lowest scaling type value */
4435 sortTreeInfo(&scaling_types);
4437 /* set current scaling type value to configured scaling type value */
4438 scaling_type_current =
4439 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
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);
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;
4451 setup.window_scaling_quality = scaling_type_current->identifier;
4453 /* needed for displaying scaling type text instead of identifier */
4454 scaling_type_text = scaling_type_current->name;
4457 static void execSetupGraphics_setScreenModes()
4459 // if (screen_modes == NULL && video.fullscreen_available)
4460 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4464 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
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;
4472 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4474 ti->node_top = &screen_modes;
4475 ti->sort_priority = x * 10000 + y;
4477 sprintf(identifier, "%dx%d", x, y);
4478 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4480 setString(&ti->identifier, identifier);
4481 setString(&ti->name, name);
4482 setString(&ti->name_sorting, name);
4483 setString(&ti->infotext, "Fullscreen Mode");
4485 pushTreeInfo(&screen_modes, ti);
4488 /* sort fullscreen modes to start with lowest available screen resolution */
4489 sortTreeInfo(&screen_modes);
4491 /* set current screen mode for fullscreen mode to configured setup value */
4492 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4493 setup.fullscreen_mode);
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);
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;
4504 if (screen_mode_current == NULL)
4505 video.fullscreen_available = FALSE;
4508 // if (video.fullscreen_available)
4509 if (screen_mode_current != NULL)
4511 setup.fullscreen_mode = screen_mode_current->identifier;
4513 /* needed for displaying screen mode name instead of identifier */
4514 screen_mode_text = screen_mode_current->name;
4518 static void execSetupGraphics()
4520 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4522 // update "setup.window_scaling_percent" from list selection
4523 execSetupGraphics_setWindowSizes(FALSE);
4527 // update list selection from "setup.window_scaling_percent"
4528 execSetupGraphics_setWindowSizes(TRUE);
4531 execSetupGraphics_setScalingTypes();
4532 execSetupGraphics_setScreenModes();
4534 setup_mode = SETUP_MODE_GRAPHICS;
4538 #if defined(TARGET_SDL2)
4539 // window scaling may have changed at this point
4540 ToggleFullscreenOrChangeWindowScalingIfNeeded();
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);
4548 #if !defined(PLATFORM_ANDROID)
4549 #if defined(TARGET_SDL2)
4550 static void execSetupChooseWindowSize()
4553 if (!video.window_scaling_available)
4557 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4562 static void execSetupChooseScalingType()
4564 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4569 static void execSetupChooseScreenMode()
4571 if (!video.fullscreen_available)
4574 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4581 static void execSetupChooseVolumeSimple()
4583 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4588 static void execSetupChooseVolumeLoops()
4590 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4595 static void execSetupChooseVolumeMusic()
4597 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4602 static void execSetupSound()
4605 if (volumes_simple == NULL)
4609 for (i = 0; volumes_list[i].value != -1; i++)
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;
4616 ti->node_top = &volumes_simple;
4617 ti->sort_priority = value;
4619 sprintf(identifier, "%d", value);
4620 sprintf(name, "%s", text);
4622 setString(&ti->identifier, identifier);
4623 setString(&ti->name, name);
4624 setString(&ti->name_sorting, name);
4625 setString(&ti->infotext, "Sound Volume");
4627 pushTreeInfo(&volumes_simple, ti);
4630 /* sort volume values to start with lowest volume value */
4631 sortTreeInfo(&volumes_simple);
4633 /* set current volume value to configured volume value */
4634 volume_simple_current =
4635 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
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));
4642 /* if that also fails, set current volume to first available value */
4643 if (volume_simple_current == NULL)
4644 volume_simple_current = volumes_simple;
4647 if (volumes_loops == NULL)
4651 for (i = 0; volumes_list[i].value != -1; i++)
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;
4658 ti->node_top = &volumes_loops;
4659 ti->sort_priority = value;
4661 sprintf(identifier, "%d", value);
4662 sprintf(name, "%s", text);
4664 setString(&ti->identifier, identifier);
4665 setString(&ti->name, name);
4666 setString(&ti->name_sorting, name);
4667 setString(&ti->infotext, "Loops Volume");
4669 pushTreeInfo(&volumes_loops, ti);
4672 /* sort volume values to start with lowest volume value */
4673 sortTreeInfo(&volumes_loops);
4675 /* set current volume value to configured volume value */
4676 volume_loops_current =
4677 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
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));
4684 /* if that also fails, set current volume to first available value */
4685 if (volume_loops_current == NULL)
4686 volume_loops_current = volumes_loops;
4689 if (volumes_music == NULL)
4693 for (i = 0; volumes_list[i].value != -1; i++)
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;
4700 ti->node_top = &volumes_music;
4701 ti->sort_priority = value;
4703 sprintf(identifier, "%d", value);
4704 sprintf(name, "%s", text);
4706 setString(&ti->identifier, identifier);
4707 setString(&ti->name, name);
4708 setString(&ti->name_sorting, name);
4709 setString(&ti->infotext, "Music Volume");
4711 pushTreeInfo(&volumes_music, ti);
4714 /* sort volume values to start with lowest volume value */
4715 sortTreeInfo(&volumes_music);
4717 /* set current volume value to configured volume value */
4718 volume_music_current =
4719 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
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));
4726 /* if that also fails, set current volume to first available value */
4727 if (volume_music_current == NULL)
4728 volume_music_current = volumes_music;
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);
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;
4741 setup_mode = SETUP_MODE_SOUND;
4746 static void execSetupArtwork()
4749 printf("::: '%s', '%s', '%s'\n",
4750 artwork.gfx_current->subdir,
4751 artwork.gfx_current->fullpath,
4752 artwork.gfx_current->basepath);
4755 setup.graphics_set = artwork.gfx_current->identifier;
4756 setup.sounds_set = artwork.snd_current->identifier;
4757 setup.music_set = artwork.mus_current->identifier;
4759 /* needed if last screen (setup choice) changed graphics, sounds or music */
4760 ReloadCustomArtwork(0);
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;
4767 setup_mode = SETUP_MODE_ARTWORK;
4772 static void execSetupChooseGraphics()
4774 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4779 static void execSetupChooseSounds()
4781 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4786 static void execSetupChooseMusic()
4788 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4793 static void execSetupInput()
4795 setup_mode = SETUP_MODE_INPUT;
4800 static void execSetupShortcuts()
4802 setup_mode = SETUP_MODE_SHORTCUTS;
4807 static void execSetupShortcuts1()
4809 setup_mode = SETUP_MODE_SHORTCUTS_1;
4814 static void execSetupShortcuts2()
4816 setup_mode = SETUP_MODE_SHORTCUTS_2;
4821 static void execSetupShortcuts3()
4823 setup_mode = SETUP_MODE_SHORTCUTS_3;
4828 static void execSetupShortcuts4()
4830 setup_mode = SETUP_MODE_SHORTCUTS_4;
4835 static void execSetupShortcuts5()
4837 setup_mode = SETUP_MODE_SHORTCUTS_5;
4842 static void execExitSetup()
4844 game_status = GAME_MODE_MAIN;
4846 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4849 static void execSaveAndExitSetup()
4855 static struct TokenInfo setup_info_main[] =
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" },
4871 static struct TokenInfo setup_info_game[] =
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, "" },
4882 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4883 { TYPE_STRING, &scroll_delay_text, "" },
4885 { TYPE_EMPTY, NULL, "" },
4886 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4891 static struct TokenInfo setup_info_editor[] =
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:" },
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:" },
4907 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
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, "" },
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, "" },
4917 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4918 { TYPE_EMPTY, NULL, "" },
4919 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4924 static struct TokenInfo setup_info_graphics[] =
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, "" },
4932 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4933 { TYPE_STRING, &scaling_type_text, "" },
4936 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4937 { TYPE_STRING, &screen_mode_text, "" },
4941 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4944 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4945 { TYPE_STRING, &scroll_delay_text, "" },
4948 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
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" },
4964 static struct TokenInfo setup_info_sound[] =
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" },
4982 static struct TokenInfo setup_info_artwork[] =
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, "" },
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:" },
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:" },
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:" },
5008 { TYPE_EMPTY, NULL, "" },
5009 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5014 static struct TokenInfo setup_info_input[] =
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" },
5034 static struct TokenInfo setup_info_shortcuts[] =
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" },
5047 static struct TokenInfo setup_info_shortcuts_1[] =
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" },
5064 static struct TokenInfo setup_info_shortcuts_2[] =
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" },
5082 static struct TokenInfo setup_info_shortcuts_3[] =
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" },
5102 static struct TokenInfo setup_info_shortcuts_4[] =
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" },
5116 static struct TokenInfo setup_info_shortcuts_5[] =
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" },
5132 static Key getSetupKey()
5134 Key key = KSYM_UNDEFINED;
5135 boolean got_key_event = FALSE;
5137 while (!got_key_event)
5139 if (PendingEvent()) /* got event */
5147 case EVENT_KEYPRESS:
5149 key = GetEventKey((KeyEvent *)&event, TRUE);
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 */
5155 got_key_event = TRUE;
5159 case EVENT_KEYRELEASE:
5160 key_joystick_mapping = 0;
5164 HandleOtherEvents(&event);
5172 /* don't eat all CPU time */
5179 static int getSetupTextFont(int type)
5181 if (type & (TYPE_SWITCH |
5193 static int getSetupValueFont(int type, void *value)
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);
5207 return FONT_VALUE_1;
5210 static void drawSetupValue(int pos)
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;
5222 int type = setup_info[pos].type;
5223 void *value = setup_info[pos].value;
5224 char *value_string = getSetupValue(type, value);
5229 if (value_string == NULL)
5232 if (type & TYPE_KEY)
5234 xpos = MENU_SCREEN_START_XPOS;
5236 if (type & TYPE_QUERY)
5237 value_string = "<press key>";
5239 else if (type & TYPE_STRING)
5241 int max_value_len = (SCR_FIELDX - 2) * 2;
5243 xpos = MENU_SCREEN_START_XPOS;
5245 if (strlen(value_string) > max_value_len)
5246 value_string[max_value_len] = '\0';
5248 else if (type & TYPE_YES_NO_AUTO)
5250 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5253 startx = mSX + xpos * 32;
5254 starty = mSY + ypos * 32;
5255 font_nr = getSetupValueFont(type, value);
5256 font_width = getFontWidth(font_nr);
5258 font_height = getFontHeight(font_nr);
5261 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5262 if (setup_mode != SETUP_MODE_INPUT)
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;
5273 if (xpos == MENU_SCREEN_START_XPOS &&
5274 startx + font1_xoffset < text_startx + text_font_xoffset)
5275 correct_font_draw_xoffset = TRUE;
5277 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5278 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5279 correct_font_draw_xoffset = TRUE;
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)
5285 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5286 font_draw_xoffset_modified = TRUE;
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));
5297 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5299 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5300 DrawText(startx + i * font_width, starty, " ", font_nr);
5303 DrawText(startx, starty, value_string, font_nr);
5305 if (font_draw_xoffset_modified)
5306 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5309 static void changeSetupValue(int pos, int dx)
5311 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5313 *(boolean *)setup_info[pos].value ^= TRUE;
5315 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5317 *(int *)setup_info[pos].value =
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));
5324 else if (setup_info[pos].type & TYPE_KEY)
5328 setup_info[pos].type |= TYPE_QUERY;
5329 drawSetupValue(pos);
5330 setup_info[pos].type &= ~TYPE_QUERY;
5332 key = getSetupKey();
5333 if (key != KSYM_UNDEFINED)
5334 *(Key *)setup_info[pos].value = key;
5337 drawSetupValue(pos);
5339 // fullscreen state may have changed at this point
5340 if (setup_info[pos].value == &setup.fullscreen)
5341 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5344 static void DrawCursorAndText_Setup(int pos, boolean active)
5346 int xpos = MENU_SCREEN_START_XPOS;
5347 int ypos = MENU_SCREEN_START_YPOS + pos;
5348 int font_nr = getSetupTextFont(setup_info[pos].type);
5350 if (setup_info == setup_info_input)
5351 font_nr = FONT_MENU_1;
5354 font_nr = FONT_ACTIVE(font_nr);
5356 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5358 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5359 drawCursor(pos, active);
5362 static void DrawSetupScreen_Generic()
5364 boolean redraw_all = FALSE;
5365 char *title_string = NULL;
5369 CloseDoor(DOOR_CLOSE_2);
5371 if (redraw_mask & REDRAW_ALL)
5375 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5376 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5377 int2str(0, redraw_mask)));
5381 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5382 FadeOut(redraw_mask);
5384 FadeOut(REDRAW_FIELD);
5389 if (setup_mode == SETUP_MODE_MAIN)
5391 setup_info = setup_info_main;
5392 title_string = "Setup";
5394 else if (setup_mode == SETUP_MODE_GAME)
5396 setup_info = setup_info_game;
5397 title_string = "Setup Game";
5399 else if (setup_mode == SETUP_MODE_EDITOR)
5401 setup_info = setup_info_editor;
5402 title_string = "Setup Editor";
5404 else if (setup_mode == SETUP_MODE_GRAPHICS)
5406 setup_info = setup_info_graphics;
5407 title_string = "Setup Graphics";
5409 else if (setup_mode == SETUP_MODE_SOUND)
5411 setup_info = setup_info_sound;
5412 title_string = "Setup Sound";
5414 else if (setup_mode == SETUP_MODE_ARTWORK)
5416 setup_info = setup_info_artwork;
5417 title_string = "Custom Artwork";
5419 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5421 setup_info = setup_info_shortcuts;
5422 title_string = "Setup Shortcuts";
5424 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5426 setup_info = setup_info_shortcuts_1;
5427 title_string = "Setup Shortcuts";
5429 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5431 setup_info = setup_info_shortcuts_2;
5432 title_string = "Setup Shortcuts";
5434 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5436 setup_info = setup_info_shortcuts_3;
5437 title_string = "Setup Shortcuts";
5439 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5441 setup_info = setup_info_shortcuts_4;
5442 title_string = "Setup Shortcuts";
5444 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5446 setup_info = setup_info_shortcuts_5;
5447 title_string = "Setup Shortcuts";
5450 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5454 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5456 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5459 void *value_ptr = setup_info[i].value;
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;
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);
5478 DrawCursorAndText_Setup(i, FALSE);
5480 if (setup_info[i].type & TYPE_VALUE)
5487 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5488 "Joysticks deactivated in setup menu");
5492 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5496 redraw_mask = REDRAW_ALL;
5499 FadeIn(redraw_mask);
5501 FadeIn(REDRAW_FIELD);
5506 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5510 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5512 static int choice_store[MAX_SETUP_MODES];
5513 int choice = choice_store[setup_mode]; /* always starts with 0 */
5517 if (button == MB_MENU_INITIALIZE)
5519 /* advance to first valid menu entry */
5520 while (choice < num_setup_info &&
5521 setup_info[choice].type & TYPE_SKIP_ENTRY)
5523 choice_store[setup_mode] = choice;
5525 DrawCursorAndText_Setup(choice, TRUE);
5529 else if (button == MB_MENU_LEAVE)
5531 PlaySound(SND_MENU_ITEM_SELECTING);
5533 // for (y = 0; y < num_setup_info; y++)
5534 for (y = 0; setup_info[y].type != 0; y++)
5536 if (setup_info[y].type & TYPE_LEAVE_MENU)
5538 void (*menu_callback_function)(void) = setup_info[y].value;
5542 menu_callback_function();
5544 break; /* absolutely needed because function changes 'setup_info'! */
5551 if (mx || my) /* mouse input */
5553 x = (mx - mSX) / 32;
5554 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5556 else if (dx || dy) /* keyboard input */
5560 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
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;
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)
5576 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5580 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5582 PlaySound(SND_MENU_ITEM_ACTIVATING);
5584 DrawCursorAndText_Setup(choice, FALSE);
5585 DrawCursorAndText_Setup(y, TRUE);
5587 choice = choice_store[setup_mode] = y;
5590 else if (!(setup_info[y].type & TYPE_GHOSTED))
5592 PlaySound(SND_MENU_ITEM_SELECTING);
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)
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)
5604 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5606 void (*menu_callback_function)(void) = setup_info[y].value;
5608 FadeSetFromType(setup_info[y].type);
5610 menu_callback_function();
5614 if (setup_info[y].type & TYPE_VALUE)
5615 changeSetupValue(y, dx);
5621 void DrawSetupScreen_Input()
5626 FadeOut(REDRAW_FIELD);
5632 setup_info = setup_info_input;
5635 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5639 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5640 "Joysticks deactivated on this screen");
5642 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5643 "Joysticks deactivated on this screen");
5648 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5650 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
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);
5660 DrawCursorAndText_Setup(i, FALSE);
5664 DeactivateJoystickForCalibration();
5669 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5670 "Joysticks deactivated on this screen");
5672 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5673 "Joysticks deactivated on this screen");
5677 /* create gadgets for setup input menu screen */
5678 FreeScreenGadgets();
5679 CreateScreenGadgets();
5681 /* map gadgets for setup input menu screen */
5682 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5684 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5687 FadeIn(REDRAW_FIELD);
5693 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5695 if (device_name == NULL)
5698 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5701 if (strlen(device_name) > 1)
5703 char c1 = device_name[strlen(device_name) - 1];
5704 char c2 = device_name[strlen(device_name) - 2];
5706 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5707 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5710 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5711 strlen(device_name));
5714 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5717 static struct SetupKeyboardInfo custom_key;
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" }
5731 static char *joystick_name[MAX_PLAYERS] =
5738 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5742 custom_key = setup.input[player_nr].key;
5744 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5745 FONT_INPUT_1_ACTIVE);
5747 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5749 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5750 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5752 if (setup.input[player_nr].use_joystick)
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);
5758 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5759 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5763 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5764 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5767 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
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);
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);
5781 for (i = 0; i < 6; i++)
5783 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5785 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5787 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5788 (setup.input[player_nr].use_joystick ?
5790 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5794 static int input_player_nr = 0;
5796 void HandleSetupScreen_Input_Player(int step, int direction)
5798 int old_player_nr = input_player_nr;
5801 new_player_nr = old_player_nr + step * direction;
5802 if (new_player_nr < 0)
5804 if (new_player_nr > MAX_PLAYERS - 1)
5805 new_player_nr = MAX_PLAYERS - 1;
5807 if (new_player_nr != old_player_nr)
5809 input_player_nr = new_player_nr;
5811 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5815 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5817 static int choice = 0;
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;
5825 if (button == MB_MENU_INITIALIZE)
5827 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5829 DrawCursorAndText_Setup(choice, TRUE);
5833 else if (button == MB_MENU_LEAVE)
5835 setup_mode = SETUP_MODE_MAIN;
5842 if (mx || my) /* mouse input */
5844 x = (mx - mSX) / 32;
5845 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5847 else if (dx || dy) /* keyboard input */
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;
5858 if (y >= pos_empty1 && y <= pos_empty2)
5859 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5862 if (y == 0 && dx != 0 && button)
5864 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5866 else if (IN_VIS_FIELD(x, y) &&
5867 y >= pos_start && y <= pos_end &&
5868 !(y >= pos_empty1 && y <= pos_empty2))
5874 DrawCursorAndText_Setup(choice, FALSE);
5875 DrawCursorAndText_Setup(y, TRUE);
5877 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5886 char *device_name = setup.input[input_player_nr].joy.device_name;
5888 if (!setup.input[input_player_nr].use_joystick)
5890 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5892 setJoystickDeviceToNr(device_name, new_device_nr);
5893 setup.input[input_player_nr].use_joystick = TRUE;
5897 int device_nr = getJoystickNrFromDeviceName(device_name);
5898 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5900 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5901 setup.input[input_player_nr].use_joystick = FALSE;
5903 setJoystickDeviceToNr(device_name, new_device_nr);
5906 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5910 if (setup.input[input_player_nr].use_joystick)
5913 CalibrateJoystick(input_player_nr);
5916 CustomizeKeyboard(input_player_nr);
5918 else if (y == pos_end)
5924 setup_mode = SETUP_MODE_MAIN;
5931 void CustomizeKeyboard(int player_nr)
5935 boolean finished = FALSE;
5936 static struct SetupKeyboardInfo custom_key;
5941 } customize_step[] =
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" }
5951 /* read existing key bindings from player setup */
5952 custom_key = setup.input[player_nr].key;
5955 FadeOut(REDRAW_FIELD);
5959 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
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);
5975 FadeIn(REDRAW_FIELD);
5982 if (PendingEvent()) /* got event */
5990 case EVENT_KEYPRESS:
5992 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5994 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5996 if (key == KSYM_Escape)
5997 FadeSkipNextFadeIn();
6003 /* all keys configured -- wait for "Escape" or "Return" key */
6007 /* press 'Enter' to keep the existing key binding */
6008 if (key == KSYM_Return)
6009 key = *customize_step[step_nr].key;
6011 /* check if key already used */
6012 for (i = 0; i < step_nr; i++)
6013 if (*customize_step[i].key == key)
6018 /* got new key binding */
6019 *customize_step[step_nr].key = key;
6020 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6022 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6023 getKeyNameFromKey(key), FONT_VALUE_1);
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);
6032 /* press 'Enter' to leave */
6035 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6036 "Press Enter", FONT_TITLE_1);
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),
6051 case EVENT_KEYRELEASE:
6052 key_joystick_mapping = 0;
6056 HandleOtherEvents(&event);
6064 /* don't eat all CPU time */
6068 /* write new key bindings back to player setup */
6069 setup.input[player_nr].key = custom_key;
6072 DrawSetupScreen_Input();
6075 static boolean CalibrateJoystickMain(int player_nr)
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;
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;
6091 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6094 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6098 FadeOut(REDRAW_FIELD);
6102 for (y = 0; y < 3; y++)
6104 for (x = 0; x < 3; x++)
6106 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6107 check[x][y] = FALSE;
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!");
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);
6123 /* eventually uncalibrated center position (joystick could be uncentered) */
6124 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6127 new_joystick_xmiddle = joy_x;
6128 new_joystick_ymiddle = joy_y;
6130 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6132 FadeIn(REDRAW_FIELD);
6134 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6139 if (PendingEvent()) /* got event */
6147 case EVENT_KEYPRESS:
6148 switch (GetEventKey((KeyEvent *)&event, TRUE))
6151 if (check_remaining == 0)
6156 FadeSkipNextFadeIn();
6165 case EVENT_KEYRELEASE:
6166 key_joystick_mapping = 0;
6170 HandleOtherEvents(&event);
6175 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
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);
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;
6190 CheckJoystickData();
6192 joy_value = Joystick(player_nr);
6194 if (joy_value & JOY_BUTTON && check_remaining == 0)
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);
6200 if (x != last_x || y != last_y)
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);
6210 if (check_remaining > 0 && !check[x+1][y+1])
6212 check[x+1][y+1] = TRUE;
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);
6234 /* don't eat all CPU time */
6238 /* calibrated center position (joystick should now be centered) */
6239 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6242 new_joystick_xmiddle = joy_x;
6243 new_joystick_ymiddle = joy_y;
6248 DrawSetupScreen_Input();
6251 /* wait until the last pressed button was released */
6252 while (Joystick(player_nr) & JOY_BUTTON)
6254 if (PendingEvent()) /* got event */
6259 HandleOtherEvents(&event);
6268 void CalibrateJoystick(int player_nr)
6270 if (!CalibrateJoystickMain(player_nr))
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;
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! ");
6283 Delay(2000); /* show error message for a short time */
6289 DrawSetupScreen_Input();
6293 void DrawSetupScreen()
6295 DeactivateJoystick();
6297 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
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);
6324 DrawSetupScreen_Generic();
6330 void RedrawSetupScreenAfterFullscreenToggle()
6333 if (setup_mode == SETUP_MODE_GRAPHICS ||
6334 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6336 // update list selection from "setup.window_scaling_percent"
6337 execSetupGraphics_setWindowSizes(TRUE);
6342 if (setup_mode == SETUP_MODE_GRAPHICS)
6347 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
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);
6374 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6381 void HandleGameActions()
6383 if (game_status != GAME_MODE_PLAYING)
6386 GameActions(); /* main game loop */
6388 if (tape.auto_play && !tape.playing)
6389 AutoPlayTape(); /* continue automatically playing next tape */
6393 /* ---------- new screen button stuff -------------------------------------- */
6395 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
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);
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);
6410 case SCREEN_CTRL_ID_PREV_LEVEL:
6411 *x = mSX + TILEX * getPrevlevelButtonPos();
6412 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6415 case SCREEN_CTRL_ID_NEXT_LEVEL:
6416 *x = mSX + TILEX * getNextLevelButtonPos();
6417 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6421 case SCREEN_CTRL_ID_PREV_PLAYER:
6422 *x = mSX + TILEX * 10;
6423 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6426 case SCREEN_CTRL_ID_NEXT_PLAYER:
6427 *x = mSX + TILEX * 12;
6428 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6432 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6438 int gfx_unpressed, gfx_pressed;
6439 void (*get_gadget_position)(int *, int *, int);
6443 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6446 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6447 getScreenMenuButtonPos,
6448 SCREEN_CTRL_ID_PREV_LEVEL,
6453 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6454 getScreenMenuButtonPos,
6455 SCREEN_CTRL_ID_NEXT_LEVEL,
6460 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6461 getScreenMenuButtonPos,
6462 SCREEN_CTRL_ID_PREV_PLAYER,
6467 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6468 getScreenMenuButtonPos,
6469 SCREEN_CTRL_ID_NEXT_PLAYER,
6477 int gfx_unpressed, gfx_pressed;
6481 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6484 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6486 -1, -1, /* these values are not constant, but can change at runtime */
6488 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6490 SCREEN_CTRL_ID_SCROLL_UP,
6494 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6496 -1, -1, /* these values are not constant, but can change at runtime */
6498 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6500 SCREEN_CTRL_ID_SCROLL_DOWN,
6507 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6508 Bitmap **gfx_unpressed, **gfx_pressed;
6510 int gfx_unpressed, gfx_pressed;
6517 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6520 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6521 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6523 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
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 */
6529 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6530 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6532 GD_TYPE_SCROLLBAR_VERTICAL,
6533 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6534 "scroll level series vertically"
6538 static void CreateScreenMenubuttons()
6540 struct GadgetInfo *gi;
6541 unsigned int event_mask;
6544 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
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;
6552 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6554 menubutton_info[i].get_gadget_position(&x, &y, id);
6556 width = SC_MENUBUTTON_XSIZE;
6557 height = SC_MENUBUTTON_YSIZE;
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;
6568 gi = CreateGadget(GDI_CUSTOM_ID, id,
6569 GDI_CUSTOM_TYPE_ID, i,
6570 GDI_INFO_TEXT, menubutton_info[i].infotext,
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,
6585 Error(ERR_EXIT, "cannot create gadget");
6587 screen_gadget[id] = gi;
6591 static void CreateScreenScrollbuttons()
6593 struct GadgetInfo *gi;
6594 unsigned int event_mask;
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;
6603 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
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;
6611 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
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;
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);
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;
6631 gi = CreateGadget(GDI_CUSTOM_ID, id,
6632 GDI_CUSTOM_TYPE_ID, i,
6633 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
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,
6648 Error(ERR_EXIT, "cannot create gadget");
6650 screen_gadget[id] = gi;
6654 static void CreateScreenScrollbars()
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;
6664 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6666 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6667 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6668 int gfx_unpressed, gfx_pressed;
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;
6678 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
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;
6685 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6686 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6688 items_max = num_page_entries;
6689 items_visible = num_page_entries;
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;
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;
6710 gi = CreateGadget(GDI_CUSTOM_ID, id,
6711 GDI_CUSTOM_TYPE_ID, i,
6712 GDI_INFO_TEXT, scrollbar_info[i].infotext,
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,
6722 GDI_WHEEL_AREA_X, SX,
6723 GDI_WHEEL_AREA_Y, SY,
6724 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6725 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
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,
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,
6742 Error(ERR_EXIT, "cannot create gadget");
6744 screen_gadget[id] = gi;
6748 void CreateScreenGadgets()
6750 int last_game_status = game_status; /* save current game status */
6752 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6755 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6757 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
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;
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);
6773 CreateScreenMenubuttons();
6776 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6777 game_status = GAME_MODE_LEVELS;
6780 CreateScreenScrollbuttons();
6781 CreateScreenScrollbars();
6783 game_status = last_game_status; /* restore current game status */
6786 void FreeScreenGadgets()
6790 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6791 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6793 /* prevent freeing clip mask and GC twice */
6794 scrollbar_bitmap[i]->clip_mask = None;
6795 scrollbar_bitmap[i]->stored_clip_gc = None;
6797 FreeBitmap(scrollbar_bitmap[i]);
6801 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6802 FreeGadget(screen_gadget[i]);
6805 void MapScreenMenuGadgets(int screen_mask)
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]);
6814 void MapScreenTreeGadgets(TreeInfo *ti)
6816 int num_entries = numTreeInfoInGroup(ti);
6819 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6822 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6823 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6825 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6826 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6829 static void HandleScreenGadgets(struct GadgetInfo *gi)
6831 int id = gi->custom_id;
6832 int button = gi->event.button;
6833 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6837 case SCREEN_CTRL_ID_PREV_LEVEL:
6838 HandleMainMenu_SelectLevel(step, -1);
6841 case SCREEN_CTRL_ID_NEXT_LEVEL:
6842 HandleMainMenu_SelectLevel(step, +1);
6845 case SCREEN_CTRL_ID_PREV_PLAYER:
6846 HandleSetupScreen_Input_Player(step, -1);
6849 case SCREEN_CTRL_ID_NEXT_PLAYER:
6850 HandleSetupScreen_Input_Player(step, +1);
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);
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);
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);