1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
28 /* screens in the setup menu */
29 #define SETUP_MODE_MAIN 0
30 #define SETUP_MODE_GAME 1
31 #define SETUP_MODE_CHOOSE_GAME_SPEED 2
32 #define SETUP_MODE_EDITOR 3
33 #define SETUP_MODE_INPUT 4
34 #define SETUP_MODE_SHORTCUT_1 5
35 #define SETUP_MODE_SHORTCUT_2 6
36 #define SETUP_MODE_GRAPHICS 7
37 #define SETUP_MODE_CHOOSE_SCREEN_MODE 8
38 #define SETUP_MODE_SOUND 9
39 #define SETUP_MODE_ARTWORK 10
40 #define SETUP_MODE_CHOOSE_GRAPHICS 11
41 #define SETUP_MODE_CHOOSE_SOUNDS 12
42 #define SETUP_MODE_CHOOSE_MUSIC 13
44 #define MAX_SETUP_MODES 14
46 /* for input setup functions */
47 #define SETUPINPUT_SCREEN_POS_START 0
48 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
49 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
50 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
52 /* screens on the info screen */
53 #define INFO_MODE_MAIN 0
54 #define INFO_MODE_TITLE 1
55 #define INFO_MODE_ELEMENTS 2
56 #define INFO_MODE_MUSIC 3
57 #define INFO_MODE_CREDITS 4
58 #define INFO_MODE_PROGRAM 5
59 #define INFO_MODE_VERSION 6
60 #define INFO_MODE_LEVELSET 7
62 #define MAX_INFO_MODES 8
64 /* for various menu stuff */
65 #define MENU_SCREEN_START_XPOS 1
66 #define MENU_SCREEN_START_YPOS 2
67 #define MENU_SCREEN_VALUE_XPOS 14
68 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
69 #define MENU_TITLE1_YPOS 8
70 #define MENU_TITLE2_YPOS 46
71 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
72 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
73 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
74 MENU_SCREEN_START_XPOS)
75 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
77 /* buttons and scrollbars identifiers */
78 #define SCREEN_CTRL_ID_PREV_LEVEL 0
79 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
80 #define SCREEN_CTRL_ID_PREV_PLAYER 2
81 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
82 #define SCREEN_CTRL_ID_SCROLL_UP 4
83 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
84 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
86 #define NUM_SCREEN_GADGETS 7
88 #define NUM_SCREEN_MENUBUTTONS 4
89 #define NUM_SCREEN_SCROLLBUTTONS 2
90 #define NUM_SCREEN_SCROLLBARS 1
92 #define SCREEN_MASK_MAIN (1 << 0)
93 #define SCREEN_MASK_INPUT (1 << 1)
95 /* graphic position and size values for buttons and scrollbars */
96 #define SC_MENUBUTTON_XSIZE TILEX
97 #define SC_MENUBUTTON_YSIZE TILEY
99 #define SC_SCROLLBUTTON_XSIZE TILEX
100 #define SC_SCROLLBUTTON_YSIZE TILEY
102 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
104 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
105 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
106 SC_SCROLLBUTTON_YSIZE)
108 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
109 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
111 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
112 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
113 SC_SCROLLBUTTON_YSIZE)
115 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
116 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
117 SC_SCROLL_VERTICAL_YSIZE)
119 #define SC_BORDER_SIZE 14
121 /* other useful macro definitions */
122 #define BUTTON_GRAPHIC_ACTIVE(g) \
123 (g == IMG_MENU_BUTTON_LEFT ? IMG_MENU_BUTTON_LEFT_ACTIVE : \
124 g == IMG_MENU_BUTTON_RIGHT ? IMG_MENU_BUTTON_RIGHT_ACTIVE : \
125 g == IMG_MENU_BUTTON_UP ? IMG_MENU_BUTTON_UP_ACTIVE : \
126 g == IMG_MENU_BUTTON_DOWN ? IMG_MENU_BUTTON_DOWN_ACTIVE : \
127 g == IMG_MENU_BUTTON_LEAVE_MENU ? IMG_MENU_BUTTON_LEAVE_MENU_ACTIVE : \
128 g == IMG_MENU_BUTTON_ENTER_MENU ? IMG_MENU_BUTTON_ENTER_MENU_ACTIVE : \
129 g == IMG_MENU_BUTTON_PREV_LEVEL ? IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE : \
130 g == IMG_MENU_BUTTON_NEXT_LEVEL ? IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE : \
131 IMG_MENU_BUTTON_ACTIVE)
134 /* forward declarations of internal functions */
135 static void HandleScreenGadgets(struct GadgetInfo *);
136 static void HandleSetupScreen_Generic(int, int, int, int, int);
137 static void HandleSetupScreen_Input(int, int, int, int, int);
138 static void CustomizeKeyboard(int);
139 static void CalibrateJoystick(int);
140 static void execSetupGame(void);
141 static void execSetupGraphics(void);
142 static void execSetupArtwork(void);
143 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
145 static void DrawChooseLevel(void);
146 static void DrawInfoScreen(void);
147 static void DrawAndFadeInInfoScreen(int);
148 static void DrawSetupScreen(void);
150 static void DrawInfoScreenExt(int, int);
151 static void DrawInfoScreen_NotAvailable(char *, char *);
152 static void DrawInfoScreen_HelpAnim(int, int, boolean);
153 static void DrawInfoScreen_HelpText(int, int, int, int);
154 static void HandleInfoScreen_Main(int, int, int, int, int);
155 static void HandleInfoScreen_TitleScreen(int);
156 static void HandleInfoScreen_Elements(int);
157 static void HandleInfoScreen_Music(int);
158 static void HandleInfoScreen_Credits(int);
159 static void HandleInfoScreen_Program(int);
160 static void HandleInfoScreen_Version(int);
162 static void MapScreenMenuGadgets(int);
163 static void MapScreenTreeGadgets(TreeInfo *);
165 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
167 static int setup_mode = SETUP_MODE_MAIN;
168 static int info_mode = INFO_MODE_MAIN;
170 static TreeInfo *screen_modes = NULL;
171 static TreeInfo *screen_mode_current = NULL;
173 static TreeInfo *game_speeds = NULL;
174 static TreeInfo *game_speed_current = NULL;
180 } game_speeds_list[] =
189 { 1000, "1/1s (Extremely Slow)" },
194 { 29, "1/35s (Original Supaplex)" },
196 { 20, "1/50s (Normal Speed)" },
197 { 14, "1/70s (Maximum Supaplex)" },
201 { 1, "1/1000s (Extremely Fast)" },
207 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
208 (s) <= GAME_MODE_SETUP ? (s) : \
209 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
210 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
212 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
213 (i) <= INFO_MODE_LEVELSET ? (i) : \
216 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
217 menu.draw_xoffset[GAME_MODE_INFO] : \
218 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
219 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
220 menu.draw_yoffset[GAME_MODE_INFO] : \
221 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
223 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
224 DRAW_XOFFSET_INFO(info_mode) : \
225 menu.draw_xoffset[DRAW_MODE(s)])
226 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
227 DRAW_YOFFSET_INFO(info_mode) : \
228 menu.draw_yoffset[DRAW_MODE(s)])
230 #define mSX (SX + DRAW_XOFFSET(game_status))
231 #define mSY (SY + DRAW_YOFFSET(game_status))
233 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
234 menu.list_size[game_status] : \
235 MAX_MENU_ENTRIES_ON_SCREEN)
237 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
238 #define NUM_SCROLLBAR_BITMAPS 2
239 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
243 /* title display and control definitions */
245 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
246 2 * MAX_NUM_TITLE_MESSAGES)
248 static int num_title_screens = 0;
250 struct TitleControlInfo
258 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
261 /* main menu display and control definitions */
263 #define MAIN_CONTROL_NAME 0
264 #define MAIN_CONTROL_LEVELS 1
265 #define MAIN_CONTROL_SCORES 2
266 #define MAIN_CONTROL_EDITOR 3
267 #define MAIN_CONTROL_INFO 4
268 #define MAIN_CONTROL_GAME 5
269 #define MAIN_CONTROL_SETUP 6
270 #define MAIN_CONTROL_QUIT 7
271 #define MAIN_CONTROL_PREV_LEVEL 8
272 #define MAIN_CONTROL_NEXT_LEVEL 9
273 #define MAIN_CONTROL_FIRST_LEVEL 10
274 #define MAIN_CONTROL_LAST_LEVEL 11
275 #define MAIN_CONTROL_LEVEL_NUMBER 12
276 #define MAIN_CONTROL_LEVEL_INFO_1 13
277 #define MAIN_CONTROL_LEVEL_INFO_2 14
278 #define MAIN_CONTROL_LEVEL_NAME 15
279 #define MAIN_CONTROL_LEVEL_AUTHOR 16
280 #define MAIN_CONTROL_LEVEL_YEAR 17
281 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
282 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
283 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
284 #define MAIN_CONTROL_TITLE_1 21
285 #define MAIN_CONTROL_TITLE_2 22
286 #define MAIN_CONTROL_TITLE_3 23
288 static char str_main_text_name[10];
289 static char str_main_text_first_level[10];
290 static char str_main_text_last_level[10];
291 static char str_main_text_level_number[10];
293 static char *main_text_name = str_main_text_name;
294 static char *main_text_first_level = str_main_text_first_level;
295 static char *main_text_last_level = str_main_text_last_level;
296 static char *main_text_level_number = str_main_text_level_number;
297 static char *main_text_levels = "Levelset";
298 static char *main_text_scores = "Hall Of Fame";
299 static char *main_text_editor = "Level Creator";
300 static char *main_text_info = "Info Screen";
301 static char *main_text_game = "Start Game";
302 static char *main_text_setup = "Setup";
303 static char *main_text_quit = "Quit";
304 static char *main_text_level_name = level.name;
305 static char *main_text_level_author = level.author;
306 static char *main_text_level_year = NULL;
307 static char *main_text_level_imported_from = NULL;
308 static char *main_text_level_imported_by = NULL;
309 static char *main_text_level_tested_by = NULL;
310 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
311 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
312 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
314 struct MainControlInfo
318 struct MenuPosInfo *pos_button;
321 struct TextPosInfo *pos_text;
324 struct TextPosInfo *pos_input;
328 static struct MainControlInfo main_controls[] =
332 &menu.main.button.name, IMG_MENU_BUTTON,
333 &menu.main.text.name, &main_text_name,
334 &menu.main.input.name, &setup.player_name,
338 &menu.main.button.levels, IMG_MENU_BUTTON_ENTER_MENU,
339 &menu.main.text.levels, &main_text_levels,
344 &menu.main.button.scores, IMG_MENU_BUTTON,
345 &menu.main.text.scores, &main_text_scores,
350 &menu.main.button.editor, IMG_MENU_BUTTON,
351 &menu.main.text.editor, &main_text_editor,
356 &menu.main.button.info, IMG_MENU_BUTTON_ENTER_MENU,
357 &menu.main.text.info, &main_text_info,
362 &menu.main.button.game, IMG_MENU_BUTTON,
363 &menu.main.text.game, &main_text_game,
368 &menu.main.button.setup, IMG_MENU_BUTTON_ENTER_MENU,
369 &menu.main.text.setup, &main_text_setup,
374 &menu.main.button.quit, IMG_MENU_BUTTON,
375 &menu.main.text.quit, &main_text_quit,
379 /* (these two buttons are real gadgets) */
381 MAIN_CONTROL_PREV_LEVEL,
382 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
387 MAIN_CONTROL_NEXT_LEVEL,
388 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
394 MAIN_CONTROL_FIRST_LEVEL,
396 &menu.main.text.first_level, &main_text_first_level,
400 MAIN_CONTROL_LAST_LEVEL,
402 &menu.main.text.last_level, &main_text_last_level,
406 MAIN_CONTROL_LEVEL_NUMBER,
408 &menu.main.text.level_number, &main_text_level_number,
412 MAIN_CONTROL_LEVEL_INFO_1,
414 &menu.main.text.level_info_1, NULL,
418 MAIN_CONTROL_LEVEL_INFO_2,
420 &menu.main.text.level_info_2, NULL,
424 MAIN_CONTROL_LEVEL_NAME,
426 &menu.main.text.level_name, &main_text_level_name,
430 MAIN_CONTROL_LEVEL_AUTHOR,
432 &menu.main.text.level_author, &main_text_level_author,
436 MAIN_CONTROL_LEVEL_YEAR,
438 &menu.main.text.level_year, &main_text_level_year,
442 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
444 &menu.main.text.level_imported_from, &main_text_level_imported_from,
448 MAIN_CONTROL_LEVEL_IMPORTED_BY,
450 &menu.main.text.level_imported_by, &main_text_level_imported_by,
454 MAIN_CONTROL_LEVEL_TESTED_BY,
456 &menu.main.text.level_tested_by, &main_text_level_tested_by,
460 MAIN_CONTROL_TITLE_1,
462 &menu.main.text.title_1, &main_text_title_1,
466 MAIN_CONTROL_TITLE_2,
468 &menu.main.text.title_2, &main_text_title_2,
472 MAIN_CONTROL_TITLE_3,
474 &menu.main.text.title_3, &main_text_title_3,
487 static int getTitleScreenGraphic(int nr, boolean initial)
489 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
492 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
494 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
498 static int getTitleScreenGameMode(boolean initial)
500 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
504 static int getTitleMessageGameMode(boolean initial)
506 return (initial ? GAME_MODE_MESSAGE_INITIAL : GAME_MODE_MESSAGE);
509 static int getTitleScreenBackground(boolean initial)
511 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
514 static int getTitleMessageBackground(boolean initial)
516 return (initial ? IMG_BACKGROUND_MESSAGE_INITIAL : IMG_BACKGROUND_MESSAGE);
519 static int getTitleSound(int nr, boolean initial, boolean is_image)
521 int mode = (is_image ?
522 (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE) :
523 (initial ? GAME_MODE_MESSAGE_INITIAL : GAME_MODE_MESSAGE));
524 int base = (is_image ?
525 (initial ? SND_TITLESCREEN_INITIAL_1 : SND_TITLESCREEN_1) :
526 (initial ? SND_TITLEMESSAGE_INITIAL_1 : SND_TITLEMESSAGE_1));
528 int sound_global = menu.sound[mode];
529 int sound_local = base + nr;
532 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
533 nr, initial, is_image,
534 sound_global, getSoundListEntry(sound_global)->filename,
535 sound_local, getSoundListEntry(sound_local)->filename);
538 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
541 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
544 return SND_UNDEFINED;
547 static int getTitleMusic(int nr, boolean initial, boolean is_image)
549 int mode = (is_image ?
550 (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE) :
551 (initial ? GAME_MODE_MESSAGE_INITIAL : GAME_MODE_MESSAGE));
552 int base = (is_image ?
553 (initial ? MUS_TITLESCREEN_INITIAL_1 : MUS_TITLESCREEN_1) :
554 (initial ? MUS_TITLEMESSAGE_INITIAL_1 : MUS_TITLEMESSAGE_1));
556 int music_global = menu.music[mode];
557 int music_local = base + nr;
560 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
561 nr, initial, is_image,
562 music_global, getMusicListEntry(music_global)->filename,
563 music_local, getMusicListEntry(music_local)->filename);
566 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
569 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
572 return MUS_UNDEFINED;
575 static int compareTitleControlInfo(const void *object1, const void *object2)
577 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
578 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
581 if (tci1->initial != tci2->initial)
582 compare_result = (tci1->initial ? -1 : +1);
583 else if (tci1->sort_priority != tci2->sort_priority)
584 compare_result = tci1->sort_priority - tci2->sort_priority;
585 else if (tci1->is_image != tci2->is_image)
586 compare_result = (tci1->is_image ? -1 : +1);
588 compare_result = tci1->local_nr - tci2->local_nr;
590 return compare_result;
593 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
595 int nr, int sort_priority)
597 title_controls[num_title_screens].is_image = is_image;
598 title_controls[num_title_screens].initial = initial;
599 title_controls[num_title_screens].local_nr = nr;
600 title_controls[num_title_screens].sort_priority = sort_priority;
605 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
609 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
611 int graphic = getTitleScreenGraphic(i, initial);
612 Bitmap *bitmap = graphic_info[graphic].bitmap;
613 int sort_priority = graphic_info[graphic].sort_priority;
616 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
619 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
621 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
622 char *filename = getLevelSetTitleMessageFilename(i, initial);
623 int sort_priority = tmi->sort_priority;
625 if (filename != NULL)
626 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
630 static void InitializeTitleControls(boolean show_title_initial)
632 num_title_screens = 0;
634 if (show_title_initial)
635 InitializeTitleControls_CheckTitleInfo(TRUE);
637 InitializeTitleControls_CheckTitleInfo(FALSE);
639 /* sort title screens according to sort_priority and title number */
640 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
641 compareTitleControlInfo);
644 static boolean visibleMenuPos(struct MenuPosInfo *pos)
646 return (pos != NULL && pos->x != -1 && pos->y != -1);
649 static boolean visibleTextPos(struct TextPosInfo *pos)
651 return (pos != NULL && pos->x != -1 && pos->y != -1);
654 static void InitializeMainControls()
656 boolean local_team_mode = (!options.network && setup.team_mode);
659 /* set main control text values to dynamically determined values */
660 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
661 sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
662 sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
663 sprintf(main_text_level_number, "%s", int2str(level_nr, 3));
665 main_text_level_year = leveldir_current->year;
666 main_text_level_imported_from = leveldir_current->imported_from;
667 main_text_level_imported_by = leveldir_current->imported_by;
668 main_text_level_tested_by = leveldir_current->tested_by;
670 /* set main control screen positions to dynamically determined values */
671 for (i = 0; main_controls[i].nr != -1; i++)
673 struct MainControlInfo *mci = &main_controls[i];
675 struct MenuPosInfo *pos_button = mci->pos_button;
676 struct TextPosInfo *pos_text = mci->pos_text;
677 struct TextPosInfo *pos_input = mci->pos_input;
678 char *text = (mci->text ? *mci->text : NULL);
679 char *input = (mci->input ? *mci->input : NULL);
680 int button_graphic = mci->button_graphic;
682 int font_text = (pos_text ? pos_text->font : -1);
683 int font_input = (pos_input ? pos_input->font : -1);
685 int font_text = mci->font_text;
686 int font_input = mci->font_input;
689 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
690 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
691 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
692 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
693 int text_chars = (text != NULL ? strlen(text) : 0);
694 int input_chars = (input != NULL ? strlen(input) : 0);
697 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
699 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
700 int text_width = font_text_width * text_chars;
701 int text_height = font_text_height;
702 int input_width = font_input_width * input_chars;
703 int input_height = font_input_height;
705 if (nr == MAIN_CONTROL_NAME)
708 if (menu.main.input.name.x == -1)
709 menu.main.input.name.x = menu.main.text.name.x + text_width;
710 if (menu.main.input.name.y == -1)
711 menu.main.input.name.y = menu.main.text.name.y;
715 menu.main.input.name.width = input_width;
716 menu.main.input.name.height = input_height;
718 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
719 menu.main.input.name.height = font_input_height;
723 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
725 if (pos_button->width == 0)
726 pos_button->width = button_width;
727 if (pos_button->height == 0)
728 pos_button->height = button_height;
731 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
733 /* calculate width for non-clickable text -- needed for text alignment */
734 boolean calculate_text_width = (pos_button == NULL && text != NULL);
736 if (visibleMenuPos(pos_button))
738 if (pos_text->x == -1)
739 pos_text->x = pos_button->x + pos_button->width;
740 if (pos_text->y == -1)
741 pos_text->y = pos_button->y;
744 if (pos_text->width == -1 || calculate_text_width)
745 pos_text->width = text_width;
746 if (pos_text->height == -1)
747 pos_text->height = text_height;
750 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
752 if (visibleTextPos(pos_text))
754 if (pos_input->x == -1)
755 pos_input->x = pos_text->x + pos_text->width;
756 if (pos_input->y == -1)
757 pos_input->y = pos_text->y;
760 if (pos_input->width == -1)
761 pos_input->width = input_width;
762 if (pos_input->height == -1)
763 pos_input->height = input_height;
768 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
769 boolean active_input)
773 for (i = 0; main_controls[i].nr != -1; i++)
775 struct MainControlInfo *mci = &main_controls[i];
777 if (mci->nr == nr || nr == -1)
779 struct MenuPosInfo *pos_button = mci->pos_button;
780 struct TextPosInfo *pos_text = mci->pos_text;
781 struct TextPosInfo *pos_input = mci->pos_input;
782 char *text = (mci->text ? *mci->text : NULL);
783 char *input = (mci->input ? *mci->input : NULL);
784 int button_graphic = mci->button_graphic;
786 int font_text = (pos_text ? pos_text->font : -1);
787 int font_input = (pos_input ? pos_input->font : -1);
789 int font_text = mci->font_text;
790 int font_input = mci->font_input;
795 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
796 font_text = FONT_ACTIVE(font_text);
801 font_input = FONT_ACTIVE(font_input);
804 if (visibleMenuPos(pos_button))
806 struct MenuPosInfo *pos = pos_button;
807 int x = mSX + pos->x;
808 int y = mSY + pos->y;
810 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
811 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
814 if (visibleTextPos(pos_text) && text != NULL)
816 struct TextPosInfo *pos = pos_text;
817 int x = mSX + ALIGNED_TEXT_XPOS(pos);
818 int y = mSY + ALIGNED_TEXT_YPOS(pos);
821 /* (check why/if this is needed) */
822 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
824 DrawText(x, y, text, font_text);
827 if (visibleTextPos(pos_input) && input != NULL)
829 struct TextPosInfo *pos = pos_input;
830 int x = mSX + ALIGNED_TEXT_XPOS(pos);
831 int y = mSY + ALIGNED_TEXT_YPOS(pos);
834 /* (check why/if this is needed) */
835 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
837 DrawText(x, y, input, font_input);
843 static void DrawCursorAndText_Main(int nr, boolean active_text)
845 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
849 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
851 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
855 static struct MainControlInfo *getMainControlInfo(int nr)
859 for (i = 0; main_controls[i].nr != -1; i++)
860 if (main_controls[i].nr == nr)
861 return &main_controls[i];
866 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
871 int rect_x = ALIGNED_TEXT_XPOS(rect);
872 int rect_y = ALIGNED_TEXT_YPOS(rect);
874 return (x >= rect_x && x < rect_x + rect->width &&
875 y >= rect_y && y < rect_y + rect->height);
878 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
883 int rect_x = ALIGNED_TEXT_XPOS(rect);
884 int rect_y = ALIGNED_TEXT_YPOS(rect);
886 return (x >= rect_x && x < rect_x + rect->width &&
887 y >= rect_y && y < rect_y + rect->height);
890 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
892 static int cursor_array[SCR_FIELDY];
893 int x = mSX + TILEX * xpos;
894 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
899 cursor_array[ypos] = graphic;
901 graphic = cursor_array[ypos];
905 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
907 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
908 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
911 static void initCursor(int ypos, int graphic)
913 drawCursorExt(0, ypos, FALSE, graphic);
916 static void drawCursor(int ypos, boolean active)
918 drawCursorExt(0, ypos, active, -1);
921 static void drawCursorXY(int xpos, int ypos, int graphic)
923 drawCursorExt(xpos, ypos, FALSE, graphic);
926 static void drawChooseTreeCursor(int ypos, boolean active)
928 int last_game_status = game_status; /* save current game status */
930 /* force LEVELS draw offset on artwork setup screen */
931 game_status = GAME_MODE_LEVELS;
933 drawCursorExt(0, ypos, active, -1);
935 game_status = last_game_status; /* restore current game status */
940 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
941 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
945 static int getPrevlevelButtonPos()
950 static int getCurrentLevelTextPos()
952 return (getPrevlevelButtonPos() + 1);
955 static int getNextLevelButtonPos()
957 return getPrevlevelButtonPos() + 3 + 1;
960 static int getLevelRangeTextPos()
962 return getNextLevelButtonPos() + 1;
966 int effectiveGameStatus()
968 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
969 return GAME_MODE_TITLE;
974 void DrawTitleScreenImage(int nr, boolean initial)
976 int graphic = getTitleScreenGraphic(nr, initial);
977 Bitmap *bitmap = graphic_info[graphic].bitmap;
979 int width = graphic_info[graphic].width;
980 int height = graphic_info[graphic].height;
981 int src_x = graphic_info[graphic].src_x;
982 int src_y = graphic_info[graphic].src_y;
984 int width = graphic_info[graphic].src_image_width;
985 int height = graphic_info[graphic].src_image_height;
986 int src_x = 0, src_y = 0;
993 if (width > WIN_XSIZE)
995 /* image width too large for window => center image horizontally */
996 src_x = (width - WIN_XSIZE) / 2;
1000 if (height > WIN_YSIZE)
1002 /* image height too large for window => center image vertically */
1003 src_y = (height - WIN_YSIZE) / 2;
1007 /* always display title screens centered */
1008 dst_x = (WIN_XSIZE - width) / 2;
1009 dst_y = (WIN_YSIZE - height) / 2;
1011 SetDrawBackgroundMask(REDRAW_ALL);
1012 SetWindowBackgroundImage(getTitleScreenBackground(initial));
1014 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1016 if (DrawingOnBackground(dst_x, dst_y))
1017 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1019 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1021 redraw_mask = REDRAW_ALL;
1023 /* reset fading control values to default config settings */
1024 title.fade_delay_final = title.fade_delay;
1025 title.post_delay_final = title.post_delay;
1026 title.auto_delay_final = title.auto_delay;
1028 /* override default settings with image config settings, if defined */
1029 if (graphic_info[graphic].fade_delay > -1)
1030 title.fade_delay_final = graphic_info[graphic].fade_delay;
1031 if (graphic_info[graphic].post_delay > -1)
1032 title.post_delay_final = graphic_info[graphic].post_delay;
1033 if (graphic_info[graphic].auto_delay > -1)
1034 title.auto_delay_final = graphic_info[graphic].auto_delay;
1037 void DrawTitleScreenMessage(int nr, boolean initial)
1039 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1040 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1042 int font_nr = FONT_TEXT_1;
1046 int pad_y = 32 + 14;
1049 int max_chars_per_line;
1050 int max_lines_per_screen;
1052 int last_game_status = game_status; /* save current game status */
1054 if (filename == NULL)
1057 /* force MESSAGE font on title message screen */
1058 game_status = getTitleMessageGameMode(initial);
1060 /* if chars set to "-1", automatically determine by text and font width */
1061 if (tmi->chars == -1)
1062 tmi->chars = tmi->width / getFontWidth(tmi->font);
1064 tmi->width = tmi->chars * getFontWidth(tmi->font);
1066 /* if lines set to "-1", automatically determine by text and font height */
1067 if (tmi->lines == -1)
1068 tmi->lines = tmi->height / getFontHeight(tmi->font);
1070 tmi->height = tmi->lines * getFontHeight(tmi->font);
1072 SetDrawBackgroundMask(REDRAW_ALL);
1073 SetWindowBackgroundImage(getTitleMessageBackground(initial));
1075 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1078 font_width = getFontWidth(font_nr);
1079 font_height = getFontHeight(font_nr);
1080 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1081 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1085 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1086 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1087 tmi->autowrap, tmi->centered, tmi->skip_comments);
1089 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1090 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1091 tmi->skip_comments);
1094 game_status = last_game_status; /* restore current game status */
1097 void DrawTitleScreen()
1099 KeyboardAutoRepeatOff();
1102 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1105 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1110 boolean CheckTitleScreen(boolean levelset_has_changed)
1112 static boolean show_title_initial = TRUE;
1113 boolean show_titlescreen = FALSE;
1115 /* needed to be able to skip title screen, if no image or message defined */
1116 InitializeTitleControls(show_title_initial);
1118 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1119 show_titlescreen = TRUE;
1121 /* show initial title images and messages only once at program start */
1122 show_title_initial = FALSE;
1124 return (show_titlescreen && num_title_screens > 0);
1127 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1129 static LevelDirTree *leveldir_last_valid = NULL;
1130 boolean levelset_has_changed = FALSE;
1132 boolean local_team_mode = (!options.network && setup.team_mode);
1133 char *name_text = (local_team_mode ? "Team:" : "Name:");
1134 int name_width, level_width;
1141 FadeSoundsAndMusic();
1143 KeyboardAutoRepeatOn();
1146 SetDrawDeactivationMask(REDRAW_NONE);
1147 SetDrawBackgroundMask(REDRAW_FIELD);
1149 audio.sound_deactivated = FALSE;
1153 /* needed if last screen was the playing screen, invoked from level editor */
1154 if (level_editor_test_game)
1156 game_status = GAME_MODE_EDITOR;
1162 /* needed if last screen was the editor screen */
1163 UndrawSpecialEditorDoor();
1165 /* needed if last screen was the setup screen and fullscreen state changed */
1166 ToggleFullscreenIfNeeded();
1168 /* leveldir_current may be invalid (level group, parent link) */
1169 if (!validLevelSeries(leveldir_current))
1170 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1172 if (leveldir_current != leveldir_last_valid)
1173 levelset_has_changed = TRUE;
1175 /* store valid level series information */
1176 leveldir_last_valid = leveldir_current;
1178 /* needed if last screen (level choice) changed graphics, sounds or music */
1179 ReloadCustomArtwork(0);
1181 #if defined(TARGET_SDL)
1182 SetDrawtoField(DRAW_BACKBUFFER);
1186 if (CheckTitleScreen(levelset_has_changed))
1188 game_status = GAME_MODE_TITLE;
1197 if (setup.show_titlescreen &&
1198 ((levelset_has_changed &&
1199 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1200 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1201 (show_title_initial &&
1202 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1203 getLevelSetMessageFilename(1, TRUE) != NULL))))
1205 game_status = GAME_MODE_TITLE;
1213 /* level_nr may have been set to value over handicap with level editor */
1214 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1215 level_nr = leveldir_current->handicap_level;
1217 LoadLevel(level_nr);
1219 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1223 InitializeMainControls();
1226 DrawCursorAndText_Main(-1, FALSE);
1228 for (i = 0; main_controls[i].nr != -1; i++)
1230 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1231 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1232 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1233 char *text = main_controls[i].text;
1234 char *input = main_controls[i].input;
1235 int button_graphic = main_controls[i].button_graphic;
1236 int font_text = main_controls[i].font_text;
1237 int font_input = main_controls[i].font_input;
1239 if (pos_button != NULL)
1240 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1243 if (pos_text != NULL && text != NULL)
1244 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1246 if (pos_input != NULL && input != NULL)
1247 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1255 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1256 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1257 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1258 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1259 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1260 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1261 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1262 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1264 /* calculated after (possible) reload of custom artwork */
1265 name_width = getTextWidth(name_text, FONT_MENU_1);
1266 level_width = 9 * 32;
1268 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1271 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1272 int2str(level_nr, 3), FONT_VALUE_1);
1275 int text_height = getFontHeight(FONT_TEXT_3);
1276 int xpos = getLevelRangeTextPos() * 32 + 8;
1277 int ypos2 = 3 * 32 + 16;
1278 int ypos1 = ypos2 - text_height;
1280 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1281 "%03d", leveldir_current->first_level);
1282 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1283 "%03d", leveldir_current->last_level);
1286 for (i = 0; i < 8; i++)
1287 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1290 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1293 DrawPreviewLevel(TRUE);
1295 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1298 if (TAPE_IS_EMPTY(tape))
1300 DrawCompleteVideoDisplay();
1305 /* create gadgets for main menu screen */
1306 FreeScreenGadgets();
1307 CreateScreenGadgets();
1309 /* map gadgets for main menu screen */
1311 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1313 DrawMaskedBorder(REDRAW_ALL);
1316 FadeIn(redraw_mask);
1320 SetMouseCursor(CURSOR_DEFAULT);
1324 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1327 void DrawAndFadeInMainMenu(int redraw_mask)
1329 DrawMainMenuExt(redraw_mask, TRUE);
1334 DrawMainMenuExt(REDRAW_ALL, FALSE);
1338 static void gotoTopLevelDir()
1340 /* move upwards to top level directory */
1341 while (leveldir_current->node_parent)
1343 /* write a "path" into level tree for easy navigation to last level */
1344 if (leveldir_current->node_parent->node_group->cl_first == -1)
1346 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1347 int leveldir_pos = posTreeInfo(leveldir_current);
1348 int num_page_entries;
1349 int cl_first, cl_cursor;
1351 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1352 num_page_entries = num_leveldirs;
1354 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1356 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1357 cl_cursor = leveldir_pos - cl_first;
1359 leveldir_current->node_parent->node_group->cl_first = cl_first;
1360 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1363 leveldir_current = leveldir_current->node_parent;
1369 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1371 static unsigned long title_delay = 0;
1372 static int title_screen_nr = 0;
1373 static int last_sound = -1, last_music = -1;
1374 boolean return_to_main_menu = FALSE;
1375 boolean use_fading_main_menu = TRUE;
1377 boolean use_cross_fading = FALSE;
1379 boolean use_cross_fading = !show_title_initial; /* default */
1381 struct TitleControlInfo *tci;
1384 if (button == MB_MENU_INITIALIZE)
1387 int last_game_status = game_status; /* save current game status */
1391 title_screen_nr = 0;
1392 tci = &title_controls[title_screen_nr];
1394 last_sound = SND_UNDEFINED;
1395 last_music = MUS_UNDEFINED;
1398 /* determine number of title screens to display (images and messages) */
1399 InitializeTitleControls();
1402 if (game_status == GAME_MODE_INFO)
1404 if (num_title_screens == 0)
1406 DrawInfoScreen_NotAvailable("Title screen information:",
1407 "No title screen for this level set.");
1409 title.auto_delay_final = -1;
1414 FadeSoundsAndMusic();
1416 FadeOut(REDRAW_ALL);
1421 DrawTitleScreenImage(tci->local_nr, tci->initial);
1425 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1427 title.fade_delay_final = title.fade_delay;
1428 title.post_delay_final = title.post_delay;
1429 title.auto_delay_final = -1;
1433 sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
1434 music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
1436 if (sound != last_sound)
1437 PlayMenuSoundExt(sound);
1438 if (music != last_music)
1439 PlayMenuMusicExt(music);
1445 SetMouseCursor(CURSOR_NONE);
1449 DelayReached(&title_delay, 0); /* reset delay counter */
1454 if (title.auto_delay_final > -1 &&
1455 DelayReached(&title_delay, title.auto_delay_final))
1456 button = MB_MENU_CHOICE;
1458 if (button == MB_MENU_LEAVE)
1460 return_to_main_menu = TRUE;
1461 use_fading_main_menu = FALSE;
1463 else if (button == MB_MENU_CHOICE)
1467 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1469 FadeOut(REDRAW_FIELD);
1471 info_mode = INFO_MODE_MAIN;
1472 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1478 tci = &title_controls[title_screen_nr];
1482 graphic_info[getTitleScreenGraphic(tci->local_nr,
1483 tci->initial)].anim_mode;
1485 anim_mode = ANIM_FADE; /* ??? */
1487 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1488 anim_mode == ANIM_CROSSFADE ? TRUE :
1491 if (title_screen_nr < num_title_screens)
1493 sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
1494 music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
1496 if (sound == SND_UNDEFINED || sound != last_sound)
1498 if (music == MUS_UNDEFINED || music != last_music)
1501 if (use_cross_fading)
1502 FadeCrossSaveBackbuffer();
1504 FadeOut(REDRAW_ALL);
1507 DrawTitleScreenImage(tci->local_nr, tci->initial);
1509 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1512 sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
1513 music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
1515 if (sound != last_sound)
1516 PlayMenuSoundExt(sound);
1517 if (music != last_music)
1518 PlayMenuMusicExt(music);
1524 if (use_cross_fading)
1525 FadeCross(REDRAW_ALL);
1529 DelayReached(&title_delay, 0); /* reset delay counter */
1533 FadeSoundsAndMusic();
1535 FadeOut(REDRAW_ALL);
1537 return_to_main_menu = TRUE;
1541 if (return_to_main_menu)
1545 SetMouseCursor(CURSOR_DEFAULT);
1547 if (game_status == GAME_MODE_INFO)
1549 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1551 info_mode = INFO_MODE_MAIN;
1552 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1554 else /* default: return to main menu */
1556 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1558 game_status = GAME_MODE_MAIN;
1559 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1566 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1568 static unsigned long title_delay = 0;
1569 static int title_nr = 0;
1570 static boolean showing_message = FALSE;
1571 char *filename = getLevelSetMessageFilename();
1572 boolean return_to_main_menu = FALSE;
1573 boolean use_fading_main_menu = TRUE;
1574 boolean use_cross_fading = !show_title_initial; /* default */
1575 boolean no_title_info = (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL &&
1576 getLevelSetMessageFilename(1, FALSE) == NULL);
1578 if (button == MB_MENU_INITIALIZE)
1580 int last_game_status = game_status; /* save current game status */
1584 showing_message = FALSE;
1586 if (show_title_initial &&
1587 graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap == NULL &&
1588 getLevelSetMessageFilename(1, TRUE) == NULL)
1589 show_title_initial = FALSE;
1591 if (game_status == GAME_MODE_INFO)
1595 DrawInfoScreen_NotAvailable("Title screen information:",
1596 "No title screen for this level set.");
1598 title.auto_delay_final = -1;
1603 FadeSoundsAndMusic();
1605 FadeOut(REDRAW_ALL);
1608 /* force TITLE music on title info screen */
1609 game_status = GAME_MODE_TITLE;
1614 game_status = last_game_status; /* restore current game status */
1616 if (graphic_info[getTitleScreenGraphic(0, show_title_initial)].bitmap != NULL)
1618 DrawTitleScreenImage(title_nr, show_title_initial);
1622 DrawTitleScreenMessage(filename);
1624 showing_message = TRUE;
1626 title.fade_delay_final = title.fade_delay;
1627 title.post_delay_final = title.post_delay;
1628 title.auto_delay_final = -1;
1633 DelayReached(&title_delay, 0); /* reset delay counter */
1638 if (title.auto_delay_final > -1 &&
1639 DelayReached(&title_delay, title.auto_delay_final))
1640 button = MB_MENU_CHOICE;
1642 if (button == MB_MENU_LEAVE)
1644 return_to_main_menu = TRUE;
1645 use_fading_main_menu = FALSE;
1647 else if (button == MB_MENU_CHOICE)
1651 if (game_status == GAME_MODE_INFO && no_title_info)
1653 FadeOut(REDRAW_FIELD);
1655 info_mode = INFO_MODE_MAIN;
1656 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1663 if (show_title_initial &&
1664 (title_nr >= MAX_NUM_TITLE_IMAGES ||
1665 graphic_info[IMG_TITLESCREEN_INITIAL_1 + title_nr].bitmap == NULL))
1667 show_title_initial = FALSE;
1669 title_nr = 0; /* restart with title screens for current level set */
1672 anim_mode = graphic_info[getTitleScreenGraphic(title_nr, show_title_initial)].anim_mode;
1674 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1675 anim_mode == ANIM_CROSSFADE ? TRUE :
1678 if (!use_cross_fading)
1679 FadeOut(REDRAW_ALL);
1681 if (title_nr < MAX_NUM_TITLE_IMAGES &&
1682 graphic_info[getTitleScreenGraphic(title_nr, show_title_initial)].bitmap != NULL)
1684 if (use_cross_fading)
1685 FadeCrossSaveBackbuffer();
1687 DrawTitleScreenImage(title_nr, show_title_initial);
1689 if (use_cross_fading)
1690 FadeCross(REDRAW_ALL);
1694 DelayReached(&title_delay, 0); /* reset delay counter */
1696 else if (!showing_message && filename != NULL)
1698 if (use_cross_fading)
1699 FadeCrossSaveBackbuffer();
1701 DrawTitleScreenMessage(filename);
1703 if (use_cross_fading)
1704 FadeCross(REDRAW_ALL);
1708 DelayReached(&title_delay, 0); /* reset delay counter */
1710 showing_message = TRUE;
1714 FadeSoundsAndMusic();
1716 FadeOut(REDRAW_ALL);
1718 return_to_main_menu = TRUE;
1722 if (return_to_main_menu)
1724 show_title_initial = FALSE;
1728 if (game_status == GAME_MODE_INFO)
1730 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1732 info_mode = INFO_MODE_MAIN;
1733 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1735 else /* default: return to main menu */
1737 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1739 game_status = GAME_MODE_MAIN;
1740 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1746 void HandleMainMenu_SelectLevel(int step, int direction)
1748 int old_level_nr = level_nr;
1751 new_level_nr = old_level_nr + step * direction;
1752 if (new_level_nr < leveldir_current->first_level)
1753 new_level_nr = leveldir_current->first_level;
1754 if (new_level_nr > leveldir_current->last_level)
1755 new_level_nr = leveldir_current->last_level;
1757 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1759 /* skipping levels is only allowed when trying to skip single level */
1760 if (setup.skip_levels && step == 1 &&
1761 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1763 leveldir_current->handicap_level++;
1764 SaveLevelSetup_SeriesInfo();
1767 new_level_nr = leveldir_current->handicap_level;
1770 if (new_level_nr != old_level_nr)
1772 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1774 PlaySound(SND_MENU_ITEM_SELECTING);
1776 level_nr = new_level_nr;
1779 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1780 int2str(level_nr, 3), mci->pos_text->font);
1782 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1785 LoadLevel(level_nr);
1786 DrawPreviewLevel(TRUE);
1790 DrawCompleteVideoDisplay();
1792 /* needed because DrawPreviewLevel() takes some time */
1800 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1802 static int choice = MAIN_CONTROL_GAME;
1806 if (button == MB_MENU_INITIALIZE)
1808 DrawCursorAndText_Main(choice, TRUE);
1813 if (mx || my) /* mouse input */
1817 for (i = 0; main_controls[i].nr != -1; i++)
1819 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1820 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1821 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1823 pos = main_controls[i].nr;
1829 else if (dx || dy) /* keyboard input */
1831 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1832 choice == MAIN_CONTROL_SETUP))
1833 button = MB_MENU_CHOICE;
1838 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1840 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1842 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1848 PlaySound(SND_MENU_ITEM_ACTIVATING);
1850 DrawCursorAndText_Main(choice, FALSE);
1851 DrawCursorAndText_Main(pos, TRUE);
1858 PlaySound(SND_MENU_ITEM_SELECTING);
1860 if (pos == MAIN_CONTROL_NAME)
1862 game_status = GAME_MODE_PSEUDO_TYPENAME;
1864 HandleTypeName(strlen(setup.player_name), 0);
1866 else if (pos == MAIN_CONTROL_LEVELS)
1870 game_status = GAME_MODE_LEVELS;
1872 SaveLevelSetup_LastSeries();
1873 SaveLevelSetup_SeriesInfo();
1882 else if (pos == MAIN_CONTROL_SCORES)
1884 game_status = GAME_MODE_SCORES;
1888 else if (pos == MAIN_CONTROL_EDITOR)
1890 if (leveldir_current->readonly &&
1891 !strEqual(setup.player_name, "Artsoft"))
1892 Request("This level is read only !", REQ_CONFIRM);
1894 game_status = GAME_MODE_EDITOR;
1898 else if (pos == MAIN_CONTROL_INFO)
1900 game_status = GAME_MODE_INFO;
1901 info_mode = INFO_MODE_MAIN;
1905 else if (pos == MAIN_CONTROL_GAME)
1907 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1909 else if (pos == MAIN_CONTROL_SETUP)
1911 game_status = GAME_MODE_SETUP;
1912 setup_mode = SETUP_MODE_MAIN;
1916 else if (pos == MAIN_CONTROL_QUIT)
1918 SaveLevelSetup_LastSeries();
1919 SaveLevelSetup_SeriesInfo();
1921 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1922 game_status = GAME_MODE_QUIT;
1927 if (game_status == GAME_MODE_MAIN)
1929 DrawPreviewLevel(FALSE);
1936 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1938 static int choice = 5;
1942 if (button == MB_MENU_INITIALIZE)
1944 drawCursor(choice, TRUE);
1949 if (mx || my) /* mouse input */
1951 x = (mx - mSX) / 32;
1952 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1954 else if (dx || dy) /* keyboard input */
1956 if (dx && choice == 1)
1957 x = (dx < 0 ? 10 : 14);
1960 if (choice == 4 || choice == 6)
1961 button = MB_MENU_CHOICE;
1967 if (y == 1 && dx != 0 && button)
1969 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1971 else if (IN_VIS_FIELD(x, y) &&
1972 y >= 0 && y <= 7 && (y != 1 || x < 10))
1978 drawCursor(choice, FALSE);
1979 drawCursor(y, TRUE);
1988 game_status = GAME_MODE_PSEUDO_TYPENAME;
1989 HandleTypeName(strlen(setup.player_name), 0);
1995 game_status = GAME_MODE_LEVELS;
1996 SaveLevelSetup_LastSeries();
1997 SaveLevelSetup_SeriesInfo();
2008 game_status = GAME_MODE_SCORES;
2013 if (leveldir_current->readonly &&
2014 !strEqual(setup.player_name, "Artsoft"))
2015 Request("This level is read only !", REQ_CONFIRM);
2016 game_status = GAME_MODE_EDITOR;
2021 game_status = GAME_MODE_INFO;
2022 info_mode = INFO_MODE_MAIN;
2027 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2031 game_status = GAME_MODE_SETUP;
2032 setup_mode = SETUP_MODE_MAIN;
2038 SaveLevelSetup_LastSeries();
2039 SaveLevelSetup_SeriesInfo();
2041 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2042 game_status = GAME_MODE_QUIT;
2047 if (game_status == GAME_MODE_MAIN)
2049 DrawPreviewLevel(FALSE);
2057 /* ========================================================================= */
2058 /* info screen functions */
2059 /* ========================================================================= */
2061 static struct TokenInfo *info_info;
2062 static int num_info_info;
2064 static void execInfoTitleScreen()
2066 info_mode = INFO_MODE_TITLE;
2070 static void execInfoElements()
2072 info_mode = INFO_MODE_ELEMENTS;
2076 static void execInfoMusic()
2078 info_mode = INFO_MODE_MUSIC;
2082 static void execInfoCredits()
2084 info_mode = INFO_MODE_CREDITS;
2088 static void execInfoProgram()
2090 info_mode = INFO_MODE_PROGRAM;
2094 static void execInfoVersion()
2096 info_mode = INFO_MODE_VERSION;
2100 static void execInfoLevelSet()
2102 info_mode = INFO_MODE_LEVELSET;
2106 static void execExitInfo()
2108 game_status = GAME_MODE_MAIN;
2112 static struct TokenInfo info_info_main[] =
2114 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2115 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2116 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2117 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2118 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2119 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2120 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2121 { TYPE_EMPTY, NULL, "" },
2122 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2127 static void DrawCursorAndText_Info(int pos, boolean active)
2129 int xpos = MENU_SCREEN_START_XPOS;
2130 int ypos = MENU_SCREEN_START_YPOS + pos;
2131 int font_nr = FONT_MENU_1;
2134 font_nr = FONT_ACTIVE(font_nr);
2136 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2138 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2139 drawCursor(pos, active);
2142 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2147 CloseDoor(DOOR_CLOSE_2);
2151 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2153 info_info = info_info_main;
2156 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2159 int xpos = MENU_SCREEN_START_XPOS;
2160 int ypos = MENU_SCREEN_START_YPOS + i;
2161 int font_nr = FONT_MENU_1;
2164 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2165 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2166 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2167 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2168 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2169 initCursor(i, IMG_MENU_BUTTON);
2172 DrawCursorAndText_Info(i, FALSE);
2174 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2180 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2185 DrawMaskedBorder(REDRAW_ALL);
2188 FadeIn(redraw_mask);
2195 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2197 static int choice_store[MAX_INFO_MODES];
2198 int choice = choice_store[info_mode]; /* always starts with 0 */
2202 if (button == MB_MENU_INITIALIZE)
2204 /* advance to first valid menu entry */
2205 while (choice < num_info_info &&
2206 info_info[choice].type & TYPE_SKIP_ENTRY)
2208 choice_store[info_mode] = choice;
2211 DrawCursorAndText_Info(choice, TRUE);
2213 drawCursor(choice, TRUE);
2218 else if (button == MB_MENU_LEAVE)
2220 for (y = 0; y < num_info_info; y++)
2222 if (info_info[y].type & TYPE_LEAVE_MENU)
2224 void (*menu_callback_function)(void) = info_info[y].value;
2226 menu_callback_function();
2228 break; /* absolutely needed because function changes 'info_info'! */
2235 if (mx || my) /* mouse input */
2237 x = (mx - mSX) / 32;
2238 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2240 else if (dx || dy) /* keyboard input */
2244 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2246 if (info_info[choice].type & menu_navigation_type ||
2247 info_info[choice].type & TYPE_ENTER_SCREEN ||
2248 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2249 button = MB_MENU_CHOICE;
2254 /* jump to next non-empty menu entry (up or down) */
2255 while (y > 0 && y < num_info_info - 1 &&
2256 info_info[y].type & TYPE_SKIP_ENTRY)
2260 if (IN_VIS_FIELD(x, y) &&
2261 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2267 PlaySound(SND_MENU_ITEM_ACTIVATING);
2270 DrawCursorAndText_Info(choice, FALSE);
2271 DrawCursorAndText_Info(y, TRUE);
2273 drawCursor(choice, FALSE);
2274 drawCursor(y, TRUE);
2277 choice = choice_store[info_mode] = y;
2280 else if (!(info_info[y].type & TYPE_GHOSTED))
2282 PlaySound(SND_MENU_ITEM_SELECTING);
2284 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2286 void (*menu_callback_function)(void) = info_info[choice].value;
2288 menu_callback_function();
2294 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2297 int ystart1 = mSY - SY + 100;
2298 int ystart2 = mSY - SY + 150;
2299 int ybottom = mSY - SY + SYSIZE - 20;
2303 int ybottom = SYSIZE - 20;
2306 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2308 FadeOut(REDRAW_FIELD);
2313 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2314 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2316 DrawTextSCentered(ybottom, FONT_TEXT_4,
2317 "Press any key or button for info menu");
2319 FadeIn(REDRAW_FIELD);
2322 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2324 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2325 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2326 int xstart = mSX + 16;
2327 int ystart1 = mSY - SY + 100;
2328 int ystart2 = mSY + 64 + 2 * 32;
2329 int ybottom = mSY - SY + SYSIZE - 20;
2330 int ystep = TILEY + 4;
2331 int element, action, direction;
2339 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2340 infoscreen_step[i] = infoscreen_frame[i] = 0;
2345 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2347 DrawTextSCentered(ybottom, FONT_TEXT_4,
2348 "Press any key or button for next page");
2354 while (helpanim_info[j].element != HELPANIM_LIST_END)
2356 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2361 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2370 j += infoscreen_step[i - start];
2372 element = helpanim_info[j].element;
2373 action = helpanim_info[j].action;
2374 direction = helpanim_info[j].direction;
2377 element = EL_UNKNOWN;
2379 if (action != -1 && direction != -1)
2380 graphic = el_act_dir2img(element, action, direction);
2381 else if (action != -1)
2382 graphic = el_act2img(element, action);
2383 else if (direction != -1)
2384 graphic = el_dir2img(element, direction);
2386 graphic = el2img(element);
2388 delay = helpanim_info[j++].delay;
2393 if (infoscreen_frame[i - start] == 0)
2396 infoscreen_frame[i - start] = delay - 1;
2400 sync_frame = delay - infoscreen_frame[i - start];
2401 infoscreen_frame[i - start]--;
2404 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2406 if (!infoscreen_frame[i - start])
2407 infoscreen_step[i - start] = 0;
2411 if (!infoscreen_frame[i - start])
2412 infoscreen_step[i - start]++;
2413 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2419 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2421 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2422 graphic, sync_frame, USE_MASKING);
2425 DrawInfoScreen_HelpText(element, action, direction, i - start);
2430 redraw_mask |= REDRAW_FIELD;
2435 static char *getHelpText(int element, int action, int direction)
2437 char token[MAX_LINE_LEN];
2439 strcpy(token, element_info[element].token_name);
2442 strcat(token, element_action_info[action].suffix);
2444 if (direction != -1)
2445 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2447 return getHashEntry(helptext_info, token);
2450 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2453 int font_nr = FONT_INFO_ELEMENTS;
2455 int font_nr = FONT_LEVEL_NUMBER;
2457 int font_width = getFontWidth(font_nr);
2458 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2459 int sy = mSY + 65 + 2 * 32 + 1;
2460 int ystep = TILEY + 4;
2461 int pad_x = sx - SX;
2462 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2463 int max_lines_per_text = 2;
2466 if (action != -1 && direction != -1) /* element.action.direction */
2467 text = getHelpText(element, action, direction);
2469 if (text == NULL && action != -1) /* element.action */
2470 text = getHelpText(element, action, -1);
2472 if (text == NULL && direction != -1) /* element.direction */
2473 text = getHelpText(element, -1, direction);
2475 if (text == NULL) /* base element */
2476 text = getHelpText(element, -1, -1);
2478 if (text == NULL) /* not found */
2479 text = "No description available";
2481 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2482 sy += getFontHeight(font_nr) / 2;
2485 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2486 max_chars_per_line, -1, max_lines_per_text, -1,
2487 TRUE, FALSE, FALSE);
2489 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2490 max_chars_per_line, max_lines_per_text);
2494 void DrawInfoScreen_TitleScreen()
2499 void HandleInfoScreen_TitleScreen(int button)
2501 HandleTitleScreen(0, 0, 0, 0, button);
2504 void DrawInfoScreen_Elements()
2506 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2508 FadeOut(REDRAW_FIELD);
2513 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2515 FadeIn(REDRAW_FIELD);
2520 void HandleInfoScreen_Elements(int button)
2522 static unsigned long info_delay = 0;
2523 static int num_anims;
2524 static int num_pages;
2526 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2529 if (button == MB_MENU_INITIALIZE)
2531 boolean new_element = TRUE;
2535 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2537 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2539 else if (new_element)
2542 new_element = FALSE;
2546 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2550 if (button == MB_MENU_LEAVE)
2552 PlaySound(SND_MENU_ITEM_SELECTING);
2554 info_mode = INFO_MODE_MAIN;
2559 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2561 if (button != MB_MENU_INITIALIZE)
2563 PlaySound(SND_MENU_ITEM_SELECTING);
2568 if (page >= num_pages)
2570 FadeSoundsAndMusic();
2571 FadeOut(REDRAW_FIELD);
2573 info_mode = INFO_MODE_MAIN;
2574 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2579 if (button != MB_MENU_INITIALIZE)
2580 FadeCrossSaveBackbuffer();
2582 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2584 if (button != MB_MENU_INITIALIZE)
2585 FadeCross(REDRAW_FIELD);
2589 if (DelayReached(&info_delay, GameFrameDelay))
2590 if (page < num_pages)
2591 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2593 PlayMenuSoundIfLoop();
2597 void DrawInfoScreen_Music()
2599 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2601 FadeOut(REDRAW_FIELD);
2608 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2610 FadeIn(REDRAW_FIELD);
2613 void HandleInfoScreen_Music(int button)
2615 static struct MusicFileInfo *list = NULL;
2616 int ystart1 = mSY - SY + 100;
2617 int ystart2 = mSY - SY + 150;
2618 int ybottom = mSY - SY + SYSIZE - 20;
2621 if (button == MB_MENU_INITIALIZE)
2623 list = music_file_info;
2627 FadeSoundsAndMusic();
2632 DrawTextSCentered(ystart1, FONT_TEXT_1,
2633 "No music info for this level set.");
2635 DrawTextSCentered(ybottom, FONT_TEXT_4,
2636 "Press any key or button for info menu");
2642 if (button == MB_MENU_LEAVE)
2644 PlaySound(SND_MENU_ITEM_SELECTING);
2646 FadeSoundsAndMusic();
2648 info_mode = INFO_MODE_MAIN;
2653 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2657 if (button != MB_MENU_INITIALIZE)
2659 PlaySound(SND_MENU_ITEM_SELECTING);
2667 FadeSoundsAndMusic();
2668 FadeOut(REDRAW_FIELD);
2670 info_mode = INFO_MODE_MAIN;
2671 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2676 FadeSoundsAndMusic();
2678 if (button != MB_MENU_INITIALIZE)
2679 FadeCrossSaveBackbuffer();
2686 int sound = list->music;
2688 if (sound_info[sound].loop)
2689 PlaySoundLoop(sound);
2693 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2697 PlayMusic(list->music);
2699 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2702 if (!strEqual(list->title, UNKNOWN_NAME))
2704 if (!strEqual(list->title_header, UNKNOWN_NAME))
2705 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2707 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2710 if (!strEqual(list->artist, UNKNOWN_NAME))
2712 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2713 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2715 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2717 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2720 if (!strEqual(list->album, UNKNOWN_NAME))
2722 if (!strEqual(list->album_header, UNKNOWN_NAME))
2723 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2725 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2727 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2730 if (!strEqual(list->year, UNKNOWN_NAME))
2732 if (!strEqual(list->year_header, UNKNOWN_NAME))
2733 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2735 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2737 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2740 DrawTextSCentered(ybottom, FONT_TEXT_4,
2741 "Press any key or button for next page");
2743 if (button != MB_MENU_INITIALIZE)
2744 FadeCross(REDRAW_FIELD);
2747 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2748 PlaySoundLoop(list->music);
2751 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2753 int ystart1 = mSY - SY + 100;
2754 int ystart2 = mSY - SY + 150;
2755 int ybottom = mSY - SY + SYSIZE - 20;
2764 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2768 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2769 "Special thanks to");
2770 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2772 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2774 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2775 "\"Boulder Dash\"");
2776 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2778 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2780 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2782 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2783 "First Star Software");
2785 else if (screen_nr == 1)
2787 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2788 "Special thanks to");
2789 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2790 "Klaus Heinz & Volker Wertich");
2791 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2793 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2794 "\"Emerald Mine\"");
2795 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2797 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2799 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2801 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2804 else if (screen_nr == 2)
2806 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2807 "Special thanks to");
2808 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2809 "Michael Stopp & Philip Jespersen");
2810 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2812 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2814 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2816 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2818 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2820 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2821 "Digital Integration");
2823 else if (screen_nr == 3)
2825 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2826 "Special thanks to");
2827 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2828 "Hiroyuki Imabayashi");
2829 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2831 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2833 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2835 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2837 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2839 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2842 else if (screen_nr == 4)
2844 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2845 "Special thanks to");
2846 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2848 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2850 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2851 "Jürgen Bonhagen");
2852 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2853 "for the continuous creation");
2854 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2855 "of outstanding level sets");
2857 else if (screen_nr == 5)
2859 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2861 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2863 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2864 "for ideas and inspiration by");
2865 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2868 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2870 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2872 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2873 "for ideas and inspiration by");
2874 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2877 else if (screen_nr == 6)
2879 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2881 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2883 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2884 "for the new Emerald Mine engine");
2886 else if (screen_nr == 7)
2888 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2890 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2892 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2893 "for the initial DOS port");
2895 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2897 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2899 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2900 "for some additional toons");
2902 else if (screen_nr == 8)
2904 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2905 "And not to forget:");
2906 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2908 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2909 "All those who contributed");
2910 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2911 "levels to this game");
2912 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2922 DrawTextSCentered(ybottom, FONT_TEXT_4,
2923 "Press any key or button for next page");
2928 void DrawInfoScreen_Credits()
2930 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2932 FadeSoundsAndMusic();
2934 FadeOut(REDRAW_FIELD);
2936 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2938 FadeIn(REDRAW_FIELD);
2941 void HandleInfoScreen_Credits(int button)
2943 static int screen_nr = 0;
2945 if (button == MB_MENU_INITIALIZE)
2949 DrawInfoScreen_CreditsScreen(screen_nr);
2951 else if (button == MB_MENU_LEAVE)
2953 PlaySound(SND_MENU_ITEM_SELECTING);
2955 info_mode = INFO_MODE_MAIN;
2960 else if (button == MB_MENU_CHOICE)
2962 boolean show_screen;
2964 PlaySound(SND_MENU_ITEM_SELECTING);
2968 FadeCrossSaveBackbuffer();
2970 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
2974 FadeCross(REDRAW_FIELD);
2978 FadeSoundsAndMusic();
2979 FadeOut(REDRAW_FIELD);
2981 info_mode = INFO_MODE_MAIN;
2982 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2987 PlayMenuSoundIfLoop();
2991 void DrawInfoScreen_Program()
2993 int ystart1 = mSY - SY + 100;
2994 int ystart2 = mSY - SY + 150;
2995 int ybottom = mSY - SY + SYSIZE - 20;
2998 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3000 FadeOut(REDRAW_FIELD);
3005 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3007 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3008 "This game is Freeware!");
3009 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3010 "If you like it, send e-mail to:");
3011 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3012 PROGRAM_EMAIL_STRING);
3013 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3014 "or SnailMail to:");
3015 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3017 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3018 "Detmolder Strasse 189");
3019 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3021 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3023 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3024 "More information and levels:");
3025 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3026 PROGRAM_WEBSITE_STRING);
3027 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3028 "If you have created new levels,");
3029 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3030 "send them to me to include them!");
3031 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3034 DrawTextSCentered(ybottom, FONT_TEXT_4,
3035 "Press any key or button for info menu");
3037 FadeIn(REDRAW_FIELD);
3040 void HandleInfoScreen_Program(int button)
3042 if (button == MB_MENU_LEAVE)
3044 PlaySound(SND_MENU_ITEM_SELECTING);
3046 info_mode = INFO_MODE_MAIN;
3051 else if (button == MB_MENU_CHOICE)
3053 PlaySound(SND_MENU_ITEM_SELECTING);
3055 FadeSoundsAndMusic();
3056 FadeOut(REDRAW_FIELD);
3058 info_mode = INFO_MODE_MAIN;
3059 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3063 PlayMenuSoundIfLoop();
3067 void DrawInfoScreen_Version()
3069 int font_header = FONT_TEXT_3;
3070 int font_text = FONT_TEXT_2;
3071 int xstep = getFontWidth(font_text);
3072 int ystep = getFontHeight(font_text);
3073 int ystart1 = mSY - SY + 100;
3074 int ystart2 = mSY - SY + 150;
3075 int ybottom = mSY - SY + SYSIZE - 20;
3076 int xstart1 = mSX + 2 * xstep;
3077 int xstart2 = mSX + 19 * xstep;
3078 #if defined(TARGET_SDL)
3079 int xstart3 = mSX + 29 * xstep;
3080 SDL_version sdl_version_compiled;
3081 const SDL_version *sdl_version_linked;
3082 int driver_name_len = 8;
3083 char driver_name[driver_name_len];
3086 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3088 FadeOut(REDRAW_FIELD);
3093 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3095 DrawTextF(xstart1, ystart2, font_header, "Name");
3096 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3099 DrawTextF(xstart1, ystart2, font_header, "Version");
3100 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3103 DrawTextF(xstart1, ystart2, font_header, "Platform");
3104 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3107 DrawTextF(xstart1, ystart2, font_header, "Target");
3108 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3111 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3112 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3114 #if defined(TARGET_SDL)
3115 ystart2 += 3 * ystep;
3116 DrawTextF(xstart1, ystart2, font_header, "Library");
3117 DrawTextF(xstart2, ystart2, font_header, "compiled");
3118 DrawTextF(xstart3, ystart2, font_header, "linked");
3120 SDL_VERSION(&sdl_version_compiled);
3121 sdl_version_linked = SDL_Linked_Version();
3123 ystart2 += 2 * ystep;
3124 DrawTextF(xstart1, ystart2, font_text, "SDL");
3125 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3126 sdl_version_compiled.major,
3127 sdl_version_compiled.minor,
3128 sdl_version_compiled.patch);
3129 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3130 sdl_version_linked->major,
3131 sdl_version_linked->minor,
3132 sdl_version_linked->patch);
3134 SDL_IMAGE_VERSION(&sdl_version_compiled);
3135 sdl_version_linked = IMG_Linked_Version();
3138 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3139 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3140 sdl_version_compiled.major,
3141 sdl_version_compiled.minor,
3142 sdl_version_compiled.patch);
3143 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3144 sdl_version_linked->major,
3145 sdl_version_linked->minor,
3146 sdl_version_linked->patch);
3148 SDL_MIXER_VERSION(&sdl_version_compiled);
3149 sdl_version_linked = Mix_Linked_Version();
3152 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3153 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3154 sdl_version_compiled.major,
3155 sdl_version_compiled.minor,
3156 sdl_version_compiled.patch);
3157 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3158 sdl_version_linked->major,
3159 sdl_version_linked->minor,
3160 sdl_version_linked->patch);
3162 SDL_NET_VERSION(&sdl_version_compiled);
3163 sdl_version_linked = SDLNet_Linked_Version();
3166 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3167 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3168 sdl_version_compiled.major,
3169 sdl_version_compiled.minor,
3170 sdl_version_compiled.patch);
3171 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3172 sdl_version_linked->major,
3173 sdl_version_linked->minor,
3174 sdl_version_linked->patch);
3176 ystart2 += 3 * ystep;
3177 DrawTextF(xstart1, ystart2, font_header, "Driver");
3178 DrawTextF(xstart2, ystart2, font_header, "Requested");
3179 DrawTextF(xstart3, ystart2, font_header, "Used");
3181 SDL_VideoDriverName(driver_name, driver_name_len);
3183 ystart2 += 2 * ystep;
3184 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3185 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3186 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3188 SDL_AudioDriverName(driver_name, driver_name_len);
3191 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3192 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3193 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3196 DrawTextSCentered(ybottom, FONT_TEXT_4,
3197 "Press any key or button for info menu");
3199 FadeIn(REDRAW_FIELD);
3202 void HandleInfoScreen_Version(int button)
3204 if (button == MB_MENU_LEAVE)
3206 PlaySound(SND_MENU_ITEM_SELECTING);
3208 info_mode = INFO_MODE_MAIN;
3213 else if (button == MB_MENU_CHOICE)
3215 PlaySound(SND_MENU_ITEM_SELECTING);
3217 FadeSoundsAndMusic();
3218 FadeOut(REDRAW_FIELD);
3220 info_mode = INFO_MODE_MAIN;
3221 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3225 PlayMenuSoundIfLoop();
3229 void DrawInfoScreen_LevelSet()
3231 struct TitleMessageInfo *tmi = &readme;
3232 char *filename = getLevelSetInfoFilename();
3234 /* if chars set to "-1", automatically determine by text and font width */
3235 if (tmi->chars == -1)
3236 tmi->chars = tmi->width / getFontWidth(tmi->font);
3238 tmi->width = tmi->chars * getFontWidth(tmi->font);
3240 /* if lines set to "-1", automatically determine by text and font height */
3241 if (tmi->lines == -1)
3242 tmi->lines = tmi->height / getFontHeight(tmi->font);
3244 tmi->height = tmi->lines * getFontHeight(tmi->font);
3246 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3248 FadeOut(REDRAW_FIELD);
3253 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3255 if (filename != NULL)
3256 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3257 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3258 tmi->autowrap, tmi->centered, tmi->skip_comments);
3260 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3261 "No information for this level set.");
3263 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3264 "Press any key or button for info menu");
3266 FadeIn(REDRAW_FIELD);
3269 void HandleInfoScreen_LevelSet(int button)
3271 if (button == MB_MENU_LEAVE)
3273 PlaySound(SND_MENU_ITEM_SELECTING);
3275 info_mode = INFO_MODE_MAIN;
3280 else if (button == MB_MENU_CHOICE)
3282 PlaySound(SND_MENU_ITEM_SELECTING);
3284 FadeSoundsAndMusic();
3285 FadeOut(REDRAW_FIELD);
3287 info_mode = INFO_MODE_MAIN;
3288 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3292 PlayMenuSoundIfLoop();
3296 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3298 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3300 if (info_mode == INFO_MODE_TITLE)
3301 DrawInfoScreen_TitleScreen();
3302 else if (info_mode == INFO_MODE_ELEMENTS)
3303 DrawInfoScreen_Elements();
3304 else if (info_mode == INFO_MODE_MUSIC)
3305 DrawInfoScreen_Music();
3306 else if (info_mode == INFO_MODE_CREDITS)
3307 DrawInfoScreen_Credits();
3308 else if (info_mode == INFO_MODE_PROGRAM)
3309 DrawInfoScreen_Program();
3310 else if (info_mode == INFO_MODE_VERSION)
3311 DrawInfoScreen_Version();
3312 else if (info_mode == INFO_MODE_LEVELSET)
3313 DrawInfoScreen_LevelSet();
3315 DrawInfoScreen_Main(redraw_mask, do_fading);
3317 if (info_mode != INFO_MODE_MAIN &&
3318 info_mode != INFO_MODE_TITLE &&
3319 info_mode != INFO_MODE_MUSIC)
3326 void DrawAndFadeInInfoScreen(int redraw_mask)
3328 DrawInfoScreenExt(redraw_mask, TRUE);
3331 void DrawInfoScreen()
3333 DrawInfoScreenExt(REDRAW_ALL, FALSE);
3336 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3338 if (info_mode == INFO_MODE_TITLE)
3339 HandleInfoScreen_TitleScreen(button);
3340 else if (info_mode == INFO_MODE_ELEMENTS)
3341 HandleInfoScreen_Elements(button);
3342 else if (info_mode == INFO_MODE_MUSIC)
3343 HandleInfoScreen_Music(button);
3344 else if (info_mode == INFO_MODE_CREDITS)
3345 HandleInfoScreen_Credits(button);
3346 else if (info_mode == INFO_MODE_PROGRAM)
3347 HandleInfoScreen_Program(button);
3348 else if (info_mode == INFO_MODE_VERSION)
3349 HandleInfoScreen_Version(button);
3350 else if (info_mode == INFO_MODE_LEVELSET)
3351 HandleInfoScreen_LevelSet(button);
3353 HandleInfoScreen_Main(mx, my, dx, dy, button);
3359 /* ========================================================================= */
3360 /* type name functions */
3361 /* ========================================================================= */
3363 void HandleTypeName(int newxpos, Key key)
3365 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3366 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3368 struct TextPosInfo *pos = mci->pos_input;
3369 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3370 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3373 static int xpos = 0;
3375 static int xpos = 0, ypos = 2;
3377 int font_nr = pos->font;
3378 int font_active_nr = FONT_ACTIVE(font_nr);
3379 int font_width = getFontWidth(font_active_nr);
3382 int startx = mSX + mci->pos_input->x;
3383 int starty = mSY + mci->pos_input->y;
3386 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3387 int startx = mSX + 32 + name_width;
3388 int starty = mSY + ypos * 32;
3390 char key_char = getValidConfigValueChar(getCharFromKey(key));
3391 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3392 boolean is_active = TRUE;
3394 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3398 strcpy(last_player_name, setup.player_name);
3403 /* add one character width for added cursor character */
3404 pos->width += font_width;
3405 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3407 DrawText(startx, starty, setup.player_name, font_active_nr);
3408 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3411 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3413 setup.player_name[xpos] = key_char;
3414 setup.player_name[xpos + 1] = 0;
3419 /* add one character width for added name text character */
3420 pos->width += font_width;
3421 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3423 DrawText(startx, starty, setup.player_name, font_active_nr);
3424 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3427 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3431 setup.player_name[xpos] = 0;
3434 /* remove one character width for removed name text character */
3435 pos->width -= font_width;
3436 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3438 DrawText(startx, starty, setup.player_name, font_active_nr);
3439 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3442 else if (key == KSYM_Return && xpos > 0)
3445 /* remove one character width for removed cursor text character */
3446 pos->width -= font_width;
3447 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3449 DrawText(startx, starty, setup.player_name, font_nr);
3450 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3457 game_status = GAME_MODE_MAIN;
3459 else if (key == KSYM_Escape)
3461 strcpy(setup.player_name, last_player_name);
3465 game_status = GAME_MODE_MAIN;
3470 pos->width = (strlen(setup.player_name) + 1) * font_width;
3471 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3473 DrawText(startx, starty, setup.player_name, font_active_nr);
3474 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3478 pos->width = strlen(setup.player_name) * font_width;
3479 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3481 DrawText(startx, starty, setup.player_name, font_nr);
3486 /* ========================================================================= */
3487 /* tree menu functions */
3488 /* ========================================================================= */
3490 static void DrawChooseTree(TreeInfo **ti_ptr)
3494 FreeScreenGadgets();
3495 CreateScreenGadgets();
3497 CloseDoor(DOOR_CLOSE_2);
3501 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3502 MapScreenTreeGadgets(*ti_ptr);
3508 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3510 struct GadgetInfo *gi = screen_gadget[id];
3511 int items_max, items_visible, item_position;
3513 items_max = numTreeInfoInGroup(ti);
3514 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3515 item_position = first_entry;
3517 if (item_position > items_max - items_visible)
3518 item_position = items_max - items_visible;
3520 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3521 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3522 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3525 static void drawChooseTreeList(int first_entry, int num_page_entries,
3529 char *title_string = NULL;
3530 int yoffset_sets = MENU_TITLE1_YPOS;
3531 int yoffset_setup = 16;
3532 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3534 int last_game_status = game_status; /* save current game status */
3536 title_string = ti->infotext;
3538 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3540 /* force LEVELS font on artwork setup screen */
3541 game_status = GAME_MODE_LEVELS;
3544 /* clear tree list area, but not title or scrollbar */
3545 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3546 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3547 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3549 /* clear tree list area, but not title or scrollbar */
3550 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3551 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3552 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3555 for (i = 0; i < num_page_entries; i++)
3557 TreeInfo *node, *node_first;
3558 int entry_pos = first_entry + i;
3559 int xpos = MENU_SCREEN_START_XPOS;
3560 int ypos = MENU_SCREEN_START_YPOS + i;
3561 int startx = mSX + xpos * 32;
3562 int starty = mSY + ypos * 32;
3563 int font_nr = FONT_TEXT_1;
3564 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3565 int startx_text = startx + font_xoffset;
3566 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3567 int text_size = startx_scrollbar - startx_text;
3568 int max_buffer_len = text_size / getFontWidth(font_nr);
3569 char buffer[max_buffer_len + 1];
3571 node_first = getTreeInfoFirstGroupEntry(ti);
3572 node = getTreeInfoFromPos(node_first, entry_pos);
3574 strncpy(buffer, node->name, max_buffer_len);
3575 buffer[max_buffer_len] = '\0';
3577 DrawText(startx, starty, buffer, font_nr + node->color);
3579 if (node->parent_link)
3580 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3581 else if (node->level_group)
3582 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3584 initCursor(i, IMG_MENU_BUTTON);
3587 game_status = last_game_status; /* restore current game status */
3589 redraw_mask |= REDRAW_FIELD;
3592 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3594 TreeInfo *node, *node_first;
3595 int x, last_redraw_mask = redraw_mask;
3596 int ypos = MENU_TITLE2_YPOS;
3597 int font_nr = FONT_TITLE_2;
3599 if (ti->type != TREE_TYPE_LEVEL_DIR)
3602 node_first = getTreeInfoFirstGroupEntry(ti);
3603 node = getTreeInfoFromPos(node_first, entry_pos);
3605 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3607 if (node->parent_link)
3608 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3610 else if (node->level_group)
3611 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3613 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3614 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3615 node->levels, node->class_desc);
3617 /* let BackToFront() redraw only what is needed */
3618 redraw_mask = last_redraw_mask | REDRAW_TILES;
3619 for (x = 0; x < SCR_FIELDX; x++)
3620 MarkTileDirty(x, 1);
3623 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3626 TreeInfo *ti = *ti_ptr;
3628 int y = ti->cl_cursor;
3629 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3630 int num_entries = numTreeInfoInGroup(ti);
3631 int num_page_entries;
3632 int last_game_status = game_status; /* save current game status */
3633 boolean position_set_by_scrollbar = (dx == 999);
3635 /* force LEVELS draw offset on choose level and artwork setup screen */
3636 game_status = GAME_MODE_LEVELS;
3638 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3639 num_page_entries = num_entries;
3641 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3643 game_status = last_game_status; /* restore current game status */
3645 if (button == MB_MENU_INITIALIZE)
3647 int num_entries = numTreeInfoInGroup(ti);
3648 int entry_pos = posTreeInfo(ti);
3650 if (ti->cl_first == -1)
3652 /* only on initialization */
3653 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3654 ti->cl_cursor = entry_pos - ti->cl_first;
3656 else if (ti->cl_cursor >= num_page_entries ||
3657 (num_entries > num_page_entries &&
3658 num_entries - ti->cl_first < num_page_entries))
3660 /* only after change of list size (by custom graphic configuration) */
3661 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3662 ti->cl_cursor = entry_pos - ti->cl_first;
3665 if (position_set_by_scrollbar)
3668 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3671 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3672 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3673 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3677 else if (button == MB_MENU_LEAVE)
3679 PlaySound(SND_MENU_ITEM_SELECTING);
3681 if (ti->node_parent)
3683 *ti_ptr = ti->node_parent;
3684 DrawChooseTree(ti_ptr);
3686 else if (game_status == GAME_MODE_SETUP)
3688 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3690 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3691 execSetupGraphics();
3697 game_status = GAME_MODE_MAIN;
3704 if (mx || my) /* mouse input */
3706 int last_game_status = game_status; /* save current game status */
3708 /* force LEVELS draw offset on artwork setup screen */
3709 game_status = GAME_MODE_LEVELS;
3711 x = (mx - mSX) / 32;
3712 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3714 game_status = last_game_status; /* restore current game status */
3716 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3718 /* move cursor instead of scrolling when already at start/end of list */
3719 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3721 else if (dy == +1 * SCROLL_LINE &&
3722 ti->cl_first + num_page_entries == num_entries)
3725 /* handle scrolling screen one line or page */
3726 if (ti->cl_cursor + dy < 0 ||
3727 ti->cl_cursor + dy > num_page_entries - 1)
3729 if (ABS(dy) == SCROLL_PAGE)
3730 step = num_page_entries - 1;
3732 if (dy < 0 && ti->cl_first > 0)
3734 /* scroll page/line up */
3736 ti->cl_first -= step;
3737 if (ti->cl_first < 0)
3740 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3741 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3742 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3744 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3747 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3749 /* scroll page/line down */
3751 ti->cl_first += step;
3752 if (ti->cl_first + num_page_entries > num_entries)
3753 ti->cl_first = MAX(0, num_entries - num_page_entries);
3755 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3756 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3757 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3759 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3766 /* handle moving cursor one line */
3767 y = ti->cl_cursor + dy;
3772 TreeInfo *node_first, *node_cursor;
3773 int entry_pos = ti->cl_first + y;
3775 node_first = getTreeInfoFirstGroupEntry(ti);
3776 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3778 if (node_cursor->node_group)
3780 PlaySound(SND_MENU_ITEM_SELECTING);
3782 node_cursor->cl_first = ti->cl_first;
3783 node_cursor->cl_cursor = ti->cl_cursor;
3784 *ti_ptr = node_cursor->node_group;
3785 DrawChooseTree(ti_ptr);
3790 else if (dx == -1 && ti->node_parent)
3792 PlaySound(SND_MENU_ITEM_SELECTING);
3794 *ti_ptr = ti->node_parent;
3795 DrawChooseTree(ti_ptr);
3800 if (!anyScrollbarGadgetActive() &&
3801 IN_VIS_FIELD(x, y) &&
3802 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3803 y >= 0 && y < num_page_entries)
3807 if (y != ti->cl_cursor)
3809 PlaySound(SND_MENU_ITEM_ACTIVATING);
3811 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3812 drawChooseTreeCursor(y, TRUE);
3813 drawChooseTreeInfo(ti->cl_first + y, ti);
3820 TreeInfo *node_first, *node_cursor;
3821 int entry_pos = ti->cl_first + y;
3823 PlaySound(SND_MENU_ITEM_SELECTING);
3825 node_first = getTreeInfoFirstGroupEntry(ti);
3826 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3828 if (node_cursor->node_group)
3830 node_cursor->cl_first = ti->cl_first;
3831 node_cursor->cl_cursor = ti->cl_cursor;
3832 *ti_ptr = node_cursor->node_group;
3833 DrawChooseTree(ti_ptr);
3835 else if (node_cursor->parent_link)
3837 *ti_ptr = node_cursor->node_parent;
3838 DrawChooseTree(ti_ptr);
3842 node_cursor->cl_first = ti->cl_first;
3843 node_cursor->cl_cursor = ti->cl_cursor;
3844 *ti_ptr = node_cursor;
3846 if (ti->type == TREE_TYPE_LEVEL_DIR)
3848 LoadLevelSetup_SeriesInfo();
3850 SaveLevelSetup_LastSeries();
3851 SaveLevelSetup_SeriesInfo();
3855 if (game_status == GAME_MODE_SETUP)
3857 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3859 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3860 execSetupGraphics();
3866 game_status = GAME_MODE_MAIN;
3874 void DrawChooseLevel()
3876 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3878 DrawChooseTree(&leveldir_current);
3884 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3886 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3891 void DrawHallOfFame(int highlight_position)
3894 FadeSoundsAndMusic();
3896 /* (this is needed when called from GameEnd() after winning a game) */
3897 KeyboardAutoRepeatOn();
3900 /* (this is needed when called from GameEnd() after winning a game) */
3901 SetDrawDeactivationMask(REDRAW_NONE);
3902 SetDrawBackgroundMask(REDRAW_FIELD);
3904 CloseDoor(DOOR_CLOSE_2);
3906 if (highlight_position < 0)
3907 LoadScore(level_nr);
3909 FadeOut(REDRAW_FIELD);
3916 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3918 FadeIn(REDRAW_FIELD);
3921 static void drawHallOfFameList(int first_entry, int highlight_position)
3925 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3928 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3929 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3930 "HighScores of Level %d", level_nr);
3932 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3934 int entry = first_entry + i;
3935 boolean active = (entry == highlight_position);
3936 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3937 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3938 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3939 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3940 int dx1 = 3 * getFontWidth(font_nr1);
3941 int dx2 = dx1 + getFontWidth(font_nr1);
3942 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3943 int sy = mSY + 64 + i * 32;
3945 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3946 DrawText(mSX + dx1, sy, ".", font_nr1);
3947 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3949 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3950 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3952 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3955 redraw_mask |= REDRAW_FIELD;
3958 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3960 static int first_entry = 0;
3961 static int highlight_position = 0;
3962 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3964 if (button == MB_MENU_INITIALIZE)
3967 highlight_position = mx;
3968 drawHallOfFameList(first_entry, highlight_position);
3973 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3974 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3978 if (first_entry > 0)
3980 first_entry -= step;
3981 if (first_entry < 0)
3984 drawHallOfFameList(first_entry, highlight_position);
3989 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3991 first_entry += step;
3992 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3993 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3995 drawHallOfFameList(first_entry, highlight_position);
3998 else if (button == MB_MENU_LEAVE)
4000 PlaySound(SND_MENU_ITEM_SELECTING);
4002 FadeSound(SND_BACKGROUND_SCORES);
4004 game_status = GAME_MODE_MAIN;
4008 else if (button == MB_MENU_CHOICE)
4010 PlaySound(SND_MENU_ITEM_SELECTING);
4012 FadeSound(SND_BACKGROUND_SCORES);
4013 FadeOut(REDRAW_FIELD);
4015 game_status = GAME_MODE_MAIN;
4017 DrawAndFadeInMainMenu(REDRAW_FIELD);
4020 if (game_status == GAME_MODE_SCORES)
4021 PlayMenuSoundIfLoop();
4027 /* ========================================================================= */
4028 /* setup screen functions */
4029 /* ========================================================================= */
4031 static struct TokenInfo *setup_info;
4032 static int num_setup_info;
4034 static char *screen_mode_text;
4035 static char *game_speed_text;
4036 static char *graphics_set_name;
4037 static char *sounds_set_name;
4038 static char *music_set_name;
4040 static void execSetupMain()
4042 setup_mode = SETUP_MODE_MAIN;
4046 static void execSetupGame()
4048 if (game_speeds == NULL)
4052 for (i = 0; game_speeds_list[i].value != -1; i++)
4054 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4055 char identifier[32], name[32];
4056 int value = game_speeds_list[i].value;
4057 char *text = game_speeds_list[i].text;
4059 ti->node_top = &game_speeds;
4060 ti->sort_priority = 10000 - value;
4062 sprintf(identifier, "%d", value);
4063 sprintf(name, "%s", text);
4065 setString(&ti->identifier, identifier);
4066 setString(&ti->name, name);
4067 setString(&ti->name_sorting, name);
4068 setString(&ti->infotext, "Game Speed");
4070 pushTreeInfo(&game_speeds, ti);
4073 /* sort game speed values to start with slowest game speed */
4074 sortTreeInfo(&game_speeds);
4076 /* set current game speed to configured game speed value */
4077 game_speed_current =
4078 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4080 /* if that fails, set current game speed to reliable default value */
4081 if (game_speed_current == NULL)
4082 game_speed_current =
4083 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4085 /* if that also fails, set current game speed to first available speed */
4086 if (game_speed_current == NULL)
4087 game_speed_current = game_speeds;
4090 setup.game_frame_delay = atoi(game_speed_current->identifier);
4092 /* needed for displaying game speed text instead of identifier */
4093 game_speed_text = game_speed_current->name;
4095 setup_mode = SETUP_MODE_GAME;
4099 static void execSetupChooseGameSpeed()
4101 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4105 static void execSetupEditor()
4107 setup_mode = SETUP_MODE_EDITOR;
4111 static void execSetupGraphics()
4113 if (video.fullscreen_available && screen_modes == NULL)
4117 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4119 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4120 char identifier[32], name[32];
4121 int x = video.fullscreen_modes[i].width;
4122 int y = video.fullscreen_modes[i].height;
4125 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4127 ti->node_top = &screen_modes;
4128 ti->sort_priority = x * 10000 + y;
4130 sprintf(identifier, "%dx%d", x, y);
4131 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4133 setString(&ti->identifier, identifier);
4134 setString(&ti->name, name);
4135 setString(&ti->name_sorting, name);
4136 setString(&ti->infotext, "Fullscreen Mode");
4138 pushTreeInfo(&screen_modes, ti);
4141 /* sort fullscreen modes to start with lowest available screen resolution */
4142 sortTreeInfo(&screen_modes);
4144 /* set current screen mode for fullscreen mode to configured setup value */
4145 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4146 setup.fullscreen_mode);
4148 /* if that fails, set current screen mode to reliable default value */
4149 if (screen_mode_current == NULL)
4150 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4151 DEFAULT_FULLSCREEN_MODE);
4153 /* if that also fails, set current screen mode to first available mode */
4154 if (screen_mode_current == NULL)
4155 screen_mode_current = screen_modes;
4157 if (screen_mode_current == NULL)
4158 video.fullscreen_available = FALSE;
4161 if (video.fullscreen_available)
4163 setup.fullscreen_mode = screen_mode_current->identifier;
4165 /* needed for displaying screen mode name instead of identifier */
4166 screen_mode_text = screen_mode_current->name;
4169 setup_mode = SETUP_MODE_GRAPHICS;
4173 static void execSetupChooseScreenMode()
4175 if (!video.fullscreen_available)
4178 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4182 static void execSetupSound()
4184 setup_mode = SETUP_MODE_SOUND;
4188 static void execSetupArtwork()
4190 setup.graphics_set = artwork.gfx_current->identifier;
4191 setup.sounds_set = artwork.snd_current->identifier;
4192 setup.music_set = artwork.mus_current->identifier;
4194 /* needed if last screen (setup choice) changed graphics, sounds or music */
4195 ReloadCustomArtwork(0);
4197 /* needed for displaying artwork name instead of artwork identifier */
4198 graphics_set_name = artwork.gfx_current->name;
4199 sounds_set_name = artwork.snd_current->name;
4200 music_set_name = artwork.mus_current->name;
4202 setup_mode = SETUP_MODE_ARTWORK;
4206 static void execSetupChooseGraphics()
4208 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4212 static void execSetupChooseSounds()
4214 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4218 static void execSetupChooseMusic()
4220 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4224 static void execSetupInput()
4226 setup_mode = SETUP_MODE_INPUT;
4230 static void execSetupShortcut1()
4232 setup_mode = SETUP_MODE_SHORTCUT_1;
4236 static void execSetupShortcut2()
4238 setup_mode = SETUP_MODE_SHORTCUT_2;
4242 static void execExitSetup()
4244 game_status = GAME_MODE_MAIN;
4248 static void execSaveAndExitSetup()
4254 static struct TokenInfo setup_info_main[] =
4256 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4257 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4258 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4259 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4260 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4261 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4262 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
4263 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
4264 { TYPE_EMPTY, NULL, "" },
4265 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4266 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4271 static struct TokenInfo setup_info_game[] =
4273 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4274 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4275 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4276 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4277 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4278 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4279 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4280 { TYPE_STRING, &game_speed_text, "" },
4281 { TYPE_EMPTY, NULL, "" },
4282 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4287 static struct TokenInfo setup_info_editor[] =
4290 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4291 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4292 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4293 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4294 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4295 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4296 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4297 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4299 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4300 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4301 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4303 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4305 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4306 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4307 { TYPE_EMPTY, NULL, "" },
4309 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4310 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4311 { TYPE_EMPTY, NULL, "" },
4313 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4314 { TYPE_EMPTY, NULL, "" },
4315 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4320 static struct TokenInfo setup_info_graphics[] =
4322 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4323 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4324 { TYPE_STRING, &screen_mode_text, "" },
4325 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
4327 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4328 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4330 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4331 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4332 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4333 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4334 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4335 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4336 { TYPE_EMPTY, NULL, "" },
4337 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4342 static struct TokenInfo setup_info_sound[] =
4344 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4345 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4346 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4347 { TYPE_EMPTY, NULL, "" },
4348 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4353 static struct TokenInfo setup_info_artwork[] =
4355 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4356 { TYPE_STRING, &graphics_set_name, "" },
4357 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4358 { TYPE_STRING, &sounds_set_name, "" },
4359 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4360 { TYPE_STRING, &music_set_name, "" },
4361 { TYPE_EMPTY, NULL, "" },
4363 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4364 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4365 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4367 { TYPE_STRING, NULL, "Override Level Artwork:"},
4368 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4369 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4370 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4372 { TYPE_EMPTY, NULL, "" },
4373 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4378 static struct TokenInfo setup_info_input[] =
4380 { TYPE_SWITCH, NULL, "Player:" },
4381 { TYPE_SWITCH, NULL, "Device:" },
4382 { TYPE_ENTER_MENU, NULL, "" },
4383 { TYPE_EMPTY, NULL, "" },
4384 { TYPE_EMPTY, NULL, "" },
4385 { TYPE_EMPTY, NULL, "" },
4386 { TYPE_EMPTY, NULL, "" },
4387 { TYPE_EMPTY, NULL, "" },
4388 { TYPE_EMPTY, NULL, "" },
4389 { TYPE_EMPTY, NULL, "" },
4390 { TYPE_EMPTY, NULL, "" },
4391 { TYPE_EMPTY, NULL, "" },
4392 { TYPE_EMPTY, NULL, "" },
4393 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4398 static struct TokenInfo setup_info_shortcut_1[] =
4400 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4401 { TYPE_KEY, &setup.shortcut.save_game, "" },
4402 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4403 { TYPE_KEY, &setup.shortcut.load_game, "" },
4404 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4405 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4406 { TYPE_EMPTY, NULL, "" },
4407 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4408 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4409 { TYPE_EMPTY, NULL, "" },
4410 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4415 static struct TokenInfo setup_info_shortcut_2[] =
4417 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4418 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4419 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4420 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4421 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4422 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4423 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4424 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4425 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4426 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4427 { TYPE_EMPTY, NULL, "" },
4428 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4433 static Key getSetupKey()
4435 Key key = KSYM_UNDEFINED;
4436 boolean got_key_event = FALSE;
4438 while (!got_key_event)
4440 if (PendingEvent()) /* got event */
4448 case EVENT_KEYPRESS:
4450 key = GetEventKey((KeyEvent *)&event, TRUE);
4452 /* press 'Escape' or 'Enter' to keep the existing key binding */
4453 if (key == KSYM_Escape || key == KSYM_Return)
4454 key = KSYM_UNDEFINED; /* keep old value */
4456 got_key_event = TRUE;
4460 case EVENT_KEYRELEASE:
4461 key_joystick_mapping = 0;
4465 HandleOtherEvents(&event);
4473 /* don't eat all CPU time */
4480 static int getSetupTextFont(int type)
4482 if (type & (TYPE_SWITCH |
4493 static int getSetupValueFont(int type, void *value)
4495 if (type & TYPE_KEY)
4496 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4497 else if (type & TYPE_STRING)
4498 return FONT_VALUE_2;
4499 else if (type & TYPE_ECS_AGA)
4500 return FONT_VALUE_1;
4501 else if (type & TYPE_BOOLEAN_STYLE)
4502 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4504 return FONT_VALUE_1;
4507 static void drawSetupValue(int pos)
4509 boolean font_draw_xoffset_modified = FALSE;
4510 int font_draw_xoffset_old = -1;
4511 int xpos = MENU_SCREEN_VALUE_XPOS;
4512 int ypos = MENU_SCREEN_START_YPOS + pos;
4513 int startx = mSX + xpos * 32;
4514 int starty = mSY + ypos * 32;
4515 int font_nr, font_width;
4516 int type = setup_info[pos].type;
4517 void *value = setup_info[pos].value;
4518 char *value_string = getSetupValue(type, value);
4521 if (value_string == NULL)
4524 if (type & TYPE_KEY)
4526 xpos = MENU_SCREEN_START_XPOS;
4528 if (type & TYPE_QUERY)
4530 value_string = "<press key>";
4533 else if (type & TYPE_STRING)
4535 int max_value_len = (SCR_FIELDX - 2) * 2;
4537 xpos = MENU_SCREEN_START_XPOS;
4539 if (strlen(value_string) > max_value_len)
4540 value_string[max_value_len] = '\0';
4543 startx = mSX + xpos * 32;
4544 starty = mSY + ypos * 32;
4545 font_nr = getSetupValueFont(type, value);
4546 font_width = getFontWidth(font_nr);
4548 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4549 if (setup_mode != SETUP_MODE_INPUT)
4551 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4552 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4553 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4554 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4555 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4556 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4557 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4558 boolean correct_font_draw_xoffset = FALSE;
4560 if (xpos == MENU_SCREEN_START_XPOS &&
4561 startx + font1_xoffset < text_startx + text_font_xoffset)
4562 correct_font_draw_xoffset = TRUE;
4564 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4565 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4566 correct_font_draw_xoffset = TRUE;
4568 /* check if setup value would overlap with setup text when printed */
4569 /* (this can happen for extreme/wrong values for font draw offset) */
4570 if (correct_font_draw_xoffset)
4572 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4573 font_draw_xoffset_modified = TRUE;
4575 if (type & TYPE_KEY)
4576 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4577 else if (!(type & TYPE_STRING))
4578 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4579 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4583 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4584 DrawText(startx + i * font_width, starty, " ", font_nr);
4586 DrawText(startx, starty, value_string, font_nr);
4588 if (font_draw_xoffset_modified)
4589 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4592 static void changeSetupValue(int pos)
4594 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4596 *(boolean *)setup_info[pos].value ^= TRUE;
4598 else if (setup_info[pos].type & TYPE_KEY)
4602 setup_info[pos].type |= TYPE_QUERY;
4603 drawSetupValue(pos);
4604 setup_info[pos].type &= ~TYPE_QUERY;
4606 key = getSetupKey();
4607 if (key != KSYM_UNDEFINED)
4608 *(Key *)setup_info[pos].value = key;
4611 drawSetupValue(pos);
4614 static void DrawCursorAndText_Setup(int pos, boolean active)
4616 int xpos = MENU_SCREEN_START_XPOS;
4617 int ypos = MENU_SCREEN_START_YPOS + pos;
4618 int font_nr = getSetupTextFont(setup_info[pos].type);
4620 if (setup_info == setup_info_input)
4621 font_nr = FONT_MENU_1;
4624 font_nr = FONT_ACTIVE(font_nr);
4626 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4628 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4629 drawCursor(pos, active);
4632 static void DrawSetupScreen_Generic()
4634 char *title_string = NULL;
4638 CloseDoor(DOOR_CLOSE_2);
4642 if (setup_mode == SETUP_MODE_MAIN)
4644 setup_info = setup_info_main;
4645 title_string = "Setup";
4647 else if (setup_mode == SETUP_MODE_GAME)
4649 setup_info = setup_info_game;
4650 title_string = "Setup Game";
4652 else if (setup_mode == SETUP_MODE_EDITOR)
4654 setup_info = setup_info_editor;
4655 title_string = "Setup Editor";
4657 else if (setup_mode == SETUP_MODE_GRAPHICS)
4659 setup_info = setup_info_graphics;
4660 title_string = "Setup Graphics";
4662 else if (setup_mode == SETUP_MODE_SOUND)
4664 setup_info = setup_info_sound;
4665 title_string = "Setup Sound";
4667 else if (setup_mode == SETUP_MODE_ARTWORK)
4669 setup_info = setup_info_artwork;
4670 title_string = "Custom Artwork";
4672 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
4674 setup_info = setup_info_shortcut_1;
4675 title_string = "Setup Shortcuts";
4677 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
4679 setup_info = setup_info_shortcut_2;
4680 title_string = "Setup Shortcuts";
4683 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4686 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4688 void *value_ptr = setup_info[i].value;
4691 int xpos = MENU_SCREEN_START_XPOS;
4692 int ypos = MENU_SCREEN_START_YPOS + i;
4696 /* set some entries to "unchangeable" according to other variables */
4697 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4698 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4699 (value_ptr == &setup.sound_music && !audio.music_available) ||
4700 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4701 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4702 setup_info[i].type |= TYPE_GHOSTED;
4704 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4705 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4706 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4707 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4708 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4709 initCursor(i, IMG_MENU_BUTTON);
4712 DrawCursorAndText_Setup(i, FALSE);
4714 font_nr = getSetupTextFont(setup_info[i].type);
4716 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
4719 if (setup_info[i].type & TYPE_VALUE)
4726 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4727 "Joysticks deactivated in setup menu");
4732 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4735 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4737 static int choice_store[MAX_SETUP_MODES];
4738 int choice = choice_store[setup_mode]; /* always starts with 0 */
4742 if (button == MB_MENU_INITIALIZE)
4744 /* advance to first valid menu entry */
4745 while (choice < num_setup_info &&
4746 setup_info[choice].type & TYPE_SKIP_ENTRY)
4748 choice_store[setup_mode] = choice;
4751 DrawCursorAndText_Setup(choice, TRUE);
4753 drawCursor(choice, TRUE);
4758 else if (button == MB_MENU_LEAVE)
4760 PlaySound(SND_MENU_ITEM_SELECTING);
4762 for (y = 0; y < num_setup_info; y++)
4764 if (setup_info[y].type & TYPE_LEAVE_MENU)
4766 void (*menu_callback_function)(void) = setup_info[y].value;
4768 menu_callback_function();
4770 break; /* absolutely needed because function changes 'setup_info'! */
4777 if (mx || my) /* mouse input */
4779 x = (mx - mSX) / 32;
4780 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4782 else if (dx || dy) /* keyboard input */
4786 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4788 if (setup_info[choice].type & menu_navigation_type ||
4789 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
4790 button = MB_MENU_CHOICE;
4795 /* jump to next non-empty menu entry (up or down) */
4796 while (y > 0 && y < num_setup_info - 1 &&
4797 setup_info[y].type & TYPE_SKIP_ENTRY)
4801 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4805 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4807 PlaySound(SND_MENU_ITEM_ACTIVATING);
4810 DrawCursorAndText_Setup(choice, FALSE);
4811 DrawCursorAndText_Setup(y, TRUE);
4813 drawCursor(choice, FALSE);
4814 drawCursor(y, TRUE);
4817 choice = choice_store[setup_mode] = y;
4820 else if (!(setup_info[y].type & TYPE_GHOSTED))
4822 PlaySound(SND_MENU_ITEM_SELECTING);
4824 /* when selecting key headline, execute function for key value change */
4825 if (setup_info[y].type & TYPE_KEYTEXT &&
4826 setup_info[y + 1].type & TYPE_KEY)
4829 /* when selecting string value, execute function for list selection */
4830 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4831 setup_info[y - 1].type & TYPE_ENTER_LIST)
4834 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4836 void (*menu_callback_function)(void) = setup_info[y].value;
4838 menu_callback_function();
4842 if (setup_info[y].type & TYPE_VALUE)
4843 changeSetupValue(y);
4849 void DrawSetupScreen_Input()
4858 setup_info = setup_info_input;
4861 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4864 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4866 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4867 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4868 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4869 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4870 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4871 initCursor(i, IMG_MENU_BUTTON);
4873 DrawCursorAndText_Setup(i, FALSE);
4876 initCursor(0, IMG_MENU_BUTTON);
4877 initCursor(1, IMG_MENU_BUTTON);
4878 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
4879 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
4881 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
4882 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
4883 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
4887 DeactivateJoystickForCalibration();
4890 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4891 "Joysticks deactivated on this screen");
4894 /* create gadgets for setup input menu screen */
4895 FreeScreenGadgets();
4896 CreateScreenGadgets();
4898 /* map gadgets for setup input menu screen */
4899 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4901 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4906 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4908 if (device_name == NULL)
4911 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4914 if (strlen(device_name) > 1)
4916 char c1 = device_name[strlen(device_name) - 1];
4917 char c2 = device_name[strlen(device_name) - 2];
4919 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4920 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4923 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4924 strlen(device_name));
4927 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4930 static struct SetupKeyboardInfo custom_key;
4937 { &custom_key.left, "Joystick Left" },
4938 { &custom_key.right, "Joystick Right" },
4939 { &custom_key.up, "Joystick Up" },
4940 { &custom_key.down, "Joystick Down" },
4941 { &custom_key.snap, "Button 1" },
4942 { &custom_key.drop, "Button 2" }
4944 static char *joystick_name[MAX_PLAYERS] =
4951 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4955 custom_key = setup.input[player_nr].key;
4957 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4958 FONT_INPUT_1_ACTIVE);
4960 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4962 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4963 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4965 if (setup.input[player_nr].use_joystick)
4967 char *device_name = setup.input[player_nr].joy.device_name;
4968 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4969 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4971 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4972 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4976 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4977 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4980 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4982 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4983 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4984 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4985 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4987 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4988 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4989 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4990 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4991 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4992 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4994 for (i = 0; i < 6; i++)
4996 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4998 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5000 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5001 (setup.input[player_nr].use_joystick ?
5003 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5007 static int input_player_nr = 0;
5009 void HandleSetupScreen_Input_Player(int step, int direction)
5011 int old_player_nr = input_player_nr;
5014 new_player_nr = old_player_nr + step * direction;
5015 if (new_player_nr < 0)
5017 if (new_player_nr > MAX_PLAYERS - 1)
5018 new_player_nr = MAX_PLAYERS - 1;
5020 if (new_player_nr != old_player_nr)
5022 input_player_nr = new_player_nr;
5024 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5028 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5030 static int choice = 0;
5033 int pos_start = SETUPINPUT_SCREEN_POS_START;
5034 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5035 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5036 int pos_end = SETUPINPUT_SCREEN_POS_END;
5038 if (button == MB_MENU_INITIALIZE)
5040 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5043 DrawCursorAndText_Setup(choice, TRUE);
5045 drawCursor(choice, TRUE);
5050 else if (button == MB_MENU_LEAVE)
5052 setup_mode = SETUP_MODE_MAIN;
5059 if (mx || my) /* mouse input */
5061 x = (mx - mSX) / 32;
5062 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5064 else if (dx || dy) /* keyboard input */
5066 if (dx && choice == 0)
5067 x = (dx < 0 ? 10 : 12);
5068 else if ((dx && choice == 1) ||
5069 (dx == +1 && choice == 2) ||
5070 (dx == -1 && choice == pos_end))
5071 button = MB_MENU_CHOICE;
5075 if (y >= pos_empty1 && y <= pos_empty2)
5076 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5079 if (y == 0 && dx != 0 && button)
5081 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5083 else if (IN_VIS_FIELD(x, y) &&
5084 y >= pos_start && y <= pos_end &&
5085 !(y >= pos_empty1 && y <= pos_empty2))
5092 DrawCursorAndText_Setup(choice, FALSE);
5093 DrawCursorAndText_Setup(y, TRUE);
5095 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5097 drawCursor(choice, FALSE);
5098 drawCursor(y, TRUE);
5108 char *device_name = setup.input[input_player_nr].joy.device_name;
5110 if (!setup.input[input_player_nr].use_joystick)
5112 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5114 setJoystickDeviceToNr(device_name, new_device_nr);
5115 setup.input[input_player_nr].use_joystick = TRUE;
5119 int device_nr = getJoystickNrFromDeviceName(device_name);
5120 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5122 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5123 setup.input[input_player_nr].use_joystick = FALSE;
5125 setJoystickDeviceToNr(device_name, new_device_nr);
5128 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5132 if (setup.input[input_player_nr].use_joystick)
5135 CalibrateJoystick(input_player_nr);
5138 CustomizeKeyboard(input_player_nr);
5140 else if (y == pos_end)
5144 setup_mode = SETUP_MODE_MAIN;
5151 void CustomizeKeyboard(int player_nr)
5155 boolean finished = FALSE;
5156 static struct SetupKeyboardInfo custom_key;
5161 } customize_step[] =
5163 { &custom_key.left, "Move Left" },
5164 { &custom_key.right, "Move Right" },
5165 { &custom_key.up, "Move Up" },
5166 { &custom_key.down, "Move Down" },
5167 { &custom_key.snap, "Snap Field" },
5168 { &custom_key.drop, "Drop Element" }
5171 /* read existing key bindings from player setup */
5172 custom_key = setup.input[player_nr].key;
5176 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5182 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5183 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5184 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5185 "Key:", FONT_INPUT_1_ACTIVE);
5186 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5187 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5191 if (PendingEvent()) /* got event */
5199 case EVENT_KEYPRESS:
5201 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5203 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5209 /* all keys configured -- wait for "Escape" or "Return" key */
5213 /* press 'Enter' to keep the existing key binding */
5214 if (key == KSYM_Return)
5215 key = *customize_step[step_nr].key;
5217 /* check if key already used */
5218 for (i = 0; i < step_nr; i++)
5219 if (*customize_step[i].key == key)
5224 /* got new key binding */
5225 *customize_step[step_nr].key = key;
5226 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5228 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5229 getKeyNameFromKey(key), FONT_VALUE_1);
5232 /* un-highlight last query */
5233 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5234 customize_step[step_nr - 1].text, FONT_MENU_1);
5235 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5236 "Key:", FONT_MENU_1);
5238 /* press 'Enter' to leave */
5241 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5242 "Press Enter", FONT_TITLE_1);
5246 /* query next key binding */
5247 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5248 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5249 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5250 "Key:", FONT_INPUT_1_ACTIVE);
5251 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5252 getKeyNameFromKey(*customize_step[step_nr].key),
5257 case EVENT_KEYRELEASE:
5258 key_joystick_mapping = 0;
5262 HandleOtherEvents(&event);
5270 /* don't eat all CPU time */
5274 /* write new key bindings back to player setup */
5275 setup.input[player_nr].key = custom_key;
5278 DrawSetupScreen_Input();
5281 static boolean CalibrateJoystickMain(int player_nr)
5283 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5284 int new_joystick_xright = JOYSTICK_XMIDDLE;
5285 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5286 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5287 int new_joystick_xmiddle, new_joystick_ymiddle;
5289 int joystick_fd = joystick.fd[player_nr];
5290 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5291 boolean check[3][3];
5292 int check_remaining = 3 * 3;
5297 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5300 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5305 for (y = 0; y < 3; y++)
5307 for (x = 0; x < 3; x++)
5309 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5310 check[x][y] = FALSE;
5314 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5315 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5316 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5317 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5318 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5319 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5320 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5322 joy_value = Joystick(player_nr);
5323 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5324 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5326 /* eventually uncalibrated center position (joystick could be uncentered) */
5327 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5330 new_joystick_xmiddle = joy_x;
5331 new_joystick_ymiddle = joy_y;
5333 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5336 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5341 if (PendingEvent()) /* got event */
5349 case EVENT_KEYPRESS:
5350 switch (GetEventKey((KeyEvent *)&event, TRUE))
5353 if (check_remaining == 0)
5366 case EVENT_KEYRELEASE:
5367 key_joystick_mapping = 0;
5371 HandleOtherEvents(&event);
5376 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5379 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5380 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5381 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5382 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5384 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5385 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5386 setup.input[player_nr].joy.xright = new_joystick_xright;
5387 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5388 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5389 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5391 CheckJoystickData();
5393 joy_value = Joystick(player_nr);
5395 if (joy_value & JOY_BUTTON && check_remaining == 0)
5398 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5399 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5401 if (x != last_x || y != last_y)
5403 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5404 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5409 if (check_remaining > 0 && !check[x+1][y+1])
5411 check[x+1][y+1] = TRUE;
5417 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5418 setup.input[player_nr].joy.xleft,
5419 setup.input[player_nr].joy.xmiddle,
5420 setup.input[player_nr].joy.xright);
5421 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5422 setup.input[player_nr].joy.yupper,
5423 setup.input[player_nr].joy.ymiddle,
5424 setup.input[player_nr].joy.ylower);
5433 /* don't eat all CPU time */
5437 /* calibrated center position (joystick should now be centered) */
5438 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5441 new_joystick_xmiddle = joy_x;
5442 new_joystick_ymiddle = joy_y;
5447 DrawSetupScreen_Input();
5450 /* wait until the last pressed button was released */
5451 while (Joystick(player_nr) & JOY_BUTTON)
5453 if (PendingEvent()) /* got event */
5458 HandleOtherEvents(&event);
5467 void CalibrateJoystick(int player_nr)
5469 if (!CalibrateJoystickMain(player_nr))
5471 char *device_name = setup.input[player_nr].joy.device_name;
5472 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5473 int xpos = mSX - SX;
5474 int ypos = mSY - SY;
5478 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5479 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5482 Delay(2000); /* show error message for a short time */
5488 DrawSetupScreen_Input();
5492 void DrawSetupScreen()
5494 DeactivateJoystick();
5496 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5498 if (setup_mode == SETUP_MODE_INPUT)
5499 DrawSetupScreen_Input();
5500 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5501 DrawChooseTree(&game_speed_current);
5502 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5503 DrawChooseTree(&screen_mode_current);
5504 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5505 DrawChooseTree(&artwork.gfx_current);
5506 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5507 DrawChooseTree(&artwork.snd_current);
5508 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5509 DrawChooseTree(&artwork.mus_current);
5511 DrawSetupScreen_Generic();
5517 void RedrawSetupScreenAfterFullscreenToggle()
5519 if (setup_mode == SETUP_MODE_GRAPHICS)
5523 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5525 if (setup_mode == SETUP_MODE_INPUT)
5526 HandleSetupScreen_Input(mx, my, dx, dy, button);
5527 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5528 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5529 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5530 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5531 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5532 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5533 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5534 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5535 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5536 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5538 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5543 void HandleGameActions()
5545 if (game_status != GAME_MODE_PLAYING)
5548 GameActions(); /* main game loop */
5550 if (tape.auto_play && !tape.playing)
5551 AutoPlayTape(); /* continue automatically playing next tape */
5555 /* ---------- new screen button stuff -------------------------------------- */
5557 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5562 case SCREEN_CTRL_ID_PREV_LEVEL:
5563 *x = mSX + menu.main.button.prev_level.x;
5564 *y = mSY + menu.main.button.prev_level.y;
5567 case SCREEN_CTRL_ID_NEXT_LEVEL:
5568 *x = mSX + menu.main.button.next_level.x;
5569 *y = mSY + menu.main.button.next_level.y;
5572 case SCREEN_CTRL_ID_PREV_LEVEL:
5573 *x = mSX + TILEX * getPrevlevelButtonPos();
5574 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5577 case SCREEN_CTRL_ID_NEXT_LEVEL:
5578 *x = mSX + TILEX * getNextLevelButtonPos();
5579 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5583 case SCREEN_CTRL_ID_PREV_PLAYER:
5584 *x = mSX + TILEX * 10;
5585 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5588 case SCREEN_CTRL_ID_NEXT_PLAYER:
5589 *x = mSX + TILEX * 12;
5590 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5594 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5600 int gfx_unpressed, gfx_pressed;
5601 void (*get_gadget_position)(int *, int *, int);
5605 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5608 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5609 getScreenMenuButtonPos,
5610 SCREEN_CTRL_ID_PREV_LEVEL,
5615 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5616 getScreenMenuButtonPos,
5617 SCREEN_CTRL_ID_NEXT_LEVEL,
5622 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5623 getScreenMenuButtonPos,
5624 SCREEN_CTRL_ID_PREV_PLAYER,
5629 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5630 getScreenMenuButtonPos,
5631 SCREEN_CTRL_ID_NEXT_PLAYER,
5639 int gfx_unpressed, gfx_pressed;
5643 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5646 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5647 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5648 SCREEN_CTRL_ID_SCROLL_UP,
5652 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5653 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5654 SCREEN_CTRL_ID_SCROLL_DOWN,
5661 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5662 Bitmap **gfx_unpressed, **gfx_pressed;
5664 int gfx_unpressed, gfx_pressed;
5671 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5674 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5675 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5677 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5679 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5680 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5681 GD_TYPE_SCROLLBAR_VERTICAL,
5682 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5683 "scroll level series vertically"
5687 static void CreateScreenMenubuttons()
5689 struct GadgetInfo *gi;
5690 unsigned long event_mask;
5693 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5695 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5696 int gfx_unpressed, gfx_pressed;
5697 int x, y, width, height;
5698 int gd_x1, gd_x2, gd_y1, gd_y2;
5699 int id = menubutton_info[i].gadget_id;
5701 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5703 menubutton_info[i].get_gadget_position(&x, &y, id);
5705 width = SC_MENUBUTTON_XSIZE;
5706 height = SC_MENUBUTTON_YSIZE;
5708 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5709 gfx_pressed = menubutton_info[i].gfx_pressed;
5710 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5711 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5712 gd_x1 = graphic_info[gfx_unpressed].src_x;
5713 gd_y1 = graphic_info[gfx_unpressed].src_y;
5714 gd_x2 = graphic_info[gfx_pressed].src_x;
5715 gd_y2 = graphic_info[gfx_pressed].src_y;
5717 gi = CreateGadget(GDI_CUSTOM_ID, id,
5718 GDI_CUSTOM_TYPE_ID, i,
5719 GDI_INFO_TEXT, menubutton_info[i].infotext,
5724 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5725 GDI_STATE, GD_BUTTON_UNPRESSED,
5726 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5727 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5728 GDI_DIRECT_DRAW, FALSE,
5729 GDI_EVENT_MASK, event_mask,
5730 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5734 Error(ERR_EXIT, "cannot create gadget");
5736 screen_gadget[id] = gi;
5740 static void CreateScreenScrollbuttons()
5742 struct GadgetInfo *gi;
5743 unsigned long event_mask;
5746 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5748 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5749 int gfx_unpressed, gfx_pressed;
5750 int x, y, width, height;
5751 int gd_x1, gd_x2, gd_y1, gd_y2;
5752 int id = scrollbutton_info[i].gadget_id;
5754 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5756 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5757 y = mSY + scrollbutton_info[i].y;
5758 width = SC_SCROLLBUTTON_XSIZE;
5759 height = SC_SCROLLBUTTON_YSIZE;
5761 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5762 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5763 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5765 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5766 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5767 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5768 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5769 gd_x1 = graphic_info[gfx_unpressed].src_x;
5770 gd_y1 = graphic_info[gfx_unpressed].src_y;
5771 gd_x2 = graphic_info[gfx_pressed].src_x;
5772 gd_y2 = graphic_info[gfx_pressed].src_y;
5774 gi = CreateGadget(GDI_CUSTOM_ID, id,
5775 GDI_CUSTOM_TYPE_ID, i,
5776 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5781 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5782 GDI_STATE, GD_BUTTON_UNPRESSED,
5783 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5784 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5785 GDI_DIRECT_DRAW, FALSE,
5786 GDI_EVENT_MASK, event_mask,
5787 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5791 Error(ERR_EXIT, "cannot create gadget");
5793 screen_gadget[id] = gi;
5797 static void CreateScreenScrollbars()
5801 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5803 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5804 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5805 int gfx_unpressed, gfx_pressed;
5807 int x, y, width, height;
5808 int gd_x1, gd_x2, gd_y1, gd_y2;
5809 struct GadgetInfo *gi;
5810 int items_max, items_visible, item_position;
5811 unsigned long event_mask;
5812 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5813 int id = scrollbar_info[i].gadget_id;
5815 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5817 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5818 y = mSY + scrollbar_info[i].y;
5819 width = scrollbar_info[i].width;
5820 height = scrollbar_info[i].height;
5822 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5823 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5825 items_max = num_page_entries;
5826 items_visible = num_page_entries;
5829 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5830 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5831 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5837 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5838 gfx_pressed = scrollbar_info[i].gfx_pressed;
5839 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5840 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5841 gd_x1 = graphic_info[gfx_unpressed].src_x;
5842 gd_y1 = graphic_info[gfx_unpressed].src_y;
5843 gd_x2 = graphic_info[gfx_pressed].src_x;
5844 gd_y2 = graphic_info[gfx_pressed].src_y;
5847 gi = CreateGadget(GDI_CUSTOM_ID, id,
5848 GDI_CUSTOM_TYPE_ID, i,
5849 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5854 GDI_TYPE, scrollbar_info[i].type,
5855 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5856 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5857 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5859 GDI_WHEEL_AREA_X, SX,
5860 GDI_WHEEL_AREA_Y, SY,
5861 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5862 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5864 GDI_WHEEL_AREA_X, 0,
5865 GDI_WHEEL_AREA_Y, 0,
5866 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5867 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5869 GDI_STATE, GD_BUTTON_UNPRESSED,
5870 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5871 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5872 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5873 GDI_DIRECT_DRAW, FALSE,
5874 GDI_EVENT_MASK, event_mask,
5875 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5879 Error(ERR_EXIT, "cannot create gadget");
5881 screen_gadget[id] = gi;
5885 void CreateScreenGadgets()
5887 int last_game_status = game_status; /* save current game status */
5889 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5892 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5894 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5896 /* copy pointers to clip mask and GC */
5897 scrollbar_bitmap[i]->clip_mask =
5898 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5899 scrollbar_bitmap[i]->stored_clip_gc =
5900 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5902 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5903 scrollbar_bitmap[i],
5904 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5905 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5906 TILEX, TILEY, 0, 0);
5910 CreateScreenMenubuttons();
5912 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5913 game_status = GAME_MODE_LEVELS;
5915 CreateScreenScrollbuttons();
5916 CreateScreenScrollbars();
5918 game_status = last_game_status; /* restore current game status */
5921 void FreeScreenGadgets()
5925 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5926 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5928 /* prevent freeing clip mask and GC twice */
5929 scrollbar_bitmap[i]->clip_mask = None;
5930 scrollbar_bitmap[i]->stored_clip_gc = None;
5932 FreeBitmap(scrollbar_bitmap[i]);
5936 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5937 FreeGadget(screen_gadget[i]);
5940 void MapScreenMenuGadgets(int screen_mask)
5944 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5945 if (screen_mask & menubutton_info[i].screen_mask)
5946 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5949 void MapScreenTreeGadgets(TreeInfo *ti)
5951 int num_entries = numTreeInfoInGroup(ti);
5954 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5957 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5958 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5960 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5961 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5964 static void HandleScreenGadgets(struct GadgetInfo *gi)
5966 int id = gi->custom_id;
5967 int button = gi->event.button;
5968 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5972 case SCREEN_CTRL_ID_PREV_LEVEL:
5973 HandleMainMenu_SelectLevel(step, -1);
5976 case SCREEN_CTRL_ID_NEXT_LEVEL:
5977 HandleMainMenu_SelectLevel(step, +1);
5980 case SCREEN_CTRL_ID_PREV_PLAYER:
5981 HandleSetupScreen_Input_Player(step, -1);
5984 case SCREEN_CTRL_ID_NEXT_PLAYER:
5985 HandleSetupScreen_Input_Player(step, +1);
5988 case SCREEN_CTRL_ID_SCROLL_UP:
5989 if (game_status == GAME_MODE_LEVELS)
5990 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5991 else if (game_status == GAME_MODE_SETUP)
5992 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5995 case SCREEN_CTRL_ID_SCROLL_DOWN:
5996 if (game_status == GAME_MODE_LEVELS)
5997 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5998 else if (game_status == GAME_MODE_SETUP)
5999 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6002 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6003 if (game_status == GAME_MODE_LEVELS)
6004 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6005 else if (game_status == GAME_MODE_SETUP)
6006 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);