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_TOUCH 7
51 #define SETUP_MODE_SHORTCUTS 8
52 #define SETUP_MODE_SHORTCUTS_1 9
53 #define SETUP_MODE_SHORTCUTS_2 10
54 #define SETUP_MODE_SHORTCUTS_3 11
55 #define SETUP_MODE_SHORTCUTS_4 12
56 #define SETUP_MODE_SHORTCUTS_5 13
58 /* sub-screens on the setup screen (generic) */
59 #define SETUP_MODE_CHOOSE_ARTWORK 14
60 #define SETUP_MODE_CHOOSE_OTHER 15
62 /* sub-screens on the setup screen (specific) */
63 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
64 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
65 #define SETUP_MODE_CHOOSE_SCREEN_MODE 18
66 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
67 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
68 #define SETUP_MODE_CHOOSE_GRAPHICS 21
69 #define SETUP_MODE_CHOOSE_SOUNDS 22
70 #define SETUP_MODE_CHOOSE_MUSIC 23
71 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 24
72 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 25
73 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 26
74 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 27
75 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 28
76 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 29
78 #define MAX_SETUP_MODES 30
80 /* for input setup functions */
81 #define SETUPINPUT_SCREEN_POS_START 0
82 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
83 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
84 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
86 /* for various menu stuff */
87 #define MENU_SCREEN_START_XPOS 1
88 #define MENU_SCREEN_START_YPOS 2
90 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
91 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
93 #define MENU_SCREEN_VALUE_XPOS 14
94 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
96 #define MENU_TITLE1_YPOS 8
97 #define MENU_TITLE2_YPOS 46
98 #define MENU_SCREEN_INFO_XSTART 16
99 #define MENU_SCREEN_INFO_YSTART1 100
100 #define MENU_SCREEN_INFO_YSTART2 128
101 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
102 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
103 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
104 MENU_SCREEN_INFO_YSTART2 - \
106 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
108 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
109 MENU_SCREEN_INFO_YSTEP, \
110 MAX_INFO_ELEMENTS_ON_SCREEN)
112 #define NUM_INFO_ELEMENTS_ON_SCREEN 10
114 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
116 #define MAX_MENU_TEXT_LENGTH_BIG 13
117 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
119 #define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \
120 MENU_SCREEN_START_XPOS)
121 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
124 /* buttons and scrollbars identifiers */
125 #define SCREEN_CTRL_ID_PREV_LEVEL 0
126 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
127 #define SCREEN_CTRL_ID_PREV_PLAYER 2
128 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
129 #define SCREEN_CTRL_ID_SCROLL_UP 4
130 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
131 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
133 #define NUM_SCREEN_GADGETS 7
135 #define NUM_SCREEN_MENUBUTTONS 4
136 #define NUM_SCREEN_SCROLLBUTTONS 2
137 #define NUM_SCREEN_SCROLLBARS 1
139 #define SCREEN_MASK_MAIN (1 << 0)
140 #define SCREEN_MASK_INPUT (1 << 1)
142 /* graphic position and size values for buttons and scrollbars */
143 #define SC_MENUBUTTON_XSIZE TILEX
144 #define SC_MENUBUTTON_YSIZE TILEY
146 #define SC_SCROLLBUTTON_XSIZE TILEX
147 #define SC_SCROLLBUTTON_YSIZE TILEY
149 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
151 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
152 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
153 SC_SCROLLBUTTON_YSIZE)
155 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
156 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
158 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
159 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
160 SC_SCROLLBUTTON_YSIZE)
162 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
163 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
164 SC_SCROLL_VERTICAL_YSIZE)
166 #define SC_BORDER_SIZE 14
169 /* forward declarations of internal functions */
170 static void HandleScreenGadgets(struct GadgetInfo *);
171 static void HandleSetupScreen_Generic(int, int, int, int, int);
172 static void HandleSetupScreen_Input(int, int, int, int, int);
173 static void CustomizeKeyboard(int);
174 static void CalibrateJoystick(int);
175 static void execSetupGame(void);
176 static void execSetupGraphics(void);
177 static void execSetupSound(void);
178 static void execSetupTouch(void);
179 static void execSetupArtwork(void);
180 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
182 static void DrawChooseLevelSet(void);
183 static void DrawChooseLevelNr(void);
184 static void DrawInfoScreen(void);
185 static void DrawAndFadeInInfoScreen(int);
186 static void DrawSetupScreen(void);
188 static void DrawInfoScreenExt(int, int);
189 static void DrawInfoScreen_NotAvailable(char *, char *);
190 static void DrawInfoScreen_HelpAnim(int, int, boolean);
191 static void DrawInfoScreen_HelpText(int, int, int, int);
192 static void HandleInfoScreen_Main(int, int, int, int, int);
193 static void HandleInfoScreen_TitleScreen(int);
194 static void HandleInfoScreen_Elements(int);
195 static void HandleInfoScreen_Music(int);
196 static void HandleInfoScreen_Credits(int);
197 static void HandleInfoScreen_Program(int);
198 static void HandleInfoScreen_Version(int);
200 static void MapScreenMenuGadgets(int);
201 static void MapScreenGadgets(int);
202 static void MapScreenTreeGadgets(TreeInfo *);
204 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
206 static int info_mode = INFO_MODE_MAIN;
207 static int setup_mode = SETUP_MODE_MAIN;
209 static TreeInfo *screen_modes = NULL;
210 static TreeInfo *screen_mode_current = NULL;
212 static TreeInfo *window_sizes = NULL;
213 static TreeInfo *window_size_current = NULL;
215 static TreeInfo *scaling_types = NULL;
216 static TreeInfo *scaling_type_current = NULL;
218 static TreeInfo *scroll_delays = NULL;
219 static TreeInfo *scroll_delay_current = NULL;
221 static TreeInfo *game_speeds = NULL;
222 static TreeInfo *game_speed_current = NULL;
224 static TreeInfo *volumes_simple = NULL;
225 static TreeInfo *volume_simple_current = NULL;
227 static TreeInfo *volumes_loops = NULL;
228 static TreeInfo *volume_loops_current = NULL;
230 static TreeInfo *volumes_music = NULL;
231 static TreeInfo *volume_music_current = NULL;
233 static TreeInfo *touch_controls = NULL;
234 static TreeInfo *touch_control_current = NULL;
236 static TreeInfo *move_distances = NULL;
237 static TreeInfo *move_distance_current = NULL;
239 static TreeInfo *drop_distances = NULL;
240 static TreeInfo *drop_distance_current = NULL;
242 static TreeInfo *level_number = NULL;
243 static TreeInfo *level_number_current = NULL;
249 } window_sizes_list[] =
254 { 100, "100 % (Default)" },
271 } scaling_types_list[] =
273 { SCALING_QUALITY_NEAREST, "None" },
274 { SCALING_QUALITY_LINEAR, "Linear" },
275 { SCALING_QUALITY_BEST, "Anisotropic" },
284 } game_speeds_list[] =
293 { 1000, "1/1s (Extremely Slow)" },
298 { 29, "1/35s (Original Supaplex)" },
300 { 20, "1/50s (Normal Speed)" },
301 { 14, "1/70s (Maximum Supaplex)" },
305 { 1, "1/1000s (Extremely Fast)" },
315 } scroll_delays_list[] =
317 { 0, "0 Tiles (No Scroll Delay)" },
320 { 3, "3 Tiles (Default)" },
325 { 8, "8 Tiles (Maximum Scroll Delay)"},
355 } touch_controls_list[] =
357 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
358 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
382 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
383 (s) <= GAME_MODE_SETUP ? (s) : \
384 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
385 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
387 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
388 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
389 (i) <= INFO_MODE_LEVELSET ? (i) : \
392 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
393 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
394 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
395 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
396 SETUP_MODE_CHOOSE_ARTWORK : \
397 SETUP_MODE_CHOOSE_OTHER)
399 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
400 menu.draw_xoffset[GAME_MODE_INFO] : \
401 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
402 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
403 menu.draw_yoffset[GAME_MODE_INFO] : \
404 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
406 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
407 menu.draw_xoffset[GAME_MODE_SETUP] : \
408 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
409 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
410 menu.draw_yoffset[GAME_MODE_SETUP] : \
411 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
413 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
414 DRAW_XOFFSET_INFO(info_mode) : \
415 (s) == GAME_MODE_SETUP ? \
416 DRAW_XOFFSET_SETUP(setup_mode) : \
417 menu.draw_xoffset[DRAW_MODE(s)])
418 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
419 DRAW_YOFFSET_INFO(info_mode) : \
420 (s) == GAME_MODE_SETUP ? \
421 DRAW_YOFFSET_SETUP(setup_mode) : \
422 menu.draw_yoffset[DRAW_MODE(s)])
424 #define mSX (SX + DRAW_XOFFSET(game_status))
425 #define mSY (SY + DRAW_YOFFSET(game_status))
427 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
428 menu.list_size[game_status] : \
429 MAX_MENU_ENTRIES_ON_SCREEN)
432 /* title display and control definitions */
434 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
435 2 * MAX_NUM_TITLE_MESSAGES)
437 static int num_title_screens = 0;
439 struct TitleControlInfo
447 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
449 /* main menu display and control definitions */
451 #define MAIN_CONTROL_NAME 0
452 #define MAIN_CONTROL_LEVELS 1
453 #define MAIN_CONTROL_SCORES 2
454 #define MAIN_CONTROL_EDITOR 3
455 #define MAIN_CONTROL_INFO 4
456 #define MAIN_CONTROL_GAME 5
457 #define MAIN_CONTROL_SETUP 6
458 #define MAIN_CONTROL_QUIT 7
459 #define MAIN_CONTROL_PREV_LEVEL 8
460 #define MAIN_CONTROL_NEXT_LEVEL 9
461 #define MAIN_CONTROL_FIRST_LEVEL 10
462 #define MAIN_CONTROL_LAST_LEVEL 11
463 #define MAIN_CONTROL_LEVEL_NUMBER 12
464 #define MAIN_CONTROL_LEVEL_INFO_1 13
465 #define MAIN_CONTROL_LEVEL_INFO_2 14
466 #define MAIN_CONTROL_LEVEL_NAME 15
467 #define MAIN_CONTROL_LEVEL_AUTHOR 16
468 #define MAIN_CONTROL_LEVEL_YEAR 17
469 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
470 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
471 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
472 #define MAIN_CONTROL_TITLE_1 21
473 #define MAIN_CONTROL_TITLE_2 22
474 #define MAIN_CONTROL_TITLE_3 23
476 static char str_main_text_name[10];
477 static char str_main_text_first_level[10];
478 static char str_main_text_last_level[10];
479 static char str_main_text_level_number[10];
481 static char *main_text_name = str_main_text_name;
482 static char *main_text_first_level = str_main_text_first_level;
483 static char *main_text_last_level = str_main_text_last_level;
484 static char *main_text_level_number = str_main_text_level_number;
485 static char *main_text_levels = "Levelset";
486 static char *main_text_scores = "Hall Of Fame";
487 static char *main_text_editor = "Level Creator";
488 static char *main_text_info = "Info Screen";
489 static char *main_text_game = "Start Game";
490 static char *main_text_setup = "Setup";
491 static char *main_text_quit = "Quit";
492 static char *main_text_level_name = level.name;
493 static char *main_text_level_author = level.author;
494 static char *main_text_level_year = NULL;
495 static char *main_text_level_imported_from = NULL;
496 static char *main_text_level_imported_by = NULL;
497 static char *main_text_level_tested_by = NULL;
498 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
499 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
500 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
502 struct MainControlInfo
506 struct MenuPosInfo *pos_button;
509 struct TextPosInfo *pos_text;
512 struct TextPosInfo *pos_input;
516 static struct MainControlInfo main_controls[] =
520 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
521 &menu.main.text.name, &main_text_name,
522 &menu.main.input.name, &setup.player_name,
526 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
527 &menu.main.text.levels, &main_text_levels,
532 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
533 &menu.main.text.scores, &main_text_scores,
538 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
539 &menu.main.text.editor, &main_text_editor,
544 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
545 &menu.main.text.info, &main_text_info,
550 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
551 &menu.main.text.game, &main_text_game,
556 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
557 &menu.main.text.setup, &main_text_setup,
562 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
563 &menu.main.text.quit, &main_text_quit,
567 /* (these two buttons are real gadgets) */
569 MAIN_CONTROL_PREV_LEVEL,
570 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
575 MAIN_CONTROL_NEXT_LEVEL,
576 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
582 MAIN_CONTROL_FIRST_LEVEL,
584 &menu.main.text.first_level, &main_text_first_level,
588 MAIN_CONTROL_LAST_LEVEL,
590 &menu.main.text.last_level, &main_text_last_level,
594 MAIN_CONTROL_LEVEL_NUMBER,
596 &menu.main.text.level_number, &main_text_level_number,
600 MAIN_CONTROL_LEVEL_INFO_1,
602 &menu.main.text.level_info_1, NULL,
606 MAIN_CONTROL_LEVEL_INFO_2,
608 &menu.main.text.level_info_2, NULL,
612 MAIN_CONTROL_LEVEL_NAME,
614 &menu.main.text.level_name, &main_text_level_name,
618 MAIN_CONTROL_LEVEL_AUTHOR,
620 &menu.main.text.level_author, &main_text_level_author,
624 MAIN_CONTROL_LEVEL_YEAR,
626 &menu.main.text.level_year, &main_text_level_year,
630 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
632 &menu.main.text.level_imported_from, &main_text_level_imported_from,
636 MAIN_CONTROL_LEVEL_IMPORTED_BY,
638 &menu.main.text.level_imported_by, &main_text_level_imported_by,
642 MAIN_CONTROL_LEVEL_TESTED_BY,
644 &menu.main.text.level_tested_by, &main_text_level_tested_by,
648 MAIN_CONTROL_TITLE_1,
650 &menu.main.text.title_1, &main_text_title_1,
654 MAIN_CONTROL_TITLE_2,
656 &menu.main.text.title_2, &main_text_title_2,
660 MAIN_CONTROL_TITLE_3,
662 &menu.main.text.title_3, &main_text_title_3,
675 static int getTitleScreenGraphic(int nr, boolean initial)
677 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
680 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
682 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
686 static int getTitleScreenGameMode(boolean initial)
688 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
692 static int getTitleMessageGameMode(boolean initial)
694 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
698 static int getTitleScreenBackground(boolean initial)
700 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
705 static int getTitleMessageBackground(int nr, boolean initial)
707 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
711 static int getTitleBackground(int nr, boolean initial, boolean is_image)
713 int base = (is_image ?
714 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
715 IMG_BACKGROUND_TITLESCREEN_1) :
716 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
717 IMG_BACKGROUND_TITLEMESSAGE_1));
718 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
719 IMG_BACKGROUND_TITLE);
720 int graphic_local = base + nr;
722 if (graphic_info[graphic_local].bitmap != NULL)
723 return graphic_local;
725 if (graphic_info[graphic_global].bitmap != NULL)
726 return graphic_global;
728 return IMG_UNDEFINED;
731 static int getTitleSound(struct TitleControlInfo *tci)
733 boolean is_image = tci->is_image;
734 int initial = tci->initial;
735 int nr = tci->local_nr;
736 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
737 int base = (is_image ?
738 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
739 SND_BACKGROUND_TITLESCREEN_1) :
740 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
741 SND_BACKGROUND_TITLEMESSAGE_1));
742 int sound_global = menu.sound[mode];
743 int sound_local = base + nr;
746 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
747 nr, initial, is_image,
748 sound_global, getSoundListEntry(sound_global)->filename,
749 sound_local, getSoundListEntry(sound_local)->filename);
752 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
755 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
758 return SND_UNDEFINED;
761 static int getTitleMusic(struct TitleControlInfo *tci)
763 boolean is_image = tci->is_image;
764 int initial = tci->initial;
765 int nr = tci->local_nr;
766 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
767 int base = (is_image ?
768 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
769 MUS_BACKGROUND_TITLESCREEN_1) :
770 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
771 MUS_BACKGROUND_TITLEMESSAGE_1));
772 int music_global = menu.music[mode];
773 int music_local = base + nr;
776 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
777 nr, initial, is_image,
778 music_global, getMusicListEntry(music_global)->filename,
779 music_local, getMusicListEntry(music_local)->filename);
782 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
785 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
788 return MUS_UNDEFINED;
791 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
793 boolean is_image = tci->is_image;
794 int initial = tci->initial;
795 int nr = tci->local_nr;
796 struct TitleFadingInfo ti;
800 int graphic = getTitleScreenGraphic(nr, initial);
802 /* initialize fading control values to default title config settings */
803 ti = (initial ? title_initial_default : title_default);
805 /* override default settings with image config settings, if defined */
806 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
807 ti.fade_mode = graphic_info[graphic].fade_mode;
808 if (graphic_info[graphic].fade_delay > -1)
809 ti.fade_delay = graphic_info[graphic].fade_delay;
810 if (graphic_info[graphic].post_delay > -1)
811 ti.post_delay = graphic_info[graphic].post_delay;
812 if (graphic_info[graphic].auto_delay > -1)
813 ti.auto_delay = graphic_info[graphic].auto_delay;
819 ti.fade_mode = titlemessage_initial[nr].fade_mode;
820 ti.fade_delay = titlemessage_initial[nr].fade_delay;
821 ti.post_delay = titlemessage_initial[nr].post_delay;
822 ti.auto_delay = titlemessage_initial[nr].auto_delay;
826 ti.fade_mode = titlemessage[nr].fade_mode;
827 ti.fade_delay = titlemessage[nr].fade_delay;
828 ti.post_delay = titlemessage[nr].post_delay;
829 ti.auto_delay = titlemessage[nr].auto_delay;
834 if (ti.anim_mode == ANIM_NONE)
835 ti.fade_delay = ti.post_delay = 0;
841 static int compareTitleControlInfo(const void *object1, const void *object2)
843 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
844 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
847 if (tci1->initial != tci2->initial)
848 compare_result = (tci1->initial ? -1 : +1);
849 else if (tci1->sort_priority != tci2->sort_priority)
850 compare_result = tci1->sort_priority - tci2->sort_priority;
851 else if (tci1->is_image != tci2->is_image)
852 compare_result = (tci1->is_image ? -1 : +1);
854 compare_result = tci1->local_nr - tci2->local_nr;
856 return compare_result;
859 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
861 int nr, int sort_priority)
863 title_controls[num_title_screens].is_image = is_image;
864 title_controls[num_title_screens].initial = initial;
865 title_controls[num_title_screens].local_nr = nr;
866 title_controls[num_title_screens].sort_priority = sort_priority;
871 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
875 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
877 int graphic = getTitleScreenGraphic(i, initial);
878 Bitmap *bitmap = graphic_info[graphic].bitmap;
879 int sort_priority = graphic_info[graphic].sort_priority;
882 /* skip images and messages (fonts!) when using forced custom graphics */
883 if (setup.override_level_graphics && !initial)
888 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
891 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
893 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
894 char *filename = getLevelSetTitleMessageFilename(i, initial);
895 int sort_priority = tmi->sort_priority;
898 /* skip images and messages (fonts!) when using forced custom graphics */
899 if (setup.override_level_graphics)
903 if (filename != NULL)
904 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
908 static void InitializeTitleControls(boolean show_title_initial)
910 num_title_screens = 0;
913 /* 1st step: initialize title screens for game start (only when starting) */
914 if (show_title_initial)
915 InitializeTitleControls_CheckTitleInfo(TRUE);
918 /* 2nd step: initialize title screens for current level set */
919 InitializeTitleControls_CheckTitleInfo(FALSE);
921 /* sort title screens according to sort_priority and title number */
922 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
923 compareTitleControlInfo);
926 static boolean visibleMenuPos(struct MenuPosInfo *pos)
928 return (pos != NULL && pos->x != -1 && pos->y != -1);
931 static boolean visibleTextPos(struct TextPosInfo *pos)
933 return (pos != NULL && pos->x != -1 && pos->y != -1);
936 static void InitializeMainControls()
938 boolean local_team_mode = (!options.network && setup.team_mode);
941 /* set main control text values to dynamically determined values */
942 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
944 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
945 menu.main.text.first_level.size));
946 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
947 menu.main.text.last_level.size));
948 strcpy(main_text_level_number, int2str(level_nr,
949 menu.main.text.level_number.size));
951 main_text_level_year = leveldir_current->year;
952 main_text_level_imported_from = leveldir_current->imported_from;
953 main_text_level_imported_by = leveldir_current->imported_by;
954 main_text_level_tested_by = leveldir_current->tested_by;
956 /* set main control screen positions to dynamically determined values */
957 for (i = 0; main_controls[i].nr != -1; i++)
959 struct MainControlInfo *mci = &main_controls[i];
961 struct MenuPosInfo *pos_button = mci->pos_button;
962 struct TextPosInfo *pos_text = mci->pos_text;
963 struct TextPosInfo *pos_input = mci->pos_input;
964 char *text = (mci->text ? *mci->text : NULL);
965 char *input = (mci->input ? *mci->input : NULL);
966 int button_graphic = mci->button_graphic;
968 int font_text = (pos_text ? pos_text->font : -1);
969 int font_input = (pos_input ? pos_input->font : -1);
971 int font_text = mci->font_text;
972 int font_input = mci->font_input;
975 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
976 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
977 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
978 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
979 int text_chars = (text != NULL ? strlen(text) : 0);
980 int input_chars = (input != NULL ? strlen(input) : 0);
983 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
985 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
986 int text_width = font_text_width * text_chars;
987 int text_height = font_text_height;
988 int input_width = font_input_width * input_chars;
989 int input_height = font_input_height;
991 if (nr == MAIN_CONTROL_NAME)
994 if (menu.main.input.name.x == -1)
995 menu.main.input.name.x = menu.main.text.name.x + text_width;
996 if (menu.main.input.name.y == -1)
997 menu.main.input.name.y = menu.main.text.name.y;
1001 menu.main.input.name.width = input_width;
1002 menu.main.input.name.height = input_height;
1004 menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
1005 menu.main.input.name.height = font_input_height;
1009 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1011 if (pos_button->width == 0)
1012 pos_button->width = button_width;
1013 if (pos_button->height == 0)
1014 pos_button->height = button_height;
1017 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1020 /* calculate size for non-clickable text -- needed for text alignment */
1021 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1023 /* calculate width for non-clickable text -- needed for text alignment */
1024 boolean calculate_text_width = (pos_button == NULL && text != NULL);
1027 if (visibleMenuPos(pos_button))
1029 if (pos_text->x == -1)
1030 pos_text->x = pos_button->x + pos_button->width;
1031 if (pos_text->y == -1)
1032 pos_text->y = pos_button->y;
1036 if (pos_text->width == -1 || calculate_text_size)
1037 pos_text->width = text_width;
1038 if (pos_text->height == -1 || calculate_text_size)
1039 pos_text->height = text_height;
1041 if (pos_text->width == -1 || calculate_text_width)
1042 pos_text->width = text_width;
1043 if (pos_text->height == -1)
1044 pos_text->height = text_height;
1048 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1050 if (visibleTextPos(pos_text))
1052 if (pos_input->x == -1)
1053 pos_input->x = pos_text->x + pos_text->width;
1054 if (pos_input->y == -1)
1055 pos_input->y = pos_text->y;
1058 if (pos_input->width == -1)
1059 pos_input->width = input_width;
1060 if (pos_input->height == -1)
1061 pos_input->height = input_height;
1066 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1067 boolean active_input)
1071 for (i = 0; main_controls[i].nr != -1; i++)
1073 struct MainControlInfo *mci = &main_controls[i];
1075 if (mci->nr == nr || nr == -1)
1077 struct MenuPosInfo *pos_button = mci->pos_button;
1078 struct TextPosInfo *pos_text = mci->pos_text;
1079 struct TextPosInfo *pos_input = mci->pos_input;
1080 char *text = (mci->text ? *mci->text : NULL);
1081 char *input = (mci->input ? *mci->input : NULL);
1082 int button_graphic = mci->button_graphic;
1084 int font_text = (pos_text ? pos_text->font : -1);
1085 int font_input = (pos_input ? pos_input->font : -1);
1087 int font_text = mci->font_text;
1088 int font_input = mci->font_input;
1093 button_graphic = BUTTON_ACTIVE(button_graphic);
1094 font_text = FONT_ACTIVE(font_text);
1099 font_input = FONT_ACTIVE(font_input);
1102 if (visibleMenuPos(pos_button))
1104 struct MenuPosInfo *pos = pos_button;
1105 int x = mSX + pos->x;
1106 int y = mSY + pos->y;
1108 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1109 DrawFixedGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
1112 if (visibleTextPos(pos_text) && text != NULL)
1114 struct TextPosInfo *pos = pos_text;
1115 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1116 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1119 /* (check why/if this is needed) */
1120 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1122 DrawText(x, y, text, font_text);
1125 if (visibleTextPos(pos_input) && input != NULL)
1127 struct TextPosInfo *pos = pos_input;
1128 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1129 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1132 /* (check why/if this is needed) */
1133 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1135 DrawText(x, y, input, font_input);
1141 static void DrawCursorAndText_Main(int nr, boolean active_text)
1143 DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
1147 static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
1149 DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
1153 static struct MainControlInfo *getMainControlInfo(int nr)
1157 for (i = 0; main_controls[i].nr != -1; i++)
1158 if (main_controls[i].nr == nr)
1159 return &main_controls[i];
1164 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1169 int rect_x = ALIGNED_TEXT_XPOS(rect);
1170 int rect_y = ALIGNED_TEXT_YPOS(rect);
1172 return (x >= rect_x && x < rect_x + rect->width &&
1173 y >= rect_y && y < rect_y + rect->height);
1176 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1181 int rect_x = ALIGNED_TEXT_XPOS(rect);
1182 int rect_y = ALIGNED_TEXT_YPOS(rect);
1185 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1186 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1187 (x >= rect_x && x < rect_x + rect->width &&
1188 y >= rect_y && y < rect_y + rect->height));
1191 return (x >= rect_x && x < rect_x + rect->width &&
1192 y >= rect_y && y < rect_y + rect->height);
1195 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1198 static int cursor_array[MAX_LEV_FIELDY];
1200 static int cursor_array[SCR_FIELDY];
1202 int x = mSX + TILEX * xpos;
1203 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1208 cursor_array[ypos] = graphic;
1210 graphic = cursor_array[ypos];
1214 graphic = BUTTON_ACTIVE(graphic);
1216 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1217 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1220 static void initCursor(int ypos, int graphic)
1222 drawCursorExt(0, ypos, FALSE, graphic);
1225 static void drawCursor(int ypos, boolean active)
1227 drawCursorExt(0, ypos, active, -1);
1230 static void drawCursorXY(int xpos, int ypos, int graphic)
1232 drawCursorExt(xpos, ypos, FALSE, graphic);
1235 static void drawChooseTreeCursor(int ypos, boolean active)
1237 int last_game_status = game_status; /* save current game status */
1240 /* force LEVELS draw offset on artwork setup screen */
1241 game_status = GAME_MODE_LEVELS;
1244 drawCursorExt(0, ypos, active, -1);
1246 game_status = last_game_status; /* restore current game status */
1251 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1252 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1256 static int getPrevlevelButtonPos()
1261 static int getCurrentLevelTextPos()
1263 return (getPrevlevelButtonPos() + 1);
1266 static int getNextLevelButtonPos()
1268 return getPrevlevelButtonPos() + 3 + 1;
1271 static int getLevelRangeTextPos()
1273 return getNextLevelButtonPos() + 1;
1277 int effectiveGameStatus()
1279 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1280 return GAME_MODE_TITLE;
1285 void DrawTitleScreenImage(int nr, boolean initial)
1287 int graphic = getTitleScreenGraphic(nr, initial);
1288 Bitmap *bitmap = graphic_info[graphic].bitmap;
1289 int width = graphic_info[graphic].width;
1290 int height = graphic_info[graphic].height;
1291 int src_x = graphic_info[graphic].src_x;
1292 int src_y = graphic_info[graphic].src_y;
1298 if (width > WIN_XSIZE)
1300 /* image width too large for window => center image horizontally */
1301 src_x = (width - WIN_XSIZE) / 2;
1305 if (height > WIN_YSIZE)
1307 /* image height too large for window => center image vertically */
1308 src_y = (height - WIN_YSIZE) / 2;
1312 /* always display title screens centered */
1313 dst_x = (WIN_XSIZE - width) / 2;
1314 dst_y = (WIN_YSIZE - height) / 2;
1316 SetDrawBackgroundMask(REDRAW_ALL);
1317 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1319 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1321 if (DrawingOnBackground(dst_x, dst_y))
1323 SetClipOrigin(bitmap, bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y);
1324 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1327 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1329 redraw_mask = REDRAW_ALL;
1332 void DrawTitleScreenMessage(int nr, boolean initial)
1334 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1335 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1336 int last_game_status = game_status; /* save current game status */
1338 if (filename == NULL)
1341 /* force TITLE font on title message screen */
1342 game_status = getTitleMessageGameMode(initial);
1344 /* if chars set to "-1", automatically determine by text and font width */
1345 if (tmi->chars == -1)
1346 tmi->chars = tmi->width / getFontWidth(tmi->font);
1348 tmi->width = tmi->chars * getFontWidth(tmi->font);
1350 /* if lines set to "-1", automatically determine by text and font height */
1351 if (tmi->lines == -1)
1352 tmi->lines = tmi->height / getFontHeight(tmi->font);
1354 tmi->height = tmi->lines * getFontHeight(tmi->font);
1356 SetDrawBackgroundMask(REDRAW_ALL);
1357 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1359 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1361 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1362 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1363 tmi->autowrap, tmi->centered, tmi->parse_comments);
1365 game_status = last_game_status; /* restore current game status */
1368 void DrawTitleScreen()
1370 KeyboardAutoRepeatOff();
1373 SetMainBackgroundImage(IMG_BACKGROUND_TITLE);
1376 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1381 boolean CheckTitleScreen(boolean levelset_has_changed)
1383 static boolean show_title_initial = TRUE;
1384 boolean show_titlescreen = FALSE;
1386 /* needed to be able to skip title screen, if no image or message defined */
1387 InitializeTitleControls(show_title_initial);
1389 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1390 show_titlescreen = TRUE;
1392 /* show initial title images and messages only once at program start */
1393 show_title_initial = FALSE;
1395 return (show_titlescreen && num_title_screens > 0);
1398 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1400 static LevelDirTree *leveldir_last_valid = NULL;
1401 boolean levelset_has_changed = FALSE;
1403 LimitScreenUpdates(FALSE);
1405 FadeSetLeaveScreen();
1407 /* do not fade out here -- function may continue and fade on editor screen */
1410 FadeSoundsAndMusic();
1412 KeyboardAutoRepeatOn();
1415 SetDrawDeactivationMask(REDRAW_NONE);
1416 SetDrawBackgroundMask(REDRAW_FIELD);
1418 audio.sound_deactivated = FALSE;
1422 /* needed if last screen was the playing screen, invoked from level editor */
1423 if (level_editor_test_game)
1425 game_status = GAME_MODE_EDITOR;
1431 /* needed if last screen was the setup screen and fullscreen state changed */
1432 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1433 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1435 /* leveldir_current may be invalid (level group, parent link) */
1436 if (!validLevelSeries(leveldir_current))
1437 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1439 if (leveldir_current != leveldir_last_valid)
1440 levelset_has_changed = TRUE;
1442 /* store valid level series information */
1443 leveldir_last_valid = leveldir_current;
1445 init_last = init; /* switch to new busy animation */
1447 /* needed if last screen (level choice) changed graphics, sounds or music */
1448 ReloadCustomArtwork(0);
1450 if (redraw_mask & REDRAW_ALL)
1451 fade_mask = REDRAW_ALL;
1457 /* needed if last screen was the editor screen */
1458 UndrawSpecialEditorDoor();
1462 if (fade_mask == REDRAW_FIELD)
1468 /* needed if different viewport properties defined for menues */
1469 ChangeViewportPropertiesIfNeeded();
1473 /* needed if last screen was the editor screen */
1474 UndrawSpecialEditorDoor();
1477 #if defined(TARGET_SDL)
1478 SetDrawtoField(DRAW_BACKBUFFER);
1481 if (CheckTitleScreen(levelset_has_changed))
1483 game_status = GAME_MODE_TITLE;
1490 /* level_nr may have been set to value over handicap with level editor */
1491 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1492 level_nr = leveldir_current->handicap_level;
1494 LoadLevel(level_nr);
1495 LoadScore(level_nr);
1497 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1500 if (fade_mask == REDRAW_ALL)
1502 // int door_state = GetDoorState();
1506 // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1512 InitializeMainControls();
1514 DrawCursorAndText_Main(-1, FALSE);
1515 DrawPreviewLevelInitial();
1517 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1520 if (TAPE_IS_EMPTY(tape))
1522 DrawCompleteVideoDisplay();
1527 /* create gadgets for main menu screen */
1528 FreeScreenGadgets();
1529 CreateScreenGadgets();
1531 /* map gadgets for main menu screen */
1533 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1536 /* copy actual game door content to door double buffer for OpenDoor() */
1537 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1541 // if (fade_mask == REDRAW_ALL)
1542 // (always redraw current door state)
1544 int door_state = GetDoorState();
1546 // RedrawBackground();
1548 OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1553 redraw_mask |= REDRAW_ALL;
1558 DrawMaskedBorder(REDRAW_ALL);
1564 /* update screen area with special editor door */
1565 redraw_mask |= REDRAW_ALL;
1569 SetMouseCursor(CURSOR_DEFAULT);
1573 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1576 void DrawAndFadeInMainMenu(int fade_mask)
1578 DrawMainMenuExt(fade_mask, TRUE);
1583 DrawMainMenuExt(REDRAW_ALL, FALSE);
1586 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1587 static void gotoTopLevelDir()
1589 /* move upwards to top level directory */
1590 while (leveldir_current->node_parent)
1592 /* write a "path" into level tree for easy navigation to last level */
1593 if (leveldir_current->node_parent->node_group->cl_first == -1)
1595 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1596 int leveldir_pos = posTreeInfo(leveldir_current);
1597 int num_page_entries;
1598 int cl_first, cl_cursor;
1600 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1601 num_page_entries = num_leveldirs;
1603 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1605 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1606 cl_cursor = leveldir_pos - cl_first;
1608 leveldir_current->node_parent->node_group->cl_first = cl_first;
1609 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1612 leveldir_current = leveldir_current->node_parent;
1617 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1619 static unsigned int title_delay = 0;
1620 static int title_screen_nr = 0;
1621 static int last_sound = -1, last_music = -1;
1622 boolean return_to_main_menu = FALSE;
1623 boolean use_fading_main_menu = TRUE;
1624 struct TitleControlInfo *tci;
1625 struct TitleFadingInfo fading_default;
1626 struct TitleFadingInfo fading_last = fading;
1627 struct TitleFadingInfo fading_next;
1630 if (button == MB_MENU_INITIALIZE)
1633 title_screen_nr = 0;
1634 tci = &title_controls[title_screen_nr];
1636 last_sound = SND_UNDEFINED;
1637 last_music = MUS_UNDEFINED;
1639 if (game_status == GAME_MODE_INFO)
1641 if (num_title_screens == 0)
1643 DrawInfoScreen_NotAvailable("Title screen information:",
1644 "No title screen for this level set.");
1649 FadeSoundsAndMusic();
1652 FadeOut(REDRAW_ALL);
1657 DrawTitleScreenImage(tci->local_nr, tci->initial);
1659 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1661 fading_default = (tci->initial ? title_initial_default : title_default);
1663 fading = fading_next = getTitleFading(tci);
1667 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1668 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1670 fading.fade_mode = FADE_MODE_FADE;
1671 fading.fade_delay = fading_default.fade_delay;
1674 if (fading_last.fade_mode != FADE_MODE_CROSSFADE &&
1675 fading_next.fade_mode == FADE_MODE_CROSSFADE)
1676 fading.fade_mode = FADE_MODE_FADE;
1681 sound = getTitleSound(tci);
1682 music = getTitleMusic(tci);
1684 if (sound != last_sound)
1685 PlayMenuSoundExt(sound);
1686 if (music != last_music)
1687 PlayMenuMusicExt(music);
1693 SetMouseCursor(CURSOR_NONE);
1699 fading = fading_next;
1701 DelayReached(&title_delay, 0); /* reset delay counter */
1707 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1708 button = MB_MENU_CHOICE;
1710 if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay))
1711 button = MB_MENU_CHOICE;
1714 if (button == MB_MENU_LEAVE)
1716 return_to_main_menu = TRUE;
1717 use_fading_main_menu = FALSE;
1719 else if (button == MB_MENU_CHOICE)
1721 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1724 FadeOut(REDRAW_FIELD);
1727 FadeSetEnterScreen();
1729 info_mode = INFO_MODE_MAIN;
1730 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1736 tci = &title_controls[title_screen_nr];
1738 if (title_screen_nr < num_title_screens)
1740 sound = getTitleSound(tci);
1741 music = getTitleMusic(tci);
1743 if (sound == SND_UNDEFINED || sound != last_sound)
1745 if (music == MUS_UNDEFINED || music != last_music)
1749 FadeOut(REDRAW_ALL);
1753 DrawTitleScreenImage(tci->local_nr, tci->initial);
1755 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1757 fading_next = getTitleFading(tci);
1760 sound = getTitleSound(tci);
1761 music = getTitleMusic(tci);
1763 if (sound != last_sound)
1764 PlayMenuSoundExt(sound);
1765 if (music != last_music)
1766 PlayMenuMusicExt(music);
1773 /* last screen already faded out, next screen has no animation */
1774 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1775 fading_next.fade_mode == FADE_MODE_NONE)
1776 fading = fading_next;
1778 /* last screen already faded out, next screen has no animation */
1779 if (fading.fade_mode != FADE_MODE_CROSSFADE &&
1780 fading_next.fade_mode == FADE_MODE_NONE)
1781 fading = fading_next;
1788 fading = fading_next;
1790 DelayReached(&title_delay, 0); /* reset delay counter */
1794 FadeSoundsAndMusic();
1796 return_to_main_menu = TRUE;
1800 if (return_to_main_menu)
1806 SetMouseCursor(CURSOR_DEFAULT);
1808 if (game_status == GAME_MODE_INFO)
1811 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1814 info_mode = INFO_MODE_MAIN;
1815 DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu);
1817 else /* default: return to main menu */
1820 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1823 game_status = GAME_MODE_MAIN;
1824 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1829 void HandleMainMenu_SelectLevel(int step, int direction)
1831 int old_level_nr = level_nr;
1834 new_level_nr = old_level_nr + step * direction;
1835 if (new_level_nr < leveldir_current->first_level)
1836 new_level_nr = leveldir_current->first_level;
1837 if (new_level_nr > leveldir_current->last_level)
1838 new_level_nr = leveldir_current->last_level;
1840 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1842 /* skipping levels is only allowed when trying to skip single level */
1843 if (setup.skip_levels && step == 1 &&
1844 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1846 leveldir_current->handicap_level++;
1847 SaveLevelSetup_SeriesInfo();
1850 new_level_nr = leveldir_current->handicap_level;
1853 if (new_level_nr != old_level_nr)
1855 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1857 PlaySound(SND_MENU_ITEM_SELECTING);
1859 level_nr = new_level_nr;
1861 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1862 int2str(level_nr, menu.main.text.level_number.size),
1863 mci->pos_text->font);
1865 LoadLevel(level_nr);
1866 DrawPreviewLevelInitial();
1870 DrawCompleteVideoDisplay();
1872 /* needed because DrawPreviewLevelInitial() takes some time */
1878 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1880 static int choice = MAIN_CONTROL_GAME;
1884 if (button == MB_MENU_INITIALIZE)
1886 DrawCursorAndText_Main(choice, TRUE);
1891 if (mx || my) /* mouse input */
1895 for (i = 0; main_controls[i].nr != -1; i++)
1898 printf("::: check click (%d, %d) for %d [%d] ...\n",
1899 mx - mSX, my - mSY, i, main_controls[i].nr);
1902 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1903 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1904 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1907 printf("::: inside %d\n", i);
1910 pos = main_controls[i].nr;
1916 else if (dx || dy) /* keyboard input */
1918 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1919 choice == MAIN_CONTROL_SETUP))
1920 button = MB_MENU_CHOICE;
1925 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1927 HandleMainMenu_SelectLevel(1, dx < 0 ? -1 : +1);
1929 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1931 HandleMainMenu_SelectLevel(MAX_LEVELS, -1);
1933 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1935 HandleMainMenu_SelectLevel(MAX_LEVELS, +1);
1937 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1939 game_status = GAME_MODE_LEVELNR;
1942 ChangeViewportPropertiesIfNeeded();
1945 DrawChooseLevelNr();
1947 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1953 PlaySound(SND_MENU_ITEM_ACTIVATING);
1955 DrawCursorAndText_Main(choice, FALSE);
1956 DrawCursorAndText_Main(pos, TRUE);
1963 PlaySound(SND_MENU_ITEM_SELECTING);
1965 if (pos == MAIN_CONTROL_NAME)
1967 game_status = GAME_MODE_PSEUDO_TYPENAME;
1969 HandleTypeName(strlen(setup.player_name), 0);
1971 else if (pos == MAIN_CONTROL_LEVELS)
1975 game_status = GAME_MODE_LEVELS;
1977 SaveLevelSetup_LastSeries();
1978 SaveLevelSetup_SeriesInfo();
1980 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1985 ChangeViewportPropertiesIfNeeded();
1988 DrawChooseLevelSet();
1991 else if (pos == MAIN_CONTROL_SCORES)
1993 game_status = GAME_MODE_SCORES;
1996 ChangeViewportPropertiesIfNeeded();
2001 else if (pos == MAIN_CONTROL_EDITOR)
2003 if (leveldir_current->readonly &&
2004 !strEqual(setup.player_name, "Artsoft"))
2005 Request("This level is read only!", REQ_CONFIRM);
2007 CloseDoor(DOOR_CLOSE_2);
2009 game_status = GAME_MODE_EDITOR;
2011 FadeSetEnterScreen();
2014 /* needed if different viewport properties defined for editor */
2015 ChangeViewportPropertiesIfNeeded();
2020 else if (pos == MAIN_CONTROL_INFO)
2022 game_status = GAME_MODE_INFO;
2023 info_mode = INFO_MODE_MAIN;
2026 ChangeViewportPropertiesIfNeeded();
2031 else if (pos == MAIN_CONTROL_GAME)
2033 StartGameActions(options.network, setup.autorecord, level.random_seed);
2035 else if (pos == MAIN_CONTROL_SETUP)
2037 game_status = GAME_MODE_SETUP;
2038 setup_mode = SETUP_MODE_MAIN;
2041 ChangeViewportPropertiesIfNeeded();
2046 else if (pos == MAIN_CONTROL_QUIT)
2048 SaveLevelSetup_LastSeries();
2049 SaveLevelSetup_SeriesInfo();
2051 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2052 game_status = GAME_MODE_QUIT;
2058 if (game_status == GAME_MODE_MAIN)
2060 DrawPreviewLevelAnimation();
2067 /* ========================================================================= */
2068 /* info screen functions */
2069 /* ========================================================================= */
2071 static struct TokenInfo *info_info;
2072 static int num_info_info;
2074 static void execInfoTitleScreen()
2076 info_mode = INFO_MODE_TITLE;
2081 static void execInfoElements()
2083 info_mode = INFO_MODE_ELEMENTS;
2088 static void execInfoMusic()
2090 info_mode = INFO_MODE_MUSIC;
2095 static void execInfoCredits()
2097 info_mode = INFO_MODE_CREDITS;
2102 static void execInfoProgram()
2104 info_mode = INFO_MODE_PROGRAM;
2109 static void execInfoVersion()
2111 info_mode = INFO_MODE_VERSION;
2116 static void execInfoLevelSet()
2118 info_mode = INFO_MODE_LEVELSET;
2123 static void execExitInfo()
2125 game_status = GAME_MODE_MAIN;
2127 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2130 static struct TokenInfo info_info_main[] =
2132 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2133 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2134 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2135 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2136 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2137 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2138 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2139 { TYPE_EMPTY, NULL, "" },
2140 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2145 static void DrawCursorAndText_Info(int pos, boolean active)
2147 int xpos = MENU_SCREEN_START_XPOS;
2148 int ypos = MENU_SCREEN_START_YPOS + pos;
2149 int font_nr = FONT_MENU_1;
2152 font_nr = FONT_ACTIVE(font_nr);
2154 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
2156 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
2157 drawCursor(pos, active);
2160 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2165 CloseDoor(DOOR_CLOSE_2);
2167 /* (needed after displaying title screens which disable auto repeat) */
2168 KeyboardAutoRepeatOn();
2170 FadeSetLeaveScreen();
2177 if (fade_mask == REDRAW_ALL)
2181 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2187 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2189 info_info = info_info_main;
2193 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2195 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2198 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2199 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2200 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2201 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2202 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2203 initCursor(i, IMG_MENU_BUTTON);
2205 DrawCursorAndText_Info(i, FALSE);
2210 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2215 DrawMaskedBorder(fade_mask);
2222 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2224 static int choice_store[MAX_INFO_MODES];
2225 int choice = choice_store[info_mode]; /* always starts with 0 */
2229 if (button == MB_MENU_INITIALIZE)
2231 /* advance to first valid menu entry */
2232 while (choice < num_info_info &&
2233 info_info[choice].type & TYPE_SKIP_ENTRY)
2235 choice_store[info_mode] = choice;
2237 DrawCursorAndText_Info(choice, TRUE);
2241 else if (button == MB_MENU_LEAVE)
2243 for (y = 0; y < num_info_info; y++)
2245 if (info_info[y].type & TYPE_LEAVE_MENU)
2247 void (*menu_callback_function)(void) = info_info[y].value;
2251 menu_callback_function();
2253 break; /* absolutely needed because function changes 'info_info'! */
2260 if (mx || my) /* mouse input */
2262 x = (mx - mSX) / 32;
2263 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2265 else if (dx || dy) /* keyboard input */
2269 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2271 if (info_info[choice].type & menu_navigation_type ||
2272 info_info[choice].type & TYPE_ENTER_SCREEN ||
2273 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2274 info_info[choice].type & TYPE_YES_NO_AUTO)
2275 button = MB_MENU_CHOICE;
2280 /* jump to next non-empty menu entry (up or down) */
2281 while (y > 0 && y < num_info_info - 1 &&
2282 info_info[y].type & TYPE_SKIP_ENTRY)
2286 if (IN_VIS_FIELD(x, y) &&
2287 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2293 PlaySound(SND_MENU_ITEM_ACTIVATING);
2295 DrawCursorAndText_Info(choice, FALSE);
2296 DrawCursorAndText_Info(y, TRUE);
2298 choice = choice_store[info_mode] = y;
2301 else if (!(info_info[y].type & TYPE_GHOSTED))
2303 PlaySound(SND_MENU_ITEM_SELECTING);
2305 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2307 void (*menu_callback_function)(void) = info_info[choice].value;
2309 FadeSetFromType(info_info[y].type);
2311 menu_callback_function();
2317 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2319 int ystart1 = mSY - SY + 100;
2320 int ystart2 = mSY - SY + 150;
2321 int ybottom = mSY - SY + SYSIZE - 20;
2323 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
2325 FadeOut(REDRAW_FIELD);
2330 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2331 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2333 DrawTextSCentered(ybottom, FONT_TEXT_4,
2334 "Press any key or button for info menu");
2336 FadeIn(REDRAW_FIELD);
2339 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2341 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2342 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2343 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2344 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2345 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2346 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2347 int ystep = MENU_SCREEN_INFO_YSTEP;
2348 int element, action, direction;
2356 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2357 infoscreen_step[i] = infoscreen_frame[i] = 0;
2362 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2364 DrawTextSCentered(ybottom, FONT_TEXT_4,
2365 "Press any key or button for next page");
2371 while (helpanim_info[j].element != HELPANIM_LIST_END)
2373 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2378 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2387 j += infoscreen_step[i - start];
2389 element = helpanim_info[j].element;
2390 action = helpanim_info[j].action;
2391 direction = helpanim_info[j].direction;
2394 element = EL_UNKNOWN;
2396 if (action != -1 && direction != -1)
2397 graphic = el_act_dir2img(element, action, direction);
2398 else if (action != -1)
2399 graphic = el_act2img(element, action);
2400 else if (direction != -1)
2401 graphic = el_dir2img(element, direction);
2403 graphic = el2img(element);
2405 delay = helpanim_info[j++].delay;
2410 if (infoscreen_frame[i - start] == 0)
2413 infoscreen_frame[i - start] = delay - 1;
2417 sync_frame = delay - infoscreen_frame[i - start];
2418 infoscreen_frame[i - start]--;
2421 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2423 if (!infoscreen_frame[i - start])
2424 infoscreen_step[i - start] = 0;
2428 if (!infoscreen_frame[i - start])
2429 infoscreen_step[i - start]++;
2430 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2436 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2438 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2439 graphic, sync_frame, USE_MASKING);
2442 DrawInfoScreen_HelpText(element, action, direction, i - start);
2447 redraw_mask |= REDRAW_FIELD;
2452 static char *getHelpText(int element, int action, int direction)
2454 char token[MAX_LINE_LEN];
2456 strcpy(token, element_info[element].token_name);
2459 strcat(token, element_action_info[action].suffix);
2461 if (direction != -1)
2462 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2464 return getHashEntry(helptext_info, token);
2467 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2469 int font_nr = FONT_INFO_ELEMENTS;
2470 int font_width = getFontWidth(font_nr);
2471 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2472 int sy = mSY + 65 + 2 * 32 + 1;
2473 int ystep = TILEY + 4;
2474 int pad_x = sx - SX;
2475 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2476 int max_lines_per_text = 2;
2479 if (action != -1 && direction != -1) /* element.action.direction */
2480 text = getHelpText(element, action, direction);
2482 if (text == NULL && action != -1) /* element.action */
2483 text = getHelpText(element, action, -1);
2485 if (text == NULL && direction != -1) /* element.direction */
2486 text = getHelpText(element, -1, direction);
2488 if (text == NULL) /* base element */
2489 text = getHelpText(element, -1, -1);
2491 if (text == NULL) /* not found */
2492 text = "No description available";
2494 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2495 sy += getFontHeight(font_nr) / 2;
2497 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2498 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2499 TRUE, FALSE, FALSE);
2502 void DrawInfoScreen_TitleScreen()
2507 void HandleInfoScreen_TitleScreen(int button)
2509 HandleTitleScreen(0, 0, 0, 0, button);
2512 void DrawInfoScreen_Elements()
2514 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2516 FadeOut(REDRAW_FIELD);
2521 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2523 FadeIn(REDRAW_FIELD);
2528 void HandleInfoScreen_Elements(int button)
2530 static unsigned int info_delay = 0;
2531 static int num_anims;
2532 static int num_pages;
2534 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2537 if (button == MB_MENU_INITIALIZE)
2539 boolean new_element = TRUE;
2543 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2545 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2547 else if (new_element)
2550 new_element = FALSE;
2554 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2558 if (button == MB_MENU_LEAVE)
2560 PlaySound(SND_MENU_ITEM_SELECTING);
2562 info_mode = INFO_MODE_MAIN;
2567 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2569 if (button != MB_MENU_INITIALIZE)
2571 PlaySound(SND_MENU_ITEM_SELECTING);
2576 if (page >= num_pages)
2578 FadeSoundsAndMusic();
2580 info_mode = INFO_MODE_MAIN;
2581 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2588 FadeSetNextScreen();
2591 if (button != MB_MENU_INITIALIZE)
2592 FadeOut(REDRAW_FIELD);
2594 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2596 if (button != MB_MENU_INITIALIZE)
2597 FadeIn(REDRAW_FIELD);
2601 if (DelayReached(&info_delay, GameFrameDelay))
2602 if (page < num_pages)
2603 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2605 PlayMenuSoundIfLoop();
2609 void DrawInfoScreen_Music()
2611 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2614 FadeOut(REDRAW_FIELD);
2622 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2625 FadeIn(REDRAW_FIELD);
2629 void HandleInfoScreen_Music(int button)
2631 static struct MusicFileInfo *list = NULL;
2632 int ystart1 = mSY - SY + 100;
2633 int ystart2 = mSY - SY + 150;
2634 int ybottom = mSY - SY + SYSIZE - 20;
2637 if (button == MB_MENU_INITIALIZE)
2639 list = music_file_info;
2643 FadeSoundsAndMusic();
2648 DrawTextSCentered(ystart1, FONT_TEXT_1,
2649 "No music info for this level set.");
2651 DrawTextSCentered(ybottom, FONT_TEXT_4,
2652 "Press any key or button for info menu");
2658 if (button == MB_MENU_LEAVE)
2660 PlaySound(SND_MENU_ITEM_SELECTING);
2662 FadeSoundsAndMusic();
2664 info_mode = INFO_MODE_MAIN;
2669 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2673 if (button != MB_MENU_INITIALIZE)
2675 PlaySound(SND_MENU_ITEM_SELECTING);
2683 FadeSoundsAndMusic();
2685 info_mode = INFO_MODE_MAIN;
2686 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2691 FadeSoundsAndMusic();
2694 if (list != music_file_info)
2695 FadeSetNextScreen();
2698 if (button != MB_MENU_INITIALIZE)
2699 FadeOut(REDRAW_FIELD);
2706 int sound = list->music;
2708 if (sound_info[sound].loop)
2709 PlaySoundLoop(sound);
2713 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2717 PlayMusic(list->music);
2719 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2722 if (!strEqual(list->title, UNKNOWN_NAME))
2724 if (!strEqual(list->title_header, UNKNOWN_NAME))
2725 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2727 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2730 if (!strEqual(list->artist, UNKNOWN_NAME))
2732 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2733 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2735 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2737 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2740 if (!strEqual(list->album, UNKNOWN_NAME))
2742 if (!strEqual(list->album_header, UNKNOWN_NAME))
2743 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2745 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2747 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2750 if (!strEqual(list->year, UNKNOWN_NAME))
2752 if (!strEqual(list->year_header, UNKNOWN_NAME))
2753 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2755 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2757 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2760 DrawTextSCentered(ybottom, FONT_TEXT_4,
2761 "Press any key or button for next page");
2763 if (button != MB_MENU_INITIALIZE)
2764 FadeIn(REDRAW_FIELD);
2767 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2768 PlaySoundLoop(list->music);
2771 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2773 int ystart1 = mSY - SY + 100;
2774 int ystart2 = mSY - SY + 150;
2775 int ybottom = mSY - SY + SYSIZE - 20;
2781 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2785 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2786 "Special thanks to");
2787 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2789 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2791 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2792 "\"Boulder Dash\"");
2793 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2795 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2797 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2799 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2800 "First Star Software");
2802 else if (screen_nr == 1)
2804 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2805 "Special thanks to");
2806 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2807 "Klaus Heinz & Volker Wertich");
2808 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2810 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2811 "\"Emerald Mine\"");
2812 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2814 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2816 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2818 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2821 else if (screen_nr == 2)
2823 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2824 "Special thanks to");
2825 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2826 "Michael Stopp & Philip Jespersen");
2827 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2829 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2831 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2833 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2835 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2837 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2838 "Digital Integration");
2840 else if (screen_nr == 3)
2842 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2843 "Special thanks to");
2844 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2845 "Hiroyuki Imabayashi");
2846 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2848 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2850 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2852 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2854 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2856 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2859 else if (screen_nr == 4)
2861 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2862 "Special thanks to");
2863 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2865 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2867 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2868 "Jürgen Bonhagen");
2869 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2870 "for the continuous creation");
2871 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2872 "of outstanding level sets");
2874 else if (screen_nr == 5)
2876 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2878 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2880 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2881 "for ideas and inspiration by");
2882 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2885 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2887 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2889 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2890 "for ideas and inspiration by");
2891 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2894 else if (screen_nr == 6)
2896 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2898 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2901 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2902 "for the code base used for the");
2903 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2904 "native Emerald Mine engine");
2906 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2907 "for the new Emerald Mine engine");
2910 else if (screen_nr == 7)
2912 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2914 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2916 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2917 "for the initial DOS port");
2919 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2921 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2923 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2924 "for some additional toons");
2926 else if (screen_nr == 8)
2928 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2929 "And not to forget:");
2930 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2932 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2933 "All those who contributed");
2934 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2935 "levels to this game");
2936 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2940 DrawTextSCentered(ybottom, FONT_TEXT_4,
2941 "Press any key or button for next page");
2944 void DrawInfoScreen_Credits()
2946 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2948 FadeSoundsAndMusic();
2951 FadeOut(REDRAW_FIELD);
2954 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2957 FadeIn(REDRAW_FIELD);
2961 void HandleInfoScreen_Credits(int button)
2963 static int screen_nr = 0;
2964 int num_screens = 9;
2966 if (button == MB_MENU_INITIALIZE)
2970 // DrawInfoScreen_CreditsScreen(screen_nr);
2973 if (button == MB_MENU_LEAVE)
2975 PlaySound(SND_MENU_ITEM_SELECTING);
2977 info_mode = INFO_MODE_MAIN;
2982 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2984 if (button != MB_MENU_INITIALIZE)
2986 PlaySound(SND_MENU_ITEM_SELECTING);
2991 if (screen_nr >= num_screens)
2993 FadeSoundsAndMusic();
2995 info_mode = INFO_MODE_MAIN;
2996 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3003 FadeSetNextScreen();
3006 if (button != MB_MENU_INITIALIZE)
3007 FadeOut(REDRAW_FIELD);
3009 DrawInfoScreen_CreditsScreen(screen_nr);
3011 if (button != MB_MENU_INITIALIZE)
3012 FadeIn(REDRAW_FIELD);
3016 PlayMenuSoundIfLoop();
3020 void DrawInfoScreen_Program()
3022 int ystart1 = mSY - SY + 100;
3023 int ystart2 = mSY - SY + 150;
3024 int ybottom = mSY - SY + SYSIZE - 20;
3027 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3030 FadeOut(REDRAW_FIELD);
3036 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3038 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3039 "This game is Freeware!");
3040 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3041 "If you like it, send e-mail to:");
3042 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3043 PROGRAM_EMAIL_STRING);
3045 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3046 "More information and levels:");
3047 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3048 PROGRAM_WEBSITE_STRING);
3049 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3050 "If you have created new levels,");
3051 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3052 "send them to me to include them!");
3053 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3056 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3057 "or SnailMail to:");
3058 DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
3060 DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3,
3061 "Detmolder Strasse 189");
3062 DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3,
3064 DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3,
3066 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3067 "More information and levels:");
3068 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3069 PROGRAM_WEBSITE_STRING);
3070 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3071 "If you have created new levels,");
3072 DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2,
3073 "send them to me to include them!");
3074 DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
3078 DrawTextSCentered(ybottom, FONT_TEXT_4,
3079 "Press any key or button for info menu");
3082 FadeIn(REDRAW_FIELD);
3086 void HandleInfoScreen_Program(int button)
3088 if (button == MB_MENU_LEAVE)
3090 PlaySound(SND_MENU_ITEM_SELECTING);
3092 info_mode = INFO_MODE_MAIN;
3097 else if (button == MB_MENU_CHOICE)
3099 PlaySound(SND_MENU_ITEM_SELECTING);
3101 FadeSoundsAndMusic();
3104 FadeOut(REDRAW_FIELD);
3107 info_mode = INFO_MODE_MAIN;
3108 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3112 PlayMenuSoundIfLoop();
3116 void DrawInfoScreen_Version()
3118 int font_header = FONT_TEXT_3;
3119 int font_text = FONT_TEXT_2;
3120 int xstep = getFontWidth(font_text);
3121 int ystep = getFontHeight(font_text);
3122 int ystart1 = mSY - SY + 100;
3123 int ystart2 = mSY - SY + 150;
3124 int ybottom = mSY - SY + SYSIZE - 20;
3125 int xstart1 = mSX - SX + 2 * xstep;
3126 int xstart2 = mSX - SX + 18 * xstep;
3127 #if defined(TARGET_SDL)
3128 int xstart3 = mSX - SX + 28 * xstep;
3129 SDL_version sdl_version_compiled;
3130 const SDL_version *sdl_version_linked;
3131 int driver_name_len = 10;
3132 #if defined(TARGET_SDL2)
3133 SDL_version sdl_version_linked_ext;
3134 const char *driver_name = NULL;
3136 char driver_name[driver_name_len];
3140 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3143 FadeOut(REDRAW_FIELD);
3149 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3151 DrawTextF(xstart1, ystart2, font_header, "Name");
3152 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
3155 DrawTextF(xstart1, ystart2, font_header, "Version");
3156 DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString());
3159 DrawTextF(xstart1, ystart2, font_header, "Platform");
3160 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3163 DrawTextF(xstart1, ystart2, font_header, "Target");
3164 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3167 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3168 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3170 #if defined(TARGET_SDL)
3171 ystart2 += 3 * ystep;
3172 DrawTextF(xstart1, ystart2, font_header, "Library");
3173 DrawTextF(xstart2, ystart2, font_header, "compiled");
3174 DrawTextF(xstart3, ystart2, font_header, "linked");
3176 SDL_VERSION(&sdl_version_compiled);
3177 #if defined(TARGET_SDL2)
3178 SDL_GetVersion(&sdl_version_linked_ext);
3179 sdl_version_linked = &sdl_version_linked_ext;
3181 sdl_version_linked = SDL_Linked_Version();
3184 ystart2 += 2 * ystep;
3185 DrawTextF(xstart1, ystart2, font_text, "SDL");
3186 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3187 sdl_version_compiled.major,
3188 sdl_version_compiled.minor,
3189 sdl_version_compiled.patch);
3190 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3191 sdl_version_linked->major,
3192 sdl_version_linked->minor,
3193 sdl_version_linked->patch);
3195 SDL_IMAGE_VERSION(&sdl_version_compiled);
3196 sdl_version_linked = IMG_Linked_Version();
3199 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3200 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3201 sdl_version_compiled.major,
3202 sdl_version_compiled.minor,
3203 sdl_version_compiled.patch);
3204 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3205 sdl_version_linked->major,
3206 sdl_version_linked->minor,
3207 sdl_version_linked->patch);
3209 SDL_MIXER_VERSION(&sdl_version_compiled);
3210 sdl_version_linked = Mix_Linked_Version();
3213 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3214 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3215 sdl_version_compiled.major,
3216 sdl_version_compiled.minor,
3217 sdl_version_compiled.patch);
3218 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3219 sdl_version_linked->major,
3220 sdl_version_linked->minor,
3221 sdl_version_linked->patch);
3223 SDL_NET_VERSION(&sdl_version_compiled);
3224 sdl_version_linked = SDLNet_Linked_Version();
3227 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3228 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3229 sdl_version_compiled.major,
3230 sdl_version_compiled.minor,
3231 sdl_version_compiled.patch);
3232 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3233 sdl_version_linked->major,
3234 sdl_version_linked->minor,
3235 sdl_version_linked->patch);
3237 ystart2 += 3 * ystep;
3238 DrawTextF(xstart1, ystart2, font_header, "Driver");
3239 DrawTextF(xstart2, ystart2, font_header, "Requested");
3240 DrawTextF(xstart3, ystart2, font_header, "Used");
3242 #if defined(TARGET_SDL2)
3243 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3245 SDL_VideoDriverName(driver_name, driver_name_len);
3248 ystart2 += 2 * ystep;
3249 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3250 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3251 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3253 #if defined(TARGET_SDL2)
3254 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3256 SDL_AudioDriverName(driver_name, driver_name_len);
3260 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3261 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3262 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3265 DrawTextSCentered(ybottom, FONT_TEXT_4,
3266 "Press any key or button for info menu");
3269 FadeIn(REDRAW_FIELD);
3273 void HandleInfoScreen_Version(int button)
3275 if (button == MB_MENU_LEAVE)
3277 PlaySound(SND_MENU_ITEM_SELECTING);
3279 info_mode = INFO_MODE_MAIN;
3284 else if (button == MB_MENU_CHOICE)
3286 PlaySound(SND_MENU_ITEM_SELECTING);
3288 FadeSoundsAndMusic();
3291 FadeOut(REDRAW_FIELD);
3294 info_mode = INFO_MODE_MAIN;
3295 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3299 PlayMenuSoundIfLoop();
3303 void DrawInfoScreen_LevelSet()
3305 struct TitleMessageInfo *tmi = &readme;
3306 char *filename = getLevelSetInfoFilename();
3308 /* if chars set to "-1", automatically determine by text and font width */
3309 if (tmi->chars == -1)
3310 tmi->chars = tmi->width / getFontWidth(tmi->font);
3312 tmi->width = tmi->chars * getFontWidth(tmi->font);
3314 /* if lines set to "-1", automatically determine by text and font height */
3315 if (tmi->lines == -1)
3316 tmi->lines = tmi->height / getFontHeight(tmi->font);
3318 tmi->height = tmi->lines * getFontHeight(tmi->font);
3320 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3323 FadeOut(REDRAW_FIELD);
3329 DrawTextCentered(mSY + 100, FONT_TEXT_1, "Level Set Information:");
3331 if (filename != NULL)
3332 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3333 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3334 tmi->autowrap, tmi->centered, tmi->parse_comments);
3336 DrawTextCentered(mSY + ALIGNED_TEXT_YPOS(tmi), FONT_TEXT_2,
3337 "No information for this level set.");
3339 DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4,
3340 "Press any key or button for info menu");
3343 FadeIn(REDRAW_FIELD);
3347 void HandleInfoScreen_LevelSet(int button)
3349 if (button == MB_MENU_LEAVE)
3351 PlaySound(SND_MENU_ITEM_SELECTING);
3353 info_mode = INFO_MODE_MAIN;
3358 else if (button == MB_MENU_CHOICE)
3360 PlaySound(SND_MENU_ITEM_SELECTING);
3362 FadeSoundsAndMusic();
3365 FadeOut(REDRAW_FIELD);
3368 info_mode = INFO_MODE_MAIN;
3369 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3373 PlayMenuSoundIfLoop();
3377 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3379 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3381 if (info_mode == INFO_MODE_TITLE)
3382 DrawInfoScreen_TitleScreen();
3383 else if (info_mode == INFO_MODE_ELEMENTS)
3384 DrawInfoScreen_Elements();
3385 else if (info_mode == INFO_MODE_MUSIC)
3386 DrawInfoScreen_Music();
3387 else if (info_mode == INFO_MODE_CREDITS)
3388 DrawInfoScreen_Credits();
3389 else if (info_mode == INFO_MODE_PROGRAM)
3390 DrawInfoScreen_Program();
3391 else if (info_mode == INFO_MODE_VERSION)
3392 DrawInfoScreen_Version();
3393 else if (info_mode == INFO_MODE_LEVELSET)
3394 DrawInfoScreen_LevelSet();
3396 DrawInfoScreen_Main(fade_mask, do_fading);
3398 if (info_mode != INFO_MODE_MAIN &&
3399 info_mode != INFO_MODE_TITLE &&
3400 info_mode != INFO_MODE_MUSIC)
3407 void DrawAndFadeInInfoScreen(int fade_mask)
3409 DrawInfoScreenExt(fade_mask, TRUE);
3412 void DrawInfoScreen()
3414 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3417 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3419 if (info_mode == INFO_MODE_TITLE)
3420 HandleInfoScreen_TitleScreen(button);
3421 else if (info_mode == INFO_MODE_ELEMENTS)
3422 HandleInfoScreen_Elements(button);
3423 else if (info_mode == INFO_MODE_MUSIC)
3424 HandleInfoScreen_Music(button);
3425 else if (info_mode == INFO_MODE_CREDITS)
3426 HandleInfoScreen_Credits(button);
3427 else if (info_mode == INFO_MODE_PROGRAM)
3428 HandleInfoScreen_Program(button);
3429 else if (info_mode == INFO_MODE_VERSION)
3430 HandleInfoScreen_Version(button);
3431 else if (info_mode == INFO_MODE_LEVELSET)
3432 HandleInfoScreen_LevelSet(button);
3434 HandleInfoScreen_Main(mx, my, dx, dy, button);
3442 /* ========================================================================= */
3443 /* type name functions */
3444 /* ========================================================================= */
3446 void HandleTypeName(int newxpos, Key key)
3448 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3449 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3450 struct TextPosInfo *pos = mci->pos_input;
3451 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3452 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3453 static int xpos = 0;
3454 int font_nr = pos->font;
3455 int font_active_nr = FONT_ACTIVE(font_nr);
3456 int font_width = getFontWidth(font_active_nr);
3457 char key_char = getValidConfigValueChar(getCharFromKey(key));
3458 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3459 boolean is_active = TRUE;
3461 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3465 strcpy(last_player_name, setup.player_name);
3469 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3471 setup.player_name[xpos] = key_char;
3472 setup.player_name[xpos + 1] = 0;
3476 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3480 setup.player_name[xpos] = 0;
3482 else if (key == KSYM_Return && xpos > 0)
3488 game_status = GAME_MODE_MAIN;
3490 else if (key == KSYM_Escape)
3492 strcpy(setup.player_name, last_player_name);
3496 game_status = GAME_MODE_MAIN;
3501 pos->width = (strlen(setup.player_name) + 1) * font_width;
3502 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3504 DrawText(startx, starty, setup.player_name, font_active_nr);
3505 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3509 pos->width = strlen(setup.player_name) * font_width;
3510 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3512 DrawText(startx, starty, setup.player_name, font_nr);
3517 /* ========================================================================= */
3518 /* tree menu functions */
3519 /* ========================================================================= */
3521 static void DrawChooseTree(TreeInfo **ti_ptr)
3525 FreeScreenGadgets();
3526 CreateScreenGadgets();
3528 CloseDoor(DOOR_CLOSE_2);
3531 FadeOut(REDRAW_FIELD);
3536 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3537 MapScreenTreeGadgets(*ti_ptr);
3540 FadeIn(REDRAW_FIELD);
3546 static void AdjustScrollbar(int id, int items_max, int items_visible,
3549 struct GadgetInfo *gi = screen_gadget[id];
3551 if (item_position > items_max - items_visible)
3552 item_position = items_max - items_visible;
3554 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3555 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3556 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3559 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3562 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3565 struct GadgetInfo *gi = screen_gadget[id];
3566 int items_max, items_visible, item_position;
3568 items_max = numTreeInfoInGroup(ti);
3569 items_visible = NUM_MENU_ENTRIES_ON_SCREEN;
3570 item_position = first_entry;
3572 if (item_position > items_max - items_visible)
3573 item_position = items_max - items_visible;
3575 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3576 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3577 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3581 static void drawChooseTreeList(int first_entry, int num_page_entries,
3585 char *title_string = NULL;
3586 int yoffset_sets = MENU_TITLE1_YPOS;
3587 int yoffset_setup = 16;
3588 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3589 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3590 int last_game_status = game_status; /* save current game status */
3592 title_string = ti->infotext;
3594 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3597 /* force LEVELS font on artwork setup screen */
3598 game_status = GAME_MODE_LEVELS;
3602 /* clear tree list area, but not title or scrollbar */
3603 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3604 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3605 NUM_MENU_ENTRIES_ON_SCREEN * 32);
3607 /* clear tree list area, but not title or scrollbar */
3608 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3609 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
3610 MAX_MENU_ENTRIES_ON_SCREEN * 32);
3613 for (i = 0; i < num_page_entries; i++)
3615 TreeInfo *node, *node_first;
3616 int entry_pos = first_entry + i;
3617 int xpos = MENU_SCREEN_START_XPOS;
3618 int ypos = MENU_SCREEN_START_YPOS + i;
3619 int startx = mSX + xpos * 32;
3620 int starty = mSY + ypos * 32;
3621 int font_nr = FONT_TEXT_1;
3622 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3623 int startx_text = startx + font_xoffset;
3624 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3625 int text_size = startx_scrollbar - startx_text;
3626 int max_buffer_len = text_size / getFontWidth(font_nr);
3627 char buffer[max_buffer_len + 1];
3629 node_first = getTreeInfoFirstGroupEntry(ti);
3630 node = getTreeInfoFromPos(node_first, entry_pos);
3632 strncpy(buffer, node->name, max_buffer_len);
3633 buffer[max_buffer_len] = '\0';
3635 DrawText(startx, starty, buffer, font_nr + node->color);
3637 if (node->parent_link)
3638 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3639 else if (node->level_group)
3640 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3642 initCursor(i, IMG_MENU_BUTTON);
3645 game_status = last_game_status; /* restore current game status */
3647 redraw_mask |= REDRAW_FIELD;
3650 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3652 TreeInfo *node, *node_first;
3653 int x, last_redraw_mask = redraw_mask;
3654 int ypos = MENU_TITLE2_YPOS;
3655 int font_nr = FONT_TITLE_2;
3657 if (ti->type == TREE_TYPE_LEVEL_NR)
3658 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3660 if (ti->type != TREE_TYPE_LEVEL_DIR)
3663 node_first = getTreeInfoFirstGroupEntry(ti);
3664 node = getTreeInfoFromPos(node_first, entry_pos);
3666 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3669 if (node->parent_link)
3670 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3671 node->node_parent->name);
3672 else if (node->level_group)
3673 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3675 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3676 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3677 node->levels, (node->levels > 1 ? "levels" : "level"),
3680 if (node->parent_link)
3681 DrawTextFCentered(ypos, font_nr, "leave group \"%s\"",
3683 else if (node->level_group)
3684 DrawTextFCentered(ypos, font_nr, "enter group \"%s\"",
3686 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3687 DrawTextFCentered(ypos, font_nr, "%3d levels (%s)",
3688 node->levels, node->class_desc);
3691 /* let BackToFront() redraw only what is needed */
3692 redraw_mask = last_redraw_mask | REDRAW_TILES;
3693 for (x = 0; x < SCR_FIELDX; x++)
3694 MarkTileDirty(x, 1);
3697 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3700 TreeInfo *ti = *ti_ptr;
3702 int y = ti->cl_cursor;
3703 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3704 int num_entries = numTreeInfoInGroup(ti);
3705 int num_page_entries;
3706 int last_game_status = game_status; /* save current game status */
3707 boolean position_set_by_scrollbar = (dx == 999);
3710 /* force LEVELS draw offset on choose level and artwork setup screen */
3711 game_status = GAME_MODE_LEVELS;
3714 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3715 num_page_entries = num_entries;
3717 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3719 game_status = last_game_status; /* restore current game status */
3721 if (button == MB_MENU_INITIALIZE)
3723 int num_entries = numTreeInfoInGroup(ti);
3724 int entry_pos = posTreeInfo(ti);
3726 if (ti->cl_first == -1)
3728 /* only on initialization */
3729 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3730 ti->cl_cursor = entry_pos - ti->cl_first;
3732 else if (ti->cl_cursor >= num_page_entries ||
3733 (num_entries > num_page_entries &&
3734 num_entries - ti->cl_first < num_page_entries))
3736 /* only after change of list size (by custom graphic configuration) */
3737 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3738 ti->cl_cursor = entry_pos - ti->cl_first;
3741 if (position_set_by_scrollbar)
3744 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3747 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3748 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3749 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3753 else if (button == MB_MENU_LEAVE)
3757 PlaySound(SND_MENU_ITEM_SELECTING);
3759 if (ti->node_parent)
3761 *ti_ptr = ti->node_parent;
3762 DrawChooseTree(ti_ptr);
3764 else if (game_status == GAME_MODE_SETUP)
3766 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3767 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
3769 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3770 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3771 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3772 execSetupGraphics();
3773 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3774 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3775 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3777 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3778 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3779 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3786 if (game_status == GAME_MODE_LEVELNR)
3787 level_nr = atoi(level_number_current->identifier);
3789 game_status = GAME_MODE_MAIN;
3791 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3797 if (mx || my) /* mouse input */
3799 int last_game_status = game_status; /* save current game status */
3802 /* force LEVELS draw offset on artwork setup screen */
3803 game_status = GAME_MODE_LEVELS;
3806 x = (mx - mSX) / 32;
3807 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3809 game_status = last_game_status; /* restore current game status */
3811 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3813 /* move cursor instead of scrolling when already at start/end of list */
3814 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3816 else if (dy == +1 * SCROLL_LINE &&
3817 ti->cl_first + num_page_entries == num_entries)
3820 /* handle scrolling screen one line or page */
3821 if (ti->cl_cursor + dy < 0 ||
3822 ti->cl_cursor + dy > num_page_entries - 1)
3825 boolean redraw = FALSE;
3827 if (ABS(dy) == SCROLL_PAGE)
3828 step = num_page_entries - 1;
3830 if (dy < 0 && ti->cl_first > 0)
3832 /* scroll page/line up */
3834 ti->cl_first -= step;
3835 if (ti->cl_first < 0)
3840 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3842 /* scroll page/line down */
3844 ti->cl_first += step;
3845 if (ti->cl_first + num_page_entries > num_entries)
3846 ti->cl_first = MAX(0, num_entries - num_page_entries);
3853 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3854 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3855 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3857 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3863 if (ABS(dy) == SCROLL_PAGE)
3864 step = num_page_entries - 1;
3866 if (dy < 0 && ti->cl_first > 0)
3868 /* scroll page/line up */
3870 ti->cl_first -= step;
3871 if (ti->cl_first < 0)
3874 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3875 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3876 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3878 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3881 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3883 /* scroll page/line down */
3885 ti->cl_first += step;
3886 if (ti->cl_first + num_page_entries > num_entries)
3887 ti->cl_first = MAX(0, num_entries - num_page_entries);
3889 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3890 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3891 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3893 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3901 /* handle moving cursor one line */
3902 y = ti->cl_cursor + dy;
3907 TreeInfo *node_first, *node_cursor;
3908 int entry_pos = ti->cl_first + y;
3910 node_first = getTreeInfoFirstGroupEntry(ti);
3911 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3913 if (node_cursor->node_group)
3917 PlaySound(SND_MENU_ITEM_SELECTING);
3919 node_cursor->cl_first = ti->cl_first;
3920 node_cursor->cl_cursor = ti->cl_cursor;
3921 *ti_ptr = node_cursor->node_group;
3922 DrawChooseTree(ti_ptr);
3927 else if (dx == -1 && ti->node_parent)
3931 PlaySound(SND_MENU_ITEM_SELECTING);
3933 *ti_ptr = ti->node_parent;
3934 DrawChooseTree(ti_ptr);
3939 if (!anyScrollbarGadgetActive() &&
3940 IN_VIS_FIELD(x, y) &&
3941 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3942 y >= 0 && y < num_page_entries)
3945 printf("::: TEST/HandleChooseTree [%d, %d, %d, %d]\n", Counter(),
3946 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
3951 if (y != ti->cl_cursor)
3953 PlaySound(SND_MENU_ITEM_ACTIVATING);
3955 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3956 drawChooseTreeCursor(y, TRUE);
3957 drawChooseTreeInfo(ti->cl_first + y, ti);
3964 TreeInfo *node_first, *node_cursor;
3965 int entry_pos = ti->cl_first + y;
3967 PlaySound(SND_MENU_ITEM_SELECTING);
3969 node_first = getTreeInfoFirstGroupEntry(ti);
3970 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3972 if (node_cursor->node_group)
3976 node_cursor->cl_first = ti->cl_first;
3977 node_cursor->cl_cursor = ti->cl_cursor;
3978 *ti_ptr = node_cursor->node_group;
3979 DrawChooseTree(ti_ptr);
3981 else if (node_cursor->parent_link)
3985 *ti_ptr = node_cursor->node_parent;
3986 DrawChooseTree(ti_ptr);
3993 FadeSetEnterScreen();
3996 node_cursor->cl_first = ti->cl_first;
3997 node_cursor->cl_cursor = ti->cl_cursor;
3998 *ti_ptr = node_cursor;
4000 if (ti->type == TREE_TYPE_LEVEL_DIR)
4002 LoadLevelSetup_SeriesInfo();
4004 SaveLevelSetup_LastSeries();
4005 SaveLevelSetup_SeriesInfo();
4009 if (game_status == GAME_MODE_SETUP)
4011 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4012 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
4014 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4015 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4016 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4017 execSetupGraphics();
4018 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4019 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4020 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4022 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4023 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4024 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4031 if (game_status == GAME_MODE_LEVELNR)
4032 level_nr = atoi(level_number_current->identifier);
4034 game_status = GAME_MODE_MAIN;
4043 void DrawChooseLevelSet()
4045 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4047 DrawChooseTree(&leveldir_current);
4053 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4055 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4062 void DrawChooseLevelNr()
4066 if (level_number != NULL)
4068 freeTreeInfo(level_number);
4070 level_number = NULL;
4073 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4075 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4076 char identifier[32], name[32];
4079 /* temporarily load level info to get level name */
4080 LoadLevelInfoOnly(i);
4082 ti->node_top = &level_number;
4083 ti->sort_priority = 10000 + value;
4084 ti->color = (level.no_valid_file ? FC_BLUE :
4085 LevelStats_getSolved(i) ? FC_GREEN :
4086 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4088 sprintf(identifier, "%d", value);
4089 sprintf(name, "%03d: %s", value,
4090 (level.no_valid_file ? "(no file)" : level.name));
4092 setString(&ti->identifier, identifier);
4093 setString(&ti->name, name);
4094 setString(&ti->name_sorting, name);
4096 pushTreeInfo(&level_number, ti);
4099 /* sort level number values to start with lowest level number */
4100 sortTreeInfo(&level_number);
4102 /* set current level number to current level number */
4103 level_number_current =
4104 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4106 /* if that also fails, set current level number to first available level */
4107 if (level_number_current == NULL)
4108 level_number_current = level_number;
4110 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4113 DrawChooseTree(&level_number_current);
4115 DrawChooseTree(&leveldir_current);
4122 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4125 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4127 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4135 void DrawHallOfFame(int highlight_position)
4138 FadeSoundsAndMusic();
4140 /* (this is needed when called from GameEnd() after winning a game) */
4141 KeyboardAutoRepeatOn();
4144 /* (this is needed when called from GameEnd() after winning a game) */
4145 SetDrawDeactivationMask(REDRAW_NONE);
4146 SetDrawBackgroundMask(REDRAW_FIELD);
4148 CloseDoor(DOOR_CLOSE_2);
4150 if (highlight_position < 0)
4151 LoadScore(level_nr);
4153 FadeSetEnterScreen();
4155 // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]);
4158 FadeOut(REDRAW_FIELD);
4166 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4169 FadeIn(REDRAW_FIELD);
4173 static void drawHallOfFameList(int first_entry, int highlight_position)
4177 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4180 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4181 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4182 "HighScores of Level %d", level_nr);
4184 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4186 int entry = first_entry + i;
4187 boolean active = (entry == highlight_position);
4188 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4189 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4190 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4191 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4192 int dx1 = 3 * getFontWidth(font_nr1);
4193 int dx2 = dx1 + getFontWidth(font_nr1);
4195 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4);
4196 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4198 int dx3 = dx2 + 25 * getFontWidth(font_nr3);
4200 int sy = mSY + 64 + i * 32;
4202 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4203 DrawText(mSX + dx1, sy, ".", font_nr1);
4205 for (j = 0; j < num_dots; j++)
4206 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4208 DrawText(mSX + dx2, sy, ".........................", font_nr3);
4211 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4212 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4214 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4217 redraw_mask |= REDRAW_FIELD;
4220 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4222 static int first_entry = 0;
4223 static int highlight_position = 0;
4224 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4226 if (button == MB_MENU_INITIALIZE)
4229 highlight_position = mx;
4230 drawHallOfFameList(first_entry, highlight_position);
4235 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4236 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4240 if (first_entry > 0)
4242 first_entry -= step;
4243 if (first_entry < 0)
4246 drawHallOfFameList(first_entry, highlight_position);
4251 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4253 first_entry += step;
4254 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4255 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4257 drawHallOfFameList(first_entry, highlight_position);
4260 else if (button == MB_MENU_LEAVE)
4262 PlaySound(SND_MENU_ITEM_SELECTING);
4264 FadeSound(SND_BACKGROUND_SCORES);
4266 game_status = GAME_MODE_MAIN;
4270 else if (button == MB_MENU_CHOICE)
4272 PlaySound(SND_MENU_ITEM_SELECTING);
4274 FadeSound(SND_BACKGROUND_SCORES);
4277 FadeOut(REDRAW_FIELD);
4280 game_status = GAME_MODE_MAIN;
4282 DrawAndFadeInMainMenu(REDRAW_FIELD);
4285 if (game_status == GAME_MODE_SCORES)
4286 PlayMenuSoundIfLoop();
4294 /* ========================================================================= */
4295 /* setup screen functions */
4296 /* ========================================================================= */
4298 static struct TokenInfo *setup_info;
4299 static int num_setup_info; /* number of setup entries shown on screen */
4300 static int max_setup_info; /* total number of setup entries in list */
4302 static char *screen_mode_text;
4303 static char *window_size_text;
4304 static char *scaling_type_text;
4305 static char *scroll_delay_text;
4306 static char *game_speed_text;
4307 static char *graphics_set_name;
4308 static char *sounds_set_name;
4309 static char *music_set_name;
4310 static char *volume_simple_text;
4311 static char *volume_loops_text;
4312 static char *volume_music_text;
4313 static char *touch_controls_text;
4314 static char *move_distance_text;
4315 static char *drop_distance_text;
4317 static void execSetupMain()
4319 setup_mode = SETUP_MODE_MAIN;
4324 static void execSetupGame_setGameSpeeds()
4326 if (game_speeds == NULL)
4330 for (i = 0; game_speeds_list[i].value != -1; i++)
4332 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4333 char identifier[32], name[32];
4334 int value = game_speeds_list[i].value;
4335 char *text = game_speeds_list[i].text;
4337 ti->node_top = &game_speeds;
4338 ti->sort_priority = 10000 - value;
4340 sprintf(identifier, "%d", value);
4341 sprintf(name, "%s", text);
4343 setString(&ti->identifier, identifier);
4344 setString(&ti->name, name);
4345 setString(&ti->name_sorting, name);
4346 setString(&ti->infotext, "Game Speed");
4348 pushTreeInfo(&game_speeds, ti);
4351 /* sort game speed values to start with slowest game speed */
4352 sortTreeInfo(&game_speeds);
4354 /* set current game speed to configured game speed value */
4355 game_speed_current =
4356 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4358 /* if that fails, set current game speed to reliable default value */
4359 if (game_speed_current == NULL)
4360 game_speed_current =
4361 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4363 /* if that also fails, set current game speed to first available speed */
4364 if (game_speed_current == NULL)
4365 game_speed_current = game_speeds;
4368 setup.game_frame_delay = atoi(game_speed_current->identifier);
4370 /* needed for displaying game speed text instead of identifier */
4371 game_speed_text = game_speed_current->name;
4374 static void execSetupGame_setScrollDelays()
4376 if (scroll_delays == NULL)
4380 for (i = 0; scroll_delays_list[i].value != -1; i++)
4382 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4383 char identifier[32], name[32];
4384 int value = scroll_delays_list[i].value;
4385 char *text = scroll_delays_list[i].text;
4387 ti->node_top = &scroll_delays;
4388 ti->sort_priority = value;
4390 sprintf(identifier, "%d", value);
4391 sprintf(name, "%s", text);
4393 setString(&ti->identifier, identifier);
4394 setString(&ti->name, name);
4395 setString(&ti->name_sorting, name);
4396 setString(&ti->infotext, "Scaling Type");
4398 pushTreeInfo(&scroll_delays, ti);
4401 /* sort scaling type values to start with lowest scaling type value */
4402 sortTreeInfo(&scroll_delays);
4404 /* set current scaling type value to configured scaling type value */
4405 scroll_delay_current =
4406 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4408 /* if that fails, set current scaling type to reliable default value */
4409 if (scroll_delay_current == NULL)
4410 scroll_delay_current =
4411 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4413 /* if that also fails, set current scaling type to first available value */
4414 if (scroll_delay_current == NULL)
4415 scroll_delay_current = scroll_delays;
4418 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4420 /* needed for displaying scaling type text instead of identifier */
4421 scroll_delay_text = scroll_delay_current->name;
4424 static void execSetupGame()
4426 execSetupGame_setGameSpeeds();
4427 execSetupGame_setScrollDelays();
4429 setup_mode = SETUP_MODE_GAME;
4434 static void execSetupChooseGameSpeed()
4436 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4441 static void execSetupChooseScrollDelay()
4443 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4448 static void execSetupEditor()
4450 setup_mode = SETUP_MODE_EDITOR;
4455 static void execSetupGraphics_setWindowSizes(boolean update_list)
4457 if (window_sizes != NULL && update_list)
4459 freeTreeInfo(window_sizes);
4461 window_sizes = NULL;
4464 if (window_sizes == NULL)
4466 boolean current_window_size_found = FALSE;
4469 for (i = 0; window_sizes_list[i].value != -1; i++)
4471 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4472 char identifier[32], name[32];
4473 int value = window_sizes_list[i].value;
4474 char *text = window_sizes_list[i].text;
4476 ti->node_top = &window_sizes;
4477 ti->sort_priority = value;
4479 sprintf(identifier, "%d", value);
4480 sprintf(name, "%s", text);
4482 setString(&ti->identifier, identifier);
4483 setString(&ti->name, name);
4484 setString(&ti->name_sorting, name);
4485 setString(&ti->infotext, "Window Scaling");
4487 pushTreeInfo(&window_sizes, ti);
4489 if (value == setup.window_scaling_percent)
4490 current_window_size_found = TRUE;
4493 if (!current_window_size_found)
4495 // add entry for non-preset window scaling value
4497 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4498 char identifier[32], name[32];
4499 int value = setup.window_scaling_percent;
4501 ti->node_top = &window_sizes;
4502 ti->sort_priority = value;
4504 sprintf(identifier, "%d", value);
4505 sprintf(name, "%d %% (Current)", value);
4507 setString(&ti->identifier, identifier);
4508 setString(&ti->name, name);
4509 setString(&ti->name_sorting, name);
4510 setString(&ti->infotext, "Window Scaling");
4512 pushTreeInfo(&window_sizes, ti);
4515 /* sort window size values to start with lowest window size value */
4516 sortTreeInfo(&window_sizes);
4518 /* set current window size value to configured window size value */
4519 window_size_current =
4520 getTreeInfoFromIdentifier(window_sizes,
4521 i_to_a(setup.window_scaling_percent));
4523 /* if that fails, set current window size to reliable default value */
4524 if (window_size_current == NULL)
4525 window_size_current =
4526 getTreeInfoFromIdentifier(window_sizes,
4527 i_to_a(STD_WINDOW_SCALING_PERCENT));
4529 /* if that also fails, set current window size to first available value */
4530 if (window_size_current == NULL)
4531 window_size_current = window_sizes;
4534 setup.window_scaling_percent = atoi(window_size_current->identifier);
4536 /* needed for displaying window size text instead of identifier */
4537 window_size_text = window_size_current->name;
4540 static void execSetupGraphics_setScalingTypes()
4542 if (scaling_types == NULL)
4546 for (i = 0; scaling_types_list[i].value != NULL; i++)
4548 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4549 char identifier[32], name[32];
4550 char *value = scaling_types_list[i].value;
4551 char *text = scaling_types_list[i].text;
4553 ti->node_top = &scaling_types;
4554 ti->sort_priority = i;
4556 sprintf(identifier, "%s", value);
4557 sprintf(name, "%s", text);
4559 setString(&ti->identifier, identifier);
4560 setString(&ti->name, name);
4561 setString(&ti->name_sorting, name);
4562 setString(&ti->infotext, "Anti-Aliasing");
4564 pushTreeInfo(&scaling_types, ti);
4567 /* sort scaling type values to start with lowest scaling type value */
4568 sortTreeInfo(&scaling_types);
4570 /* set current scaling type value to configured scaling type value */
4571 scaling_type_current =
4572 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4574 /* if that fails, set current scaling type to reliable default value */
4575 if (scaling_type_current == NULL)
4576 scaling_type_current =
4577 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4579 /* if that also fails, set current scaling type to first available value */
4580 if (scaling_type_current == NULL)
4581 scaling_type_current = scaling_types;
4584 setup.window_scaling_quality = scaling_type_current->identifier;
4586 /* needed for displaying scaling type text instead of identifier */
4587 scaling_type_text = scaling_type_current->name;
4590 static void execSetupGraphics_setScreenModes()
4592 // if (screen_modes == NULL && video.fullscreen_available)
4593 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4597 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4599 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4600 char identifier[32], name[32];
4601 int x = video.fullscreen_modes[i].width;
4602 int y = video.fullscreen_modes[i].height;
4605 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4607 ti->node_top = &screen_modes;
4608 ti->sort_priority = x * 10000 + y;
4610 sprintf(identifier, "%dx%d", x, y);
4611 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4613 setString(&ti->identifier, identifier);
4614 setString(&ti->name, name);
4615 setString(&ti->name_sorting, name);
4616 setString(&ti->infotext, "Fullscreen Mode");
4618 pushTreeInfo(&screen_modes, ti);
4621 /* sort fullscreen modes to start with lowest available screen resolution */
4622 sortTreeInfo(&screen_modes);
4624 /* set current screen mode for fullscreen mode to configured setup value */
4625 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4626 setup.fullscreen_mode);
4628 /* if that fails, set current screen mode to reliable default value */
4629 if (screen_mode_current == NULL)
4630 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4631 DEFAULT_FULLSCREEN_MODE);
4633 /* if that also fails, set current screen mode to first available mode */
4634 if (screen_mode_current == NULL)
4635 screen_mode_current = screen_modes;
4637 if (screen_mode_current == NULL)
4638 video.fullscreen_available = FALSE;
4641 // if (video.fullscreen_available)
4642 if (screen_mode_current != NULL)
4644 setup.fullscreen_mode = screen_mode_current->identifier;
4646 /* needed for displaying screen mode name instead of identifier */
4647 screen_mode_text = screen_mode_current->name;
4651 static void execSetupGraphics()
4653 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4655 // update "setup.window_scaling_percent" from list selection
4656 execSetupGraphics_setWindowSizes(FALSE);
4660 // update list selection from "setup.window_scaling_percent"
4661 execSetupGraphics_setWindowSizes(TRUE);
4664 execSetupGraphics_setScalingTypes();
4665 execSetupGraphics_setScreenModes();
4667 setup_mode = SETUP_MODE_GRAPHICS;
4671 #if defined(TARGET_SDL2)
4672 // window scaling may have changed at this point
4673 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4675 // window scaling quality may have changed at this point
4676 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4677 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4681 #if !defined(PLATFORM_ANDROID)
4682 #if defined(TARGET_SDL2)
4683 static void execSetupChooseWindowSize()
4686 if (!video.window_scaling_available)
4690 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4695 static void execSetupChooseScalingType()
4697 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4702 static void execSetupChooseScreenMode()
4704 if (!video.fullscreen_available)
4707 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4714 static void execSetupChooseVolumeSimple()
4716 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4721 static void execSetupChooseVolumeLoops()
4723 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4728 static void execSetupChooseVolumeMusic()
4730 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4735 static void execSetupSound()
4738 if (volumes_simple == NULL)
4742 for (i = 0; volumes_list[i].value != -1; i++)
4744 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4745 char identifier[32], name[32];
4746 int value = volumes_list[i].value;
4747 char *text = volumes_list[i].text;
4749 ti->node_top = &volumes_simple;
4750 ti->sort_priority = value;
4752 sprintf(identifier, "%d", value);
4753 sprintf(name, "%s", text);
4755 setString(&ti->identifier, identifier);
4756 setString(&ti->name, name);
4757 setString(&ti->name_sorting, name);
4758 setString(&ti->infotext, "Sound Volume");
4760 pushTreeInfo(&volumes_simple, ti);
4763 /* sort volume values to start with lowest volume value */
4764 sortTreeInfo(&volumes_simple);
4766 /* set current volume value to configured volume value */
4767 volume_simple_current =
4768 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4770 /* if that fails, set current volume to reliable default value */
4771 if (volume_simple_current == NULL)
4772 volume_simple_current =
4773 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4775 /* if that also fails, set current volume to first available value */
4776 if (volume_simple_current == NULL)
4777 volume_simple_current = volumes_simple;
4780 if (volumes_loops == NULL)
4784 for (i = 0; volumes_list[i].value != -1; i++)
4786 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4787 char identifier[32], name[32];
4788 int value = volumes_list[i].value;
4789 char *text = volumes_list[i].text;
4791 ti->node_top = &volumes_loops;
4792 ti->sort_priority = value;
4794 sprintf(identifier, "%d", value);
4795 sprintf(name, "%s", text);
4797 setString(&ti->identifier, identifier);
4798 setString(&ti->name, name);
4799 setString(&ti->name_sorting, name);
4800 setString(&ti->infotext, "Loops Volume");
4802 pushTreeInfo(&volumes_loops, ti);
4805 /* sort volume values to start with lowest volume value */
4806 sortTreeInfo(&volumes_loops);
4808 /* set current volume value to configured volume value */
4809 volume_loops_current =
4810 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4812 /* if that fails, set current volume to reliable default value */
4813 if (volume_loops_current == NULL)
4814 volume_loops_current =
4815 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4817 /* if that also fails, set current volume to first available value */
4818 if (volume_loops_current == NULL)
4819 volume_loops_current = volumes_loops;
4822 if (volumes_music == NULL)
4826 for (i = 0; volumes_list[i].value != -1; i++)
4828 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4829 char identifier[32], name[32];
4830 int value = volumes_list[i].value;
4831 char *text = volumes_list[i].text;
4833 ti->node_top = &volumes_music;
4834 ti->sort_priority = value;
4836 sprintf(identifier, "%d", value);
4837 sprintf(name, "%s", text);
4839 setString(&ti->identifier, identifier);
4840 setString(&ti->name, name);
4841 setString(&ti->name_sorting, name);
4842 setString(&ti->infotext, "Music Volume");
4844 pushTreeInfo(&volumes_music, ti);
4847 /* sort volume values to start with lowest volume value */
4848 sortTreeInfo(&volumes_music);
4850 /* set current volume value to configured volume value */
4851 volume_music_current =
4852 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4854 /* if that fails, set current volume to reliable default value */
4855 if (volume_music_current == NULL)
4856 volume_music_current =
4857 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4859 /* if that also fails, set current volume to first available value */
4860 if (volume_music_current == NULL)
4861 volume_music_current = volumes_music;
4864 setup.volume_simple = atoi(volume_simple_current->identifier);
4865 setup.volume_loops = atoi(volume_loops_current->identifier);
4866 setup.volume_music = atoi(volume_music_current->identifier);
4868 /* needed for displaying volume text instead of identifier */
4869 volume_simple_text = volume_simple_current->name;
4870 volume_loops_text = volume_loops_current->name;
4871 volume_music_text = volume_music_current->name;
4874 setup_mode = SETUP_MODE_SOUND;
4879 static void execSetupChooseTouchControls()
4881 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4886 static void execSetupChooseMoveDistance()
4888 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4893 static void execSetupChooseDropDistance()
4895 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4900 static void execSetupTouch()
4903 if (touch_controls == NULL)
4907 for (i = 0; touch_controls_list[i].value != NULL; i++)
4909 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4910 char identifier[32], name[32];
4911 char *value = touch_controls_list[i].value;
4912 char *text = touch_controls_list[i].text;
4914 ti->node_top = &touch_controls;
4915 ti->sort_priority = i;
4917 sprintf(identifier, "%s", value);
4918 sprintf(name, "%s", text);
4920 setString(&ti->identifier, identifier);
4921 setString(&ti->name, name);
4922 setString(&ti->name_sorting, name);
4923 setString(&ti->infotext, "Control Type");
4925 pushTreeInfo(&touch_controls, ti);
4928 /* sort touch control values to start with lowest touch control value */
4929 sortTreeInfo(&touch_controls);
4931 /* set current touch control value to configured touch control value */
4932 touch_control_current =
4933 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4935 /* if that fails, set current touch control to reliable default value */
4936 if (touch_control_current == NULL)
4937 touch_control_current =
4938 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4940 /* if that also fails, set current touch control to first available value */
4941 if (touch_control_current == NULL)
4942 touch_control_current = touch_controls;
4945 if (move_distances == NULL)
4949 for (i = 0; distances_list[i].value != -1; i++)
4951 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4952 char identifier[32], name[32];
4953 int value = distances_list[i].value;
4954 char *text = distances_list[i].text;
4956 ti->node_top = &move_distances;
4957 ti->sort_priority = value;
4959 sprintf(identifier, "%d", value);
4960 sprintf(name, "%s", text);
4962 setString(&ti->identifier, identifier);
4963 setString(&ti->name, name);
4964 setString(&ti->name_sorting, name);
4965 setString(&ti->infotext, "Move Distance");
4967 pushTreeInfo(&move_distances, ti);
4970 /* sort distance values to start with lowest distance value */
4971 sortTreeInfo(&move_distances);
4973 /* set current distance value to configured distance value */
4974 move_distance_current =
4975 getTreeInfoFromIdentifier(move_distances,
4976 i_to_a(setup.touch.move_distance));
4978 /* if that fails, set current distance to reliable default value */
4979 if (move_distance_current == NULL)
4980 move_distance_current =
4981 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4983 /* if that also fails, set current distance to first available value */
4984 if (move_distance_current == NULL)
4985 move_distance_current = move_distances;
4988 if (drop_distances == NULL)
4992 for (i = 0; distances_list[i].value != -1; i++)
4994 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4995 char identifier[32], name[32];
4996 int value = distances_list[i].value;
4997 char *text = distances_list[i].text;
4999 ti->node_top = &drop_distances;
5000 ti->sort_priority = value;
5002 sprintf(identifier, "%d", value);
5003 sprintf(name, "%s", text);
5005 setString(&ti->identifier, identifier);
5006 setString(&ti->name, name);
5007 setString(&ti->name_sorting, name);
5008 setString(&ti->infotext, "Drop Distance");
5010 pushTreeInfo(&drop_distances, ti);
5013 /* sort distance values to start with lowest distance value */
5014 sortTreeInfo(&drop_distances);
5016 /* set current distance value to configured distance value */
5017 drop_distance_current =
5018 getTreeInfoFromIdentifier(drop_distances,
5019 i_to_a(setup.touch.drop_distance));
5021 /* if that fails, set current distance to reliable default value */
5022 if (drop_distance_current == NULL)
5023 drop_distance_current =
5024 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5026 /* if that also fails, set current distance to first available value */
5027 if (drop_distance_current == NULL)
5028 drop_distance_current = drop_distances;
5031 setup.touch.control_type = touch_control_current->identifier;
5032 setup.touch.move_distance = atoi(move_distance_current->identifier);
5033 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5035 /* needed for displaying volume text instead of identifier */
5036 touch_controls_text = touch_control_current->name;
5037 move_distance_text = move_distance_current->name;
5038 drop_distance_text = drop_distance_current->name;
5041 setup_mode = SETUP_MODE_TOUCH;
5046 static void execSetupArtwork()
5049 printf("::: '%s', '%s', '%s'\n",
5050 artwork.gfx_current->subdir,
5051 artwork.gfx_current->fullpath,
5052 artwork.gfx_current->basepath);
5055 setup.graphics_set = artwork.gfx_current->identifier;
5056 setup.sounds_set = artwork.snd_current->identifier;
5057 setup.music_set = artwork.mus_current->identifier;
5059 /* needed if last screen (setup choice) changed graphics, sounds or music */
5060 ReloadCustomArtwork(0);
5062 /* needed for displaying artwork name instead of artwork identifier */
5063 graphics_set_name = artwork.gfx_current->name;
5064 sounds_set_name = artwork.snd_current->name;
5065 music_set_name = artwork.mus_current->name;
5067 setup_mode = SETUP_MODE_ARTWORK;
5072 static void execSetupChooseGraphics()
5074 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5079 static void execSetupChooseSounds()
5081 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5086 static void execSetupChooseMusic()
5088 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5093 static void execSetupInput()
5095 setup_mode = SETUP_MODE_INPUT;
5100 static void execSetupShortcuts()
5102 setup_mode = SETUP_MODE_SHORTCUTS;
5107 static void execSetupShortcuts1()
5109 setup_mode = SETUP_MODE_SHORTCUTS_1;
5114 static void execSetupShortcuts2()
5116 setup_mode = SETUP_MODE_SHORTCUTS_2;
5121 static void execSetupShortcuts3()
5123 setup_mode = SETUP_MODE_SHORTCUTS_3;
5128 static void execSetupShortcuts4()
5130 setup_mode = SETUP_MODE_SHORTCUTS_4;
5135 static void execSetupShortcuts5()
5137 setup_mode = SETUP_MODE_SHORTCUTS_5;
5142 static void execExitSetup()
5144 game_status = GAME_MODE_MAIN;
5146 DrawMainMenuExt(REDRAW_FIELD, FALSE);
5149 static void execSaveAndExitSetup()
5155 static struct TokenInfo setup_info_main[] =
5157 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5158 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5159 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5160 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5161 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5162 #if !defined(PLATFORM_ANDROID)
5163 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5164 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5166 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5168 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5169 { TYPE_EMPTY, NULL, "" },
5170 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5171 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5176 static struct TokenInfo setup_info_game[] =
5178 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5179 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5180 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5181 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5182 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5183 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5184 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5185 { TYPE_STRING, &game_speed_text, "" },
5187 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5188 { TYPE_STRING, &scroll_delay_text, "" },
5190 { TYPE_EMPTY, NULL, "" },
5191 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5196 static struct TokenInfo setup_info_editor[] =
5199 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5200 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5201 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5202 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5203 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5204 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5205 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5206 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5208 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5209 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5210 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5212 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5214 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5215 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5216 { TYPE_EMPTY, NULL, "" },
5218 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5219 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5220 { TYPE_EMPTY, NULL, "" },
5222 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5223 { TYPE_EMPTY, NULL, "" },
5224 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5229 static struct TokenInfo setup_info_graphics[] =
5231 #if !defined(PLATFORM_ANDROID)
5232 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5233 #if defined(TARGET_SDL2)
5234 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5235 { TYPE_STRING, &window_size_text, "" },
5237 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5238 { TYPE_STRING, &scaling_type_text, "" },
5241 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5242 { TYPE_STRING, &screen_mode_text, "" },
5246 { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" },
5249 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5250 { TYPE_STRING, &scroll_delay_text, "" },
5253 { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" },
5255 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5256 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5257 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5258 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5259 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5260 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5261 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5262 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5263 { TYPE_EMPTY, NULL, "" },
5264 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5269 static struct TokenInfo setup_info_sound[] =
5271 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5272 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5273 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5274 { TYPE_EMPTY, NULL, "" },
5275 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5276 { TYPE_STRING, &volume_simple_text, "" },
5277 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5278 { TYPE_STRING, &volume_loops_text, "" },
5279 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5280 { TYPE_STRING, &volume_music_text, "" },
5281 { TYPE_EMPTY, NULL, "" },
5282 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5287 static struct TokenInfo setup_info_artwork[] =
5289 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5290 { TYPE_STRING, &graphics_set_name, "" },
5291 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5292 { TYPE_STRING, &sounds_set_name, "" },
5293 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5294 { TYPE_STRING, &music_set_name, "" },
5295 { TYPE_EMPTY, NULL, "" },
5298 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5299 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5300 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5302 { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" },
5303 { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" },
5304 { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" },
5305 { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" },
5308 { TYPE_STRING, NULL, "Override Level Artwork:"},
5309 { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" },
5310 { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" },
5311 { TYPE_YES_NO, &setup.override_level_music, "Music:" },
5313 { TYPE_EMPTY, NULL, "" },
5314 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5319 static struct TokenInfo setup_info_input[] =
5321 { TYPE_SWITCH, NULL, "Player:" },
5322 { TYPE_SWITCH, NULL, "Device:" },
5323 { TYPE_ENTER_MENU, NULL, "" },
5324 { TYPE_EMPTY, NULL, "" },
5325 { TYPE_EMPTY, NULL, "" },
5326 { TYPE_EMPTY, NULL, "" },
5327 { TYPE_EMPTY, NULL, "" },
5328 { TYPE_EMPTY, NULL, "" },
5329 { TYPE_EMPTY, NULL, "" },
5330 { TYPE_EMPTY, NULL, "" },
5331 { TYPE_EMPTY, NULL, "" },
5332 { TYPE_EMPTY, NULL, "" },
5333 { TYPE_EMPTY, NULL, "" },
5334 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5339 static struct TokenInfo setup_info_touch[] =
5341 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5342 { TYPE_STRING, &touch_controls_text, "" },
5343 { TYPE_EMPTY, NULL, "" },
5344 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5345 { TYPE_STRING, &move_distance_text, "" },
5346 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5347 { TYPE_STRING, &drop_distance_text, "" },
5348 { TYPE_EMPTY, NULL, "" },
5349 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5354 static struct TokenInfo setup_info_shortcuts[] =
5356 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5357 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5358 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5359 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5360 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5361 { TYPE_EMPTY, NULL, "" },
5362 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5367 static struct TokenInfo setup_info_shortcuts_1[] =
5369 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5370 { TYPE_KEY, &setup.shortcut.save_game, "" },
5371 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5372 { TYPE_KEY, &setup.shortcut.load_game, "" },
5373 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5374 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5375 { TYPE_EMPTY, NULL, "" },
5376 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5377 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5378 { TYPE_EMPTY, NULL, "" },
5379 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5384 static struct TokenInfo setup_info_shortcuts_2[] =
5386 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5387 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5388 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5389 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5390 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5391 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5392 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5393 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5394 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5395 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5396 { TYPE_EMPTY, NULL, "" },
5397 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5402 static struct TokenInfo setup_info_shortcuts_3[] =
5404 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5405 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5406 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5407 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5408 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5409 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5410 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5411 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5412 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5413 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5414 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5415 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5416 { TYPE_EMPTY, NULL, "" },
5417 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5422 static struct TokenInfo setup_info_shortcuts_4[] =
5424 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5425 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5426 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5427 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5428 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5429 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5430 { TYPE_EMPTY, NULL, "" },
5431 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5436 static struct TokenInfo setup_info_shortcuts_5[] =
5438 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5439 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5440 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5441 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5442 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5443 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5444 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5445 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5446 { TYPE_EMPTY, NULL, "" },
5447 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5452 static Key getSetupKey()
5454 Key key = KSYM_UNDEFINED;
5455 boolean got_key_event = FALSE;
5457 while (!got_key_event)
5459 if (PendingEvent()) /* got event */
5467 case EVENT_KEYPRESS:
5469 key = GetEventKey((KeyEvent *)&event, TRUE);
5471 /* press 'Escape' or 'Enter' to keep the existing key binding */
5472 if (key == KSYM_Escape || key == KSYM_Return)
5473 key = KSYM_UNDEFINED; /* keep old value */
5475 got_key_event = TRUE;
5479 case EVENT_KEYRELEASE:
5480 key_joystick_mapping = 0;
5484 HandleOtherEvents(&event);
5492 /* don't eat all CPU time */
5499 static int getSetupTextFont(int type)
5501 if (type & (TYPE_SWITCH |
5513 static int getSetupValueFont(int type, void *value)
5515 if (type & TYPE_KEY)
5516 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5517 else if (type & TYPE_STRING)
5518 return FONT_VALUE_2;
5519 else if (type & TYPE_ECS_AGA)
5520 return FONT_VALUE_1;
5521 else if (type & TYPE_BOOLEAN_STYLE)
5522 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5523 else if (type & TYPE_YES_NO_AUTO)
5524 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5525 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5527 return FONT_VALUE_1;
5531 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5533 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5534 struct TokenInfo *si = &setup_info[si_pos];
5535 boolean font_draw_xoffset_modified = FALSE;
5536 int font_draw_xoffset_old = -1;
5537 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5538 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5539 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5540 int xpos = menu_screen_value_xpos;
5541 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5542 int startx = mSX + xpos * 32;
5543 int starty = mSY + ypos * 32;
5544 int font_nr, font_width;
5548 int type = si->type;
5549 void *value = si->value;
5550 char *value_string = getSetupValue(type, value);
5555 if (value_string == NULL)
5558 if (type & TYPE_KEY)
5560 xpos = MENU_SCREEN_START_XPOS;
5562 if (type & TYPE_QUERY)
5563 value_string = "<press key>";
5565 else if (type & TYPE_STRING)
5567 int max_value_len = (SCR_FIELDX - 2) * 2;
5569 xpos = MENU_SCREEN_START_XPOS;
5571 if (strlen(value_string) > max_value_len)
5572 value_string[max_value_len] = '\0';
5574 else if (type & TYPE_YES_NO_AUTO)
5576 xpos = menu_screen_value_xpos - 1;
5579 startx = mSX + xpos * 32;
5580 starty = mSY + ypos * 32;
5581 font_nr = getSetupValueFont(type, value);
5582 font_width = getFontWidth(font_nr);
5584 font_height = getFontHeight(font_nr);
5588 if (menu_screen_value_xpos < 1 + MAX_MENU_TEXT_LENGTH_BIG)
5592 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5593 if (setup_mode != SETUP_MODE_INPUT)
5595 int max_menu_text_length_big = (menu_screen_value_xpos -
5596 MENU_SCREEN_START_XPOS);
5597 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5598 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5599 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5600 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5601 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5602 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5603 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5604 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5605 boolean correct_font_draw_xoffset = FALSE;
5607 if (xpos == MENU_SCREEN_START_XPOS &&
5608 startx + font1_xoffset < text_startx + text_font_xoffset)
5609 correct_font_draw_xoffset = TRUE;
5611 if (xpos == menu_screen_value_xpos &&
5612 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5613 correct_font_draw_xoffset = TRUE;
5615 /* check if setup value would overlap with setup text when printed */
5616 /* (this can happen for extreme/wrong values for font draw offset) */
5617 if (correct_font_draw_xoffset)
5619 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5620 font_draw_xoffset_modified = TRUE;
5622 if (type & TYPE_KEY)
5623 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5624 else if (!(type & TYPE_STRING))
5625 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5626 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5631 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5633 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5634 DrawText(startx + i * font_width, starty, " ", font_nr);
5637 // printf("::: startx == %d\n", startx);
5639 DrawText(startx, starty, value_string, font_nr);
5641 if (font_draw_xoffset_modified)
5642 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5647 static void drawSetupValue(int pos)
5649 boolean font_draw_xoffset_modified = FALSE;
5650 int font_draw_xoffset_old = -1;
5651 int xpos = MENU_SCREEN_VALUE_XPOS;
5652 int ypos = MENU_SCREEN_START_YPOS + pos;
5653 int startx = mSX + xpos * 32;
5654 int starty = mSY + ypos * 32;
5655 int font_nr, font_width;
5659 int type = setup_info[pos].type;
5660 void *value = setup_info[pos].value;
5661 char *value_string = getSetupValue(type, value);
5666 if (value_string == NULL)
5669 if (type & TYPE_KEY)
5671 xpos = MENU_SCREEN_START_XPOS;
5673 if (type & TYPE_QUERY)
5674 value_string = "<press key>";
5676 else if (type & TYPE_STRING)
5678 int max_value_len = (SCR_FIELDX - 2) * 2;
5680 xpos = MENU_SCREEN_START_XPOS;
5682 if (strlen(value_string) > max_value_len)
5683 value_string[max_value_len] = '\0';
5685 else if (type & TYPE_YES_NO_AUTO)
5687 xpos = MENU_SCREEN_VALUE_XPOS - 1;
5690 startx = mSX + xpos * 32;
5691 starty = mSY + ypos * 32;
5692 font_nr = getSetupValueFont(type, value);
5693 font_width = getFontWidth(font_nr);
5695 font_height = getFontHeight(font_nr);
5698 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5699 if (setup_mode != SETUP_MODE_INPUT)
5701 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5702 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5703 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5704 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5705 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5706 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5707 int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr);
5708 boolean correct_font_draw_xoffset = FALSE;
5710 if (xpos == MENU_SCREEN_START_XPOS &&
5711 startx + font1_xoffset < text_startx + text_font_xoffset)
5712 correct_font_draw_xoffset = TRUE;
5714 if (xpos == MENU_SCREEN_VALUE_XPOS &&
5715 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5716 correct_font_draw_xoffset = TRUE;
5718 /* check if setup value would overlap with setup text when printed */
5719 /* (this can happen for extreme/wrong values for font draw offset) */
5720 if (correct_font_draw_xoffset)
5722 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5723 font_draw_xoffset_modified = TRUE;
5725 if (type & TYPE_KEY)
5726 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5727 else if (!(type & TYPE_STRING))
5728 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5729 MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr));
5734 DrawBackground(startx, starty, SX + SXSIZE - startx, font_height);
5736 for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++)
5737 DrawText(startx + i * font_width, starty, " ", font_nr);
5740 DrawText(startx, starty, value_string, font_nr);
5742 if (font_draw_xoffset_modified)
5743 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5748 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5750 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5751 struct TokenInfo *si = &setup_info[si_pos];
5753 if (si->type & TYPE_BOOLEAN_STYLE)
5755 *(boolean *)si->value ^= TRUE;
5757 else if (si->type & TYPE_YES_NO_AUTO)
5761 (*(int *)si->value == AUTO ? TRUE :
5762 *(int *)si->value == TRUE ? FALSE : AUTO) :
5763 (*(int *)si->value == TRUE ? AUTO :
5764 *(int *)si->value == AUTO ? FALSE : TRUE));
5766 else if (si->type & TYPE_KEY)
5770 si->type |= TYPE_QUERY;
5771 drawSetupValue(screen_pos, setup_info_pos_raw);
5772 si->type &= ~TYPE_QUERY;
5774 key = getSetupKey();
5775 if (key != KSYM_UNDEFINED)
5776 *(Key *)si->value = key;
5779 drawSetupValue(screen_pos, setup_info_pos_raw);
5781 // fullscreen state may have changed at this point
5782 if (si->value == &setup.fullscreen)
5783 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5788 static void changeSetupValue(int pos, int dx)
5790 if (setup_info[pos].type & TYPE_BOOLEAN_STYLE)
5792 *(boolean *)setup_info[pos].value ^= TRUE;
5794 else if (setup_info[pos].type & TYPE_YES_NO_AUTO)
5796 *(int *)setup_info[pos].value =
5798 (*(int *)setup_info[pos].value == AUTO ? TRUE :
5799 *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) :
5800 (*(int *)setup_info[pos].value == TRUE ? AUTO :
5801 *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE));
5803 else if (setup_info[pos].type & TYPE_KEY)
5807 setup_info[pos].type |= TYPE_QUERY;
5808 drawSetupValue(pos, -1);
5809 setup_info[pos].type &= ~TYPE_QUERY;
5811 key = getSetupKey();
5812 if (key != KSYM_UNDEFINED)
5813 *(Key *)setup_info[pos].value = key;
5816 drawSetupValue(pos, -1);
5818 // fullscreen state may have changed at this point
5819 if (setup_info[pos].value == &setup.fullscreen)
5820 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5825 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5828 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5829 struct TokenInfo *si = &setup_info[si_pos];
5830 int xpos = MENU_SCREEN_START_XPOS;
5831 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5832 int font_nr = getSetupTextFont(si->type);
5834 if (setup_info == setup_info_input)
5835 font_nr = FONT_MENU_1;
5838 font_nr = FONT_ACTIVE(font_nr);
5840 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5842 if (si->type & ~TYPE_SKIP_ENTRY)
5843 drawCursor(screen_pos, active);
5846 static void DrawCursorAndText_Setup(int pos, boolean active)
5848 int xpos = MENU_SCREEN_START_XPOS;
5849 int ypos = MENU_SCREEN_START_YPOS + pos;
5850 int font_nr = getSetupTextFont(setup_info[pos].type);
5852 if (setup_info == setup_info_input)
5853 font_nr = FONT_MENU_1;
5856 font_nr = FONT_ACTIVE(font_nr);
5858 DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr);
5860 if (setup_info[pos].type & ~TYPE_SKIP_ENTRY)
5861 drawCursor(pos, active);
5865 static void drawSetupInfoList(struct TokenInfo *setup_info,
5866 int first_entry, int num_page_entries)
5870 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5871 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5873 if (num_page_entries > max_setup_info)
5874 num_page_entries = max_setup_info;
5876 if (first_entry + num_page_entries > max_setup_info)
5880 /* clear tree list area, but not title or scrollbar */
5881 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
5882 SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset,
5883 NUM_MENU_ENTRIES_ON_SCREEN * 32);
5886 for (i = 0; i < num_page_entries; i++)
5888 int setup_info_pos = first_entry + i;
5889 struct TokenInfo *si = &setup_info[setup_info_pos];
5890 void *value_ptr = si->value;
5892 /* set some entries to "unchangeable" according to other variables */
5893 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5894 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5895 (value_ptr == &setup.sound_music && !audio.music_available) ||
5896 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5897 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5898 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5899 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5900 si->type |= TYPE_GHOSTED;
5902 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5903 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5904 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5905 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5906 else if (si->type & ~TYPE_SKIP_ENTRY)
5907 initCursor(i, IMG_MENU_BUTTON);
5909 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5911 if (si->type & TYPE_VALUE)
5912 drawSetupValue(i, setup_info_pos);
5916 static void DrawSetupScreen_Generic()
5918 boolean redraw_all = FALSE;
5919 char *title_string = NULL;
5925 FreeScreenGadgets();
5926 CreateScreenGadgets();
5929 CloseDoor(DOOR_CLOSE_2);
5931 if (redraw_mask & REDRAW_ALL)
5935 printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" :
5936 redraw_mask & REDRAW_ALL ? "REDRAW_ALL" :
5937 int2str(0, redraw_mask)));
5941 /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */
5942 FadeOut(redraw_mask);
5944 FadeOut(REDRAW_FIELD);
5949 if (setup_mode == SETUP_MODE_MAIN)
5951 setup_info = setup_info_main;
5952 title_string = "Setup";
5954 else if (setup_mode == SETUP_MODE_GAME)
5956 setup_info = setup_info_game;
5957 title_string = "Setup Game";
5959 else if (setup_mode == SETUP_MODE_EDITOR)
5961 setup_info = setup_info_editor;
5962 title_string = "Setup Editor";
5964 else if (setup_mode == SETUP_MODE_GRAPHICS)
5966 setup_info = setup_info_graphics;
5967 title_string = "Setup Graphics";
5969 else if (setup_mode == SETUP_MODE_SOUND)
5971 setup_info = setup_info_sound;
5972 title_string = "Setup Sound";
5974 else if (setup_mode == SETUP_MODE_ARTWORK)
5976 setup_info = setup_info_artwork;
5977 title_string = "Custom Artwork";
5979 else if (setup_mode == SETUP_MODE_TOUCH)
5981 setup_info = setup_info_touch;
5982 title_string = "Setup Touch Ctrls";
5984 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5986 setup_info = setup_info_shortcuts;
5987 title_string = "Setup Shortcuts";
5989 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5991 setup_info = setup_info_shortcuts_1;
5992 title_string = "Setup Shortcuts";
5994 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5996 setup_info = setup_info_shortcuts_2;
5997 title_string = "Setup Shortcuts";
5999 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6001 setup_info = setup_info_shortcuts_3;
6002 title_string = "Setup Shortcuts";
6004 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6006 setup_info = setup_info_shortcuts_4;
6007 title_string = "Setup Shortcuts";
6009 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6011 setup_info = setup_info_shortcuts_5;
6012 title_string = "Setup Shortcuts";
6015 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6020 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6024 for (i = 0; setup_info[i].type != 0; i++)
6028 drawSetupInfoList(setup_info, 0, NUM_MENU_ENTRIES_ON_SCREEN);
6035 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6037 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6040 void *value_ptr = setup_info[i].value;
6042 /* set some entries to "unchangeable" according to other variables */
6043 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
6044 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
6045 (value_ptr == &setup.sound_music && !audio.music_available) ||
6046 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
6047 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
6048 (value_ptr == &window_size_text && !video.window_scaling_available) ||
6049 (value_ptr == &scaling_type_text && !video.window_scaling_available))
6050 setup_info[i].type |= TYPE_GHOSTED;
6052 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6053 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6054 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6055 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6056 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6057 initCursor(i, IMG_MENU_BUTTON);
6059 DrawCursorAndText_Setup(i, FALSE);
6061 if (setup_info[i].type & TYPE_VALUE)
6069 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6070 "Joysticks deactivated in setup menu");
6074 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6078 MapScreenGadgets(max_setup_info);
6082 redraw_mask = REDRAW_ALL;
6085 FadeIn(redraw_mask);
6087 FadeIn(REDRAW_FIELD);
6092 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6096 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6098 static int choice_store[MAX_SETUP_MODES];
6099 static int first_entry_store[MAX_SETUP_MODES];
6100 int choice = choice_store[setup_mode]; /* starts with 0 */
6101 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
6104 int y = choice - first_entry;
6109 boolean position_set_by_scrollbar = (dx == 999);
6111 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6112 int num_page_entries;
6114 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
6117 if (button == MB_MENU_INITIALIZE)
6119 /* advance to first valid menu entry */
6120 while (choice < num_setup_info &&
6121 setup_info[choice].type & TYPE_SKIP_ENTRY)
6124 choice_store[setup_mode] = choice;
6128 if (position_set_by_scrollbar)
6129 first_entry = first_entry_store[setup_mode] = dy;
6131 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6132 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6134 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6138 if (choice < first_entry)
6140 choice = first_entry;
6142 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6145 else if (choice > first_entry + num_page_entries - 1)
6147 choice = first_entry + num_page_entries - 1;
6149 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6153 choice_store[setup_mode] = choice;
6155 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6157 DrawCursorAndText_Setup(choice, -1, TRUE);
6162 else if (button == MB_MENU_LEAVE)
6166 PlaySound(SND_MENU_ITEM_SELECTING);
6168 for (i = 0; setup_info[i].type != 0; i++)
6170 if (setup_info[i].type & TYPE_LEAVE_MENU)
6172 void (*menu_callback_function)(void) = setup_info[i].value;
6176 menu_callback_function();
6178 break; /* absolutely needed because function changes 'setup_info'! */
6185 if (mx || my) /* mouse input */
6187 x = (mx - mSX) / 32;
6188 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6191 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
6193 else if (dx || dy) /* keyboard input */
6196 /* move cursor instead of scrolling when already at start/end of list */
6197 if (dy == -1 * SCROLL_LINE && first_entry == 0)
6199 else if (dy == +1 * SCROLL_LINE &&
6200 first_entry + num_page_entries == max_setup_info)
6203 /* handle scrolling screen one line or page */
6205 y + dy > num_page_entries - 1)
6207 boolean redraw = FALSE;
6209 if (ABS(dy) == SCROLL_PAGE)
6210 step = num_page_entries - 1;
6212 if (dy < 0 && first_entry > 0)
6214 /* scroll page/line up */
6216 first_entry -= step;
6217 if (first_entry < 0)
6222 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
6224 /* scroll page/line down */
6226 first_entry += step;
6227 if (first_entry + num_page_entries > max_setup_info)
6228 first_entry = MAX(0, max_setup_info - num_page_entries);
6235 choice += first_entry - first_entry_store[setup_mode];
6237 if (choice < first_entry)
6239 choice = first_entry;
6241 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6244 else if (choice > first_entry + num_page_entries - 1)
6246 choice = first_entry + num_page_entries - 1;
6248 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6252 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
6256 if (choice < first_entry ||
6257 choice > first_entry + num_page_entries - 1)
6258 first_entry += SIGN(dy);
6262 // printf("::: MARK 1: %d\n", first_entry);
6264 first_entry_store[setup_mode] = first_entry;
6265 choice_store[setup_mode] = choice;
6267 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6269 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6271 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6272 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6280 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
6282 if (setup_info[choice].type & menu_navigation_type ||
6283 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
6284 setup_info[choice].type & TYPE_YES_NO_AUTO)
6285 button = MB_MENU_CHOICE;
6295 /* jump to next non-empty menu entry (up or down) */
6297 while (first_entry + y > 0 &&
6298 first_entry + y < max_setup_info - 1 &&
6299 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6302 while (y > 0 && y < num_setup_info - 1 &&
6303 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
6307 if (!IN_VIS_FIELD(x, y))
6309 choice += y - y_old;
6311 if (choice < first_entry)
6312 first_entry = choice;
6313 else if (choice > first_entry + num_page_entries - 1)
6314 first_entry = choice - num_page_entries + 1;
6316 first_entry += y - y_old;
6319 if (first_entry >= 0 &&
6320 first_entry + num_page_entries <= max_setup_info)
6322 first_entry_store[setup_mode] = first_entry;
6324 if (choice < first_entry)
6325 choice = first_entry;
6326 else if (choice > first_entry + num_page_entries - 1)
6327 choice = first_entry + num_page_entries - 1;
6329 choice_store[setup_mode] = choice;
6331 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
6333 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
6335 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
6336 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
6344 if (!anyScrollbarGadgetActive() &&
6345 IN_VIS_FIELD(x, y) &&
6346 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
6347 y >= 0 && y < num_page_entries)
6349 if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info)
6353 printf("::: TEST/HandleSetupScreen_Generic [%d, %d, %d, %d]\n", Counter(),
6354 button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x);
6360 if (first_entry + y != choice &&
6361 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
6363 PlaySound(SND_MENU_ITEM_ACTIVATING);
6365 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
6366 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
6368 choice = choice_store[setup_mode] = first_entry + y;
6371 if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY)
6373 PlaySound(SND_MENU_ITEM_ACTIVATING);
6375 DrawCursorAndText_Setup(choice, -1, FALSE);
6376 DrawCursorAndText_Setup(y, -1, TRUE);
6378 choice = choice_store[setup_mode] = y;
6383 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
6385 PlaySound(SND_MENU_ITEM_SELECTING);
6387 /* when selecting key headline, execute function for key value change */
6388 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
6389 setup_info[first_entry + y + 1].type & TYPE_KEY)
6392 /* when selecting string value, execute function for list selection */
6393 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
6394 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
6397 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
6399 void (*menu_callback_function)(void) =
6400 setup_info[first_entry + y].value;
6402 FadeSetFromType(setup_info[first_entry + y].type);
6404 menu_callback_function();
6408 if (setup_info[first_entry + y].type & TYPE_VALUE)
6409 changeSetupValue(y, first_entry + y, dx);
6413 else if (!(setup_info[y].type & TYPE_GHOSTED))
6415 PlaySound(SND_MENU_ITEM_SELECTING);
6417 /* when selecting key headline, execute function for key value change */
6418 if (setup_info[y].type & TYPE_KEYTEXT &&
6419 setup_info[y + 1].type & TYPE_KEY)
6422 /* when selecting string value, execute function for list selection */
6423 if (setup_info[y].type & TYPE_STRING && y > 0 &&
6424 setup_info[y - 1].type & TYPE_ENTER_LIST)
6427 if (setup_info[y].type & TYPE_ENTER_OR_LEAVE)
6429 void (*menu_callback_function)(void) = setup_info[y].value;
6431 FadeSetFromType(setup_info[y].type);
6433 menu_callback_function();
6437 if (setup_info[y].type & TYPE_VALUE)
6438 changeSetupValue(y, dx);
6445 void DrawSetupScreen_Input()
6450 FadeOut(REDRAW_FIELD);
6456 setup_info = setup_info_input;
6459 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
6463 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6464 "Joysticks deactivated on this screen");
6466 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6467 "Joysticks deactivated on this screen");
6472 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
6474 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6477 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6478 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6479 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6480 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6481 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6482 initCursor(i, IMG_MENU_BUTTON);
6484 DrawCursorAndText_Setup(i, -1, FALSE);
6488 DeactivateJoystickForCalibration();
6493 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
6494 "Joysticks deactivated on this screen");
6496 DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
6497 "Joysticks deactivated on this screen");
6501 /* create gadgets for setup input menu screen */
6502 FreeScreenGadgets();
6503 CreateScreenGadgets();
6505 /* map gadgets for setup input menu screen */
6506 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6508 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6511 FadeIn(REDRAW_FIELD);
6517 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6519 if (device_name == NULL)
6522 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6525 if (strlen(device_name) > 1)
6527 char c1 = device_name[strlen(device_name) - 1];
6528 char c2 = device_name[strlen(device_name) - 2];
6530 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6531 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6534 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6535 strlen(device_name));
6538 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6541 static struct SetupKeyboardInfo custom_key;
6548 { &custom_key.left, "Joystick Left" },
6549 { &custom_key.right, "Joystick Right" },
6550 { &custom_key.up, "Joystick Up" },
6551 { &custom_key.down, "Joystick Down" },
6552 { &custom_key.snap, "Button 1" },
6553 { &custom_key.drop, "Button 2" }
6555 static char *joystick_name[MAX_PLAYERS] =
6562 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6566 custom_key = setup.input[player_nr].key;
6568 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6569 FONT_INPUT_1_ACTIVE);
6571 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6573 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6574 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6576 if (setup.input[player_nr].use_joystick)
6578 char *device_name = setup.input[player_nr].joy.device_name;
6579 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6580 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6582 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6583 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6587 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6588 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6591 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6593 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6594 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6595 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6596 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6598 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6599 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6600 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6601 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6602 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6603 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6605 for (i = 0; i < 6; i++)
6607 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6609 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6611 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6612 (setup.input[player_nr].use_joystick ?
6614 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6618 static int input_player_nr = 0;
6620 void HandleSetupScreen_Input_Player(int step, int direction)
6622 int old_player_nr = input_player_nr;
6625 new_player_nr = old_player_nr + step * direction;
6626 if (new_player_nr < 0)
6628 if (new_player_nr > MAX_PLAYERS - 1)
6629 new_player_nr = MAX_PLAYERS - 1;
6631 if (new_player_nr != old_player_nr)
6633 input_player_nr = new_player_nr;
6635 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6639 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6641 static int choice = 0;
6644 int pos_start = SETUPINPUT_SCREEN_POS_START;
6645 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6646 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6647 int pos_end = SETUPINPUT_SCREEN_POS_END;
6649 if (button == MB_MENU_INITIALIZE)
6651 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6653 DrawCursorAndText_Setup(choice, -1, TRUE);
6657 else if (button == MB_MENU_LEAVE)
6659 setup_mode = SETUP_MODE_MAIN;
6666 if (mx || my) /* mouse input */
6668 x = (mx - mSX) / 32;
6669 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6671 else if (dx || dy) /* keyboard input */
6673 if (dx && choice == 0)
6674 x = (dx < 0 ? 10 : 12);
6675 else if ((dx && choice == 1) ||
6676 (dx == +1 && choice == 2) ||
6677 (dx == -1 && choice == pos_end))
6678 button = MB_MENU_CHOICE;
6682 if (y >= pos_empty1 && y <= pos_empty2)
6683 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6686 if (y == 0 && dx != 0 && button)
6688 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6690 else if (IN_VIS_FIELD(x, y) &&
6691 y >= pos_start && y <= pos_end &&
6692 !(y >= pos_empty1 && y <= pos_empty2))
6698 DrawCursorAndText_Setup(choice, -1, FALSE);
6699 DrawCursorAndText_Setup(y, -1, TRUE);
6701 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6710 char *device_name = setup.input[input_player_nr].joy.device_name;
6712 if (!setup.input[input_player_nr].use_joystick)
6714 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6716 setJoystickDeviceToNr(device_name, new_device_nr);
6717 setup.input[input_player_nr].use_joystick = TRUE;
6721 int device_nr = getJoystickNrFromDeviceName(device_name);
6722 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6724 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6725 setup.input[input_player_nr].use_joystick = FALSE;
6727 setJoystickDeviceToNr(device_name, new_device_nr);
6730 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6734 if (setup.input[input_player_nr].use_joystick)
6737 CalibrateJoystick(input_player_nr);
6740 CustomizeKeyboard(input_player_nr);
6742 else if (y == pos_end)
6748 setup_mode = SETUP_MODE_MAIN;
6755 void CustomizeKeyboard(int player_nr)
6759 boolean finished = FALSE;
6760 static struct SetupKeyboardInfo custom_key;
6765 } customize_step[] =
6767 { &custom_key.left, "Move Left" },
6768 { &custom_key.right, "Move Right" },
6769 { &custom_key.up, "Move Up" },
6770 { &custom_key.down, "Move Down" },
6771 { &custom_key.snap, "Snap Field" },
6772 { &custom_key.drop, "Drop Element" }
6775 /* read existing key bindings from player setup */
6776 custom_key = setup.input[player_nr].key;
6779 FadeOut(REDRAW_FIELD);
6783 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6791 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6792 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6793 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6794 "Key:", FONT_INPUT_1_ACTIVE);
6795 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6796 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6799 FadeIn(REDRAW_FIELD);
6806 if (PendingEvent()) /* got event */
6814 case EVENT_KEYPRESS:
6816 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6818 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6820 if (key == KSYM_Escape)
6821 FadeSkipNextFadeIn();
6827 /* all keys configured -- wait for "Escape" or "Return" key */
6831 /* press 'Enter' to keep the existing key binding */
6832 if (key == KSYM_Return)
6833 key = *customize_step[step_nr].key;
6835 /* check if key already used */
6836 for (i = 0; i < step_nr; i++)
6837 if (*customize_step[i].key == key)
6842 /* got new key binding */
6843 *customize_step[step_nr].key = key;
6844 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6846 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6847 getKeyNameFromKey(key), FONT_VALUE_1);
6850 /* un-highlight last query */
6851 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6852 customize_step[step_nr - 1].text, FONT_MENU_1);
6853 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6854 "Key:", FONT_MENU_1);
6856 /* press 'Enter' to leave */
6859 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6860 "Press Enter", FONT_TITLE_1);
6864 /* query next key binding */
6865 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6866 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6867 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6868 "Key:", FONT_INPUT_1_ACTIVE);
6869 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6870 getKeyNameFromKey(*customize_step[step_nr].key),
6875 case EVENT_KEYRELEASE:
6876 key_joystick_mapping = 0;
6880 HandleOtherEvents(&event);
6888 /* don't eat all CPU time */
6892 /* write new key bindings back to player setup */
6893 setup.input[player_nr].key = custom_key;
6896 DrawSetupScreen_Input();
6899 static boolean CalibrateJoystickMain(int player_nr)
6901 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6902 int new_joystick_xright = JOYSTICK_XMIDDLE;
6903 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6904 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6905 int new_joystick_xmiddle, new_joystick_ymiddle;
6907 int joystick_fd = joystick.fd[player_nr];
6908 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6909 boolean check[3][3];
6910 int check_remaining = 3 * 3;
6915 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6918 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6922 FadeOut(REDRAW_FIELD);
6926 for (y = 0; y < 3; y++)
6928 for (x = 0; x < 3; x++)
6930 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6931 check[x][y] = FALSE;
6935 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6936 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6937 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6938 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6939 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6940 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6941 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6943 joy_value = Joystick(player_nr);
6944 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6945 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6947 /* eventually uncalibrated center position (joystick could be uncentered) */
6948 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6951 new_joystick_xmiddle = joy_x;
6952 new_joystick_ymiddle = joy_y;
6954 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6956 FadeIn(REDRAW_FIELD);
6958 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6963 if (PendingEvent()) /* got event */
6971 case EVENT_KEYPRESS:
6972 switch (GetEventKey((KeyEvent *)&event, TRUE))
6975 if (check_remaining == 0)
6980 FadeSkipNextFadeIn();
6989 case EVENT_KEYRELEASE:
6990 key_joystick_mapping = 0;
6994 HandleOtherEvents(&event);
6999 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
7002 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
7003 new_joystick_xright = MAX(new_joystick_xright, joy_x);
7004 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
7005 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
7007 setup.input[player_nr].joy.xleft = new_joystick_xleft;
7008 setup.input[player_nr].joy.yupper = new_joystick_yupper;
7009 setup.input[player_nr].joy.xright = new_joystick_xright;
7010 setup.input[player_nr].joy.ylower = new_joystick_ylower;
7011 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
7012 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
7014 CheckJoystickData();
7016 joy_value = Joystick(player_nr);
7018 if (joy_value & JOY_BUTTON && check_remaining == 0)
7021 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
7022 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
7024 if (x != last_x || y != last_y)
7026 DrawFixedGraphic(xpos + last_x, ypos + last_y,
7027 IMG_MENU_CALIBRATE_YELLOW, 0);
7028 DrawFixedGraphic(xpos + x, ypos + y,
7029 IMG_MENU_CALIBRATE_RED, 0);
7034 if (check_remaining > 0 && !check[x+1][y+1])
7036 check[x+1][y+1] = TRUE;
7042 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
7043 setup.input[player_nr].joy.xleft,
7044 setup.input[player_nr].joy.xmiddle,
7045 setup.input[player_nr].joy.xright);
7046 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
7047 setup.input[player_nr].joy.yupper,
7048 setup.input[player_nr].joy.ymiddle,
7049 setup.input[player_nr].joy.ylower);
7058 /* don't eat all CPU time */
7062 /* calibrated center position (joystick should now be centered) */
7063 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
7066 new_joystick_xmiddle = joy_x;
7067 new_joystick_ymiddle = joy_y;
7072 DrawSetupScreen_Input();
7075 /* wait until the last pressed button was released */
7076 while (Joystick(player_nr) & JOY_BUTTON)
7078 if (PendingEvent()) /* got event */
7083 HandleOtherEvents(&event);
7092 void CalibrateJoystick(int player_nr)
7094 if (!CalibrateJoystickMain(player_nr))
7096 char *device_name = setup.input[player_nr].joy.device_name;
7097 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7098 int xpos = mSX - SX;
7099 int ypos = mSY - SY;
7103 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
7104 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
7107 Delay(2000); /* show error message for a short time */
7113 DrawSetupScreen_Input();
7117 void DrawSetupScreen()
7119 DeactivateJoystick();
7121 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
7123 if (setup_mode == SETUP_MODE_INPUT)
7124 DrawSetupScreen_Input();
7125 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7126 DrawChooseTree(&game_speed_current);
7127 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7128 DrawChooseTree(&scroll_delay_current);
7129 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
7130 DrawChooseTree(&screen_mode_current);
7131 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7132 DrawChooseTree(&window_size_current);
7133 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7134 DrawChooseTree(&scaling_type_current);
7135 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7136 DrawChooseTree(&artwork.gfx_current);
7137 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7138 DrawChooseTree(&artwork.snd_current);
7139 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7140 DrawChooseTree(&artwork.mus_current);
7141 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7142 DrawChooseTree(&volume_simple_current);
7143 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7144 DrawChooseTree(&volume_loops_current);
7145 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7146 DrawChooseTree(&volume_music_current);
7147 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7148 DrawChooseTree(&touch_control_current);
7149 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7150 DrawChooseTree(&move_distance_current);
7151 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7152 DrawChooseTree(&drop_distance_current);
7154 DrawSetupScreen_Generic();
7160 void RedrawSetupScreenAfterFullscreenToggle()
7163 if (setup_mode == SETUP_MODE_GRAPHICS ||
7164 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7166 // update list selection from "setup.window_scaling_percent"
7167 execSetupGraphics_setWindowSizes(TRUE);
7172 if (setup_mode == SETUP_MODE_GRAPHICS)
7177 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7179 if (setup_mode == SETUP_MODE_INPUT)
7180 HandleSetupScreen_Input(mx, my, dx, dy, button);
7181 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7182 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7183 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7184 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7185 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
7186 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
7187 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7188 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7189 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7190 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7191 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7192 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7193 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7194 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7195 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7196 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7197 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7198 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7199 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7200 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7201 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7202 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7203 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7204 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7205 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7206 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7207 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7208 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7210 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7217 void HandleGameActions()
7219 if (game_status != GAME_MODE_PLAYING)
7222 GameActions(); /* main game loop */
7224 if (tape.auto_play && !tape.playing)
7225 AutoPlayTape(); /* continue automatically playing next tape */
7229 /* ---------- new screen button stuff -------------------------------------- */
7231 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7236 case SCREEN_CTRL_ID_PREV_LEVEL:
7237 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7238 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7241 case SCREEN_CTRL_ID_NEXT_LEVEL:
7242 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7243 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7246 case SCREEN_CTRL_ID_PREV_LEVEL:
7247 *x = mSX + TILEX * getPrevlevelButtonPos();
7248 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
7251 case SCREEN_CTRL_ID_NEXT_LEVEL:
7252 *x = mSX + TILEX * getNextLevelButtonPos();
7253 *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1);
7257 case SCREEN_CTRL_ID_PREV_PLAYER:
7258 *x = mSX + TILEX * 10;
7259 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7262 case SCREEN_CTRL_ID_NEXT_PLAYER:
7263 *x = mSX + TILEX * 12;
7264 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7268 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7274 int gfx_unpressed, gfx_pressed;
7275 void (*get_gadget_position)(int *, int *, int);
7279 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7282 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7283 getScreenMenuButtonPos,
7284 SCREEN_CTRL_ID_PREV_LEVEL,
7289 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7290 getScreenMenuButtonPos,
7291 SCREEN_CTRL_ID_NEXT_LEVEL,
7296 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7297 getScreenMenuButtonPos,
7298 SCREEN_CTRL_ID_PREV_PLAYER,
7303 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7304 getScreenMenuButtonPos,
7305 SCREEN_CTRL_ID_NEXT_PLAYER,
7313 int gfx_unpressed, gfx_pressed;
7317 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7320 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7322 -1, -1, /* these values are not constant, but can change at runtime */
7324 SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS,
7326 SCREEN_CTRL_ID_SCROLL_UP,
7330 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7332 -1, -1, /* these values are not constant, but can change at runtime */
7334 SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS,
7336 SCREEN_CTRL_ID_SCROLL_DOWN,
7343 int gfx_unpressed, gfx_pressed;
7349 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7352 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7354 -1, -1, /* these values are not constant, but can change at runtime */
7355 -1, -1, /* these values are not constant, but can change at runtime */
7357 SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS,
7358 SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE,
7360 GD_TYPE_SCROLLBAR_VERTICAL,
7361 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7362 "scroll level series vertically"
7366 static void CreateScreenMenubuttons()
7368 struct GadgetInfo *gi;
7369 unsigned int event_mask;
7372 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7374 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7375 int gfx_unpressed, gfx_pressed;
7376 int x, y, width, height;
7377 int gd_x1, gd_x2, gd_y1, gd_y2;
7378 int id = menubutton_info[i].gadget_id;
7380 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7382 menubutton_info[i].get_gadget_position(&x, &y, id);
7384 width = SC_MENUBUTTON_XSIZE;
7385 height = SC_MENUBUTTON_YSIZE;
7387 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7388 gfx_pressed = menubutton_info[i].gfx_pressed;
7389 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7390 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7391 gd_x1 = graphic_info[gfx_unpressed].src_x;
7392 gd_y1 = graphic_info[gfx_unpressed].src_y;
7393 gd_x2 = graphic_info[gfx_pressed].src_x;
7394 gd_y2 = graphic_info[gfx_pressed].src_y;
7396 gi = CreateGadget(GDI_CUSTOM_ID, id,
7397 GDI_CUSTOM_TYPE_ID, i,
7398 GDI_INFO_TEXT, menubutton_info[i].infotext,
7403 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7404 GDI_STATE, GD_BUTTON_UNPRESSED,
7405 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7406 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7407 GDI_DIRECT_DRAW, FALSE,
7408 GDI_EVENT_MASK, event_mask,
7409 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7413 Error(ERR_EXIT, "cannot create gadget");
7415 screen_gadget[id] = gi;
7419 static void CreateScreenScrollbuttons()
7421 struct GadgetInfo *gi;
7422 unsigned int event_mask;
7425 /* these values are not constant, but can change at runtime */
7426 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
7427 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
7428 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
7429 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
7431 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7433 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7434 int gfx_unpressed, gfx_pressed;
7435 int x, y, width, height;
7436 int gd_x1, gd_x2, gd_y1, gd_y2;
7437 int id = scrollbutton_info[i].gadget_id;
7439 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7441 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
7442 y = mSY + scrollbutton_info[i].y;
7443 width = SC_SCROLLBUTTON_XSIZE;
7444 height = SC_SCROLLBUTTON_YSIZE;
7446 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
7447 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
7448 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
7450 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
7451 gfx_pressed = scrollbutton_info[i].gfx_pressed;
7452 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7453 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7454 gd_x1 = graphic_info[gfx_unpressed].src_x;
7455 gd_y1 = graphic_info[gfx_unpressed].src_y;
7456 gd_x2 = graphic_info[gfx_pressed].src_x;
7457 gd_y2 = graphic_info[gfx_pressed].src_y;
7459 gi = CreateGadget(GDI_CUSTOM_ID, id,
7460 GDI_CUSTOM_TYPE_ID, i,
7461 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
7466 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7467 GDI_STATE, GD_BUTTON_UNPRESSED,
7468 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7469 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7470 GDI_DIRECT_DRAW, FALSE,
7471 GDI_EVENT_MASK, event_mask,
7472 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7476 Error(ERR_EXIT, "cannot create gadget");
7478 screen_gadget[id] = gi;
7482 static void CreateScreenScrollbars()
7486 /* these values are not constant, but can change at runtime */
7487 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
7488 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
7489 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
7490 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
7492 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7494 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7495 int gfx_unpressed, gfx_pressed;
7496 int x, y, width, height;
7497 int gd_x1, gd_x2, gd_y1, gd_y2;
7498 struct GadgetInfo *gi;
7499 int items_max, items_visible, item_position;
7500 unsigned int event_mask;
7501 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
7502 int id = scrollbar_info[i].gadget_id;
7504 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
7506 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
7507 y = mSY + scrollbar_info[i].y;
7508 width = scrollbar_info[i].width;
7509 height = scrollbar_info[i].height;
7511 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
7512 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
7514 items_max = num_page_entries;
7515 items_visible = num_page_entries;
7518 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
7519 gfx_pressed = scrollbar_info[i].gfx_pressed;
7520 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7521 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7522 gd_x1 = graphic_info[gfx_unpressed].src_x;
7523 gd_y1 = graphic_info[gfx_unpressed].src_y;
7524 gd_x2 = graphic_info[gfx_pressed].src_x;
7525 gd_y2 = graphic_info[gfx_pressed].src_y;
7527 gi = CreateGadget(GDI_CUSTOM_ID, id,
7528 GDI_CUSTOM_TYPE_ID, i,
7529 GDI_INFO_TEXT, scrollbar_info[i].infotext,
7534 GDI_TYPE, scrollbar_info[i].type,
7535 GDI_SCROLLBAR_ITEMS_MAX, items_max,
7536 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
7537 GDI_SCROLLBAR_ITEM_POSITION, item_position,
7539 GDI_WHEEL_AREA_X, SX,
7540 GDI_WHEEL_AREA_Y, SY,
7541 GDI_WHEEL_AREA_WIDTH, SXSIZE,
7542 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
7544 GDI_WHEEL_AREA_X, 0,
7545 GDI_WHEEL_AREA_Y, 0,
7546 GDI_WHEEL_AREA_WIDTH, WIN_XSIZE,
7547 GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE,
7549 GDI_STATE, GD_BUTTON_UNPRESSED,
7550 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7551 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7552 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
7553 GDI_DIRECT_DRAW, FALSE,
7554 GDI_EVENT_MASK, event_mask,
7555 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7559 Error(ERR_EXIT, "cannot create gadget");
7561 screen_gadget[id] = gi;
7565 void CreateScreenGadgets()
7567 int last_game_status = game_status; /* save current game status */
7569 CreateScreenMenubuttons();
7572 /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */
7573 game_status = GAME_MODE_LEVELS;
7576 CreateScreenScrollbuttons();
7577 CreateScreenScrollbars();
7579 game_status = last_game_status; /* restore current game status */
7582 void FreeScreenGadgets()
7586 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
7587 FreeGadget(screen_gadget[i]);
7590 void MapScreenMenuGadgets(int screen_mask)
7594 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7595 if (screen_mask & menubutton_info[i].screen_mask)
7596 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
7599 void MapScreenGadgets(int num_entries)
7603 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7606 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7607 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7609 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7610 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7613 void MapScreenTreeGadgets(TreeInfo *ti)
7616 MapScreenGadgets(numTreeInfoInGroup(ti));
7618 int num_entries = numTreeInfoInGroup(ti);
7621 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
7624 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
7625 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
7627 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
7628 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7632 static void HandleScreenGadgets(struct GadgetInfo *gi)
7634 int id = gi->custom_id;
7635 int button = gi->event.button;
7636 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7640 case SCREEN_CTRL_ID_PREV_LEVEL:
7641 HandleMainMenu_SelectLevel(step, -1);
7644 case SCREEN_CTRL_ID_NEXT_LEVEL:
7645 HandleMainMenu_SelectLevel(step, +1);
7648 case SCREEN_CTRL_ID_PREV_PLAYER:
7649 HandleSetupScreen_Input_Player(step, -1);
7652 case SCREEN_CTRL_ID_NEXT_PLAYER:
7653 HandleSetupScreen_Input_Player(step, +1);
7656 case SCREEN_CTRL_ID_SCROLL_UP:
7657 if (game_status == GAME_MODE_LEVELS)
7658 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7659 else if (game_status == GAME_MODE_LEVELNR)
7660 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7661 else if (game_status == GAME_MODE_SETUP)
7662 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7665 case SCREEN_CTRL_ID_SCROLL_DOWN:
7666 if (game_status == GAME_MODE_LEVELS)
7667 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7668 else if (game_status == GAME_MODE_LEVELNR)
7669 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7670 else if (game_status == GAME_MODE_SETUP)
7671 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7674 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7675 if (game_status == GAME_MODE_LEVELS)
7676 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7677 else if (game_status == GAME_MODE_LEVELNR)
7678 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7679 else if (game_status == GAME_MODE_SETUP)
7680 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);