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 MAX_INFO_ELEMENTS_ON_SCREEN 10
90 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
91 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
92 MENU_SCREEN_START_XPOS)
93 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
95 /* buttons and scrollbars identifiers */
96 #define SCREEN_CTRL_ID_PREV_LEVEL 0
97 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
98 #define SCREEN_CTRL_ID_PREV_PLAYER 2
99 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
100 #define SCREEN_CTRL_ID_SCROLL_UP 4
101 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
102 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
104 #define NUM_SCREEN_GADGETS 7
106 #define NUM_SCREEN_MENUBUTTONS 4
107 #define NUM_SCREEN_SCROLLBUTTONS 2
108 #define NUM_SCREEN_SCROLLBARS 1
110 #define SCREEN_MASK_MAIN (1 << 0)
111 #define SCREEN_MASK_INPUT (1 << 1)
113 /* graphic position and size values for buttons and scrollbars */
114 #define SC_MENUBUTTON_XSIZE TILEX
115 #define SC_MENUBUTTON_YSIZE TILEY
117 #define SC_SCROLLBUTTON_XSIZE TILEX
118 #define SC_SCROLLBUTTON_YSIZE TILEY
120 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
122 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
123 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
124 SC_SCROLLBUTTON_YSIZE)
126 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
127 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
129 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
130 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
131 SC_SCROLLBUTTON_YSIZE)
133 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
134 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
135 SC_SCROLL_VERTICAL_YSIZE)
137 #define SC_BORDER_SIZE 14
140 /* forward declarations of internal functions */
141 static void HandleScreenGadgets(struct GadgetInfo *);
142 static void HandleSetupScreen_Generic(int, int, int, int, int);
143 static void HandleSetupScreen_Input(int, int, int, int, int);
144 static void CustomizeKeyboard(int);
145 static void CalibrateJoystick(int);
146 static void execSetupGame(void);
147 static void execSetupGraphics(void);
148 static void execSetupSound(void);
149 static void execSetupArtwork(void);
150 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
152 static void DrawChooseLevelSet(void);
153 static void DrawChooseLevelNr(void);
154 static void DrawInfoScreen(void);
155 static void DrawAndFadeInInfoScreen(int);
156 static void DrawSetupScreen(void);
158 static void DrawInfoScreenExt(int, int);
159 static void DrawInfoScreen_NotAvailable(char *, char *);
160 static void DrawInfoScreen_HelpAnim(int, int, boolean);
161 static void DrawInfoScreen_HelpText(int, int, int, int);
162 static void HandleInfoScreen_Main(int, int, int, int, int);
163 static void HandleInfoScreen_TitleScreen(int);
164 static void HandleInfoScreen_Elements(int);
165 static void HandleInfoScreen_Music(int);
166 static void HandleInfoScreen_Credits(int);
167 static void HandleInfoScreen_Program(int);
168 static void HandleInfoScreen_Version(int);
170 static void MapScreenMenuGadgets(int);
171 static void MapScreenTreeGadgets(TreeInfo *);
173 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
175 static int info_mode = INFO_MODE_MAIN;
176 static int setup_mode = SETUP_MODE_MAIN;
178 static TreeInfo *screen_modes = NULL;
179 static TreeInfo *screen_mode_current = NULL;
181 static TreeInfo *window_sizes = NULL;
182 static TreeInfo *window_size_current = NULL;
184 static TreeInfo *scaling_types = NULL;
185 static TreeInfo *scaling_type_current = NULL;
187 static TreeInfo *scroll_delays = NULL;
188 static TreeInfo *scroll_delay_current = NULL;
190 static TreeInfo *game_speeds = NULL;
191 static TreeInfo *game_speed_current = NULL;
193 static TreeInfo *volumes_simple = NULL;
194 static TreeInfo *volume_simple_current = NULL;
196 static TreeInfo *volumes_loops = NULL;
197 static TreeInfo *volume_loops_current = NULL;
199 static TreeInfo *volumes_music = NULL;
200 static TreeInfo *volume_music_current = NULL;
202 static TreeInfo *level_number = NULL;
203 static TreeInfo *level_number_current = NULL;
209 } window_sizes_list[] =
214 { 100, "100 % (Default)" },
231 } scaling_types_list[] =
233 { SCALING_QUALITY_NEAREST, "None" },
234 { SCALING_QUALITY_LINEAR, "Linear" },
235 { SCALING_QUALITY_BEST, "Anisotropic" },
244 } game_speeds_list[] =
253 { 1000, "1/1s (Extremely Slow)" },
258 { 29, "1/35s (Original Supaplex)" },
260 { 20, "1/50s (Normal Speed)" },
261 { 14, "1/70s (Maximum Supaplex)" },
265 { 1, "1/1000s (Extremely Fast)" },
275 } scroll_delays_list[] =
277 { 0, "0 Tiles (No Scroll Delay)" },
280 { 3, "3 Tiles (Default)" },
285 { 8, "8 Tiles (Maximum Scroll Delay)"},
311 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
312 (s) <= GAME_MODE_SETUP ? (s) : \
313 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
314 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
316 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
317 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
318 (i) <= INFO_MODE_LEVELSET ? (i) : \
321 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
322 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
323 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
324 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
325 SETUP_MODE_CHOOSE_ARTWORK : \
326 SETUP_MODE_CHOOSE_OTHER)
328 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
329 menu.draw_xoffset[GAME_MODE_INFO] : \
330 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
331 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
332 menu.draw_yoffset[GAME_MODE_INFO] : \
333 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
335 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
336 menu.draw_xoffset[GAME_MODE_SETUP] : \
337 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
338 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
339 menu.draw_yoffset[GAME_MODE_SETUP] : \
340 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
342 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
343 DRAW_XOFFSET_INFO(info_mode) : \
344 (s) == GAME_MODE_SETUP ? \
345 DRAW_XOFFSET_SETUP(setup_mode) : \
346 menu.draw_xoffset[DRAW_MODE(s)])
347 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
348 DRAW_YOFFSET_INFO(info_mode) : \
349 (s) == GAME_MODE_SETUP ? \
350 DRAW_YOFFSET_SETUP(setup_mode) : \
351 menu.draw_yoffset[DRAW_MODE(s)])
353 #define mSX (SX + DRAW_XOFFSET(game_status))
354 #define mSY (SY + DRAW_YOFFSET(game_status))
356 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
357 menu.list_size[game_status] : \
358 MAX_MENU_ENTRIES_ON_SCREEN)
360 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
361 #define NUM_SCROLLBAR_BITMAPS 2
362 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
366 /* title display and control definitions */
368 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
369 2 * MAX_NUM_TITLE_MESSAGES)
371 static int num_title_screens = 0;
373 struct TitleControlInfo
381 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
383 /* main menu display and control definitions */
385 #define MAIN_CONTROL_NAME 0
386 #define MAIN_CONTROL_LEVELS 1
387 #define MAIN_CONTROL_SCORES 2
388 #define MAIN_CONTROL_EDITOR 3
389 #define MAIN_CONTROL_INFO 4
390 #define MAIN_CONTROL_GAME 5
391 #define MAIN_CONTROL_SETUP 6
392 #define MAIN_CONTROL_QUIT 7
393 #define MAIN_CONTROL_PREV_LEVEL 8
394 #define MAIN_CONTROL_NEXT_LEVEL 9
395 #define MAIN_CONTROL_FIRST_LEVEL 10
396 #define MAIN_CONTROL_LAST_LEVEL 11
397 #define MAIN_CONTROL_LEVEL_NUMBER 12
398 #define MAIN_CONTROL_LEVEL_INFO_1 13
399 #define MAIN_CONTROL_LEVEL_INFO_2 14
400 #define MAIN_CONTROL_LEVEL_NAME 15
401 #define MAIN_CONTROL_LEVEL_AUTHOR 16
402 #define MAIN_CONTROL_LEVEL_YEAR 17
403 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
404 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
405 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
406 #define MAIN_CONTROL_TITLE_1 21
407 #define MAIN_CONTROL_TITLE_2 22
408 #define MAIN_CONTROL_TITLE_3 23
410 static char str_main_text_name[10];
411 static char str_main_text_first_level[10];
412 static char str_main_text_last_level[10];
413 static char str_main_text_level_number[10];
415 static char *main_text_name = str_main_text_name;
416 static char *main_text_first_level = str_main_text_first_level;
417 static char *main_text_last_level = str_main_text_last_level;
418 static char *main_text_level_number = str_main_text_level_number;
419 static char *main_text_levels = "Levelset";
420 static char *main_text_scores = "Hall Of Fame";
421 static char *main_text_editor = "Level Creator";
422 static char *main_text_info = "Info Screen";
423 static char *main_text_game = "Start Game";
424 static char *main_text_setup = "Setup";
425 static char *main_text_quit = "Quit";
426 static char *main_text_level_name = level.name;
427 static char *main_text_level_author = level.author;
428 static char *main_text_level_year = NULL;
429 static char *main_text_level_imported_from = NULL;
430 static char *main_text_level_imported_by = NULL;
431 static char *main_text_level_tested_by = NULL;
432 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
433 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
434 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
436 struct MainControlInfo
440 struct MenuPosInfo *pos_button;
443 struct TextPosInfo *pos_text;
446 struct TextPosInfo *pos_input;
450 static struct MainControlInfo main_controls[] =
454 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
455 &menu.main.text.name, &main_text_name,
456 &menu.main.input.name, &setup.player_name,
460 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
461 &menu.main.text.levels, &main_text_levels,
466 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
467 &menu.main.text.scores, &main_text_scores,
472 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
473 &menu.main.text.editor, &main_text_editor,
478 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
479 &menu.main.text.info, &main_text_info,
484 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
485 &menu.main.text.game, &main_text_game,
490 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
491 &menu.main.text.setup, &main_text_setup,
496 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
497 &menu.main.text.quit, &main_text_quit,
501 /* (these two buttons are real gadgets) */
503 MAIN_CONTROL_PREV_LEVEL,
504 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
509 MAIN_CONTROL_NEXT_LEVEL,
510 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
516 MAIN_CONTROL_FIRST_LEVEL,
518 &menu.main.text.first_level, &main_text_first_level,
522 MAIN_CONTROL_LAST_LEVEL,
524 &menu.main.text.last_level, &main_text_last_level,
528 MAIN_CONTROL_LEVEL_NUMBER,
530 &menu.main.text.level_number, &main_text_level_number,
534 MAIN_CONTROL_LEVEL_INFO_1,
536 &menu.main.text.level_info_1, NULL,
540 MAIN_CONTROL_LEVEL_INFO_2,
542 &menu.main.text.level_info_2, NULL,
546 MAIN_CONTROL_LEVEL_NAME,
548 &menu.main.text.level_name, &main_text_level_name,
552 MAIN_CONTROL_LEVEL_AUTHOR,
554 &menu.main.text.level_author, &main_text_level_author,
558 MAIN_CONTROL_LEVEL_YEAR,
560 &menu.main.text.level_year, &main_text_level_year,
564 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
566 &menu.main.text.level_imported_from, &main_text_level_imported_from,
570 MAIN_CONTROL_LEVEL_IMPORTED_BY,
572 &menu.main.text.level_imported_by, &main_text_level_imported_by,
576 MAIN_CONTROL_LEVEL_TESTED_BY,
578 &menu.main.text.level_tested_by, &main_text_level_tested_by,
582 MAIN_CONTROL_TITLE_1,
584 &menu.main.text.title_1, &main_text_title_1,
588 MAIN_CONTROL_TITLE_2,
590 &menu.main.text.title_2, &main_text_title_2,
594 MAIN_CONTROL_TITLE_3,
596 &menu.main.text.title_3, &main_text_title_3,
609 static int getTitleScreenGraphic(int nr, boolean initial)
611 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
614 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
616 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
620 static int getTitleScreenGameMode(boolean initial)
622 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
626 static int getTitleMessageGameMode(boolean initial)
628 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
632 static int getTitleScreenBackground(boolean initial)
634 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
639 static int getTitleMessageBackground(int nr, boolean initial)
641 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
645 static int getTitleBackground(int nr, boolean initial, boolean is_image)
647 int base = (is_image ?
648 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
649 IMG_BACKGROUND_TITLESCREEN_1) :
650 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
651 IMG_BACKGROUND_TITLEMESSAGE_1));
652 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
653 IMG_BACKGROUND_TITLE);
654 int graphic_local = base + nr;
656 if (graphic_info[graphic_local].bitmap != NULL)
657 return graphic_local;
659 if (graphic_info[graphic_global].bitmap != NULL)
660 return graphic_global;
662 return IMG_UNDEFINED;
665 static int getTitleSound(struct TitleControlInfo *tci)
667 boolean is_image = tci->is_image;
668 int initial = tci->initial;
669 int nr = tci->local_nr;
670 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
671 int base = (is_image ?
672 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
673 SND_BACKGROUND_TITLESCREEN_1) :
674 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
675 SND_BACKGROUND_TITLEMESSAGE_1));
676 int sound_global = menu.sound[mode];
677 int sound_local = base + nr;
680 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
681 nr, initial, is_image,
682 sound_global, getSoundListEntry(sound_global)->filename,
683 sound_local, getSoundListEntry(sound_local)->filename);
686 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
689 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
692 return SND_UNDEFINED;
695 static int getTitleMusic(struct TitleControlInfo *tci)
697 boolean is_image = tci->is_image;
698 int initial = tci->initial;
699 int nr = tci->local_nr;
700 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
701 int base = (is_image ?
702 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
703 MUS_BACKGROUND_TITLESCREEN_1) :
704 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
705 MUS_BACKGROUND_TITLEMESSAGE_1));
706 int music_global = menu.music[mode];
707 int music_local = base + nr;
710 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
711 nr, initial, is_image,
712 music_global, getMusicListEntry(music_global)->filename,
713 music_local, getMusicListEntry(music_local)->filename);
716 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
719 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
722 return MUS_UNDEFINED;
725 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
727 boolean is_image = tci->is_image;
728 int initial = tci->initial;
729 int nr = tci->local_nr;
730 struct TitleFadingInfo ti;
734 int graphic = getTitleScreenGraphic(nr, initial);
736 /* initialize fading control values to default title config settings */
737 ti = (initial ? title_initial_default : title_default);
739 /* override default settings with image config settings, if defined */
740 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
741 ti.fade_mode = graphic_info[graphic].fade_mode;
742 if (graphic_info[graphic].fade_delay > -1)
743 ti.fade_delay = graphic_info[graphic].fade_delay;
744 if (graphic_info[graphic].post_delay > -1)
745 ti.post_delay = graphic_info[graphic].post_delay;
746 if (graphic_info[graphic].auto_delay > -1)
747 ti.auto_delay = graphic_info[graphic].auto_delay;
753 ti.fade_mode = titlemessage_initial[nr].fade_mode;
754 ti.fade_delay = titlemessage_initial[nr].fade_delay;
755 ti.post_delay = titlemessage_initial[nr].post_delay;
756 ti.auto_delay = titlemessage_initial[nr].auto_delay;
760 ti.fade_mode = titlemessage[nr].fade_mode;
761 ti.fade_delay = titlemessage[nr].fade_delay;
762 ti.post_delay = titlemessage[nr].post_delay;
763 ti.auto_delay = titlemessage[nr].auto_delay;
768 if (ti.anim_mode == ANIM_NONE)
769 ti.fade_delay = ti.post_delay = 0;
775 static int compareTitleControlInfo(const void *object1, const void *object2)
777 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
778 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
781 if (tci1->initial != tci2->initial)
782 compare_result = (tci1->initial ? -1 : +1);
783 else if (tci1->sort_priority != tci2->sort_priority)
784 compare_result = tci1->sort_priority - tci2->sort_priority;
785 else if (tci1->is_image != tci2->is_image)
786 compare_result = (tci1->is_image ? -1 : +1);
788 compare_result = tci1->local_nr - tci2->local_nr;
790 return compare_result;
793 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
795 int nr, int sort_priority)
797 title_controls[num_title_screens].is_image = is_image;
798 title_controls[num_title_screens].initial = initial;
799 title_controls[num_title_screens].local_nr = nr;
800 title_controls[num_title_screens].sort_priority = sort_priority;
805 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
809 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
811 int graphic = getTitleScreenGraphic(i, initial);
812 Bitmap *bitmap = graphic_info[graphic].bitmap;
813 int sort_priority = graphic_info[graphic].sort_priority;
816 /* skip images and messages (fonts!) when using forced custom graphics */
817 if (setup.override_level_graphics && !initial)
822 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
825 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
827 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
828 char *filename = getLevelSetTitleMessageFilename(i, initial);
829 int sort_priority = tmi->sort_priority;
832 /* skip images and messages (fonts!) when using forced custom graphics */
833 if (setup.override_level_graphics)
837 if (filename != NULL)
838 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
842 static void InitializeTitleControls(boolean show_title_initial)
844 num_title_screens = 0;
847 /* 1st step: initialize title screens for game start (only when starting) */
848 if (show_title_initial)
849 InitializeTitleControls_CheckTitleInfo(TRUE);
852 /* 2nd step: initialize title screens for current level set */
853 InitializeTitleControls_CheckTitleInfo(FALSE);
855 /* sort title screens according to sort_priority and title number */
856 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
857 compareTitleControlInfo);
860 static boolean visibleMenuPos(struct MenuPosInfo *pos)
862 return (pos != NULL && pos->x != -1 && pos->y != -1);
865 static boolean visibleTextPos(struct TextPosInfo *pos)
867 return (pos != NULL && pos->x != -1 && pos->y != -1);
870 static void InitializeMainControls()
872 boolean local_team_mode = (!options.network && setup.team_mode);
875 /* set main control text values to dynamically determined values */
876 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
878 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
879 menu.main.text.first_level.size));
880 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
881 menu.main.text.last_level.size));
882 strcpy(main_text_level_number, int2str(level_nr,
883 menu.main.text.level_number.size));
885 main_text_level_year = leveldir_current->year;
886 main_text_level_imported_from = leveldir_current->imported_from;
887 main_text_level_imported_by = leveldir_current->imported_by;
888 main_text_level_tested_by = leveldir_current->tested_by;
890 /* set main control screen positions to dynamically determined values */
891 for (i = 0; main_controls[i].nr != -1; i++)
893 struct MainControlInfo *mci = &main_controls[i];
895 struct MenuPosInfo *pos_button = mci->pos_button;
896 struct TextPosInfo *pos_text = mci->pos_text;
897 struct TextPosInfo *pos_input = mci->pos_input;
898 char *text = (mci->text ? *mci->text : NULL);
899 char *input = (mci->input ? *mci->input : NULL);
900 int button_graphic = mci->button_graphic;
902 int font_text = (pos_text ? pos_text->font : -1);
903 int font_input = (pos_input ? pos_input->font : -1);
905 int font_text = mci->font_text;
906 int font_input = mci->font_input;
909 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
910 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
911 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
912 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
913 int text_chars = (text != NULL ? strlen(text) : 0);
914 int input_chars = (input != NULL ? strlen(input) : 0);
917 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
919 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
920 int text_width = font_text_width * text_chars;
921 int text_height = font_text_height;
922 int input_width = font_input_width * input_chars;
923 int input_height = font_input_height;
925 if (nr == MAIN_CONTROL_NAME)
928 if (menu.main.input.name.x == -1)
929 menu.main.input.name.x = menu.main.text.name.x + text_width;
930 if (menu.main.input.name.y == -1)
931 menu.main.input.name.y = menu.main.text.name.y;
935 menu.main.input.name.width = input_width;
936 menu.main.input.name.height = input_height;
938 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
939 menu.main.input.name.height = font_input_height;
943 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
945 if (pos_button->width == 0)
946 pos_button->width = button_width;
947 if (pos_button->height == 0)
948 pos_button->height = button_height;
951 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
954 /* calculate size for non-clickable text -- needed for text alignment */
955 boolean calculate_text_size = (pos_button == NULL && text != NULL);
957 /* calculate width for non-clickable text -- needed for text alignment */
958 boolean calculate_text_width = (pos_button == NULL && text != NULL);
961 if (visibleMenuPos(pos_button))
963 if (pos_text->x == -1)
964 pos_text->x = pos_button->x + pos_button->width;
965 if (pos_text->y == -1)
966 pos_text->y = pos_button->y;
970 if (pos_text->width == -1 || calculate_text_size)
971 pos_text->width = text_width;
972 if (pos_text->height == -1 || calculate_text_size)
973 pos_text->height = text_height;
975 if (pos_text->width == -1 || calculate_text_width)
976 pos_text->width = text_width;
977 if (pos_text->height == -1)
978 pos_text->height = text_height;
982 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
984 if (visibleTextPos(pos_text))
986 if (pos_input->x == -1)
987 pos_input->x = pos_text->x + pos_text->width;
988 if (pos_input->y == -1)
989 pos_input->y = pos_text->y;
992 if (pos_input->width == -1)
993 pos_input->width = input_width;
994 if (pos_input->height == -1)
995 pos_input->height = input_height;
1000 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1001 boolean active_input)
1005 for (i = 0; main_controls[i].nr != -1; i++)
1007 struct MainControlInfo *mci = &main_controls[i];
1009 if (mci->nr == nr || nr == -1)
1011 struct MenuPosInfo *pos_button = mci->pos_button;
1012 struct TextPosInfo *pos_text = mci->pos_text;
1013 struct TextPosInfo *pos_input = mci->pos_input;
1014 char *text = (mci->text ? *mci->text : NULL);
1015 char *input = (mci->input ? *mci->input : NULL);
1016 int button_graphic = mci->button_graphic;
1018 int font_text = (pos_text ? pos_text->font : -1);
1019 int font_input = (pos_input ? pos_input->font : -1);
1021 int font_text = mci->font_text;
1022 int font_input = mci->font_input;
1027 button_graphic = BUTTON_ACTIVE(button_graphic);
1028 font_text = FONT_ACTIVE(font_text);
1033 font_input = FONT_ACTIVE(font_input);
1036 if (visibleMenuPos(pos_button))
1038 struct MenuPosInfo *pos = pos_button;
1039 int x = mSX + pos->x;
1040 int y = mSY + pos->y;
1042 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1043 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1046 if (visibleTextPos(pos_text) && text != NULL)
1048 struct TextPosInfo *pos = pos_text;
1049 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1050 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1053 /* (check why/if this is needed) */
1054 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1056 DrawText(x, y, text, font_text);
1059 if (visibleTextPos(pos_input) && input != NULL)
1061 struct TextPosInfo *pos = pos_input;
1062 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1063 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1066 /* (check why/if this is needed) */
1067 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1069 DrawText(x, y, input, font_input);
1075 static void DrawCursorAndText_Main(int nr, boolean active_text)
1077 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1081 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1083 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1087 static struct MainControlInfo *getMainControlInfo(int nr)
1091 for (i = 0; main_controls[i].nr != -1; i++)
1092 if (main_controls[i].nr == nr)
1093 return &main_controls[i];
1098 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1103 int rect_x = ALIGNED_TEXT_XPOS(rect);
1104 int rect_y = ALIGNED_TEXT_YPOS(rect);
1106 return (x >= rect_x && x < rect_x + rect->width &&
1107 y >= rect_y && y < rect_y + rect->height);
1110 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1115 int rect_x = ALIGNED_TEXT_XPOS(rect);
1116 int rect_y = ALIGNED_TEXT_YPOS(rect);
1119 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1120 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1121 (x >= rect_x && x < rect_x + rect->width &&
1122 y >= rect_y && y < rect_y + rect->height));
1125 return (x >= rect_x && x < rect_x + rect->width &&
1126 y >= rect_y && y < rect_y + rect->height);
1129 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1132 static int cursor_array[MAX_LEV_FIELDY];
1134 static int cursor_array[SCR_FIELDY];
1136 int x = mSX + TILEX * xpos;
1137 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1142 cursor_array[ypos] = graphic;
1144 graphic = cursor_array[ypos];
1148 graphic = BUTTON_ACTIVE(graphic);
1150 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1151 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1154 static void initCursor(int ypos, int graphic)
1156 drawCursorExt(0, ypos, FALSE, graphic);
1159 static void drawCursor(int ypos, boolean active)
1161 drawCursorExt(0, ypos, active, -1);
1164 static void drawCursorXY(int xpos, int ypos, int graphic)
1166 drawCursorExt(xpos, ypos, FALSE, graphic);
1169 static void drawChooseTreeCursor(int ypos, boolean active)
1171 int last_game_status = game_status; /* save current game status */
1174 /* force LEVELS draw offset on artwork setup screen */
1175 game_status = GAME_MODE_LEVELS;
1178 drawCursorExt(0, ypos, active, -1);
1180 game_status = last_game_status; /* restore current game status */
1185 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1186 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1190 static int getPrevlevelButtonPos()
1195 static int getCurrentLevelTextPos()
1197 return (getPrevlevelButtonPos() + 1);
1200 static int getNextLevelButtonPos()
1202 return getPrevlevelButtonPos() + 3 + 1;
1205 static int getLevelRangeTextPos()
1207 return getNextLevelButtonPos() + 1;
1211 int effectiveGameStatus()
1213 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1214 return GAME_MODE_TITLE;
1219 void DrawTitleScreenImage(int nr, boolean initial)
1221 int graphic = getTitleScreenGraphic(nr, initial);
1222 Bitmap *bitmap = graphic_info[graphic].bitmap;
1223 int width = graphic_info[graphic].width;
1224 int height = graphic_info[graphic].height;
1225 int src_x = graphic_info[graphic].src_x;
1226 int src_y = graphic_info[graphic].src_y;
1232 if (width > WIN_XSIZE)
1234 /* image width too large for window => center image horizontally */
1235 src_x = (width - WIN_XSIZE) / 2;
1239 if (height > WIN_YSIZE)
1241 /* image height too large for window => center image vertically */
1242 src_y = (height - WIN_YSIZE) / 2;
1246 /* always display title screens centered */
1247 dst_x = (WIN_XSIZE - width) / 2;
1248 dst_y = (WIN_YSIZE - height) / 2;
1250 SetDrawBackgroundMask(REDRAW_ALL);
1251 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1253 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1255 if (DrawingOnBackground(dst_x, dst_y))
1257 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1258 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1261 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1263 redraw_mask = REDRAW_ALL;
1266 void DrawTitleScreenMessage(int nr, boolean initial)
1268 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1269 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1270 int last_game_status = game_status; /* save current game status */
1272 if (filename == NULL)
1275 /* force TITLE font on title message screen */
1276 game_status = getTitleMessageGameMode(initial);
1278 /* if chars set to "-1", automatically determine by text and font width */
1279 if (tmi->chars == -1)
1280 tmi->chars = tmi->width / getFontWidth(tmi->font);
1282 tmi->width = tmi->chars * getFontWidth(tmi->font);
1284 /* if lines set to "-1", automatically determine by text and font height */
1285 if (tmi->lines == -1)
1286 tmi->lines = tmi->height / getFontHeight(tmi->font);
1288 tmi->height = tmi->lines * getFontHeight(tmi->font);
1290 SetDrawBackgroundMask(REDRAW_ALL);
1291 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1293 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1295 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1296 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1297 tmi->autowrap, tmi->centered, tmi->parse_comments);
1299 game_status = last_game_status; /* restore current game status */
1302 void DrawTitleScreen()
1304 KeyboardAutoRepeatOff();
1307 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1310 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1315 boolean CheckTitleScreen(boolean levelset_has_changed)
1317 static boolean show_title_initial = TRUE;
1318 boolean show_titlescreen = FALSE;
1320 /* needed to be able to skip title screen, if no image or message defined */
1321 InitializeTitleControls(show_title_initial);
1323 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1324 show_titlescreen = TRUE;
1326 /* show initial title images and messages only once at program start */
1327 show_title_initial = FALSE;
1329 return (show_titlescreen && num_title_screens > 0);
1332 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1334 static LevelDirTree *leveldir_last_valid = NULL;
1335 boolean levelset_has_changed = FALSE;
1337 LimitScreenUpdates(FALSE);
1339 FadeSetLeaveScreen();
1341 /* do not fade out here -- function may continue and fade on editor screen */
1344 FadeSoundsAndMusic();
1346 KeyboardAutoRepeatOn();
1349 SetDrawDeactivationMask(REDRAW_NONE);
1350 SetDrawBackgroundMask(REDRAW_FIELD);
1352 audio.sound_deactivated = FALSE;
1356 /* needed if last screen was the playing screen, invoked from level editor */
1357 if (level_editor_test_game)
1359 game_status = GAME_MODE_EDITOR;
1365 /* needed if last screen was the setup screen and fullscreen state changed */
1366 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1367 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1369 /* leveldir_current may be invalid (level group, parent link) */
1370 if (!validLevelSeries(leveldir_current))
1371 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1373 if (leveldir_current != leveldir_last_valid)
1374 levelset_has_changed = TRUE;
1376 /* store valid level series information */
1377 leveldir_last_valid = leveldir_current;
1379 init_last = init; /* switch to new busy animation */
1381 /* needed if last screen (level choice) changed graphics, sounds or music */
1382 ReloadCustomArtwork(0);
1384 if (redraw_mask & REDRAW_ALL)
1385 fade_mask = REDRAW_ALL;
1391 /* needed if last screen was the editor screen */
1392 UndrawSpecialEditorDoor();
1396 if (fade_mask == REDRAW_FIELD)
1402 /* needed if different viewport properties defined for menues */
1403 ChangeViewportPropertiesIfNeeded();
1407 /* needed if last screen was the editor screen */
1408 UndrawSpecialEditorDoor();
1411 #if defined(TARGET_SDL)
1412 SetDrawtoField(DRAW_BACKBUFFER);
1415 if (CheckTitleScreen(levelset_has_changed))
1417 game_status = GAME_MODE_TITLE;
1424 /* level_nr may have been set to value over handicap with level editor */
1425 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1426 level_nr = leveldir_current->handicap_level;
1428 LoadLevel(level_nr);
1429 LoadScore(level_nr);
1431 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1434 if (fade_mask == REDRAW_ALL)
1436 // int door_state = GetDoorState();
1440 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1446 InitializeMainControls();
1448 DrawCursorAndText_Main(-1, FALSE);
1449 DrawPreviewLevelInitial();
1451 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1454 if (TAPE_IS_EMPTY(tape))
1456 DrawCompleteVideoDisplay();
1461 /* create gadgets for main menu screen */
1462 FreeScreenGadgets();
1463 CreateScreenGadgets();
1465 /* map gadgets for main menu screen */
1467 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1470 if (fade_mask == REDRAW_ALL)
1472 int door_state = GetDoorState();
1474 // RedrawBackground();
1476 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1480 DrawMaskedBorder(REDRAW_ALL);
1486 /* update screen area with special editor door */
1487 redraw_mask |= REDRAW_ALL;
1491 SetMouseCursor(CURSOR_DEFAULT);
1495 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1498 void DrawAndFadeInMainMenu(int fade_mask)
1500 DrawMainMenuExt(fade_mask, TRUE);
1505 DrawMainMenuExt(REDRAW_ALL, FALSE);
1508 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1509 static void gotoTopLevelDir()
1511 /* move upwards to top level directory */
1512 while (leveldir_current->node_parent)
1514 /* write a "path" into level tree for easy navigation to last level */
1515 if (leveldir_current->node_parent->node_group->cl_first == -1)
1517 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1518 int leveldir_pos = posTreeInfo(leveldir_current);
1519 int num_page_entries;
1520 int cl_first, cl_cursor;
1522 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1523 num_page_entries = num_leveldirs;
1525 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1527 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1528 cl_cursor = leveldir_pos - cl_first;
1530 leveldir_current->node_parent->node_group->cl_first = cl_first;
1531 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1534 leveldir_current = leveldir_current->node_parent;
1539 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1541 static unsigned int title_delay = 0;
1542 static int title_screen_nr = 0;
1543 static int last_sound = -1, last_music = -1;
1544 boolean return_to_main_menu = FALSE;
1545 boolean use_fading_main_menu = TRUE;
1546 struct TitleControlInfo *tci;
1547 struct TitleFadingInfo fading_default;
1548 struct TitleFadingInfo fading_last = fading;
1549 struct TitleFadingInfo fading_next;
1552 if (button == MB_MENU_INITIALIZE)
1555 title_screen_nr = 0;
1556 tci = &title_controls[title_screen_nr];
1558 last_sound = SND_UNDEFINED;
1559 last_music = MUS_UNDEFINED;
1561 if (game_status == GAME_MODE_INFO)
1563 if (num_title_screens == 0)
1565 DrawInfoScreen_NotAvailable("Title screen information:",
1566 "No title screen for this level set.");
1571 FadeSoundsAndMusic();
1574 FadeOut(REDRAW_ALL);
1579 DrawTitleScreenImage(tci->local_nr, tci->initial);
1581 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1583 fading_default = (tci->initial ? title_initial_default : title_default);
1585 fading = fading_next = getTitleFading(tci);
1589 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1590 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1592 fading.fade_mode = FADE_MODE_FADE;
1593 fading.fade_delay = fading_default.fade_delay;
1596 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1597 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1598 fading.fade_mode = FADE_MODE_FADE;
1603 sound = getTitleSound(tci);
1604 music = getTitleMusic(tci);
1606 if (sound != last_sound)
1607 PlayMenuSoundExt(sound);
1608 if (music != last_music)
1609 PlayMenuMusicExt(music);
1615 SetMouseCursor(CURSOR_NONE);
1621 fading = fading_next;
1623 DelayReached(&title_delay, 0); /* reset delay counter */
1629 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1630 button = MB_MENU_CHOICE;
1632 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1633 button = MB_MENU_CHOICE;
1636 if (button == MB_MENU_LEAVE)
1638 return_to_main_menu = TRUE;
1639 use_fading_main_menu = FALSE;
1641 else if (button == MB_MENU_CHOICE)
1643 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1646 FadeOut(REDRAW_FIELD);
1649 FadeSetEnterScreen();
1651 info_mode = INFO_MODE_MAIN;
1652 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1658 tci = &title_controls[title_screen_nr];
1660 if (title_screen_nr < num_title_screens)
1662 sound = getTitleSound(tci);
1663 music = getTitleMusic(tci);
1665 if (sound == SND_UNDEFINED || sound != last_sound)
1667 if (music == MUS_UNDEFINED || music != last_music)
1671 FadeOut(REDRAW_ALL);
1675 DrawTitleScreenImage(tci->local_nr, tci->initial);
1677 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1679 fading_next = getTitleFading(tci);
1682 sound = getTitleSound(tci);
1683 music = getTitleMusic(tci);
1685 if (sound != last_sound)
1686 PlayMenuSoundExt(sound);
1687 if (music != last_music)
1688 PlayMenuMusicExt(music);
1695 /* last screen already faded out, next screen has no animation */
1696 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1697 fading_next.fade_mode == FADE_MODE_NONE)
1698 fading = fading_next;
1700 /* last screen already faded out, next screen has no animation */
1701 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1702 fading_next.fade_mode == FADE_MODE_NONE)
1703 fading = fading_next;
1710 fading = fading_next;
1712 DelayReached(&title_delay, 0); /* reset delay counter */
1716 FadeSoundsAndMusic();
1718 return_to_main_menu = TRUE;
1722 if (return_to_main_menu)
1728 SetMouseCursor(CURSOR_DEFAULT);
1730 if (game_status == GAME_MODE_INFO)
1733 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1736 info_mode = INFO_MODE_MAIN;
1737 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1739 else /* default: return to main menu */
1742 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1745 game_status = GAME_MODE_MAIN;
1746 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1751 void HandleMainMenu_SelectLevel(int step, int direction)
1753 int old_level_nr = level_nr;
1756 new_level_nr = old_level_nr + step * direction;
1757 if (new_level_nr < leveldir_current->first_level)
1758 new_level_nr = leveldir_current->first_level;
1759 if (new_level_nr > leveldir_current->last_level)
1760 new_level_nr = leveldir_current->last_level;
1762 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1764 /* skipping levels is only allowed when trying to skip single level */
1765 if (setup.skip_levels && step == 1 &&
1766 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1768 leveldir_current->handicap_level++;
1769 SaveLevelSetup_SeriesInfo();
1772 new_level_nr = leveldir_current->handicap_level;
1775 if (new_level_nr != old_level_nr)
1777 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1779 PlaySound(SND_MENU_ITEM_SELECTING);
1781 level_nr = new_level_nr;
1783 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1784 int2str(level_nr, menu.main.text.level_number.size),
1785 mci->pos_text->font);
1787 LoadLevel(level_nr);
1788 DrawPreviewLevelInitial();
1792 DrawCompleteVideoDisplay();
1794 /* needed because DrawPreviewLevelInitial() takes some time */
1800 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1802 static int choice = MAIN_CONTROL_GAME;
1806 if (button == MB_MENU_INITIALIZE)
1808 DrawCursorAndText_Main(choice, TRUE);
1813 if (mx || my) /* mouse input */
1817 for (i = 0; main_controls[i].nr != -1; i++)
1820 printf("::: check click (%d, %d) for %d [%d] ...\n",
1821 mx - mSX, my - mSY, i, main_controls[i].nr);
1824 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1825 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1826 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1829 printf("::: inside %d\n", i);
1832 pos = main_controls[i].nr;
1838 else if (dx || dy) /* keyboard input */
1840 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1841 choice == MAIN_CONTROL_SETUP))
1842 button = MB_MENU_CHOICE;
1847 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1849 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1851 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1853 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1855 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1857 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1859 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1861 game_status = GAME_MODE_LEVELNR;
1863 DrawChooseLevelNr();
1865 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1871 PlaySound(SND_MENU_ITEM_ACTIVATING);
1873 DrawCursorAndText_Main(choice, FALSE);
1874 DrawCursorAndText_Main(pos, TRUE);
1881 PlaySound(SND_MENU_ITEM_SELECTING);
1883 if (pos == MAIN_CONTROL_NAME)
1885 game_status = GAME_MODE_PSEUDO_TYPENAME;
1887 HandleTypeName(strlen(setup.player_name), 0);
1889 else if (pos == MAIN_CONTROL_LEVELS)
1893 game_status = GAME_MODE_LEVELS;
1895 SaveLevelSetup_LastSeries();
1896 SaveLevelSetup_SeriesInfo();
1898 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1902 DrawChooseLevelSet();
1905 else if (pos == MAIN_CONTROL_SCORES)
1907 game_status = GAME_MODE_SCORES;
1911 else if (pos == MAIN_CONTROL_EDITOR)
1913 if (leveldir_current->readonly &&
1914 !strEqual(setup.player_name, "Artsoft"))
1915 Request("This level is read only!", REQ_CONFIRM);
1917 game_status = GAME_MODE_EDITOR;
1919 FadeSetEnterScreen();
1922 /* needed if different viewport properties defined for editor */
1923 ChangeViewportPropertiesIfNeeded();
1928 else if (pos == MAIN_CONTROL_INFO)
1930 game_status = GAME_MODE_INFO;
1931 info_mode = INFO_MODE_MAIN;
1935 else if (pos == MAIN_CONTROL_GAME)
1937 StartGameActions(options.network, setup.autorecord, level.random_seed);
1939 else if (pos == MAIN_CONTROL_SETUP)
1941 game_status = GAME_MODE_SETUP;
1942 setup_mode = SETUP_MODE_MAIN;
1946 else if (pos == MAIN_CONTROL_QUIT)
1948 SaveLevelSetup_LastSeries();
1949 SaveLevelSetup_SeriesInfo();
1951 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1952 game_status = GAME_MODE_QUIT;
1958 if (game_status == GAME_MODE_MAIN)
1960 DrawPreviewLevelAnimation();
1967 /* ========================================================================= */
1968 /* info screen functions */
1969 /* ========================================================================= */
1971 static struct TokenInfo *info_info;
1972 static int num_info_info;
1974 static void execInfoTitleScreen()
1976 info_mode = INFO_MODE_TITLE;
1981 static void execInfoElements()
1983 info_mode = INFO_MODE_ELEMENTS;
1988 static void execInfoMusic()
1990 info_mode = INFO_MODE_MUSIC;
1995 static void execInfoCredits()
1997 info_mode = INFO_MODE_CREDITS;
2002 static void execInfoProgram()
2004 info_mode = INFO_MODE_PROGRAM;
2009 static void execInfoVersion()
2011 info_mode = INFO_MODE_VERSION;
2016 static void execInfoLevelSet()
2018 info_mode = INFO_MODE_LEVELSET;
2023 static void execExitInfo()
2025 game_status = GAME_MODE_MAIN;
2027 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2030 static struct TokenInfo info_info_main[] =
2032 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2033 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2034 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2035 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2036 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2037 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2038 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2039 { TYPE_EMPTY, NULL, "" },
2040 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2045 static void DrawCursorAndText_Info(int pos, boolean active)
2047 int xpos = MENU_SCREEN_START_XPOS;
2048 int ypos = MENU_SCREEN_START_YPOS + pos;
2049 int font_nr = FONT_MENU_1;
2052 font_nr = FONT_ACTIVE(font_nr);
2054 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2056 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2057 drawCursor(pos, active);
2060 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2065 CloseDoor(DOOR_CLOSE_2);
2067 /* (needed after displaying title screens which disable auto repeat) */
2068 KeyboardAutoRepeatOn();
2070 FadeSetLeaveScreen();
2077 if (fade_mask == REDRAW_ALL)
2081 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2087 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2089 info_info = info_info_main;
2093 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2095 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2098 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2099 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2100 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2101 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2102 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2103 initCursor(i, IMG_MENU_BUTTON);
2105 DrawCursorAndText_Info(i, FALSE);
2110 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2115 DrawMaskedBorder(fade_mask);
2122 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2124 static int choice_store[MAX_INFO_MODES];
2125 int choice = choice_store[info_mode]; /* always starts with 0 */
2129 if (button == MB_MENU_INITIALIZE)
2131 /* advance to first valid menu entry */
2132 while (choice < num_info_info &&
2133 info_info[choice].type & TYPE_SKIP_ENTRY)
2135 choice_store[info_mode] = choice;
2137 DrawCursorAndText_Info(choice, TRUE);
2141 else if (button == MB_MENU_LEAVE)
2143 for (y = 0; y < num_info_info; y++)
2145 if (info_info[y].type & TYPE_LEAVE_MENU)
2147 void (*menu_callback_function)(void) = info_info[y].value;
2151 menu_callback_function();
2153 break; /* absolutely needed because function changes 'info_info'! */
2160 if (mx || my) /* mouse input */
2162 x = (mx - mSX) / 32;
2163 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2165 else if (dx || dy) /* keyboard input */
2169 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2171 if (info_info[choice].type & menu_navigation_type ||
2172 info_info[choice].type & TYPE_ENTER_SCREEN ||
2173 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2174 info_info[choice].type & TYPE_YES_NO_AUTO)
2175 button = MB_MENU_CHOICE;
2180 /* jump to next non-empty menu entry (up or down) */
2181 while (y > 0 && y < num_info_info - 1 &&
2182 info_info[y].type & TYPE_SKIP_ENTRY)
2186 if (IN_VIS_FIELD(x, y) &&
2187 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2193 PlaySound(SND_MENU_ITEM_ACTIVATING);
2195 DrawCursorAndText_Info(choice, FALSE);
2196 DrawCursorAndText_Info(y, TRUE);
2198 choice = choice_store[info_mode] = y;
2201 else if (!(info_info[y].type & TYPE_GHOSTED))
2203 PlaySound(SND_MENU_ITEM_SELECTING);
2205 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2207 void (*menu_callback_function)(void) = info_info[choice].value;
2209 FadeSetFromType(info_info[y].type);
2211 menu_callback_function();
2217 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2219 int ystart1 = mSY - SY + 100;
2220 int ystart2 = mSY - SY + 150;
2221 int ybottom = mSY - SY + SYSIZE - 20;
2223 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2225 FadeOut(REDRAW_FIELD);
2230 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2231 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2233 DrawTextSCentered(ybottom, FONT_TEXT_4,
2234 "Press any key or button for info menu");
2236 FadeIn(REDRAW_FIELD);
2239 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2241 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2242 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2243 int xstart = mSX + 16;
2244 int ystart1 = mSY - SY + 100;
2245 int ystart2 = mSY + 64 + 2 * 32;
2246 int ybottom = mSY - SY + SYSIZE - 20;
2247 int ystep = TILEY + 4;
2248 int element, action, direction;
2256 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2257 infoscreen_step[i] = infoscreen_frame[i] = 0;
2262 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2264 DrawTextSCentered(ybottom, FONT_TEXT_4,
2265 "Press any key or button for next page");
2271 while (helpanim_info[j].element != HELPANIM_LIST_END)
2273 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2278 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2287 j += infoscreen_step[i - start];
2289 element = helpanim_info[j].element;
2290 action = helpanim_info[j].action;
2291 direction = helpanim_info[j].direction;
2294 element = EL_UNKNOWN;
2296 if (action != -1 && direction != -1)
2297 graphic = el_act_dir2img(element, action, direction);
2298 else if (action != -1)
2299 graphic = el_act2img(element, action);
2300 else if (direction != -1)
2301 graphic = el_dir2img(element, direction);
2303 graphic = el2img(element);
2305 delay = helpanim_info[j++].delay;
2310 if (infoscreen_frame[i - start] == 0)
2313 infoscreen_frame[i - start] = delay - 1;
2317 sync_frame = delay - infoscreen_frame[i - start];
2318 infoscreen_frame[i - start]--;
2321 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2323 if (!infoscreen_frame[i - start])
2324 infoscreen_step[i - start] = 0;
2328 if (!infoscreen_frame[i - start])
2329 infoscreen_step[i - start]++;
2330 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2336 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2338 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2339 graphic, sync_frame, USE_MASKING);
2342 DrawInfoScreen_HelpText(element, action, direction, i - start);
2347 redraw_mask |= REDRAW_FIELD;
2352 static char *getHelpText(int element, int action, int direction)
2354 char token[MAX_LINE_LEN];
2356 strcpy(token, element_info[element].token_name);
2359 strcat(token, element_action_info[action].suffix);
2361 if (direction != -1)
2362 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2364 return getHashEntry(helptext_info, token);
2367 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2369 int font_nr = FONT_INFO_ELEMENTS;
2370 int font_width = getFontWidth(font_nr);
2371 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2372 int sy = mSY + 65 + 2 * 32 + 1;
2373 int ystep = TILEY + 4;
2374 int pad_x = sx - SX;
2375 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2376 int max_lines_per_text = 2;
2379 if (action != -1 && direction != -1) /* element.action.direction */
2380 text = getHelpText(element, action, direction);
2382 if (text == NULL && action != -1) /* element.action */
2383 text = getHelpText(element, action, -1);
2385 if (text == NULL && direction != -1) /* element.direction */
2386 text = getHelpText(element, -1, direction);
2388 if (text == NULL) /* base element */
2389 text = getHelpText(element, -1, -1);
2391 if (text == NULL) /* not found */
2392 text = "No description available";
2394 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2395 sy += getFontHeight(font_nr) / 2;
2397 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2398 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2399 TRUE, FALSE, FALSE);
2402 void DrawInfoScreen_TitleScreen()
2407 void HandleInfoScreen_TitleScreen(int button)
2409 HandleTitleScreen(0, 0, 0, 0, button);
2412 void DrawInfoScreen_Elements()
2414 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2416 FadeOut(REDRAW_FIELD);
2421 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2423 FadeIn(REDRAW_FIELD);
2428 void HandleInfoScreen_Elements(int button)
2430 static unsigned int info_delay = 0;
2431 static int num_anims;
2432 static int num_pages;
2434 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2437 if (button == MB_MENU_INITIALIZE)
2439 boolean new_element = TRUE;
2443 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2445 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2447 else if (new_element)
2450 new_element = FALSE;
2454 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2458 if (button == MB_MENU_LEAVE)
2460 PlaySound(SND_MENU_ITEM_SELECTING);
2462 info_mode = INFO_MODE_MAIN;
2467 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2469 if (button != MB_MENU_INITIALIZE)
2471 PlaySound(SND_MENU_ITEM_SELECTING);
2476 if (page >= num_pages)
2478 FadeSoundsAndMusic();
2480 info_mode = INFO_MODE_MAIN;
2481 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2488 FadeSetNextScreen();
2491 if (button != MB_MENU_INITIALIZE)
2492 FadeOut(REDRAW_FIELD);
2494 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2496 if (button != MB_MENU_INITIALIZE)
2497 FadeIn(REDRAW_FIELD);
2501 if (DelayReached(&info_delay, GameFrameDelay))
2502 if (page < num_pages)
2503 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2505 PlayMenuSoundIfLoop();
2509 void DrawInfoScreen_Music()
2511 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2514 FadeOut(REDRAW_FIELD);
2522 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2525 FadeIn(REDRAW_FIELD);
2529 void HandleInfoScreen_Music(int button)
2531 static struct MusicFileInfo *list = NULL;
2532 int ystart1 = mSY - SY + 100;
2533 int ystart2 = mSY - SY + 150;
2534 int ybottom = mSY - SY + SYSIZE - 20;
2537 if (button == MB_MENU_INITIALIZE)
2539 list = music_file_info;
2543 FadeSoundsAndMusic();
2548 DrawTextSCentered(ystart1, FONT_TEXT_1,
2549 "No music info for this level set.");
2551 DrawTextSCentered(ybottom, FONT_TEXT_4,
2552 "Press any key or button for info menu");
2558 if (button == MB_MENU_LEAVE)
2560 PlaySound(SND_MENU_ITEM_SELECTING);
2562 FadeSoundsAndMusic();
2564 info_mode = INFO_MODE_MAIN;
2569 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2573 if (button != MB_MENU_INITIALIZE)
2575 PlaySound(SND_MENU_ITEM_SELECTING);
2583 FadeSoundsAndMusic();
2585 info_mode = INFO_MODE_MAIN;
2586 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2591 FadeSoundsAndMusic();
2594 if (list != music_file_info)
2595 FadeSetNextScreen();
2598 if (button != MB_MENU_INITIALIZE)
2599 FadeOut(REDRAW_FIELD);
2606 int sound = list->music;
2608 if (sound_info[sound].loop)
2609 PlaySoundLoop(sound);
2613 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2617 PlayMusic(list->music);
2619 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2622 if (!strEqual(list->title, UNKNOWN_NAME))
2624 if (!strEqual(list->title_header, UNKNOWN_NAME))
2625 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2627 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2630 if (!strEqual(list->artist, UNKNOWN_NAME))
2632 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2633 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2635 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2637 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2640 if (!strEqual(list->album, UNKNOWN_NAME))
2642 if (!strEqual(list->album_header, UNKNOWN_NAME))
2643 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2645 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2647 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2650 if (!strEqual(list->year, UNKNOWN_NAME))
2652 if (!strEqual(list->year_header, UNKNOWN_NAME))
2653 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2655 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2657 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2660 DrawTextSCentered(ybottom, FONT_TEXT_4,
2661 "Press any key or button for next page");
2663 if (button != MB_MENU_INITIALIZE)
2664 FadeIn(REDRAW_FIELD);
2667 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2668 PlaySoundLoop(list->music);
2671 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2673 int ystart1 = mSY - SY + 100;
2674 int ystart2 = mSY - SY + 150;
2675 int ybottom = mSY - SY + SYSIZE - 20;
2681 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2685 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2686 "Special thanks to");
2687 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2689 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2691 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2692 "\"Boulder Dash\"");
2693 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2695 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2697 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2699 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2700 "First Star Software");
2702 else if (screen_nr == 1)
2704 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2705 "Special thanks to");
2706 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2707 "Klaus Heinz & Volker Wertich");
2708 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2710 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2711 "\"Emerald Mine\"");
2712 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2714 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2716 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2718 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2721 else if (screen_nr == 2)
2723 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2724 "Special thanks to");
2725 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2726 "Michael Stopp & Philip Jespersen");
2727 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2729 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2731 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2733 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2735 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2737 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2738 "Digital Integration");
2740 else if (screen_nr == 3)
2742 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2743 "Special thanks to");
2744 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2745 "Hiroyuki Imabayashi");
2746 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2748 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2750 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2752 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2754 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2756 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2759 else if (screen_nr == 4)
2761 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2762 "Special thanks to");
2763 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2765 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2767 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2768 "Jürgen Bonhagen");
2769 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2770 "for the continuous creation");
2771 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2772 "of outstanding level sets");
2774 else if (screen_nr == 5)
2776 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2778 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2780 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2781 "for ideas and inspiration by");
2782 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2785 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2787 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2789 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2790 "for ideas and inspiration by");
2791 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2794 else if (screen_nr == 6)
2796 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2798 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2801 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2802 "for the code base used for the");
2803 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2804 "native Emerald Mine engine");
2806 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2807 "for the new Emerald Mine engine");
2810 else if (screen_nr == 7)
2812 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2814 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2816 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2817 "for the initial DOS port");
2819 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2821 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2823 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2824 "for some additional toons");
2826 else if (screen_nr == 8)
2828 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2829 "And not to forget:");
2830 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2832 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2833 "All those who contributed");
2834 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2835 "levels to this game");
2836 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2840 DrawTextSCentered(ybottom, FONT_TEXT_4,
2841 "Press any key or button for next page");
2844 void DrawInfoScreen_Credits()
2846 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2848 FadeSoundsAndMusic();
2851 FadeOut(REDRAW_FIELD);
2854 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2857 FadeIn(REDRAW_FIELD);
2861 void HandleInfoScreen_Credits(int button)
2863 static int screen_nr = 0;
2864 int num_screens = 9;
2866 if (button == MB_MENU_INITIALIZE)
2870 // DrawInfoScreen_CreditsScreen(screen_nr);
2873 if (button == MB_MENU_LEAVE)
2875 PlaySound(SND_MENU_ITEM_SELECTING);
2877 info_mode = INFO_MODE_MAIN;
2882 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2884 if (button != MB_MENU_INITIALIZE)
2886 PlaySound(SND_MENU_ITEM_SELECTING);
2891 if (screen_nr >= num_screens)
2893 FadeSoundsAndMusic();
2895 info_mode = INFO_MODE_MAIN;
2896 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2903 FadeSetNextScreen();
2906 if (button != MB_MENU_INITIALIZE)
2907 FadeOut(REDRAW_FIELD);
2909 DrawInfoScreen_CreditsScreen(screen_nr);
2911 if (button != MB_MENU_INITIALIZE)
2912 FadeIn(REDRAW_FIELD);
2916 PlayMenuSoundIfLoop();
2920 void DrawInfoScreen_Program()
2922 int ystart1 = mSY - SY + 100;
2923 int ystart2 = mSY - SY + 150;
2924 int ybottom = mSY - SY + SYSIZE - 20;
2927 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2930 FadeOut(REDRAW_FIELD);
2936 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2938 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2939 "This game is Freeware!");
2940 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2941 "If you like it, send e-mail to:");
2942 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2943 PROGRAM_EMAIL_STRING);
2945 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2946 "More information and levels:");
2947 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2948 PROGRAM_WEBSITE_STRING);
2949 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2950 "If you have created new levels,");
2951 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2952 "send them to me to include them!");
2953 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2956 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2957 "or SnailMail to:");
2958 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2960 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2961 "Detmolder Strasse 189");
2962 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2964 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2966 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2967 "More information and levels:");
2968 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2969 PROGRAM_WEBSITE_STRING);
2970 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2971 "If you have created new levels,");
2972 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2973 "send them to me to include them!");
2974 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2978 DrawTextSCentered(ybottom, FONT_TEXT_4,
2979 "Press any key or button for info menu");
2982 FadeIn(REDRAW_FIELD);
2986 void HandleInfoScreen_Program(int button)
2988 if (button == MB_MENU_LEAVE)
2990 PlaySound(SND_MENU_ITEM_SELECTING);
2992 info_mode = INFO_MODE_MAIN;
2997 else if (button == MB_MENU_CHOICE)
2999 PlaySound(SND_MENU_ITEM_SELECTING);
3001 FadeSoundsAndMusic();
3004 FadeOut(REDRAW_FIELD);
3007 info_mode = INFO_MODE_MAIN;
3008 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3012 PlayMenuSoundIfLoop();
3016 void DrawInfoScreen_Version()
3018 int font_header = FONT_TEXT_3;
3019 int font_text = FONT_TEXT_2;
3020 int xstep = getFontWidth(font_text);
3021 int ystep = getFontHeight(font_text);
3022 int ystart1 = mSY - SY + 100;
3023 int ystart2 = mSY - SY + 150;
3024 int ybottom = mSY - SY + SYSIZE - 20;
3025 int xstart1 = mSX - SX + 2 * xstep;
3026 int xstart2 = mSX - SX + 18 * xstep;
3027 #if defined(TARGET_SDL)
3028 int xstart3 = mSX - SX + 28 * xstep;
3029 SDL_version sdl_version_compiled;
3030 const SDL_version *sdl_version_linked;
3031 int driver_name_len = 10;
3032 #if defined(TARGET_SDL2)
3033 SDL_version sdl_version_linked_ext;
3034 const char *driver_name = NULL;
3036 char driver_name[driver_name_len];
3040 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3043 FadeOut(REDRAW_FIELD);
3049 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3051 DrawTextF(xstart1, ystart2, font_header, "Name");
3052 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3055 DrawTextF(xstart1, ystart2, font_header, "Version");
3056 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3059 DrawTextF(xstart1, ystart2, font_header, "Platform");
3060 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3063 DrawTextF(xstart1, ystart2, font_header, "Target");
3064 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3067 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3068 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3070 #if defined(TARGET_SDL)
3071 ystart2 += 3 * ystep;
3072 DrawTextF(xstart1, ystart2, font_header, "Library");
3073 DrawTextF(xstart2, ystart2, font_header, "compiled");
3074 DrawTextF(xstart3, ystart2, font_header, "linked");
3076 SDL_VERSION(&sdl_version_compiled);
3077 #if defined(TARGET_SDL2)
3078 SDL_GetVersion(&sdl_version_linked_ext);
3079 sdl_version_linked = &sdl_version_linked_ext;
3081 sdl_version_linked = SDL_Linked_Version();
3084 ystart2 += 2 * ystep;
3085 DrawTextF(xstart1, ystart2, font_text, "SDL");
3086 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3087 sdl_version_compiled.major,
3088 sdl_version_compiled.minor,
3089 sdl_version_compiled.patch);
3090 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3091 sdl_version_linked->major,
3092 sdl_version_linked->minor,
3093 sdl_version_linked->patch);
3095 SDL_IMAGE_VERSION(&sdl_version_compiled);
3096 sdl_version_linked = IMG_Linked_Version();
3099 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3100 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3101 sdl_version_compiled.major,
3102 sdl_version_compiled.minor,
3103 sdl_version_compiled.patch);
3104 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3105 sdl_version_linked->major,
3106 sdl_version_linked->minor,
3107 sdl_version_linked->patch);
3109 SDL_MIXER_VERSION(&sdl_version_compiled);
3110 sdl_version_linked = Mix_Linked_Version();
3113 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3114 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3115 sdl_version_compiled.major,
3116 sdl_version_compiled.minor,
3117 sdl_version_compiled.patch);
3118 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3119 sdl_version_linked->major,
3120 sdl_version_linked->minor,
3121 sdl_version_linked->patch);
3123 SDL_NET_VERSION(&sdl_version_compiled);
3124 sdl_version_linked = SDLNet_Linked_Version();
3127 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3128 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3129 sdl_version_compiled.major,
3130 sdl_version_compiled.minor,
3131 sdl_version_compiled.patch);
3132 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3133 sdl_version_linked->major,
3134 sdl_version_linked->minor,
3135 sdl_version_linked->patch);
3137 ystart2 += 3 * ystep;
3138 DrawTextF(xstart1, ystart2, font_header, "Driver");
3139 DrawTextF(xstart2, ystart2, font_header, "Requested");
3140 DrawTextF(xstart3, ystart2, font_header, "Used");
3142 #if defined(TARGET_SDL2)
3143 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3145 SDL_VideoDriverName(driver_name, driver_name_len);
3148 ystart2 += 2 * ystep;
3149 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3150 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3151 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3153 #if defined(TARGET_SDL2)
3154 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3156 SDL_AudioDriverName(driver_name, driver_name_len);
3160 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3161 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3162 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3165 DrawTextSCentered(ybottom, FONT_TEXT_4,
3166 "Press any key or button for info menu");
3169 FadeIn(REDRAW_FIELD);
3173 void HandleInfoScreen_Version(int button)
3175 if (button == MB_MENU_LEAVE)
3177 PlaySound(SND_MENU_ITEM_SELECTING);
3179 info_mode = INFO_MODE_MAIN;
3184 else if (button == MB_MENU_CHOICE)
3186 PlaySound(SND_MENU_ITEM_SELECTING);
3188 FadeSoundsAndMusic();
3191 FadeOut(REDRAW_FIELD);
3194 info_mode = INFO_MODE_MAIN;
3195 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3199 PlayMenuSoundIfLoop();
3203 void DrawInfoScreen_LevelSet()
3205 struct TitleMessageInfo *tmi = &readme;
3206 char *filename = getLevelSetInfoFilename();
3208 /* if chars set to "-1", automatically determine by text and font width */
3209 if (tmi->chars == -1)
3210 tmi->chars = tmi->width / getFontWidth(tmi->font);
3212 tmi->width = tmi->chars * getFontWidth(tmi->font);
3214 /* if lines set to "-1", automatically determine by text and font height */
3215 if (tmi->lines == -1)
3216 tmi->lines = tmi->height / getFontHeight(tmi->font);
3218 tmi->height = tmi->lines * getFontHeight(tmi->font);
3220 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3223 FadeOut(REDRAW_FIELD);
3229 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3231 if (filename != NULL)
3232 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3233 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3234 tmi->autowrap, tmi->centered, tmi->parse_comments);
3236 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3237 "No information for this level set.");
3239 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3240 "Press any key or button for info menu");
3243 FadeIn(REDRAW_FIELD);
3247 void HandleInfoScreen_LevelSet(int button)
3249 if (button == MB_MENU_LEAVE)
3251 PlaySound(SND_MENU_ITEM_SELECTING);
3253 info_mode = INFO_MODE_MAIN;
3258 else if (button == MB_MENU_CHOICE)
3260 PlaySound(SND_MENU_ITEM_SELECTING);
3262 FadeSoundsAndMusic();
3265 FadeOut(REDRAW_FIELD);
3268 info_mode = INFO_MODE_MAIN;
3269 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3273 PlayMenuSoundIfLoop();
3277 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3279 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3281 if (info_mode == INFO_MODE_TITLE)
3282 DrawInfoScreen_TitleScreen();
3283 else if (info_mode == INFO_MODE_ELEMENTS)
3284 DrawInfoScreen_Elements();
3285 else if (info_mode == INFO_MODE_MUSIC)
3286 DrawInfoScreen_Music();
3287 else if (info_mode == INFO_MODE_CREDITS)
3288 DrawInfoScreen_Credits();
3289 else if (info_mode == INFO_MODE_PROGRAM)
3290 DrawInfoScreen_Program();
3291 else if (info_mode == INFO_MODE_VERSION)
3292 DrawInfoScreen_Version();
3293 else if (info_mode == INFO_MODE_LEVELSET)
3294 DrawInfoScreen_LevelSet();
3296 DrawInfoScreen_Main(fade_mask, do_fading);
3298 if (info_mode != INFO_MODE_MAIN &&
3299 info_mode != INFO_MODE_TITLE &&
3300 info_mode != INFO_MODE_MUSIC)
3307 void DrawAndFadeInInfoScreen(int fade_mask)
3309 DrawInfoScreenExt(fade_mask, TRUE);
3312 void DrawInfoScreen()
3314 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3317 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3319 if (info_mode == INFO_MODE_TITLE)
3320 HandleInfoScreen_TitleScreen(button);
3321 else if (info_mode == INFO_MODE_ELEMENTS)
3322 HandleInfoScreen_Elements(button);
3323 else if (info_mode == INFO_MODE_MUSIC)
3324 HandleInfoScreen_Music(button);
3325 else if (info_mode == INFO_MODE_CREDITS)
3326 HandleInfoScreen_Credits(button);
3327 else if (info_mode == INFO_MODE_PROGRAM)
3328 HandleInfoScreen_Program(button);
3329 else if (info_mode == INFO_MODE_VERSION)
3330 HandleInfoScreen_Version(button);
3331 else if (info_mode == INFO_MODE_LEVELSET)
3332 HandleInfoScreen_LevelSet(button);
3334 HandleInfoScreen_Main(mx, my, dx, dy, button);
3342 /* ========================================================================= */
3343 /* type name functions */
3344 /* ========================================================================= */
3346 void HandleTypeName(int newxpos, Key key)
3348 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3349 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3350 struct TextPosInfo *pos = mci->pos_input;
3351 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3352 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3353 static int xpos = 0;
3354 int font_nr = pos->font;
3355 int font_active_nr = FONT_ACTIVE(font_nr);
3356 int font_width = getFontWidth(font_active_nr);
3357 char key_char = getValidConfigValueChar(getCharFromKey(key));
3358 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3359 boolean is_active = TRUE;
3361 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3365 strcpy(last_player_name, setup.player_name);
3369 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3371 setup.player_name[xpos] = key_char;
3372 setup.player_name[xpos + 1] = 0;
3376 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3380 setup.player_name[xpos] = 0;
3382 else if (key == KSYM_Return && xpos > 0)
3388 game_status = GAME_MODE_MAIN;
3390 else if (key == KSYM_Escape)
3392 strcpy(setup.player_name, last_player_name);
3396 game_status = GAME_MODE_MAIN;
3401 pos->width = (strlen(setup.player_name) + 1) * font_width;
3402 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3404 DrawText(startx, starty, setup.player_name, font_active_nr);
3405 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3409 pos->width = strlen(setup.player_name) * font_width;
3410 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3412 DrawText(startx, starty, setup.player_name, font_nr);
3417 /* ========================================================================= */
3418 /* tree menu functions */
3419 /* ========================================================================= */
3421 static void DrawChooseTree(TreeInfo **ti_ptr)
3425 FreeScreenGadgets();
3426 CreateScreenGadgets();
3428 CloseDoor(DOOR_CLOSE_2);
3431 FadeOut(REDRAW_FIELD);
3436 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3437 MapScreenTreeGadgets(*ti_ptr);
3440 FadeIn(REDRAW_FIELD);
3446 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3448 struct GadgetInfo *gi = screen_gadget[id];
3449 int items_max, items_visible, item_position;
3451 items_max = numTreeInfoInGroup(ti);
3452 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3453 item_position = first_entry;
3455 if (item_position > items_max - items_visible)
3456 item_position = items_max - items_visible;
3458 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3459 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3460 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3463 static void drawChooseTreeList(int first_entry, int num_page_entries,
3467 char *title_string = NULL;
3468 int yoffset_sets = MENU_TITLE1_YPOS;
3469 int yoffset_setup = 16;
3470 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3471 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3472 int last_game_status = game_status; /* save current game status */
3474 title_string = ti->infotext;
3476 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3479 /* force LEVELS font on artwork setup screen */
3480 game_status = GAME_MODE_LEVELS;
3484 /* clear tree list area, but not title or scrollbar */
3485 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3486 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3487 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3489 /* clear tree list area, but not title or scrollbar */
3490 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3491 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3492 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3495 for (i = 0; i < num_page_entries; i++)
3497 TreeInfo *node, *node_first;
3498 int entry_pos = first_entry + i;
3499 int xpos = MENU_SCREEN_START_XPOS;
3500 int ypos = MENU_SCREEN_START_YPOS + i;
3501 int startx = mSX + xpos * 32;
3502 int starty = mSY + ypos * 32;
3503 int font_nr = FONT_TEXT_1;
3504 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3505 int startx_text = startx + font_xoffset;
3506 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3507 int text_size = startx_scrollbar - startx_text;
3508 int max_buffer_len = text_size / getFontWidth(font_nr);
3509 char buffer[max_buffer_len + 1];
3511 node_first = getTreeInfoFirstGroupEntry(ti);
3512 node = getTreeInfoFromPos(node_first, entry_pos);
3514 strncpy(buffer, node->name, max_buffer_len);
3515 buffer[max_buffer_len] = '\0';
3517 DrawText(startx, starty, buffer, font_nr + node->color);
3519 if (node->parent_link)
3520 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3521 else if (node->level_group)
3522 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3524 initCursor(i, IMG_MENU_BUTTON);
3527 game_status = last_game_status; /* restore current game status */
3529 redraw_mask |= REDRAW_FIELD;
3532 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3534 TreeInfo *node, *node_first;
3535 int x, last_redraw_mask = redraw_mask;
3536 int ypos = MENU_TITLE2_YPOS;
3537 int font_nr = FONT_TITLE_2;
3539 if (ti->type == TREE_TYPE_LEVEL_NR)
3540 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3542 if (ti->type != TREE_TYPE_LEVEL_DIR)
3545 node_first = getTreeInfoFirstGroupEntry(ti);
3546 node = getTreeInfoFromPos(node_first, entry_pos);
3548 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3551 if (node->parent_link)
3552 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3553 node->node_parent->name);
3554 else if (node->level_group)
3555 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3557 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3558 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3559 node->levels, (node->levels > 1 ? "levels" : "level"),
3562 if (node->parent_link)
3563 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3565 else if (node->level_group)
3566 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3568 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3569 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3570 node->levels, node->class_desc);
3573 /* let BackToFront() redraw only what is needed */
3574 redraw_mask = last_redraw_mask | REDRAW_TILES;
3575 for (x = 0; x < SCR_FIELDX; x++)
3576 MarkTileDirty(x, 1);
3579 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3582 TreeInfo *ti = *ti_ptr;
3584 int y = ti->cl_cursor;
3585 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3586 int num_entries = numTreeInfoInGroup(ti);
3587 int num_page_entries;
3588 int last_game_status = game_status; /* save current game status */
3589 boolean position_set_by_scrollbar = (dx == 999);
3592 /* force LEVELS draw offset on choose level and artwork setup screen */
3593 game_status = GAME_MODE_LEVELS;
3596 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3597 num_page_entries = num_entries;
3599 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3601 game_status = last_game_status; /* restore current game status */
3603 if (button == MB_MENU_INITIALIZE)
3605 int num_entries = numTreeInfoInGroup(ti);
3606 int entry_pos = posTreeInfo(ti);
3608 if (ti->cl_first == -1)
3610 /* only on initialization */
3611 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3612 ti->cl_cursor = entry_pos - ti->cl_first;
3614 else if (ti->cl_cursor >= num_page_entries ||
3615 (num_entries > num_page_entries &&
3616 num_entries - ti->cl_first < num_page_entries))
3618 /* only after change of list size (by custom graphic configuration) */
3619 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3620 ti->cl_cursor = entry_pos - ti->cl_first;
3623 if (position_set_by_scrollbar)
3626 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3629 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3630 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3631 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3635 else if (button == MB_MENU_LEAVE)
3639 PlaySound(SND_MENU_ITEM_SELECTING);
3641 if (ti->node_parent)
3643 *ti_ptr = ti->node_parent;
3644 DrawChooseTree(ti_ptr);
3646 else if (game_status == GAME_MODE_SETUP)
3648 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3649 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3651 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3652 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3653 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3654 execSetupGraphics();
3655 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3656 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3657 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3664 if (game_status == GAME_MODE_LEVELNR)
3665 level_nr = atoi(level_number_current->identifier);
3667 game_status = GAME_MODE_MAIN;
3669 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3675 if (mx || my) /* mouse input */
3677 int last_game_status = game_status; /* save current game status */
3680 /* force LEVELS draw offset on artwork setup screen */
3681 game_status = GAME_MODE_LEVELS;
3684 x = (mx - mSX) / 32;
3685 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3687 game_status = last_game_status; /* restore current game status */
3689 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3691 /* move cursor instead of scrolling when already at start/end of list */
3692 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3694 else if (dy == +1 * SCROLL_LINE &&
3695 ti->cl_first + num_page_entries == num_entries)
3698 /* handle scrolling screen one line or page */
3699 if (ti->cl_cursor + dy < 0 ||
3700 ti->cl_cursor + dy > num_page_entries - 1)
3702 if (ABS(dy) == SCROLL_PAGE)
3703 step = num_page_entries - 1;
3705 if (dy < 0 && ti->cl_first > 0)
3707 /* scroll page/line up */
3709 ti->cl_first -= step;
3710 if (ti->cl_first < 0)
3713 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3714 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3715 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3717 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3720 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3722 /* scroll page/line down */
3724 ti->cl_first += step;
3725 if (ti->cl_first + num_page_entries > num_entries)
3726 ti->cl_first = MAX(0, num_entries - num_page_entries);
3728 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3729 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3730 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3732 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3739 /* handle moving cursor one line */
3740 y = ti->cl_cursor + dy;
3745 TreeInfo *node_first, *node_cursor;
3746 int entry_pos = ti->cl_first + y;
3748 node_first = getTreeInfoFirstGroupEntry(ti);
3749 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3751 if (node_cursor->node_group)
3755 PlaySound(SND_MENU_ITEM_SELECTING);
3757 node_cursor->cl_first = ti->cl_first;
3758 node_cursor->cl_cursor = ti->cl_cursor;
3759 *ti_ptr = node_cursor->node_group;
3760 DrawChooseTree(ti_ptr);
3765 else if (dx == -1 && ti->node_parent)
3769 PlaySound(SND_MENU_ITEM_SELECTING);
3771 *ti_ptr = ti->node_parent;
3772 DrawChooseTree(ti_ptr);
3777 if (!anyScrollbarGadgetActive() &&
3778 IN_VIS_FIELD(x, y) &&
3779 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3780 y >= 0 && y < num_page_entries)
3784 if (y != ti->cl_cursor)
3786 PlaySound(SND_MENU_ITEM_ACTIVATING);
3788 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3789 drawChooseTreeCursor(y, TRUE);
3790 drawChooseTreeInfo(ti->cl_first + y, ti);
3797 TreeInfo *node_first, *node_cursor;
3798 int entry_pos = ti->cl_first + y;
3800 PlaySound(SND_MENU_ITEM_SELECTING);
3802 node_first = getTreeInfoFirstGroupEntry(ti);
3803 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3805 if (node_cursor->node_group)
3809 node_cursor->cl_first = ti->cl_first;
3810 node_cursor->cl_cursor = ti->cl_cursor;
3811 *ti_ptr = node_cursor->node_group;
3812 DrawChooseTree(ti_ptr);
3814 else if (node_cursor->parent_link)
3818 *ti_ptr = node_cursor->node_parent;
3819 DrawChooseTree(ti_ptr);
3826 FadeSetEnterScreen();
3829 node_cursor->cl_first = ti->cl_first;
3830 node_cursor->cl_cursor = ti->cl_cursor;
3831 *ti_ptr = node_cursor;
3833 if (ti->type == TREE_TYPE_LEVEL_DIR)
3835 LoadLevelSetup_SeriesInfo();
3837 SaveLevelSetup_LastSeries();
3838 SaveLevelSetup_SeriesInfo();
3842 if (game_status == GAME_MODE_SETUP)
3844 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3845 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3847 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3848 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3849 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3850 execSetupGraphics();
3851 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3852 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3853 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3860 if (game_status == GAME_MODE_LEVELNR)
3861 level_nr = atoi(level_number_current->identifier);
3863 game_status = GAME_MODE_MAIN;
3872 void DrawChooseLevelSet()
3874 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3876 DrawChooseTree(&leveldir_current);
3882 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3884 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3891 void DrawChooseLevelNr()
3895 if (level_number != NULL)
3897 freeTreeInfo(level_number);
3899 level_number = NULL;
3902 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3904 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3905 char identifier[32], name[32];
3908 /* temporarily load level info to get level name */
3909 LoadLevelInfoOnly(i);
3911 ti->node_top = &level_number;
3912 ti->sort_priority = 10000 + value;
3913 ti->color = (level.no_valid_file ? FC_BLUE :
3914 LevelStats_getSolved(i) ? FC_GREEN :
3915 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3917 sprintf(identifier, "%d", value);
3918 sprintf(name, "%03d: %s", value,
3919 (level.no_valid_file ? "(no file)" : level.name));
3921 setString(&ti->identifier, identifier);
3922 setString(&ti->name, name);
3923 setString(&ti->name_sorting, name);
3925 pushTreeInfo(&level_number, ti);
3928 /* sort level number values to start with lowest level number */
3929 sortTreeInfo(&level_number);
3931 /* set current level number to current level number */
3932 level_number_current =
3933 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3935 /* if that also fails, set current level number to first available level */
3936 if (level_number_current == NULL)
3937 level_number_current = level_number;
3939 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3942 DrawChooseTree(&level_number_current);
3944 DrawChooseTree(&leveldir_current);
3951 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3954 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3956 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3964 void DrawHallOfFame(int highlight_position)
3967 FadeSoundsAndMusic();
3969 /* (this is needed when called from GameEnd() after winning a game) */
3970 KeyboardAutoRepeatOn();
3973 /* (this is needed when called from GameEnd() after winning a game) */
3974 SetDrawDeactivationMask(REDRAW_NONE);
3975 SetDrawBackgroundMask(REDRAW_FIELD);
3977 CloseDoor(DOOR_CLOSE_2);
3979 if (highlight_position < 0)
3980 LoadScore(level_nr);
3982 FadeSetEnterScreen();
3984 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3987 FadeOut(REDRAW_FIELD);
3995 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3998 FadeIn(REDRAW_FIELD);
4002 static void drawHallOfFameList(int first_entry, int highlight_position)
4006 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4009 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4010 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4011 "HighScores of Level %d", level_nr);
4013 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4015 int entry = first_entry + i;
4016 boolean active = (entry == highlight_position);
4017 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4018 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4019 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4020 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4021 int dx1 = 3 * getFontWidth(font_nr1);
4022 int dx2 = dx1 + getFontWidth(font_nr1);
4023 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4024 int sy = mSY + 64 + i * 32;
4026 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4027 DrawText(mSX + dx1, sy, ".", font_nr1);
4028 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4030 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4031 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4033 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4036 redraw_mask |= REDRAW_FIELD;
4039 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4041 static int first_entry = 0;
4042 static int highlight_position = 0;
4043 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4045 if (button == MB_MENU_INITIALIZE)
4048 highlight_position = mx;
4049 drawHallOfFameList(first_entry, highlight_position);
4054 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4055 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4059 if (first_entry > 0)
4061 first_entry -= step;
4062 if (first_entry < 0)
4065 drawHallOfFameList(first_entry, highlight_position);
4070 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4072 first_entry += step;
4073 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4074 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4076 drawHallOfFameList(first_entry, highlight_position);
4079 else if (button == MB_MENU_LEAVE)
4081 PlaySound(SND_MENU_ITEM_SELECTING);
4083 FadeSound(SND_BACKGROUND_SCORES);
4085 game_status = GAME_MODE_MAIN;
4089 else if (button == MB_MENU_CHOICE)
4091 PlaySound(SND_MENU_ITEM_SELECTING);
4093 FadeSound(SND_BACKGROUND_SCORES);
4096 FadeOut(REDRAW_FIELD);
4099 game_status = GAME_MODE_MAIN;
4101 DrawAndFadeInMainMenu(REDRAW_FIELD);
4104 if (game_status == GAME_MODE_SCORES)
4105 PlayMenuSoundIfLoop();
4113 /* ========================================================================= */
4114 /* setup screen functions */
4115 /* ========================================================================= */
4117 static struct TokenInfo *setup_info;
4118 static int num_setup_info;
4120 static char *screen_mode_text;
4121 static char *window_size_text;
4122 static char *scaling_type_text;
4123 static char *scroll_delay_text;
4124 static char *game_speed_text;
4125 static char *graphics_set_name;
4126 static char *sounds_set_name;
4127 static char *music_set_name;
4128 static char *volume_simple_text;
4129 static char *volume_loops_text;
4130 static char *volume_music_text;
4132 static void execSetupMain()
4134 setup_mode = SETUP_MODE_MAIN;
4139 static void execSetupGame_setGameSpeeds()
4141 if (game_speeds == NULL)
4145 for (i = 0; game_speeds_list[i].value != -1; i++)
4147 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4148 char identifier[32], name[32];
4149 int value = game_speeds_list[i].value;
4150 char *text = game_speeds_list[i].text;
4152 ti->node_top = &game_speeds;
4153 ti->sort_priority = 10000 - value;
4155 sprintf(identifier, "%d", value);
4156 sprintf(name, "%s", text);
4158 setString(&ti->identifier, identifier);
4159 setString(&ti->name, name);
4160 setString(&ti->name_sorting, name);
4161 setString(&ti->infotext, "Game Speed");
4163 pushTreeInfo(&game_speeds, ti);
4166 /* sort game speed values to start with slowest game speed */
4167 sortTreeInfo(&game_speeds);
4169 /* set current game speed to configured game speed value */
4170 game_speed_current =
4171 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4173 /* if that fails, set current game speed to reliable default value */
4174 if (game_speed_current == NULL)
4175 game_speed_current =
4176 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4178 /* if that also fails, set current game speed to first available speed */
4179 if (game_speed_current == NULL)
4180 game_speed_current = game_speeds;
4183 setup.game_frame_delay = atoi(game_speed_current->identifier);
4185 /* needed for displaying game speed text instead of identifier */
4186 game_speed_text = game_speed_current->name;
4189 static void execSetupGame_setScrollDelays()
4191 if (scroll_delays == NULL)
4195 for (i = 0; scroll_delays_list[i].value != -1; i++)
4197 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4198 char identifier[32], name[32];
4199 int value = scroll_delays_list[i].value;
4200 char *text = scroll_delays_list[i].text;
4202 ti->node_top = &scroll_delays;
4203 ti->sort_priority = value;
4205 sprintf(identifier, "%d", value);
4206 sprintf(name, "%s", text);
4208 setString(&ti->identifier, identifier);
4209 setString(&ti->name, name);
4210 setString(&ti->name_sorting, name);
4211 setString(&ti->infotext, "Scaling Type");
4213 pushTreeInfo(&scroll_delays, ti);
4216 /* sort scaling type values to start with lowest scaling type value */
4217 sortTreeInfo(&scroll_delays);
4219 /* set current scaling type value to configured scaling type value */
4220 scroll_delay_current =
4221 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4223 /* if that fails, set current scaling type to reliable default value */
4224 if (scroll_delay_current == NULL)
4225 scroll_delay_current =
4226 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4228 /* if that also fails, set current scaling type to first available value */
4229 if (scroll_delay_current == NULL)
4230 scroll_delay_current = scroll_delays;
4233 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4235 /* needed for displaying scaling type text instead of identifier */
4236 scroll_delay_text = scroll_delay_current->name;
4239 static void execSetupGame()
4241 execSetupGame_setGameSpeeds();
4242 execSetupGame_setScrollDelays();
4244 setup_mode = SETUP_MODE_GAME;
4249 static void execSetupChooseGameSpeed()
4251 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4256 static void execSetupChooseScrollDelay()
4258 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4263 static void execSetupEditor()
4265 setup_mode = SETUP_MODE_EDITOR;
4270 static void execSetupGraphics_setWindowSizes(boolean update_list)
4272 if (window_sizes != NULL && update_list)
4274 freeTreeInfo(window_sizes);
4276 window_sizes = NULL;
4279 if (window_sizes == NULL)
4281 boolean current_window_size_found = FALSE;
4284 for (i = 0; window_sizes_list[i].value != -1; i++)
4286 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4287 char identifier[32], name[32];
4288 int value = window_sizes_list[i].value;
4289 char *text = window_sizes_list[i].text;
4291 ti->node_top = &window_sizes;
4292 ti->sort_priority = value;
4294 sprintf(identifier, "%d", value);
4295 sprintf(name, "%s", text);
4297 setString(&ti->identifier, identifier);
4298 setString(&ti->name, name);
4299 setString(&ti->name_sorting, name);
4300 setString(&ti->infotext, "Window Scaling");
4302 pushTreeInfo(&window_sizes, ti);
4304 if (value == setup.window_scaling_percent)
4305 current_window_size_found = TRUE;
4308 if (!current_window_size_found)
4310 // add entry for non-preset window scaling value
4312 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4313 char identifier[32], name[32];
4314 int value = setup.window_scaling_percent;
4316 ti->node_top = &window_sizes;
4317 ti->sort_priority = value;
4319 sprintf(identifier, "%d", value);
4320 sprintf(name, "%d %% (Current)", value);
4322 setString(&ti->identifier, identifier);
4323 setString(&ti->name, name);
4324 setString(&ti->name_sorting, name);
4325 setString(&ti->infotext, "Window Scaling");
4327 pushTreeInfo(&window_sizes, ti);
4330 /* sort window size values to start with lowest window size value */
4331 sortTreeInfo(&window_sizes);
4333 /* set current window size value to configured window size value */
4334 window_size_current =
4335 getTreeInfoFromIdentifier(window_sizes,
4336 i_to_a(setup.window_scaling_percent));
4338 /* if that fails, set current window size to reliable default value */
4339 if (window_size_current == NULL)
4340 window_size_current =
4341 getTreeInfoFromIdentifier(window_sizes,
4342 i_to_a(STD_WINDOW_SCALING_PERCENT));
4344 /* if that also fails, set current window size to first available value */
4345 if (window_size_current == NULL)
4346 window_size_current = window_sizes;
4349 setup.window_scaling_percent = atoi(window_size_current->identifier);
4351 /* needed for displaying window size text instead of identifier */
4352 window_size_text = window_size_current->name;
4355 static void execSetupGraphics_setScalingTypes()
4357 if (scaling_types == NULL)
4361 for (i = 0; scaling_types_list[i].value != NULL; i++)
4363 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4364 char identifier[32], name[32];
4365 char *value = scaling_types_list[i].value;
4366 char *text = scaling_types_list[i].text;
4368 ti->node_top = &scaling_types;
4369 ti->sort_priority = i;
4371 sprintf(identifier, "%s", value);
4372 sprintf(name, "%s", text);
4374 setString(&ti->identifier, identifier);
4375 setString(&ti->name, name);
4376 setString(&ti->name_sorting, name);
4377 setString(&ti->infotext, "Anti-Aliasing");
4379 pushTreeInfo(&scaling_types, ti);
4382 /* sort scaling type values to start with lowest scaling type value */
4383 sortTreeInfo(&scaling_types);
4385 /* set current scaling type value to configured scaling type value */
4386 scaling_type_current =
4387 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4389 /* if that fails, set current scaling type to reliable default value */
4390 if (scaling_type_current == NULL)
4391 scaling_type_current =
4392 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4394 /* if that also fails, set current scaling type to first available value */
4395 if (scaling_type_current == NULL)
4396 scaling_type_current = scaling_types;
4399 setup.window_scaling_quality = scaling_type_current->identifier;
4401 /* needed for displaying scaling type text instead of identifier */
4402 scaling_type_text = scaling_type_current->name;
4405 static void execSetupGraphics_setScreenModes()
4407 // if (screen_modes == NULL && video.fullscreen_available)
4408 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4412 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4414 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4415 char identifier[32], name[32];
4416 int x = video.fullscreen_modes[i].width;
4417 int y = video.fullscreen_modes[i].height;
4420 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4422 ti->node_top = &screen_modes;
4423 ti->sort_priority = x * 10000 + y;
4425 sprintf(identifier, "%dx%d", x, y);
4426 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4428 setString(&ti->identifier, identifier);
4429 setString(&ti->name, name);
4430 setString(&ti->name_sorting, name);
4431 setString(&ti->infotext, "Fullscreen Mode");
4433 pushTreeInfo(&screen_modes, ti);
4436 /* sort fullscreen modes to start with lowest available screen resolution */
4437 sortTreeInfo(&screen_modes);
4439 /* set current screen mode for fullscreen mode to configured setup value */
4440 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4441 setup.fullscreen_mode);
4443 /* if that fails, set current screen mode to reliable default value */
4444 if (screen_mode_current == NULL)
4445 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4446 DEFAULT_FULLSCREEN_MODE);
4448 /* if that also fails, set current screen mode to first available mode */
4449 if (screen_mode_current == NULL)
4450 screen_mode_current = screen_modes;
4452 if (screen_mode_current == NULL)
4453 video.fullscreen_available = FALSE;
4456 // if (video.fullscreen_available)
4457 if (screen_mode_current != NULL)
4459 setup.fullscreen_mode = screen_mode_current->identifier;
4461 /* needed for displaying screen mode name instead of identifier */
4462 screen_mode_text = screen_mode_current->name;
4466 static void execSetupGraphics()
4468 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4470 // update "setup.window_scaling_percent" from list selection
4471 execSetupGraphics_setWindowSizes(FALSE);
4475 // update list selection from "setup.window_scaling_percent"
4476 execSetupGraphics_setWindowSizes(TRUE);
4479 execSetupGraphics_setScalingTypes();
4480 execSetupGraphics_setScreenModes();
4482 setup_mode = SETUP_MODE_GRAPHICS;
4486 #if defined(TARGET_SDL2)
4487 // window scaling may have changed at this point
4488 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4490 // window scaling quality may have changed at this point
4491 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4492 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4496 #if !defined(PLATFORM_ANDROID)
4497 #if defined(TARGET_SDL2)
4498 static void execSetupChooseWindowSize()
4501 if (!video.window_scaling_available)
4505 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4510 static void execSetupChooseScalingType()
4512 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4517 static void execSetupChooseScreenMode()
4519 if (!video.fullscreen_available)
4522 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4529 static void execSetupChooseVolumeSimple()
4531 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4536 static void execSetupChooseVolumeLoops()
4538 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4543 static void execSetupChooseVolumeMusic()
4545 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4550 static void execSetupSound()
4553 if (volumes_simple == NULL)
4557 for (i = 0; volumes_list[i].value != -1; i++)
4559 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4560 char identifier[32], name[32];
4561 int value = volumes_list[i].value;
4562 char *text = volumes_list[i].text;
4564 ti->node_top = &volumes_simple;
4565 ti->sort_priority = value;
4567 sprintf(identifier, "%d", value);
4568 sprintf(name, "%s", text);
4570 setString(&ti->identifier, identifier);
4571 setString(&ti->name, name);
4572 setString(&ti->name_sorting, name);
4573 setString(&ti->infotext, "Sound Volume");
4575 pushTreeInfo(&volumes_simple, ti);
4578 /* sort volume values to start with lowest volume value */
4579 sortTreeInfo(&volumes_simple);
4581 /* set current volume value to configured volume value */
4582 volume_simple_current =
4583 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4585 /* if that fails, set current volume to reliable default value */
4586 if (volume_simple_current == NULL)
4587 volume_simple_current =
4588 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4590 /* if that also fails, set current volume to first available value */
4591 if (volume_simple_current == NULL)
4592 volume_simple_current = volumes_simple;
4595 if (volumes_loops == NULL)
4599 for (i = 0; volumes_list[i].value != -1; i++)
4601 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4602 char identifier[32], name[32];
4603 int value = volumes_list[i].value;
4604 char *text = volumes_list[i].text;
4606 ti->node_top = &volumes_loops;
4607 ti->sort_priority = value;
4609 sprintf(identifier, "%d", value);
4610 sprintf(name, "%s", text);
4612 setString(&ti->identifier, identifier);
4613 setString(&ti->name, name);
4614 setString(&ti->name_sorting, name);
4615 setString(&ti->infotext, "Loops Volume");
4617 pushTreeInfo(&volumes_loops, ti);
4620 /* sort volume values to start with lowest volume value */
4621 sortTreeInfo(&volumes_loops);
4623 /* set current volume value to configured volume value */
4624 volume_loops_current =
4625 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4627 /* if that fails, set current volume to reliable default value */
4628 if (volume_loops_current == NULL)
4629 volume_loops_current =
4630 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4632 /* if that also fails, set current volume to first available value */
4633 if (volume_loops_current == NULL)
4634 volume_loops_current = volumes_loops;
4637 if (volumes_music == NULL)
4641 for (i = 0; volumes_list[i].value != -1; i++)
4643 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4644 char identifier[32], name[32];
4645 int value = volumes_list[i].value;
4646 char *text = volumes_list[i].text;
4648 ti->node_top = &volumes_music;
4649 ti->sort_priority = value;
4651 sprintf(identifier, "%d", value);
4652 sprintf(name, "%s", text);
4654 setString(&ti->identifier, identifier);
4655 setString(&ti->name, name);
4656 setString(&ti->name_sorting, name);
4657 setString(&ti->infotext, "Music Volume");
4659 pushTreeInfo(&volumes_music, ti);
4662 /* sort volume values to start with lowest volume value */
4663 sortTreeInfo(&volumes_music);
4665 /* set current volume value to configured volume value */
4666 volume_music_current =
4667 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4669 /* if that fails, set current volume to reliable default value */
4670 if (volume_music_current == NULL)
4671 volume_music_current =
4672 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4674 /* if that also fails, set current volume to first available value */
4675 if (volume_music_current == NULL)
4676 volume_music_current = volumes_music;
4679 setup.volume_simple = atoi(volume_simple_current->identifier);
4680 setup.volume_loops = atoi(volume_loops_current->identifier);
4681 setup.volume_music = atoi(volume_music_current->identifier);
4683 /* needed for displaying volume text instead of identifier */
4684 volume_simple_text = volume_simple_current->name;
4685 volume_loops_text = volume_loops_current->name;
4686 volume_music_text = volume_music_current->name;
4689 setup_mode = SETUP_MODE_SOUND;
4694 static void execSetupArtwork()
4697 printf("::: '%s', '%s', '%s'\n",
4698 artwork.gfx_current->subdir,
4699 artwork.gfx_current->fullpath,
4700 artwork.gfx_current->basepath);
4703 setup.graphics_set = artwork.gfx_current->identifier;
4704 setup.sounds_set = artwork.snd_current->identifier;
4705 setup.music_set = artwork.mus_current->identifier;
4707 /* needed if last screen (setup choice) changed graphics, sounds or music */
4708 ReloadCustomArtwork(0);
4710 /* needed for displaying artwork name instead of artwork identifier */
4711 graphics_set_name = artwork.gfx_current->name;
4712 sounds_set_name = artwork.snd_current->name;
4713 music_set_name = artwork.mus_current->name;
4715 setup_mode = SETUP_MODE_ARTWORK;
4720 static void execSetupChooseGraphics()
4722 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4727 static void execSetupChooseSounds()
4729 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4734 static void execSetupChooseMusic()
4736 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4741 static void execSetupInput()
4743 setup_mode = SETUP_MODE_INPUT;
4748 static void execSetupShortcuts()
4750 setup_mode = SETUP_MODE_SHORTCUTS;
4755 static void execSetupShortcuts1()
4757 setup_mode = SETUP_MODE_SHORTCUTS_1;
4762 static void execSetupShortcuts2()
4764 setup_mode = SETUP_MODE_SHORTCUTS_2;
4769 static void execSetupShortcuts3()
4771 setup_mode = SETUP_MODE_SHORTCUTS_3;
4776 static void execSetupShortcuts4()
4778 setup_mode = SETUP_MODE_SHORTCUTS_4;
4783 static void execSetupShortcuts5()
4785 setup_mode = SETUP_MODE_SHORTCUTS_5;
4790 static void execExitSetup()
4792 game_status = GAME_MODE_MAIN;
4794 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4797 static void execSaveAndExitSetup()
4803 static struct TokenInfo setup_info_main[] =
4805 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4806 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4807 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4808 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4809 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4810 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4811 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4812 { TYPE_EMPTY, NULL, "" },
4813 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4814 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4819 static struct TokenInfo setup_info_game[] =
4821 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4822 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4823 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4824 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4825 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4826 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4827 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4828 { TYPE_STRING, &game_speed_text, "" },
4830 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4831 { TYPE_STRING, &scroll_delay_text, "" },
4833 { TYPE_EMPTY, NULL, "" },
4834 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4839 static struct TokenInfo setup_info_editor[] =
4842 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4843 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4844 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4845 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4846 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4847 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4848 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4849 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4851 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4852 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4853 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4855 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4857 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4858 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4859 { TYPE_EMPTY, NULL, "" },
4861 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4862 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4863 { TYPE_EMPTY, NULL, "" },
4865 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4866 { TYPE_EMPTY, NULL, "" },
4867 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4872 static struct TokenInfo setup_info_graphics[] =
4874 #if !defined(PLATFORM_ANDROID)
4875 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4876 #if defined(TARGET_SDL2)
4877 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4878 { TYPE_STRING, &window_size_text, "" },
4880 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4881 { TYPE_STRING, &scaling_type_text, "" },
4884 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4885 { TYPE_STRING, &screen_mode_text, "" },
4889 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4892 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4893 { TYPE_STRING, &scroll_delay_text, "" },
4896 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4898 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4899 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4900 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4901 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4902 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4903 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4904 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4905 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4906 { TYPE_EMPTY, NULL, "" },
4907 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4912 static struct TokenInfo setup_info_sound[] =
4914 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4915 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4916 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4917 { TYPE_EMPTY, NULL, "" },
4918 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4919 { TYPE_STRING, &volume_simple_text, "" },
4920 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4921 { TYPE_STRING, &volume_loops_text, "" },
4922 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4923 { TYPE_STRING, &volume_music_text, "" },
4924 { TYPE_EMPTY, NULL, "" },
4925 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4930 static struct TokenInfo setup_info_artwork[] =
4932 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4933 { TYPE_STRING, &graphics_set_name, "" },
4934 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4935 { TYPE_STRING, &sounds_set_name, "" },
4936 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4937 { TYPE_STRING, &music_set_name, "" },
4938 { TYPE_EMPTY, NULL, "" },
4941 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4942 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4943 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4945 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4946 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4947 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4948 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4951 { TYPE_STRING, NULL, "Override Level Artwork:"},
4952 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4953 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4954 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4956 { TYPE_EMPTY, NULL, "" },
4957 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4962 static struct TokenInfo setup_info_input[] =
4964 { TYPE_SWITCH, NULL, "Player:" },
4965 { TYPE_SWITCH, NULL, "Device:" },
4966 { TYPE_ENTER_MENU, NULL, "" },
4967 { TYPE_EMPTY, NULL, "" },
4968 { TYPE_EMPTY, NULL, "" },
4969 { TYPE_EMPTY, NULL, "" },
4970 { TYPE_EMPTY, NULL, "" },
4971 { TYPE_EMPTY, NULL, "" },
4972 { TYPE_EMPTY, NULL, "" },
4973 { TYPE_EMPTY, NULL, "" },
4974 { TYPE_EMPTY, NULL, "" },
4975 { TYPE_EMPTY, NULL, "" },
4976 { TYPE_EMPTY, NULL, "" },
4977 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4982 static struct TokenInfo setup_info_shortcuts[] =
4984 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4985 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4986 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4987 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4988 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4989 { TYPE_EMPTY, NULL, "" },
4990 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4995 static struct TokenInfo setup_info_shortcuts_1[] =
4997 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4998 { TYPE_KEY, &setup.shortcut.save_game, "" },
4999 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5000 { TYPE_KEY, &setup.shortcut.load_game, "" },
5001 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5002 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5003 { TYPE_EMPTY, NULL, "" },
5004 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5005 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5006 { TYPE_EMPTY, NULL, "" },
5007 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5012 static struct TokenInfo setup_info_shortcuts_2[] =
5014 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5015 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5016 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5017 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5018 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5019 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5020 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5021 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5022 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5023 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5024 { TYPE_EMPTY, NULL, "" },
5025 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5030 static struct TokenInfo setup_info_shortcuts_3[] =
5032 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5033 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5034 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5035 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5036 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5037 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5038 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5039 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5040 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5041 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5042 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5043 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5044 { TYPE_EMPTY, NULL, "" },
5045 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5050 static struct TokenInfo setup_info_shortcuts_4[] =
5052 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5053 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5054 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5055 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5056 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5057 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5058 { TYPE_EMPTY, NULL, "" },
5059 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5064 static struct TokenInfo setup_info_shortcuts_5[] =
5066 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5067 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5068 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5069 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5070 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5071 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5072 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5073 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5074 { TYPE_EMPTY, NULL, "" },
5075 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5080 static Key getSetupKey()
5082 Key key = KSYM_UNDEFINED;
5083 boolean got_key_event = FALSE;
5085 while (!got_key_event)
5087 if (PendingEvent()) /* got event */
5095 case EVENT_KEYPRESS:
5097 key = GetEventKey((KeyEvent *)&event, TRUE);
5099 /* press 'Escape' or 'Enter' to keep the existing key binding */
5100 if (key == KSYM_Escape || key == KSYM_Return)
5101 key = KSYM_UNDEFINED; /* keep old value */
5103 got_key_event = TRUE;
5107 case EVENT_KEYRELEASE:
5108 key_joystick_mapping = 0;
5112 HandleOtherEvents(&event);
5120 /* don't eat all CPU time */
5127 static int getSetupTextFont(int type)
5129 if (type & (TYPE_SWITCH |
5141 static int getSetupValueFont(int type, void *value)
5143 if (type & TYPE_KEY)
5144 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5145 else if (type & TYPE_STRING)
5146 return FONT_VALUE_2;
5147 else if (type & TYPE_ECS_AGA)
5148 return FONT_VALUE_1;
5149 else if (type & TYPE_BOOLEAN_STYLE)
5150 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5151 else if (type & TYPE_YES_NO_AUTO)
5152 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5153 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5155 return FONT_VALUE_1;
5158 static void drawSetupValue(int pos)
5160 boolean font_draw_xoffset_modified = FALSE;
5161 int font_draw_xoffset_old = -1;
5162 int xpos = MENU_SCREEN_VALUE_XPOS;
5163 int ypos = MENU_SCREEN_START_YPOS + pos;
5164 int startx = mSX + xpos * 32;
5165 int starty = mSY + ypos * 32;
5166 int font_nr, font_width;
5170 int type = setup_info[pos].type;
5171 void *value = setup_info[pos].value;
5172 char *value_string = getSetupValue(type, value);
5177 if (value_string == NULL)
5180 if (type & TYPE_KEY)
5182 xpos = MENU_SCREEN_START_XPOS;
5184 if (type & TYPE_QUERY)
5185 value_string = "<press key>";
5187 else if (type & TYPE_STRING)
5189 int max_value_len = (SCR_FIELDX - 2) * 2;
5191 xpos = MENU_SCREEN_START_XPOS;
5193 if (strlen(value_string) > max_value_len)
5194 value_string[max_value_len] = '\0';
5196 else if (type & TYPE_YES_NO_AUTO)
5198 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5201 startx = mSX + xpos * 32;
5202 starty = mSY + ypos * 32;
5203 font_nr = getSetupValueFont(type, value);
5204 font_width = getFontWidth(font_nr);
5206 font_height = getFontHeight(font_nr);
5209 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5210 if (setup_mode != SETUP_MODE_INPUT)
5212 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5213 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5214 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5215 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5216 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5217 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5218 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5219 boolean correct_font_draw_xoffset = FALSE;
5221 if (xpos == MENU_SCREEN_START_XPOS &&
5222 startx + font1_xoffset < text_startx + text_font_xoffset)
5223 correct_font_draw_xoffset = TRUE;
5225 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5226 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5227 correct_font_draw_xoffset = TRUE;
5229 /* check if setup value would overlap with setup text when printed */
5230 /* (this can happen for extreme/wrong values for font draw offset) */
5231 if (correct_font_draw_xoffset)
5233 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5234 font_draw_xoffset_modified = TRUE;
5236 if (type & TYPE_KEY)
5237 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5238 else if (!(type & TYPE_STRING))
5239 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5240 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5245 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5247 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5248 DrawText(startx + i * font_width, starty, " ", font_nr);
5251 DrawText(startx, starty, value_string, font_nr);
5253 if (font_draw_xoffset_modified)
5254 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5257 static void changeSetupValue(int pos, int dx)
5259 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5261 *(boolean *)setup_info[pos].value ^= TRUE;
5263 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5265 *(int *)setup_info[pos].value =
5267 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5268 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5269 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5270 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5272 else if (setup_info[pos].type & TYPE_KEY)
5276 setup_info[pos].type |= TYPE_QUERY;
5277 drawSetupValue(pos);
5278 setup_info[pos].type &= ~TYPE_QUERY;
5280 key = getSetupKey();
5281 if (key != KSYM_UNDEFINED)
5282 *(Key *)setup_info[pos].value = key;
5285 drawSetupValue(pos);
5287 // fullscreen state may have changed at this point
5288 if (setup_info[pos].value == &setup.fullscreen)
5289 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5292 static void DrawCursorAndText_Setup(int pos, boolean active)
5294 int xpos = MENU_SCREEN_START_XPOS;
5295 int ypos = MENU_SCREEN_START_YPOS + pos;
5296 int font_nr = getSetupTextFont(setup_info[pos].type);
5298 if (setup_info == setup_info_input)
5299 font_nr = FONT_MENU_1;
5302 font_nr = FONT_ACTIVE(font_nr);
5304 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5306 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5307 drawCursor(pos, active);
5310 static void DrawSetupScreen_Generic()
5312 boolean redraw_all = FALSE;
5313 char *title_string = NULL;
5317 CloseDoor(DOOR_CLOSE_2);
5319 if (redraw_mask & REDRAW_ALL)
5323 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5324 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5325 int2str(0, redraw_mask)));
5329 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5330 FadeOut(redraw_mask);
5332 FadeOut(REDRAW_FIELD);
5337 if (setup_mode == SETUP_MODE_MAIN)
5339 setup_info = setup_info_main;
5340 title_string = "Setup";
5342 else if (setup_mode == SETUP_MODE_GAME)
5344 setup_info = setup_info_game;
5345 title_string = "Setup Game";
5347 else if (setup_mode == SETUP_MODE_EDITOR)
5349 setup_info = setup_info_editor;
5350 title_string = "Setup Editor";
5352 else if (setup_mode == SETUP_MODE_GRAPHICS)
5354 setup_info = setup_info_graphics;
5355 title_string = "Setup Graphics";
5357 else if (setup_mode == SETUP_MODE_SOUND)
5359 setup_info = setup_info_sound;
5360 title_string = "Setup Sound";
5362 else if (setup_mode == SETUP_MODE_ARTWORK)
5364 setup_info = setup_info_artwork;
5365 title_string = "Custom Artwork";
5367 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5369 setup_info = setup_info_shortcuts;
5370 title_string = "Setup Shortcuts";
5372 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5374 setup_info = setup_info_shortcuts_1;
5375 title_string = "Setup Shortcuts";
5377 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5379 setup_info = setup_info_shortcuts_2;
5380 title_string = "Setup Shortcuts";
5382 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5384 setup_info = setup_info_shortcuts_3;
5385 title_string = "Setup Shortcuts";
5387 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5389 setup_info = setup_info_shortcuts_4;
5390 title_string = "Setup Shortcuts";
5392 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5394 setup_info = setup_info_shortcuts_5;
5395 title_string = "Setup Shortcuts";
5398 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5402 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5404 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5407 void *value_ptr = setup_info[i].value;
5409 /* set some entries to "unchangeable" according to other variables */
5410 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5411 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5412 (value_ptr == &setup.sound_music && !audio.music_available) ||
5413 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5414 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5415 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5416 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5417 setup_info[i].type |= TYPE_GHOSTED;
5419 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5420 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5421 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5422 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5423 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5424 initCursor(i, IMG_MENU_BUTTON);
5426 DrawCursorAndText_Setup(i, FALSE);
5428 if (setup_info[i].type & TYPE_VALUE)
5435 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5436 "Joysticks deactivated in setup menu");
5440 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5444 redraw_mask = REDRAW_ALL;
5447 FadeIn(redraw_mask);
5449 FadeIn(REDRAW_FIELD);
5454 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5458 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5460 static int choice_store[MAX_SETUP_MODES];
5461 int choice = choice_store[setup_mode]; /* always starts with 0 */
5465 if (button == MB_MENU_INITIALIZE)
5467 /* advance to first valid menu entry */
5468 while (choice < num_setup_info &&
5469 setup_info[choice].type & TYPE_SKIP_ENTRY)
5471 choice_store[setup_mode] = choice;
5473 DrawCursorAndText_Setup(choice, TRUE);
5477 else if (button == MB_MENU_LEAVE)
5479 PlaySound(SND_MENU_ITEM_SELECTING);
5481 // for (y = 0; y < num_setup_info; y++)
5482 for (y = 0; setup_info[y].type != 0; y++)
5484 if (setup_info[y].type & TYPE_LEAVE_MENU)
5486 void (*menu_callback_function)(void) = setup_info[y].value;
5490 menu_callback_function();
5492 break; /* absolutely needed because function changes 'setup_info'! */
5499 if (mx || my) /* mouse input */
5501 x = (mx - mSX) / 32;
5502 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5504 else if (dx || dy) /* keyboard input */
5508 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5510 if (setup_info[choice].type & menu_navigation_type ||
5511 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5512 setup_info[choice].type & TYPE_YES_NO_AUTO)
5513 button = MB_MENU_CHOICE;
5518 /* jump to next non-empty menu entry (up or down) */
5519 while (y > 0 && y < num_setup_info - 1 &&
5520 setup_info[y].type & TYPE_SKIP_ENTRY)
5524 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5528 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5530 PlaySound(SND_MENU_ITEM_ACTIVATING);
5532 DrawCursorAndText_Setup(choice, FALSE);
5533 DrawCursorAndText_Setup(y, TRUE);
5535 choice = choice_store[setup_mode] = y;
5538 else if (!(setup_info[y].type & TYPE_GHOSTED))
5540 PlaySound(SND_MENU_ITEM_SELECTING);
5542 /* when selecting key headline, execute function for key value change */
5543 if (setup_info[y].type & TYPE_KEYTEXT &&
5544 setup_info[y + 1].type & TYPE_KEY)
5547 /* when selecting string value, execute function for list selection */
5548 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5549 setup_info[y - 1].type & TYPE_ENTER_LIST)
5552 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5554 void (*menu_callback_function)(void) = setup_info[y].value;
5556 FadeSetFromType(setup_info[y].type);
5558 menu_callback_function();
5562 if (setup_info[y].type & TYPE_VALUE)
5563 changeSetupValue(y, dx);
5569 void DrawSetupScreen_Input()
5574 FadeOut(REDRAW_FIELD);
5580 setup_info = setup_info_input;
5583 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5587 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5588 "Joysticks deactivated on this screen");
5590 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5591 "Joysticks deactivated on this screen");
5596 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5598 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5601 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5602 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5603 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5604 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5605 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5606 initCursor(i, IMG_MENU_BUTTON);
5608 DrawCursorAndText_Setup(i, FALSE);
5612 DeactivateJoystickForCalibration();
5617 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5618 "Joysticks deactivated on this screen");
5620 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5621 "Joysticks deactivated on this screen");
5625 /* create gadgets for setup input menu screen */
5626 FreeScreenGadgets();
5627 CreateScreenGadgets();
5629 /* map gadgets for setup input menu screen */
5630 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5632 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5635 FadeIn(REDRAW_FIELD);
5641 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5643 if (device_name == NULL)
5646 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5649 if (strlen(device_name) > 1)
5651 char c1 = device_name[strlen(device_name) - 1];
5652 char c2 = device_name[strlen(device_name) - 2];
5654 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5655 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5658 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5659 strlen(device_name));
5662 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5665 static struct SetupKeyboardInfo custom_key;
5672 { &custom_key.left, "Joystick Left" },
5673 { &custom_key.right, "Joystick Right" },
5674 { &custom_key.up, "Joystick Up" },
5675 { &custom_key.down, "Joystick Down" },
5676 { &custom_key.snap, "Button 1" },
5677 { &custom_key.drop, "Button 2" }
5679 static char *joystick_name[MAX_PLAYERS] =
5686 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5690 custom_key = setup.input[player_nr].key;
5692 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5693 FONT_INPUT_1_ACTIVE);
5695 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5697 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5698 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5700 if (setup.input[player_nr].use_joystick)
5702 char *device_name = setup.input[player_nr].joy.device_name;
5703 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5704 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5706 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5707 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5711 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5712 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5715 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5717 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5718 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5719 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5720 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5722 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5723 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5724 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5725 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5726 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5727 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5729 for (i = 0; i < 6; i++)
5731 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5733 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5735 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5736 (setup.input[player_nr].use_joystick ?
5738 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5742 static int input_player_nr = 0;
5744 void HandleSetupScreen_Input_Player(int step, int direction)
5746 int old_player_nr = input_player_nr;
5749 new_player_nr = old_player_nr + step * direction;
5750 if (new_player_nr < 0)
5752 if (new_player_nr > MAX_PLAYERS - 1)
5753 new_player_nr = MAX_PLAYERS - 1;
5755 if (new_player_nr != old_player_nr)
5757 input_player_nr = new_player_nr;
5759 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5763 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5765 static int choice = 0;
5768 int pos_start = SETUPINPUT_SCREEN_POS_START;
5769 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5770 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5771 int pos_end = SETUPINPUT_SCREEN_POS_END;
5773 if (button == MB_MENU_INITIALIZE)
5775 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5777 DrawCursorAndText_Setup(choice, TRUE);
5781 else if (button == MB_MENU_LEAVE)
5783 setup_mode = SETUP_MODE_MAIN;
5790 if (mx || my) /* mouse input */
5792 x = (mx - mSX) / 32;
5793 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5795 else if (dx || dy) /* keyboard input */
5797 if (dx && choice == 0)
5798 x = (dx < 0 ? 10 : 12);
5799 else if ((dx && choice == 1) ||
5800 (dx == +1 && choice == 2) ||
5801 (dx == -1 && choice == pos_end))
5802 button = MB_MENU_CHOICE;
5806 if (y >= pos_empty1 && y <= pos_empty2)
5807 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5810 if (y == 0 && dx != 0 && button)
5812 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5814 else if (IN_VIS_FIELD(x, y) &&
5815 y >= pos_start && y <= pos_end &&
5816 !(y >= pos_empty1 && y <= pos_empty2))
5822 DrawCursorAndText_Setup(choice, FALSE);
5823 DrawCursorAndText_Setup(y, TRUE);
5825 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5834 char *device_name = setup.input[input_player_nr].joy.device_name;
5836 if (!setup.input[input_player_nr].use_joystick)
5838 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5840 setJoystickDeviceToNr(device_name, new_device_nr);
5841 setup.input[input_player_nr].use_joystick = TRUE;
5845 int device_nr = getJoystickNrFromDeviceName(device_name);
5846 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5848 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5849 setup.input[input_player_nr].use_joystick = FALSE;
5851 setJoystickDeviceToNr(device_name, new_device_nr);
5854 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5858 if (setup.input[input_player_nr].use_joystick)
5861 CalibrateJoystick(input_player_nr);
5864 CustomizeKeyboard(input_player_nr);
5866 else if (y == pos_end)
5872 setup_mode = SETUP_MODE_MAIN;
5879 void CustomizeKeyboard(int player_nr)
5883 boolean finished = FALSE;
5884 static struct SetupKeyboardInfo custom_key;
5889 } customize_step[] =
5891 { &custom_key.left, "Move Left" },
5892 { &custom_key.right, "Move Right" },
5893 { &custom_key.up, "Move Up" },
5894 { &custom_key.down, "Move Down" },
5895 { &custom_key.snap, "Snap Field" },
5896 { &custom_key.drop, "Drop Element" }
5899 /* read existing key bindings from player setup */
5900 custom_key = setup.input[player_nr].key;
5903 FadeOut(REDRAW_FIELD);
5907 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5915 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5916 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5917 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5918 "Key:", FONT_INPUT_1_ACTIVE);
5919 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5920 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5923 FadeIn(REDRAW_FIELD);
5930 if (PendingEvent()) /* got event */
5938 case EVENT_KEYPRESS:
5940 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5942 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5944 if (key == KSYM_Escape)
5945 FadeSkipNextFadeIn();
5951 /* all keys configured -- wait for "Escape" or "Return" key */
5955 /* press 'Enter' to keep the existing key binding */
5956 if (key == KSYM_Return)
5957 key = *customize_step[step_nr].key;
5959 /* check if key already used */
5960 for (i = 0; i < step_nr; i++)
5961 if (*customize_step[i].key == key)
5966 /* got new key binding */
5967 *customize_step[step_nr].key = key;
5968 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5970 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5971 getKeyNameFromKey(key), FONT_VALUE_1);
5974 /* un-highlight last query */
5975 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5976 customize_step[step_nr - 1].text, FONT_MENU_1);
5977 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5978 "Key:", FONT_MENU_1);
5980 /* press 'Enter' to leave */
5983 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5984 "Press Enter", FONT_TITLE_1);
5988 /* query next key binding */
5989 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5990 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5991 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5992 "Key:", FONT_INPUT_1_ACTIVE);
5993 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5994 getKeyNameFromKey(*customize_step[step_nr].key),
5999 case EVENT_KEYRELEASE:
6000 key_joystick_mapping = 0;
6004 HandleOtherEvents(&event);
6012 /* don't eat all CPU time */
6016 /* write new key bindings back to player setup */
6017 setup.input[player_nr].key = custom_key;
6020 DrawSetupScreen_Input();
6023 static boolean CalibrateJoystickMain(int player_nr)
6025 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6026 int new_joystick_xright = JOYSTICK_XMIDDLE;
6027 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6028 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6029 int new_joystick_xmiddle, new_joystick_ymiddle;
6031 int joystick_fd = joystick.fd[player_nr];
6032 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6033 boolean check[3][3];
6034 int check_remaining = 3 * 3;
6039 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6042 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6046 FadeOut(REDRAW_FIELD);
6050 for (y = 0; y < 3; y++)
6052 for (x = 0; x < 3; x++)
6054 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6055 check[x][y] = FALSE;
6059 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6060 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6061 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6062 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6063 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6064 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6065 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6067 joy_value = Joystick(player_nr);
6068 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6069 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6071 /* eventually uncalibrated center position (joystick could be uncentered) */
6072 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6075 new_joystick_xmiddle = joy_x;
6076 new_joystick_ymiddle = joy_y;
6078 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6080 FadeIn(REDRAW_FIELD);
6082 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6087 if (PendingEvent()) /* got event */
6095 case EVENT_KEYPRESS:
6096 switch (GetEventKey((KeyEvent *)&event, TRUE))
6099 if (check_remaining == 0)
6104 FadeSkipNextFadeIn();
6113 case EVENT_KEYRELEASE:
6114 key_joystick_mapping = 0;
6118 HandleOtherEvents(&event);
6123 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6126 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6127 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6128 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6129 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6131 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6132 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6133 setup.input[player_nr].joy.xright = new_joystick_xright;
6134 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6135 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6136 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6138 CheckJoystickData();
6140 joy_value = Joystick(player_nr);
6142 if (joy_value & JOY_BUTTON && check_remaining == 0)
6145 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6146 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6148 if (x != last_x || y != last_y)
6150 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6151 IMG_MENU_CALIBRATE_YELLOW, 0);
6152 DrawFixedGraphic(xpos + x, ypos + y,
6153 IMG_MENU_CALIBRATE_RED, 0);
6158 if (check_remaining > 0 && !check[x+1][y+1])
6160 check[x+1][y+1] = TRUE;
6166 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6167 setup.input[player_nr].joy.xleft,
6168 setup.input[player_nr].joy.xmiddle,
6169 setup.input[player_nr].joy.xright);
6170 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6171 setup.input[player_nr].joy.yupper,
6172 setup.input[player_nr].joy.ymiddle,
6173 setup.input[player_nr].joy.ylower);
6182 /* don't eat all CPU time */
6186 /* calibrated center position (joystick should now be centered) */
6187 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6190 new_joystick_xmiddle = joy_x;
6191 new_joystick_ymiddle = joy_y;
6196 DrawSetupScreen_Input();
6199 /* wait until the last pressed button was released */
6200 while (Joystick(player_nr) & JOY_BUTTON)
6202 if (PendingEvent()) /* got event */
6207 HandleOtherEvents(&event);
6216 void CalibrateJoystick(int player_nr)
6218 if (!CalibrateJoystickMain(player_nr))
6220 char *device_name = setup.input[player_nr].joy.device_name;
6221 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6222 int xpos = mSX - SX;
6223 int ypos = mSY - SY;
6227 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6228 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6231 Delay(2000); /* show error message for a short time */
6237 DrawSetupScreen_Input();
6241 void DrawSetupScreen()
6243 DeactivateJoystick();
6245 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6247 if (setup_mode == SETUP_MODE_INPUT)
6248 DrawSetupScreen_Input();
6249 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6250 DrawChooseTree(&game_speed_current);
6251 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6252 DrawChooseTree(&scroll_delay_current);
6253 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6254 DrawChooseTree(&screen_mode_current);
6255 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6256 DrawChooseTree(&window_size_current);
6257 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6258 DrawChooseTree(&scaling_type_current);
6259 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6260 DrawChooseTree(&artwork.gfx_current);
6261 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6262 DrawChooseTree(&artwork.snd_current);
6263 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6264 DrawChooseTree(&artwork.mus_current);
6265 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6266 DrawChooseTree(&volume_simple_current);
6267 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6268 DrawChooseTree(&volume_loops_current);
6269 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6270 DrawChooseTree(&volume_music_current);
6272 DrawSetupScreen_Generic();
6278 void RedrawSetupScreenAfterFullscreenToggle()
6281 if (setup_mode == SETUP_MODE_GRAPHICS ||
6282 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6284 // update list selection from "setup.window_scaling_percent"
6285 execSetupGraphics_setWindowSizes(TRUE);
6290 if (setup_mode == SETUP_MODE_GRAPHICS)
6295 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6297 if (setup_mode == SETUP_MODE_INPUT)
6298 HandleSetupScreen_Input(mx, my, dx, dy, button);
6299 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6300 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6301 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6302 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6303 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6304 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6305 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6306 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6307 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6308 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6309 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6310 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6311 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6312 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6313 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6314 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6315 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6316 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6317 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6318 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6319 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6320 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6322 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6329 void HandleGameActions()
6331 if (game_status != GAME_MODE_PLAYING)
6334 GameActions(); /* main game loop */
6336 if (tape.auto_play && !tape.playing)
6337 AutoPlayTape(); /* continue automatically playing next tape */
6341 /* ---------- new screen button stuff -------------------------------------- */
6343 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6348 case SCREEN_CTRL_ID_PREV_LEVEL:
6349 *x = mSX + menu.main.button.prev_level.x;
6350 *y = mSY + menu.main.button.prev_level.y;
6353 case SCREEN_CTRL_ID_NEXT_LEVEL:
6354 *x = mSX + menu.main.button.next_level.x;
6355 *y = mSY + menu.main.button.next_level.y;
6358 case SCREEN_CTRL_ID_PREV_LEVEL:
6359 *x = mSX + TILEX * getPrevlevelButtonPos();
6360 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6363 case SCREEN_CTRL_ID_NEXT_LEVEL:
6364 *x = mSX + TILEX * getNextLevelButtonPos();
6365 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6369 case SCREEN_CTRL_ID_PREV_PLAYER:
6370 *x = mSX + TILEX * 10;
6371 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6374 case SCREEN_CTRL_ID_NEXT_PLAYER:
6375 *x = mSX + TILEX * 12;
6376 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6380 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6386 int gfx_unpressed, gfx_pressed;
6387 void (*get_gadget_position)(int *, int *, int);
6391 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6394 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6395 getScreenMenuButtonPos,
6396 SCREEN_CTRL_ID_PREV_LEVEL,
6401 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6402 getScreenMenuButtonPos,
6403 SCREEN_CTRL_ID_NEXT_LEVEL,
6408 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6409 getScreenMenuButtonPos,
6410 SCREEN_CTRL_ID_PREV_PLAYER,
6415 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6416 getScreenMenuButtonPos,
6417 SCREEN_CTRL_ID_NEXT_PLAYER,
6425 int gfx_unpressed, gfx_pressed;
6429 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6432 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6434 -1, -1, /* these values are not constant, but can change at runtime */
6436 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6438 SCREEN_CTRL_ID_SCROLL_UP,
6442 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6444 -1, -1, /* these values are not constant, but can change at runtime */
6446 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6448 SCREEN_CTRL_ID_SCROLL_DOWN,
6455 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6456 Bitmap **gfx_unpressed, **gfx_pressed;
6458 int gfx_unpressed, gfx_pressed;
6465 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6468 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6469 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6471 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6474 -1, -1, /* these values are not constant, but can change at runtime */
6475 -1, -1, /* these values are not constant, but can change at runtime */
6477 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6478 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6480 GD_TYPE_SCROLLBAR_VERTICAL,
6481 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6482 "scroll level series vertically"
6486 static void CreateScreenMenubuttons()
6488 struct GadgetInfo *gi;
6489 unsigned int event_mask;
6492 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6494 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6495 int gfx_unpressed, gfx_pressed;
6496 int x, y, width, height;
6497 int gd_x1, gd_x2, gd_y1, gd_y2;
6498 int id = menubutton_info[i].gadget_id;
6500 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6502 menubutton_info[i].get_gadget_position(&x, &y, id);
6504 width = SC_MENUBUTTON_XSIZE;
6505 height = SC_MENUBUTTON_YSIZE;
6507 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6508 gfx_pressed = menubutton_info[i].gfx_pressed;
6509 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6510 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6511 gd_x1 = graphic_info[gfx_unpressed].src_x;
6512 gd_y1 = graphic_info[gfx_unpressed].src_y;
6513 gd_x2 = graphic_info[gfx_pressed].src_x;
6514 gd_y2 = graphic_info[gfx_pressed].src_y;
6516 gi = CreateGadget(GDI_CUSTOM_ID, id,
6517 GDI_CUSTOM_TYPE_ID, i,
6518 GDI_INFO_TEXT, menubutton_info[i].infotext,
6523 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6524 GDI_STATE, GD_BUTTON_UNPRESSED,
6525 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6526 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6527 GDI_DIRECT_DRAW, FALSE,
6528 GDI_EVENT_MASK, event_mask,
6529 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6533 Error(ERR_EXIT, "cannot create gadget");
6535 screen_gadget[id] = gi;
6539 static void CreateScreenScrollbuttons()
6541 struct GadgetInfo *gi;
6542 unsigned int event_mask;
6545 /* these values are not constant, but can change at runtime */
6546 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6547 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6548 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6549 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6551 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6553 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6554 int gfx_unpressed, gfx_pressed;
6555 int x, y, width, height;
6556 int gd_x1, gd_x2, gd_y1, gd_y2;
6557 int id = scrollbutton_info[i].gadget_id;
6559 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6561 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6562 y = mSY + scrollbutton_info[i].y;
6563 width = SC_SCROLLBUTTON_XSIZE;
6564 height = SC_SCROLLBUTTON_YSIZE;
6566 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6567 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6568 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6570 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6571 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6572 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6573 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6574 gd_x1 = graphic_info[gfx_unpressed].src_x;
6575 gd_y1 = graphic_info[gfx_unpressed].src_y;
6576 gd_x2 = graphic_info[gfx_pressed].src_x;
6577 gd_y2 = graphic_info[gfx_pressed].src_y;
6579 gi = CreateGadget(GDI_CUSTOM_ID, id,
6580 GDI_CUSTOM_TYPE_ID, i,
6581 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6586 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6587 GDI_STATE, GD_BUTTON_UNPRESSED,
6588 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6589 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6590 GDI_DIRECT_DRAW, FALSE,
6591 GDI_EVENT_MASK, event_mask,
6592 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6596 Error(ERR_EXIT, "cannot create gadget");
6598 screen_gadget[id] = gi;
6602 static void CreateScreenScrollbars()
6606 /* these values are not constant, but can change at runtime */
6607 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6608 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6609 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6610 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6612 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6614 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6615 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6616 int gfx_unpressed, gfx_pressed;
6618 int x, y, width, height;
6619 int gd_x1, gd_x2, gd_y1, gd_y2;
6620 struct GadgetInfo *gi;
6621 int items_max, items_visible, item_position;
6622 unsigned int event_mask;
6623 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6624 int id = scrollbar_info[i].gadget_id;
6626 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6628 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6629 y = mSY + scrollbar_info[i].y;
6630 width = scrollbar_info[i].width;
6631 height = scrollbar_info[i].height;
6633 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6634 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6636 items_max = num_page_entries;
6637 items_visible = num_page_entries;
6640 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6641 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6642 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6648 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6649 gfx_pressed = scrollbar_info[i].gfx_pressed;
6650 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6651 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6652 gd_x1 = graphic_info[gfx_unpressed].src_x;
6653 gd_y1 = graphic_info[gfx_unpressed].src_y;
6654 gd_x2 = graphic_info[gfx_pressed].src_x;
6655 gd_y2 = graphic_info[gfx_pressed].src_y;
6658 gi = CreateGadget(GDI_CUSTOM_ID, id,
6659 GDI_CUSTOM_TYPE_ID, i,
6660 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6665 GDI_TYPE, scrollbar_info[i].type,
6666 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6667 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6668 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6670 GDI_WHEEL_AREA_X, SX,
6671 GDI_WHEEL_AREA_Y, SY,
6672 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6673 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6675 GDI_WHEEL_AREA_X, 0,
6676 GDI_WHEEL_AREA_Y, 0,
6677 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6678 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6680 GDI_STATE, GD_BUTTON_UNPRESSED,
6681 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6682 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6683 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6684 GDI_DIRECT_DRAW, FALSE,
6685 GDI_EVENT_MASK, event_mask,
6686 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6690 Error(ERR_EXIT, "cannot create gadget");
6692 screen_gadget[id] = gi;
6696 void CreateScreenGadgets()
6698 int last_game_status = game_status; /* save current game status */
6700 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6703 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6705 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6707 /* copy pointers to clip mask and GC */
6708 scrollbar_bitmap[i]->clip_mask =
6709 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6710 scrollbar_bitmap[i]->stored_clip_gc =
6711 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6713 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6714 scrollbar_bitmap[i],
6715 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6716 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6717 TILEX, TILEY, 0, 0);
6721 CreateScreenMenubuttons();
6724 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6725 game_status = GAME_MODE_LEVELS;
6728 CreateScreenScrollbuttons();
6729 CreateScreenScrollbars();
6731 game_status = last_game_status; /* restore current game status */
6734 void FreeScreenGadgets()
6738 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6739 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6741 /* prevent freeing clip mask and GC twice */
6742 scrollbar_bitmap[i]->clip_mask = None;
6743 scrollbar_bitmap[i]->stored_clip_gc = None;
6745 FreeBitmap(scrollbar_bitmap[i]);
6749 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6750 FreeGadget(screen_gadget[i]);
6753 void MapScreenMenuGadgets(int screen_mask)
6757 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6758 if (screen_mask & menubutton_info[i].screen_mask)
6759 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6762 void MapScreenTreeGadgets(TreeInfo *ti)
6764 int num_entries = numTreeInfoInGroup(ti);
6767 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6770 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6771 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6773 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6774 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6777 static void HandleScreenGadgets(struct GadgetInfo *gi)
6779 int id = gi->custom_id;
6780 int button = gi->event.button;
6781 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6785 case SCREEN_CTRL_ID_PREV_LEVEL:
6786 HandleMainMenu_SelectLevel(step, -1);
6789 case SCREEN_CTRL_ID_NEXT_LEVEL:
6790 HandleMainMenu_SelectLevel(step, +1);
6793 case SCREEN_CTRL_ID_PREV_PLAYER:
6794 HandleSetupScreen_Input_Player(step, -1);
6797 case SCREEN_CTRL_ID_NEXT_PLAYER:
6798 HandleSetupScreen_Input_Player(step, +1);
6801 case SCREEN_CTRL_ID_SCROLL_UP:
6802 if (game_status == GAME_MODE_LEVELS)
6803 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6804 else if (game_status == GAME_MODE_LEVELNR)
6805 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6806 else if (game_status == GAME_MODE_SETUP)
6807 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6810 case SCREEN_CTRL_ID_SCROLL_DOWN:
6811 if (game_status == GAME_MODE_LEVELS)
6812 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6813 else if (game_status == GAME_MODE_LEVELNR)
6814 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6815 else if (game_status == GAME_MODE_SETUP)
6816 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6819 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6820 if (game_status == GAME_MODE_LEVELS)
6821 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6822 else if (game_status == GAME_MODE_LEVELNR)
6823 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6824 else if (game_status == GAME_MODE_SETUP)
6825 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);