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_TITLE_INITIAL : GAME_MODE_TITLE);
510 static int getTitleScreenBackground(boolean initial)
512 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
517 static int getTitleMessageBackground(int nr, boolean initial)
519 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
523 static int getTitleBackground(int nr, boolean initial, boolean is_image)
525 int base = (is_image ?
526 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
527 IMG_BACKGROUND_TITLESCREEN_1) :
528 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
529 IMG_BACKGROUND_TITLEMESSAGE_1));
530 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
531 IMG_BACKGROUND_TITLE);
532 int graphic_local = base + nr;
534 if (graphic_info[graphic_local].bitmap != NULL)
535 return graphic_local;
537 if (graphic_info[graphic_global].bitmap != NULL)
538 return graphic_global;
540 return IMG_UNDEFINED;
543 static int getTitleSound(int nr, boolean initial, boolean is_image)
545 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
546 int base = (is_image ?
547 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
548 SND_BACKGROUND_TITLESCREEN_1) :
549 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
550 SND_BACKGROUND_TITLEMESSAGE_1));
551 int sound_global = menu.sound[mode];
552 int sound_local = base + nr;
555 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
556 nr, initial, is_image,
557 sound_global, getSoundListEntry(sound_global)->filename,
558 sound_local, getSoundListEntry(sound_local)->filename);
561 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
564 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
567 return SND_UNDEFINED;
570 static int getTitleMusic(int nr, boolean initial, boolean is_image)
572 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
573 int base = (is_image ?
574 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
575 MUS_BACKGROUND_TITLESCREEN_1) :
576 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
577 MUS_BACKGROUND_TITLEMESSAGE_1));
578 int music_global = menu.music[mode];
579 int music_local = base + nr;
582 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
583 nr, initial, is_image,
584 music_global, getMusicListEntry(music_global)->filename,
585 music_local, getMusicListEntry(music_local)->filename);
588 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
591 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
594 return MUS_UNDEFINED;
597 static int compareTitleControlInfo(const void *object1, const void *object2)
599 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
600 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
603 if (tci1->initial != tci2->initial)
604 compare_result = (tci1->initial ? -1 : +1);
605 else if (tci1->sort_priority != tci2->sort_priority)
606 compare_result = tci1->sort_priority - tci2->sort_priority;
607 else if (tci1->is_image != tci2->is_image)
608 compare_result = (tci1->is_image ? -1 : +1);
610 compare_result = tci1->local_nr - tci2->local_nr;
612 return compare_result;
615 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
617 int nr, int sort_priority)
619 title_controls[num_title_screens].is_image = is_image;
620 title_controls[num_title_screens].initial = initial;
621 title_controls[num_title_screens].local_nr = nr;
622 title_controls[num_title_screens].sort_priority = sort_priority;
627 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
631 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
633 int graphic = getTitleScreenGraphic(i, initial);
634 Bitmap *bitmap = graphic_info[graphic].bitmap;
635 int sort_priority = graphic_info[graphic].sort_priority;
638 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
641 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
643 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
644 char *filename = getLevelSetTitleMessageFilename(i, initial);
645 int sort_priority = tmi->sort_priority;
647 if (filename != NULL)
648 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
652 static void InitializeTitleControls(boolean show_title_initial)
654 num_title_screens = 0;
656 if (show_title_initial)
657 InitializeTitleControls_CheckTitleInfo(TRUE);
659 InitializeTitleControls_CheckTitleInfo(FALSE);
661 /* sort title screens according to sort_priority and title number */
662 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
663 compareTitleControlInfo);
666 static boolean visibleMenuPos(struct MenuPosInfo *pos)
668 return (pos != NULL && pos->x != -1 && pos->y != -1);
671 static boolean visibleTextPos(struct TextPosInfo *pos)
673 return (pos != NULL && pos->x != -1 && pos->y != -1);
676 static void InitializeMainControls()
678 boolean local_team_mode = (!options.network && setup.team_mode);
681 /* set main control text values to dynamically determined values */
682 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
683 sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
684 sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
685 sprintf(main_text_level_number, "%s", int2str(level_nr, 3));
687 main_text_level_year = leveldir_current->year;
688 main_text_level_imported_from = leveldir_current->imported_from;
689 main_text_level_imported_by = leveldir_current->imported_by;
690 main_text_level_tested_by = leveldir_current->tested_by;
692 /* set main control screen positions to dynamically determined values */
693 for (i = 0; main_controls[i].nr != -1; i++)
695 struct MainControlInfo *mci = &main_controls[i];
697 struct MenuPosInfo *pos_button = mci->pos_button;
698 struct TextPosInfo *pos_text = mci->pos_text;
699 struct TextPosInfo *pos_input = mci->pos_input;
700 char *text = (mci->text ? *mci->text : NULL);
701 char *input = (mci->input ? *mci->input : NULL);
702 int button_graphic = mci->button_graphic;
704 int font_text = (pos_text ? pos_text->font : -1);
705 int font_input = (pos_input ? pos_input->font : -1);
707 int font_text = mci->font_text;
708 int font_input = mci->font_input;
711 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
712 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
713 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
714 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
715 int text_chars = (text != NULL ? strlen(text) : 0);
716 int input_chars = (input != NULL ? strlen(input) : 0);
719 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
721 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
722 int text_width = font_text_width * text_chars;
723 int text_height = font_text_height;
724 int input_width = font_input_width * input_chars;
725 int input_height = font_input_height;
727 if (nr == MAIN_CONTROL_NAME)
730 if (menu.main.input.name.x == -1)
731 menu.main.input.name.x = menu.main.text.name.x + text_width;
732 if (menu.main.input.name.y == -1)
733 menu.main.input.name.y = menu.main.text.name.y;
737 menu.main.input.name.width = input_width;
738 menu.main.input.name.height = input_height;
740 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
741 menu.main.input.name.height = font_input_height;
745 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
747 if (pos_button->width == 0)
748 pos_button->width = button_width;
749 if (pos_button->height == 0)
750 pos_button->height = button_height;
753 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
755 /* calculate width for non-clickable text -- needed for text alignment */
756 boolean calculate_text_width = (pos_button == NULL && text != NULL);
758 if (visibleMenuPos(pos_button))
760 if (pos_text->x == -1)
761 pos_text->x = pos_button->x + pos_button->width;
762 if (pos_text->y == -1)
763 pos_text->y = pos_button->y;
766 if (pos_text->width == -1 || calculate_text_width)
767 pos_text->width = text_width;
768 if (pos_text->height == -1)
769 pos_text->height = text_height;
772 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
774 if (visibleTextPos(pos_text))
776 if (pos_input->x == -1)
777 pos_input->x = pos_text->x + pos_text->width;
778 if (pos_input->y == -1)
779 pos_input->y = pos_text->y;
782 if (pos_input->width == -1)
783 pos_input->width = input_width;
784 if (pos_input->height == -1)
785 pos_input->height = input_height;
790 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
791 boolean active_input)
795 for (i = 0; main_controls[i].nr != -1; i++)
797 struct MainControlInfo *mci = &main_controls[i];
799 if (mci->nr == nr || nr == -1)
801 struct MenuPosInfo *pos_button = mci->pos_button;
802 struct TextPosInfo *pos_text = mci->pos_text;
803 struct TextPosInfo *pos_input = mci->pos_input;
804 char *text = (mci->text ? *mci->text : NULL);
805 char *input = (mci->input ? *mci->input : NULL);
806 int button_graphic = mci->button_graphic;
808 int font_text = (pos_text ? pos_text->font : -1);
809 int font_input = (pos_input ? pos_input->font : -1);
811 int font_text = mci->font_text;
812 int font_input = mci->font_input;
817 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
818 font_text = FONT_ACTIVE(font_text);
823 font_input = FONT_ACTIVE(font_input);
826 if (visibleMenuPos(pos_button))
828 struct MenuPosInfo *pos = pos_button;
829 int x = mSX + pos->x;
830 int y = mSY + pos->y;
832 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
833 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
836 if (visibleTextPos(pos_text) && text != NULL)
838 struct TextPosInfo *pos = pos_text;
839 int x = mSX + ALIGNED_TEXT_XPOS(pos);
840 int y = mSY + ALIGNED_TEXT_YPOS(pos);
843 /* (check why/if this is needed) */
844 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
846 DrawText(x, y, text, font_text);
849 if (visibleTextPos(pos_input) && input != NULL)
851 struct TextPosInfo *pos = pos_input;
852 int x = mSX + ALIGNED_TEXT_XPOS(pos);
853 int y = mSY + ALIGNED_TEXT_YPOS(pos);
856 /* (check why/if this is needed) */
857 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
859 DrawText(x, y, input, font_input);
865 static void DrawCursorAndText_Main(int nr, boolean active_text)
867 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
871 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
873 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
877 static struct MainControlInfo *getMainControlInfo(int nr)
881 for (i = 0; main_controls[i].nr != -1; i++)
882 if (main_controls[i].nr == nr)
883 return &main_controls[i];
888 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
893 int rect_x = ALIGNED_TEXT_XPOS(rect);
894 int rect_y = ALIGNED_TEXT_YPOS(rect);
896 return (x >= rect_x && x < rect_x + rect->width &&
897 y >= rect_y && y < rect_y + rect->height);
900 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
905 int rect_x = ALIGNED_TEXT_XPOS(rect);
906 int rect_y = ALIGNED_TEXT_YPOS(rect);
908 return (x >= rect_x && x < rect_x + rect->width &&
909 y >= rect_y && y < rect_y + rect->height);
912 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
914 static int cursor_array[SCR_FIELDY];
915 int x = mSX + TILEX * xpos;
916 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
921 cursor_array[ypos] = graphic;
923 graphic = cursor_array[ypos];
927 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
929 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
930 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
933 static void initCursor(int ypos, int graphic)
935 drawCursorExt(0, ypos, FALSE, graphic);
938 static void drawCursor(int ypos, boolean active)
940 drawCursorExt(0, ypos, active, -1);
943 static void drawCursorXY(int xpos, int ypos, int graphic)
945 drawCursorExt(xpos, ypos, FALSE, graphic);
948 static void drawChooseTreeCursor(int ypos, boolean active)
950 int last_game_status = game_status; /* save current game status */
952 /* force LEVELS draw offset on artwork setup screen */
953 game_status = GAME_MODE_LEVELS;
955 drawCursorExt(0, ypos, active, -1);
957 game_status = last_game_status; /* restore current game status */
962 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
963 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
967 static int getPrevlevelButtonPos()
972 static int getCurrentLevelTextPos()
974 return (getPrevlevelButtonPos() + 1);
977 static int getNextLevelButtonPos()
979 return getPrevlevelButtonPos() + 3 + 1;
982 static int getLevelRangeTextPos()
984 return getNextLevelButtonPos() + 1;
988 int effectiveGameStatus()
990 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
991 return GAME_MODE_TITLE;
996 void DrawTitleScreenImage(int nr, boolean initial)
998 int graphic = getTitleScreenGraphic(nr, initial);
999 Bitmap *bitmap = graphic_info[graphic].bitmap;
1001 int width = graphic_info[graphic].width;
1002 int height = graphic_info[graphic].height;
1003 int src_x = graphic_info[graphic].src_x;
1004 int src_y = graphic_info[graphic].src_y;
1006 int width = graphic_info[graphic].src_image_width;
1007 int height = graphic_info[graphic].src_image_height;
1008 int src_x = 0, src_y = 0;
1015 if (width > WIN_XSIZE)
1017 /* image width too large for window => center image horizontally */
1018 src_x = (width - WIN_XSIZE) / 2;
1022 if (height > WIN_YSIZE)
1024 /* image height too large for window => center image vertically */
1025 src_y = (height - WIN_YSIZE) / 2;
1029 /* always display title screens centered */
1030 dst_x = (WIN_XSIZE - width) / 2;
1031 dst_y = (WIN_YSIZE - height) / 2;
1033 SetDrawBackgroundMask(REDRAW_ALL);
1034 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1036 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1038 if (DrawingOnBackground(dst_x, dst_y))
1039 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1041 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1043 redraw_mask = REDRAW_ALL;
1045 /* reset fading control values to default config settings */
1046 title.fade_delay_final = title.fade_delay;
1047 title.post_delay_final = title.post_delay;
1048 title.auto_delay_final = title.auto_delay;
1050 /* override default settings with image config settings, if defined */
1051 if (graphic_info[graphic].fade_delay > -1)
1052 title.fade_delay_final = graphic_info[graphic].fade_delay;
1053 if (graphic_info[graphic].post_delay > -1)
1054 title.post_delay_final = graphic_info[graphic].post_delay;
1055 if (graphic_info[graphic].auto_delay > -1)
1056 title.auto_delay_final = graphic_info[graphic].auto_delay;
1059 void DrawTitleScreenMessage(int nr, boolean initial)
1061 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1062 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1064 int font_nr = FONT_TEXT_1;
1068 int pad_y = 32 + 14;
1071 int max_chars_per_line;
1072 int max_lines_per_screen;
1074 int last_game_status = game_status; /* save current game status */
1076 if (filename == NULL)
1079 /* force TITLE font on title message screen */
1080 game_status = getTitleMessageGameMode(initial);
1082 /* if chars set to "-1", automatically determine by text and font width */
1083 if (tmi->chars == -1)
1084 tmi->chars = tmi->width / getFontWidth(tmi->font);
1086 tmi->width = tmi->chars * getFontWidth(tmi->font);
1088 /* if lines set to "-1", automatically determine by text and font height */
1089 if (tmi->lines == -1)
1090 tmi->lines = tmi->height / getFontHeight(tmi->font);
1092 tmi->height = tmi->lines * getFontHeight(tmi->font);
1094 SetDrawBackgroundMask(REDRAW_ALL);
1095 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1097 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1100 font_width = getFontWidth(font_nr);
1101 font_height = getFontHeight(font_nr);
1102 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1103 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1107 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1108 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1109 tmi->autowrap, tmi->centered, tmi->parse_comments);
1111 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1112 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1113 tmi->parse_comments);
1116 game_status = last_game_status; /* restore current game status */
1119 void DrawTitleScreen()
1121 KeyboardAutoRepeatOff();
1124 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1127 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1132 boolean CheckTitleScreen(boolean levelset_has_changed)
1134 static boolean show_title_initial = TRUE;
1135 boolean show_titlescreen = FALSE;
1137 /* needed to be able to skip title screen, if no image or message defined */
1138 InitializeTitleControls(show_title_initial);
1140 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1141 show_titlescreen = TRUE;
1143 /* show initial title images and messages only once at program start */
1144 show_title_initial = FALSE;
1146 return (show_titlescreen && num_title_screens > 0);
1149 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1151 static LevelDirTree *leveldir_last_valid = NULL;
1152 boolean levelset_has_changed = FALSE;
1154 boolean local_team_mode = (!options.network && setup.team_mode);
1155 char *name_text = (local_team_mode ? "Team:" : "Name:");
1156 int name_width, level_width;
1163 FadeSoundsAndMusic();
1165 KeyboardAutoRepeatOn();
1168 SetDrawDeactivationMask(REDRAW_NONE);
1169 SetDrawBackgroundMask(REDRAW_FIELD);
1171 audio.sound_deactivated = FALSE;
1175 /* needed if last screen was the playing screen, invoked from level editor */
1176 if (level_editor_test_game)
1178 game_status = GAME_MODE_EDITOR;
1184 /* needed if last screen was the editor screen */
1185 UndrawSpecialEditorDoor();
1187 /* needed if last screen was the setup screen and fullscreen state changed */
1188 ToggleFullscreenIfNeeded();
1190 /* leveldir_current may be invalid (level group, parent link) */
1191 if (!validLevelSeries(leveldir_current))
1192 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1194 if (leveldir_current != leveldir_last_valid)
1195 levelset_has_changed = TRUE;
1197 /* store valid level series information */
1198 leveldir_last_valid = leveldir_current;
1200 /* needed if last screen (level choice) changed graphics, sounds or music */
1201 ReloadCustomArtwork(0);
1203 #if defined(TARGET_SDL)
1204 SetDrawtoField(DRAW_BACKBUFFER);
1208 if (CheckTitleScreen(levelset_has_changed))
1210 game_status = GAME_MODE_TITLE;
1219 if (setup.show_titlescreen &&
1220 ((levelset_has_changed &&
1221 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1222 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1223 (show_title_initial &&
1224 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1225 getLevelSetMessageFilename(1, TRUE) != NULL))))
1227 game_status = GAME_MODE_TITLE;
1235 /* level_nr may have been set to value over handicap with level editor */
1236 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1237 level_nr = leveldir_current->handicap_level;
1239 LoadLevel(level_nr);
1241 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1245 InitializeMainControls();
1248 DrawCursorAndText_Main(-1, FALSE);
1250 for (i = 0; main_controls[i].nr != -1; i++)
1252 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1253 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1254 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1255 char *text = main_controls[i].text;
1256 char *input = main_controls[i].input;
1257 int button_graphic = main_controls[i].button_graphic;
1258 int font_text = main_controls[i].font_text;
1259 int font_input = main_controls[i].font_input;
1261 if (pos_button != NULL)
1262 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1265 if (pos_text != NULL && text != NULL)
1266 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1268 if (pos_input != NULL && input != NULL)
1269 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1277 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1278 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1279 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1280 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1281 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1282 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1283 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1284 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1286 /* calculated after (possible) reload of custom artwork */
1287 name_width = getTextWidth(name_text, FONT_MENU_1);
1288 level_width = 9 * 32;
1290 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1293 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1294 int2str(level_nr, 3), FONT_VALUE_1);
1297 int text_height = getFontHeight(FONT_TEXT_3);
1298 int xpos = getLevelRangeTextPos() * 32 + 8;
1299 int ypos2 = 3 * 32 + 16;
1300 int ypos1 = ypos2 - text_height;
1302 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1303 "%03d", leveldir_current->first_level);
1304 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1305 "%03d", leveldir_current->last_level);
1308 for (i = 0; i < 8; i++)
1309 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1312 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1315 DrawPreviewLevel(TRUE);
1317 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1320 if (TAPE_IS_EMPTY(tape))
1322 DrawCompleteVideoDisplay();
1327 /* create gadgets for main menu screen */
1328 FreeScreenGadgets();
1329 CreateScreenGadgets();
1331 /* map gadgets for main menu screen */
1333 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1335 DrawMaskedBorder(REDRAW_ALL);
1338 FadeIn(redraw_mask);
1342 SetMouseCursor(CURSOR_DEFAULT);
1346 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1349 void DrawAndFadeInMainMenu(int redraw_mask)
1351 DrawMainMenuExt(redraw_mask, TRUE);
1356 DrawMainMenuExt(REDRAW_ALL, FALSE);
1360 static void gotoTopLevelDir()
1362 /* move upwards to top level directory */
1363 while (leveldir_current->node_parent)
1365 /* write a "path" into level tree for easy navigation to last level */
1366 if (leveldir_current->node_parent->node_group->cl_first == -1)
1368 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1369 int leveldir_pos = posTreeInfo(leveldir_current);
1370 int num_page_entries;
1371 int cl_first, cl_cursor;
1373 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1374 num_page_entries = num_leveldirs;
1376 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1378 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1379 cl_cursor = leveldir_pos - cl_first;
1381 leveldir_current->node_parent->node_group->cl_first = cl_first;
1382 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1385 leveldir_current = leveldir_current->node_parent;
1391 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1393 static unsigned long title_delay = 0;
1394 static int title_screen_nr = 0;
1395 static int last_sound = -1, last_music = -1;
1396 boolean return_to_main_menu = FALSE;
1397 boolean use_fading_main_menu = TRUE;
1399 boolean use_cross_fading = FALSE;
1401 boolean use_cross_fading = !show_title_initial; /* default */
1403 struct TitleControlInfo *tci;
1406 if (button == MB_MENU_INITIALIZE)
1409 int last_game_status = game_status; /* save current game status */
1413 title_screen_nr = 0;
1414 tci = &title_controls[title_screen_nr];
1416 last_sound = SND_UNDEFINED;
1417 last_music = MUS_UNDEFINED;
1420 /* determine number of title screens to display (images and messages) */
1421 InitializeTitleControls();
1424 if (game_status == GAME_MODE_INFO)
1426 if (num_title_screens == 0)
1428 DrawInfoScreen_NotAvailable("Title screen information:",
1429 "No title screen for this level set.");
1431 title.auto_delay_final = -1;
1436 FadeSoundsAndMusic();
1438 FadeOut(REDRAW_ALL);
1443 DrawTitleScreenImage(tci->local_nr, tci->initial);
1447 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1449 title.fade_delay_final = title.fade_delay;
1450 title.post_delay_final = title.post_delay;
1451 title.auto_delay_final = -1;
1455 sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
1456 music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
1458 if (sound != last_sound)
1459 PlayMenuSoundExt(sound);
1460 if (music != last_music)
1461 PlayMenuMusicExt(music);
1467 SetMouseCursor(CURSOR_NONE);
1471 DelayReached(&title_delay, 0); /* reset delay counter */
1476 if (title.auto_delay_final > -1 &&
1477 DelayReached(&title_delay, title.auto_delay_final))
1478 button = MB_MENU_CHOICE;
1480 if (button == MB_MENU_LEAVE)
1482 return_to_main_menu = TRUE;
1483 use_fading_main_menu = FALSE;
1485 else if (button == MB_MENU_CHOICE)
1489 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1491 FadeOut(REDRAW_FIELD);
1493 info_mode = INFO_MODE_MAIN;
1494 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1500 tci = &title_controls[title_screen_nr];
1504 graphic_info[getTitleScreenGraphic(tci->local_nr,
1505 tci->initial)].anim_mode;
1507 anim_mode = ANIM_FADE; /* ??? */
1509 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1510 anim_mode == ANIM_CROSSFADE ? TRUE :
1513 if (title_screen_nr < num_title_screens)
1515 sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
1516 music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
1518 if (sound == SND_UNDEFINED || sound != last_sound)
1520 if (music == MUS_UNDEFINED || music != last_music)
1523 if (use_cross_fading)
1524 FadeCrossSaveBackbuffer();
1526 FadeOut(REDRAW_ALL);
1529 DrawTitleScreenImage(tci->local_nr, tci->initial);
1531 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1534 sound = getTitleSound(tci->local_nr, tci->initial, tci->is_image);
1535 music = getTitleMusic(tci->local_nr, tci->initial, tci->is_image);
1537 if (sound != last_sound)
1538 PlayMenuSoundExt(sound);
1539 if (music != last_music)
1540 PlayMenuMusicExt(music);
1546 if (use_cross_fading)
1547 FadeCross(REDRAW_ALL);
1551 DelayReached(&title_delay, 0); /* reset delay counter */
1555 FadeSoundsAndMusic();
1557 FadeOut(REDRAW_ALL);
1559 return_to_main_menu = TRUE;
1563 if (return_to_main_menu)
1567 SetMouseCursor(CURSOR_DEFAULT);
1569 if (game_status == GAME_MODE_INFO)
1571 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1573 info_mode = INFO_MODE_MAIN;
1574 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1576 else /* default: return to main menu */
1578 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1580 game_status = GAME_MODE_MAIN;
1581 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1588 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1590 static unsigned long title_delay = 0;
1591 static int title_nr = 0;
1592 static boolean showing_message = FALSE;
1593 char *filename = getLevelSetMessageFilename();
1594 boolean return_to_main_menu = FALSE;
1595 boolean use_fading_main_menu = TRUE;
1596 boolean use_cross_fading = !show_title_initial; /* default */
1597 boolean no_title_info = (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL &&
1598 getLevelSetMessageFilename(1, FALSE) == NULL);
1600 if (button == MB_MENU_INITIALIZE)
1602 int last_game_status = game_status; /* save current game status */
1606 showing_message = FALSE;
1608 if (show_title_initial &&
1609 graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap == NULL &&
1610 getLevelSetMessageFilename(1, TRUE) == NULL)
1611 show_title_initial = FALSE;
1613 if (game_status == GAME_MODE_INFO)
1617 DrawInfoScreen_NotAvailable("Title screen information:",
1618 "No title screen for this level set.");
1620 title.auto_delay_final = -1;
1625 FadeSoundsAndMusic();
1627 FadeOut(REDRAW_ALL);
1630 /* force TITLE music on title info screen */
1631 game_status = GAME_MODE_TITLE;
1636 game_status = last_game_status; /* restore current game status */
1638 if (graphic_info[getTitleScreenGraphic(0, show_title_initial)].bitmap != NULL)
1640 DrawTitleScreenImage(title_nr, show_title_initial);
1644 DrawTitleScreenMessage(filename);
1646 showing_message = TRUE;
1648 title.fade_delay_final = title.fade_delay;
1649 title.post_delay_final = title.post_delay;
1650 title.auto_delay_final = -1;
1655 DelayReached(&title_delay, 0); /* reset delay counter */
1660 if (title.auto_delay_final > -1 &&
1661 DelayReached(&title_delay, title.auto_delay_final))
1662 button = MB_MENU_CHOICE;
1664 if (button == MB_MENU_LEAVE)
1666 return_to_main_menu = TRUE;
1667 use_fading_main_menu = FALSE;
1669 else if (button == MB_MENU_CHOICE)
1673 if (game_status == GAME_MODE_INFO && no_title_info)
1675 FadeOut(REDRAW_FIELD);
1677 info_mode = INFO_MODE_MAIN;
1678 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1685 if (show_title_initial &&
1686 (title_nr >= MAX_NUM_TITLE_IMAGES ||
1687 graphic_info[IMG_TITLESCREEN_INITIAL_1 + title_nr].bitmap == NULL))
1689 show_title_initial = FALSE;
1691 title_nr = 0; /* restart with title screens for current level set */
1694 anim_mode = graphic_info[getTitleScreenGraphic(title_nr, show_title_initial)].anim_mode;
1696 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1697 anim_mode == ANIM_CROSSFADE ? TRUE :
1700 if (!use_cross_fading)
1701 FadeOut(REDRAW_ALL);
1703 if (title_nr < MAX_NUM_TITLE_IMAGES &&
1704 graphic_info[getTitleScreenGraphic(title_nr, show_title_initial)].bitmap != NULL)
1706 if (use_cross_fading)
1707 FadeCrossSaveBackbuffer();
1709 DrawTitleScreenImage(title_nr, show_title_initial);
1711 if (use_cross_fading)
1712 FadeCross(REDRAW_ALL);
1716 DelayReached(&title_delay, 0); /* reset delay counter */
1718 else if (!showing_message && filename != NULL)
1720 if (use_cross_fading)
1721 FadeCrossSaveBackbuffer();
1723 DrawTitleScreenMessage(filename);
1725 if (use_cross_fading)
1726 FadeCross(REDRAW_ALL);
1730 DelayReached(&title_delay, 0); /* reset delay counter */
1732 showing_message = TRUE;
1736 FadeSoundsAndMusic();
1738 FadeOut(REDRAW_ALL);
1740 return_to_main_menu = TRUE;
1744 if (return_to_main_menu)
1746 show_title_initial = FALSE;
1750 if (game_status == GAME_MODE_INFO)
1752 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1754 info_mode = INFO_MODE_MAIN;
1755 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1757 else /* default: return to main menu */
1759 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1761 game_status = GAME_MODE_MAIN;
1762 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1768 void HandleMainMenu_SelectLevel(int step, int direction)
1770 int old_level_nr = level_nr;
1773 new_level_nr = old_level_nr + step * direction;
1774 if (new_level_nr < leveldir_current->first_level)
1775 new_level_nr = leveldir_current->first_level;
1776 if (new_level_nr > leveldir_current->last_level)
1777 new_level_nr = leveldir_current->last_level;
1779 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1781 /* skipping levels is only allowed when trying to skip single level */
1782 if (setup.skip_levels && step == 1 &&
1783 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1785 leveldir_current->handicap_level++;
1786 SaveLevelSetup_SeriesInfo();
1789 new_level_nr = leveldir_current->handicap_level;
1792 if (new_level_nr != old_level_nr)
1794 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1796 PlaySound(SND_MENU_ITEM_SELECTING);
1798 level_nr = new_level_nr;
1801 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1802 int2str(level_nr, 3), mci->pos_text->font);
1804 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1807 LoadLevel(level_nr);
1808 DrawPreviewLevel(TRUE);
1812 DrawCompleteVideoDisplay();
1814 /* needed because DrawPreviewLevel() takes some time */
1822 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1824 static int choice = MAIN_CONTROL_GAME;
1828 if (button == MB_MENU_INITIALIZE)
1830 DrawCursorAndText_Main(choice, TRUE);
1835 if (mx || my) /* mouse input */
1839 for (i = 0; main_controls[i].nr != -1; i++)
1841 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1842 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1843 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1845 pos = main_controls[i].nr;
1851 else if (dx || dy) /* keyboard input */
1853 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1854 choice == MAIN_CONTROL_SETUP))
1855 button = MB_MENU_CHOICE;
1860 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1862 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1864 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1870 PlaySound(SND_MENU_ITEM_ACTIVATING);
1872 DrawCursorAndText_Main(choice, FALSE);
1873 DrawCursorAndText_Main(pos, TRUE);
1880 PlaySound(SND_MENU_ITEM_SELECTING);
1882 if (pos == MAIN_CONTROL_NAME)
1884 game_status = GAME_MODE_PSEUDO_TYPENAME;
1886 HandleTypeName(strlen(setup.player_name), 0);
1888 else if (pos == MAIN_CONTROL_LEVELS)
1892 game_status = GAME_MODE_LEVELS;
1894 SaveLevelSetup_LastSeries();
1895 SaveLevelSetup_SeriesInfo();
1904 else if (pos == MAIN_CONTROL_SCORES)
1906 game_status = GAME_MODE_SCORES;
1910 else if (pos == MAIN_CONTROL_EDITOR)
1912 if (leveldir_current->readonly &&
1913 !strEqual(setup.player_name, "Artsoft"))
1914 Request("This level is read only !", REQ_CONFIRM);
1916 game_status = GAME_MODE_EDITOR;
1920 else if (pos == MAIN_CONTROL_INFO)
1922 game_status = GAME_MODE_INFO;
1923 info_mode = INFO_MODE_MAIN;
1927 else if (pos == MAIN_CONTROL_GAME)
1929 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1931 else if (pos == MAIN_CONTROL_SETUP)
1933 game_status = GAME_MODE_SETUP;
1934 setup_mode = SETUP_MODE_MAIN;
1938 else if (pos == MAIN_CONTROL_QUIT)
1940 SaveLevelSetup_LastSeries();
1941 SaveLevelSetup_SeriesInfo();
1943 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1944 game_status = GAME_MODE_QUIT;
1949 if (game_status == GAME_MODE_MAIN)
1951 DrawPreviewLevel(FALSE);
1958 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1960 static int choice = 5;
1964 if (button == MB_MENU_INITIALIZE)
1966 drawCursor(choice, TRUE);
1971 if (mx || my) /* mouse input */
1973 x = (mx - mSX) / 32;
1974 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1976 else if (dx || dy) /* keyboard input */
1978 if (dx && choice == 1)
1979 x = (dx < 0 ? 10 : 14);
1982 if (choice == 4 || choice == 6)
1983 button = MB_MENU_CHOICE;
1989 if (y == 1 && dx != 0 && button)
1991 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1993 else if (IN_VIS_FIELD(x, y) &&
1994 y >= 0 && y <= 7 && (y != 1 || x < 10))
2000 drawCursor(choice, FALSE);
2001 drawCursor(y, TRUE);
2010 game_status = GAME_MODE_PSEUDO_TYPENAME;
2011 HandleTypeName(strlen(setup.player_name), 0);
2017 game_status = GAME_MODE_LEVELS;
2018 SaveLevelSetup_LastSeries();
2019 SaveLevelSetup_SeriesInfo();
2030 game_status = GAME_MODE_SCORES;
2035 if (leveldir_current->readonly &&
2036 !strEqual(setup.player_name, "Artsoft"))
2037 Request("This level is read only !", REQ_CONFIRM);
2038 game_status = GAME_MODE_EDITOR;
2043 game_status = GAME_MODE_INFO;
2044 info_mode = INFO_MODE_MAIN;
2049 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2053 game_status = GAME_MODE_SETUP;
2054 setup_mode = SETUP_MODE_MAIN;
2060 SaveLevelSetup_LastSeries();
2061 SaveLevelSetup_SeriesInfo();
2063 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2064 game_status = GAME_MODE_QUIT;
2069 if (game_status == GAME_MODE_MAIN)
2071 DrawPreviewLevel(FALSE);
2079 /* ========================================================================= */
2080 /* info screen functions */
2081 /* ========================================================================= */
2083 static struct TokenInfo *info_info;
2084 static int num_info_info;
2086 static void execInfoTitleScreen()
2088 info_mode = INFO_MODE_TITLE;
2092 static void execInfoElements()
2094 info_mode = INFO_MODE_ELEMENTS;
2098 static void execInfoMusic()
2100 info_mode = INFO_MODE_MUSIC;
2104 static void execInfoCredits()
2106 info_mode = INFO_MODE_CREDITS;
2110 static void execInfoProgram()
2112 info_mode = INFO_MODE_PROGRAM;
2116 static void execInfoVersion()
2118 info_mode = INFO_MODE_VERSION;
2122 static void execInfoLevelSet()
2124 info_mode = INFO_MODE_LEVELSET;
2128 static void execExitInfo()
2130 game_status = GAME_MODE_MAIN;
2134 static struct TokenInfo info_info_main[] =
2136 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2137 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2138 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2139 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2140 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2141 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2142 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2143 { TYPE_EMPTY, NULL, "" },
2144 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2149 static void DrawCursorAndText_Info(int pos, boolean active)
2151 int xpos = MENU_SCREEN_START_XPOS;
2152 int ypos = MENU_SCREEN_START_YPOS + pos;
2153 int font_nr = FONT_MENU_1;
2156 font_nr = FONT_ACTIVE(font_nr);
2158 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2160 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2161 drawCursor(pos, active);
2164 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2169 CloseDoor(DOOR_CLOSE_2);
2173 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2175 info_info = info_info_main;
2178 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2181 int xpos = MENU_SCREEN_START_XPOS;
2182 int ypos = MENU_SCREEN_START_YPOS + i;
2183 int font_nr = FONT_MENU_1;
2186 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2187 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2188 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2189 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2190 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2191 initCursor(i, IMG_MENU_BUTTON);
2194 DrawCursorAndText_Info(i, FALSE);
2196 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2202 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2207 DrawMaskedBorder(REDRAW_ALL);
2210 FadeIn(redraw_mask);
2217 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2219 static int choice_store[MAX_INFO_MODES];
2220 int choice = choice_store[info_mode]; /* always starts with 0 */
2224 if (button == MB_MENU_INITIALIZE)
2226 /* advance to first valid menu entry */
2227 while (choice < num_info_info &&
2228 info_info[choice].type & TYPE_SKIP_ENTRY)
2230 choice_store[info_mode] = choice;
2233 DrawCursorAndText_Info(choice, TRUE);
2235 drawCursor(choice, TRUE);
2240 else if (button == MB_MENU_LEAVE)
2242 for (y = 0; y < num_info_info; y++)
2244 if (info_info[y].type & TYPE_LEAVE_MENU)
2246 void (*menu_callback_function)(void) = info_info[y].value;
2248 menu_callback_function();
2250 break; /* absolutely needed because function changes 'info_info'! */
2257 if (mx || my) /* mouse input */
2259 x = (mx - mSX) / 32;
2260 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2262 else if (dx || dy) /* keyboard input */
2266 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2268 if (info_info[choice].type & menu_navigation_type ||
2269 info_info[choice].type & TYPE_ENTER_SCREEN ||
2270 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2271 button = MB_MENU_CHOICE;
2276 /* jump to next non-empty menu entry (up or down) */
2277 while (y > 0 && y < num_info_info - 1 &&
2278 info_info[y].type & TYPE_SKIP_ENTRY)
2282 if (IN_VIS_FIELD(x, y) &&
2283 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2289 PlaySound(SND_MENU_ITEM_ACTIVATING);
2292 DrawCursorAndText_Info(choice, FALSE);
2293 DrawCursorAndText_Info(y, TRUE);
2295 drawCursor(choice, FALSE);
2296 drawCursor(y, TRUE);
2299 choice = choice_store[info_mode] = y;
2302 else if (!(info_info[y].type & TYPE_GHOSTED))
2304 PlaySound(SND_MENU_ITEM_SELECTING);
2306 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2308 void (*menu_callback_function)(void) = info_info[choice].value;
2310 menu_callback_function();
2316 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2319 int ystart1 = mSY - SY + 100;
2320 int ystart2 = mSY - SY + 150;
2321 int ybottom = mSY - SY + SYSIZE - 20;
2325 int ybottom = SYSIZE - 20;
2328 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2330 FadeOut(REDRAW_FIELD);
2335 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2336 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2338 DrawTextSCentered(ybottom, FONT_TEXT_4,
2339 "Press any key or button for info menu");
2341 FadeIn(REDRAW_FIELD);
2344 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2346 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2347 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2348 int xstart = mSX + 16;
2349 int ystart1 = mSY - SY + 100;
2350 int ystart2 = mSY + 64 + 2 * 32;
2351 int ybottom = mSY - SY + SYSIZE - 20;
2352 int ystep = TILEY + 4;
2353 int element, action, direction;
2361 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2362 infoscreen_step[i] = infoscreen_frame[i] = 0;
2367 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2369 DrawTextSCentered(ybottom, FONT_TEXT_4,
2370 "Press any key or button for next page");
2376 while (helpanim_info[j].element != HELPANIM_LIST_END)
2378 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2383 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2392 j += infoscreen_step[i - start];
2394 element = helpanim_info[j].element;
2395 action = helpanim_info[j].action;
2396 direction = helpanim_info[j].direction;
2399 element = EL_UNKNOWN;
2401 if (action != -1 && direction != -1)
2402 graphic = el_act_dir2img(element, action, direction);
2403 else if (action != -1)
2404 graphic = el_act2img(element, action);
2405 else if (direction != -1)
2406 graphic = el_dir2img(element, direction);
2408 graphic = el2img(element);
2410 delay = helpanim_info[j++].delay;
2415 if (infoscreen_frame[i - start] == 0)
2418 infoscreen_frame[i - start] = delay - 1;
2422 sync_frame = delay - infoscreen_frame[i - start];
2423 infoscreen_frame[i - start]--;
2426 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2428 if (!infoscreen_frame[i - start])
2429 infoscreen_step[i - start] = 0;
2433 if (!infoscreen_frame[i - start])
2434 infoscreen_step[i - start]++;
2435 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2441 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2443 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2444 graphic, sync_frame, USE_MASKING);
2447 DrawInfoScreen_HelpText(element, action, direction, i - start);
2452 redraw_mask |= REDRAW_FIELD;
2457 static char *getHelpText(int element, int action, int direction)
2459 char token[MAX_LINE_LEN];
2461 strcpy(token, element_info[element].token_name);
2464 strcat(token, element_action_info[action].suffix);
2466 if (direction != -1)
2467 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2469 return getHashEntry(helptext_info, token);
2472 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2475 int font_nr = FONT_INFO_ELEMENTS;
2477 int font_nr = FONT_LEVEL_NUMBER;
2479 int font_width = getFontWidth(font_nr);
2480 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2481 int sy = mSY + 65 + 2 * 32 + 1;
2482 int ystep = TILEY + 4;
2483 int pad_x = sx - SX;
2484 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2485 int max_lines_per_text = 2;
2488 if (action != -1 && direction != -1) /* element.action.direction */
2489 text = getHelpText(element, action, direction);
2491 if (text == NULL && action != -1) /* element.action */
2492 text = getHelpText(element, action, -1);
2494 if (text == NULL && direction != -1) /* element.direction */
2495 text = getHelpText(element, -1, direction);
2497 if (text == NULL) /* base element */
2498 text = getHelpText(element, -1, -1);
2500 if (text == NULL) /* not found */
2501 text = "No description available";
2503 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2504 sy += getFontHeight(font_nr) / 2;
2507 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2508 max_chars_per_line, -1, max_lines_per_text, -1,
2509 TRUE, FALSE, FALSE);
2511 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2512 max_chars_per_line, max_lines_per_text);
2516 void DrawInfoScreen_TitleScreen()
2521 void HandleInfoScreen_TitleScreen(int button)
2523 HandleTitleScreen(0, 0, 0, 0, button);
2526 void DrawInfoScreen_Elements()
2528 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2530 FadeOut(REDRAW_FIELD);
2535 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2537 FadeIn(REDRAW_FIELD);
2542 void HandleInfoScreen_Elements(int button)
2544 static unsigned long info_delay = 0;
2545 static int num_anims;
2546 static int num_pages;
2548 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2551 if (button == MB_MENU_INITIALIZE)
2553 boolean new_element = TRUE;
2557 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2559 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2561 else if (new_element)
2564 new_element = FALSE;
2568 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2572 if (button == MB_MENU_LEAVE)
2574 PlaySound(SND_MENU_ITEM_SELECTING);
2576 info_mode = INFO_MODE_MAIN;
2581 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2583 if (button != MB_MENU_INITIALIZE)
2585 PlaySound(SND_MENU_ITEM_SELECTING);
2590 if (page >= num_pages)
2592 FadeSoundsAndMusic();
2593 FadeOut(REDRAW_FIELD);
2595 info_mode = INFO_MODE_MAIN;
2596 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2601 if (button != MB_MENU_INITIALIZE)
2602 FadeCrossSaveBackbuffer();
2604 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2606 if (button != MB_MENU_INITIALIZE)
2607 FadeCross(REDRAW_FIELD);
2611 if (DelayReached(&info_delay, GameFrameDelay))
2612 if (page < num_pages)
2613 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2615 PlayMenuSoundIfLoop();
2619 void DrawInfoScreen_Music()
2621 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2623 FadeOut(REDRAW_FIELD);
2630 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2632 FadeIn(REDRAW_FIELD);
2635 void HandleInfoScreen_Music(int button)
2637 static struct MusicFileInfo *list = NULL;
2638 int ystart1 = mSY - SY + 100;
2639 int ystart2 = mSY - SY + 150;
2640 int ybottom = mSY - SY + SYSIZE - 20;
2643 if (button == MB_MENU_INITIALIZE)
2645 list = music_file_info;
2649 FadeSoundsAndMusic();
2654 DrawTextSCentered(ystart1, FONT_TEXT_1,
2655 "No music info for this level set.");
2657 DrawTextSCentered(ybottom, FONT_TEXT_4,
2658 "Press any key or button for info menu");
2664 if (button == MB_MENU_LEAVE)
2666 PlaySound(SND_MENU_ITEM_SELECTING);
2668 FadeSoundsAndMusic();
2670 info_mode = INFO_MODE_MAIN;
2675 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2679 if (button != MB_MENU_INITIALIZE)
2681 PlaySound(SND_MENU_ITEM_SELECTING);
2689 FadeSoundsAndMusic();
2690 FadeOut(REDRAW_FIELD);
2692 info_mode = INFO_MODE_MAIN;
2693 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2698 FadeSoundsAndMusic();
2700 if (button != MB_MENU_INITIALIZE)
2701 FadeCrossSaveBackbuffer();
2708 int sound = list->music;
2710 if (sound_info[sound].loop)
2711 PlaySoundLoop(sound);
2715 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2719 PlayMusic(list->music);
2721 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2724 if (!strEqual(list->title, UNKNOWN_NAME))
2726 if (!strEqual(list->title_header, UNKNOWN_NAME))
2727 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2729 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2732 if (!strEqual(list->artist, UNKNOWN_NAME))
2734 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2735 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2737 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2739 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2742 if (!strEqual(list->album, UNKNOWN_NAME))
2744 if (!strEqual(list->album_header, UNKNOWN_NAME))
2745 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2747 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2749 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2752 if (!strEqual(list->year, UNKNOWN_NAME))
2754 if (!strEqual(list->year_header, UNKNOWN_NAME))
2755 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2757 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2759 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2762 DrawTextSCentered(ybottom, FONT_TEXT_4,
2763 "Press any key or button for next page");
2765 if (button != MB_MENU_INITIALIZE)
2766 FadeCross(REDRAW_FIELD);
2769 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2770 PlaySoundLoop(list->music);
2773 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2775 int ystart1 = mSY - SY + 100;
2776 int ystart2 = mSY - SY + 150;
2777 int ybottom = mSY - SY + SYSIZE - 20;
2786 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2790 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2791 "Special thanks to");
2792 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2794 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2796 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2797 "\"Boulder Dash\"");
2798 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2800 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2802 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2804 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2805 "First Star Software");
2807 else if (screen_nr == 1)
2809 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2810 "Special thanks to");
2811 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2812 "Klaus Heinz & Volker Wertich");
2813 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2815 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2816 "\"Emerald Mine\"");
2817 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2819 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2821 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2823 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2826 else if (screen_nr == 2)
2828 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2829 "Special thanks to");
2830 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2831 "Michael Stopp & Philip Jespersen");
2832 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2834 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2836 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2838 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2840 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2842 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2843 "Digital Integration");
2845 else if (screen_nr == 3)
2847 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2848 "Special thanks to");
2849 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2850 "Hiroyuki Imabayashi");
2851 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2853 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2855 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2857 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2859 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2861 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2864 else if (screen_nr == 4)
2866 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2867 "Special thanks to");
2868 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2870 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2872 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2873 "Jürgen Bonhagen");
2874 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2875 "for the continuous creation");
2876 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2877 "of outstanding level sets");
2879 else if (screen_nr == 5)
2881 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2883 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2885 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2886 "for ideas and inspiration by");
2887 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2890 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2892 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2894 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2895 "for ideas and inspiration by");
2896 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2899 else if (screen_nr == 6)
2901 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2903 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2905 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2906 "for the new Emerald Mine engine");
2908 else if (screen_nr == 7)
2910 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2912 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2914 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2915 "for the initial DOS port");
2917 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2919 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2921 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2922 "for some additional toons");
2924 else if (screen_nr == 8)
2926 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2927 "And not to forget:");
2928 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2930 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2931 "All those who contributed");
2932 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2933 "levels to this game");
2934 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2944 DrawTextSCentered(ybottom, FONT_TEXT_4,
2945 "Press any key or button for next page");
2950 void DrawInfoScreen_Credits()
2952 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2954 FadeSoundsAndMusic();
2956 FadeOut(REDRAW_FIELD);
2958 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2960 FadeIn(REDRAW_FIELD);
2963 void HandleInfoScreen_Credits(int button)
2965 static int screen_nr = 0;
2967 if (button == MB_MENU_INITIALIZE)
2971 DrawInfoScreen_CreditsScreen(screen_nr);
2973 else if (button == MB_MENU_LEAVE)
2975 PlaySound(SND_MENU_ITEM_SELECTING);
2977 info_mode = INFO_MODE_MAIN;
2982 else if (button == MB_MENU_CHOICE)
2984 boolean show_screen;
2986 PlaySound(SND_MENU_ITEM_SELECTING);
2990 FadeCrossSaveBackbuffer();
2992 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
2996 FadeCross(REDRAW_FIELD);
3000 FadeSoundsAndMusic();
3001 FadeOut(REDRAW_FIELD);
3003 info_mode = INFO_MODE_MAIN;
3004 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3009 PlayMenuSoundIfLoop();
3013 void DrawInfoScreen_Program()
3015 int ystart1 = mSY - SY + 100;
3016 int ystart2 = mSY - SY + 150;
3017 int ybottom = mSY - SY + SYSIZE - 20;
3020 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3022 FadeOut(REDRAW_FIELD);
3027 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3029 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3030 "This game is Freeware!");
3031 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3032 "If you like it, send e-mail to:");
3033 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3034 PROGRAM_EMAIL_STRING);
3035 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3036 "or SnailMail to:");
3037 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3039 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3040 "Detmolder Strasse 189");
3041 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3043 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3045 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3046 "More information and levels:");
3047 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3048 PROGRAM_WEBSITE_STRING);
3049 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3050 "If you have created new levels,");
3051 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3052 "send them to me to include them!");
3053 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3056 DrawTextSCentered(ybottom, FONT_TEXT_4,
3057 "Press any key or button for info menu");
3059 FadeIn(REDRAW_FIELD);
3062 void HandleInfoScreen_Program(int button)
3064 if (button == MB_MENU_LEAVE)
3066 PlaySound(SND_MENU_ITEM_SELECTING);
3068 info_mode = INFO_MODE_MAIN;
3073 else if (button == MB_MENU_CHOICE)
3075 PlaySound(SND_MENU_ITEM_SELECTING);
3077 FadeSoundsAndMusic();
3078 FadeOut(REDRAW_FIELD);
3080 info_mode = INFO_MODE_MAIN;
3081 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3085 PlayMenuSoundIfLoop();
3089 void DrawInfoScreen_Version()
3091 int font_header = FONT_TEXT_3;
3092 int font_text = FONT_TEXT_2;
3093 int xstep = getFontWidth(font_text);
3094 int ystep = getFontHeight(font_text);
3095 int ystart1 = mSY - SY + 100;
3096 int ystart2 = mSY - SY + 150;
3097 int ybottom = mSY - SY + SYSIZE - 20;
3098 int xstart1 = mSX + 2 * xstep;
3099 int xstart2 = mSX + 19 * xstep;
3100 #if defined(TARGET_SDL)
3101 int xstart3 = mSX + 29 * xstep;
3102 SDL_version sdl_version_compiled;
3103 const SDL_version *sdl_version_linked;
3104 int driver_name_len = 8;
3105 char driver_name[driver_name_len];
3108 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3110 FadeOut(REDRAW_FIELD);
3115 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3117 DrawTextF(xstart1, ystart2, font_header, "Name");
3118 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3121 DrawTextF(xstart1, ystart2, font_header, "Version");
3122 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3125 DrawTextF(xstart1, ystart2, font_header, "Platform");
3126 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3129 DrawTextF(xstart1, ystart2, font_header, "Target");
3130 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3133 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3134 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3136 #if defined(TARGET_SDL)
3137 ystart2 += 3 * ystep;
3138 DrawTextF(xstart1, ystart2, font_header, "Library");
3139 DrawTextF(xstart2, ystart2, font_header, "compiled");
3140 DrawTextF(xstart3, ystart2, font_header, "linked");
3142 SDL_VERSION(&sdl_version_compiled);
3143 sdl_version_linked = SDL_Linked_Version();
3145 ystart2 += 2 * ystep;
3146 DrawTextF(xstart1, ystart2, font_text, "SDL");
3147 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3148 sdl_version_compiled.major,
3149 sdl_version_compiled.minor,
3150 sdl_version_compiled.patch);
3151 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3152 sdl_version_linked->major,
3153 sdl_version_linked->minor,
3154 sdl_version_linked->patch);
3156 SDL_IMAGE_VERSION(&sdl_version_compiled);
3157 sdl_version_linked = IMG_Linked_Version();
3160 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3161 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3162 sdl_version_compiled.major,
3163 sdl_version_compiled.minor,
3164 sdl_version_compiled.patch);
3165 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3166 sdl_version_linked->major,
3167 sdl_version_linked->minor,
3168 sdl_version_linked->patch);
3170 SDL_MIXER_VERSION(&sdl_version_compiled);
3171 sdl_version_linked = Mix_Linked_Version();
3174 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3175 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3176 sdl_version_compiled.major,
3177 sdl_version_compiled.minor,
3178 sdl_version_compiled.patch);
3179 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3180 sdl_version_linked->major,
3181 sdl_version_linked->minor,
3182 sdl_version_linked->patch);
3184 SDL_NET_VERSION(&sdl_version_compiled);
3185 sdl_version_linked = SDLNet_Linked_Version();
3188 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3189 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3190 sdl_version_compiled.major,
3191 sdl_version_compiled.minor,
3192 sdl_version_compiled.patch);
3193 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3194 sdl_version_linked->major,
3195 sdl_version_linked->minor,
3196 sdl_version_linked->patch);
3198 ystart2 += 3 * ystep;
3199 DrawTextF(xstart1, ystart2, font_header, "Driver");
3200 DrawTextF(xstart2, ystart2, font_header, "Requested");
3201 DrawTextF(xstart3, ystart2, font_header, "Used");
3203 SDL_VideoDriverName(driver_name, driver_name_len);
3205 ystart2 += 2 * ystep;
3206 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3207 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3208 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3210 SDL_AudioDriverName(driver_name, driver_name_len);
3213 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3214 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3215 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3218 DrawTextSCentered(ybottom, FONT_TEXT_4,
3219 "Press any key or button for info menu");
3221 FadeIn(REDRAW_FIELD);
3224 void HandleInfoScreen_Version(int button)
3226 if (button == MB_MENU_LEAVE)
3228 PlaySound(SND_MENU_ITEM_SELECTING);
3230 info_mode = INFO_MODE_MAIN;
3235 else if (button == MB_MENU_CHOICE)
3237 PlaySound(SND_MENU_ITEM_SELECTING);
3239 FadeSoundsAndMusic();
3240 FadeOut(REDRAW_FIELD);
3242 info_mode = INFO_MODE_MAIN;
3243 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3247 PlayMenuSoundIfLoop();
3251 void DrawInfoScreen_LevelSet()
3253 struct TitleMessageInfo *tmi = &readme;
3254 char *filename = getLevelSetInfoFilename();
3256 /* if chars set to "-1", automatically determine by text and font width */
3257 if (tmi->chars == -1)
3258 tmi->chars = tmi->width / getFontWidth(tmi->font);
3260 tmi->width = tmi->chars * getFontWidth(tmi->font);
3262 /* if lines set to "-1", automatically determine by text and font height */
3263 if (tmi->lines == -1)
3264 tmi->lines = tmi->height / getFontHeight(tmi->font);
3266 tmi->height = tmi->lines * getFontHeight(tmi->font);
3268 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3270 FadeOut(REDRAW_FIELD);
3275 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3277 if (filename != NULL)
3278 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3279 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3280 tmi->autowrap, tmi->centered, tmi->parse_comments);
3282 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3283 "No information for this level set.");
3285 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3286 "Press any key or button for info menu");
3288 FadeIn(REDRAW_FIELD);
3291 void HandleInfoScreen_LevelSet(int button)
3293 if (button == MB_MENU_LEAVE)
3295 PlaySound(SND_MENU_ITEM_SELECTING);
3297 info_mode = INFO_MODE_MAIN;
3302 else if (button == MB_MENU_CHOICE)
3304 PlaySound(SND_MENU_ITEM_SELECTING);
3306 FadeSoundsAndMusic();
3307 FadeOut(REDRAW_FIELD);
3309 info_mode = INFO_MODE_MAIN;
3310 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3314 PlayMenuSoundIfLoop();
3318 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3320 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3322 if (info_mode == INFO_MODE_TITLE)
3323 DrawInfoScreen_TitleScreen();
3324 else if (info_mode == INFO_MODE_ELEMENTS)
3325 DrawInfoScreen_Elements();
3326 else if (info_mode == INFO_MODE_MUSIC)
3327 DrawInfoScreen_Music();
3328 else if (info_mode == INFO_MODE_CREDITS)
3329 DrawInfoScreen_Credits();
3330 else if (info_mode == INFO_MODE_PROGRAM)
3331 DrawInfoScreen_Program();
3332 else if (info_mode == INFO_MODE_VERSION)
3333 DrawInfoScreen_Version();
3334 else if (info_mode == INFO_MODE_LEVELSET)
3335 DrawInfoScreen_LevelSet();
3337 DrawInfoScreen_Main(redraw_mask, do_fading);
3339 if (info_mode != INFO_MODE_MAIN &&
3340 info_mode != INFO_MODE_TITLE &&
3341 info_mode != INFO_MODE_MUSIC)
3348 void DrawAndFadeInInfoScreen(int redraw_mask)
3350 DrawInfoScreenExt(redraw_mask, TRUE);
3353 void DrawInfoScreen()
3355 DrawInfoScreenExt(REDRAW_ALL, FALSE);
3358 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3360 if (info_mode == INFO_MODE_TITLE)
3361 HandleInfoScreen_TitleScreen(button);
3362 else if (info_mode == INFO_MODE_ELEMENTS)
3363 HandleInfoScreen_Elements(button);
3364 else if (info_mode == INFO_MODE_MUSIC)
3365 HandleInfoScreen_Music(button);
3366 else if (info_mode == INFO_MODE_CREDITS)
3367 HandleInfoScreen_Credits(button);
3368 else if (info_mode == INFO_MODE_PROGRAM)
3369 HandleInfoScreen_Program(button);
3370 else if (info_mode == INFO_MODE_VERSION)
3371 HandleInfoScreen_Version(button);
3372 else if (info_mode == INFO_MODE_LEVELSET)
3373 HandleInfoScreen_LevelSet(button);
3375 HandleInfoScreen_Main(mx, my, dx, dy, button);
3381 /* ========================================================================= */
3382 /* type name functions */
3383 /* ========================================================================= */
3385 void HandleTypeName(int newxpos, Key key)
3387 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3388 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3390 struct TextPosInfo *pos = mci->pos_input;
3391 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3392 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3395 static int xpos = 0;
3397 static int xpos = 0, ypos = 2;
3399 int font_nr = pos->font;
3400 int font_active_nr = FONT_ACTIVE(font_nr);
3401 int font_width = getFontWidth(font_active_nr);
3404 int startx = mSX + mci->pos_input->x;
3405 int starty = mSY + mci->pos_input->y;
3408 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3409 int startx = mSX + 32 + name_width;
3410 int starty = mSY + ypos * 32;
3412 char key_char = getValidConfigValueChar(getCharFromKey(key));
3413 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3414 boolean is_active = TRUE;
3416 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3420 strcpy(last_player_name, setup.player_name);
3425 /* add one character width for added cursor character */
3426 pos->width += font_width;
3427 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3429 DrawText(startx, starty, setup.player_name, font_active_nr);
3430 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3433 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3435 setup.player_name[xpos] = key_char;
3436 setup.player_name[xpos + 1] = 0;
3441 /* add one character width for added name text character */
3442 pos->width += font_width;
3443 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3445 DrawText(startx, starty, setup.player_name, font_active_nr);
3446 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3449 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3453 setup.player_name[xpos] = 0;
3456 /* remove one character width for removed name text character */
3457 pos->width -= font_width;
3458 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3460 DrawText(startx, starty, setup.player_name, font_active_nr);
3461 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3464 else if (key == KSYM_Return && xpos > 0)
3467 /* remove one character width for removed cursor text character */
3468 pos->width -= font_width;
3469 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3471 DrawText(startx, starty, setup.player_name, font_nr);
3472 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3479 game_status = GAME_MODE_MAIN;
3481 else if (key == KSYM_Escape)
3483 strcpy(setup.player_name, last_player_name);
3487 game_status = GAME_MODE_MAIN;
3492 pos->width = (strlen(setup.player_name) + 1) * font_width;
3493 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3495 DrawText(startx, starty, setup.player_name, font_active_nr);
3496 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3500 pos->width = strlen(setup.player_name) * font_width;
3501 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3503 DrawText(startx, starty, setup.player_name, font_nr);
3508 /* ========================================================================= */
3509 /* tree menu functions */
3510 /* ========================================================================= */
3512 static void DrawChooseTree(TreeInfo **ti_ptr)
3516 FreeScreenGadgets();
3517 CreateScreenGadgets();
3519 CloseDoor(DOOR_CLOSE_2);
3523 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3524 MapScreenTreeGadgets(*ti_ptr);
3530 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3532 struct GadgetInfo *gi = screen_gadget[id];
3533 int items_max, items_visible, item_position;
3535 items_max = numTreeInfoInGroup(ti);
3536 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3537 item_position = first_entry;
3539 if (item_position > items_max - items_visible)
3540 item_position = items_max - items_visible;
3542 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3543 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3544 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3547 static void drawChooseTreeList(int first_entry, int num_page_entries,
3551 char *title_string = NULL;
3552 int yoffset_sets = MENU_TITLE1_YPOS;
3553 int yoffset_setup = 16;
3554 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3556 int last_game_status = game_status; /* save current game status */
3558 title_string = ti->infotext;
3560 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3562 /* force LEVELS font on artwork setup screen */
3563 game_status = GAME_MODE_LEVELS;
3566 /* clear tree list area, but not title or scrollbar */
3567 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3568 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3569 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3571 /* clear tree list area, but not title or scrollbar */
3572 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3573 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3574 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3577 for (i = 0; i < num_page_entries; i++)
3579 TreeInfo *node, *node_first;
3580 int entry_pos = first_entry + i;
3581 int xpos = MENU_SCREEN_START_XPOS;
3582 int ypos = MENU_SCREEN_START_YPOS + i;
3583 int startx = mSX + xpos * 32;
3584 int starty = mSY + ypos * 32;
3585 int font_nr = FONT_TEXT_1;
3586 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3587 int startx_text = startx + font_xoffset;
3588 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3589 int text_size = startx_scrollbar - startx_text;
3590 int max_buffer_len = text_size / getFontWidth(font_nr);
3591 char buffer[max_buffer_len + 1];
3593 node_first = getTreeInfoFirstGroupEntry(ti);
3594 node = getTreeInfoFromPos(node_first, entry_pos);
3596 strncpy(buffer, node->name, max_buffer_len);
3597 buffer[max_buffer_len] = '\0';
3599 DrawText(startx, starty, buffer, font_nr + node->color);
3601 if (node->parent_link)
3602 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3603 else if (node->level_group)
3604 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3606 initCursor(i, IMG_MENU_BUTTON);
3609 game_status = last_game_status; /* restore current game status */
3611 redraw_mask |= REDRAW_FIELD;
3614 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3616 TreeInfo *node, *node_first;
3617 int x, last_redraw_mask = redraw_mask;
3618 int ypos = MENU_TITLE2_YPOS;
3619 int font_nr = FONT_TITLE_2;
3621 if (ti->type != TREE_TYPE_LEVEL_DIR)
3624 node_first = getTreeInfoFirstGroupEntry(ti);
3625 node = getTreeInfoFromPos(node_first, entry_pos);
3627 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3629 if (node->parent_link)
3630 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3632 else if (node->level_group)
3633 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3635 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3636 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3637 node->levels, node->class_desc);
3639 /* let BackToFront() redraw only what is needed */
3640 redraw_mask = last_redraw_mask | REDRAW_TILES;
3641 for (x = 0; x < SCR_FIELDX; x++)
3642 MarkTileDirty(x, 1);
3645 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3648 TreeInfo *ti = *ti_ptr;
3650 int y = ti->cl_cursor;
3651 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3652 int num_entries = numTreeInfoInGroup(ti);
3653 int num_page_entries;
3654 int last_game_status = game_status; /* save current game status */
3655 boolean position_set_by_scrollbar = (dx == 999);
3657 /* force LEVELS draw offset on choose level and artwork setup screen */
3658 game_status = GAME_MODE_LEVELS;
3660 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3661 num_page_entries = num_entries;
3663 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3665 game_status = last_game_status; /* restore current game status */
3667 if (button == MB_MENU_INITIALIZE)
3669 int num_entries = numTreeInfoInGroup(ti);
3670 int entry_pos = posTreeInfo(ti);
3672 if (ti->cl_first == -1)
3674 /* only on initialization */
3675 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3676 ti->cl_cursor = entry_pos - ti->cl_first;
3678 else if (ti->cl_cursor >= num_page_entries ||
3679 (num_entries > num_page_entries &&
3680 num_entries - ti->cl_first < num_page_entries))
3682 /* only after change of list size (by custom graphic configuration) */
3683 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3684 ti->cl_cursor = entry_pos - ti->cl_first;
3687 if (position_set_by_scrollbar)
3690 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3693 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3694 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3695 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3699 else if (button == MB_MENU_LEAVE)
3701 PlaySound(SND_MENU_ITEM_SELECTING);
3703 if (ti->node_parent)
3705 *ti_ptr = ti->node_parent;
3706 DrawChooseTree(ti_ptr);
3708 else if (game_status == GAME_MODE_SETUP)
3710 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3712 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3713 execSetupGraphics();
3719 game_status = GAME_MODE_MAIN;
3726 if (mx || my) /* mouse input */
3728 int last_game_status = game_status; /* save current game status */
3730 /* force LEVELS draw offset on artwork setup screen */
3731 game_status = GAME_MODE_LEVELS;
3733 x = (mx - mSX) / 32;
3734 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3736 game_status = last_game_status; /* restore current game status */
3738 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3740 /* move cursor instead of scrolling when already at start/end of list */
3741 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3743 else if (dy == +1 * SCROLL_LINE &&
3744 ti->cl_first + num_page_entries == num_entries)
3747 /* handle scrolling screen one line or page */
3748 if (ti->cl_cursor + dy < 0 ||
3749 ti->cl_cursor + dy > num_page_entries - 1)
3751 if (ABS(dy) == SCROLL_PAGE)
3752 step = num_page_entries - 1;
3754 if (dy < 0 && ti->cl_first > 0)
3756 /* scroll page/line up */
3758 ti->cl_first -= step;
3759 if (ti->cl_first < 0)
3762 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3763 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3764 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3766 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3769 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3771 /* scroll page/line down */
3773 ti->cl_first += step;
3774 if (ti->cl_first + num_page_entries > num_entries)
3775 ti->cl_first = MAX(0, num_entries - num_page_entries);
3777 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3778 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3779 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3781 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3788 /* handle moving cursor one line */
3789 y = ti->cl_cursor + dy;
3794 TreeInfo *node_first, *node_cursor;
3795 int entry_pos = ti->cl_first + y;
3797 node_first = getTreeInfoFirstGroupEntry(ti);
3798 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3800 if (node_cursor->node_group)
3802 PlaySound(SND_MENU_ITEM_SELECTING);
3804 node_cursor->cl_first = ti->cl_first;
3805 node_cursor->cl_cursor = ti->cl_cursor;
3806 *ti_ptr = node_cursor->node_group;
3807 DrawChooseTree(ti_ptr);
3812 else if (dx == -1 && ti->node_parent)
3814 PlaySound(SND_MENU_ITEM_SELECTING);
3816 *ti_ptr = ti->node_parent;
3817 DrawChooseTree(ti_ptr);
3822 if (!anyScrollbarGadgetActive() &&
3823 IN_VIS_FIELD(x, y) &&
3824 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3825 y >= 0 && y < num_page_entries)
3829 if (y != ti->cl_cursor)
3831 PlaySound(SND_MENU_ITEM_ACTIVATING);
3833 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3834 drawChooseTreeCursor(y, TRUE);
3835 drawChooseTreeInfo(ti->cl_first + y, ti);
3842 TreeInfo *node_first, *node_cursor;
3843 int entry_pos = ti->cl_first + y;
3845 PlaySound(SND_MENU_ITEM_SELECTING);
3847 node_first = getTreeInfoFirstGroupEntry(ti);
3848 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3850 if (node_cursor->node_group)
3852 node_cursor->cl_first = ti->cl_first;
3853 node_cursor->cl_cursor = ti->cl_cursor;
3854 *ti_ptr = node_cursor->node_group;
3855 DrawChooseTree(ti_ptr);
3857 else if (node_cursor->parent_link)
3859 *ti_ptr = node_cursor->node_parent;
3860 DrawChooseTree(ti_ptr);
3864 node_cursor->cl_first = ti->cl_first;
3865 node_cursor->cl_cursor = ti->cl_cursor;
3866 *ti_ptr = node_cursor;
3868 if (ti->type == TREE_TYPE_LEVEL_DIR)
3870 LoadLevelSetup_SeriesInfo();
3872 SaveLevelSetup_LastSeries();
3873 SaveLevelSetup_SeriesInfo();
3877 if (game_status == GAME_MODE_SETUP)
3879 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3881 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3882 execSetupGraphics();
3888 game_status = GAME_MODE_MAIN;
3896 void DrawChooseLevel()
3898 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3900 DrawChooseTree(&leveldir_current);
3906 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3908 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3913 void DrawHallOfFame(int highlight_position)
3916 FadeSoundsAndMusic();
3918 /* (this is needed when called from GameEnd() after winning a game) */
3919 KeyboardAutoRepeatOn();
3922 /* (this is needed when called from GameEnd() after winning a game) */
3923 SetDrawDeactivationMask(REDRAW_NONE);
3924 SetDrawBackgroundMask(REDRAW_FIELD);
3926 CloseDoor(DOOR_CLOSE_2);
3928 if (highlight_position < 0)
3929 LoadScore(level_nr);
3931 FadeOut(REDRAW_FIELD);
3938 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3940 FadeIn(REDRAW_FIELD);
3943 static void drawHallOfFameList(int first_entry, int highlight_position)
3947 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3950 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3951 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3952 "HighScores of Level %d", level_nr);
3954 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3956 int entry = first_entry + i;
3957 boolean active = (entry == highlight_position);
3958 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3959 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3960 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3961 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3962 int dx1 = 3 * getFontWidth(font_nr1);
3963 int dx2 = dx1 + getFontWidth(font_nr1);
3964 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3965 int sy = mSY + 64 + i * 32;
3967 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3968 DrawText(mSX + dx1, sy, ".", font_nr1);
3969 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3971 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3972 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3974 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3977 redraw_mask |= REDRAW_FIELD;
3980 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3982 static int first_entry = 0;
3983 static int highlight_position = 0;
3984 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3986 if (button == MB_MENU_INITIALIZE)
3989 highlight_position = mx;
3990 drawHallOfFameList(first_entry, highlight_position);
3995 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3996 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4000 if (first_entry > 0)
4002 first_entry -= step;
4003 if (first_entry < 0)
4006 drawHallOfFameList(first_entry, highlight_position);
4011 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4013 first_entry += step;
4014 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4015 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4017 drawHallOfFameList(first_entry, highlight_position);
4020 else if (button == MB_MENU_LEAVE)
4022 PlaySound(SND_MENU_ITEM_SELECTING);
4024 FadeSound(SND_BACKGROUND_SCORES);
4026 game_status = GAME_MODE_MAIN;
4030 else if (button == MB_MENU_CHOICE)
4032 PlaySound(SND_MENU_ITEM_SELECTING);
4034 FadeSound(SND_BACKGROUND_SCORES);
4035 FadeOut(REDRAW_FIELD);
4037 game_status = GAME_MODE_MAIN;
4039 DrawAndFadeInMainMenu(REDRAW_FIELD);
4042 if (game_status == GAME_MODE_SCORES)
4043 PlayMenuSoundIfLoop();
4049 /* ========================================================================= */
4050 /* setup screen functions */
4051 /* ========================================================================= */
4053 static struct TokenInfo *setup_info;
4054 static int num_setup_info;
4056 static char *screen_mode_text;
4057 static char *game_speed_text;
4058 static char *graphics_set_name;
4059 static char *sounds_set_name;
4060 static char *music_set_name;
4062 static void execSetupMain()
4064 setup_mode = SETUP_MODE_MAIN;
4068 static void execSetupGame()
4070 if (game_speeds == NULL)
4074 for (i = 0; game_speeds_list[i].value != -1; i++)
4076 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4077 char identifier[32], name[32];
4078 int value = game_speeds_list[i].value;
4079 char *text = game_speeds_list[i].text;
4081 ti->node_top = &game_speeds;
4082 ti->sort_priority = 10000 - value;
4084 sprintf(identifier, "%d", value);
4085 sprintf(name, "%s", text);
4087 setString(&ti->identifier, identifier);
4088 setString(&ti->name, name);
4089 setString(&ti->name_sorting, name);
4090 setString(&ti->infotext, "Game Speed");
4092 pushTreeInfo(&game_speeds, ti);
4095 /* sort game speed values to start with slowest game speed */
4096 sortTreeInfo(&game_speeds);
4098 /* set current game speed to configured game speed value */
4099 game_speed_current =
4100 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4102 /* if that fails, set current game speed to reliable default value */
4103 if (game_speed_current == NULL)
4104 game_speed_current =
4105 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4107 /* if that also fails, set current game speed to first available speed */
4108 if (game_speed_current == NULL)
4109 game_speed_current = game_speeds;
4112 setup.game_frame_delay = atoi(game_speed_current->identifier);
4114 /* needed for displaying game speed text instead of identifier */
4115 game_speed_text = game_speed_current->name;
4117 setup_mode = SETUP_MODE_GAME;
4121 static void execSetupChooseGameSpeed()
4123 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4127 static void execSetupEditor()
4129 setup_mode = SETUP_MODE_EDITOR;
4133 static void execSetupGraphics()
4135 if (video.fullscreen_available && screen_modes == NULL)
4139 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4141 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4142 char identifier[32], name[32];
4143 int x = video.fullscreen_modes[i].width;
4144 int y = video.fullscreen_modes[i].height;
4147 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4149 ti->node_top = &screen_modes;
4150 ti->sort_priority = x * 10000 + y;
4152 sprintf(identifier, "%dx%d", x, y);
4153 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4155 setString(&ti->identifier, identifier);
4156 setString(&ti->name, name);
4157 setString(&ti->name_sorting, name);
4158 setString(&ti->infotext, "Fullscreen Mode");
4160 pushTreeInfo(&screen_modes, ti);
4163 /* sort fullscreen modes to start with lowest available screen resolution */
4164 sortTreeInfo(&screen_modes);
4166 /* set current screen mode for fullscreen mode to configured setup value */
4167 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4168 setup.fullscreen_mode);
4170 /* if that fails, set current screen mode to reliable default value */
4171 if (screen_mode_current == NULL)
4172 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4173 DEFAULT_FULLSCREEN_MODE);
4175 /* if that also fails, set current screen mode to first available mode */
4176 if (screen_mode_current == NULL)
4177 screen_mode_current = screen_modes;
4179 if (screen_mode_current == NULL)
4180 video.fullscreen_available = FALSE;
4183 if (video.fullscreen_available)
4185 setup.fullscreen_mode = screen_mode_current->identifier;
4187 /* needed for displaying screen mode name instead of identifier */
4188 screen_mode_text = screen_mode_current->name;
4191 setup_mode = SETUP_MODE_GRAPHICS;
4195 static void execSetupChooseScreenMode()
4197 if (!video.fullscreen_available)
4200 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4204 static void execSetupSound()
4206 setup_mode = SETUP_MODE_SOUND;
4210 static void execSetupArtwork()
4212 setup.graphics_set = artwork.gfx_current->identifier;
4213 setup.sounds_set = artwork.snd_current->identifier;
4214 setup.music_set = artwork.mus_current->identifier;
4216 /* needed if last screen (setup choice) changed graphics, sounds or music */
4217 ReloadCustomArtwork(0);
4219 /* needed for displaying artwork name instead of artwork identifier */
4220 graphics_set_name = artwork.gfx_current->name;
4221 sounds_set_name = artwork.snd_current->name;
4222 music_set_name = artwork.mus_current->name;
4224 setup_mode = SETUP_MODE_ARTWORK;
4228 static void execSetupChooseGraphics()
4230 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4234 static void execSetupChooseSounds()
4236 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4240 static void execSetupChooseMusic()
4242 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4246 static void execSetupInput()
4248 setup_mode = SETUP_MODE_INPUT;
4252 static void execSetupShortcut1()
4254 setup_mode = SETUP_MODE_SHORTCUT_1;
4258 static void execSetupShortcut2()
4260 setup_mode = SETUP_MODE_SHORTCUT_2;
4264 static void execExitSetup()
4266 game_status = GAME_MODE_MAIN;
4270 static void execSaveAndExitSetup()
4276 static struct TokenInfo setup_info_main[] =
4278 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4279 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4280 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4281 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4282 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4283 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4284 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
4285 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
4286 { TYPE_EMPTY, NULL, "" },
4287 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4288 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4293 static struct TokenInfo setup_info_game[] =
4295 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4296 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4297 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4298 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4299 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4300 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4301 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4302 { TYPE_STRING, &game_speed_text, "" },
4303 { TYPE_EMPTY, NULL, "" },
4304 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4309 static struct TokenInfo setup_info_editor[] =
4312 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4313 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4314 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4315 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4316 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4317 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4318 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4319 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4321 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4322 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4323 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4325 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4327 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4328 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4329 { TYPE_EMPTY, NULL, "" },
4331 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4332 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4333 { TYPE_EMPTY, NULL, "" },
4335 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4336 { TYPE_EMPTY, NULL, "" },
4337 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4342 static struct TokenInfo setup_info_graphics[] =
4344 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4345 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4346 { TYPE_STRING, &screen_mode_text, "" },
4347 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
4349 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4350 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4352 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4353 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4354 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4355 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4356 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4357 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4358 { TYPE_EMPTY, NULL, "" },
4359 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4364 static struct TokenInfo setup_info_sound[] =
4366 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4367 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4368 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4369 { TYPE_EMPTY, NULL, "" },
4370 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4375 static struct TokenInfo setup_info_artwork[] =
4377 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4378 { TYPE_STRING, &graphics_set_name, "" },
4379 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4380 { TYPE_STRING, &sounds_set_name, "" },
4381 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4382 { TYPE_STRING, &music_set_name, "" },
4383 { TYPE_EMPTY, NULL, "" },
4385 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4386 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4387 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4389 { TYPE_STRING, NULL, "Override Level Artwork:"},
4390 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4391 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4392 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4394 { TYPE_EMPTY, NULL, "" },
4395 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4400 static struct TokenInfo setup_info_input[] =
4402 { TYPE_SWITCH, NULL, "Player:" },
4403 { TYPE_SWITCH, NULL, "Device:" },
4404 { TYPE_ENTER_MENU, NULL, "" },
4405 { TYPE_EMPTY, NULL, "" },
4406 { TYPE_EMPTY, NULL, "" },
4407 { TYPE_EMPTY, NULL, "" },
4408 { TYPE_EMPTY, NULL, "" },
4409 { TYPE_EMPTY, NULL, "" },
4410 { TYPE_EMPTY, NULL, "" },
4411 { TYPE_EMPTY, NULL, "" },
4412 { TYPE_EMPTY, NULL, "" },
4413 { TYPE_EMPTY, NULL, "" },
4414 { TYPE_EMPTY, NULL, "" },
4415 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4420 static struct TokenInfo setup_info_shortcut_1[] =
4422 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4423 { TYPE_KEY, &setup.shortcut.save_game, "" },
4424 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4425 { TYPE_KEY, &setup.shortcut.load_game, "" },
4426 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4427 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4428 { TYPE_EMPTY, NULL, "" },
4429 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4430 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4431 { TYPE_EMPTY, NULL, "" },
4432 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4437 static struct TokenInfo setup_info_shortcut_2[] =
4439 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4440 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4441 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4442 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4443 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4444 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4445 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4446 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4447 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4448 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4449 { TYPE_EMPTY, NULL, "" },
4450 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4455 static Key getSetupKey()
4457 Key key = KSYM_UNDEFINED;
4458 boolean got_key_event = FALSE;
4460 while (!got_key_event)
4462 if (PendingEvent()) /* got event */
4470 case EVENT_KEYPRESS:
4472 key = GetEventKey((KeyEvent *)&event, TRUE);
4474 /* press 'Escape' or 'Enter' to keep the existing key binding */
4475 if (key == KSYM_Escape || key == KSYM_Return)
4476 key = KSYM_UNDEFINED; /* keep old value */
4478 got_key_event = TRUE;
4482 case EVENT_KEYRELEASE:
4483 key_joystick_mapping = 0;
4487 HandleOtherEvents(&event);
4495 /* don't eat all CPU time */
4502 static int getSetupTextFont(int type)
4504 if (type & (TYPE_SWITCH |
4515 static int getSetupValueFont(int type, void *value)
4517 if (type & TYPE_KEY)
4518 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4519 else if (type & TYPE_STRING)
4520 return FONT_VALUE_2;
4521 else if (type & TYPE_ECS_AGA)
4522 return FONT_VALUE_1;
4523 else if (type & TYPE_BOOLEAN_STYLE)
4524 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4526 return FONT_VALUE_1;
4529 static void drawSetupValue(int pos)
4531 boolean font_draw_xoffset_modified = FALSE;
4532 int font_draw_xoffset_old = -1;
4533 int xpos = MENU_SCREEN_VALUE_XPOS;
4534 int ypos = MENU_SCREEN_START_YPOS + pos;
4535 int startx = mSX + xpos * 32;
4536 int starty = mSY + ypos * 32;
4537 int font_nr, font_width;
4538 int type = setup_info[pos].type;
4539 void *value = setup_info[pos].value;
4540 char *value_string = getSetupValue(type, value);
4543 if (value_string == NULL)
4546 if (type & TYPE_KEY)
4548 xpos = MENU_SCREEN_START_XPOS;
4550 if (type & TYPE_QUERY)
4552 value_string = "<press key>";
4555 else if (type & TYPE_STRING)
4557 int max_value_len = (SCR_FIELDX - 2) * 2;
4559 xpos = MENU_SCREEN_START_XPOS;
4561 if (strlen(value_string) > max_value_len)
4562 value_string[max_value_len] = '\0';
4565 startx = mSX + xpos * 32;
4566 starty = mSY + ypos * 32;
4567 font_nr = getSetupValueFont(type, value);
4568 font_width = getFontWidth(font_nr);
4570 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4571 if (setup_mode != SETUP_MODE_INPUT)
4573 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4574 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4575 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4576 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4577 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4578 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4579 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4580 boolean correct_font_draw_xoffset = FALSE;
4582 if (xpos == MENU_SCREEN_START_XPOS &&
4583 startx + font1_xoffset < text_startx + text_font_xoffset)
4584 correct_font_draw_xoffset = TRUE;
4586 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4587 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4588 correct_font_draw_xoffset = TRUE;
4590 /* check if setup value would overlap with setup text when printed */
4591 /* (this can happen for extreme/wrong values for font draw offset) */
4592 if (correct_font_draw_xoffset)
4594 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4595 font_draw_xoffset_modified = TRUE;
4597 if (type & TYPE_KEY)
4598 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4599 else if (!(type & TYPE_STRING))
4600 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4601 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4605 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4606 DrawText(startx + i * font_width, starty, " ", font_nr);
4608 DrawText(startx, starty, value_string, font_nr);
4610 if (font_draw_xoffset_modified)
4611 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4614 static void changeSetupValue(int pos)
4616 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4618 *(boolean *)setup_info[pos].value ^= TRUE;
4620 else if (setup_info[pos].type & TYPE_KEY)
4624 setup_info[pos].type |= TYPE_QUERY;
4625 drawSetupValue(pos);
4626 setup_info[pos].type &= ~TYPE_QUERY;
4628 key = getSetupKey();
4629 if (key != KSYM_UNDEFINED)
4630 *(Key *)setup_info[pos].value = key;
4633 drawSetupValue(pos);
4636 static void DrawCursorAndText_Setup(int pos, boolean active)
4638 int xpos = MENU_SCREEN_START_XPOS;
4639 int ypos = MENU_SCREEN_START_YPOS + pos;
4640 int font_nr = getSetupTextFont(setup_info[pos].type);
4642 if (setup_info == setup_info_input)
4643 font_nr = FONT_MENU_1;
4646 font_nr = FONT_ACTIVE(font_nr);
4648 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4650 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4651 drawCursor(pos, active);
4654 static void DrawSetupScreen_Generic()
4656 char *title_string = NULL;
4660 CloseDoor(DOOR_CLOSE_2);
4664 if (setup_mode == SETUP_MODE_MAIN)
4666 setup_info = setup_info_main;
4667 title_string = "Setup";
4669 else if (setup_mode == SETUP_MODE_GAME)
4671 setup_info = setup_info_game;
4672 title_string = "Setup Game";
4674 else if (setup_mode == SETUP_MODE_EDITOR)
4676 setup_info = setup_info_editor;
4677 title_string = "Setup Editor";
4679 else if (setup_mode == SETUP_MODE_GRAPHICS)
4681 setup_info = setup_info_graphics;
4682 title_string = "Setup Graphics";
4684 else if (setup_mode == SETUP_MODE_SOUND)
4686 setup_info = setup_info_sound;
4687 title_string = "Setup Sound";
4689 else if (setup_mode == SETUP_MODE_ARTWORK)
4691 setup_info = setup_info_artwork;
4692 title_string = "Custom Artwork";
4694 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
4696 setup_info = setup_info_shortcut_1;
4697 title_string = "Setup Shortcuts";
4699 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
4701 setup_info = setup_info_shortcut_2;
4702 title_string = "Setup Shortcuts";
4705 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4708 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4710 void *value_ptr = setup_info[i].value;
4713 int xpos = MENU_SCREEN_START_XPOS;
4714 int ypos = MENU_SCREEN_START_YPOS + i;
4718 /* set some entries to "unchangeable" according to other variables */
4719 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4720 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4721 (value_ptr == &setup.sound_music && !audio.music_available) ||
4722 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4723 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4724 setup_info[i].type |= TYPE_GHOSTED;
4726 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4727 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4728 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4729 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4730 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4731 initCursor(i, IMG_MENU_BUTTON);
4734 DrawCursorAndText_Setup(i, FALSE);
4736 font_nr = getSetupTextFont(setup_info[i].type);
4738 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
4741 if (setup_info[i].type & TYPE_VALUE)
4748 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4749 "Joysticks deactivated in setup menu");
4754 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4757 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4759 static int choice_store[MAX_SETUP_MODES];
4760 int choice = choice_store[setup_mode]; /* always starts with 0 */
4764 if (button == MB_MENU_INITIALIZE)
4766 /* advance to first valid menu entry */
4767 while (choice < num_setup_info &&
4768 setup_info[choice].type & TYPE_SKIP_ENTRY)
4770 choice_store[setup_mode] = choice;
4773 DrawCursorAndText_Setup(choice, TRUE);
4775 drawCursor(choice, TRUE);
4780 else if (button == MB_MENU_LEAVE)
4782 PlaySound(SND_MENU_ITEM_SELECTING);
4784 for (y = 0; y < num_setup_info; y++)
4786 if (setup_info[y].type & TYPE_LEAVE_MENU)
4788 void (*menu_callback_function)(void) = setup_info[y].value;
4790 menu_callback_function();
4792 break; /* absolutely needed because function changes 'setup_info'! */
4799 if (mx || my) /* mouse input */
4801 x = (mx - mSX) / 32;
4802 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4804 else if (dx || dy) /* keyboard input */
4808 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4810 if (setup_info[choice].type & menu_navigation_type ||
4811 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
4812 button = MB_MENU_CHOICE;
4817 /* jump to next non-empty menu entry (up or down) */
4818 while (y > 0 && y < num_setup_info - 1 &&
4819 setup_info[y].type & TYPE_SKIP_ENTRY)
4823 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4827 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4829 PlaySound(SND_MENU_ITEM_ACTIVATING);
4832 DrawCursorAndText_Setup(choice, FALSE);
4833 DrawCursorAndText_Setup(y, TRUE);
4835 drawCursor(choice, FALSE);
4836 drawCursor(y, TRUE);
4839 choice = choice_store[setup_mode] = y;
4842 else if (!(setup_info[y].type & TYPE_GHOSTED))
4844 PlaySound(SND_MENU_ITEM_SELECTING);
4846 /* when selecting key headline, execute function for key value change */
4847 if (setup_info[y].type & TYPE_KEYTEXT &&
4848 setup_info[y + 1].type & TYPE_KEY)
4851 /* when selecting string value, execute function for list selection */
4852 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4853 setup_info[y - 1].type & TYPE_ENTER_LIST)
4856 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4858 void (*menu_callback_function)(void) = setup_info[y].value;
4860 menu_callback_function();
4864 if (setup_info[y].type & TYPE_VALUE)
4865 changeSetupValue(y);
4871 void DrawSetupScreen_Input()
4880 setup_info = setup_info_input;
4883 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4886 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4888 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4889 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4890 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4891 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4892 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4893 initCursor(i, IMG_MENU_BUTTON);
4895 DrawCursorAndText_Setup(i, FALSE);
4898 initCursor(0, IMG_MENU_BUTTON);
4899 initCursor(1, IMG_MENU_BUTTON);
4900 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
4901 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
4903 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
4904 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
4905 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
4909 DeactivateJoystickForCalibration();
4912 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4913 "Joysticks deactivated on this screen");
4916 /* create gadgets for setup input menu screen */
4917 FreeScreenGadgets();
4918 CreateScreenGadgets();
4920 /* map gadgets for setup input menu screen */
4921 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4923 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4928 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4930 if (device_name == NULL)
4933 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4936 if (strlen(device_name) > 1)
4938 char c1 = device_name[strlen(device_name) - 1];
4939 char c2 = device_name[strlen(device_name) - 2];
4941 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4942 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4945 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4946 strlen(device_name));
4949 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4952 static struct SetupKeyboardInfo custom_key;
4959 { &custom_key.left, "Joystick Left" },
4960 { &custom_key.right, "Joystick Right" },
4961 { &custom_key.up, "Joystick Up" },
4962 { &custom_key.down, "Joystick Down" },
4963 { &custom_key.snap, "Button 1" },
4964 { &custom_key.drop, "Button 2" }
4966 static char *joystick_name[MAX_PLAYERS] =
4973 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4977 custom_key = setup.input[player_nr].key;
4979 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4980 FONT_INPUT_1_ACTIVE);
4982 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4984 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4985 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4987 if (setup.input[player_nr].use_joystick)
4989 char *device_name = setup.input[player_nr].joy.device_name;
4990 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4991 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4993 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4994 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4998 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4999 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5002 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5004 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5005 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5006 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5007 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5009 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5010 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5011 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5012 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5013 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5014 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5016 for (i = 0; i < 6; i++)
5018 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5020 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5022 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5023 (setup.input[player_nr].use_joystick ?
5025 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5029 static int input_player_nr = 0;
5031 void HandleSetupScreen_Input_Player(int step, int direction)
5033 int old_player_nr = input_player_nr;
5036 new_player_nr = old_player_nr + step * direction;
5037 if (new_player_nr < 0)
5039 if (new_player_nr > MAX_PLAYERS - 1)
5040 new_player_nr = MAX_PLAYERS - 1;
5042 if (new_player_nr != old_player_nr)
5044 input_player_nr = new_player_nr;
5046 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5050 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5052 static int choice = 0;
5055 int pos_start = SETUPINPUT_SCREEN_POS_START;
5056 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5057 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5058 int pos_end = SETUPINPUT_SCREEN_POS_END;
5060 if (button == MB_MENU_INITIALIZE)
5062 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5065 DrawCursorAndText_Setup(choice, TRUE);
5067 drawCursor(choice, TRUE);
5072 else if (button == MB_MENU_LEAVE)
5074 setup_mode = SETUP_MODE_MAIN;
5081 if (mx || my) /* mouse input */
5083 x = (mx - mSX) / 32;
5084 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5086 else if (dx || dy) /* keyboard input */
5088 if (dx && choice == 0)
5089 x = (dx < 0 ? 10 : 12);
5090 else if ((dx && choice == 1) ||
5091 (dx == +1 && choice == 2) ||
5092 (dx == -1 && choice == pos_end))
5093 button = MB_MENU_CHOICE;
5097 if (y >= pos_empty1 && y <= pos_empty2)
5098 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5101 if (y == 0 && dx != 0 && button)
5103 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5105 else if (IN_VIS_FIELD(x, y) &&
5106 y >= pos_start && y <= pos_end &&
5107 !(y >= pos_empty1 && y <= pos_empty2))
5114 DrawCursorAndText_Setup(choice, FALSE);
5115 DrawCursorAndText_Setup(y, TRUE);
5117 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5119 drawCursor(choice, FALSE);
5120 drawCursor(y, TRUE);
5130 char *device_name = setup.input[input_player_nr].joy.device_name;
5132 if (!setup.input[input_player_nr].use_joystick)
5134 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5136 setJoystickDeviceToNr(device_name, new_device_nr);
5137 setup.input[input_player_nr].use_joystick = TRUE;
5141 int device_nr = getJoystickNrFromDeviceName(device_name);
5142 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5144 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5145 setup.input[input_player_nr].use_joystick = FALSE;
5147 setJoystickDeviceToNr(device_name, new_device_nr);
5150 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5154 if (setup.input[input_player_nr].use_joystick)
5157 CalibrateJoystick(input_player_nr);
5160 CustomizeKeyboard(input_player_nr);
5162 else if (y == pos_end)
5166 setup_mode = SETUP_MODE_MAIN;
5173 void CustomizeKeyboard(int player_nr)
5177 boolean finished = FALSE;
5178 static struct SetupKeyboardInfo custom_key;
5183 } customize_step[] =
5185 { &custom_key.left, "Move Left" },
5186 { &custom_key.right, "Move Right" },
5187 { &custom_key.up, "Move Up" },
5188 { &custom_key.down, "Move Down" },
5189 { &custom_key.snap, "Snap Field" },
5190 { &custom_key.drop, "Drop Element" }
5193 /* read existing key bindings from player setup */
5194 custom_key = setup.input[player_nr].key;
5198 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5204 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5205 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5206 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5207 "Key:", FONT_INPUT_1_ACTIVE);
5208 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5209 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5213 if (PendingEvent()) /* got event */
5221 case EVENT_KEYPRESS:
5223 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5225 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5231 /* all keys configured -- wait for "Escape" or "Return" key */
5235 /* press 'Enter' to keep the existing key binding */
5236 if (key == KSYM_Return)
5237 key = *customize_step[step_nr].key;
5239 /* check if key already used */
5240 for (i = 0; i < step_nr; i++)
5241 if (*customize_step[i].key == key)
5246 /* got new key binding */
5247 *customize_step[step_nr].key = key;
5248 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5250 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5251 getKeyNameFromKey(key), FONT_VALUE_1);
5254 /* un-highlight last query */
5255 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5256 customize_step[step_nr - 1].text, FONT_MENU_1);
5257 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5258 "Key:", FONT_MENU_1);
5260 /* press 'Enter' to leave */
5263 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5264 "Press Enter", FONT_TITLE_1);
5268 /* query next key binding */
5269 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5270 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5271 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5272 "Key:", FONT_INPUT_1_ACTIVE);
5273 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5274 getKeyNameFromKey(*customize_step[step_nr].key),
5279 case EVENT_KEYRELEASE:
5280 key_joystick_mapping = 0;
5284 HandleOtherEvents(&event);
5292 /* don't eat all CPU time */
5296 /* write new key bindings back to player setup */
5297 setup.input[player_nr].key = custom_key;
5300 DrawSetupScreen_Input();
5303 static boolean CalibrateJoystickMain(int player_nr)
5305 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5306 int new_joystick_xright = JOYSTICK_XMIDDLE;
5307 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5308 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5309 int new_joystick_xmiddle, new_joystick_ymiddle;
5311 int joystick_fd = joystick.fd[player_nr];
5312 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5313 boolean check[3][3];
5314 int check_remaining = 3 * 3;
5319 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5322 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5327 for (y = 0; y < 3; y++)
5329 for (x = 0; x < 3; x++)
5331 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5332 check[x][y] = FALSE;
5336 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5337 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5338 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5339 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5340 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5341 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5342 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5344 joy_value = Joystick(player_nr);
5345 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5346 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5348 /* eventually uncalibrated center position (joystick could be uncentered) */
5349 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5352 new_joystick_xmiddle = joy_x;
5353 new_joystick_ymiddle = joy_y;
5355 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5358 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5363 if (PendingEvent()) /* got event */
5371 case EVENT_KEYPRESS:
5372 switch (GetEventKey((KeyEvent *)&event, TRUE))
5375 if (check_remaining == 0)
5388 case EVENT_KEYRELEASE:
5389 key_joystick_mapping = 0;
5393 HandleOtherEvents(&event);
5398 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5401 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5402 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5403 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5404 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5406 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5407 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5408 setup.input[player_nr].joy.xright = new_joystick_xright;
5409 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5410 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5411 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5413 CheckJoystickData();
5415 joy_value = Joystick(player_nr);
5417 if (joy_value & JOY_BUTTON && check_remaining == 0)
5420 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5421 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5423 if (x != last_x || y != last_y)
5425 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5426 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5431 if (check_remaining > 0 && !check[x+1][y+1])
5433 check[x+1][y+1] = TRUE;
5439 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5440 setup.input[player_nr].joy.xleft,
5441 setup.input[player_nr].joy.xmiddle,
5442 setup.input[player_nr].joy.xright);
5443 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5444 setup.input[player_nr].joy.yupper,
5445 setup.input[player_nr].joy.ymiddle,
5446 setup.input[player_nr].joy.ylower);
5455 /* don't eat all CPU time */
5459 /* calibrated center position (joystick should now be centered) */
5460 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5463 new_joystick_xmiddle = joy_x;
5464 new_joystick_ymiddle = joy_y;
5469 DrawSetupScreen_Input();
5472 /* wait until the last pressed button was released */
5473 while (Joystick(player_nr) & JOY_BUTTON)
5475 if (PendingEvent()) /* got event */
5480 HandleOtherEvents(&event);
5489 void CalibrateJoystick(int player_nr)
5491 if (!CalibrateJoystickMain(player_nr))
5493 char *device_name = setup.input[player_nr].joy.device_name;
5494 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5495 int xpos = mSX - SX;
5496 int ypos = mSY - SY;
5500 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5501 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5504 Delay(2000); /* show error message for a short time */
5510 DrawSetupScreen_Input();
5514 void DrawSetupScreen()
5516 DeactivateJoystick();
5518 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5520 if (setup_mode == SETUP_MODE_INPUT)
5521 DrawSetupScreen_Input();
5522 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5523 DrawChooseTree(&game_speed_current);
5524 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5525 DrawChooseTree(&screen_mode_current);
5526 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5527 DrawChooseTree(&artwork.gfx_current);
5528 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5529 DrawChooseTree(&artwork.snd_current);
5530 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5531 DrawChooseTree(&artwork.mus_current);
5533 DrawSetupScreen_Generic();
5539 void RedrawSetupScreenAfterFullscreenToggle()
5541 if (setup_mode == SETUP_MODE_GRAPHICS)
5545 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5547 if (setup_mode == SETUP_MODE_INPUT)
5548 HandleSetupScreen_Input(mx, my, dx, dy, button);
5549 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5550 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5551 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5552 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5553 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5554 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5555 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5556 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5557 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5558 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5560 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5565 void HandleGameActions()
5567 if (game_status != GAME_MODE_PLAYING)
5570 GameActions(); /* main game loop */
5572 if (tape.auto_play && !tape.playing)
5573 AutoPlayTape(); /* continue automatically playing next tape */
5577 /* ---------- new screen button stuff -------------------------------------- */
5579 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5584 case SCREEN_CTRL_ID_PREV_LEVEL:
5585 *x = mSX + menu.main.button.prev_level.x;
5586 *y = mSY + menu.main.button.prev_level.y;
5589 case SCREEN_CTRL_ID_NEXT_LEVEL:
5590 *x = mSX + menu.main.button.next_level.x;
5591 *y = mSY + menu.main.button.next_level.y;
5594 case SCREEN_CTRL_ID_PREV_LEVEL:
5595 *x = mSX + TILEX * getPrevlevelButtonPos();
5596 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5599 case SCREEN_CTRL_ID_NEXT_LEVEL:
5600 *x = mSX + TILEX * getNextLevelButtonPos();
5601 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5605 case SCREEN_CTRL_ID_PREV_PLAYER:
5606 *x = mSX + TILEX * 10;
5607 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5610 case SCREEN_CTRL_ID_NEXT_PLAYER:
5611 *x = mSX + TILEX * 12;
5612 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5616 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5622 int gfx_unpressed, gfx_pressed;
5623 void (*get_gadget_position)(int *, int *, int);
5627 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5630 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5631 getScreenMenuButtonPos,
5632 SCREEN_CTRL_ID_PREV_LEVEL,
5637 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5638 getScreenMenuButtonPos,
5639 SCREEN_CTRL_ID_NEXT_LEVEL,
5644 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5645 getScreenMenuButtonPos,
5646 SCREEN_CTRL_ID_PREV_PLAYER,
5651 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5652 getScreenMenuButtonPos,
5653 SCREEN_CTRL_ID_NEXT_PLAYER,
5661 int gfx_unpressed, gfx_pressed;
5665 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5668 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5669 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5670 SCREEN_CTRL_ID_SCROLL_UP,
5674 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5675 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5676 SCREEN_CTRL_ID_SCROLL_DOWN,
5683 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5684 Bitmap **gfx_unpressed, **gfx_pressed;
5686 int gfx_unpressed, gfx_pressed;
5693 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5696 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5697 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5699 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5701 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5702 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5703 GD_TYPE_SCROLLBAR_VERTICAL,
5704 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5705 "scroll level series vertically"
5709 static void CreateScreenMenubuttons()
5711 struct GadgetInfo *gi;
5712 unsigned long event_mask;
5715 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5717 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5718 int gfx_unpressed, gfx_pressed;
5719 int x, y, width, height;
5720 int gd_x1, gd_x2, gd_y1, gd_y2;
5721 int id = menubutton_info[i].gadget_id;
5723 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5725 menubutton_info[i].get_gadget_position(&x, &y, id);
5727 width = SC_MENUBUTTON_XSIZE;
5728 height = SC_MENUBUTTON_YSIZE;
5730 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5731 gfx_pressed = menubutton_info[i].gfx_pressed;
5732 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5733 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5734 gd_x1 = graphic_info[gfx_unpressed].src_x;
5735 gd_y1 = graphic_info[gfx_unpressed].src_y;
5736 gd_x2 = graphic_info[gfx_pressed].src_x;
5737 gd_y2 = graphic_info[gfx_pressed].src_y;
5739 gi = CreateGadget(GDI_CUSTOM_ID, id,
5740 GDI_CUSTOM_TYPE_ID, i,
5741 GDI_INFO_TEXT, menubutton_info[i].infotext,
5746 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5747 GDI_STATE, GD_BUTTON_UNPRESSED,
5748 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5749 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5750 GDI_DIRECT_DRAW, FALSE,
5751 GDI_EVENT_MASK, event_mask,
5752 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5756 Error(ERR_EXIT, "cannot create gadget");
5758 screen_gadget[id] = gi;
5762 static void CreateScreenScrollbuttons()
5764 struct GadgetInfo *gi;
5765 unsigned long event_mask;
5768 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5770 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5771 int gfx_unpressed, gfx_pressed;
5772 int x, y, width, height;
5773 int gd_x1, gd_x2, gd_y1, gd_y2;
5774 int id = scrollbutton_info[i].gadget_id;
5776 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5778 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5779 y = mSY + scrollbutton_info[i].y;
5780 width = SC_SCROLLBUTTON_XSIZE;
5781 height = SC_SCROLLBUTTON_YSIZE;
5783 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5784 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5785 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5787 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5788 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5789 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5790 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5791 gd_x1 = graphic_info[gfx_unpressed].src_x;
5792 gd_y1 = graphic_info[gfx_unpressed].src_y;
5793 gd_x2 = graphic_info[gfx_pressed].src_x;
5794 gd_y2 = graphic_info[gfx_pressed].src_y;
5796 gi = CreateGadget(GDI_CUSTOM_ID, id,
5797 GDI_CUSTOM_TYPE_ID, i,
5798 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5803 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5804 GDI_STATE, GD_BUTTON_UNPRESSED,
5805 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5806 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5807 GDI_DIRECT_DRAW, FALSE,
5808 GDI_EVENT_MASK, event_mask,
5809 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5813 Error(ERR_EXIT, "cannot create gadget");
5815 screen_gadget[id] = gi;
5819 static void CreateScreenScrollbars()
5823 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5825 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5826 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5827 int gfx_unpressed, gfx_pressed;
5829 int x, y, width, height;
5830 int gd_x1, gd_x2, gd_y1, gd_y2;
5831 struct GadgetInfo *gi;
5832 int items_max, items_visible, item_position;
5833 unsigned long event_mask;
5834 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5835 int id = scrollbar_info[i].gadget_id;
5837 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5839 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5840 y = mSY + scrollbar_info[i].y;
5841 width = scrollbar_info[i].width;
5842 height = scrollbar_info[i].height;
5844 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5845 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5847 items_max = num_page_entries;
5848 items_visible = num_page_entries;
5851 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5852 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5853 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5859 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5860 gfx_pressed = scrollbar_info[i].gfx_pressed;
5861 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5862 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5863 gd_x1 = graphic_info[gfx_unpressed].src_x;
5864 gd_y1 = graphic_info[gfx_unpressed].src_y;
5865 gd_x2 = graphic_info[gfx_pressed].src_x;
5866 gd_y2 = graphic_info[gfx_pressed].src_y;
5869 gi = CreateGadget(GDI_CUSTOM_ID, id,
5870 GDI_CUSTOM_TYPE_ID, i,
5871 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5876 GDI_TYPE, scrollbar_info[i].type,
5877 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5878 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5879 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5881 GDI_WHEEL_AREA_X, SX,
5882 GDI_WHEEL_AREA_Y, SY,
5883 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5884 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5886 GDI_WHEEL_AREA_X, 0,
5887 GDI_WHEEL_AREA_Y, 0,
5888 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5889 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5891 GDI_STATE, GD_BUTTON_UNPRESSED,
5892 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5893 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5894 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5895 GDI_DIRECT_DRAW, FALSE,
5896 GDI_EVENT_MASK, event_mask,
5897 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5901 Error(ERR_EXIT, "cannot create gadget");
5903 screen_gadget[id] = gi;
5907 void CreateScreenGadgets()
5909 int last_game_status = game_status; /* save current game status */
5911 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5914 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5916 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5918 /* copy pointers to clip mask and GC */
5919 scrollbar_bitmap[i]->clip_mask =
5920 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5921 scrollbar_bitmap[i]->stored_clip_gc =
5922 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5924 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5925 scrollbar_bitmap[i],
5926 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5927 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5928 TILEX, TILEY, 0, 0);
5932 CreateScreenMenubuttons();
5934 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5935 game_status = GAME_MODE_LEVELS;
5937 CreateScreenScrollbuttons();
5938 CreateScreenScrollbars();
5940 game_status = last_game_status; /* restore current game status */
5943 void FreeScreenGadgets()
5947 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5948 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5950 /* prevent freeing clip mask and GC twice */
5951 scrollbar_bitmap[i]->clip_mask = None;
5952 scrollbar_bitmap[i]->stored_clip_gc = None;
5954 FreeBitmap(scrollbar_bitmap[i]);
5958 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5959 FreeGadget(screen_gadget[i]);
5962 void MapScreenMenuGadgets(int screen_mask)
5966 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5967 if (screen_mask & menubutton_info[i].screen_mask)
5968 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5971 void MapScreenTreeGadgets(TreeInfo *ti)
5973 int num_entries = numTreeInfoInGroup(ti);
5976 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5979 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5980 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5982 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5983 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5986 static void HandleScreenGadgets(struct GadgetInfo *gi)
5988 int id = gi->custom_id;
5989 int button = gi->event.button;
5990 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5994 case SCREEN_CTRL_ID_PREV_LEVEL:
5995 HandleMainMenu_SelectLevel(step, -1);
5998 case SCREEN_CTRL_ID_NEXT_LEVEL:
5999 HandleMainMenu_SelectLevel(step, +1);
6002 case SCREEN_CTRL_ID_PREV_PLAYER:
6003 HandleSetupScreen_Input_Player(step, -1);
6006 case SCREEN_CTRL_ID_NEXT_PLAYER:
6007 HandleSetupScreen_Input_Player(step, +1);
6010 case SCREEN_CTRL_ID_SCROLL_UP:
6011 if (game_status == GAME_MODE_LEVELS)
6012 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6013 else if (game_status == GAME_MODE_SETUP)
6014 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6017 case SCREEN_CTRL_ID_SCROLL_DOWN:
6018 if (game_status == GAME_MODE_LEVELS)
6019 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6020 else if (game_status == GAME_MODE_SETUP)
6021 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6024 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6025 if (game_status == GAME_MODE_LEVELS)
6026 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6027 else if (game_status == GAME_MODE_SETUP)
6028 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);