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)" },
282 // this mode may work under certain conditions, but does not work on Windows
283 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
285 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
294 } game_speeds_list[] =
303 { 1000, "1/1s (Extremely Slow)" },
308 { 29, "1/35s (Original Supaplex)" },
310 { 20, "1/50s (Normal Speed)" },
311 { 14, "1/70s (Maximum Supaplex)" },
315 { 1, "1/1000s (Extremely Fast)" },
325 } scroll_delays_list[] =
327 { 0, "0 Tiles (No Scroll Delay)" },
330 { 3, "3 Tiles (Default)" },
335 { 8, "8 Tiles (Maximum Scroll Delay)"},
344 } snapshot_modes_list[] =
346 { STR_SNAPSHOT_MODE_OFF, "Off" },
347 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
348 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
349 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
382 } touch_controls_list[] =
384 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
385 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
386 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
410 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
411 (s) <= GAME_MODE_SETUP ? (s) : \
412 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
413 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
415 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
416 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
417 (i) <= INFO_MODE_LEVELSET ? (i) : \
420 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
421 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
422 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
423 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
424 SETUP_MODE_CHOOSE_ARTWORK : \
425 SETUP_MODE_CHOOSE_OTHER)
427 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
428 menu.draw_xoffset[GAME_MODE_INFO] : \
429 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
430 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
431 menu.draw_yoffset[GAME_MODE_INFO] : \
432 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
434 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
435 menu.draw_xoffset[GAME_MODE_SETUP] : \
436 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
437 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
438 menu.draw_yoffset[GAME_MODE_SETUP] : \
439 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
441 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
442 DRAW_XOFFSET_INFO(info_mode) : \
443 (s) == GAME_MODE_SETUP ? \
444 DRAW_XOFFSET_SETUP(setup_mode) : \
445 menu.draw_xoffset[DRAW_MODE(s)])
446 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
447 DRAW_YOFFSET_INFO(info_mode) : \
448 (s) == GAME_MODE_SETUP ? \
449 DRAW_YOFFSET_SETUP(setup_mode) : \
450 menu.draw_yoffset[DRAW_MODE(s)])
452 #define mSX (SX + DRAW_XOFFSET(game_status))
453 #define mSY (SY + DRAW_YOFFSET(game_status))
455 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
456 menu.list_size[game_status] : \
457 MAX_MENU_ENTRIES_ON_SCREEN)
459 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
460 NUM_MENU_ENTRIES_ON_SCREEN)
463 /* title display and control definitions */
465 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
466 2 * MAX_NUM_TITLE_MESSAGES)
468 #define NO_DIRECT_LEVEL_SELECT (-1)
471 static int num_title_screens = 0;
473 struct TitleControlInfo
482 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
484 /* main menu display and control definitions */
486 #define MAIN_CONTROL_NAME 0
487 #define MAIN_CONTROL_LEVELS 1
488 #define MAIN_CONTROL_SCORES 2
489 #define MAIN_CONTROL_EDITOR 3
490 #define MAIN_CONTROL_INFO 4
491 #define MAIN_CONTROL_GAME 5
492 #define MAIN_CONTROL_SETUP 6
493 #define MAIN_CONTROL_QUIT 7
494 #define MAIN_CONTROL_PREV_LEVEL 8
495 #define MAIN_CONTROL_NEXT_LEVEL 9
496 #define MAIN_CONTROL_FIRST_LEVEL 10
497 #define MAIN_CONTROL_LAST_LEVEL 11
498 #define MAIN_CONTROL_LEVEL_NUMBER 12
499 #define MAIN_CONTROL_LEVEL_INFO_1 13
500 #define MAIN_CONTROL_LEVEL_INFO_2 14
501 #define MAIN_CONTROL_LEVEL_NAME 15
502 #define MAIN_CONTROL_LEVEL_AUTHOR 16
503 #define MAIN_CONTROL_LEVEL_YEAR 17
504 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
505 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
506 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
507 #define MAIN_CONTROL_TITLE_1 21
508 #define MAIN_CONTROL_TITLE_2 22
509 #define MAIN_CONTROL_TITLE_3 23
511 static char str_main_text_name[10];
512 static char str_main_text_first_level[10];
513 static char str_main_text_last_level[10];
514 static char str_main_text_level_number[10];
516 static char *main_text_name = str_main_text_name;
517 static char *main_text_first_level = str_main_text_first_level;
518 static char *main_text_last_level = str_main_text_last_level;
519 static char *main_text_level_number = str_main_text_level_number;
520 static char *main_text_levels = "Levelset";
521 static char *main_text_scores = "Hall Of Fame";
522 static char *main_text_editor = "Level Creator";
523 static char *main_text_info = "Info Screen";
524 static char *main_text_game = "Start Game";
525 static char *main_text_setup = "Setup";
526 static char *main_text_quit = "Quit";
527 static char *main_text_level_name = level.name;
528 static char *main_text_level_author = level.author;
529 static char *main_text_level_year = NULL;
530 static char *main_text_level_imported_from = NULL;
531 static char *main_text_level_imported_by = NULL;
532 static char *main_text_level_tested_by = NULL;
534 struct MainControlInfo
538 struct MenuPosInfo *pos_button;
541 struct TextPosInfo *pos_text;
544 struct TextPosInfo *pos_input;
548 static struct MainControlInfo main_controls[] =
552 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
553 &menu.main.text.name, &main_text_name,
554 &menu.main.input.name, &setup.player_name,
558 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
559 &menu.main.text.levels, &main_text_levels,
564 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
565 &menu.main.text.scores, &main_text_scores,
570 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
571 &menu.main.text.editor, &main_text_editor,
576 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
577 &menu.main.text.info, &main_text_info,
582 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
583 &menu.main.text.game, &main_text_game,
588 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
589 &menu.main.text.setup, &main_text_setup,
594 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
595 &menu.main.text.quit, &main_text_quit,
599 /* (these two buttons are real gadgets) */
601 MAIN_CONTROL_PREV_LEVEL,
602 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
607 MAIN_CONTROL_NEXT_LEVEL,
608 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
614 MAIN_CONTROL_FIRST_LEVEL,
616 &menu.main.text.first_level, &main_text_first_level,
620 MAIN_CONTROL_LAST_LEVEL,
622 &menu.main.text.last_level, &main_text_last_level,
626 MAIN_CONTROL_LEVEL_NUMBER,
628 &menu.main.text.level_number, &main_text_level_number,
632 MAIN_CONTROL_LEVEL_INFO_1,
634 &menu.main.text.level_info_1, NULL,
638 MAIN_CONTROL_LEVEL_INFO_2,
640 &menu.main.text.level_info_2, NULL,
644 MAIN_CONTROL_LEVEL_NAME,
646 &menu.main.text.level_name, &main_text_level_name,
650 MAIN_CONTROL_LEVEL_AUTHOR,
652 &menu.main.text.level_author, &main_text_level_author,
656 MAIN_CONTROL_LEVEL_YEAR,
658 &menu.main.text.level_year, &main_text_level_year,
662 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
664 &menu.main.text.level_imported_from, &main_text_level_imported_from,
668 MAIN_CONTROL_LEVEL_IMPORTED_BY,
670 &menu.main.text.level_imported_by, &main_text_level_imported_by,
674 MAIN_CONTROL_LEVEL_TESTED_BY,
676 &menu.main.text.level_tested_by, &main_text_level_tested_by,
680 MAIN_CONTROL_TITLE_1,
682 &menu.main.text.title_1, &setup.internal.program_title,
686 MAIN_CONTROL_TITLE_2,
688 &menu.main.text.title_2, &setup.internal.program_copyright,
692 MAIN_CONTROL_TITLE_3,
694 &menu.main.text.title_3, &setup.internal.program_company,
707 static int getTitleScreenGraphic(int nr, boolean initial)
709 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
712 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
714 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
718 static int getTitleScreenGameMode(boolean initial)
720 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
724 static int getTitleMessageGameMode(boolean initial)
726 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
729 static int getTitleAnimMode(struct TitleControlInfo *tci)
731 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
733 return base + tci->local_nr;
737 static int getTitleScreenBackground(boolean initial)
739 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
744 static int getTitleMessageBackground(int nr, boolean initial)
746 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
750 static int getTitleBackground(int nr, boolean initial, boolean is_image)
752 int base = (is_image ?
753 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
754 IMG_BACKGROUND_TITLESCREEN_1) :
755 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
756 IMG_BACKGROUND_TITLEMESSAGE_1));
757 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
758 IMG_BACKGROUND_TITLE);
759 int graphic_local = base + nr;
761 if (graphic_info[graphic_local].bitmap != NULL)
762 return graphic_local;
764 if (graphic_info[graphic_global].bitmap != NULL)
765 return graphic_global;
767 return IMG_UNDEFINED;
770 static int getTitleSound(struct TitleControlInfo *tci)
772 boolean is_image = tci->is_image;
773 int initial = tci->initial;
774 int nr = tci->local_nr;
775 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
776 int base = (is_image ?
777 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
778 SND_BACKGROUND_TITLESCREEN_1) :
779 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
780 SND_BACKGROUND_TITLEMESSAGE_1));
781 int sound_global = menu.sound[mode];
782 int sound_local = base + nr;
785 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
786 nr, initial, is_image,
787 sound_global, getSoundListEntry(sound_global)->filename,
788 sound_local, getSoundListEntry(sound_local)->filename);
791 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
794 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
797 return SND_UNDEFINED;
800 static int getTitleMusic(struct TitleControlInfo *tci)
802 boolean is_image = tci->is_image;
803 int initial = tci->initial;
804 int nr = tci->local_nr;
805 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
806 int base = (is_image ?
807 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
808 MUS_BACKGROUND_TITLESCREEN_1) :
809 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
810 MUS_BACKGROUND_TITLEMESSAGE_1));
811 int music_global = menu.music[mode];
812 int music_local = base + nr;
815 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
816 nr, initial, is_image,
817 music_global, getMusicListEntry(music_global)->filename,
818 music_local, getMusicListEntry(music_local)->filename);
821 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
824 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
827 return MUS_UNDEFINED;
830 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
832 boolean is_image = tci->is_image;
833 boolean initial = tci->initial;
834 boolean first = tci->first;
835 int nr = tci->local_nr;
836 struct TitleMessageInfo tmi;
837 struct TitleFadingInfo ti;
839 tmi = (is_image ? (initial ? (first ?
840 titlescreen_initial_first[nr] :
841 titlescreen_initial[nr])
843 titlescreen_first[nr] :
845 : (initial ? (first ?
846 titlemessage_initial_first[nr] :
847 titlemessage_initial[nr])
849 titlemessage_first[nr] :
852 ti.fade_mode = tmi.fade_mode;
853 ti.fade_delay = tmi.fade_delay;
854 ti.post_delay = tmi.post_delay;
855 ti.auto_delay = tmi.auto_delay;
860 static int compareTitleControlInfo(const void *object1, const void *object2)
862 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
863 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
866 if (tci1->initial != tci2->initial)
867 compare_result = (tci1->initial ? -1 : +1);
868 else if (tci1->sort_priority != tci2->sort_priority)
869 compare_result = tci1->sort_priority - tci2->sort_priority;
870 else if (tci1->is_image != tci2->is_image)
871 compare_result = (tci1->is_image ? -1 : +1);
873 compare_result = tci1->local_nr - tci2->local_nr;
875 return compare_result;
878 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
880 int nr, int sort_priority)
882 title_controls[num_title_screens].is_image = is_image;
883 title_controls[num_title_screens].initial = initial;
884 title_controls[num_title_screens].local_nr = nr;
885 title_controls[num_title_screens].sort_priority = sort_priority;
887 title_controls[num_title_screens].first = FALSE; /* will be set later */
892 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
896 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
898 int graphic = getTitleScreenGraphic(i, initial);
899 Bitmap *bitmap = graphic_info[graphic].bitmap;
900 int sort_priority = graphic_info[graphic].sort_priority;
903 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
906 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
908 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
909 char *filename = getLevelSetTitleMessageFilename(i, initial);
910 int sort_priority = tmi->sort_priority;
912 if (filename != NULL)
913 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
917 static void InitializeTitleControls(boolean show_title_initial)
919 num_title_screens = 0;
921 /* 1st step: initialize title screens for game start (only when starting) */
922 if (show_title_initial)
923 InitializeTitleControls_CheckTitleInfo(TRUE);
925 /* 2nd step: initialize title screens for current level set */
926 InitializeTitleControls_CheckTitleInfo(FALSE);
928 /* sort title screens according to sort_priority and title number */
929 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
930 compareTitleControlInfo);
932 /* mark first title screen */
933 title_controls[0].first = TRUE;
936 static boolean visibleMenuPos(struct MenuPosInfo *pos)
938 return (pos != NULL && pos->x != -1 && pos->y != -1);
941 static boolean visibleTextPos(struct TextPosInfo *pos)
943 return (pos != NULL && pos->x != -1 && pos->y != -1);
946 static void InitializeMainControls()
948 boolean local_team_mode = (!options.network && setup.team_mode);
951 /* set main control text values to dynamically determined values */
952 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
954 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
955 menu.main.text.first_level.size));
956 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
957 menu.main.text.last_level.size));
958 strcpy(main_text_level_number, int2str(level_nr,
959 menu.main.text.level_number.size));
961 main_text_level_year = leveldir_current->year;
962 main_text_level_imported_from = leveldir_current->imported_from;
963 main_text_level_imported_by = leveldir_current->imported_by;
964 main_text_level_tested_by = leveldir_current->tested_by;
966 /* set main control screen positions to dynamically determined values */
967 for (i = 0; main_controls[i].nr != -1; i++)
969 struct MainControlInfo *mci = &main_controls[i];
971 struct MenuPosInfo *pos_button = mci->pos_button;
972 struct TextPosInfo *pos_text = mci->pos_text;
973 struct TextPosInfo *pos_input = mci->pos_input;
974 char *text = (mci->text ? *mci->text : NULL);
975 char *input = (mci->input ? *mci->input : NULL);
976 int button_graphic = mci->button_graphic;
977 int font_text = (pos_text ? pos_text->font : -1);
978 int font_input = (pos_input ? pos_input->font : -1);
980 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
981 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
982 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
983 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
984 int text_chars = (text != NULL ? strlen(text) : 0);
985 int input_chars = (input != NULL ? strlen(input) : 0);
988 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
990 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
991 int text_width = font_text_width * text_chars;
992 int text_height = font_text_height;
993 int input_width = font_input_width * input_chars;
994 int input_height = font_input_height;
996 if (nr == MAIN_CONTROL_NAME)
998 menu.main.input.name.width = input_width;
999 menu.main.input.name.height = input_height;
1002 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1004 pos_button->width = button_width;
1005 pos_button->height = button_height;
1008 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1010 /* calculate size for non-clickable text -- needed for text alignment */
1011 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1013 if (pos_text->width == -1 || calculate_text_size)
1014 pos_text->width = text_width;
1015 if (pos_text->height == -1 || calculate_text_size)
1016 pos_text->height = text_height;
1018 if (visibleMenuPos(pos_button))
1020 if (pos_text->x == -1)
1021 pos_text->x = pos_button->x + pos_button->width;
1022 if (pos_text->y == -1)
1024 pos_button->y + (pos_button->height - pos_text->height) / 2;
1028 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1030 if (visibleTextPos(pos_text))
1032 if (pos_input->x == -1)
1033 pos_input->x = pos_text->x + pos_text->width;
1034 if (pos_input->y == -1)
1035 pos_input->y = pos_text->y;
1038 if (pos_input->width == -1)
1039 pos_input->width = input_width;
1040 if (pos_input->height == -1)
1041 pos_input->height = input_height;
1046 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1047 int graphic, boolean pressed)
1049 struct GraphicInfo *g = &graphic_info[graphic];
1052 int xoffset = (pressed ? g->pressed_xoffset : 0);
1053 int yoffset = (pressed ? g->pressed_yoffset : 0);
1055 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1057 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1058 g->width, g->height, dst_x, dst_y);
1061 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1062 boolean active_input,
1063 boolean pressed_button)
1067 for (i = 0; main_controls[i].nr != -1; i++)
1069 struct MainControlInfo *mci = &main_controls[i];
1071 if (mci->nr == nr || nr == -1)
1073 struct MenuPosInfo *pos_button = mci->pos_button;
1074 struct TextPosInfo *pos_text = mci->pos_text;
1075 struct TextPosInfo *pos_input = mci->pos_input;
1076 char *text = (mci->text ? *mci->text : NULL);
1077 char *input = (mci->input ? *mci->input : NULL);
1078 int button_graphic = mci->button_graphic;
1079 int font_text = (pos_text ? pos_text->font : -1);
1080 int font_input = (pos_input ? pos_input->font : -1);
1084 button_graphic = BUTTON_ACTIVE(button_graphic);
1085 font_text = FONT_ACTIVE(font_text);
1090 font_input = FONT_ACTIVE(font_input);
1093 if (visibleMenuPos(pos_button))
1095 struct MenuPosInfo *pos = pos_button;
1096 int x = mSX + pos->x;
1097 int y = mSY + pos->y;
1099 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1100 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1103 if (visibleTextPos(pos_text) && text != NULL)
1105 struct TextPosInfo *pos = pos_text;
1106 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1107 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1110 /* (check why/if this is needed) */
1111 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1113 DrawText(x, y, text, font_text);
1116 if (visibleTextPos(pos_input) && input != NULL)
1118 struct TextPosInfo *pos = pos_input;
1119 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1120 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1123 /* (check why/if this is needed) */
1124 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1126 DrawText(x, y, input, font_input);
1132 static void DrawCursorAndText_Main(int nr, boolean active_text,
1133 boolean pressed_button)
1135 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1139 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1140 boolean pressed_button)
1142 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1146 static struct MainControlInfo *getMainControlInfo(int nr)
1150 for (i = 0; main_controls[i].nr != -1; i++)
1151 if (main_controls[i].nr == nr)
1152 return &main_controls[i];
1157 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1162 int rect_x = ALIGNED_TEXT_XPOS(rect);
1163 int rect_y = ALIGNED_TEXT_YPOS(rect);
1165 return (x >= rect_x && x < rect_x + rect->width &&
1166 y >= rect_y && y < rect_y + rect->height);
1169 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1174 int rect_x = ALIGNED_TEXT_XPOS(rect);
1175 int rect_y = ALIGNED_TEXT_YPOS(rect);
1178 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1179 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1180 (x >= rect_x && x < rect_x + rect->width &&
1181 y >= rect_y && y < rect_y + rect->height));
1184 return (x >= rect_x && x < rect_x + rect->width &&
1185 y >= rect_y && y < rect_y + rect->height);
1188 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1190 int rect_width = preview->xsize * preview->tile_size;
1191 int rect_height = preview->ysize * preview->tile_size;
1192 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1193 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1195 return (x >= rect_x && x < rect_x + rect_width &&
1196 y >= rect_y && y < rect_y + rect_height);
1199 static void AdjustScrollbar(int id, int items_max, int items_visible,
1202 struct GadgetInfo *gi = screen_gadget[id];
1204 if (item_position > items_max - items_visible)
1205 item_position = items_max - items_visible;
1207 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1208 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1209 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1212 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1214 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1218 static void clearMenuListArea()
1220 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1222 /* correct scrollbar position if placed outside menu (playfield) area */
1223 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1224 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1226 /* clear menu list area, but not title or scrollbar */
1227 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1228 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1231 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1233 static int cursor_array[MAX_LEV_FIELDY];
1234 int x = mSX + TILEX * xpos;
1235 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1240 cursor_array[ypos] = graphic;
1242 graphic = cursor_array[ypos];
1246 graphic = BUTTON_ACTIVE(graphic);
1248 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1249 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1252 static void initCursor(int ypos, int graphic)
1254 drawCursorExt(0, ypos, FALSE, graphic);
1257 static void drawCursor(int ypos, boolean active)
1259 drawCursorExt(0, ypos, active, -1);
1262 static void drawCursorXY(int xpos, int ypos, int graphic)
1264 drawCursorExt(xpos, ypos, FALSE, graphic);
1267 static void drawChooseTreeCursor(int ypos, boolean active)
1269 drawCursorExt(0, ypos, active, -1);
1274 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1275 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1276 setup.internal.program_copyright);
1279 void DrawTitleScreenImage(int nr, boolean initial)
1281 int graphic = getTitleScreenGraphic(nr, initial);
1282 Bitmap *bitmap = graphic_info[graphic].bitmap;
1283 int width = graphic_info[graphic].width;
1284 int height = graphic_info[graphic].height;
1285 int src_x = graphic_info[graphic].src_x;
1286 int src_y = graphic_info[graphic].src_y;
1292 if (width > WIN_XSIZE)
1294 /* image width too large for window => center image horizontally */
1295 src_x = (width - WIN_XSIZE) / 2;
1299 if (height > WIN_YSIZE)
1301 /* image height too large for window => center image vertically */
1302 src_y = (height - WIN_YSIZE) / 2;
1306 /* always display title screens centered */
1307 dst_x = (WIN_XSIZE - width) / 2;
1308 dst_y = (WIN_YSIZE - height) / 2;
1310 SetDrawBackgroundMask(REDRAW_ALL);
1311 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1313 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1315 if (DrawingOnBackground(dst_x, dst_y))
1316 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1318 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1320 redraw_mask = REDRAW_ALL;
1323 void DrawTitleScreenMessage(int nr, boolean initial)
1325 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1326 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1328 if (filename == NULL)
1331 /* force TITLE font on title message screen */
1332 SetFontStatus(getTitleMessageGameMode(initial));
1334 /* if chars *and* width set to "-1", automatically determine width */
1335 if (tmi->chars == -1 && tmi->width == -1)
1336 tmi->width = viewport.window[game_status].width;
1338 /* if lines *and* height set to "-1", automatically determine height */
1339 if (tmi->lines == -1 && tmi->height == -1)
1340 tmi->height = viewport.window[game_status].height;
1342 /* if chars set to "-1", automatically determine by text and font width */
1343 if (tmi->chars == -1)
1344 tmi->chars = tmi->width / getFontWidth(tmi->font);
1346 tmi->width = tmi->chars * getFontWidth(tmi->font);
1348 /* if lines set to "-1", automatically determine by text and font height */
1349 if (tmi->lines == -1)
1350 tmi->lines = tmi->height / getFontHeight(tmi->font);
1352 tmi->height = tmi->lines * getFontHeight(tmi->font);
1354 /* if x set to "-1", automatically determine by width and alignment */
1356 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1358 /* if y set to "-1", automatically determine by height and alignment */
1360 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1362 SetDrawBackgroundMask(REDRAW_ALL);
1363 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1365 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1367 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1368 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1369 tmi->autowrap, tmi->centered, tmi->parse_comments);
1374 void DrawTitleScreen()
1376 KeyboardAutoRepeatOff();
1378 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1381 boolean CheckTitleScreen(boolean levelset_has_changed)
1383 static boolean show_title_initial = TRUE;
1384 boolean show_titlescreen = FALSE;
1386 /* needed to be able to skip title screen, if no image or message defined */
1387 InitializeTitleControls(show_title_initial);
1389 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1390 show_titlescreen = TRUE;
1392 /* show initial title images and messages only once at program start */
1393 show_title_initial = FALSE;
1395 return (show_titlescreen && num_title_screens > 0);
1400 static LevelDirTree *leveldir_last_valid = NULL;
1401 boolean levelset_has_changed = FALSE;
1402 int fade_mask = REDRAW_FIELD;
1404 LimitScreenUpdates(FALSE);
1406 FadeSetLeaveScreen();
1408 /* do not fade out here -- function may continue and fade on editor screen */
1411 FadeMenuSoundsAndMusic();
1413 ExpireSoundLoops(FALSE);
1415 KeyboardAutoRepeatOn();
1418 audio.sound_deactivated = FALSE;
1422 /* needed if last screen was the playing screen, invoked from level editor */
1423 if (level_editor_test_game)
1425 CloseDoor(DOOR_CLOSE_ALL);
1427 SetGameStatus(GAME_MODE_EDITOR);
1434 /* needed if last screen was the setup screen and fullscreen state changed */
1435 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1436 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1438 /* leveldir_current may be invalid (level group, parent link) */
1439 if (!validLevelSeries(leveldir_current))
1440 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1442 if (leveldir_current != leveldir_last_valid)
1443 levelset_has_changed = TRUE;
1445 /* store valid level series information */
1446 leveldir_last_valid = leveldir_current;
1448 init_last = init; /* switch to new busy animation */
1450 /* needed if last screen (level choice) changed graphics, sounds or music */
1451 ReloadCustomArtwork(0);
1453 if (CheckTitleScreen(levelset_has_changed))
1455 SetGameStatus(GAME_MODE_TITLE);
1462 if (redraw_mask & REDRAW_ALL)
1463 fade_mask = REDRAW_ALL;
1465 if (CheckIfGlobalBorderHasChanged())
1466 fade_mask = REDRAW_ALL;
1470 /* needed if different viewport properties defined for menues */
1471 ChangeViewportPropertiesIfNeeded();
1473 SetDrawtoField(DRAW_TO_BACKBUFFER);
1475 /* level_nr may have been set to value over handicap with level editor */
1476 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1477 level_nr = leveldir_current->handicap_level;
1479 LoadLevel(level_nr);
1480 LoadScore(level_nr);
1482 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1483 SetDrawDeactivationMask(REDRAW_NONE);
1484 SetDrawBackgroundMask(REDRAW_FIELD);
1486 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1489 if (fade_mask == REDRAW_ALL)
1490 RedrawGlobalBorder();
1495 InitializeMainControls();
1497 DrawCursorAndText_Main(-1, FALSE, FALSE);
1498 DrawPreviewLevelInitial();
1500 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1503 if (TAPE_IS_EMPTY(tape))
1505 DrawCompleteVideoDisplay();
1507 PlayMenuSoundsAndMusic();
1509 /* create gadgets for main menu screen */
1510 FreeScreenGadgets();
1511 CreateScreenGadgets();
1513 /* map gadgets for main menu screen */
1515 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1517 /* copy actual game door content to door double buffer for OpenDoor() */
1518 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1519 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1521 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1523 DrawMaskedBorder(fade_mask);
1528 /* update screen area with special editor door */
1529 redraw_mask |= REDRAW_ALL;
1532 SetMouseCursor(CURSOR_DEFAULT);
1534 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1537 static void gotoTopLevelDir()
1539 /* move upwards until inside (but not above) top level directory */
1540 while (leveldir_current->node_parent &&
1541 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1543 /* write a "path" into level tree for easy navigation to last level */
1544 if (leveldir_current->node_parent->node_group->cl_first == -1)
1546 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1547 int leveldir_pos = posTreeInfo(leveldir_current);
1548 int num_page_entries;
1549 int cl_first, cl_cursor;
1551 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1552 num_page_entries = num_leveldirs;
1554 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1556 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1557 cl_cursor = leveldir_pos - cl_first;
1559 leveldir_current->node_parent->node_group->cl_first = cl_first;
1560 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1563 leveldir_current = leveldir_current->node_parent;
1567 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1569 static unsigned int title_delay = 0;
1570 static int title_screen_nr = 0;
1571 static int last_sound = -1, last_music = -1;
1572 boolean return_to_main_menu = FALSE;
1573 struct TitleControlInfo *tci;
1576 if (button == MB_MENU_INITIALIZE)
1579 title_screen_nr = 0;
1580 tci = &title_controls[title_screen_nr];
1582 SetAnimStatus(getTitleAnimMode(tci));
1584 last_sound = SND_UNDEFINED;
1585 last_music = MUS_UNDEFINED;
1587 if (num_title_screens != 0)
1589 FadeSetEnterScreen();
1591 /* use individual title fading instead of global "enter screen" fading */
1592 fading = getTitleFading(tci);
1595 if (game_status_last_screen == GAME_MODE_INFO)
1597 if (num_title_screens == 0)
1599 /* switch game mode from title screen mode back to info screen mode */
1600 SetGameStatus(GAME_MODE_INFO);
1602 /* store that last screen was info screen, not main menu screen */
1603 game_status_last_screen = GAME_MODE_INFO;
1605 DrawInfoScreen_NotAvailable("Title screen information:",
1606 "No title screen for this level set.");
1610 FadeMenuSoundsAndMusic();
1613 FadeOut(REDRAW_ALL);
1615 /* title screens may have different window size */
1616 ChangeViewportPropertiesIfNeeded();
1618 /* only required to update logic for redrawing global border */
1622 DrawTitleScreenImage(tci->local_nr, tci->initial);
1624 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1626 sound = getTitleSound(tci);
1627 music = getTitleMusic(tci);
1629 if (sound != last_sound)
1630 PlayMenuSoundExt(sound);
1631 if (music != last_music)
1632 PlayMenuMusicExt(music);
1637 SetMouseCursor(CURSOR_NONE);
1641 DelayReached(&title_delay, 0); /* reset delay counter */
1646 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1647 button = MB_MENU_CHOICE;
1649 if (button == MB_MENU_LEAVE)
1651 return_to_main_menu = TRUE;
1653 else if (button == MB_MENU_CHOICE)
1655 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1657 SetGameStatus(GAME_MODE_INFO);
1659 info_mode = INFO_MODE_MAIN;
1668 if (title_screen_nr < num_title_screens)
1670 tci = &title_controls[title_screen_nr];
1672 SetAnimStatus(getTitleAnimMode(tci));
1674 sound = getTitleSound(tci);
1675 music = getTitleMusic(tci);
1677 if (last_sound != SND_UNDEFINED && sound != last_sound)
1678 FadeSound(last_sound);
1679 if (last_music != MUS_UNDEFINED && music != last_music)
1682 fading = getTitleFading(tci);
1684 FadeOut(REDRAW_ALL);
1687 DrawTitleScreenImage(tci->local_nr, tci->initial);
1689 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1691 sound = getTitleSound(tci);
1692 music = getTitleMusic(tci);
1694 if (sound != last_sound)
1695 PlayMenuSoundExt(sound);
1696 if (music != last_music)
1697 PlayMenuMusicExt(music);
1704 DelayReached(&title_delay, 0); /* reset delay counter */
1708 FadeMenuSoundsAndMusic();
1710 return_to_main_menu = TRUE;
1714 if (return_to_main_menu)
1716 SetMouseCursor(CURSOR_DEFAULT);
1718 /* force full menu screen redraw after displaying title screens */
1719 redraw_mask = REDRAW_ALL;
1721 if (game_status_last_screen == GAME_MODE_INFO)
1723 SetGameStatus(GAME_MODE_INFO);
1725 info_mode = INFO_MODE_MAIN;
1729 else /* default: return to main menu */
1731 SetGameStatus(GAME_MODE_MAIN);
1738 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1740 int old_level_nr = level_nr;
1743 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1744 new_level_nr = selected_level_nr;
1746 new_level_nr = old_level_nr + step * direction;
1748 if (new_level_nr < leveldir_current->first_level)
1749 new_level_nr = leveldir_current->first_level;
1750 if (new_level_nr > leveldir_current->last_level)
1751 new_level_nr = leveldir_current->last_level;
1753 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1755 /* skipping levels is only allowed when trying to skip single level */
1756 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1757 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1759 leveldir_current->handicap_level++;
1760 SaveLevelSetup_SeriesInfo();
1763 new_level_nr = leveldir_current->handicap_level;
1766 if (new_level_nr != old_level_nr)
1768 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1770 PlaySound(SND_MENU_ITEM_SELECTING);
1772 level_nr = new_level_nr;
1774 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1775 int2str(level_nr, menu.main.text.level_number.size),
1776 mci->pos_text->font);
1778 LoadLevel(level_nr);
1779 DrawPreviewLevelInitial();
1783 DrawCompleteVideoDisplay();
1785 /* needed because DrawPreviewLevelInitial() takes some time */
1787 /* SyncDisplay(); */
1791 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1793 static int choice = MAIN_CONTROL_GAME;
1794 static boolean button_pressed_last = FALSE;
1795 boolean button_pressed = FALSE;
1799 if (button == MB_MENU_INITIALIZE)
1801 DrawCursorAndText_Main(choice, TRUE, FALSE);
1806 if (mx || my) /* mouse input */
1810 for (i = 0; main_controls[i].nr != -1; i++)
1812 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1813 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1814 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1816 pos = main_controls[i].nr;
1822 /* check if level preview was clicked */
1823 if (insidePreviewRect(&preview, mx - SX, my - SY))
1824 pos = MAIN_CONTROL_GAME;
1826 // handle pressed/unpressed state for active/inactive menu buttons
1827 // (if pos != -1, "i" contains index position corresponding to "pos")
1829 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1830 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1831 button_pressed = TRUE;
1833 if (button_pressed != button_pressed_last)
1835 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1838 PlaySound(SND_MENU_BUTTON_PRESSING);
1840 PlaySound(SND_MENU_BUTTON_RELEASING);
1843 else if (dx || dy) /* keyboard input */
1845 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1846 choice == MAIN_CONTROL_SETUP))
1847 button = MB_MENU_CHOICE;
1852 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1854 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1856 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1858 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1860 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1862 CloseDoor(DOOR_CLOSE_2);
1864 SetGameStatus(GAME_MODE_LEVELNR);
1866 DrawChooseLevelNr();
1868 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1874 PlaySound(SND_MENU_ITEM_ACTIVATING);
1876 DrawCursorAndText_Main(choice, FALSE, FALSE);
1877 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1883 if (choice != MAIN_CONTROL_INFO &&
1884 choice != MAIN_CONTROL_SETUP)
1885 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
1890 PlaySound(SND_MENU_ITEM_SELECTING);
1892 if (pos == MAIN_CONTROL_NAME)
1894 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1896 HandleTypeName(strlen(setup.player_name), 0);
1898 else if (pos == MAIN_CONTROL_LEVELS)
1902 CloseDoor(DOOR_CLOSE_2);
1904 SetGameStatus(GAME_MODE_LEVELS);
1906 SaveLevelSetup_LastSeries();
1907 SaveLevelSetup_SeriesInfo();
1909 if (setup.internal.choose_from_top_leveldir)
1912 DrawChooseLevelSet();
1915 else if (pos == MAIN_CONTROL_SCORES)
1917 CloseDoor(DOOR_CLOSE_2);
1919 SetGameStatus(GAME_MODE_SCORES);
1923 else if (pos == MAIN_CONTROL_EDITOR)
1925 if (leveldir_current->readonly &&
1926 !strEqual(setup.player_name, "Artsoft"))
1927 Request("This level is read only!", REQ_CONFIRM);
1929 CloseDoor(DOOR_CLOSE_2);
1931 SetGameStatus(GAME_MODE_EDITOR);
1933 FadeSetEnterScreen();
1937 else if (pos == MAIN_CONTROL_INFO)
1939 CloseDoor(DOOR_CLOSE_2);
1941 SetGameStatus(GAME_MODE_INFO);
1943 info_mode = INFO_MODE_MAIN;
1947 else if (pos == MAIN_CONTROL_GAME)
1949 StartGameActions(options.network, setup.autorecord, level.random_seed);
1951 else if (pos == MAIN_CONTROL_SETUP)
1953 CloseDoor(DOOR_CLOSE_2);
1955 SetGameStatus(GAME_MODE_SETUP);
1957 setup_mode = SETUP_MODE_MAIN;
1961 else if (pos == MAIN_CONTROL_QUIT)
1963 SaveLevelSetup_LastSeries();
1964 SaveLevelSetup_SeriesInfo();
1966 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1967 SetGameStatus(GAME_MODE_QUIT);
1972 button_pressed_last = button_pressed;
1976 /* ========================================================================= */
1977 /* info screen functions */
1978 /* ========================================================================= */
1980 static struct TokenInfo *info_info;
1981 static int num_info_info; /* number of info entries shown on screen */
1982 static int max_info_info; /* total number of info entries in list */
1984 static void execInfoTitleScreen()
1986 info_mode = INFO_MODE_TITLE;
1991 static void execInfoElements()
1993 info_mode = INFO_MODE_ELEMENTS;
1998 static void execInfoMusic()
2000 info_mode = INFO_MODE_MUSIC;
2005 static void execInfoCredits()
2007 info_mode = INFO_MODE_CREDITS;
2012 static void execInfoProgram()
2014 info_mode = INFO_MODE_PROGRAM;
2019 static void execInfoVersion()
2021 info_mode = INFO_MODE_VERSION;
2026 static void execInfoLevelSet()
2028 info_mode = INFO_MODE_LEVELSET;
2033 static void execExitInfo()
2035 SetGameStatus(GAME_MODE_MAIN);
2040 static struct TokenInfo info_info_main[] =
2042 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2043 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2044 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2045 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2046 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2047 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2048 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2049 { TYPE_EMPTY, NULL, "" },
2050 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2055 static int getMenuTextFont(int type)
2057 if (type & (TYPE_SWITCH |
2069 static struct TokenInfo *setup_info;
2070 static struct TokenInfo setup_info_input[];
2072 static struct TokenInfo *menu_info;
2074 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2075 int screen_pos, int menu_info_pos_raw,
2078 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2079 struct TokenInfo *ti = &token_info[pos];
2080 int xpos = MENU_SCREEN_START_XPOS;
2081 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2082 int font_nr = getMenuTextFont(ti->type);
2084 if (token_info == setup_info_input)
2085 font_nr = FONT_MENU_1;
2088 font_nr = FONT_ACTIVE(font_nr);
2090 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2092 if (ti->type & ~TYPE_SKIP_ENTRY)
2093 drawCursor(screen_pos, active);
2096 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2099 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2102 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2105 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2108 static char *window_size_text;
2109 static char *scaling_type_text;
2111 static void drawSetupValue(int, int);
2113 static void drawMenuInfoList(int first_entry, int num_page_entries,
2114 int max_page_entries)
2118 if (first_entry + num_page_entries > max_page_entries)
2121 clearMenuListArea();
2123 for (i = 0; i < num_page_entries; i++)
2125 int menu_info_pos = first_entry + i;
2126 struct TokenInfo *si = &menu_info[menu_info_pos];
2127 void *value_ptr = si->value;
2129 /* set some entries to "unchangeable" according to other variables */
2130 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2131 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2132 (value_ptr == &setup.sound_music && !audio.music_available) ||
2133 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2134 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2135 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2136 si->type |= TYPE_GHOSTED;
2138 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2139 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2140 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2141 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2142 else if (si->type & ~TYPE_SKIP_ENTRY)
2143 initCursor(i, IMG_MENU_BUTTON);
2145 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2147 if (si->type & TYPE_VALUE &&
2148 menu_info == setup_info)
2149 drawSetupValue(i, menu_info_pos);
2153 static void DrawInfoScreen_Main()
2155 int fade_mask = REDRAW_FIELD;
2158 if (redraw_mask & REDRAW_ALL)
2159 fade_mask = REDRAW_ALL;
2161 if (CheckIfGlobalBorderHasChanged())
2162 fade_mask = REDRAW_ALL;
2165 FadeMenuSoundsAndMusic();
2167 FreeScreenGadgets();
2168 CreateScreenGadgets();
2170 /* (needed after displaying title screens which disable auto repeat) */
2171 KeyboardAutoRepeatOn();
2173 FadeSetLeaveScreen();
2177 /* needed if different viewport properties defined for info screen */
2178 ChangeViewportPropertiesIfNeeded();
2180 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2184 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2186 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2188 info_info = info_info_main;
2190 // determine maximal number of info entries that can be displayed on screen
2192 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2195 // determine maximal number of info entries available for menu of info screen
2197 for (i = 0; info_info[i].type != 0; i++)
2200 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2202 MapScreenGadgets(max_info_info);
2204 PlayMenuSoundsAndMusic();
2206 DrawMaskedBorder(fade_mask);
2211 static void changeSetupValue(int, int, int);
2213 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2214 int mode, int num_page_entries, int max_page_entries)
2216 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2217 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2218 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2219 int *num_page_entries_last = num_page_entries_all_last[game_status];
2220 int *choice_store = choice_stores[game_status];
2221 int *first_entry_store = first_entry_stores[game_status];
2222 int choice = choice_store[mode]; /* starts with 0 */
2223 int first_entry = first_entry_store[mode]; /* starts with 0 */
2225 int y = choice - first_entry;
2227 boolean position_set_by_scrollbar = (dx == 999);
2228 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2231 if (button == MB_MENU_INITIALIZE)
2233 // check if number of menu page entries has changed (may happen by change
2234 // of custom artwork definition value for 'list_size' for this menu screen)
2235 // (in this case, the last menu position most probably has to be corrected)
2236 if (num_page_entries != num_page_entries_last[mode])
2238 choice_store[mode] = first_entry_store[mode] = 0;
2240 choice = first_entry = 0;
2243 num_page_entries_last[mode] = num_page_entries;
2246 /* advance to first valid menu entry */
2247 while (choice < num_page_entries &&
2248 menu_info[choice].type & TYPE_SKIP_ENTRY)
2251 if (position_set_by_scrollbar)
2252 first_entry = first_entry_store[mode] = dy;
2254 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2255 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2257 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2259 if (choice < first_entry)
2261 choice = first_entry;
2263 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2266 else if (choice > first_entry + num_page_entries - 1)
2268 choice = first_entry + num_page_entries - 1;
2270 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2274 choice_store[mode] = choice;
2276 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2280 else if (button == MB_MENU_LEAVE)
2282 PlaySound(SND_MENU_ITEM_SELECTING);
2284 for (i = 0; i < max_page_entries; i++)
2286 if (menu_info[i].type & TYPE_LEAVE_MENU)
2288 void (*menu_callback_function)(void) = menu_info[i].value;
2292 menu_callback_function();
2294 break; /* absolutely needed because function changes 'menu_info'! */
2301 if (mx || my) /* mouse input */
2303 x = (mx - mSX) / 32;
2304 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2306 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2308 /* move cursor instead of scrolling when already at start/end of list */
2309 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2311 else if (dy == +1 * SCROLL_LINE &&
2312 first_entry + num_page_entries == max_page_entries)
2315 /* handle scrolling screen one line or page */
2317 y + dy > num_page_entries - 1)
2319 boolean redraw = FALSE;
2321 if (ABS(dy) == SCROLL_PAGE)
2322 step = num_page_entries - 1;
2324 if (dy < 0 && first_entry > 0)
2326 /* scroll page/line up */
2328 first_entry -= step;
2329 if (first_entry < 0)
2334 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2336 /* scroll page/line down */
2338 first_entry += step;
2339 if (first_entry + num_page_entries > max_page_entries)
2340 first_entry = MAX(0, max_page_entries - num_page_entries);
2347 choice += first_entry - first_entry_store[mode];
2349 if (choice < first_entry)
2351 choice = first_entry;
2353 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2356 else if (choice > first_entry + num_page_entries - 1)
2358 choice = first_entry + num_page_entries - 1;
2360 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2363 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2367 if (choice < first_entry ||
2368 choice > first_entry + num_page_entries - 1)
2369 first_entry += SIGN(dy);
2372 first_entry_store[mode] = first_entry;
2373 choice_store[mode] = choice;
2375 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2377 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2379 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2380 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2388 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2390 if (menu_info[choice].type & menu_navigation_type ||
2391 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2392 menu_info[choice].type & TYPE_YES_NO_AUTO)
2393 button = MB_MENU_CHOICE;
2398 /* jump to next non-empty menu entry (up or down) */
2399 while (first_entry + y > 0 &&
2400 first_entry + y < max_page_entries - 1 &&
2401 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2404 if (!IN_VIS_MENU(x, y))
2406 choice += y - y_old;
2408 if (choice < first_entry)
2409 first_entry = choice;
2410 else if (choice > first_entry + num_page_entries - 1)
2411 first_entry = choice - num_page_entries + 1;
2413 if (first_entry >= 0 &&
2414 first_entry + num_page_entries <= max_page_entries)
2416 first_entry_store[mode] = first_entry;
2418 if (choice < first_entry)
2419 choice = first_entry;
2420 else if (choice > first_entry + num_page_entries - 1)
2421 choice = first_entry + num_page_entries - 1;
2423 choice_store[mode] = choice;
2425 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2427 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2429 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2430 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2437 if (!anyScrollbarGadgetActive() &&
2438 IN_VIS_MENU(x, y) &&
2439 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2440 y >= 0 && y < num_page_entries)
2444 if (first_entry + y != choice &&
2445 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2447 PlaySound(SND_MENU_ITEM_ACTIVATING);
2449 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2450 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2452 choice = choice_store[mode] = first_entry + y;
2456 PlaySound(SND_MENU_ITEM_SELECTING);
2458 for (i = 0; menu_info[i].type != 0; i++)
2460 if (menu_info[i].type & TYPE_LEAVE_MENU)
2462 void (*menu_callback_function)(void) = menu_info[i].value;
2466 menu_callback_function();
2468 /* absolutely needed because function changes 'menu_info'! */
2476 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2478 PlaySound(SND_MENU_ITEM_SELECTING);
2480 /* when selecting key headline, execute function for key value change */
2481 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2482 menu_info[first_entry + y + 1].type & TYPE_KEY)
2485 /* when selecting string value, execute function for list selection */
2486 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2487 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2490 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2492 void (*menu_callback_function)(void) =
2493 menu_info[first_entry + y].value;
2495 FadeSetFromType(menu_info[first_entry + y].type);
2497 menu_callback_function();
2499 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2500 menu_info == setup_info)
2502 changeSetupValue(y, first_entry + y, dx);
2508 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2510 menu_info = info_info;
2512 HandleMenuScreen(mx, my, dx, dy, button,
2513 info_mode, num_info_info, max_info_info);
2516 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2518 int ystart1 = mSY - SY + 100;
2519 int ystart2 = mSY - SY + 150;
2520 int ybottom = mSY - SY + SYSIZE - 20;
2522 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2524 FadeOut(REDRAW_FIELD);
2529 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2530 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2532 DrawTextSCentered(ybottom, FONT_TEXT_4,
2533 "Press any key or button for info menu");
2535 FadeIn(REDRAW_FIELD);
2538 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2540 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2541 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2542 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2543 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2544 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2545 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2546 int ystep = MENU_SCREEN_INFO_YSTEP;
2547 int element, action, direction;
2555 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2556 infoscreen_step[i] = infoscreen_frame[i] = 0;
2561 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2563 DrawTextSCentered(ybottom, FONT_TEXT_4,
2564 "Press any key or button for next page");
2570 while (helpanim_info[j].element != HELPANIM_LIST_END)
2572 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2577 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2586 j += infoscreen_step[i - start];
2588 element = helpanim_info[j].element;
2589 action = helpanim_info[j].action;
2590 direction = helpanim_info[j].direction;
2593 element = EL_UNKNOWN;
2595 if (action != -1 && direction != -1)
2596 graphic = el_act_dir2img(element, action, direction);
2597 else if (action != -1)
2598 graphic = el_act2img(element, action);
2599 else if (direction != -1)
2600 graphic = el_dir2img(element, direction);
2602 graphic = el2img(element);
2604 delay = helpanim_info[j++].delay;
2609 if (infoscreen_frame[i - start] == 0)
2612 infoscreen_frame[i - start] = delay - 1;
2616 sync_frame = delay - infoscreen_frame[i - start];
2617 infoscreen_frame[i - start]--;
2620 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2622 if (!infoscreen_frame[i - start])
2623 infoscreen_step[i - start] = 0;
2627 if (!infoscreen_frame[i - start])
2628 infoscreen_step[i - start]++;
2629 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2635 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2637 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2638 graphic, sync_frame, USE_MASKING);
2641 DrawInfoScreen_HelpText(element, action, direction, i - start);
2646 redraw_mask |= REDRAW_FIELD;
2651 static char *getHelpText(int element, int action, int direction)
2653 char token[MAX_LINE_LEN];
2655 strcpy(token, element_info[element].token_name);
2658 strcat(token, element_action_info[action].suffix);
2660 if (direction != -1)
2661 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2663 return getHashEntry(helptext_info, token);
2666 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2668 int font_nr = FONT_INFO_ELEMENTS;
2669 int font_width = getFontWidth(font_nr);
2670 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2671 int sy = mSY + 65 + 2 * 32 + 1;
2672 int ystep = TILEY + 4;
2673 int pad_x = sx - SX;
2674 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2675 int max_lines_per_text = 2;
2678 if (action != -1 && direction != -1) /* element.action.direction */
2679 text = getHelpText(element, action, direction);
2681 if (text == NULL && action != -1) /* element.action */
2682 text = getHelpText(element, action, -1);
2684 if (text == NULL && direction != -1) /* element.direction */
2685 text = getHelpText(element, -1, direction);
2687 if (text == NULL) /* base element */
2688 text = getHelpText(element, -1, -1);
2690 if (text == NULL) /* not found */
2691 text = "No description available";
2693 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2694 sy += getFontHeight(font_nr) / 2;
2696 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2697 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2698 TRUE, FALSE, FALSE);
2701 void DrawInfoScreen_TitleScreen()
2703 SetGameStatus(GAME_MODE_TITLE);
2708 void HandleInfoScreen_TitleScreen(int button)
2710 HandleTitleScreen(0, 0, 0, 0, button);
2713 void DrawInfoScreen_Elements()
2715 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2717 FadeOut(REDRAW_FIELD);
2722 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2724 FadeIn(REDRAW_FIELD);
2727 void HandleInfoScreen_Elements(int button)
2729 static unsigned int info_delay = 0;
2730 static int num_anims;
2731 static int num_pages;
2733 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2736 if (button == MB_MENU_INITIALIZE)
2738 boolean new_element = TRUE;
2742 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2744 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2746 else if (new_element)
2749 new_element = FALSE;
2753 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2757 if (button == MB_MENU_LEAVE)
2759 PlaySound(SND_MENU_ITEM_SELECTING);
2761 info_mode = INFO_MODE_MAIN;
2766 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2768 if (button != MB_MENU_INITIALIZE)
2770 PlaySound(SND_MENU_ITEM_SELECTING);
2775 if (page >= num_pages)
2777 FadeMenuSoundsAndMusic();
2779 info_mode = INFO_MODE_MAIN;
2786 FadeSetNextScreen();
2788 if (button != MB_MENU_INITIALIZE)
2789 FadeOut(REDRAW_FIELD);
2791 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2793 if (button != MB_MENU_INITIALIZE)
2794 FadeIn(REDRAW_FIELD);
2798 if (DelayReached(&info_delay, GameFrameDelay))
2799 if (page < num_pages)
2800 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2802 PlayMenuSoundIfLoop();
2806 void DrawInfoScreen_Music()
2808 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2810 FadeOut(REDRAW_FIELD);
2817 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2819 FadeIn(REDRAW_FIELD);
2822 void HandleInfoScreen_Music(int button)
2824 static struct MusicFileInfo *list = NULL;
2825 int ystart1 = mSY - SY + 100;
2826 int ystart2 = mSY - SY + 150;
2827 int ybottom = mSY - SY + SYSIZE - 20;
2830 if (button == MB_MENU_INITIALIZE)
2832 list = music_file_info;
2836 FadeMenuSoundsAndMusic();
2841 DrawTextSCentered(ystart1, FONT_TEXT_1,
2842 "No music info for this level set.");
2844 DrawTextSCentered(ybottom, FONT_TEXT_4,
2845 "Press any key or button for info menu");
2851 if (button == MB_MENU_LEAVE)
2853 PlaySound(SND_MENU_ITEM_SELECTING);
2855 FadeMenuSoundsAndMusic();
2857 info_mode = INFO_MODE_MAIN;
2862 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2866 if (button != MB_MENU_INITIALIZE)
2868 PlaySound(SND_MENU_ITEM_SELECTING);
2876 FadeMenuSoundsAndMusic();
2878 info_mode = INFO_MODE_MAIN;
2884 FadeMenuSoundsAndMusic();
2886 if (list != music_file_info)
2887 FadeSetNextScreen();
2889 if (button != MB_MENU_INITIALIZE)
2890 FadeOut(REDRAW_FIELD);
2897 int sound = list->music;
2899 if (sound_info[sound].loop)
2900 PlaySoundLoop(sound);
2904 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2908 PlayMusic(list->music);
2910 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2913 if (!strEqual(list->title, UNKNOWN_NAME))
2915 if (!strEqual(list->title_header, UNKNOWN_NAME))
2916 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2918 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2921 if (!strEqual(list->artist, UNKNOWN_NAME))
2923 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2924 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2926 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2928 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2931 if (!strEqual(list->album, UNKNOWN_NAME))
2933 if (!strEqual(list->album_header, UNKNOWN_NAME))
2934 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2936 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2938 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2941 if (!strEqual(list->year, UNKNOWN_NAME))
2943 if (!strEqual(list->year_header, UNKNOWN_NAME))
2944 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2946 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2948 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2951 DrawTextSCentered(ybottom, FONT_TEXT_4,
2952 "Press any key or button for next page");
2954 if (button != MB_MENU_INITIALIZE)
2955 FadeIn(REDRAW_FIELD);
2958 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2959 PlaySoundLoop(list->music);
2962 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2964 int ystart1 = mSY - SY + 100;
2965 int ystart2 = mSY - SY + 150;
2966 int ybottom = mSY - SY + SYSIZE - 20;
2972 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2976 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2977 "Special thanks to");
2978 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2980 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2982 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2983 "\"Boulder Dash\"");
2984 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2986 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2988 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2990 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2991 "First Star Software");
2993 else if (screen_nr == 1)
2995 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2996 "Special thanks to");
2997 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2998 "Klaus Heinz & Volker Wertich");
2999 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3001 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3002 "\"Emerald Mine\"");
3003 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3005 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3007 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3009 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3012 else if (screen_nr == 2)
3014 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3015 "Special thanks to");
3016 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3017 "Michael Stopp & Philip Jespersen");
3018 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3020 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3022 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3024 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3026 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3028 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3029 "Digital Integration");
3031 else if (screen_nr == 3)
3033 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3034 "Special thanks to");
3035 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3036 "Hiroyuki Imabayashi");
3037 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3039 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3041 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3043 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3045 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3047 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3050 else if (screen_nr == 4)
3052 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3053 "Special thanks to");
3054 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3056 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3058 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3059 "J\xfcrgen Bonhagen");
3060 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3061 "for the continuous creation");
3062 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3063 "of outstanding level sets");
3065 else if (screen_nr == 5)
3067 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3069 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3071 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3072 "for ideas and inspiration by");
3073 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3076 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3078 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3080 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3081 "for ideas and inspiration by");
3082 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3085 else if (screen_nr == 6)
3087 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3089 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3092 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3093 "for the code base used for the");
3094 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3095 "native Emerald Mine engine");
3097 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3098 "for the new Emerald Mine engine");
3101 else if (screen_nr == 7)
3103 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3105 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3107 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3108 "for the initial DOS port");
3110 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3112 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3114 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3115 "for some additional toons");
3117 else if (screen_nr == 8)
3119 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3120 "And not to forget:");
3121 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3123 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3124 "All those who contributed");
3125 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3126 "levels to this game");
3127 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3131 DrawTextSCentered(ybottom, FONT_TEXT_4,
3132 "Press any key or button for next page");
3135 void DrawInfoScreen_Credits()
3137 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3139 FadeMenuSoundsAndMusic();
3141 FadeOut(REDRAW_FIELD);
3143 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3145 FadeIn(REDRAW_FIELD);
3148 void HandleInfoScreen_Credits(int button)
3150 static int screen_nr = 0;
3151 int num_screens = 9;
3153 if (button == MB_MENU_INITIALIZE)
3157 // DrawInfoScreen_CreditsScreen(screen_nr);
3160 if (button == MB_MENU_LEAVE)
3162 PlaySound(SND_MENU_ITEM_SELECTING);
3164 info_mode = INFO_MODE_MAIN;
3169 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3171 if (button != MB_MENU_INITIALIZE)
3173 PlaySound(SND_MENU_ITEM_SELECTING);
3178 if (screen_nr >= num_screens)
3180 FadeMenuSoundsAndMusic();
3182 info_mode = INFO_MODE_MAIN;
3189 FadeSetNextScreen();
3191 if (button != MB_MENU_INITIALIZE)
3192 FadeOut(REDRAW_FIELD);
3194 DrawInfoScreen_CreditsScreen(screen_nr);
3196 if (button != MB_MENU_INITIALIZE)
3197 FadeIn(REDRAW_FIELD);
3201 PlayMenuSoundIfLoop();
3205 void DrawInfoScreen_Program()
3207 int ystart1 = mSY - SY + 100;
3208 int ystart2 = mSY - SY + 150;
3209 int ybottom = mSY - SY + SYSIZE - 20;
3212 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3214 FadeOut(REDRAW_FIELD);
3219 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3221 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3222 "This game is Freeware!");
3223 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3224 "If you like it, send e-mail to:");
3225 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3226 setup.internal.program_email);
3227 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3228 "More information and levels:");
3229 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3230 setup.internal.program_website);
3231 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3232 "If you have created new levels,");
3233 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3234 "send them to me to include them!");
3235 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3238 DrawTextSCentered(ybottom, FONT_TEXT_4,
3239 "Press any key or button for info menu");
3241 FadeIn(REDRAW_FIELD);
3244 void HandleInfoScreen_Program(int button)
3246 if (button == MB_MENU_LEAVE)
3248 PlaySound(SND_MENU_ITEM_SELECTING);
3250 info_mode = INFO_MODE_MAIN;
3255 else if (button == MB_MENU_CHOICE)
3257 PlaySound(SND_MENU_ITEM_SELECTING);
3259 FadeMenuSoundsAndMusic();
3261 info_mode = INFO_MODE_MAIN;
3266 PlayMenuSoundIfLoop();
3270 void DrawInfoScreen_Version()
3272 int font_header = FONT_TEXT_3;
3273 int font_text = FONT_TEXT_2;
3274 int xstep = getFontWidth(font_text);
3275 int ystep = getFontHeight(font_text);
3276 int ystart1 = mSY - SY + 100;
3277 int ystart2 = mSY - SY + 150;
3278 int ybottom = mSY - SY + SYSIZE - 20;
3279 int xstart1 = mSX - SX + 2 * xstep;
3280 int xstart2 = mSX - SX + 18 * xstep;
3281 int xstart3 = mSX - SX + 28 * xstep;
3282 SDL_version sdl_version_compiled;
3283 const SDL_version *sdl_version_linked;
3284 int driver_name_len = 10;
3285 #if defined(TARGET_SDL2)
3286 SDL_version sdl_version_linked_ext;
3287 const char *driver_name = NULL;
3289 char driver_name[driver_name_len];
3292 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3294 FadeOut(REDRAW_FIELD);
3299 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3301 DrawTextF(xstart1, ystart2, font_header, "Name");
3302 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3305 DrawTextF(xstart1, ystart2, font_header, "Version");
3306 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3309 DrawTextF(xstart1, ystart2, font_header, "Platform");
3310 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3313 DrawTextF(xstart1, ystart2, font_header, "Target");
3314 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3317 DrawTextF(xstart1, ystart2, font_header, "Source date");
3318 DrawTextF(xstart2, ystart2, font_text, getSourceDateString());
3320 ystart2 += 3 * ystep;
3321 DrawTextF(xstart1, ystart2, font_header, "Library");
3322 DrawTextF(xstart2, ystart2, font_header, "compiled");
3323 DrawTextF(xstart3, ystart2, font_header, "linked");
3325 SDL_VERSION(&sdl_version_compiled);
3326 #if defined(TARGET_SDL2)
3327 SDL_GetVersion(&sdl_version_linked_ext);
3328 sdl_version_linked = &sdl_version_linked_ext;
3330 sdl_version_linked = SDL_Linked_Version();
3333 ystart2 += 2 * ystep;
3334 DrawTextF(xstart1, ystart2, font_text, "SDL");
3335 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3336 sdl_version_compiled.major,
3337 sdl_version_compiled.minor,
3338 sdl_version_compiled.patch);
3339 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3340 sdl_version_linked->major,
3341 sdl_version_linked->minor,
3342 sdl_version_linked->patch);
3344 SDL_IMAGE_VERSION(&sdl_version_compiled);
3345 sdl_version_linked = IMG_Linked_Version();
3348 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3349 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3350 sdl_version_compiled.major,
3351 sdl_version_compiled.minor,
3352 sdl_version_compiled.patch);
3353 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3354 sdl_version_linked->major,
3355 sdl_version_linked->minor,
3356 sdl_version_linked->patch);
3358 SDL_MIXER_VERSION(&sdl_version_compiled);
3359 sdl_version_linked = Mix_Linked_Version();
3362 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3363 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3364 sdl_version_compiled.major,
3365 sdl_version_compiled.minor,
3366 sdl_version_compiled.patch);
3367 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3368 sdl_version_linked->major,
3369 sdl_version_linked->minor,
3370 sdl_version_linked->patch);
3372 SDL_NET_VERSION(&sdl_version_compiled);
3373 sdl_version_linked = SDLNet_Linked_Version();
3376 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3377 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3378 sdl_version_compiled.major,
3379 sdl_version_compiled.minor,
3380 sdl_version_compiled.patch);
3381 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3382 sdl_version_linked->major,
3383 sdl_version_linked->minor,
3384 sdl_version_linked->patch);
3386 ystart2 += 3 * ystep;
3387 DrawTextF(xstart1, ystart2, font_header, "Driver");
3388 DrawTextF(xstart2, ystart2, font_header, "Requested");
3389 DrawTextF(xstart3, ystart2, font_header, "Used");
3391 #if defined(TARGET_SDL2)
3392 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3394 SDL_VideoDriverName(driver_name, driver_name_len);
3397 ystart2 += 2 * ystep;
3398 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3399 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3400 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3402 #if defined(TARGET_SDL2)
3403 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3405 SDL_AudioDriverName(driver_name, driver_name_len);
3409 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3410 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3411 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3413 DrawTextSCentered(ybottom, FONT_TEXT_4,
3414 "Press any key or button for info menu");
3416 FadeIn(REDRAW_FIELD);
3419 void HandleInfoScreen_Version(int button)
3421 if (button == MB_MENU_LEAVE)
3423 PlaySound(SND_MENU_ITEM_SELECTING);
3425 info_mode = INFO_MODE_MAIN;
3430 else if (button == MB_MENU_CHOICE)
3432 PlaySound(SND_MENU_ITEM_SELECTING);
3434 FadeMenuSoundsAndMusic();
3436 info_mode = INFO_MODE_MAIN;
3441 PlayMenuSoundIfLoop();
3445 void DrawInfoScreen_LevelSet()
3447 struct TitleMessageInfo *tmi = &readme;
3448 char *filename = getLevelSetInfoFilename();
3449 char *title = "Level Set Information:";
3450 int ystart1 = mSY - SY + 100;
3451 int ybottom = mSY - SY + SYSIZE - 20;
3453 if (filename == NULL)
3455 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3460 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3462 FadeOut(REDRAW_FIELD);
3467 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3469 /* if x position set to "-1", automatically determine by playfield width */
3471 tmi->x = SXSIZE / 2;
3473 /* if y position set to "-1", use static default value */
3477 /* if width set to "-1", automatically determine by playfield width */
3478 if (tmi->width == -1)
3479 tmi->width = SXSIZE - 2 * TILEX;
3481 /* if height set to "-1", automatically determine by playfield height */
3482 if (tmi->height == -1)
3483 tmi->height = SYSIZE - 20 - tmi->y - 10;
3485 /* if chars set to "-1", automatically determine by text and font width */
3486 if (tmi->chars == -1)
3487 tmi->chars = tmi->width / getFontWidth(tmi->font);
3489 tmi->width = tmi->chars * getFontWidth(tmi->font);
3491 /* if lines set to "-1", automatically determine by text and font height */
3492 if (tmi->lines == -1)
3493 tmi->lines = tmi->height / getFontHeight(tmi->font);
3495 tmi->height = tmi->lines * getFontHeight(tmi->font);
3497 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3498 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3499 tmi->autowrap, tmi->centered, tmi->parse_comments);
3501 DrawTextSCentered(ybottom, FONT_TEXT_4,
3502 "Press any key or button for info menu");
3504 FadeIn(REDRAW_FIELD);
3507 void HandleInfoScreen_LevelSet(int button)
3509 if (button == MB_MENU_LEAVE)
3511 PlaySound(SND_MENU_ITEM_SELECTING);
3513 info_mode = INFO_MODE_MAIN;
3518 else if (button == MB_MENU_CHOICE)
3520 PlaySound(SND_MENU_ITEM_SELECTING);
3522 FadeMenuSoundsAndMusic();
3524 info_mode = INFO_MODE_MAIN;
3529 PlayMenuSoundIfLoop();
3533 static void DrawInfoScreen()
3535 if (info_mode == INFO_MODE_TITLE)
3536 DrawInfoScreen_TitleScreen();
3537 else if (info_mode == INFO_MODE_ELEMENTS)
3538 DrawInfoScreen_Elements();
3539 else if (info_mode == INFO_MODE_MUSIC)
3540 DrawInfoScreen_Music();
3541 else if (info_mode == INFO_MODE_CREDITS)
3542 DrawInfoScreen_Credits();
3543 else if (info_mode == INFO_MODE_PROGRAM)
3544 DrawInfoScreen_Program();
3545 else if (info_mode == INFO_MODE_VERSION)
3546 DrawInfoScreen_Version();
3547 else if (info_mode == INFO_MODE_LEVELSET)
3548 DrawInfoScreen_LevelSet();
3550 DrawInfoScreen_Main();
3552 if (info_mode != INFO_MODE_MAIN &&
3553 info_mode != INFO_MODE_TITLE &&
3554 info_mode != INFO_MODE_MUSIC)
3555 PlayMenuSoundsAndMusic();
3558 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3560 if (info_mode == INFO_MODE_TITLE)
3561 HandleInfoScreen_TitleScreen(button);
3562 else if (info_mode == INFO_MODE_ELEMENTS)
3563 HandleInfoScreen_Elements(button);
3564 else if (info_mode == INFO_MODE_MUSIC)
3565 HandleInfoScreen_Music(button);
3566 else if (info_mode == INFO_MODE_CREDITS)
3567 HandleInfoScreen_Credits(button);
3568 else if (info_mode == INFO_MODE_PROGRAM)
3569 HandleInfoScreen_Program(button);
3570 else if (info_mode == INFO_MODE_VERSION)
3571 HandleInfoScreen_Version(button);
3572 else if (info_mode == INFO_MODE_LEVELSET)
3573 HandleInfoScreen_LevelSet(button);
3575 HandleInfoScreen_Main(mx, my, dx, dy, button);
3579 /* ========================================================================= */
3580 /* type name functions */
3581 /* ========================================================================= */
3583 void HandleTypeName(int newxpos, Key key)
3585 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3586 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3587 struct TextPosInfo *pos = mci->pos_input;
3588 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3589 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3590 static int xpos = 0;
3591 int font_nr = pos->font;
3592 int font_active_nr = FONT_ACTIVE(font_nr);
3593 int font_width = getFontWidth(font_active_nr);
3594 char key_char = getValidConfigValueChar(getCharFromKey(key));
3595 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3596 boolean is_active = TRUE;
3598 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3602 strcpy(last_player_name, setup.player_name);
3606 StartTextInput(startx, starty, pos->width, pos->height);
3608 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3610 setup.player_name[xpos] = key_char;
3611 setup.player_name[xpos + 1] = 0;
3615 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3619 setup.player_name[xpos] = 0;
3621 else if (key == KSYM_Return && xpos > 0)
3627 SetGameStatus(GAME_MODE_MAIN);
3629 else if (key == KSYM_Escape)
3631 strcpy(setup.player_name, last_player_name);
3635 SetGameStatus(GAME_MODE_MAIN);
3640 pos->width = (strlen(setup.player_name) + 1) * font_width;
3641 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3643 DrawText(startx, starty, setup.player_name, font_active_nr);
3644 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3648 pos->width = strlen(setup.player_name) * font_width;
3649 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3651 DrawText(startx, starty, setup.player_name, font_nr);
3658 /* ========================================================================= */
3659 /* tree menu functions */
3660 /* ========================================================================= */
3662 static void DrawChooseTree(TreeInfo **ti_ptr)
3664 int fade_mask = REDRAW_FIELD;
3666 if (CheckIfGlobalBorderHasChanged())
3667 fade_mask = REDRAW_ALL;
3669 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3671 SetGameStatus(GAME_MODE_MAIN);
3680 FreeScreenGadgets();
3681 CreateScreenGadgets();
3685 /* needed if different viewport properties defined for choosing level (set) */
3686 ChangeViewportPropertiesIfNeeded();
3688 if (game_status == GAME_MODE_LEVELNR)
3689 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3690 else if (game_status == GAME_MODE_LEVELS)
3691 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3695 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3697 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3698 MapScreenTreeGadgets(*ti_ptr);
3700 DrawMaskedBorder(fade_mask);
3705 static void drawChooseTreeList(int first_entry, int num_page_entries,
3709 char *title_string = NULL;
3710 int yoffset_sets = MENU_TITLE1_YPOS;
3711 int yoffset_setup = 16;
3712 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3713 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3715 title_string = ti->infotext;
3717 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3719 clearMenuListArea();
3721 for (i = 0; i < num_page_entries; i++)
3723 TreeInfo *node, *node_first;
3724 int entry_pos = first_entry + i;
3725 int xpos = MENU_SCREEN_START_XPOS;
3726 int ypos = MENU_SCREEN_START_YPOS + i;
3727 int startx = mSX + xpos * 32;
3728 int starty = mSY + ypos * 32;
3729 int font_nr = FONT_TEXT_1;
3730 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3731 int startx_text = startx + font_xoffset;
3732 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3733 int text_size = startx_scrollbar - startx_text;
3734 int max_buffer_len = text_size / getFontWidth(font_nr);
3735 char buffer[max_buffer_len + 1];
3737 node_first = getTreeInfoFirstGroupEntry(ti);
3738 node = getTreeInfoFromPos(node_first, entry_pos);
3740 strncpy(buffer, node->name, max_buffer_len);
3741 buffer[max_buffer_len] = '\0';
3743 DrawText(startx, starty, buffer, font_nr + node->color);
3745 if (node->parent_link)
3746 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3747 else if (node->level_group)
3748 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3750 initCursor(i, IMG_MENU_BUTTON);
3753 redraw_mask |= REDRAW_FIELD;
3756 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3758 TreeInfo *node, *node_first;
3759 int x, last_redraw_mask = redraw_mask;
3760 int ypos = MENU_TITLE2_YPOS;
3761 int font_nr = FONT_TITLE_2;
3763 if (ti->type == TREE_TYPE_LEVEL_NR)
3764 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3766 if (ti->type != TREE_TYPE_LEVEL_DIR)
3769 node_first = getTreeInfoFirstGroupEntry(ti);
3770 node = getTreeInfoFromPos(node_first, entry_pos);
3772 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3774 if (node->parent_link)
3775 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3776 node->node_parent->name);
3777 else if (node->level_group)
3778 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3780 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3781 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3782 node->levels, (node->levels > 1 ? "levels" : "level"),
3785 /* let BackToFront() redraw only what is needed */
3786 redraw_mask = last_redraw_mask;
3787 for (x = 0; x < SCR_FIELDX; x++)
3788 MarkTileDirty(x, 1);
3791 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3794 TreeInfo *ti = *ti_ptr;
3796 int y = ti->cl_cursor;
3797 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3798 int num_entries = numTreeInfoInGroup(ti);
3799 int num_page_entries;
3800 boolean position_set_by_scrollbar = (dx == 999);
3802 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3803 num_page_entries = num_entries;
3805 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3807 if (button == MB_MENU_INITIALIZE)
3809 int num_entries = numTreeInfoInGroup(ti);
3810 int entry_pos = posTreeInfo(ti);
3812 if (ti->cl_first == -1)
3814 /* only on initialization */
3815 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3816 ti->cl_cursor = entry_pos - ti->cl_first;
3818 else if (ti->cl_cursor >= num_page_entries ||
3819 (num_entries > num_page_entries &&
3820 num_entries - ti->cl_first < num_page_entries))
3822 /* only after change of list size (by custom graphic configuration) */
3823 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3824 ti->cl_cursor = entry_pos - ti->cl_first;
3827 if (position_set_by_scrollbar)
3830 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3833 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3834 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3835 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3839 else if (button == MB_MENU_LEAVE)
3843 PlaySound(SND_MENU_ITEM_SELECTING);
3845 if (ti->node_parent)
3847 *ti_ptr = ti->node_parent;
3848 DrawChooseTree(ti_ptr);
3850 else if (game_status == GAME_MODE_SETUP)
3852 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3853 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3854 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3856 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3857 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
3858 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
3859 execSetupGraphics();
3860 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3861 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3862 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3864 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3865 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3866 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3873 if (game_status == GAME_MODE_LEVELNR)
3875 int new_level_nr = atoi(level_number_current->identifier);
3877 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3880 SetGameStatus(GAME_MODE_MAIN);
3888 if (mx || my) /* mouse input */
3890 x = (mx - mSX) / 32;
3891 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3893 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3895 /* move cursor instead of scrolling when already at start/end of list */
3896 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3898 else if (dy == +1 * SCROLL_LINE &&
3899 ti->cl_first + num_page_entries == num_entries)
3902 /* handle scrolling screen one line or page */
3903 if (ti->cl_cursor + dy < 0 ||
3904 ti->cl_cursor + dy > num_page_entries - 1)
3906 boolean redraw = FALSE;
3908 if (ABS(dy) == SCROLL_PAGE)
3909 step = num_page_entries - 1;
3911 if (dy < 0 && ti->cl_first > 0)
3913 /* scroll page/line up */
3915 ti->cl_first -= step;
3916 if (ti->cl_first < 0)
3921 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3923 /* scroll page/line down */
3925 ti->cl_first += step;
3926 if (ti->cl_first + num_page_entries > num_entries)
3927 ti->cl_first = MAX(0, num_entries - num_page_entries);
3934 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3935 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3936 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3938 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3945 /* handle moving cursor one line */
3946 y = ti->cl_cursor + dy;
3951 TreeInfo *node_first, *node_cursor;
3952 int entry_pos = ti->cl_first + y;
3954 node_first = getTreeInfoFirstGroupEntry(ti);
3955 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3957 if (node_cursor->node_group)
3961 PlaySound(SND_MENU_ITEM_SELECTING);
3963 node_cursor->cl_first = ti->cl_first;
3964 node_cursor->cl_cursor = ti->cl_cursor;
3965 *ti_ptr = node_cursor->node_group;
3966 DrawChooseTree(ti_ptr);
3971 else if (dx == -1 && ti->node_parent)
3975 PlaySound(SND_MENU_ITEM_SELECTING);
3977 *ti_ptr = ti->node_parent;
3978 DrawChooseTree(ti_ptr);
3983 if (!anyScrollbarGadgetActive() &&
3984 IN_VIS_MENU(x, y) &&
3985 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3986 y >= 0 && y < num_page_entries)
3990 if (y != ti->cl_cursor)
3992 PlaySound(SND_MENU_ITEM_ACTIVATING);
3994 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3995 drawChooseTreeCursor(y, TRUE);
3996 drawChooseTreeInfo(ti->cl_first + y, ti);
4002 if (game_status == GAME_MODE_SETUP)
4004 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4005 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4006 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4008 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4009 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4010 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4011 execSetupGraphics();
4012 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4013 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4014 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4016 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4017 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4018 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4027 TreeInfo *node_first, *node_cursor;
4028 int entry_pos = ti->cl_first + y;
4030 PlaySound(SND_MENU_ITEM_SELECTING);
4032 node_first = getTreeInfoFirstGroupEntry(ti);
4033 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4035 if (node_cursor->node_group)
4039 node_cursor->cl_first = ti->cl_first;
4040 node_cursor->cl_cursor = ti->cl_cursor;
4041 *ti_ptr = node_cursor->node_group;
4042 DrawChooseTree(ti_ptr);
4044 else if (node_cursor->parent_link)
4048 *ti_ptr = node_cursor->node_parent;
4049 DrawChooseTree(ti_ptr);
4055 node_cursor->cl_first = ti->cl_first;
4056 node_cursor->cl_cursor = ti->cl_cursor;
4057 *ti_ptr = node_cursor;
4059 if (ti->type == TREE_TYPE_LEVEL_DIR)
4061 LoadLevelSetup_SeriesInfo();
4063 SaveLevelSetup_LastSeries();
4064 SaveLevelSetup_SeriesInfo();
4068 if (game_status == GAME_MODE_SETUP)
4070 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4071 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4072 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4074 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4075 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4076 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4077 execSetupGraphics();
4078 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4079 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4080 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4082 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4083 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4084 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4091 if (game_status == GAME_MODE_LEVELNR)
4093 int new_level_nr = atoi(level_number_current->identifier);
4095 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4098 SetGameStatus(GAME_MODE_MAIN);
4107 void DrawChooseLevelSet()
4109 FadeMenuSoundsAndMusic();
4111 DrawChooseTree(&leveldir_current);
4113 PlayMenuSoundsAndMusic();
4116 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4118 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4121 void DrawChooseLevelNr()
4125 FadeMenuSoundsAndMusic();
4127 if (level_number != NULL)
4129 freeTreeInfo(level_number);
4131 level_number = NULL;
4134 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4136 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4137 char identifier[32], name[32];
4140 /* temporarily load level info to get level name */
4141 LoadLevelInfoOnly(i);
4143 ti->node_top = &level_number;
4144 ti->sort_priority = 10000 + value;
4145 ti->color = (level.no_level_file ? FC_BLUE :
4146 LevelStats_getSolved(i) ? FC_GREEN :
4147 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4149 sprintf(identifier, "%d", value);
4150 sprintf(name, "%03d: %s", value,
4151 (level.no_level_file ? "(no file)" : level.name));
4153 setString(&ti->identifier, identifier);
4154 setString(&ti->name, name);
4155 setString(&ti->name_sorting, name);
4157 pushTreeInfo(&level_number, ti);
4160 /* sort level number values to start with lowest level number */
4161 sortTreeInfo(&level_number);
4163 /* set current level number to current level number */
4164 level_number_current =
4165 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4167 /* if that also fails, set current level number to first available level */
4168 if (level_number_current == NULL)
4169 level_number_current = level_number;
4171 DrawChooseTree(&level_number_current);
4173 PlayMenuSoundsAndMusic();
4176 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4178 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4181 void DrawHallOfFame(int highlight_position)
4183 int fade_mask = REDRAW_FIELD;
4185 if (CheckIfGlobalBorderHasChanged())
4186 fade_mask = REDRAW_ALL;
4189 FadeMenuSoundsAndMusic();
4191 /* (this is needed when called from GameEnd() after winning a game) */
4192 KeyboardAutoRepeatOn();
4195 /* (this is needed when called from GameEnd() after winning a game) */
4196 SetDrawDeactivationMask(REDRAW_NONE);
4197 SetDrawBackgroundMask(REDRAW_FIELD);
4199 if (highlight_position < 0)
4200 LoadScore(level_nr);
4202 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4204 FadeSetEnterScreen();
4208 /* needed if different viewport properties defined for scores */
4209 ChangeViewportPropertiesIfNeeded();
4211 PlayMenuSoundsAndMusic();
4213 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4215 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4217 DrawMaskedBorder(fade_mask);
4222 static void drawHallOfFameList(int first_entry, int highlight_position)
4226 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4229 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4230 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4231 "HighScores of Level %d", level_nr);
4233 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4235 int entry = first_entry + i;
4236 boolean active = (entry == highlight_position);
4237 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4238 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4239 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4240 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4241 int dxoff = getFontDrawOffsetX(font_nr1);
4242 int dx1 = 3 * getFontWidth(font_nr1);
4243 int dx2 = dx1 + getFontWidth(font_nr1);
4244 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4245 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4246 int sy = mSY + 64 + i * 32;
4248 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4249 DrawText(mSX + dx1, sy, ".", font_nr1);
4251 for (j = 0; j < num_dots; j++)
4252 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4254 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4255 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4257 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4260 redraw_mask |= REDRAW_FIELD;
4263 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4265 static int first_entry = 0;
4266 static int highlight_position = 0;
4267 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4269 if (button == MB_MENU_INITIALIZE)
4272 highlight_position = mx;
4273 drawHallOfFameList(first_entry, highlight_position);
4278 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4279 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4283 if (first_entry > 0)
4285 first_entry -= step;
4286 if (first_entry < 0)
4289 drawHallOfFameList(first_entry, highlight_position);
4294 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4296 first_entry += step;
4297 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4298 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4300 drawHallOfFameList(first_entry, highlight_position);
4303 else if (button == MB_MENU_LEAVE)
4305 PlaySound(SND_MENU_ITEM_SELECTING);
4307 FadeSound(SND_BACKGROUND_SCORES);
4309 SetGameStatus(GAME_MODE_MAIN);
4313 else if (button == MB_MENU_CHOICE)
4315 PlaySound(SND_MENU_ITEM_SELECTING);
4317 FadeSound(SND_BACKGROUND_SCORES);
4319 SetGameStatus(GAME_MODE_MAIN);
4324 if (game_status == GAME_MODE_SCORES)
4325 PlayMenuSoundIfLoop();
4329 /* ========================================================================= */
4330 /* setup screen functions */
4331 /* ========================================================================= */
4333 static struct TokenInfo *setup_info;
4334 static int num_setup_info; /* number of setup entries shown on screen */
4335 static int max_setup_info; /* total number of setup entries in list */
4337 static char *window_size_text;
4338 static char *scaling_type_text;
4339 static char *rendering_mode_text;
4340 static char *scroll_delay_text;
4341 static char *snapshot_mode_text;
4342 static char *game_speed_text;
4343 static char *graphics_set_name;
4344 static char *sounds_set_name;
4345 static char *music_set_name;
4346 static char *volume_simple_text;
4347 static char *volume_loops_text;
4348 static char *volume_music_text;
4349 static char *touch_controls_text;
4350 static char *move_distance_text;
4351 static char *drop_distance_text;
4353 static void execSetupMain()
4355 setup_mode = SETUP_MODE_MAIN;
4360 static void execSetupGame_setGameSpeeds()
4362 if (game_speeds == NULL)
4366 for (i = 0; game_speeds_list[i].value != -1; i++)
4368 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4369 char identifier[32], name[32];
4370 int value = game_speeds_list[i].value;
4371 char *text = game_speeds_list[i].text;
4373 ti->node_top = &game_speeds;
4374 ti->sort_priority = 10000 - value;
4376 sprintf(identifier, "%d", value);
4377 sprintf(name, "%s", text);
4379 setString(&ti->identifier, identifier);
4380 setString(&ti->name, name);
4381 setString(&ti->name_sorting, name);
4382 setString(&ti->infotext, "Game Speed");
4384 pushTreeInfo(&game_speeds, ti);
4387 /* sort game speed values to start with slowest game speed */
4388 sortTreeInfo(&game_speeds);
4390 /* set current game speed to configured game speed value */
4391 game_speed_current =
4392 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4394 /* if that fails, set current game speed to reliable default value */
4395 if (game_speed_current == NULL)
4396 game_speed_current =
4397 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4399 /* if that also fails, set current game speed to first available speed */
4400 if (game_speed_current == NULL)
4401 game_speed_current = game_speeds;
4404 setup.game_frame_delay = atoi(game_speed_current->identifier);
4406 /* needed for displaying game speed text instead of identifier */
4407 game_speed_text = game_speed_current->name;
4410 static void execSetupGame_setScrollDelays()
4412 if (scroll_delays == NULL)
4416 for (i = 0; scroll_delays_list[i].value != -1; i++)
4418 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4419 char identifier[32], name[32];
4420 int value = scroll_delays_list[i].value;
4421 char *text = scroll_delays_list[i].text;
4423 ti->node_top = &scroll_delays;
4424 ti->sort_priority = value;
4426 sprintf(identifier, "%d", value);
4427 sprintf(name, "%s", text);
4429 setString(&ti->identifier, identifier);
4430 setString(&ti->name, name);
4431 setString(&ti->name_sorting, name);
4432 setString(&ti->infotext, "Scroll Delay");
4434 pushTreeInfo(&scroll_delays, ti);
4437 /* sort scroll delay values to start with lowest scroll delay value */
4438 sortTreeInfo(&scroll_delays);
4440 /* set current scroll delay value to configured scroll delay value */
4441 scroll_delay_current =
4442 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4444 /* if that fails, set current scroll delay to reliable default value */
4445 if (scroll_delay_current == NULL)
4446 scroll_delay_current =
4447 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4449 /* if that also fails, set current scroll delay to first available value */
4450 if (scroll_delay_current == NULL)
4451 scroll_delay_current = scroll_delays;
4454 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4456 /* needed for displaying scroll delay text instead of identifier */
4457 scroll_delay_text = scroll_delay_current->name;
4460 static void execSetupGame_setSnapshotModes()
4462 if (snapshot_modes == NULL)
4466 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4468 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4469 char identifier[32], name[32];
4470 char *value = snapshot_modes_list[i].value;
4471 char *text = snapshot_modes_list[i].text;
4473 ti->node_top = &snapshot_modes;
4474 ti->sort_priority = i;
4476 sprintf(identifier, "%s", value);
4477 sprintf(name, "%s", text);
4479 setString(&ti->identifier, identifier);
4480 setString(&ti->name, name);
4481 setString(&ti->name_sorting, name);
4482 setString(&ti->infotext, "Snapshot Mode");
4484 pushTreeInfo(&snapshot_modes, ti);
4487 /* sort snapshot mode values to start with lowest snapshot mode value */
4488 sortTreeInfo(&snapshot_modes);
4490 /* set current snapshot mode value to configured snapshot mode value */
4491 snapshot_mode_current =
4492 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4494 /* if that fails, set current snapshot mode to reliable default value */
4495 if (snapshot_mode_current == NULL)
4496 snapshot_mode_current =
4497 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4499 /* if that also fails, set current snapshot mode to first available value */
4500 if (snapshot_mode_current == NULL)
4501 snapshot_mode_current = snapshot_modes;
4504 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4506 /* needed for displaying snapshot mode text instead of identifier */
4507 snapshot_mode_text = snapshot_mode_current->name;
4510 static void execSetupGame()
4512 execSetupGame_setGameSpeeds();
4513 execSetupGame_setScrollDelays();
4514 execSetupGame_setSnapshotModes();
4516 setup_mode = SETUP_MODE_GAME;
4521 static void execSetupChooseGameSpeed()
4523 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4528 static void execSetupChooseScrollDelay()
4530 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4535 static void execSetupChooseSnapshotMode()
4537 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4542 static void execSetupEditor()
4544 setup_mode = SETUP_MODE_EDITOR;
4549 static void execSetupGraphics_setWindowSizes(boolean update_list)
4551 if (window_sizes != NULL && update_list)
4553 freeTreeInfo(window_sizes);
4555 window_sizes = NULL;
4558 if (window_sizes == NULL)
4560 boolean current_window_size_found = FALSE;
4563 for (i = 0; window_sizes_list[i].value != -1; i++)
4565 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4566 char identifier[32], name[32];
4567 int value = window_sizes_list[i].value;
4568 char *text = window_sizes_list[i].text;
4570 ti->node_top = &window_sizes;
4571 ti->sort_priority = value;
4573 sprintf(identifier, "%d", value);
4574 sprintf(name, "%s", text);
4576 setString(&ti->identifier, identifier);
4577 setString(&ti->name, name);
4578 setString(&ti->name_sorting, name);
4579 setString(&ti->infotext, "Window Scaling");
4581 pushTreeInfo(&window_sizes, ti);
4583 if (value == setup.window_scaling_percent)
4584 current_window_size_found = TRUE;
4587 if (!current_window_size_found)
4589 // add entry for non-preset window scaling value
4591 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4592 char identifier[32], name[32];
4593 int value = setup.window_scaling_percent;
4595 ti->node_top = &window_sizes;
4596 ti->sort_priority = value;
4598 sprintf(identifier, "%d", value);
4599 sprintf(name, "%d %% (Current)", value);
4601 setString(&ti->identifier, identifier);
4602 setString(&ti->name, name);
4603 setString(&ti->name_sorting, name);
4604 setString(&ti->infotext, "Window Scaling");
4606 pushTreeInfo(&window_sizes, ti);
4609 /* sort window size values to start with lowest window size value */
4610 sortTreeInfo(&window_sizes);
4612 /* set current window size value to configured window size value */
4613 window_size_current =
4614 getTreeInfoFromIdentifier(window_sizes,
4615 i_to_a(setup.window_scaling_percent));
4617 /* if that fails, set current window size to reliable default value */
4618 if (window_size_current == NULL)
4619 window_size_current =
4620 getTreeInfoFromIdentifier(window_sizes,
4621 i_to_a(STD_WINDOW_SCALING_PERCENT));
4623 /* if that also fails, set current window size to first available value */
4624 if (window_size_current == NULL)
4625 window_size_current = window_sizes;
4628 setup.window_scaling_percent = atoi(window_size_current->identifier);
4630 /* needed for displaying window size text instead of identifier */
4631 window_size_text = window_size_current->name;
4634 static void execSetupGraphics_setScalingTypes()
4636 if (scaling_types == NULL)
4640 for (i = 0; scaling_types_list[i].value != NULL; i++)
4642 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4643 char identifier[32], name[32];
4644 char *value = scaling_types_list[i].value;
4645 char *text = scaling_types_list[i].text;
4647 ti->node_top = &scaling_types;
4648 ti->sort_priority = i;
4650 sprintf(identifier, "%s", value);
4651 sprintf(name, "%s", text);
4653 setString(&ti->identifier, identifier);
4654 setString(&ti->name, name);
4655 setString(&ti->name_sorting, name);
4656 setString(&ti->infotext, "Anti-Aliasing");
4658 pushTreeInfo(&scaling_types, ti);
4661 /* sort scaling type values to start with lowest scaling type value */
4662 sortTreeInfo(&scaling_types);
4664 /* set current scaling type value to configured scaling type value */
4665 scaling_type_current =
4666 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4668 /* if that fails, set current scaling type to reliable default value */
4669 if (scaling_type_current == NULL)
4670 scaling_type_current =
4671 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4673 /* if that also fails, set current scaling type to first available value */
4674 if (scaling_type_current == NULL)
4675 scaling_type_current = scaling_types;
4678 setup.window_scaling_quality = scaling_type_current->identifier;
4680 /* needed for displaying scaling type text instead of identifier */
4681 scaling_type_text = scaling_type_current->name;
4684 static void execSetupGraphics_setRenderingModes()
4686 if (rendering_modes == NULL)
4690 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4692 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4693 char identifier[32], name[32];
4694 char *value = rendering_modes_list[i].value;
4695 char *text = rendering_modes_list[i].text;
4697 ti->node_top = &rendering_modes;
4698 ti->sort_priority = i;
4700 sprintf(identifier, "%s", value);
4701 sprintf(name, "%s", text);
4703 setString(&ti->identifier, identifier);
4704 setString(&ti->name, name);
4705 setString(&ti->name_sorting, name);
4706 setString(&ti->infotext, "Special Rendering");
4708 pushTreeInfo(&rendering_modes, ti);
4711 /* sort rendering mode values to start with lowest rendering mode value */
4712 sortTreeInfo(&rendering_modes);
4714 /* set current rendering mode value to configured rendering mode value */
4715 rendering_mode_current =
4716 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4718 /* if that fails, set current rendering mode to reliable default value */
4719 if (rendering_mode_current == NULL)
4720 rendering_mode_current =
4721 getTreeInfoFromIdentifier(rendering_modes,
4722 STR_SPECIAL_RENDERING_DEFAULT);
4724 /* if that also fails, set current rendering mode to first available one */
4725 if (rendering_mode_current == NULL)
4726 rendering_mode_current = rendering_modes;
4729 setup.screen_rendering_mode = rendering_mode_current->identifier;
4731 /* needed for displaying rendering mode text instead of identifier */
4732 rendering_mode_text = rendering_mode_current->name;
4735 static void execSetupGraphics()
4737 // update "setup.window_scaling_percent" from list selection
4738 // (in this case, window scaling was changed on setup screen)
4739 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4740 execSetupGraphics_setWindowSizes(FALSE);
4742 // update list selection from "setup.window_scaling_percent"
4743 // (window scaling may have changed by resizing the window)
4744 execSetupGraphics_setWindowSizes(TRUE);
4746 execSetupGraphics_setScalingTypes();
4747 execSetupGraphics_setRenderingModes();
4749 setup_mode = SETUP_MODE_GRAPHICS;
4753 #if defined(TARGET_SDL2)
4754 // window scaling may have changed at this point
4755 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4757 // window scaling quality may have changed at this point
4758 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4759 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4761 // screen rendering mode may have changed at this point
4762 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4766 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4767 static void execSetupChooseWindowSize()
4769 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4774 static void execSetupChooseScalingType()
4776 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4781 static void execSetupChooseRenderingMode()
4783 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4789 static void execSetupChooseVolumeSimple()
4791 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4796 static void execSetupChooseVolumeLoops()
4798 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4803 static void execSetupChooseVolumeMusic()
4805 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4810 static void execSetupSound()
4812 if (volumes_simple == NULL)
4814 boolean current_volume_simple_found = FALSE;
4817 for (i = 0; volumes_list[i].value != -1; i++)
4819 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4820 char identifier[32], name[32];
4821 int value = volumes_list[i].value;
4822 char *text = volumes_list[i].text;
4824 ti->node_top = &volumes_simple;
4825 ti->sort_priority = value;
4827 sprintf(identifier, "%d", value);
4828 sprintf(name, "%s", text);
4830 setString(&ti->identifier, identifier);
4831 setString(&ti->name, name);
4832 setString(&ti->name_sorting, name);
4833 setString(&ti->infotext, "Sound Volume");
4835 pushTreeInfo(&volumes_simple, ti);
4837 if (value == setup.volume_simple)
4838 current_volume_simple_found = TRUE;
4841 if (!current_volume_simple_found)
4843 // add entry for non-preset volume value
4845 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4846 char identifier[32], name[32];
4847 int value = setup.volume_simple;
4849 ti->node_top = &volumes_simple;
4850 ti->sort_priority = value;
4852 sprintf(identifier, "%d", value);
4853 sprintf(name, "%d %% (Current)", value);
4855 setString(&ti->identifier, identifier);
4856 setString(&ti->name, name);
4857 setString(&ti->name_sorting, name);
4858 setString(&ti->infotext, "Sound Volume");
4860 pushTreeInfo(&volumes_simple, ti);
4863 /* sort volume values to start with lowest volume value */
4864 sortTreeInfo(&volumes_simple);
4866 /* set current volume value to configured volume value */
4867 volume_simple_current =
4868 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4870 /* if that fails, set current volume to reliable default value */
4871 if (volume_simple_current == NULL)
4872 volume_simple_current =
4873 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4875 /* if that also fails, set current volume to first available value */
4876 if (volume_simple_current == NULL)
4877 volume_simple_current = volumes_simple;
4880 if (volumes_loops == NULL)
4882 boolean current_volume_loops_found = FALSE;
4885 for (i = 0; volumes_list[i].value != -1; i++)
4887 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4888 char identifier[32], name[32];
4889 int value = volumes_list[i].value;
4890 char *text = volumes_list[i].text;
4892 ti->node_top = &volumes_loops;
4893 ti->sort_priority = value;
4895 sprintf(identifier, "%d", value);
4896 sprintf(name, "%s", text);
4898 setString(&ti->identifier, identifier);
4899 setString(&ti->name, name);
4900 setString(&ti->name_sorting, name);
4901 setString(&ti->infotext, "Loops Volume");
4903 pushTreeInfo(&volumes_loops, ti);
4905 if (value == setup.volume_loops)
4906 current_volume_loops_found = TRUE;
4909 if (!current_volume_loops_found)
4911 // add entry for non-preset volume value
4913 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4914 char identifier[32], name[32];
4915 int value = setup.volume_loops;
4917 ti->node_top = &volumes_loops;
4918 ti->sort_priority = value;
4920 sprintf(identifier, "%d", value);
4921 sprintf(name, "%d %% (Current)", value);
4923 setString(&ti->identifier, identifier);
4924 setString(&ti->name, name);
4925 setString(&ti->name_sorting, name);
4926 setString(&ti->infotext, "Loops Volume");
4928 pushTreeInfo(&volumes_loops, ti);
4931 /* sort volume values to start with lowest volume value */
4932 sortTreeInfo(&volumes_loops);
4934 /* set current volume value to configured volume value */
4935 volume_loops_current =
4936 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4938 /* if that fails, set current volume to reliable default value */
4939 if (volume_loops_current == NULL)
4940 volume_loops_current =
4941 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4943 /* if that also fails, set current volume to first available value */
4944 if (volume_loops_current == NULL)
4945 volume_loops_current = volumes_loops;
4948 if (volumes_music == NULL)
4950 boolean current_volume_music_found = FALSE;
4953 for (i = 0; volumes_list[i].value != -1; i++)
4955 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4956 char identifier[32], name[32];
4957 int value = volumes_list[i].value;
4958 char *text = volumes_list[i].text;
4960 ti->node_top = &volumes_music;
4961 ti->sort_priority = value;
4963 sprintf(identifier, "%d", value);
4964 sprintf(name, "%s", text);
4966 setString(&ti->identifier, identifier);
4967 setString(&ti->name, name);
4968 setString(&ti->name_sorting, name);
4969 setString(&ti->infotext, "Music Volume");
4971 pushTreeInfo(&volumes_music, ti);
4973 if (value == setup.volume_music)
4974 current_volume_music_found = TRUE;
4977 if (!current_volume_music_found)
4979 // add entry for non-preset volume value
4981 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4982 char identifier[32], name[32];
4983 int value = setup.volume_music;
4985 ti->node_top = &volumes_music;
4986 ti->sort_priority = value;
4988 sprintf(identifier, "%d", value);
4989 sprintf(name, "%d %% (Current)", value);
4991 setString(&ti->identifier, identifier);
4992 setString(&ti->name, name);
4993 setString(&ti->name_sorting, name);
4994 setString(&ti->infotext, "Music Volume");
4996 pushTreeInfo(&volumes_music, ti);
4999 /* sort volume values to start with lowest volume value */
5000 sortTreeInfo(&volumes_music);
5002 /* set current volume value to configured volume value */
5003 volume_music_current =
5004 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5006 /* if that fails, set current volume to reliable default value */
5007 if (volume_music_current == NULL)
5008 volume_music_current =
5009 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5011 /* if that also fails, set current volume to first available value */
5012 if (volume_music_current == NULL)
5013 volume_music_current = volumes_music;
5016 setup.volume_simple = atoi(volume_simple_current->identifier);
5017 setup.volume_loops = atoi(volume_loops_current->identifier);
5018 setup.volume_music = atoi(volume_music_current->identifier);
5020 /* needed for displaying volume text instead of identifier */
5021 volume_simple_text = volume_simple_current->name;
5022 volume_loops_text = volume_loops_current->name;
5023 volume_music_text = volume_music_current->name;
5025 setup_mode = SETUP_MODE_SOUND;
5030 static void execSetupChooseTouchControls()
5032 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5037 static void execSetupChooseMoveDistance()
5039 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5044 static void execSetupChooseDropDistance()
5046 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5051 static void execSetupTouch()
5053 if (touch_controls == NULL)
5057 for (i = 0; touch_controls_list[i].value != NULL; i++)
5059 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5060 char identifier[32], name[32];
5061 char *value = touch_controls_list[i].value;
5062 char *text = touch_controls_list[i].text;
5064 ti->node_top = &touch_controls;
5065 ti->sort_priority = i;
5067 sprintf(identifier, "%s", value);
5068 sprintf(name, "%s", text);
5070 setString(&ti->identifier, identifier);
5071 setString(&ti->name, name);
5072 setString(&ti->name_sorting, name);
5073 setString(&ti->infotext, "Control Type");
5075 pushTreeInfo(&touch_controls, ti);
5078 /* sort touch control values to start with lowest touch control value */
5079 sortTreeInfo(&touch_controls);
5081 /* set current touch control value to configured touch control value */
5082 touch_control_current =
5083 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5085 /* if that fails, set current touch control to reliable default value */
5086 if (touch_control_current == NULL)
5087 touch_control_current =
5088 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5090 /* if that also fails, set current touch control to first available value */
5091 if (touch_control_current == NULL)
5092 touch_control_current = touch_controls;
5095 if (move_distances == NULL)
5099 for (i = 0; distances_list[i].value != -1; i++)
5101 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5102 char identifier[32], name[32];
5103 int value = distances_list[i].value;
5104 char *text = distances_list[i].text;
5106 ti->node_top = &move_distances;
5107 ti->sort_priority = value;
5109 sprintf(identifier, "%d", value);
5110 sprintf(name, "%s", text);
5112 setString(&ti->identifier, identifier);
5113 setString(&ti->name, name);
5114 setString(&ti->name_sorting, name);
5115 setString(&ti->infotext, "Move Distance");
5117 pushTreeInfo(&move_distances, ti);
5120 /* sort distance values to start with lowest distance value */
5121 sortTreeInfo(&move_distances);
5123 /* set current distance value to configured distance value */
5124 move_distance_current =
5125 getTreeInfoFromIdentifier(move_distances,
5126 i_to_a(setup.touch.move_distance));
5128 /* if that fails, set current distance to reliable default value */
5129 if (move_distance_current == NULL)
5130 move_distance_current =
5131 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5133 /* if that also fails, set current distance to first available value */
5134 if (move_distance_current == NULL)
5135 move_distance_current = move_distances;
5138 if (drop_distances == NULL)
5142 for (i = 0; distances_list[i].value != -1; i++)
5144 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5145 char identifier[32], name[32];
5146 int value = distances_list[i].value;
5147 char *text = distances_list[i].text;
5149 ti->node_top = &drop_distances;
5150 ti->sort_priority = value;
5152 sprintf(identifier, "%d", value);
5153 sprintf(name, "%s", text);
5155 setString(&ti->identifier, identifier);
5156 setString(&ti->name, name);
5157 setString(&ti->name_sorting, name);
5158 setString(&ti->infotext, "Drop Distance");
5160 pushTreeInfo(&drop_distances, ti);
5163 /* sort distance values to start with lowest distance value */
5164 sortTreeInfo(&drop_distances);
5166 /* set current distance value to configured distance value */
5167 drop_distance_current =
5168 getTreeInfoFromIdentifier(drop_distances,
5169 i_to_a(setup.touch.drop_distance));
5171 /* if that fails, set current distance to reliable default value */
5172 if (drop_distance_current == NULL)
5173 drop_distance_current =
5174 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5176 /* if that also fails, set current distance to first available value */
5177 if (drop_distance_current == NULL)
5178 drop_distance_current = drop_distances;
5181 setup.touch.control_type = touch_control_current->identifier;
5182 setup.touch.move_distance = atoi(move_distance_current->identifier);
5183 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5185 /* needed for displaying volume text instead of identifier */
5186 touch_controls_text = touch_control_current->name;
5187 move_distance_text = move_distance_current->name;
5188 drop_distance_text = drop_distance_current->name;
5190 setup_mode = SETUP_MODE_TOUCH;
5195 static void execSetupArtwork()
5198 printf("::: '%s', '%s', '%s'\n",
5199 artwork.gfx_current->subdir,
5200 artwork.gfx_current->fullpath,
5201 artwork.gfx_current->basepath);
5204 setup.graphics_set = artwork.gfx_current->identifier;
5205 setup.sounds_set = artwork.snd_current->identifier;
5206 setup.music_set = artwork.mus_current->identifier;
5208 /* needed if last screen (setup choice) changed graphics, sounds or music */
5209 ReloadCustomArtwork(0);
5211 /* needed for displaying artwork name instead of artwork identifier */
5212 graphics_set_name = artwork.gfx_current->name;
5213 sounds_set_name = artwork.snd_current->name;
5214 music_set_name = artwork.mus_current->name;
5216 setup_mode = SETUP_MODE_ARTWORK;
5221 static void execSetupChooseGraphics()
5223 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5228 static void execSetupChooseSounds()
5230 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5235 static void execSetupChooseMusic()
5237 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5242 #if !defined(PLATFORM_ANDROID)
5243 static void execSetupInput()
5245 setup_mode = SETUP_MODE_INPUT;
5251 static void execSetupShortcuts()
5253 setup_mode = SETUP_MODE_SHORTCUTS;
5258 static void execSetupShortcuts1()
5260 setup_mode = SETUP_MODE_SHORTCUTS_1;
5265 static void execSetupShortcuts2()
5267 setup_mode = SETUP_MODE_SHORTCUTS_2;
5272 static void execSetupShortcuts3()
5274 setup_mode = SETUP_MODE_SHORTCUTS_3;
5279 static void execSetupShortcuts4()
5281 setup_mode = SETUP_MODE_SHORTCUTS_4;
5286 static void execSetupShortcuts5()
5288 setup_mode = SETUP_MODE_SHORTCUTS_5;
5293 static void execExitSetup()
5295 SetGameStatus(GAME_MODE_MAIN);
5300 static void execSaveAndExitSetup()
5306 static struct TokenInfo setup_info_main[] =
5308 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5309 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5310 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5311 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5312 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5313 #if !defined(PLATFORM_ANDROID)
5314 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5315 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5317 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5319 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5320 { TYPE_EMPTY, NULL, "" },
5321 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5322 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5327 static struct TokenInfo setup_info_game[] =
5329 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5330 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5331 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5332 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5333 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5334 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5335 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5336 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5337 { TYPE_STRING, &game_speed_text, "" },
5339 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5340 { TYPE_STRING, &scroll_delay_text, "" },
5342 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5343 { TYPE_STRING, &snapshot_mode_text, "" },
5344 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5345 { TYPE_EMPTY, NULL, "" },
5346 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5351 static struct TokenInfo setup_info_editor[] =
5354 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5355 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5356 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5357 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5358 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5359 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5360 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5361 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5362 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5363 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5365 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5366 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5368 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5370 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5371 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5372 { TYPE_EMPTY, NULL, "" },
5374 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5375 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5376 { TYPE_EMPTY, NULL, "" },
5378 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5379 { TYPE_EMPTY, NULL, "" },
5380 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5385 static struct TokenInfo setup_info_graphics[] =
5387 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5388 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5389 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5390 { TYPE_STRING, &window_size_text, "" },
5391 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5392 { TYPE_STRING, &scaling_type_text, "" },
5393 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5394 { TYPE_STRING, &rendering_mode_text, "" },
5397 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5398 { TYPE_STRING, &scroll_delay_text, "" },
5400 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5401 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5402 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5403 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5404 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5405 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5406 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5407 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5408 { TYPE_EMPTY, NULL, "" },
5409 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5414 static struct TokenInfo setup_info_sound[] =
5416 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5417 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5418 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5419 { TYPE_EMPTY, NULL, "" },
5420 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5421 { TYPE_STRING, &volume_simple_text, "" },
5422 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5423 { TYPE_STRING, &volume_loops_text, "" },
5424 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5425 { TYPE_STRING, &volume_music_text, "" },
5426 { TYPE_EMPTY, NULL, "" },
5427 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5432 static struct TokenInfo setup_info_artwork[] =
5434 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5435 { TYPE_STRING, &graphics_set_name, "" },
5436 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5437 { TYPE_STRING, &sounds_set_name, "" },
5438 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5439 { TYPE_STRING, &music_set_name, "" },
5440 { TYPE_EMPTY, NULL, "" },
5441 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5442 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5443 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5444 { TYPE_EMPTY, NULL, "" },
5445 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5450 static struct TokenInfo setup_info_input[] =
5452 { TYPE_SWITCH, NULL, "Player:" },
5453 { TYPE_SWITCH, NULL, "Device:" },
5454 { TYPE_ENTER_MENU, NULL, "" },
5455 { TYPE_EMPTY, NULL, "" },
5456 { TYPE_EMPTY, NULL, "" },
5457 { TYPE_EMPTY, NULL, "" },
5458 { TYPE_EMPTY, NULL, "" },
5459 { TYPE_EMPTY, NULL, "" },
5460 { TYPE_EMPTY, NULL, "" },
5461 { TYPE_EMPTY, NULL, "" },
5462 { TYPE_EMPTY, NULL, "" },
5463 { TYPE_EMPTY, NULL, "" },
5464 { TYPE_EMPTY, NULL, "" },
5465 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5470 static struct TokenInfo setup_info_touch[] =
5472 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5473 { TYPE_STRING, &touch_controls_text, "" },
5474 { TYPE_EMPTY, NULL, "" },
5475 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5480 static struct TokenInfo setup_info_touch_wipe_gestures[] =
5482 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5483 { TYPE_STRING, &touch_controls_text, "" },
5484 { TYPE_EMPTY, NULL, "" },
5485 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5486 { TYPE_STRING, &move_distance_text, "" },
5487 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5488 { TYPE_STRING, &drop_distance_text, "" },
5489 { TYPE_EMPTY, NULL, "" },
5490 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5495 static struct TokenInfo setup_info_shortcuts[] =
5497 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5498 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5499 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5500 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5501 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5502 { TYPE_EMPTY, NULL, "" },
5503 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5508 static struct TokenInfo setup_info_shortcuts_1[] =
5510 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5511 { TYPE_KEY, &setup.shortcut.save_game, "" },
5512 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5513 { TYPE_KEY, &setup.shortcut.load_game, "" },
5514 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5515 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5516 { TYPE_EMPTY, NULL, "" },
5517 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5518 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5519 { TYPE_EMPTY, NULL, "" },
5520 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5525 static struct TokenInfo setup_info_shortcuts_2[] =
5527 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5528 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5529 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5530 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5531 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5532 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5533 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5534 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5535 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5536 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5537 { TYPE_EMPTY, NULL, "" },
5538 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5543 static struct TokenInfo setup_info_shortcuts_3[] =
5545 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5546 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5547 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5548 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5549 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5550 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5551 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5552 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5553 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5554 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5555 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5556 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5557 { TYPE_EMPTY, NULL, "" },
5558 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5563 static struct TokenInfo setup_info_shortcuts_4[] =
5565 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5566 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5567 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5568 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5569 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5570 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5571 { TYPE_EMPTY, NULL, "" },
5572 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5577 static struct TokenInfo setup_info_shortcuts_5[] =
5579 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5580 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5581 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5582 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5583 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5584 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5585 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5586 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5587 { TYPE_EMPTY, NULL, "" },
5588 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5593 static Key getSetupKey()
5595 Key key = KSYM_UNDEFINED;
5596 boolean got_key_event = FALSE;
5598 while (!got_key_event)
5600 if (PendingEvent()) /* got event */
5608 case EVENT_KEYPRESS:
5610 key = GetEventKey((KeyEvent *)&event, TRUE);
5612 /* press 'Escape' or 'Enter' to keep the existing key binding */
5613 if (key == KSYM_Escape || key == KSYM_Return)
5614 key = KSYM_UNDEFINED; /* keep old value */
5616 got_key_event = TRUE;
5620 case EVENT_KEYRELEASE:
5621 key_joystick_mapping = 0;
5625 HandleOtherEvents(&event);
5636 static int getSetupValueFont(int type, void *value)
5638 if (type & TYPE_KEY)
5639 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5640 else if (type & TYPE_STRING)
5641 return FONT_VALUE_2;
5642 else if (type & TYPE_ECS_AGA)
5643 return FONT_VALUE_1;
5644 else if (type & TYPE_BOOLEAN_STYLE)
5645 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5646 else if (type & TYPE_YES_NO_AUTO)
5647 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5648 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5650 return FONT_VALUE_1;
5653 static int getSetupValueFontNarrow(int type, int font_nr)
5655 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5656 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5657 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5661 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5663 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5664 struct TokenInfo *si = &setup_info[si_pos];
5665 boolean font_draw_xoffset_modified = FALSE;
5666 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5667 int font_draw_xoffset_old = -1;
5668 int xoffset = (scrollbar_needed ? -1 : 0);
5669 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5670 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5671 int xpos = menu_screen_value_xpos;
5672 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5673 int startx = mSX + xpos * 32;
5674 int starty = mSY + ypos * 32;
5675 int font_nr, font_nr_default, font_width_default;
5676 int type = si->type;
5677 void *value = si->value;
5678 char *value_string = getSetupValue(type, value);
5681 if (value_string == NULL)
5684 if (type & TYPE_KEY)
5686 xpos = MENU_SCREEN_START_XPOS;
5688 if (type & TYPE_QUERY)
5689 value_string = "<press key>";
5691 else if (type & TYPE_STRING)
5693 int max_value_len = (SCR_FIELDX - 2) * 2;
5695 xpos = MENU_SCREEN_START_XPOS;
5697 if (strlen(value_string) > max_value_len)
5698 value_string[max_value_len] = '\0';
5700 else if (type & TYPE_YES_NO_AUTO)
5702 xpos = menu_screen_value_xpos - 1;
5705 startx = mSX + xpos * 32;
5706 starty = mSY + ypos * 32;
5707 font_nr_default = getSetupValueFont(type, value);
5708 font_width_default = getFontWidth(font_nr_default);
5710 font_nr = font_nr_default;
5712 // special check if right-side setup values moved left due to scrollbar
5713 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5715 int max_menu_text_length = 26; // maximum text length for classic menu
5716 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5717 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5718 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5719 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5720 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5722 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5725 startx = mSX + xpos * 32;
5727 font_nr = getSetupValueFontNarrow(type, font_nr);
5731 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5732 if (setup_mode != SETUP_MODE_INPUT)
5734 int max_menu_text_length_big = (menu_screen_value_xpos -
5735 MENU_SCREEN_START_XPOS);
5736 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5737 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5738 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5739 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5740 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5741 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5742 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5743 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5744 boolean correct_font_draw_xoffset = FALSE;
5746 if (xpos == MENU_SCREEN_START_XPOS &&
5747 startx + font1_xoffset < text_startx + text_font_xoffset)
5748 correct_font_draw_xoffset = TRUE;
5750 if (xpos == menu_screen_value_xpos &&
5751 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5752 correct_font_draw_xoffset = TRUE;
5754 /* check if setup value would overlap with setup text when printed */
5755 /* (this can happen for extreme/wrong values for font draw offset) */
5756 if (correct_font_draw_xoffset)
5758 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5759 font_draw_xoffset_modified = TRUE;
5761 if (type & TYPE_KEY)
5762 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5763 else if (!(type & TYPE_STRING))
5764 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5765 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5769 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5770 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
5772 DrawText(startx, starty, value_string, font_nr);
5774 if (font_draw_xoffset_modified)
5775 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5778 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5780 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5781 struct TokenInfo *si = &setup_info[si_pos];
5783 if (si->type & TYPE_BOOLEAN_STYLE)
5785 *(boolean *)si->value ^= TRUE;
5787 else if (si->type & TYPE_YES_NO_AUTO)
5791 (*(int *)si->value == AUTO ? TRUE :
5792 *(int *)si->value == TRUE ? FALSE : AUTO) :
5793 (*(int *)si->value == TRUE ? AUTO :
5794 *(int *)si->value == AUTO ? FALSE : TRUE));
5796 else if (si->type & TYPE_KEY)
5800 si->type |= TYPE_QUERY;
5801 drawSetupValue(screen_pos, setup_info_pos_raw);
5802 si->type &= ~TYPE_QUERY;
5804 key = getSetupKey();
5805 if (key != KSYM_UNDEFINED)
5806 *(Key *)si->value = key;
5809 drawSetupValue(screen_pos, setup_info_pos_raw);
5811 // fullscreen state may have changed at this point
5812 if (si->value == &setup.fullscreen)
5813 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5816 static void DrawSetupScreen_Generic()
5818 int fade_mask = REDRAW_FIELD;
5819 boolean redraw_all = FALSE;
5820 char *title_string = NULL;
5823 if (CheckIfGlobalBorderHasChanged())
5824 fade_mask = REDRAW_ALL;
5827 FadeMenuSoundsAndMusic();
5829 FreeScreenGadgets();
5830 CreateScreenGadgets();
5832 if (redraw_mask & REDRAW_ALL)
5837 /* needed if different viewport properties defined for setup screen */
5838 ChangeViewportPropertiesIfNeeded();
5840 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5844 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5846 if (setup_mode == SETUP_MODE_MAIN)
5848 setup_info = setup_info_main;
5849 title_string = "Setup";
5851 else if (setup_mode == SETUP_MODE_GAME)
5853 setup_info = setup_info_game;
5854 title_string = "Setup Game";
5856 else if (setup_mode == SETUP_MODE_EDITOR)
5858 setup_info = setup_info_editor;
5859 title_string = "Setup Editor";
5861 else if (setup_mode == SETUP_MODE_GRAPHICS)
5863 setup_info = setup_info_graphics;
5864 title_string = "Setup Graphics";
5866 else if (setup_mode == SETUP_MODE_SOUND)
5868 setup_info = setup_info_sound;
5869 title_string = "Setup Sound";
5871 else if (setup_mode == SETUP_MODE_ARTWORK)
5873 setup_info = setup_info_artwork;
5874 title_string = "Custom Artwork";
5876 else if (setup_mode == SETUP_MODE_TOUCH)
5878 setup_info = setup_info_touch;
5879 title_string = "Setup Touch Ctrls";
5881 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
5882 setup_info = setup_info_touch_wipe_gestures;
5884 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5886 setup_info = setup_info_shortcuts;
5887 title_string = "Setup Shortcuts";
5889 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5891 setup_info = setup_info_shortcuts_1;
5892 title_string = "Setup Shortcuts";
5894 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5896 setup_info = setup_info_shortcuts_2;
5897 title_string = "Setup Shortcuts";
5899 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5901 setup_info = setup_info_shortcuts_3;
5902 title_string = "Setup Shortcuts";
5904 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5906 setup_info = setup_info_shortcuts_4;
5907 title_string = "Setup Shortcuts";
5909 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5911 setup_info = setup_info_shortcuts_5;
5912 title_string = "Setup Shortcuts";
5915 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5917 // determine maximal number of setup entries that can be displayed on screen
5919 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5922 // determine maximal number of setup entries available for this setup screen
5924 for (i = 0; setup_info[i].type != 0; i++)
5927 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5929 MapScreenGadgets(max_setup_info);
5932 redraw_mask = fade_mask = REDRAW_ALL;
5934 DrawMaskedBorder(fade_mask);
5939 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5941 menu_info = setup_info;
5943 HandleMenuScreen(mx, my, dx, dy, button,
5944 setup_mode, num_setup_info, max_setup_info);
5947 void DrawSetupScreen_Input()
5951 FadeOut(REDRAW_FIELD);
5955 setup_info = setup_info_input;
5957 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5959 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5960 "Joysticks deactivated on this screen");
5962 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5964 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5965 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5966 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5967 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5968 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5969 initCursor(i, IMG_MENU_BUTTON);
5971 DrawCursorAndText_Setup(i, -1, FALSE);
5974 /* create gadgets for setup input menu screen */
5975 FreeScreenGadgets();
5976 CreateScreenGadgets();
5978 /* map gadgets for setup input menu screen */
5979 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5981 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5983 FadeIn(REDRAW_FIELD);
5986 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5988 if (device_name == NULL)
5991 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5994 if (strlen(device_name) > 1)
5996 char c1 = device_name[strlen(device_name) - 1];
5997 char c2 = device_name[strlen(device_name) - 2];
5999 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6000 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6003 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6004 strlen(device_name));
6007 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6010 static struct SetupKeyboardInfo custom_key;
6017 { &custom_key.left, "Joystick Left" },
6018 { &custom_key.right, "Joystick Right" },
6019 { &custom_key.up, "Joystick Up" },
6020 { &custom_key.down, "Joystick Down" },
6021 { &custom_key.snap, "Button 1" },
6022 { &custom_key.drop, "Button 2" }
6024 static char *joystick_name[MAX_PLAYERS] =
6031 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6035 custom_key = setup.input[player_nr].key;
6037 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6038 FONT_INPUT_1_ACTIVE);
6040 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6042 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6043 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6045 if (setup.input[player_nr].use_joystick)
6047 char *device_name = setup.input[player_nr].joy.device_name;
6048 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6049 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6051 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6052 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6056 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6057 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6060 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6062 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6063 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6064 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6065 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6067 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6068 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6069 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6070 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6071 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6072 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6074 for (i = 0; i < 6; i++)
6076 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6078 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6080 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6081 (setup.input[player_nr].use_joystick ?
6083 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6087 static int input_player_nr = 0;
6089 void HandleSetupScreen_Input_Player(int step, int direction)
6091 int old_player_nr = input_player_nr;
6094 new_player_nr = old_player_nr + step * direction;
6095 if (new_player_nr < 0)
6097 if (new_player_nr > MAX_PLAYERS - 1)
6098 new_player_nr = MAX_PLAYERS - 1;
6100 if (new_player_nr != old_player_nr)
6102 input_player_nr = new_player_nr;
6104 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6108 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6110 static int choice = 0;
6113 int pos_start = SETUPINPUT_SCREEN_POS_START;
6114 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6115 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6116 int pos_end = SETUPINPUT_SCREEN_POS_END;
6118 if (button == MB_MENU_INITIALIZE)
6120 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6122 DrawCursorAndText_Setup(choice, -1, TRUE);
6126 else if (button == MB_MENU_LEAVE)
6128 setup_mode = SETUP_MODE_MAIN;
6135 if (mx || my) /* mouse input */
6137 x = (mx - mSX) / 32;
6138 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6140 else if (dx || dy) /* keyboard input */
6142 if (dx && choice == 0)
6143 x = (dx < 0 ? 10 : 12);
6144 else if ((dx && choice == 1) ||
6145 (dx == +1 && choice == 2) ||
6146 (dx == -1 && choice == pos_end))
6147 button = MB_MENU_CHOICE;
6151 if (y >= pos_empty1 && y <= pos_empty2)
6152 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6155 if (y == 0 && dx != 0 && button)
6157 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6159 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6160 y >= pos_start && y <= pos_end &&
6161 !(y >= pos_empty1 && y <= pos_empty2))
6167 DrawCursorAndText_Setup(choice, -1, FALSE);
6168 DrawCursorAndText_Setup(y, -1, TRUE);
6170 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6179 char *device_name = setup.input[input_player_nr].joy.device_name;
6181 if (!setup.input[input_player_nr].use_joystick)
6183 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6185 setJoystickDeviceToNr(device_name, new_device_nr);
6186 setup.input[input_player_nr].use_joystick = TRUE;
6190 int device_nr = getJoystickNrFromDeviceName(device_name);
6191 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6193 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6194 setup.input[input_player_nr].use_joystick = FALSE;
6196 setJoystickDeviceToNr(device_name, new_device_nr);
6199 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6203 if (setup.input[input_player_nr].use_joystick)
6206 CalibrateJoystick(input_player_nr);
6209 CustomizeKeyboard(input_player_nr);
6211 else if (y == pos_end)
6217 setup_mode = SETUP_MODE_MAIN;
6224 void CustomizeKeyboard(int player_nr)
6228 boolean finished = FALSE;
6229 static struct SetupKeyboardInfo custom_key;
6234 } customize_step[] =
6236 { &custom_key.left, "Move Left" },
6237 { &custom_key.right, "Move Right" },
6238 { &custom_key.up, "Move Up" },
6239 { &custom_key.down, "Move Down" },
6240 { &custom_key.snap, "Snap Field" },
6241 { &custom_key.drop, "Drop Element" }
6244 /* read existing key bindings from player setup */
6245 custom_key = setup.input[player_nr].key;
6248 FadeOut(REDRAW_FIELD);
6252 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6255 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6256 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6257 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6258 "Key:", FONT_INPUT_1_ACTIVE);
6259 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6260 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6262 FadeIn(REDRAW_FIELD);
6266 if (PendingEvent()) /* got event */
6274 case EVENT_KEYPRESS:
6276 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6278 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6280 if (key == KSYM_Escape)
6281 FadeSkipNextFadeIn();
6287 /* all keys configured -- wait for "Escape" or "Return" key */
6291 /* press 'Enter' to keep the existing key binding */
6292 if (key == KSYM_Return)
6293 key = *customize_step[step_nr].key;
6295 /* check if key already used */
6296 for (i = 0; i < step_nr; i++)
6297 if (*customize_step[i].key == key)
6302 /* got new key binding */
6303 *customize_step[step_nr].key = key;
6304 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6306 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6307 getKeyNameFromKey(key), FONT_VALUE_1);
6310 /* un-highlight last query */
6311 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6312 customize_step[step_nr - 1].text, FONT_MENU_1);
6313 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6314 "Key:", FONT_MENU_1);
6316 /* press 'Enter' to leave */
6319 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6320 "Press Enter", FONT_TITLE_1);
6324 /* query next key binding */
6325 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6326 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6327 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6328 "Key:", FONT_INPUT_1_ACTIVE);
6329 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6330 getKeyNameFromKey(*customize_step[step_nr].key),
6335 case EVENT_KEYRELEASE:
6336 key_joystick_mapping = 0;
6340 HandleOtherEvents(&event);
6348 /* write new key bindings back to player setup */
6349 setup.input[player_nr].key = custom_key;
6351 DrawSetupScreen_Input();
6354 static boolean CalibrateJoystickMain(int player_nr)
6356 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6357 int new_joystick_xright = JOYSTICK_XMIDDLE;
6358 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6359 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6360 int new_joystick_xmiddle, new_joystick_ymiddle;
6362 int joystick_fd = joystick.fd[player_nr];
6363 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6364 boolean check[3][3];
6365 int check_remaining = 3 * 3;
6370 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6373 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6377 FadeOut(REDRAW_FIELD);
6381 for (y = 0; y < 3; y++)
6383 for (x = 0; x < 3; x++)
6385 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6386 check[x][y] = FALSE;
6390 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6391 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6392 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6393 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6394 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6395 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6396 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6398 joy_value = Joystick(player_nr);
6399 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6400 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6402 /* eventually uncalibrated center position (joystick could be uncentered) */
6403 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6406 new_joystick_xmiddle = joy_x;
6407 new_joystick_ymiddle = joy_y;
6409 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6411 FadeIn(REDRAW_FIELD);
6413 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6417 if (PendingEvent()) /* got event */
6425 case EVENT_KEYPRESS:
6426 switch (GetEventKey((KeyEvent *)&event, TRUE))
6429 if (check_remaining == 0)
6434 FadeSkipNextFadeIn();
6443 case EVENT_KEYRELEASE:
6444 key_joystick_mapping = 0;
6448 HandleOtherEvents(&event);
6453 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6456 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6457 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6458 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6459 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6461 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6462 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6463 setup.input[player_nr].joy.xright = new_joystick_xright;
6464 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6465 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6466 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6468 CheckJoystickData();
6470 joy_value = Joystick(player_nr);
6472 if (joy_value & JOY_BUTTON && check_remaining == 0)
6475 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6476 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6478 if (x != last_x || y != last_y)
6480 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6481 IMG_MENU_CALIBRATE_YELLOW, 0);
6482 DrawFixedGraphic(xpos + x, ypos + y,
6483 IMG_MENU_CALIBRATE_RED, 0);
6488 if (check_remaining > 0 && !check[x+1][y+1])
6490 check[x+1][y+1] = TRUE;
6498 /* calibrated center position (joystick should now be centered) */
6499 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6502 new_joystick_xmiddle = joy_x;
6503 new_joystick_ymiddle = joy_y;
6505 /* wait until the last pressed button was released */
6506 while (Joystick(player_nr) & JOY_BUTTON)
6508 if (PendingEvent()) /* got event */
6513 HandleOtherEvents(&event);
6522 void CalibrateJoystick(int player_nr)
6524 if (!CalibrateJoystickMain(player_nr))
6526 char *device_name = setup.input[player_nr].joy.device_name;
6527 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6528 int xpos = mSX - SX;
6529 int ypos = mSY - SY;
6533 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6534 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6537 Delay(2000); /* show error message for a short time */
6542 DrawSetupScreen_Input();
6545 void DrawSetupScreen()
6547 DeactivateJoystick();
6549 if (setup_mode == SETUP_MODE_INPUT)
6550 DrawSetupScreen_Input();
6551 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6552 DrawChooseTree(&game_speed_current);
6553 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6554 DrawChooseTree(&scroll_delay_current);
6555 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6556 DrawChooseTree(&snapshot_mode_current);
6557 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6558 DrawChooseTree(&window_size_current);
6559 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6560 DrawChooseTree(&scaling_type_current);
6561 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6562 DrawChooseTree(&rendering_mode_current);
6563 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6564 DrawChooseTree(&artwork.gfx_current);
6565 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6566 DrawChooseTree(&artwork.snd_current);
6567 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6568 DrawChooseTree(&artwork.mus_current);
6569 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6570 DrawChooseTree(&volume_simple_current);
6571 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6572 DrawChooseTree(&volume_loops_current);
6573 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6574 DrawChooseTree(&volume_music_current);
6575 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6576 DrawChooseTree(&touch_control_current);
6577 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6578 DrawChooseTree(&move_distance_current);
6579 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6580 DrawChooseTree(&drop_distance_current);
6582 DrawSetupScreen_Generic();
6584 PlayMenuSoundsAndMusic();
6587 void RedrawSetupScreenAfterFullscreenToggle()
6589 if (setup_mode == SETUP_MODE_GRAPHICS ||
6590 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6592 // update list selection from "setup.window_scaling_percent"
6593 execSetupGraphics_setWindowSizes(TRUE);
6599 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6601 if (setup_mode == SETUP_MODE_INPUT)
6602 HandleSetupScreen_Input(mx, my, dx, dy, button);
6603 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6604 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6605 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6606 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6607 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6608 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6609 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6610 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6611 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6612 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6613 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6614 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
6615 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6616 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6617 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6618 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6619 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6620 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6621 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6622 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6623 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6624 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6625 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6626 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6627 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6628 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6629 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6630 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6631 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6632 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6634 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6637 void HandleGameActions()
6639 if (game_status != GAME_MODE_PLAYING)
6642 GameActions(); /* main game loop */
6644 if (tape.auto_play && !tape.playing)
6645 AutoPlayTape(); /* continue automatically playing next tape */
6649 /* ---------- new screen button stuff -------------------------------------- */
6651 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6655 case SCREEN_CTRL_ID_PREV_LEVEL:
6656 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6657 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6660 case SCREEN_CTRL_ID_NEXT_LEVEL:
6661 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6662 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6665 case SCREEN_CTRL_ID_PREV_PLAYER:
6666 *x = mSX + TILEX * 10;
6667 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6670 case SCREEN_CTRL_ID_NEXT_PLAYER:
6671 *x = mSX + TILEX * 12;
6672 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6676 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6682 int gfx_unpressed, gfx_pressed;
6683 void (*get_gadget_position)(int *, int *, int);
6687 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6690 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6691 getScreenMenuButtonPos,
6692 SCREEN_CTRL_ID_PREV_LEVEL,
6697 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6698 getScreenMenuButtonPos,
6699 SCREEN_CTRL_ID_NEXT_LEVEL,
6704 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6705 getScreenMenuButtonPos,
6706 SCREEN_CTRL_ID_PREV_PLAYER,
6711 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6712 getScreenMenuButtonPos,
6713 SCREEN_CTRL_ID_NEXT_PLAYER,
6721 int gfx_unpressed, gfx_pressed;
6725 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6728 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6729 -1, -1, /* these values are not constant, but can change at runtime */
6730 SCREEN_CTRL_ID_SCROLL_UP,
6734 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6735 -1, -1, /* these values are not constant, but can change at runtime */
6736 SCREEN_CTRL_ID_SCROLL_DOWN,
6743 int gfx_unpressed, gfx_pressed;
6749 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6752 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6753 -1, -1, /* these values are not constant, but can change at runtime */
6754 -1, -1, /* these values are not constant, but can change at runtime */
6755 GD_TYPE_SCROLLBAR_VERTICAL,
6756 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6757 "scroll level series vertically"
6761 static void CreateScreenMenubuttons()
6763 struct GadgetInfo *gi;
6764 unsigned int event_mask;
6767 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6769 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6770 int gfx_unpressed, gfx_pressed;
6771 int x, y, width, height;
6772 int gd_x1, gd_x2, gd_y1, gd_y2;
6773 int id = menubutton_info[i].gadget_id;
6775 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6777 menubutton_info[i].get_gadget_position(&x, &y, id);
6779 width = SC_MENUBUTTON_XSIZE;
6780 height = SC_MENUBUTTON_YSIZE;
6782 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6783 gfx_pressed = menubutton_info[i].gfx_pressed;
6784 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6785 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6786 gd_x1 = graphic_info[gfx_unpressed].src_x;
6787 gd_y1 = graphic_info[gfx_unpressed].src_y;
6788 gd_x2 = graphic_info[gfx_pressed].src_x;
6789 gd_y2 = graphic_info[gfx_pressed].src_y;
6791 gi = CreateGadget(GDI_CUSTOM_ID, id,
6792 GDI_CUSTOM_TYPE_ID, i,
6793 GDI_INFO_TEXT, menubutton_info[i].infotext,
6798 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6799 GDI_STATE, GD_BUTTON_UNPRESSED,
6800 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6801 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6802 GDI_DIRECT_DRAW, FALSE,
6803 GDI_EVENT_MASK, event_mask,
6804 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6808 Error(ERR_EXIT, "cannot create gadget");
6810 screen_gadget[id] = gi;
6814 static void CreateScreenScrollbuttons()
6816 struct GadgetInfo *gi;
6817 unsigned int event_mask;
6820 /* these values are not constant, but can change at runtime */
6821 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6822 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6823 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6824 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6826 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6828 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6829 int gfx_unpressed, gfx_pressed;
6830 int x, y, width, height;
6831 int gd_x1, gd_x2, gd_y1, gd_y2;
6832 int id = scrollbutton_info[i].gadget_id;
6834 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6836 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6837 y = mSY + scrollbutton_info[i].y;
6838 width = SC_SCROLLBUTTON_XSIZE;
6839 height = SC_SCROLLBUTTON_YSIZE;
6841 /* correct scrollbar position if placed outside menu (playfield) area */
6842 if (x > SX + SC_SCROLL_UP_XPOS)
6843 x = SX + SC_SCROLL_UP_XPOS;
6845 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6846 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6847 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6849 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6850 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6851 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6852 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6853 gd_x1 = graphic_info[gfx_unpressed].src_x;
6854 gd_y1 = graphic_info[gfx_unpressed].src_y;
6855 gd_x2 = graphic_info[gfx_pressed].src_x;
6856 gd_y2 = graphic_info[gfx_pressed].src_y;
6858 gi = CreateGadget(GDI_CUSTOM_ID, id,
6859 GDI_CUSTOM_TYPE_ID, i,
6860 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6865 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6866 GDI_STATE, GD_BUTTON_UNPRESSED,
6867 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6868 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6869 GDI_DIRECT_DRAW, FALSE,
6870 GDI_EVENT_MASK, event_mask,
6871 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6875 Error(ERR_EXIT, "cannot create gadget");
6877 screen_gadget[id] = gi;
6881 static void CreateScreenScrollbars()
6885 /* these values are not constant, but can change at runtime */
6886 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6887 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6888 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6889 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6891 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6893 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6894 int gfx_unpressed, gfx_pressed;
6895 int x, y, width, height;
6896 int gd_x1, gd_x2, gd_y1, gd_y2;
6897 struct GadgetInfo *gi;
6898 int items_max, items_visible, item_position;
6899 unsigned int event_mask;
6900 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6901 int id = scrollbar_info[i].gadget_id;
6903 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6905 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6906 y = mSY + scrollbar_info[i].y;
6907 width = scrollbar_info[i].width;
6908 height = scrollbar_info[i].height;
6910 /* correct scrollbar position if placed outside menu (playfield) area */
6911 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6912 x = SX + SC_SCROLL_VERTICAL_XPOS;
6914 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6915 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6917 items_max = num_page_entries;
6918 items_visible = num_page_entries;
6921 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6922 gfx_pressed = scrollbar_info[i].gfx_pressed;
6923 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6924 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6925 gd_x1 = graphic_info[gfx_unpressed].src_x;
6926 gd_y1 = graphic_info[gfx_unpressed].src_y;
6927 gd_x2 = graphic_info[gfx_pressed].src_x;
6928 gd_y2 = graphic_info[gfx_pressed].src_y;
6930 gi = CreateGadget(GDI_CUSTOM_ID, id,
6931 GDI_CUSTOM_TYPE_ID, i,
6932 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6937 GDI_TYPE, scrollbar_info[i].type,
6938 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6939 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6940 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6941 GDI_WHEEL_AREA_X, SX,
6942 GDI_WHEEL_AREA_Y, SY,
6943 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6944 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6945 GDI_STATE, GD_BUTTON_UNPRESSED,
6946 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6947 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6948 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6949 GDI_DIRECT_DRAW, FALSE,
6950 GDI_EVENT_MASK, event_mask,
6951 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6955 Error(ERR_EXIT, "cannot create gadget");
6957 screen_gadget[id] = gi;
6961 void CreateScreenGadgets()
6963 CreateScreenMenubuttons();
6965 CreateScreenScrollbuttons();
6966 CreateScreenScrollbars();
6969 void FreeScreenGadgets()
6973 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6974 FreeGadget(screen_gadget[i]);
6977 void MapScreenMenuGadgets(int screen_mask)
6981 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6982 if (screen_mask & menubutton_info[i].screen_mask)
6983 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6986 void MapScreenGadgets(int num_entries)
6990 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6993 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6994 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6996 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6997 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
7000 void MapScreenTreeGadgets(TreeInfo *ti)
7002 MapScreenGadgets(numTreeInfoInGroup(ti));
7005 static void HandleScreenGadgets(struct GadgetInfo *gi)
7007 int id = gi->custom_id;
7008 int button = gi->event.button;
7009 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
7013 case SCREEN_CTRL_ID_PREV_LEVEL:
7014 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
7017 case SCREEN_CTRL_ID_NEXT_LEVEL:
7018 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
7021 case SCREEN_CTRL_ID_PREV_PLAYER:
7022 HandleSetupScreen_Input_Player(step, -1);
7025 case SCREEN_CTRL_ID_NEXT_PLAYER:
7026 HandleSetupScreen_Input_Player(step, +1);
7029 case SCREEN_CTRL_ID_SCROLL_UP:
7030 if (game_status == GAME_MODE_LEVELS)
7031 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7032 else if (game_status == GAME_MODE_LEVELNR)
7033 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7034 else if (game_status == GAME_MODE_SETUP)
7035 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7036 else if (game_status == GAME_MODE_INFO)
7037 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7040 case SCREEN_CTRL_ID_SCROLL_DOWN:
7041 if (game_status == GAME_MODE_LEVELS)
7042 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7043 else if (game_status == GAME_MODE_LEVELNR)
7044 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7045 else if (game_status == GAME_MODE_SETUP)
7046 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7047 else if (game_status == GAME_MODE_INFO)
7048 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7051 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7052 if (game_status == GAME_MODE_LEVELS)
7053 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7054 else if (game_status == GAME_MODE_LEVELNR)
7055 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7056 else if (game_status == GAME_MODE_SETUP)
7057 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7058 else if (game_status == GAME_MODE_INFO)
7059 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);