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)
1028 static int cursor_array[SCR_FIELDY];
1029 int x = mSX + TILEX * xpos;
1030 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1035 cursor_array[ypos] = graphic;
1037 graphic = cursor_array[ypos];
1041 graphic = BUTTON_ACTIVE(graphic);
1043 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1044 DrawGraphicThruMaskExt(drawto, x, y, graphic, 0);
1047 static void initCursor(int ypos, int graphic)
1049 drawCursorExt(0, ypos, FALSE, graphic);
1052 static void drawCursor(int ypos, boolean active)
1054 drawCursorExt(0, ypos, active, -1);
1057 static void drawCursorXY(int xpos, int ypos, int graphic)
1059 drawCursorExt(xpos, ypos, FALSE, graphic);
1062 static void drawChooseTreeCursor(int ypos, boolean active)
1064 int last_game_status = game_status; /* save current game status */
1067 /* force LEVELS draw offset on artwork setup screen */
1068 game_status = GAME_MODE_LEVELS;
1071 drawCursorExt(0, ypos, active, -1);
1073 game_status = last_game_status; /* restore current game status */
1078 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1079 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1083 static int getPrevlevelButtonPos()
1088 static int getCurrentLevelTextPos()
1090 return (getPrevlevelButtonPos() + 1);
1093 static int getNextLevelButtonPos()
1095 return getPrevlevelButtonPos() + 3 + 1;
1098 static int getLevelRangeTextPos()
1100 return getNextLevelButtonPos() + 1;
1104 int effectiveGameStatus()
1106 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1107 return GAME_MODE_TITLE;
1112 void DrawTitleScreenImage(int nr, boolean initial)
1114 int graphic = getTitleScreenGraphic(nr, initial);
1115 Bitmap *bitmap = graphic_info[graphic].bitmap;
1116 int width = graphic_info[graphic].width;
1117 int height = graphic_info[graphic].height;
1118 int src_x = graphic_info[graphic].src_x;
1119 int src_y = graphic_info[graphic].src_y;
1125 if (width > WIN_XSIZE)
1127 /* image width too large for window => center image horizontally */
1128 src_x = (width - WIN_XSIZE) / 2;
1132 if (height > WIN_YSIZE)
1134 /* image height too large for window => center image vertically */
1135 src_y = (height - WIN_YSIZE) / 2;
1139 /* always display title screens centered */
1140 dst_x = (WIN_XSIZE - width) / 2;
1141 dst_y = (WIN_YSIZE - height) / 2;
1143 SetDrawBackgroundMask(REDRAW_ALL);
1144 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1146 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1148 if (DrawingOnBackground(dst_x, dst_y))
1150 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1151 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1154 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1156 redraw_mask = REDRAW_ALL;
1159 void DrawTitleScreenMessage(int nr, boolean initial)
1161 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1162 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1163 int last_game_status = game_status; /* save current game status */
1165 if (filename == NULL)
1168 /* force TITLE font on title message screen */
1169 game_status = getTitleMessageGameMode(initial);
1171 /* if chars set to "-1", automatically determine by text and font width */
1172 if (tmi->chars == -1)
1173 tmi->chars = tmi->width / getFontWidth(tmi->font);
1175 tmi->width = tmi->chars * getFontWidth(tmi->font);
1177 /* if lines set to "-1", automatically determine by text and font height */
1178 if (tmi->lines == -1)
1179 tmi->lines = tmi->height / getFontHeight(tmi->font);
1181 tmi->height = tmi->lines * getFontHeight(tmi->font);
1183 SetDrawBackgroundMask(REDRAW_ALL);
1184 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1186 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1188 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1189 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
1190 tmi->autowrap, tmi->centered, tmi->parse_comments);
1192 game_status = last_game_status; /* restore current game status */
1195 void DrawTitleScreen()
1197 KeyboardAutoRepeatOff();
1200 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1203 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1208 boolean CheckTitleScreen(boolean levelset_has_changed)
1210 static boolean show_title_initial = TRUE;
1211 boolean show_titlescreen = FALSE;
1213 /* needed to be able to skip title screen, if no image or message defined */
1214 InitializeTitleControls(show_title_initial);
1216 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1217 show_titlescreen = TRUE;
1219 /* show initial title images and messages only once at program start */
1220 show_title_initial = FALSE;
1222 return (show_titlescreen && num_title_screens > 0);
1225 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1227 static LevelDirTree *leveldir_last_valid = NULL;
1228 boolean levelset_has_changed = FALSE;
1230 FadeSetLeaveScreen();
1232 /* do not fade out here -- function may continue and fade on editor screen */
1235 FadeSoundsAndMusic();
1237 KeyboardAutoRepeatOn();
1240 SetDrawDeactivationMask(REDRAW_NONE);
1241 SetDrawBackgroundMask(REDRAW_FIELD);
1243 audio.sound_deactivated = FALSE;
1247 /* needed if last screen was the playing screen, invoked from level editor */
1248 if (level_editor_test_game)
1250 game_status = GAME_MODE_EDITOR;
1256 /* needed if last screen was the setup screen and fullscreen state changed */
1257 ToggleFullscreenIfNeeded();
1259 /* leveldir_current may be invalid (level group, parent link) */
1260 if (!validLevelSeries(leveldir_current))
1261 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1263 if (leveldir_current != leveldir_last_valid)
1264 levelset_has_changed = TRUE;
1266 /* store valid level series information */
1267 leveldir_last_valid = leveldir_current;
1269 init_last = init; /* switch to new busy animation */
1271 /* needed if last screen (level choice) changed graphics, sounds or music */
1272 ReloadCustomArtwork(0);
1274 if (redraw_mask & REDRAW_ALL)
1275 fade_mask = REDRAW_ALL;
1280 /* needed if last screen was the editor screen */
1281 UndrawSpecialEditorDoor();
1283 if (fade_mask == REDRAW_FIELD)
1289 /* needed if newly loaded custom artwork requires a different screen mode */
1290 ChangeScreenModeIfNeeded();
1293 #if defined(TARGET_SDL)
1294 SetDrawtoField(DRAW_BACKBUFFER);
1297 if (CheckTitleScreen(levelset_has_changed))
1299 game_status = GAME_MODE_TITLE;
1306 /* level_nr may have been set to value over handicap with level editor */
1307 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1308 level_nr = leveldir_current->handicap_level;
1310 LoadLevel(level_nr);
1311 LoadScore(level_nr);
1313 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1316 if (fade_mask == REDRAW_ALL)
1318 // int door_state = GetDoorState();
1322 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1328 InitializeMainControls();
1330 DrawCursorAndText_Main(-1, FALSE);
1331 DrawPreviewLevel(TRUE);
1333 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1336 if (TAPE_IS_EMPTY(tape))
1338 DrawCompleteVideoDisplay();
1343 /* create gadgets for main menu screen */
1344 FreeScreenGadgets();
1345 CreateScreenGadgets();
1347 /* map gadgets for main menu screen */
1349 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1352 if (fade_mask == REDRAW_ALL)
1354 int door_state = GetDoorState();
1356 // RedrawBackground();
1358 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1362 DrawMaskedBorder(REDRAW_ALL);
1368 /* update screen area with special editor door */
1369 redraw_mask |= REDRAW_ALL;
1373 SetMouseCursor(CURSOR_DEFAULT);
1377 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1380 void DrawAndFadeInMainMenu(int fade_mask)
1382 DrawMainMenuExt(fade_mask, TRUE);
1387 DrawMainMenuExt(REDRAW_ALL, FALSE);
1391 static void gotoTopLevelDir()
1393 /* move upwards to top level directory */
1394 while (leveldir_current->node_parent)
1396 /* write a "path" into level tree for easy navigation to last level */
1397 if (leveldir_current->node_parent->node_group->cl_first == -1)
1399 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1400 int leveldir_pos = posTreeInfo(leveldir_current);
1401 int num_page_entries;
1402 int cl_first, cl_cursor;
1404 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1405 num_page_entries = num_leveldirs;
1407 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1409 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1410 cl_cursor = leveldir_pos - cl_first;
1412 leveldir_current->node_parent->node_group->cl_first = cl_first;
1413 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1416 leveldir_current = leveldir_current->node_parent;
1421 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1423 static unsigned long title_delay = 0;
1424 static int title_screen_nr = 0;
1425 static int last_sound = -1, last_music = -1;
1426 boolean return_to_main_menu = FALSE;
1427 boolean use_fading_main_menu = TRUE;
1428 struct TitleControlInfo *tci;
1429 struct TitleFadingInfo fading_default;
1430 struct TitleFadingInfo fading_last = fading;
1431 struct TitleFadingInfo fading_next;
1434 if (button == MB_MENU_INITIALIZE)
1437 title_screen_nr = 0;
1438 tci = &title_controls[title_screen_nr];
1440 last_sound = SND_UNDEFINED;
1441 last_music = MUS_UNDEFINED;
1443 if (game_status == GAME_MODE_INFO)
1445 if (num_title_screens == 0)
1447 DrawInfoScreen_NotAvailable("Title screen information:",
1448 "No title screen for this level set.");
1453 FadeSoundsAndMusic();
1456 FadeOut(REDRAW_ALL);
1461 DrawTitleScreenImage(tci->local_nr, tci->initial);
1463 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1465 fading_default = (tci->initial ? title_initial_default : title_default);
1467 fading = fading_next = getTitleFading(tci);
1471 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1472 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1474 fading.fade_mode = FADE_MODE_FADE;
1475 fading.fade_delay = fading_default.fade_delay;
1478 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1479 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1480 fading.fade_mode = FADE_MODE_FADE;
1485 sound = getTitleSound(tci);
1486 music = getTitleMusic(tci);
1488 if (sound != last_sound)
1489 PlayMenuSoundExt(sound);
1490 if (music != last_music)
1491 PlayMenuMusicExt(music);
1497 SetMouseCursor(CURSOR_NONE);
1503 fading = fading_next;
1505 DelayReached(&title_delay, 0); /* reset delay counter */
1511 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1512 button = MB_MENU_CHOICE;
1514 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1515 button = MB_MENU_CHOICE;
1518 if (button == MB_MENU_LEAVE)
1520 return_to_main_menu = TRUE;
1521 use_fading_main_menu = FALSE;
1523 else if (button == MB_MENU_CHOICE)
1525 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1528 FadeOut(REDRAW_FIELD);
1531 FadeSetEnterScreen();
1533 info_mode = INFO_MODE_MAIN;
1534 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1540 tci = &title_controls[title_screen_nr];
1542 if (title_screen_nr < num_title_screens)
1544 sound = getTitleSound(tci);
1545 music = getTitleMusic(tci);
1547 if (sound == SND_UNDEFINED || sound != last_sound)
1549 if (music == MUS_UNDEFINED || music != last_music)
1553 FadeOut(REDRAW_ALL);
1557 DrawTitleScreenImage(tci->local_nr, tci->initial);
1559 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1561 fading_next = getTitleFading(tci);
1564 sound = getTitleSound(tci);
1565 music = getTitleMusic(tci);
1567 if (sound != last_sound)
1568 PlayMenuSoundExt(sound);
1569 if (music != last_music)
1570 PlayMenuMusicExt(music);
1577 /* last screen already faded out, next screen has no animation */
1578 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1579 fading_next.fade_mode == FADE_MODE_NONE)
1580 fading = fading_next;
1582 /* last screen already faded out, next screen has no animation */
1583 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1584 fading_next.fade_mode == FADE_MODE_NONE)
1585 fading = fading_next;
1592 fading = fading_next;
1594 DelayReached(&title_delay, 0); /* reset delay counter */
1598 FadeSoundsAndMusic();
1600 return_to_main_menu = TRUE;
1604 if (return_to_main_menu)
1610 SetMouseCursor(CURSOR_DEFAULT);
1612 if (game_status == GAME_MODE_INFO)
1615 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1618 info_mode = INFO_MODE_MAIN;
1619 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1621 else /* default: return to main menu */
1624 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1627 game_status = GAME_MODE_MAIN;
1628 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1633 void HandleMainMenu_SelectLevel(int step, int direction)
1635 int old_level_nr = level_nr;
1638 new_level_nr = old_level_nr + step * direction;
1639 if (new_level_nr < leveldir_current->first_level)
1640 new_level_nr = leveldir_current->first_level;
1641 if (new_level_nr > leveldir_current->last_level)
1642 new_level_nr = leveldir_current->last_level;
1644 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1646 /* skipping levels is only allowed when trying to skip single level */
1647 if (setup.skip_levels && step == 1 &&
1648 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1650 leveldir_current->handicap_level++;
1651 SaveLevelSetup_SeriesInfo();
1654 new_level_nr = leveldir_current->handicap_level;
1657 if (new_level_nr != old_level_nr)
1659 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1661 PlaySound(SND_MENU_ITEM_SELECTING);
1663 level_nr = new_level_nr;
1665 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1666 int2str(level_nr, menu.main.text.level_number.size),
1667 mci->pos_text->font);
1669 LoadLevel(level_nr);
1670 DrawPreviewLevel(TRUE);
1674 DrawCompleteVideoDisplay();
1676 /* needed because DrawPreviewLevel() takes some time */
1682 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1684 static int choice = MAIN_CONTROL_GAME;
1688 if (button == MB_MENU_INITIALIZE)
1690 DrawCursorAndText_Main(choice, TRUE);
1695 if (mx || my) /* mouse input */
1699 for (i = 0; main_controls[i].nr != -1; i++)
1701 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1702 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1703 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1705 pos = main_controls[i].nr;
1711 else if (dx || dy) /* keyboard input */
1713 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1714 choice == MAIN_CONTROL_SETUP))
1715 button = MB_MENU_CHOICE;
1720 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1722 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1724 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1730 PlaySound(SND_MENU_ITEM_ACTIVATING);
1732 DrawCursorAndText_Main(choice, FALSE);
1733 DrawCursorAndText_Main(pos, TRUE);
1740 PlaySound(SND_MENU_ITEM_SELECTING);
1742 if (pos == MAIN_CONTROL_NAME)
1744 game_status = GAME_MODE_PSEUDO_TYPENAME;
1746 HandleTypeName(strlen(setup.player_name), 0);
1748 else if (pos == MAIN_CONTROL_LEVELS)
1752 game_status = GAME_MODE_LEVELS;
1754 SaveLevelSetup_LastSeries();
1755 SaveLevelSetup_SeriesInfo();
1764 else if (pos == MAIN_CONTROL_SCORES)
1766 game_status = GAME_MODE_SCORES;
1770 else if (pos == MAIN_CONTROL_EDITOR)
1772 if (leveldir_current->readonly &&
1773 !strEqual(setup.player_name, "Artsoft"))
1774 Request("This level is read only !", REQ_CONFIRM);
1776 game_status = GAME_MODE_EDITOR;
1778 FadeSetEnterScreen();
1782 else if (pos == MAIN_CONTROL_INFO)
1784 game_status = GAME_MODE_INFO;
1785 info_mode = INFO_MODE_MAIN;
1789 else if (pos == MAIN_CONTROL_GAME)
1791 StartGameActions(options.network, setup.autorecord, level.random_seed);
1793 else if (pos == MAIN_CONTROL_SETUP)
1795 game_status = GAME_MODE_SETUP;
1796 setup_mode = SETUP_MODE_MAIN;
1800 else if (pos == MAIN_CONTROL_QUIT)
1802 SaveLevelSetup_LastSeries();
1803 SaveLevelSetup_SeriesInfo();
1805 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1806 game_status = GAME_MODE_QUIT;
1811 if (game_status == GAME_MODE_MAIN)
1813 DrawPreviewLevel(FALSE);
1819 /* ========================================================================= */
1820 /* info screen functions */
1821 /* ========================================================================= */
1823 static struct TokenInfo *info_info;
1824 static int num_info_info;
1826 static void execInfoTitleScreen()
1828 info_mode = INFO_MODE_TITLE;
1833 static void execInfoElements()
1835 info_mode = INFO_MODE_ELEMENTS;
1840 static void execInfoMusic()
1842 info_mode = INFO_MODE_MUSIC;
1847 static void execInfoCredits()
1849 info_mode = INFO_MODE_CREDITS;
1854 static void execInfoProgram()
1856 info_mode = INFO_MODE_PROGRAM;
1861 static void execInfoVersion()
1863 info_mode = INFO_MODE_VERSION;
1868 static void execInfoLevelSet()
1870 info_mode = INFO_MODE_LEVELSET;
1875 static void execExitInfo()
1877 game_status = GAME_MODE_MAIN;
1879 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1882 static struct TokenInfo info_info_main[] =
1884 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1885 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1886 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1887 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1888 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1889 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1890 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1891 { TYPE_EMPTY, NULL, "" },
1892 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1897 static void DrawCursorAndText_Info(int pos, boolean active)
1899 int xpos = MENU_SCREEN_START_XPOS;
1900 int ypos = MENU_SCREEN_START_YPOS + pos;
1901 int font_nr = FONT_MENU_1;
1904 font_nr = FONT_ACTIVE(font_nr);
1906 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1908 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1909 drawCursor(pos, active);
1912 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1917 CloseDoor(DOOR_CLOSE_2);
1919 /* (needed after displaying title screens which disable auto repeat) */
1920 KeyboardAutoRepeatOn();
1922 FadeSetLeaveScreen();
1929 if (fade_mask == REDRAW_ALL)
1933 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1939 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1941 info_info = info_info_main;
1945 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1947 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1950 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1951 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1952 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1953 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1954 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1955 initCursor(i, IMG_MENU_BUTTON);
1957 DrawCursorAndText_Info(i, FALSE);
1962 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1967 DrawMaskedBorder(fade_mask);
1974 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1976 static int choice_store[MAX_INFO_MODES];
1977 int choice = choice_store[info_mode]; /* always starts with 0 */
1981 if (button == MB_MENU_INITIALIZE)
1983 /* advance to first valid menu entry */
1984 while (choice < num_info_info &&
1985 info_info[choice].type & TYPE_SKIP_ENTRY)
1987 choice_store[info_mode] = choice;
1989 DrawCursorAndText_Info(choice, TRUE);
1993 else if (button == MB_MENU_LEAVE)
1995 for (y = 0; y < num_info_info; y++)
1997 if (info_info[y].type & TYPE_LEAVE_MENU)
1999 void (*menu_callback_function)(void) = info_info[y].value;
2003 menu_callback_function();
2005 break; /* absolutely needed because function changes 'info_info'! */
2012 if (mx || my) /* mouse input */
2014 x = (mx - mSX) / 32;
2015 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2017 else if (dx || dy) /* keyboard input */
2021 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2023 if (info_info[choice].type & menu_navigation_type ||
2024 info_info[choice].type & TYPE_ENTER_SCREEN ||
2025 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2026 info_info[choice].type & TYPE_YES_NO_AUTO)
2027 button = MB_MENU_CHOICE;
2032 /* jump to next non-empty menu entry (up or down) */
2033 while (y > 0 && y < num_info_info - 1 &&
2034 info_info[y].type & TYPE_SKIP_ENTRY)
2038 if (IN_VIS_FIELD(x, y) &&
2039 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2045 PlaySound(SND_MENU_ITEM_ACTIVATING);
2047 DrawCursorAndText_Info(choice, FALSE);
2048 DrawCursorAndText_Info(y, TRUE);
2050 choice = choice_store[info_mode] = y;
2053 else if (!(info_info[y].type & TYPE_GHOSTED))
2055 PlaySound(SND_MENU_ITEM_SELECTING);
2057 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2059 void (*menu_callback_function)(void) = info_info[choice].value;
2061 FadeSetFromType(info_info[y].type);
2063 menu_callback_function();
2069 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2071 int ystart1 = mSY - SY + 100;
2072 int ystart2 = mSY - SY + 150;
2073 int ybottom = mSY - SY + SYSIZE - 20;
2075 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2077 FadeOut(REDRAW_FIELD);
2082 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2083 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2085 DrawTextSCentered(ybottom, FONT_TEXT_4,
2086 "Press any key or button for info menu");
2088 FadeIn(REDRAW_FIELD);
2091 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2093 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2094 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2095 int xstart = mSX + 16;
2096 int ystart1 = mSY - SY + 100;
2097 int ystart2 = mSY + 64 + 2 * 32;
2098 int ybottom = mSY - SY + SYSIZE - 20;
2099 int ystep = TILEY + 4;
2100 int element, action, direction;
2108 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2109 infoscreen_step[i] = infoscreen_frame[i] = 0;
2114 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2116 DrawTextSCentered(ybottom, FONT_TEXT_4,
2117 "Press any key or button for next page");
2123 while (helpanim_info[j].element != HELPANIM_LIST_END)
2125 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2130 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2139 j += infoscreen_step[i - start];
2141 element = helpanim_info[j].element;
2142 action = helpanim_info[j].action;
2143 direction = helpanim_info[j].direction;
2146 element = EL_UNKNOWN;
2148 if (action != -1 && direction != -1)
2149 graphic = el_act_dir2img(element, action, direction);
2150 else if (action != -1)
2151 graphic = el_act2img(element, action);
2152 else if (direction != -1)
2153 graphic = el_dir2img(element, direction);
2155 graphic = el2img(element);
2157 delay = helpanim_info[j++].delay;
2162 if (infoscreen_frame[i - start] == 0)
2165 infoscreen_frame[i - start] = delay - 1;
2169 sync_frame = delay - infoscreen_frame[i - start];
2170 infoscreen_frame[i - start]--;
2173 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2175 if (!infoscreen_frame[i - start])
2176 infoscreen_step[i - start] = 0;
2180 if (!infoscreen_frame[i - start])
2181 infoscreen_step[i - start]++;
2182 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2188 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2190 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2191 graphic, sync_frame, USE_MASKING);
2194 DrawInfoScreen_HelpText(element, action, direction, i - start);
2199 redraw_mask |= REDRAW_FIELD;
2204 static char *getHelpText(int element, int action, int direction)
2206 char token[MAX_LINE_LEN];
2208 strcpy(token, element_info[element].token_name);
2211 strcat(token, element_action_info[action].suffix);
2213 if (direction != -1)
2214 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2216 return getHashEntry(helptext_info, token);
2219 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2221 int font_nr = FONT_INFO_ELEMENTS;
2222 int font_width = getFontWidth(font_nr);
2223 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2224 int sy = mSY + 65 + 2 * 32 + 1;
2225 int ystep = TILEY + 4;
2226 int pad_x = sx - SX;
2227 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2228 int max_lines_per_text = 2;
2231 if (action != -1 && direction != -1) /* element.action.direction */
2232 text = getHelpText(element, action, direction);
2234 if (text == NULL && action != -1) /* element.action */
2235 text = getHelpText(element, action, -1);
2237 if (text == NULL && direction != -1) /* element.direction */
2238 text = getHelpText(element, -1, direction);
2240 if (text == NULL) /* base element */
2241 text = getHelpText(element, -1, -1);
2243 if (text == NULL) /* not found */
2244 text = "No description available";
2246 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2247 sy += getFontHeight(font_nr) / 2;
2249 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2250 max_chars_per_line, -1, max_lines_per_text, -1,
2251 TRUE, FALSE, FALSE);
2254 void DrawInfoScreen_TitleScreen()
2259 void HandleInfoScreen_TitleScreen(int button)
2261 HandleTitleScreen(0, 0, 0, 0, button);
2264 void DrawInfoScreen_Elements()
2266 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2268 FadeOut(REDRAW_FIELD);
2273 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2275 FadeIn(REDRAW_FIELD);
2280 void HandleInfoScreen_Elements(int button)
2282 static unsigned long info_delay = 0;
2283 static int num_anims;
2284 static int num_pages;
2286 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2289 if (button == MB_MENU_INITIALIZE)
2291 boolean new_element = TRUE;
2295 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2297 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2299 else if (new_element)
2302 new_element = FALSE;
2306 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2310 if (button == MB_MENU_LEAVE)
2312 PlaySound(SND_MENU_ITEM_SELECTING);
2314 info_mode = INFO_MODE_MAIN;
2319 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2321 if (button != MB_MENU_INITIALIZE)
2323 PlaySound(SND_MENU_ITEM_SELECTING);
2328 if (page >= num_pages)
2330 FadeSoundsAndMusic();
2332 info_mode = INFO_MODE_MAIN;
2333 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2340 FadeSetNextScreen();
2343 if (button != MB_MENU_INITIALIZE)
2344 FadeOut(REDRAW_FIELD);
2346 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2348 if (button != MB_MENU_INITIALIZE)
2349 FadeIn(REDRAW_FIELD);
2353 if (DelayReached(&info_delay, GameFrameDelay))
2354 if (page < num_pages)
2355 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2357 PlayMenuSoundIfLoop();
2361 void DrawInfoScreen_Music()
2363 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2366 FadeOut(REDRAW_FIELD);
2374 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2377 FadeIn(REDRAW_FIELD);
2381 void HandleInfoScreen_Music(int button)
2383 static struct MusicFileInfo *list = NULL;
2384 int ystart1 = mSY - SY + 100;
2385 int ystart2 = mSY - SY + 150;
2386 int ybottom = mSY - SY + SYSIZE - 20;
2389 if (button == MB_MENU_INITIALIZE)
2391 list = music_file_info;
2395 FadeSoundsAndMusic();
2400 DrawTextSCentered(ystart1, FONT_TEXT_1,
2401 "No music info for this level set.");
2403 DrawTextSCentered(ybottom, FONT_TEXT_4,
2404 "Press any key or button for info menu");
2410 if (button == MB_MENU_LEAVE)
2412 PlaySound(SND_MENU_ITEM_SELECTING);
2414 FadeSoundsAndMusic();
2416 info_mode = INFO_MODE_MAIN;
2421 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2425 if (button != MB_MENU_INITIALIZE)
2427 PlaySound(SND_MENU_ITEM_SELECTING);
2435 FadeSoundsAndMusic();
2437 info_mode = INFO_MODE_MAIN;
2438 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2443 FadeSoundsAndMusic();
2446 if (list != music_file_info)
2447 FadeSetNextScreen();
2450 if (button != MB_MENU_INITIALIZE)
2451 FadeOut(REDRAW_FIELD);
2458 int sound = list->music;
2460 if (sound_info[sound].loop)
2461 PlaySoundLoop(sound);
2465 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2469 PlayMusic(list->music);
2471 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2474 if (!strEqual(list->title, UNKNOWN_NAME))
2476 if (!strEqual(list->title_header, UNKNOWN_NAME))
2477 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2479 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2482 if (!strEqual(list->artist, UNKNOWN_NAME))
2484 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2485 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2487 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2489 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2492 if (!strEqual(list->album, UNKNOWN_NAME))
2494 if (!strEqual(list->album_header, UNKNOWN_NAME))
2495 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2497 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2499 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2502 if (!strEqual(list->year, UNKNOWN_NAME))
2504 if (!strEqual(list->year_header, UNKNOWN_NAME))
2505 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2507 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2509 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2512 DrawTextSCentered(ybottom, FONT_TEXT_4,
2513 "Press any key or button for next page");
2515 if (button != MB_MENU_INITIALIZE)
2516 FadeIn(REDRAW_FIELD);
2519 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2520 PlaySoundLoop(list->music);
2523 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2525 int ystart1 = mSY - SY + 100;
2526 int ystart2 = mSY - SY + 150;
2527 int ybottom = mSY - SY + SYSIZE - 20;
2533 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2537 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2538 "Special thanks to");
2539 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2541 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2543 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2544 "\"Boulder Dash\"");
2545 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2547 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2549 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2551 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2552 "First Star Software");
2554 else if (screen_nr == 1)
2556 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2557 "Special thanks to");
2558 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2559 "Klaus Heinz & Volker Wertich");
2560 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2562 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2563 "\"Emerald Mine\"");
2564 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2566 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2568 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2570 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2573 else if (screen_nr == 2)
2575 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2576 "Special thanks to");
2577 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2578 "Michael Stopp & Philip Jespersen");
2579 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2581 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2583 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2585 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2587 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2589 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2590 "Digital Integration");
2592 else if (screen_nr == 3)
2594 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2595 "Special thanks to");
2596 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2597 "Hiroyuki Imabayashi");
2598 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2600 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2602 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2604 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2606 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2608 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2611 else if (screen_nr == 4)
2613 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2614 "Special thanks to");
2615 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2617 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2619 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2620 "Jürgen Bonhagen");
2621 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2622 "for the continuous creation");
2623 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2624 "of outstanding level sets");
2626 else if (screen_nr == 5)
2628 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2630 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2632 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2633 "for ideas and inspiration by");
2634 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2637 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2639 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2641 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2642 "for ideas and inspiration by");
2643 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2646 else if (screen_nr == 6)
2648 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2650 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2653 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2654 "for the code base used for the");
2655 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2656 "native Emerald Mine engine");
2658 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2659 "for the new Emerald Mine engine");
2662 else if (screen_nr == 7)
2664 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2666 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2668 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2669 "for the initial DOS port");
2671 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2673 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2675 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2676 "for some additional toons");
2678 else if (screen_nr == 8)
2680 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2681 "And not to forget:");
2682 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2684 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2685 "All those who contributed");
2686 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2687 "levels to this game");
2688 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2692 DrawTextSCentered(ybottom, FONT_TEXT_4,
2693 "Press any key or button for next page");
2696 void DrawInfoScreen_Credits()
2698 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2700 FadeSoundsAndMusic();
2703 FadeOut(REDRAW_FIELD);
2706 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2709 FadeIn(REDRAW_FIELD);
2713 void HandleInfoScreen_Credits(int button)
2715 static int screen_nr = 0;
2716 int num_screens = 9;
2718 if (button == MB_MENU_INITIALIZE)
2722 // DrawInfoScreen_CreditsScreen(screen_nr);
2725 if (button == MB_MENU_LEAVE)
2727 PlaySound(SND_MENU_ITEM_SELECTING);
2729 info_mode = INFO_MODE_MAIN;
2734 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2736 if (button != MB_MENU_INITIALIZE)
2738 PlaySound(SND_MENU_ITEM_SELECTING);
2743 if (screen_nr >= num_screens)
2745 FadeSoundsAndMusic();
2747 info_mode = INFO_MODE_MAIN;
2748 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2755 FadeSetNextScreen();
2758 if (button != MB_MENU_INITIALIZE)
2759 FadeOut(REDRAW_FIELD);
2761 DrawInfoScreen_CreditsScreen(screen_nr);
2763 if (button != MB_MENU_INITIALIZE)
2764 FadeIn(REDRAW_FIELD);
2768 PlayMenuSoundIfLoop();
2772 void DrawInfoScreen_Program()
2774 int ystart1 = mSY - SY + 100;
2775 int ystart2 = mSY - SY + 150;
2776 int ybottom = mSY - SY + SYSIZE - 20;
2779 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2782 FadeOut(REDRAW_FIELD);
2788 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2790 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2791 "This game is Freeware!");
2792 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2793 "If you like it, send e-mail to:");
2794 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2795 PROGRAM_EMAIL_STRING);
2796 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2797 "or SnailMail to:");
2798 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2800 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2801 "Detmolder Strasse 189");
2802 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2804 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2806 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2807 "More information and levels:");
2808 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2809 PROGRAM_WEBSITE_STRING);
2810 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2811 "If you have created new levels,");
2812 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2813 "send them to me to include them!");
2814 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2817 DrawTextSCentered(ybottom, FONT_TEXT_4,
2818 "Press any key or button for info menu");
2821 FadeIn(REDRAW_FIELD);
2825 void HandleInfoScreen_Program(int button)
2827 if (button == MB_MENU_LEAVE)
2829 PlaySound(SND_MENU_ITEM_SELECTING);
2831 info_mode = INFO_MODE_MAIN;
2836 else if (button == MB_MENU_CHOICE)
2838 PlaySound(SND_MENU_ITEM_SELECTING);
2840 FadeSoundsAndMusic();
2843 FadeOut(REDRAW_FIELD);
2846 info_mode = INFO_MODE_MAIN;
2847 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2851 PlayMenuSoundIfLoop();
2855 void DrawInfoScreen_Version()
2857 int font_header = FONT_TEXT_3;
2858 int font_text = FONT_TEXT_2;
2859 int xstep = getFontWidth(font_text);
2860 int ystep = getFontHeight(font_text);
2861 int ystart1 = mSY - SY + 100;
2862 int ystart2 = mSY - SY + 150;
2863 int ybottom = mSY - SY + SYSIZE - 20;
2864 int xstart1 = mSX + 2 * xstep;
2865 int xstart2 = mSX + 19 * xstep;
2866 #if defined(TARGET_SDL)
2867 int xstart3 = mSX + 29 * xstep;
2868 SDL_version sdl_version_compiled;
2869 const SDL_version *sdl_version_linked;
2870 int driver_name_len = 8;
2871 char driver_name[driver_name_len];
2874 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2877 FadeOut(REDRAW_FIELD);
2883 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2885 DrawTextF(xstart1, ystart2, font_header, "Name");
2886 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2889 DrawTextF(xstart1, ystart2, font_header, "Version");
2890 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2893 DrawTextF(xstart1, ystart2, font_header, "Platform");
2894 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2897 DrawTextF(xstart1, ystart2, font_header, "Target");
2898 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2901 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2902 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2904 #if defined(TARGET_SDL)
2905 ystart2 += 3 * ystep;
2906 DrawTextF(xstart1, ystart2, font_header, "Library");
2907 DrawTextF(xstart2, ystart2, font_header, "compiled");
2908 DrawTextF(xstart3, ystart2, font_header, "linked");
2910 SDL_VERSION(&sdl_version_compiled);
2911 sdl_version_linked = SDL_Linked_Version();
2913 ystart2 += 2 * ystep;
2914 DrawTextF(xstart1, ystart2, font_text, "SDL");
2915 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2916 sdl_version_compiled.major,
2917 sdl_version_compiled.minor,
2918 sdl_version_compiled.patch);
2919 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2920 sdl_version_linked->major,
2921 sdl_version_linked->minor,
2922 sdl_version_linked->patch);
2924 SDL_IMAGE_VERSION(&sdl_version_compiled);
2925 sdl_version_linked = IMG_Linked_Version();
2928 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2929 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2930 sdl_version_compiled.major,
2931 sdl_version_compiled.minor,
2932 sdl_version_compiled.patch);
2933 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2934 sdl_version_linked->major,
2935 sdl_version_linked->minor,
2936 sdl_version_linked->patch);
2938 SDL_MIXER_VERSION(&sdl_version_compiled);
2939 sdl_version_linked = Mix_Linked_Version();
2942 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2943 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2944 sdl_version_compiled.major,
2945 sdl_version_compiled.minor,
2946 sdl_version_compiled.patch);
2947 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2948 sdl_version_linked->major,
2949 sdl_version_linked->minor,
2950 sdl_version_linked->patch);
2952 SDL_NET_VERSION(&sdl_version_compiled);
2953 sdl_version_linked = SDLNet_Linked_Version();
2956 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2957 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2958 sdl_version_compiled.major,
2959 sdl_version_compiled.minor,
2960 sdl_version_compiled.patch);
2961 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2962 sdl_version_linked->major,
2963 sdl_version_linked->minor,
2964 sdl_version_linked->patch);
2966 ystart2 += 3 * ystep;
2967 DrawTextF(xstart1, ystart2, font_header, "Driver");
2968 DrawTextF(xstart2, ystart2, font_header, "Requested");
2969 DrawTextF(xstart3, ystart2, font_header, "Used");
2971 SDL_VideoDriverName(driver_name, driver_name_len);
2973 ystart2 += 2 * ystep;
2974 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2975 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2976 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2978 SDL_AudioDriverName(driver_name, driver_name_len);
2981 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2982 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2983 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2986 DrawTextSCentered(ybottom, FONT_TEXT_4,
2987 "Press any key or button for info menu");
2990 FadeIn(REDRAW_FIELD);
2994 void HandleInfoScreen_Version(int button)
2996 if (button == MB_MENU_LEAVE)
2998 PlaySound(SND_MENU_ITEM_SELECTING);
3000 info_mode = INFO_MODE_MAIN;
3005 else if (button == MB_MENU_CHOICE)
3007 PlaySound(SND_MENU_ITEM_SELECTING);
3009 FadeSoundsAndMusic();
3012 FadeOut(REDRAW_FIELD);
3015 info_mode = INFO_MODE_MAIN;
3016 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3020 PlayMenuSoundIfLoop();
3024 void DrawInfoScreen_LevelSet()
3026 struct TitleMessageInfo *tmi = &readme;
3027 char *filename = getLevelSetInfoFilename();
3029 /* if chars set to "-1", automatically determine by text and font width */
3030 if (tmi->chars == -1)
3031 tmi->chars = tmi->width / getFontWidth(tmi->font);
3033 tmi->width = tmi->chars * getFontWidth(tmi->font);
3035 /* if lines set to "-1", automatically determine by text and font height */
3036 if (tmi->lines == -1)
3037 tmi->lines = tmi->height / getFontHeight(tmi->font);
3039 tmi->height = tmi->lines * getFontHeight(tmi->font);
3041 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3044 FadeOut(REDRAW_FIELD);
3050 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3052 if (filename != NULL)
3053 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3054 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3055 tmi->autowrap, tmi->centered, tmi->parse_comments);
3057 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3058 "No information for this level set.");
3060 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3061 "Press any key or button for info menu");
3064 FadeIn(REDRAW_FIELD);
3068 void HandleInfoScreen_LevelSet(int button)
3070 if (button == MB_MENU_LEAVE)
3072 PlaySound(SND_MENU_ITEM_SELECTING);
3074 info_mode = INFO_MODE_MAIN;
3079 else if (button == MB_MENU_CHOICE)
3081 PlaySound(SND_MENU_ITEM_SELECTING);
3083 FadeSoundsAndMusic();
3086 FadeOut(REDRAW_FIELD);
3089 info_mode = INFO_MODE_MAIN;
3090 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3094 PlayMenuSoundIfLoop();
3098 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3100 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3102 if (info_mode == INFO_MODE_TITLE)
3103 DrawInfoScreen_TitleScreen();
3104 else if (info_mode == INFO_MODE_ELEMENTS)
3105 DrawInfoScreen_Elements();
3106 else if (info_mode == INFO_MODE_MUSIC)
3107 DrawInfoScreen_Music();
3108 else if (info_mode == INFO_MODE_CREDITS)
3109 DrawInfoScreen_Credits();
3110 else if (info_mode == INFO_MODE_PROGRAM)
3111 DrawInfoScreen_Program();
3112 else if (info_mode == INFO_MODE_VERSION)
3113 DrawInfoScreen_Version();
3114 else if (info_mode == INFO_MODE_LEVELSET)
3115 DrawInfoScreen_LevelSet();
3117 DrawInfoScreen_Main(fade_mask, do_fading);
3119 if (info_mode != INFO_MODE_MAIN &&
3120 info_mode != INFO_MODE_TITLE &&
3121 info_mode != INFO_MODE_MUSIC)
3128 void DrawAndFadeInInfoScreen(int fade_mask)
3130 DrawInfoScreenExt(fade_mask, TRUE);
3133 void DrawInfoScreen()
3135 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3138 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3140 if (info_mode == INFO_MODE_TITLE)
3141 HandleInfoScreen_TitleScreen(button);
3142 else if (info_mode == INFO_MODE_ELEMENTS)
3143 HandleInfoScreen_Elements(button);
3144 else if (info_mode == INFO_MODE_MUSIC)
3145 HandleInfoScreen_Music(button);
3146 else if (info_mode == INFO_MODE_CREDITS)
3147 HandleInfoScreen_Credits(button);
3148 else if (info_mode == INFO_MODE_PROGRAM)
3149 HandleInfoScreen_Program(button);
3150 else if (info_mode == INFO_MODE_VERSION)
3151 HandleInfoScreen_Version(button);
3152 else if (info_mode == INFO_MODE_LEVELSET)
3153 HandleInfoScreen_LevelSet(button);
3155 HandleInfoScreen_Main(mx, my, dx, dy, button);
3161 /* ========================================================================= */
3162 /* type name functions */
3163 /* ========================================================================= */
3165 void HandleTypeName(int newxpos, Key key)
3167 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3168 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3169 struct TextPosInfo *pos = mci->pos_input;
3170 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3171 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3172 static int xpos = 0;
3173 int font_nr = pos->font;
3174 int font_active_nr = FONT_ACTIVE(font_nr);
3175 int font_width = getFontWidth(font_active_nr);
3176 char key_char = getValidConfigValueChar(getCharFromKey(key));
3177 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3178 boolean is_active = TRUE;
3180 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3184 strcpy(last_player_name, setup.player_name);
3188 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3190 setup.player_name[xpos] = key_char;
3191 setup.player_name[xpos + 1] = 0;
3195 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3199 setup.player_name[xpos] = 0;
3201 else if (key == KSYM_Return && xpos > 0)
3207 game_status = GAME_MODE_MAIN;
3209 else if (key == KSYM_Escape)
3211 strcpy(setup.player_name, last_player_name);
3215 game_status = GAME_MODE_MAIN;
3220 pos->width = (strlen(setup.player_name) + 1) * font_width;
3221 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3223 DrawText(startx, starty, setup.player_name, font_active_nr);
3224 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3228 pos->width = strlen(setup.player_name) * font_width;
3229 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3231 DrawText(startx, starty, setup.player_name, font_nr);
3236 /* ========================================================================= */
3237 /* tree menu functions */
3238 /* ========================================================================= */
3240 static void DrawChooseTree(TreeInfo **ti_ptr)
3244 FreeScreenGadgets();
3245 CreateScreenGadgets();
3247 CloseDoor(DOOR_CLOSE_2);
3250 FadeOut(REDRAW_FIELD);
3255 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3256 MapScreenTreeGadgets(*ti_ptr);
3259 FadeIn(REDRAW_FIELD);
3265 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3267 struct GadgetInfo *gi = screen_gadget[id];
3268 int items_max, items_visible, item_position;
3270 items_max = numTreeInfoInGroup(ti);
3271 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3272 item_position = first_entry;
3274 if (item_position > items_max - items_visible)
3275 item_position = items_max - items_visible;
3277 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3278 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3279 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3282 static void drawChooseTreeList(int first_entry, int num_page_entries,
3286 char *title_string = NULL;
3287 int yoffset_sets = MENU_TITLE1_YPOS;
3288 int yoffset_setup = 16;
3289 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3291 int last_game_status = game_status; /* save current game status */
3293 title_string = ti->infotext;
3295 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3298 /* force LEVELS font on artwork setup screen */
3299 game_status = GAME_MODE_LEVELS;
3303 /* clear tree list area, but not title or scrollbar */
3304 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3305 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3306 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3308 /* clear tree list area, but not title or scrollbar */
3309 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3310 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3311 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3314 for (i = 0; i < num_page_entries; i++)
3316 TreeInfo *node, *node_first;
3317 int entry_pos = first_entry + i;
3318 int xpos = MENU_SCREEN_START_XPOS;
3319 int ypos = MENU_SCREEN_START_YPOS + i;
3320 int startx = mSX + xpos * 32;
3321 int starty = mSY + ypos * 32;
3322 int font_nr = FONT_TEXT_1;
3323 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3324 int startx_text = startx + font_xoffset;
3325 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3326 int text_size = startx_scrollbar - startx_text;
3327 int max_buffer_len = text_size / getFontWidth(font_nr);
3328 char buffer[max_buffer_len + 1];
3330 node_first = getTreeInfoFirstGroupEntry(ti);
3331 node = getTreeInfoFromPos(node_first, entry_pos);
3333 strncpy(buffer, node->name, max_buffer_len);
3334 buffer[max_buffer_len] = '\0';
3336 DrawText(startx, starty, buffer, font_nr + node->color);
3338 if (node->parent_link)
3339 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3340 else if (node->level_group)
3341 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3343 initCursor(i, IMG_MENU_BUTTON);
3346 game_status = last_game_status; /* restore current game status */
3348 redraw_mask |= REDRAW_FIELD;
3351 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3353 TreeInfo *node, *node_first;
3354 int x, last_redraw_mask = redraw_mask;
3355 int ypos = MENU_TITLE2_YPOS;
3356 int font_nr = FONT_TITLE_2;
3358 if (ti->type != TREE_TYPE_LEVEL_DIR)
3361 node_first = getTreeInfoFirstGroupEntry(ti);
3362 node = getTreeInfoFromPos(node_first, entry_pos);
3364 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3366 if (node->parent_link)
3367 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3369 else if (node->level_group)
3370 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3372 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3373 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3374 node->levels, node->class_desc);
3376 /* let BackToFront() redraw only what is needed */
3377 redraw_mask = last_redraw_mask | REDRAW_TILES;
3378 for (x = 0; x < SCR_FIELDX; x++)
3379 MarkTileDirty(x, 1);
3382 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3385 TreeInfo *ti = *ti_ptr;
3387 int y = ti->cl_cursor;
3388 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3389 int num_entries = numTreeInfoInGroup(ti);
3390 int num_page_entries;
3391 int last_game_status = game_status; /* save current game status */
3392 boolean position_set_by_scrollbar = (dx == 999);
3395 /* force LEVELS draw offset on choose level and artwork setup screen */
3396 game_status = GAME_MODE_LEVELS;
3399 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3400 num_page_entries = num_entries;
3402 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3404 game_status = last_game_status; /* restore current game status */
3406 if (button == MB_MENU_INITIALIZE)
3408 int num_entries = numTreeInfoInGroup(ti);
3409 int entry_pos = posTreeInfo(ti);
3411 if (ti->cl_first == -1)
3413 /* only on initialization */
3414 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3415 ti->cl_cursor = entry_pos - ti->cl_first;
3417 else if (ti->cl_cursor >= num_page_entries ||
3418 (num_entries > num_page_entries &&
3419 num_entries - ti->cl_first < num_page_entries))
3421 /* only after change of list size (by custom graphic configuration) */
3422 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3423 ti->cl_cursor = entry_pos - ti->cl_first;
3426 if (position_set_by_scrollbar)
3429 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3432 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3433 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3434 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3438 else if (button == MB_MENU_LEAVE)
3442 PlaySound(SND_MENU_ITEM_SELECTING);
3444 if (ti->node_parent)
3446 *ti_ptr = ti->node_parent;
3447 DrawChooseTree(ti_ptr);
3449 else if (game_status == GAME_MODE_SETUP)
3451 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3453 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3454 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3455 execSetupGraphics();
3461 game_status = GAME_MODE_MAIN;
3463 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3469 if (mx || my) /* mouse input */
3471 int last_game_status = game_status; /* save current game status */
3474 /* force LEVELS draw offset on artwork setup screen */
3475 game_status = GAME_MODE_LEVELS;
3478 x = (mx - mSX) / 32;
3479 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3481 game_status = last_game_status; /* restore current game status */
3483 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3485 /* move cursor instead of scrolling when already at start/end of list */
3486 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3488 else if (dy == +1 * SCROLL_LINE &&
3489 ti->cl_first + num_page_entries == num_entries)
3492 /* handle scrolling screen one line or page */
3493 if (ti->cl_cursor + dy < 0 ||
3494 ti->cl_cursor + dy > num_page_entries - 1)
3496 if (ABS(dy) == SCROLL_PAGE)
3497 step = num_page_entries - 1;
3499 if (dy < 0 && ti->cl_first > 0)
3501 /* scroll page/line up */
3503 ti->cl_first -= step;
3504 if (ti->cl_first < 0)
3507 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3508 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3509 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3511 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3514 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3516 /* scroll page/line down */
3518 ti->cl_first += step;
3519 if (ti->cl_first + num_page_entries > num_entries)
3520 ti->cl_first = MAX(0, num_entries - num_page_entries);
3522 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3523 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3524 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3526 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3533 /* handle moving cursor one line */
3534 y = ti->cl_cursor + dy;
3539 TreeInfo *node_first, *node_cursor;
3540 int entry_pos = ti->cl_first + y;
3542 node_first = getTreeInfoFirstGroupEntry(ti);
3543 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3545 if (node_cursor->node_group)
3549 PlaySound(SND_MENU_ITEM_SELECTING);
3551 node_cursor->cl_first = ti->cl_first;
3552 node_cursor->cl_cursor = ti->cl_cursor;
3553 *ti_ptr = node_cursor->node_group;
3554 DrawChooseTree(ti_ptr);
3559 else if (dx == -1 && ti->node_parent)
3563 PlaySound(SND_MENU_ITEM_SELECTING);
3565 *ti_ptr = ti->node_parent;
3566 DrawChooseTree(ti_ptr);
3571 if (!anyScrollbarGadgetActive() &&
3572 IN_VIS_FIELD(x, y) &&
3573 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3574 y >= 0 && y < num_page_entries)
3578 if (y != ti->cl_cursor)
3580 PlaySound(SND_MENU_ITEM_ACTIVATING);
3582 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3583 drawChooseTreeCursor(y, TRUE);
3584 drawChooseTreeInfo(ti->cl_first + y, ti);
3591 TreeInfo *node_first, *node_cursor;
3592 int entry_pos = ti->cl_first + y;
3594 PlaySound(SND_MENU_ITEM_SELECTING);
3596 node_first = getTreeInfoFirstGroupEntry(ti);
3597 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3599 if (node_cursor->node_group)
3603 node_cursor->cl_first = ti->cl_first;
3604 node_cursor->cl_cursor = ti->cl_cursor;
3605 *ti_ptr = node_cursor->node_group;
3606 DrawChooseTree(ti_ptr);
3608 else if (node_cursor->parent_link)
3612 *ti_ptr = node_cursor->node_parent;
3613 DrawChooseTree(ti_ptr);
3617 FadeSetEnterScreen();
3619 node_cursor->cl_first = ti->cl_first;
3620 node_cursor->cl_cursor = ti->cl_cursor;
3621 *ti_ptr = node_cursor;
3623 if (ti->type == TREE_TYPE_LEVEL_DIR)
3625 LoadLevelSetup_SeriesInfo();
3627 SaveLevelSetup_LastSeries();
3628 SaveLevelSetup_SeriesInfo();
3632 if (game_status == GAME_MODE_SETUP)
3634 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3636 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3637 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3638 execSetupGraphics();
3644 game_status = GAME_MODE_MAIN;
3652 void DrawChooseLevel()
3654 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3656 DrawChooseTree(&leveldir_current);
3662 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3664 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3669 void DrawHallOfFame(int highlight_position)
3672 FadeSoundsAndMusic();
3674 /* (this is needed when called from GameEnd() after winning a game) */
3675 KeyboardAutoRepeatOn();
3678 /* (this is needed when called from GameEnd() after winning a game) */
3679 SetDrawDeactivationMask(REDRAW_NONE);
3680 SetDrawBackgroundMask(REDRAW_FIELD);
3682 CloseDoor(DOOR_CLOSE_2);
3684 if (highlight_position < 0)
3685 LoadScore(level_nr);
3687 FadeSetEnterScreen();
3689 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3692 FadeOut(REDRAW_FIELD);
3700 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3703 FadeIn(REDRAW_FIELD);
3707 static void drawHallOfFameList(int first_entry, int highlight_position)
3711 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3714 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3715 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3716 "HighScores of Level %d", level_nr);
3718 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3720 int entry = first_entry + i;
3721 boolean active = (entry == highlight_position);
3722 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3723 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3724 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3725 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3726 int dx1 = 3 * getFontWidth(font_nr1);
3727 int dx2 = dx1 + getFontWidth(font_nr1);
3728 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3729 int sy = mSY + 64 + i * 32;
3731 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3732 DrawText(mSX + dx1, sy, ".", font_nr1);
3733 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3735 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3736 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3738 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3741 redraw_mask |= REDRAW_FIELD;
3744 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3746 static int first_entry = 0;
3747 static int highlight_position = 0;
3748 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3750 if (button == MB_MENU_INITIALIZE)
3753 highlight_position = mx;
3754 drawHallOfFameList(first_entry, highlight_position);
3759 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3760 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3764 if (first_entry > 0)
3766 first_entry -= step;
3767 if (first_entry < 0)
3770 drawHallOfFameList(first_entry, highlight_position);
3775 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3777 first_entry += step;
3778 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3779 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3781 drawHallOfFameList(first_entry, highlight_position);
3784 else if (button == MB_MENU_LEAVE)
3786 PlaySound(SND_MENU_ITEM_SELECTING);
3788 FadeSound(SND_BACKGROUND_SCORES);
3790 game_status = GAME_MODE_MAIN;
3794 else if (button == MB_MENU_CHOICE)
3796 PlaySound(SND_MENU_ITEM_SELECTING);
3798 FadeSound(SND_BACKGROUND_SCORES);
3801 FadeOut(REDRAW_FIELD);
3804 game_status = GAME_MODE_MAIN;
3806 DrawAndFadeInMainMenu(REDRAW_FIELD);
3809 if (game_status == GAME_MODE_SCORES)
3810 PlayMenuSoundIfLoop();
3816 /* ========================================================================= */
3817 /* setup screen functions */
3818 /* ========================================================================= */
3820 static struct TokenInfo *setup_info;
3821 static int num_setup_info;
3823 static char *screen_mode_text;
3824 static char *scroll_delay_text;
3825 static char *game_speed_text;
3826 static char *graphics_set_name;
3827 static char *sounds_set_name;
3828 static char *music_set_name;
3830 static void execSetupMain()
3832 setup_mode = SETUP_MODE_MAIN;
3837 static void execSetupGame()
3839 if (game_speeds == NULL)
3843 for (i = 0; game_speeds_list[i].value != -1; i++)
3845 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3846 char identifier[32], name[32];
3847 int value = game_speeds_list[i].value;
3848 char *text = game_speeds_list[i].text;
3850 ti->node_top = &game_speeds;
3851 ti->sort_priority = 10000 - value;
3853 sprintf(identifier, "%d", value);
3854 sprintf(name, "%s", text);
3856 setString(&ti->identifier, identifier);
3857 setString(&ti->name, name);
3858 setString(&ti->name_sorting, name);
3859 setString(&ti->infotext, "Game Speed");
3861 pushTreeInfo(&game_speeds, ti);
3864 /* sort game speed values to start with slowest game speed */
3865 sortTreeInfo(&game_speeds);
3867 /* set current game speed to configured game speed value */
3868 game_speed_current =
3869 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3871 /* if that fails, set current game speed to reliable default value */
3872 if (game_speed_current == NULL)
3873 game_speed_current =
3874 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3876 /* if that also fails, set current game speed to first available speed */
3877 if (game_speed_current == NULL)
3878 game_speed_current = game_speeds;
3881 setup.game_frame_delay = atoi(game_speed_current->identifier);
3883 /* needed for displaying game speed text instead of identifier */
3884 game_speed_text = game_speed_current->name;
3886 setup_mode = SETUP_MODE_GAME;
3891 static void execSetupChooseGameSpeed()
3893 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3898 static void execSetupEditor()
3900 setup_mode = SETUP_MODE_EDITOR;
3905 static void execSetupGraphics()
3907 if (video.fullscreen_available && screen_modes == NULL)
3911 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3913 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3914 char identifier[32], name[32];
3915 int x = video.fullscreen_modes[i].width;
3916 int y = video.fullscreen_modes[i].height;
3919 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3921 ti->node_top = &screen_modes;
3922 ti->sort_priority = x * 10000 + y;
3924 sprintf(identifier, "%dx%d", x, y);
3925 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3927 setString(&ti->identifier, identifier);
3928 setString(&ti->name, name);
3929 setString(&ti->name_sorting, name);
3930 setString(&ti->infotext, "Fullscreen Mode");
3932 pushTreeInfo(&screen_modes, ti);
3935 /* sort fullscreen modes to start with lowest available screen resolution */
3936 sortTreeInfo(&screen_modes);
3938 /* set current screen mode for fullscreen mode to configured setup value */
3939 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3940 setup.fullscreen_mode);
3942 /* if that fails, set current screen mode to reliable default value */
3943 if (screen_mode_current == NULL)
3944 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3945 DEFAULT_FULLSCREEN_MODE);
3947 /* if that also fails, set current screen mode to first available mode */
3948 if (screen_mode_current == NULL)
3949 screen_mode_current = screen_modes;
3951 if (screen_mode_current == NULL)
3952 video.fullscreen_available = FALSE;
3955 if (video.fullscreen_available)
3957 setup.fullscreen_mode = screen_mode_current->identifier;
3959 /* needed for displaying screen mode name instead of identifier */
3960 screen_mode_text = screen_mode_current->name;
3964 if (scroll_delays == NULL)
3968 for (i = 0; scroll_delays_list[i].value != -1; i++)
3970 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3971 char identifier[32], name[32];
3972 int value = scroll_delays_list[i].value;
3973 char *text = scroll_delays_list[i].text;
3975 ti->node_top = &scroll_delays;
3976 ti->sort_priority = value;
3978 sprintf(identifier, "%d", value);
3979 sprintf(name, "%s", text);
3981 setString(&ti->identifier, identifier);
3982 setString(&ti->name, name);
3983 setString(&ti->name_sorting, name);
3984 setString(&ti->infotext, "Scroll Delay");
3986 pushTreeInfo(&scroll_delays, ti);
3989 /* sort scroll delay values to start with lowest scroll delay value */
3990 sortTreeInfo(&scroll_delays);
3992 /* set current scroll delay value to configured scroll delay value */
3993 scroll_delay_current =
3994 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
3996 /* if that fails, set current scroll delay to reliable default value */
3997 if (scroll_delay_current == NULL)
3998 scroll_delay_current =
3999 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4001 /* if that also fails, set current scroll delay to first available value */
4002 if (scroll_delay_current == NULL)
4003 scroll_delay_current = scroll_delays;
4006 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4008 /* needed for displaying scroll delay text instead of identifier */
4009 scroll_delay_text = scroll_delay_current->name;
4012 setup_mode = SETUP_MODE_GRAPHICS;
4016 static void execSetupChooseScreenMode()
4018 if (!video.fullscreen_available)
4021 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4026 static void execSetupChooseScrollDelay()
4028 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4033 static void execSetupSound()
4035 setup_mode = SETUP_MODE_SOUND;
4040 static void execSetupArtwork()
4043 printf("::: '%s', '%s', '%s'\n",
4044 artwork.gfx_current->subdir,
4045 artwork.gfx_current->fullpath,
4046 artwork.gfx_current->basepath);
4049 setup.graphics_set = artwork.gfx_current->identifier;
4050 setup.sounds_set = artwork.snd_current->identifier;
4051 setup.music_set = artwork.mus_current->identifier;
4053 /* needed if last screen (setup choice) changed graphics, sounds or music */
4054 ReloadCustomArtwork(0);
4056 /* needed for displaying artwork name instead of artwork identifier */
4057 graphics_set_name = artwork.gfx_current->name;
4058 sounds_set_name = artwork.snd_current->name;
4059 music_set_name = artwork.mus_current->name;
4061 setup_mode = SETUP_MODE_ARTWORK;
4066 static void execSetupChooseGraphics()
4068 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4073 static void execSetupChooseSounds()
4075 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4080 static void execSetupChooseMusic()
4082 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4087 static void execSetupInput()
4089 setup_mode = SETUP_MODE_INPUT;
4094 static void execSetupShortcuts()
4096 setup_mode = SETUP_MODE_SHORTCUTS;
4101 static void execSetupShortcuts1()
4103 setup_mode = SETUP_MODE_SHORTCUTS_1;
4108 static void execSetupShortcuts2()
4110 setup_mode = SETUP_MODE_SHORTCUTS_2;
4115 static void execSetupShortcuts3()
4117 setup_mode = SETUP_MODE_SHORTCUTS_3;
4122 static void execSetupShortcuts4()
4124 setup_mode = SETUP_MODE_SHORTCUTS_4;
4129 static void execExitSetup()
4131 game_status = GAME_MODE_MAIN;
4133 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4136 static void execSaveAndExitSetup()
4142 static struct TokenInfo setup_info_main[] =
4144 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4145 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4146 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4147 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4148 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4149 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4150 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4151 { TYPE_EMPTY, NULL, "" },
4152 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4153 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4158 static struct TokenInfo setup_info_game[] =
4160 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4161 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4162 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4163 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4164 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4165 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4166 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4167 { TYPE_STRING, &game_speed_text, "" },
4168 { TYPE_EMPTY, NULL, "" },
4169 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4174 static struct TokenInfo setup_info_editor[] =
4177 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4178 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4179 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4180 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4181 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4182 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4183 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4184 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4186 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4187 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4188 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4190 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4192 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4193 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4194 { TYPE_EMPTY, NULL, "" },
4196 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4197 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4198 { TYPE_EMPTY, NULL, "" },
4200 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4201 { TYPE_EMPTY, NULL, "" },
4202 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4207 static struct TokenInfo setup_info_graphics[] =
4209 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4210 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4211 { TYPE_STRING, &screen_mode_text, "" },
4213 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4215 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4216 { TYPE_STRING, &scroll_delay_text, "" },
4218 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4220 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4221 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4222 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4223 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4224 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4225 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4226 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4227 { TYPE_EMPTY, NULL, "" },
4228 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4233 static struct TokenInfo setup_info_sound[] =
4235 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4236 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4237 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4238 { TYPE_EMPTY, NULL, "" },
4239 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4244 static struct TokenInfo setup_info_artwork[] =
4246 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4247 { TYPE_STRING, &graphics_set_name, "" },
4248 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4249 { TYPE_STRING, &sounds_set_name, "" },
4250 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4251 { TYPE_STRING, &music_set_name, "" },
4252 { TYPE_EMPTY, NULL, "" },
4255 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4256 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4257 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4259 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4260 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4261 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4262 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4265 { TYPE_STRING, NULL, "Override Level Artwork:"},
4266 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4267 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4268 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4270 { TYPE_EMPTY, NULL, "" },
4271 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4276 static struct TokenInfo setup_info_input[] =
4278 { TYPE_SWITCH, NULL, "Player:" },
4279 { TYPE_SWITCH, NULL, "Device:" },
4280 { TYPE_ENTER_MENU, NULL, "" },
4281 { TYPE_EMPTY, NULL, "" },
4282 { TYPE_EMPTY, NULL, "" },
4283 { TYPE_EMPTY, NULL, "" },
4284 { TYPE_EMPTY, NULL, "" },
4285 { TYPE_EMPTY, NULL, "" },
4286 { TYPE_EMPTY, NULL, "" },
4287 { TYPE_EMPTY, NULL, "" },
4288 { TYPE_EMPTY, NULL, "" },
4289 { TYPE_EMPTY, NULL, "" },
4290 { TYPE_EMPTY, NULL, "" },
4291 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4296 static struct TokenInfo setup_info_shortcuts[] =
4298 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4299 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4300 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4301 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4302 { TYPE_EMPTY, NULL, "" },
4303 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4308 static struct TokenInfo setup_info_shortcuts_1[] =
4310 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4311 { TYPE_KEY, &setup.shortcut.save_game, "" },
4312 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4313 { TYPE_KEY, &setup.shortcut.load_game, "" },
4314 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4315 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4316 { TYPE_EMPTY, NULL, "" },
4317 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4318 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4319 { TYPE_EMPTY, NULL, "" },
4320 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4325 static struct TokenInfo setup_info_shortcuts_2[] =
4327 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4328 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4329 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4330 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4331 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4332 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4333 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4334 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4335 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4336 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4337 { TYPE_EMPTY, NULL, "" },
4338 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4343 static struct TokenInfo setup_info_shortcuts_3[] =
4345 { TYPE_KEYTEXT, NULL, "Tape Eject:", },
4346 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4347 { TYPE_KEYTEXT, NULL, "Tape Stop:", },
4348 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4349 { TYPE_KEYTEXT, NULL, "Tape Pause:", },
4350 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4351 { TYPE_KEYTEXT, NULL, "Tape Record:", },
4352 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4353 { TYPE_KEYTEXT, NULL, "Tape Play:", },
4354 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4355 { TYPE_EMPTY, NULL, "" },
4356 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4361 static struct TokenInfo setup_info_shortcuts_4[] =
4363 { TYPE_KEYTEXT, NULL, "Sound Effects (Normal):", },
4364 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4365 { TYPE_KEYTEXT, NULL, "Sound Effects (Looping):", },
4366 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4367 { TYPE_KEYTEXT, NULL, "Music:", },
4368 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4369 { TYPE_EMPTY, NULL, "" },
4370 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4375 static Key getSetupKey()
4377 Key key = KSYM_UNDEFINED;
4378 boolean got_key_event = FALSE;
4380 while (!got_key_event)
4382 if (PendingEvent()) /* got event */
4390 case EVENT_KEYPRESS:
4392 key = GetEventKey((KeyEvent *)&event, TRUE);
4394 /* press 'Escape' or 'Enter' to keep the existing key binding */
4395 if (key == KSYM_Escape || key == KSYM_Return)
4396 key = KSYM_UNDEFINED; /* keep old value */
4398 got_key_event = TRUE;
4402 case EVENT_KEYRELEASE:
4403 key_joystick_mapping = 0;
4407 HandleOtherEvents(&event);
4415 /* don't eat all CPU time */
4422 static int getSetupTextFont(int type)
4424 if (type & (TYPE_SWITCH |
4436 static int getSetupValueFont(int type, void *value)
4438 if (type & TYPE_KEY)
4439 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4440 else if (type & TYPE_STRING)
4441 return FONT_VALUE_2;
4442 else if (type & TYPE_ECS_AGA)
4443 return FONT_VALUE_1;
4444 else if (type & TYPE_BOOLEAN_STYLE)
4445 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4446 else if (type & TYPE_YES_NO_AUTO)
4447 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4448 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4450 return FONT_VALUE_1;
4453 static void drawSetupValue(int pos)
4455 boolean font_draw_xoffset_modified = FALSE;
4456 int font_draw_xoffset_old = -1;
4457 int xpos = MENU_SCREEN_VALUE_XPOS;
4458 int ypos = MENU_SCREEN_START_YPOS + pos;
4459 int startx = mSX + xpos * 32;
4460 int starty = mSY + ypos * 32;
4461 int font_nr, font_width, font_height;
4462 int type = setup_info[pos].type;
4463 void *value = setup_info[pos].value;
4464 char *value_string = getSetupValue(type, value);
4469 if (value_string == NULL)
4472 if (type & TYPE_KEY)
4474 xpos = MENU_SCREEN_START_XPOS;
4476 if (type & TYPE_QUERY)
4477 value_string = "<press key>";
4479 else if (type & TYPE_STRING)
4481 int max_value_len = (SCR_FIELDX - 2) * 2;
4483 xpos = MENU_SCREEN_START_XPOS;
4485 if (strlen(value_string) > max_value_len)
4486 value_string[max_value_len] = '\0';
4488 else if (type & TYPE_YES_NO_AUTO)
4490 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4493 startx = mSX + xpos * 32;
4494 starty = mSY + ypos * 32;
4495 font_nr = getSetupValueFont(type, value);
4496 font_width = getFontWidth(font_nr);
4497 font_height = getFontHeight(font_nr);
4499 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4500 if (setup_mode != SETUP_MODE_INPUT)
4502 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4503 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4504 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4505 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4506 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4507 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4508 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4509 boolean correct_font_draw_xoffset = FALSE;
4511 if (xpos == MENU_SCREEN_START_XPOS &&
4512 startx + font1_xoffset < text_startx + text_font_xoffset)
4513 correct_font_draw_xoffset = TRUE;
4515 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4516 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4517 correct_font_draw_xoffset = TRUE;
4519 /* check if setup value would overlap with setup text when printed */
4520 /* (this can happen for extreme/wrong values for font draw offset) */
4521 if (correct_font_draw_xoffset)
4523 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4524 font_draw_xoffset_modified = TRUE;
4526 if (type & TYPE_KEY)
4527 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4528 else if (!(type & TYPE_STRING))
4529 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4530 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4535 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4537 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4538 DrawText(startx + i * font_width, starty, " ", font_nr);
4541 DrawText(startx, starty, value_string, font_nr);
4543 if (font_draw_xoffset_modified)
4544 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4547 static void changeSetupValue(int pos, int dx)
4549 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4551 *(boolean *)setup_info[pos].value ^= TRUE;
4553 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4555 *(int *)setup_info[pos].value =
4557 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4558 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4559 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4560 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4562 else if (setup_info[pos].type & TYPE_KEY)
4566 setup_info[pos].type |= TYPE_QUERY;
4567 drawSetupValue(pos);
4568 setup_info[pos].type &= ~TYPE_QUERY;
4570 key = getSetupKey();
4571 if (key != KSYM_UNDEFINED)
4572 *(Key *)setup_info[pos].value = key;
4575 drawSetupValue(pos);
4578 static void DrawCursorAndText_Setup(int pos, boolean active)
4580 int xpos = MENU_SCREEN_START_XPOS;
4581 int ypos = MENU_SCREEN_START_YPOS + pos;
4582 int font_nr = getSetupTextFont(setup_info[pos].type);
4584 if (setup_info == setup_info_input)
4585 font_nr = FONT_MENU_1;
4588 font_nr = FONT_ACTIVE(font_nr);
4590 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4592 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4593 drawCursor(pos, active);
4596 static void DrawSetupScreen_Generic()
4598 boolean redraw_all = FALSE;
4599 char *title_string = NULL;
4603 CloseDoor(DOOR_CLOSE_2);
4605 if (redraw_mask & REDRAW_ALL)
4609 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4610 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4611 int2str(0, redraw_mask)));
4615 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4616 FadeOut(redraw_mask);
4618 FadeOut(REDRAW_FIELD);
4623 if (setup_mode == SETUP_MODE_MAIN)
4625 setup_info = setup_info_main;
4626 title_string = "Setup";
4628 else if (setup_mode == SETUP_MODE_GAME)
4630 setup_info = setup_info_game;
4631 title_string = "Setup Game";
4633 else if (setup_mode == SETUP_MODE_EDITOR)
4635 setup_info = setup_info_editor;
4636 title_string = "Setup Editor";
4638 else if (setup_mode == SETUP_MODE_GRAPHICS)
4640 setup_info = setup_info_graphics;
4641 title_string = "Setup Graphics";
4643 else if (setup_mode == SETUP_MODE_SOUND)
4645 setup_info = setup_info_sound;
4646 title_string = "Setup Sound";
4648 else if (setup_mode == SETUP_MODE_ARTWORK)
4650 setup_info = setup_info_artwork;
4651 title_string = "Custom Artwork";
4653 else if (setup_mode == SETUP_MODE_SHORTCUTS)
4655 setup_info = setup_info_shortcuts;
4656 title_string = "Setup Shortcuts";
4658 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4660 setup_info = setup_info_shortcuts_1;
4661 title_string = "Setup Shortcuts";
4663 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4665 setup_info = setup_info_shortcuts_2;
4666 title_string = "Setup Shortcuts";
4668 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
4670 setup_info = setup_info_shortcuts_3;
4671 title_string = "Setup Shortcuts";
4673 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
4675 setup_info = setup_info_shortcuts_4;
4676 title_string = "Setup Shortcuts";
4679 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4683 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4685 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4688 void *value_ptr = setup_info[i].value;
4690 /* set some entries to "unchangeable" according to other variables */
4691 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4692 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4693 (value_ptr == &setup.sound_music && !audio.music_available) ||
4694 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4695 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4696 setup_info[i].type |= TYPE_GHOSTED;
4698 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4699 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4700 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4701 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4702 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4703 initCursor(i, IMG_MENU_BUTTON);
4705 DrawCursorAndText_Setup(i, FALSE);
4707 if (setup_info[i].type & TYPE_VALUE)
4714 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4715 "Joysticks deactivated in setup menu");
4719 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4723 redraw_mask = REDRAW_ALL;
4726 FadeIn(redraw_mask);
4728 FadeIn(REDRAW_FIELD);
4733 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4737 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4739 static int choice_store[MAX_SETUP_MODES];
4740 int choice = choice_store[setup_mode]; /* always starts with 0 */
4744 if (button == MB_MENU_INITIALIZE)
4746 /* advance to first valid menu entry */
4747 while (choice < num_setup_info &&
4748 setup_info[choice].type & TYPE_SKIP_ENTRY)
4750 choice_store[setup_mode] = choice;
4752 DrawCursorAndText_Setup(choice, TRUE);
4756 else if (button == MB_MENU_LEAVE)
4758 PlaySound(SND_MENU_ITEM_SELECTING);
4760 for (y = 0; y < num_setup_info; y++)
4762 if (setup_info[y].type & TYPE_LEAVE_MENU)
4764 void (*menu_callback_function)(void) = setup_info[y].value;
4768 menu_callback_function();
4770 break; /* absolutely needed because function changes 'setup_info'! */
4777 if (mx || my) /* mouse input */
4779 x = (mx - mSX) / 32;
4780 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4782 else if (dx || dy) /* keyboard input */
4786 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4788 if (setup_info[choice].type & menu_navigation_type ||
4789 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4790 setup_info[choice].type & TYPE_YES_NO_AUTO)
4791 button = MB_MENU_CHOICE;
4796 /* jump to next non-empty menu entry (up or down) */
4797 while (y > 0 && y < num_setup_info - 1 &&
4798 setup_info[y].type & TYPE_SKIP_ENTRY)
4802 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4806 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4808 PlaySound(SND_MENU_ITEM_ACTIVATING);
4810 DrawCursorAndText_Setup(choice, FALSE);
4811 DrawCursorAndText_Setup(y, TRUE);
4813 choice = choice_store[setup_mode] = y;
4816 else if (!(setup_info[y].type & TYPE_GHOSTED))
4818 PlaySound(SND_MENU_ITEM_SELECTING);
4820 /* when selecting key headline, execute function for key value change */
4821 if (setup_info[y].type & TYPE_KEYTEXT &&
4822 setup_info[y + 1].type & TYPE_KEY)
4825 /* when selecting string value, execute function for list selection */
4826 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4827 setup_info[y - 1].type & TYPE_ENTER_LIST)
4830 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4832 void (*menu_callback_function)(void) = setup_info[y].value;
4834 FadeSetFromType(setup_info[y].type);
4836 menu_callback_function();
4840 if (setup_info[y].type & TYPE_VALUE)
4841 changeSetupValue(y, dx);
4847 void DrawSetupScreen_Input()
4852 FadeOut(REDRAW_FIELD);
4858 setup_info = setup_info_input;
4861 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4865 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4866 "Joysticks deactivated on this screen");
4868 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4869 "Joysticks deactivated on this screen");
4874 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4876 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4879 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4880 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4881 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4882 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4883 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4884 initCursor(i, IMG_MENU_BUTTON);
4886 DrawCursorAndText_Setup(i, FALSE);
4890 DeactivateJoystickForCalibration();
4895 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4896 "Joysticks deactivated on this screen");
4898 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4899 "Joysticks deactivated on this screen");
4903 /* create gadgets for setup input menu screen */
4904 FreeScreenGadgets();
4905 CreateScreenGadgets();
4907 /* map gadgets for setup input menu screen */
4908 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4910 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4913 FadeIn(REDRAW_FIELD);
4919 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4921 if (device_name == NULL)
4924 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4927 if (strlen(device_name) > 1)
4929 char c1 = device_name[strlen(device_name) - 1];
4930 char c2 = device_name[strlen(device_name) - 2];
4932 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4933 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4936 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4937 strlen(device_name));
4940 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4943 static struct SetupKeyboardInfo custom_key;
4950 { &custom_key.left, "Joystick Left" },
4951 { &custom_key.right, "Joystick Right" },
4952 { &custom_key.up, "Joystick Up" },
4953 { &custom_key.down, "Joystick Down" },
4954 { &custom_key.snap, "Button 1" },
4955 { &custom_key.drop, "Button 2" }
4957 static char *joystick_name[MAX_PLAYERS] =
4964 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4968 custom_key = setup.input[player_nr].key;
4970 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4971 FONT_INPUT_1_ACTIVE);
4973 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4975 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4976 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4978 if (setup.input[player_nr].use_joystick)
4980 char *device_name = setup.input[player_nr].joy.device_name;
4981 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4982 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4984 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4985 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4989 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4990 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4993 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4995 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4996 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4997 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4998 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5000 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5001 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5002 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5003 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5004 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5005 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5007 for (i = 0; i < 6; i++)
5009 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5011 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5013 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5014 (setup.input[player_nr].use_joystick ?
5016 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5020 static int input_player_nr = 0;
5022 void HandleSetupScreen_Input_Player(int step, int direction)
5024 int old_player_nr = input_player_nr;
5027 new_player_nr = old_player_nr + step * direction;
5028 if (new_player_nr < 0)
5030 if (new_player_nr > MAX_PLAYERS - 1)
5031 new_player_nr = MAX_PLAYERS - 1;
5033 if (new_player_nr != old_player_nr)
5035 input_player_nr = new_player_nr;
5037 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5041 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5043 static int choice = 0;
5046 int pos_start = SETUPINPUT_SCREEN_POS_START;
5047 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5048 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5049 int pos_end = SETUPINPUT_SCREEN_POS_END;
5051 if (button == MB_MENU_INITIALIZE)
5053 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5055 DrawCursorAndText_Setup(choice, TRUE);
5059 else if (button == MB_MENU_LEAVE)
5061 setup_mode = SETUP_MODE_MAIN;
5068 if (mx || my) /* mouse input */
5070 x = (mx - mSX) / 32;
5071 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5073 else if (dx || dy) /* keyboard input */
5075 if (dx && choice == 0)
5076 x = (dx < 0 ? 10 : 12);
5077 else if ((dx && choice == 1) ||
5078 (dx == +1 && choice == 2) ||
5079 (dx == -1 && choice == pos_end))
5080 button = MB_MENU_CHOICE;
5084 if (y >= pos_empty1 && y <= pos_empty2)
5085 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5088 if (y == 0 && dx != 0 && button)
5090 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5092 else if (IN_VIS_FIELD(x, y) &&
5093 y >= pos_start && y <= pos_end &&
5094 !(y >= pos_empty1 && y <= pos_empty2))
5100 DrawCursorAndText_Setup(choice, FALSE);
5101 DrawCursorAndText_Setup(y, TRUE);
5103 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5112 char *device_name = setup.input[input_player_nr].joy.device_name;
5114 if (!setup.input[input_player_nr].use_joystick)
5116 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5118 setJoystickDeviceToNr(device_name, new_device_nr);
5119 setup.input[input_player_nr].use_joystick = TRUE;
5123 int device_nr = getJoystickNrFromDeviceName(device_name);
5124 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5126 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5127 setup.input[input_player_nr].use_joystick = FALSE;
5129 setJoystickDeviceToNr(device_name, new_device_nr);
5132 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5136 if (setup.input[input_player_nr].use_joystick)
5139 CalibrateJoystick(input_player_nr);
5142 CustomizeKeyboard(input_player_nr);
5144 else if (y == pos_end)
5150 setup_mode = SETUP_MODE_MAIN;
5157 void CustomizeKeyboard(int player_nr)
5161 boolean finished = FALSE;
5162 static struct SetupKeyboardInfo custom_key;
5167 } customize_step[] =
5169 { &custom_key.left, "Move Left" },
5170 { &custom_key.right, "Move Right" },
5171 { &custom_key.up, "Move Up" },
5172 { &custom_key.down, "Move Down" },
5173 { &custom_key.snap, "Snap Field" },
5174 { &custom_key.drop, "Drop Element" }
5177 /* read existing key bindings from player setup */
5178 custom_key = setup.input[player_nr].key;
5181 FadeOut(REDRAW_FIELD);
5185 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5193 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5194 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5195 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5196 "Key:", FONT_INPUT_1_ACTIVE);
5197 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5198 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5201 FadeIn(REDRAW_FIELD);
5208 if (PendingEvent()) /* got event */
5216 case EVENT_KEYPRESS:
5218 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5220 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5222 if (key == KSYM_Escape)
5223 FadeSkipNextFadeIn();
5229 /* all keys configured -- wait for "Escape" or "Return" key */
5233 /* press 'Enter' to keep the existing key binding */
5234 if (key == KSYM_Return)
5235 key = *customize_step[step_nr].key;
5237 /* check if key already used */
5238 for (i = 0; i < step_nr; i++)
5239 if (*customize_step[i].key == key)
5244 /* got new key binding */
5245 *customize_step[step_nr].key = key;
5246 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5248 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5249 getKeyNameFromKey(key), FONT_VALUE_1);
5252 /* un-highlight last query */
5253 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5254 customize_step[step_nr - 1].text, FONT_MENU_1);
5255 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5256 "Key:", FONT_MENU_1);
5258 /* press 'Enter' to leave */
5261 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5262 "Press Enter", FONT_TITLE_1);
5266 /* query next key binding */
5267 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5268 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5269 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5270 "Key:", FONT_INPUT_1_ACTIVE);
5271 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5272 getKeyNameFromKey(*customize_step[step_nr].key),
5277 case EVENT_KEYRELEASE:
5278 key_joystick_mapping = 0;
5282 HandleOtherEvents(&event);
5290 /* don't eat all CPU time */
5294 /* write new key bindings back to player setup */
5295 setup.input[player_nr].key = custom_key;
5298 DrawSetupScreen_Input();
5301 static boolean CalibrateJoystickMain(int player_nr)
5303 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5304 int new_joystick_xright = JOYSTICK_XMIDDLE;
5305 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5306 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5307 int new_joystick_xmiddle, new_joystick_ymiddle;
5309 int joystick_fd = joystick.fd[player_nr];
5310 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5311 boolean check[3][3];
5312 int check_remaining = 3 * 3;
5317 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5320 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5324 FadeOut(REDRAW_FIELD);
5328 for (y = 0; y < 3; y++)
5330 for (x = 0; x < 3; x++)
5332 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5333 check[x][y] = FALSE;
5337 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5338 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5339 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5340 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5341 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5342 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5343 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5345 joy_value = Joystick(player_nr);
5346 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5347 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5349 /* eventually uncalibrated center position (joystick could be uncentered) */
5350 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5353 new_joystick_xmiddle = joy_x;
5354 new_joystick_ymiddle = joy_y;
5356 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5358 FadeIn(REDRAW_FIELD);
5360 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5365 if (PendingEvent()) /* got event */
5373 case EVENT_KEYPRESS:
5374 switch (GetEventKey((KeyEvent *)&event, TRUE))
5377 if (check_remaining == 0)
5382 FadeSkipNextFadeIn();
5391 case EVENT_KEYRELEASE:
5392 key_joystick_mapping = 0;
5396 HandleOtherEvents(&event);
5401 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5404 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5405 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5406 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5407 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5409 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5410 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5411 setup.input[player_nr].joy.xright = new_joystick_xright;
5412 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5413 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5414 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5416 CheckJoystickData();
5418 joy_value = Joystick(player_nr);
5420 if (joy_value & JOY_BUTTON && check_remaining == 0)
5423 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5424 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5426 if (x != last_x || y != last_y)
5428 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5429 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5434 if (check_remaining > 0 && !check[x+1][y+1])
5436 check[x+1][y+1] = TRUE;
5442 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5443 setup.input[player_nr].joy.xleft,
5444 setup.input[player_nr].joy.xmiddle,
5445 setup.input[player_nr].joy.xright);
5446 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5447 setup.input[player_nr].joy.yupper,
5448 setup.input[player_nr].joy.ymiddle,
5449 setup.input[player_nr].joy.ylower);
5458 /* don't eat all CPU time */
5462 /* calibrated center position (joystick should now be centered) */
5463 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5466 new_joystick_xmiddle = joy_x;
5467 new_joystick_ymiddle = joy_y;
5472 DrawSetupScreen_Input();
5475 /* wait until the last pressed button was released */
5476 while (Joystick(player_nr) & JOY_BUTTON)
5478 if (PendingEvent()) /* got event */
5483 HandleOtherEvents(&event);
5492 void CalibrateJoystick(int player_nr)
5494 if (!CalibrateJoystickMain(player_nr))
5496 char *device_name = setup.input[player_nr].joy.device_name;
5497 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5498 int xpos = mSX - SX;
5499 int ypos = mSY - SY;
5503 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5504 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5507 Delay(2000); /* show error message for a short time */
5513 DrawSetupScreen_Input();
5517 void DrawSetupScreen()
5519 DeactivateJoystick();
5521 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5523 if (setup_mode == SETUP_MODE_INPUT)
5524 DrawSetupScreen_Input();
5525 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5526 DrawChooseTree(&game_speed_current);
5527 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5528 DrawChooseTree(&screen_mode_current);
5529 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5530 DrawChooseTree(&scroll_delay_current);
5531 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5532 DrawChooseTree(&artwork.gfx_current);
5533 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5534 DrawChooseTree(&artwork.snd_current);
5535 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5536 DrawChooseTree(&artwork.mus_current);
5538 DrawSetupScreen_Generic();
5544 void RedrawSetupScreenAfterFullscreenToggle()
5546 if (setup_mode == SETUP_MODE_GRAPHICS)
5550 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5552 if (setup_mode == SETUP_MODE_INPUT)
5553 HandleSetupScreen_Input(mx, my, dx, dy, button);
5554 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5555 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5556 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5557 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5558 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5559 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5560 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5561 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5562 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5563 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5564 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5565 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5567 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5572 void HandleGameActions()
5574 if (game_status != GAME_MODE_PLAYING)
5577 GameActions(); /* main game loop */
5579 if (tape.auto_play && !tape.playing)
5580 AutoPlayTape(); /* continue automatically playing next tape */
5584 /* ---------- new screen button stuff -------------------------------------- */
5586 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5591 case SCREEN_CTRL_ID_PREV_LEVEL:
5592 *x = mSX + menu.main.button.prev_level.x;
5593 *y = mSY + menu.main.button.prev_level.y;
5596 case SCREEN_CTRL_ID_NEXT_LEVEL:
5597 *x = mSX + menu.main.button.next_level.x;
5598 *y = mSY + menu.main.button.next_level.y;
5601 case SCREEN_CTRL_ID_PREV_LEVEL:
5602 *x = mSX + TILEX * getPrevlevelButtonPos();
5603 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5606 case SCREEN_CTRL_ID_NEXT_LEVEL:
5607 *x = mSX + TILEX * getNextLevelButtonPos();
5608 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5612 case SCREEN_CTRL_ID_PREV_PLAYER:
5613 *x = mSX + TILEX * 10;
5614 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5617 case SCREEN_CTRL_ID_NEXT_PLAYER:
5618 *x = mSX + TILEX * 12;
5619 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5623 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5629 int gfx_unpressed, gfx_pressed;
5630 void (*get_gadget_position)(int *, int *, int);
5634 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5637 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5638 getScreenMenuButtonPos,
5639 SCREEN_CTRL_ID_PREV_LEVEL,
5644 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5645 getScreenMenuButtonPos,
5646 SCREEN_CTRL_ID_NEXT_LEVEL,
5651 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5652 getScreenMenuButtonPos,
5653 SCREEN_CTRL_ID_PREV_PLAYER,
5658 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5659 getScreenMenuButtonPos,
5660 SCREEN_CTRL_ID_NEXT_PLAYER,
5668 int gfx_unpressed, gfx_pressed;
5672 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5675 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5676 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5677 SCREEN_CTRL_ID_SCROLL_UP,
5681 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5682 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5683 SCREEN_CTRL_ID_SCROLL_DOWN,
5690 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5691 Bitmap **gfx_unpressed, **gfx_pressed;
5693 int gfx_unpressed, gfx_pressed;
5700 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5703 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5704 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5706 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5708 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5709 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5710 GD_TYPE_SCROLLBAR_VERTICAL,
5711 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5712 "scroll level series vertically"
5716 static void CreateScreenMenubuttons()
5718 struct GadgetInfo *gi;
5719 unsigned long event_mask;
5722 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5724 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5725 int gfx_unpressed, gfx_pressed;
5726 int x, y, width, height;
5727 int gd_x1, gd_x2, gd_y1, gd_y2;
5728 int id = menubutton_info[i].gadget_id;
5730 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5732 menubutton_info[i].get_gadget_position(&x, &y, id);
5734 width = SC_MENUBUTTON_XSIZE;
5735 height = SC_MENUBUTTON_YSIZE;
5737 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5738 gfx_pressed = menubutton_info[i].gfx_pressed;
5739 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5740 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5741 gd_x1 = graphic_info[gfx_unpressed].src_x;
5742 gd_y1 = graphic_info[gfx_unpressed].src_y;
5743 gd_x2 = graphic_info[gfx_pressed].src_x;
5744 gd_y2 = graphic_info[gfx_pressed].src_y;
5746 gi = CreateGadget(GDI_CUSTOM_ID, id,
5747 GDI_CUSTOM_TYPE_ID, i,
5748 GDI_INFO_TEXT, menubutton_info[i].infotext,
5753 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5754 GDI_STATE, GD_BUTTON_UNPRESSED,
5755 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5756 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5757 GDI_DIRECT_DRAW, FALSE,
5758 GDI_EVENT_MASK, event_mask,
5759 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5763 Error(ERR_EXIT, "cannot create gadget");
5765 screen_gadget[id] = gi;
5769 static void CreateScreenScrollbuttons()
5771 struct GadgetInfo *gi;
5772 unsigned long event_mask;
5775 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5777 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5778 int gfx_unpressed, gfx_pressed;
5779 int x, y, width, height;
5780 int gd_x1, gd_x2, gd_y1, gd_y2;
5781 int id = scrollbutton_info[i].gadget_id;
5783 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5785 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5786 y = mSY + scrollbutton_info[i].y;
5787 width = SC_SCROLLBUTTON_XSIZE;
5788 height = SC_SCROLLBUTTON_YSIZE;
5790 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5791 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5792 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5794 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5795 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5796 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5797 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5798 gd_x1 = graphic_info[gfx_unpressed].src_x;
5799 gd_y1 = graphic_info[gfx_unpressed].src_y;
5800 gd_x2 = graphic_info[gfx_pressed].src_x;
5801 gd_y2 = graphic_info[gfx_pressed].src_y;
5803 gi = CreateGadget(GDI_CUSTOM_ID, id,
5804 GDI_CUSTOM_TYPE_ID, i,
5805 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5810 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5811 GDI_STATE, GD_BUTTON_UNPRESSED,
5812 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5813 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5814 GDI_DIRECT_DRAW, FALSE,
5815 GDI_EVENT_MASK, event_mask,
5816 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5820 Error(ERR_EXIT, "cannot create gadget");
5822 screen_gadget[id] = gi;
5826 static void CreateScreenScrollbars()
5830 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5832 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5833 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5834 int gfx_unpressed, gfx_pressed;
5836 int x, y, width, height;
5837 int gd_x1, gd_x2, gd_y1, gd_y2;
5838 struct GadgetInfo *gi;
5839 int items_max, items_visible, item_position;
5840 unsigned long event_mask;
5841 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5842 int id = scrollbar_info[i].gadget_id;
5844 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5846 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5847 y = mSY + scrollbar_info[i].y;
5848 width = scrollbar_info[i].width;
5849 height = scrollbar_info[i].height;
5851 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5852 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5854 items_max = num_page_entries;
5855 items_visible = num_page_entries;
5858 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5859 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5860 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5866 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5867 gfx_pressed = scrollbar_info[i].gfx_pressed;
5868 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5869 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5870 gd_x1 = graphic_info[gfx_unpressed].src_x;
5871 gd_y1 = graphic_info[gfx_unpressed].src_y;
5872 gd_x2 = graphic_info[gfx_pressed].src_x;
5873 gd_y2 = graphic_info[gfx_pressed].src_y;
5876 gi = CreateGadget(GDI_CUSTOM_ID, id,
5877 GDI_CUSTOM_TYPE_ID, i,
5878 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5883 GDI_TYPE, scrollbar_info[i].type,
5884 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5885 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5886 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5888 GDI_WHEEL_AREA_X, SX,
5889 GDI_WHEEL_AREA_Y, SY,
5890 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5891 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5893 GDI_WHEEL_AREA_X, 0,
5894 GDI_WHEEL_AREA_Y, 0,
5895 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5896 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5898 GDI_STATE, GD_BUTTON_UNPRESSED,
5899 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5900 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5901 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5902 GDI_DIRECT_DRAW, FALSE,
5903 GDI_EVENT_MASK, event_mask,
5904 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5908 Error(ERR_EXIT, "cannot create gadget");
5910 screen_gadget[id] = gi;
5914 void CreateScreenGadgets()
5916 int last_game_status = game_status; /* save current game status */
5918 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5921 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5923 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5925 /* copy pointers to clip mask and GC */
5926 scrollbar_bitmap[i]->clip_mask =
5927 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5928 scrollbar_bitmap[i]->stored_clip_gc =
5929 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5931 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5932 scrollbar_bitmap[i],
5933 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5934 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5935 TILEX, TILEY, 0, 0);
5939 CreateScreenMenubuttons();
5942 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5943 game_status = GAME_MODE_LEVELS;
5946 CreateScreenScrollbuttons();
5947 CreateScreenScrollbars();
5949 game_status = last_game_status; /* restore current game status */
5952 void FreeScreenGadgets()
5956 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5957 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5959 /* prevent freeing clip mask and GC twice */
5960 scrollbar_bitmap[i]->clip_mask = None;
5961 scrollbar_bitmap[i]->stored_clip_gc = None;
5963 FreeBitmap(scrollbar_bitmap[i]);
5967 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5968 FreeGadget(screen_gadget[i]);
5971 void MapScreenMenuGadgets(int screen_mask)
5975 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5976 if (screen_mask & menubutton_info[i].screen_mask)
5977 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5980 void MapScreenTreeGadgets(TreeInfo *ti)
5982 int num_entries = numTreeInfoInGroup(ti);
5985 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5988 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5989 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5991 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5992 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5995 static void HandleScreenGadgets(struct GadgetInfo *gi)
5997 int id = gi->custom_id;
5998 int button = gi->event.button;
5999 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6003 case SCREEN_CTRL_ID_PREV_LEVEL:
6004 HandleMainMenu_SelectLevel(step, -1);
6007 case SCREEN_CTRL_ID_NEXT_LEVEL:
6008 HandleMainMenu_SelectLevel(step, +1);
6011 case SCREEN_CTRL_ID_PREV_PLAYER:
6012 HandleSetupScreen_Input_Player(step, -1);
6015 case SCREEN_CTRL_ID_NEXT_PLAYER:
6016 HandleSetupScreen_Input_Player(step, +1);
6019 case SCREEN_CTRL_ID_SCROLL_UP:
6020 if (game_status == GAME_MODE_LEVELS)
6021 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6022 else if (game_status == GAME_MODE_SETUP)
6023 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6026 case SCREEN_CTRL_ID_SCROLL_DOWN:
6027 if (game_status == GAME_MODE_LEVELS)
6028 HandleChooseLevel(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6029 else if (game_status == GAME_MODE_SETUP)
6030 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6033 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6034 if (game_status == GAME_MODE_LEVELS)
6035 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6036 else if (game_status == GAME_MODE_SETUP)
6037 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);