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_last = fading;
1564 struct TitleFadingInfo fading_next;
1567 if (button == MB_MENU_INITIALIZE)
1570 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1574 int last_game_status = game_status; /* save current game status */
1578 title_screen_nr = 0;
1579 tci = &title_controls[title_screen_nr];
1581 last_sound = SND_UNDEFINED;
1582 last_music = MUS_UNDEFINED;
1585 /* determine number of title screens to display (images and messages) */
1586 InitializeTitleControls();
1589 if (game_status == GAME_MODE_INFO)
1591 if (num_title_screens == 0)
1593 DrawInfoScreen_NotAvailable("Title screen information:",
1594 "No title screen for this level set.");
1597 /* use default settings for fading, but always disable auto delay */
1598 fading = title_default;
1599 fading.auto_delay = -1;
1605 FadeSoundsAndMusic();
1608 FadeOut(REDRAW_ALL);
1613 DrawTitleScreenImage(tci->local_nr, tci->initial);
1615 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1617 fading = fading_next = getTitleFading(tci);
1619 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1620 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1621 fading.fade_mode = FADE_MODE_FADE;
1624 sound = getTitleSound(tci);
1625 music = getTitleMusic(tci);
1627 if (sound != last_sound)
1628 PlayMenuSoundExt(sound);
1629 if (music != last_music)
1630 PlayMenuMusicExt(music);
1636 SetMouseCursor(CURSOR_NONE);
1642 fading = fading_next;
1644 DelayReached(&title_delay, 0); /* reset delay counter */
1650 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1651 button = MB_MENU_CHOICE;
1653 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1654 button = MB_MENU_CHOICE;
1657 if (button == MB_MENU_LEAVE)
1659 return_to_main_menu = TRUE;
1660 use_fading_main_menu = FALSE;
1662 else if (button == MB_MENU_CHOICE)
1665 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1668 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1671 FadeOut(REDRAW_FIELD);
1676 info_mode = INFO_MODE_MAIN;
1677 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1683 tci = &title_controls[title_screen_nr];
1685 if (title_screen_nr < num_title_screens)
1689 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1696 graphic_info[getTitleScreenGraphic(tci->local_nr,
1697 tci->initial)].anim_mode;
1699 anim_mode = ANIM_FADE; /* ??? */
1701 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1702 anim_mode == ANIM_CROSSFADE ? TRUE :
1706 sound = getTitleSound(tci);
1707 music = getTitleMusic(tci);
1709 if (sound == SND_UNDEFINED || sound != last_sound)
1711 if (music == MUS_UNDEFINED || music != last_music)
1715 FadeOut(REDRAW_ALL);
1719 DrawTitleScreenImage(tci->local_nr, tci->initial);
1721 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1723 fading_next = getTitleFading(tci);
1726 sound = getTitleSound(tci);
1727 music = getTitleMusic(tci);
1729 if (sound != last_sound)
1730 PlayMenuSoundExt(sound);
1731 if (music != last_music)
1732 PlayMenuMusicExt(music);
1739 printf("::: %d -> %d\n", fading.fade_mode, fading_next.fade_mode);
1742 /* last screen already faded out, next screen has no animation */
1743 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1744 fading_next.fade_mode == FADE_MODE_NONE)
1745 fading = fading_next;
1751 fading = fading_next;
1753 DelayReached(&title_delay, 0); /* reset delay counter */
1757 FadeSoundsAndMusic();
1763 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1767 FadeOut(REDRAW_ALL);
1771 FadeOut(REDRAW_ALL);
1775 return_to_main_menu = TRUE;
1779 if (return_to_main_menu)
1785 SetMouseCursor(CURSOR_DEFAULT);
1787 if (game_status == GAME_MODE_INFO)
1790 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1793 info_mode = INFO_MODE_MAIN;
1794 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1796 else /* default: return to main menu */
1799 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1802 game_status = GAME_MODE_MAIN;
1803 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1808 void HandleMainMenu_SelectLevel(int step, int direction)
1810 int old_level_nr = level_nr;
1813 new_level_nr = old_level_nr + step * direction;
1814 if (new_level_nr < leveldir_current->first_level)
1815 new_level_nr = leveldir_current->first_level;
1816 if (new_level_nr > leveldir_current->last_level)
1817 new_level_nr = leveldir_current->last_level;
1819 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1821 /* skipping levels is only allowed when trying to skip single level */
1822 if (setup.skip_levels && step == 1 &&
1823 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1825 leveldir_current->handicap_level++;
1826 SaveLevelSetup_SeriesInfo();
1829 new_level_nr = leveldir_current->handicap_level;
1832 if (new_level_nr != old_level_nr)
1834 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1836 PlaySound(SND_MENU_ITEM_SELECTING);
1838 level_nr = new_level_nr;
1841 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1842 int2str(level_nr, 3), mci->pos_text->font);
1844 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1847 LoadLevel(level_nr);
1848 DrawPreviewLevel(TRUE);
1852 DrawCompleteVideoDisplay();
1854 /* needed because DrawPreviewLevel() takes some time */
1862 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1864 static int choice = MAIN_CONTROL_GAME;
1868 if (button == MB_MENU_INITIALIZE)
1870 DrawCursorAndText_Main(choice, TRUE);
1875 if (mx || my) /* mouse input */
1879 for (i = 0; main_controls[i].nr != -1; i++)
1881 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1882 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1883 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1885 pos = main_controls[i].nr;
1891 else if (dx || dy) /* keyboard input */
1893 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1894 choice == MAIN_CONTROL_SETUP))
1895 button = MB_MENU_CHOICE;
1900 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1902 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1904 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1910 PlaySound(SND_MENU_ITEM_ACTIVATING);
1912 DrawCursorAndText_Main(choice, FALSE);
1913 DrawCursorAndText_Main(pos, TRUE);
1920 PlaySound(SND_MENU_ITEM_SELECTING);
1922 if (pos == MAIN_CONTROL_NAME)
1924 game_status = GAME_MODE_PSEUDO_TYPENAME;
1926 HandleTypeName(strlen(setup.player_name), 0);
1928 else if (pos == MAIN_CONTROL_LEVELS)
1932 game_status = GAME_MODE_LEVELS;
1934 SaveLevelSetup_LastSeries();
1935 SaveLevelSetup_SeriesInfo();
1944 else if (pos == MAIN_CONTROL_SCORES)
1946 game_status = GAME_MODE_SCORES;
1950 else if (pos == MAIN_CONTROL_EDITOR)
1952 if (leveldir_current->readonly &&
1953 !strEqual(setup.player_name, "Artsoft"))
1954 Request("This level is read only !", REQ_CONFIRM);
1956 game_status = GAME_MODE_EDITOR;
1962 else if (pos == MAIN_CONTROL_INFO)
1964 game_status = GAME_MODE_INFO;
1965 info_mode = INFO_MODE_MAIN;
1968 fading = menu.navigation;
1973 else if (pos == MAIN_CONTROL_GAME)
1975 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1977 else if (pos == MAIN_CONTROL_SETUP)
1979 game_status = GAME_MODE_SETUP;
1980 setup_mode = SETUP_MODE_MAIN;
1984 else if (pos == MAIN_CONTROL_QUIT)
1986 SaveLevelSetup_LastSeries();
1987 SaveLevelSetup_SeriesInfo();
1989 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1990 game_status = GAME_MODE_QUIT;
1995 if (game_status == GAME_MODE_MAIN)
1997 DrawPreviewLevel(FALSE);
2004 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2006 static int choice = 5;
2010 if (button == MB_MENU_INITIALIZE)
2012 drawCursor(choice, TRUE);
2017 if (mx || my) /* mouse input */
2019 x = (mx - mSX) / 32;
2020 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2022 else if (dx || dy) /* keyboard input */
2024 if (dx && choice == 1)
2025 x = (dx < 0 ? 10 : 14);
2028 if (choice == 4 || choice == 6)
2029 button = MB_MENU_CHOICE;
2035 if (y == 1 && dx != 0 && button)
2037 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
2039 else if (IN_VIS_FIELD(x, y) &&
2040 y >= 0 && y <= 7 && (y != 1 || x < 10))
2046 drawCursor(choice, FALSE);
2047 drawCursor(y, TRUE);
2056 game_status = GAME_MODE_PSEUDO_TYPENAME;
2057 HandleTypeName(strlen(setup.player_name), 0);
2063 game_status = GAME_MODE_LEVELS;
2064 SaveLevelSetup_LastSeries();
2065 SaveLevelSetup_SeriesInfo();
2076 game_status = GAME_MODE_SCORES;
2081 if (leveldir_current->readonly &&
2082 !strEqual(setup.player_name, "Artsoft"))
2083 Request("This level is read only !", REQ_CONFIRM);
2084 game_status = GAME_MODE_EDITOR;
2089 game_status = GAME_MODE_INFO;
2090 info_mode = INFO_MODE_MAIN;
2095 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2099 game_status = GAME_MODE_SETUP;
2100 setup_mode = SETUP_MODE_MAIN;
2106 SaveLevelSetup_LastSeries();
2107 SaveLevelSetup_SeriesInfo();
2109 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2110 game_status = GAME_MODE_QUIT;
2115 if (game_status == GAME_MODE_MAIN)
2117 DrawPreviewLevel(FALSE);
2125 /* ========================================================================= */
2126 /* info screen functions */
2127 /* ========================================================================= */
2129 static struct TokenInfo *info_info;
2130 static int num_info_info;
2132 static void execInfoTitleScreen()
2138 info_mode = INFO_MODE_TITLE;
2142 static void execInfoElements()
2148 info_mode = INFO_MODE_ELEMENTS;
2152 static void execInfoMusic()
2158 info_mode = INFO_MODE_MUSIC;
2162 static void execInfoCredits()
2168 info_mode = INFO_MODE_CREDITS;
2172 static void execInfoProgram()
2178 info_mode = INFO_MODE_PROGRAM;
2182 static void execInfoVersion()
2188 info_mode = INFO_MODE_VERSION;
2192 static void execInfoLevelSet()
2198 info_mode = INFO_MODE_LEVELSET;
2202 static void execExitInfo()
2208 game_status = GAME_MODE_MAIN;
2210 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2216 static struct TokenInfo info_info_main[] =
2218 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2219 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2220 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2221 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2222 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2223 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2224 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2225 { TYPE_EMPTY, NULL, "" },
2226 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2231 static void DrawCursorAndText_Info(int pos, boolean active)
2233 int xpos = MENU_SCREEN_START_XPOS;
2234 int ypos = MENU_SCREEN_START_YPOS + pos;
2235 int font_nr = FONT_MENU_1;
2238 font_nr = FONT_ACTIVE(font_nr);
2240 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2242 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2243 drawCursor(pos, active);
2246 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2251 CloseDoor(DOOR_CLOSE_2);
2254 FadeOut(redraw_mask);
2258 if (redraw_mask == REDRAW_ALL)
2261 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2267 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2269 info_info = info_info_main;
2272 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2275 int xpos = MENU_SCREEN_START_XPOS;
2276 int ypos = MENU_SCREEN_START_YPOS + i;
2277 int font_nr = FONT_MENU_1;
2280 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2281 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2282 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2283 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2284 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2285 initCursor(i, IMG_MENU_BUTTON);
2288 DrawCursorAndText_Info(i, FALSE);
2290 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2296 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2301 DrawMaskedBorder(redraw_mask);
2304 FadeIn(redraw_mask);
2309 else if (fading.anim_mode == ANIM_CROSSFADE)
2310 FadeCross(redraw_mask);
2312 FadeIn(redraw_mask);
2315 FadeIn(redraw_mask);
2324 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2326 static int choice_store[MAX_INFO_MODES];
2327 int choice = choice_store[info_mode]; /* always starts with 0 */
2331 if (button == MB_MENU_INITIALIZE)
2333 /* advance to first valid menu entry */
2334 while (choice < num_info_info &&
2335 info_info[choice].type & TYPE_SKIP_ENTRY)
2337 choice_store[info_mode] = choice;
2340 DrawCursorAndText_Info(choice, TRUE);
2342 drawCursor(choice, TRUE);
2347 else if (button == MB_MENU_LEAVE)
2349 for (y = 0; y < num_info_info; y++)
2351 if (info_info[y].type & TYPE_LEAVE_MENU)
2353 void (*menu_callback_function)(void) = info_info[y].value;
2357 menu_callback_function();
2359 break; /* absolutely needed because function changes 'info_info'! */
2366 if (mx || my) /* mouse input */
2368 x = (mx - mSX) / 32;
2369 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2371 else if (dx || dy) /* keyboard input */
2375 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2377 if (info_info[choice].type & menu_navigation_type ||
2378 info_info[choice].type & TYPE_ENTER_SCREEN ||
2379 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2380 button = MB_MENU_CHOICE;
2385 /* jump to next non-empty menu entry (up or down) */
2386 while (y > 0 && y < num_info_info - 1 &&
2387 info_info[y].type & TYPE_SKIP_ENTRY)
2391 if (IN_VIS_FIELD(x, y) &&
2392 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2398 PlaySound(SND_MENU_ITEM_ACTIVATING);
2401 DrawCursorAndText_Info(choice, FALSE);
2402 DrawCursorAndText_Info(y, TRUE);
2404 drawCursor(choice, FALSE);
2405 drawCursor(y, TRUE);
2408 choice = choice_store[info_mode] = y;
2411 else if (!(info_info[y].type & TYPE_GHOSTED))
2413 PlaySound(SND_MENU_ITEM_SELECTING);
2415 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2417 void (*menu_callback_function)(void) = info_info[choice].value;
2419 FadeSetFromType(info_info[y].type);
2421 menu_callback_function();
2427 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2430 int ystart1 = mSY - SY + 100;
2431 int ystart2 = mSY - SY + 150;
2432 int ybottom = mSY - SY + SYSIZE - 20;
2436 int ybottom = SYSIZE - 20;
2439 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2442 FadeOut(REDRAW_FIELD);
2448 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2449 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2451 DrawTextSCentered(ybottom, FONT_TEXT_4,
2452 "Press any key or button for info menu");
2455 FadeIn(REDRAW_FIELD);
2459 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2461 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2462 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2463 int xstart = mSX + 16;
2464 int ystart1 = mSY - SY + 100;
2465 int ystart2 = mSY + 64 + 2 * 32;
2466 int ybottom = mSY - SY + SYSIZE - 20;
2467 int ystep = TILEY + 4;
2468 int element, action, direction;
2476 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2477 infoscreen_step[i] = infoscreen_frame[i] = 0;
2482 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2484 DrawTextSCentered(ybottom, FONT_TEXT_4,
2485 "Press any key or button for next page");
2491 while (helpanim_info[j].element != HELPANIM_LIST_END)
2493 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2498 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2507 j += infoscreen_step[i - start];
2509 element = helpanim_info[j].element;
2510 action = helpanim_info[j].action;
2511 direction = helpanim_info[j].direction;
2514 element = EL_UNKNOWN;
2516 if (action != -1 && direction != -1)
2517 graphic = el_act_dir2img(element, action, direction);
2518 else if (action != -1)
2519 graphic = el_act2img(element, action);
2520 else if (direction != -1)
2521 graphic = el_dir2img(element, direction);
2523 graphic = el2img(element);
2525 delay = helpanim_info[j++].delay;
2530 if (infoscreen_frame[i - start] == 0)
2533 infoscreen_frame[i - start] = delay - 1;
2537 sync_frame = delay - infoscreen_frame[i - start];
2538 infoscreen_frame[i - start]--;
2541 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2543 if (!infoscreen_frame[i - start])
2544 infoscreen_step[i - start] = 0;
2548 if (!infoscreen_frame[i - start])
2549 infoscreen_step[i - start]++;
2550 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2556 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2558 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2559 graphic, sync_frame, USE_MASKING);
2562 DrawInfoScreen_HelpText(element, action, direction, i - start);
2567 redraw_mask |= REDRAW_FIELD;
2572 static char *getHelpText(int element, int action, int direction)
2574 char token[MAX_LINE_LEN];
2576 strcpy(token, element_info[element].token_name);
2579 strcat(token, element_action_info[action].suffix);
2581 if (direction != -1)
2582 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2584 return getHashEntry(helptext_info, token);
2587 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2590 int font_nr = FONT_INFO_ELEMENTS;
2592 int font_nr = FONT_LEVEL_NUMBER;
2594 int font_width = getFontWidth(font_nr);
2595 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2596 int sy = mSY + 65 + 2 * 32 + 1;
2597 int ystep = TILEY + 4;
2598 int pad_x = sx - SX;
2599 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2600 int max_lines_per_text = 2;
2603 if (action != -1 && direction != -1) /* element.action.direction */
2604 text = getHelpText(element, action, direction);
2606 if (text == NULL && action != -1) /* element.action */
2607 text = getHelpText(element, action, -1);
2609 if (text == NULL && direction != -1) /* element.direction */
2610 text = getHelpText(element, -1, direction);
2612 if (text == NULL) /* base element */
2613 text = getHelpText(element, -1, -1);
2615 if (text == NULL) /* not found */
2616 text = "No description available";
2618 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2619 sy += getFontHeight(font_nr) / 2;
2622 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2623 max_chars_per_line, -1, max_lines_per_text, -1,
2624 TRUE, FALSE, FALSE);
2626 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2627 max_chars_per_line, max_lines_per_text);
2631 void DrawInfoScreen_TitleScreen()
2636 void HandleInfoScreen_TitleScreen(int button)
2638 HandleTitleScreen(0, 0, 0, 0, button);
2641 void DrawInfoScreen_Elements()
2643 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2646 FadeOut(REDRAW_FIELD);
2652 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2655 FadeIn(REDRAW_FIELD);
2661 void HandleInfoScreen_Elements(int button)
2663 static unsigned long info_delay = 0;
2664 static int num_anims;
2665 static int num_pages;
2667 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2670 if (button == MB_MENU_INITIALIZE)
2672 boolean new_element = TRUE;
2676 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2678 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2680 else if (new_element)
2683 new_element = FALSE;
2687 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2691 if (button == MB_MENU_LEAVE)
2693 PlaySound(SND_MENU_ITEM_SELECTING);
2695 info_mode = INFO_MODE_MAIN;
2700 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2702 if (button != MB_MENU_INITIALIZE)
2704 PlaySound(SND_MENU_ITEM_SELECTING);
2709 if (page >= num_pages)
2711 FadeSoundsAndMusic();
2714 FadeOut(REDRAW_FIELD);
2717 info_mode = INFO_MODE_MAIN;
2718 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2723 if (button != MB_MENU_INITIALIZE)
2724 FadeCrossSaveBackbuffer();
2726 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2728 if (button != MB_MENU_INITIALIZE)
2729 FadeCross(REDRAW_FIELD);
2733 if (DelayReached(&info_delay, GameFrameDelay))
2734 if (page < num_pages)
2735 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2737 PlayMenuSoundIfLoop();
2741 void DrawInfoScreen_Music()
2743 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2746 FadeOut(REDRAW_FIELD);
2754 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2757 FadeIn(REDRAW_FIELD);
2761 void HandleInfoScreen_Music(int button)
2763 static struct MusicFileInfo *list = NULL;
2764 int ystart1 = mSY - SY + 100;
2765 int ystart2 = mSY - SY + 150;
2766 int ybottom = mSY - SY + SYSIZE - 20;
2769 if (button == MB_MENU_INITIALIZE)
2771 list = music_file_info;
2775 FadeSoundsAndMusic();
2780 DrawTextSCentered(ystart1, FONT_TEXT_1,
2781 "No music info for this level set.");
2783 DrawTextSCentered(ybottom, FONT_TEXT_4,
2784 "Press any key or button for info menu");
2790 if (button == MB_MENU_LEAVE)
2792 PlaySound(SND_MENU_ITEM_SELECTING);
2794 FadeSoundsAndMusic();
2796 info_mode = INFO_MODE_MAIN;
2801 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2805 if (button != MB_MENU_INITIALIZE)
2807 PlaySound(SND_MENU_ITEM_SELECTING);
2815 FadeSoundsAndMusic();
2818 FadeOut(REDRAW_FIELD);
2821 info_mode = INFO_MODE_MAIN;
2822 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2827 FadeSoundsAndMusic();
2829 if (button != MB_MENU_INITIALIZE)
2830 FadeCrossSaveBackbuffer();
2837 int sound = list->music;
2839 if (sound_info[sound].loop)
2840 PlaySoundLoop(sound);
2844 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2848 PlayMusic(list->music);
2850 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2853 if (!strEqual(list->title, UNKNOWN_NAME))
2855 if (!strEqual(list->title_header, UNKNOWN_NAME))
2856 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2858 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2861 if (!strEqual(list->artist, UNKNOWN_NAME))
2863 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2864 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2866 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2868 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2871 if (!strEqual(list->album, UNKNOWN_NAME))
2873 if (!strEqual(list->album_header, UNKNOWN_NAME))
2874 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2876 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2878 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2881 if (!strEqual(list->year, UNKNOWN_NAME))
2883 if (!strEqual(list->year_header, UNKNOWN_NAME))
2884 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2886 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2888 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2891 DrawTextSCentered(ybottom, FONT_TEXT_4,
2892 "Press any key or button for next page");
2894 if (button != MB_MENU_INITIALIZE)
2895 FadeCross(REDRAW_FIELD);
2898 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2899 PlaySoundLoop(list->music);
2902 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2904 int ystart1 = mSY - SY + 100;
2905 int ystart2 = mSY - SY + 150;
2906 int ybottom = mSY - SY + SYSIZE - 20;
2915 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2919 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2920 "Special thanks to");
2921 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2923 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2925 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2926 "\"Boulder Dash\"");
2927 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2929 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2931 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2933 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2934 "First Star Software");
2936 else if (screen_nr == 1)
2938 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2939 "Special thanks to");
2940 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2941 "Klaus Heinz & Volker Wertich");
2942 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2944 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2945 "\"Emerald Mine\"");
2946 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2948 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2950 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2952 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2955 else if (screen_nr == 2)
2957 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2958 "Special thanks to");
2959 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2960 "Michael Stopp & Philip Jespersen");
2961 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2963 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2965 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2967 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2969 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2971 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2972 "Digital Integration");
2974 else if (screen_nr == 3)
2976 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2977 "Special thanks to");
2978 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2979 "Hiroyuki Imabayashi");
2980 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2982 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2984 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2986 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2988 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2990 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2993 else if (screen_nr == 4)
2995 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2996 "Special thanks to");
2997 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2999 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3001 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3002 "Jürgen Bonhagen");
3003 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3004 "for the continuous creation");
3005 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3006 "of outstanding level sets");
3008 else if (screen_nr == 5)
3010 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3012 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3015 "for ideas and inspiration by");
3016 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3019 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3021 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3023 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3024 "for ideas and inspiration by");
3025 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3028 else if (screen_nr == 6)
3030 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3032 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3034 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3035 "for the new Emerald Mine engine");
3037 else if (screen_nr == 7)
3039 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3041 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3043 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3044 "for the initial DOS port");
3046 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3048 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3050 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3051 "for some additional toons");
3053 else if (screen_nr == 8)
3055 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3056 "And not to forget:");
3057 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3059 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3060 "All those who contributed");
3061 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3062 "levels to this game");
3063 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3073 DrawTextSCentered(ybottom, FONT_TEXT_4,
3074 "Press any key or button for next page");
3079 void DrawInfoScreen_Credits()
3081 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3083 FadeSoundsAndMusic();
3086 FadeOut(REDRAW_FIELD);
3089 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3092 FadeIn(REDRAW_FIELD);
3096 void HandleInfoScreen_Credits(int button)
3098 static int screen_nr = 0;
3100 if (button == MB_MENU_INITIALIZE)
3104 DrawInfoScreen_CreditsScreen(screen_nr);
3106 else if (button == MB_MENU_LEAVE)
3108 PlaySound(SND_MENU_ITEM_SELECTING);
3110 info_mode = INFO_MODE_MAIN;
3115 else if (button == MB_MENU_CHOICE)
3117 boolean show_screen;
3119 PlaySound(SND_MENU_ITEM_SELECTING);
3123 FadeCrossSaveBackbuffer();
3125 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
3129 FadeCross(REDRAW_FIELD);
3133 FadeSoundsAndMusic();
3136 FadeOut(REDRAW_FIELD);
3139 info_mode = INFO_MODE_MAIN;
3140 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3145 PlayMenuSoundIfLoop();
3149 void DrawInfoScreen_Program()
3151 int ystart1 = mSY - SY + 100;
3152 int ystart2 = mSY - SY + 150;
3153 int ybottom = mSY - SY + SYSIZE - 20;
3156 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3159 FadeOut(REDRAW_FIELD);
3165 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3167 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3168 "This game is Freeware!");
3169 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3170 "If you like it, send e-mail to:");
3171 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3172 PROGRAM_EMAIL_STRING);
3173 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3174 "or SnailMail to:");
3175 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3177 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3178 "Detmolder Strasse 189");
3179 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3181 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3183 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3184 "More information and levels:");
3185 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3186 PROGRAM_WEBSITE_STRING);
3187 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3188 "If you have created new levels,");
3189 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3190 "send them to me to include them!");
3191 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3194 DrawTextSCentered(ybottom, FONT_TEXT_4,
3195 "Press any key or button for info menu");
3198 FadeIn(REDRAW_FIELD);
3202 void HandleInfoScreen_Program(int button)
3204 if (button == MB_MENU_LEAVE)
3206 PlaySound(SND_MENU_ITEM_SELECTING);
3208 info_mode = INFO_MODE_MAIN;
3213 else if (button == MB_MENU_CHOICE)
3215 PlaySound(SND_MENU_ITEM_SELECTING);
3217 FadeSoundsAndMusic();
3220 FadeOut(REDRAW_FIELD);
3223 info_mode = INFO_MODE_MAIN;
3224 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3228 PlayMenuSoundIfLoop();
3232 void DrawInfoScreen_Version()
3234 int font_header = FONT_TEXT_3;
3235 int font_text = FONT_TEXT_2;
3236 int xstep = getFontWidth(font_text);
3237 int ystep = getFontHeight(font_text);
3238 int ystart1 = mSY - SY + 100;
3239 int ystart2 = mSY - SY + 150;
3240 int ybottom = mSY - SY + SYSIZE - 20;
3241 int xstart1 = mSX + 2 * xstep;
3242 int xstart2 = mSX + 19 * xstep;
3243 #if defined(TARGET_SDL)
3244 int xstart3 = mSX + 29 * xstep;
3245 SDL_version sdl_version_compiled;
3246 const SDL_version *sdl_version_linked;
3247 int driver_name_len = 8;
3248 char driver_name[driver_name_len];
3251 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3254 FadeOut(REDRAW_FIELD);
3260 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3262 DrawTextF(xstart1, ystart2, font_header, "Name");
3263 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3266 DrawTextF(xstart1, ystart2, font_header, "Version");
3267 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3270 DrawTextF(xstart1, ystart2, font_header, "Platform");
3271 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3274 DrawTextF(xstart1, ystart2, font_header, "Target");
3275 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3278 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3279 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3281 #if defined(TARGET_SDL)
3282 ystart2 += 3 * ystep;
3283 DrawTextF(xstart1, ystart2, font_header, "Library");
3284 DrawTextF(xstart2, ystart2, font_header, "compiled");
3285 DrawTextF(xstart3, ystart2, font_header, "linked");
3287 SDL_VERSION(&sdl_version_compiled);
3288 sdl_version_linked = SDL_Linked_Version();
3290 ystart2 += 2 * ystep;
3291 DrawTextF(xstart1, ystart2, font_text, "SDL");
3292 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3293 sdl_version_compiled.major,
3294 sdl_version_compiled.minor,
3295 sdl_version_compiled.patch);
3296 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3297 sdl_version_linked->major,
3298 sdl_version_linked->minor,
3299 sdl_version_linked->patch);
3301 SDL_IMAGE_VERSION(&sdl_version_compiled);
3302 sdl_version_linked = IMG_Linked_Version();
3305 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3306 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3307 sdl_version_compiled.major,
3308 sdl_version_compiled.minor,
3309 sdl_version_compiled.patch);
3310 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3311 sdl_version_linked->major,
3312 sdl_version_linked->minor,
3313 sdl_version_linked->patch);
3315 SDL_MIXER_VERSION(&sdl_version_compiled);
3316 sdl_version_linked = Mix_Linked_Version();
3319 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3320 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3321 sdl_version_compiled.major,
3322 sdl_version_compiled.minor,
3323 sdl_version_compiled.patch);
3324 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3325 sdl_version_linked->major,
3326 sdl_version_linked->minor,
3327 sdl_version_linked->patch);
3329 SDL_NET_VERSION(&sdl_version_compiled);
3330 sdl_version_linked = SDLNet_Linked_Version();
3333 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3334 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3335 sdl_version_compiled.major,
3336 sdl_version_compiled.minor,
3337 sdl_version_compiled.patch);
3338 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3339 sdl_version_linked->major,
3340 sdl_version_linked->minor,
3341 sdl_version_linked->patch);
3343 ystart2 += 3 * ystep;
3344 DrawTextF(xstart1, ystart2, font_header, "Driver");
3345 DrawTextF(xstart2, ystart2, font_header, "Requested");
3346 DrawTextF(xstart3, ystart2, font_header, "Used");
3348 SDL_VideoDriverName(driver_name, driver_name_len);
3350 ystart2 += 2 * ystep;
3351 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3352 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3353 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3355 SDL_AudioDriverName(driver_name, driver_name_len);
3358 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3359 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3360 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3363 DrawTextSCentered(ybottom, FONT_TEXT_4,
3364 "Press any key or button for info menu");
3367 FadeIn(REDRAW_FIELD);
3371 void HandleInfoScreen_Version(int button)
3373 if (button == MB_MENU_LEAVE)
3375 PlaySound(SND_MENU_ITEM_SELECTING);
3377 info_mode = INFO_MODE_MAIN;
3382 else if (button == MB_MENU_CHOICE)
3384 PlaySound(SND_MENU_ITEM_SELECTING);
3386 FadeSoundsAndMusic();
3389 FadeOut(REDRAW_FIELD);
3392 info_mode = INFO_MODE_MAIN;
3393 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3397 PlayMenuSoundIfLoop();
3401 void DrawInfoScreen_LevelSet()
3403 struct TitleMessageInfo *tmi = &readme;
3404 char *filename = getLevelSetInfoFilename();
3406 /* if chars set to "-1", automatically determine by text and font width */
3407 if (tmi->chars == -1)
3408 tmi->chars = tmi->width / getFontWidth(tmi->font);
3410 tmi->width = tmi->chars * getFontWidth(tmi->font);
3412 /* if lines set to "-1", automatically determine by text and font height */
3413 if (tmi->lines == -1)
3414 tmi->lines = tmi->height / getFontHeight(tmi->font);
3416 tmi->height = tmi->lines * getFontHeight(tmi->font);
3418 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3421 FadeOut(REDRAW_FIELD);
3427 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3429 if (filename != NULL)
3430 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3431 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3432 tmi->autowrap, tmi->centered, tmi->parse_comments);
3434 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3435 "No information for this level set.");
3437 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3438 "Press any key or button for info menu");
3441 FadeIn(REDRAW_FIELD);
3445 void HandleInfoScreen_LevelSet(int button)
3447 if (button == MB_MENU_LEAVE)
3449 PlaySound(SND_MENU_ITEM_SELECTING);
3451 info_mode = INFO_MODE_MAIN;
3456 else if (button == MB_MENU_CHOICE)
3458 PlaySound(SND_MENU_ITEM_SELECTING);
3460 FadeSoundsAndMusic();
3463 FadeOut(REDRAW_FIELD);
3466 info_mode = INFO_MODE_MAIN;
3467 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3471 PlayMenuSoundIfLoop();
3475 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3477 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3479 if (info_mode == INFO_MODE_TITLE)
3480 DrawInfoScreen_TitleScreen();
3481 else if (info_mode == INFO_MODE_ELEMENTS)
3482 DrawInfoScreen_Elements();
3483 else if (info_mode == INFO_MODE_MUSIC)
3484 DrawInfoScreen_Music();
3485 else if (info_mode == INFO_MODE_CREDITS)
3486 DrawInfoScreen_Credits();
3487 else if (info_mode == INFO_MODE_PROGRAM)
3488 DrawInfoScreen_Program();
3489 else if (info_mode == INFO_MODE_VERSION)
3490 DrawInfoScreen_Version();
3491 else if (info_mode == INFO_MODE_LEVELSET)
3492 DrawInfoScreen_LevelSet();
3494 DrawInfoScreen_Main(redraw_mask, do_fading);
3496 if (info_mode != INFO_MODE_MAIN &&
3497 info_mode != INFO_MODE_TITLE &&
3498 info_mode != INFO_MODE_MUSIC)
3505 void DrawAndFadeInInfoScreen(int redraw_mask)
3507 DrawInfoScreenExt(redraw_mask, TRUE);
3510 void DrawInfoScreen()
3512 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3515 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3517 if (info_mode == INFO_MODE_TITLE)
3518 HandleInfoScreen_TitleScreen(button);
3519 else if (info_mode == INFO_MODE_ELEMENTS)
3520 HandleInfoScreen_Elements(button);
3521 else if (info_mode == INFO_MODE_MUSIC)
3522 HandleInfoScreen_Music(button);
3523 else if (info_mode == INFO_MODE_CREDITS)
3524 HandleInfoScreen_Credits(button);
3525 else if (info_mode == INFO_MODE_PROGRAM)
3526 HandleInfoScreen_Program(button);
3527 else if (info_mode == INFO_MODE_VERSION)
3528 HandleInfoScreen_Version(button);
3529 else if (info_mode == INFO_MODE_LEVELSET)
3530 HandleInfoScreen_LevelSet(button);
3532 HandleInfoScreen_Main(mx, my, dx, dy, button);
3538 /* ========================================================================= */
3539 /* type name functions */
3540 /* ========================================================================= */
3542 void HandleTypeName(int newxpos, Key key)
3544 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3545 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3547 struct TextPosInfo *pos = mci->pos_input;
3548 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3549 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3552 static int xpos = 0;
3554 static int xpos = 0, ypos = 2;
3556 int font_nr = pos->font;
3557 int font_active_nr = FONT_ACTIVE(font_nr);
3558 int font_width = getFontWidth(font_active_nr);
3561 int startx = mSX + mci->pos_input->x;
3562 int starty = mSY + mci->pos_input->y;
3565 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3566 int startx = mSX + 32 + name_width;
3567 int starty = mSY + ypos * 32;
3569 char key_char = getValidConfigValueChar(getCharFromKey(key));
3570 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3571 boolean is_active = TRUE;
3573 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3577 strcpy(last_player_name, setup.player_name);
3582 /* add one character width for added cursor character */
3583 pos->width += font_width;
3584 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3586 DrawText(startx, starty, setup.player_name, font_active_nr);
3587 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3590 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3592 setup.player_name[xpos] = key_char;
3593 setup.player_name[xpos + 1] = 0;
3598 /* add one character width for added name text character */
3599 pos->width += font_width;
3600 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3602 DrawText(startx, starty, setup.player_name, font_active_nr);
3603 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3606 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3610 setup.player_name[xpos] = 0;
3613 /* remove one character width for removed name text character */
3614 pos->width -= font_width;
3615 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3617 DrawText(startx, starty, setup.player_name, font_active_nr);
3618 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3621 else if (key == KSYM_Return && xpos > 0)
3624 /* remove one character width for removed cursor text character */
3625 pos->width -= font_width;
3626 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3628 DrawText(startx, starty, setup.player_name, font_nr);
3629 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3636 game_status = GAME_MODE_MAIN;
3638 else if (key == KSYM_Escape)
3640 strcpy(setup.player_name, last_player_name);
3644 game_status = GAME_MODE_MAIN;
3649 pos->width = (strlen(setup.player_name) + 1) * font_width;
3650 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3652 DrawText(startx, starty, setup.player_name, font_active_nr);
3653 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3657 pos->width = strlen(setup.player_name) * font_width;
3658 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3660 DrawText(startx, starty, setup.player_name, font_nr);
3665 /* ========================================================================= */
3666 /* tree menu functions */
3667 /* ========================================================================= */
3669 static void DrawChooseTree(TreeInfo **ti_ptr)
3673 FreeScreenGadgets();
3674 CreateScreenGadgets();
3676 CloseDoor(DOOR_CLOSE_2);
3679 FadeOut(REDRAW_FIELD);
3684 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3685 MapScreenTreeGadgets(*ti_ptr);
3688 FadeIn(REDRAW_FIELD);
3694 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3696 struct GadgetInfo *gi = screen_gadget[id];
3697 int items_max, items_visible, item_position;
3699 items_max = numTreeInfoInGroup(ti);
3700 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3701 item_position = first_entry;
3703 if (item_position > items_max - items_visible)
3704 item_position = items_max - items_visible;
3706 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3707 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3708 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3711 static void drawChooseTreeList(int first_entry, int num_page_entries,
3715 char *title_string = NULL;
3716 int yoffset_sets = MENU_TITLE1_YPOS;
3717 int yoffset_setup = 16;
3718 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3720 int last_game_status = game_status; /* save current game status */
3722 title_string = ti->infotext;
3724 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3726 /* force LEVELS font on artwork setup screen */
3727 game_status = GAME_MODE_LEVELS;
3730 /* clear tree list area, but not title or scrollbar */
3731 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3732 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3733 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3735 /* clear tree list area, but not title or scrollbar */
3736 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3737 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3738 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3741 for (i = 0; i < num_page_entries; i++)
3743 TreeInfo *node, *node_first;
3744 int entry_pos = first_entry + i;
3745 int xpos = MENU_SCREEN_START_XPOS;
3746 int ypos = MENU_SCREEN_START_YPOS + i;
3747 int startx = mSX + xpos * 32;
3748 int starty = mSY + ypos * 32;
3749 int font_nr = FONT_TEXT_1;
3750 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3751 int startx_text = startx + font_xoffset;
3752 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3753 int text_size = startx_scrollbar - startx_text;
3754 int max_buffer_len = text_size / getFontWidth(font_nr);
3755 char buffer[max_buffer_len + 1];
3757 node_first = getTreeInfoFirstGroupEntry(ti);
3758 node = getTreeInfoFromPos(node_first, entry_pos);
3760 strncpy(buffer, node->name, max_buffer_len);
3761 buffer[max_buffer_len] = '\0';
3763 DrawText(startx, starty, buffer, font_nr + node->color);
3765 if (node->parent_link)
3766 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3767 else if (node->level_group)
3768 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3770 initCursor(i, IMG_MENU_BUTTON);
3773 game_status = last_game_status; /* restore current game status */
3775 redraw_mask |= REDRAW_FIELD;
3778 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3780 TreeInfo *node, *node_first;
3781 int x, last_redraw_mask = redraw_mask;
3782 int ypos = MENU_TITLE2_YPOS;
3783 int font_nr = FONT_TITLE_2;
3785 if (ti->type != TREE_TYPE_LEVEL_DIR)
3788 node_first = getTreeInfoFirstGroupEntry(ti);
3789 node = getTreeInfoFromPos(node_first, entry_pos);
3791 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3793 if (node->parent_link)
3794 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3796 else if (node->level_group)
3797 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3799 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3800 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3801 node->levels, node->class_desc);
3803 /* let BackToFront() redraw only what is needed */
3804 redraw_mask = last_redraw_mask | REDRAW_TILES;
3805 for (x = 0; x < SCR_FIELDX; x++)
3806 MarkTileDirty(x, 1);
3809 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3812 TreeInfo *ti = *ti_ptr;
3814 int y = ti->cl_cursor;
3815 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3816 int num_entries = numTreeInfoInGroup(ti);
3817 int num_page_entries;
3818 int last_game_status = game_status; /* save current game status */
3819 boolean position_set_by_scrollbar = (dx == 999);
3821 /* force LEVELS draw offset on choose level and artwork setup screen */
3822 game_status = GAME_MODE_LEVELS;
3824 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3825 num_page_entries = num_entries;
3827 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3829 game_status = last_game_status; /* restore current game status */
3831 if (button == MB_MENU_INITIALIZE)
3833 int num_entries = numTreeInfoInGroup(ti);
3834 int entry_pos = posTreeInfo(ti);
3836 if (ti->cl_first == -1)
3838 /* only on initialization */
3839 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3840 ti->cl_cursor = entry_pos - ti->cl_first;
3842 else if (ti->cl_cursor >= num_page_entries ||
3843 (num_entries > num_page_entries &&
3844 num_entries - ti->cl_first < num_page_entries))
3846 /* only after change of list size (by custom graphic configuration) */
3847 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3848 ti->cl_cursor = entry_pos - ti->cl_first;
3851 if (position_set_by_scrollbar)
3854 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3857 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3858 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3859 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3863 else if (button == MB_MENU_LEAVE)
3867 PlaySound(SND_MENU_ITEM_SELECTING);
3869 if (ti->node_parent)
3871 *ti_ptr = ti->node_parent;
3872 DrawChooseTree(ti_ptr);
3874 else if (game_status == GAME_MODE_SETUP)
3876 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3878 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3879 execSetupGraphics();
3885 game_status = GAME_MODE_MAIN;
3887 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3896 if (mx || my) /* mouse input */
3898 int last_game_status = game_status; /* save current game status */
3900 /* force LEVELS draw offset on artwork setup screen */
3901 game_status = GAME_MODE_LEVELS;
3903 x = (mx - mSX) / 32;
3904 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3906 game_status = last_game_status; /* restore current game status */
3908 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3910 /* move cursor instead of scrolling when already at start/end of list */
3911 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3913 else if (dy == +1 * SCROLL_LINE &&
3914 ti->cl_first + num_page_entries == num_entries)
3917 /* handle scrolling screen one line or page */
3918 if (ti->cl_cursor + dy < 0 ||
3919 ti->cl_cursor + dy > num_page_entries - 1)
3921 if (ABS(dy) == SCROLL_PAGE)
3922 step = num_page_entries - 1;
3924 if (dy < 0 && ti->cl_first > 0)
3926 /* scroll page/line up */
3928 ti->cl_first -= step;
3929 if (ti->cl_first < 0)
3932 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3933 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3934 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3936 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3939 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3941 /* scroll page/line down */
3943 ti->cl_first += step;
3944 if (ti->cl_first + num_page_entries > num_entries)
3945 ti->cl_first = MAX(0, num_entries - num_page_entries);
3947 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3948 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3949 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3951 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3958 /* handle moving cursor one line */
3959 y = ti->cl_cursor + dy;
3964 TreeInfo *node_first, *node_cursor;
3965 int entry_pos = ti->cl_first + y;
3967 node_first = getTreeInfoFirstGroupEntry(ti);
3968 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3970 if (node_cursor->node_group)
3974 PlaySound(SND_MENU_ITEM_SELECTING);
3976 node_cursor->cl_first = ti->cl_first;
3977 node_cursor->cl_cursor = ti->cl_cursor;
3978 *ti_ptr = node_cursor->node_group;
3979 DrawChooseTree(ti_ptr);
3984 else if (dx == -1 && ti->node_parent)
3988 PlaySound(SND_MENU_ITEM_SELECTING);
3990 *ti_ptr = ti->node_parent;
3991 DrawChooseTree(ti_ptr);
3996 if (!anyScrollbarGadgetActive() &&
3997 IN_VIS_FIELD(x, y) &&
3998 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3999 y >= 0 && y < num_page_entries)
4003 if (y != ti->cl_cursor)
4005 PlaySound(SND_MENU_ITEM_ACTIVATING);
4007 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4008 drawChooseTreeCursor(y, TRUE);
4009 drawChooseTreeInfo(ti->cl_first + y, ti);
4016 TreeInfo *node_first, *node_cursor;
4017 int entry_pos = ti->cl_first + y;
4019 PlaySound(SND_MENU_ITEM_SELECTING);
4021 node_first = getTreeInfoFirstGroupEntry(ti);
4022 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4024 if (node_cursor->node_group)
4028 node_cursor->cl_first = ti->cl_first;
4029 node_cursor->cl_cursor = ti->cl_cursor;
4030 *ti_ptr = node_cursor->node_group;
4031 DrawChooseTree(ti_ptr);
4033 else if (node_cursor->parent_link)
4037 *ti_ptr = node_cursor->node_parent;
4038 DrawChooseTree(ti_ptr);
4044 node_cursor->cl_first = ti->cl_first;
4045 node_cursor->cl_cursor = ti->cl_cursor;
4046 *ti_ptr = node_cursor;
4048 if (ti->type == TREE_TYPE_LEVEL_DIR)
4050 LoadLevelSetup_SeriesInfo();
4052 SaveLevelSetup_LastSeries();
4053 SaveLevelSetup_SeriesInfo();
4057 if (game_status == GAME_MODE_SETUP)
4059 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
4061 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
4062 execSetupGraphics();
4068 game_status = GAME_MODE_MAIN;
4076 void DrawChooseLevel()
4078 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4080 DrawChooseTree(&leveldir_current);
4086 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
4088 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4093 void DrawHallOfFame(int highlight_position)
4096 FadeSoundsAndMusic();
4098 /* (this is needed when called from GameEnd() after winning a game) */
4099 KeyboardAutoRepeatOn();
4102 /* (this is needed when called from GameEnd() after winning a game) */
4103 SetDrawDeactivationMask(REDRAW_NONE);
4104 SetDrawBackgroundMask(REDRAW_FIELD);
4106 CloseDoor(DOOR_CLOSE_2);
4108 if (highlight_position < 0)
4109 LoadScore(level_nr);
4114 FadeOut(REDRAW_FIELD);
4122 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4125 FadeIn(REDRAW_FIELD);
4129 static void drawHallOfFameList(int first_entry, int highlight_position)
4133 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4136 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4137 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4138 "HighScores of Level %d", level_nr);
4140 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4142 int entry = first_entry + i;
4143 boolean active = (entry == highlight_position);
4144 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4145 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4146 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4147 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4148 int dx1 = 3 * getFontWidth(font_nr1);
4149 int dx2 = dx1 + getFontWidth(font_nr1);
4150 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4151 int sy = mSY + 64 + i * 32;
4153 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4154 DrawText(mSX + dx1, sy, ".", font_nr1);
4155 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4157 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4158 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4160 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4163 redraw_mask |= REDRAW_FIELD;
4166 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4168 static int first_entry = 0;
4169 static int highlight_position = 0;
4170 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4172 if (button == MB_MENU_INITIALIZE)
4175 highlight_position = mx;
4176 drawHallOfFameList(first_entry, highlight_position);
4181 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4182 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4186 if (first_entry > 0)
4188 first_entry -= step;
4189 if (first_entry < 0)
4192 drawHallOfFameList(first_entry, highlight_position);
4197 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4199 first_entry += step;
4200 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4201 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4203 drawHallOfFameList(first_entry, highlight_position);
4206 else if (button == MB_MENU_LEAVE)
4208 PlaySound(SND_MENU_ITEM_SELECTING);
4210 FadeSound(SND_BACKGROUND_SCORES);
4212 game_status = GAME_MODE_MAIN;
4216 else if (button == MB_MENU_CHOICE)
4218 PlaySound(SND_MENU_ITEM_SELECTING);
4220 FadeSound(SND_BACKGROUND_SCORES);
4223 FadeOut(REDRAW_FIELD);
4226 game_status = GAME_MODE_MAIN;
4228 DrawAndFadeInMainMenu(REDRAW_FIELD);
4231 if (game_status == GAME_MODE_SCORES)
4232 PlayMenuSoundIfLoop();
4238 /* ========================================================================= */
4239 /* setup screen functions */
4240 /* ========================================================================= */
4242 static struct TokenInfo *setup_info;
4243 static int num_setup_info;
4245 static char *screen_mode_text;
4246 static char *game_speed_text;
4247 static char *graphics_set_name;
4248 static char *sounds_set_name;
4249 static char *music_set_name;
4251 static void execSetupMain()
4257 setup_mode = SETUP_MODE_MAIN;
4261 static void execSetupGame()
4267 if (game_speeds == NULL)
4271 for (i = 0; game_speeds_list[i].value != -1; i++)
4273 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4274 char identifier[32], name[32];
4275 int value = game_speeds_list[i].value;
4276 char *text = game_speeds_list[i].text;
4278 ti->node_top = &game_speeds;
4279 ti->sort_priority = 10000 - value;
4281 sprintf(identifier, "%d", value);
4282 sprintf(name, "%s", text);
4284 setString(&ti->identifier, identifier);
4285 setString(&ti->name, name);
4286 setString(&ti->name_sorting, name);
4287 setString(&ti->infotext, "Game Speed");
4289 pushTreeInfo(&game_speeds, ti);
4292 /* sort game speed values to start with slowest game speed */
4293 sortTreeInfo(&game_speeds);
4295 /* set current game speed to configured game speed value */
4296 game_speed_current =
4297 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4299 /* if that fails, set current game speed to reliable default value */
4300 if (game_speed_current == NULL)
4301 game_speed_current =
4302 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4304 /* if that also fails, set current game speed to first available speed */
4305 if (game_speed_current == NULL)
4306 game_speed_current = game_speeds;
4309 setup.game_frame_delay = atoi(game_speed_current->identifier);
4311 /* needed for displaying game speed text instead of identifier */
4312 game_speed_text = game_speed_current->name;
4314 setup_mode = SETUP_MODE_GAME;
4318 static void execSetupChooseGameSpeed()
4324 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4328 static void execSetupEditor()
4334 setup_mode = SETUP_MODE_EDITOR;
4338 static void execSetupGraphics()
4344 if (video.fullscreen_available && screen_modes == NULL)
4348 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4350 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4351 char identifier[32], name[32];
4352 int x = video.fullscreen_modes[i].width;
4353 int y = video.fullscreen_modes[i].height;
4356 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4358 ti->node_top = &screen_modes;
4359 ti->sort_priority = x * 10000 + y;
4361 sprintf(identifier, "%dx%d", x, y);
4362 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4364 setString(&ti->identifier, identifier);
4365 setString(&ti->name, name);
4366 setString(&ti->name_sorting, name);
4367 setString(&ti->infotext, "Fullscreen Mode");
4369 pushTreeInfo(&screen_modes, ti);
4372 /* sort fullscreen modes to start with lowest available screen resolution */
4373 sortTreeInfo(&screen_modes);
4375 /* set current screen mode for fullscreen mode to configured setup value */
4376 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4377 setup.fullscreen_mode);
4379 /* if that fails, set current screen mode to reliable default value */
4380 if (screen_mode_current == NULL)
4381 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4382 DEFAULT_FULLSCREEN_MODE);
4384 /* if that also fails, set current screen mode to first available mode */
4385 if (screen_mode_current == NULL)
4386 screen_mode_current = screen_modes;
4388 if (screen_mode_current == NULL)
4389 video.fullscreen_available = FALSE;
4392 if (video.fullscreen_available)
4394 setup.fullscreen_mode = screen_mode_current->identifier;
4396 /* needed for displaying screen mode name instead of identifier */
4397 screen_mode_text = screen_mode_current->name;
4400 setup_mode = SETUP_MODE_GRAPHICS;
4404 static void execSetupChooseScreenMode()
4410 if (!video.fullscreen_available)
4413 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4417 static void execSetupSound()
4423 setup_mode = SETUP_MODE_SOUND;
4427 static void execSetupArtwork()
4433 setup.graphics_set = artwork.gfx_current->identifier;
4434 setup.sounds_set = artwork.snd_current->identifier;
4435 setup.music_set = artwork.mus_current->identifier;
4437 /* needed if last screen (setup choice) changed graphics, sounds or music */
4438 ReloadCustomArtwork(0);
4440 /* needed for displaying artwork name instead of artwork identifier */
4441 graphics_set_name = artwork.gfx_current->name;
4442 sounds_set_name = artwork.snd_current->name;
4443 music_set_name = artwork.mus_current->name;
4445 setup_mode = SETUP_MODE_ARTWORK;
4449 static void execSetupChooseGraphics()
4455 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4459 static void execSetupChooseSounds()
4465 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4469 static void execSetupChooseMusic()
4475 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4479 static void execSetupInput()
4485 setup_mode = SETUP_MODE_INPUT;
4489 static void execSetupShortcut1()
4495 setup_mode = SETUP_MODE_SHORTCUT_1;
4499 static void execSetupShortcut2()
4505 setup_mode = SETUP_MODE_SHORTCUT_2;
4509 static void execExitSetup()
4515 game_status = GAME_MODE_MAIN;
4517 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4523 static void execSaveAndExitSetup()
4529 static struct TokenInfo setup_info_main[] =
4531 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4532 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4533 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4534 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4535 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4536 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4537 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
4538 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
4539 { TYPE_EMPTY, NULL, "" },
4540 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4541 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4546 static struct TokenInfo setup_info_game[] =
4548 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4549 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4550 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4551 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4552 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4553 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4554 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4555 { TYPE_STRING, &game_speed_text, "" },
4556 { TYPE_EMPTY, NULL, "" },
4557 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4562 static struct TokenInfo setup_info_editor[] =
4565 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4566 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4567 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4568 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4569 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4570 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4571 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4572 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4574 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4575 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4576 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4578 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4580 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4581 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4582 { TYPE_EMPTY, NULL, "" },
4584 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4585 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4586 { TYPE_EMPTY, NULL, "" },
4588 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4589 { TYPE_EMPTY, NULL, "" },
4590 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4595 static struct TokenInfo setup_info_graphics[] =
4597 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4598 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4599 { TYPE_STRING, &screen_mode_text, "" },
4600 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
4602 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4603 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4605 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4606 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4607 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4608 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4609 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4610 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4611 { TYPE_EMPTY, NULL, "" },
4612 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4617 static struct TokenInfo setup_info_sound[] =
4619 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4620 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4621 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4622 { TYPE_EMPTY, NULL, "" },
4623 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4628 static struct TokenInfo setup_info_artwork[] =
4630 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4631 { TYPE_STRING, &graphics_set_name, "" },
4632 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4633 { TYPE_STRING, &sounds_set_name, "" },
4634 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4635 { TYPE_STRING, &music_set_name, "" },
4636 { TYPE_EMPTY, NULL, "" },
4638 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4639 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4640 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4642 { TYPE_STRING, NULL, "Override Level Artwork:"},
4643 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4644 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4645 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4647 { TYPE_EMPTY, NULL, "" },
4648 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4653 static struct TokenInfo setup_info_input[] =
4655 { TYPE_SWITCH, NULL, "Player:" },
4656 { TYPE_SWITCH, NULL, "Device:" },
4657 { TYPE_ENTER_MENU, NULL, "" },
4658 { TYPE_EMPTY, NULL, "" },
4659 { TYPE_EMPTY, NULL, "" },
4660 { TYPE_EMPTY, NULL, "" },
4661 { TYPE_EMPTY, NULL, "" },
4662 { TYPE_EMPTY, NULL, "" },
4663 { TYPE_EMPTY, NULL, "" },
4664 { TYPE_EMPTY, NULL, "" },
4665 { TYPE_EMPTY, NULL, "" },
4666 { TYPE_EMPTY, NULL, "" },
4667 { TYPE_EMPTY, NULL, "" },
4668 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4673 static struct TokenInfo setup_info_shortcut_1[] =
4675 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4676 { TYPE_KEY, &setup.shortcut.save_game, "" },
4677 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4678 { TYPE_KEY, &setup.shortcut.load_game, "" },
4679 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4680 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4681 { TYPE_EMPTY, NULL, "" },
4682 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4683 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4684 { TYPE_EMPTY, NULL, "" },
4685 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4690 static struct TokenInfo setup_info_shortcut_2[] =
4692 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4693 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4694 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4695 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4696 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4697 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4698 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4699 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4700 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4701 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4702 { TYPE_EMPTY, NULL, "" },
4703 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4708 static Key getSetupKey()
4710 Key key = KSYM_UNDEFINED;
4711 boolean got_key_event = FALSE;
4713 while (!got_key_event)
4715 if (PendingEvent()) /* got event */
4723 case EVENT_KEYPRESS:
4725 key = GetEventKey((KeyEvent *)&event, TRUE);
4727 /* press 'Escape' or 'Enter' to keep the existing key binding */
4728 if (key == KSYM_Escape || key == KSYM_Return)
4729 key = KSYM_UNDEFINED; /* keep old value */
4731 got_key_event = TRUE;
4735 case EVENT_KEYRELEASE:
4736 key_joystick_mapping = 0;
4740 HandleOtherEvents(&event);
4748 /* don't eat all CPU time */
4755 static int getSetupTextFont(int type)
4757 if (type & (TYPE_SWITCH |
4768 static int getSetupValueFont(int type, void *value)
4770 if (type & TYPE_KEY)
4771 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4772 else if (type & TYPE_STRING)
4773 return FONT_VALUE_2;
4774 else if (type & TYPE_ECS_AGA)
4775 return FONT_VALUE_1;
4776 else if (type & TYPE_BOOLEAN_STYLE)
4777 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4779 return FONT_VALUE_1;
4782 static void drawSetupValue(int pos)
4784 boolean font_draw_xoffset_modified = FALSE;
4785 int font_draw_xoffset_old = -1;
4786 int xpos = MENU_SCREEN_VALUE_XPOS;
4787 int ypos = MENU_SCREEN_START_YPOS + pos;
4788 int startx = mSX + xpos * 32;
4789 int starty = mSY + ypos * 32;
4790 int font_nr, font_width;
4791 int type = setup_info[pos].type;
4792 void *value = setup_info[pos].value;
4793 char *value_string = getSetupValue(type, value);
4796 if (value_string == NULL)
4799 if (type & TYPE_KEY)
4801 xpos = MENU_SCREEN_START_XPOS;
4803 if (type & TYPE_QUERY)
4805 value_string = "<press key>";
4808 else if (type & TYPE_STRING)
4810 int max_value_len = (SCR_FIELDX - 2) * 2;
4812 xpos = MENU_SCREEN_START_XPOS;
4814 if (strlen(value_string) > max_value_len)
4815 value_string[max_value_len] = '\0';
4818 startx = mSX + xpos * 32;
4819 starty = mSY + ypos * 32;
4820 font_nr = getSetupValueFont(type, value);
4821 font_width = getFontWidth(font_nr);
4823 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4824 if (setup_mode != SETUP_MODE_INPUT)
4826 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4827 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4828 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4829 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4830 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4831 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4832 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4833 boolean correct_font_draw_xoffset = FALSE;
4835 if (xpos == MENU_SCREEN_START_XPOS &&
4836 startx + font1_xoffset < text_startx + text_font_xoffset)
4837 correct_font_draw_xoffset = TRUE;
4839 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4840 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4841 correct_font_draw_xoffset = TRUE;
4843 /* check if setup value would overlap with setup text when printed */
4844 /* (this can happen for extreme/wrong values for font draw offset) */
4845 if (correct_font_draw_xoffset)
4847 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4848 font_draw_xoffset_modified = TRUE;
4850 if (type & TYPE_KEY)
4851 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4852 else if (!(type & TYPE_STRING))
4853 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4854 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4858 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4859 DrawText(startx + i * font_width, starty, " ", font_nr);
4861 DrawText(startx, starty, value_string, font_nr);
4863 if (font_draw_xoffset_modified)
4864 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4867 static void changeSetupValue(int pos)
4869 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4871 *(boolean *)setup_info[pos].value ^= TRUE;
4873 else if (setup_info[pos].type & TYPE_KEY)
4877 setup_info[pos].type |= TYPE_QUERY;
4878 drawSetupValue(pos);
4879 setup_info[pos].type &= ~TYPE_QUERY;
4881 key = getSetupKey();
4882 if (key != KSYM_UNDEFINED)
4883 *(Key *)setup_info[pos].value = key;
4886 drawSetupValue(pos);
4889 static void DrawCursorAndText_Setup(int pos, boolean active)
4891 int xpos = MENU_SCREEN_START_XPOS;
4892 int ypos = MENU_SCREEN_START_YPOS + pos;
4893 int font_nr = getSetupTextFont(setup_info[pos].type);
4895 if (setup_info == setup_info_input)
4896 font_nr = FONT_MENU_1;
4899 font_nr = FONT_ACTIVE(font_nr);
4901 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4903 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4904 drawCursor(pos, active);
4907 static void DrawSetupScreen_Generic()
4909 char *title_string = NULL;
4913 CloseDoor(DOOR_CLOSE_2);
4916 FadeOut(REDRAW_FIELD);
4921 if (setup_mode == SETUP_MODE_MAIN)
4923 setup_info = setup_info_main;
4924 title_string = "Setup";
4926 else if (setup_mode == SETUP_MODE_GAME)
4928 setup_info = setup_info_game;
4929 title_string = "Setup Game";
4931 else if (setup_mode == SETUP_MODE_EDITOR)
4933 setup_info = setup_info_editor;
4934 title_string = "Setup Editor";
4936 else if (setup_mode == SETUP_MODE_GRAPHICS)
4938 setup_info = setup_info_graphics;
4939 title_string = "Setup Graphics";
4941 else if (setup_mode == SETUP_MODE_SOUND)
4943 setup_info = setup_info_sound;
4944 title_string = "Setup Sound";
4946 else if (setup_mode == SETUP_MODE_ARTWORK)
4948 setup_info = setup_info_artwork;
4949 title_string = "Custom Artwork";
4951 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
4953 setup_info = setup_info_shortcut_1;
4954 title_string = "Setup Shortcuts";
4956 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
4958 setup_info = setup_info_shortcut_2;
4959 title_string = "Setup Shortcuts";
4962 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4965 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4967 void *value_ptr = setup_info[i].value;
4970 int xpos = MENU_SCREEN_START_XPOS;
4971 int ypos = MENU_SCREEN_START_YPOS + i;
4975 /* set some entries to "unchangeable" according to other variables */
4976 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4977 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4978 (value_ptr == &setup.sound_music && !audio.music_available) ||
4979 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4980 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4981 setup_info[i].type |= TYPE_GHOSTED;
4983 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4984 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4985 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4986 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4987 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4988 initCursor(i, IMG_MENU_BUTTON);
4991 DrawCursorAndText_Setup(i, FALSE);
4993 font_nr = getSetupTextFont(setup_info[i].type);
4995 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
4998 if (setup_info[i].type & TYPE_VALUE)
5005 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5006 "Joysticks deactivated in setup menu");
5010 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5014 FadeIn(REDRAW_FIELD);
5019 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5023 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5025 static int choice_store[MAX_SETUP_MODES];
5026 int choice = choice_store[setup_mode]; /* always starts with 0 */
5030 if (button == MB_MENU_INITIALIZE)
5032 /* advance to first valid menu entry */
5033 while (choice < num_setup_info &&
5034 setup_info[choice].type & TYPE_SKIP_ENTRY)
5036 choice_store[setup_mode] = choice;
5039 DrawCursorAndText_Setup(choice, TRUE);
5041 drawCursor(choice, TRUE);
5046 else if (button == MB_MENU_LEAVE)
5048 PlaySound(SND_MENU_ITEM_SELECTING);
5050 for (y = 0; y < num_setup_info; y++)
5052 if (setup_info[y].type & TYPE_LEAVE_MENU)
5054 void (*menu_callback_function)(void) = setup_info[y].value;
5058 menu_callback_function();
5060 break; /* absolutely needed because function changes 'setup_info'! */
5067 if (mx || my) /* mouse input */
5069 x = (mx - mSX) / 32;
5070 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5072 else if (dx || dy) /* keyboard input */
5076 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5078 if (setup_info[choice].type & menu_navigation_type ||
5079 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
5080 button = MB_MENU_CHOICE;
5085 /* jump to next non-empty menu entry (up or down) */
5086 while (y > 0 && y < num_setup_info - 1 &&
5087 setup_info[y].type & TYPE_SKIP_ENTRY)
5091 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5095 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5097 PlaySound(SND_MENU_ITEM_ACTIVATING);
5100 DrawCursorAndText_Setup(choice, FALSE);
5101 DrawCursorAndText_Setup(y, TRUE);
5103 drawCursor(choice, FALSE);
5104 drawCursor(y, TRUE);
5107 choice = choice_store[setup_mode] = y;
5110 else if (!(setup_info[y].type & TYPE_GHOSTED))
5112 PlaySound(SND_MENU_ITEM_SELECTING);
5114 /* when selecting key headline, execute function for key value change */
5115 if (setup_info[y].type & TYPE_KEYTEXT &&
5116 setup_info[y + 1].type & TYPE_KEY)
5119 /* when selecting string value, execute function for list selection */
5120 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5121 setup_info[y - 1].type & TYPE_ENTER_LIST)
5124 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5126 void (*menu_callback_function)(void) = setup_info[y].value;
5128 FadeSetFromType(setup_info[y].type);
5130 menu_callback_function();
5134 if (setup_info[y].type & TYPE_VALUE)
5135 changeSetupValue(y);
5141 void DrawSetupScreen_Input()
5148 FadeOut(REDRAW_FIELD);
5154 setup_info = setup_info_input;
5157 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5160 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5162 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5163 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5164 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5165 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5166 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5167 initCursor(i, IMG_MENU_BUTTON);
5169 DrawCursorAndText_Setup(i, FALSE);
5172 initCursor(0, IMG_MENU_BUTTON);
5173 initCursor(1, IMG_MENU_BUTTON);
5174 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
5175 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
5177 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
5178 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
5179 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
5183 DeactivateJoystickForCalibration();
5186 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5187 "Joysticks deactivated on this screen");
5190 /* create gadgets for setup input menu screen */
5191 FreeScreenGadgets();
5192 CreateScreenGadgets();
5194 /* map gadgets for setup input menu screen */
5195 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5197 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5200 FadeIn(REDRAW_FIELD);
5206 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5208 if (device_name == NULL)
5211 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5214 if (strlen(device_name) > 1)
5216 char c1 = device_name[strlen(device_name) - 1];
5217 char c2 = device_name[strlen(device_name) - 2];
5219 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5220 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5223 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5224 strlen(device_name));
5227 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5230 static struct SetupKeyboardInfo custom_key;
5237 { &custom_key.left, "Joystick Left" },
5238 { &custom_key.right, "Joystick Right" },
5239 { &custom_key.up, "Joystick Up" },
5240 { &custom_key.down, "Joystick Down" },
5241 { &custom_key.snap, "Button 1" },
5242 { &custom_key.drop, "Button 2" }
5244 static char *joystick_name[MAX_PLAYERS] =
5251 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5255 custom_key = setup.input[player_nr].key;
5257 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5258 FONT_INPUT_1_ACTIVE);
5260 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5262 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5263 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5265 if (setup.input[player_nr].use_joystick)
5267 char *device_name = setup.input[player_nr].joy.device_name;
5268 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5269 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5271 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5272 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5276 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5277 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5280 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5282 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5283 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5284 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5285 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5287 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5288 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5289 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5290 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5291 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5292 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5294 for (i = 0; i < 6; i++)
5296 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5298 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5300 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5301 (setup.input[player_nr].use_joystick ?
5303 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5307 static int input_player_nr = 0;
5309 void HandleSetupScreen_Input_Player(int step, int direction)
5311 int old_player_nr = input_player_nr;
5314 new_player_nr = old_player_nr + step * direction;
5315 if (new_player_nr < 0)
5317 if (new_player_nr > MAX_PLAYERS - 1)
5318 new_player_nr = MAX_PLAYERS - 1;
5320 if (new_player_nr != old_player_nr)
5322 input_player_nr = new_player_nr;
5324 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5328 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5330 static int choice = 0;
5333 int pos_start = SETUPINPUT_SCREEN_POS_START;
5334 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5335 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5336 int pos_end = SETUPINPUT_SCREEN_POS_END;
5338 if (button == MB_MENU_INITIALIZE)
5340 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5343 DrawCursorAndText_Setup(choice, TRUE);
5345 drawCursor(choice, TRUE);
5350 else if (button == MB_MENU_LEAVE)
5352 setup_mode = SETUP_MODE_MAIN;
5359 if (mx || my) /* mouse input */
5361 x = (mx - mSX) / 32;
5362 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5364 else if (dx || dy) /* keyboard input */
5366 if (dx && choice == 0)
5367 x = (dx < 0 ? 10 : 12);
5368 else if ((dx && choice == 1) ||
5369 (dx == +1 && choice == 2) ||
5370 (dx == -1 && choice == pos_end))
5371 button = MB_MENU_CHOICE;
5375 if (y >= pos_empty1 && y <= pos_empty2)
5376 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5379 if (y == 0 && dx != 0 && button)
5381 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5383 else if (IN_VIS_FIELD(x, y) &&
5384 y >= pos_start && y <= pos_end &&
5385 !(y >= pos_empty1 && y <= pos_empty2))
5392 DrawCursorAndText_Setup(choice, FALSE);
5393 DrawCursorAndText_Setup(y, TRUE);
5395 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5397 drawCursor(choice, FALSE);
5398 drawCursor(y, TRUE);
5408 char *device_name = setup.input[input_player_nr].joy.device_name;
5410 if (!setup.input[input_player_nr].use_joystick)
5412 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5414 setJoystickDeviceToNr(device_name, new_device_nr);
5415 setup.input[input_player_nr].use_joystick = TRUE;
5419 int device_nr = getJoystickNrFromDeviceName(device_name);
5420 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5422 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5423 setup.input[input_player_nr].use_joystick = FALSE;
5425 setJoystickDeviceToNr(device_name, new_device_nr);
5428 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5432 if (setup.input[input_player_nr].use_joystick)
5435 CalibrateJoystick(input_player_nr);
5438 CustomizeKeyboard(input_player_nr);
5440 else if (y == pos_end)
5446 setup_mode = SETUP_MODE_MAIN;
5453 void CustomizeKeyboard(int player_nr)
5457 boolean finished = FALSE;
5458 static struct SetupKeyboardInfo custom_key;
5463 } customize_step[] =
5465 { &custom_key.left, "Move Left" },
5466 { &custom_key.right, "Move Right" },
5467 { &custom_key.up, "Move Up" },
5468 { &custom_key.down, "Move Down" },
5469 { &custom_key.snap, "Snap Field" },
5470 { &custom_key.drop, "Drop Element" }
5473 /* read existing key bindings from player setup */
5474 custom_key = setup.input[player_nr].key;
5477 FadeOut(REDRAW_FIELD);
5481 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5489 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5490 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5491 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5492 "Key:", FONT_INPUT_1_ACTIVE);
5493 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5494 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5497 FadeIn(REDRAW_FIELD);
5504 if (PendingEvent()) /* got event */
5512 case EVENT_KEYPRESS:
5514 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5516 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5518 if (key == KSYM_Escape)
5519 FadeSkipNextFadeIn();
5525 /* all keys configured -- wait for "Escape" or "Return" key */
5529 /* press 'Enter' to keep the existing key binding */
5530 if (key == KSYM_Return)
5531 key = *customize_step[step_nr].key;
5533 /* check if key already used */
5534 for (i = 0; i < step_nr; i++)
5535 if (*customize_step[i].key == key)
5540 /* got new key binding */
5541 *customize_step[step_nr].key = key;
5542 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5544 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5545 getKeyNameFromKey(key), FONT_VALUE_1);
5548 /* un-highlight last query */
5549 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5550 customize_step[step_nr - 1].text, FONT_MENU_1);
5551 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5552 "Key:", FONT_MENU_1);
5554 /* press 'Enter' to leave */
5557 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5558 "Press Enter", FONT_TITLE_1);
5562 /* query next key binding */
5563 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5564 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5565 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5566 "Key:", FONT_INPUT_1_ACTIVE);
5567 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5568 getKeyNameFromKey(*customize_step[step_nr].key),
5573 case EVENT_KEYRELEASE:
5574 key_joystick_mapping = 0;
5578 HandleOtherEvents(&event);
5586 /* don't eat all CPU time */
5590 /* write new key bindings back to player setup */
5591 setup.input[player_nr].key = custom_key;
5594 DrawSetupScreen_Input();
5597 static boolean CalibrateJoystickMain(int player_nr)
5599 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5600 int new_joystick_xright = JOYSTICK_XMIDDLE;
5601 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5602 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5603 int new_joystick_xmiddle, new_joystick_ymiddle;
5605 int joystick_fd = joystick.fd[player_nr];
5606 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5607 boolean check[3][3];
5608 int check_remaining = 3 * 3;
5613 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5616 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5620 FadeOut(REDRAW_FIELD);
5624 for (y = 0; y < 3; y++)
5626 for (x = 0; x < 3; x++)
5628 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5629 check[x][y] = FALSE;
5633 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5634 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5635 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5636 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5637 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5638 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5639 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5641 joy_value = Joystick(player_nr);
5642 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5643 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5645 /* eventually uncalibrated center position (joystick could be uncentered) */
5646 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5649 new_joystick_xmiddle = joy_x;
5650 new_joystick_ymiddle = joy_y;
5652 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5655 FadeIn(REDRAW_FIELD);
5660 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5665 if (PendingEvent()) /* got event */
5673 case EVENT_KEYPRESS:
5674 switch (GetEventKey((KeyEvent *)&event, TRUE))
5677 if (check_remaining == 0)
5682 FadeSkipNextFadeIn();
5691 case EVENT_KEYRELEASE:
5692 key_joystick_mapping = 0;
5696 HandleOtherEvents(&event);
5701 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5704 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5705 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5706 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5707 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5709 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5710 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5711 setup.input[player_nr].joy.xright = new_joystick_xright;
5712 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5713 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5714 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5716 CheckJoystickData();
5718 joy_value = Joystick(player_nr);
5720 if (joy_value & JOY_BUTTON && check_remaining == 0)
5723 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5724 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5726 if (x != last_x || y != last_y)
5728 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5729 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5734 if (check_remaining > 0 && !check[x+1][y+1])
5736 check[x+1][y+1] = TRUE;
5742 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5743 setup.input[player_nr].joy.xleft,
5744 setup.input[player_nr].joy.xmiddle,
5745 setup.input[player_nr].joy.xright);
5746 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5747 setup.input[player_nr].joy.yupper,
5748 setup.input[player_nr].joy.ymiddle,
5749 setup.input[player_nr].joy.ylower);
5758 /* don't eat all CPU time */
5762 /* calibrated center position (joystick should now be centered) */
5763 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5766 new_joystick_xmiddle = joy_x;
5767 new_joystick_ymiddle = joy_y;
5772 DrawSetupScreen_Input();
5775 /* wait until the last pressed button was released */
5776 while (Joystick(player_nr) & JOY_BUTTON)
5778 if (PendingEvent()) /* got event */
5783 HandleOtherEvents(&event);
5792 void CalibrateJoystick(int player_nr)
5794 if (!CalibrateJoystickMain(player_nr))
5796 char *device_name = setup.input[player_nr].joy.device_name;
5797 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5798 int xpos = mSX - SX;
5799 int ypos = mSY - SY;
5803 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5804 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5807 Delay(2000); /* show error message for a short time */
5813 DrawSetupScreen_Input();
5817 void DrawSetupScreen()
5819 DeactivateJoystick();
5821 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5823 if (setup_mode == SETUP_MODE_INPUT)
5824 DrawSetupScreen_Input();
5825 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5826 DrawChooseTree(&game_speed_current);
5827 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5828 DrawChooseTree(&screen_mode_current);
5829 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5830 DrawChooseTree(&artwork.gfx_current);
5831 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5832 DrawChooseTree(&artwork.snd_current);
5833 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5834 DrawChooseTree(&artwork.mus_current);
5836 DrawSetupScreen_Generic();
5842 void RedrawSetupScreenAfterFullscreenToggle()
5844 if (setup_mode == SETUP_MODE_GRAPHICS)
5848 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5850 if (setup_mode == SETUP_MODE_INPUT)
5851 HandleSetupScreen_Input(mx, my, dx, dy, button);
5852 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5853 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5854 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5855 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5856 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5857 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5858 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5859 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5860 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5861 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5863 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5868 void HandleGameActions()
5870 if (game_status != GAME_MODE_PLAYING)
5873 GameActions(); /* main game loop */
5875 if (tape.auto_play && !tape.playing)
5876 AutoPlayTape(); /* continue automatically playing next tape */
5880 /* ---------- new screen button stuff -------------------------------------- */
5882 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5887 case SCREEN_CTRL_ID_PREV_LEVEL:
5888 *x = mSX + menu.main.button.prev_level.x;
5889 *y = mSY + menu.main.button.prev_level.y;
5892 case SCREEN_CTRL_ID_NEXT_LEVEL:
5893 *x = mSX + menu.main.button.next_level.x;
5894 *y = mSY + menu.main.button.next_level.y;
5897 case SCREEN_CTRL_ID_PREV_LEVEL:
5898 *x = mSX + TILEX * getPrevlevelButtonPos();
5899 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5902 case SCREEN_CTRL_ID_NEXT_LEVEL:
5903 *x = mSX + TILEX * getNextLevelButtonPos();
5904 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5908 case SCREEN_CTRL_ID_PREV_PLAYER:
5909 *x = mSX + TILEX * 10;
5910 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5913 case SCREEN_CTRL_ID_NEXT_PLAYER:
5914 *x = mSX + TILEX * 12;
5915 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5919 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5925 int gfx_unpressed, gfx_pressed;
5926 void (*get_gadget_position)(int *, int *, int);
5930 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5933 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5934 getScreenMenuButtonPos,
5935 SCREEN_CTRL_ID_PREV_LEVEL,
5940 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5941 getScreenMenuButtonPos,
5942 SCREEN_CTRL_ID_NEXT_LEVEL,
5947 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5948 getScreenMenuButtonPos,
5949 SCREEN_CTRL_ID_PREV_PLAYER,
5954 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5955 getScreenMenuButtonPos,
5956 SCREEN_CTRL_ID_NEXT_PLAYER,
5964 int gfx_unpressed, gfx_pressed;
5968 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5971 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5972 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5973 SCREEN_CTRL_ID_SCROLL_UP,
5977 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5978 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5979 SCREEN_CTRL_ID_SCROLL_DOWN,
5986 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5987 Bitmap **gfx_unpressed, **gfx_pressed;
5989 int gfx_unpressed, gfx_pressed;
5996 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5999 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6000 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6002 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6004 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6005 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6006 GD_TYPE_SCROLLBAR_VERTICAL,
6007 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6008 "scroll level series vertically"
6012 static void CreateScreenMenubuttons()
6014 struct GadgetInfo *gi;
6015 unsigned long event_mask;
6018 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6020 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6021 int gfx_unpressed, gfx_pressed;
6022 int x, y, width, height;
6023 int gd_x1, gd_x2, gd_y1, gd_y2;
6024 int id = menubutton_info[i].gadget_id;
6026 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6028 menubutton_info[i].get_gadget_position(&x, &y, id);
6030 width = SC_MENUBUTTON_XSIZE;
6031 height = SC_MENUBUTTON_YSIZE;
6033 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6034 gfx_pressed = menubutton_info[i].gfx_pressed;
6035 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6036 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6037 gd_x1 = graphic_info[gfx_unpressed].src_x;
6038 gd_y1 = graphic_info[gfx_unpressed].src_y;
6039 gd_x2 = graphic_info[gfx_pressed].src_x;
6040 gd_y2 = graphic_info[gfx_pressed].src_y;
6042 gi = CreateGadget(GDI_CUSTOM_ID, id,
6043 GDI_CUSTOM_TYPE_ID, i,
6044 GDI_INFO_TEXT, menubutton_info[i].infotext,
6049 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6050 GDI_STATE, GD_BUTTON_UNPRESSED,
6051 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6052 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6053 GDI_DIRECT_DRAW, FALSE,
6054 GDI_EVENT_MASK, event_mask,
6055 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6059 Error(ERR_EXIT, "cannot create gadget");
6061 screen_gadget[id] = gi;
6065 static void CreateScreenScrollbuttons()
6067 struct GadgetInfo *gi;
6068 unsigned long event_mask;
6071 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6073 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6074 int gfx_unpressed, gfx_pressed;
6075 int x, y, width, height;
6076 int gd_x1, gd_x2, gd_y1, gd_y2;
6077 int id = scrollbutton_info[i].gadget_id;
6079 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6081 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6082 y = mSY + scrollbutton_info[i].y;
6083 width = SC_SCROLLBUTTON_XSIZE;
6084 height = SC_SCROLLBUTTON_YSIZE;
6086 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6087 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6088 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6090 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6091 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6092 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6093 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6094 gd_x1 = graphic_info[gfx_unpressed].src_x;
6095 gd_y1 = graphic_info[gfx_unpressed].src_y;
6096 gd_x2 = graphic_info[gfx_pressed].src_x;
6097 gd_y2 = graphic_info[gfx_pressed].src_y;
6099 gi = CreateGadget(GDI_CUSTOM_ID, id,
6100 GDI_CUSTOM_TYPE_ID, i,
6101 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6106 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6107 GDI_STATE, GD_BUTTON_UNPRESSED,
6108 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6109 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6110 GDI_DIRECT_DRAW, FALSE,
6111 GDI_EVENT_MASK, event_mask,
6112 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6116 Error(ERR_EXIT, "cannot create gadget");
6118 screen_gadget[id] = gi;
6122 static void CreateScreenScrollbars()
6126 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6128 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6129 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6130 int gfx_unpressed, gfx_pressed;
6132 int x, y, width, height;
6133 int gd_x1, gd_x2, gd_y1, gd_y2;
6134 struct GadgetInfo *gi;
6135 int items_max, items_visible, item_position;
6136 unsigned long event_mask;
6137 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6138 int id = scrollbar_info[i].gadget_id;
6140 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6142 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6143 y = mSY + scrollbar_info[i].y;
6144 width = scrollbar_info[i].width;
6145 height = scrollbar_info[i].height;
6147 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6148 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6150 items_max = num_page_entries;
6151 items_visible = num_page_entries;
6154 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6155 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6156 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6162 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6163 gfx_pressed = scrollbar_info[i].gfx_pressed;
6164 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6165 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6166 gd_x1 = graphic_info[gfx_unpressed].src_x;
6167 gd_y1 = graphic_info[gfx_unpressed].src_y;
6168 gd_x2 = graphic_info[gfx_pressed].src_x;
6169 gd_y2 = graphic_info[gfx_pressed].src_y;
6172 gi = CreateGadget(GDI_CUSTOM_ID, id,
6173 GDI_CUSTOM_TYPE_ID, i,
6174 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6179 GDI_TYPE, scrollbar_info[i].type,
6180 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6181 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6182 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6184 GDI_WHEEL_AREA_X, SX,
6185 GDI_WHEEL_AREA_Y, SY,
6186 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6187 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6189 GDI_WHEEL_AREA_X, 0,
6190 GDI_WHEEL_AREA_Y, 0,
6191 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6192 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6194 GDI_STATE, GD_BUTTON_UNPRESSED,
6195 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6196 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6197 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6198 GDI_DIRECT_DRAW, FALSE,
6199 GDI_EVENT_MASK, event_mask,
6200 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6204 Error(ERR_EXIT, "cannot create gadget");
6206 screen_gadget[id] = gi;
6210 void CreateScreenGadgets()
6212 int last_game_status = game_status; /* save current game status */
6214 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6217 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6219 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6221 /* copy pointers to clip mask and GC */
6222 scrollbar_bitmap[i]->clip_mask =
6223 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6224 scrollbar_bitmap[i]->stored_clip_gc =
6225 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6227 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6228 scrollbar_bitmap[i],
6229 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6230 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6231 TILEX, TILEY, 0, 0);
6235 CreateScreenMenubuttons();
6237 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6238 game_status = GAME_MODE_LEVELS;
6240 CreateScreenScrollbuttons();
6241 CreateScreenScrollbars();
6243 game_status = last_game_status; /* restore current game status */
6246 void FreeScreenGadgets()
6250 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6251 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6253 /* prevent freeing clip mask and GC twice */
6254 scrollbar_bitmap[i]->clip_mask = None;
6255 scrollbar_bitmap[i]->stored_clip_gc = None;
6257 FreeBitmap(scrollbar_bitmap[i]);
6261 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6262 FreeGadget(screen_gadget[i]);
6265 void MapScreenMenuGadgets(int screen_mask)
6269 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6270 if (screen_mask & menubutton_info[i].screen_mask)
6271 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6274 void MapScreenTreeGadgets(TreeInfo *ti)
6276 int num_entries = numTreeInfoInGroup(ti);
6279 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6282 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6283 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6285 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6286 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6289 static void HandleScreenGadgets(struct GadgetInfo *gi)
6291 int id = gi->custom_id;
6292 int button = gi->event.button;
6293 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6297 case SCREEN_CTRL_ID_PREV_LEVEL:
6298 HandleMainMenu_SelectLevel(step, -1);
6301 case SCREEN_CTRL_ID_NEXT_LEVEL:
6302 HandleMainMenu_SelectLevel(step, +1);
6305 case SCREEN_CTRL_ID_PREV_PLAYER:
6306 HandleSetupScreen_Input_Player(step, -1);
6309 case SCREEN_CTRL_ID_NEXT_PLAYER:
6310 HandleSetupScreen_Input_Player(step, +1);
6313 case SCREEN_CTRL_ID_SCROLL_UP:
6314 if (game_status == GAME_MODE_LEVELS)
6315 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6316 else if (game_status == GAME_MODE_SETUP)
6317 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6320 case SCREEN_CTRL_ID_SCROLL_DOWN:
6321 if (game_status == GAME_MODE_LEVELS)
6322 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6323 else if (game_status == GAME_MODE_SETUP)
6324 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6327 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6328 if (game_status == GAME_MODE_LEVELS)
6329 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6330 else if (game_status == GAME_MODE_SETUP)
6331 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);