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 CloseDoor(DOOR_CLOSE_2);
1919 game_status = GAME_MODE_EDITOR;
1921 FadeSetEnterScreen();
1924 /* needed if different viewport properties defined for editor */
1925 ChangeViewportPropertiesIfNeeded();
1930 else if (pos == MAIN_CONTROL_INFO)
1932 game_status = GAME_MODE_INFO;
1933 info_mode = INFO_MODE_MAIN;
1937 else if (pos == MAIN_CONTROL_GAME)
1939 StartGameActions(options.network, setup.autorecord, level.random_seed);
1941 else if (pos == MAIN_CONTROL_SETUP)
1943 game_status = GAME_MODE_SETUP;
1944 setup_mode = SETUP_MODE_MAIN;
1948 else if (pos == MAIN_CONTROL_QUIT)
1950 SaveLevelSetup_LastSeries();
1951 SaveLevelSetup_SeriesInfo();
1953 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1954 game_status = GAME_MODE_QUIT;
1960 if (game_status == GAME_MODE_MAIN)
1962 DrawPreviewLevelAnimation();
1969 /* ========================================================================= */
1970 /* info screen functions */
1971 /* ========================================================================= */
1973 static struct TokenInfo *info_info;
1974 static int num_info_info;
1976 static void execInfoTitleScreen()
1978 info_mode = INFO_MODE_TITLE;
1983 static void execInfoElements()
1985 info_mode = INFO_MODE_ELEMENTS;
1990 static void execInfoMusic()
1992 info_mode = INFO_MODE_MUSIC;
1997 static void execInfoCredits()
1999 info_mode = INFO_MODE_CREDITS;
2004 static void execInfoProgram()
2006 info_mode = INFO_MODE_PROGRAM;
2011 static void execInfoVersion()
2013 info_mode = INFO_MODE_VERSION;
2018 static void execInfoLevelSet()
2020 info_mode = INFO_MODE_LEVELSET;
2025 static void execExitInfo()
2027 game_status = GAME_MODE_MAIN;
2029 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2032 static struct TokenInfo info_info_main[] =
2034 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2035 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2036 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2037 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2038 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2039 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2040 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2041 { TYPE_EMPTY, NULL, "" },
2042 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2047 static void DrawCursorAndText_Info(int pos, boolean active)
2049 int xpos = MENU_SCREEN_START_XPOS;
2050 int ypos = MENU_SCREEN_START_YPOS + pos;
2051 int font_nr = FONT_MENU_1;
2054 font_nr = FONT_ACTIVE(font_nr);
2056 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2058 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2059 drawCursor(pos, active);
2062 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2067 CloseDoor(DOOR_CLOSE_2);
2069 /* (needed after displaying title screens which disable auto repeat) */
2070 KeyboardAutoRepeatOn();
2072 FadeSetLeaveScreen();
2079 if (fade_mask == REDRAW_ALL)
2083 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2089 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2091 info_info = info_info_main;
2095 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2097 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2100 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2101 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2102 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2103 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2104 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2105 initCursor(i, IMG_MENU_BUTTON);
2107 DrawCursorAndText_Info(i, FALSE);
2112 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2117 DrawMaskedBorder(fade_mask);
2124 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2126 static int choice_store[MAX_INFO_MODES];
2127 int choice = choice_store[info_mode]; /* always starts with 0 */
2131 if (button == MB_MENU_INITIALIZE)
2133 /* advance to first valid menu entry */
2134 while (choice < num_info_info &&
2135 info_info[choice].type & TYPE_SKIP_ENTRY)
2137 choice_store[info_mode] = choice;
2139 DrawCursorAndText_Info(choice, TRUE);
2143 else if (button == MB_MENU_LEAVE)
2145 for (y = 0; y < num_info_info; y++)
2147 if (info_info[y].type & TYPE_LEAVE_MENU)
2149 void (*menu_callback_function)(void) = info_info[y].value;
2153 menu_callback_function();
2155 break; /* absolutely needed because function changes 'info_info'! */
2162 if (mx || my) /* mouse input */
2164 x = (mx - mSX) / 32;
2165 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2167 else if (dx || dy) /* keyboard input */
2171 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2173 if (info_info[choice].type & menu_navigation_type ||
2174 info_info[choice].type & TYPE_ENTER_SCREEN ||
2175 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2176 info_info[choice].type & TYPE_YES_NO_AUTO)
2177 button = MB_MENU_CHOICE;
2182 /* jump to next non-empty menu entry (up or down) */
2183 while (y > 0 && y < num_info_info - 1 &&
2184 info_info[y].type & TYPE_SKIP_ENTRY)
2188 if (IN_VIS_FIELD(x, y) &&
2189 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2195 PlaySound(SND_MENU_ITEM_ACTIVATING);
2197 DrawCursorAndText_Info(choice, FALSE);
2198 DrawCursorAndText_Info(y, TRUE);
2200 choice = choice_store[info_mode] = y;
2203 else if (!(info_info[y].type & TYPE_GHOSTED))
2205 PlaySound(SND_MENU_ITEM_SELECTING);
2207 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2209 void (*menu_callback_function)(void) = info_info[choice].value;
2211 FadeSetFromType(info_info[y].type);
2213 menu_callback_function();
2219 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2221 int ystart1 = mSY - SY + 100;
2222 int ystart2 = mSY - SY + 150;
2223 int ybottom = mSY - SY + SYSIZE - 20;
2225 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2227 FadeOut(REDRAW_FIELD);
2232 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2233 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2235 DrawTextSCentered(ybottom, FONT_TEXT_4,
2236 "Press any key or button for info menu");
2238 FadeIn(REDRAW_FIELD);
2241 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2243 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2244 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2245 int xstart = mSX + 16;
2246 int ystart1 = mSY - SY + 100;
2247 int ystart2 = mSY + 64 + 2 * 32;
2248 int ybottom = mSY - SY + SYSIZE - 20;
2249 int ystep = TILEY + 4;
2250 int element, action, direction;
2258 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2259 infoscreen_step[i] = infoscreen_frame[i] = 0;
2264 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2266 DrawTextSCentered(ybottom, FONT_TEXT_4,
2267 "Press any key or button for next page");
2273 while (helpanim_info[j].element != HELPANIM_LIST_END)
2275 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2280 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2289 j += infoscreen_step[i - start];
2291 element = helpanim_info[j].element;
2292 action = helpanim_info[j].action;
2293 direction = helpanim_info[j].direction;
2296 element = EL_UNKNOWN;
2298 if (action != -1 && direction != -1)
2299 graphic = el_act_dir2img(element, action, direction);
2300 else if (action != -1)
2301 graphic = el_act2img(element, action);
2302 else if (direction != -1)
2303 graphic = el_dir2img(element, direction);
2305 graphic = el2img(element);
2307 delay = helpanim_info[j++].delay;
2312 if (infoscreen_frame[i - start] == 0)
2315 infoscreen_frame[i - start] = delay - 1;
2319 sync_frame = delay - infoscreen_frame[i - start];
2320 infoscreen_frame[i - start]--;
2323 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2325 if (!infoscreen_frame[i - start])
2326 infoscreen_step[i - start] = 0;
2330 if (!infoscreen_frame[i - start])
2331 infoscreen_step[i - start]++;
2332 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2338 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2340 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2341 graphic, sync_frame, USE_MASKING);
2344 DrawInfoScreen_HelpText(element, action, direction, i - start);
2349 redraw_mask |= REDRAW_FIELD;
2354 static char *getHelpText(int element, int action, int direction)
2356 char token[MAX_LINE_LEN];
2358 strcpy(token, element_info[element].token_name);
2361 strcat(token, element_action_info[action].suffix);
2363 if (direction != -1)
2364 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2366 return getHashEntry(helptext_info, token);
2369 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2371 int font_nr = FONT_INFO_ELEMENTS;
2372 int font_width = getFontWidth(font_nr);
2373 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2374 int sy = mSY + 65 + 2 * 32 + 1;
2375 int ystep = TILEY + 4;
2376 int pad_x = sx - SX;
2377 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2378 int max_lines_per_text = 2;
2381 if (action != -1 && direction != -1) /* element.action.direction */
2382 text = getHelpText(element, action, direction);
2384 if (text == NULL && action != -1) /* element.action */
2385 text = getHelpText(element, action, -1);
2387 if (text == NULL && direction != -1) /* element.direction */
2388 text = getHelpText(element, -1, direction);
2390 if (text == NULL) /* base element */
2391 text = getHelpText(element, -1, -1);
2393 if (text == NULL) /* not found */
2394 text = "No description available";
2396 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2397 sy += getFontHeight(font_nr) / 2;
2399 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2400 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2401 TRUE, FALSE, FALSE);
2404 void DrawInfoScreen_TitleScreen()
2409 void HandleInfoScreen_TitleScreen(int button)
2411 HandleTitleScreen(0, 0, 0, 0, button);
2414 void DrawInfoScreen_Elements()
2416 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2418 FadeOut(REDRAW_FIELD);
2423 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2425 FadeIn(REDRAW_FIELD);
2430 void HandleInfoScreen_Elements(int button)
2432 static unsigned int info_delay = 0;
2433 static int num_anims;
2434 static int num_pages;
2436 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2439 if (button == MB_MENU_INITIALIZE)
2441 boolean new_element = TRUE;
2445 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2447 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2449 else if (new_element)
2452 new_element = FALSE;
2456 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2460 if (button == MB_MENU_LEAVE)
2462 PlaySound(SND_MENU_ITEM_SELECTING);
2464 info_mode = INFO_MODE_MAIN;
2469 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2471 if (button != MB_MENU_INITIALIZE)
2473 PlaySound(SND_MENU_ITEM_SELECTING);
2478 if (page >= num_pages)
2480 FadeSoundsAndMusic();
2482 info_mode = INFO_MODE_MAIN;
2483 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2490 FadeSetNextScreen();
2493 if (button != MB_MENU_INITIALIZE)
2494 FadeOut(REDRAW_FIELD);
2496 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2498 if (button != MB_MENU_INITIALIZE)
2499 FadeIn(REDRAW_FIELD);
2503 if (DelayReached(&info_delay, GameFrameDelay))
2504 if (page < num_pages)
2505 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2507 PlayMenuSoundIfLoop();
2511 void DrawInfoScreen_Music()
2513 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2516 FadeOut(REDRAW_FIELD);
2524 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2527 FadeIn(REDRAW_FIELD);
2531 void HandleInfoScreen_Music(int button)
2533 static struct MusicFileInfo *list = NULL;
2534 int ystart1 = mSY - SY + 100;
2535 int ystart2 = mSY - SY + 150;
2536 int ybottom = mSY - SY + SYSIZE - 20;
2539 if (button == MB_MENU_INITIALIZE)
2541 list = music_file_info;
2545 FadeSoundsAndMusic();
2550 DrawTextSCentered(ystart1, FONT_TEXT_1,
2551 "No music info for this level set.");
2553 DrawTextSCentered(ybottom, FONT_TEXT_4,
2554 "Press any key or button for info menu");
2560 if (button == MB_MENU_LEAVE)
2562 PlaySound(SND_MENU_ITEM_SELECTING);
2564 FadeSoundsAndMusic();
2566 info_mode = INFO_MODE_MAIN;
2571 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2575 if (button != MB_MENU_INITIALIZE)
2577 PlaySound(SND_MENU_ITEM_SELECTING);
2585 FadeSoundsAndMusic();
2587 info_mode = INFO_MODE_MAIN;
2588 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2593 FadeSoundsAndMusic();
2596 if (list != music_file_info)
2597 FadeSetNextScreen();
2600 if (button != MB_MENU_INITIALIZE)
2601 FadeOut(REDRAW_FIELD);
2608 int sound = list->music;
2610 if (sound_info[sound].loop)
2611 PlaySoundLoop(sound);
2615 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2619 PlayMusic(list->music);
2621 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2624 if (!strEqual(list->title, UNKNOWN_NAME))
2626 if (!strEqual(list->title_header, UNKNOWN_NAME))
2627 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2629 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2632 if (!strEqual(list->artist, UNKNOWN_NAME))
2634 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2635 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2637 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2639 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2642 if (!strEqual(list->album, UNKNOWN_NAME))
2644 if (!strEqual(list->album_header, UNKNOWN_NAME))
2645 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2647 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2649 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2652 if (!strEqual(list->year, UNKNOWN_NAME))
2654 if (!strEqual(list->year_header, UNKNOWN_NAME))
2655 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2657 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2659 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2662 DrawTextSCentered(ybottom, FONT_TEXT_4,
2663 "Press any key or button for next page");
2665 if (button != MB_MENU_INITIALIZE)
2666 FadeIn(REDRAW_FIELD);
2669 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2670 PlaySoundLoop(list->music);
2673 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2675 int ystart1 = mSY - SY + 100;
2676 int ystart2 = mSY - SY + 150;
2677 int ybottom = mSY - SY + SYSIZE - 20;
2683 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2687 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2688 "Special thanks to");
2689 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2691 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2693 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2694 "\"Boulder Dash\"");
2695 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2697 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2699 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2701 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2702 "First Star Software");
2704 else if (screen_nr == 1)
2706 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2707 "Special thanks to");
2708 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2709 "Klaus Heinz & Volker Wertich");
2710 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2712 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2713 "\"Emerald Mine\"");
2714 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2716 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2718 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2720 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2723 else if (screen_nr == 2)
2725 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2726 "Special thanks to");
2727 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2728 "Michael Stopp & Philip Jespersen");
2729 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2731 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2733 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2735 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2737 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2739 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2740 "Digital Integration");
2742 else if (screen_nr == 3)
2744 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2745 "Special thanks to");
2746 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2747 "Hiroyuki Imabayashi");
2748 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2750 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2752 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2754 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2756 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2758 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2761 else if (screen_nr == 4)
2763 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2764 "Special thanks to");
2765 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2767 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2769 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2770 "Jürgen Bonhagen");
2771 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2772 "for the continuous creation");
2773 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2774 "of outstanding level sets");
2776 else if (screen_nr == 5)
2778 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2780 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2782 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2783 "for ideas and inspiration by");
2784 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2787 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2789 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2791 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2792 "for ideas and inspiration by");
2793 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2796 else if (screen_nr == 6)
2798 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2800 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2803 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2804 "for the code base used for the");
2805 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2806 "native Emerald Mine engine");
2808 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2809 "for the new Emerald Mine engine");
2812 else if (screen_nr == 7)
2814 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2816 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2818 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2819 "for the initial DOS port");
2821 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2823 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2825 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2826 "for some additional toons");
2828 else if (screen_nr == 8)
2830 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2831 "And not to forget:");
2832 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2834 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2835 "All those who contributed");
2836 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2837 "levels to this game");
2838 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2842 DrawTextSCentered(ybottom, FONT_TEXT_4,
2843 "Press any key or button for next page");
2846 void DrawInfoScreen_Credits()
2848 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2850 FadeSoundsAndMusic();
2853 FadeOut(REDRAW_FIELD);
2856 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2859 FadeIn(REDRAW_FIELD);
2863 void HandleInfoScreen_Credits(int button)
2865 static int screen_nr = 0;
2866 int num_screens = 9;
2868 if (button == MB_MENU_INITIALIZE)
2872 // DrawInfoScreen_CreditsScreen(screen_nr);
2875 if (button == MB_MENU_LEAVE)
2877 PlaySound(SND_MENU_ITEM_SELECTING);
2879 info_mode = INFO_MODE_MAIN;
2884 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2886 if (button != MB_MENU_INITIALIZE)
2888 PlaySound(SND_MENU_ITEM_SELECTING);
2893 if (screen_nr >= num_screens)
2895 FadeSoundsAndMusic();
2897 info_mode = INFO_MODE_MAIN;
2898 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2905 FadeSetNextScreen();
2908 if (button != MB_MENU_INITIALIZE)
2909 FadeOut(REDRAW_FIELD);
2911 DrawInfoScreen_CreditsScreen(screen_nr);
2913 if (button != MB_MENU_INITIALIZE)
2914 FadeIn(REDRAW_FIELD);
2918 PlayMenuSoundIfLoop();
2922 void DrawInfoScreen_Program()
2924 int ystart1 = mSY - SY + 100;
2925 int ystart2 = mSY - SY + 150;
2926 int ybottom = mSY - SY + SYSIZE - 20;
2929 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2932 FadeOut(REDRAW_FIELD);
2938 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2940 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2941 "This game is Freeware!");
2942 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2943 "If you like it, send e-mail to:");
2944 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2945 PROGRAM_EMAIL_STRING);
2947 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2948 "More information and levels:");
2949 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2950 PROGRAM_WEBSITE_STRING);
2951 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2952 "If you have created new levels,");
2953 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2954 "send them to me to include them!");
2955 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2958 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2959 "or SnailMail to:");
2960 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2962 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2963 "Detmolder Strasse 189");
2964 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2966 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2968 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2969 "More information and levels:");
2970 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2971 PROGRAM_WEBSITE_STRING);
2972 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2973 "If you have created new levels,");
2974 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2975 "send them to me to include them!");
2976 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2980 DrawTextSCentered(ybottom, FONT_TEXT_4,
2981 "Press any key or button for info menu");
2984 FadeIn(REDRAW_FIELD);
2988 void HandleInfoScreen_Program(int button)
2990 if (button == MB_MENU_LEAVE)
2992 PlaySound(SND_MENU_ITEM_SELECTING);
2994 info_mode = INFO_MODE_MAIN;
2999 else if (button == MB_MENU_CHOICE)
3001 PlaySound(SND_MENU_ITEM_SELECTING);
3003 FadeSoundsAndMusic();
3006 FadeOut(REDRAW_FIELD);
3009 info_mode = INFO_MODE_MAIN;
3010 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3014 PlayMenuSoundIfLoop();
3018 void DrawInfoScreen_Version()
3020 int font_header = FONT_TEXT_3;
3021 int font_text = FONT_TEXT_2;
3022 int xstep = getFontWidth(font_text);
3023 int ystep = getFontHeight(font_text);
3024 int ystart1 = mSY - SY + 100;
3025 int ystart2 = mSY - SY + 150;
3026 int ybottom = mSY - SY + SYSIZE - 20;
3027 int xstart1 = mSX - SX + 2 * xstep;
3028 int xstart2 = mSX - SX + 18 * xstep;
3029 #if defined(TARGET_SDL)
3030 int xstart3 = mSX - SX + 28 * xstep;
3031 SDL_version sdl_version_compiled;
3032 const SDL_version *sdl_version_linked;
3033 int driver_name_len = 10;
3034 #if defined(TARGET_SDL2)
3035 SDL_version sdl_version_linked_ext;
3036 const char *driver_name = NULL;
3038 char driver_name[driver_name_len];
3042 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3045 FadeOut(REDRAW_FIELD);
3051 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3053 DrawTextF(xstart1, ystart2, font_header, "Name");
3054 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3057 DrawTextF(xstart1, ystart2, font_header, "Version");
3058 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3061 DrawTextF(xstart1, ystart2, font_header, "Platform");
3062 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3065 DrawTextF(xstart1, ystart2, font_header, "Target");
3066 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3069 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3070 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3072 #if defined(TARGET_SDL)
3073 ystart2 += 3 * ystep;
3074 DrawTextF(xstart1, ystart2, font_header, "Library");
3075 DrawTextF(xstart2, ystart2, font_header, "compiled");
3076 DrawTextF(xstart3, ystart2, font_header, "linked");
3078 SDL_VERSION(&sdl_version_compiled);
3079 #if defined(TARGET_SDL2)
3080 SDL_GetVersion(&sdl_version_linked_ext);
3081 sdl_version_linked = &sdl_version_linked_ext;
3083 sdl_version_linked = SDL_Linked_Version();
3086 ystart2 += 2 * ystep;
3087 DrawTextF(xstart1, ystart2, font_text, "SDL");
3088 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3089 sdl_version_compiled.major,
3090 sdl_version_compiled.minor,
3091 sdl_version_compiled.patch);
3092 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3093 sdl_version_linked->major,
3094 sdl_version_linked->minor,
3095 sdl_version_linked->patch);
3097 SDL_IMAGE_VERSION(&sdl_version_compiled);
3098 sdl_version_linked = IMG_Linked_Version();
3101 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3102 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3103 sdl_version_compiled.major,
3104 sdl_version_compiled.minor,
3105 sdl_version_compiled.patch);
3106 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3107 sdl_version_linked->major,
3108 sdl_version_linked->minor,
3109 sdl_version_linked->patch);
3111 SDL_MIXER_VERSION(&sdl_version_compiled);
3112 sdl_version_linked = Mix_Linked_Version();
3115 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3116 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3117 sdl_version_compiled.major,
3118 sdl_version_compiled.minor,
3119 sdl_version_compiled.patch);
3120 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3121 sdl_version_linked->major,
3122 sdl_version_linked->minor,
3123 sdl_version_linked->patch);
3125 SDL_NET_VERSION(&sdl_version_compiled);
3126 sdl_version_linked = SDLNet_Linked_Version();
3129 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3130 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3131 sdl_version_compiled.major,
3132 sdl_version_compiled.minor,
3133 sdl_version_compiled.patch);
3134 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3135 sdl_version_linked->major,
3136 sdl_version_linked->minor,
3137 sdl_version_linked->patch);
3139 ystart2 += 3 * ystep;
3140 DrawTextF(xstart1, ystart2, font_header, "Driver");
3141 DrawTextF(xstart2, ystart2, font_header, "Requested");
3142 DrawTextF(xstart3, ystart2, font_header, "Used");
3144 #if defined(TARGET_SDL2)
3145 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3147 SDL_VideoDriverName(driver_name, driver_name_len);
3150 ystart2 += 2 * ystep;
3151 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3152 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3153 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3155 #if defined(TARGET_SDL2)
3156 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3158 SDL_AudioDriverName(driver_name, driver_name_len);
3162 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3163 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3164 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3167 DrawTextSCentered(ybottom, FONT_TEXT_4,
3168 "Press any key or button for info menu");
3171 FadeIn(REDRAW_FIELD);
3175 void HandleInfoScreen_Version(int button)
3177 if (button == MB_MENU_LEAVE)
3179 PlaySound(SND_MENU_ITEM_SELECTING);
3181 info_mode = INFO_MODE_MAIN;
3186 else if (button == MB_MENU_CHOICE)
3188 PlaySound(SND_MENU_ITEM_SELECTING);
3190 FadeSoundsAndMusic();
3193 FadeOut(REDRAW_FIELD);
3196 info_mode = INFO_MODE_MAIN;
3197 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3201 PlayMenuSoundIfLoop();
3205 void DrawInfoScreen_LevelSet()
3207 struct TitleMessageInfo *tmi = &readme;
3208 char *filename = getLevelSetInfoFilename();
3210 /* if chars set to "-1", automatically determine by text and font width */
3211 if (tmi->chars == -1)
3212 tmi->chars = tmi->width / getFontWidth(tmi->font);
3214 tmi->width = tmi->chars * getFontWidth(tmi->font);
3216 /* if lines set to "-1", automatically determine by text and font height */
3217 if (tmi->lines == -1)
3218 tmi->lines = tmi->height / getFontHeight(tmi->font);
3220 tmi->height = tmi->lines * getFontHeight(tmi->font);
3222 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3225 FadeOut(REDRAW_FIELD);
3231 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3233 if (filename != NULL)
3234 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3235 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3236 tmi->autowrap, tmi->centered, tmi->parse_comments);
3238 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3239 "No information for this level set.");
3241 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3242 "Press any key or button for info menu");
3245 FadeIn(REDRAW_FIELD);
3249 void HandleInfoScreen_LevelSet(int button)
3251 if (button == MB_MENU_LEAVE)
3253 PlaySound(SND_MENU_ITEM_SELECTING);
3255 info_mode = INFO_MODE_MAIN;
3260 else if (button == MB_MENU_CHOICE)
3262 PlaySound(SND_MENU_ITEM_SELECTING);
3264 FadeSoundsAndMusic();
3267 FadeOut(REDRAW_FIELD);
3270 info_mode = INFO_MODE_MAIN;
3271 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3275 PlayMenuSoundIfLoop();
3279 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3281 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3283 if (info_mode == INFO_MODE_TITLE)
3284 DrawInfoScreen_TitleScreen();
3285 else if (info_mode == INFO_MODE_ELEMENTS)
3286 DrawInfoScreen_Elements();
3287 else if (info_mode == INFO_MODE_MUSIC)
3288 DrawInfoScreen_Music();
3289 else if (info_mode == INFO_MODE_CREDITS)
3290 DrawInfoScreen_Credits();
3291 else if (info_mode == INFO_MODE_PROGRAM)
3292 DrawInfoScreen_Program();
3293 else if (info_mode == INFO_MODE_VERSION)
3294 DrawInfoScreen_Version();
3295 else if (info_mode == INFO_MODE_LEVELSET)
3296 DrawInfoScreen_LevelSet();
3298 DrawInfoScreen_Main(fade_mask, do_fading);
3300 if (info_mode != INFO_MODE_MAIN &&
3301 info_mode != INFO_MODE_TITLE &&
3302 info_mode != INFO_MODE_MUSIC)
3309 void DrawAndFadeInInfoScreen(int fade_mask)
3311 DrawInfoScreenExt(fade_mask, TRUE);
3314 void DrawInfoScreen()
3316 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3319 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3321 if (info_mode == INFO_MODE_TITLE)
3322 HandleInfoScreen_TitleScreen(button);
3323 else if (info_mode == INFO_MODE_ELEMENTS)
3324 HandleInfoScreen_Elements(button);
3325 else if (info_mode == INFO_MODE_MUSIC)
3326 HandleInfoScreen_Music(button);
3327 else if (info_mode == INFO_MODE_CREDITS)
3328 HandleInfoScreen_Credits(button);
3329 else if (info_mode == INFO_MODE_PROGRAM)
3330 HandleInfoScreen_Program(button);
3331 else if (info_mode == INFO_MODE_VERSION)
3332 HandleInfoScreen_Version(button);
3333 else if (info_mode == INFO_MODE_LEVELSET)
3334 HandleInfoScreen_LevelSet(button);
3336 HandleInfoScreen_Main(mx, my, dx, dy, button);
3344 /* ========================================================================= */
3345 /* type name functions */
3346 /* ========================================================================= */
3348 void HandleTypeName(int newxpos, Key key)
3350 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3351 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3352 struct TextPosInfo *pos = mci->pos_input;
3353 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3354 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3355 static int xpos = 0;
3356 int font_nr = pos->font;
3357 int font_active_nr = FONT_ACTIVE(font_nr);
3358 int font_width = getFontWidth(font_active_nr);
3359 char key_char = getValidConfigValueChar(getCharFromKey(key));
3360 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3361 boolean is_active = TRUE;
3363 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3367 strcpy(last_player_name, setup.player_name);
3371 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3373 setup.player_name[xpos] = key_char;
3374 setup.player_name[xpos + 1] = 0;
3378 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3382 setup.player_name[xpos] = 0;
3384 else if (key == KSYM_Return && xpos > 0)
3390 game_status = GAME_MODE_MAIN;
3392 else if (key == KSYM_Escape)
3394 strcpy(setup.player_name, last_player_name);
3398 game_status = GAME_MODE_MAIN;
3403 pos->width = (strlen(setup.player_name) + 1) * font_width;
3404 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3406 DrawText(startx, starty, setup.player_name, font_active_nr);
3407 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3411 pos->width = strlen(setup.player_name) * font_width;
3412 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3414 DrawText(startx, starty, setup.player_name, font_nr);
3419 /* ========================================================================= */
3420 /* tree menu functions */
3421 /* ========================================================================= */
3423 static void DrawChooseTree(TreeInfo **ti_ptr)
3427 FreeScreenGadgets();
3428 CreateScreenGadgets();
3430 CloseDoor(DOOR_CLOSE_2);
3433 FadeOut(REDRAW_FIELD);
3438 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3439 MapScreenTreeGadgets(*ti_ptr);
3442 FadeIn(REDRAW_FIELD);
3448 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3450 struct GadgetInfo *gi = screen_gadget[id];
3451 int items_max, items_visible, item_position;
3453 items_max = numTreeInfoInGroup(ti);
3454 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3455 item_position = first_entry;
3457 if (item_position > items_max - items_visible)
3458 item_position = items_max - items_visible;
3460 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3461 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3462 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3465 static void drawChooseTreeList(int first_entry, int num_page_entries,
3469 char *title_string = NULL;
3470 int yoffset_sets = MENU_TITLE1_YPOS;
3471 int yoffset_setup = 16;
3472 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3473 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3474 int last_game_status = game_status; /* save current game status */
3476 title_string = ti->infotext;
3478 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3481 /* force LEVELS font on artwork setup screen */
3482 game_status = GAME_MODE_LEVELS;
3486 /* clear tree list area, but not title or scrollbar */
3487 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3488 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3489 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3491 /* clear tree list area, but not title or scrollbar */
3492 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3493 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3494 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3497 for (i = 0; i < num_page_entries; i++)
3499 TreeInfo *node, *node_first;
3500 int entry_pos = first_entry + i;
3501 int xpos = MENU_SCREEN_START_XPOS;
3502 int ypos = MENU_SCREEN_START_YPOS + i;
3503 int startx = mSX + xpos * 32;
3504 int starty = mSY + ypos * 32;
3505 int font_nr = FONT_TEXT_1;
3506 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3507 int startx_text = startx + font_xoffset;
3508 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3509 int text_size = startx_scrollbar - startx_text;
3510 int max_buffer_len = text_size / getFontWidth(font_nr);
3511 char buffer[max_buffer_len + 1];
3513 node_first = getTreeInfoFirstGroupEntry(ti);
3514 node = getTreeInfoFromPos(node_first, entry_pos);
3516 strncpy(buffer, node->name, max_buffer_len);
3517 buffer[max_buffer_len] = '\0';
3519 DrawText(startx, starty, buffer, font_nr + node->color);
3521 if (node->parent_link)
3522 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3523 else if (node->level_group)
3524 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3526 initCursor(i, IMG_MENU_BUTTON);
3529 game_status = last_game_status; /* restore current game status */
3531 redraw_mask |= REDRAW_FIELD;
3534 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3536 TreeInfo *node, *node_first;
3537 int x, last_redraw_mask = redraw_mask;
3538 int ypos = MENU_TITLE2_YPOS;
3539 int font_nr = FONT_TITLE_2;
3541 if (ti->type == TREE_TYPE_LEVEL_NR)
3542 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3544 if (ti->type != TREE_TYPE_LEVEL_DIR)
3547 node_first = getTreeInfoFirstGroupEntry(ti);
3548 node = getTreeInfoFromPos(node_first, entry_pos);
3550 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3553 if (node->parent_link)
3554 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3555 node->node_parent->name);
3556 else if (node->level_group)
3557 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3559 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3560 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3561 node->levels, (node->levels > 1 ? "levels" : "level"),
3564 if (node->parent_link)
3565 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3567 else if (node->level_group)
3568 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3570 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3571 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3572 node->levels, node->class_desc);
3575 /* let BackToFront() redraw only what is needed */
3576 redraw_mask = last_redraw_mask | REDRAW_TILES;
3577 for (x = 0; x < SCR_FIELDX; x++)
3578 MarkTileDirty(x, 1);
3581 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3584 TreeInfo *ti = *ti_ptr;
3586 int y = ti->cl_cursor;
3587 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3588 int num_entries = numTreeInfoInGroup(ti);
3589 int num_page_entries;
3590 int last_game_status = game_status; /* save current game status */
3591 boolean position_set_by_scrollbar = (dx == 999);
3594 /* force LEVELS draw offset on choose level and artwork setup screen */
3595 game_status = GAME_MODE_LEVELS;
3598 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3599 num_page_entries = num_entries;
3601 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3603 game_status = last_game_status; /* restore current game status */
3605 if (button == MB_MENU_INITIALIZE)
3607 int num_entries = numTreeInfoInGroup(ti);
3608 int entry_pos = posTreeInfo(ti);
3610 if (ti->cl_first == -1)
3612 /* only on initialization */
3613 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3614 ti->cl_cursor = entry_pos - ti->cl_first;
3616 else if (ti->cl_cursor >= num_page_entries ||
3617 (num_entries > num_page_entries &&
3618 num_entries - ti->cl_first < num_page_entries))
3620 /* only after change of list size (by custom graphic configuration) */
3621 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3622 ti->cl_cursor = entry_pos - ti->cl_first;
3625 if (position_set_by_scrollbar)
3628 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3631 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3632 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3633 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3637 else if (button == MB_MENU_LEAVE)
3641 PlaySound(SND_MENU_ITEM_SELECTING);
3643 if (ti->node_parent)
3645 *ti_ptr = ti->node_parent;
3646 DrawChooseTree(ti_ptr);
3648 else if (game_status == GAME_MODE_SETUP)
3650 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3651 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3653 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3654 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3655 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3656 execSetupGraphics();
3657 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3658 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3659 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3666 if (game_status == GAME_MODE_LEVELNR)
3667 level_nr = atoi(level_number_current->identifier);
3669 game_status = GAME_MODE_MAIN;
3671 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3677 if (mx || my) /* mouse input */
3679 int last_game_status = game_status; /* save current game status */
3682 /* force LEVELS draw offset on artwork setup screen */
3683 game_status = GAME_MODE_LEVELS;
3686 x = (mx - mSX) / 32;
3687 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3689 game_status = last_game_status; /* restore current game status */
3691 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3693 /* move cursor instead of scrolling when already at start/end of list */
3694 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3696 else if (dy == +1 * SCROLL_LINE &&
3697 ti->cl_first + num_page_entries == num_entries)
3700 /* handle scrolling screen one line or page */
3701 if (ti->cl_cursor + dy < 0 ||
3702 ti->cl_cursor + dy > num_page_entries - 1)
3704 if (ABS(dy) == SCROLL_PAGE)
3705 step = num_page_entries - 1;
3707 if (dy < 0 && ti->cl_first > 0)
3709 /* scroll page/line up */
3711 ti->cl_first -= step;
3712 if (ti->cl_first < 0)
3715 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3716 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3717 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3719 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3722 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3724 /* scroll page/line down */
3726 ti->cl_first += step;
3727 if (ti->cl_first + num_page_entries > num_entries)
3728 ti->cl_first = MAX(0, num_entries - num_page_entries);
3730 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3731 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3732 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3734 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3741 /* handle moving cursor one line */
3742 y = ti->cl_cursor + dy;
3747 TreeInfo *node_first, *node_cursor;
3748 int entry_pos = ti->cl_first + y;
3750 node_first = getTreeInfoFirstGroupEntry(ti);
3751 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3753 if (node_cursor->node_group)
3757 PlaySound(SND_MENU_ITEM_SELECTING);
3759 node_cursor->cl_first = ti->cl_first;
3760 node_cursor->cl_cursor = ti->cl_cursor;
3761 *ti_ptr = node_cursor->node_group;
3762 DrawChooseTree(ti_ptr);
3767 else if (dx == -1 && ti->node_parent)
3771 PlaySound(SND_MENU_ITEM_SELECTING);
3773 *ti_ptr = ti->node_parent;
3774 DrawChooseTree(ti_ptr);
3779 if (!anyScrollbarGadgetActive() &&
3780 IN_VIS_FIELD(x, y) &&
3781 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3782 y >= 0 && y < num_page_entries)
3786 if (y != ti->cl_cursor)
3788 PlaySound(SND_MENU_ITEM_ACTIVATING);
3790 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3791 drawChooseTreeCursor(y, TRUE);
3792 drawChooseTreeInfo(ti->cl_first + y, ti);
3799 TreeInfo *node_first, *node_cursor;
3800 int entry_pos = ti->cl_first + y;
3802 PlaySound(SND_MENU_ITEM_SELECTING);
3804 node_first = getTreeInfoFirstGroupEntry(ti);
3805 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3807 if (node_cursor->node_group)
3811 node_cursor->cl_first = ti->cl_first;
3812 node_cursor->cl_cursor = ti->cl_cursor;
3813 *ti_ptr = node_cursor->node_group;
3814 DrawChooseTree(ti_ptr);
3816 else if (node_cursor->parent_link)
3820 *ti_ptr = node_cursor->node_parent;
3821 DrawChooseTree(ti_ptr);
3828 FadeSetEnterScreen();
3831 node_cursor->cl_first = ti->cl_first;
3832 node_cursor->cl_cursor = ti->cl_cursor;
3833 *ti_ptr = node_cursor;
3835 if (ti->type == TREE_TYPE_LEVEL_DIR)
3837 LoadLevelSetup_SeriesInfo();
3839 SaveLevelSetup_LastSeries();
3840 SaveLevelSetup_SeriesInfo();
3844 if (game_status == GAME_MODE_SETUP)
3846 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3847 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3849 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3850 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3851 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3852 execSetupGraphics();
3853 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3854 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3855 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3862 if (game_status == GAME_MODE_LEVELNR)
3863 level_nr = atoi(level_number_current->identifier);
3865 game_status = GAME_MODE_MAIN;
3874 void DrawChooseLevelSet()
3876 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3878 DrawChooseTree(&leveldir_current);
3884 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3886 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3893 void DrawChooseLevelNr()
3897 if (level_number != NULL)
3899 freeTreeInfo(level_number);
3901 level_number = NULL;
3904 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3906 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3907 char identifier[32], name[32];
3910 /* temporarily load level info to get level name */
3911 LoadLevelInfoOnly(i);
3913 ti->node_top = &level_number;
3914 ti->sort_priority = 10000 + value;
3915 ti->color = (level.no_valid_file ? FC_BLUE :
3916 LevelStats_getSolved(i) ? FC_GREEN :
3917 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3919 sprintf(identifier, "%d", value);
3920 sprintf(name, "%03d: %s", value,
3921 (level.no_valid_file ? "(no file)" : level.name));
3923 setString(&ti->identifier, identifier);
3924 setString(&ti->name, name);
3925 setString(&ti->name_sorting, name);
3927 pushTreeInfo(&level_number, ti);
3930 /* sort level number values to start with lowest level number */
3931 sortTreeInfo(&level_number);
3933 /* set current level number to current level number */
3934 level_number_current =
3935 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3937 /* if that also fails, set current level number to first available level */
3938 if (level_number_current == NULL)
3939 level_number_current = level_number;
3941 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3944 DrawChooseTree(&level_number_current);
3946 DrawChooseTree(&leveldir_current);
3953 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3956 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3958 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3966 void DrawHallOfFame(int highlight_position)
3969 FadeSoundsAndMusic();
3971 /* (this is needed when called from GameEnd() after winning a game) */
3972 KeyboardAutoRepeatOn();
3975 /* (this is needed when called from GameEnd() after winning a game) */
3976 SetDrawDeactivationMask(REDRAW_NONE);
3977 SetDrawBackgroundMask(REDRAW_FIELD);
3979 CloseDoor(DOOR_CLOSE_2);
3981 if (highlight_position < 0)
3982 LoadScore(level_nr);
3984 FadeSetEnterScreen();
3986 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3989 FadeOut(REDRAW_FIELD);
3997 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4000 FadeIn(REDRAW_FIELD);
4004 static void drawHallOfFameList(int first_entry, int highlight_position)
4008 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4011 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4012 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4013 "HighScores of Level %d", level_nr);
4015 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4017 int entry = first_entry + i;
4018 boolean active = (entry == highlight_position);
4019 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4020 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4021 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4022 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4023 int dx1 = 3 * getFontWidth(font_nr1);
4024 int dx2 = dx1 + getFontWidth(font_nr1);
4025 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4026 int sy = mSY + 64 + i * 32;
4028 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4029 DrawText(mSX + dx1, sy, ".", font_nr1);
4030 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4032 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4033 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4035 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4038 redraw_mask |= REDRAW_FIELD;
4041 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4043 static int first_entry = 0;
4044 static int highlight_position = 0;
4045 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4047 if (button == MB_MENU_INITIALIZE)
4050 highlight_position = mx;
4051 drawHallOfFameList(first_entry, highlight_position);
4056 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4057 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4061 if (first_entry > 0)
4063 first_entry -= step;
4064 if (first_entry < 0)
4067 drawHallOfFameList(first_entry, highlight_position);
4072 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4074 first_entry += step;
4075 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4076 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4078 drawHallOfFameList(first_entry, highlight_position);
4081 else if (button == MB_MENU_LEAVE)
4083 PlaySound(SND_MENU_ITEM_SELECTING);
4085 FadeSound(SND_BACKGROUND_SCORES);
4087 game_status = GAME_MODE_MAIN;
4091 else if (button == MB_MENU_CHOICE)
4093 PlaySound(SND_MENU_ITEM_SELECTING);
4095 FadeSound(SND_BACKGROUND_SCORES);
4098 FadeOut(REDRAW_FIELD);
4101 game_status = GAME_MODE_MAIN;
4103 DrawAndFadeInMainMenu(REDRAW_FIELD);
4106 if (game_status == GAME_MODE_SCORES)
4107 PlayMenuSoundIfLoop();
4115 /* ========================================================================= */
4116 /* setup screen functions */
4117 /* ========================================================================= */
4119 static struct TokenInfo *setup_info;
4120 static int num_setup_info;
4122 static char *screen_mode_text;
4123 static char *window_size_text;
4124 static char *scaling_type_text;
4125 static char *scroll_delay_text;
4126 static char *game_speed_text;
4127 static char *graphics_set_name;
4128 static char *sounds_set_name;
4129 static char *music_set_name;
4130 static char *volume_simple_text;
4131 static char *volume_loops_text;
4132 static char *volume_music_text;
4134 static void execSetupMain()
4136 setup_mode = SETUP_MODE_MAIN;
4141 static void execSetupGame_setGameSpeeds()
4143 if (game_speeds == NULL)
4147 for (i = 0; game_speeds_list[i].value != -1; i++)
4149 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4150 char identifier[32], name[32];
4151 int value = game_speeds_list[i].value;
4152 char *text = game_speeds_list[i].text;
4154 ti->node_top = &game_speeds;
4155 ti->sort_priority = 10000 - value;
4157 sprintf(identifier, "%d", value);
4158 sprintf(name, "%s", text);
4160 setString(&ti->identifier, identifier);
4161 setString(&ti->name, name);
4162 setString(&ti->name_sorting, name);
4163 setString(&ti->infotext, "Game Speed");
4165 pushTreeInfo(&game_speeds, ti);
4168 /* sort game speed values to start with slowest game speed */
4169 sortTreeInfo(&game_speeds);
4171 /* set current game speed to configured game speed value */
4172 game_speed_current =
4173 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4175 /* if that fails, set current game speed to reliable default value */
4176 if (game_speed_current == NULL)
4177 game_speed_current =
4178 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4180 /* if that also fails, set current game speed to first available speed */
4181 if (game_speed_current == NULL)
4182 game_speed_current = game_speeds;
4185 setup.game_frame_delay = atoi(game_speed_current->identifier);
4187 /* needed for displaying game speed text instead of identifier */
4188 game_speed_text = game_speed_current->name;
4191 static void execSetupGame_setScrollDelays()
4193 if (scroll_delays == NULL)
4197 for (i = 0; scroll_delays_list[i].value != -1; i++)
4199 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4200 char identifier[32], name[32];
4201 int value = scroll_delays_list[i].value;
4202 char *text = scroll_delays_list[i].text;
4204 ti->node_top = &scroll_delays;
4205 ti->sort_priority = value;
4207 sprintf(identifier, "%d", value);
4208 sprintf(name, "%s", text);
4210 setString(&ti->identifier, identifier);
4211 setString(&ti->name, name);
4212 setString(&ti->name_sorting, name);
4213 setString(&ti->infotext, "Scaling Type");
4215 pushTreeInfo(&scroll_delays, ti);
4218 /* sort scaling type values to start with lowest scaling type value */
4219 sortTreeInfo(&scroll_delays);
4221 /* set current scaling type value to configured scaling type value */
4222 scroll_delay_current =
4223 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4225 /* if that fails, set current scaling type to reliable default value */
4226 if (scroll_delay_current == NULL)
4227 scroll_delay_current =
4228 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4230 /* if that also fails, set current scaling type to first available value */
4231 if (scroll_delay_current == NULL)
4232 scroll_delay_current = scroll_delays;
4235 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4237 /* needed for displaying scaling type text instead of identifier */
4238 scroll_delay_text = scroll_delay_current->name;
4241 static void execSetupGame()
4243 execSetupGame_setGameSpeeds();
4244 execSetupGame_setScrollDelays();
4246 setup_mode = SETUP_MODE_GAME;
4251 static void execSetupChooseGameSpeed()
4253 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4258 static void execSetupChooseScrollDelay()
4260 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4265 static void execSetupEditor()
4267 setup_mode = SETUP_MODE_EDITOR;
4272 static void execSetupGraphics_setWindowSizes(boolean update_list)
4274 if (window_sizes != NULL && update_list)
4276 freeTreeInfo(window_sizes);
4278 window_sizes = NULL;
4281 if (window_sizes == NULL)
4283 boolean current_window_size_found = FALSE;
4286 for (i = 0; window_sizes_list[i].value != -1; i++)
4288 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4289 char identifier[32], name[32];
4290 int value = window_sizes_list[i].value;
4291 char *text = window_sizes_list[i].text;
4293 ti->node_top = &window_sizes;
4294 ti->sort_priority = value;
4296 sprintf(identifier, "%d", value);
4297 sprintf(name, "%s", text);
4299 setString(&ti->identifier, identifier);
4300 setString(&ti->name, name);
4301 setString(&ti->name_sorting, name);
4302 setString(&ti->infotext, "Window Scaling");
4304 pushTreeInfo(&window_sizes, ti);
4306 if (value == setup.window_scaling_percent)
4307 current_window_size_found = TRUE;
4310 if (!current_window_size_found)
4312 // add entry for non-preset window scaling value
4314 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4315 char identifier[32], name[32];
4316 int value = setup.window_scaling_percent;
4318 ti->node_top = &window_sizes;
4319 ti->sort_priority = value;
4321 sprintf(identifier, "%d", value);
4322 sprintf(name, "%d %% (Current)", value);
4324 setString(&ti->identifier, identifier);
4325 setString(&ti->name, name);
4326 setString(&ti->name_sorting, name);
4327 setString(&ti->infotext, "Window Scaling");
4329 pushTreeInfo(&window_sizes, ti);
4332 /* sort window size values to start with lowest window size value */
4333 sortTreeInfo(&window_sizes);
4335 /* set current window size value to configured window size value */
4336 window_size_current =
4337 getTreeInfoFromIdentifier(window_sizes,
4338 i_to_a(setup.window_scaling_percent));
4340 /* if that fails, set current window size to reliable default value */
4341 if (window_size_current == NULL)
4342 window_size_current =
4343 getTreeInfoFromIdentifier(window_sizes,
4344 i_to_a(STD_WINDOW_SCALING_PERCENT));
4346 /* if that also fails, set current window size to first available value */
4347 if (window_size_current == NULL)
4348 window_size_current = window_sizes;
4351 setup.window_scaling_percent = atoi(window_size_current->identifier);
4353 /* needed for displaying window size text instead of identifier */
4354 window_size_text = window_size_current->name;
4357 static void execSetupGraphics_setScalingTypes()
4359 if (scaling_types == NULL)
4363 for (i = 0; scaling_types_list[i].value != NULL; i++)
4365 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4366 char identifier[32], name[32];
4367 char *value = scaling_types_list[i].value;
4368 char *text = scaling_types_list[i].text;
4370 ti->node_top = &scaling_types;
4371 ti->sort_priority = i;
4373 sprintf(identifier, "%s", value);
4374 sprintf(name, "%s", text);
4376 setString(&ti->identifier, identifier);
4377 setString(&ti->name, name);
4378 setString(&ti->name_sorting, name);
4379 setString(&ti->infotext, "Anti-Aliasing");
4381 pushTreeInfo(&scaling_types, ti);
4384 /* sort scaling type values to start with lowest scaling type value */
4385 sortTreeInfo(&scaling_types);
4387 /* set current scaling type value to configured scaling type value */
4388 scaling_type_current =
4389 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4391 /* if that fails, set current scaling type to reliable default value */
4392 if (scaling_type_current == NULL)
4393 scaling_type_current =
4394 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4396 /* if that also fails, set current scaling type to first available value */
4397 if (scaling_type_current == NULL)
4398 scaling_type_current = scaling_types;
4401 setup.window_scaling_quality = scaling_type_current->identifier;
4403 /* needed for displaying scaling type text instead of identifier */
4404 scaling_type_text = scaling_type_current->name;
4407 static void execSetupGraphics_setScreenModes()
4409 // if (screen_modes == NULL && video.fullscreen_available)
4410 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4414 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4416 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4417 char identifier[32], name[32];
4418 int x = video.fullscreen_modes[i].width;
4419 int y = video.fullscreen_modes[i].height;
4422 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4424 ti->node_top = &screen_modes;
4425 ti->sort_priority = x * 10000 + y;
4427 sprintf(identifier, "%dx%d", x, y);
4428 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4430 setString(&ti->identifier, identifier);
4431 setString(&ti->name, name);
4432 setString(&ti->name_sorting, name);
4433 setString(&ti->infotext, "Fullscreen Mode");
4435 pushTreeInfo(&screen_modes, ti);
4438 /* sort fullscreen modes to start with lowest available screen resolution */
4439 sortTreeInfo(&screen_modes);
4441 /* set current screen mode for fullscreen mode to configured setup value */
4442 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4443 setup.fullscreen_mode);
4445 /* if that fails, set current screen mode to reliable default value */
4446 if (screen_mode_current == NULL)
4447 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4448 DEFAULT_FULLSCREEN_MODE);
4450 /* if that also fails, set current screen mode to first available mode */
4451 if (screen_mode_current == NULL)
4452 screen_mode_current = screen_modes;
4454 if (screen_mode_current == NULL)
4455 video.fullscreen_available = FALSE;
4458 // if (video.fullscreen_available)
4459 if (screen_mode_current != NULL)
4461 setup.fullscreen_mode = screen_mode_current->identifier;
4463 /* needed for displaying screen mode name instead of identifier */
4464 screen_mode_text = screen_mode_current->name;
4468 static void execSetupGraphics()
4470 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4472 // update "setup.window_scaling_percent" from list selection
4473 execSetupGraphics_setWindowSizes(FALSE);
4477 // update list selection from "setup.window_scaling_percent"
4478 execSetupGraphics_setWindowSizes(TRUE);
4481 execSetupGraphics_setScalingTypes();
4482 execSetupGraphics_setScreenModes();
4484 setup_mode = SETUP_MODE_GRAPHICS;
4488 #if defined(TARGET_SDL2)
4489 // window scaling may have changed at this point
4490 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4492 // window scaling quality may have changed at this point
4493 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4494 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4498 #if !defined(PLATFORM_ANDROID)
4499 #if defined(TARGET_SDL2)
4500 static void execSetupChooseWindowSize()
4503 if (!video.window_scaling_available)
4507 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4512 static void execSetupChooseScalingType()
4514 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4519 static void execSetupChooseScreenMode()
4521 if (!video.fullscreen_available)
4524 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4531 static void execSetupChooseVolumeSimple()
4533 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4538 static void execSetupChooseVolumeLoops()
4540 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4545 static void execSetupChooseVolumeMusic()
4547 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4552 static void execSetupSound()
4555 if (volumes_simple == NULL)
4559 for (i = 0; volumes_list[i].value != -1; i++)
4561 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4562 char identifier[32], name[32];
4563 int value = volumes_list[i].value;
4564 char *text = volumes_list[i].text;
4566 ti->node_top = &volumes_simple;
4567 ti->sort_priority = value;
4569 sprintf(identifier, "%d", value);
4570 sprintf(name, "%s", text);
4572 setString(&ti->identifier, identifier);
4573 setString(&ti->name, name);
4574 setString(&ti->name_sorting, name);
4575 setString(&ti->infotext, "Sound Volume");
4577 pushTreeInfo(&volumes_simple, ti);
4580 /* sort volume values to start with lowest volume value */
4581 sortTreeInfo(&volumes_simple);
4583 /* set current volume value to configured volume value */
4584 volume_simple_current =
4585 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4587 /* if that fails, set current volume to reliable default value */
4588 if (volume_simple_current == NULL)
4589 volume_simple_current =
4590 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4592 /* if that also fails, set current volume to first available value */
4593 if (volume_simple_current == NULL)
4594 volume_simple_current = volumes_simple;
4597 if (volumes_loops == NULL)
4601 for (i = 0; volumes_list[i].value != -1; i++)
4603 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4604 char identifier[32], name[32];
4605 int value = volumes_list[i].value;
4606 char *text = volumes_list[i].text;
4608 ti->node_top = &volumes_loops;
4609 ti->sort_priority = value;
4611 sprintf(identifier, "%d", value);
4612 sprintf(name, "%s", text);
4614 setString(&ti->identifier, identifier);
4615 setString(&ti->name, name);
4616 setString(&ti->name_sorting, name);
4617 setString(&ti->infotext, "Loops Volume");
4619 pushTreeInfo(&volumes_loops, ti);
4622 /* sort volume values to start with lowest volume value */
4623 sortTreeInfo(&volumes_loops);
4625 /* set current volume value to configured volume value */
4626 volume_loops_current =
4627 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4629 /* if that fails, set current volume to reliable default value */
4630 if (volume_loops_current == NULL)
4631 volume_loops_current =
4632 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4634 /* if that also fails, set current volume to first available value */
4635 if (volume_loops_current == NULL)
4636 volume_loops_current = volumes_loops;
4639 if (volumes_music == NULL)
4643 for (i = 0; volumes_list[i].value != -1; i++)
4645 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4646 char identifier[32], name[32];
4647 int value = volumes_list[i].value;
4648 char *text = volumes_list[i].text;
4650 ti->node_top = &volumes_music;
4651 ti->sort_priority = value;
4653 sprintf(identifier, "%d", value);
4654 sprintf(name, "%s", text);
4656 setString(&ti->identifier, identifier);
4657 setString(&ti->name, name);
4658 setString(&ti->name_sorting, name);
4659 setString(&ti->infotext, "Music Volume");
4661 pushTreeInfo(&volumes_music, ti);
4664 /* sort volume values to start with lowest volume value */
4665 sortTreeInfo(&volumes_music);
4667 /* set current volume value to configured volume value */
4668 volume_music_current =
4669 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4671 /* if that fails, set current volume to reliable default value */
4672 if (volume_music_current == NULL)
4673 volume_music_current =
4674 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4676 /* if that also fails, set current volume to first available value */
4677 if (volume_music_current == NULL)
4678 volume_music_current = volumes_music;
4681 setup.volume_simple = atoi(volume_simple_current->identifier);
4682 setup.volume_loops = atoi(volume_loops_current->identifier);
4683 setup.volume_music = atoi(volume_music_current->identifier);
4685 /* needed for displaying volume text instead of identifier */
4686 volume_simple_text = volume_simple_current->name;
4687 volume_loops_text = volume_loops_current->name;
4688 volume_music_text = volume_music_current->name;
4691 setup_mode = SETUP_MODE_SOUND;
4696 static void execSetupArtwork()
4699 printf("::: '%s', '%s', '%s'\n",
4700 artwork.gfx_current->subdir,
4701 artwork.gfx_current->fullpath,
4702 artwork.gfx_current->basepath);
4705 setup.graphics_set = artwork.gfx_current->identifier;
4706 setup.sounds_set = artwork.snd_current->identifier;
4707 setup.music_set = artwork.mus_current->identifier;
4709 /* needed if last screen (setup choice) changed graphics, sounds or music */
4710 ReloadCustomArtwork(0);
4712 /* needed for displaying artwork name instead of artwork identifier */
4713 graphics_set_name = artwork.gfx_current->name;
4714 sounds_set_name = artwork.snd_current->name;
4715 music_set_name = artwork.mus_current->name;
4717 setup_mode = SETUP_MODE_ARTWORK;
4722 static void execSetupChooseGraphics()
4724 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4729 static void execSetupChooseSounds()
4731 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4736 static void execSetupChooseMusic()
4738 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4743 static void execSetupInput()
4745 setup_mode = SETUP_MODE_INPUT;
4750 static void execSetupShortcuts()
4752 setup_mode = SETUP_MODE_SHORTCUTS;
4757 static void execSetupShortcuts1()
4759 setup_mode = SETUP_MODE_SHORTCUTS_1;
4764 static void execSetupShortcuts2()
4766 setup_mode = SETUP_MODE_SHORTCUTS_2;
4771 static void execSetupShortcuts3()
4773 setup_mode = SETUP_MODE_SHORTCUTS_3;
4778 static void execSetupShortcuts4()
4780 setup_mode = SETUP_MODE_SHORTCUTS_4;
4785 static void execSetupShortcuts5()
4787 setup_mode = SETUP_MODE_SHORTCUTS_5;
4792 static void execExitSetup()
4794 game_status = GAME_MODE_MAIN;
4796 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4799 static void execSaveAndExitSetup()
4805 static struct TokenInfo setup_info_main[] =
4807 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4808 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4809 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4810 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4811 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4812 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4813 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4814 { TYPE_EMPTY, NULL, "" },
4815 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4816 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4821 static struct TokenInfo setup_info_game[] =
4823 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4824 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4825 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4826 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4827 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4828 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4829 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4830 { TYPE_STRING, &game_speed_text, "" },
4832 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4833 { TYPE_STRING, &scroll_delay_text, "" },
4835 { TYPE_EMPTY, NULL, "" },
4836 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4841 static struct TokenInfo setup_info_editor[] =
4844 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4845 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4846 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4847 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4848 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4849 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4850 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4851 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4853 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4854 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4855 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4857 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4859 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4860 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4861 { TYPE_EMPTY, NULL, "" },
4863 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4864 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4865 { TYPE_EMPTY, NULL, "" },
4867 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4868 { TYPE_EMPTY, NULL, "" },
4869 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4874 static struct TokenInfo setup_info_graphics[] =
4876 #if !defined(PLATFORM_ANDROID)
4877 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4878 #if defined(TARGET_SDL2)
4879 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4880 { TYPE_STRING, &window_size_text, "" },
4882 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4883 { TYPE_STRING, &scaling_type_text, "" },
4886 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4887 { TYPE_STRING, &screen_mode_text, "" },
4891 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4894 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4895 { TYPE_STRING, &scroll_delay_text, "" },
4898 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4900 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4901 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4902 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4903 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4904 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4905 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4906 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4907 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4908 { TYPE_EMPTY, NULL, "" },
4909 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4914 static struct TokenInfo setup_info_sound[] =
4916 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4917 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4918 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4919 { TYPE_EMPTY, NULL, "" },
4920 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4921 { TYPE_STRING, &volume_simple_text, "" },
4922 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4923 { TYPE_STRING, &volume_loops_text, "" },
4924 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4925 { TYPE_STRING, &volume_music_text, "" },
4926 { TYPE_EMPTY, NULL, "" },
4927 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4932 static struct TokenInfo setup_info_artwork[] =
4934 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4935 { TYPE_STRING, &graphics_set_name, "" },
4936 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4937 { TYPE_STRING, &sounds_set_name, "" },
4938 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4939 { TYPE_STRING, &music_set_name, "" },
4940 { TYPE_EMPTY, NULL, "" },
4943 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4944 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4945 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4947 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4948 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4949 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4950 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4953 { TYPE_STRING, NULL, "Override Level Artwork:"},
4954 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4955 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4956 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4958 { TYPE_EMPTY, NULL, "" },
4959 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4964 static struct TokenInfo setup_info_input[] =
4966 { TYPE_SWITCH, NULL, "Player:" },
4967 { TYPE_SWITCH, NULL, "Device:" },
4968 { TYPE_ENTER_MENU, 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_EMPTY, NULL, "" },
4978 { TYPE_EMPTY, NULL, "" },
4979 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4984 static struct TokenInfo setup_info_shortcuts[] =
4986 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4987 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4988 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4989 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4990 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4991 { TYPE_EMPTY, NULL, "" },
4992 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4997 static struct TokenInfo setup_info_shortcuts_1[] =
4999 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5000 { TYPE_KEY, &setup.shortcut.save_game, "" },
5001 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5002 { TYPE_KEY, &setup.shortcut.load_game, "" },
5003 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5004 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5005 { TYPE_EMPTY, NULL, "" },
5006 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5007 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5008 { TYPE_EMPTY, NULL, "" },
5009 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5014 static struct TokenInfo setup_info_shortcuts_2[] =
5016 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5017 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5018 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5019 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5020 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5021 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5022 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5023 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5024 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5025 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5026 { TYPE_EMPTY, NULL, "" },
5027 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5032 static struct TokenInfo setup_info_shortcuts_3[] =
5034 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5035 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5036 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5037 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5038 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5039 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5040 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5041 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5042 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5043 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5044 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5045 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5046 { TYPE_EMPTY, NULL, "" },
5047 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5052 static struct TokenInfo setup_info_shortcuts_4[] =
5054 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5055 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5056 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5057 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5058 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5059 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5060 { TYPE_EMPTY, NULL, "" },
5061 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5066 static struct TokenInfo setup_info_shortcuts_5[] =
5068 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5069 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5070 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5071 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5072 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5073 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5074 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5075 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5076 { TYPE_EMPTY, NULL, "" },
5077 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5082 static Key getSetupKey()
5084 Key key = KSYM_UNDEFINED;
5085 boolean got_key_event = FALSE;
5087 while (!got_key_event)
5089 if (PendingEvent()) /* got event */
5097 case EVENT_KEYPRESS:
5099 key = GetEventKey((KeyEvent *)&event, TRUE);
5101 /* press 'Escape' or 'Enter' to keep the existing key binding */
5102 if (key == KSYM_Escape || key == KSYM_Return)
5103 key = KSYM_UNDEFINED; /* keep old value */
5105 got_key_event = TRUE;
5109 case EVENT_KEYRELEASE:
5110 key_joystick_mapping = 0;
5114 HandleOtherEvents(&event);
5122 /* don't eat all CPU time */
5129 static int getSetupTextFont(int type)
5131 if (type & (TYPE_SWITCH |
5143 static int getSetupValueFont(int type, void *value)
5145 if (type & TYPE_KEY)
5146 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5147 else if (type & TYPE_STRING)
5148 return FONT_VALUE_2;
5149 else if (type & TYPE_ECS_AGA)
5150 return FONT_VALUE_1;
5151 else if (type & TYPE_BOOLEAN_STYLE)
5152 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5153 else if (type & TYPE_YES_NO_AUTO)
5154 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5155 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5157 return FONT_VALUE_1;
5160 static void drawSetupValue(int pos)
5162 boolean font_draw_xoffset_modified = FALSE;
5163 int font_draw_xoffset_old = -1;
5164 int xpos = MENU_SCREEN_VALUE_XPOS;
5165 int ypos = MENU_SCREEN_START_YPOS + pos;
5166 int startx = mSX + xpos * 32;
5167 int starty = mSY + ypos * 32;
5168 int font_nr, font_width;
5172 int type = setup_info[pos].type;
5173 void *value = setup_info[pos].value;
5174 char *value_string = getSetupValue(type, value);
5179 if (value_string == NULL)
5182 if (type & TYPE_KEY)
5184 xpos = MENU_SCREEN_START_XPOS;
5186 if (type & TYPE_QUERY)
5187 value_string = "<press key>";
5189 else if (type & TYPE_STRING)
5191 int max_value_len = (SCR_FIELDX - 2) * 2;
5193 xpos = MENU_SCREEN_START_XPOS;
5195 if (strlen(value_string) > max_value_len)
5196 value_string[max_value_len] = '\0';
5198 else if (type & TYPE_YES_NO_AUTO)
5200 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5203 startx = mSX + xpos * 32;
5204 starty = mSY + ypos * 32;
5205 font_nr = getSetupValueFont(type, value);
5206 font_width = getFontWidth(font_nr);
5208 font_height = getFontHeight(font_nr);
5211 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5212 if (setup_mode != SETUP_MODE_INPUT)
5214 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5215 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5216 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5217 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5218 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5219 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5220 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5221 boolean correct_font_draw_xoffset = FALSE;
5223 if (xpos == MENU_SCREEN_START_XPOS &&
5224 startx + font1_xoffset < text_startx + text_font_xoffset)
5225 correct_font_draw_xoffset = TRUE;
5227 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5228 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5229 correct_font_draw_xoffset = TRUE;
5231 /* check if setup value would overlap with setup text when printed */
5232 /* (this can happen for extreme/wrong values for font draw offset) */
5233 if (correct_font_draw_xoffset)
5235 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5236 font_draw_xoffset_modified = TRUE;
5238 if (type & TYPE_KEY)
5239 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5240 else if (!(type & TYPE_STRING))
5241 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5242 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5247 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5249 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5250 DrawText(startx + i * font_width, starty, " ", font_nr);
5253 DrawText(startx, starty, value_string, font_nr);
5255 if (font_draw_xoffset_modified)
5256 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5259 static void changeSetupValue(int pos, int dx)
5261 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5263 *(boolean *)setup_info[pos].value ^= TRUE;
5265 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5267 *(int *)setup_info[pos].value =
5269 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5270 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5271 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5272 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5274 else if (setup_info[pos].type & TYPE_KEY)
5278 setup_info[pos].type |= TYPE_QUERY;
5279 drawSetupValue(pos);
5280 setup_info[pos].type &= ~TYPE_QUERY;
5282 key = getSetupKey();
5283 if (key != KSYM_UNDEFINED)
5284 *(Key *)setup_info[pos].value = key;
5287 drawSetupValue(pos);
5289 // fullscreen state may have changed at this point
5290 if (setup_info[pos].value == &setup.fullscreen)
5291 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5294 static void DrawCursorAndText_Setup(int pos, boolean active)
5296 int xpos = MENU_SCREEN_START_XPOS;
5297 int ypos = MENU_SCREEN_START_YPOS + pos;
5298 int font_nr = getSetupTextFont(setup_info[pos].type);
5300 if (setup_info == setup_info_input)
5301 font_nr = FONT_MENU_1;
5304 font_nr = FONT_ACTIVE(font_nr);
5306 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5308 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5309 drawCursor(pos, active);
5312 static void DrawSetupScreen_Generic()
5314 boolean redraw_all = FALSE;
5315 char *title_string = NULL;
5319 CloseDoor(DOOR_CLOSE_2);
5321 if (redraw_mask & REDRAW_ALL)
5325 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5326 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5327 int2str(0, redraw_mask)));
5331 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5332 FadeOut(redraw_mask);
5334 FadeOut(REDRAW_FIELD);
5339 if (setup_mode == SETUP_MODE_MAIN)
5341 setup_info = setup_info_main;
5342 title_string = "Setup";
5344 else if (setup_mode == SETUP_MODE_GAME)
5346 setup_info = setup_info_game;
5347 title_string = "Setup Game";
5349 else if (setup_mode == SETUP_MODE_EDITOR)
5351 setup_info = setup_info_editor;
5352 title_string = "Setup Editor";
5354 else if (setup_mode == SETUP_MODE_GRAPHICS)
5356 setup_info = setup_info_graphics;
5357 title_string = "Setup Graphics";
5359 else if (setup_mode == SETUP_MODE_SOUND)
5361 setup_info = setup_info_sound;
5362 title_string = "Setup Sound";
5364 else if (setup_mode == SETUP_MODE_ARTWORK)
5366 setup_info = setup_info_artwork;
5367 title_string = "Custom Artwork";
5369 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5371 setup_info = setup_info_shortcuts;
5372 title_string = "Setup Shortcuts";
5374 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5376 setup_info = setup_info_shortcuts_1;
5377 title_string = "Setup Shortcuts";
5379 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5381 setup_info = setup_info_shortcuts_2;
5382 title_string = "Setup Shortcuts";
5384 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5386 setup_info = setup_info_shortcuts_3;
5387 title_string = "Setup Shortcuts";
5389 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5391 setup_info = setup_info_shortcuts_4;
5392 title_string = "Setup Shortcuts";
5394 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5396 setup_info = setup_info_shortcuts_5;
5397 title_string = "Setup Shortcuts";
5400 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5404 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5406 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5409 void *value_ptr = setup_info[i].value;
5411 /* set some entries to "unchangeable" according to other variables */
5412 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5413 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5414 (value_ptr == &setup.sound_music && !audio.music_available) ||
5415 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5416 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5417 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5418 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5419 setup_info[i].type |= TYPE_GHOSTED;
5421 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5422 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5423 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5424 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5425 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5426 initCursor(i, IMG_MENU_BUTTON);
5428 DrawCursorAndText_Setup(i, FALSE);
5430 if (setup_info[i].type & TYPE_VALUE)
5437 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5438 "Joysticks deactivated in setup menu");
5442 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5446 redraw_mask = REDRAW_ALL;
5449 FadeIn(redraw_mask);
5451 FadeIn(REDRAW_FIELD);
5456 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5460 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5462 static int choice_store[MAX_SETUP_MODES];
5463 int choice = choice_store[setup_mode]; /* always starts with 0 */
5467 if (button == MB_MENU_INITIALIZE)
5469 /* advance to first valid menu entry */
5470 while (choice < num_setup_info &&
5471 setup_info[choice].type & TYPE_SKIP_ENTRY)
5473 choice_store[setup_mode] = choice;
5475 DrawCursorAndText_Setup(choice, TRUE);
5479 else if (button == MB_MENU_LEAVE)
5481 PlaySound(SND_MENU_ITEM_SELECTING);
5483 // for (y = 0; y < num_setup_info; y++)
5484 for (y = 0; setup_info[y].type != 0; y++)
5486 if (setup_info[y].type & TYPE_LEAVE_MENU)
5488 void (*menu_callback_function)(void) = setup_info[y].value;
5492 menu_callback_function();
5494 break; /* absolutely needed because function changes 'setup_info'! */
5501 if (mx || my) /* mouse input */
5503 x = (mx - mSX) / 32;
5504 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5506 else if (dx || dy) /* keyboard input */
5510 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5512 if (setup_info[choice].type & menu_navigation_type ||
5513 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5514 setup_info[choice].type & TYPE_YES_NO_AUTO)
5515 button = MB_MENU_CHOICE;
5520 /* jump to next non-empty menu entry (up or down) */
5521 while (y > 0 && y < num_setup_info - 1 &&
5522 setup_info[y].type & TYPE_SKIP_ENTRY)
5526 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5530 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5532 PlaySound(SND_MENU_ITEM_ACTIVATING);
5534 DrawCursorAndText_Setup(choice, FALSE);
5535 DrawCursorAndText_Setup(y, TRUE);
5537 choice = choice_store[setup_mode] = y;
5540 else if (!(setup_info[y].type & TYPE_GHOSTED))
5542 PlaySound(SND_MENU_ITEM_SELECTING);
5544 /* when selecting key headline, execute function for key value change */
5545 if (setup_info[y].type & TYPE_KEYTEXT &&
5546 setup_info[y + 1].type & TYPE_KEY)
5549 /* when selecting string value, execute function for list selection */
5550 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5551 setup_info[y - 1].type & TYPE_ENTER_LIST)
5554 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5556 void (*menu_callback_function)(void) = setup_info[y].value;
5558 FadeSetFromType(setup_info[y].type);
5560 menu_callback_function();
5564 if (setup_info[y].type & TYPE_VALUE)
5565 changeSetupValue(y, dx);
5571 void DrawSetupScreen_Input()
5576 FadeOut(REDRAW_FIELD);
5582 setup_info = setup_info_input;
5585 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5589 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5590 "Joysticks deactivated on this screen");
5592 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5593 "Joysticks deactivated on this screen");
5598 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5600 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5603 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5604 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5605 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5606 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5607 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5608 initCursor(i, IMG_MENU_BUTTON);
5610 DrawCursorAndText_Setup(i, FALSE);
5614 DeactivateJoystickForCalibration();
5619 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5620 "Joysticks deactivated on this screen");
5622 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5623 "Joysticks deactivated on this screen");
5627 /* create gadgets for setup input menu screen */
5628 FreeScreenGadgets();
5629 CreateScreenGadgets();
5631 /* map gadgets for setup input menu screen */
5632 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5634 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5637 FadeIn(REDRAW_FIELD);
5643 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5645 if (device_name == NULL)
5648 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5651 if (strlen(device_name) > 1)
5653 char c1 = device_name[strlen(device_name) - 1];
5654 char c2 = device_name[strlen(device_name) - 2];
5656 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5657 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5660 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5661 strlen(device_name));
5664 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5667 static struct SetupKeyboardInfo custom_key;
5674 { &custom_key.left, "Joystick Left" },
5675 { &custom_key.right, "Joystick Right" },
5676 { &custom_key.up, "Joystick Up" },
5677 { &custom_key.down, "Joystick Down" },
5678 { &custom_key.snap, "Button 1" },
5679 { &custom_key.drop, "Button 2" }
5681 static char *joystick_name[MAX_PLAYERS] =
5688 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5692 custom_key = setup.input[player_nr].key;
5694 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5695 FONT_INPUT_1_ACTIVE);
5697 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5699 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5700 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5702 if (setup.input[player_nr].use_joystick)
5704 char *device_name = setup.input[player_nr].joy.device_name;
5705 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5706 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5708 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5709 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5713 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5714 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5717 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5719 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5720 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5721 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5722 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5724 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5725 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5726 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5727 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5728 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5729 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5731 for (i = 0; i < 6; i++)
5733 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5735 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5737 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5738 (setup.input[player_nr].use_joystick ?
5740 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5744 static int input_player_nr = 0;
5746 void HandleSetupScreen_Input_Player(int step, int direction)
5748 int old_player_nr = input_player_nr;
5751 new_player_nr = old_player_nr + step * direction;
5752 if (new_player_nr < 0)
5754 if (new_player_nr > MAX_PLAYERS - 1)
5755 new_player_nr = MAX_PLAYERS - 1;
5757 if (new_player_nr != old_player_nr)
5759 input_player_nr = new_player_nr;
5761 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5765 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5767 static int choice = 0;
5770 int pos_start = SETUPINPUT_SCREEN_POS_START;
5771 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5772 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5773 int pos_end = SETUPINPUT_SCREEN_POS_END;
5775 if (button == MB_MENU_INITIALIZE)
5777 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5779 DrawCursorAndText_Setup(choice, TRUE);
5783 else if (button == MB_MENU_LEAVE)
5785 setup_mode = SETUP_MODE_MAIN;
5792 if (mx || my) /* mouse input */
5794 x = (mx - mSX) / 32;
5795 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5797 else if (dx || dy) /* keyboard input */
5799 if (dx && choice == 0)
5800 x = (dx < 0 ? 10 : 12);
5801 else if ((dx && choice == 1) ||
5802 (dx == +1 && choice == 2) ||
5803 (dx == -1 && choice == pos_end))
5804 button = MB_MENU_CHOICE;
5808 if (y >= pos_empty1 && y <= pos_empty2)
5809 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5812 if (y == 0 && dx != 0 && button)
5814 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5816 else if (IN_VIS_FIELD(x, y) &&
5817 y >= pos_start && y <= pos_end &&
5818 !(y >= pos_empty1 && y <= pos_empty2))
5824 DrawCursorAndText_Setup(choice, FALSE);
5825 DrawCursorAndText_Setup(y, TRUE);
5827 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5836 char *device_name = setup.input[input_player_nr].joy.device_name;
5838 if (!setup.input[input_player_nr].use_joystick)
5840 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5842 setJoystickDeviceToNr(device_name, new_device_nr);
5843 setup.input[input_player_nr].use_joystick = TRUE;
5847 int device_nr = getJoystickNrFromDeviceName(device_name);
5848 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5850 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5851 setup.input[input_player_nr].use_joystick = FALSE;
5853 setJoystickDeviceToNr(device_name, new_device_nr);
5856 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5860 if (setup.input[input_player_nr].use_joystick)
5863 CalibrateJoystick(input_player_nr);
5866 CustomizeKeyboard(input_player_nr);
5868 else if (y == pos_end)
5874 setup_mode = SETUP_MODE_MAIN;
5881 void CustomizeKeyboard(int player_nr)
5885 boolean finished = FALSE;
5886 static struct SetupKeyboardInfo custom_key;
5891 } customize_step[] =
5893 { &custom_key.left, "Move Left" },
5894 { &custom_key.right, "Move Right" },
5895 { &custom_key.up, "Move Up" },
5896 { &custom_key.down, "Move Down" },
5897 { &custom_key.snap, "Snap Field" },
5898 { &custom_key.drop, "Drop Element" }
5901 /* read existing key bindings from player setup */
5902 custom_key = setup.input[player_nr].key;
5905 FadeOut(REDRAW_FIELD);
5909 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5917 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5918 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5919 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5920 "Key:", FONT_INPUT_1_ACTIVE);
5921 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5922 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5925 FadeIn(REDRAW_FIELD);
5932 if (PendingEvent()) /* got event */
5940 case EVENT_KEYPRESS:
5942 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5944 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5946 if (key == KSYM_Escape)
5947 FadeSkipNextFadeIn();
5953 /* all keys configured -- wait for "Escape" or "Return" key */
5957 /* press 'Enter' to keep the existing key binding */
5958 if (key == KSYM_Return)
5959 key = *customize_step[step_nr].key;
5961 /* check if key already used */
5962 for (i = 0; i < step_nr; i++)
5963 if (*customize_step[i].key == key)
5968 /* got new key binding */
5969 *customize_step[step_nr].key = key;
5970 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5972 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5973 getKeyNameFromKey(key), FONT_VALUE_1);
5976 /* un-highlight last query */
5977 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5978 customize_step[step_nr - 1].text, FONT_MENU_1);
5979 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5980 "Key:", FONT_MENU_1);
5982 /* press 'Enter' to leave */
5985 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5986 "Press Enter", FONT_TITLE_1);
5990 /* query next key binding */
5991 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5992 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5993 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5994 "Key:", FONT_INPUT_1_ACTIVE);
5995 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5996 getKeyNameFromKey(*customize_step[step_nr].key),
6001 case EVENT_KEYRELEASE:
6002 key_joystick_mapping = 0;
6006 HandleOtherEvents(&event);
6014 /* don't eat all CPU time */
6018 /* write new key bindings back to player setup */
6019 setup.input[player_nr].key = custom_key;
6022 DrawSetupScreen_Input();
6025 static boolean CalibrateJoystickMain(int player_nr)
6027 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6028 int new_joystick_xright = JOYSTICK_XMIDDLE;
6029 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6030 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6031 int new_joystick_xmiddle, new_joystick_ymiddle;
6033 int joystick_fd = joystick.fd[player_nr];
6034 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6035 boolean check[3][3];
6036 int check_remaining = 3 * 3;
6041 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6044 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6048 FadeOut(REDRAW_FIELD);
6052 for (y = 0; y < 3; y++)
6054 for (x = 0; x < 3; x++)
6056 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6057 check[x][y] = FALSE;
6061 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6062 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6063 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6064 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6065 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6066 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6067 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6069 joy_value = Joystick(player_nr);
6070 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6071 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6073 /* eventually uncalibrated center position (joystick could be uncentered) */
6074 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6077 new_joystick_xmiddle = joy_x;
6078 new_joystick_ymiddle = joy_y;
6080 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6082 FadeIn(REDRAW_FIELD);
6084 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6089 if (PendingEvent()) /* got event */
6097 case EVENT_KEYPRESS:
6098 switch (GetEventKey((KeyEvent *)&event, TRUE))
6101 if (check_remaining == 0)
6106 FadeSkipNextFadeIn();
6115 case EVENT_KEYRELEASE:
6116 key_joystick_mapping = 0;
6120 HandleOtherEvents(&event);
6125 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6128 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6129 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6130 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6131 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6133 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6134 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6135 setup.input[player_nr].joy.xright = new_joystick_xright;
6136 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6137 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6138 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6140 CheckJoystickData();
6142 joy_value = Joystick(player_nr);
6144 if (joy_value & JOY_BUTTON && check_remaining == 0)
6147 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6148 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6150 if (x != last_x || y != last_y)
6152 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6153 IMG_MENU_CALIBRATE_YELLOW, 0);
6154 DrawFixedGraphic(xpos + x, ypos + y,
6155 IMG_MENU_CALIBRATE_RED, 0);
6160 if (check_remaining > 0 && !check[x+1][y+1])
6162 check[x+1][y+1] = TRUE;
6168 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6169 setup.input[player_nr].joy.xleft,
6170 setup.input[player_nr].joy.xmiddle,
6171 setup.input[player_nr].joy.xright);
6172 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6173 setup.input[player_nr].joy.yupper,
6174 setup.input[player_nr].joy.ymiddle,
6175 setup.input[player_nr].joy.ylower);
6184 /* don't eat all CPU time */
6188 /* calibrated center position (joystick should now be centered) */
6189 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6192 new_joystick_xmiddle = joy_x;
6193 new_joystick_ymiddle = joy_y;
6198 DrawSetupScreen_Input();
6201 /* wait until the last pressed button was released */
6202 while (Joystick(player_nr) & JOY_BUTTON)
6204 if (PendingEvent()) /* got event */
6209 HandleOtherEvents(&event);
6218 void CalibrateJoystick(int player_nr)
6220 if (!CalibrateJoystickMain(player_nr))
6222 char *device_name = setup.input[player_nr].joy.device_name;
6223 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6224 int xpos = mSX - SX;
6225 int ypos = mSY - SY;
6229 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6230 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6233 Delay(2000); /* show error message for a short time */
6239 DrawSetupScreen_Input();
6243 void DrawSetupScreen()
6245 DeactivateJoystick();
6247 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6249 if (setup_mode == SETUP_MODE_INPUT)
6250 DrawSetupScreen_Input();
6251 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6252 DrawChooseTree(&game_speed_current);
6253 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6254 DrawChooseTree(&scroll_delay_current);
6255 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6256 DrawChooseTree(&screen_mode_current);
6257 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6258 DrawChooseTree(&window_size_current);
6259 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6260 DrawChooseTree(&scaling_type_current);
6261 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6262 DrawChooseTree(&artwork.gfx_current);
6263 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6264 DrawChooseTree(&artwork.snd_current);
6265 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6266 DrawChooseTree(&artwork.mus_current);
6267 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6268 DrawChooseTree(&volume_simple_current);
6269 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6270 DrawChooseTree(&volume_loops_current);
6271 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6272 DrawChooseTree(&volume_music_current);
6274 DrawSetupScreen_Generic();
6280 void RedrawSetupScreenAfterFullscreenToggle()
6283 if (setup_mode == SETUP_MODE_GRAPHICS ||
6284 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6286 // update list selection from "setup.window_scaling_percent"
6287 execSetupGraphics_setWindowSizes(TRUE);
6292 if (setup_mode == SETUP_MODE_GRAPHICS)
6297 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6299 if (setup_mode == SETUP_MODE_INPUT)
6300 HandleSetupScreen_Input(mx, my, dx, dy, button);
6301 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6302 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6303 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6304 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6305 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6306 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6307 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6308 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6309 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6310 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6311 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6312 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6313 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6314 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6315 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6316 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6317 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6318 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6319 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6320 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6321 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6322 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6324 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6331 void HandleGameActions()
6333 if (game_status != GAME_MODE_PLAYING)
6336 GameActions(); /* main game loop */
6338 if (tape.auto_play && !tape.playing)
6339 AutoPlayTape(); /* continue automatically playing next tape */
6343 /* ---------- new screen button stuff -------------------------------------- */
6345 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6350 case SCREEN_CTRL_ID_PREV_LEVEL:
6351 *x = mSX + menu.main.button.prev_level.x;
6352 *y = mSY + menu.main.button.prev_level.y;
6355 case SCREEN_CTRL_ID_NEXT_LEVEL:
6356 *x = mSX + menu.main.button.next_level.x;
6357 *y = mSY + menu.main.button.next_level.y;
6360 case SCREEN_CTRL_ID_PREV_LEVEL:
6361 *x = mSX + TILEX * getPrevlevelButtonPos();
6362 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6365 case SCREEN_CTRL_ID_NEXT_LEVEL:
6366 *x = mSX + TILEX * getNextLevelButtonPos();
6367 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6371 case SCREEN_CTRL_ID_PREV_PLAYER:
6372 *x = mSX + TILEX * 10;
6373 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6376 case SCREEN_CTRL_ID_NEXT_PLAYER:
6377 *x = mSX + TILEX * 12;
6378 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6382 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6388 int gfx_unpressed, gfx_pressed;
6389 void (*get_gadget_position)(int *, int *, int);
6393 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6396 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6397 getScreenMenuButtonPos,
6398 SCREEN_CTRL_ID_PREV_LEVEL,
6403 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6404 getScreenMenuButtonPos,
6405 SCREEN_CTRL_ID_NEXT_LEVEL,
6410 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6411 getScreenMenuButtonPos,
6412 SCREEN_CTRL_ID_PREV_PLAYER,
6417 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6418 getScreenMenuButtonPos,
6419 SCREEN_CTRL_ID_NEXT_PLAYER,
6427 int gfx_unpressed, gfx_pressed;
6431 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6434 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6436 -1, -1, /* these values are not constant, but can change at runtime */
6438 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6440 SCREEN_CTRL_ID_SCROLL_UP,
6444 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6446 -1, -1, /* these values are not constant, but can change at runtime */
6448 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6450 SCREEN_CTRL_ID_SCROLL_DOWN,
6457 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6458 Bitmap **gfx_unpressed, **gfx_pressed;
6460 int gfx_unpressed, gfx_pressed;
6467 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6470 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6471 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6473 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6476 -1, -1, /* these values are not constant, but can change at runtime */
6477 -1, -1, /* these values are not constant, but can change at runtime */
6479 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6480 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6482 GD_TYPE_SCROLLBAR_VERTICAL,
6483 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6484 "scroll level series vertically"
6488 static void CreateScreenMenubuttons()
6490 struct GadgetInfo *gi;
6491 unsigned int event_mask;
6494 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6496 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6497 int gfx_unpressed, gfx_pressed;
6498 int x, y, width, height;
6499 int gd_x1, gd_x2, gd_y1, gd_y2;
6500 int id = menubutton_info[i].gadget_id;
6502 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6504 menubutton_info[i].get_gadget_position(&x, &y, id);
6506 width = SC_MENUBUTTON_XSIZE;
6507 height = SC_MENUBUTTON_YSIZE;
6509 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6510 gfx_pressed = menubutton_info[i].gfx_pressed;
6511 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6512 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6513 gd_x1 = graphic_info[gfx_unpressed].src_x;
6514 gd_y1 = graphic_info[gfx_unpressed].src_y;
6515 gd_x2 = graphic_info[gfx_pressed].src_x;
6516 gd_y2 = graphic_info[gfx_pressed].src_y;
6518 gi = CreateGadget(GDI_CUSTOM_ID, id,
6519 GDI_CUSTOM_TYPE_ID, i,
6520 GDI_INFO_TEXT, menubutton_info[i].infotext,
6525 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6526 GDI_STATE, GD_BUTTON_UNPRESSED,
6527 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6528 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6529 GDI_DIRECT_DRAW, FALSE,
6530 GDI_EVENT_MASK, event_mask,
6531 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6535 Error(ERR_EXIT, "cannot create gadget");
6537 screen_gadget[id] = gi;
6541 static void CreateScreenScrollbuttons()
6543 struct GadgetInfo *gi;
6544 unsigned int event_mask;
6547 /* these values are not constant, but can change at runtime */
6548 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6549 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6550 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6551 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6553 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6555 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6556 int gfx_unpressed, gfx_pressed;
6557 int x, y, width, height;
6558 int gd_x1, gd_x2, gd_y1, gd_y2;
6559 int id = scrollbutton_info[i].gadget_id;
6561 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6563 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6564 y = mSY + scrollbutton_info[i].y;
6565 width = SC_SCROLLBUTTON_XSIZE;
6566 height = SC_SCROLLBUTTON_YSIZE;
6568 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6569 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6570 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6572 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6573 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6574 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6575 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6576 gd_x1 = graphic_info[gfx_unpressed].src_x;
6577 gd_y1 = graphic_info[gfx_unpressed].src_y;
6578 gd_x2 = graphic_info[gfx_pressed].src_x;
6579 gd_y2 = graphic_info[gfx_pressed].src_y;
6581 gi = CreateGadget(GDI_CUSTOM_ID, id,
6582 GDI_CUSTOM_TYPE_ID, i,
6583 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6588 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6589 GDI_STATE, GD_BUTTON_UNPRESSED,
6590 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6591 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6592 GDI_DIRECT_DRAW, FALSE,
6593 GDI_EVENT_MASK, event_mask,
6594 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6598 Error(ERR_EXIT, "cannot create gadget");
6600 screen_gadget[id] = gi;
6604 static void CreateScreenScrollbars()
6608 /* these values are not constant, but can change at runtime */
6609 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6610 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6611 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6612 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6614 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6616 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6617 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6618 int gfx_unpressed, gfx_pressed;
6620 int x, y, width, height;
6621 int gd_x1, gd_x2, gd_y1, gd_y2;
6622 struct GadgetInfo *gi;
6623 int items_max, items_visible, item_position;
6624 unsigned int event_mask;
6625 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6626 int id = scrollbar_info[i].gadget_id;
6628 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6630 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6631 y = mSY + scrollbar_info[i].y;
6632 width = scrollbar_info[i].width;
6633 height = scrollbar_info[i].height;
6635 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6636 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6638 items_max = num_page_entries;
6639 items_visible = num_page_entries;
6642 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6643 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6644 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6650 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6651 gfx_pressed = scrollbar_info[i].gfx_pressed;
6652 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6653 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6654 gd_x1 = graphic_info[gfx_unpressed].src_x;
6655 gd_y1 = graphic_info[gfx_unpressed].src_y;
6656 gd_x2 = graphic_info[gfx_pressed].src_x;
6657 gd_y2 = graphic_info[gfx_pressed].src_y;
6660 gi = CreateGadget(GDI_CUSTOM_ID, id,
6661 GDI_CUSTOM_TYPE_ID, i,
6662 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6667 GDI_TYPE, scrollbar_info[i].type,
6668 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6669 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6670 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6672 GDI_WHEEL_AREA_X, SX,
6673 GDI_WHEEL_AREA_Y, SY,
6674 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6675 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6677 GDI_WHEEL_AREA_X, 0,
6678 GDI_WHEEL_AREA_Y, 0,
6679 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6680 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6682 GDI_STATE, GD_BUTTON_UNPRESSED,
6683 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6684 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6685 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6686 GDI_DIRECT_DRAW, FALSE,
6687 GDI_EVENT_MASK, event_mask,
6688 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6692 Error(ERR_EXIT, "cannot create gadget");
6694 screen_gadget[id] = gi;
6698 void CreateScreenGadgets()
6700 int last_game_status = game_status; /* save current game status */
6702 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6705 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6707 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6709 /* copy pointers to clip mask and GC */
6710 scrollbar_bitmap[i]->clip_mask =
6711 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6712 scrollbar_bitmap[i]->stored_clip_gc =
6713 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6715 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6716 scrollbar_bitmap[i],
6717 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6718 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6719 TILEX, TILEY, 0, 0);
6723 CreateScreenMenubuttons();
6726 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6727 game_status = GAME_MODE_LEVELS;
6730 CreateScreenScrollbuttons();
6731 CreateScreenScrollbars();
6733 game_status = last_game_status; /* restore current game status */
6736 void FreeScreenGadgets()
6740 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6741 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6743 /* prevent freeing clip mask and GC twice */
6744 scrollbar_bitmap[i]->clip_mask = None;
6745 scrollbar_bitmap[i]->stored_clip_gc = None;
6747 FreeBitmap(scrollbar_bitmap[i]);
6751 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6752 FreeGadget(screen_gadget[i]);
6755 void MapScreenMenuGadgets(int screen_mask)
6759 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6760 if (screen_mask & menubutton_info[i].screen_mask)
6761 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6764 void MapScreenTreeGadgets(TreeInfo *ti)
6766 int num_entries = numTreeInfoInGroup(ti);
6769 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6772 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6773 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6775 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6776 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6779 static void HandleScreenGadgets(struct GadgetInfo *gi)
6781 int id = gi->custom_id;
6782 int button = gi->event.button;
6783 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6787 case SCREEN_CTRL_ID_PREV_LEVEL:
6788 HandleMainMenu_SelectLevel(step, -1);
6791 case SCREEN_CTRL_ID_NEXT_LEVEL:
6792 HandleMainMenu_SelectLevel(step, +1);
6795 case SCREEN_CTRL_ID_PREV_PLAYER:
6796 HandleSetupScreen_Input_Player(step, -1);
6799 case SCREEN_CTRL_ID_NEXT_PLAYER:
6800 HandleSetupScreen_Input_Player(step, +1);
6803 case SCREEN_CTRL_ID_SCROLL_UP:
6804 if (game_status == GAME_MODE_LEVELS)
6805 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6806 else if (game_status == GAME_MODE_LEVELNR)
6807 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6808 else if (game_status == GAME_MODE_SETUP)
6809 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6812 case SCREEN_CTRL_ID_SCROLL_DOWN:
6813 if (game_status == GAME_MODE_LEVELS)
6814 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6815 else if (game_status == GAME_MODE_LEVELNR)
6816 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6817 else if (game_status == GAME_MODE_SETUP)
6818 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6821 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6822 if (game_status == GAME_MODE_LEVELS)
6823 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6824 else if (game_status == GAME_MODE_LEVELNR)
6825 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6826 else if (game_status == GAME_MODE_SETUP)
6827 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);