1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
26 /* screens on the info screen */
27 #define INFO_MODE_MAIN 0
28 #define INFO_MODE_TITLE 1
29 #define INFO_MODE_ELEMENTS 2
30 #define INFO_MODE_MUSIC 3
31 #define INFO_MODE_CREDITS 4
32 #define INFO_MODE_PROGRAM 5
33 #define INFO_MODE_VERSION 6
34 #define INFO_MODE_LEVELSET 7
36 #define MAX_INFO_MODES 8
38 /* screens on the setup screen */
39 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
40 /* (should also match corresponding entries in src/conf_gfx.c) */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_TOUCH 7
49 #define SETUP_MODE_SHORTCUTS 8
50 #define SETUP_MODE_SHORTCUTS_1 9
51 #define SETUP_MODE_SHORTCUTS_2 10
52 #define SETUP_MODE_SHORTCUTS_3 11
53 #define SETUP_MODE_SHORTCUTS_4 12
54 #define SETUP_MODE_SHORTCUTS_5 13
56 /* sub-screens on the setup screen (generic) */
57 #define SETUP_MODE_CHOOSE_ARTWORK 14
58 #define SETUP_MODE_CHOOSE_OTHER 15
60 /* sub-screens on the setup screen (specific) */
61 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
64 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
65 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
66 #define SETUP_MODE_CHOOSE_RENDERING 21
67 #define SETUP_MODE_CHOOSE_GRAPHICS 22
68 #define SETUP_MODE_CHOOSE_SOUNDS 23
69 #define SETUP_MODE_CHOOSE_MUSIC 24
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
73 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
74 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
75 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
77 #define MAX_SETUP_MODES 31
79 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
81 /* for input setup functions */
82 #define SETUPINPUT_SCREEN_POS_START 0
83 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
84 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
85 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
87 /* for various menu stuff */
88 #define MENU_SCREEN_START_XPOS 1
89 #define MENU_SCREEN_START_YPOS 2
90 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
91 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
103 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
104 MENU_SCREEN_INFO_YSTEP)
105 #define NUM_INFO_ELEMENTS_FROM_CONF \
106 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
107 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
108 MAX_MENU_ENTRIES_ON_SCREEN)
109 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
110 MAX_INFO_ELEMENTS_ON_SCREEN), \
111 NUM_INFO_ELEMENTS_FROM_CONF)
112 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
113 #define MAX_MENU_TEXT_LENGTH_BIG 13
114 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
116 /* buttons and scrollbars identifiers */
117 #define SCREEN_CTRL_ID_PREV_LEVEL 0
118 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
119 #define SCREEN_CTRL_ID_PREV_PLAYER 2
120 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
121 #define SCREEN_CTRL_ID_SCROLL_UP 4
122 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
123 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
125 #define NUM_SCREEN_GADGETS 7
127 #define NUM_SCREEN_MENUBUTTONS 4
128 #define NUM_SCREEN_SCROLLBUTTONS 2
129 #define NUM_SCREEN_SCROLLBARS 1
131 #define SCREEN_MASK_MAIN (1 << 0)
132 #define SCREEN_MASK_INPUT (1 << 1)
134 /* graphic position and size values for buttons and scrollbars */
135 #define SC_MENUBUTTON_XSIZE TILEX
136 #define SC_MENUBUTTON_YSIZE TILEY
138 #define SC_SCROLLBUTTON_XSIZE TILEX
139 #define SC_SCROLLBUTTON_YSIZE TILEY
141 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
143 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
144 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
145 SC_SCROLLBUTTON_YSIZE)
147 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
148 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
150 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
151 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
152 SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
156 SC_SCROLL_VERTICAL_YSIZE)
158 #define SC_BORDER_SIZE 14
161 /* forward declarations of internal functions */
162 static void HandleScreenGadgets(struct GadgetInfo *);
163 static void HandleSetupScreen_Generic(int, int, int, int, int);
164 static void HandleSetupScreen_Input(int, int, int, int, int);
165 static void CustomizeKeyboard(int);
166 static void ConfigureJoystick(int);
167 static void execSetupGame(void);
168 static void execSetupGraphics(void);
169 static void execSetupSound(void);
170 static void execSetupTouch(void);
171 static void execSetupArtwork(void);
172 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
174 static void DrawChooseLevelSet(void);
175 static void DrawChooseLevelNr(void);
176 static void DrawInfoScreen(void);
177 static void DrawSetupScreen(void);
179 static void DrawInfoScreen_NotAvailable(char *, char *);
180 static void DrawInfoScreen_HelpAnim(int, int, boolean);
181 static void DrawInfoScreen_HelpText(int, int, int, int);
182 static void HandleInfoScreen_Main(int, int, int, int, int);
183 static void HandleInfoScreen_TitleScreen(int);
184 static void HandleInfoScreen_Elements(int);
185 static void HandleInfoScreen_Music(int);
186 static void HandleInfoScreen_Credits(int);
187 static void HandleInfoScreen_Program(int);
188 static void HandleInfoScreen_Version(int);
190 static void MapScreenMenuGadgets(int);
191 static void MapScreenGadgets(int);
192 static void MapScreenTreeGadgets(TreeInfo *);
194 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
196 static int info_mode = INFO_MODE_MAIN;
197 static int setup_mode = SETUP_MODE_MAIN;
199 static TreeInfo *window_sizes = NULL;
200 static TreeInfo *window_size_current = NULL;
202 static TreeInfo *scaling_types = NULL;
203 static TreeInfo *scaling_type_current = NULL;
205 static TreeInfo *rendering_modes = NULL;
206 static TreeInfo *rendering_mode_current = NULL;
208 static TreeInfo *scroll_delays = NULL;
209 static TreeInfo *scroll_delay_current = NULL;
211 static TreeInfo *snapshot_modes = NULL;
212 static TreeInfo *snapshot_mode_current = NULL;
214 static TreeInfo *game_speeds = NULL;
215 static TreeInfo *game_speed_current = NULL;
217 static TreeInfo *volumes_simple = NULL;
218 static TreeInfo *volume_simple_current = NULL;
220 static TreeInfo *volumes_loops = NULL;
221 static TreeInfo *volume_loops_current = NULL;
223 static TreeInfo *volumes_music = NULL;
224 static TreeInfo *volume_music_current = NULL;
226 static TreeInfo *touch_controls = NULL;
227 static TreeInfo *touch_control_current = NULL;
229 static TreeInfo *move_distances = NULL;
230 static TreeInfo *move_distance_current = NULL;
232 static TreeInfo *drop_distances = NULL;
233 static TreeInfo *drop_distance_current = NULL;
235 static TreeInfo *level_number = NULL;
236 static TreeInfo *level_number_current = NULL;
242 } window_sizes_list[] =
247 { 100, "100 % (Default)" },
264 } scaling_types_list[] =
266 { SCALING_QUALITY_NEAREST, "None" },
267 { SCALING_QUALITY_LINEAR, "Linear" },
268 { SCALING_QUALITY_BEST, "Anisotropic" },
277 } rendering_modes_list[] =
279 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
280 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
282 // this mode may work under certain conditions, but does not work on Windows
283 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
285 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
294 } game_speeds_list[] =
303 { 1000, "1/1s (Extremely Slow)" },
308 { 29, "1/35s (Original Supaplex)" },
310 { 20, "1/50s (Normal Speed)" },
311 { 14, "1/70s (Maximum Supaplex)" },
315 { 1, "1/1000s (Extremely Fast)" },
325 } scroll_delays_list[] =
327 { 0, "0 Tiles (No Scroll Delay)" },
330 { 3, "3 Tiles (Default)" },
335 { 8, "8 Tiles (Maximum Scroll Delay)"},
344 } snapshot_modes_list[] =
346 { STR_SNAPSHOT_MODE_OFF, "Off" },
347 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
348 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
349 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
382 } touch_controls_list[] =
384 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
385 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
386 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
410 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
411 (s) <= GAME_MODE_SETUP ? (s) : \
412 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
413 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
415 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
416 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
417 (i) <= INFO_MODE_LEVELSET ? (i) : \
420 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
421 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
422 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
423 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
424 SETUP_MODE_CHOOSE_ARTWORK : \
425 SETUP_MODE_CHOOSE_OTHER)
427 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
428 menu.draw_xoffset[GAME_MODE_INFO] : \
429 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
430 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
431 menu.draw_yoffset[GAME_MODE_INFO] : \
432 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
434 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
435 menu.draw_xoffset[GAME_MODE_SETUP] : \
436 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
437 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
438 menu.draw_yoffset[GAME_MODE_SETUP] : \
439 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
441 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
442 DRAW_XOFFSET_INFO(info_mode) : \
443 (s) == GAME_MODE_SETUP ? \
444 DRAW_XOFFSET_SETUP(setup_mode) : \
445 menu.draw_xoffset[DRAW_MODE(s)])
446 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
447 DRAW_YOFFSET_INFO(info_mode) : \
448 (s) == GAME_MODE_SETUP ? \
449 DRAW_YOFFSET_SETUP(setup_mode) : \
450 menu.draw_yoffset[DRAW_MODE(s)])
452 #define mSX (SX + DRAW_XOFFSET(game_status))
453 #define mSY (SY + DRAW_YOFFSET(game_status))
455 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
456 menu.list_size[game_status] : \
457 MAX_MENU_ENTRIES_ON_SCREEN)
459 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
460 NUM_MENU_ENTRIES_ON_SCREEN)
463 /* title display and control definitions */
465 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
466 2 * MAX_NUM_TITLE_MESSAGES)
468 #define NO_DIRECT_LEVEL_SELECT (-1)
471 static int num_title_screens = 0;
473 struct TitleControlInfo
482 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
484 /* main menu display and control definitions */
486 #define MAIN_CONTROL_NAME 0
487 #define MAIN_CONTROL_LEVELS 1
488 #define MAIN_CONTROL_SCORES 2
489 #define MAIN_CONTROL_EDITOR 3
490 #define MAIN_CONTROL_INFO 4
491 #define MAIN_CONTROL_GAME 5
492 #define MAIN_CONTROL_SETUP 6
493 #define MAIN_CONTROL_QUIT 7
494 #define MAIN_CONTROL_PREV_LEVEL 8
495 #define MAIN_CONTROL_NEXT_LEVEL 9
496 #define MAIN_CONTROL_FIRST_LEVEL 10
497 #define MAIN_CONTROL_LAST_LEVEL 11
498 #define MAIN_CONTROL_LEVEL_NUMBER 12
499 #define MAIN_CONTROL_LEVEL_INFO_1 13
500 #define MAIN_CONTROL_LEVEL_INFO_2 14
501 #define MAIN_CONTROL_LEVEL_NAME 15
502 #define MAIN_CONTROL_LEVEL_AUTHOR 16
503 #define MAIN_CONTROL_LEVEL_YEAR 17
504 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
505 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
506 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
507 #define MAIN_CONTROL_TITLE_1 21
508 #define MAIN_CONTROL_TITLE_2 22
509 #define MAIN_CONTROL_TITLE_3 23
511 static char str_main_text_name[10];
512 static char str_main_text_first_level[10];
513 static char str_main_text_last_level[10];
514 static char str_main_text_level_number[10];
516 static char *main_text_name = str_main_text_name;
517 static char *main_text_first_level = str_main_text_first_level;
518 static char *main_text_last_level = str_main_text_last_level;
519 static char *main_text_level_number = str_main_text_level_number;
520 static char *main_text_levels = "Levelset";
521 static char *main_text_scores = "Hall Of Fame";
522 static char *main_text_editor = "Level Creator";
523 static char *main_text_info = "Info Screen";
524 static char *main_text_game = "Start Game";
525 static char *main_text_setup = "Setup";
526 static char *main_text_quit = "Quit";
527 static char *main_text_level_name = level.name;
528 static char *main_text_level_author = level.author;
529 static char *main_text_level_year = NULL;
530 static char *main_text_level_imported_from = NULL;
531 static char *main_text_level_imported_by = NULL;
532 static char *main_text_level_tested_by = NULL;
534 struct MainControlInfo
538 struct MenuPosInfo *pos_button;
541 struct TextPosInfo *pos_text;
544 struct TextPosInfo *pos_input;
548 static struct MainControlInfo main_controls[] =
552 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
553 &menu.main.text.name, &main_text_name,
554 &menu.main.input.name, &setup.player_name,
558 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
559 &menu.main.text.levels, &main_text_levels,
564 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
565 &menu.main.text.scores, &main_text_scores,
570 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
571 &menu.main.text.editor, &main_text_editor,
576 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
577 &menu.main.text.info, &main_text_info,
582 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
583 &menu.main.text.game, &main_text_game,
588 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
589 &menu.main.text.setup, &main_text_setup,
594 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
595 &menu.main.text.quit, &main_text_quit,
599 /* (these two buttons are real gadgets) */
601 MAIN_CONTROL_PREV_LEVEL,
602 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
607 MAIN_CONTROL_NEXT_LEVEL,
608 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
614 MAIN_CONTROL_FIRST_LEVEL,
616 &menu.main.text.first_level, &main_text_first_level,
620 MAIN_CONTROL_LAST_LEVEL,
622 &menu.main.text.last_level, &main_text_last_level,
626 MAIN_CONTROL_LEVEL_NUMBER,
628 &menu.main.text.level_number, &main_text_level_number,
632 MAIN_CONTROL_LEVEL_INFO_1,
634 &menu.main.text.level_info_1, NULL,
638 MAIN_CONTROL_LEVEL_INFO_2,
640 &menu.main.text.level_info_2, NULL,
644 MAIN_CONTROL_LEVEL_NAME,
646 &menu.main.text.level_name, &main_text_level_name,
650 MAIN_CONTROL_LEVEL_AUTHOR,
652 &menu.main.text.level_author, &main_text_level_author,
656 MAIN_CONTROL_LEVEL_YEAR,
658 &menu.main.text.level_year, &main_text_level_year,
662 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
664 &menu.main.text.level_imported_from, &main_text_level_imported_from,
668 MAIN_CONTROL_LEVEL_IMPORTED_BY,
670 &menu.main.text.level_imported_by, &main_text_level_imported_by,
674 MAIN_CONTROL_LEVEL_TESTED_BY,
676 &menu.main.text.level_tested_by, &main_text_level_tested_by,
680 MAIN_CONTROL_TITLE_1,
682 &menu.main.text.title_1, &setup.internal.program_title,
686 MAIN_CONTROL_TITLE_2,
688 &menu.main.text.title_2, &setup.internal.program_copyright,
692 MAIN_CONTROL_TITLE_3,
694 &menu.main.text.title_3, &setup.internal.program_company,
707 static int getTitleScreenGraphic(int nr, boolean initial)
709 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
712 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
714 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
718 static int getTitleScreenGameMode(boolean initial)
720 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
724 static int getTitleMessageGameMode(boolean initial)
726 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
729 static int getTitleAnimMode(struct TitleControlInfo *tci)
731 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
733 return base + tci->local_nr;
737 static int getTitleScreenBackground(boolean initial)
739 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
744 static int getTitleMessageBackground(int nr, boolean initial)
746 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
750 static int getTitleBackground(int nr, boolean initial, boolean is_image)
752 int base = (is_image ?
753 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
754 IMG_BACKGROUND_TITLESCREEN_1) :
755 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
756 IMG_BACKGROUND_TITLEMESSAGE_1));
757 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
758 IMG_BACKGROUND_TITLE);
759 int graphic_local = base + nr;
761 if (graphic_info[graphic_local].bitmap != NULL)
762 return graphic_local;
764 if (graphic_info[graphic_global].bitmap != NULL)
765 return graphic_global;
767 return IMG_UNDEFINED;
770 static int getTitleSound(struct TitleControlInfo *tci)
772 boolean is_image = tci->is_image;
773 int initial = tci->initial;
774 int nr = tci->local_nr;
775 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
776 int base = (is_image ?
777 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
778 SND_BACKGROUND_TITLESCREEN_1) :
779 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
780 SND_BACKGROUND_TITLEMESSAGE_1));
781 int sound_global = menu.sound[mode];
782 int sound_local = base + nr;
785 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
786 nr, initial, is_image,
787 sound_global, getSoundListEntry(sound_global)->filename,
788 sound_local, getSoundListEntry(sound_local)->filename);
791 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
794 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
797 return SND_UNDEFINED;
800 static int getTitleMusic(struct TitleControlInfo *tci)
802 boolean is_image = tci->is_image;
803 int initial = tci->initial;
804 int nr = tci->local_nr;
805 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
806 int base = (is_image ?
807 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
808 MUS_BACKGROUND_TITLESCREEN_1) :
809 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
810 MUS_BACKGROUND_TITLEMESSAGE_1));
811 int music_global = menu.music[mode];
812 int music_local = base + nr;
815 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
816 nr, initial, is_image,
817 music_global, getMusicListEntry(music_global)->filename,
818 music_local, getMusicListEntry(music_local)->filename);
821 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
824 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
827 return MUS_UNDEFINED;
830 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
832 boolean is_image = tci->is_image;
833 boolean initial = tci->initial;
834 boolean first = tci->first;
835 int nr = tci->local_nr;
836 struct TitleMessageInfo tmi;
837 struct TitleFadingInfo ti;
839 tmi = (is_image ? (initial ? (first ?
840 titlescreen_initial_first[nr] :
841 titlescreen_initial[nr])
843 titlescreen_first[nr] :
845 : (initial ? (first ?
846 titlemessage_initial_first[nr] :
847 titlemessage_initial[nr])
849 titlemessage_first[nr] :
852 ti.fade_mode = tmi.fade_mode;
853 ti.fade_delay = tmi.fade_delay;
854 ti.post_delay = tmi.post_delay;
855 ti.auto_delay = tmi.auto_delay;
860 static int compareTitleControlInfo(const void *object1, const void *object2)
862 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
863 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
866 if (tci1->initial != tci2->initial)
867 compare_result = (tci1->initial ? -1 : +1);
868 else if (tci1->sort_priority != tci2->sort_priority)
869 compare_result = tci1->sort_priority - tci2->sort_priority;
870 else if (tci1->is_image != tci2->is_image)
871 compare_result = (tci1->is_image ? -1 : +1);
873 compare_result = tci1->local_nr - tci2->local_nr;
875 return compare_result;
878 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
880 int nr, int sort_priority)
882 title_controls[num_title_screens].is_image = is_image;
883 title_controls[num_title_screens].initial = initial;
884 title_controls[num_title_screens].local_nr = nr;
885 title_controls[num_title_screens].sort_priority = sort_priority;
887 title_controls[num_title_screens].first = FALSE; /* will be set later */
892 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
896 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
898 int graphic = getTitleScreenGraphic(i, initial);
899 Bitmap *bitmap = graphic_info[graphic].bitmap;
900 int sort_priority = graphic_info[graphic].sort_priority;
903 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
906 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
908 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
909 char *filename = getLevelSetTitleMessageFilename(i, initial);
910 int sort_priority = tmi->sort_priority;
912 if (filename != NULL)
913 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
917 static void InitializeTitleControls(boolean show_title_initial)
919 num_title_screens = 0;
921 /* 1st step: initialize title screens for game start (only when starting) */
922 if (show_title_initial)
923 InitializeTitleControls_CheckTitleInfo(TRUE);
925 /* 2nd step: initialize title screens for current level set */
926 InitializeTitleControls_CheckTitleInfo(FALSE);
928 /* sort title screens according to sort_priority and title number */
929 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
930 compareTitleControlInfo);
932 /* mark first title screen */
933 title_controls[0].first = TRUE;
936 static boolean visibleMenuPos(struct MenuPosInfo *pos)
938 return (pos != NULL && pos->x != -1 && pos->y != -1);
941 static boolean visibleTextPos(struct TextPosInfo *pos)
943 return (pos != NULL && pos->x != -1 && pos->y != -1);
946 static void InitializeMainControls()
948 boolean local_team_mode = (!options.network && setup.team_mode);
951 /* set main control text values to dynamically determined values */
952 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
954 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
955 menu.main.text.first_level.size));
956 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
957 menu.main.text.last_level.size));
958 strcpy(main_text_level_number, int2str(level_nr,
959 menu.main.text.level_number.size));
961 main_text_level_year = leveldir_current->year;
962 main_text_level_imported_from = leveldir_current->imported_from;
963 main_text_level_imported_by = leveldir_current->imported_by;
964 main_text_level_tested_by = leveldir_current->tested_by;
966 /* set main control screen positions to dynamically determined values */
967 for (i = 0; main_controls[i].nr != -1; i++)
969 struct MainControlInfo *mci = &main_controls[i];
971 struct MenuPosInfo *pos_button = mci->pos_button;
972 struct TextPosInfo *pos_text = mci->pos_text;
973 struct TextPosInfo *pos_input = mci->pos_input;
974 char *text = (mci->text ? *mci->text : NULL);
975 char *input = (mci->input ? *mci->input : NULL);
976 int button_graphic = mci->button_graphic;
977 int font_text = (pos_text ? pos_text->font : -1);
978 int font_input = (pos_input ? pos_input->font : -1);
980 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
981 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
982 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
983 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
984 int text_chars = (text != NULL ? strlen(text) : 0);
985 int input_chars = (input != NULL ? strlen(input) : 0);
988 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
990 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
991 int text_width = font_text_width * text_chars;
992 int text_height = font_text_height;
993 int input_width = font_input_width * input_chars;
994 int input_height = font_input_height;
996 if (nr == MAIN_CONTROL_NAME)
998 menu.main.input.name.width = input_width;
999 menu.main.input.name.height = input_height;
1002 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1004 pos_button->width = button_width;
1005 pos_button->height = button_height;
1008 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1010 /* calculate size for non-clickable text -- needed for text alignment */
1011 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1013 if (pos_text->width == -1 || calculate_text_size)
1014 pos_text->width = text_width;
1015 if (pos_text->height == -1 || calculate_text_size)
1016 pos_text->height = text_height;
1018 if (visibleMenuPos(pos_button))
1020 if (pos_text->x == -1)
1021 pos_text->x = pos_button->x + pos_button->width;
1022 if (pos_text->y == -1)
1024 pos_button->y + (pos_button->height - pos_text->height) / 2;
1028 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1030 if (visibleTextPos(pos_text))
1032 if (pos_input->x == -1)
1033 pos_input->x = pos_text->x + pos_text->width;
1034 if (pos_input->y == -1)
1035 pos_input->y = pos_text->y;
1038 if (pos_input->width == -1)
1039 pos_input->width = input_width;
1040 if (pos_input->height == -1)
1041 pos_input->height = input_height;
1046 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1047 int graphic, boolean pressed)
1049 struct GraphicInfo *g = &graphic_info[graphic];
1052 int xoffset = (pressed ? g->pressed_xoffset : 0);
1053 int yoffset = (pressed ? g->pressed_yoffset : 0);
1055 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1057 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1058 g->width, g->height, dst_x, dst_y);
1061 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1062 boolean active_input,
1063 boolean pressed_button)
1067 for (i = 0; main_controls[i].nr != -1; i++)
1069 struct MainControlInfo *mci = &main_controls[i];
1071 if (mci->nr == nr || nr == -1)
1073 struct MenuPosInfo *pos_button = mci->pos_button;
1074 struct TextPosInfo *pos_text = mci->pos_text;
1075 struct TextPosInfo *pos_input = mci->pos_input;
1076 char *text = (mci->text ? *mci->text : NULL);
1077 char *input = (mci->input ? *mci->input : NULL);
1078 int button_graphic = mci->button_graphic;
1079 int font_text = (pos_text ? pos_text->font : -1);
1080 int font_input = (pos_input ? pos_input->font : -1);
1084 button_graphic = BUTTON_ACTIVE(button_graphic);
1085 font_text = FONT_ACTIVE(font_text);
1090 font_input = FONT_ACTIVE(font_input);
1093 if (visibleMenuPos(pos_button))
1095 struct MenuPosInfo *pos = pos_button;
1096 int x = mSX + pos->x;
1097 int y = mSY + pos->y;
1099 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1100 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1103 if (visibleTextPos(pos_text) && text != NULL)
1105 struct TextPosInfo *pos = pos_text;
1106 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1107 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1110 /* (check why/if this is needed) */
1111 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1113 DrawText(x, y, text, font_text);
1116 if (visibleTextPos(pos_input) && input != NULL)
1118 struct TextPosInfo *pos = pos_input;
1119 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1120 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1123 /* (check why/if this is needed) */
1124 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1126 DrawText(x, y, input, font_input);
1132 static void DrawCursorAndText_Main(int nr, boolean active_text,
1133 boolean pressed_button)
1135 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1139 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1140 boolean pressed_button)
1142 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1146 static struct MainControlInfo *getMainControlInfo(int nr)
1150 for (i = 0; main_controls[i].nr != -1; i++)
1151 if (main_controls[i].nr == nr)
1152 return &main_controls[i];
1157 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1162 int rect_x = ALIGNED_TEXT_XPOS(rect);
1163 int rect_y = ALIGNED_TEXT_YPOS(rect);
1165 return (x >= rect_x && x < rect_x + rect->width &&
1166 y >= rect_y && y < rect_y + rect->height);
1169 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1174 int rect_x = ALIGNED_TEXT_XPOS(rect);
1175 int rect_y = ALIGNED_TEXT_YPOS(rect);
1178 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1179 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1180 (x >= rect_x && x < rect_x + rect->width &&
1181 y >= rect_y && y < rect_y + rect->height));
1184 return (x >= rect_x && x < rect_x + rect->width &&
1185 y >= rect_y && y < rect_y + rect->height);
1188 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1190 int rect_width = preview->xsize * preview->tile_size;
1191 int rect_height = preview->ysize * preview->tile_size;
1192 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1193 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1195 return (x >= rect_x && x < rect_x + rect_width &&
1196 y >= rect_y && y < rect_y + rect_height);
1199 static void AdjustScrollbar(int id, int items_max, int items_visible,
1202 struct GadgetInfo *gi = screen_gadget[id];
1204 if (item_position > items_max - items_visible)
1205 item_position = items_max - items_visible;
1207 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1208 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1209 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1212 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1214 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1218 static void clearMenuListArea()
1220 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1222 /* correct scrollbar position if placed outside menu (playfield) area */
1223 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1224 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1226 /* clear menu list area, but not title or scrollbar */
1227 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1228 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1231 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1233 static int cursor_array[MAX_LEV_FIELDY];
1234 int x = mSX + TILEX * xpos;
1235 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1240 cursor_array[ypos] = graphic;
1242 graphic = cursor_array[ypos];
1246 graphic = BUTTON_ACTIVE(graphic);
1248 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1249 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1252 static void initCursor(int ypos, int graphic)
1254 drawCursorExt(0, ypos, FALSE, graphic);
1257 static void drawCursor(int ypos, boolean active)
1259 drawCursorExt(0, ypos, active, -1);
1262 static void drawCursorXY(int xpos, int ypos, int graphic)
1264 drawCursorExt(xpos, ypos, FALSE, graphic);
1267 static void drawChooseTreeCursor(int ypos, boolean active)
1269 drawCursorExt(0, ypos, active, -1);
1274 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1275 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1276 setup.internal.program_copyright);
1279 void DrawTitleScreenImage(int nr, boolean initial)
1281 int graphic = getTitleScreenGraphic(nr, initial);
1282 Bitmap *bitmap = graphic_info[graphic].bitmap;
1283 int width = graphic_info[graphic].width;
1284 int height = graphic_info[graphic].height;
1285 int src_x = graphic_info[graphic].src_x;
1286 int src_y = graphic_info[graphic].src_y;
1292 if (width > WIN_XSIZE)
1294 /* image width too large for window => center image horizontally */
1295 src_x = (width - WIN_XSIZE) / 2;
1299 if (height > WIN_YSIZE)
1301 /* image height too large for window => center image vertically */
1302 src_y = (height - WIN_YSIZE) / 2;
1306 /* always display title screens centered */
1307 dst_x = (WIN_XSIZE - width) / 2;
1308 dst_y = (WIN_YSIZE - height) / 2;
1310 SetDrawBackgroundMask(REDRAW_ALL);
1311 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1313 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1315 if (DrawingOnBackground(dst_x, dst_y))
1316 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1318 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1320 redraw_mask = REDRAW_ALL;
1323 void DrawTitleScreenMessage(int nr, boolean initial)
1325 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1326 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1328 if (filename == NULL)
1331 /* force TITLE font on title message screen */
1332 SetFontStatus(getTitleMessageGameMode(initial));
1334 /* if chars *and* width set to "-1", automatically determine width */
1335 if (tmi->chars == -1 && tmi->width == -1)
1336 tmi->width = viewport.window[game_status].width;
1338 /* if lines *and* height set to "-1", automatically determine height */
1339 if (tmi->lines == -1 && tmi->height == -1)
1340 tmi->height = viewport.window[game_status].height;
1342 /* if chars set to "-1", automatically determine by text and font width */
1343 if (tmi->chars == -1)
1344 tmi->chars = tmi->width / getFontWidth(tmi->font);
1346 tmi->width = tmi->chars * getFontWidth(tmi->font);
1348 /* if lines set to "-1", automatically determine by text and font height */
1349 if (tmi->lines == -1)
1350 tmi->lines = tmi->height / getFontHeight(tmi->font);
1352 tmi->height = tmi->lines * getFontHeight(tmi->font);
1354 /* if x set to "-1", automatically determine by width and alignment */
1356 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1358 /* if y set to "-1", automatically determine by height and alignment */
1360 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1362 SetDrawBackgroundMask(REDRAW_ALL);
1363 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1365 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1367 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1368 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1369 tmi->autowrap, tmi->centered, tmi->parse_comments);
1374 void DrawTitleScreen()
1376 KeyboardAutoRepeatOff();
1378 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1381 boolean CheckTitleScreen(boolean levelset_has_changed)
1383 static boolean show_title_initial = TRUE;
1384 boolean show_titlescreen = FALSE;
1386 /* needed to be able to skip title screen, if no image or message defined */
1387 InitializeTitleControls(show_title_initial);
1389 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1390 show_titlescreen = TRUE;
1392 /* show initial title images and messages only once at program start */
1393 show_title_initial = FALSE;
1395 return (show_titlescreen && num_title_screens > 0);
1400 static LevelDirTree *leveldir_last_valid = NULL;
1401 boolean levelset_has_changed = FALSE;
1402 int fade_mask = REDRAW_FIELD;
1404 LimitScreenUpdates(FALSE);
1406 FadeSetLeaveScreen();
1408 /* do not fade out here -- function may continue and fade on editor screen */
1411 FadeMenuSoundsAndMusic();
1413 ExpireSoundLoops(FALSE);
1415 KeyboardAutoRepeatOn();
1417 audio.sound_deactivated = FALSE;
1421 /* needed if last screen was the playing screen, invoked from level editor */
1422 if (level_editor_test_game)
1424 CloseDoor(DOOR_CLOSE_ALL);
1426 SetGameStatus(GAME_MODE_EDITOR);
1433 /* needed if last screen was the setup screen and fullscreen state changed */
1434 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1435 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1437 /* leveldir_current may be invalid (level group, parent link) */
1438 if (!validLevelSeries(leveldir_current))
1439 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1441 if (leveldir_current != leveldir_last_valid)
1442 levelset_has_changed = TRUE;
1444 /* store valid level series information */
1445 leveldir_last_valid = leveldir_current;
1447 init_last = init; /* switch to new busy animation */
1449 /* needed if last screen (level choice) changed graphics, sounds or music */
1450 ReloadCustomArtwork(0);
1452 if (CheckTitleScreen(levelset_has_changed))
1454 SetGameStatus(GAME_MODE_TITLE);
1461 if (redraw_mask & REDRAW_ALL)
1462 fade_mask = REDRAW_ALL;
1464 if (CheckIfGlobalBorderHasChanged())
1465 fade_mask = REDRAW_ALL;
1469 /* needed if different viewport properties defined for menues */
1470 ChangeViewportPropertiesIfNeeded();
1472 SetDrawtoField(DRAW_TO_BACKBUFFER);
1474 /* level_nr may have been set to value over handicap with level editor */
1475 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1476 level_nr = leveldir_current->handicap_level;
1478 LoadLevel(level_nr);
1479 LoadScore(level_nr);
1481 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1482 SetDrawDeactivationMask(REDRAW_NONE);
1483 SetDrawBackgroundMask(REDRAW_FIELD);
1485 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1488 if (fade_mask == REDRAW_ALL)
1489 RedrawGlobalBorder();
1494 InitializeMainControls();
1496 DrawCursorAndText_Main(-1, FALSE, FALSE);
1497 DrawPreviewLevelInitial();
1499 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1502 if (TAPE_IS_EMPTY(tape))
1504 DrawCompleteVideoDisplay();
1506 PlayMenuSoundsAndMusic();
1508 /* create gadgets for main menu screen */
1509 FreeScreenGadgets();
1510 CreateScreenGadgets();
1512 /* map gadgets for main menu screen */
1514 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1516 /* copy actual game door content to door double buffer for OpenDoor() */
1517 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1518 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1520 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1522 DrawMaskedBorder(fade_mask);
1527 /* update screen area with special editor door */
1528 redraw_mask |= REDRAW_ALL;
1531 SetMouseCursor(CURSOR_DEFAULT);
1533 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1536 static void gotoTopLevelDir()
1538 /* move upwards until inside (but not above) top level directory */
1539 while (leveldir_current->node_parent &&
1540 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1542 /* write a "path" into level tree for easy navigation to last level */
1543 if (leveldir_current->node_parent->node_group->cl_first == -1)
1545 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1546 int leveldir_pos = posTreeInfo(leveldir_current);
1547 int num_page_entries;
1548 int cl_first, cl_cursor;
1550 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1551 num_page_entries = num_leveldirs;
1553 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1555 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1556 cl_cursor = leveldir_pos - cl_first;
1558 leveldir_current->node_parent->node_group->cl_first = cl_first;
1559 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1562 leveldir_current = leveldir_current->node_parent;
1566 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1568 static unsigned int title_delay = 0;
1569 static int title_screen_nr = 0;
1570 static int last_sound = -1, last_music = -1;
1571 boolean return_to_main_menu = FALSE;
1572 struct TitleControlInfo *tci;
1575 if (button == MB_MENU_INITIALIZE)
1578 title_screen_nr = 0;
1579 tci = &title_controls[title_screen_nr];
1581 SetAnimStatus(getTitleAnimMode(tci));
1583 last_sound = SND_UNDEFINED;
1584 last_music = MUS_UNDEFINED;
1586 if (num_title_screens != 0)
1588 FadeSetEnterScreen();
1590 /* use individual title fading instead of global "enter screen" fading */
1591 fading = getTitleFading(tci);
1594 if (game_status_last_screen == GAME_MODE_INFO)
1596 if (num_title_screens == 0)
1598 /* switch game mode from title screen mode back to info screen mode */
1599 SetGameStatus(GAME_MODE_INFO);
1601 /* store that last screen was info screen, not main menu screen */
1602 game_status_last_screen = GAME_MODE_INFO;
1604 DrawInfoScreen_NotAvailable("Title screen information:",
1605 "No title screen for this level set.");
1609 FadeMenuSoundsAndMusic();
1612 FadeOut(REDRAW_ALL);
1614 /* title screens may have different window size */
1615 ChangeViewportPropertiesIfNeeded();
1617 /* only required to update logic for redrawing global border */
1621 DrawTitleScreenImage(tci->local_nr, tci->initial);
1623 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1625 sound = getTitleSound(tci);
1626 music = getTitleMusic(tci);
1628 if (sound != last_sound)
1629 PlayMenuSoundExt(sound);
1630 if (music != last_music)
1631 PlayMenuMusicExt(music);
1636 SetMouseCursor(CURSOR_NONE);
1640 DelayReached(&title_delay, 0); /* reset delay counter */
1645 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1646 button = MB_MENU_CHOICE;
1648 if (button == MB_MENU_LEAVE)
1650 return_to_main_menu = TRUE;
1652 else if (button == MB_MENU_CHOICE)
1654 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1656 SetGameStatus(GAME_MODE_INFO);
1658 info_mode = INFO_MODE_MAIN;
1667 if (title_screen_nr < num_title_screens)
1669 tci = &title_controls[title_screen_nr];
1671 SetAnimStatus(getTitleAnimMode(tci));
1673 sound = getTitleSound(tci);
1674 music = getTitleMusic(tci);
1676 if (last_sound != SND_UNDEFINED && sound != last_sound)
1677 FadeSound(last_sound);
1678 if (last_music != MUS_UNDEFINED && music != last_music)
1681 fading = getTitleFading(tci);
1683 FadeOut(REDRAW_ALL);
1686 DrawTitleScreenImage(tci->local_nr, tci->initial);
1688 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1690 sound = getTitleSound(tci);
1691 music = getTitleMusic(tci);
1693 if (sound != last_sound)
1694 PlayMenuSoundExt(sound);
1695 if (music != last_music)
1696 PlayMenuMusicExt(music);
1703 DelayReached(&title_delay, 0); /* reset delay counter */
1707 FadeMenuSoundsAndMusic();
1709 return_to_main_menu = TRUE;
1713 if (return_to_main_menu)
1715 SetMouseCursor(CURSOR_DEFAULT);
1717 /* force full menu screen redraw after displaying title screens */
1718 redraw_mask = REDRAW_ALL;
1720 if (game_status_last_screen == GAME_MODE_INFO)
1722 SetGameStatus(GAME_MODE_INFO);
1724 info_mode = INFO_MODE_MAIN;
1728 else /* default: return to main menu */
1730 SetGameStatus(GAME_MODE_MAIN);
1737 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1739 int old_level_nr = level_nr;
1742 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1743 new_level_nr = selected_level_nr;
1745 new_level_nr = old_level_nr + step * direction;
1747 if (new_level_nr < leveldir_current->first_level)
1748 new_level_nr = leveldir_current->first_level;
1749 if (new_level_nr > leveldir_current->last_level)
1750 new_level_nr = leveldir_current->last_level;
1752 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1754 /* skipping levels is only allowed when trying to skip single level */
1755 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1756 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1758 leveldir_current->handicap_level++;
1759 SaveLevelSetup_SeriesInfo();
1762 new_level_nr = leveldir_current->handicap_level;
1765 if (new_level_nr != old_level_nr)
1767 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1769 PlaySound(SND_MENU_ITEM_SELECTING);
1771 level_nr = new_level_nr;
1773 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1774 int2str(level_nr, menu.main.text.level_number.size),
1775 mci->pos_text->font);
1777 LoadLevel(level_nr);
1778 DrawPreviewLevelInitial();
1782 DrawCompleteVideoDisplay();
1784 /* needed because DrawPreviewLevelInitial() takes some time */
1786 /* SyncDisplay(); */
1790 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1792 static int choice = MAIN_CONTROL_GAME;
1793 static boolean button_pressed_last = FALSE;
1794 boolean button_pressed = FALSE;
1798 if (button == MB_MENU_INITIALIZE)
1800 DrawCursorAndText_Main(choice, TRUE, FALSE);
1805 if (mx || my) /* mouse input */
1809 for (i = 0; main_controls[i].nr != -1; i++)
1811 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1812 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1813 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1815 pos = main_controls[i].nr;
1821 /* check if level preview was clicked */
1822 if (insidePreviewRect(&preview, mx - SX, my - SY))
1823 pos = MAIN_CONTROL_GAME;
1825 // handle pressed/unpressed state for active/inactive menu buttons
1826 // (if pos != -1, "i" contains index position corresponding to "pos")
1828 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1829 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1830 button_pressed = TRUE;
1832 if (button_pressed != button_pressed_last)
1834 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1837 PlaySound(SND_MENU_BUTTON_PRESSING);
1839 PlaySound(SND_MENU_BUTTON_RELEASING);
1842 else if (dx || dy) /* keyboard input */
1844 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1845 choice == MAIN_CONTROL_SETUP))
1846 button = MB_MENU_CHOICE;
1851 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1853 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1855 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1857 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1859 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1861 CloseDoor(DOOR_CLOSE_2);
1863 SetGameStatus(GAME_MODE_LEVELNR);
1865 DrawChooseLevelNr();
1867 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1873 PlaySound(SND_MENU_ITEM_ACTIVATING);
1875 DrawCursorAndText_Main(choice, FALSE, FALSE);
1876 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1882 if (choice != MAIN_CONTROL_INFO &&
1883 choice != MAIN_CONTROL_SETUP)
1884 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
1889 PlaySound(SND_MENU_ITEM_SELECTING);
1891 if (pos == MAIN_CONTROL_NAME)
1893 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1895 HandleTypeName(strlen(setup.player_name), 0);
1897 else if (pos == MAIN_CONTROL_LEVELS)
1901 CloseDoor(DOOR_CLOSE_2);
1903 SetGameStatus(GAME_MODE_LEVELS);
1905 SaveLevelSetup_LastSeries();
1906 SaveLevelSetup_SeriesInfo();
1908 if (setup.internal.choose_from_top_leveldir)
1911 DrawChooseLevelSet();
1914 else if (pos == MAIN_CONTROL_SCORES)
1916 CloseDoor(DOOR_CLOSE_2);
1918 SetGameStatus(GAME_MODE_SCORES);
1922 else if (pos == MAIN_CONTROL_EDITOR)
1924 if (leveldir_current->readonly &&
1925 !strEqual(setup.player_name, "Artsoft"))
1926 Request("This level is read only!", REQ_CONFIRM);
1928 CloseDoor(DOOR_CLOSE_2);
1930 SetGameStatus(GAME_MODE_EDITOR);
1932 FadeSetEnterScreen();
1936 else if (pos == MAIN_CONTROL_INFO)
1938 CloseDoor(DOOR_CLOSE_2);
1940 SetGameStatus(GAME_MODE_INFO);
1942 info_mode = INFO_MODE_MAIN;
1946 else if (pos == MAIN_CONTROL_GAME)
1948 StartGameActions(options.network, setup.autorecord, level.random_seed);
1950 else if (pos == MAIN_CONTROL_SETUP)
1952 CloseDoor(DOOR_CLOSE_2);
1954 SetGameStatus(GAME_MODE_SETUP);
1956 setup_mode = SETUP_MODE_MAIN;
1960 else if (pos == MAIN_CONTROL_QUIT)
1962 SaveLevelSetup_LastSeries();
1963 SaveLevelSetup_SeriesInfo();
1965 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1966 SetGameStatus(GAME_MODE_QUIT);
1971 button_pressed_last = button_pressed;
1975 /* ========================================================================= */
1976 /* info screen functions */
1977 /* ========================================================================= */
1979 static struct TokenInfo *info_info;
1980 static int num_info_info; /* number of info entries shown on screen */
1981 static int max_info_info; /* total number of info entries in list */
1983 static void execInfoTitleScreen()
1985 info_mode = INFO_MODE_TITLE;
1990 static void execInfoElements()
1992 info_mode = INFO_MODE_ELEMENTS;
1997 static void execInfoMusic()
1999 info_mode = INFO_MODE_MUSIC;
2004 static void execInfoCredits()
2006 info_mode = INFO_MODE_CREDITS;
2011 static void execInfoProgram()
2013 info_mode = INFO_MODE_PROGRAM;
2018 static void execInfoVersion()
2020 info_mode = INFO_MODE_VERSION;
2025 static void execInfoLevelSet()
2027 info_mode = INFO_MODE_LEVELSET;
2032 static void execExitInfo()
2034 SetGameStatus(GAME_MODE_MAIN);
2039 static struct TokenInfo info_info_main[] =
2041 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2042 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2043 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2044 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2045 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2046 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2047 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2048 { TYPE_EMPTY, NULL, "" },
2049 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2054 static int getMenuTextFont(int type)
2056 if (type & (TYPE_SWITCH |
2068 static struct TokenInfo *setup_info;
2069 static struct TokenInfo setup_info_input[];
2071 static struct TokenInfo *menu_info;
2073 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2074 int screen_pos, int menu_info_pos_raw,
2077 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2078 struct TokenInfo *ti = &token_info[pos];
2079 int xpos = MENU_SCREEN_START_XPOS;
2080 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2081 int font_nr = getMenuTextFont(ti->type);
2083 if (token_info == setup_info_input)
2084 font_nr = FONT_MENU_1;
2087 font_nr = FONT_ACTIVE(font_nr);
2089 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2091 if (ti->type & ~TYPE_SKIP_ENTRY)
2092 drawCursor(screen_pos, active);
2095 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2098 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2101 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2104 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2107 static char *window_size_text;
2108 static char *scaling_type_text;
2110 static void drawSetupValue(int, int);
2112 static void drawMenuInfoList(int first_entry, int num_page_entries,
2113 int max_page_entries)
2117 if (first_entry + num_page_entries > max_page_entries)
2120 clearMenuListArea();
2122 for (i = 0; i < num_page_entries; i++)
2124 int menu_info_pos = first_entry + i;
2125 struct TokenInfo *si = &menu_info[menu_info_pos];
2126 void *value_ptr = si->value;
2128 /* set some entries to "unchangeable" according to other variables */
2129 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2130 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2131 (value_ptr == &setup.sound_music && !audio.music_available) ||
2132 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2133 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2134 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2135 si->type |= TYPE_GHOSTED;
2137 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2138 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2139 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2140 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2141 else if (si->type & ~TYPE_SKIP_ENTRY)
2142 initCursor(i, IMG_MENU_BUTTON);
2144 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2146 if (si->type & TYPE_VALUE &&
2147 menu_info == setup_info)
2148 drawSetupValue(i, menu_info_pos);
2152 static void DrawInfoScreen_Main()
2154 int fade_mask = REDRAW_FIELD;
2157 if (redraw_mask & REDRAW_ALL)
2158 fade_mask = REDRAW_ALL;
2160 if (CheckIfGlobalBorderHasChanged())
2161 fade_mask = REDRAW_ALL;
2164 FadeMenuSoundsAndMusic();
2166 FreeScreenGadgets();
2167 CreateScreenGadgets();
2169 /* (needed after displaying title screens which disable auto repeat) */
2170 KeyboardAutoRepeatOn();
2172 FadeSetLeaveScreen();
2176 /* needed if different viewport properties defined for info screen */
2177 ChangeViewportPropertiesIfNeeded();
2179 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2183 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2185 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2187 info_info = info_info_main;
2189 // determine maximal number of info entries that can be displayed on screen
2191 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2194 // determine maximal number of info entries available for menu of info screen
2196 for (i = 0; info_info[i].type != 0; i++)
2199 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2201 MapScreenGadgets(max_info_info);
2203 PlayMenuSoundsAndMusic();
2205 DrawMaskedBorder(fade_mask);
2210 static void changeSetupValue(int, int, int);
2212 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2213 int mode, int num_page_entries, int max_page_entries)
2215 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2216 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2217 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2218 int *num_page_entries_last = num_page_entries_all_last[game_status];
2219 int *choice_store = choice_stores[game_status];
2220 int *first_entry_store = first_entry_stores[game_status];
2221 int choice = choice_store[mode]; /* starts with 0 */
2222 int first_entry = first_entry_store[mode]; /* starts with 0 */
2224 int y = choice - first_entry;
2226 boolean position_set_by_scrollbar = (dx == 999);
2227 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2230 if (button == MB_MENU_INITIALIZE)
2232 // check if number of menu page entries has changed (may happen by change
2233 // of custom artwork definition value for 'list_size' for this menu screen)
2234 // (in this case, the last menu position most probably has to be corrected)
2235 if (num_page_entries != num_page_entries_last[mode])
2237 choice_store[mode] = first_entry_store[mode] = 0;
2239 choice = first_entry = 0;
2242 num_page_entries_last[mode] = num_page_entries;
2245 /* advance to first valid menu entry */
2246 while (choice < num_page_entries &&
2247 menu_info[choice].type & TYPE_SKIP_ENTRY)
2250 if (position_set_by_scrollbar)
2251 first_entry = first_entry_store[mode] = dy;
2253 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2254 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2256 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2258 if (choice < first_entry)
2260 choice = first_entry;
2262 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2265 else if (choice > first_entry + num_page_entries - 1)
2267 choice = first_entry + num_page_entries - 1;
2269 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2273 choice_store[mode] = choice;
2275 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2279 else if (button == MB_MENU_LEAVE)
2281 PlaySound(SND_MENU_ITEM_SELECTING);
2283 for (i = 0; i < max_page_entries; i++)
2285 if (menu_info[i].type & TYPE_LEAVE_MENU)
2287 void (*menu_callback_function)(void) = menu_info[i].value;
2291 menu_callback_function();
2293 break; /* absolutely needed because function changes 'menu_info'! */
2300 if (mx || my) /* mouse input */
2302 x = (mx - mSX) / 32;
2303 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2305 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2307 /* move cursor instead of scrolling when already at start/end of list */
2308 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2310 else if (dy == +1 * SCROLL_LINE &&
2311 first_entry + num_page_entries == max_page_entries)
2314 /* handle scrolling screen one line or page */
2316 y + dy > num_page_entries - 1)
2318 boolean redraw = FALSE;
2320 if (ABS(dy) == SCROLL_PAGE)
2321 step = num_page_entries - 1;
2323 if (dy < 0 && first_entry > 0)
2325 /* scroll page/line up */
2327 first_entry -= step;
2328 if (first_entry < 0)
2333 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2335 /* scroll page/line down */
2337 first_entry += step;
2338 if (first_entry + num_page_entries > max_page_entries)
2339 first_entry = MAX(0, max_page_entries - num_page_entries);
2346 choice += first_entry - first_entry_store[mode];
2348 if (choice < first_entry)
2350 choice = first_entry;
2352 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2355 else if (choice > first_entry + num_page_entries - 1)
2357 choice = first_entry + num_page_entries - 1;
2359 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2362 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2366 if (choice < first_entry ||
2367 choice > first_entry + num_page_entries - 1)
2368 first_entry += SIGN(dy);
2371 first_entry_store[mode] = first_entry;
2372 choice_store[mode] = choice;
2374 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2376 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2378 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2379 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2387 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2389 if (menu_info[choice].type & menu_navigation_type ||
2390 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2391 menu_info[choice].type & TYPE_YES_NO_AUTO)
2392 button = MB_MENU_CHOICE;
2397 /* jump to next non-empty menu entry (up or down) */
2398 while (first_entry + y > 0 &&
2399 first_entry + y < max_page_entries - 1 &&
2400 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2403 if (!IN_VIS_MENU(x, y))
2405 choice += y - y_old;
2407 if (choice < first_entry)
2408 first_entry = choice;
2409 else if (choice > first_entry + num_page_entries - 1)
2410 first_entry = choice - num_page_entries + 1;
2412 if (first_entry >= 0 &&
2413 first_entry + num_page_entries <= max_page_entries)
2415 first_entry_store[mode] = first_entry;
2417 if (choice < first_entry)
2418 choice = first_entry;
2419 else if (choice > first_entry + num_page_entries - 1)
2420 choice = first_entry + num_page_entries - 1;
2422 choice_store[mode] = choice;
2424 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2426 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2428 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2429 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2436 if (!anyScrollbarGadgetActive() &&
2437 IN_VIS_MENU(x, y) &&
2438 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2439 y >= 0 && y < num_page_entries)
2443 if (first_entry + y != choice &&
2444 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2446 PlaySound(SND_MENU_ITEM_ACTIVATING);
2448 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2449 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2451 choice = choice_store[mode] = first_entry + y;
2455 PlaySound(SND_MENU_ITEM_SELECTING);
2457 for (i = 0; menu_info[i].type != 0; i++)
2459 if (menu_info[i].type & TYPE_LEAVE_MENU)
2461 void (*menu_callback_function)(void) = menu_info[i].value;
2465 menu_callback_function();
2467 /* absolutely needed because function changes 'menu_info'! */
2475 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2477 PlaySound(SND_MENU_ITEM_SELECTING);
2479 /* when selecting key headline, execute function for key value change */
2480 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2481 menu_info[first_entry + y + 1].type & TYPE_KEY)
2484 /* when selecting string value, execute function for list selection */
2485 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2486 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2489 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2491 void (*menu_callback_function)(void) =
2492 menu_info[first_entry + y].value;
2494 FadeSetFromType(menu_info[first_entry + y].type);
2496 menu_callback_function();
2498 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2499 menu_info == setup_info)
2501 changeSetupValue(y, first_entry + y, dx);
2507 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2509 menu_info = info_info;
2511 HandleMenuScreen(mx, my, dx, dy, button,
2512 info_mode, num_info_info, max_info_info);
2515 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2517 int ystart1 = mSY - SY + 100;
2518 int ystart2 = mSY - SY + 150;
2519 int ybottom = mSY - SY + SYSIZE - 20;
2521 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2523 FadeOut(REDRAW_FIELD);
2528 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2529 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2531 DrawTextSCentered(ybottom, FONT_TEXT_4,
2532 "Press any key or button for info menu");
2534 FadeIn(REDRAW_FIELD);
2537 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2539 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2540 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2541 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2542 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2543 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2544 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2545 int ystep = MENU_SCREEN_INFO_YSTEP;
2546 int element, action, direction;
2554 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2555 infoscreen_step[i] = infoscreen_frame[i] = 0;
2560 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2562 DrawTextSCentered(ybottom, FONT_TEXT_4,
2563 "Press any key or button for next page");
2569 while (helpanim_info[j].element != HELPANIM_LIST_END)
2571 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2576 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2585 j += infoscreen_step[i - start];
2587 element = helpanim_info[j].element;
2588 action = helpanim_info[j].action;
2589 direction = helpanim_info[j].direction;
2592 element = EL_UNKNOWN;
2594 if (action != -1 && direction != -1)
2595 graphic = el_act_dir2img(element, action, direction);
2596 else if (action != -1)
2597 graphic = el_act2img(element, action);
2598 else if (direction != -1)
2599 graphic = el_dir2img(element, direction);
2601 graphic = el2img(element);
2603 delay = helpanim_info[j++].delay;
2608 if (infoscreen_frame[i - start] == 0)
2611 infoscreen_frame[i - start] = delay - 1;
2615 sync_frame = delay - infoscreen_frame[i - start];
2616 infoscreen_frame[i - start]--;
2619 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2621 if (!infoscreen_frame[i - start])
2622 infoscreen_step[i - start] = 0;
2626 if (!infoscreen_frame[i - start])
2627 infoscreen_step[i - start]++;
2628 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2634 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2636 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2637 graphic, sync_frame, USE_MASKING);
2640 DrawInfoScreen_HelpText(element, action, direction, i - start);
2645 redraw_mask |= REDRAW_FIELD;
2650 static char *getHelpText(int element, int action, int direction)
2652 char token[MAX_LINE_LEN];
2654 strcpy(token, element_info[element].token_name);
2657 strcat(token, element_action_info[action].suffix);
2659 if (direction != -1)
2660 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2662 return getHashEntry(helptext_info, token);
2665 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2667 int font_nr = FONT_INFO_ELEMENTS;
2668 int font_width = getFontWidth(font_nr);
2669 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2670 int sy = mSY + 65 + 2 * 32 + 1;
2671 int ystep = TILEY + 4;
2672 int pad_x = sx - SX;
2673 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2674 int max_lines_per_text = 2;
2677 if (action != -1 && direction != -1) /* element.action.direction */
2678 text = getHelpText(element, action, direction);
2680 if (text == NULL && action != -1) /* element.action */
2681 text = getHelpText(element, action, -1);
2683 if (text == NULL && direction != -1) /* element.direction */
2684 text = getHelpText(element, -1, direction);
2686 if (text == NULL) /* base element */
2687 text = getHelpText(element, -1, -1);
2689 if (text == NULL) /* not found */
2690 text = "No description available";
2692 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2693 sy += getFontHeight(font_nr) / 2;
2695 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2696 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2697 TRUE, FALSE, FALSE);
2700 void DrawInfoScreen_TitleScreen()
2702 SetGameStatus(GAME_MODE_TITLE);
2707 void HandleInfoScreen_TitleScreen(int button)
2709 HandleTitleScreen(0, 0, 0, 0, button);
2712 void DrawInfoScreen_Elements()
2714 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2716 FadeOut(REDRAW_FIELD);
2721 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2723 FadeIn(REDRAW_FIELD);
2726 void HandleInfoScreen_Elements(int button)
2728 static unsigned int info_delay = 0;
2729 static int num_anims;
2730 static int num_pages;
2732 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2735 if (button == MB_MENU_INITIALIZE)
2737 boolean new_element = TRUE;
2741 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2743 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2745 else if (new_element)
2748 new_element = FALSE;
2752 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2756 if (button == MB_MENU_LEAVE)
2758 PlaySound(SND_MENU_ITEM_SELECTING);
2760 info_mode = INFO_MODE_MAIN;
2765 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2767 if (button != MB_MENU_INITIALIZE)
2769 PlaySound(SND_MENU_ITEM_SELECTING);
2774 if (page >= num_pages)
2776 FadeMenuSoundsAndMusic();
2778 info_mode = INFO_MODE_MAIN;
2785 FadeSetNextScreen();
2787 if (button != MB_MENU_INITIALIZE)
2788 FadeOut(REDRAW_FIELD);
2790 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2792 if (button != MB_MENU_INITIALIZE)
2793 FadeIn(REDRAW_FIELD);
2797 if (DelayReached(&info_delay, GameFrameDelay))
2798 if (page < num_pages)
2799 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2801 PlayMenuSoundIfLoop();
2805 void DrawInfoScreen_Music()
2807 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2809 FadeOut(REDRAW_FIELD);
2816 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2818 FadeIn(REDRAW_FIELD);
2821 void HandleInfoScreen_Music(int button)
2823 static struct MusicFileInfo *list = NULL;
2824 int ystart1 = mSY - SY + 100;
2825 int ystart2 = mSY - SY + 150;
2826 int ybottom = mSY - SY + SYSIZE - 20;
2829 if (button == MB_MENU_INITIALIZE)
2831 list = music_file_info;
2835 FadeMenuSoundsAndMusic();
2840 DrawTextSCentered(ystart1, FONT_TEXT_1,
2841 "No music info for this level set.");
2843 DrawTextSCentered(ybottom, FONT_TEXT_4,
2844 "Press any key or button for info menu");
2850 if (button == MB_MENU_LEAVE)
2852 PlaySound(SND_MENU_ITEM_SELECTING);
2854 FadeMenuSoundsAndMusic();
2856 info_mode = INFO_MODE_MAIN;
2861 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2865 if (button != MB_MENU_INITIALIZE)
2867 PlaySound(SND_MENU_ITEM_SELECTING);
2875 FadeMenuSoundsAndMusic();
2877 info_mode = INFO_MODE_MAIN;
2883 FadeMenuSoundsAndMusic();
2885 if (list != music_file_info)
2886 FadeSetNextScreen();
2888 if (button != MB_MENU_INITIALIZE)
2889 FadeOut(REDRAW_FIELD);
2896 int sound = list->music;
2898 if (sound_info[sound].loop)
2899 PlaySoundLoop(sound);
2903 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2907 PlayMusic(list->music);
2909 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2912 if (!strEqual(list->title, UNKNOWN_NAME))
2914 if (!strEqual(list->title_header, UNKNOWN_NAME))
2915 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2917 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2920 if (!strEqual(list->artist, UNKNOWN_NAME))
2922 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2923 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2925 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2927 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2930 if (!strEqual(list->album, UNKNOWN_NAME))
2932 if (!strEqual(list->album_header, UNKNOWN_NAME))
2933 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2935 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2937 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2940 if (!strEqual(list->year, UNKNOWN_NAME))
2942 if (!strEqual(list->year_header, UNKNOWN_NAME))
2943 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2945 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2947 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2950 DrawTextSCentered(ybottom, FONT_TEXT_4,
2951 "Press any key or button for next page");
2953 if (button != MB_MENU_INITIALIZE)
2954 FadeIn(REDRAW_FIELD);
2957 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2958 PlaySoundLoop(list->music);
2961 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2963 int ystart1 = mSY - SY + 100;
2964 int ystart2 = mSY - SY + 150;
2965 int ybottom = mSY - SY + SYSIZE - 20;
2971 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2975 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2976 "Special thanks to");
2977 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2979 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2981 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2982 "\"Boulder Dash\"");
2983 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2985 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2987 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2989 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2990 "First Star Software");
2992 else if (screen_nr == 1)
2994 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2995 "Special thanks to");
2996 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2997 "Klaus Heinz & Volker Wertich");
2998 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3000 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3001 "\"Emerald Mine\"");
3002 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3004 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3006 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3008 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3011 else if (screen_nr == 2)
3013 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3014 "Special thanks to");
3015 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3016 "Michael Stopp & Philip Jespersen");
3017 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3019 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3021 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3023 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3025 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3027 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3028 "Digital Integration");
3030 else if (screen_nr == 3)
3032 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3033 "Special thanks to");
3034 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3035 "Hiroyuki Imabayashi");
3036 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3038 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3040 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3042 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3044 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3046 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3049 else if (screen_nr == 4)
3051 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3052 "Special thanks to");
3053 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3055 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3057 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3058 "J\xfcrgen Bonhagen");
3059 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3060 "for the continuous creation");
3061 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3062 "of outstanding level sets");
3064 else if (screen_nr == 5)
3066 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3068 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3070 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3071 "for ideas and inspiration by");
3072 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3075 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3077 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3079 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3080 "for ideas and inspiration by");
3081 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3084 else if (screen_nr == 6)
3086 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3088 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3091 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3092 "for the code base used for the");
3093 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3094 "native Emerald Mine engine");
3096 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3097 "for the new Emerald Mine engine");
3100 else if (screen_nr == 7)
3102 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3104 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3106 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3107 "for the initial DOS port");
3109 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3111 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3113 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3114 "for some additional toons");
3116 else if (screen_nr == 8)
3118 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3119 "And not to forget:");
3120 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3122 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3123 "All those who contributed");
3124 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3125 "levels to this game");
3126 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3130 DrawTextSCentered(ybottom, FONT_TEXT_4,
3131 "Press any key or button for next page");
3134 void DrawInfoScreen_Credits()
3136 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3138 FadeMenuSoundsAndMusic();
3140 FadeOut(REDRAW_FIELD);
3142 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3144 FadeIn(REDRAW_FIELD);
3147 void HandleInfoScreen_Credits(int button)
3149 static int screen_nr = 0;
3150 int num_screens = 9;
3152 if (button == MB_MENU_INITIALIZE)
3156 // DrawInfoScreen_CreditsScreen(screen_nr);
3159 if (button == MB_MENU_LEAVE)
3161 PlaySound(SND_MENU_ITEM_SELECTING);
3163 info_mode = INFO_MODE_MAIN;
3168 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3170 if (button != MB_MENU_INITIALIZE)
3172 PlaySound(SND_MENU_ITEM_SELECTING);
3177 if (screen_nr >= num_screens)
3179 FadeMenuSoundsAndMusic();
3181 info_mode = INFO_MODE_MAIN;
3188 FadeSetNextScreen();
3190 if (button != MB_MENU_INITIALIZE)
3191 FadeOut(REDRAW_FIELD);
3193 DrawInfoScreen_CreditsScreen(screen_nr);
3195 if (button != MB_MENU_INITIALIZE)
3196 FadeIn(REDRAW_FIELD);
3200 PlayMenuSoundIfLoop();
3204 void DrawInfoScreen_Program()
3206 int ystart1 = mSY - SY + 100;
3207 int ystart2 = mSY - SY + 150;
3208 int ybottom = mSY - SY + SYSIZE - 20;
3211 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3213 FadeOut(REDRAW_FIELD);
3218 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3220 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3221 "This game is Freeware!");
3222 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3223 "If you like it, send e-mail to:");
3224 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3225 setup.internal.program_email);
3226 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3227 "More information and levels:");
3228 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3229 setup.internal.program_website);
3230 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3231 "If you have created new levels,");
3232 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3233 "send them to me to include them!");
3234 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3237 DrawTextSCentered(ybottom, FONT_TEXT_4,
3238 "Press any key or button for info menu");
3240 FadeIn(REDRAW_FIELD);
3243 void HandleInfoScreen_Program(int button)
3245 if (button == MB_MENU_LEAVE)
3247 PlaySound(SND_MENU_ITEM_SELECTING);
3249 info_mode = INFO_MODE_MAIN;
3254 else if (button == MB_MENU_CHOICE)
3256 PlaySound(SND_MENU_ITEM_SELECTING);
3258 FadeMenuSoundsAndMusic();
3260 info_mode = INFO_MODE_MAIN;
3265 PlayMenuSoundIfLoop();
3269 void DrawInfoScreen_Version()
3271 int font_header = FONT_TEXT_3;
3272 int font_text = FONT_TEXT_2;
3273 int xstep = getFontWidth(font_text);
3274 int ystep = getFontHeight(font_text);
3275 int ystart1 = mSY - SY + 100;
3276 int ystart2 = mSY - SY + 150;
3277 int ybottom = mSY - SY + SYSIZE - 20;
3278 int xstart1 = mSX - SX + 2 * xstep;
3279 int xstart2 = mSX - SX + 18 * xstep;
3280 int xstart3 = mSX - SX + 28 * xstep;
3281 SDL_version sdl_version_compiled;
3282 const SDL_version *sdl_version_linked;
3283 int driver_name_len = 10;
3284 #if defined(TARGET_SDL2)
3285 SDL_version sdl_version_linked_ext;
3286 const char *driver_name = NULL;
3288 char driver_name[driver_name_len];
3291 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3293 FadeOut(REDRAW_FIELD);
3298 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3300 DrawTextF(xstart1, ystart2, font_header, "Name");
3301 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3304 DrawTextF(xstart1, ystart2, font_header, "Version");
3305 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3308 DrawTextF(xstart1, ystart2, font_header, "Platform");
3309 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3312 DrawTextF(xstart1, ystart2, font_header, "Target");
3313 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3316 DrawTextF(xstart1, ystart2, font_header, "Source date");
3317 DrawTextF(xstart2, ystart2, font_text, getSourceDateString());
3319 ystart2 += 3 * ystep;
3320 DrawTextF(xstart1, ystart2, font_header, "Library");
3321 DrawTextF(xstart2, ystart2, font_header, "compiled");
3322 DrawTextF(xstart3, ystart2, font_header, "linked");
3324 SDL_VERSION(&sdl_version_compiled);
3325 #if defined(TARGET_SDL2)
3326 SDL_GetVersion(&sdl_version_linked_ext);
3327 sdl_version_linked = &sdl_version_linked_ext;
3329 sdl_version_linked = SDL_Linked_Version();
3332 ystart2 += 2 * ystep;
3333 DrawTextF(xstart1, ystart2, font_text, "SDL");
3334 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3335 sdl_version_compiled.major,
3336 sdl_version_compiled.minor,
3337 sdl_version_compiled.patch);
3338 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3339 sdl_version_linked->major,
3340 sdl_version_linked->minor,
3341 sdl_version_linked->patch);
3343 SDL_IMAGE_VERSION(&sdl_version_compiled);
3344 sdl_version_linked = IMG_Linked_Version();
3347 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3348 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3349 sdl_version_compiled.major,
3350 sdl_version_compiled.minor,
3351 sdl_version_compiled.patch);
3352 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3353 sdl_version_linked->major,
3354 sdl_version_linked->minor,
3355 sdl_version_linked->patch);
3357 SDL_MIXER_VERSION(&sdl_version_compiled);
3358 sdl_version_linked = Mix_Linked_Version();
3361 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3362 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3363 sdl_version_compiled.major,
3364 sdl_version_compiled.minor,
3365 sdl_version_compiled.patch);
3366 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3367 sdl_version_linked->major,
3368 sdl_version_linked->minor,
3369 sdl_version_linked->patch);
3371 SDL_NET_VERSION(&sdl_version_compiled);
3372 sdl_version_linked = SDLNet_Linked_Version();
3375 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3376 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3377 sdl_version_compiled.major,
3378 sdl_version_compiled.minor,
3379 sdl_version_compiled.patch);
3380 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3381 sdl_version_linked->major,
3382 sdl_version_linked->minor,
3383 sdl_version_linked->patch);
3385 ystart2 += 3 * ystep;
3386 DrawTextF(xstart1, ystart2, font_header, "Driver");
3387 DrawTextF(xstart2, ystart2, font_header, "Requested");
3388 DrawTextF(xstart3, ystart2, font_header, "Used");
3390 #if defined(TARGET_SDL2)
3391 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3393 SDL_VideoDriverName(driver_name, driver_name_len);
3396 ystart2 += 2 * ystep;
3397 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3398 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3399 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3401 #if defined(TARGET_SDL2)
3402 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3404 SDL_AudioDriverName(driver_name, driver_name_len);
3408 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3409 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3410 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3412 DrawTextSCentered(ybottom, FONT_TEXT_4,
3413 "Press any key or button for info menu");
3415 FadeIn(REDRAW_FIELD);
3418 void HandleInfoScreen_Version(int button)
3420 if (button == MB_MENU_LEAVE)
3422 PlaySound(SND_MENU_ITEM_SELECTING);
3424 info_mode = INFO_MODE_MAIN;
3429 else if (button == MB_MENU_CHOICE)
3431 PlaySound(SND_MENU_ITEM_SELECTING);
3433 FadeMenuSoundsAndMusic();
3435 info_mode = INFO_MODE_MAIN;
3440 PlayMenuSoundIfLoop();
3444 void DrawInfoScreen_LevelSet()
3446 struct TitleMessageInfo *tmi = &readme;
3447 char *filename = getLevelSetInfoFilename();
3448 char *title = "Level Set Information:";
3449 int ystart1 = mSY - SY + 100;
3450 int ybottom = mSY - SY + SYSIZE - 20;
3452 if (filename == NULL)
3454 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3459 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3461 FadeOut(REDRAW_FIELD);
3466 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3468 /* if x position set to "-1", automatically determine by playfield width */
3470 tmi->x = SXSIZE / 2;
3472 /* if y position set to "-1", use static default value */
3476 /* if width set to "-1", automatically determine by playfield width */
3477 if (tmi->width == -1)
3478 tmi->width = SXSIZE - 2 * TILEX;
3480 /* if height set to "-1", automatically determine by playfield height */
3481 if (tmi->height == -1)
3482 tmi->height = SYSIZE - 20 - tmi->y - 10;
3484 /* if chars set to "-1", automatically determine by text and font width */
3485 if (tmi->chars == -1)
3486 tmi->chars = tmi->width / getFontWidth(tmi->font);
3488 tmi->width = tmi->chars * getFontWidth(tmi->font);
3490 /* if lines set to "-1", automatically determine by text and font height */
3491 if (tmi->lines == -1)
3492 tmi->lines = tmi->height / getFontHeight(tmi->font);
3494 tmi->height = tmi->lines * getFontHeight(tmi->font);
3496 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3497 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3498 tmi->autowrap, tmi->centered, tmi->parse_comments);
3500 DrawTextSCentered(ybottom, FONT_TEXT_4,
3501 "Press any key or button for info menu");
3503 FadeIn(REDRAW_FIELD);
3506 void HandleInfoScreen_LevelSet(int button)
3508 if (button == MB_MENU_LEAVE)
3510 PlaySound(SND_MENU_ITEM_SELECTING);
3512 info_mode = INFO_MODE_MAIN;
3517 else if (button == MB_MENU_CHOICE)
3519 PlaySound(SND_MENU_ITEM_SELECTING);
3521 FadeMenuSoundsAndMusic();
3523 info_mode = INFO_MODE_MAIN;
3528 PlayMenuSoundIfLoop();
3532 static void DrawInfoScreen()
3534 if (info_mode == INFO_MODE_TITLE)
3535 DrawInfoScreen_TitleScreen();
3536 else if (info_mode == INFO_MODE_ELEMENTS)
3537 DrawInfoScreen_Elements();
3538 else if (info_mode == INFO_MODE_MUSIC)
3539 DrawInfoScreen_Music();
3540 else if (info_mode == INFO_MODE_CREDITS)
3541 DrawInfoScreen_Credits();
3542 else if (info_mode == INFO_MODE_PROGRAM)
3543 DrawInfoScreen_Program();
3544 else if (info_mode == INFO_MODE_VERSION)
3545 DrawInfoScreen_Version();
3546 else if (info_mode == INFO_MODE_LEVELSET)
3547 DrawInfoScreen_LevelSet();
3549 DrawInfoScreen_Main();
3551 if (info_mode != INFO_MODE_MAIN &&
3552 info_mode != INFO_MODE_TITLE &&
3553 info_mode != INFO_MODE_MUSIC)
3554 PlayMenuSoundsAndMusic();
3557 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3559 if (info_mode == INFO_MODE_TITLE)
3560 HandleInfoScreen_TitleScreen(button);
3561 else if (info_mode == INFO_MODE_ELEMENTS)
3562 HandleInfoScreen_Elements(button);
3563 else if (info_mode == INFO_MODE_MUSIC)
3564 HandleInfoScreen_Music(button);
3565 else if (info_mode == INFO_MODE_CREDITS)
3566 HandleInfoScreen_Credits(button);
3567 else if (info_mode == INFO_MODE_PROGRAM)
3568 HandleInfoScreen_Program(button);
3569 else if (info_mode == INFO_MODE_VERSION)
3570 HandleInfoScreen_Version(button);
3571 else if (info_mode == INFO_MODE_LEVELSET)
3572 HandleInfoScreen_LevelSet(button);
3574 HandleInfoScreen_Main(mx, my, dx, dy, button);
3578 /* ========================================================================= */
3579 /* type name functions */
3580 /* ========================================================================= */
3582 void HandleTypeName(int newxpos, Key key)
3584 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3585 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3586 struct TextPosInfo *pos = mci->pos_input;
3587 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3588 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3589 static int xpos = 0;
3590 int font_nr = pos->font;
3591 int font_active_nr = FONT_ACTIVE(font_nr);
3592 int font_width = getFontWidth(font_active_nr);
3593 char key_char = getValidConfigValueChar(getCharFromKey(key));
3594 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3595 boolean is_active = TRUE;
3597 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3601 strcpy(last_player_name, setup.player_name);
3605 StartTextInput(startx, starty, pos->width, pos->height);
3607 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3609 setup.player_name[xpos] = key_char;
3610 setup.player_name[xpos + 1] = 0;
3614 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3618 setup.player_name[xpos] = 0;
3620 else if (key == KSYM_Return && xpos > 0)
3626 SetGameStatus(GAME_MODE_MAIN);
3628 else if (key == KSYM_Escape)
3630 strcpy(setup.player_name, last_player_name);
3634 SetGameStatus(GAME_MODE_MAIN);
3639 pos->width = (strlen(setup.player_name) + 1) * font_width;
3640 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3642 DrawText(startx, starty, setup.player_name, font_active_nr);
3643 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3647 pos->width = strlen(setup.player_name) * font_width;
3648 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3650 DrawText(startx, starty, setup.player_name, font_nr);
3657 /* ========================================================================= */
3658 /* tree menu functions */
3659 /* ========================================================================= */
3661 static void DrawChooseTree(TreeInfo **ti_ptr)
3663 int fade_mask = REDRAW_FIELD;
3665 if (CheckIfGlobalBorderHasChanged())
3666 fade_mask = REDRAW_ALL;
3668 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3670 SetGameStatus(GAME_MODE_MAIN);
3679 FreeScreenGadgets();
3680 CreateScreenGadgets();
3684 /* needed if different viewport properties defined for choosing level (set) */
3685 ChangeViewportPropertiesIfNeeded();
3687 if (game_status == GAME_MODE_LEVELNR)
3688 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3689 else if (game_status == GAME_MODE_LEVELS)
3690 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3694 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3696 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3697 MapScreenTreeGadgets(*ti_ptr);
3699 DrawMaskedBorder(fade_mask);
3704 static void drawChooseTreeList(int first_entry, int num_page_entries,
3708 char *title_string = NULL;
3709 int yoffset_sets = MENU_TITLE1_YPOS;
3710 int yoffset_setup = 16;
3711 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3712 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3714 title_string = ti->infotext;
3716 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3718 clearMenuListArea();
3720 for (i = 0; i < num_page_entries; i++)
3722 TreeInfo *node, *node_first;
3723 int entry_pos = first_entry + i;
3724 int xpos = MENU_SCREEN_START_XPOS;
3725 int ypos = MENU_SCREEN_START_YPOS + i;
3726 int startx = mSX + xpos * 32;
3727 int starty = mSY + ypos * 32;
3728 int font_nr = FONT_TEXT_1;
3729 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3730 int startx_text = startx + font_xoffset;
3731 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3732 int text_size = startx_scrollbar - startx_text;
3733 int max_buffer_len = text_size / getFontWidth(font_nr);
3734 char buffer[max_buffer_len + 1];
3736 node_first = getTreeInfoFirstGroupEntry(ti);
3737 node = getTreeInfoFromPos(node_first, entry_pos);
3739 strncpy(buffer, node->name, max_buffer_len);
3740 buffer[max_buffer_len] = '\0';
3742 DrawText(startx, starty, buffer, font_nr + node->color);
3744 if (node->parent_link)
3745 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3746 else if (node->level_group)
3747 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3749 initCursor(i, IMG_MENU_BUTTON);
3752 redraw_mask |= REDRAW_FIELD;
3755 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3757 TreeInfo *node, *node_first;
3758 int x, last_redraw_mask = redraw_mask;
3759 int ypos = MENU_TITLE2_YPOS;
3760 int font_nr = FONT_TITLE_2;
3762 if (ti->type == TREE_TYPE_LEVEL_NR)
3763 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3765 if (ti->type != TREE_TYPE_LEVEL_DIR)
3768 node_first = getTreeInfoFirstGroupEntry(ti);
3769 node = getTreeInfoFromPos(node_first, entry_pos);
3771 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3773 if (node->parent_link)
3774 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3775 node->node_parent->name);
3776 else if (node->level_group)
3777 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3779 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3780 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3781 node->levels, (node->levels > 1 ? "levels" : "level"),
3784 /* let BackToFront() redraw only what is needed */
3785 redraw_mask = last_redraw_mask;
3786 for (x = 0; x < SCR_FIELDX; x++)
3787 MarkTileDirty(x, 1);
3790 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3793 TreeInfo *ti = *ti_ptr;
3795 int y = ti->cl_cursor;
3796 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3797 int num_entries = numTreeInfoInGroup(ti);
3798 int num_page_entries;
3799 boolean position_set_by_scrollbar = (dx == 999);
3801 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3802 num_page_entries = num_entries;
3804 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3806 if (button == MB_MENU_INITIALIZE)
3808 int num_entries = numTreeInfoInGroup(ti);
3809 int entry_pos = posTreeInfo(ti);