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 on the info screen */
29 #define INFO_MODE_MAIN 0
30 #define INFO_MODE_TITLE 1
31 #define INFO_MODE_ELEMENTS 2
32 #define INFO_MODE_MUSIC 3
33 #define INFO_MODE_CREDITS 4
34 #define INFO_MODE_PROGRAM 5
35 #define INFO_MODE_VERSION 6
36 #define INFO_MODE_LEVELSET 7
38 #define MAX_INFO_MODES 8
40 /* screens on the setup screen */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_SHORTCUTS 7
49 #define SETUP_MODE_SHORTCUTS_1 8
50 #define SETUP_MODE_SHORTCUTS_2 9
51 #define SETUP_MODE_SHORTCUTS_3 10
52 #define SETUP_MODE_SHORTCUTS_4 11
53 #define SETUP_MODE_SHORTCUTS_5 12
55 /* sub-screens on the setup screen (generic) */
56 #define SETUP_MODE_CHOOSE_ARTWORK 13
57 #define SETUP_MODE_CHOOSE_OTHER 14
59 /* sub-screens on the setup screen (specific) */
60 #define SETUP_MODE_CHOOSE_GAME_SPEED 15
61 #define SETUP_MODE_CHOOSE_SCREEN_MODE 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_GRAPHICS 18
64 #define SETUP_MODE_CHOOSE_SOUNDS 19
65 #define SETUP_MODE_CHOOSE_MUSIC 20
67 #define MAX_SETUP_MODES 21
69 /* for input setup functions */
70 #define SETUPINPUT_SCREEN_POS_START 0
71 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
72 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
73 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
75 /* for various menu stuff */
76 #define MENU_SCREEN_START_XPOS 1
77 #define MENU_SCREEN_START_YPOS 2
78 #define MENU_SCREEN_VALUE_XPOS 14
79 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
80 #define MENU_TITLE1_YPOS 8
81 #define MENU_TITLE2_YPOS 46
82 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
83 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
84 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
85 MENU_SCREEN_START_XPOS)
86 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
88 /* buttons and scrollbars identifiers */
89 #define SCREEN_CTRL_ID_PREV_LEVEL 0
90 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
91 #define SCREEN_CTRL_ID_PREV_PLAYER 2
92 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
93 #define SCREEN_CTRL_ID_SCROLL_UP 4
94 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
95 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
97 #define NUM_SCREEN_GADGETS 7
99 #define NUM_SCREEN_MENUBUTTONS 4
100 #define NUM_SCREEN_SCROLLBUTTONS 2
101 #define NUM_SCREEN_SCROLLBARS 1
103 #define SCREEN_MASK_MAIN (1 << 0)
104 #define SCREEN_MASK_INPUT (1 << 1)
106 /* graphic position and size values for buttons and scrollbars */
107 #define SC_MENUBUTTON_XSIZE TILEX
108 #define SC_MENUBUTTON_YSIZE TILEY
110 #define SC_SCROLLBUTTON_XSIZE TILEX
111 #define SC_SCROLLBUTTON_YSIZE TILEY
113 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
115 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
116 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
117 SC_SCROLLBUTTON_YSIZE)
119 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
120 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
122 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
123 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
124 SC_SCROLLBUTTON_YSIZE)
126 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
127 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
128 SC_SCROLL_VERTICAL_YSIZE)
130 #define SC_BORDER_SIZE 14
133 /* forward declarations of internal functions */
134 static void HandleScreenGadgets(struct GadgetInfo *);
135 static void HandleSetupScreen_Generic(int, int, int, int, int);
136 static void HandleSetupScreen_Input(int, int, int, int, int);
137 static void CustomizeKeyboard(int);
138 static void CalibrateJoystick(int);
139 static void execSetupGame(void);
140 static void execSetupGraphics(void);
141 static void execSetupArtwork(void);
142 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
144 static void DrawChooseLevel(void);
145 static void DrawInfoScreen(void);
146 static void DrawAndFadeInInfoScreen(int);
147 static void DrawSetupScreen(void);
149 static void DrawInfoScreenExt(int, int);
150 static void DrawInfoScreen_NotAvailable(char *, char *);
151 static void DrawInfoScreen_HelpAnim(int, int, boolean);
152 static void DrawInfoScreen_HelpText(int, int, int, int);
153 static void HandleInfoScreen_Main(int, int, int, int, int);
154 static void HandleInfoScreen_TitleScreen(int);
155 static void HandleInfoScreen_Elements(int);
156 static void HandleInfoScreen_Music(int);
157 static void HandleInfoScreen_Credits(int);
158 static void HandleInfoScreen_Program(int);
159 static void HandleInfoScreen_Version(int);
161 static void MapScreenMenuGadgets(int);
162 static void MapScreenTreeGadgets(TreeInfo *);
164 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
166 static int info_mode = INFO_MODE_MAIN;
167 static int setup_mode = SETUP_MODE_MAIN;
169 static TreeInfo *screen_modes = NULL;
170 static TreeInfo *screen_mode_current = NULL;
172 static TreeInfo *scroll_delays = NULL;
173 static TreeInfo *scroll_delay_current = NULL;
175 static TreeInfo *game_speeds = NULL;
176 static TreeInfo *game_speed_current = NULL;
182 } game_speeds_list[] =
191 { 1000, "1/1s (Extremely Slow)" },
196 { 29, "1/35s (Original Supaplex)" },
198 { 20, "1/50s (Normal Speed)" },
199 { 14, "1/70s (Maximum Supaplex)" },
203 { 1, "1/1000s (Extremely Fast)" },
213 } scroll_delays_list[] =
215 { 0, "0 Tiles (No Scroll Delay)" },
218 { 3, "3 Tiles (Default)" },
223 { 8, "8 Tiles (Maximum Scroll Delay)"},
228 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
229 (s) <= GAME_MODE_SETUP ? (s) : \
230 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
231 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
233 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
234 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
235 (i) <= INFO_MODE_LEVELSET ? (i) : \
238 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
239 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
240 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
241 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
242 SETUP_MODE_CHOOSE_ARTWORK : \
243 SETUP_MODE_CHOOSE_OTHER)
245 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
246 menu.draw_xoffset[GAME_MODE_INFO] : \
247 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
248 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
249 menu.draw_yoffset[GAME_MODE_INFO] : \
250 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
252 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
253 menu.draw_xoffset[GAME_MODE_SETUP] : \
254 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
255 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
256 menu.draw_yoffset[GAME_MODE_SETUP] : \
257 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
259 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
260 DRAW_XOFFSET_INFO(info_mode) : \
261 (s) == GAME_MODE_SETUP ? \
262 DRAW_XOFFSET_SETUP(setup_mode) : \
263 menu.draw_xoffset[DRAW_MODE(s)])
264 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
265 DRAW_YOFFSET_INFO(info_mode) : \
266 (s) == GAME_MODE_SETUP ? \
267 DRAW_YOFFSET_SETUP(setup_mode) : \
268 menu.draw_yoffset[DRAW_MODE(s)])
270 #define mSX (SX + DRAW_XOFFSET(game_status))
271 #define mSY (SY + DRAW_YOFFSET(game_status))
273 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
274 menu.list_size[game_status] : \
275 MAX_MENU_ENTRIES_ON_SCREEN)
277 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
278 #define NUM_SCROLLBAR_BITMAPS 2
279 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
283 /* title display and control definitions */
285 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
286 2 * MAX_NUM_TITLE_MESSAGES)
288 static int num_title_screens = 0;
290 struct TitleControlInfo
298 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
300 /* main menu display and control definitions */
302 #define MAIN_CONTROL_NAME 0
303 #define MAIN_CONTROL_LEVELS 1
304 #define MAIN_CONTROL_SCORES 2
305 #define MAIN_CONTROL_EDITOR 3
306 #define MAIN_CONTROL_INFO 4
307 #define MAIN_CONTROL_GAME 5
308 #define MAIN_CONTROL_SETUP 6
309 #define MAIN_CONTROL_QUIT 7
310 #define MAIN_CONTROL_PREV_LEVEL 8
311 #define MAIN_CONTROL_NEXT_LEVEL 9
312 #define MAIN_CONTROL_FIRST_LEVEL 10
313 #define MAIN_CONTROL_LAST_LEVEL 11
314 #define MAIN_CONTROL_LEVEL_NUMBER 12
315 #define MAIN_CONTROL_LEVEL_INFO_1 13
316 #define MAIN_CONTROL_LEVEL_INFO_2 14
317 #define MAIN_CONTROL_LEVEL_NAME 15
318 #define MAIN_CONTROL_LEVEL_AUTHOR 16
319 #define MAIN_CONTROL_LEVEL_YEAR 17
320 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
321 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
322 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
323 #define MAIN_CONTROL_TITLE_1 21
324 #define MAIN_CONTROL_TITLE_2 22
325 #define MAIN_CONTROL_TITLE_3 23
327 static char str_main_text_name[10];
328 static char str_main_text_first_level[10];
329 static char str_main_text_last_level[10];
330 static char str_main_text_level_number[10];
332 static char *main_text_name = str_main_text_name;
333 static char *main_text_first_level = str_main_text_first_level;
334 static char *main_text_last_level = str_main_text_last_level;
335 static char *main_text_level_number = str_main_text_level_number;
336 static char *main_text_levels = "Levelset";
337 static char *main_text_scores = "Hall Of Fame";
338 static char *main_text_editor = "Level Creator";
339 static char *main_text_info = "Info Screen";
340 static char *main_text_game = "Start Game";
341 static char *main_text_setup = "Setup";
342 static char *main_text_quit = "Quit";
343 static char *main_text_level_name = level.name;
344 static char *main_text_level_author = level.author;
345 static char *main_text_level_year = NULL;
346 static char *main_text_level_imported_from = NULL;
347 static char *main_text_level_imported_by = NULL;
348 static char *main_text_level_tested_by = NULL;
349 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
350 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
351 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
353 struct MainControlInfo
357 struct MenuPosInfo *pos_button;
360 struct TextPosInfo *pos_text;
363 struct TextPosInfo *pos_input;
367 static struct MainControlInfo main_controls[] =
371 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
372 &menu.main.text.name, &main_text_name,
373 &menu.main.input.name, &setup.player_name,
377 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
378 &menu.main.text.levels, &main_text_levels,
383 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
384 &menu.main.text.scores, &main_text_scores,
389 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
390 &menu.main.text.editor, &main_text_editor,
395 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
396 &menu.main.text.info, &main_text_info,
401 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
402 &menu.main.text.game, &main_text_game,
407 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
408 &menu.main.text.setup, &main_text_setup,
413 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
414 &menu.main.text.quit, &main_text_quit,
418 /* (these two buttons are real gadgets) */
420 MAIN_CONTROL_PREV_LEVEL,
421 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
426 MAIN_CONTROL_NEXT_LEVEL,
427 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
433 MAIN_CONTROL_FIRST_LEVEL,
435 &menu.main.text.first_level, &main_text_first_level,
439 MAIN_CONTROL_LAST_LEVEL,
441 &menu.main.text.last_level, &main_text_last_level,
445 MAIN_CONTROL_LEVEL_NUMBER,
447 &menu.main.text.level_number, &main_text_level_number,
451 MAIN_CONTROL_LEVEL_INFO_1,
453 &menu.main.text.level_info_1, NULL,
457 MAIN_CONTROL_LEVEL_INFO_2,
459 &menu.main.text.level_info_2, NULL,
463 MAIN_CONTROL_LEVEL_NAME,
465 &menu.main.text.level_name, &main_text_level_name,
469 MAIN_CONTROL_LEVEL_AUTHOR,
471 &menu.main.text.level_author, &main_text_level_author,
475 MAIN_CONTROL_LEVEL_YEAR,
477 &menu.main.text.level_year, &main_text_level_year,
481 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
483 &menu.main.text.level_imported_from, &main_text_level_imported_from,
487 MAIN_CONTROL_LEVEL_IMPORTED_BY,
489 &menu.main.text.level_imported_by, &main_text_level_imported_by,
493 MAIN_CONTROL_LEVEL_TESTED_BY,
495 &menu.main.text.level_tested_by, &main_text_level_tested_by,
499 MAIN_CONTROL_TITLE_1,
501 &menu.main.text.title_1, &main_text_title_1,
505 MAIN_CONTROL_TITLE_2,
507 &menu.main.text.title_2, &main_text_title_2,
511 MAIN_CONTROL_TITLE_3,
513 &menu.main.text.title_3, &main_text_title_3,
526 static int getTitleScreenGraphic(int nr, boolean initial)
528 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
531 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
533 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
537 static int getTitleScreenGameMode(boolean initial)
539 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
543 static int getTitleMessageGameMode(boolean initial)
545 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
549 static int getTitleScreenBackground(boolean initial)
551 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
556 static int getTitleMessageBackground(int nr, boolean initial)
558 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
562 static int getTitleBackground(int nr, boolean initial, boolean is_image)
564 int base = (is_image ?
565 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
566 IMG_BACKGROUND_TITLESCREEN_1) :
567 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
568 IMG_BACKGROUND_TITLEMESSAGE_1));
569 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
570 IMG_BACKGROUND_TITLE);
571 int graphic_local = base + nr;
573 if (graphic_info[graphic_local].bitmap != NULL)
574 return graphic_local;
576 if (graphic_info[graphic_global].bitmap != NULL)
577 return graphic_global;
579 return IMG_UNDEFINED;
582 static int getTitleSound(struct TitleControlInfo *tci)
584 boolean is_image = tci->is_image;
585 int initial = tci->initial;
586 int nr = tci->local_nr;
587 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
588 int base = (is_image ?
589 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
590 SND_BACKGROUND_TITLESCREEN_1) :
591 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
592 SND_BACKGROUND_TITLEMESSAGE_1));
593 int sound_global = menu.sound[mode];
594 int sound_local = base + nr;
597 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
598 nr, initial, is_image,
599 sound_global, getSoundListEntry(sound_global)->filename,
600 sound_local, getSoundListEntry(sound_local)->filename);
603 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
606 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
609 return SND_UNDEFINED;
612 static int getTitleMusic(struct TitleControlInfo *tci)
614 boolean is_image = tci->is_image;
615 int initial = tci->initial;
616 int nr = tci->local_nr;
617 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
618 int base = (is_image ?
619 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
620 MUS_BACKGROUND_TITLESCREEN_1) :
621 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
622 MUS_BACKGROUND_TITLEMESSAGE_1));
623 int music_global = menu.music[mode];
624 int music_local = base + nr;
627 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
628 nr, initial, is_image,
629 music_global, getMusicListEntry(music_global)->filename,
630 music_local, getMusicListEntry(music_local)->filename);
633 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
636 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
639 return MUS_UNDEFINED;
642 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
644 boolean is_image = tci->is_image;
645 int initial = tci->initial;
646 int nr = tci->local_nr;
647 struct TitleFadingInfo ti;
651 int graphic = getTitleScreenGraphic(nr, initial);
653 /* initialize fading control values to default title config settings */
654 ti = (initial ? title_initial_default : title_default);
656 /* override default settings with image config settings, if defined */
657 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
658 ti.fade_mode = graphic_info[graphic].fade_mode;
659 if (graphic_info[graphic].fade_delay > -1)
660 ti.fade_delay = graphic_info[graphic].fade_delay;
661 if (graphic_info[graphic].post_delay > -1)
662 ti.post_delay = graphic_info[graphic].post_delay;
663 if (graphic_info[graphic].auto_delay > -1)
664 ti.auto_delay = graphic_info[graphic].auto_delay;
670 ti.fade_mode = titlemessage_initial[nr].fade_mode;
671 ti.fade_delay = titlemessage_initial[nr].fade_delay;
672 ti.post_delay = titlemessage_initial[nr].post_delay;
673 ti.auto_delay = titlemessage_initial[nr].auto_delay;
677 ti.fade_mode = titlemessage[nr].fade_mode;
678 ti.fade_delay = titlemessage[nr].fade_delay;
679 ti.post_delay = titlemessage[nr].post_delay;
680 ti.auto_delay = titlemessage[nr].auto_delay;
685 if (ti.anim_mode == ANIM_NONE)
686 ti.fade_delay = ti.post_delay = 0;
692 static int compareTitleControlInfo(const void *object1, const void *object2)
694 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
695 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
698 if (tci1->initial != tci2->initial)
699 compare_result = (tci1->initial ? -1 : +1);
700 else if (tci1->sort_priority != tci2->sort_priority)
701 compare_result = tci1->sort_priority - tci2->sort_priority;
702 else if (tci1->is_image != tci2->is_image)
703 compare_result = (tci1->is_image ? -1 : +1);
705 compare_result = tci1->local_nr - tci2->local_nr;
707 return compare_result;
710 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
712 int nr, int sort_priority)
714 title_controls[num_title_screens].is_image = is_image;
715 title_controls[num_title_screens].initial = initial;
716 title_controls[num_title_screens].local_nr = nr;
717 title_controls[num_title_screens].sort_priority = sort_priority;
722 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
726 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
728 int graphic = getTitleScreenGraphic(i, initial);
729 Bitmap *bitmap = graphic_info[graphic].bitmap;
730 int sort_priority = graphic_info[graphic].sort_priority;
733 /* skip images and messages (fonts!) when using forced custom graphics */
734 if (setup.override_level_graphics && !initial)
739 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
742 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
744 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
745 char *filename = getLevelSetTitleMessageFilename(i, initial);
746 int sort_priority = tmi->sort_priority;
749 /* skip images and messages (fonts!) when using forced custom graphics */
750 if (setup.override_level_graphics)
754 if (filename != NULL)
755 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
759 static void InitializeTitleControls(boolean show_title_initial)
761 num_title_screens = 0;
764 /* 1st step: initialize title screens for game start (only when starting) */
765 if (show_title_initial)
766 InitializeTitleControls_CheckTitleInfo(TRUE);
769 /* 2nd step: initialize title screens for current level set */
770 InitializeTitleControls_CheckTitleInfo(FALSE);
772 /* sort title screens according to sort_priority and title number */
773 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
774 compareTitleControlInfo);
777 static boolean visibleMenuPos(struct MenuPosInfo *pos)
779 return (pos != NULL && pos->x != -1 && pos->y != -1);
782 static boolean visibleTextPos(struct TextPosInfo *pos)
784 return (pos != NULL && pos->x != -1 && pos->y != -1);
787 static void InitializeMainControls()
789 boolean local_team_mode = (!options.network && setup.team_mode);
792 /* set main control text values to dynamically determined values */
793 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
795 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
796 menu.main.text.first_level.size));
797 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
798 menu.main.text.last_level.size));
799 strcpy(main_text_level_number, int2str(level_nr,
800 menu.main.text.level_number.size));
802 main_text_level_year = leveldir_current->year;
803 main_text_level_imported_from = leveldir_current->imported_from;
804 main_text_level_imported_by = leveldir_current->imported_by;
805 main_text_level_tested_by = leveldir_current->tested_by;
807 /* set main control screen positions to dynamically determined values */
808 for (i = 0; main_controls[i].nr != -1; i++)
810 struct MainControlInfo *mci = &main_controls[i];
812 struct MenuPosInfo *pos_button = mci->pos_button;
813 struct TextPosInfo *pos_text = mci->pos_text;
814 struct TextPosInfo *pos_input = mci->pos_input;
815 char *text = (mci->text ? *mci->text : NULL);
816 char *input = (mci->input ? *mci->input : NULL);
817 int button_graphic = mci->button_graphic;
819 int font_text = (pos_text ? pos_text->font : -1);
820 int font_input = (pos_input ? pos_input->font : -1);
822 int font_text = mci->font_text;
823 int font_input = mci->font_input;
826 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
827 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
828 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
829 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
830 int text_chars = (text != NULL ? strlen(text) : 0);
831 int input_chars = (input != NULL ? strlen(input) : 0);
834 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
836 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
837 int text_width = font_text_width * text_chars;
838 int text_height = font_text_height;
839 int input_width = font_input_width * input_chars;
840 int input_height = font_input_height;
842 if (nr == MAIN_CONTROL_NAME)
845 if (menu.main.input.name.x == -1)
846 menu.main.input.name.x = menu.main.text.name.x + text_width;
847 if (menu.main.input.name.y == -1)
848 menu.main.input.name.y = menu.main.text.name.y;
852 menu.main.input.name.width = input_width;
853 menu.main.input.name.height = input_height;
855 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
856 menu.main.input.name.height = font_input_height;
860 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
862 if (pos_button->width == 0)
863 pos_button->width = button_width;
864 if (pos_button->height == 0)
865 pos_button->height = button_height;
868 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
870 /* calculate width for non-clickable text -- needed for text alignment */
871 boolean calculate_text_width = (pos_button == NULL && text != NULL);
873 if (visibleMenuPos(pos_button))
875 if (pos_text->x == -1)
876 pos_text->x = pos_button->x + pos_button->width;
877 if (pos_text->y == -1)
878 pos_text->y = pos_button->y;
881 if (pos_text->width == -1 || calculate_text_width)
882 pos_text->width = text_width;
883 if (pos_text->height == -1)
884 pos_text->height = text_height;
887 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
889 if (visibleTextPos(pos_text))
891 if (pos_input->x == -1)
892 pos_input->x = pos_text->x + pos_text->width;
893 if (pos_input->y == -1)
894 pos_input->y = pos_text->y;
897 if (pos_input->width == -1)
898 pos_input->width = input_width;
899 if (pos_input->height == -1)
900 pos_input->height = input_height;
905 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
906 boolean active_input)
910 for (i = 0; main_controls[i].nr != -1; i++)
912 struct MainControlInfo *mci = &main_controls[i];
914 if (mci->nr == nr || nr == -1)
916 struct MenuPosInfo *pos_button = mci->pos_button;
917 struct TextPosInfo *pos_text = mci->pos_text;
918 struct TextPosInfo *pos_input = mci->pos_input;
919 char *text = (mci->text ? *mci->text : NULL);
920 char *input = (mci->input ? *mci->input : NULL);
921 int button_graphic = mci->button_graphic;
923 int font_text = (pos_text ? pos_text->font : -1);
924 int font_input = (pos_input ? pos_input->font : -1);
926 int font_text = mci->font_text;
927 int font_input = mci->font_input;
932 button_graphic = BUTTON_ACTIVE(button_graphic);
933 font_text = FONT_ACTIVE(font_text);
938 font_input = FONT_ACTIVE(font_input);
941 if (visibleMenuPos(pos_button))
943 struct MenuPosInfo *pos = pos_button;
944 int x = mSX + pos->x;
945 int y = mSY + pos->y;
947 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
948 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
951 if (visibleTextPos(pos_text) && text != NULL)
953 struct TextPosInfo *pos = pos_text;
954 int x = mSX + ALIGNED_TEXT_XPOS(pos);
955 int y = mSY + ALIGNED_TEXT_YPOS(pos);
958 /* (check why/if this is needed) */
959 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
961 DrawText(x, y, text, font_text);
964 if (visibleTextPos(pos_input) && input != NULL)
966 struct TextPosInfo *pos = pos_input;
967 int x = mSX + ALIGNED_TEXT_XPOS(pos);
968 int y = mSY + ALIGNED_TEXT_YPOS(pos);
971 /* (check why/if this is needed) */
972 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
974 DrawText(x, y, input, font_input);
980 static void DrawCursorAndText_Main(int nr, boolean active_text)
982 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
986 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
988 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
992 static struct MainControlInfo *getMainControlInfo(int nr)
996 for (i = 0; main_controls[i].nr != -1; i++)
997 if (main_controls[i].nr == nr)
998 return &main_controls[i];
1003 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1008 int rect_x = ALIGNED_TEXT_XPOS(rect);
1009 int rect_y = ALIGNED_TEXT_YPOS(rect);
1011 return (x >= rect_x && x < rect_x + rect->width &&
1012 y >= rect_y && y < rect_y + rect->height);
1015 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1020 int rect_x = ALIGNED_TEXT_XPOS(rect);
1021 int rect_y = ALIGNED_TEXT_YPOS(rect);
1023 return (x >= rect_x && x < rect_x + rect->width &&
1024 y >= rect_y && y < rect_y + rect->height);
1027 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1030 static int cursor_array[MAX_LEV_FIELDY];
1032 static int cursor_array[SCR_FIELDY];
1034 int x = mSX + TILEX * xpos;
1035 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1040 cursor_array[ypos] = graphic;
1042 graphic = cursor_array[ypos];
1046 graphic = BUTTON_ACTIVE(graphic);
1048 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1049 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1052 static void initCursor(int ypos, int graphic)
1054 drawCursorExt(0, ypos, FALSE, graphic);
1057 static void drawCursor(int ypos, boolean active)
1059 drawCursorExt(0, ypos, active, -1);
1062 static void drawCursorXY(int xpos, int ypos, int graphic)
1064 drawCursorExt(xpos, ypos, FALSE, graphic);
1067 static void drawChooseTreeCursor(int ypos, boolean active)
1069 int last_game_status = game_status; /* save current game status */
1072 /* force LEVELS draw offset on artwork setup screen */
1073 game_status = GAME_MODE_LEVELS;
1076 drawCursorExt(0, ypos, active, -1);
1078 game_status = last_game_status; /* restore current game status */
1083 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1084 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1088 static int getPrevlevelButtonPos()
1093 static int getCurrentLevelTextPos()
1095 return (getPrevlevelButtonPos() + 1);
1098 static int getNextLevelButtonPos()
1100 return getPrevlevelButtonPos() + 3 + 1;
1103 static int getLevelRangeTextPos()
1105 return getNextLevelButtonPos() + 1;
1109 int effectiveGameStatus()
1111 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1112 return GAME_MODE_TITLE;
1117 void DrawTitleScreenImage(int nr, boolean initial)
1119 int graphic = getTitleScreenGraphic(nr, initial);
1120 Bitmap *bitmap = graphic_info[graphic].bitmap;
1121 int width = graphic_info[graphic].width;
1122 int height = graphic_info[graphic].height;
1123 int src_x = graphic_info[graphic].src_x;
1124 int src_y = graphic_info[graphic].src_y;
1130 if (width > WIN_XSIZE)
1132 /* image width too large for window => center image horizontally */
1133 src_x = (width - WIN_XSIZE) / 2;
1137 if (height > WIN_YSIZE)
1139 /* image height too large for window => center image vertically */
1140 src_y = (height - WIN_YSIZE) / 2;
1144 /* always display title screens centered */
1145 dst_x = (WIN_XSIZE - width) / 2;
1146 dst_y = (WIN_YSIZE - height) / 2;
1148 SetDrawBackgroundMask(REDRAW_ALL);
1149 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1151 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1153 if (DrawingOnBackground(dst_x, dst_y))
1155 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1156 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1159 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1161 redraw_mask = REDRAW_ALL;
1164 void DrawTitleScreenMessage(int nr, boolean initial)
1166 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1167 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1168 int last_game_status = game_status; /* save current game status */
1170 if (filename == NULL)
1173 /* force TITLE font on title message screen */
1174 game_status = getTitleMessageGameMode(initial);
1176 /* if chars set to "-1", automatically determine by text and font width */
1177 if (tmi->chars == -1)
1178 tmi->chars = tmi->width / getFontWidth(tmi->font);
1180 tmi->width = tmi->chars * getFontWidth(tmi->font);
1182 /* if lines set to "-1", automatically determine by text and font height */
1183 if (tmi->lines == -1)
1184 tmi->lines = tmi->height / getFontHeight(tmi->font);
1186 tmi->height = tmi->lines * getFontHeight(tmi->font);
1188 SetDrawBackgroundMask(REDRAW_ALL);
1189 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1191 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1193 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1194 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1195 tmi->autowrap, tmi->centered, tmi->parse_comments);
1197 game_status = last_game_status; /* restore current game status */
1200 void DrawTitleScreen()
1202 KeyboardAutoRepeatOff();
1205 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1208 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1213 boolean CheckTitleScreen(boolean levelset_has_changed)
1215 static boolean show_title_initial = TRUE;
1216 boolean show_titlescreen = FALSE;
1218 /* needed to be able to skip title screen, if no image or message defined */
1219 InitializeTitleControls(show_title_initial);
1221 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1222 show_titlescreen = TRUE;
1224 /* show initial title images and messages only once at program start */
1225 show_title_initial = FALSE;
1227 return (show_titlescreen && num_title_screens > 0);
1230 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1232 static LevelDirTree *leveldir_last_valid = NULL;
1233 boolean levelset_has_changed = FALSE;
1235 FadeSetLeaveScreen();
1237 /* do not fade out here -- function may continue and fade on editor screen */
1240 FadeSoundsAndMusic();
1242 KeyboardAutoRepeatOn();
1245 SetDrawDeactivationMask(REDRAW_NONE);
1246 SetDrawBackgroundMask(REDRAW_FIELD);
1248 audio.sound_deactivated = FALSE;
1252 /* needed if last screen was the playing screen, invoked from level editor */
1253 if (level_editor_test_game)
1255 game_status = GAME_MODE_EDITOR;
1261 /* needed if last screen was the setup screen and fullscreen state changed */
1262 ToggleFullscreenIfNeeded();
1264 /* leveldir_current may be invalid (level group, parent link) */
1265 if (!validLevelSeries(leveldir_current))
1266 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1268 if (leveldir_current != leveldir_last_valid)
1269 levelset_has_changed = TRUE;
1271 /* store valid level series information */
1272 leveldir_last_valid = leveldir_current;
1274 init_last = init; /* switch to new busy animation */
1276 /* needed if last screen (level choice) changed graphics, sounds or music */
1277 ReloadCustomArtwork(0);
1279 if (redraw_mask & REDRAW_ALL)
1280 fade_mask = REDRAW_ALL;
1285 /* needed if last screen was the editor screen */
1286 UndrawSpecialEditorDoor();
1288 if (fade_mask == REDRAW_FIELD)
1294 /* needed if different viewport properties defined for menues */
1295 ChangeViewportPropertiesIfNeeded();
1298 #if defined(TARGET_SDL)
1299 SetDrawtoField(DRAW_BACKBUFFER);
1302 if (CheckTitleScreen(levelset_has_changed))
1304 game_status = GAME_MODE_TITLE;
1311 /* level_nr may have been set to value over handicap with level editor */
1312 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1313 level_nr = leveldir_current->handicap_level;
1315 LoadLevel(level_nr);
1316 LoadScore(level_nr);
1318 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1321 if (fade_mask == REDRAW_ALL)
1323 // int door_state = GetDoorState();
1327 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1333 InitializeMainControls();
1335 DrawCursorAndText_Main(-1, FALSE);
1336 DrawPreviewLevel(TRUE);
1338 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1341 if (TAPE_IS_EMPTY(tape))
1343 DrawCompleteVideoDisplay();
1348 /* create gadgets for main menu screen */
1349 FreeScreenGadgets();
1350 CreateScreenGadgets();
1352 /* map gadgets for main menu screen */
1354 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1357 if (fade_mask == REDRAW_ALL)
1359 int door_state = GetDoorState();
1361 // RedrawBackground();
1363 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1367 DrawMaskedBorder(REDRAW_ALL);
1373 /* update screen area with special editor door */
1374 redraw_mask |= REDRAW_ALL;
1378 SetMouseCursor(CURSOR_DEFAULT);
1382 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1385 void DrawAndFadeInMainMenu(int fade_mask)
1387 DrawMainMenuExt(fade_mask, TRUE);
1392 DrawMainMenuExt(REDRAW_ALL, FALSE);
1395 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1396 static void gotoTopLevelDir()
1398 /* move upwards to top level directory */
1399 while (leveldir_current->node_parent)
1401 /* write a "path" into level tree for easy navigation to last level */
1402 if (leveldir_current->node_parent->node_group->cl_first == -1)
1404 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1405 int leveldir_pos = posTreeInfo(leveldir_current);
1406 int num_page_entries;
1407 int cl_first, cl_cursor;
1409 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1410 num_page_entries = num_leveldirs;
1412 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1414 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1415 cl_cursor = leveldir_pos - cl_first;
1417 leveldir_current->node_parent->node_group->cl_first = cl_first;
1418 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1421 leveldir_current = leveldir_current->node_parent;
1426 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1428 static unsigned long title_delay = 0;
1429 static int title_screen_nr = 0;
1430 static int last_sound = -1, last_music = -1;
1431 boolean return_to_main_menu = FALSE;
1432 boolean use_fading_main_menu = TRUE;
1433 struct TitleControlInfo *tci;
1434 struct TitleFadingInfo fading_default;
1435 struct TitleFadingInfo fading_last = fading;
1436 struct TitleFadingInfo fading_next;
1439 if (button == MB_MENU_INITIALIZE)
1442 title_screen_nr = 0;
1443 tci = &title_controls[title_screen_nr];
1445 last_sound = SND_UNDEFINED;
1446 last_music = MUS_UNDEFINED;
1448 if (game_status == GAME_MODE_INFO)
1450 if (num_title_screens == 0)
1452 DrawInfoScreen_NotAvailable("Title screen information:",
1453 "No title screen for this level set.");
1458 FadeSoundsAndMusic();
1461 FadeOut(REDRAW_ALL);
1466 DrawTitleScreenImage(tci->local_nr, tci->initial);
1468 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1470 fading_default = (tci->initial ? title_initial_default : title_default);
1472 fading = fading_next = getTitleFading(tci);
1476 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1477 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1479 fading.fade_mode = FADE_MODE_FADE;
1480 fading.fade_delay = fading_default.fade_delay;
1483 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1484 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1485 fading.fade_mode = FADE_MODE_FADE;
1490 sound = getTitleSound(tci);
1491 music = getTitleMusic(tci);
1493 if (sound != last_sound)
1494 PlayMenuSoundExt(sound);
1495 if (music != last_music)
1496 PlayMenuMusicExt(music);
1502 SetMouseCursor(CURSOR_NONE);
1508 fading = fading_next;
1510 DelayReached(&title_delay, 0); /* reset delay counter */
1516 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1517 button = MB_MENU_CHOICE;
1519 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1520 button = MB_MENU_CHOICE;
1523 if (button == MB_MENU_LEAVE)
1525 return_to_main_menu = TRUE;
1526 use_fading_main_menu = FALSE;
1528 else if (button == MB_MENU_CHOICE)
1530 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1533 FadeOut(REDRAW_FIELD);
1536 FadeSetEnterScreen();
1538 info_mode = INFO_MODE_MAIN;
1539 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1545 tci = &title_controls[title_screen_nr];
1547 if (title_screen_nr < num_title_screens)
1549 sound = getTitleSound(tci);
1550 music = getTitleMusic(tci);
1552 if (sound == SND_UNDEFINED || sound != last_sound)
1554 if (music == MUS_UNDEFINED || music != last_music)
1558 FadeOut(REDRAW_ALL);
1562 DrawTitleScreenImage(tci->local_nr, tci->initial);
1564 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1566 fading_next = getTitleFading(tci);
1569 sound = getTitleSound(tci);
1570 music = getTitleMusic(tci);
1572 if (sound != last_sound)
1573 PlayMenuSoundExt(sound);
1574 if (music != last_music)
1575 PlayMenuMusicExt(music);
1582 /* last screen already faded out, next screen has no animation */
1583 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1584 fading_next.fade_mode == FADE_MODE_NONE)
1585 fading = fading_next;
1587 /* last screen already faded out, next screen has no animation */
1588 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1589 fading_next.fade_mode == FADE_MODE_NONE)
1590 fading = fading_next;
1597 fading = fading_next;
1599 DelayReached(&title_delay, 0); /* reset delay counter */
1603 FadeSoundsAndMusic();
1605 return_to_main_menu = TRUE;
1609 if (return_to_main_menu)
1615 SetMouseCursor(CURSOR_DEFAULT);
1617 if (game_status == GAME_MODE_INFO)
1620 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1623 info_mode = INFO_MODE_MAIN;
1624 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1626 else /* default: return to main menu */
1629 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1632 game_status = GAME_MODE_MAIN;
1633 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1638 void HandleMainMenu_SelectLevel(int step, int direction)
1640 int old_level_nr = level_nr;
1643 new_level_nr = old_level_nr + step * direction;
1644 if (new_level_nr < leveldir_current->first_level)
1645 new_level_nr = leveldir_current->first_level;
1646 if (new_level_nr > leveldir_current->last_level)
1647 new_level_nr = leveldir_current->last_level;
1649 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1651 /* skipping levels is only allowed when trying to skip single level */
1652 if (setup.skip_levels && step == 1 &&
1653 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1655 leveldir_current->handicap_level++;
1656 SaveLevelSetup_SeriesInfo();
1659 new_level_nr = leveldir_current->handicap_level;
1662 if (new_level_nr != old_level_nr)
1664 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1666 PlaySound(SND_MENU_ITEM_SELECTING);
1668 level_nr = new_level_nr;
1670 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1671 int2str(level_nr, menu.main.text.level_number.size),
1672 mci->pos_text->font);
1674 LoadLevel(level_nr);
1675 DrawPreviewLevel(TRUE);
1679 DrawCompleteVideoDisplay();
1681 /* needed because DrawPreviewLevel() takes some time */
1687 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1689 static int choice = MAIN_CONTROL_GAME;
1693 if (button == MB_MENU_INITIALIZE)
1695 DrawCursorAndText_Main(choice, TRUE);
1700 if (mx || my) /* mouse input */
1704 for (i = 0; main_controls[i].nr != -1; i++)
1706 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1707 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1708 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1710 pos = main_controls[i].nr;
1716 else if (dx || dy) /* keyboard input */
1718 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1719 choice == MAIN_CONTROL_SETUP))
1720 button = MB_MENU_CHOICE;
1725 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1727 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1729 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1735 PlaySound(SND_MENU_ITEM_ACTIVATING);
1737 DrawCursorAndText_Main(choice, FALSE);
1738 DrawCursorAndText_Main(pos, TRUE);
1745 PlaySound(SND_MENU_ITEM_SELECTING);
1747 if (pos == MAIN_CONTROL_NAME)
1749 game_status = GAME_MODE_PSEUDO_TYPENAME;
1751 HandleTypeName(strlen(setup.player_name), 0);
1753 else if (pos == MAIN_CONTROL_LEVELS)
1757 game_status = GAME_MODE_LEVELS;
1759 SaveLevelSetup_LastSeries();
1760 SaveLevelSetup_SeriesInfo();
1762 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1769 else if (pos == MAIN_CONTROL_SCORES)
1771 game_status = GAME_MODE_SCORES;
1775 else if (pos == MAIN_CONTROL_EDITOR)
1777 if (leveldir_current->readonly &&
1778 !strEqual(setup.player_name, "Artsoft"))
1779 Request("This level is read only !", REQ_CONFIRM);
1781 game_status = GAME_MODE_EDITOR;
1783 FadeSetEnterScreen();
1786 /* needed if different viewport properties defined for editor */
1787 ChangeViewportPropertiesIfNeeded();
1792 else if (pos == MAIN_CONTROL_INFO)
1794 game_status = GAME_MODE_INFO;
1795 info_mode = INFO_MODE_MAIN;
1799 else if (pos == MAIN_CONTROL_GAME)
1801 StartGameActions(options.network, setup.autorecord, level.random_seed);
1803 else if (pos == MAIN_CONTROL_SETUP)
1805 game_status = GAME_MODE_SETUP;
1806 setup_mode = SETUP_MODE_MAIN;
1810 else if (pos == MAIN_CONTROL_QUIT)
1812 SaveLevelSetup_LastSeries();
1813 SaveLevelSetup_SeriesInfo();
1815 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1816 game_status = GAME_MODE_QUIT;
1821 if (game_status == GAME_MODE_MAIN)
1823 DrawPreviewLevel(FALSE);
1829 /* ========================================================================= */
1830 /* info screen functions */
1831 /* ========================================================================= */
1833 static struct TokenInfo *info_info;
1834 static int num_info_info;
1836 static void execInfoTitleScreen()
1838 info_mode = INFO_MODE_TITLE;
1843 static void execInfoElements()
1845 info_mode = INFO_MODE_ELEMENTS;
1850 static void execInfoMusic()
1852 info_mode = INFO_MODE_MUSIC;
1857 static void execInfoCredits()
1859 info_mode = INFO_MODE_CREDITS;
1864 static void execInfoProgram()
1866 info_mode = INFO_MODE_PROGRAM;
1871 static void execInfoVersion()
1873 info_mode = INFO_MODE_VERSION;
1878 static void execInfoLevelSet()
1880 info_mode = INFO_MODE_LEVELSET;
1885 static void execExitInfo()
1887 game_status = GAME_MODE_MAIN;
1889 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1892 static struct TokenInfo info_info_main[] =
1894 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1895 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1896 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1897 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1898 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1899 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1900 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1901 { TYPE_EMPTY, NULL, "" },
1902 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1907 static void DrawCursorAndText_Info(int pos, boolean active)
1909 int xpos = MENU_SCREEN_START_XPOS;
1910 int ypos = MENU_SCREEN_START_YPOS + pos;
1911 int font_nr = FONT_MENU_1;
1914 font_nr = FONT_ACTIVE(font_nr);
1916 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1918 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1919 drawCursor(pos, active);
1922 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1927 CloseDoor(DOOR_CLOSE_2);
1929 /* (needed after displaying title screens which disable auto repeat) */
1930 KeyboardAutoRepeatOn();
1932 FadeSetLeaveScreen();
1939 if (fade_mask == REDRAW_ALL)
1943 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1949 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1951 info_info = info_info_main;
1955 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1957 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1960 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1961 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1962 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1963 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1964 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1965 initCursor(i, IMG_MENU_BUTTON);
1967 DrawCursorAndText_Info(i, FALSE);
1972 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1977 DrawMaskedBorder(fade_mask);
1984 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1986 static int choice_store[MAX_INFO_MODES];
1987 int choice = choice_store[info_mode]; /* always starts with 0 */
1991 if (button == MB_MENU_INITIALIZE)
1993 /* advance to first valid menu entry */
1994 while (choice < num_info_info &&
1995 info_info[choice].type & TYPE_SKIP_ENTRY)
1997 choice_store[info_mode] = choice;
1999 DrawCursorAndText_Info(choice, TRUE);
2003 else if (button == MB_MENU_LEAVE)
2005 for (y = 0; y < num_info_info; y++)
2007 if (info_info[y].type & TYPE_LEAVE_MENU)
2009 void (*menu_callback_function)(void) = info_info[y].value;
2013 menu_callback_function();
2015 break; /* absolutely needed because function changes 'info_info'! */
2022 if (mx || my) /* mouse input */
2024 x = (mx - mSX) / 32;
2025 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2027 else if (dx || dy) /* keyboard input */
2031 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2033 if (info_info[choice].type & menu_navigation_type ||
2034 info_info[choice].type & TYPE_ENTER_SCREEN ||
2035 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2036 info_info[choice].type & TYPE_YES_NO_AUTO)
2037 button = MB_MENU_CHOICE;
2042 /* jump to next non-empty menu entry (up or down) */
2043 while (y > 0 && y < num_info_info - 1 &&
2044 info_info[y].type & TYPE_SKIP_ENTRY)
2048 if (IN_VIS_FIELD(x, y) &&
2049 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2055 PlaySound(SND_MENU_ITEM_ACTIVATING);
2057 DrawCursorAndText_Info(choice, FALSE);
2058 DrawCursorAndText_Info(y, TRUE);
2060 choice = choice_store[info_mode] = y;
2063 else if (!(info_info[y].type & TYPE_GHOSTED))
2065 PlaySound(SND_MENU_ITEM_SELECTING);
2067 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2069 void (*menu_callback_function)(void) = info_info[choice].value;
2071 FadeSetFromType(info_info[y].type);
2073 menu_callback_function();
2079 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2081 int ystart1 = mSY - SY + 100;
2082 int ystart2 = mSY - SY + 150;
2083 int ybottom = mSY - SY + SYSIZE - 20;
2085 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2087 FadeOut(REDRAW_FIELD);
2092 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2093 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2095 DrawTextSCentered(ybottom, FONT_TEXT_4,
2096 "Press any key or button for info menu");
2098 FadeIn(REDRAW_FIELD);
2101 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2103 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2104 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2105 int xstart = mSX + 16;
2106 int ystart1 = mSY - SY + 100;
2107 int ystart2 = mSY + 64 + 2 * 32;
2108 int ybottom = mSY - SY + SYSIZE - 20;
2109 int ystep = TILEY + 4;
2110 int element, action, direction;
2118 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2119 infoscreen_step[i] = infoscreen_frame[i] = 0;
2124 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2126 DrawTextSCentered(ybottom, FONT_TEXT_4,
2127 "Press any key or button for next page");
2133 while (helpanim_info[j].element != HELPANIM_LIST_END)
2135 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2140 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2149 j += infoscreen_step[i - start];
2151 element = helpanim_info[j].element;
2152 action = helpanim_info[j].action;
2153 direction = helpanim_info[j].direction;
2156 element = EL_UNKNOWN;
2158 if (action != -1 && direction != -1)
2159 graphic = el_act_dir2img(element, action, direction);
2160 else if (action != -1)
2161 graphic = el_act2img(element, action);
2162 else if (direction != -1)
2163 graphic = el_dir2img(element, direction);
2165 graphic = el2img(element);
2167 delay = helpanim_info[j++].delay;
2172 if (infoscreen_frame[i - start] == 0)
2175 infoscreen_frame[i - start] = delay - 1;
2179 sync_frame = delay - infoscreen_frame[i - start];
2180 infoscreen_frame[i - start]--;
2183 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2185 if (!infoscreen_frame[i - start])
2186 infoscreen_step[i - start] = 0;
2190 if (!infoscreen_frame[i - start])
2191 infoscreen_step[i - start]++;
2192 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2198 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2200 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2201 graphic, sync_frame, USE_MASKING);
2204 DrawInfoScreen_HelpText(element, action, direction, i - start);
2209 redraw_mask |= REDRAW_FIELD;
2214 static char *getHelpText(int element, int action, int direction)
2216 char token[MAX_LINE_LEN];
2218 strcpy(token, element_info[element].token_name);
2221 strcat(token, element_action_info[action].suffix);
2223 if (direction != -1)
2224 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2226 return getHashEntry(helptext_info, token);
2229 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2231 int font_nr = FONT_INFO_ELEMENTS;
2232 int font_width = getFontWidth(font_nr);
2233 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2234 int sy = mSY + 65 + 2 * 32 + 1;
2235 int ystep = TILEY + 4;
2236 int pad_x = sx - SX;
2237 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2238 int max_lines_per_text = 2;
2241 if (action != -1 && direction != -1) /* element.action.direction */
2242 text = getHelpText(element, action, direction);
2244 if (text == NULL && action != -1) /* element.action */
2245 text = getHelpText(element, action, -1);
2247 if (text == NULL && direction != -1) /* element.direction */
2248 text = getHelpText(element, -1, direction);
2250 if (text == NULL) /* base element */
2251 text = getHelpText(element, -1, -1);
2253 if (text == NULL) /* not found */
2254 text = "No description available";
2256 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2257 sy += getFontHeight(font_nr) / 2;
2259 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2260 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2261 TRUE, FALSE, FALSE);
2264 void DrawInfoScreen_TitleScreen()
2269 void HandleInfoScreen_TitleScreen(int button)
2271 HandleTitleScreen(0, 0, 0, 0, button);
2274 void DrawInfoScreen_Elements()
2276 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2278 FadeOut(REDRAW_FIELD);
2283 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2285 FadeIn(REDRAW_FIELD);
2290 void HandleInfoScreen_Elements(int button)
2292 static unsigned long info_delay = 0;
2293 static int num_anims;
2294 static int num_pages;
2296 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2299 if (button == MB_MENU_INITIALIZE)
2301 boolean new_element = TRUE;
2305 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2307 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2309 else if (new_element)
2312 new_element = FALSE;
2316 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2320 if (button == MB_MENU_LEAVE)
2322 PlaySound(SND_MENU_ITEM_SELECTING);
2324 info_mode = INFO_MODE_MAIN;
2329 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2331 if (button != MB_MENU_INITIALIZE)
2333 PlaySound(SND_MENU_ITEM_SELECTING);
2338 if (page >= num_pages)
2340 FadeSoundsAndMusic();
2342 info_mode = INFO_MODE_MAIN;
2343 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2350 FadeSetNextScreen();
2353 if (button != MB_MENU_INITIALIZE)
2354 FadeOut(REDRAW_FIELD);
2356 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2358 if (button != MB_MENU_INITIALIZE)
2359 FadeIn(REDRAW_FIELD);
2363 if (DelayReached(&info_delay, GameFrameDelay))
2364 if (page < num_pages)
2365 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2367 PlayMenuSoundIfLoop();
2371 void DrawInfoScreen_Music()
2373 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2376 FadeOut(REDRAW_FIELD);
2384 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2387 FadeIn(REDRAW_FIELD);
2391 void HandleInfoScreen_Music(int button)
2393 static struct MusicFileInfo *list = NULL;
2394 int ystart1 = mSY - SY + 100;
2395 int ystart2 = mSY - SY + 150;
2396 int ybottom = mSY - SY + SYSIZE - 20;
2399 if (button == MB_MENU_INITIALIZE)
2401 list = music_file_info;
2405 FadeSoundsAndMusic();
2410 DrawTextSCentered(ystart1, FONT_TEXT_1,
2411 "No music info for this level set.");
2413 DrawTextSCentered(ybottom, FONT_TEXT_4,
2414 "Press any key or button for info menu");
2420 if (button == MB_MENU_LEAVE)
2422 PlaySound(SND_MENU_ITEM_SELECTING);
2424 FadeSoundsAndMusic();
2426 info_mode = INFO_MODE_MAIN;
2431 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2435 if (button != MB_MENU_INITIALIZE)
2437 PlaySound(SND_MENU_ITEM_SELECTING);
2445 FadeSoundsAndMusic();
2447 info_mode = INFO_MODE_MAIN;
2448 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2453 FadeSoundsAndMusic();
2456 if (list != music_file_info)
2457 FadeSetNextScreen();
2460 if (button != MB_MENU_INITIALIZE)
2461 FadeOut(REDRAW_FIELD);
2468 int sound = list->music;
2470 if (sound_info[sound].loop)
2471 PlaySoundLoop(sound);
2475 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2479 PlayMusic(list->music);
2481 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2484 if (!strEqual(list->title, UNKNOWN_NAME))
2486 if (!strEqual(list->title_header, UNKNOWN_NAME))
2487 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2489 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2492 if (!strEqual(list->artist, UNKNOWN_NAME))
2494 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2495 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2497 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2499 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2502 if (!strEqual(list->album, UNKNOWN_NAME))
2504 if (!strEqual(list->album_header, UNKNOWN_NAME))
2505 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2507 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2509 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2512 if (!strEqual(list->year, UNKNOWN_NAME))
2514 if (!strEqual(list->year_header, UNKNOWN_NAME))
2515 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2517 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2519 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2522 DrawTextSCentered(ybottom, FONT_TEXT_4,
2523 "Press any key or button for next page");
2525 if (button != MB_MENU_INITIALIZE)
2526 FadeIn(REDRAW_FIELD);
2529 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2530 PlaySoundLoop(list->music);
2533 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2535 int ystart1 = mSY - SY + 100;
2536 int ystart2 = mSY - SY + 150;
2537 int ybottom = mSY - SY + SYSIZE - 20;
2543 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2547 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2548 "Special thanks to");
2549 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2551 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2553 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2554 "\"Boulder Dash\"");
2555 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2557 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2559 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2561 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2562 "First Star Software");
2564 else if (screen_nr == 1)
2566 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2567 "Special thanks to");
2568 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2569 "Klaus Heinz & Volker Wertich");
2570 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2572 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2573 "\"Emerald Mine\"");
2574 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2576 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2578 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2580 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2583 else if (screen_nr == 2)
2585 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2586 "Special thanks to");
2587 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2588 "Michael Stopp & Philip Jespersen");
2589 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2591 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2593 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2595 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2597 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2599 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2600 "Digital Integration");
2602 else if (screen_nr == 3)
2604 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2605 "Special thanks to");
2606 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2607 "Hiroyuki Imabayashi");
2608 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2610 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2612 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2614 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2616 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2618 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2621 else if (screen_nr == 4)
2623 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2624 "Special thanks to");
2625 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2627 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2629 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2630 "Jürgen Bonhagen");
2631 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2632 "for the continuous creation");
2633 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2634 "of outstanding level sets");
2636 else if (screen_nr == 5)
2638 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2640 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2642 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2643 "for ideas and inspiration by");
2644 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2647 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2649 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2651 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2652 "for ideas and inspiration by");
2653 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2656 else if (screen_nr == 6)
2658 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2660 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2663 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2664 "for the code base used for the");
2665 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2666 "native Emerald Mine engine");
2668 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2669 "for the new Emerald Mine engine");
2672 else if (screen_nr == 7)
2674 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2676 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2678 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2679 "for the initial DOS port");
2681 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2683 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2685 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2686 "for some additional toons");
2688 else if (screen_nr == 8)
2690 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2691 "And not to forget:");
2692 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2694 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2695 "All those who contributed");
2696 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2697 "levels to this game");
2698 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2702 DrawTextSCentered(ybottom, FONT_TEXT_4,
2703 "Press any key or button for next page");
2706 void DrawInfoScreen_Credits()
2708 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2710 FadeSoundsAndMusic();
2713 FadeOut(REDRAW_FIELD);
2716 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2719 FadeIn(REDRAW_FIELD);
2723 void HandleInfoScreen_Credits(int button)
2725 static int screen_nr = 0;
2726 int num_screens = 9;
2728 if (button == MB_MENU_INITIALIZE)
2732 // DrawInfoScreen_CreditsScreen(screen_nr);
2735 if (button == MB_MENU_LEAVE)
2737 PlaySound(SND_MENU_ITEM_SELECTING);
2739 info_mode = INFO_MODE_MAIN;
2744 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2746 if (button != MB_MENU_INITIALIZE)
2748 PlaySound(SND_MENU_ITEM_SELECTING);
2753 if (screen_nr >= num_screens)
2755 FadeSoundsAndMusic();
2757 info_mode = INFO_MODE_MAIN;
2758 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2765 FadeSetNextScreen();
2768 if (button != MB_MENU_INITIALIZE)
2769 FadeOut(REDRAW_FIELD);
2771 DrawInfoScreen_CreditsScreen(screen_nr);
2773 if (button != MB_MENU_INITIALIZE)
2774 FadeIn(REDRAW_FIELD);
2778 PlayMenuSoundIfLoop();
2782 void DrawInfoScreen_Program()
2784 int ystart1 = mSY - SY + 100;
2785 int ystart2 = mSY - SY + 150;
2786 int ybottom = mSY - SY + SYSIZE - 20;
2789 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2792 FadeOut(REDRAW_FIELD);
2798 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2800 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2801 "This game is Freeware!");
2802 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2803 "If you like it, send e-mail to:");
2804 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2805 PROGRAM_EMAIL_STRING);
2806 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2807 "or SnailMail to:");
2808 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2810 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2811 "Detmolder Strasse 189");
2812 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2814 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2816 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2817 "More information and levels:");
2818 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2819 PROGRAM_WEBSITE_STRING);
2820 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2821 "If you have created new levels,");
2822 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2823 "send them to me to include them!");
2824 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2827 DrawTextSCentered(ybottom, FONT_TEXT_4,
2828 "Press any key or button for info menu");
2831 FadeIn(REDRAW_FIELD);
2835 void HandleInfoScreen_Program(int button)
2837 if (button == MB_MENU_LEAVE)
2839 PlaySound(SND_MENU_ITEM_SELECTING);
2841 info_mode = INFO_MODE_MAIN;
2846 else if (button == MB_MENU_CHOICE)
2848 PlaySound(SND_MENU_ITEM_SELECTING);
2850 FadeSoundsAndMusic();
2853 FadeOut(REDRAW_FIELD);
2856 info_mode = INFO_MODE_MAIN;
2857 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2861 PlayMenuSoundIfLoop();
2865 void DrawInfoScreen_Version()
2867 int font_header = FONT_TEXT_3;
2868 int font_text = FONT_TEXT_2;
2869 int xstep = getFontWidth(font_text);
2870 int ystep = getFontHeight(font_text);
2871 int ystart1 = mSY - SY + 100;
2872 int ystart2 = mSY - SY + 150;
2873 int ybottom = mSY - SY + SYSIZE - 20;
2874 int xstart1 = mSX + 2 * xstep;
2875 int xstart2 = mSX + 19 * xstep;
2876 #if defined(TARGET_SDL)
2877 int xstart3 = mSX + 29 * xstep;
2878 SDL_version sdl_version_compiled;
2879 const SDL_version *sdl_version_linked;
2880 int driver_name_len = 8;
2881 char driver_name[driver_name_len];
2884 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2887 FadeOut(REDRAW_FIELD);
2893 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2895 DrawTextF(xstart1, ystart2, font_header, "Name");
2896 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2899 DrawTextF(xstart1, ystart2, font_header, "Version");
2900 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2903 DrawTextF(xstart1, ystart2, font_header, "Platform");
2904 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2907 DrawTextF(xstart1, ystart2, font_header, "Target");
2908 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2911 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2912 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2914 #if defined(TARGET_SDL)
2915 ystart2 += 3 * ystep;
2916 DrawTextF(xstart1, ystart2, font_header, "Library");
2917 DrawTextF(xstart2, ystart2, font_header, "compiled");
2918 DrawTextF(xstart3, ystart2, font_header, "linked");
2920 SDL_VERSION(&sdl_version_compiled);
2921 sdl_version_linked = SDL_Linked_Version();
2923 ystart2 += 2 * ystep;
2924 DrawTextF(xstart1, ystart2, font_text, "SDL");
2925 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2926 sdl_version_compiled.major,
2927 sdl_version_compiled.minor,
2928 sdl_version_compiled.patch);
2929 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2930 sdl_version_linked->major,
2931 sdl_version_linked->minor,
2932 sdl_version_linked->patch);
2934 SDL_IMAGE_VERSION(&sdl_version_compiled);
2935 sdl_version_linked = IMG_Linked_Version();
2938 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2939 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2940 sdl_version_compiled.major,
2941 sdl_version_compiled.minor,
2942 sdl_version_compiled.patch);
2943 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2944 sdl_version_linked->major,
2945 sdl_version_linked->minor,
2946 sdl_version_linked->patch);
2948 SDL_MIXER_VERSION(&sdl_version_compiled);
2949 sdl_version_linked = Mix_Linked_Version();
2952 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2953 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2954 sdl_version_compiled.major,
2955 sdl_version_compiled.minor,
2956 sdl_version_compiled.patch);
2957 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2958 sdl_version_linked->major,
2959 sdl_version_linked->minor,
2960 sdl_version_linked->patch);
2962 SDL_NET_VERSION(&sdl_version_compiled);
2963 sdl_version_linked = SDLNet_Linked_Version();
2966 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2967 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2968 sdl_version_compiled.major,
2969 sdl_version_compiled.minor,
2970 sdl_version_compiled.patch);
2971 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2972 sdl_version_linked->major,
2973 sdl_version_linked->minor,
2974 sdl_version_linked->patch);
2976 ystart2 += 3 * ystep;
2977 DrawTextF(xstart1, ystart2, font_header, "Driver");
2978 DrawTextF(xstart2, ystart2, font_header, "Requested");
2979 DrawTextF(xstart3, ystart2, font_header, "Used");
2981 SDL_VideoDriverName(driver_name, driver_name_len);
2983 ystart2 += 2 * ystep;
2984 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2985 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2986 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2988 SDL_AudioDriverName(driver_name, driver_name_len);
2991 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2992 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2993 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2996 DrawTextSCentered(ybottom, FONT_TEXT_4,
2997 "Press any key or button for info menu");
3000 FadeIn(REDRAW_FIELD);
3004 void HandleInfoScreen_Version(int button)
3006 if (button == MB_MENU_LEAVE)
3008 PlaySound(SND_MENU_ITEM_SELECTING);
3010 info_mode = INFO_MODE_MAIN;
3015 else if (button == MB_MENU_CHOICE)
3017 PlaySound(SND_MENU_ITEM_SELECTING);
3019 FadeSoundsAndMusic();
3022 FadeOut(REDRAW_FIELD);
3025 info_mode = INFO_MODE_MAIN;
3026 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3030 PlayMenuSoundIfLoop();
3034 void DrawInfoScreen_LevelSet()
3036 struct TitleMessageInfo *tmi = &readme;
3037 char *filename = getLevelSetInfoFilename();
3039 /* if chars set to "-1", automatically determine by text and font width */
3040 if (tmi->chars == -1)
3041 tmi->chars = tmi->width / getFontWidth(tmi->font);
3043 tmi->width = tmi->chars * getFontWidth(tmi->font);
3045 /* if lines set to "-1", automatically determine by text and font height */
3046 if (tmi->lines == -1)
3047 tmi->lines = tmi->height / getFontHeight(tmi->font);
3049 tmi->height = tmi->lines * getFontHeight(tmi->font);
3051 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3054 FadeOut(REDRAW_FIELD);
3060 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3062 if (filename != NULL)
3063 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3064 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3065 tmi->autowrap, tmi->centered, tmi->parse_comments);
3067 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3068 "No information for this level set.");
3070 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3071 "Press any key or button for info menu");
3074 FadeIn(REDRAW_FIELD);
3078 void HandleInfoScreen_LevelSet(int button)
3080 if (button == MB_MENU_LEAVE)
3082 PlaySound(SND_MENU_ITEM_SELECTING);
3084 info_mode = INFO_MODE_MAIN;
3089 else if (button == MB_MENU_CHOICE)
3091 PlaySound(SND_MENU_ITEM_SELECTING);
3093 FadeSoundsAndMusic();
3096 FadeOut(REDRAW_FIELD);
3099 info_mode = INFO_MODE_MAIN;
3100 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3104 PlayMenuSoundIfLoop();
3108 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3110 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3112 if (info_mode == INFO_MODE_TITLE)
3113 DrawInfoScreen_TitleScreen();
3114 else if (info_mode == INFO_MODE_ELEMENTS)
3115 DrawInfoScreen_Elements();
3116 else if (info_mode == INFO_MODE_MUSIC)
3117 DrawInfoScreen_Music();
3118 else if (info_mode == INFO_MODE_CREDITS)
3119 DrawInfoScreen_Credits();
3120 else if (info_mode == INFO_MODE_PROGRAM)
3121 DrawInfoScreen_Program();
3122 else if (info_mode == INFO_MODE_VERSION)
3123 DrawInfoScreen_Version();
3124 else if (info_mode == INFO_MODE_LEVELSET)
3125 DrawInfoScreen_LevelSet();
3127 DrawInfoScreen_Main(fade_mask, do_fading);
3129 if (info_mode != INFO_MODE_MAIN &&
3130 info_mode != INFO_MODE_TITLE &&
3131 info_mode != INFO_MODE_MUSIC)
3138 void DrawAndFadeInInfoScreen(int fade_mask)
3140 DrawInfoScreenExt(fade_mask, TRUE);
3143 void DrawInfoScreen()
3145 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3148 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3150 if (info_mode == INFO_MODE_TITLE)
3151 HandleInfoScreen_TitleScreen(button);
3152 else if (info_mode == INFO_MODE_ELEMENTS)
3153 HandleInfoScreen_Elements(button);
3154 else if (info_mode == INFO_MODE_MUSIC)
3155 HandleInfoScreen_Music(button);
3156 else if (info_mode == INFO_MODE_CREDITS)
3157 HandleInfoScreen_Credits(button);
3158 else if (info_mode == INFO_MODE_PROGRAM)
3159 HandleInfoScreen_Program(button);
3160 else if (info_mode == INFO_MODE_VERSION)
3161 HandleInfoScreen_Version(button);
3162 else if (info_mode == INFO_MODE_LEVELSET)
3163 HandleInfoScreen_LevelSet(button);
3165 HandleInfoScreen_Main(mx, my, dx, dy, button);
3171 /* ========================================================================= */
3172 /* type name functions */
3173 /* ========================================================================= */
3175 void HandleTypeName(int newxpos, Key key)
3177 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3178 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3179 struct TextPosInfo *pos = mci->pos_input;
3180 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3181 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3182 static int xpos = 0;
3183 int font_nr = pos->font;
3184 int font_active_nr = FONT_ACTIVE(font_nr);
3185 int font_width = getFontWidth(font_active_nr);
3186 char key_char = getValidConfigValueChar(getCharFromKey(key));
3187 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3188 boolean is_active = TRUE;
3190 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3194 strcpy(last_player_name, setup.player_name);
3198 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3200 setup.player_name[xpos] = key_char;
3201 setup.player_name[xpos + 1] = 0;
3205 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3209 setup.player_name[xpos] = 0;
3211 else if (key == KSYM_Return && xpos > 0)
3217 game_status = GAME_MODE_MAIN;
3219 else if (key == KSYM_Escape)
3221 strcpy(setup.player_name, last_player_name);
3225 game_status = GAME_MODE_MAIN;
3230 pos->width = (strlen(setup.player_name) + 1) * font_width;
3231 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3233 DrawText(startx, starty, setup.player_name, font_active_nr);
3234 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3238 pos->width = strlen(setup.player_name) * font_width;
3239 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3241 DrawText(startx, starty, setup.player_name, font_nr);
3246 /* ========================================================================= */
3247 /* tree menu functions */
3248 /* ========================================================================= */
3250 static void DrawChooseTree(TreeInfo **ti_ptr)
3254 FreeScreenGadgets();
3255 CreateScreenGadgets();
3257 CloseDoor(DOOR_CLOSE_2);
3260 FadeOut(REDRAW_FIELD);
3265 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3266 MapScreenTreeGadgets(*ti_ptr);
3269 FadeIn(REDRAW_FIELD);
3275 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3277 struct GadgetInfo *gi = screen_gadget[id];
3278 int items_max, items_visible, item_position;
3280 items_max = numTreeInfoInGroup(ti);
3281 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3282 item_position = first_entry;
3284 if (item_position > items_max - items_visible)
3285 item_position = items_max - items_visible;
3287 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3288 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3289 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3292 static void drawChooseTreeList(int first_entry, int num_page_entries,
3296 char *title_string = NULL;
3297 int yoffset_sets = MENU_TITLE1_YPOS;
3298 int yoffset_setup = 16;
3299 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3301 int last_game_status = game_status; /* save current game status */
3303 title_string = ti->infotext;
3305 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3308 /* force LEVELS font on artwork setup screen */
3309 game_status = GAME_MODE_LEVELS;
3313 /* clear tree list area, but not title or scrollbar */
3314 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3315 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3316 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3318 /* clear tree list area, but not title or scrollbar */
3319 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3320 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3321 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3324 for (i = 0; i < num_page_entries; i++)
3326 TreeInfo *node, *node_first;
3327 int entry_pos = first_entry + i;
3328 int xpos = MENU_SCREEN_START_XPOS;
3329 int ypos = MENU_SCREEN_START_YPOS + i;
3330 int startx = mSX + xpos * 32;
3331 int starty = mSY + ypos * 32;
3332 int font_nr = FONT_TEXT_1;
3333 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3334 int startx_text = startx + font_xoffset;
3335 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3336 int text_size = startx_scrollbar - startx_text;
3337 int max_buffer_len = text_size / getFontWidth(font_nr);
3338 char buffer[max_buffer_len + 1];
3340 node_first = getTreeInfoFirstGroupEntry(ti);
3341 node = getTreeInfoFromPos(node_first, entry_pos);
3343 strncpy(buffer, node->name, max_buffer_len);
3344 buffer[max_buffer_len] = '\0';
3346 DrawText(startx, starty, buffer, font_nr + node->color);
3348 if (node->parent_link)
3349 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3350 else if (node->level_group)
3351 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3353 initCursor(i, IMG_MENU_BUTTON);
3356 game_status = last_game_status; /* restore current game status */
3358 redraw_mask |= REDRAW_FIELD;
3361 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3363 TreeInfo *node, *node_first;
3364 int x, last_redraw_mask = redraw_mask;
3365 int ypos = MENU_TITLE2_YPOS;
3366 int font_nr = FONT_TITLE_2;
3368 if (ti->type != TREE_TYPE_LEVEL_DIR)
3371 node_first = getTreeInfoFirstGroupEntry(ti);
3372 node = getTreeInfoFromPos(node_first, entry_pos);
3374 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3376 if (node->parent_link)
3377 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3379 else if (node->level_group)
3380 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3382 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3383 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3384 node->levels, node->class_desc);
3386 /* let BackToFront() redraw only what is needed */
3387 redraw_mask = last_redraw_mask | REDRAW_TILES;
3388 for (x = 0; x < SCR_FIELDX; x++)
3389 MarkTileDirty(x, 1);
3392 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3395 TreeInfo *ti = *ti_ptr;
3397 int y = ti->cl_cursor;
3398 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3399 int num_entries = numTreeInfoInGroup(ti);
3400 int num_page_entries;
3401 int last_game_status = game_status; /* save current game status */
3402 boolean position_set_by_scrollbar = (dx == 999);
3405 /* force LEVELS draw offset on choose level and artwork setup screen */
3406 game_status = GAME_MODE_LEVELS;
3409 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3410 num_page_entries = num_entries;
3412 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3414 game_status = last_game_status; /* restore current game status */
3416 if (button == MB_MENU_INITIALIZE)
3418 int num_entries = numTreeInfoInGroup(ti);
3419 int entry_pos = posTreeInfo(ti);
3421 if (ti->cl_first == -1)
3423 /* only on initialization */
3424 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3425 ti->cl_cursor = entry_pos - ti->cl_first;
3427 else if (ti->cl_cursor >= num_page_entries ||
3428 (num_entries > num_page_entries &&
3429 num_entries - ti->cl_first < num_page_entries))
3431 /* only after change of list size (by custom graphic configuration) */
3432 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3433 ti->cl_cursor = entry_pos - ti->cl_first;
3436 if (position_set_by_scrollbar)
3439 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3442 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3443 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3444 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3448 else if (button == MB_MENU_LEAVE)
3452 PlaySound(SND_MENU_ITEM_SELECTING);
3454 if (ti->node_parent)
3456 *ti_ptr = ti->node_parent;
3457 DrawChooseTree(ti_ptr);
3459 else if (game_status == GAME_MODE_SETUP)
3461 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3463 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3464 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3465 execSetupGraphics();
3471 game_status = GAME_MODE_MAIN;
3473 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3479 if (mx || my) /* mouse input */
3481 int last_game_status = game_status; /* save current game status */
3484 /* force LEVELS draw offset on artwork setup screen */
3485 game_status = GAME_MODE_LEVELS;
3488 x = (mx - mSX) / 32;
3489 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3491 game_status = last_game_status; /* restore current game status */
3493 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3495 /* move cursor instead of scrolling when already at start/end of list */
3496 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3498 else if (dy == +1 * SCROLL_LINE &&
3499 ti->cl_first + num_page_entries == num_entries)
3502 /* handle scrolling screen one line or page */
3503 if (ti->cl_cursor + dy < 0 ||
3504 ti->cl_cursor + dy > num_page_entries - 1)
3506 if (ABS(dy) == SCROLL_PAGE)
3507 step = num_page_entries - 1;
3509 if (dy < 0 && ti->cl_first > 0)
3511 /* scroll page/line up */
3513 ti->cl_first -= step;
3514 if (ti->cl_first < 0)
3517 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3518 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3519 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3521 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3524 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3526 /* scroll page/line down */
3528 ti->cl_first += step;
3529 if (ti->cl_first + num_page_entries > num_entries)
3530 ti->cl_first = MAX(0, num_entries - num_page_entries);
3532 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3533 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3534 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3536 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3543 /* handle moving cursor one line */
3544 y = ti->cl_cursor + dy;
3549 TreeInfo *node_first, *node_cursor;
3550 int entry_pos = ti->cl_first + y;
3552 node_first = getTreeInfoFirstGroupEntry(ti);
3553 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3555 if (node_cursor->node_group)
3559 PlaySound(SND_MENU_ITEM_SELECTING);
3561 node_cursor->cl_first = ti->cl_first;
3562 node_cursor->cl_cursor = ti->cl_cursor;
3563 *ti_ptr = node_cursor->node_group;
3564 DrawChooseTree(ti_ptr);
3569 else if (dx == -1 && ti->node_parent)
3573 PlaySound(SND_MENU_ITEM_SELECTING);
3575 *ti_ptr = ti->node_parent;
3576 DrawChooseTree(ti_ptr);
3581 if (!anyScrollbarGadgetActive() &&
3582 IN_VIS_FIELD(x, y) &&
3583 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3584 y >= 0 && y < num_page_entries)
3588 if (y != ti->cl_cursor)
3590 PlaySound(SND_MENU_ITEM_ACTIVATING);
3592 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3593 drawChooseTreeCursor(y, TRUE);
3594 drawChooseTreeInfo(ti->cl_first + y, ti);
3601 TreeInfo *node_first, *node_cursor;
3602 int entry_pos = ti->cl_first + y;
3604 PlaySound(SND_MENU_ITEM_SELECTING);
3606 node_first = getTreeInfoFirstGroupEntry(ti);
3607 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3609 if (node_cursor->node_group)
3613 node_cursor->cl_first = ti->cl_first;
3614 node_cursor->cl_cursor = ti->cl_cursor;
3615 *ti_ptr = node_cursor->node_group;
3616 DrawChooseTree(ti_ptr);
3618 else if (node_cursor->parent_link)
3622 *ti_ptr = node_cursor->node_parent;
3623 DrawChooseTree(ti_ptr);
3627 FadeSetEnterScreen();
3629 node_cursor->cl_first = ti->cl_first;
3630 node_cursor->cl_cursor = ti->cl_cursor;
3631 *ti_ptr = node_cursor;
3633 if (ti->type == TREE_TYPE_LEVEL_DIR)
3635 LoadLevelSetup_SeriesInfo();
3637 SaveLevelSetup_LastSeries();
3638 SaveLevelSetup_SeriesInfo();
3642 if (game_status == GAME_MODE_SETUP)
3644 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3646 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3647 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3648 execSetupGraphics();
3654 game_status = GAME_MODE_MAIN;
3662 void DrawChooseLevel()
3664 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3666 DrawChooseTree(&leveldir_current);
3672 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3674 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3679 void DrawHallOfFame(int highlight_position)
3682 FadeSoundsAndMusic();
3684 /* (this is needed when called from GameEnd() after winning a game) */
3685 KeyboardAutoRepeatOn();
3688 /* (this is needed when called from GameEnd() after winning a game) */
3689 SetDrawDeactivationMask(REDRAW_NONE);
3690 SetDrawBackgroundMask(REDRAW_FIELD);
3692 CloseDoor(DOOR_CLOSE_2);
3694 if (highlight_position < 0)
3695 LoadScore(level_nr);
3697 FadeSetEnterScreen();
3699 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3702 FadeOut(REDRAW_FIELD);
3710 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3713 FadeIn(REDRAW_FIELD);
3717 static void drawHallOfFameList(int first_entry, int highlight_position)
3721 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3724 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3725 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3726 "HighScores of Level %d", level_nr);
3728 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3730 int entry = first_entry + i;
3731 boolean active = (entry == highlight_position);
3732 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3733 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3734 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3735 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3736 int dx1 = 3 * getFontWidth(font_nr1);
3737 int dx2 = dx1 + getFontWidth(font_nr1);
3738 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3739 int sy = mSY + 64 + i * 32;
3741 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3742 DrawText(mSX + dx1, sy, ".", font_nr1);
3743 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3745 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3746 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3748 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3751 redraw_mask |= REDRAW_FIELD;
3754 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3756 static int first_entry = 0;
3757 static int highlight_position = 0;
3758 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3760 if (button == MB_MENU_INITIALIZE)
3763 highlight_position = mx;
3764 drawHallOfFameList(first_entry, highlight_position);
3769 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3770 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3774 if (first_entry > 0)
3776 first_entry -= step;
3777 if (first_entry < 0)
3780 drawHallOfFameList(first_entry, highlight_position);
3785 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3787 first_entry += step;
3788 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3789 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3791 drawHallOfFameList(first_entry, highlight_position);
3794 else if (button == MB_MENU_LEAVE)
3796 PlaySound(SND_MENU_ITEM_SELECTING);
3798 FadeSound(SND_BACKGROUND_SCORES);
3800 game_status = GAME_MODE_MAIN;
3804 else if (button == MB_MENU_CHOICE)
3806 PlaySound(SND_MENU_ITEM_SELECTING);
3808 FadeSound(SND_BACKGROUND_SCORES);
3811 FadeOut(REDRAW_FIELD);
3814 game_status = GAME_MODE_MAIN;
3816 DrawAndFadeInMainMenu(REDRAW_FIELD);
3819 if (game_status == GAME_MODE_SCORES)
3820 PlayMenuSoundIfLoop();
3826 /* ========================================================================= */
3827 /* setup screen functions */
3828 /* ========================================================================= */
3830 static struct TokenInfo *setup_info;
3831 static int num_setup_info;
3833 static char *screen_mode_text;
3834 static char *scroll_delay_text;
3835 static char *game_speed_text;
3836 static char *graphics_set_name;
3837 static char *sounds_set_name;
3838 static char *music_set_name;
3840 static void execSetupMain()
3842 setup_mode = SETUP_MODE_MAIN;
3847 static void execSetupGame()
3849 if (game_speeds == NULL)
3853 for (i = 0; game_speeds_list[i].value != -1; i++)
3855 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3856 char identifier[32], name[32];
3857 int value = game_speeds_list[i].value;
3858 char *text = game_speeds_list[i].text;
3860 ti->node_top = &game_speeds;
3861 ti->sort_priority = 10000 - value;
3863 sprintf(identifier, "%d", value);
3864 sprintf(name, "%s", text);
3866 setString(&ti->identifier, identifier);
3867 setString(&ti->name, name);
3868 setString(&ti->name_sorting, name);
3869 setString(&ti->infotext, "Game Speed");
3871 pushTreeInfo(&game_speeds, ti);
3874 /* sort game speed values to start with slowest game speed */
3875 sortTreeInfo(&game_speeds);
3877 /* set current game speed to configured game speed value */
3878 game_speed_current =
3879 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3881 /* if that fails, set current game speed to reliable default value */
3882 if (game_speed_current == NULL)
3883 game_speed_current =
3884 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3886 /* if that also fails, set current game speed to first available speed */
3887 if (game_speed_current == NULL)
3888 game_speed_current = game_speeds;
3891 setup.game_frame_delay = atoi(game_speed_current->identifier);
3893 /* needed for displaying game speed text instead of identifier */
3894 game_speed_text = game_speed_current->name;
3896 setup_mode = SETUP_MODE_GAME;
3901 static void execSetupChooseGameSpeed()
3903 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3908 static void execSetupEditor()
3910 setup_mode = SETUP_MODE_EDITOR;
3915 static void execSetupGraphics()
3917 if (video.fullscreen_available && screen_modes == NULL)
3921 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3923 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3924 char identifier[32], name[32];
3925 int x = video.fullscreen_modes[i].width;
3926 int y = video.fullscreen_modes[i].height;
3929 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3931 ti->node_top = &screen_modes;
3932 ti->sort_priority = x * 10000 + y;
3934 sprintf(identifier, "%dx%d", x, y);
3935 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3937 setString(&ti->identifier, identifier);
3938 setString(&ti->name, name);
3939 setString(&ti->name_sorting, name);
3940 setString(&ti->infotext, "Fullscreen Mode");
3942 pushTreeInfo(&screen_modes, ti);
3945 /* sort fullscreen modes to start with lowest available screen resolution */
3946 sortTreeInfo(&screen_modes);
3948 /* set current screen mode for fullscreen mode to configured setup value */
3949 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3950 setup.fullscreen_mode);
3952 /* if that fails, set current screen mode to reliable default value */
3953 if (screen_mode_current == NULL)
3954 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3955 DEFAULT_FULLSCREEN_MODE);
3957 /* if that also fails, set current screen mode to first available mode */
3958 if (screen_mode_current == NULL)
3959 screen_mode_current = screen_modes;
3961 if (screen_mode_current == NULL)
3962 video.fullscreen_available = FALSE;
3965 if (video.fullscreen_available)
3967 setup.fullscreen_mode = screen_mode_current->identifier;
3969 /* needed for displaying screen mode name instead of identifier */
3970 screen_mode_text = screen_mode_current->name;
3974 if (scroll_delays == NULL)
3978 for (i = 0; scroll_delays_list[i].value != -1; i++)
3980 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3981 char identifier[32], name[32];
3982 int value = scroll_delays_list[i].value;
3983 char *text = scroll_delays_list[i].text;
3985 ti->node_top = &scroll_delays;
3986 ti->sort_priority = value;
3988 sprintf(identifier, "%d", value);
3989 sprintf(name, "%s", text);
3991 setString(&ti->identifier, identifier);
3992 setString(&ti->name, name);
3993 setString(&ti->name_sorting, name);
3994 setString(&ti->infotext, "Scroll Delay");
3996 pushTreeInfo(&scroll_delays, ti);
3999 /* sort scroll delay values to start with lowest scroll delay value */
4000 sortTreeInfo(&scroll_delays);
4002 /* set current scroll delay value to configured scroll delay value */
4003 scroll_delay_current =
4004 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4006 /* if that fails, set current scroll delay to reliable default value */
4007 if (scroll_delay_current == NULL)
4008 scroll_delay_current =
4009 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4011 /* if that also fails, set current scroll delay to first available value */
4012 if (scroll_delay_current == NULL)
4013 scroll_delay_current = scroll_delays;
4016 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4018 /* needed for displaying scroll delay text instead of identifier */
4019 scroll_delay_text = scroll_delay_current->name;
4022 setup_mode = SETUP_MODE_GRAPHICS;
4026 static void execSetupChooseScreenMode()
4028 if (!video.fullscreen_available)
4031 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4036 static void execSetupChooseScrollDelay()
4038 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4043 static void execSetupSound()
4045 setup_mode = SETUP_MODE_SOUND;
4050 static void execSetupArtwork()
4053 printf("::: '%s', '%s', '%s'\n",
4054 artwork.gfx_current->subdir,
4055 artwork.gfx_current->fullpath,
4056 artwork.gfx_current->basepath);
4059 setup.graphics_set = artwork.gfx_current->identifier;
4060 setup.sounds_set = artwork.snd_current->identifier;
4061 setup.music_set = artwork.mus_current->identifier;
4063 /* needed if last screen (setup choice) changed graphics, sounds or music */
4064 ReloadCustomArtwork(0);
4066 /* needed for displaying artwork name instead of artwork identifier */
4067 graphics_set_name = artwork.gfx_current->name;
4068 sounds_set_name = artwork.snd_current->name;
4069 music_set_name = artwork.mus_current->name;
4071 setup_mode = SETUP_MODE_ARTWORK;
4076 static void execSetupChooseGraphics()
4078 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4083 static void execSetupChooseSounds()
4085 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4090 static void execSetupChooseMusic()
4092 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4097 static void execSetupInput()
4099 setup_mode = SETUP_MODE_INPUT;
4104 static void execSetupShortcuts()
4106 setup_mode = SETUP_MODE_SHORTCUTS;
4111 static void execSetupShortcuts1()
4113 setup_mode = SETUP_MODE_SHORTCUTS_1;
4118 static void execSetupShortcuts2()
4120 setup_mode = SETUP_MODE_SHORTCUTS_2;
4125 static void execSetupShortcuts3()
4127 setup_mode = SETUP_MODE_SHORTCUTS_3;
4132 static void execSetupShortcuts4()
4134 setup_mode = SETUP_MODE_SHORTCUTS_4;
4139 static void execSetupShortcuts5()
4141 setup_mode = SETUP_MODE_SHORTCUTS_5;
4146 static void execExitSetup()
4148 game_status = GAME_MODE_MAIN;
4150 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4153 static void execSaveAndExitSetup()
4159 static struct TokenInfo setup_info_main[] =
4161 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4162 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4163 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4164 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4165 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4166 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4167 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4168 { TYPE_EMPTY, NULL, "" },
4169 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4170 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4175 static struct TokenInfo setup_info_game[] =
4177 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4178 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4179 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4180 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4181 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4182 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4183 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4184 { TYPE_STRING, &game_speed_text, "" },
4185 { TYPE_EMPTY, NULL, "" },
4186 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4191 static struct TokenInfo setup_info_editor[] =
4194 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4195 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4196 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4197 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4198 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4199 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4200 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4201 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4203 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4204 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4205 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4207 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4209 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4210 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4211 { TYPE_EMPTY, NULL, "" },
4213 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4214 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4215 { TYPE_EMPTY, NULL, "" },
4217 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4218 { TYPE_EMPTY, NULL, "" },
4219 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4224 static struct TokenInfo setup_info_graphics[] =
4226 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4227 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4228 { TYPE_STRING, &screen_mode_text, "" },
4230 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4232 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4233 { TYPE_STRING, &scroll_delay_text, "" },
4235 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4237 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4238 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4239 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4240 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4241 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4242 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4243 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4244 { TYPE_EMPTY, NULL, "" },
4245 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4250 static struct TokenInfo setup_info_sound[] =
4252 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4253 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4254 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4255 { TYPE_EMPTY, NULL, "" },
4256 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4261 static struct TokenInfo setup_info_artwork[] =
4263 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4264 { TYPE_STRING, &graphics_set_name, "" },
4265 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4266 { TYPE_STRING, &sounds_set_name, "" },
4267 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4268 { TYPE_STRING, &music_set_name, "" },
4269 { TYPE_EMPTY, NULL, "" },
4272 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4273 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4274 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4276 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4277 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4278 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4279 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4282 { TYPE_STRING, NULL, "Override Level Artwork:"},
4283 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4284 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4285 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4287 { TYPE_EMPTY, NULL, "" },
4288 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4293 static struct TokenInfo setup_info_input[] =
4295 { TYPE_SWITCH, NULL, "Player:" },
4296 { TYPE_SWITCH, NULL, "Device:" },
4297 { TYPE_ENTER_MENU, NULL, "" },
4298 { TYPE_EMPTY, NULL, "" },
4299 { TYPE_EMPTY, NULL, "" },
4300 { TYPE_EMPTY, NULL, "" },
4301 { TYPE_EMPTY, NULL, "" },
4302 { TYPE_EMPTY, NULL, "" },
4303 { TYPE_EMPTY, NULL, "" },
4304 { TYPE_EMPTY, NULL, "" },
4305 { TYPE_EMPTY, NULL, "" },
4306 { TYPE_EMPTY, NULL, "" },
4307 { TYPE_EMPTY, NULL, "" },
4308 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4313 static struct TokenInfo setup_info_shortcuts[] =
4315 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4316 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4317 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4318 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4319 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4320 { TYPE_EMPTY, NULL, "" },
4321 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4326 static struct TokenInfo setup_info_shortcuts_1[] =
4328 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4329 { TYPE_KEY, &setup.shortcut.save_game, "" },
4330 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4331 { TYPE_KEY, &setup.shortcut.load_game, "" },
4332 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4333 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4334 { TYPE_EMPTY, NULL, "" },
4335 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4336 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4337 { TYPE_EMPTY, NULL, "" },
4338 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4343 static struct TokenInfo setup_info_shortcuts_2[] =
4345 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4346 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4347 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4348 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4349 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4350 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4351 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4352 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4353 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4354 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4355 { TYPE_EMPTY, NULL, "" },
4356 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4361 static struct TokenInfo setup_info_shortcuts_3[] =
4363 { TYPE_KEYTEXT, NULL, "Tape Eject:", },
4364 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4365 { TYPE_KEYTEXT, NULL, "Tape Stop:", },
4366 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4367 { TYPE_KEYTEXT, NULL, "Tape Pause:", },
4368 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4369 { TYPE_KEYTEXT, NULL, "Tape Record:", },
4370 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4371 { TYPE_KEYTEXT, NULL, "Tape Play:", },
4372 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4373 { TYPE_EMPTY, NULL, "" },
4374 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4379 static struct TokenInfo setup_info_shortcuts_4[] =
4381 { TYPE_KEYTEXT, NULL, "Sound Effects (Normal):", },
4382 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4383 { TYPE_KEYTEXT, NULL, "Sound Effects (Looping):", },
4384 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4385 { TYPE_KEYTEXT, NULL, "Music:", },
4386 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4387 { TYPE_EMPTY, NULL, "" },
4388 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4393 static struct TokenInfo setup_info_shortcuts_5[] =
4395 { TYPE_KEYTEXT, NULL, "Snap Left:", },
4396 { TYPE_KEY, &setup.shortcut.snap_left, "" },
4397 { TYPE_KEYTEXT, NULL, "Snap Right:", },
4398 { TYPE_KEY, &setup.shortcut.snap_right, "" },
4399 { TYPE_KEYTEXT, NULL, "Snap Up:", },
4400 { TYPE_KEY, &setup.shortcut.snap_up, "" },
4401 { TYPE_KEYTEXT, NULL, "Snap Down:", },
4402 { TYPE_KEY, &setup.shortcut.snap_down, "" },
4403 { TYPE_EMPTY, NULL, "" },
4404 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4409 static Key getSetupKey()
4411 Key key = KSYM_UNDEFINED;
4412 boolean got_key_event = FALSE;
4414 while (!got_key_event)
4416 if (PendingEvent()) /* got event */
4424 case EVENT_KEYPRESS:
4426 key = GetEventKey((KeyEvent *)&event, TRUE);
4428 /* press 'Escape' or 'Enter' to keep the existing key binding */
4429 if (key == KSYM_Escape || key == KSYM_Return)
4430 key = KSYM_UNDEFINED; /* keep old value */
4432 got_key_event = TRUE;
4436 case EVENT_KEYRELEASE:
4437 key_joystick_mapping = 0;
4441 HandleOtherEvents(&event);
4449 /* don't eat all CPU time */
4456 static int getSetupTextFont(int type)
4458 if (type & (TYPE_SWITCH |
4470 static int getSetupValueFont(int type, void *value)
4472 if (type & TYPE_KEY)
4473 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4474 else if (type & TYPE_STRING)
4475 return FONT_VALUE_2;
4476 else if (type & TYPE_ECS_AGA)
4477 return FONT_VALUE_1;
4478 else if (type & TYPE_BOOLEAN_STYLE)
4479 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4480 else if (type & TYPE_YES_NO_AUTO)
4481 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4482 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4484 return FONT_VALUE_1;
4487 static void drawSetupValue(int pos)
4489 boolean font_draw_xoffset_modified = FALSE;
4490 int font_draw_xoffset_old = -1;
4491 int xpos = MENU_SCREEN_VALUE_XPOS;
4492 int ypos = MENU_SCREEN_START_YPOS + pos;
4493 int startx = mSX + xpos * 32;
4494 int starty = mSY + ypos * 32;
4495 int font_nr, font_width, font_height;
4496 int type = setup_info[pos].type;
4497 void *value = setup_info[pos].value;
4498 char *value_string = getSetupValue(type, value);
4503 if (value_string == NULL)
4506 if (type & TYPE_KEY)
4508 xpos = MENU_SCREEN_START_XPOS;
4510 if (type & TYPE_QUERY)
4511 value_string = "<press key>";
4513 else if (type & TYPE_STRING)
4515 int max_value_len = (SCR_FIELDX - 2) * 2;
4517 xpos = MENU_SCREEN_START_XPOS;
4519 if (strlen(value_string) > max_value_len)
4520 value_string[max_value_len] = '\0';
4522 else if (type & TYPE_YES_NO_AUTO)
4524 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4527 startx = mSX + xpos * 32;
4528 starty = mSY + ypos * 32;
4529 font_nr = getSetupValueFont(type, value);
4530 font_width = getFontWidth(font_nr);
4531 font_height = getFontHeight(font_nr);
4533 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4534 if (setup_mode != SETUP_MODE_INPUT)
4536 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4537 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4538 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4539 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4540 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4541 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4542 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4543 boolean correct_font_draw_xoffset = FALSE;
4545 if (xpos == MENU_SCREEN_START_XPOS &&
4546 startx + font1_xoffset < text_startx + text_font_xoffset)
4547 correct_font_draw_xoffset = TRUE;
4549 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4550 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4551 correct_font_draw_xoffset = TRUE;
4553 /* check if setup value would overlap with setup text when printed */
4554 /* (this can happen for extreme/wrong values for font draw offset) */
4555 if (correct_font_draw_xoffset)
4557 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4558 font_draw_xoffset_modified = TRUE;
4560 if (type & TYPE_KEY)
4561 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4562 else if (!(type & TYPE_STRING))
4563 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4564 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4569 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4571 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4572 DrawText(startx + i * font_width, starty, " ", font_nr);
4575 DrawText(startx, starty, value_string, font_nr);
4577 if (font_draw_xoffset_modified)
4578 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4581 static void changeSetupValue(int pos, int dx)
4583 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4585 *(boolean *)setup_info[pos].value ^= TRUE;
4587 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4589 *(int *)setup_info[pos].value =
4591 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4592 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4593 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4594 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4596 else if (setup_info[pos].type & TYPE_KEY)
4600 setup_info[pos].type |= TYPE_QUERY;
4601 drawSetupValue(pos);
4602 setup_info[pos].type &= ~TYPE_QUERY;
4604 key = getSetupKey();
4605 if (key != KSYM_UNDEFINED)
4606 *(Key *)setup_info[pos].value = key;
4609 drawSetupValue(pos);
4612 static void DrawCursorAndText_Setup(int pos, boolean active)
4614 int xpos = MENU_SCREEN_START_XPOS;
4615 int ypos = MENU_SCREEN_START_YPOS + pos;
4616 int font_nr = getSetupTextFont(setup_info[pos].type);
4618 if (setup_info == setup_info_input)
4619 font_nr = FONT_MENU_1;
4622 font_nr = FONT_ACTIVE(font_nr);
4624 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4626 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4627 drawCursor(pos, active);
4630 static void DrawSetupScreen_Generic()
4632 boolean redraw_all = FALSE;
4633 char *title_string = NULL;
4637 CloseDoor(DOOR_CLOSE_2);
4639 if (redraw_mask & REDRAW_ALL)
4643 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4644 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4645 int2str(0, redraw_mask)));
4649 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4650 FadeOut(redraw_mask);
4652 FadeOut(REDRAW_FIELD);
4657 if (setup_mode == SETUP_MODE_MAIN)
4659 setup_info = setup_info_main;
4660 title_string = "Setup";
4662 else if (setup_mode == SETUP_MODE_GAME)
4664 setup_info = setup_info_game;
4665 title_string = "Setup Game";
4667 else if (setup_mode == SETUP_MODE_EDITOR)
4669 setup_info = setup_info_editor;
4670 title_string = "Setup Editor";
4672 else if (setup_mode == SETUP_MODE_GRAPHICS)
4674 setup_info = setup_info_graphics;
4675 title_string = "Setup Graphics";
4677 else if (setup_mode == SETUP_MODE_SOUND)
4679 setup_info = setup_info_sound;
4680 title_string = "Setup Sound";
4682 else if (setup_mode == SETUP_MODE_ARTWORK)
4684 setup_info = setup_info_artwork;
4685 title_string = "Custom Artwork";
4687 else if (setup_mode == SETUP_MODE_SHORTCUTS)
4689 setup_info = setup_info_shortcuts;
4690 title_string = "Setup Shortcuts";
4692 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4694 setup_info = setup_info_shortcuts_1;
4695 title_string = "Setup Shortcuts";
4697 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4699 setup_info = setup_info_shortcuts_2;
4700 title_string = "Setup Shortcuts";
4702 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
4704 setup_info = setup_info_shortcuts_3;
4705 title_string = "Setup Shortcuts";
4707 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
4709 setup_info = setup_info_shortcuts_4;
4710 title_string = "Setup Shortcuts";
4712 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
4714 setup_info = setup_info_shortcuts_5;
4715 title_string = "Setup Shortcuts";
4718 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4722 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4724 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4727 void *value_ptr = setup_info[i].value;
4729 /* set some entries to "unchangeable" according to other variables */
4730 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4731 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4732 (value_ptr == &setup.sound_music && !audio.music_available) ||
4733 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4734 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4735 setup_info[i].type |= TYPE_GHOSTED;
4737 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4738 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4739 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4740 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4741 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4742 initCursor(i, IMG_MENU_BUTTON);
4744 DrawCursorAndText_Setup(i, FALSE);
4746 if (setup_info[i].type & TYPE_VALUE)
4753 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4754 "Joysticks deactivated in setup menu");
4758 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4762 redraw_mask = REDRAW_ALL;
4765 FadeIn(redraw_mask);
4767 FadeIn(REDRAW_FIELD);
4772 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4776 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4778 static int choice_store[MAX_SETUP_MODES];
4779 int choice = choice_store[setup_mode]; /* always starts with 0 */
4783 if (button == MB_MENU_INITIALIZE)
4785 /* advance to first valid menu entry */
4786 while (choice < num_setup_info &&
4787 setup_info[choice].type & TYPE_SKIP_ENTRY)
4789 choice_store[setup_mode] = choice;
4791 DrawCursorAndText_Setup(choice, TRUE);
4795 else if (button == MB_MENU_LEAVE)
4797 PlaySound(SND_MENU_ITEM_SELECTING);
4799 for (y = 0; y < num_setup_info; y++)
4801 if (setup_info[y].type & TYPE_LEAVE_MENU)
4803 void (*menu_callback_function)(void) = setup_info[y].value;
4807 menu_callback_function();
4809 break; /* absolutely needed because function changes 'setup_info'! */
4816 if (mx || my) /* mouse input */
4818 x = (mx - mSX) / 32;
4819 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4821 else if (dx || dy) /* keyboard input */
4825 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4827 if (setup_info[choice].type & menu_navigation_type ||
4828 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4829 setup_info[choice].type & TYPE_YES_NO_AUTO)
4830 button = MB_MENU_CHOICE;
4835 /* jump to next non-empty menu entry (up or down) */
4836 while (y > 0 && y < num_setup_info - 1 &&
4837 setup_info[y].type & TYPE_SKIP_ENTRY)
4841 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4845 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4847 PlaySound(SND_MENU_ITEM_ACTIVATING);
4849 DrawCursorAndText_Setup(choice, FALSE);
4850 DrawCursorAndText_Setup(y, TRUE);
4852 choice = choice_store[setup_mode] = y;
4855 else if (!(setup_info[y].type & TYPE_GHOSTED))
4857 PlaySound(SND_MENU_ITEM_SELECTING);
4859 /* when selecting key headline, execute function for key value change */
4860 if (setup_info[y].type & TYPE_KEYTEXT &&
4861 setup_info[y + 1].type & TYPE_KEY)
4864 /* when selecting string value, execute function for list selection */
4865 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4866 setup_info[y - 1].type & TYPE_ENTER_LIST)
4869 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4871 void (*menu_callback_function)(void) = setup_info[y].value;
4873 FadeSetFromType(setup_info[y].type);
4875 menu_callback_function();
4879 if (setup_info[y].type & TYPE_VALUE)
4880 changeSetupValue(y, dx);
4886 void DrawSetupScreen_Input()
4891 FadeOut(REDRAW_FIELD);
4897 setup_info = setup_info_input;
4900 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4904 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4905 "Joysticks deactivated on this screen");
4907 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4908 "Joysticks deactivated on this screen");
4913 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4915 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4918 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4919 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4920 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4921 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4922 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4923 initCursor(i, IMG_MENU_BUTTON);
4925 DrawCursorAndText_Setup(i, FALSE);
4929 DeactivateJoystickForCalibration();
4934 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4935 "Joysticks deactivated on this screen");
4937 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4938 "Joysticks deactivated on this screen");
4942 /* create gadgets for setup input menu screen */
4943 FreeScreenGadgets();
4944 CreateScreenGadgets();
4946 /* map gadgets for setup input menu screen */
4947 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4949 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4952 FadeIn(REDRAW_FIELD);
4958 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4960 if (device_name == NULL)
4963 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4966 if (strlen(device_name) > 1)
4968 char c1 = device_name[strlen(device_name) - 1];
4969 char c2 = device_name[strlen(device_name) - 2];
4971 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4972 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4975 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4976 strlen(device_name));
4979 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4982 static struct SetupKeyboardInfo custom_key;
4989 { &custom_key.left, "Joystick Left" },
4990 { &custom_key.right, "Joystick Right" },
4991 { &custom_key.up, "Joystick Up" },
4992 { &custom_key.down, "Joystick Down" },
4993 { &custom_key.snap, "Button 1" },
4994 { &custom_key.drop, "Button 2" }
4996 static char *joystick_name[MAX_PLAYERS] =
5003 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5007 custom_key = setup.input[player_nr].key;
5009 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5010 FONT_INPUT_1_ACTIVE);
5012 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5014 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5015 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5017 if (setup.input[player_nr].use_joystick)
5019 char *device_name = setup.input[player_nr].joy.device_name;
5020 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5021 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5023 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5024 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5028 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5029 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5032 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5034 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5035 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5036 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5037 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5039 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5040 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5041 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5042 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5043 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5044 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5046 for (i = 0; i < 6; i++)
5048 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5050 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5052 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5053 (setup.input[player_nr].use_joystick ?
5055 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5059 static int input_player_nr = 0;
5061 void HandleSetupScreen_Input_Player(int step, int direction)
5063 int old_player_nr = input_player_nr;
5066 new_player_nr = old_player_nr + step * direction;
5067 if (new_player_nr < 0)
5069 if (new_player_nr > MAX_PLAYERS - 1)
5070 new_player_nr = MAX_PLAYERS - 1;
5072 if (new_player_nr != old_player_nr)
5074 input_player_nr = new_player_nr;
5076 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5080 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5082 static int choice = 0;
5085 int pos_start = SETUPINPUT_SCREEN_POS_START;
5086 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5087 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5088 int pos_end = SETUPINPUT_SCREEN_POS_END;
5090 if (button == MB_MENU_INITIALIZE)
5092 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5094 DrawCursorAndText_Setup(choice, TRUE);
5098 else if (button == MB_MENU_LEAVE)
5100 setup_mode = SETUP_MODE_MAIN;
5107 if (mx || my) /* mouse input */
5109 x = (mx - mSX) / 32;
5110 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5112 else if (dx || dy) /* keyboard input */
5114 if (dx && choice == 0)
5115 x = (dx < 0 ? 10 : 12);
5116 else if ((dx && choice == 1) ||
5117 (dx == +1 && choice == 2) ||
5118 (dx == -1 && choice == pos_end))
5119 button = MB_MENU_CHOICE;
5123 if (y >= pos_empty1 && y <= pos_empty2)
5124 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5127 if (y == 0 && dx != 0 && button)
5129 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5131 else if (IN_VIS_FIELD(x, y) &&
5132 y >= pos_start && y <= pos_end &&
5133 !(y >= pos_empty1 && y <= pos_empty2))
5139 DrawCursorAndText_Setup(choice, FALSE);
5140 DrawCursorAndText_Setup(y, TRUE);
5142 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5151 char *device_name = setup.input[input_player_nr].joy.device_name;
5153 if (!setup.input[input_player_nr].use_joystick)
5155 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5157 setJoystickDeviceToNr(device_name, new_device_nr);
5158 setup.input[input_player_nr].use_joystick = TRUE;
5162 int device_nr = getJoystickNrFromDeviceName(device_name);
5163 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5165 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5166 setup.input[input_player_nr].use_joystick = FALSE;
5168 setJoystickDeviceToNr(device_name, new_device_nr);
5171 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5175 if (setup.input[input_player_nr].use_joystick)
5178 CalibrateJoystick(input_player_nr);
5181 CustomizeKeyboard(input_player_nr);
5183 else if (y == pos_end)
5189 setup_mode = SETUP_MODE_MAIN;
5196 void CustomizeKeyboard(int player_nr)
5200 boolean finished = FALSE;
5201 static struct SetupKeyboardInfo custom_key;
5206 } customize_step[] =
5208 { &custom_key.left, "Move Left" },
5209 { &custom_key.right, "Move Right" },
5210 { &custom_key.up, "Move Up" },
5211 { &custom_key.down, "Move Down" },
5212 { &custom_key.snap, "Snap Field" },
5213 { &custom_key.drop, "Drop Element" }
5216 /* read existing key bindings from player setup */
5217 custom_key = setup.input[player_nr].key;
5220 FadeOut(REDRAW_FIELD);
5224 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5232 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5233 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5234 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5235 "Key:", FONT_INPUT_1_ACTIVE);
5236 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5237 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5240 FadeIn(REDRAW_FIELD);
5247 if (PendingEvent()) /* got event */
5255 case EVENT_KEYPRESS:
5257 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5259 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5261 if (key == KSYM_Escape)
5262 FadeSkipNextFadeIn();
5268 /* all keys configured -- wait for "Escape" or "Return" key */
5272 /* press 'Enter' to keep the existing key binding */
5273 if (key == KSYM_Return)
5274 key = *customize_step[step_nr].key;
5276 /* check if key already used */
5277 for (i = 0; i < step_nr; i++)
5278 if (*customize_step[i].key == key)
5283 /* got new key binding */
5284 *customize_step[step_nr].key = key;
5285 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5287 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5288 getKeyNameFromKey(key), FONT_VALUE_1);
5291 /* un-highlight last query */
5292 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5293 customize_step[step_nr - 1].text, FONT_MENU_1);
5294 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5295 "Key:", FONT_MENU_1);
5297 /* press 'Enter' to leave */
5300 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5301 "Press Enter", FONT_TITLE_1);
5305 /* query next key binding */
5306 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5307 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5308 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5309 "Key:", FONT_INPUT_1_ACTIVE);
5310 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5311 getKeyNameFromKey(*customize_step[step_nr].key),
5316 case EVENT_KEYRELEASE:
5317 key_joystick_mapping = 0;
5321 HandleOtherEvents(&event);
5329 /* don't eat all CPU time */
5333 /* write new key bindings back to player setup */
5334 setup.input[player_nr].key = custom_key;
5337 DrawSetupScreen_Input();
5340 static boolean CalibrateJoystickMain(int player_nr)
5342 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5343 int new_joystick_xright = JOYSTICK_XMIDDLE;
5344 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5345 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5346 int new_joystick_xmiddle, new_joystick_ymiddle;
5348 int joystick_fd = joystick.fd[player_nr];
5349 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5350 boolean check[3][3];
5351 int check_remaining = 3 * 3;
5356 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5359 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5363 FadeOut(REDRAW_FIELD);
5367 for (y = 0; y < 3; y++)
5369 for (x = 0; x < 3; x++)
5371 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5372 check[x][y] = FALSE;
5376 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5377 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5378 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5379 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5380 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5381 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5382 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5384 joy_value = Joystick(player_nr);
5385 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5386 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5388 /* eventually uncalibrated center position (joystick could be uncentered) */
5389 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5392 new_joystick_xmiddle = joy_x;
5393 new_joystick_ymiddle = joy_y;
5395 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5397 FadeIn(REDRAW_FIELD);
5399 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5404 if (PendingEvent()) /* got event */
5412 case EVENT_KEYPRESS:
5413 switch (GetEventKey((KeyEvent *)&event, TRUE))
5416 if (check_remaining == 0)
5421 FadeSkipNextFadeIn();
5430 case EVENT_KEYRELEASE:
5431 key_joystick_mapping = 0;
5435 HandleOtherEvents(&event);
5440 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5443 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5444 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5445 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5446 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5448 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5449 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5450 setup.input[player_nr].joy.xright = new_joystick_xright;
5451 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5452 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5453 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5455 CheckJoystickData();
5457 joy_value = Joystick(player_nr);
5459 if (joy_value & JOY_BUTTON && check_remaining == 0)
5462 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5463 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5465 if (x != last_x || y != last_y)
5467 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5468 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5473 if (check_remaining > 0 && !check[x+1][y+1])
5475 check[x+1][y+1] = TRUE;
5481 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5482 setup.input[player_nr].joy.xleft,
5483 setup.input[player_nr].joy.xmiddle,
5484 setup.input[player_nr].joy.xright);
5485 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5486 setup.input[player_nr].joy.yupper,
5487 setup.input[player_nr].joy.ymiddle,
5488 setup.input[player_nr].joy.ylower);
5497 /* don't eat all CPU time */
5501 /* calibrated center position (joystick should now be centered) */
5502 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5505 new_joystick_xmiddle = joy_x;
5506 new_joystick_ymiddle = joy_y;
5511 DrawSetupScreen_Input();
5514 /* wait until the last pressed button was released */
5515 while (Joystick(player_nr) & JOY_BUTTON)
5517 if (PendingEvent()) /* got event */
5522 HandleOtherEvents(&event);
5531 void CalibrateJoystick(int player_nr)
5533 if (!CalibrateJoystickMain(player_nr))
5535 char *device_name = setup.input[player_nr].joy.device_name;
5536 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5537 int xpos = mSX - SX;
5538 int ypos = mSY - SY;
5542 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5543 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5546 Delay(2000); /* show error message for a short time */
5552 DrawSetupScreen_Input();
5556 void DrawSetupScreen()
5558 DeactivateJoystick();
5560 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5562 if (setup_mode == SETUP_MODE_INPUT)
5563 DrawSetupScreen_Input();
5564 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5565 DrawChooseTree(&game_speed_current);
5566 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5567 DrawChooseTree(&screen_mode_current);
5568 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5569 DrawChooseTree(&scroll_delay_current);
5570 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5571 DrawChooseTree(&artwork.gfx_current);
5572 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5573 DrawChooseTree(&artwork.snd_current);
5574 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5575 DrawChooseTree(&artwork.mus_current);
5577 DrawSetupScreen_Generic();
5583 void RedrawSetupScreenAfterFullscreenToggle()
5585 if (setup_mode == SETUP_MODE_GRAPHICS)
5589 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5591 if (setup_mode == SETUP_MODE_INPUT)
5592 HandleSetupScreen_Input(mx, my, dx, dy, button);
5593 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5594 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5595 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5596 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5597 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5598 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5599 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5600 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5601 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5602 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5603 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5604 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5606 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5611 void HandleGameActions()
5613 if (game_status != GAME_MODE_PLAYING)
5616 GameActions(); /* main game loop */
5618 if (tape.auto_play && !tape.playing)
5619 AutoPlayTape(); /* continue automatically playing next tape */
5623 /* ---------- new screen button stuff -------------------------------------- */
5625 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5630 case SCREEN_CTRL_ID_PREV_LEVEL:
5631 *x = mSX + menu.main.button.prev_level.x;
5632 *y = mSY + menu.main.button.prev_level.y;
5635 case SCREEN_CTRL_ID_NEXT_LEVEL:
5636 *x = mSX + menu.main.button.next_level.x;
5637 *y = mSY + menu.main.button.next_level.y;
5640 case SCREEN_CTRL_ID_PREV_LEVEL:
5641 *x = mSX + TILEX * getPrevlevelButtonPos();
5642 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5645 case SCREEN_CTRL_ID_NEXT_LEVEL:
5646 *x = mSX + TILEX * getNextLevelButtonPos();
5647 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5651 case SCREEN_CTRL_ID_PREV_PLAYER:
5652 *x = mSX + TILEX * 10;
5653 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5656 case SCREEN_CTRL_ID_NEXT_PLAYER:
5657 *x = mSX + TILEX * 12;
5658 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5662 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5668 int gfx_unpressed, gfx_pressed;
5669 void (*get_gadget_position)(int *, int *, int);
5673 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5676 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5677 getScreenMenuButtonPos,
5678 SCREEN_CTRL_ID_PREV_LEVEL,
5683 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5684 getScreenMenuButtonPos,
5685 SCREEN_CTRL_ID_NEXT_LEVEL,
5690 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5691 getScreenMenuButtonPos,
5692 SCREEN_CTRL_ID_PREV_PLAYER,
5697 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5698 getScreenMenuButtonPos,
5699 SCREEN_CTRL_ID_NEXT_PLAYER,
5707 int gfx_unpressed, gfx_pressed;
5711 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5714 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5716 -1, -1, /* these values are not constant, but can change at runtime */
5718 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5720 SCREEN_CTRL_ID_SCROLL_UP,
5724 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5726 -1, -1, /* these values are not constant, but can change at runtime */
5728 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5730 SCREEN_CTRL_ID_SCROLL_DOWN,
5737 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5738 Bitmap **gfx_unpressed, **gfx_pressed;
5740 int gfx_unpressed, gfx_pressed;
5747 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5750 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5751 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5753 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5756 -1, -1, /* these values are not constant, but can change at runtime */
5757 -1, -1, /* these values are not constant, but can change at runtime */
5759 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5760 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5762 GD_TYPE_SCROLLBAR_VERTICAL,
5763 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5764 "scroll level series vertically"
5768 static void CreateScreenMenubuttons()
5770 struct GadgetInfo *gi;
5771 unsigned long event_mask;
5774 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5776 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5777 int gfx_unpressed, gfx_pressed;
5778 int x, y, width, height;
5779 int gd_x1, gd_x2, gd_y1, gd_y2;
5780 int id = menubutton_info[i].gadget_id;
5782 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5784 menubutton_info[i].get_gadget_position(&x, &y, id);
5786 width = SC_MENUBUTTON_XSIZE;
5787 height = SC_MENUBUTTON_YSIZE;
5789 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5790 gfx_pressed = menubutton_info[i].gfx_pressed;
5791 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5792 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5793 gd_x1 = graphic_info[gfx_unpressed].src_x;
5794 gd_y1 = graphic_info[gfx_unpressed].src_y;
5795 gd_x2 = graphic_info[gfx_pressed].src_x;
5796 gd_y2 = graphic_info[gfx_pressed].src_y;
5798 gi = CreateGadget(GDI_CUSTOM_ID, id,
5799 GDI_CUSTOM_TYPE_ID, i,
5800 GDI_INFO_TEXT, menubutton_info[i].infotext,
5805 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5806 GDI_STATE, GD_BUTTON_UNPRESSED,
5807 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5808 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5809 GDI_DIRECT_DRAW, FALSE,
5810 GDI_EVENT_MASK, event_mask,
5811 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5815 Error(ERR_EXIT, "cannot create gadget");
5817 screen_gadget[id] = gi;
5821 static void CreateScreenScrollbuttons()
5823 struct GadgetInfo *gi;
5824 unsigned long event_mask;
5827 /* these values are not constant, but can change at runtime */
5828 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
5829 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
5830 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
5831 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
5833 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5835 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5836 int gfx_unpressed, gfx_pressed;
5837 int x, y, width, height;
5838 int gd_x1, gd_x2, gd_y1, gd_y2;
5839 int id = scrollbutton_info[i].gadget_id;
5841 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5843 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5844 y = mSY + scrollbutton_info[i].y;
5845 width = SC_SCROLLBUTTON_XSIZE;
5846 height = SC_SCROLLBUTTON_YSIZE;
5848 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5849 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5850 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5852 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5853 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5854 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5855 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5856 gd_x1 = graphic_info[gfx_unpressed].src_x;
5857 gd_y1 = graphic_info[gfx_unpressed].src_y;
5858 gd_x2 = graphic_info[gfx_pressed].src_x;
5859 gd_y2 = graphic_info[gfx_pressed].src_y;
5861 gi = CreateGadget(GDI_CUSTOM_ID, id,
5862 GDI_CUSTOM_TYPE_ID, i,
5863 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5868 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5869 GDI_STATE, GD_BUTTON_UNPRESSED,
5870 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5871 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5872 GDI_DIRECT_DRAW, FALSE,
5873 GDI_EVENT_MASK, event_mask,
5874 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5878 Error(ERR_EXIT, "cannot create gadget");
5880 screen_gadget[id] = gi;
5884 static void CreateScreenScrollbars()
5888 /* these values are not constant, but can change at runtime */
5889 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
5890 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
5891 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
5892 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
5894 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5896 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5897 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5898 int gfx_unpressed, gfx_pressed;
5900 int x, y, width, height;
5901 int gd_x1, gd_x2, gd_y1, gd_y2;
5902 struct GadgetInfo *gi;
5903 int items_max, items_visible, item_position;
5904 unsigned long event_mask;
5905 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5906 int id = scrollbar_info[i].gadget_id;
5908 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5910 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5911 y = mSY + scrollbar_info[i].y;
5912 width = scrollbar_info[i].width;
5913 height = scrollbar_info[i].height;
5915 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5916 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5918 items_max = num_page_entries;
5919 items_visible = num_page_entries;
5922 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5923 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5924 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5930 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5931 gfx_pressed = scrollbar_info[i].gfx_pressed;
5932 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5933 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5934 gd_x1 = graphic_info[gfx_unpressed].src_x;
5935 gd_y1 = graphic_info[gfx_unpressed].src_y;
5936 gd_x2 = graphic_info[gfx_pressed].src_x;
5937 gd_y2 = graphic_info[gfx_pressed].src_y;
5940 gi = CreateGadget(GDI_CUSTOM_ID, id,
5941 GDI_CUSTOM_TYPE_ID, i,
5942 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5947 GDI_TYPE, scrollbar_info[i].type,
5948 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5949 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5950 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5952 GDI_WHEEL_AREA_X, SX,
5953 GDI_WHEEL_AREA_Y, SY,
5954 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5955 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5957 GDI_WHEEL_AREA_X, 0,
5958 GDI_WHEEL_AREA_Y, 0,
5959 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5960 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5962 GDI_STATE, GD_BUTTON_UNPRESSED,
5963 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5964 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5965 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5966 GDI_DIRECT_DRAW, FALSE,
5967 GDI_EVENT_MASK, event_mask,
5968 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5972 Error(ERR_EXIT, "cannot create gadget");
5974 screen_gadget[id] = gi;
5978 void CreateScreenGadgets()
5980 int last_game_status = game_status; /* save current game status */
5982 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5985 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5987 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5989 /* copy pointers to clip mask and GC */
5990 scrollbar_bitmap[i]->clip_mask =
5991 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5992 scrollbar_bitmap[i]->stored_clip_gc =
5993 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5995 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5996 scrollbar_bitmap[i],
5997 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5998 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5999 TILEX, TILEY, 0, 0);
6003 CreateScreenMenubuttons();
6006 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6007 game_status = GAME_MODE_LEVELS;
6010 CreateScreenScrollbuttons();
6011 CreateScreenScrollbars();
6013 game_status = last_game_status; /* restore current game status */
6016 void FreeScreenGadgets()
6020 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6021 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6023 /* prevent freeing clip mask and GC twice */
6024 scrollbar_bitmap[i]->clip_mask = None;
6025 scrollbar_bitmap[i]->stored_clip_gc = None;
6027 FreeBitmap(scrollbar_bitmap[i]);
6031 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6032 FreeGadget(screen_gadget[i]);
6035 void MapScreenMenuGadgets(int screen_mask)
6039 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6040 if (screen_mask & menubutton_info[i].screen_mask)
6041 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6044 void MapScreenTreeGadgets(TreeInfo *ti)
6046 int num_entries = numTreeInfoInGroup(ti);
6049 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6052 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6053 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6055 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6056 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6059 static void HandleScreenGadgets(struct GadgetInfo *gi)
6061 int id = gi->custom_id;
6062 int button = gi->event.button;
6063 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6067 case SCREEN_CTRL_ID_PREV_LEVEL:
6068 HandleMainMenu_SelectLevel(step, -1);
6071 case SCREEN_CTRL_ID_NEXT_LEVEL:
6072 HandleMainMenu_SelectLevel(step, +1);
6075 case SCREEN_CTRL_ID_PREV_PLAYER:
6076 HandleSetupScreen_Input_Player(step, -1);
6079 case SCREEN_CTRL_ID_NEXT_PLAYER:
6080 HandleSetupScreen_Input_Player(step, +1);
6083 case SCREEN_CTRL_ID_SCROLL_UP:
6084 if (game_status == GAME_MODE_LEVELS)
6085 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6086 else if (game_status == GAME_MODE_SETUP)
6087 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6090 case SCREEN_CTRL_ID_SCROLL_DOWN:
6091 if (game_status == GAME_MODE_LEVELS)
6092 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6093 else if (game_status == GAME_MODE_SETUP)
6094 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6097 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6098 if (game_status == GAME_MODE_LEVELS)
6099 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6100 else if (game_status == GAME_MODE_SETUP)
6101 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);