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_SCROLL_DELAY 16
64 #define SETUP_MODE_CHOOSE_SCREEN_MODE 17
65 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 18
66 #define SETUP_MODE_CHOOSE_SCALING_TYPE 19
67 #define SETUP_MODE_CHOOSE_GRAPHICS 20
68 #define SETUP_MODE_CHOOSE_SOUNDS 21
69 #define SETUP_MODE_CHOOSE_MUSIC 22
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 23
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 24
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 25
74 #define MAX_SETUP_MODES 26
76 /* for input setup functions */
77 #define SETUPINPUT_SCREEN_POS_START 0
78 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
79 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
80 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
82 /* for various menu stuff */
83 #define MENU_SCREEN_START_XPOS 1
84 #define MENU_SCREEN_START_YPOS 2
86 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
87 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
89 #define MENU_SCREEN_VALUE_XPOS 14
90 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
104 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
105 MENU_SCREEN_INFO_YSTEP, \
106 MAX_INFO_ELEMENTS_ON_SCREEN)
108 #define NUM_INFO_ELEMENTS_ON_SCREEN 10
110 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
112 #define MAX_MENU_TEXT_LENGTH_BIG 13
113 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
115 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
116 MENU_SCREEN_START_XPOS)
117 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
120 /* buttons and scrollbars identifiers */
121 #define SCREEN_CTRL_ID_PREV_LEVEL 0
122 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
123 #define SCREEN_CTRL_ID_PREV_PLAYER 2
124 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
125 #define SCREEN_CTRL_ID_SCROLL_UP 4
126 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
127 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
129 #define NUM_SCREEN_GADGETS 7
131 #define NUM_SCREEN_MENUBUTTONS 4
132 #define NUM_SCREEN_SCROLLBUTTONS 2
133 #define NUM_SCREEN_SCROLLBARS 1
135 #define SCREEN_MASK_MAIN (1 << 0)
136 #define SCREEN_MASK_INPUT (1 << 1)
138 /* graphic position and size values for buttons and scrollbars */
139 #define SC_MENUBUTTON_XSIZE TILEX
140 #define SC_MENUBUTTON_YSIZE TILEY
142 #define SC_SCROLLBUTTON_XSIZE TILEX
143 #define SC_SCROLLBUTTON_YSIZE TILEY
145 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
147 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
148 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
149 SC_SCROLLBUTTON_YSIZE)
151 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
152 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
156 SC_SCROLLBUTTON_YSIZE)
158 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
159 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
160 SC_SCROLL_VERTICAL_YSIZE)
162 #define SC_BORDER_SIZE 14
165 /* forward declarations of internal functions */
166 static void HandleScreenGadgets(struct GadgetInfo *);
167 static void HandleSetupScreen_Generic(int, int, int, int, int);
168 static void HandleSetupScreen_Input(int, int, int, int, int);
169 static void CustomizeKeyboard(int);
170 static void CalibrateJoystick(int);
171 static void execSetupGame(void);
172 static void execSetupGraphics(void);
173 static void execSetupSound(void);
174 static void execSetupArtwork(void);
175 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
177 static void DrawChooseLevelSet(void);
178 static void DrawChooseLevelNr(void);
179 static void DrawInfoScreen(void);
180 static void DrawAndFadeInInfoScreen(int);
181 static void DrawSetupScreen(void);
183 static void DrawInfoScreenExt(int, int);
184 static void DrawInfoScreen_NotAvailable(char *, char *);
185 static void DrawInfoScreen_HelpAnim(int, int, boolean);
186 static void DrawInfoScreen_HelpText(int, int, int, int);
187 static void HandleInfoScreen_Main(int, int, int, int, int);
188 static void HandleInfoScreen_TitleScreen(int);
189 static void HandleInfoScreen_Elements(int);
190 static void HandleInfoScreen_Music(int);
191 static void HandleInfoScreen_Credits(int);
192 static void HandleInfoScreen_Program(int);
193 static void HandleInfoScreen_Version(int);
195 static void MapScreenMenuGadgets(int);
196 static void MapScreenGadgets(int);
197 static void MapScreenTreeGadgets(TreeInfo *);
199 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
201 static int info_mode = INFO_MODE_MAIN;
202 static int setup_mode = SETUP_MODE_MAIN;
204 static TreeInfo *screen_modes = NULL;
205 static TreeInfo *screen_mode_current = NULL;
207 static TreeInfo *window_sizes = NULL;
208 static TreeInfo *window_size_current = NULL;
210 static TreeInfo *scaling_types = NULL;
211 static TreeInfo *scaling_type_current = NULL;
213 static TreeInfo *scroll_delays = NULL;
214 static TreeInfo *scroll_delay_current = NULL;
216 static TreeInfo *game_speeds = NULL;
217 static TreeInfo *game_speed_current = NULL;
219 static TreeInfo *volumes_simple = NULL;
220 static TreeInfo *volume_simple_current = NULL;
222 static TreeInfo *volumes_loops = NULL;
223 static TreeInfo *volume_loops_current = NULL;
225 static TreeInfo *volumes_music = NULL;
226 static TreeInfo *volume_music_current = NULL;
228 static TreeInfo *level_number = NULL;
229 static TreeInfo *level_number_current = NULL;
235 } window_sizes_list[] =
240 { 100, "100 % (Default)" },
257 } scaling_types_list[] =
259 { SCALING_QUALITY_NEAREST, "None" },
260 { SCALING_QUALITY_LINEAR, "Linear" },
261 { SCALING_QUALITY_BEST, "Anisotropic" },
270 } game_speeds_list[] =
279 { 1000, "1/1s (Extremely Slow)" },
284 { 29, "1/35s (Original Supaplex)" },
286 { 20, "1/50s (Normal Speed)" },
287 { 14, "1/70s (Maximum Supaplex)" },
291 { 1, "1/1000s (Extremely Fast)" },
301 } scroll_delays_list[] =
303 { 0, "0 Tiles (No Scroll Delay)" },
306 { 3, "3 Tiles (Default)" },
311 { 8, "8 Tiles (Maximum Scroll Delay)"},
337 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
338 (s) <= GAME_MODE_SETUP ? (s) : \
339 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
340 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
342 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
343 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
344 (i) <= INFO_MODE_LEVELSET ? (i) : \
347 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
348 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
349 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
350 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
351 SETUP_MODE_CHOOSE_ARTWORK : \
352 SETUP_MODE_CHOOSE_OTHER)
354 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
355 menu.draw_xoffset[GAME_MODE_INFO] : \
356 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
357 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
358 menu.draw_yoffset[GAME_MODE_INFO] : \
359 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
361 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
362 menu.draw_xoffset[GAME_MODE_SETUP] : \
363 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
364 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
365 menu.draw_yoffset[GAME_MODE_SETUP] : \
366 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
368 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
369 DRAW_XOFFSET_INFO(info_mode) : \
370 (s) == GAME_MODE_SETUP ? \
371 DRAW_XOFFSET_SETUP(setup_mode) : \
372 menu.draw_xoffset[DRAW_MODE(s)])
373 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
374 DRAW_YOFFSET_INFO(info_mode) : \
375 (s) == GAME_MODE_SETUP ? \
376 DRAW_YOFFSET_SETUP(setup_mode) : \
377 menu.draw_yoffset[DRAW_MODE(s)])
379 #define mSX (SX + DRAW_XOFFSET(game_status))
380 #define mSY (SY + DRAW_YOFFSET(game_status))
382 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
383 menu.list_size[game_status] : \
384 MAX_MENU_ENTRIES_ON_SCREEN)
386 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
387 #define NUM_SCROLLBAR_BITMAPS 2
388 static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
392 /* title display and control definitions */
394 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
395 2 * MAX_NUM_TITLE_MESSAGES)
397 static int num_title_screens = 0;
399 struct TitleControlInfo
407 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
409 /* main menu display and control definitions */
411 #define MAIN_CONTROL_NAME 0
412 #define MAIN_CONTROL_LEVELS 1
413 #define MAIN_CONTROL_SCORES 2
414 #define MAIN_CONTROL_EDITOR 3
415 #define MAIN_CONTROL_INFO 4
416 #define MAIN_CONTROL_GAME 5
417 #define MAIN_CONTROL_SETUP 6
418 #define MAIN_CONTROL_QUIT 7
419 #define MAIN_CONTROL_PREV_LEVEL 8
420 #define MAIN_CONTROL_NEXT_LEVEL 9
421 #define MAIN_CONTROL_FIRST_LEVEL 10
422 #define MAIN_CONTROL_LAST_LEVEL 11
423 #define MAIN_CONTROL_LEVEL_NUMBER 12
424 #define MAIN_CONTROL_LEVEL_INFO_1 13
425 #define MAIN_CONTROL_LEVEL_INFO_2 14
426 #define MAIN_CONTROL_LEVEL_NAME 15
427 #define MAIN_CONTROL_LEVEL_AUTHOR 16
428 #define MAIN_CONTROL_LEVEL_YEAR 17
429 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
430 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
431 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
432 #define MAIN_CONTROL_TITLE_1 21
433 #define MAIN_CONTROL_TITLE_2 22
434 #define MAIN_CONTROL_TITLE_3 23
436 static char str_main_text_name[10];
437 static char str_main_text_first_level[10];
438 static char str_main_text_last_level[10];
439 static char str_main_text_level_number[10];
441 static char *main_text_name = str_main_text_name;
442 static char *main_text_first_level = str_main_text_first_level;
443 static char *main_text_last_level = str_main_text_last_level;
444 static char *main_text_level_number = str_main_text_level_number;
445 static char *main_text_levels = "Levelset";
446 static char *main_text_scores = "Hall Of Fame";
447 static char *main_text_editor = "Level Creator";
448 static char *main_text_info = "Info Screen";
449 static char *main_text_game = "Start Game";
450 static char *main_text_setup = "Setup";
451 static char *main_text_quit = "Quit";
452 static char *main_text_level_name = level.name;
453 static char *main_text_level_author = level.author;
454 static char *main_text_level_year = NULL;
455 static char *main_text_level_imported_from = NULL;
456 static char *main_text_level_imported_by = NULL;
457 static char *main_text_level_tested_by = NULL;
458 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
459 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
460 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
462 struct MainControlInfo
466 struct MenuPosInfo *pos_button;
469 struct TextPosInfo *pos_text;
472 struct TextPosInfo *pos_input;
476 static struct MainControlInfo main_controls[] =
480 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
481 &menu.main.text.name, &main_text_name,
482 &menu.main.input.name, &setup.player_name,
486 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
487 &menu.main.text.levels, &main_text_levels,
492 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
493 &menu.main.text.scores, &main_text_scores,
498 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
499 &menu.main.text.editor, &main_text_editor,
504 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
505 &menu.main.text.info, &main_text_info,
510 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
511 &menu.main.text.game, &main_text_game,
516 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
517 &menu.main.text.setup, &main_text_setup,
522 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
523 &menu.main.text.quit, &main_text_quit,
527 /* (these two buttons are real gadgets) */
529 MAIN_CONTROL_PREV_LEVEL,
530 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
535 MAIN_CONTROL_NEXT_LEVEL,
536 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
542 MAIN_CONTROL_FIRST_LEVEL,
544 &menu.main.text.first_level, &main_text_first_level,
548 MAIN_CONTROL_LAST_LEVEL,
550 &menu.main.text.last_level, &main_text_last_level,
554 MAIN_CONTROL_LEVEL_NUMBER,
556 &menu.main.text.level_number, &main_text_level_number,
560 MAIN_CONTROL_LEVEL_INFO_1,
562 &menu.main.text.level_info_1, NULL,
566 MAIN_CONTROL_LEVEL_INFO_2,
568 &menu.main.text.level_info_2, NULL,
572 MAIN_CONTROL_LEVEL_NAME,
574 &menu.main.text.level_name, &main_text_level_name,
578 MAIN_CONTROL_LEVEL_AUTHOR,
580 &menu.main.text.level_author, &main_text_level_author,
584 MAIN_CONTROL_LEVEL_YEAR,
586 &menu.main.text.level_year, &main_text_level_year,
590 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
592 &menu.main.text.level_imported_from, &main_text_level_imported_from,
596 MAIN_CONTROL_LEVEL_IMPORTED_BY,
598 &menu.main.text.level_imported_by, &main_text_level_imported_by,
602 MAIN_CONTROL_LEVEL_TESTED_BY,
604 &menu.main.text.level_tested_by, &main_text_level_tested_by,
608 MAIN_CONTROL_TITLE_1,
610 &menu.main.text.title_1, &main_text_title_1,
614 MAIN_CONTROL_TITLE_2,
616 &menu.main.text.title_2, &main_text_title_2,
620 MAIN_CONTROL_TITLE_3,
622 &menu.main.text.title_3, &main_text_title_3,
635 static int getTitleScreenGraphic(int nr, boolean initial)
637 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
640 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
642 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
646 static int getTitleScreenGameMode(boolean initial)
648 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
652 static int getTitleMessageGameMode(boolean initial)
654 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
658 static int getTitleScreenBackground(boolean initial)
660 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
665 static int getTitleMessageBackground(int nr, boolean initial)
667 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
671 static int getTitleBackground(int nr, boolean initial, boolean is_image)
673 int base = (is_image ?
674 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
675 IMG_BACKGROUND_TITLESCREEN_1) :
676 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
677 IMG_BACKGROUND_TITLEMESSAGE_1));
678 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
679 IMG_BACKGROUND_TITLE);
680 int graphic_local = base + nr;
682 if (graphic_info[graphic_local].bitmap != NULL)
683 return graphic_local;
685 if (graphic_info[graphic_global].bitmap != NULL)
686 return graphic_global;
688 return IMG_UNDEFINED;
691 static int getTitleSound(struct TitleControlInfo *tci)
693 boolean is_image = tci->is_image;
694 int initial = tci->initial;
695 int nr = tci->local_nr;
696 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
697 int base = (is_image ?
698 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
699 SND_BACKGROUND_TITLESCREEN_1) :
700 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
701 SND_BACKGROUND_TITLEMESSAGE_1));
702 int sound_global = menu.sound[mode];
703 int sound_local = base + nr;
706 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
707 nr, initial, is_image,
708 sound_global, getSoundListEntry(sound_global)->filename,
709 sound_local, getSoundListEntry(sound_local)->filename);
712 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
715 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
718 return SND_UNDEFINED;
721 static int getTitleMusic(struct TitleControlInfo *tci)
723 boolean is_image = tci->is_image;
724 int initial = tci->initial;
725 int nr = tci->local_nr;
726 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
727 int base = (is_image ?
728 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
729 MUS_BACKGROUND_TITLESCREEN_1) :
730 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
731 MUS_BACKGROUND_TITLEMESSAGE_1));
732 int music_global = menu.music[mode];
733 int music_local = base + nr;
736 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
737 nr, initial, is_image,
738 music_global, getMusicListEntry(music_global)->filename,
739 music_local, getMusicListEntry(music_local)->filename);
742 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
745 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
748 return MUS_UNDEFINED;
751 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
753 boolean is_image = tci->is_image;
754 int initial = tci->initial;
755 int nr = tci->local_nr;
756 struct TitleFadingInfo ti;
760 int graphic = getTitleScreenGraphic(nr, initial);
762 /* initialize fading control values to default title config settings */
763 ti = (initial ? title_initial_default : title_default);
765 /* override default settings with image config settings, if defined */
766 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
767 ti.fade_mode = graphic_info[graphic].fade_mode;
768 if (graphic_info[graphic].fade_delay > -1)
769 ti.fade_delay = graphic_info[graphic].fade_delay;
770 if (graphic_info[graphic].post_delay > -1)
771 ti.post_delay = graphic_info[graphic].post_delay;
772 if (graphic_info[graphic].auto_delay > -1)
773 ti.auto_delay = graphic_info[graphic].auto_delay;
779 ti.fade_mode = titlemessage_initial[nr].fade_mode;
780 ti.fade_delay = titlemessage_initial[nr].fade_delay;
781 ti.post_delay = titlemessage_initial[nr].post_delay;
782 ti.auto_delay = titlemessage_initial[nr].auto_delay;
786 ti.fade_mode = titlemessage[nr].fade_mode;
787 ti.fade_delay = titlemessage[nr].fade_delay;
788 ti.post_delay = titlemessage[nr].post_delay;
789 ti.auto_delay = titlemessage[nr].auto_delay;
794 if (ti.anim_mode == ANIM_NONE)
795 ti.fade_delay = ti.post_delay = 0;
801 static int compareTitleControlInfo(const void *object1, const void *object2)
803 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
804 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
807 if (tci1->initial != tci2->initial)
808 compare_result = (tci1->initial ? -1 : +1);
809 else if (tci1->sort_priority != tci2->sort_priority)
810 compare_result = tci1->sort_priority - tci2->sort_priority;
811 else if (tci1->is_image != tci2->is_image)
812 compare_result = (tci1->is_image ? -1 : +1);
814 compare_result = tci1->local_nr - tci2->local_nr;
816 return compare_result;
819 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
821 int nr, int sort_priority)
823 title_controls[num_title_screens].is_image = is_image;
824 title_controls[num_title_screens].initial = initial;
825 title_controls[num_title_screens].local_nr = nr;
826 title_controls[num_title_screens].sort_priority = sort_priority;
831 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
835 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
837 int graphic = getTitleScreenGraphic(i, initial);
838 Bitmap *bitmap = graphic_info[graphic].bitmap;
839 int sort_priority = graphic_info[graphic].sort_priority;
842 /* skip images and messages (fonts!) when using forced custom graphics */
843 if (setup.override_level_graphics && !initial)
848 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
851 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
853 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
854 char *filename = getLevelSetTitleMessageFilename(i, initial);
855 int sort_priority = tmi->sort_priority;
858 /* skip images and messages (fonts!) when using forced custom graphics */
859 if (setup.override_level_graphics)
863 if (filename != NULL)
864 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
868 static void InitializeTitleControls(boolean show_title_initial)
870 num_title_screens = 0;
873 /* 1st step: initialize title screens for game start (only when starting) */
874 if (show_title_initial)
875 InitializeTitleControls_CheckTitleInfo(TRUE);
878 /* 2nd step: initialize title screens for current level set */
879 InitializeTitleControls_CheckTitleInfo(FALSE);
881 /* sort title screens according to sort_priority and title number */
882 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
883 compareTitleControlInfo);
886 static boolean visibleMenuPos(struct MenuPosInfo *pos)
888 return (pos != NULL && pos->x != -1 && pos->y != -1);
891 static boolean visibleTextPos(struct TextPosInfo *pos)
893 return (pos != NULL && pos->x != -1 && pos->y != -1);
896 static void InitializeMainControls()
898 boolean local_team_mode = (!options.network && setup.team_mode);
901 /* set main control text values to dynamically determined values */
902 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
904 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
905 menu.main.text.first_level.size));
906 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
907 menu.main.text.last_level.size));
908 strcpy(main_text_level_number, int2str(level_nr,
909 menu.main.text.level_number.size));
911 main_text_level_year = leveldir_current->year;
912 main_text_level_imported_from = leveldir_current->imported_from;
913 main_text_level_imported_by = leveldir_current->imported_by;
914 main_text_level_tested_by = leveldir_current->tested_by;
916 /* set main control screen positions to dynamically determined values */
917 for (i = 0; main_controls[i].nr != -1; i++)
919 struct MainControlInfo *mci = &main_controls[i];
921 struct MenuPosInfo *pos_button = mci->pos_button;
922 struct TextPosInfo *pos_text = mci->pos_text;
923 struct TextPosInfo *pos_input = mci->pos_input;
924 char *text = (mci->text ? *mci->text : NULL);
925 char *input = (mci->input ? *mci->input : NULL);
926 int button_graphic = mci->button_graphic;
928 int font_text = (pos_text ? pos_text->font : -1);
929 int font_input = (pos_input ? pos_input->font : -1);
931 int font_text = mci->font_text;
932 int font_input = mci->font_input;
935 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
936 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
937 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
938 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
939 int text_chars = (text != NULL ? strlen(text) : 0);
940 int input_chars = (input != NULL ? strlen(input) : 0);
943 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
945 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
946 int text_width = font_text_width * text_chars;
947 int text_height = font_text_height;
948 int input_width = font_input_width * input_chars;
949 int input_height = font_input_height;
951 if (nr == MAIN_CONTROL_NAME)
954 if (menu.main.input.name.x == -1)
955 menu.main.input.name.x = menu.main.text.name.x + text_width;
956 if (menu.main.input.name.y == -1)
957 menu.main.input.name.y = menu.main.text.name.y;
961 menu.main.input.name.width = input_width;
962 menu.main.input.name.height = input_height;
964 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
965 menu.main.input.name.height = font_input_height;
969 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
971 if (pos_button->width == 0)
972 pos_button->width = button_width;
973 if (pos_button->height == 0)
974 pos_button->height = button_height;
977 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
980 /* calculate size for non-clickable text -- needed for text alignment */
981 boolean calculate_text_size = (pos_button == NULL && text != NULL);
983 /* calculate width for non-clickable text -- needed for text alignment */
984 boolean calculate_text_width = (pos_button == NULL && text != NULL);
987 if (visibleMenuPos(pos_button))
989 if (pos_text->x == -1)
990 pos_text->x = pos_button->x + pos_button->width;
991 if (pos_text->y == -1)
992 pos_text->y = pos_button->y;
996 if (pos_text->width == -1 || calculate_text_size)
997 pos_text->width = text_width;
998 if (pos_text->height == -1 || calculate_text_size)
999 pos_text->height = text_height;
1001 if (pos_text->width == -1 || calculate_text_width)
1002 pos_text->width = text_width;
1003 if (pos_text->height == -1)
1004 pos_text->height = text_height;
1008 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1010 if (visibleTextPos(pos_text))
1012 if (pos_input->x == -1)
1013 pos_input->x = pos_text->x + pos_text->width;
1014 if (pos_input->y == -1)
1015 pos_input->y = pos_text->y;
1018 if (pos_input->width == -1)
1019 pos_input->width = input_width;
1020 if (pos_input->height == -1)
1021 pos_input->height = input_height;
1026 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1027 boolean active_input)
1031 for (i = 0; main_controls[i].nr != -1; i++)
1033 struct MainControlInfo *mci = &main_controls[i];
1035 if (mci->nr == nr || nr == -1)
1037 struct MenuPosInfo *pos_button = mci->pos_button;
1038 struct TextPosInfo *pos_text = mci->pos_text;
1039 struct TextPosInfo *pos_input = mci->pos_input;
1040 char *text = (mci->text ? *mci->text : NULL);
1041 char *input = (mci->input ? *mci->input : NULL);
1042 int button_graphic = mci->button_graphic;
1044 int font_text = (pos_text ? pos_text->font : -1);
1045 int font_input = (pos_input ? pos_input->font : -1);
1047 int font_text = mci->font_text;
1048 int font_input = mci->font_input;
1053 button_graphic = BUTTON_ACTIVE(button_graphic);
1054 font_text = FONT_ACTIVE(font_text);
1059 font_input = FONT_ACTIVE(font_input);
1062 if (visibleMenuPos(pos_button))
1064 struct MenuPosInfo *pos = pos_button;
1065 int x = mSX + pos->x;
1066 int y = mSY + pos->y;
1068 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1069 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1072 if (visibleTextPos(pos_text) && text != NULL)
1074 struct TextPosInfo *pos = pos_text;
1075 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1076 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1079 /* (check why/if this is needed) */
1080 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1082 DrawText(x, y, text, font_text);
1085 if (visibleTextPos(pos_input) && input != NULL)
1087 struct TextPosInfo *pos = pos_input;
1088 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1089 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1092 /* (check why/if this is needed) */
1093 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1095 DrawText(x, y, input, font_input);
1101 static void DrawCursorAndText_Main(int nr, boolean active_text)
1103 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1107 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1109 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1113 static struct MainControlInfo *getMainControlInfo(int nr)
1117 for (i = 0; main_controls[i].nr != -1; i++)
1118 if (main_controls[i].nr == nr)
1119 return &main_controls[i];
1124 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1129 int rect_x = ALIGNED_TEXT_XPOS(rect);
1130 int rect_y = ALIGNED_TEXT_YPOS(rect);
1132 return (x >= rect_x && x < rect_x + rect->width &&
1133 y >= rect_y && y < rect_y + rect->height);
1136 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1141 int rect_x = ALIGNED_TEXT_XPOS(rect);
1142 int rect_y = ALIGNED_TEXT_YPOS(rect);
1145 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1146 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1147 (x >= rect_x && x < rect_x + rect->width &&
1148 y >= rect_y && y < rect_y + rect->height));
1151 return (x >= rect_x && x < rect_x + rect->width &&
1152 y >= rect_y && y < rect_y + rect->height);
1155 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1158 static int cursor_array[MAX_LEV_FIELDY];
1160 static int cursor_array[SCR_FIELDY];
1162 int x = mSX + TILEX * xpos;
1163 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1168 cursor_array[ypos] = graphic;
1170 graphic = cursor_array[ypos];
1174 graphic = BUTTON_ACTIVE(graphic);
1176 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1177 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1180 static void initCursor(int ypos, int graphic)
1182 drawCursorExt(0, ypos, FALSE, graphic);
1185 static void drawCursor(int ypos, boolean active)
1187 drawCursorExt(0, ypos, active, -1);
1190 static void drawCursorXY(int xpos, int ypos, int graphic)
1192 drawCursorExt(xpos, ypos, FALSE, graphic);
1195 static void drawChooseTreeCursor(int ypos, boolean active)
1197 int last_game_status = game_status; /* save current game status */
1200 /* force LEVELS draw offset on artwork setup screen */
1201 game_status = GAME_MODE_LEVELS;
1204 drawCursorExt(0, ypos, active, -1);
1206 game_status = last_game_status; /* restore current game status */
1211 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1212 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1216 static int getPrevlevelButtonPos()
1221 static int getCurrentLevelTextPos()
1223 return (getPrevlevelButtonPos() + 1);
1226 static int getNextLevelButtonPos()
1228 return getPrevlevelButtonPos() + 3 + 1;
1231 static int getLevelRangeTextPos()
1233 return getNextLevelButtonPos() + 1;
1237 int effectiveGameStatus()
1239 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1240 return GAME_MODE_TITLE;
1245 void DrawTitleScreenImage(int nr, boolean initial)
1247 int graphic = getTitleScreenGraphic(nr, initial);
1248 Bitmap *bitmap = graphic_info[graphic].bitmap;
1249 int width = graphic_info[graphic].width;
1250 int height = graphic_info[graphic].height;
1251 int src_x = graphic_info[graphic].src_x;
1252 int src_y = graphic_info[graphic].src_y;
1258 if (width > WIN_XSIZE)
1260 /* image width too large for window => center image horizontally */
1261 src_x = (width - WIN_XSIZE) / 2;
1265 if (height > WIN_YSIZE)
1267 /* image height too large for window => center image vertically */
1268 src_y = (height - WIN_YSIZE) / 2;
1272 /* always display title screens centered */
1273 dst_x = (WIN_XSIZE - width) / 2;
1274 dst_y = (WIN_YSIZE - height) / 2;
1276 SetDrawBackgroundMask(REDRAW_ALL);
1277 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1279 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1281 if (DrawingOnBackground(dst_x, dst_y))
1283 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1284 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1287 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1289 redraw_mask = REDRAW_ALL;
1292 void DrawTitleScreenMessage(int nr, boolean initial)
1294 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1295 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1296 int last_game_status = game_status; /* save current game status */
1298 if (filename == NULL)
1301 /* force TITLE font on title message screen */
1302 game_status = getTitleMessageGameMode(initial);
1304 /* if chars set to "-1", automatically determine by text and font width */
1305 if (tmi->chars == -1)
1306 tmi->chars = tmi->width / getFontWidth(tmi->font);
1308 tmi->width = tmi->chars * getFontWidth(tmi->font);
1310 /* if lines set to "-1", automatically determine by text and font height */
1311 if (tmi->lines == -1)
1312 tmi->lines = tmi->height / getFontHeight(tmi->font);
1314 tmi->height = tmi->lines * getFontHeight(tmi->font);
1316 SetDrawBackgroundMask(REDRAW_ALL);
1317 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1319 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1321 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1322 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1323 tmi->autowrap, tmi->centered, tmi->parse_comments);
1325 game_status = last_game_status; /* restore current game status */
1328 void DrawTitleScreen()
1330 KeyboardAutoRepeatOff();
1333 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1336 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1341 boolean CheckTitleScreen(boolean levelset_has_changed)
1343 static boolean show_title_initial = TRUE;
1344 boolean show_titlescreen = FALSE;
1346 /* needed to be able to skip title screen, if no image or message defined */
1347 InitializeTitleControls(show_title_initial);
1349 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1350 show_titlescreen = TRUE;
1352 /* show initial title images and messages only once at program start */
1353 show_title_initial = FALSE;
1355 return (show_titlescreen && num_title_screens > 0);
1358 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1360 static LevelDirTree *leveldir_last_valid = NULL;
1361 boolean levelset_has_changed = FALSE;
1363 LimitScreenUpdates(FALSE);
1365 FadeSetLeaveScreen();
1367 /* do not fade out here -- function may continue and fade on editor screen */
1370 FadeSoundsAndMusic();
1372 KeyboardAutoRepeatOn();
1375 SetDrawDeactivationMask(REDRAW_NONE);
1376 SetDrawBackgroundMask(REDRAW_FIELD);
1378 audio.sound_deactivated = FALSE;
1382 /* needed if last screen was the playing screen, invoked from level editor */
1383 if (level_editor_test_game)
1385 game_status = GAME_MODE_EDITOR;
1391 /* needed if last screen was the setup screen and fullscreen state changed */
1392 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1393 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1395 /* leveldir_current may be invalid (level group, parent link) */
1396 if (!validLevelSeries(leveldir_current))
1397 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1399 if (leveldir_current != leveldir_last_valid)
1400 levelset_has_changed = TRUE;
1402 /* store valid level series information */
1403 leveldir_last_valid = leveldir_current;
1405 init_last = init; /* switch to new busy animation */
1407 /* needed if last screen (level choice) changed graphics, sounds or music */
1408 ReloadCustomArtwork(0);
1410 if (redraw_mask & REDRAW_ALL)
1411 fade_mask = REDRAW_ALL;
1417 /* needed if last screen was the editor screen */
1418 UndrawSpecialEditorDoor();
1422 if (fade_mask == REDRAW_FIELD)
1428 /* needed if different viewport properties defined for menues */
1429 ChangeViewportPropertiesIfNeeded();
1433 /* needed if last screen was the editor screen */
1434 UndrawSpecialEditorDoor();
1437 #if defined(TARGET_SDL)
1438 SetDrawtoField(DRAW_BACKBUFFER);
1441 if (CheckTitleScreen(levelset_has_changed))
1443 game_status = GAME_MODE_TITLE;
1450 /* level_nr may have been set to value over handicap with level editor */
1451 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1452 level_nr = leveldir_current->handicap_level;
1454 LoadLevel(level_nr);
1455 LoadScore(level_nr);
1457 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1460 if (fade_mask == REDRAW_ALL)
1462 // int door_state = GetDoorState();
1466 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1472 InitializeMainControls();
1474 DrawCursorAndText_Main(-1, FALSE);
1475 DrawPreviewLevelInitial();
1477 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1480 if (TAPE_IS_EMPTY(tape))
1482 DrawCompleteVideoDisplay();
1487 /* create gadgets for main menu screen */
1488 FreeScreenGadgets();
1489 CreateScreenGadgets();
1491 /* map gadgets for main menu screen */
1493 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1496 /* copy actual game door content to door double buffer for OpenDoor() */
1497 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1501 if (fade_mask == REDRAW_ALL)
1503 int door_state = GetDoorState();
1505 // RedrawBackground();
1507 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1511 DrawMaskedBorder(REDRAW_ALL);
1517 /* update screen area with special editor door */
1518 redraw_mask |= REDRAW_ALL;
1522 SetMouseCursor(CURSOR_DEFAULT);
1526 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1529 void DrawAndFadeInMainMenu(int fade_mask)
1531 DrawMainMenuExt(fade_mask, TRUE);
1536 DrawMainMenuExt(REDRAW_ALL, FALSE);
1539 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1540 static void gotoTopLevelDir()
1542 /* move upwards to top level directory */
1543 while (leveldir_current->node_parent)
1545 /* write a "path" into level tree for easy navigation to last level */
1546 if (leveldir_current->node_parent->node_group->cl_first == -1)
1548 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1549 int leveldir_pos = posTreeInfo(leveldir_current);
1550 int num_page_entries;
1551 int cl_first, cl_cursor;
1553 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1554 num_page_entries = num_leveldirs;
1556 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1558 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1559 cl_cursor = leveldir_pos - cl_first;
1561 leveldir_current->node_parent->node_group->cl_first = cl_first;
1562 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1565 leveldir_current = leveldir_current->node_parent;
1570 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1572 static unsigned int title_delay = 0;
1573 static int title_screen_nr = 0;
1574 static int last_sound = -1, last_music = -1;
1575 boolean return_to_main_menu = FALSE;
1576 boolean use_fading_main_menu = TRUE;
1577 struct TitleControlInfo *tci;
1578 struct TitleFadingInfo fading_default;
1579 struct TitleFadingInfo fading_last = fading;
1580 struct TitleFadingInfo fading_next;
1583 if (button == MB_MENU_INITIALIZE)
1586 title_screen_nr = 0;
1587 tci = &title_controls[title_screen_nr];
1589 last_sound = SND_UNDEFINED;
1590 last_music = MUS_UNDEFINED;
1592 if (game_status == GAME_MODE_INFO)
1594 if (num_title_screens == 0)
1596 DrawInfoScreen_NotAvailable("Title screen information:",
1597 "No title screen for this level set.");
1602 FadeSoundsAndMusic();
1605 FadeOut(REDRAW_ALL);
1610 DrawTitleScreenImage(tci->local_nr, tci->initial);
1612 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1614 fading_default = (tci->initial ? title_initial_default : title_default);
1616 fading = fading_next = getTitleFading(tci);
1620 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1621 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1623 fading.fade_mode = FADE_MODE_FADE;
1624 fading.fade_delay = fading_default.fade_delay;
1627 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1628 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1629 fading.fade_mode = FADE_MODE_FADE;
1634 sound = getTitleSound(tci);
1635 music = getTitleMusic(tci);
1637 if (sound != last_sound)
1638 PlayMenuSoundExt(sound);
1639 if (music != last_music)
1640 PlayMenuMusicExt(music);
1646 SetMouseCursor(CURSOR_NONE);
1652 fading = fading_next;
1654 DelayReached(&title_delay, 0); /* reset delay counter */
1660 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1661 button = MB_MENU_CHOICE;
1663 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1664 button = MB_MENU_CHOICE;
1667 if (button == MB_MENU_LEAVE)
1669 return_to_main_menu = TRUE;
1670 use_fading_main_menu = FALSE;
1672 else if (button == MB_MENU_CHOICE)
1674 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1677 FadeOut(REDRAW_FIELD);
1680 FadeSetEnterScreen();
1682 info_mode = INFO_MODE_MAIN;
1683 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1689 tci = &title_controls[title_screen_nr];
1691 if (title_screen_nr < num_title_screens)
1693 sound = getTitleSound(tci);
1694 music = getTitleMusic(tci);
1696 if (sound == SND_UNDEFINED || sound != last_sound)
1698 if (music == MUS_UNDEFINED || music != last_music)
1702 FadeOut(REDRAW_ALL);
1706 DrawTitleScreenImage(tci->local_nr, tci->initial);
1708 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1710 fading_next = getTitleFading(tci);
1713 sound = getTitleSound(tci);
1714 music = getTitleMusic(tci);
1716 if (sound != last_sound)
1717 PlayMenuSoundExt(sound);
1718 if (music != last_music)
1719 PlayMenuMusicExt(music);
1726 /* last screen already faded out, next screen has no animation */
1727 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1728 fading_next.fade_mode == FADE_MODE_NONE)
1729 fading = fading_next;
1731 /* last screen already faded out, next screen has no animation */
1732 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1733 fading_next.fade_mode == FADE_MODE_NONE)
1734 fading = fading_next;
1741 fading = fading_next;
1743 DelayReached(&title_delay, 0); /* reset delay counter */
1747 FadeSoundsAndMusic();
1749 return_to_main_menu = TRUE;
1753 if (return_to_main_menu)
1759 SetMouseCursor(CURSOR_DEFAULT);
1761 if (game_status == GAME_MODE_INFO)
1764 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1767 info_mode = INFO_MODE_MAIN;
1768 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1770 else /* default: return to main menu */
1773 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1776 game_status = GAME_MODE_MAIN;
1777 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1782 void HandleMainMenu_SelectLevel(int step, int direction)
1784 int old_level_nr = level_nr;
1787 new_level_nr = old_level_nr + step * direction;
1788 if (new_level_nr < leveldir_current->first_level)
1789 new_level_nr = leveldir_current->first_level;
1790 if (new_level_nr > leveldir_current->last_level)
1791 new_level_nr = leveldir_current->last_level;
1793 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1795 /* skipping levels is only allowed when trying to skip single level */
1796 if (setup.skip_levels && step == 1 &&
1797 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1799 leveldir_current->handicap_level++;
1800 SaveLevelSetup_SeriesInfo();
1803 new_level_nr = leveldir_current->handicap_level;
1806 if (new_level_nr != old_level_nr)
1808 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1810 PlaySound(SND_MENU_ITEM_SELECTING);
1812 level_nr = new_level_nr;
1814 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1815 int2str(level_nr, menu.main.text.level_number.size),
1816 mci->pos_text->font);
1818 LoadLevel(level_nr);
1819 DrawPreviewLevelInitial();
1823 DrawCompleteVideoDisplay();
1825 /* needed because DrawPreviewLevelInitial() takes some time */
1831 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1833 static int choice = MAIN_CONTROL_GAME;
1837 if (button == MB_MENU_INITIALIZE)
1839 DrawCursorAndText_Main(choice, TRUE);
1844 if (mx || my) /* mouse input */
1848 for (i = 0; main_controls[i].nr != -1; i++)
1851 printf("::: check click (%d, %d) for %d [%d] ...\n",
1852 mx - mSX, my - mSY, i, main_controls[i].nr);
1855 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1856 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1857 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1860 printf("::: inside %d\n", i);
1863 pos = main_controls[i].nr;
1869 else if (dx || dy) /* keyboard input */
1871 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1872 choice == MAIN_CONTROL_SETUP))
1873 button = MB_MENU_CHOICE;
1878 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1880 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1882 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1884 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1886 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1888 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1890 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1892 game_status = GAME_MODE_LEVELNR;
1895 ChangeViewportPropertiesIfNeeded();
1898 DrawChooseLevelNr();
1900 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1906 PlaySound(SND_MENU_ITEM_ACTIVATING);
1908 DrawCursorAndText_Main(choice, FALSE);
1909 DrawCursorAndText_Main(pos, TRUE);
1916 PlaySound(SND_MENU_ITEM_SELECTING);
1918 if (pos == MAIN_CONTROL_NAME)
1920 game_status = GAME_MODE_PSEUDO_TYPENAME;
1922 HandleTypeName(strlen(setup.player_name), 0);
1924 else if (pos == MAIN_CONTROL_LEVELS)
1928 game_status = GAME_MODE_LEVELS;
1930 SaveLevelSetup_LastSeries();
1931 SaveLevelSetup_SeriesInfo();
1933 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1938 ChangeViewportPropertiesIfNeeded();
1941 DrawChooseLevelSet();
1944 else if (pos == MAIN_CONTROL_SCORES)
1946 game_status = GAME_MODE_SCORES;
1949 ChangeViewportPropertiesIfNeeded();
1954 else if (pos == MAIN_CONTROL_EDITOR)
1956 if (leveldir_current->readonly &&
1957 !strEqual(setup.player_name, "Artsoft"))
1958 Request("This level is read only!", REQ_CONFIRM);
1960 CloseDoor(DOOR_CLOSE_2);
1962 game_status = GAME_MODE_EDITOR;
1964 FadeSetEnterScreen();
1967 /* needed if different viewport properties defined for editor */
1968 ChangeViewportPropertiesIfNeeded();
1973 else if (pos == MAIN_CONTROL_INFO)
1975 game_status = GAME_MODE_INFO;
1976 info_mode = INFO_MODE_MAIN;
1979 ChangeViewportPropertiesIfNeeded();
1984 else if (pos == MAIN_CONTROL_GAME)
1986 StartGameActions(options.network, setup.autorecord, level.random_seed);
1988 else if (pos == MAIN_CONTROL_SETUP)
1990 game_status = GAME_MODE_SETUP;
1991 setup_mode = SETUP_MODE_MAIN;
1994 ChangeViewportPropertiesIfNeeded();
1999 else if (pos == MAIN_CONTROL_QUIT)
2001 SaveLevelSetup_LastSeries();
2002 SaveLevelSetup_SeriesInfo();
2004 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2005 game_status = GAME_MODE_QUIT;
2011 if (game_status == GAME_MODE_MAIN)
2013 DrawPreviewLevelAnimation();
2020 /* ========================================================================= */
2021 /* info screen functions */
2022 /* ========================================================================= */
2024 static struct TokenInfo *info_info;
2025 static int num_info_info;
2027 static void execInfoTitleScreen()
2029 info_mode = INFO_MODE_TITLE;
2034 static void execInfoElements()
2036 info_mode = INFO_MODE_ELEMENTS;
2041 static void execInfoMusic()
2043 info_mode = INFO_MODE_MUSIC;
2048 static void execInfoCredits()
2050 info_mode = INFO_MODE_CREDITS;
2055 static void execInfoProgram()
2057 info_mode = INFO_MODE_PROGRAM;
2062 static void execInfoVersion()
2064 info_mode = INFO_MODE_VERSION;
2069 static void execInfoLevelSet()
2071 info_mode = INFO_MODE_LEVELSET;
2076 static void execExitInfo()
2078 game_status = GAME_MODE_MAIN;
2080 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2083 static struct TokenInfo info_info_main[] =
2085 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2086 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2087 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2088 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2089 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2090 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2091 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2092 { TYPE_EMPTY, NULL, "" },
2093 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2098 static void DrawCursorAndText_Info(int pos, boolean active)
2100 int xpos = MENU_SCREEN_START_XPOS;
2101 int ypos = MENU_SCREEN_START_YPOS + pos;
2102 int font_nr = FONT_MENU_1;
2105 font_nr = FONT_ACTIVE(font_nr);
2107 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2109 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2110 drawCursor(pos, active);
2113 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2118 CloseDoor(DOOR_CLOSE_2);
2120 /* (needed after displaying title screens which disable auto repeat) */
2121 KeyboardAutoRepeatOn();
2123 FadeSetLeaveScreen();
2130 if (fade_mask == REDRAW_ALL)
2134 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2140 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2142 info_info = info_info_main;
2146 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2148 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2151 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2152 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2153 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2154 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2155 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2156 initCursor(i, IMG_MENU_BUTTON);
2158 DrawCursorAndText_Info(i, FALSE);
2163 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2168 DrawMaskedBorder(fade_mask);
2175 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2177 static int choice_store[MAX_INFO_MODES];
2178 int choice = choice_store[info_mode]; /* always starts with 0 */
2182 if (button == MB_MENU_INITIALIZE)
2184 /* advance to first valid menu entry */
2185 while (choice < num_info_info &&
2186 info_info[choice].type & TYPE_SKIP_ENTRY)
2188 choice_store[info_mode] = choice;
2190 DrawCursorAndText_Info(choice, TRUE);
2194 else if (button == MB_MENU_LEAVE)
2196 for (y = 0; y < num_info_info; y++)
2198 if (info_info[y].type & TYPE_LEAVE_MENU)
2200 void (*menu_callback_function)(void) = info_info[y].value;
2204 menu_callback_function();
2206 break; /* absolutely needed because function changes 'info_info'! */
2213 if (mx || my) /* mouse input */
2215 x = (mx - mSX) / 32;
2216 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2218 else if (dx || dy) /* keyboard input */
2222 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2224 if (info_info[choice].type & menu_navigation_type ||
2225 info_info[choice].type & TYPE_ENTER_SCREEN ||
2226 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2227 info_info[choice].type & TYPE_YES_NO_AUTO)
2228 button = MB_MENU_CHOICE;
2233 /* jump to next non-empty menu entry (up or down) */
2234 while (y > 0 && y < num_info_info - 1 &&
2235 info_info[y].type & TYPE_SKIP_ENTRY)
2239 if (IN_VIS_FIELD(x, y) &&
2240 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2246 PlaySound(SND_MENU_ITEM_ACTIVATING);
2248 DrawCursorAndText_Info(choice, FALSE);
2249 DrawCursorAndText_Info(y, TRUE);
2251 choice = choice_store[info_mode] = y;
2254 else if (!(info_info[y].type & TYPE_GHOSTED))
2256 PlaySound(SND_MENU_ITEM_SELECTING);
2258 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2260 void (*menu_callback_function)(void) = info_info[choice].value;
2262 FadeSetFromType(info_info[y].type);
2264 menu_callback_function();
2270 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2272 int ystart1 = mSY - SY + 100;
2273 int ystart2 = mSY - SY + 150;
2274 int ybottom = mSY - SY + SYSIZE - 20;
2276 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2278 FadeOut(REDRAW_FIELD);
2283 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2284 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2286 DrawTextSCentered(ybottom, FONT_TEXT_4,
2287 "Press any key or button for info menu");
2289 FadeIn(REDRAW_FIELD);
2292 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2294 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2295 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2296 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2297 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2298 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2299 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2300 int ystep = MENU_SCREEN_INFO_YSTEP;
2301 int element, action, direction;
2309 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2310 infoscreen_step[i] = infoscreen_frame[i] = 0;
2315 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2317 DrawTextSCentered(ybottom, FONT_TEXT_4,
2318 "Press any key or button for next page");
2324 while (helpanim_info[j].element != HELPANIM_LIST_END)
2326 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2331 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2340 j += infoscreen_step[i - start];
2342 element = helpanim_info[j].element;
2343 action = helpanim_info[j].action;
2344 direction = helpanim_info[j].direction;
2347 element = EL_UNKNOWN;
2349 if (action != -1 && direction != -1)
2350 graphic = el_act_dir2img(element, action, direction);
2351 else if (action != -1)
2352 graphic = el_act2img(element, action);
2353 else if (direction != -1)
2354 graphic = el_dir2img(element, direction);
2356 graphic = el2img(element);
2358 delay = helpanim_info[j++].delay;
2363 if (infoscreen_frame[i - start] == 0)
2366 infoscreen_frame[i - start] = delay - 1;
2370 sync_frame = delay - infoscreen_frame[i - start];
2371 infoscreen_frame[i - start]--;
2374 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2376 if (!infoscreen_frame[i - start])
2377 infoscreen_step[i - start] = 0;
2381 if (!infoscreen_frame[i - start])
2382 infoscreen_step[i - start]++;
2383 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2389 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2391 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2392 graphic, sync_frame, USE_MASKING);
2395 DrawInfoScreen_HelpText(element, action, direction, i - start);
2400 redraw_mask |= REDRAW_FIELD;
2405 static char *getHelpText(int element, int action, int direction)
2407 char token[MAX_LINE_LEN];
2409 strcpy(token, element_info[element].token_name);
2412 strcat(token, element_action_info[action].suffix);
2414 if (direction != -1)
2415 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2417 return getHashEntry(helptext_info, token);
2420 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2422 int font_nr = FONT_INFO_ELEMENTS;
2423 int font_width = getFontWidth(font_nr);
2424 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2425 int sy = mSY + 65 + 2 * 32 + 1;
2426 int ystep = TILEY + 4;
2427 int pad_x = sx - SX;
2428 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2429 int max_lines_per_text = 2;
2432 if (action != -1 && direction != -1) /* element.action.direction */
2433 text = getHelpText(element, action, direction);
2435 if (text == NULL && action != -1) /* element.action */
2436 text = getHelpText(element, action, -1);
2438 if (text == NULL && direction != -1) /* element.direction */
2439 text = getHelpText(element, -1, direction);
2441 if (text == NULL) /* base element */
2442 text = getHelpText(element, -1, -1);
2444 if (text == NULL) /* not found */
2445 text = "No description available";
2447 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2448 sy += getFontHeight(font_nr) / 2;
2450 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2451 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2452 TRUE, FALSE, FALSE);
2455 void DrawInfoScreen_TitleScreen()
2460 void HandleInfoScreen_TitleScreen(int button)
2462 HandleTitleScreen(0, 0, 0, 0, button);
2465 void DrawInfoScreen_Elements()
2467 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2469 FadeOut(REDRAW_FIELD);
2474 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2476 FadeIn(REDRAW_FIELD);
2481 void HandleInfoScreen_Elements(int button)
2483 static unsigned int info_delay = 0;
2484 static int num_anims;
2485 static int num_pages;
2487 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2490 if (button == MB_MENU_INITIALIZE)
2492 boolean new_element = TRUE;
2496 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2498 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2500 else if (new_element)
2503 new_element = FALSE;
2507 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2511 if (button == MB_MENU_LEAVE)
2513 PlaySound(SND_MENU_ITEM_SELECTING);
2515 info_mode = INFO_MODE_MAIN;
2520 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2522 if (button != MB_MENU_INITIALIZE)
2524 PlaySound(SND_MENU_ITEM_SELECTING);
2529 if (page >= num_pages)
2531 FadeSoundsAndMusic();
2533 info_mode = INFO_MODE_MAIN;
2534 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2541 FadeSetNextScreen();
2544 if (button != MB_MENU_INITIALIZE)
2545 FadeOut(REDRAW_FIELD);
2547 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2549 if (button != MB_MENU_INITIALIZE)
2550 FadeIn(REDRAW_FIELD);
2554 if (DelayReached(&info_delay, GameFrameDelay))
2555 if (page < num_pages)
2556 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2558 PlayMenuSoundIfLoop();
2562 void DrawInfoScreen_Music()
2564 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2567 FadeOut(REDRAW_FIELD);
2575 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2578 FadeIn(REDRAW_FIELD);
2582 void HandleInfoScreen_Music(int button)
2584 static struct MusicFileInfo *list = NULL;
2585 int ystart1 = mSY - SY + 100;
2586 int ystart2 = mSY - SY + 150;
2587 int ybottom = mSY - SY + SYSIZE - 20;
2590 if (button == MB_MENU_INITIALIZE)
2592 list = music_file_info;
2596 FadeSoundsAndMusic();
2601 DrawTextSCentered(ystart1, FONT_TEXT_1,
2602 "No music info for this level set.");
2604 DrawTextSCentered(ybottom, FONT_TEXT_4,
2605 "Press any key or button for info menu");
2611 if (button == MB_MENU_LEAVE)
2613 PlaySound(SND_MENU_ITEM_SELECTING);
2615 FadeSoundsAndMusic();
2617 info_mode = INFO_MODE_MAIN;
2622 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2626 if (button != MB_MENU_INITIALIZE)
2628 PlaySound(SND_MENU_ITEM_SELECTING);
2636 FadeSoundsAndMusic();
2638 info_mode = INFO_MODE_MAIN;
2639 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2644 FadeSoundsAndMusic();
2647 if (list != music_file_info)
2648 FadeSetNextScreen();
2651 if (button != MB_MENU_INITIALIZE)
2652 FadeOut(REDRAW_FIELD);
2659 int sound = list->music;
2661 if (sound_info[sound].loop)
2662 PlaySoundLoop(sound);
2666 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2670 PlayMusic(list->music);
2672 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2675 if (!strEqual(list->title, UNKNOWN_NAME))
2677 if (!strEqual(list->title_header, UNKNOWN_NAME))
2678 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2680 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2683 if (!strEqual(list->artist, UNKNOWN_NAME))
2685 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2686 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2688 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2690 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2693 if (!strEqual(list->album, UNKNOWN_NAME))
2695 if (!strEqual(list->album_header, UNKNOWN_NAME))
2696 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2698 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2700 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2703 if (!strEqual(list->year, UNKNOWN_NAME))
2705 if (!strEqual(list->year_header, UNKNOWN_NAME))
2706 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2708 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2710 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2713 DrawTextSCentered(ybottom, FONT_TEXT_4,
2714 "Press any key or button for next page");
2716 if (button != MB_MENU_INITIALIZE)
2717 FadeIn(REDRAW_FIELD);
2720 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2721 PlaySoundLoop(list->music);
2724 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2726 int ystart1 = mSY - SY + 100;
2727 int ystart2 = mSY - SY + 150;
2728 int ybottom = mSY - SY + SYSIZE - 20;
2734 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2738 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2739 "Special thanks to");
2740 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2742 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2744 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2745 "\"Boulder Dash\"");
2746 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2748 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2750 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2752 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2753 "First Star Software");
2755 else if (screen_nr == 1)
2757 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2758 "Special thanks to");
2759 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2760 "Klaus Heinz & Volker Wertich");
2761 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2763 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2764 "\"Emerald Mine\"");
2765 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2767 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2769 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2771 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2774 else if (screen_nr == 2)
2776 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2777 "Special thanks to");
2778 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2779 "Michael Stopp & Philip Jespersen");
2780 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2782 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2784 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2786 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2788 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2790 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2791 "Digital Integration");
2793 else if (screen_nr == 3)
2795 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2796 "Special thanks to");
2797 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2798 "Hiroyuki Imabayashi");
2799 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2801 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2803 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2805 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2807 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2809 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2812 else if (screen_nr == 4)
2814 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2815 "Special thanks to");
2816 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2818 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2820 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2821 "Jürgen Bonhagen");
2822 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2823 "for the continuous creation");
2824 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2825 "of outstanding level sets");
2827 else if (screen_nr == 5)
2829 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2831 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2833 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2834 "for ideas and inspiration by");
2835 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2838 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2840 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2842 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2843 "for ideas and inspiration by");
2844 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2847 else if (screen_nr == 6)
2849 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2851 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2854 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2855 "for the code base used for the");
2856 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2857 "native Emerald Mine engine");
2859 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2860 "for the new Emerald Mine engine");
2863 else if (screen_nr == 7)
2865 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2867 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2869 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2870 "for the initial DOS port");
2872 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2874 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2876 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2877 "for some additional toons");
2879 else if (screen_nr == 8)
2881 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2882 "And not to forget:");
2883 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2885 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2886 "All those who contributed");
2887 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2888 "levels to this game");
2889 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2893 DrawTextSCentered(ybottom, FONT_TEXT_4,
2894 "Press any key or button for next page");
2897 void DrawInfoScreen_Credits()
2899 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2901 FadeSoundsAndMusic();
2904 FadeOut(REDRAW_FIELD);
2907 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2910 FadeIn(REDRAW_FIELD);
2914 void HandleInfoScreen_Credits(int button)
2916 static int screen_nr = 0;
2917 int num_screens = 9;
2919 if (button == MB_MENU_INITIALIZE)
2923 // DrawInfoScreen_CreditsScreen(screen_nr);
2926 if (button == MB_MENU_LEAVE)
2928 PlaySound(SND_MENU_ITEM_SELECTING);
2930 info_mode = INFO_MODE_MAIN;
2935 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2937 if (button != MB_MENU_INITIALIZE)
2939 PlaySound(SND_MENU_ITEM_SELECTING);
2944 if (screen_nr >= num_screens)
2946 FadeSoundsAndMusic();
2948 info_mode = INFO_MODE_MAIN;
2949 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2956 FadeSetNextScreen();
2959 if (button != MB_MENU_INITIALIZE)
2960 FadeOut(REDRAW_FIELD);
2962 DrawInfoScreen_CreditsScreen(screen_nr);
2964 if (button != MB_MENU_INITIALIZE)
2965 FadeIn(REDRAW_FIELD);
2969 PlayMenuSoundIfLoop();
2973 void DrawInfoScreen_Program()
2975 int ystart1 = mSY - SY + 100;
2976 int ystart2 = mSY - SY + 150;
2977 int ybottom = mSY - SY + SYSIZE - 20;
2980 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2983 FadeOut(REDRAW_FIELD);
2989 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2991 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2992 "This game is Freeware!");
2993 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2994 "If you like it, send e-mail to:");
2995 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2996 PROGRAM_EMAIL_STRING);
2998 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2999 "More information and levels:");
3000 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3001 PROGRAM_WEBSITE_STRING);
3002 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3003 "If you have created new levels,");
3004 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3005 "send them to me to include them!");
3006 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3009 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3010 "or SnailMail to:");
3011 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3013 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3014 "Detmolder Strasse 189");
3015 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3017 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3019 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3020 "More information and levels:");
3021 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3022 PROGRAM_WEBSITE_STRING);
3023 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3024 "If you have created new levels,");
3025 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3026 "send them to me to include them!");
3027 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3031 DrawTextSCentered(ybottom, FONT_TEXT_4,
3032 "Press any key or button for info menu");
3035 FadeIn(REDRAW_FIELD);
3039 void HandleInfoScreen_Program(int button)
3041 if (button == MB_MENU_LEAVE)
3043 PlaySound(SND_MENU_ITEM_SELECTING);
3045 info_mode = INFO_MODE_MAIN;
3050 else if (button == MB_MENU_CHOICE)
3052 PlaySound(SND_MENU_ITEM_SELECTING);
3054 FadeSoundsAndMusic();
3057 FadeOut(REDRAW_FIELD);
3060 info_mode = INFO_MODE_MAIN;
3061 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3065 PlayMenuSoundIfLoop();
3069 void DrawInfoScreen_Version()
3071 int font_header = FONT_TEXT_3;
3072 int font_text = FONT_TEXT_2;
3073 int xstep = getFontWidth(font_text);
3074 int ystep = getFontHeight(font_text);
3075 int ystart1 = mSY - SY + 100;
3076 int ystart2 = mSY - SY + 150;
3077 int ybottom = mSY - SY + SYSIZE - 20;
3078 int xstart1 = mSX - SX + 2 * xstep;
3079 int xstart2 = mSX - SX + 18 * xstep;
3080 #if defined(TARGET_SDL)
3081 int xstart3 = mSX - SX + 28 * xstep;
3082 SDL_version sdl_version_compiled;
3083 const SDL_version *sdl_version_linked;
3084 int driver_name_len = 10;
3085 #if defined(TARGET_SDL2)
3086 SDL_version sdl_version_linked_ext;
3087 const char *driver_name = NULL;
3089 char driver_name[driver_name_len];
3093 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3096 FadeOut(REDRAW_FIELD);
3102 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3104 DrawTextF(xstart1, ystart2, font_header, "Name");
3105 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3108 DrawTextF(xstart1, ystart2, font_header, "Version");
3109 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3112 DrawTextF(xstart1, ystart2, font_header, "Platform");
3113 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3116 DrawTextF(xstart1, ystart2, font_header, "Target");
3117 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3120 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3121 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3123 #if defined(TARGET_SDL)
3124 ystart2 += 3 * ystep;
3125 DrawTextF(xstart1, ystart2, font_header, "Library");
3126 DrawTextF(xstart2, ystart2, font_header, "compiled");
3127 DrawTextF(xstart3, ystart2, font_header, "linked");
3129 SDL_VERSION(&sdl_version_compiled);
3130 #if defined(TARGET_SDL2)
3131 SDL_GetVersion(&sdl_version_linked_ext);
3132 sdl_version_linked = &sdl_version_linked_ext;
3134 sdl_version_linked = SDL_Linked_Version();
3137 ystart2 += 2 * ystep;
3138 DrawTextF(xstart1, ystart2, font_text, "SDL");
3139 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3140 sdl_version_compiled.major,
3141 sdl_version_compiled.minor,
3142 sdl_version_compiled.patch);
3143 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3144 sdl_version_linked->major,
3145 sdl_version_linked->minor,
3146 sdl_version_linked->patch);
3148 SDL_IMAGE_VERSION(&sdl_version_compiled);
3149 sdl_version_linked = IMG_Linked_Version();
3152 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3153 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3154 sdl_version_compiled.major,
3155 sdl_version_compiled.minor,
3156 sdl_version_compiled.patch);
3157 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3158 sdl_version_linked->major,
3159 sdl_version_linked->minor,
3160 sdl_version_linked->patch);
3162 SDL_MIXER_VERSION(&sdl_version_compiled);
3163 sdl_version_linked = Mix_Linked_Version();
3166 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3167 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3168 sdl_version_compiled.major,
3169 sdl_version_compiled.minor,
3170 sdl_version_compiled.patch);
3171 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3172 sdl_version_linked->major,
3173 sdl_version_linked->minor,
3174 sdl_version_linked->patch);
3176 SDL_NET_VERSION(&sdl_version_compiled);
3177 sdl_version_linked = SDLNet_Linked_Version();
3180 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3181 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3182 sdl_version_compiled.major,
3183 sdl_version_compiled.minor,
3184 sdl_version_compiled.patch);
3185 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3186 sdl_version_linked->major,
3187 sdl_version_linked->minor,
3188 sdl_version_linked->patch);
3190 ystart2 += 3 * ystep;
3191 DrawTextF(xstart1, ystart2, font_header, "Driver");
3192 DrawTextF(xstart2, ystart2, font_header, "Requested");
3193 DrawTextF(xstart3, ystart2, font_header, "Used");
3195 #if defined(TARGET_SDL2)
3196 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3198 SDL_VideoDriverName(driver_name, driver_name_len);
3201 ystart2 += 2 * ystep;
3202 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3203 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3204 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3206 #if defined(TARGET_SDL2)
3207 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3209 SDL_AudioDriverName(driver_name, driver_name_len);
3213 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3214 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3215 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3218 DrawTextSCentered(ybottom, FONT_TEXT_4,
3219 "Press any key or button for info menu");
3222 FadeIn(REDRAW_FIELD);
3226 void HandleInfoScreen_Version(int button)
3228 if (button == MB_MENU_LEAVE)
3230 PlaySound(SND_MENU_ITEM_SELECTING);
3232 info_mode = INFO_MODE_MAIN;
3237 else if (button == MB_MENU_CHOICE)
3239 PlaySound(SND_MENU_ITEM_SELECTING);
3241 FadeSoundsAndMusic();
3244 FadeOut(REDRAW_FIELD);
3247 info_mode = INFO_MODE_MAIN;
3248 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3252 PlayMenuSoundIfLoop();
3256 void DrawInfoScreen_LevelSet()
3258 struct TitleMessageInfo *tmi = &readme;
3259 char *filename = getLevelSetInfoFilename();
3261 /* if chars set to "-1", automatically determine by text and font width */
3262 if (tmi->chars == -1)
3263 tmi->chars = tmi->width / getFontWidth(tmi->font);
3265 tmi->width = tmi->chars * getFontWidth(tmi->font);
3267 /* if lines set to "-1", automatically determine by text and font height */
3268 if (tmi->lines == -1)
3269 tmi->lines = tmi->height / getFontHeight(tmi->font);
3271 tmi->height = tmi->lines * getFontHeight(tmi->font);
3273 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3276 FadeOut(REDRAW_FIELD);
3282 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3284 if (filename != NULL)
3285 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3286 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3287 tmi->autowrap, tmi->centered, tmi->parse_comments);
3289 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3290 "No information for this level set.");
3292 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3293 "Press any key or button for info menu");
3296 FadeIn(REDRAW_FIELD);
3300 void HandleInfoScreen_LevelSet(int button)
3302 if (button == MB_MENU_LEAVE)
3304 PlaySound(SND_MENU_ITEM_SELECTING);
3306 info_mode = INFO_MODE_MAIN;
3311 else if (button == MB_MENU_CHOICE)
3313 PlaySound(SND_MENU_ITEM_SELECTING);
3315 FadeSoundsAndMusic();
3318 FadeOut(REDRAW_FIELD);
3321 info_mode = INFO_MODE_MAIN;
3322 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3326 PlayMenuSoundIfLoop();
3330 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3332 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3334 if (info_mode == INFO_MODE_TITLE)
3335 DrawInfoScreen_TitleScreen();
3336 else if (info_mode == INFO_MODE_ELEMENTS)
3337 DrawInfoScreen_Elements();
3338 else if (info_mode == INFO_MODE_MUSIC)
3339 DrawInfoScreen_Music();
3340 else if (info_mode == INFO_MODE_CREDITS)
3341 DrawInfoScreen_Credits();
3342 else if (info_mode == INFO_MODE_PROGRAM)
3343 DrawInfoScreen_Program();
3344 else if (info_mode == INFO_MODE_VERSION)
3345 DrawInfoScreen_Version();
3346 else if (info_mode == INFO_MODE_LEVELSET)
3347 DrawInfoScreen_LevelSet();
3349 DrawInfoScreen_Main(fade_mask, do_fading);
3351 if (info_mode != INFO_MODE_MAIN &&
3352 info_mode != INFO_MODE_TITLE &&
3353 info_mode != INFO_MODE_MUSIC)
3360 void DrawAndFadeInInfoScreen(int fade_mask)
3362 DrawInfoScreenExt(fade_mask, TRUE);
3365 void DrawInfoScreen()
3367 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3370 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3372 if (info_mode == INFO_MODE_TITLE)
3373 HandleInfoScreen_TitleScreen(button);
3374 else if (info_mode == INFO_MODE_ELEMENTS)
3375 HandleInfoScreen_Elements(button);
3376 else if (info_mode == INFO_MODE_MUSIC)
3377 HandleInfoScreen_Music(button);
3378 else if (info_mode == INFO_MODE_CREDITS)
3379 HandleInfoScreen_Credits(button);
3380 else if (info_mode == INFO_MODE_PROGRAM)
3381 HandleInfoScreen_Program(button);
3382 else if (info_mode == INFO_MODE_VERSION)
3383 HandleInfoScreen_Version(button);
3384 else if (info_mode == INFO_MODE_LEVELSET)
3385 HandleInfoScreen_LevelSet(button);
3387 HandleInfoScreen_Main(mx, my, dx, dy, button);
3395 /* ========================================================================= */
3396 /* type name functions */
3397 /* ========================================================================= */
3399 void HandleTypeName(int newxpos, Key key)
3401 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3402 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3403 struct TextPosInfo *pos = mci->pos_input;
3404 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3405 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3406 static int xpos = 0;
3407 int font_nr = pos->font;
3408 int font_active_nr = FONT_ACTIVE(font_nr);
3409 int font_width = getFontWidth(font_active_nr);
3410 char key_char = getValidConfigValueChar(getCharFromKey(key));
3411 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3412 boolean is_active = TRUE;
3414 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3418 strcpy(last_player_name, setup.player_name);
3422 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3424 setup.player_name[xpos] = key_char;
3425 setup.player_name[xpos + 1] = 0;
3429 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3433 setup.player_name[xpos] = 0;
3435 else if (key == KSYM_Return && xpos > 0)
3441 game_status = GAME_MODE_MAIN;
3443 else if (key == KSYM_Escape)
3445 strcpy(setup.player_name, last_player_name);
3449 game_status = GAME_MODE_MAIN;
3454 pos->width = (strlen(setup.player_name) + 1) * font_width;
3455 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3457 DrawText(startx, starty, setup.player_name, font_active_nr);
3458 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3462 pos->width = strlen(setup.player_name) * font_width;
3463 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3465 DrawText(startx, starty, setup.player_name, font_nr);
3470 /* ========================================================================= */
3471 /* tree menu functions */
3472 /* ========================================================================= */
3474 static void DrawChooseTree(TreeInfo **ti_ptr)
3478 FreeScreenGadgets();
3479 CreateScreenGadgets();
3481 CloseDoor(DOOR_CLOSE_2);
3484 FadeOut(REDRAW_FIELD);
3489 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3490 MapScreenTreeGadgets(*ti_ptr);
3493 FadeIn(REDRAW_FIELD);
3499 static void AdjustScrollbar(int id, int items_max, int items_visible,
3502 struct GadgetInfo *gi = screen_gadget[id];
3504 if (item_position > items_max - items_visible)
3505 item_position = items_max - items_visible;
3507 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3508 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3509 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3512 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3515 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3518 struct GadgetInfo *gi = screen_gadget[id];
3519 int items_max, items_visible, item_position;
3521 items_max = numTreeInfoInGroup(ti);
3522 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3523 item_position = first_entry;
3525 if (item_position > items_max - items_visible)
3526 item_position = items_max - items_visible;
3528 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3529 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3530 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3534 static void drawChooseTreeList(int first_entry, int num_page_entries,
3538 char *title_string = NULL;
3539 int yoffset_sets = MENU_TITLE1_YPOS;
3540 int yoffset_setup = 16;
3541 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3542 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3543 int last_game_status = game_status; /* save current game status */
3545 title_string = ti->infotext;
3547 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3550 /* force LEVELS font on artwork setup screen */
3551 game_status = GAME_MODE_LEVELS;
3555 /* clear tree list area, but not title or scrollbar */
3556 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3557 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3558 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3560 /* clear tree list area, but not title or scrollbar */
3561 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3562 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3563 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3566 for (i = 0; i < num_page_entries; i++)
3568 TreeInfo *node, *node_first;
3569 int entry_pos = first_entry + i;
3570 int xpos = MENU_SCREEN_START_XPOS;
3571 int ypos = MENU_SCREEN_START_YPOS + i;
3572 int startx = mSX + xpos * 32;
3573 int starty = mSY + ypos * 32;
3574 int font_nr = FONT_TEXT_1;
3575 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3576 int startx_text = startx + font_xoffset;
3577 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3578 int text_size = startx_scrollbar - startx_text;
3579 int max_buffer_len = text_size / getFontWidth(font_nr);
3580 char buffer[max_buffer_len + 1];
3582 node_first = getTreeInfoFirstGroupEntry(ti);
3583 node = getTreeInfoFromPos(node_first, entry_pos);
3585 strncpy(buffer, node->name, max_buffer_len);
3586 buffer[max_buffer_len] = '\0';
3588 DrawText(startx, starty, buffer, font_nr + node->color);
3590 if (node->parent_link)
3591 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3592 else if (node->level_group)
3593 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3595 initCursor(i, IMG_MENU_BUTTON);
3598 game_status = last_game_status; /* restore current game status */
3600 redraw_mask |= REDRAW_FIELD;
3603 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3605 TreeInfo *node, *node_first;
3606 int x, last_redraw_mask = redraw_mask;
3607 int ypos = MENU_TITLE2_YPOS;
3608 int font_nr = FONT_TITLE_2;
3610 if (ti->type == TREE_TYPE_LEVEL_NR)
3611 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3613 if (ti->type != TREE_TYPE_LEVEL_DIR)
3616 node_first = getTreeInfoFirstGroupEntry(ti);
3617 node = getTreeInfoFromPos(node_first, entry_pos);
3619 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3622 if (node->parent_link)
3623 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3624 node->node_parent->name);
3625 else if (node->level_group)
3626 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3628 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3629 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3630 node->levels, (node->levels > 1 ? "levels" : "level"),
3633 if (node->parent_link)
3634 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3636 else if (node->level_group)
3637 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3639 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3640 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3641 node->levels, node->class_desc);
3644 /* let BackToFront() redraw only what is needed */
3645 redraw_mask = last_redraw_mask | REDRAW_TILES;
3646 for (x = 0; x < SCR_FIELDX; x++)
3647 MarkTileDirty(x, 1);
3650 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3653 TreeInfo *ti = *ti_ptr;
3655 int y = ti->cl_cursor;
3656 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3657 int num_entries = numTreeInfoInGroup(ti);
3658 int num_page_entries;
3659 int last_game_status = game_status; /* save current game status */
3660 boolean position_set_by_scrollbar = (dx == 999);
3663 /* force LEVELS draw offset on choose level and artwork setup screen */
3664 game_status = GAME_MODE_LEVELS;
3667 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3668 num_page_entries = num_entries;
3670 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3672 game_status = last_game_status; /* restore current game status */
3674 if (button == MB_MENU_INITIALIZE)
3676 int num_entries = numTreeInfoInGroup(ti);
3677 int entry_pos = posTreeInfo(ti);
3679 if (ti->cl_first == -1)
3681 /* only on initialization */
3682 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3683 ti->cl_cursor = entry_pos - ti->cl_first;
3685 else if (ti->cl_cursor >= num_page_entries ||
3686 (num_entries > num_page_entries &&
3687 num_entries - ti->cl_first < num_page_entries))
3689 /* only after change of list size (by custom graphic configuration) */
3690 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3691 ti->cl_cursor = entry_pos - ti->cl_first;
3694 if (position_set_by_scrollbar)
3697 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3700 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3701 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3702 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3706 else if (button == MB_MENU_LEAVE)
3710 PlaySound(SND_MENU_ITEM_SELECTING);
3712 if (ti->node_parent)
3714 *ti_ptr = ti->node_parent;
3715 DrawChooseTree(ti_ptr);
3717 else if (game_status == GAME_MODE_SETUP)
3719 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3720 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3722 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3723 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3724 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3725 execSetupGraphics();
3726 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3727 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3728 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3735 if (game_status == GAME_MODE_LEVELNR)
3736 level_nr = atoi(level_number_current->identifier);
3738 game_status = GAME_MODE_MAIN;
3740 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3746 if (mx || my) /* mouse input */
3748 int last_game_status = game_status; /* save current game status */
3751 /* force LEVELS draw offset on artwork setup screen */
3752 game_status = GAME_MODE_LEVELS;
3755 x = (mx - mSX) / 32;
3756 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3758 game_status = last_game_status; /* restore current game status */
3760 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3762 /* move cursor instead of scrolling when already at start/end of list */
3763 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3765 else if (dy == +1 * SCROLL_LINE &&
3766 ti->cl_first + num_page_entries == num_entries)
3769 /* handle scrolling screen one line or page */
3770 if (ti->cl_cursor + dy < 0 ||
3771 ti->cl_cursor + dy > num_page_entries - 1)
3774 boolean redraw = FALSE;
3776 if (ABS(dy) == SCROLL_PAGE)
3777 step = num_page_entries - 1;
3779 if (dy < 0 && ti->cl_first > 0)
3781 /* scroll page/line up */
3783 ti->cl_first -= step;
3784 if (ti->cl_first < 0)
3789 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3791 /* scroll page/line down */
3793 ti->cl_first += step;
3794 if (ti->cl_first + num_page_entries > num_entries)
3795 ti->cl_first = MAX(0, num_entries - num_page_entries);
3802 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3803 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3804 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3806 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3812 if (ABS(dy) == SCROLL_PAGE)
3813 step = num_page_entries - 1;
3815 if (dy < 0 && ti->cl_first > 0)
3817 /* scroll page/line up */
3819 ti->cl_first -= step;
3820 if (ti->cl_first < 0)
3823 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3824 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3825 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3827 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3830 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3832 /* scroll page/line down */
3834 ti->cl_first += step;
3835 if (ti->cl_first + num_page_entries > num_entries)
3836 ti->cl_first = MAX(0, num_entries - num_page_entries);
3838 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3839 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3840 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3842 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3850 /* handle moving cursor one line */
3851 y = ti->cl_cursor + dy;
3856 TreeInfo *node_first, *node_cursor;
3857 int entry_pos = ti->cl_first + y;
3859 node_first = getTreeInfoFirstGroupEntry(ti);
3860 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3862 if (node_cursor->node_group)
3866 PlaySound(SND_MENU_ITEM_SELECTING);
3868 node_cursor->cl_first = ti->cl_first;
3869 node_cursor->cl_cursor = ti->cl_cursor;
3870 *ti_ptr = node_cursor->node_group;
3871 DrawChooseTree(ti_ptr);
3876 else if (dx == -1 && ti->node_parent)
3880 PlaySound(SND_MENU_ITEM_SELECTING);
3882 *ti_ptr = ti->node_parent;
3883 DrawChooseTree(ti_ptr);
3888 if (!anyScrollbarGadgetActive() &&
3889 IN_VIS_FIELD(x, y) &&
3890 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3891 y >= 0 && y < num_page_entries)
3894 printf("::: TEST/HandleChooseTree [%d, %d, %d, %d]\n", Counter(),
3895 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
3900 if (y != ti->cl_cursor)
3902 PlaySound(SND_MENU_ITEM_ACTIVATING);
3904 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3905 drawChooseTreeCursor(y, TRUE);
3906 drawChooseTreeInfo(ti->cl_first + y, ti);
3913 TreeInfo *node_first, *node_cursor;
3914 int entry_pos = ti->cl_first + y;
3916 PlaySound(SND_MENU_ITEM_SELECTING);
3918 node_first = getTreeInfoFirstGroupEntry(ti);
3919 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3921 if (node_cursor->node_group)
3925 node_cursor->cl_first = ti->cl_first;
3926 node_cursor->cl_cursor = ti->cl_cursor;
3927 *ti_ptr = node_cursor->node_group;
3928 DrawChooseTree(ti_ptr);
3930 else if (node_cursor->parent_link)
3934 *ti_ptr = node_cursor->node_parent;
3935 DrawChooseTree(ti_ptr);
3942 FadeSetEnterScreen();
3945 node_cursor->cl_first = ti->cl_first;
3946 node_cursor->cl_cursor = ti->cl_cursor;
3947 *ti_ptr = node_cursor;
3949 if (ti->type == TREE_TYPE_LEVEL_DIR)
3951 LoadLevelSetup_SeriesInfo();
3953 SaveLevelSetup_LastSeries();
3954 SaveLevelSetup_SeriesInfo();
3958 if (game_status == GAME_MODE_SETUP)
3960 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3961 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3963 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3964 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3965 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3966 execSetupGraphics();
3967 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3968 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3969 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3976 if (game_status == GAME_MODE_LEVELNR)
3977 level_nr = atoi(level_number_current->identifier);
3979 game_status = GAME_MODE_MAIN;
3988 void DrawChooseLevelSet()
3990 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3992 DrawChooseTree(&leveldir_current);
3998 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4000 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4007 void DrawChooseLevelNr()
4011 if (level_number != NULL)
4013 freeTreeInfo(level_number);
4015 level_number = NULL;
4018 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4020 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4021 char identifier[32], name[32];
4024 /* temporarily load level info to get level name */
4025 LoadLevelInfoOnly(i);
4027 ti->node_top = &level_number;
4028 ti->sort_priority = 10000 + value;
4029 ti->color = (level.no_valid_file ? FC_BLUE :
4030 LevelStats_getSolved(i) ? FC_GREEN :
4031 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4033 sprintf(identifier, "%d", value);
4034 sprintf(name, "%03d: %s", value,
4035 (level.no_valid_file ? "(no file)" : level.name));
4037 setString(&ti->identifier, identifier);
4038 setString(&ti->name, name);
4039 setString(&ti->name_sorting, name);
4041 pushTreeInfo(&level_number, ti);
4044 /* sort level number values to start with lowest level number */
4045 sortTreeInfo(&level_number);
4047 /* set current level number to current level number */
4048 level_number_current =
4049 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4051 /* if that also fails, set current level number to first available level */
4052 if (level_number_current == NULL)
4053 level_number_current = level_number;
4055 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4058 DrawChooseTree(&level_number_current);
4060 DrawChooseTree(&leveldir_current);
4067 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4070 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4072 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4080 void DrawHallOfFame(int highlight_position)
4083 FadeSoundsAndMusic();
4085 /* (this is needed when called from GameEnd() after winning a game) */
4086 KeyboardAutoRepeatOn();
4089 /* (this is needed when called from GameEnd() after winning a game) */
4090 SetDrawDeactivationMask(REDRAW_NONE);
4091 SetDrawBackgroundMask(REDRAW_FIELD);
4093 CloseDoor(DOOR_CLOSE_2);
4095 if (highlight_position < 0)
4096 LoadScore(level_nr);
4098 FadeSetEnterScreen();
4100 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4103 FadeOut(REDRAW_FIELD);
4111 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4114 FadeIn(REDRAW_FIELD);
4118 static void drawHallOfFameList(int first_entry, int highlight_position)
4122 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4125 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4126 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4127 "HighScores of Level %d", level_nr);
4129 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4131 int entry = first_entry + i;
4132 boolean active = (entry == highlight_position);
4133 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4134 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4135 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4136 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4137 int dx1 = 3 * getFontWidth(font_nr1);
4138 int dx2 = dx1 + getFontWidth(font_nr1);
4140 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
4141 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4143 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4145 int sy = mSY + 64 + i * 32;
4147 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4148 DrawText(mSX + dx1, sy, ".", font_nr1);
4150 for (j = 0; j < num_dots; j++)
4151 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4153 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4156 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4157 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4159 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4162 redraw_mask |= REDRAW_FIELD;
4165 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4167 static int first_entry = 0;
4168 static int highlight_position = 0;
4169 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4171 if (button == MB_MENU_INITIALIZE)
4174 highlight_position = mx;
4175 drawHallOfFameList(first_entry, highlight_position);
4180 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4181 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4185 if (first_entry > 0)
4187 first_entry -= step;
4188 if (first_entry < 0)
4191 drawHallOfFameList(first_entry, highlight_position);
4196 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4198 first_entry += step;
4199 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4200 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4202 drawHallOfFameList(first_entry, highlight_position);
4205 else if (button == MB_MENU_LEAVE)
4207 PlaySound(SND_MENU_ITEM_SELECTING);
4209 FadeSound(SND_BACKGROUND_SCORES);
4211 game_status = GAME_MODE_MAIN;
4215 else if (button == MB_MENU_CHOICE)
4217 PlaySound(SND_MENU_ITEM_SELECTING);
4219 FadeSound(SND_BACKGROUND_SCORES);
4222 FadeOut(REDRAW_FIELD);
4225 game_status = GAME_MODE_MAIN;
4227 DrawAndFadeInMainMenu(REDRAW_FIELD);
4230 if (game_status == GAME_MODE_SCORES)
4231 PlayMenuSoundIfLoop();
4239 /* ========================================================================= */
4240 /* setup screen functions */
4241 /* ========================================================================= */
4243 static struct TokenInfo *setup_info;
4244 static int num_setup_info; /* number of setup entries shown on screen */
4245 static int max_setup_info; /* total number of setup entries in list */
4247 static char *screen_mode_text;
4248 static char *window_size_text;
4249 static char *scaling_type_text;
4250 static char *scroll_delay_text;
4251 static char *game_speed_text;
4252 static char *graphics_set_name;
4253 static char *sounds_set_name;
4254 static char *music_set_name;
4255 static char *volume_simple_text;
4256 static char *volume_loops_text;
4257 static char *volume_music_text;
4259 static void execSetupMain()
4261 setup_mode = SETUP_MODE_MAIN;
4266 static void execSetupGame_setGameSpeeds()
4268 if (game_speeds == NULL)
4272 for (i = 0; game_speeds_list[i].value != -1; i++)
4274 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4275 char identifier[32], name[32];
4276 int value = game_speeds_list[i].value;
4277 char *text = game_speeds_list[i].text;
4279 ti->node_top = &game_speeds;
4280 ti->sort_priority = 10000 - value;
4282 sprintf(identifier, "%d", value);
4283 sprintf(name, "%s", text);
4285 setString(&ti->identifier, identifier);
4286 setString(&ti->name, name);
4287 setString(&ti->name_sorting, name);
4288 setString(&ti->infotext, "Game Speed");
4290 pushTreeInfo(&game_speeds, ti);
4293 /* sort game speed values to start with slowest game speed */
4294 sortTreeInfo(&game_speeds);
4296 /* set current game speed to configured game speed value */
4297 game_speed_current =
4298 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4300 /* if that fails, set current game speed to reliable default value */
4301 if (game_speed_current == NULL)
4302 game_speed_current =
4303 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4305 /* if that also fails, set current game speed to first available speed */
4306 if (game_speed_current == NULL)
4307 game_speed_current = game_speeds;
4310 setup.game_frame_delay = atoi(game_speed_current->identifier);
4312 /* needed for displaying game speed text instead of identifier */
4313 game_speed_text = game_speed_current->name;
4316 static void execSetupGame_setScrollDelays()
4318 if (scroll_delays == NULL)
4322 for (i = 0; scroll_delays_list[i].value != -1; i++)
4324 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4325 char identifier[32], name[32];
4326 int value = scroll_delays_list[i].value;
4327 char *text = scroll_delays_list[i].text;
4329 ti->node_top = &scroll_delays;
4330 ti->sort_priority = value;
4332 sprintf(identifier, "%d", value);
4333 sprintf(name, "%s", text);
4335 setString(&ti->identifier, identifier);
4336 setString(&ti->name, name);
4337 setString(&ti->name_sorting, name);
4338 setString(&ti->infotext, "Scaling Type");
4340 pushTreeInfo(&scroll_delays, ti);
4343 /* sort scaling type values to start with lowest scaling type value */
4344 sortTreeInfo(&scroll_delays);
4346 /* set current scaling type value to configured scaling type value */
4347 scroll_delay_current =
4348 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4350 /* if that fails, set current scaling type to reliable default value */
4351 if (scroll_delay_current == NULL)
4352 scroll_delay_current =
4353 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4355 /* if that also fails, set current scaling type to first available value */
4356 if (scroll_delay_current == NULL)
4357 scroll_delay_current = scroll_delays;
4360 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4362 /* needed for displaying scaling type text instead of identifier */
4363 scroll_delay_text = scroll_delay_current->name;
4366 static void execSetupGame()
4368 execSetupGame_setGameSpeeds();
4369 execSetupGame_setScrollDelays();
4371 setup_mode = SETUP_MODE_GAME;
4376 static void execSetupChooseGameSpeed()
4378 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4383 static void execSetupChooseScrollDelay()
4385 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4390 static void execSetupEditor()
4392 setup_mode = SETUP_MODE_EDITOR;
4397 static void execSetupGraphics_setWindowSizes(boolean update_list)
4399 if (window_sizes != NULL && update_list)
4401 freeTreeInfo(window_sizes);
4403 window_sizes = NULL;
4406 if (window_sizes == NULL)
4408 boolean current_window_size_found = FALSE;
4411 for (i = 0; window_sizes_list[i].value != -1; i++)
4413 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4414 char identifier[32], name[32];
4415 int value = window_sizes_list[i].value;
4416 char *text = window_sizes_list[i].text;
4418 ti->node_top = &window_sizes;
4419 ti->sort_priority = value;
4421 sprintf(identifier, "%d", value);
4422 sprintf(name, "%s", text);
4424 setString(&ti->identifier, identifier);
4425 setString(&ti->name, name);
4426 setString(&ti->name_sorting, name);
4427 setString(&ti->infotext, "Window Scaling");
4429 pushTreeInfo(&window_sizes, ti);
4431 if (value == setup.window_scaling_percent)
4432 current_window_size_found = TRUE;
4435 if (!current_window_size_found)
4437 // add entry for non-preset window scaling value
4439 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4440 char identifier[32], name[32];
4441 int value = setup.window_scaling_percent;
4443 ti->node_top = &window_sizes;
4444 ti->sort_priority = value;
4446 sprintf(identifier, "%d", value);
4447 sprintf(name, "%d %% (Current)", value);
4449 setString(&ti->identifier, identifier);
4450 setString(&ti->name, name);
4451 setString(&ti->name_sorting, name);
4452 setString(&ti->infotext, "Window Scaling");
4454 pushTreeInfo(&window_sizes, ti);
4457 /* sort window size values to start with lowest window size value */
4458 sortTreeInfo(&window_sizes);
4460 /* set current window size value to configured window size value */
4461 window_size_current =
4462 getTreeInfoFromIdentifier(window_sizes,
4463 i_to_a(setup.window_scaling_percent));
4465 /* if that fails, set current window size to reliable default value */
4466 if (window_size_current == NULL)
4467 window_size_current =
4468 getTreeInfoFromIdentifier(window_sizes,
4469 i_to_a(STD_WINDOW_SCALING_PERCENT));
4471 /* if that also fails, set current window size to first available value */
4472 if (window_size_current == NULL)
4473 window_size_current = window_sizes;
4476 setup.window_scaling_percent = atoi(window_size_current->identifier);
4478 /* needed for displaying window size text instead of identifier */
4479 window_size_text = window_size_current->name;
4482 static void execSetupGraphics_setScalingTypes()
4484 if (scaling_types == NULL)
4488 for (i = 0; scaling_types_list[i].value != NULL; i++)
4490 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4491 char identifier[32], name[32];
4492 char *value = scaling_types_list[i].value;
4493 char *text = scaling_types_list[i].text;
4495 ti->node_top = &scaling_types;
4496 ti->sort_priority = i;
4498 sprintf(identifier, "%s", value);
4499 sprintf(name, "%s", text);
4501 setString(&ti->identifier, identifier);
4502 setString(&ti->name, name);
4503 setString(&ti->name_sorting, name);
4504 setString(&ti->infotext, "Anti-Aliasing");
4506 pushTreeInfo(&scaling_types, ti);
4509 /* sort scaling type values to start with lowest scaling type value */
4510 sortTreeInfo(&scaling_types);
4512 /* set current scaling type value to configured scaling type value */
4513 scaling_type_current =
4514 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4516 /* if that fails, set current scaling type to reliable default value */
4517 if (scaling_type_current == NULL)
4518 scaling_type_current =
4519 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4521 /* if that also fails, set current scaling type to first available value */
4522 if (scaling_type_current == NULL)
4523 scaling_type_current = scaling_types;
4526 setup.window_scaling_quality = scaling_type_current->identifier;
4528 /* needed for displaying scaling type text instead of identifier */
4529 scaling_type_text = scaling_type_current->name;
4532 static void execSetupGraphics_setScreenModes()
4534 // if (screen_modes == NULL && video.fullscreen_available)
4535 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4539 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4541 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4542 char identifier[32], name[32];
4543 int x = video.fullscreen_modes[i].width;
4544 int y = video.fullscreen_modes[i].height;
4547 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4549 ti->node_top = &screen_modes;
4550 ti->sort_priority = x * 10000 + y;
4552 sprintf(identifier, "%dx%d", x, y);
4553 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4555 setString(&ti->identifier, identifier);
4556 setString(&ti->name, name);
4557 setString(&ti->name_sorting, name);
4558 setString(&ti->infotext, "Fullscreen Mode");
4560 pushTreeInfo(&screen_modes, ti);
4563 /* sort fullscreen modes to start with lowest available screen resolution */
4564 sortTreeInfo(&screen_modes);
4566 /* set current screen mode for fullscreen mode to configured setup value */
4567 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4568 setup.fullscreen_mode);
4570 /* if that fails, set current screen mode to reliable default value */
4571 if (screen_mode_current == NULL)
4572 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4573 DEFAULT_FULLSCREEN_MODE);
4575 /* if that also fails, set current screen mode to first available mode */
4576 if (screen_mode_current == NULL)
4577 screen_mode_current = screen_modes;
4579 if (screen_mode_current == NULL)
4580 video.fullscreen_available = FALSE;
4583 // if (video.fullscreen_available)
4584 if (screen_mode_current != NULL)
4586 setup.fullscreen_mode = screen_mode_current->identifier;
4588 /* needed for displaying screen mode name instead of identifier */
4589 screen_mode_text = screen_mode_current->name;
4593 static void execSetupGraphics()
4595 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4597 // update "setup.window_scaling_percent" from list selection
4598 execSetupGraphics_setWindowSizes(FALSE);
4602 // update list selection from "setup.window_scaling_percent"
4603 execSetupGraphics_setWindowSizes(TRUE);
4606 execSetupGraphics_setScalingTypes();
4607 execSetupGraphics_setScreenModes();
4609 setup_mode = SETUP_MODE_GRAPHICS;
4613 #if defined(TARGET_SDL2)
4614 // window scaling may have changed at this point
4615 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4617 // window scaling quality may have changed at this point
4618 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4619 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4623 #if !defined(PLATFORM_ANDROID)
4624 #if defined(TARGET_SDL2)
4625 static void execSetupChooseWindowSize()
4628 if (!video.window_scaling_available)
4632 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4637 static void execSetupChooseScalingType()
4639 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4644 static void execSetupChooseScreenMode()
4646 if (!video.fullscreen_available)
4649 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4656 static void execSetupChooseVolumeSimple()
4658 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4663 static void execSetupChooseVolumeLoops()
4665 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4670 static void execSetupChooseVolumeMusic()
4672 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4677 static void execSetupSound()
4680 if (volumes_simple == NULL)
4684 for (i = 0; volumes_list[i].value != -1; i++)
4686 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4687 char identifier[32], name[32];
4688 int value = volumes_list[i].value;
4689 char *text = volumes_list[i].text;
4691 ti->node_top = &volumes_simple;
4692 ti->sort_priority = value;
4694 sprintf(identifier, "%d", value);
4695 sprintf(name, "%s", text);
4697 setString(&ti->identifier, identifier);
4698 setString(&ti->name, name);
4699 setString(&ti->name_sorting, name);
4700 setString(&ti->infotext, "Sound Volume");
4702 pushTreeInfo(&volumes_simple, ti);
4705 /* sort volume values to start with lowest volume value */
4706 sortTreeInfo(&volumes_simple);
4708 /* set current volume value to configured volume value */
4709 volume_simple_current =
4710 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4712 /* if that fails, set current volume to reliable default value */
4713 if (volume_simple_current == NULL)
4714 volume_simple_current =
4715 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4717 /* if that also fails, set current volume to first available value */
4718 if (volume_simple_current == NULL)
4719 volume_simple_current = volumes_simple;
4722 if (volumes_loops == NULL)
4726 for (i = 0; volumes_list[i].value != -1; i++)
4728 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4729 char identifier[32], name[32];
4730 int value = volumes_list[i].value;
4731 char *text = volumes_list[i].text;
4733 ti->node_top = &volumes_loops;
4734 ti->sort_priority = value;
4736 sprintf(identifier, "%d", value);
4737 sprintf(name, "%s", text);
4739 setString(&ti->identifier, identifier);
4740 setString(&ti->name, name);
4741 setString(&ti->name_sorting, name);
4742 setString(&ti->infotext, "Loops Volume");
4744 pushTreeInfo(&volumes_loops, ti);
4747 /* sort volume values to start with lowest volume value */
4748 sortTreeInfo(&volumes_loops);
4750 /* set current volume value to configured volume value */
4751 volume_loops_current =
4752 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4754 /* if that fails, set current volume to reliable default value */
4755 if (volume_loops_current == NULL)
4756 volume_loops_current =
4757 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4759 /* if that also fails, set current volume to first available value */
4760 if (volume_loops_current == NULL)
4761 volume_loops_current = volumes_loops;
4764 if (volumes_music == NULL)
4768 for (i = 0; volumes_list[i].value != -1; i++)
4770 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4771 char identifier[32], name[32];
4772 int value = volumes_list[i].value;
4773 char *text = volumes_list[i].text;
4775 ti->node_top = &volumes_music;
4776 ti->sort_priority = value;
4778 sprintf(identifier, "%d", value);
4779 sprintf(name, "%s", text);
4781 setString(&ti->identifier, identifier);
4782 setString(&ti->name, name);
4783 setString(&ti->name_sorting, name);
4784 setString(&ti->infotext, "Music Volume");
4786 pushTreeInfo(&volumes_music, ti);
4789 /* sort volume values to start with lowest volume value */
4790 sortTreeInfo(&volumes_music);
4792 /* set current volume value to configured volume value */
4793 volume_music_current =
4794 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4796 /* if that fails, set current volume to reliable default value */
4797 if (volume_music_current == NULL)
4798 volume_music_current =
4799 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4801 /* if that also fails, set current volume to first available value */
4802 if (volume_music_current == NULL)
4803 volume_music_current = volumes_music;
4806 setup.volume_simple = atoi(volume_simple_current->identifier);
4807 setup.volume_loops = atoi(volume_loops_current->identifier);
4808 setup.volume_music = atoi(volume_music_current->identifier);
4810 /* needed for displaying volume text instead of identifier */
4811 volume_simple_text = volume_simple_current->name;
4812 volume_loops_text = volume_loops_current->name;
4813 volume_music_text = volume_music_current->name;
4816 setup_mode = SETUP_MODE_SOUND;
4821 static void execSetupArtwork()
4824 printf("::: '%s', '%s', '%s'\n",
4825 artwork.gfx_current->subdir,
4826 artwork.gfx_current->fullpath,
4827 artwork.gfx_current->basepath);
4830 setup.graphics_set = artwork.gfx_current->identifier;
4831 setup.sounds_set = artwork.snd_current->identifier;
4832 setup.music_set = artwork.mus_current->identifier;
4834 /* needed if last screen (setup choice) changed graphics, sounds or music */
4835 ReloadCustomArtwork(0);
4837 /* needed for displaying artwork name instead of artwork identifier */
4838 graphics_set_name = artwork.gfx_current->name;
4839 sounds_set_name = artwork.snd_current->name;
4840 music_set_name = artwork.mus_current->name;
4842 setup_mode = SETUP_MODE_ARTWORK;
4847 static void execSetupChooseGraphics()
4849 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4854 static void execSetupChooseSounds()
4856 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4861 static void execSetupChooseMusic()
4863 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4868 static void execSetupInput()
4870 setup_mode = SETUP_MODE_INPUT;
4875 static void execSetupShortcuts()
4877 setup_mode = SETUP_MODE_SHORTCUTS;
4882 static void execSetupShortcuts1()
4884 setup_mode = SETUP_MODE_SHORTCUTS_1;
4889 static void execSetupShortcuts2()
4891 setup_mode = SETUP_MODE_SHORTCUTS_2;
4896 static void execSetupShortcuts3()
4898 setup_mode = SETUP_MODE_SHORTCUTS_3;
4903 static void execSetupShortcuts4()
4905 setup_mode = SETUP_MODE_SHORTCUTS_4;
4910 static void execSetupShortcuts5()
4912 setup_mode = SETUP_MODE_SHORTCUTS_5;
4917 static void execExitSetup()
4919 game_status = GAME_MODE_MAIN;
4921 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4924 static void execSaveAndExitSetup()
4930 static struct TokenInfo setup_info_main[] =
4932 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4933 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4934 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4935 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4936 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4937 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4938 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4939 { TYPE_EMPTY, NULL, "" },
4940 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4941 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4946 static struct TokenInfo setup_info_game[] =
4948 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4949 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4950 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4951 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4952 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4953 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4954 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4955 { TYPE_STRING, &game_speed_text, "" },
4957 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4958 { TYPE_STRING, &scroll_delay_text, "" },
4960 { TYPE_EMPTY, NULL, "" },
4961 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4966 static struct TokenInfo setup_info_editor[] =
4969 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
4970 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
4971 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
4972 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
4973 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
4974 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
4975 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
4976 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
4978 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
4979 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
4980 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
4982 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
4984 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
4985 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
4986 { TYPE_EMPTY, NULL, "" },
4988 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
4989 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
4990 { TYPE_EMPTY, NULL, "" },
4992 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
4993 { TYPE_EMPTY, NULL, "" },
4994 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
4999 static struct TokenInfo setup_info_graphics[] =
5001 #if !defined(PLATFORM_ANDROID)
5002 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5003 #if defined(TARGET_SDL2)
5004 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5005 { TYPE_STRING, &window_size_text, "" },
5007 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5008 { TYPE_STRING, &scaling_type_text, "" },
5011 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5012 { TYPE_STRING, &screen_mode_text, "" },
5016 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
5019 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5020 { TYPE_STRING, &scroll_delay_text, "" },
5023 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
5025 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5026 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5027 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5028 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5029 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5030 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5031 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5032 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5033 { TYPE_EMPTY, NULL, "" },
5034 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5039 static struct TokenInfo setup_info_sound[] =
5041 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5042 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5043 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5044 { TYPE_EMPTY, NULL, "" },
5045 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5046 { TYPE_STRING, &volume_simple_text, "" },
5047 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5048 { TYPE_STRING, &volume_loops_text, "" },
5049 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5050 { TYPE_STRING, &volume_music_text, "" },
5051 { TYPE_EMPTY, NULL, "" },
5052 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5057 static struct TokenInfo setup_info_artwork[] =
5059 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5060 { TYPE_STRING, &graphics_set_name, "" },
5061 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5062 { TYPE_STRING, &sounds_set_name, "" },
5063 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5064 { TYPE_STRING, &music_set_name, "" },
5065 { TYPE_EMPTY, NULL, "" },
5068 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5069 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5070 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5072 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
5073 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
5074 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
5075 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
5078 { TYPE_STRING, NULL, "Override Level Artwork:"},
5079 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
5080 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
5081 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
5083 { TYPE_EMPTY, NULL, "" },
5084 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5089 static struct TokenInfo setup_info_input[] =
5091 { TYPE_SWITCH, NULL, "Player:" },
5092 { TYPE_SWITCH, NULL, "Device:" },
5093 { TYPE_ENTER_MENU, NULL, "" },
5094 { TYPE_EMPTY, NULL, "" },
5095 { TYPE_EMPTY, NULL, "" },
5096 { TYPE_EMPTY, NULL, "" },
5097 { TYPE_EMPTY, NULL, "" },
5098 { TYPE_EMPTY, NULL, "" },
5099 { TYPE_EMPTY, NULL, "" },
5100 { TYPE_EMPTY, NULL, "" },
5101 { TYPE_EMPTY, NULL, "" },
5102 { TYPE_EMPTY, NULL, "" },
5103 { TYPE_EMPTY, NULL, "" },
5104 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5109 static struct TokenInfo setup_info_shortcuts[] =
5111 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5112 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5113 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5114 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5115 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5116 { TYPE_EMPTY, NULL, "" },
5117 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5122 static struct TokenInfo setup_info_shortcuts_1[] =
5124 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5125 { TYPE_KEY, &setup.shortcut.save_game, "" },
5126 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5127 { TYPE_KEY, &setup.shortcut.load_game, "" },
5128 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5129 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5130 { TYPE_EMPTY, NULL, "" },
5131 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5132 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5133 { TYPE_EMPTY, NULL, "" },
5134 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5139 static struct TokenInfo setup_info_shortcuts_2[] =
5141 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5142 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5143 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5144 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5145 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5146 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5147 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5148 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5149 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5150 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5151 { TYPE_EMPTY, NULL, "" },
5152 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5157 static struct TokenInfo setup_info_shortcuts_3[] =
5159 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5160 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5161 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5162 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5163 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5164 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5165 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5166 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5167 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5168 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5169 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5170 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5171 { TYPE_EMPTY, NULL, "" },
5172 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5177 static struct TokenInfo setup_info_shortcuts_4[] =
5179 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5180 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5181 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5182 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5183 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5184 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5185 { TYPE_EMPTY, NULL, "" },
5186 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5191 static struct TokenInfo setup_info_shortcuts_5[] =
5193 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5194 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5195 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5196 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5197 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5198 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5199 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5200 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5201 { TYPE_EMPTY, NULL, "" },
5202 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5207 static Key getSetupKey()
5209 Key key = KSYM_UNDEFINED;
5210 boolean got_key_event = FALSE;
5212 while (!got_key_event)
5214 if (PendingEvent()) /* got event */
5222 case EVENT_KEYPRESS:
5224 key = GetEventKey((KeyEvent *)&event, TRUE);
5226 /* press 'Escape' or 'Enter' to keep the existing key binding */
5227 if (key == KSYM_Escape || key == KSYM_Return)
5228 key = KSYM_UNDEFINED; /* keep old value */
5230 got_key_event = TRUE;
5234 case EVENT_KEYRELEASE:
5235 key_joystick_mapping = 0;
5239 HandleOtherEvents(&event);
5247 /* don't eat all CPU time */
5254 static int getSetupTextFont(int type)
5256 if (type & (TYPE_SWITCH |
5268 static int getSetupValueFont(int type, void *value)
5270 if (type & TYPE_KEY)
5271 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5272 else if (type & TYPE_STRING)
5273 return FONT_VALUE_2;
5274 else if (type & TYPE_ECS_AGA)
5275 return FONT_VALUE_1;
5276 else if (type & TYPE_BOOLEAN_STYLE)
5277 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5278 else if (type & TYPE_YES_NO_AUTO)
5279 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5280 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5282 return FONT_VALUE_1;
5286 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5288 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5289 struct TokenInfo *si = &setup_info[si_pos];
5290 boolean font_draw_xoffset_modified = FALSE;
5291 int font_draw_xoffset_old = -1;
5292 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5293 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5294 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5295 int xpos = menu_screen_value_xpos;
5296 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5297 int startx = mSX + xpos * 32;
5298 int starty = mSY + ypos * 32;
5299 int font_nr, font_width;
5303 int type = si->type;
5304 void *value = si->value;
5305 char *value_string = getSetupValue(type, value);
5310 if (value_string == NULL)
5313 if (type & TYPE_KEY)
5315 xpos = MENU_SCREEN_START_XPOS;
5317 if (type & TYPE_QUERY)
5318 value_string = "<press key>";
5320 else if (type & TYPE_STRING)
5322 int max_value_len = (SCR_FIELDX - 2) * 2;
5324 xpos = MENU_SCREEN_START_XPOS;
5326 if (strlen(value_string) > max_value_len)
5327 value_string[max_value_len] = '\0';
5329 else if (type & TYPE_YES_NO_AUTO)
5331 xpos = menu_screen_value_xpos - 1;
5334 startx = mSX + xpos * 32;
5335 starty = mSY + ypos * 32;
5336 font_nr = getSetupValueFont(type, value);
5337 font_width = getFontWidth(font_nr);
5339 font_height = getFontHeight(font_nr);
5343 if (menu_screen_value_xpos < 1 + MAX_MENU_TEXT_LENGTH_BIG)
5347 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5348 if (setup_mode != SETUP_MODE_INPUT)
5350 int max_menu_text_length_big = (menu_screen_value_xpos -
5351 MENU_SCREEN_START_XPOS);
5352 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5353 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5354 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5355 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5356 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5357 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5358 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5359 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5360 boolean correct_font_draw_xoffset = FALSE;
5362 if (xpos == MENU_SCREEN_START_XPOS &&
5363 startx + font1_xoffset < text_startx + text_font_xoffset)
5364 correct_font_draw_xoffset = TRUE;
5366 if (xpos == menu_screen_value_xpos &&
5367 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5368 correct_font_draw_xoffset = TRUE;
5370 /* check if setup value would overlap with setup text when printed */
5371 /* (this can happen for extreme/wrong values for font draw offset) */
5372 if (correct_font_draw_xoffset)
5374 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5375 font_draw_xoffset_modified = TRUE;
5377 if (type & TYPE_KEY)
5378 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5379 else if (!(type & TYPE_STRING))
5380 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5381 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5386 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5388 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5389 DrawText(startx + i * font_width, starty, " ", font_nr);
5392 // printf("::: startx == %d\n", startx);
5394 DrawText(startx, starty, value_string, font_nr);
5396 if (font_draw_xoffset_modified)
5397 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5402 static void drawSetupValue(int pos)
5404 boolean font_draw_xoffset_modified = FALSE;
5405 int font_draw_xoffset_old = -1;
5406 int xpos = MENU_SCREEN_VALUE_XPOS;
5407 int ypos = MENU_SCREEN_START_YPOS + pos;
5408 int startx = mSX + xpos * 32;
5409 int starty = mSY + ypos * 32;
5410 int font_nr, font_width;
5414 int type = setup_info[pos].type;
5415 void *value = setup_info[pos].value;
5416 char *value_string = getSetupValue(type, value);
5421 if (value_string == NULL)
5424 if (type & TYPE_KEY)
5426 xpos = MENU_SCREEN_START_XPOS;
5428 if (type & TYPE_QUERY)
5429 value_string = "<press key>";
5431 else if (type & TYPE_STRING)
5433 int max_value_len = (SCR_FIELDX - 2) * 2;
5435 xpos = MENU_SCREEN_START_XPOS;
5437 if (strlen(value_string) > max_value_len)
5438 value_string[max_value_len] = '\0';
5440 else if (type & TYPE_YES_NO_AUTO)
5442 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5445 startx = mSX + xpos * 32;
5446 starty = mSY + ypos * 32;
5447 font_nr = getSetupValueFont(type, value);
5448 font_width = getFontWidth(font_nr);
5450 font_height = getFontHeight(font_nr);
5453 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5454 if (setup_mode != SETUP_MODE_INPUT)
5456 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5457 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5458 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5459 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5460 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5461 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5462 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5463 boolean correct_font_draw_xoffset = FALSE;
5465 if (xpos == MENU_SCREEN_START_XPOS &&
5466 startx + font1_xoffset < text_startx + text_font_xoffset)
5467 correct_font_draw_xoffset = TRUE;
5469 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5470 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5471 correct_font_draw_xoffset = TRUE;
5473 /* check if setup value would overlap with setup text when printed */
5474 /* (this can happen for extreme/wrong values for font draw offset) */
5475 if (correct_font_draw_xoffset)
5477 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5478 font_draw_xoffset_modified = TRUE;
5480 if (type & TYPE_KEY)
5481 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5482 else if (!(type & TYPE_STRING))
5483 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5484 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5489 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5491 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5492 DrawText(startx + i * font_width, starty, " ", font_nr);
5495 DrawText(startx, starty, value_string, font_nr);
5497 if (font_draw_xoffset_modified)
5498 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5503 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5505 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5506 struct TokenInfo *si = &setup_info[si_pos];
5508 if (si->type & TYPE_BOOLEAN_STYLE)
5510 *(boolean *)si->value ^= TRUE;
5512 else if (si->type & TYPE_YES_NO_AUTO)
5516 (*(int *)si->value == AUTO ? TRUE :
5517 *(int *)si->value == TRUE ? FALSE : AUTO) :
5518 (*(int *)si->value == TRUE ? AUTO :
5519 *(int *)si->value == AUTO ? FALSE : TRUE));
5521 else if (si->type & TYPE_KEY)
5525 si->type |= TYPE_QUERY;
5526 drawSetupValue(screen_pos, setup_info_pos_raw);
5527 si->type &= ~TYPE_QUERY;
5529 key = getSetupKey();
5530 if (key != KSYM_UNDEFINED)
5531 *(Key *)si->value = key;
5534 drawSetupValue(screen_pos, setup_info_pos_raw);
5536 // fullscreen state may have changed at this point
5537 if (si->value == &setup.fullscreen)
5538 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5543 static void changeSetupValue(int pos, int dx)
5545 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5547 *(boolean *)setup_info[pos].value ^= TRUE;
5549 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5551 *(int *)setup_info[pos].value =
5553 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5554 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5555 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5556 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5558 else if (setup_info[pos].type & TYPE_KEY)
5562 setup_info[pos].type |= TYPE_QUERY;
5563 drawSetupValue(pos, -1);
5564 setup_info[pos].type &= ~TYPE_QUERY;
5566 key = getSetupKey();
5567 if (key != KSYM_UNDEFINED)
5568 *(Key *)setup_info[pos].value = key;
5571 drawSetupValue(pos, -1);
5573 // fullscreen state may have changed at this point
5574 if (setup_info[pos].value == &setup.fullscreen)
5575 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5580 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5583 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5584 struct TokenInfo *si = &setup_info[si_pos];
5585 int xpos = MENU_SCREEN_START_XPOS;
5586 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5587 int font_nr = getSetupTextFont(si->type);
5589 if (setup_info == setup_info_input)
5590 font_nr = FONT_MENU_1;
5593 font_nr = FONT_ACTIVE(font_nr);
5595 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5597 if (si->type & ~TYPE_SKIP_ENTRY)
5598 drawCursor(screen_pos, active);
5601 static void DrawCursorAndText_Setup(int pos, boolean active)
5603 int xpos = MENU_SCREEN_START_XPOS;
5604 int ypos = MENU_SCREEN_START_YPOS + pos;
5605 int font_nr = getSetupTextFont(setup_info[pos].type);
5607 if (setup_info == setup_info_input)
5608 font_nr = FONT_MENU_1;
5611 font_nr = FONT_ACTIVE(font_nr);
5613 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5615 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5616 drawCursor(pos, active);
5620 static void drawSetupInfoList(struct TokenInfo *setup_info,
5621 int first_entry, int num_page_entries)
5625 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5626 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5628 if (num_page_entries > max_setup_info)
5629 num_page_entries = max_setup_info;
5631 if (first_entry + num_page_entries > max_setup_info)
5635 /* clear tree list area, but not title or scrollbar */
5636 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
5637 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
5638 NUM_MENU_ENTRIES_ON_SCREEN * 32);
5641 for (i = 0; i < num_page_entries; i++)
5643 int setup_info_pos = first_entry + i;
5644 struct TokenInfo *si = &setup_info[setup_info_pos];
5645 void *value_ptr = si->value;
5647 /* set some entries to "unchangeable" according to other variables */
5648 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5649 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5650 (value_ptr == &setup.sound_music && !audio.music_available) ||
5651 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5652 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5653 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5654 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5655 si->type |= TYPE_GHOSTED;
5657 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5658 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5659 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5660 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5661 else if (si->type & ~TYPE_SKIP_ENTRY)
5662 initCursor(i, IMG_MENU_BUTTON);
5664 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5666 if (si->type & TYPE_VALUE)
5667 drawSetupValue(i, setup_info_pos);
5671 static void DrawSetupScreen_Generic()
5673 boolean redraw_all = FALSE;
5674 char *title_string = NULL;
5680 FreeScreenGadgets();
5681 CreateScreenGadgets();
5684 CloseDoor(DOOR_CLOSE_2);
5686 if (redraw_mask & REDRAW_ALL)
5690 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5691 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5692 int2str(0, redraw_mask)));
5696 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5697 FadeOut(redraw_mask);
5699 FadeOut(REDRAW_FIELD);
5704 if (setup_mode == SETUP_MODE_MAIN)
5706 setup_info = setup_info_main;
5707 title_string = "Setup";
5709 else if (setup_mode == SETUP_MODE_GAME)
5711 setup_info = setup_info_game;
5712 title_string = "Setup Game";
5714 else if (setup_mode == SETUP_MODE_EDITOR)
5716 setup_info = setup_info_editor;
5717 title_string = "Setup Editor";
5719 else if (setup_mode == SETUP_MODE_GRAPHICS)
5721 setup_info = setup_info_graphics;
5722 title_string = "Setup Graphics";
5724 else if (setup_mode == SETUP_MODE_SOUND)
5726 setup_info = setup_info_sound;
5727 title_string = "Setup Sound";
5729 else if (setup_mode == SETUP_MODE_ARTWORK)
5731 setup_info = setup_info_artwork;
5732 title_string = "Custom Artwork";
5734 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5736 setup_info = setup_info_shortcuts;
5737 title_string = "Setup Shortcuts";
5739 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5741 setup_info = setup_info_shortcuts_1;
5742 title_string = "Setup Shortcuts";
5744 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5746 setup_info = setup_info_shortcuts_2;
5747 title_string = "Setup Shortcuts";
5749 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5751 setup_info = setup_info_shortcuts_3;
5752 title_string = "Setup Shortcuts";
5754 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5756 setup_info = setup_info_shortcuts_4;
5757 title_string = "Setup Shortcuts";
5759 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5761 setup_info = setup_info_shortcuts_5;
5762 title_string = "Setup Shortcuts";
5765 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5770 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5774 for (i = 0; setup_info[i].type != 0; i++)
5778 drawSetupInfoList(setup_info, 0, NUM_MENU_ENTRIES_ON_SCREEN);
5785 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5787 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5790 void *value_ptr = setup_info[i].value;
5792 /* set some entries to "unchangeable" according to other variables */
5793 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5794 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5795 (value_ptr == &setup.sound_music && !audio.music_available) ||
5796 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5797 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5798 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5799 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5800 setup_info[i].type |= TYPE_GHOSTED;
5802 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5803 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5804 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5805 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5806 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5807 initCursor(i, IMG_MENU_BUTTON);
5809 DrawCursorAndText_Setup(i, FALSE);
5811 if (setup_info[i].type & TYPE_VALUE)
5819 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
5820 "Joysticks deactivated in setup menu");
5824 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5828 MapScreenGadgets(max_setup_info);
5832 redraw_mask = REDRAW_ALL;
5835 FadeIn(redraw_mask);
5837 FadeIn(REDRAW_FIELD);
5842 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5846 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5848 static int choice_store[MAX_SETUP_MODES];
5849 static int first_entry_store[MAX_SETUP_MODES];
5850 int choice = choice_store[setup_mode]; /* starts with 0 */
5851 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5854 int y = choice - first_entry;
5859 boolean position_set_by_scrollbar = (dx == 999);
5861 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5862 int num_page_entries;
5864 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5867 if (button == MB_MENU_INITIALIZE)
5869 /* advance to first valid menu entry */
5870 while (choice < num_setup_info &&
5871 setup_info[choice].type & TYPE_SKIP_ENTRY)
5874 choice_store[setup_mode] = choice;
5878 if (position_set_by_scrollbar)
5879 first_entry = first_entry_store[setup_mode] = dy;
5881 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5882 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5884 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5888 if (choice < first_entry)
5890 choice = first_entry;
5892 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5895 else if (choice > first_entry + num_page_entries - 1)
5897 choice = first_entry + num_page_entries - 1;
5899 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5903 choice_store[setup_mode] = choice;
5905 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5907 DrawCursorAndText_Setup(choice, -1, TRUE);
5912 else if (button == MB_MENU_LEAVE)
5916 PlaySound(SND_MENU_ITEM_SELECTING);
5918 for (i = 0; setup_info[i].type != 0; i++)
5920 if (setup_info[i].type & TYPE_LEAVE_MENU)
5922 void (*menu_callback_function)(void) = setup_info[i].value;
5926 menu_callback_function();
5928 break; /* absolutely needed because function changes 'setup_info'! */
5935 if (mx || my) /* mouse input */
5937 x = (mx - mSX) / 32;
5938 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5941 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5943 else if (dx || dy) /* keyboard input */
5946 /* move cursor instead of scrolling when already at start/end of list */
5947 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5949 else if (dy == +1 * SCROLL_LINE &&
5950 first_entry + num_page_entries == max_setup_info)
5953 /* handle scrolling screen one line or page */
5955 y + dy > num_page_entries - 1)
5957 boolean redraw = FALSE;
5959 if (ABS(dy) == SCROLL_PAGE)
5960 step = num_page_entries - 1;
5962 if (dy < 0 && first_entry > 0)
5964 /* scroll page/line up */
5966 first_entry -= step;
5967 if (first_entry < 0)
5972 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5974 /* scroll page/line down */
5976 first_entry += step;
5977 if (first_entry + num_page_entries > max_setup_info)
5978 first_entry = MAX(0, max_setup_info - num_page_entries);
5985 choice += first_entry - first_entry_store[setup_mode];
5987 if (choice < first_entry)
5989 choice = first_entry;
5991 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5994 else if (choice > first_entry + num_page_entries - 1)
5996 choice = first_entry + num_page_entries - 1;
5998 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6002 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6006 if (choice < first_entry ||
6007 choice > first_entry + num_page_entries - 1)
6008 first_entry += SIGN(dy);
6012 // printf("::: MARK 1: %d\n", first_entry);
6014 first_entry_store[setup_mode] = first_entry;
6015 choice_store[setup_mode] = choice;
6017 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6019 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6021 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6022 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6030 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
6032 if (setup_info[choice].type & menu_navigation_type ||
6033 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
6034 setup_info[choice].type & TYPE_YES_NO_AUTO)
6035 button = MB_MENU_CHOICE;
6045 /* jump to next non-empty menu entry (up or down) */
6047 while (first_entry + y > 0 &&
6048 first_entry + y < max_setup_info - 1 &&
6049 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6052 while (y > 0 && y < num_setup_info - 1 &&
6053 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6057 if (!IN_VIS_FIELD(x, y))
6059 choice += y - y_old;
6061 if (choice < first_entry)
6062 first_entry = choice;
6063 else if (choice > first_entry + num_page_entries - 1)
6064 first_entry = choice - num_page_entries + 1;
6066 first_entry += y - y_old;
6069 if (first_entry >= 0 &&
6070 first_entry + num_page_entries <= max_setup_info)
6072 first_entry_store[setup_mode] = first_entry;
6074 if (choice < first_entry)
6075 choice = first_entry;
6076 else if (choice > first_entry + num_page_entries - 1)
6077 choice = first_entry + num_page_entries - 1;
6079 choice_store[setup_mode] = choice;
6081 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6083 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6085 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6086 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6094 if (!anyScrollbarGadgetActive() &&
6095 IN_VIS_FIELD(x, y) &&
6096 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
6097 y >= 0 && y < num_page_entries)
6099 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
6103 printf("::: TEST/HandleSetupScreen_Generic [%d, %d, %d, %d]\n", Counter(),
6104 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
6110 if (first_entry + y != choice &&
6111 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
6113 PlaySound(SND_MENU_ITEM_ACTIVATING);
6115 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
6116 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
6118 choice = choice_store[setup_mode] = first_entry + y;
6121 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
6123 PlaySound(SND_MENU_ITEM_ACTIVATING);
6125 DrawCursorAndText_Setup(choice, -1, FALSE);
6126 DrawCursorAndText_Setup(y, -1, TRUE);
6128 choice = choice_store[setup_mode] = y;
6133 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
6135 PlaySound(SND_MENU_ITEM_SELECTING);
6137 /* when selecting key headline, execute function for key value change */
6138 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
6139 setup_info[first_entry + y + 1].type & TYPE_KEY)
6142 /* when selecting string value, execute function for list selection */
6143 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
6144 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
6147 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
6149 void (*menu_callback_function)(void) =
6150 setup_info[first_entry + y].value;
6152 FadeSetFromType(setup_info[first_entry + y].type);
6154 menu_callback_function();
6158 if (setup_info[first_entry + y].type & TYPE_VALUE)
6159 changeSetupValue(y, first_entry + y, dx);
6163 else if (!(setup_info[y].type & TYPE_GHOSTED))
6165 PlaySound(SND_MENU_ITEM_SELECTING);
6167 /* when selecting key headline, execute function for key value change */
6168 if (setup_info[y].type & TYPE_KEYTEXT &&
6169 setup_info[y + 1].type & TYPE_KEY)
6172 /* when selecting string value, execute function for list selection */
6173 if (setup_info[y].type & TYPE_STRING && y > 0 &&
6174 setup_info[y - 1].type & TYPE_ENTER_LIST)
6177 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
6179 void (*menu_callback_function)(void) = setup_info[y].value;
6181 FadeSetFromType(setup_info[y].type);
6183 menu_callback_function();
6187 if (setup_info[y].type & TYPE_VALUE)
6188 changeSetupValue(y, dx);
6195 void DrawSetupScreen_Input()
6200 FadeOut(REDRAW_FIELD);
6206 setup_info = setup_info_input;
6209 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
6213 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6214 "Joysticks deactivated on this screen");
6216 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6217 "Joysticks deactivated on this screen");
6222 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6224 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6227 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6228 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6229 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6230 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6231 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6232 initCursor(i, IMG_MENU_BUTTON);
6234 DrawCursorAndText_Setup(i, -1, FALSE);
6238 DeactivateJoystickForCalibration();
6243 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6244 "Joysticks deactivated on this screen");
6246 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6247 "Joysticks deactivated on this screen");
6251 /* create gadgets for setup input menu screen */
6252 FreeScreenGadgets();
6253 CreateScreenGadgets();
6255 /* map gadgets for setup input menu screen */
6256 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6258 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6261 FadeIn(REDRAW_FIELD);
6267 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6269 if (device_name == NULL)
6272 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6275 if (strlen(device_name) > 1)
6277 char c1 = device_name[strlen(device_name) - 1];
6278 char c2 = device_name[strlen(device_name) - 2];
6280 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6281 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6284 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6285 strlen(device_name));
6288 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6291 static struct SetupKeyboardInfo custom_key;
6298 { &custom_key.left, "Joystick Left" },
6299 { &custom_key.right, "Joystick Right" },
6300 { &custom_key.up, "Joystick Up" },
6301 { &custom_key.down, "Joystick Down" },
6302 { &custom_key.snap, "Button 1" },
6303 { &custom_key.drop, "Button 2" }
6305 static char *joystick_name[MAX_PLAYERS] =
6312 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6316 custom_key = setup.input[player_nr].key;
6318 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6319 FONT_INPUT_1_ACTIVE);
6321 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6323 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6324 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6326 if (setup.input[player_nr].use_joystick)
6328 char *device_name = setup.input[player_nr].joy.device_name;
6329 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6330 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6332 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6333 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6337 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6338 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6341 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6343 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6344 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6345 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6346 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6348 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6349 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6350 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6351 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6352 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6353 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6355 for (i = 0; i < 6; i++)
6357 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6359 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6361 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6362 (setup.input[player_nr].use_joystick ?
6364 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6368 static int input_player_nr = 0;
6370 void HandleSetupScreen_Input_Player(int step, int direction)
6372 int old_player_nr = input_player_nr;
6375 new_player_nr = old_player_nr + step * direction;
6376 if (new_player_nr < 0)
6378 if (new_player_nr > MAX_PLAYERS - 1)
6379 new_player_nr = MAX_PLAYERS - 1;
6381 if (new_player_nr != old_player_nr)
6383 input_player_nr = new_player_nr;
6385 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6389 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6391 static int choice = 0;
6394 int pos_start = SETUPINPUT_SCREEN_POS_START;
6395 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6396 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6397 int pos_end = SETUPINPUT_SCREEN_POS_END;
6399 if (button == MB_MENU_INITIALIZE)
6401 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6403 DrawCursorAndText_Setup(choice, -1, TRUE);
6407 else if (button == MB_MENU_LEAVE)
6409 setup_mode = SETUP_MODE_MAIN;
6416 if (mx || my) /* mouse input */
6418 x = (mx - mSX) / 32;
6419 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6421 else if (dx || dy) /* keyboard input */
6423 if (dx && choice == 0)
6424 x = (dx < 0 ? 10 : 12);
6425 else if ((dx && choice == 1) ||
6426 (dx == +1 && choice == 2) ||
6427 (dx == -1 && choice == pos_end))
6428 button = MB_MENU_CHOICE;
6432 if (y >= pos_empty1 && y <= pos_empty2)
6433 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6436 if (y == 0 && dx != 0 && button)
6438 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6440 else if (IN_VIS_FIELD(x, y) &&
6441 y >= pos_start && y <= pos_end &&
6442 !(y >= pos_empty1 && y <= pos_empty2))
6448 DrawCursorAndText_Setup(choice, -1, FALSE);
6449 DrawCursorAndText_Setup(y, -1, TRUE);
6451 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6460 char *device_name = setup.input[input_player_nr].joy.device_name;
6462 if (!setup.input[input_player_nr].use_joystick)
6464 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6466 setJoystickDeviceToNr(device_name, new_device_nr);
6467 setup.input[input_player_nr].use_joystick = TRUE;
6471 int device_nr = getJoystickNrFromDeviceName(device_name);
6472 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6474 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6475 setup.input[input_player_nr].use_joystick = FALSE;
6477 setJoystickDeviceToNr(device_name, new_device_nr);
6480 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6484 if (setup.input[input_player_nr].use_joystick)
6487 CalibrateJoystick(input_player_nr);
6490 CustomizeKeyboard(input_player_nr);
6492 else if (y == pos_end)
6498 setup_mode = SETUP_MODE_MAIN;
6505 void CustomizeKeyboard(int player_nr)
6509 boolean finished = FALSE;
6510 static struct SetupKeyboardInfo custom_key;
6515 } customize_step[] =
6517 { &custom_key.left, "Move Left" },
6518 { &custom_key.right, "Move Right" },
6519 { &custom_key.up, "Move Up" },
6520 { &custom_key.down, "Move Down" },
6521 { &custom_key.snap, "Snap Field" },
6522 { &custom_key.drop, "Drop Element" }
6525 /* read existing key bindings from player setup */
6526 custom_key = setup.input[player_nr].key;
6529 FadeOut(REDRAW_FIELD);
6533 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6541 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6542 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6543 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6544 "Key:", FONT_INPUT_1_ACTIVE);
6545 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6546 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6549 FadeIn(REDRAW_FIELD);
6556 if (PendingEvent()) /* got event */
6564 case EVENT_KEYPRESS:
6566 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6568 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6570 if (key == KSYM_Escape)
6571 FadeSkipNextFadeIn();
6577 /* all keys configured -- wait for "Escape" or "Return" key */
6581 /* press 'Enter' to keep the existing key binding */
6582 if (key == KSYM_Return)
6583 key = *customize_step[step_nr].key;
6585 /* check if key already used */
6586 for (i = 0; i < step_nr; i++)
6587 if (*customize_step[i].key == key)
6592 /* got new key binding */
6593 *customize_step[step_nr].key = key;
6594 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6596 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6597 getKeyNameFromKey(key), FONT_VALUE_1);
6600 /* un-highlight last query */
6601 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6602 customize_step[step_nr - 1].text, FONT_MENU_1);
6603 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6604 "Key:", FONT_MENU_1);
6606 /* press 'Enter' to leave */
6609 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6610 "Press Enter", FONT_TITLE_1);
6614 /* query next key binding */
6615 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6616 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6617 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6618 "Key:", FONT_INPUT_1_ACTIVE);
6619 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6620 getKeyNameFromKey(*customize_step[step_nr].key),
6625 case EVENT_KEYRELEASE:
6626 key_joystick_mapping = 0;
6630 HandleOtherEvents(&event);
6638 /* don't eat all CPU time */
6642 /* write new key bindings back to player setup */
6643 setup.input[player_nr].key = custom_key;
6646 DrawSetupScreen_Input();
6649 static boolean CalibrateJoystickMain(int player_nr)
6651 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6652 int new_joystick_xright = JOYSTICK_XMIDDLE;
6653 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6654 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6655 int new_joystick_xmiddle, new_joystick_ymiddle;
6657 int joystick_fd = joystick.fd[player_nr];
6658 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6659 boolean check[3][3];
6660 int check_remaining = 3 * 3;
6665 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6668 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6672 FadeOut(REDRAW_FIELD);
6676 for (y = 0; y < 3; y++)
6678 for (x = 0; x < 3; x++)
6680 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6681 check[x][y] = FALSE;
6685 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6686 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6687 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6688 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6689 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6690 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6691 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6693 joy_value = Joystick(player_nr);
6694 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6695 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6697 /* eventually uncalibrated center position (joystick could be uncentered) */
6698 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6701 new_joystick_xmiddle = joy_x;
6702 new_joystick_ymiddle = joy_y;
6704 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6706 FadeIn(REDRAW_FIELD);
6708 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6713 if (PendingEvent()) /* got event */
6721 case EVENT_KEYPRESS:
6722 switch (GetEventKey((KeyEvent *)&event, TRUE))
6725 if (check_remaining == 0)
6730 FadeSkipNextFadeIn();
6739 case EVENT_KEYRELEASE:
6740 key_joystick_mapping = 0;
6744 HandleOtherEvents(&event);
6749 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6752 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6753 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6754 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6755 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6757 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6758 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6759 setup.input[player_nr].joy.xright = new_joystick_xright;
6760 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6761 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6762 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6764 CheckJoystickData();
6766 joy_value = Joystick(player_nr);
6768 if (joy_value & JOY_BUTTON && check_remaining == 0)
6771 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6772 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6774 if (x != last_x || y != last_y)
6776 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6777 IMG_MENU_CALIBRATE_YELLOW, 0);
6778 DrawFixedGraphic(xpos + x, ypos + y,
6779 IMG_MENU_CALIBRATE_RED, 0);
6784 if (check_remaining > 0 && !check[x+1][y+1])
6786 check[x+1][y+1] = TRUE;
6792 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
6793 setup.input[player_nr].joy.xleft,
6794 setup.input[player_nr].joy.xmiddle,
6795 setup.input[player_nr].joy.xright);
6796 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
6797 setup.input[player_nr].joy.yupper,
6798 setup.input[player_nr].joy.ymiddle,
6799 setup.input[player_nr].joy.ylower);
6808 /* don't eat all CPU time */
6812 /* calibrated center position (joystick should now be centered) */
6813 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6816 new_joystick_xmiddle = joy_x;
6817 new_joystick_ymiddle = joy_y;
6822 DrawSetupScreen_Input();
6825 /* wait until the last pressed button was released */
6826 while (Joystick(player_nr) & JOY_BUTTON)
6828 if (PendingEvent()) /* got event */
6833 HandleOtherEvents(&event);
6842 void CalibrateJoystick(int player_nr)
6844 if (!CalibrateJoystickMain(player_nr))
6846 char *device_name = setup.input[player_nr].joy.device_name;
6847 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6848 int xpos = mSX - SX;
6849 int ypos = mSY - SY;
6853 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6854 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6857 Delay(2000); /* show error message for a short time */
6863 DrawSetupScreen_Input();
6867 void DrawSetupScreen()
6869 DeactivateJoystick();
6871 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6873 if (setup_mode == SETUP_MODE_INPUT)
6874 DrawSetupScreen_Input();
6875 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6876 DrawChooseTree(&game_speed_current);
6877 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6878 DrawChooseTree(&scroll_delay_current);
6879 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6880 DrawChooseTree(&screen_mode_current);
6881 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6882 DrawChooseTree(&window_size_current);
6883 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6884 DrawChooseTree(&scaling_type_current);
6885 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6886 DrawChooseTree(&artwork.gfx_current);
6887 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6888 DrawChooseTree(&artwork.snd_current);
6889 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6890 DrawChooseTree(&artwork.mus_current);
6891 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6892 DrawChooseTree(&volume_simple_current);
6893 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6894 DrawChooseTree(&volume_loops_current);
6895 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6896 DrawChooseTree(&volume_music_current);
6898 DrawSetupScreen_Generic();
6904 void RedrawSetupScreenAfterFullscreenToggle()
6907 if (setup_mode == SETUP_MODE_GRAPHICS ||
6908 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6910 // update list selection from "setup.window_scaling_percent"
6911 execSetupGraphics_setWindowSizes(TRUE);
6916 if (setup_mode == SETUP_MODE_GRAPHICS)
6921 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6923 if (setup_mode == SETUP_MODE_INPUT)
6924 HandleSetupScreen_Input(mx, my, dx, dy, button);
6925 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6926 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6927 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6928 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6929 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6930 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6931 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6932 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6933 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6934 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6935 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6936 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6937 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6938 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6939 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6940 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6941 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6942 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6943 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6944 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6945 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6946 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6948 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6955 void HandleGameActions()
6957 if (game_status != GAME_MODE_PLAYING)
6960 GameActions(); /* main game loop */
6962 if (tape.auto_play && !tape.playing)
6963 AutoPlayTape(); /* continue automatically playing next tape */
6967 /* ---------- new screen button stuff -------------------------------------- */
6969 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6974 case SCREEN_CTRL_ID_PREV_LEVEL:
6975 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6976 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6979 case SCREEN_CTRL_ID_NEXT_LEVEL:
6980 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6981 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6984 case SCREEN_CTRL_ID_PREV_LEVEL:
6985 *x = mSX + TILEX * getPrevlevelButtonPos();
6986 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6989 case SCREEN_CTRL_ID_NEXT_LEVEL:
6990 *x = mSX + TILEX * getNextLevelButtonPos();
6991 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
6995 case SCREEN_CTRL_ID_PREV_PLAYER:
6996 *x = mSX + TILEX * 10;
6997 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7000 case SCREEN_CTRL_ID_NEXT_PLAYER:
7001 *x = mSX + TILEX * 12;
7002 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7006 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7012 int gfx_unpressed, gfx_pressed;
7013 void (*get_gadget_position)(int *, int *, int);
7017 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7020 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7021 getScreenMenuButtonPos,
7022 SCREEN_CTRL_ID_PREV_LEVEL,
7027 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7028 getScreenMenuButtonPos,
7029 SCREEN_CTRL_ID_NEXT_LEVEL,
7034 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7035 getScreenMenuButtonPos,
7036 SCREEN_CTRL_ID_PREV_PLAYER,
7041 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7042 getScreenMenuButtonPos,
7043 SCREEN_CTRL_ID_NEXT_PLAYER,
7051 int gfx_unpressed, gfx_pressed;
7055 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7058 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7060 -1, -1, /* these values are not constant, but can change at runtime */
7062 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
7064 SCREEN_CTRL_ID_SCROLL_UP,
7068 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7070 -1, -1, /* these values are not constant, but can change at runtime */
7072 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
7074 SCREEN_CTRL_ID_SCROLL_DOWN,
7081 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7082 Bitmap **gfx_unpressed, **gfx_pressed;
7084 int gfx_unpressed, gfx_pressed;
7091 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7094 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7095 &scrollbar_bitmap[0], &scrollbar_bitmap[1],
7097 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7100 -1, -1, /* these values are not constant, but can change at runtime */
7101 -1, -1, /* these values are not constant, but can change at runtime */
7103 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
7104 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
7106 GD_TYPE_SCROLLBAR_VERTICAL,
7107 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7108 "scroll level series vertically"
7112 static void CreateScreenMenubuttons()
7114 struct GadgetInfo *gi;
7115 unsigned int event_mask;
7118 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7120 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7121 int gfx_unpressed, gfx_pressed;
7122 int x, y, width, height;
7123 int gd_x1, gd_x2, gd_y1, gd_y2;
7124 int id = menubutton_info[i].gadget_id;
7126 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7128 menubutton_info[i].get_gadget_position(&x, &y, id);
7130 width = SC_MENUBUTTON_XSIZE;
7131 height = SC_MENUBUTTON_YSIZE;
7133 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7134 gfx_pressed = menubutton_info[i].gfx_pressed;
7135 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7136 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7137 gd_x1 = graphic_info[gfx_unpressed].src_x;
7138 gd_y1 = graphic_info[gfx_unpressed].src_y;
7139 gd_x2 = graphic_info[gfx_pressed].src_x;
7140 gd_y2 = graphic_info[gfx_pressed].src_y;
7142 gi = CreateGadget(GDI_CUSTOM_ID, id,
7143 GDI_CUSTOM_TYPE_ID, i,
7144 GDI_INFO_TEXT, menubutton_info[i].infotext,
7149 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7150 GDI_STATE, GD_BUTTON_UNPRESSED,
7151 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7152 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7153 GDI_DIRECT_DRAW, FALSE,
7154 GDI_EVENT_MASK, event_mask,
7155 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7159 Error(ERR_EXIT, "cannot create gadget");
7161 screen_gadget[id] = gi;
7165 static void CreateScreenScrollbuttons()
7167 struct GadgetInfo *gi;
7168 unsigned int event_mask;
7171 /* these values are not constant, but can change at runtime */
7172 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7173 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7174 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7175 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7177 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7179 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7180 int gfx_unpressed, gfx_pressed;
7181 int x, y, width, height;
7182 int gd_x1, gd_x2, gd_y1, gd_y2;
7183 int id = scrollbutton_info[i].gadget_id;
7185 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7187 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7188 y = mSY + scrollbutton_info[i].y;
7189 width = SC_SCROLLBUTTON_XSIZE;
7190 height = SC_SCROLLBUTTON_YSIZE;
7192 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7193 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7194 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7196 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7197 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7198 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7199 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7200 gd_x1 = graphic_info[gfx_unpressed].src_x;
7201 gd_y1 = graphic_info[gfx_unpressed].src_y;
7202 gd_x2 = graphic_info[gfx_pressed].src_x;
7203 gd_y2 = graphic_info[gfx_pressed].src_y;
7205 gi = CreateGadget(GDI_CUSTOM_ID, id,
7206 GDI_CUSTOM_TYPE_ID, i,
7207 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7212 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7213 GDI_STATE, GD_BUTTON_UNPRESSED,
7214 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7215 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7216 GDI_DIRECT_DRAW, FALSE,
7217 GDI_EVENT_MASK, event_mask,
7218 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7222 Error(ERR_EXIT, "cannot create gadget");
7224 screen_gadget[id] = gi;
7228 static void CreateScreenScrollbars()
7232 /* these values are not constant, but can change at runtime */
7233 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7234 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7235 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7236 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7238 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7240 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7241 #if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7242 int gfx_unpressed, gfx_pressed;
7244 int x, y, width, height;
7245 int gd_x1, gd_x2, gd_y1, gd_y2;
7246 struct GadgetInfo *gi;
7247 int items_max, items_visible, item_position;
7248 unsigned int event_mask;
7249 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7250 int id = scrollbar_info[i].gadget_id;
7252 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7254 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7255 y = mSY + scrollbar_info[i].y;
7256 width = scrollbar_info[i].width;
7257 height = scrollbar_info[i].height;
7259 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7260 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7262 items_max = num_page_entries;
7263 items_visible = num_page_entries;
7266 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7267 gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed;
7268 gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed;
7274 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7275 gfx_pressed = scrollbar_info[i].gfx_pressed;
7276 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7277 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7278 gd_x1 = graphic_info[gfx_unpressed].src_x;
7279 gd_y1 = graphic_info[gfx_unpressed].src_y;
7280 gd_x2 = graphic_info[gfx_pressed].src_x;
7281 gd_y2 = graphic_info[gfx_pressed].src_y;
7284 gi = CreateGadget(GDI_CUSTOM_ID, id,
7285 GDI_CUSTOM_TYPE_ID, i,
7286 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7291 GDI_TYPE, scrollbar_info[i].type,
7292 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7293 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7294 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7296 GDI_WHEEL_AREA_X, SX,
7297 GDI_WHEEL_AREA_Y, SY,
7298 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7299 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7301 GDI_WHEEL_AREA_X, 0,
7302 GDI_WHEEL_AREA_Y, 0,
7303 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
7304 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
7306 GDI_STATE, GD_BUTTON_UNPRESSED,
7307 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7308 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7309 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7310 GDI_DIRECT_DRAW, FALSE,
7311 GDI_EVENT_MASK, event_mask,
7312 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7316 Error(ERR_EXIT, "cannot create gadget");
7318 screen_gadget[id] = gi;
7322 void CreateScreenGadgets()
7324 int last_game_status = game_status; /* save current game status */
7326 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7329 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
7331 scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH);
7333 /* copy pointers to clip mask and GC */
7334 scrollbar_bitmap[i]->clip_mask =
7335 graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask;
7336 scrollbar_bitmap[i]->stored_clip_gc =
7337 graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc;
7339 BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap,
7340 scrollbar_bitmap[i],
7341 graphic_info[IMG_MENU_SCROLLBAR + i].src_x,
7342 graphic_info[IMG_MENU_SCROLLBAR + i].src_y,
7343 TILEX, TILEY, 0, 0);
7347 CreateScreenMenubuttons();
7350 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
7351 game_status = GAME_MODE_LEVELS;
7354 CreateScreenScrollbuttons();
7355 CreateScreenScrollbars();
7357 game_status = last_game_status; /* restore current game status */
7360 void FreeScreenGadgets()
7364 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
7365 for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++)
7367 /* prevent freeing clip mask and GC twice */
7368 scrollbar_bitmap[i]->clip_mask = None;
7369 scrollbar_bitmap[i]->stored_clip_gc = None;
7371 FreeBitmap(scrollbar_bitmap[i]);
7375 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7376 FreeGadget(screen_gadget[i]);
7379 void MapScreenMenuGadgets(int screen_mask)
7383 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7384 if (screen_mask & menubutton_info[i].screen_mask)
7385 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7388 void MapScreenGadgets(int num_entries)
7392 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7395 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7396 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7398 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7399 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7402 void MapScreenTreeGadgets(TreeInfo *ti)
7405 MapScreenGadgets(numTreeInfoInGroup(ti));
7407 int num_entries = numTreeInfoInGroup(ti);
7410 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7413 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7414 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7416 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7417 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7421 static void HandleScreenGadgets(struct GadgetInfo *gi)
7423 int id = gi->custom_id;
7424 int button = gi->event.button;
7425 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7429 case SCREEN_CTRL_ID_PREV_LEVEL:
7430 HandleMainMenu_SelectLevel(step, -1);
7433 case SCREEN_CTRL_ID_NEXT_LEVEL:
7434 HandleMainMenu_SelectLevel(step, +1);
7437 case SCREEN_CTRL_ID_PREV_PLAYER:
7438 HandleSetupScreen_Input_Player(step, -1);
7441 case SCREEN_CTRL_ID_NEXT_PLAYER:
7442 HandleSetupScreen_Input_Player(step, +1);
7445 case SCREEN_CTRL_ID_SCROLL_UP:
7446 if (game_status == GAME_MODE_LEVELS)
7447 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7448 else if (game_status == GAME_MODE_LEVELNR)
7449 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7450 else if (game_status == GAME_MODE_SETUP)
7451 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7454 case SCREEN_CTRL_ID_SCROLL_DOWN:
7455 if (game_status == GAME_MODE_LEVELS)
7456 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7457 else if (game_status == GAME_MODE_LEVELNR)
7458 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7459 else if (game_status == GAME_MODE_SETUP)
7460 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7463 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7464 if (game_status == GAME_MODE_LEVELS)
7465 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7466 else if (game_status == GAME_MODE_LEVELNR)
7467 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7468 else if (game_status == GAME_MODE_SETUP)
7469 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);