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 FadeSetLeaveScreen();
1322 /* do not fade out here -- function may continue and fade on editor screen */
1325 FadeSoundsAndMusic();
1327 KeyboardAutoRepeatOn();
1330 SetDrawDeactivationMask(REDRAW_NONE);
1331 SetDrawBackgroundMask(REDRAW_FIELD);
1333 audio.sound_deactivated = FALSE;
1337 /* needed if last screen was the playing screen, invoked from level editor */
1338 if (level_editor_test_game)
1340 game_status = GAME_MODE_EDITOR;
1346 /* needed if last screen was the setup screen and fullscreen state changed */
1347 ToggleFullscreenIfNeeded();
1349 /* leveldir_current may be invalid (level group, parent link) */
1350 if (!validLevelSeries(leveldir_current))
1351 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1353 if (leveldir_current != leveldir_last_valid)
1354 levelset_has_changed = TRUE;
1356 /* store valid level series information */
1357 leveldir_last_valid = leveldir_current;
1359 init_last = init; /* switch to new busy animation */
1361 /* needed if last screen (level choice) changed graphics, sounds or music */
1362 ReloadCustomArtwork(0);
1364 if (redraw_mask & REDRAW_ALL)
1365 fade_mask = REDRAW_ALL;
1370 /* needed if last screen was the editor screen */
1371 UndrawSpecialEditorDoor();
1373 if (fade_mask == REDRAW_FIELD)
1379 /* needed if different viewport properties defined for menues */
1380 ChangeViewportPropertiesIfNeeded();
1383 #if defined(TARGET_SDL)
1384 SetDrawtoField(DRAW_BACKBUFFER);
1387 if (CheckTitleScreen(levelset_has_changed))
1389 game_status = GAME_MODE_TITLE;
1396 /* level_nr may have been set to value over handicap with level editor */
1397 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1398 level_nr = leveldir_current->handicap_level;
1400 LoadLevel(level_nr);
1401 LoadScore(level_nr);
1403 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1406 if (fade_mask == REDRAW_ALL)
1408 // int door_state = GetDoorState();
1412 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1418 InitializeMainControls();
1420 DrawCursorAndText_Main(-1, FALSE);
1421 DrawPreviewLevel(TRUE);
1423 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1426 if (TAPE_IS_EMPTY(tape))
1428 DrawCompleteVideoDisplay();
1433 /* create gadgets for main menu screen */
1434 FreeScreenGadgets();
1435 CreateScreenGadgets();
1437 /* map gadgets for main menu screen */
1439 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1442 if (fade_mask == REDRAW_ALL)
1444 int door_state = GetDoorState();
1446 // RedrawBackground();
1448 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1452 DrawMaskedBorder(REDRAW_ALL);
1458 /* update screen area with special editor door */
1459 redraw_mask |= REDRAW_ALL;
1463 SetMouseCursor(CURSOR_DEFAULT);
1467 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1470 void DrawAndFadeInMainMenu(int fade_mask)
1472 DrawMainMenuExt(fade_mask, TRUE);
1477 DrawMainMenuExt(REDRAW_ALL, FALSE);
1480 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1481 static void gotoTopLevelDir()
1483 /* move upwards to top level directory */
1484 while (leveldir_current->node_parent)
1486 /* write a "path" into level tree for easy navigation to last level */
1487 if (leveldir_current->node_parent->node_group->cl_first == -1)
1489 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1490 int leveldir_pos = posTreeInfo(leveldir_current);
1491 int num_page_entries;
1492 int cl_first, cl_cursor;
1494 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1495 num_page_entries = num_leveldirs;
1497 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1499 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1500 cl_cursor = leveldir_pos - cl_first;
1502 leveldir_current->node_parent->node_group->cl_first = cl_first;
1503 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1506 leveldir_current = leveldir_current->node_parent;
1511 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1513 static unsigned int title_delay = 0;
1514 static int title_screen_nr = 0;
1515 static int last_sound = -1, last_music = -1;
1516 boolean return_to_main_menu = FALSE;
1517 boolean use_fading_main_menu = TRUE;
1518 struct TitleControlInfo *tci;
1519 struct TitleFadingInfo fading_default;
1520 struct TitleFadingInfo fading_last = fading;
1521 struct TitleFadingInfo fading_next;
1524 if (button == MB_MENU_INITIALIZE)
1527 title_screen_nr = 0;
1528 tci = &title_controls[title_screen_nr];
1530 last_sound = SND_UNDEFINED;
1531 last_music = MUS_UNDEFINED;
1533 if (game_status == GAME_MODE_INFO)
1535 if (num_title_screens == 0)
1537 DrawInfoScreen_NotAvailable("Title screen information:",
1538 "No title screen for this level set.");
1543 FadeSoundsAndMusic();
1546 FadeOut(REDRAW_ALL);
1551 DrawTitleScreenImage(tci->local_nr, tci->initial);
1553 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1555 fading_default = (tci->initial ? title_initial_default : title_default);
1557 fading = fading_next = getTitleFading(tci);
1561 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1562 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1564 fading.fade_mode = FADE_MODE_FADE;
1565 fading.fade_delay = fading_default.fade_delay;
1568 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1569 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1570 fading.fade_mode = FADE_MODE_FADE;
1575 sound = getTitleSound(tci);
1576 music = getTitleMusic(tci);
1578 if (sound != last_sound)
1579 PlayMenuSoundExt(sound);
1580 if (music != last_music)
1581 PlayMenuMusicExt(music);
1587 SetMouseCursor(CURSOR_NONE);
1593 fading = fading_next;
1595 DelayReached(&title_delay, 0); /* reset delay counter */
1601 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1602 button = MB_MENU_CHOICE;
1604 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1605 button = MB_MENU_CHOICE;
1608 if (button == MB_MENU_LEAVE)
1610 return_to_main_menu = TRUE;
1611 use_fading_main_menu = FALSE;
1613 else if (button == MB_MENU_CHOICE)
1615 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1618 FadeOut(REDRAW_FIELD);
1621 FadeSetEnterScreen();
1623 info_mode = INFO_MODE_MAIN;
1624 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1630 tci = &title_controls[title_screen_nr];
1632 if (title_screen_nr < num_title_screens)
1634 sound = getTitleSound(tci);
1635 music = getTitleMusic(tci);
1637 if (sound == SND_UNDEFINED || sound != last_sound)
1639 if (music == MUS_UNDEFINED || music != last_music)
1643 FadeOut(REDRAW_ALL);
1647 DrawTitleScreenImage(tci->local_nr, tci->initial);
1649 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1651 fading_next = getTitleFading(tci);
1654 sound = getTitleSound(tci);
1655 music = getTitleMusic(tci);
1657 if (sound != last_sound)
1658 PlayMenuSoundExt(sound);
1659 if (music != last_music)
1660 PlayMenuMusicExt(music);
1667 /* last screen already faded out, next screen has no animation */
1668 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1669 fading_next.fade_mode == FADE_MODE_NONE)
1670 fading = fading_next;
1672 /* last screen already faded out, next screen has no animation */
1673 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1674 fading_next.fade_mode == FADE_MODE_NONE)
1675 fading = fading_next;
1682 fading = fading_next;
1684 DelayReached(&title_delay, 0); /* reset delay counter */
1688 FadeSoundsAndMusic();
1690 return_to_main_menu = TRUE;
1694 if (return_to_main_menu)
1700 SetMouseCursor(CURSOR_DEFAULT);
1702 if (game_status == GAME_MODE_INFO)
1705 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1708 info_mode = INFO_MODE_MAIN;
1709 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1711 else /* default: return to main menu */
1714 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1717 game_status = GAME_MODE_MAIN;
1718 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1723 void HandleMainMenu_SelectLevel(int step, int direction)
1725 int old_level_nr = level_nr;
1728 new_level_nr = old_level_nr + step * direction;
1729 if (new_level_nr < leveldir_current->first_level)
1730 new_level_nr = leveldir_current->first_level;
1731 if (new_level_nr > leveldir_current->last_level)
1732 new_level_nr = leveldir_current->last_level;
1734 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1736 /* skipping levels is only allowed when trying to skip single level */
1737 if (setup.skip_levels && step == 1 &&
1738 Request("Level still unsolved ! Skip despite handicap ?", REQ_ASK))
1740 leveldir_current->handicap_level++;
1741 SaveLevelSetup_SeriesInfo();
1744 new_level_nr = leveldir_current->handicap_level;
1747 if (new_level_nr != old_level_nr)
1749 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1751 PlaySound(SND_MENU_ITEM_SELECTING);
1753 level_nr = new_level_nr;
1755 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1756 int2str(level_nr, menu.main.text.level_number.size),
1757 mci->pos_text->font);
1759 LoadLevel(level_nr);
1760 DrawPreviewLevel(TRUE);
1764 DrawCompleteVideoDisplay();
1766 /* needed because DrawPreviewLevel() takes some time */
1772 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1774 static int choice = MAIN_CONTROL_GAME;
1778 if (button == MB_MENU_INITIALIZE)
1780 DrawCursorAndText_Main(choice, TRUE);
1785 if (mx || my) /* mouse input */
1789 for (i = 0; main_controls[i].nr != -1; i++)
1792 printf("::: check click (%d, %d) for %d [%d] ...\n",
1793 mx - mSX, my - mSY, i, main_controls[i].nr);
1796 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1797 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1798 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1801 printf("::: inside %d\n", i);
1804 pos = main_controls[i].nr;
1810 else if (dx || dy) /* keyboard input */
1812 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1813 choice == MAIN_CONTROL_SETUP))
1814 button = MB_MENU_CHOICE;
1819 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1821 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1823 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1825 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1827 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1829 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1831 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1833 game_status = GAME_MODE_LEVELNR;
1835 DrawChooseLevelNr();
1837 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1843 PlaySound(SND_MENU_ITEM_ACTIVATING);
1845 DrawCursorAndText_Main(choice, FALSE);
1846 DrawCursorAndText_Main(pos, TRUE);
1853 PlaySound(SND_MENU_ITEM_SELECTING);
1855 if (pos == MAIN_CONTROL_NAME)
1857 game_status = GAME_MODE_PSEUDO_TYPENAME;
1859 HandleTypeName(strlen(setup.player_name), 0);
1861 else if (pos == MAIN_CONTROL_LEVELS)
1865 game_status = GAME_MODE_LEVELS;
1867 SaveLevelSetup_LastSeries();
1868 SaveLevelSetup_SeriesInfo();
1870 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1874 DrawChooseLevelSet();
1877 else if (pos == MAIN_CONTROL_SCORES)
1879 game_status = GAME_MODE_SCORES;
1883 else if (pos == MAIN_CONTROL_EDITOR)
1885 if (leveldir_current->readonly &&
1886 !strEqual(setup.player_name, "Artsoft"))
1887 Request("This level is read only !", REQ_CONFIRM);
1889 game_status = GAME_MODE_EDITOR;
1891 FadeSetEnterScreen();
1894 /* needed if different viewport properties defined for editor */
1895 ChangeViewportPropertiesIfNeeded();
1900 else if (pos == MAIN_CONTROL_INFO)
1902 game_status = GAME_MODE_INFO;
1903 info_mode = INFO_MODE_MAIN;
1907 else if (pos == MAIN_CONTROL_GAME)
1909 StartGameActions(options.network, setup.autorecord, level.random_seed);
1911 else if (pos == MAIN_CONTROL_SETUP)
1913 game_status = GAME_MODE_SETUP;
1914 setup_mode = SETUP_MODE_MAIN;
1918 else if (pos == MAIN_CONTROL_QUIT)
1920 SaveLevelSetup_LastSeries();
1921 SaveLevelSetup_SeriesInfo();
1923 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
1924 game_status = GAME_MODE_QUIT;
1929 if (game_status == GAME_MODE_MAIN)
1931 DrawPreviewLevel(FALSE);
1937 /* ========================================================================= */
1938 /* info screen functions */
1939 /* ========================================================================= */
1941 static struct TokenInfo *info_info;
1942 static int num_info_info;
1944 static void execInfoTitleScreen()
1946 info_mode = INFO_MODE_TITLE;
1951 static void execInfoElements()
1953 info_mode = INFO_MODE_ELEMENTS;
1958 static void execInfoMusic()
1960 info_mode = INFO_MODE_MUSIC;
1965 static void execInfoCredits()
1967 info_mode = INFO_MODE_CREDITS;
1972 static void execInfoProgram()
1974 info_mode = INFO_MODE_PROGRAM;
1979 static void execInfoVersion()
1981 info_mode = INFO_MODE_VERSION;
1986 static void execInfoLevelSet()
1988 info_mode = INFO_MODE_LEVELSET;
1993 static void execExitInfo()
1995 game_status = GAME_MODE_MAIN;
1997 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2000 static struct TokenInfo info_info_main[] =
2002 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2003 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2004 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2005 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2006 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2007 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2008 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2009 { TYPE_EMPTY, NULL, "" },
2010 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2015 static void DrawCursorAndText_Info(int pos, boolean active)
2017 int xpos = MENU_SCREEN_START_XPOS;
2018 int ypos = MENU_SCREEN_START_YPOS + pos;
2019 int font_nr = FONT_MENU_1;
2022 font_nr = FONT_ACTIVE(font_nr);
2024 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2026 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2027 drawCursor(pos, active);
2030 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2035 CloseDoor(DOOR_CLOSE_2);
2037 /* (needed after displaying title screens which disable auto repeat) */
2038 KeyboardAutoRepeatOn();
2040 FadeSetLeaveScreen();
2047 if (fade_mask == REDRAW_ALL)
2051 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2057 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2059 info_info = info_info_main;
2063 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2065 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2068 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2069 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2070 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2071 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2072 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2073 initCursor(i, IMG_MENU_BUTTON);
2075 DrawCursorAndText_Info(i, FALSE);
2080 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2085 DrawMaskedBorder(fade_mask);
2092 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2094 static int choice_store[MAX_INFO_MODES];
2095 int choice = choice_store[info_mode]; /* always starts with 0 */
2099 if (button == MB_MENU_INITIALIZE)
2101 /* advance to first valid menu entry */
2102 while (choice < num_info_info &&
2103 info_info[choice].type & TYPE_SKIP_ENTRY)
2105 choice_store[info_mode] = choice;
2107 DrawCursorAndText_Info(choice, TRUE);
2111 else if (button == MB_MENU_LEAVE)
2113 for (y = 0; y < num_info_info; y++)
2115 if (info_info[y].type & TYPE_LEAVE_MENU)
2117 void (*menu_callback_function)(void) = info_info[y].value;
2121 menu_callback_function();
2123 break; /* absolutely needed because function changes 'info_info'! */
2130 if (mx || my) /* mouse input */
2132 x = (mx - mSX) / 32;
2133 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2135 else if (dx || dy) /* keyboard input */
2139 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2141 if (info_info[choice].type & menu_navigation_type ||
2142 info_info[choice].type & TYPE_ENTER_SCREEN ||
2143 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2144 info_info[choice].type & TYPE_YES_NO_AUTO)
2145 button = MB_MENU_CHOICE;
2150 /* jump to next non-empty menu entry (up or down) */
2151 while (y > 0 && y < num_info_info - 1 &&
2152 info_info[y].type & TYPE_SKIP_ENTRY)
2156 if (IN_VIS_FIELD(x, y) &&
2157 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2163 PlaySound(SND_MENU_ITEM_ACTIVATING);
2165 DrawCursorAndText_Info(choice, FALSE);
2166 DrawCursorAndText_Info(y, TRUE);
2168 choice = choice_store[info_mode] = y;
2171 else if (!(info_info[y].type & TYPE_GHOSTED))
2173 PlaySound(SND_MENU_ITEM_SELECTING);
2175 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2177 void (*menu_callback_function)(void) = info_info[choice].value;
2179 FadeSetFromType(info_info[y].type);
2181 menu_callback_function();
2187 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2189 int ystart1 = mSY - SY + 100;
2190 int ystart2 = mSY - SY + 150;
2191 int ybottom = mSY - SY + SYSIZE - 20;
2193 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2195 FadeOut(REDRAW_FIELD);
2200 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2201 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2203 DrawTextSCentered(ybottom, FONT_TEXT_4,
2204 "Press any key or button for info menu");
2206 FadeIn(REDRAW_FIELD);
2209 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2211 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2212 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2213 int xstart = mSX + 16;
2214 int ystart1 = mSY - SY + 100;
2215 int ystart2 = mSY + 64 + 2 * 32;
2216 int ybottom = mSY - SY + SYSIZE - 20;
2217 int ystep = TILEY + 4;
2218 int element, action, direction;
2226 for (i = 0; i < MAX_INFO_ELEMENTS_ON_SCREEN; i++)
2227 infoscreen_step[i] = infoscreen_frame[i] = 0;
2232 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2234 DrawTextSCentered(ybottom, FONT_TEXT_4,
2235 "Press any key or button for next page");
2241 while (helpanim_info[j].element != HELPANIM_LIST_END)
2243 if (i >= start + MAX_INFO_ELEMENTS_ON_SCREEN ||
2248 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2257 j += infoscreen_step[i - start];
2259 element = helpanim_info[j].element;
2260 action = helpanim_info[j].action;
2261 direction = helpanim_info[j].direction;
2264 element = EL_UNKNOWN;
2266 if (action != -1 && direction != -1)
2267 graphic = el_act_dir2img(element, action, direction);
2268 else if (action != -1)
2269 graphic = el_act2img(element, action);
2270 else if (direction != -1)
2271 graphic = el_dir2img(element, direction);
2273 graphic = el2img(element);
2275 delay = helpanim_info[j++].delay;
2280 if (infoscreen_frame[i - start] == 0)
2283 infoscreen_frame[i - start] = delay - 1;
2287 sync_frame = delay - infoscreen_frame[i - start];
2288 infoscreen_frame[i - start]--;
2291 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2293 if (!infoscreen_frame[i - start])
2294 infoscreen_step[i - start] = 0;
2298 if (!infoscreen_frame[i - start])
2299 infoscreen_step[i - start]++;
2300 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2306 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2308 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2309 graphic, sync_frame, USE_MASKING);
2312 DrawInfoScreen_HelpText(element, action, direction, i - start);
2317 redraw_mask |= REDRAW_FIELD;
2322 static char *getHelpText(int element, int action, int direction)
2324 char token[MAX_LINE_LEN];
2326 strcpy(token, element_info[element].token_name);
2329 strcat(token, element_action_info[action].suffix);
2331 if (direction != -1)
2332 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2334 return getHashEntry(helptext_info, token);
2337 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2339 int font_nr = FONT_INFO_ELEMENTS;
2340 int font_width = getFontWidth(font_nr);
2341 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2342 int sy = mSY + 65 + 2 * 32 + 1;
2343 int ystep = TILEY + 4;
2344 int pad_x = sx - SX;
2345 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2346 int max_lines_per_text = 2;
2349 if (action != -1 && direction != -1) /* element.action.direction */
2350 text = getHelpText(element, action, direction);
2352 if (text == NULL && action != -1) /* element.action */
2353 text = getHelpText(element, action, -1);
2355 if (text == NULL && direction != -1) /* element.direction */
2356 text = getHelpText(element, -1, direction);
2358 if (text == NULL) /* base element */
2359 text = getHelpText(element, -1, -1);
2361 if (text == NULL) /* not found */
2362 text = "No description available";
2364 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2365 sy += getFontHeight(font_nr) / 2;
2367 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2368 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2369 TRUE, FALSE, FALSE);
2372 void DrawInfoScreen_TitleScreen()
2377 void HandleInfoScreen_TitleScreen(int button)
2379 HandleTitleScreen(0, 0, 0, 0, button);
2382 void DrawInfoScreen_Elements()
2384 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2386 FadeOut(REDRAW_FIELD);
2391 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2393 FadeIn(REDRAW_FIELD);
2398 void HandleInfoScreen_Elements(int button)
2400 static unsigned int info_delay = 0;
2401 static int num_anims;
2402 static int num_pages;
2404 int anims_per_page = MAX_INFO_ELEMENTS_ON_SCREEN;
2407 if (button == MB_MENU_INITIALIZE)
2409 boolean new_element = TRUE;
2413 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2415 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2417 else if (new_element)
2420 new_element = FALSE;
2424 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2428 if (button == MB_MENU_LEAVE)
2430 PlaySound(SND_MENU_ITEM_SELECTING);
2432 info_mode = INFO_MODE_MAIN;
2437 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2439 if (button != MB_MENU_INITIALIZE)
2441 PlaySound(SND_MENU_ITEM_SELECTING);
2446 if (page >= num_pages)
2448 FadeSoundsAndMusic();
2450 info_mode = INFO_MODE_MAIN;
2451 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2458 FadeSetNextScreen();
2461 if (button != MB_MENU_INITIALIZE)
2462 FadeOut(REDRAW_FIELD);
2464 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2466 if (button != MB_MENU_INITIALIZE)
2467 FadeIn(REDRAW_FIELD);
2471 if (DelayReached(&info_delay, GameFrameDelay))
2472 if (page < num_pages)
2473 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2475 PlayMenuSoundIfLoop();
2479 void DrawInfoScreen_Music()
2481 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2484 FadeOut(REDRAW_FIELD);
2492 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2495 FadeIn(REDRAW_FIELD);
2499 void HandleInfoScreen_Music(int button)
2501 static struct MusicFileInfo *list = NULL;
2502 int ystart1 = mSY - SY + 100;
2503 int ystart2 = mSY - SY + 150;
2504 int ybottom = mSY - SY + SYSIZE - 20;
2507 if (button == MB_MENU_INITIALIZE)
2509 list = music_file_info;
2513 FadeSoundsAndMusic();
2518 DrawTextSCentered(ystart1, FONT_TEXT_1,
2519 "No music info for this level set.");
2521 DrawTextSCentered(ybottom, FONT_TEXT_4,
2522 "Press any key or button for info menu");
2528 if (button == MB_MENU_LEAVE)
2530 PlaySound(SND_MENU_ITEM_SELECTING);
2532 FadeSoundsAndMusic();
2534 info_mode = INFO_MODE_MAIN;
2539 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2543 if (button != MB_MENU_INITIALIZE)
2545 PlaySound(SND_MENU_ITEM_SELECTING);
2553 FadeSoundsAndMusic();
2555 info_mode = INFO_MODE_MAIN;
2556 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2561 FadeSoundsAndMusic();
2564 if (list != music_file_info)
2565 FadeSetNextScreen();
2568 if (button != MB_MENU_INITIALIZE)
2569 FadeOut(REDRAW_FIELD);
2576 int sound = list->music;
2578 if (sound_info[sound].loop)
2579 PlaySoundLoop(sound);
2583 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2587 PlayMusic(list->music);
2589 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2592 if (!strEqual(list->title, UNKNOWN_NAME))
2594 if (!strEqual(list->title_header, UNKNOWN_NAME))
2595 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2597 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2600 if (!strEqual(list->artist, UNKNOWN_NAME))
2602 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2603 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2605 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2607 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2610 if (!strEqual(list->album, UNKNOWN_NAME))
2612 if (!strEqual(list->album_header, UNKNOWN_NAME))
2613 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2615 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2617 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2620 if (!strEqual(list->year, UNKNOWN_NAME))
2622 if (!strEqual(list->year_header, UNKNOWN_NAME))
2623 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2625 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2627 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2630 DrawTextSCentered(ybottom, FONT_TEXT_4,
2631 "Press any key or button for next page");
2633 if (button != MB_MENU_INITIALIZE)
2634 FadeIn(REDRAW_FIELD);
2637 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2638 PlaySoundLoop(list->music);
2641 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2643 int ystart1 = mSY - SY + 100;
2644 int ystart2 = mSY - SY + 150;
2645 int ybottom = mSY - SY + SYSIZE - 20;
2651 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2655 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2656 "Special thanks to");
2657 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2659 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2661 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2662 "\"Boulder Dash\"");
2663 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2665 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2667 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2669 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2670 "First Star Software");
2672 else if (screen_nr == 1)
2674 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2675 "Special thanks to");
2676 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2677 "Klaus Heinz & Volker Wertich");
2678 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2680 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2681 "\"Emerald Mine\"");
2682 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2684 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2686 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2688 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2691 else if (screen_nr == 2)
2693 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2694 "Special thanks to");
2695 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2696 "Michael Stopp & Philip Jespersen");
2697 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2699 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2701 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2703 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2705 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2707 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2708 "Digital Integration");
2710 else if (screen_nr == 3)
2712 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2713 "Special thanks to");
2714 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2715 "Hiroyuki Imabayashi");
2716 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2718 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2720 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2722 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2724 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2726 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2729 else if (screen_nr == 4)
2731 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2732 "Special thanks to");
2733 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2735 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2737 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2738 "Jürgen Bonhagen");
2739 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2740 "for the continuous creation");
2741 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2742 "of outstanding level sets");
2744 else if (screen_nr == 5)
2746 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2748 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2750 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2751 "for ideas and inspiration by");
2752 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2755 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2757 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2759 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2760 "for ideas and inspiration by");
2761 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2764 else if (screen_nr == 6)
2766 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2768 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2771 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2772 "for the code base used for the");
2773 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2774 "native Emerald Mine engine");
2776 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2777 "for the new Emerald Mine engine");
2780 else if (screen_nr == 7)
2782 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2784 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2786 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2787 "for the initial DOS port");
2789 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2791 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2793 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2794 "for some additional toons");
2796 else if (screen_nr == 8)
2798 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2799 "And not to forget:");
2800 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2802 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2803 "All those who contributed");
2804 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2805 "levels to this game");
2806 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2810 DrawTextSCentered(ybottom, FONT_TEXT_4,
2811 "Press any key or button for next page");
2814 void DrawInfoScreen_Credits()
2816 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2818 FadeSoundsAndMusic();
2821 FadeOut(REDRAW_FIELD);
2824 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2827 FadeIn(REDRAW_FIELD);
2831 void HandleInfoScreen_Credits(int button)
2833 static int screen_nr = 0;
2834 int num_screens = 9;
2836 if (button == MB_MENU_INITIALIZE)
2840 // DrawInfoScreen_CreditsScreen(screen_nr);
2843 if (button == MB_MENU_LEAVE)
2845 PlaySound(SND_MENU_ITEM_SELECTING);
2847 info_mode = INFO_MODE_MAIN;
2852 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2854 if (button != MB_MENU_INITIALIZE)
2856 PlaySound(SND_MENU_ITEM_SELECTING);
2861 if (screen_nr >= num_screens)
2863 FadeSoundsAndMusic();
2865 info_mode = INFO_MODE_MAIN;
2866 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2873 FadeSetNextScreen();
2876 if (button != MB_MENU_INITIALIZE)
2877 FadeOut(REDRAW_FIELD);
2879 DrawInfoScreen_CreditsScreen(screen_nr);
2881 if (button != MB_MENU_INITIALIZE)
2882 FadeIn(REDRAW_FIELD);
2886 PlayMenuSoundIfLoop();
2890 void DrawInfoScreen_Program()
2892 int ystart1 = mSY - SY + 100;
2893 int ystart2 = mSY - SY + 150;
2894 int ybottom = mSY - SY + SYSIZE - 20;
2897 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2900 FadeOut(REDRAW_FIELD);
2906 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2908 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2909 "This game is Freeware!");
2910 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2911 "If you like it, send e-mail to:");
2912 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2913 PROGRAM_EMAIL_STRING);
2915 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2916 "More information and levels:");
2917 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2918 PROGRAM_WEBSITE_STRING);
2919 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2920 "If you have created new levels,");
2921 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2922 "send them to me to include them!");
2923 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2926 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2927 "or SnailMail to:");
2928 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
2930 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
2931 "Detmolder Strasse 189");
2932 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
2934 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
2936 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2937 "More information and levels:");
2938 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2939 PROGRAM_WEBSITE_STRING);
2940 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2941 "If you have created new levels,");
2942 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
2943 "send them to me to include them!");
2944 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
2948 DrawTextSCentered(ybottom, FONT_TEXT_4,
2949 "Press any key or button for info menu");
2952 FadeIn(REDRAW_FIELD);
2956 void HandleInfoScreen_Program(int button)
2958 if (button == MB_MENU_LEAVE)
2960 PlaySound(SND_MENU_ITEM_SELECTING);
2962 info_mode = INFO_MODE_MAIN;
2967 else if (button == MB_MENU_CHOICE)
2969 PlaySound(SND_MENU_ITEM_SELECTING);
2971 FadeSoundsAndMusic();
2974 FadeOut(REDRAW_FIELD);
2977 info_mode = INFO_MODE_MAIN;
2978 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2982 PlayMenuSoundIfLoop();
2986 void DrawInfoScreen_Version()
2988 int font_header = FONT_TEXT_3;
2989 int font_text = FONT_TEXT_2;
2990 int xstep = getFontWidth(font_text);
2991 int ystep = getFontHeight(font_text);
2992 int ystart1 = mSY - SY + 100;
2993 int ystart2 = mSY - SY + 150;
2994 int ybottom = mSY - SY + SYSIZE - 20;
2995 int xstart1 = mSX - SX + 2 * xstep;
2996 int xstart2 = mSX - SX + 18 * xstep;
2997 #if defined(TARGET_SDL)
2998 int xstart3 = mSX - SX + 28 * xstep;
2999 SDL_version sdl_version_compiled;
3000 const SDL_version *sdl_version_linked;
3001 int driver_name_len = 10;
3002 #if defined(TARGET_SDL2)
3003 SDL_version sdl_version_linked_ext;
3004 const char *driver_name = NULL;
3006 char driver_name[driver_name_len];
3010 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3013 FadeOut(REDRAW_FIELD);
3019 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3021 DrawTextF(xstart1, ystart2, font_header, "Name");
3022 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3025 DrawTextF(xstart1, ystart2, font_header, "Version");
3026 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3029 DrawTextF(xstart1, ystart2, font_header, "Platform");
3030 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3033 DrawTextF(xstart1, ystart2, font_header, "Target");
3034 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3037 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3038 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3040 #if defined(TARGET_SDL)
3041 ystart2 += 3 * ystep;
3042 DrawTextF(xstart1, ystart2, font_header, "Library");
3043 DrawTextF(xstart2, ystart2, font_header, "compiled");
3044 DrawTextF(xstart3, ystart2, font_header, "linked");
3046 SDL_VERSION(&sdl_version_compiled);
3047 #if defined(TARGET_SDL2)
3048 SDL_GetVersion(&sdl_version_linked_ext);
3049 sdl_version_linked = &sdl_version_linked_ext;
3051 sdl_version_linked = SDL_Linked_Version();
3054 ystart2 += 2 * ystep;
3055 DrawTextF(xstart1, ystart2, font_text, "SDL");
3056 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3057 sdl_version_compiled.major,
3058 sdl_version_compiled.minor,
3059 sdl_version_compiled.patch);
3060 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3061 sdl_version_linked->major,
3062 sdl_version_linked->minor,
3063 sdl_version_linked->patch);
3065 SDL_IMAGE_VERSION(&sdl_version_compiled);
3066 sdl_version_linked = IMG_Linked_Version();
3069 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3070 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3071 sdl_version_compiled.major,
3072 sdl_version_compiled.minor,
3073 sdl_version_compiled.patch);
3074 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3075 sdl_version_linked->major,
3076 sdl_version_linked->minor,
3077 sdl_version_linked->patch);
3079 SDL_MIXER_VERSION(&sdl_version_compiled);
3080 sdl_version_linked = Mix_Linked_Version();
3083 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3084 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3085 sdl_version_compiled.major,
3086 sdl_version_compiled.minor,
3087 sdl_version_compiled.patch);
3088 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3089 sdl_version_linked->major,
3090 sdl_version_linked->minor,
3091 sdl_version_linked->patch);
3093 SDL_NET_VERSION(&sdl_version_compiled);
3094 sdl_version_linked = SDLNet_Linked_Version();
3097 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3098 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3099 sdl_version_compiled.major,
3100 sdl_version_compiled.minor,
3101 sdl_version_compiled.patch);
3102 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3103 sdl_version_linked->major,
3104 sdl_version_linked->minor,
3105 sdl_version_linked->patch);
3107 ystart2 += 3 * ystep;
3108 DrawTextF(xstart1, ystart2, font_header, "Driver");
3109 DrawTextF(xstart2, ystart2, font_header, "Requested");
3110 DrawTextF(xstart3, ystart2, font_header, "Used");
3112 #if defined(TARGET_SDL2)
3113 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3115 SDL_VideoDriverName(driver_name, driver_name_len);
3118 ystart2 += 2 * ystep;
3119 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3120 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3121 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3123 #if defined(TARGET_SDL2)
3124 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3126 SDL_AudioDriverName(driver_name, driver_name_len);
3130 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3131 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3132 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3135 DrawTextSCentered(ybottom, FONT_TEXT_4,
3136 "Press any key or button for info menu");
3139 FadeIn(REDRAW_FIELD);
3143 void HandleInfoScreen_Version(int button)
3145 if (button == MB_MENU_LEAVE)
3147 PlaySound(SND_MENU_ITEM_SELECTING);
3149 info_mode = INFO_MODE_MAIN;
3154 else if (button == MB_MENU_CHOICE)
3156 PlaySound(SND_MENU_ITEM_SELECTING);
3158 FadeSoundsAndMusic();
3161 FadeOut(REDRAW_FIELD);
3164 info_mode = INFO_MODE_MAIN;
3165 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3169 PlayMenuSoundIfLoop();
3173 void DrawInfoScreen_LevelSet()
3175 struct TitleMessageInfo *tmi = &readme;
3176 char *filename = getLevelSetInfoFilename();
3178 /* if chars set to "-1", automatically determine by text and font width */
3179 if (tmi->chars == -1)
3180 tmi->chars = tmi->width / getFontWidth(tmi->font);
3182 tmi->width = tmi->chars * getFontWidth(tmi->font);
3184 /* if lines set to "-1", automatically determine by text and font height */
3185 if (tmi->lines == -1)
3186 tmi->lines = tmi->height / getFontHeight(tmi->font);
3188 tmi->height = tmi->lines * getFontHeight(tmi->font);
3190 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3193 FadeOut(REDRAW_FIELD);
3199 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3201 if (filename != NULL)
3202 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3203 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3204 tmi->autowrap, tmi->centered, tmi->parse_comments);
3206 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3207 "No information for this level set.");
3209 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3210 "Press any key or button for info menu");
3213 FadeIn(REDRAW_FIELD);
3217 void HandleInfoScreen_LevelSet(int button)
3219 if (button == MB_MENU_LEAVE)
3221 PlaySound(SND_MENU_ITEM_SELECTING);
3223 info_mode = INFO_MODE_MAIN;
3228 else if (button == MB_MENU_CHOICE)
3230 PlaySound(SND_MENU_ITEM_SELECTING);
3232 FadeSoundsAndMusic();
3235 FadeOut(REDRAW_FIELD);
3238 info_mode = INFO_MODE_MAIN;
3239 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3243 PlayMenuSoundIfLoop();
3247 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3249 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3251 if (info_mode == INFO_MODE_TITLE)
3252 DrawInfoScreen_TitleScreen();
3253 else if (info_mode == INFO_MODE_ELEMENTS)
3254 DrawInfoScreen_Elements();
3255 else if (info_mode == INFO_MODE_MUSIC)
3256 DrawInfoScreen_Music();
3257 else if (info_mode == INFO_MODE_CREDITS)
3258 DrawInfoScreen_Credits();
3259 else if (info_mode == INFO_MODE_PROGRAM)
3260 DrawInfoScreen_Program();
3261 else if (info_mode == INFO_MODE_VERSION)
3262 DrawInfoScreen_Version();
3263 else if (info_mode == INFO_MODE_LEVELSET)
3264 DrawInfoScreen_LevelSet();
3266 DrawInfoScreen_Main(fade_mask, do_fading);
3268 if (info_mode != INFO_MODE_MAIN &&
3269 info_mode != INFO_MODE_TITLE &&
3270 info_mode != INFO_MODE_MUSIC)
3277 void DrawAndFadeInInfoScreen(int fade_mask)
3279 DrawInfoScreenExt(fade_mask, TRUE);
3282 void DrawInfoScreen()
3284 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3287 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3289 if (info_mode == INFO_MODE_TITLE)
3290 HandleInfoScreen_TitleScreen(button);
3291 else if (info_mode == INFO_MODE_ELEMENTS)
3292 HandleInfoScreen_Elements(button);
3293 else if (info_mode == INFO_MODE_MUSIC)
3294 HandleInfoScreen_Music(button);
3295 else if (info_mode == INFO_MODE_CREDITS)
3296 HandleInfoScreen_Credits(button);
3297 else if (info_mode == INFO_MODE_PROGRAM)
3298 HandleInfoScreen_Program(button);
3299 else if (info_mode == INFO_MODE_VERSION)
3300 HandleInfoScreen_Version(button);
3301 else if (info_mode == INFO_MODE_LEVELSET)
3302 HandleInfoScreen_LevelSet(button);
3304 HandleInfoScreen_Main(mx, my, dx, dy, button);
3310 /* ========================================================================= */
3311 /* type name functions */
3312 /* ========================================================================= */
3314 void HandleTypeName(int newxpos, Key key)
3316 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3317 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3318 struct TextPosInfo *pos = mci->pos_input;
3319 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3320 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3321 static int xpos = 0;
3322 int font_nr = pos->font;
3323 int font_active_nr = FONT_ACTIVE(font_nr);
3324 int font_width = getFontWidth(font_active_nr);
3325 char key_char = getValidConfigValueChar(getCharFromKey(key));
3326 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3327 boolean is_active = TRUE;
3329 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3333 strcpy(last_player_name, setup.player_name);
3337 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3339 setup.player_name[xpos] = key_char;
3340 setup.player_name[xpos + 1] = 0;
3344 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3348 setup.player_name[xpos] = 0;
3350 else if (key == KSYM_Return && xpos > 0)
3356 game_status = GAME_MODE_MAIN;
3358 else if (key == KSYM_Escape)
3360 strcpy(setup.player_name, last_player_name);
3364 game_status = GAME_MODE_MAIN;
3369 pos->width = (strlen(setup.player_name) + 1) * font_width;
3370 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3372 DrawText(startx, starty, setup.player_name, font_active_nr);
3373 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3377 pos->width = strlen(setup.player_name) * font_width;
3378 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3380 DrawText(startx, starty, setup.player_name, font_nr);
3385 /* ========================================================================= */
3386 /* tree menu functions */
3387 /* ========================================================================= */
3389 static void DrawChooseTree(TreeInfo **ti_ptr)
3393 FreeScreenGadgets();
3394 CreateScreenGadgets();
3396 CloseDoor(DOOR_CLOSE_2);
3399 FadeOut(REDRAW_FIELD);
3404 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3405 MapScreenTreeGadgets(*ti_ptr);
3408 FadeIn(REDRAW_FIELD);
3414 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3416 struct GadgetInfo *gi = screen_gadget[id];
3417 int items_max, items_visible, item_position;
3419 items_max = numTreeInfoInGroup(ti);
3420 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3421 item_position = first_entry;
3423 if (item_position > items_max - items_visible)
3424 item_position = items_max - items_visible;
3426 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3427 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3428 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3431 static void drawChooseTreeList(int first_entry, int num_page_entries,
3435 char *title_string = NULL;
3436 int yoffset_sets = MENU_TITLE1_YPOS;
3437 int yoffset_setup = 16;
3438 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3439 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3440 int last_game_status = game_status; /* save current game status */
3442 title_string = ti->infotext;
3444 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3447 /* force LEVELS font on artwork setup screen */
3448 game_status = GAME_MODE_LEVELS;
3452 /* clear tree list area, but not title or scrollbar */
3453 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3454 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3455 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3457 /* clear tree list area, but not title or scrollbar */
3458 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3459 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3460 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3463 for (i = 0; i < num_page_entries; i++)
3465 TreeInfo *node, *node_first;
3466 int entry_pos = first_entry + i;
3467 int xpos = MENU_SCREEN_START_XPOS;
3468 int ypos = MENU_SCREEN_START_YPOS + i;
3469 int startx = mSX + xpos * 32;
3470 int starty = mSY + ypos * 32;
3471 int font_nr = FONT_TEXT_1;
3472 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3473 int startx_text = startx + font_xoffset;
3474 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3475 int text_size = startx_scrollbar - startx_text;
3476 int max_buffer_len = text_size / getFontWidth(font_nr);
3477 char buffer[max_buffer_len + 1];
3479 node_first = getTreeInfoFirstGroupEntry(ti);
3480 node = getTreeInfoFromPos(node_first, entry_pos);
3482 strncpy(buffer, node->name, max_buffer_len);
3483 buffer[max_buffer_len] = '\0';
3485 DrawText(startx, starty, buffer, font_nr + node->color);
3487 if (node->parent_link)
3488 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3489 else if (node->level_group)
3490 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3492 initCursor(i, IMG_MENU_BUTTON);
3495 game_status = last_game_status; /* restore current game status */
3497 redraw_mask |= REDRAW_FIELD;
3500 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3502 TreeInfo *node, *node_first;
3503 int x, last_redraw_mask = redraw_mask;
3504 int ypos = MENU_TITLE2_YPOS;
3505 int font_nr = FONT_TITLE_2;
3507 if (ti->type == TREE_TYPE_LEVEL_NR)
3508 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3510 if (ti->type != TREE_TYPE_LEVEL_DIR)
3513 node_first = getTreeInfoFirstGroupEntry(ti);
3514 node = getTreeInfoFromPos(node_first, entry_pos);
3516 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3519 if (node->parent_link)
3520 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3521 node->node_parent->name);
3522 else if (node->level_group)
3523 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3525 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3526 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3527 node->levels, (node->levels > 1 ? "levels" : "level"),
3530 if (node->parent_link)
3531 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3533 else if (node->level_group)
3534 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3536 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3537 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3538 node->levels, node->class_desc);
3541 /* let BackToFront() redraw only what is needed */
3542 redraw_mask = last_redraw_mask | REDRAW_TILES;
3543 for (x = 0; x < SCR_FIELDX; x++)
3544 MarkTileDirty(x, 1);
3547 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3550 TreeInfo *ti = *ti_ptr;
3552 int y = ti->cl_cursor;
3553 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3554 int num_entries = numTreeInfoInGroup(ti);
3555 int num_page_entries;
3556 int last_game_status = game_status; /* save current game status */
3557 boolean position_set_by_scrollbar = (dx == 999);
3560 /* force LEVELS draw offset on choose level and artwork setup screen */
3561 game_status = GAME_MODE_LEVELS;
3564 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3565 num_page_entries = num_entries;
3567 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3569 game_status = last_game_status; /* restore current game status */
3571 if (button == MB_MENU_INITIALIZE)
3573 int num_entries = numTreeInfoInGroup(ti);
3574 int entry_pos = posTreeInfo(ti);
3576 if (ti->cl_first == -1)
3578 /* only on initialization */
3579 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3580 ti->cl_cursor = entry_pos - ti->cl_first;
3582 else if (ti->cl_cursor >= num_page_entries ||
3583 (num_entries > num_page_entries &&
3584 num_entries - ti->cl_first < num_page_entries))
3586 /* only after change of list size (by custom graphic configuration) */
3587 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3588 ti->cl_cursor = entry_pos - ti->cl_first;
3591 if (position_set_by_scrollbar)
3594 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3597 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3598 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3599 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3603 else if (button == MB_MENU_LEAVE)
3607 PlaySound(SND_MENU_ITEM_SELECTING);
3609 if (ti->node_parent)
3611 *ti_ptr = ti->node_parent;
3612 DrawChooseTree(ti_ptr);
3614 else if (game_status == GAME_MODE_SETUP)
3616 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3618 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3619 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3620 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3621 execSetupGraphics();
3622 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3623 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3624 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3631 if (game_status == GAME_MODE_LEVELNR)
3632 level_nr = atoi(level_number_current->identifier);
3634 game_status = GAME_MODE_MAIN;
3636 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3642 if (mx || my) /* mouse input */
3644 int last_game_status = game_status; /* save current game status */
3647 /* force LEVELS draw offset on artwork setup screen */
3648 game_status = GAME_MODE_LEVELS;
3651 x = (mx - mSX) / 32;
3652 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3654 game_status = last_game_status; /* restore current game status */
3656 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3658 /* move cursor instead of scrolling when already at start/end of list */
3659 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3661 else if (dy == +1 * SCROLL_LINE &&
3662 ti->cl_first + num_page_entries == num_entries)
3665 /* handle scrolling screen one line or page */
3666 if (ti->cl_cursor + dy < 0 ||
3667 ti->cl_cursor + dy > num_page_entries - 1)
3669 if (ABS(dy) == SCROLL_PAGE)
3670 step = num_page_entries - 1;
3672 if (dy < 0 && ti->cl_first > 0)
3674 /* scroll page/line up */
3676 ti->cl_first -= step;
3677 if (ti->cl_first < 0)
3680 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3681 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3682 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3684 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3687 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3689 /* scroll page/line down */
3691 ti->cl_first += step;
3692 if (ti->cl_first + num_page_entries > num_entries)
3693 ti->cl_first = MAX(0, num_entries - num_page_entries);
3695 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3696 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3697 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3699 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3706 /* handle moving cursor one line */
3707 y = ti->cl_cursor + dy;
3712 TreeInfo *node_first, *node_cursor;
3713 int entry_pos = ti->cl_first + y;
3715 node_first = getTreeInfoFirstGroupEntry(ti);
3716 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3718 if (node_cursor->node_group)
3722 PlaySound(SND_MENU_ITEM_SELECTING);
3724 node_cursor->cl_first = ti->cl_first;
3725 node_cursor->cl_cursor = ti->cl_cursor;
3726 *ti_ptr = node_cursor->node_group;
3727 DrawChooseTree(ti_ptr);
3732 else if (dx == -1 && ti->node_parent)
3736 PlaySound(SND_MENU_ITEM_SELECTING);
3738 *ti_ptr = ti->node_parent;
3739 DrawChooseTree(ti_ptr);
3744 if (!anyScrollbarGadgetActive() &&
3745 IN_VIS_FIELD(x, y) &&
3746 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3747 y >= 0 && y < num_page_entries)
3751 if (y != ti->cl_cursor)
3753 PlaySound(SND_MENU_ITEM_ACTIVATING);
3755 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3756 drawChooseTreeCursor(y, TRUE);
3757 drawChooseTreeInfo(ti->cl_first + y, ti);
3764 TreeInfo *node_first, *node_cursor;
3765 int entry_pos = ti->cl_first + y;
3767 PlaySound(SND_MENU_ITEM_SELECTING);
3769 node_first = getTreeInfoFirstGroupEntry(ti);
3770 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3772 if (node_cursor->node_group)
3776 node_cursor->cl_first = ti->cl_first;
3777 node_cursor->cl_cursor = ti->cl_cursor;
3778 *ti_ptr = node_cursor->node_group;
3779 DrawChooseTree(ti_ptr);
3781 else if (node_cursor->parent_link)
3785 *ti_ptr = node_cursor->node_parent;
3786 DrawChooseTree(ti_ptr);
3793 FadeSetEnterScreen();
3796 node_cursor->cl_first = ti->cl_first;
3797 node_cursor->cl_cursor = ti->cl_cursor;
3798 *ti_ptr = node_cursor;
3800 if (ti->type == TREE_TYPE_LEVEL_DIR)
3802 LoadLevelSetup_SeriesInfo();
3804 SaveLevelSetup_LastSeries();
3805 SaveLevelSetup_SeriesInfo();
3809 if (game_status == GAME_MODE_SETUP)
3811 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
3813 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3814 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3815 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3816 execSetupGraphics();
3817 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3818 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3819 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3826 if (game_status == GAME_MODE_LEVELNR)
3827 level_nr = atoi(level_number_current->identifier);
3829 game_status = GAME_MODE_MAIN;
3838 void DrawChooseLevelSet()
3840 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3842 DrawChooseTree(&leveldir_current);
3848 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3850 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3855 void DrawChooseLevelNr()
3859 if (level_number != NULL)
3861 freeTreeInfo(level_number);
3863 level_number = NULL;
3866 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3868 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3869 char identifier[32], name[32];
3872 /* temporarily load level info to get level name */
3873 LoadLevelInfoOnly(i);
3875 ti->node_top = &level_number;
3876 ti->sort_priority = 10000 + value;
3877 ti->color = (level.no_valid_file ? FC_BLUE :
3878 LevelStats_getSolved(i) ? FC_GREEN :
3879 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3881 sprintf(identifier, "%d", value);
3882 sprintf(name, "%03d: %s", value,
3883 (level.no_valid_file ? "(no file)" : level.name));
3885 setString(&ti->identifier, identifier);
3886 setString(&ti->name, name);
3887 setString(&ti->name_sorting, name);
3889 pushTreeInfo(&level_number, ti);
3892 /* sort level number values to start with lowest level number */
3893 sortTreeInfo(&level_number);
3895 /* set current level number to current level number */
3896 level_number_current =
3897 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3899 /* if that also fails, set current level number to first available level */
3900 if (level_number_current == NULL)
3901 level_number_current = level_number;
3903 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3906 DrawChooseTree(&level_number_current);
3908 DrawChooseTree(&leveldir_current);
3915 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3918 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3920 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3926 void DrawHallOfFame(int highlight_position)
3929 FadeSoundsAndMusic();
3931 /* (this is needed when called from GameEnd() after winning a game) */
3932 KeyboardAutoRepeatOn();
3935 /* (this is needed when called from GameEnd() after winning a game) */
3936 SetDrawDeactivationMask(REDRAW_NONE);
3937 SetDrawBackgroundMask(REDRAW_FIELD);
3939 CloseDoor(DOOR_CLOSE_2);
3941 if (highlight_position < 0)
3942 LoadScore(level_nr);
3944 FadeSetEnterScreen();
3946 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
3949 FadeOut(REDRAW_FIELD);
3957 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3960 FadeIn(REDRAW_FIELD);
3964 static void drawHallOfFameList(int first_entry, int highlight_position)
3968 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3971 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3972 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3973 "HighScores of Level %d", level_nr);
3975 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3977 int entry = first_entry + i;
3978 boolean active = (entry == highlight_position);
3979 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3980 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3981 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3982 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3983 int dx1 = 3 * getFontWidth(font_nr1);
3984 int dx2 = dx1 + getFontWidth(font_nr1);
3985 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
3986 int sy = mSY + 64 + i * 32;
3988 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3989 DrawText(mSX + dx1, sy, ".", font_nr1);
3990 DrawText(mSX + dx2, sy, ".........................", font_nr3);
3992 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3993 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3995 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3998 redraw_mask |= REDRAW_FIELD;
4001 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4003 static int first_entry = 0;
4004 static int highlight_position = 0;
4005 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4007 if (button == MB_MENU_INITIALIZE)
4010 highlight_position = mx;
4011 drawHallOfFameList(first_entry, highlight_position);
4016 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4017 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4021 if (first_entry > 0)
4023 first_entry -= step;
4024 if (first_entry < 0)
4027 drawHallOfFameList(first_entry, highlight_position);
4032 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4034 first_entry += step;
4035 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4036 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4038 drawHallOfFameList(first_entry, highlight_position);
4041 else if (button == MB_MENU_LEAVE)
4043 PlaySound(SND_MENU_ITEM_SELECTING);
4045 FadeSound(SND_BACKGROUND_SCORES);
4047 game_status = GAME_MODE_MAIN;
4051 else if (button == MB_MENU_CHOICE)
4053 PlaySound(SND_MENU_ITEM_SELECTING);
4055 FadeSound(SND_BACKGROUND_SCORES);
4058 FadeOut(REDRAW_FIELD);
4061 game_status = GAME_MODE_MAIN;
4063 DrawAndFadeInMainMenu(REDRAW_FIELD);
4066 if (game_status == GAME_MODE_SCORES)
4067 PlayMenuSoundIfLoop();
4073 /* ========================================================================= */
4074 /* setup screen functions */
4075 /* ========================================================================= */
4077 static struct TokenInfo *setup_info;
4078 static int num_setup_info;
4080 static char *screen_mode_text;
4081 static char *window_size_text;
4082 static char *scroll_delay_text;
4083 static char *game_speed_text;
4084 static char *graphics_set_name;
4085 static char *sounds_set_name;
4086 static char *music_set_name;
4087 static char *volume_simple_text;
4088 static char *volume_loops_text;
4089 static char *volume_music_text;
4091 static void execSetupMain()
4093 setup_mode = SETUP_MODE_MAIN;
4098 static void execSetupGame()
4100 if (game_speeds == NULL)
4104 for (i = 0; game_speeds_list[i].value != -1; i++)
4106 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4107 char identifier[32], name[32];
4108 int value = game_speeds_list[i].value;
4109 char *text = game_speeds_list[i].text;
4111 ti->node_top = &game_speeds;
4112 ti->sort_priority = 10000 - value;
4114 sprintf(identifier, "%d", value);
4115 sprintf(name, "%s", text);
4117 setString(&ti->identifier, identifier);
4118 setString(&ti->name, name);
4119 setString(&ti->name_sorting, name);
4120 setString(&ti->infotext, "Game Speed");
4122 pushTreeInfo(&game_speeds, ti);
4125 /* sort game speed values to start with slowest game speed */
4126 sortTreeInfo(&game_speeds);
4128 /* set current game speed to configured game speed value */
4129 game_speed_current =
4130 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4132 /* if that fails, set current game speed to reliable default value */
4133 if (game_speed_current == NULL)
4134 game_speed_current =
4135 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4137 /* if that also fails, set current game speed to first available speed */
4138 if (game_speed_current == NULL)
4139 game_speed_current = game_speeds;
4142 setup.game_frame_delay = atoi(game_speed_current->identifier);
4144 /* needed for displaying game speed text instead of identifier */
4145 game_speed_text = game_speed_current->name;
4147 setup_mode = SETUP_MODE_GAME;
4152 static void execSetupChooseGameSpeed()
4154 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4159 static void execSetupEditor()
4161 setup_mode = SETUP_MODE_EDITOR;
4166 static void execSetupGraphics_setWindowSizes(boolean update_list)
4168 if (window_sizes != NULL && update_list)
4170 freeTreeInfo(window_sizes);
4172 window_sizes = NULL;
4175 if (window_sizes == NULL)
4177 boolean current_window_size_found = FALSE;
4180 for (i = 0; window_sizes_list[i].value != -1; i++)
4182 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4183 char identifier[32], name[32];
4184 int value = window_sizes_list[i].value;
4185 char *text = window_sizes_list[i].text;
4187 ti->node_top = &window_sizes;
4188 ti->sort_priority = value;
4190 sprintf(identifier, "%d", value);
4191 sprintf(name, "%s", text);
4193 setString(&ti->identifier, identifier);
4194 setString(&ti->name, name);
4195 setString(&ti->name_sorting, name);
4196 setString(&ti->infotext, "Window Scaling");
4198 pushTreeInfo(&window_sizes, ti);
4200 if (value == setup.window_scaling_percent)
4201 current_window_size_found = TRUE;
4204 if (!current_window_size_found)
4206 // add entry for non-preset window scaling value
4208 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4209 char identifier[32], name[32];
4210 int value = setup.window_scaling_percent;
4212 ti->node_top = &window_sizes;
4213 ti->sort_priority = value;
4215 sprintf(identifier, "%d", value);
4216 sprintf(name, "%d %% (Current)", value);
4218 setString(&ti->identifier, identifier);
4219 setString(&ti->name, name);
4220 setString(&ti->name_sorting, name);
4221 setString(&ti->infotext, "Window Scaling");
4223 pushTreeInfo(&window_sizes, ti);
4226 /* sort window size values to start with lowest window size value */
4227 sortTreeInfo(&window_sizes);
4229 /* set current window size value to configured window size value */
4230 window_size_current =
4231 getTreeInfoFromIdentifier(window_sizes,
4232 i_to_a(setup.window_scaling_percent));
4234 /* if that fails, set current window size to reliable default value */
4235 if (window_size_current == NULL)
4236 window_size_current =
4237 getTreeInfoFromIdentifier(window_sizes,
4238 i_to_a(STD_WINDOW_SCALING_PERCENT));
4240 /* if that also fails, set current window size to first available value */
4241 if (window_size_current == NULL)
4242 window_size_current = window_sizes;
4245 setup.window_scaling_percent = atoi(window_size_current->identifier);
4247 /* needed for displaying window size text instead of identifier */
4248 window_size_text = window_size_current->name;
4251 static void execSetupGraphics_setScreenModes()
4253 // if (screen_modes == NULL && video.fullscreen_available)
4254 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4258 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4260 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4261 char identifier[32], name[32];
4262 int x = video.fullscreen_modes[i].width;
4263 int y = video.fullscreen_modes[i].height;
4266 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4268 ti->node_top = &screen_modes;
4269 ti->sort_priority = x * 10000 + y;
4271 sprintf(identifier, "%dx%d", x, y);
4272 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4274 setString(&ti->identifier, identifier);
4275 setString(&ti->name, name);
4276 setString(&ti->name_sorting, name);
4277 setString(&ti->infotext, "Fullscreen Mode");
4279 pushTreeInfo(&screen_modes, ti);
4282 /* sort fullscreen modes to start with lowest available screen resolution */
4283 sortTreeInfo(&screen_modes);
4285 /* set current screen mode for fullscreen mode to configured setup value */
4286 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4287 setup.fullscreen_mode);
4289 /* if that fails, set current screen mode to reliable default value */
4290 if (screen_mode_current == NULL)
4291 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4292 DEFAULT_FULLSCREEN_MODE);
4294 /* if that also fails, set current screen mode to first available mode */
4295 if (screen_mode_current == NULL)
4296 screen_mode_current = screen_modes;
4298 if (screen_mode_current == NULL)
4299 video.fullscreen_available = FALSE;
4302 // if (video.fullscreen_available)
4303 if (screen_mode_current != NULL)
4305 setup.fullscreen_mode = screen_mode_current->identifier;
4307 /* needed for displaying screen mode name instead of identifier */
4308 screen_mode_text = screen_mode_current->name;
4312 static void execSetupGraphics_setScrollDelays()
4314 if (scroll_delays == NULL)
4318 for (i = 0; scroll_delays_list[i].value != -1; i++)
4320 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4321 char identifier[32], name[32];
4322 int value = scroll_delays_list[i].value;
4323 char *text = scroll_delays_list[i].text;
4325 ti->node_top = &scroll_delays;
4326 ti->sort_priority = value;
4328 sprintf(identifier, "%d", value);
4329 sprintf(name, "%s", text);
4331 setString(&ti->identifier, identifier);
4332 setString(&ti->name, name);
4333 setString(&ti->name_sorting, name);
4334 setString(&ti->infotext, "Scroll Delay");
4336 pushTreeInfo(&scroll_delays, ti);
4339 /* sort scroll delay values to start with lowest scroll delay value */
4340 sortTreeInfo(&scroll_delays);
4342 /* set current scroll delay value to configured scroll delay value */
4343 scroll_delay_current =
4344 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4346 /* if that fails, set current scroll delay to reliable default value */
4347 if (scroll_delay_current == NULL)
4348 scroll_delay_current =
4349 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4351 /* if that also fails, set current scroll delay to first available value */
4352 if (scroll_delay_current == NULL)
4353 scroll_delay_current = scroll_delays;
4356 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4358 /* needed for displaying scroll delay text instead of identifier */
4359 scroll_delay_text = scroll_delay_current->name;
4362 static void execSetupGraphics()
4364 // update "setup.window_scaling_percent" from list selection
4365 execSetupGraphics_setWindowSizes(FALSE);
4366 // maybe remove non-preset value (if standard value was selected)
4367 execSetupGraphics_setWindowSizes(TRUE);
4369 execSetupGraphics_setScreenModes();
4370 execSetupGraphics_setScrollDelays();
4372 setup_mode = SETUP_MODE_GRAPHICS;
4377 #if !defined(PLATFORM_ANDROID)
4378 #if defined(TARGET_SDL2)
4379 static void execSetupChooseWindowSize()
4382 if (!video.window_scaling_available)
4386 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4391 static void execSetupChooseScreenMode()
4393 if (!video.fullscreen_available)
4396 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4403 static void execSetupChooseScrollDelay()
4405 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4410 static void execSetupChooseVolumeSimple()
4412 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4417 static void execSetupChooseVolumeLoops()
4419 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4424 static void execSetupChooseVolumeMusic()
4426 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4431 static void execSetupSound()
4434 if (volumes_simple == NULL)
4438 for (i = 0; volumes_list[i].value != -1; i++)
4440 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4441 char identifier[32], name[32];
4442 int value = volumes_list[i].value;
4443 char *text = volumes_list[i].text;
4445 ti->node_top = &volumes_simple;
4446 ti->sort_priority = value;
4448 sprintf(identifier, "%d", value);
4449 sprintf(name, "%s", text);
4451 setString(&ti->identifier, identifier);
4452 setString(&ti->name, name);
4453 setString(&ti->name_sorting, name);
4454 setString(&ti->infotext, "Sound Volume");
4456 pushTreeInfo(&volumes_simple, ti);
4459 /* sort volume values to start with lowest volume value */
4460 sortTreeInfo(&volumes_simple);
4462 /* set current volume value to configured volume value */
4463 volume_simple_current =
4464 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4466 /* if that fails, set current volume to reliable default value */
4467 if (volume_simple_current == NULL)
4468 volume_simple_current =
4469 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4471 /* if that also fails, set current volume to first available value */
4472 if (volume_simple_current == NULL)
4473 volume_simple_current = volumes_simple;
4476 if (volumes_loops == NULL)
4480 for (i = 0; volumes_list[i].value != -1; i++)
4482 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4483 char identifier[32], name[32];
4484 int value = volumes_list[i].value;
4485 char *text = volumes_list[i].text;
4487 ti->node_top = &volumes_loops;
4488 ti->sort_priority = value;
4490 sprintf(identifier, "%d", value);
4491 sprintf(name, "%s", text);
4493 setString(&ti->identifier, identifier);
4494 setString(&ti->name, name);
4495 setString(&ti->name_sorting, name);
4496 setString(&ti->infotext, "Loops Volume");
4498 pushTreeInfo(&volumes_loops, ti);
4501 /* sort volume values to start with lowest volume value */
4502 sortTreeInfo(&volumes_loops);
4504 /* set current volume value to configured volume value */
4505 volume_loops_current =
4506 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4508 /* if that fails, set current volume to reliable default value */
4509 if (volume_loops_current == NULL)
4510 volume_loops_current =
4511 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4513 /* if that also fails, set current volume to first available value */
4514 if (volume_loops_current == NULL)
4515 volume_loops_current = volumes_loops;
4518 if (volumes_music == NULL)
4522 for (i = 0; volumes_list[i].value != -1; i++)
4524 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4525 char identifier[32], name[32];
4526 int value = volumes_list[i].value;
4527 char *text = volumes_list[i].text;
4529 ti->node_top = &volumes_music;
4530 ti->sort_priority = value;
4532 sprintf(identifier, "%d", value);
4533 sprintf(name, "%s", text);
4535 setString(&ti->identifier, identifier);
4536 setString(&ti->name, name);
4537 setString(&ti->name_sorting, name);
4538 setString(&ti->infotext, "Music Volume");
4540 pushTreeInfo(&volumes_music, ti);
4543 /* sort volume values to start with lowest volume value */
4544 sortTreeInfo(&volumes_music);
4546 /* set current volume value to configured volume value */
4547 volume_music_current =
4548 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4550 /* if that fails, set current volume to reliable default value */
4551 if (volume_music_current == NULL)
4552 volume_music_current =
4553 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4555 /* if that also fails, set current volume to first available value */
4556 if (volume_music_current == NULL)
4557 volume_music_current = volumes_music;
4560 setup.volume_simple = atoi(volume_simple_current->identifier);
4561 setup.volume_loops = atoi(volume_loops_current->identifier);
4562 setup.volume_music = atoi(volume_music_current->identifier);
4564 /* needed for displaying volume text instead of identifier */
4565 volume_simple_text = volume_simple_current->name;
4566 volume_loops_text = volume_loops_current->name;
4567 volume_music_text = volume_music_current->name;
4570 setup_mode = SETUP_MODE_SOUND;
4575 static void execSetupArtwork()
4578 printf("::: '%s', '%s', '%s'\n",
4579 artwork.gfx_current->subdir,
4580 artwork.gfx_current->fullpath,
4581 artwork.gfx_current->basepath);
4584 setup.graphics_set = artwork.gfx_current->identifier;
4585 setup.sounds_set = artwork.snd_current->identifier;
4586 setup.music_set = artwork.mus_current->identifier;
4588 /* needed if last screen (setup choice) changed graphics, sounds or music */
4589 ReloadCustomArtwork(0);
4591 /* needed for displaying artwork name instead of artwork identifier */
4592 graphics_set_name = artwork.gfx_current->name;
4593 sounds_set_name = artwork.snd_current->name;
4594 music_set_name = artwork.mus_current->name;
4596 setup_mode = SETUP_MODE_ARTWORK;
4601 static void execSetupChooseGraphics()
4603 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4608 static void execSetupChooseSounds()
4610 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4615 static void execSetupChooseMusic()
4617 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4622 static void execSetupInput()
4624 setup_mode = SETUP_MODE_INPUT;
4629 static void execSetupShortcuts()
4631 setup_mode = SETUP_MODE_SHORTCUTS;
4636 static void execSetupShortcuts1()
4638 setup_mode = SETUP_MODE_SHORTCUTS_1;
4643 static void execSetupShortcuts2()
4645 setup_mode = SETUP_MODE_SHORTCUTS_2;
4650 static void execSetupShortcuts3()
4652 setup_mode = SETUP_MODE_SHORTCUTS_3;
4657 static void execSetupShortcuts4()
4659 setup_mode = SETUP_MODE_SHORTCUTS_4;
4664 static void execSetupShortcuts5()
4666 setup_mode = SETUP_MODE_SHORTCUTS_5;
4671 static void execExitSetup()
4673 game_status = GAME_MODE_MAIN;
4675 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4678 static void execSaveAndExitSetup()
4684 static struct TokenInfo setup_info_main[] =
4686 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4687 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4688 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4689 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4690 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4691 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4692 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4693 { TYPE_EMPTY, NULL, "" },
4694 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4695 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4700 static struct TokenInfo setup_info_game[] =
4702 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4703 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4704 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4705 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4706 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4707 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4708 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4709 { TYPE_STRING, &game_speed_text, "" },
4710 { TYPE_EMPTY, NULL, "" },
4711 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4716 static struct TokenInfo setup_info_editor[] =
4719 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4720 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4721 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4722 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4723 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4724 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4725 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4726 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4728 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4729 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4730 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4732 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4734 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4735 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4736 { TYPE_EMPTY, NULL, "" },
4738 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4739 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4740 { TYPE_EMPTY, NULL, "" },
4742 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4743 { TYPE_EMPTY, NULL, "" },
4744 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4749 static struct TokenInfo setup_info_graphics[] =
4751 #if !defined(PLATFORM_ANDROID)
4752 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
4753 #if defined(TARGET_SDL2)
4754 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
4755 { TYPE_STRING, &window_size_text, "" },
4757 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
4758 { TYPE_STRING, &screen_mode_text, "" },
4762 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
4764 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay Value:" },
4765 { TYPE_STRING, &scroll_delay_text, "" },
4767 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
4769 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
4770 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
4771 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
4772 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
4773 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
4774 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
4775 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
4776 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
4777 { TYPE_EMPTY, NULL, "" },
4778 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4783 static struct TokenInfo setup_info_sound[] =
4785 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
4786 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
4787 { TYPE_SWITCH, &setup.sound_music, "Music:" },
4788 { TYPE_EMPTY, NULL, "" },
4789 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
4790 { TYPE_STRING, &volume_simple_text, "" },
4791 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
4792 { TYPE_STRING, &volume_loops_text, "" },
4793 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
4794 { TYPE_STRING, &volume_music_text, "" },
4795 { TYPE_EMPTY, NULL, "" },
4796 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4801 static struct TokenInfo setup_info_artwork[] =
4803 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
4804 { TYPE_STRING, &graphics_set_name, "" },
4805 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
4806 { TYPE_STRING, &sounds_set_name, "" },
4807 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
4808 { TYPE_STRING, &music_set_name, "" },
4809 { TYPE_EMPTY, NULL, "" },
4812 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
4813 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
4814 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
4816 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
4817 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
4818 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
4819 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
4822 { TYPE_STRING, NULL, "Override Level Artwork:"},
4823 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
4824 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
4825 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
4827 { TYPE_EMPTY, NULL, "" },
4828 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4833 static struct TokenInfo setup_info_input[] =
4835 { TYPE_SWITCH, NULL, "Player:" },
4836 { TYPE_SWITCH, NULL, "Device:" },
4837 { TYPE_ENTER_MENU, NULL, "" },
4838 { TYPE_EMPTY, NULL, "" },
4839 { TYPE_EMPTY, NULL, "" },
4840 { TYPE_EMPTY, NULL, "" },
4841 { TYPE_EMPTY, NULL, "" },
4842 { TYPE_EMPTY, NULL, "" },
4843 { TYPE_EMPTY, NULL, "" },
4844 { TYPE_EMPTY, NULL, "" },
4845 { TYPE_EMPTY, NULL, "" },
4846 { TYPE_EMPTY, NULL, "" },
4847 { TYPE_EMPTY, NULL, "" },
4848 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4853 static struct TokenInfo setup_info_shortcuts[] =
4855 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
4856 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
4857 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
4858 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
4859 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
4860 { TYPE_EMPTY, NULL, "" },
4861 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4866 static struct TokenInfo setup_info_shortcuts_1[] =
4868 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
4869 { TYPE_KEY, &setup.shortcut.save_game, "" },
4870 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
4871 { TYPE_KEY, &setup.shortcut.load_game, "" },
4872 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
4873 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
4874 { TYPE_EMPTY, NULL, "" },
4875 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
4876 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
4877 { TYPE_EMPTY, NULL, "" },
4878 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4883 static struct TokenInfo setup_info_shortcuts_2[] =
4885 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
4886 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
4887 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
4888 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
4889 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
4890 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
4891 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
4892 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
4893 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
4894 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
4895 { TYPE_EMPTY, NULL, "" },
4896 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4901 static struct TokenInfo setup_info_shortcuts_3[] =
4903 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
4904 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
4905 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
4906 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
4907 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
4908 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
4909 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
4910 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
4911 { TYPE_KEYTEXT, NULL, "Record Tape:", },
4912 { TYPE_KEY, &setup.shortcut.tape_record, "" },
4913 { TYPE_KEYTEXT, NULL, "Play Tape:", },
4914 { TYPE_KEY, &setup.shortcut.tape_play, "" },
4915 { TYPE_EMPTY, NULL, "" },
4916 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4921 static struct TokenInfo setup_info_shortcuts_4[] =
4923 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
4924 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
4925 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
4926 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
4927 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
4928 { TYPE_KEY, &setup.shortcut.sound_music, "" },
4929 { TYPE_EMPTY, NULL, "" },
4930 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4935 static struct TokenInfo setup_info_shortcuts_5[] =
4937 { TYPE_KEYTEXT, NULL, "Snap Left:", },
4938 { TYPE_KEY, &setup.shortcut.snap_left, "" },
4939 { TYPE_KEYTEXT, NULL, "Snap Right:", },
4940 { TYPE_KEY, &setup.shortcut.snap_right, "" },
4941 { TYPE_KEYTEXT, NULL, "Snap Up:", },
4942 { TYPE_KEY, &setup.shortcut.snap_up, "" },
4943 { TYPE_KEYTEXT, NULL, "Snap Down:", },
4944 { TYPE_KEY, &setup.shortcut.snap_down, "" },
4945 { TYPE_EMPTY, NULL, "" },
4946 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
4951 static Key getSetupKey()
4953 Key key = KSYM_UNDEFINED;
4954 boolean got_key_event = FALSE;
4956 while (!got_key_event)
4958 if (PendingEvent()) /* got event */
4966 case EVENT_KEYPRESS:
4968 key = GetEventKey((KeyEvent *)&event, TRUE);
4970 /* press 'Escape' or 'Enter' to keep the existing key binding */
4971 if (key == KSYM_Escape || key == KSYM_Return)
4972 key = KSYM_UNDEFINED; /* keep old value */
4974 got_key_event = TRUE;
4978 case EVENT_KEYRELEASE:
4979 key_joystick_mapping = 0;
4983 HandleOtherEvents(&event);
4991 /* don't eat all CPU time */
4998 static int getSetupTextFont(int type)
5000 if (type & (TYPE_SWITCH |
5012 static int getSetupValueFont(int type, void *value)
5014 if (type & TYPE_KEY)
5015 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5016 else if (type & TYPE_STRING)
5017 return FONT_VALUE_2;
5018 else if (type & TYPE_ECS_AGA)
5019 return FONT_VALUE_1;
5020 else if (type & TYPE_BOOLEAN_STYLE)
5021 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5022 else if (type & TYPE_YES_NO_AUTO)
5023 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5024 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5026 return FONT_VALUE_1;
5029 static void drawSetupValue(int pos)
5031 boolean font_draw_xoffset_modified = FALSE;
5032 int font_draw_xoffset_old = -1;
5033 int xpos = MENU_SCREEN_VALUE_XPOS;
5034 int ypos = MENU_SCREEN_START_YPOS + pos;
5035 int startx = mSX + xpos * 32;
5036 int starty = mSY + ypos * 32;
5037 int font_nr, font_width;
5041 int type = setup_info[pos].type;
5042 void *value = setup_info[pos].value;
5043 char *value_string = getSetupValue(type, value);
5048 if (value_string == NULL)
5051 if (type & TYPE_KEY)
5053 xpos = MENU_SCREEN_START_XPOS;
5055 if (type & TYPE_QUERY)
5056 value_string = "<press key>";
5058 else if (type & TYPE_STRING)
5060 int max_value_len = (SCR_FIELDX - 2) * 2;
5062 xpos = MENU_SCREEN_START_XPOS;
5064 if (strlen(value_string) > max_value_len)
5065 value_string[max_value_len] = '\0';
5067 else if (type & TYPE_YES_NO_AUTO)
5069 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5072 startx = mSX + xpos * 32;
5073 starty = mSY + ypos * 32;
5074 font_nr = getSetupValueFont(type, value);
5075 font_width = getFontWidth(font_nr);
5077 font_height = getFontHeight(font_nr);
5080 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5081 if (setup_mode != SETUP_MODE_INPUT)
5083 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5084 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5085 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5086 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5087 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5088 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5089 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5090 boolean correct_font_draw_xoffset = FALSE;
5092 if (xpos == MENU_SCREEN_START_XPOS &&
5093 startx + font1_xoffset < text_startx + text_font_xoffset)
5094 correct_font_draw_xoffset = TRUE;
5096 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5097 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5098 correct_font_draw_xoffset = TRUE;
5100 /* check if setup value would overlap with setup text when printed */
5101 /* (this can happen for extreme/wrong values for font draw offset) */
5102 if (correct_font_draw_xoffset)
5104 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5105 font_draw_xoffset_modified = TRUE;
5107 if (type & TYPE_KEY)
5108 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5109 else if (!(type & TYPE_STRING))
5110 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5111 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5116 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5118 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5119 DrawText(startx + i * font_width, starty, " ", font_nr);
5122 DrawText(startx, starty, value_string, font_nr);
5124 if (font_draw_xoffset_modified)
5125 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5128 static void changeSetupValue(int pos, int dx)
5130 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5132 *(boolean *)setup_info[pos].value ^= TRUE;
5134 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5136 *(int *)setup_info[pos].value =
5138 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5139 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5140 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5141 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5143 else if (setup_info[pos].type & TYPE_KEY)
5147 setup_info[pos].type |= TYPE_QUERY;
5148 drawSetupValue(pos);
5149 setup_info[pos].type &= ~TYPE_QUERY;
5151 key = getSetupKey();
5152 if (key != KSYM_UNDEFINED)
5153 *(Key *)setup_info[pos].value = key;
5156 drawSetupValue(pos);
5159 static void DrawCursorAndText_Setup(int pos, boolean active)
5161 int xpos = MENU_SCREEN_START_XPOS;
5162 int ypos = MENU_SCREEN_START_YPOS + pos;
5163 int font_nr = getSetupTextFont(setup_info[pos].type);
5165 if (setup_info == setup_info_input)
5166 font_nr = FONT_MENU_1;
5169 font_nr = FONT_ACTIVE(font_nr);
5171 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5173 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5174 drawCursor(pos, active);
5177 static void DrawSetupScreen_Generic()
5179 boolean redraw_all = FALSE;
5180 char *title_string = NULL;
5184 CloseDoor(DOOR_CLOSE_2);
5186 if (redraw_mask & REDRAW_ALL)
5190 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5191 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5192 int2str(0, redraw_mask)));
5196 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5197 FadeOut(redraw_mask);
5199 FadeOut(REDRAW_FIELD);
5204 if (setup_mode == SETUP_MODE_MAIN)
5206 setup_info = setup_info_main;
5207 title_string = "Setup";
5209 else if (setup_mode == SETUP_MODE_GAME)
5211 setup_info = setup_info_game;
5212 title_string = "Setup Game";
5214 else if (setup_mode == SETUP_MODE_EDITOR)
5216 setup_info = setup_info_editor;
5217 title_string = "Setup Editor";
5219 else if (setup_mode == SETUP_MODE_GRAPHICS)
5221 setup_info = setup_info_graphics;
5222 title_string = "Setup Graphics";
5224 else if (setup_mode == SETUP_MODE_SOUND)
5226 setup_info = setup_info_sound;
5227 title_string = "Setup Sound";
5229 else if (setup_mode == SETUP_MODE_ARTWORK)
5231 setup_info = setup_info_artwork;
5232 title_string = "Custom Artwork";
5234 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5236 setup_info = setup_info_shortcuts;
5237 title_string = "Setup Shortcuts";
5239 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5241 setup_info = setup_info_shortcuts_1;
5242 title_string = "Setup Shortcuts";
5244 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5246 setup_info = setup_info_shortcuts_2;
5247 title_string = "Setup Shortcuts";
5249 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5251 setup_info = setup_info_shortcuts_3;
5252 title_string = "Setup Shortcuts";
5254 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5256 setup_info = setup_info_shortcuts_4;
5257 title_string = "Setup Shortcuts";
5259 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5261 setup_info = setup_info_shortcuts_5;
5262 title_string = "Setup Shortcuts";
5265 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5269 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5271 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5274 void *value_ptr = setup_info[i].value;
5276 /* set some entries to "unchangeable" according to other variables */
5277 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5278 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5279 (value_ptr == &setup.sound_music && !audio.music_available) ||
5280 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5281 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5282 (value_ptr == &window_size_text && !video.window_scaling_available))
5283 setup_info[i].type |= TYPE_GHOSTED;
5285 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5286 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5287 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5288 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5289 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5290 initCursor(i, IMG_MENU_BUTTON);
5292 DrawCursorAndText_Setup(i, FALSE);
5294 if (setup_info[i].type & TYPE_VALUE)
5301 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5302 "Joysticks deactivated in setup menu");
5306 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5310 redraw_mask = REDRAW_ALL;
5313 FadeIn(redraw_mask);
5315 FadeIn(REDRAW_FIELD);
5320 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5324 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5326 static int choice_store[MAX_SETUP_MODES];
5327 int choice = choice_store[setup_mode]; /* always starts with 0 */
5331 if (button == MB_MENU_INITIALIZE)
5333 /* advance to first valid menu entry */
5334 while (choice < num_setup_info &&
5335 setup_info[choice].type & TYPE_SKIP_ENTRY)
5337 choice_store[setup_mode] = choice;
5339 DrawCursorAndText_Setup(choice, TRUE);
5343 else if (button == MB_MENU_LEAVE)
5345 PlaySound(SND_MENU_ITEM_SELECTING);
5347 for (y = 0; y < num_setup_info; y++)
5349 if (setup_info[y].type & TYPE_LEAVE_MENU)
5351 void (*menu_callback_function)(void) = setup_info[y].value;
5355 menu_callback_function();
5357 break; /* absolutely needed because function changes 'setup_info'! */
5364 if (mx || my) /* mouse input */
5366 x = (mx - mSX) / 32;
5367 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5369 else if (dx || dy) /* keyboard input */
5373 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5375 if (setup_info[choice].type & menu_navigation_type ||
5376 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5377 setup_info[choice].type & TYPE_YES_NO_AUTO)
5378 button = MB_MENU_CHOICE;
5383 /* jump to next non-empty menu entry (up or down) */
5384 while (y > 0 && y < num_setup_info - 1 &&
5385 setup_info[y].type & TYPE_SKIP_ENTRY)
5389 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
5393 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
5395 PlaySound(SND_MENU_ITEM_ACTIVATING);
5397 DrawCursorAndText_Setup(choice, FALSE);
5398 DrawCursorAndText_Setup(y, TRUE);
5400 choice = choice_store[setup_mode] = y;
5403 else if (!(setup_info[y].type & TYPE_GHOSTED))
5405 PlaySound(SND_MENU_ITEM_SELECTING);
5407 /* when selecting key headline, execute function for key value change */
5408 if (setup_info[y].type & TYPE_KEYTEXT &&
5409 setup_info[y + 1].type & TYPE_KEY)
5412 /* when selecting string value, execute function for list selection */
5413 if (setup_info[y].type & TYPE_STRING && y > 0 &&
5414 setup_info[y - 1].type & TYPE_ENTER_LIST)
5417 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
5419 void (*menu_callback_function)(void) = setup_info[y].value;
5421 FadeSetFromType(setup_info[y].type);
5423 menu_callback_function();
5427 if (setup_info[y].type & TYPE_VALUE)
5428 changeSetupValue(y, dx);
5434 void DrawSetupScreen_Input()
5439 FadeOut(REDRAW_FIELD);
5445 setup_info = setup_info_input;
5448 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5452 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5453 "Joysticks deactivated on this screen");
5455 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5456 "Joysticks deactivated on this screen");
5461 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5463 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5466 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5467 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5468 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5469 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5470 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5471 initCursor(i, IMG_MENU_BUTTON);
5473 DrawCursorAndText_Setup(i, FALSE);
5477 DeactivateJoystickForCalibration();
5482 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5483 "Joysticks deactivated on this screen");
5485 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5486 "Joysticks deactivated on this screen");
5490 /* create gadgets for setup input menu screen */
5491 FreeScreenGadgets();
5492 CreateScreenGadgets();
5494 /* map gadgets for setup input menu screen */
5495 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5497 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5500 FadeIn(REDRAW_FIELD);
5506 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5508 if (device_name == NULL)
5511 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5514 if (strlen(device_name) > 1)
5516 char c1 = device_name[strlen(device_name) - 1];
5517 char c2 = device_name[strlen(device_name) - 2];
5519 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5520 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5523 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5524 strlen(device_name));
5527 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5530 static struct SetupKeyboardInfo custom_key;
5537 { &custom_key.left, "Joystick Left" },
5538 { &custom_key.right, "Joystick Right" },
5539 { &custom_key.up, "Joystick Up" },
5540 { &custom_key.down, "Joystick Down" },
5541 { &custom_key.snap, "Button 1" },
5542 { &custom_key.drop, "Button 2" }
5544 static char *joystick_name[MAX_PLAYERS] =
5551 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5555 custom_key = setup.input[player_nr].key;
5557 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5558 FONT_INPUT_1_ACTIVE);
5560 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5562 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5563 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5565 if (setup.input[player_nr].use_joystick)
5567 char *device_name = setup.input[player_nr].joy.device_name;
5568 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5569 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5571 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5572 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5576 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5577 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5580 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5582 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5583 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5584 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5585 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5587 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5588 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5589 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5590 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5591 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5592 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5594 for (i = 0; i < 6; i++)
5596 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5598 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5600 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5601 (setup.input[player_nr].use_joystick ?
5603 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5607 static int input_player_nr = 0;
5609 void HandleSetupScreen_Input_Player(int step, int direction)
5611 int old_player_nr = input_player_nr;
5614 new_player_nr = old_player_nr + step * direction;
5615 if (new_player_nr < 0)
5617 if (new_player_nr > MAX_PLAYERS - 1)
5618 new_player_nr = MAX_PLAYERS - 1;
5620 if (new_player_nr != old_player_nr)
5622 input_player_nr = new_player_nr;
5624 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5628 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
5630 static int choice = 0;
5633 int pos_start = SETUPINPUT_SCREEN_POS_START;
5634 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
5635 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
5636 int pos_end = SETUPINPUT_SCREEN_POS_END;
5638 if (button == MB_MENU_INITIALIZE)
5640 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
5642 DrawCursorAndText_Setup(choice, TRUE);
5646 else if (button == MB_MENU_LEAVE)
5648 setup_mode = SETUP_MODE_MAIN;
5655 if (mx || my) /* mouse input */
5657 x = (mx - mSX) / 32;
5658 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5660 else if (dx || dy) /* keyboard input */
5662 if (dx && choice == 0)
5663 x = (dx < 0 ? 10 : 12);
5664 else if ((dx && choice == 1) ||
5665 (dx == +1 && choice == 2) ||
5666 (dx == -1 && choice == pos_end))
5667 button = MB_MENU_CHOICE;
5671 if (y >= pos_empty1 && y <= pos_empty2)
5672 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
5675 if (y == 0 && dx != 0 && button)
5677 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
5679 else if (IN_VIS_FIELD(x, y) &&
5680 y >= pos_start && y <= pos_end &&
5681 !(y >= pos_empty1 && y <= pos_empty2))
5687 DrawCursorAndText_Setup(choice, FALSE);
5688 DrawCursorAndText_Setup(y, TRUE);
5690 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
5699 char *device_name = setup.input[input_player_nr].joy.device_name;
5701 if (!setup.input[input_player_nr].use_joystick)
5703 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
5705 setJoystickDeviceToNr(device_name, new_device_nr);
5706 setup.input[input_player_nr].use_joystick = TRUE;
5710 int device_nr = getJoystickNrFromDeviceName(device_name);
5711 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
5713 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
5714 setup.input[input_player_nr].use_joystick = FALSE;
5716 setJoystickDeviceToNr(device_name, new_device_nr);
5719 drawPlayerSetupInputInfo(input_player_nr, FALSE);
5723 if (setup.input[input_player_nr].use_joystick)
5726 CalibrateJoystick(input_player_nr);
5729 CustomizeKeyboard(input_player_nr);
5731 else if (y == pos_end)
5737 setup_mode = SETUP_MODE_MAIN;
5744 void CustomizeKeyboard(int player_nr)
5748 boolean finished = FALSE;
5749 static struct SetupKeyboardInfo custom_key;
5754 } customize_step[] =
5756 { &custom_key.left, "Move Left" },
5757 { &custom_key.right, "Move Right" },
5758 { &custom_key.up, "Move Up" },
5759 { &custom_key.down, "Move Down" },
5760 { &custom_key.snap, "Snap Field" },
5761 { &custom_key.drop, "Drop Element" }
5764 /* read existing key bindings from player setup */
5765 custom_key = setup.input[player_nr].key;
5768 FadeOut(REDRAW_FIELD);
5772 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
5780 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5781 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5782 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5783 "Key:", FONT_INPUT_1_ACTIVE);
5784 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5785 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
5788 FadeIn(REDRAW_FIELD);
5795 if (PendingEvent()) /* got event */
5803 case EVENT_KEYPRESS:
5805 Key key = GetEventKey((KeyEvent *)&event, FALSE);
5807 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
5809 if (key == KSYM_Escape)
5810 FadeSkipNextFadeIn();
5816 /* all keys configured -- wait for "Escape" or "Return" key */
5820 /* press 'Enter' to keep the existing key binding */
5821 if (key == KSYM_Return)
5822 key = *customize_step[step_nr].key;
5824 /* check if key already used */
5825 for (i = 0; i < step_nr; i++)
5826 if (*customize_step[i].key == key)
5831 /* got new key binding */
5832 *customize_step[step_nr].key = key;
5833 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5835 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5836 getKeyNameFromKey(key), FONT_VALUE_1);
5839 /* un-highlight last query */
5840 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
5841 customize_step[step_nr - 1].text, FONT_MENU_1);
5842 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
5843 "Key:", FONT_MENU_1);
5845 /* press 'Enter' to leave */
5848 DrawText(mSX + 16, mSY + 15 * 32 + 16,
5849 "Press Enter", FONT_TITLE_1);
5853 /* query next key binding */
5854 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
5855 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
5856 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
5857 "Key:", FONT_INPUT_1_ACTIVE);
5858 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
5859 getKeyNameFromKey(*customize_step[step_nr].key),
5864 case EVENT_KEYRELEASE:
5865 key_joystick_mapping = 0;
5869 HandleOtherEvents(&event);
5877 /* don't eat all CPU time */
5881 /* write new key bindings back to player setup */
5882 setup.input[player_nr].key = custom_key;
5885 DrawSetupScreen_Input();
5888 static boolean CalibrateJoystickMain(int player_nr)
5890 int new_joystick_xleft = JOYSTICK_XMIDDLE;
5891 int new_joystick_xright = JOYSTICK_XMIDDLE;
5892 int new_joystick_yupper = JOYSTICK_YMIDDLE;
5893 int new_joystick_ylower = JOYSTICK_YMIDDLE;
5894 int new_joystick_xmiddle, new_joystick_ymiddle;
5896 int joystick_fd = joystick.fd[player_nr];
5897 int x, y, last_x, last_y, xpos = 8, ypos = 3;
5898 boolean check[3][3];
5899 int check_remaining = 3 * 3;
5904 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
5907 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
5911 FadeOut(REDRAW_FIELD);
5915 for (y = 0; y < 3; y++)
5917 for (x = 0; x < 3; x++)
5919 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
5920 check[x][y] = FALSE;
5924 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
5925 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
5926 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
5927 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
5928 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
5929 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
5930 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
5932 joy_value = Joystick(player_nr);
5933 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
5934 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
5936 /* eventually uncalibrated center position (joystick could be uncentered) */
5937 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5940 new_joystick_xmiddle = joy_x;
5941 new_joystick_ymiddle = joy_y;
5943 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
5945 FadeIn(REDRAW_FIELD);
5947 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
5952 if (PendingEvent()) /* got event */
5960 case EVENT_KEYPRESS:
5961 switch (GetEventKey((KeyEvent *)&event, TRUE))
5964 if (check_remaining == 0)
5969 FadeSkipNextFadeIn();
5978 case EVENT_KEYRELEASE:
5979 key_joystick_mapping = 0;
5983 HandleOtherEvents(&event);
5988 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
5991 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
5992 new_joystick_xright = MAX(new_joystick_xright, joy_x);
5993 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
5994 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
5996 setup.input[player_nr].joy.xleft = new_joystick_xleft;
5997 setup.input[player_nr].joy.yupper = new_joystick_yupper;
5998 setup.input[player_nr].joy.xright = new_joystick_xright;
5999 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6000 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6001 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6003 CheckJoystickData();
6005 joy_value = Joystick(player_nr);
6007 if (joy_value & JOY_BUTTON && check_remaining == 0)
6010 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6011 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6013 if (x != last_x || y != last_y)
6015 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6016 IMG_MENU_CALIBRATE_YELLOW, 0);
6017 DrawFixedGraphic(xpos + x, ypos + y,
6018 IMG_MENU_CALIBRATE_RED, 0);
6023 if (check_remaining > 0 && !check[x+1][y+1])
6025 check[x+1][y+1] = TRUE;
6031 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6032 setup.input[player_nr].joy.xleft,
6033 setup.input[player_nr].joy.xmiddle,
6034 setup.input[player_nr].joy.xright);
6035 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6036 setup.input[player_nr].joy.yupper,
6037 setup.input[player_nr].joy.ymiddle,
6038 setup.input[player_nr].joy.ylower);
6047 /* don't eat all CPU time */
6051 /* calibrated center position (joystick should now be centered) */
6052 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6055 new_joystick_xmiddle = joy_x;
6056 new_joystick_ymiddle = joy_y;
6061 DrawSetupScreen_Input();
6064 /* wait until the last pressed button was released */
6065 while (Joystick(player_nr) & JOY_BUTTON)
6067 if (PendingEvent()) /* got event */
6072 HandleOtherEvents(&event);
6081 void CalibrateJoystick(int player_nr)
6083 if (!CalibrateJoystickMain(player_nr))
6085 char *device_name = setup.input[player_nr].joy.device_name;
6086 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6087 int xpos = mSX - SX;
6088 int ypos = mSY - SY;
6092 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6093 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6096 Delay(2000); /* show error message for a short time */
6102 DrawSetupScreen_Input();
6106 void DrawSetupScreen()
6108 DeactivateJoystick();
6110 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6112 if (setup_mode == SETUP_MODE_INPUT)
6113 DrawSetupScreen_Input();
6114 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6115 DrawChooseTree(&game_speed_current);
6116 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6117 DrawChooseTree(&screen_mode_current);
6118 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6119 DrawChooseTree(&window_size_current);
6120 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6121 DrawChooseTree(&scroll_delay_current);
6122 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6123 DrawChooseTree(&artwork.gfx_current);
6124 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6125 DrawChooseTree(&artwork.snd_current);
6126 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6127 DrawChooseTree(&artwork.mus_current);
6128 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6129 DrawChooseTree(&volume_simple_current);
6130 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6131 DrawChooseTree(&volume_loops_current);
6132 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6133 DrawChooseTree(&volume_music_current);
6135 DrawSetupScreen_Generic();
6141 void RedrawSetupScreenAfterFullscreenToggle()
6144 if (setup_mode == SETUP_MODE_GRAPHICS ||
6145 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6147 // update "setup.window_scaling_percent" from list selection
6148 execSetupGraphics_setWindowSizes(TRUE);
6153 if (setup_mode == SETUP_MODE_GRAPHICS)
6158 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6160 if (setup_mode == SETUP_MODE_INPUT)
6161 HandleSetupScreen_Input(mx, my, dx, dy, button);
6162 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6163 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6164 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6165 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6166 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6167 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6168 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6169 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6170 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6171 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6172 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6173 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6174 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6175 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6176 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6177 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6178 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6179 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6180 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6181 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6183 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6188 void HandleGameActions()
6190 if (game_status != GAME_MODE_PLAYING)
6193 GameActions(); /* main game loop */
6195 if (tape.auto_play && !tape.playing)
6196 AutoPlayTape(); /* continue automatically playing next tape */
6200 /* ---------- new screen button stuff -------------------------------------- */
6202 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6207 case SCREEN_CTRL_ID_PREV_LEVEL:
6208 *x = mSX + menu.main.button.prev_level.x;
6209 *y = mSY + menu.main.button.prev_level.y;
6212 case SCREEN_CTRL_ID_NEXT_LEVEL:
6213 *x = mSX + menu.main.button.next_level.x;
6214 *y = mSY + menu.main.button.next_level.y;
6217 case SCREEN_CTRL_ID_PREV_LEVEL:
6218 *x = mSX + TILEX * getPrevlevelButtonPos();
6219 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6222 case SCREEN_CTRL_ID_NEXT_LEVEL:
6223 *x = mSX + TILEX * getNextLevelButtonPos();
6224 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6228 case SCREEN_CTRL_ID_PREV_PLAYER:
6229 *x = mSX + TILEX * 10;
6230 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6233 case SCREEN_CTRL_ID_NEXT_PLAYER:
6234 *x = mSX + TILEX * 12;
6235 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6239 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6245 int gfx_unpressed, gfx_pressed;
6246 void (*get_gadget_position)(int *, int *, int);
6250 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6253 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6254 getScreenMenuButtonPos,
6255 SCREEN_CTRL_ID_PREV_LEVEL,
6260 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6261 getScreenMenuButtonPos,
6262 SCREEN_CTRL_ID_NEXT_LEVEL,
6267 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6268 getScreenMenuButtonPos,
6269 SCREEN_CTRL_ID_PREV_PLAYER,
6274 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6275 getScreenMenuButtonPos,
6276 SCREEN_CTRL_ID_NEXT_PLAYER,
6284 int gfx_unpressed, gfx_pressed;
6288 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6291 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6293 -1, -1, /* these values are not constant, but can change at runtime */
6295 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
6297 SCREEN_CTRL_ID_SCROLL_UP,
6301 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6303 -1, -1, /* these values are not constant, but can change at runtime */
6305 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
6307 SCREEN_CTRL_ID_SCROLL_DOWN,
6314 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6315 Bitmap **gfx_unpressed, **gfx_pressed;
6317 int gfx_unpressed, gfx_pressed;
6324 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6327 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6328 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
6330 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6333 -1, -1, /* these values are not constant, but can change at runtime */
6334 -1, -1, /* these values are not constant, but can change at runtime */
6336 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
6337 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
6339 GD_TYPE_SCROLLBAR_VERTICAL,
6340 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6341 "scroll level series vertically"
6345 static void CreateScreenMenubuttons()
6347 struct GadgetInfo *gi;
6348 unsigned int event_mask;
6351 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6353 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6354 int gfx_unpressed, gfx_pressed;
6355 int x, y, width, height;
6356 int gd_x1, gd_x2, gd_y1, gd_y2;
6357 int id = menubutton_info[i].gadget_id;
6359 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6361 menubutton_info[i].get_gadget_position(&x, &y, id);
6363 width = SC_MENUBUTTON_XSIZE;
6364 height = SC_MENUBUTTON_YSIZE;
6366 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6367 gfx_pressed = menubutton_info[i].gfx_pressed;
6368 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6369 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6370 gd_x1 = graphic_info[gfx_unpressed].src_x;
6371 gd_y1 = graphic_info[gfx_unpressed].src_y;
6372 gd_x2 = graphic_info[gfx_pressed].src_x;
6373 gd_y2 = graphic_info[gfx_pressed].src_y;
6375 gi = CreateGadget(GDI_CUSTOM_ID, id,
6376 GDI_CUSTOM_TYPE_ID, i,
6377 GDI_INFO_TEXT, menubutton_info[i].infotext,
6382 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6383 GDI_STATE, GD_BUTTON_UNPRESSED,
6384 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6385 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6386 GDI_DIRECT_DRAW, FALSE,
6387 GDI_EVENT_MASK, event_mask,
6388 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6392 Error(ERR_EXIT, "cannot create gadget");
6394 screen_gadget[id] = gi;
6398 static void CreateScreenScrollbuttons()
6400 struct GadgetInfo *gi;
6401 unsigned int event_mask;
6404 /* these values are not constant, but can change at runtime */
6405 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6406 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6407 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6408 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6410 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6412 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6413 int gfx_unpressed, gfx_pressed;
6414 int x, y, width, height;
6415 int gd_x1, gd_x2, gd_y1, gd_y2;
6416 int id = scrollbutton_info[i].gadget_id;
6418 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6420 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6421 y = mSY + scrollbutton_info[i].y;
6422 width = SC_SCROLLBUTTON_XSIZE;
6423 height = SC_SCROLLBUTTON_YSIZE;
6425 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6426 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6427 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6429 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6430 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6431 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6432 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6433 gd_x1 = graphic_info[gfx_unpressed].src_x;
6434 gd_y1 = graphic_info[gfx_unpressed].src_y;
6435 gd_x2 = graphic_info[gfx_pressed].src_x;
6436 gd_y2 = graphic_info[gfx_pressed].src_y;
6438 gi = CreateGadget(GDI_CUSTOM_ID, id,
6439 GDI_CUSTOM_TYPE_ID, i,
6440 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6445 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6446 GDI_STATE, GD_BUTTON_UNPRESSED,
6447 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6448 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6449 GDI_DIRECT_DRAW, FALSE,
6450 GDI_EVENT_MASK, event_mask,
6451 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6455 Error(ERR_EXIT, "cannot create gadget");
6457 screen_gadget[id] = gi;
6461 static void CreateScreenScrollbars()
6465 /* these values are not constant, but can change at runtime */
6466 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6467 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6468 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6469 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6471 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6473 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6474 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6475 int gfx_unpressed, gfx_pressed;
6477 int x, y, width, height;
6478 int gd_x1, gd_x2, gd_y1, gd_y2;
6479 struct GadgetInfo *gi;
6480 int items_max, items_visible, item_position;
6481 unsigned int event_mask;
6482 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6483 int id = scrollbar_info[i].gadget_id;
6485 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6487 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6488 y = mSY + scrollbar_info[i].y;
6489 width = scrollbar_info[i].width;
6490 height = scrollbar_info[i].height;
6492 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6493 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6495 items_max = num_page_entries;
6496 items_visible = num_page_entries;
6499 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6500 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
6501 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
6507 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6508 gfx_pressed = scrollbar_info[i].gfx_pressed;
6509 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6510 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6511 gd_x1 = graphic_info[gfx_unpressed].src_x;
6512 gd_y1 = graphic_info[gfx_unpressed].src_y;
6513 gd_x2 = graphic_info[gfx_pressed].src_x;
6514 gd_y2 = graphic_info[gfx_pressed].src_y;
6517 gi = CreateGadget(GDI_CUSTOM_ID, id,
6518 GDI_CUSTOM_TYPE_ID, i,
6519 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6524 GDI_TYPE, scrollbar_info[i].type,
6525 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6526 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6527 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6529 GDI_WHEEL_AREA_X, SX,
6530 GDI_WHEEL_AREA_Y, SY,
6531 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6532 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6534 GDI_WHEEL_AREA_X, 0,
6535 GDI_WHEEL_AREA_Y, 0,
6536 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
6537 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
6539 GDI_STATE, GD_BUTTON_UNPRESSED,
6540 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6541 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6542 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6543 GDI_DIRECT_DRAW, FALSE,
6544 GDI_EVENT_MASK, event_mask,
6545 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6549 Error(ERR_EXIT, "cannot create gadget");
6551 screen_gadget[id] = gi;
6555 void CreateScreenGadgets()
6557 int last_game_status = game_status; /* save current game status */
6559 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6562 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6564 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
6566 /* copy pointers to clip mask and GC */
6567 scrollbar_bitmap[i]->clip_mask =
6568 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
6569 scrollbar_bitmap[i]->stored_clip_gc =
6570 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
6572 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
6573 scrollbar_bitmap[i],
6574 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
6575 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
6576 TILEX, TILEY, 0, 0);
6580 CreateScreenMenubuttons();
6583 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
6584 game_status = GAME_MODE_LEVELS;
6587 CreateScreenScrollbuttons();
6588 CreateScreenScrollbars();
6590 game_status = last_game_status; /* restore current game status */
6593 void FreeScreenGadgets()
6597 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
6598 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
6600 /* prevent freeing clip mask and GC twice */
6601 scrollbar_bitmap[i]->clip_mask = None;
6602 scrollbar_bitmap[i]->stored_clip_gc = None;
6604 FreeBitmap(scrollbar_bitmap[i]);
6608 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6609 FreeGadget(screen_gadget[i]);
6612 void MapScreenMenuGadgets(int screen_mask)
6616 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6617 if (screen_mask & menubutton_info[i].screen_mask)
6618 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6621 void MapScreenTreeGadgets(TreeInfo *ti)
6623 int num_entries = numTreeInfoInGroup(ti);
6626 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6629 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6630 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6632 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6633 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6636 static void HandleScreenGadgets(struct GadgetInfo *gi)
6638 int id = gi->custom_id;
6639 int button = gi->event.button;
6640 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6644 case SCREEN_CTRL_ID_PREV_LEVEL:
6645 HandleMainMenu_SelectLevel(step, -1);
6648 case SCREEN_CTRL_ID_NEXT_LEVEL:
6649 HandleMainMenu_SelectLevel(step, +1);
6652 case SCREEN_CTRL_ID_PREV_PLAYER:
6653 HandleSetupScreen_Input_Player(step, -1);
6656 case SCREEN_CTRL_ID_NEXT_PLAYER:
6657 HandleSetupScreen_Input_Player(step, +1);
6660 case SCREEN_CTRL_ID_SCROLL_UP:
6661 if (game_status == GAME_MODE_LEVELS)
6662 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6663 else if (game_status == GAME_MODE_LEVELNR)
6664 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6665 else if (game_status == GAME_MODE_SETUP)
6666 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6669 case SCREEN_CTRL_ID_SCROLL_DOWN:
6670 if (game_status == GAME_MODE_LEVELS)
6671 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6672 else if (game_status == GAME_MODE_LEVELNR)
6673 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6674 else if (game_status == GAME_MODE_SETUP)
6675 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6678 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6679 if (game_status == GAME_MODE_LEVELS)
6680 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6681 else if (game_status == GAME_MODE_LEVELNR)
6682 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6683 else if (game_status == GAME_MODE_SETUP)
6684 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);