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].anim_mode != ANIM_DEFAULT)
618 ti.anim_mode = graphic_info[graphic].anim_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.anim_mode = titlemessage_initial[nr].anim_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.anim_mode = titlemessage[nr].anim_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;
644 if (ti.anim_mode == ANIM_NONE)
645 ti.fade_delay = ti.post_delay = 0;
650 static int compareTitleControlInfo(const void *object1, const void *object2)
652 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
653 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
656 if (tci1->initial != tci2->initial)
657 compare_result = (tci1->initial ? -1 : +1);
658 else if (tci1->sort_priority != tci2->sort_priority)
659 compare_result = tci1->sort_priority - tci2->sort_priority;
660 else if (tci1->is_image != tci2->is_image)
661 compare_result = (tci1->is_image ? -1 : +1);
663 compare_result = tci1->local_nr - tci2->local_nr;
665 return compare_result;
668 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
670 int nr, int sort_priority)
672 title_controls[num_title_screens].is_image = is_image;
673 title_controls[num_title_screens].initial = initial;
674 title_controls[num_title_screens].local_nr = nr;
675 title_controls[num_title_screens].sort_priority = sort_priority;
680 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
684 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
686 int graphic = getTitleScreenGraphic(i, initial);
687 Bitmap *bitmap = graphic_info[graphic].bitmap;
688 int sort_priority = graphic_info[graphic].sort_priority;
691 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
694 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
696 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
697 char *filename = getLevelSetTitleMessageFilename(i, initial);
698 int sort_priority = tmi->sort_priority;
700 if (filename != NULL)
701 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
705 static void InitializeTitleControls(boolean show_title_initial)
707 num_title_screens = 0;
709 if (show_title_initial)
710 InitializeTitleControls_CheckTitleInfo(TRUE);
712 InitializeTitleControls_CheckTitleInfo(FALSE);
714 /* sort title screens according to sort_priority and title number */
715 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
716 compareTitleControlInfo);
719 static boolean visibleMenuPos(struct MenuPosInfo *pos)
721 return (pos != NULL && pos->x != -1 && pos->y != -1);
724 static boolean visibleTextPos(struct TextPosInfo *pos)
726 return (pos != NULL && pos->x != -1 && pos->y != -1);
729 static void InitializeMainControls()
731 boolean local_team_mode = (!options.network && setup.team_mode);
734 /* set main control text values to dynamically determined values */
735 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
736 sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
737 sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
738 sprintf(main_text_level_number, "%s", int2str(level_nr, 3));
740 main_text_level_year = leveldir_current->year;
741 main_text_level_imported_from = leveldir_current->imported_from;
742 main_text_level_imported_by = leveldir_current->imported_by;
743 main_text_level_tested_by = leveldir_current->tested_by;
745 /* set main control screen positions to dynamically determined values */
746 for (i = 0; main_controls[i].nr != -1; i++)
748 struct MainControlInfo *mci = &main_controls[i];
750 struct MenuPosInfo *pos_button = mci->pos_button;
751 struct TextPosInfo *pos_text = mci->pos_text;
752 struct TextPosInfo *pos_input = mci->pos_input;
753 char *text = (mci->text ? *mci->text : NULL);
754 char *input = (mci->input ? *mci->input : NULL);
755 int button_graphic = mci->button_graphic;
757 int font_text = (pos_text ? pos_text->font : -1);
758 int font_input = (pos_input ? pos_input->font : -1);
760 int font_text = mci->font_text;
761 int font_input = mci->font_input;
764 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
765 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
766 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
767 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
768 int text_chars = (text != NULL ? strlen(text) : 0);
769 int input_chars = (input != NULL ? strlen(input) : 0);
772 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
774 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
775 int text_width = font_text_width * text_chars;
776 int text_height = font_text_height;
777 int input_width = font_input_width * input_chars;
778 int input_height = font_input_height;
780 if (nr == MAIN_CONTROL_NAME)
783 if (menu.main.input.name.x == -1)
784 menu.main.input.name.x = menu.main.text.name.x + text_width;
785 if (menu.main.input.name.y == -1)
786 menu.main.input.name.y = menu.main.text.name.y;
790 menu.main.input.name.width = input_width;
791 menu.main.input.name.height = input_height;
793 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
794 menu.main.input.name.height = font_input_height;
798 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
800 if (pos_button->width == 0)
801 pos_button->width = button_width;
802 if (pos_button->height == 0)
803 pos_button->height = button_height;
806 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
808 /* calculate width for non-clickable text -- needed for text alignment */
809 boolean calculate_text_width = (pos_button == NULL && text != NULL);
811 if (visibleMenuPos(pos_button))
813 if (pos_text->x == -1)
814 pos_text->x = pos_button->x + pos_button->width;
815 if (pos_text->y == -1)
816 pos_text->y = pos_button->y;
819 if (pos_text->width == -1 || calculate_text_width)
820 pos_text->width = text_width;
821 if (pos_text->height == -1)
822 pos_text->height = text_height;
825 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
827 if (visibleTextPos(pos_text))
829 if (pos_input->x == -1)
830 pos_input->x = pos_text->x + pos_text->width;
831 if (pos_input->y == -1)
832 pos_input->y = pos_text->y;
835 if (pos_input->width == -1)
836 pos_input->width = input_width;
837 if (pos_input->height == -1)
838 pos_input->height = input_height;
843 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
844 boolean active_input)
848 for (i = 0; main_controls[i].nr != -1; i++)
850 struct MainControlInfo *mci = &main_controls[i];
852 if (mci->nr == nr || nr == -1)
854 struct MenuPosInfo *pos_button = mci->pos_button;
855 struct TextPosInfo *pos_text = mci->pos_text;
856 struct TextPosInfo *pos_input = mci->pos_input;
857 char *text = (mci->text ? *mci->text : NULL);
858 char *input = (mci->input ? *mci->input : NULL);
859 int button_graphic = mci->button_graphic;
861 int font_text = (pos_text ? pos_text->font : -1);
862 int font_input = (pos_input ? pos_input->font : -1);
864 int font_text = mci->font_text;
865 int font_input = mci->font_input;
870 button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
871 font_text = FONT_ACTIVE(font_text);
876 font_input = FONT_ACTIVE(font_input);
879 if (visibleMenuPos(pos_button))
881 struct MenuPosInfo *pos = pos_button;
882 int x = mSX + pos->x;
883 int y = mSY + pos->y;
885 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
886 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
889 if (visibleTextPos(pos_text) && text != NULL)
891 struct TextPosInfo *pos = pos_text;
892 int x = mSX + ALIGNED_TEXT_XPOS(pos);
893 int y = mSY + ALIGNED_TEXT_YPOS(pos);
896 /* (check why/if this is needed) */
897 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
899 DrawText(x, y, text, font_text);
902 if (visibleTextPos(pos_input) && input != NULL)
904 struct TextPosInfo *pos = pos_input;
905 int x = mSX + ALIGNED_TEXT_XPOS(pos);
906 int y = mSY + ALIGNED_TEXT_YPOS(pos);
909 /* (check why/if this is needed) */
910 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
912 DrawText(x, y, input, font_input);
918 static void DrawCursorAndText_Main(int nr, boolean active_text)
920 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
924 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
926 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
930 static struct MainControlInfo *getMainControlInfo(int nr)
934 for (i = 0; main_controls[i].nr != -1; i++)
935 if (main_controls[i].nr == nr)
936 return &main_controls[i];
941 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
946 int rect_x = ALIGNED_TEXT_XPOS(rect);
947 int rect_y = ALIGNED_TEXT_YPOS(rect);
949 return (x >= rect_x && x < rect_x + rect->width &&
950 y >= rect_y && y < rect_y + rect->height);
953 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
958 int rect_x = ALIGNED_TEXT_XPOS(rect);
959 int rect_y = ALIGNED_TEXT_YPOS(rect);
961 return (x >= rect_x && x < rect_x + rect->width &&
962 y >= rect_y && y < rect_y + rect->height);
965 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
967 static int cursor_array[SCR_FIELDY];
968 int x = mSX + TILEX * xpos;
969 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
974 cursor_array[ypos] = graphic;
976 graphic = cursor_array[ypos];
980 graphic = BUTTON_GRAPHIC_ACTIVE(graphic);
982 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
983 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
986 static void initCursor(int ypos, int graphic)
988 drawCursorExt(0, ypos, FALSE, graphic);
991 static void drawCursor(int ypos, boolean active)
993 drawCursorExt(0, ypos, active, -1);
996 static void drawCursorXY(int xpos, int ypos, int graphic)
998 drawCursorExt(xpos, ypos, FALSE, graphic);
1001 static void drawChooseTreeCursor(int ypos, boolean active)
1003 int last_game_status = game_status; /* save current game status */
1005 /* force LEVELS draw offset on artwork setup screen */
1006 game_status = GAME_MODE_LEVELS;
1008 drawCursorExt(0, ypos, active, -1);
1010 game_status = last_game_status; /* restore current game status */
1015 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1016 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1020 static int getPrevlevelButtonPos()
1025 static int getCurrentLevelTextPos()
1027 return (getPrevlevelButtonPos() + 1);
1030 static int getNextLevelButtonPos()
1032 return getPrevlevelButtonPos() + 3 + 1;
1035 static int getLevelRangeTextPos()
1037 return getNextLevelButtonPos() + 1;
1041 int effectiveGameStatus()
1043 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1044 return GAME_MODE_TITLE;
1049 void DrawTitleScreenImage(int nr, boolean initial)
1051 int graphic = getTitleScreenGraphic(nr, initial);
1052 Bitmap *bitmap = graphic_info[graphic].bitmap;
1054 int width = graphic_info[graphic].width;
1055 int height = graphic_info[graphic].height;
1056 int src_x = graphic_info[graphic].src_x;
1057 int src_y = graphic_info[graphic].src_y;
1059 int width = graphic_info[graphic].src_image_width;
1060 int height = graphic_info[graphic].src_image_height;
1061 int src_x = 0, src_y = 0;
1068 if (width > WIN_XSIZE)
1070 /* image width too large for window => center image horizontally */
1071 src_x = (width - WIN_XSIZE) / 2;
1075 if (height > WIN_YSIZE)
1077 /* image height too large for window => center image vertically */
1078 src_y = (height - WIN_YSIZE) / 2;
1082 /* always display title screens centered */
1083 dst_x = (WIN_XSIZE - width) / 2;
1084 dst_y = (WIN_YSIZE - height) / 2;
1086 SetDrawBackgroundMask(REDRAW_ALL);
1087 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1089 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1091 if (DrawingOnBackground(dst_x, dst_y))
1092 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1094 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1096 redraw_mask = REDRAW_ALL;
1098 /* reset fading control values to default config settings */
1102 title = getTitleFading(nr, initial, TRUE);
1107 title.fade_delay_final = title.fade_delay;
1108 title.post_delay_final = title.post_delay;
1109 title.auto_delay_final = title.auto_delay;
1111 /* override default settings with image config settings, if defined */
1112 if (graphic_info[graphic].anim_mode != ANIM_DEFAULT)
1113 title.anim_mode = graphic_info[graphic].anim_mode;
1114 if (graphic_info[graphic].fade_delay > -1)
1115 title.fade_delay = graphic_info[graphic].fade_delay;
1116 if (graphic_info[graphic].post_delay > -1)
1117 title.post_delay = graphic_info[graphic].post_delay;
1118 if (graphic_info[graphic].auto_delay > -1)
1119 title.auto_delay = graphic_info[graphic].auto_delay;
1123 void DrawTitleScreenMessage(int nr, boolean initial)
1125 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1126 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1128 int font_nr = FONT_TEXT_1;
1132 int pad_y = 32 + 14;
1135 int max_chars_per_line;
1136 int max_lines_per_screen;
1138 int last_game_status = game_status; /* save current game status */
1140 if (filename == NULL)
1143 /* force TITLE font on title message screen */
1144 game_status = getTitleMessageGameMode(initial);
1146 /* if chars set to "-1", automatically determine by text and font width */
1147 if (tmi->chars == -1)
1148 tmi->chars = tmi->width / getFontWidth(tmi->font);
1150 tmi->width = tmi->chars * getFontWidth(tmi->font);
1152 /* if lines set to "-1", automatically determine by text and font height */
1153 if (tmi->lines == -1)
1154 tmi->lines = tmi->height / getFontHeight(tmi->font);
1156 tmi->height = tmi->lines * getFontHeight(tmi->font);
1158 SetDrawBackgroundMask(REDRAW_ALL);
1159 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1161 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1164 font_width = getFontWidth(font_nr);
1165 font_height = getFontHeight(font_nr);
1166 max_chars_per_line = (WIN_XSIZE - 2 * pad_x) / font_width;
1167 max_lines_per_screen = (WIN_YSIZE - pad_y) / font_height - 1;
1171 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1172 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1173 tmi->autowrap, tmi->centered, tmi->parse_comments);
1175 DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
1176 max_lines_per_screen, -1, tmi->autowrap, tmi->centered,
1177 tmi->parse_comments);
1180 game_status = last_game_status; /* restore current game status */
1183 void DrawTitleScreen()
1185 KeyboardAutoRepeatOff();
1188 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1191 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1196 boolean CheckTitleScreen(boolean levelset_has_changed)
1198 static boolean show_title_initial = TRUE;
1199 boolean show_titlescreen = FALSE;
1201 /* needed to be able to skip title screen, if no image or message defined */
1202 InitializeTitleControls(show_title_initial);
1204 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1205 show_titlescreen = TRUE;
1207 /* show initial title images and messages only once at program start */
1208 show_title_initial = FALSE;
1210 return (show_titlescreen && num_title_screens > 0);
1213 void DrawMainMenuExt(int redraw_mask, boolean do_fading)
1215 static LevelDirTree *leveldir_last_valid = NULL;
1216 boolean levelset_has_changed = FALSE;
1218 boolean local_team_mode = (!options.network && setup.team_mode);
1219 char *name_text = (local_team_mode ? "Team:" : "Name:");
1220 int name_width, level_width;
1227 /* !!! CHANGE THIS !!! */
1228 title = title_default;
1232 FadeSoundsAndMusic();
1234 KeyboardAutoRepeatOn();
1237 SetDrawDeactivationMask(REDRAW_NONE);
1238 SetDrawBackgroundMask(REDRAW_FIELD);
1240 audio.sound_deactivated = FALSE;
1244 /* needed if last screen was the playing screen, invoked from level editor */
1245 if (level_editor_test_game)
1247 game_status = GAME_MODE_EDITOR;
1253 /* needed if last screen was the editor screen */
1254 UndrawSpecialEditorDoor();
1256 /* needed if last screen was the setup screen and fullscreen state changed */
1257 ToggleFullscreenIfNeeded();
1259 /* leveldir_current may be invalid (level group, parent link) */
1260 if (!validLevelSeries(leveldir_current))
1261 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1263 if (leveldir_current != leveldir_last_valid)
1264 levelset_has_changed = TRUE;
1266 /* store valid level series information */
1267 leveldir_last_valid = leveldir_current;
1269 /* needed if last screen (level choice) changed graphics, sounds or music */
1270 ReloadCustomArtwork(0);
1272 #if defined(TARGET_SDL)
1273 SetDrawtoField(DRAW_BACKBUFFER);
1277 if (levelset_has_changed)
1278 fading = title_default;
1282 if (CheckTitleScreen(levelset_has_changed))
1284 game_status = GAME_MODE_TITLE;
1293 if (setup.show_titlescreen &&
1294 ((levelset_has_changed &&
1295 (graphic_info[IMG_TITLESCREEN_1].bitmap != NULL ||
1296 getLevelSetMessageFilename(1, FALSE) != NULL)) ||
1297 (show_title_initial &&
1298 (graphic_info[IMG_TITLESCREEN_INITIAL_1].bitmap != NULL ||
1299 getLevelSetMessageFilename(1, TRUE) != NULL))))
1301 game_status = GAME_MODE_TITLE;
1309 /* level_nr may have been set to value over handicap with level editor */
1310 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1311 level_nr = leveldir_current->handicap_level;
1313 LoadLevel(level_nr);
1315 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1319 InitializeMainControls();
1322 DrawCursorAndText_Main(-1, FALSE);
1324 for (i = 0; main_controls[i].nr != -1; i++)
1326 struct MenuPosInfo *pos_button = main_controls[i].pos_button;
1327 struct MenuPosInfo *pos_text = main_controls[i].pos_text;
1328 struct MenuPosInfo *pos_input = main_controls[i].pos_input;
1329 char *text = main_controls[i].text;
1330 char *input = main_controls[i].input;
1331 int button_graphic = main_controls[i].button_graphic;
1332 int font_text = main_controls[i].font_text;
1333 int font_input = main_controls[i].font_input;
1335 if (pos_button != NULL)
1336 DrawGraphicThruMaskExt(drawto, mSX + pos_button->x, mSY + pos_button->y,
1339 if (pos_text != NULL && text != NULL)
1340 DrawText(mSX + pos_text->x, mSY + pos_text->y, text, font_text);
1342 if (pos_input != NULL && input != NULL)
1343 DrawText(mSX + pos_input->x, mSY + pos_input->y, input, font_input);
1351 DrawText(mSX + 32, mSY + 2 * 32, name_text, FONT_MENU_1);
1352 DrawText(mSX + 32, mSY + 3 * 32, "Levelset", FONT_MENU_1);
1353 DrawText(mSX + 32, mSY + 4 * 32, "Hall Of Fame", FONT_MENU_1);
1354 DrawText(mSX + 32, mSY + 5 * 32, "Level Creator", FONT_MENU_1);
1355 DrawText(mSX + 32, mSY + 6 * 32, "Info Screen", FONT_MENU_1);
1356 DrawText(mSX + 32, mSY + 7 * 32, "Start Game", FONT_MENU_1);
1357 DrawText(mSX + 32, mSY + 8 * 32, "Setup", FONT_MENU_1);
1358 DrawText(mSX + 32, mSY + 9 * 32, "Quit", FONT_MENU_1);
1360 /* calculated after (possible) reload of custom artwork */
1361 name_width = getTextWidth(name_text, FONT_MENU_1);
1362 level_width = 9 * 32;
1364 DrawText(mSX + 32 + name_width, mSY + 2 * 32, setup.player_name,
1367 DrawText(mSX + getCurrentLevelTextPos() * 32, mSY + 3 * 32,
1368 int2str(level_nr, 3), FONT_VALUE_1);
1371 int text_height = getFontHeight(FONT_TEXT_3);
1372 int xpos = getLevelRangeTextPos() * 32 + 8;
1373 int ypos2 = 3 * 32 + 16;
1374 int ypos1 = ypos2 - text_height;
1376 DrawTextF(mSX - SX + xpos, mSY - SY + ypos1, FONT_TEXT_3,
1377 "%03d", leveldir_current->first_level);
1378 DrawTextF(mSX - SX + xpos, mSY - SY + ypos2, FONT_TEXT_3,
1379 "%03d", leveldir_current->last_level);
1382 for (i = 0; i < 8; i++)
1383 initCursor(i, (i == 1 || i == 4 || i == 6 ? IMG_MENU_BUTTON_ENTER_MENU :
1386 DrawTextSCentered(326, FONT_TITLE_2, PROGRAM_GAME_BY_STRING);
1389 DrawPreviewLevel(TRUE);
1391 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1394 if (TAPE_IS_EMPTY(tape))
1396 DrawCompleteVideoDisplay();
1401 /* create gadgets for main menu screen */
1402 FreeScreenGadgets();
1403 CreateScreenGadgets();
1405 /* map gadgets for main menu screen */
1407 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1409 DrawMaskedBorder(REDRAW_ALL);
1414 else if (fading.anim_mode == ANIM_CROSSFADE)
1415 FadeCross(redraw_mask);
1417 FadeIn(redraw_mask);
1420 FadeIn(redraw_mask);
1426 fading = menu.navigation;
1428 fading = title_default;
1431 SetMouseCursor(CURSOR_DEFAULT);
1435 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1438 void DrawAndFadeInMainMenu(int redraw_mask)
1440 DrawMainMenuExt(redraw_mask, TRUE);
1445 DrawMainMenuExt(REDRAW_ALL, FALSE);
1449 static void gotoTopLevelDir()
1451 /* move upwards to top level directory */
1452 while (leveldir_current->node_parent)
1454 /* write a "path" into level tree for easy navigation to last level */
1455 if (leveldir_current->node_parent->node_group->cl_first == -1)
1457 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1458 int leveldir_pos = posTreeInfo(leveldir_current);
1459 int num_page_entries;
1460 int cl_first, cl_cursor;
1462 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1463 num_page_entries = num_leveldirs;
1465 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1467 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1468 cl_cursor = leveldir_pos - cl_first;
1470 leveldir_current->node_parent->node_group->cl_first = cl_first;
1471 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1474 leveldir_current = leveldir_current->node_parent;
1479 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1481 static unsigned long title_delay = 0;
1482 static int title_screen_nr = 0;
1483 static int last_sound = -1, last_music = -1;
1484 boolean return_to_main_menu = FALSE;
1485 boolean use_fading_main_menu = TRUE;
1488 boolean use_cross_fading = FALSE;
1490 boolean use_cross_fading = !show_title_initial; /* default */
1493 struct TitleControlInfo *tci;
1494 struct TitleFadingInfo fading_next;
1497 if (button == MB_MENU_INITIALIZE)
1500 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1504 int last_game_status = game_status; /* save current game status */
1508 title_screen_nr = 0;
1509 tci = &title_controls[title_screen_nr];
1511 last_sound = SND_UNDEFINED;
1512 last_music = MUS_UNDEFINED;
1515 /* determine number of title screens to display (images and messages) */
1516 InitializeTitleControls();
1519 if (game_status == GAME_MODE_INFO)
1521 if (num_title_screens == 0)
1523 DrawInfoScreen_NotAvailable("Title screen information:",
1524 "No title screen for this level set.");
1526 /* use default settings for fading, but always disable auto delay */
1527 fading = title_default;
1528 fading.auto_delay = -1;
1533 FadeSoundsAndMusic();
1536 if (use_cross_fading)
1537 FadeCrossSaveBackbuffer();
1539 FadeOut(REDRAW_ALL);
1541 FadeOut(REDRAW_ALL);
1546 DrawTitleScreenImage(tci->local_nr, tci->initial);
1548 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1550 fading = getTitleFading(tci);
1553 sound = getTitleSound(tci);
1554 music = getTitleMusic(tci);
1556 if (sound != last_sound)
1557 PlayMenuSoundExt(sound);
1558 if (music != last_music)
1559 PlayMenuMusicExt(music);
1565 SetMouseCursor(CURSOR_NONE);
1568 if (use_cross_fading)
1569 FadeCross(REDRAW_ALL);
1576 DelayReached(&title_delay, 0); /* reset delay counter */
1581 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1582 button = MB_MENU_CHOICE;
1584 if (button == MB_MENU_LEAVE)
1586 return_to_main_menu = TRUE;
1587 use_fading_main_menu = FALSE;
1589 else if (button == MB_MENU_CHOICE)
1592 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1595 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1597 FadeOut(REDRAW_FIELD);
1599 info_mode = INFO_MODE_MAIN;
1600 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1606 tci = &title_controls[title_screen_nr];
1608 if (title_screen_nr < num_title_screens)
1612 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1619 graphic_info[getTitleScreenGraphic(tci->local_nr,
1620 tci->initial)].anim_mode;
1622 anim_mode = ANIM_FADE; /* ??? */
1624 use_cross_fading = (anim_mode == ANIM_FADE ? FALSE :
1625 anim_mode == ANIM_CROSSFADE ? TRUE :
1629 sound = getTitleSound(tci);
1630 music = getTitleMusic(tci);
1632 if (sound == SND_UNDEFINED || sound != last_sound)
1634 if (music == MUS_UNDEFINED || music != last_music)
1637 if (use_cross_fading)
1638 FadeCrossSaveBackbuffer();
1640 FadeOut(REDRAW_ALL);
1643 DrawTitleScreenImage(tci->local_nr, tci->initial);
1645 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1647 fading_next = getTitleFading(tci);
1650 sound = getTitleSound(tci);
1651 music = getTitleMusic(tci);
1653 if (sound != last_sound)
1654 PlayMenuSoundExt(sound);
1655 if (music != last_music)
1656 PlayMenuMusicExt(music);
1662 /* last screen already faded out, next screen has no animation */
1663 if (!use_cross_fading && fading_next.anim_mode == ANIM_NONE)
1664 fading = fading_next;
1666 if (use_cross_fading)
1667 FadeCross(REDRAW_ALL);
1671 fading = fading_next;
1673 DelayReached(&title_delay, 0); /* reset delay counter */
1677 FadeSoundsAndMusic();
1682 boolean use_cross_fading = (fading.anim_mode == ANIM_CROSSFADE);
1685 if (use_cross_fading)
1686 FadeCrossSaveBackbuffer();
1688 FadeOut(REDRAW_ALL);
1691 FadeOut(REDRAW_ALL);
1694 return_to_main_menu = TRUE;
1698 if (return_to_main_menu)
1702 SetMouseCursor(CURSOR_DEFAULT);
1704 if (game_status == GAME_MODE_INFO)
1706 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1708 info_mode = INFO_MODE_MAIN;
1709 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1711 else /* default: return to main menu */
1713 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1715 game_status = GAME_MODE_MAIN;
1716 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1721 void HandleMainMenu_SelectLevel(int step, int direction)
1723 int old_level_nr = level_nr;
1726 new_level_nr = old_level_nr + step * direction;
1727 if (new_level_nr < leveldir_current->first_level)
1728 new_level_nr = leveldir_current->first_level;
1729 if (new_level_nr > leveldir_current->last_level)
1730 new_level_nr = leveldir_current->last_level;
1732 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1734 /* skipping levels is only allowed when trying to skip single level */
1735 if (setup.skip_levels && step == 1 &&
1736 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1738 leveldir_current->handicap_level++;
1739 SaveLevelSetup_SeriesInfo();
1742 new_level_nr = leveldir_current->handicap_level;
1745 if (new_level_nr != old_level_nr)
1747 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1749 PlaySound(SND_MENU_ITEM_SELECTING);
1751 level_nr = new_level_nr;
1754 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1755 int2str(level_nr, 3), mci->pos_text->font);
1757 DrawText(mSX + 11 * 32, mSY + 3 * 32, int2str(level_nr, 3), FONT_VALUE_1);
1760 LoadLevel(level_nr);
1761 DrawPreviewLevel(TRUE);
1765 DrawCompleteVideoDisplay();
1767 /* needed because DrawPreviewLevel() takes some time */
1775 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1777 static int choice = MAIN_CONTROL_GAME;
1781 if (button == MB_MENU_INITIALIZE)
1783 DrawCursorAndText_Main(choice, TRUE);
1788 if (mx || my) /* mouse input */
1792 for (i = 0; main_controls[i].nr != -1; i++)
1794 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1795 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1796 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1798 pos = main_controls[i].nr;
1804 else if (dx || dy) /* keyboard input */
1806 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1807 choice == MAIN_CONTROL_SETUP))
1808 button = MB_MENU_CHOICE;
1813 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1815 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1817 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1823 PlaySound(SND_MENU_ITEM_ACTIVATING);
1825 DrawCursorAndText_Main(choice, FALSE);
1826 DrawCursorAndText_Main(pos, TRUE);
1833 PlaySound(SND_MENU_ITEM_SELECTING);
1835 if (pos == MAIN_CONTROL_NAME)
1837 game_status = GAME_MODE_PSEUDO_TYPENAME;
1839 HandleTypeName(strlen(setup.player_name), 0);
1841 else if (pos == MAIN_CONTROL_LEVELS)
1845 game_status = GAME_MODE_LEVELS;
1847 SaveLevelSetup_LastSeries();
1848 SaveLevelSetup_SeriesInfo();
1857 else if (pos == MAIN_CONTROL_SCORES)
1859 game_status = GAME_MODE_SCORES;
1863 else if (pos == MAIN_CONTROL_EDITOR)
1865 if (leveldir_current->readonly &&
1866 !strEqual(setup.player_name, "Artsoft"))
1867 Request("This level is read only !", REQ_CONFIRM);
1869 game_status = GAME_MODE_EDITOR;
1873 else if (pos == MAIN_CONTROL_INFO)
1875 game_status = GAME_MODE_INFO;
1876 info_mode = INFO_MODE_MAIN;
1880 else if (pos == MAIN_CONTROL_GAME)
1882 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
1884 else if (pos == MAIN_CONTROL_SETUP)
1886 game_status = GAME_MODE_SETUP;
1887 setup_mode = SETUP_MODE_MAIN;
1891 else if (pos == MAIN_CONTROL_QUIT)
1893 SaveLevelSetup_LastSeries();
1894 SaveLevelSetup_SeriesInfo();
1896 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1897 game_status = GAME_MODE_QUIT;
1902 if (game_status == GAME_MODE_MAIN)
1904 DrawPreviewLevel(FALSE);
1911 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1913 static int choice = 5;
1917 if (button == MB_MENU_INITIALIZE)
1919 drawCursor(choice, TRUE);
1924 if (mx || my) /* mouse input */
1926 x = (mx - mSX) / 32;
1927 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
1929 else if (dx || dy) /* keyboard input */
1931 if (dx && choice == 1)
1932 x = (dx < 0 ? 10 : 14);
1935 if (choice == 4 || choice == 6)
1936 button = MB_MENU_CHOICE;
1942 if (y == 1 && dx != 0 && button)
1944 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1946 else if (IN_VIS_FIELD(x, y) &&
1947 y >= 0 && y <= 7 && (y != 1 || x < 10))
1953 drawCursor(choice, FALSE);
1954 drawCursor(y, TRUE);
1963 game_status = GAME_MODE_PSEUDO_TYPENAME;
1964 HandleTypeName(strlen(setup.player_name), 0);
1970 game_status = GAME_MODE_LEVELS;
1971 SaveLevelSetup_LastSeries();
1972 SaveLevelSetup_SeriesInfo();
1983 game_status = GAME_MODE_SCORES;
1988 if (leveldir_current->readonly &&
1989 !strEqual(setup.player_name, "Artsoft"))
1990 Request("This level is read only !", REQ_CONFIRM);
1991 game_status = GAME_MODE_EDITOR;
1996 game_status = GAME_MODE_INFO;
1997 info_mode = INFO_MODE_MAIN;
2002 StartGameActions(options.network, setup.autorecord, NEW_RANDOMIZE);
2006 game_status = GAME_MODE_SETUP;
2007 setup_mode = SETUP_MODE_MAIN;
2013 SaveLevelSetup_LastSeries();
2014 SaveLevelSetup_SeriesInfo();
2016 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
2017 game_status = GAME_MODE_QUIT;
2022 if (game_status == GAME_MODE_MAIN)
2024 DrawPreviewLevel(FALSE);
2032 /* ========================================================================= */
2033 /* info screen functions */
2034 /* ========================================================================= */
2036 static struct TokenInfo *info_info;
2037 static int num_info_info;
2039 static void execInfoTitleScreen()
2041 info_mode = INFO_MODE_TITLE;
2045 static void execInfoElements()
2047 info_mode = INFO_MODE_ELEMENTS;
2051 static void execInfoMusic()
2053 info_mode = INFO_MODE_MUSIC;
2057 static void execInfoCredits()
2059 info_mode = INFO_MODE_CREDITS;
2063 static void execInfoProgram()
2065 info_mode = INFO_MODE_PROGRAM;
2069 static void execInfoVersion()
2071 info_mode = INFO_MODE_VERSION;
2075 static void execInfoLevelSet()
2077 info_mode = INFO_MODE_LEVELSET;
2081 static void execExitInfo()
2083 game_status = GAME_MODE_MAIN;
2087 static struct TokenInfo info_info_main[] =
2089 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2090 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2091 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2092 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2093 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2094 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2095 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2096 { TYPE_EMPTY, NULL, "" },
2097 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2102 static void DrawCursorAndText_Info(int pos, boolean active)
2104 int xpos = MENU_SCREEN_START_XPOS;
2105 int ypos = MENU_SCREEN_START_YPOS + pos;
2106 int font_nr = FONT_MENU_1;
2109 font_nr = FONT_ACTIVE(font_nr);
2111 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2113 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2114 drawCursor(pos, active);
2117 static void DrawInfoScreen_Main(int redraw_mask, boolean do_fading)
2122 CloseDoor(DOOR_CLOSE_2);
2126 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2128 info_info = info_info_main;
2131 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2134 int xpos = MENU_SCREEN_START_XPOS;
2135 int ypos = MENU_SCREEN_START_YPOS + i;
2136 int font_nr = FONT_MENU_1;
2139 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2140 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2141 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2142 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2143 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2144 initCursor(i, IMG_MENU_BUTTON);
2147 DrawCursorAndText_Info(i, FALSE);
2149 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[i].text, font_nr);
2155 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2160 DrawMaskedBorder(REDRAW_ALL);
2165 else if (fading.anim_mode == ANIM_CROSSFADE)
2166 FadeCross(redraw_mask);
2168 FadeIn(redraw_mask);
2171 FadeIn(redraw_mask);
2179 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2181 static int choice_store[MAX_INFO_MODES];
2182 int choice = choice_store[info_mode]; /* always starts with 0 */
2186 if (button == MB_MENU_INITIALIZE)
2188 /* advance to first valid menu entry */
2189 while (choice < num_info_info &&
2190 info_info[choice].type & TYPE_SKIP_ENTRY)
2192 choice_store[info_mode] = choice;
2195 DrawCursorAndText_Info(choice, TRUE);
2197 drawCursor(choice, TRUE);
2202 else if (button == MB_MENU_LEAVE)
2204 for (y = 0; y < num_info_info; y++)
2206 if (info_info[y].type & TYPE_LEAVE_MENU)
2208 void (*menu_callback_function)(void) = info_info[y].value;
2210 menu_callback_function();
2212 break; /* absolutely needed because function changes 'info_info'! */
2219 if (mx || my) /* mouse input */
2221 x = (mx - mSX) / 32;
2222 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2224 else if (dx || dy) /* keyboard input */
2228 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2230 if (info_info[choice].type & menu_navigation_type ||
2231 info_info[choice].type & TYPE_ENTER_SCREEN ||
2232 info_info[choice].type & TYPE_BOOLEAN_STYLE)
2233 button = MB_MENU_CHOICE;
2238 /* jump to next non-empty menu entry (up or down) */
2239 while (y > 0 && y < num_info_info - 1 &&
2240 info_info[y].type & TYPE_SKIP_ENTRY)
2244 if (IN_VIS_FIELD(x, y) &&
2245 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2251 PlaySound(SND_MENU_ITEM_ACTIVATING);
2254 DrawCursorAndText_Info(choice, FALSE);
2255 DrawCursorAndText_Info(y, TRUE);
2257 drawCursor(choice, FALSE);
2258 drawCursor(y, TRUE);
2261 choice = choice_store[info_mode] = y;
2264 else if (!(info_info[y].type & TYPE_GHOSTED))
2266 PlaySound(SND_MENU_ITEM_SELECTING);
2268 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2270 void (*menu_callback_function)(void) = info_info[choice].value;
2272 menu_callback_function();
2278 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2281 int ystart1 = mSY - SY + 100;
2282 int ystart2 = mSY - SY + 150;
2283 int ybottom = mSY - SY + SYSIZE - 20;
2287 int ybottom = SYSIZE - 20;
2290 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2292 FadeOut(REDRAW_FIELD);
2297 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2298 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2300 DrawTextSCentered(ybottom, FONT_TEXT_4,
2301 "Press any key or button for info menu");
2303 FadeIn(REDRAW_FIELD);
2306 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2308 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2309 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2310 int xstart = mSX + 16;
2311 int ystart1 = mSY - SY + 100;
2312 int ystart2 = mSY + 64 + 2 * 32;
2313 int ybottom = mSY - SY + SYSIZE - 20;
2314 int ystep = TILEY + 4;
2315 int element, action, direction;
2323 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2324 infoscreen_step[i] = infoscreen_frame[i] = 0;
2329 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2331 DrawTextSCentered(ybottom, FONT_TEXT_4,
2332 "Press any key or button for next page");
2338 while (helpanim_info[j].element != HELPANIM_LIST_END)
2340 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2345 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2354 j += infoscreen_step[i - start];
2356 element = helpanim_info[j].element;
2357 action = helpanim_info[j].action;
2358 direction = helpanim_info[j].direction;
2361 element = EL_UNKNOWN;
2363 if (action != -1 && direction != -1)
2364 graphic = el_act_dir2img(element, action, direction);
2365 else if (action != -1)
2366 graphic = el_act2img(element, action);
2367 else if (direction != -1)
2368 graphic = el_dir2img(element, direction);
2370 graphic = el2img(element);
2372 delay = helpanim_info[j++].delay;
2377 if (infoscreen_frame[i - start] == 0)
2380 infoscreen_frame[i - start] = delay - 1;
2384 sync_frame = delay - infoscreen_frame[i - start];
2385 infoscreen_frame[i - start]--;
2388 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2390 if (!infoscreen_frame[i - start])
2391 infoscreen_step[i - start] = 0;
2395 if (!infoscreen_frame[i - start])
2396 infoscreen_step[i - start]++;
2397 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2403 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2405 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2406 graphic, sync_frame, USE_MASKING);
2409 DrawInfoScreen_HelpText(element, action, direction, i - start);
2414 redraw_mask |= REDRAW_FIELD;
2419 static char *getHelpText(int element, int action, int direction)
2421 char token[MAX_LINE_LEN];
2423 strcpy(token, element_info[element].token_name);
2426 strcat(token, element_action_info[action].suffix);
2428 if (direction != -1)
2429 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2431 return getHashEntry(helptext_info, token);
2434 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2437 int font_nr = FONT_INFO_ELEMENTS;
2439 int font_nr = FONT_LEVEL_NUMBER;
2441 int font_width = getFontWidth(font_nr);
2442 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2443 int sy = mSY + 65 + 2 * 32 + 1;
2444 int ystep = TILEY + 4;
2445 int pad_x = sx - SX;
2446 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2447 int max_lines_per_text = 2;
2450 if (action != -1 && direction != -1) /* element.action.direction */
2451 text = getHelpText(element, action, direction);
2453 if (text == NULL && action != -1) /* element.action */
2454 text = getHelpText(element, action, -1);
2456 if (text == NULL && direction != -1) /* element.direction */
2457 text = getHelpText(element, -1, direction);
2459 if (text == NULL) /* base element */
2460 text = getHelpText(element, -1, -1);
2462 if (text == NULL) /* not found */
2463 text = "No description available";
2465 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2466 sy += getFontHeight(font_nr) / 2;
2469 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2470 max_chars_per_line, -1, max_lines_per_text, -1,
2471 TRUE, FALSE, FALSE);
2473 DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr,
2474 max_chars_per_line, max_lines_per_text);
2478 void DrawInfoScreen_TitleScreen()
2483 void HandleInfoScreen_TitleScreen(int button)
2485 HandleTitleScreen(0, 0, 0, 0, button);
2488 void DrawInfoScreen_Elements()
2490 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2492 FadeOut(REDRAW_FIELD);
2497 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2499 FadeIn(REDRAW_FIELD);
2504 void HandleInfoScreen_Elements(int button)
2506 static unsigned long info_delay = 0;
2507 static int num_anims;
2508 static int num_pages;
2510 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2513 if (button == MB_MENU_INITIALIZE)
2515 boolean new_element = TRUE;
2519 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2521 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2523 else if (new_element)
2526 new_element = FALSE;
2530 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2534 if (button == MB_MENU_LEAVE)
2536 PlaySound(SND_MENU_ITEM_SELECTING);
2538 info_mode = INFO_MODE_MAIN;
2543 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2545 if (button != MB_MENU_INITIALIZE)
2547 PlaySound(SND_MENU_ITEM_SELECTING);
2552 if (page >= num_pages)
2554 FadeSoundsAndMusic();
2555 FadeOut(REDRAW_FIELD);
2557 info_mode = INFO_MODE_MAIN;
2558 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2563 if (button != MB_MENU_INITIALIZE)
2564 FadeCrossSaveBackbuffer();
2566 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2568 if (button != MB_MENU_INITIALIZE)
2569 FadeCross(REDRAW_FIELD);
2573 if (DelayReached(&info_delay, GameFrameDelay))
2574 if (page < num_pages)
2575 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2577 PlayMenuSoundIfLoop();
2581 void DrawInfoScreen_Music()
2583 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2585 FadeOut(REDRAW_FIELD);
2592 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2594 FadeIn(REDRAW_FIELD);
2597 void HandleInfoScreen_Music(int button)
2599 static struct MusicFileInfo *list = NULL;
2600 int ystart1 = mSY - SY + 100;
2601 int ystart2 = mSY - SY + 150;
2602 int ybottom = mSY - SY + SYSIZE - 20;
2605 if (button == MB_MENU_INITIALIZE)
2607 list = music_file_info;
2611 FadeSoundsAndMusic();
2616 DrawTextSCentered(ystart1, FONT_TEXT_1,
2617 "No music info for this level set.");
2619 DrawTextSCentered(ybottom, FONT_TEXT_4,
2620 "Press any key or button for info menu");
2626 if (button == MB_MENU_LEAVE)
2628 PlaySound(SND_MENU_ITEM_SELECTING);
2630 FadeSoundsAndMusic();
2632 info_mode = INFO_MODE_MAIN;
2637 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2641 if (button != MB_MENU_INITIALIZE)
2643 PlaySound(SND_MENU_ITEM_SELECTING);
2651 FadeSoundsAndMusic();
2652 FadeOut(REDRAW_FIELD);
2654 info_mode = INFO_MODE_MAIN;
2655 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2660 FadeSoundsAndMusic();
2662 if (button != MB_MENU_INITIALIZE)
2663 FadeCrossSaveBackbuffer();
2670 int sound = list->music;
2672 if (sound_info[sound].loop)
2673 PlaySoundLoop(sound);
2677 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2681 PlayMusic(list->music);
2683 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2686 if (!strEqual(list->title, UNKNOWN_NAME))
2688 if (!strEqual(list->title_header, UNKNOWN_NAME))
2689 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2691 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2694 if (!strEqual(list->artist, UNKNOWN_NAME))
2696 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2697 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2699 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2701 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2704 if (!strEqual(list->album, UNKNOWN_NAME))
2706 if (!strEqual(list->album_header, UNKNOWN_NAME))
2707 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2709 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2711 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2714 if (!strEqual(list->year, UNKNOWN_NAME))
2716 if (!strEqual(list->year_header, UNKNOWN_NAME))
2717 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2719 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2721 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2724 DrawTextSCentered(ybottom, FONT_TEXT_4,
2725 "Press any key or button for next page");
2727 if (button != MB_MENU_INITIALIZE)
2728 FadeCross(REDRAW_FIELD);
2731 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2732 PlaySoundLoop(list->music);
2735 static boolean DrawInfoScreen_CreditsScreen(int screen_nr)
2737 int ystart1 = mSY - SY + 100;
2738 int ystart2 = mSY - SY + 150;
2739 int ybottom = mSY - SY + SYSIZE - 20;
2748 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2752 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2753 "Special thanks to");
2754 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2756 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2758 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2759 "\"Boulder Dash\"");
2760 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2762 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2764 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2766 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2767 "First Star Software");
2769 else if (screen_nr == 1)
2771 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2772 "Special thanks to");
2773 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2774 "Klaus Heinz & Volker Wertich");
2775 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2777 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2778 "\"Emerald Mine\"");
2779 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2781 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2783 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2785 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2788 else if (screen_nr == 2)
2790 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2791 "Special thanks to");
2792 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2793 "Michael Stopp & Philip Jespersen");
2794 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2796 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2798 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2800 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2802 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2804 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2805 "Digital Integration");
2807 else if (screen_nr == 3)
2809 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2810 "Special thanks to");
2811 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2812 "Hiroyuki Imabayashi");
2813 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2815 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2817 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2819 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2821 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2823 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2826 else if (screen_nr == 4)
2828 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2829 "Special thanks to");
2830 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2832 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2834 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2835 "Jürgen Bonhagen");
2836 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2837 "for the continuous creation");
2838 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2839 "of outstanding level sets");
2841 else if (screen_nr == 5)
2843 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2845 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2847 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2848 "for ideas and inspiration by");
2849 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2852 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2854 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2856 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2857 "for ideas and inspiration by");
2858 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2861 else if (screen_nr == 6)
2863 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2865 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2867 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2868 "for the new Emerald Mine engine");
2870 else if (screen_nr == 7)
2872 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2874 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2876 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2877 "for the initial DOS port");
2879 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2881 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2883 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2884 "for some additional toons");
2886 else if (screen_nr == 8)
2888 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2889 "And not to forget:");
2890 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2892 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2893 "All those who contributed");
2894 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2895 "levels to this game");
2896 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2906 DrawTextSCentered(ybottom, FONT_TEXT_4,
2907 "Press any key or button for next page");
2912 void DrawInfoScreen_Credits()
2914 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2916 FadeSoundsAndMusic();
2918 FadeOut(REDRAW_FIELD);
2920 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2922 FadeIn(REDRAW_FIELD);
2925 void HandleInfoScreen_Credits(int button)
2927 static int screen_nr = 0;
2929 if (button == MB_MENU_INITIALIZE)
2933 DrawInfoScreen_CreditsScreen(screen_nr);
2935 else if (button == MB_MENU_LEAVE)
2937 PlaySound(SND_MENU_ITEM_SELECTING);
2939 info_mode = INFO_MODE_MAIN;
2944 else if (button == MB_MENU_CHOICE)
2946 boolean show_screen;
2948 PlaySound(SND_MENU_ITEM_SELECTING);
2952 FadeCrossSaveBackbuffer();
2954 show_screen = DrawInfoScreen_CreditsScreen(screen_nr);
2958 FadeCross(REDRAW_FIELD);
2962 FadeSoundsAndMusic();
2963 FadeOut(REDRAW_FIELD);
2965 info_mode = INFO_MODE_MAIN;
2966 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2971 PlayMenuSoundIfLoop();
2975 void DrawInfoScreen_Program()
2977 int ystart1 = mSY - SY + 100;
2978 int ystart2 = mSY - SY + 150;
2979 int ybottom = mSY - SY + SYSIZE - 20;
2982 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2984 FadeOut(REDRAW_FIELD);
2989 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2991 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2992 "This game is Freeware!");
2993 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2994 "If you like it, send e-mail to:");
2995 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2996 PROGRAM_EMAIL_STRING);
2997 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2998 "or SnailMail to:");
2999 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3001 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3002 "Detmolder Strasse 189");
3003 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3005 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3007 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3008 "More information and levels:");
3009 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3010 PROGRAM_WEBSITE_STRING);
3011 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3012 "If you have created new levels,");
3013 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3014 "send them to me to include them!");
3015 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3018 DrawTextSCentered(ybottom, FONT_TEXT_4,
3019 "Press any key or button for info menu");
3021 FadeIn(REDRAW_FIELD);
3024 void HandleInfoScreen_Program(int button)
3026 if (button == MB_MENU_LEAVE)
3028 PlaySound(SND_MENU_ITEM_SELECTING);
3030 info_mode = INFO_MODE_MAIN;
3035 else if (button == MB_MENU_CHOICE)
3037 PlaySound(SND_MENU_ITEM_SELECTING);
3039 FadeSoundsAndMusic();
3040 FadeOut(REDRAW_FIELD);
3042 info_mode = INFO_MODE_MAIN;
3043 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3047 PlayMenuSoundIfLoop();
3051 void DrawInfoScreen_Version()
3053 int font_header = FONT_TEXT_3;
3054 int font_text = FONT_TEXT_2;
3055 int xstep = getFontWidth(font_text);
3056 int ystep = getFontHeight(font_text);
3057 int ystart1 = mSY - SY + 100;
3058 int ystart2 = mSY - SY + 150;
3059 int ybottom = mSY - SY + SYSIZE - 20;
3060 int xstart1 = mSX + 2 * xstep;
3061 int xstart2 = mSX + 19 * xstep;
3062 #if defined(TARGET_SDL)
3063 int xstart3 = mSX + 29 * xstep;
3064 SDL_version sdl_version_compiled;
3065 const SDL_version *sdl_version_linked;
3066 int driver_name_len = 8;
3067 char driver_name[driver_name_len];
3070 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3072 FadeOut(REDRAW_FIELD);
3077 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3079 DrawTextF(xstart1, ystart2, font_header, "Name");
3080 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3083 DrawTextF(xstart1, ystart2, font_header, "Version");
3084 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3087 DrawTextF(xstart1, ystart2, font_header, "Platform");
3088 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3091 DrawTextF(xstart1, ystart2, font_header, "Target");
3092 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3095 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3096 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3098 #if defined(TARGET_SDL)
3099 ystart2 += 3 * ystep;
3100 DrawTextF(xstart1, ystart2, font_header, "Library");
3101 DrawTextF(xstart2, ystart2, font_header, "compiled");
3102 DrawTextF(xstart3, ystart2, font_header, "linked");
3104 SDL_VERSION(&sdl_version_compiled);
3105 sdl_version_linked = SDL_Linked_Version();
3107 ystart2 += 2 * ystep;
3108 DrawTextF(xstart1, ystart2, font_text, "SDL");
3109 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3110 sdl_version_compiled.major,
3111 sdl_version_compiled.minor,
3112 sdl_version_compiled.patch);
3113 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3114 sdl_version_linked->major,
3115 sdl_version_linked->minor,
3116 sdl_version_linked->patch);
3118 SDL_IMAGE_VERSION(&sdl_version_compiled);
3119 sdl_version_linked = IMG_Linked_Version();
3122 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3123 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3124 sdl_version_compiled.major,
3125 sdl_version_compiled.minor,
3126 sdl_version_compiled.patch);
3127 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3128 sdl_version_linked->major,
3129 sdl_version_linked->minor,
3130 sdl_version_linked->patch);
3132 SDL_MIXER_VERSION(&sdl_version_compiled);
3133 sdl_version_linked = Mix_Linked_Version();
3136 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3137 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3138 sdl_version_compiled.major,
3139 sdl_version_compiled.minor,
3140 sdl_version_compiled.patch);
3141 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3142 sdl_version_linked->major,
3143 sdl_version_linked->minor,
3144 sdl_version_linked->patch);
3146 SDL_NET_VERSION(&sdl_version_compiled);
3147 sdl_version_linked = SDLNet_Linked_Version();
3150 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3151 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3152 sdl_version_compiled.major,
3153 sdl_version_compiled.minor,
3154 sdl_version_compiled.patch);
3155 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3156 sdl_version_linked->major,
3157 sdl_version_linked->minor,
3158 sdl_version_linked->patch);
3160 ystart2 += 3 * ystep;
3161 DrawTextF(xstart1, ystart2, font_header, "Driver");
3162 DrawTextF(xstart2, ystart2, font_header, "Requested");
3163 DrawTextF(xstart3, ystart2, font_header, "Used");
3165 SDL_VideoDriverName(driver_name, driver_name_len);
3167 ystart2 += 2 * ystep;
3168 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3169 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3170 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3172 SDL_AudioDriverName(driver_name, driver_name_len);
3175 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3176 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3177 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3180 DrawTextSCentered(ybottom, FONT_TEXT_4,
3181 "Press any key or button for info menu");
3183 FadeIn(REDRAW_FIELD);
3186 void HandleInfoScreen_Version(int button)
3188 if (button == MB_MENU_LEAVE)
3190 PlaySound(SND_MENU_ITEM_SELECTING);
3192 info_mode = INFO_MODE_MAIN;
3197 else if (button == MB_MENU_CHOICE)
3199 PlaySound(SND_MENU_ITEM_SELECTING);
3201 FadeSoundsAndMusic();
3202 FadeOut(REDRAW_FIELD);
3204 info_mode = INFO_MODE_MAIN;
3205 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3209 PlayMenuSoundIfLoop();
3213 void DrawInfoScreen_LevelSet()
3215 struct TitleMessageInfo *tmi = &readme;
3216 char *filename = getLevelSetInfoFilename();
3218 /* if chars set to "-1", automatically determine by text and font width */
3219 if (tmi->chars == -1)
3220 tmi->chars = tmi->width / getFontWidth(tmi->font);
3222 tmi->width = tmi->chars * getFontWidth(tmi->font);
3224 /* if lines set to "-1", automatically determine by text and font height */
3225 if (tmi->lines == -1)
3226 tmi->lines = tmi->height / getFontHeight(tmi->font);
3228 tmi->height = tmi->lines * getFontHeight(tmi->font);
3230 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3232 FadeOut(REDRAW_FIELD);
3237 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3239 if (filename != NULL)
3240 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3241 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3242 tmi->autowrap, tmi->centered, tmi->parse_comments);
3244 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3245 "No information for this level set.");
3247 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3248 "Press any key or button for info menu");
3250 FadeIn(REDRAW_FIELD);
3253 void HandleInfoScreen_LevelSet(int button)
3255 if (button == MB_MENU_LEAVE)
3257 PlaySound(SND_MENU_ITEM_SELECTING);
3259 info_mode = INFO_MODE_MAIN;
3264 else if (button == MB_MENU_CHOICE)
3266 PlaySound(SND_MENU_ITEM_SELECTING);
3268 FadeSoundsAndMusic();
3269 FadeOut(REDRAW_FIELD);
3271 info_mode = INFO_MODE_MAIN;
3272 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3276 PlayMenuSoundIfLoop();
3280 static void DrawInfoScreenExt(int redraw_mask, boolean do_fading)
3282 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3284 if (info_mode == INFO_MODE_TITLE)
3285 DrawInfoScreen_TitleScreen();
3286 else if (info_mode == INFO_MODE_ELEMENTS)
3287 DrawInfoScreen_Elements();
3288 else if (info_mode == INFO_MODE_MUSIC)
3289 DrawInfoScreen_Music();
3290 else if (info_mode == INFO_MODE_CREDITS)
3291 DrawInfoScreen_Credits();
3292 else if (info_mode == INFO_MODE_PROGRAM)
3293 DrawInfoScreen_Program();
3294 else if (info_mode == INFO_MODE_VERSION)
3295 DrawInfoScreen_Version();
3296 else if (info_mode == INFO_MODE_LEVELSET)
3297 DrawInfoScreen_LevelSet();
3299 DrawInfoScreen_Main(redraw_mask, do_fading);
3301 if (info_mode != INFO_MODE_MAIN &&
3302 info_mode != INFO_MODE_TITLE &&
3303 info_mode != INFO_MODE_MUSIC)
3310 void DrawAndFadeInInfoScreen(int redraw_mask)
3312 DrawInfoScreenExt(redraw_mask, TRUE);
3315 void DrawInfoScreen()
3317 fading = menu.destination;
3319 DrawInfoScreenExt(REDRAW_ALL, FALSE);
3322 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3324 if (info_mode == INFO_MODE_TITLE)
3325 HandleInfoScreen_TitleScreen(button);
3326 else if (info_mode == INFO_MODE_ELEMENTS)
3327 HandleInfoScreen_Elements(button);
3328 else if (info_mode == INFO_MODE_MUSIC)
3329 HandleInfoScreen_Music(button);
3330 else if (info_mode == INFO_MODE_CREDITS)
3331 HandleInfoScreen_Credits(button);
3332 else if (info_mode == INFO_MODE_PROGRAM)
3333 HandleInfoScreen_Program(button);
3334 else if (info_mode == INFO_MODE_VERSION)
3335 HandleInfoScreen_Version(button);
3336 else if (info_mode == INFO_MODE_LEVELSET)
3337 HandleInfoScreen_LevelSet(button);
3339 HandleInfoScreen_Main(mx, my, dx, dy, button);
3345 /* ========================================================================= */
3346 /* type name functions */
3347 /* ========================================================================= */
3349 void HandleTypeName(int newxpos, Key key)
3351 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3352 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3354 struct TextPosInfo *pos = mci->pos_input;
3355 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3356 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3359 static int xpos = 0;
3361 static int xpos = 0, ypos = 2;
3363 int font_nr = pos->font;
3364 int font_active_nr = FONT_ACTIVE(font_nr);
3365 int font_width = getFontWidth(font_active_nr);
3368 int startx = mSX + mci->pos_input->x;
3369 int starty = mSY + mci->pos_input->y;
3372 int name_width = getFontWidth(FONT_MENU_1) * strlen("Name:");
3373 int startx = mSX + 32 + name_width;
3374 int starty = mSY + ypos * 32;
3376 char key_char = getValidConfigValueChar(getCharFromKey(key));
3377 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3378 boolean is_active = TRUE;
3380 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3384 strcpy(last_player_name, setup.player_name);
3389 /* add one character width for added cursor character */
3390 pos->width += font_width;
3391 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3393 DrawText(startx, starty, setup.player_name, font_active_nr);
3394 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3397 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3399 setup.player_name[xpos] = key_char;
3400 setup.player_name[xpos + 1] = 0;
3405 /* add one character width for added name text character */
3406 pos->width += font_width;
3407 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3409 DrawText(startx, starty, setup.player_name, font_active_nr);
3410 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3413 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3417 setup.player_name[xpos] = 0;
3420 /* remove one character width for removed name text character */
3421 pos->width -= font_width;
3422 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3424 DrawText(startx, starty, setup.player_name, font_active_nr);
3425 DrawText(startx + xpos * font_width, starty, "_ ", font_active_nr);
3428 else if (key == KSYM_Return && xpos > 0)
3431 /* remove one character width for removed cursor text character */
3432 pos->width -= font_width;
3433 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3435 DrawText(startx, starty, setup.player_name, font_nr);
3436 DrawText(startx + xpos * font_width, starty, " ", font_active_nr);
3443 game_status = GAME_MODE_MAIN;
3445 else if (key == KSYM_Escape)
3447 strcpy(setup.player_name, last_player_name);
3451 game_status = GAME_MODE_MAIN;
3456 pos->width = (strlen(setup.player_name) + 1) * font_width;
3457 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3459 DrawText(startx, starty, setup.player_name, font_active_nr);
3460 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3464 pos->width = strlen(setup.player_name) * font_width;
3465 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3467 DrawText(startx, starty, setup.player_name, font_nr);
3472 /* ========================================================================= */
3473 /* tree menu functions */
3474 /* ========================================================================= */
3476 static void DrawChooseTree(TreeInfo **ti_ptr)
3480 FreeScreenGadgets();
3481 CreateScreenGadgets();
3483 CloseDoor(DOOR_CLOSE_2);
3487 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3488 MapScreenTreeGadgets(*ti_ptr);
3494 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3496 struct GadgetInfo *gi = screen_gadget[id];
3497 int items_max, items_visible, item_position;
3499 items_max = numTreeInfoInGroup(ti);
3500 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3501 item_position = first_entry;
3503 if (item_position > items_max - items_visible)
3504 item_position = items_max - items_visible;
3506 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3507 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3508 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3511 static void drawChooseTreeList(int first_entry, int num_page_entries,
3515 char *title_string = NULL;
3516 int yoffset_sets = MENU_TITLE1_YPOS;
3517 int yoffset_setup = 16;
3518 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3520 int last_game_status = game_status; /* save current game status */
3522 title_string = ti->infotext;
3524 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3526 /* force LEVELS font on artwork setup screen */
3527 game_status = GAME_MODE_LEVELS;
3530 /* clear tree list area, but not title or scrollbar */
3531 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3532 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3533 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3535 /* clear tree list area, but not title or scrollbar */
3536 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3537 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3538 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3541 for (i = 0; i < num_page_entries; i++)
3543 TreeInfo *node, *node_first;
3544 int entry_pos = first_entry + i;
3545 int xpos = MENU_SCREEN_START_XPOS;
3546 int ypos = MENU_SCREEN_START_YPOS + i;
3547 int startx = mSX + xpos * 32;
3548 int starty = mSY + ypos * 32;
3549 int font_nr = FONT_TEXT_1;
3550 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3551 int startx_text = startx + font_xoffset;
3552 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3553 int text_size = startx_scrollbar - startx_text;
3554 int max_buffer_len = text_size / getFontWidth(font_nr);
3555 char buffer[max_buffer_len + 1];
3557 node_first = getTreeInfoFirstGroupEntry(ti);
3558 node = getTreeInfoFromPos(node_first, entry_pos);
3560 strncpy(buffer, node->name, max_buffer_len);
3561 buffer[max_buffer_len] = '\0';
3563 DrawText(startx, starty, buffer, font_nr + node->color);
3565 if (node->parent_link)
3566 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3567 else if (node->level_group)
3568 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3570 initCursor(i, IMG_MENU_BUTTON);
3573 game_status = last_game_status; /* restore current game status */
3575 redraw_mask |= REDRAW_FIELD;
3578 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3580 TreeInfo *node, *node_first;
3581 int x, last_redraw_mask = redraw_mask;
3582 int ypos = MENU_TITLE2_YPOS;
3583 int font_nr = FONT_TITLE_2;
3585 if (ti->type != TREE_TYPE_LEVEL_DIR)
3588 node_first = getTreeInfoFirstGroupEntry(ti);
3589 node = getTreeInfoFromPos(node_first, entry_pos);
3591 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3593 if (node->parent_link)
3594 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3596 else if (node->level_group)
3597 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3599 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3600 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3601 node->levels, node->class_desc);
3603 /* let BackToFront() redraw only what is needed */
3604 redraw_mask = last_redraw_mask | REDRAW_TILES;
3605 for (x = 0; x < SCR_FIELDX; x++)
3606 MarkTileDirty(x, 1);
3609 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3612 TreeInfo *ti = *ti_ptr;
3614 int y = ti->cl_cursor;
3615 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3616 int num_entries = numTreeInfoInGroup(ti);
3617 int num_page_entries;
3618 int last_game_status = game_status; /* save current game status */
3619 boolean position_set_by_scrollbar = (dx == 999);
3621 /* force LEVELS draw offset on choose level and artwork setup screen */
3622 game_status = GAME_MODE_LEVELS;
3624 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3625 num_page_entries = num_entries;
3627 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3629 game_status = last_game_status; /* restore current game status */
3631 if (button == MB_MENU_INITIALIZE)
3633 int num_entries = numTreeInfoInGroup(ti);
3634 int entry_pos = posTreeInfo(ti);
3636 if (ti->cl_first == -1)
3638 /* only on initialization */
3639 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3640 ti->cl_cursor = entry_pos - ti->cl_first;
3642 else if (ti->cl_cursor >= num_page_entries ||
3643 (num_entries > num_page_entries &&
3644 num_entries - ti->cl_first < num_page_entries))
3646 /* only after change of list size (by custom graphic configuration) */
3647 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3648 ti->cl_cursor = entry_pos - ti->cl_first;
3651 if (position_set_by_scrollbar)
3654 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3657 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3658 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3659 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3663 else if (button == MB_MENU_LEAVE)
3665 PlaySound(SND_MENU_ITEM_SELECTING);
3667 if (ti->node_parent)
3669 *ti_ptr = ti->node_parent;
3670 DrawChooseTree(ti_ptr);
3672 else if (game_status == GAME_MODE_SETUP)
3674 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3676 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3677 execSetupGraphics();
3683 game_status = GAME_MODE_MAIN;
3690 if (mx || my) /* mouse input */
3692 int last_game_status = game_status; /* save current game status */
3694 /* force LEVELS draw offset on artwork setup screen */
3695 game_status = GAME_MODE_LEVELS;
3697 x = (mx - mSX) / 32;
3698 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3700 game_status = last_game_status; /* restore current game status */
3702 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3704 /* move cursor instead of scrolling when already at start/end of list */
3705 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3707 else if (dy == +1 * SCROLL_LINE &&
3708 ti->cl_first + num_page_entries == num_entries)
3711 /* handle scrolling screen one line or page */
3712 if (ti->cl_cursor + dy < 0 ||
3713 ti->cl_cursor + dy > num_page_entries - 1)
3715 if (ABS(dy) == SCROLL_PAGE)
3716 step = num_page_entries - 1;
3718 if (dy < 0 && ti->cl_first > 0)
3720 /* scroll page/line up */
3722 ti->cl_first -= step;
3723 if (ti->cl_first < 0)
3726 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3727 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3728 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3730 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3733 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3735 /* scroll page/line down */
3737 ti->cl_first += step;
3738 if (ti->cl_first + num_page_entries > num_entries)
3739 ti->cl_first = MAX(0, num_entries - num_page_entries);
3741 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3742 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3743 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3745 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3752 /* handle moving cursor one line */
3753 y = ti->cl_cursor + dy;
3758 TreeInfo *node_first, *node_cursor;
3759 int entry_pos = ti->cl_first + y;
3761 node_first = getTreeInfoFirstGroupEntry(ti);
3762 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3764 if (node_cursor->node_group)
3766 PlaySound(SND_MENU_ITEM_SELECTING);
3768 node_cursor->cl_first = ti->cl_first;
3769 node_cursor->cl_cursor = ti->cl_cursor;
3770 *ti_ptr = node_cursor->node_group;
3771 DrawChooseTree(ti_ptr);
3776 else if (dx == -1 && ti->node_parent)
3778 PlaySound(SND_MENU_ITEM_SELECTING);
3780 *ti_ptr = ti->node_parent;
3781 DrawChooseTree(ti_ptr);
3786 if (!anyScrollbarGadgetActive() &&
3787 IN_VIS_FIELD(x, y) &&
3788 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3789 y >= 0 && y < num_page_entries)
3793 if (y != ti->cl_cursor)
3795 PlaySound(SND_MENU_ITEM_ACTIVATING);
3797 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3798 drawChooseTreeCursor(y, TRUE);
3799 drawChooseTreeInfo(ti->cl_first + y, ti);
3806 TreeInfo *node_first, *node_cursor;
3807 int entry_pos = ti->cl_first + y;
3809 PlaySound(SND_MENU_ITEM_SELECTING);
3811 node_first = getTreeInfoFirstGroupEntry(ti);
3812 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3814 if (node_cursor->node_group)
3816 node_cursor->cl_first = ti->cl_first;
3817 node_cursor->cl_cursor = ti->cl_cursor;
3818 *ti_ptr = node_cursor->node_group;
3819 DrawChooseTree(ti_ptr);
3821 else if (node_cursor->parent_link)
3823 *ti_ptr = node_cursor->node_parent;
3824 DrawChooseTree(ti_ptr);
3828 node_cursor->cl_first = ti->cl_first;
3829 node_cursor->cl_cursor = ti->cl_cursor;
3830 *ti_ptr = node_cursor;
3832 if (ti->type == TREE_TYPE_LEVEL_DIR)
3834 LoadLevelSetup_SeriesInfo();
3836 SaveLevelSetup_LastSeries();
3837 SaveLevelSetup_SeriesInfo();
3841 if (game_status == GAME_MODE_SETUP)
3843 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3845 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
3846 execSetupGraphics();
3852 game_status = GAME_MODE_MAIN;
3860 void DrawChooseLevel()
3862 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3864 DrawChooseTree(&leveldir_current);
3870 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3872 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3877 void DrawHallOfFame(int highlight_position)
3880 FadeSoundsAndMusic();
3882 /* (this is needed when called from GameEnd() after winning a game) */
3883 KeyboardAutoRepeatOn();
3886 /* (this is needed when called from GameEnd() after winning a game) */
3887 SetDrawDeactivationMask(REDRAW_NONE);
3888 SetDrawBackgroundMask(REDRAW_FIELD);
3890 CloseDoor(DOOR_CLOSE_2);
3892 if (highlight_position < 0)
3893 LoadScore(level_nr);
3895 FadeOut(REDRAW_FIELD);
3902 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3904 FadeIn(REDRAW_FIELD);
3907 static void drawHallOfFameList(int first_entry, int highlight_position)
3911 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3914 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3915 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3916 "HighScores of Level %d", level_nr);
3918 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3920 int entry = first_entry + i;
3921 boolean active = (entry == highlight_position);
3922 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3923 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3924 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3925 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3926 int dx1 = 3 * getFontWidth(font_nr1);
3927 int dx2 = dx1 + getFontWidth(font_nr1);
3928 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3929 int sy = mSY + 64 + i * 32;
3931 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3932 DrawText(mSX + dx1, sy, ".", font_nr1);
3933 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3935 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3936 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3938 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3941 redraw_mask |= REDRAW_FIELD;
3944 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3946 static int first_entry = 0;
3947 static int highlight_position = 0;
3948 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3950 if (button == MB_MENU_INITIALIZE)
3953 highlight_position = mx;
3954 drawHallOfFameList(first_entry, highlight_position);
3959 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3960 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3964 if (first_entry > 0)
3966 first_entry -= step;
3967 if (first_entry < 0)
3970 drawHallOfFameList(first_entry, highlight_position);
3975 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3977 first_entry += step;
3978 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3979 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3981 drawHallOfFameList(first_entry, highlight_position);
3984 else if (button == MB_MENU_LEAVE)
3986 PlaySound(SND_MENU_ITEM_SELECTING);
3988 FadeSound(SND_BACKGROUND_SCORES);
3990 game_status = GAME_MODE_MAIN;
3994 else if (button == MB_MENU_CHOICE)
3996 PlaySound(SND_MENU_ITEM_SELECTING);
3998 FadeSound(SND_BACKGROUND_SCORES);
3999 FadeOut(REDRAW_FIELD);
4001 game_status = GAME_MODE_MAIN;
4003 DrawAndFadeInMainMenu(REDRAW_FIELD);
4006 if (game_status == GAME_MODE_SCORES)
4007 PlayMenuSoundIfLoop();
4013 /* ========================================================================= */
4014 /* setup screen functions */
4015 /* ========================================================================= */
4017 static struct TokenInfo *setup_info;
4018 static int num_setup_info;
4020 static char *screen_mode_text;
4021 static char *game_speed_text;
4022 static char *graphics_set_name;
4023 static char *sounds_set_name;
4024 static char *music_set_name;
4026 static void execSetupMain()
4028 setup_mode = SETUP_MODE_MAIN;
4032 static void execSetupGame()
4034 if (game_speeds == NULL)
4038 for (i = 0; game_speeds_list[i].value != -1; i++)
4040 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4041 char identifier[32], name[32];
4042 int value = game_speeds_list[i].value;
4043 char *text = game_speeds_list[i].text;
4045 ti->node_top = &game_speeds;
4046 ti->sort_priority = 10000 - value;
4048 sprintf(identifier, "%d", value);
4049 sprintf(name, "%s", text);
4051 setString(&ti->identifier, identifier);
4052 setString(&ti->name, name);
4053 setString(&ti->name_sorting, name);
4054 setString(&ti->infotext, "Game Speed");
4056 pushTreeInfo(&game_speeds, ti);
4059 /* sort game speed values to start with slowest game speed */
4060 sortTreeInfo(&game_speeds);
4062 /* set current game speed to configured game speed value */
4063 game_speed_current =
4064 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4066 /* if that fails, set current game speed to reliable default value */
4067 if (game_speed_current == NULL)
4068 game_speed_current =
4069 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4071 /* if that also fails, set current game speed to first available speed */
4072 if (game_speed_current == NULL)
4073 game_speed_current = game_speeds;
4076 setup.game_frame_delay = atoi(game_speed_current->identifier);
4078 /* needed for displaying game speed text instead of identifier */
4079 game_speed_text = game_speed_current->name;
4081 setup_mode = SETUP_MODE_GAME;
4085 static void execSetupChooseGameSpeed()
4087 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4091 static void execSetupEditor()
4093 setup_mode = SETUP_MODE_EDITOR;
4097 static void execSetupGraphics()
4099 if (video.fullscreen_available && screen_modes == NULL)
4103 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4105 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4106 char identifier[32], name[32];
4107 int x = video.fullscreen_modes[i].width;
4108 int y = video.fullscreen_modes[i].height;
4111 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4113 ti->node_top = &screen_modes;
4114 ti->sort_priority = x * 10000 + y;
4116 sprintf(identifier, "%dx%d", x, y);
4117 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4119 setString(&ti->identifier, identifier);
4120 setString(&ti->name, name);
4121 setString(&ti->name_sorting, name);
4122 setString(&ti->infotext, "Fullscreen Mode");
4124 pushTreeInfo(&screen_modes, ti);
4127 /* sort fullscreen modes to start with lowest available screen resolution */
4128 sortTreeInfo(&screen_modes);
4130 /* set current screen mode for fullscreen mode to configured setup value */
4131 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4132 setup.fullscreen_mode);
4134 /* if that fails, set current screen mode to reliable default value */
4135 if (screen_mode_current == NULL)
4136 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4137 DEFAULT_FULLSCREEN_MODE);
4139 /* if that also fails, set current screen mode to first available mode */
4140 if (screen_mode_current == NULL)
4141 screen_mode_current = screen_modes;
4143 if (screen_mode_current == NULL)
4144 video.fullscreen_available = FALSE;
4147 if (video.fullscreen_available)
4149 setup.fullscreen_mode = screen_mode_current->identifier;
4151 /* needed for displaying screen mode name instead of identifier */
4152 screen_mode_text = screen_mode_current->name;
4155 setup_mode = SETUP_MODE_GRAPHICS;
4159 static void execSetupChooseScreenMode()
4161 if (!video.fullscreen_available)
4164 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4168 static void execSetupSound()
4170 setup_mode = SETUP_MODE_SOUND;
4174 static void execSetupArtwork()
4176 setup.graphics_set = artwork.gfx_current->identifier;
4177 setup.sounds_set = artwork.snd_current->identifier;
4178 setup.music_set = artwork.mus_current->identifier;
4180 /* needed if last screen (setup choice) changed graphics, sounds or music */
4181 ReloadCustomArtwork(0);
4183 /* needed for displaying artwork name instead of artwork identifier */
4184 graphics_set_name = artwork.gfx_current->name;
4185 sounds_set_name = artwork.snd_current->name;
4186 music_set_name = artwork.mus_current->name;
4188 setup_mode = SETUP_MODE_ARTWORK;
4192 static void execSetupChooseGraphics()
4194 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4198 static void execSetupChooseSounds()
4200 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4204 static void execSetupChooseMusic()
4206 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4210 static void execSetupInput()
4212 setup_mode = SETUP_MODE_INPUT;
4216 static void execSetupShortcut1()
4218 setup_mode = SETUP_MODE_SHORTCUT_1;
4222 static void execSetupShortcut2()
4224 setup_mode = SETUP_MODE_SHORTCUT_2;
4228 static void execExitSetup()
4230 game_status = GAME_MODE_MAIN;
4234 static void execSaveAndExitSetup()
4240 static struct TokenInfo setup_info_main[] =
4242 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4243 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4244 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4245 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4246 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4247 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4248 { TYPE_ENTER_MENU, execSetupShortcut1, "Key Shortcuts 1" },
4249 { TYPE_ENTER_MENU, execSetupShortcut2, "Key Shortcuts 2" },
4250 { TYPE_EMPTY, NULL, "" },
4251 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4252 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4257 static struct TokenInfo setup_info_game[] =
4259 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4260 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4261 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4262 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4263 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4264 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4265 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4266 { TYPE_STRING, &game_speed_text, "" },
4267 { TYPE_EMPTY, NULL, "" },
4268 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4273 static struct TokenInfo setup_info_editor[] =
4276 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4277 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4278 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4279 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4280 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4281 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4282 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4283 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4285 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4286 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4287 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4289 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4291 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4292 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4293 { TYPE_EMPTY, NULL, "" },
4295 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4296 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4297 { TYPE_EMPTY, NULL, "" },
4299 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4300 { TYPE_EMPTY, NULL, "" },
4301 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4306 static struct TokenInfo setup_info_graphics[] =
4308 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4309 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4310 { TYPE_STRING, &screen_mode_text, "" },
4311 { TYPE_SWITCH, &setup.scroll_delay, "Delayed Scrolling:" },
4313 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4314 { TYPE_SWITCH, &setup.double_buffering,"Double-Buffering:" },
4316 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4317 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4318 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4319 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4320 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4321 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4322 { TYPE_EMPTY, NULL, "" },
4323 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4328 static struct TokenInfo setup_info_sound[] =
4330 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4331 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4332 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4333 { TYPE_EMPTY, NULL, "" },
4334 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4339 static struct TokenInfo setup_info_artwork[] =
4341 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4342 { TYPE_STRING, &graphics_set_name, "" },
4343 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4344 { TYPE_STRING, &sounds_set_name, "" },
4345 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4346 { TYPE_STRING, &music_set_name, "" },
4347 { TYPE_EMPTY, NULL, "" },
4349 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4350 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4351 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4353 { TYPE_STRING, NULL, "Override Level Artwork:"},
4354 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4355 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4356 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4358 { TYPE_EMPTY, NULL, "" },
4359 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4364 static struct TokenInfo setup_info_input[] =
4366 { TYPE_SWITCH, NULL, "Player:" },
4367 { TYPE_SWITCH, NULL, "Device:" },
4368 { TYPE_ENTER_MENU, NULL, "" },
4369 { TYPE_EMPTY, NULL, "" },
4370 { TYPE_EMPTY, NULL, "" },
4371 { TYPE_EMPTY, NULL, "" },
4372 { TYPE_EMPTY, NULL, "" },
4373 { TYPE_EMPTY, NULL, "" },
4374 { TYPE_EMPTY, NULL, "" },
4375 { TYPE_EMPTY, NULL, "" },
4376 { TYPE_EMPTY, NULL, "" },
4377 { TYPE_EMPTY, NULL, "" },
4378 { TYPE_EMPTY, NULL, "" },
4379 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4384 static struct TokenInfo setup_info_shortcut_1[] =
4386 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4387 { TYPE_KEY, &setup.shortcut.save_game, "" },
4388 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4389 { TYPE_KEY, &setup.shortcut.load_game, "" },
4390 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4391 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4392 { TYPE_EMPTY, NULL, "" },
4393 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4394 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4395 { TYPE_EMPTY, NULL, "" },
4396 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4401 static struct TokenInfo setup_info_shortcut_2[] =
4403 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4404 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4405 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4406 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4407 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4408 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4409 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4410 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4411 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4412 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4413 { TYPE_EMPTY, NULL, "" },
4414 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4419 static Key getSetupKey()
4421 Key key = KSYM_UNDEFINED;
4422 boolean got_key_event = FALSE;
4424 while (!got_key_event)
4426 if (PendingEvent()) /* got event */
4434 case EVENT_KEYPRESS:
4436 key = GetEventKey((KeyEvent *)&event, TRUE);
4438 /* press 'Escape' or 'Enter' to keep the existing key binding */
4439 if (key == KSYM_Escape || key == KSYM_Return)
4440 key = KSYM_UNDEFINED; /* keep old value */
4442 got_key_event = TRUE;
4446 case EVENT_KEYRELEASE:
4447 key_joystick_mapping = 0;
4451 HandleOtherEvents(&event);
4459 /* don't eat all CPU time */
4466 static int getSetupTextFont(int type)
4468 if (type & (TYPE_SWITCH |
4479 static int getSetupValueFont(int type, void *value)
4481 if (type & TYPE_KEY)
4482 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4483 else if (type & TYPE_STRING)
4484 return FONT_VALUE_2;
4485 else if (type & TYPE_ECS_AGA)
4486 return FONT_VALUE_1;
4487 else if (type & TYPE_BOOLEAN_STYLE)
4488 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4490 return FONT_VALUE_1;
4493 static void drawSetupValue(int pos)
4495 boolean font_draw_xoffset_modified = FALSE;
4496 int font_draw_xoffset_old = -1;
4497 int xpos = MENU_SCREEN_VALUE_XPOS;
4498 int ypos = MENU_SCREEN_START_YPOS + pos;
4499 int startx = mSX + xpos * 32;
4500 int starty = mSY + ypos * 32;
4501 int font_nr, font_width;
4502 int type = setup_info[pos].type;
4503 void *value = setup_info[pos].value;
4504 char *value_string = getSetupValue(type, value);
4507 if (value_string == NULL)
4510 if (type & TYPE_KEY)
4512 xpos = MENU_SCREEN_START_XPOS;
4514 if (type & TYPE_QUERY)
4516 value_string = "<press key>";
4519 else if (type & TYPE_STRING)
4521 int max_value_len = (SCR_FIELDX - 2) * 2;
4523 xpos = MENU_SCREEN_START_XPOS;
4525 if (strlen(value_string) > max_value_len)
4526 value_string[max_value_len] = '\0';
4529 startx = mSX + xpos * 32;
4530 starty = mSY + ypos * 32;
4531 font_nr = getSetupValueFont(type, value);
4532 font_width = getFontWidth(font_nr);
4534 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4535 if (setup_mode != SETUP_MODE_INPUT)
4537 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4538 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4539 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4540 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4541 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4542 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4543 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4544 boolean correct_font_draw_xoffset = FALSE;
4546 if (xpos == MENU_SCREEN_START_XPOS &&
4547 startx + font1_xoffset < text_startx + text_font_xoffset)
4548 correct_font_draw_xoffset = TRUE;
4550 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4551 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4552 correct_font_draw_xoffset = TRUE;
4554 /* check if setup value would overlap with setup text when printed */
4555 /* (this can happen for extreme/wrong values for font draw offset) */
4556 if (correct_font_draw_xoffset)
4558 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4559 font_draw_xoffset_modified = TRUE;
4561 if (type & TYPE_KEY)
4562 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4563 else if (!(type & TYPE_STRING))
4564 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4565 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4569 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4570 DrawText(startx + i * font_width, starty, " ", font_nr);
4572 DrawText(startx, starty, value_string, font_nr);
4574 if (font_draw_xoffset_modified)
4575 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4578 static void changeSetupValue(int pos)
4580 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4582 *(boolean *)setup_info[pos].value ^= TRUE;
4584 else if (setup_info[pos].type & TYPE_KEY)
4588 setup_info[pos].type |= TYPE_QUERY;
4589 drawSetupValue(pos);
4590 setup_info[pos].type &= ~TYPE_QUERY;
4592 key = getSetupKey();
4593 if (key != KSYM_UNDEFINED)
4594 *(Key *)setup_info[pos].value = key;
4597 drawSetupValue(pos);
4600 static void DrawCursorAndText_Setup(int pos, boolean active)
4602 int xpos = MENU_SCREEN_START_XPOS;
4603 int ypos = MENU_SCREEN_START_YPOS + pos;
4604 int font_nr = getSetupTextFont(setup_info[pos].type);
4606 if (setup_info == setup_info_input)
4607 font_nr = FONT_MENU_1;
4610 font_nr = FONT_ACTIVE(font_nr);
4612 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4614 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4615 drawCursor(pos, active);
4618 static void DrawSetupScreen_Generic()
4620 char *title_string = NULL;
4624 CloseDoor(DOOR_CLOSE_2);
4628 if (setup_mode == SETUP_MODE_MAIN)
4630 setup_info = setup_info_main;
4631 title_string = "Setup";
4633 else if (setup_mode == SETUP_MODE_GAME)
4635 setup_info = setup_info_game;
4636 title_string = "Setup Game";
4638 else if (setup_mode == SETUP_MODE_EDITOR)
4640 setup_info = setup_info_editor;
4641 title_string = "Setup Editor";
4643 else if (setup_mode == SETUP_MODE_GRAPHICS)
4645 setup_info = setup_info_graphics;
4646 title_string = "Setup Graphics";
4648 else if (setup_mode == SETUP_MODE_SOUND)
4650 setup_info = setup_info_sound;
4651 title_string = "Setup Sound";
4653 else if (setup_mode == SETUP_MODE_ARTWORK)
4655 setup_info = setup_info_artwork;
4656 title_string = "Custom Artwork";
4658 else if (setup_mode == SETUP_MODE_SHORTCUT_1)
4660 setup_info = setup_info_shortcut_1;
4661 title_string = "Setup Shortcuts";
4663 else if (setup_mode == SETUP_MODE_SHORTCUT_2)
4665 setup_info = setup_info_shortcut_2;
4666 title_string = "Setup Shortcuts";
4669 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4672 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4674 void *value_ptr = setup_info[i].value;
4677 int xpos = MENU_SCREEN_START_XPOS;
4678 int ypos = MENU_SCREEN_START_YPOS + i;
4682 /* set some entries to "unchangeable" according to other variables */
4683 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4684 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4685 (value_ptr == &setup.sound_music && !audio.music_available) ||
4686 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4687 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4688 setup_info[i].type |= TYPE_GHOSTED;
4690 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4691 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4692 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4693 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4694 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4695 initCursor(i, IMG_MENU_BUTTON);
4698 DrawCursorAndText_Setup(i, FALSE);
4700 font_nr = getSetupTextFont(setup_info[i].type);
4702 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[i].text, font_nr);
4705 if (setup_info[i].type & TYPE_VALUE)
4712 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4713 "Joysticks deactivated in setup menu");
4718 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4721 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4723 static int choice_store[MAX_SETUP_MODES];
4724 int choice = choice_store[setup_mode]; /* always starts with 0 */
4728 if (button == MB_MENU_INITIALIZE)
4730 /* advance to first valid menu entry */
4731 while (choice < num_setup_info &&
4732 setup_info[choice].type & TYPE_SKIP_ENTRY)
4734 choice_store[setup_mode] = choice;
4737 DrawCursorAndText_Setup(choice, TRUE);
4739 drawCursor(choice, TRUE);
4744 else if (button == MB_MENU_LEAVE)
4746 PlaySound(SND_MENU_ITEM_SELECTING);
4748 for (y = 0; y < num_setup_info; y++)
4750 if (setup_info[y].type & TYPE_LEAVE_MENU)
4752 void (*menu_callback_function)(void) = setup_info[y].value;
4754 menu_callback_function();
4756 break; /* absolutely needed because function changes 'setup_info'! */
4763 if (mx || my) /* mouse input */
4765 x = (mx - mSX) / 32;
4766 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4768 else if (dx || dy) /* keyboard input */
4772 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4774 if (setup_info[choice].type & menu_navigation_type ||
4775 setup_info[choice].type & TYPE_BOOLEAN_STYLE)
4776 button = MB_MENU_CHOICE;
4781 /* jump to next non-empty menu entry (up or down) */
4782 while (y > 0 && y < num_setup_info - 1 &&
4783 setup_info[y].type & TYPE_SKIP_ENTRY)
4787 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4791 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4793 PlaySound(SND_MENU_ITEM_ACTIVATING);
4796 DrawCursorAndText_Setup(choice, FALSE);
4797 DrawCursorAndText_Setup(y, TRUE);
4799 drawCursor(choice, FALSE);
4800 drawCursor(y, TRUE);
4803 choice = choice_store[setup_mode] = y;
4806 else if (!(setup_info[y].type & TYPE_GHOSTED))
4808 PlaySound(SND_MENU_ITEM_SELECTING);
4810 /* when selecting key headline, execute function for key value change */
4811 if (setup_info[y].type & TYPE_KEYTEXT &&
4812 setup_info[y + 1].type & TYPE_KEY)
4815 /* when selecting string value, execute function for list selection */
4816 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4817 setup_info[y - 1].type & TYPE_ENTER_LIST)
4820 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4822 void (*menu_callback_function)(void) = setup_info[y].value;
4824 menu_callback_function();
4828 if (setup_info[y].type & TYPE_VALUE)
4829 changeSetupValue(y);
4835 void DrawSetupScreen_Input()
4844 setup_info = setup_info_input;
4847 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4850 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4852 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4853 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4854 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4855 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4856 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4857 initCursor(i, IMG_MENU_BUTTON);
4859 DrawCursorAndText_Setup(i, FALSE);
4862 initCursor(0, IMG_MENU_BUTTON);
4863 initCursor(1, IMG_MENU_BUTTON);
4864 initCursor(2, IMG_MENU_BUTTON_ENTER_MENU);
4865 initCursor(13, IMG_MENU_BUTTON_LEAVE_MENU);
4867 DrawText(mSX + 32, mSY + 2 * 32, "Player:", FONT_MENU_1);
4868 DrawText(mSX + 32, mSY + 3 * 32, "Device:", FONT_MENU_1);
4869 DrawText(mSX + 32, mSY + 15 * 32, "Back", FONT_MENU_1);
4873 DeactivateJoystickForCalibration();
4876 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4877 "Joysticks deactivated on this screen");
4880 /* create gadgets for setup input menu screen */
4881 FreeScreenGadgets();
4882 CreateScreenGadgets();
4884 /* map gadgets for setup input menu screen */
4885 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4887 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4892 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4894 if (device_name == NULL)
4897 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4900 if (strlen(device_name) > 1)
4902 char c1 = device_name[strlen(device_name) - 1];
4903 char c2 = device_name[strlen(device_name) - 2];
4905 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4906 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4909 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4910 strlen(device_name));
4913 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4916 static struct SetupKeyboardInfo custom_key;
4923 { &custom_key.left, "Joystick Left" },
4924 { &custom_key.right, "Joystick Right" },
4925 { &custom_key.up, "Joystick Up" },
4926 { &custom_key.down, "Joystick Down" },
4927 { &custom_key.snap, "Button 1" },
4928 { &custom_key.drop, "Button 2" }
4930 static char *joystick_name[MAX_PLAYERS] =
4937 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4941 custom_key = setup.input[player_nr].key;
4943 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4944 FONT_INPUT_1_ACTIVE);
4946 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4948 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4949 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4951 if (setup.input[player_nr].use_joystick)
4953 char *device_name = setup.input[player_nr].joy.device_name;
4954 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4955 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4957 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4958 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4962 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4963 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4966 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4968 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4969 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4970 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4971 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4973 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4974 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4975 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4976 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4977 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4978 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
4980 for (i = 0; i < 6; i++)
4982 int ypos = 6 + i + (i > 3 ? i-3 : 0);
4984 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4986 DrawText(mSX + 3 * 32, mSY + ypos * 32,
4987 (setup.input[player_nr].use_joystick ?
4989 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
4993 static int input_player_nr = 0;
4995 void HandleSetupScreen_Input_Player(int step, int direction)
4997 int old_player_nr = input_player_nr;
5000 new_player_nr = old_player_nr + step * direction;
5001 if (new_player_nr < 0)
5003 if (new_player_nr > MAX_PLAYERS - 1)
5004 new_player_nr = MAX_PLAYERS - 1;
5006 if (new_player_nr != old_player_nr)
5008 input_player_nr = new_player_nr;
5010 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5014 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5016 static int choice = 0;
5019 int pos_start = SETUPINPUT_SCREEN_POS_START;
5020 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5021 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5022 int pos_end = SETUPINPUT_SCREEN_POS_END;
5024 if (button == MB_MENU_INITIALIZE)
5026 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5029 DrawCursorAndText_Setup(choice, TRUE);
5031 drawCursor(choice, TRUE);
5036 else if (button == MB_MENU_LEAVE)
5038 setup_mode = SETUP_MODE_MAIN;
5045 if (mx || my) /* mouse input */
5047 x = (mx - mSX) / 32;
5048 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5050 else if (dx || dy) /* keyboard input */
5052 if (dx && choice == 0)
5053 x = (dx < 0 ? 10 : 12);
5054 else if ((dx && choice == 1) ||
5055 (dx == +1 && choice == 2) ||
5056 (dx == -1 && choice == pos_end))
5057 button = MB_MENU_CHOICE;
5061 if (y >= pos_empty1 && y <= pos_empty2)
5062 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5065 if (y == 0 && dx != 0 && button)
5067 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5069 else if (IN_VIS_FIELD(x, y) &&
5070 y >= pos_start && y <= pos_end &&
5071 !(y >= pos_empty1 && y <= pos_empty2))
5078 DrawCursorAndText_Setup(choice, FALSE);
5079 DrawCursorAndText_Setup(y, TRUE);
5081 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5083 drawCursor(choice, FALSE);
5084 drawCursor(y, TRUE);
5094 char *device_name = setup.input[input_player_nr].joy.device_name;
5096 if (!setup.input[input_player_nr].use_joystick)
5098 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5100 setJoystickDeviceToNr(device_name, new_device_nr);
5101 setup.input[input_player_nr].use_joystick = TRUE;
5105 int device_nr = getJoystickNrFromDeviceName(device_name);
5106 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5108 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5109 setup.input[input_player_nr].use_joystick = FALSE;
5111 setJoystickDeviceToNr(device_name, new_device_nr);
5114 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5118 if (setup.input[input_player_nr].use_joystick)
5121 CalibrateJoystick(input_player_nr);
5124 CustomizeKeyboard(input_player_nr);
5126 else if (y == pos_end)
5130 setup_mode = SETUP_MODE_MAIN;
5137 void CustomizeKeyboard(int player_nr)
5141 boolean finished = FALSE;
5142 static struct SetupKeyboardInfo custom_key;
5147 } customize_step[] =
5149 { &custom_key.left, "Move Left" },
5150 { &custom_key.right, "Move Right" },
5151 { &custom_key.up, "Move Up" },
5152 { &custom_key.down, "Move Down" },
5153 { &custom_key.snap, "Snap Field" },
5154 { &custom_key.drop, "Drop Element" }
5157 /* read existing key bindings from player setup */
5158 custom_key = setup.input[player_nr].key;
5162 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5168 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5169 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5170 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5171 "Key:", FONT_INPUT_1_ACTIVE);
5172 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5173 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5177 if (PendingEvent()) /* got event */
5185 case EVENT_KEYPRESS:
5187 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5189 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5195 /* all keys configured -- wait for "Escape" or "Return" key */
5199 /* press 'Enter' to keep the existing key binding */
5200 if (key == KSYM_Return)
5201 key = *customize_step[step_nr].key;
5203 /* check if key already used */
5204 for (i = 0; i < step_nr; i++)
5205 if (*customize_step[i].key == key)
5210 /* got new key binding */
5211 *customize_step[step_nr].key = key;
5212 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5214 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5215 getKeyNameFromKey(key), FONT_VALUE_1);
5218 /* un-highlight last query */
5219 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5220 customize_step[step_nr - 1].text, FONT_MENU_1);
5221 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5222 "Key:", FONT_MENU_1);
5224 /* press 'Enter' to leave */
5227 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5228 "Press Enter", FONT_TITLE_1);
5232 /* query next key binding */
5233 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5234 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5235 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5236 "Key:", FONT_INPUT_1_ACTIVE);
5237 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5238 getKeyNameFromKey(*customize_step[step_nr].key),
5243 case EVENT_KEYRELEASE:
5244 key_joystick_mapping = 0;
5248 HandleOtherEvents(&event);
5256 /* don't eat all CPU time */
5260 /* write new key bindings back to player setup */
5261 setup.input[player_nr].key = custom_key;
5264 DrawSetupScreen_Input();
5267 static boolean CalibrateJoystickMain(int player_nr)
5269 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5270 int new_joystick_xright = JOYSTICK_XMIDDLE;
5271 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5272 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5273 int new_joystick_xmiddle, new_joystick_ymiddle;
5275 int joystick_fd = joystick.fd[player_nr];
5276 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5277 boolean check[3][3];
5278 int check_remaining = 3 * 3;
5283 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5286 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5291 for (y = 0; y < 3; y++)
5293 for (x = 0; x < 3; x++)
5295 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5296 check[x][y] = FALSE;
5300 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5301 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5302 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5303 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5304 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5305 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5306 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5308 joy_value = Joystick(player_nr);
5309 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5310 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5312 /* eventually uncalibrated center position (joystick could be uncentered) */
5313 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5316 new_joystick_xmiddle = joy_x;
5317 new_joystick_ymiddle = joy_y;
5319 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5322 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5327 if (PendingEvent()) /* got event */
5335 case EVENT_KEYPRESS:
5336 switch (GetEventKey((KeyEvent *)&event, TRUE))
5339 if (check_remaining == 0)
5352 case EVENT_KEYRELEASE:
5353 key_joystick_mapping = 0;
5357 HandleOtherEvents(&event);
5362 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5365 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5366 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5367 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5368 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5370 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5371 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5372 setup.input[player_nr].joy.xright = new_joystick_xright;
5373 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5374 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5375 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5377 CheckJoystickData();
5379 joy_value = Joystick(player_nr);
5381 if (joy_value & JOY_BUTTON && check_remaining == 0)
5384 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5385 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5387 if (x != last_x || y != last_y)
5389 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5390 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5395 if (check_remaining > 0 && !check[x+1][y+1])
5397 check[x+1][y+1] = TRUE;
5403 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5404 setup.input[player_nr].joy.xleft,
5405 setup.input[player_nr].joy.xmiddle,
5406 setup.input[player_nr].joy.xright);
5407 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5408 setup.input[player_nr].joy.yupper,
5409 setup.input[player_nr].joy.ymiddle,
5410 setup.input[player_nr].joy.ylower);
5419 /* don't eat all CPU time */
5423 /* calibrated center position (joystick should now be centered) */
5424 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5427 new_joystick_xmiddle = joy_x;
5428 new_joystick_ymiddle = joy_y;
5433 DrawSetupScreen_Input();
5436 /* wait until the last pressed button was released */
5437 while (Joystick(player_nr) & JOY_BUTTON)
5439 if (PendingEvent()) /* got event */
5444 HandleOtherEvents(&event);
5453 void CalibrateJoystick(int player_nr)
5455 if (!CalibrateJoystickMain(player_nr))
5457 char *device_name = setup.input[player_nr].joy.device_name;
5458 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5459 int xpos = mSX - SX;
5460 int ypos = mSY - SY;
5464 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5465 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5468 Delay(2000); /* show error message for a short time */
5474 DrawSetupScreen_Input();
5478 void DrawSetupScreen()
5480 DeactivateJoystick();
5482 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5484 if (setup_mode == SETUP_MODE_INPUT)
5485 DrawSetupScreen_Input();
5486 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5487 DrawChooseTree(&game_speed_current);
5488 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5489 DrawChooseTree(&screen_mode_current);
5490 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5491 DrawChooseTree(&artwork.gfx_current);
5492 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5493 DrawChooseTree(&artwork.snd_current);
5494 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5495 DrawChooseTree(&artwork.mus_current);
5497 DrawSetupScreen_Generic();
5503 void RedrawSetupScreenAfterFullscreenToggle()
5505 if (setup_mode == SETUP_MODE_GRAPHICS)
5509 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5511 if (setup_mode == SETUP_MODE_INPUT)
5512 HandleSetupScreen_Input(mx, my, dx, dy, button);
5513 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5514 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5515 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5516 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5517 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5518 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5519 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5520 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5521 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5522 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5524 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5529 void HandleGameActions()
5531 if (game_status != GAME_MODE_PLAYING)
5534 GameActions(); /* main game loop */
5536 if (tape.auto_play && !tape.playing)
5537 AutoPlayTape(); /* continue automatically playing next tape */
5541 /* ---------- new screen button stuff -------------------------------------- */
5543 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5548 case SCREEN_CTRL_ID_PREV_LEVEL:
5549 *x = mSX + menu.main.button.prev_level.x;
5550 *y = mSY + menu.main.button.prev_level.y;
5553 case SCREEN_CTRL_ID_NEXT_LEVEL:
5554 *x = mSX + menu.main.button.next_level.x;
5555 *y = mSY + menu.main.button.next_level.y;
5558 case SCREEN_CTRL_ID_PREV_LEVEL:
5559 *x = mSX + TILEX * getPrevlevelButtonPos();
5560 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5563 case SCREEN_CTRL_ID_NEXT_LEVEL:
5564 *x = mSX + TILEX * getNextLevelButtonPos();
5565 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5569 case SCREEN_CTRL_ID_PREV_PLAYER:
5570 *x = mSX + TILEX * 10;
5571 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5574 case SCREEN_CTRL_ID_NEXT_PLAYER:
5575 *x = mSX + TILEX * 12;
5576 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5580 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5586 int gfx_unpressed, gfx_pressed;
5587 void (*get_gadget_position)(int *, int *, int);
5591 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5594 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5595 getScreenMenuButtonPos,
5596 SCREEN_CTRL_ID_PREV_LEVEL,
5601 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5602 getScreenMenuButtonPos,
5603 SCREEN_CTRL_ID_NEXT_LEVEL,
5608 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5609 getScreenMenuButtonPos,
5610 SCREEN_CTRL_ID_PREV_PLAYER,
5615 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5616 getScreenMenuButtonPos,
5617 SCREEN_CTRL_ID_NEXT_PLAYER,
5625 int gfx_unpressed, gfx_pressed;
5629 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5632 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5633 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5634 SCREEN_CTRL_ID_SCROLL_UP,
5638 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5639 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5640 SCREEN_CTRL_ID_SCROLL_DOWN,
5647 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5648 Bitmap **gfx_unpressed, **gfx_pressed;
5650 int gfx_unpressed, gfx_pressed;
5657 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5660 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5661 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5663 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5665 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5666 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5667 GD_TYPE_SCROLLBAR_VERTICAL,
5668 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5669 "scroll level series vertically"
5673 static void CreateScreenMenubuttons()
5675 struct GadgetInfo *gi;
5676 unsigned long event_mask;
5679 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5681 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5682 int gfx_unpressed, gfx_pressed;
5683 int x, y, width, height;
5684 int gd_x1, gd_x2, gd_y1, gd_y2;
5685 int id = menubutton_info[i].gadget_id;
5687 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5689 menubutton_info[i].get_gadget_position(&x, &y, id);
5691 width = SC_MENUBUTTON_XSIZE;
5692 height = SC_MENUBUTTON_YSIZE;
5694 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5695 gfx_pressed = menubutton_info[i].gfx_pressed;
5696 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5697 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5698 gd_x1 = graphic_info[gfx_unpressed].src_x;
5699 gd_y1 = graphic_info[gfx_unpressed].src_y;
5700 gd_x2 = graphic_info[gfx_pressed].src_x;
5701 gd_y2 = graphic_info[gfx_pressed].src_y;
5703 gi = CreateGadget(GDI_CUSTOM_ID, id,
5704 GDI_CUSTOM_TYPE_ID, i,
5705 GDI_INFO_TEXT, menubutton_info[i].infotext,
5710 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5711 GDI_STATE, GD_BUTTON_UNPRESSED,
5712 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5713 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5714 GDI_DIRECT_DRAW, FALSE,
5715 GDI_EVENT_MASK, event_mask,
5716 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5720 Error(ERR_EXIT, "cannot create gadget");
5722 screen_gadget[id] = gi;
5726 static void CreateScreenScrollbuttons()
5728 struct GadgetInfo *gi;
5729 unsigned long event_mask;
5732 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5734 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5735 int gfx_unpressed, gfx_pressed;
5736 int x, y, width, height;
5737 int gd_x1, gd_x2, gd_y1, gd_y2;
5738 int id = scrollbutton_info[i].gadget_id;
5740 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5742 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5743 y = mSY + scrollbutton_info[i].y;
5744 width = SC_SCROLLBUTTON_XSIZE;
5745 height = SC_SCROLLBUTTON_YSIZE;
5747 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5748 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5749 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5751 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5752 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5753 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5754 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5755 gd_x1 = graphic_info[gfx_unpressed].src_x;
5756 gd_y1 = graphic_info[gfx_unpressed].src_y;
5757 gd_x2 = graphic_info[gfx_pressed].src_x;
5758 gd_y2 = graphic_info[gfx_pressed].src_y;
5760 gi = CreateGadget(GDI_CUSTOM_ID, id,
5761 GDI_CUSTOM_TYPE_ID, i,
5762 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5767 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5768 GDI_STATE, GD_BUTTON_UNPRESSED,
5769 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5770 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5771 GDI_DIRECT_DRAW, FALSE,
5772 GDI_EVENT_MASK, event_mask,
5773 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5777 Error(ERR_EXIT, "cannot create gadget");
5779 screen_gadget[id] = gi;
5783 static void CreateScreenScrollbars()
5787 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5789 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5790 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5791 int gfx_unpressed, gfx_pressed;
5793 int x, y, width, height;
5794 int gd_x1, gd_x2, gd_y1, gd_y2;
5795 struct GadgetInfo *gi;
5796 int items_max, items_visible, item_position;
5797 unsigned long event_mask;
5798 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5799 int id = scrollbar_info[i].gadget_id;
5801 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5803 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5804 y = mSY + scrollbar_info[i].y;
5805 width = scrollbar_info[i].width;
5806 height = scrollbar_info[i].height;
5808 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5809 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5811 items_max = num_page_entries;
5812 items_visible = num_page_entries;
5815 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5816 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5817 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5823 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5824 gfx_pressed = scrollbar_info[i].gfx_pressed;
5825 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5826 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5827 gd_x1 = graphic_info[gfx_unpressed].src_x;
5828 gd_y1 = graphic_info[gfx_unpressed].src_y;
5829 gd_x2 = graphic_info[gfx_pressed].src_x;
5830 gd_y2 = graphic_info[gfx_pressed].src_y;
5833 gi = CreateGadget(GDI_CUSTOM_ID, id,
5834 GDI_CUSTOM_TYPE_ID, i,
5835 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5840 GDI_TYPE, scrollbar_info[i].type,
5841 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5842 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5843 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5845 GDI_WHEEL_AREA_X, SX,
5846 GDI_WHEEL_AREA_Y, SY,
5847 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5848 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5850 GDI_WHEEL_AREA_X, 0,
5851 GDI_WHEEL_AREA_Y, 0,
5852 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5853 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5855 GDI_STATE, GD_BUTTON_UNPRESSED,
5856 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5857 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5858 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5859 GDI_DIRECT_DRAW, FALSE,
5860 GDI_EVENT_MASK, event_mask,
5861 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5865 Error(ERR_EXIT, "cannot create gadget");
5867 screen_gadget[id] = gi;
5871 void CreateScreenGadgets()
5873 int last_game_status = game_status; /* save current game status */
5875 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5878 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5880 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5882 /* copy pointers to clip mask and GC */
5883 scrollbar_bitmap[i]->clip_mask =
5884 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5885 scrollbar_bitmap[i]->stored_clip_gc =
5886 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5888 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5889 scrollbar_bitmap[i],
5890 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5891 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5892 TILEX, TILEY, 0, 0);
5896 CreateScreenMenubuttons();
5898 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5899 game_status = GAME_MODE_LEVELS;
5901 CreateScreenScrollbuttons();
5902 CreateScreenScrollbars();
5904 game_status = last_game_status; /* restore current game status */
5907 void FreeScreenGadgets()
5911 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5912 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5914 /* prevent freeing clip mask and GC twice */
5915 scrollbar_bitmap[i]->clip_mask = None;
5916 scrollbar_bitmap[i]->stored_clip_gc = None;
5918 FreeBitmap(scrollbar_bitmap[i]);
5922 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5923 FreeGadget(screen_gadget[i]);
5926 void MapScreenMenuGadgets(int screen_mask)
5930 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5931 if (screen_mask & menubutton_info[i].screen_mask)
5932 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5935 void MapScreenTreeGadgets(TreeInfo *ti)
5937 int num_entries = numTreeInfoInGroup(ti);
5940 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5943 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5944 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5946 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5947 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5950 static void HandleScreenGadgets(struct GadgetInfo *gi)
5952 int id = gi->custom_id;
5953 int button = gi->event.button;
5954 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5958 case SCREEN_CTRL_ID_PREV_LEVEL:
5959 HandleMainMenu_SelectLevel(step, -1);
5962 case SCREEN_CTRL_ID_NEXT_LEVEL:
5963 HandleMainMenu_SelectLevel(step, +1);
5966 case SCREEN_CTRL_ID_PREV_PLAYER:
5967 HandleSetupScreen_Input_Player(step, -1);
5970 case SCREEN_CTRL_ID_NEXT_PLAYER:
5971 HandleSetupScreen_Input_Player(step, +1);
5974 case SCREEN_CTRL_ID_SCROLL_UP:
5975 if (game_status == GAME_MODE_LEVELS)
5976 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5977 else if (game_status == GAME_MODE_SETUP)
5978 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
5981 case SCREEN_CTRL_ID_SCROLL_DOWN:
5982 if (game_status == GAME_MODE_LEVELS)
5983 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5984 else if (game_status == GAME_MODE_SETUP)
5985 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
5988 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
5989 if (game_status == GAME_MODE_LEVELS)
5990 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
5991 else if (game_status == GAME_MODE_SETUP)
5992 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);