1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
26 /* screens on the info screen */
27 #define INFO_MODE_MAIN 0
28 #define INFO_MODE_TITLE 1
29 #define INFO_MODE_ELEMENTS 2
30 #define INFO_MODE_MUSIC 3
31 #define INFO_MODE_CREDITS 4
32 #define INFO_MODE_PROGRAM 5
33 #define INFO_MODE_VERSION 6
34 #define INFO_MODE_LEVELSET 7
36 #define MAX_INFO_MODES 8
38 /* screens on the setup screen */
39 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
40 /* (should also match corresponding entries in src/conf_gfx.c) */
41 #define SETUP_MODE_MAIN 0
42 #define SETUP_MODE_GAME 1
43 #define SETUP_MODE_EDITOR 2
44 #define SETUP_MODE_GRAPHICS 3
45 #define SETUP_MODE_SOUND 4
46 #define SETUP_MODE_ARTWORK 5
47 #define SETUP_MODE_INPUT 6
48 #define SETUP_MODE_TOUCH 7
49 #define SETUP_MODE_SHORTCUTS 8
50 #define SETUP_MODE_SHORTCUTS_1 9
51 #define SETUP_MODE_SHORTCUTS_2 10
52 #define SETUP_MODE_SHORTCUTS_3 11
53 #define SETUP_MODE_SHORTCUTS_4 12
54 #define SETUP_MODE_SHORTCUTS_5 13
56 /* sub-screens on the setup screen (generic) */
57 #define SETUP_MODE_CHOOSE_ARTWORK 14
58 #define SETUP_MODE_CHOOSE_OTHER 15
60 /* sub-screens on the setup screen (specific) */
61 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
62 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
63 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
64 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
65 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
66 #define SETUP_MODE_CHOOSE_RENDERING 21
67 #define SETUP_MODE_CHOOSE_GRAPHICS 22
68 #define SETUP_MODE_CHOOSE_SOUNDS 23
69 #define SETUP_MODE_CHOOSE_MUSIC 24
70 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
71 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
72 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
73 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
74 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
75 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
77 #define MAX_SETUP_MODES 31
79 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
81 /* for input setup functions */
82 #define SETUPINPUT_SCREEN_POS_START 0
83 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
84 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
85 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
87 /* for various menu stuff */
88 #define MENU_SCREEN_START_XPOS 1
89 #define MENU_SCREEN_START_YPOS 2
90 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
91 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
92 #define MENU_TITLE1_YPOS 8
93 #define MENU_TITLE2_YPOS 46
94 #define MENU_SCREEN_INFO_XSTART 16
95 #define MENU_SCREEN_INFO_YSTART1 100
96 #define MENU_SCREEN_INFO_YSTART2 128
97 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
98 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
99 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
100 MENU_SCREEN_INFO_YSTART2 - \
102 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
103 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
104 MENU_SCREEN_INFO_YSTEP)
105 #define NUM_INFO_ELEMENTS_FROM_CONF \
106 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
107 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
108 MAX_MENU_ENTRIES_ON_SCREEN)
109 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
110 MAX_INFO_ELEMENTS_ON_SCREEN), \
111 NUM_INFO_ELEMENTS_FROM_CONF)
112 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
113 #define MAX_MENU_TEXT_LENGTH_BIG 13
114 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
116 /* buttons and scrollbars identifiers */
117 #define SCREEN_CTRL_ID_PREV_LEVEL 0
118 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
119 #define SCREEN_CTRL_ID_PREV_PLAYER 2
120 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
121 #define SCREEN_CTRL_ID_SCROLL_UP 4
122 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
123 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
125 #define NUM_SCREEN_GADGETS 7
127 #define NUM_SCREEN_MENUBUTTONS 4
128 #define NUM_SCREEN_SCROLLBUTTONS 2
129 #define NUM_SCREEN_SCROLLBARS 1
131 #define SCREEN_MASK_MAIN (1 << 0)
132 #define SCREEN_MASK_INPUT (1 << 1)
134 /* graphic position and size values for buttons and scrollbars */
135 #define SC_MENUBUTTON_XSIZE TILEX
136 #define SC_MENUBUTTON_YSIZE TILEY
138 #define SC_SCROLLBUTTON_XSIZE TILEX
139 #define SC_SCROLLBUTTON_YSIZE TILEY
141 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
143 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
144 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
145 SC_SCROLLBUTTON_YSIZE)
147 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
148 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
150 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
151 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
152 SC_SCROLLBUTTON_YSIZE)
154 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
155 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
156 SC_SCROLL_VERTICAL_YSIZE)
158 #define SC_BORDER_SIZE 14
161 /* forward declarations of internal functions */
162 static void HandleScreenGadgets(struct GadgetInfo *);
163 static void HandleSetupScreen_Generic(int, int, int, int, int);
164 static void HandleSetupScreen_Input(int, int, int, int, int);
165 static void CustomizeKeyboard(int);
166 static void CalibrateJoystick(int);
167 static void execSetupGame(void);
168 static void execSetupGraphics(void);
169 static void execSetupSound(void);
170 static void execSetupTouch(void);
171 static void execSetupArtwork(void);
172 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
174 static void DrawChooseLevelSet(void);
175 static void DrawChooseLevelNr(void);
176 static void DrawInfoScreen(void);
177 static void DrawSetupScreen(void);
179 static void DrawInfoScreen_NotAvailable(char *, char *);
180 static void DrawInfoScreen_HelpAnim(int, int, boolean);
181 static void DrawInfoScreen_HelpText(int, int, int, int);
182 static void HandleInfoScreen_Main(int, int, int, int, int);
183 static void HandleInfoScreen_TitleScreen(int);
184 static void HandleInfoScreen_Elements(int);
185 static void HandleInfoScreen_Music(int);
186 static void HandleInfoScreen_Credits(int);
187 static void HandleInfoScreen_Program(int);
188 static void HandleInfoScreen_Version(int);
190 static void MapScreenMenuGadgets(int);
191 static void MapScreenGadgets(int);
192 static void MapScreenTreeGadgets(TreeInfo *);
194 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
196 static int info_mode = INFO_MODE_MAIN;
197 static int setup_mode = SETUP_MODE_MAIN;
199 static TreeInfo *window_sizes = NULL;
200 static TreeInfo *window_size_current = NULL;
202 static TreeInfo *scaling_types = NULL;
203 static TreeInfo *scaling_type_current = NULL;
205 static TreeInfo *rendering_modes = NULL;
206 static TreeInfo *rendering_mode_current = NULL;
208 static TreeInfo *scroll_delays = NULL;
209 static TreeInfo *scroll_delay_current = NULL;
211 static TreeInfo *snapshot_modes = NULL;
212 static TreeInfo *snapshot_mode_current = NULL;
214 static TreeInfo *game_speeds = NULL;
215 static TreeInfo *game_speed_current = NULL;
217 static TreeInfo *volumes_simple = NULL;
218 static TreeInfo *volume_simple_current = NULL;
220 static TreeInfo *volumes_loops = NULL;
221 static TreeInfo *volume_loops_current = NULL;
223 static TreeInfo *volumes_music = NULL;
224 static TreeInfo *volume_music_current = NULL;
226 static TreeInfo *touch_controls = NULL;
227 static TreeInfo *touch_control_current = NULL;
229 static TreeInfo *move_distances = NULL;
230 static TreeInfo *move_distance_current = NULL;
232 static TreeInfo *drop_distances = NULL;
233 static TreeInfo *drop_distance_current = NULL;
235 static TreeInfo *level_number = NULL;
236 static TreeInfo *level_number_current = NULL;
242 } window_sizes_list[] =
247 { 100, "100 % (Default)" },
264 } scaling_types_list[] =
266 { SCALING_QUALITY_NEAREST, "None" },
267 { SCALING_QUALITY_LINEAR, "Linear" },
268 { SCALING_QUALITY_BEST, "Anisotropic" },
277 } rendering_modes_list[] =
279 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
280 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
281 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
282 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
291 } game_speeds_list[] =
300 { 1000, "1/1s (Extremely Slow)" },
305 { 29, "1/35s (Original Supaplex)" },
307 { 20, "1/50s (Normal Speed)" },
308 { 14, "1/70s (Maximum Supaplex)" },
312 { 1, "1/1000s (Extremely Fast)" },
322 } scroll_delays_list[] =
324 { 0, "0 Tiles (No Scroll Delay)" },
327 { 3, "3 Tiles (Default)" },
332 { 8, "8 Tiles (Maximum Scroll Delay)"},
341 } snapshot_modes_list[] =
343 { STR_SNAPSHOT_MODE_OFF, "Off" },
344 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
345 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
346 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
379 } touch_controls_list[] =
381 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
382 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
406 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
407 (s) <= GAME_MODE_SETUP ? (s) : \
408 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
409 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
411 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
412 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
413 (i) <= INFO_MODE_LEVELSET ? (i) : \
416 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
417 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
418 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
419 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
420 SETUP_MODE_CHOOSE_ARTWORK : \
421 SETUP_MODE_CHOOSE_OTHER)
423 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
424 menu.draw_xoffset[GAME_MODE_INFO] : \
425 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
426 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
427 menu.draw_yoffset[GAME_MODE_INFO] : \
428 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
430 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
431 menu.draw_xoffset[GAME_MODE_SETUP] : \
432 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
433 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
434 menu.draw_yoffset[GAME_MODE_SETUP] : \
435 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
437 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
438 DRAW_XOFFSET_INFO(info_mode) : \
439 (s) == GAME_MODE_SETUP ? \
440 DRAW_XOFFSET_SETUP(setup_mode) : \
441 menu.draw_xoffset[DRAW_MODE(s)])
442 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
443 DRAW_YOFFSET_INFO(info_mode) : \
444 (s) == GAME_MODE_SETUP ? \
445 DRAW_YOFFSET_SETUP(setup_mode) : \
446 menu.draw_yoffset[DRAW_MODE(s)])
448 #define mSX (SX + DRAW_XOFFSET(game_status))
449 #define mSY (SY + DRAW_YOFFSET(game_status))
451 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
452 menu.list_size[game_status] : \
453 MAX_MENU_ENTRIES_ON_SCREEN)
455 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
456 NUM_MENU_ENTRIES_ON_SCREEN)
459 /* title display and control definitions */
461 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
462 2 * MAX_NUM_TITLE_MESSAGES)
464 #define NO_DIRECT_LEVEL_SELECT (-1)
467 static int num_title_screens = 0;
469 struct TitleControlInfo
478 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
480 /* main menu display and control definitions */
482 #define MAIN_CONTROL_NAME 0
483 #define MAIN_CONTROL_LEVELS 1
484 #define MAIN_CONTROL_SCORES 2
485 #define MAIN_CONTROL_EDITOR 3
486 #define MAIN_CONTROL_INFO 4
487 #define MAIN_CONTROL_GAME 5
488 #define MAIN_CONTROL_SETUP 6
489 #define MAIN_CONTROL_QUIT 7
490 #define MAIN_CONTROL_PREV_LEVEL 8
491 #define MAIN_CONTROL_NEXT_LEVEL 9
492 #define MAIN_CONTROL_FIRST_LEVEL 10
493 #define MAIN_CONTROL_LAST_LEVEL 11
494 #define MAIN_CONTROL_LEVEL_NUMBER 12
495 #define MAIN_CONTROL_LEVEL_INFO_1 13
496 #define MAIN_CONTROL_LEVEL_INFO_2 14
497 #define MAIN_CONTROL_LEVEL_NAME 15
498 #define MAIN_CONTROL_LEVEL_AUTHOR 16
499 #define MAIN_CONTROL_LEVEL_YEAR 17
500 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
501 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
502 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
503 #define MAIN_CONTROL_TITLE_1 21
504 #define MAIN_CONTROL_TITLE_2 22
505 #define MAIN_CONTROL_TITLE_3 23
507 static char str_main_text_name[10];
508 static char str_main_text_first_level[10];
509 static char str_main_text_last_level[10];
510 static char str_main_text_level_number[10];
512 static char *main_text_name = str_main_text_name;
513 static char *main_text_first_level = str_main_text_first_level;
514 static char *main_text_last_level = str_main_text_last_level;
515 static char *main_text_level_number = str_main_text_level_number;
516 static char *main_text_levels = "Levelset";
517 static char *main_text_scores = "Hall Of Fame";
518 static char *main_text_editor = "Level Creator";
519 static char *main_text_info = "Info Screen";
520 static char *main_text_game = "Start Game";
521 static char *main_text_setup = "Setup";
522 static char *main_text_quit = "Quit";
523 static char *main_text_level_name = level.name;
524 static char *main_text_level_author = level.author;
525 static char *main_text_level_year = NULL;
526 static char *main_text_level_imported_from = NULL;
527 static char *main_text_level_imported_by = NULL;
528 static char *main_text_level_tested_by = NULL;
530 struct MainControlInfo
534 struct MenuPosInfo *pos_button;
537 struct TextPosInfo *pos_text;
540 struct TextPosInfo *pos_input;
544 static struct MainControlInfo main_controls[] =
548 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
549 &menu.main.text.name, &main_text_name,
550 &menu.main.input.name, &setup.player_name,
554 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
555 &menu.main.text.levels, &main_text_levels,
560 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
561 &menu.main.text.scores, &main_text_scores,
566 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
567 &menu.main.text.editor, &main_text_editor,
572 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
573 &menu.main.text.info, &main_text_info,
578 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
579 &menu.main.text.game, &main_text_game,
584 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
585 &menu.main.text.setup, &main_text_setup,
590 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
591 &menu.main.text.quit, &main_text_quit,
595 /* (these two buttons are real gadgets) */
597 MAIN_CONTROL_PREV_LEVEL,
598 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
603 MAIN_CONTROL_NEXT_LEVEL,
604 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
610 MAIN_CONTROL_FIRST_LEVEL,
612 &menu.main.text.first_level, &main_text_first_level,
616 MAIN_CONTROL_LAST_LEVEL,
618 &menu.main.text.last_level, &main_text_last_level,
622 MAIN_CONTROL_LEVEL_NUMBER,
624 &menu.main.text.level_number, &main_text_level_number,
628 MAIN_CONTROL_LEVEL_INFO_1,
630 &menu.main.text.level_info_1, NULL,
634 MAIN_CONTROL_LEVEL_INFO_2,
636 &menu.main.text.level_info_2, NULL,
640 MAIN_CONTROL_LEVEL_NAME,
642 &menu.main.text.level_name, &main_text_level_name,
646 MAIN_CONTROL_LEVEL_AUTHOR,
648 &menu.main.text.level_author, &main_text_level_author,
652 MAIN_CONTROL_LEVEL_YEAR,
654 &menu.main.text.level_year, &main_text_level_year,
658 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
660 &menu.main.text.level_imported_from, &main_text_level_imported_from,
664 MAIN_CONTROL_LEVEL_IMPORTED_BY,
666 &menu.main.text.level_imported_by, &main_text_level_imported_by,
670 MAIN_CONTROL_LEVEL_TESTED_BY,
672 &menu.main.text.level_tested_by, &main_text_level_tested_by,
676 MAIN_CONTROL_TITLE_1,
678 &menu.main.text.title_1, &setup.internal.program_title,
682 MAIN_CONTROL_TITLE_2,
684 &menu.main.text.title_2, &setup.internal.program_copyright,
688 MAIN_CONTROL_TITLE_3,
690 &menu.main.text.title_3, &setup.internal.program_company,
703 static int getTitleScreenGraphic(int nr, boolean initial)
705 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
708 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
710 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
714 static int getTitleScreenGameMode(boolean initial)
716 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
720 static int getTitleMessageGameMode(boolean initial)
722 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
725 static int getTitleAnimMode(struct TitleControlInfo *tci)
727 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
729 return base + tci->local_nr;
733 static int getTitleScreenBackground(boolean initial)
735 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
740 static int getTitleMessageBackground(int nr, boolean initial)
742 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
746 static int getTitleBackground(int nr, boolean initial, boolean is_image)
748 int base = (is_image ?
749 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
750 IMG_BACKGROUND_TITLESCREEN_1) :
751 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
752 IMG_BACKGROUND_TITLEMESSAGE_1));
753 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
754 IMG_BACKGROUND_TITLE);
755 int graphic_local = base + nr;
757 if (graphic_info[graphic_local].bitmap != NULL)
758 return graphic_local;
760 if (graphic_info[graphic_global].bitmap != NULL)
761 return graphic_global;
763 return IMG_UNDEFINED;
766 static int getTitleSound(struct TitleControlInfo *tci)
768 boolean is_image = tci->is_image;
769 int initial = tci->initial;
770 int nr = tci->local_nr;
771 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
772 int base = (is_image ?
773 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
774 SND_BACKGROUND_TITLESCREEN_1) :
775 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
776 SND_BACKGROUND_TITLEMESSAGE_1));
777 int sound_global = menu.sound[mode];
778 int sound_local = base + nr;
781 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
782 nr, initial, is_image,
783 sound_global, getSoundListEntry(sound_global)->filename,
784 sound_local, getSoundListEntry(sound_local)->filename);
787 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
790 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
793 return SND_UNDEFINED;
796 static int getTitleMusic(struct TitleControlInfo *tci)
798 boolean is_image = tci->is_image;
799 int initial = tci->initial;
800 int nr = tci->local_nr;
801 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
802 int base = (is_image ?
803 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
804 MUS_BACKGROUND_TITLESCREEN_1) :
805 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
806 MUS_BACKGROUND_TITLEMESSAGE_1));
807 int music_global = menu.music[mode];
808 int music_local = base + nr;
811 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
812 nr, initial, is_image,
813 music_global, getMusicListEntry(music_global)->filename,
814 music_local, getMusicListEntry(music_local)->filename);
817 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
820 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
823 return MUS_UNDEFINED;
826 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
828 boolean is_image = tci->is_image;
829 boolean initial = tci->initial;
830 boolean first = tci->first;
831 int nr = tci->local_nr;
832 struct TitleMessageInfo tmi;
833 struct TitleFadingInfo ti;
835 tmi = (is_image ? (initial ? (first ?
836 titlescreen_initial_first[nr] :
837 titlescreen_initial[nr])
839 titlescreen_first[nr] :
841 : (initial ? (first ?
842 titlemessage_initial_first[nr] :
843 titlemessage_initial[nr])
845 titlemessage_first[nr] :
848 ti.fade_mode = tmi.fade_mode;
849 ti.fade_delay = tmi.fade_delay;
850 ti.post_delay = tmi.post_delay;
851 ti.auto_delay = tmi.auto_delay;
856 static int compareTitleControlInfo(const void *object1, const void *object2)
858 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
859 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
862 if (tci1->initial != tci2->initial)
863 compare_result = (tci1->initial ? -1 : +1);
864 else if (tci1->sort_priority != tci2->sort_priority)
865 compare_result = tci1->sort_priority - tci2->sort_priority;
866 else if (tci1->is_image != tci2->is_image)
867 compare_result = (tci1->is_image ? -1 : +1);
869 compare_result = tci1->local_nr - tci2->local_nr;
871 return compare_result;
874 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
876 int nr, int sort_priority)
878 title_controls[num_title_screens].is_image = is_image;
879 title_controls[num_title_screens].initial = initial;
880 title_controls[num_title_screens].local_nr = nr;
881 title_controls[num_title_screens].sort_priority = sort_priority;
883 title_controls[num_title_screens].first = FALSE; /* will be set later */
888 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
892 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
894 int graphic = getTitleScreenGraphic(i, initial);
895 Bitmap *bitmap = graphic_info[graphic].bitmap;
896 int sort_priority = graphic_info[graphic].sort_priority;
899 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
902 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
904 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
905 char *filename = getLevelSetTitleMessageFilename(i, initial);
906 int sort_priority = tmi->sort_priority;
908 if (filename != NULL)
909 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
913 static void InitializeTitleControls(boolean show_title_initial)
915 num_title_screens = 0;
917 /* 1st step: initialize title screens for game start (only when starting) */
918 if (show_title_initial)
919 InitializeTitleControls_CheckTitleInfo(TRUE);
921 /* 2nd step: initialize title screens for current level set */
922 InitializeTitleControls_CheckTitleInfo(FALSE);
924 /* sort title screens according to sort_priority and title number */
925 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
926 compareTitleControlInfo);
928 /* mark first title screen */
929 title_controls[0].first = TRUE;
932 static boolean visibleMenuPos(struct MenuPosInfo *pos)
934 return (pos != NULL && pos->x != -1 && pos->y != -1);
937 static boolean visibleTextPos(struct TextPosInfo *pos)
939 return (pos != NULL && pos->x != -1 && pos->y != -1);
942 static void InitializeMainControls()
944 boolean local_team_mode = (!options.network && setup.team_mode);
947 /* set main control text values to dynamically determined values */
948 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
950 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
951 menu.main.text.first_level.size));
952 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
953 menu.main.text.last_level.size));
954 strcpy(main_text_level_number, int2str(level_nr,
955 menu.main.text.level_number.size));
957 main_text_level_year = leveldir_current->year;
958 main_text_level_imported_from = leveldir_current->imported_from;
959 main_text_level_imported_by = leveldir_current->imported_by;
960 main_text_level_tested_by = leveldir_current->tested_by;
962 /* set main control screen positions to dynamically determined values */
963 for (i = 0; main_controls[i].nr != -1; i++)
965 struct MainControlInfo *mci = &main_controls[i];
967 struct MenuPosInfo *pos_button = mci->pos_button;
968 struct TextPosInfo *pos_text = mci->pos_text;
969 struct TextPosInfo *pos_input = mci->pos_input;
970 char *text = (mci->text ? *mci->text : NULL);
971 char *input = (mci->input ? *mci->input : NULL);
972 int button_graphic = mci->button_graphic;
973 int font_text = (pos_text ? pos_text->font : -1);
974 int font_input = (pos_input ? pos_input->font : -1);
976 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
977 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
978 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
979 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
980 int text_chars = (text != NULL ? strlen(text) : 0);
981 int input_chars = (input != NULL ? strlen(input) : 0);
984 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
986 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
987 int text_width = font_text_width * text_chars;
988 int text_height = font_text_height;
989 int input_width = font_input_width * input_chars;
990 int input_height = font_input_height;
992 if (nr == MAIN_CONTROL_NAME)
994 menu.main.input.name.width = input_width;
995 menu.main.input.name.height = input_height;
998 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1000 pos_button->width = button_width;
1001 pos_button->height = button_height;
1004 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1006 /* calculate size for non-clickable text -- needed for text alignment */
1007 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1009 if (pos_text->width == -1 || calculate_text_size)
1010 pos_text->width = text_width;
1011 if (pos_text->height == -1 || calculate_text_size)
1012 pos_text->height = text_height;
1014 if (visibleMenuPos(pos_button))
1016 if (pos_text->x == -1)
1017 pos_text->x = pos_button->x + pos_button->width;
1018 if (pos_text->y == -1)
1020 pos_button->y + (pos_button->height - pos_text->height) / 2;
1024 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1026 if (visibleTextPos(pos_text))
1028 if (pos_input->x == -1)
1029 pos_input->x = pos_text->x + pos_text->width;
1030 if (pos_input->y == -1)
1031 pos_input->y = pos_text->y;
1034 if (pos_input->width == -1)
1035 pos_input->width = input_width;
1036 if (pos_input->height == -1)
1037 pos_input->height = input_height;
1042 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1043 int graphic, boolean pressed)
1045 struct GraphicInfo *g = &graphic_info[graphic];
1048 int xoffset = (pressed ? g->pressed_xoffset : 0);
1049 int yoffset = (pressed ? g->pressed_yoffset : 0);
1051 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1053 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1054 g->width, g->height, dst_x, dst_y);
1057 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1058 boolean active_input,
1059 boolean pressed_button)
1063 for (i = 0; main_controls[i].nr != -1; i++)
1065 struct MainControlInfo *mci = &main_controls[i];
1067 if (mci->nr == nr || nr == -1)
1069 struct MenuPosInfo *pos_button = mci->pos_button;
1070 struct TextPosInfo *pos_text = mci->pos_text;
1071 struct TextPosInfo *pos_input = mci->pos_input;
1072 char *text = (mci->text ? *mci->text : NULL);
1073 char *input = (mci->input ? *mci->input : NULL);
1074 int button_graphic = mci->button_graphic;
1075 int font_text = (pos_text ? pos_text->font : -1);
1076 int font_input = (pos_input ? pos_input->font : -1);
1080 button_graphic = BUTTON_ACTIVE(button_graphic);
1081 font_text = FONT_ACTIVE(font_text);
1086 font_input = FONT_ACTIVE(font_input);
1089 if (visibleMenuPos(pos_button))
1091 struct MenuPosInfo *pos = pos_button;
1092 int x = mSX + pos->x;
1093 int y = mSY + pos->y;
1095 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1096 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1099 if (visibleTextPos(pos_text) && text != NULL)
1101 struct TextPosInfo *pos = pos_text;
1102 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1103 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1106 /* (check why/if this is needed) */
1107 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1109 DrawText(x, y, text, font_text);
1112 if (visibleTextPos(pos_input) && input != NULL)
1114 struct TextPosInfo *pos = pos_input;
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_input);
1122 DrawText(x, y, input, font_input);
1128 static void DrawCursorAndText_Main(int nr, boolean active_text,
1129 boolean pressed_button)
1131 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1135 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1136 boolean pressed_button)
1138 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1142 static struct MainControlInfo *getMainControlInfo(int nr)
1146 for (i = 0; main_controls[i].nr != -1; i++)
1147 if (main_controls[i].nr == nr)
1148 return &main_controls[i];
1153 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1158 int rect_x = ALIGNED_TEXT_XPOS(rect);
1159 int rect_y = ALIGNED_TEXT_YPOS(rect);
1161 return (x >= rect_x && x < rect_x + rect->width &&
1162 y >= rect_y && y < rect_y + rect->height);
1165 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1170 int rect_x = ALIGNED_TEXT_XPOS(rect);
1171 int rect_y = ALIGNED_TEXT_YPOS(rect);
1174 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1175 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1176 (x >= rect_x && x < rect_x + rect->width &&
1177 y >= rect_y && y < rect_y + rect->height));
1180 return (x >= rect_x && x < rect_x + rect->width &&
1181 y >= rect_y && y < rect_y + rect->height);
1184 static void AdjustScrollbar(int id, int items_max, int items_visible,
1187 struct GadgetInfo *gi = screen_gadget[id];
1189 if (item_position > items_max - items_visible)
1190 item_position = items_max - items_visible;
1192 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1193 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1194 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1197 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1199 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1203 static void clearMenuListArea()
1205 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1207 /* correct scrollbar position if placed outside menu (playfield) area */
1208 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1209 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1211 /* clear menu list area, but not title or scrollbar */
1212 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1213 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1216 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1218 static int cursor_array[MAX_LEV_FIELDY];
1219 int x = mSX + TILEX * xpos;
1220 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1225 cursor_array[ypos] = graphic;
1227 graphic = cursor_array[ypos];
1231 graphic = BUTTON_ACTIVE(graphic);
1233 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1234 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1237 static void initCursor(int ypos, int graphic)
1239 drawCursorExt(0, ypos, FALSE, graphic);
1242 static void drawCursor(int ypos, boolean active)
1244 drawCursorExt(0, ypos, active, -1);
1247 static void drawCursorXY(int xpos, int ypos, int graphic)
1249 drawCursorExt(xpos, ypos, FALSE, graphic);
1252 static void drawChooseTreeCursor(int ypos, boolean active)
1254 drawCursorExt(0, ypos, active, -1);
1259 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1260 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1261 setup.internal.program_copyright);
1264 void DrawTitleScreenImage(int nr, boolean initial)
1266 int graphic = getTitleScreenGraphic(nr, initial);
1267 Bitmap *bitmap = graphic_info[graphic].bitmap;
1268 int width = graphic_info[graphic].width;
1269 int height = graphic_info[graphic].height;
1270 int src_x = graphic_info[graphic].src_x;
1271 int src_y = graphic_info[graphic].src_y;
1277 if (width > WIN_XSIZE)
1279 /* image width too large for window => center image horizontally */
1280 src_x = (width - WIN_XSIZE) / 2;
1284 if (height > WIN_YSIZE)
1286 /* image height too large for window => center image vertically */
1287 src_y = (height - WIN_YSIZE) / 2;
1291 /* always display title screens centered */
1292 dst_x = (WIN_XSIZE - width) / 2;
1293 dst_y = (WIN_YSIZE - height) / 2;
1295 SetDrawBackgroundMask(REDRAW_ALL);
1296 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1298 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1300 if (DrawingOnBackground(dst_x, dst_y))
1301 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1303 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1305 redraw_mask = REDRAW_ALL;
1308 void DrawTitleScreenMessage(int nr, boolean initial)
1310 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1311 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1313 if (filename == NULL)
1316 /* force TITLE font on title message screen */
1317 SetFontStatus(getTitleMessageGameMode(initial));
1319 /* if chars *and* width set to "-1", automatically determine width */
1320 if (tmi->chars == -1 && tmi->width == -1)
1321 tmi->width = viewport.window[game_status].width;
1323 /* if lines *and* height set to "-1", automatically determine height */
1324 if (tmi->lines == -1 && tmi->height == -1)
1325 tmi->height = viewport.window[game_status].height;
1327 /* if chars set to "-1", automatically determine by text and font width */
1328 if (tmi->chars == -1)
1329 tmi->chars = tmi->width / getFontWidth(tmi->font);
1331 tmi->width = tmi->chars * getFontWidth(tmi->font);
1333 /* if lines set to "-1", automatically determine by text and font height */
1334 if (tmi->lines == -1)
1335 tmi->lines = tmi->height / getFontHeight(tmi->font);
1337 tmi->height = tmi->lines * getFontHeight(tmi->font);
1339 /* if x set to "-1", automatically determine by width and alignment */
1341 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1343 /* if y set to "-1", automatically determine by height and alignment */
1345 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1347 SetDrawBackgroundMask(REDRAW_ALL);
1348 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1350 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1352 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1353 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1354 tmi->autowrap, tmi->centered, tmi->parse_comments);
1359 void DrawTitleScreen()
1361 KeyboardAutoRepeatOff();
1363 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1368 boolean CheckTitleScreen(boolean levelset_has_changed)
1370 static boolean show_title_initial = TRUE;
1371 boolean show_titlescreen = FALSE;
1373 /* needed to be able to skip title screen, if no image or message defined */
1374 InitializeTitleControls(show_title_initial);
1376 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1377 show_titlescreen = TRUE;
1379 /* show initial title images and messages only once at program start */
1380 show_title_initial = FALSE;
1382 return (show_titlescreen && num_title_screens > 0);
1387 static LevelDirTree *leveldir_last_valid = NULL;
1388 boolean levelset_has_changed = FALSE;
1389 int fade_mask = REDRAW_FIELD;
1391 LimitScreenUpdates(FALSE);
1393 FadeSetLeaveScreen();
1395 /* do not fade out here -- function may continue and fade on editor screen */
1398 FadeSoundsAndMusic();
1400 ExpireSoundLoops(FALSE);
1402 KeyboardAutoRepeatOn();
1405 audio.sound_deactivated = FALSE;
1409 /* needed if last screen was the playing screen, invoked from level editor */
1410 if (level_editor_test_game)
1412 CloseDoor(DOOR_CLOSE_ALL);
1414 SetGameStatus(GAME_MODE_EDITOR);
1421 /* needed if last screen was the setup screen and fullscreen state changed */
1422 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1423 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1425 /* leveldir_current may be invalid (level group, parent link) */
1426 if (!validLevelSeries(leveldir_current))
1427 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1429 if (leveldir_current != leveldir_last_valid)
1430 levelset_has_changed = TRUE;
1432 /* store valid level series information */
1433 leveldir_last_valid = leveldir_current;
1435 init_last = init; /* switch to new busy animation */
1437 /* needed if last screen (level choice) changed graphics, sounds or music */
1438 ReloadCustomArtwork(0);
1440 if (CheckTitleScreen(levelset_has_changed))
1442 game_status_last_screen = GAME_MODE_MAIN;
1444 SetGameStatus(GAME_MODE_TITLE);
1451 /* needed if different viewport properties defined for menues */
1452 ChangeViewportPropertiesIfNeeded();
1454 if (redraw_mask & REDRAW_ALL)
1455 fade_mask = REDRAW_ALL;
1457 if (CheckIfGlobalBorderHasChanged())
1458 fade_mask = REDRAW_ALL;
1462 SetDrawtoField(DRAW_BACKBUFFER);
1464 /* level_nr may have been set to value over handicap with level editor */
1465 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1466 level_nr = leveldir_current->handicap_level;
1468 LoadLevel(level_nr);
1469 LoadScore(level_nr);
1471 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1472 SetDrawDeactivationMask(REDRAW_NONE);
1473 SetDrawBackgroundMask(REDRAW_FIELD);
1475 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1478 if (fade_mask == REDRAW_ALL)
1479 RedrawGlobalBorder();
1484 InitializeMainControls();
1486 DrawCursorAndText_Main(-1, FALSE, FALSE);
1487 DrawPreviewLevelInitial();
1489 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1492 if (TAPE_IS_EMPTY(tape))
1494 DrawCompleteVideoDisplay();
1499 /* create gadgets for main menu screen */
1500 FreeScreenGadgets();
1501 CreateScreenGadgets();
1503 /* map gadgets for main menu screen */
1505 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1507 /* copy actual game door content to door double buffer for OpenDoor() */
1508 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1509 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1511 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1513 DrawMaskedBorder(fade_mask);
1518 /* update screen area with special editor door */
1519 redraw_mask |= REDRAW_ALL;
1522 SetMouseCursor(CURSOR_DEFAULT);
1526 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1529 static void gotoTopLevelDir()
1531 /* move upwards until inside (but not above) top level directory */
1532 while (leveldir_current->node_parent &&
1533 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1535 /* write a "path" into level tree for easy navigation to last level */
1536 if (leveldir_current->node_parent->node_group->cl_first == -1)
1538 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1539 int leveldir_pos = posTreeInfo(leveldir_current);
1540 int num_page_entries;
1541 int cl_first, cl_cursor;
1543 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1544 num_page_entries = num_leveldirs;
1546 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1548 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1549 cl_cursor = leveldir_pos - cl_first;
1551 leveldir_current->node_parent->node_group->cl_first = cl_first;
1552 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1555 leveldir_current = leveldir_current->node_parent;
1559 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1561 static unsigned int title_delay = 0;
1562 static int title_screen_nr = 0;
1563 static int last_sound = -1, last_music = -1;
1564 boolean return_to_main_menu = FALSE;
1565 struct TitleControlInfo *tci;
1568 if (button == MB_MENU_INITIALIZE)
1571 title_screen_nr = 0;
1572 tci = &title_controls[title_screen_nr];
1574 SetAnimStatus(getTitleAnimMode(tci));
1576 last_sound = SND_UNDEFINED;
1577 last_music = MUS_UNDEFINED;
1579 if (num_title_screens != 0)
1581 FadeSetEnterScreen();
1583 /* use individual title fading instead of global "enter screen" fading */
1584 fading = getTitleFading(tci);
1587 if (game_status_last_screen == GAME_MODE_INFO)
1589 if (num_title_screens == 0)
1591 /* switch game mode from title screen mode back to info screen mode */
1592 SetGameStatus(GAME_MODE_INFO);
1594 DrawInfoScreen_NotAvailable("Title screen information:",
1595 "No title screen for this level set.");
1599 FadeSoundsAndMusic();
1602 FadeOut(REDRAW_ALL);
1604 /* only required to update logic for redrawing global border */
1607 /* title screens may have different window size */
1608 ChangeViewportPropertiesIfNeeded();
1611 DrawTitleScreenImage(tci->local_nr, tci->initial);
1613 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1615 sound = getTitleSound(tci);
1616 music = getTitleMusic(tci);
1618 if (sound != last_sound)
1619 PlayMenuSoundExt(sound);
1620 if (music != last_music)
1621 PlayMenuMusicExt(music);
1626 SetMouseCursor(CURSOR_NONE);
1630 DelayReached(&title_delay, 0); /* reset delay counter */
1635 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1636 button = MB_MENU_CHOICE;
1638 if (button == MB_MENU_LEAVE)
1640 return_to_main_menu = TRUE;
1642 else if (button == MB_MENU_CHOICE)
1644 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1646 SetGameStatus(GAME_MODE_INFO);
1648 info_mode = INFO_MODE_MAIN;
1657 if (title_screen_nr < num_title_screens)
1659 tci = &title_controls[title_screen_nr];
1661 SetAnimStatus(getTitleAnimMode(tci));
1663 sound = getTitleSound(tci);
1664 music = getTitleMusic(tci);
1666 if (last_sound != SND_UNDEFINED && sound != last_sound)
1667 FadeSound(last_sound);
1668 if (last_music != MUS_UNDEFINED && music != last_music)
1671 fading = getTitleFading(tci);
1673 FadeOut(REDRAW_ALL);
1676 DrawTitleScreenImage(tci->local_nr, tci->initial);
1678 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1680 sound = getTitleSound(tci);
1681 music = getTitleMusic(tci);
1683 if (sound != last_sound)
1684 PlayMenuSoundExt(sound);
1685 if (music != last_music)
1686 PlayMenuMusicExt(music);
1693 DelayReached(&title_delay, 0); /* reset delay counter */
1697 FadeSoundsAndMusic();
1699 return_to_main_menu = TRUE;
1703 if (return_to_main_menu)
1705 SetMouseCursor(CURSOR_DEFAULT);
1707 /* force full menu screen redraw after displaying title screens */
1708 redraw_mask = REDRAW_ALL;
1710 if (game_status_last_screen == GAME_MODE_INFO)
1712 SetGameStatus(GAME_MODE_INFO);
1714 info_mode = INFO_MODE_MAIN;
1718 else /* default: return to main menu */
1720 SetGameStatus(GAME_MODE_MAIN);
1727 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1729 int old_level_nr = level_nr;
1732 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1733 new_level_nr = selected_level_nr;
1735 new_level_nr = old_level_nr + step * direction;
1737 if (new_level_nr < leveldir_current->first_level)
1738 new_level_nr = leveldir_current->first_level;
1739 if (new_level_nr > leveldir_current->last_level)
1740 new_level_nr = leveldir_current->last_level;
1742 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1744 /* skipping levels is only allowed when trying to skip single level */
1745 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1746 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1748 leveldir_current->handicap_level++;
1749 SaveLevelSetup_SeriesInfo();
1752 new_level_nr = leveldir_current->handicap_level;
1755 if (new_level_nr != old_level_nr)
1757 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1759 PlaySound(SND_MENU_ITEM_SELECTING);
1761 level_nr = new_level_nr;
1763 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1764 int2str(level_nr, menu.main.text.level_number.size),
1765 mci->pos_text->font);
1767 LoadLevel(level_nr);
1768 DrawPreviewLevelInitial();
1772 DrawCompleteVideoDisplay();
1774 /* needed because DrawPreviewLevelInitial() takes some time */
1776 /* SyncDisplay(); */
1780 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1782 static int choice = MAIN_CONTROL_GAME;
1783 static boolean button_pressed_last = FALSE;
1784 boolean button_pressed = FALSE;
1788 if (button == MB_MENU_INITIALIZE)
1790 DrawCursorAndText_Main(choice, TRUE, FALSE);
1795 if (mx || my) /* mouse input */
1799 for (i = 0; main_controls[i].nr != -1; i++)
1801 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1802 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1803 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1805 pos = main_controls[i].nr;
1811 // handle pressed/unpressed state for active/inactive menu buttons
1812 // (if pos != -1, "i" contains index position corresponding to "pos")
1814 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1815 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1816 button_pressed = TRUE;
1818 if (button_pressed != button_pressed_last)
1820 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1823 PlaySound(SND_MENU_BUTTON_PRESSING);
1825 PlaySound(SND_MENU_BUTTON_RELEASING);
1828 else if (dx || dy) /* keyboard input */
1830 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1831 choice == MAIN_CONTROL_SETUP))
1832 button = MB_MENU_CHOICE;
1837 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1839 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1841 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1843 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1845 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1847 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1849 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1853 CloseDoor(DOOR_CLOSE_2);
1855 SetGameStatus(GAME_MODE_LEVELNR);
1857 ChangeViewportPropertiesIfNeeded();
1859 DrawChooseLevelNr();
1861 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1867 PlaySound(SND_MENU_ITEM_ACTIVATING);
1869 DrawCursorAndText_Main(choice, FALSE, FALSE);
1870 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1877 PlaySound(SND_MENU_ITEM_SELECTING);
1879 if (pos == MAIN_CONTROL_NAME)
1881 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1883 HandleTypeName(strlen(setup.player_name), 0);
1885 else if (pos == MAIN_CONTROL_LEVELS)
1891 CloseDoor(DOOR_CLOSE_2);
1893 SetGameStatus(GAME_MODE_LEVELS);
1895 SaveLevelSetup_LastSeries();
1896 SaveLevelSetup_SeriesInfo();
1898 if (setup.internal.choose_from_top_leveldir)
1901 ChangeViewportPropertiesIfNeeded();
1903 DrawChooseLevelSet();
1906 else if (pos == MAIN_CONTROL_SCORES)
1910 CloseDoor(DOOR_CLOSE_2);
1912 SetGameStatus(GAME_MODE_SCORES);
1916 else if (pos == MAIN_CONTROL_EDITOR)
1918 if (leveldir_current->readonly &&
1919 !strEqual(setup.player_name, "Artsoft"))
1920 Request("This level is read only!", REQ_CONFIRM);
1924 CloseDoor(DOOR_CLOSE_2);
1926 SetGameStatus(GAME_MODE_EDITOR);
1928 FadeSetEnterScreen();
1932 else if (pos == MAIN_CONTROL_INFO)
1936 CloseDoor(DOOR_CLOSE_2);
1938 SetGameStatus(GAME_MODE_INFO);
1940 info_mode = INFO_MODE_MAIN;
1942 ChangeViewportPropertiesIfNeeded();
1946 else if (pos == MAIN_CONTROL_GAME)
1950 StartGameActions(options.network, setup.autorecord, level.random_seed);
1952 else if (pos == MAIN_CONTROL_SETUP)
1956 CloseDoor(DOOR_CLOSE_2);
1958 SetGameStatus(GAME_MODE_SETUP);
1960 setup_mode = SETUP_MODE_MAIN;
1962 ChangeViewportPropertiesIfNeeded();
1966 else if (pos == MAIN_CONTROL_QUIT)
1968 SaveLevelSetup_LastSeries();
1969 SaveLevelSetup_SeriesInfo();
1971 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1972 SetGameStatus(GAME_MODE_QUIT);
1977 button_pressed_last = button_pressed;
1981 /* ========================================================================= */
1982 /* info screen functions */
1983 /* ========================================================================= */
1985 static struct TokenInfo *info_info;
1986 static int num_info_info; /* number of info entries shown on screen */
1987 static int max_info_info; /* total number of info entries in list */
1989 static void execInfoTitleScreen()
1991 info_mode = INFO_MODE_TITLE;
1996 static void execInfoElements()
1998 info_mode = INFO_MODE_ELEMENTS;
2003 static void execInfoMusic()
2005 info_mode = INFO_MODE_MUSIC;
2010 static void execInfoCredits()
2012 info_mode = INFO_MODE_CREDITS;
2017 static void execInfoProgram()
2019 info_mode = INFO_MODE_PROGRAM;
2024 static void execInfoVersion()
2026 info_mode = INFO_MODE_VERSION;
2031 static void execInfoLevelSet()
2033 info_mode = INFO_MODE_LEVELSET;
2038 static void execExitInfo()
2040 SetGameStatus(GAME_MODE_MAIN);
2045 static struct TokenInfo info_info_main[] =
2047 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2048 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2049 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2050 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2051 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2052 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2053 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2054 { TYPE_EMPTY, NULL, "" },
2055 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2060 static int getMenuTextFont(int type)
2062 if (type & (TYPE_SWITCH |
2074 static struct TokenInfo *setup_info;
2075 static struct TokenInfo setup_info_input[];
2077 static struct TokenInfo *menu_info;
2079 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2080 int screen_pos, int menu_info_pos_raw,
2083 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2084 struct TokenInfo *ti = &token_info[pos];
2085 int xpos = MENU_SCREEN_START_XPOS;
2086 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2087 int font_nr = getMenuTextFont(ti->type);
2089 if (token_info == setup_info_input)
2090 font_nr = FONT_MENU_1;
2093 font_nr = FONT_ACTIVE(font_nr);
2095 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2097 if (ti->type & ~TYPE_SKIP_ENTRY)
2098 drawCursor(screen_pos, active);
2101 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2104 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2107 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2110 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2113 static char *window_size_text;
2114 static char *scaling_type_text;
2116 static void drawSetupValue(int, int);
2118 static void drawMenuInfoList(int first_entry, int num_page_entries,
2119 int max_page_entries)
2123 if (first_entry + num_page_entries > max_page_entries)
2126 clearMenuListArea();
2128 for (i = 0; i < num_page_entries; i++)
2130 int menu_info_pos = first_entry + i;
2131 struct TokenInfo *si = &menu_info[menu_info_pos];
2132 void *value_ptr = si->value;
2134 /* set some entries to "unchangeable" according to other variables */
2135 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2136 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2137 (value_ptr == &setup.sound_music && !audio.music_available) ||
2138 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2139 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2140 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2141 si->type |= TYPE_GHOSTED;
2143 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2144 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2145 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2146 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2147 else if (si->type & ~TYPE_SKIP_ENTRY)
2148 initCursor(i, IMG_MENU_BUTTON);
2150 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2152 if (si->type & TYPE_VALUE &&
2153 menu_info == setup_info)
2154 drawSetupValue(i, menu_info_pos);
2158 static void DrawInfoScreen_Main()
2160 int fade_mask = REDRAW_FIELD;
2163 if (redraw_mask & REDRAW_ALL)
2164 fade_mask = REDRAW_ALL;
2166 if (CheckIfGlobalBorderHasChanged())
2167 fade_mask = REDRAW_ALL;
2170 FadeSoundsAndMusic();
2172 FreeScreenGadgets();
2173 CreateScreenGadgets();
2175 /* (needed after displaying title screens which disable auto repeat) */
2176 KeyboardAutoRepeatOn();
2178 FadeSetLeaveScreen();
2182 ChangeViewportPropertiesIfNeeded();
2186 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2188 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2190 info_info = info_info_main;
2192 // determine maximal number of info entries that can be displayed on screen
2194 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2197 // determine maximal number of info entries available for menu of info screen
2199 for (i = 0; info_info[i].type != 0; i++)
2202 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2204 MapScreenGadgets(max_info_info);
2209 DrawMaskedBorder(fade_mask);
2216 static void changeSetupValue(int, int, int);
2218 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2219 int mode, int num_page_entries, int max_page_entries)
2221 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2222 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2223 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2224 int *num_page_entries_last = num_page_entries_all_last[game_status];
2225 int *choice_store = choice_stores[game_status];
2226 int *first_entry_store = first_entry_stores[game_status];
2227 int choice = choice_store[mode]; /* starts with 0 */
2228 int first_entry = first_entry_store[mode]; /* starts with 0 */
2230 int y = choice - first_entry;
2232 boolean position_set_by_scrollbar = (dx == 999);
2233 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2236 if (button == MB_MENU_INITIALIZE)
2238 // check if number of menu page entries has changed (may happen by change
2239 // of custom artwork definition value for 'list_size' for this menu screen)
2240 // (in this case, the last menu position most probably has to be corrected)
2241 if (num_page_entries != num_page_entries_last[mode])
2243 choice_store[mode] = first_entry_store[mode] = 0;
2245 choice = first_entry = 0;
2248 num_page_entries_last[mode] = num_page_entries;
2251 /* advance to first valid menu entry */
2252 while (choice < num_page_entries &&
2253 menu_info[choice].type & TYPE_SKIP_ENTRY)
2256 if (position_set_by_scrollbar)
2257 first_entry = first_entry_store[mode] = dy;
2259 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2260 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2262 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2264 if (choice < first_entry)
2266 choice = first_entry;
2268 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2271 else if (choice > first_entry + num_page_entries - 1)
2273 choice = first_entry + num_page_entries - 1;
2275 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2279 choice_store[mode] = choice;
2281 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2285 else if (button == MB_MENU_LEAVE)
2287 PlaySound(SND_MENU_ITEM_SELECTING);
2289 for (i = 0; i < max_page_entries; i++)
2291 if (menu_info[i].type & TYPE_LEAVE_MENU)
2293 void (*menu_callback_function)(void) = menu_info[i].value;
2297 menu_callback_function();
2299 break; /* absolutely needed because function changes 'menu_info'! */
2306 if (mx || my) /* mouse input */
2308 x = (mx - mSX) / 32;
2309 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2311 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2313 /* move cursor instead of scrolling when already at start/end of list */
2314 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2316 else if (dy == +1 * SCROLL_LINE &&
2317 first_entry + num_page_entries == max_page_entries)
2320 /* handle scrolling screen one line or page */
2322 y + dy > num_page_entries - 1)
2324 boolean redraw = FALSE;
2326 if (ABS(dy) == SCROLL_PAGE)
2327 step = num_page_entries - 1;
2329 if (dy < 0 && first_entry > 0)
2331 /* scroll page/line up */
2333 first_entry -= step;
2334 if (first_entry < 0)
2339 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2341 /* scroll page/line down */
2343 first_entry += step;
2344 if (first_entry + num_page_entries > max_page_entries)
2345 first_entry = MAX(0, max_page_entries - num_page_entries);
2352 choice += first_entry - first_entry_store[mode];
2354 if (choice < first_entry)
2356 choice = first_entry;
2358 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2361 else if (choice > first_entry + num_page_entries - 1)
2363 choice = first_entry + num_page_entries - 1;
2365 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2368 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2372 if (choice < first_entry ||
2373 choice > first_entry + num_page_entries - 1)
2374 first_entry += SIGN(dy);
2377 first_entry_store[mode] = first_entry;
2378 choice_store[mode] = choice;
2380 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2382 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2384 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2385 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2393 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2395 if (menu_info[choice].type & menu_navigation_type ||
2396 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2397 menu_info[choice].type & TYPE_YES_NO_AUTO)
2398 button = MB_MENU_CHOICE;
2403 /* jump to next non-empty menu entry (up or down) */
2404 while (first_entry + y > 0 &&
2405 first_entry + y < max_page_entries - 1 &&
2406 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2409 if (!IN_VIS_MENU(x, y))
2411 choice += y - y_old;
2413 if (choice < first_entry)
2414 first_entry = choice;
2415 else if (choice > first_entry + num_page_entries - 1)
2416 first_entry = choice - num_page_entries + 1;
2418 if (first_entry >= 0 &&
2419 first_entry + num_page_entries <= max_page_entries)
2421 first_entry_store[mode] = first_entry;
2423 if (choice < first_entry)
2424 choice = first_entry;
2425 else if (choice > first_entry + num_page_entries - 1)
2426 choice = first_entry + num_page_entries - 1;
2428 choice_store[mode] = choice;
2430 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2432 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2434 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2435 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2442 if (!anyScrollbarGadgetActive() &&
2443 IN_VIS_MENU(x, y) &&
2444 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2445 y >= 0 && y < num_page_entries)
2449 if (first_entry + y != choice &&
2450 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2452 PlaySound(SND_MENU_ITEM_ACTIVATING);
2454 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2455 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2457 choice = choice_store[mode] = first_entry + y;
2460 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2462 PlaySound(SND_MENU_ITEM_SELECTING);
2464 /* when selecting key headline, execute function for key value change */
2465 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2466 menu_info[first_entry + y + 1].type & TYPE_KEY)
2469 /* when selecting string value, execute function for list selection */
2470 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2471 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2474 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2476 void (*menu_callback_function)(void) =
2477 menu_info[first_entry + y].value;
2479 FadeSetFromType(menu_info[first_entry + y].type);
2481 menu_callback_function();
2483 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2484 menu_info == setup_info)
2486 changeSetupValue(y, first_entry + y, dx);
2492 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2494 menu_info = info_info;
2496 HandleMenuScreen(mx, my, dx, dy, button,
2497 info_mode, num_info_info, max_info_info);
2500 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2502 int ystart1 = mSY - SY + 100;
2503 int ystart2 = mSY - SY + 150;
2504 int ybottom = mSY - SY + SYSIZE - 20;
2506 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2508 FadeOut(REDRAW_FIELD);
2513 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2514 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2516 DrawTextSCentered(ybottom, FONT_TEXT_4,
2517 "Press any key or button for info menu");
2519 FadeIn(REDRAW_FIELD);
2522 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2524 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2525 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2526 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2527 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2528 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2529 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2530 int ystep = MENU_SCREEN_INFO_YSTEP;
2531 int element, action, direction;
2539 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2540 infoscreen_step[i] = infoscreen_frame[i] = 0;
2545 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2547 DrawTextSCentered(ybottom, FONT_TEXT_4,
2548 "Press any key or button for next page");
2554 while (helpanim_info[j].element != HELPANIM_LIST_END)
2556 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2561 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2570 j += infoscreen_step[i - start];
2572 element = helpanim_info[j].element;
2573 action = helpanim_info[j].action;
2574 direction = helpanim_info[j].direction;
2577 element = EL_UNKNOWN;
2579 if (action != -1 && direction != -1)
2580 graphic = el_act_dir2img(element, action, direction);
2581 else if (action != -1)
2582 graphic = el_act2img(element, action);
2583 else if (direction != -1)
2584 graphic = el_dir2img(element, direction);
2586 graphic = el2img(element);
2588 delay = helpanim_info[j++].delay;
2593 if (infoscreen_frame[i - start] == 0)
2596 infoscreen_frame[i - start] = delay - 1;
2600 sync_frame = delay - infoscreen_frame[i - start];
2601 infoscreen_frame[i - start]--;
2604 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2606 if (!infoscreen_frame[i - start])
2607 infoscreen_step[i - start] = 0;
2611 if (!infoscreen_frame[i - start])
2612 infoscreen_step[i - start]++;
2613 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2619 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2621 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2622 graphic, sync_frame, USE_MASKING);
2625 DrawInfoScreen_HelpText(element, action, direction, i - start);
2630 redraw_mask |= REDRAW_FIELD;
2635 static char *getHelpText(int element, int action, int direction)
2637 char token[MAX_LINE_LEN];
2639 strcpy(token, element_info[element].token_name);
2642 strcat(token, element_action_info[action].suffix);
2644 if (direction != -1)
2645 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2647 return getHashEntry(helptext_info, token);
2650 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2652 int font_nr = FONT_INFO_ELEMENTS;
2653 int font_width = getFontWidth(font_nr);
2654 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2655 int sy = mSY + 65 + 2 * 32 + 1;
2656 int ystep = TILEY + 4;
2657 int pad_x = sx - SX;
2658 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2659 int max_lines_per_text = 2;
2662 if (action != -1 && direction != -1) /* element.action.direction */
2663 text = getHelpText(element, action, direction);
2665 if (text == NULL && action != -1) /* element.action */
2666 text = getHelpText(element, action, -1);
2668 if (text == NULL && direction != -1) /* element.direction */
2669 text = getHelpText(element, -1, direction);
2671 if (text == NULL) /* base element */
2672 text = getHelpText(element, -1, -1);
2674 if (text == NULL) /* not found */
2675 text = "No description available";
2677 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2678 sy += getFontHeight(font_nr) / 2;
2680 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2681 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2682 TRUE, FALSE, FALSE);
2685 void DrawInfoScreen_TitleScreen()
2687 game_status_last_screen = GAME_MODE_INFO;
2689 SetGameStatus(GAME_MODE_TITLE);
2694 void HandleInfoScreen_TitleScreen(int button)
2696 HandleTitleScreen(0, 0, 0, 0, button);
2699 void DrawInfoScreen_Elements()
2701 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2703 FadeOut(REDRAW_FIELD);
2708 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2710 FadeIn(REDRAW_FIELD);
2715 void HandleInfoScreen_Elements(int button)
2717 static unsigned int info_delay = 0;
2718 static int num_anims;
2719 static int num_pages;
2721 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2724 if (button == MB_MENU_INITIALIZE)
2726 boolean new_element = TRUE;
2730 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2732 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2734 else if (new_element)
2737 new_element = FALSE;
2741 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2745 if (button == MB_MENU_LEAVE)
2747 PlaySound(SND_MENU_ITEM_SELECTING);
2749 info_mode = INFO_MODE_MAIN;
2754 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2756 if (button != MB_MENU_INITIALIZE)
2758 PlaySound(SND_MENU_ITEM_SELECTING);
2763 if (page >= num_pages)
2765 FadeSoundsAndMusic();
2767 info_mode = INFO_MODE_MAIN;
2774 FadeSetNextScreen();
2776 if (button != MB_MENU_INITIALIZE)
2777 FadeOut(REDRAW_FIELD);
2779 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2781 if (button != MB_MENU_INITIALIZE)
2782 FadeIn(REDRAW_FIELD);
2786 if (DelayReached(&info_delay, GameFrameDelay))
2787 if (page < num_pages)
2788 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2790 PlayMenuSoundIfLoop();
2794 void DrawInfoScreen_Music()
2796 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2798 FadeOut(REDRAW_FIELD);
2805 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2807 FadeIn(REDRAW_FIELD);
2810 void HandleInfoScreen_Music(int button)
2812 static struct MusicFileInfo *list = NULL;
2813 int ystart1 = mSY - SY + 100;
2814 int ystart2 = mSY - SY + 150;
2815 int ybottom = mSY - SY + SYSIZE - 20;
2818 if (button == MB_MENU_INITIALIZE)
2820 list = music_file_info;
2824 FadeSoundsAndMusic();
2829 DrawTextSCentered(ystart1, FONT_TEXT_1,
2830 "No music info for this level set.");
2832 DrawTextSCentered(ybottom, FONT_TEXT_4,
2833 "Press any key or button for info menu");
2839 if (button == MB_MENU_LEAVE)
2841 PlaySound(SND_MENU_ITEM_SELECTING);
2843 FadeSoundsAndMusic();
2845 info_mode = INFO_MODE_MAIN;
2850 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2854 if (button != MB_MENU_INITIALIZE)
2856 PlaySound(SND_MENU_ITEM_SELECTING);
2864 FadeSoundsAndMusic();
2866 info_mode = INFO_MODE_MAIN;
2872 FadeSoundsAndMusic();
2874 if (list != music_file_info)
2875 FadeSetNextScreen();
2877 if (button != MB_MENU_INITIALIZE)
2878 FadeOut(REDRAW_FIELD);
2885 int sound = list->music;
2887 if (sound_info[sound].loop)
2888 PlaySoundLoop(sound);
2892 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2896 PlayMusic(list->music);
2898 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2901 if (!strEqual(list->title, UNKNOWN_NAME))
2903 if (!strEqual(list->title_header, UNKNOWN_NAME))
2904 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2906 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2909 if (!strEqual(list->artist, UNKNOWN_NAME))
2911 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2912 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2914 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2916 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2919 if (!strEqual(list->album, UNKNOWN_NAME))
2921 if (!strEqual(list->album_header, UNKNOWN_NAME))
2922 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2924 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2926 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2929 if (!strEqual(list->year, UNKNOWN_NAME))
2931 if (!strEqual(list->year_header, UNKNOWN_NAME))
2932 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2934 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2936 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2939 DrawTextSCentered(ybottom, FONT_TEXT_4,
2940 "Press any key or button for next page");
2942 if (button != MB_MENU_INITIALIZE)
2943 FadeIn(REDRAW_FIELD);
2946 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2947 PlaySoundLoop(list->music);
2950 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2952 int ystart1 = mSY - SY + 100;
2953 int ystart2 = mSY - SY + 150;
2954 int ybottom = mSY - SY + SYSIZE - 20;
2960 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2964 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2965 "Special thanks to");
2966 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2968 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2970 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2971 "\"Boulder Dash\"");
2972 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2974 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2976 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2978 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2979 "First Star Software");
2981 else if (screen_nr == 1)
2983 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2984 "Special thanks to");
2985 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2986 "Klaus Heinz & Volker Wertich");
2987 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2989 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2990 "\"Emerald Mine\"");
2991 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2993 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2995 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2997 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3000 else if (screen_nr == 2)
3002 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3003 "Special thanks to");
3004 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3005 "Michael Stopp & Philip Jespersen");
3006 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3008 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3010 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3012 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3014 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3016 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3017 "Digital Integration");
3019 else if (screen_nr == 3)
3021 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3022 "Special thanks to");
3023 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3024 "Hiroyuki Imabayashi");
3025 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3027 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3029 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3031 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3033 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3035 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3038 else if (screen_nr == 4)
3040 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3041 "Special thanks to");
3042 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3044 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3046 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3047 "J\xfcrgen Bonhagen");
3048 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3049 "for the continuous creation");
3050 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3051 "of outstanding level sets");
3053 else if (screen_nr == 5)
3055 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3057 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3059 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3060 "for ideas and inspiration by");
3061 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3064 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3066 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3068 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3069 "for ideas and inspiration by");
3070 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3073 else if (screen_nr == 6)
3075 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3077 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3080 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3081 "for the code base used for the");
3082 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3083 "native Emerald Mine engine");
3085 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3086 "for the new Emerald Mine engine");
3089 else if (screen_nr == 7)
3091 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3093 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3095 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3096 "for the initial DOS port");
3098 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3100 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3102 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3103 "for some additional toons");
3105 else if (screen_nr == 8)
3107 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3108 "And not to forget:");
3109 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3111 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3112 "All those who contributed");
3113 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3114 "levels to this game");
3115 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3119 DrawTextSCentered(ybottom, FONT_TEXT_4,
3120 "Press any key or button for next page");
3123 void DrawInfoScreen_Credits()
3125 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3127 FadeSoundsAndMusic();
3129 FadeOut(REDRAW_FIELD);
3131 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3133 FadeIn(REDRAW_FIELD);
3136 void HandleInfoScreen_Credits(int button)
3138 static int screen_nr = 0;
3139 int num_screens = 9;
3141 if (button == MB_MENU_INITIALIZE)
3145 // DrawInfoScreen_CreditsScreen(screen_nr);
3148 if (button == MB_MENU_LEAVE)
3150 PlaySound(SND_MENU_ITEM_SELECTING);
3152 info_mode = INFO_MODE_MAIN;
3157 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3159 if (button != MB_MENU_INITIALIZE)
3161 PlaySound(SND_MENU_ITEM_SELECTING);
3166 if (screen_nr >= num_screens)
3168 FadeSoundsAndMusic();
3170 info_mode = INFO_MODE_MAIN;
3177 FadeSetNextScreen();
3179 if (button != MB_MENU_INITIALIZE)
3180 FadeOut(REDRAW_FIELD);
3182 DrawInfoScreen_CreditsScreen(screen_nr);
3184 if (button != MB_MENU_INITIALIZE)
3185 FadeIn(REDRAW_FIELD);
3189 PlayMenuSoundIfLoop();
3193 void DrawInfoScreen_Program()
3195 int ystart1 = mSY - SY + 100;
3196 int ystart2 = mSY - SY + 150;
3197 int ybottom = mSY - SY + SYSIZE - 20;
3200 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3202 FadeOut(REDRAW_FIELD);
3207 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3209 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3210 "This game is Freeware!");
3211 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3212 "If you like it, send e-mail to:");
3213 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3214 setup.internal.program_email);
3215 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3216 "More information and levels:");
3217 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3218 setup.internal.program_website);
3219 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3220 "If you have created new levels,");
3221 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3222 "send them to me to include them!");
3223 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3226 DrawTextSCentered(ybottom, FONT_TEXT_4,
3227 "Press any key or button for info menu");
3229 FadeIn(REDRAW_FIELD);
3232 void HandleInfoScreen_Program(int button)
3234 if (button == MB_MENU_LEAVE)
3236 PlaySound(SND_MENU_ITEM_SELECTING);
3238 info_mode = INFO_MODE_MAIN;
3243 else if (button == MB_MENU_CHOICE)
3245 PlaySound(SND_MENU_ITEM_SELECTING);
3247 FadeSoundsAndMusic();
3249 info_mode = INFO_MODE_MAIN;
3254 PlayMenuSoundIfLoop();
3258 void DrawInfoScreen_Version()
3260 int font_header = FONT_TEXT_3;
3261 int font_text = FONT_TEXT_2;
3262 int xstep = getFontWidth(font_text);
3263 int ystep = getFontHeight(font_text);
3264 int ystart1 = mSY - SY + 100;
3265 int ystart2 = mSY - SY + 150;
3266 int ybottom = mSY - SY + SYSIZE - 20;
3267 int xstart1 = mSX - SX + 2 * xstep;
3268 int xstart2 = mSX - SX + 18 * xstep;
3269 int xstart3 = mSX - SX + 28 * xstep;
3270 SDL_version sdl_version_compiled;
3271 const SDL_version *sdl_version_linked;
3272 int driver_name_len = 10;
3273 #if defined(TARGET_SDL2)
3274 SDL_version sdl_version_linked_ext;
3275 const char *driver_name = NULL;
3277 char driver_name[driver_name_len];
3280 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3282 FadeOut(REDRAW_FIELD);
3287 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3289 DrawTextF(xstart1, ystart2, font_header, "Name");
3290 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3293 DrawTextF(xstart1, ystart2, font_header, "Version");
3294 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3297 DrawTextF(xstart1, ystart2, font_header, "Platform");
3298 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3301 DrawTextF(xstart1, ystart2, font_header, "Target");
3302 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3305 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3306 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3308 ystart2 += 3 * ystep;
3309 DrawTextF(xstart1, ystart2, font_header, "Library");
3310 DrawTextF(xstart2, ystart2, font_header, "compiled");
3311 DrawTextF(xstart3, ystart2, font_header, "linked");
3313 SDL_VERSION(&sdl_version_compiled);
3314 #if defined(TARGET_SDL2)
3315 SDL_GetVersion(&sdl_version_linked_ext);
3316 sdl_version_linked = &sdl_version_linked_ext;
3318 sdl_version_linked = SDL_Linked_Version();
3321 ystart2 += 2 * ystep;
3322 DrawTextF(xstart1, ystart2, font_text, "SDL");
3323 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3324 sdl_version_compiled.major,
3325 sdl_version_compiled.minor,
3326 sdl_version_compiled.patch);
3327 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3328 sdl_version_linked->major,
3329 sdl_version_linked->minor,
3330 sdl_version_linked->patch);
3332 SDL_IMAGE_VERSION(&sdl_version_compiled);
3333 sdl_version_linked = IMG_Linked_Version();
3336 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3337 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3338 sdl_version_compiled.major,
3339 sdl_version_compiled.minor,
3340 sdl_version_compiled.patch);
3341 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3342 sdl_version_linked->major,
3343 sdl_version_linked->minor,
3344 sdl_version_linked->patch);
3346 SDL_MIXER_VERSION(&sdl_version_compiled);
3347 sdl_version_linked = Mix_Linked_Version();
3350 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3351 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3352 sdl_version_compiled.major,
3353 sdl_version_compiled.minor,
3354 sdl_version_compiled.patch);
3355 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3356 sdl_version_linked->major,
3357 sdl_version_linked->minor,
3358 sdl_version_linked->patch);
3360 SDL_NET_VERSION(&sdl_version_compiled);
3361 sdl_version_linked = SDLNet_Linked_Version();
3364 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3365 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3366 sdl_version_compiled.major,
3367 sdl_version_compiled.minor,
3368 sdl_version_compiled.patch);
3369 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3370 sdl_version_linked->major,
3371 sdl_version_linked->minor,
3372 sdl_version_linked->patch);
3374 ystart2 += 3 * ystep;
3375 DrawTextF(xstart1, ystart2, font_header, "Driver");
3376 DrawTextF(xstart2, ystart2, font_header, "Requested");
3377 DrawTextF(xstart3, ystart2, font_header, "Used");
3379 #if defined(TARGET_SDL2)
3380 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3382 SDL_VideoDriverName(driver_name, driver_name_len);
3385 ystart2 += 2 * ystep;
3386 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3387 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3388 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3390 #if defined(TARGET_SDL2)
3391 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3393 SDL_AudioDriverName(driver_name, driver_name_len);
3397 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3398 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3399 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3401 DrawTextSCentered(ybottom, FONT_TEXT_4,
3402 "Press any key or button for info menu");
3404 FadeIn(REDRAW_FIELD);
3407 void HandleInfoScreen_Version(int button)
3409 if (button == MB_MENU_LEAVE)
3411 PlaySound(SND_MENU_ITEM_SELECTING);
3413 info_mode = INFO_MODE_MAIN;
3418 else if (button == MB_MENU_CHOICE)
3420 PlaySound(SND_MENU_ITEM_SELECTING);
3422 FadeSoundsAndMusic();
3424 info_mode = INFO_MODE_MAIN;
3429 PlayMenuSoundIfLoop();
3433 void DrawInfoScreen_LevelSet()
3435 struct TitleMessageInfo *tmi = &readme;
3436 char *filename = getLevelSetInfoFilename();
3437 char *title = "Level Set Information:";
3438 int ystart1 = mSY - SY + 100;
3439 int ybottom = mSY - SY + SYSIZE - 20;
3441 if (filename == NULL)
3443 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3448 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3450 FadeOut(REDRAW_FIELD);
3455 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3457 /* if x position set to "-1", automatically determine by playfield width */
3459 tmi->x = SXSIZE / 2;
3461 /* if y position set to "-1", use static default value */
3465 /* if width set to "-1", automatically determine by playfield width */
3466 if (tmi->width == -1)
3467 tmi->width = SXSIZE - 2 * TILEX;
3469 /* if height set to "-1", automatically determine by playfield height */
3470 if (tmi->height == -1)
3471 tmi->height = SYSIZE - 20 - tmi->y - 10;
3473 /* if chars set to "-1", automatically determine by text and font width */
3474 if (tmi->chars == -1)
3475 tmi->chars = tmi->width / getFontWidth(tmi->font);
3477 tmi->width = tmi->chars * getFontWidth(tmi->font);
3479 /* if lines set to "-1", automatically determine by text and font height */
3480 if (tmi->lines == -1)
3481 tmi->lines = tmi->height / getFontHeight(tmi->font);
3483 tmi->height = tmi->lines * getFontHeight(tmi->font);
3485 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3486 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3487 tmi->autowrap, tmi->centered, tmi->parse_comments);
3489 DrawTextSCentered(ybottom, FONT_TEXT_4,
3490 "Press any key or button for info menu");
3492 FadeIn(REDRAW_FIELD);
3495 void HandleInfoScreen_LevelSet(int button)
3497 if (button == MB_MENU_LEAVE)
3499 PlaySound(SND_MENU_ITEM_SELECTING);
3501 info_mode = INFO_MODE_MAIN;
3506 else if (button == MB_MENU_CHOICE)
3508 PlaySound(SND_MENU_ITEM_SELECTING);
3510 FadeSoundsAndMusic();
3512 info_mode = INFO_MODE_MAIN;
3517 PlayMenuSoundIfLoop();
3521 static void DrawInfoScreen()
3523 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3525 if (info_mode == INFO_MODE_TITLE)
3526 DrawInfoScreen_TitleScreen();
3527 else if (info_mode == INFO_MODE_ELEMENTS)
3528 DrawInfoScreen_Elements();
3529 else if (info_mode == INFO_MODE_MUSIC)
3530 DrawInfoScreen_Music();
3531 else if (info_mode == INFO_MODE_CREDITS)
3532 DrawInfoScreen_Credits();
3533 else if (info_mode == INFO_MODE_PROGRAM)
3534 DrawInfoScreen_Program();
3535 else if (info_mode == INFO_MODE_VERSION)
3536 DrawInfoScreen_Version();
3537 else if (info_mode == INFO_MODE_LEVELSET)
3538 DrawInfoScreen_LevelSet();
3540 DrawInfoScreen_Main();
3542 if (info_mode != INFO_MODE_MAIN &&
3543 info_mode != INFO_MODE_TITLE &&
3544 info_mode != INFO_MODE_MUSIC)
3551 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3553 if (info_mode == INFO_MODE_TITLE)
3554 HandleInfoScreen_TitleScreen(button);
3555 else if (info_mode == INFO_MODE_ELEMENTS)
3556 HandleInfoScreen_Elements(button);
3557 else if (info_mode == INFO_MODE_MUSIC)
3558 HandleInfoScreen_Music(button);
3559 else if (info_mode == INFO_MODE_CREDITS)
3560 HandleInfoScreen_Credits(button);
3561 else if (info_mode == INFO_MODE_PROGRAM)
3562 HandleInfoScreen_Program(button);
3563 else if (info_mode == INFO_MODE_VERSION)
3564 HandleInfoScreen_Version(button);
3565 else if (info_mode == INFO_MODE_LEVELSET)
3566 HandleInfoScreen_LevelSet(button);
3568 HandleInfoScreen_Main(mx, my, dx, dy, button);
3572 /* ========================================================================= */
3573 /* type name functions */
3574 /* ========================================================================= */
3576 void HandleTypeName(int newxpos, Key key)
3578 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3579 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3580 struct TextPosInfo *pos = mci->pos_input;
3581 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3582 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3583 static int xpos = 0;
3584 int font_nr = pos->font;
3585 int font_active_nr = FONT_ACTIVE(font_nr);
3586 int font_width = getFontWidth(font_active_nr);
3587 char key_char = getValidConfigValueChar(getCharFromKey(key));
3588 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3589 boolean is_active = TRUE;
3591 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3595 strcpy(last_player_name, setup.player_name);
3599 #if defined(TARGET_SDL2)
3600 SDL_StartTextInput();
3603 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3605 setup.player_name[xpos] = key_char;
3606 setup.player_name[xpos + 1] = 0;
3610 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3614 setup.player_name[xpos] = 0;
3616 else if (key == KSYM_Return && xpos > 0)
3622 SetGameStatus(GAME_MODE_MAIN);
3624 else if (key == KSYM_Escape)
3626 strcpy(setup.player_name, last_player_name);
3630 SetGameStatus(GAME_MODE_MAIN);
3635 pos->width = (strlen(setup.player_name) + 1) * font_width;
3636 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3638 DrawText(startx, starty, setup.player_name, font_active_nr);
3639 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3643 pos->width = strlen(setup.player_name) * font_width;
3644 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3646 DrawText(startx, starty, setup.player_name, font_nr);
3648 #if defined(TARGET_SDL2)
3649 SDL_StopTextInput();
3655 /* ========================================================================= */
3656 /* tree menu functions */
3657 /* ========================================================================= */
3659 static void DrawChooseTree(TreeInfo **ti_ptr)
3661 int fade_mask = REDRAW_FIELD;
3663 if (CheckIfGlobalBorderHasChanged())
3664 fade_mask = REDRAW_ALL;
3666 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3668 SetGameStatus(GAME_MODE_MAIN);
3677 FreeScreenGadgets();
3678 CreateScreenGadgets();
3684 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3686 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3687 MapScreenTreeGadgets(*ti_ptr);
3689 DrawMaskedBorder(fade_mask);
3696 static void drawChooseTreeList(int first_entry, int num_page_entries,
3700 char *title_string = NULL;
3701 int yoffset_sets = MENU_TITLE1_YPOS;
3702 int yoffset_setup = 16;
3703 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3704 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3706 title_string = ti->infotext;
3708 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3710 clearMenuListArea();
3712 for (i = 0; i < num_page_entries; i++)
3714 TreeInfo *node, *node_first;
3715 int entry_pos = first_entry + i;
3716 int xpos = MENU_SCREEN_START_XPOS;
3717 int ypos = MENU_SCREEN_START_YPOS + i;
3718 int startx = mSX + xpos * 32;
3719 int starty = mSY + ypos * 32;
3720 int font_nr = FONT_TEXT_1;
3721 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3722 int startx_text = startx + font_xoffset;
3723 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3724 int text_size = startx_scrollbar - startx_text;
3725 int max_buffer_len = text_size / getFontWidth(font_nr);
3726 char buffer[max_buffer_len + 1];
3728 node_first = getTreeInfoFirstGroupEntry(ti);
3729 node = getTreeInfoFromPos(node_first, entry_pos);
3731 strncpy(buffer, node->name, max_buffer_len);
3732 buffer[max_buffer_len] = '\0';
3734 DrawText(startx, starty, buffer, font_nr + node->color);
3736 if (node->parent_link)
3737 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3738 else if (node->level_group)
3739 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3741 initCursor(i, IMG_MENU_BUTTON);
3744 redraw_mask |= REDRAW_FIELD;
3747 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3749 TreeInfo *node, *node_first;
3750 int x, last_redraw_mask = redraw_mask;
3751 int ypos = MENU_TITLE2_YPOS;
3752 int font_nr = FONT_TITLE_2;
3754 if (ti->type == TREE_TYPE_LEVEL_NR)
3755 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3757 if (ti->type != TREE_TYPE_LEVEL_DIR)
3760 node_first = getTreeInfoFirstGroupEntry(ti);
3761 node = getTreeInfoFromPos(node_first, entry_pos);
3763 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3765 if (node->parent_link)
3766 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3767 node->node_parent->name);
3768 else if (node->level_group)
3769 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3771 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3772 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3773 node->levels, (node->levels > 1 ? "levels" : "level"),
3776 /* let BackToFront() redraw only what is needed */
3777 redraw_mask = last_redraw_mask;
3778 for (x = 0; x < SCR_FIELDX; x++)
3779 MarkTileDirty(x, 1);
3782 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3785 TreeInfo *ti = *ti_ptr;
3787 int y = ti->cl_cursor;
3788 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3789 int num_entries = numTreeInfoInGroup(ti);
3790 int num_page_entries;
3791 boolean position_set_by_scrollbar = (dx == 999);
3793 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3794 num_page_entries = num_entries;
3796 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3798 if (button == MB_MENU_INITIALIZE)
3800 int num_entries = numTreeInfoInGroup(ti);
3801 int entry_pos = posTreeInfo(ti);
3803 if (ti->cl_first == -1)
3805 /* only on initialization */
3806 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3807 ti->cl_cursor = entry_pos - ti->cl_first;
3809 else if (ti->cl_cursor >= num_page_entries ||
3810 (num_entries > num_page_entries &&
3811 num_entries - ti->cl_first < num_page_entries))
3813 /* only after change of list size (by custom graphic configuration) */
3814 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3815 ti->cl_cursor = entry_pos - ti->cl_first;
3818 if (position_set_by_scrollbar)
3821 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3824 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3825 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3826 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3830 else if (button == MB_MENU_LEAVE)
3834 PlaySound(SND_MENU_ITEM_SELECTING);
3836 if (ti->node_parent)
3838 *ti_ptr = ti->node_parent;
3839 DrawChooseTree(ti_ptr);
3841 else if (game_status == GAME_MODE_SETUP)
3843 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3844 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3845 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3847 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3848 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
3849 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
3850 execSetupGraphics();
3851 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3852 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3853 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3855 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3856 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3857 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3864 if (game_status == GAME_MODE_LEVELNR)
3866 int new_level_nr = atoi(level_number_current->identifier);
3868 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3871 SetGameStatus(GAME_MODE_MAIN);
3879 if (mx || my) /* mouse input */
3881 x = (mx - mSX) / 32;
3882 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3884 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3886 /* move cursor instead of scrolling when already at start/end of list */
3887 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3889 else if (dy == +1 * SCROLL_LINE &&
3890 ti->cl_first + num_page_entries == num_entries)
3893 /* handle scrolling screen one line or page */
3894 if (ti->cl_cursor + dy < 0 ||
3895 ti->cl_cursor + dy > num_page_entries - 1)
3897 boolean redraw = FALSE;
3899 if (ABS(dy) == SCROLL_PAGE)
3900 step = num_page_entries - 1;
3902 if (dy < 0 && ti->cl_first > 0)
3904 /* scroll page/line up */
3906 ti->cl_first -= step;
3907 if (ti->cl_first < 0)
3912 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3914 /* scroll page/line down */
3916 ti->cl_first += step;
3917 if (ti->cl_first + num_page_entries > num_entries)
3918 ti->cl_first = MAX(0, num_entries - num_page_entries);
3925 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3926 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3927 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3929 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3936 /* handle moving cursor one line */
3937 y = ti->cl_cursor + dy;
3942 TreeInfo *node_first, *node_cursor;
3943 int entry_pos = ti->cl_first + y;
3945 node_first = getTreeInfoFirstGroupEntry(ti);
3946 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3948 if (node_cursor->node_group)
3952 PlaySound(SND_MENU_ITEM_SELECTING);
3954 node_cursor->cl_first = ti->cl_first;
3955 node_cursor->cl_cursor = ti->cl_cursor;
3956 *ti_ptr = node_cursor->node_group;
3957 DrawChooseTree(ti_ptr);
3962 else if (dx == -1 && ti->node_parent)
3966 PlaySound(SND_MENU_ITEM_SELECTING);
3968 *ti_ptr = ti->node_parent;
3969 DrawChooseTree(ti_ptr);
3974 if (!anyScrollbarGadgetActive() &&
3975 IN_VIS_MENU(x, y) &&
3976 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3977 y >= 0 && y < num_page_entries)
3981 if (y != ti->cl_cursor)
3983 PlaySound(SND_MENU_ITEM_ACTIVATING);
3985 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3986 drawChooseTreeCursor(y, TRUE);
3987 drawChooseTreeInfo(ti->cl_first + y, ti);
3994 TreeInfo *node_first, *node_cursor;
3995 int entry_pos = ti->cl_first + y;
3997 PlaySound(SND_MENU_ITEM_SELECTING);
3999 node_first = getTreeInfoFirstGroupEntry(ti);
4000 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4002 if (node_cursor->node_group)
4006 node_cursor->cl_first = ti->cl_first;
4007 node_cursor->cl_cursor = ti->cl_cursor;
4008 *ti_ptr = node_cursor->node_group;
4009 DrawChooseTree(ti_ptr);
4011 else if (node_cursor->parent_link)
4015 *ti_ptr = node_cursor->node_parent;
4016 DrawChooseTree(ti_ptr);
4022 node_cursor->cl_first = ti->cl_first;
4023 node_cursor->cl_cursor = ti->cl_cursor;
4024 *ti_ptr = node_cursor;
4026 if (ti->type == TREE_TYPE_LEVEL_DIR)
4028 LoadLevelSetup_SeriesInfo();
4030 SaveLevelSetup_LastSeries();
4031 SaveLevelSetup_SeriesInfo();
4035 if (game_status == GAME_MODE_SETUP)
4037 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4038 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4039 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4041 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4042 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4043 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4044 execSetupGraphics();
4045 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4046 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4047 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4049 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4050 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4051 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4058 if (game_status == GAME_MODE_LEVELNR)
4060 int new_level_nr = atoi(level_number_current->identifier);
4062 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4065 SetGameStatus(GAME_MODE_MAIN);
4074 void DrawChooseLevelSet()
4076 FadeSoundsAndMusic();
4078 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4080 DrawChooseTree(&leveldir_current);
4086 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4088 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4091 void DrawChooseLevelNr()
4095 FadeSoundsAndMusic();
4097 if (level_number != NULL)
4099 freeTreeInfo(level_number);
4101 level_number = NULL;
4104 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4106 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4107 char identifier[32], name[32];
4110 /* temporarily load level info to get level name */
4111 LoadLevelInfoOnly(i);
4113 ti->node_top = &level_number;
4114 ti->sort_priority = 10000 + value;
4115 ti->color = (level.no_valid_file ? FC_BLUE :
4116 LevelStats_getSolved(i) ? FC_GREEN :
4117 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4119 sprintf(identifier, "%d", value);
4120 sprintf(name, "%03d: %s", value,
4121 (level.no_valid_file ? "(no file)" : level.name));
4123 setString(&ti->identifier, identifier);
4124 setString(&ti->name, name);
4125 setString(&ti->name_sorting, name);
4127 pushTreeInfo(&level_number, ti);
4130 /* sort level number values to start with lowest level number */
4131 sortTreeInfo(&level_number);
4133 /* set current level number to current level number */
4134 level_number_current =
4135 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4137 /* if that also fails, set current level number to first available level */
4138 if (level_number_current == NULL)
4139 level_number_current = level_number;
4141 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4143 DrawChooseTree(&level_number_current);
4149 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4151 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4154 void DrawHallOfFame(int highlight_position)
4156 int fade_mask = REDRAW_FIELD;
4158 /* needed if different viewport properties defined for scores */
4159 ChangeViewportPropertiesIfNeeded();
4161 if (CheckIfGlobalBorderHasChanged())
4162 fade_mask = REDRAW_ALL;
4165 FadeSoundsAndMusic();
4167 /* (this is needed when called from GameEnd() after winning a game) */
4168 KeyboardAutoRepeatOn();
4171 /* (this is needed when called from GameEnd() after winning a game) */
4172 SetDrawDeactivationMask(REDRAW_NONE);
4173 SetDrawBackgroundMask(REDRAW_FIELD);
4175 if (highlight_position < 0)
4176 LoadScore(level_nr);
4178 FadeSetEnterScreen();
4187 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4189 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4191 DrawMaskedBorder(fade_mask);
4196 static void drawHallOfFameList(int first_entry, int highlight_position)
4200 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4203 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4204 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4205 "HighScores of Level %d", level_nr);
4207 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4209 int entry = first_entry + i;
4210 boolean active = (entry == highlight_position);
4211 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4212 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4213 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4214 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4215 int dx1 = 3 * getFontWidth(font_nr1);
4216 int dx2 = dx1 + getFontWidth(font_nr1);
4217 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4218 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4219 int sy = mSY + 64 + i * 32;
4221 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4222 DrawText(mSX + dx1, sy, ".", font_nr1);
4224 for (j = 0; j < num_dots; j++)
4225 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4227 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4228 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4230 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4233 redraw_mask |= REDRAW_FIELD;
4236 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4238 static int first_entry = 0;
4239 static int highlight_position = 0;
4240 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4242 if (button == MB_MENU_INITIALIZE)
4245 highlight_position = mx;
4246 drawHallOfFameList(first_entry, highlight_position);
4251 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4252 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4256 if (first_entry > 0)
4258 first_entry -= step;
4259 if (first_entry < 0)
4262 drawHallOfFameList(first_entry, highlight_position);
4267 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4269 first_entry += step;
4270 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4271 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4273 drawHallOfFameList(first_entry, highlight_position);
4276 else if (button == MB_MENU_LEAVE)
4278 PlaySound(SND_MENU_ITEM_SELECTING);
4280 FadeSound(SND_BACKGROUND_SCORES);
4282 SetGameStatus(GAME_MODE_MAIN);
4286 else if (button == MB_MENU_CHOICE)
4288 PlaySound(SND_MENU_ITEM_SELECTING);
4290 FadeSound(SND_BACKGROUND_SCORES);
4292 SetGameStatus(GAME_MODE_MAIN);
4297 if (game_status == GAME_MODE_SCORES)
4298 PlayMenuSoundIfLoop();
4302 /* ========================================================================= */
4303 /* setup screen functions */
4304 /* ========================================================================= */
4306 static struct TokenInfo *setup_info;
4307 static int num_setup_info; /* number of setup entries shown on screen */
4308 static int max_setup_info; /* total number of setup entries in list */
4310 static char *window_size_text;
4311 static char *scaling_type_text;
4312 static char *rendering_mode_text;
4313 static char *scroll_delay_text;
4314 static char *snapshot_mode_text;
4315 static char *game_speed_text;
4316 static char *graphics_set_name;
4317 static char *sounds_set_name;
4318 static char *music_set_name;
4319 static char *volume_simple_text;
4320 static char *volume_loops_text;
4321 static char *volume_music_text;
4322 static char *touch_controls_text;
4323 static char *move_distance_text;
4324 static char *drop_distance_text;
4326 static void execSetupMain()
4328 setup_mode = SETUP_MODE_MAIN;
4333 static void execSetupGame_setGameSpeeds()
4335 if (game_speeds == NULL)
4339 for (i = 0; game_speeds_list[i].value != -1; i++)
4341 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4342 char identifier[32], name[32];
4343 int value = game_speeds_list[i].value;
4344 char *text = game_speeds_list[i].text;
4346 ti->node_top = &game_speeds;
4347 ti->sort_priority = 10000 - value;
4349 sprintf(identifier, "%d", value);
4350 sprintf(name, "%s", text);
4352 setString(&ti->identifier, identifier);
4353 setString(&ti->name, name);
4354 setString(&ti->name_sorting, name);
4355 setString(&ti->infotext, "Game Speed");
4357 pushTreeInfo(&game_speeds, ti);
4360 /* sort game speed values to start with slowest game speed */
4361 sortTreeInfo(&game_speeds);
4363 /* set current game speed to configured game speed value */
4364 game_speed_current =
4365 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4367 /* if that fails, set current game speed to reliable default value */
4368 if (game_speed_current == NULL)
4369 game_speed_current =
4370 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4372 /* if that also fails, set current game speed to first available speed */
4373 if (game_speed_current == NULL)
4374 game_speed_current = game_speeds;
4377 setup.game_frame_delay = atoi(game_speed_current->identifier);
4379 /* needed for displaying game speed text instead of identifier */
4380 game_speed_text = game_speed_current->name;
4383 static void execSetupGame_setScrollDelays()
4385 if (scroll_delays == NULL)
4389 for (i = 0; scroll_delays_list[i].value != -1; i++)
4391 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4392 char identifier[32], name[32];
4393 int value = scroll_delays_list[i].value;
4394 char *text = scroll_delays_list[i].text;
4396 ti->node_top = &scroll_delays;
4397 ti->sort_priority = value;
4399 sprintf(identifier, "%d", value);
4400 sprintf(name, "%s", text);
4402 setString(&ti->identifier, identifier);
4403 setString(&ti->name, name);
4404 setString(&ti->name_sorting, name);
4405 setString(&ti->infotext, "Scroll Delay");
4407 pushTreeInfo(&scroll_delays, ti);
4410 /* sort scroll delay values to start with lowest scroll delay value */
4411 sortTreeInfo(&scroll_delays);
4413 /* set current scroll delay value to configured scroll delay value */
4414 scroll_delay_current =
4415 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4417 /* if that fails, set current scroll delay to reliable default value */
4418 if (scroll_delay_current == NULL)
4419 scroll_delay_current =
4420 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4422 /* if that also fails, set current scroll delay to first available value */
4423 if (scroll_delay_current == NULL)
4424 scroll_delay_current = scroll_delays;
4427 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4429 /* needed for displaying scroll delay text instead of identifier */
4430 scroll_delay_text = scroll_delay_current->name;
4433 static void execSetupGame_setSnapshotModes()
4435 if (snapshot_modes == NULL)
4439 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4441 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4442 char identifier[32], name[32];
4443 char *value = snapshot_modes_list[i].value;
4444 char *text = snapshot_modes_list[i].text;
4446 ti->node_top = &snapshot_modes;
4447 ti->sort_priority = i;
4449 sprintf(identifier, "%s", value);
4450 sprintf(name, "%s", text);
4452 setString(&ti->identifier, identifier);
4453 setString(&ti->name, name);
4454 setString(&ti->name_sorting, name);
4455 setString(&ti->infotext, "Snapshot Mode");
4457 pushTreeInfo(&snapshot_modes, ti);
4460 /* sort snapshot mode values to start with lowest snapshot mode value */
4461 sortTreeInfo(&snapshot_modes);
4463 /* set current snapshot mode value to configured snapshot mode value */
4464 snapshot_mode_current =
4465 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4467 /* if that fails, set current snapshot mode to reliable default value */
4468 if (snapshot_mode_current == NULL)
4469 snapshot_mode_current =
4470 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4472 /* if that also fails, set current snapshot mode to first available value */
4473 if (snapshot_mode_current == NULL)
4474 snapshot_mode_current = snapshot_modes;
4477 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4479 /* needed for displaying snapshot mode text instead of identifier */
4480 snapshot_mode_text = snapshot_mode_current->name;
4483 static void execSetupGame()
4485 execSetupGame_setGameSpeeds();
4486 execSetupGame_setScrollDelays();
4487 execSetupGame_setSnapshotModes();
4489 setup_mode = SETUP_MODE_GAME;
4494 static void execSetupChooseGameSpeed()
4496 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4501 static void execSetupChooseScrollDelay()
4503 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4508 static void execSetupChooseSnapshotMode()
4510 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4515 static void execSetupEditor()
4517 setup_mode = SETUP_MODE_EDITOR;
4522 static void execSetupGraphics_setWindowSizes(boolean update_list)
4524 if (window_sizes != NULL && update_list)
4526 freeTreeInfo(window_sizes);
4528 window_sizes = NULL;
4531 if (window_sizes == NULL)
4533 boolean current_window_size_found = FALSE;
4536 for (i = 0; window_sizes_list[i].value != -1; i++)
4538 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4539 char identifier[32], name[32];
4540 int value = window_sizes_list[i].value;
4541 char *text = window_sizes_list[i].text;
4543 ti->node_top = &window_sizes;
4544 ti->sort_priority = value;
4546 sprintf(identifier, "%d", value);
4547 sprintf(name, "%s", text);
4549 setString(&ti->identifier, identifier);
4550 setString(&ti->name, name);
4551 setString(&ti->name_sorting, name);
4552 setString(&ti->infotext, "Window Scaling");
4554 pushTreeInfo(&window_sizes, ti);
4556 if (value == setup.window_scaling_percent)
4557 current_window_size_found = TRUE;
4560 if (!current_window_size_found)
4562 // add entry for non-preset window scaling value
4564 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4565 char identifier[32], name[32];
4566 int value = setup.window_scaling_percent;
4568 ti->node_top = &window_sizes;
4569 ti->sort_priority = value;
4571 sprintf(identifier, "%d", value);
4572 sprintf(name, "%d %% (Current)", value);
4574 setString(&ti->identifier, identifier);
4575 setString(&ti->name, name);
4576 setString(&ti->name_sorting, name);
4577 setString(&ti->infotext, "Window Scaling");
4579 pushTreeInfo(&window_sizes, ti);
4582 /* sort window size values to start with lowest window size value */
4583 sortTreeInfo(&window_sizes);
4585 /* set current window size value to configured window size value */
4586 window_size_current =
4587 getTreeInfoFromIdentifier(window_sizes,
4588 i_to_a(setup.window_scaling_percent));
4590 /* if that fails, set current window size to reliable default value */
4591 if (window_size_current == NULL)
4592 window_size_current =
4593 getTreeInfoFromIdentifier(window_sizes,
4594 i_to_a(STD_WINDOW_SCALING_PERCENT));
4596 /* if that also fails, set current window size to first available value */
4597 if (window_size_current == NULL)
4598 window_size_current = window_sizes;
4601 setup.window_scaling_percent = atoi(window_size_current->identifier);
4603 /* needed for displaying window size text instead of identifier */
4604 window_size_text = window_size_current->name;
4607 static void execSetupGraphics_setScalingTypes()
4609 if (scaling_types == NULL)
4613 for (i = 0; scaling_types_list[i].value != NULL; i++)
4615 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4616 char identifier[32], name[32];
4617 char *value = scaling_types_list[i].value;
4618 char *text = scaling_types_list[i].text;
4620 ti->node_top = &scaling_types;
4621 ti->sort_priority = i;
4623 sprintf(identifier, "%s", value);
4624 sprintf(name, "%s", text);
4626 setString(&ti->identifier, identifier);
4627 setString(&ti->name, name);
4628 setString(&ti->name_sorting, name);
4629 setString(&ti->infotext, "Anti-Aliasing");
4631 pushTreeInfo(&scaling_types, ti);
4634 /* sort scaling type values to start with lowest scaling type value */
4635 sortTreeInfo(&scaling_types);
4637 /* set current scaling type value to configured scaling type value */
4638 scaling_type_current =
4639 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4641 /* if that fails, set current scaling type to reliable default value */
4642 if (scaling_type_current == NULL)
4643 scaling_type_current =
4644 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4646 /* if that also fails, set current scaling type to first available value */
4647 if (scaling_type_current == NULL)
4648 scaling_type_current = scaling_types;
4651 setup.window_scaling_quality = scaling_type_current->identifier;
4653 /* needed for displaying scaling type text instead of identifier */
4654 scaling_type_text = scaling_type_current->name;
4657 static void execSetupGraphics_setRenderingModes()
4659 if (rendering_modes == NULL)
4663 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4665 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4666 char identifier[32], name[32];
4667 char *value = rendering_modes_list[i].value;
4668 char *text = rendering_modes_list[i].text;
4670 ti->node_top = &rendering_modes;
4671 ti->sort_priority = i;
4673 sprintf(identifier, "%s", value);
4674 sprintf(name, "%s", text);
4676 setString(&ti->identifier, identifier);
4677 setString(&ti->name, name);
4678 setString(&ti->name_sorting, name);
4679 setString(&ti->infotext, "Special Rendering");
4681 pushTreeInfo(&rendering_modes, ti);
4684 /* sort rendering mode values to start with lowest rendering mode value */
4685 sortTreeInfo(&rendering_modes);
4687 /* set current rendering mode value to configured rendering mode value */
4688 rendering_mode_current =
4689 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4691 /* if that fails, set current rendering mode to reliable default value */
4692 if (rendering_mode_current == NULL)
4693 rendering_mode_current =
4694 getTreeInfoFromIdentifier(rendering_modes,
4695 STR_SPECIAL_RENDERING_DEFAULT);
4697 /* if that also fails, set current rendering mode to first available one */
4698 if (rendering_mode_current == NULL)
4699 rendering_mode_current = rendering_modes;
4702 setup.screen_rendering_mode = rendering_mode_current->identifier;
4704 /* needed for displaying rendering mode text instead of identifier */
4705 rendering_mode_text = rendering_mode_current->name;
4708 static void execSetupGraphics()
4710 // update "setup.window_scaling_percent" from list selection
4711 // (in this case, window scaling was changed on setup screen)
4712 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4713 execSetupGraphics_setWindowSizes(FALSE);
4715 // update list selection from "setup.window_scaling_percent"
4716 // (window scaling may have changed by resizing the window)
4717 execSetupGraphics_setWindowSizes(TRUE);
4719 execSetupGraphics_setScalingTypes();
4720 execSetupGraphics_setRenderingModes();
4722 setup_mode = SETUP_MODE_GRAPHICS;
4726 #if defined(TARGET_SDL2)
4727 // window scaling may have changed at this point
4728 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4730 // window scaling quality may have changed at this point
4731 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4732 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4734 // screen rendering mode may have changed at this point
4735 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4739 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4740 static void execSetupChooseWindowSize()
4742 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4747 static void execSetupChooseScalingType()
4749 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4754 static void execSetupChooseRenderingMode()
4756 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4762 static void execSetupChooseVolumeSimple()
4764 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4769 static void execSetupChooseVolumeLoops()
4771 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4776 static void execSetupChooseVolumeMusic()
4778 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4783 static void execSetupSound()
4785 if (volumes_simple == NULL)
4787 boolean current_volume_simple_found = FALSE;
4790 for (i = 0; volumes_list[i].value != -1; i++)
4792 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4793 char identifier[32], name[32];
4794 int value = volumes_list[i].value;
4795 char *text = volumes_list[i].text;
4797 ti->node_top = &volumes_simple;
4798 ti->sort_priority = value;
4800 sprintf(identifier, "%d", value);
4801 sprintf(name, "%s", text);
4803 setString(&ti->identifier, identifier);
4804 setString(&ti->name, name);
4805 setString(&ti->name_sorting, name);
4806 setString(&ti->infotext, "Sound Volume");
4808 pushTreeInfo(&volumes_simple, ti);
4810 if (value == setup.volume_simple)
4811 current_volume_simple_found = TRUE;
4814 if (!current_volume_simple_found)
4816 // add entry for non-preset volume value
4818 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4819 char identifier[32], name[32];
4820 int value = setup.volume_simple;
4822 ti->node_top = &volumes_simple;
4823 ti->sort_priority = value;
4825 sprintf(identifier, "%d", value);
4826 sprintf(name, "%d %% (Current)", value);
4828 setString(&ti->identifier, identifier);
4829 setString(&ti->name, name);
4830 setString(&ti->name_sorting, name);
4831 setString(&ti->infotext, "Sound Volume");
4833 pushTreeInfo(&volumes_simple, ti);
4836 /* sort volume values to start with lowest volume value */
4837 sortTreeInfo(&volumes_simple);
4839 /* set current volume value to configured volume value */
4840 volume_simple_current =
4841 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4843 /* if that fails, set current volume to reliable default value */
4844 if (volume_simple_current == NULL)
4845 volume_simple_current =
4846 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4848 /* if that also fails, set current volume to first available value */
4849 if (volume_simple_current == NULL)
4850 volume_simple_current = volumes_simple;
4853 if (volumes_loops == NULL)
4855 boolean current_volume_loops_found = FALSE;
4858 for (i = 0; volumes_list[i].value != -1; i++)
4860 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4861 char identifier[32], name[32];
4862 int value = volumes_list[i].value;
4863 char *text = volumes_list[i].text;
4865 ti->node_top = &volumes_loops;
4866 ti->sort_priority = value;
4868 sprintf(identifier, "%d", value);
4869 sprintf(name, "%s", text);
4871 setString(&ti->identifier, identifier);
4872 setString(&ti->name, name);
4873 setString(&ti->name_sorting, name);
4874 setString(&ti->infotext, "Loops Volume");
4876 pushTreeInfo(&volumes_loops, ti);
4878 if (value == setup.volume_loops)
4879 current_volume_loops_found = TRUE;
4882 if (!current_volume_loops_found)
4884 // add entry for non-preset volume value
4886 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4887 char identifier[32], name[32];
4888 int value = setup.volume_loops;
4890 ti->node_top = &volumes_loops;
4891 ti->sort_priority = value;
4893 sprintf(identifier, "%d", value);
4894 sprintf(name, "%d %% (Current)", value);
4896 setString(&ti->identifier, identifier);
4897 setString(&ti->name, name);
4898 setString(&ti->name_sorting, name);
4899 setString(&ti->infotext, "Loops Volume");
4901 pushTreeInfo(&volumes_loops, ti);
4904 /* sort volume values to start with lowest volume value */
4905 sortTreeInfo(&volumes_loops);
4907 /* set current volume value to configured volume value */
4908 volume_loops_current =
4909 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4911 /* if that fails, set current volume to reliable default value */
4912 if (volume_loops_current == NULL)
4913 volume_loops_current =
4914 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4916 /* if that also fails, set current volume to first available value */
4917 if (volume_loops_current == NULL)
4918 volume_loops_current = volumes_loops;
4921 if (volumes_music == NULL)
4923 boolean current_volume_music_found = FALSE;
4926 for (i = 0; volumes_list[i].value != -1; i++)
4928 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4929 char identifier[32], name[32];
4930 int value = volumes_list[i].value;
4931 char *text = volumes_list[i].text;
4933 ti->node_top = &volumes_music;
4934 ti->sort_priority = value;
4936 sprintf(identifier, "%d", value);
4937 sprintf(name, "%s", text);
4939 setString(&ti->identifier, identifier);
4940 setString(&ti->name, name);
4941 setString(&ti->name_sorting, name);
4942 setString(&ti->infotext, "Music Volume");
4944 pushTreeInfo(&volumes_music, ti);
4946 if (value == setup.volume_music)
4947 current_volume_music_found = TRUE;
4950 if (!current_volume_music_found)
4952 // add entry for non-preset volume value
4954 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4955 char identifier[32], name[32];
4956 int value = setup.volume_music;
4958 ti->node_top = &volumes_music;
4959 ti->sort_priority = value;
4961 sprintf(identifier, "%d", value);
4962 sprintf(name, "%d %% (Current)", value);
4964 setString(&ti->identifier, identifier);
4965 setString(&ti->name, name);
4966 setString(&ti->name_sorting, name);
4967 setString(&ti->infotext, "Music Volume");
4969 pushTreeInfo(&volumes_music, ti);
4972 /* sort volume values to start with lowest volume value */
4973 sortTreeInfo(&volumes_music);
4975 /* set current volume value to configured volume value */
4976 volume_music_current =
4977 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4979 /* if that fails, set current volume to reliable default value */
4980 if (volume_music_current == NULL)
4981 volume_music_current =
4982 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4984 /* if that also fails, set current volume to first available value */
4985 if (volume_music_current == NULL)
4986 volume_music_current = volumes_music;
4989 setup.volume_simple = atoi(volume_simple_current->identifier);
4990 setup.volume_loops = atoi(volume_loops_current->identifier);
4991 setup.volume_music = atoi(volume_music_current->identifier);
4993 /* needed for displaying volume text instead of identifier */
4994 volume_simple_text = volume_simple_current->name;
4995 volume_loops_text = volume_loops_current->name;
4996 volume_music_text = volume_music_current->name;
4998 setup_mode = SETUP_MODE_SOUND;
5003 static void execSetupChooseTouchControls()
5005 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5010 static void execSetupChooseMoveDistance()
5012 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5017 static void execSetupChooseDropDistance()
5019 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5024 static void execSetupTouch()
5026 if (touch_controls == NULL)
5030 for (i = 0; touch_controls_list[i].value != NULL; i++)
5032 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5033 char identifier[32], name[32];
5034 char *value = touch_controls_list[i].value;
5035 char *text = touch_controls_list[i].text;
5037 ti->node_top = &touch_controls;
5038 ti->sort_priority = i;
5040 sprintf(identifier, "%s", value);
5041 sprintf(name, "%s", text);
5043 setString(&ti->identifier, identifier);
5044 setString(&ti->name, name);
5045 setString(&ti->name_sorting, name);
5046 setString(&ti->infotext, "Control Type");
5048 pushTreeInfo(&touch_controls, ti);
5051 /* sort touch control values to start with lowest touch control value */
5052 sortTreeInfo(&touch_controls);
5054 /* set current touch control value to configured touch control value */
5055 touch_control_current =
5056 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5058 /* if that fails, set current touch control to reliable default value */
5059 if (touch_control_current == NULL)
5060 touch_control_current =
5061 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5063 /* if that also fails, set current touch control to first available value */
5064 if (touch_control_current == NULL)
5065 touch_control_current = touch_controls;
5068 if (move_distances == NULL)
5072 for (i = 0; distances_list[i].value != -1; i++)
5074 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5075 char identifier[32], name[32];
5076 int value = distances_list[i].value;
5077 char *text = distances_list[i].text;
5079 ti->node_top = &move_distances;
5080 ti->sort_priority = value;
5082 sprintf(identifier, "%d", value);
5083 sprintf(name, "%s", text);
5085 setString(&ti->identifier, identifier);
5086 setString(&ti->name, name);
5087 setString(&ti->name_sorting, name);
5088 setString(&ti->infotext, "Move Distance");
5090 pushTreeInfo(&move_distances, ti);
5093 /* sort distance values to start with lowest distance value */
5094 sortTreeInfo(&move_distances);
5096 /* set current distance value to configured distance value */
5097 move_distance_current =
5098 getTreeInfoFromIdentifier(move_distances,
5099 i_to_a(setup.touch.move_distance));
5101 /* if that fails, set current distance to reliable default value */
5102 if (move_distance_current == NULL)
5103 move_distance_current =
5104 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5106 /* if that also fails, set current distance to first available value */
5107 if (move_distance_current == NULL)
5108 move_distance_current = move_distances;
5111 if (drop_distances == NULL)
5115 for (i = 0; distances_list[i].value != -1; i++)
5117 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5118 char identifier[32], name[32];
5119 int value = distances_list[i].value;
5120 char *text = distances_list[i].text;
5122 ti->node_top = &drop_distances;
5123 ti->sort_priority = value;
5125 sprintf(identifier, "%d", value);
5126 sprintf(name, "%s", text);
5128 setString(&ti->identifier, identifier);
5129 setString(&ti->name, name);
5130 setString(&ti->name_sorting, name);
5131 setString(&ti->infotext, "Drop Distance");
5133 pushTreeInfo(&drop_distances, ti);
5136 /* sort distance values to start with lowest distance value */
5137 sortTreeInfo(&drop_distances);
5139 /* set current distance value to configured distance value */
5140 drop_distance_current =
5141 getTreeInfoFromIdentifier(drop_distances,
5142 i_to_a(setup.touch.drop_distance));
5144 /* if that fails, set current distance to reliable default value */
5145 if (drop_distance_current == NULL)
5146 drop_distance_current =
5147 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5149 /* if that also fails, set current distance to first available value */
5150 if (drop_distance_current == NULL)
5151 drop_distance_current = drop_distances;
5154 setup.touch.control_type = touch_control_current->identifier;
5155 setup.touch.move_distance = atoi(move_distance_current->identifier);
5156 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5158 /* needed for displaying volume text instead of identifier */
5159 touch_controls_text = touch_control_current->name;
5160 move_distance_text = move_distance_current->name;
5161 drop_distance_text = drop_distance_current->name;
5163 setup_mode = SETUP_MODE_TOUCH;
5168 static void execSetupArtwork()
5171 printf("::: '%s', '%s', '%s'\n",
5172 artwork.gfx_current->subdir,
5173 artwork.gfx_current->fullpath,
5174 artwork.gfx_current->basepath);
5177 setup.graphics_set = artwork.gfx_current->identifier;
5178 setup.sounds_set = artwork.snd_current->identifier;
5179 setup.music_set = artwork.mus_current->identifier;
5181 /* needed if last screen (setup choice) changed graphics, sounds or music */
5182 ReloadCustomArtwork(0);
5184 /* needed for displaying artwork name instead of artwork identifier */
5185 graphics_set_name = artwork.gfx_current->name;
5186 sounds_set_name = artwork.snd_current->name;
5187 music_set_name = artwork.mus_current->name;
5189 setup_mode = SETUP_MODE_ARTWORK;
5194 static void execSetupChooseGraphics()
5196 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5201 static void execSetupChooseSounds()
5203 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5208 static void execSetupChooseMusic()
5210 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5215 #if !defined(PLATFORM_ANDROID)
5216 static void execSetupInput()
5218 setup_mode = SETUP_MODE_INPUT;
5224 static void execSetupShortcuts()
5226 setup_mode = SETUP_MODE_SHORTCUTS;
5231 static void execSetupShortcuts1()
5233 setup_mode = SETUP_MODE_SHORTCUTS_1;
5238 static void execSetupShortcuts2()
5240 setup_mode = SETUP_MODE_SHORTCUTS_2;
5245 static void execSetupShortcuts3()
5247 setup_mode = SETUP_MODE_SHORTCUTS_3;
5252 static void execSetupShortcuts4()
5254 setup_mode = SETUP_MODE_SHORTCUTS_4;
5259 static void execSetupShortcuts5()
5261 setup_mode = SETUP_MODE_SHORTCUTS_5;
5266 static void execExitSetup()
5268 SetGameStatus(GAME_MODE_MAIN);
5273 static void execSaveAndExitSetup()
5279 static struct TokenInfo setup_info_main[] =
5281 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5282 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5283 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5284 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5285 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5286 #if !defined(PLATFORM_ANDROID)
5287 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5288 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5290 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5292 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5293 { TYPE_EMPTY, NULL, "" },
5294 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5295 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5300 static struct TokenInfo setup_info_game[] =
5302 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5303 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5304 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5305 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5306 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5307 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5308 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5309 { TYPE_STRING, &game_speed_text, "" },
5311 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5312 { TYPE_STRING, &scroll_delay_text, "" },
5314 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5315 { TYPE_STRING, &snapshot_mode_text, "" },
5316 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5317 { TYPE_EMPTY, NULL, "" },
5318 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5323 static struct TokenInfo setup_info_editor[] =
5326 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5327 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5328 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5329 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5330 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5331 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5332 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5333 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5335 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5336 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5337 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5339 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5341 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5342 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5343 { TYPE_EMPTY, NULL, "" },
5345 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5346 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5347 { TYPE_EMPTY, NULL, "" },
5349 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5350 { TYPE_EMPTY, NULL, "" },
5351 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5356 static struct TokenInfo setup_info_graphics[] =
5358 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5359 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5360 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5361 { TYPE_STRING, &window_size_text, "" },
5362 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5363 { TYPE_STRING, &scaling_type_text, "" },
5364 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5365 { TYPE_STRING, &rendering_mode_text, "" },
5368 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5369 { TYPE_STRING, &scroll_delay_text, "" },
5371 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5372 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5373 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5374 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5375 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5376 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5377 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5378 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5379 { TYPE_EMPTY, NULL, "" },
5380 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5385 static struct TokenInfo setup_info_sound[] =
5387 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5388 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5389 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5390 { TYPE_EMPTY, NULL, "" },
5391 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5392 { TYPE_STRING, &volume_simple_text, "" },
5393 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5394 { TYPE_STRING, &volume_loops_text, "" },
5395 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5396 { TYPE_STRING, &volume_music_text, "" },
5397 { TYPE_EMPTY, NULL, "" },
5398 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5403 static struct TokenInfo setup_info_artwork[] =
5405 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5406 { TYPE_STRING, &graphics_set_name, "" },
5407 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5408 { TYPE_STRING, &sounds_set_name, "" },
5409 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5410 { TYPE_STRING, &music_set_name, "" },
5411 { TYPE_EMPTY, NULL, "" },
5412 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5413 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5414 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5415 { TYPE_EMPTY, NULL, "" },
5416 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5421 static struct TokenInfo setup_info_input[] =
5423 { TYPE_SWITCH, NULL, "Player:" },
5424 { TYPE_SWITCH, NULL, "Device:" },
5425 { TYPE_ENTER_MENU, NULL, "" },
5426 { TYPE_EMPTY, NULL, "" },
5427 { TYPE_EMPTY, NULL, "" },
5428 { TYPE_EMPTY, NULL, "" },
5429 { TYPE_EMPTY, NULL, "" },
5430 { TYPE_EMPTY, NULL, "" },
5431 { TYPE_EMPTY, NULL, "" },
5432 { TYPE_EMPTY, NULL, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_EMPTY, NULL, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5441 static struct TokenInfo setup_info_touch[] =
5443 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5444 { TYPE_STRING, &touch_controls_text, "" },
5445 { TYPE_EMPTY, NULL, "" },
5446 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5447 { TYPE_STRING, &move_distance_text, "" },
5448 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5449 { TYPE_STRING, &drop_distance_text, "" },
5450 { TYPE_EMPTY, NULL, "" },
5451 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5456 static struct TokenInfo setup_info_shortcuts[] =
5458 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5459 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5460 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5461 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5462 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5463 { TYPE_EMPTY, NULL, "" },
5464 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5469 static struct TokenInfo setup_info_shortcuts_1[] =
5471 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5472 { TYPE_KEY, &setup.shortcut.save_game, "" },
5473 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5474 { TYPE_KEY, &setup.shortcut.load_game, "" },
5475 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5476 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5477 { TYPE_EMPTY, NULL, "" },
5478 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5479 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5480 { TYPE_EMPTY, NULL, "" },
5481 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5486 static struct TokenInfo setup_info_shortcuts_2[] =
5488 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5489 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5490 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5491 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5492 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5493 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5494 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5495 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5496 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5497 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5498 { TYPE_EMPTY, NULL, "" },
5499 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5504 static struct TokenInfo setup_info_shortcuts_3[] =
5506 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5507 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5508 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5509 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5510 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5511 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5512 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5513 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5514 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5515 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5516 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5517 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5518 { TYPE_EMPTY, NULL, "" },
5519 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5524 static struct TokenInfo setup_info_shortcuts_4[] =
5526 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5527 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5528 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5529 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5530 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5531 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5532 { TYPE_EMPTY, NULL, "" },
5533 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5538 static struct TokenInfo setup_info_shortcuts_5[] =
5540 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5541 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5542 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5543 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5544 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5545 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5546 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5547 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5548 { TYPE_EMPTY, NULL, "" },
5549 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5554 static Key getSetupKey()
5556 Key key = KSYM_UNDEFINED;
5557 boolean got_key_event = FALSE;
5559 while (!got_key_event)
5561 if (PendingEvent()) /* got event */
5569 case EVENT_KEYPRESS:
5571 key = GetEventKey((KeyEvent *)&event, TRUE);
5573 /* press 'Escape' or 'Enter' to keep the existing key binding */
5574 if (key == KSYM_Escape || key == KSYM_Return)
5575 key = KSYM_UNDEFINED; /* keep old value */
5577 got_key_event = TRUE;
5581 case EVENT_KEYRELEASE:
5582 key_joystick_mapping = 0;
5586 HandleOtherEvents(&event);
5598 static int getSetupValueFont(int type, void *value)
5600 if (type & TYPE_KEY)
5601 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5602 else if (type & TYPE_STRING)
5603 return FONT_VALUE_2;
5604 else if (type & TYPE_ECS_AGA)
5605 return FONT_VALUE_1;
5606 else if (type & TYPE_BOOLEAN_STYLE)
5607 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5608 else if (type & TYPE_YES_NO_AUTO)
5609 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5610 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5612 return FONT_VALUE_1;
5615 static int getSetupValueFontNarrow(int type, int font_nr)
5617 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5618 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5619 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5623 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5625 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5626 struct TokenInfo *si = &setup_info[si_pos];
5627 boolean font_draw_xoffset_modified = FALSE;
5628 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5629 int font_draw_xoffset_old = -1;
5630 int xoffset = (scrollbar_needed ? -1 : 0);
5631 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5632 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5633 int xpos = menu_screen_value_xpos;
5634 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5635 int startx = mSX + xpos * 32;
5636 int starty = mSY + ypos * 32;
5637 int font_nr, font_nr_default, font_width_default;
5638 int type = si->type;
5639 void *value = si->value;
5640 char *value_string = getSetupValue(type, value);
5643 if (value_string == NULL)
5646 if (type & TYPE_KEY)
5648 xpos = MENU_SCREEN_START_XPOS;
5650 if (type & TYPE_QUERY)
5651 value_string = "<press key>";
5653 else if (type & TYPE_STRING)
5655 int max_value_len = (SCR_FIELDX - 2) * 2;
5657 xpos = MENU_SCREEN_START_XPOS;
5659 if (strlen(value_string) > max_value_len)
5660 value_string[max_value_len] = '\0';
5662 else if (type & TYPE_YES_NO_AUTO)
5664 xpos = menu_screen_value_xpos - 1;
5667 startx = mSX + xpos * 32;
5668 starty = mSY + ypos * 32;
5669 font_nr_default = getSetupValueFont(type, value);
5670 font_width_default = getFontWidth(font_nr_default);
5672 font_nr = font_nr_default;
5674 // special check if right-side setup values moved left due to scrollbar
5675 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5677 int max_menu_text_length = 26; // maximum text length for classic menu
5678 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5679 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5680 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5681 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5682 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5684 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5687 startx = mSX + xpos * 32;
5689 font_nr = getSetupValueFontNarrow(type, font_nr);
5693 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5694 if (setup_mode != SETUP_MODE_INPUT)
5696 int max_menu_text_length_big = (menu_screen_value_xpos -
5697 MENU_SCREEN_START_XPOS);
5698 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5699 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5700 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5701 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5702 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5703 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5704 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5705 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5706 boolean correct_font_draw_xoffset = FALSE;
5708 if (xpos == MENU_SCREEN_START_XPOS &&
5709 startx + font1_xoffset < text_startx + text_font_xoffset)
5710 correct_font_draw_xoffset = TRUE;
5712 if (xpos == menu_screen_value_xpos &&
5713 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5714 correct_font_draw_xoffset = TRUE;
5716 /* check if setup value would overlap with setup text when printed */
5717 /* (this can happen for extreme/wrong values for font draw offset) */
5718 if (correct_font_draw_xoffset)
5720 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5721 font_draw_xoffset_modified = TRUE;
5723 if (type & TYPE_KEY)
5724 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5725 else if (!(type & TYPE_STRING))
5726 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5727 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5731 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5732 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
5734 DrawText(startx, starty, value_string, font_nr);
5736 if (font_draw_xoffset_modified)
5737 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5740 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5742 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5743 struct TokenInfo *si = &setup_info[si_pos];
5745 if (si->type & TYPE_BOOLEAN_STYLE)
5747 *(boolean *)si->value ^= TRUE;
5749 else if (si->type & TYPE_YES_NO_AUTO)
5753 (*(int *)si->value == AUTO ? TRUE :
5754 *(int *)si->value == TRUE ? FALSE : AUTO) :
5755 (*(int *)si->value == TRUE ? AUTO :
5756 *(int *)si->value == AUTO ? FALSE : TRUE));
5758 else if (si->type & TYPE_KEY)
5762 si->type |= TYPE_QUERY;
5763 drawSetupValue(screen_pos, setup_info_pos_raw);
5764 si->type &= ~TYPE_QUERY;
5766 key = getSetupKey();
5767 if (key != KSYM_UNDEFINED)
5768 *(Key *)si->value = key;
5771 drawSetupValue(screen_pos, setup_info_pos_raw);
5773 // fullscreen state may have changed at this point
5774 if (si->value == &setup.fullscreen)
5775 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5778 static void DrawSetupScreen_Generic()
5780 int fade_mask = REDRAW_FIELD;
5781 boolean redraw_all = FALSE;
5782 char *title_string = NULL;
5785 if (CheckIfGlobalBorderHasChanged())
5786 fade_mask = REDRAW_ALL;
5789 FadeSoundsAndMusic();
5791 FreeScreenGadgets();
5792 CreateScreenGadgets();
5794 if (redraw_mask & REDRAW_ALL)
5801 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5803 if (setup_mode == SETUP_MODE_MAIN)
5805 setup_info = setup_info_main;
5806 title_string = "Setup";
5808 else if (setup_mode == SETUP_MODE_GAME)
5810 setup_info = setup_info_game;
5811 title_string = "Setup Game";
5813 else if (setup_mode == SETUP_MODE_EDITOR)
5815 setup_info = setup_info_editor;
5816 title_string = "Setup Editor";
5818 else if (setup_mode == SETUP_MODE_GRAPHICS)
5820 setup_info = setup_info_graphics;
5821 title_string = "Setup Graphics";
5823 else if (setup_mode == SETUP_MODE_SOUND)
5825 setup_info = setup_info_sound;
5826 title_string = "Setup Sound";
5828 else if (setup_mode == SETUP_MODE_ARTWORK)
5830 setup_info = setup_info_artwork;
5831 title_string = "Custom Artwork";
5833 else if (setup_mode == SETUP_MODE_TOUCH)
5835 setup_info = setup_info_touch;
5836 title_string = "Setup Touch Ctrls";
5838 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5840 setup_info = setup_info_shortcuts;
5841 title_string = "Setup Shortcuts";
5843 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5845 setup_info = setup_info_shortcuts_1;
5846 title_string = "Setup Shortcuts";
5848 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5850 setup_info = setup_info_shortcuts_2;
5851 title_string = "Setup Shortcuts";
5853 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5855 setup_info = setup_info_shortcuts_3;
5856 title_string = "Setup Shortcuts";
5858 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5860 setup_info = setup_info_shortcuts_4;
5861 title_string = "Setup Shortcuts";
5863 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5865 setup_info = setup_info_shortcuts_5;
5866 title_string = "Setup Shortcuts";
5869 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5871 // determine maximal number of setup entries that can be displayed on screen
5873 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5876 // determine maximal number of setup entries available for this setup screen
5878 for (i = 0; setup_info[i].type != 0; i++)
5881 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5883 MapScreenGadgets(max_setup_info);
5886 redraw_mask = fade_mask = REDRAW_ALL;
5888 DrawMaskedBorder(fade_mask);
5895 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5897 menu_info = setup_info;
5899 HandleMenuScreen(mx, my, dx, dy, button,
5900 setup_mode, num_setup_info, max_setup_info);
5903 void DrawSetupScreen_Input()
5907 FadeOut(REDRAW_FIELD);
5911 setup_info = setup_info_input;
5913 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5915 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5916 "Joysticks deactivated on this screen");
5918 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5920 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5921 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5922 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5923 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5924 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5925 initCursor(i, IMG_MENU_BUTTON);
5927 DrawCursorAndText_Setup(i, -1, FALSE);
5930 /* create gadgets for setup input menu screen */
5931 FreeScreenGadgets();
5932 CreateScreenGadgets();
5934 /* map gadgets for setup input menu screen */
5935 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5937 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5939 FadeIn(REDRAW_FIELD);
5944 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5946 if (device_name == NULL)
5949 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5952 if (strlen(device_name) > 1)
5954 char c1 = device_name[strlen(device_name) - 1];
5955 char c2 = device_name[strlen(device_name) - 2];
5957 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5958 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5961 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5962 strlen(device_name));
5965 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5968 static struct SetupKeyboardInfo custom_key;
5975 { &custom_key.left, "Joystick Left" },
5976 { &custom_key.right, "Joystick Right" },
5977 { &custom_key.up, "Joystick Up" },
5978 { &custom_key.down, "Joystick Down" },
5979 { &custom_key.snap, "Button 1" },
5980 { &custom_key.drop, "Button 2" }
5982 static char *joystick_name[MAX_PLAYERS] =
5989 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5993 custom_key = setup.input[player_nr].key;
5995 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5996 FONT_INPUT_1_ACTIVE);
5998 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6000 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6001 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6003 if (setup.input[player_nr].use_joystick)
6005 char *device_name = setup.input[player_nr].joy.device_name;
6006 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6007 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6009 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6010 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6014 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6015 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6018 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6020 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6021 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6022 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6023 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6025 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6026 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6027 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6028 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6029 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6030 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6032 for (i = 0; i < 6; i++)
6034 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6036 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6038 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6039 (setup.input[player_nr].use_joystick ?
6041 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6045 static int input_player_nr = 0;
6047 void HandleSetupScreen_Input_Player(int step, int direction)
6049 int old_player_nr = input_player_nr;
6052 new_player_nr = old_player_nr + step * direction;
6053 if (new_player_nr < 0)
6055 if (new_player_nr > MAX_PLAYERS - 1)
6056 new_player_nr = MAX_PLAYERS - 1;
6058 if (new_player_nr != old_player_nr)
6060 input_player_nr = new_player_nr;
6062 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6066 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6068 static int choice = 0;
6071 int pos_start = SETUPINPUT_SCREEN_POS_START;
6072 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6073 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6074 int pos_end = SETUPINPUT_SCREEN_POS_END;
6076 if (button == MB_MENU_INITIALIZE)
6078 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6080 DrawCursorAndText_Setup(choice, -1, TRUE);
6084 else if (button == MB_MENU_LEAVE)
6086 setup_mode = SETUP_MODE_MAIN;
6093 if (mx || my) /* mouse input */
6095 x = (mx - mSX) / 32;
6096 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6098 else if (dx || dy) /* keyboard input */
6100 if (dx && choice == 0)
6101 x = (dx < 0 ? 10 : 12);
6102 else if ((dx && choice == 1) ||
6103 (dx == +1 && choice == 2) ||
6104 (dx == -1 && choice == pos_end))
6105 button = MB_MENU_CHOICE;
6109 if (y >= pos_empty1 && y <= pos_empty2)
6110 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6113 if (y == 0 && dx != 0 && button)
6115 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6117 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6118 y >= pos_start && y <= pos_end &&
6119 !(y >= pos_empty1 && y <= pos_empty2))
6125 DrawCursorAndText_Setup(choice, -1, FALSE);
6126 DrawCursorAndText_Setup(y, -1, TRUE);
6128 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6137 char *device_name = setup.input[input_player_nr].joy.device_name;
6139 if (!setup.input[input_player_nr].use_joystick)
6141 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6143 setJoystickDeviceToNr(device_name, new_device_nr);
6144 setup.input[input_player_nr].use_joystick = TRUE;
6148 int device_nr = getJoystickNrFromDeviceName(device_name);
6149 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6151 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6152 setup.input[input_player_nr].use_joystick = FALSE;
6154 setJoystickDeviceToNr(device_name, new_device_nr);
6157 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6161 if (setup.input[input_player_nr].use_joystick)
6164 CalibrateJoystick(input_player_nr);
6167 CustomizeKeyboard(input_player_nr);
6169 else if (y == pos_end)
6175 setup_mode = SETUP_MODE_MAIN;
6182 void CustomizeKeyboard(int player_nr)
6186 boolean finished = FALSE;
6187 static struct SetupKeyboardInfo custom_key;
6192 } customize_step[] =
6194 { &custom_key.left, "Move Left" },
6195 { &custom_key.right, "Move Right" },
6196 { &custom_key.up, "Move Up" },
6197 { &custom_key.down, "Move Down" },
6198 { &custom_key.snap, "Snap Field" },
6199 { &custom_key.drop, "Drop Element" }
6202 /* read existing key bindings from player setup */
6203 custom_key = setup.input[player_nr].key;
6206 FadeOut(REDRAW_FIELD);
6210 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6213 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6214 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6215 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6216 "Key:", FONT_INPUT_1_ACTIVE);
6217 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6218 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6220 FadeIn(REDRAW_FIELD);
6226 if (PendingEvent()) /* got event */
6234 case EVENT_KEYPRESS:
6236 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6238 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6240 if (key == KSYM_Escape)
6241 FadeSkipNextFadeIn();
6247 /* all keys configured -- wait for "Escape" or "Return" key */
6251 /* press 'Enter' to keep the existing key binding */
6252 if (key == KSYM_Return)
6253 key = *customize_step[step_nr].key;
6255 /* check if key already used */
6256 for (i = 0; i < step_nr; i++)
6257 if (*customize_step[i].key == key)
6262 /* got new key binding */
6263 *customize_step[step_nr].key = key;
6264 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6266 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6267 getKeyNameFromKey(key), FONT_VALUE_1);
6270 /* un-highlight last query */
6271 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6272 customize_step[step_nr - 1].text, FONT_MENU_1);
6273 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6274 "Key:", FONT_MENU_1);
6276 /* press 'Enter' to leave */
6279 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6280 "Press Enter", FONT_TITLE_1);
6284 /* query next key binding */
6285 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6286 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6287 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6288 "Key:", FONT_INPUT_1_ACTIVE);
6289 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6290 getKeyNameFromKey(*customize_step[step_nr].key),
6295 case EVENT_KEYRELEASE:
6296 key_joystick_mapping = 0;
6300 HandleOtherEvents(&event);
6309 /* write new key bindings back to player setup */
6310 setup.input[player_nr].key = custom_key;
6313 DrawSetupScreen_Input();
6316 static boolean CalibrateJoystickMain(int player_nr)
6318 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6319 int new_joystick_xright = JOYSTICK_XMIDDLE;
6320 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6321 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6322 int new_joystick_xmiddle, new_joystick_ymiddle;
6324 int joystick_fd = joystick.fd[player_nr];
6325 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6326 boolean check[3][3];
6327 int check_remaining = 3 * 3;
6332 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6335 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6339 FadeOut(REDRAW_FIELD);
6343 for (y = 0; y < 3; y++)
6345 for (x = 0; x < 3; x++)
6347 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6348 check[x][y] = FALSE;
6352 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6353 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6354 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6355 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6356 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6357 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6358 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6360 joy_value = Joystick(player_nr);
6361 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6362 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6364 /* eventually uncalibrated center position (joystick could be uncentered) */
6365 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6368 new_joystick_xmiddle = joy_x;
6369 new_joystick_ymiddle = joy_y;
6371 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6373 FadeIn(REDRAW_FIELD);
6375 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6380 if (PendingEvent()) /* got event */
6388 case EVENT_KEYPRESS:
6389 switch (GetEventKey((KeyEvent *)&event, TRUE))
6392 if (check_remaining == 0)
6397 FadeSkipNextFadeIn();
6406 case EVENT_KEYRELEASE:
6407 key_joystick_mapping = 0;
6411 HandleOtherEvents(&event);
6416 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6419 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6420 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6421 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6422 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6424 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6425 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6426 setup.input[player_nr].joy.xright = new_joystick_xright;
6427 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6428 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6429 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6431 CheckJoystickData();
6433 joy_value = Joystick(player_nr);
6435 if (joy_value & JOY_BUTTON && check_remaining == 0)
6438 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6439 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6441 if (x != last_x || y != last_y)
6443 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6444 IMG_MENU_CALIBRATE_YELLOW, 0);
6445 DrawFixedGraphic(xpos + x, ypos + y,
6446 IMG_MENU_CALIBRATE_RED, 0);
6451 if (check_remaining > 0 && !check[x+1][y+1])
6453 check[x+1][y+1] = TRUE;
6462 /* calibrated center position (joystick should now be centered) */
6463 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6466 new_joystick_xmiddle = joy_x;
6467 new_joystick_ymiddle = joy_y;
6471 /* wait until the last pressed button was released */
6472 while (Joystick(player_nr) & JOY_BUTTON)
6474 if (PendingEvent()) /* got event */
6479 HandleOtherEvents(&event);
6488 void CalibrateJoystick(int player_nr)
6490 if (!CalibrateJoystickMain(player_nr))
6492 char *device_name = setup.input[player_nr].joy.device_name;
6493 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6494 int xpos = mSX - SX;
6495 int ypos = mSY - SY;
6499 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6500 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6503 Delay(2000); /* show error message for a short time */
6508 DrawSetupScreen_Input();
6511 void DrawSetupScreen()
6513 DeactivateJoystick();
6515 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6517 if (setup_mode == SETUP_MODE_INPUT)
6518 DrawSetupScreen_Input();
6519 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6520 DrawChooseTree(&game_speed_current);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6522 DrawChooseTree(&scroll_delay_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6524 DrawChooseTree(&snapshot_mode_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6526 DrawChooseTree(&window_size_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6528 DrawChooseTree(&scaling_type_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6530 DrawChooseTree(&rendering_mode_current);
6531 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6532 DrawChooseTree(&artwork.gfx_current);
6533 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6534 DrawChooseTree(&artwork.snd_current);
6535 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6536 DrawChooseTree(&artwork.mus_current);
6537 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6538 DrawChooseTree(&volume_simple_current);
6539 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6540 DrawChooseTree(&volume_loops_current);
6541 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6542 DrawChooseTree(&volume_music_current);
6543 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6544 DrawChooseTree(&touch_control_current);
6545 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6546 DrawChooseTree(&move_distance_current);
6547 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6548 DrawChooseTree(&drop_distance_current);
6550 DrawSetupScreen_Generic();
6556 void RedrawSetupScreenAfterFullscreenToggle()
6558 if (setup_mode == SETUP_MODE_GRAPHICS ||
6559 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6561 // update list selection from "setup.window_scaling_percent"
6562 execSetupGraphics_setWindowSizes(TRUE);
6568 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6570 if (setup_mode == SETUP_MODE_INPUT)
6571 HandleSetupScreen_Input(mx, my, dx, dy, button);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6573 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6575 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6577 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6579 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6581 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6582 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6583 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
6584 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6585 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6586 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6587 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6588 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6589 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6590 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6591 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6592 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6593 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6594 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6595 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6596 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6597 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6598 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6599 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6600 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6601 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6603 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6606 void HandleGameActions()
6608 if (game_status != GAME_MODE_PLAYING)
6611 GameActions(); /* main game loop */
6613 if (tape.auto_play && !tape.playing)
6614 AutoPlayTape(); /* continue automatically playing next tape */
6618 /* ---------- new screen button stuff -------------------------------------- */
6620 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6624 case SCREEN_CTRL_ID_PREV_LEVEL:
6625 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6626 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6629 case SCREEN_CTRL_ID_NEXT_LEVEL:
6630 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6631 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6634 case SCREEN_CTRL_ID_PREV_PLAYER:
6635 *x = mSX + TILEX * 10;
6636 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6639 case SCREEN_CTRL_ID_NEXT_PLAYER:
6640 *x = mSX + TILEX * 12;
6641 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6645 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6651 int gfx_unpressed, gfx_pressed;
6652 void (*get_gadget_position)(int *, int *, int);
6656 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6659 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6660 getScreenMenuButtonPos,
6661 SCREEN_CTRL_ID_PREV_LEVEL,
6666 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6667 getScreenMenuButtonPos,
6668 SCREEN_CTRL_ID_NEXT_LEVEL,
6673 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6674 getScreenMenuButtonPos,
6675 SCREEN_CTRL_ID_PREV_PLAYER,
6680 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6681 getScreenMenuButtonPos,
6682 SCREEN_CTRL_ID_NEXT_PLAYER,
6690 int gfx_unpressed, gfx_pressed;
6694 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6697 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6698 -1, -1, /* these values are not constant, but can change at runtime */
6699 SCREEN_CTRL_ID_SCROLL_UP,
6703 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6704 -1, -1, /* these values are not constant, but can change at runtime */
6705 SCREEN_CTRL_ID_SCROLL_DOWN,
6712 int gfx_unpressed, gfx_pressed;
6718 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6721 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6722 -1, -1, /* these values are not constant, but can change at runtime */
6723 -1, -1, /* these values are not constant, but can change at runtime */
6724 GD_TYPE_SCROLLBAR_VERTICAL,
6725 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6726 "scroll level series vertically"
6730 static void CreateScreenMenubuttons()
6732 struct GadgetInfo *gi;
6733 unsigned int event_mask;
6736 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6738 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6739 int gfx_unpressed, gfx_pressed;
6740 int x, y, width, height;
6741 int gd_x1, gd_x2, gd_y1, gd_y2;
6742 int id = menubutton_info[i].gadget_id;
6744 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6746 menubutton_info[i].get_gadget_position(&x, &y, id);
6748 width = SC_MENUBUTTON_XSIZE;
6749 height = SC_MENUBUTTON_YSIZE;
6751 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6752 gfx_pressed = menubutton_info[i].gfx_pressed;
6753 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6754 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6755 gd_x1 = graphic_info[gfx_unpressed].src_x;
6756 gd_y1 = graphic_info[gfx_unpressed].src_y;
6757 gd_x2 = graphic_info[gfx_pressed].src_x;
6758 gd_y2 = graphic_info[gfx_pressed].src_y;
6760 gi = CreateGadget(GDI_CUSTOM_ID, id,
6761 GDI_CUSTOM_TYPE_ID, i,
6762 GDI_INFO_TEXT, menubutton_info[i].infotext,
6767 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6768 GDI_STATE, GD_BUTTON_UNPRESSED,
6769 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6770 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6771 GDI_DIRECT_DRAW, FALSE,
6772 GDI_EVENT_MASK, event_mask,
6773 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6777 Error(ERR_EXIT, "cannot create gadget");
6779 screen_gadget[id] = gi;
6783 static void CreateScreenScrollbuttons()
6785 struct GadgetInfo *gi;
6786 unsigned int event_mask;
6789 /* these values are not constant, but can change at runtime */
6790 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6791 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6792 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6793 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6795 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6797 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6798 int gfx_unpressed, gfx_pressed;
6799 int x, y, width, height;
6800 int gd_x1, gd_x2, gd_y1, gd_y2;
6801 int id = scrollbutton_info[i].gadget_id;
6803 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6805 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6806 y = mSY + scrollbutton_info[i].y;
6807 width = SC_SCROLLBUTTON_XSIZE;
6808 height = SC_SCROLLBUTTON_YSIZE;
6810 /* correct scrollbar position if placed outside menu (playfield) area */
6811 if (x > SX + SC_SCROLL_UP_XPOS)
6812 x = SX + SC_SCROLL_UP_XPOS;
6814 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6815 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6816 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6818 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6819 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6820 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6821 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6822 gd_x1 = graphic_info[gfx_unpressed].src_x;
6823 gd_y1 = graphic_info[gfx_unpressed].src_y;
6824 gd_x2 = graphic_info[gfx_pressed].src_x;
6825 gd_y2 = graphic_info[gfx_pressed].src_y;
6827 gi = CreateGadget(GDI_CUSTOM_ID, id,
6828 GDI_CUSTOM_TYPE_ID, i,
6829 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6834 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6835 GDI_STATE, GD_BUTTON_UNPRESSED,
6836 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6837 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6838 GDI_DIRECT_DRAW, FALSE,
6839 GDI_EVENT_MASK, event_mask,
6840 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6844 Error(ERR_EXIT, "cannot create gadget");
6846 screen_gadget[id] = gi;
6850 static void CreateScreenScrollbars()
6854 /* these values are not constant, but can change at runtime */
6855 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6856 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6857 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6858 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6860 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6862 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6863 int gfx_unpressed, gfx_pressed;
6864 int x, y, width, height;
6865 int gd_x1, gd_x2, gd_y1, gd_y2;
6866 struct GadgetInfo *gi;
6867 int items_max, items_visible, item_position;
6868 unsigned int event_mask;
6869 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6870 int id = scrollbar_info[i].gadget_id;
6872 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6874 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6875 y = mSY + scrollbar_info[i].y;
6876 width = scrollbar_info[i].width;
6877 height = scrollbar_info[i].height;
6879 /* correct scrollbar position if placed outside menu (playfield) area */
6880 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6881 x = SX + SC_SCROLL_VERTICAL_XPOS;
6883 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6884 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6886 items_max = num_page_entries;
6887 items_visible = num_page_entries;
6890 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6891 gfx_pressed = scrollbar_info[i].gfx_pressed;
6892 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6893 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6894 gd_x1 = graphic_info[gfx_unpressed].src_x;
6895 gd_y1 = graphic_info[gfx_unpressed].src_y;
6896 gd_x2 = graphic_info[gfx_pressed].src_x;
6897 gd_y2 = graphic_info[gfx_pressed].src_y;
6899 gi = CreateGadget(GDI_CUSTOM_ID, id,
6900 GDI_CUSTOM_TYPE_ID, i,
6901 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6906 GDI_TYPE, scrollbar_info[i].type,
6907 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6908 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6909 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6910 GDI_WHEEL_AREA_X, SX,
6911 GDI_WHEEL_AREA_Y, SY,
6912 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6913 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6914 GDI_STATE, GD_BUTTON_UNPRESSED,
6915 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6916 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6917 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6918 GDI_DIRECT_DRAW, FALSE,
6919 GDI_EVENT_MASK, event_mask,
6920 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6924 Error(ERR_EXIT, "cannot create gadget");
6926 screen_gadget[id] = gi;
6930 void CreateScreenGadgets()
6932 CreateScreenMenubuttons();
6934 CreateScreenScrollbuttons();
6935 CreateScreenScrollbars();
6938 void FreeScreenGadgets()
6942 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6943 FreeGadget(screen_gadget[i]);
6946 void MapScreenMenuGadgets(int screen_mask)
6950 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6951 if (screen_mask & menubutton_info[i].screen_mask)
6952 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6955 void MapScreenGadgets(int num_entries)
6959 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6962 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6963 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6965 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6966 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6969 void MapScreenTreeGadgets(TreeInfo *ti)
6971 MapScreenGadgets(numTreeInfoInGroup(ti));
6974 static void HandleScreenGadgets(struct GadgetInfo *gi)
6976 int id = gi->custom_id;
6977 int button = gi->event.button;
6978 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6982 case SCREEN_CTRL_ID_PREV_LEVEL:
6983 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6986 case SCREEN_CTRL_ID_NEXT_LEVEL:
6987 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6990 case SCREEN_CTRL_ID_PREV_PLAYER:
6991 HandleSetupScreen_Input_Player(step, -1);
6994 case SCREEN_CTRL_ID_NEXT_PLAYER:
6995 HandleSetupScreen_Input_Player(step, +1);
6998 case SCREEN_CTRL_ID_SCROLL_UP:
6999 if (game_status == GAME_MODE_LEVELS)
7000 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7001 else if (game_status == GAME_MODE_LEVELNR)
7002 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7003 else if (game_status == GAME_MODE_SETUP)
7004 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7005 else if (game_status == GAME_MODE_INFO)
7006 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7009 case SCREEN_CTRL_ID_SCROLL_DOWN:
7010 if (game_status == GAME_MODE_LEVELS)
7011 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7012 else if (game_status == GAME_MODE_LEVELNR)
7013 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7014 else if (game_status == GAME_MODE_SETUP)
7015 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7016 else if (game_status == GAME_MODE_INFO)
7017 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7020 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7021 if (game_status == GAME_MODE_LEVELS)
7022 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7023 else if (game_status == GAME_MODE_LEVELNR)
7024 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7025 else if (game_status == GAME_MODE_SETUP)
7026 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7027 else if (game_status == GAME_MODE_INFO)
7028 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);