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"
27 #define DEBUG_JOYSTICKS 0
30 /* screens on the info screen */
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 /* screens on the setup screen */
43 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
44 /* (should also match corresponding entries in src/conf_gfx.c) */
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_EDITOR 2
48 #define SETUP_MODE_GRAPHICS 3
49 #define SETUP_MODE_SOUND 4
50 #define SETUP_MODE_ARTWORK 5
51 #define SETUP_MODE_INPUT 6
52 #define SETUP_MODE_TOUCH 7
53 #define SETUP_MODE_SHORTCUTS 8
54 #define SETUP_MODE_SHORTCUTS_1 9
55 #define SETUP_MODE_SHORTCUTS_2 10
56 #define SETUP_MODE_SHORTCUTS_3 11
57 #define SETUP_MODE_SHORTCUTS_4 12
58 #define SETUP_MODE_SHORTCUTS_5 13
60 /* sub-screens on the setup screen (generic) */
61 #define SETUP_MODE_CHOOSE_ARTWORK 14
62 #define SETUP_MODE_CHOOSE_OTHER 15
64 /* sub-screens on the setup screen (specific) */
65 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
70 #define SETUP_MODE_CHOOSE_RENDERING 21
71 #define SETUP_MODE_CHOOSE_GRAPHICS 22
72 #define SETUP_MODE_CHOOSE_SOUNDS 23
73 #define SETUP_MODE_CHOOSE_MUSIC 24
74 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
75 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
76 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
77 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
78 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
79 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
81 #define MAX_SETUP_MODES 31
83 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
85 /* for input setup functions */
86 #define SETUPINPUT_SCREEN_POS_START 0
87 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
88 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
89 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
91 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
92 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
94 /* for various menu stuff */
95 #define MENU_SCREEN_START_XPOS 1
96 #define MENU_SCREEN_START_YPOS 2
97 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
98 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
99 #define MENU_TITLE1_YPOS 8
100 #define MENU_TITLE2_YPOS 46
101 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
102 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
103 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
104 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
105 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
106 #define MENU_SCREEN_INFO_XSTART 16
107 #define MENU_SCREEN_INFO_YSTART1 100
108 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
109 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
110 MENU_INFO_FONT_TITLE))
111 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
112 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
113 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
114 MENU_SCREEN_INFO_YSTART2 - \
116 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
117 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
118 MENU_SCREEN_INFO_YSTEP)
119 #define NUM_INFO_ELEMENTS_FROM_CONF \
120 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
121 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
122 MAX_MENU_ENTRIES_ON_SCREEN)
123 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
124 MAX_INFO_ELEMENTS_ON_SCREEN), \
125 NUM_INFO_ELEMENTS_FROM_CONF)
126 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
127 #define MAX_MENU_TEXT_LENGTH_BIG 13
128 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
130 /* buttons and scrollbars identifiers */
131 #define SCREEN_CTRL_ID_PREV_LEVEL 0
132 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
133 #define SCREEN_CTRL_ID_PREV_PLAYER 2
134 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
135 #define SCREEN_CTRL_ID_SCROLL_UP 4
136 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
137 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
139 #define NUM_SCREEN_GADGETS 7
141 #define NUM_SCREEN_MENUBUTTONS 4
142 #define NUM_SCREEN_SCROLLBUTTONS 2
143 #define NUM_SCREEN_SCROLLBARS 1
145 #define SCREEN_MASK_MAIN (1 << 0)
146 #define SCREEN_MASK_INPUT (1 << 1)
148 /* graphic position and size values for buttons and scrollbars */
149 #define SC_MENUBUTTON_XSIZE TILEX
150 #define SC_MENUBUTTON_YSIZE TILEY
152 #define SC_SCROLLBUTTON_XSIZE TILEX
153 #define SC_SCROLLBUTTON_YSIZE TILEY
155 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
157 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
158 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
159 SC_SCROLLBUTTON_YSIZE)
161 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
162 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
164 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
165 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
166 SC_SCROLLBUTTON_YSIZE)
168 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
169 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
170 SC_SCROLL_VERTICAL_YSIZE)
172 #define SC_BORDER_SIZE 14
175 /* forward declarations of internal functions */
176 static void HandleScreenGadgets(struct GadgetInfo *);
177 static void HandleSetupScreen_Generic(int, int, int, int, int);
178 static void HandleSetupScreen_Input(int, int, int, int, int);
179 static void CustomizeKeyboard(int);
180 static void ConfigureJoystick(int);
181 static void execSetupGame(void);
182 static void execSetupGraphics(void);
183 static void execSetupSound(void);
184 static void execSetupTouch(void);
185 static void execSetupArtwork(void);
186 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
188 static void DrawChooseLevelSet(void);
189 static void DrawChooseLevelNr(void);
190 static void DrawInfoScreen(void);
191 static void DrawSetupScreen(void);
193 static void DrawInfoScreen_NotAvailable(char *, char *);
194 static void DrawInfoScreen_HelpAnim(int, int, boolean);
195 static void DrawInfoScreen_HelpText(int, int, int, int);
196 static void HandleInfoScreen_Main(int, int, int, int, int);
197 static void HandleInfoScreen_TitleScreen(int);
198 static void HandleInfoScreen_Elements(int);
199 static void HandleInfoScreen_Music(int);
200 static void HandleInfoScreen_Credits(int);
201 static void HandleInfoScreen_Program(int);
202 static void HandleInfoScreen_Version(int);
204 static void MapScreenMenuGadgets(int);
205 static void MapScreenGadgets(int);
206 static void MapScreenTreeGadgets(TreeInfo *);
208 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
210 static int info_mode = INFO_MODE_MAIN;
211 static int setup_mode = SETUP_MODE_MAIN;
213 static TreeInfo *window_sizes = NULL;
214 static TreeInfo *window_size_current = NULL;
216 static TreeInfo *scaling_types = NULL;
217 static TreeInfo *scaling_type_current = NULL;
219 static TreeInfo *rendering_modes = NULL;
220 static TreeInfo *rendering_mode_current = NULL;
222 static TreeInfo *scroll_delays = NULL;
223 static TreeInfo *scroll_delay_current = NULL;
225 static TreeInfo *snapshot_modes = NULL;
226 static TreeInfo *snapshot_mode_current = NULL;
228 static TreeInfo *game_speeds = NULL;
229 static TreeInfo *game_speed_current = NULL;
231 static TreeInfo *volumes_simple = NULL;
232 static TreeInfo *volume_simple_current = NULL;
234 static TreeInfo *volumes_loops = NULL;
235 static TreeInfo *volume_loops_current = NULL;
237 static TreeInfo *volumes_music = NULL;
238 static TreeInfo *volume_music_current = NULL;
240 static TreeInfo *touch_controls = NULL;
241 static TreeInfo *touch_control_current = NULL;
243 static TreeInfo *move_distances = NULL;
244 static TreeInfo *move_distance_current = NULL;
246 static TreeInfo *drop_distances = NULL;
247 static TreeInfo *drop_distance_current = NULL;
249 static TreeInfo *level_number = NULL;
250 static TreeInfo *level_number_current = NULL;
256 } window_sizes_list[] =
261 { 100, "100 % (Default)" },
278 } scaling_types_list[] =
280 { SCALING_QUALITY_NEAREST, "None" },
281 { SCALING_QUALITY_LINEAR, "Linear" },
282 { SCALING_QUALITY_BEST, "Anisotropic" },
291 } rendering_modes_list[] =
293 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
294 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
296 // this mode may work under certain conditions, but does not work on Windows
297 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
299 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
308 } game_speeds_list[] =
317 { 1000, "1/1s (Extremely Slow)" },
322 { 29, "1/35s (Original Supaplex)" },
324 { 20, "1/50s (Normal Speed)" },
325 { 14, "1/70s (Maximum Supaplex)" },
329 { 1, "1/1000s (Extremely Fast)" },
339 } scroll_delays_list[] =
341 { 0, "0 Tiles (No Scroll Delay)" },
344 { 3, "3 Tiles (Default)" },
349 { 8, "8 Tiles (Maximum Scroll Delay)"},
358 } snapshot_modes_list[] =
360 { STR_SNAPSHOT_MODE_OFF, "Off" },
361 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
362 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
363 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
396 } touch_controls_list[] =
398 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
399 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
400 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
424 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
425 (s) <= GAME_MODE_SETUP ? (s) : \
426 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
427 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
429 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
430 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
431 (i) <= INFO_MODE_LEVELSET ? (i) : \
434 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
435 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
436 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
437 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
438 SETUP_MODE_CHOOSE_ARTWORK : \
439 SETUP_MODE_CHOOSE_OTHER)
441 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
442 menu.draw_xoffset[GAME_MODE_INFO] : \
443 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
444 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
445 menu.draw_yoffset[GAME_MODE_INFO] : \
446 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
447 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
448 menu.extra_spacing[GAME_MODE_INFO] : \
449 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
451 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
452 menu.draw_xoffset[GAME_MODE_SETUP] : \
453 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
454 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
455 menu.draw_yoffset[GAME_MODE_SETUP] : \
456 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
457 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
458 menu.extra_spacing[GAME_MODE_SETUP] : \
459 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
461 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
462 DRAW_XOFFSET_INFO(info_mode) : \
463 (s) == GAME_MODE_SETUP ? \
464 DRAW_XOFFSET_SETUP(setup_mode) : \
465 menu.draw_xoffset[DRAW_MODE(s)])
466 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
467 DRAW_YOFFSET_INFO(info_mode) : \
468 (s) == GAME_MODE_SETUP ? \
469 DRAW_YOFFSET_SETUP(setup_mode) : \
470 menu.draw_yoffset[DRAW_MODE(s)])
471 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
472 EXTRA_SPACING_INFO(info_mode) : \
473 (s) == GAME_MODE_SETUP ? \
474 EXTRA_SPACING_SETUP(setup_mode) : \
475 menu.extra_spacing[DRAW_MODE(s)])
477 #define mSX (SX + DRAW_XOFFSET(game_status))
478 #define mSY (SY + DRAW_YOFFSET(game_status))
480 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
481 menu.list_size[game_status] : \
482 MAX_MENU_ENTRIES_ON_SCREEN)
484 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
485 NUM_MENU_ENTRIES_ON_SCREEN)
488 /* title display and control definitions */
490 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
491 2 * MAX_NUM_TITLE_MESSAGES)
493 #define NO_DIRECT_LEVEL_SELECT (-1)
496 static int num_title_screens = 0;
498 struct TitleControlInfo
507 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
509 /* main menu display and control definitions */
511 #define MAIN_CONTROL_NAME 0
512 #define MAIN_CONTROL_LEVELS 1
513 #define MAIN_CONTROL_SCORES 2
514 #define MAIN_CONTROL_EDITOR 3
515 #define MAIN_CONTROL_INFO 4
516 #define MAIN_CONTROL_GAME 5
517 #define MAIN_CONTROL_SETUP 6
518 #define MAIN_CONTROL_QUIT 7
519 #define MAIN_CONTROL_PREV_LEVEL 8
520 #define MAIN_CONTROL_NEXT_LEVEL 9
521 #define MAIN_CONTROL_FIRST_LEVEL 10
522 #define MAIN_CONTROL_LAST_LEVEL 11
523 #define MAIN_CONTROL_LEVEL_NUMBER 12
524 #define MAIN_CONTROL_LEVEL_INFO_1 13
525 #define MAIN_CONTROL_LEVEL_INFO_2 14
526 #define MAIN_CONTROL_LEVEL_NAME 15
527 #define MAIN_CONTROL_LEVEL_AUTHOR 16
528 #define MAIN_CONTROL_LEVEL_YEAR 17
529 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
530 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
531 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
532 #define MAIN_CONTROL_TITLE_1 21
533 #define MAIN_CONTROL_TITLE_2 22
534 #define MAIN_CONTROL_TITLE_3 23
536 static char str_main_text_name[10];
537 static char str_main_text_first_level[10];
538 static char str_main_text_last_level[10];
539 static char str_main_text_level_number[10];
541 static char *main_text_name = str_main_text_name;
542 static char *main_text_first_level = str_main_text_first_level;
543 static char *main_text_last_level = str_main_text_last_level;
544 static char *main_text_level_number = str_main_text_level_number;
545 static char *main_text_levels = "Levelset";
546 static char *main_text_scores = "Hall Of Fame";
547 static char *main_text_editor = "Level Creator";
548 static char *main_text_info = "Info Screen";
549 static char *main_text_game = "Start Game";
550 static char *main_text_setup = "Setup";
551 static char *main_text_quit = "Quit";
552 static char *main_text_level_name = level.name;
553 static char *main_text_level_author = level.author;
554 static char *main_text_level_year = NULL;
555 static char *main_text_level_imported_from = NULL;
556 static char *main_text_level_imported_by = NULL;
557 static char *main_text_level_tested_by = NULL;
559 struct MainControlInfo
563 struct MenuPosInfo *pos_button;
566 struct TextPosInfo *pos_text;
569 struct TextPosInfo *pos_input;
573 static struct MainControlInfo main_controls[] =
577 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
578 &menu.main.text.name, &main_text_name,
579 &menu.main.input.name, &setup.player_name,
583 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
584 &menu.main.text.levels, &main_text_levels,
589 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
590 &menu.main.text.scores, &main_text_scores,
595 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
596 &menu.main.text.editor, &main_text_editor,
601 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
602 &menu.main.text.info, &main_text_info,
607 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
608 &menu.main.text.game, &main_text_game,
613 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
614 &menu.main.text.setup, &main_text_setup,
619 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
620 &menu.main.text.quit, &main_text_quit,
624 /* (these two buttons are real gadgets) */
626 MAIN_CONTROL_PREV_LEVEL,
627 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
632 MAIN_CONTROL_NEXT_LEVEL,
633 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
639 MAIN_CONTROL_FIRST_LEVEL,
641 &menu.main.text.first_level, &main_text_first_level,
645 MAIN_CONTROL_LAST_LEVEL,
647 &menu.main.text.last_level, &main_text_last_level,
651 MAIN_CONTROL_LEVEL_NUMBER,
653 &menu.main.text.level_number, &main_text_level_number,
657 MAIN_CONTROL_LEVEL_INFO_1,
659 &menu.main.text.level_info_1, NULL,
663 MAIN_CONTROL_LEVEL_INFO_2,
665 &menu.main.text.level_info_2, NULL,
669 MAIN_CONTROL_LEVEL_NAME,
671 &menu.main.text.level_name, &main_text_level_name,
675 MAIN_CONTROL_LEVEL_AUTHOR,
677 &menu.main.text.level_author, &main_text_level_author,
681 MAIN_CONTROL_LEVEL_YEAR,
683 &menu.main.text.level_year, &main_text_level_year,
687 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
689 &menu.main.text.level_imported_from, &main_text_level_imported_from,
693 MAIN_CONTROL_LEVEL_IMPORTED_BY,
695 &menu.main.text.level_imported_by, &main_text_level_imported_by,
699 MAIN_CONTROL_LEVEL_TESTED_BY,
701 &menu.main.text.level_tested_by, &main_text_level_tested_by,
705 MAIN_CONTROL_TITLE_1,
707 &menu.main.text.title_1, &setup.internal.program_title,
711 MAIN_CONTROL_TITLE_2,
713 &menu.main.text.title_2, &setup.internal.program_copyright,
717 MAIN_CONTROL_TITLE_3,
719 &menu.main.text.title_3, &setup.internal.program_company,
732 static int getTitleScreenGraphic(int nr, boolean initial)
734 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
737 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
739 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
743 static int getTitleScreenGameMode(boolean initial)
745 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
749 static int getTitleMessageGameMode(boolean initial)
751 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
754 static int getTitleAnimMode(struct TitleControlInfo *tci)
756 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
758 return base + tci->local_nr;
762 static int getTitleScreenBackground(boolean initial)
764 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
769 static int getTitleMessageBackground(int nr, boolean initial)
771 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
775 static int getTitleBackground(int nr, boolean initial, boolean is_image)
777 int base = (is_image ?
778 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
779 IMG_BACKGROUND_TITLESCREEN_1) :
780 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
781 IMG_BACKGROUND_TITLEMESSAGE_1));
782 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
783 IMG_BACKGROUND_TITLE);
784 int graphic_local = base + nr;
786 if (graphic_info[graphic_local].bitmap != NULL)
787 return graphic_local;
789 if (graphic_info[graphic_global].bitmap != NULL)
790 return graphic_global;
792 return IMG_UNDEFINED;
795 static int getTitleSound(struct TitleControlInfo *tci)
797 boolean is_image = tci->is_image;
798 int initial = tci->initial;
799 int nr = tci->local_nr;
800 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
801 int base = (is_image ?
802 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
803 SND_BACKGROUND_TITLESCREEN_1) :
804 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
805 SND_BACKGROUND_TITLEMESSAGE_1));
806 int sound_global = menu.sound[mode];
807 int sound_local = base + nr;
810 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
811 nr, initial, is_image,
812 sound_global, getSoundListEntry(sound_global)->filename,
813 sound_local, getSoundListEntry(sound_local)->filename);
816 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
819 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
822 return SND_UNDEFINED;
825 static int getTitleMusic(struct TitleControlInfo *tci)
827 boolean is_image = tci->is_image;
828 int initial = tci->initial;
829 int nr = tci->local_nr;
830 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
831 int base = (is_image ?
832 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
833 MUS_BACKGROUND_TITLESCREEN_1) :
834 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
835 MUS_BACKGROUND_TITLEMESSAGE_1));
836 int music_global = menu.music[mode];
837 int music_local = base + nr;
840 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
841 nr, initial, is_image,
842 music_global, getMusicListEntry(music_global)->filename,
843 music_local, getMusicListEntry(music_local)->filename);
846 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
849 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
852 return MUS_UNDEFINED;
855 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
857 boolean is_image = tci->is_image;
858 boolean initial = tci->initial;
859 boolean first = tci->first;
860 int nr = tci->local_nr;
861 struct TitleMessageInfo tmi;
862 struct TitleFadingInfo ti;
864 tmi = (is_image ? (initial ? (first ?
865 titlescreen_initial_first[nr] :
866 titlescreen_initial[nr])
868 titlescreen_first[nr] :
870 : (initial ? (first ?
871 titlemessage_initial_first[nr] :
872 titlemessage_initial[nr])
874 titlemessage_first[nr] :
877 ti.fade_mode = tmi.fade_mode;
878 ti.fade_delay = tmi.fade_delay;
879 ti.post_delay = tmi.post_delay;
880 ti.auto_delay = tmi.auto_delay;
885 static int compareTitleControlInfo(const void *object1, const void *object2)
887 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
888 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
891 if (tci1->initial != tci2->initial)
892 compare_result = (tci1->initial ? -1 : +1);
893 else if (tci1->sort_priority != tci2->sort_priority)
894 compare_result = tci1->sort_priority - tci2->sort_priority;
895 else if (tci1->is_image != tci2->is_image)
896 compare_result = (tci1->is_image ? -1 : +1);
898 compare_result = tci1->local_nr - tci2->local_nr;
900 return compare_result;
903 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
905 int nr, int sort_priority)
907 title_controls[num_title_screens].is_image = is_image;
908 title_controls[num_title_screens].initial = initial;
909 title_controls[num_title_screens].local_nr = nr;
910 title_controls[num_title_screens].sort_priority = sort_priority;
912 title_controls[num_title_screens].first = FALSE; /* will be set later */
917 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
921 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
923 int graphic = getTitleScreenGraphic(i, initial);
924 Bitmap *bitmap = graphic_info[graphic].bitmap;
925 int sort_priority = graphic_info[graphic].sort_priority;
928 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
931 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
933 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
934 char *filename = getLevelSetTitleMessageFilename(i, initial);
935 int sort_priority = tmi->sort_priority;
937 if (filename != NULL)
938 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
942 static void InitializeTitleControls(boolean show_title_initial)
944 num_title_screens = 0;
946 /* 1st step: initialize title screens for game start (only when starting) */
947 if (show_title_initial)
948 InitializeTitleControls_CheckTitleInfo(TRUE);
950 /* 2nd step: initialize title screens for current level set */
951 InitializeTitleControls_CheckTitleInfo(FALSE);
953 /* sort title screens according to sort_priority and title number */
954 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
955 compareTitleControlInfo);
957 /* mark first title screen */
958 title_controls[0].first = TRUE;
961 static boolean visibleMenuPos(struct MenuPosInfo *pos)
963 return (pos != NULL && pos->x != -1 && pos->y != -1);
966 static boolean visibleTextPos(struct TextPosInfo *pos)
968 return (pos != NULL && pos->x != -1 && pos->y != -1);
971 static void InitializeMainControls()
973 boolean local_team_mode = (!options.network && setup.team_mode);
976 /* set main control text values to dynamically determined values */
977 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
979 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
980 menu.main.text.first_level.size));
981 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
982 menu.main.text.last_level.size));
983 strcpy(main_text_level_number, int2str(level_nr,
984 menu.main.text.level_number.size));
986 main_text_level_year = leveldir_current->year;
987 main_text_level_imported_from = leveldir_current->imported_from;
988 main_text_level_imported_by = leveldir_current->imported_by;
989 main_text_level_tested_by = leveldir_current->tested_by;
991 /* set main control screen positions to dynamically determined values */
992 for (i = 0; main_controls[i].nr != -1; i++)
994 struct MainControlInfo *mci = &main_controls[i];
996 struct MenuPosInfo *pos_button = mci->pos_button;
997 struct TextPosInfo *pos_text = mci->pos_text;
998 struct TextPosInfo *pos_input = mci->pos_input;
999 char *text = (mci->text ? *mci->text : NULL);
1000 char *input = (mci->input ? *mci->input : NULL);
1001 int button_graphic = mci->button_graphic;
1002 int font_text = (pos_text ? pos_text->font : -1);
1003 int font_input = (pos_input ? pos_input->font : -1);
1005 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1006 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1007 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1008 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1009 int text_chars = (text != NULL ? strlen(text) : 0);
1010 int input_chars = (input != NULL ? strlen(input) : 0);
1013 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1015 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1016 int text_width = font_text_width * text_chars;
1017 int text_height = font_text_height;
1018 int input_width = font_input_width * input_chars;
1019 int input_height = font_input_height;
1021 if (nr == MAIN_CONTROL_NAME)
1023 menu.main.input.name.width = input_width;
1024 menu.main.input.name.height = input_height;
1027 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1029 pos_button->width = button_width;
1030 pos_button->height = button_height;
1033 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1035 /* calculate size for non-clickable text -- needed for text alignment */
1036 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1038 if (pos_text->width == -1 || calculate_text_size)
1039 pos_text->width = text_width;
1040 if (pos_text->height == -1 || calculate_text_size)
1041 pos_text->height = text_height;
1043 if (visibleMenuPos(pos_button))
1045 if (pos_text->x == -1)
1046 pos_text->x = pos_button->x + pos_button->width;
1047 if (pos_text->y == -1)
1049 pos_button->y + (pos_button->height - pos_text->height) / 2;
1053 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1055 if (visibleTextPos(pos_text))
1057 if (pos_input->x == -1)
1058 pos_input->x = pos_text->x + pos_text->width;
1059 if (pos_input->y == -1)
1060 pos_input->y = pos_text->y;
1063 if (pos_input->width == -1)
1064 pos_input->width = input_width;
1065 if (pos_input->height == -1)
1066 pos_input->height = input_height;
1071 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1072 int graphic, boolean pressed)
1074 struct GraphicInfo *g = &graphic_info[graphic];
1077 int xoffset = (pressed ? g->pressed_xoffset : 0);
1078 int yoffset = (pressed ? g->pressed_yoffset : 0);
1080 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1082 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1083 g->width, g->height, dst_x, dst_y);
1086 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1087 boolean active_input,
1088 boolean pressed_button)
1092 for (i = 0; main_controls[i].nr != -1; i++)
1094 struct MainControlInfo *mci = &main_controls[i];
1096 if (mci->nr == nr || nr == -1)
1098 struct MenuPosInfo *pos_button = mci->pos_button;
1099 struct TextPosInfo *pos_text = mci->pos_text;
1100 struct TextPosInfo *pos_input = mci->pos_input;
1101 char *text = (mci->text ? *mci->text : NULL);
1102 char *input = (mci->input ? *mci->input : NULL);
1103 int button_graphic = mci->button_graphic;
1104 int font_text = (pos_text ? pos_text->font : -1);
1105 int font_input = (pos_input ? pos_input->font : -1);
1109 button_graphic = BUTTON_ACTIVE(button_graphic);
1110 font_text = FONT_ACTIVE(font_text);
1115 font_input = FONT_ACTIVE(font_input);
1118 if (visibleMenuPos(pos_button))
1120 struct MenuPosInfo *pos = pos_button;
1121 int x = mSX + pos->x;
1122 int y = mSY + pos->y;
1124 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1125 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1128 if (visibleTextPos(pos_text) && text != NULL)
1130 struct TextPosInfo *pos = pos_text;
1131 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1132 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1135 /* (check why/if this is needed) */
1136 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1138 DrawText(x, y, text, font_text);
1141 if (visibleTextPos(pos_input) && input != NULL)
1143 struct TextPosInfo *pos = pos_input;
1144 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1145 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1148 /* (check why/if this is needed) */
1149 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1151 DrawText(x, y, input, font_input);
1157 static void DrawCursorAndText_Main(int nr, boolean active_text,
1158 boolean pressed_button)
1160 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1164 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1165 boolean pressed_button)
1167 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1171 static struct MainControlInfo *getMainControlInfo(int nr)
1175 for (i = 0; main_controls[i].nr != -1; i++)
1176 if (main_controls[i].nr == nr)
1177 return &main_controls[i];
1182 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1187 int rect_x = ALIGNED_TEXT_XPOS(rect);
1188 int rect_y = ALIGNED_TEXT_YPOS(rect);
1190 return (x >= rect_x && x < rect_x + rect->width &&
1191 y >= rect_y && y < rect_y + rect->height);
1194 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1199 int rect_x = ALIGNED_TEXT_XPOS(rect);
1200 int rect_y = ALIGNED_TEXT_YPOS(rect);
1203 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1204 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1205 (x >= rect_x && x < rect_x + rect->width &&
1206 y >= rect_y && y < rect_y + rect->height));
1209 return (x >= rect_x && x < rect_x + rect->width &&
1210 y >= rect_y && y < rect_y + rect->height);
1213 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1215 int rect_width = preview->xsize * preview->tile_size;
1216 int rect_height = preview->ysize * preview->tile_size;
1217 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1218 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1220 return (x >= rect_x && x < rect_x + rect_width &&
1221 y >= rect_y && y < rect_y + rect_height);
1224 static void AdjustScrollbar(int id, int items_max, int items_visible,
1227 struct GadgetInfo *gi = screen_gadget[id];
1229 if (item_position > items_max - items_visible)
1230 item_position = items_max - items_visible;
1232 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1233 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1234 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1237 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1239 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1243 static void clearMenuListArea()
1245 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1247 /* correct scrollbar position if placed outside menu (playfield) area */
1248 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1249 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1251 /* clear menu list area, but not title or scrollbar */
1252 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1253 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1256 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1258 static int cursor_array[MAX_LEV_FIELDY];
1259 int x = mSX + TILEX * xpos;
1260 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1265 cursor_array[ypos] = graphic;
1267 graphic = cursor_array[ypos];
1271 graphic = BUTTON_ACTIVE(graphic);
1273 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1274 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1277 static void initCursor(int ypos, int graphic)
1279 drawCursorExt(0, ypos, FALSE, graphic);
1282 static void drawCursor(int ypos, boolean active)
1284 drawCursorExt(0, ypos, active, -1);
1287 static void drawCursorXY(int xpos, int ypos, int graphic)
1289 drawCursorExt(xpos, ypos, FALSE, graphic);
1292 static void drawChooseTreeCursor(int ypos, boolean active)
1294 drawCursorExt(0, ypos, active, -1);
1299 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1300 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1301 setup.internal.program_copyright);
1304 void DrawTitleScreenImage(int nr, boolean initial)
1306 int graphic = getTitleScreenGraphic(nr, initial);
1307 Bitmap *bitmap = graphic_info[graphic].bitmap;
1308 int width = graphic_info[graphic].width;
1309 int height = graphic_info[graphic].height;
1310 int src_x = graphic_info[graphic].src_x;
1311 int src_y = graphic_info[graphic].src_y;
1317 if (width > WIN_XSIZE)
1319 /* image width too large for window => center image horizontally */
1320 src_x = (width - WIN_XSIZE) / 2;
1324 if (height > WIN_YSIZE)
1326 /* image height too large for window => center image vertically */
1327 src_y = (height - WIN_YSIZE) / 2;
1331 /* always display title screens centered */
1332 dst_x = (WIN_XSIZE - width) / 2;
1333 dst_y = (WIN_YSIZE - height) / 2;
1335 SetDrawBackgroundMask(REDRAW_ALL);
1336 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1338 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1340 if (DrawingOnBackground(dst_x, dst_y))
1341 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1343 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1345 redraw_mask = REDRAW_ALL;
1348 void DrawTitleScreenMessage(int nr, boolean initial)
1350 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1351 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1353 if (filename == NULL)
1356 /* force TITLE font on title message screen */
1357 SetFontStatus(getTitleMessageGameMode(initial));
1359 /* if chars *and* width set to "-1", automatically determine width */
1360 if (tmi->chars == -1 && tmi->width == -1)
1361 tmi->width = viewport.window[game_status].width;
1363 /* if lines *and* height set to "-1", automatically determine height */
1364 if (tmi->lines == -1 && tmi->height == -1)
1365 tmi->height = viewport.window[game_status].height;
1367 /* if chars set to "-1", automatically determine by text and font width */
1368 if (tmi->chars == -1)
1369 tmi->chars = tmi->width / getFontWidth(tmi->font);
1371 tmi->width = tmi->chars * getFontWidth(tmi->font);
1373 /* if lines set to "-1", automatically determine by text and font height */
1374 if (tmi->lines == -1)
1375 tmi->lines = tmi->height / getFontHeight(tmi->font);
1377 tmi->height = tmi->lines * getFontHeight(tmi->font);
1379 /* if x set to "-1", automatically determine by width and alignment */
1381 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1383 /* if y set to "-1", automatically determine by height and alignment */
1385 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1387 SetDrawBackgroundMask(REDRAW_ALL);
1388 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1390 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1392 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1393 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1394 tmi->autowrap, tmi->centered, tmi->parse_comments);
1399 void DrawTitleScreen()
1401 KeyboardAutoRepeatOff();
1403 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1406 boolean CheckTitleScreen(boolean levelset_has_changed)
1408 static boolean show_title_initial = TRUE;
1409 boolean show_titlescreen = FALSE;
1411 /* needed to be able to skip title screen, if no image or message defined */
1412 InitializeTitleControls(show_title_initial);
1414 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1415 show_titlescreen = TRUE;
1417 /* show initial title images and messages only once at program start */
1418 show_title_initial = FALSE;
1420 return (show_titlescreen && num_title_screens > 0);
1425 static LevelDirTree *leveldir_last_valid = NULL;
1426 boolean levelset_has_changed = FALSE;
1427 int fade_mask = REDRAW_FIELD;
1429 LimitScreenUpdates(FALSE);
1431 FadeSetLeaveScreen();
1433 /* do not fade out here -- function may continue and fade on editor screen */
1436 FadeMenuSoundsAndMusic();
1438 ExpireSoundLoops(FALSE);
1440 KeyboardAutoRepeatOn();
1442 audio.sound_deactivated = FALSE;
1446 /* needed if last screen was the playing screen, invoked from level editor */
1447 if (level_editor_test_game)
1449 CloseDoor(DOOR_CLOSE_ALL);
1451 SetGameStatus(GAME_MODE_EDITOR);
1458 /* needed if last screen was the setup screen and fullscreen state changed */
1459 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1460 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1462 /* leveldir_current may be invalid (level group, parent link) */
1463 if (!validLevelSeries(leveldir_current))
1464 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1466 if (leveldir_current != leveldir_last_valid)
1467 levelset_has_changed = TRUE;
1469 /* store valid level series information */
1470 leveldir_last_valid = leveldir_current;
1472 init_last = init; /* switch to new busy animation */
1474 /* needed if last screen (level choice) changed graphics, sounds or music */
1475 ReloadCustomArtwork(0);
1477 if (CheckTitleScreen(levelset_has_changed))
1479 SetGameStatus(GAME_MODE_TITLE);
1486 if (redraw_mask & REDRAW_ALL)
1487 fade_mask = REDRAW_ALL;
1489 if (CheckIfGlobalBorderHasChanged())
1490 fade_mask = REDRAW_ALL;
1494 /* needed if different viewport properties defined for menues */
1495 ChangeViewportPropertiesIfNeeded();
1497 SetDrawtoField(DRAW_TO_BACKBUFFER);
1499 /* level_nr may have been set to value over handicap with level editor */
1500 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1501 level_nr = leveldir_current->handicap_level;
1503 LoadLevel(level_nr);
1504 LoadScore(level_nr);
1506 SaveLevelSetup_SeriesInfo();
1508 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1509 SetDrawDeactivationMask(REDRAW_NONE);
1510 SetDrawBackgroundMask(REDRAW_FIELD);
1512 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1515 if (fade_mask == REDRAW_ALL)
1516 RedrawGlobalBorder();
1521 InitializeMainControls();
1523 DrawCursorAndText_Main(-1, FALSE, FALSE);
1524 DrawPreviewLevelInitial();
1526 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1529 if (TAPE_IS_EMPTY(tape))
1531 DrawCompleteVideoDisplay();
1533 PlayMenuSoundsAndMusic();
1535 /* create gadgets for main menu screen */
1536 FreeScreenGadgets();
1537 CreateScreenGadgets();
1539 /* map gadgets for main menu screen */
1541 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1543 /* copy actual game door content to door double buffer for OpenDoor() */
1544 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1545 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1547 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1549 DrawMaskedBorder(fade_mask);
1554 /* update screen area with special editor door */
1555 redraw_mask |= REDRAW_ALL;
1558 SetMouseCursor(CURSOR_DEFAULT);
1560 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1563 static void gotoTopLevelDir()
1565 /* move upwards until inside (but not above) top level directory */
1566 while (leveldir_current->node_parent &&
1567 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1569 /* write a "path" into level tree for easy navigation to last level */
1570 if (leveldir_current->node_parent->node_group->cl_first == -1)
1572 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1573 int leveldir_pos = posTreeInfo(leveldir_current);
1574 int num_page_entries;
1575 int cl_first, cl_cursor;
1577 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1578 num_page_entries = num_leveldirs;
1580 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1582 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1583 cl_cursor = leveldir_pos - cl_first;
1585 leveldir_current->node_parent->node_group->cl_first = cl_first;
1586 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1589 leveldir_current = leveldir_current->node_parent;
1593 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1595 static unsigned int title_delay = 0;
1596 static int title_screen_nr = 0;
1597 static int last_sound = -1, last_music = -1;
1598 boolean return_to_main_menu = FALSE;
1599 struct TitleControlInfo *tci;
1602 if (button == MB_MENU_INITIALIZE)
1605 title_screen_nr = 0;
1606 tci = &title_controls[title_screen_nr];
1608 SetAnimStatus(getTitleAnimMode(tci));
1610 last_sound = SND_UNDEFINED;
1611 last_music = MUS_UNDEFINED;
1613 if (num_title_screens != 0)
1615 FadeSetEnterScreen();
1617 /* use individual title fading instead of global "enter screen" fading */
1618 fading = getTitleFading(tci);
1621 if (game_status_last_screen == GAME_MODE_INFO)
1623 if (num_title_screens == 0)
1625 /* switch game mode from title screen mode back to info screen mode */
1626 SetGameStatus(GAME_MODE_INFO);
1628 /* store that last screen was info screen, not main menu screen */
1629 game_status_last_screen = GAME_MODE_INFO;
1631 DrawInfoScreen_NotAvailable("Title screen information:",
1632 "No title screen for this level set.");
1636 FadeMenuSoundsAndMusic();
1639 FadeOut(REDRAW_ALL);
1641 /* title screens may have different window size */
1642 ChangeViewportPropertiesIfNeeded();
1644 /* only required to update logic for redrawing global border */
1648 DrawTitleScreenImage(tci->local_nr, tci->initial);
1650 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1652 sound = getTitleSound(tci);
1653 music = getTitleMusic(tci);
1655 if (sound != last_sound)
1656 PlayMenuSoundExt(sound);
1657 if (music != last_music)
1658 PlayMenuMusicExt(music);
1663 SetMouseCursor(CURSOR_NONE);
1667 DelayReached(&title_delay, 0); /* reset delay counter */
1672 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1673 button = MB_MENU_CHOICE;
1675 if (button == MB_MENU_LEAVE)
1677 return_to_main_menu = TRUE;
1679 else if (button == MB_MENU_CHOICE)
1681 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1683 SetGameStatus(GAME_MODE_INFO);
1685 info_mode = INFO_MODE_MAIN;
1694 if (title_screen_nr < num_title_screens)
1696 tci = &title_controls[title_screen_nr];
1698 SetAnimStatus(getTitleAnimMode(tci));
1700 sound = getTitleSound(tci);
1701 music = getTitleMusic(tci);
1703 if (last_sound != SND_UNDEFINED && sound != last_sound)
1704 FadeSound(last_sound);
1705 if (last_music != MUS_UNDEFINED && music != last_music)
1708 fading = getTitleFading(tci);
1710 FadeOut(REDRAW_ALL);
1713 DrawTitleScreenImage(tci->local_nr, tci->initial);
1715 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1717 sound = getTitleSound(tci);
1718 music = getTitleMusic(tci);
1720 if (sound != last_sound)
1721 PlayMenuSoundExt(sound);
1722 if (music != last_music)
1723 PlayMenuMusicExt(music);
1730 DelayReached(&title_delay, 0); /* reset delay counter */
1734 FadeMenuSoundsAndMusic();
1736 return_to_main_menu = TRUE;
1740 if (return_to_main_menu)
1742 SetMouseCursor(CURSOR_DEFAULT);
1744 /* force full menu screen redraw after displaying title screens */
1745 redraw_mask = REDRAW_ALL;
1747 if (game_status_last_screen == GAME_MODE_INFO)
1749 SetGameStatus(GAME_MODE_INFO);
1751 info_mode = INFO_MODE_MAIN;
1755 else /* default: return to main menu */
1757 SetGameStatus(GAME_MODE_MAIN);
1764 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1766 int old_level_nr = level_nr;
1769 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1770 new_level_nr = selected_level_nr;
1772 new_level_nr = old_level_nr + step * direction;
1774 if (new_level_nr < leveldir_current->first_level)
1775 new_level_nr = leveldir_current->first_level;
1776 if (new_level_nr > leveldir_current->last_level)
1777 new_level_nr = leveldir_current->last_level;
1779 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1781 /* skipping levels is only allowed when trying to skip single level */
1782 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1783 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1785 leveldir_current->handicap_level++;
1786 SaveLevelSetup_SeriesInfo();
1789 new_level_nr = leveldir_current->handicap_level;
1792 if (new_level_nr != old_level_nr)
1794 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1796 PlaySound(SND_MENU_ITEM_SELECTING);
1798 level_nr = new_level_nr;
1800 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1801 int2str(level_nr, menu.main.text.level_number.size),
1802 mci->pos_text->font);
1804 LoadLevel(level_nr);
1805 DrawPreviewLevelInitial();
1809 DrawCompleteVideoDisplay();
1811 SaveLevelSetup_SeriesInfo();
1813 /* needed because DrawPreviewLevelInitial() takes some time */
1815 /* SyncDisplay(); */
1819 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1821 static int choice = MAIN_CONTROL_GAME;
1822 static boolean button_pressed_last = FALSE;
1823 boolean button_pressed = FALSE;
1827 if (button == MB_MENU_INITIALIZE)
1829 DrawCursorAndText_Main(choice, TRUE, FALSE);
1834 if (mx || my) /* mouse input */
1838 for (i = 0; main_controls[i].nr != -1; i++)
1840 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1841 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1842 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1844 pos = main_controls[i].nr;
1850 /* check if level preview was clicked */
1851 if (insidePreviewRect(&preview, mx - SX, my - SY))
1852 pos = MAIN_CONTROL_GAME;
1854 // handle pressed/unpressed state for active/inactive menu buttons
1855 // (if pos != -1, "i" contains index position corresponding to "pos")
1857 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1858 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1859 button_pressed = TRUE;
1861 if (button_pressed != button_pressed_last)
1863 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1866 PlaySound(SND_MENU_BUTTON_PRESSING);
1868 PlaySound(SND_MENU_BUTTON_RELEASING);
1871 else if (dx || dy) /* keyboard input */
1873 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1874 choice == MAIN_CONTROL_SETUP))
1875 button = MB_MENU_CHOICE;
1880 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1882 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1884 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1886 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1888 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1890 CloseDoor(DOOR_CLOSE_2);
1892 SetGameStatus(GAME_MODE_LEVELNR);
1894 DrawChooseLevelNr();
1896 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1902 PlaySound(SND_MENU_ITEM_ACTIVATING);
1904 DrawCursorAndText_Main(choice, FALSE, FALSE);
1905 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1911 if (choice != MAIN_CONTROL_INFO &&
1912 choice != MAIN_CONTROL_SETUP)
1913 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
1918 PlaySound(SND_MENU_ITEM_SELECTING);
1920 if (pos == MAIN_CONTROL_NAME)
1922 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1924 HandleTypeName(strlen(setup.player_name), 0);
1926 else if (pos == MAIN_CONTROL_LEVELS)
1930 CloseDoor(DOOR_CLOSE_2);
1932 SetGameStatus(GAME_MODE_LEVELS);
1934 SaveLevelSetup_LastSeries();
1935 SaveLevelSetup_SeriesInfo();
1937 if (setup.internal.choose_from_top_leveldir)
1940 DrawChooseLevelSet();
1943 else if (pos == MAIN_CONTROL_SCORES)
1945 CloseDoor(DOOR_CLOSE_2);
1947 SetGameStatus(GAME_MODE_SCORES);
1951 else if (pos == MAIN_CONTROL_EDITOR)
1953 if (leveldir_current->readonly &&
1954 !strEqual(setup.player_name, "Artsoft"))
1955 Request("This level is read only!", REQ_CONFIRM);
1957 CloseDoor(DOOR_CLOSE_2);
1959 SetGameStatus(GAME_MODE_EDITOR);
1961 FadeSetEnterScreen();
1965 else if (pos == MAIN_CONTROL_INFO)
1967 CloseDoor(DOOR_CLOSE_2);
1969 SetGameStatus(GAME_MODE_INFO);
1971 info_mode = INFO_MODE_MAIN;
1975 else if (pos == MAIN_CONTROL_GAME)
1977 StartGameActions(options.network, setup.autorecord, level.random_seed);
1979 else if (pos == MAIN_CONTROL_SETUP)
1981 CloseDoor(DOOR_CLOSE_2);
1983 SetGameStatus(GAME_MODE_SETUP);
1985 setup_mode = SETUP_MODE_MAIN;
1989 else if (pos == MAIN_CONTROL_QUIT)
1991 SaveLevelSetup_LastSeries();
1992 SaveLevelSetup_SeriesInfo();
1994 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1995 SetGameStatus(GAME_MODE_QUIT);
2000 button_pressed_last = button_pressed;
2004 /* ========================================================================= */
2005 /* info screen functions */
2006 /* ========================================================================= */
2008 static struct TokenInfo *info_info;
2009 static int num_info_info; /* number of info entries shown on screen */
2010 static int max_info_info; /* total number of info entries in list */
2012 static void execInfoTitleScreen()
2014 info_mode = INFO_MODE_TITLE;
2019 static void execInfoElements()
2021 info_mode = INFO_MODE_ELEMENTS;
2026 static void execInfoMusic()
2028 info_mode = INFO_MODE_MUSIC;
2033 static void execInfoCredits()
2035 info_mode = INFO_MODE_CREDITS;
2040 static void execInfoProgram()
2042 info_mode = INFO_MODE_PROGRAM;
2047 static void execInfoVersion()
2049 info_mode = INFO_MODE_VERSION;
2054 static void execInfoLevelSet()
2056 info_mode = INFO_MODE_LEVELSET;
2061 static void execExitInfo()
2063 SetGameStatus(GAME_MODE_MAIN);
2068 static struct TokenInfo info_info_main[] =
2070 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2071 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2072 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2073 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2074 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2075 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2076 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2077 { TYPE_EMPTY, NULL, "" },
2078 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2083 static int getMenuTextFont(int type)
2085 if (type & (TYPE_SWITCH |
2097 static struct TokenInfo *setup_info;
2098 static struct TokenInfo setup_info_input[];
2100 static struct TokenInfo *menu_info;
2102 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2103 int screen_pos, int menu_info_pos_raw,
2106 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2107 struct TokenInfo *ti = &token_info[pos];
2108 int xpos = MENU_SCREEN_START_XPOS;
2109 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2110 int font_nr = getMenuTextFont(ti->type);
2112 if (token_info == setup_info_input)
2113 font_nr = FONT_MENU_1;
2116 font_nr = FONT_ACTIVE(font_nr);
2118 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2120 if (ti->type & ~TYPE_SKIP_ENTRY)
2121 drawCursor(screen_pos, active);
2124 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2127 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2130 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2133 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2136 static char *window_size_text;
2137 static char *scaling_type_text;
2139 static void drawSetupValue(int, int);
2141 static void drawMenuInfoList(int first_entry, int num_page_entries,
2142 int max_page_entries)
2146 if (first_entry + num_page_entries > max_page_entries)
2149 clearMenuListArea();
2151 for (i = 0; i < num_page_entries; i++)
2153 int menu_info_pos = first_entry + i;
2154 struct TokenInfo *si = &menu_info[menu_info_pos];
2155 void *value_ptr = si->value;
2157 /* set some entries to "unchangeable" according to other variables */
2158 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2159 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2160 (value_ptr == &setup.sound_music && !audio.music_available) ||
2161 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2162 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2163 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2164 si->type |= TYPE_GHOSTED;
2166 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2167 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2168 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2169 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2170 else if (si->type & ~TYPE_SKIP_ENTRY)
2171 initCursor(i, IMG_MENU_BUTTON);
2173 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2175 if (si->type & TYPE_VALUE &&
2176 menu_info == setup_info)
2177 drawSetupValue(i, menu_info_pos);
2181 static void DrawInfoScreen_Main()
2183 int fade_mask = REDRAW_FIELD;
2186 if (redraw_mask & REDRAW_ALL)
2187 fade_mask = REDRAW_ALL;
2189 if (CheckIfGlobalBorderHasChanged())
2190 fade_mask = REDRAW_ALL;
2193 FadeMenuSoundsAndMusic();
2195 FreeScreenGadgets();
2196 CreateScreenGadgets();
2198 /* (needed after displaying title screens which disable auto repeat) */
2199 KeyboardAutoRepeatOn();
2201 FadeSetLeaveScreen();
2205 /* needed if different viewport properties defined for info screen */
2206 ChangeViewportPropertiesIfNeeded();
2208 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2212 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2214 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2216 info_info = info_info_main;
2218 // determine maximal number of info entries that can be displayed on screen
2220 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2223 // determine maximal number of info entries available for menu of info screen
2225 for (i = 0; info_info[i].type != 0; i++)
2228 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2230 MapScreenGadgets(max_info_info);
2232 PlayMenuSoundsAndMusic();
2234 DrawMaskedBorder(fade_mask);
2239 static void changeSetupValue(int, int, int);
2241 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2242 int mode, int num_page_entries, int max_page_entries)
2244 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2245 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2246 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2247 int *num_page_entries_last = num_page_entries_all_last[game_status];
2248 int *choice_store = choice_stores[game_status];
2249 int *first_entry_store = first_entry_stores[game_status];
2250 int choice = choice_store[mode]; /* starts with 0 */
2251 int first_entry = first_entry_store[mode]; /* starts with 0 */
2253 int y = choice - first_entry;
2255 boolean position_set_by_scrollbar = (dx == 999);
2256 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2259 if (button == MB_MENU_INITIALIZE)
2261 // check if number of menu page entries has changed (may happen by change
2262 // of custom artwork definition value for 'list_size' for this menu screen)
2263 // (in this case, the last menu position most probably has to be corrected)
2264 if (num_page_entries != num_page_entries_last[mode])
2266 choice_store[mode] = first_entry_store[mode] = 0;
2268 choice = first_entry = 0;
2271 num_page_entries_last[mode] = num_page_entries;
2274 /* advance to first valid menu entry */
2275 while (choice < num_page_entries &&
2276 menu_info[choice].type & TYPE_SKIP_ENTRY)
2279 if (position_set_by_scrollbar)
2280 first_entry = first_entry_store[mode] = dy;
2282 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2283 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2285 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2287 if (choice < first_entry)
2289 choice = first_entry;
2291 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2294 else if (choice > first_entry + num_page_entries - 1)
2296 choice = first_entry + num_page_entries - 1;
2298 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2302 choice_store[mode] = choice;
2304 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2308 else if (button == MB_MENU_LEAVE)
2310 PlaySound(SND_MENU_ITEM_SELECTING);
2312 for (i = 0; i < max_page_entries; i++)
2314 if (menu_info[i].type & TYPE_LEAVE_MENU)
2316 void (*menu_callback_function)(void) = menu_info[i].value;
2320 menu_callback_function();
2322 break; /* absolutely needed because function changes 'menu_info'! */
2329 if (mx || my) /* mouse input */
2331 x = (mx - mSX) / 32;
2332 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2334 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2336 /* move cursor instead of scrolling when already at start/end of list */
2337 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2339 else if (dy == +1 * SCROLL_LINE &&
2340 first_entry + num_page_entries == max_page_entries)
2343 /* handle scrolling screen one line or page */
2345 y + dy > num_page_entries - 1)
2347 boolean redraw = FALSE;
2349 if (ABS(dy) == SCROLL_PAGE)
2350 step = num_page_entries - 1;
2352 if (dy < 0 && first_entry > 0)
2354 /* scroll page/line up */
2356 first_entry -= step;
2357 if (first_entry < 0)
2362 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2364 /* scroll page/line down */
2366 first_entry += step;
2367 if (first_entry + num_page_entries > max_page_entries)
2368 first_entry = MAX(0, max_page_entries - num_page_entries);
2375 choice += first_entry - first_entry_store[mode];
2377 if (choice < first_entry)
2379 choice = first_entry;
2381 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2384 else if (choice > first_entry + num_page_entries - 1)
2386 choice = first_entry + num_page_entries - 1;
2388 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2391 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2395 if (choice < first_entry ||
2396 choice > first_entry + num_page_entries - 1)
2397 first_entry += SIGN(dy);
2400 first_entry_store[mode] = first_entry;
2401 choice_store[mode] = choice;
2403 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2405 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2407 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2408 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2416 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2418 if (menu_info[choice].type & menu_navigation_type ||
2419 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2420 menu_info[choice].type & TYPE_YES_NO_AUTO)
2421 button = MB_MENU_CHOICE;
2426 /* jump to next non-empty menu entry (up or down) */
2427 while (first_entry + y > 0 &&
2428 first_entry + y < max_page_entries - 1 &&
2429 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2432 if (!IN_VIS_MENU(x, y))
2434 choice += y - y_old;
2436 if (choice < first_entry)
2437 first_entry = choice;
2438 else if (choice > first_entry + num_page_entries - 1)
2439 first_entry = choice - num_page_entries + 1;
2441 if (first_entry >= 0 &&
2442 first_entry + num_page_entries <= max_page_entries)
2444 first_entry_store[mode] = first_entry;
2446 if (choice < first_entry)
2447 choice = first_entry;
2448 else if (choice > first_entry + num_page_entries - 1)
2449 choice = first_entry + num_page_entries - 1;
2451 choice_store[mode] = choice;
2453 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2455 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2457 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2458 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2465 if (!anyScrollbarGadgetActive() &&
2466 IN_VIS_MENU(x, y) &&
2467 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2468 y >= 0 && y < num_page_entries)
2472 if (first_entry + y != choice &&
2473 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2475 PlaySound(SND_MENU_ITEM_ACTIVATING);
2477 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2478 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2480 choice = choice_store[mode] = first_entry + y;
2484 PlaySound(SND_MENU_ITEM_SELECTING);
2486 for (i = 0; menu_info[i].type != 0; i++)
2488 if (menu_info[i].type & TYPE_LEAVE_MENU)
2490 void (*menu_callback_function)(void) = menu_info[i].value;
2494 menu_callback_function();
2496 /* absolutely needed because function changes 'menu_info'! */
2504 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2506 PlaySound(SND_MENU_ITEM_SELECTING);
2508 /* when selecting key headline, execute function for key value change */
2509 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2510 menu_info[first_entry + y + 1].type & TYPE_KEY)
2513 /* when selecting string value, execute function for list selection */
2514 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2515 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2518 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2520 void (*menu_callback_function)(void) =
2521 menu_info[first_entry + y].value;
2523 FadeSetFromType(menu_info[first_entry + y].type);
2525 menu_callback_function();
2527 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2528 menu_info == setup_info)
2530 changeSetupValue(y, first_entry + y, dx);
2536 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2538 menu_info = info_info;
2540 HandleMenuScreen(mx, my, dx, dy, button,
2541 info_mode, num_info_info, max_info_info);
2544 static int getMenuFontSpacing(int spacing_height, int font_nr)
2546 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2548 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2552 static int getMenuTextSpacing(int spacing_height, int font_nr)
2554 return (getMenuFontSpacing(spacing_height, font_nr) +
2555 EXTRA_SPACING(game_status));
2558 static int getMenuTextStep(int spacing_height, int font_nr)
2560 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2563 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2565 int font_title = MENU_INFO_FONT_TITLE;
2566 int font_error = FONT_TEXT_2;
2567 int font_foot = MENU_INFO_FONT_FOOT;
2568 int spacing_title = menu.headline1_spacing_info[info_mode];
2569 int ystep_title = getMenuTextStep(spacing_title, font_title);
2570 int ystart1 = mSY - SY + 100;
2571 int ystart2 = ystart1 + ystep_title;
2572 int ybottom = mSY - SY + SYSIZE - 20;
2574 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2576 FadeOut(REDRAW_FIELD);
2581 DrawTextSCentered(ystart1, font_title, text_title);
2582 DrawTextSCentered(ystart2, font_error, text_error);
2584 DrawTextSCentered(ybottom, font_foot,
2585 "Press any key or button for info menu");
2587 FadeIn(REDRAW_FIELD);
2590 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2592 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2593 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2594 int font_title = MENU_INFO_FONT_TITLE;
2595 int font_foot = MENU_INFO_FONT_FOOT;
2596 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2597 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2598 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2599 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2600 int ystep = MENU_SCREEN_INFO_YSTEP;
2601 int element, action, direction;
2609 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2610 infoscreen_step[i] = infoscreen_frame[i] = 0;
2615 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2617 DrawTextSCentered(ybottom, font_foot,
2618 "Press any key or button for next page");
2624 while (helpanim_info[j].element != HELPANIM_LIST_END)
2626 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2631 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2640 j += infoscreen_step[i - start];
2642 element = helpanim_info[j].element;
2643 action = helpanim_info[j].action;
2644 direction = helpanim_info[j].direction;
2647 element = EL_UNKNOWN;
2649 if (action != -1 && direction != -1)
2650 graphic = el_act_dir2img(element, action, direction);
2651 else if (action != -1)
2652 graphic = el_act2img(element, action);
2653 else if (direction != -1)
2654 graphic = el_dir2img(element, direction);
2656 graphic = el2img(element);
2658 delay = helpanim_info[j++].delay;
2663 if (infoscreen_frame[i - start] == 0)
2666 infoscreen_frame[i - start] = delay - 1;
2670 sync_frame = delay - infoscreen_frame[i - start];
2671 infoscreen_frame[i - start]--;
2674 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2676 if (!infoscreen_frame[i - start])
2677 infoscreen_step[i - start] = 0;
2681 if (!infoscreen_frame[i - start])
2682 infoscreen_step[i - start]++;
2683 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2689 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2691 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2692 graphic, sync_frame, USE_MASKING);
2695 DrawInfoScreen_HelpText(element, action, direction, i - start);
2700 redraw_mask |= REDRAW_FIELD;
2705 static char *getHelpText(int element, int action, int direction)
2707 char token[MAX_LINE_LEN];
2709 strcpy(token, element_info[element].token_name);
2712 strcat(token, element_action_info[action].suffix);
2714 if (direction != -1)
2715 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2717 return getHashEntry(helptext_info, token);
2720 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2722 int font_nr = FONT_INFO_ELEMENTS;
2723 int font_width = getFontWidth(font_nr);
2724 int font_height = getFontHeight(font_nr);
2725 int yoffset = (TILEX - 2 * font_height) / 2;
2726 int xstart = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2727 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2728 int ystep = TILEY + 4;
2729 int pad_x = xstart - SX;
2730 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2731 int max_lines_per_text = 2;
2734 if (action != -1 && direction != -1) /* element.action.direction */
2735 text = getHelpText(element, action, direction);
2737 if (text == NULL && action != -1) /* element.action */
2738 text = getHelpText(element, action, -1);
2740 if (text == NULL && direction != -1) /* element.direction */
2741 text = getHelpText(element, -1, direction);
2743 if (text == NULL) /* base element */
2744 text = getHelpText(element, -1, -1);
2746 if (text == NULL) /* not found */
2747 text = "No description available";
2749 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2750 ystart += getFontHeight(font_nr) / 2;
2752 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2753 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2754 TRUE, FALSE, FALSE);
2757 void DrawInfoScreen_TitleScreen()
2759 SetGameStatus(GAME_MODE_TITLE);
2764 void HandleInfoScreen_TitleScreen(int button)
2766 HandleTitleScreen(0, 0, 0, 0, button);
2769 void DrawInfoScreen_Elements()
2771 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2773 FadeOut(REDRAW_FIELD);
2778 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2780 FadeIn(REDRAW_FIELD);
2783 void HandleInfoScreen_Elements(int button)
2785 static unsigned int info_delay = 0;
2786 static int num_anims;
2787 static int num_pages;
2789 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2792 if (button == MB_MENU_INITIALIZE)
2794 boolean new_element = TRUE;
2798 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2800 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2802 else if (new_element)
2805 new_element = FALSE;
2809 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2813 if (button == MB_MENU_LEAVE)
2815 PlaySound(SND_MENU_ITEM_SELECTING);
2817 info_mode = INFO_MODE_MAIN;
2822 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2824 if (button != MB_MENU_INITIALIZE)
2826 PlaySound(SND_MENU_ITEM_SELECTING);
2831 if (page >= num_pages)
2833 FadeMenuSoundsAndMusic();
2835 info_mode = INFO_MODE_MAIN;
2842 FadeSetNextScreen();
2844 if (button != MB_MENU_INITIALIZE)
2845 FadeOut(REDRAW_FIELD);
2847 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2849 if (button != MB_MENU_INITIALIZE)
2850 FadeIn(REDRAW_FIELD);
2854 if (DelayReached(&info_delay, GameFrameDelay))
2855 if (page < num_pages)
2856 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2858 PlayMenuSoundIfLoop();
2862 void DrawInfoScreen_Music()
2864 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2866 FadeOut(REDRAW_FIELD);
2873 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2875 FadeIn(REDRAW_FIELD);
2878 void HandleInfoScreen_Music(int button)
2880 static struct MusicFileInfo *list = NULL;
2881 int font_title = MENU_INFO_FONT_TITLE;
2882 int font_head = MENU_INFO_FONT_HEAD;
2883 int font_text = MENU_INFO_FONT_TEXT;
2884 int font_foot = MENU_INFO_FONT_FOOT;
2885 int spacing_title = menu.headline1_spacing_info[info_mode];
2886 int spacing_head = menu.headline2_spacing_info[info_mode];
2887 int ystep_title = getMenuTextStep(spacing_title, font_title);
2888 int ystep_head = getMenuTextStep(spacing_head, font_head);
2889 int ystart = mSY - SY + 100;
2890 int ybottom = mSY - SY + SYSIZE - 20;
2892 if (button == MB_MENU_INITIALIZE)
2894 list = music_file_info;
2898 FadeMenuSoundsAndMusic();
2903 DrawTextSCentered(ystart, font_title,
2904 "No music info for this level set.");
2906 DrawTextSCentered(ybottom, font_foot,
2907 "Press any key or button for info menu");
2913 if (button == MB_MENU_LEAVE)
2915 PlaySound(SND_MENU_ITEM_SELECTING);
2917 FadeMenuSoundsAndMusic();
2919 info_mode = INFO_MODE_MAIN;
2924 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2926 if (button != MB_MENU_INITIALIZE)
2928 PlaySound(SND_MENU_ITEM_SELECTING);
2936 FadeMenuSoundsAndMusic();
2938 info_mode = INFO_MODE_MAIN;
2944 FadeMenuSoundsAndMusic();
2946 if (list != music_file_info)
2947 FadeSetNextScreen();
2949 if (button != MB_MENU_INITIALIZE)
2950 FadeOut(REDRAW_FIELD);
2957 int sound = list->music;
2959 if (sound_info[sound].loop)
2960 PlaySoundLoop(sound);
2964 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
2968 PlayMusic(list->music);
2970 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
2973 ystart += ystep_title;
2975 if (!strEqual(list->title, UNKNOWN_NAME))
2977 if (!strEqual(list->title_header, UNKNOWN_NAME))
2979 DrawTextSCentered(ystart, font_head, list->title_header);
2980 ystart += ystep_head;
2983 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
2984 ystart += ystep_head;
2987 if (!strEqual(list->artist, UNKNOWN_NAME))
2989 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2990 DrawTextSCentered(ystart, font_head, list->artist_header);
2992 DrawTextSCentered(ystart, font_head, "by");
2994 ystart += ystep_head;
2996 DrawTextFCentered(ystart, font_text, "%s", list->artist);
2997 ystart += ystep_head;
3000 if (!strEqual(list->album, UNKNOWN_NAME))
3002 if (!strEqual(list->album_header, UNKNOWN_NAME))
3003 DrawTextSCentered(ystart, font_head, list->album_header);
3005 DrawTextSCentered(ystart, font_head, "from the album");
3007 ystart += ystep_head;
3009 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3010 ystart += ystep_head;
3013 if (!strEqual(list->year, UNKNOWN_NAME))
3015 if (!strEqual(list->year_header, UNKNOWN_NAME))
3016 DrawTextSCentered(ystart, font_head, list->year_header);
3018 DrawTextSCentered(ystart, font_head, "from the year");
3020 ystart += ystep_head;
3022 DrawTextFCentered(ystart, font_text, "%s", list->year);
3023 ystart += ystep_head;
3026 DrawTextSCentered(ybottom, FONT_TEXT_4,
3027 "Press any key or button for next page");
3029 if (button != MB_MENU_INITIALIZE)
3030 FadeIn(REDRAW_FIELD);
3033 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3034 PlaySoundLoop(list->music);
3037 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3039 int font_title = MENU_INFO_FONT_TITLE;
3040 int font_head = MENU_INFO_FONT_HEAD;
3041 int font_text = MENU_INFO_FONT_TEXT;
3042 int font_foot = MENU_INFO_FONT_FOOT;
3043 int spacing_title = menu.headline1_spacing_info[info_mode];
3044 int spacing_head = menu.headline2_spacing_info[info_mode];
3045 int spacing_para = menu.paragraph_spacing_info[info_mode];
3046 int spacing_line = menu.line_spacing_info[info_mode];
3047 int ystep_title = getMenuTextStep(spacing_title, font_title);
3048 int ystep_head = getMenuTextStep(spacing_head, font_head);
3049 int ystep_para = getMenuTextStep(spacing_para, font_text);
3050 int ystep_line = getMenuTextStep(spacing_line, font_text);
3051 int ystart = mSY - SY + 100;
3052 int ybottom = mSY - SY + SYSIZE - 20;
3057 DrawTextSCentered(ystart, font_title, "Credits:");
3058 ystart += ystep_title;
3062 DrawTextSCentered(ystart, font_head,
3063 "Special thanks to");
3064 ystart += ystep_head;
3065 DrawTextSCentered(ystart, font_text,
3067 ystart += ystep_head;
3068 DrawTextSCentered(ystart, font_head,
3070 ystart += ystep_head;
3071 DrawTextSCentered(ystart, font_text,
3072 "\"Boulder Dash\"");
3073 ystart += ystep_head;
3074 DrawTextSCentered(ystart, font_head,
3076 ystart += ystep_head;
3077 DrawTextSCentered(ystart, font_text,
3079 ystart += ystep_head;
3080 DrawTextSCentered(ystart, font_head,
3082 ystart += ystep_head;
3083 DrawTextSCentered(ystart, font_text,
3084 "First Star Software");
3086 else if (screen_nr == 1)
3088 DrawTextSCentered(ystart, font_head,
3089 "Special thanks to");
3090 ystart += ystep_head;
3091 DrawTextSCentered(ystart, font_text,
3092 "Klaus Heinz & Volker Wertich");
3093 ystart += ystep_head;
3094 DrawTextSCentered(ystart, font_head,
3096 ystart += ystep_head;
3097 DrawTextSCentered(ystart, font_text,
3098 "\"Emerald Mine\"");
3099 ystart += ystep_head;
3100 DrawTextSCentered(ystart, font_head,
3102 ystart += ystep_head;
3103 DrawTextSCentered(ystart, font_text,
3105 ystart += ystep_head;
3106 DrawTextSCentered(ystart, font_head,
3108 ystart += ystep_head;
3109 DrawTextSCentered(ystart, font_text,
3112 else if (screen_nr == 2)
3114 DrawTextSCentered(ystart, font_head,
3115 "Special thanks to");
3116 ystart += ystep_head;
3117 DrawTextSCentered(ystart, font_text,
3118 "Michael Stopp & Philip Jespersen");
3119 ystart += ystep_head;
3120 DrawTextSCentered(ystart, font_head,
3122 ystart += ystep_head;
3123 DrawTextSCentered(ystart, font_text,
3125 ystart += ystep_head;
3126 DrawTextSCentered(ystart, font_head,
3128 ystart += ystep_head;
3129 DrawTextSCentered(ystart, font_text,
3131 ystart += ystep_head;
3132 DrawTextSCentered(ystart, font_head,
3134 ystart += ystep_head;
3135 DrawTextSCentered(ystart, font_text,
3136 "Digital Integration");
3138 else if (screen_nr == 3)
3140 DrawTextSCentered(ystart, font_head,
3141 "Special thanks to");
3142 ystart += ystep_head;
3143 DrawTextSCentered(ystart, font_text,
3144 "Hiroyuki Imabayashi");
3145 ystart += ystep_head;
3146 DrawTextSCentered(ystart, font_head,
3148 ystart += ystep_head;
3149 DrawTextSCentered(ystart, font_text,
3151 ystart += ystep_head;
3152 DrawTextSCentered(ystart, font_head,
3154 ystart += ystep_head;
3155 DrawTextSCentered(ystart, font_text,
3157 ystart += ystep_head;
3158 DrawTextSCentered(ystart, font_head,
3160 ystart += ystep_head;
3161 DrawTextSCentered(ystart, font_text,
3164 else if (screen_nr == 4)
3166 DrawTextSCentered(ystart, font_head,
3167 "Special thanks to");
3168 ystart += ystep_head;
3169 DrawTextSCentered(ystart, font_text,
3171 ystart += ystep_head;
3172 DrawTextSCentered(ystart, font_head,
3174 ystart += ystep_head;
3175 DrawTextSCentered(ystart, font_text,
3176 "J\xfcrgen Bonhagen");
3177 ystart += ystep_head;
3178 DrawTextSCentered(ystart, font_head,
3179 "for the continuous creation");
3180 ystart += ystep_line;
3181 DrawTextSCentered(ystart, font_head,
3182 "of outstanding level sets");
3184 else if (screen_nr == 5)
3186 DrawTextSCentered(ystart, font_head,
3188 ystart += ystep_head;
3189 DrawTextSCentered(ystart, font_text,
3191 ystart += ystep_head;
3192 DrawTextSCentered(ystart, font_head,
3193 "for ideas and inspiration by");
3194 ystart += ystep_head;
3195 DrawTextSCentered(ystart, font_text,
3197 ystart += ystep_para;
3199 DrawTextSCentered(ystart, font_head,
3201 ystart += ystep_head;
3202 DrawTextSCentered(ystart, font_text,
3204 ystart += ystep_head;
3205 DrawTextSCentered(ystart, font_head,
3206 "for ideas and inspiration by");
3207 ystart += ystep_head;
3208 DrawTextSCentered(ystart, font_text,
3211 else if (screen_nr == 6)
3213 DrawTextSCentered(ystart, font_head,
3215 ystart += ystep_head;
3216 DrawTextSCentered(ystart, font_text,
3218 ystart += ystep_head;
3219 DrawTextSCentered(ystart, font_head,
3220 "for the code base used for the");
3221 ystart += ystep_line;
3222 DrawTextSCentered(ystart, font_head,
3223 "native Emerald Mine engine");
3225 else if (screen_nr == 7)
3227 DrawTextSCentered(ystart, font_head,
3229 ystart += ystep_head;
3230 DrawTextSCentered(ystart, font_text,
3232 ystart += ystep_head;
3233 DrawTextSCentered(ystart, font_head,
3234 "for the initial DOS port");
3235 ystart += ystep_para;
3237 DrawTextSCentered(ystart, font_head,
3239 ystart += ystep_head;
3240 DrawTextSCentered(ystart, font_text,
3242 ystart += ystep_head;
3243 DrawTextSCentered(ystart, font_head,
3244 "for some additional toons");
3246 else if (screen_nr == 8)
3248 DrawTextSCentered(ystart, font_head,
3249 "And not to forget:");
3250 ystart += ystep_head;
3251 DrawTextSCentered(ystart, font_head,
3253 ystart += ystep_head;
3254 DrawTextSCentered(ystart, font_text,
3255 "All those who contributed");
3256 ystart += ystep_line;
3257 DrawTextSCentered(ystart, font_text,
3258 "levels to this game");
3259 ystart += ystep_line;
3260 DrawTextSCentered(ystart, font_text,
3264 DrawTextSCentered(ybottom, font_foot,
3265 "Press any key or button for next page");
3268 void DrawInfoScreen_Credits()
3270 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3272 FadeMenuSoundsAndMusic();
3274 FadeOut(REDRAW_FIELD);
3276 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3278 FadeIn(REDRAW_FIELD);
3281 void HandleInfoScreen_Credits(int button)
3283 static int screen_nr = 0;
3284 int num_screens = 9;
3286 if (button == MB_MENU_INITIALIZE)
3290 // DrawInfoScreen_CreditsScreen(screen_nr);
3293 if (button == MB_MENU_LEAVE)
3295 PlaySound(SND_MENU_ITEM_SELECTING);
3297 info_mode = INFO_MODE_MAIN;
3302 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3304 if (button != MB_MENU_INITIALIZE)
3306 PlaySound(SND_MENU_ITEM_SELECTING);
3311 if (screen_nr >= num_screens)
3313 FadeMenuSoundsAndMusic();
3315 info_mode = INFO_MODE_MAIN;
3322 FadeSetNextScreen();
3324 if (button != MB_MENU_INITIALIZE)
3325 FadeOut(REDRAW_FIELD);
3327 DrawInfoScreen_CreditsScreen(screen_nr);
3329 if (button != MB_MENU_INITIALIZE)
3330 FadeIn(REDRAW_FIELD);
3334 PlayMenuSoundIfLoop();
3338 void DrawInfoScreen_Program()
3340 int font_title = MENU_INFO_FONT_TITLE;
3341 int font_head = MENU_INFO_FONT_HEAD;
3342 int font_text = MENU_INFO_FONT_TEXT;
3343 int font_foot = MENU_INFO_FONT_FOOT;
3344 int spacing_title = menu.headline1_spacing_info[info_mode];
3345 int spacing_head = menu.headline2_spacing_info[info_mode];
3346 int spacing_para = menu.paragraph_spacing_info[info_mode];
3347 int spacing_line = menu.line_spacing_info[info_mode];
3348 int ystep_title = getMenuTextStep(spacing_title, font_title);
3349 int ystep_head = getMenuTextStep(spacing_head, font_head);
3350 int ystep_para = getMenuTextStep(spacing_para, font_text);
3351 int ystep_line = getMenuTextStep(spacing_line, font_text);
3352 int ystart = mSY - SY + 100;
3353 int ybottom = mSY - SY + SYSIZE - 20;
3355 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3357 FadeOut(REDRAW_FIELD);
3362 DrawTextSCentered(ystart, font_title, "Program Information:");
3363 ystart += ystep_title;
3365 DrawTextSCentered(ystart, font_head,
3366 "This game is Freeware!");
3367 ystart += ystep_head;
3368 DrawTextSCentered(ystart, font_head,
3369 "If you like it, send e-mail to:");
3370 ystart += ystep_head;
3371 DrawTextSCentered(ystart, font_text,
3372 setup.internal.program_email);
3373 ystart += ystep_para;
3375 DrawTextSCentered(ystart, font_head,
3376 "More information and levels:");
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_text,
3379 setup.internal.program_website);
3380 ystart += ystep_para;
3382 DrawTextSCentered(ystart, font_head,
3383 "If you have created new levels,");
3384 ystart += ystep_line;
3385 DrawTextSCentered(ystart, font_head,
3386 "send them to me to include them!");
3387 ystart += ystep_head;
3388 DrawTextSCentered(ystart, font_head,
3391 DrawTextSCentered(ybottom, font_foot,
3392 "Press any key or button for info menu");
3394 FadeIn(REDRAW_FIELD);
3397 void HandleInfoScreen_Program(int button)
3399 if (button == MB_MENU_LEAVE)
3401 PlaySound(SND_MENU_ITEM_SELECTING);
3403 info_mode = INFO_MODE_MAIN;
3408 else if (button == MB_MENU_CHOICE)
3410 PlaySound(SND_MENU_ITEM_SELECTING);
3412 FadeMenuSoundsAndMusic();
3414 info_mode = INFO_MODE_MAIN;
3419 PlayMenuSoundIfLoop();
3423 void DrawInfoScreen_Version()
3425 int font_title = MENU_INFO_FONT_TITLE;
3426 int font_head = MENU_INFO_FONT_HEAD;
3427 int font_text = MENU_INFO_FONT_TEXT;
3428 int font_foot = MENU_INFO_FONT_FOOT;
3429 int spacing_title = menu.headline1_spacing_info[info_mode];
3430 int spacing_head = menu.headline2_spacing_info[info_mode];
3431 int spacing_para = menu.paragraph_spacing_info[info_mode];
3432 int spacing_line = menu.line_spacing_info[info_mode];
3433 int xstep = getFontWidth(font_text);
3434 int ystep_title = getMenuTextStep(spacing_title, font_title);
3435 int ystep_head = getMenuTextStep(spacing_head, font_head);
3436 int ystep_para = getMenuTextStep(spacing_para, font_text);
3437 int ystep_line = getMenuTextStep(spacing_line, font_text);
3438 int ystart = mSY - SY + 100;
3439 int ybottom = mSY - SY + SYSIZE - 20;
3440 int xstart1 = mSX - SX + 2 * xstep;
3441 int xstart2 = mSX - SX + 18 * xstep;
3442 int xstart3 = mSX - SX + 28 * xstep;
3443 SDL_version sdl_version_compiled;
3444 const SDL_version *sdl_version_linked;
3445 int driver_name_len = 10;
3446 #if defined(TARGET_SDL2)
3447 SDL_version sdl_version_linked_ext;
3448 const char *driver_name = NULL;
3450 char driver_name[driver_name_len];
3453 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3455 FadeOut(REDRAW_FIELD);
3460 DrawTextSCentered(ystart, font_title, "Version Information:");
3461 ystart += ystep_title;
3463 DrawTextF(xstart1, ystart, font_head, "Name");
3464 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3465 ystart += ystep_line;
3467 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3469 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3470 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3471 ystart += ystep_line;
3473 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3474 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3475 ystart += ystep_line;
3479 DrawTextF(xstart1, ystart, font_head, "Version");
3480 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3481 ystart += ystep_line;
3484 DrawTextF(xstart1, ystart, font_head, "Platform");
3485 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3486 ystart += ystep_line;
3488 DrawTextF(xstart1, ystart, font_head, "Target");
3489 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3490 ystart += ystep_line;
3492 DrawTextF(xstart1, ystart, font_head, "Source date");
3493 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3494 ystart += ystep_para;
3496 DrawTextF(xstart1, ystart, font_head, "Library");
3497 DrawTextF(xstart2, ystart, font_head, "compiled");
3498 DrawTextF(xstart3, ystart, font_head, "linked");
3499 ystart += ystep_head;
3501 SDL_VERSION(&sdl_version_compiled);
3502 #if defined(TARGET_SDL2)
3503 SDL_GetVersion(&sdl_version_linked_ext);
3504 sdl_version_linked = &sdl_version_linked_ext;
3506 sdl_version_linked = SDL_Linked_Version();
3509 DrawTextF(xstart1, ystart, font_text, "SDL");
3510 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3511 sdl_version_compiled.major,
3512 sdl_version_compiled.minor,
3513 sdl_version_compiled.patch);
3514 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3515 sdl_version_linked->major,
3516 sdl_version_linked->minor,
3517 sdl_version_linked->patch);
3518 ystart += ystep_line;
3520 SDL_IMAGE_VERSION(&sdl_version_compiled);
3521 sdl_version_linked = IMG_Linked_Version();
3523 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3524 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3525 sdl_version_compiled.major,
3526 sdl_version_compiled.minor,
3527 sdl_version_compiled.patch);
3528 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3529 sdl_version_linked->major,
3530 sdl_version_linked->minor,
3531 sdl_version_linked->patch);
3532 ystart += ystep_line;
3534 SDL_MIXER_VERSION(&sdl_version_compiled);
3535 sdl_version_linked = Mix_Linked_Version();
3537 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3538 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3539 sdl_version_compiled.major,
3540 sdl_version_compiled.minor,
3541 sdl_version_compiled.patch);
3542 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3543 sdl_version_linked->major,
3544 sdl_version_linked->minor,
3545 sdl_version_linked->patch);
3546 ystart += ystep_line;
3548 SDL_NET_VERSION(&sdl_version_compiled);
3549 sdl_version_linked = SDLNet_Linked_Version();
3551 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3552 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3553 sdl_version_compiled.major,
3554 sdl_version_compiled.minor,
3555 sdl_version_compiled.patch);
3556 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3557 sdl_version_linked->major,
3558 sdl_version_linked->minor,
3559 sdl_version_linked->patch);
3560 ystart += ystep_para;
3562 DrawTextF(xstart1, ystart, font_head, "Driver");
3563 DrawTextF(xstart2, ystart, font_head, "Requested");
3564 DrawTextF(xstart3, ystart, font_head, "Used");
3565 ystart += ystep_head;
3567 #if defined(TARGET_SDL2)
3568 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3570 SDL_VideoDriverName(driver_name, driver_name_len);
3573 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3574 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3575 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3576 ystart += ystep_line;
3578 #if defined(TARGET_SDL2)
3579 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3581 SDL_AudioDriverName(driver_name, driver_name_len);
3584 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3585 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3586 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3588 DrawTextSCentered(ybottom, font_foot,
3589 "Press any key or button for info menu");
3591 FadeIn(REDRAW_FIELD);
3594 void HandleInfoScreen_Version(int button)
3596 if (button == MB_MENU_LEAVE)
3598 PlaySound(SND_MENU_ITEM_SELECTING);
3600 info_mode = INFO_MODE_MAIN;
3605 else if (button == MB_MENU_CHOICE)
3607 PlaySound(SND_MENU_ITEM_SELECTING);
3609 FadeMenuSoundsAndMusic();
3611 info_mode = INFO_MODE_MAIN;
3616 PlayMenuSoundIfLoop();
3620 void DrawInfoScreen_LevelSet()
3622 struct TitleMessageInfo *tmi = &readme;
3623 char *filename = getLevelSetInfoFilename();
3624 char *title = "Level Set Information:";
3625 int ystart = mSY - SY + 100;
3626 int ybottom = mSY - SY + SYSIZE - 20;
3628 if (filename == NULL)
3630 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3635 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3637 FadeOut(REDRAW_FIELD);
3642 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3644 /* if x position set to "-1", automatically determine by playfield width */
3646 tmi->x = SXSIZE / 2;
3648 /* if y position set to "-1", use static default value */
3652 /* if width set to "-1", automatically determine by playfield width */
3653 if (tmi->width == -1)
3654 tmi->width = SXSIZE - 2 * TILEX;
3656 /* if height set to "-1", automatically determine by playfield height */
3657 if (tmi->height == -1)
3658 tmi->height = SYSIZE - 20 - tmi->y - 10;
3660 /* if chars set to "-1", automatically determine by text and font width */
3661 if (tmi->chars == -1)
3662 tmi->chars = tmi->width / getFontWidth(tmi->font);
3664 tmi->width = tmi->chars * getFontWidth(tmi->font);
3666 /* if lines set to "-1", automatically determine by text and font height */
3667 if (tmi->lines == -1)
3668 tmi->lines = tmi->height / getFontHeight(tmi->font);
3670 tmi->height = tmi->lines * getFontHeight(tmi->font);
3672 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3673 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3674 tmi->autowrap, tmi->centered, tmi->parse_comments);
3676 DrawTextSCentered(ybottom, FONT_TEXT_4,
3677 "Press any key or button for info menu");
3679 FadeIn(REDRAW_FIELD);
3682 void HandleInfoScreen_LevelSet(int button)
3684 if (button == MB_MENU_LEAVE)
3686 PlaySound(SND_MENU_ITEM_SELECTING);
3688 info_mode = INFO_MODE_MAIN;
3693 else if (button == MB_MENU_CHOICE)
3695 PlaySound(SND_MENU_ITEM_SELECTING);
3697 FadeMenuSoundsAndMusic();
3699 info_mode = INFO_MODE_MAIN;
3704 PlayMenuSoundIfLoop();
3708 static void DrawInfoScreen()
3710 if (info_mode == INFO_MODE_TITLE)
3711 DrawInfoScreen_TitleScreen();
3712 else if (info_mode == INFO_MODE_ELEMENTS)
3713 DrawInfoScreen_Elements();
3714 else if (info_mode == INFO_MODE_MUSIC)
3715 DrawInfoScreen_Music();
3716 else if (info_mode == INFO_MODE_CREDITS)
3717 DrawInfoScreen_Credits();
3718 else if (info_mode == INFO_MODE_PROGRAM)
3719 DrawInfoScreen_Program();
3720 else if (info_mode == INFO_MODE_VERSION)
3721 DrawInfoScreen_Version();
3722 else if (info_mode == INFO_MODE_LEVELSET)
3723 DrawInfoScreen_LevelSet();
3725 DrawInfoScreen_Main();
3727 if (info_mode != INFO_MODE_MAIN &&
3728 info_mode != INFO_MODE_TITLE &&
3729 info_mode != INFO_MODE_MUSIC)
3730 PlayMenuSoundsAndMusic();
3733 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3735 if (info_mode == INFO_MODE_TITLE)
3736 HandleInfoScreen_TitleScreen(button);
3737 else if (info_mode == INFO_MODE_ELEMENTS)
3738 HandleInfoScreen_Elements(button);
3739 else if (info_mode == INFO_MODE_MUSIC)
3740 HandleInfoScreen_Music(button);
3741 else if (info_mode == INFO_MODE_CREDITS)
3742 HandleInfoScreen_Credits(button);
3743 else if (info_mode == INFO_MODE_PROGRAM)
3744 HandleInfoScreen_Program(button);
3745 else if (info_mode == INFO_MODE_VERSION)
3746 HandleInfoScreen_Version(button);
3747 else if (info_mode == INFO_MODE_LEVELSET)
3748 HandleInfoScreen_LevelSet(button);
3750 HandleInfoScreen_Main(mx, my, dx, dy, button);
3754 /* ========================================================================= */
3755 /* type name functions */
3756 /* ========================================================================= */
3758 void HandleTypeName(int newxpos, Key key)
3760 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3761 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3762 struct TextPosInfo *pos = mci->pos_input;
3763 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3764 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3765 static int xpos = 0;
3766 int font_nr = pos->font;
3767 int font_active_nr = FONT_ACTIVE(font_nr);
3768 int font_width = getFontWidth(font_active_nr);
3769 char key_char = getValidConfigValueChar(getCharFromKey(key));
3770 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3771 boolean is_active = TRUE;
3773 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3777 strcpy(last_player_name, setup.player_name);
3781 StartTextInput(startx, starty, pos->width, pos->height);
3783 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3785 setup.player_name[xpos] = key_char;
3786 setup.player_name[xpos + 1] = 0;
3790 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3794 setup.player_name[xpos] = 0;
3796 else if (key == KSYM_Return && xpos > 0)
3802 SetGameStatus(GAME_MODE_MAIN);
3804 else if (key == KSYM_Escape)
3806 strcpy(setup.player_name, last_player_name);
3810 SetGameStatus(GAME_MODE_MAIN);
3815 pos->width = (strlen(setup.player_name) + 1) * font_width;
3816 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3818 DrawText(startx, starty, setup.player_name, font_active_nr);
3819 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3823 pos->width = strlen(setup.player_name) * font_width;
3824 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3826 DrawText(startx, starty, setup.player_name, font_nr);
3833 /* ========================================================================= */
3834 /* tree menu functions */
3835 /* ========================================================================= */
3837 static void DrawChooseTree(TreeInfo **ti_ptr)
3839 int fade_mask = REDRAW_FIELD;
3841 if (CheckIfGlobalBorderHasChanged())
3842 fade_mask = REDRAW_ALL;
3844 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3846 SetGameStatus(GAME_MODE_MAIN);
3855 FreeScreenGadgets();
3856 CreateScreenGadgets();
3860 /* needed if different viewport properties defined for choosing level (set) */
3861 ChangeViewportPropertiesIfNeeded();
3863 if (game_status == GAME_MODE_LEVELNR)
3864 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3865 else if (game_status == GAME_MODE_LEVELS)
3866 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3870 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3872 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3873 MapScreenTreeGadgets(*ti_ptr);
3875 DrawMaskedBorder(fade_mask);
3880 static void drawChooseTreeList(int first_entry, int num_page_entries,
3884 char *title_string = NULL;
3885 int yoffset_sets = MENU_TITLE1_YPOS;
3886 int yoffset_setup = 16;
3887 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3888 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3890 title_string = ti->infotext;
3892 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3894 clearMenuListArea();
3896 for (i = 0; i < num_page_entries; i++)
3898 TreeInfo *node, *node_first;
3899 int entry_pos = first_entry + i;
3900 int xpos = MENU_SCREEN_START_XPOS;
3901 int ypos = MENU_SCREEN_START_YPOS + i;
3902 int startx = mSX + xpos * 32;
3903 int starty = mSY + ypos * 32;
3904 int font_nr = FONT_TEXT_1;
3905 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3906 int startx_text = startx + font_xoffset;
3907 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3908 int text_size = startx_scrollbar - startx_text;
3909 int max_buffer_len = text_size / getFontWidth(font_nr);
3910 char buffer[max_buffer_len + 1];
3912 node_first = getTreeInfoFirstGroupEntry(ti);
3913 node = getTreeInfoFromPos(node_first, entry_pos);
3915 strncpy(buffer, node->name, max_buffer_len);
3916 buffer[max_buffer_len] = '\0';
3918 DrawText(startx, starty, buffer, font_nr + node->color);
3920 if (node->parent_link)
3921 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3922 else if (node->level_group)
3923 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3925 initCursor(i, IMG_MENU_BUTTON);
3928 redraw_mask |= REDRAW_FIELD;
3931 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3933 TreeInfo *node, *node_first;
3934 int x, last_redraw_mask = redraw_mask;
3935 int ypos = MENU_TITLE2_YPOS;
3936 int font_nr = FONT_TITLE_2;
3938 if (ti->type == TREE_TYPE_LEVEL_NR)
3939 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3941 if (ti->type != TREE_TYPE_LEVEL_DIR)
3944 node_first = getTreeInfoFirstGroupEntry(ti);
3945 node = getTreeInfoFromPos(node_first, entry_pos);
3947 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3949 if (node->parent_link)
3950 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3951 node->node_parent->name);
3952 else if (node->level_group)
3953 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3955 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3956 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3957 node->levels, (node->levels > 1 ? "levels" : "level"),
3960 /* let BackToFront() redraw only what is needed */
3961 redraw_mask = last_redraw_mask;
3962 for (x = 0; x < SCR_FIELDX; x++)
3963 MarkTileDirty(x, 1);
3966 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3969 TreeInfo *ti = *ti_ptr;
3971 int y = ti->cl_cursor;
3972 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3973 int num_entries = numTreeInfoInGroup(ti);
3974 int num_page_entries;
3975 boolean position_set_by_scrollbar = (dx == 999);
3977 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3978 num_page_entries = num_entries;
3980 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3982 if (button == MB_MENU_INITIALIZE)
3984 int num_entries = numTreeInfoInGroup(ti);
3985 int entry_pos = posTreeInfo(ti);
3987 if (ti->cl_first == -1)
3989 /* only on initialization */
3990 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3991 ti->cl_cursor = entry_pos - ti->cl_first;
3993 else if (ti->cl_cursor >= num_page_entries ||
3994 (num_entries > num_page_entries &&
3995 num_entries - ti->cl_first < num_page_entries))
3997 /* only after change of list size (by custom graphic configuration) */
3998 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3999 ti->cl_cursor = entry_pos - ti->cl_first;
4002 if (position_set_by_scrollbar)
4005 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4008 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4009 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4010 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4014 else if (button == MB_MENU_LEAVE)
4018 PlaySound(SND_MENU_ITEM_SELECTING);
4020 if (ti->node_parent)
4022 *ti_ptr = ti->node_parent;
4023 DrawChooseTree(ti_ptr);
4025 else if (game_status == GAME_MODE_SETUP)
4027 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4028 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4029 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4031 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4032 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4033 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4034 execSetupGraphics();
4035 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4036 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4037 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4039 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4040 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4041 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4048 if (game_status == GAME_MODE_LEVELNR)
4050 int new_level_nr = atoi(level_number_current->identifier);
4052 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4055 SetGameStatus(GAME_MODE_MAIN);
4063 if (mx || my) /* mouse input */
4065 x = (mx - mSX) / 32;
4066 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4068 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4070 /* move cursor instead of scrolling when already at start/end of list */
4071 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4073 else if (dy == +1 * SCROLL_LINE &&
4074 ti->cl_first + num_page_entries == num_entries)
4077 /* handle scrolling screen one line or page */
4078 if (ti->cl_cursor + dy < 0 ||
4079 ti->cl_cursor + dy > num_page_entries - 1)
4081 boolean redraw = FALSE;
4083 if (ABS(dy) == SCROLL_PAGE)
4084 step = num_page_entries - 1;
4086 if (dy < 0 && ti->cl_first > 0)
4088 /* scroll page/line up */
4090 ti->cl_first -= step;
4091 if (ti->cl_first < 0)
4096 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4098 /* scroll page/line down */
4100 ti->cl_first += step;
4101 if (ti->cl_first + num_page_entries > num_entries)
4102 ti->cl_first = MAX(0, num_entries - num_page_entries);
4109 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4110 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4111 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4113 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4120 /* handle moving cursor one line */
4121 y = ti->cl_cursor + dy;
4126 TreeInfo *node_first, *node_cursor;
4127 int entry_pos = ti->cl_first + y;
4129 node_first = getTreeInfoFirstGroupEntry(ti);
4130 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4132 if (node_cursor->node_group)
4136 PlaySound(SND_MENU_ITEM_SELECTING);
4138 node_cursor->cl_first = ti->cl_first;
4139 node_cursor->cl_cursor = ti->cl_cursor;
4140 *ti_ptr = node_cursor->node_group;
4141 DrawChooseTree(ti_ptr);
4146 else if (dx == -1 && ti->node_parent)
4150 PlaySound(SND_MENU_ITEM_SELECTING);
4152 *ti_ptr = ti->node_parent;
4153 DrawChooseTree(ti_ptr);
4158 if (!anyScrollbarGadgetActive() &&
4159 IN_VIS_MENU(x, y) &&
4160 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4161 y >= 0 && y < num_page_entries)
4165 if (y != ti->cl_cursor)
4167 PlaySound(SND_MENU_ITEM_ACTIVATING);
4169 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4170 drawChooseTreeCursor(y, TRUE);
4171 drawChooseTreeInfo(ti->cl_first + y, ti);
4177 if (game_status == GAME_MODE_SETUP)
4179 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4180 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4181 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4183 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4184 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4185 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4186 execSetupGraphics();
4187 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4188 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4189 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4191 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4192 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4193 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4202 TreeInfo *node_first, *node_cursor;
4203 int entry_pos = ti->cl_first + y;
4205 PlaySound(SND_MENU_ITEM_SELECTING);
4207 node_first = getTreeInfoFirstGroupEntry(ti);
4208 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4210 if (node_cursor->node_group)
4214 node_cursor->cl_first = ti->cl_first;
4215 node_cursor->cl_cursor = ti->cl_cursor;
4216 *ti_ptr = node_cursor->node_group;
4217 DrawChooseTree(ti_ptr);
4219 else if (node_cursor->parent_link)
4223 *ti_ptr = node_cursor->node_parent;
4224 DrawChooseTree(ti_ptr);
4230 node_cursor->cl_first = ti->cl_first;
4231 node_cursor->cl_cursor = ti->cl_cursor;
4232 *ti_ptr = node_cursor;
4234 if (ti->type == TREE_TYPE_LEVEL_DIR)
4236 LoadLevelSetup_SeriesInfo();
4238 SaveLevelSetup_LastSeries();
4239 SaveLevelSetup_SeriesInfo();
4243 if (game_status == GAME_MODE_SETUP)
4245 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4246 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4247 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4249 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4250 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4251 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4252 execSetupGraphics();
4253 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4254 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4255 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4257 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4258 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4259 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4266 if (game_status == GAME_MODE_LEVELNR)
4268 int new_level_nr = atoi(level_number_current->identifier);
4270 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4273 SetGameStatus(GAME_MODE_MAIN);
4282 void DrawChooseLevelSet()
4284 FadeMenuSoundsAndMusic();
4286 DrawChooseTree(&leveldir_current);
4288 PlayMenuSoundsAndMusic();
4291 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4293 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4296 void DrawChooseLevelNr()
4300 FadeMenuSoundsAndMusic();
4302 if (level_number != NULL)
4304 freeTreeInfo(level_number);
4306 level_number = NULL;
4309 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4311 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4312 char identifier[32], name[32];
4315 /* temporarily load level info to get level name */
4316 LoadLevelInfoOnly(i);
4318 ti->node_top = &level_number;
4319 ti->sort_priority = 10000 + value;
4320 ti->color = (level.no_level_file ? FC_BLUE :
4321 LevelStats_getSolved(i) ? FC_GREEN :
4322 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4324 snprintf(identifier, sizeof(identifier), "%d", value);
4325 snprintf(name, sizeof(name), "%03d: %s", value,
4326 (level.no_level_file ? "(no file)" : level.name));
4328 setString(&ti->identifier, identifier);
4329 setString(&ti->name, name);
4330 setString(&ti->name_sorting, name);
4332 pushTreeInfo(&level_number, ti);
4335 /* sort level number values to start with lowest level number */
4336 sortTreeInfo(&level_number);
4338 /* set current level number to current level number */
4339 level_number_current =
4340 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4342 /* if that also fails, set current level number to first available level */
4343 if (level_number_current == NULL)
4344 level_number_current = level_number;
4346 DrawChooseTree(&level_number_current);
4348 PlayMenuSoundsAndMusic();
4351 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4353 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4356 void DrawHallOfFame(int highlight_position)
4358 int fade_mask = REDRAW_FIELD;
4360 if (CheckIfGlobalBorderHasChanged())
4361 fade_mask = REDRAW_ALL;
4364 FadeMenuSoundsAndMusic();
4366 /* (this is needed when called from GameEnd() after winning a game) */
4367 KeyboardAutoRepeatOn();
4369 /* (this is needed when called from GameEnd() after winning a game) */
4370 SetDrawDeactivationMask(REDRAW_NONE);
4371 SetDrawBackgroundMask(REDRAW_FIELD);
4373 if (highlight_position < 0)
4374 LoadScore(level_nr);
4376 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4378 FadeSetEnterScreen();
4382 /* needed if different viewport properties defined for scores */
4383 ChangeViewportPropertiesIfNeeded();
4385 PlayMenuSoundsAndMusic();
4387 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4389 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4391 DrawMaskedBorder(fade_mask);
4396 static void drawHallOfFameList(int first_entry, int highlight_position)
4400 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4403 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4404 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4405 "HighScores of Level %d", level_nr);
4407 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4409 int entry = first_entry + i;
4410 boolean active = (entry == highlight_position);
4411 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4412 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4413 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4414 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4415 int dxoff = getFontDrawOffsetX(font_nr1);
4416 int dx1 = 3 * getFontWidth(font_nr1);
4417 int dx2 = dx1 + getFontWidth(font_nr1);
4418 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4419 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4420 int sy = mSY + 64 + i * 32;
4422 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4423 DrawText(mSX + dx1, sy, ".", font_nr1);
4425 for (j = 0; j < num_dots; j++)
4426 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4428 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4429 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4431 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4434 redraw_mask |= REDRAW_FIELD;
4437 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4439 static int first_entry = 0;
4440 static int highlight_position = 0;
4441 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4443 if (button == MB_MENU_INITIALIZE)
4446 highlight_position = mx;
4447 drawHallOfFameList(first_entry, highlight_position);
4452 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4453 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4457 if (first_entry > 0)
4459 first_entry -= step;
4460 if (first_entry < 0)
4463 drawHallOfFameList(first_entry, highlight_position);
4468 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4470 first_entry += step;
4471 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4472 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4474 drawHallOfFameList(first_entry, highlight_position);
4477 else if (button == MB_MENU_LEAVE)
4479 PlaySound(SND_MENU_ITEM_SELECTING);
4481 FadeSound(SND_BACKGROUND_SCORES);
4483 SetGameStatus(GAME_MODE_MAIN);
4487 else if (button == MB_MENU_CHOICE)
4489 PlaySound(SND_MENU_ITEM_SELECTING);
4491 FadeSound(SND_BACKGROUND_SCORES);
4493 SetGameStatus(GAME_MODE_MAIN);
4498 if (game_status == GAME_MODE_SCORES)
4499 PlayMenuSoundIfLoop();
4503 /* ========================================================================= */
4504 /* setup screen functions */
4505 /* ========================================================================= */
4507 static struct TokenInfo *setup_info;
4508 static int num_setup_info; /* number of setup entries shown on screen */
4509 static int max_setup_info; /* total number of setup entries in list */
4511 static char *window_size_text;
4512 static char *scaling_type_text;
4513 static char *rendering_mode_text;
4514 static char *scroll_delay_text;
4515 static char *snapshot_mode_text;
4516 static char *game_speed_text;
4517 static char *graphics_set_name;
4518 static char *sounds_set_name;
4519 static char *music_set_name;
4520 static char *volume_simple_text;
4521 static char *volume_loops_text;
4522 static char *volume_music_text;
4523 static char *touch_controls_text;
4524 static char *move_distance_text;
4525 static char *drop_distance_text;
4527 static void execSetupMain()
4529 setup_mode = SETUP_MODE_MAIN;
4534 static void execSetupGame_setGameSpeeds()
4536 if (game_speeds == NULL)
4540 for (i = 0; game_speeds_list[i].value != -1; i++)
4542 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4543 char identifier[32], name[32];
4544 int value = game_speeds_list[i].value;
4545 char *text = game_speeds_list[i].text;
4547 ti->node_top = &game_speeds;
4548 ti->sort_priority = 10000 - value;
4550 sprintf(identifier, "%d", value);
4551 sprintf(name, "%s", text);
4553 setString(&ti->identifier, identifier);
4554 setString(&ti->name, name);
4555 setString(&ti->name_sorting, name);
4556 setString(&ti->infotext, "Game Speed");
4558 pushTreeInfo(&game_speeds, ti);
4561 /* sort game speed values to start with slowest game speed */
4562 sortTreeInfo(&game_speeds);
4564 /* set current game speed to configured game speed value */
4565 game_speed_current =