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;
1883 DrawChooseLevelNr();
1885 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1891 PlaySound(SND_MENU_ITEM_ACTIVATING);
1893 DrawCursorAndText_Main(choice, FALSE);
1894 DrawCursorAndText_Main(pos, TRUE);
1901 PlaySound(SND_MENU_ITEM_SELECTING);
1903 if (pos == MAIN_CONTROL_NAME)
1905 game_status = GAME_MODE_PSEUDO_TYPENAME;
1907 HandleTypeName(strlen(setup.player_name), 0);
1909 else if (pos == MAIN_CONTROL_LEVELS)
1913 game_status = GAME_MODE_LEVELS;
1915 SaveLevelSetup_LastSeries();
1916 SaveLevelSetup_SeriesInfo();
1918 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1922 DrawChooseLevelSet();
1925 else if (pos == MAIN_CONTROL_SCORES)
1927 game_status = GAME_MODE_SCORES;
1931 else if (pos == MAIN_CONTROL_EDITOR)
1933 if (leveldir_current->readonly &&
1934 !strEqual(setup.player_name, "Artsoft"))
1935 Request("This level is read only!", REQ_CONFIRM);
1937 CloseDoor(DOOR_CLOSE_2);
1939 game_status = GAME_MODE_EDITOR;
1941 FadeSetEnterScreen();
1944 /* needed if different viewport properties defined for editor */
1945 ChangeViewportPropertiesIfNeeded();
1950 else if (pos == MAIN_CONTROL_INFO)
1952 game_status = GAME_MODE_INFO;
1953 info_mode = INFO_MODE_MAIN;
1957 else if (pos == MAIN_CONTROL_GAME)
1959 StartGameActions(options.network, setup.autorecord, level.random_seed);
1961 else if (pos == MAIN_CONTROL_SETUP)
1963 game_status = GAME_MODE_SETUP;
1964 setup_mode = SETUP_MODE_MAIN;
1967 ChangeViewportPropertiesIfNeeded();
1972 else if (pos == MAIN_CONTROL_QUIT)
1974 SaveLevelSetup_LastSeries();
1975 SaveLevelSetup_SeriesInfo();
1977 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1978 game_status = GAME_MODE_QUIT;
1984 if (game_status == GAME_MODE_MAIN)
1986 DrawPreviewLevelAnimation();
1993 /* ========================================================================= */
1994 /* info screen functions */
1995 /* ========================================================================= */
1997 static struct TokenInfo *info_info;
1998 static int num_info_info;
2000 static void execInfoTitleScreen()
2002 info_mode = INFO_MODE_TITLE;
2007 static void execInfoElements()
2009 info_mode = INFO_MODE_ELEMENTS;
2014 static void execInfoMusic()
2016 info_mode = INFO_MODE_MUSIC;
2021 static void execInfoCredits()
2023 info_mode = INFO_MODE_CREDITS;
2028 static void execInfoProgram()
2030 info_mode = INFO_MODE_PROGRAM;
2035 static void execInfoVersion()
2037 info_mode = INFO_MODE_VERSION;
2042 static void execInfoLevelSet()
2044 info_mode = INFO_MODE_LEVELSET;
2049 static void execExitInfo()
2051 game_status = GAME_MODE_MAIN;
2053 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2056 static struct TokenInfo info_info_main[] =
2058 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2059 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2060 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2061 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2062 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2063 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2064 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2065 { TYPE_EMPTY, NULL, "" },
2066 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2071 static void DrawCursorAndText_Info(int pos, boolean active)
2073 int xpos = MENU_SCREEN_START_XPOS;
2074 int ypos = MENU_SCREEN_START_YPOS + pos;
2075 int font_nr = FONT_MENU_1;
2078 font_nr = FONT_ACTIVE(font_nr);
2080 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2082 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2083 drawCursor(pos, active);
2086 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2091 CloseDoor(DOOR_CLOSE_2);
2093 /* (needed after displaying title screens which disable auto repeat) */
2094 KeyboardAutoRepeatOn();
2096 FadeSetLeaveScreen();
2103 if (fade_mask == REDRAW_ALL)
2107 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2113 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2115 info_info = info_info_main;
2119 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2121 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2124 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2125 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2126 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2127 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2128 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2129 initCursor(i, IMG_MENU_BUTTON);
2131 DrawCursorAndText_Info(i, FALSE);
2136 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2141 DrawMaskedBorder(fade_mask);
2148 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2150 static int choice_store[MAX_INFO_MODES];
2151 int choice = choice_store[info_mode]; /* always starts with 0 */
2155 if (button == MB_MENU_INITIALIZE)
2157 /* advance to first valid menu entry */
2158 while (choice < num_info_info &&
2159 info_info[choice].type & TYPE_SKIP_ENTRY)
2161 choice_store[info_mode] = choice;
2163 DrawCursorAndText_Info(choice, TRUE);
2167 else if (button == MB_MENU_LEAVE)
2169 for (y = 0; y < num_info_info; y++)
2171 if (info_info[y].type & TYPE_LEAVE_MENU)
2173 void (*menu_callback_function)(void) = info_info[y].value;
2177 menu_callback_function();
2179 break; /* absolutely needed because function changes 'info_info'! */
2186 if (mx || my) /* mouse input */
2188 x = (mx - mSX) / 32;
2189 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2191 else if (dx || dy) /* keyboard input */
2195 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2197 if (info_info[choice].type & menu_navigation_type ||
2198 info_info[choice].type & TYPE_ENTER_SCREEN ||
2199 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2200 info_info[choice].type & TYPE_YES_NO_AUTO)
2201 button = MB_MENU_CHOICE;
2206 /* jump to next non-empty menu entry (up or down) */
2207 while (y > 0 && y < num_info_info - 1 &&
2208 info_info[y].type & TYPE_SKIP_ENTRY)
2212 if (IN_VIS_FIELD(x, y) &&
2213 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2219 PlaySound(SND_MENU_ITEM_ACTIVATING);
2221 DrawCursorAndText_Info(choice, FALSE);
2222 DrawCursorAndText_Info(y, TRUE);
2224 choice = choice_store[info_mode] = y;
2227 else if (!(info_info[y].type & TYPE_GHOSTED))
2229 PlaySound(SND_MENU_ITEM_SELECTING);
2231 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2233 void (*menu_callback_function)(void) = info_info[choice].value;
2235 FadeSetFromType(info_info[y].type);
2237 menu_callback_function();
2243 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2245 int ystart1 = mSY - SY + 100;
2246 int ystart2 = mSY - SY + 150;
2247 int ybottom = mSY - SY + SYSIZE - 20;
2249 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2251 FadeOut(REDRAW_FIELD);
2256 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2257 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2259 DrawTextSCentered(ybottom, FONT_TEXT_4,
2260 "Press any key or button for info menu");
2262 FadeIn(REDRAW_FIELD);
2265 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2267 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2268 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2269 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2270 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2271 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2272 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2273 int ystep = MENU_SCREEN_INFO_YSTEP;
2274 int element, action, direction;
2282 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2283 infoscreen_step[i] = infoscreen_frame[i] = 0;
2288 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2290 DrawTextSCentered(ybottom, FONT_TEXT_4,
2291 "Press any key or button for next page");
2297 while (helpanim_info[j].element != HELPANIM_LIST_END)
2299 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2304 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2313 j += infoscreen_step[i - start];
2315 element = helpanim_info[j].element;
2316 action = helpanim_info[j].action;
2317 direction = helpanim_info[j].direction;
2320 element = EL_UNKNOWN;
2322 if (action != -1 && direction != -1)
2323 graphic = el_act_dir2img(element, action, direction);
2324 else if (action != -1)
2325 graphic = el_act2img(element, action);
2326 else if (direction != -1)
2327 graphic = el_dir2img(element, direction);
2329 graphic = el2img(element);
2331 delay = helpanim_info[j++].delay;
2336 if (infoscreen_frame[i - start] == 0)
2339 infoscreen_frame[i - start] = delay - 1;
2343 sync_frame = delay - infoscreen_frame[i - start];
2344 infoscreen_frame[i - start]--;
2347 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2349 if (!infoscreen_frame[i - start])
2350 infoscreen_step[i - start] = 0;
2354 if (!infoscreen_frame[i - start])
2355 infoscreen_step[i - start]++;
2356 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2362 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2364 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2365 graphic, sync_frame, USE_MASKING);
2368 DrawInfoScreen_HelpText(element, action, direction, i - start);
2373 redraw_mask |= REDRAW_FIELD;
2378 static char *getHelpText(int element, int action, int direction)
2380 char token[MAX_LINE_LEN];
2382 strcpy(token, element_info[element].token_name);
2385 strcat(token, element_action_info[action].suffix);
2387 if (direction != -1)
2388 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2390 return getHashEntry(helptext_info, token);
2393 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2395 int font_nr = FONT_INFO_ELEMENTS;
2396 int font_width = getFontWidth(font_nr);
2397 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2398 int sy = mSY + 65 + 2 * 32 + 1;
2399 int ystep = TILEY + 4;
2400 int pad_x = sx - SX;
2401 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2402 int max_lines_per_text = 2;
2405 if (action != -1 && direction != -1) /* element.action.direction */
2406 text = getHelpText(element, action, direction);
2408 if (text == NULL && action != -1) /* element.action */
2409 text = getHelpText(element, action, -1);
2411 if (text == NULL && direction != -1) /* element.direction */
2412 text = getHelpText(element, -1, direction);
2414 if (text == NULL) /* base element */
2415 text = getHelpText(element, -1, -1);
2417 if (text == NULL) /* not found */
2418 text = "No description available";
2420 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2421 sy += getFontHeight(font_nr) / 2;
2423 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2424 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2425 TRUE, FALSE, FALSE);
2428 void DrawInfoScreen_TitleScreen()
2433 void HandleInfoScreen_TitleScreen(int button)
2435 HandleTitleScreen(0, 0, 0, 0, button);
2438 void DrawInfoScreen_Elements()
2440 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2442 FadeOut(REDRAW_FIELD);
2447 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2449 FadeIn(REDRAW_FIELD);
2454 void HandleInfoScreen_Elements(int button)
2456 static unsigned int info_delay = 0;
2457 static int num_anims;
2458 static int num_pages;
2460 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2463 if (button == MB_MENU_INITIALIZE)
2465 boolean new_element = TRUE;
2469 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2471 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2473 else if (new_element)
2476 new_element = FALSE;
2480 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2484 if (button == MB_MENU_LEAVE)
2486 PlaySound(SND_MENU_ITEM_SELECTING);
2488 info_mode = INFO_MODE_MAIN;
2493 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2495 if (button != MB_MENU_INITIALIZE)
2497 PlaySound(SND_MENU_ITEM_SELECTING);
2502 if (page >= num_pages)
2504 FadeSoundsAndMusic();
2506 info_mode = INFO_MODE_MAIN;
2507 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2514 FadeSetNextScreen();
2517 if (button != MB_MENU_INITIALIZE)
2518 FadeOut(REDRAW_FIELD);
2520 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2522 if (button != MB_MENU_INITIALIZE)
2523 FadeIn(REDRAW_FIELD);
2527 if (DelayReached(&info_delay, GameFrameDelay))
2528 if (page < num_pages)
2529 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2531 PlayMenuSoundIfLoop();
2535 void DrawInfoScreen_Music()
2537 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2540 FadeOut(REDRAW_FIELD);
2548 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2551 FadeIn(REDRAW_FIELD);
2555 void HandleInfoScreen_Music(int button)
2557 static struct MusicFileInfo *list = NULL;
2558 int ystart1 = mSY - SY + 100;
2559 int ystart2 = mSY - SY + 150;
2560 int ybottom = mSY - SY + SYSIZE - 20;
2563 if (button == MB_MENU_INITIALIZE)
2565 list = music_file_info;
2569 FadeSoundsAndMusic();
2574 DrawTextSCentered(ystart1, FONT_TEXT_1,
2575 "No music info for this level set.");
2577 DrawTextSCentered(ybottom, FONT_TEXT_4,
2578 "Press any key or button for info menu");
2584 if (button == MB_MENU_LEAVE)
2586 PlaySound(SND_MENU_ITEM_SELECTING);
2588 FadeSoundsAndMusic();
2590 info_mode = INFO_MODE_MAIN;
2595 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2599 if (button != MB_MENU_INITIALIZE)
2601 PlaySound(SND_MENU_ITEM_SELECTING);
2609 FadeSoundsAndMusic();
2611 info_mode = INFO_MODE_MAIN;
2612 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2617 FadeSoundsAndMusic();
2620 if (list != music_file_info)
2621 FadeSetNextScreen();
2624 if (button != MB_MENU_INITIALIZE)
2625 FadeOut(REDRAW_FIELD);
2632 int sound = list->music;
2634 if (sound_info[sound].loop)
2635 PlaySoundLoop(sound);
2639 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2643 PlayMusic(list->music);
2645 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2648 if (!strEqual(list->title, UNKNOWN_NAME))
2650 if (!strEqual(list->title_header, UNKNOWN_NAME))
2651 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2653 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2656 if (!strEqual(list->artist, UNKNOWN_NAME))
2658 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2659 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2661 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2663 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2666 if (!strEqual(list->album, UNKNOWN_NAME))
2668 if (!strEqual(list->album_header, UNKNOWN_NAME))
2669 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2671 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2673 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2676 if (!strEqual(list->year, UNKNOWN_NAME))
2678 if (!strEqual(list->year_header, UNKNOWN_NAME))
2679 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2681 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2683 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2686 DrawTextSCentered(ybottom, FONT_TEXT_4,
2687 "Press any key or button for next page");
2689 if (button != MB_MENU_INITIALIZE)
2690 FadeIn(REDRAW_FIELD);
2693 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2694 PlaySoundLoop(list->music);
2697 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2699 int ystart1 = mSY - SY + 100;
2700 int ystart2 = mSY - SY + 150;
2701 int ybottom = mSY - SY + SYSIZE - 20;
2707 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2711 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2712 "Special thanks to");
2713 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2715 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2717 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2718 "\"Boulder Dash\"");
2719 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2721 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2723 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2725 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2726 "First Star Software");
2728 else if (screen_nr == 1)
2730 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2731 "Special thanks to");
2732 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2733 "Klaus Heinz & Volker Wertich");
2734 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2736 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2737 "\"Emerald Mine\"");
2738 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2740 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2742 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2744 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2747 else if (screen_nr == 2)
2749 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2750 "Special thanks to");
2751 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2752 "Michael Stopp & Philip Jespersen");
2753 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2755 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2757 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2759 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2761 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2763 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2764 "Digital Integration");
2766 else if (screen_nr == 3)
2768 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2769 "Special thanks to");
2770 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2771 "Hiroyuki Imabayashi");
2772 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2774 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2776 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2778 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2780 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2782 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2785 else if (screen_nr == 4)
2787 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2788 "Special thanks to");
2789 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2791 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2793 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2794 "Jürgen Bonhagen");
2795 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2796 "for the continuous creation");
2797 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2798 "of outstanding level sets");
2800 else if (screen_nr == 5)
2802 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2804 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2806 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2807 "for ideas and inspiration by");
2808 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2811 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2813 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2815 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2816 "for ideas and inspiration by");
2817 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2820 else if (screen_nr == 6)
2822 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2824 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2827 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2828 "for the code base used for the");
2829 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2830 "native Emerald Mine engine");
2832 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2833 "for the new Emerald Mine engine");
2836 else if (screen_nr == 7)
2838 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2840 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2842 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2843 "for the initial DOS port");
2845 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2847 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2849 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2850 "for some additional toons");
2852 else if (screen_nr == 8)
2854 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2855 "And not to forget:");
2856 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2858 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2859 "All those who contributed");
2860 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2861 "levels to this game");
2862 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2866 DrawTextSCentered(ybottom, FONT_TEXT_4,
2867 "Press any key or button for next page");
2870 void DrawInfoScreen_Credits()
2872 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2874 FadeSoundsAndMusic();
2877 FadeOut(REDRAW_FIELD);
2880 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2883 FadeIn(REDRAW_FIELD);
2887 void HandleInfoScreen_Credits(int button)
2889 static int screen_nr = 0;
2890 int num_screens = 9;
2892 if (button == MB_MENU_INITIALIZE)
2896 // DrawInfoScreen_CreditsScreen(screen_nr);
2899 if (button == MB_MENU_LEAVE)
2901 PlaySound(SND_MENU_ITEM_SELECTING);
2903 info_mode = INFO_MODE_MAIN;
2908 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2910 if (button != MB_MENU_INITIALIZE)
2912 PlaySound(SND_MENU_ITEM_SELECTING);
2917 if (screen_nr >= num_screens)
2919 FadeSoundsAndMusic();
2921 info_mode = INFO_MODE_MAIN;
2922 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2929 FadeSetNextScreen();
2932 if (button != MB_MENU_INITIALIZE)
2933 FadeOut(REDRAW_FIELD);
2935 DrawInfoScreen_CreditsScreen(screen_nr);
2937 if (button != MB_MENU_INITIALIZE)
2938 FadeIn(REDRAW_FIELD);
2942 PlayMenuSoundIfLoop();
2946 void DrawInfoScreen_Program()
2948 int ystart1 = mSY - SY + 100;
2949 int ystart2 = mSY - SY + 150;
2950 int ybottom = mSY - SY + SYSIZE - 20;
2953 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2956 FadeOut(REDRAW_FIELD);
2962 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2964 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2965 "This game is Freeware!");
2966 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2967 "If you like it, send e-mail to:");
2968 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2969 PROGRAM_EMAIL_STRING);
2971 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2972 "More information and levels:");
2973 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2974 PROGRAM_WEBSITE_STRING);
2975 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2976 "If you have created new levels,");
2977 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2978 "send them to me to include them!");
2979 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2982 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2983 "or SnailMail to:");
2984 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2986 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2987 "Detmolder Strasse 189");
2988 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2990 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2992 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2993 "More information and levels:");
2994 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2995 PROGRAM_WEBSITE_STRING);
2996 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2997 "If you have created new levels,");
2998 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2999 "send them to me to include them!");
3000 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3004 DrawTextSCentered(ybottom, FONT_TEXT_4,
3005 "Press any key or button for info menu");
3008 FadeIn(REDRAW_FIELD);
3012 void HandleInfoScreen_Program(int button)
3014 if (button == MB_MENU_LEAVE)
3016 PlaySound(SND_MENU_ITEM_SELECTING);
3018 info_mode = INFO_MODE_MAIN;
3023 else if (button == MB_MENU_CHOICE)
3025 PlaySound(SND_MENU_ITEM_SELECTING);
3027 FadeSoundsAndMusic();
3030 FadeOut(REDRAW_FIELD);
3033 info_mode = INFO_MODE_MAIN;
3034 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3038 PlayMenuSoundIfLoop();
3042 void DrawInfoScreen_Version()
3044 int font_header = FONT_TEXT_3;
3045 int font_text = FONT_TEXT_2;
3046 int xstep = getFontWidth(font_text);
3047 int ystep = getFontHeight(font_text);
3048 int ystart1 = mSY - SY + 100;
3049 int ystart2 = mSY - SY + 150;
3050 int ybottom = mSY - SY + SYSIZE - 20;
3051 int xstart1 = mSX - SX + 2 * xstep;
3052 int xstart2 = mSX - SX + 18 * xstep;
3053 #if defined(TARGET_SDL)
3054 int xstart3 = mSX - SX + 28 * xstep;
3055 SDL_version sdl_version_compiled;
3056 const SDL_version *sdl_version_linked;
3057 int driver_name_len = 10;
3058 #if defined(TARGET_SDL2)
3059 SDL_version sdl_version_linked_ext;
3060 const char *driver_name = NULL;
3062 char driver_name[driver_name_len];
3066 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3069 FadeOut(REDRAW_FIELD);
3075 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3077 DrawTextF(xstart1, ystart2, font_header, "Name");
3078 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3081 DrawTextF(xstart1, ystart2, font_header, "Version");
3082 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3085 DrawTextF(xstart1, ystart2, font_header, "Platform");
3086 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3089 DrawTextF(xstart1, ystart2, font_header, "Target");
3090 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3093 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3094 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3096 #if defined(TARGET_SDL)
3097 ystart2 += 3 * ystep;
3098 DrawTextF(xstart1, ystart2, font_header, "Library");
3099 DrawTextF(xstart2, ystart2, font_header, "compiled");
3100 DrawTextF(xstart3, ystart2, font_header, "linked");
3102 SDL_VERSION(&sdl_version_compiled);
3103 #if defined(TARGET_SDL2)
3104 SDL_GetVersion(&sdl_version_linked_ext);
3105 sdl_version_linked = &sdl_version_linked_ext;
3107 sdl_version_linked = SDL_Linked_Version();
3110 ystart2 += 2 * ystep;
3111 DrawTextF(xstart1, ystart2, font_text, "SDL");
3112 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3113 sdl_version_compiled.major,
3114 sdl_version_compiled.minor,
3115 sdl_version_compiled.patch);
3116 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3117 sdl_version_linked->major,
3118 sdl_version_linked->minor,
3119 sdl_version_linked->patch);
3121 SDL_IMAGE_VERSION(&sdl_version_compiled);
3122 sdl_version_linked = IMG_Linked_Version();
3125 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3126 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3127 sdl_version_compiled.major,
3128 sdl_version_compiled.minor,
3129 sdl_version_compiled.patch);
3130 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3131 sdl_version_linked->major,
3132 sdl_version_linked->minor,
3133 sdl_version_linked->patch);
3135 SDL_MIXER_VERSION(&sdl_version_compiled);
3136 sdl_version_linked = Mix_Linked_Version();
3139 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3140 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3141 sdl_version_compiled.major,
3142 sdl_version_compiled.minor,
3143 sdl_version_compiled.patch);
3144 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3145 sdl_version_linked->major,
3146 sdl_version_linked->minor,
3147 sdl_version_linked->patch);
3149 SDL_NET_VERSION(&sdl_version_compiled);
3150 sdl_version_linked = SDLNet_Linked_Version();
3153 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3154 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3155 sdl_version_compiled.major,
3156 sdl_version_compiled.minor,
3157 sdl_version_compiled.patch);
3158 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3159 sdl_version_linked->major,
3160 sdl_version_linked->minor,
3161 sdl_version_linked->patch);
3163 ystart2 += 3 * ystep;
3164 DrawTextF(xstart1, ystart2, font_header, "Driver");
3165 DrawTextF(xstart2, ystart2, font_header, "Requested");
3166 DrawTextF(xstart3, ystart2, font_header, "Used");
3168 #if defined(TARGET_SDL2)
3169 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3171 SDL_VideoDriverName(driver_name, driver_name_len);
3174 ystart2 += 2 * ystep;
3175 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3176 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3177 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3179 #if defined(TARGET_SDL2)
3180 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3182 SDL_AudioDriverName(driver_name, driver_name_len);
3186 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3187 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3188 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3191 DrawTextSCentered(ybottom, FONT_TEXT_4,
3192 "Press any key or button for info menu");
3195 FadeIn(REDRAW_FIELD);
3199 void HandleInfoScreen_Version(int button)
3201 if (button == MB_MENU_LEAVE)
3203 PlaySound(SND_MENU_ITEM_SELECTING);
3205 info_mode = INFO_MODE_MAIN;
3210 else if (button == MB_MENU_CHOICE)
3212 PlaySound(SND_MENU_ITEM_SELECTING);
3214 FadeSoundsAndMusic();
3217 FadeOut(REDRAW_FIELD);
3220 info_mode = INFO_MODE_MAIN;
3221 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3225 PlayMenuSoundIfLoop();
3229 void DrawInfoScreen_LevelSet()
3231 struct TitleMessageInfo *tmi = &readme;
3232 char *filename = getLevelSetInfoFilename();
3234 /* if chars set to "-1", automatically determine by text and font width */
3235 if (tmi->chars == -1)
3236 tmi->chars = tmi->width / getFontWidth(tmi->font);
3238 tmi->width = tmi->chars * getFontWidth(tmi->font);
3240 /* if lines set to "-1", automatically determine by text and font height */
3241 if (tmi->lines == -1)
3242 tmi->lines = tmi->height / getFontHeight(tmi->font);
3244 tmi->height = tmi->lines * getFontHeight(tmi->font);
3246 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3249 FadeOut(REDRAW_FIELD);
3255 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3257 if (filename != NULL)
3258 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3259 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3260 tmi->autowrap, tmi->centered, tmi->parse_comments);
3262 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3263 "No information for this level set.");
3265 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3266 "Press any key or button for info menu");
3269 FadeIn(REDRAW_FIELD);
3273 void HandleInfoScreen_LevelSet(int button)
3275 if (button == MB_MENU_LEAVE)
3277 PlaySound(SND_MENU_ITEM_SELECTING);
3279 info_mode = INFO_MODE_MAIN;
3284 else if (button == MB_MENU_CHOICE)
3286 PlaySound(SND_MENU_ITEM_SELECTING);
3288 FadeSoundsAndMusic();
3291 FadeOut(REDRAW_FIELD);
3294 info_mode = INFO_MODE_MAIN;
3295 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3299 PlayMenuSoundIfLoop();
3303 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3305 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3307 if (info_mode == INFO_MODE_TITLE)
3308 DrawInfoScreen_TitleScreen();
3309 else if (info_mode == INFO_MODE_ELEMENTS)
3310 DrawInfoScreen_Elements();
3311 else if (info_mode == INFO_MODE_MUSIC)
3312 DrawInfoScreen_Music();
3313 else if (info_mode == INFO_MODE_CREDITS)
3314 DrawInfoScreen_Credits();
3315 else if (info_mode == INFO_MODE_PROGRAM)
3316 DrawInfoScreen_Program();
3317 else if (info_mode == INFO_MODE_VERSION)
3318 DrawInfoScreen_Version();
3319 else if (info_mode == INFO_MODE_LEVELSET)
3320 DrawInfoScreen_LevelSet();
3322 DrawInfoScreen_Main(fade_mask, do_fading);
3324 if (info_mode != INFO_MODE_MAIN &&
3325 info_mode != INFO_MODE_TITLE &&
3326 info_mode != INFO_MODE_MUSIC)
3333 void DrawAndFadeInInfoScreen(int fade_mask)
3335 DrawInfoScreenExt(fade_mask, TRUE);
3338 void DrawInfoScreen()
3340 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3343 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3345 if (info_mode == INFO_MODE_TITLE)
3346 HandleInfoScreen_TitleScreen(button);
3347 else if (info_mode == INFO_MODE_ELEMENTS)
3348 HandleInfoScreen_Elements(button);
3349 else if (info_mode == INFO_MODE_MUSIC)
3350 HandleInfoScreen_Music(button);
3351 else if (info_mode == INFO_MODE_CREDITS)
3352 HandleInfoScreen_Credits(button);
3353 else if (info_mode == INFO_MODE_PROGRAM)
3354 HandleInfoScreen_Program(button);
3355 else if (info_mode == INFO_MODE_VERSION)
3356 HandleInfoScreen_Version(button);
3357 else if (info_mode == INFO_MODE_LEVELSET)
3358 HandleInfoScreen_LevelSet(button);
3360 HandleInfoScreen_Main(mx, my, dx, dy, button);
3368 /* ========================================================================= */
3369 /* type name functions */
3370 /* ========================================================================= */
3372 void HandleTypeName(int newxpos, Key key)
3374 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3375 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3376 struct TextPosInfo *pos = mci->pos_input;
3377 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3378 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3379 static int xpos = 0;
3380 int font_nr = pos->font;
3381 int font_active_nr = FONT_ACTIVE(font_nr);
3382 int font_width = getFontWidth(font_active_nr);
3383 char key_char = getValidConfigValueChar(getCharFromKey(key));
3384 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3385 boolean is_active = TRUE;
3387 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3391 strcpy(last_player_name, setup.player_name);
3395 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3397 setup.player_name[xpos] = key_char;
3398 setup.player_name[xpos + 1] = 0;
3402 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3406 setup.player_name[xpos] = 0;
3408 else if (key == KSYM_Return && xpos > 0)
3414 game_status = GAME_MODE_MAIN;
3416 else if (key == KSYM_Escape)
3418 strcpy(setup.player_name, last_player_name);
3422 game_status = GAME_MODE_MAIN;
3427 pos->width = (strlen(setup.player_name) + 1) * font_width;
3428 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3430 DrawText(startx, starty, setup.player_name, font_active_nr);
3431 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3435 pos->width = strlen(setup.player_name) * font_width;
3436 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3438 DrawText(startx, starty, setup.player_name, font_nr);
3443 /* ========================================================================= */
3444 /* tree menu functions */
3445 /* ========================================================================= */
3447 static void DrawChooseTree(TreeInfo **ti_ptr)
3451 FreeScreenGadgets();
3452 CreateScreenGadgets();
3454 CloseDoor(DOOR_CLOSE_2);
3457 FadeOut(REDRAW_FIELD);
3462 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3463 MapScreenTreeGadgets(*ti_ptr);
3466 FadeIn(REDRAW_FIELD);
3472 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3474 struct GadgetInfo *gi = screen_gadget[id];
3475 int items_max, items_visible, item_position;
3477 items_max = numTreeInfoInGroup(ti);
3478 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3479 item_position = first_entry;
3481 if (item_position > items_max - items_visible)
3482 item_position = items_max - items_visible;
3484 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3485 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3486 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3489 static void drawChooseTreeList(int first_entry, int num_page_entries,
3493 char *title_string = NULL;
3494 int yoffset_sets = MENU_TITLE1_YPOS;
3495 int yoffset_setup = 16;
3496 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3497 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3498 int last_game_status = game_status; /* save current game status */
3500 title_string = ti->infotext;
3502 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3505 /* force LEVELS font on artwork setup screen */
3506 game_status = GAME_MODE_LEVELS;
3510 /* clear tree list area, but not title or scrollbar */
3511 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3512 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3513 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3515 /* clear tree list area, but not title or scrollbar */
3516 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3517 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3518 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3521 for (i = 0; i < num_page_entries; i++)
3523 TreeInfo *node, *node_first;
3524 int entry_pos = first_entry + i;
3525 int xpos = MENU_SCREEN_START_XPOS;
3526 int ypos = MENU_SCREEN_START_YPOS + i;
3527 int startx = mSX + xpos * 32;
3528 int starty = mSY + ypos * 32;
3529 int font_nr = FONT_TEXT_1;
3530 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3531 int startx_text = startx + font_xoffset;
3532 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3533 int text_size = startx_scrollbar - startx_text;
3534 int max_buffer_len = text_size / getFontWidth(font_nr);
3535 char buffer[max_buffer_len + 1];
3537 node_first = getTreeInfoFirstGroupEntry(ti);
3538 node = getTreeInfoFromPos(node_first, entry_pos);
3540 strncpy(buffer, node->name, max_buffer_len);
3541 buffer[max_buffer_len] = '\0';
3543 DrawText(startx, starty, buffer, font_nr + node->color);
3545 if (node->parent_link)
3546 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3547 else if (node->level_group)
3548 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3550 initCursor(i, IMG_MENU_BUTTON);
3553 game_status = last_game_status; /* restore current game status */
3555 redraw_mask |= REDRAW_FIELD;
3558 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3560 TreeInfo *node, *node_first;
3561 int x, last_redraw_mask = redraw_mask;
3562 int ypos = MENU_TITLE2_YPOS;
3563 int font_nr = FONT_TITLE_2;
3565 if (ti->type == TREE_TYPE_LEVEL_NR)
3566 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3568 if (ti->type != TREE_TYPE_LEVEL_DIR)
3571 node_first = getTreeInfoFirstGroupEntry(ti);
3572 node = getTreeInfoFromPos(node_first, entry_pos);
3574 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3577 if (node->parent_link)
3578 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3579 node->node_parent->name);
3580 else if (node->level_group)
3581 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3583 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3584 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3585 node->levels, (node->levels > 1 ? "levels" : "level"),
3588 if (node->parent_link)
3589 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3591 else if (node->level_group)
3592 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3594 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3595 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3596 node->levels, node->class_desc);
3599 /* let BackToFront() redraw only what is needed */
3600 redraw_mask = last_redraw_mask | REDRAW_TILES;
3601 for (x = 0; x < SCR_FIELDX; x++)
3602 MarkTileDirty(x, 1);
3605 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3608 TreeInfo *ti = *ti_ptr;
3610 int y = ti->cl_cursor;
3611 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3612 int num_entries = numTreeInfoInGroup(ti);
3613 int num_page_entries;
3614 int last_game_status = game_status; /* save current game status */
3615 boolean position_set_by_scrollbar = (dx == 999);
3618 /* force LEVELS draw offset on choose level and artwork setup screen */
3619 game_status = GAME_MODE_LEVELS;
3622 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3623 num_page_entries = num_entries;
3625 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3627 game_status = last_game_status; /* restore current game status */
3629 if (button == MB_MENU_INITIALIZE)
3631 int num_entries = numTreeInfoInGroup(ti);
3632 int entry_pos = posTreeInfo(ti);
3634 if (ti->cl_first == -1)
3636 /* only on initialization */
3637 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3638 ti->cl_cursor = entry_pos - ti->cl_first;
3640 else if (ti->cl_cursor >= num_page_entries ||
3641 (num_entries > num_page_entries &&
3642 num_entries - ti->cl_first < num_page_entries))
3644 /* only after change of list size (by custom graphic configuration) */
3645 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3646 ti->cl_cursor = entry_pos - ti->cl_first;
3649 if (position_set_by_scrollbar)
3652 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3655 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3656 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3657 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3661 else if (button == MB_MENU_LEAVE)
3665 PlaySound(SND_MENU_ITEM_SELECTING);
3667 if (ti->node_parent)
3669 *ti_ptr = ti->node_parent;
3670 DrawChooseTree(ti_ptr);
3672 else if (game_status == GAME_MODE_SETUP)
3674 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3675 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3677 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3678 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3679 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3680 execSetupGraphics();
3681 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3682 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3683 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3690 if (game_status == GAME_MODE_LEVELNR)
3691 level_nr = atoi(level_number_current->identifier);
3693 game_status = GAME_MODE_MAIN;
3695 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3701 if (mx || my) /* mouse input */
3703 int last_game_status = game_status; /* save current game status */
3706 /* force LEVELS draw offset on artwork setup screen */
3707 game_status = GAME_MODE_LEVELS;
3710 x = (mx - mSX) / 32;
3711 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3713 game_status = last_game_status; /* restore current game status */
3715 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3717 /* move cursor instead of scrolling when already at start/end of list */
3718 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3720 else if (dy == +1 * SCROLL_LINE &&
3721 ti->cl_first + num_page_entries == num_entries)
3724 /* handle scrolling screen one line or page */
3725 if (ti->cl_cursor + dy < 0 ||
3726 ti->cl_cursor + dy > num_page_entries - 1)
3728 if (ABS(dy) == SCROLL_PAGE)
3729 step = num_page_entries - 1;
3731 if (dy < 0 && ti->cl_first > 0)
3733 /* scroll page/line up */
3735 ti->cl_first -= step;
3736 if (ti->cl_first < 0)
3739 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3740 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3741 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3743 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3746 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3748 /* scroll page/line down */
3750 ti->cl_first += step;
3751 if (ti->cl_first + num_page_entries > num_entries)
3752 ti->cl_first = MAX(0, num_entries - num_page_entries);
3754 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3755 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3756 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3758 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3765 /* handle moving cursor one line */
3766 y = ti->cl_cursor + dy;
3771 TreeInfo *node_first, *node_cursor;
3772 int entry_pos = ti->cl_first + y;
3774 node_first = getTreeInfoFirstGroupEntry(ti);
3775 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3777 if (node_cursor->node_group)
3781 PlaySound(SND_MENU_ITEM_SELECTING);
3783 node_cursor->cl_first = ti->cl_first;
3784 node_cursor->cl_cursor = ti->cl_cursor;
3785 *ti_ptr = node_cursor->node_group;
3786 DrawChooseTree(ti_ptr);
3791 else if (dx == -1 && ti->node_parent)
3795 PlaySound(SND_MENU_ITEM_SELECTING);
3797 *ti_ptr = ti->node_parent;
3798 DrawChooseTree(ti_ptr);
3803 if (!anyScrollbarGadgetActive() &&
3804 IN_VIS_FIELD(x, y) &&
3805 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3806 y >= 0 && y < num_page_entries)
3810 if (y != ti->cl_cursor)
3812 PlaySound(SND_MENU_ITEM_ACTIVATING);
3814 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3815 drawChooseTreeCursor(y, TRUE);
3816 drawChooseTreeInfo(ti->cl_first + y, ti);
3823 TreeInfo *node_first, *node_cursor;
3824 int entry_pos = ti->cl_first + y;
3826 PlaySound(SND_MENU_ITEM_SELECTING);
3828 node_first = getTreeInfoFirstGroupEntry(ti);
3829 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3831 if (node_cursor->node_group)
3835 node_cursor->cl_first = ti->cl_first;
3836 node_cursor->cl_cursor = ti->cl_cursor;
3837 *ti_ptr = node_cursor->node_group;
3838 DrawChooseTree(ti_ptr);
3840 else if (node_cursor->parent_link)
3844 *ti_ptr = node_cursor->node_parent;
3845 DrawChooseTree(ti_ptr);
3852 FadeSetEnterScreen();
3855 node_cursor->cl_first = ti->cl_first;
3856 node_cursor->cl_cursor = ti->cl_cursor;
3857 *ti_ptr = node_cursor;
3859 if (ti->type == TREE_TYPE_LEVEL_DIR)
3861 LoadLevelSetup_SeriesInfo();
3863 SaveLevelSetup_LastSeries();
3864 SaveLevelSetup_SeriesInfo();
3868 if (game_status == GAME_MODE_SETUP)
3870 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3871 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3873 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3874 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3875 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3876 execSetupGraphics();
3877 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3878 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3879 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3886 if (game_status == GAME_MODE_LEVELNR)
3887 level_nr = atoi(level_number_current->identifier);
3889 game_status = GAME_MODE_MAIN;
3898 void DrawChooseLevelSet()
3900 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3902 DrawChooseTree(&leveldir_current);
3908 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3910 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3917 void DrawChooseLevelNr()
3921 if (level_number != NULL)
3923 freeTreeInfo(level_number);
3925 level_number = NULL;
3928 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3930 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3931 char identifier[32], name[32];
3934 /* temporarily load level info to get level name */
3935 LoadLevelInfoOnly(i);
3937 ti->node_top = &level_number;
3938 ti->sort_priority = 10000 + value;
3939 ti->color = (level.no_valid_file ? FC_BLUE :
3940 LevelStats_getSolved(i) ? FC_GREEN :
3941 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3943 sprintf(identifier, "%d", value);
3944 sprintf(name, "%03d: %s", value,
3945 (level.no_valid_file ? "(no file)" : level.name));
3947 setString(&ti->identifier, identifier);
3948 setString(&ti->name, name);
3949 setString(&ti->name_sorting, name);
3951 pushTreeInfo(&level_number, ti);
3954 /* sort level number values to start with lowest level number */
3955 sortTreeInfo(&level_number);
3957 /* set current level number to current level number */
3958 level_number_current =
3959 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3961 /* if that also fails, set current level number to first available level */
3962 if (level_number_current == NULL)
3963 level_number_current = level_number;
3965 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3968 DrawChooseTree(&level_number_current);
3970 DrawChooseTree(&leveldir_current);
3977 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3980 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3982 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3990 void DrawHallOfFame(int highlight_position)
3993 FadeSoundsAndMusic();
3995 /* (this is needed when called from GameEnd() after winning a game) */
3996 KeyboardAutoRepeatOn();
3999 /* (this is needed when called from GameEnd() after winning a game) */
4000 SetDrawDeactivationMask(REDRAW_NONE);
4001 SetDrawBackgroundMask(REDRAW_FIELD);
4003 CloseDoor(DOOR_CLOSE_2);
4005 if (highlight_position < 0)
4006 LoadScore(level_nr);
4008 FadeSetEnterScreen();
4010 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4013 FadeOut(REDRAW_FIELD);
4021 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4024 FadeIn(REDRAW_FIELD);
4028 static void drawHallOfFameList(int first_entry, int highlight_position)
4032 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4035 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4036 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4037 "HighScores of Level %d", level_nr);
4039 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4041 int entry = first_entry + i;
4042 boolean active = (entry == highlight_position);
4043 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4044 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4045 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4046 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4047 int dx1 = 3 * getFontWidth(font_nr1);
4048 int dx2 = dx1 + getFontWidth(font_nr1);
4050 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
4051 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4053 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4055 int sy = mSY + 64 + i * 32;
4057 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4058 DrawText(mSX + dx1, sy, ".", font_nr1);
4060 for (j = 0; j < num_dots; j++)
4061 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4063 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4066 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4067 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4069 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4072 redraw_mask |= REDRAW_FIELD;
4075 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4077 static int first_entry = 0;
4078 static int highlight_position = 0;
4079 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4081 if (button == MB_MENU_INITIALIZE)
4084 highlight_position = mx;
4085 drawHallOfFameList(first_entry, highlight_position);
4090 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4091 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4095 if (first_entry > 0)
4097 first_entry -= step;
4098 if (first_entry < 0)
4101 drawHallOfFameList(first_entry, highlight_position);
4106 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4108 first_entry += step;
4109 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4110 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4112 drawHallOfFameList(first_entry, highlight_position);
4115 else if (button == MB_MENU_LEAVE)
4117 PlaySound(SND_MENU_ITEM_SELECTING);
4119 FadeSound(SND_BACKGROUND_SCORES);
4121 game_status = GAME_MODE_MAIN;
4125 else if (button == MB_MENU_CHOICE)
4127 PlaySound(SND_MENU_ITEM_SELECTING);
4129 FadeSound(SND_BACKGROUND_SCORES);
4132 FadeOut(REDRAW_FIELD);
4135 game_status = GAME_MODE_MAIN;
4137 DrawAndFadeInMainMenu(REDRAW_FIELD);
4140 if (game_status == GAME_MODE_SCORES)
4141 PlayMenuSoundIfLoop();
4149 /* ========================================================================= */
4150 /* setup screen functions */
4151 /* ========================================================================= */
4153 static struct TokenInfo *setup_info;
4154 static int num_setup_info;
4156 static char *screen_mode_text;
4157 static char *window_size_text;
4158 static char *scaling_type_text;
4159 static char *scroll_delay_text;
4160 static char *game_speed_text;
4161 static char *graphics_set_name;
4162 static char *sounds_set_name;
4163 static char *music_set_name;
4164 static char *volume_simple_text;
4165 static char *volume_loops_text;
4166 static char *volume_music_text;
4168 static void execSetupMain()
4170 setup_mode = SETUP_MODE_MAIN;
4175 static void execSetupGame_setGameSpeeds()
4177 if (game_speeds == NULL)
4181 for (i = 0; game_speeds_list[i].value != -1; i++)
4183 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4184 char identifier[32], name[32];
4185 int value = game_speeds_list[i].value;
4186 char *text = game_speeds_list[i].text;
4188 ti->node_top = &game_speeds;
4189 ti->sort_priority = 10000 - value;
4191 sprintf(identifier, "%d", value);
4192 sprintf(name, "%s", text);
4194 setString(&ti->identifier, identifier);
4195 setString(&ti->name, name);
4196 setString(&ti->name_sorting, name);
4197 setString(&ti->infotext, "Game Speed");
4199 pushTreeInfo(&game_speeds, ti);
4202 /* sort game speed values to start with slowest game speed */
4203 sortTreeInfo(&game_speeds);
4205 /* set current game speed to configured game speed value */
4206 game_speed_current =
4207 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4209 /* if that fails, set current game speed to reliable default value */
4210 if (game_speed_current == NULL)
4211 game_speed_current =
4212 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4214 /* if that also fails, set current game speed to first available speed */
4215 if (game_speed_current == NULL)
4216 game_speed_current = game_speeds;
4219 setup.game_frame_delay = atoi(game_speed_current->identifier);
4221 /* needed for displaying game speed text instead of identifier */
4222 game_speed_text = game_speed_current->name;
4225 static void execSetupGame_setScrollDelays()
4227 if (scroll_delays == NULL)
4231 for (i = 0; scroll_delays_list[i].value != -1; i++)
4233 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4234 char identifier[32], name[32];
4235 int value = scroll_delays_list[i].value;
4236 char *text = scroll_delays_list[i].text;
4238 ti->node_top = &scroll_delays;
4239 ti->sort_priority = value;
4241 sprintf(identifier, "%d", value);
4242 sprintf(name, "%s", text);
4244 setString(&ti->identifier, identifier);
4245 setString(&ti->name, name);
4246 setString(&ti->name_sorting, name);
4247 setString(&ti->infotext, "Scaling Type");
4249 pushTreeInfo(&scroll_delays, ti);
4252 /* sort scaling type values to start with lowest scaling type value */
4253 sortTreeInfo(&scroll_delays);
4255 /* set current scaling type value to configured scaling type value */
4256 scroll_delay_current =
4257 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4259 /* if that fails, set current scaling type to reliable default value */
4260 if (scroll_delay_current == NULL)
4261 scroll_delay_current =
4262 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4264 /* if that also fails, set current scaling type to first available value */
4265 if (scroll_delay_current == NULL)
4266 scroll_delay_current = scroll_delays;
4269 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4271 /* needed for displaying scaling type text instead of identifier */
4272 scroll_delay_text = scroll_delay_current->name;
4275 static void execSetupGame()
4277 execSetupGame_setGameSpeeds();
4278 execSetupGame_setScrollDelays();
4280 setup_mode = SETUP_MODE_GAME;
4285 static void execSetupChooseGameSpeed()
4287 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4292 static void execSetupChooseScrollDelay()
4294 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4299 static void execSetupEditor()
4301 setup_mode = SETUP_MODE_EDITOR;
4306 static void execSetupGraphics_setWindowSizes(boolean update_list)
4308 if (window_sizes != NULL && update_list)
4310 freeTreeInfo(window_sizes);
4312 window_sizes = NULL;
4315 if (window_sizes == NULL)
4317 boolean current_window_size_found = FALSE;
4320 for (i = 0; window_sizes_list[i].value != -1; i++)
4322 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4323 char identifier[32], name[32];
4324 int value = window_sizes_list[i].value;
4325 char *text = window_sizes_list[i].text;
4327 ti->node_top = &window_sizes;
4328 ti->sort_priority = value;
4330 sprintf(identifier, "%d", value);
4331 sprintf(name, "%s", text);
4333 setString(&ti->identifier, identifier);
4334 setString(&ti->name, name);
4335 setString(&ti->name_sorting, name);
4336 setString(&ti->infotext, "Window Scaling");
4338 pushTreeInfo(&window_sizes, ti);
4340 if (value == setup.window_scaling_percent)
4341 current_window_size_found = TRUE;
4344 if (!current_window_size_found)
4346 // add entry for non-preset window scaling value
4348 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4349 char identifier[32], name[32];
4350 int value = setup.window_scaling_percent;
4352 ti->node_top = &window_sizes;
4353 ti->sort_priority = value;
4355 sprintf(identifier, "%d", value);
4356 sprintf(name, "%d %% (Current)", value);
4358 setString(&ti->identifier, identifier);
4359 setString(&ti->name, name);
4360 setString(&ti->name_sorting, name);
4361 setString(&ti->infotext, "Window Scaling");
4363 pushTreeInfo(&window_sizes, ti);
4366 /* sort window size values to start with lowest window size value */
4367 sortTreeInfo(&window_sizes);
4369 /* set current window size value to configured window size value */
4370 window_size_current =
4371 getTreeInfoFromIdentifier(window_sizes,
4372 i_to_a(setup.window_scaling_percent));
4374 /* if that fails, set current window size to reliable default value */
4375 if (window_size_current == NULL)
4376 window_size_current =
4377 getTreeInfoFromIdentifier(window_sizes,
4378 i_to_a(STD_WINDOW_SCALING_PERCENT));
4380 /* if that also fails, set current window size to first available value */
4381 if (window_size_current == NULL)
4382 window_size_current = window_sizes;
4385 setup.window_scaling_percent = atoi(window_size_current->identifier);
4387 /* needed for displaying window size text instead of identifier */
4388 window_size_text = window_size_current->name;
4391 static void execSetupGraphics_setScalingTypes()
4393 if (scaling_types == NULL)
4397 for (i = 0; scaling_types_list[i].value != NULL; i++)
4399 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4400 char identifier[32], name[32];
4401 char *value = scaling_types_list[i].value;
4402 char *text = scaling_types_list[i].text;
4404 ti->node_top = &scaling_types;
4405 ti->sort_priority = i;
4407 sprintf(identifier, "%s", value);
4408 sprintf(name, "%s", text);
4410 setString(&ti->identifier, identifier);
4411 setString(&ti->name, name);
4412 setString(&ti->name_sorting, name);
4413 setString(&ti->infotext, "Anti-Aliasing");
4415 pushTreeInfo(&scaling_types, ti);
4418 /* sort scaling type values to start with lowest scaling type value */
4419 sortTreeInfo(&scaling_types);
4421 /* set current scaling type value to configured scaling type value */
4422 scaling_type_current =
4423 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4425 /* if that fails, set current scaling type to reliable default value */
4426 if (scaling_type_current == NULL)
4427 scaling_type_current =
4428 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4430 /* if that also fails, set current scaling type to first available value */
4431 if (scaling_type_current == NULL)
4432 scaling_type_current = scaling_types;
4435 setup.window_scaling_quality = scaling_type_current->identifier;
4437 /* needed for displaying scaling type text instead of identifier */
4438 scaling_type_text = scaling_type_current->name;
4441 static void execSetupGraphics_setScreenModes()
4443 // if (screen_modes == NULL && video.fullscreen_available)
4444 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4448 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4450 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4451 char identifier[32], name[32];
4452 int x = video.fullscreen_modes[i].width;
4453 int y = video.fullscreen_modes[i].height;
4456 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4458 ti->node_top = &screen_modes;
4459 ti->sort_priority = x * 10000 + y;
4461 sprintf(identifier, "%dx%d", x, y);
4462 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4464 setString(&ti->identifier, identifier);
4465 setString(&ti->name, name);
4466 setString(&ti->name_sorting, name);
4467 setString(&ti->infotext, "Fullscreen Mode");
4469 pushTreeInfo(&screen_modes, ti);
4472 /* sort fullscreen modes to start with lowest available screen resolution */
4473 sortTreeInfo(&screen_modes);
4475 /* set current screen mode for fullscreen mode to configured setup value */
4476 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4477 setup.fullscreen_mode);
4479 /* if that fails, set current screen mode to reliable default value */
4480 if (screen_mode_current == NULL)
4481 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4482 DEFAULT_FULLSCREEN_MODE);
4484 /* if that also fails, set current screen mode to first available mode */
4485 if (screen_mode_current == NULL)
4486 screen_mode_current = screen_modes;
4488 if (screen_mode_current == NULL)
4489 video.fullscreen_available = FALSE;
4492 // if (video.fullscreen_available)
4493 if (screen_mode_current != NULL)
4495 setup.fullscreen_mode = screen_mode_current->identifier;
4497 /* needed for displaying screen mode name instead of identifier */
4498 screen_mode_text = screen_mode_current->name;
4502 static void execSetupGraphics()
4504 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4506 // update "setup.window_scaling_percent" from list selection
4507 execSetupGraphics_setWindowSizes(FALSE);
4511 // update list selection from "setup.window_scaling_percent"
4512 execSetupGraphics_setWindowSizes(TRUE);
4515 execSetupGraphics_setScalingTypes();
4516 execSetupGraphics_setScreenModes();
4518 setup_mode = SETUP_MODE_GRAPHICS;
4522 #if defined(TARGET_SDL2)
4523 // window scaling may have changed at this point
4524 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4526 // window scaling quality may have changed at this point
4527 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4528 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4532 #if !defined(PLATFORM_ANDROID)
4533 #if defined(TARGET_SDL2)
4534 static void execSetupChooseWindowSize()
4537 if (!video.window_scaling_available)
4541 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4546 static void execSetupChooseScalingType()
4548 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4553 static void execSetupChooseScreenMode()
4555 if (!video.fullscreen_available)
4558 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4565 static void execSetupChooseVolumeSimple()
4567 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4572 static void execSetupChooseVolumeLoops()
4574 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4579 static void execSetupChooseVolumeMusic()
4581 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4586 static void execSetupSound()
4589 if (volumes_simple == NULL)
4593 for (i = 0; volumes_list[i].value != -1; i++)
4595 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4596 char identifier[32], name[32];
4597 int value = volumes_list[i].value;
4598 char *text = volumes_list[i].text;
4600 ti->node_top = &volumes_simple;
4601 ti->sort_priority = value;
4603 sprintf(identifier, "%d", value);
4604 sprintf(name, "%s", text);
4606 setString(&ti->identifier, identifier);
4607 setString(&ti->name, name);
4608 setString(&ti->name_sorting, name);
4609 setString(&ti->infotext, "Sound Volume");
4611 pushTreeInfo(&volumes_simple, ti);
4614 /* sort volume values to start with lowest volume value */
4615 sortTreeInfo(&volumes_simple);
4617 /* set current volume value to configured volume value */
4618 volume_simple_current =
4619 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4621 /* if that fails, set current volume to reliable default value */
4622 if (volume_simple_current == NULL)
4623 volume_simple_current =
4624 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4626 /* if that also fails, set current volume to first available value */
4627 if (volume_simple_current == NULL)
4628 volume_simple_current = volumes_simple;
4631 if (volumes_loops == NULL)
4635 for (i = 0; volumes_list[i].value != -1; i++)
4637 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4638 char identifier[32], name[32];
4639 int value = volumes_list[i].value;
4640 char *text = volumes_list[i].text;
4642 ti->node_top = &volumes_loops;
4643 ti->sort_priority = value;
4645 sprintf(identifier, "%d", value);
4646 sprintf(name, "%s", text);
4648 setString(&ti->identifier, identifier);
4649 setString(&ti->name, name);
4650 setString(&ti->name_sorting, name);
4651 setString(&ti->infotext, "Loops Volume");
4653 pushTreeInfo(&volumes_loops, ti);
4656 /* sort volume values to start with lowest volume value */
4657 sortTreeInfo(&volumes_loops);
4659 /* set current volume value to configured volume value */
4660 volume_loops_current =
4661 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4663 /* if that fails, set current volume to reliable default value */
4664 if (volume_loops_current == NULL)
4665 volume_loops_current =
4666 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4668 /* if that also fails, set current volume to first available value */
4669 if (volume_loops_current == NULL)
4670 volume_loops_current = volumes_loops;
4673 if (volumes_music == NULL)
4677 for (i = 0; volumes_list[i].value != -1; i++)
4679 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4680 char identifier[32], name[32];
4681 int value = volumes_list[i].value;
4682 char *text = volumes_list[i].text;
4684 ti->node_top = &volumes_music;
4685 ti->sort_priority = value;
4687 sprintf(identifier, "%d", value);
4688 sprintf(name, "%s", text);
4690 setString(&ti->identifier, identifier);
4691 setString(&ti->name, name);
4692 setString(&ti->name_sorting, name);
4693 setString(&ti->infotext, "Music Volume");
4695 pushTreeInfo(&volumes_music, ti);
4698 /* sort volume values to start with lowest volume value */
4699 sortTreeInfo(&volumes_music);
4701 /* set current volume value to configured volume value */
4702 volume_music_current =
4703 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4705 /* if that fails, set current volume to reliable default value */
4706 if (volume_music_current == NULL)
4707 volume_music_current =
4708 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4710 /* if that also fails, set current volume to first available value */
4711 if (volume_music_current == NULL)
4712 volume_music_current = volumes_music;
4715 setup.volume_simple = atoi(volume_simple_current->identifier);
4716 setup.volume_loops = atoi(volume_loops_current->identifier);
4717 setup.volume_music = atoi(volume_music_current->identifier);
4719 /* needed for displaying volume text instead of identifier */
4720 volume_simple_text = volume_simple_current->name;
4721 volume_loops_text = volume_loops_current->name;
4722 volume_music_text = volume_music_current->name;
4725 setup_mode = SETUP_MODE_SOUND;
4730 static void execSetupArtwork()
4733 printf("::: '%s', '%s', '%s'\n",
4734 artwork.gfx_current->subdir,
4735 artwork.gfx_current->fullpath,
4736 artwork.gfx_current->basepath);
4739 setup.graphics_set = artwork.gfx_current->identifier;
4740 setup.sounds_set = artwork.snd_current->identifier;
4741 setup.music_set = artwork.mus_current->identifier;
4743 /* needed if last screen (setup choice) changed graphics, sounds or music */
4744 ReloadCustomArtwork(0);
4746 /* needed for displaying artwork name instead of artwork identifier */
4747 graphics_set_name = artwork.gfx_current->name;
4748 sounds_set_name = artwork.snd_current->name;
4749 music_set_name = artwork.mus_current->name;
4751 setup_mode = SETUP_MODE_ARTWORK;
4756 static void execSetupChooseGraphics()
4758 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4763 static void execSetupChooseSounds()
4765 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4770 static void execSetupChooseMusic()
4772 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4777 static void execSetupInput()
4779 setup_mode = SETUP_MODE_INPUT;
4784 static void execSetupShortcuts()
4786 setup_mode = SETUP_MODE_SHORTCUTS;
4791 static void execSetupShortcuts1()
4793 setup_mode = SETUP_MODE_SHORTCUTS_1;
4798 static void execSetupShortcuts2()
4800 setup_mode = SETUP_MODE_SHORTCUTS_2;
4805 static void execSetupShortcuts3()
4807 setup_mode = SETUP_MODE_SHORTCUTS_3;
4812 static void execSetupShortcuts4()
4814 setup_mode = SETUP_MODE_SHORTCUTS_4;
4819 static void execSetupShortcuts5()
4821 setup_mode = SETUP_MODE_SHORTCUTS_5;
4826 static void execExitSetup()
4828 game_status = GAME_MODE_MAIN;
4830 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4833 static void execSaveAndExitSetup()
4839 static struct TokenInfo setup_info_main[] =
4841 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4842 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4843 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4844 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4845 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4846 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4847 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4848 { TYPE_EMPTY, NULL, "" },
4849 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4850 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4855 static struct TokenInfo setup_info_game[] =
4857 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4858 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4859 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4860 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4861 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4862 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4863 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4864 { TYPE_STRING, &game_speed_text, "" },
4866 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4867 { TYPE_STRING, &scroll_delay_text, "" },
4869 { TYPE_EMPTY, NULL, "" },
4870 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4875 static struct TokenInfo setup_info_editor[] =
4878 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4879 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4880 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4881 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4882 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4883 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4884 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4885 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4887 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4888 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4889 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4891 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4893 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4894 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4895 { TYPE_EMPTY, NULL, "" },
4897 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4898 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4899 { TYPE_EMPTY, NULL, "" },
4901 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4902 { TYPE_EMPTY, NULL, "" },
4903 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4908 static struct TokenInfo setup_info_graphics[] =
4910 #if !defined(PLATFORM_ANDROID)
4911 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4912 #if defined(TARGET_SDL2)
4913 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4914 { TYPE_STRING, &window_size_text, "" },
4916 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4917 { TYPE_STRING, &scaling_type_text, "" },
4920 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4921 { TYPE_STRING, &screen_mode_text, "" },
4925 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4928 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4929 { TYPE_STRING, &scroll_delay_text, "" },
4932 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4934 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4935 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4936 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4937 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4938 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4939 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4940 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4941 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4942 { TYPE_EMPTY, NULL, "" },
4943 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4948 static struct TokenInfo setup_info_sound[] =
4950 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4951 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4952 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4953 { TYPE_EMPTY, NULL, "" },
4954 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4955 { TYPE_STRING, &volume_simple_text, "" },
4956 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4957 { TYPE_STRING, &volume_loops_text, "" },
4958 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4959 { TYPE_STRING, &volume_music_text, "" },
4960 { TYPE_EMPTY, NULL, "" },
4961 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4966 static struct TokenInfo setup_info_artwork[] =
4968 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4969 { TYPE_STRING, &graphics_set_name, "" },
4970 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4971 { TYPE_STRING, &sounds_set_name, "" },
4972 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4973 { TYPE_STRING, &music_set_name, "" },
4974 { TYPE_EMPTY, NULL, "" },
4977 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4978 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4979 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4981 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4982 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4983 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4984 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4987 { TYPE_STRING, NULL, "Override Level Artwork:"},
4988 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4989 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4990 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4992 { TYPE_EMPTY, NULL, "" },
4993 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4998 static struct TokenInfo setup_info_input[] =
5000 { TYPE_SWITCH, NULL, "Player:" },
5001 { TYPE_SWITCH, NULL, "Device:" },
5002 { TYPE_ENTER_MENU, NULL, "" },
5003 { TYPE_EMPTY, NULL, "" },
5004 { TYPE_EMPTY, NULL, "" },
5005 { TYPE_EMPTY, NULL, "" },
5006 { TYPE_EMPTY, NULL, "" },
5007 { TYPE_EMPTY, NULL, "" },
5008 { TYPE_EMPTY, NULL, "" },
5009 { TYPE_EMPTY, NULL, "" },
5010 { TYPE_EMPTY, NULL, "" },
5011 { TYPE_EMPTY, NULL, "" },
5012 { TYPE_EMPTY, NULL, "" },
5013 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5018 static struct TokenInfo setup_info_shortcuts[] =
5020 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5021 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5022 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5023 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5024 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5025 { TYPE_EMPTY, NULL, "" },
5026 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5031 static struct TokenInfo setup_info_shortcuts_1[] =
5033 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5034 { TYPE_KEY, &setup.shortcut.save_game, "" },
5035 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5036 { TYPE_KEY, &setup.shortcut.load_game, "" },
5037 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5038 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5039 { TYPE_EMPTY, NULL, "" },
5040 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5041 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5042 { TYPE_EMPTY, NULL, "" },
5043 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5048 static struct TokenInfo setup_info_shortcuts_2[] =
5050 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5051 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5052 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5053 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5054 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5055 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5056 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5057 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5058 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5059 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5060 { TYPE_EMPTY, NULL, "" },
5061 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5066 static struct TokenInfo setup_info_shortcuts_3[] =
5068 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5069 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5070 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5071 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5072 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5073 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5074 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5075 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5076 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5077 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5078 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5079 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5080 { TYPE_EMPTY, NULL, "" },
5081 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5086 static struct TokenInfo setup_info_shortcuts_4[] =
5088 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5089 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5090 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5091 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5092 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5093 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5094 { TYPE_EMPTY, NULL, "" },
5095 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5100 static struct TokenInfo setup_info_shortcuts_5[] =
5102 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5103 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5104 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5105 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5106 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5107 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5108 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5109 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5110 { TYPE_EMPTY, NULL, "" },
5111 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5116 static Key getSetupKey()
5118 Key key = KSYM_UNDEFINED;
5119 boolean got_key_event = FALSE;
5121 while (!got_key_event)
5123 if (PendingEvent()) /* got event */
5131 case EVENT_KEYPRESS:
5133 key = GetEventKey((KeyEvent *)&event, TRUE);
5135 /* press 'Escape' or 'Enter' to keep the existing key binding */
5136 if (key == KSYM_Escape || key == KSYM_Return)
5137 key = KSYM_UNDEFINED; /* keep old value */
5139 got_key_event = TRUE;
5143 case EVENT_KEYRELEASE:
5144 key_joystick_mapping = 0;
5148 HandleOtherEvents(&event);
5156 /* don't eat all CPU time */
5163 static int getSetupTextFont(int type)
5165 if (type & (TYPE_SWITCH |
5177 static int getSetupValueFont(int type, void *value)
5179 if (type & TYPE_KEY)
5180 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5181 else if (type & TYPE_STRING)
5182 return FONT_VALUE_2;
5183 else if (type & TYPE_ECS_AGA)
5184 return FONT_VALUE_1;
5185 else if (type & TYPE_BOOLEAN_STYLE)
5186 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5187 else if (type & TYPE_YES_NO_AUTO)
5188 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5189 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5191 return FONT_VALUE_1;
5194 static void drawSetupValue(int pos)
5196 boolean font_draw_xoffset_modified = FALSE;
5197 int font_draw_xoffset_old = -1;
5198 int xpos = MENU_SCREEN_VALUE_XPOS;
5199 int ypos = MENU_SCREEN_START_YPOS + pos;
5200 int startx = mSX + xpos * 32;
5201 int starty = mSY + ypos * 32;
5202 int font_nr, font_width;
5206 int type = setup_info[pos].type;
5207 void *value = setup_info[pos].value;
5208 char *value_string = getSetupValue(type, value);
5213 if (value_string == NULL)
5216 if (type & TYPE_KEY)
5218 xpos = MENU_SCREEN_START_XPOS;
5220 if (type & TYPE_QUERY)
5221 value_string = "<press key>";
5223 else if (type & TYPE_STRING)
5225 int max_value_len = (SCR_FIELDX - 2) * 2;
5227 xpos = MENU_SCREEN_START_XPOS;
5229 if (strlen(value_string) > max_value_len)
5230 value_string[max_value_len] = '\0';
5232 else if (type & TYPE_YES_NO_AUTO)
5234 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5237 startx = mSX + xpos * 32;
5238 starty = mSY + ypos * 32;
5239 font_nr = getSetupValueFont(type, value);
5240 font_width = getFontWidth(font_nr);
5242 font_height = getFontHeight(font_nr);
5245 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5246 if (setup_mode != SETUP_MODE_INPUT)
5248 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5249 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5250 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5251 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5252 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5253 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5254 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5255 boolean correct_font_draw_xoffset = FALSE;
5257 if (xpos == MENU_SCREEN_START_XPOS &&
5258 startx + font1_xoffset < text_startx + text_font_xoffset)
5259 correct_font_draw_xoffset = TRUE;
5261 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5262 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5263 correct_font_draw_xoffset = TRUE;
5265 /* check if setup value would overlap with setup text when printed */
5266 /* (this can happen for extreme/wrong values for font draw offset) */
5267 if (correct_font_draw_xoffset)
5269 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5270 font_draw_xoffset_modified = TRUE;
5272 if (type & TYPE_KEY)
5273 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5274 else if (!(type & TYPE_STRING))
5275 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5276 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5281 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5283 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5284 DrawText(startx + i * font_width, starty, " ", font_nr);
5287 DrawText(startx, starty, value_string, font_nr);
5289 if (font_draw_xoffset_modified)
5290 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5293 static void changeSetupValue(int pos, int dx)
5295 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5297 *(boolean *)setup_info[pos].value ^= TRUE;
5299 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5301 *(int *)setup_info[pos].value =
5303 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5304 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5305 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5306 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5308 else if (setup_info[pos].type & TYPE_KEY)
5312 setup_info[pos].type |= TYPE_QUERY;
5313 drawSetupValue(pos);
5314 setup_info[pos].type &= ~TYPE_QUERY;
5316 key = getSetupKey();
5317 if (key != KSYM_UNDEFINED)
5318 *(Key *)setup_info[pos].value = key;
5321 drawSetupValue(pos);
5323 // fullscreen state may have changed at this point
5324 if (setup_info[pos].value == &setup.fullscreen)
5325 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5328 static void DrawCursorAndText_Setup(int pos, boolean active)
5330 int xpos = MENU_SCREEN_START_XPOS;
5331 int ypos = MENU_SCREEN_START_YPOS + pos;
5332 int font_nr = getSetupTextFont(setup_info[pos].type);
5334 if (setup_info == setup_info_input)
5335 font_nr = FONT_MENU_1;
5338 font_nr = FONT_ACTIVE(font_nr);
5340 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5342 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5343 drawCursor(pos, active);
5346 static void DrawSetupScreen_Generic()
5348 boolean redraw_all = FALSE;
5349 char *title_string = NULL;
5353 CloseDoor(DOOR_CLOSE_2);
5355 if (redraw_mask & REDRAW_ALL)
5359 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5360 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5361 int2str(0, redraw_mask)));
5365 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5366 FadeOut(redraw_mask);
5368 FadeOut(REDRAW_FIELD);
5373 if (setup_mode == SETUP_MODE_MAIN)
5375 setup_info = setup_info_main;
5376 title_string = "Setup";
5378 else if (setup_mode == SETUP_MODE_GAME)
5380 setup_info = setup_info_game;
5381 title_string = "Setup Game";
5383 else if (setup_mode == SETUP_MODE_EDITOR)
5385 setup_info = setup_info_editor;
5386 title_string = "Setup Editor";
5388 else if (setup_mode == SETUP_MODE_GRAPHICS)
5390 setup_info = setup_info_graphics;
5391 title_string = "Setup Graphics";
5393 else if (setup_mode == SETUP_MODE_SOUND)
5395 setup_info = setup_info_sound;
5396 title_string = "Setup Sound";
5398 else if (setup_mode == SETUP_MODE_ARTWORK)
5400 setup_info = setup_info_artwork;
5401 title_string = "Custom Artwork";
5403 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5405 setup_info = setup_info_shortcuts;
5406 title_string = "Setup Shortcuts";
5408 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5410 setup_info = setup_info_shortcuts_1;
5411 title_string = "Setup Shortcuts";
5413 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5415 setup_info = setup_info_shortcuts_2;
5416 title_string = "Setup Shortcuts";
5418 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5420 setup_info = setup_info_shortcuts_3;
5421 title_string = "Setup Shortcuts";
5423 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5425 setup_info = setup_info_shortcuts_4;
5426 title_string = "Setup Shortcuts";
5428 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5430 setup_info = setup_info_shortcuts_5;
5431 title_string = "Setup Shortcuts";
5434 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5438 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5440 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5443 void *value_ptr = setup_info[i].value;
5445 /* set some entries to "unchangeable" according to other variables */
5446 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5447 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5448 (value_ptr == &setup.sound_music && !audio.music_available) ||
5449 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5450 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5451 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5452 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5453 setup_info[i].type |= TYPE_GHOSTED;
5455 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5456 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5457 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5458 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5459 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5460 initCursor(i, IMG_MENU_BUTTON);
5462 DrawCursorAndText_Setup(i, FALSE);
5464 if (setup_info[i].type & TYPE_VALUE)
5471 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5472 "Joysticks deactivated in setup menu");
5476 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5480 redraw_mask = REDRAW_ALL;
5483 FadeIn(redraw_mask);
5485 FadeIn(REDRAW_FIELD);
5490 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5494 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5496 static int choice_store[MAX_SETUP_MODES];
5497 int choice = choice_store[setup_mode]; /* always starts with 0 */
5501 if (button == MB_MENU_INITIALIZE)
5503 /* advance to first valid menu entry */
5504 while (choice < num_setup_info &&
5505 setup_info[choice].type & TYPE_SKIP_ENTRY)
5507 choice_store[setup_mode] = choice;
5509 DrawCursorAndText_Setup(choice, TRUE);
5513 else if (button == MB_MENU_LEAVE)
5515 PlaySound(SND_MENU_ITEM_SELECTING);
5517 // for (y = 0; y < num_setup_info; y++)
5518 for (y = 0; setup_info[y].type != 0; y++)
5520 if (setup_info[y].type & TYPE_LEAVE_MENU)
5522 void (*menu_callback_function)(void) = setup_info[y].value;
5526 menu_callback_function();
5528 break; /* absolutely needed because function changes 'setup_info'! */
5535 if (mx || my) /* mouse input */
5537 x = (mx - mSX) / 32;
5538 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5540 else if (dx || dy) /* keyboard input */
5544 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5546 if (setup_info[choice].type & menu_navigation_type ||
5547 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5548 setup_info[choice].type & TYPE_YES_NO_AUTO)
5549 button = MB_MENU_CHOICE;
5554 /* jump to next non-empty menu entry (up or down) */
5555 while (y > 0 && y < num_setup_info - 1 &&
5556 setup_info[y].type & TYPE_SKIP_ENTRY)
5560 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5564 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5566 PlaySound(SND_MENU_ITEM_ACTIVATING);
5568 DrawCursorAndText_Setup(choice, FALSE);
5569 DrawCursorAndText_Setup(y, TRUE);
5571 choice = choice_store[setup_mode] = y;
5574 else if (!(setup_info[y].type & TYPE_GHOSTED))
5576 PlaySound(SND_MENU_ITEM_SELECTING);
5578 /* when selecting key headline, execute function for key value change */
5579 if (setup_info[y].type & TYPE_KEYTEXT &&
5580 setup_info[y + 1].type & TYPE_KEY)
5583 /* when selecting string value, execute function for list selection */
5584 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5585 setup_info[y - 1].type & TYPE_ENTER_LIST)
5588 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5590 void (*menu_callback_function)(void) = setup_info[y].value;
5592 FadeSetFromType(setup_info[y].type);
5594 menu_callback_function();
5598 if (setup_info[y].type & TYPE_VALUE)
5599 changeSetupValue(y, dx);
5605 void DrawSetupScreen_Input()
5610 FadeOut(REDRAW_FIELD);
5616 setup_info = setup_info_input;
5619 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5623 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5624 "Joysticks deactivated on this screen");
5626 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5627 "Joysticks deactivated on this screen");
5632 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5634 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5637 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5638 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5639 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5640 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5641 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5642 initCursor(i, IMG_MENU_BUTTON);
5644 DrawCursorAndText_Setup(i, FALSE);
5648 DeactivateJoystickForCalibration();
5653 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5654 "Joysticks deactivated on this screen");
5656 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5657 "Joysticks deactivated on this screen");
5661 /* create gadgets for setup input menu screen */
5662 FreeScreenGadgets();
5663 CreateScreenGadgets();
5665 /* map gadgets for setup input menu screen */
5666 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5668 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5671 FadeIn(REDRAW_FIELD);
5677 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5679 if (device_name == NULL)
5682 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5685 if (strlen(device_name) > 1)
5687 char c1 = device_name[strlen(device_name) - 1];
5688 char c2 = device_name[strlen(device_name) - 2];
5690 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5691 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5694 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5695 strlen(device_name));
5698 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5701 static struct SetupKeyboardInfo custom_key;
5708 { &custom_key.left, "Joystick Left" },
5709 { &custom_key.right, "Joystick Right" },
5710 { &custom_key.up, "Joystick Up" },
5711 { &custom_key.down, "Joystick Down" },
5712 { &custom_key.snap, "Button 1" },
5713 { &custom_key.drop, "Button 2" }
5715 static char *joystick_name[MAX_PLAYERS] =
5722 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5726 custom_key = setup.input[player_nr].key;
5728 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5729 FONT_INPUT_1_ACTIVE);
5731 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5733 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5734 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5736 if (setup.input[player_nr].use_joystick)
5738 char *device_name = setup.input[player_nr].joy.device_name;
5739 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5740 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5742 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5743 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5747 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5748 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5751 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5753 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5754 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5755 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5756 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5758 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5759 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5760 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5761 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5762 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5763 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5765 for (i = 0; i < 6; i++)
5767 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5769 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5771 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5772 (setup.input[player_nr].use_joystick ?
5774 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5778 static int input_player_nr = 0;
5780 void HandleSetupScreen_Input_Player(int step, int direction)
5782 int old_player_nr = input_player_nr;
5785 new_player_nr = old_player_nr + step * direction;
5786 if (new_player_nr < 0)
5788 if (new_player_nr > MAX_PLAYERS - 1)
5789 new_player_nr = MAX_PLAYERS - 1;
5791 if (new_player_nr != old_player_nr)
5793 input_player_nr = new_player_nr;
5795 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5799 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5801 static int choice = 0;
5804 int pos_start = SETUPINPUT_SCREEN_POS_START;
5805 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5806 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5807 int pos_end = SETUPINPUT_SCREEN_POS_END;
5809 if (button == MB_MENU_INITIALIZE)
5811 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5813 DrawCursorAndText_Setup(choice, TRUE);
5817 else if (button == MB_MENU_LEAVE)
5819 setup_mode = SETUP_MODE_MAIN;
5826 if (mx || my) /* mouse input */
5828 x = (mx - mSX) / 32;
5829 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5831 else if (dx || dy) /* keyboard input */
5833 if (dx && choice == 0)
5834 x = (dx < 0 ? 10 : 12);
5835 else if ((dx && choice == 1) ||
5836 (dx == +1 && choice == 2) ||
5837 (dx == -1 && choice == pos_end))
5838 button = MB_MENU_CHOICE;
5842 if (y >= pos_empty1 && y <= pos_empty2)
5843 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5846 if (y == 0 && dx != 0 && button)
5848 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5850 else if (IN_VIS_FIELD(x, y) &&
5851 y >= pos_start && y <= pos_end &&
5852 !(y >= pos_empty1 && y <= pos_empty2))
5858 DrawCursorAndText_Setup(choice, FALSE);
5859 DrawCursorAndText_Setup(y, TRUE);
5861 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5870 char *device_name = setup.input[input_player_nr].joy.device_name;
5872 if (!setup.input[input_player_nr].use_joystick)
5874 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5876 setJoystickDeviceToNr(device_name, new_device_nr);
5877 setup.input[input_player_nr].use_joystick = TRUE;
5881 int device_nr = getJoystickNrFromDeviceName(device_name);
5882 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5884 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5885 setup.input[input_player_nr].use_joystick = FALSE;
5887 setJoystickDeviceToNr(device_name, new_device_nr);
5890 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5894 if (setup.input[input_player_nr].use_joystick)
5897 CalibrateJoystick(input_player_nr);
5900 CustomizeKeyboard(input_player_nr);
5902 else if (y == pos_end)
5908 setup_mode = SETUP_MODE_MAIN;
5915 void CustomizeKeyboard(int player_nr)
5919 boolean finished = FALSE;
5920 static struct SetupKeyboardInfo custom_key;
5925 } customize_step[] =
5927 { &custom_key.left, "Move Left" },
5928 { &custom_key.right, "Move Right" },
5929 { &custom_key.up, "Move Up" },
5930 { &custom_key.down, "Move Down" },
5931 { &custom_key.snap, "Snap Field" },
5932 { &custom_key.drop, "Drop Element" }
5935 /* read existing key bindings from player setup */
5936 custom_key = setup.input[player_nr].key;
5939 FadeOut(REDRAW_FIELD);
5943 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5951 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5952 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5953 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5954 "Key:", FONT_INPUT_1_ACTIVE);
5955 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5956 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5959 FadeIn(REDRAW_FIELD);
5966 if (PendingEvent()) /* got event */
5974 case EVENT_KEYPRESS:
5976 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5978 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5980 if (key == KSYM_Escape)
5981 FadeSkipNextFadeIn();
5987 /* all keys configured -- wait for "Escape" or "Return" key */
5991 /* press 'Enter' to keep the existing key binding */
5992 if (key == KSYM_Return)
5993 key = *customize_step[step_nr].key;
5995 /* check if key already used */
5996 for (i = 0; i < step_nr; i++)
5997 if (*customize_step[i].key == key)
6002 /* got new key binding */
6003 *customize_step[step_nr].key = key;
6004 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6006 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6007 getKeyNameFromKey(key), FONT_VALUE_1);
6010 /* un-highlight last query */
6011 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6012 customize_step[step_nr - 1].text, FONT_MENU_1);
6013 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6014 "Key:", FONT_MENU_1);
6016 /* press 'Enter' to leave */
6019 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6020 "Press Enter", FONT_TITLE_1);
6024 /* query next key binding */
6025 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6026 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6027 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6028 "Key:", FONT_INPUT_1_ACTIVE);
6029 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6030 getKeyNameFromKey(*customize_step[step_nr].key),
6035 case EVENT_KEYRELEASE:
6036 key_joystick_mapping = 0;
6040 HandleOtherEvents(&event);
6048 /* don't eat all CPU time */
6052 /* write new key bindings back to player setup */
6053 setup.input[player_nr].key = custom_key;
6056 DrawSetupScreen_Input();
6059 static boolean CalibrateJoystickMain(int player_nr)
6061 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6062 int new_joystick_xright = JOYSTICK_XMIDDLE;
6063 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6064 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6065 int new_joystick_xmiddle, new_joystick_ymiddle;
6067 int joystick_fd = joystick.fd[player_nr];
6068 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6069 boolean check[3][3];
6070 int check_remaining = 3 * 3;
6075 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6078 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6082 FadeOut(REDRAW_FIELD);
6086 for (y = 0; y < 3; y++)
6088 for (x = 0; x < 3; x++)
6090 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6091 check[x][y] = FALSE;
6095 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6096 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6097 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6098 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6099 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6100 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6101 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6103 joy_value = Joystick(player_nr);
6104 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6105 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6107 /* eventually uncalibrated center position (joystick could be uncentered) */
6108 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6111 new_joystick_xmiddle = joy_x;
6112 new_joystick_ymiddle = joy_y;
6114 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6116 FadeIn(REDRAW_FIELD);
6118 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6123 if (PendingEvent()) /* got event */
6131 case EVENT_KEYPRESS:
6132 switch (GetEventKey((KeyEvent *)&event, TRUE))
6135 if (check_remaining == 0)
6140 FadeSkipNextFadeIn();
6149 case EVENT_KEYRELEASE:
6150 key_joystick_mapping = 0;
6154 HandleOtherEvents(&event);
6159 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6162 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6163 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6164 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6165 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6167 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6168 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6169 setup.input[player_nr].joy.xright = new_joystick_xright;
6170 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6171 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6172 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6174 CheckJoystickData();
6176 joy_value = Joystick(player_nr);
6178 if (joy_value & JOY_BUTTON && check_remaining == 0)
6181 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6182 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6184 if (x != last_x || y != last_y)
6186 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6187 IMG_MENU_CALIBRATE_YELLOW, 0);
6188 DrawFixedGraphic(xpos + x, ypos + y,
6189 IMG_MENU_CALIBRATE_RED, 0);
6194 if (check_remaining > 0 && !check[x+1][y+1])
6196 check[x+1][y+1] = TRUE;
6202 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6203 setup.input[player_nr].joy.xleft,
6204 setup.input[player_nr].joy.xmiddle,
6205 setup.input[player_nr].joy.xright);
6206 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6207 setup.input[player_nr].joy.yupper,
6208 setup.input[player_nr].joy.ymiddle,
6209 setup.input[player_nr].joy.ylower);
6218 /* don't eat all CPU time */
6222 /* calibrated center position (joystick should now be centered) */
6223 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6226 new_joystick_xmiddle = joy_x;
6227 new_joystick_ymiddle = joy_y;
6232 DrawSetupScreen_Input();
6235 /* wait until the last pressed button was released */
6236 while (Joystick(player_nr) & JOY_BUTTON)
6238 if (PendingEvent()) /* got event */
6243 HandleOtherEvents(&event);
6252 void CalibrateJoystick(int player_nr)
6254 if (!CalibrateJoystickMain(player_nr))
6256 char *device_name = setup.input[player_nr].joy.device_name;
6257 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6258 int xpos = mSX - SX;
6259 int ypos = mSY - SY;
6263 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6264 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6267 Delay(2000); /* show error message for a short time */
6273 DrawSetupScreen_Input();
6277 void DrawSetupScreen()
6279 DeactivateJoystick();
6281 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6283 if (setup_mode == SETUP_MODE_INPUT)
6284 DrawSetupScreen_Input();
6285 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6286 DrawChooseTree(&game_speed_current);
6287 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6288 DrawChooseTree(&scroll_delay_current);
6289 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6290 DrawChooseTree(&screen_mode_current);
6291 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6292 DrawChooseTree(&window_size_current);
6293 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6294 DrawChooseTree(&scaling_type_current);
6295 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6296 DrawChooseTree(&artwork.gfx_current);
6297 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6298 DrawChooseTree(&artwork.snd_current);
6299 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6300 DrawChooseTree(&artwork.mus_current);
6301 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6302 DrawChooseTree(&volume_simple_current);
6303 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6304 DrawChooseTree(&volume_loops_current);
6305 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6306 DrawChooseTree(&volume_music_current);
6308 DrawSetupScreen_Generic();
6314 void RedrawSetupScreenAfterFullscreenToggle()
6317 if (setup_mode == SETUP_MODE_GRAPHICS ||
6318 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6320 // update list selection from "setup.window_scaling_percent"
6321 execSetupGraphics_setWindowSizes(TRUE);
6326 if (setup_mode == SETUP_MODE_GRAPHICS)
6331 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6333 if (setup_mode == SETUP_MODE_INPUT)
6334 HandleSetupScreen_Input(mx, my, dx, dy, button);
6335 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6336 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6337 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6338 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6339 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6340 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6341 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6342 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6343 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6344 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6345 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6346 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6347 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6348 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6349 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6350 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6351 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6352 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6353 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6354 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6355 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6356 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6358 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6365 void HandleGameActions()
6367 if (game_status != GAME_MODE_PLAYING)
6370 GameActions(); /* main game loop */
6372 if (tape.auto_play && !tape.playing)
6373 AutoPlayTape(); /* continue automatically playing next tape */
6377 /* ---------- new screen button stuff -------------------------------------- */
6379 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6384 case SCREEN_CTRL_ID_PREV_LEVEL:
6385 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6386 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6389 case SCREEN_CTRL_ID_NEXT_LEVEL:
6390 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6391 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6394 case SCREEN_CTRL_ID_PREV_LEVEL:
6395 *x = mSX + TILEX * getPrevlevelButtonPos();
6396 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6399 case SCREEN_CTRL_ID_NEXT_LEVEL:
6400 *x = mSX + TILEX * getNextLevelButtonPos();
6401 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6405 case SCREEN_CTRL_ID_PREV_PLAYER:
6406 *x = mSX + TILEX * 10;
6407 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6410 case SCREEN_CTRL_ID_NEXT_PLAYER:
6411 *x = mSX + TILEX * 12;
6412 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6416 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6422 int gfx_unpressed, gfx_pressed;
6423 void (*get_gadget_position)(int *, int *, int);
6427 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6430 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6431 getScreenMenuButtonPos,
6432 SCREEN_CTRL_ID_PREV_LEVEL,
6437 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6438 getScreenMenuButtonPos,
6439 SCREEN_CTRL_ID_NEXT_LEVEL,
6444 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6445 getScreenMenuButtonPos,
6446 SCREEN_CTRL_ID_PREV_PLAYER,
6451 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6452 getScreenMenuButtonPos,
6453 SCREEN_CTRL_ID_NEXT_PLAYER,
6461 int gfx_unpressed, gfx_pressed;
6465 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6468 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6470 -1, -1, /* these values are not constant, but can change at runtime */
6472 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6474 SCREEN_CTRL_ID_SCROLL_UP,
6478 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6480 -1, -1, /* these values are not constant, but can change at runtime */
6482 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6484 SCREEN_CTRL_ID_SCROLL_DOWN,
6491 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6492 Bitmap **gfx_unpressed, **gfx_pressed;
6494 int gfx_unpressed, gfx_pressed;
6501 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6504 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6505 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6507 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6510 -1, -1, /* these values are not constant, but can change at runtime */
6511 -1, -1, /* these values are not constant, but can change at runtime */
6513 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6514 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6516 GD_TYPE_SCROLLBAR_VERTICAL,
6517 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6518 "scroll level series vertically"
6522 static void CreateScreenMenubuttons()
6524 struct GadgetInfo *gi;
6525 unsigned int event_mask;
6528 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6530 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6531 int gfx_unpressed, gfx_pressed;
6532 int x, y, width, height;
6533 int gd_x1, gd_x2, gd_y1, gd_y2;
6534 int id = menubutton_info[i].gadget_id;
6536 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6538 menubutton_info[i].get_gadget_position(&x, &y, id);
6540 width = SC_MENUBUTTON_XSIZE;
6541 height = SC_MENUBUTTON_YSIZE;
6543 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6544 gfx_pressed = menubutton_info[i].gfx_pressed;
6545 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6546 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6547 gd_x1 = graphic_info[gfx_unpressed].src_x;
6548 gd_y1 = graphic_info[gfx_unpressed].src_y;
6549 gd_x2 = graphic_info[gfx_pressed].src_x;
6550 gd_y2 = graphic_info[gfx_pressed].src_y;
6552 gi = CreateGadget(GDI_CUSTOM_ID, id,
6553 GDI_CUSTOM_TYPE_ID, i,
6554 GDI_INFO_TEXT, menubutton_info[i].infotext,
6559 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6560 GDI_STATE, GD_BUTTON_UNPRESSED,
6561 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6562 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6563 GDI_DIRECT_DRAW, FALSE,
6564 GDI_EVENT_MASK, event_mask,
6565 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6569 Error(ERR_EXIT, "cannot create gadget");
6571 screen_gadget[id] = gi;
6575 static void CreateScreenScrollbuttons()
6577 struct GadgetInfo *gi;
6578 unsigned int event_mask;
6581 /* these values are not constant, but can change at runtime */
6582 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6583 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6584 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6585 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6587 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6589 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6590 int gfx_unpressed, gfx_pressed;
6591 int x, y, width, height;
6592 int gd_x1, gd_x2, gd_y1, gd_y2;
6593 int id = scrollbutton_info[i].gadget_id;
6595 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6597 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6598 y = mSY + scrollbutton_info[i].y;
6599 width = SC_SCROLLBUTTON_XSIZE;
6600 height = SC_SCROLLBUTTON_YSIZE;
6602 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6603 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6604 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6606 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6607 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6608 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6609 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6610 gd_x1 = graphic_info[gfx_unpressed].src_x;
6611 gd_y1 = graphic_info[gfx_unpressed].src_y;
6612 gd_x2 = graphic_info[gfx_pressed].src_x;
6613 gd_y2 = graphic_info[gfx_pressed].src_y;
6615 gi = CreateGadget(GDI_CUSTOM_ID, id,
6616 GDI_CUSTOM_TYPE_ID, i,
6617 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6622 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6623 GDI_STATE, GD_BUTTON_UNPRESSED,
6624 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6625 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6626 GDI_DIRECT_DRAW, FALSE,
6627 GDI_EVENT_MASK, event_mask,
6628 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6632 Error(ERR_EXIT, "cannot create gadget");
6634 screen_gadget[id] = gi;
6638 static void CreateScreenScrollbars()
6642 /* these values are not constant, but can change at runtime */
6643 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6644 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6645 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6646 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6648 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6650 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6651 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6652 int gfx_unpressed, gfx_pressed;
6654 int x, y, width, height;
6655 int gd_x1, gd_x2, gd_y1, gd_y2;
6656 struct GadgetInfo *gi;
6657 int items_max, items_visible, item_position;
6658 unsigned int event_mask;
6659 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6660 int id = scrollbar_info[i].gadget_id;
6662 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6664 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6665 y = mSY + scrollbar_info[i].y;
6666 width = scrollbar_info[i].width;
6667 height = scrollbar_info[i].height;
6669 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6670 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6672 items_max = num_page_entries;
6673 items_visible = num_page_entries;
6676 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6677 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6678 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6684 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6685 gfx_pressed = scrollbar_info[i].gfx_pressed;
6686 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6687 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6688 gd_x1 = graphic_info[gfx_unpressed].src_x;
6689 gd_y1 = graphic_info[gfx_unpressed].src_y;
6690 gd_x2 = graphic_info[gfx_pressed].src_x;
6691 gd_y2 = graphic_info[gfx_pressed].src_y;
6694 gi = CreateGadget(GDI_CUSTOM_ID, id,
6695 GDI_CUSTOM_TYPE_ID, i,
6696 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6701 GDI_TYPE, scrollbar_info[i].type,
6702 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6703 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6704 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6706 GDI_WHEEL_AREA_X, SX,
6707 GDI_WHEEL_AREA_Y, SY,
6708 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6709 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6711 GDI_WHEEL_AREA_X, 0,
6712 GDI_WHEEL_AREA_Y, 0,
6713 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6714 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6716 GDI_STATE, GD_BUTTON_UNPRESSED,
6717 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6718 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6719 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6720 GDI_DIRECT_DRAW, FALSE,
6721 GDI_EVENT_MASK, event_mask,
6722 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6726 Error(ERR_EXIT, "cannot create gadget");
6728 screen_gadget[id] = gi;
6732 void CreateScreenGadgets()
6734 int last_game_status = game_status; /* save current game status */
6736 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6739 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6741 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6743 /* copy pointers to clip mask and GC */
6744 scrollbar_bitmap[i]->clip_mask =
6745 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6746 scrollbar_bitmap[i]->stored_clip_gc =
6747 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6749 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6750 scrollbar_bitmap[i],
6751 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6752 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6753 TILEX, TILEY, 0, 0);
6757 CreateScreenMenubuttons();
6760 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6761 game_status = GAME_MODE_LEVELS;
6764 CreateScreenScrollbuttons();
6765 CreateScreenScrollbars();
6767 game_status = last_game_status; /* restore current game status */
6770 void FreeScreenGadgets()
6774 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6775 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6777 /* prevent freeing clip mask and GC twice */
6778 scrollbar_bitmap[i]->clip_mask = None;
6779 scrollbar_bitmap[i]->stored_clip_gc = None;
6781 FreeBitmap(scrollbar_bitmap[i]);
6785 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6786 FreeGadget(screen_gadget[i]);
6789 void MapScreenMenuGadgets(int screen_mask)
6793 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6794 if (screen_mask & menubutton_info[i].screen_mask)
6795 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6798 void MapScreenTreeGadgets(TreeInfo *ti)
6800 int num_entries = numTreeInfoInGroup(ti);
6803 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6806 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6807 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6809 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6810 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6813 static void HandleScreenGadgets(struct GadgetInfo *gi)
6815 int id = gi->custom_id;
6816 int button = gi->event.button;
6817 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6821 case SCREEN_CTRL_ID_PREV_LEVEL:
6822 HandleMainMenu_SelectLevel(step, -1);
6825 case SCREEN_CTRL_ID_NEXT_LEVEL:
6826 HandleMainMenu_SelectLevel(step, +1);
6829 case SCREEN_CTRL_ID_PREV_PLAYER:
6830 HandleSetupScreen_Input_Player(step, -1);
6833 case SCREEN_CTRL_ID_NEXT_PLAYER:
6834 HandleSetupScreen_Input_Player(step, +1);
6837 case SCREEN_CTRL_ID_SCROLL_UP:
6838 if (game_status == GAME_MODE_LEVELS)
6839 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6840 else if (game_status == GAME_MODE_LEVELNR)
6841 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6842 else if (game_status == GAME_MODE_SETUP)
6843 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6846 case SCREEN_CTRL_ID_SCROLL_DOWN:
6847 if (game_status == GAME_MODE_LEVELS)
6848 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6849 else if (game_status == GAME_MODE_LEVELNR)
6850 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6851 else if (game_status == GAME_MODE_SETUP)
6852 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6855 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6856 if (game_status == GAME_MODE_LEVELS)
6857 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6858 else if (game_status == GAME_MODE_LEVELNR)
6859 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6860 else if (game_status == GAME_MODE_SETUP)
6861 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);