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 /* needed if last screen (level choice) changed graphics, sounds or music */
1270 ReloadCustomArtwork(0);
1272 if (redraw_mask & REDRAW_ALL)
1273 fade_mask = REDRAW_ALL;
1278 /* needed if last screen was the editor screen */
1279 UndrawSpecialEditorDoor();
1281 if (fade_mask == REDRAW_FIELD)
1286 #if defined(TARGET_SDL)
1287 SetDrawtoField(DRAW_BACKBUFFER);
1290 if (CheckTitleScreen(levelset_has_changed))
1292 game_status = GAME_MODE_TITLE;
1299 /* level_nr may have been set to value over handicap with level editor */
1300 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1301 level_nr = leveldir_current->handicap_level;
1303 LoadLevel(level_nr);
1304 LoadScore(level_nr);
1306 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1309 if (fade_mask == REDRAW_ALL)
1311 // int door_state = GetDoorState();
1315 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1321 InitializeMainControls();
1323 DrawCursorAndText_Main(-1, FALSE);
1324 DrawPreviewLevel(TRUE);
1326 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1329 if (TAPE_IS_EMPTY(tape))
1331 DrawCompleteVideoDisplay();
1336 /* create gadgets for main menu screen */
1337 FreeScreenGadgets();
1338 CreateScreenGadgets();
1340 /* map gadgets for main menu screen */
1342 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1345 if (fade_mask == REDRAW_ALL)
1347 int door_state = GetDoorState();
1349 // RedrawBackground();
1351 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1355 DrawMaskedBorder(REDRAW_ALL);
1361 /* update screen area with special editor door */
1362 redraw_mask |= REDRAW_ALL;
1366 SetMouseCursor(CURSOR_DEFAULT);
1370 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1373 void DrawAndFadeInMainMenu(int fade_mask)
1375 DrawMainMenuExt(fade_mask, TRUE);
1380 DrawMainMenuExt(REDRAW_ALL, FALSE);
1384 static void gotoTopLevelDir()
1386 /* move upwards to top level directory */
1387 while (leveldir_current->node_parent)
1389 /* write a "path" into level tree for easy navigation to last level */
1390 if (leveldir_current->node_parent->node_group->cl_first == -1)
1392 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1393 int leveldir_pos = posTreeInfo(leveldir_current);
1394 int num_page_entries;
1395 int cl_first, cl_cursor;
1397 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1398 num_page_entries = num_leveldirs;
1400 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1402 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1403 cl_cursor = leveldir_pos - cl_first;
1405 leveldir_current->node_parent->node_group->cl_first = cl_first;
1406 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1409 leveldir_current = leveldir_current->node_parent;
1414 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1416 static unsigned long title_delay = 0;
1417 static int title_screen_nr = 0;
1418 static int last_sound = -1, last_music = -1;
1419 boolean return_to_main_menu = FALSE;
1420 boolean use_fading_main_menu = TRUE;
1421 struct TitleControlInfo *tci;
1422 struct TitleFadingInfo fading_default;
1423 struct TitleFadingInfo fading_last = fading;
1424 struct TitleFadingInfo fading_next;
1427 if (button == MB_MENU_INITIALIZE)
1430 title_screen_nr = 0;
1431 tci = &title_controls[title_screen_nr];
1433 last_sound = SND_UNDEFINED;
1434 last_music = MUS_UNDEFINED;
1436 if (game_status == GAME_MODE_INFO)
1438 if (num_title_screens == 0)
1440 DrawInfoScreen_NotAvailable("Title screen information:",
1441 "No title screen for this level set.");
1446 FadeSoundsAndMusic();
1449 FadeOut(REDRAW_ALL);
1454 DrawTitleScreenImage(tci->local_nr, tci->initial);
1456 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1458 fading_default = (tci->initial ? title_initial_default : title_default);
1460 fading = fading_next = getTitleFading(tci);
1464 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1465 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1467 fading.fade_mode = FADE_MODE_FADE;
1468 fading.fade_delay = fading_default.fade_delay;
1471 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1472 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1473 fading.fade_mode = FADE_MODE_FADE;
1478 sound = getTitleSound(tci);
1479 music = getTitleMusic(tci);
1481 if (sound != last_sound)
1482 PlayMenuSoundExt(sound);
1483 if (music != last_music)
1484 PlayMenuMusicExt(music);
1490 SetMouseCursor(CURSOR_NONE);
1496 fading = fading_next;
1498 DelayReached(&title_delay, 0); /* reset delay counter */
1504 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1505 button = MB_MENU_CHOICE;
1507 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1508 button = MB_MENU_CHOICE;
1511 if (button == MB_MENU_LEAVE)
1513 return_to_main_menu = TRUE;
1514 use_fading_main_menu = FALSE;
1516 else if (button == MB_MENU_CHOICE)
1518 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1521 FadeOut(REDRAW_FIELD);
1524 FadeSetEnterScreen();
1526 info_mode = INFO_MODE_MAIN;
1527 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1533 tci = &title_controls[title_screen_nr];
1535 if (title_screen_nr < num_title_screens)
1537 sound = getTitleSound(tci);
1538 music = getTitleMusic(tci);
1540 if (sound == SND_UNDEFINED || sound != last_sound)
1542 if (music == MUS_UNDEFINED || music != last_music)
1546 FadeOut(REDRAW_ALL);
1550 DrawTitleScreenImage(tci->local_nr, tci->initial);
1552 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1554 fading_next = getTitleFading(tci);
1557 sound = getTitleSound(tci);
1558 music = getTitleMusic(tci);
1560 if (sound != last_sound)
1561 PlayMenuSoundExt(sound);
1562 if (music != last_music)
1563 PlayMenuMusicExt(music);
1570 /* last screen already faded out, next screen has no animation */
1571 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1572 fading_next.fade_mode == FADE_MODE_NONE)
1573 fading = fading_next;
1575 /* last screen already faded out, next screen has no animation */
1576 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1577 fading_next.fade_mode == FADE_MODE_NONE)
1578 fading = fading_next;
1585 fading = fading_next;
1587 DelayReached(&title_delay, 0); /* reset delay counter */
1591 FadeSoundsAndMusic();
1593 return_to_main_menu = TRUE;
1597 if (return_to_main_menu)
1603 SetMouseCursor(CURSOR_DEFAULT);
1605 if (game_status == GAME_MODE_INFO)
1608 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1611 info_mode = INFO_MODE_MAIN;
1612 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1614 else /* default: return to main menu */
1617 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1620 game_status = GAME_MODE_MAIN;
1621 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1626 void HandleMainMenu_SelectLevel(int step, int direction)
1628 int old_level_nr = level_nr;
1631 new_level_nr = old_level_nr + step * direction;
1632 if (new_level_nr < leveldir_current->first_level)
1633 new_level_nr = leveldir_current->first_level;
1634 if (new_level_nr > leveldir_current->last_level)
1635 new_level_nr = leveldir_current->last_level;
1637 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1639 /* skipping levels is only allowed when trying to skip single level */
1640 if (setup.skip_levels && step == 1 &&
1641 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1643 leveldir_current->handicap_level++;
1644 SaveLevelSetup_SeriesInfo();
1647 new_level_nr = leveldir_current->handicap_level;
1650 if (new_level_nr != old_level_nr)
1652 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1654 PlaySound(SND_MENU_ITEM_SELECTING);
1656 level_nr = new_level_nr;
1658 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1659 int2str(level_nr, menu.main.text.level_number.size),
1660 mci->pos_text->font);
1662 LoadLevel(level_nr);
1663 DrawPreviewLevel(TRUE);
1667 DrawCompleteVideoDisplay();
1669 /* needed because DrawPreviewLevel() takes some time */
1675 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1677 static int choice = MAIN_CONTROL_GAME;
1681 if (button == MB_MENU_INITIALIZE)
1683 DrawCursorAndText_Main(choice, TRUE);
1688 if (mx || my) /* mouse input */
1692 for (i = 0; main_controls[i].nr != -1; i++)
1694 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1695 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1696 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1698 pos = main_controls[i].nr;
1704 else if (dx || dy) /* keyboard input */
1706 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1707 choice == MAIN_CONTROL_SETUP))
1708 button = MB_MENU_CHOICE;
1713 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1715 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1717 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1723 PlaySound(SND_MENU_ITEM_ACTIVATING);
1725 DrawCursorAndText_Main(choice, FALSE);
1726 DrawCursorAndText_Main(pos, TRUE);
1733 PlaySound(SND_MENU_ITEM_SELECTING);
1735 if (pos == MAIN_CONTROL_NAME)
1737 game_status = GAME_MODE_PSEUDO_TYPENAME;
1739 HandleTypeName(strlen(setup.player_name), 0);
1741 else if (pos == MAIN_CONTROL_LEVELS)
1745 game_status = GAME_MODE_LEVELS;
1747 SaveLevelSetup_LastSeries();
1748 SaveLevelSetup_SeriesInfo();
1757 else if (pos == MAIN_CONTROL_SCORES)
1759 game_status = GAME_MODE_SCORES;
1763 else if (pos == MAIN_CONTROL_EDITOR)
1765 if (leveldir_current->readonly &&
1766 !strEqual(setup.player_name, "Artsoft"))
1767 Request("This level is read only !", REQ_CONFIRM);
1769 game_status = GAME_MODE_EDITOR;
1771 FadeSetEnterScreen();
1775 else if (pos == MAIN_CONTROL_INFO)
1777 game_status = GAME_MODE_INFO;
1778 info_mode = INFO_MODE_MAIN;
1782 else if (pos == MAIN_CONTROL_GAME)
1784 StartGameActions(options.network, setup.autorecord, level.random_seed);
1786 else if (pos == MAIN_CONTROL_SETUP)
1788 game_status = GAME_MODE_SETUP;
1789 setup_mode = SETUP_MODE_MAIN;
1793 else if (pos == MAIN_CONTROL_QUIT)
1795 SaveLevelSetup_LastSeries();
1796 SaveLevelSetup_SeriesInfo();
1798 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1799 game_status = GAME_MODE_QUIT;
1804 if (game_status == GAME_MODE_MAIN)
1806 DrawPreviewLevel(FALSE);
1812 /* ========================================================================= */
1813 /* info screen functions */
1814 /* ========================================================================= */
1816 static struct TokenInfo *info_info;
1817 static int num_info_info;
1819 static void execInfoTitleScreen()
1821 info_mode = INFO_MODE_TITLE;
1826 static void execInfoElements()
1828 info_mode = INFO_MODE_ELEMENTS;
1833 static void execInfoMusic()
1835 info_mode = INFO_MODE_MUSIC;
1840 static void execInfoCredits()
1842 info_mode = INFO_MODE_CREDITS;
1847 static void execInfoProgram()
1849 info_mode = INFO_MODE_PROGRAM;
1854 static void execInfoVersion()
1856 info_mode = INFO_MODE_VERSION;
1861 static void execInfoLevelSet()
1863 info_mode = INFO_MODE_LEVELSET;
1868 static void execExitInfo()
1870 game_status = GAME_MODE_MAIN;
1872 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1875 static struct TokenInfo info_info_main[] =
1877 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1878 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1879 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1880 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1881 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1882 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1883 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1884 { TYPE_EMPTY, NULL, "" },
1885 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1890 static void DrawCursorAndText_Info(int pos, boolean active)
1892 int xpos = MENU_SCREEN_START_XPOS;
1893 int ypos = MENU_SCREEN_START_YPOS + pos;
1894 int font_nr = FONT_MENU_1;
1897 font_nr = FONT_ACTIVE(font_nr);
1899 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1901 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1902 drawCursor(pos, active);
1905 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1910 CloseDoor(DOOR_CLOSE_2);
1912 /* (needed after displaying title screens which disable auto repeat) */
1913 KeyboardAutoRepeatOn();
1915 FadeSetLeaveScreen();
1922 if (fade_mask == REDRAW_ALL)
1926 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1932 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
1934 info_info = info_info_main;
1938 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
1940 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
1943 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
1944 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
1945 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
1946 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
1947 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
1948 initCursor(i, IMG_MENU_BUTTON);
1950 DrawCursorAndText_Info(i, FALSE);
1955 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
1960 DrawMaskedBorder(fade_mask);
1967 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
1969 static int choice_store[MAX_INFO_MODES];
1970 int choice = choice_store[info_mode]; /* always starts with 0 */
1974 if (button == MB_MENU_INITIALIZE)
1976 /* advance to first valid menu entry */
1977 while (choice < num_info_info &&
1978 info_info[choice].type & TYPE_SKIP_ENTRY)
1980 choice_store[info_mode] = choice;
1982 DrawCursorAndText_Info(choice, TRUE);
1986 else if (button == MB_MENU_LEAVE)
1988 for (y = 0; y < num_info_info; y++)
1990 if (info_info[y].type & TYPE_LEAVE_MENU)
1992 void (*menu_callback_function)(void) = info_info[y].value;
1996 menu_callback_function();
1998 break; /* absolutely needed because function changes 'info_info'! */
2005 if (mx || my) /* mouse input */
2007 x = (mx - mSX) / 32;
2008 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2010 else if (dx || dy) /* keyboard input */
2014 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2016 if (info_info[choice].type & menu_navigation_type ||
2017 info_info[choice].type & TYPE_ENTER_SCREEN ||
2018 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2019 info_info[choice].type & TYPE_YES_NO_AUTO)
2020 button = MB_MENU_CHOICE;
2025 /* jump to next non-empty menu entry (up or down) */
2026 while (y > 0 && y < num_info_info - 1 &&
2027 info_info[y].type & TYPE_SKIP_ENTRY)
2031 if (IN_VIS_FIELD(x, y) &&
2032 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2038 PlaySound(SND_MENU_ITEM_ACTIVATING);
2040 DrawCursorAndText_Info(choice, FALSE);
2041 DrawCursorAndText_Info(y, TRUE);
2043 choice = choice_store[info_mode] = y;
2046 else if (!(info_info[y].type & TYPE_GHOSTED))
2048 PlaySound(SND_MENU_ITEM_SELECTING);
2050 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2052 void (*menu_callback_function)(void) = info_info[choice].value;
2054 FadeSetFromType(info_info[y].type);
2056 menu_callback_function();
2062 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2064 int ystart1 = mSY - SY + 100;
2065 int ystart2 = mSY - SY + 150;
2066 int ybottom = mSY - SY + SYSIZE - 20;
2068 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2070 FadeOut(REDRAW_FIELD);
2075 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2076 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2078 DrawTextSCentered(ybottom, FONT_TEXT_4,
2079 "Press any key or button for info menu");
2081 FadeIn(REDRAW_FIELD);
2084 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2086 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2087 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2088 int xstart = mSX + 16;
2089 int ystart1 = mSY - SY + 100;
2090 int ystart2 = mSY + 64 + 2 * 32;
2091 int ybottom = mSY - SY + SYSIZE - 20;
2092 int ystep = TILEY + 4;
2093 int element, action, direction;
2101 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2102 infoscreen_step[i] = infoscreen_frame[i] = 0;
2107 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2109 DrawTextSCentered(ybottom, FONT_TEXT_4,
2110 "Press any key or button for next page");
2116 while (helpanim_info[j].element != HELPANIM_LIST_END)
2118 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2123 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2132 j += infoscreen_step[i - start];
2134 element = helpanim_info[j].element;
2135 action = helpanim_info[j].action;
2136 direction = helpanim_info[j].direction;
2139 element = EL_UNKNOWN;
2141 if (action != -1 && direction != -1)
2142 graphic = el_act_dir2img(element, action, direction);
2143 else if (action != -1)
2144 graphic = el_act2img(element, action);
2145 else if (direction != -1)
2146 graphic = el_dir2img(element, direction);
2148 graphic = el2img(element);
2150 delay = helpanim_info[j++].delay;
2155 if (infoscreen_frame[i - start] == 0)
2158 infoscreen_frame[i - start] = delay - 1;
2162 sync_frame = delay - infoscreen_frame[i - start];
2163 infoscreen_frame[i - start]--;
2166 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2168 if (!infoscreen_frame[i - start])
2169 infoscreen_step[i - start] = 0;
2173 if (!infoscreen_frame[i - start])
2174 infoscreen_step[i - start]++;
2175 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2181 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2183 DrawGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2184 graphic, sync_frame, USE_MASKING);
2187 DrawInfoScreen_HelpText(element, action, direction, i - start);
2192 redraw_mask |= REDRAW_FIELD;
2197 static char *getHelpText(int element, int action, int direction)
2199 char token[MAX_LINE_LEN];
2201 strcpy(token, element_info[element].token_name);
2204 strcat(token, element_action_info[action].suffix);
2206 if (direction != -1)
2207 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2209 return getHashEntry(helptext_info, token);
2212 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2214 int font_nr = FONT_INFO_ELEMENTS;
2215 int font_width = getFontWidth(font_nr);
2216 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2217 int sy = mSY + 65 + 2 * 32 + 1;
2218 int ystep = TILEY + 4;
2219 int pad_x = sx - SX;
2220 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2221 int max_lines_per_text = 2;
2224 if (action != -1 && direction != -1) /* element.action.direction */
2225 text = getHelpText(element, action, direction);
2227 if (text == NULL && action != -1) /* element.action */
2228 text = getHelpText(element, action, -1);
2230 if (text == NULL && direction != -1) /* element.direction */
2231 text = getHelpText(element, -1, direction);
2233 if (text == NULL) /* base element */
2234 text = getHelpText(element, -1, -1);
2236 if (text == NULL) /* not found */
2237 text = "No description available";
2239 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2240 sy += getFontHeight(font_nr) / 2;
2242 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2243 max_chars_per_line, -1, max_lines_per_text, -1,
2244 TRUE, FALSE, FALSE);
2247 void DrawInfoScreen_TitleScreen()
2252 void HandleInfoScreen_TitleScreen(int button)
2254 HandleTitleScreen(0, 0, 0, 0, button);
2257 void DrawInfoScreen_Elements()
2259 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2261 FadeOut(REDRAW_FIELD);
2266 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2268 FadeIn(REDRAW_FIELD);
2273 void HandleInfoScreen_Elements(int button)
2275 static unsigned long info_delay = 0;
2276 static int num_anims;
2277 static int num_pages;
2279 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2282 if (button == MB_MENU_INITIALIZE)
2284 boolean new_element = TRUE;
2288 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2290 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2292 else if (new_element)
2295 new_element = FALSE;
2299 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2303 if (button == MB_MENU_LEAVE)
2305 PlaySound(SND_MENU_ITEM_SELECTING);
2307 info_mode = INFO_MODE_MAIN;
2312 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2314 if (button != MB_MENU_INITIALIZE)
2316 PlaySound(SND_MENU_ITEM_SELECTING);
2321 if (page >= num_pages)
2323 FadeSoundsAndMusic();
2325 info_mode = INFO_MODE_MAIN;
2326 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2333 FadeSetNextScreen();
2336 if (button != MB_MENU_INITIALIZE)
2337 FadeOut(REDRAW_FIELD);
2339 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2341 if (button != MB_MENU_INITIALIZE)
2342 FadeIn(REDRAW_FIELD);
2346 if (DelayReached(&info_delay, GameFrameDelay))
2347 if (page < num_pages)
2348 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2350 PlayMenuSoundIfLoop();
2354 void DrawInfoScreen_Music()
2356 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2359 FadeOut(REDRAW_FIELD);
2367 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2370 FadeIn(REDRAW_FIELD);
2374 void HandleInfoScreen_Music(int button)
2376 static struct MusicFileInfo *list = NULL;
2377 int ystart1 = mSY - SY + 100;
2378 int ystart2 = mSY - SY + 150;
2379 int ybottom = mSY - SY + SYSIZE - 20;
2382 if (button == MB_MENU_INITIALIZE)
2384 list = music_file_info;
2388 FadeSoundsAndMusic();
2393 DrawTextSCentered(ystart1, FONT_TEXT_1,
2394 "No music info for this level set.");
2396 DrawTextSCentered(ybottom, FONT_TEXT_4,
2397 "Press any key or button for info menu");
2403 if (button == MB_MENU_LEAVE)
2405 PlaySound(SND_MENU_ITEM_SELECTING);
2407 FadeSoundsAndMusic();
2409 info_mode = INFO_MODE_MAIN;
2414 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2418 if (button != MB_MENU_INITIALIZE)
2420 PlaySound(SND_MENU_ITEM_SELECTING);
2428 FadeSoundsAndMusic();
2430 info_mode = INFO_MODE_MAIN;
2431 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2436 FadeSoundsAndMusic();
2439 if (list != music_file_info)
2440 FadeSetNextScreen();
2443 if (button != MB_MENU_INITIALIZE)
2444 FadeOut(REDRAW_FIELD);
2451 int sound = list->music;
2453 if (sound_info[sound].loop)
2454 PlaySoundLoop(sound);
2458 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2462 PlayMusic(list->music);
2464 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2467 if (!strEqual(list->title, UNKNOWN_NAME))
2469 if (!strEqual(list->title_header, UNKNOWN_NAME))
2470 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2472 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2475 if (!strEqual(list->artist, UNKNOWN_NAME))
2477 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2478 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2480 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2482 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2485 if (!strEqual(list->album, UNKNOWN_NAME))
2487 if (!strEqual(list->album_header, UNKNOWN_NAME))
2488 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2490 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2492 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2495 if (!strEqual(list->year, UNKNOWN_NAME))
2497 if (!strEqual(list->year_header, UNKNOWN_NAME))
2498 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2500 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2502 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2505 DrawTextSCentered(ybottom, FONT_TEXT_4,
2506 "Press any key or button for next page");
2508 if (button != MB_MENU_INITIALIZE)
2509 FadeIn(REDRAW_FIELD);
2512 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2513 PlaySoundLoop(list->music);
2516 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2518 int ystart1 = mSY - SY + 100;
2519 int ystart2 = mSY - SY + 150;
2520 int ybottom = mSY - SY + SYSIZE - 20;
2526 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2530 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2531 "Special thanks to");
2532 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2534 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2536 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2537 "\"Boulder Dash\"");
2538 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2540 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2542 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2544 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2545 "First Star Software");
2547 else if (screen_nr == 1)
2549 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2550 "Special thanks to");
2551 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2552 "Klaus Heinz & Volker Wertich");
2553 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2555 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2556 "\"Emerald Mine\"");
2557 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2559 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2561 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2563 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2566 else if (screen_nr == 2)
2568 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2569 "Special thanks to");
2570 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2571 "Michael Stopp & Philip Jespersen");
2572 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2574 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2576 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2578 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2580 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2582 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2583 "Digital Integration");
2585 else if (screen_nr == 3)
2587 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2588 "Special thanks to");
2589 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2590 "Hiroyuki Imabayashi");
2591 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2593 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2595 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2597 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2599 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2601 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2604 else if (screen_nr == 4)
2606 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2607 "Special thanks to");
2608 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2610 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2612 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2613 "Jürgen Bonhagen");
2614 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2615 "for the continuous creation");
2616 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2617 "of outstanding level sets");
2619 else if (screen_nr == 5)
2621 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2623 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2625 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2626 "for ideas and inspiration by");
2627 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2630 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2632 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2634 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2635 "for ideas and inspiration by");
2636 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2639 else if (screen_nr == 6)
2641 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2643 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2646 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2647 "for the code base used for the");
2648 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2649 "native Emerald Mine engine");
2651 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2652 "for the new Emerald Mine engine");
2655 else if (screen_nr == 7)
2657 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2659 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2661 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2662 "for the initial DOS port");
2664 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2666 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2668 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2669 "for some additional toons");
2671 else if (screen_nr == 8)
2673 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2674 "And not to forget:");
2675 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2677 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2678 "All those who contributed");
2679 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2680 "levels to this game");
2681 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2685 DrawTextSCentered(ybottom, FONT_TEXT_4,
2686 "Press any key or button for next page");
2689 void DrawInfoScreen_Credits()
2691 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2693 FadeSoundsAndMusic();
2696 FadeOut(REDRAW_FIELD);
2699 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2702 FadeIn(REDRAW_FIELD);
2706 void HandleInfoScreen_Credits(int button)
2708 static int screen_nr = 0;
2709 int num_screens = 9;
2711 if (button == MB_MENU_INITIALIZE)
2715 // DrawInfoScreen_CreditsScreen(screen_nr);
2718 if (button == MB_MENU_LEAVE)
2720 PlaySound(SND_MENU_ITEM_SELECTING);
2722 info_mode = INFO_MODE_MAIN;
2727 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2729 if (button != MB_MENU_INITIALIZE)
2731 PlaySound(SND_MENU_ITEM_SELECTING);
2736 if (screen_nr >= num_screens)
2738 FadeSoundsAndMusic();
2740 info_mode = INFO_MODE_MAIN;
2741 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2748 FadeSetNextScreen();
2751 if (button != MB_MENU_INITIALIZE)
2752 FadeOut(REDRAW_FIELD);
2754 DrawInfoScreen_CreditsScreen(screen_nr);
2756 if (button != MB_MENU_INITIALIZE)
2757 FadeIn(REDRAW_FIELD);
2761 PlayMenuSoundIfLoop();
2765 void DrawInfoScreen_Program()
2767 int ystart1 = mSY - SY + 100;
2768 int ystart2 = mSY - SY + 150;
2769 int ybottom = mSY - SY + SYSIZE - 20;
2772 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2775 FadeOut(REDRAW_FIELD);
2781 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2783 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2784 "This game is Freeware!");
2785 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2786 "If you like it, send e-mail to:");
2787 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2788 PROGRAM_EMAIL_STRING);
2789 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2790 "or SnailMail to:");
2791 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2793 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2794 "Detmolder Strasse 189");
2795 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2797 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2799 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2800 "More information and levels:");
2801 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2802 PROGRAM_WEBSITE_STRING);
2803 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2804 "If you have created new levels,");
2805 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2806 "send them to me to include them!");
2807 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2810 DrawTextSCentered(ybottom, FONT_TEXT_4,
2811 "Press any key or button for info menu");
2814 FadeIn(REDRAW_FIELD);
2818 void HandleInfoScreen_Program(int button)
2820 if (button == MB_MENU_LEAVE)
2822 PlaySound(SND_MENU_ITEM_SELECTING);
2824 info_mode = INFO_MODE_MAIN;
2829 else if (button == MB_MENU_CHOICE)
2831 PlaySound(SND_MENU_ITEM_SELECTING);
2833 FadeSoundsAndMusic();
2836 FadeOut(REDRAW_FIELD);
2839 info_mode = INFO_MODE_MAIN;
2840 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2844 PlayMenuSoundIfLoop();
2848 void DrawInfoScreen_Version()
2850 int font_header = FONT_TEXT_3;
2851 int font_text = FONT_TEXT_2;
2852 int xstep = getFontWidth(font_text);
2853 int ystep = getFontHeight(font_text);
2854 int ystart1 = mSY - SY + 100;
2855 int ystart2 = mSY - SY + 150;
2856 int ybottom = mSY - SY + SYSIZE - 20;
2857 int xstart1 = mSX + 2 * xstep;
2858 int xstart2 = mSX + 19 * xstep;
2859 #if defined(TARGET_SDL)
2860 int xstart3 = mSX + 29 * xstep;
2861 SDL_version sdl_version_compiled;
2862 const SDL_version *sdl_version_linked;
2863 int driver_name_len = 8;
2864 char driver_name[driver_name_len];
2867 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2870 FadeOut(REDRAW_FIELD);
2876 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2878 DrawTextF(xstart1, ystart2, font_header, "Name");
2879 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2882 DrawTextF(xstart1, ystart2, font_header, "Version");
2883 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
2886 DrawTextF(xstart1, ystart2, font_header, "Platform");
2887 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2890 DrawTextF(xstart1, ystart2, font_header, "Target");
2891 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2894 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2895 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2897 #if defined(TARGET_SDL)
2898 ystart2 += 3 * ystep;
2899 DrawTextF(xstart1, ystart2, font_header, "Library");
2900 DrawTextF(xstart2, ystart2, font_header, "compiled");
2901 DrawTextF(xstart3, ystart2, font_header, "linked");
2903 SDL_VERSION(&sdl_version_compiled);
2904 sdl_version_linked = SDL_Linked_Version();
2906 ystart2 += 2 * ystep;
2907 DrawTextF(xstart1, ystart2, font_text, "SDL");
2908 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2909 sdl_version_compiled.major,
2910 sdl_version_compiled.minor,
2911 sdl_version_compiled.patch);
2912 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2913 sdl_version_linked->major,
2914 sdl_version_linked->minor,
2915 sdl_version_linked->patch);
2917 SDL_IMAGE_VERSION(&sdl_version_compiled);
2918 sdl_version_linked = IMG_Linked_Version();
2921 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2922 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2923 sdl_version_compiled.major,
2924 sdl_version_compiled.minor,
2925 sdl_version_compiled.patch);
2926 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2927 sdl_version_linked->major,
2928 sdl_version_linked->minor,
2929 sdl_version_linked->patch);
2931 SDL_MIXER_VERSION(&sdl_version_compiled);
2932 sdl_version_linked = Mix_Linked_Version();
2935 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2936 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2937 sdl_version_compiled.major,
2938 sdl_version_compiled.minor,
2939 sdl_version_compiled.patch);
2940 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2941 sdl_version_linked->major,
2942 sdl_version_linked->minor,
2943 sdl_version_linked->patch);
2945 SDL_NET_VERSION(&sdl_version_compiled);
2946 sdl_version_linked = SDLNet_Linked_Version();
2949 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
2950 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2951 sdl_version_compiled.major,
2952 sdl_version_compiled.minor,
2953 sdl_version_compiled.patch);
2954 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2955 sdl_version_linked->major,
2956 sdl_version_linked->minor,
2957 sdl_version_linked->patch);
2959 ystart2 += 3 * ystep;
2960 DrawTextF(xstart1, ystart2, font_header, "Driver");
2961 DrawTextF(xstart2, ystart2, font_header, "Requested");
2962 DrawTextF(xstart3, ystart2, font_header, "Used");
2964 SDL_VideoDriverName(driver_name, driver_name_len);
2966 ystart2 += 2 * ystep;
2967 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
2968 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
2969 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2971 SDL_AudioDriverName(driver_name, driver_name_len);
2974 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
2975 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
2976 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
2979 DrawTextSCentered(ybottom, FONT_TEXT_4,
2980 "Press any key or button for info menu");
2983 FadeIn(REDRAW_FIELD);
2987 void HandleInfoScreen_Version(int button)
2989 if (button == MB_MENU_LEAVE)
2991 PlaySound(SND_MENU_ITEM_SELECTING);
2993 info_mode = INFO_MODE_MAIN;
2998 else if (button == MB_MENU_CHOICE)
3000 PlaySound(SND_MENU_ITEM_SELECTING);
3002 FadeSoundsAndMusic();
3005 FadeOut(REDRAW_FIELD);
3008 info_mode = INFO_MODE_MAIN;
3009 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3013 PlayMenuSoundIfLoop();
3017 void DrawInfoScreen_LevelSet()
3019 struct TitleMessageInfo *tmi = &readme;
3020 char *filename = getLevelSetInfoFilename();
3022 /* if chars set to "-1", automatically determine by text and font width */
3023 if (tmi->chars == -1)
3024 tmi->chars = tmi->width / getFontWidth(tmi->font);
3026 tmi->width = tmi->chars * getFontWidth(tmi->font);
3028 /* if lines set to "-1", automatically determine by text and font height */
3029 if (tmi->lines == -1)
3030 tmi->lines = tmi->height / getFontHeight(tmi->font);
3032 tmi->height = tmi->lines * getFontHeight(tmi->font);
3034 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3037 FadeOut(REDRAW_FIELD);
3043 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3045 if (filename != NULL)
3046 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3047 filename, tmi->font, tmi->chars, -1, tmi->lines, -1,
3048 tmi->autowrap, tmi->centered, tmi->parse_comments);
3050 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3051 "No information for this level set.");
3053 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3054 "Press any key or button for info menu");
3057 FadeIn(REDRAW_FIELD);
3061 void HandleInfoScreen_LevelSet(int button)
3063 if (button == MB_MENU_LEAVE)
3065 PlaySound(SND_MENU_ITEM_SELECTING);
3067 info_mode = INFO_MODE_MAIN;
3072 else if (button == MB_MENU_CHOICE)
3074 PlaySound(SND_MENU_ITEM_SELECTING);
3076 FadeSoundsAndMusic();
3079 FadeOut(REDRAW_FIELD);
3082 info_mode = INFO_MODE_MAIN;
3083 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3087 PlayMenuSoundIfLoop();
3091 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3093 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3095 if (info_mode == INFO_MODE_TITLE)
3096 DrawInfoScreen_TitleScreen();
3097 else if (info_mode == INFO_MODE_ELEMENTS)
3098 DrawInfoScreen_Elements();
3099 else if (info_mode == INFO_MODE_MUSIC)
3100 DrawInfoScreen_Music();
3101 else if (info_mode == INFO_MODE_CREDITS)
3102 DrawInfoScreen_Credits();
3103 else if (info_mode == INFO_MODE_PROGRAM)
3104 DrawInfoScreen_Program();
3105 else if (info_mode == INFO_MODE_VERSION)
3106 DrawInfoScreen_Version();
3107 else if (info_mode == INFO_MODE_LEVELSET)
3108 DrawInfoScreen_LevelSet();
3110 DrawInfoScreen_Main(fade_mask, do_fading);
3112 if (info_mode != INFO_MODE_MAIN &&
3113 info_mode != INFO_MODE_TITLE &&
3114 info_mode != INFO_MODE_MUSIC)
3121 void DrawAndFadeInInfoScreen(int fade_mask)
3123 DrawInfoScreenExt(fade_mask, TRUE);
3126 void DrawInfoScreen()
3128 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3131 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3133 if (info_mode == INFO_MODE_TITLE)
3134 HandleInfoScreen_TitleScreen(button);
3135 else if (info_mode == INFO_MODE_ELEMENTS)
3136 HandleInfoScreen_Elements(button);
3137 else if (info_mode == INFO_MODE_MUSIC)
3138 HandleInfoScreen_Music(button);
3139 else if (info_mode == INFO_MODE_CREDITS)
3140 HandleInfoScreen_Credits(button);
3141 else if (info_mode == INFO_MODE_PROGRAM)
3142 HandleInfoScreen_Program(button);
3143 else if (info_mode == INFO_MODE_VERSION)
3144 HandleInfoScreen_Version(button);
3145 else if (info_mode == INFO_MODE_LEVELSET)
3146 HandleInfoScreen_LevelSet(button);
3148 HandleInfoScreen_Main(mx, my, dx, dy, button);
3154 /* ========================================================================= */
3155 /* type name functions */
3156 /* ========================================================================= */
3158 void HandleTypeName(int newxpos, Key key)
3160 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3161 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3162 struct TextPosInfo *pos = mci->pos_input;
3163 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3164 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3165 static int xpos = 0;
3166 int font_nr = pos->font;
3167 int font_active_nr = FONT_ACTIVE(font_nr);
3168 int font_width = getFontWidth(font_active_nr);
3169 char key_char = getValidConfigValueChar(getCharFromKey(key));
3170 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3171 boolean is_active = TRUE;
3173 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3177 strcpy(last_player_name, setup.player_name);
3181 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3183 setup.player_name[xpos] = key_char;
3184 setup.player_name[xpos + 1] = 0;
3188 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3192 setup.player_name[xpos] = 0;
3194 else if (key == KSYM_Return && xpos > 0)
3200 game_status = GAME_MODE_MAIN;
3202 else if (key == KSYM_Escape)
3204 strcpy(setup.player_name, last_player_name);
3208 game_status = GAME_MODE_MAIN;
3213 pos->width = (strlen(setup.player_name) + 1) * font_width;
3214 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3216 DrawText(startx, starty, setup.player_name, font_active_nr);
3217 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3221 pos->width = strlen(setup.player_name) * font_width;
3222 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3224 DrawText(startx, starty, setup.player_name, font_nr);
3229 /* ========================================================================= */
3230 /* tree menu functions */
3231 /* ========================================================================= */
3233 static void DrawChooseTree(TreeInfo **ti_ptr)
3237 FreeScreenGadgets();
3238 CreateScreenGadgets();
3240 CloseDoor(DOOR_CLOSE_2);
3243 FadeOut(REDRAW_FIELD);
3248 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3249 MapScreenTreeGadgets(*ti_ptr);
3252 FadeIn(REDRAW_FIELD);
3258 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3260 struct GadgetInfo *gi = screen_gadget[id];
3261 int items_max, items_visible, item_position;
3263 items_max = numTreeInfoInGroup(ti);
3264 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3265 item_position = first_entry;
3267 if (item_position > items_max - items_visible)
3268 item_position = items_max - items_visible;
3270 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3271 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3272 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3275 static void drawChooseTreeList(int first_entry, int num_page_entries,
3279 char *title_string = NULL;
3280 int yoffset_sets = MENU_TITLE1_YPOS;
3281 int yoffset_setup = 16;
3282 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ? yoffset_sets :
3284 int last_game_status = game_status; /* save current game status */
3286 title_string = ti->infotext;
3288 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3291 /* force LEVELS font on artwork setup screen */
3292 game_status = GAME_MODE_LEVELS;
3296 /* clear tree list area, but not title or scrollbar */
3297 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3298 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3299 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3301 /* clear tree list area, but not title or scrollbar */
3302 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3303 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3304 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3307 for (i = 0; i < num_page_entries; i++)
3309 TreeInfo *node, *node_first;
3310 int entry_pos = first_entry + i;
3311 int xpos = MENU_SCREEN_START_XPOS;
3312 int ypos = MENU_SCREEN_START_YPOS + i;
3313 int startx = mSX + xpos * 32;
3314 int starty = mSY + ypos * 32;
3315 int font_nr = FONT_TEXT_1;
3316 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3317 int startx_text = startx + font_xoffset;
3318 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3319 int text_size = startx_scrollbar - startx_text;
3320 int max_buffer_len = text_size / getFontWidth(font_nr);
3321 char buffer[max_buffer_len + 1];
3323 node_first = getTreeInfoFirstGroupEntry(ti);
3324 node = getTreeInfoFromPos(node_first, entry_pos);
3326 strncpy(buffer, node->name, max_buffer_len);
3327 buffer[max_buffer_len] = '\0';
3329 DrawText(startx, starty, buffer, font_nr + node->color);
3331 if (node->parent_link)
3332 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3333 else if (node->level_group)
3334 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3336 initCursor(i, IMG_MENU_BUTTON);
3339 game_status = last_game_status; /* restore current game status */
3341 redraw_mask |= REDRAW_FIELD;
3344 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3346 TreeInfo *node, *node_first;
3347 int x, last_redraw_mask = redraw_mask;
3348 int ypos = MENU_TITLE2_YPOS;
3349 int font_nr = FONT_TITLE_2;
3351 if (ti->type != TREE_TYPE_LEVEL_DIR)
3354 node_first = getTreeInfoFirstGroupEntry(ti);
3355 node = getTreeInfoFromPos(node_first, entry_pos);
3357 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3359 if (node->parent_link)
3360 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3362 else if (node->level_group)
3363 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3365 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3366 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3367 node->levels, node->class_desc);
3369 /* let BackToFront() redraw only what is needed */
3370 redraw_mask = last_redraw_mask | REDRAW_TILES;
3371 for (x = 0; x < SCR_FIELDX; x++)
3372 MarkTileDirty(x, 1);
3375 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3378 TreeInfo *ti = *ti_ptr;
3380 int y = ti->cl_cursor;
3381 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3382 int num_entries = numTreeInfoInGroup(ti);
3383 int num_page_entries;
3384 int last_game_status = game_status; /* save current game status */
3385 boolean position_set_by_scrollbar = (dx == 999);
3388 /* force LEVELS draw offset on choose level and artwork setup screen */
3389 game_status = GAME_MODE_LEVELS;
3392 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3393 num_page_entries = num_entries;
3395 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3397 game_status = last_game_status; /* restore current game status */
3399 if (button == MB_MENU_INITIALIZE)
3401 int num_entries = numTreeInfoInGroup(ti);
3402 int entry_pos = posTreeInfo(ti);
3404 if (ti->cl_first == -1)
3406 /* only on initialization */
3407 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3408 ti->cl_cursor = entry_pos - ti->cl_first;
3410 else if (ti->cl_cursor >= num_page_entries ||
3411 (num_entries > num_page_entries &&
3412 num_entries - ti->cl_first < num_page_entries))
3414 /* only after change of list size (by custom graphic configuration) */
3415 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3416 ti->cl_cursor = entry_pos - ti->cl_first;
3419 if (position_set_by_scrollbar)
3422 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3425 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3426 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3427 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3431 else if (button == MB_MENU_LEAVE)
3435 PlaySound(SND_MENU_ITEM_SELECTING);
3437 if (ti->node_parent)
3439 *ti_ptr = ti->node_parent;
3440 DrawChooseTree(ti_ptr);
3442 else if (game_status == GAME_MODE_SETUP)
3444 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3446 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3447 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3448 execSetupGraphics();
3454 game_status = GAME_MODE_MAIN;
3456 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3462 if (mx || my) /* mouse input */
3464 int last_game_status = game_status; /* save current game status */
3467 /* force LEVELS draw offset on artwork setup screen */
3468 game_status = GAME_MODE_LEVELS;
3471 x = (mx - mSX) / 32;
3472 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3474 game_status = last_game_status; /* restore current game status */
3476 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3478 /* move cursor instead of scrolling when already at start/end of list */
3479 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3481 else if (dy == +1 * SCROLL_LINE &&
3482 ti->cl_first + num_page_entries == num_entries)
3485 /* handle scrolling screen one line or page */
3486 if (ti->cl_cursor + dy < 0 ||
3487 ti->cl_cursor + dy > num_page_entries - 1)
3489 if (ABS(dy) == SCROLL_PAGE)
3490 step = num_page_entries - 1;
3492 if (dy < 0 && ti->cl_first > 0)
3494 /* scroll page/line up */
3496 ti->cl_first -= step;
3497 if (ti->cl_first < 0)
3500 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3501 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3502 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3504 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3507 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3509 /* scroll page/line down */
3511 ti->cl_first += step;
3512 if (ti->cl_first + num_page_entries > num_entries)
3513 ti->cl_first = MAX(0, num_entries - num_page_entries);
3515 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3516 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3517 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3519 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3526 /* handle moving cursor one line */
3527 y = ti->cl_cursor + dy;
3532 TreeInfo *node_first, *node_cursor;
3533 int entry_pos = ti->cl_first + y;
3535 node_first = getTreeInfoFirstGroupEntry(ti);
3536 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3538 if (node_cursor->node_group)
3542 PlaySound(SND_MENU_ITEM_SELECTING);
3544 node_cursor->cl_first = ti->cl_first;
3545 node_cursor->cl_cursor = ti->cl_cursor;
3546 *ti_ptr = node_cursor->node_group;
3547 DrawChooseTree(ti_ptr);
3552 else if (dx == -1 && ti->node_parent)
3556 PlaySound(SND_MENU_ITEM_SELECTING);
3558 *ti_ptr = ti->node_parent;
3559 DrawChooseTree(ti_ptr);
3564 if (!anyScrollbarGadgetActive() &&
3565 IN_VIS_FIELD(x, y) &&
3566 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3567 y >= 0 && y < num_page_entries)
3571 if (y != ti->cl_cursor)
3573 PlaySound(SND_MENU_ITEM_ACTIVATING);
3575 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3576 drawChooseTreeCursor(y, TRUE);
3577 drawChooseTreeInfo(ti->cl_first + y, ti);
3584 TreeInfo *node_first, *node_cursor;
3585 int entry_pos = ti->cl_first + y;
3587 PlaySound(SND_MENU_ITEM_SELECTING);
3589 node_first = getTreeInfoFirstGroupEntry(ti);
3590 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3592 if (node_cursor->node_group)
3596 node_cursor->cl_first = ti->cl_first;
3597 node_cursor->cl_cursor = ti->cl_cursor;
3598 *ti_ptr = node_cursor->node_group;
3599 DrawChooseTree(ti_ptr);
3601 else if (node_cursor->parent_link)
3605 *ti_ptr = node_cursor->node_parent;
3606 DrawChooseTree(ti_ptr);
3610 FadeSetEnterScreen();
3612 node_cursor->cl_first = ti->cl_first;
3613 node_cursor->cl_cursor = ti->cl_cursor;
3614 *ti_ptr = node_cursor;
3616 if (ti->type == TREE_TYPE_LEVEL_DIR)
3618 LoadLevelSetup_SeriesInfo();
3620 SaveLevelSetup_LastSeries();
3621 SaveLevelSetup_SeriesInfo();
3625 if (game_status == GAME_MODE_SETUP)
3627 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3629 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3630 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3631 execSetupGraphics();
3637 game_status = GAME_MODE_MAIN;
3645 void DrawChooseLevel()
3647 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3649 DrawChooseTree(&leveldir_current);
3655 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
3657 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3662 void DrawHallOfFame(int highlight_position)
3665 FadeSoundsAndMusic();
3667 /* (this is needed when called from GameEnd() after winning a game) */
3668 KeyboardAutoRepeatOn();
3671 /* (this is needed when called from GameEnd() after winning a game) */
3672 SetDrawDeactivationMask(REDRAW_NONE);
3673 SetDrawBackgroundMask(REDRAW_FIELD);
3675 CloseDoor(DOOR_CLOSE_2);
3677 if (highlight_position < 0)
3678 LoadScore(level_nr);
3680 FadeSetEnterScreen();
3682 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3685 FadeOut(REDRAW_FIELD);
3693 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3696 FadeIn(REDRAW_FIELD);
3700 static void drawHallOfFameList(int first_entry, int highlight_position)
3704 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3707 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3708 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3709 "HighScores of Level %d", level_nr);
3711 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3713 int entry = first_entry + i;
3714 boolean active = (entry == highlight_position);
3715 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3716 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3717 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3718 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3719 int dx1 = 3 * getFontWidth(font_nr1);
3720 int dx2 = dx1 + getFontWidth(font_nr1);
3721 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3722 int sy = mSY + 64 + i * 32;
3724 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3725 DrawText(mSX + dx1, sy, ".", font_nr1);
3726 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3728 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3729 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3731 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3734 redraw_mask |= REDRAW_FIELD;
3737 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3739 static int first_entry = 0;
3740 static int highlight_position = 0;
3741 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3743 if (button == MB_MENU_INITIALIZE)
3746 highlight_position = mx;
3747 drawHallOfFameList(first_entry, highlight_position);
3752 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3753 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3757 if (first_entry > 0)
3759 first_entry -= step;
3760 if (first_entry < 0)
3763 drawHallOfFameList(first_entry, highlight_position);
3768 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3770 first_entry += step;
3771 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3772 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3774 drawHallOfFameList(first_entry, highlight_position);
3777 else if (button == MB_MENU_LEAVE)
3779 PlaySound(SND_MENU_ITEM_SELECTING);
3781 FadeSound(SND_BACKGROUND_SCORES);
3783 game_status = GAME_MODE_MAIN;
3787 else if (button == MB_MENU_CHOICE)
3789 PlaySound(SND_MENU_ITEM_SELECTING);
3791 FadeSound(SND_BACKGROUND_SCORES);
3794 FadeOut(REDRAW_FIELD);
3797 game_status = GAME_MODE_MAIN;
3799 DrawAndFadeInMainMenu(REDRAW_FIELD);
3802 if (game_status == GAME_MODE_SCORES)
3803 PlayMenuSoundIfLoop();
3809 /* ========================================================================= */
3810 /* setup screen functions */
3811 /* ========================================================================= */
3813 static struct TokenInfo *setup_info;
3814 static int num_setup_info;
3816 static char *screen_mode_text;
3817 static char *scroll_delay_text;
3818 static char *game_speed_text;
3819 static char *graphics_set_name;
3820 static char *sounds_set_name;
3821 static char *music_set_name;
3823 static void execSetupMain()
3825 setup_mode = SETUP_MODE_MAIN;
3830 static void execSetupGame()
3832 if (game_speeds == NULL)
3836 for (i = 0; game_speeds_list[i].value != -1; i++)
3838 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3839 char identifier[32], name[32];
3840 int value = game_speeds_list[i].value;
3841 char *text = game_speeds_list[i].text;
3843 ti->node_top = &game_speeds;
3844 ti->sort_priority = 10000 - value;
3846 sprintf(identifier, "%d", value);
3847 sprintf(name, "%s", text);
3849 setString(&ti->identifier, identifier);
3850 setString(&ti->name, name);
3851 setString(&ti->name_sorting, name);
3852 setString(&ti->infotext, "Game Speed");
3854 pushTreeInfo(&game_speeds, ti);
3857 /* sort game speed values to start with slowest game speed */
3858 sortTreeInfo(&game_speeds);
3860 /* set current game speed to configured game speed value */
3861 game_speed_current =
3862 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
3864 /* if that fails, set current game speed to reliable default value */
3865 if (game_speed_current == NULL)
3866 game_speed_current =
3867 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
3869 /* if that also fails, set current game speed to first available speed */
3870 if (game_speed_current == NULL)
3871 game_speed_current = game_speeds;
3874 setup.game_frame_delay = atoi(game_speed_current->identifier);
3876 /* needed for displaying game speed text instead of identifier */
3877 game_speed_text = game_speed_current->name;
3879 setup_mode = SETUP_MODE_GAME;
3884 static void execSetupChooseGameSpeed()
3886 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
3891 static void execSetupEditor()
3893 setup_mode = SETUP_MODE_EDITOR;
3898 static void execSetupGraphics()
3900 if (video.fullscreen_available && screen_modes == NULL)
3904 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
3906 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3907 char identifier[32], name[32];
3908 int x = video.fullscreen_modes[i].width;
3909 int y = video.fullscreen_modes[i].height;
3912 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
3914 ti->node_top = &screen_modes;
3915 ti->sort_priority = x * 10000 + y;
3917 sprintf(identifier, "%dx%d", x, y);
3918 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
3920 setString(&ti->identifier, identifier);
3921 setString(&ti->name, name);
3922 setString(&ti->name_sorting, name);
3923 setString(&ti->infotext, "Fullscreen Mode");
3925 pushTreeInfo(&screen_modes, ti);
3928 /* sort fullscreen modes to start with lowest available screen resolution */
3929 sortTreeInfo(&screen_modes);
3931 /* set current screen mode for fullscreen mode to configured setup value */
3932 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3933 setup.fullscreen_mode);
3935 /* if that fails, set current screen mode to reliable default value */
3936 if (screen_mode_current == NULL)
3937 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
3938 DEFAULT_FULLSCREEN_MODE);
3940 /* if that also fails, set current screen mode to first available mode */
3941 if (screen_mode_current == NULL)
3942 screen_mode_current = screen_modes;
3944 if (screen_mode_current == NULL)
3945 video.fullscreen_available = FALSE;
3948 if (video.fullscreen_available)
3950 setup.fullscreen_mode = screen_mode_current->identifier;
3952 /* needed for displaying screen mode name instead of identifier */
3953 screen_mode_text = screen_mode_current->name;
3957 if (scroll_delays == NULL)
3961 for (i = 0; scroll_delays_list[i].value != -1; i++)
3963 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
3964 char identifier[32], name[32];
3965 int value = scroll_delays_list[i].value;
3966 char *text = scroll_delays_list[i].text;
3968 ti->node_top = &scroll_delays;
3969 ti->sort_priority = value;
3971 sprintf(identifier, "%d", value);
3972 sprintf(name, "%s", text);
3974 setString(&ti->identifier, identifier);
3975 setString(&ti->name, name);
3976 setString(&ti->name_sorting, name);
3977 setString(&ti->infotext, "Scroll Delay");
3979 pushTreeInfo(&scroll_delays, ti);
3982 /* sort scroll delay values to start with lowest scroll delay value */
3983 sortTreeInfo(&scroll_delays);
3985 /* set current scroll delay value to configured scroll delay value */
3986 scroll_delay_current =
3987 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
3989 /* if that fails, set current scroll delay to reliable default value */
3990 if (scroll_delay_current == NULL)
3991 scroll_delay_current =
3992 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
3994 /* if that also fails, set current scroll delay to first available value */
3995 if (scroll_delay_current == NULL)
3996 scroll_delay_current = scroll_delays;
3999 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4001 /* needed for displaying scroll delay text instead of identifier */
4002 scroll_delay_text = scroll_delay_current->name;
4005 setup_mode = SETUP_MODE_GRAPHICS;
4009 static void execSetupChooseScreenMode()
4011 if (!video.fullscreen_available)
4014 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4019 static void execSetupChooseScrollDelay()
4021 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4026 static void execSetupSound()
4028 setup_mode = SETUP_MODE_SOUND;
4033 static void execSetupArtwork()
4036 printf("::: '%s', '%s', '%s'\n",
4037 artwork.gfx_current->subdir,
4038 artwork.gfx_current->fullpath,
4039 artwork.gfx_current->basepath);
4042 setup.graphics_set = artwork.gfx_current->identifier;
4043 setup.sounds_set = artwork.snd_current->identifier;
4044 setup.music_set = artwork.mus_current->identifier;
4046 /* needed if last screen (setup choice) changed graphics, sounds or music */
4047 ReloadCustomArtwork(0);
4049 /* needed for displaying artwork name instead of artwork identifier */
4050 graphics_set_name = artwork.gfx_current->name;
4051 sounds_set_name = artwork.snd_current->name;
4052 music_set_name = artwork.mus_current->name;
4054 setup_mode = SETUP_MODE_ARTWORK;
4059 static void execSetupChooseGraphics()
4061 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4066 static void execSetupChooseSounds()
4068 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4073 static void execSetupChooseMusic()
4075 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4080 static void execSetupInput()
4082 setup_mode = SETUP_MODE_INPUT;
4087 static void execSetupShortcuts()
4089 setup_mode = SETUP_MODE_SHORTCUTS;
4094 static void execSetupShortcuts1()
4096 setup_mode = SETUP_MODE_SHORTCUTS_1;
4101 static void execSetupShortcuts2()
4103 setup_mode = SETUP_MODE_SHORTCUTS_2;
4108 static void execSetupShortcuts3()
4110 setup_mode = SETUP_MODE_SHORTCUTS_3;
4115 static void execSetupShortcuts4()
4117 setup_mode = SETUP_MODE_SHORTCUTS_4;
4122 static void execExitSetup()
4124 game_status = GAME_MODE_MAIN;
4126 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4129 static void execSaveAndExitSetup()
4135 static struct TokenInfo setup_info_main[] =
4137 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4138 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4139 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4140 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4141 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4142 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4143 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4144 { TYPE_EMPTY, NULL, "" },
4145 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4146 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4151 static struct TokenInfo setup_info_game[] =
4153 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4154 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4155 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4156 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4157 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4158 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4159 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4160 { TYPE_STRING, &game_speed_text, "" },
4161 { TYPE_EMPTY, NULL, "" },
4162 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4167 static struct TokenInfo setup_info_editor[] =
4170 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4171 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4172 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4173 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4174 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4175 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4176 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4177 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4179 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4180 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4181 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4183 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4185 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4186 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4187 { TYPE_EMPTY, NULL, "" },
4189 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4190 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4191 { TYPE_EMPTY, NULL, "" },
4193 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4194 { TYPE_EMPTY, NULL, "" },
4195 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4200 static struct TokenInfo setup_info_graphics[] =
4202 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4203 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4204 { TYPE_STRING, &screen_mode_text, "" },
4206 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4208 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4209 { TYPE_STRING, &scroll_delay_text, "" },
4211 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4213 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4214 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4215 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4216 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4217 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4218 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4219 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4220 { TYPE_EMPTY, NULL, "" },
4221 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4226 static struct TokenInfo setup_info_sound[] =
4228 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4229 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4230 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4231 { TYPE_EMPTY, NULL, "" },
4232 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4237 static struct TokenInfo setup_info_artwork[] =
4239 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4240 { TYPE_STRING, &graphics_set_name, "" },
4241 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4242 { TYPE_STRING, &sounds_set_name, "" },
4243 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4244 { TYPE_STRING, &music_set_name, "" },
4245 { TYPE_EMPTY, NULL, "" },
4248 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4249 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4250 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4252 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4253 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4254 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4255 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4258 { TYPE_STRING, NULL, "Override Level Artwork:"},
4259 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4260 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4261 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4263 { TYPE_EMPTY, NULL, "" },
4264 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4269 static struct TokenInfo setup_info_input[] =
4271 { TYPE_SWITCH, NULL, "Player:" },
4272 { TYPE_SWITCH, NULL, "Device:" },
4273 { TYPE_ENTER_MENU, NULL, "" },
4274 { TYPE_EMPTY, NULL, "" },
4275 { TYPE_EMPTY, NULL, "" },
4276 { TYPE_EMPTY, NULL, "" },
4277 { TYPE_EMPTY, NULL, "" },
4278 { TYPE_EMPTY, NULL, "" },
4279 { TYPE_EMPTY, NULL, "" },
4280 { TYPE_EMPTY, NULL, "" },
4281 { TYPE_EMPTY, NULL, "" },
4282 { TYPE_EMPTY, NULL, "" },
4283 { TYPE_EMPTY, NULL, "" },
4284 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4289 static struct TokenInfo setup_info_shortcuts[] =
4291 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4292 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4293 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4294 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4295 { TYPE_EMPTY, NULL, "" },
4296 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4301 static struct TokenInfo setup_info_shortcuts_1[] =
4303 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4304 { TYPE_KEY, &setup.shortcut.save_game, "" },
4305 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4306 { TYPE_KEY, &setup.shortcut.load_game, "" },
4307 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4308 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4309 { TYPE_EMPTY, NULL, "" },
4310 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4311 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4312 { TYPE_EMPTY, NULL, "" },
4313 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4318 static struct TokenInfo setup_info_shortcuts_2[] =
4320 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4321 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4322 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4323 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4324 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4325 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4326 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4327 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4328 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4329 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4330 { TYPE_EMPTY, NULL, "" },
4331 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4336 static struct TokenInfo setup_info_shortcuts_3[] =
4338 { TYPE_KEYTEXT, NULL, "Tape Eject:", },
4339 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4340 { TYPE_KEYTEXT, NULL, "Tape Stop:", },
4341 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4342 { TYPE_KEYTEXT, NULL, "Tape Pause:", },
4343 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4344 { TYPE_KEYTEXT, NULL, "Tape Record:", },
4345 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4346 { TYPE_KEYTEXT, NULL, "Tape Play:", },
4347 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4348 { TYPE_EMPTY, NULL, "" },
4349 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4354 static struct TokenInfo setup_info_shortcuts_4[] =
4356 { TYPE_KEYTEXT, NULL, "Sound Effects (Normal):", },
4357 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4358 { TYPE_KEYTEXT, NULL, "Sound Effects (Looping):", },
4359 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4360 { TYPE_KEYTEXT, NULL, "Music:", },
4361 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4362 { TYPE_EMPTY, NULL, "" },
4363 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4368 static Key getSetupKey()
4370 Key key = KSYM_UNDEFINED;
4371 boolean got_key_event = FALSE;
4373 while (!got_key_event)
4375 if (PendingEvent()) /* got event */
4383 case EVENT_KEYPRESS:
4385 key = GetEventKey((KeyEvent *)&event, TRUE);
4387 /* press 'Escape' or 'Enter' to keep the existing key binding */
4388 if (key == KSYM_Escape || key == KSYM_Return)
4389 key = KSYM_UNDEFINED; /* keep old value */
4391 got_key_event = TRUE;
4395 case EVENT_KEYRELEASE:
4396 key_joystick_mapping = 0;
4400 HandleOtherEvents(&event);
4408 /* don't eat all CPU time */
4415 static int getSetupTextFont(int type)
4417 if (type & (TYPE_SWITCH |
4429 static int getSetupValueFont(int type, void *value)
4431 if (type & TYPE_KEY)
4432 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
4433 else if (type & TYPE_STRING)
4434 return FONT_VALUE_2;
4435 else if (type & TYPE_ECS_AGA)
4436 return FONT_VALUE_1;
4437 else if (type & TYPE_BOOLEAN_STYLE)
4438 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
4439 else if (type & TYPE_YES_NO_AUTO)
4440 return (*(int *)value == AUTO ? FONT_OPTION_ON :
4441 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
4443 return FONT_VALUE_1;
4446 static void drawSetupValue(int pos)
4448 boolean font_draw_xoffset_modified = FALSE;
4449 int font_draw_xoffset_old = -1;
4450 int xpos = MENU_SCREEN_VALUE_XPOS;
4451 int ypos = MENU_SCREEN_START_YPOS + pos;
4452 int startx = mSX + xpos * 32;
4453 int starty = mSY + ypos * 32;
4454 int font_nr, font_width, font_height;
4455 int type = setup_info[pos].type;
4456 void *value = setup_info[pos].value;
4457 char *value_string = getSetupValue(type, value);
4462 if (value_string == NULL)
4465 if (type & TYPE_KEY)
4467 xpos = MENU_SCREEN_START_XPOS;
4469 if (type & TYPE_QUERY)
4470 value_string = "<press key>";
4472 else if (type & TYPE_STRING)
4474 int max_value_len = (SCR_FIELDX - 2) * 2;
4476 xpos = MENU_SCREEN_START_XPOS;
4478 if (strlen(value_string) > max_value_len)
4479 value_string[max_value_len] = '\0';
4481 else if (type & TYPE_YES_NO_AUTO)
4483 xpos = MENU_SCREEN_VALUE_XPOS - 1;
4486 startx = mSX + xpos * 32;
4487 starty = mSY + ypos * 32;
4488 font_nr = getSetupValueFont(type, value);
4489 font_width = getFontWidth(font_nr);
4490 font_height = getFontHeight(font_nr);
4492 /* downward compatibility correction for Juergen Bonhagen's menu settings */
4493 if (setup_mode != SETUP_MODE_INPUT)
4495 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
4496 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4497 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
4498 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
4499 int text_font_nr = getSetupTextFont(FONT_MENU_2);
4500 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
4501 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
4502 boolean correct_font_draw_xoffset = FALSE;
4504 if (xpos == MENU_SCREEN_START_XPOS &&
4505 startx + font1_xoffset < text_startx + text_font_xoffset)
4506 correct_font_draw_xoffset = TRUE;
4508 if (xpos == MENU_SCREEN_VALUE_XPOS &&
4509 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
4510 correct_font_draw_xoffset = TRUE;
4512 /* check if setup value would overlap with setup text when printed */
4513 /* (this can happen for extreme/wrong values for font draw offset) */
4514 if (correct_font_draw_xoffset)
4516 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
4517 font_draw_xoffset_modified = TRUE;
4519 if (type & TYPE_KEY)
4520 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
4521 else if (!(type & TYPE_STRING))
4522 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
4523 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
4528 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
4530 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
4531 DrawText(startx + i * font_width, starty, " ", font_nr);
4534 DrawText(startx, starty, value_string, font_nr);
4536 if (font_draw_xoffset_modified)
4537 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
4540 static void changeSetupValue(int pos, int dx)
4542 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
4544 *(boolean *)setup_info[pos].value ^= TRUE;
4546 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
4548 *(int *)setup_info[pos].value =
4550 (*(int *)setup_info[pos].value == AUTO ? TRUE :
4551 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
4552 (*(int *)setup_info[pos].value == TRUE ? AUTO :
4553 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
4555 else if (setup_info[pos].type & TYPE_KEY)
4559 setup_info[pos].type |= TYPE_QUERY;
4560 drawSetupValue(pos);
4561 setup_info[pos].type &= ~TYPE_QUERY;
4563 key = getSetupKey();
4564 if (key != KSYM_UNDEFINED)
4565 *(Key *)setup_info[pos].value = key;
4568 drawSetupValue(pos);
4571 static void DrawCursorAndText_Setup(int pos, boolean active)
4573 int xpos = MENU_SCREEN_START_XPOS;
4574 int ypos = MENU_SCREEN_START_YPOS + pos;
4575 int font_nr = getSetupTextFont(setup_info[pos].type);
4577 if (setup_info == setup_info_input)
4578 font_nr = FONT_MENU_1;
4581 font_nr = FONT_ACTIVE(font_nr);
4583 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
4585 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
4586 drawCursor(pos, active);
4589 static void DrawSetupScreen_Generic()
4591 boolean redraw_all = FALSE;
4592 char *title_string = NULL;
4596 CloseDoor(DOOR_CLOSE_2);
4598 if (redraw_mask & REDRAW_ALL)
4602 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
4603 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
4604 int2str(0, redraw_mask)));
4608 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
4609 FadeOut(redraw_mask);
4611 FadeOut(REDRAW_FIELD);
4616 if (setup_mode == SETUP_MODE_MAIN)
4618 setup_info = setup_info_main;
4619 title_string = "Setup";
4621 else if (setup_mode == SETUP_MODE_GAME)
4623 setup_info = setup_info_game;
4624 title_string = "Setup Game";
4626 else if (setup_mode == SETUP_MODE_EDITOR)
4628 setup_info = setup_info_editor;
4629 title_string = "Setup Editor";
4631 else if (setup_mode == SETUP_MODE_GRAPHICS)
4633 setup_info = setup_info_graphics;
4634 title_string = "Setup Graphics";
4636 else if (setup_mode == SETUP_MODE_SOUND)
4638 setup_info = setup_info_sound;
4639 title_string = "Setup Sound";
4641 else if (setup_mode == SETUP_MODE_ARTWORK)
4643 setup_info = setup_info_artwork;
4644 title_string = "Custom Artwork";
4646 else if (setup_mode == SETUP_MODE_SHORTCUTS)
4648 setup_info = setup_info_shortcuts;
4649 title_string = "Setup Shortcuts";
4651 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
4653 setup_info = setup_info_shortcuts_1;
4654 title_string = "Setup Shortcuts";
4656 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
4658 setup_info = setup_info_shortcuts_2;
4659 title_string = "Setup Shortcuts";
4661 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
4663 setup_info = setup_info_shortcuts_3;
4664 title_string = "Setup Shortcuts";
4666 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
4668 setup_info = setup_info_shortcuts_4;
4669 title_string = "Setup Shortcuts";
4672 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
4676 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4678 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4681 void *value_ptr = setup_info[i].value;
4683 /* set some entries to "unchangeable" according to other variables */
4684 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
4685 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
4686 (value_ptr == &setup.sound_music && !audio.music_available) ||
4687 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
4688 (value_ptr == &screen_mode_text && !video.fullscreen_available))
4689 setup_info[i].type |= TYPE_GHOSTED;
4691 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4692 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4693 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4694 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4695 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4696 initCursor(i, IMG_MENU_BUTTON);
4698 DrawCursorAndText_Setup(i, FALSE);
4700 if (setup_info[i].type & TYPE_VALUE)
4707 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4708 "Joysticks deactivated in setup menu");
4712 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4716 redraw_mask = REDRAW_ALL;
4719 FadeIn(redraw_mask);
4721 FadeIn(REDRAW_FIELD);
4726 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
4730 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
4732 static int choice_store[MAX_SETUP_MODES];
4733 int choice = choice_store[setup_mode]; /* always starts with 0 */
4737 if (button == MB_MENU_INITIALIZE)
4739 /* advance to first valid menu entry */
4740 while (choice < num_setup_info &&
4741 setup_info[choice].type & TYPE_SKIP_ENTRY)
4743 choice_store[setup_mode] = choice;
4745 DrawCursorAndText_Setup(choice, TRUE);
4749 else if (button == MB_MENU_LEAVE)
4751 PlaySound(SND_MENU_ITEM_SELECTING);
4753 for (y = 0; y < num_setup_info; y++)
4755 if (setup_info[y].type & TYPE_LEAVE_MENU)
4757 void (*menu_callback_function)(void) = setup_info[y].value;
4761 menu_callback_function();
4763 break; /* absolutely needed because function changes 'setup_info'! */
4770 if (mx || my) /* mouse input */
4772 x = (mx - mSX) / 32;
4773 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4775 else if (dx || dy) /* keyboard input */
4779 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
4781 if (setup_info[choice].type & menu_navigation_type ||
4782 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
4783 setup_info[choice].type & TYPE_YES_NO_AUTO)
4784 button = MB_MENU_CHOICE;
4789 /* jump to next non-empty menu entry (up or down) */
4790 while (y > 0 && y < num_setup_info - 1 &&
4791 setup_info[y].type & TYPE_SKIP_ENTRY)
4795 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
4799 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
4801 PlaySound(SND_MENU_ITEM_ACTIVATING);
4803 DrawCursorAndText_Setup(choice, FALSE);
4804 DrawCursorAndText_Setup(y, TRUE);
4806 choice = choice_store[setup_mode] = y;
4809 else if (!(setup_info[y].type & TYPE_GHOSTED))
4811 PlaySound(SND_MENU_ITEM_SELECTING);
4813 /* when selecting key headline, execute function for key value change */
4814 if (setup_info[y].type & TYPE_KEYTEXT &&
4815 setup_info[y + 1].type & TYPE_KEY)
4818 /* when selecting string value, execute function for list selection */
4819 if (setup_info[y].type & TYPE_STRING && y > 0 &&
4820 setup_info[y - 1].type & TYPE_ENTER_LIST)
4823 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
4825 void (*menu_callback_function)(void) = setup_info[y].value;
4827 FadeSetFromType(setup_info[y].type);
4829 menu_callback_function();
4833 if (setup_info[y].type & TYPE_VALUE)
4834 changeSetupValue(y, dx);
4840 void DrawSetupScreen_Input()
4845 FadeOut(REDRAW_FIELD);
4851 setup_info = setup_info_input;
4854 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
4858 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4859 "Joysticks deactivated on this screen");
4861 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4862 "Joysticks deactivated on this screen");
4867 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
4869 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4872 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
4873 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4874 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
4875 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4876 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
4877 initCursor(i, IMG_MENU_BUTTON);
4879 DrawCursorAndText_Setup(i, FALSE);
4883 DeactivateJoystickForCalibration();
4888 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
4889 "Joysticks deactivated on this screen");
4891 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
4892 "Joysticks deactivated on this screen");
4896 /* create gadgets for setup input menu screen */
4897 FreeScreenGadgets();
4898 CreateScreenGadgets();
4900 /* map gadgets for setup input menu screen */
4901 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
4903 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
4906 FadeIn(REDRAW_FIELD);
4912 static void setJoystickDeviceToNr(char *device_name, int device_nr)
4914 if (device_name == NULL)
4917 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
4920 if (strlen(device_name) > 1)
4922 char c1 = device_name[strlen(device_name) - 1];
4923 char c2 = device_name[strlen(device_name) - 2];
4925 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
4926 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
4929 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
4930 strlen(device_name));
4933 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
4936 static struct SetupKeyboardInfo custom_key;
4943 { &custom_key.left, "Joystick Left" },
4944 { &custom_key.right, "Joystick Right" },
4945 { &custom_key.up, "Joystick Up" },
4946 { &custom_key.down, "Joystick Down" },
4947 { &custom_key.snap, "Button 1" },
4948 { &custom_key.drop, "Button 2" }
4950 static char *joystick_name[MAX_PLAYERS] =
4957 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
4961 custom_key = setup.input[player_nr].key;
4963 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
4964 FONT_INPUT_1_ACTIVE);
4966 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4968 DrawGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
4969 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
4971 if (setup.input[player_nr].use_joystick)
4973 char *device_name = setup.input[player_nr].joy.device_name;
4974 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
4975 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
4977 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
4978 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
4982 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
4983 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
4986 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
4988 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
4989 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
4990 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
4991 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
4993 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
4994 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
4995 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
4996 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
4997 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
4998 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5000 for (i = 0; i < 6; i++)
5002 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5004 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5006 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5007 (setup.input[player_nr].use_joystick ?
5009 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5013 static int input_player_nr = 0;
5015 void HandleSetupScreen_Input_Player(int step, int direction)
5017 int old_player_nr = input_player_nr;
5020 new_player_nr = old_player_nr + step * direction;
5021 if (new_player_nr < 0)
5023 if (new_player_nr > MAX_PLAYERS - 1)
5024 new_player_nr = MAX_PLAYERS - 1;
5026 if (new_player_nr != old_player_nr)
5028 input_player_nr = new_player_nr;
5030 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5034 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5036 static int choice = 0;
5039 int pos_start = SETUPINPUT_SCREEN_POS_START;
5040 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5041 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5042 int pos_end = SETUPINPUT_SCREEN_POS_END;
5044 if (button == MB_MENU_INITIALIZE)
5046 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5048 DrawCursorAndText_Setup(choice, TRUE);
5052 else if (button == MB_MENU_LEAVE)
5054 setup_mode = SETUP_MODE_MAIN;
5061 if (mx || my) /* mouse input */
5063 x = (mx - mSX) / 32;
5064 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5066 else if (dx || dy) /* keyboard input */
5068 if (dx && choice == 0)
5069 x = (dx < 0 ? 10 : 12);
5070 else if ((dx && choice == 1) ||
5071 (dx == +1 && choice == 2) ||
5072 (dx == -1 && choice == pos_end))
5073 button = MB_MENU_CHOICE;
5077 if (y >= pos_empty1 && y <= pos_empty2)
5078 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5081 if (y == 0 && dx != 0 && button)
5083 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5085 else if (IN_VIS_FIELD(x, y) &&
5086 y >= pos_start && y <= pos_end &&
5087 !(y >= pos_empty1 && y <= pos_empty2))
5093 DrawCursorAndText_Setup(choice, FALSE);
5094 DrawCursorAndText_Setup(y, TRUE);
5096 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5105 char *device_name = setup.input[input_player_nr].joy.device_name;
5107 if (!setup.input[input_player_nr].use_joystick)
5109 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5111 setJoystickDeviceToNr(device_name, new_device_nr);
5112 setup.input[input_player_nr].use_joystick = TRUE;
5116 int device_nr = getJoystickNrFromDeviceName(device_name);
5117 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5119 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5120 setup.input[input_player_nr].use_joystick = FALSE;
5122 setJoystickDeviceToNr(device_name, new_device_nr);
5125 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5129 if (setup.input[input_player_nr].use_joystick)
5132 CalibrateJoystick(input_player_nr);
5135 CustomizeKeyboard(input_player_nr);
5137 else if (y == pos_end)
5143 setup_mode = SETUP_MODE_MAIN;
5150 void CustomizeKeyboard(int player_nr)
5154 boolean finished = FALSE;
5155 static struct SetupKeyboardInfo custom_key;
5160 } customize_step[] =
5162 { &custom_key.left, "Move Left" },
5163 { &custom_key.right, "Move Right" },
5164 { &custom_key.up, "Move Up" },
5165 { &custom_key.down, "Move Down" },
5166 { &custom_key.snap, "Snap Field" },
5167 { &custom_key.drop, "Drop Element" }
5170 /* read existing key bindings from player setup */
5171 custom_key = setup.input[player_nr].key;
5174 FadeOut(REDRAW_FIELD);
5178 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5186 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5187 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5188 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5189 "Key:", FONT_INPUT_1_ACTIVE);
5190 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5191 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5194 FadeIn(REDRAW_FIELD);
5201 if (PendingEvent()) /* got event */
5209 case EVENT_KEYPRESS:
5211 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5213 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5215 if (key == KSYM_Escape)
5216 FadeSkipNextFadeIn();
5222 /* all keys configured -- wait for "Escape" or "Return" key */
5226 /* press 'Enter' to keep the existing key binding */
5227 if (key == KSYM_Return)
5228 key = *customize_step[step_nr].key;
5230 /* check if key already used */
5231 for (i = 0; i < step_nr; i++)
5232 if (*customize_step[i].key == key)
5237 /* got new key binding */
5238 *customize_step[step_nr].key = key;
5239 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5241 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5242 getKeyNameFromKey(key), FONT_VALUE_1);
5245 /* un-highlight last query */
5246 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5247 customize_step[step_nr - 1].text, FONT_MENU_1);
5248 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5249 "Key:", FONT_MENU_1);
5251 /* press 'Enter' to leave */
5254 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5255 "Press Enter", FONT_TITLE_1);
5259 /* query next key binding */
5260 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5261 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5262 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5263 "Key:", FONT_INPUT_1_ACTIVE);
5264 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5265 getKeyNameFromKey(*customize_step[step_nr].key),
5270 case EVENT_KEYRELEASE:
5271 key_joystick_mapping = 0;
5275 HandleOtherEvents(&event);
5283 /* don't eat all CPU time */
5287 /* write new key bindings back to player setup */
5288 setup.input[player_nr].key = custom_key;
5291 DrawSetupScreen_Input();
5294 static boolean CalibrateJoystickMain(int player_nr)
5296 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5297 int new_joystick_xright = JOYSTICK_XMIDDLE;
5298 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5299 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5300 int new_joystick_xmiddle, new_joystick_ymiddle;
5302 int joystick_fd = joystick.fd[player_nr];
5303 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5304 boolean check[3][3];
5305 int check_remaining = 3 * 3;
5310 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5313 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5317 FadeOut(REDRAW_FIELD);
5321 for (y = 0; y < 3; y++)
5323 for (x = 0; x < 3; x++)
5325 DrawGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5326 check[x][y] = FALSE;
5330 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5331 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5332 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5333 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5334 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5335 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5336 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5338 joy_value = Joystick(player_nr);
5339 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5340 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5342 /* eventually uncalibrated center position (joystick could be uncentered) */
5343 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5346 new_joystick_xmiddle = joy_x;
5347 new_joystick_ymiddle = joy_y;
5349 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5351 FadeIn(REDRAW_FIELD);
5353 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5358 if (PendingEvent()) /* got event */
5366 case EVENT_KEYPRESS:
5367 switch (GetEventKey((KeyEvent *)&event, TRUE))
5370 if (check_remaining == 0)
5375 FadeSkipNextFadeIn();
5384 case EVENT_KEYRELEASE:
5385 key_joystick_mapping = 0;
5389 HandleOtherEvents(&event);
5394 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5397 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5398 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5399 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5400 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5402 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5403 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5404 setup.input[player_nr].joy.xright = new_joystick_xright;
5405 setup.input[player_nr].joy.ylower = new_joystick_ylower;
5406 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
5407 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
5409 CheckJoystickData();
5411 joy_value = Joystick(player_nr);
5413 if (joy_value & JOY_BUTTON && check_remaining == 0)
5416 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5417 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5419 if (x != last_x || y != last_y)
5421 DrawGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_YELLOW, 0);
5422 DrawGraphic(xpos + x, ypos + y, IMG_MENU_CALIBRATE_RED, 0);
5427 if (check_remaining > 0 && !check[x+1][y+1])
5429 check[x+1][y+1] = TRUE;
5435 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
5436 setup.input[player_nr].joy.xleft,
5437 setup.input[player_nr].joy.xmiddle,
5438 setup.input[player_nr].joy.xright);
5439 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
5440 setup.input[player_nr].joy.yupper,
5441 setup.input[player_nr].joy.ymiddle,
5442 setup.input[player_nr].joy.ylower);
5451 /* don't eat all CPU time */
5455 /* calibrated center position (joystick should now be centered) */
5456 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5459 new_joystick_xmiddle = joy_x;
5460 new_joystick_ymiddle = joy_y;
5465 DrawSetupScreen_Input();
5468 /* wait until the last pressed button was released */
5469 while (Joystick(player_nr) & JOY_BUTTON)
5471 if (PendingEvent()) /* got event */
5476 HandleOtherEvents(&event);
5485 void CalibrateJoystick(int player_nr)
5487 if (!CalibrateJoystickMain(player_nr))
5489 char *device_name = setup.input[player_nr].joy.device_name;
5490 int nr = getJoystickNrFromDeviceName(device_name) + 1;
5491 int xpos = mSX - SX;
5492 int ypos = mSY - SY;
5496 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
5497 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
5500 Delay(2000); /* show error message for a short time */
5506 DrawSetupScreen_Input();
5510 void DrawSetupScreen()
5512 DeactivateJoystick();
5514 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5516 if (setup_mode == SETUP_MODE_INPUT)
5517 DrawSetupScreen_Input();
5518 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5519 DrawChooseTree(&game_speed_current);
5520 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5521 DrawChooseTree(&screen_mode_current);
5522 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5523 DrawChooseTree(&scroll_delay_current);
5524 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5525 DrawChooseTree(&artwork.gfx_current);
5526 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5527 DrawChooseTree(&artwork.snd_current);
5528 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5529 DrawChooseTree(&artwork.mus_current);
5531 DrawSetupScreen_Generic();
5537 void RedrawSetupScreenAfterFullscreenToggle()
5539 if (setup_mode == SETUP_MODE_GRAPHICS)
5543 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
5545 if (setup_mode == SETUP_MODE_INPUT)
5546 HandleSetupScreen_Input(mx, my, dx, dy, button);
5547 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
5548 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
5549 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
5550 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
5551 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
5552 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
5553 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
5554 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
5555 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
5556 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
5557 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
5558 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
5560 HandleSetupScreen_Generic(mx, my, dx, dy, button);
5565 void HandleGameActions()
5567 if (game_status != GAME_MODE_PLAYING)
5570 GameActions(); /* main game loop */
5572 if (tape.auto_play && !tape.playing)
5573 AutoPlayTape(); /* continue automatically playing next tape */
5577 /* ---------- new screen button stuff -------------------------------------- */
5579 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
5584 case SCREEN_CTRL_ID_PREV_LEVEL:
5585 *x = mSX + menu.main.button.prev_level.x;
5586 *y = mSY + menu.main.button.prev_level.y;
5589 case SCREEN_CTRL_ID_NEXT_LEVEL:
5590 *x = mSX + menu.main.button.next_level.x;
5591 *y = mSY + menu.main.button.next_level.y;
5594 case SCREEN_CTRL_ID_PREV_LEVEL:
5595 *x = mSX + TILEX * getPrevlevelButtonPos();
5596 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5599 case SCREEN_CTRL_ID_NEXT_LEVEL:
5600 *x = mSX + TILEX * getNextLevelButtonPos();
5601 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
5605 case SCREEN_CTRL_ID_PREV_PLAYER:
5606 *x = mSX + TILEX * 10;
5607 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5610 case SCREEN_CTRL_ID_NEXT_PLAYER:
5611 *x = mSX + TILEX * 12;
5612 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
5616 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
5622 int gfx_unpressed, gfx_pressed;
5623 void (*get_gadget_position)(int *, int *, int);
5627 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
5630 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
5631 getScreenMenuButtonPos,
5632 SCREEN_CTRL_ID_PREV_LEVEL,
5637 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
5638 getScreenMenuButtonPos,
5639 SCREEN_CTRL_ID_NEXT_LEVEL,
5644 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
5645 getScreenMenuButtonPos,
5646 SCREEN_CTRL_ID_PREV_PLAYER,
5651 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
5652 getScreenMenuButtonPos,
5653 SCREEN_CTRL_ID_NEXT_PLAYER,
5661 int gfx_unpressed, gfx_pressed;
5665 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
5668 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
5669 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
5670 SCREEN_CTRL_ID_SCROLL_UP,
5674 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
5675 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
5676 SCREEN_CTRL_ID_SCROLL_DOWN,
5683 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5684 Bitmap **gfx_unpressed, **gfx_pressed;
5686 int gfx_unpressed, gfx_pressed;
5693 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
5696 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5697 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
5699 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
5701 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
5702 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
5703 GD_TYPE_SCROLLBAR_VERTICAL,
5704 SCREEN_CTRL_ID_SCROLL_VERTICAL,
5705 "scroll level series vertically"
5709 static void CreateScreenMenubuttons()
5711 struct GadgetInfo *gi;
5712 unsigned long event_mask;
5715 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5717 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5718 int gfx_unpressed, gfx_pressed;
5719 int x, y, width, height;
5720 int gd_x1, gd_x2, gd_y1, gd_y2;
5721 int id = menubutton_info[i].gadget_id;
5723 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5725 menubutton_info[i].get_gadget_position(&x, &y, id);
5727 width = SC_MENUBUTTON_XSIZE;
5728 height = SC_MENUBUTTON_YSIZE;
5730 gfx_unpressed = menubutton_info[i].gfx_unpressed;
5731 gfx_pressed = menubutton_info[i].gfx_pressed;
5732 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5733 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5734 gd_x1 = graphic_info[gfx_unpressed].src_x;
5735 gd_y1 = graphic_info[gfx_unpressed].src_y;
5736 gd_x2 = graphic_info[gfx_pressed].src_x;
5737 gd_y2 = graphic_info[gfx_pressed].src_y;
5739 gi = CreateGadget(GDI_CUSTOM_ID, id,
5740 GDI_CUSTOM_TYPE_ID, i,
5741 GDI_INFO_TEXT, menubutton_info[i].infotext,
5746 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5747 GDI_STATE, GD_BUTTON_UNPRESSED,
5748 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5749 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5750 GDI_DIRECT_DRAW, FALSE,
5751 GDI_EVENT_MASK, event_mask,
5752 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5756 Error(ERR_EXIT, "cannot create gadget");
5758 screen_gadget[id] = gi;
5762 static void CreateScreenScrollbuttons()
5764 struct GadgetInfo *gi;
5765 unsigned long event_mask;
5768 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5770 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5771 int gfx_unpressed, gfx_pressed;
5772 int x, y, width, height;
5773 int gd_x1, gd_x2, gd_y1, gd_y2;
5774 int id = scrollbutton_info[i].gadget_id;
5776 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5778 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
5779 y = mSY + scrollbutton_info[i].y;
5780 width = SC_SCROLLBUTTON_XSIZE;
5781 height = SC_SCROLLBUTTON_YSIZE;
5783 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
5784 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
5785 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
5787 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
5788 gfx_pressed = scrollbutton_info[i].gfx_pressed;
5789 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5790 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5791 gd_x1 = graphic_info[gfx_unpressed].src_x;
5792 gd_y1 = graphic_info[gfx_unpressed].src_y;
5793 gd_x2 = graphic_info[gfx_pressed].src_x;
5794 gd_y2 = graphic_info[gfx_pressed].src_y;
5796 gi = CreateGadget(GDI_CUSTOM_ID, id,
5797 GDI_CUSTOM_TYPE_ID, i,
5798 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
5803 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5804 GDI_STATE, GD_BUTTON_UNPRESSED,
5805 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5806 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5807 GDI_DIRECT_DRAW, FALSE,
5808 GDI_EVENT_MASK, event_mask,
5809 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5813 Error(ERR_EXIT, "cannot create gadget");
5815 screen_gadget[id] = gi;
5819 static void CreateScreenScrollbars()
5823 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5825 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
5826 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5827 int gfx_unpressed, gfx_pressed;
5829 int x, y, width, height;
5830 int gd_x1, gd_x2, gd_y1, gd_y2;
5831 struct GadgetInfo *gi;
5832 int items_max, items_visible, item_position;
5833 unsigned long event_mask;
5834 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5835 int id = scrollbar_info[i].gadget_id;
5837 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5839 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
5840 y = mSY + scrollbar_info[i].y;
5841 width = scrollbar_info[i].width;
5842 height = scrollbar_info[i].height;
5844 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
5845 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
5847 items_max = num_page_entries;
5848 items_visible = num_page_entries;
5851 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5852 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
5853 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
5859 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
5860 gfx_pressed = scrollbar_info[i].gfx_pressed;
5861 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
5862 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
5863 gd_x1 = graphic_info[gfx_unpressed].src_x;
5864 gd_y1 = graphic_info[gfx_unpressed].src_y;
5865 gd_x2 = graphic_info[gfx_pressed].src_x;
5866 gd_y2 = graphic_info[gfx_pressed].src_y;
5869 gi = CreateGadget(GDI_CUSTOM_ID, id,
5870 GDI_CUSTOM_TYPE_ID, i,
5871 GDI_INFO_TEXT, scrollbar_info[i].infotext,
5876 GDI_TYPE, scrollbar_info[i].type,
5877 GDI_SCROLLBAR_ITEMS_MAX, items_max,
5878 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5879 GDI_SCROLLBAR_ITEM_POSITION, item_position,
5881 GDI_WHEEL_AREA_X, SX,
5882 GDI_WHEEL_AREA_Y, SY,
5883 GDI_WHEEL_AREA_WIDTH, SXSIZE,
5884 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
5886 GDI_WHEEL_AREA_X, 0,
5887 GDI_WHEEL_AREA_Y, 0,
5888 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
5889 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
5891 GDI_STATE, GD_BUTTON_UNPRESSED,
5892 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
5893 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
5894 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
5895 GDI_DIRECT_DRAW, FALSE,
5896 GDI_EVENT_MASK, event_mask,
5897 GDI_CALLBACK_ACTION, HandleScreenGadgets,
5901 Error(ERR_EXIT, "cannot create gadget");
5903 screen_gadget[id] = gi;
5907 void CreateScreenGadgets()
5909 int last_game_status = game_status; /* save current game status */
5911 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5914 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5916 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
5918 /* copy pointers to clip mask and GC */
5919 scrollbar_bitmap[i]->clip_mask =
5920 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
5921 scrollbar_bitmap[i]->stored_clip_gc =
5922 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
5924 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
5925 scrollbar_bitmap[i],
5926 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
5927 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
5928 TILEX, TILEY, 0, 0);
5932 CreateScreenMenubuttons();
5935 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
5936 game_status = GAME_MODE_LEVELS;
5939 CreateScreenScrollbuttons();
5940 CreateScreenScrollbars();
5942 game_status = last_game_status; /* restore current game status */
5945 void FreeScreenGadgets()
5949 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
5950 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
5952 /* prevent freeing clip mask and GC twice */
5953 scrollbar_bitmap[i]->clip_mask = None;
5954 scrollbar_bitmap[i]->stored_clip_gc = None;
5956 FreeBitmap(scrollbar_bitmap[i]);
5960 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
5961 FreeGadget(screen_gadget[i]);
5964 void MapScreenMenuGadgets(int screen_mask)
5968 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
5969 if (screen_mask & menubutton_info[i].screen_mask)
5970 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
5973 void MapScreenTreeGadgets(TreeInfo *ti)
5975 int num_entries = numTreeInfoInGroup(ti);
5978 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
5981 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
5982 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
5984 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
5985 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
5988 static void HandleScreenGadgets(struct GadgetInfo *gi)
5990 int id = gi->custom_id;
5991 int button = gi->event.button;
5992 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5996 case SCREEN_CTRL_ID_PREV_LEVEL:
5997 HandleMainMenu_SelectLevel(step, -1);
6000 case SCREEN_CTRL_ID_NEXT_LEVEL:
6001 HandleMainMenu_SelectLevel(step, +1);
6004 case SCREEN_CTRL_ID_PREV_PLAYER:
6005 HandleSetupScreen_Input_Player(step, -1);
6008 case SCREEN_CTRL_ID_NEXT_PLAYER:
6009 HandleSetupScreen_Input_Player(step, +1);
6012 case SCREEN_CTRL_ID_SCROLL_UP:
6013 if (game_status == GAME_MODE_LEVELS)
6014 HandleChooseLevel(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6015 else if (game_status == GAME_MODE_SETUP)
6016 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6019 case SCREEN_CTRL_ID_SCROLL_DOWN:
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_VERTICAL:
6027 if (game_status == GAME_MODE_LEVELS)
6028 HandleChooseLevel(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6029 else if (game_status == GAME_MODE_SETUP)
6030 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);