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;
1390 /* needed if last screen was the editor screen */
1391 UndrawSpecialEditorDoor();
1393 if (fade_mask == REDRAW_FIELD)
1399 /* needed if different viewport properties defined for menues */
1400 ChangeViewportPropertiesIfNeeded();
1403 #if defined(TARGET_SDL)
1404 SetDrawtoField(DRAW_BACKBUFFER);
1407 if (CheckTitleScreen(levelset_has_changed))
1409 game_status = GAME_MODE_TITLE;
1416 /* level_nr may have been set to value over handicap with level editor */
1417 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1418 level_nr = leveldir_current->handicap_level;
1420 LoadLevel(level_nr);
1421 LoadScore(level_nr);
1423 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1426 if (fade_mask == REDRAW_ALL)
1428 // int door_state = GetDoorState();
1432 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1438 InitializeMainControls();
1440 DrawCursorAndText_Main(-1, FALSE);
1441 DrawPreviewLevelInitial();
1443 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1446 if (TAPE_IS_EMPTY(tape))
1448 DrawCompleteVideoDisplay();
1453 /* create gadgets for main menu screen */
1454 FreeScreenGadgets();
1455 CreateScreenGadgets();
1457 /* map gadgets for main menu screen */
1459 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1462 if (fade_mask == REDRAW_ALL)
1464 int door_state = GetDoorState();
1466 // RedrawBackground();
1468 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1472 DrawMaskedBorder(REDRAW_ALL);
1478 /* update screen area with special editor door */
1479 redraw_mask |= REDRAW_ALL;
1483 SetMouseCursor(CURSOR_DEFAULT);
1487 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1490 void DrawAndFadeInMainMenu(int fade_mask)
1492 DrawMainMenuExt(fade_mask, TRUE);
1497 DrawMainMenuExt(REDRAW_ALL, FALSE);
1500 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1501 static void gotoTopLevelDir()
1503 /* move upwards to top level directory */
1504 while (leveldir_current->node_parent)
1506 /* write a "path" into level tree for easy navigation to last level */
1507 if (leveldir_current->node_parent->node_group->cl_first == -1)
1509 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1510 int leveldir_pos = posTreeInfo(leveldir_current);
1511 int num_page_entries;
1512 int cl_first, cl_cursor;
1514 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1515 num_page_entries = num_leveldirs;
1517 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1519 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1520 cl_cursor = leveldir_pos - cl_first;
1522 leveldir_current->node_parent->node_group->cl_first = cl_first;
1523 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1526 leveldir_current = leveldir_current->node_parent;
1531 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1533 static unsigned int title_delay = 0;
1534 static int title_screen_nr = 0;
1535 static int last_sound = -1, last_music = -1;
1536 boolean return_to_main_menu = FALSE;
1537 boolean use_fading_main_menu = TRUE;
1538 struct TitleControlInfo *tci;
1539 struct TitleFadingInfo fading_default;
1540 struct TitleFadingInfo fading_last = fading;
1541 struct TitleFadingInfo fading_next;
1544 if (button == MB_MENU_INITIALIZE)
1547 title_screen_nr = 0;
1548 tci = &title_controls[title_screen_nr];
1550 last_sound = SND_UNDEFINED;
1551 last_music = MUS_UNDEFINED;
1553 if (game_status == GAME_MODE_INFO)
1555 if (num_title_screens == 0)
1557 DrawInfoScreen_NotAvailable("Title screen information:",
1558 "No title screen for this level set.");
1563 FadeSoundsAndMusic();
1566 FadeOut(REDRAW_ALL);
1571 DrawTitleScreenImage(tci->local_nr, tci->initial);
1573 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1575 fading_default = (tci->initial ? title_initial_default : title_default);
1577 fading = fading_next = getTitleFading(tci);
1581 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1582 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1584 fading.fade_mode = FADE_MODE_FADE;
1585 fading.fade_delay = fading_default.fade_delay;
1588 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1589 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1590 fading.fade_mode = FADE_MODE_FADE;
1595 sound = getTitleSound(tci);
1596 music = getTitleMusic(tci);
1598 if (sound != last_sound)
1599 PlayMenuSoundExt(sound);
1600 if (music != last_music)
1601 PlayMenuMusicExt(music);
1607 SetMouseCursor(CURSOR_NONE);
1613 fading = fading_next;
1615 DelayReached(&title_delay, 0); /* reset delay counter */
1621 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1622 button = MB_MENU_CHOICE;
1624 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1625 button = MB_MENU_CHOICE;
1628 if (button == MB_MENU_LEAVE)
1630 return_to_main_menu = TRUE;
1631 use_fading_main_menu = FALSE;
1633 else if (button == MB_MENU_CHOICE)
1635 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1638 FadeOut(REDRAW_FIELD);
1641 FadeSetEnterScreen();
1643 info_mode = INFO_MODE_MAIN;
1644 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1650 tci = &title_controls[title_screen_nr];
1652 if (title_screen_nr < num_title_screens)
1654 sound = getTitleSound(tci);
1655 music = getTitleMusic(tci);
1657 if (sound == SND_UNDEFINED || sound != last_sound)
1659 if (music == MUS_UNDEFINED || music != last_music)
1663 FadeOut(REDRAW_ALL);
1667 DrawTitleScreenImage(tci->local_nr, tci->initial);
1669 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1671 fading_next = getTitleFading(tci);
1674 sound = getTitleSound(tci);
1675 music = getTitleMusic(tci);
1677 if (sound != last_sound)
1678 PlayMenuSoundExt(sound);
1679 if (music != last_music)
1680 PlayMenuMusicExt(music);
1687 /* last screen already faded out, next screen has no animation */
1688 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1689 fading_next.fade_mode == FADE_MODE_NONE)
1690 fading = fading_next;
1692 /* last screen already faded out, next screen has no animation */
1693 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1694 fading_next.fade_mode == FADE_MODE_NONE)
1695 fading = fading_next;
1702 fading = fading_next;
1704 DelayReached(&title_delay, 0); /* reset delay counter */
1708 FadeSoundsAndMusic();
1710 return_to_main_menu = TRUE;
1714 if (return_to_main_menu)
1720 SetMouseCursor(CURSOR_DEFAULT);
1722 if (game_status == GAME_MODE_INFO)
1725 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1728 info_mode = INFO_MODE_MAIN;
1729 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1731 else /* default: return to main menu */
1734 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1737 game_status = GAME_MODE_MAIN;
1738 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1743 void HandleMainMenu_SelectLevel(int step, int direction)
1745 int old_level_nr = level_nr;
1748 new_level_nr = old_level_nr + step * direction;
1749 if (new_level_nr < leveldir_current->first_level)
1750 new_level_nr = leveldir_current->first_level;
1751 if (new_level_nr > leveldir_current->last_level)
1752 new_level_nr = leveldir_current->last_level;
1754 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1756 /* skipping levels is only allowed when trying to skip single level */
1757 if (setup.skip_levels && step == 1 &&
1758 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1760 leveldir_current->handicap_level++;
1761 SaveLevelSetup_SeriesInfo();
1764 new_level_nr = leveldir_current->handicap_level;
1767 if (new_level_nr != old_level_nr)
1769 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1771 PlaySound(SND_MENU_ITEM_SELECTING);
1773 level_nr = new_level_nr;
1775 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1776 int2str(level_nr, menu.main.text.level_number.size),
1777 mci->pos_text->font);
1779 LoadLevel(level_nr);
1780 DrawPreviewLevelInitial();
1784 DrawCompleteVideoDisplay();
1786 /* needed because DrawPreviewLevelInitial() takes some time */
1792 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1794 static int choice = MAIN_CONTROL_GAME;
1798 if (button == MB_MENU_INITIALIZE)
1800 DrawCursorAndText_Main(choice, TRUE);
1805 if (mx || my) /* mouse input */
1809 for (i = 0; main_controls[i].nr != -1; i++)
1812 printf("::: check click (%d, %d) for %d [%d] ...\n",
1813 mx - mSX, my - mSY, i, main_controls[i].nr);
1816 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1817 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1818 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1821 printf("::: inside %d\n", i);
1824 pos = main_controls[i].nr;
1830 else if (dx || dy) /* keyboard input */
1832 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1833 choice == MAIN_CONTROL_SETUP))
1834 button = MB_MENU_CHOICE;
1839 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1841 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1843 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1845 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1847 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1849 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1851 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1853 game_status = GAME_MODE_LEVELNR;
1855 DrawChooseLevelNr();
1857 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1863 PlaySound(SND_MENU_ITEM_ACTIVATING);
1865 DrawCursorAndText_Main(choice, FALSE);
1866 DrawCursorAndText_Main(pos, TRUE);
1873 PlaySound(SND_MENU_ITEM_SELECTING);
1875 if (pos == MAIN_CONTROL_NAME)
1877 game_status = GAME_MODE_PSEUDO_TYPENAME;
1879 HandleTypeName(strlen(setup.player_name), 0);
1881 else if (pos == MAIN_CONTROL_LEVELS)
1885 game_status = GAME_MODE_LEVELS;
1887 SaveLevelSetup_LastSeries();
1888 SaveLevelSetup_SeriesInfo();
1890 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1894 DrawChooseLevelSet();
1897 else if (pos == MAIN_CONTROL_SCORES)
1899 game_status = GAME_MODE_SCORES;
1903 else if (pos == MAIN_CONTROL_EDITOR)
1905 if (leveldir_current->readonly &&
1906 !strEqual(setup.player_name, "Artsoft"))
1907 Request("This level is read only!", REQ_CONFIRM);
1909 game_status = GAME_MODE_EDITOR;
1911 FadeSetEnterScreen();
1914 /* needed if different viewport properties defined for editor */
1915 ChangeViewportPropertiesIfNeeded();
1920 else if (pos == MAIN_CONTROL_INFO)
1922 game_status = GAME_MODE_INFO;
1923 info_mode = INFO_MODE_MAIN;
1927 else if (pos == MAIN_CONTROL_GAME)
1929 StartGameActions(options.network, setup.autorecord, level.random_seed);
1931 else if (pos == MAIN_CONTROL_SETUP)
1933 game_status = GAME_MODE_SETUP;
1934 setup_mode = SETUP_MODE_MAIN;
1938 else if (pos == MAIN_CONTROL_QUIT)
1940 SaveLevelSetup_LastSeries();
1941 SaveLevelSetup_SeriesInfo();
1943 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1944 game_status = GAME_MODE_QUIT;
1950 if (game_status == GAME_MODE_MAIN)
1952 DrawPreviewLevelAnimation();
1959 /* ========================================================================= */
1960 /* info screen functions */
1961 /* ========================================================================= */
1963 static struct TokenInfo *info_info;
1964 static int num_info_info;
1966 static void execInfoTitleScreen()
1968 info_mode = INFO_MODE_TITLE;
1973 static void execInfoElements()
1975 info_mode = INFO_MODE_ELEMENTS;
1980 static void execInfoMusic()
1982 info_mode = INFO_MODE_MUSIC;
1987 static void execInfoCredits()
1989 info_mode = INFO_MODE_CREDITS;
1994 static void execInfoProgram()
1996 info_mode = INFO_MODE_PROGRAM;
2001 static void execInfoVersion()
2003 info_mode = INFO_MODE_VERSION;
2008 static void execInfoLevelSet()
2010 info_mode = INFO_MODE_LEVELSET;
2015 static void execExitInfo()
2017 game_status = GAME_MODE_MAIN;
2019 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2022 static struct TokenInfo info_info_main[] =
2024 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2025 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2026 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2027 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2028 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2029 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2030 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2031 { TYPE_EMPTY, NULL, "" },
2032 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2037 static void DrawCursorAndText_Info(int pos, boolean active)
2039 int xpos = MENU_SCREEN_START_XPOS;
2040 int ypos = MENU_SCREEN_START_YPOS + pos;
2041 int font_nr = FONT_MENU_1;
2044 font_nr = FONT_ACTIVE(font_nr);
2046 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2048 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2049 drawCursor(pos, active);
2052 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2057 CloseDoor(DOOR_CLOSE_2);
2059 /* (needed after displaying title screens which disable auto repeat) */
2060 KeyboardAutoRepeatOn();
2062 FadeSetLeaveScreen();
2069 if (fade_mask == REDRAW_ALL)
2073 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2079 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2081 info_info = info_info_main;
2085 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2087 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2090 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2091 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2092 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2093 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2094 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2095 initCursor(i, IMG_MENU_BUTTON);
2097 DrawCursorAndText_Info(i, FALSE);
2102 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2107 DrawMaskedBorder(fade_mask);
2114 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2116 static int choice_store[MAX_INFO_MODES];
2117 int choice = choice_store[info_mode]; /* always starts with 0 */
2121 if (button == MB_MENU_INITIALIZE)
2123 /* advance to first valid menu entry */
2124 while (choice < num_info_info &&
2125 info_info[choice].type & TYPE_SKIP_ENTRY)
2127 choice_store[info_mode] = choice;
2129 DrawCursorAndText_Info(choice, TRUE);
2133 else if (button == MB_MENU_LEAVE)
2135 for (y = 0; y < num_info_info; y++)
2137 if (info_info[y].type & TYPE_LEAVE_MENU)
2139 void (*menu_callback_function)(void) = info_info[y].value;
2143 menu_callback_function();
2145 break; /* absolutely needed because function changes 'info_info'! */
2152 if (mx || my) /* mouse input */
2154 x = (mx - mSX) / 32;
2155 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2157 else if (dx || dy) /* keyboard input */
2161 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2163 if (info_info[choice].type & menu_navigation_type ||
2164 info_info[choice].type & TYPE_ENTER_SCREEN ||
2165 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2166 info_info[choice].type & TYPE_YES_NO_AUTO)
2167 button = MB_MENU_CHOICE;
2172 /* jump to next non-empty menu entry (up or down) */
2173 while (y > 0 && y < num_info_info - 1 &&
2174 info_info[y].type & TYPE_SKIP_ENTRY)
2178 if (IN_VIS_FIELD(x, y) &&
2179 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2185 PlaySound(SND_MENU_ITEM_ACTIVATING);
2187 DrawCursorAndText_Info(choice, FALSE);
2188 DrawCursorAndText_Info(y, TRUE);
2190 choice = choice_store[info_mode] = y;
2193 else if (!(info_info[y].type & TYPE_GHOSTED))
2195 PlaySound(SND_MENU_ITEM_SELECTING);
2197 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2199 void (*menu_callback_function)(void) = info_info[choice].value;
2201 FadeSetFromType(info_info[y].type);
2203 menu_callback_function();
2209 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2211 int ystart1 = mSY - SY + 100;
2212 int ystart2 = mSY - SY + 150;
2213 int ybottom = mSY - SY + SYSIZE - 20;
2215 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2217 FadeOut(REDRAW_FIELD);
2222 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2223 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2225 DrawTextSCentered(ybottom, FONT_TEXT_4,
2226 "Press any key or button for info menu");
2228 FadeIn(REDRAW_FIELD);
2231 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2233 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2234 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2235 int xstart = mSX + 16;
2236 int ystart1 = mSY - SY + 100;
2237 int ystart2 = mSY + 64 + 2 * 32;
2238 int ybottom = mSY - SY + SYSIZE - 20;
2239 int ystep = TILEY + 4;
2240 int element, action, direction;
2248 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2249 infoscreen_step[i] = infoscreen_frame[i] = 0;
2254 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2256 DrawTextSCentered(ybottom, FONT_TEXT_4,
2257 "Press any key or button for next page");
2263 while (helpanim_info[j].element != HELPANIM_LIST_END)
2265 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2270 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2279 j += infoscreen_step[i - start];
2281 element = helpanim_info[j].element;
2282 action = helpanim_info[j].action;
2283 direction = helpanim_info[j].direction;
2286 element = EL_UNKNOWN;
2288 if (action != -1 && direction != -1)
2289 graphic = el_act_dir2img(element, action, direction);
2290 else if (action != -1)
2291 graphic = el_act2img(element, action);
2292 else if (direction != -1)
2293 graphic = el_dir2img(element, direction);
2295 graphic = el2img(element);
2297 delay = helpanim_info[j++].delay;
2302 if (infoscreen_frame[i - start] == 0)
2305 infoscreen_frame[i - start] = delay - 1;
2309 sync_frame = delay - infoscreen_frame[i - start];
2310 infoscreen_frame[i - start]--;
2313 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2315 if (!infoscreen_frame[i - start])
2316 infoscreen_step[i - start] = 0;
2320 if (!infoscreen_frame[i - start])
2321 infoscreen_step[i - start]++;
2322 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2328 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2330 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2331 graphic, sync_frame, USE_MASKING);
2334 DrawInfoScreen_HelpText(element, action, direction, i - start);
2339 redraw_mask |= REDRAW_FIELD;
2344 static char *getHelpText(int element, int action, int direction)
2346 char token[MAX_LINE_LEN];
2348 strcpy(token, element_info[element].token_name);
2351 strcat(token, element_action_info[action].suffix);
2353 if (direction != -1)
2354 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2356 return getHashEntry(helptext_info, token);
2359 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2361 int font_nr = FONT_INFO_ELEMENTS;
2362 int font_width = getFontWidth(font_nr);
2363 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2364 int sy = mSY + 65 + 2 * 32 + 1;
2365 int ystep = TILEY + 4;
2366 int pad_x = sx - SX;
2367 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2368 int max_lines_per_text = 2;
2371 if (action != -1 && direction != -1) /* element.action.direction */
2372 text = getHelpText(element, action, direction);
2374 if (text == NULL && action != -1) /* element.action */
2375 text = getHelpText(element, action, -1);
2377 if (text == NULL && direction != -1) /* element.direction */
2378 text = getHelpText(element, -1, direction);
2380 if (text == NULL) /* base element */
2381 text = getHelpText(element, -1, -1);
2383 if (text == NULL) /* not found */
2384 text = "No description available";
2386 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2387 sy += getFontHeight(font_nr) / 2;
2389 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2390 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2391 TRUE, FALSE, FALSE);
2394 void DrawInfoScreen_TitleScreen()
2399 void HandleInfoScreen_TitleScreen(int button)
2401 HandleTitleScreen(0, 0, 0, 0, button);
2404 void DrawInfoScreen_Elements()
2406 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2408 FadeOut(REDRAW_FIELD);
2413 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2415 FadeIn(REDRAW_FIELD);
2420 void HandleInfoScreen_Elements(int button)
2422 static unsigned int info_delay = 0;
2423 static int num_anims;
2424 static int num_pages;
2426 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2429 if (button == MB_MENU_INITIALIZE)
2431 boolean new_element = TRUE;
2435 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2437 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2439 else if (new_element)
2442 new_element = FALSE;
2446 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2450 if (button == MB_MENU_LEAVE)
2452 PlaySound(SND_MENU_ITEM_SELECTING);
2454 info_mode = INFO_MODE_MAIN;
2459 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2461 if (button != MB_MENU_INITIALIZE)
2463 PlaySound(SND_MENU_ITEM_SELECTING);
2468 if (page >= num_pages)
2470 FadeSoundsAndMusic();
2472 info_mode = INFO_MODE_MAIN;
2473 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2480 FadeSetNextScreen();
2483 if (button != MB_MENU_INITIALIZE)
2484 FadeOut(REDRAW_FIELD);
2486 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2488 if (button != MB_MENU_INITIALIZE)
2489 FadeIn(REDRAW_FIELD);
2493 if (DelayReached(&info_delay, GameFrameDelay))
2494 if (page < num_pages)
2495 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2497 PlayMenuSoundIfLoop();
2501 void DrawInfoScreen_Music()
2503 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2506 FadeOut(REDRAW_FIELD);
2514 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2517 FadeIn(REDRAW_FIELD);
2521 void HandleInfoScreen_Music(int button)
2523 static struct MusicFileInfo *list = NULL;
2524 int ystart1 = mSY - SY + 100;
2525 int ystart2 = mSY - SY + 150;
2526 int ybottom = mSY - SY + SYSIZE - 20;
2529 if (button == MB_MENU_INITIALIZE)
2531 list = music_file_info;
2535 FadeSoundsAndMusic();
2540 DrawTextSCentered(ystart1, FONT_TEXT_1,
2541 "No music info for this level set.");
2543 DrawTextSCentered(ybottom, FONT_TEXT_4,
2544 "Press any key or button for info menu");
2550 if (button == MB_MENU_LEAVE)
2552 PlaySound(SND_MENU_ITEM_SELECTING);
2554 FadeSoundsAndMusic();
2556 info_mode = INFO_MODE_MAIN;
2561 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2565 if (button != MB_MENU_INITIALIZE)
2567 PlaySound(SND_MENU_ITEM_SELECTING);
2575 FadeSoundsAndMusic();
2577 info_mode = INFO_MODE_MAIN;
2578 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2583 FadeSoundsAndMusic();
2586 if (list != music_file_info)
2587 FadeSetNextScreen();
2590 if (button != MB_MENU_INITIALIZE)
2591 FadeOut(REDRAW_FIELD);
2598 int sound = list->music;
2600 if (sound_info[sound].loop)
2601 PlaySoundLoop(sound);
2605 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2609 PlayMusic(list->music);
2611 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2614 if (!strEqual(list->title, UNKNOWN_NAME))
2616 if (!strEqual(list->title_header, UNKNOWN_NAME))
2617 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2619 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2622 if (!strEqual(list->artist, UNKNOWN_NAME))
2624 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2625 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2627 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2629 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2632 if (!strEqual(list->album, UNKNOWN_NAME))
2634 if (!strEqual(list->album_header, UNKNOWN_NAME))
2635 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2637 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2639 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2642 if (!strEqual(list->year, UNKNOWN_NAME))
2644 if (!strEqual(list->year_header, UNKNOWN_NAME))
2645 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2647 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2649 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2652 DrawTextSCentered(ybottom, FONT_TEXT_4,
2653 "Press any key or button for next page");
2655 if (button != MB_MENU_INITIALIZE)
2656 FadeIn(REDRAW_FIELD);
2659 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2660 PlaySoundLoop(list->music);
2663 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2665 int ystart1 = mSY - SY + 100;
2666 int ystart2 = mSY - SY + 150;
2667 int ybottom = mSY - SY + SYSIZE - 20;
2673 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2677 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2678 "Special thanks to");
2679 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2681 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2683 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2684 "\"Boulder Dash\"");
2685 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2687 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2689 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2691 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2692 "First Star Software");
2694 else if (screen_nr == 1)
2696 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2697 "Special thanks to");
2698 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2699 "Klaus Heinz & Volker Wertich");
2700 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2702 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2703 "\"Emerald Mine\"");
2704 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2706 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2708 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2710 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2713 else if (screen_nr == 2)
2715 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2716 "Special thanks to");
2717 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2718 "Michael Stopp & Philip Jespersen");
2719 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2721 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2723 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2725 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2727 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2729 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2730 "Digital Integration");
2732 else if (screen_nr == 3)
2734 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2735 "Special thanks to");
2736 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2737 "Hiroyuki Imabayashi");
2738 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2740 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2742 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2744 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2746 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2748 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2751 else if (screen_nr == 4)
2753 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2754 "Special thanks to");
2755 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2757 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2759 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2760 "Jürgen Bonhagen");
2761 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2762 "for the continuous creation");
2763 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2764 "of outstanding level sets");
2766 else if (screen_nr == 5)
2768 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2770 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2772 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2773 "for ideas and inspiration by");
2774 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2777 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2779 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2781 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2782 "for ideas and inspiration by");
2783 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2786 else if (screen_nr == 6)
2788 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2790 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2793 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2794 "for the code base used for the");
2795 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2796 "native Emerald Mine engine");
2798 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2799 "for the new Emerald Mine engine");
2802 else if (screen_nr == 7)
2804 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2806 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2808 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2809 "for the initial DOS port");
2811 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2813 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2815 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2816 "for some additional toons");
2818 else if (screen_nr == 8)
2820 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2821 "And not to forget:");
2822 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2824 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2825 "All those who contributed");
2826 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2827 "levels to this game");
2828 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2832 DrawTextSCentered(ybottom, FONT_TEXT_4,
2833 "Press any key or button for next page");
2836 void DrawInfoScreen_Credits()
2838 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2840 FadeSoundsAndMusic();
2843 FadeOut(REDRAW_FIELD);
2846 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2849 FadeIn(REDRAW_FIELD);
2853 void HandleInfoScreen_Credits(int button)
2855 static int screen_nr = 0;
2856 int num_screens = 9;
2858 if (button == MB_MENU_INITIALIZE)
2862 // DrawInfoScreen_CreditsScreen(screen_nr);
2865 if (button == MB_MENU_LEAVE)
2867 PlaySound(SND_MENU_ITEM_SELECTING);
2869 info_mode = INFO_MODE_MAIN;
2874 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2876 if (button != MB_MENU_INITIALIZE)
2878 PlaySound(SND_MENU_ITEM_SELECTING);
2883 if (screen_nr >= num_screens)
2885 FadeSoundsAndMusic();
2887 info_mode = INFO_MODE_MAIN;
2888 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2895 FadeSetNextScreen();
2898 if (button != MB_MENU_INITIALIZE)
2899 FadeOut(REDRAW_FIELD);
2901 DrawInfoScreen_CreditsScreen(screen_nr);
2903 if (button != MB_MENU_INITIALIZE)
2904 FadeIn(REDRAW_FIELD);
2908 PlayMenuSoundIfLoop();
2912 void DrawInfoScreen_Program()
2914 int ystart1 = mSY - SY + 100;
2915 int ystart2 = mSY - SY + 150;
2916 int ybottom = mSY - SY + SYSIZE - 20;
2919 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2922 FadeOut(REDRAW_FIELD);
2928 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2930 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2931 "This game is Freeware!");
2932 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2933 "If you like it, send e-mail to:");
2934 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2935 PROGRAM_EMAIL_STRING);
2937 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2938 "More information and levels:");
2939 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2940 PROGRAM_WEBSITE_STRING);
2941 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2942 "If you have created new levels,");
2943 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2944 "send them to me to include them!");
2945 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2948 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2949 "or SnailMail to:");
2950 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2952 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2953 "Detmolder Strasse 189");
2954 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2956 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2958 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2959 "More information and levels:");
2960 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2961 PROGRAM_WEBSITE_STRING);
2962 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2963 "If you have created new levels,");
2964 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2965 "send them to me to include them!");
2966 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2970 DrawTextSCentered(ybottom, FONT_TEXT_4,
2971 "Press any key or button for info menu");
2974 FadeIn(REDRAW_FIELD);
2978 void HandleInfoScreen_Program(int button)
2980 if (button == MB_MENU_LEAVE)
2982 PlaySound(SND_MENU_ITEM_SELECTING);
2984 info_mode = INFO_MODE_MAIN;
2989 else if (button == MB_MENU_CHOICE)
2991 PlaySound(SND_MENU_ITEM_SELECTING);
2993 FadeSoundsAndMusic();
2996 FadeOut(REDRAW_FIELD);
2999 info_mode = INFO_MODE_MAIN;
3000 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3004 PlayMenuSoundIfLoop();
3008 void DrawInfoScreen_Version()
3010 int font_header = FONT_TEXT_3;
3011 int font_text = FONT_TEXT_2;
3012 int xstep = getFontWidth(font_text);
3013 int ystep = getFontHeight(font_text);
3014 int ystart1 = mSY - SY + 100;
3015 int ystart2 = mSY - SY + 150;
3016 int ybottom = mSY - SY + SYSIZE - 20;
3017 int xstart1 = mSX - SX + 2 * xstep;
3018 int xstart2 = mSX - SX + 18 * xstep;
3019 #if defined(TARGET_SDL)
3020 int xstart3 = mSX - SX + 28 * xstep;
3021 SDL_version sdl_version_compiled;
3022 const SDL_version *sdl_version_linked;
3023 int driver_name_len = 10;
3024 #if defined(TARGET_SDL2)
3025 SDL_version sdl_version_linked_ext;
3026 const char *driver_name = NULL;
3028 char driver_name[driver_name_len];
3032 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3035 FadeOut(REDRAW_FIELD);
3041 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3043 DrawTextF(xstart1, ystart2, font_header, "Name");
3044 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3047 DrawTextF(xstart1, ystart2, font_header, "Version");
3048 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3051 DrawTextF(xstart1, ystart2, font_header, "Platform");
3052 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3055 DrawTextF(xstart1, ystart2, font_header, "Target");
3056 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3059 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3060 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3062 #if defined(TARGET_SDL)
3063 ystart2 += 3 * ystep;
3064 DrawTextF(xstart1, ystart2, font_header, "Library");
3065 DrawTextF(xstart2, ystart2, font_header, "compiled");
3066 DrawTextF(xstart3, ystart2, font_header, "linked");
3068 SDL_VERSION(&sdl_version_compiled);
3069 #if defined(TARGET_SDL2)
3070 SDL_GetVersion(&sdl_version_linked_ext);
3071 sdl_version_linked = &sdl_version_linked_ext;
3073 sdl_version_linked = SDL_Linked_Version();
3076 ystart2 += 2 * ystep;
3077 DrawTextF(xstart1, ystart2, font_text, "SDL");
3078 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3079 sdl_version_compiled.major,
3080 sdl_version_compiled.minor,
3081 sdl_version_compiled.patch);
3082 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3083 sdl_version_linked->major,
3084 sdl_version_linked->minor,
3085 sdl_version_linked->patch);
3087 SDL_IMAGE_VERSION(&sdl_version_compiled);
3088 sdl_version_linked = IMG_Linked_Version();
3091 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3092 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3093 sdl_version_compiled.major,
3094 sdl_version_compiled.minor,
3095 sdl_version_compiled.patch);
3096 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3097 sdl_version_linked->major,
3098 sdl_version_linked->minor,
3099 sdl_version_linked->patch);
3101 SDL_MIXER_VERSION(&sdl_version_compiled);
3102 sdl_version_linked = Mix_Linked_Version();
3105 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3106 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3107 sdl_version_compiled.major,
3108 sdl_version_compiled.minor,
3109 sdl_version_compiled.patch);
3110 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3111 sdl_version_linked->major,
3112 sdl_version_linked->minor,
3113 sdl_version_linked->patch);
3115 SDL_NET_VERSION(&sdl_version_compiled);
3116 sdl_version_linked = SDLNet_Linked_Version();
3119 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3120 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3121 sdl_version_compiled.major,
3122 sdl_version_compiled.minor,
3123 sdl_version_compiled.patch);
3124 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3125 sdl_version_linked->major,
3126 sdl_version_linked->minor,
3127 sdl_version_linked->patch);
3129 ystart2 += 3 * ystep;
3130 DrawTextF(xstart1, ystart2, font_header, "Driver");
3131 DrawTextF(xstart2, ystart2, font_header, "Requested");
3132 DrawTextF(xstart3, ystart2, font_header, "Used");
3134 #if defined(TARGET_SDL2)
3135 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3137 SDL_VideoDriverName(driver_name, driver_name_len);
3140 ystart2 += 2 * ystep;
3141 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3142 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3143 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3145 #if defined(TARGET_SDL2)
3146 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3148 SDL_AudioDriverName(driver_name, driver_name_len);
3152 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3153 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3154 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3157 DrawTextSCentered(ybottom, FONT_TEXT_4,
3158 "Press any key or button for info menu");
3161 FadeIn(REDRAW_FIELD);
3165 void HandleInfoScreen_Version(int button)
3167 if (button == MB_MENU_LEAVE)
3169 PlaySound(SND_MENU_ITEM_SELECTING);
3171 info_mode = INFO_MODE_MAIN;
3176 else if (button == MB_MENU_CHOICE)
3178 PlaySound(SND_MENU_ITEM_SELECTING);
3180 FadeSoundsAndMusic();
3183 FadeOut(REDRAW_FIELD);
3186 info_mode = INFO_MODE_MAIN;
3187 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3191 PlayMenuSoundIfLoop();
3195 void DrawInfoScreen_LevelSet()
3197 struct TitleMessageInfo *tmi = &readme;
3198 char *filename = getLevelSetInfoFilename();
3200 /* if chars set to "-1", automatically determine by text and font width */
3201 if (tmi->chars == -1)
3202 tmi->chars = tmi->width / getFontWidth(tmi->font);
3204 tmi->width = tmi->chars * getFontWidth(tmi->font);
3206 /* if lines set to "-1", automatically determine by text and font height */
3207 if (tmi->lines == -1)
3208 tmi->lines = tmi->height / getFontHeight(tmi->font);
3210 tmi->height = tmi->lines * getFontHeight(tmi->font);
3212 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3215 FadeOut(REDRAW_FIELD);
3221 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3223 if (filename != NULL)
3224 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3225 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3226 tmi->autowrap, tmi->centered, tmi->parse_comments);
3228 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3229 "No information for this level set.");
3231 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3232 "Press any key or button for info menu");
3235 FadeIn(REDRAW_FIELD);
3239 void HandleInfoScreen_LevelSet(int button)
3241 if (button == MB_MENU_LEAVE)
3243 PlaySound(SND_MENU_ITEM_SELECTING);
3245 info_mode = INFO_MODE_MAIN;
3250 else if (button == MB_MENU_CHOICE)
3252 PlaySound(SND_MENU_ITEM_SELECTING);
3254 FadeSoundsAndMusic();
3257 FadeOut(REDRAW_FIELD);
3260 info_mode = INFO_MODE_MAIN;
3261 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3265 PlayMenuSoundIfLoop();
3269 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3271 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3273 if (info_mode == INFO_MODE_TITLE)
3274 DrawInfoScreen_TitleScreen();
3275 else if (info_mode == INFO_MODE_ELEMENTS)
3276 DrawInfoScreen_Elements();
3277 else if (info_mode == INFO_MODE_MUSIC)
3278 DrawInfoScreen_Music();
3279 else if (info_mode == INFO_MODE_CREDITS)
3280 DrawInfoScreen_Credits();
3281 else if (info_mode == INFO_MODE_PROGRAM)
3282 DrawInfoScreen_Program();
3283 else if (info_mode == INFO_MODE_VERSION)
3284 DrawInfoScreen_Version();
3285 else if (info_mode == INFO_MODE_LEVELSET)
3286 DrawInfoScreen_LevelSet();
3288 DrawInfoScreen_Main(fade_mask, do_fading);
3290 if (info_mode != INFO_MODE_MAIN &&
3291 info_mode != INFO_MODE_TITLE &&
3292 info_mode != INFO_MODE_MUSIC)
3299 void DrawAndFadeInInfoScreen(int fade_mask)
3301 DrawInfoScreenExt(fade_mask, TRUE);
3304 void DrawInfoScreen()
3306 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3309 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3311 if (info_mode == INFO_MODE_TITLE)
3312 HandleInfoScreen_TitleScreen(button);
3313 else if (info_mode == INFO_MODE_ELEMENTS)
3314 HandleInfoScreen_Elements(button);
3315 else if (info_mode == INFO_MODE_MUSIC)
3316 HandleInfoScreen_Music(button);
3317 else if (info_mode == INFO_MODE_CREDITS)
3318 HandleInfoScreen_Credits(button);
3319 else if (info_mode == INFO_MODE_PROGRAM)
3320 HandleInfoScreen_Program(button);
3321 else if (info_mode == INFO_MODE_VERSION)
3322 HandleInfoScreen_Version(button);
3323 else if (info_mode == INFO_MODE_LEVELSET)
3324 HandleInfoScreen_LevelSet(button);
3326 HandleInfoScreen_Main(mx, my, dx, dy, button);
3334 /* ========================================================================= */
3335 /* type name functions */
3336 /* ========================================================================= */
3338 void HandleTypeName(int newxpos, Key key)
3340 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3341 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3342 struct TextPosInfo *pos = mci->pos_input;
3343 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3344 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3345 static int xpos = 0;
3346 int font_nr = pos->font;
3347 int font_active_nr = FONT_ACTIVE(font_nr);
3348 int font_width = getFontWidth(font_active_nr);
3349 char key_char = getValidConfigValueChar(getCharFromKey(key));
3350 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3351 boolean is_active = TRUE;
3353 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3357 strcpy(last_player_name, setup.player_name);
3361 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3363 setup.player_name[xpos] = key_char;
3364 setup.player_name[xpos + 1] = 0;
3368 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3372 setup.player_name[xpos] = 0;
3374 else if (key == KSYM_Return && xpos > 0)
3380 game_status = GAME_MODE_MAIN;
3382 else if (key == KSYM_Escape)
3384 strcpy(setup.player_name, last_player_name);
3388 game_status = GAME_MODE_MAIN;
3393 pos->width = (strlen(setup.player_name) + 1) * font_width;
3394 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3396 DrawText(startx, starty, setup.player_name, font_active_nr);
3397 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3401 pos->width = strlen(setup.player_name) * font_width;
3402 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3404 DrawText(startx, starty, setup.player_name, font_nr);
3409 /* ========================================================================= */
3410 /* tree menu functions */
3411 /* ========================================================================= */
3413 static void DrawChooseTree(TreeInfo **ti_ptr)
3417 FreeScreenGadgets();
3418 CreateScreenGadgets();
3420 CloseDoor(DOOR_CLOSE_2);
3423 FadeOut(REDRAW_FIELD);
3428 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3429 MapScreenTreeGadgets(*ti_ptr);
3432 FadeIn(REDRAW_FIELD);
3438 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3440 struct GadgetInfo *gi = screen_gadget[id];
3441 int items_max, items_visible, item_position;
3443 items_max = numTreeInfoInGroup(ti);
3444 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3445 item_position = first_entry;
3447 if (item_position > items_max - items_visible)
3448 item_position = items_max - items_visible;
3450 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3451 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3452 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3455 static void drawChooseTreeList(int first_entry, int num_page_entries,
3459 char *title_string = NULL;
3460 int yoffset_sets = MENU_TITLE1_YPOS;
3461 int yoffset_setup = 16;
3462 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3463 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3464 int last_game_status = game_status; /* save current game status */
3466 title_string = ti->infotext;
3468 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3471 /* force LEVELS font on artwork setup screen */
3472 game_status = GAME_MODE_LEVELS;
3476 /* clear tree list area, but not title or scrollbar */
3477 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3478 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3479 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3481 /* clear tree list area, but not title or scrollbar */
3482 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3483 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3484 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3487 for (i = 0; i < num_page_entries; i++)
3489 TreeInfo *node, *node_first;
3490 int entry_pos = first_entry + i;
3491 int xpos = MENU_SCREEN_START_XPOS;
3492 int ypos = MENU_SCREEN_START_YPOS + i;
3493 int startx = mSX + xpos * 32;
3494 int starty = mSY + ypos * 32;
3495 int font_nr = FONT_TEXT_1;
3496 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3497 int startx_text = startx + font_xoffset;
3498 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3499 int text_size = startx_scrollbar - startx_text;
3500 int max_buffer_len = text_size / getFontWidth(font_nr);
3501 char buffer[max_buffer_len + 1];
3503 node_first = getTreeInfoFirstGroupEntry(ti);
3504 node = getTreeInfoFromPos(node_first, entry_pos);
3506 strncpy(buffer, node->name, max_buffer_len);
3507 buffer[max_buffer_len] = '\0';
3509 DrawText(startx, starty, buffer, font_nr + node->color);
3511 if (node->parent_link)
3512 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3513 else if (node->level_group)
3514 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3516 initCursor(i, IMG_MENU_BUTTON);
3519 game_status = last_game_status; /* restore current game status */
3521 redraw_mask |= REDRAW_FIELD;
3524 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3526 TreeInfo *node, *node_first;
3527 int x, last_redraw_mask = redraw_mask;
3528 int ypos = MENU_TITLE2_YPOS;
3529 int font_nr = FONT_TITLE_2;
3531 if (ti->type == TREE_TYPE_LEVEL_NR)
3532 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3534 if (ti->type != TREE_TYPE_LEVEL_DIR)
3537 node_first = getTreeInfoFirstGroupEntry(ti);
3538 node = getTreeInfoFromPos(node_first, entry_pos);
3540 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3543 if (node->parent_link)
3544 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3545 node->node_parent->name);
3546 else if (node->level_group)
3547 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3549 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3550 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3551 node->levels, (node->levels > 1 ? "levels" : "level"),
3554 if (node->parent_link)
3555 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3557 else if (node->level_group)
3558 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3560 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3561 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3562 node->levels, node->class_desc);
3565 /* let BackToFront() redraw only what is needed */
3566 redraw_mask = last_redraw_mask | REDRAW_TILES;
3567 for (x = 0; x < SCR_FIELDX; x++)
3568 MarkTileDirty(x, 1);
3571 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3574 TreeInfo *ti = *ti_ptr;
3576 int y = ti->cl_cursor;
3577 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3578 int num_entries = numTreeInfoInGroup(ti);
3579 int num_page_entries;
3580 int last_game_status = game_status; /* save current game status */
3581 boolean position_set_by_scrollbar = (dx == 999);
3584 /* force LEVELS draw offset on choose level and artwork setup screen */
3585 game_status = GAME_MODE_LEVELS;
3588 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3589 num_page_entries = num_entries;
3591 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3593 game_status = last_game_status; /* restore current game status */
3595 if (button == MB_MENU_INITIALIZE)
3597 int num_entries = numTreeInfoInGroup(ti);
3598 int entry_pos = posTreeInfo(ti);
3600 if (ti->cl_first == -1)
3602 /* only on initialization */
3603 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3604 ti->cl_cursor = entry_pos - ti->cl_first;
3606 else if (ti->cl_cursor >= num_page_entries ||
3607 (num_entries > num_page_entries &&
3608 num_entries - ti->cl_first < num_page_entries))
3610 /* only after change of list size (by custom graphic configuration) */
3611 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3612 ti->cl_cursor = entry_pos - ti->cl_first;
3615 if (position_set_by_scrollbar)
3618 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3621 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3622 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3623 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3627 else if (button == MB_MENU_LEAVE)
3631 PlaySound(SND_MENU_ITEM_SELECTING);
3633 if (ti->node_parent)
3635 *ti_ptr = ti->node_parent;
3636 DrawChooseTree(ti_ptr);
3638 else if (game_status == GAME_MODE_SETUP)
3640 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3641 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3643 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3644 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3645 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3646 execSetupGraphics();
3647 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3648 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3649 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3656 if (game_status == GAME_MODE_LEVELNR)
3657 level_nr = atoi(level_number_current->identifier);
3659 game_status = GAME_MODE_MAIN;
3661 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3667 if (mx || my) /* mouse input */
3669 int last_game_status = game_status; /* save current game status */
3672 /* force LEVELS draw offset on artwork setup screen */
3673 game_status = GAME_MODE_LEVELS;
3676 x = (mx - mSX) / 32;
3677 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3679 game_status = last_game_status; /* restore current game status */
3681 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3683 /* move cursor instead of scrolling when already at start/end of list */
3684 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3686 else if (dy == +1 * SCROLL_LINE &&
3687 ti->cl_first + num_page_entries == num_entries)
3690 /* handle scrolling screen one line or page */
3691 if (ti->cl_cursor + dy < 0 ||
3692 ti->cl_cursor + dy > num_page_entries - 1)
3694 if (ABS(dy) == SCROLL_PAGE)
3695 step = num_page_entries - 1;
3697 if (dy < 0 && ti->cl_first > 0)
3699 /* scroll page/line up */
3701 ti->cl_first -= step;
3702 if (ti->cl_first < 0)
3705 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3706 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3707 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3709 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3712 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3714 /* scroll page/line down */
3716 ti->cl_first += step;
3717 if (ti->cl_first + num_page_entries > num_entries)
3718 ti->cl_first = MAX(0, num_entries - num_page_entries);
3720 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3721 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3722 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3724 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3731 /* handle moving cursor one line */
3732 y = ti->cl_cursor + dy;
3737 TreeInfo *node_first, *node_cursor;
3738 int entry_pos = ti->cl_first + y;
3740 node_first = getTreeInfoFirstGroupEntry(ti);
3741 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3743 if (node_cursor->node_group)
3747 PlaySound(SND_MENU_ITEM_SELECTING);
3749 node_cursor->cl_first = ti->cl_first;
3750 node_cursor->cl_cursor = ti->cl_cursor;
3751 *ti_ptr = node_cursor->node_group;
3752 DrawChooseTree(ti_ptr);
3757 else if (dx == -1 && ti->node_parent)
3761 PlaySound(SND_MENU_ITEM_SELECTING);
3763 *ti_ptr = ti->node_parent;
3764 DrawChooseTree(ti_ptr);
3769 if (!anyScrollbarGadgetActive() &&
3770 IN_VIS_FIELD(x, y) &&
3771 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3772 y >= 0 && y < num_page_entries)
3776 if (y != ti->cl_cursor)
3778 PlaySound(SND_MENU_ITEM_ACTIVATING);
3780 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3781 drawChooseTreeCursor(y, TRUE);
3782 drawChooseTreeInfo(ti->cl_first + y, ti);
3789 TreeInfo *node_first, *node_cursor;
3790 int entry_pos = ti->cl_first + y;
3792 PlaySound(SND_MENU_ITEM_SELECTING);
3794 node_first = getTreeInfoFirstGroupEntry(ti);
3795 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3797 if (node_cursor->node_group)
3801 node_cursor->cl_first = ti->cl_first;
3802 node_cursor->cl_cursor = ti->cl_cursor;
3803 *ti_ptr = node_cursor->node_group;
3804 DrawChooseTree(ti_ptr);
3806 else if (node_cursor->parent_link)
3810 *ti_ptr = node_cursor->node_parent;
3811 DrawChooseTree(ti_ptr);
3818 FadeSetEnterScreen();
3821 node_cursor->cl_first = ti->cl_first;
3822 node_cursor->cl_cursor = ti->cl_cursor;
3823 *ti_ptr = node_cursor;
3825 if (ti->type == TREE_TYPE_LEVEL_DIR)
3827 LoadLevelSetup_SeriesInfo();
3829 SaveLevelSetup_LastSeries();
3830 SaveLevelSetup_SeriesInfo();
3834 if (game_status == GAME_MODE_SETUP)
3836 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3837 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3839 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3840 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3841 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3842 execSetupGraphics();
3843 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3844 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3845 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3852 if (game_status == GAME_MODE_LEVELNR)
3853 level_nr = atoi(level_number_current->identifier);
3855 game_status = GAME_MODE_MAIN;
3864 void DrawChooseLevelSet()
3866 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3868 DrawChooseTree(&leveldir_current);
3874 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3876 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3883 void DrawChooseLevelNr()
3887 if (level_number != NULL)
3889 freeTreeInfo(level_number);
3891 level_number = NULL;
3894 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3896 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3897 char identifier[32], name[32];
3900 /* temporarily load level info to get level name */
3901 LoadLevelInfoOnly(i);
3903 ti->node_top = &level_number;
3904 ti->sort_priority = 10000 + value;
3905 ti->color = (level.no_valid_file ? FC_BLUE :
3906 LevelStats_getSolved(i) ? FC_GREEN :
3907 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3909 sprintf(identifier, "%d", value);
3910 sprintf(name, "%03d: %s", value,
3911 (level.no_valid_file ? "(no file)" : level.name));
3913 setString(&ti->identifier, identifier);
3914 setString(&ti->name, name);
3915 setString(&ti->name_sorting, name);
3917 pushTreeInfo(&level_number, ti);
3920 /* sort level number values to start with lowest level number */
3921 sortTreeInfo(&level_number);
3923 /* set current level number to current level number */
3924 level_number_current =
3925 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3927 /* if that also fails, set current level number to first available level */
3928 if (level_number_current == NULL)
3929 level_number_current = level_number;
3931 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3934 DrawChooseTree(&level_number_current);
3936 DrawChooseTree(&leveldir_current);
3943 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3946 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3948 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3956 void DrawHallOfFame(int highlight_position)
3959 FadeSoundsAndMusic();
3961 /* (this is needed when called from GameEnd() after winning a game) */
3962 KeyboardAutoRepeatOn();
3965 /* (this is needed when called from GameEnd() after winning a game) */
3966 SetDrawDeactivationMask(REDRAW_NONE);
3967 SetDrawBackgroundMask(REDRAW_FIELD);
3969 CloseDoor(DOOR_CLOSE_2);
3971 if (highlight_position < 0)
3972 LoadScore(level_nr);
3974 FadeSetEnterScreen();
3976 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3979 FadeOut(REDRAW_FIELD);
3987 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3990 FadeIn(REDRAW_FIELD);
3994 static void drawHallOfFameList(int first_entry, int highlight_position)
3998 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4001 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4002 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4003 "HighScores of Level %d", level_nr);
4005 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4007 int entry = first_entry + i;
4008 boolean active = (entry == highlight_position);
4009 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4010 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4011 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4012 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4013 int dx1 = 3 * getFontWidth(font_nr1);
4014 int dx2 = dx1 + getFontWidth(font_nr1);
4015 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4016 int sy = mSY + 64 + i * 32;
4018 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4019 DrawText(mSX + dx1, sy, ".", font_nr1);
4020 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4022 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4023 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4025 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4028 redraw_mask |= REDRAW_FIELD;
4031 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4033 static int first_entry = 0;
4034 static int highlight_position = 0;
4035 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4037 if (button == MB_MENU_INITIALIZE)
4040 highlight_position = mx;
4041 drawHallOfFameList(first_entry, highlight_position);
4046 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4047 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4051 if (first_entry > 0)
4053 first_entry -= step;
4054 if (first_entry < 0)
4057 drawHallOfFameList(first_entry, highlight_position);
4062 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4064 first_entry += step;
4065 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4066 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4068 drawHallOfFameList(first_entry, highlight_position);
4071 else if (button == MB_MENU_LEAVE)
4073 PlaySound(SND_MENU_ITEM_SELECTING);
4075 FadeSound(SND_BACKGROUND_SCORES);
4077 game_status = GAME_MODE_MAIN;
4081 else if (button == MB_MENU_CHOICE)
4083 PlaySound(SND_MENU_ITEM_SELECTING);
4085 FadeSound(SND_BACKGROUND_SCORES);
4088 FadeOut(REDRAW_FIELD);
4091 game_status = GAME_MODE_MAIN;
4093 DrawAndFadeInMainMenu(REDRAW_FIELD);
4096 if (game_status == GAME_MODE_SCORES)
4097 PlayMenuSoundIfLoop();
4105 /* ========================================================================= */
4106 /* setup screen functions */
4107 /* ========================================================================= */
4109 static struct TokenInfo *setup_info;
4110 static int num_setup_info;
4112 static char *screen_mode_text;
4113 static char *window_size_text;
4114 static char *scaling_type_text;
4115 static char *scroll_delay_text;
4116 static char *game_speed_text;
4117 static char *graphics_set_name;
4118 static char *sounds_set_name;
4119 static char *music_set_name;
4120 static char *volume_simple_text;
4121 static char *volume_loops_text;
4122 static char *volume_music_text;
4124 static void execSetupMain()
4126 setup_mode = SETUP_MODE_MAIN;
4131 static void execSetupGame_setGameSpeeds()
4133 if (game_speeds == NULL)
4137 for (i = 0; game_speeds_list[i].value != -1; i++)
4139 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4140 char identifier[32], name[32];
4141 int value = game_speeds_list[i].value;
4142 char *text = game_speeds_list[i].text;
4144 ti->node_top = &game_speeds;
4145 ti->sort_priority = 10000 - value;
4147 sprintf(identifier, "%d", value);
4148 sprintf(name, "%s", text);
4150 setString(&ti->identifier, identifier);
4151 setString(&ti->name, name);
4152 setString(&ti->name_sorting, name);
4153 setString(&ti->infotext, "Game Speed");
4155 pushTreeInfo(&game_speeds, ti);
4158 /* sort game speed values to start with slowest game speed */
4159 sortTreeInfo(&game_speeds);
4161 /* set current game speed to configured game speed value */
4162 game_speed_current =
4163 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4165 /* if that fails, set current game speed to reliable default value */
4166 if (game_speed_current == NULL)
4167 game_speed_current =
4168 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4170 /* if that also fails, set current game speed to first available speed */
4171 if (game_speed_current == NULL)
4172 game_speed_current = game_speeds;
4175 setup.game_frame_delay = atoi(game_speed_current->identifier);
4177 /* needed for displaying game speed text instead of identifier */
4178 game_speed_text = game_speed_current->name;
4181 static void execSetupGame_setScrollDelays()
4183 if (scroll_delays == NULL)
4187 for (i = 0; scroll_delays_list[i].value != -1; i++)
4189 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4190 char identifier[32], name[32];
4191 int value = scroll_delays_list[i].value;
4192 char *text = scroll_delays_list[i].text;
4194 ti->node_top = &scroll_delays;
4195 ti->sort_priority = value;
4197 sprintf(identifier, "%d", value);
4198 sprintf(name, "%s", text);
4200 setString(&ti->identifier, identifier);
4201 setString(&ti->name, name);
4202 setString(&ti->name_sorting, name);
4203 setString(&ti->infotext, "Scaling Type");
4205 pushTreeInfo(&scroll_delays, ti);
4208 /* sort scaling type values to start with lowest scaling type value */
4209 sortTreeInfo(&scroll_delays);
4211 /* set current scaling type value to configured scaling type value */
4212 scroll_delay_current =
4213 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4215 /* if that fails, set current scaling type to reliable default value */
4216 if (scroll_delay_current == NULL)
4217 scroll_delay_current =
4218 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4220 /* if that also fails, set current scaling type to first available value */
4221 if (scroll_delay_current == NULL)
4222 scroll_delay_current = scroll_delays;
4225 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4227 /* needed for displaying scaling type text instead of identifier */
4228 scroll_delay_text = scroll_delay_current->name;
4231 static void execSetupGame()
4233 execSetupGame_setGameSpeeds();
4234 execSetupGame_setScrollDelays();
4236 setup_mode = SETUP_MODE_GAME;
4241 static void execSetupChooseGameSpeed()
4243 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4248 static void execSetupChooseScrollDelay()
4250 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4255 static void execSetupEditor()
4257 setup_mode = SETUP_MODE_EDITOR;
4262 static void execSetupGraphics_setWindowSizes(boolean update_list)
4264 if (window_sizes != NULL && update_list)
4266 freeTreeInfo(window_sizes);
4268 window_sizes = NULL;
4271 if (window_sizes == NULL)
4273 boolean current_window_size_found = FALSE;
4276 for (i = 0; window_sizes_list[i].value != -1; i++)
4278 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4279 char identifier[32], name[32];
4280 int value = window_sizes_list[i].value;
4281 char *text = window_sizes_list[i].text;
4283 ti->node_top = &window_sizes;
4284 ti->sort_priority = value;
4286 sprintf(identifier, "%d", value);
4287 sprintf(name, "%s", text);
4289 setString(&ti->identifier, identifier);
4290 setString(&ti->name, name);
4291 setString(&ti->name_sorting, name);
4292 setString(&ti->infotext, "Window Scaling");
4294 pushTreeInfo(&window_sizes, ti);
4296 if (value == setup.window_scaling_percent)
4297 current_window_size_found = TRUE;
4300 if (!current_window_size_found)
4302 // add entry for non-preset window scaling value
4304 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4305 char identifier[32], name[32];
4306 int value = setup.window_scaling_percent;
4308 ti->node_top = &window_sizes;
4309 ti->sort_priority = value;
4311 sprintf(identifier, "%d", value);
4312 sprintf(name, "%d %% (Current)", value);
4314 setString(&ti->identifier, identifier);
4315 setString(&ti->name, name);
4316 setString(&ti->name_sorting, name);
4317 setString(&ti->infotext, "Window Scaling");
4319 pushTreeInfo(&window_sizes, ti);
4322 /* sort window size values to start with lowest window size value */
4323 sortTreeInfo(&window_sizes);
4325 /* set current window size value to configured window size value */
4326 window_size_current =
4327 getTreeInfoFromIdentifier(window_sizes,
4328 i_to_a(setup.window_scaling_percent));
4330 /* if that fails, set current window size to reliable default value */
4331 if (window_size_current == NULL)
4332 window_size_current =
4333 getTreeInfoFromIdentifier(window_sizes,
4334 i_to_a(STD_WINDOW_SCALING_PERCENT));
4336 /* if that also fails, set current window size to first available value */
4337 if (window_size_current == NULL)
4338 window_size_current = window_sizes;
4341 setup.window_scaling_percent = atoi(window_size_current->identifier);
4343 /* needed for displaying window size text instead of identifier */
4344 window_size_text = window_size_current->name;
4347 static void execSetupGraphics_setScalingTypes()
4349 if (scaling_types == NULL)
4353 for (i = 0; scaling_types_list[i].value != NULL; i++)
4355 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4356 char identifier[32], name[32];
4357 char *value = scaling_types_list[i].value;
4358 char *text = scaling_types_list[i].text;
4360 ti->node_top = &scaling_types;
4361 ti->sort_priority = i;
4363 sprintf(identifier, "%s", value);
4364 sprintf(name, "%s", text);
4366 setString(&ti->identifier, identifier);
4367 setString(&ti->name, name);
4368 setString(&ti->name_sorting, name);
4369 setString(&ti->infotext, "Anti-Aliasing");
4371 pushTreeInfo(&scaling_types, ti);
4374 /* sort scaling type values to start with lowest scaling type value */
4375 sortTreeInfo(&scaling_types);
4377 /* set current scaling type value to configured scaling type value */
4378 scaling_type_current =
4379 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4381 /* if that fails, set current scaling type to reliable default value */
4382 if (scaling_type_current == NULL)
4383 scaling_type_current =
4384 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4386 /* if that also fails, set current scaling type to first available value */
4387 if (scaling_type_current == NULL)
4388 scaling_type_current = scaling_types;
4391 setup.window_scaling_quality = scaling_type_current->identifier;
4393 /* needed for displaying scaling type text instead of identifier */
4394 scaling_type_text = scaling_type_current->name;
4397 static void execSetupGraphics_setScreenModes()
4399 // if (screen_modes == NULL && video.fullscreen_available)
4400 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4404 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4406 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4407 char identifier[32], name[32];
4408 int x = video.fullscreen_modes[i].width;
4409 int y = video.fullscreen_modes[i].height;
4412 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4414 ti->node_top = &screen_modes;
4415 ti->sort_priority = x * 10000 + y;
4417 sprintf(identifier, "%dx%d", x, y);
4418 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4420 setString(&ti->identifier, identifier);
4421 setString(&ti->name, name);
4422 setString(&ti->name_sorting, name);
4423 setString(&ti->infotext, "Fullscreen Mode");
4425 pushTreeInfo(&screen_modes, ti);
4428 /* sort fullscreen modes to start with lowest available screen resolution */
4429 sortTreeInfo(&screen_modes);
4431 /* set current screen mode for fullscreen mode to configured setup value */
4432 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4433 setup.fullscreen_mode);
4435 /* if that fails, set current screen mode to reliable default value */
4436 if (screen_mode_current == NULL)
4437 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4438 DEFAULT_FULLSCREEN_MODE);
4440 /* if that also fails, set current screen mode to first available mode */
4441 if (screen_mode_current == NULL)
4442 screen_mode_current = screen_modes;
4444 if (screen_mode_current == NULL)
4445 video.fullscreen_available = FALSE;
4448 // if (video.fullscreen_available)
4449 if (screen_mode_current != NULL)
4451 setup.fullscreen_mode = screen_mode_current->identifier;
4453 /* needed for displaying screen mode name instead of identifier */
4454 screen_mode_text = screen_mode_current->name;
4458 static void execSetupGraphics()
4460 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4462 // update "setup.window_scaling_percent" from list selection
4463 execSetupGraphics_setWindowSizes(FALSE);
4467 // update list selection from "setup.window_scaling_percent"
4468 execSetupGraphics_setWindowSizes(TRUE);
4471 execSetupGraphics_setScalingTypes();
4472 execSetupGraphics_setScreenModes();
4474 setup_mode = SETUP_MODE_GRAPHICS;
4478 #if defined(TARGET_SDL2)
4479 // window scaling may have changed at this point
4480 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4482 // window scaling quality may have changed at this point
4483 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4484 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4488 #if !defined(PLATFORM_ANDROID)
4489 #if defined(TARGET_SDL2)
4490 static void execSetupChooseWindowSize()
4493 if (!video.window_scaling_available)
4497 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4502 static void execSetupChooseScalingType()
4504 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4509 static void execSetupChooseScreenMode()
4511 if (!video.fullscreen_available)
4514 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4521 static void execSetupChooseVolumeSimple()
4523 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4528 static void execSetupChooseVolumeLoops()
4530 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4535 static void execSetupChooseVolumeMusic()
4537 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4542 static void execSetupSound()
4545 if (volumes_simple == NULL)
4549 for (i = 0; volumes_list[i].value != -1; i++)
4551 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4552 char identifier[32], name[32];
4553 int value = volumes_list[i].value;
4554 char *text = volumes_list[i].text;
4556 ti->node_top = &volumes_simple;
4557 ti->sort_priority = value;
4559 sprintf(identifier, "%d", value);
4560 sprintf(name, "%s", text);
4562 setString(&ti->identifier, identifier);
4563 setString(&ti->name, name);
4564 setString(&ti->name_sorting, name);
4565 setString(&ti->infotext, "Sound Volume");
4567 pushTreeInfo(&volumes_simple, ti);
4570 /* sort volume values to start with lowest volume value */
4571 sortTreeInfo(&volumes_simple);
4573 /* set current volume value to configured volume value */
4574 volume_simple_current =
4575 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4577 /* if that fails, set current volume to reliable default value */
4578 if (volume_simple_current == NULL)
4579 volume_simple_current =
4580 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4582 /* if that also fails, set current volume to first available value */
4583 if (volume_simple_current == NULL)
4584 volume_simple_current = volumes_simple;
4587 if (volumes_loops == NULL)
4591 for (i = 0; volumes_list[i].value != -1; i++)
4593 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4594 char identifier[32], name[32];
4595 int value = volumes_list[i].value;
4596 char *text = volumes_list[i].text;
4598 ti->node_top = &volumes_loops;
4599 ti->sort_priority = value;
4601 sprintf(identifier, "%d", value);
4602 sprintf(name, "%s", text);
4604 setString(&ti->identifier, identifier);
4605 setString(&ti->name, name);
4606 setString(&ti->name_sorting, name);
4607 setString(&ti->infotext, "Loops Volume");
4609 pushTreeInfo(&volumes_loops, ti);
4612 /* sort volume values to start with lowest volume value */
4613 sortTreeInfo(&volumes_loops);
4615 /* set current volume value to configured volume value */
4616 volume_loops_current =
4617 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4619 /* if that fails, set current volume to reliable default value */
4620 if (volume_loops_current == NULL)
4621 volume_loops_current =
4622 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4624 /* if that also fails, set current volume to first available value */
4625 if (volume_loops_current == NULL)
4626 volume_loops_current = volumes_loops;
4629 if (volumes_music == NULL)
4633 for (i = 0; volumes_list[i].value != -1; i++)
4635 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4636 char identifier[32], name[32];
4637 int value = volumes_list[i].value;
4638 char *text = volumes_list[i].text;
4640 ti->node_top = &volumes_music;
4641 ti->sort_priority = value;
4643 sprintf(identifier, "%d", value);
4644 sprintf(name, "%s", text);
4646 setString(&ti->identifier, identifier);
4647 setString(&ti->name, name);
4648 setString(&ti->name_sorting, name);
4649 setString(&ti->infotext, "Music Volume");
4651 pushTreeInfo(&volumes_music, ti);
4654 /* sort volume values to start with lowest volume value */
4655 sortTreeInfo(&volumes_music);
4657 /* set current volume value to configured volume value */
4658 volume_music_current =
4659 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4661 /* if that fails, set current volume to reliable default value */
4662 if (volume_music_current == NULL)
4663 volume_music_current =
4664 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4666 /* if that also fails, set current volume to first available value */
4667 if (volume_music_current == NULL)
4668 volume_music_current = volumes_music;
4671 setup.volume_simple = atoi(volume_simple_current->identifier);
4672 setup.volume_loops = atoi(volume_loops_current->identifier);
4673 setup.volume_music = atoi(volume_music_current->identifier);
4675 /* needed for displaying volume text instead of identifier */
4676 volume_simple_text = volume_simple_current->name;
4677 volume_loops_text = volume_loops_current->name;
4678 volume_music_text = volume_music_current->name;
4681 setup_mode = SETUP_MODE_SOUND;
4686 static void execSetupArtwork()
4689 printf("::: '%s', '%s', '%s'\n",
4690 artwork.gfx_current->subdir,
4691 artwork.gfx_current->fullpath,
4692 artwork.gfx_current->basepath);
4695 setup.graphics_set = artwork.gfx_current->identifier;
4696 setup.sounds_set = artwork.snd_current->identifier;
4697 setup.music_set = artwork.mus_current->identifier;
4699 /* needed if last screen (setup choice) changed graphics, sounds or music */
4700 ReloadCustomArtwork(0);
4702 /* needed for displaying artwork name instead of artwork identifier */
4703 graphics_set_name = artwork.gfx_current->name;
4704 sounds_set_name = artwork.snd_current->name;
4705 music_set_name = artwork.mus_current->name;
4707 setup_mode = SETUP_MODE_ARTWORK;
4712 static void execSetupChooseGraphics()
4714 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4719 static void execSetupChooseSounds()
4721 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4726 static void execSetupChooseMusic()
4728 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4733 static void execSetupInput()
4735 setup_mode = SETUP_MODE_INPUT;
4740 static void execSetupShortcuts()
4742 setup_mode = SETUP_MODE_SHORTCUTS;
4747 static void execSetupShortcuts1()
4749 setup_mode = SETUP_MODE_SHORTCUTS_1;
4754 static void execSetupShortcuts2()
4756 setup_mode = SETUP_MODE_SHORTCUTS_2;
4761 static void execSetupShortcuts3()
4763 setup_mode = SETUP_MODE_SHORTCUTS_3;
4768 static void execSetupShortcuts4()
4770 setup_mode = SETUP_MODE_SHORTCUTS_4;
4775 static void execSetupShortcuts5()
4777 setup_mode = SETUP_MODE_SHORTCUTS_5;
4782 static void execExitSetup()
4784 game_status = GAME_MODE_MAIN;
4786 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4789 static void execSaveAndExitSetup()
4795 static struct TokenInfo setup_info_main[] =
4797 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4798 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4799 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4800 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4801 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4802 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4803 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4804 { TYPE_EMPTY, NULL, "" },
4805 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4806 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4811 static struct TokenInfo setup_info_game[] =
4813 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4814 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4815 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4816 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4817 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4818 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4819 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4820 { TYPE_STRING, &game_speed_text, "" },
4822 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4823 { TYPE_STRING, &scroll_delay_text, "" },
4825 { TYPE_EMPTY, NULL, "" },
4826 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4831 static struct TokenInfo setup_info_editor[] =
4834 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4835 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4836 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4837 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4838 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4839 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4840 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4841 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4843 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4844 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4845 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4847 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4849 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4850 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4851 { TYPE_EMPTY, NULL, "" },
4853 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4854 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4855 { TYPE_EMPTY, NULL, "" },
4857 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4858 { TYPE_EMPTY, NULL, "" },
4859 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4864 static struct TokenInfo setup_info_graphics[] =
4866 #if !defined(PLATFORM_ANDROID)
4867 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4868 #if defined(TARGET_SDL2)
4869 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4870 { TYPE_STRING, &window_size_text, "" },
4872 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
4873 { TYPE_STRING, &scaling_type_text, "" },
4876 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4877 { TYPE_STRING, &screen_mode_text, "" },
4881 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4884 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4885 { TYPE_STRING, &scroll_delay_text, "" },
4888 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4890 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4891 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4892 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4893 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4894 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4895 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4896 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4897 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4898 { TYPE_EMPTY, NULL, "" },
4899 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4904 static struct TokenInfo setup_info_sound[] =
4906 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4907 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4908 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4909 { TYPE_EMPTY, NULL, "" },
4910 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4911 { TYPE_STRING, &volume_simple_text, "" },
4912 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4913 { TYPE_STRING, &volume_loops_text, "" },
4914 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4915 { TYPE_STRING, &volume_music_text, "" },
4916 { TYPE_EMPTY, NULL, "" },
4917 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4922 static struct TokenInfo setup_info_artwork[] =
4924 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4925 { TYPE_STRING, &graphics_set_name, "" },
4926 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4927 { TYPE_STRING, &sounds_set_name, "" },
4928 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4929 { TYPE_STRING, &music_set_name, "" },
4930 { TYPE_EMPTY, NULL, "" },
4933 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4934 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4935 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4937 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4938 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4939 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4940 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4943 { TYPE_STRING, NULL, "Override Level Artwork:"},
4944 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4945 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4946 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4948 { TYPE_EMPTY, NULL, "" },
4949 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4954 static struct TokenInfo setup_info_input[] =
4956 { TYPE_SWITCH, NULL, "Player:" },
4957 { TYPE_SWITCH, NULL, "Device:" },
4958 { TYPE_ENTER_MENU, NULL, "" },
4959 { TYPE_EMPTY, NULL, "" },
4960 { TYPE_EMPTY, NULL, "" },
4961 { TYPE_EMPTY, NULL, "" },
4962 { TYPE_EMPTY, NULL, "" },
4963 { TYPE_EMPTY, NULL, "" },
4964 { TYPE_EMPTY, NULL, "" },
4965 { TYPE_EMPTY, NULL, "" },
4966 { TYPE_EMPTY, NULL, "" },
4967 { TYPE_EMPTY, NULL, "" },
4968 { TYPE_EMPTY, NULL, "" },
4969 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4974 static struct TokenInfo setup_info_shortcuts[] =
4976 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4977 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4978 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4979 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4980 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4981 { TYPE_EMPTY, NULL, "" },
4982 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4987 static struct TokenInfo setup_info_shortcuts_1[] =
4989 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4990 { TYPE_KEY, &setup.shortcut.save_game, "" },
4991 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4992 { TYPE_KEY, &setup.shortcut.load_game, "" },
4993 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4994 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4995 { TYPE_EMPTY, NULL, "" },
4996 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4997 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4998 { TYPE_EMPTY, NULL, "" },
4999 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5004 static struct TokenInfo setup_info_shortcuts_2[] =
5006 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5007 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5008 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5009 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5010 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5011 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5012 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5013 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5014 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5015 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5016 { TYPE_EMPTY, NULL, "" },
5017 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5022 static struct TokenInfo setup_info_shortcuts_3[] =
5024 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5025 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5026 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5027 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5028 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5029 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5030 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5031 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5032 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5033 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5034 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5035 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5036 { TYPE_EMPTY, NULL, "" },
5037 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5042 static struct TokenInfo setup_info_shortcuts_4[] =
5044 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5045 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5046 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5047 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5048 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5049 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5050 { TYPE_EMPTY, NULL, "" },
5051 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5056 static struct TokenInfo setup_info_shortcuts_5[] =
5058 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5059 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5060 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5061 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5062 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5063 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5064 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5065 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5066 { TYPE_EMPTY, NULL, "" },
5067 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5072 static Key getSetupKey()
5074 Key key = KSYM_UNDEFINED;
5075 boolean got_key_event = FALSE;
5077 while (!got_key_event)
5079 if (PendingEvent()) /* got event */
5087 case EVENT_KEYPRESS:
5089 key = GetEventKey((KeyEvent *)&event, TRUE);
5091 /* press 'Escape' or 'Enter' to keep the existing key binding */
5092 if (key == KSYM_Escape || key == KSYM_Return)
5093 key = KSYM_UNDEFINED; /* keep old value */
5095 got_key_event = TRUE;
5099 case EVENT_KEYRELEASE:
5100 key_joystick_mapping = 0;
5104 HandleOtherEvents(&event);
5112 /* don't eat all CPU time */
5119 static int getSetupTextFont(int type)
5121 if (type & (TYPE_SWITCH |
5133 static int getSetupValueFont(int type, void *value)
5135 if (type & TYPE_KEY)
5136 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5137 else if (type & TYPE_STRING)
5138 return FONT_VALUE_2;
5139 else if (type & TYPE_ECS_AGA)
5140 return FONT_VALUE_1;
5141 else if (type & TYPE_BOOLEAN_STYLE)
5142 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5143 else if (type & TYPE_YES_NO_AUTO)
5144 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5145 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5147 return FONT_VALUE_1;
5150 static void drawSetupValue(int pos)
5152 boolean font_draw_xoffset_modified = FALSE;
5153 int font_draw_xoffset_old = -1;
5154 int xpos = MENU_SCREEN_VALUE_XPOS;
5155 int ypos = MENU_SCREEN_START_YPOS + pos;
5156 int startx = mSX + xpos * 32;
5157 int starty = mSY + ypos * 32;
5158 int font_nr, font_width;
5162 int type = setup_info[pos].type;
5163 void *value = setup_info[pos].value;
5164 char *value_string = getSetupValue(type, value);
5169 if (value_string == NULL)
5172 if (type & TYPE_KEY)
5174 xpos = MENU_SCREEN_START_XPOS;
5176 if (type & TYPE_QUERY)
5177 value_string = "<press key>";
5179 else if (type & TYPE_STRING)
5181 int max_value_len = (SCR_FIELDX - 2) * 2;
5183 xpos = MENU_SCREEN_START_XPOS;
5185 if (strlen(value_string) > max_value_len)
5186 value_string[max_value_len] = '\0';
5188 else if (type & TYPE_YES_NO_AUTO)
5190 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5193 startx = mSX + xpos * 32;
5194 starty = mSY + ypos * 32;
5195 font_nr = getSetupValueFont(type, value);
5196 font_width = getFontWidth(font_nr);
5198 font_height = getFontHeight(font_nr);
5201 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5202 if (setup_mode != SETUP_MODE_INPUT)
5204 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5205 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5206 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5207 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5208 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5209 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5210 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5211 boolean correct_font_draw_xoffset = FALSE;
5213 if (xpos == MENU_SCREEN_START_XPOS &&
5214 startx + font1_xoffset < text_startx + text_font_xoffset)
5215 correct_font_draw_xoffset = TRUE;
5217 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5218 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5219 correct_font_draw_xoffset = TRUE;
5221 /* check if setup value would overlap with setup text when printed */
5222 /* (this can happen for extreme/wrong values for font draw offset) */
5223 if (correct_font_draw_xoffset)
5225 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5226 font_draw_xoffset_modified = TRUE;
5228 if (type & TYPE_KEY)
5229 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5230 else if (!(type & TYPE_STRING))
5231 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5232 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5237 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5239 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5240 DrawText(startx + i * font_width, starty, " ", font_nr);
5243 DrawText(startx, starty, value_string, font_nr);
5245 if (font_draw_xoffset_modified)
5246 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5249 static void changeSetupValue(int pos, int dx)
5251 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5253 *(boolean *)setup_info[pos].value ^= TRUE;
5255 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5257 *(int *)setup_info[pos].value =
5259 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5260 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5261 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5262 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5264 else if (setup_info[pos].type & TYPE_KEY)
5268 setup_info[pos].type |= TYPE_QUERY;
5269 drawSetupValue(pos);
5270 setup_info[pos].type &= ~TYPE_QUERY;
5272 key = getSetupKey();
5273 if (key != KSYM_UNDEFINED)
5274 *(Key *)setup_info[pos].value = key;
5277 drawSetupValue(pos);
5279 // fullscreen state may have changed at this point
5280 if (setup_info[pos].value == &setup.fullscreen)
5281 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5284 static void DrawCursorAndText_Setup(int pos, boolean active)
5286 int xpos = MENU_SCREEN_START_XPOS;
5287 int ypos = MENU_SCREEN_START_YPOS + pos;
5288 int font_nr = getSetupTextFont(setup_info[pos].type);
5290 if (setup_info == setup_info_input)
5291 font_nr = FONT_MENU_1;
5294 font_nr = FONT_ACTIVE(font_nr);
5296 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5298 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5299 drawCursor(pos, active);
5302 static void DrawSetupScreen_Generic()
5304 boolean redraw_all = FALSE;
5305 char *title_string = NULL;
5309 CloseDoor(DOOR_CLOSE_2);
5311 if (redraw_mask & REDRAW_ALL)
5315 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5316 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5317 int2str(0, redraw_mask)));
5321 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5322 FadeOut(redraw_mask);
5324 FadeOut(REDRAW_FIELD);
5329 if (setup_mode == SETUP_MODE_MAIN)
5331 setup_info = setup_info_main;
5332 title_string = "Setup";
5334 else if (setup_mode == SETUP_MODE_GAME)
5336 setup_info = setup_info_game;
5337 title_string = "Setup Game";
5339 else if (setup_mode == SETUP_MODE_EDITOR)
5341 setup_info = setup_info_editor;
5342 title_string = "Setup Editor";
5344 else if (setup_mode == SETUP_MODE_GRAPHICS)
5346 setup_info = setup_info_graphics;
5347 title_string = "Setup Graphics";
5349 else if (setup_mode == SETUP_MODE_SOUND)
5351 setup_info = setup_info_sound;
5352 title_string = "Setup Sound";
5354 else if (setup_mode == SETUP_MODE_ARTWORK)
5356 setup_info = setup_info_artwork;
5357 title_string = "Custom Artwork";
5359 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5361 setup_info = setup_info_shortcuts;
5362 title_string = "Setup Shortcuts";
5364 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5366 setup_info = setup_info_shortcuts_1;
5367 title_string = "Setup Shortcuts";
5369 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5371 setup_info = setup_info_shortcuts_2;
5372 title_string = "Setup Shortcuts";
5374 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5376 setup_info = setup_info_shortcuts_3;
5377 title_string = "Setup Shortcuts";
5379 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5381 setup_info = setup_info_shortcuts_4;
5382 title_string = "Setup Shortcuts";
5384 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5386 setup_info = setup_info_shortcuts_5;
5387 title_string = "Setup Shortcuts";
5390 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5394 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5396 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5399 void *value_ptr = setup_info[i].value;
5401 /* set some entries to "unchangeable" according to other variables */
5402 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5403 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5404 (value_ptr == &setup.sound_music && !audio.music_available) ||
5405 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5406 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5407 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5408 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5409 setup_info[i].type |= TYPE_GHOSTED;
5411 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5412 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5413 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5414 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5415 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5416 initCursor(i, IMG_MENU_BUTTON);
5418 DrawCursorAndText_Setup(i, FALSE);
5420 if (setup_info[i].type & TYPE_VALUE)
5427 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5428 "Joysticks deactivated in setup menu");
5432 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5436 redraw_mask = REDRAW_ALL;
5439 FadeIn(redraw_mask);
5441 FadeIn(REDRAW_FIELD);
5446 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5450 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5452 static int choice_store[MAX_SETUP_MODES];
5453 int choice = choice_store[setup_mode]; /* always starts with 0 */
5457 if (button == MB_MENU_INITIALIZE)
5459 /* advance to first valid menu entry */
5460 while (choice < num_setup_info &&
5461 setup_info[choice].type & TYPE_SKIP_ENTRY)
5463 choice_store[setup_mode] = choice;
5465 DrawCursorAndText_Setup(choice, TRUE);
5469 else if (button == MB_MENU_LEAVE)
5471 PlaySound(SND_MENU_ITEM_SELECTING);
5473 // for (y = 0; y < num_setup_info; y++)
5474 for (y = 0; setup_info[y].type != 0; y++)
5476 if (setup_info[y].type & TYPE_LEAVE_MENU)
5478 void (*menu_callback_function)(void) = setup_info[y].value;
5482 menu_callback_function();
5484 break; /* absolutely needed because function changes 'setup_info'! */
5491 if (mx || my) /* mouse input */
5493 x = (mx - mSX) / 32;
5494 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5496 else if (dx || dy) /* keyboard input */
5500 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5502 if (setup_info[choice].type & menu_navigation_type ||
5503 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5504 setup_info[choice].type & TYPE_YES_NO_AUTO)
5505 button = MB_MENU_CHOICE;
5510 /* jump to next non-empty menu entry (up or down) */
5511 while (y > 0 && y < num_setup_info - 1 &&
5512 setup_info[y].type & TYPE_SKIP_ENTRY)
5516 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5520 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5522 PlaySound(SND_MENU_ITEM_ACTIVATING);
5524 DrawCursorAndText_Setup(choice, FALSE);
5525 DrawCursorAndText_Setup(y, TRUE);
5527 choice = choice_store[setup_mode] = y;
5530 else if (!(setup_info[y].type & TYPE_GHOSTED))
5532 PlaySound(SND_MENU_ITEM_SELECTING);
5534 /* when selecting key headline, execute function for key value change */
5535 if (setup_info[y].type & TYPE_KEYTEXT &&
5536 setup_info[y + 1].type & TYPE_KEY)
5539 /* when selecting string value, execute function for list selection */
5540 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5541 setup_info[y - 1].type & TYPE_ENTER_LIST)
5544 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5546 void (*menu_callback_function)(void) = setup_info[y].value;
5548 FadeSetFromType(setup_info[y].type);
5550 menu_callback_function();
5554 if (setup_info[y].type & TYPE_VALUE)
5555 changeSetupValue(y, dx);
5561 void DrawSetupScreen_Input()
5566 FadeOut(REDRAW_FIELD);
5572 setup_info = setup_info_input;
5575 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5579 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5580 "Joysticks deactivated on this screen");
5582 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5583 "Joysticks deactivated on this screen");
5588 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5590 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5593 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5594 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5595 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5596 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5597 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5598 initCursor(i, IMG_MENU_BUTTON);
5600 DrawCursorAndText_Setup(i, FALSE);
5604 DeactivateJoystickForCalibration();
5609 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5610 "Joysticks deactivated on this screen");
5612 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5613 "Joysticks deactivated on this screen");
5617 /* create gadgets for setup input menu screen */
5618 FreeScreenGadgets();
5619 CreateScreenGadgets();
5621 /* map gadgets for setup input menu screen */
5622 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5624 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5627 FadeIn(REDRAW_FIELD);
5633 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5635 if (device_name == NULL)
5638 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5641 if (strlen(device_name) > 1)
5643 char c1 = device_name[strlen(device_name) - 1];
5644 char c2 = device_name[strlen(device_name) - 2];
5646 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5647 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5650 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5651 strlen(device_name));
5654 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5657 static struct SetupKeyboardInfo custom_key;
5664 { &custom_key.left, "Joystick Left" },
5665 { &custom_key.right, "Joystick Right" },
5666 { &custom_key.up, "Joystick Up" },
5667 { &custom_key.down, "Joystick Down" },
5668 { &custom_key.snap, "Button 1" },
5669 { &custom_key.drop, "Button 2" }
5671 static char *joystick_name[MAX_PLAYERS] =
5678 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5682 custom_key = setup.input[player_nr].key;
5684 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5685 FONT_INPUT_1_ACTIVE);
5687 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5689 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5690 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5692 if (setup.input[player_nr].use_joystick)
5694 char *device_name = setup.input[player_nr].joy.device_name;
5695 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5696 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5698 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5699 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5703 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5704 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5707 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5709 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5710 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5711 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5712 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5714 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5715 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5716 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5717 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5718 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5719 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5721 for (i = 0; i < 6; i++)
5723 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5725 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5727 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5728 (setup.input[player_nr].use_joystick ?
5730 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5734 static int input_player_nr = 0;
5736 void HandleSetupScreen_Input_Player(int step, int direction)
5738 int old_player_nr = input_player_nr;
5741 new_player_nr = old_player_nr + step * direction;
5742 if (new_player_nr < 0)
5744 if (new_player_nr > MAX_PLAYERS - 1)
5745 new_player_nr = MAX_PLAYERS - 1;
5747 if (new_player_nr != old_player_nr)
5749 input_player_nr = new_player_nr;
5751 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5755 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5757 static int choice = 0;
5760 int pos_start = SETUPINPUT_SCREEN_POS_START;
5761 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5762 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5763 int pos_end = SETUPINPUT_SCREEN_POS_END;
5765 if (button == MB_MENU_INITIALIZE)
5767 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5769 DrawCursorAndText_Setup(choice, TRUE);
5773 else if (button == MB_MENU_LEAVE)
5775 setup_mode = SETUP_MODE_MAIN;
5782 if (mx || my) /* mouse input */
5784 x = (mx - mSX) / 32;
5785 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5787 else if (dx || dy) /* keyboard input */
5789 if (dx && choice == 0)
5790 x = (dx < 0 ? 10 : 12);
5791 else if ((dx && choice == 1) ||
5792 (dx == +1 && choice == 2) ||
5793 (dx == -1 && choice == pos_end))
5794 button = MB_MENU_CHOICE;
5798 if (y >= pos_empty1 && y <= pos_empty2)
5799 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5802 if (y == 0 && dx != 0 && button)
5804 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5806 else if (IN_VIS_FIELD(x, y) &&
5807 y >= pos_start && y <= pos_end &&
5808 !(y >= pos_empty1 && y <= pos_empty2))
5814 DrawCursorAndText_Setup(choice, FALSE);
5815 DrawCursorAndText_Setup(y, TRUE);
5817 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5826 char *device_name = setup.input[input_player_nr].joy.device_name;
5828 if (!setup.input[input_player_nr].use_joystick)
5830 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5832 setJoystickDeviceToNr(device_name, new_device_nr);
5833 setup.input[input_player_nr].use_joystick = TRUE;
5837 int device_nr = getJoystickNrFromDeviceName(device_name);
5838 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5840 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5841 setup.input[input_player_nr].use_joystick = FALSE;
5843 setJoystickDeviceToNr(device_name, new_device_nr);
5846 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5850 if (setup.input[input_player_nr].use_joystick)
5853 CalibrateJoystick(input_player_nr);
5856 CustomizeKeyboard(input_player_nr);
5858 else if (y == pos_end)
5864 setup_mode = SETUP_MODE_MAIN;
5871 void CustomizeKeyboard(int player_nr)
5875 boolean finished = FALSE;
5876 static struct SetupKeyboardInfo custom_key;
5881 } customize_step[] =
5883 { &custom_key.left, "Move Left" },
5884 { &custom_key.right, "Move Right" },
5885 { &custom_key.up, "Move Up" },
5886 { &custom_key.down, "Move Down" },
5887 { &custom_key.snap, "Snap Field" },
5888 { &custom_key.drop, "Drop Element" }
5891 /* read existing key bindings from player setup */
5892 custom_key = setup.input[player_nr].key;
5895 FadeOut(REDRAW_FIELD);
5899 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5907 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5908 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5909 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5910 "Key:", FONT_INPUT_1_ACTIVE);
5911 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5912 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5915 FadeIn(REDRAW_FIELD);
5922 if (PendingEvent()) /* got event */
5930 case EVENT_KEYPRESS:
5932 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5934 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5936 if (key == KSYM_Escape)
5937 FadeSkipNextFadeIn();
5943 /* all keys configured -- wait for "Escape" or "Return" key */
5947 /* press 'Enter' to keep the existing key binding */
5948 if (key == KSYM_Return)
5949 key = *customize_step[step_nr].key;
5951 /* check if key already used */
5952 for (i = 0; i < step_nr; i++)
5953 if (*customize_step[i].key == key)
5958 /* got new key binding */
5959 *customize_step[step_nr].key = key;
5960 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5962 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5963 getKeyNameFromKey(key), FONT_VALUE_1);
5966 /* un-highlight last query */
5967 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5968 customize_step[step_nr - 1].text, FONT_MENU_1);
5969 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5970 "Key:", FONT_MENU_1);
5972 /* press 'Enter' to leave */
5975 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5976 "Press Enter", FONT_TITLE_1);
5980 /* query next key binding */
5981 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5982 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5983 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5984 "Key:", FONT_INPUT_1_ACTIVE);
5985 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5986 getKeyNameFromKey(*customize_step[step_nr].key),
5991 case EVENT_KEYRELEASE:
5992 key_joystick_mapping = 0;
5996 HandleOtherEvents(&event);
6004 /* don't eat all CPU time */
6008 /* write new key bindings back to player setup */
6009 setup.input[player_nr].key = custom_key;
6012 DrawSetupScreen_Input();
6015 static boolean CalibrateJoystickMain(int player_nr)
6017 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6018 int new_joystick_xright = JOYSTICK_XMIDDLE;
6019 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6020 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6021 int new_joystick_xmiddle, new_joystick_ymiddle;
6023 int joystick_fd = joystick.fd[player_nr];
6024 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6025 boolean check[3][3];
6026 int check_remaining = 3 * 3;
6031 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6034 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6038 FadeOut(REDRAW_FIELD);
6042 for (y = 0; y < 3; y++)
6044 for (x = 0; x < 3; x++)
6046 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6047 check[x][y] = FALSE;
6051 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6052 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6053 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6054 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6055 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6056 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6057 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6059 joy_value = Joystick(player_nr);
6060 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6061 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6063 /* eventually uncalibrated center position (joystick could be uncentered) */
6064 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6067 new_joystick_xmiddle = joy_x;
6068 new_joystick_ymiddle = joy_y;
6070 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6072 FadeIn(REDRAW_FIELD);
6074 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6079 if (PendingEvent()) /* got event */
6087 case EVENT_KEYPRESS:
6088 switch (GetEventKey((KeyEvent *)&event, TRUE))
6091 if (check_remaining == 0)
6096 FadeSkipNextFadeIn();
6105 case EVENT_KEYRELEASE:
6106 key_joystick_mapping = 0;
6110 HandleOtherEvents(&event);
6115 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6118 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6119 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6120 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6121 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6123 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6124 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6125 setup.input[player_nr].joy.xright = new_joystick_xright;
6126 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6127 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6128 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6130 CheckJoystickData();
6132 joy_value = Joystick(player_nr);
6134 if (joy_value & JOY_BUTTON && check_remaining == 0)
6137 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6138 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6140 if (x != last_x || y != last_y)
6142 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6143 IMG_MENU_CALIBRATE_YELLOW, 0);
6144 DrawFixedGraphic(xpos + x, ypos + y,
6145 IMG_MENU_CALIBRATE_RED, 0);
6150 if (check_remaining > 0 && !check[x+1][y+1])
6152 check[x+1][y+1] = TRUE;
6158 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6159 setup.input[player_nr].joy.xleft,
6160 setup.input[player_nr].joy.xmiddle,
6161 setup.input[player_nr].joy.xright);
6162 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6163 setup.input[player_nr].joy.yupper,
6164 setup.input[player_nr].joy.ymiddle,
6165 setup.input[player_nr].joy.ylower);
6174 /* don't eat all CPU time */
6178 /* calibrated center position (joystick should now be centered) */
6179 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6182 new_joystick_xmiddle = joy_x;
6183 new_joystick_ymiddle = joy_y;
6188 DrawSetupScreen_Input();
6191 /* wait until the last pressed button was released */
6192 while (Joystick(player_nr) & JOY_BUTTON)
6194 if (PendingEvent()) /* got event */
6199 HandleOtherEvents(&event);
6208 void CalibrateJoystick(int player_nr)
6210 if (!CalibrateJoystickMain(player_nr))
6212 char *device_name = setup.input[player_nr].joy.device_name;
6213 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6214 int xpos = mSX - SX;
6215 int ypos = mSY - SY;
6219 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6220 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6223 Delay(2000); /* show error message for a short time */
6229 DrawSetupScreen_Input();
6233 void DrawSetupScreen()
6235 DeactivateJoystick();
6237 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6239 if (setup_mode == SETUP_MODE_INPUT)
6240 DrawSetupScreen_Input();
6241 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6242 DrawChooseTree(&game_speed_current);
6243 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6244 DrawChooseTree(&scroll_delay_current);
6245 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6246 DrawChooseTree(&screen_mode_current);
6247 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6248 DrawChooseTree(&window_size_current);
6249 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6250 DrawChooseTree(&scaling_type_current);
6251 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6252 DrawChooseTree(&artwork.gfx_current);
6253 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6254 DrawChooseTree(&artwork.snd_current);
6255 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6256 DrawChooseTree(&artwork.mus_current);
6257 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6258 DrawChooseTree(&volume_simple_current);
6259 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6260 DrawChooseTree(&volume_loops_current);
6261 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6262 DrawChooseTree(&volume_music_current);
6264 DrawSetupScreen_Generic();
6270 void RedrawSetupScreenAfterFullscreenToggle()
6273 if (setup_mode == SETUP_MODE_GRAPHICS ||
6274 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6276 // update list selection from "setup.window_scaling_percent"
6277 execSetupGraphics_setWindowSizes(TRUE);
6282 if (setup_mode == SETUP_MODE_GRAPHICS)
6287 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6289 if (setup_mode == SETUP_MODE_INPUT)
6290 HandleSetupScreen_Input(mx, my, dx, dy, button);
6291 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6292 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6293 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6294 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6295 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6296 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6297 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6298 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6299 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6300 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6301 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6302 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6303 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6304 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6305 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6306 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6307 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6308 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6309 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6310 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6311 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6312 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6314 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6321 void HandleGameActions()
6323 if (game_status != GAME_MODE_PLAYING)
6326 GameActions(); /* main game loop */
6328 if (tape.auto_play && !tape.playing)
6329 AutoPlayTape(); /* continue automatically playing next tape */
6333 /* ---------- new screen button stuff -------------------------------------- */
6335 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6340 case SCREEN_CTRL_ID_PREV_LEVEL:
6341 *x = mSX + menu.main.button.prev_level.x;
6342 *y = mSY + menu.main.button.prev_level.y;
6345 case SCREEN_CTRL_ID_NEXT_LEVEL:
6346 *x = mSX + menu.main.button.next_level.x;
6347 *y = mSY + menu.main.button.next_level.y;
6350 case SCREEN_CTRL_ID_PREV_LEVEL:
6351 *x = mSX + TILEX * getPrevlevelButtonPos();
6352 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6355 case SCREEN_CTRL_ID_NEXT_LEVEL:
6356 *x = mSX + TILEX * getNextLevelButtonPos();
6357 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6361 case SCREEN_CTRL_ID_PREV_PLAYER:
6362 *x = mSX + TILEX * 10;
6363 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6366 case SCREEN_CTRL_ID_NEXT_PLAYER:
6367 *x = mSX + TILEX * 12;
6368 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6372 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6378 int gfx_unpressed, gfx_pressed;
6379 void (*get_gadget_position)(int *, int *, int);
6383 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6386 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6387 getScreenMenuButtonPos,
6388 SCREEN_CTRL_ID_PREV_LEVEL,
6393 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6394 getScreenMenuButtonPos,
6395 SCREEN_CTRL_ID_NEXT_LEVEL,
6400 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6401 getScreenMenuButtonPos,
6402 SCREEN_CTRL_ID_PREV_PLAYER,
6407 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6408 getScreenMenuButtonPos,
6409 SCREEN_CTRL_ID_NEXT_PLAYER,
6417 int gfx_unpressed, gfx_pressed;
6421 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6424 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6426 -1, -1, /* these values are not constant, but can change at runtime */
6428 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6430 SCREEN_CTRL_ID_SCROLL_UP,
6434 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6436 -1, -1, /* these values are not constant, but can change at runtime */
6438 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6440 SCREEN_CTRL_ID_SCROLL_DOWN,
6447 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6448 Bitmap **gfx_unpressed, **gfx_pressed;
6450 int gfx_unpressed, gfx_pressed;
6457 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6460 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6461 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6463 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6466 -1, -1, /* these values are not constant, but can change at runtime */
6467 -1, -1, /* these values are not constant, but can change at runtime */
6469 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6470 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6472 GD_TYPE_SCROLLBAR_VERTICAL,
6473 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6474 "scroll level series vertically"
6478 static void CreateScreenMenubuttons()
6480 struct GadgetInfo *gi;
6481 unsigned int event_mask;
6484 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6486 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6487 int gfx_unpressed, gfx_pressed;
6488 int x, y, width, height;
6489 int gd_x1, gd_x2, gd_y1, gd_y2;
6490 int id = menubutton_info[i].gadget_id;
6492 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6494 menubutton_info[i].get_gadget_position(&x, &y, id);
6496 width = SC_MENUBUTTON_XSIZE;
6497 height = SC_MENUBUTTON_YSIZE;
6499 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6500 gfx_pressed = menubutton_info[i].gfx_pressed;
6501 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6502 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6503 gd_x1 = graphic_info[gfx_unpressed].src_x;
6504 gd_y1 = graphic_info[gfx_unpressed].src_y;
6505 gd_x2 = graphic_info[gfx_pressed].src_x;
6506 gd_y2 = graphic_info[gfx_pressed].src_y;
6508 gi = CreateGadget(GDI_CUSTOM_ID, id,
6509 GDI_CUSTOM_TYPE_ID, i,
6510 GDI_INFO_TEXT, menubutton_info[i].infotext,
6515 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6516 GDI_STATE, GD_BUTTON_UNPRESSED,
6517 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6518 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6519 GDI_DIRECT_DRAW, FALSE,
6520 GDI_EVENT_MASK, event_mask,
6521 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6525 Error(ERR_EXIT, "cannot create gadget");
6527 screen_gadget[id] = gi;
6531 static void CreateScreenScrollbuttons()
6533 struct GadgetInfo *gi;
6534 unsigned int event_mask;
6537 /* these values are not constant, but can change at runtime */
6538 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6539 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6540 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6541 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6543 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6545 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6546 int gfx_unpressed, gfx_pressed;
6547 int x, y, width, height;
6548 int gd_x1, gd_x2, gd_y1, gd_y2;
6549 int id = scrollbutton_info[i].gadget_id;
6551 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6553 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6554 y = mSY + scrollbutton_info[i].y;
6555 width = SC_SCROLLBUTTON_XSIZE;
6556 height = SC_SCROLLBUTTON_YSIZE;
6558 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6559 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6560 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6562 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6563 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6564 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6565 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6566 gd_x1 = graphic_info[gfx_unpressed].src_x;
6567 gd_y1 = graphic_info[gfx_unpressed].src_y;
6568 gd_x2 = graphic_info[gfx_pressed].src_x;
6569 gd_y2 = graphic_info[gfx_pressed].src_y;
6571 gi = CreateGadget(GDI_CUSTOM_ID, id,
6572 GDI_CUSTOM_TYPE_ID, i,
6573 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6578 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6579 GDI_STATE, GD_BUTTON_UNPRESSED,
6580 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6581 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6582 GDI_DIRECT_DRAW, FALSE,
6583 GDI_EVENT_MASK, event_mask,
6584 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6588 Error(ERR_EXIT, "cannot create gadget");
6590 screen_gadget[id] = gi;
6594 static void CreateScreenScrollbars()
6598 /* these values are not constant, but can change at runtime */
6599 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6600 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6601 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6602 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6604 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6606 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6607 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6608 int gfx_unpressed, gfx_pressed;
6610 int x, y, width, height;
6611 int gd_x1, gd_x2, gd_y1, gd_y2;
6612 struct GadgetInfo *gi;
6613 int items_max, items_visible, item_position;
6614 unsigned int event_mask;
6615 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6616 int id = scrollbar_info[i].gadget_id;
6618 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6620 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6621 y = mSY + scrollbar_info[i].y;
6622 width = scrollbar_info[i].width;
6623 height = scrollbar_info[i].height;
6625 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6626 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6628 items_max = num_page_entries;
6629 items_visible = num_page_entries;
6632 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6633 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6634 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6640 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6641 gfx_pressed = scrollbar_info[i].gfx_pressed;
6642 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6643 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6644 gd_x1 = graphic_info[gfx_unpressed].src_x;
6645 gd_y1 = graphic_info[gfx_unpressed].src_y;
6646 gd_x2 = graphic_info[gfx_pressed].src_x;
6647 gd_y2 = graphic_info[gfx_pressed].src_y;
6650 gi = CreateGadget(GDI_CUSTOM_ID, id,
6651 GDI_CUSTOM_TYPE_ID, i,
6652 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6657 GDI_TYPE, scrollbar_info[i].type,
6658 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6659 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6660 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6662 GDI_WHEEL_AREA_X, SX,
6663 GDI_WHEEL_AREA_Y, SY,
6664 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6665 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6667 GDI_WHEEL_AREA_X, 0,
6668 GDI_WHEEL_AREA_Y, 0,
6669 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6670 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6672 GDI_STATE, GD_BUTTON_UNPRESSED,
6673 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6674 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6675 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6676 GDI_DIRECT_DRAW, FALSE,
6677 GDI_EVENT_MASK, event_mask,
6678 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6682 Error(ERR_EXIT, "cannot create gadget");
6684 screen_gadget[id] = gi;
6688 void CreateScreenGadgets()
6690 int last_game_status = game_status; /* save current game status */
6692 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6695 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6697 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6699 /* copy pointers to clip mask and GC */
6700 scrollbar_bitmap[i]->clip_mask =
6701 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6702 scrollbar_bitmap[i]->stored_clip_gc =
6703 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6705 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6706 scrollbar_bitmap[i],
6707 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6708 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6709 TILEX, TILEY, 0, 0);
6713 CreateScreenMenubuttons();
6716 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6717 game_status = GAME_MODE_LEVELS;
6720 CreateScreenScrollbuttons();
6721 CreateScreenScrollbars();
6723 game_status = last_game_status; /* restore current game status */
6726 void FreeScreenGadgets()
6730 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6731 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6733 /* prevent freeing clip mask and GC twice */
6734 scrollbar_bitmap[i]->clip_mask = None;
6735 scrollbar_bitmap[i]->stored_clip_gc = None;
6737 FreeBitmap(scrollbar_bitmap[i]);
6741 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6742 FreeGadget(screen_gadget[i]);
6745 void MapScreenMenuGadgets(int screen_mask)
6749 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6750 if (screen_mask & menubutton_info[i].screen_mask)
6751 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6754 void MapScreenTreeGadgets(TreeInfo *ti)
6756 int num_entries = numTreeInfoInGroup(ti);
6759 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6762 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6763 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6765 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6766 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6769 static void HandleScreenGadgets(struct GadgetInfo *gi)
6771 int id = gi->custom_id;
6772 int button = gi->event.button;
6773 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6777 case SCREEN_CTRL_ID_PREV_LEVEL:
6778 HandleMainMenu_SelectLevel(step, -1);
6781 case SCREEN_CTRL_ID_NEXT_LEVEL:
6782 HandleMainMenu_SelectLevel(step, +1);
6785 case SCREEN_CTRL_ID_PREV_PLAYER:
6786 HandleSetupScreen_Input_Player(step, -1);
6789 case SCREEN_CTRL_ID_NEXT_PLAYER:
6790 HandleSetupScreen_Input_Player(step, +1);
6793 case SCREEN_CTRL_ID_SCROLL_UP:
6794 if (game_status == GAME_MODE_LEVELS)
6795 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6796 else if (game_status == GAME_MODE_LEVELNR)
6797 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6798 else if (game_status == GAME_MODE_SETUP)
6799 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6802 case SCREEN_CTRL_ID_SCROLL_DOWN:
6803 if (game_status == GAME_MODE_LEVELS)
6804 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6805 else if (game_status == GAME_MODE_LEVELNR)
6806 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6807 else if (game_status == GAME_MODE_SETUP)
6808 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6811 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6812 if (game_status == GAME_MODE_LEVELS)
6813 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6814 else if (game_status == GAME_MODE_LEVELNR)
6815 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6816 else if (game_status == GAME_MODE_SETUP)
6817 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);