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);
1421 /* needed if different viewport properties defined for menues */
1422 ChangeViewportPropertiesIfNeeded();
1425 if (redraw_mask & REDRAW_ALL)
1426 fade_mask = REDRAW_ALL;
1428 if (CheckIfRedrawGlobalBorderIsNeeded())
1429 fade_mask = REDRAW_ALL;
1434 /* needed if different viewport properties defined for menues */
1435 ChangeViewportPropertiesIfNeeded();
1438 /* needed if last screen was the editor screen */
1439 UndrawSpecialEditorDoor();
1441 SetDrawtoField(DRAW_BACKBUFFER);
1443 /* reset drawing area change flag */
1444 DrawingAreaChanged();
1446 if (CheckTitleScreen(levelset_has_changed))
1448 game_status = GAME_MODE_TITLE;
1455 /* level_nr may have been set to value over handicap with level editor */
1456 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1457 level_nr = leveldir_current->handicap_level;
1459 LoadLevel(level_nr);
1460 LoadScore(level_nr);
1462 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1463 SetDrawDeactivationMask(REDRAW_NONE);
1464 SetDrawBackgroundMask(REDRAW_FIELD);
1466 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1469 if (fade_mask == REDRAW_ALL)
1470 RedrawGlobalBorder();
1475 InitializeMainControls();
1477 DrawCursorAndText_Main(-1, FALSE, FALSE);
1478 DrawPreviewLevelInitial();
1480 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1483 if (TAPE_IS_EMPTY(tape))
1485 DrawCompleteVideoDisplay();
1490 /* create gadgets for main menu screen */
1491 FreeScreenGadgets();
1492 CreateScreenGadgets();
1494 /* map gadgets for main menu screen */
1496 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1498 /* copy actual game door content to door double buffer for OpenDoor() */
1499 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1501 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1503 DrawMaskedBorder(REDRAW_ALL);
1506 if (redraw_mask & REDRAW_ALL)
1507 fade_mask = REDRAW_ALL;
1513 /* update screen area with special editor door */
1514 redraw_mask |= REDRAW_ALL;
1517 SetMouseCursor(CURSOR_DEFAULT);
1521 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1524 void DrawAndFadeInMainMenu(int fade_mask)
1526 DrawMainMenuExt(fade_mask, TRUE);
1531 DrawMainMenuExt(REDRAW_ALL, FALSE);
1534 static void gotoTopLevelDir()
1536 /* move upwards until inside (but not above) top level directory */
1537 while (leveldir_current->node_parent &&
1538 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1540 /* write a "path" into level tree for easy navigation to last level */
1541 if (leveldir_current->node_parent->node_group->cl_first == -1)
1543 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1544 int leveldir_pos = posTreeInfo(leveldir_current);
1545 int num_page_entries;
1546 int cl_first, cl_cursor;
1548 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1549 num_page_entries = num_leveldirs;
1551 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1553 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1554 cl_cursor = leveldir_pos - cl_first;
1556 leveldir_current->node_parent->node_group->cl_first = cl_first;
1557 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1560 leveldir_current = leveldir_current->node_parent;
1564 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1566 static unsigned int title_delay = 0;
1567 static int title_screen_nr = 0;
1568 static int last_sound = -1, last_music = -1;
1569 boolean return_to_main_menu = FALSE;
1570 boolean use_fading_main_menu = TRUE;
1571 struct TitleControlInfo *tci;
1572 struct TitleFadingInfo fading_default;
1573 struct TitleFadingInfo fading_last = fading;
1574 struct TitleFadingInfo fading_next;
1577 if (button == MB_MENU_INITIALIZE)
1580 title_screen_nr = 0;
1581 tci = &title_controls[title_screen_nr];
1583 last_sound = SND_UNDEFINED;
1584 last_music = MUS_UNDEFINED;
1586 if (game_status == GAME_MODE_INFO)
1588 if (num_title_screens == 0)
1590 DrawInfoScreen_NotAvailable("Title screen information:",
1591 "No title screen for this level set.");
1596 FadeSoundsAndMusic();
1598 FadeOut(REDRAW_ALL);
1602 DrawTitleScreenImage(tci->local_nr, tci->initial);
1604 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1606 fading_default = (tci->initial ? title_initial_default : title_default);
1608 fading = fading_next = getTitleFading(tci);
1610 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1611 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1613 fading.fade_mode = FADE_MODE_FADE;
1614 fading.fade_delay = fading_default.fade_delay;
1617 sound = getTitleSound(tci);
1618 music = getTitleMusic(tci);
1620 if (sound != last_sound)
1621 PlayMenuSoundExt(sound);
1622 if (music != last_music)
1623 PlayMenuMusicExt(music);
1628 SetMouseCursor(CURSOR_NONE);
1632 fading = fading_next;
1634 DelayReached(&title_delay, 0); /* reset delay counter */
1639 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1640 button = MB_MENU_CHOICE;
1642 if (button == MB_MENU_LEAVE)
1644 return_to_main_menu = TRUE;
1645 use_fading_main_menu = FALSE;
1647 else if (button == MB_MENU_CHOICE)
1649 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1651 FadeSetEnterScreen();
1653 info_mode = INFO_MODE_MAIN;
1654 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1660 tci = &title_controls[title_screen_nr];
1662 if (title_screen_nr < num_title_screens)
1664 sound = getTitleSound(tci);
1665 music = getTitleMusic(tci);
1667 if (sound == SND_UNDEFINED || sound != last_sound)
1669 if (music == MUS_UNDEFINED || music != last_music)
1672 FadeOut(REDRAW_ALL);
1675 DrawTitleScreenImage(tci->local_nr, tci->initial);
1677 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1679 fading_next = getTitleFading(tci);
1681 sound = getTitleSound(tci);
1682 music = getTitleMusic(tci);
1684 if (sound != last_sound)
1685 PlayMenuSoundExt(sound);
1686 if (music != last_music)
1687 PlayMenuMusicExt(music);
1692 /* last screen already faded out, next screen has no animation */
1693 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1694 fading_next.fade_mode == FADE_MODE_NONE)
1695 fading = fading_next;
1699 fading = fading_next;
1701 DelayReached(&title_delay, 0); /* reset delay counter */
1705 FadeSoundsAndMusic();
1707 return_to_main_menu = TRUE;
1711 if (return_to_main_menu)
1713 SetMouseCursor(CURSOR_DEFAULT);
1715 if (game_status == GAME_MODE_INFO)
1717 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1719 info_mode = INFO_MODE_MAIN;
1721 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1723 else /* default: return to main menu */
1725 game_status = GAME_MODE_MAIN;
1727 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1732 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1734 int old_level_nr = level_nr;
1737 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1738 new_level_nr = selected_level_nr;
1740 new_level_nr = old_level_nr + step * direction;
1742 if (new_level_nr < leveldir_current->first_level)
1743 new_level_nr = leveldir_current->first_level;
1744 if (new_level_nr > leveldir_current->last_level)
1745 new_level_nr = leveldir_current->last_level;
1747 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1749 /* skipping levels is only allowed when trying to skip single level */
1750 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1751 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1753 leveldir_current->handicap_level++;
1754 SaveLevelSetup_SeriesInfo();
1757 new_level_nr = leveldir_current->handicap_level;
1760 if (new_level_nr != old_level_nr)
1762 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1764 PlaySound(SND_MENU_ITEM_SELECTING);
1766 level_nr = new_level_nr;
1768 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1769 int2str(level_nr, menu.main.text.level_number.size),
1770 mci->pos_text->font);
1772 LoadLevel(level_nr);
1773 DrawPreviewLevelInitial();
1777 DrawCompleteVideoDisplay();
1779 /* needed because DrawPreviewLevelInitial() takes some time */
1781 /* SyncDisplay(); */
1785 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1787 static int choice = MAIN_CONTROL_GAME;
1788 static boolean button_pressed_last = FALSE;
1789 boolean button_pressed = FALSE;
1793 if (button == MB_MENU_INITIALIZE)
1795 DrawCursorAndText_Main(choice, TRUE, FALSE);
1800 if (mx || my) /* mouse input */
1804 for (i = 0; main_controls[i].nr != -1; i++)
1806 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1807 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1808 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1810 pos = main_controls[i].nr;
1816 // handle pressed/unpressed state for active/inactive menu buttons
1817 // (if pos != -1, "i" contains index position corresponding to "pos")
1819 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1820 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1821 button_pressed = TRUE;
1823 if (button_pressed != button_pressed_last)
1825 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1828 PlaySound(SND_MENU_BUTTON_PRESSING);
1830 PlaySound(SND_MENU_BUTTON_RELEASING);
1833 else if (dx || dy) /* keyboard input */
1835 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1836 choice == MAIN_CONTROL_SETUP))
1837 button = MB_MENU_CHOICE;
1842 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1844 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1846 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1848 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1850 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1852 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1854 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1856 game_status = GAME_MODE_LEVELNR;
1858 ChangeViewportPropertiesIfNeeded();
1860 DrawChooseLevelNr();
1862 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1868 PlaySound(SND_MENU_ITEM_ACTIVATING);
1870 DrawCursorAndText_Main(choice, FALSE, FALSE);
1871 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1878 PlaySound(SND_MENU_ITEM_SELECTING);
1880 if (pos == MAIN_CONTROL_NAME)
1882 game_status = GAME_MODE_PSEUDO_TYPENAME;
1884 HandleTypeName(strlen(setup.player_name), 0);
1886 else if (pos == MAIN_CONTROL_LEVELS)
1890 game_status = GAME_MODE_LEVELS;
1892 SaveLevelSetup_LastSeries();
1893 SaveLevelSetup_SeriesInfo();
1895 if (setup.internal.choose_from_top_leveldir)
1898 ChangeViewportPropertiesIfNeeded();
1900 DrawChooseLevelSet();
1903 else if (pos == MAIN_CONTROL_SCORES)
1905 game_status = GAME_MODE_SCORES;
1908 /* required before door position may be changed in next step */
1909 CloseDoor(DOOR_CLOSE_ALL);
1912 ChangeViewportPropertiesIfNeeded();
1916 else if (pos == MAIN_CONTROL_EDITOR)
1918 if (leveldir_current->readonly &&
1919 !strEqual(setup.player_name, "Artsoft"))
1920 Request("This level is read only!", REQ_CONFIRM);
1922 CloseDoor(DOOR_CLOSE_2);
1924 game_status = GAME_MODE_EDITOR;
1926 FadeSetEnterScreen();
1930 else if (pos == MAIN_CONTROL_INFO)
1932 game_status = GAME_MODE_INFO;
1933 info_mode = INFO_MODE_MAIN;
1935 ChangeViewportPropertiesIfNeeded();
1939 else if (pos == MAIN_CONTROL_GAME)
1941 StartGameActions(options.network, setup.autorecord, level.random_seed);
1943 else if (pos == MAIN_CONTROL_SETUP)
1945 game_status = GAME_MODE_SETUP;
1946 setup_mode = SETUP_MODE_MAIN;
1948 ChangeViewportPropertiesIfNeeded();
1952 else if (pos == MAIN_CONTROL_QUIT)
1954 SaveLevelSetup_LastSeries();
1955 SaveLevelSetup_SeriesInfo();
1957 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1958 game_status = GAME_MODE_QUIT;
1963 button_pressed_last = button_pressed;
1967 /* ========================================================================= */
1968 /* info screen functions */
1969 /* ========================================================================= */
1971 static struct TokenInfo *info_info;
1972 static int num_info_info; /* number of info entries shown on screen */
1973 static int max_info_info; /* total number of info entries in list */
1975 static void execInfoTitleScreen()
1977 info_mode = INFO_MODE_TITLE;
1982 static void execInfoElements()
1984 info_mode = INFO_MODE_ELEMENTS;
1989 static void execInfoMusic()
1991 info_mode = INFO_MODE_MUSIC;
1996 static void execInfoCredits()
1998 info_mode = INFO_MODE_CREDITS;
2003 static void execInfoProgram()
2005 info_mode = INFO_MODE_PROGRAM;
2010 static void execInfoVersion()
2012 info_mode = INFO_MODE_VERSION;
2017 static void execInfoLevelSet()
2019 info_mode = INFO_MODE_LEVELSET;
2024 static void execExitInfo()
2026 game_status = GAME_MODE_MAIN;
2028 DrawMainMenuExt(REDRAW_FIELD, FALSE);
2031 static struct TokenInfo info_info_main[] =
2033 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2034 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2035 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2036 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2037 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2038 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2039 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2040 { TYPE_EMPTY, NULL, "" },
2041 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2046 static int getMenuTextFont(int type)
2048 if (type & (TYPE_SWITCH |
2060 static struct TokenInfo *setup_info;
2061 static struct TokenInfo setup_info_input[];
2063 static struct TokenInfo *menu_info;
2065 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2066 int screen_pos, int menu_info_pos_raw,
2069 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2070 struct TokenInfo *ti = &token_info[pos];
2071 int xpos = MENU_SCREEN_START_XPOS;
2072 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2073 int font_nr = getMenuTextFont(ti->type);
2075 if (token_info == setup_info_input)
2076 font_nr = FONT_MENU_1;
2079 font_nr = FONT_ACTIVE(font_nr);
2081 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2083 if (ti->type & ~TYPE_SKIP_ENTRY)
2084 drawCursor(screen_pos, active);
2087 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2090 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2093 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2096 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2099 static char *screen_mode_text;
2100 static char *window_size_text;
2101 static char *scaling_type_text;
2103 static void drawSetupValue(int, int);
2105 static void drawMenuInfoList(int first_entry, int num_page_entries,
2106 int max_page_entries)
2110 if (first_entry + num_page_entries > max_page_entries)
2113 clearMenuListArea();
2115 for (i = 0; i < num_page_entries; i++)
2117 int menu_info_pos = first_entry + i;
2118 struct TokenInfo *si = &menu_info[menu_info_pos];
2119 void *value_ptr = si->value;
2121 /* set some entries to "unchangeable" according to other variables */
2122 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2123 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2124 (value_ptr == &setup.sound_music && !audio.music_available) ||
2125 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2126 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
2127 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2128 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2129 si->type |= TYPE_GHOSTED;
2131 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2132 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2133 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2134 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2135 else if (si->type & ~TYPE_SKIP_ENTRY)
2136 initCursor(i, IMG_MENU_BUTTON);
2138 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2140 if (si->type & TYPE_VALUE &&
2141 menu_info == setup_info)
2142 drawSetupValue(i, menu_info_pos);
2146 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
2150 if (CheckIfRedrawGlobalBorderIsNeeded())
2151 fade_mask = REDRAW_ALL;
2155 FreeScreenGadgets();
2156 CreateScreenGadgets();
2158 CloseDoor(DOOR_CLOSE_2);
2160 /* (needed after displaying title screens which disable auto repeat) */
2161 KeyboardAutoRepeatOn();
2163 FadeSetLeaveScreen();
2167 if (fade_mask == REDRAW_ALL)
2169 RedrawGlobalBorder();
2171 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2176 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2178 info_info = info_info_main;
2180 // determine maximal number of info entries that can be displayed on screen
2182 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2185 // determine maximal number of info entries available for menu of info screen
2187 for (i = 0; info_info[i].type != 0; i++)
2190 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2192 MapScreenGadgets(max_info_info);
2197 DrawMaskedBorder(fade_mask);
2204 static void changeSetupValue(int, int, int);
2206 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2207 int mode, int num_page_entries, int max_page_entries)
2209 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2210 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2211 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2212 int *num_page_entries_last = num_page_entries_all_last[game_status];
2213 int *choice_store = choice_stores[game_status];
2214 int *first_entry_store = first_entry_stores[game_status];
2215 int choice = choice_store[mode]; /* starts with 0 */
2216 int first_entry = first_entry_store[mode]; /* starts with 0 */
2218 int y = choice - first_entry;
2220 boolean position_set_by_scrollbar = (dx == 999);
2221 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2224 if (button == MB_MENU_INITIALIZE)
2226 // check if number of menu page entries has changed (may happen by change
2227 // of custom artwork definition value for 'list_size' for this menu screen)
2228 // (in this case, the last menu position most probably has to be corrected)
2229 if (num_page_entries != num_page_entries_last[mode])
2231 choice_store[mode] = first_entry_store[mode] = 0;
2233 choice = first_entry = 0;
2236 num_page_entries_last[mode] = num_page_entries;
2239 /* advance to first valid menu entry */
2240 while (choice < num_page_entries &&
2241 menu_info[choice].type & TYPE_SKIP_ENTRY)
2244 if (position_set_by_scrollbar)
2245 first_entry = first_entry_store[mode] = dy;
2247 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2248 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2250 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2252 if (choice < first_entry)
2254 choice = first_entry;
2256 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2259 else if (choice > first_entry + num_page_entries - 1)
2261 choice = first_entry + num_page_entries - 1;
2263 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2267 choice_store[mode] = choice;
2269 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2273 else if (button == MB_MENU_LEAVE)
2275 PlaySound(SND_MENU_ITEM_SELECTING);
2277 for (i = 0; i < max_page_entries; i++)
2279 if (menu_info[i].type & TYPE_LEAVE_MENU)
2281 void (*menu_callback_function)(void) = menu_info[i].value;
2285 menu_callback_function();
2287 break; /* absolutely needed because function changes 'menu_info'! */
2294 if (mx || my) /* mouse input */
2296 x = (mx - mSX) / 32;
2297 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2299 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2301 /* move cursor instead of scrolling when already at start/end of list */
2302 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2304 else if (dy == +1 * SCROLL_LINE &&
2305 first_entry + num_page_entries == max_page_entries)
2308 /* handle scrolling screen one line or page */
2310 y + dy > num_page_entries - 1)
2312 boolean redraw = FALSE;
2314 if (ABS(dy) == SCROLL_PAGE)
2315 step = num_page_entries - 1;
2317 if (dy < 0 && first_entry > 0)
2319 /* scroll page/line up */
2321 first_entry -= step;
2322 if (first_entry < 0)
2327 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2329 /* scroll page/line down */
2331 first_entry += step;
2332 if (first_entry + num_page_entries > max_page_entries)
2333 first_entry = MAX(0, max_page_entries - num_page_entries);
2340 choice += first_entry - first_entry_store[mode];
2342 if (choice < first_entry)
2344 choice = first_entry;
2346 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2349 else if (choice > first_entry + num_page_entries - 1)
2351 choice = first_entry + num_page_entries - 1;
2353 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2356 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2360 if (choice < first_entry ||
2361 choice > first_entry + num_page_entries - 1)
2362 first_entry += SIGN(dy);
2365 first_entry_store[mode] = first_entry;
2366 choice_store[mode] = choice;
2368 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2370 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2372 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2373 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2381 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2383 if (menu_info[choice].type & menu_navigation_type ||
2384 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2385 menu_info[choice].type & TYPE_YES_NO_AUTO)
2386 button = MB_MENU_CHOICE;
2391 /* jump to next non-empty menu entry (up or down) */
2392 while (first_entry + y > 0 &&
2393 first_entry + y < max_page_entries - 1 &&
2394 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2397 if (!IN_VIS_MENU(x, y))
2399 choice += y - y_old;
2401 if (choice < first_entry)
2402 first_entry = choice;
2403 else if (choice > first_entry + num_page_entries - 1)
2404 first_entry = choice - num_page_entries + 1;
2406 if (first_entry >= 0 &&
2407 first_entry + num_page_entries <= max_page_entries)
2409 first_entry_store[mode] = first_entry;
2411 if (choice < first_entry)
2412 choice = first_entry;
2413 else if (choice > first_entry + num_page_entries - 1)
2414 choice = first_entry + num_page_entries - 1;
2416 choice_store[mode] = choice;
2418 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2420 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2422 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2423 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2430 if (!anyScrollbarGadgetActive() &&
2431 IN_VIS_MENU(x, y) &&
2432 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2433 y >= 0 && y < num_page_entries)
2437 if (first_entry + y != choice &&
2438 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2440 PlaySound(SND_MENU_ITEM_ACTIVATING);
2442 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2443 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2445 choice = choice_store[mode] = first_entry + y;
2448 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2450 PlaySound(SND_MENU_ITEM_SELECTING);
2452 /* when selecting key headline, execute function for key value change */
2453 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2454 menu_info[first_entry + y + 1].type & TYPE_KEY)
2457 /* when selecting string value, execute function for list selection */
2458 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2459 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2462 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2464 void (*menu_callback_function)(void) =
2465 menu_info[first_entry + y].value;
2467 FadeSetFromType(menu_info[first_entry + y].type);
2469 menu_callback_function();
2471 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2472 menu_info == setup_info)
2474 changeSetupValue(y, first_entry + y, dx);
2480 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2482 menu_info = info_info;
2484 HandleMenuScreen(mx, my, dx, dy, button,
2485 info_mode, num_info_info, max_info_info);
2488 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2490 int ystart1 = mSY - SY + 100;
2491 int ystart2 = mSY - SY + 150;
2492 int ybottom = mSY - SY + SYSIZE - 20;
2494 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2496 FadeOut(REDRAW_FIELD);
2501 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2502 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2504 DrawTextSCentered(ybottom, FONT_TEXT_4,
2505 "Press any key or button for info menu");
2507 FadeIn(REDRAW_FIELD);
2510 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2512 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2513 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2514 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2515 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2516 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2517 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2518 int ystep = MENU_SCREEN_INFO_YSTEP;
2519 int element, action, direction;
2527 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2528 infoscreen_step[i] = infoscreen_frame[i] = 0;
2533 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2535 DrawTextSCentered(ybottom, FONT_TEXT_4,
2536 "Press any key or button for next page");
2542 while (helpanim_info[j].element != HELPANIM_LIST_END)
2544 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2549 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2558 j += infoscreen_step[i - start];
2560 element = helpanim_info[j].element;
2561 action = helpanim_info[j].action;
2562 direction = helpanim_info[j].direction;
2565 element = EL_UNKNOWN;
2567 if (action != -1 && direction != -1)
2568 graphic = el_act_dir2img(element, action, direction);
2569 else if (action != -1)
2570 graphic = el_act2img(element, action);
2571 else if (direction != -1)
2572 graphic = el_dir2img(element, direction);
2574 graphic = el2img(element);
2576 delay = helpanim_info[j++].delay;
2581 if (infoscreen_frame[i - start] == 0)
2584 infoscreen_frame[i - start] = delay - 1;
2588 sync_frame = delay - infoscreen_frame[i - start];
2589 infoscreen_frame[i - start]--;
2592 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2594 if (!infoscreen_frame[i - start])
2595 infoscreen_step[i - start] = 0;
2599 if (!infoscreen_frame[i - start])
2600 infoscreen_step[i - start]++;
2601 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2607 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2609 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2610 graphic, sync_frame, USE_MASKING);
2613 DrawInfoScreen_HelpText(element, action, direction, i - start);
2618 redraw_mask |= REDRAW_FIELD;
2623 static char *getHelpText(int element, int action, int direction)
2625 char token[MAX_LINE_LEN];
2627 strcpy(token, element_info[element].token_name);
2630 strcat(token, element_action_info[action].suffix);
2632 if (direction != -1)
2633 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2635 return getHashEntry(helptext_info, token);
2638 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2640 int font_nr = FONT_INFO_ELEMENTS;
2641 int font_width = getFontWidth(font_nr);
2642 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2643 int sy = mSY + 65 + 2 * 32 + 1;
2644 int ystep = TILEY + 4;
2645 int pad_x = sx - SX;
2646 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2647 int max_lines_per_text = 2;
2650 if (action != -1 && direction != -1) /* element.action.direction */
2651 text = getHelpText(element, action, direction);
2653 if (text == NULL && action != -1) /* element.action */
2654 text = getHelpText(element, action, -1);
2656 if (text == NULL && direction != -1) /* element.direction */
2657 text = getHelpText(element, -1, direction);
2659 if (text == NULL) /* base element */
2660 text = getHelpText(element, -1, -1);
2662 if (text == NULL) /* not found */
2663 text = "No description available";
2665 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2666 sy += getFontHeight(font_nr) / 2;
2668 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2669 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2670 TRUE, FALSE, FALSE);
2673 void DrawInfoScreen_TitleScreen()
2678 void HandleInfoScreen_TitleScreen(int button)
2680 HandleTitleScreen(0, 0, 0, 0, button);
2683 void DrawInfoScreen_Elements()
2685 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2687 FadeOut(REDRAW_FIELD);
2692 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2694 FadeIn(REDRAW_FIELD);
2699 void HandleInfoScreen_Elements(int button)
2701 static unsigned int info_delay = 0;
2702 static int num_anims;
2703 static int num_pages;
2705 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2708 if (button == MB_MENU_INITIALIZE)
2710 boolean new_element = TRUE;
2714 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2716 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2718 else if (new_element)
2721 new_element = FALSE;
2725 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2729 if (button == MB_MENU_LEAVE)
2731 PlaySound(SND_MENU_ITEM_SELECTING);
2733 info_mode = INFO_MODE_MAIN;
2738 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2740 if (button != MB_MENU_INITIALIZE)
2742 PlaySound(SND_MENU_ITEM_SELECTING);
2747 if (page >= num_pages)
2749 FadeSoundsAndMusic();
2751 info_mode = INFO_MODE_MAIN;
2752 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2758 FadeSetNextScreen();
2760 if (button != MB_MENU_INITIALIZE)
2761 FadeOut(REDRAW_FIELD);
2763 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2765 if (button != MB_MENU_INITIALIZE)
2766 FadeIn(REDRAW_FIELD);
2770 if (DelayReached(&info_delay, GameFrameDelay))
2771 if (page < num_pages)
2772 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2774 PlayMenuSoundIfLoop();
2778 void DrawInfoScreen_Music()
2780 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2782 FadeOut(REDRAW_FIELD);
2789 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2791 FadeIn(REDRAW_FIELD);
2794 void HandleInfoScreen_Music(int button)
2796 static struct MusicFileInfo *list = NULL;
2797 int ystart1 = mSY - SY + 100;
2798 int ystart2 = mSY - SY + 150;
2799 int ybottom = mSY - SY + SYSIZE - 20;
2802 if (button == MB_MENU_INITIALIZE)
2804 list = music_file_info;
2808 FadeSoundsAndMusic();
2813 DrawTextSCentered(ystart1, FONT_TEXT_1,
2814 "No music info for this level set.");
2816 DrawTextSCentered(ybottom, FONT_TEXT_4,
2817 "Press any key or button for info menu");
2823 if (button == MB_MENU_LEAVE)
2825 PlaySound(SND_MENU_ITEM_SELECTING);
2827 FadeSoundsAndMusic();
2829 info_mode = INFO_MODE_MAIN;
2834 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2838 if (button != MB_MENU_INITIALIZE)
2840 PlaySound(SND_MENU_ITEM_SELECTING);
2848 FadeSoundsAndMusic();
2850 info_mode = INFO_MODE_MAIN;
2851 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2856 FadeSoundsAndMusic();
2858 if (list != music_file_info)
2859 FadeSetNextScreen();
2861 if (button != MB_MENU_INITIALIZE)
2862 FadeOut(REDRAW_FIELD);
2869 int sound = list->music;
2871 if (sound_info[sound].loop)
2872 PlaySoundLoop(sound);
2876 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2880 PlayMusic(list->music);
2882 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2885 if (!strEqual(list->title, UNKNOWN_NAME))
2887 if (!strEqual(list->title_header, UNKNOWN_NAME))
2888 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2890 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2893 if (!strEqual(list->artist, UNKNOWN_NAME))
2895 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2896 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2898 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2900 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2903 if (!strEqual(list->album, UNKNOWN_NAME))
2905 if (!strEqual(list->album_header, UNKNOWN_NAME))
2906 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2908 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2910 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2913 if (!strEqual(list->year, UNKNOWN_NAME))
2915 if (!strEqual(list->year_header, UNKNOWN_NAME))
2916 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2918 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2920 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2923 DrawTextSCentered(ybottom, FONT_TEXT_4,
2924 "Press any key or button for next page");
2926 if (button != MB_MENU_INITIALIZE)
2927 FadeIn(REDRAW_FIELD);
2930 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2931 PlaySoundLoop(list->music);
2934 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2936 int ystart1 = mSY - SY + 100;
2937 int ystart2 = mSY - SY + 150;
2938 int ybottom = mSY - SY + SYSIZE - 20;
2944 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2948 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2949 "Special thanks to");
2950 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2952 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2954 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2955 "\"Boulder Dash\"");
2956 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2958 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2960 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2962 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2963 "First Star Software");
2965 else if (screen_nr == 1)
2967 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2968 "Special thanks to");
2969 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2970 "Klaus Heinz & Volker Wertich");
2971 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2973 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2974 "\"Emerald Mine\"");
2975 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2977 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2979 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2981 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2984 else if (screen_nr == 2)
2986 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2987 "Special thanks to");
2988 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2989 "Michael Stopp & Philip Jespersen");
2990 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2992 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2994 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2996 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2998 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3000 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3001 "Digital Integration");
3003 else if (screen_nr == 3)
3005 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3006 "Special thanks to");
3007 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3008 "Hiroyuki Imabayashi");
3009 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3011 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3013 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3015 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3017 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3019 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
3022 else if (screen_nr == 4)
3024 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3025 "Special thanks to");
3026 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3028 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3030 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3031 "J\xfcrgen Bonhagen");
3032 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3033 "for the continuous creation");
3034 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3035 "of outstanding level sets");
3037 else if (screen_nr == 5)
3039 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3041 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3043 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3044 "for ideas and inspiration by");
3045 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3048 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
3050 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
3052 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3053 "for ideas and inspiration by");
3054 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
3057 else if (screen_nr == 6)
3059 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3061 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3064 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3065 "for the code base used for the");
3066 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
3067 "native Emerald Mine engine");
3069 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3070 "for the new Emerald Mine engine");
3073 else if (screen_nr == 7)
3075 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3077 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
3079 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
3080 "for the initial DOS port");
3082 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3084 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3086 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
3087 "for some additional toons");
3089 else if (screen_nr == 8)
3091 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3092 "And not to forget:");
3093 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3095 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3096 "All those who contributed");
3097 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
3098 "levels to this game");
3099 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
3103 DrawTextSCentered(ybottom, FONT_TEXT_4,
3104 "Press any key or button for next page");
3107 void DrawInfoScreen_Credits()
3109 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3111 FadeSoundsAndMusic();
3113 FadeOut(REDRAW_FIELD);
3115 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3117 FadeIn(REDRAW_FIELD);
3120 void HandleInfoScreen_Credits(int button)
3122 static int screen_nr = 0;
3123 int num_screens = 9;
3125 if (button == MB_MENU_INITIALIZE)
3129 // DrawInfoScreen_CreditsScreen(screen_nr);
3132 if (button == MB_MENU_LEAVE)
3134 PlaySound(SND_MENU_ITEM_SELECTING);
3136 info_mode = INFO_MODE_MAIN;
3141 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3143 if (button != MB_MENU_INITIALIZE)
3145 PlaySound(SND_MENU_ITEM_SELECTING);
3150 if (screen_nr >= num_screens)
3152 FadeSoundsAndMusic();
3154 info_mode = INFO_MODE_MAIN;
3155 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3161 FadeSetNextScreen();
3163 if (button != MB_MENU_INITIALIZE)
3164 FadeOut(REDRAW_FIELD);
3166 DrawInfoScreen_CreditsScreen(screen_nr);
3168 if (button != MB_MENU_INITIALIZE)
3169 FadeIn(REDRAW_FIELD);
3173 PlayMenuSoundIfLoop();
3177 void DrawInfoScreen_Program()
3179 int ystart1 = mSY - SY + 100;
3180 int ystart2 = mSY - SY + 150;
3181 int ybottom = mSY - SY + SYSIZE - 20;
3184 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3186 FadeOut(REDRAW_FIELD);
3191 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
3193 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
3194 "This game is Freeware!");
3195 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
3196 "If you like it, send e-mail to:");
3197 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
3198 setup.internal.program_email);
3199 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
3200 "More information and levels:");
3201 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
3202 setup.internal.program_website);
3203 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
3204 "If you have created new levels,");
3205 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
3206 "send them to me to include them!");
3207 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
3210 DrawTextSCentered(ybottom, FONT_TEXT_4,
3211 "Press any key or button for info menu");
3213 FadeIn(REDRAW_FIELD);
3216 void HandleInfoScreen_Program(int button)
3218 if (button == MB_MENU_LEAVE)
3220 PlaySound(SND_MENU_ITEM_SELECTING);
3222 info_mode = INFO_MODE_MAIN;
3227 else if (button == MB_MENU_CHOICE)
3229 PlaySound(SND_MENU_ITEM_SELECTING);
3231 FadeSoundsAndMusic();
3233 info_mode = INFO_MODE_MAIN;
3234 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3238 PlayMenuSoundIfLoop();
3242 void DrawInfoScreen_Version()
3244 int font_header = FONT_TEXT_3;
3245 int font_text = FONT_TEXT_2;
3246 int xstep = getFontWidth(font_text);
3247 int ystep = getFontHeight(font_text);
3248 int ystart1 = mSY - SY + 100;
3249 int ystart2 = mSY - SY + 150;
3250 int ybottom = mSY - SY + SYSIZE - 20;
3251 int xstart1 = mSX - SX + 2 * xstep;
3252 int xstart2 = mSX - SX + 18 * xstep;
3253 int xstart3 = mSX - SX + 28 * xstep;
3254 SDL_version sdl_version_compiled;
3255 const SDL_version *sdl_version_linked;
3256 int driver_name_len = 10;
3257 #if defined(TARGET_SDL2)
3258 SDL_version sdl_version_linked_ext;
3259 const char *driver_name = NULL;
3261 char driver_name[driver_name_len];
3264 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3266 FadeOut(REDRAW_FIELD);
3271 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
3273 DrawTextF(xstart1, ystart2, font_header, "Name");
3274 DrawTextF(xstart2, ystart2, font_text, getProgramTitleString());
3277 DrawTextF(xstart1, ystart2, font_header, "Version");
3278 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
3281 DrawTextF(xstart1, ystart2, font_header, "Platform");
3282 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
3285 DrawTextF(xstart1, ystart2, font_header, "Target");
3286 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
3289 DrawTextF(xstart1, ystart2, font_header, "Compile time");
3290 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
3292 ystart2 += 3 * ystep;
3293 DrawTextF(xstart1, ystart2, font_header, "Library");
3294 DrawTextF(xstart2, ystart2, font_header, "compiled");
3295 DrawTextF(xstart3, ystart2, font_header, "linked");
3297 SDL_VERSION(&sdl_version_compiled);
3298 #if defined(TARGET_SDL2)
3299 SDL_GetVersion(&sdl_version_linked_ext);
3300 sdl_version_linked = &sdl_version_linked_ext;
3302 sdl_version_linked = SDL_Linked_Version();
3305 ystart2 += 2 * ystep;
3306 DrawTextF(xstart1, ystart2, font_text, "SDL");
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_IMAGE_VERSION(&sdl_version_compiled);
3317 sdl_version_linked = IMG_Linked_Version();
3320 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
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 SDL_MIXER_VERSION(&sdl_version_compiled);
3331 sdl_version_linked = Mix_Linked_Version();
3334 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
3335 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3336 sdl_version_compiled.major,
3337 sdl_version_compiled.minor,
3338 sdl_version_compiled.patch);
3339 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3340 sdl_version_linked->major,
3341 sdl_version_linked->minor,
3342 sdl_version_linked->patch);
3344 SDL_NET_VERSION(&sdl_version_compiled);
3345 sdl_version_linked = SDLNet_Linked_Version();
3348 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3349 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3350 sdl_version_compiled.major,
3351 sdl_version_compiled.minor,
3352 sdl_version_compiled.patch);
3353 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3354 sdl_version_linked->major,
3355 sdl_version_linked->minor,
3356 sdl_version_linked->patch);
3358 ystart2 += 3 * ystep;
3359 DrawTextF(xstart1, ystart2, font_header, "Driver");
3360 DrawTextF(xstart2, ystart2, font_header, "Requested");
3361 DrawTextF(xstart3, ystart2, font_header, "Used");
3363 #if defined(TARGET_SDL2)
3364 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3366 SDL_VideoDriverName(driver_name, driver_name_len);
3369 ystart2 += 2 * ystep;
3370 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3371 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3372 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3374 #if defined(TARGET_SDL2)
3375 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3377 SDL_AudioDriverName(driver_name, driver_name_len);
3381 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3382 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3383 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3385 DrawTextSCentered(ybottom, FONT_TEXT_4,
3386 "Press any key or button for info menu");
3388 FadeIn(REDRAW_FIELD);
3391 void HandleInfoScreen_Version(int button)
3393 if (button == MB_MENU_LEAVE)
3395 PlaySound(SND_MENU_ITEM_SELECTING);
3397 info_mode = INFO_MODE_MAIN;
3402 else if (button == MB_MENU_CHOICE)
3404 PlaySound(SND_MENU_ITEM_SELECTING);
3406 FadeSoundsAndMusic();
3408 info_mode = INFO_MODE_MAIN;
3409 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3413 PlayMenuSoundIfLoop();
3417 void DrawInfoScreen_LevelSet()
3419 struct TitleMessageInfo *tmi = &readme;
3420 char *filename = getLevelSetInfoFilename();
3421 char *title = "Level Set Information:";
3422 int ystart1 = mSY - SY + 100;
3423 int ybottom = mSY - SY + SYSIZE - 20;
3425 if (filename == NULL)
3427 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3432 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3434 FadeOut(REDRAW_FIELD);
3439 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3441 /* if x position set to "-1", automatically determine by playfield width */
3443 tmi->x = SXSIZE / 2;
3445 /* if y position set to "-1", use static default value */
3449 /* if width set to "-1", automatically determine by playfield width */
3450 if (tmi->width == -1)
3451 tmi->width = SXSIZE - 2 * TILEX;
3453 /* if height set to "-1", automatically determine by playfield height */
3454 if (tmi->height == -1)
3455 tmi->height = SYSIZE - 20 - tmi->y - 10;
3457 /* if chars set to "-1", automatically determine by text and font width */
3458 if (tmi->chars == -1)
3459 tmi->chars = tmi->width / getFontWidth(tmi->font);
3461 tmi->width = tmi->chars * getFontWidth(tmi->font);
3463 /* if lines set to "-1", automatically determine by text and font height */
3464 if (tmi->lines == -1)
3465 tmi->lines = tmi->height / getFontHeight(tmi->font);
3467 tmi->height = tmi->lines * getFontHeight(tmi->font);
3469 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3470 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3471 tmi->autowrap, tmi->centered, tmi->parse_comments);
3473 DrawTextSCentered(ybottom, FONT_TEXT_4,
3474 "Press any key or button for info menu");
3476 FadeIn(REDRAW_FIELD);
3479 void HandleInfoScreen_LevelSet(int button)
3481 if (button == MB_MENU_LEAVE)
3483 PlaySound(SND_MENU_ITEM_SELECTING);
3485 info_mode = INFO_MODE_MAIN;
3490 else if (button == MB_MENU_CHOICE)
3492 PlaySound(SND_MENU_ITEM_SELECTING);
3494 FadeSoundsAndMusic();
3496 info_mode = INFO_MODE_MAIN;
3497 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3501 PlayMenuSoundIfLoop();
3505 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3507 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3509 if (info_mode == INFO_MODE_TITLE)
3510 DrawInfoScreen_TitleScreen();
3511 else if (info_mode == INFO_MODE_ELEMENTS)
3512 DrawInfoScreen_Elements();
3513 else if (info_mode == INFO_MODE_MUSIC)
3514 DrawInfoScreen_Music();
3515 else if (info_mode == INFO_MODE_CREDITS)
3516 DrawInfoScreen_Credits();
3517 else if (info_mode == INFO_MODE_PROGRAM)
3518 DrawInfoScreen_Program();
3519 else if (info_mode == INFO_MODE_VERSION)
3520 DrawInfoScreen_Version();
3521 else if (info_mode == INFO_MODE_LEVELSET)
3522 DrawInfoScreen_LevelSet();
3524 DrawInfoScreen_Main(fade_mask, do_fading);
3526 if (info_mode != INFO_MODE_MAIN &&
3527 info_mode != INFO_MODE_TITLE &&
3528 info_mode != INFO_MODE_MUSIC)
3535 void DrawAndFadeInInfoScreen(int fade_mask)
3537 DrawInfoScreenExt(fade_mask, TRUE);
3540 void DrawInfoScreen()
3542 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3545 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3547 if (info_mode == INFO_MODE_TITLE)
3548 HandleInfoScreen_TitleScreen(button);
3549 else if (info_mode == INFO_MODE_ELEMENTS)
3550 HandleInfoScreen_Elements(button);
3551 else if (info_mode == INFO_MODE_MUSIC)
3552 HandleInfoScreen_Music(button);
3553 else if (info_mode == INFO_MODE_CREDITS)
3554 HandleInfoScreen_Credits(button);
3555 else if (info_mode == INFO_MODE_PROGRAM)
3556 HandleInfoScreen_Program(button);
3557 else if (info_mode == INFO_MODE_VERSION)
3558 HandleInfoScreen_Version(button);
3559 else if (info_mode == INFO_MODE_LEVELSET)
3560 HandleInfoScreen_LevelSet(button);
3562 HandleInfoScreen_Main(mx, my, dx, dy, button);
3566 /* ========================================================================= */
3567 /* type name functions */
3568 /* ========================================================================= */
3570 void HandleTypeName(int newxpos, Key key)
3572 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3573 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3574 struct TextPosInfo *pos = mci->pos_input;
3575 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3576 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3577 static int xpos = 0;
3578 int font_nr = pos->font;
3579 int font_active_nr = FONT_ACTIVE(font_nr);
3580 int font_width = getFontWidth(font_active_nr);
3581 char key_char = getValidConfigValueChar(getCharFromKey(key));
3582 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3583 boolean is_active = TRUE;
3585 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3589 strcpy(last_player_name, setup.player_name);
3593 #if defined(TARGET_SDL2)
3594 SDL_StartTextInput();
3597 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3599 setup.player_name[xpos] = key_char;
3600 setup.player_name[xpos + 1] = 0;
3604 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3608 setup.player_name[xpos] = 0;
3610 else if (key == KSYM_Return && xpos > 0)
3616 game_status = GAME_MODE_MAIN;
3618 else if (key == KSYM_Escape)
3620 strcpy(setup.player_name, last_player_name);
3624 game_status = GAME_MODE_MAIN;
3629 pos->width = (strlen(setup.player_name) + 1) * font_width;
3630 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3632 DrawText(startx, starty, setup.player_name, font_active_nr);
3633 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3637 pos->width = strlen(setup.player_name) * font_width;
3638 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3640 DrawText(startx, starty, setup.player_name, font_nr);
3642 #if defined(TARGET_SDL2)
3643 SDL_StopTextInput();
3649 /* ========================================================================= */
3650 /* tree menu functions */
3651 /* ========================================================================= */
3653 static void DrawChooseTree(TreeInfo **ti_ptr)
3655 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3657 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3659 game_status = GAME_MODE_MAIN;
3661 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3668 FreeScreenGadgets();
3669 CreateScreenGadgets();
3671 CloseDoor(DOOR_CLOSE_2);
3677 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3678 MapScreenTreeGadgets(*ti_ptr);
3685 static void drawChooseTreeList(int first_entry, int num_page_entries,
3689 char *title_string = NULL;
3690 int yoffset_sets = MENU_TITLE1_YPOS;
3691 int yoffset_setup = 16;
3692 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3693 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3694 int last_game_status = game_status; /* save current game status */
3696 title_string = ti->infotext;
3698 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3700 clearMenuListArea();
3702 for (i = 0; i < num_page_entries; i++)
3704 TreeInfo *node, *node_first;
3705 int entry_pos = first_entry + i;
3706 int xpos = MENU_SCREEN_START_XPOS;
3707 int ypos = MENU_SCREEN_START_YPOS + i;
3708 int startx = mSX + xpos * 32;
3709 int starty = mSY + ypos * 32;
3710 int font_nr = FONT_TEXT_1;
3711 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3712 int startx_text = startx + font_xoffset;
3713 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3714 int text_size = startx_scrollbar - startx_text;
3715 int max_buffer_len = text_size / getFontWidth(font_nr);
3716 char buffer[max_buffer_len + 1];
3718 node_first = getTreeInfoFirstGroupEntry(ti);
3719 node = getTreeInfoFromPos(node_first, entry_pos);
3721 strncpy(buffer, node->name, max_buffer_len);
3722 buffer[max_buffer_len] = '\0';
3724 DrawText(startx, starty, buffer, font_nr + node->color);
3726 if (node->parent_link)
3727 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3728 else if (node->level_group)
3729 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3731 initCursor(i, IMG_MENU_BUTTON);
3734 game_status = last_game_status; /* restore current game status */
3736 redraw_mask |= REDRAW_FIELD;
3739 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3741 TreeInfo *node, *node_first;
3742 int x, last_redraw_mask = redraw_mask;
3743 int ypos = MENU_TITLE2_YPOS;
3744 int font_nr = FONT_TITLE_2;
3746 if (ti->type == TREE_TYPE_LEVEL_NR)
3747 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3749 if (ti->type != TREE_TYPE_LEVEL_DIR)
3752 node_first = getTreeInfoFirstGroupEntry(ti);
3753 node = getTreeInfoFromPos(node_first, entry_pos);
3755 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3757 if (node->parent_link)
3758 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3759 node->node_parent->name);
3760 else if (node->level_group)
3761 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3763 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3764 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3765 node->levels, (node->levels > 1 ? "levels" : "level"),
3768 /* let BackToFront() redraw only what is needed */
3769 redraw_mask = last_redraw_mask;
3770 for (x = 0; x < SCR_FIELDX; x++)
3771 MarkTileDirty(x, 1);
3774 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3777 TreeInfo *ti = *ti_ptr;
3779 int y = ti->cl_cursor;
3780 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3781 int num_entries = numTreeInfoInGroup(ti);
3782 int num_page_entries;
3783 int last_game_status = game_status; /* save current game status */
3784 boolean position_set_by_scrollbar = (dx == 999);
3786 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3787 num_page_entries = num_entries;
3789 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3791 game_status = last_game_status; /* restore current game status */
3793 if (button == MB_MENU_INITIALIZE)
3795 int num_entries = numTreeInfoInGroup(ti);
3796 int entry_pos = posTreeInfo(ti);
3798 if (ti->cl_first == -1)
3800 /* only on initialization */
3801 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3802 ti->cl_cursor = entry_pos - ti->cl_first;
3804 else if (ti->cl_cursor >= num_page_entries ||
3805 (num_entries > num_page_entries &&
3806 num_entries - ti->cl_first < num_page_entries))
3808 /* only after change of list size (by custom graphic configuration) */
3809 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3810 ti->cl_cursor = entry_pos - ti->cl_first;
3813 if (position_set_by_scrollbar)
3816 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3819 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3820 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3821 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3825 else if (button == MB_MENU_LEAVE)
3829 PlaySound(SND_MENU_ITEM_SELECTING);
3831 if (ti->node_parent)
3833 *ti_ptr = ti->node_parent;
3834 DrawChooseTree(ti_ptr);
3836 else if (game_status == GAME_MODE_SETUP)
3838 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3839 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3840 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3842 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3843 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3844 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3845 execSetupGraphics();
3846 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3847 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3848 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3850 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3851 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3852 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3859 if (game_status == GAME_MODE_LEVELNR)
3861 int new_level_nr = atoi(level_number_current->identifier);
3863 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3866 game_status = GAME_MODE_MAIN;
3868 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3874 if (mx || my) /* mouse input */
3876 int last_game_status = game_status; /* save current game status */
3878 x = (mx - mSX) / 32;
3879 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3881 game_status = last_game_status; /* restore current game status */
3883 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3885 /* move cursor instead of scrolling when already at start/end of list */
3886 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3888 else if (dy == +1 * SCROLL_LINE &&
3889 ti->cl_first + num_page_entries == num_entries)
3892 /* handle scrolling screen one line or page */
3893 if (ti->cl_cursor + dy < 0 ||
3894 ti->cl_cursor + dy > num_page_entries - 1)
3896 boolean redraw = FALSE;
3898 if (ABS(dy) == SCROLL_PAGE)
3899 step = num_page_entries - 1;
3901 if (dy < 0 && ti->cl_first > 0)
3903 /* scroll page/line up */
3905 ti->cl_first -= step;
3906 if (ti->cl_first < 0)
3911 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3913 /* scroll page/line down */
3915 ti->cl_first += step;
3916 if (ti->cl_first + num_page_entries > num_entries)
3917 ti->cl_first = MAX(0, num_entries - num_page_entries);
3924 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3925 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3926 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3928 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3935 /* handle moving cursor one line */
3936 y = ti->cl_cursor + dy;
3941 TreeInfo *node_first, *node_cursor;
3942 int entry_pos = ti->cl_first + y;
3944 node_first = getTreeInfoFirstGroupEntry(ti);
3945 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3947 if (node_cursor->node_group)
3951 PlaySound(SND_MENU_ITEM_SELECTING);
3953 node_cursor->cl_first = ti->cl_first;
3954 node_cursor->cl_cursor = ti->cl_cursor;
3955 *ti_ptr = node_cursor->node_group;
3956 DrawChooseTree(ti_ptr);
3961 else if (dx == -1 && ti->node_parent)
3965 PlaySound(SND_MENU_ITEM_SELECTING);
3967 *ti_ptr = ti->node_parent;
3968 DrawChooseTree(ti_ptr);
3973 if (!anyScrollbarGadgetActive() &&
3974 IN_VIS_MENU(x, y) &&
3975 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3976 y >= 0 && y < num_page_entries)
3980 if (y != ti->cl_cursor)
3982 PlaySound(SND_MENU_ITEM_ACTIVATING);
3984 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3985 drawChooseTreeCursor(y, TRUE);
3986 drawChooseTreeInfo(ti->cl_first + y, ti);
3993 TreeInfo *node_first, *node_cursor;
3994 int entry_pos = ti->cl_first + y;
3996 PlaySound(SND_MENU_ITEM_SELECTING);
3998 node_first = getTreeInfoFirstGroupEntry(ti);
3999 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4001 if (node_cursor->node_group)
4005 node_cursor->cl_first = ti->cl_first;
4006 node_cursor->cl_cursor = ti->cl_cursor;
4007 *ti_ptr = node_cursor->node_group;
4008 DrawChooseTree(ti_ptr);
4010 else if (node_cursor->parent_link)
4014 *ti_ptr = node_cursor->node_parent;
4015 DrawChooseTree(ti_ptr);
4021 node_cursor->cl_first = ti->cl_first;
4022 node_cursor->cl_cursor = ti->cl_cursor;
4023 *ti_ptr = node_cursor;
4025 if (ti->type == TREE_TYPE_LEVEL_DIR)
4027 LoadLevelSetup_SeriesInfo();
4029 SaveLevelSetup_LastSeries();
4030 SaveLevelSetup_SeriesInfo();
4034 if (game_status == GAME_MODE_SETUP)
4036 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4037 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4038 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4040 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
4041 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4042 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
4043 execSetupGraphics();
4044 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4045 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4046 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4048 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4049 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4050 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
4057 if (game_status == GAME_MODE_LEVELNR)
4059 int new_level_nr = atoi(level_number_current->identifier);
4061 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4064 game_status = GAME_MODE_MAIN;
4073 void DrawChooseLevelSet()
4075 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4077 DrawChooseTree(&leveldir_current);
4083 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4085 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4088 void DrawChooseLevelNr()
4092 if (level_number != NULL)
4094 freeTreeInfo(level_number);
4096 level_number = NULL;
4099 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4101 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4102 char identifier[32], name[32];
4105 /* temporarily load level info to get level name */
4106 LoadLevelInfoOnly(i);
4108 ti->node_top = &level_number;
4109 ti->sort_priority = 10000 + value;
4110 ti->color = (level.no_valid_file ? FC_BLUE :
4111 LevelStats_getSolved(i) ? FC_GREEN :
4112 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4114 sprintf(identifier, "%d", value);
4115 sprintf(name, "%03d: %s", value,
4116 (level.no_valid_file ? "(no file)" : level.name));
4118 setString(&ti->identifier, identifier);
4119 setString(&ti->name, name);
4120 setString(&ti->name_sorting, name);
4122 pushTreeInfo(&level_number, ti);
4125 /* sort level number values to start with lowest level number */
4126 sortTreeInfo(&level_number);
4128 /* set current level number to current level number */
4129 level_number_current =
4130 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4132 /* if that also fails, set current level number to first available level */
4133 if (level_number_current == NULL)
4134 level_number_current = level_number;
4136 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4138 DrawChooseTree(&level_number_current);
4144 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4146 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4149 void DrawHallOfFame(int highlight_position)
4151 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
4154 FadeSoundsAndMusic();
4156 /* (this is needed when called from GameEnd() after winning a game) */
4157 KeyboardAutoRepeatOn();
4160 /* (this is needed when called from GameEnd() after winning a game) */
4161 SetDrawDeactivationMask(REDRAW_NONE);
4162 SetDrawBackgroundMask(REDRAW_FIELD);
4164 CloseDoor(DOOR_CLOSE_ALL);
4166 if (highlight_position < 0)
4167 LoadScore(level_nr);
4169 FadeSetEnterScreen();
4178 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4183 static void drawHallOfFameList(int first_entry, int highlight_position)
4187 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4190 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4191 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4192 "HighScores of Level %d", level_nr);
4194 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4196 int entry = first_entry + i;
4197 boolean active = (entry == highlight_position);
4198 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4199 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4200 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4201 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4202 int dx1 = 3 * getFontWidth(font_nr1);
4203 int dx2 = dx1 + getFontWidth(font_nr1);
4204 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
4205 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4206 int sy = mSY + 64 + i * 32;
4208 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4209 DrawText(mSX + dx1, sy, ".", font_nr1);
4211 for (j = 0; j < num_dots; j++)
4212 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4214 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4215 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4217 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4220 redraw_mask |= REDRAW_FIELD;
4223 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4225 static int first_entry = 0;
4226 static int highlight_position = 0;
4227 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4229 if (button == MB_MENU_INITIALIZE)
4232 highlight_position = mx;
4233 drawHallOfFameList(first_entry, highlight_position);
4238 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4239 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4243 if (first_entry > 0)
4245 first_entry -= step;
4246 if (first_entry < 0)
4249 drawHallOfFameList(first_entry, highlight_position);
4254 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4256 first_entry += step;
4257 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4258 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4260 drawHallOfFameList(first_entry, highlight_position);
4263 else if (button == MB_MENU_LEAVE)
4265 PlaySound(SND_MENU_ITEM_SELECTING);
4267 FadeSound(SND_BACKGROUND_SCORES);
4269 game_status = GAME_MODE_MAIN;
4273 else if (button == MB_MENU_CHOICE)
4275 PlaySound(SND_MENU_ITEM_SELECTING);
4277 FadeSound(SND_BACKGROUND_SCORES);
4279 game_status = GAME_MODE_MAIN;
4281 DrawAndFadeInMainMenu(REDRAW_FIELD);
4284 if (game_status == GAME_MODE_SCORES)
4285 PlayMenuSoundIfLoop();
4289 /* ========================================================================= */
4290 /* setup screen functions */
4291 /* ========================================================================= */
4293 static struct TokenInfo *setup_info;
4294 static int num_setup_info; /* number of setup entries shown on screen */
4295 static int max_setup_info; /* total number of setup entries in list */
4297 static char *screen_mode_text;
4298 static char *window_size_text;
4299 static char *scaling_type_text;
4300 static char *scroll_delay_text;
4301 static char *snapshot_mode_text;
4302 static char *game_speed_text;
4303 static char *graphics_set_name;
4304 static char *sounds_set_name;
4305 static char *music_set_name;
4306 static char *volume_simple_text;
4307 static char *volume_loops_text;
4308 static char *volume_music_text;
4309 static char *touch_controls_text;
4310 static char *move_distance_text;
4311 static char *drop_distance_text;
4313 static void execSetupMain()
4315 setup_mode = SETUP_MODE_MAIN;
4320 static void execSetupGame_setGameSpeeds()
4322 if (game_speeds == NULL)
4326 for (i = 0; game_speeds_list[i].value != -1; i++)
4328 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4329 char identifier[32], name[32];
4330 int value = game_speeds_list[i].value;
4331 char *text = game_speeds_list[i].text;
4333 ti->node_top = &game_speeds;
4334 ti->sort_priority = 10000 - value;
4336 sprintf(identifier, "%d", value);
4337 sprintf(name, "%s", text);
4339 setString(&ti->identifier, identifier);
4340 setString(&ti->name, name);
4341 setString(&ti->name_sorting, name);
4342 setString(&ti->infotext, "Game Speed");
4344 pushTreeInfo(&game_speeds, ti);
4347 /* sort game speed values to start with slowest game speed */
4348 sortTreeInfo(&game_speeds);
4350 /* set current game speed to configured game speed value */
4351 game_speed_current =
4352 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4354 /* if that fails, set current game speed to reliable default value */
4355 if (game_speed_current == NULL)
4356 game_speed_current =
4357 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4359 /* if that also fails, set current game speed to first available speed */
4360 if (game_speed_current == NULL)
4361 game_speed_current = game_speeds;
4364 setup.game_frame_delay = atoi(game_speed_current->identifier);
4366 /* needed for displaying game speed text instead of identifier */
4367 game_speed_text = game_speed_current->name;
4370 static void execSetupGame_setScrollDelays()
4372 if (scroll_delays == NULL)
4376 for (i = 0; scroll_delays_list[i].value != -1; i++)
4378 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4379 char identifier[32], name[32];
4380 int value = scroll_delays_list[i].value;
4381 char *text = scroll_delays_list[i].text;
4383 ti->node_top = &scroll_delays;
4384 ti->sort_priority = value;
4386 sprintf(identifier, "%d", value);
4387 sprintf(name, "%s", text);
4389 setString(&ti->identifier, identifier);
4390 setString(&ti->name, name);
4391 setString(&ti->name_sorting, name);
4392 setString(&ti->infotext, "Scaling Type");
4394 pushTreeInfo(&scroll_delays, ti);
4397 /* sort scaling type values to start with lowest scaling type value */
4398 sortTreeInfo(&scroll_delays);
4400 /* set current scaling type value to configured scaling type value */
4401 scroll_delay_current =
4402 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4404 /* if that fails, set current scaling type to reliable default value */
4405 if (scroll_delay_current == NULL)
4406 scroll_delay_current =
4407 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4409 /* if that also fails, set current scaling type to first available value */
4410 if (scroll_delay_current == NULL)
4411 scroll_delay_current = scroll_delays;
4414 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4416 /* needed for displaying scaling type text instead of identifier */
4417 scroll_delay_text = scroll_delay_current->name;
4420 static void execSetupGame_setSnapshotModes()
4422 if (snapshot_modes == NULL)
4426 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4428 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4429 char identifier[32], name[32];
4430 char *value = snapshot_modes_list[i].value;
4431 char *text = snapshot_modes_list[i].text;
4433 ti->node_top = &snapshot_modes;
4434 ti->sort_priority = i;
4436 sprintf(identifier, "%s", value);
4437 sprintf(name, "%s", text);
4439 setString(&ti->identifier, identifier);
4440 setString(&ti->name, name);
4441 setString(&ti->name_sorting, name);
4442 setString(&ti->infotext, "Snapshot Mode");
4444 pushTreeInfo(&snapshot_modes, ti);
4447 /* sort snapshot mode values to start with lowest snapshot mode value */
4448 sortTreeInfo(&snapshot_modes);
4450 /* set current snapshot mode value to configured snapshot mode value */
4451 snapshot_mode_current =
4452 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4454 /* if that fails, set current snapshot mode to reliable default value */
4455 if (snapshot_mode_current == NULL)
4456 snapshot_mode_current =
4457 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4459 /* if that also fails, set current snapshot mode to first available value */
4460 if (snapshot_mode_current == NULL)
4461 snapshot_mode_current = snapshot_modes;
4464 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4466 /* needed for displaying snapshot mode text instead of identifier */
4467 snapshot_mode_text = snapshot_mode_current->name;
4470 static void execSetupGame()
4472 execSetupGame_setGameSpeeds();
4473 execSetupGame_setScrollDelays();
4474 execSetupGame_setSnapshotModes();
4476 setup_mode = SETUP_MODE_GAME;
4481 static void execSetupChooseGameSpeed()
4483 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4488 static void execSetupChooseScrollDelay()
4490 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4495 static void execSetupChooseSnapshotMode()
4497 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4502 static void execSetupEditor()
4504 setup_mode = SETUP_MODE_EDITOR;
4509 static void execSetupGraphics_setWindowSizes(boolean update_list)
4511 if (window_sizes != NULL && update_list)
4513 freeTreeInfo(window_sizes);
4515 window_sizes = NULL;
4518 if (window_sizes == NULL)
4520 boolean current_window_size_found = FALSE;
4523 for (i = 0; window_sizes_list[i].value != -1; i++)
4525 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4526 char identifier[32], name[32];
4527 int value = window_sizes_list[i].value;
4528 char *text = window_sizes_list[i].text;
4530 ti->node_top = &window_sizes;
4531 ti->sort_priority = value;
4533 sprintf(identifier, "%d", value);
4534 sprintf(name, "%s", text);
4536 setString(&ti->identifier, identifier);
4537 setString(&ti->name, name);
4538 setString(&ti->name_sorting, name);
4539 setString(&ti->infotext, "Window Scaling");
4541 pushTreeInfo(&window_sizes, ti);
4543 if (value == setup.window_scaling_percent)
4544 current_window_size_found = TRUE;
4547 if (!current_window_size_found)
4549 // add entry for non-preset window scaling value
4551 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4552 char identifier[32], name[32];
4553 int value = setup.window_scaling_percent;
4555 ti->node_top = &window_sizes;
4556 ti->sort_priority = value;
4558 sprintf(identifier, "%d", value);
4559 sprintf(name, "%d %% (Current)", value);
4561 setString(&ti->identifier, identifier);
4562 setString(&ti->name, name);
4563 setString(&ti->name_sorting, name);
4564 setString(&ti->infotext, "Window Scaling");
4566 pushTreeInfo(&window_sizes, ti);
4569 /* sort window size values to start with lowest window size value */
4570 sortTreeInfo(&window_sizes);
4572 /* set current window size value to configured window size value */
4573 window_size_current =
4574 getTreeInfoFromIdentifier(window_sizes,
4575 i_to_a(setup.window_scaling_percent));
4577 /* if that fails, set current window size to reliable default value */
4578 if (window_size_current == NULL)
4579 window_size_current =
4580 getTreeInfoFromIdentifier(window_sizes,
4581 i_to_a(STD_WINDOW_SCALING_PERCENT));
4583 /* if that also fails, set current window size to first available value */
4584 if (window_size_current == NULL)
4585 window_size_current = window_sizes;
4588 setup.window_scaling_percent = atoi(window_size_current->identifier);
4590 /* needed for displaying window size text instead of identifier */
4591 window_size_text = window_size_current->name;
4594 static void execSetupGraphics_setScalingTypes()
4596 if (scaling_types == NULL)
4600 for (i = 0; scaling_types_list[i].value != NULL; i++)
4602 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4603 char identifier[32], name[32];
4604 char *value = scaling_types_list[i].value;
4605 char *text = scaling_types_list[i].text;
4607 ti->node_top = &scaling_types;
4608 ti->sort_priority = i;
4610 sprintf(identifier, "%s", value);
4611 sprintf(name, "%s", text);
4613 setString(&ti->identifier, identifier);
4614 setString(&ti->name, name);
4615 setString(&ti->name_sorting, name);
4616 setString(&ti->infotext, "Anti-Aliasing");
4618 pushTreeInfo(&scaling_types, ti);
4621 /* sort scaling type values to start with lowest scaling type value */
4622 sortTreeInfo(&scaling_types);
4624 /* set current scaling type value to configured scaling type value */
4625 scaling_type_current =
4626 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4628 /* if that fails, set current scaling type to reliable default value */
4629 if (scaling_type_current == NULL)
4630 scaling_type_current =
4631 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4633 /* if that also fails, set current scaling type to first available value */
4634 if (scaling_type_current == NULL)
4635 scaling_type_current = scaling_types;
4638 setup.window_scaling_quality = scaling_type_current->identifier;
4640 /* needed for displaying scaling type text instead of identifier */
4641 scaling_type_text = scaling_type_current->name;
4644 static void execSetupGraphics_setScreenModes()
4646 // if (screen_modes == NULL && video.fullscreen_available)
4647 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4651 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4653 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4654 char identifier[32], name[32];
4655 int x = video.fullscreen_modes[i].width;
4656 int y = video.fullscreen_modes[i].height;
4659 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4661 ti->node_top = &screen_modes;
4662 ti->sort_priority = x * 10000 + y;
4664 sprintf(identifier, "%dx%d", x, y);
4665 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4667 setString(&ti->identifier, identifier);
4668 setString(&ti->name, name);
4669 setString(&ti->name_sorting, name);
4670 setString(&ti->infotext, "Fullscreen Mode");
4672 pushTreeInfo(&screen_modes, ti);
4675 /* sort fullscreen modes to start with lowest available screen resolution */
4676 sortTreeInfo(&screen_modes);
4678 /* set current screen mode for fullscreen mode to configured setup value */
4679 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4680 setup.fullscreen_mode);
4682 /* if that fails, set current screen mode to reliable default value */
4683 if (screen_mode_current == NULL)
4684 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4685 DEFAULT_FULLSCREEN_MODE);
4687 /* if that also fails, set current screen mode to first available mode */
4688 if (screen_mode_current == NULL)
4689 screen_mode_current = screen_modes;
4691 if (screen_mode_current == NULL)
4692 video.fullscreen_available = FALSE;
4695 // if (video.fullscreen_available)
4696 if (screen_mode_current != NULL)
4698 setup.fullscreen_mode = screen_mode_current->identifier;
4700 /* needed for displaying screen mode name instead of identifier */
4701 screen_mode_text = screen_mode_current->name;
4705 static void execSetupGraphics()
4707 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4709 // update "setup.window_scaling_percent" from list selection
4710 execSetupGraphics_setWindowSizes(FALSE);
4714 // update list selection from "setup.window_scaling_percent"
4715 execSetupGraphics_setWindowSizes(TRUE);
4718 execSetupGraphics_setScalingTypes();
4719 execSetupGraphics_setScreenModes();
4721 setup_mode = SETUP_MODE_GRAPHICS;
4725 #if defined(TARGET_SDL2)
4726 // window scaling may have changed at this point
4727 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4729 // window scaling quality may have changed at this point
4730 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4731 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4735 #if !defined(PLATFORM_ANDROID)
4736 #if defined(TARGET_SDL2)
4737 static void execSetupChooseWindowSize()
4739 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4744 static void execSetupChooseScalingType()
4746 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4751 static void execSetupChooseScreenMode()
4753 if (!video.fullscreen_available)
4756 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4763 static void execSetupChooseVolumeSimple()
4765 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4770 static void execSetupChooseVolumeLoops()
4772 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4777 static void execSetupChooseVolumeMusic()
4779 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4784 static void execSetupSound()
4786 if (volumes_simple == NULL)
4788 boolean current_volume_simple_found = FALSE;
4791 for (i = 0; volumes_list[i].value != -1; i++)
4793 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4794 char identifier[32], name[32];
4795 int value = volumes_list[i].value;
4796 char *text = volumes_list[i].text;
4798 ti->node_top = &volumes_simple;
4799 ti->sort_priority = value;
4801 sprintf(identifier, "%d", value);
4802 sprintf(name, "%s", text);
4804 setString(&ti->identifier, identifier);
4805 setString(&ti->name, name);
4806 setString(&ti->name_sorting, name);
4807 setString(&ti->infotext, "Sound Volume");
4809 pushTreeInfo(&volumes_simple, ti);
4811 if (value == setup.volume_simple)
4812 current_volume_simple_found = TRUE;
4815 if (!current_volume_simple_found)
4817 // add entry for non-preset volume value
4819 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4820 char identifier[32], name[32];
4821 int value = setup.volume_simple;
4823 ti->node_top = &volumes_simple;
4824 ti->sort_priority = value;
4826 sprintf(identifier, "%d", value);
4827 sprintf(name, "%d %% (Current)", value);
4829 setString(&ti->identifier, identifier);
4830 setString(&ti->name, name);
4831 setString(&ti->name_sorting, name);
4832 setString(&ti->infotext, "Sound Volume");
4834 pushTreeInfo(&volumes_simple, ti);
4837 /* sort volume values to start with lowest volume value */
4838 sortTreeInfo(&volumes_simple);
4840 /* set current volume value to configured volume value */
4841 volume_simple_current =
4842 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4844 /* if that fails, set current volume to reliable default value */
4845 if (volume_simple_current == NULL)
4846 volume_simple_current =
4847 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4849 /* if that also fails, set current volume to first available value */
4850 if (volume_simple_current == NULL)
4851 volume_simple_current = volumes_simple;
4854 if (volumes_loops == NULL)
4856 boolean current_volume_loops_found = FALSE;
4859 for (i = 0; volumes_list[i].value != -1; i++)
4861 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4862 char identifier[32], name[32];
4863 int value = volumes_list[i].value;
4864 char *text = volumes_list[i].text;
4866 ti->node_top = &volumes_loops;
4867 ti->sort_priority = value;
4869 sprintf(identifier, "%d", value);
4870 sprintf(name, "%s", text);
4872 setString(&ti->identifier, identifier);
4873 setString(&ti->name, name);
4874 setString(&ti->name_sorting, name);
4875 setString(&ti->infotext, "Loops Volume");
4877 pushTreeInfo(&volumes_loops, ti);
4879 if (value == setup.volume_loops)
4880 current_volume_loops_found = TRUE;
4883 if (!current_volume_loops_found)
4885 // add entry for non-preset volume value
4887 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4888 char identifier[32], name[32];
4889 int value = setup.volume_loops;
4891 ti->node_top = &volumes_loops;
4892 ti->sort_priority = value;
4894 sprintf(identifier, "%d", value);
4895 sprintf(name, "%d %% (Current)", value);
4897 setString(&ti->identifier, identifier);
4898 setString(&ti->name, name);
4899 setString(&ti->name_sorting, name);
4900 setString(&ti->infotext, "Loops Volume");
4902 pushTreeInfo(&volumes_loops, ti);
4905 /* sort volume values to start with lowest volume value */
4906 sortTreeInfo(&volumes_loops);
4908 /* set current volume value to configured volume value */
4909 volume_loops_current =
4910 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4912 /* if that fails, set current volume to reliable default value */
4913 if (volume_loops_current == NULL)
4914 volume_loops_current =
4915 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4917 /* if that also fails, set current volume to first available value */
4918 if (volume_loops_current == NULL)
4919 volume_loops_current = volumes_loops;
4922 if (volumes_music == NULL)
4924 boolean current_volume_music_found = FALSE;
4927 for (i = 0; volumes_list[i].value != -1; i++)
4929 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4930 char identifier[32], name[32];
4931 int value = volumes_list[i].value;
4932 char *text = volumes_list[i].text;
4934 ti->node_top = &volumes_music;
4935 ti->sort_priority = value;
4937 sprintf(identifier, "%d", value);
4938 sprintf(name, "%s", text);
4940 setString(&ti->identifier, identifier);
4941 setString(&ti->name, name);
4942 setString(&ti->name_sorting, name);
4943 setString(&ti->infotext, "Music Volume");
4945 pushTreeInfo(&volumes_music, ti);
4947 if (value == setup.volume_music)
4948 current_volume_music_found = TRUE;
4951 if (!current_volume_music_found)
4953 // add entry for non-preset volume value
4955 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4956 char identifier[32], name[32];
4957 int value = setup.volume_music;
4959 ti->node_top = &volumes_music;
4960 ti->sort_priority = value;
4962 sprintf(identifier, "%d", value);
4963 sprintf(name, "%d %% (Current)", value);
4965 setString(&ti->identifier, identifier);
4966 setString(&ti->name, name);
4967 setString(&ti->name_sorting, name);
4968 setString(&ti->infotext, "Music Volume");
4970 pushTreeInfo(&volumes_music, ti);
4973 /* sort volume values to start with lowest volume value */
4974 sortTreeInfo(&volumes_music);
4976 /* set current volume value to configured volume value */
4977 volume_music_current =
4978 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4980 /* if that fails, set current volume to reliable default value */
4981 if (volume_music_current == NULL)
4982 volume_music_current =
4983 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4985 /* if that also fails, set current volume to first available value */
4986 if (volume_music_current == NULL)
4987 volume_music_current = volumes_music;
4990 setup.volume_simple = atoi(volume_simple_current->identifier);
4991 setup.volume_loops = atoi(volume_loops_current->identifier);
4992 setup.volume_music = atoi(volume_music_current->identifier);
4994 /* needed for displaying volume text instead of identifier */
4995 volume_simple_text = volume_simple_current->name;
4996 volume_loops_text = volume_loops_current->name;
4997 volume_music_text = volume_music_current->name;
4999 setup_mode = SETUP_MODE_SOUND;
5004 static void execSetupChooseTouchControls()
5006 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5011 static void execSetupChooseMoveDistance()
5013 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5018 static void execSetupChooseDropDistance()
5020 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5025 static void execSetupTouch()
5027 if (touch_controls == NULL)
5031 for (i = 0; touch_controls_list[i].value != NULL; i++)
5033 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5034 char identifier[32], name[32];
5035 char *value = touch_controls_list[i].value;
5036 char *text = touch_controls_list[i].text;
5038 ti->node_top = &touch_controls;
5039 ti->sort_priority = i;
5041 sprintf(identifier, "%s", value);
5042 sprintf(name, "%s", text);
5044 setString(&ti->identifier, identifier);
5045 setString(&ti->name, name);
5046 setString(&ti->name_sorting, name);
5047 setString(&ti->infotext, "Control Type");
5049 pushTreeInfo(&touch_controls, ti);
5052 /* sort touch control values to start with lowest touch control value */
5053 sortTreeInfo(&touch_controls);
5055 /* set current touch control value to configured touch control value */
5056 touch_control_current =
5057 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5059 /* if that fails, set current touch control to reliable default value */
5060 if (touch_control_current == NULL)
5061 touch_control_current =
5062 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5064 /* if that also fails, set current touch control to first available value */
5065 if (touch_control_current == NULL)
5066 touch_control_current = touch_controls;
5069 if (move_distances == NULL)
5073 for (i = 0; distances_list[i].value != -1; i++)
5075 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5076 char identifier[32], name[32];
5077 int value = distances_list[i].value;
5078 char *text = distances_list[i].text;
5080 ti->node_top = &move_distances;
5081 ti->sort_priority = value;
5083 sprintf(identifier, "%d", value);
5084 sprintf(name, "%s", text);
5086 setString(&ti->identifier, identifier);
5087 setString(&ti->name, name);
5088 setString(&ti->name_sorting, name);
5089 setString(&ti->infotext, "Move Distance");
5091 pushTreeInfo(&move_distances, ti);
5094 /* sort distance values to start with lowest distance value */
5095 sortTreeInfo(&move_distances);
5097 /* set current distance value to configured distance value */
5098 move_distance_current =
5099 getTreeInfoFromIdentifier(move_distances,
5100 i_to_a(setup.touch.move_distance));
5102 /* if that fails, set current distance to reliable default value */
5103 if (move_distance_current == NULL)
5104 move_distance_current =
5105 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
5107 /* if that also fails, set current distance to first available value */
5108 if (move_distance_current == NULL)
5109 move_distance_current = move_distances;
5112 if (drop_distances == NULL)
5116 for (i = 0; distances_list[i].value != -1; i++)
5118 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5119 char identifier[32], name[32];
5120 int value = distances_list[i].value;
5121 char *text = distances_list[i].text;
5123 ti->node_top = &drop_distances;
5124 ti->sort_priority = value;
5126 sprintf(identifier, "%d", value);
5127 sprintf(name, "%s", text);
5129 setString(&ti->identifier, identifier);
5130 setString(&ti->name, name);
5131 setString(&ti->name_sorting, name);
5132 setString(&ti->infotext, "Drop Distance");
5134 pushTreeInfo(&drop_distances, ti);
5137 /* sort distance values to start with lowest distance value */
5138 sortTreeInfo(&drop_distances);
5140 /* set current distance value to configured distance value */
5141 drop_distance_current =
5142 getTreeInfoFromIdentifier(drop_distances,
5143 i_to_a(setup.touch.drop_distance));
5145 /* if that fails, set current distance to reliable default value */
5146 if (drop_distance_current == NULL)
5147 drop_distance_current =
5148 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
5150 /* if that also fails, set current distance to first available value */
5151 if (drop_distance_current == NULL)
5152 drop_distance_current = drop_distances;
5155 setup.touch.control_type = touch_control_current->identifier;
5156 setup.touch.move_distance = atoi(move_distance_current->identifier);
5157 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5159 /* needed for displaying volume text instead of identifier */
5160 touch_controls_text = touch_control_current->name;
5161 move_distance_text = move_distance_current->name;
5162 drop_distance_text = drop_distance_current->name;
5164 setup_mode = SETUP_MODE_TOUCH;
5169 static void execSetupArtwork()
5172 printf("::: '%s', '%s', '%s'\n",
5173 artwork.gfx_current->subdir,
5174 artwork.gfx_current->fullpath,
5175 artwork.gfx_current->basepath);
5178 setup.graphics_set = artwork.gfx_current->identifier;
5179 setup.sounds_set = artwork.snd_current->identifier;
5180 setup.music_set = artwork.mus_current->identifier;
5182 /* needed if last screen (setup choice) changed graphics, sounds or music */
5183 ReloadCustomArtwork(0);
5185 /* needed for displaying artwork name instead of artwork identifier */
5186 graphics_set_name = artwork.gfx_current->name;
5187 sounds_set_name = artwork.snd_current->name;
5188 music_set_name = artwork.mus_current->name;
5190 setup_mode = SETUP_MODE_ARTWORK;
5195 static void execSetupChooseGraphics()
5197 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5202 static void execSetupChooseSounds()
5204 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5209 static void execSetupChooseMusic()
5211 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5216 #if !defined(PLATFORM_ANDROID)
5217 static void execSetupInput()
5219 setup_mode = SETUP_MODE_INPUT;
5225 static void execSetupShortcuts()
5227 setup_mode = SETUP_MODE_SHORTCUTS;
5232 static void execSetupShortcuts1()
5234 setup_mode = SETUP_MODE_SHORTCUTS_1;
5239 static void execSetupShortcuts2()
5241 setup_mode = SETUP_MODE_SHORTCUTS_2;
5246 static void execSetupShortcuts3()
5248 setup_mode = SETUP_MODE_SHORTCUTS_3;
5253 static void execSetupShortcuts4()
5255 setup_mode = SETUP_MODE_SHORTCUTS_4;
5260 static void execSetupShortcuts5()
5262 setup_mode = SETUP_MODE_SHORTCUTS_5;
5267 static void execExitSetup()
5269 game_status = GAME_MODE_MAIN;
5271 DrawMainMenuExt(REDRAW_FIELD, FALSE);
5274 static void execSaveAndExitSetup()
5280 static struct TokenInfo setup_info_main[] =
5282 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
5283 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
5284 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
5285 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
5286 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
5287 #if !defined(PLATFORM_ANDROID)
5288 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
5289 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5291 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
5293 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
5294 { TYPE_EMPTY, NULL, "" },
5295 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
5296 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
5301 static struct TokenInfo setup_info_game[] =
5303 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5304 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5305 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5306 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5307 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5308 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5309 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5310 { TYPE_STRING, &game_speed_text, "" },
5312 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5313 { TYPE_STRING, &scroll_delay_text, "" },
5315 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5316 { TYPE_STRING, &snapshot_mode_text, "" },
5317 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5318 { TYPE_EMPTY, NULL, "" },
5319 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5324 static struct TokenInfo setup_info_editor[] =
5327 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5328 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5329 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5330 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5331 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5332 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5333 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5334 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5336 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5337 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5338 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5340 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5342 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5343 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5344 { TYPE_EMPTY, NULL, "" },
5346 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5347 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5348 { TYPE_EMPTY, NULL, "" },
5350 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5351 { TYPE_EMPTY, NULL, "" },
5352 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5357 static struct TokenInfo setup_info_graphics[] =
5359 #if !defined(PLATFORM_ANDROID)
5360 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5361 #if defined(TARGET_SDL2)
5362 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5363 { TYPE_STRING, &window_size_text, "" },
5364 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5365 { TYPE_STRING, &scaling_type_text, "" },
5367 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5368 { TYPE_STRING, &screen_mode_text, "" },
5372 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5373 { TYPE_STRING, &scroll_delay_text, "" },
5375 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5376 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5377 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5378 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5379 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5380 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5381 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5382 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5383 { TYPE_EMPTY, NULL, "" },
5384 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5389 static struct TokenInfo setup_info_sound[] =
5391 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5392 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5393 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5394 { TYPE_EMPTY, NULL, "" },
5395 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5396 { TYPE_STRING, &volume_simple_text, "" },
5397 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5398 { TYPE_STRING, &volume_loops_text, "" },
5399 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5400 { TYPE_STRING, &volume_music_text, "" },
5401 { TYPE_EMPTY, NULL, "" },
5402 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5407 static struct TokenInfo setup_info_artwork[] =
5409 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5410 { TYPE_STRING, &graphics_set_name, "" },
5411 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5412 { TYPE_STRING, &sounds_set_name, "" },
5413 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5414 { TYPE_STRING, &music_set_name, "" },
5415 { TYPE_EMPTY, NULL, "" },
5416 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5417 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5418 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5419 { TYPE_EMPTY, NULL, "" },
5420 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5425 static struct TokenInfo setup_info_input[] =
5427 { TYPE_SWITCH, NULL, "Player:" },
5428 { TYPE_SWITCH, NULL, "Device:" },
5429 { TYPE_ENTER_MENU, NULL, "" },
5430 { TYPE_EMPTY, NULL, "" },
5431 { TYPE_EMPTY, NULL, "" },
5432 { TYPE_EMPTY, NULL, "" },
5433 { TYPE_EMPTY, NULL, "" },
5434 { TYPE_EMPTY, NULL, "" },
5435 { TYPE_EMPTY, NULL, "" },
5436 { TYPE_EMPTY, NULL, "" },
5437 { TYPE_EMPTY, NULL, "" },
5438 { TYPE_EMPTY, NULL, "" },
5439 { TYPE_EMPTY, NULL, "" },
5440 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5445 static struct TokenInfo setup_info_touch[] =
5447 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5448 { TYPE_STRING, &touch_controls_text, "" },
5449 { TYPE_EMPTY, NULL, "" },
5450 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5451 { TYPE_STRING, &move_distance_text, "" },
5452 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5453 { TYPE_STRING, &drop_distance_text, "" },
5454 { TYPE_EMPTY, NULL, "" },
5455 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5460 static struct TokenInfo setup_info_shortcuts[] =
5462 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5463 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5464 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5465 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5466 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5467 { TYPE_EMPTY, NULL, "" },
5468 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5473 static struct TokenInfo setup_info_shortcuts_1[] =
5475 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5476 { TYPE_KEY, &setup.shortcut.save_game, "" },
5477 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5478 { TYPE_KEY, &setup.shortcut.load_game, "" },
5479 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5480 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5481 { TYPE_EMPTY, NULL, "" },
5482 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5483 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5484 { TYPE_EMPTY, NULL, "" },
5485 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5490 static struct TokenInfo setup_info_shortcuts_2[] =
5492 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5493 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5494 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5495 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5496 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5497 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5498 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5499 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5500 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5501 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5502 { TYPE_EMPTY, NULL, "" },
5503 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5508 static struct TokenInfo setup_info_shortcuts_3[] =
5510 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5511 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5512 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5513 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5514 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5515 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5516 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5517 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5518 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5519 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5520 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5521 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5522 { TYPE_EMPTY, NULL, "" },
5523 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5528 static struct TokenInfo setup_info_shortcuts_4[] =
5530 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5531 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5532 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5533 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5534 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5535 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5536 { TYPE_EMPTY, NULL, "" },
5537 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5542 static struct TokenInfo setup_info_shortcuts_5[] =
5544 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5545 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5546 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5547 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5548 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5549 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5550 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5551 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5552 { TYPE_EMPTY, NULL, "" },
5553 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5558 static Key getSetupKey()
5560 Key key = KSYM_UNDEFINED;
5561 boolean got_key_event = FALSE;
5563 while (!got_key_event)
5565 if (PendingEvent()) /* got event */
5573 case EVENT_KEYPRESS:
5575 key = GetEventKey((KeyEvent *)&event, TRUE);
5577 /* press 'Escape' or 'Enter' to keep the existing key binding */
5578 if (key == KSYM_Escape || key == KSYM_Return)
5579 key = KSYM_UNDEFINED; /* keep old value */
5581 got_key_event = TRUE;
5585 case EVENT_KEYRELEASE:
5586 key_joystick_mapping = 0;
5590 HandleOtherEvents(&event);
5598 /* don't eat all CPU time */
5605 static int getSetupValueFont(int type, void *value)
5607 if (type & TYPE_KEY)
5608 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5609 else if (type & TYPE_STRING)
5610 return FONT_VALUE_2;
5611 else if (type & TYPE_ECS_AGA)
5612 return FONT_VALUE_1;
5613 else if (type & TYPE_BOOLEAN_STYLE)
5614 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5615 else if (type & TYPE_YES_NO_AUTO)
5616 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5617 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5619 return FONT_VALUE_1;
5622 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5624 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5625 struct TokenInfo *si = &setup_info[si_pos];
5626 boolean font_draw_xoffset_modified = FALSE;
5627 int font_draw_xoffset_old = -1;
5628 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5629 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5630 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5631 int xpos = menu_screen_value_xpos;
5632 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5633 int startx = mSX + xpos * 32;
5634 int starty = mSY + ypos * 32;
5635 int font_nr, font_width;
5636 int type = si->type;
5637 void *value = si->value;
5638 char *value_string = getSetupValue(type, value);
5641 if (value_string == NULL)
5644 if (type & TYPE_KEY)
5646 xpos = MENU_SCREEN_START_XPOS;
5648 if (type & TYPE_QUERY)
5649 value_string = "<press key>";
5651 else if (type & TYPE_STRING)
5653 int max_value_len = (SCR_FIELDX - 2) * 2;
5655 xpos = MENU_SCREEN_START_XPOS;
5657 if (strlen(value_string) > max_value_len)
5658 value_string[max_value_len] = '\0';
5660 else if (type & TYPE_YES_NO_AUTO)
5662 xpos = menu_screen_value_xpos - 1;
5665 startx = mSX + xpos * 32;
5666 starty = mSY + ypos * 32;
5667 font_nr = getSetupValueFont(type, value);
5668 font_width = getFontWidth(font_nr);
5670 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5671 if (setup_mode != SETUP_MODE_INPUT)
5673 int max_menu_text_length_big = (menu_screen_value_xpos -
5674 MENU_SCREEN_START_XPOS);
5675 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5676 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5677 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5678 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5679 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5680 int text_font_nr = getMenuTextFont(FONT_MENU_2);
5681 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5682 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5683 boolean correct_font_draw_xoffset = FALSE;
5685 if (xpos == MENU_SCREEN_START_XPOS &&
5686 startx + font1_xoffset < text_startx + text_font_xoffset)
5687 correct_font_draw_xoffset = TRUE;
5689 if (xpos == menu_screen_value_xpos &&
5690 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5691 correct_font_draw_xoffset = TRUE;
5693 /* check if setup value would overlap with setup text when printed */
5694 /* (this can happen for extreme/wrong values for font draw offset) */
5695 if (correct_font_draw_xoffset)
5697 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5698 font_draw_xoffset_modified = TRUE;
5700 if (type & TYPE_KEY)
5701 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5702 else if (!(type & TYPE_STRING))
5703 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5704 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5708 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5709 DrawText(startx + i * font_width, starty, " ", font_nr);
5711 DrawText(startx, starty, value_string, font_nr);
5713 if (font_draw_xoffset_modified)
5714 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5717 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5719 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5720 struct TokenInfo *si = &setup_info[si_pos];
5722 if (si->type & TYPE_BOOLEAN_STYLE)
5724 *(boolean *)si->value ^= TRUE;
5726 else if (si->type & TYPE_YES_NO_AUTO)
5730 (*(int *)si->value == AUTO ? TRUE :
5731 *(int *)si->value == TRUE ? FALSE : AUTO) :
5732 (*(int *)si->value == TRUE ? AUTO :
5733 *(int *)si->value == AUTO ? FALSE : TRUE));
5735 else if (si->type & TYPE_KEY)
5739 si->type |= TYPE_QUERY;
5740 drawSetupValue(screen_pos, setup_info_pos_raw);
5741 si->type &= ~TYPE_QUERY;
5743 key = getSetupKey();
5744 if (key != KSYM_UNDEFINED)
5745 *(Key *)si->value = key;
5748 drawSetupValue(screen_pos, setup_info_pos_raw);
5750 // fullscreen state may have changed at this point
5751 if (si->value == &setup.fullscreen)
5752 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5755 static void DrawSetupScreen_Generic()
5757 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5758 boolean redraw_all = FALSE;
5759 char *title_string = NULL;
5762 if (CheckIfRedrawGlobalBorderIsNeeded())
5763 fade_mask = REDRAW_ALL;
5767 FreeScreenGadgets();
5768 CreateScreenGadgets();
5770 CloseDoor(DOOR_CLOSE_2);
5772 if (redraw_mask & REDRAW_ALL)
5779 if (setup_mode == SETUP_MODE_MAIN)
5781 setup_info = setup_info_main;
5782 title_string = "Setup";
5784 else if (setup_mode == SETUP_MODE_GAME)
5786 setup_info = setup_info_game;
5787 title_string = "Setup Game";
5789 else if (setup_mode == SETUP_MODE_EDITOR)
5791 setup_info = setup_info_editor;
5792 title_string = "Setup Editor";
5794 else if (setup_mode == SETUP_MODE_GRAPHICS)
5796 setup_info = setup_info_graphics;
5797 title_string = "Setup Graphics";
5799 else if (setup_mode == SETUP_MODE_SOUND)
5801 setup_info = setup_info_sound;
5802 title_string = "Setup Sound";
5804 else if (setup_mode == SETUP_MODE_ARTWORK)
5806 setup_info = setup_info_artwork;
5807 title_string = "Custom Artwork";
5809 else if (setup_mode == SETUP_MODE_TOUCH)
5811 setup_info = setup_info_touch;
5812 title_string = "Setup Touch Ctrls";
5814 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5816 setup_info = setup_info_shortcuts;
5817 title_string = "Setup Shortcuts";
5819 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5821 setup_info = setup_info_shortcuts_1;
5822 title_string = "Setup Shortcuts";
5824 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5826 setup_info = setup_info_shortcuts_2;
5827 title_string = "Setup Shortcuts";
5829 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5831 setup_info = setup_info_shortcuts_3;
5832 title_string = "Setup Shortcuts";
5834 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5836 setup_info = setup_info_shortcuts_4;
5837 title_string = "Setup Shortcuts";
5839 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5841 setup_info = setup_info_shortcuts_5;
5842 title_string = "Setup Shortcuts";
5845 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5847 // determine maximal number of setup entries that can be displayed on screen
5849 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5852 // determine maximal number of setup entries available for this setup screen
5854 for (i = 0; setup_info[i].type != 0; i++)
5857 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5859 MapScreenGadgets(max_setup_info);
5862 redraw_mask = fade_mask = REDRAW_ALL;
5869 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5871 menu_info = setup_info;
5873 HandleMenuScreen(mx, my, dx, dy, button,
5874 setup_mode, num_setup_info, max_setup_info);
5877 void DrawSetupScreen_Input()
5881 FadeOut(REDRAW_FIELD);
5885 setup_info = setup_info_input;
5887 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5889 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5890 "Joysticks deactivated on this screen");
5892 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5894 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5895 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5896 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5897 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5898 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5899 initCursor(i, IMG_MENU_BUTTON);
5901 DrawCursorAndText_Setup(i, -1, FALSE);
5904 /* create gadgets for setup input menu screen */
5905 FreeScreenGadgets();
5906 CreateScreenGadgets();
5908 /* map gadgets for setup input menu screen */
5909 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5911 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5913 FadeIn(REDRAW_FIELD);
5918 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5920 if (device_name == NULL)
5923 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5926 if (strlen(device_name) > 1)
5928 char c1 = device_name[strlen(device_name) - 1];
5929 char c2 = device_name[strlen(device_name) - 2];
5931 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5932 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5935 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5936 strlen(device_name));
5939 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5942 static struct SetupKeyboardInfo custom_key;
5949 { &custom_key.left, "Joystick Left" },
5950 { &custom_key.right, "Joystick Right" },
5951 { &custom_key.up, "Joystick Up" },
5952 { &custom_key.down, "Joystick Down" },
5953 { &custom_key.snap, "Button 1" },
5954 { &custom_key.drop, "Button 2" }
5956 static char *joystick_name[MAX_PLAYERS] =
5963 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5967 custom_key = setup.input[player_nr].key;
5969 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5970 FONT_INPUT_1_ACTIVE);
5972 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5974 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5975 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5977 if (setup.input[player_nr].use_joystick)
5979 char *device_name = setup.input[player_nr].joy.device_name;
5980 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5981 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5983 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5984 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
5988 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
5989 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
5992 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
5994 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
5995 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
5996 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
5997 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
5999 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6000 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6001 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6002 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6003 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6004 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6006 for (i = 0; i < 6; i++)
6008 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6010 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6012 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6013 (setup.input[player_nr].use_joystick ?
6015 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6019 static int input_player_nr = 0;
6021 void HandleSetupScreen_Input_Player(int step, int direction)
6023 int old_player_nr = input_player_nr;
6026 new_player_nr = old_player_nr + step * direction;
6027 if (new_player_nr < 0)
6029 if (new_player_nr > MAX_PLAYERS - 1)
6030 new_player_nr = MAX_PLAYERS - 1;
6032 if (new_player_nr != old_player_nr)
6034 input_player_nr = new_player_nr;
6036 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6040 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6042 static int choice = 0;
6045 int pos_start = SETUPINPUT_SCREEN_POS_START;
6046 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6047 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6048 int pos_end = SETUPINPUT_SCREEN_POS_END;
6050 if (button == MB_MENU_INITIALIZE)
6052 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6054 DrawCursorAndText_Setup(choice, -1, TRUE);
6058 else if (button == MB_MENU_LEAVE)
6060 setup_mode = SETUP_MODE_MAIN;
6067 if (mx || my) /* mouse input */
6069 x = (mx - mSX) / 32;
6070 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6072 else if (dx || dy) /* keyboard input */
6074 if (dx && choice == 0)
6075 x = (dx < 0 ? 10 : 12);
6076 else if ((dx && choice == 1) ||
6077 (dx == +1 && choice == 2) ||
6078 (dx == -1 && choice == pos_end))
6079 button = MB_MENU_CHOICE;
6083 if (y >= pos_empty1 && y <= pos_empty2)
6084 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6087 if (y == 0 && dx != 0 && button)
6089 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6091 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6092 y >= pos_start && y <= pos_end &&
6093 !(y >= pos_empty1 && y <= pos_empty2))
6099 DrawCursorAndText_Setup(choice, -1, FALSE);
6100 DrawCursorAndText_Setup(y, -1, TRUE);
6102 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6111 char *device_name = setup.input[input_player_nr].joy.device_name;
6113 if (!setup.input[input_player_nr].use_joystick)
6115 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6117 setJoystickDeviceToNr(device_name, new_device_nr);
6118 setup.input[input_player_nr].use_joystick = TRUE;
6122 int device_nr = getJoystickNrFromDeviceName(device_name);
6123 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6125 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6126 setup.input[input_player_nr].use_joystick = FALSE;
6128 setJoystickDeviceToNr(device_name, new_device_nr);
6131 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6135 if (setup.input[input_player_nr].use_joystick)
6138 CalibrateJoystick(input_player_nr);
6141 CustomizeKeyboard(input_player_nr);
6143 else if (y == pos_end)
6149 setup_mode = SETUP_MODE_MAIN;
6156 void CustomizeKeyboard(int player_nr)
6160 boolean finished = FALSE;
6161 static struct SetupKeyboardInfo custom_key;
6166 } customize_step[] =
6168 { &custom_key.left, "Move Left" },
6169 { &custom_key.right, "Move Right" },
6170 { &custom_key.up, "Move Up" },
6171 { &custom_key.down, "Move Down" },
6172 { &custom_key.snap, "Snap Field" },
6173 { &custom_key.drop, "Drop Element" }
6176 /* read existing key bindings from player setup */
6177 custom_key = setup.input[player_nr].key;
6180 FadeOut(REDRAW_FIELD);
6184 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6187 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6188 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6189 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6190 "Key:", FONT_INPUT_1_ACTIVE);
6191 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6192 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6194 FadeIn(REDRAW_FIELD);
6200 if (PendingEvent()) /* got event */
6208 case EVENT_KEYPRESS:
6210 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6212 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6214 if (key == KSYM_Escape)
6215 FadeSkipNextFadeIn();
6221 /* all keys configured -- wait for "Escape" or "Return" key */
6225 /* press 'Enter' to keep the existing key binding */
6226 if (key == KSYM_Return)
6227 key = *customize_step[step_nr].key;
6229 /* check if key already used */
6230 for (i = 0; i < step_nr; i++)
6231 if (*customize_step[i].key == key)
6236 /* got new key binding */
6237 *customize_step[step_nr].key = key;
6238 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6240 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6241 getKeyNameFromKey(key), FONT_VALUE_1);
6244 /* un-highlight last query */
6245 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6246 customize_step[step_nr - 1].text, FONT_MENU_1);
6247 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6248 "Key:", FONT_MENU_1);
6250 /* press 'Enter' to leave */
6253 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6254 "Press Enter", FONT_TITLE_1);
6258 /* query next key binding */
6259 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6260 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6261 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6262 "Key:", FONT_INPUT_1_ACTIVE);
6263 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6264 getKeyNameFromKey(*customize_step[step_nr].key),
6269 case EVENT_KEYRELEASE:
6270 key_joystick_mapping = 0;
6274 HandleOtherEvents(&event);
6282 /* don't eat all CPU time */
6286 /* write new key bindings back to player setup */
6287 setup.input[player_nr].key = custom_key;
6290 DrawSetupScreen_Input();
6293 static boolean CalibrateJoystickMain(int player_nr)
6295 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6296 int new_joystick_xright = JOYSTICK_XMIDDLE;
6297 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6298 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6299 int new_joystick_xmiddle, new_joystick_ymiddle;
6301 int joystick_fd = joystick.fd[player_nr];
6302 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6303 boolean check[3][3];
6304 int check_remaining = 3 * 3;
6309 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6312 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6316 FadeOut(REDRAW_FIELD);
6320 for (y = 0; y < 3; y++)
6322 for (x = 0; x < 3; x++)
6324 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6325 check[x][y] = FALSE;
6329 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6330 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6331 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6332 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6333 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6334 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6335 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6337 joy_value = Joystick(player_nr);
6338 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6339 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6341 /* eventually uncalibrated center position (joystick could be uncentered) */
6342 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6345 new_joystick_xmiddle = joy_x;
6346 new_joystick_ymiddle = joy_y;
6348 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6350 FadeIn(REDRAW_FIELD);
6352 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6357 if (PendingEvent()) /* got event */
6365 case EVENT_KEYPRESS:
6366 switch (GetEventKey((KeyEvent *)&event, TRUE))
6369 if (check_remaining == 0)
6374 FadeSkipNextFadeIn();
6383 case EVENT_KEYRELEASE:
6384 key_joystick_mapping = 0;
6388 HandleOtherEvents(&event);
6393 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6396 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6397 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6398 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6399 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6401 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6402 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6403 setup.input[player_nr].joy.xright = new_joystick_xright;
6404 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6405 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6406 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6408 CheckJoystickData();
6410 joy_value = Joystick(player_nr);
6412 if (joy_value & JOY_BUTTON && check_remaining == 0)
6415 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6416 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6418 if (x != last_x || y != last_y)
6420 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6421 IMG_MENU_CALIBRATE_YELLOW, 0);
6422 DrawFixedGraphic(xpos + x, ypos + y,
6423 IMG_MENU_CALIBRATE_RED, 0);
6428 if (check_remaining > 0 && !check[x+1][y+1])
6430 check[x+1][y+1] = TRUE;
6438 /* don't eat all CPU time */
6442 /* calibrated center position (joystick should now be centered) */
6443 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6446 new_joystick_xmiddle = joy_x;
6447 new_joystick_ymiddle = joy_y;
6451 /* wait until the last pressed button was released */
6452 while (Joystick(player_nr) & JOY_BUTTON)
6454 if (PendingEvent()) /* got event */
6459 HandleOtherEvents(&event);
6468 void CalibrateJoystick(int player_nr)
6470 if (!CalibrateJoystickMain(player_nr))
6472 char *device_name = setup.input[player_nr].joy.device_name;
6473 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6474 int xpos = mSX - SX;
6475 int ypos = mSY - SY;
6479 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6480 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6483 Delay(2000); /* show error message for a short time */
6488 DrawSetupScreen_Input();
6491 void DrawSetupScreen()
6493 DeactivateJoystick();
6495 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6497 if (setup_mode == SETUP_MODE_INPUT)
6498 DrawSetupScreen_Input();
6499 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6500 DrawChooseTree(&game_speed_current);
6501 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6502 DrawChooseTree(&scroll_delay_current);
6503 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6504 DrawChooseTree(&snapshot_mode_current);
6505 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6506 DrawChooseTree(&screen_mode_current);
6507 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6508 DrawChooseTree(&window_size_current);
6509 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6510 DrawChooseTree(&scaling_type_current);
6511 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6512 DrawChooseTree(&artwork.gfx_current);
6513 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6514 DrawChooseTree(&artwork.snd_current);
6515 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6516 DrawChooseTree(&artwork.mus_current);
6517 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6518 DrawChooseTree(&volume_simple_current);
6519 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6520 DrawChooseTree(&volume_loops_current);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6522 DrawChooseTree(&volume_music_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6524 DrawChooseTree(&touch_control_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6526 DrawChooseTree(&move_distance_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6528 DrawChooseTree(&drop_distance_current);
6530 DrawSetupScreen_Generic();
6536 void RedrawSetupScreenAfterFullscreenToggle()
6538 if (setup_mode == SETUP_MODE_GRAPHICS ||
6539 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6541 // update list selection from "setup.window_scaling_percent"
6542 execSetupGraphics_setWindowSizes(TRUE);
6548 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6550 if (setup_mode == SETUP_MODE_INPUT)
6551 HandleSetupScreen_Input(mx, my, dx, dy, button);
6552 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6553 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6554 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6555 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6556 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6557 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6558 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6559 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6560 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6561 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6562 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6563 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6564 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6565 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6566 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6567 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6568 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6569 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6570 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6571 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6573 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6575 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6577 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6579 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6581 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6583 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6586 void HandleGameActions()
6588 if (game_status != GAME_MODE_PLAYING)
6591 GameActions(); /* main game loop */
6593 if (tape.auto_play && !tape.playing)
6594 AutoPlayTape(); /* continue automatically playing next tape */
6598 /* ---------- new screen button stuff -------------------------------------- */
6600 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6604 case SCREEN_CTRL_ID_PREV_LEVEL:
6605 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6606 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6609 case SCREEN_CTRL_ID_NEXT_LEVEL:
6610 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6611 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6614 case SCREEN_CTRL_ID_PREV_PLAYER:
6615 *x = mSX + TILEX * 10;
6616 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6619 case SCREEN_CTRL_ID_NEXT_PLAYER:
6620 *x = mSX + TILEX * 12;
6621 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6625 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6631 int gfx_unpressed, gfx_pressed;
6632 void (*get_gadget_position)(int *, int *, int);
6636 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6639 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6640 getScreenMenuButtonPos,
6641 SCREEN_CTRL_ID_PREV_LEVEL,
6646 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6647 getScreenMenuButtonPos,
6648 SCREEN_CTRL_ID_NEXT_LEVEL,
6653 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6654 getScreenMenuButtonPos,
6655 SCREEN_CTRL_ID_PREV_PLAYER,
6660 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6661 getScreenMenuButtonPos,
6662 SCREEN_CTRL_ID_NEXT_PLAYER,
6670 int gfx_unpressed, gfx_pressed;
6674 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6677 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6678 -1, -1, /* these values are not constant, but can change at runtime */
6679 SCREEN_CTRL_ID_SCROLL_UP,
6683 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6684 -1, -1, /* these values are not constant, but can change at runtime */
6685 SCREEN_CTRL_ID_SCROLL_DOWN,
6692 int gfx_unpressed, gfx_pressed;
6698 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6701 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6702 -1, -1, /* these values are not constant, but can change at runtime */
6703 -1, -1, /* these values are not constant, but can change at runtime */
6704 GD_TYPE_SCROLLBAR_VERTICAL,
6705 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6706 "scroll level series vertically"
6710 static void CreateScreenMenubuttons()
6712 struct GadgetInfo *gi;
6713 unsigned int event_mask;
6716 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6718 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6719 int gfx_unpressed, gfx_pressed;
6720 int x, y, width, height;
6721 int gd_x1, gd_x2, gd_y1, gd_y2;
6722 int id = menubutton_info[i].gadget_id;
6724 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6726 menubutton_info[i].get_gadget_position(&x, &y, id);
6728 width = SC_MENUBUTTON_XSIZE;
6729 height = SC_MENUBUTTON_YSIZE;
6731 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6732 gfx_pressed = menubutton_info[i].gfx_pressed;
6733 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6734 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6735 gd_x1 = graphic_info[gfx_unpressed].src_x;
6736 gd_y1 = graphic_info[gfx_unpressed].src_y;
6737 gd_x2 = graphic_info[gfx_pressed].src_x;
6738 gd_y2 = graphic_info[gfx_pressed].src_y;
6740 gi = CreateGadget(GDI_CUSTOM_ID, id,
6741 GDI_CUSTOM_TYPE_ID, i,
6742 GDI_INFO_TEXT, menubutton_info[i].infotext,
6747 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6748 GDI_STATE, GD_BUTTON_UNPRESSED,
6749 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6750 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6751 GDI_DIRECT_DRAW, FALSE,
6752 GDI_EVENT_MASK, event_mask,
6753 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6757 Error(ERR_EXIT, "cannot create gadget");
6759 screen_gadget[id] = gi;
6763 static void CreateScreenScrollbuttons()
6765 struct GadgetInfo *gi;
6766 unsigned int event_mask;
6769 /* these values are not constant, but can change at runtime */
6770 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6771 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6772 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6773 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6775 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6777 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6778 int gfx_unpressed, gfx_pressed;
6779 int x, y, width, height;
6780 int gd_x1, gd_x2, gd_y1, gd_y2;
6781 int id = scrollbutton_info[i].gadget_id;
6783 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6785 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6786 y = mSY + scrollbutton_info[i].y;
6787 width = SC_SCROLLBUTTON_XSIZE;
6788 height = SC_SCROLLBUTTON_YSIZE;
6790 /* correct scrollbar position if placed outside menu (playfield) area */
6791 if (x > SX + SC_SCROLL_UP_XPOS)
6792 x = SX + SC_SCROLL_UP_XPOS;
6794 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6795 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6796 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6798 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6799 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6800 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6801 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6802 gd_x1 = graphic_info[gfx_unpressed].src_x;
6803 gd_y1 = graphic_info[gfx_unpressed].src_y;
6804 gd_x2 = graphic_info[gfx_pressed].src_x;
6805 gd_y2 = graphic_info[gfx_pressed].src_y;
6807 gi = CreateGadget(GDI_CUSTOM_ID, id,
6808 GDI_CUSTOM_TYPE_ID, i,
6809 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6814 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6815 GDI_STATE, GD_BUTTON_UNPRESSED,
6816 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6817 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6818 GDI_DIRECT_DRAW, FALSE,
6819 GDI_EVENT_MASK, event_mask,
6820 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6824 Error(ERR_EXIT, "cannot create gadget");
6826 screen_gadget[id] = gi;
6830 static void CreateScreenScrollbars()
6834 /* these values are not constant, but can change at runtime */
6835 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6836 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6837 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6838 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6840 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6842 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6843 int gfx_unpressed, gfx_pressed;
6844 int x, y, width, height;
6845 int gd_x1, gd_x2, gd_y1, gd_y2;
6846 struct GadgetInfo *gi;
6847 int items_max, items_visible, item_position;
6848 unsigned int event_mask;
6849 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6850 int id = scrollbar_info[i].gadget_id;
6852 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6854 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6855 y = mSY + scrollbar_info[i].y;
6856 width = scrollbar_info[i].width;
6857 height = scrollbar_info[i].height;
6859 /* correct scrollbar position if placed outside menu (playfield) area */
6860 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6861 x = SX + SC_SCROLL_VERTICAL_XPOS;
6863 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6864 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6866 items_max = num_page_entries;
6867 items_visible = num_page_entries;
6870 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6871 gfx_pressed = scrollbar_info[i].gfx_pressed;
6872 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6873 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6874 gd_x1 = graphic_info[gfx_unpressed].src_x;
6875 gd_y1 = graphic_info[gfx_unpressed].src_y;
6876 gd_x2 = graphic_info[gfx_pressed].src_x;
6877 gd_y2 = graphic_info[gfx_pressed].src_y;
6879 gi = CreateGadget(GDI_CUSTOM_ID, id,
6880 GDI_CUSTOM_TYPE_ID, i,
6881 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6886 GDI_TYPE, scrollbar_info[i].type,
6887 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6888 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6889 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6890 GDI_WHEEL_AREA_X, SX,
6891 GDI_WHEEL_AREA_Y, SY,
6892 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6893 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6894 GDI_STATE, GD_BUTTON_UNPRESSED,
6895 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6896 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6897 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6898 GDI_DIRECT_DRAW, FALSE,
6899 GDI_EVENT_MASK, event_mask,
6900 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6904 Error(ERR_EXIT, "cannot create gadget");
6906 screen_gadget[id] = gi;
6910 void CreateScreenGadgets()
6912 int last_game_status = game_status; /* save current game status */
6914 CreateScreenMenubuttons();
6916 CreateScreenScrollbuttons();
6917 CreateScreenScrollbars();
6919 game_status = last_game_status; /* restore current game status */
6922 void FreeScreenGadgets()
6926 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6927 FreeGadget(screen_gadget[i]);
6930 void MapScreenMenuGadgets(int screen_mask)
6934 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6935 if (screen_mask & menubutton_info[i].screen_mask)
6936 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6939 void MapScreenGadgets(int num_entries)
6943 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6946 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6947 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6949 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6950 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6953 void MapScreenTreeGadgets(TreeInfo *ti)
6955 MapScreenGadgets(numTreeInfoInGroup(ti));
6958 static void HandleScreenGadgets(struct GadgetInfo *gi)
6960 int id = gi->custom_id;
6961 int button = gi->event.button;
6962 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6966 case SCREEN_CTRL_ID_PREV_LEVEL:
6967 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6970 case SCREEN_CTRL_ID_NEXT_LEVEL:
6971 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6974 case SCREEN_CTRL_ID_PREV_PLAYER:
6975 HandleSetupScreen_Input_Player(step, -1);
6978 case SCREEN_CTRL_ID_NEXT_PLAYER:
6979 HandleSetupScreen_Input_Player(step, +1);
6982 case SCREEN_CTRL_ID_SCROLL_UP:
6983 if (game_status == GAME_MODE_LEVELS)
6984 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6985 else if (game_status == GAME_MODE_LEVELNR)
6986 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6987 else if (game_status == GAME_MODE_SETUP)
6988 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6989 else if (game_status == GAME_MODE_INFO)
6990 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6993 case SCREEN_CTRL_ID_SCROLL_DOWN:
6994 if (game_status == GAME_MODE_LEVELS)
6995 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6996 else if (game_status == GAME_MODE_LEVELNR)
6997 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
6998 else if (game_status == GAME_MODE_SETUP)
6999 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7000 else if (game_status == GAME_MODE_INFO)
7001 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7004 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7005 if (game_status == GAME_MODE_LEVELS)
7006 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7007 else if (game_status == GAME_MODE_LEVELNR)
7008 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7009 else if (game_status == GAME_MODE_SETUP)
7010 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
7011 else if (game_status == GAME_MODE_INFO)
7012 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);