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 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
42 /* (should also match corresponding entries in src/conf_gfx.c) */
43 #define SETUP_MODE_MAIN 0
44 #define SETUP_MODE_GAME 1
45 #define SETUP_MODE_EDITOR 2
46 #define SETUP_MODE_GRAPHICS 3
47 #define SETUP_MODE_SOUND 4
48 #define SETUP_MODE_ARTWORK 5
49 #define SETUP_MODE_INPUT 6
50 #define SETUP_MODE_SHORTCUTS 7
51 #define SETUP_MODE_SHORTCUTS_1 8
52 #define SETUP_MODE_SHORTCUTS_2 9
53 #define SETUP_MODE_SHORTCUTS_3 10
54 #define SETUP_MODE_SHORTCUTS_4 11
55 #define SETUP_MODE_SHORTCUTS_5 12
57 /* sub-screens on the setup screen (generic) */
58 #define SETUP_MODE_CHOOSE_ARTWORK 13
59 #define SETUP_MODE_CHOOSE_OTHER 14
61 /* sub-screens on the setup screen (specific) */
62 #define SETUP_MODE_CHOOSE_GAME_SPEED 15
63 #define SETUP_MODE_CHOOSE_SCREEN_MODE 16
64 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 17
65 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
66 #define SETUP_MODE_CHOOSE_GRAPHICS 19
67 #define SETUP_MODE_CHOOSE_SOUNDS 20
68 #define SETUP_MODE_CHOOSE_MUSIC 21
69 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 22
70 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 23
71 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 24
73 #define MAX_SETUP_MODES 25
75 /* for input setup functions */
76 #define SETUPINPUT_SCREEN_POS_START 0
77 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
78 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
79 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
81 /* for various menu stuff */
82 #define MENU_SCREEN_START_XPOS 1
83 #define MENU_SCREEN_START_YPOS 2
84 #define MENU_SCREEN_VALUE_XPOS 14
85 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
86 #define MENU_TITLE1_YPOS 8
87 #define MENU_TITLE2_YPOS 46
88 #define MAX_INFO_ELEMENTS_ON_SCREEN 10
89 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
90 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
91 MENU_SCREEN_START_XPOS)
92 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
94 /* buttons and scrollbars identifiers */
95 #define SCREEN_CTRL_ID_PREV_LEVEL 0
96 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
97 #define SCREEN_CTRL_ID_PREV_PLAYER 2
98 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
99 #define SCREEN_CTRL_ID_SCROLL_UP 4
100 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
101 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
103 #define NUM_SCREEN_GADGETS 7
105 #define NUM_SCREEN_MENUBUTTONS 4
106 #define NUM_SCREEN_SCROLLBUTTONS 2
107 #define NUM_SCREEN_SCROLLBARS 1
109 #define SCREEN_MASK_MAIN (1 << 0)
110 #define SCREEN_MASK_INPUT (1 << 1)
112 /* graphic position and size values for buttons and scrollbars */
113 #define SC_MENUBUTTON_XSIZE TILEX
114 #define SC_MENUBUTTON_YSIZE TILEY
116 #define SC_SCROLLBUTTON_XSIZE TILEX
117 #define SC_SCROLLBUTTON_YSIZE TILEY
119 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
121 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
122 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
123 SC_SCROLLBUTTON_YSIZE)
125 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
126 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
128 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
129 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
130 SC_SCROLLBUTTON_YSIZE)
132 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
133 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
134 SC_SCROLL_VERTICAL_YSIZE)
136 #define SC_BORDER_SIZE 14
139 /* forward declarations of internal functions */
140 static void HandleScreenGadgets(struct GadgetInfo *);
141 static void HandleSetupScreen_Generic(int, int, int, int, int);
142 static void HandleSetupScreen_Input(int, int, int, int, int);
143 static void CustomizeKeyboard(int);
144 static void CalibrateJoystick(int);
145 static void execSetupGame(void);
146 static void execSetupGraphics(void);
147 static void execSetupSound(void);
148 static void execSetupArtwork(void);
149 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
151 static void DrawChooseLevelSet(void);
152 static void DrawChooseLevelNr(void);
153 static void DrawInfoScreen(void);
154 static void DrawAndFadeInInfoScreen(int);
155 static void DrawSetupScreen(void);
157 static void DrawInfoScreenExt(int, int);
158 static void DrawInfoScreen_NotAvailable(char *, char *);
159 static void DrawInfoScreen_HelpAnim(int, int, boolean);
160 static void DrawInfoScreen_HelpText(int, int, int, int);
161 static void HandleInfoScreen_Main(int, int, int, int, int);
162 static void HandleInfoScreen_TitleScreen(int);
163 static void HandleInfoScreen_Elements(int);
164 static void HandleInfoScreen_Music(int);
165 static void HandleInfoScreen_Credits(int);
166 static void HandleInfoScreen_Program(int);
167 static void HandleInfoScreen_Version(int);
169 static void MapScreenMenuGadgets(int);
170 static void MapScreenTreeGadgets(TreeInfo *);
172 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
174 static int info_mode = INFO_MODE_MAIN;
175 static int setup_mode = SETUP_MODE_MAIN;
177 static TreeInfo *screen_modes = NULL;
178 static TreeInfo *screen_mode_current = NULL;
180 static TreeInfo *window_sizes = NULL;
181 static TreeInfo *window_size_current = NULL;
183 static TreeInfo *scroll_delays = NULL;
184 static TreeInfo *scroll_delay_current = NULL;
186 static TreeInfo *game_speeds = NULL;
187 static TreeInfo *game_speed_current = NULL;
189 static TreeInfo *volumes_simple = NULL;
190 static TreeInfo *volume_simple_current = NULL;
192 static TreeInfo *volumes_loops = NULL;
193 static TreeInfo *volume_loops_current = NULL;
195 static TreeInfo *volumes_music = NULL;
196 static TreeInfo *volume_music_current = NULL;
198 static TreeInfo *level_number = NULL;
199 static TreeInfo *level_number_current = NULL;
205 } window_sizes_list[] =
210 { 100, "100 % (Default)" },
227 } game_speeds_list[] =
236 { 1000, "1/1s (Extremely Slow)" },
241 { 29, "1/35s (Original Supaplex)" },
243 { 20, "1/50s (Normal Speed)" },
244 { 14, "1/70s (Maximum Supaplex)" },
248 { 1, "1/1000s (Extremely Fast)" },
258 } scroll_delays_list[] =
260 { 0, "0 Tiles (No Scroll Delay)" },
263 { 3, "3 Tiles (Default)" },
268 { 8, "8 Tiles (Maximum Scroll Delay)"},
294 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
295 (s) <= GAME_MODE_SETUP ? (s) : \
296 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
297 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
299 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
300 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
301 (i) <= INFO_MODE_LEVELSET ? (i) : \
304 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
305 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
306 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
307 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
308 SETUP_MODE_CHOOSE_ARTWORK : \
309 SETUP_MODE_CHOOSE_OTHER)
311 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
312 menu.draw_xoffset[GAME_MODE_INFO] : \
313 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
314 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
315 menu.draw_yoffset[GAME_MODE_INFO] : \
316 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
318 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
319 menu.draw_xoffset[GAME_MODE_SETUP] : \
320 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
321 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
322 menu.draw_yoffset[GAME_MODE_SETUP] : \
323 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
325 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
326 DRAW_XOFFSET_INFO(info_mode) : \
327 (s) == GAME_MODE_SETUP ? \
328 DRAW_XOFFSET_SETUP(setup_mode) : \
329 menu.draw_xoffset[DRAW_MODE(s)])
330 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
331 DRAW_YOFFSET_INFO(info_mode) : \
332 (s) == GAME_MODE_SETUP ? \
333 DRAW_YOFFSET_SETUP(setup_mode) : \
334 menu.draw_yoffset[DRAW_MODE(s)])
336 #define mSX (SX + DRAW_XOFFSET(game_status))
337 #define mSY (SY + DRAW_YOFFSET(game_status))
339 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
340 menu.list_size[game_status] : \
341 MAX_MENU_ENTRIES_ON_SCREEN)
343 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
344 #define NUM_SCROLLBAR_BITMAPS 2
345 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
349 /* title display and control definitions */
351 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
352 2 * MAX_NUM_TITLE_MESSAGES)
354 static int num_title_screens = 0;
356 struct TitleControlInfo
364 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
366 /* main menu display and control definitions */
368 #define MAIN_CONTROL_NAME 0
369 #define MAIN_CONTROL_LEVELS 1
370 #define MAIN_CONTROL_SCORES 2
371 #define MAIN_CONTROL_EDITOR 3
372 #define MAIN_CONTROL_INFO 4
373 #define MAIN_CONTROL_GAME 5
374 #define MAIN_CONTROL_SETUP 6
375 #define MAIN_CONTROL_QUIT 7
376 #define MAIN_CONTROL_PREV_LEVEL 8
377 #define MAIN_CONTROL_NEXT_LEVEL 9
378 #define MAIN_CONTROL_FIRST_LEVEL 10
379 #define MAIN_CONTROL_LAST_LEVEL 11
380 #define MAIN_CONTROL_LEVEL_NUMBER 12
381 #define MAIN_CONTROL_LEVEL_INFO_1 13
382 #define MAIN_CONTROL_LEVEL_INFO_2 14
383 #define MAIN_CONTROL_LEVEL_NAME 15
384 #define MAIN_CONTROL_LEVEL_AUTHOR 16
385 #define MAIN_CONTROL_LEVEL_YEAR 17
386 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
387 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
388 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
389 #define MAIN_CONTROL_TITLE_1 21
390 #define MAIN_CONTROL_TITLE_2 22
391 #define MAIN_CONTROL_TITLE_3 23
393 static char str_main_text_name[10];
394 static char str_main_text_first_level[10];
395 static char str_main_text_last_level[10];
396 static char str_main_text_level_number[10];
398 static char *main_text_name = str_main_text_name;
399 static char *main_text_first_level = str_main_text_first_level;
400 static char *main_text_last_level = str_main_text_last_level;
401 static char *main_text_level_number = str_main_text_level_number;
402 static char *main_text_levels = "Levelset";
403 static char *main_text_scores = "Hall Of Fame";
404 static char *main_text_editor = "Level Creator";
405 static char *main_text_info = "Info Screen";
406 static char *main_text_game = "Start Game";
407 static char *main_text_setup = "Setup";
408 static char *main_text_quit = "Quit";
409 static char *main_text_level_name = level.name;
410 static char *main_text_level_author = level.author;
411 static char *main_text_level_year = NULL;
412 static char *main_text_level_imported_from = NULL;
413 static char *main_text_level_imported_by = NULL;
414 static char *main_text_level_tested_by = NULL;
415 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
416 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
417 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
419 struct MainControlInfo
423 struct MenuPosInfo *pos_button;
426 struct TextPosInfo *pos_text;
429 struct TextPosInfo *pos_input;
433 static struct MainControlInfo main_controls[] =
437 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
438 &menu.main.text.name, &main_text_name,
439 &menu.main.input.name, &setup.player_name,
443 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
444 &menu.main.text.levels, &main_text_levels,
449 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
450 &menu.main.text.scores, &main_text_scores,
455 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
456 &menu.main.text.editor, &main_text_editor,
461 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
462 &menu.main.text.info, &main_text_info,
467 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
468 &menu.main.text.game, &main_text_game,
473 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
474 &menu.main.text.setup, &main_text_setup,
479 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
480 &menu.main.text.quit, &main_text_quit,
484 /* (these two buttons are real gadgets) */
486 MAIN_CONTROL_PREV_LEVEL,
487 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
492 MAIN_CONTROL_NEXT_LEVEL,
493 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
499 MAIN_CONTROL_FIRST_LEVEL,
501 &menu.main.text.first_level, &main_text_first_level,
505 MAIN_CONTROL_LAST_LEVEL,
507 &menu.main.text.last_level, &main_text_last_level,
511 MAIN_CONTROL_LEVEL_NUMBER,
513 &menu.main.text.level_number, &main_text_level_number,
517 MAIN_CONTROL_LEVEL_INFO_1,
519 &menu.main.text.level_info_1, NULL,
523 MAIN_CONTROL_LEVEL_INFO_2,
525 &menu.main.text.level_info_2, NULL,
529 MAIN_CONTROL_LEVEL_NAME,
531 &menu.main.text.level_name, &main_text_level_name,
535 MAIN_CONTROL_LEVEL_AUTHOR,
537 &menu.main.text.level_author, &main_text_level_author,
541 MAIN_CONTROL_LEVEL_YEAR,
543 &menu.main.text.level_year, &main_text_level_year,
547 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
549 &menu.main.text.level_imported_from, &main_text_level_imported_from,
553 MAIN_CONTROL_LEVEL_IMPORTED_BY,
555 &menu.main.text.level_imported_by, &main_text_level_imported_by,
559 MAIN_CONTROL_LEVEL_TESTED_BY,
561 &menu.main.text.level_tested_by, &main_text_level_tested_by,
565 MAIN_CONTROL_TITLE_1,
567 &menu.main.text.title_1, &main_text_title_1,
571 MAIN_CONTROL_TITLE_2,
573 &menu.main.text.title_2, &main_text_title_2,
577 MAIN_CONTROL_TITLE_3,
579 &menu.main.text.title_3, &main_text_title_3,
592 static int getTitleScreenGraphic(int nr, boolean initial)
594 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
597 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
599 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
603 static int getTitleScreenGameMode(boolean initial)
605 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
609 static int getTitleMessageGameMode(boolean initial)
611 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
615 static int getTitleScreenBackground(boolean initial)
617 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
622 static int getTitleMessageBackground(int nr, boolean initial)
624 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
628 static int getTitleBackground(int nr, boolean initial, boolean is_image)
630 int base = (is_image ?
631 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
632 IMG_BACKGROUND_TITLESCREEN_1) :
633 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
634 IMG_BACKGROUND_TITLEMESSAGE_1));
635 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
636 IMG_BACKGROUND_TITLE);
637 int graphic_local = base + nr;
639 if (graphic_info[graphic_local].bitmap != NULL)
640 return graphic_local;
642 if (graphic_info[graphic_global].bitmap != NULL)
643 return graphic_global;
645 return IMG_UNDEFINED;
648 static int getTitleSound(struct TitleControlInfo *tci)
650 boolean is_image = tci->is_image;
651 int initial = tci->initial;
652 int nr = tci->local_nr;
653 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
654 int base = (is_image ?
655 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
656 SND_BACKGROUND_TITLESCREEN_1) :
657 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
658 SND_BACKGROUND_TITLEMESSAGE_1));
659 int sound_global = menu.sound[mode];
660 int sound_local = base + nr;
663 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
664 nr, initial, is_image,
665 sound_global, getSoundListEntry(sound_global)->filename,
666 sound_local, getSoundListEntry(sound_local)->filename);
669 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
672 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
675 return SND_UNDEFINED;
678 static int getTitleMusic(struct TitleControlInfo *tci)
680 boolean is_image = tci->is_image;
681 int initial = tci->initial;
682 int nr = tci->local_nr;
683 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
684 int base = (is_image ?
685 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
686 MUS_BACKGROUND_TITLESCREEN_1) :
687 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
688 MUS_BACKGROUND_TITLEMESSAGE_1));
689 int music_global = menu.music[mode];
690 int music_local = base + nr;
693 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
694 nr, initial, is_image,
695 music_global, getMusicListEntry(music_global)->filename,
696 music_local, getMusicListEntry(music_local)->filename);
699 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
702 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
705 return MUS_UNDEFINED;
708 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
710 boolean is_image = tci->is_image;
711 int initial = tci->initial;
712 int nr = tci->local_nr;
713 struct TitleFadingInfo ti;
717 int graphic = getTitleScreenGraphic(nr, initial);
719 /* initialize fading control values to default title config settings */
720 ti = (initial ? title_initial_default : title_default);
722 /* override default settings with image config settings, if defined */
723 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
724 ti.fade_mode = graphic_info[graphic].fade_mode;
725 if (graphic_info[graphic].fade_delay > -1)
726 ti.fade_delay = graphic_info[graphic].fade_delay;
727 if (graphic_info[graphic].post_delay > -1)
728 ti.post_delay = graphic_info[graphic].post_delay;
729 if (graphic_info[graphic].auto_delay > -1)
730 ti.auto_delay = graphic_info[graphic].auto_delay;
736 ti.fade_mode = titlemessage_initial[nr].fade_mode;
737 ti.fade_delay = titlemessage_initial[nr].fade_delay;
738 ti.post_delay = titlemessage_initial[nr].post_delay;
739 ti.auto_delay = titlemessage_initial[nr].auto_delay;
743 ti.fade_mode = titlemessage[nr].fade_mode;
744 ti.fade_delay = titlemessage[nr].fade_delay;
745 ti.post_delay = titlemessage[nr].post_delay;
746 ti.auto_delay = titlemessage[nr].auto_delay;
751 if (ti.anim_mode == ANIM_NONE)
752 ti.fade_delay = ti.post_delay = 0;
758 static int compareTitleControlInfo(const void *object1, const void *object2)
760 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
761 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
764 if (tci1->initial != tci2->initial)
765 compare_result = (tci1->initial ? -1 : +1);
766 else if (tci1->sort_priority != tci2->sort_priority)
767 compare_result = tci1->sort_priority - tci2->sort_priority;
768 else if (tci1->is_image != tci2->is_image)
769 compare_result = (tci1->is_image ? -1 : +1);
771 compare_result = tci1->local_nr - tci2->local_nr;
773 return compare_result;
776 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
778 int nr, int sort_priority)
780 title_controls[num_title_screens].is_image = is_image;
781 title_controls[num_title_screens].initial = initial;
782 title_controls[num_title_screens].local_nr = nr;
783 title_controls[num_title_screens].sort_priority = sort_priority;
788 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
792 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
794 int graphic = getTitleScreenGraphic(i, initial);
795 Bitmap *bitmap = graphic_info[graphic].bitmap;
796 int sort_priority = graphic_info[graphic].sort_priority;
799 /* skip images and messages (fonts!) when using forced custom graphics */
800 if (setup.override_level_graphics && !initial)
805 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
808 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
810 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
811 char *filename = getLevelSetTitleMessageFilename(i, initial);
812 int sort_priority = tmi->sort_priority;
815 /* skip images and messages (fonts!) when using forced custom graphics */
816 if (setup.override_level_graphics)
820 if (filename != NULL)
821 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
825 static void InitializeTitleControls(boolean show_title_initial)
827 num_title_screens = 0;
830 /* 1st step: initialize title screens for game start (only when starting) */
831 if (show_title_initial)
832 InitializeTitleControls_CheckTitleInfo(TRUE);
835 /* 2nd step: initialize title screens for current level set */
836 InitializeTitleControls_CheckTitleInfo(FALSE);
838 /* sort title screens according to sort_priority and title number */
839 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
840 compareTitleControlInfo);
843 static boolean visibleMenuPos(struct MenuPosInfo *pos)
845 return (pos != NULL && pos->x != -1 && pos->y != -1);
848 static boolean visibleTextPos(struct TextPosInfo *pos)
850 return (pos != NULL && pos->x != -1 && pos->y != -1);
853 static void InitializeMainControls()
855 boolean local_team_mode = (!options.network && setup.team_mode);
858 /* set main control text values to dynamically determined values */
859 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
861 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
862 menu.main.text.first_level.size));
863 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
864 menu.main.text.last_level.size));
865 strcpy(main_text_level_number, int2str(level_nr,
866 menu.main.text.level_number.size));
868 main_text_level_year = leveldir_current->year;
869 main_text_level_imported_from = leveldir_current->imported_from;
870 main_text_level_imported_by = leveldir_current->imported_by;
871 main_text_level_tested_by = leveldir_current->tested_by;
873 /* set main control screen positions to dynamically determined values */
874 for (i = 0; main_controls[i].nr != -1; i++)
876 struct MainControlInfo *mci = &main_controls[i];
878 struct MenuPosInfo *pos_button = mci->pos_button;
879 struct TextPosInfo *pos_text = mci->pos_text;
880 struct TextPosInfo *pos_input = mci->pos_input;
881 char *text = (mci->text ? *mci->text : NULL);
882 char *input = (mci->input ? *mci->input : NULL);
883 int button_graphic = mci->button_graphic;
885 int font_text = (pos_text ? pos_text->font : -1);
886 int font_input = (pos_input ? pos_input->font : -1);
888 int font_text = mci->font_text;
889 int font_input = mci->font_input;
892 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
893 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
894 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
895 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
896 int text_chars = (text != NULL ? strlen(text) : 0);
897 int input_chars = (input != NULL ? strlen(input) : 0);
900 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
902 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
903 int text_width = font_text_width * text_chars;
904 int text_height = font_text_height;
905 int input_width = font_input_width * input_chars;
906 int input_height = font_input_height;
908 if (nr == MAIN_CONTROL_NAME)
911 if (menu.main.input.name.x == -1)
912 menu.main.input.name.x = menu.main.text.name.x + text_width;
913 if (menu.main.input.name.y == -1)
914 menu.main.input.name.y = menu.main.text.name.y;
918 menu.main.input.name.width = input_width;
919 menu.main.input.name.height = input_height;
921 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
922 menu.main.input.name.height = font_input_height;
926 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
928 if (pos_button->width == 0)
929 pos_button->width = button_width;
930 if (pos_button->height == 0)
931 pos_button->height = button_height;
934 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
937 /* calculate size for non-clickable text -- needed for text alignment */
938 boolean calculate_text_size = (pos_button == NULL && text != NULL);
940 /* calculate width for non-clickable text -- needed for text alignment */
941 boolean calculate_text_width = (pos_button == NULL && text != NULL);
944 if (visibleMenuPos(pos_button))
946 if (pos_text->x == -1)
947 pos_text->x = pos_button->x + pos_button->width;
948 if (pos_text->y == -1)
949 pos_text->y = pos_button->y;
953 if (pos_text->width == -1 || calculate_text_size)
954 pos_text->width = text_width;
955 if (pos_text->height == -1 || calculate_text_size)
956 pos_text->height = text_height;
958 if (pos_text->width == -1 || calculate_text_width)
959 pos_text->width = text_width;
960 if (pos_text->height == -1)
961 pos_text->height = text_height;
965 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
967 if (visibleTextPos(pos_text))
969 if (pos_input->x == -1)
970 pos_input->x = pos_text->x + pos_text->width;
971 if (pos_input->y == -1)
972 pos_input->y = pos_text->y;
975 if (pos_input->width == -1)
976 pos_input->width = input_width;
977 if (pos_input->height == -1)
978 pos_input->height = input_height;
983 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
984 boolean active_input)
988 for (i = 0; main_controls[i].nr != -1; i++)
990 struct MainControlInfo *mci = &main_controls[i];
992 if (mci->nr == nr || nr == -1)
994 struct MenuPosInfo *pos_button = mci->pos_button;
995 struct TextPosInfo *pos_text = mci->pos_text;
996 struct TextPosInfo *pos_input = mci->pos_input;
997 char *text = (mci->text ? *mci->text : NULL);
998 char *input = (mci->input ? *mci->input : NULL);
999 int button_graphic = mci->button_graphic;
1001 int font_text = (pos_text ? pos_text->font : -1);
1002 int font_input = (pos_input ? pos_input->font : -1);
1004 int font_text = mci->font_text;
1005 int font_input = mci->font_input;
1010 button_graphic = BUTTON_ACTIVE(button_graphic);
1011 font_text = FONT_ACTIVE(font_text);
1016 font_input = FONT_ACTIVE(font_input);
1019 if (visibleMenuPos(pos_button))
1021 struct MenuPosInfo *pos = pos_button;
1022 int x = mSX + pos->x;
1023 int y = mSY + pos->y;
1025 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1026 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1029 if (visibleTextPos(pos_text) && text != NULL)
1031 struct TextPosInfo *pos = pos_text;
1032 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1033 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1036 /* (check why/if this is needed) */
1037 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1039 DrawText(x, y, text, font_text);
1042 if (visibleTextPos(pos_input) && input != NULL)
1044 struct TextPosInfo *pos = pos_input;
1045 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1046 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1049 /* (check why/if this is needed) */
1050 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1052 DrawText(x, y, input, font_input);
1058 static void DrawCursorAndText_Main(int nr, boolean active_text)
1060 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1064 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1066 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1070 static struct MainControlInfo *getMainControlInfo(int nr)
1074 for (i = 0; main_controls[i].nr != -1; i++)
1075 if (main_controls[i].nr == nr)
1076 return &main_controls[i];
1081 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1086 int rect_x = ALIGNED_TEXT_XPOS(rect);
1087 int rect_y = ALIGNED_TEXT_YPOS(rect);
1089 return (x >= rect_x && x < rect_x + rect->width &&
1090 y >= rect_y && y < rect_y + rect->height);
1093 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1098 int rect_x = ALIGNED_TEXT_XPOS(rect);
1099 int rect_y = ALIGNED_TEXT_YPOS(rect);
1102 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1103 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1104 (x >= rect_x && x < rect_x + rect->width &&
1105 y >= rect_y && y < rect_y + rect->height));
1108 return (x >= rect_x && x < rect_x + rect->width &&
1109 y >= rect_y && y < rect_y + rect->height);
1112 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1115 static int cursor_array[MAX_LEV_FIELDY];
1117 static int cursor_array[SCR_FIELDY];
1119 int x = mSX + TILEX * xpos;
1120 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1125 cursor_array[ypos] = graphic;
1127 graphic = cursor_array[ypos];
1131 graphic = BUTTON_ACTIVE(graphic);
1133 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1134 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1137 static void initCursor(int ypos, int graphic)
1139 drawCursorExt(0, ypos, FALSE, graphic);
1142 static void drawCursor(int ypos, boolean active)
1144 drawCursorExt(0, ypos, active, -1);
1147 static void drawCursorXY(int xpos, int ypos, int graphic)
1149 drawCursorExt(xpos, ypos, FALSE, graphic);
1152 static void drawChooseTreeCursor(int ypos, boolean active)
1154 int last_game_status = game_status; /* save current game status */
1157 /* force LEVELS draw offset on artwork setup screen */
1158 game_status = GAME_MODE_LEVELS;
1161 drawCursorExt(0, ypos, active, -1);
1163 game_status = last_game_status; /* restore current game status */
1168 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1169 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1173 static int getPrevlevelButtonPos()
1178 static int getCurrentLevelTextPos()
1180 return (getPrevlevelButtonPos() + 1);
1183 static int getNextLevelButtonPos()
1185 return getPrevlevelButtonPos() + 3 + 1;
1188 static int getLevelRangeTextPos()
1190 return getNextLevelButtonPos() + 1;
1194 int effectiveGameStatus()
1196 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1197 return GAME_MODE_TITLE;
1202 void DrawTitleScreenImage(int nr, boolean initial)
1204 int graphic = getTitleScreenGraphic(nr, initial);
1205 Bitmap *bitmap = graphic_info[graphic].bitmap;
1206 int width = graphic_info[graphic].width;
1207 int height = graphic_info[graphic].height;
1208 int src_x = graphic_info[graphic].src_x;
1209 int src_y = graphic_info[graphic].src_y;
1215 if (width > WIN_XSIZE)
1217 /* image width too large for window => center image horizontally */
1218 src_x = (width - WIN_XSIZE) / 2;
1222 if (height > WIN_YSIZE)
1224 /* image height too large for window => center image vertically */
1225 src_y = (height - WIN_YSIZE) / 2;
1229 /* always display title screens centered */
1230 dst_x = (WIN_XSIZE - width) / 2;
1231 dst_y = (WIN_YSIZE - height) / 2;
1233 SetDrawBackgroundMask(REDRAW_ALL);
1234 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1236 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1238 if (DrawingOnBackground(dst_x, dst_y))
1240 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1241 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1244 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1246 redraw_mask = REDRAW_ALL;
1249 void DrawTitleScreenMessage(int nr, boolean initial)
1251 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1252 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1253 int last_game_status = game_status; /* save current game status */
1255 if (filename == NULL)
1258 /* force TITLE font on title message screen */
1259 game_status = getTitleMessageGameMode(initial);
1261 /* if chars set to "-1", automatically determine by text and font width */
1262 if (tmi->chars == -1)
1263 tmi->chars = tmi->width / getFontWidth(tmi->font);
1265 tmi->width = tmi->chars * getFontWidth(tmi->font);
1267 /* if lines set to "-1", automatically determine by text and font height */
1268 if (tmi->lines == -1)
1269 tmi->lines = tmi->height / getFontHeight(tmi->font);
1271 tmi->height = tmi->lines * getFontHeight(tmi->font);
1273 SetDrawBackgroundMask(REDRAW_ALL);
1274 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1276 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1278 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1279 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1280 tmi->autowrap, tmi->centered, tmi->parse_comments);
1282 game_status = last_game_status; /* restore current game status */
1285 void DrawTitleScreen()
1287 KeyboardAutoRepeatOff();
1290 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1293 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1298 boolean CheckTitleScreen(boolean levelset_has_changed)
1300 static boolean show_title_initial = TRUE;
1301 boolean show_titlescreen = FALSE;
1303 /* needed to be able to skip title screen, if no image or message defined */
1304 InitializeTitleControls(show_title_initial);
1306 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1307 show_titlescreen = TRUE;
1309 /* show initial title images and messages only once at program start */
1310 show_title_initial = FALSE;
1312 return (show_titlescreen && num_title_screens > 0);
1315 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1317 static LevelDirTree *leveldir_last_valid = NULL;
1318 boolean levelset_has_changed = FALSE;
1320 LimitScreenUpdates(FALSE);
1322 FadeSetLeaveScreen();
1324 /* do not fade out here -- function may continue and fade on editor screen */
1327 FadeSoundsAndMusic();
1329 KeyboardAutoRepeatOn();
1332 SetDrawDeactivationMask(REDRAW_NONE);
1333 SetDrawBackgroundMask(REDRAW_FIELD);
1335 audio.sound_deactivated = FALSE;
1339 /* needed if last screen was the playing screen, invoked from level editor */
1340 if (level_editor_test_game)
1342 game_status = GAME_MODE_EDITOR;
1348 /* needed if last screen was the setup screen and fullscreen state changed */
1349 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1350 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1352 /* leveldir_current may be invalid (level group, parent link) */
1353 if (!validLevelSeries(leveldir_current))
1354 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1356 if (leveldir_current != leveldir_last_valid)
1357 levelset_has_changed = TRUE;
1359 /* store valid level series information */
1360 leveldir_last_valid = leveldir_current;
1362 init_last = init; /* switch to new busy animation */
1364 /* needed if last screen (level choice) changed graphics, sounds or music */
1365 ReloadCustomArtwork(0);
1367 if (redraw_mask & REDRAW_ALL)
1368 fade_mask = REDRAW_ALL;
1373 /* needed if last screen was the editor screen */
1374 UndrawSpecialEditorDoor();
1376 if (fade_mask == REDRAW_FIELD)
1382 /* needed if different viewport properties defined for menues */
1383 ChangeViewportPropertiesIfNeeded();
1386 #if defined(TARGET_SDL)
1387 SetDrawtoField(DRAW_BACKBUFFER);
1390 if (CheckTitleScreen(levelset_has_changed))
1392 game_status = GAME_MODE_TITLE;
1399 /* level_nr may have been set to value over handicap with level editor */
1400 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1401 level_nr = leveldir_current->handicap_level;
1403 LoadLevel(level_nr);
1404 LoadScore(level_nr);
1406 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1409 if (fade_mask == REDRAW_ALL)
1411 // int door_state = GetDoorState();
1415 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1421 InitializeMainControls();
1423 DrawCursorAndText_Main(-1, FALSE);
1424 DrawPreviewLevelInitial();
1426 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1429 if (TAPE_IS_EMPTY(tape))
1431 DrawCompleteVideoDisplay();
1436 /* create gadgets for main menu screen */
1437 FreeScreenGadgets();
1438 CreateScreenGadgets();
1440 /* map gadgets for main menu screen */
1442 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1445 if (fade_mask == REDRAW_ALL)
1447 int door_state = GetDoorState();
1449 // RedrawBackground();
1451 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1455 DrawMaskedBorder(REDRAW_ALL);
1461 /* update screen area with special editor door */
1462 redraw_mask |= REDRAW_ALL;
1466 SetMouseCursor(CURSOR_DEFAULT);
1470 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1473 void DrawAndFadeInMainMenu(int fade_mask)
1475 DrawMainMenuExt(fade_mask, TRUE);
1480 DrawMainMenuExt(REDRAW_ALL, FALSE);
1483 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1484 static void gotoTopLevelDir()
1486 /* move upwards to top level directory */
1487 while (leveldir_current->node_parent)
1489 /* write a "path" into level tree for easy navigation to last level */
1490 if (leveldir_current->node_parent->node_group->cl_first == -1)
1492 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1493 int leveldir_pos = posTreeInfo(leveldir_current);
1494 int num_page_entries;
1495 int cl_first, cl_cursor;
1497 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1498 num_page_entries = num_leveldirs;
1500 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1502 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1503 cl_cursor = leveldir_pos - cl_first;
1505 leveldir_current->node_parent->node_group->cl_first = cl_first;
1506 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1509 leveldir_current = leveldir_current->node_parent;
1514 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1516 static unsigned int title_delay = 0;
1517 static int title_screen_nr = 0;
1518 static int last_sound = -1, last_music = -1;
1519 boolean return_to_main_menu = FALSE;
1520 boolean use_fading_main_menu = TRUE;
1521 struct TitleControlInfo *tci;
1522 struct TitleFadingInfo fading_default;
1523 struct TitleFadingInfo fading_last = fading;
1524 struct TitleFadingInfo fading_next;
1527 if (button == MB_MENU_INITIALIZE)
1530 title_screen_nr = 0;
1531 tci = &title_controls[title_screen_nr];
1533 last_sound = SND_UNDEFINED;
1534 last_music = MUS_UNDEFINED;
1536 if (game_status == GAME_MODE_INFO)
1538 if (num_title_screens == 0)
1540 DrawInfoScreen_NotAvailable("Title screen information:",
1541 "No title screen for this level set.");
1546 FadeSoundsAndMusic();
1549 FadeOut(REDRAW_ALL);
1554 DrawTitleScreenImage(tci->local_nr, tci->initial);
1556 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1558 fading_default = (tci->initial ? title_initial_default : title_default);
1560 fading = fading_next = getTitleFading(tci);
1564 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1565 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1567 fading.fade_mode = FADE_MODE_FADE;
1568 fading.fade_delay = fading_default.fade_delay;
1571 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1572 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1573 fading.fade_mode = FADE_MODE_FADE;
1578 sound = getTitleSound(tci);
1579 music = getTitleMusic(tci);
1581 if (sound != last_sound)
1582 PlayMenuSoundExt(sound);
1583 if (music != last_music)
1584 PlayMenuMusicExt(music);
1590 SetMouseCursor(CURSOR_NONE);
1596 fading = fading_next;
1598 DelayReached(&title_delay, 0); /* reset delay counter */
1604 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1605 button = MB_MENU_CHOICE;
1607 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1608 button = MB_MENU_CHOICE;
1611 if (button == MB_MENU_LEAVE)
1613 return_to_main_menu = TRUE;
1614 use_fading_main_menu = FALSE;
1616 else if (button == MB_MENU_CHOICE)
1618 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1621 FadeOut(REDRAW_FIELD);
1624 FadeSetEnterScreen();
1626 info_mode = INFO_MODE_MAIN;
1627 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1633 tci = &title_controls[title_screen_nr];
1635 if (title_screen_nr < num_title_screens)
1637 sound = getTitleSound(tci);
1638 music = getTitleMusic(tci);
1640 if (sound == SND_UNDEFINED || sound != last_sound)
1642 if (music == MUS_UNDEFINED || music != last_music)
1646 FadeOut(REDRAW_ALL);
1650 DrawTitleScreenImage(tci->local_nr, tci->initial);
1652 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1654 fading_next = getTitleFading(tci);
1657 sound = getTitleSound(tci);
1658 music = getTitleMusic(tci);
1660 if (sound != last_sound)
1661 PlayMenuSoundExt(sound);
1662 if (music != last_music)
1663 PlayMenuMusicExt(music);
1670 /* last screen already faded out, next screen has no animation */
1671 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1672 fading_next.fade_mode == FADE_MODE_NONE)
1673 fading = fading_next;
1675 /* last screen already faded out, next screen has no animation */
1676 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1677 fading_next.fade_mode == FADE_MODE_NONE)
1678 fading = fading_next;
1685 fading = fading_next;
1687 DelayReached(&title_delay, 0); /* reset delay counter */
1691 FadeSoundsAndMusic();
1693 return_to_main_menu = TRUE;
1697 if (return_to_main_menu)
1703 SetMouseCursor(CURSOR_DEFAULT);
1705 if (game_status == GAME_MODE_INFO)
1708 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1711 info_mode = INFO_MODE_MAIN;
1712 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1714 else /* default: return to main menu */
1717 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1720 game_status = GAME_MODE_MAIN;
1721 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1726 void HandleMainMenu_SelectLevel(int step, int direction)
1728 int old_level_nr = level_nr;
1731 new_level_nr = old_level_nr + step * direction;
1732 if (new_level_nr < leveldir_current->first_level)
1733 new_level_nr = leveldir_current->first_level;
1734 if (new_level_nr > leveldir_current->last_level)
1735 new_level_nr = leveldir_current->last_level;
1737 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1739 /* skipping levels is only allowed when trying to skip single level */
1740 if (setup.skip_levels && step == 1 &&
1741 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1743 leveldir_current->handicap_level++;
1744 SaveLevelSetup_SeriesInfo();
1747 new_level_nr = leveldir_current->handicap_level;
1750 if (new_level_nr != old_level_nr)
1752 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1754 PlaySound(SND_MENU_ITEM_SELECTING);
1756 level_nr = new_level_nr;
1758 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1759 int2str(level_nr, menu.main.text.level_number.size),
1760 mci->pos_text->font);
1762 LoadLevel(level_nr);
1763 DrawPreviewLevelInitial();
1767 DrawCompleteVideoDisplay();
1769 /* needed because DrawPreviewLevelInitial() takes some time */
1775 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1777 static int choice = MAIN_CONTROL_GAME;
1781 if (button == MB_MENU_INITIALIZE)
1783 DrawCursorAndText_Main(choice, TRUE);
1788 if (mx || my) /* mouse input */
1792 for (i = 0; main_controls[i].nr != -1; i++)
1795 printf("::: check click (%d, %d) for %d [%d] ...\n",
1796 mx - mSX, my - mSY, i, main_controls[i].nr);
1799 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1800 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1801 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1804 printf("::: inside %d\n", i);
1807 pos = main_controls[i].nr;
1813 else if (dx || dy) /* keyboard input */
1815 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1816 choice == MAIN_CONTROL_SETUP))
1817 button = MB_MENU_CHOICE;
1822 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1824 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1826 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1828 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1830 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1832 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1834 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1836 game_status = GAME_MODE_LEVELNR;
1838 DrawChooseLevelNr();
1840 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1846 PlaySound(SND_MENU_ITEM_ACTIVATING);
1848 DrawCursorAndText_Main(choice, FALSE);
1849 DrawCursorAndText_Main(pos, TRUE);
1856 PlaySound(SND_MENU_ITEM_SELECTING);
1858 if (pos == MAIN_CONTROL_NAME)
1860 game_status = GAME_MODE_PSEUDO_TYPENAME;
1862 HandleTypeName(strlen(setup.player_name), 0);
1864 else if (pos == MAIN_CONTROL_LEVELS)
1868 game_status = GAME_MODE_LEVELS;
1870 SaveLevelSetup_LastSeries();
1871 SaveLevelSetup_SeriesInfo();
1873 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1877 DrawChooseLevelSet();
1880 else if (pos == MAIN_CONTROL_SCORES)
1882 game_status = GAME_MODE_SCORES;
1886 else if (pos == MAIN_CONTROL_EDITOR)
1888 if (leveldir_current->readonly &&
1889 !strEqual(setup.player_name, "Artsoft"))
1890 Request("This level is read only !", REQ_CONFIRM);
1892 game_status = GAME_MODE_EDITOR;
1894 FadeSetEnterScreen();
1897 /* needed if different viewport properties defined for editor */
1898 ChangeViewportPropertiesIfNeeded();
1903 else if (pos == MAIN_CONTROL_INFO)
1905 game_status = GAME_MODE_INFO;
1906 info_mode = INFO_MODE_MAIN;
1910 else if (pos == MAIN_CONTROL_GAME)
1912 StartGameActions(options.network, setup.autorecord, level.random_seed);
1914 else if (pos == MAIN_CONTROL_SETUP)
1916 game_status = GAME_MODE_SETUP;
1917 setup_mode = SETUP_MODE_MAIN;
1921 else if (pos == MAIN_CONTROL_QUIT)
1923 SaveLevelSetup_LastSeries();
1924 SaveLevelSetup_SeriesInfo();
1926 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1927 game_status = GAME_MODE_QUIT;
1933 if (game_status == GAME_MODE_MAIN)
1935 DrawPreviewLevelAnimation();
1942 /* ========================================================================= */
1943 /* info screen functions */
1944 /* ========================================================================= */
1946 static struct TokenInfo *info_info;
1947 static int num_info_info;
1949 static void execInfoTitleScreen()
1951 info_mode = INFO_MODE_TITLE;
1956 static void execInfoElements()
1958 info_mode = INFO_MODE_ELEMENTS;
1963 static void execInfoMusic()
1965 info_mode = INFO_MODE_MUSIC;
1970 static void execInfoCredits()
1972 info_mode = INFO_MODE_CREDITS;
1977 static void execInfoProgram()
1979 info_mode = INFO_MODE_PROGRAM;
1984 static void execInfoVersion()
1986 info_mode = INFO_MODE_VERSION;
1991 static void execInfoLevelSet()
1993 info_mode = INFO_MODE_LEVELSET;
1998 static void execExitInfo()
2000 game_status = GAME_MODE_MAIN;
2002 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2005 static struct TokenInfo info_info_main[] =
2007 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2008 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2009 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2010 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2011 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2012 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2013 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2014 { TYPE_EMPTY, NULL, "" },
2015 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2020 static void DrawCursorAndText_Info(int pos, boolean active)
2022 int xpos = MENU_SCREEN_START_XPOS;
2023 int ypos = MENU_SCREEN_START_YPOS + pos;
2024 int font_nr = FONT_MENU_1;
2027 font_nr = FONT_ACTIVE(font_nr);
2029 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2031 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2032 drawCursor(pos, active);
2035 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2040 CloseDoor(DOOR_CLOSE_2);
2042 /* (needed after displaying title screens which disable auto repeat) */
2043 KeyboardAutoRepeatOn();
2045 FadeSetLeaveScreen();
2052 if (fade_mask == REDRAW_ALL)
2056 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2062 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2064 info_info = info_info_main;
2068 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2070 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2073 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2074 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2075 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2076 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2077 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2078 initCursor(i, IMG_MENU_BUTTON);
2080 DrawCursorAndText_Info(i, FALSE);
2085 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2090 DrawMaskedBorder(fade_mask);
2097 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2099 static int choice_store[MAX_INFO_MODES];
2100 int choice = choice_store[info_mode]; /* always starts with 0 */
2104 if (button == MB_MENU_INITIALIZE)
2106 /* advance to first valid menu entry */
2107 while (choice < num_info_info &&
2108 info_info[choice].type & TYPE_SKIP_ENTRY)
2110 choice_store[info_mode] = choice;
2112 DrawCursorAndText_Info(choice, TRUE);
2116 else if (button == MB_MENU_LEAVE)
2118 for (y = 0; y < num_info_info; y++)
2120 if (info_info[y].type & TYPE_LEAVE_MENU)
2122 void (*menu_callback_function)(void) = info_info[y].value;
2126 menu_callback_function();
2128 break; /* absolutely needed because function changes 'info_info'! */
2135 if (mx || my) /* mouse input */
2137 x = (mx - mSX) / 32;
2138 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2140 else if (dx || dy) /* keyboard input */
2144 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2146 if (info_info[choice].type & menu_navigation_type ||
2147 info_info[choice].type & TYPE_ENTER_SCREEN ||
2148 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2149 info_info[choice].type & TYPE_YES_NO_AUTO)
2150 button = MB_MENU_CHOICE;
2155 /* jump to next non-empty menu entry (up or down) */
2156 while (y > 0 && y < num_info_info - 1 &&
2157 info_info[y].type & TYPE_SKIP_ENTRY)
2161 if (IN_VIS_FIELD(x, y) &&
2162 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2168 PlaySound(SND_MENU_ITEM_ACTIVATING);
2170 DrawCursorAndText_Info(choice, FALSE);
2171 DrawCursorAndText_Info(y, TRUE);
2173 choice = choice_store[info_mode] = y;
2176 else if (!(info_info[y].type & TYPE_GHOSTED))
2178 PlaySound(SND_MENU_ITEM_SELECTING);
2180 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2182 void (*menu_callback_function)(void) = info_info[choice].value;
2184 FadeSetFromType(info_info[y].type);
2186 menu_callback_function();
2192 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2194 int ystart1 = mSY - SY + 100;
2195 int ystart2 = mSY - SY + 150;
2196 int ybottom = mSY - SY + SYSIZE - 20;
2198 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2200 FadeOut(REDRAW_FIELD);
2205 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2206 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2208 DrawTextSCentered(ybottom, FONT_TEXT_4,
2209 "Press any key or button for info menu");
2211 FadeIn(REDRAW_FIELD);
2214 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2216 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2217 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2218 int xstart = mSX + 16;
2219 int ystart1 = mSY - SY + 100;
2220 int ystart2 = mSY + 64 + 2 * 32;
2221 int ybottom = mSY - SY + SYSIZE - 20;
2222 int ystep = TILEY + 4;
2223 int element, action, direction;
2231 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2232 infoscreen_step[i] = infoscreen_frame[i] = 0;
2237 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2239 DrawTextSCentered(ybottom, FONT_TEXT_4,
2240 "Press any key or button for next page");
2246 while (helpanim_info[j].element != HELPANIM_LIST_END)
2248 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2253 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2262 j += infoscreen_step[i - start];
2264 element = helpanim_info[j].element;
2265 action = helpanim_info[j].action;
2266 direction = helpanim_info[j].direction;
2269 element = EL_UNKNOWN;
2271 if (action != -1 && direction != -1)
2272 graphic = el_act_dir2img(element, action, direction);
2273 else if (action != -1)
2274 graphic = el_act2img(element, action);
2275 else if (direction != -1)
2276 graphic = el_dir2img(element, direction);
2278 graphic = el2img(element);
2280 delay = helpanim_info[j++].delay;
2285 if (infoscreen_frame[i - start] == 0)
2288 infoscreen_frame[i - start] = delay - 1;
2292 sync_frame = delay - infoscreen_frame[i - start];
2293 infoscreen_frame[i - start]--;
2296 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2298 if (!infoscreen_frame[i - start])
2299 infoscreen_step[i - start] = 0;
2303 if (!infoscreen_frame[i - start])
2304 infoscreen_step[i - start]++;
2305 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2311 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2313 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2314 graphic, sync_frame, USE_MASKING);
2317 DrawInfoScreen_HelpText(element, action, direction, i - start);
2322 redraw_mask |= REDRAW_FIELD;
2327 static char *getHelpText(int element, int action, int direction)
2329 char token[MAX_LINE_LEN];
2331 strcpy(token, element_info[element].token_name);
2334 strcat(token, element_action_info[action].suffix);
2336 if (direction != -1)
2337 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2339 return getHashEntry(helptext_info, token);
2342 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2344 int font_nr = FONT_INFO_ELEMENTS;
2345 int font_width = getFontWidth(font_nr);
2346 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2347 int sy = mSY + 65 + 2 * 32 + 1;
2348 int ystep = TILEY + 4;
2349 int pad_x = sx - SX;
2350 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2351 int max_lines_per_text = 2;
2354 if (action != -1 && direction != -1) /* element.action.direction */
2355 text = getHelpText(element, action, direction);
2357 if (text == NULL && action != -1) /* element.action */
2358 text = getHelpText(element, action, -1);
2360 if (text == NULL && direction != -1) /* element.direction */
2361 text = getHelpText(element, -1, direction);
2363 if (text == NULL) /* base element */
2364 text = getHelpText(element, -1, -1);
2366 if (text == NULL) /* not found */
2367 text = "No description available";
2369 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2370 sy += getFontHeight(font_nr) / 2;
2372 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2373 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2374 TRUE, FALSE, FALSE);
2377 void DrawInfoScreen_TitleScreen()
2382 void HandleInfoScreen_TitleScreen(int button)
2384 HandleTitleScreen(0, 0, 0, 0, button);
2387 void DrawInfoScreen_Elements()
2389 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2391 FadeOut(REDRAW_FIELD);
2396 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2398 FadeIn(REDRAW_FIELD);
2403 void HandleInfoScreen_Elements(int button)
2405 static unsigned int info_delay = 0;
2406 static int num_anims;
2407 static int num_pages;
2409 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2412 if (button == MB_MENU_INITIALIZE)
2414 boolean new_element = TRUE;
2418 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2420 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2422 else if (new_element)
2425 new_element = FALSE;
2429 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2433 if (button == MB_MENU_LEAVE)
2435 PlaySound(SND_MENU_ITEM_SELECTING);
2437 info_mode = INFO_MODE_MAIN;
2442 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2444 if (button != MB_MENU_INITIALIZE)
2446 PlaySound(SND_MENU_ITEM_SELECTING);
2451 if (page >= num_pages)
2453 FadeSoundsAndMusic();
2455 info_mode = INFO_MODE_MAIN;
2456 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2463 FadeSetNextScreen();
2466 if (button != MB_MENU_INITIALIZE)
2467 FadeOut(REDRAW_FIELD);
2469 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2471 if (button != MB_MENU_INITIALIZE)
2472 FadeIn(REDRAW_FIELD);
2476 if (DelayReached(&info_delay, GameFrameDelay))
2477 if (page < num_pages)
2478 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2480 PlayMenuSoundIfLoop();
2484 void DrawInfoScreen_Music()
2486 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2489 FadeOut(REDRAW_FIELD);
2497 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2500 FadeIn(REDRAW_FIELD);
2504 void HandleInfoScreen_Music(int button)
2506 static struct MusicFileInfo *list = NULL;
2507 int ystart1 = mSY - SY + 100;
2508 int ystart2 = mSY - SY + 150;
2509 int ybottom = mSY - SY + SYSIZE - 20;
2512 if (button == MB_MENU_INITIALIZE)
2514 list = music_file_info;
2518 FadeSoundsAndMusic();
2523 DrawTextSCentered(ystart1, FONT_TEXT_1,
2524 "No music info for this level set.");
2526 DrawTextSCentered(ybottom, FONT_TEXT_4,
2527 "Press any key or button for info menu");
2533 if (button == MB_MENU_LEAVE)
2535 PlaySound(SND_MENU_ITEM_SELECTING);
2537 FadeSoundsAndMusic();
2539 info_mode = INFO_MODE_MAIN;
2544 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2548 if (button != MB_MENU_INITIALIZE)
2550 PlaySound(SND_MENU_ITEM_SELECTING);
2558 FadeSoundsAndMusic();
2560 info_mode = INFO_MODE_MAIN;
2561 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2566 FadeSoundsAndMusic();
2569 if (list != music_file_info)
2570 FadeSetNextScreen();
2573 if (button != MB_MENU_INITIALIZE)
2574 FadeOut(REDRAW_FIELD);
2581 int sound = list->music;
2583 if (sound_info[sound].loop)
2584 PlaySoundLoop(sound);
2588 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2592 PlayMusic(list->music);
2594 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2597 if (!strEqual(list->title, UNKNOWN_NAME))
2599 if (!strEqual(list->title_header, UNKNOWN_NAME))
2600 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2602 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2605 if (!strEqual(list->artist, UNKNOWN_NAME))
2607 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2608 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2610 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2612 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2615 if (!strEqual(list->album, UNKNOWN_NAME))
2617 if (!strEqual(list->album_header, UNKNOWN_NAME))
2618 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2620 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2622 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2625 if (!strEqual(list->year, UNKNOWN_NAME))
2627 if (!strEqual(list->year_header, UNKNOWN_NAME))
2628 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2630 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2632 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2635 DrawTextSCentered(ybottom, FONT_TEXT_4,
2636 "Press any key or button for next page");
2638 if (button != MB_MENU_INITIALIZE)
2639 FadeIn(REDRAW_FIELD);
2642 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2643 PlaySoundLoop(list->music);
2646 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2648 int ystart1 = mSY - SY + 100;
2649 int ystart2 = mSY - SY + 150;
2650 int ybottom = mSY - SY + SYSIZE - 20;
2656 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2660 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2661 "Special thanks to");
2662 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2664 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2666 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2667 "\"Boulder Dash\"");
2668 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2670 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2672 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2674 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2675 "First Star Software");
2677 else if (screen_nr == 1)
2679 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2680 "Special thanks to");
2681 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2682 "Klaus Heinz & Volker Wertich");
2683 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2685 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2686 "\"Emerald Mine\"");
2687 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2689 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2691 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2693 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2696 else if (screen_nr == 2)
2698 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2699 "Special thanks to");
2700 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2701 "Michael Stopp & Philip Jespersen");
2702 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2704 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2706 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2708 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2710 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2712 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2713 "Digital Integration");
2715 else if (screen_nr == 3)
2717 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2718 "Special thanks to");
2719 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2720 "Hiroyuki Imabayashi");
2721 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2723 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2725 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2727 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2729 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2731 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2734 else if (screen_nr == 4)
2736 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2737 "Special thanks to");
2738 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2740 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2742 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2743 "Jürgen Bonhagen");
2744 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2745 "for the continuous creation");
2746 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2747 "of outstanding level sets");
2749 else if (screen_nr == 5)
2751 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2753 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2755 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2756 "for ideas and inspiration by");
2757 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2760 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2762 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2764 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2765 "for ideas and inspiration by");
2766 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2769 else if (screen_nr == 6)
2771 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2773 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2776 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2777 "for the code base used for the");
2778 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2779 "native Emerald Mine engine");
2781 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2782 "for the new Emerald Mine engine");
2785 else if (screen_nr == 7)
2787 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2789 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2791 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2792 "for the initial DOS port");
2794 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2796 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2798 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2799 "for some additional toons");
2801 else if (screen_nr == 8)
2803 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2804 "And not to forget:");
2805 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2807 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2808 "All those who contributed");
2809 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2810 "levels to this game");
2811 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2815 DrawTextSCentered(ybottom, FONT_TEXT_4,
2816 "Press any key or button for next page");
2819 void DrawInfoScreen_Credits()
2821 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2823 FadeSoundsAndMusic();
2826 FadeOut(REDRAW_FIELD);
2829 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2832 FadeIn(REDRAW_FIELD);
2836 void HandleInfoScreen_Credits(int button)
2838 static int screen_nr = 0;
2839 int num_screens = 9;
2841 if (button == MB_MENU_INITIALIZE)
2845 // DrawInfoScreen_CreditsScreen(screen_nr);
2848 if (button == MB_MENU_LEAVE)
2850 PlaySound(SND_MENU_ITEM_SELECTING);
2852 info_mode = INFO_MODE_MAIN;
2857 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2859 if (button != MB_MENU_INITIALIZE)
2861 PlaySound(SND_MENU_ITEM_SELECTING);
2866 if (screen_nr >= num_screens)
2868 FadeSoundsAndMusic();
2870 info_mode = INFO_MODE_MAIN;
2871 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2878 FadeSetNextScreen();
2881 if (button != MB_MENU_INITIALIZE)
2882 FadeOut(REDRAW_FIELD);
2884 DrawInfoScreen_CreditsScreen(screen_nr);
2886 if (button != MB_MENU_INITIALIZE)
2887 FadeIn(REDRAW_FIELD);
2891 PlayMenuSoundIfLoop();
2895 void DrawInfoScreen_Program()
2897 int ystart1 = mSY - SY + 100;
2898 int ystart2 = mSY - SY + 150;
2899 int ybottom = mSY - SY + SYSIZE - 20;
2902 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2905 FadeOut(REDRAW_FIELD);
2911 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2913 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2914 "This game is Freeware!");
2915 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2916 "If you like it, send e-mail to:");
2917 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2918 PROGRAM_EMAIL_STRING);
2920 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2921 "More information and levels:");
2922 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2923 PROGRAM_WEBSITE_STRING);
2924 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2925 "If you have created new levels,");
2926 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2927 "send them to me to include them!");
2928 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2931 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2932 "or SnailMail to:");
2933 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2935 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2936 "Detmolder Strasse 189");
2937 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2939 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2941 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2942 "More information and levels:");
2943 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2944 PROGRAM_WEBSITE_STRING);
2945 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2946 "If you have created new levels,");
2947 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2948 "send them to me to include them!");
2949 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2953 DrawTextSCentered(ybottom, FONT_TEXT_4,
2954 "Press any key or button for info menu");
2957 FadeIn(REDRAW_FIELD);
2961 void HandleInfoScreen_Program(int button)
2963 if (button == MB_MENU_LEAVE)
2965 PlaySound(SND_MENU_ITEM_SELECTING);
2967 info_mode = INFO_MODE_MAIN;
2972 else if (button == MB_MENU_CHOICE)
2974 PlaySound(SND_MENU_ITEM_SELECTING);
2976 FadeSoundsAndMusic();
2979 FadeOut(REDRAW_FIELD);
2982 info_mode = INFO_MODE_MAIN;
2983 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2987 PlayMenuSoundIfLoop();
2991 void DrawInfoScreen_Version()
2993 int font_header = FONT_TEXT_3;
2994 int font_text = FONT_TEXT_2;
2995 int xstep = getFontWidth(font_text);
2996 int ystep = getFontHeight(font_text);
2997 int ystart1 = mSY - SY + 100;
2998 int ystart2 = mSY - SY + 150;
2999 int ybottom = mSY - SY + SYSIZE - 20;
3000 int xstart1 = mSX - SX + 2 * xstep;
3001 int xstart2 = mSX - SX + 18 * xstep;
3002 #if defined(TARGET_SDL)
3003 int xstart3 = mSX - SX + 28 * xstep;
3004 SDL_version sdl_version_compiled;
3005 const SDL_version *sdl_version_linked;
3006 int driver_name_len = 10;
3007 #if defined(TARGET_SDL2)
3008 SDL_version sdl_version_linked_ext;
3009 const char *driver_name = NULL;
3011 char driver_name[driver_name_len];
3015 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3018 FadeOut(REDRAW_FIELD);
3024 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3026 DrawTextF(xstart1, ystart2, font_header, "Name");
3027 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3030 DrawTextF(xstart1, ystart2, font_header, "Version");
3031 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3034 DrawTextF(xstart1, ystart2, font_header, "Platform");
3035 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3038 DrawTextF(xstart1, ystart2, font_header, "Target");
3039 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3042 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3043 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3045 #if defined(TARGET_SDL)
3046 ystart2 += 3 * ystep;
3047 DrawTextF(xstart1, ystart2, font_header, "Library");
3048 DrawTextF(xstart2, ystart2, font_header, "compiled");
3049 DrawTextF(xstart3, ystart2, font_header, "linked");
3051 SDL_VERSION(&sdl_version_compiled);
3052 #if defined(TARGET_SDL2)
3053 SDL_GetVersion(&sdl_version_linked_ext);
3054 sdl_version_linked = &sdl_version_linked_ext;
3056 sdl_version_linked = SDL_Linked_Version();
3059 ystart2 += 2 * ystep;
3060 DrawTextF(xstart1, ystart2, font_text, "SDL");
3061 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3062 sdl_version_compiled.major,
3063 sdl_version_compiled.minor,
3064 sdl_version_compiled.patch);
3065 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3066 sdl_version_linked->major,
3067 sdl_version_linked->minor,
3068 sdl_version_linked->patch);
3070 SDL_IMAGE_VERSION(&sdl_version_compiled);
3071 sdl_version_linked = IMG_Linked_Version();
3074 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3075 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3076 sdl_version_compiled.major,
3077 sdl_version_compiled.minor,
3078 sdl_version_compiled.patch);
3079 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3080 sdl_version_linked->major,
3081 sdl_version_linked->minor,
3082 sdl_version_linked->patch);
3084 SDL_MIXER_VERSION(&sdl_version_compiled);
3085 sdl_version_linked = Mix_Linked_Version();
3088 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3089 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3090 sdl_version_compiled.major,
3091 sdl_version_compiled.minor,
3092 sdl_version_compiled.patch);
3093 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3094 sdl_version_linked->major,
3095 sdl_version_linked->minor,
3096 sdl_version_linked->patch);
3098 SDL_NET_VERSION(&sdl_version_compiled);
3099 sdl_version_linked = SDLNet_Linked_Version();
3102 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3103 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3104 sdl_version_compiled.major,
3105 sdl_version_compiled.minor,
3106 sdl_version_compiled.patch);
3107 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3108 sdl_version_linked->major,
3109 sdl_version_linked->minor,
3110 sdl_version_linked->patch);
3112 ystart2 += 3 * ystep;
3113 DrawTextF(xstart1, ystart2, font_header, "Driver");
3114 DrawTextF(xstart2, ystart2, font_header, "Requested");
3115 DrawTextF(xstart3, ystart2, font_header, "Used");
3117 #if defined(TARGET_SDL2)
3118 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3120 SDL_VideoDriverName(driver_name, driver_name_len);
3123 ystart2 += 2 * ystep;
3124 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3125 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3126 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3128 #if defined(TARGET_SDL2)
3129 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3131 SDL_AudioDriverName(driver_name, driver_name_len);
3135 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3136 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3137 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3140 DrawTextSCentered(ybottom, FONT_TEXT_4,
3141 "Press any key or button for info menu");
3144 FadeIn(REDRAW_FIELD);
3148 void HandleInfoScreen_Version(int button)
3150 if (button == MB_MENU_LEAVE)
3152 PlaySound(SND_MENU_ITEM_SELECTING);
3154 info_mode = INFO_MODE_MAIN;
3159 else if (button == MB_MENU_CHOICE)
3161 PlaySound(SND_MENU_ITEM_SELECTING);
3163 FadeSoundsAndMusic();
3166 FadeOut(REDRAW_FIELD);
3169 info_mode = INFO_MODE_MAIN;
3170 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3174 PlayMenuSoundIfLoop();
3178 void DrawInfoScreen_LevelSet()
3180 struct TitleMessageInfo *tmi = &readme;
3181 char *filename = getLevelSetInfoFilename();
3183 /* if chars set to "-1", automatically determine by text and font width */
3184 if (tmi->chars == -1)
3185 tmi->chars = tmi->width / getFontWidth(tmi->font);
3187 tmi->width = tmi->chars * getFontWidth(tmi->font);
3189 /* if lines set to "-1", automatically determine by text and font height */
3190 if (tmi->lines == -1)
3191 tmi->lines = tmi->height / getFontHeight(tmi->font);
3193 tmi->height = tmi->lines * getFontHeight(tmi->font);
3195 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3198 FadeOut(REDRAW_FIELD);
3204 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3206 if (filename != NULL)
3207 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3208 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3209 tmi->autowrap, tmi->centered, tmi->parse_comments);
3211 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3212 "No information for this level set.");
3214 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3215 "Press any key or button for info menu");
3218 FadeIn(REDRAW_FIELD);
3222 void HandleInfoScreen_LevelSet(int button)
3224 if (button == MB_MENU_LEAVE)
3226 PlaySound(SND_MENU_ITEM_SELECTING);
3228 info_mode = INFO_MODE_MAIN;
3233 else if (button == MB_MENU_CHOICE)
3235 PlaySound(SND_MENU_ITEM_SELECTING);
3237 FadeSoundsAndMusic();
3240 FadeOut(REDRAW_FIELD);
3243 info_mode = INFO_MODE_MAIN;
3244 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3248 PlayMenuSoundIfLoop();
3252 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3254 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3256 if (info_mode == INFO_MODE_TITLE)
3257 DrawInfoScreen_TitleScreen();
3258 else if (info_mode == INFO_MODE_ELEMENTS)
3259 DrawInfoScreen_Elements();
3260 else if (info_mode == INFO_MODE_MUSIC)
3261 DrawInfoScreen_Music();
3262 else if (info_mode == INFO_MODE_CREDITS)
3263 DrawInfoScreen_Credits();
3264 else if (info_mode == INFO_MODE_PROGRAM)
3265 DrawInfoScreen_Program();
3266 else if (info_mode == INFO_MODE_VERSION)
3267 DrawInfoScreen_Version();
3268 else if (info_mode == INFO_MODE_LEVELSET)
3269 DrawInfoScreen_LevelSet();
3271 DrawInfoScreen_Main(fade_mask, do_fading);
3273 if (info_mode != INFO_MODE_MAIN &&
3274 info_mode != INFO_MODE_TITLE &&
3275 info_mode != INFO_MODE_MUSIC)
3282 void DrawAndFadeInInfoScreen(int fade_mask)
3284 DrawInfoScreenExt(fade_mask, TRUE);
3287 void DrawInfoScreen()
3289 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3292 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3294 if (info_mode == INFO_MODE_TITLE)
3295 HandleInfoScreen_TitleScreen(button);
3296 else if (info_mode == INFO_MODE_ELEMENTS)
3297 HandleInfoScreen_Elements(button);
3298 else if (info_mode == INFO_MODE_MUSIC)
3299 HandleInfoScreen_Music(button);
3300 else if (info_mode == INFO_MODE_CREDITS)
3301 HandleInfoScreen_Credits(button);
3302 else if (info_mode == INFO_MODE_PROGRAM)
3303 HandleInfoScreen_Program(button);
3304 else if (info_mode == INFO_MODE_VERSION)
3305 HandleInfoScreen_Version(button);
3306 else if (info_mode == INFO_MODE_LEVELSET)
3307 HandleInfoScreen_LevelSet(button);
3309 HandleInfoScreen_Main(mx, my, dx, dy, button);
3317 /* ========================================================================= */
3318 /* type name functions */
3319 /* ========================================================================= */
3321 void HandleTypeName(int newxpos, Key key)
3323 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3324 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3325 struct TextPosInfo *pos = mci->pos_input;
3326 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3327 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3328 static int xpos = 0;
3329 int font_nr = pos->font;
3330 int font_active_nr = FONT_ACTIVE(font_nr);
3331 int font_width = getFontWidth(font_active_nr);
3332 char key_char = getValidConfigValueChar(getCharFromKey(key));
3333 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3334 boolean is_active = TRUE;
3336 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3340 strcpy(last_player_name, setup.player_name);
3344 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3346 setup.player_name[xpos] = key_char;
3347 setup.player_name[xpos + 1] = 0;
3351 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3355 setup.player_name[xpos] = 0;
3357 else if (key == KSYM_Return && xpos > 0)
3363 game_status = GAME_MODE_MAIN;
3365 else if (key == KSYM_Escape)
3367 strcpy(setup.player_name, last_player_name);
3371 game_status = GAME_MODE_MAIN;
3376 pos->width = (strlen(setup.player_name) + 1) * font_width;
3377 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3379 DrawText(startx, starty, setup.player_name, font_active_nr);
3380 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3384 pos->width = strlen(setup.player_name) * font_width;
3385 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3387 DrawText(startx, starty, setup.player_name, font_nr);
3392 /* ========================================================================= */
3393 /* tree menu functions */
3394 /* ========================================================================= */
3396 static void DrawChooseTree(TreeInfo **ti_ptr)
3400 FreeScreenGadgets();
3401 CreateScreenGadgets();
3403 CloseDoor(DOOR_CLOSE_2);
3406 FadeOut(REDRAW_FIELD);
3411 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3412 MapScreenTreeGadgets(*ti_ptr);
3415 FadeIn(REDRAW_FIELD);
3421 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3423 struct GadgetInfo *gi = screen_gadget[id];
3424 int items_max, items_visible, item_position;
3426 items_max = numTreeInfoInGroup(ti);
3427 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3428 item_position = first_entry;
3430 if (item_position > items_max - items_visible)
3431 item_position = items_max - items_visible;
3433 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3434 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3435 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3438 static void drawChooseTreeList(int first_entry, int num_page_entries,
3442 char *title_string = NULL;
3443 int yoffset_sets = MENU_TITLE1_YPOS;
3444 int yoffset_setup = 16;
3445 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3446 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3447 int last_game_status = game_status; /* save current game status */
3449 title_string = ti->infotext;
3451 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3454 /* force LEVELS font on artwork setup screen */
3455 game_status = GAME_MODE_LEVELS;
3459 /* clear tree list area, but not title or scrollbar */
3460 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3461 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3462 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3464 /* clear tree list area, but not title or scrollbar */
3465 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3466 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3467 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3470 for (i = 0; i < num_page_entries; i++)
3472 TreeInfo *node, *node_first;
3473 int entry_pos = first_entry + i;
3474 int xpos = MENU_SCREEN_START_XPOS;
3475 int ypos = MENU_SCREEN_START_YPOS + i;
3476 int startx = mSX + xpos * 32;
3477 int starty = mSY + ypos * 32;
3478 int font_nr = FONT_TEXT_1;
3479 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3480 int startx_text = startx + font_xoffset;
3481 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3482 int text_size = startx_scrollbar - startx_text;
3483 int max_buffer_len = text_size / getFontWidth(font_nr);
3484 char buffer[max_buffer_len + 1];
3486 node_first = getTreeInfoFirstGroupEntry(ti);
3487 node = getTreeInfoFromPos(node_first, entry_pos);
3489 strncpy(buffer, node->name, max_buffer_len);
3490 buffer[max_buffer_len] = '\0';
3492 DrawText(startx, starty, buffer, font_nr + node->color);
3494 if (node->parent_link)
3495 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3496 else if (node->level_group)
3497 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3499 initCursor(i, IMG_MENU_BUTTON);
3502 game_status = last_game_status; /* restore current game status */
3504 redraw_mask |= REDRAW_FIELD;
3507 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3509 TreeInfo *node, *node_first;
3510 int x, last_redraw_mask = redraw_mask;
3511 int ypos = MENU_TITLE2_YPOS;
3512 int font_nr = FONT_TITLE_2;
3514 if (ti->type == TREE_TYPE_LEVEL_NR)
3515 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3517 if (ti->type != TREE_TYPE_LEVEL_DIR)
3520 node_first = getTreeInfoFirstGroupEntry(ti);
3521 node = getTreeInfoFromPos(node_first, entry_pos);
3523 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3526 if (node->parent_link)
3527 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3528 node->node_parent->name);
3529 else if (node->level_group)
3530 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3532 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3533 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3534 node->levels, (node->levels > 1 ? "levels" : "level"),
3537 if (node->parent_link)
3538 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3540 else if (node->level_group)
3541 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3543 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3544 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3545 node->levels, node->class_desc);
3548 /* let BackToFront() redraw only what is needed */
3549 redraw_mask = last_redraw_mask | REDRAW_TILES;
3550 for (x = 0; x < SCR_FIELDX; x++)
3551 MarkTileDirty(x, 1);
3554 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3557 TreeInfo *ti = *ti_ptr;
3559 int y = ti->cl_cursor;
3560 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3561 int num_entries = numTreeInfoInGroup(ti);
3562 int num_page_entries;
3563 int last_game_status = game_status; /* save current game status */
3564 boolean position_set_by_scrollbar = (dx == 999);
3567 /* force LEVELS draw offset on choose level and artwork setup screen */
3568 game_status = GAME_MODE_LEVELS;
3571 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3572 num_page_entries = num_entries;
3574 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3576 game_status = last_game_status; /* restore current game status */
3578 if (button == MB_MENU_INITIALIZE)
3580 int num_entries = numTreeInfoInGroup(ti);
3581 int entry_pos = posTreeInfo(ti);
3583 if (ti->cl_first == -1)
3585 /* only on initialization */
3586 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3587 ti->cl_cursor = entry_pos - ti->cl_first;
3589 else if (ti->cl_cursor >= num_page_entries ||
3590 (num_entries > num_page_entries &&
3591 num_entries - ti->cl_first < num_page_entries))
3593 /* only after change of list size (by custom graphic configuration) */
3594 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3595 ti->cl_cursor = entry_pos - ti->cl_first;
3598 if (position_set_by_scrollbar)
3601 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3604 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3605 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3606 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3610 else if (button == MB_MENU_LEAVE)
3614 PlaySound(SND_MENU_ITEM_SELECTING);
3616 if (ti->node_parent)
3618 *ti_ptr = ti->node_parent;
3619 DrawChooseTree(ti_ptr);
3621 else if (game_status == GAME_MODE_SETUP)
3623 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3625 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3626 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3627 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3628 execSetupGraphics();
3629 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3630 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3631 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3638 if (game_status == GAME_MODE_LEVELNR)
3639 level_nr = atoi(level_number_current->identifier);
3641 game_status = GAME_MODE_MAIN;
3643 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3649 if (mx || my) /* mouse input */
3651 int last_game_status = game_status; /* save current game status */
3654 /* force LEVELS draw offset on artwork setup screen */
3655 game_status = GAME_MODE_LEVELS;
3658 x = (mx - mSX) / 32;
3659 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3661 game_status = last_game_status; /* restore current game status */
3663 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3665 /* move cursor instead of scrolling when already at start/end of list */
3666 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3668 else if (dy == +1 * SCROLL_LINE &&
3669 ti->cl_first + num_page_entries == num_entries)
3672 /* handle scrolling screen one line or page */
3673 if (ti->cl_cursor + dy < 0 ||
3674 ti->cl_cursor + dy > num_page_entries - 1)
3676 if (ABS(dy) == SCROLL_PAGE)
3677 step = num_page_entries - 1;
3679 if (dy < 0 && ti->cl_first > 0)
3681 /* scroll page/line up */
3683 ti->cl_first -= step;
3684 if (ti->cl_first < 0)
3687 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3688 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3689 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3691 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3694 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3696 /* scroll page/line down */
3698 ti->cl_first += step;
3699 if (ti->cl_first + num_page_entries > num_entries)
3700 ti->cl_first = MAX(0, num_entries - num_page_entries);
3702 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3703 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3704 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3706 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3713 /* handle moving cursor one line */
3714 y = ti->cl_cursor + dy;
3719 TreeInfo *node_first, *node_cursor;
3720 int entry_pos = ti->cl_first + y;
3722 node_first = getTreeInfoFirstGroupEntry(ti);
3723 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3725 if (node_cursor->node_group)
3729 PlaySound(SND_MENU_ITEM_SELECTING);
3731 node_cursor->cl_first = ti->cl_first;
3732 node_cursor->cl_cursor = ti->cl_cursor;
3733 *ti_ptr = node_cursor->node_group;
3734 DrawChooseTree(ti_ptr);
3739 else if (dx == -1 && ti->node_parent)
3743 PlaySound(SND_MENU_ITEM_SELECTING);
3745 *ti_ptr = ti->node_parent;
3746 DrawChooseTree(ti_ptr);
3751 if (!anyScrollbarGadgetActive() &&
3752 IN_VIS_FIELD(x, y) &&
3753 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3754 y >= 0 && y < num_page_entries)
3758 if (y != ti->cl_cursor)
3760 PlaySound(SND_MENU_ITEM_ACTIVATING);
3762 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3763 drawChooseTreeCursor(y, TRUE);
3764 drawChooseTreeInfo(ti->cl_first + y, ti);
3771 TreeInfo *node_first, *node_cursor;
3772 int entry_pos = ti->cl_first + y;
3774 PlaySound(SND_MENU_ITEM_SELECTING);
3776 node_first = getTreeInfoFirstGroupEntry(ti);
3777 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3779 if (node_cursor->node_group)
3783 node_cursor->cl_first = ti->cl_first;
3784 node_cursor->cl_cursor = ti->cl_cursor;
3785 *ti_ptr = node_cursor->node_group;
3786 DrawChooseTree(ti_ptr);
3788 else if (node_cursor->parent_link)
3792 *ti_ptr = node_cursor->node_parent;
3793 DrawChooseTree(ti_ptr);
3800 FadeSetEnterScreen();
3803 node_cursor->cl_first = ti->cl_first;
3804 node_cursor->cl_cursor = ti->cl_cursor;
3805 *ti_ptr = node_cursor;
3807 if (ti->type == TREE_TYPE_LEVEL_DIR)
3809 LoadLevelSetup_SeriesInfo();
3811 SaveLevelSetup_LastSeries();
3812 SaveLevelSetup_SeriesInfo();
3816 if (game_status == GAME_MODE_SETUP)
3818 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3820 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3821 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3822 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3823 execSetupGraphics();
3824 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3825 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3826 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3833 if (game_status == GAME_MODE_LEVELNR)
3834 level_nr = atoi(level_number_current->identifier);
3836 game_status = GAME_MODE_MAIN;
3845 void DrawChooseLevelSet()
3847 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3849 DrawChooseTree(&leveldir_current);
3855 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3857 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3864 void DrawChooseLevelNr()
3868 if (level_number != NULL)
3870 freeTreeInfo(level_number);
3872 level_number = NULL;
3875 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3877 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3878 char identifier[32], name[32];
3881 /* temporarily load level info to get level name */
3882 LoadLevelInfoOnly(i);
3884 ti->node_top = &level_number;
3885 ti->sort_priority = 10000 + value;
3886 ti->color = (level.no_valid_file ? FC_BLUE :
3887 LevelStats_getSolved(i) ? FC_GREEN :
3888 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3890 sprintf(identifier, "%d", value);
3891 sprintf(name, "%03d: %s", value,
3892 (level.no_valid_file ? "(no file)" : level.name));
3894 setString(&ti->identifier, identifier);
3895 setString(&ti->name, name);
3896 setString(&ti->name_sorting, name);
3898 pushTreeInfo(&level_number, ti);
3901 /* sort level number values to start with lowest level number */
3902 sortTreeInfo(&level_number);
3904 /* set current level number to current level number */
3905 level_number_current =
3906 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3908 /* if that also fails, set current level number to first available level */
3909 if (level_number_current == NULL)
3910 level_number_current = level_number;
3912 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3915 DrawChooseTree(&level_number_current);
3917 DrawChooseTree(&leveldir_current);
3924 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3927 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3929 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3937 void DrawHallOfFame(int highlight_position)
3940 FadeSoundsAndMusic();
3942 /* (this is needed when called from GameEnd() after winning a game) */
3943 KeyboardAutoRepeatOn();
3946 /* (this is needed when called from GameEnd() after winning a game) */
3947 SetDrawDeactivationMask(REDRAW_NONE);
3948 SetDrawBackgroundMask(REDRAW_FIELD);
3950 CloseDoor(DOOR_CLOSE_2);
3952 if (highlight_position < 0)
3953 LoadScore(level_nr);
3955 FadeSetEnterScreen();
3957 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3960 FadeOut(REDRAW_FIELD);
3968 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3971 FadeIn(REDRAW_FIELD);
3975 static void drawHallOfFameList(int first_entry, int highlight_position)
3979 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3982 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3983 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3984 "HighScores of Level %d", level_nr);
3986 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3988 int entry = first_entry + i;
3989 boolean active = (entry == highlight_position);
3990 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3991 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3992 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3993 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3994 int dx1 = 3 * getFontWidth(font_nr1);
3995 int dx2 = dx1 + getFontWidth(font_nr1);
3996 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3997 int sy = mSY + 64 + i * 32;
3999 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4000 DrawText(mSX + dx1, sy, ".", font_nr1);
4001 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4003 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4004 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4006 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4009 redraw_mask |= REDRAW_FIELD;
4012 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4014 static int first_entry = 0;
4015 static int highlight_position = 0;
4016 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4018 if (button == MB_MENU_INITIALIZE)
4021 highlight_position = mx;
4022 drawHallOfFameList(first_entry, highlight_position);
4027 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4028 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4032 if (first_entry > 0)
4034 first_entry -= step;
4035 if (first_entry < 0)
4038 drawHallOfFameList(first_entry, highlight_position);
4043 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4045 first_entry += step;
4046 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4047 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4049 drawHallOfFameList(first_entry, highlight_position);
4052 else if (button == MB_MENU_LEAVE)
4054 PlaySound(SND_MENU_ITEM_SELECTING);
4056 FadeSound(SND_BACKGROUND_SCORES);
4058 game_status = GAME_MODE_MAIN;
4062 else if (button == MB_MENU_CHOICE)
4064 PlaySound(SND_MENU_ITEM_SELECTING);
4066 FadeSound(SND_BACKGROUND_SCORES);
4069 FadeOut(REDRAW_FIELD);
4072 game_status = GAME_MODE_MAIN;
4074 DrawAndFadeInMainMenu(REDRAW_FIELD);
4077 if (game_status == GAME_MODE_SCORES)
4078 PlayMenuSoundIfLoop();
4086 /* ========================================================================= */
4087 /* setup screen functions */
4088 /* ========================================================================= */
4090 static struct TokenInfo *setup_info;
4091 static int num_setup_info;
4093 static char *screen_mode_text;
4094 static char *window_size_text;
4095 static char *scroll_delay_text;
4096 static char *game_speed_text;
4097 static char *graphics_set_name;
4098 static char *sounds_set_name;
4099 static char *music_set_name;
4100 static char *volume_simple_text;
4101 static char *volume_loops_text;
4102 static char *volume_music_text;
4104 static void execSetupMain()
4106 setup_mode = SETUP_MODE_MAIN;
4111 static void execSetupGame()
4113 if (game_speeds == NULL)
4117 for (i = 0; game_speeds_list[i].value != -1; i++)
4119 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4120 char identifier[32], name[32];
4121 int value = game_speeds_list[i].value;
4122 char *text = game_speeds_list[i].text;
4124 ti->node_top = &game_speeds;
4125 ti->sort_priority = 10000 - value;
4127 sprintf(identifier, "%d", value);
4128 sprintf(name, "%s", text);
4130 setString(&ti->identifier, identifier);
4131 setString(&ti->name, name);
4132 setString(&ti->name_sorting, name);
4133 setString(&ti->infotext, "Game Speed");
4135 pushTreeInfo(&game_speeds, ti);
4138 /* sort game speed values to start with slowest game speed */
4139 sortTreeInfo(&game_speeds);
4141 /* set current game speed to configured game speed value */
4142 game_speed_current =
4143 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4145 /* if that fails, set current game speed to reliable default value */
4146 if (game_speed_current == NULL)
4147 game_speed_current =
4148 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4150 /* if that also fails, set current game speed to first available speed */
4151 if (game_speed_current == NULL)
4152 game_speed_current = game_speeds;
4155 setup.game_frame_delay = atoi(game_speed_current->identifier);
4157 /* needed for displaying game speed text instead of identifier */
4158 game_speed_text = game_speed_current->name;
4160 setup_mode = SETUP_MODE_GAME;
4165 static void execSetupChooseGameSpeed()
4167 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4172 static void execSetupEditor()
4174 setup_mode = SETUP_MODE_EDITOR;
4179 static void execSetupGraphics_setWindowSizes(boolean update_list)
4181 if (window_sizes != NULL && update_list)
4183 freeTreeInfo(window_sizes);
4185 window_sizes = NULL;
4188 if (window_sizes == NULL)
4190 boolean current_window_size_found = FALSE;
4193 for (i = 0; window_sizes_list[i].value != -1; i++)
4195 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4196 char identifier[32], name[32];
4197 int value = window_sizes_list[i].value;
4198 char *text = window_sizes_list[i].text;
4200 ti->node_top = &window_sizes;
4201 ti->sort_priority = value;
4203 sprintf(identifier, "%d", value);
4204 sprintf(name, "%s", text);
4206 setString(&ti->identifier, identifier);
4207 setString(&ti->name, name);
4208 setString(&ti->name_sorting, name);
4209 setString(&ti->infotext, "Window Scaling");
4211 pushTreeInfo(&window_sizes, ti);
4213 if (value == setup.window_scaling_percent)
4214 current_window_size_found = TRUE;
4217 if (!current_window_size_found)
4219 // add entry for non-preset window scaling value
4221 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4222 char identifier[32], name[32];
4223 int value = setup.window_scaling_percent;
4225 ti->node_top = &window_sizes;
4226 ti->sort_priority = value;
4228 sprintf(identifier, "%d", value);
4229 sprintf(name, "%d %% (Current)", value);
4231 setString(&ti->identifier, identifier);
4232 setString(&ti->name, name);
4233 setString(&ti->name_sorting, name);
4234 setString(&ti->infotext, "Window Scaling");
4236 pushTreeInfo(&window_sizes, ti);
4239 /* sort window size values to start with lowest window size value */
4240 sortTreeInfo(&window_sizes);
4242 /* set current window size value to configured window size value */
4243 window_size_current =
4244 getTreeInfoFromIdentifier(window_sizes,
4245 i_to_a(setup.window_scaling_percent));
4247 /* if that fails, set current window size to reliable default value */
4248 if (window_size_current == NULL)
4249 window_size_current =
4250 getTreeInfoFromIdentifier(window_sizes,
4251 i_to_a(STD_WINDOW_SCALING_PERCENT));
4253 /* if that also fails, set current window size to first available value */
4254 if (window_size_current == NULL)
4255 window_size_current = window_sizes;
4258 setup.window_scaling_percent = atoi(window_size_current->identifier);
4260 /* needed for displaying window size text instead of identifier */
4261 window_size_text = window_size_current->name;
4264 static void execSetupGraphics_setScreenModes()
4266 // if (screen_modes == NULL && video.fullscreen_available)
4267 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4271 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4273 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4274 char identifier[32], name[32];
4275 int x = video.fullscreen_modes[i].width;
4276 int y = video.fullscreen_modes[i].height;
4279 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4281 ti->node_top = &screen_modes;
4282 ti->sort_priority = x * 10000 + y;
4284 sprintf(identifier, "%dx%d", x, y);
4285 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4287 setString(&ti->identifier, identifier);
4288 setString(&ti->name, name);
4289 setString(&ti->name_sorting, name);
4290 setString(&ti->infotext, "Fullscreen Mode");
4292 pushTreeInfo(&screen_modes, ti);
4295 /* sort fullscreen modes to start with lowest available screen resolution */
4296 sortTreeInfo(&screen_modes);
4298 /* set current screen mode for fullscreen mode to configured setup value */
4299 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4300 setup.fullscreen_mode);
4302 /* if that fails, set current screen mode to reliable default value */
4303 if (screen_mode_current == NULL)
4304 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4305 DEFAULT_FULLSCREEN_MODE);
4307 /* if that also fails, set current screen mode to first available mode */
4308 if (screen_mode_current == NULL)
4309 screen_mode_current = screen_modes;
4311 if (screen_mode_current == NULL)
4312 video.fullscreen_available = FALSE;
4315 // if (video.fullscreen_available)
4316 if (screen_mode_current != NULL)
4318 setup.fullscreen_mode = screen_mode_current->identifier;
4320 /* needed for displaying screen mode name instead of identifier */
4321 screen_mode_text = screen_mode_current->name;
4325 static void execSetupGraphics_setScrollDelays()
4327 if (scroll_delays == NULL)
4331 for (i = 0; scroll_delays_list[i].value != -1; i++)
4333 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4334 char identifier[32], name[32];
4335 int value = scroll_delays_list[i].value;
4336 char *text = scroll_delays_list[i].text;
4338 ti->node_top = &scroll_delays;
4339 ti->sort_priority = value;
4341 sprintf(identifier, "%d", value);
4342 sprintf(name, "%s", text);
4344 setString(&ti->identifier, identifier);
4345 setString(&ti->name, name);
4346 setString(&ti->name_sorting, name);
4347 setString(&ti->infotext, "Scroll Delay");
4349 pushTreeInfo(&scroll_delays, ti);
4352 /* sort scroll delay values to start with lowest scroll delay value */
4353 sortTreeInfo(&scroll_delays);
4355 /* set current scroll delay value to configured scroll delay value */
4356 scroll_delay_current =
4357 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4359 /* if that fails, set current scroll delay to reliable default value */
4360 if (scroll_delay_current == NULL)
4361 scroll_delay_current =
4362 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4364 /* if that also fails, set current scroll delay to first available value */
4365 if (scroll_delay_current == NULL)
4366 scroll_delay_current = scroll_delays;
4369 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4371 /* needed for displaying scroll delay text instead of identifier */
4372 scroll_delay_text = scroll_delay_current->name;
4375 static void execSetupGraphics()
4377 // update "setup.window_scaling_percent" from list selection
4378 execSetupGraphics_setWindowSizes(FALSE);
4379 // maybe remove non-preset value (if standard value was selected)
4380 execSetupGraphics_setWindowSizes(TRUE);
4382 execSetupGraphics_setScreenModes();
4383 execSetupGraphics_setScrollDelays();
4385 setup_mode = SETUP_MODE_GRAPHICS;
4389 // window scaling may have changed at this point
4390 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4393 #if !defined(PLATFORM_ANDROID)
4394 #if defined(TARGET_SDL2)
4395 static void execSetupChooseWindowSize()
4398 if (!video.window_scaling_available)
4402 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4407 static void execSetupChooseScreenMode()
4409 if (!video.fullscreen_available)
4412 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4419 static void execSetupChooseScrollDelay()
4421 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4426 static void execSetupChooseVolumeSimple()
4428 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4433 static void execSetupChooseVolumeLoops()
4435 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4440 static void execSetupChooseVolumeMusic()
4442 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4447 static void execSetupSound()
4450 if (volumes_simple == NULL)
4454 for (i = 0; volumes_list[i].value != -1; i++)
4456 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4457 char identifier[32], name[32];
4458 int value = volumes_list[i].value;
4459 char *text = volumes_list[i].text;
4461 ti->node_top = &volumes_simple;
4462 ti->sort_priority = value;
4464 sprintf(identifier, "%d", value);
4465 sprintf(name, "%s", text);
4467 setString(&ti->identifier, identifier);
4468 setString(&ti->name, name);
4469 setString(&ti->name_sorting, name);
4470 setString(&ti->infotext, "Sound Volume");
4472 pushTreeInfo(&volumes_simple, ti);
4475 /* sort volume values to start with lowest volume value */
4476 sortTreeInfo(&volumes_simple);
4478 /* set current volume value to configured volume value */
4479 volume_simple_current =
4480 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4482 /* if that fails, set current volume to reliable default value */
4483 if (volume_simple_current == NULL)
4484 volume_simple_current =
4485 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4487 /* if that also fails, set current volume to first available value */
4488 if (volume_simple_current == NULL)
4489 volume_simple_current = volumes_simple;
4492 if (volumes_loops == NULL)
4496 for (i = 0; volumes_list[i].value != -1; i++)
4498 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4499 char identifier[32], name[32];
4500 int value = volumes_list[i].value;
4501 char *text = volumes_list[i].text;
4503 ti->node_top = &volumes_loops;
4504 ti->sort_priority = value;
4506 sprintf(identifier, "%d", value);
4507 sprintf(name, "%s", text);
4509 setString(&ti->identifier, identifier);
4510 setString(&ti->name, name);
4511 setString(&ti->name_sorting, name);
4512 setString(&ti->infotext, "Loops Volume");
4514 pushTreeInfo(&volumes_loops, ti);
4517 /* sort volume values to start with lowest volume value */
4518 sortTreeInfo(&volumes_loops);
4520 /* set current volume value to configured volume value */
4521 volume_loops_current =
4522 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4524 /* if that fails, set current volume to reliable default value */
4525 if (volume_loops_current == NULL)
4526 volume_loops_current =
4527 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4529 /* if that also fails, set current volume to first available value */
4530 if (volume_loops_current == NULL)
4531 volume_loops_current = volumes_loops;
4534 if (volumes_music == NULL)
4538 for (i = 0; volumes_list[i].value != -1; i++)
4540 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4541 char identifier[32], name[32];
4542 int value = volumes_list[i].value;
4543 char *text = volumes_list[i].text;
4545 ti->node_top = &volumes_music;
4546 ti->sort_priority = value;
4548 sprintf(identifier, "%d", value);
4549 sprintf(name, "%s", text);
4551 setString(&ti->identifier, identifier);
4552 setString(&ti->name, name);
4553 setString(&ti->name_sorting, name);
4554 setString(&ti->infotext, "Music Volume");
4556 pushTreeInfo(&volumes_music, ti);
4559 /* sort volume values to start with lowest volume value */
4560 sortTreeInfo(&volumes_music);
4562 /* set current volume value to configured volume value */
4563 volume_music_current =
4564 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4566 /* if that fails, set current volume to reliable default value */
4567 if (volume_music_current == NULL)
4568 volume_music_current =
4569 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4571 /* if that also fails, set current volume to first available value */
4572 if (volume_music_current == NULL)
4573 volume_music_current = volumes_music;
4576 setup.volume_simple = atoi(volume_simple_current->identifier);
4577 setup.volume_loops = atoi(volume_loops_current->identifier);
4578 setup.volume_music = atoi(volume_music_current->identifier);
4580 /* needed for displaying volume text instead of identifier */
4581 volume_simple_text = volume_simple_current->name;
4582 volume_loops_text = volume_loops_current->name;
4583 volume_music_text = volume_music_current->name;
4586 setup_mode = SETUP_MODE_SOUND;
4591 static void execSetupArtwork()
4594 printf("::: '%s', '%s', '%s'\n",
4595 artwork.gfx_current->subdir,
4596 artwork.gfx_current->fullpath,
4597 artwork.gfx_current->basepath);
4600 setup.graphics_set = artwork.gfx_current->identifier;
4601 setup.sounds_set = artwork.snd_current->identifier;
4602 setup.music_set = artwork.mus_current->identifier;
4604 /* needed if last screen (setup choice) changed graphics, sounds or music */
4605 ReloadCustomArtwork(0);
4607 /* needed for displaying artwork name instead of artwork identifier */
4608 graphics_set_name = artwork.gfx_current->name;
4609 sounds_set_name = artwork.snd_current->name;
4610 music_set_name = artwork.mus_current->name;
4612 setup_mode = SETUP_MODE_ARTWORK;
4617 static void execSetupChooseGraphics()
4619 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4624 static void execSetupChooseSounds()
4626 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4631 static void execSetupChooseMusic()
4633 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4638 static void execSetupInput()
4640 setup_mode = SETUP_MODE_INPUT;
4645 static void execSetupShortcuts()
4647 setup_mode = SETUP_MODE_SHORTCUTS;
4652 static void execSetupShortcuts1()
4654 setup_mode = SETUP_MODE_SHORTCUTS_1;
4659 static void execSetupShortcuts2()
4661 setup_mode = SETUP_MODE_SHORTCUTS_2;
4666 static void execSetupShortcuts3()
4668 setup_mode = SETUP_MODE_SHORTCUTS_3;
4673 static void execSetupShortcuts4()
4675 setup_mode = SETUP_MODE_SHORTCUTS_4;
4680 static void execSetupShortcuts5()
4682 setup_mode = SETUP_MODE_SHORTCUTS_5;
4687 static void execExitSetup()
4689 game_status = GAME_MODE_MAIN;
4691 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4694 static void execSaveAndExitSetup()
4700 static struct TokenInfo setup_info_main[] =
4702 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4703 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4704 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4705 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4706 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4707 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4708 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4709 { TYPE_EMPTY, NULL, "" },
4710 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4711 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4716 static struct TokenInfo setup_info_game[] =
4718 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4719 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4720 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4721 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4722 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4723 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4724 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4725 { TYPE_STRING, &game_speed_text, "" },
4726 { TYPE_EMPTY, NULL, "" },
4727 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4732 static struct TokenInfo setup_info_editor[] =
4735 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4736 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4737 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4738 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4739 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4740 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4741 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4742 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4744 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4745 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4746 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4748 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4750 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4751 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4752 { TYPE_EMPTY, NULL, "" },
4754 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4755 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4756 { TYPE_EMPTY, NULL, "" },
4758 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4759 { TYPE_EMPTY, NULL, "" },
4760 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4765 static struct TokenInfo setup_info_graphics[] =
4767 #if !defined(PLATFORM_ANDROID)
4768 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4769 #if defined(TARGET_SDL2)
4770 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4771 { TYPE_STRING, &window_size_text, "" },
4773 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4774 { TYPE_STRING, &screen_mode_text, "" },
4778 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4780 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4781 { TYPE_STRING, &scroll_delay_text, "" },
4783 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4785 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4786 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4787 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4788 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4789 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4790 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4791 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4792 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4793 { TYPE_EMPTY, NULL, "" },
4794 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4799 static struct TokenInfo setup_info_sound[] =
4801 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4802 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4803 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4804 { TYPE_EMPTY, NULL, "" },
4805 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4806 { TYPE_STRING, &volume_simple_text, "" },
4807 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4808 { TYPE_STRING, &volume_loops_text, "" },
4809 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4810 { TYPE_STRING, &volume_music_text, "" },
4811 { TYPE_EMPTY, NULL, "" },
4812 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4817 static struct TokenInfo setup_info_artwork[] =
4819 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4820 { TYPE_STRING, &graphics_set_name, "" },
4821 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4822 { TYPE_STRING, &sounds_set_name, "" },
4823 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4824 { TYPE_STRING, &music_set_name, "" },
4825 { TYPE_EMPTY, NULL, "" },
4828 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4829 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4830 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4832 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4833 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4834 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4835 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4838 { TYPE_STRING, NULL, "Override Level Artwork:"},
4839 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4840 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4841 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4843 { TYPE_EMPTY, NULL, "" },
4844 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4849 static struct TokenInfo setup_info_input[] =
4851 { TYPE_SWITCH, NULL, "Player:" },
4852 { TYPE_SWITCH, NULL, "Device:" },
4853 { TYPE_ENTER_MENU, NULL, "" },
4854 { TYPE_EMPTY, NULL, "" },
4855 { TYPE_EMPTY, NULL, "" },
4856 { TYPE_EMPTY, NULL, "" },
4857 { TYPE_EMPTY, NULL, "" },
4858 { TYPE_EMPTY, NULL, "" },
4859 { TYPE_EMPTY, NULL, "" },
4860 { TYPE_EMPTY, NULL, "" },
4861 { TYPE_EMPTY, NULL, "" },
4862 { TYPE_EMPTY, NULL, "" },
4863 { TYPE_EMPTY, NULL, "" },
4864 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4869 static struct TokenInfo setup_info_shortcuts[] =
4871 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4872 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4873 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4874 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4875 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4876 { TYPE_EMPTY, NULL, "" },
4877 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4882 static struct TokenInfo setup_info_shortcuts_1[] =
4884 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4885 { TYPE_KEY, &setup.shortcut.save_game, "" },
4886 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4887 { TYPE_KEY, &setup.shortcut.load_game, "" },
4888 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4889 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4890 { TYPE_EMPTY, NULL, "" },
4891 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4892 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4893 { TYPE_EMPTY, NULL, "" },
4894 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4899 static struct TokenInfo setup_info_shortcuts_2[] =
4901 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4902 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4903 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4904 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4905 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4906 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4907 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4908 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4909 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4910 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4911 { TYPE_EMPTY, NULL, "" },
4912 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4917 static struct TokenInfo setup_info_shortcuts_3[] =
4919 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
4920 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4921 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
4922 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
4923 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
4924 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4925 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
4926 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4927 { TYPE_KEYTEXT, NULL, "Record Tape:", },
4928 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4929 { TYPE_KEYTEXT, NULL, "Play Tape:", },
4930 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4931 { TYPE_EMPTY, NULL, "" },
4932 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4937 static struct TokenInfo setup_info_shortcuts_4[] =
4939 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
4940 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4941 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
4942 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4943 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
4944 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4945 { TYPE_EMPTY, NULL, "" },
4946 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4951 static struct TokenInfo setup_info_shortcuts_5[] =
4953 { TYPE_KEYTEXT, NULL, "Snap Left:", },
4954 { TYPE_KEY, &setup.shortcut.snap_left, "" },
4955 { TYPE_KEYTEXT, NULL, "Snap Right:", },
4956 { TYPE_KEY, &setup.shortcut.snap_right, "" },
4957 { TYPE_KEYTEXT, NULL, "Snap Up:", },
4958 { TYPE_KEY, &setup.shortcut.snap_up, "" },
4959 { TYPE_KEYTEXT, NULL, "Snap Down:", },
4960 { TYPE_KEY, &setup.shortcut.snap_down, "" },
4961 { TYPE_EMPTY, NULL, "" },
4962 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4967 static Key getSetupKey()
4969 Key key = KSYM_UNDEFINED;
4970 boolean got_key_event = FALSE;
4972 while (!got_key_event)
4974 if (PendingEvent()) /* got event */
4982 case EVENT_KEYPRESS:
4984 key = GetEventKey((KeyEvent *)&event, TRUE);
4986 /* press 'Escape' or 'Enter' to keep the existing key binding */
4987 if (key == KSYM_Escape || key == KSYM_Return)
4988 key = KSYM_UNDEFINED; /* keep old value */
4990 got_key_event = TRUE;
4994 case EVENT_KEYRELEASE:
4995 key_joystick_mapping = 0;
4999 HandleOtherEvents(&event);
5007 /* don't eat all CPU time */
5014 static int getSetupTextFont(int type)
5016 if (type & (TYPE_SWITCH |
5028 static int getSetupValueFont(int type, void *value)
5030 if (type & TYPE_KEY)
5031 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5032 else if (type & TYPE_STRING)
5033 return FONT_VALUE_2;
5034 else if (type & TYPE_ECS_AGA)
5035 return FONT_VALUE_1;
5036 else if (type & TYPE_BOOLEAN_STYLE)
5037 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5038 else if (type & TYPE_YES_NO_AUTO)
5039 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5040 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5042 return FONT_VALUE_1;
5045 static void drawSetupValue(int pos)
5047 boolean font_draw_xoffset_modified = FALSE;
5048 int font_draw_xoffset_old = -1;
5049 int xpos = MENU_SCREEN_VALUE_XPOS;
5050 int ypos = MENU_SCREEN_START_YPOS + pos;
5051 int startx = mSX + xpos * 32;
5052 int starty = mSY + ypos * 32;
5053 int font_nr, font_width;
5057 int type = setup_info[pos].type;
5058 void *value = setup_info[pos].value;
5059 char *value_string = getSetupValue(type, value);
5064 if (value_string == NULL)
5067 if (type & TYPE_KEY)
5069 xpos = MENU_SCREEN_START_XPOS;
5071 if (type & TYPE_QUERY)
5072 value_string = "<press key>";
5074 else if (type & TYPE_STRING)
5076 int max_value_len = (SCR_FIELDX - 2) * 2;
5078 xpos = MENU_SCREEN_START_XPOS;
5080 if (strlen(value_string) > max_value_len)
5081 value_string[max_value_len] = '\0';
5083 else if (type & TYPE_YES_NO_AUTO)
5085 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5088 startx = mSX + xpos * 32;
5089 starty = mSY + ypos * 32;
5090 font_nr = getSetupValueFont(type, value);
5091 font_width = getFontWidth(font_nr);
5093 font_height = getFontHeight(font_nr);
5096 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5097 if (setup_mode != SETUP_MODE_INPUT)
5099 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5100 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5101 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5102 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5103 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5104 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5105 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5106 boolean correct_font_draw_xoffset = FALSE;
5108 if (xpos == MENU_SCREEN_START_XPOS &&
5109 startx + font1_xoffset < text_startx + text_font_xoffset)
5110 correct_font_draw_xoffset = TRUE;
5112 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5113 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5114 correct_font_draw_xoffset = TRUE;
5116 /* check if setup value would overlap with setup text when printed */
5117 /* (this can happen for extreme/wrong values for font draw offset) */
5118 if (correct_font_draw_xoffset)
5120 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5121 font_draw_xoffset_modified = TRUE;
5123 if (type & TYPE_KEY)
5124 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5125 else if (!(type & TYPE_STRING))
5126 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5127 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5132 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5134 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5135 DrawText(startx + i * font_width, starty, " ", font_nr);
5138 DrawText(startx, starty, value_string, font_nr);
5140 if (font_draw_xoffset_modified)
5141 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5144 static void changeSetupValue(int pos, int dx)
5146 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5148 *(boolean *)setup_info[pos].value ^= TRUE;
5150 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5152 *(int *)setup_info[pos].value =
5154 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5155 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5156 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5157 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5159 else if (setup_info[pos].type & TYPE_KEY)
5163 setup_info[pos].type |= TYPE_QUERY;
5164 drawSetupValue(pos);
5165 setup_info[pos].type &= ~TYPE_QUERY;
5167 key = getSetupKey();
5168 if (key != KSYM_UNDEFINED)
5169 *(Key *)setup_info[pos].value = key;
5172 drawSetupValue(pos);
5174 // fullscreen state may have changed at this point
5175 if (setup_info[pos].value == &setup.fullscreen)
5176 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5179 static void DrawCursorAndText_Setup(int pos, boolean active)
5181 int xpos = MENU_SCREEN_START_XPOS;
5182 int ypos = MENU_SCREEN_START_YPOS + pos;
5183 int font_nr = getSetupTextFont(setup_info[pos].type);
5185 if (setup_info == setup_info_input)
5186 font_nr = FONT_MENU_1;
5189 font_nr = FONT_ACTIVE(font_nr);
5191 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5193 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5194 drawCursor(pos, active);
5197 static void DrawSetupScreen_Generic()
5199 boolean redraw_all = FALSE;
5200 char *title_string = NULL;
5204 CloseDoor(DOOR_CLOSE_2);
5206 if (redraw_mask & REDRAW_ALL)
5210 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5211 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5212 int2str(0, redraw_mask)));
5216 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5217 FadeOut(redraw_mask);
5219 FadeOut(REDRAW_FIELD);
5224 if (setup_mode == SETUP_MODE_MAIN)
5226 setup_info = setup_info_main;
5227 title_string = "Setup";
5229 else if (setup_mode == SETUP_MODE_GAME)
5231 setup_info = setup_info_game;
5232 title_string = "Setup Game";
5234 else if (setup_mode == SETUP_MODE_EDITOR)
5236 setup_info = setup_info_editor;
5237 title_string = "Setup Editor";
5239 else if (setup_mode == SETUP_MODE_GRAPHICS)
5241 setup_info = setup_info_graphics;
5242 title_string = "Setup Graphics";
5244 else if (setup_mode == SETUP_MODE_SOUND)
5246 setup_info = setup_info_sound;
5247 title_string = "Setup Sound";
5249 else if (setup_mode == SETUP_MODE_ARTWORK)
5251 setup_info = setup_info_artwork;
5252 title_string = "Custom Artwork";
5254 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5256 setup_info = setup_info_shortcuts;
5257 title_string = "Setup Shortcuts";
5259 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5261 setup_info = setup_info_shortcuts_1;
5262 title_string = "Setup Shortcuts";
5264 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5266 setup_info = setup_info_shortcuts_2;
5267 title_string = "Setup Shortcuts";
5269 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5271 setup_info = setup_info_shortcuts_3;
5272 title_string = "Setup Shortcuts";
5274 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5276 setup_info = setup_info_shortcuts_4;
5277 title_string = "Setup Shortcuts";
5279 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5281 setup_info = setup_info_shortcuts_5;
5282 title_string = "Setup Shortcuts";
5285 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5289 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5291 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5294 void *value_ptr = setup_info[i].value;
5296 /* set some entries to "unchangeable" according to other variables */
5297 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5298 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5299 (value_ptr == &setup.sound_music && !audio.music_available) ||
5300 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5301 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5302 (value_ptr == &window_size_text && !video.window_scaling_available))
5303 setup_info[i].type |= TYPE_GHOSTED;
5305 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5306 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5307 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5308 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5309 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5310 initCursor(i, IMG_MENU_BUTTON);
5312 DrawCursorAndText_Setup(i, FALSE);
5314 if (setup_info[i].type & TYPE_VALUE)
5321 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5322 "Joysticks deactivated in setup menu");
5326 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5330 redraw_mask = REDRAW_ALL;
5333 FadeIn(redraw_mask);
5335 FadeIn(REDRAW_FIELD);
5340 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5344 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5346 static int choice_store[MAX_SETUP_MODES];
5347 int choice = choice_store[setup_mode]; /* always starts with 0 */
5351 if (button == MB_MENU_INITIALIZE)
5353 /* advance to first valid menu entry */
5354 while (choice < num_setup_info &&
5355 setup_info[choice].type & TYPE_SKIP_ENTRY)
5357 choice_store[setup_mode] = choice;
5359 DrawCursorAndText_Setup(choice, TRUE);
5363 else if (button == MB_MENU_LEAVE)
5365 PlaySound(SND_MENU_ITEM_SELECTING);
5367 for (y = 0; y < num_setup_info; y++)
5369 if (setup_info[y].type & TYPE_LEAVE_MENU)
5371 void (*menu_callback_function)(void) = setup_info[y].value;
5375 menu_callback_function();
5377 break; /* absolutely needed because function changes 'setup_info'! */
5384 if (mx || my) /* mouse input */
5386 x = (mx - mSX) / 32;
5387 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5389 else if (dx || dy) /* keyboard input */
5393 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5395 if (setup_info[choice].type & menu_navigation_type ||
5396 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5397 setup_info[choice].type & TYPE_YES_NO_AUTO)
5398 button = MB_MENU_CHOICE;
5403 /* jump to next non-empty menu entry (up or down) */
5404 while (y > 0 && y < num_setup_info - 1 &&
5405 setup_info[y].type & TYPE_SKIP_ENTRY)
5409 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5413 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5415 PlaySound(SND_MENU_ITEM_ACTIVATING);
5417 DrawCursorAndText_Setup(choice, FALSE);
5418 DrawCursorAndText_Setup(y, TRUE);
5420 choice = choice_store[setup_mode] = y;
5423 else if (!(setup_info[y].type & TYPE_GHOSTED))
5425 PlaySound(SND_MENU_ITEM_SELECTING);
5427 /* when selecting key headline, execute function for key value change */
5428 if (setup_info[y].type & TYPE_KEYTEXT &&
5429 setup_info[y + 1].type & TYPE_KEY)
5432 /* when selecting string value, execute function for list selection */
5433 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5434 setup_info[y - 1].type & TYPE_ENTER_LIST)
5437 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5439 void (*menu_callback_function)(void) = setup_info[y].value;
5441 FadeSetFromType(setup_info[y].type);
5443 menu_callback_function();
5447 if (setup_info[y].type & TYPE_VALUE)
5448 changeSetupValue(y, dx);
5454 void DrawSetupScreen_Input()
5459 FadeOut(REDRAW_FIELD);
5465 setup_info = setup_info_input;
5468 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5472 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5473 "Joysticks deactivated on this screen");
5475 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5476 "Joysticks deactivated on this screen");
5481 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5483 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5486 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5487 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5488 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5489 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5490 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5491 initCursor(i, IMG_MENU_BUTTON);
5493 DrawCursorAndText_Setup(i, FALSE);
5497 DeactivateJoystickForCalibration();
5502 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5503 "Joysticks deactivated on this screen");
5505 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5506 "Joysticks deactivated on this screen");
5510 /* create gadgets for setup input menu screen */
5511 FreeScreenGadgets();
5512 CreateScreenGadgets();
5514 /* map gadgets for setup input menu screen */
5515 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5517 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5520 FadeIn(REDRAW_FIELD);
5526 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5528 if (device_name == NULL)
5531 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5534 if (strlen(device_name) > 1)
5536 char c1 = device_name[strlen(device_name) - 1];
5537 char c2 = device_name[strlen(device_name) - 2];
5539 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5540 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5543 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5544 strlen(device_name));
5547 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5550 static struct SetupKeyboardInfo custom_key;
5557 { &custom_key.left, "Joystick Left" },
5558 { &custom_key.right, "Joystick Right" },
5559 { &custom_key.up, "Joystick Up" },
5560 { &custom_key.down, "Joystick Down" },
5561 { &custom_key.snap, "Button 1" },
5562 { &custom_key.drop, "Button 2" }
5564 static char *joystick_name[MAX_PLAYERS] =
5571 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5575 custom_key = setup.input[player_nr].key;
5577 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5578 FONT_INPUT_1_ACTIVE);
5580 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5582 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5583 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5585 if (setup.input[player_nr].use_joystick)
5587 char *device_name = setup.input[player_nr].joy.device_name;
5588 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5589 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5591 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5592 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5596 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5597 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5600 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5602 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5603 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5604 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5605 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5607 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5608 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5609 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5610 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5611 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5612 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5614 for (i = 0; i < 6; i++)
5616 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5618 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5620 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5621 (setup.input[player_nr].use_joystick ?
5623 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5627 static int input_player_nr = 0;
5629 void HandleSetupScreen_Input_Player(int step, int direction)
5631 int old_player_nr = input_player_nr;
5634 new_player_nr = old_player_nr + step * direction;
5635 if (new_player_nr < 0)
5637 if (new_player_nr > MAX_PLAYERS - 1)
5638 new_player_nr = MAX_PLAYERS - 1;
5640 if (new_player_nr != old_player_nr)
5642 input_player_nr = new_player_nr;
5644 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5648 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5650 static int choice = 0;
5653 int pos_start = SETUPINPUT_SCREEN_POS_START;
5654 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5655 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5656 int pos_end = SETUPINPUT_SCREEN_POS_END;
5658 if (button == MB_MENU_INITIALIZE)
5660 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5662 DrawCursorAndText_Setup(choice, TRUE);
5666 else if (button == MB_MENU_LEAVE)
5668 setup_mode = SETUP_MODE_MAIN;
5675 if (mx || my) /* mouse input */
5677 x = (mx - mSX) / 32;
5678 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5680 else if (dx || dy) /* keyboard input */
5682 if (dx && choice == 0)
5683 x = (dx < 0 ? 10 : 12);
5684 else if ((dx && choice == 1) ||
5685 (dx == +1 && choice == 2) ||
5686 (dx == -1 && choice == pos_end))
5687 button = MB_MENU_CHOICE;
5691 if (y >= pos_empty1 && y <= pos_empty2)
5692 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5695 if (y == 0 && dx != 0 && button)
5697 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5699 else if (IN_VIS_FIELD(x, y) &&
5700 y >= pos_start && y <= pos_end &&
5701 !(y >= pos_empty1 && y <= pos_empty2))
5707 DrawCursorAndText_Setup(choice, FALSE);
5708 DrawCursorAndText_Setup(y, TRUE);
5710 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5719 char *device_name = setup.input[input_player_nr].joy.device_name;
5721 if (!setup.input[input_player_nr].use_joystick)
5723 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5725 setJoystickDeviceToNr(device_name, new_device_nr);
5726 setup.input[input_player_nr].use_joystick = TRUE;
5730 int device_nr = getJoystickNrFromDeviceName(device_name);
5731 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5733 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5734 setup.input[input_player_nr].use_joystick = FALSE;
5736 setJoystickDeviceToNr(device_name, new_device_nr);
5739 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5743 if (setup.input[input_player_nr].use_joystick)
5746 CalibrateJoystick(input_player_nr);
5749 CustomizeKeyboard(input_player_nr);
5751 else if (y == pos_end)
5757 setup_mode = SETUP_MODE_MAIN;
5764 void CustomizeKeyboard(int player_nr)
5768 boolean finished = FALSE;
5769 static struct SetupKeyboardInfo custom_key;
5774 } customize_step[] =
5776 { &custom_key.left, "Move Left" },
5777 { &custom_key.right, "Move Right" },
5778 { &custom_key.up, "Move Up" },
5779 { &custom_key.down, "Move Down" },
5780 { &custom_key.snap, "Snap Field" },
5781 { &custom_key.drop, "Drop Element" }
5784 /* read existing key bindings from player setup */
5785 custom_key = setup.input[player_nr].key;
5788 FadeOut(REDRAW_FIELD);
5792 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5800 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5801 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5802 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5803 "Key:", FONT_INPUT_1_ACTIVE);
5804 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5805 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5808 FadeIn(REDRAW_FIELD);
5815 if (PendingEvent()) /* got event */
5823 case EVENT_KEYPRESS:
5825 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5827 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5829 if (key == KSYM_Escape)
5830 FadeSkipNextFadeIn();
5836 /* all keys configured -- wait for "Escape" or "Return" key */
5840 /* press 'Enter' to keep the existing key binding */
5841 if (key == KSYM_Return)
5842 key = *customize_step[step_nr].key;
5844 /* check if key already used */
5845 for (i = 0; i < step_nr; i++)
5846 if (*customize_step[i].key == key)
5851 /* got new key binding */
5852 *customize_step[step_nr].key = key;
5853 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5855 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5856 getKeyNameFromKey(key), FONT_VALUE_1);
5859 /* un-highlight last query */
5860 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5861 customize_step[step_nr - 1].text, FONT_MENU_1);
5862 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5863 "Key:", FONT_MENU_1);
5865 /* press 'Enter' to leave */
5868 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5869 "Press Enter", FONT_TITLE_1);
5873 /* query next key binding */
5874 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5875 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5876 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5877 "Key:", FONT_INPUT_1_ACTIVE);
5878 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5879 getKeyNameFromKey(*customize_step[step_nr].key),
5884 case EVENT_KEYRELEASE:
5885 key_joystick_mapping = 0;
5889 HandleOtherEvents(&event);
5897 /* don't eat all CPU time */
5901 /* write new key bindings back to player setup */
5902 setup.input[player_nr].key = custom_key;
5905 DrawSetupScreen_Input();
5908 static boolean CalibrateJoystickMain(int player_nr)
5910 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5911 int new_joystick_xright = JOYSTICK_XMIDDLE;
5912 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5913 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5914 int new_joystick_xmiddle, new_joystick_ymiddle;
5916 int joystick_fd = joystick.fd[player_nr];
5917 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5918 boolean check[3][3];
5919 int check_remaining = 3 * 3;
5924 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5927 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5931 FadeOut(REDRAW_FIELD);
5935 for (y = 0; y < 3; y++)
5937 for (x = 0; x < 3; x++)
5939 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5940 check[x][y] = FALSE;
5944 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5945 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5946 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5947 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5948 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5949 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5950 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5952 joy_value = Joystick(player_nr);
5953 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5954 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5956 /* eventually uncalibrated center position (joystick could be uncentered) */
5957 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5960 new_joystick_xmiddle = joy_x;
5961 new_joystick_ymiddle = joy_y;
5963 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5965 FadeIn(REDRAW_FIELD);
5967 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5972 if (PendingEvent()) /* got event */
5980 case EVENT_KEYPRESS:
5981 switch (GetEventKey((KeyEvent *)&event, TRUE))
5984 if (check_remaining == 0)
5989 FadeSkipNextFadeIn();
5998 case EVENT_KEYRELEASE:
5999 key_joystick_mapping = 0;
6003 HandleOtherEvents(&event);
6008 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6011 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6012 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6013 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6014 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6016 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6017 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6018 setup.input[player_nr].joy.xright = new_joystick_xright;
6019 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6020 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6021 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6023 CheckJoystickData();
6025 joy_value = Joystick(player_nr);
6027 if (joy_value & JOY_BUTTON && check_remaining == 0)
6030 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6031 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6033 if (x != last_x || y != last_y)
6035 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6036 IMG_MENU_CALIBRATE_YELLOW, 0);
6037 DrawFixedGraphic(xpos + x, ypos + y,
6038 IMG_MENU_CALIBRATE_RED, 0);
6043 if (check_remaining > 0 && !check[x+1][y+1])
6045 check[x+1][y+1] = TRUE;
6051 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6052 setup.input[player_nr].joy.xleft,
6053 setup.input[player_nr].joy.xmiddle,
6054 setup.input[player_nr].joy.xright);
6055 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6056 setup.input[player_nr].joy.yupper,
6057 setup.input[player_nr].joy.ymiddle,
6058 setup.input[player_nr].joy.ylower);
6067 /* don't eat all CPU time */
6071 /* calibrated center position (joystick should now be centered) */
6072 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6075 new_joystick_xmiddle = joy_x;
6076 new_joystick_ymiddle = joy_y;
6081 DrawSetupScreen_Input();
6084 /* wait until the last pressed button was released */
6085 while (Joystick(player_nr) & JOY_BUTTON)
6087 if (PendingEvent()) /* got event */
6092 HandleOtherEvents(&event);
6101 void CalibrateJoystick(int player_nr)
6103 if (!CalibrateJoystickMain(player_nr))
6105 char *device_name = setup.input[player_nr].joy.device_name;
6106 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6107 int xpos = mSX - SX;
6108 int ypos = mSY - SY;
6112 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6113 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6116 Delay(2000); /* show error message for a short time */
6122 DrawSetupScreen_Input();
6126 void DrawSetupScreen()
6128 DeactivateJoystick();
6130 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6132 if (setup_mode == SETUP_MODE_INPUT)
6133 DrawSetupScreen_Input();
6134 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6135 DrawChooseTree(&game_speed_current);
6136 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6137 DrawChooseTree(&screen_mode_current);
6138 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6139 DrawChooseTree(&window_size_current);
6140 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6141 DrawChooseTree(&scroll_delay_current);
6142 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6143 DrawChooseTree(&artwork.gfx_current);
6144 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6145 DrawChooseTree(&artwork.snd_current);
6146 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6147 DrawChooseTree(&artwork.mus_current);
6148 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6149 DrawChooseTree(&volume_simple_current);
6150 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6151 DrawChooseTree(&volume_loops_current);
6152 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6153 DrawChooseTree(&volume_music_current);
6155 DrawSetupScreen_Generic();
6161 void RedrawSetupScreenAfterFullscreenToggle()
6164 if (setup_mode == SETUP_MODE_GRAPHICS ||
6165 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6167 // update "setup.window_scaling_percent" from list selection
6168 execSetupGraphics_setWindowSizes(TRUE);
6173 if (setup_mode == SETUP_MODE_GRAPHICS)
6178 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6180 if (setup_mode == SETUP_MODE_INPUT)
6181 HandleSetupScreen_Input(mx, my, dx, dy, button);
6182 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6183 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6184 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6185 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6186 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6187 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6188 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6189 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6190 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6191 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6192 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6193 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6194 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6195 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6196 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6197 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6198 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6199 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6200 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6201 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6203 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6210 void HandleGameActions()
6212 if (game_status != GAME_MODE_PLAYING)
6215 GameActions(); /* main game loop */
6217 if (tape.auto_play && !tape.playing)
6218 AutoPlayTape(); /* continue automatically playing next tape */
6222 /* ---------- new screen button stuff -------------------------------------- */
6224 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6229 case SCREEN_CTRL_ID_PREV_LEVEL:
6230 *x = mSX + menu.main.button.prev_level.x;
6231 *y = mSY + menu.main.button.prev_level.y;
6234 case SCREEN_CTRL_ID_NEXT_LEVEL:
6235 *x = mSX + menu.main.button.next_level.x;
6236 *y = mSY + menu.main.button.next_level.y;
6239 case SCREEN_CTRL_ID_PREV_LEVEL:
6240 *x = mSX + TILEX * getPrevlevelButtonPos();
6241 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6244 case SCREEN_CTRL_ID_NEXT_LEVEL:
6245 *x = mSX + TILEX * getNextLevelButtonPos();
6246 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6250 case SCREEN_CTRL_ID_PREV_PLAYER:
6251 *x = mSX + TILEX * 10;
6252 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6255 case SCREEN_CTRL_ID_NEXT_PLAYER:
6256 *x = mSX + TILEX * 12;
6257 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6261 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6267 int gfx_unpressed, gfx_pressed;
6268 void (*get_gadget_position)(int *, int *, int);
6272 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6275 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6276 getScreenMenuButtonPos,
6277 SCREEN_CTRL_ID_PREV_LEVEL,
6282 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6283 getScreenMenuButtonPos,
6284 SCREEN_CTRL_ID_NEXT_LEVEL,
6289 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6290 getScreenMenuButtonPos,
6291 SCREEN_CTRL_ID_PREV_PLAYER,
6296 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6297 getScreenMenuButtonPos,
6298 SCREEN_CTRL_ID_NEXT_PLAYER,
6306 int gfx_unpressed, gfx_pressed;
6310 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6313 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6315 -1, -1, /* these values are not constant, but can change at runtime */
6317 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6319 SCREEN_CTRL_ID_SCROLL_UP,
6323 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6325 -1, -1, /* these values are not constant, but can change at runtime */
6327 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6329 SCREEN_CTRL_ID_SCROLL_DOWN,
6336 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6337 Bitmap **gfx_unpressed, **gfx_pressed;
6339 int gfx_unpressed, gfx_pressed;
6346 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6349 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6350 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6352 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6355 -1, -1, /* these values are not constant, but can change at runtime */
6356 -1, -1, /* these values are not constant, but can change at runtime */
6358 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6359 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6361 GD_TYPE_SCROLLBAR_VERTICAL,
6362 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6363 "scroll level series vertically"
6367 static void CreateScreenMenubuttons()
6369 struct GadgetInfo *gi;
6370 unsigned int event_mask;
6373 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6375 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6376 int gfx_unpressed, gfx_pressed;
6377 int x, y, width, height;
6378 int gd_x1, gd_x2, gd_y1, gd_y2;
6379 int id = menubutton_info[i].gadget_id;
6381 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6383 menubutton_info[i].get_gadget_position(&x, &y, id);
6385 width = SC_MENUBUTTON_XSIZE;
6386 height = SC_MENUBUTTON_YSIZE;
6388 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6389 gfx_pressed = menubutton_info[i].gfx_pressed;
6390 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6391 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6392 gd_x1 = graphic_info[gfx_unpressed].src_x;
6393 gd_y1 = graphic_info[gfx_unpressed].src_y;
6394 gd_x2 = graphic_info[gfx_pressed].src_x;
6395 gd_y2 = graphic_info[gfx_pressed].src_y;
6397 gi = CreateGadget(GDI_CUSTOM_ID, id,
6398 GDI_CUSTOM_TYPE_ID, i,
6399 GDI_INFO_TEXT, menubutton_info[i].infotext,
6404 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6405 GDI_STATE, GD_BUTTON_UNPRESSED,
6406 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6407 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6408 GDI_DIRECT_DRAW, FALSE,
6409 GDI_EVENT_MASK, event_mask,
6410 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6414 Error(ERR_EXIT, "cannot create gadget");
6416 screen_gadget[id] = gi;
6420 static void CreateScreenScrollbuttons()
6422 struct GadgetInfo *gi;
6423 unsigned int event_mask;
6426 /* these values are not constant, but can change at runtime */
6427 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6428 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6429 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6430 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6432 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6434 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6435 int gfx_unpressed, gfx_pressed;
6436 int x, y, width, height;
6437 int gd_x1, gd_x2, gd_y1, gd_y2;
6438 int id = scrollbutton_info[i].gadget_id;
6440 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6442 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6443 y = mSY + scrollbutton_info[i].y;
6444 width = SC_SCROLLBUTTON_XSIZE;
6445 height = SC_SCROLLBUTTON_YSIZE;
6447 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6448 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6449 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6451 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6452 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6453 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6454 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6455 gd_x1 = graphic_info[gfx_unpressed].src_x;
6456 gd_y1 = graphic_info[gfx_unpressed].src_y;
6457 gd_x2 = graphic_info[gfx_pressed].src_x;
6458 gd_y2 = graphic_info[gfx_pressed].src_y;
6460 gi = CreateGadget(GDI_CUSTOM_ID, id,
6461 GDI_CUSTOM_TYPE_ID, i,
6462 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6467 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6468 GDI_STATE, GD_BUTTON_UNPRESSED,
6469 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6470 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6471 GDI_DIRECT_DRAW, FALSE,
6472 GDI_EVENT_MASK, event_mask,
6473 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6477 Error(ERR_EXIT, "cannot create gadget");
6479 screen_gadget[id] = gi;
6483 static void CreateScreenScrollbars()
6487 /* these values are not constant, but can change at runtime */
6488 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6489 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6490 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6491 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6493 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6495 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6496 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6497 int gfx_unpressed, gfx_pressed;
6499 int x, y, width, height;
6500 int gd_x1, gd_x2, gd_y1, gd_y2;
6501 struct GadgetInfo *gi;
6502 int items_max, items_visible, item_position;
6503 unsigned int event_mask;
6504 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6505 int id = scrollbar_info[i].gadget_id;
6507 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6509 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6510 y = mSY + scrollbar_info[i].y;
6511 width = scrollbar_info[i].width;
6512 height = scrollbar_info[i].height;
6514 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6515 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6517 items_max = num_page_entries;
6518 items_visible = num_page_entries;
6521 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6522 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6523 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6529 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6530 gfx_pressed = scrollbar_info[i].gfx_pressed;
6531 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6532 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6533 gd_x1 = graphic_info[gfx_unpressed].src_x;
6534 gd_y1 = graphic_info[gfx_unpressed].src_y;
6535 gd_x2 = graphic_info[gfx_pressed].src_x;
6536 gd_y2 = graphic_info[gfx_pressed].src_y;
6539 gi = CreateGadget(GDI_CUSTOM_ID, id,
6540 GDI_CUSTOM_TYPE_ID, i,
6541 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6546 GDI_TYPE, scrollbar_info[i].type,
6547 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6548 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6549 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6551 GDI_WHEEL_AREA_X, SX,
6552 GDI_WHEEL_AREA_Y, SY,
6553 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6554 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6556 GDI_WHEEL_AREA_X, 0,
6557 GDI_WHEEL_AREA_Y, 0,
6558 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6559 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6561 GDI_STATE, GD_BUTTON_UNPRESSED,
6562 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6563 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6564 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6565 GDI_DIRECT_DRAW, FALSE,
6566 GDI_EVENT_MASK, event_mask,
6567 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6571 Error(ERR_EXIT, "cannot create gadget");
6573 screen_gadget[id] = gi;
6577 void CreateScreenGadgets()
6579 int last_game_status = game_status; /* save current game status */
6581 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6584 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6586 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6588 /* copy pointers to clip mask and GC */
6589 scrollbar_bitmap[i]->clip_mask =
6590 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6591 scrollbar_bitmap[i]->stored_clip_gc =
6592 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6594 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6595 scrollbar_bitmap[i],
6596 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6597 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6598 TILEX, TILEY, 0, 0);
6602 CreateScreenMenubuttons();
6605 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6606 game_status = GAME_MODE_LEVELS;
6609 CreateScreenScrollbuttons();
6610 CreateScreenScrollbars();
6612 game_status = last_game_status; /* restore current game status */
6615 void FreeScreenGadgets()
6619 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6620 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6622 /* prevent freeing clip mask and GC twice */
6623 scrollbar_bitmap[i]->clip_mask = None;
6624 scrollbar_bitmap[i]->stored_clip_gc = None;
6626 FreeBitmap(scrollbar_bitmap[i]);
6630 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6631 FreeGadget(screen_gadget[i]);
6634 void MapScreenMenuGadgets(int screen_mask)
6638 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6639 if (screen_mask & menubutton_info[i].screen_mask)
6640 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6643 void MapScreenTreeGadgets(TreeInfo *ti)
6645 int num_entries = numTreeInfoInGroup(ti);
6648 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6651 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6652 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6654 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6655 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6658 static void HandleScreenGadgets(struct GadgetInfo *gi)
6660 int id = gi->custom_id;
6661 int button = gi->event.button;
6662 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6666 case SCREEN_CTRL_ID_PREV_LEVEL:
6667 HandleMainMenu_SelectLevel(step, -1);
6670 case SCREEN_CTRL_ID_NEXT_LEVEL:
6671 HandleMainMenu_SelectLevel(step, +1);
6674 case SCREEN_CTRL_ID_PREV_PLAYER:
6675 HandleSetupScreen_Input_Player(step, -1);
6678 case SCREEN_CTRL_ID_NEXT_PLAYER:
6679 HandleSetupScreen_Input_Player(step, +1);
6682 case SCREEN_CTRL_ID_SCROLL_UP:
6683 if (game_status == GAME_MODE_LEVELS)
6684 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6685 else if (game_status == GAME_MODE_LEVELNR)
6686 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6687 else if (game_status == GAME_MODE_SETUP)
6688 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6691 case SCREEN_CTRL_ID_SCROLL_DOWN:
6692 if (game_status == GAME_MODE_LEVELS)
6693 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6694 else if (game_status == GAME_MODE_LEVELNR)
6695 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6696 else if (game_status == GAME_MODE_SETUP)
6697 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6700 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6701 if (game_status == GAME_MODE_LEVELS)
6702 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6703 else if (game_status == GAME_MODE_LEVELNR)
6704 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6705 else if (game_status == GAME_MODE_SETUP)
6706 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);