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_SCREEN_MODE 19
65 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
66 #define SETUP_MODE_CHOOSE_SCALING_TYPE 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 DrawAndFadeInInfoScreen(int);
178 static void DrawSetupScreen(void);
180 static void DrawInfoScreenExt(int, int);
181 static void DrawInfoScreen_NotAvailable(char *, char *);
182 static void DrawInfoScreen_HelpAnim(int, int, boolean);
183 static void DrawInfoScreen_HelpText(int, int, int, int);
184 static void HandleInfoScreen_Main(int, int, int, int, int);
185 static void HandleInfoScreen_TitleScreen(int);
186 static void HandleInfoScreen_Elements(int);
187 static void HandleInfoScreen_Music(int);
188 static void HandleInfoScreen_Credits(int);
189 static void HandleInfoScreen_Program(int);
190 static void HandleInfoScreen_Version(int);
192 static void MapScreenMenuGadgets(int);
193 static void MapScreenGadgets(int);
194 static void MapScreenTreeGadgets(TreeInfo *);
196 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
198 static int info_mode = INFO_MODE_MAIN;
199 static int setup_mode = SETUP_MODE_MAIN;
201 static TreeInfo *screen_modes = NULL;
202 static TreeInfo *screen_mode_current = NULL;
204 static TreeInfo *window_sizes = NULL;
205 static TreeInfo *window_size_current = NULL;
207 static TreeInfo *scaling_types = NULL;
208 static TreeInfo *scaling_type_current = NULL;
210 static TreeInfo *scroll_delays = NULL;
211 static TreeInfo *scroll_delay_current = NULL;
213 static TreeInfo *snapshot_modes = NULL;
214 static TreeInfo *snapshot_mode_current = NULL;
216 static TreeInfo *game_speeds = NULL;
217 static TreeInfo *game_speed_current = NULL;
219 static TreeInfo *volumes_simple = NULL;
220 static TreeInfo *volume_simple_current = NULL;
222 static TreeInfo *volumes_loops = NULL;
223 static TreeInfo *volume_loops_current = NULL;
225 static TreeInfo *volumes_music = NULL;
226 static TreeInfo *volume_music_current = NULL;
228 static TreeInfo *touch_controls = NULL;
229 static TreeInfo *touch_control_current = NULL;
231 static TreeInfo *move_distances = NULL;
232 static TreeInfo *move_distance_current = NULL;
234 static TreeInfo *drop_distances = NULL;
235 static TreeInfo *drop_distance_current = NULL;
237 static TreeInfo *level_number = NULL;
238 static TreeInfo *level_number_current = NULL;
244 } window_sizes_list[] =
249 { 100, "100 % (Default)" },
266 } scaling_types_list[] =
268 { SCALING_QUALITY_NEAREST, "None" },
269 { SCALING_QUALITY_LINEAR, "Linear" },
270 { SCALING_QUALITY_BEST, "Anisotropic" },
279 } game_speeds_list[] =
288 { 1000, "1/1s (Extremely Slow)" },
293 { 29, "1/35s (Original Supaplex)" },
295 { 20, "1/50s (Normal Speed)" },
296 { 14, "1/70s (Maximum Supaplex)" },
300 { 1, "1/1000s (Extremely Fast)" },
310 } scroll_delays_list[] =
312 { 0, "0 Tiles (No Scroll Delay)" },
315 { 3, "3 Tiles (Default)" },
320 { 8, "8 Tiles (Maximum Scroll Delay)"},
329 } snapshot_modes_list[] =
331 { STR_SNAPSHOT_MODE_OFF, "Off" },
332 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
333 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
366 } touch_controls_list[] =
368 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
369 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
393 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
394 (s) <= GAME_MODE_SETUP ? (s) : \
395 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
396 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
398 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
399 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
400 (i) <= INFO_MODE_LEVELSET ? (i) : \
403 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
404 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
405 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
406 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
407 SETUP_MODE_CHOOSE_ARTWORK : \
408 SETUP_MODE_CHOOSE_OTHER)
410 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
411 menu.draw_xoffset[GAME_MODE_INFO] : \
412 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
413 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
414 menu.draw_yoffset[GAME_MODE_INFO] : \
415 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
417 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
418 menu.draw_xoffset[GAME_MODE_SETUP] : \
419 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
420 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
421 menu.draw_yoffset[GAME_MODE_SETUP] : \
422 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
424 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
425 DRAW_XOFFSET_INFO(info_mode) : \
426 (s) == GAME_MODE_SETUP ? \
427 DRAW_XOFFSET_SETUP(setup_mode) : \
428 menu.draw_xoffset[DRAW_MODE(s)])
429 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
430 DRAW_YOFFSET_INFO(info_mode) : \
431 (s) == GAME_MODE_SETUP ? \
432 DRAW_YOFFSET_SETUP(setup_mode) : \
433 menu.draw_yoffset[DRAW_MODE(s)])
435 #define mSX (SX + DRAW_XOFFSET(game_status))
436 #define mSY (SY + DRAW_YOFFSET(game_status))
438 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
439 menu.list_size[game_status] : \
440 MAX_MENU_ENTRIES_ON_SCREEN)
442 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
443 NUM_MENU_ENTRIES_ON_SCREEN)
446 /* title display and control definitions */
448 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
449 2 * MAX_NUM_TITLE_MESSAGES)
451 #define NO_DIRECT_LEVEL_SELECT (-1)
454 static int num_title_screens = 0;
456 struct TitleControlInfo
464 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
466 /* main menu display and control definitions */
468 #define MAIN_CONTROL_NAME 0
469 #define MAIN_CONTROL_LEVELS 1
470 #define MAIN_CONTROL_SCORES 2
471 #define MAIN_CONTROL_EDITOR 3
472 #define MAIN_CONTROL_INFO 4
473 #define MAIN_CONTROL_GAME 5
474 #define MAIN_CONTROL_SETUP 6
475 #define MAIN_CONTROL_QUIT 7
476 #define MAIN_CONTROL_PREV_LEVEL 8
477 #define MAIN_CONTROL_NEXT_LEVEL 9
478 #define MAIN_CONTROL_FIRST_LEVEL 10
479 #define MAIN_CONTROL_LAST_LEVEL 11
480 #define MAIN_CONTROL_LEVEL_NUMBER 12
481 #define MAIN_CONTROL_LEVEL_INFO_1 13
482 #define MAIN_CONTROL_LEVEL_INFO_2 14
483 #define MAIN_CONTROL_LEVEL_NAME 15
484 #define MAIN_CONTROL_LEVEL_AUTHOR 16
485 #define MAIN_CONTROL_LEVEL_YEAR 17
486 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
487 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
488 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
489 #define MAIN_CONTROL_TITLE_1 21
490 #define MAIN_CONTROL_TITLE_2 22
491 #define MAIN_CONTROL_TITLE_3 23
493 static char str_main_text_name[10];
494 static char str_main_text_first_level[10];
495 static char str_main_text_last_level[10];
496 static char str_main_text_level_number[10];
498 static char *main_text_name = str_main_text_name;
499 static char *main_text_first_level = str_main_text_first_level;
500 static char *main_text_last_level = str_main_text_last_level;
501 static char *main_text_level_number = str_main_text_level_number;
502 static char *main_text_levels = "Levelset";
503 static char *main_text_scores = "Hall Of Fame";
504 static char *main_text_editor = "Level Creator";
505 static char *main_text_info = "Info Screen";
506 static char *main_text_game = "Start Game";
507 static char *main_text_setup = "Setup";
508 static char *main_text_quit = "Quit";
509 static char *main_text_level_name = level.name;
510 static char *main_text_level_author = level.author;
511 static char *main_text_level_year = NULL;
512 static char *main_text_level_imported_from = NULL;
513 static char *main_text_level_imported_by = NULL;
514 static char *main_text_level_tested_by = NULL;
516 struct MainControlInfo
520 struct MenuPosInfo *pos_button;
523 struct TextPosInfo *pos_text;
526 struct TextPosInfo *pos_input;
530 static struct MainControlInfo main_controls[] =
534 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
535 &menu.main.text.name, &main_text_name,
536 &menu.main.input.name, &setup.player_name,
540 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
541 &menu.main.text.levels, &main_text_levels,
546 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
547 &menu.main.text.scores, &main_text_scores,
552 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
553 &menu.main.text.editor, &main_text_editor,
558 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
559 &menu.main.text.info, &main_text_info,
564 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
565 &menu.main.text.game, &main_text_game,
570 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
571 &menu.main.text.setup, &main_text_setup,
576 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
577 &menu.main.text.quit, &main_text_quit,
581 /* (these two buttons are real gadgets) */
583 MAIN_CONTROL_PREV_LEVEL,
584 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
589 MAIN_CONTROL_NEXT_LEVEL,
590 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
596 MAIN_CONTROL_FIRST_LEVEL,
598 &menu.main.text.first_level, &main_text_first_level,
602 MAIN_CONTROL_LAST_LEVEL,
604 &menu.main.text.last_level, &main_text_last_level,
608 MAIN_CONTROL_LEVEL_NUMBER,
610 &menu.main.text.level_number, &main_text_level_number,
614 MAIN_CONTROL_LEVEL_INFO_1,
616 &menu.main.text.level_info_1, NULL,
620 MAIN_CONTROL_LEVEL_INFO_2,
622 &menu.main.text.level_info_2, NULL,
626 MAIN_CONTROL_LEVEL_NAME,
628 &menu.main.text.level_name, &main_text_level_name,
632 MAIN_CONTROL_LEVEL_AUTHOR,
634 &menu.main.text.level_author, &main_text_level_author,
638 MAIN_CONTROL_LEVEL_YEAR,
640 &menu.main.text.level_year, &main_text_level_year,
644 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
646 &menu.main.text.level_imported_from, &main_text_level_imported_from,
650 MAIN_CONTROL_LEVEL_IMPORTED_BY,
652 &menu.main.text.level_imported_by, &main_text_level_imported_by,
656 MAIN_CONTROL_LEVEL_TESTED_BY,
658 &menu.main.text.level_tested_by, &main_text_level_tested_by,
662 MAIN_CONTROL_TITLE_1,
664 &menu.main.text.title_1, &setup.internal.program_title,
668 MAIN_CONTROL_TITLE_2,
670 &menu.main.text.title_2, &setup.internal.program_copyright,
674 MAIN_CONTROL_TITLE_3,
676 &menu.main.text.title_3, &setup.internal.program_company,
689 static int getTitleScreenGraphic(int nr, boolean initial)
691 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
694 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
696 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
700 static int getTitleScreenGameMode(boolean initial)
702 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
706 static int getTitleMessageGameMode(boolean initial)
708 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
712 static int getTitleScreenBackground(boolean initial)
714 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
719 static int getTitleMessageBackground(int nr, boolean initial)
721 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
725 static int getTitleBackground(int nr, boolean initial, boolean is_image)
727 int base = (is_image ?
728 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
729 IMG_BACKGROUND_TITLESCREEN_1) :
730 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
731 IMG_BACKGROUND_TITLEMESSAGE_1));
732 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
733 IMG_BACKGROUND_TITLE);
734 int graphic_local = base + nr;
736 if (graphic_info[graphic_local].bitmap != NULL)
737 return graphic_local;
739 if (graphic_info[graphic_global].bitmap != NULL)
740 return graphic_global;
742 return IMG_UNDEFINED;
745 static int getTitleSound(struct TitleControlInfo *tci)
747 boolean is_image = tci->is_image;
748 int initial = tci->initial;
749 int nr = tci->local_nr;
750 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
751 int base = (is_image ?
752 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
753 SND_BACKGROUND_TITLESCREEN_1) :
754 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
755 SND_BACKGROUND_TITLEMESSAGE_1));
756 int sound_global = menu.sound[mode];
757 int sound_local = base + nr;
760 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
761 nr, initial, is_image,
762 sound_global, getSoundListEntry(sound_global)->filename,
763 sound_local, getSoundListEntry(sound_local)->filename);
766 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
769 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
772 return SND_UNDEFINED;
775 static int getTitleMusic(struct TitleControlInfo *tci)
777 boolean is_image = tci->is_image;
778 int initial = tci->initial;
779 int nr = tci->local_nr;
780 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
781 int base = (is_image ?
782 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
783 MUS_BACKGROUND_TITLESCREEN_1) :
784 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
785 MUS_BACKGROUND_TITLEMESSAGE_1));
786 int music_global = menu.music[mode];
787 int music_local = base + nr;
790 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
791 nr, initial, is_image,
792 music_global, getMusicListEntry(music_global)->filename,
793 music_local, getMusicListEntry(music_local)->filename);
796 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
799 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
802 return MUS_UNDEFINED;
805 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
807 boolean is_image = tci->is_image;
808 int initial = tci->initial;
809 int nr = tci->local_nr;
810 struct TitleFadingInfo ti;
814 int graphic = getTitleScreenGraphic(nr, initial);
816 /* initialize fading control values to default title config settings */
817 ti = (initial ? title_initial_default : title_default);
819 /* override default settings with image config settings, if defined */
820 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
821 ti.fade_mode = graphic_info[graphic].fade_mode;
822 if (graphic_info[graphic].fade_delay > -1)
823 ti.fade_delay = graphic_info[graphic].fade_delay;
824 if (graphic_info[graphic].post_delay > -1)
825 ti.post_delay = graphic_info[graphic].post_delay;
826 if (graphic_info[graphic].auto_delay > -1)
827 ti.auto_delay = graphic_info[graphic].auto_delay;
833 ti.fade_mode = titlemessage_initial[nr].fade_mode;
834 ti.fade_delay = titlemessage_initial[nr].fade_delay;
835 ti.post_delay = titlemessage_initial[nr].post_delay;
836 ti.auto_delay = titlemessage_initial[nr].auto_delay;
840 ti.fade_mode = titlemessage[nr].fade_mode;
841 ti.fade_delay = titlemessage[nr].fade_delay;
842 ti.post_delay = titlemessage[nr].post_delay;
843 ti.auto_delay = titlemessage[nr].auto_delay;
850 static int compareTitleControlInfo(const void *object1, const void *object2)
852 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
853 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
856 if (tci1->initial != tci2->initial)
857 compare_result = (tci1->initial ? -1 : +1);
858 else if (tci1->sort_priority != tci2->sort_priority)
859 compare_result = tci1->sort_priority - tci2->sort_priority;
860 else if (tci1->is_image != tci2->is_image)
861 compare_result = (tci1->is_image ? -1 : +1);
863 compare_result = tci1->local_nr - tci2->local_nr;
865 return compare_result;
868 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
870 int nr, int sort_priority)
872 title_controls[num_title_screens].is_image = is_image;
873 title_controls[num_title_screens].initial = initial;
874 title_controls[num_title_screens].local_nr = nr;
875 title_controls[num_title_screens].sort_priority = sort_priority;
880 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
884 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
886 int graphic = getTitleScreenGraphic(i, initial);
887 Bitmap *bitmap = graphic_info[graphic].bitmap;
888 int sort_priority = graphic_info[graphic].sort_priority;
891 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
894 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
896 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
897 char *filename = getLevelSetTitleMessageFilename(i, initial);
898 int sort_priority = tmi->sort_priority;
900 if (filename != NULL)
901 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
905 static void InitializeTitleControls(boolean show_title_initial)
907 num_title_screens = 0;
909 /* 1st step: initialize title screens for game start (only when starting) */
910 if (show_title_initial)
911 InitializeTitleControls_CheckTitleInfo(TRUE);
913 /* 2nd step: initialize title screens for current level set */
914 InitializeTitleControls_CheckTitleInfo(FALSE);
916 /* sort title screens according to sort_priority and title number */
917 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
918 compareTitleControlInfo);
921 static boolean visibleMenuPos(struct MenuPosInfo *pos)
923 return (pos != NULL && pos->x != -1 && pos->y != -1);
926 static boolean visibleTextPos(struct TextPosInfo *pos)
928 return (pos != NULL && pos->x != -1 && pos->y != -1);
931 static void InitializeMainControls()
933 boolean local_team_mode = (!options.network && setup.team_mode);
936 /* set main control text values to dynamically determined values */
937 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
939 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
940 menu.main.text.first_level.size));
941 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
942 menu.main.text.last_level.size));
943 strcpy(main_text_level_number, int2str(level_nr,
944 menu.main.text.level_number.size));
946 main_text_level_year = leveldir_current->year;
947 main_text_level_imported_from = leveldir_current->imported_from;
948 main_text_level_imported_by = leveldir_current->imported_by;
949 main_text_level_tested_by = leveldir_current->tested_by;
951 /* set main control screen positions to dynamically determined values */
952 for (i = 0; main_controls[i].nr != -1; i++)
954 struct MainControlInfo *mci = &main_controls[i];
956 struct MenuPosInfo *pos_button = mci->pos_button;
957 struct TextPosInfo *pos_text = mci->pos_text;
958 struct TextPosInfo *pos_input = mci->pos_input;
959 char *text = (mci->text ? *mci->text : NULL);
960 char *input = (mci->input ? *mci->input : NULL);
961 int button_graphic = mci->button_graphic;
962 int font_text = (pos_text ? pos_text->font : -1);
963 int font_input = (pos_input ? pos_input->font : -1);
965 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
966 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
967 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
968 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
969 int text_chars = (text != NULL ? strlen(text) : 0);
970 int input_chars = (input != NULL ? strlen(input) : 0);
973 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
975 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
976 int text_width = font_text_width * text_chars;
977 int text_height = font_text_height;
978 int input_width = font_input_width * input_chars;
979 int input_height = font_input_height;
981 if (nr == MAIN_CONTROL_NAME)
983 menu.main.input.name.width = input_width;
984 menu.main.input.name.height = input_height;
987 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
989 pos_button->width = button_width;
990 pos_button->height = button_height;
993 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
995 /* calculate size for non-clickable text -- needed for text alignment */
996 boolean calculate_text_size = (pos_button == NULL && text != NULL);
998 if (pos_text->width == -1 || calculate_text_size)
999 pos_text->width = text_width;
1000 if (pos_text->height == -1 || calculate_text_size)
1001 pos_text->height = text_height;
1003 if (visibleMenuPos(pos_button))
1005 if (pos_text->x == -1)
1006 pos_text->x = pos_button->x + pos_button->width;
1007 if (pos_text->y == -1)
1009 pos_button->y + (pos_button->height - pos_text->height) / 2;
1013 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1015 if (visibleTextPos(pos_text))
1017 if (pos_input->x == -1)
1018 pos_input->x = pos_text->x + pos_text->width;
1019 if (pos_input->y == -1)
1020 pos_input->y = pos_text->y;
1023 if (pos_input->width == -1)
1024 pos_input->width = input_width;
1025 if (pos_input->height == -1)
1026 pos_input->height = input_height;
1031 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1032 int graphic, boolean pressed)
1034 struct GraphicInfo *g = &graphic_info[graphic];
1037 int xoffset = (pressed ? g->pressed_xoffset : 0);
1038 int yoffset = (pressed ? g->pressed_yoffset : 0);
1040 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1042 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1043 g->width, g->height, dst_x, dst_y);
1046 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1047 boolean active_input,
1048 boolean pressed_button)
1052 for (i = 0; main_controls[i].nr != -1; i++)
1054 struct MainControlInfo *mci = &main_controls[i];
1056 if (mci->nr == nr || nr == -1)
1058 struct MenuPosInfo *pos_button = mci->pos_button;
1059 struct TextPosInfo *pos_text = mci->pos_text;
1060 struct TextPosInfo *pos_input = mci->pos_input;
1061 char *text = (mci->text ? *mci->text : NULL);
1062 char *input = (mci->input ? *mci->input : NULL);
1063 int button_graphic = mci->button_graphic;
1064 int font_text = (pos_text ? pos_text->font : -1);
1065 int font_input = (pos_input ? pos_input->font : -1);
1069 button_graphic = BUTTON_ACTIVE(button_graphic);
1070 font_text = FONT_ACTIVE(font_text);
1075 font_input = FONT_ACTIVE(font_input);
1078 if (visibleMenuPos(pos_button))
1080 struct MenuPosInfo *pos = pos_button;
1081 int x = mSX + pos->x;
1082 int y = mSY + pos->y;
1084 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1085 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1088 if (visibleTextPos(pos_text) && text != NULL)
1090 struct TextPosInfo *pos = pos_text;
1091 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1092 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1095 /* (check why/if this is needed) */
1096 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1098 DrawText(x, y, text, font_text);
1101 if (visibleTextPos(pos_input) && input != NULL)
1103 struct TextPosInfo *pos = pos_input;
1104 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1105 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1108 /* (check why/if this is needed) */
1109 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1111 DrawText(x, y, input, font_input);
1117 static void DrawCursorAndText_Main(int nr, boolean active_text,
1118 boolean pressed_button)
1120 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1124 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1125 boolean pressed_button)
1127 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1131 static struct MainControlInfo *getMainControlInfo(int nr)
1135 for (i = 0; main_controls[i].nr != -1; i++)
1136 if (main_controls[i].nr == nr)
1137 return &main_controls[i];
1142 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1147 int rect_x = ALIGNED_TEXT_XPOS(rect);
1148 int rect_y = ALIGNED_TEXT_YPOS(rect);
1150 return (x >= rect_x && x < rect_x + rect->width &&
1151 y >= rect_y && y < rect_y + rect->height);
1154 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1159 int rect_x = ALIGNED_TEXT_XPOS(rect);
1160 int rect_y = ALIGNED_TEXT_YPOS(rect);
1163 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1164 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1165 (x >= rect_x && x < rect_x + rect->width &&
1166 y >= rect_y && y < rect_y + rect->height));
1169 return (x >= rect_x && x < rect_x + rect->width &&
1170 y >= rect_y && y < rect_y + rect->height);
1173 static void AdjustScrollbar(int id, int items_max, int items_visible,
1176 struct GadgetInfo *gi = screen_gadget[id];
1178 if (item_position > items_max - items_visible)
1179 item_position = items_max - items_visible;
1181 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1182 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1183 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1186 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1188 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1192 static void clearMenuListArea()
1194 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1196 /* correct scrollbar position if placed outside menu (playfield) area */
1197 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1198 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1200 /* clear menu list area, but not title or scrollbar */
1201 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1202 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1205 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1207 static int cursor_array[MAX_LEV_FIELDY];
1208 int x = mSX + TILEX * xpos;
1209 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1214 cursor_array[ypos] = graphic;
1216 graphic = cursor_array[ypos];
1220 graphic = BUTTON_ACTIVE(graphic);
1222 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1223 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1226 static void initCursor(int ypos, int graphic)
1228 drawCursorExt(0, ypos, FALSE, graphic);
1231 static void drawCursor(int ypos, boolean active)
1233 drawCursorExt(0, ypos, active, -1);
1236 static void drawCursorXY(int xpos, int ypos, int graphic)
1238 drawCursorExt(xpos, ypos, FALSE, graphic);
1241 static void drawChooseTreeCursor(int ypos, boolean active)
1243 int last_game_status = game_status; /* save current game status */
1245 drawCursorExt(0, ypos, active, -1);
1247 game_status = last_game_status; /* restore current game status */
1252 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, getProgramTitleString());
1253 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
1254 setup.internal.program_copyright);
1257 int effectiveGameStatus()
1259 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1260 return GAME_MODE_TITLE;
1265 void DrawTitleScreenImage(int nr, boolean initial)
1267 int graphic = getTitleScreenGraphic(nr, initial);
1268 Bitmap *bitmap = graphic_info[graphic].bitmap;
1269 int width = graphic_info[graphic].width;
1270 int height = graphic_info[graphic].height;
1271 int src_x = graphic_info[graphic].src_x;
1272 int src_y = graphic_info[graphic].src_y;
1278 if (width > WIN_XSIZE)
1280 /* image width too large for window => center image horizontally */
1281 src_x = (width - WIN_XSIZE) / 2;
1285 if (height > WIN_YSIZE)
1287 /* image height too large for window => center image vertically */
1288 src_y = (height - WIN_YSIZE) / 2;
1292 /* always display title screens centered */
1293 dst_x = (WIN_XSIZE - width) / 2;
1294 dst_y = (WIN_YSIZE - height) / 2;
1296 SetDrawBackgroundMask(REDRAW_ALL);
1297 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1299 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1301 if (DrawingOnBackground(dst_x, dst_y))
1302 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1304 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1306 redraw_mask = REDRAW_ALL;
1309 void DrawTitleScreenMessage(int nr, boolean initial)
1311 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1312 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1313 int last_game_status = game_status; /* save current game status */
1315 if (filename == NULL)
1318 /* force TITLE font on title message screen */
1319 game_status = getTitleMessageGameMode(initial);
1321 /* if chars set to "-1", automatically determine by text and font width */
1322 if (tmi->chars == -1)
1323 tmi->chars = tmi->width / getFontWidth(tmi->font);
1325 tmi->width = tmi->chars * getFontWidth(tmi->font);
1327 /* if lines set to "-1", automatically determine by text and font height */
1328 if (tmi->lines == -1)
1329 tmi->lines = tmi->height / getFontHeight(tmi->font);
1331 tmi->height = tmi->lines * getFontHeight(tmi->font);
1333 SetDrawBackgroundMask(REDRAW_ALL);
1334 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1336 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1338 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1339 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1340 tmi->autowrap, tmi->centered, tmi->parse_comments);
1342 game_status = last_game_status; /* restore current game status */
1345 void DrawTitleScreen()
1347 KeyboardAutoRepeatOff();
1349 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1354 boolean CheckTitleScreen(boolean levelset_has_changed)
1356 static boolean show_title_initial = TRUE;
1357 boolean show_titlescreen = FALSE;
1359 /* needed to be able to skip title screen, if no image or message defined */
1360 InitializeTitleControls(show_title_initial);
1362 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1363 show_titlescreen = TRUE;
1365 /* show initial title images and messages only once at program start */
1366 show_title_initial = FALSE;
1368 return (show_titlescreen && num_title_screens > 0);
1371 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1373 static LevelDirTree *leveldir_last_valid = NULL;
1374 boolean levelset_has_changed = FALSE;
1376 LimitScreenUpdates(FALSE);
1378 FadeSetLeaveScreen();
1380 /* do not fade out here -- function may continue and fade on editor screen */
1383 FadeSoundsAndMusic();
1385 KeyboardAutoRepeatOn();
1388 audio.sound_deactivated = FALSE;
1392 /* needed if last screen was the playing screen, invoked from level editor */
1393 if (level_editor_test_game)
1395 game_status = GAME_MODE_EDITOR;
1401 /* needed if last screen was the setup screen and fullscreen state changed */
1402 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1403 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1405 /* leveldir_current may be invalid (level group, parent link) */
1406 if (!validLevelSeries(leveldir_current))
1407 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1409 if (leveldir_current != leveldir_last_valid)
1410 levelset_has_changed = TRUE;
1412 /* store valid level series information */
1413 leveldir_last_valid = leveldir_current;
1415 init_last = init; /* switch to new busy animation */
1417 /* needed if last screen (level choice) changed graphics, sounds or music */
1418 ReloadCustomArtwork(0);
1420 if (redraw_mask & REDRAW_ALL)
1421 fade_mask = REDRAW_ALL;
1425 /* needed if different viewport properties defined for menues */
1426 ChangeViewportPropertiesIfNeeded();
1428 /* needed if last screen was the editor screen */
1429 UndrawSpecialEditorDoor();
1431 SetDrawtoField(DRAW_BACKBUFFER);
1433 if (CheckTitleScreen(levelset_has_changed))
1435 game_status = GAME_MODE_TITLE;
1442 /* level_nr may have been set to value over handicap with level editor */
1443 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1444 level_nr = leveldir_current->handicap_level;
1446 LoadLevel(level_nr);
1447 LoadScore(level_nr);
1449 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1450 SetDrawDeactivationMask(REDRAW_NONE);
1451 SetDrawBackgroundMask(REDRAW_FIELD);
1453 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1455 if (fade_mask == REDRAW_ALL)
1456 RedrawGlobalBorder();
1460 InitializeMainControls();
1462 DrawCursorAndText_Main(-1, FALSE, FALSE);
1463 DrawPreviewLevelInitial();
1465 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1468 if (TAPE_IS_EMPTY(tape))
1470 DrawCompleteVideoDisplay();
1475 /* create gadgets for main menu screen */
1476 FreeScreenGadgets();
1477 CreateScreenGadgets();
1479 /* map gadgets for main menu screen */
1481 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1483 /* copy actual game door content to door double buffer for OpenDoor() */
1484 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1486 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1488 DrawMaskedBorder(REDRAW_ALL);
1493 /* update screen area with special editor door */
1494 redraw_mask |= REDRAW_ALL;
1497 SetMouseCursor(CURSOR_DEFAULT);
1501 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1504 void DrawAndFadeInMainMenu(int fade_mask)
1506 DrawMainMenuExt(fade_mask, TRUE);
1511 DrawMainMenuExt(REDRAW_ALL, FALSE);
1514 static void gotoTopLevelDir()
1516 /* move upwards until inside (but not above) top level directory */
1517 while (leveldir_current->node_parent &&
1518 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1520 /* write a "path" into level tree for easy navigation to last level */
1521 if (leveldir_current->node_parent->node_group->cl_first == -1)
1523 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1524 int leveldir_pos = posTreeInfo(leveldir_current);
1525 int num_page_entries;
1526 int cl_first, cl_cursor;
1528 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1529 num_page_entries = num_leveldirs;
1531 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1533 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1534 cl_cursor = leveldir_pos - cl_first;
1536 leveldir_current->node_parent->node_group->cl_first = cl_first;
1537 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1540 leveldir_current = leveldir_current->node_parent;
1544 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1546 static unsigned int title_delay = 0;
1547 static int title_screen_nr = 0;
1548 static int last_sound = -1, last_music = -1;
1549 boolean return_to_main_menu = FALSE;
1550 boolean use_fading_main_menu = TRUE;
1551 struct TitleControlInfo *tci;
1552 struct TitleFadingInfo fading_default;
1553 struct TitleFadingInfo fading_last = fading;
1554 struct TitleFadingInfo fading_next;
1557 if (button == MB_MENU_INITIALIZE)
1560 title_screen_nr = 0;
1561 tci = &title_controls[title_screen_nr];
1563 last_sound = SND_UNDEFINED;
1564 last_music = MUS_UNDEFINED;
1566 if (game_status == GAME_MODE_INFO)
1568 if (num_title_screens == 0)
1570 DrawInfoScreen_NotAvailable("Title screen information:",
1571 "No title screen for this level set.");
1576 FadeSoundsAndMusic();
1578 FadeOut(REDRAW_ALL);
1582 DrawTitleScreenImage(tci->local_nr, tci->initial);
1584 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1586 fading_default = (tci->initial ? title_initial_default : title_default);
1588 fading = fading_next = getTitleFading(tci);
1590 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1591 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1593 fading.fade_mode = FADE_MODE_FADE;
1594 fading.fade_delay = fading_default.fade_delay;
1597 sound = getTitleSound(tci);
1598 music = getTitleMusic(tci);
1600 if (sound != last_sound)
1601 PlayMenuSoundExt(sound);
1602 if (music != last_music)
1603 PlayMenuMusicExt(music);
1608 SetMouseCursor(CURSOR_NONE);
1612 fading = fading_next;
1614 DelayReached(&title_delay, 0); /* reset delay counter */
1619 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1620 button = MB_MENU_CHOICE;
1622 if (button == MB_MENU_LEAVE)
1624 return_to_main_menu = TRUE;
1625 use_fading_main_menu = FALSE;
1627 else if (button == MB_MENU_CHOICE)
1629 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1631 FadeSetEnterScreen();
1633 info_mode = INFO_MODE_MAIN;
1634 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1640 tci = &title_controls[title_screen_nr];
1642 if (title_screen_nr < num_title_screens)
1644 sound = getTitleSound(tci);
1645 music = getTitleMusic(tci);
1647 if (sound == SND_UNDEFINED || sound != last_sound)
1649 if (music == MUS_UNDEFINED || music != last_music)
1652 FadeOut(REDRAW_ALL);
1655 DrawTitleScreenImage(tci->local_nr, tci->initial);
1657 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1659 fading_next = getTitleFading(tci);
1661 sound = getTitleSound(tci);
1662 music = getTitleMusic(tci);
1664 if (sound != last_sound)
1665 PlayMenuSoundExt(sound);
1666 if (music != last_music)
1667 PlayMenuMusicExt(music);
1672 /* last screen already faded out, next screen has no animation */
1673 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1674 fading_next.fade_mode == FADE_MODE_NONE)
1675 fading = fading_next;
1679 fading = fading_next;
1681 DelayReached(&title_delay, 0); /* reset delay counter */
1685 FadeSoundsAndMusic();
1687 return_to_main_menu = TRUE;
1691 if (return_to_main_menu)
1693 SetMouseCursor(CURSOR_DEFAULT);
1695 if (game_status == GAME_MODE_INFO)
1697 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1699 info_mode = INFO_MODE_MAIN;
1701 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1703 else /* default: return to main menu */
1705 game_status = GAME_MODE_MAIN;
1707 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1712 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1714 int old_level_nr = level_nr;
1717 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1718 new_level_nr = selected_level_nr;
1720 new_level_nr = old_level_nr + step * direction;
1722 if (new_level_nr < leveldir_current->first_level)
1723 new_level_nr = leveldir_current->first_level;
1724 if (new_level_nr > leveldir_current->last_level)
1725 new_level_nr = leveldir_current->last_level;
1727 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1729 /* skipping levels is only allowed when trying to skip single level */
1730 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1731 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1733 leveldir_current->handicap_level++;
1734 SaveLevelSetup_SeriesInfo();
1737 new_level_nr = leveldir_current->handicap_level;
1740 if (new_level_nr != old_level_nr)
1742 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1744 PlaySound(SND_MENU_ITEM_SELECTING);
1746 level_nr = new_level_nr;
1748 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1749 int2str(level_nr, menu.main.text.level_number.size),
1750 mci->pos_text->font);
1752 LoadLevel(level_nr);
1753 DrawPreviewLevelInitial();
1757 DrawCompleteVideoDisplay();
1759 /* needed because DrawPreviewLevelInitial() takes some time */
1761 /* SyncDisplay(); */
1765 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1767 static int choice = MAIN_CONTROL_GAME;
1768 static boolean button_pressed_last = FALSE;
1769 boolean button_pressed = FALSE;
1773 if (button == MB_MENU_INITIALIZE)
1775 DrawCursorAndText_Main(choice, TRUE, FALSE);
1780 if (mx || my) /* mouse input */
1784 for (i = 0; main_controls[i].nr != -1; i++)
1786 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1787 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1788 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1790 pos = main_controls[i].nr;
1796 // handle pressed/unpressed state for active/inactive menu buttons
1797 // (if pos != -1, "i" contains index position corresponding to "pos")
1799 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1800 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1801 button_pressed = TRUE;
1803 if (button_pressed != button_pressed_last)
1805 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1808 PlaySound(SND_MENU_BUTTON_PRESSING);
1810 PlaySound(SND_MENU_BUTTON_RELEASING);
1813 else if (dx || dy) /* keyboard input */
1815 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1816 choice == MAIN_CONTROL_SETUP))
1817 button = MB_MENU_CHOICE;
1822 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1824 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1826 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1828 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1830 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1832 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1834 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1836 game_status = GAME_MODE_LEVELNR;
1838 ChangeViewportPropertiesIfNeeded();
1840 DrawChooseLevelNr();
1842 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1848 PlaySound(SND_MENU_ITEM_ACTIVATING);
1850 DrawCursorAndText_Main(choice, FALSE, FALSE);
1851 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1858 PlaySound(SND_MENU_ITEM_SELECTING);
1860 if (pos == MAIN_CONTROL_NAME)
1862 game_status = GAME_MODE_PSEUDO_TYPENAME;
1864 HandleTypeName(strlen(setup.player_name), 0);
1866 else if (pos == MAIN_CONTROL_LEVELS)
1870 game_status = GAME_MODE_LEVELS;
1872 SaveLevelSetup_LastSeries();
1873 SaveLevelSetup_SeriesInfo();
1875 if (setup.internal.choose_from_top_leveldir)
1878 ChangeViewportPropertiesIfNeeded();
1880 DrawChooseLevelSet();
1883 else if (pos == MAIN_CONTROL_SCORES)
1885 game_status = GAME_MODE_SCORES;
1887 ChangeViewportPropertiesIfNeeded();
1891 else if (pos == MAIN_CONTROL_EDITOR)
1893 if (leveldir_current->readonly &&
1894 !strEqual(setup.player_name, "Artsoft"))
1895 Request("This level is read only!", REQ_CONFIRM);
1897 CloseDoor(DOOR_CLOSE_2);
1899 game_status = GAME_MODE_EDITOR;
1901 FadeSetEnterScreen();
1905 else if (pos == MAIN_CONTROL_INFO)
1907 game_status = GAME_MODE_INFO;
1908 info_mode = INFO_MODE_MAIN;
1910 ChangeViewportPropertiesIfNeeded();
1914 else if (pos == MAIN_CONTROL_GAME)
1916 StartGameActions(options.network, setup.autorecord, level.random_seed);
1918 else if (pos == MAIN_CONTROL_SETUP)
1920 game_status = GAME_MODE_SETUP;
1921 setup_mode = SETUP_MODE_MAIN;
1923 ChangeViewportPropertiesIfNeeded();
1927 else if (pos == MAIN_CONTROL_QUIT)
1929 SaveLevelSetup_LastSeries();
1930 SaveLevelSetup_SeriesInfo();
1932 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1933 game_status = GAME_MODE_QUIT;
1938 button_pressed_last = button_pressed;
1942 /* ========================================================================= */
1943 /* info screen functions */
1944 /* ========================================================================= */
1946 static struct TokenInfo *info_info;
1947 static int num_info_info; /* number of info entries shown on screen */
1948 static int max_info_info; /* total number of info entries in list */
1950 static void execInfoTitleScreen()
1952 info_mode = INFO_MODE_TITLE;
1957 static void execInfoElements()
1959 info_mode = INFO_MODE_ELEMENTS;
1964 static void execInfoMusic()
1966 info_mode = INFO_MODE_MUSIC;
1971 static void execInfoCredits()
1973 info_mode = INFO_MODE_CREDITS;
1978 static void execInfoProgram()
1980 info_mode = INFO_MODE_PROGRAM;
1985 static void execInfoVersion()
1987 info_mode = INFO_MODE_VERSION;
1992 static void execInfoLevelSet()
1994 info_mode = INFO_MODE_LEVELSET;
1999 static void execExitInfo()
2001 game_status = GAME_MODE_MAIN;
2003 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2006 static struct TokenInfo info_info_main[] =
2008 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2009 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2010 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2011 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2012 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2013 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2014 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2015 { TYPE_EMPTY, NULL, "" },
2016 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2021 static int getMenuTextFont(int type)
2023 if (type & (TYPE_SWITCH |
2035 static struct TokenInfo *setup_info;
2036 static struct TokenInfo setup_info_input[];
2038 static struct TokenInfo *menu_info;
2040 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2041 int screen_pos, int menu_info_pos_raw,
2044 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2045 struct TokenInfo *ti = &token_info[pos];
2046 int xpos = MENU_SCREEN_START_XPOS;
2047 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2048 int font_nr = getMenuTextFont(ti->type);
2050 if (token_info == setup_info_input)
2051 font_nr = FONT_MENU_1;
2054 font_nr = FONT_ACTIVE(font_nr);
2056 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2058 if (ti->type & ~TYPE_SKIP_ENTRY)
2059 drawCursor(screen_pos, active);
2062 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2065 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2068 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2071 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2074 static char *screen_mode_text;
2075 static char *window_size_text;
2076 static char *scaling_type_text;
2078 static void drawSetupValue(int, int);
2080 static void drawMenuInfoList(int first_entry, int num_page_entries,
2081 int max_page_entries)
2085 if (first_entry + num_page_entries > max_page_entries)
2088 clearMenuListArea();
2090 for (i = 0; i < num_page_entries; i++)
2092 int menu_info_pos = first_entry + i;
2093 struct TokenInfo *si = &menu_info[menu_info_pos];
2094 void *value_ptr = si->value;
2096 /* set some entries to "unchangeable" according to other variables */
2097 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2098 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2099 (value_ptr == &setup.sound_music && !audio.music_available) ||
2100 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2101 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2102 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2103 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2104 si->type |= TYPE_GHOSTED;
2106 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2107 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2108 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2109 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2110 else if (si->type & ~TYPE_SKIP_ENTRY)
2111 initCursor(i, IMG_MENU_BUTTON);
2113 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2115 if (si->type & TYPE_VALUE &&
2116 menu_info == setup_info)
2117 drawSetupValue(i, menu_info_pos);
2121 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2127 FreeScreenGadgets();
2128 CreateScreenGadgets();
2130 CloseDoor(DOOR_CLOSE_2);
2132 /* (needed after displaying title screens which disable auto repeat) */
2133 KeyboardAutoRepeatOn();
2135 FadeSetLeaveScreen();
2139 if (fade_mask == REDRAW_ALL)
2141 RedrawGlobalBorder();
2143 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2148 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2150 info_info = info_info_main;
2152 // determine maximal number of info entries that can be displayed on screen
2154 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2157 // determine maximal number of info entries available for menu of info screen
2159 for (i = 0; info_info[i].type != 0; i++)
2162 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2164 MapScreenGadgets(max_info_info);
2169 DrawMaskedBorder(fade_mask);
2176 static void changeSetupValue(int, int, int);
2178 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2179 int mode, int num_page_entries, int max_page_entries)
2181 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2182 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2183 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2184 int *num_page_entries_last = num_page_entries_all_last[game_status];
2185 int *choice_store = choice_stores[game_status];
2186 int *first_entry_store = first_entry_stores[game_status];
2187 int choice = choice_store[mode]; /* starts with 0 */
2188 int first_entry = first_entry_store[mode]; /* starts with 0 */
2190 int y = choice - first_entry;
2192 boolean position_set_by_scrollbar = (dx == 999);
2193 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2196 if (button == MB_MENU_INITIALIZE)
2198 // check if number of menu page entries has changed (may happen by change
2199 // of custom artwork definition value for 'list_size' for this menu screen)
2200 // (in this case, the last menu position most probably has to be corrected)
2201 if (num_page_entries != num_page_entries_last[mode])
2203 choice_store[mode] = first_entry_store[mode] = 0;
2205 choice = first_entry = 0;
2208 num_page_entries_last[mode] = num_page_entries;
2211 /* advance to first valid menu entry */
2212 while (choice < num_page_entries &&
2213 menu_info[choice].type & TYPE_SKIP_ENTRY)
2216 if (position_set_by_scrollbar)
2217 first_entry = first_entry_store[mode] = dy;
2219 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2220 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2222 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2224 if (choice < first_entry)
2226 choice = first_entry;
2228 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2231 else if (choice > first_entry + num_page_entries - 1)
2233 choice = first_entry + num_page_entries - 1;
2235 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2239 choice_store[mode] = choice;
2241 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2245 else if (button == MB_MENU_LEAVE)
2247 PlaySound(SND_MENU_ITEM_SELECTING);
2249 for (i = 0; i < max_page_entries; i++)
2251 if (menu_info[i].type & TYPE_LEAVE_MENU)
2253 void (*menu_callback_function)(void) = menu_info[i].value;
2257 menu_callback_function();
2259 break; /* absolutely needed because function changes 'menu_info'! */
2266 if (mx || my) /* mouse input */
2268 x = (mx - mSX) / 32;
2269 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2271 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2273 /* move cursor instead of scrolling when already at start/end of list */
2274 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2276 else if (dy == +1 * SCROLL_LINE &&
2277 first_entry + num_page_entries == max_page_entries)
2280 /* handle scrolling screen one line or page */
2282 y + dy > num_page_entries - 1)
2284 boolean redraw = FALSE;
2286 if (ABS(dy) == SCROLL_PAGE)
2287 step = num_page_entries - 1;
2289 if (dy < 0 && first_entry > 0)
2291 /* scroll page/line up */
2293 first_entry -= step;
2294 if (first_entry < 0)
2299 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2301 /* scroll page/line down */
2303 first_entry += step;
2304 if (first_entry + num_page_entries > max_page_entries)
2305 first_entry = MAX(0, max_page_entries - num_page_entries);
2312 choice += first_entry - first_entry_store[mode];
2314 if (choice < first_entry)
2316 choice = first_entry;
2318 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2321 else if (choice > first_entry + num_page_entries - 1)
2323 choice = first_entry + num_page_entries - 1;
2325 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2328 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2332 if (choice < first_entry ||
2333 choice > first_entry + num_page_entries - 1)
2334 first_entry += SIGN(dy);
2337 first_entry_store[mode] = first_entry;
2338 choice_store[mode] = choice;
2340 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2342 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2344 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2345 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2353 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2355 if (menu_info[choice].type & menu_navigation_type ||
2356 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2357 menu_info[choice].type & TYPE_YES_NO_AUTO)
2358 button = MB_MENU_CHOICE;
2363 /* jump to next non-empty menu entry (up or down) */
2364 while (first_entry + y > 0 &&
2365 first_entry + y < max_page_entries - 1 &&
2366 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2369 if (!IN_VIS_MENU(x, y))
2371 choice += y - y_old;
2373 if (choice < first_entry)
2374 first_entry = choice;
2375 else if (choice > first_entry + num_page_entries - 1)
2376 first_entry = choice - num_page_entries + 1;
2378 if (first_entry >= 0 &&
2379 first_entry + num_page_entries <= max_page_entries)
2381 first_entry_store[mode] = first_entry;
2383 if (choice < first_entry)
2384 choice = first_entry;
2385 else if (choice > first_entry + num_page_entries - 1)
2386 choice = first_entry + num_page_entries - 1;
2388 choice_store[mode] = choice;
2390 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2392 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2394 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2395 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2402 if (!anyScrollbarGadgetActive() &&
2403 IN_VIS_MENU(x, y) &&
2404 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2405 y >= 0 && y < num_page_entries)
2409 if (first_entry + y != choice &&
2410 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2412 PlaySound(SND_MENU_ITEM_ACTIVATING);
2414 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2415 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2417 choice = choice_store[mode] = first_entry + y;
2420 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2422 PlaySound(SND_MENU_ITEM_SELECTING);
2424 /* when selecting key headline, execute function for key value change */
2425 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2426 menu_info[first_entry + y + 1].type & TYPE_KEY)
2429 /* when selecting string value, execute function for list selection */
2430 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2431 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2434 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2436 void (*menu_callback_function)(void) =
2437 menu_info[first_entry + y].value;
2439 FadeSetFromType(menu_info[first_entry + y].type);
2441 menu_callback_function();
2443 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2444 menu_info == setup_info)
2446 changeSetupValue(y, first_entry + y, dx);
2452 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2454 menu_info = info_info;
2456 HandleMenuScreen(mx, my, dx, dy, button,
2457 info_mode, num_info_info, max_info_info);
2460 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2462 int ystart1 = mSY - SY + 100;
2463 int ystart2 = mSY - SY + 150;
2464 int ybottom = mSY - SY + SYSIZE - 20;
2466 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2468 FadeOut(REDRAW_FIELD);
2473 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2474 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2476 DrawTextSCentered(ybottom, FONT_TEXT_4,
2477 "Press any key or button for info menu");
2479 FadeIn(REDRAW_FIELD);
2482 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2484 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2485 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2486 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2487 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2488 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2489 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2490 int ystep = MENU_SCREEN_INFO_YSTEP;
2491 int element, action, direction;
2499 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2500 infoscreen_step[i] = infoscreen_frame[i] = 0;
2505 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2507 DrawTextSCentered(ybottom, FONT_TEXT_4,
2508 "Press any key or button for next page");
2514 while (helpanim_info[j].element != HELPANIM_LIST_END)
2516 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2521 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2530 j += infoscreen_step[i - start];
2532 element = helpanim_info[j].element;
2533 action = helpanim_info[j].action;
2534 direction = helpanim_info[j].direction;
2537 element = EL_UNKNOWN;
2539 if (action != -1 && direction != -1)
2540 graphic = el_act_dir2img(element, action, direction);
2541 else if (action != -1)
2542 graphic = el_act2img(element, action);
2543 else if (direction != -1)
2544 graphic = el_dir2img(element, direction);
2546 graphic = el2img(element);
2548 delay = helpanim_info[j++].delay;
2553 if (infoscreen_frame[i - start] == 0)
2556 infoscreen_frame[i - start] = delay - 1;
2560 sync_frame = delay - infoscreen_frame[i - start];
2561 infoscreen_frame[i - start]--;
2564 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2566 if (!infoscreen_frame[i - start])
2567 infoscreen_step[i - start] = 0;
2571 if (!infoscreen_frame[i - start])
2572 infoscreen_step[i - start]++;
2573 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2579 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2581 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2582 graphic, sync_frame, USE_MASKING);
2585 DrawInfoScreen_HelpText(element, action, direction, i - start);
2590 redraw_mask |= REDRAW_FIELD;
2595 static char *getHelpText(int element, int action, int direction)
2597 char token[MAX_LINE_LEN];
2599 strcpy(token, element_info[element].token_name);
2602 strcat(token, element_action_info[action].suffix);
2604 if (direction != -1)
2605 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2607 return getHashEntry(helptext_info, token);
2610 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2612 int font_nr = FONT_INFO_ELEMENTS;
2613 int font_width = getFontWidth(font_nr);
2614 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2615 int sy = mSY + 65 + 2 * 32 + 1;
2616 int ystep = TILEY + 4;
2617 int pad_x = sx - SX;
2618 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2619 int max_lines_per_text = 2;
2622 if (action != -1 && direction != -1) /* element.action.direction */
2623 text = getHelpText(element, action, direction);
2625 if (text == NULL && action != -1) /* element.action */
2626 text = getHelpText(element, action, -1);
2628 if (text == NULL && direction != -1) /* element.direction */
2629 text = getHelpText(element, -1, direction);
2631 if (text == NULL) /* base element */
2632 text = getHelpText(element, -1, -1);
2634 if (text == NULL) /* not found */
2635 text = "No description available";
2637 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2638 sy += getFontHeight(font_nr) / 2;
2640 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2641 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2642 TRUE, FALSE, FALSE);
2645 void DrawInfoScreen_TitleScreen()
2650 void HandleInfoScreen_TitleScreen(int button)
2652 HandleTitleScreen(0, 0, 0, 0, button);
2655 void DrawInfoScreen_Elements()
2657 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2659 FadeOut(REDRAW_FIELD);
2664 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2666 FadeIn(REDRAW_FIELD);
2671 void HandleInfoScreen_Elements(int button)
2673 static unsigned int info_delay = 0;
2674 static int num_anims;
2675 static int num_pages;
2677 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2680 if (button == MB_MENU_INITIALIZE)
2682 boolean new_element = TRUE;
2686 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2688 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2690 else if (new_element)
2693 new_element = FALSE;
2697 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2701 if (button == MB_MENU_LEAVE)
2703 PlaySound(SND_MENU_ITEM_SELECTING);
2705 info_mode = INFO_MODE_MAIN;
2710 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2712 if (button != MB_MENU_INITIALIZE)
2714 PlaySound(SND_MENU_ITEM_SELECTING);
2719 if (page >= num_pages)
2721 FadeSoundsAndMusic();
2723 info_mode = INFO_MODE_MAIN;
2724 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2730 FadeSetNextScreen();
2732 if (button != MB_MENU_INITIALIZE)
2733 FadeOut(REDRAW_FIELD);
2735 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2737 if (button != MB_MENU_INITIALIZE)
2738 FadeIn(REDRAW_FIELD);
2742 if (DelayReached(&info_delay, GameFrameDelay))
2743 if (page < num_pages)
2744 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2746 PlayMenuSoundIfLoop();
2750 void DrawInfoScreen_Music()
2752 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2754 FadeOut(REDRAW_FIELD);
2761 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2763 FadeIn(REDRAW_FIELD);
2766 void HandleInfoScreen_Music(int button)
2768 static struct MusicFileInfo *list = NULL;
2769 int ystart1 = mSY - SY + 100;
2770 int ystart2 = mSY - SY + 150;
2771 int ybottom = mSY - SY + SYSIZE - 20;
2774 if (button == MB_MENU_INITIALIZE)
2776 list = music_file_info;
2780 FadeSoundsAndMusic();
2785 DrawTextSCentered(ystart1, FONT_TEXT_1,
2786 "No music info for this level set.");
2788 DrawTextSCentered(ybottom, FONT_TEXT_4,
2789 "Press any key or button for info menu");
2795 if (button == MB_MENU_LEAVE)
2797 PlaySound(SND_MENU_ITEM_SELECTING);
2799 FadeSoundsAndMusic();
2801 info_mode = INFO_MODE_MAIN;
2806 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2810 if (button != MB_MENU_INITIALIZE)
2812 PlaySound(SND_MENU_ITEM_SELECTING);
2820 FadeSoundsAndMusic();
2822 info_mode = INFO_MODE_MAIN;
2823 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2828 FadeSoundsAndMusic();
2830 if (list != music_file_info)
2831 FadeSetNextScreen();
2833 if (button != MB_MENU_INITIALIZE)
2834 FadeOut(REDRAW_FIELD);
2841 int sound = list->music;
2843 if (sound_info[sound].loop)
2844 PlaySoundLoop(sound);
2848 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2852 PlayMusic(list->music);
2854 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2857 if (!strEqual(list->title, UNKNOWN_NAME))
2859 if (!strEqual(list->title_header, UNKNOWN_NAME))
2860 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2862 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2865 if (!strEqual(list->artist, UNKNOWN_NAME))
2867 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2868 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2870 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2872 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2875 if (!strEqual(list->album, UNKNOWN_NAME))
2877 if (!strEqual(list->album_header, UNKNOWN_NAME))
2878 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2880 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2882 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2885 if (!strEqual(list->year, UNKNOWN_NAME))
2887 if (!strEqual(list->year_header, UNKNOWN_NAME))
2888 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2890 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2892 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2895 DrawTextSCentered(ybottom, FONT_TEXT_4,
2896 "Press any key or button for next page");
2898 if (button != MB_MENU_INITIALIZE)
2899 FadeIn(REDRAW_FIELD);
2902 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2903 PlaySoundLoop(list->music);
2906 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2908 int ystart1 = mSY - SY + 100;
2909 int ystart2 = mSY - SY + 150;
2910 int ybottom = mSY - SY + SYSIZE - 20;
2916 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2920 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2921 "Special thanks to");
2922 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2924 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2926 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2927 "\"Boulder Dash\"");
2928 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2930 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2932 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2934 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2935 "First Star Software");
2937 else if (screen_nr == 1)
2939 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2940 "Special thanks to");
2941 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2942 "Klaus Heinz & Volker Wertich");
2943 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2945 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2946 "\"Emerald Mine\"");
2947 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2949 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2951 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2953 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2956 else if (screen_nr == 2)
2958 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2959 "Special thanks to");
2960 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2961 "Michael Stopp & Philip Jespersen");
2962 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2964 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
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 "Digital Integration");
2975 else if (screen_nr == 3)
2977 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2978 "Special thanks to");
2979 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2980 "Hiroyuki Imabayashi");
2981 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2983 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
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 == 4)
2996 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2997 "Special thanks to");
2998 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3000 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3002 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3003 "J\xfcrgen Bonhagen");
3004 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3005 "for the continuous creation");
3006 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3007 "of outstanding level sets");
3009 else if (screen_nr == 5)
3011 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3013 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3015 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3016 "for ideas and inspiration by");
3017 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3020 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3022 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3024 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3025 "for ideas and inspiration by");
3026 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3029 else if (screen_nr == 6)
3031 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3033 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3036 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3037 "for the code base used for the");
3038 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3039 "native Emerald Mine engine");
3041 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3042 "for the new Emerald Mine engine");
3045 else if (screen_nr == 7)
3047 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3049 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3051 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3052 "for the initial DOS port");
3054 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3056 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3058 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3059 "for some additional toons");
3061 else if (screen_nr == 8)
3063 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3064 "And not to forget:");
3065 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3067 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3068 "All those who contributed");
3069 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3070 "levels to this game");
3071 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3075 DrawTextSCentered(ybottom, FONT_TEXT_4,
3076 "Press any key or button for next page");
3079 void DrawInfoScreen_Credits()
3081 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3083 FadeSoundsAndMusic();
3085 FadeOut(REDRAW_FIELD);
3087 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3089 FadeIn(REDRAW_FIELD);
3092 void HandleInfoScreen_Credits(int button)
3094 static int screen_nr = 0;
3095 int num_screens = 9;
3097 if (button == MB_MENU_INITIALIZE)
3101 // DrawInfoScreen_CreditsScreen(screen_nr);
3104 if (button == MB_MENU_LEAVE)
3106 PlaySound(SND_MENU_ITEM_SELECTING);
3108 info_mode = INFO_MODE_MAIN;
3113 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3115 if (button != MB_MENU_INITIALIZE)
3117 PlaySound(SND_MENU_ITEM_SELECTING);
3122 if (screen_nr >= num_screens)
3124 FadeSoundsAndMusic();
3126 info_mode = INFO_MODE_MAIN;
3127 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3133 FadeSetNextScreen();
3135 if (button != MB_MENU_INITIALIZE)
3136 FadeOut(REDRAW_FIELD);
3138 DrawInfoScreen_CreditsScreen(screen_nr);
3140 if (button != MB_MENU_INITIALIZE)
3141 FadeIn(REDRAW_FIELD);
3145 PlayMenuSoundIfLoop();
3149 void DrawInfoScreen_Program()
3151 int ystart1 = mSY - SY + 100;
3152 int ystart2 = mSY - SY + 150;
3153 int ybottom = mSY - SY + SYSIZE - 20;
3156 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3158 FadeOut(REDRAW_FIELD);
3163 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3165 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3166 "This game is Freeware!");
3167 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3168 "If you like it, send e-mail to:");
3169 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3170 setup.internal.program_email);
3171 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3172 "More information and levels:");
3173 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3174 setup.internal.program_website);
3175 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3176 "If you have created new levels,");
3177 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3178 "send them to me to include them!");
3179 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3182 DrawTextSCentered(ybottom, FONT_TEXT_4,
3183 "Press any key or button for info menu");
3185 FadeIn(REDRAW_FIELD);
3188 void HandleInfoScreen_Program(int button)
3190 if (button == MB_MENU_LEAVE)
3192 PlaySound(SND_MENU_ITEM_SELECTING);
3194 info_mode = INFO_MODE_MAIN;
3199 else if (button == MB_MENU_CHOICE)
3201 PlaySound(SND_MENU_ITEM_SELECTING);
3203 FadeSoundsAndMusic();
3205 info_mode = INFO_MODE_MAIN;
3206 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3210 PlayMenuSoundIfLoop();
3214 void DrawInfoScreen_Version()
3216 int font_header = FONT_TEXT_3;
3217 int font_text = FONT_TEXT_2;
3218 int xstep = getFontWidth(font_text);
3219 int ystep = getFontHeight(font_text);
3220 int ystart1 = mSY - SY + 100;
3221 int ystart2 = mSY - SY + 150;
3222 int ybottom = mSY - SY + SYSIZE - 20;
3223 int xstart1 = mSX - SX + 2 * xstep;
3224 int xstart2 = mSX - SX + 18 * xstep;
3225 int xstart3 = mSX - SX + 28 * xstep;
3226 SDL_version sdl_version_compiled;
3227 const SDL_version *sdl_version_linked;
3228 int driver_name_len = 10;
3229 #if defined(TARGET_SDL2)
3230 SDL_version sdl_version_linked_ext;
3231 const char *driver_name = NULL;
3233 char driver_name[driver_name_len];
3236 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3238 FadeOut(REDRAW_FIELD);
3243 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3245 DrawTextF(xstart1, ystart2, font_header, "Name");
3246 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3249 DrawTextF(xstart1, ystart2, font_header, "Version");
3250 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3253 DrawTextF(xstart1, ystart2, font_header, "Platform");
3254 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3257 DrawTextF(xstart1, ystart2, font_header, "Target");
3258 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3261 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3262 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3264 ystart2 += 3 * ystep;
3265 DrawTextF(xstart1, ystart2, font_header, "Library");
3266 DrawTextF(xstart2, ystart2, font_header, "compiled");
3267 DrawTextF(xstart3, ystart2, font_header, "linked");
3269 SDL_VERSION(&sdl_version_compiled);
3270 #if defined(TARGET_SDL2)
3271 SDL_GetVersion(&sdl_version_linked_ext);
3272 sdl_version_linked = &sdl_version_linked_ext;
3274 sdl_version_linked = SDL_Linked_Version();
3277 ystart2 += 2 * ystep;
3278 DrawTextF(xstart1, ystart2, font_text, "SDL");
3279 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3280 sdl_version_compiled.major,
3281 sdl_version_compiled.minor,
3282 sdl_version_compiled.patch);
3283 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3284 sdl_version_linked->major,
3285 sdl_version_linked->minor,
3286 sdl_version_linked->patch);
3288 SDL_IMAGE_VERSION(&sdl_version_compiled);
3289 sdl_version_linked = IMG_Linked_Version();
3292 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
3293 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3294 sdl_version_compiled.major,
3295 sdl_version_compiled.minor,
3296 sdl_version_compiled.patch);
3297 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3298 sdl_version_linked->major,
3299 sdl_version_linked->minor,
3300 sdl_version_linked->patch);
3302 SDL_MIXER_VERSION(&sdl_version_compiled);
3303 sdl_version_linked = Mix_Linked_Version();
3306 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3307 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3308 sdl_version_compiled.major,
3309 sdl_version_compiled.minor,
3310 sdl_version_compiled.patch);
3311 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3312 sdl_version_linked->major,
3313 sdl_version_linked->minor,
3314 sdl_version_linked->patch);
3316 SDL_NET_VERSION(&sdl_version_compiled);
3317 sdl_version_linked = SDLNet_Linked_Version();
3320 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3321 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3322 sdl_version_compiled.major,
3323 sdl_version_compiled.minor,
3324 sdl_version_compiled.patch);
3325 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3326 sdl_version_linked->major,
3327 sdl_version_linked->minor,
3328 sdl_version_linked->patch);
3330 ystart2 += 3 * ystep;
3331 DrawTextF(xstart1, ystart2, font_header, "Driver");
3332 DrawTextF(xstart2, ystart2, font_header, "Requested");
3333 DrawTextF(xstart3, ystart2, font_header, "Used");
3335 #if defined(TARGET_SDL2)
3336 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3338 SDL_VideoDriverName(driver_name, driver_name_len);
3341 ystart2 += 2 * ystep;
3342 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3343 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3344 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3346 #if defined(TARGET_SDL2)
3347 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3349 SDL_AudioDriverName(driver_name, driver_name_len);
3353 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3354 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3355 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3357 DrawTextSCentered(ybottom, FONT_TEXT_4,
3358 "Press any key or button for info menu");
3360 FadeIn(REDRAW_FIELD);
3363 void HandleInfoScreen_Version(int button)
3365 if (button == MB_MENU_LEAVE)
3367 PlaySound(SND_MENU_ITEM_SELECTING);
3369 info_mode = INFO_MODE_MAIN;
3374 else if (button == MB_MENU_CHOICE)
3376 PlaySound(SND_MENU_ITEM_SELECTING);
3378 FadeSoundsAndMusic();
3380 info_mode = INFO_MODE_MAIN;
3381 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3385 PlayMenuSoundIfLoop();
3389 void DrawInfoScreen_LevelSet()
3391 struct TitleMessageInfo *tmi = &readme;
3392 char *filename = getLevelSetInfoFilename();
3393 char *title = "Level Set Information:";
3394 int ystart1 = mSY - SY + 100;
3395 int ybottom = mSY - SY + SYSIZE - 20;
3397 if (filename == NULL)
3399 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3404 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3406 FadeOut(REDRAW_FIELD);
3411 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3413 /* if x position set to "-1", automatically determine by playfield width */
3415 tmi->x = SXSIZE / 2;
3417 /* if y position set to "-1", use static default value */
3421 /* if width set to "-1", automatically determine by playfield width */
3422 if (tmi->width == -1)
3423 tmi->width = SXSIZE - 2 * TILEX;
3425 /* if height set to "-1", automatically determine by playfield height */
3426 if (tmi->height == -1)
3427 tmi->height = SYSIZE - 20 - tmi->y - 10;
3429 /* if chars set to "-1", automatically determine by text and font width */
3430 if (tmi->chars == -1)
3431 tmi->chars = tmi->width / getFontWidth(tmi->font);
3433 tmi->width = tmi->chars * getFontWidth(tmi->font);
3435 /* if lines set to "-1", automatically determine by text and font height */
3436 if (tmi->lines == -1)
3437 tmi->lines = tmi->height / getFontHeight(tmi->font);
3439 tmi->height = tmi->lines * getFontHeight(tmi->font);
3441 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3442 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3443 tmi->autowrap, tmi->centered, tmi->parse_comments);
3445 DrawTextSCentered(ybottom, FONT_TEXT_4,
3446 "Press any key or button for info menu");
3448 FadeIn(REDRAW_FIELD);
3451 void HandleInfoScreen_LevelSet(int button)
3453 if (button == MB_MENU_LEAVE)
3455 PlaySound(SND_MENU_ITEM_SELECTING);
3457 info_mode = INFO_MODE_MAIN;
3462 else if (button == MB_MENU_CHOICE)
3464 PlaySound(SND_MENU_ITEM_SELECTING);
3466 FadeSoundsAndMusic();
3468 info_mode = INFO_MODE_MAIN;
3469 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3473 PlayMenuSoundIfLoop();
3477 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3479 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3481 if (info_mode == INFO_MODE_TITLE)
3482 DrawInfoScreen_TitleScreen();
3483 else if (info_mode == INFO_MODE_ELEMENTS)
3484 DrawInfoScreen_Elements();
3485 else if (info_mode == INFO_MODE_MUSIC)
3486 DrawInfoScreen_Music();
3487 else if (info_mode == INFO_MODE_CREDITS)
3488 DrawInfoScreen_Credits();
3489 else if (info_mode == INFO_MODE_PROGRAM)
3490 DrawInfoScreen_Program();
3491 else if (info_mode == INFO_MODE_VERSION)
3492 DrawInfoScreen_Version();
3493 else if (info_mode == INFO_MODE_LEVELSET)
3494 DrawInfoScreen_LevelSet();
3496 DrawInfoScreen_Main(fade_mask, do_fading);
3498 if (info_mode != INFO_MODE_MAIN &&
3499 info_mode != INFO_MODE_TITLE &&
3500 info_mode != INFO_MODE_MUSIC)
3507 void DrawAndFadeInInfoScreen(int fade_mask)
3509 DrawInfoScreenExt(fade_mask, TRUE);
3512 void DrawInfoScreen()
3514 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3517 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3519 if (info_mode == INFO_MODE_TITLE)
3520 HandleInfoScreen_TitleScreen(button);
3521 else if (info_mode == INFO_MODE_ELEMENTS)
3522 HandleInfoScreen_Elements(button);
3523 else if (info_mode == INFO_MODE_MUSIC)
3524 HandleInfoScreen_Music(button);
3525 else if (info_mode == INFO_MODE_CREDITS)
3526 HandleInfoScreen_Credits(button);
3527 else if (info_mode == INFO_MODE_PROGRAM)
3528 HandleInfoScreen_Program(button);
3529 else if (info_mode == INFO_MODE_VERSION)
3530 HandleInfoScreen_Version(button);
3531 else if (info_mode == INFO_MODE_LEVELSET)
3532 HandleInfoScreen_LevelSet(button);
3534 HandleInfoScreen_Main(mx, my, dx, dy, button);
3538 /* ========================================================================= */
3539 /* type name functions */
3540 /* ========================================================================= */
3542 void HandleTypeName(int newxpos, Key key)
3544 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3545 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3546 struct TextPosInfo *pos = mci->pos_input;
3547 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3548 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3549 static int xpos = 0;
3550 int font_nr = pos->font;
3551 int font_active_nr = FONT_ACTIVE(font_nr);
3552 int font_width = getFontWidth(font_active_nr);
3553 char key_char = getValidConfigValueChar(getCharFromKey(key));
3554 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3555 boolean is_active = TRUE;
3557 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3561 strcpy(last_player_name, setup.player_name);
3565 #if defined(TARGET_SDL2)
3566 SDL_StartTextInput();
3569 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3571 setup.player_name[xpos] = key_char;
3572 setup.player_name[xpos + 1] = 0;
3576 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3580 setup.player_name[xpos] = 0;
3582 else if (key == KSYM_Return && xpos > 0)
3588 game_status = GAME_MODE_MAIN;
3590 else if (key == KSYM_Escape)
3592 strcpy(setup.player_name, last_player_name);
3596 game_status = GAME_MODE_MAIN;
3601 pos->width = (strlen(setup.player_name) + 1) * font_width;
3602 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3604 DrawText(startx, starty, setup.player_name, font_active_nr);
3605 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3609 pos->width = strlen(setup.player_name) * font_width;
3610 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3612 DrawText(startx, starty, setup.player_name, font_nr);
3614 #if defined(TARGET_SDL2)
3615 SDL_StopTextInput();
3621 /* ========================================================================= */
3622 /* tree menu functions */
3623 /* ========================================================================= */
3625 static void DrawChooseTree(TreeInfo **ti_ptr)
3627 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3629 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3631 game_status = GAME_MODE_MAIN;
3633 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3640 FreeScreenGadgets();
3641 CreateScreenGadgets();
3643 CloseDoor(DOOR_CLOSE_2);
3649 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3650 MapScreenTreeGadgets(*ti_ptr);
3657 static void drawChooseTreeList(int first_entry, int num_page_entries,
3661 char *title_string = NULL;
3662 int yoffset_sets = MENU_TITLE1_YPOS;
3663 int yoffset_setup = 16;
3664 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3665 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3666 int last_game_status = game_status; /* save current game status */
3668 title_string = ti->infotext;
3670 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3672 clearMenuListArea();
3674 for (i = 0; i < num_page_entries; i++)
3676 TreeInfo *node, *node_first;
3677 int entry_pos = first_entry + i;
3678 int xpos = MENU_SCREEN_START_XPOS;
3679 int ypos = MENU_SCREEN_START_YPOS + i;
3680 int startx = mSX + xpos * 32;
3681 int starty = mSY + ypos * 32;
3682 int font_nr = FONT_TEXT_1;
3683 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3684 int startx_text = startx + font_xoffset;
3685 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3686 int text_size = startx_scrollbar - startx_text;
3687 int max_buffer_len = text_size / getFontWidth(font_nr);
3688 char buffer[max_buffer_len + 1];
3690 node_first = getTreeInfoFirstGroupEntry(ti);
3691 node = getTreeInfoFromPos(node_first, entry_pos);
3693 strncpy(buffer, node->name, max_buffer_len);
3694 buffer[max_buffer_len] = '\0';
3696 DrawText(startx, starty, buffer, font_nr + node->color);
3698 if (node->parent_link)
3699 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3700 else if (node->level_group)
3701 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3703 initCursor(i, IMG_MENU_BUTTON);
3706 game_status = last_game_status; /* restore current game status */
3708 redraw_mask |= REDRAW_FIELD;
3711 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3713 TreeInfo *node, *node_first;
3714 int x, last_redraw_mask = redraw_mask;
3715 int ypos = MENU_TITLE2_YPOS;
3716 int font_nr = FONT_TITLE_2;
3718 if (ti->type == TREE_TYPE_LEVEL_NR)
3719 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3721 if (ti->type != TREE_TYPE_LEVEL_DIR)
3724 node_first = getTreeInfoFirstGroupEntry(ti);
3725 node = getTreeInfoFromPos(node_first, entry_pos);
3727 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3729 if (node->parent_link)
3730 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3731 node->node_parent->name);
3732 else if (node->level_group)
3733 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3735 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3736 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3737 node->levels, (node->levels > 1 ? "levels" : "level"),
3740 /* let BackToFront() redraw only what is needed */
3741 redraw_mask = last_redraw_mask;
3742 for (x = 0; x < SCR_FIELDX; x++)
3743 MarkTileDirty(x, 1);
3746 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3749 TreeInfo *ti = *ti_ptr;
3751 int y = ti->cl_cursor;
3752 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3753 int num_entries = numTreeInfoInGroup(ti);
3754 int num_page_entries;
3755 int last_game_status = game_status; /* save current game status */
3756 boolean position_set_by_scrollbar = (dx == 999);
3758 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3759 num_page_entries = num_entries;
3761 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3763 game_status = last_game_status; /* restore current game status */
3765 if (button == MB_MENU_INITIALIZE)
3767 int num_entries = numTreeInfoInGroup(ti);
3768 int entry_pos = posTreeInfo(ti);
3770 if (ti->cl_first == -1)
3772 /* only on initialization */
3773 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3774 ti->cl_cursor = entry_pos - ti->cl_first;
3776 else if (ti->cl_cursor >= num_page_entries ||
3777 (num_entries > num_page_entries &&
3778 num_entries - ti->cl_first < num_page_entries))
3780 /* only after change of list size (by custom graphic configuration) */
3781 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3782 ti->cl_cursor = entry_pos - ti->cl_first;
3785 if (position_set_by_scrollbar)
3788 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3791 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3792 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3793 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3797 else if (button == MB_MENU_LEAVE)
3801 PlaySound(SND_MENU_ITEM_SELECTING);
3803 if (ti->node_parent)
3805 *ti_ptr = ti->node_parent;
3806 DrawChooseTree(ti_ptr);
3808 else if (game_status == GAME_MODE_SETUP)
3810 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3811 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3812 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3814 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3815 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3816 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3817 execSetupGraphics();
3818 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3819 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3820 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3822 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3823 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3824 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3831 if (game_status == GAME_MODE_LEVELNR)
3833 int new_level_nr = atoi(level_number_current->identifier);
3835 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3838 game_status = GAME_MODE_MAIN;
3840 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3846 if (mx || my) /* mouse input */
3848 int last_game_status = game_status; /* save current game status */
3850 x = (mx - mSX) / 32;
3851 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3853 game_status = last_game_status; /* restore current game status */
3855 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3857 /* move cursor instead of scrolling when already at start/end of list */
3858 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3860 else if (dy == +1 * SCROLL_LINE &&
3861 ti->cl_first + num_page_entries == num_entries)
3864 /* handle scrolling screen one line or page */
3865 if (ti->cl_cursor + dy < 0 ||
3866 ti->cl_cursor + dy > num_page_entries - 1)
3868 boolean redraw = FALSE;
3870 if (ABS(dy) == SCROLL_PAGE)
3871 step = num_page_entries - 1;
3873 if (dy < 0 && ti->cl_first > 0)
3875 /* scroll page/line up */
3877 ti->cl_first -= step;
3878 if (ti->cl_first < 0)
3883 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3885 /* scroll page/line down */
3887 ti->cl_first += step;
3888 if (ti->cl_first + num_page_entries > num_entries)
3889 ti->cl_first = MAX(0, num_entries - num_page_entries);
3896 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3897 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3898 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3900 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3907 /* handle moving cursor one line */
3908 y = ti->cl_cursor + dy;
3913 TreeInfo *node_first, *node_cursor;
3914 int entry_pos = ti->cl_first + y;
3916 node_first = getTreeInfoFirstGroupEntry(ti);
3917 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3919 if (node_cursor->node_group)
3923 PlaySound(SND_MENU_ITEM_SELECTING);
3925 node_cursor->cl_first = ti->cl_first;
3926 node_cursor->cl_cursor = ti->cl_cursor;
3927 *ti_ptr = node_cursor->node_group;
3928 DrawChooseTree(ti_ptr);
3933 else if (dx == -1 && ti->node_parent)
3937 PlaySound(SND_MENU_ITEM_SELECTING);
3939 *ti_ptr = ti->node_parent;
3940 DrawChooseTree(ti_ptr);
3945 if (!anyScrollbarGadgetActive() &&
3946 IN_VIS_MENU(x, y) &&
3947 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3948 y >= 0 && y < num_page_entries)
3952 if (y != ti->cl_cursor)
3954 PlaySound(SND_MENU_ITEM_ACTIVATING);
3956 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3957 drawChooseTreeCursor(y, TRUE);
3958 drawChooseTreeInfo(ti->cl_first + y, ti);
3965 TreeInfo *node_first, *node_cursor;
3966 int entry_pos = ti->cl_first + y;
3968 PlaySound(SND_MENU_ITEM_SELECTING);
3970 node_first = getTreeInfoFirstGroupEntry(ti);
3971 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3973 if (node_cursor->node_group)
3977 node_cursor->cl_first = ti->cl_first;
3978 node_cursor->cl_cursor = ti->cl_cursor;
3979 *ti_ptr = node_cursor->node_group;
3980 DrawChooseTree(ti_ptr);
3982 else if (node_cursor->parent_link)
3986 *ti_ptr = node_cursor->node_parent;
3987 DrawChooseTree(ti_ptr);
3993 node_cursor->cl_first = ti->cl_first;
3994 node_cursor->cl_cursor = ti->cl_cursor;
3995 *ti_ptr = node_cursor;
3997 if (ti->type == TREE_TYPE_LEVEL_DIR)
3999 LoadLevelSetup_SeriesInfo();
4001 SaveLevelSetup_LastSeries();
4002 SaveLevelSetup_SeriesInfo();
4006 if (game_status == GAME_MODE_SETUP)
4008 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4009 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4010 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4012 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4013 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4014 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4015 execSetupGraphics();
4016 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4017 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4018 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4020 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4021 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4022 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4029 if (game_status == GAME_MODE_LEVELNR)
4031 int new_level_nr = atoi(level_number_current->identifier);
4033 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4036 game_status = GAME_MODE_MAIN;
4045 void DrawChooseLevelSet()
4047 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4049 DrawChooseTree(&leveldir_current);
4055 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4057 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4060 void DrawChooseLevelNr()
4064 if (level_number != NULL)
4066 freeTreeInfo(level_number);
4068 level_number = NULL;
4071 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4073 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4074 char identifier[32], name[32];
4077 /* temporarily load level info to get level name */
4078 LoadLevelInfoOnly(i);
4080 ti->node_top = &level_number;
4081 ti->sort_priority = 10000 + value;
4082 ti->color = (level.no_valid_file ? FC_BLUE :
4083 LevelStats_getSolved(i) ? FC_GREEN :
4084 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4086 sprintf(identifier, "%d", value);
4087 sprintf(name, "%03d: %s", value,
4088 (level.no_valid_file ? "(no file)" : level.name));
4090 setString(&ti->identifier, identifier);
4091 setString(&ti->name, name);
4092 setString(&ti->name_sorting, name);
4094 pushTreeInfo(&level_number, ti);
4097 /* sort level number values to start with lowest level number */
4098 sortTreeInfo(&level_number);
4100 /* set current level number to current level number */
4101 level_number_current =
4102 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4104 /* if that also fails, set current level number to first available level */
4105 if (level_number_current == NULL)
4106 level_number_current = level_number;
4108 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4110 DrawChooseTree(&level_number_current);
4116 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4118 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4121 void DrawHallOfFame(int highlight_position)
4123 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
4126 FadeSoundsAndMusic();
4128 /* (this is needed when called from GameEnd() after winning a game) */
4129 KeyboardAutoRepeatOn();
4132 /* (this is needed when called from GameEnd() after winning a game) */
4133 SetDrawDeactivationMask(REDRAW_NONE);
4134 SetDrawBackgroundMask(REDRAW_FIELD);
4136 CloseDoor(DOOR_CLOSE_ALL);
4138 if (highlight_position < 0)
4139 LoadScore(level_nr);
4141 FadeSetEnterScreen();
4150 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4155 static void drawHallOfFameList(int first_entry, int highlight_position)
4159 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4162 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4163 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4164 "HighScores of Level %d", level_nr);
4166 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4168 int entry = first_entry + i;
4169 boolean active = (entry == highlight_position);
4170 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4171 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4172 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4173 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4174 int dx1 = 3 * getFontWidth(font_nr1);
4175 int dx2 = dx1 + getFontWidth(font_nr1);
4176 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4177 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4178 int sy = mSY + 64 + i * 32;
4180 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4181 DrawText(mSX + dx1, sy, ".", font_nr1);
4183 for (j = 0; j < num_dots; j++)
4184 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4186 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4187 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4189 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4192 redraw_mask |= REDRAW_FIELD;
4195 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4197 static int first_entry = 0;
4198 static int highlight_position = 0;
4199 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4201 if (button == MB_MENU_INITIALIZE)
4204 highlight_position = mx;
4205 drawHallOfFameList(first_entry, highlight_position);
4210 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4211 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4215 if (first_entry > 0)
4217 first_entry -= step;
4218 if (first_entry < 0)
4221 drawHallOfFameList(first_entry, highlight_position);
4226 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4228 first_entry += step;
4229 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4230 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4232 drawHallOfFameList(first_entry, highlight_position);
4235 else if (button == MB_MENU_LEAVE)
4237 PlaySound(SND_MENU_ITEM_SELECTING);
4239 FadeSound(SND_BACKGROUND_SCORES);
4241 game_status = GAME_MODE_MAIN;
4245 else if (button == MB_MENU_CHOICE)
4247 PlaySound(SND_MENU_ITEM_SELECTING);
4249 FadeSound(SND_BACKGROUND_SCORES);
4251 game_status = GAME_MODE_MAIN;
4253 DrawAndFadeInMainMenu(REDRAW_FIELD);
4256 if (game_status == GAME_MODE_SCORES)
4257 PlayMenuSoundIfLoop();
4261 /* ========================================================================= */
4262 /* setup screen functions */
4263 /* ========================================================================= */
4265 static struct TokenInfo *setup_info;
4266 static int num_setup_info; /* number of setup entries shown on screen */
4267 static int max_setup_info; /* total number of setup entries in list */
4269 static char *screen_mode_text;
4270 static char *window_size_text;
4271 static char *scaling_type_text;
4272 static char *scroll_delay_text;
4273 static char *snapshot_mode_text;
4274 static char *game_speed_text;
4275 static char *graphics_set_name;
4276 static char *sounds_set_name;
4277 static char *music_set_name;
4278 static char *volume_simple_text;
4279 static char *volume_loops_text;
4280 static char *volume_music_text;
4281 static char *touch_controls_text;
4282 static char *move_distance_text;
4283 static char *drop_distance_text;
4285 static void execSetupMain()
4287 setup_mode = SETUP_MODE_MAIN;
4292 static void execSetupGame_setGameSpeeds()
4294 if (game_speeds == NULL)
4298 for (i = 0; game_speeds_list[i].value != -1; i++)
4300 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4301 char identifier[32], name[32];
4302 int value = game_speeds_list[i].value;
4303 char *text = game_speeds_list[i].text;
4305 ti->node_top = &game_speeds;
4306 ti->sort_priority = 10000 - value;
4308 sprintf(identifier, "%d", value);
4309 sprintf(name, "%s", text);
4311 setString(&ti->identifier, identifier);
4312 setString(&ti->name, name);
4313 setString(&ti->name_sorting, name);
4314 setString(&ti->infotext, "Game Speed");
4316 pushTreeInfo(&game_speeds, ti);
4319 /* sort game speed values to start with slowest game speed */
4320 sortTreeInfo(&game_speeds);
4322 /* set current game speed to configured game speed value */
4323 game_speed_current =
4324 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4326 /* if that fails, set current game speed to reliable default value */
4327 if (game_speed_current == NULL)
4328 game_speed_current =
4329 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4331 /* if that also fails, set current game speed to first available speed */
4332 if (game_speed_current == NULL)
4333 game_speed_current = game_speeds;
4336 setup.game_frame_delay = atoi(game_speed_current->identifier);
4338 /* needed for displaying game speed text instead of identifier */
4339 game_speed_text = game_speed_current->name;
4342 static void execSetupGame_setScrollDelays()
4344 if (scroll_delays == NULL)
4348 for (i = 0; scroll_delays_list[i].value != -1; i++)
4350 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4351 char identifier[32], name[32];
4352 int value = scroll_delays_list[i].value;
4353 char *text = scroll_delays_list[i].text;
4355 ti->node_top = &scroll_delays;
4356 ti->sort_priority = value;
4358 sprintf(identifier, "%d", value);
4359 sprintf(name, "%s", text);
4361 setString(&ti->identifier, identifier);
4362 setString(&ti->name, name);
4363 setString(&ti->name_sorting, name);
4364 setString(&ti->infotext, "Scaling Type");
4366 pushTreeInfo(&scroll_delays, ti);
4369 /* sort scaling type values to start with lowest scaling type value */
4370 sortTreeInfo(&scroll_delays);
4372 /* set current scaling type value to configured scaling type value */
4373 scroll_delay_current =
4374 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4376 /* if that fails, set current scaling type to reliable default value */
4377 if (scroll_delay_current == NULL)
4378 scroll_delay_current =
4379 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4381 /* if that also fails, set current scaling type to first available value */
4382 if (scroll_delay_current == NULL)
4383 scroll_delay_current = scroll_delays;
4386 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4388 /* needed for displaying scaling type text instead of identifier */
4389 scroll_delay_text = scroll_delay_current->name;
4392 static void execSetupGame_setSnapshotModes()
4394 if (snapshot_modes == NULL)
4398 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4400 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4401 char identifier[32], name[32];
4402 char *value = snapshot_modes_list[i].value;
4403 char *text = snapshot_modes_list[i].text;
4405 ti->node_top = &snapshot_modes;
4406 ti->sort_priority = i;
4408 sprintf(identifier, "%s", value);
4409 sprintf(name, "%s", text);
4411 setString(&ti->identifier, identifier);
4412 setString(&ti->name, name);
4413 setString(&ti->name_sorting, name);
4414 setString(&ti->infotext, "Snapshot Mode");
4416 pushTreeInfo(&snapshot_modes, ti);
4419 /* sort snapshot mode values to start with lowest snapshot mode value */
4420 sortTreeInfo(&snapshot_modes);
4422 /* set current snapshot mode value to configured snapshot mode value */
4423 snapshot_mode_current =
4424 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4426 /* if that fails, set current snapshot mode to reliable default value */
4427 if (snapshot_mode_current == NULL)
4428 snapshot_mode_current =
4429 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4431 /* if that also fails, set current snapshot mode to first available value */
4432 if (snapshot_mode_current == NULL)
4433 snapshot_mode_current = snapshot_modes;
4436 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4438 /* needed for displaying snapshot mode text instead of identifier */
4439 snapshot_mode_text = snapshot_mode_current->name;
4442 static void execSetupGame()
4444 execSetupGame_setGameSpeeds();
4445 execSetupGame_setScrollDelays();
4446 execSetupGame_setSnapshotModes();
4448 setup_mode = SETUP_MODE_GAME;
4453 static void execSetupChooseGameSpeed()
4455 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4460 static void execSetupChooseScrollDelay()
4462 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4467 static void execSetupChooseSnapshotMode()
4469 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4474 static void execSetupEditor()
4476 setup_mode = SETUP_MODE_EDITOR;
4481 static void execSetupGraphics_setWindowSizes(boolean update_list)
4483 if (window_sizes != NULL && update_list)
4485 freeTreeInfo(window_sizes);
4487 window_sizes = NULL;
4490 if (window_sizes == NULL)
4492 boolean current_window_size_found = FALSE;
4495 for (i = 0; window_sizes_list[i].value != -1; i++)
4497 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4498 char identifier[32], name[32];
4499 int value = window_sizes_list[i].value;
4500 char *text = window_sizes_list[i].text;
4502 ti->node_top = &window_sizes;
4503 ti->sort_priority = value;
4505 sprintf(identifier, "%d", value);
4506 sprintf(name, "%s", text);
4508 setString(&ti->identifier, identifier);
4509 setString(&ti->name, name);
4510 setString(&ti->name_sorting, name);
4511 setString(&ti->infotext, "Window Scaling");
4513 pushTreeInfo(&window_sizes, ti);
4515 if (value == setup.window_scaling_percent)
4516 current_window_size_found = TRUE;
4519 if (!current_window_size_found)
4521 // add entry for non-preset window scaling value
4523 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4524 char identifier[32], name[32];
4525 int value = setup.window_scaling_percent;
4527 ti->node_top = &window_sizes;
4528 ti->sort_priority = value;
4530 sprintf(identifier, "%d", value);
4531 sprintf(name, "%d %% (Current)", value);
4533 setString(&ti->identifier, identifier);
4534 setString(&ti->name, name);
4535 setString(&ti->name_sorting, name);
4536 setString(&ti->infotext, "Window Scaling");
4538 pushTreeInfo(&window_sizes, ti);
4541 /* sort window size values to start with lowest window size value */
4542 sortTreeInfo(&window_sizes);
4544 /* set current window size value to configured window size value */
4545 window_size_current =
4546 getTreeInfoFromIdentifier(window_sizes,
4547 i_to_a(setup.window_scaling_percent));
4549 /* if that fails, set current window size to reliable default value */
4550 if (window_size_current == NULL)
4551 window_size_current =
4552 getTreeInfoFromIdentifier(window_sizes,
4553 i_to_a(STD_WINDOW_SCALING_PERCENT));
4555 /* if that also fails, set current window size to first available value */
4556 if (window_size_current == NULL)
4557 window_size_current = window_sizes;
4560 setup.window_scaling_percent = atoi(window_size_current->identifier);
4562 /* needed for displaying window size text instead of identifier */
4563 window_size_text = window_size_current->name;
4566 static void execSetupGraphics_setScalingTypes()
4568 if (scaling_types == NULL)
4572 for (i = 0; scaling_types_list[i].value != NULL; i++)
4574 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4575 char identifier[32], name[32];
4576 char *value = scaling_types_list[i].value;
4577 char *text = scaling_types_list[i].text;
4579 ti->node_top = &scaling_types;
4580 ti->sort_priority = i;
4582 sprintf(identifier, "%s", value);
4583 sprintf(name, "%s", text);
4585 setString(&ti->identifier, identifier);
4586 setString(&ti->name, name);
4587 setString(&ti->name_sorting, name);
4588 setString(&ti->infotext, "Anti-Aliasing");
4590 pushTreeInfo(&scaling_types, ti);
4593 /* sort scaling type values to start with lowest scaling type value */
4594 sortTreeInfo(&scaling_types);
4596 /* set current scaling type value to configured scaling type value */
4597 scaling_type_current =
4598 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4600 /* if that fails, set current scaling type to reliable default value */
4601 if (scaling_type_current == NULL)
4602 scaling_type_current =
4603 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4605 /* if that also fails, set current scaling type to first available value */
4606 if (scaling_type_current == NULL)
4607 scaling_type_current = scaling_types;
4610 setup.window_scaling_quality = scaling_type_current->identifier;
4612 /* needed for displaying scaling type text instead of identifier */
4613 scaling_type_text = scaling_type_current->name;
4616 static void execSetupGraphics_setScreenModes()
4618 // if (screen_modes == NULL && video.fullscreen_available)
4619 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4623 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4625 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4626 char identifier[32], name[32];
4627 int x = video.fullscreen_modes[i].width;
4628 int y = video.fullscreen_modes[i].height;
4631 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4633 ti->node_top = &screen_modes;
4634 ti->sort_priority = x * 10000 + y;
4636 sprintf(identifier, "%dx%d", x, y);
4637 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4639 setString(&ti->identifier, identifier);
4640 setString(&ti->name, name);
4641 setString(&ti->name_sorting, name);
4642 setString(&ti->infotext, "Fullscreen Mode");
4644 pushTreeInfo(&screen_modes, ti);
4647 /* sort fullscreen modes to start with lowest available screen resolution */
4648 sortTreeInfo(&screen_modes);
4650 /* set current screen mode for fullscreen mode to configured setup value */
4651 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4652 setup.fullscreen_mode);
4654 /* if that fails, set current screen mode to reliable default value */
4655 if (screen_mode_current == NULL)
4656 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4657 DEFAULT_FULLSCREEN_MODE);
4659 /* if that also fails, set current screen mode to first available mode */
4660 if (screen_mode_current == NULL)
4661 screen_mode_current = screen_modes;
4663 if (screen_mode_current == NULL)
4664 video.fullscreen_available = FALSE;
4667 // if (video.fullscreen_available)
4668 if (screen_mode_current != NULL)
4670 setup.fullscreen_mode = screen_mode_current->identifier;
4672 /* needed for displaying screen mode name instead of identifier */
4673 screen_mode_text = screen_mode_current->name;
4677 static void execSetupGraphics()
4679 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4681 // update "setup.window_scaling_percent" from list selection
4682 execSetupGraphics_setWindowSizes(FALSE);
4686 // update list selection from "setup.window_scaling_percent"
4687 execSetupGraphics_setWindowSizes(TRUE);
4690 execSetupGraphics_setScalingTypes();
4691 execSetupGraphics_setScreenModes();
4693 setup_mode = SETUP_MODE_GRAPHICS;
4697 #if defined(TARGET_SDL2)
4698 // window scaling may have changed at this point
4699 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4701 // window scaling quality may have changed at this point
4702 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4703 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4707 #if !defined(PLATFORM_ANDROID)
4708 #if defined(TARGET_SDL2)
4709 static void execSetupChooseWindowSize()
4711 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4716 static void execSetupChooseScalingType()
4718 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4723 static void execSetupChooseScreenMode()
4725 if (!video.fullscreen_available)
4728 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4735 static void execSetupChooseVolumeSimple()
4737 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4742 static void execSetupChooseVolumeLoops()
4744 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4749 static void execSetupChooseVolumeMusic()
4751 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4756 static void execSetupSound()
4758 if (volumes_simple == NULL)
4760 boolean current_volume_simple_found = FALSE;
4763 for (i = 0; volumes_list[i].value != -1; i++)
4765 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4766 char identifier[32], name[32];
4767 int value = volumes_list[i].value;
4768 char *text = volumes_list[i].text;
4770 ti->node_top = &volumes_simple;
4771 ti->sort_priority = value;
4773 sprintf(identifier, "%d", value);
4774 sprintf(name, "%s", text);
4776 setString(&ti->identifier, identifier);
4777 setString(&ti->name, name);
4778 setString(&ti->name_sorting, name);
4779 setString(&ti->infotext, "Sound Volume");
4781 pushTreeInfo(&volumes_simple, ti);
4783 if (value == setup.volume_simple)
4784 current_volume_simple_found = TRUE;
4787 if (!current_volume_simple_found)
4789 // add entry for non-preset volume value
4791 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4792 char identifier[32], name[32];
4793 int value = setup.volume_simple;
4795 ti->node_top = &volumes_simple;
4796 ti->sort_priority = value;
4798 sprintf(identifier, "%d", value);
4799 sprintf(name, "%d %% (Current)", value);
4801 setString(&ti->identifier, identifier);
4802 setString(&ti->name, name);
4803 setString(&ti->name_sorting, name);
4804 setString(&ti->infotext, "Sound Volume");
4806 pushTreeInfo(&volumes_simple, ti);
4809 /* sort volume values to start with lowest volume value */
4810 sortTreeInfo(&volumes_simple);
4812 /* set current volume value to configured volume value */
4813 volume_simple_current =
4814 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4816 /* if that fails, set current volume to reliable default value */
4817 if (volume_simple_current == NULL)
4818 volume_simple_current =
4819 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4821 /* if that also fails, set current volume to first available value */
4822 if (volume_simple_current == NULL)
4823 volume_simple_current = volumes_simple;
4826 if (volumes_loops == NULL)
4828 boolean current_volume_loops_found = FALSE;
4831 for (i = 0; volumes_list[i].value != -1; i++)
4833 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4834 char identifier[32], name[32];
4835 int value = volumes_list[i].value;
4836 char *text = volumes_list[i].text;
4838 ti->node_top = &volumes_loops;
4839 ti->sort_priority = value;
4841 sprintf(identifier, "%d", value);
4842 sprintf(name, "%s", text);
4844 setString(&ti->identifier, identifier);
4845 setString(&ti->name, name);
4846 setString(&ti->name_sorting, name);
4847 setString(&ti->infotext, "Loops Volume");
4849 pushTreeInfo(&volumes_loops, ti);
4851 if (value == setup.volume_loops)
4852 current_volume_loops_found = TRUE;
4855 if (!current_volume_loops_found)
4857 // add entry for non-preset volume value
4859 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4860 char identifier[32], name[32];
4861 int value = setup.volume_loops;
4863 ti->node_top = &volumes_loops;
4864 ti->sort_priority = value;
4866 sprintf(identifier, "%d", value);
4867 sprintf(name, "%d %% (Current)", value);
4869 setString(&ti->identifier, identifier);
4870 setString(&ti->name, name);
4871 setString(&ti->name_sorting, name);
4872 setString(&ti->infotext, "Loops Volume");
4874 pushTreeInfo(&volumes_loops, ti);
4877 /* sort volume values to start with lowest volume value */
4878 sortTreeInfo(&volumes_loops);
4880 /* set current volume value to configured volume value */
4881 volume_loops_current =
4882 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4884 /* if that fails, set current volume to reliable default value */
4885 if (volume_loops_current == NULL)
4886 volume_loops_current =
4887 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4889 /* if that also fails, set current volume to first available value */
4890 if (volume_loops_current == NULL)
4891 volume_loops_current = volumes_loops;
4894 if (volumes_music == NULL)
4896 boolean current_volume_music_found = FALSE;
4899 for (i = 0; volumes_list[i].value != -1; i++)
4901 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4902 char identifier[32], name[32];
4903 int value = volumes_list[i].value;
4904 char *text = volumes_list[i].text;
4906 ti->node_top = &volumes_music;
4907 ti->sort_priority = value;
4909 sprintf(identifier, "%d", value);
4910 sprintf(name, "%s", text);
4912 setString(&ti->identifier, identifier);
4913 setString(&ti->name, name);
4914 setString(&ti->name_sorting, name);
4915 setString(&ti->infotext, "Music Volume");
4917 pushTreeInfo(&volumes_music, ti);
4919 if (value == setup.volume_music)
4920 current_volume_music_found = TRUE;
4923 if (!current_volume_music_found)
4925 // add entry for non-preset volume value
4927 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4928 char identifier[32], name[32];
4929 int value = setup.volume_music;
4931 ti->node_top = &volumes_music;
4932 ti->sort_priority = value;
4934 sprintf(identifier, "%d", value);
4935 sprintf(name, "%d %% (Current)", value);
4937 setString(&ti->identifier, identifier);
4938 setString(&ti->name, name);
4939 setString(&ti->name_sorting, name);
4940 setString(&ti->infotext, "Music Volume");
4942 pushTreeInfo(&volumes_music, ti);
4945 /* sort volume values to start with lowest volume value */
4946 sortTreeInfo(&volumes_music);
4948 /* set current volume value to configured volume value */
4949 volume_music_current =
4950 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4952 /* if that fails, set current volume to reliable default value */
4953 if (volume_music_current == NULL)
4954 volume_music_current =
4955 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4957 /* if that also fails, set current volume to first available value */
4958 if (volume_music_current == NULL)
4959 volume_music_current = volumes_music;
4962 setup.volume_simple = atoi(volume_simple_current->identifier);
4963 setup.volume_loops = atoi(volume_loops_current->identifier);
4964 setup.volume_music = atoi(volume_music_current->identifier);
4966 /* needed for displaying volume text instead of identifier */
4967 volume_simple_text = volume_simple_current->name;
4968 volume_loops_text = volume_loops_current->name;
4969 volume_music_text = volume_music_current->name;
4971 setup_mode = SETUP_MODE_SOUND;
4976 static void execSetupChooseTouchControls()
4978 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4983 static void execSetupChooseMoveDistance()
4985 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4990 static void execSetupChooseDropDistance()
4992 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4997 static void execSetupTouch()
4999 if (touch_controls == NULL)
5003 for (i = 0; touch_controls_list[i].value != NULL; i++)
5005 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5006 char identifier[32], name[32];
5007 char *value = touch_controls_list[i].value;
5008 char *text = touch_controls_list[i].text;
5010 ti->node_top = &touch_controls;
5011 ti->sort_priority = i;
5013 sprintf(identifier, "%s", value);
5014 sprintf(name, "%s", text);
5016 setString(&ti->identifier, identifier);
5017 setString(&ti->name, name);
5018 setString(&ti->name_sorting, name);
5019 setString(&ti->infotext, "Control Type");
5021 pushTreeInfo(&touch_controls, ti);
5024 /* sort touch control values to start with lowest touch control value */
5025 sortTreeInfo(&touch_controls);
5027 /* set current touch control value to configured touch control value */
5028 touch_control_current =
5029 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5031 /* if that fails, set current touch control to reliable default value */
5032 if (touch_control_current == NULL)
5033 touch_control_current =
5034 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5036 /* if that also fails, set current touch control to first available value */
5037 if (touch_control_current == NULL)
5038 touch_control_current = touch_controls;
5041 if (move_distances == NULL)
5045 for (i = 0; distances_list[i].value != -1; i++)
5047 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5048 char identifier[32], name[32];
5049 int value = distances_list[i].value;
5050 char *text = distances_list[i].text;
5052 ti->node_top = &move_distances;
5053 ti->sort_priority = value;
5055 sprintf(identifier, "%d", value);
5056 sprintf(name, "%s", text);
5058 setString(&ti->identifier, identifier);
5059 setString(&ti->name, name);
5060 setString(&ti->name_sorting, name);
5061 setString(&ti->infotext, "Move Distance");
5063 pushTreeInfo(&move_distances, ti);
5066 /* sort distance values to start with lowest distance value */
5067 sortTreeInfo(&move_distances);
5069 /* set current distance value to configured distance value */
5070 move_distance_current =
5071 getTreeInfoFromIdentifier(move_distances,
5072 i_to_a(setup.touch.move_distance));
5074 /* if that fails, set current distance to reliable default value */
5075 if (move_distance_current == NULL)
5076 move_distance_current =
5077 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5079 /* if that also fails, set current distance to first available value */
5080 if (move_distance_current == NULL)
5081 move_distance_current = move_distances;
5084 if (drop_distances == NULL)
5088 for (i = 0; distances_list[i].value != -1; i++)
5090 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5091 char identifier[32], name[32];
5092 int value = distances_list[i].value;
5093 char *text = distances_list[i].text;
5095 ti->node_top = &drop_distances;
5096 ti->sort_priority = value;
5098 sprintf(identifier, "%d", value);
5099 sprintf(name, "%s", text);
5101 setString(&ti->identifier, identifier);
5102 setString(&ti->name, name);
5103 setString(&ti->name_sorting, name);
5104 setString(&ti->infotext, "Drop Distance");
5106 pushTreeInfo(&drop_distances, ti);
5109 /* sort distance values to start with lowest distance value */
5110 sortTreeInfo(&drop_distances);
5112 /* set current distance value to configured distance value */
5113 drop_distance_current =
5114 getTreeInfoFromIdentifier(drop_distances,
5115 i_to_a(setup.touch.drop_distance));
5117 /* if that fails, set current distance to reliable default value */
5118 if (drop_distance_current == NULL)
5119 drop_distance_current =
5120 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5122 /* if that also fails, set current distance to first available value */
5123 if (drop_distance_current == NULL)
5124 drop_distance_current = drop_distances;
5127 setup.touch.control_type = touch_control_current->identifier;
5128 setup.touch.move_distance = atoi(move_distance_current->identifier);
5129 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5131 /* needed for displaying volume text instead of identifier */
5132 touch_controls_text = touch_control_current->name;
5133 move_distance_text = move_distance_current->name;
5134 drop_distance_text = drop_distance_current->name;
5136 setup_mode = SETUP_MODE_TOUCH;
5141 static void execSetupArtwork()
5144 printf("::: '%s', '%s', '%s'\n",
5145 artwork.gfx_current->subdir,
5146 artwork.gfx_current->fullpath,
5147 artwork.gfx_current->basepath);
5150 setup.graphics_set = artwork.gfx_current->identifier;
5151 setup.sounds_set = artwork.snd_current->identifier;
5152 setup.music_set = artwork.mus_current->identifier;
5154 /* needed if last screen (setup choice) changed graphics, sounds or music */
5155 ReloadCustomArtwork(0);
5157 /* needed for displaying artwork name instead of artwork identifier */
5158 graphics_set_name = artwork.gfx_current->name;
5159 sounds_set_name = artwork.snd_current->name;
5160 music_set_name = artwork.mus_current->name;
5162 setup_mode = SETUP_MODE_ARTWORK;
5167 static void execSetupChooseGraphics()
5169 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5174 static void execSetupChooseSounds()
5176 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5181 static void execSetupChooseMusic()
5183 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5188 #if !defined(PLATFORM_ANDROID)
5189 static void execSetupInput()
5191 setup_mode = SETUP_MODE_INPUT;
5197 static void execSetupShortcuts()
5199 setup_mode = SETUP_MODE_SHORTCUTS;
5204 static void execSetupShortcuts1()
5206 setup_mode = SETUP_MODE_SHORTCUTS_1;
5211 static void execSetupShortcuts2()
5213 setup_mode = SETUP_MODE_SHORTCUTS_2;
5218 static void execSetupShortcuts3()
5220 setup_mode = SETUP_MODE_SHORTCUTS_3;
5225 static void execSetupShortcuts4()
5227 setup_mode = SETUP_MODE_SHORTCUTS_4;
5232 static void execSetupShortcuts5()
5234 setup_mode = SETUP_MODE_SHORTCUTS_5;
5239 static void execExitSetup()
5241 game_status = GAME_MODE_MAIN;
5243 DrawMainMenuExt(REDRAW_FIELD, FALSE);
5246 static void execSaveAndExitSetup()
5252 static struct TokenInfo setup_info_main[] =
5254 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5255 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5256 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5257 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5258 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5259 #if !defined(PLATFORM_ANDROID)
5260 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5261 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5263 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5265 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5266 { TYPE_EMPTY, NULL, "" },
5267 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5268 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5273 static struct TokenInfo setup_info_game[] =
5275 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5276 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5277 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5278 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5279 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5280 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5281 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5282 { TYPE_STRING, &game_speed_text, "" },
5284 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5285 { TYPE_STRING, &scroll_delay_text, "" },
5287 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5288 { TYPE_STRING, &snapshot_mode_text, "" },
5289 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5290 { TYPE_EMPTY, NULL, "" },
5291 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5296 static struct TokenInfo setup_info_editor[] =
5299 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5300 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5301 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5302 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5303 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5304 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5305 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5306 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5308 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5309 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5310 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5312 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5314 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5315 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5316 { TYPE_EMPTY, NULL, "" },
5318 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5319 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5320 { TYPE_EMPTY, NULL, "" },
5322 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5323 { TYPE_EMPTY, NULL, "" },
5324 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5329 static struct TokenInfo setup_info_graphics[] =
5331 #if !defined(PLATFORM_ANDROID)
5332 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5333 #if defined(TARGET_SDL2)
5334 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5335 { TYPE_STRING, &window_size_text, "" },
5336 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5337 { TYPE_STRING, &scaling_type_text, "" },
5339 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5340 { TYPE_STRING, &screen_mode_text, "" },
5344 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5345 { TYPE_STRING, &scroll_delay_text, "" },
5347 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5348 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5349 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5350 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5351 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5352 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5353 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5354 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5355 { TYPE_EMPTY, NULL, "" },
5356 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5361 static struct TokenInfo setup_info_sound[] =
5363 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5364 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5365 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5366 { TYPE_EMPTY, NULL, "" },
5367 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5368 { TYPE_STRING, &volume_simple_text, "" },
5369 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5370 { TYPE_STRING, &volume_loops_text, "" },
5371 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5372 { TYPE_STRING, &volume_music_text, "" },
5373 { TYPE_EMPTY, NULL, "" },
5374 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5379 static struct TokenInfo setup_info_artwork[] =
5381 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5382 { TYPE_STRING, &graphics_set_name, "" },
5383 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5384 { TYPE_STRING, &sounds_set_name, "" },
5385 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5386 { TYPE_STRING, &music_set_name, "" },
5387 { TYPE_EMPTY, NULL, "" },
5388 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5389 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5390 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5391 { TYPE_EMPTY, NULL, "" },
5392 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5397 static struct TokenInfo setup_info_input[] =
5399 { TYPE_SWITCH, NULL, "Player:" },
5400 { TYPE_SWITCH, NULL, "Device:" },
5401 { TYPE_ENTER_MENU, NULL, "" },
5402 { TYPE_EMPTY, NULL, "" },
5403 { TYPE_EMPTY, NULL, "" },
5404 { TYPE_EMPTY, NULL, "" },
5405 { TYPE_EMPTY, NULL, "" },
5406 { TYPE_EMPTY, NULL, "" },
5407 { TYPE_EMPTY, NULL, "" },
5408 { TYPE_EMPTY, NULL, "" },
5409 { TYPE_EMPTY, NULL, "" },
5410 { TYPE_EMPTY, NULL, "" },
5411 { TYPE_EMPTY, NULL, "" },
5412 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5417 static struct TokenInfo setup_info_touch[] =
5419 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5420 { TYPE_STRING, &touch_controls_text, "" },
5421 { TYPE_EMPTY, NULL, "" },
5422 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5423 { TYPE_STRING, &move_distance_text, "" },
5424 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5425 { TYPE_STRING, &drop_distance_text, "" },
5426 { TYPE_EMPTY, NULL, "" },
5427 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5432 static struct TokenInfo setup_info_shortcuts[] =
5434 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5435 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5436 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5437 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5438 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5439 { TYPE_EMPTY, NULL, "" },
5440 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5445 static struct TokenInfo setup_info_shortcuts_1[] =
5447 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5448 { TYPE_KEY, &setup.shortcut.save_game, "" },
5449 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5450 { TYPE_KEY, &setup.shortcut.load_game, "" },
5451 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5452 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5453 { TYPE_EMPTY, NULL, "" },
5454 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5455 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5456 { TYPE_EMPTY, NULL, "" },
5457 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5462 static struct TokenInfo setup_info_shortcuts_2[] =
5464 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5465 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5466 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5467 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5468 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5469 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5470 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5471 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5472 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5473 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5474 { TYPE_EMPTY, NULL, "" },
5475 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5480 static struct TokenInfo setup_info_shortcuts_3[] =
5482 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5483 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5484 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5485 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5486 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5487 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5488 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5489 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5490 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5491 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5492 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5493 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5494 { TYPE_EMPTY, NULL, "" },
5495 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5500 static struct TokenInfo setup_info_shortcuts_4[] =
5502 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5503 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5504 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5505 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5506 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5507 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5508 { TYPE_EMPTY, NULL, "" },
5509 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5514 static struct TokenInfo setup_info_shortcuts_5[] =
5516 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5517 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5518 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5519 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5520 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5521 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5522 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5523 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5524 { TYPE_EMPTY, NULL, "" },
5525 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5530 static Key getSetupKey()
5532 Key key = KSYM_UNDEFINED;
5533 boolean got_key_event = FALSE;
5535 while (!got_key_event)
5537 if (PendingEvent()) /* got event */
5545 case EVENT_KEYPRESS:
5547 key = GetEventKey((KeyEvent *)&event, TRUE);
5549 /* press 'Escape' or 'Enter' to keep the existing key binding */
5550 if (key == KSYM_Escape || key == KSYM_Return)
5551 key = KSYM_UNDEFINED; /* keep old value */
5553 got_key_event = TRUE;
5557 case EVENT_KEYRELEASE:
5558 key_joystick_mapping = 0;
5562 HandleOtherEvents(&event);
5570 /* don't eat all CPU time */
5577 static int getSetupValueFont(int type, void *value)
5579 if (type & TYPE_KEY)
5580 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5581 else if (type & TYPE_STRING)
5582 return FONT_VALUE_2;
5583 else if (type & TYPE_ECS_AGA)
5584 return FONT_VALUE_1;
5585 else if (type & TYPE_BOOLEAN_STYLE)
5586 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5587 else if (type & TYPE_YES_NO_AUTO)
5588 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5589 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5591 return FONT_VALUE_1;
5594 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5596 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5597 struct TokenInfo *si = &setup_info[si_pos];
5598 boolean font_draw_xoffset_modified = FALSE;
5599 int font_draw_xoffset_old = -1;
5600 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5601 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5602 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5603 int xpos = menu_screen_value_xpos;
5604 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5605 int startx = mSX + xpos * 32;
5606 int starty = mSY + ypos * 32;
5607 int font_nr, font_width;
5608 int type = si->type;
5609 void *value = si->value;
5610 char *value_string = getSetupValue(type, value);
5613 if (value_string == NULL)
5616 if (type & TYPE_KEY)
5618 xpos = MENU_SCREEN_START_XPOS;
5620 if (type & TYPE_QUERY)
5621 value_string = "<press key>";
5623 else if (type & TYPE_STRING)
5625 int max_value_len = (SCR_FIELDX - 2) * 2;
5627 xpos = MENU_SCREEN_START_XPOS;
5629 if (strlen(value_string) > max_value_len)
5630 value_string[max_value_len] = '\0';
5632 else if (type & TYPE_YES_NO_AUTO)
5634 xpos = menu_screen_value_xpos - 1;
5637 startx = mSX + xpos * 32;
5638 starty = mSY + ypos * 32;
5639 font_nr = getSetupValueFont(type, value);
5640 font_width = getFontWidth(font_nr);
5642 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5643 if (setup_mode != SETUP_MODE_INPUT)
5645 int max_menu_text_length_big = (menu_screen_value_xpos -
5646 MENU_SCREEN_START_XPOS);
5647 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5648 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5649 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5650 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5651 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5652 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5653 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5654 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5655 boolean correct_font_draw_xoffset = FALSE;
5657 if (xpos == MENU_SCREEN_START_XPOS &&
5658 startx + font1_xoffset < text_startx + text_font_xoffset)
5659 correct_font_draw_xoffset = TRUE;
5661 if (xpos == menu_screen_value_xpos &&
5662 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5663 correct_font_draw_xoffset = TRUE;
5665 /* check if setup value would overlap with setup text when printed */
5666 /* (this can happen for extreme/wrong values for font draw offset) */
5667 if (correct_font_draw_xoffset)
5669 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5670 font_draw_xoffset_modified = TRUE;
5672 if (type & TYPE_KEY)
5673 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5674 else if (!(type & TYPE_STRING))
5675 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5676 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5680 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5681 DrawText(startx + i * font_width, starty, " ", font_nr);
5683 DrawText(startx, starty, value_string, font_nr);
5685 if (font_draw_xoffset_modified)
5686 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5689 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5691 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5692 struct TokenInfo *si = &setup_info[si_pos];
5694 if (si->type & TYPE_BOOLEAN_STYLE)
5696 *(boolean *)si->value ^= TRUE;
5698 else if (si->type & TYPE_YES_NO_AUTO)
5702 (*(int *)si->value == AUTO ? TRUE :
5703 *(int *)si->value == TRUE ? FALSE : AUTO) :
5704 (*(int *)si->value == TRUE ? AUTO :
5705 *(int *)si->value == AUTO ? FALSE : TRUE));
5707 else if (si->type & TYPE_KEY)
5711 si->type |= TYPE_QUERY;
5712 drawSetupValue(screen_pos, setup_info_pos_raw);
5713 si->type &= ~TYPE_QUERY;
5715 key = getSetupKey();
5716 if (key != KSYM_UNDEFINED)
5717 *(Key *)si->value = key;
5720 drawSetupValue(screen_pos, setup_info_pos_raw);
5722 // fullscreen state may have changed at this point
5723 if (si->value == &setup.fullscreen)
5724 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5727 static void DrawSetupScreen_Generic()
5729 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5730 boolean redraw_all = FALSE;
5731 char *title_string = NULL;
5736 FreeScreenGadgets();
5737 CreateScreenGadgets();
5739 CloseDoor(DOOR_CLOSE_2);
5741 if (redraw_mask & REDRAW_ALL)
5748 if (setup_mode == SETUP_MODE_MAIN)
5750 setup_info = setup_info_main;
5751 title_string = "Setup";
5753 else if (setup_mode == SETUP_MODE_GAME)
5755 setup_info = setup_info_game;
5756 title_string = "Setup Game";
5758 else if (setup_mode == SETUP_MODE_EDITOR)
5760 setup_info = setup_info_editor;
5761 title_string = "Setup Editor";
5763 else if (setup_mode == SETUP_MODE_GRAPHICS)
5765 setup_info = setup_info_graphics;
5766 title_string = "Setup Graphics";
5768 else if (setup_mode == SETUP_MODE_SOUND)
5770 setup_info = setup_info_sound;
5771 title_string = "Setup Sound";
5773 else if (setup_mode == SETUP_MODE_ARTWORK)
5775 setup_info = setup_info_artwork;
5776 title_string = "Custom Artwork";
5778 else if (setup_mode == SETUP_MODE_TOUCH)
5780 setup_info = setup_info_touch;
5781 title_string = "Setup Touch Ctrls";
5783 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5785 setup_info = setup_info_shortcuts;
5786 title_string = "Setup Shortcuts";
5788 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5790 setup_info = setup_info_shortcuts_1;
5791 title_string = "Setup Shortcuts";
5793 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5795 setup_info = setup_info_shortcuts_2;
5796 title_string = "Setup Shortcuts";
5798 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5800 setup_info = setup_info_shortcuts_3;
5801 title_string = "Setup Shortcuts";
5803 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5805 setup_info = setup_info_shortcuts_4;
5806 title_string = "Setup Shortcuts";
5808 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5810 setup_info = setup_info_shortcuts_5;
5811 title_string = "Setup Shortcuts";
5814 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5816 // determine maximal number of setup entries that can be displayed on screen
5818 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5821 // determine maximal number of setup entries available for this setup screen
5823 for (i = 0; setup_info[i].type != 0; i++)
5826 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5828 MapScreenGadgets(max_setup_info);
5831 redraw_mask = fade_mask = REDRAW_ALL;
5838 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5840 menu_info = setup_info;
5842 HandleMenuScreen(mx, my, dx, dy, button,
5843 setup_mode, num_setup_info, max_setup_info);
5846 void DrawSetupScreen_Input()
5850 FadeOut(REDRAW_FIELD);
5854 setup_info = setup_info_input;
5856 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5858 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5859 "Joysticks deactivated on this screen");
5861 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5863 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5864 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5865 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5866 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5867 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5868 initCursor(i, IMG_MENU_BUTTON);
5870 DrawCursorAndText_Setup(i, -1, FALSE);
5873 /* create gadgets for setup input menu screen */
5874 FreeScreenGadgets();
5875 CreateScreenGadgets();
5877 /* map gadgets for setup input menu screen */
5878 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5880 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5882 FadeIn(REDRAW_FIELD);
5887 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5889 if (device_name == NULL)
5892 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5895 if (strlen(device_name) > 1)
5897 char c1 = device_name[strlen(device_name) - 1];
5898 char c2 = device_name[strlen(device_name) - 2];
5900 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5901 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5904 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5905 strlen(device_name));
5908 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5911 static struct SetupKeyboardInfo custom_key;
5918 { &custom_key.left, "Joystick Left" },
5919 { &custom_key.right, "Joystick Right" },
5920 { &custom_key.up, "Joystick Up" },
5921 { &custom_key.down, "Joystick Down" },
5922 { &custom_key.snap, "Button 1" },
5923 { &custom_key.drop, "Button 2" }
5925 static char *joystick_name[MAX_PLAYERS] =
5932 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5936 custom_key = setup.input[player_nr].key;
5938 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5939 FONT_INPUT_1_ACTIVE);
5941 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5943 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5944 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5946 if (setup.input[player_nr].use_joystick)
5948 char *device_name = setup.input[player_nr].joy.device_name;
5949 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5950 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5952 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5953 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5957 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5958 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5961 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5963 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5964 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5965 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5966 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5968 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
5969 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
5970 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
5971 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
5972 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
5973 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
5975 for (i = 0; i < 6; i++)
5977 int ypos = 6 + i + (i > 3 ? i-3 : 0);
5979 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5981 DrawText(mSX + 3 * 32, mSY + ypos * 32,
5982 (setup.input[player_nr].use_joystick ?
5984 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
5988 static int input_player_nr = 0;
5990 void HandleSetupScreen_Input_Player(int step, int direction)
5992 int old_player_nr = input_player_nr;
5995 new_player_nr = old_player_nr + step * direction;
5996 if (new_player_nr < 0)
5998 if (new_player_nr > MAX_PLAYERS - 1)
5999 new_player_nr = MAX_PLAYERS - 1;
6001 if (new_player_nr != old_player_nr)
6003 input_player_nr = new_player_nr;
6005 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6009 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6011 static int choice = 0;
6014 int pos_start = SETUPINPUT_SCREEN_POS_START;
6015 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6016 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6017 int pos_end = SETUPINPUT_SCREEN_POS_END;
6019 if (button == MB_MENU_INITIALIZE)
6021 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6023 DrawCursorAndText_Setup(choice, -1, TRUE);
6027 else if (button == MB_MENU_LEAVE)
6029 setup_mode = SETUP_MODE_MAIN;
6036 if (mx || my) /* mouse input */
6038 x = (mx - mSX) / 32;
6039 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6041 else if (dx || dy) /* keyboard input */
6043 if (dx && choice == 0)
6044 x = (dx < 0 ? 10 : 12);
6045 else if ((dx && choice == 1) ||
6046 (dx == +1 && choice == 2) ||
6047 (dx == -1 && choice == pos_end))
6048 button = MB_MENU_CHOICE;
6052 if (y >= pos_empty1 && y <= pos_empty2)
6053 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6056 if (y == 0 && dx != 0 && button)
6058 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6060 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6061 y >= pos_start && y <= pos_end &&
6062 !(y >= pos_empty1 && y <= pos_empty2))
6068 DrawCursorAndText_Setup(choice, -1, FALSE);
6069 DrawCursorAndText_Setup(y, -1, TRUE);
6071 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6080 char *device_name = setup.input[input_player_nr].joy.device_name;
6082 if (!setup.input[input_player_nr].use_joystick)
6084 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6086 setJoystickDeviceToNr(device_name, new_device_nr);
6087 setup.input[input_player_nr].use_joystick = TRUE;
6091 int device_nr = getJoystickNrFromDeviceName(device_name);
6092 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6094 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6095 setup.input[input_player_nr].use_joystick = FALSE;
6097 setJoystickDeviceToNr(device_name, new_device_nr);
6100 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6104 if (setup.input[input_player_nr].use_joystick)
6107 CalibrateJoystick(input_player_nr);
6110 CustomizeKeyboard(input_player_nr);
6112 else if (y == pos_end)
6118 setup_mode = SETUP_MODE_MAIN;
6125 void CustomizeKeyboard(int player_nr)
6129 boolean finished = FALSE;
6130 static struct SetupKeyboardInfo custom_key;
6135 } customize_step[] =
6137 { &custom_key.left, "Move Left" },
6138 { &custom_key.right, "Move Right" },
6139 { &custom_key.up, "Move Up" },
6140 { &custom_key.down, "Move Down" },
6141 { &custom_key.snap, "Snap Field" },
6142 { &custom_key.drop, "Drop Element" }
6145 /* read existing key bindings from player setup */
6146 custom_key = setup.input[player_nr].key;
6149 FadeOut(REDRAW_FIELD);
6153 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6156 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6157 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6158 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6159 "Key:", FONT_INPUT_1_ACTIVE);
6160 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6161 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6163 FadeIn(REDRAW_FIELD);
6169 if (PendingEvent()) /* got event */
6177 case EVENT_KEYPRESS:
6179 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6181 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6183 if (key == KSYM_Escape)
6184 FadeSkipNextFadeIn();
6190 /* all keys configured -- wait for "Escape" or "Return" key */
6194 /* press 'Enter' to keep the existing key binding */
6195 if (key == KSYM_Return)
6196 key = *customize_step[step_nr].key;
6198 /* check if key already used */
6199 for (i = 0; i < step_nr; i++)
6200 if (*customize_step[i].key == key)
6205 /* got new key binding */
6206 *customize_step[step_nr].key = key;
6207 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6209 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6210 getKeyNameFromKey(key), FONT_VALUE_1);
6213 /* un-highlight last query */
6214 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6215 customize_step[step_nr - 1].text, FONT_MENU_1);
6216 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6217 "Key:", FONT_MENU_1);
6219 /* press 'Enter' to leave */
6222 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6223 "Press Enter", FONT_TITLE_1);
6227 /* query next key binding */
6228 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6229 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6230 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6231 "Key:", FONT_INPUT_1_ACTIVE);
6232 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6233 getKeyNameFromKey(*customize_step[step_nr].key),
6238 case EVENT_KEYRELEASE:
6239 key_joystick_mapping = 0;
6243 HandleOtherEvents(&event);
6251 /* don't eat all CPU time */
6255 /* write new key bindings back to player setup */
6256 setup.input[player_nr].key = custom_key;
6259 DrawSetupScreen_Input();
6262 static boolean CalibrateJoystickMain(int player_nr)
6264 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6265 int new_joystick_xright = JOYSTICK_XMIDDLE;
6266 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6267 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6268 int new_joystick_xmiddle, new_joystick_ymiddle;
6270 int joystick_fd = joystick.fd[player_nr];
6271 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6272 boolean check[3][3];
6273 int check_remaining = 3 * 3;
6278 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6281 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6285 FadeOut(REDRAW_FIELD);
6289 for (y = 0; y < 3; y++)
6291 for (x = 0; x < 3; x++)
6293 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6294 check[x][y] = FALSE;
6298 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6299 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6300 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6301 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6302 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6303 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6304 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6306 joy_value = Joystick(player_nr);
6307 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6308 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6310 /* eventually uncalibrated center position (joystick could be uncentered) */
6311 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6314 new_joystick_xmiddle = joy_x;
6315 new_joystick_ymiddle = joy_y;
6317 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6319 FadeIn(REDRAW_FIELD);
6321 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6326 if (PendingEvent()) /* got event */
6334 case EVENT_KEYPRESS:
6335 switch (GetEventKey((KeyEvent *)&event, TRUE))
6338 if (check_remaining == 0)
6343 FadeSkipNextFadeIn();
6352 case EVENT_KEYRELEASE:
6353 key_joystick_mapping = 0;
6357 HandleOtherEvents(&event);
6362 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6365 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6366 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6367 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6368 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6370 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6371 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6372 setup.input[player_nr].joy.xright = new_joystick_xright;
6373 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6374 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6375 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6377 CheckJoystickData();
6379 joy_value = Joystick(player_nr);
6381 if (joy_value & JOY_BUTTON && check_remaining == 0)
6384 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6385 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6387 if (x != last_x || y != last_y)
6389 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6390 IMG_MENU_CALIBRATE_YELLOW, 0);
6391 DrawFixedGraphic(xpos + x, ypos + y,
6392 IMG_MENU_CALIBRATE_RED, 0);
6397 if (check_remaining > 0 && !check[x+1][y+1])
6399 check[x+1][y+1] = TRUE;
6407 /* don't eat all CPU time */
6411 /* calibrated center position (joystick should now be centered) */
6412 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6415 new_joystick_xmiddle = joy_x;
6416 new_joystick_ymiddle = joy_y;
6420 /* wait until the last pressed button was released */
6421 while (Joystick(player_nr) & JOY_BUTTON)
6423 if (PendingEvent()) /* got event */
6428 HandleOtherEvents(&event);
6437 void CalibrateJoystick(int player_nr)
6439 if (!CalibrateJoystickMain(player_nr))
6441 char *device_name = setup.input[player_nr].joy.device_name;
6442 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6443 int xpos = mSX - SX;
6444 int ypos = mSY - SY;
6448 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6449 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6452 Delay(2000); /* show error message for a short time */
6457 DrawSetupScreen_Input();
6460 void DrawSetupScreen()
6462 DeactivateJoystick();
6464 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6466 if (setup_mode == SETUP_MODE_INPUT)
6467 DrawSetupScreen_Input();
6468 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6469 DrawChooseTree(&game_speed_current);
6470 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6471 DrawChooseTree(&scroll_delay_current);
6472 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6473 DrawChooseTree(&snapshot_mode_current);
6474 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6475 DrawChooseTree(&screen_mode_current);
6476 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6477 DrawChooseTree(&window_size_current);
6478 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6479 DrawChooseTree(&scaling_type_current);
6480 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6481 DrawChooseTree(&artwork.gfx_current);
6482 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6483 DrawChooseTree(&artwork.snd_current);
6484 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6485 DrawChooseTree(&artwork.mus_current);
6486 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6487 DrawChooseTree(&volume_simple_current);
6488 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6489 DrawChooseTree(&volume_loops_current);
6490 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6491 DrawChooseTree(&volume_music_current);
6492 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6493 DrawChooseTree(&touch_control_current);
6494 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6495 DrawChooseTree(&move_distance_current);
6496 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6497 DrawChooseTree(&drop_distance_current);
6499 DrawSetupScreen_Generic();
6505 void RedrawSetupScreenAfterFullscreenToggle()
6507 if (setup_mode == SETUP_MODE_GRAPHICS ||
6508 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6510 // update list selection from "setup.window_scaling_percent"
6511 execSetupGraphics_setWindowSizes(TRUE);
6517 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6519 if (setup_mode == SETUP_MODE_INPUT)
6520 HandleSetupScreen_Input(mx, my, dx, dy, button);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6522 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6524 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6526 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6528 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6530 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6531 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6532 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6533 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6534 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6535 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6536 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6537 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6538 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6539 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6540 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6541 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6542 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6543 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6544 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6545 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6546 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6547 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6548 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6549 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6550 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6552 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6555 void HandleGameActions()
6557 if (game_status != GAME_MODE_PLAYING)
6560 GameActions(); /* main game loop */
6562 if (tape.auto_play && !tape.playing)
6563 AutoPlayTape(); /* continue automatically playing next tape */
6567 /* ---------- new screen button stuff -------------------------------------- */
6569 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6573 case SCREEN_CTRL_ID_PREV_LEVEL:
6574 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6575 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6578 case SCREEN_CTRL_ID_NEXT_LEVEL:
6579 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6580 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6583 case SCREEN_CTRL_ID_PREV_PLAYER:
6584 *x = mSX + TILEX * 10;
6585 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6588 case SCREEN_CTRL_ID_NEXT_PLAYER:
6589 *x = mSX + TILEX * 12;
6590 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6594 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6600 int gfx_unpressed, gfx_pressed;
6601 void (*get_gadget_position)(int *, int *, int);
6605 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6608 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6609 getScreenMenuButtonPos,
6610 SCREEN_CTRL_ID_PREV_LEVEL,
6615 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6616 getScreenMenuButtonPos,
6617 SCREEN_CTRL_ID_NEXT_LEVEL,
6622 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6623 getScreenMenuButtonPos,
6624 SCREEN_CTRL_ID_PREV_PLAYER,
6629 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6630 getScreenMenuButtonPos,
6631 SCREEN_CTRL_ID_NEXT_PLAYER,
6639 int gfx_unpressed, gfx_pressed;
6643 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6646 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6647 -1, -1, /* these values are not constant, but can change at runtime */
6648 SCREEN_CTRL_ID_SCROLL_UP,
6652 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6653 -1, -1, /* these values are not constant, but can change at runtime */
6654 SCREEN_CTRL_ID_SCROLL_DOWN,
6661 int gfx_unpressed, gfx_pressed;
6667 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6670 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6671 -1, -1, /* these values are not constant, but can change at runtime */
6672 -1, -1, /* these values are not constant, but can change at runtime */
6673 GD_TYPE_SCROLLBAR_VERTICAL,
6674 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6675 "scroll level series vertically"
6679 static void CreateScreenMenubuttons()
6681 struct GadgetInfo *gi;
6682 unsigned int event_mask;
6685 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6687 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6688 int gfx_unpressed, gfx_pressed;
6689 int x, y, width, height;
6690 int gd_x1, gd_x2, gd_y1, gd_y2;
6691 int id = menubutton_info[i].gadget_id;
6693 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6695 menubutton_info[i].get_gadget_position(&x, &y, id);
6697 width = SC_MENUBUTTON_XSIZE;
6698 height = SC_MENUBUTTON_YSIZE;
6700 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6701 gfx_pressed = menubutton_info[i].gfx_pressed;
6702 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6703 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6704 gd_x1 = graphic_info[gfx_unpressed].src_x;
6705 gd_y1 = graphic_info[gfx_unpressed].src_y;
6706 gd_x2 = graphic_info[gfx_pressed].src_x;
6707 gd_y2 = graphic_info[gfx_pressed].src_y;
6709 gi = CreateGadget(GDI_CUSTOM_ID, id,
6710 GDI_CUSTOM_TYPE_ID, i,
6711 GDI_INFO_TEXT, menubutton_info[i].infotext,
6716 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6717 GDI_STATE, GD_BUTTON_UNPRESSED,
6718 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6719 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6720 GDI_DIRECT_DRAW, FALSE,
6721 GDI_EVENT_MASK, event_mask,
6722 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6726 Error(ERR_EXIT, "cannot create gadget");
6728 screen_gadget[id] = gi;
6732 static void CreateScreenScrollbuttons()
6734 struct GadgetInfo *gi;
6735 unsigned int event_mask;
6738 /* these values are not constant, but can change at runtime */
6739 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6740 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6741 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6742 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6744 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6746 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6747 int gfx_unpressed, gfx_pressed;
6748 int x, y, width, height;
6749 int gd_x1, gd_x2, gd_y1, gd_y2;
6750 int id = scrollbutton_info[i].gadget_id;
6752 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6754 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6755 y = mSY + scrollbutton_info[i].y;
6756 width = SC_SCROLLBUTTON_XSIZE;
6757 height = SC_SCROLLBUTTON_YSIZE;
6759 /* correct scrollbar position if placed outside menu (playfield) area */
6760 if (x > SX + SC_SCROLL_UP_XPOS)
6761 x = SX + SC_SCROLL_UP_XPOS;
6763 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6764 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6765 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6767 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6768 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6769 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6770 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6771 gd_x1 = graphic_info[gfx_unpressed].src_x;
6772 gd_y1 = graphic_info[gfx_unpressed].src_y;
6773 gd_x2 = graphic_info[gfx_pressed].src_x;
6774 gd_y2 = graphic_info[gfx_pressed].src_y;
6776 gi = CreateGadget(GDI_CUSTOM_ID, id,
6777 GDI_CUSTOM_TYPE_ID, i,
6778 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6783 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6784 GDI_STATE, GD_BUTTON_UNPRESSED,
6785 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6786 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6787 GDI_DIRECT_DRAW, FALSE,
6788 GDI_EVENT_MASK, event_mask,
6789 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6793 Error(ERR_EXIT, "cannot create gadget");
6795 screen_gadget[id] = gi;
6799 static void CreateScreenScrollbars()
6803 /* these values are not constant, but can change at runtime */
6804 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6805 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6806 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6807 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6809 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6811 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6812 int gfx_unpressed, gfx_pressed;
6813 int x, y, width, height;
6814 int gd_x1, gd_x2, gd_y1, gd_y2;
6815 struct GadgetInfo *gi;
6816 int items_max, items_visible, item_position;
6817 unsigned int event_mask;
6818 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6819 int id = scrollbar_info[i].gadget_id;
6821 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6823 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6824 y = mSY + scrollbar_info[i].y;
6825 width = scrollbar_info[i].width;
6826 height = scrollbar_info[i].height;
6828 /* correct scrollbar position if placed outside menu (playfield) area */
6829 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6830 x = SX + SC_SCROLL_VERTICAL_XPOS;
6832 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6833 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6835 items_max = num_page_entries;
6836 items_visible = num_page_entries;
6839 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6840 gfx_pressed = scrollbar_info[i].gfx_pressed;
6841 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6842 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6843 gd_x1 = graphic_info[gfx_unpressed].src_x;
6844 gd_y1 = graphic_info[gfx_unpressed].src_y;
6845 gd_x2 = graphic_info[gfx_pressed].src_x;
6846 gd_y2 = graphic_info[gfx_pressed].src_y;
6848 gi = CreateGadget(GDI_CUSTOM_ID, id,
6849 GDI_CUSTOM_TYPE_ID, i,
6850 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6855 GDI_TYPE, scrollbar_info[i].type,
6856 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6857 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6858 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6859 GDI_WHEEL_AREA_X, SX,
6860 GDI_WHEEL_AREA_Y, SY,
6861 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6862 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6863 GDI_STATE, GD_BUTTON_UNPRESSED,
6864 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6865 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6866 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6867 GDI_DIRECT_DRAW, FALSE,
6868 GDI_EVENT_MASK, event_mask,
6869 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6873 Error(ERR_EXIT, "cannot create gadget");
6875 screen_gadget[id] = gi;
6879 void CreateScreenGadgets()
6881 int last_game_status = game_status; /* save current game status */
6883 CreateScreenMenubuttons();
6885 CreateScreenScrollbuttons();
6886 CreateScreenScrollbars();
6888 game_status = last_game_status; /* restore current game status */
6891 void FreeScreenGadgets()
6895 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6896 FreeGadget(screen_gadget[i]);
6899 void MapScreenMenuGadgets(int screen_mask)
6903 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6904 if (screen_mask & menubutton_info[i].screen_mask)
6905 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6908 void MapScreenGadgets(int num_entries)
6912 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6915 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6916 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6918 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6919 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6922 void MapScreenTreeGadgets(TreeInfo *ti)
6924 MapScreenGadgets(numTreeInfoInGroup(ti));
6927 static void HandleScreenGadgets(struct GadgetInfo *gi)
6929 int id = gi->custom_id;
6930 int button = gi->event.button;
6931 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6935 case SCREEN_CTRL_ID_PREV_LEVEL:
6936 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6939 case SCREEN_CTRL_ID_NEXT_LEVEL:
6940 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6943 case SCREEN_CTRL_ID_PREV_PLAYER:
6944 HandleSetupScreen_Input_Player(step, -1);
6947 case SCREEN_CTRL_ID_NEXT_PLAYER:
6948 HandleSetupScreen_Input_Player(step, +1);
6951 case SCREEN_CTRL_ID_SCROLL_UP:
6952 if (game_status == GAME_MODE_LEVELS)
6953 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6954 else if (game_status == GAME_MODE_LEVELNR)
6955 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6956 else if (game_status == GAME_MODE_SETUP)
6957 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6958 else if (game_status == GAME_MODE_INFO)
6959 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6962 case SCREEN_CTRL_ID_SCROLL_DOWN:
6963 if (game_status == GAME_MODE_LEVELS)
6964 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6965 else if (game_status == GAME_MODE_LEVELNR)
6966 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6967 else if (game_status == GAME_MODE_SETUP)
6968 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6969 else if (game_status == GAME_MODE_INFO)
6970 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6973 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
6974 if (game_status == GAME_MODE_LEVELS)
6975 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6976 else if (game_status == GAME_MODE_LEVELNR)
6977 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
6978 else if (game_status == GAME_MODE_SETUP)
6979 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
6980 else if (game_status == GAME_MODE_INFO)
6981 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);