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" },
409 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
410 (s) <= GAME_MODE_SETUP ? (s) : \
411 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
412 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
414 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
415 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
416 (i) <= INFO_MODE_LEVELSET ? (i) : \
419 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
420 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
421 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
422 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
423 SETUP_MODE_CHOOSE_ARTWORK : \
424 SETUP_MODE_CHOOSE_OTHER)
426 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
427 menu.draw_xoffset[GAME_MODE_INFO] : \
428 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
429 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
430 menu.draw_yoffset[GAME_MODE_INFO] : \
431 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
433 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
434 menu.draw_xoffset[GAME_MODE_SETUP] : \
435 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
436 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
437 menu.draw_yoffset[GAME_MODE_SETUP] : \
438 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
440 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
441 DRAW_XOFFSET_INFO(info_mode) : \
442 (s) == GAME_MODE_SETUP ? \
443 DRAW_XOFFSET_SETUP(setup_mode) : \
444 menu.draw_xoffset[DRAW_MODE(s)])
445 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
446 DRAW_YOFFSET_INFO(info_mode) : \
447 (s) == GAME_MODE_SETUP ? \
448 DRAW_YOFFSET_SETUP(setup_mode) : \
449 menu.draw_yoffset[DRAW_MODE(s)])
451 #define mSX (SX + DRAW_XOFFSET(game_status))
452 #define mSY (SY + DRAW_YOFFSET(game_status))
454 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
455 menu.list_size[game_status] : \
456 MAX_MENU_ENTRIES_ON_SCREEN)
458 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
459 NUM_MENU_ENTRIES_ON_SCREEN)
462 /* title display and control definitions */
464 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
465 2 * MAX_NUM_TITLE_MESSAGES)
467 #define NO_DIRECT_LEVEL_SELECT (-1)
470 static int num_title_screens = 0;
472 struct TitleControlInfo
481 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
483 /* main menu display and control definitions */
485 #define MAIN_CONTROL_NAME 0
486 #define MAIN_CONTROL_LEVELS 1
487 #define MAIN_CONTROL_SCORES 2
488 #define MAIN_CONTROL_EDITOR 3
489 #define MAIN_CONTROL_INFO 4
490 #define MAIN_CONTROL_GAME 5
491 #define MAIN_CONTROL_SETUP 6
492 #define MAIN_CONTROL_QUIT 7
493 #define MAIN_CONTROL_PREV_LEVEL 8
494 #define MAIN_CONTROL_NEXT_LEVEL 9
495 #define MAIN_CONTROL_FIRST_LEVEL 10
496 #define MAIN_CONTROL_LAST_LEVEL 11
497 #define MAIN_CONTROL_LEVEL_NUMBER 12
498 #define MAIN_CONTROL_LEVEL_INFO_1 13
499 #define MAIN_CONTROL_LEVEL_INFO_2 14
500 #define MAIN_CONTROL_LEVEL_NAME 15
501 #define MAIN_CONTROL_LEVEL_AUTHOR 16
502 #define MAIN_CONTROL_LEVEL_YEAR 17
503 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
504 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
505 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
506 #define MAIN_CONTROL_TITLE_1 21
507 #define MAIN_CONTROL_TITLE_2 22
508 #define MAIN_CONTROL_TITLE_3 23
510 static char str_main_text_name[10];
511 static char str_main_text_first_level[10];
512 static char str_main_text_last_level[10];
513 static char str_main_text_level_number[10];
515 static char *main_text_name = str_main_text_name;
516 static char *main_text_first_level = str_main_text_first_level;
517 static char *main_text_last_level = str_main_text_last_level;
518 static char *main_text_level_number = str_main_text_level_number;
519 static char *main_text_levels = "Levelset";
520 static char *main_text_scores = "Hall Of Fame";
521 static char *main_text_editor = "Level Creator";
522 static char *main_text_info = "Info Screen";
523 static char *main_text_game = "Start Game";
524 static char *main_text_setup = "Setup";
525 static char *main_text_quit = "Quit";
526 static char *main_text_level_name = level.name;
527 static char *main_text_level_author = level.author;
528 static char *main_text_level_year = NULL;
529 static char *main_text_level_imported_from = NULL;
530 static char *main_text_level_imported_by = NULL;
531 static char *main_text_level_tested_by = NULL;
533 struct MainControlInfo
537 struct MenuPosInfo *pos_button;
540 struct TextPosInfo *pos_text;
543 struct TextPosInfo *pos_input;
547 static struct MainControlInfo main_controls[] =
551 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
552 &menu.main.text.name, &main_text_name,
553 &menu.main.input.name, &setup.player_name,
557 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
558 &menu.main.text.levels, &main_text_levels,
563 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
564 &menu.main.text.scores, &main_text_scores,
569 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
570 &menu.main.text.editor, &main_text_editor,
575 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
576 &menu.main.text.info, &main_text_info,
581 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
582 &menu.main.text.game, &main_text_game,
587 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
588 &menu.main.text.setup, &main_text_setup,
593 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
594 &menu.main.text.quit, &main_text_quit,
598 /* (these two buttons are real gadgets) */
600 MAIN_CONTROL_PREV_LEVEL,
601 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
606 MAIN_CONTROL_NEXT_LEVEL,
607 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
613 MAIN_CONTROL_FIRST_LEVEL,
615 &menu.main.text.first_level, &main_text_first_level,
619 MAIN_CONTROL_LAST_LEVEL,
621 &menu.main.text.last_level, &main_text_last_level,
625 MAIN_CONTROL_LEVEL_NUMBER,
627 &menu.main.text.level_number, &main_text_level_number,
631 MAIN_CONTROL_LEVEL_INFO_1,
633 &menu.main.text.level_info_1, NULL,
637 MAIN_CONTROL_LEVEL_INFO_2,
639 &menu.main.text.level_info_2, NULL,
643 MAIN_CONTROL_LEVEL_NAME,
645 &menu.main.text.level_name, &main_text_level_name,
649 MAIN_CONTROL_LEVEL_AUTHOR,
651 &menu.main.text.level_author, &main_text_level_author,
655 MAIN_CONTROL_LEVEL_YEAR,
657 &menu.main.text.level_year, &main_text_level_year,
661 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
663 &menu.main.text.level_imported_from, &main_text_level_imported_from,
667 MAIN_CONTROL_LEVEL_IMPORTED_BY,
669 &menu.main.text.level_imported_by, &main_text_level_imported_by,
673 MAIN_CONTROL_LEVEL_TESTED_BY,
675 &menu.main.text.level_tested_by, &main_text_level_tested_by,
679 MAIN_CONTROL_TITLE_1,
681 &menu.main.text.title_1, &setup.internal.program_title,
685 MAIN_CONTROL_TITLE_2,
687 &menu.main.text.title_2, &setup.internal.program_copyright,
691 MAIN_CONTROL_TITLE_3,
693 &menu.main.text.title_3, &setup.internal.program_company,
706 static int getTitleScreenGraphic(int nr, boolean initial)
708 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
711 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
713 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
717 static int getTitleScreenGameMode(boolean initial)
719 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
723 static int getTitleMessageGameMode(boolean initial)
725 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
728 static int getTitleAnimMode(struct TitleControlInfo *tci)
730 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
732 return base + tci->local_nr;
736 static int getTitleScreenBackground(boolean initial)
738 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
743 static int getTitleMessageBackground(int nr, boolean initial)
745 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
749 static int getTitleBackground(int nr, boolean initial, boolean is_image)
751 int base = (is_image ?
752 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
753 IMG_BACKGROUND_TITLESCREEN_1) :
754 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
755 IMG_BACKGROUND_TITLEMESSAGE_1));
756 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
757 IMG_BACKGROUND_TITLE);
758 int graphic_local = base + nr;
760 if (graphic_info[graphic_local].bitmap != NULL)
761 return graphic_local;
763 if (graphic_info[graphic_global].bitmap != NULL)
764 return graphic_global;
766 return IMG_UNDEFINED;
769 static int getTitleSound(struct TitleControlInfo *tci)
771 boolean is_image = tci->is_image;
772 int initial = tci->initial;
773 int nr = tci->local_nr;
774 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
775 int base = (is_image ?
776 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
777 SND_BACKGROUND_TITLESCREEN_1) :
778 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
779 SND_BACKGROUND_TITLEMESSAGE_1));
780 int sound_global = menu.sound[mode];
781 int sound_local = base + nr;
784 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
785 nr, initial, is_image,
786 sound_global, getSoundListEntry(sound_global)->filename,
787 sound_local, getSoundListEntry(sound_local)->filename);
790 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
793 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
796 return SND_UNDEFINED;
799 static int getTitleMusic(struct TitleControlInfo *tci)
801 boolean is_image = tci->is_image;
802 int initial = tci->initial;
803 int nr = tci->local_nr;
804 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
805 int base = (is_image ?
806 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
807 MUS_BACKGROUND_TITLESCREEN_1) :
808 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
809 MUS_BACKGROUND_TITLEMESSAGE_1));
810 int music_global = menu.music[mode];
811 int music_local = base + nr;
814 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
815 nr, initial, is_image,
816 music_global, getMusicListEntry(music_global)->filename,
817 music_local, getMusicListEntry(music_local)->filename);
820 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
823 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
826 return MUS_UNDEFINED;
829 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
831 boolean is_image = tci->is_image;
832 boolean initial = tci->initial;
833 boolean first = tci->first;
834 int nr = tci->local_nr;
835 struct TitleMessageInfo tmi;
836 struct TitleFadingInfo ti;
838 tmi = (is_image ? (initial ? (first ?
839 titlescreen_initial_first[nr] :
840 titlescreen_initial[nr])
842 titlescreen_first[nr] :
844 : (initial ? (first ?
845 titlemessage_initial_first[nr] :
846 titlemessage_initial[nr])
848 titlemessage_first[nr] :
851 ti.fade_mode = tmi.fade_mode;
852 ti.fade_delay = tmi.fade_delay;
853 ti.post_delay = tmi.post_delay;
854 ti.auto_delay = tmi.auto_delay;
859 static int compareTitleControlInfo(const void *object1, const void *object2)
861 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
862 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
865 if (tci1->initial != tci2->initial)
866 compare_result = (tci1->initial ? -1 : +1);
867 else if (tci1->sort_priority != tci2->sort_priority)
868 compare_result = tci1->sort_priority - tci2->sort_priority;
869 else if (tci1->is_image != tci2->is_image)
870 compare_result = (tci1->is_image ? -1 : +1);
872 compare_result = tci1->local_nr - tci2->local_nr;
874 return compare_result;
877 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
879 int nr, int sort_priority)
881 title_controls[num_title_screens].is_image = is_image;
882 title_controls[num_title_screens].initial = initial;
883 title_controls[num_title_screens].local_nr = nr;
884 title_controls[num_title_screens].sort_priority = sort_priority;
886 title_controls[num_title_screens].first = FALSE; /* will be set later */
891 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
895 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
897 int graphic = getTitleScreenGraphic(i, initial);
898 Bitmap *bitmap = graphic_info[graphic].bitmap;
899 int sort_priority = graphic_info[graphic].sort_priority;
902 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
905 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
907 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
908 char *filename = getLevelSetTitleMessageFilename(i, initial);
909 int sort_priority = tmi->sort_priority;
911 if (filename != NULL)
912 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
916 static void InitializeTitleControls(boolean show_title_initial)
918 num_title_screens = 0;
920 /* 1st step: initialize title screens for game start (only when starting) */
921 if (show_title_initial)
922 InitializeTitleControls_CheckTitleInfo(TRUE);
924 /* 2nd step: initialize title screens for current level set */
925 InitializeTitleControls_CheckTitleInfo(FALSE);
927 /* sort title screens according to sort_priority and title number */
928 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
929 compareTitleControlInfo);
931 /* mark first title screen */
932 title_controls[0].first = TRUE;
935 static boolean visibleMenuPos(struct MenuPosInfo *pos)
937 return (pos != NULL && pos->x != -1 && pos->y != -1);
940 static boolean visibleTextPos(struct TextPosInfo *pos)
942 return (pos != NULL && pos->x != -1 && pos->y != -1);
945 static void InitializeMainControls()
947 boolean local_team_mode = (!options.network && setup.team_mode);
950 /* set main control text values to dynamically determined values */
951 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
953 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
954 menu.main.text.first_level.size));
955 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
956 menu.main.text.last_level.size));
957 strcpy(main_text_level_number, int2str(level_nr,
958 menu.main.text.level_number.size));
960 main_text_level_year = leveldir_current->year;
961 main_text_level_imported_from = leveldir_current->imported_from;
962 main_text_level_imported_by = leveldir_current->imported_by;
963 main_text_level_tested_by = leveldir_current->tested_by;
965 /* set main control screen positions to dynamically determined values */
966 for (i = 0; main_controls[i].nr != -1; i++)
968 struct MainControlInfo *mci = &main_controls[i];
970 struct MenuPosInfo *pos_button = mci->pos_button;
971 struct TextPosInfo *pos_text = mci->pos_text;
972 struct TextPosInfo *pos_input = mci->pos_input;
973 char *text = (mci->text ? *mci->text : NULL);
974 char *input = (mci->input ? *mci->input : NULL);
975 int button_graphic = mci->button_graphic;
976 int font_text = (pos_text ? pos_text->font : -1);
977 int font_input = (pos_input ? pos_input->font : -1);
979 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
980 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
981 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
982 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
983 int text_chars = (text != NULL ? strlen(text) : 0);
984 int input_chars = (input != NULL ? strlen(input) : 0);
987 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
989 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
990 int text_width = font_text_width * text_chars;
991 int text_height = font_text_height;
992 int input_width = font_input_width * input_chars;
993 int input_height = font_input_height;
995 if (nr == MAIN_CONTROL_NAME)
997 menu.main.input.name.width = input_width;
998 menu.main.input.name.height = input_height;
1001 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1003 pos_button->width = button_width;
1004 pos_button->height = button_height;
1007 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1009 /* calculate size for non-clickable text -- needed for text alignment */
1010 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1012 if (pos_text->width == -1 || calculate_text_size)
1013 pos_text->width = text_width;
1014 if (pos_text->height == -1 || calculate_text_size)
1015 pos_text->height = text_height;
1017 if (visibleMenuPos(pos_button))
1019 if (pos_text->x == -1)
1020 pos_text->x = pos_button->x + pos_button->width;
1021 if (pos_text->y == -1)
1023 pos_button->y + (pos_button->height - pos_text->height) / 2;
1027 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1029 if (visibleTextPos(pos_text))
1031 if (pos_input->x == -1)
1032 pos_input->x = pos_text->x + pos_text->width;
1033 if (pos_input->y == -1)
1034 pos_input->y = pos_text->y;
1037 if (pos_input->width == -1)
1038 pos_input->width = input_width;
1039 if (pos_input->height == -1)
1040 pos_input->height = input_height;
1045 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1046 int graphic, boolean pressed)
1048 struct GraphicInfo *g = &graphic_info[graphic];
1051 int xoffset = (pressed ? g->pressed_xoffset : 0);
1052 int yoffset = (pressed ? g->pressed_yoffset : 0);
1054 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1056 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1057 g->width, g->height, dst_x, dst_y);
1060 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1061 boolean active_input,
1062 boolean pressed_button)
1066 for (i = 0; main_controls[i].nr != -1; i++)
1068 struct MainControlInfo *mci = &main_controls[i];
1070 if (mci->nr == nr || nr == -1)
1072 struct MenuPosInfo *pos_button = mci->pos_button;
1073 struct TextPosInfo *pos_text = mci->pos_text;
1074 struct TextPosInfo *pos_input = mci->pos_input;
1075 char *text = (mci->text ? *mci->text : NULL);
1076 char *input = (mci->input ? *mci->input : NULL);
1077 int button_graphic = mci->button_graphic;
1078 int font_text = (pos_text ? pos_text->font : -1);
1079 int font_input = (pos_input ? pos_input->font : -1);
1083 button_graphic = BUTTON_ACTIVE(button_graphic);
1084 font_text = FONT_ACTIVE(font_text);
1089 font_input = FONT_ACTIVE(font_input);
1092 if (visibleMenuPos(pos_button))
1094 struct MenuPosInfo *pos = pos_button;
1095 int x = mSX + pos->x;
1096 int y = mSY + pos->y;
1098 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1099 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1102 if (visibleTextPos(pos_text) && text != NULL)
1104 struct TextPosInfo *pos = pos_text;
1105 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1106 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1109 /* (check why/if this is needed) */
1110 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1112 DrawText(x, y, text, font_text);
1115 if (visibleTextPos(pos_input) && input != NULL)
1117 struct TextPosInfo *pos = pos_input;
1118 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1119 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1122 /* (check why/if this is needed) */
1123 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1125 DrawText(x, y, input, font_input);
1131 static void DrawCursorAndText_Main(int nr, boolean active_text,
1132 boolean pressed_button)
1134 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1138 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1139 boolean pressed_button)
1141 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1145 static struct MainControlInfo *getMainControlInfo(int nr)
1149 for (i = 0; main_controls[i].nr != -1; i++)
1150 if (main_controls[i].nr == nr)
1151 return &main_controls[i];
1156 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1161 int rect_x = ALIGNED_TEXT_XPOS(rect);
1162 int rect_y = ALIGNED_TEXT_YPOS(rect);
1164 return (x >= rect_x && x < rect_x + rect->width &&
1165 y >= rect_y && y < rect_y + rect->height);
1168 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1173 int rect_x = ALIGNED_TEXT_XPOS(rect);
1174 int rect_y = ALIGNED_TEXT_YPOS(rect);
1177 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1178 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1179 (x >= rect_x && x < rect_x + rect->width &&
1180 y >= rect_y && y < rect_y + rect->height));
1183 return (x >= rect_x && x < rect_x + rect->width &&
1184 y >= rect_y && y < rect_y + rect->height);
1187 static void AdjustScrollbar(int id, int items_max, int items_visible,
1190 struct GadgetInfo *gi = screen_gadget[id];
1192 if (item_position > items_max - items_visible)
1193 item_position = items_max - items_visible;
1195 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1196 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1197 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1200 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1202 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1206 static void clearMenuListArea()
1208 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1210 /* correct scrollbar position if placed outside menu (playfield) area */
1211 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1212 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1214 /* clear menu list area, but not title or scrollbar */
1215 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1216 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1219 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1221 static int cursor_array[MAX_LEV_FIELDY];
1222 int x = mSX + TILEX * xpos;
1223 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1228 cursor_array[ypos] = graphic;
1230 graphic = cursor_array[ypos];
1234 graphic = BUTTON_ACTIVE(graphic);
1236 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1237 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1240 static void initCursor(int ypos, int graphic)
1242 drawCursorExt(0, ypos, FALSE, graphic);
1245 static void drawCursor(int ypos, boolean active)
1247 drawCursorExt(0, ypos, active, -1);
1250 static void drawCursorXY(int xpos, int ypos, int graphic)
1252 drawCursorExt(xpos, ypos, FALSE, graphic);
1255 static void drawChooseTreeCursor(int ypos, boolean active)
1257 drawCursorExt(0, ypos, active, -1);
1262 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1263 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1264 setup.internal.program_copyright);
1267 void DrawTitleScreenImage(int nr, boolean initial)
1269 int graphic = getTitleScreenGraphic(nr, initial);
1270 Bitmap *bitmap = graphic_info[graphic].bitmap;
1271 int width = graphic_info[graphic].width;
1272 int height = graphic_info[graphic].height;
1273 int src_x = graphic_info[graphic].src_x;
1274 int src_y = graphic_info[graphic].src_y;
1280 if (width > WIN_XSIZE)
1282 /* image width too large for window => center image horizontally */
1283 src_x = (width - WIN_XSIZE) / 2;
1287 if (height > WIN_YSIZE)
1289 /* image height too large for window => center image vertically */
1290 src_y = (height - WIN_YSIZE) / 2;
1294 /* always display title screens centered */
1295 dst_x = (WIN_XSIZE - width) / 2;
1296 dst_y = (WIN_YSIZE - height) / 2;
1298 SetDrawBackgroundMask(REDRAW_ALL);
1299 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1301 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1303 if (DrawingOnBackground(dst_x, dst_y))
1304 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1306 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1308 redraw_mask = REDRAW_ALL;
1311 void DrawTitleScreenMessage(int nr, boolean initial)
1313 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1314 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1316 if (filename == NULL)
1319 /* force TITLE font on title message screen */
1320 SetFontStatus(getTitleMessageGameMode(initial));
1322 /* if chars *and* width set to "-1", automatically determine width */
1323 if (tmi->chars == -1 && tmi->width == -1)
1324 tmi->width = viewport.window[game_status].width;
1326 /* if lines *and* height set to "-1", automatically determine height */
1327 if (tmi->lines == -1 && tmi->height == -1)
1328 tmi->height = viewport.window[game_status].height;
1330 /* if chars set to "-1", automatically determine by text and font width */
1331 if (tmi->chars == -1)
1332 tmi->chars = tmi->width / getFontWidth(tmi->font);
1334 tmi->width = tmi->chars * getFontWidth(tmi->font);
1336 /* if lines set to "-1", automatically determine by text and font height */
1337 if (tmi->lines == -1)
1338 tmi->lines = tmi->height / getFontHeight(tmi->font);
1340 tmi->height = tmi->lines * getFontHeight(tmi->font);
1342 /* if x set to "-1", automatically determine by width and alignment */
1344 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1346 /* if y set to "-1", automatically determine by height and alignment */
1348 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1350 SetDrawBackgroundMask(REDRAW_ALL);
1351 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1353 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1355 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1356 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1357 tmi->autowrap, tmi->centered, tmi->parse_comments);
1362 void DrawTitleScreen()
1364 KeyboardAutoRepeatOff();
1366 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1369 boolean CheckTitleScreen(boolean levelset_has_changed)
1371 static boolean show_title_initial = TRUE;
1372 boolean show_titlescreen = FALSE;
1374 /* needed to be able to skip title screen, if no image or message defined */
1375 InitializeTitleControls(show_title_initial);
1377 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1378 show_titlescreen = TRUE;
1380 /* show initial title images and messages only once at program start */
1381 show_title_initial = FALSE;
1383 return (show_titlescreen && num_title_screens > 0);
1388 static LevelDirTree *leveldir_last_valid = NULL;
1389 boolean levelset_has_changed = FALSE;
1390 int fade_mask = REDRAW_FIELD;
1392 LimitScreenUpdates(FALSE);
1394 FadeSetLeaveScreen();
1396 /* do not fade out here -- function may continue and fade on editor screen */
1399 FadeSoundsAndMusic();
1401 ExpireSoundLoops(FALSE);
1403 KeyboardAutoRepeatOn();
1406 audio.sound_deactivated = FALSE;
1410 /* needed if last screen was the playing screen, invoked from level editor */
1411 if (level_editor_test_game)
1413 CloseDoor(DOOR_CLOSE_ALL);
1415 SetGameStatus(GAME_MODE_EDITOR);
1422 /* needed if last screen was the setup screen and fullscreen state changed */
1423 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1424 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1426 /* leveldir_current may be invalid (level group, parent link) */
1427 if (!validLevelSeries(leveldir_current))
1428 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1430 if (leveldir_current != leveldir_last_valid)
1431 levelset_has_changed = TRUE;
1433 /* store valid level series information */
1434 leveldir_last_valid = leveldir_current;
1436 init_last = init; /* switch to new busy animation */
1438 /* needed if last screen (level choice) changed graphics, sounds or music */
1439 ReloadCustomArtwork(0);
1441 if (CheckTitleScreen(levelset_has_changed))
1443 game_status_last_screen = GAME_MODE_MAIN;
1445 SetGameStatus(GAME_MODE_TITLE);
1452 if (redraw_mask & REDRAW_ALL)
1453 fade_mask = REDRAW_ALL;
1455 if (CheckIfGlobalBorderHasChanged())
1456 fade_mask = REDRAW_ALL;
1460 /* needed if different viewport properties defined for menues */
1461 ChangeViewportPropertiesIfNeeded();
1463 SetDrawtoField(DRAW_TO_BACKBUFFER);
1465 /* level_nr may have been set to value over handicap with level editor */
1466 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1467 level_nr = leveldir_current->handicap_level;
1469 LoadLevel(level_nr);
1470 LoadScore(level_nr);
1472 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1473 SetDrawDeactivationMask(REDRAW_NONE);
1474 SetDrawBackgroundMask(REDRAW_FIELD);
1476 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1479 if (fade_mask == REDRAW_ALL)
1480 RedrawGlobalBorder();
1485 InitializeMainControls();
1487 DrawCursorAndText_Main(-1, FALSE, FALSE);
1488 DrawPreviewLevelInitial();
1490 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1493 if (TAPE_IS_EMPTY(tape))
1495 DrawCompleteVideoDisplay();
1500 /* create gadgets for main menu screen */
1501 FreeScreenGadgets();
1502 CreateScreenGadgets();
1504 /* map gadgets for main menu screen */
1506 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1508 /* copy actual game door content to door double buffer for OpenDoor() */
1509 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1510 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1512 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1514 DrawMaskedBorder(fade_mask);
1519 /* update screen area with special editor door */
1520 redraw_mask |= REDRAW_ALL;
1523 SetMouseCursor(CURSOR_DEFAULT);
1525 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1528 static void gotoTopLevelDir()
1530 /* move upwards until inside (but not above) top level directory */
1531 while (leveldir_current->node_parent &&
1532 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1534 /* write a "path" into level tree for easy navigation to last level */
1535 if (leveldir_current->node_parent->node_group->cl_first == -1)
1537 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1538 int leveldir_pos = posTreeInfo(leveldir_current);
1539 int num_page_entries;
1540 int cl_first, cl_cursor;
1542 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1543 num_page_entries = num_leveldirs;
1545 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1547 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1548 cl_cursor = leveldir_pos - cl_first;
1550 leveldir_current->node_parent->node_group->cl_first = cl_first;
1551 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1554 leveldir_current = leveldir_current->node_parent;
1558 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1560 static unsigned int title_delay = 0;
1561 static int title_screen_nr = 0;
1562 static int last_sound = -1, last_music = -1;
1563 boolean return_to_main_menu = FALSE;
1564 struct TitleControlInfo *tci;
1567 if (button == MB_MENU_INITIALIZE)
1570 title_screen_nr = 0;
1571 tci = &title_controls[title_screen_nr];
1573 SetAnimStatus(getTitleAnimMode(tci));
1575 last_sound = SND_UNDEFINED;
1576 last_music = MUS_UNDEFINED;
1578 if (num_title_screens != 0)
1580 FadeSetEnterScreen();
1582 /* use individual title fading instead of global "enter screen" fading */
1583 fading = getTitleFading(tci);
1586 if (game_status_last_screen == GAME_MODE_INFO)
1588 if (num_title_screens == 0)
1590 /* switch game mode from title screen mode back to info screen mode */
1591 SetGameStatus(GAME_MODE_INFO);
1593 DrawInfoScreen_NotAvailable("Title screen information:",
1594 "No title screen for this level set.");
1598 FadeSoundsAndMusic();
1601 FadeOut(REDRAW_ALL);
1603 /* title screens may have different window size */
1604 ChangeViewportPropertiesIfNeeded();
1606 /* only required to update logic for redrawing global border */
1610 DrawTitleScreenImage(tci->local_nr, tci->initial);
1612 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1614 sound = getTitleSound(tci);
1615 music = getTitleMusic(tci);
1617 if (sound != last_sound)
1618 PlayMenuSoundExt(sound);
1619 if (music != last_music)
1620 PlayMenuMusicExt(music);
1625 SetMouseCursor(CURSOR_NONE);
1629 DelayReached(&title_delay, 0); /* reset delay counter */
1634 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1635 button = MB_MENU_CHOICE;
1637 if (button == MB_MENU_LEAVE)
1639 return_to_main_menu = TRUE;
1641 else if (button == MB_MENU_CHOICE)
1643 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1645 SetGameStatus(GAME_MODE_INFO);
1647 info_mode = INFO_MODE_MAIN;
1656 if (title_screen_nr < num_title_screens)
1658 tci = &title_controls[title_screen_nr];
1660 SetAnimStatus(getTitleAnimMode(tci));
1662 sound = getTitleSound(tci);
1663 music = getTitleMusic(tci);
1665 if (last_sound != SND_UNDEFINED && sound != last_sound)
1666 FadeSound(last_sound);
1667 if (last_music != MUS_UNDEFINED && music != last_music)
1670 fading = getTitleFading(tci);
1672 FadeOut(REDRAW_ALL);
1675 DrawTitleScreenImage(tci->local_nr, tci->initial);
1677 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1679 sound = getTitleSound(tci);
1680 music = getTitleMusic(tci);
1682 if (sound != last_sound)
1683 PlayMenuSoundExt(sound);
1684 if (music != last_music)
1685 PlayMenuMusicExt(music);
1692 DelayReached(&title_delay, 0); /* reset delay counter */
1696 FadeSoundsAndMusic();
1698 return_to_main_menu = TRUE;
1702 if (return_to_main_menu)
1704 SetMouseCursor(CURSOR_DEFAULT);
1706 /* force full menu screen redraw after displaying title screens */
1707 redraw_mask = REDRAW_ALL;
1709 if (game_status_last_screen == GAME_MODE_INFO)
1711 SetGameStatus(GAME_MODE_INFO);
1713 info_mode = INFO_MODE_MAIN;
1717 else /* default: return to main menu */
1719 SetGameStatus(GAME_MODE_MAIN);
1726 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1728 int old_level_nr = level_nr;
1731 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1732 new_level_nr = selected_level_nr;
1734 new_level_nr = old_level_nr + step * direction;
1736 if (new_level_nr < leveldir_current->first_level)
1737 new_level_nr = leveldir_current->first_level;
1738 if (new_level_nr > leveldir_current->last_level)
1739 new_level_nr = leveldir_current->last_level;
1741 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1743 /* skipping levels is only allowed when trying to skip single level */
1744 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1745 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1747 leveldir_current->handicap_level++;
1748 SaveLevelSetup_SeriesInfo();
1751 new_level_nr = leveldir_current->handicap_level;
1754 if (new_level_nr != old_level_nr)
1756 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1758 PlaySound(SND_MENU_ITEM_SELECTING);
1760 level_nr = new_level_nr;
1762 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1763 int2str(level_nr, menu.main.text.level_number.size),
1764 mci->pos_text->font);
1766 LoadLevel(level_nr);
1767 DrawPreviewLevelInitial();
1771 DrawCompleteVideoDisplay();
1773 /* needed because DrawPreviewLevelInitial() takes some time */
1775 /* SyncDisplay(); */
1779 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1781 static int choice = MAIN_CONTROL_GAME;
1782 static boolean button_pressed_last = FALSE;
1783 boolean button_pressed = FALSE;
1787 if (button == MB_MENU_INITIALIZE)
1789 DrawCursorAndText_Main(choice, TRUE, FALSE);
1794 if (mx || my) /* mouse input */
1798 for (i = 0; main_controls[i].nr != -1; i++)
1800 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1801 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1802 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1804 pos = main_controls[i].nr;
1810 // handle pressed/unpressed state for active/inactive menu buttons
1811 // (if pos != -1, "i" contains index position corresponding to "pos")
1813 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1814 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1815 button_pressed = TRUE;
1817 if (button_pressed != button_pressed_last)
1819 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1822 PlaySound(SND_MENU_BUTTON_PRESSING);
1824 PlaySound(SND_MENU_BUTTON_RELEASING);
1827 else if (dx || dy) /* keyboard input */
1829 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1830 choice == MAIN_CONTROL_SETUP))
1831 button = MB_MENU_CHOICE;
1836 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1838 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1840 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1842 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1844 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1846 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1848 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1850 CloseDoor(DOOR_CLOSE_2);
1852 SetGameStatus(GAME_MODE_LEVELNR);
1854 DrawChooseLevelNr();
1856 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1862 PlaySound(SND_MENU_ITEM_ACTIVATING);
1864 DrawCursorAndText_Main(choice, FALSE, FALSE);
1865 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1872 PlaySound(SND_MENU_ITEM_SELECTING);
1874 if (pos == MAIN_CONTROL_NAME)
1876 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
1878 HandleTypeName(strlen(setup.player_name), 0);
1880 else if (pos == MAIN_CONTROL_LEVELS)
1884 CloseDoor(DOOR_CLOSE_2);
1886 SetGameStatus(GAME_MODE_LEVELS);
1888 SaveLevelSetup_LastSeries();
1889 SaveLevelSetup_SeriesInfo();
1891 if (setup.internal.choose_from_top_leveldir)
1894 DrawChooseLevelSet();
1897 else if (pos == MAIN_CONTROL_SCORES)
1899 CloseDoor(DOOR_CLOSE_2);
1901 SetGameStatus(GAME_MODE_SCORES);
1905 else if (pos == MAIN_CONTROL_EDITOR)
1907 if (leveldir_current->readonly &&
1908 !strEqual(setup.player_name, "Artsoft"))
1909 Request("This level is read only!", REQ_CONFIRM);
1911 CloseDoor(DOOR_CLOSE_2);
1913 SetGameStatus(GAME_MODE_EDITOR);
1915 FadeSetEnterScreen();
1919 else if (pos == MAIN_CONTROL_INFO)
1921 CloseDoor(DOOR_CLOSE_2);
1923 SetGameStatus(GAME_MODE_INFO);
1925 info_mode = INFO_MODE_MAIN;
1929 else if (pos == MAIN_CONTROL_GAME)
1931 StartGameActions(options.network, setup.autorecord, level.random_seed);
1933 else if (pos == MAIN_CONTROL_SETUP)
1935 CloseDoor(DOOR_CLOSE_2);
1937 SetGameStatus(GAME_MODE_SETUP);
1939 setup_mode = SETUP_MODE_MAIN;
1943 else if (pos == MAIN_CONTROL_QUIT)
1945 SaveLevelSetup_LastSeries();
1946 SaveLevelSetup_SeriesInfo();
1948 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1949 SetGameStatus(GAME_MODE_QUIT);
1954 button_pressed_last = button_pressed;
1958 /* ========================================================================= */
1959 /* info screen functions */
1960 /* ========================================================================= */
1962 static struct TokenInfo *info_info;
1963 static int num_info_info; /* number of info entries shown on screen */
1964 static int max_info_info; /* total number of info entries in list */
1966 static void execInfoTitleScreen()
1968 info_mode = INFO_MODE_TITLE;
1973 static void execInfoElements()
1975 info_mode = INFO_MODE_ELEMENTS;
1980 static void execInfoMusic()
1982 info_mode = INFO_MODE_MUSIC;
1987 static void execInfoCredits()
1989 info_mode = INFO_MODE_CREDITS;
1994 static void execInfoProgram()
1996 info_mode = INFO_MODE_PROGRAM;
2001 static void execInfoVersion()
2003 info_mode = INFO_MODE_VERSION;
2008 static void execInfoLevelSet()
2010 info_mode = INFO_MODE_LEVELSET;
2015 static void execExitInfo()
2017 SetGameStatus(GAME_MODE_MAIN);
2022 static struct TokenInfo info_info_main[] =
2024 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2025 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2026 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2027 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2028 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2029 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2030 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2031 { TYPE_EMPTY, NULL, "" },
2032 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2037 static int getMenuTextFont(int type)
2039 if (type & (TYPE_SWITCH |
2051 static struct TokenInfo *setup_info;
2052 static struct TokenInfo setup_info_input[];
2054 static struct TokenInfo *menu_info;
2056 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2057 int screen_pos, int menu_info_pos_raw,
2060 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2061 struct TokenInfo *ti = &token_info[pos];
2062 int xpos = MENU_SCREEN_START_XPOS;
2063 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2064 int font_nr = getMenuTextFont(ti->type);
2066 if (token_info == setup_info_input)
2067 font_nr = FONT_MENU_1;
2070 font_nr = FONT_ACTIVE(font_nr);
2072 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2074 if (ti->type & ~TYPE_SKIP_ENTRY)
2075 drawCursor(screen_pos, active);
2078 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2081 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2084 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2087 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2090 static char *window_size_text;
2091 static char *scaling_type_text;
2093 static void drawSetupValue(int, int);
2095 static void drawMenuInfoList(int first_entry, int num_page_entries,
2096 int max_page_entries)
2100 if (first_entry + num_page_entries > max_page_entries)
2103 clearMenuListArea();
2105 for (i = 0; i < num_page_entries; i++)
2107 int menu_info_pos = first_entry + i;
2108 struct TokenInfo *si = &menu_info[menu_info_pos];
2109 void *value_ptr = si->value;
2111 /* set some entries to "unchangeable" according to other variables */
2112 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2113 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2114 (value_ptr == &setup.sound_music && !audio.music_available) ||
2115 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2116 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2117 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2118 si->type |= TYPE_GHOSTED;
2120 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2121 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2122 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2123 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2124 else if (si->type & ~TYPE_SKIP_ENTRY)
2125 initCursor(i, IMG_MENU_BUTTON);
2127 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2129 if (si->type & TYPE_VALUE &&
2130 menu_info == setup_info)
2131 drawSetupValue(i, menu_info_pos);
2135 static void DrawInfoScreen_Main()
2137 int fade_mask = REDRAW_FIELD;
2140 if (redraw_mask & REDRAW_ALL)
2141 fade_mask = REDRAW_ALL;
2143 if (CheckIfGlobalBorderHasChanged())
2144 fade_mask = REDRAW_ALL;
2147 FadeSoundsAndMusic();
2149 FreeScreenGadgets();
2150 CreateScreenGadgets();
2152 /* (needed after displaying title screens which disable auto repeat) */
2153 KeyboardAutoRepeatOn();
2155 FadeSetLeaveScreen();
2159 /* needed if different viewport properties defined for info screen */
2160 ChangeViewportPropertiesIfNeeded();
2162 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2166 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2168 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2170 info_info = info_info_main;
2172 // determine maximal number of info entries that can be displayed on screen
2174 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2177 // determine maximal number of info entries available for menu of info screen
2179 for (i = 0; info_info[i].type != 0; i++)
2182 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2184 MapScreenGadgets(max_info_info);
2189 DrawMaskedBorder(fade_mask);
2194 static void changeSetupValue(int, int, int);
2196 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2197 int mode, int num_page_entries, int max_page_entries)
2199 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2200 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2201 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2202 int *num_page_entries_last = num_page_entries_all_last[game_status];
2203 int *choice_store = choice_stores[game_status];
2204 int *first_entry_store = first_entry_stores[game_status];
2205 int choice = choice_store[mode]; /* starts with 0 */
2206 int first_entry = first_entry_store[mode]; /* starts with 0 */
2208 int y = choice - first_entry;
2210 boolean position_set_by_scrollbar = (dx == 999);
2211 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2214 if (button == MB_MENU_INITIALIZE)
2216 // check if number of menu page entries has changed (may happen by change
2217 // of custom artwork definition value for 'list_size' for this menu screen)
2218 // (in this case, the last menu position most probably has to be corrected)
2219 if (num_page_entries != num_page_entries_last[mode])
2221 choice_store[mode] = first_entry_store[mode] = 0;
2223 choice = first_entry = 0;
2226 num_page_entries_last[mode] = num_page_entries;
2229 /* advance to first valid menu entry */
2230 while (choice < num_page_entries &&
2231 menu_info[choice].type & TYPE_SKIP_ENTRY)
2234 if (position_set_by_scrollbar)
2235 first_entry = first_entry_store[mode] = dy;
2237 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2238 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2240 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2242 if (choice < first_entry)
2244 choice = first_entry;
2246 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2249 else if (choice > first_entry + num_page_entries - 1)
2251 choice = first_entry + num_page_entries - 1;
2253 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2257 choice_store[mode] = choice;
2259 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2263 else if (button == MB_MENU_LEAVE)
2265 PlaySound(SND_MENU_ITEM_SELECTING);
2267 for (i = 0; i < max_page_entries; i++)
2269 if (menu_info[i].type & TYPE_LEAVE_MENU)
2271 void (*menu_callback_function)(void) = menu_info[i].value;
2275 menu_callback_function();
2277 break; /* absolutely needed because function changes 'menu_info'! */
2284 if (mx || my) /* mouse input */
2286 x = (mx - mSX) / 32;
2287 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2289 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2291 /* move cursor instead of scrolling when already at start/end of list */
2292 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2294 else if (dy == +1 * SCROLL_LINE &&
2295 first_entry + num_page_entries == max_page_entries)
2298 /* handle scrolling screen one line or page */
2300 y + dy > num_page_entries - 1)
2302 boolean redraw = FALSE;
2304 if (ABS(dy) == SCROLL_PAGE)
2305 step = num_page_entries - 1;
2307 if (dy < 0 && first_entry > 0)
2309 /* scroll page/line up */
2311 first_entry -= step;
2312 if (first_entry < 0)
2317 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2319 /* scroll page/line down */
2321 first_entry += step;
2322 if (first_entry + num_page_entries > max_page_entries)
2323 first_entry = MAX(0, max_page_entries - num_page_entries);
2330 choice += first_entry - first_entry_store[mode];
2332 if (choice < first_entry)
2334 choice = first_entry;
2336 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2339 else if (choice > first_entry + num_page_entries - 1)
2341 choice = first_entry + num_page_entries - 1;
2343 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2346 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2350 if (choice < first_entry ||
2351 choice > first_entry + num_page_entries - 1)
2352 first_entry += SIGN(dy);
2355 first_entry_store[mode] = first_entry;
2356 choice_store[mode] = choice;
2358 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2360 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2362 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2363 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2371 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2373 if (menu_info[choice].type & menu_navigation_type ||
2374 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2375 menu_info[choice].type & TYPE_YES_NO_AUTO)
2376 button = MB_MENU_CHOICE;
2381 /* jump to next non-empty menu entry (up or down) */
2382 while (first_entry + y > 0 &&
2383 first_entry + y < max_page_entries - 1 &&
2384 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2387 if (!IN_VIS_MENU(x, y))
2389 choice += y - y_old;
2391 if (choice < first_entry)
2392 first_entry = choice;
2393 else if (choice > first_entry + num_page_entries - 1)
2394 first_entry = choice - num_page_entries + 1;
2396 if (first_entry >= 0 &&
2397 first_entry + num_page_entries <= max_page_entries)
2399 first_entry_store[mode] = first_entry;
2401 if (choice < first_entry)
2402 choice = first_entry;
2403 else if (choice > first_entry + num_page_entries - 1)
2404 choice = first_entry + num_page_entries - 1;
2406 choice_store[mode] = choice;
2408 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2410 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2412 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2413 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2420 if (!anyScrollbarGadgetActive() &&
2421 IN_VIS_MENU(x, y) &&
2422 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2423 y >= 0 && y < num_page_entries)
2427 if (first_entry + y != choice &&
2428 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2430 PlaySound(SND_MENU_ITEM_ACTIVATING);
2432 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2433 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2435 choice = choice_store[mode] = first_entry + y;
2438 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2440 PlaySound(SND_MENU_ITEM_SELECTING);
2442 /* when selecting key headline, execute function for key value change */
2443 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2444 menu_info[first_entry + y + 1].type & TYPE_KEY)
2447 /* when selecting string value, execute function for list selection */
2448 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2449 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2452 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2454 void (*menu_callback_function)(void) =
2455 menu_info[first_entry + y].value;
2457 FadeSetFromType(menu_info[first_entry + y].type);
2459 menu_callback_function();
2461 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2462 menu_info == setup_info)
2464 changeSetupValue(y, first_entry + y, dx);
2470 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2472 menu_info = info_info;
2474 HandleMenuScreen(mx, my, dx, dy, button,
2475 info_mode, num_info_info, max_info_info);
2478 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2480 int ystart1 = mSY - SY + 100;
2481 int ystart2 = mSY - SY + 150;
2482 int ybottom = mSY - SY + SYSIZE - 20;
2484 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2486 FadeOut(REDRAW_FIELD);
2491 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2492 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2494 DrawTextSCentered(ybottom, FONT_TEXT_4,
2495 "Press any key or button for info menu");
2497 FadeIn(REDRAW_FIELD);
2500 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2502 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2503 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2504 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2505 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2506 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2507 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2508 int ystep = MENU_SCREEN_INFO_YSTEP;
2509 int element, action, direction;
2517 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2518 infoscreen_step[i] = infoscreen_frame[i] = 0;
2523 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2525 DrawTextSCentered(ybottom, FONT_TEXT_4,
2526 "Press any key or button for next page");
2532 while (helpanim_info[j].element != HELPANIM_LIST_END)
2534 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2539 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2548 j += infoscreen_step[i - start];
2550 element = helpanim_info[j].element;
2551 action = helpanim_info[j].action;
2552 direction = helpanim_info[j].direction;
2555 element = EL_UNKNOWN;
2557 if (action != -1 && direction != -1)
2558 graphic = el_act_dir2img(element, action, direction);
2559 else if (action != -1)
2560 graphic = el_act2img(element, action);
2561 else if (direction != -1)
2562 graphic = el_dir2img(element, direction);
2564 graphic = el2img(element);
2566 delay = helpanim_info[j++].delay;
2571 if (infoscreen_frame[i - start] == 0)
2574 infoscreen_frame[i - start] = delay - 1;
2578 sync_frame = delay - infoscreen_frame[i - start];
2579 infoscreen_frame[i - start]--;
2582 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2584 if (!infoscreen_frame[i - start])
2585 infoscreen_step[i - start] = 0;
2589 if (!infoscreen_frame[i - start])
2590 infoscreen_step[i - start]++;
2591 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2597 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2599 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2600 graphic, sync_frame, USE_MASKING);
2603 DrawInfoScreen_HelpText(element, action, direction, i - start);
2608 redraw_mask |= REDRAW_FIELD;
2613 static char *getHelpText(int element, int action, int direction)
2615 char token[MAX_LINE_LEN];
2617 strcpy(token, element_info[element].token_name);
2620 strcat(token, element_action_info[action].suffix);
2622 if (direction != -1)
2623 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2625 return getHashEntry(helptext_info, token);
2628 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2630 int font_nr = FONT_INFO_ELEMENTS;
2631 int font_width = getFontWidth(font_nr);
2632 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2633 int sy = mSY + 65 + 2 * 32 + 1;
2634 int ystep = TILEY + 4;
2635 int pad_x = sx - SX;
2636 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2637 int max_lines_per_text = 2;
2640 if (action != -1 && direction != -1) /* element.action.direction */
2641 text = getHelpText(element, action, direction);
2643 if (text == NULL && action != -1) /* element.action */
2644 text = getHelpText(element, action, -1);
2646 if (text == NULL && direction != -1) /* element.direction */
2647 text = getHelpText(element, -1, direction);
2649 if (text == NULL) /* base element */
2650 text = getHelpText(element, -1, -1);
2652 if (text == NULL) /* not found */
2653 text = "No description available";
2655 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2656 sy += getFontHeight(font_nr) / 2;
2658 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2659 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2660 TRUE, FALSE, FALSE);
2663 void DrawInfoScreen_TitleScreen()
2665 game_status_last_screen = GAME_MODE_INFO;
2667 SetGameStatus(GAME_MODE_TITLE);
2672 void HandleInfoScreen_TitleScreen(int button)
2674 HandleTitleScreen(0, 0, 0, 0, button);
2677 void DrawInfoScreen_Elements()
2679 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2681 FadeOut(REDRAW_FIELD);
2686 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2688 FadeIn(REDRAW_FIELD);
2691 void HandleInfoScreen_Elements(int button)
2693 static unsigned int info_delay = 0;
2694 static int num_anims;
2695 static int num_pages;
2697 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2700 if (button == MB_MENU_INITIALIZE)
2702 boolean new_element = TRUE;
2706 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2708 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2710 else if (new_element)
2713 new_element = FALSE;
2717 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2721 if (button == MB_MENU_LEAVE)
2723 PlaySound(SND_MENU_ITEM_SELECTING);
2725 info_mode = INFO_MODE_MAIN;
2730 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2732 if (button != MB_MENU_INITIALIZE)
2734 PlaySound(SND_MENU_ITEM_SELECTING);
2739 if (page >= num_pages)
2741 FadeSoundsAndMusic();
2743 info_mode = INFO_MODE_MAIN;
2750 FadeSetNextScreen();
2752 if (button != MB_MENU_INITIALIZE)
2753 FadeOut(REDRAW_FIELD);
2755 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2757 if (button != MB_MENU_INITIALIZE)
2758 FadeIn(REDRAW_FIELD);
2762 if (DelayReached(&info_delay, GameFrameDelay))
2763 if (page < num_pages)
2764 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2766 PlayMenuSoundIfLoop();
2770 void DrawInfoScreen_Music()
2772 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2774 FadeOut(REDRAW_FIELD);
2781 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2783 FadeIn(REDRAW_FIELD);
2786 void HandleInfoScreen_Music(int button)
2788 static struct MusicFileInfo *list = NULL;
2789 int ystart1 = mSY - SY + 100;
2790 int ystart2 = mSY - SY + 150;
2791 int ybottom = mSY - SY + SYSIZE - 20;
2794 if (button == MB_MENU_INITIALIZE)
2796 list = music_file_info;
2800 FadeSoundsAndMusic();
2805 DrawTextSCentered(ystart1, FONT_TEXT_1,
2806 "No music info for this level set.");
2808 DrawTextSCentered(ybottom, FONT_TEXT_4,
2809 "Press any key or button for info menu");
2815 if (button == MB_MENU_LEAVE)
2817 PlaySound(SND_MENU_ITEM_SELECTING);
2819 FadeSoundsAndMusic();
2821 info_mode = INFO_MODE_MAIN;
2826 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2830 if (button != MB_MENU_INITIALIZE)
2832 PlaySound(SND_MENU_ITEM_SELECTING);
2840 FadeSoundsAndMusic();
2842 info_mode = INFO_MODE_MAIN;
2848 FadeSoundsAndMusic();
2850 if (list != music_file_info)
2851 FadeSetNextScreen();
2853 if (button != MB_MENU_INITIALIZE)
2854 FadeOut(REDRAW_FIELD);
2861 int sound = list->music;
2863 if (sound_info[sound].loop)
2864 PlaySoundLoop(sound);
2868 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2872 PlayMusic(list->music);
2874 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2877 if (!strEqual(list->title, UNKNOWN_NAME))
2879 if (!strEqual(list->title_header, UNKNOWN_NAME))
2880 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2882 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2885 if (!strEqual(list->artist, UNKNOWN_NAME))
2887 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2888 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2890 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2892 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2895 if (!strEqual(list->album, UNKNOWN_NAME))
2897 if (!strEqual(list->album_header, UNKNOWN_NAME))
2898 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2900 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2902 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2905 if (!strEqual(list->year, UNKNOWN_NAME))
2907 if (!strEqual(list->year_header, UNKNOWN_NAME))
2908 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2910 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2912 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2915 DrawTextSCentered(ybottom, FONT_TEXT_4,
2916 "Press any key or button for next page");
2918 if (button != MB_MENU_INITIALIZE)
2919 FadeIn(REDRAW_FIELD);
2922 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2923 PlaySoundLoop(list->music);
2926 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2928 int ystart1 = mSY - SY + 100;
2929 int ystart2 = mSY - SY + 150;
2930 int ybottom = mSY - SY + SYSIZE - 20;
2936 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2940 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2941 "Special thanks to");
2942 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2944 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2946 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2947 "\"Boulder Dash\"");
2948 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2950 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2952 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2954 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2955 "First Star Software");
2957 else if (screen_nr == 1)
2959 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2960 "Special thanks to");
2961 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2962 "Klaus Heinz & Volker Wertich");
2963 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2965 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2966 "\"Emerald Mine\"");
2967 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2969 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2971 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2973 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2976 else if (screen_nr == 2)
2978 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2979 "Special thanks to");
2980 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2981 "Michael Stopp & Philip Jespersen");
2982 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2984 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2986 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2988 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2990 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2992 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2993 "Digital Integration");
2995 else if (screen_nr == 3)
2997 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2998 "Special thanks to");
2999 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3000 "Hiroyuki Imabayashi");
3001 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3003 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3005 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3007 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3009 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3011 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3014 else if (screen_nr == 4)
3016 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3017 "Special thanks to");
3018 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3020 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3022 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3023 "J\xfcrgen Bonhagen");
3024 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3025 "for the continuous creation");
3026 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3027 "of outstanding level sets");
3029 else if (screen_nr == 5)
3031 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3033 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3035 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3036 "for ideas and inspiration by");
3037 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3040 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3042 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3044 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3045 "for ideas and inspiration by");
3046 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3049 else if (screen_nr == 6)
3051 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3053 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3056 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3057 "for the code base used for the");
3058 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3059 "native Emerald Mine engine");
3061 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3062 "for the new Emerald Mine engine");
3065 else if (screen_nr == 7)
3067 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3069 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3071 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3072 "for the initial DOS port");
3074 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3076 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3078 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3079 "for some additional toons");
3081 else if (screen_nr == 8)
3083 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3084 "And not to forget:");
3085 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3087 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3088 "All those who contributed");
3089 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3090 "levels to this game");
3091 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3095 DrawTextSCentered(ybottom, FONT_TEXT_4,
3096 "Press any key or button for next page");
3099 void DrawInfoScreen_Credits()
3101 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3103 FadeSoundsAndMusic();
3105 FadeOut(REDRAW_FIELD);
3107 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3109 FadeIn(REDRAW_FIELD);
3112 void HandleInfoScreen_Credits(int button)
3114 static int screen_nr = 0;
3115 int num_screens = 9;
3117 if (button == MB_MENU_INITIALIZE)
3121 // DrawInfoScreen_CreditsScreen(screen_nr);
3124 if (button == MB_MENU_LEAVE)
3126 PlaySound(SND_MENU_ITEM_SELECTING);
3128 info_mode = INFO_MODE_MAIN;
3133 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3135 if (button != MB_MENU_INITIALIZE)
3137 PlaySound(SND_MENU_ITEM_SELECTING);
3142 if (screen_nr >= num_screens)
3144 FadeSoundsAndMusic();
3146 info_mode = INFO_MODE_MAIN;
3153 FadeSetNextScreen();
3155 if (button != MB_MENU_INITIALIZE)
3156 FadeOut(REDRAW_FIELD);
3158 DrawInfoScreen_CreditsScreen(screen_nr);
3160 if (button != MB_MENU_INITIALIZE)
3161 FadeIn(REDRAW_FIELD);
3165 PlayMenuSoundIfLoop();
3169 void DrawInfoScreen_Program()
3171 int ystart1 = mSY - SY + 100;
3172 int ystart2 = mSY - SY + 150;
3173 int ybottom = mSY - SY + SYSIZE - 20;
3176 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3178 FadeOut(REDRAW_FIELD);
3183 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3185 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3186 "This game is Freeware!");
3187 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3188 "If you like it, send e-mail to:");
3189 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3190 setup.internal.program_email);
3191 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3192 "More information and levels:");
3193 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3194 setup.internal.program_website);
3195 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3196 "If you have created new levels,");
3197 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3198 "send them to me to include them!");
3199 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3202 DrawTextSCentered(ybottom, FONT_TEXT_4,
3203 "Press any key or button for info menu");
3205 FadeIn(REDRAW_FIELD);
3208 void HandleInfoScreen_Program(int button)
3210 if (button == MB_MENU_LEAVE)
3212 PlaySound(SND_MENU_ITEM_SELECTING);
3214 info_mode = INFO_MODE_MAIN;
3219 else if (button == MB_MENU_CHOICE)
3221 PlaySound(SND_MENU_ITEM_SELECTING);
3223 FadeSoundsAndMusic();
3225 info_mode = INFO_MODE_MAIN;
3230 PlayMenuSoundIfLoop();
3234 void DrawInfoScreen_Version()
3236 int font_header = FONT_TEXT_3;
3237 int font_text = FONT_TEXT_2;
3238 int xstep = getFontWidth(font_text);
3239 int ystep = getFontHeight(font_text);
3240 int ystart1 = mSY - SY + 100;
3241 int ystart2 = mSY - SY + 150;
3242 int ybottom = mSY - SY + SYSIZE - 20;
3243 int xstart1 = mSX - SX + 2 * xstep;
3244 int xstart2 = mSX - SX + 18 * xstep;
3245 int xstart3 = mSX - SX + 28 * xstep;
3246 SDL_version sdl_version_compiled;
3247 const SDL_version *sdl_version_linked;
3248 int driver_name_len = 10;
3249 #if defined(TARGET_SDL2)
3250 SDL_version sdl_version_linked_ext;
3251 const char *driver_name = NULL;
3253 char driver_name[driver_name_len];
3256 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3258 FadeOut(REDRAW_FIELD);
3263 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3265 DrawTextF(xstart1, ystart2, font_header, "Name");
3266 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3269 DrawTextF(xstart1, ystart2, font_header, "Version");
3270 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3273 DrawTextF(xstart1, ystart2, font_header, "Platform");
3274 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3277 DrawTextF(xstart1, ystart2, font_header, "Target");
3278 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3281 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3282 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3284 ystart2 += 3 * ystep;
3285 DrawTextF(xstart1, ystart2, font_header, "Library");
3286 DrawTextF(xstart2, ystart2, font_header, "compiled");
3287 DrawTextF(xstart3, ystart2, font_header, "linked");
3289 SDL_VERSION(&sdl_version_compiled);
3290 #if defined(TARGET_SDL2)
3291 SDL_GetVersion(&sdl_version_linked_ext);
3292 sdl_version_linked = &sdl_version_linked_ext;
3294 sdl_version_linked = SDL_Linked_Version();
3297 ystart2 += 2 * ystep;
3298 DrawTextF(xstart1, ystart2, font_text, "SDL");
3299 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3300 sdl_version_compiled.major,
3301 sdl_version_compiled.minor,
3302 sdl_version_compiled.patch);
3303 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3304 sdl_version_linked->major,
3305 sdl_version_linked->minor,
3306 sdl_version_linked->patch);
3308 SDL_IMAGE_VERSION(&sdl_version_compiled);
3309 sdl_version_linked = IMG_Linked_Version();
3312 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3313 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3314 sdl_version_compiled.major,
3315 sdl_version_compiled.minor,
3316 sdl_version_compiled.patch);
3317 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3318 sdl_version_linked->major,
3319 sdl_version_linked->minor,
3320 sdl_version_linked->patch);
3322 SDL_MIXER_VERSION(&sdl_version_compiled);
3323 sdl_version_linked = Mix_Linked_Version();
3326 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3327 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3328 sdl_version_compiled.major,
3329 sdl_version_compiled.minor,
3330 sdl_version_compiled.patch);
3331 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3332 sdl_version_linked->major,
3333 sdl_version_linked->minor,
3334 sdl_version_linked->patch);
3336 SDL_NET_VERSION(&sdl_version_compiled);
3337 sdl_version_linked = SDLNet_Linked_Version();
3340 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3341 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3342 sdl_version_compiled.major,
3343 sdl_version_compiled.minor,
3344 sdl_version_compiled.patch);
3345 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3346 sdl_version_linked->major,
3347 sdl_version_linked->minor,
3348 sdl_version_linked->patch);
3350 ystart2 += 3 * ystep;
3351 DrawTextF(xstart1, ystart2, font_header, "Driver");
3352 DrawTextF(xstart2, ystart2, font_header, "Requested");
3353 DrawTextF(xstart3, ystart2, font_header, "Used");
3355 #if defined(TARGET_SDL2)
3356 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3358 SDL_VideoDriverName(driver_name, driver_name_len);
3361 ystart2 += 2 * ystep;
3362 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3363 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3364 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3366 #if defined(TARGET_SDL2)
3367 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3369 SDL_AudioDriverName(driver_name, driver_name_len);
3373 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3374 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3375 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3377 DrawTextSCentered(ybottom, FONT_TEXT_4,
3378 "Press any key or button for info menu");
3380 FadeIn(REDRAW_FIELD);
3383 void HandleInfoScreen_Version(int button)
3385 if (button == MB_MENU_LEAVE)
3387 PlaySound(SND_MENU_ITEM_SELECTING);
3389 info_mode = INFO_MODE_MAIN;
3394 else if (button == MB_MENU_CHOICE)
3396 PlaySound(SND_MENU_ITEM_SELECTING);
3398 FadeSoundsAndMusic();
3400 info_mode = INFO_MODE_MAIN;
3405 PlayMenuSoundIfLoop();
3409 void DrawInfoScreen_LevelSet()
3411 struct TitleMessageInfo *tmi = &readme;
3412 char *filename = getLevelSetInfoFilename();
3413 char *title = "Level Set Information:";
3414 int ystart1 = mSY - SY + 100;
3415 int ybottom = mSY - SY + SYSIZE - 20;
3417 if (filename == NULL)
3419 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3424 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3426 FadeOut(REDRAW_FIELD);
3431 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3433 /* if x position set to "-1", automatically determine by playfield width */
3435 tmi->x = SXSIZE / 2;
3437 /* if y position set to "-1", use static default value */
3441 /* if width set to "-1", automatically determine by playfield width */
3442 if (tmi->width == -1)
3443 tmi->width = SXSIZE - 2 * TILEX;
3445 /* if height set to "-1", automatically determine by playfield height */
3446 if (tmi->height == -1)
3447 tmi->height = SYSIZE - 20 - tmi->y - 10;
3449 /* if chars set to "-1", automatically determine by text and font width */
3450 if (tmi->chars == -1)
3451 tmi->chars = tmi->width / getFontWidth(tmi->font);
3453 tmi->width = tmi->chars * getFontWidth(tmi->font);
3455 /* if lines set to "-1", automatically determine by text and font height */
3456 if (tmi->lines == -1)
3457 tmi->lines = tmi->height / getFontHeight(tmi->font);
3459 tmi->height = tmi->lines * getFontHeight(tmi->font);
3461 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3462 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3463 tmi->autowrap, tmi->centered, tmi->parse_comments);
3465 DrawTextSCentered(ybottom, FONT_TEXT_4,
3466 "Press any key or button for info menu");
3468 FadeIn(REDRAW_FIELD);
3471 void HandleInfoScreen_LevelSet(int button)
3473 if (button == MB_MENU_LEAVE)
3475 PlaySound(SND_MENU_ITEM_SELECTING);
3477 info_mode = INFO_MODE_MAIN;
3482 else if (button == MB_MENU_CHOICE)
3484 PlaySound(SND_MENU_ITEM_SELECTING);
3486 FadeSoundsAndMusic();
3488 info_mode = INFO_MODE_MAIN;
3493 PlayMenuSoundIfLoop();
3497 static void DrawInfoScreen()
3499 if (info_mode == INFO_MODE_TITLE)
3500 DrawInfoScreen_TitleScreen();
3501 else if (info_mode == INFO_MODE_ELEMENTS)
3502 DrawInfoScreen_Elements();
3503 else if (info_mode == INFO_MODE_MUSIC)
3504 DrawInfoScreen_Music();
3505 else if (info_mode == INFO_MODE_CREDITS)
3506 DrawInfoScreen_Credits();
3507 else if (info_mode == INFO_MODE_PROGRAM)
3508 DrawInfoScreen_Program();
3509 else if (info_mode == INFO_MODE_VERSION)
3510 DrawInfoScreen_Version();
3511 else if (info_mode == INFO_MODE_LEVELSET)
3512 DrawInfoScreen_LevelSet();
3514 DrawInfoScreen_Main();
3516 if (info_mode != INFO_MODE_MAIN &&
3517 info_mode != INFO_MODE_TITLE &&
3518 info_mode != INFO_MODE_MUSIC)
3525 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3527 if (info_mode == INFO_MODE_TITLE)
3528 HandleInfoScreen_TitleScreen(button);
3529 else if (info_mode == INFO_MODE_ELEMENTS)
3530 HandleInfoScreen_Elements(button);
3531 else if (info_mode == INFO_MODE_MUSIC)
3532 HandleInfoScreen_Music(button);
3533 else if (info_mode == INFO_MODE_CREDITS)
3534 HandleInfoScreen_Credits(button);
3535 else if (info_mode == INFO_MODE_PROGRAM)
3536 HandleInfoScreen_Program(button);
3537 else if (info_mode == INFO_MODE_VERSION)
3538 HandleInfoScreen_Version(button);
3539 else if (info_mode == INFO_MODE_LEVELSET)
3540 HandleInfoScreen_LevelSet(button);
3542 HandleInfoScreen_Main(mx, my, dx, dy, button);
3546 /* ========================================================================= */
3547 /* type name functions */
3548 /* ========================================================================= */
3550 void HandleTypeName(int newxpos, Key key)
3552 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3553 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3554 struct TextPosInfo *pos = mci->pos_input;
3555 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3556 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3557 static int xpos = 0;
3558 int font_nr = pos->font;
3559 int font_active_nr = FONT_ACTIVE(font_nr);
3560 int font_width = getFontWidth(font_active_nr);
3561 char key_char = getValidConfigValueChar(getCharFromKey(key));
3562 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3563 boolean is_active = TRUE;
3565 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3569 strcpy(last_player_name, setup.player_name);
3573 #if defined(TARGET_SDL2)
3574 SDL_StartTextInput();
3577 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3579 setup.player_name[xpos] = key_char;
3580 setup.player_name[xpos + 1] = 0;
3584 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3588 setup.player_name[xpos] = 0;
3590 else if (key == KSYM_Return && xpos > 0)
3596 SetGameStatus(GAME_MODE_MAIN);
3598 else if (key == KSYM_Escape)
3600 strcpy(setup.player_name, last_player_name);
3604 SetGameStatus(GAME_MODE_MAIN);
3609 pos->width = (strlen(setup.player_name) + 1) * font_width;
3610 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3612 DrawText(startx, starty, setup.player_name, font_active_nr);
3613 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3617 pos->width = strlen(setup.player_name) * font_width;
3618 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3620 DrawText(startx, starty, setup.player_name, font_nr);
3622 #if defined(TARGET_SDL2)
3623 SDL_StopTextInput();
3629 /* ========================================================================= */
3630 /* tree menu functions */
3631 /* ========================================================================= */
3633 static void DrawChooseTree(TreeInfo **ti_ptr)
3635 int fade_mask = REDRAW_FIELD;
3637 if (CheckIfGlobalBorderHasChanged())
3638 fade_mask = REDRAW_ALL;
3640 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3642 SetGameStatus(GAME_MODE_MAIN);
3651 FreeScreenGadgets();
3652 CreateScreenGadgets();
3656 /* needed if different viewport properties defined for choosing level (set) */
3657 ChangeViewportPropertiesIfNeeded();
3659 SetMainBackgroundImage(game_status == GAME_MODE_LEVELNR ?
3660 IMG_BACKGROUND_LEVELNR :
3661 game_status == GAME_MODE_LEVELS ?
3662 IMG_BACKGROUND_LEVELS : IMG_BACKGROUND);
3665 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3667 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3668 MapScreenTreeGadgets(*ti_ptr);
3670 DrawMaskedBorder(fade_mask);
3675 static void drawChooseTreeList(int first_entry, int num_page_entries,
3679 char *title_string = NULL;
3680 int yoffset_sets = MENU_TITLE1_YPOS;
3681 int yoffset_setup = 16;
3682 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3683 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3685 title_string = ti->infotext;
3687 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3689 clearMenuListArea();
3691 for (i = 0; i < num_page_entries; i++)
3693 TreeInfo *node, *node_first;
3694 int entry_pos = first_entry + i;
3695 int xpos = MENU_SCREEN_START_XPOS;
3696 int ypos = MENU_SCREEN_START_YPOS + i;
3697 int startx = mSX + xpos * 32;
3698 int starty = mSY + ypos * 32;
3699 int font_nr = FONT_TEXT_1;
3700 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3701 int startx_text = startx + font_xoffset;
3702 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3703 int text_size = startx_scrollbar - startx_text;
3704 int max_buffer_len = text_size / getFontWidth(font_nr);
3705 char buffer[max_buffer_len + 1];
3707 node_first = getTreeInfoFirstGroupEntry(ti);
3708 node = getTreeInfoFromPos(node_first, entry_pos);
3710 strncpy(buffer, node->name, max_buffer_len);
3711 buffer[max_buffer_len] = '\0';
3713 DrawText(startx, starty, buffer, font_nr + node->color);
3715 if (node->parent_link)
3716 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3717 else if (node->level_group)
3718 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3720 initCursor(i, IMG_MENU_BUTTON);
3723 redraw_mask |= REDRAW_FIELD;
3726 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3728 TreeInfo *node, *node_first;
3729 int x, last_redraw_mask = redraw_mask;
3730 int ypos = MENU_TITLE2_YPOS;
3731 int font_nr = FONT_TITLE_2;
3733 if (ti->type == TREE_TYPE_LEVEL_NR)
3734 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3736 if (ti->type != TREE_TYPE_LEVEL_DIR)
3739 node_first = getTreeInfoFirstGroupEntry(ti);
3740 node = getTreeInfoFromPos(node_first, entry_pos);
3742 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3744 if (node->parent_link)
3745 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3746 node->node_parent->name);
3747 else if (node->level_group)
3748 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3750 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3751 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3752 node->levels, (node->levels > 1 ? "levels" : "level"),
3755 /* let BackToFront() redraw only what is needed */
3756 redraw_mask = last_redraw_mask;
3757 for (x = 0; x < SCR_FIELDX; x++)
3758 MarkTileDirty(x, 1);
3761 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3764 TreeInfo *ti = *ti_ptr;
3766 int y = ti->cl_cursor;
3767 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3768 int num_entries = numTreeInfoInGroup(ti);
3769 int num_page_entries;
3770 boolean position_set_by_scrollbar = (dx == 999);
3772 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3773 num_page_entries = num_entries;
3775 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3777 if (button == MB_MENU_INITIALIZE)
3779 int num_entries = numTreeInfoInGroup(ti);
3780 int entry_pos = posTreeInfo(ti);
3782 if (ti->cl_first == -1)
3784 /* only on initialization */
3785 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3786 ti->cl_cursor = entry_pos - ti->cl_first;
3788 else if (ti->cl_cursor >= num_page_entries ||
3789 (num_entries > num_page_entries &&
3790 num_entries - ti->cl_first < num_page_entries))
3792 /* only after change of list size (by custom graphic configuration) */
3793 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3794 ti->cl_cursor = entry_pos - ti->cl_first;
3797 if (position_set_by_scrollbar)
3800 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3803 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3804 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3805 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3809 else if (button == MB_MENU_LEAVE)
3813 PlaySound(SND_MENU_ITEM_SELECTING);
3815 if (ti->node_parent)
3817 *ti_ptr = ti->node_parent;
3818 DrawChooseTree(ti_ptr);
3820 else if (game_status == GAME_MODE_SETUP)
3822 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3823 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3824 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3826 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3827 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
3828 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
3829 execSetupGraphics();
3830 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3831 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3832 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3834 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3835 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3836 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3843 if (game_status == GAME_MODE_LEVELNR)
3845 int new_level_nr = atoi(level_number_current->identifier);
3847 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3850 SetGameStatus(GAME_MODE_MAIN);
3858 if (mx || my) /* mouse input */
3860 x = (mx - mSX) / 32;
3861 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3863 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3865 /* move cursor instead of scrolling when already at start/end of list */
3866 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3868 else if (dy == +1 * SCROLL_LINE &&
3869 ti->cl_first + num_page_entries == num_entries)
3872 /* handle scrolling screen one line or page */
3873 if (ti->cl_cursor + dy < 0 ||
3874 ti->cl_cursor + dy > num_page_entries - 1)
3876 boolean redraw = FALSE;
3878 if (ABS(dy) == SCROLL_PAGE)
3879 step = num_page_entries - 1;
3881 if (dy < 0 && ti->cl_first > 0)
3883 /* scroll page/line up */
3885 ti->cl_first -= step;
3886 if (ti->cl_first < 0)
3891 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3893 /* scroll page/line down */
3895 ti->cl_first += step;
3896 if (ti->cl_first + num_page_entries > num_entries)
3897 ti->cl_first = MAX(0, num_entries - num_page_entries);
3904 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3905 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3906 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3908 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3915 /* handle moving cursor one line */
3916 y = ti->cl_cursor + dy;
3921 TreeInfo *node_first, *node_cursor;
3922 int entry_pos = ti->cl_first + y;
3924 node_first = getTreeInfoFirstGroupEntry(ti);
3925 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3927 if (node_cursor->node_group)
3931 PlaySound(SND_MENU_ITEM_SELECTING);
3933 node_cursor->cl_first = ti->cl_first;
3934 node_cursor->cl_cursor = ti->cl_cursor;
3935 *ti_ptr = node_cursor->node_group;
3936 DrawChooseTree(ti_ptr);
3941 else if (dx == -1 && ti->node_parent)
3945 PlaySound(SND_MENU_ITEM_SELECTING);
3947 *ti_ptr = ti->node_parent;
3948 DrawChooseTree(ti_ptr);
3953 if (!anyScrollbarGadgetActive() &&
3954 IN_VIS_MENU(x, y) &&
3955 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3956 y >= 0 && y < num_page_entries)
3960 if (y != ti->cl_cursor)
3962 PlaySound(SND_MENU_ITEM_ACTIVATING);
3964 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3965 drawChooseTreeCursor(y, TRUE);
3966 drawChooseTreeInfo(ti->cl_first + y, ti);
3973 TreeInfo *node_first, *node_cursor;
3974 int entry_pos = ti->cl_first + y;
3976 PlaySound(SND_MENU_ITEM_SELECTING);
3978 node_first = getTreeInfoFirstGroupEntry(ti);
3979 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3981 if (node_cursor->node_group)
3985 node_cursor->cl_first = ti->cl_first;
3986 node_cursor->cl_cursor = ti->cl_cursor;
3987 *ti_ptr = node_cursor->node_group;
3988 DrawChooseTree(ti_ptr);
3990 else if (node_cursor->parent_link)
3994 *ti_ptr = node_cursor->node_parent;
3995 DrawChooseTree(ti_ptr);
4001 node_cursor->cl_first = ti->cl_first;
4002 node_cursor->cl_cursor = ti->cl_cursor;
4003 *ti_ptr = node_cursor;
4005 if (ti->type == TREE_TYPE_LEVEL_DIR)
4007 LoadLevelSetup_SeriesInfo();
4009 SaveLevelSetup_LastSeries();
4010 SaveLevelSetup_SeriesInfo();
4014 if (game_status == GAME_MODE_SETUP)
4016 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4017 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4018 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4020 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4021 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4022 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4023 execSetupGraphics();
4024 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4025 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4026 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4028 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4029 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4030 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4037 if (game_status == GAME_MODE_LEVELNR)
4039 int new_level_nr = atoi(level_number_current->identifier);
4041 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4044 SetGameStatus(GAME_MODE_MAIN);
4053 void DrawChooseLevelSet()
4055 FadeSoundsAndMusic();
4057 DrawChooseTree(&leveldir_current);
4063 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4065 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4068 void DrawChooseLevelNr()
4072 FadeSoundsAndMusic();
4074 if (level_number != NULL)
4076 freeTreeInfo(level_number);
4078 level_number = NULL;
4081 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4083 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4084 char identifier[32], name[32];
4087 /* temporarily load level info to get level name */
4088 LoadLevelInfoOnly(i);
4090 ti->node_top = &level_number;
4091 ti->sort_priority = 10000 + value;
4092 ti->color = (level.no_valid_file ? FC_BLUE :
4093 LevelStats_getSolved(i) ? FC_GREEN :
4094 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4096 sprintf(identifier, "%d", value);
4097 sprintf(name, "%03d: %s", value,
4098 (level.no_valid_file ? "(no file)" : level.name));
4100 setString(&ti->identifier, identifier);
4101 setString(&ti->name, name);
4102 setString(&ti->name_sorting, name);
4104 pushTreeInfo(&level_number, ti);
4107 /* sort level number values to start with lowest level number */
4108 sortTreeInfo(&level_number);
4110 /* set current level number to current level number */
4111 level_number_current =
4112 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4114 /* if that also fails, set current level number to first available level */
4115 if (level_number_current == NULL)
4116 level_number_current = level_number;
4118 DrawChooseTree(&level_number_current);
4124 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4126 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4129 void DrawHallOfFame(int highlight_position)
4131 int fade_mask = REDRAW_FIELD;
4133 if (CheckIfGlobalBorderHasChanged())
4134 fade_mask = REDRAW_ALL;
4137 FadeSoundsAndMusic();
4139 /* (this is needed when called from GameEnd() after winning a game) */
4140 KeyboardAutoRepeatOn();
4143 /* (this is needed when called from GameEnd() after winning a game) */
4144 SetDrawDeactivationMask(REDRAW_NONE);
4145 SetDrawBackgroundMask(REDRAW_FIELD);
4147 if (highlight_position < 0)
4148 LoadScore(level_nr);
4150 FadeSetEnterScreen();
4154 /* needed if different viewport properties defined for scores */
4155 ChangeViewportPropertiesIfNeeded();
4160 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4162 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4164 DrawMaskedBorder(fade_mask);
4169 static void drawHallOfFameList(int first_entry, int highlight_position)
4173 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4176 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4177 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4178 "HighScores of Level %d", level_nr);
4180 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4182 int entry = first_entry + i;
4183 boolean active = (entry == highlight_position);
4184 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4185 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4186 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4187 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4188 int dxoff = getFontDrawOffsetX(font_nr1);
4189 int dx1 = 3 * getFontWidth(font_nr1);
4190 int dx2 = dx1 + getFontWidth(font_nr1);
4191 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4192 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4193 int sy = mSY + 64 + i * 32;
4195 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4196 DrawText(mSX + dx1, sy, ".", font_nr1);
4198 for (j = 0; j < num_dots; j++)
4199 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4201 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4202 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4204 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4207 redraw_mask |= REDRAW_FIELD;
4210 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4212 static int first_entry = 0;
4213 static int highlight_position = 0;
4214 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4216 if (button == MB_MENU_INITIALIZE)
4219 highlight_position = mx;
4220 drawHallOfFameList(first_entry, highlight_position);
4225 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4226 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4230 if (first_entry > 0)
4232 first_entry -= step;
4233 if (first_entry < 0)
4236 drawHallOfFameList(first_entry, highlight_position);
4241 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4243 first_entry += step;
4244 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4245 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4247 drawHallOfFameList(first_entry, highlight_position);
4250 else if (button == MB_MENU_LEAVE)
4252 PlaySound(SND_MENU_ITEM_SELECTING);
4254 FadeSound(SND_BACKGROUND_SCORES);
4256 SetGameStatus(GAME_MODE_MAIN);
4260 else if (button == MB_MENU_CHOICE)
4262 PlaySound(SND_MENU_ITEM_SELECTING);
4264 FadeSound(SND_BACKGROUND_SCORES);
4266 SetGameStatus(GAME_MODE_MAIN);
4271 if (game_status == GAME_MODE_SCORES)
4272 PlayMenuSoundIfLoop();
4276 /* ========================================================================= */
4277 /* setup screen functions */
4278 /* ========================================================================= */
4280 static struct TokenInfo *setup_info;
4281 static int num_setup_info; /* number of setup entries shown on screen */
4282 static int max_setup_info; /* total number of setup entries in list */
4284 static char *window_size_text;
4285 static char *scaling_type_text;
4286 static char *rendering_mode_text;
4287 static char *scroll_delay_text;
4288 static char *snapshot_mode_text;
4289 static char *game_speed_text;
4290 static char *graphics_set_name;
4291 static char *sounds_set_name;
4292 static char *music_set_name;
4293 static char *volume_simple_text;
4294 static char *volume_loops_text;
4295 static char *volume_music_text;
4296 static char *touch_controls_text;
4297 static char *move_distance_text;
4298 static char *drop_distance_text;
4300 static void execSetupMain()
4302 setup_mode = SETUP_MODE_MAIN;
4307 static void execSetupGame_setGameSpeeds()
4309 if (game_speeds == NULL)
4313 for (i = 0; game_speeds_list[i].value != -1; i++)
4315 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4316 char identifier[32], name[32];
4317 int value = game_speeds_list[i].value;
4318 char *text = game_speeds_list[i].text;
4320 ti->node_top = &game_speeds;
4321 ti->sort_priority = 10000 - value;
4323 sprintf(identifier, "%d", value);
4324 sprintf(name, "%s", text);
4326 setString(&ti->identifier, identifier);
4327 setString(&ti->name, name);
4328 setString(&ti->name_sorting, name);
4329 setString(&ti->infotext, "Game Speed");
4331 pushTreeInfo(&game_speeds, ti);
4334 /* sort game speed values to start with slowest game speed */
4335 sortTreeInfo(&game_speeds);
4337 /* set current game speed to configured game speed value */
4338 game_speed_current =
4339 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4341 /* if that fails, set current game speed to reliable default value */
4342 if (game_speed_current == NULL)
4343 game_speed_current =
4344 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4346 /* if that also fails, set current game speed to first available speed */
4347 if (game_speed_current == NULL)
4348 game_speed_current = game_speeds;
4351 setup.game_frame_delay = atoi(game_speed_current->identifier);
4353 /* needed for displaying game speed text instead of identifier */
4354 game_speed_text = game_speed_current->name;
4357 static void execSetupGame_setScrollDelays()
4359 if (scroll_delays == NULL)
4363 for (i = 0; scroll_delays_list[i].value != -1; i++)
4365 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4366 char identifier[32], name[32];
4367 int value = scroll_delays_list[i].value;
4368 char *text = scroll_delays_list[i].text;
4370 ti->node_top = &scroll_delays;
4371 ti->sort_priority = value;
4373 sprintf(identifier, "%d", value);
4374 sprintf(name, "%s", text);
4376 setString(&ti->identifier, identifier);
4377 setString(&ti->name, name);
4378 setString(&ti->name_sorting, name);
4379 setString(&ti->infotext, "Scroll Delay");
4381 pushTreeInfo(&scroll_delays, ti);
4384 /* sort scroll delay values to start with lowest scroll delay value */
4385 sortTreeInfo(&scroll_delays);
4387 /* set current scroll delay value to configured scroll delay value */
4388 scroll_delay_current =
4389 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4391 /* if that fails, set current scroll delay to reliable default value */
4392 if (scroll_delay_current == NULL)
4393 scroll_delay_current =
4394 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4396 /* if that also fails, set current scroll delay to first available value */
4397 if (scroll_delay_current == NULL)
4398 scroll_delay_current = scroll_delays;
4401 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4403 /* needed for displaying scroll delay text instead of identifier */
4404 scroll_delay_text = scroll_delay_current->name;
4407 static void execSetupGame_setSnapshotModes()
4409 if (snapshot_modes == NULL)
4413 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4415 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4416 char identifier[32], name[32];
4417 char *value = snapshot_modes_list[i].value;
4418 char *text = snapshot_modes_list[i].text;
4420 ti->node_top = &snapshot_modes;
4421 ti->sort_priority = i;
4423 sprintf(identifier, "%s", value);
4424 sprintf(name, "%s", text);
4426 setString(&ti->identifier, identifier);
4427 setString(&ti->name, name);
4428 setString(&ti->name_sorting, name);
4429 setString(&ti->infotext, "Snapshot Mode");
4431 pushTreeInfo(&snapshot_modes, ti);
4434 /* sort snapshot mode values to start with lowest snapshot mode value */
4435 sortTreeInfo(&snapshot_modes);
4437 /* set current snapshot mode value to configured snapshot mode value */
4438 snapshot_mode_current =
4439 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4441 /* if that fails, set current snapshot mode to reliable default value */
4442 if (snapshot_mode_current == NULL)
4443 snapshot_mode_current =
4444 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4446 /* if that also fails, set current snapshot mode to first available value */
4447 if (snapshot_mode_current == NULL)
4448 snapshot_mode_current = snapshot_modes;
4451 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4453 /* needed for displaying snapshot mode text instead of identifier */
4454 snapshot_mode_text = snapshot_mode_current->name;
4457 static void execSetupGame()
4459 execSetupGame_setGameSpeeds();
4460 execSetupGame_setScrollDelays();
4461 execSetupGame_setSnapshotModes();
4463 setup_mode = SETUP_MODE_GAME;
4468 static void execSetupChooseGameSpeed()
4470 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4475 static void execSetupChooseScrollDelay()
4477 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4482 static void execSetupChooseSnapshotMode()
4484 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4489 static void execSetupEditor()
4491 setup_mode = SETUP_MODE_EDITOR;
4496 static void execSetupGraphics_setWindowSizes(boolean update_list)
4498 if (window_sizes != NULL && update_list)
4500 freeTreeInfo(window_sizes);
4502 window_sizes = NULL;
4505 if (window_sizes == NULL)
4507 boolean current_window_size_found = FALSE;
4510 for (i = 0; window_sizes_list[i].value != -1; i++)
4512 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4513 char identifier[32], name[32];
4514 int value = window_sizes_list[i].value;
4515 char *text = window_sizes_list[i].text;
4517 ti->node_top = &window_sizes;
4518 ti->sort_priority = value;
4520 sprintf(identifier, "%d", value);
4521 sprintf(name, "%s", text);
4523 setString(&ti->identifier, identifier);
4524 setString(&ti->name, name);
4525 setString(&ti->name_sorting, name);
4526 setString(&ti->infotext, "Window Scaling");
4528 pushTreeInfo(&window_sizes, ti);
4530 if (value == setup.window_scaling_percent)
4531 current_window_size_found = TRUE;
4534 if (!current_window_size_found)
4536 // add entry for non-preset window scaling value
4538 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4539 char identifier[32], name[32];
4540 int value = setup.window_scaling_percent;
4542 ti->node_top = &window_sizes;
4543 ti->sort_priority = value;
4545 sprintf(identifier, "%d", value);
4546 sprintf(name, "%d %% (Current)", value);
4548 setString(&ti->identifier, identifier);
4549 setString(&ti->name, name);
4550 setString(&ti->name_sorting, name);
4551 setString(&ti->infotext, "Window Scaling");
4553 pushTreeInfo(&window_sizes, ti);
4556 /* sort window size values to start with lowest window size value */
4557 sortTreeInfo(&window_sizes);
4559 /* set current window size value to configured window size value */
4560 window_size_current =
4561 getTreeInfoFromIdentifier(window_sizes,
4562 i_to_a(setup.window_scaling_percent));
4564 /* if that fails, set current window size to reliable default value */
4565 if (window_size_current == NULL)
4566 window_size_current =
4567 getTreeInfoFromIdentifier(window_sizes,
4568 i_to_a(STD_WINDOW_SCALING_PERCENT));
4570 /* if that also fails, set current window size to first available value */
4571 if (window_size_current == NULL)
4572 window_size_current = window_sizes;
4575 setup.window_scaling_percent = atoi(window_size_current->identifier);
4577 /* needed for displaying window size text instead of identifier */
4578 window_size_text = window_size_current->name;
4581 static void execSetupGraphics_setScalingTypes()
4583 if (scaling_types == NULL)
4587 for (i = 0; scaling_types_list[i].value != NULL; i++)
4589 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4590 char identifier[32], name[32];
4591 char *value = scaling_types_list[i].value;
4592 char *text = scaling_types_list[i].text;
4594 ti->node_top = &scaling_types;
4595 ti->sort_priority = i;
4597 sprintf(identifier, "%s", value);
4598 sprintf(name, "%s", text);
4600 setString(&ti->identifier, identifier);
4601 setString(&ti->name, name);
4602 setString(&ti->name_sorting, name);
4603 setString(&ti->infotext, "Anti-Aliasing");
4605 pushTreeInfo(&scaling_types, ti);
4608 /* sort scaling type values to start with lowest scaling type value */
4609 sortTreeInfo(&scaling_types);
4611 /* set current scaling type value to configured scaling type value */
4612 scaling_type_current =
4613 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4615 /* if that fails, set current scaling type to reliable default value */
4616 if (scaling_type_current == NULL)
4617 scaling_type_current =
4618 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4620 /* if that also fails, set current scaling type to first available value */
4621 if (scaling_type_current == NULL)
4622 scaling_type_current = scaling_types;
4625 setup.window_scaling_quality = scaling_type_current->identifier;
4627 /* needed for displaying scaling type text instead of identifier */
4628 scaling_type_text = scaling_type_current->name;
4631 static void execSetupGraphics_setRenderingModes()
4633 if (rendering_modes == NULL)
4637 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4639 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4640 char identifier[32], name[32];
4641 char *value = rendering_modes_list[i].value;
4642 char *text = rendering_modes_list[i].text;
4644 ti->node_top = &rendering_modes;
4645 ti->sort_priority = i;
4647 sprintf(identifier, "%s", value);
4648 sprintf(name, "%s", text);
4650 setString(&ti->identifier, identifier);
4651 setString(&ti->name, name);
4652 setString(&ti->name_sorting, name);
4653 setString(&ti->infotext, "Special Rendering");
4655 pushTreeInfo(&rendering_modes, ti);
4658 /* sort rendering mode values to start with lowest rendering mode value */
4659 sortTreeInfo(&rendering_modes);
4661 /* set current rendering mode value to configured rendering mode value */
4662 rendering_mode_current =
4663 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4665 /* if that fails, set current rendering mode to reliable default value */
4666 if (rendering_mode_current == NULL)
4667 rendering_mode_current =
4668 getTreeInfoFromIdentifier(rendering_modes,
4669 STR_SPECIAL_RENDERING_DEFAULT);
4671 /* if that also fails, set current rendering mode to first available one */
4672 if (rendering_mode_current == NULL)
4673 rendering_mode_current = rendering_modes;
4676 setup.screen_rendering_mode = rendering_mode_current->identifier;
4678 /* needed for displaying rendering mode text instead of identifier */
4679 rendering_mode_text = rendering_mode_current->name;
4682 static void execSetupGraphics()
4684 // update "setup.window_scaling_percent" from list selection
4685 // (in this case, window scaling was changed on setup screen)
4686 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4687 execSetupGraphics_setWindowSizes(FALSE);
4689 // update list selection from "setup.window_scaling_percent"
4690 // (window scaling may have changed by resizing the window)
4691 execSetupGraphics_setWindowSizes(TRUE);
4693 execSetupGraphics_setScalingTypes();
4694 execSetupGraphics_setRenderingModes();
4696 setup_mode = SETUP_MODE_GRAPHICS;
4700 #if defined(TARGET_SDL2)
4701 // window scaling may have changed at this point
4702 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4704 // window scaling quality may have changed at this point
4705 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4706 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4708 // screen rendering mode may have changed at this point
4709 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4713 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4714 static void execSetupChooseWindowSize()
4716 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4721 static void execSetupChooseScalingType()
4723 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4728 static void execSetupChooseRenderingMode()
4730 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4736 static void execSetupChooseVolumeSimple()
4738 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4743 static void execSetupChooseVolumeLoops()
4745 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4750 static void execSetupChooseVolumeMusic()
4752 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4757 static void execSetupSound()
4759 if (volumes_simple == NULL)
4761 boolean current_volume_simple_found = FALSE;
4764 for (i = 0; volumes_list[i].value != -1; i++)
4766 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4767 char identifier[32], name[32];
4768 int value = volumes_list[i].value;
4769 char *text = volumes_list[i].text;
4771 ti->node_top = &volumes_simple;
4772 ti->sort_priority = value;
4774 sprintf(identifier, "%d", value);
4775 sprintf(name, "%s", text);
4777 setString(&ti->identifier, identifier);
4778 setString(&ti->name, name);
4779 setString(&ti->name_sorting, name);
4780 setString(&ti->infotext, "Sound Volume");
4782 pushTreeInfo(&volumes_simple, ti);
4784 if (value == setup.volume_simple)
4785 current_volume_simple_found = TRUE;
4788 if (!current_volume_simple_found)
4790 // add entry for non-preset volume value
4792 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4793 char identifier[32], name[32];
4794 int value = setup.volume_simple;
4796 ti->node_top = &volumes_simple;
4797 ti->sort_priority = value;
4799 sprintf(identifier, "%d", value);
4800 sprintf(name, "%d %% (Current)", value);
4802 setString(&ti->identifier, identifier);
4803 setString(&ti->name, name);
4804 setString(&ti->name_sorting, name);
4805 setString(&ti->infotext, "Sound Volume");
4807 pushTreeInfo(&volumes_simple, ti);
4810 /* sort volume values to start with lowest volume value */
4811 sortTreeInfo(&volumes_simple);
4813 /* set current volume value to configured volume value */
4814 volume_simple_current =
4815 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4817 /* if that fails, set current volume to reliable default value */
4818 if (volume_simple_current == NULL)
4819 volume_simple_current =
4820 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4822 /* if that also fails, set current volume to first available value */
4823 if (volume_simple_current == NULL)
4824 volume_simple_current = volumes_simple;
4827 if (volumes_loops == NULL)
4829 boolean current_volume_loops_found = FALSE;
4832 for (i = 0; volumes_list[i].value != -1; i++)
4834 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4835 char identifier[32], name[32];
4836 int value = volumes_list[i].value;
4837 char *text = volumes_list[i].text;
4839 ti->node_top = &volumes_loops;
4840 ti->sort_priority = value;
4842 sprintf(identifier, "%d", value);
4843 sprintf(name, "%s", text);
4845 setString(&ti->identifier, identifier);
4846 setString(&ti->name, name);
4847 setString(&ti->name_sorting, name);
4848 setString(&ti->infotext, "Loops Volume");
4850 pushTreeInfo(&volumes_loops, ti);
4852 if (value == setup.volume_loops)
4853 current_volume_loops_found = TRUE;
4856 if (!current_volume_loops_found)
4858 // add entry for non-preset volume value
4860 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4861 char identifier[32], name[32];
4862 int value = setup.volume_loops;
4864 ti->node_top = &volumes_loops;
4865 ti->sort_priority = value;
4867 sprintf(identifier, "%d", value);
4868 sprintf(name, "%d %% (Current)", value);
4870 setString(&ti->identifier, identifier);
4871 setString(&ti->name, name);
4872 setString(&ti->name_sorting, name);
4873 setString(&ti->infotext, "Loops Volume");
4875 pushTreeInfo(&volumes_loops, ti);
4878 /* sort volume values to start with lowest volume value */
4879 sortTreeInfo(&volumes_loops);
4881 /* set current volume value to configured volume value */
4882 volume_loops_current =
4883 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4885 /* if that fails, set current volume to reliable default value */
4886 if (volume_loops_current == NULL)
4887 volume_loops_current =
4888 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4890 /* if that also fails, set current volume to first available value */
4891 if (volume_loops_current == NULL)
4892 volume_loops_current = volumes_loops;
4895 if (volumes_music == NULL)
4897 boolean current_volume_music_found = FALSE;
4900 for (i = 0; volumes_list[i].value != -1; i++)
4902 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4903 char identifier[32], name[32];
4904 int value = volumes_list[i].value;
4905 char *text = volumes_list[i].text;
4907 ti->node_top = &volumes_music;
4908 ti->sort_priority = value;
4910 sprintf(identifier, "%d", value);
4911 sprintf(name, "%s", text);
4913 setString(&ti->identifier, identifier);
4914 setString(&ti->name, name);
4915 setString(&ti->name_sorting, name);
4916 setString(&ti->infotext, "Music Volume");
4918 pushTreeInfo(&volumes_music, ti);
4920 if (value == setup.volume_music)
4921 current_volume_music_found = TRUE;
4924 if (!current_volume_music_found)
4926 // add entry for non-preset volume value
4928 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4929 char identifier[32], name[32];
4930 int value = setup.volume_music;
4932 ti->node_top = &volumes_music;
4933 ti->sort_priority = value;
4935 sprintf(identifier, "%d", value);
4936 sprintf(name, "%d %% (Current)", value);
4938 setString(&ti->identifier, identifier);
4939 setString(&ti->name, name);
4940 setString(&ti->name_sorting, name);
4941 setString(&ti->infotext, "Music Volume");
4943 pushTreeInfo(&volumes_music, ti);
4946 /* sort volume values to start with lowest volume value */
4947 sortTreeInfo(&volumes_music);
4949 /* set current volume value to configured volume value */
4950 volume_music_current =
4951 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4953 /* if that fails, set current volume to reliable default value */
4954 if (volume_music_current == NULL)
4955 volume_music_current =
4956 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4958 /* if that also fails, set current volume to first available value */
4959 if (volume_music_current == NULL)
4960 volume_music_current = volumes_music;
4963 setup.volume_simple = atoi(volume_simple_current->identifier);
4964 setup.volume_loops = atoi(volume_loops_current->identifier);
4965 setup.volume_music = atoi(volume_music_current->identifier);
4967 /* needed for displaying volume text instead of identifier */
4968 volume_simple_text = volume_simple_current->name;
4969 volume_loops_text = volume_loops_current->name;
4970 volume_music_text = volume_music_current->name;
4972 setup_mode = SETUP_MODE_SOUND;
4977 static void execSetupChooseTouchControls()
4979 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4984 static void execSetupChooseMoveDistance()
4986 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4991 static void execSetupChooseDropDistance()
4993 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4998 static void execSetupTouch()
5000 if (touch_controls == NULL)
5004 for (i = 0; touch_controls_list[i].value != NULL; i++)
5006 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5007 char identifier[32], name[32];
5008 char *value = touch_controls_list[i].value;
5009 char *text = touch_controls_list[i].text;
5011 ti->node_top = &touch_controls;
5012 ti->sort_priority = i;
5014 sprintf(identifier, "%s", value);
5015 sprintf(name, "%s", text);
5017 setString(&ti->identifier, identifier);
5018 setString(&ti->name, name);
5019 setString(&ti->name_sorting, name);
5020 setString(&ti->infotext, "Control Type");
5022 pushTreeInfo(&touch_controls, ti);
5025 /* sort touch control values to start with lowest touch control value */
5026 sortTreeInfo(&touch_controls);
5028 /* set current touch control value to configured touch control value */
5029 touch_control_current =
5030 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5032 /* if that fails, set current touch control to reliable default value */
5033 if (touch_control_current == NULL)
5034 touch_control_current =
5035 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5037 /* if that also fails, set current touch control to first available value */
5038 if (touch_control_current == NULL)
5039 touch_control_current = touch_controls;
5042 if (move_distances == NULL)
5046 for (i = 0; distances_list[i].value != -1; i++)
5048 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5049 char identifier[32], name[32];
5050 int value = distances_list[i].value;
5051 char *text = distances_list[i].text;
5053 ti->node_top = &move_distances;
5054 ti->sort_priority = value;
5056 sprintf(identifier, "%d", value);
5057 sprintf(name, "%s", text);
5059 setString(&ti->identifier, identifier);
5060 setString(&ti->name, name);
5061 setString(&ti->name_sorting, name);
5062 setString(&ti->infotext, "Move Distance");
5064 pushTreeInfo(&move_distances, ti);
5067 /* sort distance values to start with lowest distance value */
5068 sortTreeInfo(&move_distances);
5070 /* set current distance value to configured distance value */
5071 move_distance_current =
5072 getTreeInfoFromIdentifier(move_distances,
5073 i_to_a(setup.touch.move_distance));
5075 /* if that fails, set current distance to reliable default value */
5076 if (move_distance_current == NULL)
5077 move_distance_current =
5078 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5080 /* if that also fails, set current distance to first available value */
5081 if (move_distance_current == NULL)
5082 move_distance_current = move_distances;
5085 if (drop_distances == NULL)
5089 for (i = 0; distances_list[i].value != -1; i++)
5091 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5092 char identifier[32], name[32];
5093 int value = distances_list[i].value;
5094 char *text = distances_list[i].text;
5096 ti->node_top = &drop_distances;
5097 ti->sort_priority = value;
5099 sprintf(identifier, "%d", value);
5100 sprintf(name, "%s", text);
5102 setString(&ti->identifier, identifier);
5103 setString(&ti->name, name);
5104 setString(&ti->name_sorting, name);
5105 setString(&ti->infotext, "Drop Distance");
5107 pushTreeInfo(&drop_distances, ti);
5110 /* sort distance values to start with lowest distance value */
5111 sortTreeInfo(&drop_distances);
5113 /* set current distance value to configured distance value */
5114 drop_distance_current =
5115 getTreeInfoFromIdentifier(drop_distances,
5116 i_to_a(setup.touch.drop_distance));
5118 /* if that fails, set current distance to reliable default value */
5119 if (drop_distance_current == NULL)
5120 drop_distance_current =
5121 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5123 /* if that also fails, set current distance to first available value */
5124 if (drop_distance_current == NULL)
5125 drop_distance_current = drop_distances;
5128 setup.touch.control_type = touch_control_current->identifier;
5129 setup.touch.move_distance = atoi(move_distance_current->identifier);
5130 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5132 /* needed for displaying volume text instead of identifier */
5133 touch_controls_text = touch_control_current->name;
5134 move_distance_text = move_distance_current->name;
5135 drop_distance_text = drop_distance_current->name;
5137 setup_mode = SETUP_MODE_TOUCH;
5142 static void execSetupArtwork()
5145 printf("::: '%s', '%s', '%s'\n",
5146 artwork.gfx_current->subdir,
5147 artwork.gfx_current->fullpath,
5148 artwork.gfx_current->basepath);
5151 setup.graphics_set = artwork.gfx_current->identifier;
5152 setup.sounds_set = artwork.snd_current->identifier;
5153 setup.music_set = artwork.mus_current->identifier;
5155 /* needed if last screen (setup choice) changed graphics, sounds or music */
5156 ReloadCustomArtwork(0);
5158 /* needed for displaying artwork name instead of artwork identifier */
5159 graphics_set_name = artwork.gfx_current->name;
5160 sounds_set_name = artwork.snd_current->name;
5161 music_set_name = artwork.mus_current->name;
5163 setup_mode = SETUP_MODE_ARTWORK;
5168 static void execSetupChooseGraphics()
5170 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5175 static void execSetupChooseSounds()
5177 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5182 static void execSetupChooseMusic()
5184 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5189 #if !defined(PLATFORM_ANDROID)
5190 static void execSetupInput()
5192 setup_mode = SETUP_MODE_INPUT;
5198 static void execSetupShortcuts()
5200 setup_mode = SETUP_MODE_SHORTCUTS;
5205 static void execSetupShortcuts1()
5207 setup_mode = SETUP_MODE_SHORTCUTS_1;
5212 static void execSetupShortcuts2()
5214 setup_mode = SETUP_MODE_SHORTCUTS_2;
5219 static void execSetupShortcuts3()
5221 setup_mode = SETUP_MODE_SHORTCUTS_3;
5226 static void execSetupShortcuts4()
5228 setup_mode = SETUP_MODE_SHORTCUTS_4;
5233 static void execSetupShortcuts5()
5235 setup_mode = SETUP_MODE_SHORTCUTS_5;
5240 static void execExitSetup()
5242 SetGameStatus(GAME_MODE_MAIN);
5247 static void execSaveAndExitSetup()
5253 static struct TokenInfo setup_info_main[] =
5255 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5256 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5257 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5258 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5259 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5260 #if !defined(PLATFORM_ANDROID)
5261 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5262 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5264 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5266 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5267 { TYPE_EMPTY, NULL, "" },
5268 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5269 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5274 static struct TokenInfo setup_info_game[] =
5276 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5277 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5278 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5279 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5280 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5281 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5282 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5283 { TYPE_STRING, &game_speed_text, "" },
5285 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5286 { TYPE_STRING, &scroll_delay_text, "" },
5288 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5289 { TYPE_STRING, &snapshot_mode_text, "" },
5290 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5291 { TYPE_EMPTY, NULL, "" },
5292 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5297 static struct TokenInfo setup_info_editor[] =
5300 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5301 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5302 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5303 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5304 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5305 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5306 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5307 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5309 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5310 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5311 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5313 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5315 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5316 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5317 { TYPE_EMPTY, NULL, "" },
5319 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5320 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5321 { TYPE_EMPTY, NULL, "" },
5323 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5324 { TYPE_EMPTY, NULL, "" },
5325 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5330 static struct TokenInfo setup_info_graphics[] =
5332 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5333 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5334 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5335 { TYPE_STRING, &window_size_text, "" },
5336 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5337 { TYPE_STRING, &scaling_type_text, "" },
5338 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5339 { TYPE_STRING, &rendering_mode_text, "" },
5342 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5343 { TYPE_STRING, &scroll_delay_text, "" },
5345 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5346 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5347 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5348 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5349 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5350 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5351 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5352 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5353 { TYPE_EMPTY, NULL, "" },
5354 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5359 static struct TokenInfo setup_info_sound[] =
5361 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5362 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5363 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5364 { TYPE_EMPTY, NULL, "" },
5365 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5366 { TYPE_STRING, &volume_simple_text, "" },
5367 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5368 { TYPE_STRING, &volume_loops_text, "" },
5369 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5370 { TYPE_STRING, &volume_music_text, "" },
5371 { TYPE_EMPTY, NULL, "" },
5372 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5377 static struct TokenInfo setup_info_artwork[] =
5379 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5380 { TYPE_STRING, &graphics_set_name, "" },
5381 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5382 { TYPE_STRING, &sounds_set_name, "" },
5383 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5384 { TYPE_STRING, &music_set_name, "" },
5385 { TYPE_EMPTY, NULL, "" },
5386 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5387 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5388 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5389 { TYPE_EMPTY, NULL, "" },
5390 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5395 static struct TokenInfo setup_info_input[] =
5397 { TYPE_SWITCH, NULL, "Player:" },
5398 { TYPE_SWITCH, NULL, "Device:" },
5399 { TYPE_ENTER_MENU, NULL, "" },
5400 { TYPE_EMPTY, NULL, "" },
5401 { TYPE_EMPTY, NULL, "" },
5402 { TYPE_EMPTY, NULL, "" },
5403 { TYPE_EMPTY, 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_LEAVE_MENU, execSetupMain, "Back" },
5415 static struct TokenInfo setup_info_touch[] =
5417 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5418 { TYPE_STRING, &touch_controls_text, "" },
5419 { TYPE_EMPTY, NULL, "" },
5420 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5421 { TYPE_STRING, &move_distance_text, "" },
5422 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5423 { TYPE_STRING, &drop_distance_text, "" },
5424 { TYPE_EMPTY, NULL, "" },
5425 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5430 static struct TokenInfo setup_info_shortcuts[] =
5432 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5433 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5434 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5435 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5436 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5437 { TYPE_EMPTY, NULL, "" },
5438 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5443 static struct TokenInfo setup_info_shortcuts_1[] =
5445 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5446 { TYPE_KEY, &setup.shortcut.save_game, "" },
5447 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5448 { TYPE_KEY, &setup.shortcut.load_game, "" },
5449 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5450 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5451 { TYPE_EMPTY, NULL, "" },
5452 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5453 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5454 { TYPE_EMPTY, NULL, "" },
5455 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5460 static struct TokenInfo setup_info_shortcuts_2[] =
5462 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5463 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5464 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5465 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5466 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5467 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5468 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5469 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5470 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5471 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5472 { TYPE_EMPTY, NULL, "" },
5473 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5478 static struct TokenInfo setup_info_shortcuts_3[] =
5480 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5481 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5482 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5483 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5484 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5485 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5486 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5487 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5488 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5489 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5490 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5491 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5492 { TYPE_EMPTY, NULL, "" },
5493 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5498 static struct TokenInfo setup_info_shortcuts_4[] =
5500 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5501 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5502 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5503 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5504 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5505 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5506 { TYPE_EMPTY, NULL, "" },
5507 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5512 static struct TokenInfo setup_info_shortcuts_5[] =
5514 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5515 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5516 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5517 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5518 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5519 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5520 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5521 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5522 { TYPE_EMPTY, NULL, "" },
5523 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5528 static Key getSetupKey()
5530 Key key = KSYM_UNDEFINED;
5531 boolean got_key_event = FALSE;
5533 while (!got_key_event)
5535 if (PendingEvent()) /* got event */
5543 case EVENT_KEYPRESS:
5545 key = GetEventKey((KeyEvent *)&event, TRUE);
5547 /* press 'Escape' or 'Enter' to keep the existing key binding */
5548 if (key == KSYM_Escape || key == KSYM_Return)
5549 key = KSYM_UNDEFINED; /* keep old value */
5551 got_key_event = TRUE;
5555 case EVENT_KEYRELEASE:
5556 key_joystick_mapping = 0;
5560 HandleOtherEvents(&event);
5571 static int getSetupValueFont(int type, void *value)
5573 if (type & TYPE_KEY)
5574 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5575 else if (type & TYPE_STRING)
5576 return FONT_VALUE_2;
5577 else if (type & TYPE_ECS_AGA)
5578 return FONT_VALUE_1;
5579 else if (type & TYPE_BOOLEAN_STYLE)
5580 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5581 else if (type & TYPE_YES_NO_AUTO)
5582 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5583 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5585 return FONT_VALUE_1;
5588 static int getSetupValueFontNarrow(int type, int font_nr)
5590 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5591 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5592 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5596 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5598 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5599 struct TokenInfo *si = &setup_info[si_pos];
5600 boolean font_draw_xoffset_modified = FALSE;
5601 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5602 int font_draw_xoffset_old = -1;
5603 int xoffset = (scrollbar_needed ? -1 : 0);
5604 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5605 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5606 int xpos = menu_screen_value_xpos;
5607 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5608 int startx = mSX + xpos * 32;
5609 int starty = mSY + ypos * 32;
5610 int font_nr, font_nr_default, font_width_default;
5611 int type = si->type;
5612 void *value = si->value;
5613 char *value_string = getSetupValue(type, value);
5616 if (value_string == NULL)
5619 if (type & TYPE_KEY)
5621 xpos = MENU_SCREEN_START_XPOS;
5623 if (type & TYPE_QUERY)
5624 value_string = "<press key>";
5626 else if (type & TYPE_STRING)
5628 int max_value_len = (SCR_FIELDX - 2) * 2;
5630 xpos = MENU_SCREEN_START_XPOS;
5632 if (strlen(value_string) > max_value_len)
5633 value_string[max_value_len] = '\0';
5635 else if (type & TYPE_YES_NO_AUTO)
5637 xpos = menu_screen_value_xpos - 1;
5640 startx = mSX + xpos * 32;
5641 starty = mSY + ypos * 32;
5642 font_nr_default = getSetupValueFont(type, value);
5643 font_width_default = getFontWidth(font_nr_default);
5645 font_nr = font_nr_default;
5647 // special check if right-side setup values moved left due to scrollbar
5648 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5650 int max_menu_text_length = 26; // maximum text length for classic menu
5651 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5652 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5653 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5654 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5655 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5657 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5660 startx = mSX + xpos * 32;
5662 font_nr = getSetupValueFontNarrow(type, font_nr);
5666 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5667 if (setup_mode != SETUP_MODE_INPUT)
5669 int max_menu_text_length_big = (menu_screen_value_xpos -
5670 MENU_SCREEN_START_XPOS);
5671 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5672 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5673 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5674 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5675 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5676 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5677 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5678 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5679 boolean correct_font_draw_xoffset = FALSE;
5681 if (xpos == MENU_SCREEN_START_XPOS &&
5682 startx + font1_xoffset < text_startx + text_font_xoffset)
5683 correct_font_draw_xoffset = TRUE;
5685 if (xpos == menu_screen_value_xpos &&
5686 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5687 correct_font_draw_xoffset = TRUE;
5689 /* check if setup value would overlap with setup text when printed */
5690 /* (this can happen for extreme/wrong values for font draw offset) */
5691 if (correct_font_draw_xoffset)
5693 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5694 font_draw_xoffset_modified = TRUE;
5696 if (type & TYPE_KEY)
5697 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5698 else if (!(type & TYPE_STRING))
5699 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5700 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5704 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5705 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
5707 DrawText(startx, starty, value_string, font_nr);
5709 if (font_draw_xoffset_modified)
5710 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5713 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5715 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5716 struct TokenInfo *si = &setup_info[si_pos];
5718 if (si->type & TYPE_BOOLEAN_STYLE)
5720 *(boolean *)si->value ^= TRUE;
5722 else if (si->type & TYPE_YES_NO_AUTO)
5726 (*(int *)si->value == AUTO ? TRUE :
5727 *(int *)si->value == TRUE ? FALSE : AUTO) :
5728 (*(int *)si->value == TRUE ? AUTO :
5729 *(int *)si->value == AUTO ? FALSE : TRUE));
5731 else if (si->type & TYPE_KEY)
5735 si->type |= TYPE_QUERY;
5736 drawSetupValue(screen_pos, setup_info_pos_raw);
5737 si->type &= ~TYPE_QUERY;
5739 key = getSetupKey();
5740 if (key != KSYM_UNDEFINED)
5741 *(Key *)si->value = key;
5744 drawSetupValue(screen_pos, setup_info_pos_raw);
5746 // fullscreen state may have changed at this point
5747 if (si->value == &setup.fullscreen)
5748 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5751 static void DrawSetupScreen_Generic()
5753 int fade_mask = REDRAW_FIELD;
5754 boolean redraw_all = FALSE;
5755 char *title_string = NULL;
5758 if (CheckIfGlobalBorderHasChanged())
5759 fade_mask = REDRAW_ALL;
5762 FadeSoundsAndMusic();
5764 FreeScreenGadgets();
5765 CreateScreenGadgets();
5767 if (redraw_mask & REDRAW_ALL)
5772 /* needed if different viewport properties defined for setup screen */
5773 ChangeViewportPropertiesIfNeeded();
5775 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
5779 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5781 if (setup_mode == SETUP_MODE_MAIN)
5783 setup_info = setup_info_main;
5784 title_string = "Setup";
5786 else if (setup_mode == SETUP_MODE_GAME)
5788 setup_info = setup_info_game;
5789 title_string = "Setup Game";
5791 else if (setup_mode == SETUP_MODE_EDITOR)
5793 setup_info = setup_info_editor;
5794 title_string = "Setup Editor";
5796 else if (setup_mode == SETUP_MODE_GRAPHICS)
5798 setup_info = setup_info_graphics;
5799 title_string = "Setup Graphics";
5801 else if (setup_mode == SETUP_MODE_SOUND)
5803 setup_info = setup_info_sound;
5804 title_string = "Setup Sound";
5806 else if (setup_mode == SETUP_MODE_ARTWORK)
5808 setup_info = setup_info_artwork;
5809 title_string = "Custom Artwork";
5811 else if (setup_mode == SETUP_MODE_TOUCH)
5813 setup_info = setup_info_touch;
5814 title_string = "Setup Touch Ctrls";
5816 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5818 setup_info = setup_info_shortcuts;
5819 title_string = "Setup Shortcuts";
5821 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5823 setup_info = setup_info_shortcuts_1;
5824 title_string = "Setup Shortcuts";
5826 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5828 setup_info = setup_info_shortcuts_2;
5829 title_string = "Setup Shortcuts";
5831 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5833 setup_info = setup_info_shortcuts_3;
5834 title_string = "Setup Shortcuts";
5836 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5838 setup_info = setup_info_shortcuts_4;
5839 title_string = "Setup Shortcuts";
5841 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5843 setup_info = setup_info_shortcuts_5;
5844 title_string = "Setup Shortcuts";
5847 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5849 // determine maximal number of setup entries that can be displayed on screen
5851 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5854 // determine maximal number of setup entries available for this setup screen
5856 for (i = 0; setup_info[i].type != 0; i++)
5859 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5861 MapScreenGadgets(max_setup_info);
5864 redraw_mask = fade_mask = REDRAW_ALL;
5866 DrawMaskedBorder(fade_mask);
5871 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5873 menu_info = setup_info;
5875 HandleMenuScreen(mx, my, dx, dy, button,
5876 setup_mode, num_setup_info, max_setup_info);
5879 void DrawSetupScreen_Input()
5883 FadeOut(REDRAW_FIELD);
5887 setup_info = setup_info_input;
5889 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5891 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5892 "Joysticks deactivated on this screen");
5894 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5896 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5897 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5898 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5899 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5900 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5901 initCursor(i, IMG_MENU_BUTTON);
5903 DrawCursorAndText_Setup(i, -1, FALSE);
5906 /* create gadgets for setup input menu screen */
5907 FreeScreenGadgets();
5908 CreateScreenGadgets();
5910 /* map gadgets for setup input menu screen */
5911 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5913 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5915 FadeIn(REDRAW_FIELD);
5918 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5920 if (device_name == NULL)
5923 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5926 if (strlen(device_name) > 1)
5928 char c1 = device_name[strlen(device_name) - 1];
5929 char c2 = device_name[strlen(device_name) - 2];
5931 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5932 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5935 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5936 strlen(device_name));
5939 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5942 static struct SetupKeyboardInfo custom_key;
5949 { &custom_key.left, "Joystick Left" },
5950 { &custom_key.right, "Joystick Right" },
5951 { &custom_key.up, "Joystick Up" },
5952 { &custom_key.down, "Joystick Down" },
5953 { &custom_key.snap, "Button 1" },
5954 { &custom_key.drop, "Button 2" }
5956 static char *joystick_name[MAX_PLAYERS] =
5963 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5967 custom_key = setup.input[player_nr].key;
5969 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5970 FONT_INPUT_1_ACTIVE);
5972 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5974 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5975 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5977 if (setup.input[player_nr].use_joystick)
5979 char *device_name = setup.input[player_nr].joy.device_name;
5980 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5981 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5983 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5984 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5988 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5989 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5992 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5994 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5995 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5996 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5997 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5999 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6000 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6001 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6002 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6003 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6004 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6006 for (i = 0; i < 6; i++)
6008 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6010 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6012 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6013 (setup.input[player_nr].use_joystick ?
6015 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6019 static int input_player_nr = 0;
6021 void HandleSetupScreen_Input_Player(int step, int direction)
6023 int old_player_nr = input_player_nr;
6026 new_player_nr = old_player_nr + step * direction;
6027 if (new_player_nr < 0)
6029 if (new_player_nr > MAX_PLAYERS - 1)
6030 new_player_nr = MAX_PLAYERS - 1;
6032 if (new_player_nr != old_player_nr)
6034 input_player_nr = new_player_nr;
6036 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6040 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6042 static int choice = 0;
6045 int pos_start = SETUPINPUT_SCREEN_POS_START;
6046 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6047 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6048 int pos_end = SETUPINPUT_SCREEN_POS_END;
6050 if (button == MB_MENU_INITIALIZE)
6052 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6054 DrawCursorAndText_Setup(choice, -1, TRUE);
6058 else if (button == MB_MENU_LEAVE)
6060 setup_mode = SETUP_MODE_MAIN;
6067 if (mx || my) /* mouse input */
6069 x = (mx - mSX) / 32;
6070 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6072 else if (dx || dy) /* keyboard input */
6074 if (dx && choice == 0)
6075 x = (dx < 0 ? 10 : 12);
6076 else if ((dx && choice == 1) ||
6077 (dx == +1 && choice == 2) ||
6078 (dx == -1 && choice == pos_end))
6079 button = MB_MENU_CHOICE;
6083 if (y >= pos_empty1 && y <= pos_empty2)
6084 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6087 if (y == 0 && dx != 0 && button)
6089 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6091 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6092 y >= pos_start && y <= pos_end &&
6093 !(y >= pos_empty1 && y <= pos_empty2))
6099 DrawCursorAndText_Setup(choice, -1, FALSE);
6100 DrawCursorAndText_Setup(y, -1, TRUE);
6102 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6111 char *device_name = setup.input[input_player_nr].joy.device_name;
6113 if (!setup.input[input_player_nr].use_joystick)
6115 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6117 setJoystickDeviceToNr(device_name, new_device_nr);
6118 setup.input[input_player_nr].use_joystick = TRUE;
6122 int device_nr = getJoystickNrFromDeviceName(device_name);
6123 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6125 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6126 setup.input[input_player_nr].use_joystick = FALSE;
6128 setJoystickDeviceToNr(device_name, new_device_nr);
6131 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6135 if (setup.input[input_player_nr].use_joystick)
6138 CalibrateJoystick(input_player_nr);
6141 CustomizeKeyboard(input_player_nr);
6143 else if (y == pos_end)
6149 setup_mode = SETUP_MODE_MAIN;
6156 void CustomizeKeyboard(int player_nr)
6160 boolean finished = FALSE;
6161 static struct SetupKeyboardInfo custom_key;
6166 } customize_step[] =
6168 { &custom_key.left, "Move Left" },
6169 { &custom_key.right, "Move Right" },
6170 { &custom_key.up, "Move Up" },
6171 { &custom_key.down, "Move Down" },
6172 { &custom_key.snap, "Snap Field" },
6173 { &custom_key.drop, "Drop Element" }
6176 /* read existing key bindings from player setup */
6177 custom_key = setup.input[player_nr].key;
6180 FadeOut(REDRAW_FIELD);
6184 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6187 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6188 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6189 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6190 "Key:", FONT_INPUT_1_ACTIVE);
6191 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6192 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6194 FadeIn(REDRAW_FIELD);
6198 if (PendingEvent()) /* got event */
6206 case EVENT_KEYPRESS:
6208 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6210 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6212 if (key == KSYM_Escape)
6213 FadeSkipNextFadeIn();
6219 /* all keys configured -- wait for "Escape" or "Return" key */
6223 /* press 'Enter' to keep the existing key binding */
6224 if (key == KSYM_Return)
6225 key = *customize_step[step_nr].key;
6227 /* check if key already used */
6228 for (i = 0; i < step_nr; i++)
6229 if (*customize_step[i].key == key)
6234 /* got new key binding */
6235 *customize_step[step_nr].key = key;
6236 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6238 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6239 getKeyNameFromKey(key), FONT_VALUE_1);
6242 /* un-highlight last query */
6243 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6244 customize_step[step_nr - 1].text, FONT_MENU_1);
6245 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6246 "Key:", FONT_MENU_1);
6248 /* press 'Enter' to leave */
6251 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6252 "Press Enter", FONT_TITLE_1);
6256 /* query next key binding */
6257 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6258 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6259 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6260 "Key:", FONT_INPUT_1_ACTIVE);
6261 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6262 getKeyNameFromKey(*customize_step[step_nr].key),
6267 case EVENT_KEYRELEASE:
6268 key_joystick_mapping = 0;
6272 HandleOtherEvents(&event);
6280 /* write new key bindings back to player setup */
6281 setup.input[player_nr].key = custom_key;
6283 DrawSetupScreen_Input();
6286 static boolean CalibrateJoystickMain(int player_nr)
6288 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6289 int new_joystick_xright = JOYSTICK_XMIDDLE;
6290 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6291 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6292 int new_joystick_xmiddle, new_joystick_ymiddle;
6294 int joystick_fd = joystick.fd[player_nr];
6295 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6296 boolean check[3][3];
6297 int check_remaining = 3 * 3;
6302 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6305 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6309 FadeOut(REDRAW_FIELD);
6313 for (y = 0; y < 3; y++)
6315 for (x = 0; x < 3; x++)
6317 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6318 check[x][y] = FALSE;
6322 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6323 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6324 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6325 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6326 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6327 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6328 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6330 joy_value = Joystick(player_nr);
6331 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6332 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6334 /* eventually uncalibrated center position (joystick could be uncentered) */
6335 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6338 new_joystick_xmiddle = joy_x;
6339 new_joystick_ymiddle = joy_y;
6341 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6343 FadeIn(REDRAW_FIELD);
6345 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6349 if (PendingEvent()) /* got event */
6357 case EVENT_KEYPRESS:
6358 switch (GetEventKey((KeyEvent *)&event, TRUE))
6361 if (check_remaining == 0)
6366 FadeSkipNextFadeIn();
6375 case EVENT_KEYRELEASE:
6376 key_joystick_mapping = 0;
6380 HandleOtherEvents(&event);
6385 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6388 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6389 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6390 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6391 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6393 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6394 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6395 setup.input[player_nr].joy.xright = new_joystick_xright;
6396 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6397 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6398 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6400 CheckJoystickData();
6402 joy_value = Joystick(player_nr);
6404 if (joy_value & JOY_BUTTON && check_remaining == 0)
6407 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6408 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6410 if (x != last_x || y != last_y)
6412 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6413 IMG_MENU_CALIBRATE_YELLOW, 0);
6414 DrawFixedGraphic(xpos + x, ypos + y,
6415 IMG_MENU_CALIBRATE_RED, 0);
6420 if (check_remaining > 0 && !check[x+1][y+1])
6422 check[x+1][y+1] = TRUE;
6430 /* calibrated center position (joystick should now be centered) */
6431 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6434 new_joystick_xmiddle = joy_x;
6435 new_joystick_ymiddle = joy_y;
6437 /* wait until the last pressed button was released */
6438 while (Joystick(player_nr) & JOY_BUTTON)
6440 if (PendingEvent()) /* got event */
6445 HandleOtherEvents(&event);
6454 void CalibrateJoystick(int player_nr)
6456 if (!CalibrateJoystickMain(player_nr))
6458 char *device_name = setup.input[player_nr].joy.device_name;
6459 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6460 int xpos = mSX - SX;
6461 int ypos = mSY - SY;
6465 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6466 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6469 Delay(2000); /* show error message for a short time */
6474 DrawSetupScreen_Input();
6477 void DrawSetupScreen()
6479 DeactivateJoystick();
6481 if (setup_mode == SETUP_MODE_INPUT)
6482 DrawSetupScreen_Input();
6483 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6484 DrawChooseTree(&game_speed_current);
6485 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6486 DrawChooseTree(&scroll_delay_current);
6487 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6488 DrawChooseTree(&snapshot_mode_current);
6489 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6490 DrawChooseTree(&window_size_current);
6491 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6492 DrawChooseTree(&scaling_type_current);
6493 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6494 DrawChooseTree(&rendering_mode_current);
6495 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6496 DrawChooseTree(&artwork.gfx_current);
6497 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6498 DrawChooseTree(&artwork.snd_current);
6499 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6500 DrawChooseTree(&artwork.mus_current);
6501 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6502 DrawChooseTree(&volume_simple_current);
6503 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6504 DrawChooseTree(&volume_loops_current);
6505 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6506 DrawChooseTree(&volume_music_current);
6507 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6508 DrawChooseTree(&touch_control_current);
6509 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6510 DrawChooseTree(&move_distance_current);
6511 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6512 DrawChooseTree(&drop_distance_current);
6514 DrawSetupScreen_Generic();
6520 void RedrawSetupScreenAfterFullscreenToggle()
6522 if (setup_mode == SETUP_MODE_GRAPHICS ||
6523 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6525 // update list selection from "setup.window_scaling_percent"
6526 execSetupGraphics_setWindowSizes(TRUE);
6532 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6534 if (setup_mode == SETUP_MODE_INPUT)
6535 HandleSetupScreen_Input(mx, my, dx, dy, button);
6536 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6537 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6538 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6539 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6540 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6541 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6542 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6543 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6544 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6545 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6546 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6547 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
6548 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6549 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6550 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6551 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6552 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6553 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6554 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6555 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6556 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6557 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6558 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6559 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6560 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6561 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6562 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6563 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6564 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6565 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6567 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6570 void HandleGameActions()
6572 if (game_status != GAME_MODE_PLAYING)
6575 GameActions(); /* main game loop */
6577 if (tape.auto_play && !tape.playing)
6578 AutoPlayTape(); /* continue automatically playing next tape */
6582 /* ---------- new screen button stuff -------------------------------------- */
6584 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6588 case SCREEN_CTRL_ID_PREV_LEVEL:
6589 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6590 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6593 case SCREEN_CTRL_ID_NEXT_LEVEL:
6594 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6595 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6598 case SCREEN_CTRL_ID_PREV_PLAYER:
6599 *x = mSX + TILEX * 10;
6600 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6603 case SCREEN_CTRL_ID_NEXT_PLAYER:
6604 *x = mSX + TILEX * 12;
6605 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6609 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6615 int gfx_unpressed, gfx_pressed;
6616 void (*get_gadget_position)(int *, int *, int);
6620 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6623 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6624 getScreenMenuButtonPos,
6625 SCREEN_CTRL_ID_PREV_LEVEL,
6630 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6631 getScreenMenuButtonPos,
6632 SCREEN_CTRL_ID_NEXT_LEVEL,
6637 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6638 getScreenMenuButtonPos,
6639 SCREEN_CTRL_ID_PREV_PLAYER,
6644 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6645 getScreenMenuButtonPos,
6646 SCREEN_CTRL_ID_NEXT_PLAYER,
6654 int gfx_unpressed, gfx_pressed;
6658 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6661 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6662 -1, -1, /* these values are not constant, but can change at runtime */
6663 SCREEN_CTRL_ID_SCROLL_UP,
6667 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6668 -1, -1, /* these values are not constant, but can change at runtime */
6669 SCREEN_CTRL_ID_SCROLL_DOWN,
6676 int gfx_unpressed, gfx_pressed;
6682 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6685 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6686 -1, -1, /* these values are not constant, but can change at runtime */
6687 -1, -1, /* these values are not constant, but can change at runtime */
6688 GD_TYPE_SCROLLBAR_VERTICAL,
6689 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6690 "scroll level series vertically"
6694 static void CreateScreenMenubuttons()
6696 struct GadgetInfo *gi;
6697 unsigned int event_mask;
6700 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6702 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6703 int gfx_unpressed, gfx_pressed;
6704 int x, y, width, height;
6705 int gd_x1, gd_x2, gd_y1, gd_y2;
6706 int id = menubutton_info[i].gadget_id;
6708 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6710 menubutton_info[i].get_gadget_position(&x, &y, id);
6712 width = SC_MENUBUTTON_XSIZE;
6713 height = SC_MENUBUTTON_YSIZE;
6715 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6716 gfx_pressed = menubutton_info[i].gfx_pressed;
6717 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6718 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6719 gd_x1 = graphic_info[gfx_unpressed].src_x;
6720 gd_y1 = graphic_info[gfx_unpressed].src_y;
6721 gd_x2 = graphic_info[gfx_pressed].src_x;
6722 gd_y2 = graphic_info[gfx_pressed].src_y;
6724 gi = CreateGadget(GDI_CUSTOM_ID, id,
6725 GDI_CUSTOM_TYPE_ID, i,
6726 GDI_INFO_TEXT, menubutton_info[i].infotext,
6731 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6732 GDI_STATE, GD_BUTTON_UNPRESSED,
6733 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6734 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6735 GDI_DIRECT_DRAW, FALSE,
6736 GDI_EVENT_MASK, event_mask,
6737 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6741 Error(ERR_EXIT, "cannot create gadget");
6743 screen_gadget[id] = gi;
6747 static void CreateScreenScrollbuttons()
6749 struct GadgetInfo *gi;
6750 unsigned int event_mask;
6753 /* these values are not constant, but can change at runtime */
6754 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6755 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6756 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6757 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6759 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6761 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6762 int gfx_unpressed, gfx_pressed;
6763 int x, y, width, height;
6764 int gd_x1, gd_x2, gd_y1, gd_y2;
6765 int id = scrollbutton_info[i].gadget_id;
6767 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6769 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6770 y = mSY + scrollbutton_info[i].y;
6771 width = SC_SCROLLBUTTON_XSIZE;
6772 height = SC_SCROLLBUTTON_YSIZE;
6774 /* correct scrollbar position if placed outside menu (playfield) area */
6775 if (x > SX + SC_SCROLL_UP_XPOS)
6776 x = SX + SC_SCROLL_UP_XPOS;
6778 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6779 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6780 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6782 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6783 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6784 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6785 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6786 gd_x1 = graphic_info[gfx_unpressed].src_x;
6787 gd_y1 = graphic_info[gfx_unpressed].src_y;
6788 gd_x2 = graphic_info[gfx_pressed].src_x;
6789 gd_y2 = graphic_info[gfx_pressed].src_y;
6791 gi = CreateGadget(GDI_CUSTOM_ID, id,
6792 GDI_CUSTOM_TYPE_ID, i,
6793 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6798 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6799 GDI_STATE, GD_BUTTON_UNPRESSED,
6800 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6801 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6802 GDI_DIRECT_DRAW, FALSE,
6803 GDI_EVENT_MASK, event_mask,
6804 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6808 Error(ERR_EXIT, "cannot create gadget");
6810 screen_gadget[id] = gi;
6814 static void CreateScreenScrollbars()
6818 /* these values are not constant, but can change at runtime */
6819 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6820 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6821 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6822 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6824 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6826 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6827 int gfx_unpressed, gfx_pressed;
6828 int x, y, width, height;
6829 int gd_x1, gd_x2, gd_y1, gd_y2;
6830 struct GadgetInfo *gi;
6831 int items_max, items_visible, item_position;
6832 unsigned int event_mask;
6833 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6834 int id = scrollbar_info[i].gadget_id;
6836 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6838 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6839 y = mSY + scrollbar_info[i].y;
6840 width = scrollbar_info[i].width;
6841 height = scrollbar_info[i].height;
6843 /* correct scrollbar position if placed outside menu (playfield) area */
6844 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6845 x = SX + SC_SCROLL_VERTICAL_XPOS;
6847 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6848 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6850 items_max = num_page_entries;
6851 items_visible = num_page_entries;
6854 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6855 gfx_pressed = scrollbar_info[i].gfx_pressed;
6856 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6857 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6858 gd_x1 = graphic_info[gfx_unpressed].src_x;
6859 gd_y1 = graphic_info[gfx_unpressed].src_y;
6860 gd_x2 = graphic_info[gfx_pressed].src_x;
6861 gd_y2 = graphic_info[gfx_pressed].src_y;
6863 gi = CreateGadget(GDI_CUSTOM_ID, id,
6864 GDI_CUSTOM_TYPE_ID, i,
6865 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6870 GDI_TYPE, scrollbar_info[i].type,
6871 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6872 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6873 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6874 GDI_WHEEL_AREA_X, SX,
6875 GDI_WHEEL_AREA_Y, SY,
6876 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6877 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6878 GDI_STATE, GD_BUTTON_UNPRESSED,
6879 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6880 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6881 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6882 GDI_DIRECT_DRAW, FALSE,
6883 GDI_EVENT_MASK, event_mask,
6884 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6888 Error(ERR_EXIT, "cannot create gadget");
6890 screen_gadget[id] = gi;
6894 void CreateScreenGadgets()
6896 CreateScreenMenubuttons();
6898 CreateScreenScrollbuttons();
6899 CreateScreenScrollbars();
6902 void FreeScreenGadgets()
6906 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6907 FreeGadget(screen_gadget[i]);
6910 void MapScreenMenuGadgets(int screen_mask)
6914 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6915 if (screen_mask & menubutton_info[i].screen_mask)
6916 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6919 void MapScreenGadgets(int num_entries)
6923 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6926 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6927 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6929 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6930 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6933 void MapScreenTreeGadgets(TreeInfo *ti)
6935 MapScreenGadgets(numTreeInfoInGroup(ti));
6938 static void HandleScreenGadgets(struct GadgetInfo *gi)
6940 int id = gi->custom_id;
6941 int button = gi->event.button;
6942 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6946 case SCREEN_CTRL_ID_PREV_LEVEL:
6947 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6950 case SCREEN_CTRL_ID_NEXT_LEVEL:
6951 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6954 case SCREEN_CTRL_ID_PREV_PLAYER:
6955 HandleSetupScreen_Input_Player(step, -1);
6958 case SCREEN_CTRL_ID_NEXT_PLAYER:
6959 HandleSetupScreen_Input_Player(step, +1);
6962 case SCREEN_CTRL_ID_SCROLL_UP:
6963 if (game_status == GAME_MODE_LEVELS)
6964 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6965 else if (game_status == GAME_MODE_LEVELNR)
6966 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6967 else if (game_status == GAME_MODE_SETUP)
6968 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6969 else if (game_status == GAME_MODE_INFO)
6970 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6973 case SCREEN_CTRL_ID_SCROLL_DOWN:
6974 if (game_status == GAME_MODE_LEVELS)
6975 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6976 else if (game_status == GAME_MODE_LEVELNR)
6977 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6978 else if (game_status == GAME_MODE_SETUP)
6979 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6980 else if (game_status == GAME_MODE_INFO)
6981 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6984 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6985 if (game_status == GAME_MODE_LEVELS)
6986 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6987 else if (game_status == GAME_MODE_LEVELNR)
6988 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6989 else if (game_status == GAME_MODE_SETUP)
6990 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6991 else if (game_status == GAME_MODE_INFO)
6992 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);