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];
260 /* main menu display and control definitions */
262 #define MAIN_CONTROL_NAME 0
263 #define MAIN_CONTROL_LEVELS 1
264 #define MAIN_CONTROL_SCORES 2
265 #define MAIN_CONTROL_EDITOR 3
266 #define MAIN_CONTROL_INFO 4
267 #define MAIN_CONTROL_GAME 5
268 #define MAIN_CONTROL_SETUP 6
269 #define MAIN_CONTROL_QUIT 7
270 #define MAIN_CONTROL_PREV_LEVEL 8
271 #define MAIN_CONTROL_NEXT_LEVEL 9
272 #define MAIN_CONTROL_FIRST_LEVEL 10
273 #define MAIN_CONTROL_LAST_LEVEL 11
274 #define MAIN_CONTROL_LEVEL_NUMBER 12
275 #define MAIN_CONTROL_LEVEL_INFO_1 13
276 #define MAIN_CONTROL_LEVEL_INFO_2 14
277 #define MAIN_CONTROL_LEVEL_NAME 15
278 #define MAIN_CONTROL_LEVEL_AUTHOR 16
279 #define MAIN_CONTROL_LEVEL_YEAR 17
280 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
281 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
282 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
283 #define MAIN_CONTROL_TITLE_1 21
284 #define MAIN_CONTROL_TITLE_2 22
285 #define MAIN_CONTROL_TITLE_3 23
287 static char str_main_text_name[10];
288 static char str_main_text_first_level[10];
289 static char str_main_text_last_level[10];
290 static char str_main_text_level_number[10];
292 static char *main_text_name = str_main_text_name;
293 static char *main_text_first_level = str_main_text_first_level;
294 static char *main_text_last_level = str_main_text_last_level;
295 static char *main_text_level_number = str_main_text_level_number;
296 static char *main_text_levels = "Levelset";
297 static char *main_text_scores = "Hall Of Fame";
298 static char *main_text_editor = "Level Creator";
299 static char *main_text_info = "Info Screen";
300 static char *main_text_game = "Start Game";
301 static char *main_text_setup = "Setup";
302 static char *main_text_quit = "Quit";
303 static char *main_text_level_name = level.name;
304 static char *main_text_level_author = level.author;
305 static char *main_text_level_year = NULL;
306 static char *main_text_level_imported_from = NULL;
307 static char *main_text_level_imported_by = NULL;
308 static char *main_text_level_tested_by = NULL;
309 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
310 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
311 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
313 struct MainControlInfo
317 struct MenuPosInfo *pos_button;
320 struct TextPosInfo *pos_text;
323 struct TextPosInfo *pos_input;
327 static struct MainControlInfo main_controls[] =
331 &menu.main.button.name, IMG_MENU_BUTTON,
332 &menu.main.text.name, &main_text_name,
333 &menu.main.input.name, &setup.player_name,
337 &menu.main.button.levels, IMG_MENU_BUTTON_ENTER_MENU,
338 &menu.main.text.levels, &main_text_levels,
343 &menu.main.button.scores, IMG_MENU_BUTTON,
344 &menu.main.text.scores, &main_text_scores,
349 &menu.main.button.editor, IMG_MENU_BUTTON,
350 &menu.main.text.editor, &main_text_editor,
355 &menu.main.button.info, IMG_MENU_BUTTON_ENTER_MENU,
356 &menu.main.text.info, &main_text_info,
361 &menu.main.button.game, IMG_MENU_BUTTON,
362 &menu.main.text.game, &main_text_game,
367 &menu.main.button.setup, IMG_MENU_BUTTON_ENTER_MENU,
368 &menu.main.text.setup, &main_text_setup,
373 &menu.main.button.quit, IMG_MENU_BUTTON,
374 &menu.main.text.quit, &main_text_quit,
378 /* (these two buttons are real gadgets) */
380 MAIN_CONTROL_PREV_LEVEL,
381 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
386 MAIN_CONTROL_NEXT_LEVEL,
387 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
393 MAIN_CONTROL_FIRST_LEVEL,
395 &menu.main.text.first_level, &main_text_first_level,
399 MAIN_CONTROL_LAST_LEVEL,
401 &menu.main.text.last_level, &main_text_last_level,
405 MAIN_CONTROL_LEVEL_NUMBER,
407 &menu.main.text.level_number, &main_text_level_number,
411 MAIN_CONTROL_LEVEL_INFO_1,
413 &menu.main.text.level_info_1, NULL,
417 MAIN_CONTROL_LEVEL_INFO_2,
419 &menu.main.text.level_info_2, NULL,
423 MAIN_CONTROL_LEVEL_NAME,
425 &menu.main.text.level_name, &main_text_level_name,
429 MAIN_CONTROL_LEVEL_AUTHOR,
431 &menu.main.text.level_author, &main_text_level_author,
435 MAIN_CONTROL_LEVEL_YEAR,
437 &menu.main.text.level_year, &main_text_level_year,
441 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
443 &menu.main.text.level_imported_from, &main_text_level_imported_from,
447 MAIN_CONTROL_LEVEL_IMPORTED_BY,
449 &menu.main.text.level_imported_by, &main_text_level_imported_by,
453 MAIN_CONTROL_LEVEL_TESTED_BY,
455 &menu.main.text.level_tested_by, &main_text_level_tested_by,
459 MAIN_CONTROL_TITLE_1,
461 &menu.main.text.title_1, &main_text_title_1,
465 MAIN_CONTROL_TITLE_2,
467 &menu.main.text.title_2, &main_text_title_2,
471 MAIN_CONTROL_TITLE_3,
473 &menu.main.text.title_3, &main_text_title_3,
486 static int getTitleScreenGraphic(int nr, boolean initial)
488 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
491 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
493 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
497 static int getTitleScreenGameMode(boolean initial)
499 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
503 static int getTitleMessageGameMode(boolean initial)
505 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
509 static int getTitleScreenBackground(boolean initial)
511 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
516 static int getTitleMessageBackground(int nr, boolean initial)
518 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
522 static int getTitleBackground(int nr, boolean initial, boolean is_image)
524 int base = (is_image ?
525 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
526 IMG_BACKGROUND_TITLESCREEN_1) :
527 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
528 IMG_BACKGROUND_TITLEMESSAGE_1));
529 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
530 IMG_BACKGROUND_TITLE);
531 int graphic_local = base + nr;
533 if (graphic_info[graphic_local].bitmap != NULL)
534 return graphic_local;
536 if (graphic_info[graphic_global].bitmap != NULL)
537 return graphic_global;
539 return IMG_UNDEFINED;
542 static int getTitleSound(struct TitleControlInfo *tci)
544 boolean is_image = tci->is_image;
545 int initial = tci->initial;
546 int nr = tci->local_nr;
547 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
548 int base = (is_image ?
549 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
550 SND_BACKGROUND_TITLESCREEN_1) :
551 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
552 SND_BACKGROUND_TITLEMESSAGE_1));
553 int sound_global = menu.sound[mode];
554 int sound_local = base + nr;
557 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
558 nr, initial, is_image,
559 sound_global, getSoundListEntry(sound_global)->filename,
560 sound_local, getSoundListEntry(sound_local)->filename);
563 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
566 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
569 return SND_UNDEFINED;
572 static int getTitleMusic(struct TitleControlInfo *tci)
574 boolean is_image = tci->is_image;
575 int initial = tci->initial;
576 int nr = tci->local_nr;
577 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
578 int base = (is_image ?
579 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
580 MUS_BACKGROUND_TITLESCREEN_1) :
581 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
582 MUS_BACKGROUND_TITLEMESSAGE_1));
583 int music_global = menu.music[mode];
584 int music_local = base + nr;
587 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
588 nr, initial, is_image,
589 music_global, getMusicListEntry(music_global)->filename,
590 music_local, getMusicListEntry(music_local)->filename);
593 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
596 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
599 return MUS_UNDEFINED;
602 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
604 boolean is_image = tci->is_image;
605 int initial = tci->initial;
606 int nr = tci->local_nr;
607 struct TitleFadingInfo ti;
611 int graphic = getTitleScreenGraphic(nr, initial);
613 /* initialize fading control values to default title config settings */
614 ti = (initial ? title_initial_default : title_default);
616 /* override default settings with image config settings, if defined */
617 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
618 ti.fade_mode = graphic_info[graphic].fade_mode;
619 if (graphic_info[graphic].fade_delay > -1)
620 ti.fade_delay = graphic_info[graphic].fade_delay;
621 if (graphic_info[graphic].post_delay > -1)
622 ti.post_delay = graphic_info[graphic].post_delay;
623 if (graphic_info[graphic].auto_delay > -1)
624 ti.auto_delay = graphic_info[graphic].auto_delay;
630 ti.fade_mode = titlemessage_initial[nr].fade_mode;
631 ti.fade_delay = titlemessage_initial[nr].fade_delay;
632 ti.post_delay = titlemessage_initial[nr].post_delay;
633 ti.auto_delay = titlemessage_initial[nr].auto_delay;
637 ti.fade_mode = titlemessage[nr].fade_mode;
638 ti.fade_delay = titlemessage[nr].fade_delay;
639 ti.post_delay = titlemessage[nr].post_delay;
640 ti.auto_delay = titlemessage[nr].auto_delay;
645 if (ti.anim_mode == ANIM_NONE)
646 ti.fade_delay = ti.post_delay = 0;
652 static int compareTitleControlInfo(const void *object1, const void *object2)
654 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
655 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
658 if (tci1->initial != tci2->initial)
659 compare_result = (tci1->initial ? -1 : +1);
660 else if (tci1->sort_priority != tci2->sort_priority)
661 compare_result = tci1->sort_priority - tci2->sort_priority;
662 else if (tci1->is_image != tci2->is_image)
663 compare_result = (tci1->is_image ? -1 : +1);
665 compare_result = tci1->local_nr - tci2->local_nr;
667 return compare_result;
670 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
672 int nr, int sort_priority)
674 title_controls[num_title_screens].is_image = is_image;
675 title_controls[num_title_screens].initial = initial;
676 title_controls[num_title_screens].local_nr = nr;
677 title_controls[num_title_screens].sort_priority = sort_priority;
682 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
686 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
688 int graphic = getTitleScreenGraphic(i, initial);
689 Bitmap *bitmap = graphic_info[graphic].bitmap;
690 int sort_priority = graphic_info[graphic].sort_priority;
693 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
696 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
698 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
699 char *filename = getLevelSetTitleMessageFilename(i, initial);
700 int sort_priority = tmi->sort_priority;
702 if (filename != NULL)
703 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
707 static void InitializeTitleControls(boolean show_title_initial)
709 num_title_screens = 0;
711 if (show_title_initial)
712 InitializeTitleControls_CheckTitleInfo(TRUE);
714 InitializeTitleControls_CheckTitleInfo(FALSE);
716 /* sort title screens according to sort_priority and title number */
717 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
718 compareTitleControlInfo);
721 static boolean visibleMenuPos(struct MenuPosInfo *pos)
723 return (pos != NULL && pos->x != -1 && pos->y != -1);
726 static boolean visibleTextPos(struct TextPosInfo *pos)
728 return (pos != NULL && pos->x != -1 && pos->y != -1);
731 static void InitializeMainControls()
733 boolean local_team_mode = (!options.network && setup.team_mode);
736 /* set main control text values to dynamically determined values */
737 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
738 sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
739 sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
740 sprintf(main_text_level_number, "%s", int2str(level_nr, 3));
742 main_text_level_year = leveldir_current->year;
743 main_text_level_imported_from = leveldir_current->imported_from;
744 main_text_level_imported_by = leveldir_current->imported_by;
745 main_text_level_tested_by = leveldir_current->tested_by;
747 /* set main control screen positions to dynamically determined values */
748 for (i = 0; main_controls[i].nr != -1; i++)
750 struct MainControlInfo *mci = &main_controls[i];
752 struct MenuPosInfo *pos_button = mci->pos_button;
753 struct TextPosInfo *pos_text = mci->pos_text;
754 struct TextPosInfo *pos_input = mci->pos_input;
755 char *text = (mci->text ? *mci->text : NULL);
756 char *input = (mci->input ? *mci->input : NULL);
757 int button_graphic = mci->button_graphic;
759 int font_text = (pos_text ? pos_text->font : -1);
760 int font_input = (pos_input ? pos_input->font : -1);
762 int font_text = mci->font_text;
763 int font_input = mci->font_input;
766 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
767 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
768 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
769 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
770 int text_chars = (text != NULL ? strlen(text) : 0);
771 int input_chars = (input != NULL ? strlen(input) : 0);
774 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
776 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
777 int text_width = font_text_width * text_chars;
778 int text_height = font_text_height;
779 int input_width = font_input_width * input_chars;
780 int input_height = font_input_height;
782 if (nr == MAIN_CONTROL_NAME)
785 if (menu.main.input.name.x == -1)
786 menu.main.input.name.x = menu.main.text.name.x + text_width;
787 if (menu.main.input.name.y == -1)
788 menu.main.input.name.y = menu.main.text.name.y;
792 menu.main.input.name.width = input_width;
793 menu.main.input.name.height = input_height;
795 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
796 menu.main.input.name.height = font_input_height;
800 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
802 if (pos_button->width == 0)
803 pos_button->width = button_width;
804 if (pos_button->height == 0)
805 pos_button->height = button_height;
808 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
810 /* calculate width for non-clickable text -- needed for text alignment */
811 boolean calculate_text_width = (pos_button == NULL && text != NULL);
813 if (visibleMenuPos(pos_button))
815 if (pos_text->x == -1)
816 pos_text->x = pos_button->x + pos_button->width;
817 if (pos_text->y == -1)
818 pos_text->y = pos_button->y;
821 if (pos_text->width == -1 || calculate_text_width)
822 pos_text->width = text_width;
823 if (pos_text->height == -1)
824 pos_text->height = text_height;
827 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
829 if (visibleTextPos(pos_text))
831 if (pos_input->x == -1)
832 pos_input->x = pos_text->x + pos_text->width;
833 if (pos_input->y == -1)
834 pos_input->y = pos_text->y;
837 if (pos_input->width == -1)
838 pos_input->width = input_width;
839 if (pos_input->height == -1)
840 pos_input->height = input_height;
845 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
846 boolean active_input)
850 for (i = 0; main_controls[i].nr != -1; i++)
852 struct MainControlInfo *mci = &main_controls[i];
854 if (mci->nr == nr || nr == -1)
856 struct MenuPosInfo *pos_button = mci->pos_button;
857 struct TextPosInfo *pos_text = mci->pos_text;
858 struct TextPosInfo *pos_input = mci->pos_input;
859 char *text = (mci->text ? *mci->text : NULL);
860 char *input = (mci->input ? *mci->input : NULL);
861 int button_graphic = mci->button_graphic;
863 int font_text = (pos_text ? pos_text->font : -1);
864 int font_input = (pos_input ? pos_input->font : -1);
866 int font_text = mci->font_text;
867 int font_input = mci->font_input;
872 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
873 font_text = FONT_ACTIVE(font_text);
878 font_input = FONT_ACTIVE(font_input);
881 if (visibleMenuPos(pos_button))
883 struct MenuPosInfo *pos = pos_button;
884 int x = mSX + pos->x;
885 int y = mSY + pos->y;
887 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
888 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
891 if (visibleTextPos(pos_text) && text != NULL)
893 struct TextPosInfo *pos = pos_text;
894 int x = mSX + ALIGNED_TEXT_XPOS(pos);
895 int y = mSY + ALIGNED_TEXT_YPOS(pos);
898 /* (check why/if this is needed) */
899 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
901 DrawText(x, y, text, font_text);
904 if (visibleTextPos(pos_input) && input != NULL)
906 struct TextPosInfo *pos = pos_input;
907 int x = mSX + ALIGNED_TEXT_XPOS(pos);
908 int y = mSY + ALIGNED_TEXT_YPOS(pos);
911 /* (check why/if this is needed) */
912 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
914 DrawText(x, y, input, font_input);
920 static void DrawCursorAndText_Main(int nr, boolean active_text)
922 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
926 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
928 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
932 static struct MainControlInfo *getMainControlInfo(int nr)
936 for (i = 0; main_controls[i].nr != -1; i++)
937 if (main_controls[i].nr == nr)
938 return &main_controls[i];
943 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
948 int rect_x = ALIGNED_TEXT_XPOS(rect);
949 int rect_y = ALIGNED_TEXT_YPOS(rect);
951 return (x >= rect_x && x < rect_x + rect->width &&
952 y >= rect_y && y < rect_y + rect->height);
955 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
960 int rect_x = ALIGNED_TEXT_XPOS(rect);
961 int rect_y = ALIGNED_TEXT_YPOS(rect);
963 return (x >= rect_x && x < rect_x + rect->width &&
964 y >= rect_y && y < rect_y + rect->height);
967 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
969 static int cursor_array[SCR_FIELDY];
970 int x = mSX + TILEX * xpos;
971 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
976 cursor_array[ypos] = graphic;
978 graphic = cursor_array[ypos];
982 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
984 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
985 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
988 static void initCursor(int ypos, int graphic)
990 drawCursorExt(0, ypos, FALSE, graphic);
993 static void drawCursor(int ypos, boolean active)
995 drawCursorExt(0, ypos, active, -1);
998 static void drawCursorXY(int xpos, int ypos, int graphic)
1000 drawCursorExt(xpos, ypos, FALSE, graphic);
1003 static void drawChooseTreeCursor(int ypos, boolean active)
1005 int last_game_status = game_status; /* save current game status */
1007 /* force LEVELS draw offset on artwork setup screen */
1008 game_status = GAME_MODE_LEVELS;
1010 drawCursorExt(0, ypos, active, -1);
1012 game_status = last_game_status; /* restore current game status */
1017 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1018 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1022 static int getPrevlevelButtonPos()
1027 static int getCurrentLevelTextPos()
1029 return (getPrevlevelButtonPos() + 1);
1032 static int getNextLevelButtonPos()
1034 return getPrevlevelButtonPos() + 3 + 1;
1037 static int getLevelRangeTextPos()
1039 return getNextLevelButtonPos() + 1;
1043 int effectiveGameStatus()
1045 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1046 return GAME_MODE_TITLE;
1051 void DrawTitleScreenImage(int nr, boolean initial)
1053 int graphic = getTitleScreenGraphic(nr, initial);
1054 Bitmap *bitmap = graphic_info[graphic].bitmap;
1056 int width = graphic_info[graphic].width;
1057 int height = graphic_info[graphic].height;
1058 int src_x = graphic_info[graphic].src_x;
1059 int src_y = graphic_info[graphic].src_y;
1061 int width = graphic_info[graphic].src_image_width;
1062 int height = graphic_info[graphic].src_image_height;
1063 int src_x = 0, src_y = 0;
1070 if (width > WIN_XSIZE)
1072 /* image width too large for window => center image horizontally */
1073 src_x = (width - WIN_XSIZE) / 2;
1077 if (height > WIN_YSIZE)
1079 /* image height too large for window => center image vertically */
1080 src_y = (height - WIN_YSIZE) / 2;
1084 /* always display title screens centered */
1085 dst_x = (WIN_XSIZE - width) / 2;
1086 dst_y = (WIN_YSIZE - height) / 2;
1088 SetDrawBackgroundMask(REDRAW_ALL);
1089 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1091 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1093 if (DrawingOnBackground(dst_x, dst_y))
1094 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1096 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1098 redraw_mask = REDRAW_ALL;
1100 /* reset fading control values to default config settings */
1104 title = getTitleFading(nr, initial, TRUE);
1109 title.fade_delay_final = title.fade_delay;
1110 title.post_delay_final = title.post_delay;
1111 title.auto_delay_final = title.auto_delay;
1113 /* override default settings with image config settings, if defined */
1114 if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
1115 title.anim_mode = graphic_info[graphic].anim_mode;
1116 if (graphic_info[graphic].fade_delay > -1)
1117 title.fade_delay = graphic_info[graphic].fade_delay;
1118 if (graphic_info[graphic].post_delay > -1)
1119 title.post_delay = graphic_info[graphic].post_delay;
1120 if (graphic_info[graphic].auto_delay > -1)
1121 title.auto_delay = graphic_info[graphic].auto_delay;
1125 void DrawTitleScreenMessage(int nr, boolean initial)
1127 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1128 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1130 int font_nr = FONT_TEXT_1;
1134 int pad_y = 32 + 14;
1137 int max_chars_per_line;
1138 int max_lines_per_screen;
1140 int last_game_status = game_status; /* save current game status */
1142 if (filename == NULL)
1145 /* force TITLE font on title message screen */
1146 game_status = getTitleMessageGameMode(initial);
1148 /* if chars set to "-1", automatically determine by text and font width */
1149 if (tmi->chars == -1)
1150 tmi->chars = tmi->width / getFontWidth(tmi->font);
1152 tmi->width = tmi->chars * getFontWidth(tmi->font);
1154 /* if lines set to "-1", automatically determine by text and font height */
1155 if (tmi->lines == -1)
1156 tmi->lines = tmi->height / getFontHeight(tmi->font);
1158 tmi->height = tmi->lines * getFontHeight(tmi->font);
1160 SetDrawBackgroundMask(REDRAW_ALL);
1161 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1163 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1166 font_width = getFontWidth(font_nr);
1167 font_height = getFontHeight(font_nr);
1168 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1169 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1173 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1174 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1175 tmi->autowrap, tmi->centered, tmi->parse_comments);
1177 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1178 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1179 tmi->parse_comments);
1182 game_status = last_game_status; /* restore current game status */
1185 void DrawTitleScreen()
1187 KeyboardAutoRepeatOff();
1190 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1193 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1198 boolean CheckTitleScreen(boolean levelset_has_changed)
1200 static boolean show_title_initial = TRUE;
1201 boolean show_titlescreen = FALSE;
1203 /* needed to be able to skip title screen, if no image or message defined */
1204 InitializeTitleControls(show_title_initial);
1206 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1207 show_titlescreen = TRUE;
1209 /* show initial title images and messages only once at program start */
1210 show_title_initial = FALSE;
1212 return (show_titlescreen && num_title_screens > 0);
1215 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1217 static LevelDirTree *leveldir_last_valid = NULL;
1218 boolean levelset_has_changed = FALSE;
1220 boolean local_team_mode = (!options.network && setup.team_mode);
1221 char *name_text = (local_team_mode ? "Team:" : "Name:");
1222 int name_width, level_width;
1229 /* !!! CHANGE THIS !!! */
1230 title = title_default;
1234 printf("::: %d, %d\n", fading.anim_mode == ANIM_CROSSFADE,
1235 redraw_mask == REDRAW_ALL);
1239 FadeOut(redraw_mask);
1243 FadeSoundsAndMusic();
1245 KeyboardAutoRepeatOn();
1248 SetDrawDeactivationMask(REDRAW_NONE);
1249 SetDrawBackgroundMask(REDRAW_FIELD);
1251 audio.sound_deactivated = FALSE;
1255 /* needed if last screen was the playing screen, invoked from level editor */
1256 if (level_editor_test_game)
1258 game_status = GAME_MODE_EDITOR;
1264 /* needed if last screen was the editor screen */
1265 UndrawSpecialEditorDoor();
1267 /* needed if last screen was the setup screen and fullscreen state changed */
1268 ToggleFullscreenIfNeeded();
1270 /* leveldir_current may be invalid (level group, parent link) */
1271 if (!validLevelSeries(leveldir_current))
1272 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1274 if (leveldir_current != leveldir_last_valid)
1275 levelset_has_changed = TRUE;
1277 /* store valid level series information */
1278 leveldir_last_valid = leveldir_current;
1280 /* needed if last screen (level choice) changed graphics, sounds or music */
1281 ReloadCustomArtwork(0);
1283 #if defined(TARGET_SDL)
1284 SetDrawtoField(DRAW_BACKBUFFER);
1288 if (levelset_has_changed)
1289 fading = title_default;
1293 if (CheckTitleScreen(levelset_has_changed))
1295 game_status = GAME_MODE_TITLE;
1304 if (setup.show_titlescreen &&
1305 ((levelset_has_changed &&
1306 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1307 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1308 (show_title_initial &&
1309 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1310 getLevelSetMessageFilename(1, TRUE) != NULL))))
1312 game_status = GAME_MODE_TITLE;
1320 /* level_nr may have been set to value over handicap with level editor */
1321 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1322 level_nr = leveldir_current->handicap_level;
1324 LoadLevel(level_nr);
1326 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1329 FadeOut(redraw_mask);
1333 if (redraw_mask == REDRAW_ALL)
1336 int door_state = GetDoorState();
1341 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1345 OpenDoor(DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1347 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1356 InitializeMainControls();
1359 DrawCursorAndText_Main(-1, FALSE);
1361 for (i = 0; main_controls[i].nr != -1; i++)
1363 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1364 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1365 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1366 char *text = main_controls[i].text;
1367 char *input = main_controls[i].input;
1368 int button_graphic = main_controls[i].button_graphic;
1369 int font_text = main_controls[i].font_text;
1370 int font_input = main_controls[i].font_input;
1372 if (pos_button != NULL)
1373 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1376 if (pos_text != NULL && text != NULL)
1377 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1379 if (pos_input != NULL && input != NULL)
1380 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1388 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1389 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1390 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1391 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1392 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1393 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1394 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1395 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1397 /* calculated after (possible) reload of custom artwork */
1398 name_width = getTextWidth(name_text, FONT_MENU_1);
1399 level_width = 9 * 32;
1401 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1404 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1405 int2str(level_nr, 3), FONT_VALUE_1);
1408 int text_height = getFontHeight(FONT_TEXT_3);
1409 int xpos = getLevelRangeTextPos() * 32 + 8;
1410 int ypos2 = 3 * 32 + 16;
1411 int ypos1 = ypos2 - text_height;
1413 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1414 "%03d", leveldir_current->first_level);
1415 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1416 "%03d", leveldir_current->last_level);
1419 for (i = 0; i < 8; i++)
1420 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1423 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1426 DrawPreviewLevel(TRUE);
1428 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1431 if (TAPE_IS_EMPTY(tape))
1433 DrawCompleteVideoDisplay();
1438 /* create gadgets for main menu screen */
1439 FreeScreenGadgets();
1440 CreateScreenGadgets();
1443 BlitBitmap(drawto, window, VX, VY, VXSIZE, VYSIZE, VX, VY);
1447 /* map gadgets for main menu screen */
1449 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1451 DrawMaskedBorder(REDRAW_ALL);
1454 if (redraw_mask == REDRAW_ALL)
1456 int door_state = GetDoorState();
1458 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1464 game_status = GAME_MODE_PSEUDO_PREVIEW;
1466 DrawText(20, 400, "text_3.PREVIEW", FONT_TEXT_3);
1467 DrawText(20, 420, "text_4.PREVIEW", FONT_TEXT_4);
1469 game_status = GAME_MODE_MAIN;
1471 DrawText(20, 440, "text_3.MAIN", FONT_TEXT_3);
1472 DrawText(20, 460, "text_4.MAIN", FONT_TEXT_4);
1477 FadeIn(redraw_mask);
1482 else if (fading.anim_mode == ANIM_CROSSFADE)
1483 FadeCross(redraw_mask);
1485 FadeIn(redraw_mask);
1488 FadeIn(redraw_mask);
1497 fading = title_default;
1500 SetMouseCursor(CURSOR_DEFAULT);
1504 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1507 void DrawAndFadeInMainMenu(int redraw_mask)
1509 DrawMainMenuExt(redraw_mask, TRUE);
1514 DrawMainMenuExt(REDRAW_ALL, FALSE);
1518 static void gotoTopLevelDir()
1520 /* move upwards to top level directory */
1521 while (leveldir_current->node_parent)
1523 /* write a "path" into level tree for easy navigation to last level */
1524 if (leveldir_current->node_parent->node_group->cl_first == -1)
1526 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1527 int leveldir_pos = posTreeInfo(leveldir_current);
1528 int num_page_entries;
1529 int cl_first, cl_cursor;
1531 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1532 num_page_entries = num_leveldirs;
1534 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1536 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1537 cl_cursor = leveldir_pos - cl_first;
1539 leveldir_current->node_parent->node_group->cl_first = cl_first;
1540 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1543 leveldir_current = leveldir_current->node_parent;
1548 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1550 static unsigned long title_delay = 0;
1551 static int title_screen_nr = 0;
1552 static int last_sound = -1, last_music = -1;
1553 boolean return_to_main_menu = FALSE;
1554 boolean use_fading_main_menu = TRUE;
1557 boolean use_cross_fading = FALSE;
1559 boolean use_cross_fading = !show_title_initial; /* default */
1562 struct TitleControlInfo *tci;
1563 struct TitleFadingInfo fading_default;
1564 struct TitleFadingInfo fading_last = fading;
1565 struct TitleFadingInfo fading_next;
1568 if (button == MB_MENU_INITIALIZE)
1571 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1575 int last_game_status = game_status; /* save current game status */
1579 title_screen_nr = 0;
1580 tci = &title_controls[title_screen_nr];
1582 last_sound = SND_UNDEFINED;
1583 last_music = MUS_UNDEFINED;
1586 /* determine number of title screens to display (images and messages) */
1587 InitializeTitleControls();
1590 if (game_status == GAME_MODE_INFO)
1592 if (num_title_screens == 0)
1594 DrawInfoScreen_NotAvailable("Title screen information:",
1595 "No title screen for this level set.");
1598 /* use default settings for fading, but always disable auto delay */
1599 fading = title_default;
1600 fading.auto_delay = -1;
1606 FadeSoundsAndMusic();
1609 FadeOut(REDRAW_ALL);
1614 DrawTitleScreenImage(tci->local_nr, tci->initial);
1616 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1618 fading_default = (tci->initial ? title_initial_default : title_default);
1620 fading = fading_next = getTitleFading(tci);
1624 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1625 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1627 fading.fade_mode = FADE_MODE_FADE;
1628 fading.fade_delay = fading_default.fade_delay;
1631 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1632 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1633 fading.fade_mode = FADE_MODE_FADE;
1638 sound = getTitleSound(tci);
1639 music = getTitleMusic(tci);
1641 if (sound != last_sound)
1642 PlayMenuSoundExt(sound);
1643 if (music != last_music)
1644 PlayMenuMusicExt(music);
1650 SetMouseCursor(CURSOR_NONE);
1652 // printf("::: mode: %d, delay: %d\n", fading.fade_mode, fading.fade_delay);
1658 fading = fading_next;
1660 DelayReached(&title_delay, 0); /* reset delay counter */
1666 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1667 button = MB_MENU_CHOICE;
1669 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1670 button = MB_MENU_CHOICE;
1673 if (button == MB_MENU_LEAVE)
1675 return_to_main_menu = TRUE;
1676 use_fading_main_menu = FALSE;
1678 else if (button == MB_MENU_CHOICE)
1681 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1684 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1687 FadeOut(REDRAW_FIELD);
1692 info_mode = INFO_MODE_MAIN;
1693 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1699 tci = &title_controls[title_screen_nr];
1701 if (title_screen_nr < num_title_screens)
1705 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1712 graphic_info[getTitleScreenGraphic(tci->local_nr,
1713 tci->initial)].anim_mode;
1715 anim_mode = ANIM_FADE; /* ??? */
1717 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1718 anim_mode == ANIM_CROSSFADE ? TRUE :
1722 sound = getTitleSound(tci);
1723 music = getTitleMusic(tci);
1725 if (sound == SND_UNDEFINED || sound != last_sound)
1727 if (music == MUS_UNDEFINED || music != last_music)
1731 FadeOut(REDRAW_ALL);
1735 DrawTitleScreenImage(tci->local_nr, tci->initial);
1737 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1739 fading_next = getTitleFading(tci);
1742 sound = getTitleSound(tci);
1743 music = getTitleMusic(tci);
1745 if (sound != last_sound)
1746 PlayMenuSoundExt(sound);
1747 if (music != last_music)
1748 PlayMenuMusicExt(music);
1755 printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1759 /* last screen already faded out, next screen has no animation */
1760 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1761 fading_next.fade_mode == FADE_MODE_NONE)
1762 fading = fading_next;
1764 /* last screen already faded out, next screen has no animation */
1765 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1766 fading_next.fade_mode == FADE_MODE_NONE)
1767 fading = fading_next;
1774 fading = fading_next;
1776 DelayReached(&title_delay, 0); /* reset delay counter */
1780 FadeSoundsAndMusic();
1786 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1790 FadeOut(REDRAW_ALL);
1794 FadeOut(REDRAW_ALL);
1798 return_to_main_menu = TRUE;
1802 if (return_to_main_menu)
1808 SetMouseCursor(CURSOR_DEFAULT);
1810 if (game_status == GAME_MODE_INFO)
1813 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1816 info_mode = INFO_MODE_MAIN;
1817 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1819 else /* default: return to main menu */
1822 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1825 game_status = GAME_MODE_MAIN;
1826 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1831 void HandleMainMenu_SelectLevel(int step, int direction)
1833 int old_level_nr = level_nr;
1836 new_level_nr = old_level_nr + step * direction;
1837 if (new_level_nr < leveldir_current->first_level)
1838 new_level_nr = leveldir_current->first_level;
1839 if (new_level_nr > leveldir_current->last_level)
1840 new_level_nr = leveldir_current->last_level;
1842 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1844 /* skipping levels is only allowed when trying to skip single level */
1845 if (setup.skip_levels && step == 1 &&
1846 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1848 leveldir_current->handicap_level++;
1849 SaveLevelSetup_SeriesInfo();
1852 new_level_nr = leveldir_current->handicap_level;
1855 if (new_level_nr != old_level_nr)
1857 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1859 PlaySound(SND_MENU_ITEM_SELECTING);
1861 level_nr = new_level_nr;
1864 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1865 int2str(level_nr, 3), mci->pos_text->font);
1867 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1870 LoadLevel(level_nr);
1871 DrawPreviewLevel(TRUE);
1875 DrawCompleteVideoDisplay();
1877 /* needed because DrawPreviewLevel() takes some time */
1885 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1887 static int choice = MAIN_CONTROL_GAME;
1891 if (button == MB_MENU_INITIALIZE)
1893 DrawCursorAndText_Main(choice, TRUE);
1898 if (mx || my) /* mouse input */
1902 for (i = 0; main_controls[i].nr != -1; i++)
1904 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1905 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1906 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1908 pos = main_controls[i].nr;
1914 else if (dx || dy) /* keyboard input */
1916 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1917 choice == MAIN_CONTROL_SETUP))
1918 button = MB_MENU_CHOICE;
1923 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1925 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1927 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1933 PlaySound(SND_MENU_ITEM_ACTIVATING);
1935 DrawCursorAndText_Main(choice, FALSE);
1936 DrawCursorAndText_Main(pos, TRUE);
1943 PlaySound(SND_MENU_ITEM_SELECTING);
1945 if (pos == MAIN_CONTROL_NAME)
1947 game_status = GAME_MODE_PSEUDO_TYPENAME;
1949 HandleTypeName(strlen(setup.player_name), 0);
1951 else if (pos == MAIN_CONTROL_LEVELS)
1955 game_status = GAME_MODE_LEVELS;
1957 SaveLevelSetup_LastSeries();
1958 SaveLevelSetup_SeriesInfo();
1967 else if (pos == MAIN_CONTROL_SCORES)
1969 game_status = GAME_MODE_SCORES;
1973 else if (pos == MAIN_CONTROL_EDITOR)
1975 if (leveldir_current->readonly &&
1976 !strEqual(setup.player_name, "Artsoft"))
1977 Request("This level is read only !", REQ_CONFIRM);
1979 game_status = GAME_MODE_EDITOR;
1985 else if (pos == MAIN_CONTROL_INFO)
1987 game_status = GAME_MODE_INFO;
1988 info_mode = INFO_MODE_MAIN;
1991 fading = menu.navigation;
1996 else if (pos == MAIN_CONTROL_GAME)
1998 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2000 else if (pos == MAIN_CONTROL_SETUP)
2002 game_status = GAME_MODE_SETUP;
2003 setup_mode = SETUP_MODE_MAIN;
2007 else if (pos == MAIN_CONTROL_QUIT)
2009 SaveLevelSetup_LastSeries();
2010 SaveLevelSetup_SeriesInfo();
2012 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2013 game_status = GAME_MODE_QUIT;
2018 if (game_status == GAME_MODE_MAIN)
2020 DrawPreviewLevel(FALSE);
2027 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2029 static int choice = 5;
2033 if (button == MB_MENU_INITIALIZE)
2035 drawCursor(choice, TRUE);
2040 if (mx || my) /* mouse input */
2042 x = (mx - mSX) / 32;
2043 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2045 else if (dx || dy) /* keyboard input */
2047 if (dx && choice == 1)
2048 x = (dx < 0 ? 10 : 14);
2051 if (choice == 4 || choice == 6)
2052 button = MB_MENU_CHOICE;
2058 if (y == 1 && dx != 0 && button)
2060 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2062 else if (IN_VIS_FIELD(x, y) &&
2063 y >= 0 && y <= 7 && (y != 1 || x < 10))
2069 drawCursor(choice, FALSE);
2070 drawCursor(y, TRUE);
2079 game_status = GAME_MODE_PSEUDO_TYPENAME;
2080 HandleTypeName(strlen(setup.player_name), 0);
2086 game_status = GAME_MODE_LEVELS;
2087 SaveLevelSetup_LastSeries();
2088 SaveLevelSetup_SeriesInfo();
2099 game_status = GAME_MODE_SCORES;
2104 if (leveldir_current->readonly &&
2105 !strEqual(setup.player_name, "Artsoft"))
2106 Request("This level is read only !", REQ_CONFIRM);
2107 game_status = GAME_MODE_EDITOR;
2112 game_status = GAME_MODE_INFO;
2113 info_mode = INFO_MODE_MAIN;
2118 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2122 game_status = GAME_MODE_SETUP;
2123 setup_mode = SETUP_MODE_MAIN;
2129 SaveLevelSetup_LastSeries();
2130 SaveLevelSetup_SeriesInfo();
2132 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2133 game_status = GAME_MODE_QUIT;
2138 if (game_status == GAME_MODE_MAIN)
2140 DrawPreviewLevel(FALSE);
2148 /* ========================================================================= */
2149 /* info screen functions */
2150 /* ========================================================================= */
2152 static struct TokenInfo *info_info;
2153 static int num_info_info;
2155 static void execInfoTitleScreen()
2161 info_mode = INFO_MODE_TITLE;
2165 static void execInfoElements()
2171 info_mode = INFO_MODE_ELEMENTS;
2175 static void execInfoMusic()
2181 info_mode = INFO_MODE_MUSIC;
2185 static void execInfoCredits()
2191 info_mode = INFO_MODE_CREDITS;
2195 static void execInfoProgram()
2201 info_mode = INFO_MODE_PROGRAM;
2205 static void execInfoVersion()
2211 info_mode = INFO_MODE_VERSION;
2215 static void execInfoLevelSet()
2221 info_mode = INFO_MODE_LEVELSET;
2225 static void execExitInfo()
2231 game_status = GAME_MODE_MAIN;
2233 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2239 static struct TokenInfo info_info_main[] =
2241 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2242 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2243 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2244 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2245 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2246 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2247 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2248 { TYPE_EMPTY, NULL, "" },
2249 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2254 static void DrawCursorAndText_Info(int pos, boolean active)
2256 int xpos = MENU_SCREEN_START_XPOS;
2257 int ypos = MENU_SCREEN_START_YPOS + pos;
2258 int font_nr = FONT_MENU_1;
2261 font_nr = FONT_ACTIVE(font_nr);
2263 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2265 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2266 drawCursor(pos, active);
2269 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2274 CloseDoor(DOOR_CLOSE_2);
2276 /* (needed after displaying title screens which disable auto repeat) */
2277 KeyboardAutoRepeatOn();
2280 FadeOut(redraw_mask);
2284 if (redraw_mask == REDRAW_ALL)
2287 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2293 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2295 info_info = info_info_main;
2298 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2301 int xpos = MENU_SCREEN_START_XPOS;
2302 int ypos = MENU_SCREEN_START_YPOS + i;
2303 int font_nr = FONT_MENU_1;
2306 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2307 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2308 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2309 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2310 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2311 initCursor(i, IMG_MENU_BUTTON);
2314 DrawCursorAndText_Info(i, FALSE);
2316 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2322 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2327 DrawMaskedBorder(redraw_mask);
2330 FadeIn(redraw_mask);
2335 else if (fading.anim_mode == ANIM_CROSSFADE)
2336 FadeCross(redraw_mask);
2338 FadeIn(redraw_mask);
2341 FadeIn(redraw_mask);
2350 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2352 static int choice_store[MAX_INFO_MODES];
2353 int choice = choice_store[info_mode]; /* always starts with 0 */
2357 if (button == MB_MENU_INITIALIZE)
2359 /* advance to first valid menu entry */
2360 while (choice < num_info_info &&
2361 info_info[choice].type & TYPE_SKIP_ENTRY)
2363 choice_store[info_mode] = choice;
2366 DrawCursorAndText_Info(choice, TRUE);
2368 drawCursor(choice, TRUE);
2373 else if (button == MB_MENU_LEAVE)
2375 for (y = 0; y < num_info_info; y++)
2377 if (info_info[y].type & TYPE_LEAVE_MENU)
2379 void (*menu_callback_function)(void) = info_info[y].value;
2383 menu_callback_function();
2385 break; /* absolutely needed because function changes 'info_info'! */
2392 if (mx || my) /* mouse input */
2394 x = (mx - mSX) / 32;
2395 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2397 else if (dx || dy) /* keyboard input */
2401 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2403 if (info_info[choice].type & menu_navigation_type ||
2404 info_info[choice].type & TYPE_ENTER_SCREEN ||
2405 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2406 button = MB_MENU_CHOICE;
2411 /* jump to next non-empty menu entry (up or down) */
2412 while (y > 0 && y < num_info_info - 1 &&
2413 info_info[y].type & TYPE_SKIP_ENTRY)
2417 if (IN_VIS_FIELD(x, y) &&
2418 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2424 PlaySound(SND_MENU_ITEM_ACTIVATING);
2427 DrawCursorAndText_Info(choice, FALSE);
2428 DrawCursorAndText_Info(y, TRUE);
2430 drawCursor(choice, FALSE);
2431 drawCursor(y, TRUE);
2434 choice = choice_store[info_mode] = y;
2437 else if (!(info_info[y].type & TYPE_GHOSTED))
2439 PlaySound(SND_MENU_ITEM_SELECTING);
2441 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2443 void (*menu_callback_function)(void) = info_info[choice].value;
2445 FadeSetFromType(info_info[y].type);
2447 menu_callback_function();
2453 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2456 int ystart1 = mSY - SY + 100;
2457 int ystart2 = mSY - SY + 150;
2458 int ybottom = mSY - SY + SYSIZE - 20;
2462 int ybottom = SYSIZE - 20;
2465 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2468 FadeOut(REDRAW_FIELD);
2474 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2475 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2477 DrawTextSCentered(ybottom, FONT_TEXT_4,
2478 "Press any key or button for info menu");
2481 FadeIn(REDRAW_FIELD);
2485 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2487 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2488 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2489 int xstart = mSX + 16;
2490 int ystart1 = mSY - SY + 100;
2491 int ystart2 = mSY + 64 + 2 * 32;
2492 int ybottom = mSY - SY + SYSIZE - 20;
2493 int ystep = TILEY + 4;
2494 int element, action, direction;
2502 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2503 infoscreen_step[i] = infoscreen_frame[i] = 0;
2508 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2510 DrawTextSCentered(ybottom, FONT_TEXT_4,
2511 "Press any key or button for next page");
2517 while (helpanim_info[j].element != HELPANIM_LIST_END)
2519 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2524 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2533 j += infoscreen_step[i - start];
2535 element = helpanim_info[j].element;
2536 action = helpanim_info[j].action;
2537 direction = helpanim_info[j].direction;
2540 element = EL_UNKNOWN;
2542 if (action != -1 && direction != -1)
2543 graphic = el_act_dir2img(element, action, direction);
2544 else if (action != -1)
2545 graphic = el_act2img(element, action);
2546 else if (direction != -1)
2547 graphic = el_dir2img(element, direction);
2549 graphic = el2img(element);
2551 delay = helpanim_info[j++].delay;
2556 if (infoscreen_frame[i - start] == 0)
2559 infoscreen_frame[i - start] = delay - 1;
2563 sync_frame = delay - infoscreen_frame[i - start];
2564 infoscreen_frame[i - start]--;
2567 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2569 if (!infoscreen_frame[i - start])
2570 infoscreen_step[i - start] = 0;
2574 if (!infoscreen_frame[i - start])
2575 infoscreen_step[i - start]++;
2576 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2582 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2584 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2585 graphic, sync_frame, USE_MASKING);
2588 DrawInfoScreen_HelpText(element, action, direction, i - start);
2593 redraw_mask |= REDRAW_FIELD;
2598 static char *getHelpText(int element, int action, int direction)
2600 char token[MAX_LINE_LEN];
2602 strcpy(token, element_info[element].token_name);
2605 strcat(token, element_action_info[action].suffix);
2607 if (direction != -1)
2608 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2610 return getHashEntry(helptext_info, token);
2613 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2616 int font_nr = FONT_INFO_ELEMENTS;
2618 int font_nr = FONT_LEVEL_NUMBER;
2620 int font_width = getFontWidth(font_nr);
2621 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2622 int sy = mSY + 65 + 2 * 32 + 1;
2623 int ystep = TILEY + 4;
2624 int pad_x = sx - SX;
2625 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2626 int max_lines_per_text = 2;
2629 if (action != -1 && direction != -1) /* element.action.direction */
2630 text = getHelpText(element, action, direction);
2632 if (text == NULL && action != -1) /* element.action */
2633 text = getHelpText(element, action, -1);
2635 if (text == NULL && direction != -1) /* element.direction */
2636 text = getHelpText(element, -1, direction);
2638 if (text == NULL) /* base element */
2639 text = getHelpText(element, -1, -1);
2641 if (text == NULL) /* not found */
2642 text = "No description available";
2644 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2645 sy += getFontHeight(font_nr) / 2;
2648 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2649 max_chars_per_line, -1, max_lines_per_text, -1,
2650 TRUE, FALSE, FALSE);
2652 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2653 max_chars_per_line, max_lines_per_text);
2657 void DrawInfoScreen_TitleScreen()
2662 void HandleInfoScreen_TitleScreen(int button)
2664 HandleTitleScreen(0, 0, 0, 0, button);
2667 void DrawInfoScreen_Elements()
2669 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2672 FadeOut(REDRAW_FIELD);
2678 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2681 FadeIn(REDRAW_FIELD);
2687 void HandleInfoScreen_Elements(int button)
2689 static unsigned long info_delay = 0;
2690 static int num_anims;
2691 static int num_pages;
2693 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2696 if (button == MB_MENU_INITIALIZE)
2698 boolean new_element = TRUE;
2702 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2704 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2706 else if (new_element)
2709 new_element = FALSE;
2713 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2717 if (button == MB_MENU_LEAVE)
2719 PlaySound(SND_MENU_ITEM_SELECTING);
2721 info_mode = INFO_MODE_MAIN;
2726 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2728 if (button != MB_MENU_INITIALIZE)
2730 PlaySound(SND_MENU_ITEM_SELECTING);
2735 if (page >= num_pages)
2737 FadeSoundsAndMusic();
2740 FadeOut(REDRAW_FIELD);
2743 info_mode = INFO_MODE_MAIN;
2744 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2749 if (button != MB_MENU_INITIALIZE)
2750 FadeCrossSaveBackbuffer();
2752 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2754 if (button != MB_MENU_INITIALIZE)
2755 FadeCross(REDRAW_FIELD);
2759 if (DelayReached(&info_delay, GameFrameDelay))
2760 if (page < num_pages)
2761 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2763 PlayMenuSoundIfLoop();
2767 void DrawInfoScreen_Music()
2769 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2772 FadeOut(REDRAW_FIELD);
2780 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2783 FadeIn(REDRAW_FIELD);
2787 void HandleInfoScreen_Music(int button)
2789 static struct MusicFileInfo *list = NULL;
2790 int ystart1 = mSY - SY + 100;
2791 int ystart2 = mSY - SY + 150;
2792 int ybottom = mSY - SY + SYSIZE - 20;
2795 if (button == MB_MENU_INITIALIZE)
2797 list = music_file_info;
2801 FadeSoundsAndMusic();
2806 DrawTextSCentered(ystart1, FONT_TEXT_1,
2807 "No music info for this level set.");
2809 DrawTextSCentered(ybottom, FONT_TEXT_4,
2810 "Press any key or button for info menu");
2816 if (button == MB_MENU_LEAVE)
2818 PlaySound(SND_MENU_ITEM_SELECTING);
2820 FadeSoundsAndMusic();
2822 info_mode = INFO_MODE_MAIN;
2827 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2831 if (button != MB_MENU_INITIALIZE)
2833 PlaySound(SND_MENU_ITEM_SELECTING);
2841 FadeSoundsAndMusic();
2844 FadeOut(REDRAW_FIELD);
2847 info_mode = INFO_MODE_MAIN;
2848 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2853 FadeSoundsAndMusic();
2855 if (button != MB_MENU_INITIALIZE)
2856 FadeCrossSaveBackbuffer();
2863 int sound = list->music;
2865 if (sound_info[sound].loop)
2866 PlaySoundLoop(sound);
2870 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2874 PlayMusic(list->music);
2876 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2879 if (!strEqual(list->title, UNKNOWN_NAME))
2881 if (!strEqual(list->title_header, UNKNOWN_NAME))
2882 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2884 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2887 if (!strEqual(list->artist, UNKNOWN_NAME))
2889 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2890 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2892 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2894 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2897 if (!strEqual(list->album, UNKNOWN_NAME))
2899 if (!strEqual(list->album_header, UNKNOWN_NAME))
2900 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2902 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2904 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2907 if (!strEqual(list->year, UNKNOWN_NAME))
2909 if (!strEqual(list->year_header, UNKNOWN_NAME))
2910 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2912 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2914 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2917 DrawTextSCentered(ybottom, FONT_TEXT_4,
2918 "Press any key or button for next page");
2920 if (button != MB_MENU_INITIALIZE)
2921 FadeCross(REDRAW_FIELD);
2924 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2925 PlaySoundLoop(list->music);
2928 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2930 int ystart1 = mSY - SY + 100;
2931 int ystart2 = mSY - SY + 150;
2932 int ybottom = mSY - SY + SYSIZE - 20;
2941 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2945 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2946 "Special thanks to");
2947 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2949 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2951 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2952 "\"Boulder Dash\"");
2953 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2955 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2957 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2959 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2960 "First Star Software");
2962 else if (screen_nr == 1)
2964 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2965 "Special thanks to");
2966 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2967 "Klaus Heinz & Volker Wertich");
2968 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2970 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2971 "\"Emerald Mine\"");
2972 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2974 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2976 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2978 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2981 else if (screen_nr == 2)
2983 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2984 "Special thanks to");
2985 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2986 "Michael Stopp & Philip Jespersen");
2987 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2989 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2991 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2993 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2995 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2997 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2998 "Digital Integration");
3000 else if (screen_nr == 3)
3002 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3003 "Special thanks to");
3004 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3005 "Hiroyuki Imabayashi");
3006 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3008 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3010 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3012 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3016 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3019 else if (screen_nr == 4)
3021 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3022 "Special thanks to");
3023 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3025 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3027 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3028 "Jürgen Bonhagen");
3029 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3030 "for the continuous creation");
3031 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3032 "of outstanding level sets");
3034 else if (screen_nr == 5)
3036 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3038 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3040 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3041 "for ideas and inspiration by");
3042 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3045 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3047 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3049 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3050 "for ideas and inspiration by");
3051 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3054 else if (screen_nr == 6)
3056 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3058 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3060 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3061 "for the new Emerald Mine engine");
3063 else if (screen_nr == 7)
3065 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3067 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3069 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3070 "for the initial DOS port");
3072 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3074 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3076 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3077 "for some additional toons");
3079 else if (screen_nr == 8)
3081 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3082 "And not to forget:");
3083 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3085 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3086 "All those who contributed");
3087 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3088 "levels to this game");
3089 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3099 DrawTextSCentered(ybottom, FONT_TEXT_4,
3100 "Press any key or button for next page");
3105 void DrawInfoScreen_Credits()
3107 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3109 FadeSoundsAndMusic();
3112 FadeOut(REDRAW_FIELD);
3115 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3118 FadeIn(REDRAW_FIELD);
3122 void HandleInfoScreen_Credits(int button)
3124 static int screen_nr = 0;
3126 if (button == MB_MENU_INITIALIZE)
3130 DrawInfoScreen_CreditsScreen(screen_nr);
3132 else if (button == MB_MENU_LEAVE)
3134 PlaySound(SND_MENU_ITEM_SELECTING);
3136 info_mode = INFO_MODE_MAIN;
3141 else if (button == MB_MENU_CHOICE)
3143 boolean show_screen;
3145 PlaySound(SND_MENU_ITEM_SELECTING);
3149 FadeCrossSaveBackbuffer();
3151 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3155 FadeCross(REDRAW_FIELD);
3159 FadeSoundsAndMusic();
3162 FadeOut(REDRAW_FIELD);
3165 info_mode = INFO_MODE_MAIN;
3166 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3171 PlayMenuSoundIfLoop();
3175 void DrawInfoScreen_Program()
3177 int ystart1 = mSY - SY + 100;
3178 int ystart2 = mSY - SY + 150;
3179 int ybottom = mSY - SY + SYSIZE - 20;
3182 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3185 FadeOut(REDRAW_FIELD);
3191 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3193 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3194 "This game is Freeware!");
3195 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3196 "If you like it, send e-mail to:");
3197 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3198 PROGRAM_EMAIL_STRING);
3199 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3200 "or SnailMail to:");
3201 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3203 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3204 "Detmolder Strasse 189");
3205 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3207 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3209 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3210 "More information and levels:");
3211 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3212 PROGRAM_WEBSITE_STRING);
3213 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3214 "If you have created new levels,");
3215 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3216 "send them to me to include them!");
3217 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3220 DrawTextSCentered(ybottom, FONT_TEXT_4,
3221 "Press any key or button for info menu");
3224 FadeIn(REDRAW_FIELD);
3228 void HandleInfoScreen_Program(int button)
3230 if (button == MB_MENU_LEAVE)
3232 PlaySound(SND_MENU_ITEM_SELECTING);
3234 info_mode = INFO_MODE_MAIN;
3239 else if (button == MB_MENU_CHOICE)
3241 PlaySound(SND_MENU_ITEM_SELECTING);
3243 FadeSoundsAndMusic();
3246 FadeOut(REDRAW_FIELD);
3249 info_mode = INFO_MODE_MAIN;
3250 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3254 PlayMenuSoundIfLoop();
3258 void DrawInfoScreen_Version()
3260 int font_header = FONT_TEXT_3;
3261 int font_text = FONT_TEXT_2;
3262 int xstep = getFontWidth(font_text);
3263 int ystep = getFontHeight(font_text);
3264 int ystart1 = mSY - SY + 100;
3265 int ystart2 = mSY - SY + 150;
3266 int ybottom = mSY - SY + SYSIZE - 20;
3267 int xstart1 = mSX + 2 * xstep;
3268 int xstart2 = mSX + 19 * xstep;
3269 #if defined(TARGET_SDL)
3270 int xstart3 = mSX + 29 * xstep;
3271 SDL_version sdl_version_compiled;
3272 const SDL_version *sdl_version_linked;
3273 int driver_name_len = 8;
3274 char driver_name[driver_name_len];
3277 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3280 FadeOut(REDRAW_FIELD);
3286 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3288 DrawTextF(xstart1, ystart2, font_header, "Name");
3289 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3292 DrawTextF(xstart1, ystart2, font_header, "Version");
3293 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3296 DrawTextF(xstart1, ystart2, font_header, "Platform");
3297 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3300 DrawTextF(xstart1, ystart2, font_header, "Target");
3301 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3304 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3305 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3307 #if defined(TARGET_SDL)
3308 ystart2 += 3 * ystep;
3309 DrawTextF(xstart1, ystart2, font_header, "Library");
3310 DrawTextF(xstart2, ystart2, font_header, "compiled");
3311 DrawTextF(xstart3, ystart2, font_header, "linked");
3313 SDL_VERSION(&sdl_version_compiled);
3314 sdl_version_linked = SDL_Linked_Version();
3316 ystart2 += 2 * ystep;
3317 DrawTextF(xstart1, ystart2, font_text, "SDL");
3318 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3319 sdl_version_compiled.major,
3320 sdl_version_compiled.minor,
3321 sdl_version_compiled.patch);
3322 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3323 sdl_version_linked->major,
3324 sdl_version_linked->minor,
3325 sdl_version_linked->patch);
3327 SDL_IMAGE_VERSION(&sdl_version_compiled);
3328 sdl_version_linked = IMG_Linked_Version();
3331 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3332 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3333 sdl_version_compiled.major,
3334 sdl_version_compiled.minor,
3335 sdl_version_compiled.patch);
3336 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3337 sdl_version_linked->major,
3338 sdl_version_linked->minor,
3339 sdl_version_linked->patch);
3341 SDL_MIXER_VERSION(&sdl_version_compiled);
3342 sdl_version_linked = Mix_Linked_Version();
3345 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3346 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3347 sdl_version_compiled.major,
3348 sdl_version_compiled.minor,
3349 sdl_version_compiled.patch);
3350 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3351 sdl_version_linked->major,
3352 sdl_version_linked->minor,
3353 sdl_version_linked->patch);
3355 SDL_NET_VERSION(&sdl_version_compiled);
3356 sdl_version_linked = SDLNet_Linked_Version();
3359 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3360 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3361 sdl_version_compiled.major,
3362 sdl_version_compiled.minor,
3363 sdl_version_compiled.patch);
3364 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3365 sdl_version_linked->major,
3366 sdl_version_linked->minor,
3367 sdl_version_linked->patch);
3369 ystart2 += 3 * ystep;
3370 DrawTextF(xstart1, ystart2, font_header, "Driver");
3371 DrawTextF(xstart2, ystart2, font_header, "Requested");
3372 DrawTextF(xstart3, ystart2, font_header, "Used");
3374 SDL_VideoDriverName(driver_name, driver_name_len);
3376 ystart2 += 2 * ystep;
3377 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3378 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3379 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3381 SDL_AudioDriverName(driver_name, driver_name_len);
3384 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3385 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3386 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3389 DrawTextSCentered(ybottom, FONT_TEXT_4,
3390 "Press any key or button for info menu");
3393 FadeIn(REDRAW_FIELD);
3397 void HandleInfoScreen_Version(int button)
3399 if (button == MB_MENU_LEAVE)
3401 PlaySound(SND_MENU_ITEM_SELECTING);
3403 info_mode = INFO_MODE_MAIN;
3408 else if (button == MB_MENU_CHOICE)
3410 PlaySound(SND_MENU_ITEM_SELECTING);
3412 FadeSoundsAndMusic();
3415 FadeOut(REDRAW_FIELD);
3418 info_mode = INFO_MODE_MAIN;
3419 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3423 PlayMenuSoundIfLoop();
3427 void DrawInfoScreen_LevelSet()
3429 struct TitleMessageInfo *tmi = &readme;
3430 char *filename = getLevelSetInfoFilename();
3432 /* if chars set to "-1", automatically determine by text and font width */
3433 if (tmi->chars == -1)
3434 tmi->chars = tmi->width / getFontWidth(tmi->font);
3436 tmi->width = tmi->chars * getFontWidth(tmi->font);
3438 /* if lines set to "-1", automatically determine by text and font height */
3439 if (tmi->lines == -1)
3440 tmi->lines = tmi->height / getFontHeight(tmi->font);
3442 tmi->height = tmi->lines * getFontHeight(tmi->font);
3444 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3447 FadeOut(REDRAW_FIELD);
3453 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3455 if (filename != NULL)
3456 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3457 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3458 tmi->autowrap, tmi->centered, tmi->parse_comments);
3460 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3461 "No information for this level set.");
3463 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3464 "Press any key or button for info menu");
3467 FadeIn(REDRAW_FIELD);
3471 void HandleInfoScreen_LevelSet(int button)
3473 if (button == MB_MENU_LEAVE)
3475 PlaySound(SND_MENU_ITEM_SELECTING);
3477 info_mode = INFO_MODE_MAIN;
3482 else if (button == MB_MENU_CHOICE)
3484 PlaySound(SND_MENU_ITEM_SELECTING);
3486 FadeSoundsAndMusic();
3489 FadeOut(REDRAW_FIELD);
3492 info_mode = INFO_MODE_MAIN;
3493 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3497 PlayMenuSoundIfLoop();
3501 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3503 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3505 if (info_mode == INFO_MODE_TITLE)
3506 DrawInfoScreen_TitleScreen();
3507 else if (info_mode == INFO_MODE_ELEMENTS)
3508 DrawInfoScreen_Elements();
3509 else if (info_mode == INFO_MODE_MUSIC)
3510 DrawInfoScreen_Music();
3511 else if (info_mode == INFO_MODE_CREDITS)
3512 DrawInfoScreen_Credits();
3513 else if (info_mode == INFO_MODE_PROGRAM)
3514 DrawInfoScreen_Program();
3515 else if (info_mode == INFO_MODE_VERSION)
3516 DrawInfoScreen_Version();
3517 else if (info_mode == INFO_MODE_LEVELSET)
3518 DrawInfoScreen_LevelSet();
3520 DrawInfoScreen_Main(redraw_mask, do_fading);
3522 if (info_mode != INFO_MODE_MAIN &&
3523 info_mode != INFO_MODE_TITLE &&
3524 info_mode != INFO_MODE_MUSIC)
3531 void DrawAndFadeInInfoScreen(int redraw_mask)
3533 DrawInfoScreenExt(redraw_mask, TRUE);
3536 void DrawInfoScreen()
3538 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3541 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3543 if (info_mode == INFO_MODE_TITLE)
3544 HandleInfoScreen_TitleScreen(button);
3545 else if (info_mode == INFO_MODE_ELEMENTS)
3546 HandleInfoScreen_Elements(button);
3547 else if (info_mode == INFO_MODE_MUSIC)
3548 HandleInfoScreen_Music(button);
3549 else if (info_mode == INFO_MODE_CREDITS)
3550 HandleInfoScreen_Credits(button);
3551 else if (info_mode == INFO_MODE_PROGRAM)
3552 HandleInfoScreen_Program(button);
3553 else if (info_mode == INFO_MODE_VERSION)
3554 HandleInfoScreen_Version(button);
3555 else if (info_mode == INFO_MODE_LEVELSET)
3556 HandleInfoScreen_LevelSet(button);
3558 HandleInfoScreen_Main(mx, my, dx, dy, button);
3564 /* ========================================================================= */
3565 /* type name functions */
3566 /* ========================================================================= */
3568 void HandleTypeName(int newxpos, Key key)
3570 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3571 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3573 struct TextPosInfo *pos = mci->pos_input;
3574 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3575 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3578 static int xpos = 0;
3580 static int xpos = 0, ypos = 2;
3582 int font_nr = pos->font;
3583 int font_active_nr = FONT_ACTIVE(font_nr);
3584 int font_width = getFontWidth(font_active_nr);
3587 int startx = mSX + mci->pos_input->x;
3588 int starty = mSY + mci->pos_input->y;
3591 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3592 int startx = mSX + 32 + name_width;
3593 int starty = mSY + ypos * 32;
3595 char key_char = getValidConfigValueChar(getCharFromKey(key));
3596 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3597 boolean is_active = TRUE;
3599 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3603 strcpy(last_player_name, setup.player_name);
3608 /* add one character width for added cursor character */
3609 pos->width += font_width;
3610 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3612 DrawText(startx, starty, setup.player_name, font_active_nr);
3613 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3616 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3618 setup.player_name[xpos] = key_char;
3619 setup.player_name[xpos + 1] = 0;
3624 /* add one character width for added name text character */
3625 pos->width += font_width;
3626 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3628 DrawText(startx, starty, setup.player_name, font_active_nr);
3629 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3632 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3636 setup.player_name[xpos] = 0;
3639 /* remove one character width for removed name text character */
3640 pos->width -= font_width;
3641 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3643 DrawText(startx, starty, setup.player_name, font_active_nr);
3644 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3647 else if (key == KSYM_Return && xpos > 0)
3650 /* remove one character width for removed cursor text character */
3651 pos->width -= font_width;
3652 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3654 DrawText(startx, starty, setup.player_name, font_nr);
3655 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3662 game_status = GAME_MODE_MAIN;
3664 else if (key == KSYM_Escape)
3666 strcpy(setup.player_name, last_player_name);
3670 game_status = GAME_MODE_MAIN;
3675 pos->width = (strlen(setup.player_name) + 1) * font_width;
3676 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3678 DrawText(startx, starty, setup.player_name, font_active_nr);
3679 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3683 pos->width = strlen(setup.player_name) * font_width;
3684 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3686 DrawText(startx, starty, setup.player_name, font_nr);
3691 /* ========================================================================= */
3692 /* tree menu functions */
3693 /* ========================================================================= */
3695 static void DrawChooseTree(TreeInfo **ti_ptr)
3699 FreeScreenGadgets();
3700 CreateScreenGadgets();
3702 CloseDoor(DOOR_CLOSE_2);
3705 FadeOut(REDRAW_FIELD);
3710 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3711 MapScreenTreeGadgets(*ti_ptr);
3714 FadeIn(REDRAW_FIELD);
3720 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3722 struct GadgetInfo *gi = screen_gadget[id];
3723 int items_max, items_visible, item_position;
3725 items_max = numTreeInfoInGroup(ti);
3726 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3727 item_position = first_entry;
3729 if (item_position > items_max - items_visible)
3730 item_position = items_max - items_visible;
3732 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3733 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3734 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3737 static void drawChooseTreeList(int first_entry, int num_page_entries,
3741 char *title_string = NULL;
3742 int yoffset_sets = MENU_TITLE1_YPOS;
3743 int yoffset_setup = 16;
3744 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3746 int last_game_status = game_status; /* save current game status */
3748 title_string = ti->infotext;
3750 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3752 /* force LEVELS font on artwork setup screen */
3753 game_status = GAME_MODE_LEVELS;
3756 /* clear tree list area, but not title or scrollbar */
3757 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3758 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3759 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3761 /* clear tree list area, but not title or scrollbar */
3762 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3763 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3764 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3767 for (i = 0; i < num_page_entries; i++)
3769 TreeInfo *node, *node_first;
3770 int entry_pos = first_entry + i;
3771 int xpos = MENU_SCREEN_START_XPOS;
3772 int ypos = MENU_SCREEN_START_YPOS + i;
3773 int startx = mSX + xpos * 32;
3774 int starty = mSY + ypos * 32;
3775 int font_nr = FONT_TEXT_1;
3776 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3777 int startx_text = startx + font_xoffset;
3778 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3779 int text_size = startx_scrollbar - startx_text;
3780 int max_buffer_len = text_size / getFontWidth(font_nr);
3781 char buffer[max_buffer_len + 1];
3783 node_first = getTreeInfoFirstGroupEntry(ti);
3784 node = getTreeInfoFromPos(node_first, entry_pos);
3786 strncpy(buffer, node->name, max_buffer_len);
3787 buffer[max_buffer_len] = '\0';
3789 DrawText(startx, starty, buffer, font_nr + node->color);
3791 if (node->parent_link)
3792 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3793 else if (node->level_group)
3794 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3796 initCursor(i, IMG_MENU_BUTTON);
3799 game_status = last_game_status; /* restore current game status */
3801 redraw_mask |= REDRAW_FIELD;
3804 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3806 TreeInfo *node, *node_first;
3807 int x, last_redraw_mask = redraw_mask;
3808 int ypos = MENU_TITLE2_YPOS;
3809 int font_nr = FONT_TITLE_2;
3811 if (ti->type != TREE_TYPE_LEVEL_DIR)
3814 node_first = getTreeInfoFirstGroupEntry(ti);
3815 node = getTreeInfoFromPos(node_first, entry_pos);
3817 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3819 if (node->parent_link)
3820 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3822 else if (node->level_group)
3823 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3825 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3826 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3827 node->levels, node->class_desc);
3829 /* let BackToFront() redraw only what is needed */
3830 redraw_mask = last_redraw_mask | REDRAW_TILES;
3831 for (x = 0; x < SCR_FIELDX; x++)
3832 MarkTileDirty(x, 1);
3835 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3838 TreeInfo *ti = *ti_ptr;
3840 int y = ti->cl_cursor;
3841 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3842 int num_entries = numTreeInfoInGroup(ti);
3843 int num_page_entries;
3844 int last_game_status = game_status; /* save current game status */
3845 boolean position_set_by_scrollbar = (dx == 999);
3847 /* force LEVELS draw offset on choose level and artwork setup screen */
3848 game_status = GAME_MODE_LEVELS;
3850 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3851 num_page_entries = num_entries;
3853 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3855 game_status = last_game_status; /* restore current game status */
3857 if (button == MB_MENU_INITIALIZE)
3859 int num_entries = numTreeInfoInGroup(ti);
3860 int entry_pos = posTreeInfo(ti);
3862 if (ti->cl_first == -1)
3864 /* only on initialization */
3865 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3866 ti->cl_cursor = entry_pos - ti->cl_first;
3868 else if (ti->cl_cursor >= num_page_entries ||
3869 (num_entries > num_page_entries &&
3870 num_entries - ti->cl_first < num_page_entries))
3872 /* only after change of list size (by custom graphic configuration) */
3873 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3874 ti->cl_cursor = entry_pos - ti->cl_first;
3877 if (position_set_by_scrollbar)
3880 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3883 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3884 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3885 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3889 else if (button == MB_MENU_LEAVE)
3893 PlaySound(SND_MENU_ITEM_SELECTING);
3895 if (ti->node_parent)
3897 *ti_ptr = ti->node_parent;
3898 DrawChooseTree(ti_ptr);
3900 else if (game_status == GAME_MODE_SETUP)
3902 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3904 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3905 execSetupGraphics();
3911 game_status = GAME_MODE_MAIN;
3913 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3922 if (mx || my) /* mouse input */
3924 int last_game_status = game_status; /* save current game status */
3926 /* force LEVELS draw offset on artwork setup screen */
3927 game_status = GAME_MODE_LEVELS;
3929 x = (mx - mSX) / 32;
3930 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3932 game_status = last_game_status; /* restore current game status */
3934 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3936 /* move cursor instead of scrolling when already at start/end of list */
3937 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3939 else if (dy == +1 * SCROLL_LINE &&
3940 ti->cl_first + num_page_entries == num_entries)
3943 /* handle scrolling screen one line or page */
3944 if (ti->cl_cursor + dy < 0 ||
3945 ti->cl_cursor + dy > num_page_entries - 1)
3947 if (ABS(dy) == SCROLL_PAGE)
3948 step = num_page_entries - 1;
3950 if (dy < 0 && ti->cl_first > 0)
3952 /* scroll page/line up */
3954 ti->cl_first -= step;
3955 if (ti->cl_first < 0)
3958 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3959 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3960 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3962 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3965 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3967 /* scroll page/line down */
3969 ti->cl_first += step;
3970 if (ti->cl_first + num_page_entries > num_entries)
3971 ti->cl_first = MAX(0, num_entries - num_page_entries);
3973 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3974 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3975 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3977 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3984 /* handle moving cursor one line */
3985 y = ti->cl_cursor + dy;
3990 TreeInfo *node_first, *node_cursor;
3991 int entry_pos = ti->cl_first + y;
3993 node_first = getTreeInfoFirstGroupEntry(ti);
3994 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3996 if (node_cursor->node_group)
4000 PlaySound(SND_MENU_ITEM_SELECTING);
4002 node_cursor->cl_first = ti->cl_first;
4003 node_cursor->cl_cursor = ti->cl_cursor;
4004 *ti_ptr = node_cursor->node_group;
4005 DrawChooseTree(ti_ptr);
4010 else if (dx == -1 && ti->node_parent)
4014 PlaySound(SND_MENU_ITEM_SELECTING);
4016 *ti_ptr = ti->node_parent;
4017 DrawChooseTree(ti_ptr);
4022 if (!anyScrollbarGadgetActive() &&
4023 IN_VIS_FIELD(x, y) &&
4024 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4025 y >= 0 && y < num_page_entries)
4029 if (y != ti->cl_cursor)
4031 PlaySound(SND_MENU_ITEM_ACTIVATING);
4033 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4034 drawChooseTreeCursor(y, TRUE);
4035 drawChooseTreeInfo(ti->cl_first + y, ti);
4042 TreeInfo *node_first, *node_cursor;
4043 int entry_pos = ti->cl_first + y;
4045 PlaySound(SND_MENU_ITEM_SELECTING);
4047 node_first = getTreeInfoFirstGroupEntry(ti);
4048 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4050 if (node_cursor->node_group)
4054 node_cursor->cl_first = ti->cl_first;
4055 node_cursor->cl_cursor = ti->cl_cursor;
4056 *ti_ptr = node_cursor->node_group;
4057 DrawChooseTree(ti_ptr);
4059 else if (node_cursor->parent_link)
4063 *ti_ptr = node_cursor->node_parent;
4064 DrawChooseTree(ti_ptr);
4070 node_cursor->cl_first = ti->cl_first;
4071 node_cursor->cl_cursor = ti->cl_cursor;
4072 *ti_ptr = node_cursor;
4074 if (ti->type == TREE_TYPE_LEVEL_DIR)
4076 LoadLevelSetup_SeriesInfo();
4078 SaveLevelSetup_LastSeries();
4079 SaveLevelSetup_SeriesInfo();
4083 if (game_status == GAME_MODE_SETUP)
4085 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4087 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
4088 execSetupGraphics();
4094 game_status = GAME_MODE_MAIN;
4102 void DrawChooseLevel()
4104 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4106 DrawChooseTree(&leveldir_current);
4112 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4114 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4119 void DrawHallOfFame(int highlight_position)
4122 FadeSoundsAndMusic();
4124 /* (this is needed when called from GameEnd() after winning a game) */
4125 KeyboardAutoRepeatOn();
4128 /* (this is needed when called from GameEnd() after winning a game) */
4129 SetDrawDeactivationMask(REDRAW_NONE);
4130 SetDrawBackgroundMask(REDRAW_FIELD);
4132 CloseDoor(DOOR_CLOSE_2);
4134 if (highlight_position < 0)
4135 LoadScore(level_nr);
4140 FadeOut(REDRAW_FIELD);
4148 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4151 FadeIn(REDRAW_FIELD);
4155 static void drawHallOfFameList(int first_entry, int highlight_position)
4159 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4162 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4163 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4164 "HighScores of Level %d", level_nr);
4166 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4168 int entry = first_entry + i;
4169 boolean active = (entry == highlight_position);
4170 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4171 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4172 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4173 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4174 int dx1 = 3 * getFontWidth(font_nr1);
4175 int dx2 = dx1 + getFontWidth(font_nr1);
4176 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4177 int sy = mSY + 64 + i * 32;
4179 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4180 DrawText(mSX + dx1, sy, ".", font_nr1);
4181 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4183 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4184 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4186 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4189 redraw_mask |= REDRAW_FIELD;
4192 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4194 static int first_entry = 0;
4195 static int highlight_position = 0;
4196 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4198 if (button == MB_MENU_INITIALIZE)
4201 highlight_position = mx;
4202 drawHallOfFameList(first_entry, highlight_position);
4207 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4208 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4212 if (first_entry > 0)
4214 first_entry -= step;
4215 if (first_entry < 0)
4218 drawHallOfFameList(first_entry, highlight_position);
4223 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4225 first_entry += step;
4226 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4227 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4229 drawHallOfFameList(first_entry, highlight_position);
4232 else if (button == MB_MENU_LEAVE)
4234 PlaySound(SND_MENU_ITEM_SELECTING);
4236 FadeSound(SND_BACKGROUND_SCORES);
4238 game_status = GAME_MODE_MAIN;
4242 else if (button == MB_MENU_CHOICE)
4244 PlaySound(SND_MENU_ITEM_SELECTING);
4246 FadeSound(SND_BACKGROUND_SCORES);
4249 FadeOut(REDRAW_FIELD);
4252 game_status = GAME_MODE_MAIN;
4254 DrawAndFadeInMainMenu(REDRAW_FIELD);
4257 if (game_status == GAME_MODE_SCORES)
4258 PlayMenuSoundIfLoop();
4264 /* ========================================================================= */
4265 /* setup screen functions */
4266 /* ========================================================================= */
4268 static struct TokenInfo *setup_info;
4269 static int num_setup_info;
4271 static char *screen_mode_text;
4272 static char *game_speed_text;
4273 static char *graphics_set_name;
4274 static char *sounds_set_name;
4275 static char *music_set_name;
4277 static void execSetupMain()
4283 setup_mode = SETUP_MODE_MAIN;
4287 static void execSetupGame()
4293 if (game_speeds == NULL)
4297 for (i = 0; game_speeds_list[i].value != -1; i++)
4299 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4300 char identifier[32], name[32];
4301 int value = game_speeds_list[i].value;
4302 char *text = game_speeds_list[i].text;
4304 ti->node_top = &game_speeds;
4305 ti->sort_priority = 10000 - value;
4307 sprintf(identifier, "%d", value);
4308 sprintf(name, "%s", text);
4310 setString(&ti->identifier, identifier);
4311 setString(&ti->name, name);
4312 setString(&ti->name_sorting, name);
4313 setString(&ti->infotext, "Game Speed");
4315 pushTreeInfo(&game_speeds, ti);
4318 /* sort game speed values to start with slowest game speed */
4319 sortTreeInfo(&game_speeds);
4321 /* set current game speed to configured game speed value */
4322 game_speed_current =
4323 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4325 /* if that fails, set current game speed to reliable default value */
4326 if (game_speed_current == NULL)
4327 game_speed_current =
4328 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4330 /* if that also fails, set current game speed to first available speed */
4331 if (game_speed_current == NULL)
4332 game_speed_current = game_speeds;
4335 setup.game_frame_delay = atoi(game_speed_current->identifier);
4337 /* needed for displaying game speed text instead of identifier */
4338 game_speed_text = game_speed_current->name;
4340 setup_mode = SETUP_MODE_GAME;
4344 static void execSetupChooseGameSpeed()
4350 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4354 static void execSetupEditor()
4360 setup_mode = SETUP_MODE_EDITOR;
4364 static void execSetupGraphics()
4370 if (video.fullscreen_available && screen_modes == NULL)
4374 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4376 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4377 char identifier[32], name[32];
4378 int x = video.fullscreen_modes[i].width;
4379 int y = video.fullscreen_modes[i].height;
4382 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4384 ti->node_top = &screen_modes;
4385 ti->sort_priority = x * 10000 + y;
4387 sprintf(identifier, "%dx%d", x, y);
4388 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4390 setString(&ti->identifier, identifier);
4391 setString(&ti->name, name);
4392 setString(&ti->name_sorting, name);
4393 setString(&ti->infotext, "Fullscreen Mode");
4395 pushTreeInfo(&screen_modes, ti);
4398 /* sort fullscreen modes to start with lowest available screen resolution */
4399 sortTreeInfo(&screen_modes);
4401 /* set current screen mode for fullscreen mode to configured setup value */
4402 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4403 setup.fullscreen_mode);
4405 /* if that fails, set current screen mode to reliable default value */
4406 if (screen_mode_current == NULL)
4407 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4408 DEFAULT_FULLSCREEN_MODE);
4410 /* if that also fails, set current screen mode to first available mode */
4411 if (screen_mode_current == NULL)
4412 screen_mode_current = screen_modes;
4414 if (screen_mode_current == NULL)
4415 video.fullscreen_available = FALSE;
4418 if (video.fullscreen_available)
4420 setup.fullscreen_mode = screen_mode_current->identifier;
4422 /* needed for displaying screen mode name instead of identifier */
4423 screen_mode_text = screen_mode_current->name;
4426 setup_mode = SETUP_MODE_GRAPHICS;
4430 static void execSetupChooseScreenMode()
4436 if (!video.fullscreen_available)
4439 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4443 static void execSetupSound()
4449 setup_mode = SETUP_MODE_SOUND;
4453 static void execSetupArtwork()
4459 setup.graphics_set = artwork.gfx_current->identifier;
4460 setup.sounds_set = artwork.snd_current->identifier;
4461 setup.music_set = artwork.mus_current->identifier;
4463 /* needed if last screen (setup choice) changed graphics, sounds or music */
4464 ReloadCustomArtwork(0);
4466 /* needed for displaying artwork name instead of artwork identifier */
4467 graphics_set_name = artwork.gfx_current->name;
4468 sounds_set_name = artwork.snd_current->name;
4469 music_set_name = artwork.mus_current->name;
4471 setup_mode = SETUP_MODE_ARTWORK;
4475 static void execSetupChooseGraphics()
4481 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4485 static void execSetupChooseSounds()
4491 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4495 static void execSetupChooseMusic()
4501 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4505 static void execSetupInput()
4511 setup_mode = SETUP_MODE_INPUT;
4515 static void execSetupShortcut1()
4521 setup_mode = SETUP_MODE_SHORTCUT_1;
4525 static void execSetupShortcut2()
4531 setup_mode = SETUP_MODE_SHORTCUT_2;
4535 static void execExitSetup()
4541 game_status = GAME_MODE_MAIN;
4543 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4549 static void execSaveAndExitSetup()
4555 static struct TokenInfo setup_info_main[] =
4557 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4558 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4559 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4560 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4561 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4562 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4563 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
4564 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
4565 { TYPE_EMPTY, NULL, "" },
4566 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4567 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4572 static struct TokenInfo setup_info_game[] =
4574 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4575 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4576 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4577 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4578 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4579 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4580 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4581 { TYPE_STRING, &game_speed_text, "" },
4582 { TYPE_EMPTY, NULL, "" },
4583 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4588 static struct TokenInfo setup_info_editor[] =
4591 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4592 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4593 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4594 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4595 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4596 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4597 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4598 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4600 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4601 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4602 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4604 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4606 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4607 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4608 { TYPE_EMPTY, NULL, "" },
4610 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4611 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4612 { TYPE_EMPTY, NULL, "" },
4614 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4615 { TYPE_EMPTY, NULL, "" },
4616 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4621 static struct TokenInfo setup_info_graphics[] =
4623 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4624 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4625 { TYPE_STRING, &screen_mode_text, "" },
4626 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
4628 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4629 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4631 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4632 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4633 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4634 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4635 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4636 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4637 { TYPE_EMPTY, NULL, "" },
4638 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4643 static struct TokenInfo setup_info_sound[] =
4645 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4646 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4647 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4648 { TYPE_EMPTY, NULL, "" },
4649 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4654 static struct TokenInfo setup_info_artwork[] =
4656 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4657 { TYPE_STRING, &graphics_set_name, "" },
4658 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4659 { TYPE_STRING, &sounds_set_name, "" },
4660 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4661 { TYPE_STRING, &music_set_name, "" },
4662 { TYPE_EMPTY, NULL, "" },
4664 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4665 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4666 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4668 { TYPE_STRING, NULL, "Override Level Artwork:"},
4669 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4670 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4671 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4673 { TYPE_EMPTY, NULL, "" },
4674 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4679 static struct TokenInfo setup_info_input[] =
4681 { TYPE_SWITCH, NULL, "Player:" },
4682 { TYPE_SWITCH, NULL, "Device:" },
4683 { TYPE_ENTER_MENU, NULL, "" },
4684 { TYPE_EMPTY, NULL, "" },
4685 { TYPE_EMPTY, NULL, "" },
4686 { TYPE_EMPTY, NULL, "" },
4687 { TYPE_EMPTY, NULL, "" },
4688 { TYPE_EMPTY, NULL, "" },
4689 { TYPE_EMPTY, NULL, "" },
4690 { TYPE_EMPTY, NULL, "" },
4691 { TYPE_EMPTY, NULL, "" },
4692 { TYPE_EMPTY, NULL, "" },
4693 { TYPE_EMPTY, NULL, "" },
4694 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4699 static struct TokenInfo setup_info_shortcut_1[] =
4701 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4702 { TYPE_KEY, &setup.shortcut.save_game, "" },
4703 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4704 { TYPE_KEY, &setup.shortcut.load_game, "" },
4705 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4706 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4707 { TYPE_EMPTY, NULL, "" },
4708 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4709 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4710 { TYPE_EMPTY, NULL, "" },
4711 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4716 static struct TokenInfo setup_info_shortcut_2[] =
4718 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4719 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4720 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4721 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4722 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4723 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4724 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4725 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4726 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4727 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4728 { TYPE_EMPTY, NULL, "" },
4729 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4734 static Key getSetupKey()
4736 Key key = KSYM_UNDEFINED;
4737 boolean got_key_event = FALSE;
4739 while (!got_key_event)
4741 if (PendingEvent()) /* got event */
4749 case EVENT_KEYPRESS:
4751 key = GetEventKey((KeyEvent *)&event, TRUE);
4753 /* press 'Escape' or 'Enter' to keep the existing key binding */
4754 if (key == KSYM_Escape || key == KSYM_Return)
4755 key = KSYM_UNDEFINED; /* keep old value */
4757 got_key_event = TRUE;
4761 case EVENT_KEYRELEASE:
4762 key_joystick_mapping = 0;
4766 HandleOtherEvents(&event);
4774 /* don't eat all CPU time */
4781 static int getSetupTextFont(int type)
4783 if (type & (TYPE_SWITCH |
4794 static int getSetupValueFont(int type, void *value)
4796 if (type & TYPE_KEY)
4797 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4798 else if (type & TYPE_STRING)
4799 return FONT_VALUE_2;
4800 else if (type & TYPE_ECS_AGA)
4801 return FONT_VALUE_1;
4802 else if (type & TYPE_BOOLEAN_STYLE)
4803 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4805 return FONT_VALUE_1;
4808 static void drawSetupValue(int pos)
4810 boolean font_draw_xoffset_modified = FALSE;
4811 int font_draw_xoffset_old = -1;
4812 int xpos = MENU_SCREEN_VALUE_XPOS;
4813 int ypos = MENU_SCREEN_START_YPOS + pos;
4814 int startx = mSX + xpos * 32;
4815 int starty = mSY + ypos * 32;
4816 int font_nr, font_width;
4817 int type = setup_info[pos].type;
4818 void *value = setup_info[pos].value;
4819 char *value_string = getSetupValue(type, value);
4822 if (value_string == NULL)
4825 if (type & TYPE_KEY)
4827 xpos = MENU_SCREEN_START_XPOS;
4829 if (type & TYPE_QUERY)
4831 value_string = "<press key>";
4834 else if (type & TYPE_STRING)
4836 int max_value_len = (SCR_FIELDX - 2) * 2;
4838 xpos = MENU_SCREEN_START_XPOS;
4840 if (strlen(value_string) > max_value_len)
4841 value_string[max_value_len] = '\0';
4844 startx = mSX + xpos * 32;
4845 starty = mSY + ypos * 32;
4846 font_nr = getSetupValueFont(type, value);
4847 font_width = getFontWidth(font_nr);
4849 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4850 if (setup_mode != SETUP_MODE_INPUT)
4852 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4853 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4854 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4855 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4856 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4857 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4858 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4859 boolean correct_font_draw_xoffset = FALSE;
4861 if (xpos == MENU_SCREEN_START_XPOS &&
4862 startx + font1_xoffset < text_startx + text_font_xoffset)
4863 correct_font_draw_xoffset = TRUE;
4865 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4866 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4867 correct_font_draw_xoffset = TRUE;
4869 /* check if setup value would overlap with setup text when printed */
4870 /* (this can happen for extreme/wrong values for font draw offset) */
4871 if (correct_font_draw_xoffset)
4873 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4874 font_draw_xoffset_modified = TRUE;
4876 if (type & TYPE_KEY)
4877 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4878 else if (!(type & TYPE_STRING))
4879 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4880 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4884 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4885 DrawText(startx + i * font_width, starty, " ", font_nr);
4887 DrawText(startx, starty, value_string, font_nr);
4889 if (font_draw_xoffset_modified)
4890 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4893 static void changeSetupValue(int pos)
4895 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4897 *(boolean *)setup_info[pos].value ^= TRUE;
4899 else if (setup_info[pos].type & TYPE_KEY)
4903 setup_info[pos].type |= TYPE_QUERY;
4904 drawSetupValue(pos);
4905 setup_info[pos].type &= ~TYPE_QUERY;
4907 key = getSetupKey();
4908 if (key != KSYM_UNDEFINED)
4909 *(Key *)setup_info[pos].value = key;
4912 drawSetupValue(pos);
4915 static void DrawCursorAndText_Setup(int pos, boolean active)
4917 int xpos = MENU_SCREEN_START_XPOS;
4918 int ypos = MENU_SCREEN_START_YPOS + pos;
4919 int font_nr = getSetupTextFont(setup_info[pos].type);
4921 if (setup_info == setup_info_input)
4922 font_nr = FONT_MENU_1;
4925 font_nr = FONT_ACTIVE(font_nr);
4927 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4929 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4930 drawCursor(pos, active);
4933 static void DrawSetupScreen_Generic()
4935 char *title_string = NULL;
4939 CloseDoor(DOOR_CLOSE_2);
4942 FadeOut(REDRAW_FIELD);
4947 if (setup_mode == SETUP_MODE_MAIN)
4949 setup_info = setup_info_main;
4950 title_string = "Setup";
4952 else if (setup_mode == SETUP_MODE_GAME)
4954 setup_info = setup_info_game;
4955 title_string = "Setup Game";
4957 else if (setup_mode == SETUP_MODE_EDITOR)
4959 setup_info = setup_info_editor;
4960 title_string = "Setup Editor";
4962 else if (setup_mode == SETUP_MODE_GRAPHICS)
4964 setup_info = setup_info_graphics;
4965 title_string = "Setup Graphics";
4967 else if (setup_mode == SETUP_MODE_SOUND)
4969 setup_info = setup_info_sound;
4970 title_string = "Setup Sound";
4972 else if (setup_mode == SETUP_MODE_ARTWORK)
4974 setup_info = setup_info_artwork;
4975 title_string = "Custom Artwork";
4977 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
4979 setup_info = setup_info_shortcut_1;
4980 title_string = "Setup Shortcuts";
4982 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
4984 setup_info = setup_info_shortcut_2;
4985 title_string = "Setup Shortcuts";
4988 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4991 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4993 void *value_ptr = setup_info[i].value;
4996 int xpos = MENU_SCREEN_START_XPOS;
4997 int ypos = MENU_SCREEN_START_YPOS + i;
5001 /* set some entries to "unchangeable" according to other variables */
5002 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5003 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5004 (value_ptr == &setup.sound_music && !audio.music_available) ||
5005 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5006 (value_ptr == &screen_mode_text && !video.fullscreen_available))
5007 setup_info[i].type |= TYPE_GHOSTED;
5009 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5010 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5011 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5012 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5013 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5014 initCursor(i, IMG_MENU_BUTTON);
5017 DrawCursorAndText_Setup(i, FALSE);
5019 font_nr = getSetupTextFont(setup_info[i].type);
5021 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
5024 if (setup_info[i].type & TYPE_VALUE)
5031 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5032 "Joysticks deactivated in setup menu");
5036 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5040 FadeIn(REDRAW_FIELD);
5045 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5049 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5051 static int choice_store[MAX_SETUP_MODES];
5052 int choice = choice_store[setup_mode]; /* always starts with 0 */
5056 if (button == MB_MENU_INITIALIZE)
5058 /* advance to first valid menu entry */
5059 while (choice < num_setup_info &&
5060 setup_info[choice].type & TYPE_SKIP_ENTRY)
5062 choice_store[setup_mode] = choice;
5065 DrawCursorAndText_Setup(choice, TRUE);
5067 drawCursor(choice, TRUE);
5072 else if (button == MB_MENU_LEAVE)
5074 PlaySound(SND_MENU_ITEM_SELECTING);
5076 for (y = 0; y < num_setup_info; y++)
5078 if (setup_info[y].type & TYPE_LEAVE_MENU)
5080 void (*menu_callback_function)(void) = setup_info[y].value;
5084 menu_callback_function();
5086 break; /* absolutely needed because function changes 'setup_info'! */
5093 if (mx || my) /* mouse input */
5095 x = (mx - mSX) / 32;
5096 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5098 else if (dx || dy) /* keyboard input */
5102 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5104 if (setup_info[choice].type & menu_navigation_type ||
5105 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5106 button = MB_MENU_CHOICE;
5111 /* jump to next non-empty menu entry (up or down) */
5112 while (y > 0 && y < num_setup_info - 1 &&
5113 setup_info[y].type & TYPE_SKIP_ENTRY)
5117 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5121 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5123 PlaySound(SND_MENU_ITEM_ACTIVATING);
5126 DrawCursorAndText_Setup(choice, FALSE);
5127 DrawCursorAndText_Setup(y, TRUE);
5129 drawCursor(choice, FALSE);
5130 drawCursor(y, TRUE);
5133 choice = choice_store[setup_mode] = y;
5136 else if (!(setup_info[y].type & TYPE_GHOSTED))
5138 PlaySound(SND_MENU_ITEM_SELECTING);
5140 /* when selecting key headline, execute function for key value change */
5141 if (setup_info[y].type & TYPE_KEYTEXT &&
5142 setup_info[y + 1].type & TYPE_KEY)
5145 /* when selecting string value, execute function for list selection */
5146 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5147 setup_info[y - 1].type & TYPE_ENTER_LIST)
5150 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5152 void (*menu_callback_function)(void) = setup_info[y].value;
5154 FadeSetFromType(setup_info[y].type);
5156 menu_callback_function();
5160 if (setup_info[y].type & TYPE_VALUE)
5161 changeSetupValue(y);
5167 void DrawSetupScreen_Input()
5174 FadeOut(REDRAW_FIELD);
5180 setup_info = setup_info_input;
5183 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5186 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5188 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5189 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5190 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5191 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5192 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5193 initCursor(i, IMG_MENU_BUTTON);
5195 DrawCursorAndText_Setup(i, FALSE);
5198 initCursor(0, IMG_MENU_BUTTON);
5199 initCursor(1, IMG_MENU_BUTTON);
5200 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
5201 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5203 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
5204 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
5205 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
5209 DeactivateJoystickForCalibration();
5212 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5213 "Joysticks deactivated on this screen");
5216 /* create gadgets for setup input menu screen */
5217 FreeScreenGadgets();
5218 CreateScreenGadgets();
5220 /* map gadgets for setup input menu screen */
5221 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5223 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5226 FadeIn(REDRAW_FIELD);
5232 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5234 if (device_name == NULL)
5237 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5240 if (strlen(device_name) > 1)
5242 char c1 = device_name[strlen(device_name) - 1];
5243 char c2 = device_name[strlen(device_name) - 2];
5245 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5246 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5249 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5250 strlen(device_name));
5253 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5256 static struct SetupKeyboardInfo custom_key;
5263 { &custom_key.left, "Joystick Left" },
5264 { &custom_key.right, "Joystick Right" },
5265 { &custom_key.up, "Joystick Up" },
5266 { &custom_key.down, "Joystick Down" },
5267 { &custom_key.snap, "Button 1" },
5268 { &custom_key.drop, "Button 2" }
5270 static char *joystick_name[MAX_PLAYERS] =
5277 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5281 custom_key = setup.input[player_nr].key;
5283 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5284 FONT_INPUT_1_ACTIVE);
5286 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5288 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5289 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5291 if (setup.input[player_nr].use_joystick)
5293 char *device_name = setup.input[player_nr].joy.device_name;
5294 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5295 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5297 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5298 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5302 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5303 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5306 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5308 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5309 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5310 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5311 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5313 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5314 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5315 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5316 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5317 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5318 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5320 for (i = 0; i < 6; i++)
5322 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5324 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5326 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5327 (setup.input[player_nr].use_joystick ?
5329 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5333 static int input_player_nr = 0;
5335 void HandleSetupScreen_Input_Player(int step, int direction)
5337 int old_player_nr = input_player_nr;
5340 new_player_nr = old_player_nr + step * direction;
5341 if (new_player_nr < 0)
5343 if (new_player_nr > MAX_PLAYERS - 1)
5344 new_player_nr = MAX_PLAYERS - 1;
5346 if (new_player_nr != old_player_nr)
5348 input_player_nr = new_player_nr;
5350 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5354 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5356 static int choice = 0;
5359 int pos_start = SETUPINPUT_SCREEN_POS_START;
5360 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5361 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5362 int pos_end = SETUPINPUT_SCREEN_POS_END;
5364 if (button == MB_MENU_INITIALIZE)
5366 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5369 DrawCursorAndText_Setup(choice, TRUE);
5371 drawCursor(choice, TRUE);
5376 else if (button == MB_MENU_LEAVE)
5378 setup_mode = SETUP_MODE_MAIN;
5385 if (mx || my) /* mouse input */
5387 x = (mx - mSX) / 32;
5388 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5390 else if (dx || dy) /* keyboard input */
5392 if (dx && choice == 0)
5393 x = (dx < 0 ? 10 : 12);
5394 else if ((dx && choice == 1) ||
5395 (dx == +1 && choice == 2) ||
5396 (dx == -1 && choice == pos_end))
5397 button = MB_MENU_CHOICE;
5401 if (y >= pos_empty1 && y <= pos_empty2)
5402 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5405 if (y == 0 && dx != 0 && button)
5407 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5409 else if (IN_VIS_FIELD(x, y) &&
5410 y >= pos_start && y <= pos_end &&
5411 !(y >= pos_empty1 && y <= pos_empty2))
5418 DrawCursorAndText_Setup(choice, FALSE);
5419 DrawCursorAndText_Setup(y, TRUE);
5421 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5423 drawCursor(choice, FALSE);
5424 drawCursor(y, TRUE);
5434 char *device_name = setup.input[input_player_nr].joy.device_name;
5436 if (!setup.input[input_player_nr].use_joystick)
5438 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5440 setJoystickDeviceToNr(device_name, new_device_nr);
5441 setup.input[input_player_nr].use_joystick = TRUE;
5445 int device_nr = getJoystickNrFromDeviceName(device_name);
5446 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5448 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5449 setup.input[input_player_nr].use_joystick = FALSE;
5451 setJoystickDeviceToNr(device_name, new_device_nr);
5454 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5458 if (setup.input[input_player_nr].use_joystick)
5461 CalibrateJoystick(input_player_nr);
5464 CustomizeKeyboard(input_player_nr);
5466 else if (y == pos_end)
5472 setup_mode = SETUP_MODE_MAIN;
5479 void CustomizeKeyboard(int player_nr)
5483 boolean finished = FALSE;
5484 static struct SetupKeyboardInfo custom_key;
5489 } customize_step[] =
5491 { &custom_key.left, "Move Left" },
5492 { &custom_key.right, "Move Right" },
5493 { &custom_key.up, "Move Up" },
5494 { &custom_key.down, "Move Down" },
5495 { &custom_key.snap, "Snap Field" },
5496 { &custom_key.drop, "Drop Element" }
5499 /* read existing key bindings from player setup */
5500 custom_key = setup.input[player_nr].key;
5503 FadeOut(REDRAW_FIELD);
5507 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5515 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5516 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5517 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5518 "Key:", FONT_INPUT_1_ACTIVE);
5519 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5520 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5523 FadeIn(REDRAW_FIELD);
5530 if (PendingEvent()) /* got event */
5538 case EVENT_KEYPRESS:
5540 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5542 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5544 if (key == KSYM_Escape)
5545 FadeSkipNextFadeIn();
5551 /* all keys configured -- wait for "Escape" or "Return" key */
5555 /* press 'Enter' to keep the existing key binding */
5556 if (key == KSYM_Return)
5557 key = *customize_step[step_nr].key;
5559 /* check if key already used */
5560 for (i = 0; i < step_nr; i++)
5561 if (*customize_step[i].key == key)
5566 /* got new key binding */
5567 *customize_step[step_nr].key = key;
5568 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5570 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5571 getKeyNameFromKey(key), FONT_VALUE_1);
5574 /* un-highlight last query */
5575 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5576 customize_step[step_nr - 1].text, FONT_MENU_1);
5577 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5578 "Key:", FONT_MENU_1);
5580 /* press 'Enter' to leave */
5583 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5584 "Press Enter", FONT_TITLE_1);
5588 /* query next key binding */
5589 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5590 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5591 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5592 "Key:", FONT_INPUT_1_ACTIVE);
5593 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5594 getKeyNameFromKey(*customize_step[step_nr].key),
5599 case EVENT_KEYRELEASE:
5600 key_joystick_mapping = 0;
5604 HandleOtherEvents(&event);
5612 /* don't eat all CPU time */
5616 /* write new key bindings back to player setup */
5617 setup.input[player_nr].key = custom_key;
5620 DrawSetupScreen_Input();
5623 static boolean CalibrateJoystickMain(int player_nr)
5625 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5626 int new_joystick_xright = JOYSTICK_XMIDDLE;
5627 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5628 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5629 int new_joystick_xmiddle, new_joystick_ymiddle;
5631 int joystick_fd = joystick.fd[player_nr];
5632 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5633 boolean check[3][3];
5634 int check_remaining = 3 * 3;
5639 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5642 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5646 FadeOut(REDRAW_FIELD);
5650 for (y = 0; y < 3; y++)
5652 for (x = 0; x < 3; x++)
5654 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5655 check[x][y] = FALSE;
5659 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5660 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5661 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5662 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5663 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5664 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5665 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5667 joy_value = Joystick(player_nr);
5668 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5669 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5671 /* eventually uncalibrated center position (joystick could be uncentered) */
5672 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5675 new_joystick_xmiddle = joy_x;
5676 new_joystick_ymiddle = joy_y;
5678 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5681 FadeIn(REDRAW_FIELD);
5686 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5691 if (PendingEvent()) /* got event */
5699 case EVENT_KEYPRESS:
5700 switch (GetEventKey((KeyEvent *)&event, TRUE))
5703 if (check_remaining == 0)
5708 FadeSkipNextFadeIn();
5717 case EVENT_KEYRELEASE:
5718 key_joystick_mapping = 0;
5722 HandleOtherEvents(&event);
5727 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5730 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5731 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5732 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5733 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5735 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5736 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5737 setup.input[player_nr].joy.xright = new_joystick_xright;
5738 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5739 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5740 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5742 CheckJoystickData();
5744 joy_value = Joystick(player_nr);
5746 if (joy_value & JOY_BUTTON && check_remaining == 0)
5749 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5750 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5752 if (x != last_x || y != last_y)
5754 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5755 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5760 if (check_remaining > 0 && !check[x+1][y+1])
5762 check[x+1][y+1] = TRUE;
5768 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5769 setup.input[player_nr].joy.xleft,
5770 setup.input[player_nr].joy.xmiddle,
5771 setup.input[player_nr].joy.xright);
5772 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5773 setup.input[player_nr].joy.yupper,
5774 setup.input[player_nr].joy.ymiddle,
5775 setup.input[player_nr].joy.ylower);
5784 /* don't eat all CPU time */
5788 /* calibrated center position (joystick should now be centered) */
5789 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5792 new_joystick_xmiddle = joy_x;
5793 new_joystick_ymiddle = joy_y;
5798 DrawSetupScreen_Input();
5801 /* wait until the last pressed button was released */
5802 while (Joystick(player_nr) & JOY_BUTTON)
5804 if (PendingEvent()) /* got event */
5809 HandleOtherEvents(&event);
5818 void CalibrateJoystick(int player_nr)
5820 if (!CalibrateJoystickMain(player_nr))
5822 char *device_name = setup.input[player_nr].joy.device_name;
5823 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5824 int xpos = mSX - SX;
5825 int ypos = mSY - SY;
5829 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5830 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5833 Delay(2000); /* show error message for a short time */
5839 DrawSetupScreen_Input();
5843 void DrawSetupScreen()
5845 DeactivateJoystick();
5847 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5849 if (setup_mode == SETUP_MODE_INPUT)
5850 DrawSetupScreen_Input();
5851 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5852 DrawChooseTree(&game_speed_current);
5853 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5854 DrawChooseTree(&screen_mode_current);
5855 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5856 DrawChooseTree(&artwork.gfx_current);
5857 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5858 DrawChooseTree(&artwork.snd_current);
5859 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5860 DrawChooseTree(&artwork.mus_current);
5862 DrawSetupScreen_Generic();
5868 void RedrawSetupScreenAfterFullscreenToggle()
5870 if (setup_mode == SETUP_MODE_GRAPHICS)
5874 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5876 if (setup_mode == SETUP_MODE_INPUT)
5877 HandleSetupScreen_Input(mx, my, dx, dy, button);
5878 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5879 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5880 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5881 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5882 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5883 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5884 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5885 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5886 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5887 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5889 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5894 void HandleGameActions()
5896 if (game_status != GAME_MODE_PLAYING)
5899 GameActions(); /* main game loop */
5901 if (tape.auto_play && !tape.playing)
5902 AutoPlayTape(); /* continue automatically playing next tape */
5906 /* ---------- new screen button stuff -------------------------------------- */
5908 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5913 case SCREEN_CTRL_ID_PREV_LEVEL:
5914 *x = mSX + menu.main.button.prev_level.x;
5915 *y = mSY + menu.main.button.prev_level.y;
5918 case SCREEN_CTRL_ID_NEXT_LEVEL:
5919 *x = mSX + menu.main.button.next_level.x;
5920 *y = mSY + menu.main.button.next_level.y;
5923 case SCREEN_CTRL_ID_PREV_LEVEL:
5924 *x = mSX + TILEX * getPrevlevelButtonPos();
5925 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5928 case SCREEN_CTRL_ID_NEXT_LEVEL:
5929 *x = mSX + TILEX * getNextLevelButtonPos();
5930 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5934 case SCREEN_CTRL_ID_PREV_PLAYER:
5935 *x = mSX + TILEX * 10;
5936 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5939 case SCREEN_CTRL_ID_NEXT_PLAYER:
5940 *x = mSX + TILEX * 12;
5941 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5945 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5951 int gfx_unpressed, gfx_pressed;
5952 void (*get_gadget_position)(int *, int *, int);
5956 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5959 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5960 getScreenMenuButtonPos,
5961 SCREEN_CTRL_ID_PREV_LEVEL,
5966 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5967 getScreenMenuButtonPos,
5968 SCREEN_CTRL_ID_NEXT_LEVEL,
5973 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5974 getScreenMenuButtonPos,
5975 SCREEN_CTRL_ID_PREV_PLAYER,
5980 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5981 getScreenMenuButtonPos,
5982 SCREEN_CTRL_ID_NEXT_PLAYER,
5990 int gfx_unpressed, gfx_pressed;
5994 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5997 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5998 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5999 SCREEN_CTRL_ID_SCROLL_UP,
6003 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6004 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6005 SCREEN_CTRL_ID_SCROLL_DOWN,
6012 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6013 Bitmap **gfx_unpressed, **gfx_pressed;
6015 int gfx_unpressed, gfx_pressed;
6022 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6025 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6026 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6028 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6030 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6031 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6032 GD_TYPE_SCROLLBAR_VERTICAL,
6033 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6034 "scroll level series vertically"
6038 static void CreateScreenMenubuttons()
6040 struct GadgetInfo *gi;
6041 unsigned long event_mask;
6044 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6046 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6047 int gfx_unpressed, gfx_pressed;
6048 int x, y, width, height;
6049 int gd_x1, gd_x2, gd_y1, gd_y2;
6050 int id = menubutton_info[i].gadget_id;
6052 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6054 menubutton_info[i].get_gadget_position(&x, &y, id);
6056 width = SC_MENUBUTTON_XSIZE;
6057 height = SC_MENUBUTTON_YSIZE;
6059 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6060 gfx_pressed = menubutton_info[i].gfx_pressed;
6061 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6062 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6063 gd_x1 = graphic_info[gfx_unpressed].src_x;
6064 gd_y1 = graphic_info[gfx_unpressed].src_y;
6065 gd_x2 = graphic_info[gfx_pressed].src_x;
6066 gd_y2 = graphic_info[gfx_pressed].src_y;
6068 gi = CreateGadget(GDI_CUSTOM_ID, id,
6069 GDI_CUSTOM_TYPE_ID, i,
6070 GDI_INFO_TEXT, menubutton_info[i].infotext,
6075 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6076 GDI_STATE, GD_BUTTON_UNPRESSED,
6077 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6078 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6079 GDI_DIRECT_DRAW, FALSE,
6080 GDI_EVENT_MASK, event_mask,
6081 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6085 Error(ERR_EXIT, "cannot create gadget");
6087 screen_gadget[id] = gi;
6091 static void CreateScreenScrollbuttons()
6093 struct GadgetInfo *gi;
6094 unsigned long event_mask;
6097 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6099 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6100 int gfx_unpressed, gfx_pressed;
6101 int x, y, width, height;
6102 int gd_x1, gd_x2, gd_y1, gd_y2;
6103 int id = scrollbutton_info[i].gadget_id;
6105 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6107 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6108 y = mSY + scrollbutton_info[i].y;
6109 width = SC_SCROLLBUTTON_XSIZE;
6110 height = SC_SCROLLBUTTON_YSIZE;
6112 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6113 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6114 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6116 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6117 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6118 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6119 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6120 gd_x1 = graphic_info[gfx_unpressed].src_x;
6121 gd_y1 = graphic_info[gfx_unpressed].src_y;
6122 gd_x2 = graphic_info[gfx_pressed].src_x;
6123 gd_y2 = graphic_info[gfx_pressed].src_y;
6125 gi = CreateGadget(GDI_CUSTOM_ID, id,
6126 GDI_CUSTOM_TYPE_ID, i,
6127 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6132 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6133 GDI_STATE, GD_BUTTON_UNPRESSED,
6134 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6135 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6136 GDI_DIRECT_DRAW, FALSE,
6137 GDI_EVENT_MASK, event_mask,
6138 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6142 Error(ERR_EXIT, "cannot create gadget");
6144 screen_gadget[id] = gi;
6148 static void CreateScreenScrollbars()
6152 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6154 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6155 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6156 int gfx_unpressed, gfx_pressed;
6158 int x, y, width, height;
6159 int gd_x1, gd_x2, gd_y1, gd_y2;
6160 struct GadgetInfo *gi;
6161 int items_max, items_visible, item_position;
6162 unsigned long event_mask;
6163 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6164 int id = scrollbar_info[i].gadget_id;
6166 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6168 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6169 y = mSY + scrollbar_info[i].y;
6170 width = scrollbar_info[i].width;
6171 height = scrollbar_info[i].height;
6173 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6174 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6176 items_max = num_page_entries;
6177 items_visible = num_page_entries;
6180 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6181 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6182 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6188 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6189 gfx_pressed = scrollbar_info[i].gfx_pressed;
6190 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6191 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6192 gd_x1 = graphic_info[gfx_unpressed].src_x;
6193 gd_y1 = graphic_info[gfx_unpressed].src_y;
6194 gd_x2 = graphic_info[gfx_pressed].src_x;
6195 gd_y2 = graphic_info[gfx_pressed].src_y;
6198 gi = CreateGadget(GDI_CUSTOM_ID, id,
6199 GDI_CUSTOM_TYPE_ID, i,
6200 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6205 GDI_TYPE, scrollbar_info[i].type,
6206 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6207 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6208 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6210 GDI_WHEEL_AREA_X, SX,
6211 GDI_WHEEL_AREA_Y, SY,
6212 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6213 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6215 GDI_WHEEL_AREA_X, 0,
6216 GDI_WHEEL_AREA_Y, 0,
6217 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6218 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6220 GDI_STATE, GD_BUTTON_UNPRESSED,
6221 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6222 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6223 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6224 GDI_DIRECT_DRAW, FALSE,
6225 GDI_EVENT_MASK, event_mask,
6226 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6230 Error(ERR_EXIT, "cannot create gadget");
6232 screen_gadget[id] = gi;
6236 void CreateScreenGadgets()
6238 int last_game_status = game_status; /* save current game status */
6240 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6243 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6245 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6247 /* copy pointers to clip mask and GC */
6248 scrollbar_bitmap[i]->clip_mask =
6249 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6250 scrollbar_bitmap[i]->stored_clip_gc =
6251 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6253 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6254 scrollbar_bitmap[i],
6255 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6256 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6257 TILEX, TILEY, 0, 0);
6261 CreateScreenMenubuttons();
6263 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6264 game_status = GAME_MODE_LEVELS;
6266 CreateScreenScrollbuttons();
6267 CreateScreenScrollbars();
6269 game_status = last_game_status; /* restore current game status */
6272 void FreeScreenGadgets()
6276 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6277 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6279 /* prevent freeing clip mask and GC twice */
6280 scrollbar_bitmap[i]->clip_mask = None;
6281 scrollbar_bitmap[i]->stored_clip_gc = None;
6283 FreeBitmap(scrollbar_bitmap[i]);
6287 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6288 FreeGadget(screen_gadget[i]);
6291 void MapScreenMenuGadgets(int screen_mask)
6295 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6296 if (screen_mask & menubutton_info[i].screen_mask)
6297 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6300 void MapScreenTreeGadgets(TreeInfo *ti)
6302 int num_entries = numTreeInfoInGroup(ti);
6305 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6308 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6309 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6311 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6312 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6315 static void HandleScreenGadgets(struct GadgetInfo *gi)
6317 int id = gi->custom_id;
6318 int button = gi->event.button;
6319 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6323 case SCREEN_CTRL_ID_PREV_LEVEL:
6324 HandleMainMenu_SelectLevel(step, -1);
6327 case SCREEN_CTRL_ID_NEXT_LEVEL:
6328 HandleMainMenu_SelectLevel(step, +1);
6331 case SCREEN_CTRL_ID_PREV_PLAYER:
6332 HandleSetupScreen_Input_Player(step, -1);
6335 case SCREEN_CTRL_ID_NEXT_PLAYER:
6336 HandleSetupScreen_Input_Player(step, +1);
6339 case SCREEN_CTRL_ID_SCROLL_UP:
6340 if (game_status == GAME_MODE_LEVELS)
6341 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6342 else if (game_status == GAME_MODE_SETUP)
6343 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6346 case SCREEN_CTRL_ID_SCROLL_DOWN:
6347 if (game_status == GAME_MODE_LEVELS)
6348 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6349 else if (game_status == GAME_MODE_SETUP)
6350 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6353 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6354 if (game_status == GAME_MODE_LEVELS)
6355 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6356 else if (game_status == GAME_MODE_SETUP)
6357 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);