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;
238 static unsigned int sync_frame_delay = 0;
239 static unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
245 } window_sizes_list[] =
250 { 100, "100 % (Default)" },
267 } scaling_types_list[] =
269 { SCALING_QUALITY_NEAREST, "None" },
270 { SCALING_QUALITY_LINEAR, "Linear" },
271 { SCALING_QUALITY_BEST, "Anisotropic" },
280 } rendering_modes_list[] =
282 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
283 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
284 { 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);
729 static int getTitleScreenBackground(boolean initial)
731 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
736 static int getTitleMessageBackground(int nr, boolean initial)
738 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
742 static int getTitleBackground(int nr, boolean initial, boolean is_image)
744 int base = (is_image ?
745 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
746 IMG_BACKGROUND_TITLESCREEN_1) :
747 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
748 IMG_BACKGROUND_TITLEMESSAGE_1));
749 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
750 IMG_BACKGROUND_TITLE);
751 int graphic_local = base + nr;
753 if (graphic_info[graphic_local].bitmap != NULL)
754 return graphic_local;
756 if (graphic_info[graphic_global].bitmap != NULL)
757 return graphic_global;
759 return IMG_UNDEFINED;
762 static int getTitleSound(struct TitleControlInfo *tci)
764 boolean is_image = tci->is_image;
765 int initial = tci->initial;
766 int nr = tci->local_nr;
767 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
768 int base = (is_image ?
769 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
770 SND_BACKGROUND_TITLESCREEN_1) :
771 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
772 SND_BACKGROUND_TITLEMESSAGE_1));
773 int sound_global = menu.sound[mode];
774 int sound_local = base + nr;
777 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
778 nr, initial, is_image,
779 sound_global, getSoundListEntry(sound_global)->filename,
780 sound_local, getSoundListEntry(sound_local)->filename);
783 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
786 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
789 return SND_UNDEFINED;
792 static int getTitleMusic(struct TitleControlInfo *tci)
794 boolean is_image = tci->is_image;
795 int initial = tci->initial;
796 int nr = tci->local_nr;
797 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
798 int base = (is_image ?
799 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
800 MUS_BACKGROUND_TITLESCREEN_1) :
801 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
802 MUS_BACKGROUND_TITLEMESSAGE_1));
803 int music_global = menu.music[mode];
804 int music_local = base + nr;
807 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
808 nr, initial, is_image,
809 music_global, getMusicListEntry(music_global)->filename,
810 music_local, getMusicListEntry(music_local)->filename);
813 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
816 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
819 return MUS_UNDEFINED;
822 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
824 boolean is_image = tci->is_image;
825 boolean initial = tci->initial;
826 boolean first = tci->first;
827 int nr = tci->local_nr;
828 struct TitleMessageInfo tmi;
829 struct TitleFadingInfo ti;
831 tmi = (is_image ? (initial ? (first ?
832 titlescreen_initial_first[nr] :
833 titlescreen_initial[nr])
835 titlescreen_first[nr] :
837 : (initial ? (first ?
838 titlemessage_initial_first[nr] :
839 titlemessage_initial[nr])
841 titlemessage_first[nr] :
844 ti.fade_mode = tmi.fade_mode;
845 ti.fade_delay = tmi.fade_delay;
846 ti.post_delay = tmi.post_delay;
847 ti.auto_delay = tmi.auto_delay;
852 static int compareTitleControlInfo(const void *object1, const void *object2)
854 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
855 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
858 if (tci1->initial != tci2->initial)
859 compare_result = (tci1->initial ? -1 : +1);
860 else if (tci1->sort_priority != tci2->sort_priority)
861 compare_result = tci1->sort_priority - tci2->sort_priority;
862 else if (tci1->is_image != tci2->is_image)
863 compare_result = (tci1->is_image ? -1 : +1);
865 compare_result = tci1->local_nr - tci2->local_nr;
867 return compare_result;
870 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
872 int nr, int sort_priority)
874 title_controls[num_title_screens].is_image = is_image;
875 title_controls[num_title_screens].initial = initial;
876 title_controls[num_title_screens].local_nr = nr;
877 title_controls[num_title_screens].sort_priority = sort_priority;
879 title_controls[num_title_screens].first = FALSE; /* will be set later */
884 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
888 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
890 int graphic = getTitleScreenGraphic(i, initial);
891 Bitmap *bitmap = graphic_info[graphic].bitmap;
892 int sort_priority = graphic_info[graphic].sort_priority;
895 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
898 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
900 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
901 char *filename = getLevelSetTitleMessageFilename(i, initial);
902 int sort_priority = tmi->sort_priority;
904 if (filename != NULL)
905 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
909 static void InitializeTitleControls(boolean show_title_initial)
911 num_title_screens = 0;
913 /* 1st step: initialize title screens for game start (only when starting) */
914 if (show_title_initial)
915 InitializeTitleControls_CheckTitleInfo(TRUE);
917 /* 2nd step: initialize title screens for current level set */
918 InitializeTitleControls_CheckTitleInfo(FALSE);
920 /* sort title screens according to sort_priority and title number */
921 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
922 compareTitleControlInfo);
924 /* mark first title screen */
925 title_controls[0].first = TRUE;
928 static boolean visibleMenuPos(struct MenuPosInfo *pos)
930 return (pos != NULL && pos->x != -1 && pos->y != -1);
933 static boolean visibleTextPos(struct TextPosInfo *pos)
935 return (pos != NULL && pos->x != -1 && pos->y != -1);
938 static void InitializeMainControls()
940 boolean local_team_mode = (!options.network && setup.team_mode);
943 /* set main control text values to dynamically determined values */
944 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
946 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
947 menu.main.text.first_level.size));
948 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
949 menu.main.text.last_level.size));
950 strcpy(main_text_level_number, int2str(level_nr,
951 menu.main.text.level_number.size));
953 main_text_level_year = leveldir_current->year;
954 main_text_level_imported_from = leveldir_current->imported_from;
955 main_text_level_imported_by = leveldir_current->imported_by;
956 main_text_level_tested_by = leveldir_current->tested_by;
958 /* set main control screen positions to dynamically determined values */
959 for (i = 0; main_controls[i].nr != -1; i++)
961 struct MainControlInfo *mci = &main_controls[i];
963 struct MenuPosInfo *pos_button = mci->pos_button;
964 struct TextPosInfo *pos_text = mci->pos_text;
965 struct TextPosInfo *pos_input = mci->pos_input;
966 char *text = (mci->text ? *mci->text : NULL);
967 char *input = (mci->input ? *mci->input : NULL);
968 int button_graphic = mci->button_graphic;
969 int font_text = (pos_text ? pos_text->font : -1);
970 int font_input = (pos_input ? pos_input->font : -1);
972 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
973 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
974 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
975 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
976 int text_chars = (text != NULL ? strlen(text) : 0);
977 int input_chars = (input != NULL ? strlen(input) : 0);
980 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
982 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
983 int text_width = font_text_width * text_chars;
984 int text_height = font_text_height;
985 int input_width = font_input_width * input_chars;
986 int input_height = font_input_height;
988 if (nr == MAIN_CONTROL_NAME)
990 menu.main.input.name.width = input_width;
991 menu.main.input.name.height = input_height;
994 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
996 pos_button->width = button_width;
997 pos_button->height = button_height;
1000 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1002 /* calculate size for non-clickable text -- needed for text alignment */
1003 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1005 if (pos_text->width == -1 || calculate_text_size)
1006 pos_text->width = text_width;
1007 if (pos_text->height == -1 || calculate_text_size)
1008 pos_text->height = text_height;
1010 if (visibleMenuPos(pos_button))
1012 if (pos_text->x == -1)
1013 pos_text->x = pos_button->x + pos_button->width;
1014 if (pos_text->y == -1)
1016 pos_button->y + (pos_button->height - pos_text->height) / 2;
1020 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1022 if (visibleTextPos(pos_text))
1024 if (pos_input->x == -1)
1025 pos_input->x = pos_text->x + pos_text->width;
1026 if (pos_input->y == -1)
1027 pos_input->y = pos_text->y;
1030 if (pos_input->width == -1)
1031 pos_input->width = input_width;
1032 if (pos_input->height == -1)
1033 pos_input->height = input_height;
1038 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1039 int graphic, boolean pressed)
1041 struct GraphicInfo *g = &graphic_info[graphic];
1044 int xoffset = (pressed ? g->pressed_xoffset : 0);
1045 int yoffset = (pressed ? g->pressed_yoffset : 0);
1047 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1049 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1050 g->width, g->height, dst_x, dst_y);
1053 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1054 boolean active_input,
1055 boolean pressed_button)
1059 for (i = 0; main_controls[i].nr != -1; i++)
1061 struct MainControlInfo *mci = &main_controls[i];
1063 if (mci->nr == nr || nr == -1)
1065 struct MenuPosInfo *pos_button = mci->pos_button;
1066 struct TextPosInfo *pos_text = mci->pos_text;
1067 struct TextPosInfo *pos_input = mci->pos_input;
1068 char *text = (mci->text ? *mci->text : NULL);
1069 char *input = (mci->input ? *mci->input : NULL);
1070 int button_graphic = mci->button_graphic;
1071 int font_text = (pos_text ? pos_text->font : -1);
1072 int font_input = (pos_input ? pos_input->font : -1);
1076 button_graphic = BUTTON_ACTIVE(button_graphic);
1077 font_text = FONT_ACTIVE(font_text);
1082 font_input = FONT_ACTIVE(font_input);
1085 if (visibleMenuPos(pos_button))
1087 struct MenuPosInfo *pos = pos_button;
1088 int x = mSX + pos->x;
1089 int y = mSY + pos->y;
1091 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1092 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1095 if (visibleTextPos(pos_text) && text != NULL)
1097 struct TextPosInfo *pos = pos_text;
1098 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1099 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1102 /* (check why/if this is needed) */
1103 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1105 DrawText(x, y, text, font_text);
1108 if (visibleTextPos(pos_input) && input != NULL)
1110 struct TextPosInfo *pos = pos_input;
1111 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1112 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1115 /* (check why/if this is needed) */
1116 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1118 DrawText(x, y, input, font_input);
1124 static void DrawCursorAndText_Main(int nr, boolean active_text,
1125 boolean pressed_button)
1127 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1131 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1132 boolean pressed_button)
1134 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1138 static struct MainControlInfo *getMainControlInfo(int nr)
1142 for (i = 0; main_controls[i].nr != -1; i++)
1143 if (main_controls[i].nr == nr)
1144 return &main_controls[i];
1149 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1154 int rect_x = ALIGNED_TEXT_XPOS(rect);
1155 int rect_y = ALIGNED_TEXT_YPOS(rect);
1157 return (x >= rect_x && x < rect_x + rect->width &&
1158 y >= rect_y && y < rect_y + rect->height);
1161 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1166 int rect_x = ALIGNED_TEXT_XPOS(rect);
1167 int rect_y = ALIGNED_TEXT_YPOS(rect);
1170 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1171 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1172 (x >= rect_x && x < rect_x + rect->width &&
1173 y >= rect_y && y < rect_y + rect->height));
1176 return (x >= rect_x && x < rect_x + rect->width &&
1177 y >= rect_y && y < rect_y + rect->height);
1180 static void AdjustScrollbar(int id, int items_max, int items_visible,
1183 struct GadgetInfo *gi = screen_gadget[id];
1185 if (item_position > items_max - items_visible)
1186 item_position = items_max - items_visible;
1188 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1189 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1190 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1193 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1195 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1199 static void clearMenuListArea()
1201 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1203 /* correct scrollbar position if placed outside menu (playfield) area */
1204 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1205 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1207 /* clear menu list area, but not title or scrollbar */
1208 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1209 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1212 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1214 static int cursor_array[MAX_LEV_FIELDY];
1215 int x = mSX + TILEX * xpos;
1216 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1221 cursor_array[ypos] = graphic;
1223 graphic = cursor_array[ypos];
1227 graphic = BUTTON_ACTIVE(graphic);
1229 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1230 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1233 static void initCursor(int ypos, int graphic)
1235 drawCursorExt(0, ypos, FALSE, graphic);
1238 static void drawCursor(int ypos, boolean active)
1240 drawCursorExt(0, ypos, active, -1);
1243 static void drawCursorXY(int xpos, int ypos, int graphic)
1245 drawCursorExt(xpos, ypos, FALSE, graphic);
1248 static void drawChooseTreeCursor(int ypos, boolean active)
1250 int last_game_status = game_status; /* save current game status */
1252 drawCursorExt(0, ypos, active, -1);
1254 SetGameStatus(last_game_status); /* restore current game status */
1259 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1260 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1261 setup.internal.program_copyright);
1264 void DrawTitleScreenImage(int nr, boolean initial)
1266 int graphic = getTitleScreenGraphic(nr, initial);
1267 Bitmap *bitmap = graphic_info[graphic].bitmap;
1268 int width = graphic_info[graphic].width;
1269 int height = graphic_info[graphic].height;
1270 int src_x = graphic_info[graphic].src_x;
1271 int src_y = graphic_info[graphic].src_y;
1277 if (width > WIN_XSIZE)
1279 /* image width too large for window => center image horizontally */
1280 src_x = (width - WIN_XSIZE) / 2;
1284 if (height > WIN_YSIZE)
1286 /* image height too large for window => center image vertically */
1287 src_y = (height - WIN_YSIZE) / 2;
1291 /* always display title screens centered */
1292 dst_x = (WIN_XSIZE - width) / 2;
1293 dst_y = (WIN_YSIZE - height) / 2;
1295 SetDrawBackgroundMask(REDRAW_ALL);
1296 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1298 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1300 if (DrawingOnBackground(dst_x, dst_y))
1301 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1303 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1305 redraw_mask = REDRAW_ALL;
1308 void DrawTitleScreenMessage(int nr, boolean initial)
1310 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1311 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1312 int last_game_status = game_status; /* save current game status */
1314 if (filename == NULL)
1317 /* force TITLE font on title message screen */
1318 SetGameStatus(getTitleMessageGameMode(initial));
1320 /* if chars *and* width set to "-1", automatically determine width */
1321 if (tmi->chars == -1 && tmi->width == -1)
1322 tmi->width = viewport.window[game_status].width;
1324 /* if lines *and* height set to "-1", automatically determine height */
1325 if (tmi->lines == -1 && tmi->height == -1)
1326 tmi->height = viewport.window[game_status].height;
1328 /* if chars set to "-1", automatically determine by text and font width */
1329 if (tmi->chars == -1)
1330 tmi->chars = tmi->width / getFontWidth(tmi->font);
1332 tmi->width = tmi->chars * getFontWidth(tmi->font);
1334 /* if lines set to "-1", automatically determine by text and font height */
1335 if (tmi->lines == -1)
1336 tmi->lines = tmi->height / getFontHeight(tmi->font);
1338 tmi->height = tmi->lines * getFontHeight(tmi->font);
1340 /* if x set to "-1", automatically determine by width and alignment */
1342 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1344 /* if y set to "-1", automatically determine by height and alignment */
1346 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1348 SetDrawBackgroundMask(REDRAW_ALL);
1349 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1351 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1353 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1354 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1355 tmi->autowrap, tmi->centered, tmi->parse_comments);
1357 SetGameStatus(last_game_status); /* restore current game status */
1360 void DrawTitleScreen()
1362 KeyboardAutoRepeatOff();
1364 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 KeyboardAutoRepeatOn();
1404 audio.sound_deactivated = FALSE;
1408 /* needed if last screen was the playing screen, invoked from level editor */
1409 if (level_editor_test_game)
1411 CloseDoor(DOOR_CLOSE_ALL);
1413 SetGameStatus(GAME_MODE_EDITOR);
1420 /* needed if last screen was the setup screen and fullscreen state changed */
1421 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1422 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1424 /* leveldir_current may be invalid (level group, parent link) */
1425 if (!validLevelSeries(leveldir_current))
1426 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1428 if (leveldir_current != leveldir_last_valid)
1429 levelset_has_changed = TRUE;
1431 /* store valid level series information */
1432 leveldir_last_valid = leveldir_current;
1434 init_last = init; /* switch to new busy animation */
1436 /* needed if last screen (level choice) changed graphics, sounds or music */
1437 ReloadCustomArtwork(0);
1439 if (CheckTitleScreen(levelset_has_changed))
1441 game_status_last_screen = GAME_MODE_MAIN;
1443 SetGameStatus(GAME_MODE_TITLE);
1450 /* needed if different viewport properties defined for menues */
1451 ChangeViewportPropertiesIfNeeded();
1453 if (redraw_mask & REDRAW_ALL)
1454 fade_mask = REDRAW_ALL;
1456 if (CheckIfGlobalBorderHasChanged())
1457 fade_mask = REDRAW_ALL;
1461 SetDrawtoField(DRAW_BACKBUFFER);
1463 /* level_nr may have been set to value over handicap with level editor */
1464 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1465 level_nr = leveldir_current->handicap_level;
1467 LoadLevel(level_nr);
1468 LoadScore(level_nr);
1470 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1471 SetDrawDeactivationMask(REDRAW_NONE);
1472 SetDrawBackgroundMask(REDRAW_FIELD);
1474 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1477 if (fade_mask == REDRAW_ALL)
1478 RedrawGlobalBorder();
1483 InitializeMainControls();
1485 DrawCursorAndText_Main(-1, FALSE, FALSE);
1486 DrawPreviewLevelInitial();
1488 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1491 if (TAPE_IS_EMPTY(tape))
1493 DrawCompleteVideoDisplay();
1498 /* create gadgets for main menu screen */
1499 FreeScreenGadgets();
1500 CreateScreenGadgets();
1502 /* map gadgets for main menu screen */
1504 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1506 /* copy actual game door content to door double buffer for OpenDoor() */
1507 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1508 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1510 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1512 DrawMaskedBorder(fade_mask);
1517 /* update screen area with special editor door */
1518 redraw_mask |= REDRAW_ALL;
1521 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 last_sound = SND_UNDEFINED;
1574 last_music = MUS_UNDEFINED;
1576 if (num_title_screens != 0)
1578 FadeSetEnterScreen();
1580 /* use individual title fading instead of global "enter screen" fading */
1581 fading = getTitleFading(tci);
1584 if (game_status_last_screen == GAME_MODE_INFO)
1586 if (num_title_screens == 0)
1588 /* switch game mode from title screen mode back to info screen mode */
1589 SetGameStatus(GAME_MODE_INFO);
1591 DrawInfoScreen_NotAvailable("Title screen information:",
1592 "No title screen for this level set.");
1597 FadeSoundsAndMusic();
1600 FadeOut(REDRAW_ALL);
1602 /* only required to update logic for redrawing global border */
1605 /* title screens may have different window size */
1606 ChangeViewportPropertiesIfNeeded();
1609 DrawTitleScreenImage(tci->local_nr, tci->initial);
1611 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1613 sound = getTitleSound(tci);
1614 music = getTitleMusic(tci);
1616 if (sound != last_sound)
1617 PlayMenuSoundExt(sound);
1618 if (music != last_music)
1619 PlayMenuMusicExt(music);
1624 SetMouseCursor(CURSOR_NONE);
1628 DelayReached(&title_delay, 0); /* reset delay counter */
1633 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1634 button = MB_MENU_CHOICE;
1636 if (button == MB_MENU_LEAVE)
1638 return_to_main_menu = TRUE;
1640 else if (button == MB_MENU_CHOICE)
1642 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1644 SetGameStatus(GAME_MODE_INFO);
1646 info_mode = INFO_MODE_MAIN;
1654 tci = &title_controls[title_screen_nr];
1656 if (title_screen_nr < num_title_screens)
1658 sound = getTitleSound(tci);
1659 music = getTitleMusic(tci);
1661 if (sound == SND_UNDEFINED || sound != last_sound)
1663 if (music == MUS_UNDEFINED || music != last_music)
1666 fading = getTitleFading(tci);
1668 FadeOut(REDRAW_ALL);
1671 DrawTitleScreenImage(tci->local_nr, tci->initial);
1673 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1675 sound = getTitleSound(tci);
1676 music = getTitleMusic(tci);
1678 if (sound != last_sound)
1679 PlayMenuSoundExt(sound);
1680 if (music != last_music)
1681 PlayMenuMusicExt(music);
1688 DelayReached(&title_delay, 0); /* reset delay counter */
1692 FadeSoundsAndMusic();
1694 return_to_main_menu = TRUE;
1698 if (return_to_main_menu)
1700 SetMouseCursor(CURSOR_DEFAULT);
1702 /* force full menu screen redraw after displaying title screens */
1703 redraw_mask = REDRAW_ALL;
1705 if (game_status_last_screen == GAME_MODE_INFO)
1707 SetGameStatus(GAME_MODE_INFO);
1709 info_mode = INFO_MODE_MAIN;
1713 else /* default: return to main menu */
1715 SetGameStatus(GAME_MODE_MAIN);
1722 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1724 int old_level_nr = level_nr;
1727 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1728 new_level_nr = selected_level_nr;
1730 new_level_nr = old_level_nr + step * direction;
1732 if (new_level_nr < leveldir_current->first_level)
1733 new_level_nr = leveldir_current->first_level;
1734 if (new_level_nr > leveldir_current->last_level)
1735 new_level_nr = leveldir_current->last_level;
1737 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1739 /* skipping levels is only allowed when trying to skip single level */
1740 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1741 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1743 leveldir_current->handicap_level++;
1744 SaveLevelSetup_SeriesInfo();
1747 new_level_nr = leveldir_current->handicap_level;
1750 if (new_level_nr != old_level_nr)
1752 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1754 PlaySound(SND_MENU_ITEM_SELECTING);
1756 level_nr = new_level_nr;
1758 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1759 int2str(level_nr, menu.main.text.level_number.size),
1760 mci->pos_text->font);
1762 LoadLevel(level_nr);
1763 DrawPreviewLevelInitial();
1767 DrawCompleteVideoDisplay();
1769 /* needed because DrawPreviewLevelInitial() takes some time */
1771 /* SyncDisplay(); */
1775 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1777 static int choice = MAIN_CONTROL_GAME;
1778 static boolean button_pressed_last = FALSE;
1779 boolean button_pressed = FALSE;
1783 if (button == MB_MENU_INITIALIZE)
1785 DrawCursorAndText_Main(choice, TRUE, FALSE);
1790 if (mx || my) /* mouse input */
1794 for (i = 0; main_controls[i].nr != -1; i++)
1796 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1797 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1798 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1800 pos = main_controls[i].nr;
1806 // handle pressed/unpressed state for active/inactive menu buttons
1807 // (if pos != -1, "i" contains index position corresponding to "pos")
1809 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1810 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1811 button_pressed = TRUE;
1813 if (button_pressed != button_pressed_last)
1815 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1818 PlaySound(SND_MENU_BUTTON_PRESSING);
1820 PlaySound(SND_MENU_BUTTON_RELEASING);
1823 else if (dx || dy) /* keyboard input */
1825 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1826 choice == MAIN_CONTROL_SETUP))
1827 button = MB_MENU_CHOICE;
1832 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1834 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1836 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1838 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1840 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1842 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1844 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1848 CloseDoor(DOOR_CLOSE_2);
1850 SetGameStatus(GAME_MODE_LEVELNR);
1852 ChangeViewportPropertiesIfNeeded();
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)
1886 CloseDoor(DOOR_CLOSE_2);
1888 SetGameStatus(GAME_MODE_LEVELS);
1890 SaveLevelSetup_LastSeries();
1891 SaveLevelSetup_SeriesInfo();
1893 if (setup.internal.choose_from_top_leveldir)
1896 ChangeViewportPropertiesIfNeeded();
1898 DrawChooseLevelSet();
1901 else if (pos == MAIN_CONTROL_SCORES)
1905 CloseDoor(DOOR_CLOSE_2);
1907 SetGameStatus(GAME_MODE_SCORES);
1911 else if (pos == MAIN_CONTROL_EDITOR)
1913 if (leveldir_current->readonly &&
1914 !strEqual(setup.player_name, "Artsoft"))
1915 Request("This level is read only!", REQ_CONFIRM);
1919 CloseDoor(DOOR_CLOSE_2);
1921 SetGameStatus(GAME_MODE_EDITOR);
1923 FadeSetEnterScreen();
1927 else if (pos == MAIN_CONTROL_INFO)
1931 CloseDoor(DOOR_CLOSE_2);
1933 SetGameStatus(GAME_MODE_INFO);
1935 info_mode = INFO_MODE_MAIN;
1937 ChangeViewportPropertiesIfNeeded();
1941 else if (pos == MAIN_CONTROL_GAME)
1945 StartGameActions(options.network, setup.autorecord, level.random_seed);
1947 else if (pos == MAIN_CONTROL_SETUP)
1951 CloseDoor(DOOR_CLOSE_2);
1953 SetGameStatus(GAME_MODE_SETUP);
1955 setup_mode = SETUP_MODE_MAIN;
1957 ChangeViewportPropertiesIfNeeded();
1961 else if (pos == MAIN_CONTROL_QUIT)
1963 SaveLevelSetup_LastSeries();
1964 SaveLevelSetup_SeriesInfo();
1966 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1967 SetGameStatus(GAME_MODE_QUIT);
1972 button_pressed_last = button_pressed;
1976 /* ========================================================================= */
1977 /* info screen functions */
1978 /* ========================================================================= */
1980 static struct TokenInfo *info_info;
1981 static int num_info_info; /* number of info entries shown on screen */
1982 static int max_info_info; /* total number of info entries in list */
1984 static void execInfoTitleScreen()
1986 info_mode = INFO_MODE_TITLE;
1991 static void execInfoElements()
1993 info_mode = INFO_MODE_ELEMENTS;
1998 static void execInfoMusic()
2000 info_mode = INFO_MODE_MUSIC;
2005 static void execInfoCredits()
2007 info_mode = INFO_MODE_CREDITS;
2012 static void execInfoProgram()
2014 info_mode = INFO_MODE_PROGRAM;
2019 static void execInfoVersion()
2021 info_mode = INFO_MODE_VERSION;
2026 static void execInfoLevelSet()
2028 info_mode = INFO_MODE_LEVELSET;
2033 static void execExitInfo()
2035 SetGameStatus(GAME_MODE_MAIN);
2040 static struct TokenInfo info_info_main[] =
2042 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2043 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2044 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2045 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2046 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2047 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2048 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2049 { TYPE_EMPTY, NULL, "" },
2050 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2055 static int getMenuTextFont(int type)
2057 if (type & (TYPE_SWITCH |
2069 static struct TokenInfo *setup_info;
2070 static struct TokenInfo setup_info_input[];
2072 static struct TokenInfo *menu_info;
2074 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2075 int screen_pos, int menu_info_pos_raw,
2078 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2079 struct TokenInfo *ti = &token_info[pos];
2080 int xpos = MENU_SCREEN_START_XPOS;
2081 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2082 int font_nr = getMenuTextFont(ti->type);
2084 if (token_info == setup_info_input)
2085 font_nr = FONT_MENU_1;
2088 font_nr = FONT_ACTIVE(font_nr);
2090 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2092 if (ti->type & ~TYPE_SKIP_ENTRY)
2093 drawCursor(screen_pos, active);
2096 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2099 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2102 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2105 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2108 static char *window_size_text;
2109 static char *scaling_type_text;
2111 static void drawSetupValue(int, int);
2113 static void drawMenuInfoList(int first_entry, int num_page_entries,
2114 int max_page_entries)
2118 if (first_entry + num_page_entries > max_page_entries)
2121 clearMenuListArea();
2123 for (i = 0; i < num_page_entries; i++)
2125 int menu_info_pos = first_entry + i;
2126 struct TokenInfo *si = &menu_info[menu_info_pos];
2127 void *value_ptr = si->value;
2129 /* set some entries to "unchangeable" according to other variables */
2130 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2131 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2132 (value_ptr == &setup.sound_music && !audio.music_available) ||
2133 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2134 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2135 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2136 si->type |= TYPE_GHOSTED;
2138 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2139 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2140 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2141 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2142 else if (si->type & ~TYPE_SKIP_ENTRY)
2143 initCursor(i, IMG_MENU_BUTTON);
2145 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2147 if (si->type & TYPE_VALUE &&
2148 menu_info == setup_info)
2149 drawSetupValue(i, menu_info_pos);
2153 static void DrawInfoScreen_Main()
2155 int fade_mask = REDRAW_FIELD;
2158 if (redraw_mask & REDRAW_ALL)
2159 fade_mask = REDRAW_ALL;
2161 if (CheckIfGlobalBorderHasChanged())
2162 fade_mask = REDRAW_ALL;
2166 FreeScreenGadgets();
2167 CreateScreenGadgets();
2169 /* (needed after displaying title screens which disable auto repeat) */
2170 KeyboardAutoRepeatOn();
2172 FadeSetLeaveScreen();
2176 ChangeViewportPropertiesIfNeeded();
2180 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2182 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2184 info_info = info_info_main;
2186 // determine maximal number of info entries that can be displayed on screen
2188 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2191 // determine maximal number of info entries available for menu of info screen
2193 for (i = 0; info_info[i].type != 0; i++)
2196 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2198 MapScreenGadgets(max_info_info);
2203 DrawMaskedBorder(fade_mask);
2210 static void changeSetupValue(int, int, int);
2212 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2213 int mode, int num_page_entries, int max_page_entries)
2215 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2216 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2217 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2218 int *num_page_entries_last = num_page_entries_all_last[game_status];
2219 int *choice_store = choice_stores[game_status];
2220 int *first_entry_store = first_entry_stores[game_status];
2221 int choice = choice_store[mode]; /* starts with 0 */
2222 int first_entry = first_entry_store[mode]; /* starts with 0 */
2224 int y = choice - first_entry;
2226 boolean position_set_by_scrollbar = (dx == 999);
2227 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2230 if (button == MB_MENU_INITIALIZE)
2232 // check if number of menu page entries has changed (may happen by change
2233 // of custom artwork definition value for 'list_size' for this menu screen)
2234 // (in this case, the last menu position most probably has to be corrected)
2235 if (num_page_entries != num_page_entries_last[mode])
2237 choice_store[mode] = first_entry_store[mode] = 0;
2239 choice = first_entry = 0;
2242 num_page_entries_last[mode] = num_page_entries;
2245 /* advance to first valid menu entry */
2246 while (choice < num_page_entries &&
2247 menu_info[choice].type & TYPE_SKIP_ENTRY)
2250 if (position_set_by_scrollbar)
2251 first_entry = first_entry_store[mode] = dy;
2253 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2254 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2256 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2258 if (choice < first_entry)
2260 choice = first_entry;
2262 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2265 else if (choice > first_entry + num_page_entries - 1)
2267 choice = first_entry + num_page_entries - 1;
2269 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2273 choice_store[mode] = choice;
2275 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2279 else if (button == MB_MENU_LEAVE)
2281 PlaySound(SND_MENU_ITEM_SELECTING);
2283 for (i = 0; i < max_page_entries; i++)
2285 if (menu_info[i].type & TYPE_LEAVE_MENU)
2287 void (*menu_callback_function)(void) = menu_info[i].value;
2291 menu_callback_function();
2293 break; /* absolutely needed because function changes 'menu_info'! */
2300 if (mx || my) /* mouse input */
2302 x = (mx - mSX) / 32;
2303 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2305 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2307 /* move cursor instead of scrolling when already at start/end of list */
2308 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2310 else if (dy == +1 * SCROLL_LINE &&
2311 first_entry + num_page_entries == max_page_entries)
2314 /* handle scrolling screen one line or page */
2316 y + dy > num_page_entries - 1)
2318 boolean redraw = FALSE;
2320 if (ABS(dy) == SCROLL_PAGE)
2321 step = num_page_entries - 1;
2323 if (dy < 0 && first_entry > 0)
2325 /* scroll page/line up */
2327 first_entry -= step;
2328 if (first_entry < 0)
2333 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2335 /* scroll page/line down */
2337 first_entry += step;
2338 if (first_entry + num_page_entries > max_page_entries)
2339 first_entry = MAX(0, max_page_entries - num_page_entries);
2346 choice += first_entry - first_entry_store[mode];
2348 if (choice < first_entry)
2350 choice = first_entry;
2352 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2355 else if (choice > first_entry + num_page_entries - 1)
2357 choice = first_entry + num_page_entries - 1;
2359 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2362 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2366 if (choice < first_entry ||
2367 choice > first_entry + num_page_entries - 1)
2368 first_entry += SIGN(dy);
2371 first_entry_store[mode] = first_entry;
2372 choice_store[mode] = choice;
2374 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2376 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2378 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2379 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2387 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2389 if (menu_info[choice].type & menu_navigation_type ||
2390 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2391 menu_info[choice].type & TYPE_YES_NO_AUTO)
2392 button = MB_MENU_CHOICE;
2397 /* jump to next non-empty menu entry (up or down) */
2398 while (first_entry + y > 0 &&
2399 first_entry + y < max_page_entries - 1 &&
2400 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2403 if (!IN_VIS_MENU(x, y))
2405 choice += y - y_old;
2407 if (choice < first_entry)
2408 first_entry = choice;
2409 else if (choice > first_entry + num_page_entries - 1)
2410 first_entry = choice - num_page_entries + 1;
2412 if (first_entry >= 0 &&
2413 first_entry + num_page_entries <= max_page_entries)
2415 first_entry_store[mode] = first_entry;
2417 if (choice < first_entry)
2418 choice = first_entry;
2419 else if (choice > first_entry + num_page_entries - 1)
2420 choice = first_entry + num_page_entries - 1;
2422 choice_store[mode] = choice;
2424 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2426 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2428 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2429 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2436 if (!anyScrollbarGadgetActive() &&
2437 IN_VIS_MENU(x, y) &&
2438 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2439 y >= 0 && y < num_page_entries)
2443 if (first_entry + y != choice &&
2444 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2446 PlaySound(SND_MENU_ITEM_ACTIVATING);
2448 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2449 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2451 choice = choice_store[mode] = first_entry + y;
2454 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2456 PlaySound(SND_MENU_ITEM_SELECTING);
2458 /* when selecting key headline, execute function for key value change */
2459 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2460 menu_info[first_entry + y + 1].type & TYPE_KEY)
2463 /* when selecting string value, execute function for list selection */
2464 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2465 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2468 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2470 void (*menu_callback_function)(void) =
2471 menu_info[first_entry + y].value;
2473 FadeSetFromType(menu_info[first_entry + y].type);
2475 menu_callback_function();
2477 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2478 menu_info == setup_info)
2480 changeSetupValue(y, first_entry + y, dx);
2486 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2488 menu_info = info_info;
2490 HandleMenuScreen(mx, my, dx, dy, button,
2491 info_mode, num_info_info, max_info_info);
2494 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2496 int ystart1 = mSY - SY + 100;
2497 int ystart2 = mSY - SY + 150;
2498 int ybottom = mSY - SY + SYSIZE - 20;
2500 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2502 FadeOut(REDRAW_FIELD);
2507 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2508 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2510 DrawTextSCentered(ybottom, FONT_TEXT_4,
2511 "Press any key or button for info menu");
2513 FadeIn(REDRAW_FIELD);
2516 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2518 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2519 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2520 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2521 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2522 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2523 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2524 int ystep = MENU_SCREEN_INFO_YSTEP;
2525 int element, action, direction;
2533 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2534 infoscreen_step[i] = infoscreen_frame[i] = 0;
2539 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2541 DrawTextSCentered(ybottom, FONT_TEXT_4,
2542 "Press any key or button for next page");
2548 while (helpanim_info[j].element != HELPANIM_LIST_END)
2550 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2555 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2564 j += infoscreen_step[i - start];
2566 element = helpanim_info[j].element;
2567 action = helpanim_info[j].action;
2568 direction = helpanim_info[j].direction;
2571 element = EL_UNKNOWN;
2573 if (action != -1 && direction != -1)
2574 graphic = el_act_dir2img(element, action, direction);
2575 else if (action != -1)
2576 graphic = el_act2img(element, action);
2577 else if (direction != -1)
2578 graphic = el_dir2img(element, direction);
2580 graphic = el2img(element);
2582 delay = helpanim_info[j++].delay;
2587 if (infoscreen_frame[i - start] == 0)
2590 infoscreen_frame[i - start] = delay - 1;
2594 sync_frame = delay - infoscreen_frame[i - start];
2595 infoscreen_frame[i - start]--;
2598 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2600 if (!infoscreen_frame[i - start])
2601 infoscreen_step[i - start] = 0;
2605 if (!infoscreen_frame[i - start])
2606 infoscreen_step[i - start]++;
2607 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2613 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2615 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2616 graphic, sync_frame, USE_MASKING);
2619 DrawInfoScreen_HelpText(element, action, direction, i - start);
2624 redraw_mask |= REDRAW_FIELD;
2629 static char *getHelpText(int element, int action, int direction)
2631 char token[MAX_LINE_LEN];
2633 strcpy(token, element_info[element].token_name);
2636 strcat(token, element_action_info[action].suffix);
2638 if (direction != -1)
2639 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2641 return getHashEntry(helptext_info, token);
2644 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2646 int font_nr = FONT_INFO_ELEMENTS;
2647 int font_width = getFontWidth(font_nr);
2648 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2649 int sy = mSY + 65 + 2 * 32 + 1;
2650 int ystep = TILEY + 4;
2651 int pad_x = sx - SX;
2652 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2653 int max_lines_per_text = 2;
2656 if (action != -1 && direction != -1) /* element.action.direction */
2657 text = getHelpText(element, action, direction);
2659 if (text == NULL && action != -1) /* element.action */
2660 text = getHelpText(element, action, -1);
2662 if (text == NULL && direction != -1) /* element.direction */
2663 text = getHelpText(element, -1, direction);
2665 if (text == NULL) /* base element */
2666 text = getHelpText(element, -1, -1);
2668 if (text == NULL) /* not found */
2669 text = "No description available";
2671 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2672 sy += getFontHeight(font_nr) / 2;
2674 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2675 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2676 TRUE, FALSE, FALSE);
2679 void DrawInfoScreen_TitleScreen()
2681 game_status_last_screen = GAME_MODE_INFO;
2683 SetGameStatus(GAME_MODE_TITLE);
2688 void HandleInfoScreen_TitleScreen(int button)
2690 HandleTitleScreen(0, 0, 0, 0, button);
2693 void DrawInfoScreen_Elements()
2695 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2697 FadeOut(REDRAW_FIELD);
2702 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2704 FadeIn(REDRAW_FIELD);
2709 void HandleInfoScreen_Elements(int button)
2711 static unsigned int info_delay = 0;
2712 static int num_anims;
2713 static int num_pages;
2715 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2718 if (button == MB_MENU_INITIALIZE)
2720 boolean new_element = TRUE;
2724 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2726 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2728 else if (new_element)
2731 new_element = FALSE;
2735 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2739 if (button == MB_MENU_LEAVE)
2741 PlaySound(SND_MENU_ITEM_SELECTING);
2743 info_mode = INFO_MODE_MAIN;
2748 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2750 if (button != MB_MENU_INITIALIZE)
2752 PlaySound(SND_MENU_ITEM_SELECTING);
2757 if (page >= num_pages)
2759 FadeSoundsAndMusic();
2761 info_mode = INFO_MODE_MAIN;
2768 FadeSetNextScreen();
2770 if (button != MB_MENU_INITIALIZE)
2771 FadeOut(REDRAW_FIELD);
2773 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2775 if (button != MB_MENU_INITIALIZE)
2776 FadeIn(REDRAW_FIELD);
2780 if (DelayReached(&info_delay, GameFrameDelay))
2781 if (page < num_pages)
2782 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2784 PlayMenuSoundIfLoop();
2788 void DrawInfoScreen_Music()
2790 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2792 FadeOut(REDRAW_FIELD);
2799 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2801 FadeIn(REDRAW_FIELD);
2804 void HandleInfoScreen_Music(int button)
2806 static struct MusicFileInfo *list = NULL;
2807 int ystart1 = mSY - SY + 100;
2808 int ystart2 = mSY - SY + 150;
2809 int ybottom = mSY - SY + SYSIZE - 20;
2812 if (button == MB_MENU_INITIALIZE)
2814 list = music_file_info;
2818 FadeSoundsAndMusic();
2823 DrawTextSCentered(ystart1, FONT_TEXT_1,
2824 "No music info for this level set.");
2826 DrawTextSCentered(ybottom, FONT_TEXT_4,
2827 "Press any key or button for info menu");
2833 if (button == MB_MENU_LEAVE)
2835 PlaySound(SND_MENU_ITEM_SELECTING);
2837 FadeSoundsAndMusic();
2839 info_mode = INFO_MODE_MAIN;
2844 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2848 if (button != MB_MENU_INITIALIZE)
2850 PlaySound(SND_MENU_ITEM_SELECTING);
2858 FadeSoundsAndMusic();
2860 info_mode = INFO_MODE_MAIN;
2866 FadeSoundsAndMusic();
2868 if (list != music_file_info)
2869 FadeSetNextScreen();
2871 if (button != MB_MENU_INITIALIZE)
2872 FadeOut(REDRAW_FIELD);
2879 int sound = list->music;
2881 if (sound_info[sound].loop)
2882 PlaySoundLoop(sound);
2886 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2890 PlayMusic(list->music);
2892 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2895 if (!strEqual(list->title, UNKNOWN_NAME))
2897 if (!strEqual(list->title_header, UNKNOWN_NAME))
2898 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2900 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2903 if (!strEqual(list->artist, UNKNOWN_NAME))
2905 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2906 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2908 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2910 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2913 if (!strEqual(list->album, UNKNOWN_NAME))
2915 if (!strEqual(list->album_header, UNKNOWN_NAME))
2916 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2918 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2920 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2923 if (!strEqual(list->year, UNKNOWN_NAME))
2925 if (!strEqual(list->year_header, UNKNOWN_NAME))
2926 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2928 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2930 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2933 DrawTextSCentered(ybottom, FONT_TEXT_4,
2934 "Press any key or button for next page");
2936 if (button != MB_MENU_INITIALIZE)
2937 FadeIn(REDRAW_FIELD);
2940 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2941 PlaySoundLoop(list->music);
2944 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2946 int ystart1 = mSY - SY + 100;
2947 int ystart2 = mSY - SY + 150;
2948 int ybottom = mSY - SY + SYSIZE - 20;
2954 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2958 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2959 "Special thanks to");
2960 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2962 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2964 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2965 "\"Boulder Dash\"");
2966 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2968 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2970 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2972 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2973 "First Star Software");
2975 else if (screen_nr == 1)
2977 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2978 "Special thanks to");
2979 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2980 "Klaus Heinz & Volker Wertich");
2981 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2983 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2984 "\"Emerald Mine\"");
2985 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2987 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2989 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2991 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2994 else if (screen_nr == 2)
2996 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2997 "Special thanks to");
2998 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2999 "Michael Stopp & Philip Jespersen");
3000 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3002 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3004 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3006 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3008 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3010 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3011 "Digital Integration");
3013 else if (screen_nr == 3)
3015 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3016 "Special thanks to");
3017 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3018 "Hiroyuki Imabayashi");
3019 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3021 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3023 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3025 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3027 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3029 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3032 else if (screen_nr == 4)
3034 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3035 "Special thanks to");
3036 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3038 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3040 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3041 "J\xfcrgen Bonhagen");
3042 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3043 "for the continuous creation");
3044 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3045 "of outstanding level sets");
3047 else if (screen_nr == 5)
3049 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3051 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3053 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3054 "for ideas and inspiration by");
3055 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3058 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3060 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3062 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3063 "for ideas and inspiration by");
3064 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3067 else if (screen_nr == 6)
3069 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3071 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3074 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3075 "for the code base used for the");
3076 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3077 "native Emerald Mine engine");
3079 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3080 "for the new Emerald Mine engine");
3083 else if (screen_nr == 7)
3085 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3087 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3089 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3090 "for the initial DOS port");
3092 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3094 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3096 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3097 "for some additional toons");
3099 else if (screen_nr == 8)
3101 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3102 "And not to forget:");
3103 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3105 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3106 "All those who contributed");
3107 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3108 "levels to this game");
3109 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3113 DrawTextSCentered(ybottom, FONT_TEXT_4,
3114 "Press any key or button for next page");
3117 void DrawInfoScreen_Credits()
3119 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3121 FadeSoundsAndMusic();
3123 FadeOut(REDRAW_FIELD);
3125 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3127 FadeIn(REDRAW_FIELD);
3130 void HandleInfoScreen_Credits(int button)
3132 static int screen_nr = 0;
3133 int num_screens = 9;
3135 if (button == MB_MENU_INITIALIZE)
3139 // DrawInfoScreen_CreditsScreen(screen_nr);
3142 if (button == MB_MENU_LEAVE)
3144 PlaySound(SND_MENU_ITEM_SELECTING);
3146 info_mode = INFO_MODE_MAIN;
3151 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3153 if (button != MB_MENU_INITIALIZE)
3155 PlaySound(SND_MENU_ITEM_SELECTING);
3160 if (screen_nr >= num_screens)
3162 FadeSoundsAndMusic();
3164 info_mode = INFO_MODE_MAIN;
3171 FadeSetNextScreen();
3173 if (button != MB_MENU_INITIALIZE)
3174 FadeOut(REDRAW_FIELD);
3176 DrawInfoScreen_CreditsScreen(screen_nr);
3178 if (button != MB_MENU_INITIALIZE)
3179 FadeIn(REDRAW_FIELD);
3183 PlayMenuSoundIfLoop();
3187 void DrawInfoScreen_Program()
3189 int ystart1 = mSY - SY + 100;
3190 int ystart2 = mSY - SY + 150;
3191 int ybottom = mSY - SY + SYSIZE - 20;
3194 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3196 FadeOut(REDRAW_FIELD);
3201 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3203 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3204 "This game is Freeware!");
3205 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3206 "If you like it, send e-mail to:");
3207 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3208 setup.internal.program_email);
3209 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3210 "More information and levels:");
3211 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3212 setup.internal.program_website);
3213 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3214 "If you have created new levels,");
3215 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3216 "send them to me to include them!");
3217 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3220 DrawTextSCentered(ybottom, FONT_TEXT_4,
3221 "Press any key or button for info menu");
3223 FadeIn(REDRAW_FIELD);
3226 void HandleInfoScreen_Program(int button)
3228 if (button == MB_MENU_LEAVE)
3230 PlaySound(SND_MENU_ITEM_SELECTING);
3232 info_mode = INFO_MODE_MAIN;
3237 else if (button == MB_MENU_CHOICE)
3239 PlaySound(SND_MENU_ITEM_SELECTING);
3241 FadeSoundsAndMusic();
3243 info_mode = INFO_MODE_MAIN;
3248 PlayMenuSoundIfLoop();
3252 void DrawInfoScreen_Version()
3254 int font_header = FONT_TEXT_3;
3255 int font_text = FONT_TEXT_2;
3256 int xstep = getFontWidth(font_text);
3257 int ystep = getFontHeight(font_text);
3258 int ystart1 = mSY - SY + 100;
3259 int ystart2 = mSY - SY + 150;
3260 int ybottom = mSY - SY + SYSIZE - 20;
3261 int xstart1 = mSX - SX + 2 * xstep;
3262 int xstart2 = mSX - SX + 18 * xstep;
3263 int xstart3 = mSX - SX + 28 * xstep;
3264 SDL_version sdl_version_compiled;
3265 const SDL_version *sdl_version_linked;
3266 int driver_name_len = 10;
3267 #if defined(TARGET_SDL2)
3268 SDL_version sdl_version_linked_ext;
3269 const char *driver_name = NULL;
3271 char driver_name[driver_name_len];
3274 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3276 FadeOut(REDRAW_FIELD);
3281 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3283 DrawTextF(xstart1, ystart2, font_header, "Name");
3284 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3287 DrawTextF(xstart1, ystart2, font_header, "Version");
3288 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3291 DrawTextF(xstart1, ystart2, font_header, "Platform");
3292 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3295 DrawTextF(xstart1, ystart2, font_header, "Target");
3296 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3299 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3300 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3302 ystart2 += 3 * ystep;
3303 DrawTextF(xstart1, ystart2, font_header, "Library");
3304 DrawTextF(xstart2, ystart2, font_header, "compiled");
3305 DrawTextF(xstart3, ystart2, font_header, "linked");
3307 SDL_VERSION(&sdl_version_compiled);
3308 #if defined(TARGET_SDL2)
3309 SDL_GetVersion(&sdl_version_linked_ext);
3310 sdl_version_linked = &sdl_version_linked_ext;
3312 sdl_version_linked = SDL_Linked_Version();
3315 ystart2 += 2 * ystep;
3316 DrawTextF(xstart1, ystart2, font_text, "SDL");
3317 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3318 sdl_version_compiled.major,
3319 sdl_version_compiled.minor,
3320 sdl_version_compiled.patch);
3321 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3322 sdl_version_linked->major,
3323 sdl_version_linked->minor,
3324 sdl_version_linked->patch);
3326 SDL_IMAGE_VERSION(&sdl_version_compiled);
3327 sdl_version_linked = IMG_Linked_Version();
3330 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3331 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3332 sdl_version_compiled.major,
3333 sdl_version_compiled.minor,
3334 sdl_version_compiled.patch);
3335 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3336 sdl_version_linked->major,
3337 sdl_version_linked->minor,
3338 sdl_version_linked->patch);
3340 SDL_MIXER_VERSION(&sdl_version_compiled);
3341 sdl_version_linked = Mix_Linked_Version();
3344 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3345 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3346 sdl_version_compiled.major,
3347 sdl_version_compiled.minor,
3348 sdl_version_compiled.patch);
3349 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3350 sdl_version_linked->major,
3351 sdl_version_linked->minor,
3352 sdl_version_linked->patch);
3354 SDL_NET_VERSION(&sdl_version_compiled);
3355 sdl_version_linked = SDLNet_Linked_Version();
3358 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3359 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3360 sdl_version_compiled.major,
3361 sdl_version_compiled.minor,
3362 sdl_version_compiled.patch);
3363 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3364 sdl_version_linked->major,
3365 sdl_version_linked->minor,
3366 sdl_version_linked->patch);
3368 ystart2 += 3 * ystep;
3369 DrawTextF(xstart1, ystart2, font_header, "Driver");
3370 DrawTextF(xstart2, ystart2, font_header, "Requested");
3371 DrawTextF(xstart3, ystart2, font_header, "Used");
3373 #if defined(TARGET_SDL2)
3374 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3376 SDL_VideoDriverName(driver_name, driver_name_len);
3379 ystart2 += 2 * ystep;
3380 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3381 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3382 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3384 #if defined(TARGET_SDL2)
3385 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3387 SDL_AudioDriverName(driver_name, driver_name_len);
3391 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3392 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3393 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3395 DrawTextSCentered(ybottom, FONT_TEXT_4,
3396 "Press any key or button for info menu");
3398 FadeIn(REDRAW_FIELD);
3401 void HandleInfoScreen_Version(int button)
3403 if (button == MB_MENU_LEAVE)
3405 PlaySound(SND_MENU_ITEM_SELECTING);
3407 info_mode = INFO_MODE_MAIN;
3412 else if (button == MB_MENU_CHOICE)
3414 PlaySound(SND_MENU_ITEM_SELECTING);
3416 FadeSoundsAndMusic();
3418 info_mode = INFO_MODE_MAIN;
3423 PlayMenuSoundIfLoop();
3427 void DrawInfoScreen_LevelSet()
3429 struct TitleMessageInfo *tmi = &readme;
3430 char *filename = getLevelSetInfoFilename();
3431 char *title = "Level Set Information:";
3432 int ystart1 = mSY - SY + 100;
3433 int ybottom = mSY - SY + SYSIZE - 20;
3435 if (filename == NULL)
3437 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3442 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3444 FadeOut(REDRAW_FIELD);
3449 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3451 /* if x position set to "-1", automatically determine by playfield width */
3453 tmi->x = SXSIZE / 2;
3455 /* if y position set to "-1", use static default value */
3459 /* if width set to "-1", automatically determine by playfield width */
3460 if (tmi->width == -1)
3461 tmi->width = SXSIZE - 2 * TILEX;
3463 /* if height set to "-1", automatically determine by playfield height */
3464 if (tmi->height == -1)
3465 tmi->height = SYSIZE - 20 - tmi->y - 10;
3467 /* if chars set to "-1", automatically determine by text and font width */
3468 if (tmi->chars == -1)
3469 tmi->chars = tmi->width / getFontWidth(tmi->font);
3471 tmi->width = tmi->chars * getFontWidth(tmi->font);
3473 /* if lines set to "-1", automatically determine by text and font height */
3474 if (tmi->lines == -1)
3475 tmi->lines = tmi->height / getFontHeight(tmi->font);
3477 tmi->height = tmi->lines * getFontHeight(tmi->font);
3479 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3480 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3481 tmi->autowrap, tmi->centered, tmi->parse_comments);
3483 DrawTextSCentered(ybottom, FONT_TEXT_4,
3484 "Press any key or button for info menu");
3486 FadeIn(REDRAW_FIELD);
3489 void HandleInfoScreen_LevelSet(int button)
3491 if (button == MB_MENU_LEAVE)
3493 PlaySound(SND_MENU_ITEM_SELECTING);
3495 info_mode = INFO_MODE_MAIN;
3500 else if (button == MB_MENU_CHOICE)
3502 PlaySound(SND_MENU_ITEM_SELECTING);
3504 FadeSoundsAndMusic();
3506 info_mode = INFO_MODE_MAIN;
3511 PlayMenuSoundIfLoop();
3515 static void DrawInfoScreen()
3517 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3519 if (info_mode == INFO_MODE_TITLE)
3520 DrawInfoScreen_TitleScreen();
3521 else if (info_mode == INFO_MODE_ELEMENTS)
3522 DrawInfoScreen_Elements();
3523 else if (info_mode == INFO_MODE_MUSIC)
3524 DrawInfoScreen_Music();
3525 else if (info_mode == INFO_MODE_CREDITS)
3526 DrawInfoScreen_Credits();
3527 else if (info_mode == INFO_MODE_PROGRAM)
3528 DrawInfoScreen_Program();
3529 else if (info_mode == INFO_MODE_VERSION)
3530 DrawInfoScreen_Version();
3531 else if (info_mode == INFO_MODE_LEVELSET)
3532 DrawInfoScreen_LevelSet();
3534 DrawInfoScreen_Main();
3536 if (info_mode != INFO_MODE_MAIN &&
3537 info_mode != INFO_MODE_TITLE &&
3538 info_mode != INFO_MODE_MUSIC)
3545 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3547 if (info_mode == INFO_MODE_TITLE)
3548 HandleInfoScreen_TitleScreen(button);
3549 else if (info_mode == INFO_MODE_ELEMENTS)
3550 HandleInfoScreen_Elements(button);
3551 else if (info_mode == INFO_MODE_MUSIC)
3552 HandleInfoScreen_Music(button);
3553 else if (info_mode == INFO_MODE_CREDITS)
3554 HandleInfoScreen_Credits(button);
3555 else if (info_mode == INFO_MODE_PROGRAM)
3556 HandleInfoScreen_Program(button);
3557 else if (info_mode == INFO_MODE_VERSION)
3558 HandleInfoScreen_Version(button);
3559 else if (info_mode == INFO_MODE_LEVELSET)
3560 HandleInfoScreen_LevelSet(button);
3562 HandleInfoScreen_Main(mx, my, dx, dy, button);
3566 /* ========================================================================= */
3567 /* type name functions */
3568 /* ========================================================================= */
3570 void HandleTypeName(int newxpos, Key key)
3572 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3573 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3574 struct TextPosInfo *pos = mci->pos_input;
3575 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3576 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3577 static int xpos = 0;
3578 int font_nr = pos->font;
3579 int font_active_nr = FONT_ACTIVE(font_nr);
3580 int font_width = getFontWidth(font_active_nr);
3581 char key_char = getValidConfigValueChar(getCharFromKey(key));
3582 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3583 boolean is_active = TRUE;
3585 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3589 strcpy(last_player_name, setup.player_name);
3593 #if defined(TARGET_SDL2)
3594 SDL_StartTextInput();
3597 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3599 setup.player_name[xpos] = key_char;
3600 setup.player_name[xpos + 1] = 0;
3604 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3608 setup.player_name[xpos] = 0;
3610 else if (key == KSYM_Return && xpos > 0)
3616 SetGameStatus(GAME_MODE_MAIN);
3618 else if (key == KSYM_Escape)
3620 strcpy(setup.player_name, last_player_name);
3624 SetGameStatus(GAME_MODE_MAIN);
3629 pos->width = (strlen(setup.player_name) + 1) * font_width;
3630 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3632 DrawText(startx, starty, setup.player_name, font_active_nr);
3633 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3637 pos->width = strlen(setup.player_name) * font_width;
3638 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3640 DrawText(startx, starty, setup.player_name, font_nr);
3642 #if defined(TARGET_SDL2)
3643 SDL_StopTextInput();
3649 /* ========================================================================= */
3650 /* tree menu functions */
3651 /* ========================================================================= */
3653 static void DrawChooseTree(TreeInfo **ti_ptr)
3655 int fade_mask = REDRAW_FIELD;
3657 if (CheckIfGlobalBorderHasChanged())
3658 fade_mask = REDRAW_ALL;
3660 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3662 SetGameStatus(GAME_MODE_MAIN);
3671 FreeScreenGadgets();
3672 CreateScreenGadgets();
3678 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3680 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3681 MapScreenTreeGadgets(*ti_ptr);
3683 DrawMaskedBorder(fade_mask);
3690 static void drawChooseTreeList(int first_entry, int num_page_entries,
3694 char *title_string = NULL;
3695 int yoffset_sets = MENU_TITLE1_YPOS;
3696 int yoffset_setup = 16;
3697 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3698 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3699 int last_game_status = game_status; /* save current game status */
3701 title_string = ti->infotext;
3703 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3705 clearMenuListArea();
3707 for (i = 0; i < num_page_entries; i++)
3709 TreeInfo *node, *node_first;
3710 int entry_pos = first_entry + i;
3711 int xpos = MENU_SCREEN_START_XPOS;
3712 int ypos = MENU_SCREEN_START_YPOS + i;
3713 int startx = mSX + xpos * 32;
3714 int starty = mSY + ypos * 32;
3715 int font_nr = FONT_TEXT_1;
3716 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3717 int startx_text = startx + font_xoffset;
3718 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3719 int text_size = startx_scrollbar - startx_text;
3720 int max_buffer_len = text_size / getFontWidth(font_nr);
3721 char buffer[max_buffer_len + 1];
3723 node_first = getTreeInfoFirstGroupEntry(ti);
3724 node = getTreeInfoFromPos(node_first, entry_pos);
3726 strncpy(buffer, node->name, max_buffer_len);
3727 buffer[max_buffer_len] = '\0';
3729 DrawText(startx, starty, buffer, font_nr + node->color);
3731 if (node->parent_link)
3732 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3733 else if (node->level_group)
3734 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3736 initCursor(i, IMG_MENU_BUTTON);
3739 SetGameStatus(last_game_status); /* restore current game status */
3741 redraw_mask |= REDRAW_FIELD;
3744 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3746 TreeInfo *node, *node_first;
3747 int x, last_redraw_mask = redraw_mask;
3748 int ypos = MENU_TITLE2_YPOS;
3749 int font_nr = FONT_TITLE_2;
3751 if (ti->type == TREE_TYPE_LEVEL_NR)
3752 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3754 if (ti->type != TREE_TYPE_LEVEL_DIR)
3757 node_first = getTreeInfoFirstGroupEntry(ti);
3758 node = getTreeInfoFromPos(node_first, entry_pos);
3760 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3762 if (node->parent_link)
3763 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3764 node->node_parent->name);
3765 else if (node->level_group)
3766 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3768 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3769 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3770 node->levels, (node->levels > 1 ? "levels" : "level"),
3773 /* let BackToFront() redraw only what is needed */
3774 redraw_mask = last_redraw_mask;
3775 for (x = 0; x < SCR_FIELDX; x++)
3776 MarkTileDirty(x, 1);
3779 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3782 TreeInfo *ti = *ti_ptr;
3784 int y = ti->cl_cursor;
3785 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3786 int num_entries = numTreeInfoInGroup(ti);
3787 int num_page_entries;
3788 int last_game_status = game_status; /* save current game status */
3789 boolean position_set_by_scrollbar = (dx == 999);
3791 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3792 num_page_entries = num_entries;
3794 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3796 SetGameStatus(last_game_status); /* restore current game status */
3798 if (button == MB_MENU_INITIALIZE)
3800 int num_entries = numTreeInfoInGroup(ti);
3801 int entry_pos = posTreeInfo(ti);
3803 if (ti->cl_first == -1)
3805 /* only on initialization */
3806 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3807 ti->cl_cursor = entry_pos - ti->cl_first;
3809 else if (ti->cl_cursor >= num_page_entries ||
3810 (num_entries > num_page_entries &&
3811 num_entries - ti->cl_first < num_page_entries))
3813 /* only after change of list size (by custom graphic configuration) */
3814 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3815 ti->cl_cursor = entry_pos - ti->cl_first;
3818 if (position_set_by_scrollbar)
3821 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3824 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3825 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3826 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3830 else if (button == MB_MENU_LEAVE)
3834 PlaySound(SND_MENU_ITEM_SELECTING);
3836 if (ti->node_parent)
3838 *ti_ptr = ti->node_parent;
3839 DrawChooseTree(ti_ptr);
3841 else if (game_status == GAME_MODE_SETUP)
3843 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3844 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3845 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3847 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3848 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
3849 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
3850 execSetupGraphics();
3851 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3852 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3853 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3855 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3856 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3857 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3864 if (game_status == GAME_MODE_LEVELNR)
3866 int new_level_nr = atoi(level_number_current->identifier);
3868 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3871 SetGameStatus(GAME_MODE_MAIN);
3879 if (mx || my) /* mouse input */
3881 int last_game_status = game_status; /* save current game status */
3883 x = (mx - mSX) / 32;
3884 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3886 SetGameStatus(last_game_status); /* restore current game status */
3888 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3890 /* move cursor instead of scrolling when already at start/end of list */
3891 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3893 else if (dy == +1 * SCROLL_LINE &&
3894 ti->cl_first + num_page_entries == num_entries)
3897 /* handle scrolling screen one line or page */
3898 if (ti->cl_cursor + dy < 0 ||
3899 ti->cl_cursor + dy > num_page_entries - 1)
3901 boolean redraw = FALSE;
3903 if (ABS(dy) == SCROLL_PAGE)
3904 step = num_page_entries - 1;
3906 if (dy < 0 && ti->cl_first > 0)
3908 /* scroll page/line up */
3910 ti->cl_first -= step;
3911 if (ti->cl_first < 0)
3916 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3918 /* scroll page/line down */
3920 ti->cl_first += step;
3921 if (ti->cl_first + num_page_entries > num_entries)
3922 ti->cl_first = MAX(0, num_entries - num_page_entries);
3929 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3930 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3931 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3933 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3940 /* handle moving cursor one line */
3941 y = ti->cl_cursor + dy;
3946 TreeInfo *node_first, *node_cursor;
3947 int entry_pos = ti->cl_first + y;
3949 node_first = getTreeInfoFirstGroupEntry(ti);
3950 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3952 if (node_cursor->node_group)
3956 PlaySound(SND_MENU_ITEM_SELECTING);
3958 node_cursor->cl_first = ti->cl_first;
3959 node_cursor->cl_cursor = ti->cl_cursor;
3960 *ti_ptr = node_cursor->node_group;
3961 DrawChooseTree(ti_ptr);
3966 else if (dx == -1 && ti->node_parent)
3970 PlaySound(SND_MENU_ITEM_SELECTING);
3972 *ti_ptr = ti->node_parent;
3973 DrawChooseTree(ti_ptr);
3978 if (!anyScrollbarGadgetActive() &&
3979 IN_VIS_MENU(x, y) &&
3980 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3981 y >= 0 && y < num_page_entries)
3985 if (y != ti->cl_cursor)
3987 PlaySound(SND_MENU_ITEM_ACTIVATING);
3989 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3990 drawChooseTreeCursor(y, TRUE);
3991 drawChooseTreeInfo(ti->cl_first + y, ti);
3998 TreeInfo *node_first, *node_cursor;
3999 int entry_pos = ti->cl_first + y;
4001 PlaySound(SND_MENU_ITEM_SELECTING);
4003 node_first = getTreeInfoFirstGroupEntry(ti);
4004 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4006 if (node_cursor->node_group)
4010 node_cursor->cl_first = ti->cl_first;
4011 node_cursor->cl_cursor = ti->cl_cursor;
4012 *ti_ptr = node_cursor->node_group;
4013 DrawChooseTree(ti_ptr);
4015 else if (node_cursor->parent_link)
4019 *ti_ptr = node_cursor->node_parent;
4020 DrawChooseTree(ti_ptr);
4026 node_cursor->cl_first = ti->cl_first;
4027 node_cursor->cl_cursor = ti->cl_cursor;
4028 *ti_ptr = node_cursor;
4030 if (ti->type == TREE_TYPE_LEVEL_DIR)
4032 LoadLevelSetup_SeriesInfo();
4034 SaveLevelSetup_LastSeries();
4035 SaveLevelSetup_SeriesInfo();
4039 if (game_status == GAME_MODE_SETUP)
4041 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4042 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4043 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4045 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4046 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4047 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4048 execSetupGraphics();
4049 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4050 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4051 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4053 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4054 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4055 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4062 if (game_status == GAME_MODE_LEVELNR)
4064 int new_level_nr = atoi(level_number_current->identifier);
4066 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4069 SetGameStatus(GAME_MODE_MAIN);
4078 void DrawChooseLevelSet()
4080 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4082 DrawChooseTree(&leveldir_current);
4088 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4090 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4093 void DrawChooseLevelNr()
4097 if (level_number != NULL)
4099 freeTreeInfo(level_number);
4101 level_number = NULL;
4104 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4106 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4107 char identifier[32], name[32];
4110 /* temporarily load level info to get level name */
4111 LoadLevelInfoOnly(i);
4113 ti->node_top = &level_number;
4114 ti->sort_priority = 10000 + value;
4115 ti->color = (level.no_valid_file ? FC_BLUE :
4116 LevelStats_getSolved(i) ? FC_GREEN :
4117 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4119 sprintf(identifier, "%d", value);
4120 sprintf(name, "%03d: %s", value,
4121 (level.no_valid_file ? "(no file)" : level.name));
4123 setString(&ti->identifier, identifier);
4124 setString(&ti->name, name);
4125 setString(&ti->name_sorting, name);
4127 pushTreeInfo(&level_number, ti);
4130 /* sort level number values to start with lowest level number */
4131 sortTreeInfo(&level_number);
4133 /* set current level number to current level number */
4134 level_number_current =
4135 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4137 /* if that also fails, set current level number to first available level */
4138 if (level_number_current == NULL)
4139 level_number_current = level_number;
4141 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4143 DrawChooseTree(&level_number_current);
4149 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4151 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4154 void DrawHallOfFame(int highlight_position)
4156 int fade_mask = REDRAW_FIELD;
4158 /* needed if different viewport properties defined for scores */
4159 ChangeViewportPropertiesIfNeeded();
4161 if (CheckIfGlobalBorderHasChanged())
4162 fade_mask = REDRAW_ALL;
4165 FadeSoundsAndMusic();
4167 /* (this is needed when called from GameEnd() after winning a game) */
4168 KeyboardAutoRepeatOn();
4171 /* (this is needed when called from GameEnd() after winning a game) */
4172 SetDrawDeactivationMask(REDRAW_NONE);
4173 SetDrawBackgroundMask(REDRAW_FIELD);
4175 if (highlight_position < 0)
4176 LoadScore(level_nr);
4178 FadeSetEnterScreen();
4187 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4189 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4191 DrawMaskedBorder(fade_mask);
4196 static void drawHallOfFameList(int first_entry, int highlight_position)
4200 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4203 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4204 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4205 "HighScores of Level %d", level_nr);
4207 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4209 int entry = first_entry + i;
4210 boolean active = (entry == highlight_position);
4211 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4212 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4213 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4214 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4215 int dx1 = 3 * getFontWidth(font_nr1);
4216 int dx2 = dx1 + getFontWidth(font_nr1);
4217 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4218 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4219 int sy = mSY + 64 + i * 32;
4221 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4222 DrawText(mSX + dx1, sy, ".", font_nr1);
4224 for (j = 0; j < num_dots; j++)
4225 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4227 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4228 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4230 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4233 redraw_mask |= REDRAW_FIELD;
4236 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4238 static int first_entry = 0;
4239 static int highlight_position = 0;
4240 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4242 if (button == MB_MENU_INITIALIZE)
4245 highlight_position = mx;
4246 drawHallOfFameList(first_entry, highlight_position);
4251 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4252 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4256 if (first_entry > 0)
4258 first_entry -= step;
4259 if (first_entry < 0)
4262 drawHallOfFameList(first_entry, highlight_position);
4267 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4269 first_entry += step;
4270 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4271 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4273 drawHallOfFameList(first_entry, highlight_position);
4276 else if (button == MB_MENU_LEAVE)
4278 PlaySound(SND_MENU_ITEM_SELECTING);
4280 FadeSound(SND_BACKGROUND_SCORES);
4282 SetGameStatus(GAME_MODE_MAIN);
4286 else if (button == MB_MENU_CHOICE)
4288 PlaySound(SND_MENU_ITEM_SELECTING);
4290 FadeSound(SND_BACKGROUND_SCORES);
4292 SetGameStatus(GAME_MODE_MAIN);
4297 if (game_status == GAME_MODE_SCORES)
4298 PlayMenuSoundIfLoop();
4302 /* ========================================================================= */
4303 /* setup screen functions */
4304 /* ========================================================================= */
4306 static struct TokenInfo *setup_info;
4307 static int num_setup_info; /* number of setup entries shown on screen */
4308 static int max_setup_info; /* total number of setup entries in list */
4310 static char *window_size_text;
4311 static char *scaling_type_text;
4312 static char *rendering_mode_text;
4313 static char *scroll_delay_text;
4314 static char *snapshot_mode_text;
4315 static char *game_speed_text;
4316 static char *graphics_set_name;
4317 static char *sounds_set_name;
4318 static char *music_set_name;
4319 static char *volume_simple_text;
4320 static char *volume_loops_text;
4321 static char *volume_music_text;
4322 static char *touch_controls_text;
4323 static char *move_distance_text;
4324 static char *drop_distance_text;
4326 static void execSetupMain()
4328 setup_mode = SETUP_MODE_MAIN;
4333 static void execSetupGame_setGameSpeeds()
4335 if (game_speeds == NULL)
4339 for (i = 0; game_speeds_list[i].value != -1; i++)
4341 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4342 char identifier[32], name[32];
4343 int value = game_speeds_list[i].value;
4344 char *text = game_speeds_list[i].text;
4346 ti->node_top = &game_speeds;
4347 ti->sort_priority = 10000 - value;
4349 sprintf(identifier, "%d", value);
4350 sprintf(name, "%s", text);
4352 setString(&ti->identifier, identifier);
4353 setString(&ti->name, name);
4354 setString(&ti->name_sorting, name);
4355 setString(&ti->infotext, "Game Speed");
4357 pushTreeInfo(&game_speeds, ti);
4360 /* sort game speed values to start with slowest game speed */
4361 sortTreeInfo(&game_speeds);
4363 /* set current game speed to configured game speed value */
4364 game_speed_current =
4365 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4367 /* if that fails, set current game speed to reliable default value */
4368 if (game_speed_current == NULL)
4369 game_speed_current =
4370 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4372 /* if that also fails, set current game speed to first available speed */
4373 if (game_speed_current == NULL)
4374 game_speed_current = game_speeds;
4377 setup.game_frame_delay = atoi(game_speed_current->identifier);
4379 /* needed for displaying game speed text instead of identifier */
4380 game_speed_text = game_speed_current->name;
4383 static void execSetupGame_setScrollDelays()
4385 if (scroll_delays == NULL)
4389 for (i = 0; scroll_delays_list[i].value != -1; i++)
4391 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4392 char identifier[32], name[32];
4393 int value = scroll_delays_list[i].value;
4394 char *text = scroll_delays_list[i].text;
4396 ti->node_top = &scroll_delays;
4397 ti->sort_priority = value;
4399 sprintf(identifier, "%d", value);
4400 sprintf(name, "%s", text);
4402 setString(&ti->identifier, identifier);
4403 setString(&ti->name, name);
4404 setString(&ti->name_sorting, name);
4405 setString(&ti->infotext, "Scroll Delay");
4407 pushTreeInfo(&scroll_delays, ti);
4410 /* sort scroll delay values to start with lowest scroll delay value */
4411 sortTreeInfo(&scroll_delays);
4413 /* set current scroll delay value to configured scroll delay value */
4414 scroll_delay_current =
4415 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4417 /* if that fails, set current scroll delay to reliable default value */
4418 if (scroll_delay_current == NULL)
4419 scroll_delay_current =
4420 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4422 /* if that also fails, set current scroll delay to first available value */
4423 if (scroll_delay_current == NULL)
4424 scroll_delay_current = scroll_delays;
4427 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4429 /* needed for displaying scroll delay text instead of identifier */
4430 scroll_delay_text = scroll_delay_current->name;
4433 static void execSetupGame_setSnapshotModes()
4435 if (snapshot_modes == NULL)
4439 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4441 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4442 char identifier[32], name[32];
4443 char *value = snapshot_modes_list[i].value;
4444 char *text = snapshot_modes_list[i].text;
4446 ti->node_top = &snapshot_modes;
4447 ti->sort_priority = i;
4449 sprintf(identifier, "%s", value);
4450 sprintf(name, "%s", text);
4452 setString(&ti->identifier, identifier);
4453 setString(&ti->name, name);
4454 setString(&ti->name_sorting, name);
4455 setString(&ti->infotext, "Snapshot Mode");
4457 pushTreeInfo(&snapshot_modes, ti);
4460 /* sort snapshot mode values to start with lowest snapshot mode value */
4461 sortTreeInfo(&snapshot_modes);
4463 /* set current snapshot mode value to configured snapshot mode value */
4464 snapshot_mode_current =
4465 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4467 /* if that fails, set current snapshot mode to reliable default value */
4468 if (snapshot_mode_current == NULL)
4469 snapshot_mode_current =
4470 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4472 /* if that also fails, set current snapshot mode to first available value */
4473 if (snapshot_mode_current == NULL)
4474 snapshot_mode_current = snapshot_modes;
4477 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4479 /* needed for displaying snapshot mode text instead of identifier */
4480 snapshot_mode_text = snapshot_mode_current->name;
4483 static void execSetupGame()
4485 execSetupGame_setGameSpeeds();
4486 execSetupGame_setScrollDelays();
4487 execSetupGame_setSnapshotModes();
4489 setup_mode = SETUP_MODE_GAME;
4494 static void execSetupChooseGameSpeed()
4496 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4501 static void execSetupChooseScrollDelay()
4503 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4508 static void execSetupChooseSnapshotMode()
4510 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4515 static void execSetupEditor()
4517 setup_mode = SETUP_MODE_EDITOR;
4522 static void execSetupGraphics_setWindowSizes(boolean update_list)
4524 if (window_sizes != NULL && update_list)
4526 freeTreeInfo(window_sizes);
4528 window_sizes = NULL;
4531 if (window_sizes == NULL)
4533 boolean current_window_size_found = FALSE;
4536 for (i = 0; window_sizes_list[i].value != -1; i++)
4538 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4539 char identifier[32], name[32];
4540 int value = window_sizes_list[i].value;
4541 char *text = window_sizes_list[i].text;
4543 ti->node_top = &window_sizes;
4544 ti->sort_priority = value;
4546 sprintf(identifier, "%d", value);
4547 sprintf(name, "%s", text);
4549 setString(&ti->identifier, identifier);
4550 setString(&ti->name, name);
4551 setString(&ti->name_sorting, name);
4552 setString(&ti->infotext, "Window Scaling");
4554 pushTreeInfo(&window_sizes, ti);
4556 if (value == setup.window_scaling_percent)
4557 current_window_size_found = TRUE;
4560 if (!current_window_size_found)
4562 // add entry for non-preset window scaling value
4564 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4565 char identifier[32], name[32];
4566 int value = setup.window_scaling_percent;
4568 ti->node_top = &window_sizes;
4569 ti->sort_priority = value;
4571 sprintf(identifier, "%d", value);
4572 sprintf(name, "%d %% (Current)", value);
4574 setString(&ti->identifier, identifier);
4575 setString(&ti->name, name);
4576 setString(&ti->name_sorting, name);
4577 setString(&ti->infotext, "Window Scaling");
4579 pushTreeInfo(&window_sizes, ti);
4582 /* sort window size values to start with lowest window size value */
4583 sortTreeInfo(&window_sizes);
4585 /* set current window size value to configured window size value */
4586 window_size_current =
4587 getTreeInfoFromIdentifier(window_sizes,
4588 i_to_a(setup.window_scaling_percent));
4590 /* if that fails, set current window size to reliable default value */
4591 if (window_size_current == NULL)
4592 window_size_current =
4593 getTreeInfoFromIdentifier(window_sizes,
4594 i_to_a(STD_WINDOW_SCALING_PERCENT));
4596 /* if that also fails, set current window size to first available value */
4597 if (window_size_current == NULL)
4598 window_size_current = window_sizes;
4601 setup.window_scaling_percent = atoi(window_size_current->identifier);
4603 /* needed for displaying window size text instead of identifier */
4604 window_size_text = window_size_current->name;
4607 static void execSetupGraphics_setScalingTypes()
4609 if (scaling_types == NULL)
4613 for (i = 0; scaling_types_list[i].value != NULL; i++)
4615 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4616 char identifier[32], name[32];
4617 char *value = scaling_types_list[i].value;
4618 char *text = scaling_types_list[i].text;
4620 ti->node_top = &scaling_types;
4621 ti->sort_priority = i;
4623 sprintf(identifier, "%s", value);
4624 sprintf(name, "%s", text);
4626 setString(&ti->identifier, identifier);
4627 setString(&ti->name, name);
4628 setString(&ti->name_sorting, name);
4629 setString(&ti->infotext, "Anti-Aliasing");
4631 pushTreeInfo(&scaling_types, ti);
4634 /* sort scaling type values to start with lowest scaling type value */
4635 sortTreeInfo(&scaling_types);
4637 /* set current scaling type value to configured scaling type value */
4638 scaling_type_current =
4639 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4641 /* if that fails, set current scaling type to reliable default value */
4642 if (scaling_type_current == NULL)
4643 scaling_type_current =
4644 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4646 /* if that also fails, set current scaling type to first available value */
4647 if (scaling_type_current == NULL)
4648 scaling_type_current = scaling_types;
4651 setup.window_scaling_quality = scaling_type_current->identifier;
4653 /* needed for displaying scaling type text instead of identifier */
4654 scaling_type_text = scaling_type_current->name;
4657 static void execSetupGraphics_setRenderingModes()
4659 if (rendering_modes == NULL)
4663 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4665 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4666 char identifier[32], name[32];
4667 char *value = rendering_modes_list[i].value;
4668 char *text = rendering_modes_list[i].text;
4670 ti->node_top = &rendering_modes;
4671 ti->sort_priority = i;
4673 sprintf(identifier, "%s", value);
4674 sprintf(name, "%s", text);
4676 setString(&ti->identifier, identifier);
4677 setString(&ti->name, name);
4678 setString(&ti->name_sorting, name);
4679 setString(&ti->infotext, "Special Rendering");
4681 pushTreeInfo(&rendering_modes, ti);
4684 /* sort rendering mode values to start with lowest rendering mode value */
4685 sortTreeInfo(&rendering_modes);
4687 /* set current rendering mode value to configured rendering mode value */
4688 rendering_mode_current =
4689 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
4691 /* if that fails, set current rendering mode to reliable default value */
4692 if (rendering_mode_current == NULL)
4693 rendering_mode_current =
4694 getTreeInfoFromIdentifier(rendering_modes,
4695 STR_SPECIAL_RENDERING_DEFAULT);
4697 /* if that also fails, set current rendering mode to first available one */
4698 if (rendering_mode_current == NULL)
4699 rendering_mode_current = rendering_modes;
4702 setup.screen_rendering_mode = rendering_mode_current->identifier;
4704 /* needed for displaying rendering mode text instead of identifier */
4705 rendering_mode_text = rendering_mode_current->name;
4708 static void execSetupGraphics()
4710 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4712 // update "setup.window_scaling_percent" from list selection
4713 execSetupGraphics_setWindowSizes(FALSE);
4717 // update list selection from "setup.window_scaling_percent"
4718 execSetupGraphics_setWindowSizes(TRUE);
4721 execSetupGraphics_setScalingTypes();
4722 execSetupGraphics_setRenderingModes();
4724 setup_mode = SETUP_MODE_GRAPHICS;
4728 #if defined(TARGET_SDL2)
4729 // window scaling may have changed at this point
4730 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4732 // window scaling quality may have changed at this point
4733 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4734 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4736 // screen rendering mode may have changed at this point
4737 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
4741 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
4742 static void execSetupChooseWindowSize()
4744 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4749 static void execSetupChooseScalingType()
4751 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4756 static void execSetupChooseRenderingMode()
4758 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
4764 static void execSetupChooseVolumeSimple()
4766 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4771 static void execSetupChooseVolumeLoops()
4773 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4778 static void execSetupChooseVolumeMusic()
4780 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4785 static void execSetupSound()
4787 if (volumes_simple == NULL)
4789 boolean current_volume_simple_found = FALSE;
4792 for (i = 0; volumes_list[i].value != -1; i++)
4794 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4795 char identifier[32], name[32];
4796 int value = volumes_list[i].value;
4797 char *text = volumes_list[i].text;
4799 ti->node_top = &volumes_simple;
4800 ti->sort_priority = value;
4802 sprintf(identifier, "%d", value);
4803 sprintf(name, "%s", text);
4805 setString(&ti->identifier, identifier);
4806 setString(&ti->name, name);
4807 setString(&ti->name_sorting, name);
4808 setString(&ti->infotext, "Sound Volume");
4810 pushTreeInfo(&volumes_simple, ti);
4812 if (value == setup.volume_simple)
4813 current_volume_simple_found = TRUE;
4816 if (!current_volume_simple_found)
4818 // add entry for non-preset volume value
4820 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4821 char identifier[32], name[32];
4822 int value = setup.volume_simple;
4824 ti->node_top = &volumes_simple;
4825 ti->sort_priority = value;
4827 sprintf(identifier, "%d", value);
4828 sprintf(name, "%d %% (Current)", value);
4830 setString(&ti->identifier, identifier);
4831 setString(&ti->name, name);
4832 setString(&ti->name_sorting, name);
4833 setString(&ti->infotext, "Sound Volume");
4835 pushTreeInfo(&volumes_simple, ti);
4838 /* sort volume values to start with lowest volume value */
4839 sortTreeInfo(&volumes_simple);
4841 /* set current volume value to configured volume value */
4842 volume_simple_current =
4843 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4845 /* if that fails, set current volume to reliable default value */
4846 if (volume_simple_current == NULL)
4847 volume_simple_current =
4848 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4850 /* if that also fails, set current volume to first available value */
4851 if (volume_simple_current == NULL)
4852 volume_simple_current = volumes_simple;
4855 if (volumes_loops == NULL)
4857 boolean current_volume_loops_found = FALSE;
4860 for (i = 0; volumes_list[i].value != -1; i++)
4862 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4863 char identifier[32], name[32];
4864 int value = volumes_list[i].value;
4865 char *text = volumes_list[i].text;
4867 ti->node_top = &volumes_loops;
4868 ti->sort_priority = value;
4870 sprintf(identifier, "%d", value);
4871 sprintf(name, "%s", text);
4873 setString(&ti->identifier, identifier);
4874 setString(&ti->name, name);
4875 setString(&ti->name_sorting, name);
4876 setString(&ti->infotext, "Loops Volume");
4878 pushTreeInfo(&volumes_loops, ti);
4880 if (value == setup.volume_loops)
4881 current_volume_loops_found = TRUE;
4884 if (!current_volume_loops_found)
4886 // add entry for non-preset volume value
4888 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4889 char identifier[32], name[32];
4890 int value = setup.volume_loops;
4892 ti->node_top = &volumes_loops;
4893 ti->sort_priority = value;
4895 sprintf(identifier, "%d", value);
4896 sprintf(name, "%d %% (Current)", value);
4898 setString(&ti->identifier, identifier);
4899 setString(&ti->name, name);
4900 setString(&ti->name_sorting, name);
4901 setString(&ti->infotext, "Loops Volume");
4903 pushTreeInfo(&volumes_loops, ti);
4906 /* sort volume values to start with lowest volume value */
4907 sortTreeInfo(&volumes_loops);
4909 /* set current volume value to configured volume value */
4910 volume_loops_current =
4911 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4913 /* if that fails, set current volume to reliable default value */
4914 if (volume_loops_current == NULL)
4915 volume_loops_current =
4916 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4918 /* if that also fails, set current volume to first available value */
4919 if (volume_loops_current == NULL)
4920 volume_loops_current = volumes_loops;
4923 if (volumes_music == NULL)
4925 boolean current_volume_music_found = FALSE;
4928 for (i = 0; volumes_list[i].value != -1; i++)
4930 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4931 char identifier[32], name[32];
4932 int value = volumes_list[i].value;
4933 char *text = volumes_list[i].text;
4935 ti->node_top = &volumes_music;
4936 ti->sort_priority = value;
4938 sprintf(identifier, "%d", value);
4939 sprintf(name, "%s", text);
4941 setString(&ti->identifier, identifier);
4942 setString(&ti->name, name);
4943 setString(&ti->name_sorting, name);
4944 setString(&ti->infotext, "Music Volume");
4946 pushTreeInfo(&volumes_music, ti);
4948 if (value == setup.volume_music)
4949 current_volume_music_found = TRUE;
4952 if (!current_volume_music_found)
4954 // add entry for non-preset volume value
4956 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4957 char identifier[32], name[32];
4958 int value = setup.volume_music;
4960 ti->node_top = &volumes_music;
4961 ti->sort_priority = value;
4963 sprintf(identifier, "%d", value);
4964 sprintf(name, "%d %% (Current)", value);
4966 setString(&ti->identifier, identifier);
4967 setString(&ti->name, name);
4968 setString(&ti->name_sorting, name);
4969 setString(&ti->infotext, "Music Volume");
4971 pushTreeInfo(&volumes_music, ti);
4974 /* sort volume values to start with lowest volume value */
4975 sortTreeInfo(&volumes_music);
4977 /* set current volume value to configured volume value */
4978 volume_music_current =
4979 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4981 /* if that fails, set current volume to reliable default value */
4982 if (volume_music_current == NULL)
4983 volume_music_current =
4984 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4986 /* if that also fails, set current volume to first available value */
4987 if (volume_music_current == NULL)
4988 volume_music_current = volumes_music;
4991 setup.volume_simple = atoi(volume_simple_current->identifier);
4992 setup.volume_loops = atoi(volume_loops_current->identifier);
4993 setup.volume_music = atoi(volume_music_current->identifier);
4995 /* needed for displaying volume text instead of identifier */
4996 volume_simple_text = volume_simple_current->name;
4997 volume_loops_text = volume_loops_current->name;
4998 volume_music_text = volume_music_current->name;
5000 setup_mode = SETUP_MODE_SOUND;
5005 static void execSetupChooseTouchControls()
5007 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5012 static void execSetupChooseMoveDistance()
5014 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5019 static void execSetupChooseDropDistance()
5021 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5026 static void execSetupTouch()
5028 if (touch_controls == NULL)
5032 for (i = 0; touch_controls_list[i].value != NULL; i++)
5034 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5035 char identifier[32], name[32];
5036 char *value = touch_controls_list[i].value;
5037 char *text = touch_controls_list[i].text;
5039 ti->node_top = &touch_controls;
5040 ti->sort_priority = i;
5042 sprintf(identifier, "%s", value);
5043 sprintf(name, "%s", text);
5045 setString(&ti->identifier, identifier);
5046 setString(&ti->name, name);
5047 setString(&ti->name_sorting, name);
5048 setString(&ti->infotext, "Control Type");
5050 pushTreeInfo(&touch_controls, ti);
5053 /* sort touch control values to start with lowest touch control value */
5054 sortTreeInfo(&touch_controls);
5056 /* set current touch control value to configured touch control value */
5057 touch_control_current =
5058 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5060 /* if that fails, set current touch control to reliable default value */
5061 if (touch_control_current == NULL)
5062 touch_control_current =
5063 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5065 /* if that also fails, set current touch control to first available value */
5066 if (touch_control_current == NULL)
5067 touch_control_current = touch_controls;
5070 if (move_distances == NULL)
5074 for (i = 0; distances_list[i].value != -1; i++)
5076 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5077 char identifier[32], name[32];
5078 int value = distances_list[i].value;
5079 char *text = distances_list[i].text;
5081 ti->node_top = &move_distances;
5082 ti->sort_priority = value;
5084 sprintf(identifier, "%d", value);
5085 sprintf(name, "%s", text);
5087 setString(&ti->identifier, identifier);
5088 setString(&ti->name, name);
5089 setString(&ti->name_sorting, name);
5090 setString(&ti->infotext, "Move Distance");
5092 pushTreeInfo(&move_distances, ti);
5095 /* sort distance values to start with lowest distance value */
5096 sortTreeInfo(&move_distances);
5098 /* set current distance value to configured distance value */
5099 move_distance_current =
5100 getTreeInfoFromIdentifier(move_distances,
5101 i_to_a(setup.touch.move_distance));
5103 /* if that fails, set current distance to reliable default value */
5104 if (move_distance_current == NULL)
5105 move_distance_current =
5106 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5108 /* if that also fails, set current distance to first available value */
5109 if (move_distance_current == NULL)
5110 move_distance_current = move_distances;
5113 if (drop_distances == NULL)
5117 for (i = 0; distances_list[i].value != -1; i++)
5119 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5120 char identifier[32], name[32];
5121 int value = distances_list[i].value;
5122 char *text = distances_list[i].text;
5124 ti->node_top = &drop_distances;
5125 ti->sort_priority = value;
5127 sprintf(identifier, "%d", value);
5128 sprintf(name, "%s", text);
5130 setString(&ti->identifier, identifier);
5131 setString(&ti->name, name);
5132 setString(&ti->name_sorting, name);
5133 setString(&ti->infotext, "Drop Distance");
5135 pushTreeInfo(&drop_distances, ti);
5138 /* sort distance values to start with lowest distance value */
5139 sortTreeInfo(&drop_distances);
5141 /* set current distance value to configured distance value */
5142 drop_distance_current =
5143 getTreeInfoFromIdentifier(drop_distances,
5144 i_to_a(setup.touch.drop_distance));
5146 /* if that fails, set current distance to reliable default value */
5147 if (drop_distance_current == NULL)
5148 drop_distance_current =
5149 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5151 /* if that also fails, set current distance to first available value */
5152 if (drop_distance_current == NULL)
5153 drop_distance_current = drop_distances;
5156 setup.touch.control_type = touch_control_current->identifier;
5157 setup.touch.move_distance = atoi(move_distance_current->identifier);
5158 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5160 /* needed for displaying volume text instead of identifier */
5161 touch_controls_text = touch_control_current->name;
5162 move_distance_text = move_distance_current->name;
5163 drop_distance_text = drop_distance_current->name;
5165 setup_mode = SETUP_MODE_TOUCH;
5170 static void execSetupArtwork()
5173 printf("::: '%s', '%s', '%s'\n",
5174 artwork.gfx_current->subdir,
5175 artwork.gfx_current->fullpath,
5176 artwork.gfx_current->basepath);
5179 setup.graphics_set = artwork.gfx_current->identifier;
5180 setup.sounds_set = artwork.snd_current->identifier;
5181 setup.music_set = artwork.mus_current->identifier;
5183 /* needed if last screen (setup choice) changed graphics, sounds or music */
5184 ReloadCustomArtwork(0);
5186 /* needed for displaying artwork name instead of artwork identifier */
5187 graphics_set_name = artwork.gfx_current->name;
5188 sounds_set_name = artwork.snd_current->name;
5189 music_set_name = artwork.mus_current->name;
5191 setup_mode = SETUP_MODE_ARTWORK;
5196 static void execSetupChooseGraphics()
5198 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5203 static void execSetupChooseSounds()
5205 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5210 static void execSetupChooseMusic()
5212 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5217 #if !defined(PLATFORM_ANDROID)
5218 static void execSetupInput()
5220 setup_mode = SETUP_MODE_INPUT;
5226 static void execSetupShortcuts()
5228 setup_mode = SETUP_MODE_SHORTCUTS;
5233 static void execSetupShortcuts1()
5235 setup_mode = SETUP_MODE_SHORTCUTS_1;
5240 static void execSetupShortcuts2()
5242 setup_mode = SETUP_MODE_SHORTCUTS_2;
5247 static void execSetupShortcuts3()
5249 setup_mode = SETUP_MODE_SHORTCUTS_3;
5254 static void execSetupShortcuts4()
5256 setup_mode = SETUP_MODE_SHORTCUTS_4;
5261 static void execSetupShortcuts5()
5263 setup_mode = SETUP_MODE_SHORTCUTS_5;
5268 static void execExitSetup()
5270 SetGameStatus(GAME_MODE_MAIN);
5275 static void execSaveAndExitSetup()
5281 static struct TokenInfo setup_info_main[] =
5283 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5284 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5285 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5286 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5287 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5288 #if !defined(PLATFORM_ANDROID)
5289 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5290 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5292 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5294 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5295 { TYPE_EMPTY, NULL, "" },
5296 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5297 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5302 static struct TokenInfo setup_info_game[] =
5304 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5305 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5306 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5307 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5308 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5309 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5310 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5311 { TYPE_STRING, &game_speed_text, "" },
5313 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5314 { TYPE_STRING, &scroll_delay_text, "" },
5316 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5317 { TYPE_STRING, &snapshot_mode_text, "" },
5318 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5319 { TYPE_EMPTY, NULL, "" },
5320 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5325 static struct TokenInfo setup_info_editor[] =
5328 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5329 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5330 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5331 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5332 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5333 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5334 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5335 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5337 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5338 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5339 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5341 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5343 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5344 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5345 { TYPE_EMPTY, NULL, "" },
5347 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5348 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5349 { TYPE_EMPTY, NULL, "" },
5351 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5352 { TYPE_EMPTY, NULL, "" },
5353 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5358 static struct TokenInfo setup_info_graphics[] =
5360 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5361 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5362 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5363 { TYPE_STRING, &window_size_text, "" },
5364 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5365 { TYPE_STRING, &scaling_type_text, "" },
5366 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5367 { TYPE_STRING, &rendering_mode_text, "" },
5370 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5371 { TYPE_STRING, &scroll_delay_text, "" },
5373 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5374 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5375 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5376 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5377 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5378 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5379 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5380 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5381 { TYPE_EMPTY, NULL, "" },
5382 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5387 static struct TokenInfo setup_info_sound[] =
5389 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5390 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5391 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5392 { TYPE_EMPTY, NULL, "" },
5393 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5394 { TYPE_STRING, &volume_simple_text, "" },
5395 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5396 { TYPE_STRING, &volume_loops_text, "" },
5397 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5398 { TYPE_STRING, &volume_music_text, "" },
5399 { TYPE_EMPTY, NULL, "" },
5400 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5405 static struct TokenInfo setup_info_artwork[] =
5407 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5408 { TYPE_STRING, &graphics_set_name, "" },
5409 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5410 { TYPE_STRING, &sounds_set_name, "" },
5411 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5412 { TYPE_STRING, &music_set_name, "" },
5413 { TYPE_EMPTY, NULL, "" },
5414 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5415 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5416 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5417 { TYPE_EMPTY, NULL, "" },
5418 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5423 static struct TokenInfo setup_info_input[] =
5425 { TYPE_SWITCH, NULL, "Player:" },
5426 { TYPE_SWITCH, NULL, "Device:" },
5427 { TYPE_ENTER_MENU, NULL, "" },
5428 { TYPE_EMPTY, NULL, "" },
5429 { TYPE_EMPTY, NULL, "" },
5430 { TYPE_EMPTY, NULL, "" },
5431 { TYPE_EMPTY, NULL, "" },
5432 { TYPE_EMPTY, NULL, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_EMPTY, NULL, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_EMPTY, NULL, "" },
5437 { TYPE_EMPTY, NULL, "" },
5438 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5443 static struct TokenInfo setup_info_touch[] =
5445 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5446 { TYPE_STRING, &touch_controls_text, "" },
5447 { TYPE_EMPTY, NULL, "" },
5448 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5449 { TYPE_STRING, &move_distance_text, "" },
5450 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5451 { TYPE_STRING, &drop_distance_text, "" },
5452 { TYPE_EMPTY, NULL, "" },
5453 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5458 static struct TokenInfo setup_info_shortcuts[] =
5460 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5461 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5462 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5463 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5464 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5465 { TYPE_EMPTY, NULL, "" },
5466 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5471 static struct TokenInfo setup_info_shortcuts_1[] =
5473 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5474 { TYPE_KEY, &setup.shortcut.save_game, "" },
5475 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5476 { TYPE_KEY, &setup.shortcut.load_game, "" },
5477 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5478 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5479 { TYPE_EMPTY, NULL, "" },
5480 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5481 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5482 { TYPE_EMPTY, NULL, "" },
5483 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5488 static struct TokenInfo setup_info_shortcuts_2[] =
5490 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5491 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5492 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5493 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5494 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5495 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5496 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5497 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5498 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5499 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5500 { TYPE_EMPTY, NULL, "" },
5501 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5506 static struct TokenInfo setup_info_shortcuts_3[] =
5508 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5509 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5510 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5511 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5512 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5513 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5514 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5515 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5516 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5517 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5518 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5519 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5520 { TYPE_EMPTY, NULL, "" },
5521 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5526 static struct TokenInfo setup_info_shortcuts_4[] =
5528 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5529 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5530 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5531 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5532 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5533 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5534 { TYPE_EMPTY, NULL, "" },
5535 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5540 static struct TokenInfo setup_info_shortcuts_5[] =
5542 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5543 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5544 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5545 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5546 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5547 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5548 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5549 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5550 { TYPE_EMPTY, NULL, "" },
5551 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5556 static Key getSetupKey()
5558 Key key = KSYM_UNDEFINED;
5559 boolean got_key_event = FALSE;
5561 while (!got_key_event)
5563 if (PendingEvent()) /* got event */
5571 case EVENT_KEYPRESS:
5573 key = GetEventKey((KeyEvent *)&event, TRUE);
5575 /* press 'Escape' or 'Enter' to keep the existing key binding */
5576 if (key == KSYM_Escape || key == KSYM_Return)
5577 key = KSYM_UNDEFINED; /* keep old value */
5579 got_key_event = TRUE;
5583 case EVENT_KEYRELEASE:
5584 key_joystick_mapping = 0;
5588 HandleOtherEvents(&event);
5596 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
5602 static int getSetupValueFont(int type, void *value)
5604 if (type & TYPE_KEY)
5605 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5606 else if (type & TYPE_STRING)
5607 return FONT_VALUE_2;
5608 else if (type & TYPE_ECS_AGA)
5609 return FONT_VALUE_1;
5610 else if (type & TYPE_BOOLEAN_STYLE)
5611 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5612 else if (type & TYPE_YES_NO_AUTO)
5613 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5614 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5616 return FONT_VALUE_1;
5619 static int getSetupValueFontNarrow(int type, int font_nr)
5621 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
5622 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
5623 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
5627 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5629 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5630 struct TokenInfo *si = &setup_info[si_pos];
5631 boolean font_draw_xoffset_modified = FALSE;
5632 boolean scrollbar_needed = (num_setup_info < max_setup_info);
5633 int font_draw_xoffset_old = -1;
5634 int xoffset = (scrollbar_needed ? -1 : 0);
5635 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5636 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5637 int xpos = menu_screen_value_xpos;
5638 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5639 int startx = mSX + xpos * 32;
5640 int starty = mSY + ypos * 32;
5641 int font_nr, font_width;
5642 int type = si->type;
5643 void *value = si->value;
5644 char *value_string = getSetupValue(type, value);
5647 if (value_string == NULL)
5650 if (type & TYPE_KEY)
5652 xpos = MENU_SCREEN_START_XPOS;
5654 if (type & TYPE_QUERY)
5655 value_string = "<press key>";
5657 else if (type & TYPE_STRING)
5659 int max_value_len = (SCR_FIELDX - 2) * 2;
5661 xpos = MENU_SCREEN_START_XPOS;
5663 if (strlen(value_string) > max_value_len)
5664 value_string[max_value_len] = '\0';
5666 else if (type & TYPE_YES_NO_AUTO)
5668 xpos = menu_screen_value_xpos - 1;
5671 startx = mSX + xpos * 32;
5672 starty = mSY + ypos * 32;
5673 font_nr = getSetupValueFont(type, value);
5674 font_width = getFontWidth(font_nr);
5676 // special check if right-side setup values moved left due to scrollbar
5677 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
5679 int max_menu_text_length = 26; // maximum text length for classic menu
5680 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5681 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5682 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5683 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5684 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
5686 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
5689 startx = mSX + xpos * 32;
5691 font_nr = getSetupValueFontNarrow(type, font_nr);
5692 font_width = getFontWidth(font_nr);
5696 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5697 if (setup_mode != SETUP_MODE_INPUT)
5699 int max_menu_text_length_big = (menu_screen_value_xpos -
5700 MENU_SCREEN_START_XPOS);
5701 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5702 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5703 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5704 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5705 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5706 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5707 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5708 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5709 boolean correct_font_draw_xoffset = FALSE;
5711 if (xpos == MENU_SCREEN_START_XPOS &&
5712 startx + font1_xoffset < text_startx + text_font_xoffset)
5713 correct_font_draw_xoffset = TRUE;
5715 if (xpos == menu_screen_value_xpos &&
5716 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5717 correct_font_draw_xoffset = TRUE;
5719 /* check if setup value would overlap with setup text when printed */
5720 /* (this can happen for extreme/wrong values for font draw offset) */
5721 if (correct_font_draw_xoffset)
5723 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5724 font_draw_xoffset_modified = TRUE;
5726 if (type & TYPE_KEY)
5727 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5728 else if (!(type & TYPE_STRING))
5729 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5730 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5734 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5735 DrawText(startx + i * font_width, starty, " ", font_nr);
5737 DrawText(startx, starty, value_string, font_nr);
5739 if (font_draw_xoffset_modified)
5740 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5743 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5745 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5746 struct TokenInfo *si = &setup_info[si_pos];
5748 if (si->type & TYPE_BOOLEAN_STYLE)
5750 *(boolean *)si->value ^= TRUE;
5752 else if (si->type & TYPE_YES_NO_AUTO)
5756 (*(int *)si->value == AUTO ? TRUE :
5757 *(int *)si->value == TRUE ? FALSE : AUTO) :
5758 (*(int *)si->value == TRUE ? AUTO :
5759 *(int *)si->value == AUTO ? FALSE : TRUE));
5761 else if (si->type & TYPE_KEY)
5765 si->type |= TYPE_QUERY;
5766 drawSetupValue(screen_pos, setup_info_pos_raw);
5767 si->type &= ~TYPE_QUERY;
5769 key = getSetupKey();
5770 if (key != KSYM_UNDEFINED)
5771 *(Key *)si->value = key;
5774 drawSetupValue(screen_pos, setup_info_pos_raw);
5776 // fullscreen state may have changed at this point
5777 if (si->value == &setup.fullscreen)
5778 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5781 static void DrawSetupScreen_Generic()
5783 int fade_mask = REDRAW_FIELD;
5784 boolean redraw_all = FALSE;
5785 char *title_string = NULL;
5788 if (CheckIfGlobalBorderHasChanged())
5789 fade_mask = REDRAW_ALL;
5793 FreeScreenGadgets();
5794 CreateScreenGadgets();
5796 if (redraw_mask & REDRAW_ALL)
5803 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
5805 if (setup_mode == SETUP_MODE_MAIN)
5807 setup_info = setup_info_main;
5808 title_string = "Setup";
5810 else if (setup_mode == SETUP_MODE_GAME)
5812 setup_info = setup_info_game;
5813 title_string = "Setup Game";
5815 else if (setup_mode == SETUP_MODE_EDITOR)
5817 setup_info = setup_info_editor;
5818 title_string = "Setup Editor";
5820 else if (setup_mode == SETUP_MODE_GRAPHICS)
5822 setup_info = setup_info_graphics;
5823 title_string = "Setup Graphics";
5825 else if (setup_mode == SETUP_MODE_SOUND)
5827 setup_info = setup_info_sound;
5828 title_string = "Setup Sound";
5830 else if (setup_mode == SETUP_MODE_ARTWORK)
5832 setup_info = setup_info_artwork;
5833 title_string = "Custom Artwork";
5835 else if (setup_mode == SETUP_MODE_TOUCH)
5837 setup_info = setup_info_touch;
5838 title_string = "Setup Touch Ctrls";
5840 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5842 setup_info = setup_info_shortcuts;
5843 title_string = "Setup Shortcuts";
5845 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5847 setup_info = setup_info_shortcuts_1;
5848 title_string = "Setup Shortcuts";
5850 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5852 setup_info = setup_info_shortcuts_2;
5853 title_string = "Setup Shortcuts";
5855 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5857 setup_info = setup_info_shortcuts_3;
5858 title_string = "Setup Shortcuts";
5860 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5862 setup_info = setup_info_shortcuts_4;
5863 title_string = "Setup Shortcuts";
5865 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5867 setup_info = setup_info_shortcuts_5;
5868 title_string = "Setup Shortcuts";
5871 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5873 // determine maximal number of setup entries that can be displayed on screen
5875 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5878 // determine maximal number of setup entries available for this setup screen
5880 for (i = 0; setup_info[i].type != 0; i++)
5883 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5885 MapScreenGadgets(max_setup_info);
5888 redraw_mask = fade_mask = REDRAW_ALL;
5890 DrawMaskedBorder(fade_mask);
5897 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5899 menu_info = setup_info;
5901 HandleMenuScreen(mx, my, dx, dy, button,
5902 setup_mode, num_setup_info, max_setup_info);
5905 void DrawSetupScreen_Input()
5909 FadeOut(REDRAW_FIELD);
5913 setup_info = setup_info_input;
5915 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5917 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5918 "Joysticks deactivated on this screen");
5920 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5922 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5923 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5924 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5925 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5926 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5927 initCursor(i, IMG_MENU_BUTTON);
5929 DrawCursorAndText_Setup(i, -1, FALSE);
5932 /* create gadgets for setup input menu screen */
5933 FreeScreenGadgets();
5934 CreateScreenGadgets();
5936 /* map gadgets for setup input menu screen */
5937 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5939 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5941 FadeIn(REDRAW_FIELD);
5946 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5948 if (device_name == NULL)
5951 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5954 if (strlen(device_name) > 1)
5956 char c1 = device_name[strlen(device_name) - 1];
5957 char c2 = device_name[strlen(device_name) - 2];
5959 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5960 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5963 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5964 strlen(device_name));
5967 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5970 static struct SetupKeyboardInfo custom_key;
5977 { &custom_key.left, "Joystick Left" },
5978 { &custom_key.right, "Joystick Right" },
5979 { &custom_key.up, "Joystick Up" },
5980 { &custom_key.down, "Joystick Down" },
5981 { &custom_key.snap, "Button 1" },
5982 { &custom_key.drop, "Button 2" }
5984 static char *joystick_name[MAX_PLAYERS] =
5991 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5995 custom_key = setup.input[player_nr].key;
5997 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5998 FONT_INPUT_1_ACTIVE);
6000 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6002 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6003 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6005 if (setup.input[player_nr].use_joystick)
6007 char *device_name = setup.input[player_nr].joy.device_name;
6008 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
6009 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
6011 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6012 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6016 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6017 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6020 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6022 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6023 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6024 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6025 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6027 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6028 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6029 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6030 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6031 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6032 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6034 for (i = 0; i < 6; i++)
6036 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6038 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6040 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6041 (setup.input[player_nr].use_joystick ?
6043 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6047 static int input_player_nr = 0;
6049 void HandleSetupScreen_Input_Player(int step, int direction)
6051 int old_player_nr = input_player_nr;
6054 new_player_nr = old_player_nr + step * direction;
6055 if (new_player_nr < 0)
6057 if (new_player_nr > MAX_PLAYERS - 1)
6058 new_player_nr = MAX_PLAYERS - 1;
6060 if (new_player_nr != old_player_nr)
6062 input_player_nr = new_player_nr;
6064 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6068 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6070 static int choice = 0;
6073 int pos_start = SETUPINPUT_SCREEN_POS_START;
6074 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6075 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6076 int pos_end = SETUPINPUT_SCREEN_POS_END;
6078 if (button == MB_MENU_INITIALIZE)
6080 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6082 DrawCursorAndText_Setup(choice, -1, TRUE);
6086 else if (button == MB_MENU_LEAVE)
6088 setup_mode = SETUP_MODE_MAIN;
6095 if (mx || my) /* mouse input */
6097 x = (mx - mSX) / 32;
6098 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6100 else if (dx || dy) /* keyboard input */
6102 if (dx && choice == 0)
6103 x = (dx < 0 ? 10 : 12);
6104 else if ((dx && choice == 1) ||
6105 (dx == +1 && choice == 2) ||
6106 (dx == -1 && choice == pos_end))
6107 button = MB_MENU_CHOICE;
6111 if (y >= pos_empty1 && y <= pos_empty2)
6112 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6115 if (y == 0 && dx != 0 && button)
6117 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6119 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6120 y >= pos_start && y <= pos_end &&
6121 !(y >= pos_empty1 && y <= pos_empty2))
6127 DrawCursorAndText_Setup(choice, -1, FALSE);
6128 DrawCursorAndText_Setup(y, -1, TRUE);
6130 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6139 char *device_name = setup.input[input_player_nr].joy.device_name;
6141 if (!setup.input[input_player_nr].use_joystick)
6143 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6145 setJoystickDeviceToNr(device_name, new_device_nr);
6146 setup.input[input_player_nr].use_joystick = TRUE;
6150 int device_nr = getJoystickNrFromDeviceName(device_name);
6151 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6153 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6154 setup.input[input_player_nr].use_joystick = FALSE;
6156 setJoystickDeviceToNr(device_name, new_device_nr);
6159 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6163 if (setup.input[input_player_nr].use_joystick)
6166 CalibrateJoystick(input_player_nr);
6169 CustomizeKeyboard(input_player_nr);
6171 else if (y == pos_end)
6177 setup_mode = SETUP_MODE_MAIN;
6184 void CustomizeKeyboard(int player_nr)
6188 boolean finished = FALSE;
6189 static struct SetupKeyboardInfo custom_key;
6194 } customize_step[] =
6196 { &custom_key.left, "Move Left" },
6197 { &custom_key.right, "Move Right" },
6198 { &custom_key.up, "Move Up" },
6199 { &custom_key.down, "Move Down" },
6200 { &custom_key.snap, "Snap Field" },
6201 { &custom_key.drop, "Drop Element" }
6204 /* read existing key bindings from player setup */
6205 custom_key = setup.input[player_nr].key;
6208 FadeOut(REDRAW_FIELD);
6212 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6215 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6216 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6217 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6218 "Key:", FONT_INPUT_1_ACTIVE);
6219 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6220 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6222 FadeIn(REDRAW_FIELD);
6228 if (PendingEvent()) /* got event */
6236 case EVENT_KEYPRESS:
6238 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6240 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6242 if (key == KSYM_Escape)
6243 FadeSkipNextFadeIn();
6249 /* all keys configured -- wait for "Escape" or "Return" key */
6253 /* press 'Enter' to keep the existing key binding */
6254 if (key == KSYM_Return)
6255 key = *customize_step[step_nr].key;
6257 /* check if key already used */
6258 for (i = 0; i < step_nr; i++)
6259 if (*customize_step[i].key == key)
6264 /* got new key binding */
6265 *customize_step[step_nr].key = key;
6266 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6268 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6269 getKeyNameFromKey(key), FONT_VALUE_1);
6272 /* un-highlight last query */
6273 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6274 customize_step[step_nr - 1].text, FONT_MENU_1);
6275 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6276 "Key:", FONT_MENU_1);
6278 /* press 'Enter' to leave */
6281 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6282 "Press Enter", FONT_TITLE_1);
6286 /* query next key binding */
6287 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6288 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6289 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6290 "Key:", FONT_INPUT_1_ACTIVE);
6291 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6292 getKeyNameFromKey(*customize_step[step_nr].key),
6297 case EVENT_KEYRELEASE:
6298 key_joystick_mapping = 0;
6302 HandleOtherEvents(&event);
6310 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6313 /* write new key bindings back to player setup */
6314 setup.input[player_nr].key = custom_key;
6317 DrawSetupScreen_Input();
6320 static boolean CalibrateJoystickMain(int player_nr)
6322 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6323 int new_joystick_xright = JOYSTICK_XMIDDLE;
6324 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6325 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6326 int new_joystick_xmiddle, new_joystick_ymiddle;
6328 int joystick_fd = joystick.fd[player_nr];
6329 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6330 boolean check[3][3];
6331 int check_remaining = 3 * 3;
6336 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6339 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6343 FadeOut(REDRAW_FIELD);
6347 for (y = 0; y < 3; y++)
6349 for (x = 0; x < 3; x++)
6351 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6352 check[x][y] = FALSE;
6356 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6357 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6358 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6359 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6360 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6361 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6362 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6364 joy_value = Joystick(player_nr);
6365 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6366 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6368 /* eventually uncalibrated center position (joystick could be uncentered) */
6369 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6372 new_joystick_xmiddle = joy_x;
6373 new_joystick_ymiddle = joy_y;
6375 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6377 FadeIn(REDRAW_FIELD);
6379 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6384 if (PendingEvent()) /* got event */
6392 case EVENT_KEYPRESS:
6393 switch (GetEventKey((KeyEvent *)&event, TRUE))
6396 if (check_remaining == 0)
6401 FadeSkipNextFadeIn();
6410 case EVENT_KEYRELEASE:
6411 key_joystick_mapping = 0;
6415 HandleOtherEvents(&event);
6420 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6423 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6424 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6425 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6426 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6428 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6429 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6430 setup.input[player_nr].joy.xright = new_joystick_xright;
6431 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6432 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6433 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6435 CheckJoystickData();
6437 joy_value = Joystick(player_nr);
6439 if (joy_value & JOY_BUTTON && check_remaining == 0)
6442 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6443 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6445 if (x != last_x || y != last_y)
6447 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6448 IMG_MENU_CALIBRATE_YELLOW, 0);
6449 DrawFixedGraphic(xpos + x, ypos + y,
6450 IMG_MENU_CALIBRATE_RED, 0);
6455 if (check_remaining > 0 && !check[x+1][y+1])
6457 check[x+1][y+1] = TRUE;
6465 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6468 /* calibrated center position (joystick should now be centered) */
6469 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6472 new_joystick_xmiddle = joy_x;
6473 new_joystick_ymiddle = joy_y;
6477 /* wait until the last pressed button was released */
6478 while (Joystick(player_nr) & JOY_BUTTON)
6480 if (PendingEvent()) /* got event */
6485 HandleOtherEvents(&event);
6487 WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
6494 void CalibrateJoystick(int player_nr)
6496 if (!CalibrateJoystickMain(player_nr))
6498 char *device_name = setup.input[player_nr].joy.device_name;
6499 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6500 int xpos = mSX - SX;
6501 int ypos = mSY - SY;
6505 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6506 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6509 Delay(2000); /* show error message for a short time */
6514 DrawSetupScreen_Input();
6517 void DrawSetupScreen()
6519 DeactivateJoystick();
6521 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6523 if (setup_mode == SETUP_MODE_INPUT)
6524 DrawSetupScreen_Input();
6525 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6526 DrawChooseTree(&game_speed_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6528 DrawChooseTree(&scroll_delay_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6530 DrawChooseTree(&snapshot_mode_current);
6531 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6532 DrawChooseTree(&window_size_current);
6533 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6534 DrawChooseTree(&scaling_type_current);
6535 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6536 DrawChooseTree(&rendering_mode_current);
6537 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6538 DrawChooseTree(&artwork.gfx_current);
6539 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6540 DrawChooseTree(&artwork.snd_current);
6541 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6542 DrawChooseTree(&artwork.mus_current);
6543 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6544 DrawChooseTree(&volume_simple_current);
6545 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6546 DrawChooseTree(&volume_loops_current);
6547 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6548 DrawChooseTree(&volume_music_current);
6549 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6550 DrawChooseTree(&touch_control_current);
6551 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6552 DrawChooseTree(&move_distance_current);
6553 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6554 DrawChooseTree(&drop_distance_current);
6556 DrawSetupScreen_Generic();
6562 void RedrawSetupScreenAfterFullscreenToggle()
6564 if (setup_mode == SETUP_MODE_GRAPHICS ||
6565 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6567 // update list selection from "setup.window_scaling_percent"
6568 execSetupGraphics_setWindowSizes(TRUE);
6574 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6576 if (setup_mode == SETUP_MODE_INPUT)
6577 HandleSetupScreen_Input(mx, my, dx, dy, button);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6579 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6581 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6582 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6583 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6584 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6585 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6586 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6587 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6588 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
6589 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
6590 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6591 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6592 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6593 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6594 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6595 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6596 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6597 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6598 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6599 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6600 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6601 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6602 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6603 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6604 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6605 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6606 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6607 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6609 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6612 void HandleGameActions()
6614 if (game_status != GAME_MODE_PLAYING)
6617 GameActions(); /* main game loop */
6619 if (tape.auto_play && !tape.playing)
6620 AutoPlayTape(); /* continue automatically playing next tape */
6624 /* ---------- new screen button stuff -------------------------------------- */
6626 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6630 case SCREEN_CTRL_ID_PREV_LEVEL:
6631 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6632 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6635 case SCREEN_CTRL_ID_NEXT_LEVEL:
6636 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6637 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6640 case SCREEN_CTRL_ID_PREV_PLAYER:
6641 *x = mSX + TILEX * 10;
6642 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6645 case SCREEN_CTRL_ID_NEXT_PLAYER:
6646 *x = mSX + TILEX * 12;
6647 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6651 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6657 int gfx_unpressed, gfx_pressed;
6658 void (*get_gadget_position)(int *, int *, int);
6662 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6665 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6666 getScreenMenuButtonPos,
6667 SCREEN_CTRL_ID_PREV_LEVEL,
6672 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6673 getScreenMenuButtonPos,
6674 SCREEN_CTRL_ID_NEXT_LEVEL,
6679 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6680 getScreenMenuButtonPos,
6681 SCREEN_CTRL_ID_PREV_PLAYER,
6686 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6687 getScreenMenuButtonPos,
6688 SCREEN_CTRL_ID_NEXT_PLAYER,
6696 int gfx_unpressed, gfx_pressed;
6700 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6703 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6704 -1, -1, /* these values are not constant, but can change at runtime */
6705 SCREEN_CTRL_ID_SCROLL_UP,
6709 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6710 -1, -1, /* these values are not constant, but can change at runtime */
6711 SCREEN_CTRL_ID_SCROLL_DOWN,
6718 int gfx_unpressed, gfx_pressed;
6724 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6727 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6728 -1, -1, /* these values are not constant, but can change at runtime */
6729 -1, -1, /* these values are not constant, but can change at runtime */
6730 GD_TYPE_SCROLLBAR_VERTICAL,
6731 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6732 "scroll level series vertically"
6736 static void CreateScreenMenubuttons()
6738 struct GadgetInfo *gi;
6739 unsigned int event_mask;
6742 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6744 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6745 int gfx_unpressed, gfx_pressed;
6746 int x, y, width, height;
6747 int gd_x1, gd_x2, gd_y1, gd_y2;
6748 int id = menubutton_info[i].gadget_id;
6750 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6752 menubutton_info[i].get_gadget_position(&x, &y, id);
6754 width = SC_MENUBUTTON_XSIZE;
6755 height = SC_MENUBUTTON_YSIZE;
6757 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6758 gfx_pressed = menubutton_info[i].gfx_pressed;
6759 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6760 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6761 gd_x1 = graphic_info[gfx_unpressed].src_x;
6762 gd_y1 = graphic_info[gfx_unpressed].src_y;
6763 gd_x2 = graphic_info[gfx_pressed].src_x;
6764 gd_y2 = graphic_info[gfx_pressed].src_y;
6766 gi = CreateGadget(GDI_CUSTOM_ID, id,
6767 GDI_CUSTOM_TYPE_ID, i,
6768 GDI_INFO_TEXT, menubutton_info[i].infotext,
6773 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6774 GDI_STATE, GD_BUTTON_UNPRESSED,
6775 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6776 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6777 GDI_DIRECT_DRAW, FALSE,
6778 GDI_EVENT_MASK, event_mask,
6779 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6783 Error(ERR_EXIT, "cannot create gadget");
6785 screen_gadget[id] = gi;
6789 static void CreateScreenScrollbuttons()
6791 struct GadgetInfo *gi;
6792 unsigned int event_mask;
6795 /* these values are not constant, but can change at runtime */
6796 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6797 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6798 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6799 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6801 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6803 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6804 int gfx_unpressed, gfx_pressed;
6805 int x, y, width, height;
6806 int gd_x1, gd_x2, gd_y1, gd_y2;
6807 int id = scrollbutton_info[i].gadget_id;
6809 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6811 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6812 y = mSY + scrollbutton_info[i].y;
6813 width = SC_SCROLLBUTTON_XSIZE;
6814 height = SC_SCROLLBUTTON_YSIZE;
6816 /* correct scrollbar position if placed outside menu (playfield) area */
6817 if (x > SX + SC_SCROLL_UP_XPOS)
6818 x = SX + SC_SCROLL_UP_XPOS;
6820 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6821 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6822 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6824 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6825 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6826 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6827 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6828 gd_x1 = graphic_info[gfx_unpressed].src_x;
6829 gd_y1 = graphic_info[gfx_unpressed].src_y;
6830 gd_x2 = graphic_info[gfx_pressed].src_x;
6831 gd_y2 = graphic_info[gfx_pressed].src_y;
6833 gi = CreateGadget(GDI_CUSTOM_ID, id,
6834 GDI_CUSTOM_TYPE_ID, i,
6835 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6840 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6841 GDI_STATE, GD_BUTTON_UNPRESSED,
6842 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6843 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6844 GDI_DIRECT_DRAW, FALSE,
6845 GDI_EVENT_MASK, event_mask,
6846 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6850 Error(ERR_EXIT, "cannot create gadget");
6852 screen_gadget[id] = gi;
6856 static void CreateScreenScrollbars()
6860 /* these values are not constant, but can change at runtime */
6861 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6862 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6863 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6864 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6866 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6868 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6869 int gfx_unpressed, gfx_pressed;
6870 int x, y, width, height;
6871 int gd_x1, gd_x2, gd_y1, gd_y2;
6872 struct GadgetInfo *gi;
6873 int items_max, items_visible, item_position;
6874 unsigned int event_mask;
6875 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6876 int id = scrollbar_info[i].gadget_id;
6878 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6880 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6881 y = mSY + scrollbar_info[i].y;
6882 width = scrollbar_info[i].width;
6883 height = scrollbar_info[i].height;
6885 /* correct scrollbar position if placed outside menu (playfield) area */
6886 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6887 x = SX + SC_SCROLL_VERTICAL_XPOS;
6889 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6890 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6892 items_max = num_page_entries;
6893 items_visible = num_page_entries;
6896 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6897 gfx_pressed = scrollbar_info[i].gfx_pressed;
6898 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6899 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6900 gd_x1 = graphic_info[gfx_unpressed].src_x;
6901 gd_y1 = graphic_info[gfx_unpressed].src_y;
6902 gd_x2 = graphic_info[gfx_pressed].src_x;
6903 gd_y2 = graphic_info[gfx_pressed].src_y;
6905 gi = CreateGadget(GDI_CUSTOM_ID, id,
6906 GDI_CUSTOM_TYPE_ID, i,
6907 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6912 GDI_TYPE, scrollbar_info[i].type,
6913 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6914 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6915 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6916 GDI_WHEEL_AREA_X, SX,
6917 GDI_WHEEL_AREA_Y, SY,
6918 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6919 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6920 GDI_STATE, GD_BUTTON_UNPRESSED,
6921 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6922 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6923 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6924 GDI_DIRECT_DRAW, FALSE,
6925 GDI_EVENT_MASK, event_mask,
6926 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6930 Error(ERR_EXIT, "cannot create gadget");
6932 screen_gadget[id] = gi;
6936 void CreateScreenGadgets()
6938 int last_game_status = game_status; /* save current game status */
6940 CreateScreenMenubuttons();
6942 CreateScreenScrollbuttons();
6943 CreateScreenScrollbars();
6945 SetGameStatus(last_game_status); /* restore current game status */
6948 void FreeScreenGadgets()
6952 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6953 FreeGadget(screen_gadget[i]);
6956 void MapScreenMenuGadgets(int screen_mask)
6960 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6961 if (screen_mask & menubutton_info[i].screen_mask)
6962 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6965 void MapScreenGadgets(int num_entries)
6969 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6972 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6973 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6975 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6976 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6979 void MapScreenTreeGadgets(TreeInfo *ti)
6981 MapScreenGadgets(numTreeInfoInGroup(ti));
6984 static void HandleScreenGadgets(struct GadgetInfo *gi)
6986 int id = gi->custom_id;
6987 int button = gi->event.button;
6988 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6992 case SCREEN_CTRL_ID_PREV_LEVEL:
6993 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6996 case SCREEN_CTRL_ID_NEXT_LEVEL:
6997 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
7000 case SCREEN_CTRL_ID_PREV_PLAYER:
7001 HandleSetupScreen_Input_Player(step, -1);
7004 case SCREEN_CTRL_ID_NEXT_PLAYER:
7005 HandleSetupScreen_Input_Player(step, +1);
7008 case SCREEN_CTRL_ID_SCROLL_UP:
7009 if (game_status == GAME_MODE_LEVELS)
7010 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7011 else if (game_status == GAME_MODE_LEVELNR)
7012 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7013 else if (game_status == GAME_MODE_SETUP)
7014 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7015 else if (game_status == GAME_MODE_INFO)
7016 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7019 case SCREEN_CTRL_ID_SCROLL_DOWN:
7020 if (game_status == GAME_MODE_LEVELS)
7021 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7022 else if (game_status == GAME_MODE_LEVELNR)
7023 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7024 else if (game_status == GAME_MODE_SETUP)
7025 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7026 else if (game_status == GAME_MODE_INFO)
7027 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7030 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7031 if (game_status == GAME_MODE_LEVELS)
7032 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7033 else if (game_status == GAME_MODE_LEVELNR)
7034 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7035 else if (game_status == GAME_MODE_SETUP)
7036 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7037 else if (game_status == GAME_MODE_INFO)
7038 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);