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 /* for input setup functions */
80 #define SETUPINPUT_SCREEN_POS_START 0
81 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 4)
82 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
83 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
85 /* for various menu stuff */
86 #define MENU_SCREEN_START_XPOS 1
87 #define MENU_SCREEN_START_YPOS 2
88 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
89 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
90 #define MENU_TITLE1_YPOS 8
91 #define MENU_TITLE2_YPOS 46
92 #define MENU_SCREEN_INFO_XSTART 16
93 #define MENU_SCREEN_INFO_YSTART1 100
94 #define MENU_SCREEN_INFO_YSTART2 128
95 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
96 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - 20)
97 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
98 MENU_SCREEN_INFO_YSTART2 - \
100 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
101 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \
102 MENU_SCREEN_INFO_YSTEP, \
103 MAX_INFO_ELEMENTS_ON_SCREEN)
104 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
105 #define MAX_MENU_TEXT_LENGTH_BIG 13
106 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
108 /* buttons and scrollbars identifiers */
109 #define SCREEN_CTRL_ID_PREV_LEVEL 0
110 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
111 #define SCREEN_CTRL_ID_PREV_PLAYER 2
112 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
113 #define SCREEN_CTRL_ID_SCROLL_UP 4
114 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
115 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
117 #define NUM_SCREEN_GADGETS 7
119 #define NUM_SCREEN_MENUBUTTONS 4
120 #define NUM_SCREEN_SCROLLBUTTONS 2
121 #define NUM_SCREEN_SCROLLBARS 1
123 #define SCREEN_MASK_MAIN (1 << 0)
124 #define SCREEN_MASK_INPUT (1 << 1)
126 /* graphic position and size values for buttons and scrollbars */
127 #define SC_MENUBUTTON_XSIZE TILEX
128 #define SC_MENUBUTTON_YSIZE TILEY
130 #define SC_SCROLLBUTTON_XSIZE TILEX
131 #define SC_SCROLLBUTTON_YSIZE TILEY
133 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
135 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
136 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
137 SC_SCROLLBUTTON_YSIZE)
139 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
140 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
142 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
143 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
144 SC_SCROLLBUTTON_YSIZE)
146 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
147 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
148 SC_SCROLL_VERTICAL_YSIZE)
150 #define SC_BORDER_SIZE 14
153 /* forward declarations of internal functions */
154 static void HandleScreenGadgets(struct GadgetInfo *);
155 static void HandleSetupScreen_Generic(int, int, int, int, int);
156 static void HandleSetupScreen_Input(int, int, int, int, int);
157 static void CustomizeKeyboard(int);
158 static void CalibrateJoystick(int);
159 static void execSetupGame(void);
160 static void execSetupGraphics(void);
161 static void execSetupSound(void);
162 static void execSetupTouch(void);
163 static void execSetupArtwork(void);
164 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
166 static void DrawChooseLevelSet(void);
167 static void DrawChooseLevelNr(void);
168 static void DrawInfoScreen(void);
169 static void DrawAndFadeInInfoScreen(int);
170 static void DrawSetupScreen(void);
172 static void DrawInfoScreenExt(int, int);
173 static void DrawInfoScreen_NotAvailable(char *, char *);
174 static void DrawInfoScreen_HelpAnim(int, int, boolean);
175 static void DrawInfoScreen_HelpText(int, int, int, int);
176 static void HandleInfoScreen_Main(int, int, int, int, int);
177 static void HandleInfoScreen_TitleScreen(int);
178 static void HandleInfoScreen_Elements(int);
179 static void HandleInfoScreen_Music(int);
180 static void HandleInfoScreen_Credits(int);
181 static void HandleInfoScreen_Program(int);
182 static void HandleInfoScreen_Version(int);
184 static void MapScreenMenuGadgets(int);
185 static void MapScreenGadgets(int);
186 static void MapScreenTreeGadgets(TreeInfo *);
188 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
190 static int info_mode = INFO_MODE_MAIN;
191 static int setup_mode = SETUP_MODE_MAIN;
193 static TreeInfo *screen_modes = NULL;
194 static TreeInfo *screen_mode_current = NULL;
196 static TreeInfo *window_sizes = NULL;
197 static TreeInfo *window_size_current = NULL;
199 static TreeInfo *scaling_types = NULL;
200 static TreeInfo *scaling_type_current = NULL;
202 static TreeInfo *scroll_delays = NULL;
203 static TreeInfo *scroll_delay_current = NULL;
205 static TreeInfo *snapshot_modes = NULL;
206 static TreeInfo *snapshot_mode_current = NULL;
208 static TreeInfo *game_speeds = NULL;
209 static TreeInfo *game_speed_current = NULL;
211 static TreeInfo *volumes_simple = NULL;
212 static TreeInfo *volume_simple_current = NULL;
214 static TreeInfo *volumes_loops = NULL;
215 static TreeInfo *volume_loops_current = NULL;
217 static TreeInfo *volumes_music = NULL;
218 static TreeInfo *volume_music_current = NULL;
220 static TreeInfo *touch_controls = NULL;
221 static TreeInfo *touch_control_current = NULL;
223 static TreeInfo *move_distances = NULL;
224 static TreeInfo *move_distance_current = NULL;
226 static TreeInfo *drop_distances = NULL;
227 static TreeInfo *drop_distance_current = NULL;
229 static TreeInfo *level_number = NULL;
230 static TreeInfo *level_number_current = NULL;
236 } window_sizes_list[] =
241 { 100, "100 % (Default)" },
258 } scaling_types_list[] =
260 { SCALING_QUALITY_NEAREST, "None" },
261 { SCALING_QUALITY_LINEAR, "Linear" },
262 { SCALING_QUALITY_BEST, "Anisotropic" },
271 } game_speeds_list[] =
280 { 1000, "1/1s (Extremely Slow)" },
285 { 29, "1/35s (Original Supaplex)" },
287 { 20, "1/50s (Normal Speed)" },
288 { 14, "1/70s (Maximum Supaplex)" },
292 { 1, "1/1000s (Extremely Fast)" },
302 } scroll_delays_list[] =
304 { 0, "0 Tiles (No Scroll Delay)" },
307 { 3, "3 Tiles (Default)" },
312 { 8, "8 Tiles (Maximum Scroll Delay)"},
321 } snapshot_modes_list[] =
323 { STR_SNAPSHOT_MODE_OFF, "Off" },
324 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
325 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
358 } touch_controls_list[] =
360 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
361 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
385 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
386 (s) <= GAME_MODE_SETUP ? (s) : \
387 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
388 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
390 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
391 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
392 (i) <= INFO_MODE_LEVELSET ? (i) : \
395 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
396 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
397 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
398 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
399 SETUP_MODE_CHOOSE_ARTWORK : \
400 SETUP_MODE_CHOOSE_OTHER)
402 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
403 menu.draw_xoffset[GAME_MODE_INFO] : \
404 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
405 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
406 menu.draw_yoffset[GAME_MODE_INFO] : \
407 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
409 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
410 menu.draw_xoffset[GAME_MODE_SETUP] : \
411 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
412 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
413 menu.draw_yoffset[GAME_MODE_SETUP] : \
414 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
416 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
417 DRAW_XOFFSET_INFO(info_mode) : \
418 (s) == GAME_MODE_SETUP ? \
419 DRAW_XOFFSET_SETUP(setup_mode) : \
420 menu.draw_xoffset[DRAW_MODE(s)])
421 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
422 DRAW_YOFFSET_INFO(info_mode) : \
423 (s) == GAME_MODE_SETUP ? \
424 DRAW_YOFFSET_SETUP(setup_mode) : \
425 menu.draw_yoffset[DRAW_MODE(s)])
427 #define mSX (SX + DRAW_XOFFSET(game_status))
428 #define mSY (SY + DRAW_YOFFSET(game_status))
430 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
431 menu.list_size[game_status] : \
432 MAX_MENU_ENTRIES_ON_SCREEN)
434 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
435 NUM_MENU_ENTRIES_ON_SCREEN)
438 /* title display and control definitions */
440 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
441 2 * MAX_NUM_TITLE_MESSAGES)
443 #define NO_DIRECT_LEVEL_SELECT (-1)
446 static int num_title_screens = 0;
448 struct TitleControlInfo
456 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
458 /* main menu display and control definitions */
460 #define MAIN_CONTROL_NAME 0
461 #define MAIN_CONTROL_LEVELS 1
462 #define MAIN_CONTROL_SCORES 2
463 #define MAIN_CONTROL_EDITOR 3
464 #define MAIN_CONTROL_INFO 4
465 #define MAIN_CONTROL_GAME 5
466 #define MAIN_CONTROL_SETUP 6
467 #define MAIN_CONTROL_QUIT 7
468 #define MAIN_CONTROL_PREV_LEVEL 8
469 #define MAIN_CONTROL_NEXT_LEVEL 9
470 #define MAIN_CONTROL_FIRST_LEVEL 10
471 #define MAIN_CONTROL_LAST_LEVEL 11
472 #define MAIN_CONTROL_LEVEL_NUMBER 12
473 #define MAIN_CONTROL_LEVEL_INFO_1 13
474 #define MAIN_CONTROL_LEVEL_INFO_2 14
475 #define MAIN_CONTROL_LEVEL_NAME 15
476 #define MAIN_CONTROL_LEVEL_AUTHOR 16
477 #define MAIN_CONTROL_LEVEL_YEAR 17
478 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
479 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
480 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
481 #define MAIN_CONTROL_TITLE_1 21
482 #define MAIN_CONTROL_TITLE_2 22
483 #define MAIN_CONTROL_TITLE_3 23
485 static char str_main_text_name[10];
486 static char str_main_text_first_level[10];
487 static char str_main_text_last_level[10];
488 static char str_main_text_level_number[10];
490 static char *main_text_name = str_main_text_name;
491 static char *main_text_first_level = str_main_text_first_level;
492 static char *main_text_last_level = str_main_text_last_level;
493 static char *main_text_level_number = str_main_text_level_number;
494 static char *main_text_levels = "Levelset";
495 static char *main_text_scores = "Hall Of Fame";
496 static char *main_text_editor = "Level Creator";
497 static char *main_text_info = "Info Screen";
498 static char *main_text_game = "Start Game";
499 static char *main_text_setup = "Setup";
500 static char *main_text_quit = "Quit";
501 static char *main_text_level_name = level.name;
502 static char *main_text_level_author = level.author;
503 static char *main_text_level_year = NULL;
504 static char *main_text_level_imported_from = NULL;
505 static char *main_text_level_imported_by = NULL;
506 static char *main_text_level_tested_by = NULL;
507 static char *main_text_title_1 = PROGRAM_TITLE_STRING;
508 static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
509 static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
511 struct MainControlInfo
515 struct MenuPosInfo *pos_button;
518 struct TextPosInfo *pos_text;
521 struct TextPosInfo *pos_input;
525 static struct MainControlInfo main_controls[] =
529 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
530 &menu.main.text.name, &main_text_name,
531 &menu.main.input.name, &setup.player_name,
535 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
536 &menu.main.text.levels, &main_text_levels,
541 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
542 &menu.main.text.scores, &main_text_scores,
547 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
548 &menu.main.text.editor, &main_text_editor,
553 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
554 &menu.main.text.info, &main_text_info,
559 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
560 &menu.main.text.game, &main_text_game,
565 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
566 &menu.main.text.setup, &main_text_setup,
571 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
572 &menu.main.text.quit, &main_text_quit,
576 /* (these two buttons are real gadgets) */
578 MAIN_CONTROL_PREV_LEVEL,
579 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
584 MAIN_CONTROL_NEXT_LEVEL,
585 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
591 MAIN_CONTROL_FIRST_LEVEL,
593 &menu.main.text.first_level, &main_text_first_level,
597 MAIN_CONTROL_LAST_LEVEL,
599 &menu.main.text.last_level, &main_text_last_level,
603 MAIN_CONTROL_LEVEL_NUMBER,
605 &menu.main.text.level_number, &main_text_level_number,
609 MAIN_CONTROL_LEVEL_INFO_1,
611 &menu.main.text.level_info_1, NULL,
615 MAIN_CONTROL_LEVEL_INFO_2,
617 &menu.main.text.level_info_2, NULL,
621 MAIN_CONTROL_LEVEL_NAME,
623 &menu.main.text.level_name, &main_text_level_name,
627 MAIN_CONTROL_LEVEL_AUTHOR,
629 &menu.main.text.level_author, &main_text_level_author,
633 MAIN_CONTROL_LEVEL_YEAR,
635 &menu.main.text.level_year, &main_text_level_year,
639 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
641 &menu.main.text.level_imported_from, &main_text_level_imported_from,
645 MAIN_CONTROL_LEVEL_IMPORTED_BY,
647 &menu.main.text.level_imported_by, &main_text_level_imported_by,
651 MAIN_CONTROL_LEVEL_TESTED_BY,
653 &menu.main.text.level_tested_by, &main_text_level_tested_by,
657 MAIN_CONTROL_TITLE_1,
659 &menu.main.text.title_1, &main_text_title_1,
663 MAIN_CONTROL_TITLE_2,
665 &menu.main.text.title_2, &main_text_title_2,
669 MAIN_CONTROL_TITLE_3,
671 &menu.main.text.title_3, &main_text_title_3,
684 static int getTitleScreenGraphic(int nr, boolean initial)
686 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
689 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
691 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
695 static int getTitleScreenGameMode(boolean initial)
697 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
701 static int getTitleMessageGameMode(boolean initial)
703 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
707 static int getTitleScreenBackground(boolean initial)
709 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
714 static int getTitleMessageBackground(int nr, boolean initial)
716 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
720 static int getTitleBackground(int nr, boolean initial, boolean is_image)
722 int base = (is_image ?
723 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
724 IMG_BACKGROUND_TITLESCREEN_1) :
725 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
726 IMG_BACKGROUND_TITLEMESSAGE_1));
727 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
728 IMG_BACKGROUND_TITLE);
729 int graphic_local = base + nr;
731 if (graphic_info[graphic_local].bitmap != NULL)
732 return graphic_local;
734 if (graphic_info[graphic_global].bitmap != NULL)
735 return graphic_global;
737 return IMG_UNDEFINED;
740 static int getTitleSound(struct TitleControlInfo *tci)
742 boolean is_image = tci->is_image;
743 int initial = tci->initial;
744 int nr = tci->local_nr;
745 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
746 int base = (is_image ?
747 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
748 SND_BACKGROUND_TITLESCREEN_1) :
749 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
750 SND_BACKGROUND_TITLEMESSAGE_1));
751 int sound_global = menu.sound[mode];
752 int sound_local = base + nr;
755 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
756 nr, initial, is_image,
757 sound_global, getSoundListEntry(sound_global)->filename,
758 sound_local, getSoundListEntry(sound_local)->filename);
761 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
764 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
767 return SND_UNDEFINED;
770 static int getTitleMusic(struct TitleControlInfo *tci)
772 boolean is_image = tci->is_image;
773 int initial = tci->initial;
774 int nr = tci->local_nr;
775 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
776 int base = (is_image ?
777 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
778 MUS_BACKGROUND_TITLESCREEN_1) :
779 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
780 MUS_BACKGROUND_TITLEMESSAGE_1));
781 int music_global = menu.music[mode];
782 int music_local = base + nr;
785 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
786 nr, initial, is_image,
787 music_global, getMusicListEntry(music_global)->filename,
788 music_local, getMusicListEntry(music_local)->filename);
791 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
794 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
797 return MUS_UNDEFINED;
800 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
802 boolean is_image = tci->is_image;
803 int initial = tci->initial;
804 int nr = tci->local_nr;
805 struct TitleFadingInfo ti;
809 int graphic = getTitleScreenGraphic(nr, initial);
811 /* initialize fading control values to default title config settings */
812 ti = (initial ? title_initial_default : title_default);
814 /* override default settings with image config settings, if defined */
815 if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
816 ti.fade_mode = graphic_info[graphic].fade_mode;
817 if (graphic_info[graphic].fade_delay > -1)
818 ti.fade_delay = graphic_info[graphic].fade_delay;
819 if (graphic_info[graphic].post_delay > -1)
820 ti.post_delay = graphic_info[graphic].post_delay;
821 if (graphic_info[graphic].auto_delay > -1)
822 ti.auto_delay = graphic_info[graphic].auto_delay;
828 ti.fade_mode = titlemessage_initial[nr].fade_mode;
829 ti.fade_delay = titlemessage_initial[nr].fade_delay;
830 ti.post_delay = titlemessage_initial[nr].post_delay;
831 ti.auto_delay = titlemessage_initial[nr].auto_delay;
835 ti.fade_mode = titlemessage[nr].fade_mode;
836 ti.fade_delay = titlemessage[nr].fade_delay;
837 ti.post_delay = titlemessage[nr].post_delay;
838 ti.auto_delay = titlemessage[nr].auto_delay;
845 static int compareTitleControlInfo(const void *object1, const void *object2)
847 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
848 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
851 if (tci1->initial != tci2->initial)
852 compare_result = (tci1->initial ? -1 : +1);
853 else if (tci1->sort_priority != tci2->sort_priority)
854 compare_result = tci1->sort_priority - tci2->sort_priority;
855 else if (tci1->is_image != tci2->is_image)
856 compare_result = (tci1->is_image ? -1 : +1);
858 compare_result = tci1->local_nr - tci2->local_nr;
860 return compare_result;
863 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
865 int nr, int sort_priority)
867 title_controls[num_title_screens].is_image = is_image;
868 title_controls[num_title_screens].initial = initial;
869 title_controls[num_title_screens].local_nr = nr;
870 title_controls[num_title_screens].sort_priority = sort_priority;
875 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
879 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
881 int graphic = getTitleScreenGraphic(i, initial);
882 Bitmap *bitmap = graphic_info[graphic].bitmap;
883 int sort_priority = graphic_info[graphic].sort_priority;
886 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
889 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
891 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
892 char *filename = getLevelSetTitleMessageFilename(i, initial);
893 int sort_priority = tmi->sort_priority;
895 if (filename != NULL)
896 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
900 static void InitializeTitleControls(boolean show_title_initial)
902 num_title_screens = 0;
904 /* 1st step: initialize title screens for game start (only when starting) */
905 if (show_title_initial)
906 InitializeTitleControls_CheckTitleInfo(TRUE);
908 /* 2nd step: initialize title screens for current level set */
909 InitializeTitleControls_CheckTitleInfo(FALSE);
911 /* sort title screens according to sort_priority and title number */
912 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
913 compareTitleControlInfo);
916 static boolean visibleMenuPos(struct MenuPosInfo *pos)
918 return (pos != NULL && pos->x != -1 && pos->y != -1);
921 static boolean visibleTextPos(struct TextPosInfo *pos)
923 return (pos != NULL && pos->x != -1 && pos->y != -1);
926 static void InitializeMainControls()
928 boolean local_team_mode = (!options.network && setup.team_mode);
931 /* set main control text values to dynamically determined values */
932 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
934 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
935 menu.main.text.first_level.size));
936 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
937 menu.main.text.last_level.size));
938 strcpy(main_text_level_number, int2str(level_nr,
939 menu.main.text.level_number.size));
941 main_text_level_year = leveldir_current->year;
942 main_text_level_imported_from = leveldir_current->imported_from;
943 main_text_level_imported_by = leveldir_current->imported_by;
944 main_text_level_tested_by = leveldir_current->tested_by;
946 /* set main control screen positions to dynamically determined values */
947 for (i = 0; main_controls[i].nr != -1; i++)
949 struct MainControlInfo *mci = &main_controls[i];
951 struct MenuPosInfo *pos_button = mci->pos_button;
952 struct TextPosInfo *pos_text = mci->pos_text;
953 struct TextPosInfo *pos_input = mci->pos_input;
954 char *text = (mci->text ? *mci->text : NULL);
955 char *input = (mci->input ? *mci->input : NULL);
956 int button_graphic = mci->button_graphic;
957 int font_text = (pos_text ? pos_text->font : -1);
958 int font_input = (pos_input ? pos_input->font : -1);
960 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
961 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
962 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
963 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
964 int text_chars = (text != NULL ? strlen(text) : 0);
965 int input_chars = (input != NULL ? strlen(input) : 0);
968 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
970 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
971 int text_width = font_text_width * text_chars;
972 int text_height = font_text_height;
973 int input_width = font_input_width * input_chars;
974 int input_height = font_input_height;
976 if (nr == MAIN_CONTROL_NAME)
978 menu.main.input.name.width = input_width;
979 menu.main.input.name.height = input_height;
982 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
984 pos_button->width = button_width;
985 pos_button->height = button_height;
988 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
990 /* calculate size for non-clickable text -- needed for text alignment */
991 boolean calculate_text_size = (pos_button == NULL && text != NULL);
993 if (pos_text->width == -1 || calculate_text_size)
994 pos_text->width = text_width;
995 if (pos_text->height == -1 || calculate_text_size)
996 pos_text->height = text_height;
998 if (visibleMenuPos(pos_button))
1000 if (pos_text->x == -1)
1001 pos_text->x = pos_button->x + pos_button->width;
1002 if (pos_text->y == -1)
1004 pos_button->y + (pos_button->height - pos_text->height) / 2;
1008 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1010 if (visibleTextPos(pos_text))
1012 if (pos_input->x == -1)
1013 pos_input->x = pos_text->x + pos_text->width;
1014 if (pos_input->y == -1)
1015 pos_input->y = pos_text->y;
1018 if (pos_input->width == -1)
1019 pos_input->width = input_width;
1020 if (pos_input->height == -1)
1021 pos_input->height = input_height;
1026 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1027 int graphic, boolean pressed)
1029 struct GraphicInfo *g = &graphic_info[graphic];
1032 int xoffset = (pressed ? g->pressed_xoffset : 0);
1033 int yoffset = (pressed ? g->pressed_yoffset : 0);
1035 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1037 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1038 g->width, g->height, dst_x, dst_y);
1041 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1042 boolean active_input,
1043 boolean pressed_button)
1047 for (i = 0; main_controls[i].nr != -1; i++)
1049 struct MainControlInfo *mci = &main_controls[i];
1051 if (mci->nr == nr || nr == -1)
1053 struct MenuPosInfo *pos_button = mci->pos_button;
1054 struct TextPosInfo *pos_text = mci->pos_text;
1055 struct TextPosInfo *pos_input = mci->pos_input;
1056 char *text = (mci->text ? *mci->text : NULL);
1057 char *input = (mci->input ? *mci->input : NULL);
1058 int button_graphic = mci->button_graphic;
1059 int font_text = (pos_text ? pos_text->font : -1);
1060 int font_input = (pos_input ? pos_input->font : -1);
1064 button_graphic = BUTTON_ACTIVE(button_graphic);
1065 font_text = FONT_ACTIVE(font_text);
1070 font_input = FONT_ACTIVE(font_input);
1073 if (visibleMenuPos(pos_button))
1075 struct MenuPosInfo *pos = pos_button;
1076 int x = mSX + pos->x;
1077 int y = mSY + pos->y;
1079 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1080 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1083 if (visibleTextPos(pos_text) && text != NULL)
1085 struct TextPosInfo *pos = pos_text;
1086 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1087 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1090 /* (check why/if this is needed) */
1091 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1093 DrawText(x, y, text, font_text);
1096 if (visibleTextPos(pos_input) && input != NULL)
1098 struct TextPosInfo *pos = pos_input;
1099 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1100 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1103 /* (check why/if this is needed) */
1104 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1106 DrawText(x, y, input, font_input);
1112 static void DrawCursorAndText_Main(int nr, boolean active_text,
1113 boolean pressed_button)
1115 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1119 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1120 boolean pressed_button)
1122 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1126 static struct MainControlInfo *getMainControlInfo(int nr)
1130 for (i = 0; main_controls[i].nr != -1; i++)
1131 if (main_controls[i].nr == nr)
1132 return &main_controls[i];
1137 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1142 int rect_x = ALIGNED_TEXT_XPOS(rect);
1143 int rect_y = ALIGNED_TEXT_YPOS(rect);
1145 return (x >= rect_x && x < rect_x + rect->width &&
1146 y >= rect_y && y < rect_y + rect->height);
1149 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1154 int rect_x = ALIGNED_TEXT_XPOS(rect);
1155 int rect_y = ALIGNED_TEXT_YPOS(rect);
1158 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1159 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1160 (x >= rect_x && x < rect_x + rect->width &&
1161 y >= rect_y && y < rect_y + rect->height));
1164 return (x >= rect_x && x < rect_x + rect->width &&
1165 y >= rect_y && y < rect_y + rect->height);
1168 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1170 static int cursor_array[MAX_LEV_FIELDY];
1171 int x = mSX + TILEX * xpos;
1172 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1177 cursor_array[ypos] = graphic;
1179 graphic = cursor_array[ypos];
1183 graphic = BUTTON_ACTIVE(graphic);
1185 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1186 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1189 static void initCursor(int ypos, int graphic)
1191 drawCursorExt(0, ypos, FALSE, graphic);
1194 static void drawCursor(int ypos, boolean active)
1196 drawCursorExt(0, ypos, active, -1);
1199 static void drawCursorXY(int xpos, int ypos, int graphic)
1201 drawCursorExt(xpos, ypos, FALSE, graphic);
1204 static void drawChooseTreeCursor(int ypos, boolean active)
1206 int last_game_status = game_status; /* save current game status */
1208 drawCursorExt(0, ypos, active, -1);
1210 game_status = last_game_status; /* restore current game status */
1215 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, PROGRAM_TITLE_STRING);
1216 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING);
1219 int effectiveGameStatus()
1221 if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE)
1222 return GAME_MODE_TITLE;
1227 void DrawTitleScreenImage(int nr, boolean initial)
1229 int graphic = getTitleScreenGraphic(nr, initial);
1230 Bitmap *bitmap = graphic_info[graphic].bitmap;
1231 int width = graphic_info[graphic].width;
1232 int height = graphic_info[graphic].height;
1233 int src_x = graphic_info[graphic].src_x;
1234 int src_y = graphic_info[graphic].src_y;
1240 if (width > WIN_XSIZE)
1242 /* image width too large for window => center image horizontally */
1243 src_x = (width - WIN_XSIZE) / 2;
1247 if (height > WIN_YSIZE)
1249 /* image height too large for window => center image vertically */
1250 src_y = (height - WIN_YSIZE) / 2;
1254 /* always display title screens centered */
1255 dst_x = (WIN_XSIZE - width) / 2;
1256 dst_y = (WIN_YSIZE - height) / 2;
1258 SetDrawBackgroundMask(REDRAW_ALL);
1259 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1261 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1263 if (DrawingOnBackground(dst_x, dst_y))
1264 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1266 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1268 redraw_mask = REDRAW_ALL;
1271 void DrawTitleScreenMessage(int nr, boolean initial)
1273 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1274 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1275 int last_game_status = game_status; /* save current game status */
1277 if (filename == NULL)
1280 /* force TITLE font on title message screen */
1281 game_status = getTitleMessageGameMode(initial);
1283 /* if chars set to "-1", automatically determine by text and font width */
1284 if (tmi->chars == -1)
1285 tmi->chars = tmi->width / getFontWidth(tmi->font);
1287 tmi->width = tmi->chars * getFontWidth(tmi->font);
1289 /* if lines set to "-1", automatically determine by text and font height */
1290 if (tmi->lines == -1)
1291 tmi->lines = tmi->height / getFontHeight(tmi->font);
1293 tmi->height = tmi->lines * getFontHeight(tmi->font);
1295 SetDrawBackgroundMask(REDRAW_ALL);
1296 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1298 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1300 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1301 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1302 tmi->autowrap, tmi->centered, tmi->parse_comments);
1304 game_status = last_game_status; /* restore current game status */
1307 void DrawTitleScreen()
1309 KeyboardAutoRepeatOff();
1311 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1316 boolean CheckTitleScreen(boolean levelset_has_changed)
1318 static boolean show_title_initial = TRUE;
1319 boolean show_titlescreen = FALSE;
1321 /* needed to be able to skip title screen, if no image or message defined */
1322 InitializeTitleControls(show_title_initial);
1324 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1325 show_titlescreen = TRUE;
1327 /* show initial title images and messages only once at program start */
1328 show_title_initial = FALSE;
1330 return (show_titlescreen && num_title_screens > 0);
1333 void DrawMainMenuExt(int fade_mask, boolean do_fading)
1335 static LevelDirTree *leveldir_last_valid = NULL;
1336 boolean levelset_has_changed = FALSE;
1338 LimitScreenUpdates(FALSE);
1340 FadeSetLeaveScreen();
1342 /* do not fade out here -- function may continue and fade on editor screen */
1345 FadeSoundsAndMusic();
1347 KeyboardAutoRepeatOn();
1350 audio.sound_deactivated = FALSE;
1354 /* needed if last screen was the playing screen, invoked from level editor */
1355 if (level_editor_test_game)
1357 game_status = GAME_MODE_EDITOR;
1363 /* needed if last screen was the setup screen and fullscreen state changed */
1364 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1365 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1367 /* leveldir_current may be invalid (level group, parent link) */
1368 if (!validLevelSeries(leveldir_current))
1369 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1371 if (leveldir_current != leveldir_last_valid)
1372 levelset_has_changed = TRUE;
1374 /* store valid level series information */
1375 leveldir_last_valid = leveldir_current;
1377 init_last = init; /* switch to new busy animation */
1379 /* needed if last screen (level choice) changed graphics, sounds or music */
1380 ReloadCustomArtwork(0);
1382 if (redraw_mask & REDRAW_ALL)
1383 fade_mask = REDRAW_ALL;
1387 /* needed if different viewport properties defined for menues */
1388 ChangeViewportPropertiesIfNeeded();
1390 /* needed if last screen was the editor screen */
1391 UndrawSpecialEditorDoor();
1393 SetDrawtoField(DRAW_BACKBUFFER);
1395 if (CheckTitleScreen(levelset_has_changed))
1397 game_status = GAME_MODE_TITLE;
1404 /* level_nr may have been set to value over handicap with level editor */
1405 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1406 level_nr = leveldir_current->handicap_level;
1408 LoadLevel(level_nr);
1409 LoadScore(level_nr);
1411 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1412 SetDrawDeactivationMask(REDRAW_NONE);
1413 SetDrawBackgroundMask(REDRAW_FIELD);
1415 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1417 if (fade_mask == REDRAW_ALL)
1418 RedrawGlobalBorder();
1422 InitializeMainControls();
1424 DrawCursorAndText_Main(-1, FALSE, FALSE);
1425 DrawPreviewLevelInitial();
1427 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1430 if (TAPE_IS_EMPTY(tape))
1432 DrawCompleteVideoDisplay();
1437 /* create gadgets for main menu screen */
1438 FreeScreenGadgets();
1439 CreateScreenGadgets();
1441 /* map gadgets for main menu screen */
1443 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1445 /* copy actual game door content to door double buffer for OpenDoor() */
1446 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1448 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1450 DrawMaskedBorder(REDRAW_ALL);
1455 /* update screen area with special editor door */
1456 redraw_mask |= REDRAW_ALL;
1459 SetMouseCursor(CURSOR_DEFAULT);
1463 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1466 void DrawAndFadeInMainMenu(int fade_mask)
1468 DrawMainMenuExt(fade_mask, TRUE);
1473 DrawMainMenuExt(REDRAW_ALL, FALSE);
1476 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1477 static void gotoTopLevelDir()
1479 /* move upwards to top level directory */
1480 while (leveldir_current->node_parent)
1482 /* write a "path" into level tree for easy navigation to last level */
1483 if (leveldir_current->node_parent->node_group->cl_first == -1)
1485 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1486 int leveldir_pos = posTreeInfo(leveldir_current);
1487 int num_page_entries;
1488 int cl_first, cl_cursor;
1490 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1491 num_page_entries = num_leveldirs;
1493 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1495 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1496 cl_cursor = leveldir_pos - cl_first;
1498 leveldir_current->node_parent->node_group->cl_first = cl_first;
1499 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1502 leveldir_current = leveldir_current->node_parent;
1507 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1509 static unsigned int title_delay = 0;
1510 static int title_screen_nr = 0;
1511 static int last_sound = -1, last_music = -1;
1512 boolean return_to_main_menu = FALSE;
1513 boolean use_fading_main_menu = TRUE;
1514 struct TitleControlInfo *tci;
1515 struct TitleFadingInfo fading_default;
1516 struct TitleFadingInfo fading_last = fading;
1517 struct TitleFadingInfo fading_next;
1520 if (button == MB_MENU_INITIALIZE)
1523 title_screen_nr = 0;
1524 tci = &title_controls[title_screen_nr];
1526 last_sound = SND_UNDEFINED;
1527 last_music = MUS_UNDEFINED;
1529 if (game_status == GAME_MODE_INFO)
1531 if (num_title_screens == 0)
1533 DrawInfoScreen_NotAvailable("Title screen information:",
1534 "No title screen for this level set.");
1539 FadeSoundsAndMusic();
1541 FadeOut(REDRAW_ALL);
1545 DrawTitleScreenImage(tci->local_nr, tci->initial);
1547 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1549 fading_default = (tci->initial ? title_initial_default : title_default);
1551 fading = fading_next = getTitleFading(tci);
1553 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) &&
1554 fading_next.fade_mode & FADE_TYPE_TRANSFORM)
1556 fading.fade_mode = FADE_MODE_FADE;
1557 fading.fade_delay = fading_default.fade_delay;
1560 sound = getTitleSound(tci);
1561 music = getTitleMusic(tci);
1563 if (sound != last_sound)
1564 PlayMenuSoundExt(sound);
1565 if (music != last_music)
1566 PlayMenuMusicExt(music);
1571 SetMouseCursor(CURSOR_NONE);
1575 fading = fading_next;
1577 DelayReached(&title_delay, 0); /* reset delay counter */
1582 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1583 button = MB_MENU_CHOICE;
1585 if (button == MB_MENU_LEAVE)
1587 return_to_main_menu = TRUE;
1588 use_fading_main_menu = FALSE;
1590 else if (button == MB_MENU_CHOICE)
1592 if (game_status == GAME_MODE_INFO && num_title_screens == 0)
1594 FadeSetEnterScreen();
1596 info_mode = INFO_MODE_MAIN;
1597 DrawAndFadeInInfoScreen(REDRAW_FIELD);
1603 tci = &title_controls[title_screen_nr];
1605 if (title_screen_nr < num_title_screens)
1607 sound = getTitleSound(tci);
1608 music = getTitleMusic(tci);
1610 if (sound == SND_UNDEFINED || sound != last_sound)
1612 if (music == MUS_UNDEFINED || music != last_music)
1615 FadeOut(REDRAW_ALL);
1618 DrawTitleScreenImage(tci->local_nr, tci->initial);
1620 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1622 fading_next = getTitleFading(tci);
1624 sound = getTitleSound(tci);
1625 music = getTitleMusic(tci);
1627 if (sound != last_sound)
1628 PlayMenuSoundExt(sound);
1629 if (music != last_music)
1630 PlayMenuMusicExt(music);
1635 /* last screen already faded out, next screen has no animation */
1636 if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) &&
1637 fading_next.fade_mode == FADE_MODE_NONE)
1638 fading = fading_next;
1642 fading = fading_next;
1644 DelayReached(&title_delay, 0); /* reset delay counter */
1648 FadeSoundsAndMusic();
1650 return_to_main_menu = TRUE;
1654 if (return_to_main_menu)
1656 SetMouseCursor(CURSOR_DEFAULT);
1658 if (game_status == GAME_MODE_INFO)
1660 int fade_mask = (num_title_screens == 0 ? REDRAW_FIELD : REDRAW_ALL);
1662 info_mode = INFO_MODE_MAIN;
1664 DrawInfoScreenExt(fade_mask, use_fading_main_menu);
1666 else /* default: return to main menu */
1668 game_status = GAME_MODE_MAIN;
1670 DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu);
1675 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1677 int old_level_nr = level_nr;
1680 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1681 new_level_nr = selected_level_nr;
1683 new_level_nr = old_level_nr + step * direction;
1685 if (new_level_nr < leveldir_current->first_level)
1686 new_level_nr = leveldir_current->first_level;
1687 if (new_level_nr > leveldir_current->last_level)
1688 new_level_nr = leveldir_current->last_level;
1690 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1692 /* skipping levels is only allowed when trying to skip single level */
1693 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1694 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1696 leveldir_current->handicap_level++;
1697 SaveLevelSetup_SeriesInfo();
1700 new_level_nr = leveldir_current->handicap_level;
1703 if (new_level_nr != old_level_nr)
1705 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1707 PlaySound(SND_MENU_ITEM_SELECTING);
1709 level_nr = new_level_nr;
1711 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1712 int2str(level_nr, menu.main.text.level_number.size),
1713 mci->pos_text->font);
1715 LoadLevel(level_nr);
1716 DrawPreviewLevelInitial();
1720 DrawCompleteVideoDisplay();
1722 /* needed because DrawPreviewLevelInitial() takes some time */
1724 /* SyncDisplay(); */
1728 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1730 static int choice = MAIN_CONTROL_GAME;
1731 static boolean button_pressed_last = FALSE;
1732 boolean button_pressed = FALSE;
1736 if (button == MB_MENU_INITIALIZE)
1738 DrawCursorAndText_Main(choice, TRUE, FALSE);
1743 if (mx || my) /* mouse input */
1747 for (i = 0; main_controls[i].nr != -1; i++)
1749 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1750 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1751 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1753 pos = main_controls[i].nr;
1759 // handle pressed/unpressed state for active/inactive menu buttons
1760 // (if pos != -1, "i" contains index position corresponding to "pos")
1762 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1763 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1764 button_pressed = TRUE;
1766 if (button_pressed != button_pressed_last)
1767 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1769 else if (dx || dy) /* keyboard input */
1771 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1772 choice == MAIN_CONTROL_SETUP))
1773 button = MB_MENU_CHOICE;
1778 if (pos == MAIN_CONTROL_LEVELS && dx != 0 && button)
1780 HandleMainMenu_SelectLevel(1, (dx < 0 ? -1 : +1), NO_DIRECT_LEVEL_SELECT);
1782 else if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1784 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1786 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
1788 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
1790 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
1792 game_status = GAME_MODE_LEVELNR;
1794 ChangeViewportPropertiesIfNeeded();
1796 DrawChooseLevelNr();
1798 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
1804 PlaySound(SND_MENU_ITEM_ACTIVATING);
1806 DrawCursorAndText_Main(choice, FALSE, FALSE);
1807 DrawCursorAndText_Main(pos, TRUE, button_pressed);
1814 PlaySound(SND_MENU_ITEM_SELECTING);
1816 if (pos == MAIN_CONTROL_NAME)
1818 game_status = GAME_MODE_PSEUDO_TYPENAME;
1820 HandleTypeName(strlen(setup.player_name), 0);
1822 else if (pos == MAIN_CONTROL_LEVELS)
1826 game_status = GAME_MODE_LEVELS;
1828 SaveLevelSetup_LastSeries();
1829 SaveLevelSetup_SeriesInfo();
1831 #if defined(CREATE_SPECIAL_EDITION_RND_JUE)
1835 ChangeViewportPropertiesIfNeeded();
1837 DrawChooseLevelSet();
1840 else if (pos == MAIN_CONTROL_SCORES)
1842 game_status = GAME_MODE_SCORES;
1844 ChangeViewportPropertiesIfNeeded();
1848 else if (pos == MAIN_CONTROL_EDITOR)
1850 if (leveldir_current->readonly &&
1851 !strEqual(setup.player_name, "Artsoft"))
1852 Request("This level is read only!", REQ_CONFIRM);
1854 CloseDoor(DOOR_CLOSE_2);
1856 game_status = GAME_MODE_EDITOR;
1858 FadeSetEnterScreen();
1862 else if (pos == MAIN_CONTROL_INFO)
1864 game_status = GAME_MODE_INFO;
1865 info_mode = INFO_MODE_MAIN;
1867 ChangeViewportPropertiesIfNeeded();
1871 else if (pos == MAIN_CONTROL_GAME)
1873 StartGameActions(options.network, setup.autorecord, level.random_seed);
1875 else if (pos == MAIN_CONTROL_SETUP)
1877 game_status = GAME_MODE_SETUP;
1878 setup_mode = SETUP_MODE_MAIN;
1880 ChangeViewportPropertiesIfNeeded();
1884 else if (pos == MAIN_CONTROL_QUIT)
1886 SaveLevelSetup_LastSeries();
1887 SaveLevelSetup_SeriesInfo();
1889 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
1890 game_status = GAME_MODE_QUIT;
1895 button_pressed_last = button_pressed;
1899 /* ========================================================================= */
1900 /* info screen functions */
1901 /* ========================================================================= */
1903 static struct TokenInfo *info_info;
1904 static int num_info_info;
1906 static void execInfoTitleScreen()
1908 info_mode = INFO_MODE_TITLE;
1913 static void execInfoElements()
1915 info_mode = INFO_MODE_ELEMENTS;
1920 static void execInfoMusic()
1922 info_mode = INFO_MODE_MUSIC;
1927 static void execInfoCredits()
1929 info_mode = INFO_MODE_CREDITS;
1934 static void execInfoProgram()
1936 info_mode = INFO_MODE_PROGRAM;
1941 static void execInfoVersion()
1943 info_mode = INFO_MODE_VERSION;
1948 static void execInfoLevelSet()
1950 info_mode = INFO_MODE_LEVELSET;
1955 static void execExitInfo()
1957 game_status = GAME_MODE_MAIN;
1959 DrawMainMenuExt(REDRAW_FIELD, FALSE);
1962 static struct TokenInfo info_info_main[] =
1964 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
1965 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
1966 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
1967 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
1968 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
1969 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
1970 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
1971 { TYPE_EMPTY, NULL, "" },
1972 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
1977 static void DrawCursorAndText_Info(int pos, boolean active)
1979 int xpos = MENU_SCREEN_START_XPOS;
1980 int ypos = MENU_SCREEN_START_YPOS + pos;
1981 int font_nr = FONT_MENU_1;
1984 font_nr = FONT_ACTIVE(font_nr);
1986 DrawText(mSX + xpos * 32, mSY + ypos * 32, info_info[pos].text, font_nr);
1988 if (info_info[pos].type & ~TYPE_SKIP_ENTRY)
1989 drawCursor(pos, active);
1992 static void DrawInfoScreen_Main(int fade_mask, boolean do_fading)
1997 CloseDoor(DOOR_CLOSE_2);
1999 /* (needed after displaying title screens which disable auto repeat) */
2000 KeyboardAutoRepeatOn();
2002 FadeSetLeaveScreen();
2006 if (fade_mask == REDRAW_ALL)
2008 RedrawGlobalBorder();
2010 OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2015 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2017 info_info = info_info_main;
2020 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
2022 if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2023 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2024 else if (info_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2025 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2026 else if (info_info[i].type & ~TYPE_SKIP_ENTRY)
2027 initCursor(i, IMG_MENU_BUTTON);
2029 DrawCursorAndText_Info(i, FALSE);
2034 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2039 DrawMaskedBorder(fade_mask);
2046 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2048 static int choice_store[MAX_INFO_MODES];
2049 int choice = choice_store[info_mode]; /* always starts with 0 */
2053 if (button == MB_MENU_INITIALIZE)
2055 /* advance to first valid menu entry */
2056 while (choice < num_info_info &&
2057 info_info[choice].type & TYPE_SKIP_ENTRY)
2059 choice_store[info_mode] = choice;
2061 DrawCursorAndText_Info(choice, TRUE);
2065 else if (button == MB_MENU_LEAVE)
2067 for (y = 0; y < num_info_info; y++)
2069 if (info_info[y].type & TYPE_LEAVE_MENU)
2071 void (*menu_callback_function)(void) = info_info[y].value;
2075 menu_callback_function();
2077 break; /* absolutely needed because function changes 'info_info'! */
2084 if (mx || my) /* mouse input */
2086 x = (mx - mSX) / 32;
2087 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2089 else if (dx || dy) /* keyboard input */
2093 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2095 if (info_info[choice].type & menu_navigation_type ||
2096 info_info[choice].type & TYPE_ENTER_SCREEN ||
2097 info_info[choice].type & TYPE_BOOLEAN_STYLE ||
2098 info_info[choice].type & TYPE_YES_NO_AUTO)
2099 button = MB_MENU_CHOICE;
2104 /* jump to next non-empty menu entry (up or down) */
2105 while (y > 0 && y < num_info_info - 1 &&
2106 info_info[y].type & TYPE_SKIP_ENTRY)
2110 if (IN_VIS_MENU(x, y) &&
2111 y >= 0 && y < num_info_info && info_info[y].type & ~TYPE_SKIP_ENTRY)
2117 PlaySound(SND_MENU_ITEM_ACTIVATING);
2119 DrawCursorAndText_Info(choice, FALSE);
2120 DrawCursorAndText_Info(y, TRUE);
2122 choice = choice_store[info_mode] = y;
2125 else if (!(info_info[y].type & TYPE_GHOSTED))
2127 PlaySound(SND_MENU_ITEM_SELECTING);
2129 if (info_info[y].type & TYPE_ENTER_OR_LEAVE)
2131 void (*menu_callback_function)(void) = info_info[choice].value;
2133 FadeSetFromType(info_info[y].type);
2135 menu_callback_function();
2141 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2143 int ystart1 = mSY - SY + 100;
2144 int ystart2 = mSY - SY + 150;
2145 int ybottom = mSY - SY + SYSIZE - 20;
2147 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2149 FadeOut(REDRAW_FIELD);
2154 DrawTextSCentered(ystart1, FONT_TEXT_1, text_title);
2155 DrawTextSCentered(ystart2, FONT_TEXT_2, text_error);
2157 DrawTextSCentered(ybottom, FONT_TEXT_4,
2158 "Press any key or button for info menu");
2160 FadeIn(REDRAW_FIELD);
2163 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2165 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2166 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2167 int xstart = mSX + MENU_SCREEN_INFO_XSTART;
2168 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2169 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2170 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2171 int ystep = MENU_SCREEN_INFO_YSTEP;
2172 int element, action, direction;
2180 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2181 infoscreen_step[i] = infoscreen_frame[i] = 0;
2186 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Elements:");
2188 DrawTextSCentered(ybottom, FONT_TEXT_4,
2189 "Press any key or button for next page");
2195 while (helpanim_info[j].element != HELPANIM_LIST_END)
2197 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2202 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2211 j += infoscreen_step[i - start];
2213 element = helpanim_info[j].element;
2214 action = helpanim_info[j].action;
2215 direction = helpanim_info[j].direction;
2218 element = EL_UNKNOWN;
2220 if (action != -1 && direction != -1)
2221 graphic = el_act_dir2img(element, action, direction);
2222 else if (action != -1)
2223 graphic = el_act2img(element, action);
2224 else if (direction != -1)
2225 graphic = el_dir2img(element, direction);
2227 graphic = el2img(element);
2229 delay = helpanim_info[j++].delay;
2234 if (infoscreen_frame[i - start] == 0)
2237 infoscreen_frame[i - start] = delay - 1;
2241 sync_frame = delay - infoscreen_frame[i - start];
2242 infoscreen_frame[i - start]--;
2245 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2247 if (!infoscreen_frame[i - start])
2248 infoscreen_step[i - start] = 0;
2252 if (!infoscreen_frame[i - start])
2253 infoscreen_step[i - start]++;
2254 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2260 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2262 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2263 graphic, sync_frame, USE_MASKING);
2266 DrawInfoScreen_HelpText(element, action, direction, i - start);
2271 redraw_mask |= REDRAW_FIELD;
2276 static char *getHelpText(int element, int action, int direction)
2278 char token[MAX_LINE_LEN];
2280 strcpy(token, element_info[element].token_name);
2283 strcat(token, element_action_info[action].suffix);
2285 if (direction != -1)
2286 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2288 return getHashEntry(helptext_info, token);
2291 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2293 int font_nr = FONT_INFO_ELEMENTS;
2294 int font_width = getFontWidth(font_nr);
2295 int sx = mSX + MINI_TILEX + TILEX + MINI_TILEX;
2296 int sy = mSY + 65 + 2 * 32 + 1;
2297 int ystep = TILEY + 4;
2298 int pad_x = sx - SX;
2299 int max_chars_per_line = (SXSIZE - pad_x - MINI_TILEX) / font_width;
2300 int max_lines_per_text = 2;
2303 if (action != -1 && direction != -1) /* element.action.direction */
2304 text = getHelpText(element, action, direction);
2306 if (text == NULL && action != -1) /* element.action */
2307 text = getHelpText(element, action, -1);
2309 if (text == NULL && direction != -1) /* element.direction */
2310 text = getHelpText(element, -1, direction);
2312 if (text == NULL) /* base element */
2313 text = getHelpText(element, -1, -1);
2315 if (text == NULL) /* not found */
2316 text = "No description available";
2318 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2319 sy += getFontHeight(font_nr) / 2;
2321 DrawTextBuffer(sx, sy + ypos * ystep, text, font_nr,
2322 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2323 TRUE, FALSE, FALSE);
2326 void DrawInfoScreen_TitleScreen()
2331 void HandleInfoScreen_TitleScreen(int button)
2333 HandleTitleScreen(0, 0, 0, 0, button);
2336 void DrawInfoScreen_Elements()
2338 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2340 FadeOut(REDRAW_FIELD);
2345 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2347 FadeIn(REDRAW_FIELD);
2352 void HandleInfoScreen_Elements(int button)
2354 static unsigned int info_delay = 0;
2355 static int num_anims;
2356 static int num_pages;
2358 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2361 if (button == MB_MENU_INITIALIZE)
2363 boolean new_element = TRUE;
2367 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2369 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2371 else if (new_element)
2374 new_element = FALSE;
2378 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2382 if (button == MB_MENU_LEAVE)
2384 PlaySound(SND_MENU_ITEM_SELECTING);
2386 info_mode = INFO_MODE_MAIN;
2391 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2393 if (button != MB_MENU_INITIALIZE)
2395 PlaySound(SND_MENU_ITEM_SELECTING);
2400 if (page >= num_pages)
2402 FadeSoundsAndMusic();
2404 info_mode = INFO_MODE_MAIN;
2405 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2411 FadeSetNextScreen();
2413 if (button != MB_MENU_INITIALIZE)
2414 FadeOut(REDRAW_FIELD);
2416 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2418 if (button != MB_MENU_INITIALIZE)
2419 FadeIn(REDRAW_FIELD);
2423 if (DelayReached(&info_delay, GameFrameDelay))
2424 if (page < num_pages)
2425 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2427 PlayMenuSoundIfLoop();
2431 void DrawInfoScreen_Music()
2433 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2435 FadeOut(REDRAW_FIELD);
2442 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2444 FadeIn(REDRAW_FIELD);
2447 void HandleInfoScreen_Music(int button)
2449 static struct MusicFileInfo *list = NULL;
2450 int ystart1 = mSY - SY + 100;
2451 int ystart2 = mSY - SY + 150;
2452 int ybottom = mSY - SY + SYSIZE - 20;
2455 if (button == MB_MENU_INITIALIZE)
2457 list = music_file_info;
2461 FadeSoundsAndMusic();
2466 DrawTextSCentered(ystart1, FONT_TEXT_1,
2467 "No music info for this level set.");
2469 DrawTextSCentered(ybottom, FONT_TEXT_4,
2470 "Press any key or button for info menu");
2476 if (button == MB_MENU_LEAVE)
2478 PlaySound(SND_MENU_ITEM_SELECTING);
2480 FadeSoundsAndMusic();
2482 info_mode = INFO_MODE_MAIN;
2487 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2491 if (button != MB_MENU_INITIALIZE)
2493 PlaySound(SND_MENU_ITEM_SELECTING);
2501 FadeSoundsAndMusic();
2503 info_mode = INFO_MODE_MAIN;
2504 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2509 FadeSoundsAndMusic();
2511 if (list != music_file_info)
2512 FadeSetNextScreen();
2514 if (button != MB_MENU_INITIALIZE)
2515 FadeOut(REDRAW_FIELD);
2522 int sound = list->music;
2524 if (sound_info[sound].loop)
2525 PlaySoundLoop(sound);
2529 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Sounds:");
2533 PlayMusic(list->music);
2535 DrawTextSCentered(ystart1, FONT_TEXT_1, "The Game Background Music:");
2538 if (!strEqual(list->title, UNKNOWN_NAME))
2540 if (!strEqual(list->title_header, UNKNOWN_NAME))
2541 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->title_header);
2543 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->title);
2546 if (!strEqual(list->artist, UNKNOWN_NAME))
2548 if (!strEqual(list->artist_header, UNKNOWN_NAME))
2549 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->artist_header);
2551 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "by");
2553 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->artist);
2556 if (!strEqual(list->album, UNKNOWN_NAME))
2558 if (!strEqual(list->album_header, UNKNOWN_NAME))
2559 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->album_header);
2561 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the album");
2563 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "\"%s\"", list->album);
2566 if (!strEqual(list->year, UNKNOWN_NAME))
2568 if (!strEqual(list->year_header, UNKNOWN_NAME))
2569 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, list->year_header);
2571 DrawTextSCentered(ystart2 + y++ * dy, FONT_TEXT_2, "from the year");
2573 DrawTextFCentered(ystart2 + y++ * dy, FONT_TEXT_3, "%s", list->year);
2576 DrawTextSCentered(ybottom, FONT_TEXT_4,
2577 "Press any key or button for next page");
2579 if (button != MB_MENU_INITIALIZE)
2580 FadeIn(REDRAW_FIELD);
2583 if (list != NULL && list->is_sound && sound_info[list->music].loop)
2584 PlaySoundLoop(list->music);
2587 static void DrawInfoScreen_CreditsScreen(int screen_nr)
2589 int ystart1 = mSY - SY + 100;
2590 int ystart2 = mSY - SY + 150;
2591 int ybottom = mSY - SY + SYSIZE - 20;
2597 DrawTextSCentered(ystart1, FONT_TEXT_1, "Credits:");
2601 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2602 "Special thanks to");
2603 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2605 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2607 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2608 "\"Boulder Dash\"");
2609 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2611 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2613 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2615 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2616 "First Star Software");
2618 else if (screen_nr == 1)
2620 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2621 "Special thanks to");
2622 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2623 "Klaus Heinz & Volker Wertich");
2624 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2626 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2627 "\"Emerald Mine\"");
2628 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2630 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2632 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2634 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2637 else if (screen_nr == 2)
2639 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2640 "Special thanks to");
2641 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2642 "Michael Stopp & Philip Jespersen");
2643 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2645 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2647 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2649 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2651 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2653 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2654 "Digital Integration");
2656 else if (screen_nr == 3)
2658 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2659 "Special thanks to");
2660 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2661 "Hiroyuki Imabayashi");
2662 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2664 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2666 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2668 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2670 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2672 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_3,
2675 else if (screen_nr == 4)
2677 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2678 "Special thanks to");
2679 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2681 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2683 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2684 "J\xfcrgen Bonhagen");
2685 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2686 "for the continuous creation");
2687 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2688 "of outstanding level sets");
2690 else if (screen_nr == 5)
2692 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2694 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2696 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2697 "for ideas and inspiration by");
2698 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2701 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_2,
2703 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_3,
2705 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2706 "for ideas and inspiration by");
2707 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3,
2710 else if (screen_nr == 6)
2712 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2714 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2717 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2718 "for the code base used for the");
2719 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
2720 "native Emerald Mine engine");
2722 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2723 "for the new Emerald Mine engine");
2726 else if (screen_nr == 7)
2728 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2730 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_3,
2732 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_2,
2733 "for the initial DOS port");
2735 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2737 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2739 DrawTextSCentered(ystart2 + 6 * ystep, FONT_TEXT_2,
2740 "for some additional toons");
2742 else if (screen_nr == 8)
2744 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2745 "And not to forget:");
2746 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2748 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2749 "All those who contributed");
2750 DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_3,
2751 "levels to this game");
2752 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_3,
2756 DrawTextSCentered(ybottom, FONT_TEXT_4,
2757 "Press any key or button for next page");
2760 void DrawInfoScreen_Credits()
2762 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
2764 FadeSoundsAndMusic();
2766 FadeOut(REDRAW_FIELD);
2768 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
2770 FadeIn(REDRAW_FIELD);
2773 void HandleInfoScreen_Credits(int button)
2775 static int screen_nr = 0;
2776 int num_screens = 9;
2778 if (button == MB_MENU_INITIALIZE)
2782 // DrawInfoScreen_CreditsScreen(screen_nr);
2785 if (button == MB_MENU_LEAVE)
2787 PlaySound(SND_MENU_ITEM_SELECTING);
2789 info_mode = INFO_MODE_MAIN;
2794 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2796 if (button != MB_MENU_INITIALIZE)
2798 PlaySound(SND_MENU_ITEM_SELECTING);
2803 if (screen_nr >= num_screens)
2805 FadeSoundsAndMusic();
2807 info_mode = INFO_MODE_MAIN;
2808 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2814 FadeSetNextScreen();
2816 if (button != MB_MENU_INITIALIZE)
2817 FadeOut(REDRAW_FIELD);
2819 DrawInfoScreen_CreditsScreen(screen_nr);
2821 if (button != MB_MENU_INITIALIZE)
2822 FadeIn(REDRAW_FIELD);
2826 PlayMenuSoundIfLoop();
2830 void DrawInfoScreen_Program()
2832 int ystart1 = mSY - SY + 100;
2833 int ystart2 = mSY - SY + 150;
2834 int ybottom = mSY - SY + SYSIZE - 20;
2837 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
2839 FadeOut(REDRAW_FIELD);
2844 DrawTextSCentered(ystart1, FONT_TEXT_1, "Program Information:");
2846 DrawTextSCentered(ystart2 + 0 * ystep, FONT_TEXT_2,
2847 "This game is Freeware!");
2848 DrawTextSCentered(ystart2 + 1 * ystep, FONT_TEXT_2,
2849 "If you like it, send e-mail to:");
2850 DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
2851 PROGRAM_EMAIL_STRING);
2852 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
2853 "More information and levels:");
2854 DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
2855 PROGRAM_WEBSITE_STRING);
2856 DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
2857 "If you have created new levels,");
2858 DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
2859 "send them to me to include them!");
2860 DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
2863 DrawTextSCentered(ybottom, FONT_TEXT_4,
2864 "Press any key or button for info menu");
2866 FadeIn(REDRAW_FIELD);
2869 void HandleInfoScreen_Program(int button)
2871 if (button == MB_MENU_LEAVE)
2873 PlaySound(SND_MENU_ITEM_SELECTING);
2875 info_mode = INFO_MODE_MAIN;
2880 else if (button == MB_MENU_CHOICE)
2882 PlaySound(SND_MENU_ITEM_SELECTING);
2884 FadeSoundsAndMusic();
2886 info_mode = INFO_MODE_MAIN;
2887 DrawAndFadeInInfoScreen(REDRAW_FIELD);
2891 PlayMenuSoundIfLoop();
2895 void DrawInfoScreen_Version()
2897 int font_header = FONT_TEXT_3;
2898 int font_text = FONT_TEXT_2;
2899 int xstep = getFontWidth(font_text);
2900 int ystep = getFontHeight(font_text);
2901 int ystart1 = mSY - SY + 100;
2902 int ystart2 = mSY - SY + 150;
2903 int ybottom = mSY - SY + SYSIZE - 20;
2904 int xstart1 = mSX - SX + 2 * xstep;
2905 int xstart2 = mSX - SX + 18 * xstep;
2906 int xstart3 = mSX - SX + 28 * xstep;
2907 SDL_version sdl_version_compiled;
2908 const SDL_version *sdl_version_linked;
2909 int driver_name_len = 10;
2910 #if defined(TARGET_SDL2)
2911 SDL_version sdl_version_linked_ext;
2912 const char *driver_name = NULL;
2914 char driver_name[driver_name_len];
2917 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
2919 FadeOut(REDRAW_FIELD);
2924 DrawTextSCentered(ystart1, FONT_TEXT_1, "Version Information:");
2926 DrawTextF(xstart1, ystart2, font_header, "Name");
2927 DrawTextF(xstart2, ystart2, font_text, PROGRAM_TITLE_STRING);
2930 DrawTextF(xstart1, ystart2, font_header, "Version");
2931 DrawTextF(xstart2, ystart2, font_text, getProgramVersionString());
2934 DrawTextF(xstart1, ystart2, font_header, "Platform");
2935 DrawTextF(xstart2, ystart2, font_text, PLATFORM_STRING);
2938 DrawTextF(xstart1, ystart2, font_header, "Target");
2939 DrawTextF(xstart2, ystart2, font_text, TARGET_STRING);
2942 DrawTextF(xstart1, ystart2, font_header, "Compile time");
2943 DrawTextF(xstart2, ystart2, font_text, getCompileDateString());
2945 ystart2 += 3 * ystep;
2946 DrawTextF(xstart1, ystart2, font_header, "Library");
2947 DrawTextF(xstart2, ystart2, font_header, "compiled");
2948 DrawTextF(xstart3, ystart2, font_header, "linked");
2950 SDL_VERSION(&sdl_version_compiled);
2951 #if defined(TARGET_SDL2)
2952 SDL_GetVersion(&sdl_version_linked_ext);
2953 sdl_version_linked = &sdl_version_linked_ext;
2955 sdl_version_linked = SDL_Linked_Version();
2958 ystart2 += 2 * ystep;
2959 DrawTextF(xstart1, ystart2, font_text, "SDL");
2960 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2961 sdl_version_compiled.major,
2962 sdl_version_compiled.minor,
2963 sdl_version_compiled.patch);
2964 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2965 sdl_version_linked->major,
2966 sdl_version_linked->minor,
2967 sdl_version_linked->patch);
2969 SDL_IMAGE_VERSION(&sdl_version_compiled);
2970 sdl_version_linked = IMG_Linked_Version();
2973 DrawTextF(xstart1, ystart2, font_text, "SDL_image");
2974 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2975 sdl_version_compiled.major,
2976 sdl_version_compiled.minor,
2977 sdl_version_compiled.patch);
2978 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2979 sdl_version_linked->major,
2980 sdl_version_linked->minor,
2981 sdl_version_linked->patch);
2983 SDL_MIXER_VERSION(&sdl_version_compiled);
2984 sdl_version_linked = Mix_Linked_Version();
2987 DrawTextF(xstart1, ystart2, font_text, "SDL_mixer");
2988 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
2989 sdl_version_compiled.major,
2990 sdl_version_compiled.minor,
2991 sdl_version_compiled.patch);
2992 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
2993 sdl_version_linked->major,
2994 sdl_version_linked->minor,
2995 sdl_version_linked->patch);
2997 SDL_NET_VERSION(&sdl_version_compiled);
2998 sdl_version_linked = SDLNet_Linked_Version();
3001 DrawTextF(xstart1, ystart2, font_text, "SDL_net");
3002 DrawTextF(xstart2, ystart2, font_text, "%d.%d.%d",
3003 sdl_version_compiled.major,
3004 sdl_version_compiled.minor,
3005 sdl_version_compiled.patch);
3006 DrawTextF(xstart3, ystart2, font_text, "%d.%d.%d",
3007 sdl_version_linked->major,
3008 sdl_version_linked->minor,
3009 sdl_version_linked->patch);
3011 ystart2 += 3 * ystep;
3012 DrawTextF(xstart1, ystart2, font_header, "Driver");
3013 DrawTextF(xstart2, ystart2, font_header, "Requested");
3014 DrawTextF(xstart3, ystart2, font_header, "Used");
3016 #if defined(TARGET_SDL2)
3017 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3019 SDL_VideoDriverName(driver_name, driver_name_len);
3022 ystart2 += 2 * ystep;
3023 DrawTextF(xstart1, ystart2, font_text, "SDL_VideoDriver");
3024 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_videodriver);
3025 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3027 #if defined(TARGET_SDL2)
3028 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3030 SDL_AudioDriverName(driver_name, driver_name_len);
3034 DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver");
3035 DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver);
3036 DrawTextF(xstart3, ystart2, font_text, "%s", driver_name);
3038 DrawTextSCentered(ybottom, FONT_TEXT_4,
3039 "Press any key or button for info menu");
3041 FadeIn(REDRAW_FIELD);
3044 void HandleInfoScreen_Version(int button)
3046 if (button == MB_MENU_LEAVE)
3048 PlaySound(SND_MENU_ITEM_SELECTING);
3050 info_mode = INFO_MODE_MAIN;
3055 else if (button == MB_MENU_CHOICE)
3057 PlaySound(SND_MENU_ITEM_SELECTING);
3059 FadeSoundsAndMusic();
3061 info_mode = INFO_MODE_MAIN;
3062 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3066 PlayMenuSoundIfLoop();
3070 void DrawInfoScreen_LevelSet()
3072 struct TitleMessageInfo *tmi = &readme;
3073 char *filename = getLevelSetInfoFilename();
3074 char *title = "Level Set Information:";
3075 int ystart1 = mSY - SY + 100;
3076 int ybottom = mSY - SY + SYSIZE - 20;
3078 if (filename == NULL)
3080 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3085 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3087 FadeOut(REDRAW_FIELD);
3092 DrawTextSCentered(ystart1, FONT_TEXT_1, title);
3094 /* if x position set to "-1", automatically determine by playfield width */
3096 tmi->x = SXSIZE / 2;
3098 /* if y position set to "-1", use static default value */
3102 /* if width set to "-1", automatically determine by playfield width */
3103 if (tmi->width == -1)
3104 tmi->width = SXSIZE - 2 * TILEX;
3106 /* if height set to "-1", automatically determine by playfield height */
3107 if (tmi->height == -1)
3108 tmi->height = SYSIZE - 20 - tmi->y - 10;
3110 /* if chars set to "-1", automatically determine by text and font width */
3111 if (tmi->chars == -1)
3112 tmi->chars = tmi->width / getFontWidth(tmi->font);
3114 tmi->width = tmi->chars * getFontWidth(tmi->font);
3116 /* if lines set to "-1", automatically determine by text and font height */
3117 if (tmi->lines == -1)
3118 tmi->lines = tmi->height / getFontHeight(tmi->font);
3120 tmi->height = tmi->lines * getFontHeight(tmi->font);
3122 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3123 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3124 tmi->autowrap, tmi->centered, tmi->parse_comments);
3126 DrawTextSCentered(ybottom, FONT_TEXT_4,
3127 "Press any key or button for info menu");
3129 FadeIn(REDRAW_FIELD);
3132 void HandleInfoScreen_LevelSet(int button)
3134 if (button == MB_MENU_LEAVE)
3136 PlaySound(SND_MENU_ITEM_SELECTING);
3138 info_mode = INFO_MODE_MAIN;
3143 else if (button == MB_MENU_CHOICE)
3145 PlaySound(SND_MENU_ITEM_SELECTING);
3147 FadeSoundsAndMusic();
3149 info_mode = INFO_MODE_MAIN;
3150 DrawAndFadeInInfoScreen(REDRAW_FIELD);
3154 PlayMenuSoundIfLoop();
3158 static void DrawInfoScreenExt(int fade_mask, boolean do_fading)
3160 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
3162 if (info_mode == INFO_MODE_TITLE)
3163 DrawInfoScreen_TitleScreen();
3164 else if (info_mode == INFO_MODE_ELEMENTS)
3165 DrawInfoScreen_Elements();
3166 else if (info_mode == INFO_MODE_MUSIC)
3167 DrawInfoScreen_Music();
3168 else if (info_mode == INFO_MODE_CREDITS)
3169 DrawInfoScreen_Credits();
3170 else if (info_mode == INFO_MODE_PROGRAM)
3171 DrawInfoScreen_Program();
3172 else if (info_mode == INFO_MODE_VERSION)
3173 DrawInfoScreen_Version();
3174 else if (info_mode == INFO_MODE_LEVELSET)
3175 DrawInfoScreen_LevelSet();
3177 DrawInfoScreen_Main(fade_mask, do_fading);
3179 if (info_mode != INFO_MODE_MAIN &&
3180 info_mode != INFO_MODE_TITLE &&
3181 info_mode != INFO_MODE_MUSIC)
3188 void DrawAndFadeInInfoScreen(int fade_mask)
3190 DrawInfoScreenExt(fade_mask, TRUE);
3193 void DrawInfoScreen()
3195 DrawInfoScreenExt(REDRAW_FIELD, FALSE);
3198 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3200 if (info_mode == INFO_MODE_TITLE)
3201 HandleInfoScreen_TitleScreen(button);
3202 else if (info_mode == INFO_MODE_ELEMENTS)
3203 HandleInfoScreen_Elements(button);
3204 else if (info_mode == INFO_MODE_MUSIC)
3205 HandleInfoScreen_Music(button);
3206 else if (info_mode == INFO_MODE_CREDITS)
3207 HandleInfoScreen_Credits(button);
3208 else if (info_mode == INFO_MODE_PROGRAM)
3209 HandleInfoScreen_Program(button);
3210 else if (info_mode == INFO_MODE_VERSION)
3211 HandleInfoScreen_Version(button);
3212 else if (info_mode == INFO_MODE_LEVELSET)
3213 HandleInfoScreen_LevelSet(button);
3215 HandleInfoScreen_Main(mx, my, dx, dy, button);
3219 /* ========================================================================= */
3220 /* type name functions */
3221 /* ========================================================================= */
3223 void HandleTypeName(int newxpos, Key key)
3225 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3226 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3227 struct TextPosInfo *pos = mci->pos_input;
3228 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3229 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3230 static int xpos = 0;
3231 int font_nr = pos->font;
3232 int font_active_nr = FONT_ACTIVE(font_nr);
3233 int font_width = getFontWidth(font_active_nr);
3234 char key_char = getValidConfigValueChar(getCharFromKey(key));
3235 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3236 boolean is_active = TRUE;
3238 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3242 strcpy(last_player_name, setup.player_name);
3246 #if defined(TARGET_SDL2)
3247 SDL_StartTextInput();
3250 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3252 setup.player_name[xpos] = key_char;
3253 setup.player_name[xpos + 1] = 0;
3257 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3261 setup.player_name[xpos] = 0;
3263 else if (key == KSYM_Return && xpos > 0)
3269 game_status = GAME_MODE_MAIN;
3271 else if (key == KSYM_Escape)
3273 strcpy(setup.player_name, last_player_name);
3277 game_status = GAME_MODE_MAIN;
3282 pos->width = (strlen(setup.player_name) + 1) * font_width;
3283 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3285 DrawText(startx, starty, setup.player_name, font_active_nr);
3286 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3290 pos->width = strlen(setup.player_name) * font_width;
3291 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3293 DrawText(startx, starty, setup.player_name, font_nr);
3295 #if defined(TARGET_SDL2)
3296 SDL_StopTextInput();
3302 /* ========================================================================= */
3303 /* tree menu functions */
3304 /* ========================================================================= */
3306 static void DrawChooseTree(TreeInfo **ti_ptr)
3308 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3310 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3312 game_status = GAME_MODE_MAIN;
3314 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3321 FreeScreenGadgets();
3322 CreateScreenGadgets();
3324 CloseDoor(DOOR_CLOSE_2);
3330 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3331 MapScreenTreeGadgets(*ti_ptr);
3338 static void AdjustScrollbar(int id, int items_max, int items_visible,
3341 struct GadgetInfo *gi = screen_gadget[id];
3343 if (item_position > items_max - items_visible)
3344 item_position = items_max - items_visible;
3346 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
3347 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
3348 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
3351 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
3353 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
3357 static void clearMenuListArea()
3359 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3361 /* correct scrollbar position if placed outside menu (playfield) area */
3362 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
3363 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
3365 /* clear menu list area, but not title or scrollbar */
3366 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
3367 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
3370 static void drawChooseTreeList(int first_entry, int num_page_entries,
3374 char *title_string = NULL;
3375 int yoffset_sets = MENU_TITLE1_YPOS;
3376 int yoffset_setup = 16;
3377 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
3378 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
3379 int last_game_status = game_status; /* save current game status */
3381 title_string = ti->infotext;
3383 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
3385 clearMenuListArea();
3387 for (i = 0; i < num_page_entries; i++)
3389 TreeInfo *node, *node_first;
3390 int entry_pos = first_entry + i;
3391 int xpos = MENU_SCREEN_START_XPOS;
3392 int ypos = MENU_SCREEN_START_YPOS + i;
3393 int startx = mSX + xpos * 32;
3394 int starty = mSY + ypos * 32;
3395 int font_nr = FONT_TEXT_1;
3396 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
3397 int startx_text = startx + font_xoffset;
3398 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
3399 int text_size = startx_scrollbar - startx_text;
3400 int max_buffer_len = text_size / getFontWidth(font_nr);
3401 char buffer[max_buffer_len + 1];
3403 node_first = getTreeInfoFirstGroupEntry(ti);
3404 node = getTreeInfoFromPos(node_first, entry_pos);
3406 strncpy(buffer, node->name, max_buffer_len);
3407 buffer[max_buffer_len] = '\0';
3409 DrawText(startx, starty, buffer, font_nr + node->color);
3411 if (node->parent_link)
3412 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
3413 else if (node->level_group)
3414 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
3416 initCursor(i, IMG_MENU_BUTTON);
3419 game_status = last_game_status; /* restore current game status */
3421 redraw_mask |= REDRAW_FIELD;
3424 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
3426 TreeInfo *node, *node_first;
3427 int x, last_redraw_mask = redraw_mask;
3428 int ypos = MENU_TITLE2_YPOS;
3429 int font_nr = FONT_TITLE_2;
3431 if (ti->type == TREE_TYPE_LEVEL_NR)
3432 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
3434 if (ti->type != TREE_TYPE_LEVEL_DIR)
3437 node_first = getTreeInfoFirstGroupEntry(ti);
3438 node = getTreeInfoFromPos(node_first, entry_pos);
3440 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
3442 if (node->parent_link)
3443 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
3444 node->node_parent->name);
3445 else if (node->level_group)
3446 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
3448 else if (ti->type == TREE_TYPE_LEVEL_DIR)
3449 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
3450 node->levels, (node->levels > 1 ? "levels" : "level"),
3453 /* let BackToFront() redraw only what is needed */
3454 redraw_mask = last_redraw_mask | REDRAW_TILES;
3455 for (x = 0; x < SCR_FIELDX; x++)
3456 MarkTileDirty(x, 1);
3459 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
3462 TreeInfo *ti = *ti_ptr;
3464 int y = ti->cl_cursor;
3465 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3466 int num_entries = numTreeInfoInGroup(ti);
3467 int num_page_entries;
3468 int last_game_status = game_status; /* save current game status */
3469 boolean position_set_by_scrollbar = (dx == 999);
3471 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
3472 num_page_entries = num_entries;
3474 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
3476 game_status = last_game_status; /* restore current game status */
3478 if (button == MB_MENU_INITIALIZE)
3480 int num_entries = numTreeInfoInGroup(ti);
3481 int entry_pos = posTreeInfo(ti);
3483 if (ti->cl_first == -1)
3485 /* only on initialization */
3486 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3487 ti->cl_cursor = entry_pos - ti->cl_first;
3489 else if (ti->cl_cursor >= num_page_entries ||
3490 (num_entries > num_page_entries &&
3491 num_entries - ti->cl_first < num_page_entries))
3493 /* only after change of list size (by custom graphic configuration) */
3494 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
3495 ti->cl_cursor = entry_pos - ti->cl_first;
3498 if (position_set_by_scrollbar)
3501 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3504 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3505 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3506 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3510 else if (button == MB_MENU_LEAVE)
3514 PlaySound(SND_MENU_ITEM_SELECTING);
3516 if (ti->node_parent)
3518 *ti_ptr = ti->node_parent;
3519 DrawChooseTree(ti_ptr);
3521 else if (game_status == GAME_MODE_SETUP)
3523 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3524 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3525 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3527 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3528 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3529 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3530 execSetupGraphics();
3531 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3532 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3533 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3535 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3536 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3537 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3544 if (game_status == GAME_MODE_LEVELNR)
3546 int new_level_nr = atoi(level_number_current->identifier);
3548 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3551 game_status = GAME_MODE_MAIN;
3553 DrawMainMenuExt(REDRAW_FIELD, FALSE);
3559 if (mx || my) /* mouse input */
3561 int last_game_status = game_status; /* save current game status */
3563 x = (mx - mSX) / 32;
3564 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
3566 game_status = last_game_status; /* restore current game status */
3568 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
3570 /* move cursor instead of scrolling when already at start/end of list */
3571 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
3573 else if (dy == +1 * SCROLL_LINE &&
3574 ti->cl_first + num_page_entries == num_entries)
3577 /* handle scrolling screen one line or page */
3578 if (ti->cl_cursor + dy < 0 ||
3579 ti->cl_cursor + dy > num_page_entries - 1)
3581 boolean redraw = FALSE;
3583 if (ABS(dy) == SCROLL_PAGE)
3584 step = num_page_entries - 1;
3586 if (dy < 0 && ti->cl_first > 0)
3588 /* scroll page/line up */
3590 ti->cl_first -= step;
3591 if (ti->cl_first < 0)
3596 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
3598 /* scroll page/line down */
3600 ti->cl_first += step;
3601 if (ti->cl_first + num_page_entries > num_entries)
3602 ti->cl_first = MAX(0, num_entries - num_page_entries);
3609 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
3610 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
3611 drawChooseTreeCursor(ti->cl_cursor, TRUE);
3613 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
3620 /* handle moving cursor one line */
3621 y = ti->cl_cursor + dy;
3626 TreeInfo *node_first, *node_cursor;
3627 int entry_pos = ti->cl_first + y;
3629 node_first = getTreeInfoFirstGroupEntry(ti);
3630 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3632 if (node_cursor->node_group)
3636 PlaySound(SND_MENU_ITEM_SELECTING);
3638 node_cursor->cl_first = ti->cl_first;
3639 node_cursor->cl_cursor = ti->cl_cursor;
3640 *ti_ptr = node_cursor->node_group;
3641 DrawChooseTree(ti_ptr);
3646 else if (dx == -1 && ti->node_parent)
3650 PlaySound(SND_MENU_ITEM_SELECTING);
3652 *ti_ptr = ti->node_parent;
3653 DrawChooseTree(ti_ptr);
3658 if (!anyScrollbarGadgetActive() &&
3659 IN_VIS_MENU(x, y) &&
3660 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
3661 y >= 0 && y < num_page_entries)
3665 if (y != ti->cl_cursor)
3667 PlaySound(SND_MENU_ITEM_ACTIVATING);
3669 drawChooseTreeCursor(ti->cl_cursor, FALSE);
3670 drawChooseTreeCursor(y, TRUE);
3671 drawChooseTreeInfo(ti->cl_first + y, ti);
3678 TreeInfo *node_first, *node_cursor;
3679 int entry_pos = ti->cl_first + y;
3681 PlaySound(SND_MENU_ITEM_SELECTING);
3683 node_first = getTreeInfoFirstGroupEntry(ti);
3684 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
3686 if (node_cursor->node_group)
3690 node_cursor->cl_first = ti->cl_first;
3691 node_cursor->cl_cursor = ti->cl_cursor;
3692 *ti_ptr = node_cursor->node_group;
3693 DrawChooseTree(ti_ptr);
3695 else if (node_cursor->parent_link)
3699 *ti_ptr = node_cursor->node_parent;
3700 DrawChooseTree(ti_ptr);
3706 node_cursor->cl_first = ti->cl_first;
3707 node_cursor->cl_cursor = ti->cl_cursor;
3708 *ti_ptr = node_cursor;
3710 if (ti->type == TREE_TYPE_LEVEL_DIR)
3712 LoadLevelSetup_SeriesInfo();
3714 SaveLevelSetup_LastSeries();
3715 SaveLevelSetup_SeriesInfo();
3719 if (game_status == GAME_MODE_SETUP)
3721 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
3722 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
3723 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
3725 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
3726 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
3727 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
3728 execSetupGraphics();
3729 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
3730 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
3731 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
3733 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
3734 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
3735 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
3742 if (game_status == GAME_MODE_LEVELNR)
3744 int new_level_nr = atoi(level_number_current->identifier);
3746 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
3749 game_status = GAME_MODE_MAIN;
3758 void DrawChooseLevelSet()
3760 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3762 DrawChooseTree(&leveldir_current);
3768 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
3770 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
3773 void DrawChooseLevelNr()
3777 if (level_number != NULL)
3779 freeTreeInfo(level_number);
3781 level_number = NULL;
3784 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
3786 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
3787 char identifier[32], name[32];
3790 /* temporarily load level info to get level name */
3791 LoadLevelInfoOnly(i);
3793 ti->node_top = &level_number;
3794 ti->sort_priority = 10000 + value;
3795 ti->color = (level.no_valid_file ? FC_BLUE :
3796 LevelStats_getSolved(i) ? FC_GREEN :
3797 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
3799 sprintf(identifier, "%d", value);
3800 sprintf(name, "%03d: %s", value,
3801 (level.no_valid_file ? "(no file)" : level.name));
3803 setString(&ti->identifier, identifier);
3804 setString(&ti->name, name);
3805 setString(&ti->name_sorting, name);
3807 pushTreeInfo(&level_number, ti);
3810 /* sort level number values to start with lowest level number */
3811 sortTreeInfo(&level_number);
3813 /* set current level number to current level number */
3814 level_number_current =
3815 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
3817 /* if that also fails, set current level number to first available level */
3818 if (level_number_current == NULL)
3819 level_number_current = level_number;
3821 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3823 DrawChooseTree(&level_number_current);
3829 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
3831 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
3834 void DrawHallOfFame(int highlight_position)
3836 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
3839 FadeSoundsAndMusic();
3841 /* (this is needed when called from GameEnd() after winning a game) */
3842 KeyboardAutoRepeatOn();
3845 /* (this is needed when called from GameEnd() after winning a game) */
3846 SetDrawDeactivationMask(REDRAW_NONE);
3847 SetDrawBackgroundMask(REDRAW_FIELD);
3849 CloseDoor(DOOR_CLOSE_2);
3851 if (highlight_position < 0)
3852 LoadScore(level_nr);
3854 FadeSetEnterScreen();
3863 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
3868 static void drawHallOfFameList(int first_entry, int highlight_position)
3872 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
3875 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
3876 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
3877 "HighScores of Level %d", level_nr);
3879 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
3881 int entry = first_entry + i;
3882 boolean active = (entry == highlight_position);
3883 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
3884 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
3885 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
3886 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
3887 int dx1 = 3 * getFontWidth(font_nr1);
3888 int dx2 = dx1 + getFontWidth(font_nr1);
3889 int dx3 = SXSIZE - 2 * (mSX - SX) - 5 * getFontWidth(font_nr4);
3890 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
3891 int sy = mSY + 64 + i * 32;
3893 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
3894 DrawText(mSX + dx1, sy, ".", font_nr1);
3896 for (j = 0; j < num_dots; j++)
3897 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
3899 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
3900 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
3902 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
3905 redraw_mask |= REDRAW_FIELD;
3908 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
3910 static int first_entry = 0;
3911 static int highlight_position = 0;
3912 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
3914 if (button == MB_MENU_INITIALIZE)
3917 highlight_position = mx;
3918 drawHallOfFameList(first_entry, highlight_position);
3923 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
3924 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
3928 if (first_entry > 0)
3930 first_entry -= step;
3931 if (first_entry < 0)
3934 drawHallOfFameList(first_entry, highlight_position);
3939 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
3941 first_entry += step;
3942 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
3943 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
3945 drawHallOfFameList(first_entry, highlight_position);
3948 else if (button == MB_MENU_LEAVE)
3950 PlaySound(SND_MENU_ITEM_SELECTING);
3952 FadeSound(SND_BACKGROUND_SCORES);
3954 game_status = GAME_MODE_MAIN;
3958 else if (button == MB_MENU_CHOICE)
3960 PlaySound(SND_MENU_ITEM_SELECTING);
3962 FadeSound(SND_BACKGROUND_SCORES);
3964 game_status = GAME_MODE_MAIN;
3966 DrawAndFadeInMainMenu(REDRAW_FIELD);
3969 if (game_status == GAME_MODE_SCORES)
3970 PlayMenuSoundIfLoop();
3974 /* ========================================================================= */
3975 /* setup screen functions */
3976 /* ========================================================================= */
3978 static struct TokenInfo *setup_info;
3979 static int num_setup_info; /* number of setup entries shown on screen */
3980 static int max_setup_info; /* total number of setup entries in list */
3982 static char *screen_mode_text;
3983 static char *window_size_text;
3984 static char *scaling_type_text;
3985 static char *scroll_delay_text;
3986 static char *snapshot_mode_text;
3987 static char *game_speed_text;
3988 static char *graphics_set_name;
3989 static char *sounds_set_name;
3990 static char *music_set_name;
3991 static char *volume_simple_text;
3992 static char *volume_loops_text;
3993 static char *volume_music_text;
3994 static char *touch_controls_text;
3995 static char *move_distance_text;
3996 static char *drop_distance_text;
3998 static void execSetupMain()
4000 setup_mode = SETUP_MODE_MAIN;
4005 static void execSetupGame_setGameSpeeds()
4007 if (game_speeds == NULL)
4011 for (i = 0; game_speeds_list[i].value != -1; i++)
4013 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4014 char identifier[32], name[32];
4015 int value = game_speeds_list[i].value;
4016 char *text = game_speeds_list[i].text;
4018 ti->node_top = &game_speeds;
4019 ti->sort_priority = 10000 - value;
4021 sprintf(identifier, "%d", value);
4022 sprintf(name, "%s", text);
4024 setString(&ti->identifier, identifier);
4025 setString(&ti->name, name);
4026 setString(&ti->name_sorting, name);
4027 setString(&ti->infotext, "Game Speed");
4029 pushTreeInfo(&game_speeds, ti);
4032 /* sort game speed values to start with slowest game speed */
4033 sortTreeInfo(&game_speeds);
4035 /* set current game speed to configured game speed value */
4036 game_speed_current =
4037 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4039 /* if that fails, set current game speed to reliable default value */
4040 if (game_speed_current == NULL)
4041 game_speed_current =
4042 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4044 /* if that also fails, set current game speed to first available speed */
4045 if (game_speed_current == NULL)
4046 game_speed_current = game_speeds;
4049 setup.game_frame_delay = atoi(game_speed_current->identifier);
4051 /* needed for displaying game speed text instead of identifier */
4052 game_speed_text = game_speed_current->name;
4055 static void execSetupGame_setScrollDelays()
4057 if (scroll_delays == NULL)
4061 for (i = 0; scroll_delays_list[i].value != -1; i++)
4063 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4064 char identifier[32], name[32];
4065 int value = scroll_delays_list[i].value;
4066 char *text = scroll_delays_list[i].text;
4068 ti->node_top = &scroll_delays;
4069 ti->sort_priority = value;
4071 sprintf(identifier, "%d", value);
4072 sprintf(name, "%s", text);
4074 setString(&ti->identifier, identifier);
4075 setString(&ti->name, name);
4076 setString(&ti->name_sorting, name);
4077 setString(&ti->infotext, "Scaling Type");
4079 pushTreeInfo(&scroll_delays, ti);
4082 /* sort scaling type values to start with lowest scaling type value */
4083 sortTreeInfo(&scroll_delays);
4085 /* set current scaling type value to configured scaling type value */
4086 scroll_delay_current =
4087 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4089 /* if that fails, set current scaling type to reliable default value */
4090 if (scroll_delay_current == NULL)
4091 scroll_delay_current =
4092 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4094 /* if that also fails, set current scaling type to first available value */
4095 if (scroll_delay_current == NULL)
4096 scroll_delay_current = scroll_delays;
4099 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4101 /* needed for displaying scaling type text instead of identifier */
4102 scroll_delay_text = scroll_delay_current->name;
4105 static void execSetupGame_setSnapshotModes()
4107 if (snapshot_modes == NULL)
4111 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4113 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4114 char identifier[32], name[32];
4115 char *value = snapshot_modes_list[i].value;
4116 char *text = snapshot_modes_list[i].text;
4118 ti->node_top = &snapshot_modes;
4119 ti->sort_priority = i;
4121 sprintf(identifier, "%s", value);
4122 sprintf(name, "%s", text);
4124 setString(&ti->identifier, identifier);
4125 setString(&ti->name, name);
4126 setString(&ti->name_sorting, name);
4127 setString(&ti->infotext, "Snapshot Mode");
4129 pushTreeInfo(&snapshot_modes, ti);
4132 /* sort snapshot mode values to start with lowest snapshot mode value */
4133 sortTreeInfo(&snapshot_modes);
4135 /* set current snapshot mode value to configured snapshot mode value */
4136 snapshot_mode_current =
4137 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4139 /* if that fails, set current snapshot mode to reliable default value */
4140 if (snapshot_mode_current == NULL)
4141 snapshot_mode_current =
4142 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4144 /* if that also fails, set current snapshot mode to first available value */
4145 if (snapshot_mode_current == NULL)
4146 snapshot_mode_current = snapshot_modes;
4149 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4151 /* needed for displaying snapshot mode text instead of identifier */
4152 snapshot_mode_text = snapshot_mode_current->name;
4155 static void execSetupGame()
4157 execSetupGame_setGameSpeeds();
4158 execSetupGame_setScrollDelays();
4159 execSetupGame_setSnapshotModes();
4161 setup_mode = SETUP_MODE_GAME;
4166 static void execSetupChooseGameSpeed()
4168 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4173 static void execSetupChooseScrollDelay()
4175 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4180 static void execSetupChooseSnapshotMode()
4182 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4187 static void execSetupEditor()
4189 setup_mode = SETUP_MODE_EDITOR;
4194 static void execSetupGraphics_setWindowSizes(boolean update_list)
4196 if (window_sizes != NULL && update_list)
4198 freeTreeInfo(window_sizes);
4200 window_sizes = NULL;
4203 if (window_sizes == NULL)
4205 boolean current_window_size_found = FALSE;
4208 for (i = 0; window_sizes_list[i].value != -1; i++)
4210 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4211 char identifier[32], name[32];
4212 int value = window_sizes_list[i].value;
4213 char *text = window_sizes_list[i].text;
4215 ti->node_top = &window_sizes;
4216 ti->sort_priority = value;
4218 sprintf(identifier, "%d", value);
4219 sprintf(name, "%s", text);
4221 setString(&ti->identifier, identifier);
4222 setString(&ti->name, name);
4223 setString(&ti->name_sorting, name);
4224 setString(&ti->infotext, "Window Scaling");
4226 pushTreeInfo(&window_sizes, ti);
4228 if (value == setup.window_scaling_percent)
4229 current_window_size_found = TRUE;
4232 if (!current_window_size_found)
4234 // add entry for non-preset window scaling value
4236 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4237 char identifier[32], name[32];
4238 int value = setup.window_scaling_percent;
4240 ti->node_top = &window_sizes;
4241 ti->sort_priority = value;
4243 sprintf(identifier, "%d", value);
4244 sprintf(name, "%d %% (Current)", value);
4246 setString(&ti->identifier, identifier);
4247 setString(&ti->name, name);
4248 setString(&ti->name_sorting, name);
4249 setString(&ti->infotext, "Window Scaling");
4251 pushTreeInfo(&window_sizes, ti);
4254 /* sort window size values to start with lowest window size value */
4255 sortTreeInfo(&window_sizes);
4257 /* set current window size value to configured window size value */
4258 window_size_current =
4259 getTreeInfoFromIdentifier(window_sizes,
4260 i_to_a(setup.window_scaling_percent));
4262 /* if that fails, set current window size to reliable default value */
4263 if (window_size_current == NULL)
4264 window_size_current =
4265 getTreeInfoFromIdentifier(window_sizes,
4266 i_to_a(STD_WINDOW_SCALING_PERCENT));
4268 /* if that also fails, set current window size to first available value */
4269 if (window_size_current == NULL)
4270 window_size_current = window_sizes;
4273 setup.window_scaling_percent = atoi(window_size_current->identifier);
4275 /* needed for displaying window size text instead of identifier */
4276 window_size_text = window_size_current->name;
4279 static void execSetupGraphics_setScalingTypes()
4281 if (scaling_types == NULL)
4285 for (i = 0; scaling_types_list[i].value != NULL; i++)
4287 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4288 char identifier[32], name[32];
4289 char *value = scaling_types_list[i].value;
4290 char *text = scaling_types_list[i].text;
4292 ti->node_top = &scaling_types;
4293 ti->sort_priority = i;
4295 sprintf(identifier, "%s", value);
4296 sprintf(name, "%s", text);
4298 setString(&ti->identifier, identifier);
4299 setString(&ti->name, name);
4300 setString(&ti->name_sorting, name);
4301 setString(&ti->infotext, "Anti-Aliasing");
4303 pushTreeInfo(&scaling_types, ti);
4306 /* sort scaling type values to start with lowest scaling type value */
4307 sortTreeInfo(&scaling_types);
4309 /* set current scaling type value to configured scaling type value */
4310 scaling_type_current =
4311 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4313 /* if that fails, set current scaling type to reliable default value */
4314 if (scaling_type_current == NULL)
4315 scaling_type_current =
4316 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4318 /* if that also fails, set current scaling type to first available value */
4319 if (scaling_type_current == NULL)
4320 scaling_type_current = scaling_types;
4323 setup.window_scaling_quality = scaling_type_current->identifier;
4325 /* needed for displaying scaling type text instead of identifier */
4326 scaling_type_text = scaling_type_current->name;
4329 static void execSetupGraphics_setScreenModes()
4331 // if (screen_modes == NULL && video.fullscreen_available)
4332 if (screen_modes == NULL && video.fullscreen_modes != NULL)
4336 for (i = 0; video.fullscreen_modes[i].width != -1; i++)
4338 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4339 char identifier[32], name[32];
4340 int x = video.fullscreen_modes[i].width;
4341 int y = video.fullscreen_modes[i].height;
4344 get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
4346 ti->node_top = &screen_modes;
4347 ti->sort_priority = x * 10000 + y;
4349 sprintf(identifier, "%dx%d", x, y);
4350 sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
4352 setString(&ti->identifier, identifier);
4353 setString(&ti->name, name);
4354 setString(&ti->name_sorting, name);
4355 setString(&ti->infotext, "Fullscreen Mode");
4357 pushTreeInfo(&screen_modes, ti);
4360 /* sort fullscreen modes to start with lowest available screen resolution */
4361 sortTreeInfo(&screen_modes);
4363 /* set current screen mode for fullscreen mode to configured setup value */
4364 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4365 setup.fullscreen_mode);
4367 /* if that fails, set current screen mode to reliable default value */
4368 if (screen_mode_current == NULL)
4369 screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
4370 DEFAULT_FULLSCREEN_MODE);
4372 /* if that also fails, set current screen mode to first available mode */
4373 if (screen_mode_current == NULL)
4374 screen_mode_current = screen_modes;
4376 if (screen_mode_current == NULL)
4377 video.fullscreen_available = FALSE;
4380 // if (video.fullscreen_available)
4381 if (screen_mode_current != NULL)
4383 setup.fullscreen_mode = screen_mode_current->identifier;
4385 /* needed for displaying screen mode name instead of identifier */
4386 screen_mode_text = screen_mode_current->name;
4390 static void execSetupGraphics()
4392 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
4394 // update "setup.window_scaling_percent" from list selection
4395 execSetupGraphics_setWindowSizes(FALSE);
4399 // update list selection from "setup.window_scaling_percent"
4400 execSetupGraphics_setWindowSizes(TRUE);
4403 execSetupGraphics_setScalingTypes();
4404 execSetupGraphics_setScreenModes();
4406 setup_mode = SETUP_MODE_GRAPHICS;
4410 #if defined(TARGET_SDL2)
4411 // window scaling may have changed at this point
4412 ToggleFullscreenOrChangeWindowScalingIfNeeded();
4414 // window scaling quality may have changed at this point
4415 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
4416 SDLSetWindowScalingQuality(setup.window_scaling_quality);
4420 #if !defined(PLATFORM_ANDROID)
4421 #if defined(TARGET_SDL2)
4422 static void execSetupChooseWindowSize()
4424 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
4429 static void execSetupChooseScalingType()
4431 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
4436 static void execSetupChooseScreenMode()
4438 if (!video.fullscreen_available)
4441 setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
4448 static void execSetupChooseVolumeSimple()
4450 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
4455 static void execSetupChooseVolumeLoops()
4457 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
4462 static void execSetupChooseVolumeMusic()
4464 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
4469 static void execSetupSound()
4471 if (volumes_simple == NULL)
4473 boolean current_volume_simple_found = FALSE;
4476 for (i = 0; volumes_list[i].value != -1; i++)
4478 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4479 char identifier[32], name[32];
4480 int value = volumes_list[i].value;
4481 char *text = volumes_list[i].text;
4483 ti->node_top = &volumes_simple;
4484 ti->sort_priority = value;
4486 sprintf(identifier, "%d", value);
4487 sprintf(name, "%s", text);
4489 setString(&ti->identifier, identifier);
4490 setString(&ti->name, name);
4491 setString(&ti->name_sorting, name);
4492 setString(&ti->infotext, "Sound Volume");
4494 pushTreeInfo(&volumes_simple, ti);
4496 if (value == setup.volume_simple)
4497 current_volume_simple_found = TRUE;
4500 if (!current_volume_simple_found)
4502 // add entry for non-preset volume value
4504 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4505 char identifier[32], name[32];
4506 int value = setup.volume_simple;
4508 ti->node_top = &volumes_simple;
4509 ti->sort_priority = value;
4511 sprintf(identifier, "%d", value);
4512 sprintf(name, "%d %% (Current)", value);
4514 setString(&ti->identifier, identifier);
4515 setString(&ti->name, name);
4516 setString(&ti->name_sorting, name);
4517 setString(&ti->infotext, "Sound Volume");
4519 pushTreeInfo(&volumes_simple, ti);
4522 /* sort volume values to start with lowest volume value */
4523 sortTreeInfo(&volumes_simple);
4525 /* set current volume value to configured volume value */
4526 volume_simple_current =
4527 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
4529 /* if that fails, set current volume to reliable default value */
4530 if (volume_simple_current == NULL)
4531 volume_simple_current =
4532 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
4534 /* if that also fails, set current volume to first available value */
4535 if (volume_simple_current == NULL)
4536 volume_simple_current = volumes_simple;
4539 if (volumes_loops == NULL)
4541 boolean current_volume_loops_found = FALSE;
4544 for (i = 0; volumes_list[i].value != -1; i++)
4546 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4547 char identifier[32], name[32];
4548 int value = volumes_list[i].value;
4549 char *text = volumes_list[i].text;
4551 ti->node_top = &volumes_loops;
4552 ti->sort_priority = value;
4554 sprintf(identifier, "%d", value);
4555 sprintf(name, "%s", text);
4557 setString(&ti->identifier, identifier);
4558 setString(&ti->name, name);
4559 setString(&ti->name_sorting, name);
4560 setString(&ti->infotext, "Loops Volume");
4562 pushTreeInfo(&volumes_loops, ti);
4564 if (value == setup.volume_loops)
4565 current_volume_loops_found = TRUE;
4568 if (!current_volume_loops_found)
4570 // add entry for non-preset volume value
4572 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4573 char identifier[32], name[32];
4574 int value = setup.volume_loops;
4576 ti->node_top = &volumes_loops;
4577 ti->sort_priority = value;
4579 sprintf(identifier, "%d", value);
4580 sprintf(name, "%d %% (Current)", value);
4582 setString(&ti->identifier, identifier);
4583 setString(&ti->name, name);
4584 setString(&ti->name_sorting, name);
4585 setString(&ti->infotext, "Loops Volume");
4587 pushTreeInfo(&volumes_loops, ti);
4590 /* sort volume values to start with lowest volume value */
4591 sortTreeInfo(&volumes_loops);
4593 /* set current volume value to configured volume value */
4594 volume_loops_current =
4595 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
4597 /* if that fails, set current volume to reliable default value */
4598 if (volume_loops_current == NULL)
4599 volume_loops_current =
4600 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
4602 /* if that also fails, set current volume to first available value */
4603 if (volume_loops_current == NULL)
4604 volume_loops_current = volumes_loops;
4607 if (volumes_music == NULL)
4609 boolean current_volume_music_found = FALSE;
4612 for (i = 0; volumes_list[i].value != -1; i++)
4614 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4615 char identifier[32], name[32];
4616 int value = volumes_list[i].value;
4617 char *text = volumes_list[i].text;
4619 ti->node_top = &volumes_music;
4620 ti->sort_priority = value;
4622 sprintf(identifier, "%d", value);
4623 sprintf(name, "%s", text);
4625 setString(&ti->identifier, identifier);
4626 setString(&ti->name, name);
4627 setString(&ti->name_sorting, name);
4628 setString(&ti->infotext, "Music Volume");
4630 pushTreeInfo(&volumes_music, ti);
4632 if (value == setup.volume_music)
4633 current_volume_music_found = TRUE;
4636 if (!current_volume_music_found)
4638 // add entry for non-preset volume value
4640 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4641 char identifier[32], name[32];
4642 int value = setup.volume_music;
4644 ti->node_top = &volumes_music;
4645 ti->sort_priority = value;
4647 sprintf(identifier, "%d", value);
4648 sprintf(name, "%d %% (Current)", value);
4650 setString(&ti->identifier, identifier);
4651 setString(&ti->name, name);
4652 setString(&ti->name_sorting, name);
4653 setString(&ti->infotext, "Music Volume");
4655 pushTreeInfo(&volumes_music, ti);
4658 /* sort volume values to start with lowest volume value */
4659 sortTreeInfo(&volumes_music);
4661 /* set current volume value to configured volume value */
4662 volume_music_current =
4663 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
4665 /* if that fails, set current volume to reliable default value */
4666 if (volume_music_current == NULL)
4667 volume_music_current =
4668 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
4670 /* if that also fails, set current volume to first available value */
4671 if (volume_music_current == NULL)
4672 volume_music_current = volumes_music;
4675 setup.volume_simple = atoi(volume_simple_current->identifier);
4676 setup.volume_loops = atoi(volume_loops_current->identifier);
4677 setup.volume_music = atoi(volume_music_current->identifier);
4679 /* needed for displaying volume text instead of identifier */
4680 volume_simple_text = volume_simple_current->name;
4681 volume_loops_text = volume_loops_current->name;
4682 volume_music_text = volume_music_current->name;
4684 setup_mode = SETUP_MODE_SOUND;
4689 static void execSetupChooseTouchControls()
4691 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
4696 static void execSetupChooseMoveDistance()
4698 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
4703 static void execSetupChooseDropDistance()
4705 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
4710 static void execSetupTouch()
4712 if (touch_controls == NULL)
4716 for (i = 0; touch_controls_list[i].value != NULL; i++)
4718 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4719 char identifier[32], name[32];
4720 char *value = touch_controls_list[i].value;
4721 char *text = touch_controls_list[i].text;
4723 ti->node_top = &touch_controls;
4724 ti->sort_priority = i;
4726 sprintf(identifier, "%s", value);
4727 sprintf(name, "%s", text);
4729 setString(&ti->identifier, identifier);
4730 setString(&ti->name, name);
4731 setString(&ti->name_sorting, name);
4732 setString(&ti->infotext, "Control Type");
4734 pushTreeInfo(&touch_controls, ti);
4737 /* sort touch control values to start with lowest touch control value */
4738 sortTreeInfo(&touch_controls);
4740 /* set current touch control value to configured touch control value */
4741 touch_control_current =
4742 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
4744 /* if that fails, set current touch control to reliable default value */
4745 if (touch_control_current == NULL)
4746 touch_control_current =
4747 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
4749 /* if that also fails, set current touch control to first available value */
4750 if (touch_control_current == NULL)
4751 touch_control_current = touch_controls;
4754 if (move_distances == NULL)
4758 for (i = 0; distances_list[i].value != -1; i++)
4760 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4761 char identifier[32], name[32];
4762 int value = distances_list[i].value;
4763 char *text = distances_list[i].text;
4765 ti->node_top = &move_distances;
4766 ti->sort_priority = value;
4768 sprintf(identifier, "%d", value);
4769 sprintf(name, "%s", text);
4771 setString(&ti->identifier, identifier);
4772 setString(&ti->name, name);
4773 setString(&ti->name_sorting, name);
4774 setString(&ti->infotext, "Move Distance");
4776 pushTreeInfo(&move_distances, ti);
4779 /* sort distance values to start with lowest distance value */
4780 sortTreeInfo(&move_distances);
4782 /* set current distance value to configured distance value */
4783 move_distance_current =
4784 getTreeInfoFromIdentifier(move_distances,
4785 i_to_a(setup.touch.move_distance));
4787 /* if that fails, set current distance to reliable default value */
4788 if (move_distance_current == NULL)
4789 move_distance_current =
4790 getTreeInfoFromIdentifier(move_distances, i_to_a(1));
4792 /* if that also fails, set current distance to first available value */
4793 if (move_distance_current == NULL)
4794 move_distance_current = move_distances;
4797 if (drop_distances == NULL)
4801 for (i = 0; distances_list[i].value != -1; i++)
4803 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4804 char identifier[32], name[32];
4805 int value = distances_list[i].value;
4806 char *text = distances_list[i].text;
4808 ti->node_top = &drop_distances;
4809 ti->sort_priority = value;
4811 sprintf(identifier, "%d", value);
4812 sprintf(name, "%s", text);
4814 setString(&ti->identifier, identifier);
4815 setString(&ti->name, name);
4816 setString(&ti->name_sorting, name);
4817 setString(&ti->infotext, "Drop Distance");
4819 pushTreeInfo(&drop_distances, ti);
4822 /* sort distance values to start with lowest distance value */
4823 sortTreeInfo(&drop_distances);
4825 /* set current distance value to configured distance value */
4826 drop_distance_current =
4827 getTreeInfoFromIdentifier(drop_distances,
4828 i_to_a(setup.touch.drop_distance));
4830 /* if that fails, set current distance to reliable default value */
4831 if (drop_distance_current == NULL)
4832 drop_distance_current =
4833 getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
4835 /* if that also fails, set current distance to first available value */
4836 if (drop_distance_current == NULL)
4837 drop_distance_current = drop_distances;
4840 setup.touch.control_type = touch_control_current->identifier;
4841 setup.touch.move_distance = atoi(move_distance_current->identifier);
4842 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
4844 /* needed for displaying volume text instead of identifier */
4845 touch_controls_text = touch_control_current->name;
4846 move_distance_text = move_distance_current->name;
4847 drop_distance_text = drop_distance_current->name;
4849 setup_mode = SETUP_MODE_TOUCH;
4854 static void execSetupArtwork()
4857 printf("::: '%s', '%s', '%s'\n",
4858 artwork.gfx_current->subdir,
4859 artwork.gfx_current->fullpath,
4860 artwork.gfx_current->basepath);
4863 setup.graphics_set = artwork.gfx_current->identifier;
4864 setup.sounds_set = artwork.snd_current->identifier;
4865 setup.music_set = artwork.mus_current->identifier;
4867 /* needed if last screen (setup choice) changed graphics, sounds or music */
4868 ReloadCustomArtwork(0);
4870 /* needed for displaying artwork name instead of artwork identifier */
4871 graphics_set_name = artwork.gfx_current->name;
4872 sounds_set_name = artwork.snd_current->name;
4873 music_set_name = artwork.mus_current->name;
4875 setup_mode = SETUP_MODE_ARTWORK;
4880 static void execSetupChooseGraphics()
4882 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
4887 static void execSetupChooseSounds()
4889 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
4894 static void execSetupChooseMusic()
4896 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
4901 #if !defined(PLATFORM_ANDROID)
4902 static void execSetupInput()
4904 setup_mode = SETUP_MODE_INPUT;
4910 static void execSetupShortcuts()
4912 setup_mode = SETUP_MODE_SHORTCUTS;
4917 static void execSetupShortcuts1()
4919 setup_mode = SETUP_MODE_SHORTCUTS_1;
4924 static void execSetupShortcuts2()
4926 setup_mode = SETUP_MODE_SHORTCUTS_2;
4931 static void execSetupShortcuts3()
4933 setup_mode = SETUP_MODE_SHORTCUTS_3;
4938 static void execSetupShortcuts4()
4940 setup_mode = SETUP_MODE_SHORTCUTS_4;
4945 static void execSetupShortcuts5()
4947 setup_mode = SETUP_MODE_SHORTCUTS_5;
4952 static void execExitSetup()
4954 game_status = GAME_MODE_MAIN;
4956 DrawMainMenuExt(REDRAW_FIELD, FALSE);
4959 static void execSaveAndExitSetup()
4965 static struct TokenInfo setup_info_main[] =
4967 { TYPE_ENTER_MENU, execSetupGame, "Game & Menu" },
4968 { TYPE_ENTER_MENU, execSetupEditor, "Editor" },
4969 { TYPE_ENTER_MENU, execSetupGraphics, "Graphics" },
4970 { TYPE_ENTER_MENU, execSetupSound, "Sound & Music" },
4971 { TYPE_ENTER_MENU, execSetupArtwork, "Custom Artwork" },
4972 #if !defined(PLATFORM_ANDROID)
4973 { TYPE_ENTER_MENU, execSetupInput, "Input Devices" },
4974 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4976 { TYPE_ENTER_MENU, execSetupTouch, "Touch Controls" },
4978 { TYPE_ENTER_MENU, execSetupShortcuts, "Key Shortcuts" },
4979 { TYPE_EMPTY, NULL, "" },
4980 { TYPE_LEAVE_MENU, execExitSetup, "Exit" },
4981 { TYPE_LEAVE_MENU, execSaveAndExitSetup, "Save and Exit" },
4986 static struct TokenInfo setup_info_game[] =
4988 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
4989 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
4990 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
4991 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
4992 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
4993 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
4994 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
4995 { TYPE_STRING, &game_speed_text, "" },
4997 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
4998 { TYPE_STRING, &scroll_delay_text, "" },
5000 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5001 { TYPE_STRING, &snapshot_mode_text, "" },
5002 { TYPE_EMPTY, NULL, "" },
5003 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5008 static struct TokenInfo setup_info_editor[] =
5011 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5012 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5013 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5014 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5015 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5016 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5017 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5018 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5020 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5021 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5022 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5024 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5026 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5027 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5028 { TYPE_EMPTY, NULL, "" },
5030 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5031 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5032 { TYPE_EMPTY, NULL, "" },
5034 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5035 { TYPE_EMPTY, NULL, "" },
5036 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5041 static struct TokenInfo setup_info_graphics[] =
5043 #if !defined(PLATFORM_ANDROID)
5044 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5045 #if defined(TARGET_SDL2)
5046 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5047 { TYPE_STRING, &window_size_text, "" },
5048 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5049 { TYPE_STRING, &scaling_type_text, "" },
5051 { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" },
5052 { TYPE_STRING, &screen_mode_text, "" },
5056 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5057 { TYPE_STRING, &scroll_delay_text, "" },
5059 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5060 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5061 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5062 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5063 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
5064 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5065 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5066 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5067 { TYPE_EMPTY, NULL, "" },
5068 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5073 static struct TokenInfo setup_info_sound[] =
5075 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5076 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5077 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5078 { TYPE_EMPTY, NULL, "" },
5079 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5080 { TYPE_STRING, &volume_simple_text, "" },
5081 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5082 { TYPE_STRING, &volume_loops_text, "" },
5083 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5084 { TYPE_STRING, &volume_music_text, "" },
5085 { TYPE_EMPTY, NULL, "" },
5086 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5091 static struct TokenInfo setup_info_artwork[] =
5093 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5094 { TYPE_STRING, &graphics_set_name, "" },
5095 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5096 { TYPE_STRING, &sounds_set_name, "" },
5097 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5098 { TYPE_STRING, &music_set_name, "" },
5099 { TYPE_EMPTY, NULL, "" },
5100 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5101 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5102 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5103 { TYPE_EMPTY, NULL, "" },
5104 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5109 static struct TokenInfo setup_info_input[] =
5111 { TYPE_SWITCH, NULL, "Player:" },
5112 { TYPE_SWITCH, NULL, "Device:" },
5113 { TYPE_ENTER_MENU, NULL, "" },
5114 { TYPE_EMPTY, NULL, "" },
5115 { TYPE_EMPTY, NULL, "" },
5116 { TYPE_EMPTY, NULL, "" },
5117 { TYPE_EMPTY, NULL, "" },
5118 { TYPE_EMPTY, NULL, "" },
5119 { TYPE_EMPTY, NULL, "" },
5120 { TYPE_EMPTY, NULL, "" },
5121 { TYPE_EMPTY, NULL, "" },
5122 { TYPE_EMPTY, NULL, "" },
5123 { TYPE_EMPTY, NULL, "" },
5124 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5129 static struct TokenInfo setup_info_touch[] =
5131 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
5132 { TYPE_STRING, &touch_controls_text, "" },
5133 { TYPE_EMPTY, NULL, "" },
5134 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
5135 { TYPE_STRING, &move_distance_text, "" },
5136 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
5137 { TYPE_STRING, &drop_distance_text, "" },
5138 { TYPE_EMPTY, NULL, "" },
5139 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5144 static struct TokenInfo setup_info_shortcuts[] =
5146 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
5147 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
5148 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
5149 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
5150 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
5151 { TYPE_EMPTY, NULL, "" },
5152 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5157 static struct TokenInfo setup_info_shortcuts_1[] =
5159 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
5160 { TYPE_KEY, &setup.shortcut.save_game, "" },
5161 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
5162 { TYPE_KEY, &setup.shortcut.load_game, "" },
5163 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
5164 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
5165 { TYPE_EMPTY, NULL, "" },
5166 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
5167 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
5168 { TYPE_EMPTY, NULL, "" },
5169 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5174 static struct TokenInfo setup_info_shortcuts_2[] =
5176 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
5177 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
5178 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
5179 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
5180 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
5181 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
5182 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
5183 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
5184 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
5185 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
5186 { TYPE_EMPTY, NULL, "" },
5187 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5192 static struct TokenInfo setup_info_shortcuts_3[] =
5194 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
5195 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
5196 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
5197 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
5198 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
5199 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
5200 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
5201 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
5202 { TYPE_KEYTEXT, NULL, "Record Tape:", },
5203 { TYPE_KEY, &setup.shortcut.tape_record, "" },
5204 { TYPE_KEYTEXT, NULL, "Play Tape:", },
5205 { TYPE_KEY, &setup.shortcut.tape_play, "" },
5206 { TYPE_EMPTY, NULL, "" },
5207 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5212 static struct TokenInfo setup_info_shortcuts_4[] =
5214 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
5215 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
5216 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
5217 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
5218 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
5219 { TYPE_KEY, &setup.shortcut.sound_music, "" },
5220 { TYPE_EMPTY, NULL, "" },
5221 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5226 static struct TokenInfo setup_info_shortcuts_5[] =
5228 { TYPE_KEYTEXT, NULL, "Snap Left:", },
5229 { TYPE_KEY, &setup.shortcut.snap_left, "" },
5230 { TYPE_KEYTEXT, NULL, "Snap Right:", },
5231 { TYPE_KEY, &setup.shortcut.snap_right, "" },
5232 { TYPE_KEYTEXT, NULL, "Snap Up:", },
5233 { TYPE_KEY, &setup.shortcut.snap_up, "" },
5234 { TYPE_KEYTEXT, NULL, "Snap Down:", },
5235 { TYPE_KEY, &setup.shortcut.snap_down, "" },
5236 { TYPE_EMPTY, NULL, "" },
5237 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
5242 static Key getSetupKey()
5244 Key key = KSYM_UNDEFINED;
5245 boolean got_key_event = FALSE;
5247 while (!got_key_event)
5249 if (PendingEvent()) /* got event */
5257 case EVENT_KEYPRESS:
5259 key = GetEventKey((KeyEvent *)&event, TRUE);
5261 /* press 'Escape' or 'Enter' to keep the existing key binding */
5262 if (key == KSYM_Escape || key == KSYM_Return)
5263 key = KSYM_UNDEFINED; /* keep old value */
5265 got_key_event = TRUE;
5269 case EVENT_KEYRELEASE:
5270 key_joystick_mapping = 0;
5274 HandleOtherEvents(&event);
5282 /* don't eat all CPU time */
5289 static int getSetupTextFont(int type)
5291 if (type & (TYPE_SWITCH |
5303 static int getSetupValueFont(int type, void *value)
5305 if (type & TYPE_KEY)
5306 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
5307 else if (type & TYPE_STRING)
5308 return FONT_VALUE_2;
5309 else if (type & TYPE_ECS_AGA)
5310 return FONT_VALUE_1;
5311 else if (type & TYPE_BOOLEAN_STYLE)
5312 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
5313 else if (type & TYPE_YES_NO_AUTO)
5314 return (*(int *)value == AUTO ? FONT_OPTION_ON :
5315 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
5317 return FONT_VALUE_1;
5320 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
5322 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5323 struct TokenInfo *si = &setup_info[si_pos];
5324 boolean font_draw_xoffset_modified = FALSE;
5325 int font_draw_xoffset_old = -1;
5326 int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
5327 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
5328 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
5329 int xpos = menu_screen_value_xpos;
5330 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5331 int startx = mSX + xpos * 32;
5332 int starty = mSY + ypos * 32;
5333 int font_nr, font_width;
5334 int type = si->type;
5335 void *value = si->value;
5336 char *value_string = getSetupValue(type, value);
5339 if (value_string == NULL)
5342 if (type & TYPE_KEY)
5344 xpos = MENU_SCREEN_START_XPOS;
5346 if (type & TYPE_QUERY)
5347 value_string = "<press key>";
5349 else if (type & TYPE_STRING)
5351 int max_value_len = (SCR_FIELDX - 2) * 2;
5353 xpos = MENU_SCREEN_START_XPOS;
5355 if (strlen(value_string) > max_value_len)
5356 value_string[max_value_len] = '\0';
5358 else if (type & TYPE_YES_NO_AUTO)
5360 xpos = menu_screen_value_xpos - 1;
5363 startx = mSX + xpos * 32;
5364 starty = mSY + ypos * 32;
5365 font_nr = getSetupValueFont(type, value);
5366 font_width = getFontWidth(font_nr);
5368 /* downward compatibility correction for Juergen Bonhagen's menu settings */
5369 if (setup_mode != SETUP_MODE_INPUT)
5371 int max_menu_text_length_big = (menu_screen_value_xpos -
5372 MENU_SCREEN_START_XPOS);
5373 int max_menu_text_length_medium = max_menu_text_length_big * 2;
5374 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
5375 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
5376 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
5377 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
5378 int text_font_nr = getSetupTextFont(FONT_MENU_2);
5379 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
5380 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
5381 boolean correct_font_draw_xoffset = FALSE;
5383 if (xpos == MENU_SCREEN_START_XPOS &&
5384 startx + font1_xoffset < text_startx + text_font_xoffset)
5385 correct_font_draw_xoffset = TRUE;
5387 if (xpos == menu_screen_value_xpos &&
5388 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
5389 correct_font_draw_xoffset = TRUE;
5391 /* check if setup value would overlap with setup text when printed */
5392 /* (this can happen for extreme/wrong values for font draw offset) */
5393 if (correct_font_draw_xoffset)
5395 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
5396 font_draw_xoffset_modified = TRUE;
5398 if (type & TYPE_KEY)
5399 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
5400 else if (!(type & TYPE_STRING))
5401 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
5402 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
5406 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
5407 DrawText(startx + i * font_width, starty, " ", font_nr);
5409 DrawText(startx, starty, value_string, font_nr);
5411 if (font_draw_xoffset_modified)
5412 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
5415 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
5417 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5418 struct TokenInfo *si = &setup_info[si_pos];
5420 if (si->type & TYPE_BOOLEAN_STYLE)
5422 *(boolean *)si->value ^= TRUE;
5424 else if (si->type & TYPE_YES_NO_AUTO)
5428 (*(int *)si->value == AUTO ? TRUE :
5429 *(int *)si->value == TRUE ? FALSE : AUTO) :
5430 (*(int *)si->value == TRUE ? AUTO :
5431 *(int *)si->value == AUTO ? FALSE : TRUE));
5433 else if (si->type & TYPE_KEY)
5437 si->type |= TYPE_QUERY;
5438 drawSetupValue(screen_pos, setup_info_pos_raw);
5439 si->type &= ~TYPE_QUERY;
5441 key = getSetupKey();
5442 if (key != KSYM_UNDEFINED)
5443 *(Key *)si->value = key;
5446 drawSetupValue(screen_pos, setup_info_pos_raw);
5448 // fullscreen state may have changed at this point
5449 if (si->value == &setup.fullscreen)
5450 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5453 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw,
5456 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
5457 struct TokenInfo *si = &setup_info[si_pos];
5458 int xpos = MENU_SCREEN_START_XPOS;
5459 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
5460 int font_nr = getSetupTextFont(si->type);
5462 if (setup_info == setup_info_input)
5463 font_nr = FONT_MENU_1;
5466 font_nr = FONT_ACTIVE(font_nr);
5468 DrawText(mSX + xpos * 32, mSY + ypos * 32, si->text, font_nr);
5470 if (si->type & ~TYPE_SKIP_ENTRY)
5471 drawCursor(screen_pos, active);
5474 static void drawSetupInfoList(struct TokenInfo *setup_info,
5475 int first_entry, int num_page_entries)
5479 if (num_page_entries > NUM_MENU_ENTRIES_ON_SCREEN)
5480 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
5482 if (num_page_entries > max_setup_info)
5483 num_page_entries = max_setup_info;
5485 if (first_entry + num_page_entries > max_setup_info)
5488 clearMenuListArea();
5490 for (i = 0; i < num_page_entries; i++)
5492 int setup_info_pos = first_entry + i;
5493 struct TokenInfo *si = &setup_info[setup_info_pos];
5494 void *value_ptr = si->value;
5496 /* set some entries to "unchangeable" according to other variables */
5497 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
5498 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
5499 (value_ptr == &setup.sound_music && !audio.music_available) ||
5500 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
5501 (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
5502 (value_ptr == &window_size_text && !video.window_scaling_available) ||
5503 (value_ptr == &scaling_type_text && !video.window_scaling_available))
5504 si->type |= TYPE_GHOSTED;
5506 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5507 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5508 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5509 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5510 else if (si->type & ~TYPE_SKIP_ENTRY)
5511 initCursor(i, IMG_MENU_BUTTON);
5513 DrawCursorAndText_Setup(i, setup_info_pos, FALSE);
5515 if (si->type & TYPE_VALUE)
5516 drawSetupValue(i, setup_info_pos);
5520 static void DrawSetupScreen_Generic()
5522 int fade_mask = (DrawingAreaChanged() ? REDRAW_ALL : REDRAW_FIELD);
5523 boolean redraw_all = FALSE;
5524 char *title_string = NULL;
5529 FreeScreenGadgets();
5530 CreateScreenGadgets();
5532 CloseDoor(DOOR_CLOSE_2);
5534 if (redraw_mask & REDRAW_ALL)
5541 if (setup_mode == SETUP_MODE_MAIN)
5543 setup_info = setup_info_main;
5544 title_string = "Setup";
5546 else if (setup_mode == SETUP_MODE_GAME)
5548 setup_info = setup_info_game;
5549 title_string = "Setup Game";
5551 else if (setup_mode == SETUP_MODE_EDITOR)
5553 setup_info = setup_info_editor;
5554 title_string = "Setup Editor";
5556 else if (setup_mode == SETUP_MODE_GRAPHICS)
5558 setup_info = setup_info_graphics;
5559 title_string = "Setup Graphics";
5561 else if (setup_mode == SETUP_MODE_SOUND)
5563 setup_info = setup_info_sound;
5564 title_string = "Setup Sound";
5566 else if (setup_mode == SETUP_MODE_ARTWORK)
5568 setup_info = setup_info_artwork;
5569 title_string = "Custom Artwork";
5571 else if (setup_mode == SETUP_MODE_TOUCH)
5573 setup_info = setup_info_touch;
5574 title_string = "Setup Touch Ctrls";
5576 else if (setup_mode == SETUP_MODE_SHORTCUTS)
5578 setup_info = setup_info_shortcuts;
5579 title_string = "Setup Shortcuts";
5581 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
5583 setup_info = setup_info_shortcuts_1;
5584 title_string = "Setup Shortcuts";
5586 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
5588 setup_info = setup_info_shortcuts_2;
5589 title_string = "Setup Shortcuts";
5591 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
5593 setup_info = setup_info_shortcuts_3;
5594 title_string = "Setup Shortcuts";
5596 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
5598 setup_info = setup_info_shortcuts_4;
5599 title_string = "Setup Shortcuts";
5601 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
5603 setup_info = setup_info_shortcuts_5;
5604 title_string = "Setup Shortcuts";
5607 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
5609 // determine maximal number of setup entries that can be displayed on screen
5611 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
5614 // determine maximal number of setup entries available for this setup screen
5616 for (i = 0; setup_info[i].type != 0; i++)
5619 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
5621 MapScreenGadgets(max_setup_info);
5624 redraw_mask = fade_mask = REDRAW_ALL;
5631 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
5633 static int choice_store[MAX_SETUP_MODES];
5634 static int first_entry_store[MAX_SETUP_MODES];
5635 int choice = choice_store[setup_mode]; /* starts with 0 */
5636 int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
5638 int y = choice - first_entry;
5640 boolean position_set_by_scrollbar = (dx == 999);
5641 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
5642 int num_page_entries;
5644 num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
5646 if (button == MB_MENU_INITIALIZE)
5648 /* advance to first valid menu entry */
5649 while (choice < num_setup_info &&
5650 setup_info[choice].type & TYPE_SKIP_ENTRY)
5653 if (position_set_by_scrollbar)
5654 first_entry = first_entry_store[setup_mode] = dy;
5656 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5657 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5659 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5661 if (choice < first_entry)
5663 choice = first_entry;
5665 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5668 else if (choice > first_entry + num_page_entries - 1)
5670 choice = first_entry + num_page_entries - 1;
5672 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5676 choice_store[setup_mode] = choice;
5678 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5682 else if (button == MB_MENU_LEAVE)
5686 PlaySound(SND_MENU_ITEM_SELECTING);
5688 for (i = 0; setup_info[i].type != 0; i++)
5690 if (setup_info[i].type & TYPE_LEAVE_MENU)
5692 void (*menu_callback_function)(void) = setup_info[i].value;
5696 menu_callback_function();
5698 break; /* absolutely needed because function changes 'setup_info'! */
5705 if (mx || my) /* mouse input */
5707 x = (mx - mSX) / 32;
5708 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
5710 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
5712 /* move cursor instead of scrolling when already at start/end of list */
5713 if (dy == -1 * SCROLL_LINE && first_entry == 0)
5715 else if (dy == +1 * SCROLL_LINE &&
5716 first_entry + num_page_entries == max_setup_info)
5719 /* handle scrolling screen one line or page */
5721 y + dy > num_page_entries - 1)
5723 boolean redraw = FALSE;
5725 if (ABS(dy) == SCROLL_PAGE)
5726 step = num_page_entries - 1;
5728 if (dy < 0 && first_entry > 0)
5730 /* scroll page/line up */
5732 first_entry -= step;
5733 if (first_entry < 0)
5738 else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
5740 /* scroll page/line down */
5742 first_entry += step;
5743 if (first_entry + num_page_entries > max_setup_info)
5744 first_entry = MAX(0, max_setup_info - num_page_entries);
5751 choice += first_entry - first_entry_store[setup_mode];
5753 if (choice < first_entry)
5755 choice = first_entry;
5757 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5760 else if (choice > first_entry + num_page_entries - 1)
5762 choice = first_entry + num_page_entries - 1;
5764 if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5767 else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
5771 if (choice < first_entry ||
5772 choice > first_entry + num_page_entries - 1)
5773 first_entry += SIGN(dy);
5776 first_entry_store[setup_mode] = first_entry;
5777 choice_store[setup_mode] = choice;
5779 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5781 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5783 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5784 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5792 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
5794 if (setup_info[choice].type & menu_navigation_type ||
5795 setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
5796 setup_info[choice].type & TYPE_YES_NO_AUTO)
5797 button = MB_MENU_CHOICE;
5802 /* jump to next non-empty menu entry (up or down) */
5803 while (first_entry + y > 0 &&
5804 first_entry + y < max_setup_info - 1 &&
5805 setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
5808 if (!IN_VIS_MENU(x, y))
5810 choice += y - y_old;
5812 if (choice < first_entry)
5813 first_entry = choice;
5814 else if (choice > first_entry + num_page_entries - 1)
5815 first_entry = choice - num_page_entries + 1;
5817 if (first_entry >= 0 &&
5818 first_entry + num_page_entries <= max_setup_info)
5820 first_entry_store[setup_mode] = first_entry;
5822 if (choice < first_entry)
5823 choice = first_entry;
5824 else if (choice > first_entry + num_page_entries - 1)
5825 choice = first_entry + num_page_entries - 1;
5827 choice_store[setup_mode] = choice;
5829 drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
5831 DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
5833 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
5834 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
5841 if (!anyScrollbarGadgetActive() &&
5842 IN_VIS_MENU(x, y) &&
5843 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
5844 y >= 0 && y < num_page_entries)
5848 if (first_entry + y != choice &&
5849 setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
5851 PlaySound(SND_MENU_ITEM_ACTIVATING);
5853 DrawCursorAndText_Setup(choice - first_entry, choice, FALSE);
5854 DrawCursorAndText_Setup(y, first_entry + y, TRUE);
5856 choice = choice_store[setup_mode] = first_entry + y;
5859 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED))
5861 PlaySound(SND_MENU_ITEM_SELECTING);
5863 /* when selecting key headline, execute function for key value change */
5864 if (setup_info[first_entry + y].type & TYPE_KEYTEXT &&
5865 setup_info[first_entry + y + 1].type & TYPE_KEY)
5868 /* when selecting string value, execute function for list selection */
5869 if (setup_info[first_entry + y].type & TYPE_STRING && y > 0 &&
5870 setup_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
5873 if (setup_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
5875 void (*menu_callback_function)(void) =
5876 setup_info[first_entry + y].value;
5878 FadeSetFromType(setup_info[first_entry + y].type);
5880 menu_callback_function();
5884 if (setup_info[first_entry + y].type & TYPE_VALUE)
5885 changeSetupValue(y, first_entry + y, dx);
5891 void DrawSetupScreen_Input()
5895 FadeOut(REDRAW_FIELD);
5899 setup_info = setup_info_input;
5901 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input");
5903 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2,
5904 "Joysticks deactivated on this screen");
5906 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
5908 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
5909 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
5910 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
5911 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
5912 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
5913 initCursor(i, IMG_MENU_BUTTON);
5915 DrawCursorAndText_Setup(i, -1, FALSE);
5918 /* create gadgets for setup input menu screen */
5919 FreeScreenGadgets();
5920 CreateScreenGadgets();
5922 /* map gadgets for setup input menu screen */
5923 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
5925 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
5927 FadeIn(REDRAW_FIELD);
5932 static void setJoystickDeviceToNr(char *device_name, int device_nr)
5934 if (device_name == NULL)
5937 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
5940 if (strlen(device_name) > 1)
5942 char c1 = device_name[strlen(device_name) - 1];
5943 char c2 = device_name[strlen(device_name) - 2];
5945 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
5946 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
5949 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
5950 strlen(device_name));
5953 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
5956 static struct SetupKeyboardInfo custom_key;
5963 { &custom_key.left, "Joystick Left" },
5964 { &custom_key.right, "Joystick Right" },
5965 { &custom_key.up, "Joystick Up" },
5966 { &custom_key.down, "Joystick Down" },
5967 { &custom_key.snap, "Button 1" },
5968 { &custom_key.drop, "Button 2" }
5970 static char *joystick_name[MAX_PLAYERS] =
5977 int text_font_nr = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
5981 custom_key = setup.input[player_nr].key;
5983 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
5984 FONT_INPUT_1_ACTIVE);
5986 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5988 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
5989 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
5991 if (setup.input[player_nr].use_joystick)
5993 char *device_name = setup.input[player_nr].joy.device_name;
5994 char *text = joystick_name[getJoystickNrFromDeviceName(device_name)];
5995 int font_nr = (joystick.fd[player_nr] < 0 ? FONT_VALUE_OLD : FONT_VALUE_1);
5997 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
5998 DrawText(mSX + 32, mSY + 4 * 32, "Calibrate", text_font_nr);
6002 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", FONT_VALUE_1);
6003 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", text_font_nr);
6006 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", FONT_MENU_1);
6008 drawCursorXY(1, 4, IMG_MENU_BUTTON_LEFT);
6009 drawCursorXY(1, 5, IMG_MENU_BUTTON_RIGHT);
6010 drawCursorXY(1, 6, IMG_MENU_BUTTON_UP);
6011 drawCursorXY(1, 7, IMG_MENU_BUTTON_DOWN);
6013 DrawText(mSX + 2 * 32, mSY + 6 * 32, ":", FONT_VALUE_OLD);
6014 DrawText(mSX + 2 * 32, mSY + 7 * 32, ":", FONT_VALUE_OLD);
6015 DrawText(mSX + 2 * 32, mSY + 8 * 32, ":", FONT_VALUE_OLD);
6016 DrawText(mSX + 2 * 32, mSY + 9 * 32, ":", FONT_VALUE_OLD);
6017 DrawText(mSX + 1 * 32, mSY + 10 * 32, "Snap Field:", FONT_VALUE_OLD);
6018 DrawText(mSX + 1 * 32, mSY + 12 * 32, "Drop Element:", FONT_VALUE_OLD);
6020 for (i = 0; i < 6; i++)
6022 int ypos = 6 + i + (i > 3 ? i-3 : 0);
6024 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6026 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6027 (setup.input[player_nr].use_joystick ?
6029 getKeyNameFromKey(*custom[i].key)), FONT_VALUE_1);
6033 static int input_player_nr = 0;
6035 void HandleSetupScreen_Input_Player(int step, int direction)
6037 int old_player_nr = input_player_nr;
6040 new_player_nr = old_player_nr + step * direction;
6041 if (new_player_nr < 0)
6043 if (new_player_nr > MAX_PLAYERS - 1)
6044 new_player_nr = MAX_PLAYERS - 1;
6046 if (new_player_nr != old_player_nr)
6048 input_player_nr = new_player_nr;
6050 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6054 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6056 static int choice = 0;
6059 int pos_start = SETUPINPUT_SCREEN_POS_START;
6060 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6061 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6062 int pos_end = SETUPINPUT_SCREEN_POS_END;
6064 if (button == MB_MENU_INITIALIZE)
6066 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6068 DrawCursorAndText_Setup(choice, -1, TRUE);
6072 else if (button == MB_MENU_LEAVE)
6074 setup_mode = SETUP_MODE_MAIN;
6081 if (mx || my) /* mouse input */
6083 x = (mx - mSX) / 32;
6084 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6086 else if (dx || dy) /* keyboard input */
6088 if (dx && choice == 0)
6089 x = (dx < 0 ? 10 : 12);
6090 else if ((dx && choice == 1) ||
6091 (dx == +1 && choice == 2) ||
6092 (dx == -1 && choice == pos_end))
6093 button = MB_MENU_CHOICE;
6097 if (y >= pos_empty1 && y <= pos_empty2)
6098 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6101 if (y == 0 && dx != 0 && button)
6103 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6105 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6106 y >= pos_start && y <= pos_end &&
6107 !(y >= pos_empty1 && y <= pos_empty2))
6113 DrawCursorAndText_Setup(choice, -1, FALSE);
6114 DrawCursorAndText_Setup(y, -1, TRUE);
6116 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6125 char *device_name = setup.input[input_player_nr].joy.device_name;
6127 if (!setup.input[input_player_nr].use_joystick)
6129 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6131 setJoystickDeviceToNr(device_name, new_device_nr);
6132 setup.input[input_player_nr].use_joystick = TRUE;
6136 int device_nr = getJoystickNrFromDeviceName(device_name);
6137 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6139 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6140 setup.input[input_player_nr].use_joystick = FALSE;
6142 setJoystickDeviceToNr(device_name, new_device_nr);
6145 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6149 if (setup.input[input_player_nr].use_joystick)
6152 CalibrateJoystick(input_player_nr);
6155 CustomizeKeyboard(input_player_nr);
6157 else if (y == pos_end)
6163 setup_mode = SETUP_MODE_MAIN;
6170 void CustomizeKeyboard(int player_nr)
6174 boolean finished = FALSE;
6175 static struct SetupKeyboardInfo custom_key;
6180 } customize_step[] =
6182 { &custom_key.left, "Move Left" },
6183 { &custom_key.right, "Move Right" },
6184 { &custom_key.up, "Move Up" },
6185 { &custom_key.down, "Move Down" },
6186 { &custom_key.snap, "Snap Field" },
6187 { &custom_key.drop, "Drop Element" }
6190 /* read existing key bindings from player setup */
6191 custom_key = setup.input[player_nr].key;
6194 FadeOut(REDRAW_FIELD);
6198 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6201 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6202 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6203 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6204 "Key:", FONT_INPUT_1_ACTIVE);
6205 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6206 getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD);
6208 FadeIn(REDRAW_FIELD);
6214 if (PendingEvent()) /* got event */
6222 case EVENT_KEYPRESS:
6224 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6226 if (key == KSYM_Escape || (key == KSYM_Return && step_nr == 6))
6228 if (key == KSYM_Escape)
6229 FadeSkipNextFadeIn();
6235 /* all keys configured -- wait for "Escape" or "Return" key */
6239 /* press 'Enter' to keep the existing key binding */
6240 if (key == KSYM_Return)
6241 key = *customize_step[step_nr].key;
6243 /* check if key already used */
6244 for (i = 0; i < step_nr; i++)
6245 if (*customize_step[i].key == key)
6250 /* got new key binding */
6251 *customize_step[step_nr].key = key;
6252 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6254 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6255 getKeyNameFromKey(key), FONT_VALUE_1);
6258 /* un-highlight last query */
6259 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6260 customize_step[step_nr - 1].text, FONT_MENU_1);
6261 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6262 "Key:", FONT_MENU_1);
6264 /* press 'Enter' to leave */
6267 DrawText(mSX + 16, mSY + 15 * 32 + 16,
6268 "Press Enter", FONT_TITLE_1);
6272 /* query next key binding */
6273 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6274 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6275 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6276 "Key:", FONT_INPUT_1_ACTIVE);
6277 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6278 getKeyNameFromKey(*customize_step[step_nr].key),
6283 case EVENT_KEYRELEASE:
6284 key_joystick_mapping = 0;
6288 HandleOtherEvents(&event);
6296 /* don't eat all CPU time */
6300 /* write new key bindings back to player setup */
6301 setup.input[player_nr].key = custom_key;
6304 DrawSetupScreen_Input();
6307 static boolean CalibrateJoystickMain(int player_nr)
6309 int new_joystick_xleft = JOYSTICK_XMIDDLE;
6310 int new_joystick_xright = JOYSTICK_XMIDDLE;
6311 int new_joystick_yupper = JOYSTICK_YMIDDLE;
6312 int new_joystick_ylower = JOYSTICK_YMIDDLE;
6313 int new_joystick_xmiddle, new_joystick_ymiddle;
6315 int joystick_fd = joystick.fd[player_nr];
6316 int x, y, last_x, last_y, xpos = 8, ypos = 3;
6317 boolean check[3][3];
6318 int check_remaining = 3 * 3;
6323 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
6326 if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
6330 FadeOut(REDRAW_FIELD);
6334 for (y = 0; y < 3; y++)
6336 for (x = 0; x < 3; x++)
6338 DrawFixedGraphic(xpos + x - 1, ypos + y - 1, IMG_MENU_CALIBRATE_BLUE, 0);
6339 check[x][y] = FALSE;
6343 DrawTextSCentered(mSY - SY + 6 * 32, FONT_TITLE_1, "Rotate joystick");
6344 DrawTextSCentered(mSY - SY + 7 * 32, FONT_TITLE_1, "in all directions");
6345 DrawTextSCentered(mSY - SY + 9 * 32, FONT_TITLE_1, "if all balls");
6346 DrawTextSCentered(mSY - SY + 10 * 32, FONT_TITLE_1, "are marked,");
6347 DrawTextSCentered(mSY - SY + 11 * 32, FONT_TITLE_1, "center joystick");
6348 DrawTextSCentered(mSY - SY + 12 * 32, FONT_TITLE_1, "and");
6349 DrawTextSCentered(mSY - SY + 13 * 32, FONT_TITLE_1, "press any button!");
6351 joy_value = Joystick(player_nr);
6352 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6353 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6355 /* eventually uncalibrated center position (joystick could be uncentered) */
6356 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6359 new_joystick_xmiddle = joy_x;
6360 new_joystick_ymiddle = joy_y;
6362 DrawFixedGraphic(xpos + last_x, ypos + last_y, IMG_MENU_CALIBRATE_RED, 0);
6364 FadeIn(REDRAW_FIELD);
6366 while (Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
6371 if (PendingEvent()) /* got event */
6379 case EVENT_KEYPRESS:
6380 switch (GetEventKey((KeyEvent *)&event, TRUE))
6383 if (check_remaining == 0)
6388 FadeSkipNextFadeIn();
6397 case EVENT_KEYRELEASE:
6398 key_joystick_mapping = 0;
6402 HandleOtherEvents(&event);
6407 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6410 new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
6411 new_joystick_xright = MAX(new_joystick_xright, joy_x);
6412 new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
6413 new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
6415 setup.input[player_nr].joy.xleft = new_joystick_xleft;
6416 setup.input[player_nr].joy.yupper = new_joystick_yupper;
6417 setup.input[player_nr].joy.xright = new_joystick_xright;
6418 setup.input[player_nr].joy.ylower = new_joystick_ylower;
6419 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
6420 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
6422 CheckJoystickData();
6424 joy_value = Joystick(player_nr);
6426 if (joy_value & JOY_BUTTON && check_remaining == 0)
6429 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
6430 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
6432 if (x != last_x || y != last_y)
6434 DrawFixedGraphic(xpos + last_x, ypos + last_y,
6435 IMG_MENU_CALIBRATE_YELLOW, 0);
6436 DrawFixedGraphic(xpos + x, ypos + y,
6437 IMG_MENU_CALIBRATE_RED, 0);
6442 if (check_remaining > 0 && !check[x+1][y+1])
6444 check[x+1][y+1] = TRUE;
6452 /* don't eat all CPU time */
6456 /* calibrated center position (joystick should now be centered) */
6457 if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
6460 new_joystick_xmiddle = joy_x;
6461 new_joystick_ymiddle = joy_y;
6465 /* wait until the last pressed button was released */
6466 while (Joystick(player_nr) & JOY_BUTTON)
6468 if (PendingEvent()) /* got event */
6473 HandleOtherEvents(&event);
6482 void CalibrateJoystick(int player_nr)
6484 if (!CalibrateJoystickMain(player_nr))
6486 char *device_name = setup.input[player_nr].joy.device_name;
6487 int nr = getJoystickNrFromDeviceName(device_name) + 1;
6488 int xpos = mSX - SX;
6489 int ypos = mSY - SY;
6493 DrawTextF(xpos + 16, ypos + 6 * 32, FONT_TITLE_1, " JOYSTICK %d ", nr);
6494 DrawTextF(xpos + 16, ypos + 7 * 32, FONT_TITLE_1, " NOT AVAILABLE! ");
6497 Delay(2000); /* show error message for a short time */
6502 DrawSetupScreen_Input();
6505 void DrawSetupScreen()
6507 DeactivateJoystick();
6509 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6511 if (setup_mode == SETUP_MODE_INPUT)
6512 DrawSetupScreen_Input();
6513 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6514 DrawChooseTree(&game_speed_current);
6515 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6516 DrawChooseTree(&scroll_delay_current);
6517 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6518 DrawChooseTree(&snapshot_mode_current);
6519 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6520 DrawChooseTree(&screen_mode_current);
6521 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6522 DrawChooseTree(&window_size_current);
6523 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6524 DrawChooseTree(&scaling_type_current);
6525 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6526 DrawChooseTree(&artwork.gfx_current);
6527 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6528 DrawChooseTree(&artwork.snd_current);
6529 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6530 DrawChooseTree(&artwork.mus_current);
6531 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6532 DrawChooseTree(&volume_simple_current);
6533 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6534 DrawChooseTree(&volume_loops_current);
6535 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6536 DrawChooseTree(&volume_music_current);
6537 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6538 DrawChooseTree(&touch_control_current);
6539 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6540 DrawChooseTree(&move_distance_current);
6541 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6542 DrawChooseTree(&drop_distance_current);
6544 DrawSetupScreen_Generic();
6550 void RedrawSetupScreenAfterFullscreenToggle()
6552 if (setup_mode == SETUP_MODE_GRAPHICS ||
6553 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6555 // update list selection from "setup.window_scaling_percent"
6556 execSetupGraphics_setWindowSizes(TRUE);
6562 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
6564 if (setup_mode == SETUP_MODE_INPUT)
6565 HandleSetupScreen_Input(mx, my, dx, dy, button);
6566 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
6567 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
6568 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
6569 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
6570 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
6571 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
6572 else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE)
6573 HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current);
6574 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6575 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
6576 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
6577 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
6578 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
6579 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
6580 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
6581 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
6582 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
6583 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
6584 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
6585 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
6586 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
6587 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
6588 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
6589 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
6590 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
6591 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
6592 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
6593 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
6594 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
6595 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
6597 HandleSetupScreen_Generic(mx, my, dx, dy, button);
6600 void HandleGameActions()
6602 if (game_status != GAME_MODE_PLAYING)
6605 GameActions(); /* main game loop */
6607 if (tape.auto_play && !tape.playing)
6608 AutoPlayTape(); /* continue automatically playing next tape */
6612 /* ---------- new screen button stuff -------------------------------------- */
6614 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
6618 case SCREEN_CTRL_ID_PREV_LEVEL:
6619 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
6620 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
6623 case SCREEN_CTRL_ID_NEXT_LEVEL:
6624 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
6625 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
6628 case SCREEN_CTRL_ID_PREV_PLAYER:
6629 *x = mSX + TILEX * 10;
6630 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6633 case SCREEN_CTRL_ID_NEXT_PLAYER:
6634 *x = mSX + TILEX * 12;
6635 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
6639 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
6645 int gfx_unpressed, gfx_pressed;
6646 void (*get_gadget_position)(int *, int *, int);
6650 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
6653 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
6654 getScreenMenuButtonPos,
6655 SCREEN_CTRL_ID_PREV_LEVEL,
6660 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
6661 getScreenMenuButtonPos,
6662 SCREEN_CTRL_ID_NEXT_LEVEL,
6667 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
6668 getScreenMenuButtonPos,
6669 SCREEN_CTRL_ID_PREV_PLAYER,
6674 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
6675 getScreenMenuButtonPos,
6676 SCREEN_CTRL_ID_NEXT_PLAYER,
6684 int gfx_unpressed, gfx_pressed;
6688 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
6691 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
6692 -1, -1, /* these values are not constant, but can change at runtime */
6693 SCREEN_CTRL_ID_SCROLL_UP,
6697 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
6698 -1, -1, /* these values are not constant, but can change at runtime */
6699 SCREEN_CTRL_ID_SCROLL_DOWN,
6706 int gfx_unpressed, gfx_pressed;
6712 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
6715 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
6716 -1, -1, /* these values are not constant, but can change at runtime */
6717 -1, -1, /* these values are not constant, but can change at runtime */
6718 GD_TYPE_SCROLLBAR_VERTICAL,
6719 SCREEN_CTRL_ID_SCROLL_VERTICAL,
6720 "scroll level series vertically"
6724 static void CreateScreenMenubuttons()
6726 struct GadgetInfo *gi;
6727 unsigned int event_mask;
6730 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6732 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6733 int gfx_unpressed, gfx_pressed;
6734 int x, y, width, height;
6735 int gd_x1, gd_x2, gd_y1, gd_y2;
6736 int id = menubutton_info[i].gadget_id;
6738 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6740 menubutton_info[i].get_gadget_position(&x, &y, id);
6742 width = SC_MENUBUTTON_XSIZE;
6743 height = SC_MENUBUTTON_YSIZE;
6745 gfx_unpressed = menubutton_info[i].gfx_unpressed;
6746 gfx_pressed = menubutton_info[i].gfx_pressed;
6747 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6748 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6749 gd_x1 = graphic_info[gfx_unpressed].src_x;
6750 gd_y1 = graphic_info[gfx_unpressed].src_y;
6751 gd_x2 = graphic_info[gfx_pressed].src_x;
6752 gd_y2 = graphic_info[gfx_pressed].src_y;
6754 gi = CreateGadget(GDI_CUSTOM_ID, id,
6755 GDI_CUSTOM_TYPE_ID, i,
6756 GDI_INFO_TEXT, menubutton_info[i].infotext,
6761 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6762 GDI_STATE, GD_BUTTON_UNPRESSED,
6763 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6764 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6765 GDI_DIRECT_DRAW, FALSE,
6766 GDI_EVENT_MASK, event_mask,
6767 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6771 Error(ERR_EXIT, "cannot create gadget");
6773 screen_gadget[id] = gi;
6777 static void CreateScreenScrollbuttons()
6779 struct GadgetInfo *gi;
6780 unsigned int event_mask;
6783 /* these values are not constant, but can change at runtime */
6784 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
6785 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
6786 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
6787 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
6789 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6791 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6792 int gfx_unpressed, gfx_pressed;
6793 int x, y, width, height;
6794 int gd_x1, gd_x2, gd_y1, gd_y2;
6795 int id = scrollbutton_info[i].gadget_id;
6797 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
6799 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
6800 y = mSY + scrollbutton_info[i].y;
6801 width = SC_SCROLLBUTTON_XSIZE;
6802 height = SC_SCROLLBUTTON_YSIZE;
6804 /* correct scrollbar position if placed outside menu (playfield) area */
6805 if (x > SX + SC_SCROLL_UP_XPOS)
6806 x = SX + SC_SCROLL_UP_XPOS;
6808 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
6809 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
6810 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
6812 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
6813 gfx_pressed = scrollbutton_info[i].gfx_pressed;
6814 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6815 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6816 gd_x1 = graphic_info[gfx_unpressed].src_x;
6817 gd_y1 = graphic_info[gfx_unpressed].src_y;
6818 gd_x2 = graphic_info[gfx_pressed].src_x;
6819 gd_y2 = graphic_info[gfx_pressed].src_y;
6821 gi = CreateGadget(GDI_CUSTOM_ID, id,
6822 GDI_CUSTOM_TYPE_ID, i,
6823 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
6828 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
6829 GDI_STATE, GD_BUTTON_UNPRESSED,
6830 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6831 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6832 GDI_DIRECT_DRAW, FALSE,
6833 GDI_EVENT_MASK, event_mask,
6834 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6838 Error(ERR_EXIT, "cannot create gadget");
6840 screen_gadget[id] = gi;
6844 static void CreateScreenScrollbars()
6848 /* these values are not constant, but can change at runtime */
6849 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
6850 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
6851 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
6852 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
6854 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6856 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
6857 int gfx_unpressed, gfx_pressed;
6858 int x, y, width, height;
6859 int gd_x1, gd_x2, gd_y1, gd_y2;
6860 struct GadgetInfo *gi;
6861 int items_max, items_visible, item_position;
6862 unsigned int event_mask;
6863 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
6864 int id = scrollbar_info[i].gadget_id;
6866 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
6868 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
6869 y = mSY + scrollbar_info[i].y;
6870 width = scrollbar_info[i].width;
6871 height = scrollbar_info[i].height;
6873 /* correct scrollbar position if placed outside menu (playfield) area */
6874 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
6875 x = SX + SC_SCROLL_VERTICAL_XPOS;
6877 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
6878 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
6880 items_max = num_page_entries;
6881 items_visible = num_page_entries;
6884 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
6885 gfx_pressed = scrollbar_info[i].gfx_pressed;
6886 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
6887 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
6888 gd_x1 = graphic_info[gfx_unpressed].src_x;
6889 gd_y1 = graphic_info[gfx_unpressed].src_y;
6890 gd_x2 = graphic_info[gfx_pressed].src_x;
6891 gd_y2 = graphic_info[gfx_pressed].src_y;
6893 gi = CreateGadget(GDI_CUSTOM_ID, id,
6894 GDI_CUSTOM_TYPE_ID, i,
6895 GDI_INFO_TEXT, scrollbar_info[i].infotext,
6900 GDI_TYPE, scrollbar_info[i].type,
6901 GDI_SCROLLBAR_ITEMS_MAX, items_max,
6902 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6903 GDI_SCROLLBAR_ITEM_POSITION, item_position,
6904 GDI_WHEEL_AREA_X, SX,
6905 GDI_WHEEL_AREA_Y, SY,
6906 GDI_WHEEL_AREA_WIDTH, SXSIZE,
6907 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
6908 GDI_STATE, GD_BUTTON_UNPRESSED,
6909 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
6910 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
6911 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
6912 GDI_DIRECT_DRAW, FALSE,
6913 GDI_EVENT_MASK, event_mask,
6914 GDI_CALLBACK_ACTION, HandleScreenGadgets,
6918 Error(ERR_EXIT, "cannot create gadget");
6920 screen_gadget[id] = gi;
6924 void CreateScreenGadgets()
6926 int last_game_status = game_status; /* save current game status */
6928 CreateScreenMenubuttons();
6930 CreateScreenScrollbuttons();
6931 CreateScreenScrollbars();
6933 game_status = last_game_status; /* restore current game status */
6936 void FreeScreenGadgets()
6940 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
6941 FreeGadget(screen_gadget[i]);
6944 void MapScreenMenuGadgets(int screen_mask)
6948 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
6949 if (screen_mask & menubutton_info[i].screen_mask)
6950 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
6953 void MapScreenGadgets(int num_entries)
6957 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
6960 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
6961 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
6963 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
6964 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
6967 void MapScreenTreeGadgets(TreeInfo *ti)
6969 MapScreenGadgets(numTreeInfoInGroup(ti));
6972 static void HandleScreenGadgets(struct GadgetInfo *gi)
6974 int id = gi->custom_id;
6975 int button = gi->event.button;
6976 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
6980 case SCREEN_CTRL_ID_PREV_LEVEL:
6981 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
6984 case SCREEN_CTRL_ID_NEXT_LEVEL:
6985 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
6988 case SCREEN_CTRL_ID_PREV_PLAYER:
6989 HandleSetupScreen_Input_Player(step, -1);
6992 case SCREEN_CTRL_ID_NEXT_PLAYER:
6993 HandleSetupScreen_Input_Player(step, +1);
6996 case SCREEN_CTRL_ID_SCROLL_UP:
6997 if (game_status == GAME_MODE_LEVELS)
6998 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
6999 else if (game_status == GAME_MODE_LEVELNR)
7000 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7001 else if (game_status == GAME_MODE_SETUP)
7002 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
7005 case SCREEN_CTRL_ID_SCROLL_DOWN:
7006 if (game_status == GAME_MODE_LEVELS)
7007 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7008 else if (game_status == GAME_MODE_LEVELNR)
7009 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7010 else if (game_status == GAME_MODE_SETUP)
7011 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
7014 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
7015 if (game_status == GAME_MODE_LEVELS)
7016 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7017 else if (game_status == GAME_MODE_LEVELNR)
7018 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
7019 else if (game_status == GAME_MODE_SETUP)
7020 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);