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
54 /* sub-screens on the setup screen (generic) */
55 #define SETUP_MODE_CHOOSE_ARTWORK 12
56 #define SETUP_MODE_CHOOSE_OTHER 13
58 /* sub-screens on the setup screen (specific) */
59 #define SETUP_MODE_CHOOSE_GAME_SPEED 14
60 #define SETUP_MODE_CHOOSE_SCREEN_MODE 15
61 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 16
62 #define SETUP_MODE_CHOOSE_GRAPHICS 17
63 #define SETUP_MODE_CHOOSE_SOUNDS 18
64 #define SETUP_MODE_CHOOSE_MUSIC 19
66 #define MAX_SETUP_MODES 20
68 /* for input setup functions */
69 #define SETUPINPUT_SCREEN_POS_START 0
70 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
71 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
72 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
74 /* for various menu stuff */
75 #define MENU_SCREEN_START_XPOS 1
76 #define MENU_SCREEN_START_YPOS 2
77 #define MENU_SCREEN_VALUE_XPOS 14
78 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
79 #define MENU_TITLE1_YPOS 8
80 #define MENU_TITLE2_YPOS 46
81 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
82 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
83 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
84 MENU_SCREEN_START_XPOS)
85 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
87 /* buttons and scrollbars identifiers */
88 #define SCREEN_CTRL_ID_PREV_LEVEL 0
89 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
90 #define SCREEN_CTRL_ID_PREV_PLAYER 2
91 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
92 #define SCREEN_CTRL_ID_SCROLL_UP 4
93 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
94 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
96 #define NUM_SCREEN_GADGETS 7
98 #define NUM_SCREEN_MENUBUTTONS 4
99 #define NUM_SCREEN_SCROLLBUTTONS 2
100 #define NUM_SCREEN_SCROLLBARS 1
102 #define SCREEN_MASK_MAIN (1 << 0)
103 #define SCREEN_MASK_INPUT (1 << 1)
105 /* graphic position and size values for buttons and scrollbars */
106 #define SC_MENUBUTTON_XSIZE TILEX
107 #define SC_MENUBUTTON_YSIZE TILEY
109 #define SC_SCROLLBUTTON_XSIZE TILEX
110 #define SC_SCROLLBUTTON_YSIZE TILEY
112 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
114 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
115 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
116 SC_SCROLLBUTTON_YSIZE)
118 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
119 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
121 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
122 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
123 SC_SCROLLBUTTON_YSIZE)
125 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
126 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
127 SC_SCROLL_VERTICAL_YSIZE)
129 #define SC_BORDER_SIZE 14
132 /* forward declarations of internal functions */
133 static void HandleScreenGadgets(struct GadgetInfo *);
134 static void HandleSetupScreen_Generic(int, int, int, int, int);
135 static void HandleSetupScreen_Input(int, int, int, int, int);
136 static void CustomizeKeyboard(int);
137 static void CalibrateJoystick(int);
138 static void execSetupGame(void);
139 static void execSetupGraphics(void);
140 static void execSetupArtwork(void);
141 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
143 static void DrawChooseLevel(void);
144 static void DrawInfoScreen(void);
145 static void DrawAndFadeInInfoScreen(int);
146 static void DrawSetupScreen(void);
148 static void DrawInfoScreenExt(int, int);
149 static void DrawInfoScreen_NotAvailable(char *, char *);
150 static void DrawInfoScreen_HelpAnim(int, int, boolean);
151 static void DrawInfoScreen_HelpText(int, int, int, int);
152 static void HandleInfoScreen_Main(int, int, int, int, int);
153 static void HandleInfoScreen_TitleScreen(int);
154 static void HandleInfoScreen_Elements(int);
155 static void HandleInfoScreen_Music(int);
156 static void HandleInfoScreen_Credits(int);
157 static void HandleInfoScreen_Program(int);
158 static void HandleInfoScreen_Version(int);
160 static void MapScreenMenuGadgets(int);
161 static void MapScreenTreeGadgets(TreeInfo *);
163 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
165 static int info_mode = INFO_MODE_MAIN;
166 static int setup_mode = SETUP_MODE_MAIN;
168 static TreeInfo *screen_modes = NULL;
169 static TreeInfo *screen_mode_current = NULL;
171 static TreeInfo *scroll_delays = NULL;
172 static TreeInfo *scroll_delay_current = NULL;
174 static TreeInfo *game_speeds = NULL;
175 static TreeInfo *game_speed_current = NULL;
181 } game_speeds_list[] =
190 { 1000, "1/1s (Extremely Slow)" },
195 { 29, "1/35s (Original Supaplex)" },
197 { 20, "1/50s (Normal Speed)" },
198 { 14, "1/70s (Maximum Supaplex)" },
202 { 1, "1/1000s (Extremely Fast)" },
212 } scroll_delays_list[] =
214 { 0, "0 Tiles (No Scroll Delay)" },
217 { 3, "3 Tiles (Default)" },
222 { 8, "8 Tiles (Maximum Scroll Delay)"},
227 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
228 (s) <= GAME_MODE_SETUP ? (s) : \
229 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
230 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
232 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
233 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
234 (i) <= INFO_MODE_LEVELSET ? (i) : \
237 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
238 (i) <= SETUP_MODE_SHORTCUTS_4 ? (i) : \
239 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
240 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
241 SETUP_MODE_CHOOSE_ARTWORK : \
242 SETUP_MODE_CHOOSE_OTHER)
244 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
245 menu.draw_xoffset[GAME_MODE_INFO] : \
246 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
247 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
248 menu.draw_yoffset[GAME_MODE_INFO] : \
249 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
251 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
252 menu.draw_xoffset[GAME_MODE_SETUP] : \
253 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
254 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
255 menu.draw_yoffset[GAME_MODE_SETUP] : \
256 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
258 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
259 DRAW_XOFFSET_INFO(info_mode) : \
260 (s) == GAME_MODE_SETUP ? \
261 DRAW_XOFFSET_SETUP(setup_mode) : \
262 menu.draw_xoffset[DRAW_MODE(s)])
263 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
264 DRAW_YOFFSET_INFO(info_mode) : \
265 (s) == GAME_MODE_SETUP ? \
266 DRAW_YOFFSET_SETUP(setup_mode) : \
267 menu.draw_yoffset[DRAW_MODE(s)])
269 #define mSX (SX + DRAW_XOFFSET(game_status))
270 #define mSY (SY + DRAW_YOFFSET(game_status))
272 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
273 menu.list_size[game_status] : \
274 MAX_MENU_ENTRIES_ON_SCREEN)
276 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
277 #define NUM_SCROLLBAR_BITMAPS 2
278 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
282 /* title display and control definitions */
284 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
285 2 * MAX_NUM_TITLE_MESSAGES)
287 static int num_title_screens = 0;
289 struct TitleControlInfo
297 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
299 /* main menu display and control definitions */
301 #define MAIN_CONTROL_NAME 0
302 #define MAIN_CONTROL_LEVELS 1
303 #define MAIN_CONTROL_SCORES 2
304 #define MAIN_CONTROL_EDITOR 3
305 #define MAIN_CONTROL_INFO 4
306 #define MAIN_CONTROL_GAME 5
307 #define MAIN_CONTROL_SETUP 6
308 #define MAIN_CONTROL_QUIT 7
309 #define MAIN_CONTROL_PREV_LEVEL 8
310 #define MAIN_CONTROL_NEXT_LEVEL 9
311 #define MAIN_CONTROL_FIRST_LEVEL 10
312 #define MAIN_CONTROL_LAST_LEVEL 11
313 #define MAIN_CONTROL_LEVEL_NUMBER 12
314 #define MAIN_CONTROL_LEVEL_INFO_1 13
315 #define MAIN_CONTROL_LEVEL_INFO_2 14
316 #define MAIN_CONTROL_LEVEL_NAME 15
317 #define MAIN_CONTROL_LEVEL_AUTHOR 16
318 #define MAIN_CONTROL_LEVEL_YEAR 17
319 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
320 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
321 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
322 #define MAIN_CONTROL_TITLE_1 21
323 #define MAIN_CONTROL_TITLE_2 22
324 #define MAIN_CONTROL_TITLE_3 23
326 static char str_main_text_name[10];
327 static char str_main_text_first_level[10];
328 static char str_main_text_last_level[10];
329 static char str_main_text_level_number[10];
331 static char *main_text_name = str_main_text_name;
332 static char *main_text_first_level = str_main_text_first_level;
333 static char *main_text_last_level = str_main_text_last_level;
334 static char *main_text_level_number = str_main_text_level_number;
335 static char *main_text_levels = "Levelset";
336 static char *main_text_scores = "Hall Of Fame";
337 static char *main_text_editor = "Level Creator";
338 static char *main_text_info = "Info Screen";
339 static char *main_text_game = "Start Game";
340 static char *main_text_setup = "Setup";
341 static char *main_text_quit = "Quit";
342 static char *main_text_level_name = level.name;
343 static char *main_text_level_author = level.author;
344 static char *main_text_level_year = NULL;
345 static char *main_text_level_imported_from = NULL;
346 static char *main_text_level_imported_by = NULL;
347 static char *main_text_level_tested_by = NULL;
348 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
349 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
350 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
352 struct MainControlInfo
356 struct MenuPosInfo *pos_button;
359 struct TextPosInfo *pos_text;
362 struct TextPosInfo *pos_input;
366 static struct MainControlInfo main_controls[] =
370 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
371 &menu.main.text.name, &main_text_name,
372 &menu.main.input.name, &setup.player_name,
376 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
377 &menu.main.text.levels, &main_text_levels,
382 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
383 &menu.main.text.scores, &main_text_scores,
388 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
389 &menu.main.text.editor, &main_text_editor,
394 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
395 &menu.main.text.info, &main_text_info,
400 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
401 &menu.main.text.game, &main_text_game,
406 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
407 &menu.main.text.setup, &main_text_setup,
412 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
413 &menu.main.text.quit, &main_text_quit,
417 /* (these two buttons are real gadgets) */
419 MAIN_CONTROL_PREV_LEVEL,
420 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
425 MAIN_CONTROL_NEXT_LEVEL,
426 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
432 MAIN_CONTROL_FIRST_LEVEL,
434 &menu.main.text.first_level, &main_text_first_level,
438 MAIN_CONTROL_LAST_LEVEL,
440 &menu.main.text.last_level, &main_text_last_level,
444 MAIN_CONTROL_LEVEL_NUMBER,
446 &menu.main.text.level_number, &main_text_level_number,
450 MAIN_CONTROL_LEVEL_INFO_1,
452 &menu.main.text.level_info_1, NULL,
456 MAIN_CONTROL_LEVEL_INFO_2,
458 &menu.main.text.level_info_2, NULL,
462 MAIN_CONTROL_LEVEL_NAME,
464 &menu.main.text.level_name, &main_text_level_name,
468 MAIN_CONTROL_LEVEL_AUTHOR,
470 &menu.main.text.level_author, &main_text_level_author,
474 MAIN_CONTROL_LEVEL_YEAR,
476 &menu.main.text.level_year, &main_text_level_year,
480 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
482 &menu.main.text.level_imported_from, &main_text_level_imported_from,
486 MAIN_CONTROL_LEVEL_IMPORTED_BY,
488 &menu.main.text.level_imported_by, &main_text_level_imported_by,
492 MAIN_CONTROL_LEVEL_TESTED_BY,
494 &menu.main.text.level_tested_by, &main_text_level_tested_by,
498 MAIN_CONTROL_TITLE_1,
500 &menu.main.text.title_1, &main_text_title_1,
504 MAIN_CONTROL_TITLE_2,
506 &menu.main.text.title_2, &main_text_title_2,
510 MAIN_CONTROL_TITLE_3,
512 &menu.main.text.title_3, &main_text_title_3,
525 static int getTitleScreenGraphic(int nr, boolean initial)
527 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
530 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
532 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
536 static int getTitleScreenGameMode(boolean initial)
538 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
542 static int getTitleMessageGameMode(boolean initial)
544 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
548 static int getTitleScreenBackground(boolean initial)
550 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
555 static int getTitleMessageBackground(int nr, boolean initial)
557 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
561 static int getTitleBackground(int nr, boolean initial, boolean is_image)
563 int base = (is_image ?
564 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
565 IMG_BACKGROUND_TITLESCREEN_1) :
566 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
567 IMG_BACKGROUND_TITLEMESSAGE_1));
568 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
569 IMG_BACKGROUND_TITLE);
570 int graphic_local = base + nr;
572 if (graphic_info[graphic_local].bitmap != NULL)
573 return graphic_local;
575 if (graphic_info[graphic_global].bitmap != NULL)
576 return graphic_global;
578 return IMG_UNDEFINED;
581 static int getTitleSound(struct TitleControlInfo *tci)
583 boolean is_image = tci->is_image;
584 int initial = tci->initial;
585 int nr = tci->local_nr;
586 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
587 int base = (is_image ?
588 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
589 SND_BACKGROUND_TITLESCREEN_1) :
590 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
591 SND_BACKGROUND_TITLEMESSAGE_1));
592 int sound_global = menu.sound[mode];
593 int sound_local = base + nr;
596 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
597 nr, initial, is_image,
598 sound_global, getSoundListEntry(sound_global)->filename,
599 sound_local, getSoundListEntry(sound_local)->filename);
602 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
605 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
608 return SND_UNDEFINED;
611 static int getTitleMusic(struct TitleControlInfo *tci)
613 boolean is_image = tci->is_image;
614 int initial = tci->initial;
615 int nr = tci->local_nr;
616 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
617 int base = (is_image ?
618 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
619 MUS_BACKGROUND_TITLESCREEN_1) :
620 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
621 MUS_BACKGROUND_TITLEMESSAGE_1));
622 int music_global = menu.music[mode];
623 int music_local = base + nr;
626 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
627 nr, initial, is_image,
628 music_global, getMusicListEntry(music_global)->filename,
629 music_local, getMusicListEntry(music_local)->filename);
632 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
635 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
638 return MUS_UNDEFINED;
641 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
643 boolean is_image = tci->is_image;
644 int initial = tci->initial;
645 int nr = tci->local_nr;
646 struct TitleFadingInfo ti;
650 int graphic = getTitleScreenGraphic(nr, initial);
652 /* initialize fading control values to default title config settings */
653 ti = (initial ? title_initial_default : title_default);
655 /* override default settings with image config settings, if defined */
656 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
657 ti.fade_mode = graphic_info[graphic].fade_mode;
658 if (graphic_info[graphic].fade_delay > -1)
659 ti.fade_delay = graphic_info[graphic].fade_delay;
660 if (graphic_info[graphic].post_delay > -1)
661 ti.post_delay = graphic_info[graphic].post_delay;
662 if (graphic_info[graphic].auto_delay > -1)
663 ti.auto_delay = graphic_info[graphic].auto_delay;
669 ti.fade_mode = titlemessage_initial[nr].fade_mode;
670 ti.fade_delay = titlemessage_initial[nr].fade_delay;
671 ti.post_delay = titlemessage_initial[nr].post_delay;
672 ti.auto_delay = titlemessage_initial[nr].auto_delay;
676 ti.fade_mode = titlemessage[nr].fade_mode;
677 ti.fade_delay = titlemessage[nr].fade_delay;
678 ti.post_delay = titlemessage[nr].post_delay;
679 ti.auto_delay = titlemessage[nr].auto_delay;
684 if (ti.anim_mode == ANIM_NONE)
685 ti.fade_delay = ti.post_delay = 0;
691 static int compareTitleControlInfo(const void *object1, const void *object2)
693 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
694 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
697 if (tci1->initial != tci2->initial)
698 compare_result = (tci1->initial ? -1 : +1);
699 else if (tci1->sort_priority != tci2->sort_priority)
700 compare_result = tci1->sort_priority - tci2->sort_priority;
701 else if (tci1->is_image != tci2->is_image)
702 compare_result = (tci1->is_image ? -1 : +1);
704 compare_result = tci1->local_nr - tci2->local_nr;
706 return compare_result;
709 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
711 int nr, int sort_priority)
713 title_controls[num_title_screens].is_image = is_image;
714 title_controls[num_title_screens].initial = initial;
715 title_controls[num_title_screens].local_nr = nr;
716 title_controls[num_title_screens].sort_priority = sort_priority;
721 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
725 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
727 int graphic = getTitleScreenGraphic(i, initial);
728 Bitmap *bitmap = graphic_info[graphic].bitmap;
729 int sort_priority = graphic_info[graphic].sort_priority;
732 /* skip images and messages (fonts!) when using forced custom graphics */
733 if (setup.override_level_graphics && !initial)
738 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
741 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
743 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
744 char *filename = getLevelSetTitleMessageFilename(i, initial);
745 int sort_priority = tmi->sort_priority;
748 /* skip images and messages (fonts!) when using forced custom graphics */
749 if (setup.override_level_graphics)
753 if (filename != NULL)
754 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
758 static void InitializeTitleControls(boolean show_title_initial)
760 num_title_screens = 0;
763 /* 1st step: initialize title screens for game start (only when starting) */
764 if (show_title_initial)
765 InitializeTitleControls_CheckTitleInfo(TRUE);
768 /* 2nd step: initialize title screens for current level set */
769 InitializeTitleControls_CheckTitleInfo(FALSE);
771 /* sort title screens according to sort_priority and title number */
772 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
773 compareTitleControlInfo);
776 static boolean visibleMenuPos(struct MenuPosInfo *pos)
778 return (pos != NULL && pos->x != -1 && pos->y != -1);
781 static boolean visibleTextPos(struct TextPosInfo *pos)
783 return (pos != NULL && pos->x != -1 && pos->y != -1);
786 static void InitializeMainControls()
788 boolean local_team_mode = (!options.network && setup.team_mode);
791 /* set main control text values to dynamically determined values */
792 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
794 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
795 menu.main.text.first_level.size));
796 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
797 menu.main.text.last_level.size));
798 strcpy(main_text_level_number, int2str(level_nr,
799 menu.main.text.level_number.size));
801 main_text_level_year = leveldir_current->year;
802 main_text_level_imported_from = leveldir_current->imported_from;
803 main_text_level_imported_by = leveldir_current->imported_by;
804 main_text_level_tested_by = leveldir_current->tested_by;
806 /* set main control screen positions to dynamically determined values */
807 for (i = 0; main_controls[i].nr != -1; i++)
809 struct MainControlInfo *mci = &main_controls[i];
811 struct MenuPosInfo *pos_button = mci->pos_button;
812 struct TextPosInfo *pos_text = mci->pos_text;
813 struct TextPosInfo *pos_input = mci->pos_input;
814 char *text = (mci->text ? *mci->text : NULL);
815 char *input = (mci->input ? *mci->input : NULL);
816 int button_graphic = mci->button_graphic;
818 int font_text = (pos_text ? pos_text->font : -1);
819 int font_input = (pos_input ? pos_input->font : -1);
821 int font_text = mci->font_text;
822 int font_input = mci->font_input;
825 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
826 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
827 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
828 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
829 int text_chars = (text != NULL ? strlen(text) : 0);
830 int input_chars = (input != NULL ? strlen(input) : 0);
833 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
835 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
836 int text_width = font_text_width * text_chars;
837 int text_height = font_text_height;
838 int input_width = font_input_width * input_chars;
839 int input_height = font_input_height;
841 if (nr == MAIN_CONTROL_NAME)
844 if (menu.main.input.name.x == -1)
845 menu.main.input.name.x = menu.main.text.name.x + text_width;
846 if (menu.main.input.name.y == -1)
847 menu.main.input.name.y = menu.main.text.name.y;
851 menu.main.input.name.width = input_width;
852 menu.main.input.name.height = input_height;
854 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
855 menu.main.input.name.height = font_input_height;
859 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
861 if (pos_button->width == 0)
862 pos_button->width = button_width;
863 if (pos_button->height == 0)
864 pos_button->height = button_height;
867 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
869 /* calculate width for non-clickable text -- needed for text alignment */
870 boolean calculate_text_width = (pos_button == NULL && text != NULL);
872 if (visibleMenuPos(pos_button))
874 if (pos_text->x == -1)
875 pos_text->x = pos_button->x + pos_button->width;
876 if (pos_text->y == -1)
877 pos_text->y = pos_button->y;
880 if (pos_text->width == -1 || calculate_text_width)
881 pos_text->width = text_width;
882 if (pos_text->height == -1)
883 pos_text->height = text_height;
886 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
888 if (visibleTextPos(pos_text))
890 if (pos_input->x == -1)
891 pos_input->x = pos_text->x + pos_text->width;
892 if (pos_input->y == -1)
893 pos_input->y = pos_text->y;
896 if (pos_input->width == -1)
897 pos_input->width = input_width;
898 if (pos_input->height == -1)
899 pos_input->height = input_height;
904 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
905 boolean active_input)
909 for (i = 0; main_controls[i].nr != -1; i++)
911 struct MainControlInfo *mci = &main_controls[i];
913 if (mci->nr == nr || nr == -1)
915 struct MenuPosInfo *pos_button = mci->pos_button;
916 struct TextPosInfo *pos_text = mci->pos_text;
917 struct TextPosInfo *pos_input = mci->pos_input;
918 char *text = (mci->text ? *mci->text : NULL);
919 char *input = (mci->input ? *mci->input : NULL);
920 int button_graphic = mci->button_graphic;
922 int font_text = (pos_text ? pos_text->font : -1);
923 int font_input = (pos_input ? pos_input->font : -1);
925 int font_text = mci->font_text;
926 int font_input = mci->font_input;
931 button_graphic = BUTTON_ACTIVE(button_graphic);
932 font_text = FONT_ACTIVE(font_text);
937 font_input = FONT_ACTIVE(font_input);
940 if (visibleMenuPos(pos_button))
942 struct MenuPosInfo *pos = pos_button;
943 int x = mSX + pos->x;
944 int y = mSY + pos->y;
946 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
947 DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
950 if (visibleTextPos(pos_text) && text != NULL)
952 struct TextPosInfo *pos = pos_text;
953 int x = mSX + ALIGNED_TEXT_XPOS(pos);
954 int y = mSY + ALIGNED_TEXT_YPOS(pos);
957 /* (check why/if this is needed) */
958 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
960 DrawText(x, y, text, font_text);
963 if (visibleTextPos(pos_input) && input != NULL)
965 struct TextPosInfo *pos = pos_input;
966 int x = mSX + ALIGNED_TEXT_XPOS(pos);
967 int y = mSY + ALIGNED_TEXT_YPOS(pos);
970 /* (check why/if this is needed) */
971 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
973 DrawText(x, y, input, font_input);
979 static void DrawCursorAndText_Main(int nr, boolean active_text)
981 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
985 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
987 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
991 static struct MainControlInfo *getMainControlInfo(int nr)
995 for (i = 0; main_controls[i].nr != -1; i++)
996 if (main_controls[i].nr == nr)
997 return &main_controls[i];
1002 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1007 int rect_x = ALIGNED_TEXT_XPOS(rect);
1008 int rect_y = ALIGNED_TEXT_YPOS(rect);
1010 return (x >= rect_x && x < rect_x + rect->width &&
1011 y >= rect_y && y < rect_y + rect->height);
1014 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1019 int rect_x = ALIGNED_TEXT_XPOS(rect);
1020 int rect_y = ALIGNED_TEXT_YPOS(rect);
1022 return (x >= rect_x && x < rect_x + rect->width &&
1023 y >= rect_y && y < rect_y + rect->height);
1026 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1029 static int cursor_array[MAX_LEV_FIELDY];
1031 static int cursor_array[SCR_FIELDY];
1033 int x = mSX + TILEX * xpos;
1034 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1039 cursor_array[ypos] = graphic;
1041 graphic = cursor_array[ypos];
1045 graphic = BUTTON_ACTIVE(graphic);
1047 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1048 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1051 static void initCursor(int ypos, int graphic)
1053 drawCursorExt(0, ypos, FALSE, graphic);
1056 static void drawCursor(int ypos, boolean active)
1058 drawCursorExt(0, ypos, active, -1);
1061 static void drawCursorXY(int xpos, int ypos, int graphic)
1063 drawCursorExt(xpos, ypos, FALSE, graphic);
1066 static void drawChooseTreeCursor(int ypos, boolean active)
1068 int last_game_status = game_status; /* save current game status */
1071 /* force LEVELS draw offset on artwork setup screen */
1072 game_status = GAME_MODE_LEVELS;
1075 drawCursorExt(0, ypos, active, -1);
1077 game_status = last_game_status; /* restore current game status */
1082 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1083 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1087 static int getPrevlevelButtonPos()
1092 static int getCurrentLevelTextPos()
1094 return (getPrevlevelButtonPos() + 1);
1097 static int getNextLevelButtonPos()
1099 return getPrevlevelButtonPos() + 3 + 1;
1102 static int getLevelRangeTextPos()
1104 return getNextLevelButtonPos() + 1;
1108 int effectiveGameStatus()
1110 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1111 return GAME_MODE_TITLE;
1116 void DrawTitleScreenImage(int nr, boolean initial)
1118 int graphic = getTitleScreenGraphic(nr, initial);
1119 Bitmap *bitmap = graphic_info[graphic].bitmap;
1120 int width = graphic_info[graphic].width;
1121 int height = graphic_info[graphic].height;
1122 int src_x = graphic_info[graphic].src_x;
1123 int src_y = graphic_info[graphic].src_y;
1129 if (width > WIN_XSIZE)
1131 /* image width too large for window => center image horizontally */
1132 src_x = (width - WIN_XSIZE) / 2;
1136 if (height > WIN_YSIZE)
1138 /* image height too large for window => center image vertically */
1139 src_y = (height - WIN_YSIZE) / 2;
1143 /* always display title screens centered */
1144 dst_x = (WIN_XSIZE - width) / 2;
1145 dst_y = (WIN_YSIZE - height) / 2;
1147 SetDrawBackgroundMask(REDRAW_ALL);
1148 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1150 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1152 if (DrawingOnBackground(dst_x, dst_y))
1154 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1155 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1158 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1160 redraw_mask = REDRAW_ALL;
1163 void DrawTitleScreenMessage(int nr, boolean initial)
1165 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1166 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1167 int last_game_status = game_status; /* save current game status */
1169 if (filename == NULL)
1172 /* force TITLE font on title message screen */
1173 game_status = getTitleMessageGameMode(initial);
1175 /* if chars set to "-1", automatically determine by text and font width */
1176 if (tmi->chars == -1)
1177 tmi->chars = tmi->width / getFontWidth(tmi->font);
1179 tmi->width = tmi->chars * getFontWidth(tmi->font);
1181 /* if lines set to "-1", automatically determine by text and font height */
1182 if (tmi->lines == -1)
1183 tmi->lines = tmi->height / getFontHeight(tmi->font);
1185 tmi->height = tmi->lines * getFontHeight(tmi->font);
1187 SetDrawBackgroundMask(REDRAW_ALL);
1188 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1190 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1192 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1193 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1194 tmi->autowrap, tmi->centered, tmi->parse_comments);
1196 game_status = last_game_status; /* restore current game status */
1199 void DrawTitleScreen()
1201 KeyboardAutoRepeatOff();
1204 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1207 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1212 boolean CheckTitleScreen(boolean levelset_has_changed)
1214 static boolean show_title_initial = TRUE;
1215 boolean show_titlescreen = FALSE;
1217 /* needed to be able to skip title screen, if no image or message defined */
1218 InitializeTitleControls(show_title_initial);
1220 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1221 show_titlescreen = TRUE;
1223 /* show initial title images and messages only once at program start */
1224 show_title_initial = FALSE;
1226 return (show_titlescreen && num_title_screens > 0);
1229 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1231 static LevelDirTree *leveldir_last_valid = NULL;
1232 boolean levelset_has_changed = FALSE;
1234 FadeSetLeaveScreen();
1236 /* do not fade out here -- function may continue and fade on editor screen */
1239 FadeSoundsAndMusic();
1241 KeyboardAutoRepeatOn();
1244 SetDrawDeactivationMask(REDRAW_NONE);
1245 SetDrawBackgroundMask(REDRAW_FIELD);
1247 audio.sound_deactivated = FALSE;
1251 /* needed if last screen was the playing screen, invoked from level editor */
1252 if (level_editor_test_game)
1254 game_status = GAME_MODE_EDITOR;
1260 /* needed if last screen was the setup screen and fullscreen state changed */
1261 ToggleFullscreenIfNeeded();
1263 /* leveldir_current may be invalid (level group, parent link) */
1264 if (!validLevelSeries(leveldir_current))
1265 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1267 if (leveldir_current != leveldir_last_valid)
1268 levelset_has_changed = TRUE;
1270 /* store valid level series information */
1271 leveldir_last_valid = leveldir_current;
1273 init_last = init; /* switch to new busy animation */
1275 /* needed if last screen (level choice) changed graphics, sounds or music */
1276 ReloadCustomArtwork(0);
1278 if (redraw_mask & REDRAW_ALL)
1279 fade_mask = REDRAW_ALL;
1284 /* needed if last screen was the editor screen */
1285 UndrawSpecialEditorDoor();
1287 if (fade_mask == REDRAW_FIELD)
1293 /* needed if different viewport properties defined for menues */
1294 ChangeViewportPropertiesIfNeeded();
1297 #if defined(TARGET_SDL)
1298 SetDrawtoField(DRAW_BACKBUFFER);
1301 if (CheckTitleScreen(levelset_has_changed))
1303 game_status = GAME_MODE_TITLE;
1310 /* level_nr may have been set to value over handicap with level editor */
1311 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1312 level_nr = leveldir_current->handicap_level;
1314 LoadLevel(level_nr);
1315 LoadScore(level_nr);
1317 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1320 if (fade_mask == REDRAW_ALL)
1322 // int door_state = GetDoorState();
1326 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1332 InitializeMainControls();
1334 DrawCursorAndText_Main(-1, FALSE);
1335 DrawPreviewLevel(TRUE);
1337 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1340 if (TAPE_IS_EMPTY(tape))
1342 DrawCompleteVideoDisplay();
1347 /* create gadgets for main menu screen */
1348 FreeScreenGadgets();
1349 CreateScreenGadgets();
1351 /* map gadgets for main menu screen */
1353 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1356 if (fade_mask == REDRAW_ALL)
1358 int door_state = GetDoorState();
1360 // RedrawBackground();
1362 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1366 DrawMaskedBorder(REDRAW_ALL);
1372 /* update screen area with special editor door */
1373 redraw_mask |= REDRAW_ALL;
1377 SetMouseCursor(CURSOR_DEFAULT);
1381 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1384 void DrawAndFadeInMainMenu(int fade_mask)
1386 DrawMainMenuExt(fade_mask, TRUE);
1391 DrawMainMenuExt(REDRAW_ALL, FALSE);
1394 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1395 static void gotoTopLevelDir()
1397 /* move upwards to top level directory */
1398 while (leveldir_current->node_parent)
1400 /* write a "path" into level tree for easy navigation to last level */
1401 if (leveldir_current->node_parent->node_group->cl_first == -1)
1403 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1404 int leveldir_pos = posTreeInfo(leveldir_current);
1405 int num_page_entries;
1406 int cl_first, cl_cursor;
1408 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1409 num_page_entries = num_leveldirs;
1411 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1413 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1414 cl_cursor = leveldir_pos - cl_first;
1416 leveldir_current->node_parent->node_group->cl_first = cl_first;
1417 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1420 leveldir_current = leveldir_current->node_parent;
1425 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1427 static unsigned long title_delay = 0;
1428 static int title_screen_nr = 0;
1429 static int last_sound = -1, last_music = -1;
1430 boolean return_to_main_menu = FALSE;
1431 boolean use_fading_main_menu = TRUE;
1432 struct TitleControlInfo *tci;
1433 struct TitleFadingInfo fading_default;
1434 struct TitleFadingInfo fading_last = fading;
1435 struct TitleFadingInfo fading_next;
1438 if (button == MB_MENU_INITIALIZE)
1441 title_screen_nr = 0;
1442 tci = &title_controls[title_screen_nr];
1444 last_sound = SND_UNDEFINED;
1445 last_music = MUS_UNDEFINED;
1447 if (game_status == GAME_MODE_INFO)
1449 if (num_title_screens == 0)
1451 DrawInfoScreen_NotAvailable("Title screen information:",
1452 "No title screen for this level set.");
1457 FadeSoundsAndMusic();
1460 FadeOut(REDRAW_ALL);
1465 DrawTitleScreenImage(tci->local_nr, tci->initial);
1467 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1469 fading_default = (tci->initial ? title_initial_default : title_default);
1471 fading = fading_next = getTitleFading(tci);
1475 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1476 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1478 fading.fade_mode = FADE_MODE_FADE;
1479 fading.fade_delay = fading_default.fade_delay;
1482 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1483 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1484 fading.fade_mode = FADE_MODE_FADE;
1489 sound = getTitleSound(tci);
1490 music = getTitleMusic(tci);
1492 if (sound != last_sound)
1493 PlayMenuSoundExt(sound);
1494 if (music != last_music)
1495 PlayMenuMusicExt(music);
1501 SetMouseCursor(CURSOR_NONE);
1507 fading = fading_next;
1509 DelayReached(&title_delay, 0); /* reset delay counter */
1515 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1516 button = MB_MENU_CHOICE;
1518 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1519 button = MB_MENU_CHOICE;
1522 if (button == MB_MENU_LEAVE)
1524 return_to_main_menu = TRUE;
1525 use_fading_main_menu = FALSE;
1527 else if (button == MB_MENU_CHOICE)
1529 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1532 FadeOut(REDRAW_FIELD);
1535 FadeSetEnterScreen();
1537 info_mode = INFO_MODE_MAIN;
1538 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1544 tci = &title_controls[title_screen_nr];
1546 if (title_screen_nr < num_title_screens)
1548 sound = getTitleSound(tci);
1549 music = getTitleMusic(tci);
1551 if (sound == SND_UNDEFINED || sound != last_sound)
1553 if (music == MUS_UNDEFINED || music != last_music)
1557 FadeOut(REDRAW_ALL);
1561 DrawTitleScreenImage(tci->local_nr, tci->initial);
1563 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1565 fading_next = getTitleFading(tci);
1568 sound = getTitleSound(tci);
1569 music = getTitleMusic(tci);
1571 if (sound != last_sound)
1572 PlayMenuSoundExt(sound);
1573 if (music != last_music)
1574 PlayMenuMusicExt(music);
1581 /* last screen already faded out, next screen has no animation */
1582 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1583 fading_next.fade_mode == FADE_MODE_NONE)
1584 fading = fading_next;
1586 /* last screen already faded out, next screen has no animation */
1587 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1588 fading_next.fade_mode == FADE_MODE_NONE)
1589 fading = fading_next;
1596 fading = fading_next;
1598 DelayReached(&title_delay, 0); /* reset delay counter */
1602 FadeSoundsAndMusic();
1604 return_to_main_menu = TRUE;
1608 if (return_to_main_menu)
1614 SetMouseCursor(CURSOR_DEFAULT);
1616 if (game_status == GAME_MODE_INFO)
1619 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1622 info_mode = INFO_MODE_MAIN;
1623 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1625 else /* default: return to main menu */
1628 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1631 game_status = GAME_MODE_MAIN;
1632 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1637 void HandleMainMenu_SelectLevel(int step, int direction)
1639 int old_level_nr = level_nr;
1642 new_level_nr = old_level_nr + step * direction;
1643 if (new_level_nr < leveldir_current->first_level)
1644 new_level_nr = leveldir_current->first_level;
1645 if (new_level_nr > leveldir_current->last_level)
1646 new_level_nr = leveldir_current->last_level;
1648 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1650 /* skipping levels is only allowed when trying to skip single level */
1651 if (setup.skip_levels && step == 1 &&
1652 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1654 leveldir_current->handicap_level++;
1655 SaveLevelSetup_SeriesInfo();
1658 new_level_nr = leveldir_current->handicap_level;
1661 if (new_level_nr != old_level_nr)
1663 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1665 PlaySound(SND_MENU_ITEM_SELECTING);
1667 level_nr = new_level_nr;
1669 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1670 int2str(level_nr, menu.main.text.level_number.size),
1671 mci->pos_text->font);
1673 LoadLevel(level_nr);
1674 DrawPreviewLevel(TRUE);
1678 DrawCompleteVideoDisplay();
1680 /* needed because DrawPreviewLevel() takes some time */
1686 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1688 static int choice = MAIN_CONTROL_GAME;
1692 if (button == MB_MENU_INITIALIZE)
1694 DrawCursorAndText_Main(choice, TRUE);
1699 if (mx || my) /* mouse input */
1703 for (i = 0; main_controls[i].nr != -1; i++)
1705 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1706 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1707 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1709 pos = main_controls[i].nr;
1715 else if (dx || dy) /* keyboard input */
1717 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1718 choice == MAIN_CONTROL_SETUP))
1719 button = MB_MENU_CHOICE;
1724 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1726 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1728 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1734 PlaySound(SND_MENU_ITEM_ACTIVATING);
1736 DrawCursorAndText_Main(choice, FALSE);
1737 DrawCursorAndText_Main(pos, TRUE);
1744 PlaySound(SND_MENU_ITEM_SELECTING);
1746 if (pos == MAIN_CONTROL_NAME)
1748 game_status = GAME_MODE_PSEUDO_TYPENAME;
1750 HandleTypeName(strlen(setup.player_name), 0);
1752 else if (pos == MAIN_CONTROL_LEVELS)
1756 game_status = GAME_MODE_LEVELS;
1758 SaveLevelSetup_LastSeries();
1759 SaveLevelSetup_SeriesInfo();
1761 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1768 else if (pos == MAIN_CONTROL_SCORES)
1770 game_status = GAME_MODE_SCORES;
1774 else if (pos == MAIN_CONTROL_EDITOR)
1776 if (leveldir_current->readonly &&
1777 !strEqual(setup.player_name, "Artsoft"))
1778 Request("This level is read only !", REQ_CONFIRM);
1780 game_status = GAME_MODE_EDITOR;
1782 FadeSetEnterScreen();
1785 /* needed if different viewport properties defined for editor */
1786 ChangeViewportPropertiesIfNeeded();
1791 else if (pos == MAIN_CONTROL_INFO)
1793 game_status = GAME_MODE_INFO;
1794 info_mode = INFO_MODE_MAIN;
1798 else if (pos == MAIN_CONTROL_GAME)
1800 StartGameActions(options.network, setup.autorecord, level.random_seed);
1802 else if (pos == MAIN_CONTROL_SETUP)
1804 game_status = GAME_MODE_SETUP;
1805 setup_mode = SETUP_MODE_MAIN;
1809 else if (pos == MAIN_CONTROL_QUIT)
1811 SaveLevelSetup_LastSeries();
1812 SaveLevelSetup_SeriesInfo();
1814 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1815 game_status = GAME_MODE_QUIT;
1820 if (game_status == GAME_MODE_MAIN)
1822 DrawPreviewLevel(FALSE);
1828 /* ========================================================================= */
1829 /* info screen functions */
1830 /* ========================================================================= */
1832 static struct TokenInfo *info_info;
1833 static int num_info_info;
1835 static void execInfoTitleScreen()
1837 info_mode = INFO_MODE_TITLE;
1842 static void execInfoElements()
1844 info_mode = INFO_MODE_ELEMENTS;
1849 static void execInfoMusic()
1851 info_mode = INFO_MODE_MUSIC;
1856 static void execInfoCredits()
1858 info_mode = INFO_MODE_CREDITS;
1863 static void execInfoProgram()
1865 info_mode = INFO_MODE_PROGRAM;
1870 static void execInfoVersion()
1872 info_mode = INFO_MODE_VERSION;
1877 static void execInfoLevelSet()
1879 info_mode = INFO_MODE_LEVELSET;
1884 static void execExitInfo()
1886 game_status = GAME_MODE_MAIN;
1888 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1891 static struct TokenInfo info_info_main[] =
1893 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1894 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1895 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1896 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1897 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1898 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1899 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1900 { TYPE_EMPTY, NULL, "" },
1901 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1906 static void DrawCursorAndText_Info(int pos, boolean active)
1908 int xpos = MENU_SCREEN_START_XPOS;
1909 int ypos = MENU_SCREEN_START_YPOS + pos;
1910 int font_nr = FONT_MENU_1;
1913 font_nr = FONT_ACTIVE(font_nr);
1915 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1917 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1918 drawCursor(pos, active);
1921 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1926 CloseDoor(DOOR_CLOSE_2);
1928 /* (needed after displaying title screens which disable auto repeat) */
1929 KeyboardAutoRepeatOn();
1931 FadeSetLeaveScreen();
1938 if (fade_mask == REDRAW_ALL)
1942 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1948 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1950 info_info = info_info_main;
1954 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1956 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1959 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1960 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1961 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1962 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1963 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1964 initCursor(i, IMG_MENU_BUTTON);
1966 DrawCursorAndText_Info(i, FALSE);
1971 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1976 DrawMaskedBorder(fade_mask);
1983 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1985 static int choice_store[MAX_INFO_MODES];
1986 int choice = choice_store[info_mode]; /* always starts with 0 */
1990 if (button == MB_MENU_INITIALIZE)
1992 /* advance to first valid menu entry */
1993 while (choice < num_info_info &&
1994 info_info[choice].type & TYPE_SKIP_ENTRY)
1996 choice_store[info_mode] = choice;
1998 DrawCursorAndText_Info(choice, TRUE);
2002 else if (button == MB_MENU_LEAVE)
2004 for (y = 0; y < num_info_info; y++)
2006 if (info_info[y].type & TYPE_LEAVE_MENU)
2008 void (*menu_callback_function)(void) = info_info[y].value;
2012 menu_callback_function();
2014 break; /* absolutely needed because function changes 'info_info'! */
2021 if (mx || my) /* mouse input */
2023 x = (mx - mSX) / 32;
2024 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2026 else if (dx || dy) /* keyboard input */
2030 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2032 if (info_info[choice].type & menu_navigation_type ||
2033 info_info[choice].type & TYPE_ENTER_SCREEN ||
2034 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2035 info_info[choice].type & TYPE_YES_NO_AUTO)
2036 button = MB_MENU_CHOICE;
2041 /* jump to next non-empty menu entry (up or down) */
2042 while (y > 0 && y < num_info_info - 1 &&
2043 info_info[y].type & TYPE_SKIP_ENTRY)
2047 if (IN_VIS_FIELD(x, y) &&
2048 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2054 PlaySound(SND_MENU_ITEM_ACTIVATING);
2056 DrawCursorAndText_Info(choice, FALSE);
2057 DrawCursorAndText_Info(y, TRUE);
2059 choice = choice_store[info_mode] = y;
2062 else if (!(info_info[y].type & TYPE_GHOSTED))
2064 PlaySound(SND_MENU_ITEM_SELECTING);
2066 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2068 void (*menu_callback_function)(void) = info_info[choice].value;
2070 FadeSetFromType(info_info[y].type);
2072 menu_callback_function();
2078 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2080 int ystart1 = mSY - SY + 100;
2081 int ystart2 = mSY - SY + 150;
2082 int ybottom = mSY - SY + SYSIZE - 20;
2084 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2086 FadeOut(REDRAW_FIELD);
2091 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2092 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2094 DrawTextSCentered(ybottom, FONT_TEXT_4,
2095 "Press any key or button for info menu");
2097 FadeIn(REDRAW_FIELD);
2100 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2102 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2103 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2104 int xstart = mSX + 16;
2105 int ystart1 = mSY - SY + 100;
2106 int ystart2 = mSY + 64 + 2 * 32;
2107 int ybottom = mSY - SY + SYSIZE - 20;
2108 int ystep = TILEY + 4;
2109 int element, action, direction;
2117 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2118 infoscreen_step[i] = infoscreen_frame[i] = 0;
2123 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2125 DrawTextSCentered(ybottom, FONT_TEXT_4,
2126 "Press any key or button for next page");
2132 while (helpanim_info[j].element != HELPANIM_LIST_END)
2134 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2139 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2148 j += infoscreen_step[i - start];
2150 element = helpanim_info[j].element;
2151 action = helpanim_info[j].action;
2152 direction = helpanim_info[j].direction;
2155 element = EL_UNKNOWN;
2157 if (action != -1 && direction != -1)
2158 graphic = el_act_dir2img(element, action, direction);
2159 else if (action != -1)
2160 graphic = el_act2img(element, action);
2161 else if (direction != -1)
2162 graphic = el_dir2img(element, direction);
2164 graphic = el2img(element);
2166 delay = helpanim_info[j++].delay;
2171 if (infoscreen_frame[i - start] == 0)
2174 infoscreen_frame[i - start] = delay - 1;
2178 sync_frame = delay - infoscreen_frame[i - start];
2179 infoscreen_frame[i - start]--;
2182 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2184 if (!infoscreen_frame[i - start])
2185 infoscreen_step[i - start] = 0;
2189 if (!infoscreen_frame[i - start])
2190 infoscreen_step[i - start]++;
2191 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2197 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2199 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2200 graphic, sync_frame, USE_MASKING);
2203 DrawInfoScreen_HelpText(element, action, direction, i - start);
2208 redraw_mask |= REDRAW_FIELD;
2213 static char *getHelpText(int element, int action, int direction)
2215 char token[MAX_LINE_LEN];
2217 strcpy(token, element_info[element].token_name);
2220 strcat(token, element_action_info[action].suffix);
2222 if (direction != -1)
2223 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2225 return getHashEntry(helptext_info, token);
2228 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2230 int font_nr = FONT_INFO_ELEMENTS;
2231 int font_width = getFontWidth(font_nr);
2232 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2233 int sy = mSY + 65 + 2 * 32 + 1;
2234 int ystep = TILEY + 4;
2235 int pad_x = sx - SX;
2236 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2237 int max_lines_per_text = 2;
2240 if (action != -1 && direction != -1) /* element.action.direction */
2241 text = getHelpText(element, action, direction);
2243 if (text == NULL && action != -1) /* element.action */
2244 text = getHelpText(element, action, -1);
2246 if (text == NULL && direction != -1) /* element.direction */
2247 text = getHelpText(element, -1, direction);
2249 if (text == NULL) /* base element */
2250 text = getHelpText(element, -1, -1);
2252 if (text == NULL) /* not found */
2253 text = "No description available";
2255 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2256 sy += getFontHeight(font_nr) / 2;
2258 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2259 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2260 TRUE, FALSE, FALSE);
2263 void DrawInfoScreen_TitleScreen()
2268 void HandleInfoScreen_TitleScreen(int button)
2270 HandleTitleScreen(0, 0, 0, 0, button);
2273 void DrawInfoScreen_Elements()
2275 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2277 FadeOut(REDRAW_FIELD);
2282 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2284 FadeIn(REDRAW_FIELD);
2289 void HandleInfoScreen_Elements(int button)
2291 static unsigned long info_delay = 0;
2292 static int num_anims;
2293 static int num_pages;
2295 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2298 if (button == MB_MENU_INITIALIZE)
2300 boolean new_element = TRUE;
2304 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2306 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2308 else if (new_element)
2311 new_element = FALSE;
2315 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2319 if (button == MB_MENU_LEAVE)
2321 PlaySound(SND_MENU_ITEM_SELECTING);
2323 info_mode = INFO_MODE_MAIN;
2328 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2330 if (button != MB_MENU_INITIALIZE)
2332 PlaySound(SND_MENU_ITEM_SELECTING);
2337 if (page >= num_pages)
2339 FadeSoundsAndMusic();
2341 info_mode = INFO_MODE_MAIN;
2342 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2349 FadeSetNextScreen();
2352 if (button != MB_MENU_INITIALIZE)
2353 FadeOut(REDRAW_FIELD);
2355 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2357 if (button != MB_MENU_INITIALIZE)
2358 FadeIn(REDRAW_FIELD);
2362 if (DelayReached(&info_delay, GameFrameDelay))
2363 if (page < num_pages)
2364 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2366 PlayMenuSoundIfLoop();
2370 void DrawInfoScreen_Music()
2372 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2375 FadeOut(REDRAW_FIELD);
2383 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2386 FadeIn(REDRAW_FIELD);
2390 void HandleInfoScreen_Music(int button)
2392 static struct MusicFileInfo *list = NULL;
2393 int ystart1 = mSY - SY + 100;
2394 int ystart2 = mSY - SY + 150;
2395 int ybottom = mSY - SY + SYSIZE - 20;
2398 if (button == MB_MENU_INITIALIZE)
2400 list = music_file_info;
2404 FadeSoundsAndMusic();
2409 DrawTextSCentered(ystart1, FONT_TEXT_1,
2410 "No music info for this level set.");
2412 DrawTextSCentered(ybottom, FONT_TEXT_4,
2413 "Press any key or button for info menu");
2419 if (button == MB_MENU_LEAVE)
2421 PlaySound(SND_MENU_ITEM_SELECTING);
2423 FadeSoundsAndMusic();
2425 info_mode = INFO_MODE_MAIN;
2430 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2434 if (button != MB_MENU_INITIALIZE)
2436 PlaySound(SND_MENU_ITEM_SELECTING);
2444 FadeSoundsAndMusic();
2446 info_mode = INFO_MODE_MAIN;
2447 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2452 FadeSoundsAndMusic();
2455 if (list != music_file_info)
2456 FadeSetNextScreen();
2459 if (button != MB_MENU_INITIALIZE)
2460 FadeOut(REDRAW_FIELD);
2467 int sound = list->music;
2469 if (sound_info[sound].loop)
2470 PlaySoundLoop(sound);
2474 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2478 PlayMusic(list->music);
2480 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2483 if (!strEqual(list->title, UNKNOWN_NAME))
2485 if (!strEqual(list->title_header, UNKNOWN_NAME))
2486 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2488 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2491 if (!strEqual(list->artist, UNKNOWN_NAME))
2493 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2494 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2496 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2498 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2501 if (!strEqual(list->album, UNKNOWN_NAME))
2503 if (!strEqual(list->album_header, UNKNOWN_NAME))
2504 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2506 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2508 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2511 if (!strEqual(list->year, UNKNOWN_NAME))
2513 if (!strEqual(list->year_header, UNKNOWN_NAME))
2514 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2516 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2518 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2521 DrawTextSCentered(ybottom, FONT_TEXT_4,
2522 "Press any key or button for next page");
2524 if (button != MB_MENU_INITIALIZE)
2525 FadeIn(REDRAW_FIELD);
2528 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2529 PlaySoundLoop(list->music);
2532 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2534 int ystart1 = mSY - SY + 100;
2535 int ystart2 = mSY - SY + 150;
2536 int ybottom = mSY - SY + SYSIZE - 20;
2542 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2546 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2547 "Special thanks to");
2548 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2550 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2552 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2553 "\"Boulder Dash\"");
2554 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2556 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2558 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2560 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2561 "First Star Software");
2563 else if (screen_nr == 1)
2565 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2566 "Special thanks to");
2567 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2568 "Klaus Heinz & Volker Wertich");
2569 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2571 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2572 "\"Emerald Mine\"");
2573 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2575 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2577 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2579 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2582 else if (screen_nr == 2)
2584 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2585 "Special thanks to");
2586 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2587 "Michael Stopp & Philip Jespersen");
2588 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2590 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2592 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2594 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2596 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2598 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2599 "Digital Integration");
2601 else if (screen_nr == 3)
2603 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2604 "Special thanks to");
2605 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2606 "Hiroyuki Imabayashi");
2607 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2609 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2611 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2613 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2615 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2617 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2620 else if (screen_nr == 4)
2622 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2623 "Special thanks to");
2624 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2626 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2628 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2629 "Jürgen Bonhagen");
2630 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2631 "for the continuous creation");
2632 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2633 "of outstanding level sets");
2635 else if (screen_nr == 5)
2637 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2639 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2641 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2642 "for ideas and inspiration by");
2643 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2646 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2648 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2650 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2651 "for ideas and inspiration by");
2652 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2655 else if (screen_nr == 6)
2657 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2659 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2662 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2663 "for the code base used for the");
2664 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2665 "native Emerald Mine engine");
2667 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2668 "for the new Emerald Mine engine");
2671 else if (screen_nr == 7)
2673 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2675 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2677 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2678 "for the initial DOS port");
2680 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2682 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2684 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2685 "for some additional toons");
2687 else if (screen_nr == 8)
2689 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2690 "And not to forget:");
2691 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2693 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2694 "All those who contributed");
2695 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2696 "levels to this game");
2697 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2701 DrawTextSCentered(ybottom, FONT_TEXT_4,
2702 "Press any key or button for next page");
2705 void DrawInfoScreen_Credits()
2707 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2709 FadeSoundsAndMusic();
2712 FadeOut(REDRAW_FIELD);
2715 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2718 FadeIn(REDRAW_FIELD);
2722 void HandleInfoScreen_Credits(int button)
2724 static int screen_nr = 0;
2725 int num_screens = 9;
2727 if (button == MB_MENU_INITIALIZE)
2731 // DrawInfoScreen_CreditsScreen(screen_nr);
2734 if (button == MB_MENU_LEAVE)
2736 PlaySound(SND_MENU_ITEM_SELECTING);
2738 info_mode = INFO_MODE_MAIN;
2743 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2745 if (button != MB_MENU_INITIALIZE)
2747 PlaySound(SND_MENU_ITEM_SELECTING);
2752 if (screen_nr >= num_screens)
2754 FadeSoundsAndMusic();
2756 info_mode = INFO_MODE_MAIN;
2757 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2764 FadeSetNextScreen();
2767 if (button != MB_MENU_INITIALIZE)
2768 FadeOut(REDRAW_FIELD);
2770 DrawInfoScreen_CreditsScreen(screen_nr);
2772 if (button != MB_MENU_INITIALIZE)
2773 FadeIn(REDRAW_FIELD);
2777 PlayMenuSoundIfLoop();
2781 void DrawInfoScreen_Program()
2783 int ystart1 = mSY - SY + 100;
2784 int ystart2 = mSY - SY + 150;
2785 int ybottom = mSY - SY + SYSIZE - 20;
2788 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2791 FadeOut(REDRAW_FIELD);
2797 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2799 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2800 "This game is Freeware!");
2801 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2802 "If you like it, send e-mail to:");
2803 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2804 PROGRAM_EMAIL_STRING);
2805 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2806 "or SnailMail to:");
2807 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2809 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2810 "Detmolder Strasse 189");
2811 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2813 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2815 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2816 "More information and levels:");
2817 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2818 PROGRAM_WEBSITE_STRING);
2819 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2820 "If you have created new levels,");
2821 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2822 "send them to me to include them!");
2823 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2826 DrawTextSCentered(ybottom, FONT_TEXT_4,
2827 "Press any key or button for info menu");
2830 FadeIn(REDRAW_FIELD);
2834 void HandleInfoScreen_Program(int button)
2836 if (button == MB_MENU_LEAVE)
2838 PlaySound(SND_MENU_ITEM_SELECTING);
2840 info_mode = INFO_MODE_MAIN;
2845 else if (button == MB_MENU_CHOICE)
2847 PlaySound(SND_MENU_ITEM_SELECTING);
2849 FadeSoundsAndMusic();
2852 FadeOut(REDRAW_FIELD);
2855 info_mode = INFO_MODE_MAIN;
2856 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2860 PlayMenuSoundIfLoop();
2864 void DrawInfoScreen_Version()
2866 int font_header = FONT_TEXT_3;
2867 int font_text = FONT_TEXT_2;
2868 int xstep = getFontWidth(font_text);
2869 int ystep = getFontHeight(font_text);
2870 int ystart1 = mSY - SY + 100;
2871 int ystart2 = mSY - SY + 150;
2872 int ybottom = mSY - SY + SYSIZE - 20;
2873 int xstart1 = mSX + 2 * xstep;
2874 int xstart2 = mSX + 19 * xstep;
2875 #if defined(TARGET_SDL)
2876 int xstart3 = mSX + 29 * xstep;
2877 SDL_version sdl_version_compiled;
2878 const SDL_version *sdl_version_linked;
2879 int driver_name_len = 8;
2880 char driver_name[driver_name_len];
2883 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2886 FadeOut(REDRAW_FIELD);
2892 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2894 DrawTextF(xstart1, ystart2, font_header, "Name");
2895 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2898 DrawTextF(xstart1, ystart2, font_header, "Version");
2899 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2902 DrawTextF(xstart1, ystart2, font_header, "Platform");
2903 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2906 DrawTextF(xstart1, ystart2, font_header, "Target");
2907 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2910 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2911 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2913 #if defined(TARGET_SDL)
2914 ystart2 += 3 * ystep;
2915 DrawTextF(xstart1, ystart2, font_header, "Library");
2916 DrawTextF(xstart2, ystart2, font_header, "compiled");
2917 DrawTextF(xstart3, ystart2, font_header, "linked");
2919 SDL_VERSION(&sdl_version_compiled);
2920 sdl_version_linked = SDL_Linked_Version();
2922 ystart2 += 2 * ystep;
2923 DrawTextF(xstart1, ystart2, font_text, "SDL");
2924 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2925 sdl_version_compiled.major,
2926 sdl_version_compiled.minor,
2927 sdl_version_compiled.patch);
2928 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2929 sdl_version_linked->major,
2930 sdl_version_linked->minor,
2931 sdl_version_linked->patch);
2933 SDL_IMAGE_VERSION(&sdl_version_compiled);
2934 sdl_version_linked = IMG_Linked_Version();
2937 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2938 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2939 sdl_version_compiled.major,
2940 sdl_version_compiled.minor,
2941 sdl_version_compiled.patch);
2942 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2943 sdl_version_linked->major,
2944 sdl_version_linked->minor,
2945 sdl_version_linked->patch);
2947 SDL_MIXER_VERSION(&sdl_version_compiled);
2948 sdl_version_linked = Mix_Linked_Version();
2951 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2952 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2953 sdl_version_compiled.major,
2954 sdl_version_compiled.minor,
2955 sdl_version_compiled.patch);
2956 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2957 sdl_version_linked->major,
2958 sdl_version_linked->minor,
2959 sdl_version_linked->patch);
2961 SDL_NET_VERSION(&sdl_version_compiled);
2962 sdl_version_linked = SDLNet_Linked_Version();
2965 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2966 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2967 sdl_version_compiled.major,
2968 sdl_version_compiled.minor,
2969 sdl_version_compiled.patch);
2970 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2971 sdl_version_linked->major,
2972 sdl_version_linked->minor,
2973 sdl_version_linked->patch);
2975 ystart2 += 3 * ystep;
2976 DrawTextF(xstart1, ystart2, font_header, "Driver");
2977 DrawTextF(xstart2, ystart2, font_header, "Requested");
2978 DrawTextF(xstart3, ystart2, font_header, "Used");
2980 SDL_VideoDriverName(driver_name, driver_name_len);
2982 ystart2 += 2 * ystep;
2983 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2984 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2985 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2987 SDL_AudioDriverName(driver_name, driver_name_len);
2990 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2991 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2992 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2995 DrawTextSCentered(ybottom, FONT_TEXT_4,
2996 "Press any key or button for info menu");
2999 FadeIn(REDRAW_FIELD);
3003 void HandleInfoScreen_Version(int button)
3005 if (button == MB_MENU_LEAVE)
3007 PlaySound(SND_MENU_ITEM_SELECTING);
3009 info_mode = INFO_MODE_MAIN;
3014 else if (button == MB_MENU_CHOICE)
3016 PlaySound(SND_MENU_ITEM_SELECTING);
3018 FadeSoundsAndMusic();
3021 FadeOut(REDRAW_FIELD);
3024 info_mode = INFO_MODE_MAIN;
3025 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3029 PlayMenuSoundIfLoop();
3033 void DrawInfoScreen_LevelSet()
3035 struct TitleMessageInfo *tmi = &readme;
3036 char *filename = getLevelSetInfoFilename();
3038 /* if chars set to "-1", automatically determine by text and font width */
3039 if (tmi->chars == -1)
3040 tmi->chars = tmi->width / getFontWidth(tmi->font);
3042 tmi->width = tmi->chars * getFontWidth(tmi->font);
3044 /* if lines set to "-1", automatically determine by text and font height */
3045 if (tmi->lines == -1)
3046 tmi->lines = tmi->height / getFontHeight(tmi->font);
3048 tmi->height = tmi->lines * getFontHeight(tmi->font);
3050 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3053 FadeOut(REDRAW_FIELD);
3059 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3061 if (filename != NULL)
3062 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3063 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3064 tmi->autowrap, tmi->centered, tmi->parse_comments);
3066 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3067 "No information for this level set.");
3069 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3070 "Press any key or button for info menu");
3073 FadeIn(REDRAW_FIELD);
3077 void HandleInfoScreen_LevelSet(int button)
3079 if (button == MB_MENU_LEAVE)
3081 PlaySound(SND_MENU_ITEM_SELECTING);
3083 info_mode = INFO_MODE_MAIN;
3088 else if (button == MB_MENU_CHOICE)
3090 PlaySound(SND_MENU_ITEM_SELECTING);
3092 FadeSoundsAndMusic();
3095 FadeOut(REDRAW_FIELD);
3098 info_mode = INFO_MODE_MAIN;
3099 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3103 PlayMenuSoundIfLoop();
3107 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3109 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3111 if (info_mode == INFO_MODE_TITLE)
3112 DrawInfoScreen_TitleScreen();
3113 else if (info_mode == INFO_MODE_ELEMENTS)
3114 DrawInfoScreen_Elements();
3115 else if (info_mode == INFO_MODE_MUSIC)
3116 DrawInfoScreen_Music();
3117 else if (info_mode == INFO_MODE_CREDITS)
3118 DrawInfoScreen_Credits();
3119 else if (info_mode == INFO_MODE_PROGRAM)
3120 DrawInfoScreen_Program();
3121 else if (info_mode == INFO_MODE_VERSION)
3122 DrawInfoScreen_Version();
3123 else if (info_mode == INFO_MODE_LEVELSET)
3124 DrawInfoScreen_LevelSet();
3126 DrawInfoScreen_Main(fade_mask, do_fading);
3128 if (info_mode != INFO_MODE_MAIN &&
3129 info_mode != INFO_MODE_TITLE &&
3130 info_mode != INFO_MODE_MUSIC)
3137 void DrawAndFadeInInfoScreen(int fade_mask)
3139 DrawInfoScreenExt(fade_mask, TRUE);
3142 void DrawInfoScreen()
3144 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3147 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3149 if (info_mode == INFO_MODE_TITLE)
3150 HandleInfoScreen_TitleScreen(button);
3151 else if (info_mode == INFO_MODE_ELEMENTS)
3152 HandleInfoScreen_Elements(button);
3153 else if (info_mode == INFO_MODE_MUSIC)
3154 HandleInfoScreen_Music(button);
3155 else if (info_mode == INFO_MODE_CREDITS)
3156 HandleInfoScreen_Credits(button);
3157 else if (info_mode == INFO_MODE_PROGRAM)
3158 HandleInfoScreen_Program(button);
3159 else if (info_mode == INFO_MODE_VERSION)
3160 HandleInfoScreen_Version(button);
3161 else if (info_mode == INFO_MODE_LEVELSET)
3162 HandleInfoScreen_LevelSet(button);
3164 HandleInfoScreen_Main(mx, my, dx, dy, button);
3170 /* ========================================================================= */
3171 /* type name functions */
3172 /* ========================================================================= */
3174 void HandleTypeName(int newxpos, Key key)
3176 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3177 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3178 struct TextPosInfo *pos = mci->pos_input;
3179 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3180 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3181 static int xpos = 0;
3182 int font_nr = pos->font;
3183 int font_active_nr = FONT_ACTIVE(font_nr);
3184 int font_width = getFontWidth(font_active_nr);
3185 char key_char = getValidConfigValueChar(getCharFromKey(key));
3186 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3187 boolean is_active = TRUE;
3189 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3193 strcpy(last_player_name, setup.player_name);
3197 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3199 setup.player_name[xpos] = key_char;
3200 setup.player_name[xpos + 1] = 0;
3204 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3208 setup.player_name[xpos] = 0;
3210 else if (key == KSYM_Return && xpos > 0)
3216 game_status = GAME_MODE_MAIN;
3218 else if (key == KSYM_Escape)
3220 strcpy(setup.player_name, last_player_name);
3224 game_status = GAME_MODE_MAIN;
3229 pos->width = (strlen(setup.player_name) + 1) * font_width;
3230 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3232 DrawText(startx, starty, setup.player_name, font_active_nr);
3233 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3237 pos->width = strlen(setup.player_name) * font_width;
3238 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3240 DrawText(startx, starty, setup.player_name, font_nr);
3245 /* ========================================================================= */
3246 /* tree menu functions */
3247 /* ========================================================================= */
3249 static void DrawChooseTree(TreeInfo **ti_ptr)
3253 FreeScreenGadgets();
3254 CreateScreenGadgets();
3256 CloseDoor(DOOR_CLOSE_2);
3259 FadeOut(REDRAW_FIELD);
3264 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3265 MapScreenTreeGadgets(*ti_ptr);
3268 FadeIn(REDRAW_FIELD);
3274 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3276 struct GadgetInfo *gi = screen_gadget[id];
3277 int items_max, items_visible, item_position;
3279 items_max = numTreeInfoInGroup(ti);
3280 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3281 item_position = first_entry;
3283 if (item_position > items_max - items_visible)
3284 item_position = items_max - items_visible;
3286 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3287 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3288 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3291 static void drawChooseTreeList(int first_entry, int num_page_entries,
3295 char *title_string = NULL;
3296 int yoffset_sets = MENU_TITLE1_YPOS;
3297 int yoffset_setup = 16;
3298 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3300 int last_game_status = game_status; /* save current game status */
3302 title_string = ti->infotext;
3304 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3307 /* force LEVELS font on artwork setup screen */
3308 game_status = GAME_MODE_LEVELS;
3312 /* clear tree list area, but not title or scrollbar */
3313 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3314 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3315 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3317 /* clear tree list area, but not title or scrollbar */
3318 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3319 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3320 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3323 for (i = 0; i < num_page_entries; i++)
3325 TreeInfo *node, *node_first;
3326 int entry_pos = first_entry + i;
3327 int xpos = MENU_SCREEN_START_XPOS;
3328 int ypos = MENU_SCREEN_START_YPOS + i;
3329 int startx = mSX + xpos * 32;
3330 int starty = mSY + ypos * 32;
3331 int font_nr = FONT_TEXT_1;
3332 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3333 int startx_text = startx + font_xoffset;
3334 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3335 int text_size = startx_scrollbar - startx_text;
3336 int max_buffer_len = text_size / getFontWidth(font_nr);
3337 char buffer[max_buffer_len + 1];
3339 node_first = getTreeInfoFirstGroupEntry(ti);
3340 node = getTreeInfoFromPos(node_first, entry_pos);
3342 strncpy(buffer, node->name, max_buffer_len);
3343 buffer[max_buffer_len] = '\0';
3345 DrawText(startx, starty, buffer, font_nr + node->color);
3347 if (node->parent_link)
3348 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3349 else if (node->level_group)
3350 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3352 initCursor(i, IMG_MENU_BUTTON);
3355 game_status = last_game_status; /* restore current game status */
3357 redraw_mask |= REDRAW_FIELD;
3360 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3362 TreeInfo *node, *node_first;
3363 int x, last_redraw_mask = redraw_mask;
3364 int ypos = MENU_TITLE2_YPOS;
3365 int font_nr = FONT_TITLE_2;
3367 if (ti->type != TREE_TYPE_LEVEL_DIR)
3370 node_first = getTreeInfoFirstGroupEntry(ti);
3371 node = getTreeInfoFromPos(node_first, entry_pos);
3373 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3375 if (node->parent_link)
3376 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3378 else if (node->level_group)
3379 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3381 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3382 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3383 node->levels, node->class_desc);
3385 /* let BackToFront() redraw only what is needed */
3386 redraw_mask = last_redraw_mask | REDRAW_TILES;
3387 for (x = 0; x < SCR_FIELDX; x++)
3388 MarkTileDirty(x, 1);
3391 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3394 TreeInfo *ti = *ti_ptr;
3396 int y = ti->cl_cursor;
3397 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3398 int num_entries = numTreeInfoInGroup(ti);
3399 int num_page_entries;
3400 int last_game_status = game_status; /* save current game status */
3401 boolean position_set_by_scrollbar = (dx == 999);
3404 /* force LEVELS draw offset on choose level and artwork setup screen */
3405 game_status = GAME_MODE_LEVELS;
3408 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3409 num_page_entries = num_entries;
3411 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3413 game_status = last_game_status; /* restore current game status */
3415 if (button == MB_MENU_INITIALIZE)
3417 int num_entries = numTreeInfoInGroup(ti);
3418 int entry_pos = posTreeInfo(ti);
3420 if (ti->cl_first == -1)
3422 /* only on initialization */
3423 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3424 ti->cl_cursor = entry_pos - ti->cl_first;
3426 else if (ti->cl_cursor >= num_page_entries ||
3427 (num_entries > num_page_entries &&
3428 num_entries - ti->cl_first < num_page_entries))
3430 /* only after change of list size (by custom graphic configuration) */
3431 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3432 ti->cl_cursor = entry_pos - ti->cl_first;
3435 if (position_set_by_scrollbar)
3438 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3441 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3442 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3443 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3447 else if (button == MB_MENU_LEAVE)
3451 PlaySound(SND_MENU_ITEM_SELECTING);
3453 if (ti->node_parent)
3455 *ti_ptr = ti->node_parent;
3456 DrawChooseTree(ti_ptr);
3458 else if (game_status == GAME_MODE_SETUP)
3460 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3462 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3463 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3464 execSetupGraphics();
3470 game_status = GAME_MODE_MAIN;
3472 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3478 if (mx || my) /* mouse input */
3480 int last_game_status = game_status; /* save current game status */
3483 /* force LEVELS draw offset on artwork setup screen */
3484 game_status = GAME_MODE_LEVELS;
3487 x = (mx - mSX) / 32;
3488 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3490 game_status = last_game_status; /* restore current game status */
3492 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3494 /* move cursor instead of scrolling when already at start/end of list */
3495 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3497 else if (dy == +1 * SCROLL_LINE &&
3498 ti->cl_first + num_page_entries == num_entries)
3501 /* handle scrolling screen one line or page */
3502 if (ti->cl_cursor + dy < 0 ||
3503 ti->cl_cursor + dy > num_page_entries - 1)
3505 if (ABS(dy) == SCROLL_PAGE)
3506 step = num_page_entries - 1;
3508 if (dy < 0 && ti->cl_first > 0)
3510 /* scroll page/line up */
3512 ti->cl_first -= step;
3513 if (ti->cl_first < 0)
3516 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3517 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3518 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3520 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3523 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3525 /* scroll page/line down */
3527 ti->cl_first += step;
3528 if (ti->cl_first + num_page_entries > num_entries)
3529 ti->cl_first = MAX(0, num_entries - num_page_entries);
3531 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3532 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3533 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3535 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3542 /* handle moving cursor one line */
3543 y = ti->cl_cursor + dy;
3548 TreeInfo *node_first, *node_cursor;
3549 int entry_pos = ti->cl_first + y;
3551 node_first = getTreeInfoFirstGroupEntry(ti);
3552 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3554 if (node_cursor->node_group)
3558 PlaySound(SND_MENU_ITEM_SELECTING);
3560 node_cursor->cl_first = ti->cl_first;
3561 node_cursor->cl_cursor = ti->cl_cursor;
3562 *ti_ptr = node_cursor->node_group;
3563 DrawChooseTree(ti_ptr);
3568 else if (dx == -1 && ti->node_parent)
3572 PlaySound(SND_MENU_ITEM_SELECTING);
3574 *ti_ptr = ti->node_parent;
3575 DrawChooseTree(ti_ptr);
3580 if (!anyScrollbarGadgetActive() &&
3581 IN_VIS_FIELD(x, y) &&
3582 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3583 y >= 0 && y < num_page_entries)
3587 if (y != ti->cl_cursor)
3589 PlaySound(SND_MENU_ITEM_ACTIVATING);
3591 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3592 drawChooseTreeCursor(y, TRUE);
3593 drawChooseTreeInfo(ti->cl_first + y, ti);
3600 TreeInfo *node_first, *node_cursor;
3601 int entry_pos = ti->cl_first + y;
3603 PlaySound(SND_MENU_ITEM_SELECTING);
3605 node_first = getTreeInfoFirstGroupEntry(ti);
3606 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3608 if (node_cursor->node_group)
3612 node_cursor->cl_first = ti->cl_first;
3613 node_cursor->cl_cursor = ti->cl_cursor;
3614 *ti_ptr = node_cursor->node_group;
3615 DrawChooseTree(ti_ptr);
3617 else if (node_cursor->parent_link)
3621 *ti_ptr = node_cursor->node_parent;
3622 DrawChooseTree(ti_ptr);
3626 FadeSetEnterScreen();
3628 node_cursor->cl_first = ti->cl_first;
3629 node_cursor->cl_cursor = ti->cl_cursor;
3630 *ti_ptr = node_cursor;
3632 if (ti->type == TREE_TYPE_LEVEL_DIR)
3634 LoadLevelSetup_SeriesInfo();
3636 SaveLevelSetup_LastSeries();
3637 SaveLevelSetup_SeriesInfo();
3641 if (game_status == GAME_MODE_SETUP)
3643 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3645 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3646 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3647 execSetupGraphics();
3653 game_status = GAME_MODE_MAIN;
3661 void DrawChooseLevel()
3663 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3665 DrawChooseTree(&leveldir_current);
3671 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3673 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3678 void DrawHallOfFame(int highlight_position)
3681 FadeSoundsAndMusic();
3683 /* (this is needed when called from GameEnd() after winning a game) */
3684 KeyboardAutoRepeatOn();
3687 /* (this is needed when called from GameEnd() after winning a game) */
3688 SetDrawDeactivationMask(REDRAW_NONE);
3689 SetDrawBackgroundMask(REDRAW_FIELD);
3691 CloseDoor(DOOR_CLOSE_2);
3693 if (highlight_position < 0)
3694 LoadScore(level_nr);
3696 FadeSetEnterScreen();
3698 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3701 FadeOut(REDRAW_FIELD);
3709 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3712 FadeIn(REDRAW_FIELD);
3716 static void drawHallOfFameList(int first_entry, int highlight_position)
3720 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3723 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3724 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3725 "HighScores of Level %d", level_nr);
3727 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3729 int entry = first_entry + i;
3730 boolean active = (entry == highlight_position);
3731 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3732 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3733 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3734 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3735 int dx1 = 3 * getFontWidth(font_nr1);
3736 int dx2 = dx1 + getFontWidth(font_nr1);
3737 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3738 int sy = mSY + 64 + i * 32;
3740 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3741 DrawText(mSX + dx1, sy, ".", font_nr1);
3742 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3744 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3745 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3747 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3750 redraw_mask |= REDRAW_FIELD;
3753 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3755 static int first_entry = 0;
3756 static int highlight_position = 0;
3757 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3759 if (button == MB_MENU_INITIALIZE)
3762 highlight_position = mx;
3763 drawHallOfFameList(first_entry, highlight_position);
3768 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3769 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3773 if (first_entry > 0)
3775 first_entry -= step;
3776 if (first_entry < 0)
3779 drawHallOfFameList(first_entry, highlight_position);
3784 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3786 first_entry += step;
3787 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3788 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3790 drawHallOfFameList(first_entry, highlight_position);
3793 else if (button == MB_MENU_LEAVE)
3795 PlaySound(SND_MENU_ITEM_SELECTING);
3797 FadeSound(SND_BACKGROUND_SCORES);
3799 game_status = GAME_MODE_MAIN;
3803 else if (button == MB_MENU_CHOICE)
3805 PlaySound(SND_MENU_ITEM_SELECTING);
3807 FadeSound(SND_BACKGROUND_SCORES);
3810 FadeOut(REDRAW_FIELD);
3813 game_status = GAME_MODE_MAIN;
3815 DrawAndFadeInMainMenu(REDRAW_FIELD);
3818 if (game_status == GAME_MODE_SCORES)
3819 PlayMenuSoundIfLoop();
3825 /* ========================================================================= */
3826 /* setup screen functions */
3827 /* ========================================================================= */
3829 static struct TokenInfo *setup_info;
3830 static int num_setup_info;
3832 static char *screen_mode_text;
3833 static char *scroll_delay_text;
3834 static char *game_speed_text;
3835 static char *graphics_set_name;
3836 static char *sounds_set_name;
3837 static char *music_set_name;
3839 static void execSetupMain()
3841 setup_mode = SETUP_MODE_MAIN;
3846 static void execSetupGame()
3848 if (game_speeds == NULL)
3852 for (i = 0; game_speeds_list[i].value != -1; i++)
3854 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3855 char identifier[32], name[32];
3856 int value = game_speeds_list[i].value;
3857 char *text = game_speeds_list[i].text;
3859 ti->node_top = &game_speeds;
3860 ti->sort_priority = 10000 - value;
3862 sprintf(identifier, "%d", value);
3863 sprintf(name, "%s", text);
3865 setString(&ti->identifier, identifier);
3866 setString(&ti->name, name);
3867 setString(&ti->name_sorting, name);
3868 setString(&ti->infotext, "Game Speed");
3870 pushTreeInfo(&game_speeds, ti);
3873 /* sort game speed values to start with slowest game speed */
3874 sortTreeInfo(&game_speeds);
3876 /* set current game speed to configured game speed value */
3877 game_speed_current =
3878 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3880 /* if that fails, set current game speed to reliable default value */
3881 if (game_speed_current == NULL)
3882 game_speed_current =
3883 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3885 /* if that also fails, set current game speed to first available speed */
3886 if (game_speed_current == NULL)
3887 game_speed_current = game_speeds;
3890 setup.game_frame_delay = atoi(game_speed_current->identifier);
3892 /* needed for displaying game speed text instead of identifier */
3893 game_speed_text = game_speed_current->name;
3895 setup_mode = SETUP_MODE_GAME;
3900 static void execSetupChooseGameSpeed()
3902 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3907 static void execSetupEditor()
3909 setup_mode = SETUP_MODE_EDITOR;
3914 static void execSetupGraphics()
3916 if (video.fullscreen_available && screen_modes == NULL)
3920 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3922 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3923 char identifier[32], name[32];
3924 int x = video.fullscreen_modes[i].width;
3925 int y = video.fullscreen_modes[i].height;
3928 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3930 ti->node_top = &screen_modes;
3931 ti->sort_priority = x * 10000 + y;
3933 sprintf(identifier, "%dx%d", x, y);
3934 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3936 setString(&ti->identifier, identifier);
3937 setString(&ti->name, name);
3938 setString(&ti->name_sorting, name);
3939 setString(&ti->infotext, "Fullscreen Mode");
3941 pushTreeInfo(&screen_modes, ti);
3944 /* sort fullscreen modes to start with lowest available screen resolution */
3945 sortTreeInfo(&screen_modes);
3947 /* set current screen mode for fullscreen mode to configured setup value */
3948 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3949 setup.fullscreen_mode);
3951 /* if that fails, set current screen mode to reliable default value */
3952 if (screen_mode_current == NULL)
3953 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3954 DEFAULT_FULLSCREEN_MODE);
3956 /* if that also fails, set current screen mode to first available mode */
3957 if (screen_mode_current == NULL)
3958 screen_mode_current = screen_modes;
3960 if (screen_mode_current == NULL)
3961 video.fullscreen_available = FALSE;
3964 if (video.fullscreen_available)
3966 setup.fullscreen_mode = screen_mode_current->identifier;
3968 /* needed for displaying screen mode name instead of identifier */
3969 screen_mode_text = screen_mode_current->name;
3973 if (scroll_delays == NULL)
3977 for (i = 0; scroll_delays_list[i].value != -1; i++)
3979 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3980 char identifier[32], name[32];
3981 int value = scroll_delays_list[i].value;
3982 char *text = scroll_delays_list[i].text;
3984 ti->node_top = &scroll_delays;
3985 ti->sort_priority = value;
3987 sprintf(identifier, "%d", value);
3988 sprintf(name, "%s", text);
3990 setString(&ti->identifier, identifier);
3991 setString(&ti->name, name);
3992 setString(&ti->name_sorting, name);
3993 setString(&ti->infotext, "Scroll Delay");
3995 pushTreeInfo(&scroll_delays, ti);
3998 /* sort scroll delay values to start with lowest scroll delay value */
3999 sortTreeInfo(&scroll_delays);
4001 /* set current scroll delay value to configured scroll delay value */
4002 scroll_delay_current =
4003 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4005 /* if that fails, set current scroll delay to reliable default value */
4006 if (scroll_delay_current == NULL)
4007 scroll_delay_current =
4008 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4010 /* if that also fails, set current scroll delay to first available value */
4011 if (scroll_delay_current == NULL)
4012 scroll_delay_current = scroll_delays;
4015 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4017 /* needed for displaying scroll delay text instead of identifier */
4018 scroll_delay_text = scroll_delay_current->name;
4021 setup_mode = SETUP_MODE_GRAPHICS;
4025 static void execSetupChooseScreenMode()
4027 if (!video.fullscreen_available)
4030 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4035 static void execSetupChooseScrollDelay()
4037 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4042 static void execSetupSound()
4044 setup_mode = SETUP_MODE_SOUND;
4049 static void execSetupArtwork()
4052 printf("::: '%s', '%s', '%s'\n",
4053 artwork.gfx_current->subdir,
4054 artwork.gfx_current->fullpath,
4055 artwork.gfx_current->basepath);
4058 setup.graphics_set = artwork.gfx_current->identifier;
4059 setup.sounds_set = artwork.snd_current->identifier;
4060 setup.music_set = artwork.mus_current->identifier;
4062 /* needed if last screen (setup choice) changed graphics, sounds or music */
4063 ReloadCustomArtwork(0);
4065 /* needed for displaying artwork name instead of artwork identifier */
4066 graphics_set_name = artwork.gfx_current->name;
4067 sounds_set_name = artwork.snd_current->name;
4068 music_set_name = artwork.mus_current->name;
4070 setup_mode = SETUP_MODE_ARTWORK;
4075 static void execSetupChooseGraphics()
4077 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4082 static void execSetupChooseSounds()
4084 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4089 static void execSetupChooseMusic()
4091 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4096 static void execSetupInput()
4098 setup_mode = SETUP_MODE_INPUT;
4103 static void execSetupShortcuts()
4105 setup_mode = SETUP_MODE_SHORTCUTS;
4110 static void execSetupShortcuts1()
4112 setup_mode = SETUP_MODE_SHORTCUTS_1;
4117 static void execSetupShortcuts2()
4119 setup_mode = SETUP_MODE_SHORTCUTS_2;
4124 static void execSetupShortcuts3()
4126 setup_mode = SETUP_MODE_SHORTCUTS_3;
4131 static void execSetupShortcuts4()
4133 setup_mode = SETUP_MODE_SHORTCUTS_4;
4138 static void execExitSetup()
4140 game_status = GAME_MODE_MAIN;
4142 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4145 static void execSaveAndExitSetup()
4151 static struct TokenInfo setup_info_main[] =
4153 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4154 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4155 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4156 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4157 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4158 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4159 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4160 { TYPE_EMPTY, NULL, "" },
4161 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4162 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4167 static struct TokenInfo setup_info_game[] =
4169 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4170 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4171 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4172 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4173 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4174 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4175 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4176 { TYPE_STRING, &game_speed_text, "" },
4177 { TYPE_EMPTY, NULL, "" },
4178 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4183 static struct TokenInfo setup_info_editor[] =
4186 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4187 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4188 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4189 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4190 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4191 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4192 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4193 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4195 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4196 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4197 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4199 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4201 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4202 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4203 { TYPE_EMPTY, NULL, "" },
4205 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4206 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4207 { TYPE_EMPTY, NULL, "" },
4209 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4210 { TYPE_EMPTY, NULL, "" },
4211 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4216 static struct TokenInfo setup_info_graphics[] =
4218 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4219 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4220 { TYPE_STRING, &screen_mode_text, "" },
4222 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4224 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4225 { TYPE_STRING, &scroll_delay_text, "" },
4227 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4229 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4230 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4231 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4232 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4233 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4234 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4235 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4236 { TYPE_EMPTY, NULL, "" },
4237 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4242 static struct TokenInfo setup_info_sound[] =
4244 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4245 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4246 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4247 { TYPE_EMPTY, NULL, "" },
4248 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4253 static struct TokenInfo setup_info_artwork[] =
4255 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4256 { TYPE_STRING, &graphics_set_name, "" },
4257 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4258 { TYPE_STRING, &sounds_set_name, "" },
4259 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4260 { TYPE_STRING, &music_set_name, "" },
4261 { TYPE_EMPTY, NULL, "" },
4264 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4265 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4266 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4268 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4269 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4270 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4271 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4274 { TYPE_STRING, NULL, "Override Level Artwork:"},
4275 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4276 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4277 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4279 { TYPE_EMPTY, NULL, "" },
4280 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4285 static struct TokenInfo setup_info_input[] =
4287 { TYPE_SWITCH, NULL, "Player:" },
4288 { TYPE_SWITCH, NULL, "Device:" },
4289 { TYPE_ENTER_MENU, NULL, "" },
4290 { TYPE_EMPTY, NULL, "" },
4291 { TYPE_EMPTY, NULL, "" },
4292 { TYPE_EMPTY, NULL, "" },
4293 { TYPE_EMPTY, NULL, "" },
4294 { TYPE_EMPTY, NULL, "" },
4295 { TYPE_EMPTY, NULL, "" },
4296 { TYPE_EMPTY, NULL, "" },
4297 { TYPE_EMPTY, NULL, "" },
4298 { TYPE_EMPTY, NULL, "" },
4299 { TYPE_EMPTY, NULL, "" },
4300 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4305 static struct TokenInfo setup_info_shortcuts[] =
4307 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4308 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4309 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4310 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4311 { TYPE_EMPTY, NULL, "" },
4312 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4317 static struct TokenInfo setup_info_shortcuts_1[] =
4319 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4320 { TYPE_KEY, &setup.shortcut.save_game, "" },
4321 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4322 { TYPE_KEY, &setup.shortcut.load_game, "" },
4323 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4324 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4325 { TYPE_EMPTY, NULL, "" },
4326 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4327 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4328 { TYPE_EMPTY, NULL, "" },
4329 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4334 static struct TokenInfo setup_info_shortcuts_2[] =
4336 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4337 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4338 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4339 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4340 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4341 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4342 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4343 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4344 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4345 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4346 { TYPE_EMPTY, NULL, "" },
4347 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4352 static struct TokenInfo setup_info_shortcuts_3[] =
4354 { TYPE_KEYTEXT, NULL, "Tape Eject:", },
4355 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4356 { TYPE_KEYTEXT, NULL, "Tape Stop:", },
4357 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4358 { TYPE_KEYTEXT, NULL, "Tape Pause:", },
4359 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4360 { TYPE_KEYTEXT, NULL, "Tape Record:", },
4361 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4362 { TYPE_KEYTEXT, NULL, "Tape Play:", },
4363 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4364 { TYPE_EMPTY, NULL, "" },
4365 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4370 static struct TokenInfo setup_info_shortcuts_4[] =
4372 { TYPE_KEYTEXT, NULL, "Sound Effects (Normal):", },
4373 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4374 { TYPE_KEYTEXT, NULL, "Sound Effects (Looping):", },
4375 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4376 { TYPE_KEYTEXT, NULL, "Music:", },
4377 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4378 { TYPE_EMPTY, NULL, "" },
4379 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4384 static Key getSetupKey()
4386 Key key = KSYM_UNDEFINED;
4387 boolean got_key_event = FALSE;
4389 while (!got_key_event)
4391 if (PendingEvent()) /* got event */
4399 case EVENT_KEYPRESS:
4401 key = GetEventKey((KeyEvent *)&event, TRUE);
4403 /* press 'Escape' or 'Enter' to keep the existing key binding */
4404 if (key == KSYM_Escape || key == KSYM_Return)
4405 key = KSYM_UNDEFINED; /* keep old value */
4407 got_key_event = TRUE;
4411 case EVENT_KEYRELEASE:
4412 key_joystick_mapping = 0;
4416 HandleOtherEvents(&event);
4424 /* don't eat all CPU time */
4431 static int getSetupTextFont(int type)
4433 if (type & (TYPE_SWITCH |
4445 static int getSetupValueFont(int type, void *value)
4447 if (type & TYPE_KEY)
4448 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4449 else if (type & TYPE_STRING)
4450 return FONT_VALUE_2;
4451 else if (type & TYPE_ECS_AGA)
4452 return FONT_VALUE_1;
4453 else if (type & TYPE_BOOLEAN_STYLE)
4454 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4455 else if (type & TYPE_YES_NO_AUTO)
4456 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4457 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4459 return FONT_VALUE_1;
4462 static void drawSetupValue(int pos)
4464 boolean font_draw_xoffset_modified = FALSE;
4465 int font_draw_xoffset_old = -1;
4466 int xpos = MENU_SCREEN_VALUE_XPOS;
4467 int ypos = MENU_SCREEN_START_YPOS + pos;
4468 int startx = mSX + xpos * 32;
4469 int starty = mSY + ypos * 32;
4470 int font_nr, font_width, font_height;
4471 int type = setup_info[pos].type;
4472 void *value = setup_info[pos].value;
4473 char *value_string = getSetupValue(type, value);
4478 if (value_string == NULL)
4481 if (type & TYPE_KEY)
4483 xpos = MENU_SCREEN_START_XPOS;
4485 if (type & TYPE_QUERY)
4486 value_string = "<press key>";
4488 else if (type & TYPE_STRING)
4490 int max_value_len = (SCR_FIELDX - 2) * 2;
4492 xpos = MENU_SCREEN_START_XPOS;
4494 if (strlen(value_string) > max_value_len)
4495 value_string[max_value_len] = '\0';
4497 else if (type & TYPE_YES_NO_AUTO)
4499 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4502 startx = mSX + xpos * 32;
4503 starty = mSY + ypos * 32;
4504 font_nr = getSetupValueFont(type, value);
4505 font_width = getFontWidth(font_nr);
4506 font_height = getFontHeight(font_nr);
4508 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4509 if (setup_mode != SETUP_MODE_INPUT)
4511 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4512 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4513 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4514 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4515 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4516 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4517 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4518 boolean correct_font_draw_xoffset = FALSE;
4520 if (xpos == MENU_SCREEN_START_XPOS &&
4521 startx + font1_xoffset < text_startx + text_font_xoffset)
4522 correct_font_draw_xoffset = TRUE;
4524 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4525 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4526 correct_font_draw_xoffset = TRUE;
4528 /* check if setup value would overlap with setup text when printed */
4529 /* (this can happen for extreme/wrong values for font draw offset) */
4530 if (correct_font_draw_xoffset)
4532 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4533 font_draw_xoffset_modified = TRUE;
4535 if (type & TYPE_KEY)
4536 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4537 else if (!(type & TYPE_STRING))
4538 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4539 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4544 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4546 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4547 DrawText(startx + i * font_width, starty, " ", font_nr);
4550 DrawText(startx, starty, value_string, font_nr);
4552 if (font_draw_xoffset_modified)
4553 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4556 static void changeSetupValue(int pos, int dx)
4558 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4560 *(boolean *)setup_info[pos].value ^= TRUE;
4562 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4564 *(int *)setup_info[pos].value =
4566 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4567 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4568 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4569 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4571 else if (setup_info[pos].type & TYPE_KEY)
4575 setup_info[pos].type |= TYPE_QUERY;
4576 drawSetupValue(pos);
4577 setup_info[pos].type &= ~TYPE_QUERY;
4579 key = getSetupKey();
4580 if (key != KSYM_UNDEFINED)
4581 *(Key *)setup_info[pos].value = key;
4584 drawSetupValue(pos);
4587 static void DrawCursorAndText_Setup(int pos, boolean active)
4589 int xpos = MENU_SCREEN_START_XPOS;
4590 int ypos = MENU_SCREEN_START_YPOS + pos;
4591 int font_nr = getSetupTextFont(setup_info[pos].type);
4593 if (setup_info == setup_info_input)
4594 font_nr = FONT_MENU_1;
4597 font_nr = FONT_ACTIVE(font_nr);
4599 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4601 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4602 drawCursor(pos, active);
4605 static void DrawSetupScreen_Generic()
4607 boolean redraw_all = FALSE;
4608 char *title_string = NULL;
4612 CloseDoor(DOOR_CLOSE_2);
4614 if (redraw_mask & REDRAW_ALL)
4618 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4619 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4620 int2str(0, redraw_mask)));
4624 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4625 FadeOut(redraw_mask);
4627 FadeOut(REDRAW_FIELD);
4632 if (setup_mode == SETUP_MODE_MAIN)
4634 setup_info = setup_info_main;
4635 title_string = "Setup";
4637 else if (setup_mode == SETUP_MODE_GAME)
4639 setup_info = setup_info_game;
4640 title_string = "Setup Game";
4642 else if (setup_mode == SETUP_MODE_EDITOR)
4644 setup_info = setup_info_editor;
4645 title_string = "Setup Editor";
4647 else if (setup_mode == SETUP_MODE_GRAPHICS)
4649 setup_info = setup_info_graphics;
4650 title_string = "Setup Graphics";
4652 else if (setup_mode == SETUP_MODE_SOUND)
4654 setup_info = setup_info_sound;
4655 title_string = "Setup Sound";
4657 else if (setup_mode == SETUP_MODE_ARTWORK)
4659 setup_info = setup_info_artwork;
4660 title_string = "Custom Artwork";
4662 else if (setup_mode == SETUP_MODE_SHORTCUTS)
4664 setup_info = setup_info_shortcuts;
4665 title_string = "Setup Shortcuts";
4667 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4669 setup_info = setup_info_shortcuts_1;
4670 title_string = "Setup Shortcuts";
4672 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4674 setup_info = setup_info_shortcuts_2;
4675 title_string = "Setup Shortcuts";
4677 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
4679 setup_info = setup_info_shortcuts_3;
4680 title_string = "Setup Shortcuts";
4682 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
4684 setup_info = setup_info_shortcuts_4;
4685 title_string = "Setup Shortcuts";
4688 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4692 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4694 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4697 void *value_ptr = setup_info[i].value;
4699 /* set some entries to "unchangeable" according to other variables */
4700 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4701 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4702 (value_ptr == &setup.sound_music && !audio.music_available) ||
4703 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4704 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4705 setup_info[i].type |= TYPE_GHOSTED;
4707 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4708 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4709 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4710 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4711 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4712 initCursor(i, IMG_MENU_BUTTON);
4714 DrawCursorAndText_Setup(i, FALSE);
4716 if (setup_info[i].type & TYPE_VALUE)
4723 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4724 "Joysticks deactivated in setup menu");
4728 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4732 redraw_mask = REDRAW_ALL;
4735 FadeIn(redraw_mask);
4737 FadeIn(REDRAW_FIELD);
4742 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4746 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4748 static int choice_store[MAX_SETUP_MODES];
4749 int choice = choice_store[setup_mode]; /* always starts with 0 */
4753 if (button == MB_MENU_INITIALIZE)
4755 /* advance to first valid menu entry */
4756 while (choice < num_setup_info &&
4757 setup_info[choice].type & TYPE_SKIP_ENTRY)
4759 choice_store[setup_mode] = choice;
4761 DrawCursorAndText_Setup(choice, TRUE);
4765 else if (button == MB_MENU_LEAVE)
4767 PlaySound(SND_MENU_ITEM_SELECTING);
4769 for (y = 0; y < num_setup_info; y++)
4771 if (setup_info[y].type & TYPE_LEAVE_MENU)
4773 void (*menu_callback_function)(void) = setup_info[y].value;
4777 menu_callback_function();
4779 break; /* absolutely needed because function changes 'setup_info'! */
4786 if (mx || my) /* mouse input */
4788 x = (mx - mSX) / 32;
4789 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4791 else if (dx || dy) /* keyboard input */
4795 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4797 if (setup_info[choice].type & menu_navigation_type ||
4798 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4799 setup_info[choice].type & TYPE_YES_NO_AUTO)
4800 button = MB_MENU_CHOICE;
4805 /* jump to next non-empty menu entry (up or down) */
4806 while (y > 0 && y < num_setup_info - 1 &&
4807 setup_info[y].type & TYPE_SKIP_ENTRY)
4811 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4815 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4817 PlaySound(SND_MENU_ITEM_ACTIVATING);
4819 DrawCursorAndText_Setup(choice, FALSE);
4820 DrawCursorAndText_Setup(y, TRUE);
4822 choice = choice_store[setup_mode] = y;
4825 else if (!(setup_info[y].type & TYPE_GHOSTED))
4827 PlaySound(SND_MENU_ITEM_SELECTING);
4829 /* when selecting key headline, execute function for key value change */
4830 if (setup_info[y].type & TYPE_KEYTEXT &&
4831 setup_info[y + 1].type & TYPE_KEY)
4834 /* when selecting string value, execute function for list selection */
4835 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4836 setup_info[y - 1].type & TYPE_ENTER_LIST)
4839 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4841 void (*menu_callback_function)(void) = setup_info[y].value;
4843 FadeSetFromType(setup_info[y].type);
4845 menu_callback_function();
4849 if (setup_info[y].type & TYPE_VALUE)
4850 changeSetupValue(y, dx);
4856 void DrawSetupScreen_Input()
4861 FadeOut(REDRAW_FIELD);
4867 setup_info = setup_info_input;
4870 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4874 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4875 "Joysticks deactivated on this screen");
4877 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4878 "Joysticks deactivated on this screen");
4883 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4885 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4888 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4889 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4890 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4891 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4892 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4893 initCursor(i, IMG_MENU_BUTTON);
4895 DrawCursorAndText_Setup(i, FALSE);
4899 DeactivateJoystickForCalibration();
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");
4912 /* create gadgets for setup input menu screen */
4913 FreeScreenGadgets();
4914 CreateScreenGadgets();
4916 /* map gadgets for setup input menu screen */
4917 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4919 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4922 FadeIn(REDRAW_FIELD);
4928 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4930 if (device_name == NULL)
4933 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4936 if (strlen(device_name) > 1)
4938 char c1 = device_name[strlen(device_name) - 1];
4939 char c2 = device_name[strlen(device_name) - 2];
4941 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4942 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4945 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4946 strlen(device_name));
4949 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4952 static struct SetupKeyboardInfo custom_key;
4959 { &custom_key.left, "Joystick Left" },
4960 { &custom_key.right, "Joystick Right" },
4961 { &custom_key.up, "Joystick Up" },
4962 { &custom_key.down, "Joystick Down" },
4963 { &custom_key.snap, "Button 1" },
4964 { &custom_key.drop, "Button 2" }
4966 static char *joystick_name[MAX_PLAYERS] =
4973 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4977 custom_key = setup.input[player_nr].key;
4979 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4980 FONT_INPUT_1_ACTIVE);
4982 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4984 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4985 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4987 if (setup.input[player_nr].use_joystick)
4989 char *device_name = setup.input[player_nr].joy.device_name;
4990 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4991 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4993 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4994 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4998 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4999 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5002 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5004 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5005 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5006 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5007 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5009 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5010 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5011 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5012 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5013 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5014 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5016 for (i = 0; i < 6; i++)
5018 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5020 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5022 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5023 (setup.input[player_nr].use_joystick ?
5025 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5029 static int input_player_nr = 0;
5031 void HandleSetupScreen_Input_Player(int step, int direction)
5033 int old_player_nr = input_player_nr;
5036 new_player_nr = old_player_nr + step * direction;
5037 if (new_player_nr < 0)
5039 if (new_player_nr > MAX_PLAYERS - 1)
5040 new_player_nr = MAX_PLAYERS - 1;
5042 if (new_player_nr != old_player_nr)
5044 input_player_nr = new_player_nr;
5046 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5050 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5052 static int choice = 0;
5055 int pos_start = SETUPINPUT_SCREEN_POS_START;
5056 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5057 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5058 int pos_end = SETUPINPUT_SCREEN_POS_END;
5060 if (button == MB_MENU_INITIALIZE)
5062 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5064 DrawCursorAndText_Setup(choice, TRUE);
5068 else if (button == MB_MENU_LEAVE)
5070 setup_mode = SETUP_MODE_MAIN;
5077 if (mx || my) /* mouse input */
5079 x = (mx - mSX) / 32;
5080 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5082 else if (dx || dy) /* keyboard input */
5084 if (dx && choice == 0)
5085 x = (dx < 0 ? 10 : 12);
5086 else if ((dx && choice == 1) ||
5087 (dx == +1 && choice == 2) ||
5088 (dx == -1 && choice == pos_end))
5089 button = MB_MENU_CHOICE;
5093 if (y >= pos_empty1 && y <= pos_empty2)
5094 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5097 if (y == 0 && dx != 0 && button)
5099 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5101 else if (IN_VIS_FIELD(x, y) &&
5102 y >= pos_start && y <= pos_end &&
5103 !(y >= pos_empty1 && y <= pos_empty2))
5109 DrawCursorAndText_Setup(choice, FALSE);
5110 DrawCursorAndText_Setup(y, TRUE);
5112 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5121 char *device_name = setup.input[input_player_nr].joy.device_name;
5123 if (!setup.input[input_player_nr].use_joystick)
5125 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5127 setJoystickDeviceToNr(device_name, new_device_nr);
5128 setup.input[input_player_nr].use_joystick = TRUE;
5132 int device_nr = getJoystickNrFromDeviceName(device_name);
5133 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5135 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5136 setup.input[input_player_nr].use_joystick = FALSE;
5138 setJoystickDeviceToNr(device_name, new_device_nr);
5141 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5145 if (setup.input[input_player_nr].use_joystick)
5148 CalibrateJoystick(input_player_nr);
5151 CustomizeKeyboard(input_player_nr);
5153 else if (y == pos_end)
5159 setup_mode = SETUP_MODE_MAIN;
5166 void CustomizeKeyboard(int player_nr)
5170 boolean finished = FALSE;
5171 static struct SetupKeyboardInfo custom_key;
5176 } customize_step[] =
5178 { &custom_key.left, "Move Left" },
5179 { &custom_key.right, "Move Right" },
5180 { &custom_key.up, "Move Up" },
5181 { &custom_key.down, "Move Down" },
5182 { &custom_key.snap, "Snap Field" },
5183 { &custom_key.drop, "Drop Element" }
5186 /* read existing key bindings from player setup */
5187 custom_key = setup.input[player_nr].key;
5190 FadeOut(REDRAW_FIELD);
5194 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5202 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5203 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5204 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5205 "Key:", FONT_INPUT_1_ACTIVE);
5206 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5207 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5210 FadeIn(REDRAW_FIELD);
5217 if (PendingEvent()) /* got event */
5225 case EVENT_KEYPRESS:
5227 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5229 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5231 if (key == KSYM_Escape)
5232 FadeSkipNextFadeIn();
5238 /* all keys configured -- wait for "Escape" or "Return" key */
5242 /* press 'Enter' to keep the existing key binding */
5243 if (key == KSYM_Return)
5244 key = *customize_step[step_nr].key;
5246 /* check if key already used */
5247 for (i = 0; i < step_nr; i++)
5248 if (*customize_step[i].key == key)
5253 /* got new key binding */
5254 *customize_step[step_nr].key = key;
5255 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5257 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5258 getKeyNameFromKey(key), FONT_VALUE_1);
5261 /* un-highlight last query */
5262 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5263 customize_step[step_nr - 1].text, FONT_MENU_1);
5264 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5265 "Key:", FONT_MENU_1);
5267 /* press 'Enter' to leave */
5270 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5271 "Press Enter", FONT_TITLE_1);
5275 /* query next key binding */
5276 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5277 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5278 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5279 "Key:", FONT_INPUT_1_ACTIVE);
5280 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5281 getKeyNameFromKey(*customize_step[step_nr].key),
5286 case EVENT_KEYRELEASE:
5287 key_joystick_mapping = 0;
5291 HandleOtherEvents(&event);
5299 /* don't eat all CPU time */
5303 /* write new key bindings back to player setup */
5304 setup.input[player_nr].key = custom_key;
5307 DrawSetupScreen_Input();
5310 static boolean CalibrateJoystickMain(int player_nr)
5312 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5313 int new_joystick_xright = JOYSTICK_XMIDDLE;
5314 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5315 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5316 int new_joystick_xmiddle, new_joystick_ymiddle;
5318 int joystick_fd = joystick.fd[player_nr];
5319 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5320 boolean check[3][3];
5321 int check_remaining = 3 * 3;
5326 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5329 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5333 FadeOut(REDRAW_FIELD);
5337 for (y = 0; y < 3; y++)
5339 for (x = 0; x < 3; x++)
5341 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5342 check[x][y] = FALSE;
5346 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5347 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5348 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5349 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5350 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5351 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5352 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5354 joy_value = Joystick(player_nr);
5355 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5356 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5358 /* eventually uncalibrated center position (joystick could be uncentered) */
5359 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5362 new_joystick_xmiddle = joy_x;
5363 new_joystick_ymiddle = joy_y;
5365 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5367 FadeIn(REDRAW_FIELD);
5369 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5374 if (PendingEvent()) /* got event */
5382 case EVENT_KEYPRESS:
5383 switch (GetEventKey((KeyEvent *)&event, TRUE))
5386 if (check_remaining == 0)
5391 FadeSkipNextFadeIn();
5400 case EVENT_KEYRELEASE:
5401 key_joystick_mapping = 0;
5405 HandleOtherEvents(&event);
5410 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5413 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5414 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5415 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5416 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5418 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5419 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5420 setup.input[player_nr].joy.xright = new_joystick_xright;
5421 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5422 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5423 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5425 CheckJoystickData();
5427 joy_value = Joystick(player_nr);
5429 if (joy_value & JOY_BUTTON && check_remaining == 0)
5432 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5433 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5435 if (x != last_x || y != last_y)
5437 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5438 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5443 if (check_remaining > 0 && !check[x+1][y+1])
5445 check[x+1][y+1] = TRUE;
5451 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5452 setup.input[player_nr].joy.xleft,
5453 setup.input[player_nr].joy.xmiddle,
5454 setup.input[player_nr].joy.xright);
5455 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5456 setup.input[player_nr].joy.yupper,
5457 setup.input[player_nr].joy.ymiddle,
5458 setup.input[player_nr].joy.ylower);
5467 /* don't eat all CPU time */
5471 /* calibrated center position (joystick should now be centered) */
5472 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5475 new_joystick_xmiddle = joy_x;
5476 new_joystick_ymiddle = joy_y;
5481 DrawSetupScreen_Input();
5484 /* wait until the last pressed button was released */
5485 while (Joystick(player_nr) & JOY_BUTTON)
5487 if (PendingEvent()) /* got event */
5492 HandleOtherEvents(&event);
5501 void CalibrateJoystick(int player_nr)
5503 if (!CalibrateJoystickMain(player_nr))
5505 char *device_name = setup.input[player_nr].joy.device_name;
5506 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5507 int xpos = mSX - SX;
5508 int ypos = mSY - SY;
5512 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5513 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5516 Delay(2000); /* show error message for a short time */
5522 DrawSetupScreen_Input();
5526 void DrawSetupScreen()
5528 DeactivateJoystick();
5530 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5532 if (setup_mode == SETUP_MODE_INPUT)
5533 DrawSetupScreen_Input();
5534 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5535 DrawChooseTree(&game_speed_current);
5536 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5537 DrawChooseTree(&screen_mode_current);
5538 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5539 DrawChooseTree(&scroll_delay_current);
5540 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5541 DrawChooseTree(&artwork.gfx_current);
5542 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5543 DrawChooseTree(&artwork.snd_current);
5544 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5545 DrawChooseTree(&artwork.mus_current);
5547 DrawSetupScreen_Generic();
5553 void RedrawSetupScreenAfterFullscreenToggle()
5555 if (setup_mode == SETUP_MODE_GRAPHICS)
5559 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5561 if (setup_mode == SETUP_MODE_INPUT)
5562 HandleSetupScreen_Input(mx, my, dx, dy, button);
5563 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5564 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5565 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5566 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5567 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5568 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5569 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5570 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5571 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5572 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5573 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5574 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5576 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5581 void HandleGameActions()
5583 if (game_status != GAME_MODE_PLAYING)
5586 GameActions(); /* main game loop */
5588 if (tape.auto_play && !tape.playing)
5589 AutoPlayTape(); /* continue automatically playing next tape */
5593 /* ---------- new screen button stuff -------------------------------------- */
5595 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5600 case SCREEN_CTRL_ID_PREV_LEVEL:
5601 *x = mSX + menu.main.button.prev_level.x;
5602 *y = mSY + menu.main.button.prev_level.y;
5605 case SCREEN_CTRL_ID_NEXT_LEVEL:
5606 *x = mSX + menu.main.button.next_level.x;
5607 *y = mSY + menu.main.button.next_level.y;
5610 case SCREEN_CTRL_ID_PREV_LEVEL:
5611 *x = mSX + TILEX * getPrevlevelButtonPos();
5612 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5615 case SCREEN_CTRL_ID_NEXT_LEVEL:
5616 *x = mSX + TILEX * getNextLevelButtonPos();
5617 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5621 case SCREEN_CTRL_ID_PREV_PLAYER:
5622 *x = mSX + TILEX * 10;
5623 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5626 case SCREEN_CTRL_ID_NEXT_PLAYER:
5627 *x = mSX + TILEX * 12;
5628 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5632 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5638 int gfx_unpressed, gfx_pressed;
5639 void (*get_gadget_position)(int *, int *, int);
5643 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5646 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5647 getScreenMenuButtonPos,
5648 SCREEN_CTRL_ID_PREV_LEVEL,
5653 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5654 getScreenMenuButtonPos,
5655 SCREEN_CTRL_ID_NEXT_LEVEL,
5660 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5661 getScreenMenuButtonPos,
5662 SCREEN_CTRL_ID_PREV_PLAYER,
5667 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5668 getScreenMenuButtonPos,
5669 SCREEN_CTRL_ID_NEXT_PLAYER,
5677 int gfx_unpressed, gfx_pressed;
5681 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5684 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5686 -1, -1, /* these values are not constant, but can change at runtime */
5688 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5690 SCREEN_CTRL_ID_SCROLL_UP,
5694 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5696 -1, -1, /* these values are not constant, but can change at runtime */
5698 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5700 SCREEN_CTRL_ID_SCROLL_DOWN,
5707 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5708 Bitmap **gfx_unpressed, **gfx_pressed;
5710 int gfx_unpressed, gfx_pressed;
5717 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5720 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5721 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5723 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5726 -1, -1, /* these values are not constant, but can change at runtime */
5727 -1, -1, /* these values are not constant, but can change at runtime */
5729 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5730 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5732 GD_TYPE_SCROLLBAR_VERTICAL,
5733 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5734 "scroll level series vertically"
5738 static void CreateScreenMenubuttons()
5740 struct GadgetInfo *gi;
5741 unsigned long event_mask;
5744 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5746 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5747 int gfx_unpressed, gfx_pressed;
5748 int x, y, width, height;
5749 int gd_x1, gd_x2, gd_y1, gd_y2;
5750 int id = menubutton_info[i].gadget_id;
5752 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5754 menubutton_info[i].get_gadget_position(&x, &y, id);
5756 width = SC_MENUBUTTON_XSIZE;
5757 height = SC_MENUBUTTON_YSIZE;
5759 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5760 gfx_pressed = menubutton_info[i].gfx_pressed;
5761 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5762 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5763 gd_x1 = graphic_info[gfx_unpressed].src_x;
5764 gd_y1 = graphic_info[gfx_unpressed].src_y;
5765 gd_x2 = graphic_info[gfx_pressed].src_x;
5766 gd_y2 = graphic_info[gfx_pressed].src_y;
5768 gi = CreateGadget(GDI_CUSTOM_ID, id,
5769 GDI_CUSTOM_TYPE_ID, i,
5770 GDI_INFO_TEXT, menubutton_info[i].infotext,
5775 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5776 GDI_STATE, GD_BUTTON_UNPRESSED,
5777 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5778 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5779 GDI_DIRECT_DRAW, FALSE,
5780 GDI_EVENT_MASK, event_mask,
5781 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5785 Error(ERR_EXIT, "cannot create gadget");
5787 screen_gadget[id] = gi;
5791 static void CreateScreenScrollbuttons()
5793 struct GadgetInfo *gi;
5794 unsigned long event_mask;
5797 /* these values are not constant, but can change at runtime */
5798 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
5799 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
5800 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
5801 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
5803 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5805 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5806 int gfx_unpressed, gfx_pressed;
5807 int x, y, width, height;
5808 int gd_x1, gd_x2, gd_y1, gd_y2;
5809 int id = scrollbutton_info[i].gadget_id;
5811 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5813 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5814 y = mSY + scrollbutton_info[i].y;
5815 width = SC_SCROLLBUTTON_XSIZE;
5816 height = SC_SCROLLBUTTON_YSIZE;
5818 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5819 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5820 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5822 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5823 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5824 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5825 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5826 gd_x1 = graphic_info[gfx_unpressed].src_x;
5827 gd_y1 = graphic_info[gfx_unpressed].src_y;
5828 gd_x2 = graphic_info[gfx_pressed].src_x;
5829 gd_y2 = graphic_info[gfx_pressed].src_y;
5831 gi = CreateGadget(GDI_CUSTOM_ID, id,
5832 GDI_CUSTOM_TYPE_ID, i,
5833 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5838 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5839 GDI_STATE, GD_BUTTON_UNPRESSED,
5840 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5841 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5842 GDI_DIRECT_DRAW, FALSE,
5843 GDI_EVENT_MASK, event_mask,
5844 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5848 Error(ERR_EXIT, "cannot create gadget");
5850 screen_gadget[id] = gi;
5854 static void CreateScreenScrollbars()
5858 /* these values are not constant, but can change at runtime */
5859 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
5860 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
5861 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
5862 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
5864 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5866 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5867 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5868 int gfx_unpressed, gfx_pressed;
5870 int x, y, width, height;
5871 int gd_x1, gd_x2, gd_y1, gd_y2;
5872 struct GadgetInfo *gi;
5873 int items_max, items_visible, item_position;
5874 unsigned long event_mask;
5875 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5876 int id = scrollbar_info[i].gadget_id;
5878 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5880 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5881 y = mSY + scrollbar_info[i].y;
5882 width = scrollbar_info[i].width;
5883 height = scrollbar_info[i].height;
5885 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5886 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5888 items_max = num_page_entries;
5889 items_visible = num_page_entries;
5892 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5893 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5894 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5900 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5901 gfx_pressed = scrollbar_info[i].gfx_pressed;
5902 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5903 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5904 gd_x1 = graphic_info[gfx_unpressed].src_x;
5905 gd_y1 = graphic_info[gfx_unpressed].src_y;
5906 gd_x2 = graphic_info[gfx_pressed].src_x;
5907 gd_y2 = graphic_info[gfx_pressed].src_y;
5910 gi = CreateGadget(GDI_CUSTOM_ID, id,
5911 GDI_CUSTOM_TYPE_ID, i,
5912 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5917 GDI_TYPE, scrollbar_info[i].type,
5918 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5919 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5920 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5922 GDI_WHEEL_AREA_X, SX,
5923 GDI_WHEEL_AREA_Y, SY,
5924 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5925 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5927 GDI_WHEEL_AREA_X, 0,
5928 GDI_WHEEL_AREA_Y, 0,
5929 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5930 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5932 GDI_STATE, GD_BUTTON_UNPRESSED,
5933 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5934 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5935 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5936 GDI_DIRECT_DRAW, FALSE,
5937 GDI_EVENT_MASK, event_mask,
5938 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5942 Error(ERR_EXIT, "cannot create gadget");
5944 screen_gadget[id] = gi;
5948 void CreateScreenGadgets()
5950 int last_game_status = game_status; /* save current game status */
5952 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5955 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5957 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5959 /* copy pointers to clip mask and GC */
5960 scrollbar_bitmap[i]->clip_mask =
5961 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5962 scrollbar_bitmap[i]->stored_clip_gc =
5963 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5965 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5966 scrollbar_bitmap[i],
5967 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5968 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5969 TILEX, TILEY, 0, 0);
5973 CreateScreenMenubuttons();
5976 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5977 game_status = GAME_MODE_LEVELS;
5980 CreateScreenScrollbuttons();
5981 CreateScreenScrollbars();
5983 game_status = last_game_status; /* restore current game status */
5986 void FreeScreenGadgets()
5990 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5991 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5993 /* prevent freeing clip mask and GC twice */
5994 scrollbar_bitmap[i]->clip_mask = None;
5995 scrollbar_bitmap[i]->stored_clip_gc = None;
5997 FreeBitmap(scrollbar_bitmap[i]);
6001 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6002 FreeGadget(screen_gadget[i]);
6005 void MapScreenMenuGadgets(int screen_mask)
6009 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6010 if (screen_mask & menubutton_info[i].screen_mask)
6011 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6014 void MapScreenTreeGadgets(TreeInfo *ti)
6016 int num_entries = numTreeInfoInGroup(ti);
6019 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6022 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6023 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6025 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6026 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6029 static void HandleScreenGadgets(struct GadgetInfo *gi)
6031 int id = gi->custom_id;
6032 int button = gi->event.button;
6033 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6037 case SCREEN_CTRL_ID_PREV_LEVEL:
6038 HandleMainMenu_SelectLevel(step, -1);
6041 case SCREEN_CTRL_ID_NEXT_LEVEL:
6042 HandleMainMenu_SelectLevel(step, +1);
6045 case SCREEN_CTRL_ID_PREV_PLAYER:
6046 HandleSetupScreen_Input_Player(step, -1);
6049 case SCREEN_CTRL_ID_NEXT_PLAYER:
6050 HandleSetupScreen_Input_Player(step, +1);
6053 case SCREEN_CTRL_ID_SCROLL_UP:
6054 if (game_status == GAME_MODE_LEVELS)
6055 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6056 else if (game_status == GAME_MODE_SETUP)
6057 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6060 case SCREEN_CTRL_ID_SCROLL_DOWN:
6061 if (game_status == GAME_MODE_LEVELS)
6062 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6063 else if (game_status == GAME_MODE_SETUP)
6064 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6067 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6068 if (game_status == GAME_MODE_LEVELS)
6069 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6070 else if (game_status == GAME_MODE_SETUP)
6071 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);