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]);
497 static int compareTitleControlInfo(const void *object1, const void *object2)
499 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
500 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
503 if (tci1->initial != tci2->initial)
504 compare_result = (tci1->initial ? -1 : +1);
505 else if (tci1->sort_priority != tci2->sort_priority)
506 compare_result = tci1->sort_priority - tci2->sort_priority;
507 else if (tci1->is_image != tci2->is_image)
508 compare_result = (tci1->is_image ? -1 : +1);
510 compare_result = tci1->local_nr - tci2->local_nr;
512 return compare_result;
515 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
517 int nr, int sort_priority)
519 title_controls[num_title_screens].is_image = is_image;
520 title_controls[num_title_screens].initial = initial;
521 title_controls[num_title_screens].local_nr = nr;
522 title_controls[num_title_screens].sort_priority = sort_priority;
527 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
531 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
533 int graphic = getTitleScreenGraphic(i, initial);
534 Bitmap *bitmap = graphic_info[graphic].bitmap;
535 int sort_priority = graphic_info[graphic].sort_priority;
538 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
541 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
543 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
544 char *filename = getLevelSetTitleMessageFilename(i, initial);
545 int sort_priority = tmi->sort_priority;
547 if (filename != NULL)
548 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
552 static void InitializeTitleControls(boolean show_title_initial)
554 num_title_screens = 0;
556 if (show_title_initial)
557 InitializeTitleControls_CheckTitleInfo(TRUE);
559 InitializeTitleControls_CheckTitleInfo(FALSE);
561 /* sort title screens according to sort_priority and title number */
562 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
563 compareTitleControlInfo);
566 static boolean visibleMenuPos(struct MenuPosInfo *pos)
568 return (pos != NULL && pos->x != -1 && pos->y != -1);
571 static boolean visibleTextPos(struct TextPosInfo *pos)
573 return (pos != NULL && pos->x != -1 && pos->y != -1);
576 static void InitializeMainControls()
578 boolean local_team_mode = (!options.network && setup.team_mode);
581 /* set main control text values to dynamically determined values */
582 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
583 sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
584 sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
585 sprintf(main_text_level_number, "%s", int2str(level_nr, 3));
587 main_text_level_year = leveldir_current->year;
588 main_text_level_imported_from = leveldir_current->imported_from;
589 main_text_level_imported_by = leveldir_current->imported_by;
590 main_text_level_tested_by = leveldir_current->tested_by;
592 /* set main control screen positions to dynamically determined values */
593 for (i = 0; main_controls[i].nr != -1; i++)
595 struct MainControlInfo *mci = &main_controls[i];
597 struct MenuPosInfo *pos_button = mci->pos_button;
598 struct TextPosInfo *pos_text = mci->pos_text;
599 struct TextPosInfo *pos_input = mci->pos_input;
600 char *text = (mci->text ? *mci->text : NULL);
601 char *input = (mci->input ? *mci->input : NULL);
602 int button_graphic = mci->button_graphic;
604 int font_text = (pos_text ? pos_text->font : -1);
605 int font_input = (pos_input ? pos_input->font : -1);
607 int font_text = mci->font_text;
608 int font_input = mci->font_input;
611 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
612 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
613 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
614 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
615 int text_chars = (text != NULL ? strlen(text) : 0);
616 int input_chars = (input != NULL ? strlen(input) : 0);
619 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
621 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
622 int text_width = font_text_width * text_chars;
623 int text_height = font_text_height;
624 int input_width = font_input_width * input_chars;
625 int input_height = font_input_height;
627 if (nr == MAIN_CONTROL_NAME)
630 if (menu.main.input.name.x == -1)
631 menu.main.input.name.x = menu.main.text.name.x + text_width;
632 if (menu.main.input.name.y == -1)
633 menu.main.input.name.y = menu.main.text.name.y;
637 menu.main.input.name.width = input_width;
638 menu.main.input.name.height = input_height;
640 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
641 menu.main.input.name.height = font_input_height;
645 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
647 if (pos_button->width == 0)
648 pos_button->width = button_width;
649 if (pos_button->height == 0)
650 pos_button->height = button_height;
653 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
655 /* calculate width for non-clickable text -- needed for text alignment */
656 boolean calculate_text_width = (pos_button == NULL && text != NULL);
658 if (visibleMenuPos(pos_button))
660 if (pos_text->x == -1)
661 pos_text->x = pos_button->x + pos_button->width;
662 if (pos_text->y == -1)
663 pos_text->y = pos_button->y;
666 if (pos_text->width == -1 || calculate_text_width)
667 pos_text->width = text_width;
668 if (pos_text->height == -1)
669 pos_text->height = text_height;
672 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
674 if (visibleTextPos(pos_text))
676 if (pos_input->x == -1)
677 pos_input->x = pos_text->x + pos_text->width;
678 if (pos_input->y == -1)
679 pos_input->y = pos_text->y;
682 if (pos_input->width == -1)
683 pos_input->width = input_width;
684 if (pos_input->height == -1)
685 pos_input->height = input_height;
690 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
691 boolean active_input)
695 for (i = 0; main_controls[i].nr != -1; i++)
697 struct MainControlInfo *mci = &main_controls[i];
699 if (mci->nr == nr || nr == -1)
701 struct MenuPosInfo *pos_button = mci->pos_button;
702 struct TextPosInfo *pos_text = mci->pos_text;
703 struct TextPosInfo *pos_input = mci->pos_input;
704 char *text = (mci->text ? *mci->text : NULL);
705 char *input = (mci->input ? *mci->input : NULL);
706 int button_graphic = mci->button_graphic;
708 int font_text = (pos_text ? pos_text->font : -1);
709 int font_input = (pos_input ? pos_input->font : -1);
711 int font_text = mci->font_text;
712 int font_input = mci->font_input;
717 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
718 font_text = FONT_ACTIVE(font_text);
723 font_input = FONT_ACTIVE(font_input);
726 if (visibleMenuPos(pos_button))
728 struct MenuPosInfo *pos = pos_button;
729 int x = mSX + pos->x;
730 int y = mSY + pos->y;
732 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
733 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
736 if (visibleTextPos(pos_text) && text != NULL)
738 struct TextPosInfo *pos = pos_text;
739 int x = mSX + ALIGNED_TEXT_XPOS(pos);
740 int y = mSY + ALIGNED_TEXT_YPOS(pos);
743 /* (check why/if this is needed) */
744 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
746 DrawText(x, y, text, font_text);
749 if (visibleTextPos(pos_input) && input != NULL)
751 struct TextPosInfo *pos = pos_input;
752 int x = mSX + ALIGNED_TEXT_XPOS(pos);
753 int y = mSY + ALIGNED_TEXT_YPOS(pos);
756 /* (check why/if this is needed) */
757 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
759 DrawText(x, y, input, font_input);
765 static void DrawCursorAndText_Main(int nr, boolean active_text)
767 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
771 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
773 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
777 static struct MainControlInfo *getMainControlInfo(int nr)
781 for (i = 0; main_controls[i].nr != -1; i++)
782 if (main_controls[i].nr == nr)
783 return &main_controls[i];
788 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
793 int rect_x = ALIGNED_TEXT_XPOS(rect);
794 int rect_y = ALIGNED_TEXT_YPOS(rect);
796 return (x >= rect_x && x < rect_x + rect->width &&
797 y >= rect_y && y < rect_y + rect->height);
800 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
805 int rect_x = ALIGNED_TEXT_XPOS(rect);
806 int rect_y = ALIGNED_TEXT_YPOS(rect);
808 return (x >= rect_x && x < rect_x + rect->width &&
809 y >= rect_y && y < rect_y + rect->height);
812 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
814 static int cursor_array[SCR_FIELDY];
815 int x = mSX + TILEX * xpos;
816 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
821 cursor_array[ypos] = graphic;
823 graphic = cursor_array[ypos];
827 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
829 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
830 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
833 static void initCursor(int ypos, int graphic)
835 drawCursorExt(0, ypos, FALSE, graphic);
838 static void drawCursor(int ypos, boolean active)
840 drawCursorExt(0, ypos, active, -1);
843 static void drawCursorXY(int xpos, int ypos, int graphic)
845 drawCursorExt(xpos, ypos, FALSE, graphic);
848 static void drawChooseTreeCursor(int ypos, boolean active)
850 int last_game_status = game_status; /* save current game status */
852 /* force LEVELS draw offset on artwork setup screen */
853 game_status = GAME_MODE_LEVELS;
855 drawCursorExt(0, ypos, active, -1);
857 game_status = last_game_status; /* restore current game status */
862 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
863 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
867 static int getPrevlevelButtonPos()
872 static int getCurrentLevelTextPos()
874 return (getPrevlevelButtonPos() + 1);
877 static int getNextLevelButtonPos()
879 return getPrevlevelButtonPos() + 3 + 1;
882 static int getLevelRangeTextPos()
884 return getNextLevelButtonPos() + 1;
888 int effectiveGameStatus()
890 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
891 return GAME_MODE_TITLE;
896 void DrawTitleScreenImage(int nr, boolean initial)
898 int graphic = getTitleScreenGraphic(nr, initial);
899 Bitmap *bitmap = graphic_info[graphic].bitmap;
901 int width = graphic_info[graphic].width;
902 int height = graphic_info[graphic].height;
903 int src_x = graphic_info[graphic].src_x;
904 int src_y = graphic_info[graphic].src_y;
906 int width = graphic_info[graphic].src_image_width;
907 int height = graphic_info[graphic].src_image_height;
908 int src_x = 0, src_y = 0;
915 if (width > WIN_XSIZE)
917 /* image width too large for window => center image horizontally */
918 src_x = (width - WIN_XSIZE) / 2;
922 if (height > WIN_YSIZE)
924 /* image height too large for window => center image vertically */
925 src_y = (height - WIN_YSIZE) / 2;
929 dst_x = (WIN_XSIZE - width) / 2;
930 dst_y = (WIN_YSIZE - height) / 2;
932 SetDrawBackgroundMask(REDRAW_ALL);
933 SetWindowBackgroundImage(IMG_BACKGROUND_TITLE);
935 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
937 if (DrawingOnBackground(dst_x, dst_y))
938 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
940 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
942 redraw_mask = REDRAW_ALL;
944 /* reset fading control values to default config settings */
945 title.fade_delay_final = title.fade_delay;
946 title.post_delay_final = title.post_delay;
947 title.auto_delay_final = title.auto_delay;
949 /* override default settings with image config settings, if defined */
950 if (graphic_info[graphic].fade_delay > -1)
951 title.fade_delay_final = graphic_info[graphic].fade_delay;
952 if (graphic_info[graphic].post_delay > -1)
953 title.post_delay_final = graphic_info[graphic].post_delay;
954 if (graphic_info[graphic].auto_delay > -1)
955 title.auto_delay_final = graphic_info[graphic].auto_delay;
958 void DrawTitleScreenMessage(int nr, boolean initial)
960 char *filename = getLevelSetTitleMessageFilename(nr, initial);
961 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
963 int font_nr = FONT_TEXT_1;
970 int max_chars_per_line;
971 int max_lines_per_screen;
973 int last_game_status = game_status; /* save current game status */
975 if (filename == NULL)
978 /* force MESSAGE font on title message screen */
979 game_status = GAME_MODE_MESSAGE;
981 /* if chars set to "-1", automatically determine by text and font width */
982 if (tmi->chars == -1)
983 tmi->chars = tmi->width / getFontWidth(tmi->font);
985 tmi->width = tmi->chars * getFontWidth(tmi->font);
987 /* if lines set to "-1", automatically determine by text and font height */
988 if (tmi->lines == -1)
989 tmi->lines = tmi->height / getFontHeight(tmi->font);
991 tmi->height = tmi->lines * getFontHeight(tmi->font);
993 SetDrawBackgroundMask(REDRAW_ALL);
994 SetWindowBackgroundImage(IMG_BACKGROUND_MESSAGE);
996 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
999 font_width = getFontWidth(font_nr);
1000 font_height = getFontHeight(font_nr);
1001 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1002 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1006 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1007 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1008 tmi->autowrap, tmi->centered, tmi->skip_comments);
1010 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1011 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1012 tmi->skip_comments);
1015 game_status = last_game_status; /* restore current game status */
1018 void DrawTitleScreen()
1020 KeyboardAutoRepeatOff();
1023 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1026 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1031 boolean CheckTitleScreen(boolean levelset_has_changed)
1033 static boolean show_title_initial = TRUE;
1034 boolean show_titlescreen = FALSE;
1036 /* needed to be able to skip title screen, if no image or message defined */
1037 InitializeTitleControls(show_title_initial);
1039 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1040 show_titlescreen = TRUE;
1042 /* show initial title images and messages only once at program start */
1043 show_title_initial = FALSE;
1045 return (show_titlescreen && num_title_screens > 0);
1048 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1050 static LevelDirTree *leveldir_last_valid = NULL;
1051 boolean levelset_has_changed = FALSE;
1053 boolean local_team_mode = (!options.network && setup.team_mode);
1054 char *name_text = (local_team_mode ? "Team:" : "Name:");
1055 int name_width, level_width;
1062 FadeSoundsAndMusic();
1064 KeyboardAutoRepeatOn();
1067 SetDrawDeactivationMask(REDRAW_NONE);
1068 SetDrawBackgroundMask(REDRAW_FIELD);
1070 audio.sound_deactivated = FALSE;
1074 /* needed if last screen was the playing screen, invoked from level editor */
1075 if (level_editor_test_game)
1077 game_status = GAME_MODE_EDITOR;
1083 /* needed if last screen was the editor screen */
1084 UndrawSpecialEditorDoor();
1086 /* needed if last screen was the setup screen and fullscreen state changed */
1087 ToggleFullscreenIfNeeded();
1089 /* leveldir_current may be invalid (level group, parent link) */
1090 if (!validLevelSeries(leveldir_current))
1091 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1093 if (leveldir_current != leveldir_last_valid)
1094 levelset_has_changed = TRUE;
1096 /* store valid level series information */
1097 leveldir_last_valid = leveldir_current;
1099 /* needed if last screen (level choice) changed graphics, sounds or music */
1100 ReloadCustomArtwork(0);
1102 #if defined(TARGET_SDL)
1103 SetDrawtoField(DRAW_BACKBUFFER);
1107 if (CheckTitleScreen(levelset_has_changed))
1109 game_status = GAME_MODE_TITLE;
1118 if (setup.show_titlescreen &&
1119 ((levelset_has_changed &&
1120 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1121 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1122 (show_title_initial &&
1123 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1124 getLevelSetMessageFilename(1, TRUE) != NULL))))
1126 game_status = GAME_MODE_TITLE;
1134 /* level_nr may have been set to value over handicap with level editor */
1135 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1136 level_nr = leveldir_current->handicap_level;
1138 LoadLevel(level_nr);
1140 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1144 InitializeMainControls();
1147 DrawCursorAndText_Main(-1, FALSE);
1149 for (i = 0; main_controls[i].nr != -1; i++)
1151 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1152 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1153 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1154 char *text = main_controls[i].text;
1155 char *input = main_controls[i].input;
1156 int button_graphic = main_controls[i].button_graphic;
1157 int font_text = main_controls[i].font_text;
1158 int font_input = main_controls[i].font_input;
1160 if (pos_button != NULL)
1161 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1164 if (pos_text != NULL && text != NULL)
1165 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1167 if (pos_input != NULL && input != NULL)
1168 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1176 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1177 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1178 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1179 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1180 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1181 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1182 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1183 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1185 /* calculated after (possible) reload of custom artwork */
1186 name_width = getTextWidth(name_text, FONT_MENU_1);
1187 level_width = 9 * 32;
1189 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1192 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1193 int2str(level_nr, 3), FONT_VALUE_1);
1196 int text_height = getFontHeight(FONT_TEXT_3);
1197 int xpos = getLevelRangeTextPos() * 32 + 8;
1198 int ypos2 = 3 * 32 + 16;
1199 int ypos1 = ypos2 - text_height;
1201 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1202 "%03d", leveldir_current->first_level);
1203 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1204 "%03d", leveldir_current->last_level);
1207 for (i = 0; i < 8; i++)
1208 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1211 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1214 DrawPreviewLevel(TRUE);
1216 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1219 if (TAPE_IS_EMPTY(tape))
1221 DrawCompleteVideoDisplay();
1226 /* create gadgets for main menu screen */
1227 FreeScreenGadgets();
1228 CreateScreenGadgets();
1230 /* map gadgets for main menu screen */
1232 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1234 DrawMaskedBorder(REDRAW_ALL);
1237 FadeIn(redraw_mask);
1241 SetMouseCursor(CURSOR_DEFAULT);
1245 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1248 void DrawAndFadeInMainMenu(int redraw_mask)
1250 DrawMainMenuExt(redraw_mask, TRUE);
1255 DrawMainMenuExt(REDRAW_ALL, FALSE);
1259 static void gotoTopLevelDir()
1261 /* move upwards to top level directory */
1262 while (leveldir_current->node_parent)
1264 /* write a "path" into level tree for easy navigation to last level */
1265 if (leveldir_current->node_parent->node_group->cl_first == -1)
1267 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1268 int leveldir_pos = posTreeInfo(leveldir_current);
1269 int num_page_entries;
1270 int cl_first, cl_cursor;
1272 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1273 num_page_entries = num_leveldirs;
1275 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1277 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1278 cl_cursor = leveldir_pos - cl_first;
1280 leveldir_current->node_parent->node_group->cl_first = cl_first;
1281 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1284 leveldir_current = leveldir_current->node_parent;
1290 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1292 static unsigned long title_delay = 0;
1293 static int title_screen_nr = 0;
1294 boolean return_to_main_menu = FALSE;
1295 boolean use_fading_main_menu = TRUE;
1297 boolean use_cross_fading = FALSE;
1299 boolean use_cross_fading = !show_title_initial; /* default */
1301 struct TitleControlInfo *tci;
1303 if (button == MB_MENU_INITIALIZE)
1305 int last_game_status = game_status; /* save current game status */
1308 title_screen_nr = 0;
1309 tci = &title_controls[title_screen_nr];
1312 /* determine number of title screens to display (images and messages) */
1313 InitializeTitleControls();
1316 if (game_status == GAME_MODE_INFO)
1318 if (num_title_screens == 0)
1320 DrawInfoScreen_NotAvailable("Title screen information:",
1321 "No title screen for this level set.");
1323 title.auto_delay_final = -1;
1328 FadeSoundsAndMusic();
1330 FadeOut(REDRAW_ALL);
1333 /* force TITLE music on title info screen */
1334 game_status = GAME_MODE_TITLE;
1339 game_status = last_game_status; /* restore current game status */
1343 DrawTitleScreenImage(tci->local_nr, tci->initial);
1347 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1349 title.fade_delay_final = title.fade_delay;
1350 title.post_delay_final = title.post_delay;
1351 title.auto_delay_final = -1;
1354 SetMouseCursor(CURSOR_NONE);
1358 DelayReached(&title_delay, 0); /* reset delay counter */
1363 if (title.auto_delay_final > -1 &&
1364 DelayReached(&title_delay, title.auto_delay_final))
1365 button = MB_MENU_CHOICE;
1367 if (button == MB_MENU_LEAVE)
1369 return_to_main_menu = TRUE;
1370 use_fading_main_menu = FALSE;
1372 else if (button == MB_MENU_CHOICE)
1376 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1378 FadeOut(REDRAW_FIELD);
1380 info_mode = INFO_MODE_MAIN;
1381 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1387 tci = &title_controls[title_screen_nr];
1391 graphic_info[getTitleScreenGraphic(tci->local_nr,
1392 tci->initial)].anim_mode;
1394 anim_mode = ANIM_FADE; /* ??? */
1396 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1397 anim_mode == ANIM_CROSSFADE ? TRUE :
1400 if (title_screen_nr < num_title_screens)
1402 if (!use_cross_fading)
1403 FadeOut(REDRAW_ALL);
1405 if (use_cross_fading)
1406 FadeCrossSaveBackbuffer();
1409 DrawTitleScreenImage(tci->local_nr, tci->initial);
1411 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1413 if (use_cross_fading)
1414 FadeCross(REDRAW_ALL);
1418 DelayReached(&title_delay, 0); /* reset delay counter */
1422 FadeSoundsAndMusic();
1424 FadeOut(REDRAW_ALL);
1426 return_to_main_menu = TRUE;
1430 if (return_to_main_menu)
1434 SetMouseCursor(CURSOR_DEFAULT);
1436 if (game_status == GAME_MODE_INFO)
1438 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1440 info_mode = INFO_MODE_MAIN;
1441 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1443 else /* default: return to main menu */
1445 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1447 game_status = GAME_MODE_MAIN;
1448 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1455 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1457 static unsigned long title_delay = 0;
1458 static int title_nr = 0;
1459 static boolean showing_message = FALSE;
1460 char *filename = getLevelSetMessageFilename();
1461 boolean return_to_main_menu = FALSE;
1462 boolean use_fading_main_menu = TRUE;
1463 boolean use_cross_fading = !show_title_initial; /* default */
1464 boolean no_title_info = (graphic_info[IMG_TITLESCREEN_1].bitmap == NULL &&
1465 getLevelSetMessageFilename(1, FALSE) == NULL);
1467 if (button == MB_MENU_INITIALIZE)
1469 int last_game_status = game_status; /* save current game status */
1473 showing_message = FALSE;
1475 if (show_title_initial &&
1476 graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap == NULL &&
1477 getLevelSetMessageFilename(1, TRUE) == NULL)
1478 show_title_initial = FALSE;
1480 if (game_status == GAME_MODE_INFO)
1484 DrawInfoScreen_NotAvailable("Title screen information:",
1485 "No title screen for this level set.");
1487 title.auto_delay_final = -1;
1492 FadeSoundsAndMusic();
1494 FadeOut(REDRAW_ALL);
1497 /* force TITLE music on title info screen */
1498 game_status = GAME_MODE_TITLE;
1503 game_status = last_game_status; /* restore current game status */
1505 if (graphic_info[getTitleScreenGraphic(0, show_title_initial)].bitmap != NULL)
1507 DrawTitleScreenImage(title_nr, show_title_initial);
1511 DrawTitleScreenMessage(filename);
1513 showing_message = TRUE;
1515 title.fade_delay_final = title.fade_delay;
1516 title.post_delay_final = title.post_delay;
1517 title.auto_delay_final = -1;
1522 DelayReached(&title_delay, 0); /* reset delay counter */
1527 if (title.auto_delay_final > -1 &&
1528 DelayReached(&title_delay, title.auto_delay_final))
1529 button = MB_MENU_CHOICE;
1531 if (button == MB_MENU_LEAVE)
1533 return_to_main_menu = TRUE;
1534 use_fading_main_menu = FALSE;
1536 else if (button == MB_MENU_CHOICE)
1540 if (game_status == GAME_MODE_INFO && no_title_info)
1542 FadeOut(REDRAW_FIELD);
1544 info_mode = INFO_MODE_MAIN;
1545 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1552 if (show_title_initial &&
1553 (title_nr >= MAX_NUM_TITLE_IMAGES ||
1554 graphic_info[IMG_TITLESCREEN_INITIAL_1 + title_nr].bitmap == NULL))
1556 show_title_initial = FALSE;
1558 title_nr = 0; /* restart with title screens for current level set */
1561 anim_mode = graphic_info[getTitleScreenGraphic(title_nr, show_title_initial)].anim_mode;
1563 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1564 anim_mode == ANIM_CROSSFADE ? TRUE :
1567 if (!use_cross_fading)
1568 FadeOut(REDRAW_ALL);
1570 if (title_nr < MAX_NUM_TITLE_IMAGES &&
1571 graphic_info[getTitleScreenGraphic(title_nr, show_title_initial)].bitmap != NULL)
1573 if (use_cross_fading)
1574 FadeCrossSaveBackbuffer();
1576 DrawTitleScreenImage(title_nr, show_title_initial);
1578 if (use_cross_fading)
1579 FadeCross(REDRAW_ALL);
1583 DelayReached(&title_delay, 0); /* reset delay counter */
1585 else if (!showing_message && filename != NULL)
1587 if (use_cross_fading)
1588 FadeCrossSaveBackbuffer();
1590 DrawTitleScreenMessage(filename);
1592 if (use_cross_fading)
1593 FadeCross(REDRAW_ALL);
1597 DelayReached(&title_delay, 0); /* reset delay counter */
1599 showing_message = TRUE;
1603 FadeSoundsAndMusic();
1605 FadeOut(REDRAW_ALL);
1607 return_to_main_menu = TRUE;
1611 if (return_to_main_menu)
1613 show_title_initial = FALSE;
1617 if (game_status == GAME_MODE_INFO)
1619 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1621 info_mode = INFO_MODE_MAIN;
1622 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1624 else /* default: return to main menu */
1626 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1628 game_status = GAME_MODE_MAIN;
1629 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1635 void HandleMainMenu_SelectLevel(int step, int direction)
1637 int old_level_nr = level_nr;
1640 new_level_nr = old_level_nr + step * direction;
1641 if (new_level_nr < leveldir_current->first_level)
1642 new_level_nr = leveldir_current->first_level;
1643 if (new_level_nr > leveldir_current->last_level)
1644 new_level_nr = leveldir_current->last_level;
1646 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1648 /* skipping levels is only allowed when trying to skip single level */
1649 if (setup.skip_levels && step == 1 &&
1650 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1652 leveldir_current->handicap_level++;
1653 SaveLevelSetup_SeriesInfo();
1656 new_level_nr = leveldir_current->handicap_level;
1659 if (new_level_nr != old_level_nr)
1661 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1663 PlaySound(SND_MENU_ITEM_SELECTING);
1665 level_nr = new_level_nr;
1668 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1669 int2str(level_nr, 3), mci->pos_text->font);
1671 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1674 LoadLevel(level_nr);
1675 DrawPreviewLevel(TRUE);
1679 DrawCompleteVideoDisplay();
1681 /* needed because DrawPreviewLevel() takes some time */
1689 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1691 static int choice = MAIN_CONTROL_GAME;
1695 if (button == MB_MENU_INITIALIZE)
1697 DrawCursorAndText_Main(choice, TRUE);
1702 if (mx || my) /* mouse input */
1706 for (i = 0; main_controls[i].nr != -1; i++)
1708 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1709 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1710 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1712 pos = main_controls[i].nr;
1718 else if (dx || dy) /* keyboard input */
1720 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1721 choice == MAIN_CONTROL_SETUP))
1722 button = MB_MENU_CHOICE;
1727 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1729 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1731 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1737 PlaySound(SND_MENU_ITEM_ACTIVATING);
1739 DrawCursorAndText_Main(choice, FALSE);
1740 DrawCursorAndText_Main(pos, TRUE);
1747 PlaySound(SND_MENU_ITEM_SELECTING);
1749 if (pos == MAIN_CONTROL_NAME)
1751 game_status = GAME_MODE_PSEUDO_TYPENAME;
1753 HandleTypeName(strlen(setup.player_name), 0);
1755 else if (pos == MAIN_CONTROL_LEVELS)
1759 game_status = GAME_MODE_LEVELS;
1761 SaveLevelSetup_LastSeries();
1762 SaveLevelSetup_SeriesInfo();
1771 else if (pos == MAIN_CONTROL_SCORES)
1773 game_status = GAME_MODE_SCORES;
1777 else if (pos == MAIN_CONTROL_EDITOR)
1779 if (leveldir_current->readonly &&
1780 !strEqual(setup.player_name, "Artsoft"))
1781 Request("This level is read only !", REQ_CONFIRM);
1783 game_status = GAME_MODE_EDITOR;
1787 else if (pos == MAIN_CONTROL_INFO)
1789 game_status = GAME_MODE_INFO;
1790 info_mode = INFO_MODE_MAIN;
1794 else if (pos == MAIN_CONTROL_GAME)
1796 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1798 else if (pos == MAIN_CONTROL_SETUP)
1800 game_status = GAME_MODE_SETUP;
1801 setup_mode = SETUP_MODE_MAIN;
1805 else if (pos == MAIN_CONTROL_QUIT)
1807 SaveLevelSetup_LastSeries();
1808 SaveLevelSetup_SeriesInfo();
1810 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1811 game_status = GAME_MODE_QUIT;
1816 if (game_status == GAME_MODE_MAIN)
1818 DrawPreviewLevel(FALSE);
1825 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1827 static int choice = 5;
1831 if (button == MB_MENU_INITIALIZE)
1833 drawCursor(choice, TRUE);
1838 if (mx || my) /* mouse input */
1840 x = (mx - mSX) / 32;
1841 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1843 else if (dx || dy) /* keyboard input */
1845 if (dx && choice == 1)
1846 x = (dx < 0 ? 10 : 14);
1849 if (choice == 4 || choice == 6)
1850 button = MB_MENU_CHOICE;
1856 if (y == 1 && dx != 0 && button)
1858 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1860 else if (IN_VIS_FIELD(x, y) &&
1861 y >= 0 && y <= 7 && (y != 1 || x < 10))
1867 drawCursor(choice, FALSE);
1868 drawCursor(y, TRUE);
1877 game_status = GAME_MODE_PSEUDO_TYPENAME;
1878 HandleTypeName(strlen(setup.player_name), 0);
1884 game_status = GAME_MODE_LEVELS;
1885 SaveLevelSetup_LastSeries();
1886 SaveLevelSetup_SeriesInfo();
1897 game_status = GAME_MODE_SCORES;
1902 if (leveldir_current->readonly &&
1903 !strEqual(setup.player_name, "Artsoft"))
1904 Request("This level is read only !", REQ_CONFIRM);
1905 game_status = GAME_MODE_EDITOR;
1910 game_status = GAME_MODE_INFO;
1911 info_mode = INFO_MODE_MAIN;
1916 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1920 game_status = GAME_MODE_SETUP;
1921 setup_mode = SETUP_MODE_MAIN;
1927 SaveLevelSetup_LastSeries();
1928 SaveLevelSetup_SeriesInfo();
1930 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1931 game_status = GAME_MODE_QUIT;
1936 if (game_status == GAME_MODE_MAIN)
1938 DrawPreviewLevel(FALSE);
1946 /* ========================================================================= */
1947 /* info screen functions */
1948 /* ========================================================================= */
1950 static struct TokenInfo *info_info;
1951 static int num_info_info;
1953 static void execInfoTitleScreen()
1955 info_mode = INFO_MODE_TITLE;
1959 static void execInfoElements()
1961 info_mode = INFO_MODE_ELEMENTS;
1965 static void execInfoMusic()
1967 info_mode = INFO_MODE_MUSIC;
1971 static void execInfoCredits()
1973 info_mode = INFO_MODE_CREDITS;
1977 static void execInfoProgram()
1979 info_mode = INFO_MODE_PROGRAM;
1983 static void execInfoVersion()
1985 info_mode = INFO_MODE_VERSION;
1989 static void execInfoLevelSet()
1991 info_mode = INFO_MODE_LEVELSET;
1995 static void execExitInfo()
1997 game_status = GAME_MODE_MAIN;
2001 static struct TokenInfo info_info_main[] =
2003 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2004 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2005 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2006 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2007 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2008 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2009 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2010 { TYPE_EMPTY, NULL, "" },
2011 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2016 static void DrawCursorAndText_Info(int pos, boolean active)
2018 int xpos = MENU_SCREEN_START_XPOS;
2019 int ypos = MENU_SCREEN_START_YPOS + pos;
2020 int font_nr = FONT_MENU_1;
2023 font_nr = FONT_ACTIVE(font_nr);
2025 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2027 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2028 drawCursor(pos, active);
2031 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2036 CloseDoor(DOOR_CLOSE_2);
2040 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2042 info_info = info_info_main;
2045 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2048 int xpos = MENU_SCREEN_START_XPOS;
2049 int ypos = MENU_SCREEN_START_YPOS + i;
2050 int font_nr = FONT_MENU_1;
2053 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2054 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2055 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2056 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2057 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2058 initCursor(i, IMG_MENU_BUTTON);
2061 DrawCursorAndText_Info(i, FALSE);
2063 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2069 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2074 DrawMaskedBorder(REDRAW_ALL);
2077 FadeIn(redraw_mask);
2084 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2086 static int choice_store[MAX_INFO_MODES];
2087 int choice = choice_store[info_mode]; /* always starts with 0 */
2091 if (button == MB_MENU_INITIALIZE)
2093 /* advance to first valid menu entry */
2094 while (choice < num_info_info &&
2095 info_info[choice].type & TYPE_SKIP_ENTRY)
2097 choice_store[info_mode] = choice;
2100 DrawCursorAndText_Info(choice, TRUE);
2102 drawCursor(choice, TRUE);
2107 else if (button == MB_MENU_LEAVE)
2109 for (y = 0; y < num_info_info; y++)
2111 if (info_info[y].type & TYPE_LEAVE_MENU)
2113 void (*menu_callback_function)(void) = info_info[y].value;
2115 menu_callback_function();
2117 break; /* absolutely needed because function changes 'info_info'! */
2124 if (mx || my) /* mouse input */
2126 x = (mx - mSX) / 32;
2127 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2129 else if (dx || dy) /* keyboard input */
2133 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2135 if (info_info[choice].type & menu_navigation_type ||
2136 info_info[choice].type & TYPE_ENTER_SCREEN ||
2137 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2138 button = MB_MENU_CHOICE;
2143 /* jump to next non-empty menu entry (up or down) */
2144 while (y > 0 && y < num_info_info - 1 &&
2145 info_info[y].type & TYPE_SKIP_ENTRY)
2149 if (IN_VIS_FIELD(x, y) &&
2150 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2156 PlaySound(SND_MENU_ITEM_ACTIVATING);
2159 DrawCursorAndText_Info(choice, FALSE);
2160 DrawCursorAndText_Info(y, TRUE);
2162 drawCursor(choice, FALSE);
2163 drawCursor(y, TRUE);
2166 choice = choice_store[info_mode] = y;
2169 else if (!(info_info[y].type & TYPE_GHOSTED))
2171 PlaySound(SND_MENU_ITEM_SELECTING);
2173 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2175 void (*menu_callback_function)(void) = info_info[choice].value;
2177 menu_callback_function();
2183 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2186 int ystart1 = mSY - SY + 100;
2187 int ystart2 = mSY - SY + 150;
2188 int ybottom = mSY - SY + SYSIZE - 20;
2192 int ybottom = SYSIZE - 20;
2195 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2197 FadeOut(REDRAW_FIELD);
2202 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2203 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2205 DrawTextSCentered(ybottom, FONT_TEXT_4,
2206 "Press any key or button for info menu");
2208 FadeIn(REDRAW_FIELD);
2211 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2213 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2214 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2215 int xstart = mSX + 16;
2216 int ystart1 = mSY - SY + 100;
2217 int ystart2 = mSY + 64 + 2 * 32;
2218 int ybottom = mSY - SY + SYSIZE - 20;
2219 int ystep = TILEY + 4;
2220 int element, action, direction;
2228 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2229 infoscreen_step[i] = infoscreen_frame[i] = 0;
2234 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2236 DrawTextSCentered(ybottom, FONT_TEXT_4,
2237 "Press any key or button for next page");
2243 while (helpanim_info[j].element != HELPANIM_LIST_END)
2245 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2250 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2259 j += infoscreen_step[i - start];
2261 element = helpanim_info[j].element;
2262 action = helpanim_info[j].action;
2263 direction = helpanim_info[j].direction;
2266 element = EL_UNKNOWN;
2268 if (action != -1 && direction != -1)
2269 graphic = el_act_dir2img(element, action, direction);
2270 else if (action != -1)
2271 graphic = el_act2img(element, action);
2272 else if (direction != -1)
2273 graphic = el_dir2img(element, direction);
2275 graphic = el2img(element);
2277 delay = helpanim_info[j++].delay;
2282 if (infoscreen_frame[i - start] == 0)
2285 infoscreen_frame[i - start] = delay - 1;
2289 sync_frame = delay - infoscreen_frame[i - start];
2290 infoscreen_frame[i - start]--;
2293 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2295 if (!infoscreen_frame[i - start])
2296 infoscreen_step[i - start] = 0;
2300 if (!infoscreen_frame[i - start])
2301 infoscreen_step[i - start]++;
2302 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2308 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2310 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2311 graphic, sync_frame, USE_MASKING);
2314 DrawInfoScreen_HelpText(element, action, direction, i - start);
2319 redraw_mask |= REDRAW_FIELD;
2324 static char *getHelpText(int element, int action, int direction)
2326 char token[MAX_LINE_LEN];
2328 strcpy(token, element_info[element].token_name);
2331 strcat(token, element_action_info[action].suffix);
2333 if (direction != -1)
2334 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2336 return getHashEntry(helptext_info, token);
2339 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2342 int font_nr = FONT_INFO_ELEMENTS;
2344 int font_nr = FONT_LEVEL_NUMBER;
2346 int font_width = getFontWidth(font_nr);
2347 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2348 int sy = mSY + 65 + 2 * 32 + 1;
2349 int ystep = TILEY + 4;
2350 int pad_x = sx - SX;
2351 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2352 int max_lines_per_text = 2;
2355 if (action != -1 && direction != -1) /* element.action.direction */
2356 text = getHelpText(element, action, direction);
2358 if (text == NULL && action != -1) /* element.action */
2359 text = getHelpText(element, action, -1);
2361 if (text == NULL && direction != -1) /* element.direction */
2362 text = getHelpText(element, -1, direction);
2364 if (text == NULL) /* base element */
2365 text = getHelpText(element, -1, -1);
2367 if (text == NULL) /* not found */
2368 text = "No description available";
2370 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2371 sy += getFontHeight(font_nr) / 2;
2374 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2375 max_chars_per_line, -1, max_lines_per_text, -1,
2376 TRUE, FALSE, FALSE);
2378 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2379 max_chars_per_line, max_lines_per_text);
2383 void DrawInfoScreen_TitleScreen()
2388 void HandleInfoScreen_TitleScreen(int button)
2390 HandleTitleScreen(0, 0, 0, 0, button);
2393 void DrawInfoScreen_Elements()
2395 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2397 FadeOut(REDRAW_FIELD);
2402 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2404 FadeIn(REDRAW_FIELD);
2409 void HandleInfoScreen_Elements(int button)
2411 static unsigned long info_delay = 0;
2412 static int num_anims;
2413 static int num_pages;
2415 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2418 if (button == MB_MENU_INITIALIZE)
2420 boolean new_element = TRUE;
2424 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2426 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2428 else if (new_element)
2431 new_element = FALSE;
2435 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2439 if (button == MB_MENU_LEAVE)
2441 PlaySound(SND_MENU_ITEM_SELECTING);
2443 info_mode = INFO_MODE_MAIN;
2448 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2450 if (button != MB_MENU_INITIALIZE)
2452 PlaySound(SND_MENU_ITEM_SELECTING);
2457 if (page >= num_pages)
2459 FadeSoundsAndMusic();
2460 FadeOut(REDRAW_FIELD);
2462 info_mode = INFO_MODE_MAIN;
2463 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2468 if (button != MB_MENU_INITIALIZE)
2469 FadeCrossSaveBackbuffer();
2471 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2473 if (button != MB_MENU_INITIALIZE)
2474 FadeCross(REDRAW_FIELD);
2478 if (DelayReached(&info_delay, GameFrameDelay))
2479 if (page < num_pages)
2480 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2482 PlayMenuSoundIfLoop();
2486 void DrawInfoScreen_Music()
2488 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2490 FadeOut(REDRAW_FIELD);
2497 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2499 FadeIn(REDRAW_FIELD);
2502 void HandleInfoScreen_Music(int button)
2504 static struct MusicFileInfo *list = NULL;
2505 int ystart1 = mSY - SY + 100;
2506 int ystart2 = mSY - SY + 150;
2507 int ybottom = mSY - SY + SYSIZE - 20;
2510 if (button == MB_MENU_INITIALIZE)
2512 list = music_file_info;
2516 FadeSoundsAndMusic();
2521 DrawTextSCentered(ystart1, FONT_TEXT_1,
2522 "No music info for this level set.");
2524 DrawTextSCentered(ybottom, FONT_TEXT_4,
2525 "Press any key or button for info menu");
2531 if (button == MB_MENU_LEAVE)
2533 PlaySound(SND_MENU_ITEM_SELECTING);
2535 FadeSoundsAndMusic();
2537 info_mode = INFO_MODE_MAIN;
2542 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2546 if (button != MB_MENU_INITIALIZE)
2548 PlaySound(SND_MENU_ITEM_SELECTING);
2556 FadeSoundsAndMusic();
2557 FadeOut(REDRAW_FIELD);
2559 info_mode = INFO_MODE_MAIN;
2560 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2565 FadeSoundsAndMusic();
2567 if (button != MB_MENU_INITIALIZE)
2568 FadeCrossSaveBackbuffer();
2575 int sound = list->music;
2577 if (sound_info[sound].loop)
2578 PlaySoundLoop(sound);
2582 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2586 PlayMusic(list->music);
2588 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2591 if (!strEqual(list->title, UNKNOWN_NAME))
2593 if (!strEqual(list->title_header, UNKNOWN_NAME))
2594 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2596 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2599 if (!strEqual(list->artist, UNKNOWN_NAME))
2601 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2602 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2604 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2606 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2609 if (!strEqual(list->album, UNKNOWN_NAME))
2611 if (!strEqual(list->album_header, UNKNOWN_NAME))
2612 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2614 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2616 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2619 if (!strEqual(list->year, UNKNOWN_NAME))
2621 if (!strEqual(list->year_header, UNKNOWN_NAME))
2622 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2624 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2626 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2629 DrawTextSCentered(ybottom, FONT_TEXT_4,
2630 "Press any key or button for next page");
2632 if (button != MB_MENU_INITIALIZE)
2633 FadeCross(REDRAW_FIELD);
2636 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2637 PlaySoundLoop(list->music);
2640 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2642 int ystart1 = mSY - SY + 100;
2643 int ystart2 = mSY - SY + 150;
2644 int ybottom = mSY - SY + SYSIZE - 20;
2653 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2657 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2658 "Special thanks to");
2659 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2661 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2663 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2664 "\"Boulder Dash\"");
2665 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2667 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2669 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2671 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2672 "First Star Software");
2674 else if (screen_nr == 1)
2676 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2677 "Special thanks to");
2678 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2679 "Klaus Heinz & Volker Wertich");
2680 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2682 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2683 "\"Emerald Mine\"");
2684 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2686 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2688 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2690 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2693 else if (screen_nr == 2)
2695 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2696 "Special thanks to");
2697 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2698 "Michael Stopp & Philip Jespersen");
2699 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2701 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2703 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2705 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2707 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2709 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2710 "Digital Integration");
2712 else if (screen_nr == 3)
2714 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2715 "Special thanks to");
2716 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2717 "Hiroyuki Imabayashi");
2718 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2720 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2722 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2724 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2726 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2728 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2731 else if (screen_nr == 4)
2733 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2734 "Special thanks to");
2735 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2737 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2739 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2740 "Jürgen Bonhagen");
2741 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2742 "for the continuous creation");
2743 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2744 "of outstanding level sets");
2746 else if (screen_nr == 5)
2748 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2750 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2752 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2753 "for ideas and inspiration by");
2754 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2757 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2759 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2761 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2762 "for ideas and inspiration by");
2763 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2766 else if (screen_nr == 6)
2768 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2770 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2772 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2773 "for the new Emerald Mine engine");
2775 else if (screen_nr == 7)
2777 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2779 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2781 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2782 "for the initial DOS port");
2784 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2786 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2788 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2789 "for some additional toons");
2791 else if (screen_nr == 8)
2793 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2794 "And not to forget:");
2795 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2797 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2798 "All those who contributed");
2799 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2800 "levels to this game");
2801 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2811 DrawTextSCentered(ybottom, FONT_TEXT_4,
2812 "Press any key or button for next page");
2817 void DrawInfoScreen_Credits()
2819 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2821 FadeSoundsAndMusic();
2823 FadeOut(REDRAW_FIELD);
2825 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2827 FadeIn(REDRAW_FIELD);
2830 void HandleInfoScreen_Credits(int button)
2832 static int screen_nr = 0;
2834 if (button == MB_MENU_INITIALIZE)
2838 DrawInfoScreen_CreditsScreen(screen_nr);
2840 else if (button == MB_MENU_LEAVE)
2842 PlaySound(SND_MENU_ITEM_SELECTING);
2844 info_mode = INFO_MODE_MAIN;
2849 else if (button == MB_MENU_CHOICE)
2851 boolean show_screen;
2853 PlaySound(SND_MENU_ITEM_SELECTING);
2857 FadeCrossSaveBackbuffer();
2859 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
2863 FadeCross(REDRAW_FIELD);
2867 FadeSoundsAndMusic();
2868 FadeOut(REDRAW_FIELD);
2870 info_mode = INFO_MODE_MAIN;
2871 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2876 PlayMenuSoundIfLoop();
2880 void DrawInfoScreen_Program()
2882 int ystart1 = mSY - SY + 100;
2883 int ystart2 = mSY - SY + 150;
2884 int ybottom = mSY - SY + SYSIZE - 20;
2887 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2889 FadeOut(REDRAW_FIELD);
2894 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2896 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2897 "This game is Freeware!");
2898 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2899 "If you like it, send e-mail to:");
2900 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2901 PROGRAM_EMAIL_STRING);
2902 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2903 "or SnailMail to:");
2904 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2906 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2907 "Detmolder Strasse 189");
2908 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2910 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2912 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2913 "More information and levels:");
2914 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2915 PROGRAM_WEBSITE_STRING);
2916 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2917 "If you have created new levels,");
2918 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2919 "send them to me to include them!");
2920 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2923 DrawTextSCentered(ybottom, FONT_TEXT_4,
2924 "Press any key or button for info menu");
2926 FadeIn(REDRAW_FIELD);
2929 void HandleInfoScreen_Program(int button)
2931 if (button == MB_MENU_LEAVE)
2933 PlaySound(SND_MENU_ITEM_SELECTING);
2935 info_mode = INFO_MODE_MAIN;
2940 else if (button == MB_MENU_CHOICE)
2942 PlaySound(SND_MENU_ITEM_SELECTING);
2944 FadeSoundsAndMusic();
2945 FadeOut(REDRAW_FIELD);
2947 info_mode = INFO_MODE_MAIN;
2948 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2952 PlayMenuSoundIfLoop();
2956 void DrawInfoScreen_Version()
2958 int font_header = FONT_TEXT_3;
2959 int font_text = FONT_TEXT_2;
2960 int xstep = getFontWidth(font_text);
2961 int ystep = getFontHeight(font_text);
2962 int ystart1 = mSY - SY + 100;
2963 int ystart2 = mSY - SY + 150;
2964 int ybottom = mSY - SY + SYSIZE - 20;
2965 int xstart1 = mSX + 2 * xstep;
2966 int xstart2 = mSX + 19 * xstep;
2967 #if defined(TARGET_SDL)
2968 int xstart3 = mSX + 29 * xstep;
2969 SDL_version sdl_version_compiled;
2970 const SDL_version *sdl_version_linked;
2971 int driver_name_len = 8;
2972 char driver_name[driver_name_len];
2975 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2977 FadeOut(REDRAW_FIELD);
2982 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2984 DrawTextF(xstart1, ystart2, font_header, "Name");
2985 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2988 DrawTextF(xstart1, ystart2, font_header, "Version");
2989 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2992 DrawTextF(xstart1, ystart2, font_header, "Platform");
2993 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2996 DrawTextF(xstart1, ystart2, font_header, "Target");
2997 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3000 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3001 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3003 #if defined(TARGET_SDL)
3004 ystart2 += 3 * ystep;
3005 DrawTextF(xstart1, ystart2, font_header, "Library");
3006 DrawTextF(xstart2, ystart2, font_header, "compiled");
3007 DrawTextF(xstart3, ystart2, font_header, "linked");
3009 SDL_VERSION(&sdl_version_compiled);
3010 sdl_version_linked = SDL_Linked_Version();
3012 ystart2 += 2 * ystep;
3013 DrawTextF(xstart1, ystart2, font_text, "SDL");
3014 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3015 sdl_version_compiled.major,
3016 sdl_version_compiled.minor,
3017 sdl_version_compiled.patch);
3018 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3019 sdl_version_linked->major,
3020 sdl_version_linked->minor,
3021 sdl_version_linked->patch);
3023 SDL_IMAGE_VERSION(&sdl_version_compiled);
3024 sdl_version_linked = IMG_Linked_Version();
3027 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3028 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3029 sdl_version_compiled.major,
3030 sdl_version_compiled.minor,
3031 sdl_version_compiled.patch);
3032 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3033 sdl_version_linked->major,
3034 sdl_version_linked->minor,
3035 sdl_version_linked->patch);
3037 SDL_MIXER_VERSION(&sdl_version_compiled);
3038 sdl_version_linked = Mix_Linked_Version();
3041 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3042 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3043 sdl_version_compiled.major,
3044 sdl_version_compiled.minor,
3045 sdl_version_compiled.patch);
3046 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3047 sdl_version_linked->major,
3048 sdl_version_linked->minor,
3049 sdl_version_linked->patch);
3051 SDL_NET_VERSION(&sdl_version_compiled);
3052 sdl_version_linked = SDLNet_Linked_Version();
3055 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3056 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3057 sdl_version_compiled.major,
3058 sdl_version_compiled.minor,
3059 sdl_version_compiled.patch);
3060 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3061 sdl_version_linked->major,
3062 sdl_version_linked->minor,
3063 sdl_version_linked->patch);
3065 ystart2 += 3 * ystep;
3066 DrawTextF(xstart1, ystart2, font_header, "Driver");
3067 DrawTextF(xstart2, ystart2, font_header, "Requested");
3068 DrawTextF(xstart3, ystart2, font_header, "Used");
3070 SDL_VideoDriverName(driver_name, driver_name_len);
3072 ystart2 += 2 * ystep;
3073 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3074 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3075 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3077 SDL_AudioDriverName(driver_name, driver_name_len);
3080 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3081 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3082 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3085 DrawTextSCentered(ybottom, FONT_TEXT_4,
3086 "Press any key or button for info menu");
3088 FadeIn(REDRAW_FIELD);
3091 void HandleInfoScreen_Version(int button)
3093 if (button == MB_MENU_LEAVE)
3095 PlaySound(SND_MENU_ITEM_SELECTING);
3097 info_mode = INFO_MODE_MAIN;
3102 else if (button == MB_MENU_CHOICE)
3104 PlaySound(SND_MENU_ITEM_SELECTING);
3106 FadeSoundsAndMusic();
3107 FadeOut(REDRAW_FIELD);
3109 info_mode = INFO_MODE_MAIN;
3110 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3114 PlayMenuSoundIfLoop();
3118 void DrawInfoScreen_LevelSet()
3120 struct TitleMessageInfo *tmi = &readme;
3121 char *filename = getLevelSetInfoFilename();
3123 /* if chars set to "-1", automatically determine by text and font width */
3124 if (tmi->chars == -1)
3125 tmi->chars = tmi->width / getFontWidth(tmi->font);
3127 tmi->width = tmi->chars * getFontWidth(tmi->font);
3129 /* if lines set to "-1", automatically determine by text and font height */
3130 if (tmi->lines == -1)
3131 tmi->lines = tmi->height / getFontHeight(tmi->font);
3133 tmi->height = tmi->lines * getFontHeight(tmi->font);
3135 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3137 FadeOut(REDRAW_FIELD);
3142 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3144 if (filename != NULL)
3145 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3146 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3147 tmi->autowrap, tmi->centered, tmi->skip_comments);
3149 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3150 "No information for this level set.");
3152 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3153 "Press any key or button for info menu");
3155 FadeIn(REDRAW_FIELD);
3158 void HandleInfoScreen_LevelSet(int button)
3160 if (button == MB_MENU_LEAVE)
3162 PlaySound(SND_MENU_ITEM_SELECTING);
3164 info_mode = INFO_MODE_MAIN;
3169 else if (button == MB_MENU_CHOICE)
3171 PlaySound(SND_MENU_ITEM_SELECTING);
3173 FadeSoundsAndMusic();
3174 FadeOut(REDRAW_FIELD);
3176 info_mode = INFO_MODE_MAIN;
3177 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3181 PlayMenuSoundIfLoop();
3185 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3187 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3189 if (info_mode == INFO_MODE_TITLE)
3190 DrawInfoScreen_TitleScreen();
3191 else if (info_mode == INFO_MODE_ELEMENTS)
3192 DrawInfoScreen_Elements();
3193 else if (info_mode == INFO_MODE_MUSIC)
3194 DrawInfoScreen_Music();
3195 else if (info_mode == INFO_MODE_CREDITS)
3196 DrawInfoScreen_Credits();
3197 else if (info_mode == INFO_MODE_PROGRAM)
3198 DrawInfoScreen_Program();
3199 else if (info_mode == INFO_MODE_VERSION)
3200 DrawInfoScreen_Version();
3201 else if (info_mode == INFO_MODE_LEVELSET)
3202 DrawInfoScreen_LevelSet();
3204 DrawInfoScreen_Main(redraw_mask, do_fading);
3206 if (info_mode != INFO_MODE_MAIN &&
3207 info_mode != INFO_MODE_TITLE &&
3208 info_mode != INFO_MODE_MUSIC)
3215 void DrawAndFadeInInfoScreen(int redraw_mask)
3217 DrawInfoScreenExt(redraw_mask, TRUE);
3220 void DrawInfoScreen()
3222 DrawInfoScreenExt(REDRAW_ALL, FALSE);
3225 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3227 if (info_mode == INFO_MODE_TITLE)
3228 HandleInfoScreen_TitleScreen(button);
3229 else if (info_mode == INFO_MODE_ELEMENTS)
3230 HandleInfoScreen_Elements(button);
3231 else if (info_mode == INFO_MODE_MUSIC)
3232 HandleInfoScreen_Music(button);
3233 else if (info_mode == INFO_MODE_CREDITS)
3234 HandleInfoScreen_Credits(button);
3235 else if (info_mode == INFO_MODE_PROGRAM)
3236 HandleInfoScreen_Program(button);
3237 else if (info_mode == INFO_MODE_VERSION)
3238 HandleInfoScreen_Version(button);
3239 else if (info_mode == INFO_MODE_LEVELSET)
3240 HandleInfoScreen_LevelSet(button);
3242 HandleInfoScreen_Main(mx, my, dx, dy, button);
3248 /* ========================================================================= */
3249 /* type name functions */
3250 /* ========================================================================= */
3252 void HandleTypeName(int newxpos, Key key)
3254 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3255 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3257 struct TextPosInfo *pos = mci->pos_input;
3258 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3259 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3262 static int xpos = 0;
3264 static int xpos = 0, ypos = 2;
3266 int font_nr = pos->font;
3267 int font_active_nr = FONT_ACTIVE(font_nr);
3268 int font_width = getFontWidth(font_active_nr);
3271 int startx = mSX + mci->pos_input->x;
3272 int starty = mSY + mci->pos_input->y;
3275 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3276 int startx = mSX + 32 + name_width;
3277 int starty = mSY + ypos * 32;
3279 char key_char = getValidConfigValueChar(getCharFromKey(key));
3280 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3281 boolean is_active = TRUE;
3283 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3287 strcpy(last_player_name, setup.player_name);
3292 /* add one character width for added cursor character */
3293 pos->width += font_width;
3294 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3296 DrawText(startx, starty, setup.player_name, font_active_nr);
3297 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3300 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3302 setup.player_name[xpos] = key_char;
3303 setup.player_name[xpos + 1] = 0;
3308 /* add one character width for added name text character */
3309 pos->width += font_width;
3310 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3312 DrawText(startx, starty, setup.player_name, font_active_nr);
3313 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3316 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3320 setup.player_name[xpos] = 0;
3323 /* remove one character width for removed name text character */
3324 pos->width -= font_width;
3325 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3327 DrawText(startx, starty, setup.player_name, font_active_nr);
3328 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3331 else if (key == KSYM_Return && xpos > 0)
3334 /* remove one character width for removed cursor text character */
3335 pos->width -= font_width;
3336 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3338 DrawText(startx, starty, setup.player_name, font_nr);
3339 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3346 game_status = GAME_MODE_MAIN;
3348 else if (key == KSYM_Escape)
3350 strcpy(setup.player_name, last_player_name);
3354 game_status = GAME_MODE_MAIN;
3359 pos->width = (strlen(setup.player_name) + 1) * font_width;
3360 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3362 DrawText(startx, starty, setup.player_name, font_active_nr);
3363 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3367 pos->width = strlen(setup.player_name) * font_width;
3368 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3370 DrawText(startx, starty, setup.player_name, font_nr);
3375 /* ========================================================================= */
3376 /* tree menu functions */
3377 /* ========================================================================= */
3379 static void DrawChooseTree(TreeInfo **ti_ptr)
3383 FreeScreenGadgets();
3384 CreateScreenGadgets();
3386 CloseDoor(DOOR_CLOSE_2);
3390 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3391 MapScreenTreeGadgets(*ti_ptr);
3397 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3399 struct GadgetInfo *gi = screen_gadget[id];
3400 int items_max, items_visible, item_position;
3402 items_max = numTreeInfoInGroup(ti);
3403 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3404 item_position = first_entry;
3406 if (item_position > items_max - items_visible)
3407 item_position = items_max - items_visible;
3409 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3410 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3411 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3414 static void drawChooseTreeList(int first_entry, int num_page_entries,
3418 char *title_string = NULL;
3419 int yoffset_sets = MENU_TITLE1_YPOS;
3420 int yoffset_setup = 16;
3421 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3423 int last_game_status = game_status; /* save current game status */
3425 title_string = ti->infotext;
3427 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3429 /* force LEVELS font on artwork setup screen */
3430 game_status = GAME_MODE_LEVELS;
3433 /* clear tree list area, but not title or scrollbar */
3434 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3435 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3436 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3438 /* clear tree list area, but not title or scrollbar */
3439 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3440 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3441 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3444 for (i = 0; i < num_page_entries; i++)
3446 TreeInfo *node, *node_first;
3447 int entry_pos = first_entry + i;
3448 int xpos = MENU_SCREEN_START_XPOS;
3449 int ypos = MENU_SCREEN_START_YPOS + i;
3450 int startx = mSX + xpos * 32;
3451 int starty = mSY + ypos * 32;
3452 int font_nr = FONT_TEXT_1;
3453 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3454 int startx_text = startx + font_xoffset;
3455 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3456 int text_size = startx_scrollbar - startx_text;
3457 int max_buffer_len = text_size / getFontWidth(font_nr);
3458 char buffer[max_buffer_len + 1];
3460 node_first = getTreeInfoFirstGroupEntry(ti);
3461 node = getTreeInfoFromPos(node_first, entry_pos);
3463 strncpy(buffer, node->name, max_buffer_len);
3464 buffer[max_buffer_len] = '\0';
3466 DrawText(startx, starty, buffer, font_nr + node->color);
3468 if (node->parent_link)
3469 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3470 else if (node->level_group)
3471 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3473 initCursor(i, IMG_MENU_BUTTON);
3476 game_status = last_game_status; /* restore current game status */
3478 redraw_mask |= REDRAW_FIELD;
3481 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3483 TreeInfo *node, *node_first;
3484 int x, last_redraw_mask = redraw_mask;
3485 int ypos = MENU_TITLE2_YPOS;
3486 int font_nr = FONT_TITLE_2;
3488 if (ti->type != TREE_TYPE_LEVEL_DIR)
3491 node_first = getTreeInfoFirstGroupEntry(ti);
3492 node = getTreeInfoFromPos(node_first, entry_pos);
3494 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3496 if (node->parent_link)
3497 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3499 else if (node->level_group)
3500 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3502 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3503 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3504 node->levels, node->class_desc);
3506 /* let BackToFront() redraw only what is needed */
3507 redraw_mask = last_redraw_mask | REDRAW_TILES;
3508 for (x = 0; x < SCR_FIELDX; x++)
3509 MarkTileDirty(x, 1);
3512 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3515 TreeInfo *ti = *ti_ptr;
3517 int y = ti->cl_cursor;
3518 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3519 int num_entries = numTreeInfoInGroup(ti);
3520 int num_page_entries;
3521 int last_game_status = game_status; /* save current game status */
3522 boolean position_set_by_scrollbar = (dx == 999);
3524 /* force LEVELS draw offset on choose level and artwork setup screen */
3525 game_status = GAME_MODE_LEVELS;
3527 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3528 num_page_entries = num_entries;
3530 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3532 game_status = last_game_status; /* restore current game status */
3534 if (button == MB_MENU_INITIALIZE)
3536 int num_entries = numTreeInfoInGroup(ti);
3537 int entry_pos = posTreeInfo(ti);
3539 if (ti->cl_first == -1)
3541 /* only on initialization */
3542 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3543 ti->cl_cursor = entry_pos - ti->cl_first;
3545 else if (ti->cl_cursor >= num_page_entries ||
3546 (num_entries > num_page_entries &&
3547 num_entries - ti->cl_first < num_page_entries))
3549 /* only after change of list size (by custom graphic configuration) */
3550 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3551 ti->cl_cursor = entry_pos - ti->cl_first;
3554 if (position_set_by_scrollbar)
3557 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3560 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3561 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3562 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3566 else if (button == MB_MENU_LEAVE)
3568 PlaySound(SND_MENU_ITEM_SELECTING);
3570 if (ti->node_parent)
3572 *ti_ptr = ti->node_parent;
3573 DrawChooseTree(ti_ptr);
3575 else if (game_status == GAME_MODE_SETUP)
3577 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3579 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3580 execSetupGraphics();
3586 game_status = GAME_MODE_MAIN;
3593 if (mx || my) /* mouse input */
3595 int last_game_status = game_status; /* save current game status */
3597 /* force LEVELS draw offset on artwork setup screen */
3598 game_status = GAME_MODE_LEVELS;
3600 x = (mx - mSX) / 32;
3601 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3603 game_status = last_game_status; /* restore current game status */
3605 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3607 /* move cursor instead of scrolling when already at start/end of list */
3608 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3610 else if (dy == +1 * SCROLL_LINE &&
3611 ti->cl_first + num_page_entries == num_entries)
3614 /* handle scrolling screen one line or page */
3615 if (ti->cl_cursor + dy < 0 ||
3616 ti->cl_cursor + dy > num_page_entries - 1)
3618 if (ABS(dy) == SCROLL_PAGE)
3619 step = num_page_entries - 1;
3621 if (dy < 0 && ti->cl_first > 0)
3623 /* scroll page/line up */
3625 ti->cl_first -= step;
3626 if (ti->cl_first < 0)
3629 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3630 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3631 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3633 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3636 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3638 /* scroll page/line down */
3640 ti->cl_first += step;
3641 if (ti->cl_first + num_page_entries > num_entries)
3642 ti->cl_first = MAX(0, num_entries - num_page_entries);
3644 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3645 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3646 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3648 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3655 /* handle moving cursor one line */
3656 y = ti->cl_cursor + dy;
3661 TreeInfo *node_first, *node_cursor;
3662 int entry_pos = ti->cl_first + y;
3664 node_first = getTreeInfoFirstGroupEntry(ti);
3665 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3667 if (node_cursor->node_group)
3669 PlaySound(SND_MENU_ITEM_SELECTING);
3671 node_cursor->cl_first = ti->cl_first;
3672 node_cursor->cl_cursor = ti->cl_cursor;
3673 *ti_ptr = node_cursor->node_group;
3674 DrawChooseTree(ti_ptr);
3679 else if (dx == -1 && ti->node_parent)
3681 PlaySound(SND_MENU_ITEM_SELECTING);
3683 *ti_ptr = ti->node_parent;
3684 DrawChooseTree(ti_ptr);
3689 if (!anyScrollbarGadgetActive() &&
3690 IN_VIS_FIELD(x, y) &&
3691 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3692 y >= 0 && y < num_page_entries)
3696 if (y != ti->cl_cursor)
3698 PlaySound(SND_MENU_ITEM_ACTIVATING);
3700 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3701 drawChooseTreeCursor(y, TRUE);
3702 drawChooseTreeInfo(ti->cl_first + y, ti);
3709 TreeInfo *node_first, *node_cursor;
3710 int entry_pos = ti->cl_first + y;
3712 PlaySound(SND_MENU_ITEM_SELECTING);
3714 node_first = getTreeInfoFirstGroupEntry(ti);
3715 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3717 if (node_cursor->node_group)
3719 node_cursor->cl_first = ti->cl_first;
3720 node_cursor->cl_cursor = ti->cl_cursor;
3721 *ti_ptr = node_cursor->node_group;
3722 DrawChooseTree(ti_ptr);
3724 else if (node_cursor->parent_link)
3726 *ti_ptr = node_cursor->node_parent;
3727 DrawChooseTree(ti_ptr);
3731 node_cursor->cl_first = ti->cl_first;
3732 node_cursor->cl_cursor = ti->cl_cursor;
3733 *ti_ptr = node_cursor;
3735 if (ti->type == TREE_TYPE_LEVEL_DIR)
3737 LoadLevelSetup_SeriesInfo();
3739 SaveLevelSetup_LastSeries();
3740 SaveLevelSetup_SeriesInfo();
3744 if (game_status == GAME_MODE_SETUP)
3746 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3748 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3749 execSetupGraphics();
3755 game_status = GAME_MODE_MAIN;
3763 void DrawChooseLevel()
3765 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3767 DrawChooseTree(&leveldir_current);
3773 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3775 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3780 void DrawHallOfFame(int highlight_position)
3783 FadeSoundsAndMusic();
3785 /* (this is needed when called from GameEnd() after winning a game) */
3786 KeyboardAutoRepeatOn();
3789 /* (this is needed when called from GameEnd() after winning a game) */
3790 SetDrawDeactivationMask(REDRAW_NONE);
3791 SetDrawBackgroundMask(REDRAW_FIELD);
3793 CloseDoor(DOOR_CLOSE_2);
3795 if (highlight_position < 0)
3796 LoadScore(level_nr);
3798 FadeOut(REDRAW_FIELD);
3805 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3807 FadeIn(REDRAW_FIELD);
3810 static void drawHallOfFameList(int first_entry, int highlight_position)
3814 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3817 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3818 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3819 "HighScores of Level %d", level_nr);
3821 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3823 int entry = first_entry + i;
3824 boolean active = (entry == highlight_position);
3825 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3826 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3827 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3828 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3829 int dx1 = 3 * getFontWidth(font_nr1);
3830 int dx2 = dx1 + getFontWidth(font_nr1);
3831 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3832 int sy = mSY + 64 + i * 32;
3834 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3835 DrawText(mSX + dx1, sy, ".", font_nr1);
3836 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3838 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3839 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3841 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3844 redraw_mask |= REDRAW_FIELD;
3847 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3849 static int first_entry = 0;
3850 static int highlight_position = 0;
3851 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3853 if (button == MB_MENU_INITIALIZE)
3856 highlight_position = mx;
3857 drawHallOfFameList(first_entry, highlight_position);
3862 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3863 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3867 if (first_entry > 0)
3869 first_entry -= step;
3870 if (first_entry < 0)
3873 drawHallOfFameList(first_entry, highlight_position);
3878 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3880 first_entry += step;
3881 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3882 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3884 drawHallOfFameList(first_entry, highlight_position);
3887 else if (button == MB_MENU_LEAVE)
3889 PlaySound(SND_MENU_ITEM_SELECTING);
3891 FadeSound(SND_BACKGROUND_SCORES);
3893 game_status = GAME_MODE_MAIN;
3897 else if (button == MB_MENU_CHOICE)
3899 PlaySound(SND_MENU_ITEM_SELECTING);
3901 FadeSound(SND_BACKGROUND_SCORES);
3902 FadeOut(REDRAW_FIELD);
3904 game_status = GAME_MODE_MAIN;
3906 DrawAndFadeInMainMenu(REDRAW_FIELD);
3909 if (game_status == GAME_MODE_SCORES)
3910 PlayMenuSoundIfLoop();
3916 /* ========================================================================= */
3917 /* setup screen functions */
3918 /* ========================================================================= */
3920 static struct TokenInfo *setup_info;
3921 static int num_setup_info;
3923 static char *screen_mode_text;
3924 static char *game_speed_text;
3925 static char *graphics_set_name;
3926 static char *sounds_set_name;
3927 static char *music_set_name;
3929 static void execSetupMain()
3931 setup_mode = SETUP_MODE_MAIN;
3935 static void execSetupGame()
3937 if (game_speeds == NULL)
3941 for (i = 0; game_speeds_list[i].value != -1; i++)
3943 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3944 char identifier[32], name[32];
3945 int value = game_speeds_list[i].value;
3946 char *text = game_speeds_list[i].text;
3948 ti->node_top = &game_speeds;
3949 ti->sort_priority = 10000 - value;
3951 sprintf(identifier, "%d", value);
3952 sprintf(name, "%s", text);
3954 setString(&ti->identifier, identifier);
3955 setString(&ti->name, name);
3956 setString(&ti->name_sorting, name);
3957 setString(&ti->infotext, "Game Speed");
3959 pushTreeInfo(&game_speeds, ti);
3962 /* sort game speed values to start with slowest game speed */
3963 sortTreeInfo(&game_speeds);
3965 /* set current game speed to configured game speed value */
3966 game_speed_current =
3967 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3969 /* if that fails, set current game speed to reliable default value */
3970 if (game_speed_current == NULL)
3971 game_speed_current =
3972 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3974 /* if that also fails, set current game speed to first available speed */
3975 if (game_speed_current == NULL)
3976 game_speed_current = game_speeds;
3979 setup.game_frame_delay = atoi(game_speed_current->identifier);
3981 /* needed for displaying game speed text instead of identifier */
3982 game_speed_text = game_speed_current->name;
3984 setup_mode = SETUP_MODE_GAME;
3988 static void execSetupChooseGameSpeed()
3990 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3994 static void execSetupEditor()
3996 setup_mode = SETUP_MODE_EDITOR;
4000 static void execSetupGraphics()
4002 if (video.fullscreen_available && screen_modes == NULL)
4006 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4008 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4009 char identifier[32], name[32];
4010 int x = video.fullscreen_modes[i].width;
4011 int y = video.fullscreen_modes[i].height;
4014 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4016 ti->node_top = &screen_modes;
4017 ti->sort_priority = x * 10000 + y;
4019 sprintf(identifier, "%dx%d", x, y);
4020 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4022 setString(&ti->identifier, identifier);
4023 setString(&ti->name, name);
4024 setString(&ti->name_sorting, name);
4025 setString(&ti->infotext, "Fullscreen Mode");
4027 pushTreeInfo(&screen_modes, ti);
4030 /* sort fullscreen modes to start with lowest available screen resolution */
4031 sortTreeInfo(&screen_modes);
4033 /* set current screen mode for fullscreen mode to configured setup value */
4034 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4035 setup.fullscreen_mode);
4037 /* if that fails, set current screen mode to reliable default value */
4038 if (screen_mode_current == NULL)
4039 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4040 DEFAULT_FULLSCREEN_MODE);
4042 /* if that also fails, set current screen mode to first available mode */
4043 if (screen_mode_current == NULL)
4044 screen_mode_current = screen_modes;
4046 if (screen_mode_current == NULL)
4047 video.fullscreen_available = FALSE;
4050 if (video.fullscreen_available)
4052 setup.fullscreen_mode = screen_mode_current->identifier;
4054 /* needed for displaying screen mode name instead of identifier */
4055 screen_mode_text = screen_mode_current->name;
4058 setup_mode = SETUP_MODE_GRAPHICS;
4062 static void execSetupChooseScreenMode()
4064 if (!video.fullscreen_available)
4067 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4071 static void execSetupSound()
4073 setup_mode = SETUP_MODE_SOUND;
4077 static void execSetupArtwork()
4079 setup.graphics_set = artwork.gfx_current->identifier;
4080 setup.sounds_set = artwork.snd_current->identifier;
4081 setup.music_set = artwork.mus_current->identifier;
4083 /* needed if last screen (setup choice) changed graphics, sounds or music */
4084 ReloadCustomArtwork(0);
4086 /* needed for displaying artwork name instead of artwork identifier */
4087 graphics_set_name = artwork.gfx_current->name;
4088 sounds_set_name = artwork.snd_current->name;
4089 music_set_name = artwork.mus_current->name;
4091 setup_mode = SETUP_MODE_ARTWORK;
4095 static void execSetupChooseGraphics()
4097 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4101 static void execSetupChooseSounds()
4103 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4107 static void execSetupChooseMusic()
4109 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4113 static void execSetupInput()
4115 setup_mode = SETUP_MODE_INPUT;
4119 static void execSetupShortcut1()
4121 setup_mode = SETUP_MODE_SHORTCUT_1;
4125 static void execSetupShortcut2()
4127 setup_mode = SETUP_MODE_SHORTCUT_2;
4131 static void execExitSetup()
4133 game_status = GAME_MODE_MAIN;
4137 static void execSaveAndExitSetup()
4143 static struct TokenInfo setup_info_main[] =
4145 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4146 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4147 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4148 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4149 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4150 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4151 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
4152 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
4153 { TYPE_EMPTY, NULL, "" },
4154 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4155 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4160 static struct TokenInfo setup_info_game[] =
4162 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4163 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4164 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4165 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4166 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4167 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4168 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4169 { TYPE_STRING, &game_speed_text, "" },
4170 { TYPE_EMPTY, NULL, "" },
4171 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4176 static struct TokenInfo setup_info_editor[] =
4179 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4180 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4181 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4182 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4183 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4184 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4185 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4186 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4188 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4189 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4190 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4192 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4194 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4195 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4196 { TYPE_EMPTY, NULL, "" },
4198 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4199 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4200 { TYPE_EMPTY, NULL, "" },
4202 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4203 { TYPE_EMPTY, NULL, "" },
4204 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4209 static struct TokenInfo setup_info_graphics[] =
4211 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4212 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4213 { TYPE_STRING, &screen_mode_text, "" },
4214 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
4216 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4217 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4219 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4220 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4221 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4222 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4223 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4224 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4225 { TYPE_EMPTY, NULL, "" },
4226 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4231 static struct TokenInfo setup_info_sound[] =
4233 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4234 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4235 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4236 { TYPE_EMPTY, NULL, "" },
4237 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4242 static struct TokenInfo setup_info_artwork[] =
4244 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4245 { TYPE_STRING, &graphics_set_name, "" },
4246 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4247 { TYPE_STRING, &sounds_set_name, "" },
4248 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4249 { TYPE_STRING, &music_set_name, "" },
4250 { TYPE_EMPTY, NULL, "" },
4252 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4253 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4254 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4256 { TYPE_STRING, NULL, "Override Level Artwork:"},
4257 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4258 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4259 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4261 { TYPE_EMPTY, NULL, "" },
4262 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4267 static struct TokenInfo setup_info_input[] =
4269 { TYPE_SWITCH, NULL, "Player:" },
4270 { TYPE_SWITCH, NULL, "Device:" },
4271 { TYPE_ENTER_MENU, NULL, "" },
4272 { TYPE_EMPTY, NULL, "" },
4273 { TYPE_EMPTY, NULL, "" },
4274 { TYPE_EMPTY, NULL, "" },
4275 { TYPE_EMPTY, NULL, "" },
4276 { TYPE_EMPTY, NULL, "" },
4277 { TYPE_EMPTY, NULL, "" },
4278 { TYPE_EMPTY, NULL, "" },
4279 { TYPE_EMPTY, NULL, "" },
4280 { TYPE_EMPTY, NULL, "" },
4281 { TYPE_EMPTY, NULL, "" },
4282 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4287 static struct TokenInfo setup_info_shortcut_1[] =
4289 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4290 { TYPE_KEY, &setup.shortcut.save_game, "" },
4291 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4292 { TYPE_KEY, &setup.shortcut.load_game, "" },
4293 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4294 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4295 { TYPE_EMPTY, NULL, "" },
4296 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4297 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4298 { TYPE_EMPTY, NULL, "" },
4299 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4304 static struct TokenInfo setup_info_shortcut_2[] =
4306 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4307 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4308 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4309 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4310 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4311 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4312 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4313 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4314 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4315 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4316 { TYPE_EMPTY, NULL, "" },
4317 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4322 static Key getSetupKey()
4324 Key key = KSYM_UNDEFINED;
4325 boolean got_key_event = FALSE;
4327 while (!got_key_event)
4329 if (PendingEvent()) /* got event */
4337 case EVENT_KEYPRESS:
4339 key = GetEventKey((KeyEvent *)&event, TRUE);
4341 /* press 'Escape' or 'Enter' to keep the existing key binding */
4342 if (key == KSYM_Escape || key == KSYM_Return)
4343 key = KSYM_UNDEFINED; /* keep old value */
4345 got_key_event = TRUE;
4349 case EVENT_KEYRELEASE:
4350 key_joystick_mapping = 0;
4354 HandleOtherEvents(&event);
4362 /* don't eat all CPU time */
4369 static int getSetupTextFont(int type)
4371 if (type & (TYPE_SWITCH |
4382 static int getSetupValueFont(int type, void *value)
4384 if (type & TYPE_KEY)
4385 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4386 else if (type & TYPE_STRING)
4387 return FONT_VALUE_2;
4388 else if (type & TYPE_ECS_AGA)
4389 return FONT_VALUE_1;
4390 else if (type & TYPE_BOOLEAN_STYLE)
4391 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4393 return FONT_VALUE_1;
4396 static void drawSetupValue(int pos)
4398 boolean font_draw_xoffset_modified = FALSE;
4399 int font_draw_xoffset_old = -1;
4400 int xpos = MENU_SCREEN_VALUE_XPOS;
4401 int ypos = MENU_SCREEN_START_YPOS + pos;
4402 int startx = mSX + xpos * 32;
4403 int starty = mSY + ypos * 32;
4404 int font_nr, font_width;
4405 int type = setup_info[pos].type;
4406 void *value = setup_info[pos].value;
4407 char *value_string = getSetupValue(type, value);
4410 if (value_string == NULL)
4413 if (type & TYPE_KEY)
4415 xpos = MENU_SCREEN_START_XPOS;
4417 if (type & TYPE_QUERY)
4419 value_string = "<press key>";
4422 else if (type & TYPE_STRING)
4424 int max_value_len = (SCR_FIELDX - 2) * 2;
4426 xpos = MENU_SCREEN_START_XPOS;
4428 if (strlen(value_string) > max_value_len)
4429 value_string[max_value_len] = '\0';
4432 startx = mSX + xpos * 32;
4433 starty = mSY + ypos * 32;
4434 font_nr = getSetupValueFont(type, value);
4435 font_width = getFontWidth(font_nr);
4437 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4438 if (setup_mode != SETUP_MODE_INPUT)
4440 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4441 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4442 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4443 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4444 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4445 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4446 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4447 boolean correct_font_draw_xoffset = FALSE;
4449 if (xpos == MENU_SCREEN_START_XPOS &&
4450 startx + font1_xoffset < text_startx + text_font_xoffset)
4451 correct_font_draw_xoffset = TRUE;
4453 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4454 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4455 correct_font_draw_xoffset = TRUE;
4457 /* check if setup value would overlap with setup text when printed */
4458 /* (this can happen for extreme/wrong values for font draw offset) */
4459 if (correct_font_draw_xoffset)
4461 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4462 font_draw_xoffset_modified = TRUE;
4464 if (type & TYPE_KEY)
4465 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4466 else if (!(type & TYPE_STRING))
4467 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4468 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4472 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4473 DrawText(startx + i * font_width, starty, " ", font_nr);
4475 DrawText(startx, starty, value_string, font_nr);
4477 if (font_draw_xoffset_modified)
4478 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4481 static void changeSetupValue(int pos)
4483 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4485 *(boolean *)setup_info[pos].value ^= TRUE;
4487 else if (setup_info[pos].type & TYPE_KEY)
4491 setup_info[pos].type |= TYPE_QUERY;
4492 drawSetupValue(pos);
4493 setup_info[pos].type &= ~TYPE_QUERY;
4495 key = getSetupKey();
4496 if (key != KSYM_UNDEFINED)
4497 *(Key *)setup_info[pos].value = key;
4500 drawSetupValue(pos);
4503 static void DrawCursorAndText_Setup(int pos, boolean active)
4505 int xpos = MENU_SCREEN_START_XPOS;
4506 int ypos = MENU_SCREEN_START_YPOS + pos;
4507 int font_nr = getSetupTextFont(setup_info[pos].type);
4509 if (setup_info == setup_info_input)
4510 font_nr = FONT_MENU_1;
4513 font_nr = FONT_ACTIVE(font_nr);
4515 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4517 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4518 drawCursor(pos, active);
4521 static void DrawSetupScreen_Generic()
4523 char *title_string = NULL;
4527 CloseDoor(DOOR_CLOSE_2);
4531 if (setup_mode == SETUP_MODE_MAIN)
4533 setup_info = setup_info_main;
4534 title_string = "Setup";
4536 else if (setup_mode == SETUP_MODE_GAME)
4538 setup_info = setup_info_game;
4539 title_string = "Setup Game";
4541 else if (setup_mode == SETUP_MODE_EDITOR)
4543 setup_info = setup_info_editor;
4544 title_string = "Setup Editor";
4546 else if (setup_mode == SETUP_MODE_GRAPHICS)
4548 setup_info = setup_info_graphics;
4549 title_string = "Setup Graphics";
4551 else if (setup_mode == SETUP_MODE_SOUND)
4553 setup_info = setup_info_sound;
4554 title_string = "Setup Sound";
4556 else if (setup_mode == SETUP_MODE_ARTWORK)
4558 setup_info = setup_info_artwork;
4559 title_string = "Custom Artwork";
4561 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
4563 setup_info = setup_info_shortcut_1;
4564 title_string = "Setup Shortcuts";
4566 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
4568 setup_info = setup_info_shortcut_2;
4569 title_string = "Setup Shortcuts";
4572 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4575 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4577 void *value_ptr = setup_info[i].value;
4580 int xpos = MENU_SCREEN_START_XPOS;
4581 int ypos = MENU_SCREEN_START_YPOS + i;
4585 /* set some entries to "unchangeable" according to other variables */
4586 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4587 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4588 (value_ptr == &setup.sound_music && !audio.music_available) ||
4589 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4590 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4591 setup_info[i].type |= TYPE_GHOSTED;
4593 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4594 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4595 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4596 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4597 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4598 initCursor(i, IMG_MENU_BUTTON);
4601 DrawCursorAndText_Setup(i, FALSE);
4603 font_nr = getSetupTextFont(setup_info[i].type);
4605 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
4608 if (setup_info[i].type & TYPE_VALUE)
4615 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4616 "Joysticks deactivated in setup menu");
4621 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4624 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4626 static int choice_store[MAX_SETUP_MODES];
4627 int choice = choice_store[setup_mode]; /* always starts with 0 */
4631 if (button == MB_MENU_INITIALIZE)
4633 /* advance to first valid menu entry */
4634 while (choice < num_setup_info &&
4635 setup_info[choice].type & TYPE_SKIP_ENTRY)
4637 choice_store[setup_mode] = choice;
4640 DrawCursorAndText_Setup(choice, TRUE);
4642 drawCursor(choice, TRUE);
4647 else if (button == MB_MENU_LEAVE)
4649 PlaySound(SND_MENU_ITEM_SELECTING);
4651 for (y = 0; y < num_setup_info; y++)
4653 if (setup_info[y].type & TYPE_LEAVE_MENU)
4655 void (*menu_callback_function)(void) = setup_info[y].value;
4657 menu_callback_function();
4659 break; /* absolutely needed because function changes 'setup_info'! */
4666 if (mx || my) /* mouse input */
4668 x = (mx - mSX) / 32;
4669 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4671 else if (dx || dy) /* keyboard input */
4675 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4677 if (setup_info[choice].type & menu_navigation_type ||
4678 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
4679 button = MB_MENU_CHOICE;
4684 /* jump to next non-empty menu entry (up or down) */
4685 while (y > 0 && y < num_setup_info - 1 &&
4686 setup_info[y].type & TYPE_SKIP_ENTRY)
4690 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4694 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4696 PlaySound(SND_MENU_ITEM_ACTIVATING);
4699 DrawCursorAndText_Setup(choice, FALSE);
4700 DrawCursorAndText_Setup(y, TRUE);
4702 drawCursor(choice, FALSE);
4703 drawCursor(y, TRUE);
4706 choice = choice_store[setup_mode] = y;
4709 else if (!(setup_info[y].type & TYPE_GHOSTED))
4711 PlaySound(SND_MENU_ITEM_SELECTING);
4713 /* when selecting key headline, execute function for key value change */
4714 if (setup_info[y].type & TYPE_KEYTEXT &&
4715 setup_info[y + 1].type & TYPE_KEY)
4718 /* when selecting string value, execute function for list selection */
4719 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4720 setup_info[y - 1].type & TYPE_ENTER_LIST)
4723 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4725 void (*menu_callback_function)(void) = setup_info[y].value;
4727 menu_callback_function();
4731 if (setup_info[y].type & TYPE_VALUE)
4732 changeSetupValue(y);
4738 void DrawSetupScreen_Input()
4747 setup_info = setup_info_input;
4750 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4753 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4755 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4756 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4757 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4758 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4759 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4760 initCursor(i, IMG_MENU_BUTTON);
4762 DrawCursorAndText_Setup(i, FALSE);
4765 initCursor(0, IMG_MENU_BUTTON);
4766 initCursor(1, IMG_MENU_BUTTON);
4767 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
4768 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
4770 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
4771 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
4772 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
4776 DeactivateJoystickForCalibration();
4779 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4780 "Joysticks deactivated on this screen");
4783 /* create gadgets for setup input menu screen */
4784 FreeScreenGadgets();
4785 CreateScreenGadgets();
4787 /* map gadgets for setup input menu screen */
4788 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4790 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4795 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4797 if (device_name == NULL)
4800 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4803 if (strlen(device_name) > 1)
4805 char c1 = device_name[strlen(device_name) - 1];
4806 char c2 = device_name[strlen(device_name) - 2];
4808 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4809 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4812 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4813 strlen(device_name));
4816 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4819 static struct SetupKeyboardInfo custom_key;
4826 { &custom_key.left, "Joystick Left" },
4827 { &custom_key.right, "Joystick Right" },
4828 { &custom_key.up, "Joystick Up" },
4829 { &custom_key.down, "Joystick Down" },
4830 { &custom_key.snap, "Button 1" },
4831 { &custom_key.drop, "Button 2" }
4833 static char *joystick_name[MAX_PLAYERS] =
4840 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4844 custom_key = setup.input[player_nr].key;
4846 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4847 FONT_INPUT_1_ACTIVE);
4849 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4851 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4852 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4854 if (setup.input[player_nr].use_joystick)
4856 char *device_name = setup.input[player_nr].joy.device_name;
4857 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4858 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4860 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4861 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4865 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4866 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4869 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4871 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4872 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4873 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4874 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4876 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4877 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4878 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4879 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4880 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4881 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4883 for (i = 0; i < 6; i++)
4885 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4887 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4889 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4890 (setup.input[player_nr].use_joystick ?
4892 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4896 static int input_player_nr = 0;
4898 void HandleSetupScreen_Input_Player(int step, int direction)
4900 int old_player_nr = input_player_nr;
4903 new_player_nr = old_player_nr + step * direction;
4904 if (new_player_nr < 0)
4906 if (new_player_nr > MAX_PLAYERS - 1)
4907 new_player_nr = MAX_PLAYERS - 1;
4909 if (new_player_nr != old_player_nr)
4911 input_player_nr = new_player_nr;
4913 drawPlayerSetupInputInfo(input_player_nr, FALSE);
4917 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
4919 static int choice = 0;
4922 int pos_start = SETUPINPUT_SCREEN_POS_START;
4923 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
4924 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
4925 int pos_end = SETUPINPUT_SCREEN_POS_END;
4927 if (button == MB_MENU_INITIALIZE)
4929 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
4932 DrawCursorAndText_Setup(choice, TRUE);
4934 drawCursor(choice, TRUE);
4939 else if (button == MB_MENU_LEAVE)
4941 setup_mode = SETUP_MODE_MAIN;
4948 if (mx || my) /* mouse input */
4950 x = (mx - mSX) / 32;
4951 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4953 else if (dx || dy) /* keyboard input */
4955 if (dx && choice == 0)
4956 x = (dx < 0 ? 10 : 12);
4957 else if ((dx && choice == 1) ||
4958 (dx == +1 && choice == 2) ||
4959 (dx == -1 && choice == pos_end))
4960 button = MB_MENU_CHOICE;
4964 if (y >= pos_empty1 && y <= pos_empty2)
4965 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
4968 if (y == 0 && dx != 0 && button)
4970 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
4972 else if (IN_VIS_FIELD(x, y) &&
4973 y >= pos_start && y <= pos_end &&
4974 !(y >= pos_empty1 && y <= pos_empty2))
4981 DrawCursorAndText_Setup(choice, FALSE);
4982 DrawCursorAndText_Setup(y, TRUE);
4984 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
4986 drawCursor(choice, FALSE);
4987 drawCursor(y, TRUE);
4997 char *device_name = setup.input[input_player_nr].joy.device_name;
4999 if (!setup.input[input_player_nr].use_joystick)
5001 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5003 setJoystickDeviceToNr(device_name, new_device_nr);
5004 setup.input[input_player_nr].use_joystick = TRUE;
5008 int device_nr = getJoystickNrFromDeviceName(device_name);
5009 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5011 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5012 setup.input[input_player_nr].use_joystick = FALSE;
5014 setJoystickDeviceToNr(device_name, new_device_nr);
5017 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5021 if (setup.input[input_player_nr].use_joystick)
5024 CalibrateJoystick(input_player_nr);
5027 CustomizeKeyboard(input_player_nr);
5029 else if (y == pos_end)
5033 setup_mode = SETUP_MODE_MAIN;
5040 void CustomizeKeyboard(int player_nr)
5044 boolean finished = FALSE;
5045 static struct SetupKeyboardInfo custom_key;
5050 } customize_step[] =
5052 { &custom_key.left, "Move Left" },
5053 { &custom_key.right, "Move Right" },
5054 { &custom_key.up, "Move Up" },
5055 { &custom_key.down, "Move Down" },
5056 { &custom_key.snap, "Snap Field" },
5057 { &custom_key.drop, "Drop Element" }
5060 /* read existing key bindings from player setup */
5061 custom_key = setup.input[player_nr].key;
5065 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5071 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5072 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5073 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5074 "Key:", FONT_INPUT_1_ACTIVE);
5075 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5076 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5080 if (PendingEvent()) /* got event */
5088 case EVENT_KEYPRESS:
5090 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5092 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5098 /* all keys configured -- wait for "Escape" or "Return" key */
5102 /* press 'Enter' to keep the existing key binding */
5103 if (key == KSYM_Return)
5104 key = *customize_step[step_nr].key;
5106 /* check if key already used */
5107 for (i = 0; i < step_nr; i++)
5108 if (*customize_step[i].key == key)
5113 /* got new key binding */
5114 *customize_step[step_nr].key = key;
5115 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5117 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5118 getKeyNameFromKey(key), FONT_VALUE_1);
5121 /* un-highlight last query */
5122 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5123 customize_step[step_nr - 1].text, FONT_MENU_1);
5124 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5125 "Key:", FONT_MENU_1);
5127 /* press 'Enter' to leave */
5130 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5131 "Press Enter", FONT_TITLE_1);
5135 /* query next key binding */
5136 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5137 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5138 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5139 "Key:", FONT_INPUT_1_ACTIVE);
5140 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5141 getKeyNameFromKey(*customize_step[step_nr].key),
5146 case EVENT_KEYRELEASE:
5147 key_joystick_mapping = 0;
5151 HandleOtherEvents(&event);
5159 /* don't eat all CPU time */
5163 /* write new key bindings back to player setup */
5164 setup.input[player_nr].key = custom_key;
5167 DrawSetupScreen_Input();
5170 static boolean CalibrateJoystickMain(int player_nr)
5172 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5173 int new_joystick_xright = JOYSTICK_XMIDDLE;
5174 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5175 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5176 int new_joystick_xmiddle, new_joystick_ymiddle;
5178 int joystick_fd = joystick.fd[player_nr];
5179 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5180 boolean check[3][3];
5181 int check_remaining = 3 * 3;
5186 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5189 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5194 for (y = 0; y < 3; y++)
5196 for (x = 0; x < 3; x++)
5198 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5199 check[x][y] = FALSE;
5203 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5204 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5205 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5206 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5207 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5208 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5209 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5211 joy_value = Joystick(player_nr);
5212 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5213 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5215 /* eventually uncalibrated center position (joystick could be uncentered) */
5216 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5219 new_joystick_xmiddle = joy_x;
5220 new_joystick_ymiddle = joy_y;
5222 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5225 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5230 if (PendingEvent()) /* got event */
5238 case EVENT_KEYPRESS:
5239 switch (GetEventKey((KeyEvent *)&event, TRUE))
5242 if (check_remaining == 0)
5255 case EVENT_KEYRELEASE:
5256 key_joystick_mapping = 0;
5260 HandleOtherEvents(&event);
5265 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5268 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5269 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5270 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5271 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5273 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5274 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5275 setup.input[player_nr].joy.xright = new_joystick_xright;
5276 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5277 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5278 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5280 CheckJoystickData();
5282 joy_value = Joystick(player_nr);
5284 if (joy_value & JOY_BUTTON && check_remaining == 0)
5287 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5288 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5290 if (x != last_x || y != last_y)
5292 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5293 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5298 if (check_remaining > 0 && !check[x+1][y+1])
5300 check[x+1][y+1] = TRUE;
5306 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5307 setup.input[player_nr].joy.xleft,
5308 setup.input[player_nr].joy.xmiddle,
5309 setup.input[player_nr].joy.xright);
5310 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5311 setup.input[player_nr].joy.yupper,
5312 setup.input[player_nr].joy.ymiddle,
5313 setup.input[player_nr].joy.ylower);
5322 /* don't eat all CPU time */
5326 /* calibrated center position (joystick should now be centered) */
5327 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5330 new_joystick_xmiddle = joy_x;
5331 new_joystick_ymiddle = joy_y;
5336 DrawSetupScreen_Input();
5339 /* wait until the last pressed button was released */
5340 while (Joystick(player_nr) & JOY_BUTTON)
5342 if (PendingEvent()) /* got event */
5347 HandleOtherEvents(&event);
5356 void CalibrateJoystick(int player_nr)
5358 if (!CalibrateJoystickMain(player_nr))
5360 char *device_name = setup.input[player_nr].joy.device_name;
5361 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5362 int xpos = mSX - SX;
5363 int ypos = mSY - SY;
5367 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5368 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5371 Delay(2000); /* show error message for a short time */
5377 DrawSetupScreen_Input();
5381 void DrawSetupScreen()
5383 DeactivateJoystick();
5385 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5387 if (setup_mode == SETUP_MODE_INPUT)
5388 DrawSetupScreen_Input();
5389 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5390 DrawChooseTree(&game_speed_current);
5391 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5392 DrawChooseTree(&screen_mode_current);
5393 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5394 DrawChooseTree(&artwork.gfx_current);
5395 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5396 DrawChooseTree(&artwork.snd_current);
5397 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5398 DrawChooseTree(&artwork.mus_current);
5400 DrawSetupScreen_Generic();
5406 void RedrawSetupScreenAfterFullscreenToggle()
5408 if (setup_mode == SETUP_MODE_GRAPHICS)
5412 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5414 if (setup_mode == SETUP_MODE_INPUT)
5415 HandleSetupScreen_Input(mx, my, dx, dy, button);
5416 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5417 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5418 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5419 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5420 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5421 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5422 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5423 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5424 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5425 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5427 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5432 void HandleGameActions()
5434 if (game_status != GAME_MODE_PLAYING)
5437 GameActions(); /* main game loop */
5439 if (tape.auto_play && !tape.playing)
5440 AutoPlayTape(); /* continue automatically playing next tape */
5444 /* ---------- new screen button stuff -------------------------------------- */
5446 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5451 case SCREEN_CTRL_ID_PREV_LEVEL:
5452 *x = mSX + menu.main.button.prev_level.x;
5453 *y = mSY + menu.main.button.prev_level.y;
5456 case SCREEN_CTRL_ID_NEXT_LEVEL:
5457 *x = mSX + menu.main.button.next_level.x;
5458 *y = mSY + menu.main.button.next_level.y;
5461 case SCREEN_CTRL_ID_PREV_LEVEL:
5462 *x = mSX + TILEX * getPrevlevelButtonPos();
5463 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5466 case SCREEN_CTRL_ID_NEXT_LEVEL:
5467 *x = mSX + TILEX * getNextLevelButtonPos();
5468 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5472 case SCREEN_CTRL_ID_PREV_PLAYER:
5473 *x = mSX + TILEX * 10;
5474 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5477 case SCREEN_CTRL_ID_NEXT_PLAYER:
5478 *x = mSX + TILEX * 12;
5479 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5483 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5489 int gfx_unpressed, gfx_pressed;
5490 void (*get_gadget_position)(int *, int *, int);
5494 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5497 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5498 getScreenMenuButtonPos,
5499 SCREEN_CTRL_ID_PREV_LEVEL,
5504 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5505 getScreenMenuButtonPos,
5506 SCREEN_CTRL_ID_NEXT_LEVEL,
5511 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5512 getScreenMenuButtonPos,
5513 SCREEN_CTRL_ID_PREV_PLAYER,
5518 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5519 getScreenMenuButtonPos,
5520 SCREEN_CTRL_ID_NEXT_PLAYER,
5528 int gfx_unpressed, gfx_pressed;
5532 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5535 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5536 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5537 SCREEN_CTRL_ID_SCROLL_UP,
5541 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5542 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5543 SCREEN_CTRL_ID_SCROLL_DOWN,
5550 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5551 Bitmap **gfx_unpressed, **gfx_pressed;
5553 int gfx_unpressed, gfx_pressed;
5560 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5563 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5564 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5566 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5568 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5569 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5570 GD_TYPE_SCROLLBAR_VERTICAL,
5571 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5572 "scroll level series vertically"
5576 static void CreateScreenMenubuttons()
5578 struct GadgetInfo *gi;
5579 unsigned long event_mask;
5582 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5584 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5585 int gfx_unpressed, gfx_pressed;
5586 int x, y, width, height;
5587 int gd_x1, gd_x2, gd_y1, gd_y2;
5588 int id = menubutton_info[i].gadget_id;
5590 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5592 menubutton_info[i].get_gadget_position(&x, &y, id);
5594 width = SC_MENUBUTTON_XSIZE;
5595 height = SC_MENUBUTTON_YSIZE;
5597 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5598 gfx_pressed = menubutton_info[i].gfx_pressed;
5599 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5600 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5601 gd_x1 = graphic_info[gfx_unpressed].src_x;
5602 gd_y1 = graphic_info[gfx_unpressed].src_y;
5603 gd_x2 = graphic_info[gfx_pressed].src_x;
5604 gd_y2 = graphic_info[gfx_pressed].src_y;
5606 gi = CreateGadget(GDI_CUSTOM_ID, id,
5607 GDI_CUSTOM_TYPE_ID, i,
5608 GDI_INFO_TEXT, menubutton_info[i].infotext,
5613 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5614 GDI_STATE, GD_BUTTON_UNPRESSED,
5615 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5616 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5617 GDI_DIRECT_DRAW, FALSE,
5618 GDI_EVENT_MASK, event_mask,
5619 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5623 Error(ERR_EXIT, "cannot create gadget");
5625 screen_gadget[id] = gi;
5629 static void CreateScreenScrollbuttons()
5631 struct GadgetInfo *gi;
5632 unsigned long event_mask;
5635 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5637 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5638 int gfx_unpressed, gfx_pressed;
5639 int x, y, width, height;
5640 int gd_x1, gd_x2, gd_y1, gd_y2;
5641 int id = scrollbutton_info[i].gadget_id;
5643 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5645 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5646 y = mSY + scrollbutton_info[i].y;
5647 width = SC_SCROLLBUTTON_XSIZE;
5648 height = SC_SCROLLBUTTON_YSIZE;
5650 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5651 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5652 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5654 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5655 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5656 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5657 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5658 gd_x1 = graphic_info[gfx_unpressed].src_x;
5659 gd_y1 = graphic_info[gfx_unpressed].src_y;
5660 gd_x2 = graphic_info[gfx_pressed].src_x;
5661 gd_y2 = graphic_info[gfx_pressed].src_y;
5663 gi = CreateGadget(GDI_CUSTOM_ID, id,
5664 GDI_CUSTOM_TYPE_ID, i,
5665 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5670 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5671 GDI_STATE, GD_BUTTON_UNPRESSED,
5672 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5673 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5674 GDI_DIRECT_DRAW, FALSE,
5675 GDI_EVENT_MASK, event_mask,
5676 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5680 Error(ERR_EXIT, "cannot create gadget");
5682 screen_gadget[id] = gi;
5686 static void CreateScreenScrollbars()
5690 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5692 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5693 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5694 int gfx_unpressed, gfx_pressed;
5696 int x, y, width, height;
5697 int gd_x1, gd_x2, gd_y1, gd_y2;
5698 struct GadgetInfo *gi;
5699 int items_max, items_visible, item_position;
5700 unsigned long event_mask;
5701 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5702 int id = scrollbar_info[i].gadget_id;
5704 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5706 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5707 y = mSY + scrollbar_info[i].y;
5708 width = scrollbar_info[i].width;
5709 height = scrollbar_info[i].height;
5711 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5712 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5714 items_max = num_page_entries;
5715 items_visible = num_page_entries;
5718 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5719 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5720 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5726 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5727 gfx_pressed = scrollbar_info[i].gfx_pressed;
5728 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5729 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5730 gd_x1 = graphic_info[gfx_unpressed].src_x;
5731 gd_y1 = graphic_info[gfx_unpressed].src_y;
5732 gd_x2 = graphic_info[gfx_pressed].src_x;
5733 gd_y2 = graphic_info[gfx_pressed].src_y;
5736 gi = CreateGadget(GDI_CUSTOM_ID, id,
5737 GDI_CUSTOM_TYPE_ID, i,
5738 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5743 GDI_TYPE, scrollbar_info[i].type,
5744 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5745 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5746 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5748 GDI_WHEEL_AREA_X, SX,
5749 GDI_WHEEL_AREA_Y, SY,
5750 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5751 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5753 GDI_WHEEL_AREA_X, 0,
5754 GDI_WHEEL_AREA_Y, 0,
5755 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5756 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5758 GDI_STATE, GD_BUTTON_UNPRESSED,
5759 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5760 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5761 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5762 GDI_DIRECT_DRAW, FALSE,
5763 GDI_EVENT_MASK, event_mask,
5764 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5768 Error(ERR_EXIT, "cannot create gadget");
5770 screen_gadget[id] = gi;
5774 void CreateScreenGadgets()
5776 int last_game_status = game_status; /* save current game status */
5778 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5781 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5783 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5785 /* copy pointers to clip mask and GC */
5786 scrollbar_bitmap[i]->clip_mask =
5787 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5788 scrollbar_bitmap[i]->stored_clip_gc =
5789 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5791 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5792 scrollbar_bitmap[i],
5793 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5794 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5795 TILEX, TILEY, 0, 0);
5799 CreateScreenMenubuttons();
5801 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5802 game_status = GAME_MODE_LEVELS;
5804 CreateScreenScrollbuttons();
5805 CreateScreenScrollbars();
5807 game_status = last_game_status; /* restore current game status */
5810 void FreeScreenGadgets()
5814 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5815 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5817 /* prevent freeing clip mask and GC twice */
5818 scrollbar_bitmap[i]->clip_mask = None;
5819 scrollbar_bitmap[i]->stored_clip_gc = None;
5821 FreeBitmap(scrollbar_bitmap[i]);
5825 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5826 FreeGadget(screen_gadget[i]);
5829 void MapScreenMenuGadgets(int screen_mask)
5833 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5834 if (screen_mask & menubutton_info[i].screen_mask)
5835 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5838 void MapScreenTreeGadgets(TreeInfo *ti)
5840 int num_entries = numTreeInfoInGroup(ti);
5843 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5846 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5847 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5849 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5850 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5853 static void HandleScreenGadgets(struct GadgetInfo *gi)
5855 int id = gi->custom_id;
5856 int button = gi->event.button;
5857 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5861 case SCREEN_CTRL_ID_PREV_LEVEL:
5862 HandleMainMenu_SelectLevel(step, -1);
5865 case SCREEN_CTRL_ID_NEXT_LEVEL:
5866 HandleMainMenu_SelectLevel(step, +1);
5869 case SCREEN_CTRL_ID_PREV_PLAYER:
5870 HandleSetupScreen_Input_Player(step, -1);
5873 case SCREEN_CTRL_ID_NEXT_PLAYER:
5874 HandleSetupScreen_Input_Player(step, +1);
5877 case SCREEN_CTRL_ID_SCROLL_UP:
5878 if (game_status == GAME_MODE_LEVELS)
5879 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5880 else if (game_status == GAME_MODE_SETUP)
5881 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5884 case SCREEN_CTRL_ID_SCROLL_DOWN:
5885 if (game_status == GAME_MODE_LEVELS)
5886 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5887 else if (game_status == GAME_MODE_SETUP)
5888 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5891 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5892 if (game_status == GAME_MODE_LEVELS)
5893 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5894 else if (game_status == GAME_MODE_SETUP)
5895 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);