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_LEVELS && dx != 0 && button)
1854 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1856 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1858 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1860 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1862 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1864 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1866 CloseDoor(DOOR_CLOSE_2);
1868 SetGameStatus(GAME_MODE_LEVELNR);
1870 DrawChooseLevelNr();
1872 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1878 PlaySound(SND_MENU_ITEM_ACTIVATING);
1880 DrawCursorAndText_Main(choice, FALSE, FALSE);
1881 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1888 PlaySound(SND_MENU_ITEM_SELECTING);
1890 if (pos == MAIN_CONTROL_NAME)
1892 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1894 HandleTypeName(strlen(setup.player_name), 0);
1896 else if (pos == MAIN_CONTROL_LEVELS)
1900 CloseDoor(DOOR_CLOSE_2);
1902 SetGameStatus(GAME_MODE_LEVELS);
1904 SaveLevelSetup_LastSeries();
1905 SaveLevelSetup_SeriesInfo();
1907 if (setup.internal.choose_from_top_leveldir)
1910 DrawChooseLevelSet();
1913 else if (pos == MAIN_CONTROL_SCORES)
1915 CloseDoor(DOOR_CLOSE_2);
1917 SetGameStatus(GAME_MODE_SCORES);
1921 else if (pos == MAIN_CONTROL_EDITOR)
1923 if (leveldir_current->readonly &&
1924 !strEqual(setup.player_name, "Artsoft"))
1925 Request("This level is read only!", REQ_CONFIRM);
1927 CloseDoor(DOOR_CLOSE_2);
1929 SetGameStatus(GAME_MODE_EDITOR);
1931 FadeSetEnterScreen();
1935 else if (pos == MAIN_CONTROL_INFO)
1937 CloseDoor(DOOR_CLOSE_2);
1939 SetGameStatus(GAME_MODE_INFO);
1941 info_mode = INFO_MODE_MAIN;
1945 else if (pos == MAIN_CONTROL_GAME)
1947 StartGameActions(options.network, setup.autorecord, level.random_seed);
1949 else if (pos == MAIN_CONTROL_SETUP)
1951 CloseDoor(DOOR_CLOSE_2);
1953 SetGameStatus(GAME_MODE_SETUP);
1955 setup_mode = SETUP_MODE_MAIN;
1959 else if (pos == MAIN_CONTROL_QUIT)
1961 SaveLevelSetup_LastSeries();
1962 SaveLevelSetup_SeriesInfo();
1964 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1965 SetGameStatus(GAME_MODE_QUIT);
1970 button_pressed_last = button_pressed;
1974 /* ========================================================================= */
1975 /* info screen functions */
1976 /* ========================================================================= */
1978 static struct TokenInfo *info_info;
1979 static int num_info_info; /* number of info entries shown on screen */
1980 static int max_info_info; /* total number of info entries in list */
1982 static void execInfoTitleScreen()
1984 info_mode = INFO_MODE_TITLE;
1989 static void execInfoElements()
1991 info_mode = INFO_MODE_ELEMENTS;
1996 static void execInfoMusic()
1998 info_mode = INFO_MODE_MUSIC;
2003 static void execInfoCredits()
2005 info_mode = INFO_MODE_CREDITS;
2010 static void execInfoProgram()
2012 info_mode = INFO_MODE_PROGRAM;
2017 static void execInfoVersion()
2019 info_mode = INFO_MODE_VERSION;
2024 static void execInfoLevelSet()
2026 info_mode = INFO_MODE_LEVELSET;
2031 static void execExitInfo()
2033 SetGameStatus(GAME_MODE_MAIN);
2038 static struct TokenInfo info_info_main[] =
2040 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2041 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2042 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2043 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2044 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2045 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2046 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2047 { TYPE_EMPTY, NULL, "" },
2048 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2053 static int getMenuTextFont(int type)
2055 if (type & (TYPE_SWITCH |
2067 static struct TokenInfo *setup_info;
2068 static struct TokenInfo setup_info_input[];
2070 static struct TokenInfo *menu_info;
2072 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2073 int screen_pos, int menu_info_pos_raw,
2076 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2077 struct TokenInfo *ti = &token_info[pos];
2078 int xpos = MENU_SCREEN_START_XPOS;
2079 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2080 int font_nr = getMenuTextFont(ti->type);
2082 if (token_info == setup_info_input)
2083 font_nr = FONT_MENU_1;
2086 font_nr = FONT_ACTIVE(font_nr);
2088 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2090 if (ti->type & ~TYPE_SKIP_ENTRY)
2091 drawCursor(screen_pos, active);
2094 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2097 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2100 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2103 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2106 static char *window_size_text;
2107 static char *scaling_type_text;
2109 static void drawSetupValue(int, int);
2111 static void drawMenuInfoList(int first_entry, int num_page_entries,
2112 int max_page_entries)
2116 if (first_entry + num_page_entries > max_page_entries)
2119 clearMenuListArea();
2121 for (i = 0; i < num_page_entries; i++)
2123 int menu_info_pos = first_entry + i;
2124 struct TokenInfo *si = &menu_info[menu_info_pos];
2125 void *value_ptr = si->value;
2127 /* set some entries to "unchangeable" according to other variables */
2128 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2129 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2130 (value_ptr == &setup.sound_music && !audio.music_available) ||
2131 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2132 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2133 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2134 si->type |= TYPE_GHOSTED;
2136 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2137 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2138 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2139 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2140 else if (si->type & ~TYPE_SKIP_ENTRY)
2141 initCursor(i, IMG_MENU_BUTTON);
2143 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2145 if (si->type & TYPE_VALUE &&
2146 menu_info == setup_info)
2147 drawSetupValue(i, menu_info_pos);
2151 static void DrawInfoScreen_Main()
2153 int fade_mask = REDRAW_FIELD;
2156 if (redraw_mask & REDRAW_ALL)
2157 fade_mask = REDRAW_ALL;
2159 if (CheckIfGlobalBorderHasChanged())
2160 fade_mask = REDRAW_ALL;
2163 FadeMenuSoundsAndMusic();
2165 FreeScreenGadgets();
2166 CreateScreenGadgets();
2168 /* (needed after displaying title screens which disable auto repeat) */
2169 KeyboardAutoRepeatOn();
2171 FadeSetLeaveScreen();
2175 /* needed if different viewport properties defined for info screen */
2176 ChangeViewportPropertiesIfNeeded();
2178 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2182 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2184 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2186 info_info = info_info_main;
2188 // determine maximal number of info entries that can be displayed on screen
2190 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2193 // determine maximal number of info entries available for menu of info screen
2195 for (i = 0; info_info[i].type != 0; i++)
2198 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2200 MapScreenGadgets(max_info_info);
2202 PlayMenuSoundsAndMusic();
2204 DrawMaskedBorder(fade_mask);
2209 static void changeSetupValue(int, int, int);
2211 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2212 int mode, int num_page_entries, int max_page_entries)
2214 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2215 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2216 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2217 int *num_page_entries_last = num_page_entries_all_last[game_status];
2218 int *choice_store = choice_stores[game_status];
2219 int *first_entry_store = first_entry_stores[game_status];
2220 int choice = choice_store[mode]; /* starts with 0 */
2221 int first_entry = first_entry_store[mode]; /* starts with 0 */
2223 int y = choice - first_entry;
2225 boolean position_set_by_scrollbar = (dx == 999);
2226 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2229 if (button == MB_MENU_INITIALIZE)
2231 // check if number of menu page entries has changed (may happen by change
2232 // of custom artwork definition value for 'list_size' for this menu screen)
2233 // (in this case, the last menu position most probably has to be corrected)
2234 if (num_page_entries != num_page_entries_last[mode])
2236 choice_store[mode] = first_entry_store[mode] = 0;
2238 choice = first_entry = 0;
2241 num_page_entries_last[mode] = num_page_entries;
2244 /* advance to first valid menu entry */
2245 while (choice < num_page_entries &&
2246 menu_info[choice].type & TYPE_SKIP_ENTRY)
2249 if (position_set_by_scrollbar)
2250 first_entry = first_entry_store[mode] = dy;
2252 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2253 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2255 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2257 if (choice < first_entry)
2259 choice = first_entry;
2261 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2264 else if (choice > first_entry + num_page_entries - 1)
2266 choice = first_entry + num_page_entries - 1;
2268 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2272 choice_store[mode] = choice;
2274 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2278 else if (button == MB_MENU_LEAVE)
2280 PlaySound(SND_MENU_ITEM_SELECTING);
2282 for (i = 0; i < max_page_entries; i++)
2284 if (menu_info[i].type & TYPE_LEAVE_MENU)
2286 void (*menu_callback_function)(void) = menu_info[i].value;
2290 menu_callback_function();
2292 break; /* absolutely needed because function changes 'menu_info'! */
2299 if (mx || my) /* mouse input */
2301 x = (mx - mSX) / 32;
2302 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2304 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2306 /* move cursor instead of scrolling when already at start/end of list */
2307 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2309 else if (dy == +1 * SCROLL_LINE &&
2310 first_entry + num_page_entries == max_page_entries)
2313 /* handle scrolling screen one line or page */
2315 y + dy > num_page_entries - 1)
2317 boolean redraw = FALSE;
2319 if (ABS(dy) == SCROLL_PAGE)
2320 step = num_page_entries - 1;
2322 if (dy < 0 && first_entry > 0)
2324 /* scroll page/line up */
2326 first_entry -= step;
2327 if (first_entry < 0)
2332 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2334 /* scroll page/line down */
2336 first_entry += step;
2337 if (first_entry + num_page_entries > max_page_entries)
2338 first_entry = MAX(0, max_page_entries - num_page_entries);
2345 choice += first_entry - first_entry_store[mode];
2347 if (choice < first_entry)
2349 choice = first_entry;
2351 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2354 else if (choice > first_entry + num_page_entries - 1)
2356 choice = first_entry + num_page_entries - 1;
2358 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2361 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2365 if (choice < first_entry ||
2366 choice > first_entry + num_page_entries - 1)
2367 first_entry += SIGN(dy);
2370 first_entry_store[mode] = first_entry;
2371 choice_store[mode] = choice;
2373 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2375 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2377 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2378 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2386 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2388 if (menu_info[choice].type & menu_navigation_type ||
2389 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2390 menu_info[choice].type & TYPE_YES_NO_AUTO)
2391 button = MB_MENU_CHOICE;
2396 /* jump to next non-empty menu entry (up or down) */
2397 while (first_entry + y > 0 &&
2398 first_entry + y < max_page_entries - 1 &&
2399 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2402 if (!IN_VIS_MENU(x, y))
2404 choice += y - y_old;
2406 if (choice < first_entry)
2407 first_entry = choice;
2408 else if (choice > first_entry + num_page_entries - 1)
2409 first_entry = choice - num_page_entries + 1;
2411 if (first_entry >= 0 &&
2412 first_entry + num_page_entries <= max_page_entries)
2414 first_entry_store[mode] = first_entry;
2416 if (choice < first_entry)
2417 choice = first_entry;
2418 else if (choice > first_entry + num_page_entries - 1)
2419 choice = first_entry + num_page_entries - 1;
2421 choice_store[mode] = choice;
2423 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2425 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2427 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2428 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2435 if (!anyScrollbarGadgetActive() &&
2436 IN_VIS_MENU(x, y) &&
2437 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2438 y >= 0 && y < num_page_entries)
2442 if (first_entry + y != choice &&
2443 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2445 PlaySound(SND_MENU_ITEM_ACTIVATING);
2447 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2448 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2450 choice = choice_store[mode] = first_entry + y;
2453 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2455 PlaySound(SND_MENU_ITEM_SELECTING);
2457 /* when selecting key headline, execute function for key value change */
2458 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2459 menu_info[first_entry + y + 1].type & TYPE_KEY)
2462 /* when selecting string value, execute function for list selection */
2463 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2464 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2467 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2469 void (*menu_callback_function)(void) =
2470 menu_info[first_entry + y].value;
2472 FadeSetFromType(menu_info[first_entry + y].type);
2474 menu_callback_function();
2476 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2477 menu_info == setup_info)
2479 changeSetupValue(y, first_entry + y, dx);
2485 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2487 menu_info = info_info;
2489 HandleMenuScreen(mx, my, dx, dy, button,
2490 info_mode, num_info_info, max_info_info);
2493 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2495 int ystart1 = mSY - SY + 100;
2496 int ystart2 = mSY - SY + 150;
2497 int ybottom = mSY - SY + SYSIZE - 20;
2499 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2501 FadeOut(REDRAW_FIELD);
2506 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2507 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2509 DrawTextSCentered(ybottom, FONT_TEXT_4,
2510 "Press any key or button for info menu");
2512 FadeIn(REDRAW_FIELD);
2515 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2517 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2518 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2519 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2520 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2521 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2522 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2523 int ystep = MENU_SCREEN_INFO_YSTEP;
2524 int element, action, direction;
2532 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2533 infoscreen_step[i] = infoscreen_frame[i] = 0;
2538 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2540 DrawTextSCentered(ybottom, FONT_TEXT_4,
2541 "Press any key or button for next page");
2547 while (helpanim_info[j].element != HELPANIM_LIST_END)
2549 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2554 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2563 j += infoscreen_step[i - start];
2565 element = helpanim_info[j].element;
2566 action = helpanim_info[j].action;
2567 direction = helpanim_info[j].direction;
2570 element = EL_UNKNOWN;
2572 if (action != -1 && direction != -1)
2573 graphic = el_act_dir2img(element, action, direction);
2574 else if (action != -1)
2575 graphic = el_act2img(element, action);
2576 else if (direction != -1)
2577 graphic = el_dir2img(element, direction);
2579 graphic = el2img(element);
2581 delay = helpanim_info[j++].delay;
2586 if (infoscreen_frame[i - start] == 0)
2589 infoscreen_frame[i - start] = delay - 1;
2593 sync_frame = delay - infoscreen_frame[i - start];
2594 infoscreen_frame[i - start]--;
2597 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2599 if (!infoscreen_frame[i - start])
2600 infoscreen_step[i - start] = 0;
2604 if (!infoscreen_frame[i - start])
2605 infoscreen_step[i - start]++;
2606 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2612 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2614 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2615 graphic, sync_frame, USE_MASKING);
2618 DrawInfoScreen_HelpText(element, action, direction, i - start);
2623 redraw_mask |= REDRAW_FIELD;
2628 static char *getHelpText(int element, int action, int direction)
2630 char token[MAX_LINE_LEN];
2632 strcpy(token, element_info[element].token_name);
2635 strcat(token, element_action_info[action].suffix);
2637 if (direction != -1)
2638 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2640 return getHashEntry(helptext_info, token);
2643 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2645 int font_nr = FONT_INFO_ELEMENTS;
2646 int font_width = getFontWidth(font_nr);
2647 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2648 int sy = mSY + 65 + 2 * 32 + 1;
2649 int ystep = TILEY + 4;
2650 int pad_x = sx - SX;
2651 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2652 int max_lines_per_text = 2;
2655 if (action != -1 && direction != -1) /* element.action.direction */
2656 text = getHelpText(element, action, direction);
2658 if (text == NULL && action != -1) /* element.action */
2659 text = getHelpText(element, action, -1);
2661 if (text == NULL && direction != -1) /* element.direction */
2662 text = getHelpText(element, -1, direction);
2664 if (text == NULL) /* base element */
2665 text = getHelpText(element, -1, -1);
2667 if (text == NULL) /* not found */
2668 text = "No description available";
2670 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2671 sy += getFontHeight(font_nr) / 2;
2673 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2674 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2675 TRUE, FALSE, FALSE);
2678 void DrawInfoScreen_TitleScreen()
2680 SetGameStatus(GAME_MODE_TITLE);
2685 void HandleInfoScreen_TitleScreen(int button)
2687 HandleTitleScreen(0, 0, 0, 0, button);
2690 void DrawInfoScreen_Elements()
2692 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2694 FadeOut(REDRAW_FIELD);
2699 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2701 FadeIn(REDRAW_FIELD);
2704 void HandleInfoScreen_Elements(int button)
2706 static unsigned int info_delay = 0;
2707 static int num_anims;
2708 static int num_pages;
2710 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2713 if (button == MB_MENU_INITIALIZE)
2715 boolean new_element = TRUE;
2719 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2721 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2723 else if (new_element)
2726 new_element = FALSE;
2730 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2734 if (button == MB_MENU_LEAVE)
2736 PlaySound(SND_MENU_ITEM_SELECTING);
2738 info_mode = INFO_MODE_MAIN;
2743 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2745 if (button != MB_MENU_INITIALIZE)
2747 PlaySound(SND_MENU_ITEM_SELECTING);
2752 if (page >= num_pages)
2754 FadeMenuSoundsAndMusic();
2756 info_mode = INFO_MODE_MAIN;
2763 FadeSetNextScreen();
2765 if (button != MB_MENU_INITIALIZE)
2766 FadeOut(REDRAW_FIELD);
2768 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2770 if (button != MB_MENU_INITIALIZE)
2771 FadeIn(REDRAW_FIELD);
2775 if (DelayReached(&info_delay, GameFrameDelay))
2776 if (page < num_pages)
2777 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2779 PlayMenuSoundIfLoop();
2783 void DrawInfoScreen_Music()
2785 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2787 FadeOut(REDRAW_FIELD);
2794 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2796 FadeIn(REDRAW_FIELD);
2799 void HandleInfoScreen_Music(int button)
2801 static struct MusicFileInfo *list = NULL;
2802 int ystart1 = mSY - SY + 100;
2803 int ystart2 = mSY - SY + 150;
2804 int ybottom = mSY - SY + SYSIZE - 20;
2807 if (button == MB_MENU_INITIALIZE)
2809 list = music_file_info;
2813 FadeMenuSoundsAndMusic();
2818 DrawTextSCentered(ystart1, FONT_TEXT_1,
2819 "No music info for this level set.");
2821 DrawTextSCentered(ybottom, FONT_TEXT_4,
2822 "Press any key or button for info menu");
2828 if (button == MB_MENU_LEAVE)
2830 PlaySound(SND_MENU_ITEM_SELECTING);
2832 FadeMenuSoundsAndMusic();
2834 info_mode = INFO_MODE_MAIN;
2839 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2843 if (button != MB_MENU_INITIALIZE)
2845 PlaySound(SND_MENU_ITEM_SELECTING);
2853 FadeMenuSoundsAndMusic();
2855 info_mode = INFO_MODE_MAIN;
2861 FadeMenuSoundsAndMusic();
2863 if (list != music_file_info)
2864 FadeSetNextScreen();
2866 if (button != MB_MENU_INITIALIZE)
2867 FadeOut(REDRAW_FIELD);
2874 int sound = list->music;
2876 if (sound_info[sound].loop)
2877 PlaySoundLoop(sound);
2881 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2885 PlayMusic(list->music);
2887 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2890 if (!strEqual(list->title, UNKNOWN_NAME))
2892 if (!strEqual(list->title_header, UNKNOWN_NAME))
2893 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2895 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2898 if (!strEqual(list->artist, UNKNOWN_NAME))
2900 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2901 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2903 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2905 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2908 if (!strEqual(list->album, UNKNOWN_NAME))
2910 if (!strEqual(list->album_header, UNKNOWN_NAME))
2911 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2913 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2915 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2918 if (!strEqual(list->year, UNKNOWN_NAME))
2920 if (!strEqual(list->year_header, UNKNOWN_NAME))
2921 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2923 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2925 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2928 DrawTextSCentered(ybottom, FONT_TEXT_4,
2929 "Press any key or button for next page");
2931 if (button != MB_MENU_INITIALIZE)
2932 FadeIn(REDRAW_FIELD);
2935 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2936 PlaySoundLoop(list->music);
2939 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2941 int ystart1 = mSY - SY + 100;
2942 int ystart2 = mSY - SY + 150;
2943 int ybottom = mSY - SY + SYSIZE - 20;
2949 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2953 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2954 "Special thanks to");
2955 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2957 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2959 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2960 "\"Boulder Dash\"");
2961 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2963 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2965 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2967 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2968 "First Star Software");
2970 else if (screen_nr == 1)
2972 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2973 "Special thanks to");
2974 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2975 "Klaus Heinz & Volker Wertich");
2976 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2978 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2979 "\"Emerald Mine\"");
2980 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2982 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2984 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2986 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2989 else if (screen_nr == 2)
2991 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2992 "Special thanks to");
2993 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2994 "Michael Stopp & Philip Jespersen");
2995 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2997 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2999 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3001 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3003 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3005 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3006 "Digital Integration");
3008 else if (screen_nr == 3)
3010 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3011 "Special thanks to");
3012 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3013 "Hiroyuki Imabayashi");
3014 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3016 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3018 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3020 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3022 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3024 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3027 else if (screen_nr == 4)
3029 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3030 "Special thanks to");
3031 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3033 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3035 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3036 "J\xfcrgen Bonhagen");
3037 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3038 "for the continuous creation");
3039 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3040 "of outstanding level sets");
3042 else if (screen_nr == 5)
3044 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3046 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3048 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3049 "for ideas and inspiration by");
3050 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3053 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3055 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3057 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3058 "for ideas and inspiration by");
3059 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3062 else if (screen_nr == 6)
3064 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3066 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3069 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3070 "for the code base used for the");
3071 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3072 "native Emerald Mine engine");
3074 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3075 "for the new Emerald Mine engine");
3078 else if (screen_nr == 7)
3080 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3082 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3084 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3085 "for the initial DOS port");
3087 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3089 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3091 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3092 "for some additional toons");
3094 else if (screen_nr == 8)
3096 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3097 "And not to forget:");
3098 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3100 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3101 "All those who contributed");
3102 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3103 "levels to this game");
3104 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3108 DrawTextSCentered(ybottom, FONT_TEXT_4,
3109 "Press any key or button for next page");
3112 void DrawInfoScreen_Credits()
3114 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3116 FadeMenuSoundsAndMusic();
3118 FadeOut(REDRAW_FIELD);
3120 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3122 FadeIn(REDRAW_FIELD);
3125 void HandleInfoScreen_Credits(int button)
3127 static int screen_nr = 0;
3128 int num_screens = 9;
3130 if (button == MB_MENU_INITIALIZE)
3134 // DrawInfoScreen_CreditsScreen(screen_nr);
3137 if (button == MB_MENU_LEAVE)
3139 PlaySound(SND_MENU_ITEM_SELECTING);
3141 info_mode = INFO_MODE_MAIN;
3146 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3148 if (button != MB_MENU_INITIALIZE)
3150 PlaySound(SND_MENU_ITEM_SELECTING);
3155 if (screen_nr >= num_screens)
3157 FadeMenuSoundsAndMusic();
3159 info_mode = INFO_MODE_MAIN;
3166 FadeSetNextScreen();
3168 if (button != MB_MENU_INITIALIZE)
3169 FadeOut(REDRAW_FIELD);
3171 DrawInfoScreen_CreditsScreen(screen_nr);
3173 if (button != MB_MENU_INITIALIZE)
3174 FadeIn(REDRAW_FIELD);
3178 PlayMenuSoundIfLoop();
3182 void DrawInfoScreen_Program()
3184 int ystart1 = mSY - SY + 100;
3185 int ystart2 = mSY - SY + 150;
3186 int ybottom = mSY - SY + SYSIZE - 20;
3189 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3191 FadeOut(REDRAW_FIELD);
3196 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3198 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3199 "This game is Freeware!");
3200 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3201 "If you like it, send e-mail to:");
3202 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3203 setup.internal.program_email);
3204 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3205 "More information and levels:");
3206 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3207 setup.internal.program_website);
3208 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3209 "If you have created new levels,");
3210 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3211 "send them to me to include them!");
3212 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3215 DrawTextSCentered(ybottom, FONT_TEXT_4,
3216 "Press any key or button for info menu");
3218 FadeIn(REDRAW_FIELD);
3221 void HandleInfoScreen_Program(int button)
3223 if (button == MB_MENU_LEAVE)
3225 PlaySound(SND_MENU_ITEM_SELECTING);
3227 info_mode = INFO_MODE_MAIN;
3232 else if (button == MB_MENU_CHOICE)
3234 PlaySound(SND_MENU_ITEM_SELECTING);
3236 FadeMenuSoundsAndMusic();
3238 info_mode = INFO_MODE_MAIN;
3243 PlayMenuSoundIfLoop();
3247 void DrawInfoScreen_Version()
3249 int font_header = FONT_TEXT_3;
3250 int font_text = FONT_TEXT_2;
3251 int xstep = getFontWidth(font_text);
3252 int ystep = getFontHeight(font_text);
3253 int ystart1 = mSY - SY + 100;
3254 int ystart2 = mSY - SY + 150;
3255 int ybottom = mSY - SY + SYSIZE - 20;
3256 int xstart1 = mSX - SX + 2 * xstep;
3257 int xstart2 = mSX - SX + 18 * xstep;
3258 int xstart3 = mSX - SX + 28 * xstep;
3259 SDL_version sdl_version_compiled;
3260 const SDL_version *sdl_version_linked;
3261 int driver_name_len = 10;
3262 #if defined(TARGET_SDL2)
3263 SDL_version sdl_version_linked_ext;
3264 const char *driver_name = NULL;
3266 char driver_name[driver_name_len];
3269 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3271 FadeOut(REDRAW_FIELD);
3276 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3278 DrawTextF(xstart1, ystart2, font_header, "Name");
3279 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3282 DrawTextF(xstart1, ystart2, font_header, "Version");
3283 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3286 DrawTextF(xstart1, ystart2, font_header, "Platform");
3287 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3290 DrawTextF(xstart1, ystart2, font_header, "Target");
3291 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3294 DrawTextF(xstart1, ystart2, font_header, "Source date");
3295 DrawTextF(xstart2, ystart2, font_text, getSourceDateString());
3297 ystart2 += 3 * ystep;
3298 DrawTextF(xstart1, ystart2, font_header, "Library");
3299 DrawTextF(xstart2, ystart2, font_header, "compiled");
3300 DrawTextF(xstart3, ystart2, font_header, "linked");
3302 SDL_VERSION(&sdl_version_compiled);
3303 #if defined(TARGET_SDL2)
3304 SDL_GetVersion(&sdl_version_linked_ext);
3305 sdl_version_linked = &sdl_version_linked_ext;
3307 sdl_version_linked = SDL_Linked_Version();
3310 ystart2 += 2 * ystep;
3311 DrawTextF(xstart1, ystart2, font_text, "SDL");
3312 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3313 sdl_version_compiled.major,
3314 sdl_version_compiled.minor,
3315 sdl_version_compiled.patch);
3316 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3317 sdl_version_linked->major,
3318 sdl_version_linked->minor,
3319 sdl_version_linked->patch);
3321 SDL_IMAGE_VERSION(&sdl_version_compiled);
3322 sdl_version_linked = IMG_Linked_Version();
3325 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3326 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3327 sdl_version_compiled.major,
3328 sdl_version_compiled.minor,
3329 sdl_version_compiled.patch);
3330 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3331 sdl_version_linked->major,
3332 sdl_version_linked->minor,
3333 sdl_version_linked->patch);
3335 SDL_MIXER_VERSION(&sdl_version_compiled);
3336 sdl_version_linked = Mix_Linked_Version();
3339 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3340 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3341 sdl_version_compiled.major,
3342 sdl_version_compiled.minor,
3343 sdl_version_compiled.patch);
3344 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3345 sdl_version_linked->major,
3346 sdl_version_linked->minor,
3347 sdl_version_linked->patch);
3349 SDL_NET_VERSION(&sdl_version_compiled);
3350 sdl_version_linked = SDLNet_Linked_Version();
3353 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3354 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3355 sdl_version_compiled.major,
3356 sdl_version_compiled.minor,
3357 sdl_version_compiled.patch);
3358 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3359 sdl_version_linked->major,
3360 sdl_version_linked->minor,
3361 sdl_version_linked->patch);
3363 ystart2 += 3 * ystep;
3364 DrawTextF(xstart1, ystart2, font_header, "Driver");
3365 DrawTextF(xstart2, ystart2, font_header, "Requested");
3366 DrawTextF(xstart3, ystart2, font_header, "Used");
3368 #if defined(TARGET_SDL2)
3369 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3371 SDL_VideoDriverName(driver_name, driver_name_len);
3374 ystart2 += 2 * ystep;
3375 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3376 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3377 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3379 #if defined(TARGET_SDL2)
3380 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3382 SDL_AudioDriverName(driver_name, driver_name_len);
3386 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3387 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3388 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3390 DrawTextSCentered(ybottom, FONT_TEXT_4,
3391 "Press any key or button for info menu");
3393 FadeIn(REDRAW_FIELD);
3396 void HandleInfoScreen_Version(int button)
3398 if (button == MB_MENU_LEAVE)
3400 PlaySound(SND_MENU_ITEM_SELECTING);
3402 info_mode = INFO_MODE_MAIN;
3407 else if (button == MB_MENU_CHOICE)
3409 PlaySound(SND_MENU_ITEM_SELECTING);
3411 FadeMenuSoundsAndMusic();
3413 info_mode = INFO_MODE_MAIN;
3418 PlayMenuSoundIfLoop();
3422 void DrawInfoScreen_LevelSet()
3424 struct TitleMessageInfo *tmi = &readme;
3425 char *filename = getLevelSetInfoFilename();
3426 char *title = "Level Set Information:";
3427 int ystart1 = mSY - SY + 100;
3428 int ybottom = mSY - SY + SYSIZE - 20;
3430 if (filename == NULL)
3432 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3437 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3439 FadeOut(REDRAW_FIELD);
3444 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3446 /* if x position set to "-1", automatically determine by playfield width */
3448 tmi->x = SXSIZE / 2;
3450 /* if y position set to "-1", use static default value */
3454 /* if width set to "-1", automatically determine by playfield width */
3455 if (tmi->width == -1)
3456 tmi->width = SXSIZE - 2 * TILEX;
3458 /* if height set to "-1", automatically determine by playfield height */
3459 if (tmi->height == -1)
3460 tmi->height = SYSIZE - 20 - tmi->y - 10;
3462 /* if chars set to "-1", automatically determine by text and font width */
3463 if (tmi->chars == -1)
3464 tmi->chars = tmi->width / getFontWidth(tmi->font);
3466 tmi->width = tmi->chars * getFontWidth(tmi->font);
3468 /* if lines set to "-1", automatically determine by text and font height */
3469 if (tmi->lines == -1)
3470 tmi->lines = tmi->height / getFontHeight(tmi->font);
3472 tmi->height = tmi->lines * getFontHeight(tmi->font);
3474 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3475 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3476 tmi->autowrap, tmi->centered, tmi->parse_comments);
3478 DrawTextSCentered(ybottom, FONT_TEXT_4,
3479 "Press any key or button for info menu");
3481 FadeIn(REDRAW_FIELD);
3484 void HandleInfoScreen_LevelSet(int button)
3486 if (button == MB_MENU_LEAVE)
3488 PlaySound(SND_MENU_ITEM_SELECTING);
3490 info_mode = INFO_MODE_MAIN;
3495 else if (button == MB_MENU_CHOICE)
3497 PlaySound(SND_MENU_ITEM_SELECTING);
3499 FadeMenuSoundsAndMusic();
3501 info_mode = INFO_MODE_MAIN;
3506 PlayMenuSoundIfLoop();
3510 static void DrawInfoScreen()
3512 if (info_mode == INFO_MODE_TITLE)
3513 DrawInfoScreen_TitleScreen();
3514 else if (info_mode == INFO_MODE_ELEMENTS)
3515 DrawInfoScreen_Elements();
3516 else if (info_mode == INFO_MODE_MUSIC)
3517 DrawInfoScreen_Music();
3518 else if (info_mode == INFO_MODE_CREDITS)
3519 DrawInfoScreen_Credits();
3520 else if (info_mode == INFO_MODE_PROGRAM)
3521 DrawInfoScreen_Program();
3522 else if (info_mode == INFO_MODE_VERSION)
3523 DrawInfoScreen_Version();
3524 else if (info_mode == INFO_MODE_LEVELSET)
3525 DrawInfoScreen_LevelSet();
3527 DrawInfoScreen_Main();
3529 if (info_mode != INFO_MODE_MAIN &&
3530 info_mode != INFO_MODE_TITLE &&
3531 info_mode != INFO_MODE_MUSIC)
3532 PlayMenuSoundsAndMusic();
3535 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3537 if (info_mode == INFO_MODE_TITLE)
3538 HandleInfoScreen_TitleScreen(button);
3539 else if (info_mode == INFO_MODE_ELEMENTS)
3540 HandleInfoScreen_Elements(button);
3541 else if (info_mode == INFO_MODE_MUSIC)
3542 HandleInfoScreen_Music(button);
3543 else if (info_mode == INFO_MODE_CREDITS)
3544 HandleInfoScreen_Credits(button);
3545 else if (info_mode == INFO_MODE_PROGRAM)
3546 HandleInfoScreen_Program(button);
3547 else if (info_mode == INFO_MODE_VERSION)
3548 HandleInfoScreen_Version(button);
3549 else if (info_mode == INFO_MODE_LEVELSET)
3550 HandleInfoScreen_LevelSet(button);
3552 HandleInfoScreen_Main(mx, my, dx, dy, button);
3556 /* ========================================================================= */
3557 /* type name functions */
3558 /* ========================================================================= */
3560 void HandleTypeName(int newxpos, Key key)
3562 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3563 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3564 struct TextPosInfo *pos = mci->pos_input;
3565 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3566 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3567 static int xpos = 0;
3568 int font_nr = pos->font;
3569 int font_active_nr = FONT_ACTIVE(font_nr);
3570 int font_width = getFontWidth(font_active_nr);
3571 char key_char = getValidConfigValueChar(getCharFromKey(key));
3572 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3573 boolean is_active = TRUE;
3575 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3579 strcpy(last_player_name, setup.player_name);
3583 StartTextInput(startx, starty, pos->width, pos->height);
3585 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3587 setup.player_name[xpos] = key_char;
3588 setup.player_name[xpos + 1] = 0;
3592 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3596 setup.player_name[xpos] = 0;
3598 else if (key == KSYM_Return && xpos > 0)
3604 SetGameStatus(GAME_MODE_MAIN);
3606 else if (key == KSYM_Escape)
3608 strcpy(setup.player_name, last_player_name);
3612 SetGameStatus(GAME_MODE_MAIN);
3617 pos->width = (strlen(setup.player_name) + 1) * font_width;
3618 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3620 DrawText(startx, starty, setup.player_name, font_active_nr);
3621 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3625 pos->width = strlen(setup.player_name) * font_width;
3626 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3628 DrawText(startx, starty, setup.player_name, font_nr);
3635 /* ========================================================================= */
3636 /* tree menu functions */
3637 /* ========================================================================= */
3639 static void DrawChooseTree(TreeInfo **ti_ptr)
3641 int fade_mask = REDRAW_FIELD;
3643 if (CheckIfGlobalBorderHasChanged())
3644 fade_mask = REDRAW_ALL;
3646 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3648 SetGameStatus(GAME_MODE_MAIN);
3657 FreeScreenGadgets();
3658 CreateScreenGadgets();
3662 /* needed if different viewport properties defined for choosing level (set) */
3663 ChangeViewportPropertiesIfNeeded();
3665 if (game_status == GAME_MODE_LEVELNR)
3666 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3667 else if (game_status == GAME_MODE_LEVELS)
3668 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3672 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3674 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3675 MapScreenTreeGadgets(*ti_ptr);
3677 DrawMaskedBorder(fade_mask);
3682 static void drawChooseTreeList(int first_entry, int num_page_entries,
3686 char *title_string = NULL;
3687 int yoffset_sets = MENU_TITLE1_YPOS;
3688 int yoffset_setup = 16;
3689 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3690 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3692 title_string = ti->infotext;
3694 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3696 clearMenuListArea();
3698 for (i = 0; i < num_page_entries; i++)
3700 TreeInfo *node, *node_first;
3701 int entry_pos = first_entry + i;
3702 int xpos = MENU_SCREEN_START_XPOS;
3703 int ypos = MENU_SCREEN_START_YPOS + i;
3704 int startx = mSX + xpos * 32;
3705 int starty = mSY + ypos * 32;
3706 int font_nr = FONT_TEXT_1;
3707 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3708 int startx_text = startx + font_xoffset;
3709 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3710 int text_size = startx_scrollbar - startx_text;
3711 int max_buffer_len = text_size / getFontWidth(font_nr);
3712 char buffer[max_buffer_len + 1];
3714 node_first = getTreeInfoFirstGroupEntry(ti);
3715 node = getTreeInfoFromPos(node_first, entry_pos);
3717 strncpy(buffer, node->name, max_buffer_len);
3718 buffer[max_buffer_len] = '\0';
3720 DrawText(startx, starty, buffer, font_nr + node->color);
3722 if (node->parent_link)
3723 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3724 else if (node->level_group)
3725 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3727 initCursor(i, IMG_MENU_BUTTON);
3730 redraw_mask |= REDRAW_FIELD;
3733 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3735 TreeInfo *node, *node_first;
3736 int x, last_redraw_mask = redraw_mask;
3737 int ypos = MENU_TITLE2_YPOS;
3738 int font_nr = FONT_TITLE_2;
3740 if (ti->type == TREE_TYPE_LEVEL_NR)
3741 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3743 if (ti->type != TREE_TYPE_LEVEL_DIR)
3746 node_first = getTreeInfoFirstGroupEntry(ti);
3747 node = getTreeInfoFromPos(node_first, entry_pos);
3749 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3751 if (node->parent_link)
3752 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3753 node->node_parent->name);
3754 else if (node->level_group)
3755 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3757 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3758 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3759 node->levels, (node->levels > 1 ? "levels" : "level"),
3762 /* let BackToFront() redraw only what is needed */
3763 redraw_mask = last_redraw_mask;
3764 for (x = 0; x < SCR_FIELDX; x++)
3765 MarkTileDirty(x, 1);
3768 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3771 TreeInfo *ti = *ti_ptr;
3773 int y = ti->cl_cursor;
3774 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3775 int num_entries = numTreeInfoInGroup(ti);
3776 int num_page_entries;
3777 boolean position_set_by_scrollbar = (dx == 999);
3779 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3780 num_page_entries = num_entries;
3782 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3784 if (button == MB_MENU_INITIALIZE)
3786 int num_entries = numTreeInfoInGroup(ti);
3787 int entry_pos = posTreeInfo(ti);
3789 if (ti->cl_first == -1)
3791 /* only on initialization */
3792 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3793 ti->cl_cursor = entry_pos - ti->cl_first;
3795 else if (ti->cl_cursor >= num_page_entries ||
3796 (num_entries > num_page_entries &&
3797 num_entries - ti->cl_first < num_page_entries))
3799 /* only after change of list size (by custom graphic configuration) */
3800 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3801 ti->cl_cursor = entry_pos - ti->cl_first;
3804 if (position_set_by_scrollbar)
3807 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3810 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3811 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3812 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3816 else if (button == MB_MENU_LEAVE)
3820 PlaySound(SND_MENU_ITEM_SELECTING);
3822 if (ti->node_parent)
3824 *ti_ptr = ti->node_parent;
3825 DrawChooseTree(ti_ptr);
3827 else if (game_status == GAME_MODE_SETUP)
3829 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3830 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3831 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3833 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3834 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
3835 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
3836 execSetupGraphics();
3837 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3838 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3839 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3841 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3842 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3843 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3850 if (game_status == GAME_MODE_LEVELNR)
3852 int new_level_nr = atoi(level_number_current->identifier);
3854 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3857 SetGameStatus(GAME_MODE_MAIN);
3865 if (mx || my) /* mouse input */
3867 x = (mx - mSX) / 32;
3868 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3870 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3872 /* move cursor instead of scrolling when already at start/end of list */
3873 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3875 else if (dy == +1 * SCROLL_LINE &&
3876 ti->cl_first + num_page_entries == num_entries)
3879 /* handle scrolling screen one line or page */
3880 if (ti->cl_cursor + dy < 0 ||
3881 ti->cl_cursor + dy > num_page_entries - 1)
3883 boolean redraw = FALSE;
3885 if (ABS(dy) == SCROLL_PAGE)
3886 step = num_page_entries - 1;
3888 if (dy < 0 && ti->cl_first > 0)
3890 /* scroll page/line up */
3892 ti->cl_first -= step;
3893 if (ti->cl_first < 0)
3898 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3900 /* scroll page/line down */
3902 ti->cl_first += step;
3903 if (ti->cl_first + num_page_entries > num_entries)
3904 ti->cl_first = MAX(0, num_entries - num_page_entries);
3911 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3912 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3913 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3915 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3922 /* handle moving cursor one line */
3923 y = ti->cl_cursor + dy;
3928 TreeInfo *node_first, *node_cursor;
3929 int entry_pos = ti->cl_first + y;
3931 node_first = getTreeInfoFirstGroupEntry(ti);
3932 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3934 if (node_cursor->node_group)
3938 PlaySound(SND_MENU_ITEM_SELECTING);
3940 node_cursor->cl_first = ti->cl_first;
3941 node_cursor->cl_cursor = ti->cl_cursor;
3942 *ti_ptr = node_cursor->node_group;
3943 DrawChooseTree(ti_ptr);
3948 else if (dx == -1 && ti->node_parent)
3952 PlaySound(SND_MENU_ITEM_SELECTING);
3954 *ti_ptr = ti->node_parent;
3955 DrawChooseTree(ti_ptr);
3960 if (!anyScrollbarGadgetActive() &&
3961 IN_VIS_MENU(x, y) &&
3962 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3963 y >= 0 && y < num_page_entries)
3967 if (y != ti->cl_cursor)
3969 PlaySound(SND_MENU_ITEM_ACTIVATING);
3971 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3972 drawChooseTreeCursor(y, TRUE);
3973 drawChooseTreeInfo(ti->cl_first + y, ti);
3980 TreeInfo *node_first, *node_cursor;
3981 int entry_pos = ti->cl_first + y;
3983 PlaySound(SND_MENU_ITEM_SELECTING);
3985 node_first = getTreeInfoFirstGroupEntry(ti);
3986 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3988 if (node_cursor->node_group)
3992 node_cursor->cl_first = ti->cl_first;
3993 node_cursor->cl_cursor = ti->cl_cursor;
3994 *ti_ptr = node_cursor->node_group;
3995 DrawChooseTree(ti_ptr);
3997 else if (node_cursor->parent_link)
4001 *ti_ptr = node_cursor->node_parent;
4002 DrawChooseTree(ti_ptr);
4008 node_cursor->cl_first = ti->cl_first;
4009 node_cursor->cl_cursor = ti->cl_cursor;
4010 *ti_ptr = node_cursor;
4012 if (ti->type == TREE_TYPE_LEVEL_DIR)
4014 LoadLevelSetup_SeriesInfo();
4016 SaveLevelSetup_LastSeries();
4017 SaveLevelSetup_SeriesInfo();
4021 if (game_status == GAME_MODE_SETUP)
4023 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4024 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4025 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4027 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4028 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4029 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4030 execSetupGraphics();
4031 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4032 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4033 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4035 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4036 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4037 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4044 if (game_status == GAME_MODE_LEVELNR)
4046 int new_level_nr = atoi(level_number_current->identifier);
4048 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4051 SetGameStatus(GAME_MODE_MAIN);
4060 void DrawChooseLevelSet()
4062 FadeMenuSoundsAndMusic();
4064 DrawChooseTree(&leveldir_current);
4066 PlayMenuSoundsAndMusic();
4069 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4071 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4074 void DrawChooseLevelNr()
4078 FadeMenuSoundsAndMusic();
4080 if (level_number != NULL)
4082 freeTreeInfo(level_number);
4084 level_number = NULL;
4087 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4089 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4090 char identifier[32], name[32];
4093 /* temporarily load level info to get level name */
4094 LoadLevelInfoOnly(i);
4096 ti->node_top = &level_number;
4097 ti->sort_priority = 10000 + value;
4098 ti->color = (level.no_valid_file ? FC_BLUE :
4099 LevelStats_getSolved(i) ? FC_GREEN :
4100 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4102 sprintf(identifier, "%d", value);
4103 sprintf(name, "%03d: %s", value,
4104 (level.no_valid_file ? "(no file)" : level.name));
4106 setString(&ti->identifier, identifier);
4107 setString(&ti->name, name);
4108 setString(&ti->name_sorting, name);
4110 pushTreeInfo(&level_number, ti);
4113 /* sort level number values to start with lowest level number */
4114 sortTreeInfo(&level_number);
4116 /* set current level number to current level number */
4117 level_number_current =
4118 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4120 /* if that also fails, set current level number to first available level */
4121 if (level_number_current == NULL)
4122 level_number_current = level_number;
4124 DrawChooseTree(&level_number_current);
4126 PlayMenuSoundsAndMusic();
4129 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4131 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4134 void DrawHallOfFame(int highlight_position)
4136 int fade_mask = REDRAW_FIELD;
4138 if (CheckIfGlobalBorderHasChanged())
4139 fade_mask = REDRAW_ALL;
4142 FadeMenuSoundsAndMusic();
4144 /* (this is needed when called from GameEnd() after winning a game) */
4145 KeyboardAutoRepeatOn();
4148 /* (this is needed when called from GameEnd() after winning a game) */
4149 SetDrawDeactivationMask(REDRAW_NONE);
4150 SetDrawBackgroundMask(REDRAW_FIELD);
4152 if (highlight_position < 0)
4153 LoadScore(level_nr);
4155 FadeSetEnterScreen();
4159 /* needed if different viewport properties defined for scores */
4160 ChangeViewportPropertiesIfNeeded();
4162 PlayMenuSoundsAndMusic();
4164 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4166 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4168 DrawMaskedBorder(fade_mask);
4173 static void drawHallOfFameList(int first_entry, int highlight_position)
4177 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4180 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4181 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4182 "HighScores of Level %d", level_nr);
4184 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4186 int entry = first_entry + i;
4187 boolean active = (entry == highlight_position);
4188 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4189 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4190 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4191 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4192 int dxoff = getFontDrawOffsetX(font_nr1);
4193 int dx1 = 3 * getFontWidth(font_nr1);
4194 int dx2 = dx1 + getFontWidth(font_nr1);
4195 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4196 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4197 int sy = mSY + 64 + i * 32;
4199 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4200 DrawText(mSX + dx1, sy, ".", font_nr1);
4202 for (j = 0; j < num_dots; j++)
4203 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4205 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4206 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4208 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4211 redraw_mask |= REDRAW_FIELD;
4214 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4216 static int first_entry = 0;
4217 static int highlight_position = 0;
4218 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4220 if (button == MB_MENU_INITIALIZE)
4223 highlight_position = mx;
4224 drawHallOfFameList(first_entry, highlight_position);
4229 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4230 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4234 if (first_entry > 0)
4236 first_entry -= step;
4237 if (first_entry < 0)
4240 drawHallOfFameList(first_entry, highlight_position);
4245 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4247 first_entry += step;
4248 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4249 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4251 drawHallOfFameList(first_entry, highlight_position);
4254 else if (button == MB_MENU_LEAVE)
4256 PlaySound(SND_MENU_ITEM_SELECTING);
4258 FadeSound(SND_BACKGROUND_SCORES);
4260 SetGameStatus(GAME_MODE_MAIN);
4264 else if (button == MB_MENU_CHOICE)
4266 PlaySound(SND_MENU_ITEM_SELECTING);
4268 FadeSound(SND_BACKGROUND_SCORES);
4270 SetGameStatus(GAME_MODE_MAIN);
4275 if (game_status == GAME_MODE_SCORES)
4276 PlayMenuSoundIfLoop();
4280 /* ========================================================================= */
4281 /* setup screen functions */
4282 /* ========================================================================= */
4284 static struct TokenInfo *setup_info;
4285 static int num_setup_info; /* number of setup entries shown on screen */
4286 static int max_setup_info; /* total number of setup entries in list */
4288 static char *window_size_text;
4289 static char *scaling_type_text;
4290 static char *rendering_mode_text;
4291 static char *scroll_delay_text;
4292 static char *snapshot_mode_text;
4293 static char *game_speed_text;
4294 static char *graphics_set_name;
4295 static char *sounds_set_name;
4296 static char *music_set_name;
4297 static char *volume_simple_text;
4298 static char *volume_loops_text;
4299 static char *volume_music_text;
4300 static char *touch_controls_text;
4301 static char *move_distance_text;
4302 static char *drop_distance_text;
4304 static void execSetupMain()
4306 setup_mode = SETUP_MODE_MAIN;
4311 static void execSetupGame_setGameSpeeds()
4313 if (game_speeds == NULL)
4317 for (i = 0; game_speeds_list[i].value != -1; i++)
4319 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4320 char identifier[32], name[32];
4321 int value = game_speeds_list[i].value;
4322 char *text = game_speeds_list[i].text;
4324 ti->node_top = &game_speeds;
4325 ti->sort_priority = 10000 - value;
4327 sprintf(identifier, "%d", value);
4328 sprintf(name, "%s", text);
4330 setString(&ti->identifier, identifier);
4331 setString(&ti->name, name);
4332 setString(&ti->name_sorting, name);
4333 setString(&ti->infotext, "Game Speed");
4335 pushTreeInfo(&game_speeds, ti);
4338 /* sort game speed values to start with slowest game speed */
4339 sortTreeInfo(&game_speeds);
4341 /* set current game speed to configured game speed value */
4342 game_speed_current =
4343 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4345 /* if that fails, set current game speed to reliable default value */
4346 if (game_speed_current == NULL)
4347 game_speed_current =
4348 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4350 /* if that also fails, set current game speed to first available speed */
4351 if (game_speed_current == NULL)
4352 game_speed_current = game_speeds;
4355 setup.game_frame_delay = atoi(game_speed_current->identifier);
4357 /* needed for displaying game speed text instead of identifier */
4358 game_speed_text = game_speed_current->name;
4361 static void execSetupGame_setScrollDelays()
4363 if (scroll_delays == NULL)
4367 for (i = 0; scroll_delays_list[i].value != -1; i++)
4369 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4370 char identifier[32], name[32];
4371 int value = scroll_delays_list[i].value;
4372 char *text = scroll_delays_list[i].text;
4374 ti->node_top = &scroll_delays;
4375 ti->sort_priority = value;
4377 sprintf(identifier, "%d", value);
4378 sprintf(name, "%s", text);
4380 setString(&ti->identifier, identifier);
4381 setString(&ti->name, name);
4382 setString(&ti->name_sorting, name);
4383 setString(&ti->infotext, "Scroll Delay");
4385 pushTreeInfo(&scroll_delays, ti);
4388 /* sort scroll delay values to start with lowest scroll delay value */
4389 sortTreeInfo(&scroll_delays);
4391 /* set current scroll delay value to configured scroll delay value */
4392 scroll_delay_current =
4393 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4395 /* if that fails, set current scroll delay to reliable default value */
4396 if (scroll_delay_current == NULL)
4397 scroll_delay_current =
4398 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4400 /* if that also fails, set current scroll delay to first available value */
4401 if (scroll_delay_current == NULL)
4402 scroll_delay_current = scroll_delays;
4405 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4407 /* needed for displaying scroll delay text instead of identifier */
4408 scroll_delay_text = scroll_delay_current->name;
4411 static void execSetupGame_setSnapshotModes()
4413 if (snapshot_modes == NULL)
4417 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4419 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4420 char identifier[32], name[32];
4421 char *value = snapshot_modes_list[i].value;
4422 char *text = snapshot_modes_list[i].text;
4424 ti->node_top = &snapshot_modes;
4425 ti->sort_priority = i;
4427 sprintf(identifier, "%s", value);
4428 sprintf(name, "%s", text);
4430 setString(&ti->identifier, identifier);
4431 setString(&ti->name, name);
4432 setString(&ti->name_sorting, name);
4433 setString(&ti->infotext, "Snapshot Mode");
4435 pushTreeInfo(&snapshot_modes, ti);
4438 /* sort snapshot mode values to start with lowest snapshot mode value */
4439 sortTreeInfo(&snapshot_modes);
4441 /* set current snapshot mode value to configured snapshot mode value */
4442 snapshot_mode_current =
4443 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4445 /* if that fails, set current snapshot mode to reliable default value */
4446 if (snapshot_mode_current == NULL)
4447 snapshot_mode_current =
4448 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4450 /* if that also fails, set current snapshot mode to first available value */
4451 if (snapshot_mode_current == NULL)
4452 snapshot_mode_current = snapshot_modes;
4455 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4457 /* needed for displaying snapshot mode text instead of identifier */
4458 snapshot_mode_text = snapshot_mode_current->name;
4461 static void execSetupGame()
4463 execSetupGame_setGameSpeeds();
4464 execSetupGame_setScrollDelays();
4465 execSetupGame_setSnapshotModes();
4467 setup_mode = SETUP_MODE_GAME;
4472 static void execSetupChooseGameSpeed()
4474 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4479 static void execSetupChooseScrollDelay()
4481 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4486 static void execSetupChooseSnapshotMode()
4488 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4493 static void execSetupEditor()
4495 setup_mode = SETUP_MODE_EDITOR;
4500 static void execSetupGraphics_setWindowSizes(boolean update_list)
4502 if (window_sizes != NULL && update_list)
4504 freeTreeInfo(window_sizes);
4506 window_sizes = NULL;
4509 if (window_sizes == NULL)
4511 boolean current_window_size_found = FALSE;
4514 for (i = 0; window_sizes_list[i].value != -1; i++)
4516 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4517 char identifier[32], name[32];
4518 int value = window_sizes_list[i].value;
4519 char *text = window_sizes_list[i].text;
4521 ti->node_top = &window_sizes;
4522 ti->sort_priority = value;
4524 sprintf(identifier, "%d", value);
4525 sprintf(name, "%s", text);
4527 setString(&ti->identifier, identifier);
4528 setString(&ti->name, name);
4529 setString(&ti->name_sorting, name);
4530 setString(&ti->infotext, "Window Scaling");
4532 pushTreeInfo(&window_sizes, ti);
4534 if (value == setup.window_scaling_percent)
4535 current_window_size_found = TRUE;
4538 if (!current_window_size_found)
4540 // add entry for non-preset window scaling value
4542 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4543 char identifier[32], name[32];
4544 int value = setup.window_scaling_percent;
4546 ti->node_top = &window_sizes;
4547 ti->sort_priority = value;
4549 sprintf(identifier, "%d", value);
4550 sprintf(name, "%d %% (Current)", value);
4552 setString(&ti->identifier, identifier);
4553 setString(&ti->name, name);
4554 setString(&ti->name_sorting, name);
4555 setString(&ti->infotext, "Window Scaling");
4557 pushTreeInfo(&window_sizes, ti);
4560 /* sort window size values to start with lowest window size value */
4561 sortTreeInfo(&window_sizes);
4563 /* set current window size value to configured window size value */
4564 window_size_current =
4565 getTreeInfoFromIdentifier(window_sizes,
4566 i_to_a(setup.window_scaling_percent));
4568 /* if that fails, set current window size to reliable default value */
4569 if (window_size_current == NULL)
4570 window_size_current =
4571 getTreeInfoFromIdentifier(window_sizes,
4572 i_to_a(STD_WINDOW_SCALING_PERCENT));
4574 /* if that also fails, set current window size to first available value */
4575 if (window_size_current == NULL)
4576 window_size_current = window_sizes;
4579 setup.window_scaling_percent = atoi(window_size_current->identifier);
4581 /* needed for displaying window size text instead of identifier */
4582 window_size_text = window_size_current->name;
4585 static void execSetupGraphics_setScalingTypes()
4587 if (scaling_types == NULL)
4591 for (i = 0; scaling_types_list[i].value != NULL; i++)
4593 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4594 char identifier[32], name[32];
4595 char *value = scaling_types_list[i].value;
4596 char *text = scaling_types_list[i].text;
4598 ti->node_top = &scaling_types;
4599 ti->sort_priority = i;
4601 sprintf(identifier, "%s", value);
4602 sprintf(name, "%s", text);
4604 setString(&ti->identifier, identifier);
4605 setString(&ti->name, name);
4606 setString(&ti->name_sorting, name);
4607 setString(&ti->infotext, "Anti-Aliasing");
4609 pushTreeInfo(&scaling_types, ti);
4612 /* sort scaling type values to start with lowest scaling type value */
4613 sortTreeInfo(&scaling_types);
4615 /* set current scaling type value to configured scaling type value */
4616 scaling_type_current =
4617 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4619 /* if that fails, set current scaling type to reliable default value */
4620 if (scaling_type_current == NULL)
4621 scaling_type_current =
4622 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4624 /* if that also fails, set current scaling type to first available value */
4625 if (scaling_type_current == NULL)
4626 scaling_type_current = scaling_types;
4629 setup.window_scaling_quality = scaling_type_current->identifier;
4631 /* needed for displaying scaling type text instead of identifier */
4632 scaling_type_text = scaling_type_current->name;
4635 static void execSetupGraphics_setRenderingModes()
4637 if (rendering_modes == NULL)
4641 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4643 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4644 char identifier[32], name[32];
4645 char *value = rendering_modes_list[i].value;
4646 char *text = rendering_modes_list[i].text;
4648 ti->node_top = &rendering_modes;
4649 ti->sort_priority = i;
4651 sprintf(identifier, "%s", value);
4652 sprintf(name, "%s", text);
4654 setString(&ti->identifier, identifier);
4655 setString(&ti->name, name);
4656 setString(&ti->name_sorting, name);
4657 setString(&ti->infotext, "Special Rendering");
4659 pushTreeInfo(&rendering_modes, ti);
4662 /* sort rendering mode values to start with lowest rendering mode value */
4663 sortTreeInfo(&rendering_modes);
4665 /* set current rendering mode value to configured rendering mode value */
4666 rendering_mode_current =
4667 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4669 /* if that fails, set current rendering mode to reliable default value */
4670 if (rendering_mode_current == NULL)
4671 rendering_mode_current =
4672 getTreeInfoFromIdentifier(rendering_modes,
4673 STR_SPECIAL_RENDERING_DEFAULT);
4675 /* if that also fails, set current rendering mode to first available one */
4676 if (rendering_mode_current == NULL)
4677 rendering_mode_current = rendering_modes;
4680 setup.screen_rendering_mode = rendering_mode_current->identifier;
4682 /* needed for displaying rendering mode text instead of identifier */
4683 rendering_mode_text = rendering_mode_current->name;
4686 static void execSetupGraphics()
4688 // update "setup.window_scaling_percent" from list selection
4689 // (in this case, window scaling was changed on setup screen)
4690 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4691 execSetupGraphics_setWindowSizes(FALSE);
4693 // update list selection from "setup.window_scaling_percent"
4694 // (window scaling may have changed by resizing the window)
4695 execSetupGraphics_setWindowSizes(TRUE);
4697 execSetupGraphics_setScalingTypes();
4698 execSetupGraphics_setRenderingModes();
4700 setup_mode = SETUP_MODE_GRAPHICS;
4704 #if defined(TARGET_SDL2)
4705 // window scaling may have changed at this point
4706 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4708 // window scaling quality may have changed at this point
4709 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4710 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4712 // screen rendering mode may have changed at this point
4713 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4717 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4718 static void execSetupChooseWindowSize()
4720 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4725 static void execSetupChooseScalingType()
4727 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4732 static void execSetupChooseRenderingMode()
4734 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4740 static void execSetupChooseVolumeSimple()
4742 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4747 static void execSetupChooseVolumeLoops()
4749 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4754 static void execSetupChooseVolumeMusic()
4756 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4761 static void execSetupSound()
4763 if (volumes_simple == NULL)
4765 boolean current_volume_simple_found = FALSE;
4768 for (i = 0; volumes_list[i].value != -1; i++)
4770 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4771 char identifier[32], name[32];
4772 int value = volumes_list[i].value;
4773 char *text = volumes_list[i].text;
4775 ti->node_top = &volumes_simple;
4776 ti->sort_priority = value;
4778 sprintf(identifier, "%d", value);
4779 sprintf(name, "%s", text);
4781 setString(&ti->identifier, identifier);
4782 setString(&ti->name, name);
4783 setString(&ti->name_sorting, name);
4784 setString(&ti->infotext, "Sound Volume");
4786 pushTreeInfo(&volumes_simple, ti);
4788 if (value == setup.volume_simple)
4789 current_volume_simple_found = TRUE;
4792 if (!current_volume_simple_found)
4794 // add entry for non-preset volume value
4796 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4797 char identifier[32], name[32];
4798 int value = setup.volume_simple;
4800 ti->node_top = &volumes_simple;
4801 ti->sort_priority = value;
4803 sprintf(identifier, "%d", value);
4804 sprintf(name, "%d %% (Current)", value);
4806 setString(&ti->identifier, identifier);
4807 setString(&ti->name, name);
4808 setString(&ti->name_sorting, name);
4809 setString(&ti->infotext, "Sound Volume");
4811 pushTreeInfo(&volumes_simple, ti);
4814 /* sort volume values to start with lowest volume value */
4815 sortTreeInfo(&volumes_simple);
4817 /* set current volume value to configured volume value */
4818 volume_simple_current =
4819 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4821 /* if that fails, set current volume to reliable default value */
4822 if (volume_simple_current == NULL)
4823 volume_simple_current =
4824 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4826 /* if that also fails, set current volume to first available value */
4827 if (volume_simple_current == NULL)
4828 volume_simple_current = volumes_simple;
4831 if (volumes_loops == NULL)
4833 boolean current_volume_loops_found = FALSE;
4836 for (i = 0; volumes_list[i].value != -1; i++)
4838 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4839 char identifier[32], name[32];
4840 int value = volumes_list[i].value;
4841 char *text = volumes_list[i].text;
4843 ti->node_top = &volumes_loops;
4844 ti->sort_priority = value;
4846 sprintf(identifier, "%d", value);
4847 sprintf(name, "%s", text);
4849 setString(&ti->identifier, identifier);
4850 setString(&ti->name, name);
4851 setString(&ti->name_sorting, name);
4852 setString(&ti->infotext, "Loops Volume");
4854 pushTreeInfo(&volumes_loops, ti);
4856 if (value == setup.volume_loops)
4857 current_volume_loops_found = TRUE;
4860 if (!current_volume_loops_found)
4862 // add entry for non-preset volume value
4864 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4865 char identifier[32], name[32];
4866 int value = setup.volume_loops;
4868 ti->node_top = &volumes_loops;
4869 ti->sort_priority = value;
4871 sprintf(identifier, "%d", value);
4872 sprintf(name, "%d %% (Current)", value);
4874 setString(&ti->identifier, identifier);
4875 setString(&ti->name, name);
4876 setString(&ti->name_sorting, name);
4877 setString(&ti->infotext, "Loops Volume");
4879 pushTreeInfo(&volumes_loops, ti);
4882 /* sort volume values to start with lowest volume value */
4883 sortTreeInfo(&volumes_loops);
4885 /* set current volume value to configured volume value */
4886 volume_loops_current =
4887 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4889 /* if that fails, set current volume to reliable default value */
4890 if (volume_loops_current == NULL)
4891 volume_loops_current =
4892 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4894 /* if that also fails, set current volume to first available value */
4895 if (volume_loops_current == NULL)
4896 volume_loops_current = volumes_loops;
4899 if (volumes_music == NULL)
4901 boolean current_volume_music_found = FALSE;
4904 for (i = 0; volumes_list[i].value != -1; i++)
4906 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4907 char identifier[32], name[32];
4908 int value = volumes_list[i].value;
4909 char *text = volumes_list[i].text;
4911 ti->node_top = &volumes_music;
4912 ti->sort_priority = value;
4914 sprintf(identifier, "%d", value);
4915 sprintf(name, "%s", text);
4917 setString(&ti->identifier, identifier);
4918 setString(&ti->name, name);
4919 setString(&ti->name_sorting, name);
4920 setString(&ti->infotext, "Music Volume");
4922 pushTreeInfo(&volumes_music, ti);
4924 if (value == setup.volume_music)
4925 current_volume_music_found = TRUE;
4928 if (!current_volume_music_found)
4930 // add entry for non-preset volume value
4932 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4933 char identifier[32], name[32];
4934 int value = setup.volume_music;
4936 ti->node_top = &volumes_music;
4937 ti->sort_priority = value;
4939 sprintf(identifier, "%d", value);
4940 sprintf(name, "%d %% (Current)", value);
4942 setString(&ti->identifier, identifier);
4943 setString(&ti->name, name);
4944 setString(&ti->name_sorting, name);
4945 setString(&ti->infotext, "Music Volume");
4947 pushTreeInfo(&volumes_music, ti);
4950 /* sort volume values to start with lowest volume value */
4951 sortTreeInfo(&volumes_music);
4953 /* set current volume value to configured volume value */
4954 volume_music_current =
4955 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4957 /* if that fails, set current volume to reliable default value */
4958 if (volume_music_current == NULL)
4959 volume_music_current =
4960 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4962 /* if that also fails, set current volume to first available value */
4963 if (volume_music_current == NULL)
4964 volume_music_current = volumes_music;
4967 setup.volume_simple = atoi(volume_simple_current->identifier);
4968 setup.volume_loops = atoi(volume_loops_current->identifier);
4969 setup.volume_music = atoi(volume_music_current->identifier);
4971 /* needed for displaying volume text instead of identifier */
4972 volume_simple_text = volume_simple_current->name;
4973 volume_loops_text = volume_loops_current->name;
4974 volume_music_text = volume_music_current->name;
4976 setup_mode = SETUP_MODE_SOUND;
4981 static void execSetupChooseTouchControls()
4983 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4988 static void execSetupChooseMoveDistance()
4990 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4995 static void execSetupChooseDropDistance()
4997 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5002 static void execSetupTouch()
5004 if (touch_controls == NULL)
5008 for (i = 0; touch_controls_list[i].value != NULL; i++)
5010 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5011 char identifier[32], name[32];
5012 char *value = touch_controls_list[i].value;
5013 char *text = touch_controls_list[i].text;
5015 ti->node_top = &touch_controls;
5016 ti->sort_priority = i;
5018 sprintf(identifier, "%s", value);
5019 sprintf(name, "%s", text);
5021 setString(&ti->identifier, identifier);
5022 setString(&ti->name, name);
5023 setString(&ti->name_sorting, name);
5024 setString(&ti->infotext, "Control Type");
5026 pushTreeInfo(&touch_controls, ti);
5029 /* sort touch control values to start with lowest touch control value */
5030 sortTreeInfo(&touch_controls);
5032 /* set current touch control value to configured touch control value */
5033 touch_control_current =
5034 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5036 /* if that fails, set current touch control to reliable default value */
5037 if (touch_control_current == NULL)
5038 touch_control_current =
5039 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5041 /* if that also fails, set current touch control to first available value */
5042 if (touch_control_current == NULL)
5043 touch_control_current = touch_controls;
5046 if (move_distances == NULL)
5050 for (i = 0; distances_list[i].value != -1; i++)
5052 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5053 char identifier[32], name[32];
5054 int value = distances_list[i].value;
5055 char *text = distances_list[i].text;
5057 ti->node_top = &move_distances;
5058 ti->sort_priority = value;
5060 sprintf(identifier, "%d", value);
5061 sprintf(name, "%s", text);
5063 setString(&ti->identifier, identifier);
5064 setString(&ti->name, name);
5065 setString(&ti->name_sorting, name);
5066 setString(&ti->infotext, "Move Distance");
5068 pushTreeInfo(&move_distances, ti);
5071 /* sort distance values to start with lowest distance value */
5072 sortTreeInfo(&move_distances);
5074 /* set current distance value to configured distance value */
5075 move_distance_current =
5076 getTreeInfoFromIdentifier(move_distances,
5077 i_to_a(setup.touch.move_distance));
5079 /* if that fails, set current distance to reliable default value */
5080 if (move_distance_current == NULL)
5081 move_distance_current =
5082 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5084 /* if that also fails, set current distance to first available value */
5085 if (move_distance_current == NULL)
5086 move_distance_current = move_distances;
5089 if (drop_distances == NULL)
5093 for (i = 0; distances_list[i].value != -1; i++)
5095 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5096 char identifier[32], name[32];
5097 int value = distances_list[i].value;
5098 char *text = distances_list[i].text;
5100 ti->node_top = &drop_distances;
5101 ti->sort_priority = value;
5103 sprintf(identifier, "%d", value);
5104 sprintf(name, "%s", text);
5106 setString(&ti->identifier, identifier);
5107 setString(&ti->name, name);
5108 setString(&ti->name_sorting, name);
5109 setString(&ti->infotext, "Drop Distance");
5111 pushTreeInfo(&drop_distances, ti);
5114 /* sort distance values to start with lowest distance value */
5115 sortTreeInfo(&drop_distances);
5117 /* set current distance value to configured distance value */
5118 drop_distance_current =
5119 getTreeInfoFromIdentifier(drop_distances,
5120 i_to_a(setup.touch.drop_distance));
5122 /* if that fails, set current distance to reliable default value */
5123 if (drop_distance_current == NULL)
5124 drop_distance_current =
5125 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5127 /* if that also fails, set current distance to first available value */
5128 if (drop_distance_current == NULL)
5129 drop_distance_current = drop_distances;
5132 setup.touch.control_type = touch_control_current->identifier;
5133 setup.touch.move_distance = atoi(move_distance_current->identifier);
5134 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5136 /* needed for displaying volume text instead of identifier */
5137 touch_controls_text = touch_control_current->name;
5138 move_distance_text = move_distance_current->name;
5139 drop_distance_text = drop_distance_current->name;
5141 setup_mode = SETUP_MODE_TOUCH;
5146 static void execSetupArtwork()
5149 printf("::: '%s', '%s', '%s'\n",
5150 artwork.gfx_current->subdir,
5151 artwork.gfx_current->fullpath,
5152 artwork.gfx_current->basepath);
5155 setup.graphics_set = artwork.gfx_current->identifier;
5156 setup.sounds_set = artwork.snd_current->identifier;
5157 setup.music_set = artwork.mus_current->identifier;
5159 /* needed if last screen (setup choice) changed graphics, sounds or music */
5160 ReloadCustomArtwork(0);
5162 /* needed for displaying artwork name instead of artwork identifier */
5163 graphics_set_name = artwork.gfx_current->name;
5164 sounds_set_name = artwork.snd_current->name;
5165 music_set_name = artwork.mus_current->name;
5167 setup_mode = SETUP_MODE_ARTWORK;
5172 static void execSetupChooseGraphics()
5174 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5179 static void execSetupChooseSounds()
5181 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5186 static void execSetupChooseMusic()
5188 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5193 #if !defined(PLATFORM_ANDROID)
5194 static void execSetupInput()
5196 setup_mode = SETUP_MODE_INPUT;
5202 static void execSetupShortcuts()
5204 setup_mode = SETUP_MODE_SHORTCUTS;
5209 static void execSetupShortcuts1()
5211 setup_mode = SETUP_MODE_SHORTCUTS_1;
5216 static void execSetupShortcuts2()
5218 setup_mode = SETUP_MODE_SHORTCUTS_2;
5223 static void execSetupShortcuts3()
5225 setup_mode = SETUP_MODE_SHORTCUTS_3;
5230 static void execSetupShortcuts4()
5232 setup_mode = SETUP_MODE_SHORTCUTS_4;
5237 static void execSetupShortcuts5()
5239 setup_mode = SETUP_MODE_SHORTCUTS_5;
5244 static void execExitSetup()
5246 SetGameStatus(GAME_MODE_MAIN);
5251 static void execSaveAndExitSetup()
5257 static struct TokenInfo setup_info_main[] =
5259 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5260 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5261 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5262 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5263 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5264 #if !defined(PLATFORM_ANDROID)
5265 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5266 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5268 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5270 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5271 { TYPE_EMPTY, NULL, "" },
5272 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5273 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5278 static struct TokenInfo setup_info_game[] =
5280 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5281 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5282 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5283 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5284 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5285 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5286 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5287 { TYPE_STRING, &game_speed_text, "" },
5289 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5290 { TYPE_STRING, &scroll_delay_text, "" },
5292 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5293 { TYPE_STRING, &snapshot_mode_text, "" },
5294 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5295 { TYPE_EMPTY, NULL, "" },
5296 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5301 static struct TokenInfo setup_info_editor[] =
5304 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5305 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5306 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5307 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5308 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5309 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5310 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5311 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5313 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5314 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5315 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5317 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5319 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5320 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5321 { TYPE_EMPTY, NULL, "" },
5323 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5324 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5325 { TYPE_EMPTY, NULL, "" },
5327 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5328 { TYPE_EMPTY, NULL, "" },
5329 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5334 static struct TokenInfo setup_info_graphics[] =
5336 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5337 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5338 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5339 { TYPE_STRING, &window_size_text, "" },
5340 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5341 { TYPE_STRING, &scaling_type_text, "" },
5342 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5343 { TYPE_STRING, &rendering_mode_text, "" },
5346 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5347 { TYPE_STRING, &scroll_delay_text, "" },
5349 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5350 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5351 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5352 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5353 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5354 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5355 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5356 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5357 { TYPE_EMPTY, NULL, "" },
5358 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5363 static struct TokenInfo setup_info_sound[] =
5365 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5366 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5367 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5368 { TYPE_EMPTY, NULL, "" },
5369 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5370 { TYPE_STRING, &volume_simple_text, "" },
5371 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5372 { TYPE_STRING, &volume_loops_text, "" },
5373 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5374 { TYPE_STRING, &volume_music_text, "" },
5375 { TYPE_EMPTY, NULL, "" },
5376 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5381 static struct TokenInfo setup_info_artwork[] =
5383 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5384 { TYPE_STRING, &graphics_set_name, "" },
5385 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5386 { TYPE_STRING, &sounds_set_name, "" },
5387 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5388 { TYPE_STRING, &music_set_name, "" },
5389 { TYPE_EMPTY, NULL, "" },
5390 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5391 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5392 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5393 { TYPE_EMPTY, NULL, "" },
5394 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5399 static struct TokenInfo setup_info_input[] =
5401 { TYPE_SWITCH, NULL, "Player:" },
5402 { TYPE_SWITCH, NULL, "Device:" },
5403 { TYPE_ENTER_MENU, NULL, "" },
5404 { TYPE_EMPTY, NULL, "" },
5405 { TYPE_EMPTY, NULL, "" },
5406 { TYPE_EMPTY, NULL, "" },
5407 { TYPE_EMPTY, NULL, "" },
5408 { TYPE_EMPTY, NULL, "" },
5409 { TYPE_EMPTY, NULL, "" },
5410 { TYPE_EMPTY, NULL, "" },
5411 { TYPE_EMPTY, NULL, "" },
5412 { TYPE_EMPTY, NULL, "" },
5413 { TYPE_EMPTY, NULL, "" },
5414 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5419 static struct TokenInfo setup_info_touch[] =
5421 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5422 { TYPE_STRING, &touch_controls_text, "" },
5423 { TYPE_EMPTY, NULL, "" },
5424 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5429 static struct TokenInfo setup_info_touch_wipe_gestures[] =
5431 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5432 { TYPE_STRING, &touch_controls_text, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5435 { TYPE_STRING, &move_distance_text, "" },
5436 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5437 { TYPE_STRING, &drop_distance_text, "" },
5438 { TYPE_EMPTY, NULL, "" },
5439 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5444 static struct TokenInfo setup_info_shortcuts[] =
5446 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5447 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5448 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5449 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5450 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5451 { TYPE_EMPTY, NULL, "" },
5452 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5457 static struct TokenInfo setup_info_shortcuts_1[] =
5459 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5460 { TYPE_KEY, &setup.shortcut.save_game, "" },
5461 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5462 { TYPE_KEY, &setup.shortcut.load_game, "" },
5463 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5464 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5465 { TYPE_EMPTY, NULL, "" },
5466 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5467 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5468 { TYPE_EMPTY, NULL, "" },
5469 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5474 static struct TokenInfo setup_info_shortcuts_2[] =
5476 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5477 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5478 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5479 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5480 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5481 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5482 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5483 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5484 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5485 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5486 { TYPE_EMPTY, NULL, "" },
5487 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5492 static struct TokenInfo setup_info_shortcuts_3[] =
5494 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5495 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5496 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5497 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5498 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5499 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5500 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5501 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5502 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5503 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5504 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5505 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5506 { TYPE_EMPTY, NULL, "" },
5507 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5512 static struct TokenInfo setup_info_shortcuts_4[] =
5514 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5515 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5516 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5517 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5518 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5519 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5520 { TYPE_EMPTY, NULL, "" },
5521 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5526 static struct TokenInfo setup_info_shortcuts_5[] =
5528 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5529 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5530 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5531 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5532 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5533 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5534 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5535 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5536 { TYPE_EMPTY, NULL, "" },
5537 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5542 static Key getSetupKey()
5544 Key key = KSYM_UNDEFINED;
5545 boolean got_key_event = FALSE;
5547 while (!got_key_event)
5549 if (PendingEvent()) /* got event */
5557 case EVENT_KEYPRESS:
5559 key = GetEventKey((KeyEvent *)&event, TRUE);
5561 /* press 'Escape' or 'Enter' to keep the existing key binding */
5562 if (key == KSYM_Escape || key == KSYM_Return)
5563 key = KSYM_UNDEFINED; /* keep old value */
5565 got_key_event = TRUE;
5569 case EVENT_KEYRELEASE:
5570 key_joystick_mapping = 0;
5574 HandleOtherEvents(&event);
5585 static int getSetupValueFont(int type, void *value)
5587 if (type & TYPE_KEY)
5588 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5589 else if (type & TYPE_STRING)
5590 return FONT_VALUE_2;
5591 else if (type & TYPE_ECS_AGA)
5592 return FONT_VALUE_1;
5593 else if (type & TYPE_BOOLEAN_STYLE)
5594 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5595 else if (type & TYPE_YES_NO_AUTO)
5596 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5597 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5599 return FONT_VALUE_1;
5602 static int getSetupValueFontNarrow(int type, int font_nr)
5604 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5605 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5606 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5610 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5612 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5613 struct TokenInfo *si = &setup_info[si_pos];
5614 boolean font_draw_xoffset_modified = FALSE;
5615 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5616 int font_draw_xoffset_old = -1;
5617 int xoffset = (scrollbar_needed ? -1 : 0);
5618 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5619 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5620 int xpos = menu_screen_value_xpos;
5621 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5622 int startx = mSX + xpos * 32;
5623 int starty = mSY + ypos * 32;
5624 int font_nr, font_nr_default, font_width_default;
5625 int type = si->type;
5626 void *value = si->value;
5627 char *value_string = getSetupValue(type, value);
5630 if (value_string == NULL)
5633 if (type & TYPE_KEY)
5635 xpos = MENU_SCREEN_START_XPOS;
5637 if (type & TYPE_QUERY)
5638 value_string = "<press key>";
5640 else if (type & TYPE_STRING)
5642 int max_value_len = (SCR_FIELDX - 2) * 2;
5644 xpos = MENU_SCREEN_START_XPOS;
5646 if (strlen(value_string) > max_value_len)
5647 value_string[max_value_len] = '\0';
5649 else if (type & TYPE_YES_NO_AUTO)
5651 xpos = menu_screen_value_xpos - 1;
5654 startx = mSX + xpos * 32;
5655 starty = mSY + ypos * 32;
5656 font_nr_default = getSetupValueFont(type, value);
5657 font_width_default = getFontWidth(font_nr_default);
5659 font_nr = font_nr_default;
5661 // special check if right-side setup values moved left due to scrollbar
5662 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5664 int max_menu_text_length = 26; // maximum text length for classic menu
5665 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5666 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5667 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5668 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5669 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5671 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5674 startx = mSX + xpos * 32;
5676 font_nr = getSetupValueFontNarrow(type, font_nr);
5680 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5681 if (setup_mode != SETUP_MODE_INPUT)
5683 int max_menu_text_length_big = (menu_screen_value_xpos -
5684 MENU_SCREEN_START_XPOS);
5685 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5686 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5687 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5688 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5689 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5690 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5691 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5692 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5693 boolean correct_font_draw_xoffset = FALSE;
5695 if (xpos == MENU_SCREEN_START_XPOS &&
5696 startx + font1_xoffset < text_startx + text_font_xoffset)
5697 correct_font_draw_xoffset = TRUE;
5699 if (xpos == menu_screen_value_xpos &&
5700 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5701 correct_font_draw_xoffset = TRUE;
5703 /* check if setup value would overlap with setup text when printed */
5704 /* (this can happen for extreme/wrong values for font draw offset) */
5705 if (correct_font_draw_xoffset)
5707 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5708 font_draw_xoffset_modified = TRUE;
5710 if (type & TYPE_KEY)
5711 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5712 else if (!(type & TYPE_STRING))
5713 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5714 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5718 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5719 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
5721 DrawText(startx, starty, value_string, font_nr);
5723 if (font_draw_xoffset_modified)
5724 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5727 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5729 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5730 struct TokenInfo *si = &setup_info[si_pos];
5732 if (si->type & TYPE_BOOLEAN_STYLE)
5734 *(boolean *)si->value ^= TRUE;
5736 else if (si->type & TYPE_YES_NO_AUTO)
5740 (*(int *)si->value == AUTO ? TRUE :
5741 *(int *)si->value == TRUE ? FALSE : AUTO) :
5742 (*(int *)si->value == TRUE ? AUTO :
5743 *(int *)si->value == AUTO ? FALSE : TRUE));
5745 else if (si->type & TYPE_KEY)
5749 si->type |= TYPE_QUERY;
5750 drawSetupValue(screen_pos, setup_info_pos_raw);
5751 si->type &= ~TYPE_QUERY;
5753 key = getSetupKey();
5754 if (key != KSYM_UNDEFINED)
5755 *(Key *)si->value = key;
5758 drawSetupValue(screen_pos, setup_info_pos_raw);
5760 // fullscreen state may have changed at this point
5761 if (si->value == &setup.fullscreen)
5762 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5765 static void DrawSetupScreen_Generic()
5767 int fade_mask = REDRAW_FIELD;
5768 boolean redraw_all = FALSE;
5769 char *title_string = NULL;
5772 if (CheckIfGlobalBorderHasChanged())
5773 fade_mask = REDRAW_ALL;
5776 FadeMenuSoundsAndMusic();
5778 FreeScreenGadgets();
5779 CreateScreenGadgets();
5781 if (redraw_mask & REDRAW_ALL)
5786 /* needed if different viewport properties defined for setup screen */
5787 ChangeViewportPropertiesIfNeeded();
5789 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5793 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5795 if (setup_mode == SETUP_MODE_MAIN)
5797 setup_info = setup_info_main;
5798 title_string = "Setup";
5800 else if (setup_mode == SETUP_MODE_GAME)
5802 setup_info = setup_info_game;
5803 title_string = "Setup Game";
5805 else if (setup_mode == SETUP_MODE_EDITOR)
5807 setup_info = setup_info_editor;
5808 title_string = "Setup Editor";
5810 else if (setup_mode == SETUP_MODE_GRAPHICS)
5812 setup_info = setup_info_graphics;
5813 title_string = "Setup Graphics";
5815 else if (setup_mode == SETUP_MODE_SOUND)
5817 setup_info = setup_info_sound;
5818 title_string = "Setup Sound";
5820 else if (setup_mode == SETUP_MODE_ARTWORK)
5822 setup_info = setup_info_artwork;
5823 title_string = "Custom Artwork";
5825 else if (setup_mode == SETUP_MODE_TOUCH)
5827 setup_info = setup_info_touch;
5828 title_string = "Setup Touch Ctrls";
5830 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
5831 setup_info = setup_info_touch_wipe_gestures;
5833 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5835 setup_info = setup_info_shortcuts;
5836 title_string = "Setup Shortcuts";
5838 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5840 setup_info = setup_info_shortcuts_1;
5841 title_string = "Setup Shortcuts";
5843 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5845 setup_info = setup_info_shortcuts_2;
5846 title_string = "Setup Shortcuts";
5848 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5850 setup_info = setup_info_shortcuts_3;
5851 title_string = "Setup Shortcuts";
5853 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5855 setup_info = setup_info_shortcuts_4;
5856 title_string = "Setup Shortcuts";
5858 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5860 setup_info = setup_info_shortcuts_5;
5861 title_string = "Setup Shortcuts";
5864 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5866 // determine maximal number of setup entries that can be displayed on screen
5868 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5871 // determine maximal number of setup entries available for this setup screen
5873 for (i = 0; setup_info[i].type != 0; i++)
5876 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5878 MapScreenGadgets(max_setup_info);
5881 redraw_mask = fade_mask = REDRAW_ALL;
5883 DrawMaskedBorder(fade_mask);
5888 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5890 menu_info = setup_info;
5892 HandleMenuScreen(mx, my, dx, dy, button,
5893 setup_mode, num_setup_info, max_setup_info);
5896 void DrawSetupScreen_Input()
5900 FadeOut(REDRAW_FIELD);
5904 setup_info = setup_info_input;
5906 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5908 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5909 "Joysticks deactivated on this screen");
5911 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5913 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5914 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5915 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5916 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5917 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5918 initCursor(i, IMG_MENU_BUTTON);
5920 DrawCursorAndText_Setup(i, -1, FALSE);
5923 /* create gadgets for setup input menu screen */
5924 FreeScreenGadgets();
5925 CreateScreenGadgets();
5927 /* map gadgets for setup input menu screen */
5928 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5930 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5932 FadeIn(REDRAW_FIELD);
5935 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5937 if (device_name == NULL)
5940 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5943 if (strlen(device_name) > 1)
5945 char c1 = device_name[strlen(device_name) - 1];
5946 char c2 = device_name[strlen(device_name) - 2];
5948 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5949 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5952 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5953 strlen(device_name));
5956 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5959 static struct SetupKeyboardInfo custom_key;
5966 { &custom_key.left, "Joystick Left" },
5967 { &custom_key.right, "Joystick Right" },
5968 { &custom_key.up, "Joystick Up" },
5969 { &custom_key.down, "Joystick Down" },
5970 { &custom_key.snap, "Button 1" },
5971 { &custom_key.drop, "Button 2" }
5973 static char *joystick_name[MAX_PLAYERS] =
5980 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5984 custom_key = setup.input[player_nr].key;
5986 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5987 FONT_INPUT_1_ACTIVE);
5989 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5991 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5992 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5994 if (setup.input[player_nr].use_joystick)
5996 char *device_name = setup.input[player_nr].joy.device_name;
5997 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5998 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6000 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6001 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6005 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6006 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6009 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6011 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6012 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6013 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6014 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6016 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6017 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6018 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6019 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6020 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6021 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6023 for (i = 0; i < 6; i++)
6025 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6027 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6029 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6030 (setup.input[player_nr].use_joystick ?
6032 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6036 static int input_player_nr = 0;
6038 void HandleSetupScreen_Input_Player(int step, int direction)
6040 int old_player_nr = input_player_nr;
6043 new_player_nr = old_player_nr + step * direction;
6044 if (new_player_nr < 0)
6046 if (new_player_nr > MAX_PLAYERS - 1)
6047 new_player_nr = MAX_PLAYERS - 1;
6049 if (new_player_nr != old_player_nr)
6051 input_player_nr = new_player_nr;
6053 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6057 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6059 static int choice = 0;
6062 int pos_start = SETUPINPUT_SCREEN_POS_START;
6063 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6064 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6065 int pos_end = SETUPINPUT_SCREEN_POS_END;
6067 if (button == MB_MENU_INITIALIZE)
6069 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6071 DrawCursorAndText_Setup(choice, -1, TRUE);
6075 else if (button == MB_MENU_LEAVE)
6077 setup_mode = SETUP_MODE_MAIN;
6084 if (mx || my) /* mouse input */
6086 x = (mx - mSX) / 32;
6087 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6089 else if (dx || dy) /* keyboard input */
6091 if (dx && choice == 0)
6092 x = (dx < 0 ? 10 : 12);
6093 else if ((dx && choice == 1) ||
6094 (dx == +1 && choice == 2) ||
6095 (dx == -1 && choice == pos_end))
6096 button = MB_MENU_CHOICE;
6100 if (y >= pos_empty1 && y <= pos_empty2)
6101 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6104 if (y == 0 && dx != 0 && button)
6106 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6108 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6109 y >= pos_start && y <= pos_end &&
6110 !(y >= pos_empty1 && y <= pos_empty2))
6116 DrawCursorAndText_Setup(choice, -1, FALSE);
6117 DrawCursorAndText_Setup(y, -1, TRUE);
6119 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6128 char *device_name = setup.input[input_player_nr].joy.device_name;
6130 if (!setup.input[input_player_nr].use_joystick)
6132 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6134 setJoystickDeviceToNr(device_name, new_device_nr);
6135 setup.input[input_player_nr].use_joystick = TRUE;
6139 int device_nr = getJoystickNrFromDeviceName(device_name);
6140 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6142 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6143 setup.input[input_player_nr].use_joystick = FALSE;
6145 setJoystickDeviceToNr(device_name, new_device_nr);
6148 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6152 if (setup.input[input_player_nr].use_joystick)
6155 CalibrateJoystick(input_player_nr);
6158 CustomizeKeyboard(input_player_nr);
6160 else if (y == pos_end)
6166 setup_mode = SETUP_MODE_MAIN;
6173 void CustomizeKeyboard(int player_nr)
6177 boolean finished = FALSE;
6178 static struct SetupKeyboardInfo custom_key;
6183 } customize_step[] =
6185 { &custom_key.left, "Move Left" },
6186 { &custom_key.right, "Move Right" },
6187 { &custom_key.up, "Move Up" },
6188 { &custom_key.down, "Move Down" },
6189 { &custom_key.snap, "Snap Field" },
6190 { &custom_key.drop, "Drop Element" }
6193 /* read existing key bindings from player setup */
6194 custom_key = setup.input[player_nr].key;
6197 FadeOut(REDRAW_FIELD);
6201 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6204 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6205 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6206 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6207 "Key:", FONT_INPUT_1_ACTIVE);
6208 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6209 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6211 FadeIn(REDRAW_FIELD);
6215 if (PendingEvent()) /* got event */
6223 case EVENT_KEYPRESS:
6225 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6227 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6229 if (key == KSYM_Escape)
6230 FadeSkipNextFadeIn();
6236 /* all keys configured -- wait for "Escape" or "Return" key */
6240 /* press 'Enter' to keep the existing key binding */
6241 if (key == KSYM_Return)
6242 key = *customize_step[step_nr].key;
6244 /* check if key already used */
6245 for (i = 0; i < step_nr; i++)
6246 if (*customize_step[i].key == key)
6251 /* got new key binding */
6252 *customize_step[step_nr].key = key;
6253 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6255 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6256 getKeyNameFromKey(key), FONT_VALUE_1);
6259 /* un-highlight last query */
6260 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6261 customize_step[step_nr - 1].text, FONT_MENU_1);
6262 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6263 "Key:", FONT_MENU_1);
6265 /* press 'Enter' to leave */
6268 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6269 "Press Enter", FONT_TITLE_1);
6273 /* query next key binding */
6274 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6275 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6276 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6277 "Key:", FONT_INPUT_1_ACTIVE);
6278 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6279 getKeyNameFromKey(*customize_step[step_nr].key),
6284 case EVENT_KEYRELEASE:
6285 key_joystick_mapping = 0;
6289 HandleOtherEvents(&event);
6297 /* write new key bindings back to player setup */
6298 setup.input[player_nr].key = custom_key;
6300 DrawSetupScreen_Input();
6303 static boolean CalibrateJoystickMain(int player_nr)
6305 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6306 int new_joystick_xright = JOYSTICK_XMIDDLE;
6307 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6308 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6309 int new_joystick_xmiddle, new_joystick_ymiddle;
6311 int joystick_fd = joystick.fd[player_nr];
6312 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6313 boolean check[3][3];
6314 int check_remaining = 3 * 3;
6319 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6322 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6326 FadeOut(REDRAW_FIELD);
6330 for (y = 0; y < 3; y++)
6332 for (x = 0; x < 3; x++)
6334 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6335 check[x][y] = FALSE;
6339 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6340 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6341 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6342 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6343 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6344 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6345 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6347 joy_value = Joystick(player_nr);
6348 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6349 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6351 /* eventually uncalibrated center position (joystick could be uncentered) */
6352 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6355 new_joystick_xmiddle = joy_x;
6356 new_joystick_ymiddle = joy_y;
6358 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6360 FadeIn(REDRAW_FIELD);
6362 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6366 if (PendingEvent()) /* got event */
6374 case EVENT_KEYPRESS:
6375 switch (GetEventKey((KeyEvent *)&event, TRUE))
6378 if (check_remaining == 0)
6383 FadeSkipNextFadeIn();
6392 case EVENT_KEYRELEASE:
6393 key_joystick_mapping = 0;
6397 HandleOtherEvents(&event);
6402 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6405 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6406 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6407 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6408 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6410 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6411 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6412 setup.input[player_nr].joy.xright = new_joystick_xright;
6413 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6414 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6415 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6417 CheckJoystickData();
6419 joy_value = Joystick(player_nr);
6421 if (joy_value & JOY_BUTTON && check_remaining == 0)
6424 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6425 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6427 if (x != last_x || y != last_y)
6429 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6430 IMG_MENU_CALIBRATE_YELLOW, 0);
6431 DrawFixedGraphic(xpos + x, ypos + y,
6432 IMG_MENU_CALIBRATE_RED, 0);
6437 if (check_remaining > 0 && !check[x+1][y+1])
6439 check[x+1][y+1] = TRUE;
6447 /* calibrated center position (joystick should now be centered) */
6448 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6451 new_joystick_xmiddle = joy_x;
6452 new_joystick_ymiddle = joy_y;
6454 /* wait until the last pressed button was released */
6455 while (Joystick(player_nr) & JOY_BUTTON)
6457 if (PendingEvent()) /* got event */
6462 HandleOtherEvents(&event);
6471 void CalibrateJoystick(int player_nr)
6473 if (!CalibrateJoystickMain(player_nr))
6475 char *device_name = setup.input[player_nr].joy.device_name;
6476 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6477 int xpos = mSX - SX;
6478 int ypos = mSY - SY;
6482 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6483 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6486 Delay(2000); /* show error message for a short time */
6491 DrawSetupScreen_Input();
6494 void DrawSetupScreen()
6496 DeactivateJoystick();
6498 if (setup_mode == SETUP_MODE_INPUT)
6499 DrawSetupScreen_Input();
6500 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6501 DrawChooseTree(&game_speed_current);
6502 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6503 DrawChooseTree(&scroll_delay_current);
6504 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6505 DrawChooseTree(&snapshot_mode_current);
6506 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6507 DrawChooseTree(&window_size_current);
6508 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6509 DrawChooseTree(&scaling_type_current);
6510 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6511 DrawChooseTree(&rendering_mode_current);
6512 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6513 DrawChooseTree(&artwork.gfx_current);
6514 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6515 DrawChooseTree(&artwork.snd_current);
6516 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6517 DrawChooseTree(&artwork.mus_current);
6518 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6519 DrawChooseTree(&volume_simple_current);
6520 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6521 DrawChooseTree(&volume_loops_current);
6522 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6523 DrawChooseTree(&volume_music_current);
6524 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6525 DrawChooseTree(&touch_control_current);
6526 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6527 DrawChooseTree(&move_distance_current);
6528 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6529 DrawChooseTree(&drop_distance_current);
6531 DrawSetupScreen_Generic();
6533 PlayMenuSoundsAndMusic();
6536 void RedrawSetupScreenAfterFullscreenToggle()
6538 if (setup_mode == SETUP_MODE_GRAPHICS ||
6539 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6541 // update list selection from "setup.window_scaling_percent"
6542 execSetupGraphics_setWindowSizes(TRUE);
6548 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6550 if (setup_mode == SETUP_MODE_INPUT)
6551 HandleSetupScreen_Input(mx, my, dx, dy, button);
6552 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6553 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6554 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6555 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6556 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6557 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6558 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6559 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6560 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6561 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6562 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6563 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
6564 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6565 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6566 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6567 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6568 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6569 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6570 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6571 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6573 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6575 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6577 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6579 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6581 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6583 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6586 void HandleGameActions()
6588 if (game_status != GAME_MODE_PLAYING)
6591 GameActions(); /* main game loop */
6593 if (tape.auto_play && !tape.playing)
6594 AutoPlayTape(); /* continue automatically playing next tape */
6598 /* ---------- new screen button stuff -------------------------------------- */
6600 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6604 case SCREEN_CTRL_ID_PREV_LEVEL:
6605 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6606 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6609 case SCREEN_CTRL_ID_NEXT_LEVEL:
6610 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6611 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6614 case SCREEN_CTRL_ID_PREV_PLAYER:
6615 *x = mSX + TILEX * 10;
6616 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6619 case SCREEN_CTRL_ID_NEXT_PLAYER:
6620 *x = mSX + TILEX * 12;
6621 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6625 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6631 int gfx_unpressed, gfx_pressed;
6632 void (*get_gadget_position)(int *, int *, int);
6636 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6639 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6640 getScreenMenuButtonPos,
6641 SCREEN_CTRL_ID_PREV_LEVEL,
6646 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6647 getScreenMenuButtonPos,
6648 SCREEN_CTRL_ID_NEXT_LEVEL,
6653 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6654 getScreenMenuButtonPos,
6655 SCREEN_CTRL_ID_PREV_PLAYER,
6660 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6661 getScreenMenuButtonPos,
6662 SCREEN_CTRL_ID_NEXT_PLAYER,
6670 int gfx_unpressed, gfx_pressed;
6674 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6677 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6678 -1, -1, /* these values are not constant, but can change at runtime */
6679 SCREEN_CTRL_ID_SCROLL_UP,
6683 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6684 -1, -1, /* these values are not constant, but can change at runtime */
6685 SCREEN_CTRL_ID_SCROLL_DOWN,
6692 int gfx_unpressed, gfx_pressed;
6698 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6701 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6702 -1, -1, /* these values are not constant, but can change at runtime */
6703 -1, -1, /* these values are not constant, but can change at runtime */
6704 GD_TYPE_SCROLLBAR_VERTICAL,
6705 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6706 "scroll level series vertically"
6710 static void CreateScreenMenubuttons()
6712 struct GadgetInfo *gi;
6713 unsigned int event_mask;
6716 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6718 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6719 int gfx_unpressed, gfx_pressed;
6720 int x, y, width, height;
6721 int gd_x1, gd_x2, gd_y1, gd_y2;
6722 int id = menubutton_info[i].gadget_id;
6724 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6726 menubutton_info[i].get_gadget_position(&x, &y, id);
6728 width = SC_MENUBUTTON_XSIZE;
6729 height = SC_MENUBUTTON_YSIZE;
6731 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6732 gfx_pressed = menubutton_info[i].gfx_pressed;
6733 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6734 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6735 gd_x1 = graphic_info[gfx_unpressed].src_x;
6736 gd_y1 = graphic_info[gfx_unpressed].src_y;
6737 gd_x2 = graphic_info[gfx_pressed].src_x;
6738 gd_y2 = graphic_info[gfx_pressed].src_y;
6740 gi = CreateGadget(GDI_CUSTOM_ID, id,
6741 GDI_CUSTOM_TYPE_ID, i,
6742 GDI_INFO_TEXT, menubutton_info[i].infotext,
6747 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6748 GDI_STATE, GD_BUTTON_UNPRESSED,
6749 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6750 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6751 GDI_DIRECT_DRAW, FALSE,
6752 GDI_EVENT_MASK, event_mask,
6753 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6757 Error(ERR_EXIT, "cannot create gadget");
6759 screen_gadget[id] = gi;
6763 static void CreateScreenScrollbuttons()
6765 struct GadgetInfo *gi;
6766 unsigned int event_mask;
6769 /* these values are not constant, but can change at runtime */
6770 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6771 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6772 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6773 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6775 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6777 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6778 int gfx_unpressed, gfx_pressed;
6779 int x, y, width, height;
6780 int gd_x1, gd_x2, gd_y1, gd_y2;
6781 int id = scrollbutton_info[i].gadget_id;
6783 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6785 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6786 y = mSY + scrollbutton_info[i].y;
6787 width = SC_SCROLLBUTTON_XSIZE;
6788 height = SC_SCROLLBUTTON_YSIZE;
6790 /* correct scrollbar position if placed outside menu (playfield) area */
6791 if (x > SX + SC_SCROLL_UP_XPOS)
6792 x = SX + SC_SCROLL_UP_XPOS;
6794 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6795 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6796 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6798 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6799 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6800 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6801 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6802 gd_x1 = graphic_info[gfx_unpressed].src_x;
6803 gd_y1 = graphic_info[gfx_unpressed].src_y;
6804 gd_x2 = graphic_info[gfx_pressed].src_x;
6805 gd_y2 = graphic_info[gfx_pressed].src_y;
6807 gi = CreateGadget(GDI_CUSTOM_ID, id,
6808 GDI_CUSTOM_TYPE_ID, i,
6809 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6814 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6815 GDI_STATE, GD_BUTTON_UNPRESSED,
6816 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6817 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6818 GDI_DIRECT_DRAW, FALSE,
6819 GDI_EVENT_MASK, event_mask,
6820 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6824 Error(ERR_EXIT, "cannot create gadget");
6826 screen_gadget[id] = gi;
6830 static void CreateScreenScrollbars()
6834 /* these values are not constant, but can change at runtime */
6835 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6836 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6837 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6838 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6840 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6842 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6843 int gfx_unpressed, gfx_pressed;
6844 int x, y, width, height;
6845 int gd_x1, gd_x2, gd_y1, gd_y2;
6846 struct GadgetInfo *gi;
6847 int items_max, items_visible, item_position;
6848 unsigned int event_mask;
6849 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6850 int id = scrollbar_info[i].gadget_id;
6852 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6854 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6855 y = mSY + scrollbar_info[i].y;
6856 width = scrollbar_info[i].width;
6857 height = scrollbar_info[i].height;
6859 /* correct scrollbar position if placed outside menu (playfield) area */
6860 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6861 x = SX + SC_SCROLL_VERTICAL_XPOS;
6863 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6864 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6866 items_max = num_page_entries;
6867 items_visible = num_page_entries;
6870 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6871 gfx_pressed = scrollbar_info[i].gfx_pressed;
6872 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6873 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6874 gd_x1 = graphic_info[gfx_unpressed].src_x;
6875 gd_y1 = graphic_info[gfx_unpressed].src_y;
6876 gd_x2 = graphic_info[gfx_pressed].src_x;
6877 gd_y2 = graphic_info[gfx_pressed].src_y;
6879 gi = CreateGadget(GDI_CUSTOM_ID, id,
6880 GDI_CUSTOM_TYPE_ID, i,
6881 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6886 GDI_TYPE, scrollbar_info[i].type,
6887 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6888 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6889 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6890 GDI_WHEEL_AREA_X, SX,
6891 GDI_WHEEL_AREA_Y, SY,
6892 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6893 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6894 GDI_STATE, GD_BUTTON_UNPRESSED,
6895 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6896 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6897 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6898 GDI_DIRECT_DRAW, FALSE,
6899 GDI_EVENT_MASK, event_mask,
6900 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6904 Error(ERR_EXIT, "cannot create gadget");
6906 screen_gadget[id] = gi;
6910 void CreateScreenGadgets()
6912 CreateScreenMenubuttons();
6914 CreateScreenScrollbuttons();
6915 CreateScreenScrollbars();
6918 void FreeScreenGadgets()
6922 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6923 FreeGadget(screen_gadget[i]);
6926 void MapScreenMenuGadgets(int screen_mask)
6930 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6931 if (screen_mask & menubutton_info[i].screen_mask)
6932 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6935 void MapScreenGadgets(int num_entries)
6939 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6942 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6943 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6945 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6946 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6949 void MapScreenTreeGadgets(TreeInfo *ti)
6951 MapScreenGadgets(numTreeInfoInGroup(ti));
6954 static void HandleScreenGadgets(struct GadgetInfo *gi)
6956 int id = gi->custom_id;
6957 int button = gi->event.button;
6958 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6962 case SCREEN_CTRL_ID_PREV_LEVEL:
6963 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6966 case SCREEN_CTRL_ID_NEXT_LEVEL:
6967 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6970 case SCREEN_CTRL_ID_PREV_PLAYER:
6971 HandleSetupScreen_Input_Player(step, -1);
6974 case SCREEN_CTRL_ID_NEXT_PLAYER:
6975 HandleSetupScreen_Input_Player(step, +1);
6978 case SCREEN_CTRL_ID_SCROLL_UP:
6979 if (game_status == GAME_MODE_LEVELS)
6980 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6981 else if (game_status == GAME_MODE_LEVELNR)
6982 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6983 else if (game_status == GAME_MODE_SETUP)
6984 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6985 else if (game_status == GAME_MODE_INFO)
6986 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6989 case SCREEN_CTRL_ID_SCROLL_DOWN:
6990 if (game_status == GAME_MODE_LEVELS)
6991 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6992 else if (game_status == GAME_MODE_LEVELNR)
6993 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6994 else if (game_status == GAME_MODE_SETUP)
6995 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6996 else if (game_status == GAME_MODE_INFO)
6997 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7000 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7001 if (game_status == GAME_MODE_LEVELS)
7002 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7003 else if (game_status == GAME_MODE_LEVELNR)
7004 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7005 else if (game_status == GAME_MODE_SETUP)
7006 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7007 else if (game_status == GAME_MODE_INFO)
7008 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);