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"
27 #define DEBUG_JOYSTICKS 0
30 /* screens on the info screen */
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 /* screens on the setup screen */
43 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
44 /* (should also match corresponding entries in src/conf_gfx.c) */
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_EDITOR 2
48 #define SETUP_MODE_GRAPHICS 3
49 #define SETUP_MODE_SOUND 4
50 #define SETUP_MODE_ARTWORK 5
51 #define SETUP_MODE_INPUT 6
52 #define SETUP_MODE_TOUCH 7
53 #define SETUP_MODE_SHORTCUTS 8
54 #define SETUP_MODE_SHORTCUTS_1 9
55 #define SETUP_MODE_SHORTCUTS_2 10
56 #define SETUP_MODE_SHORTCUTS_3 11
57 #define SETUP_MODE_SHORTCUTS_4 12
58 #define SETUP_MODE_SHORTCUTS_5 13
60 /* sub-screens on the setup screen (generic) */
61 #define SETUP_MODE_CHOOSE_ARTWORK 14
62 #define SETUP_MODE_CHOOSE_OTHER 15
64 /* sub-screens on the setup screen (specific) */
65 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
70 #define SETUP_MODE_CHOOSE_RENDERING 21
71 #define SETUP_MODE_CHOOSE_GRAPHICS 22
72 #define SETUP_MODE_CHOOSE_SOUNDS 23
73 #define SETUP_MODE_CHOOSE_MUSIC 24
74 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
75 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
76 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
77 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
78 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
79 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
80 #define SETUP_MODE_CHOOSE_TRANSPARENCY 31
81 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 32
82 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 35
85 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 36
87 #define MAX_SETUP_MODES 37
89 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
91 /* setup screen titles */
92 #define STR_SETUP_MAIN "Setup"
93 #define STR_SETUP_GAME "Game & Menu"
94 #define STR_SETUP_EDITOR "Editor"
95 #define STR_SETUP_GRAPHICS "Graphics"
96 #define STR_SETUP_SOUND "Sound & Music"
97 #define STR_SETUP_ARTWORK "Custom Artwork"
98 #define STR_SETUP_INPUT "Input Devices"
99 #define STR_SETUP_TOUCH "Touch Controls"
100 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
101 #define STR_SETUP_EXIT "Exit"
102 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
104 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
105 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
106 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
107 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
108 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
109 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
110 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
111 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
112 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
113 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
114 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
115 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
116 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
117 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
118 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
119 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
120 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
122 /* for input setup functions */
123 #define SETUPINPUT_SCREEN_POS_START 0
124 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
125 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
126 #define SETUPINPUT_SCREEN_POS_END 13
128 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
129 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
131 /* for various menu stuff */
132 #define MENU_SCREEN_START_XPOS 1
133 #define MENU_SCREEN_START_YPOS 2
134 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
135 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
136 #define MENU_TITLE1_YPOS 8
137 #define MENU_TITLE2_YPOS 46
138 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
139 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
140 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
141 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
142 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
143 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
144 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
145 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
146 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
147 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
148 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
149 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
150 MENU_INFO_FONT_TITLE))
151 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
152 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
153 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
154 MENU_SCREEN_INFO_YSTART2 - \
156 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
157 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
158 MENU_SCREEN_INFO_YSTEP)
159 #define NUM_INFO_ELEMENTS_FROM_CONF \
160 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
161 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
162 MAX_MENU_ENTRIES_ON_SCREEN)
163 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
164 MAX_INFO_ELEMENTS_ON_SCREEN), \
165 NUM_INFO_ELEMENTS_FROM_CONF)
166 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
167 #define MAX_MENU_TEXT_LENGTH_BIG 13
168 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
170 /* buttons and scrollbars identifiers */
171 #define SCREEN_CTRL_ID_PREV_LEVEL 0
172 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
173 #define SCREEN_CTRL_ID_PREV_PLAYER 2
174 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
175 #define SCREEN_CTRL_ID_SCROLL_UP 4
176 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
177 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
179 #define NUM_SCREEN_GADGETS 7
181 #define NUM_SCREEN_MENUBUTTONS 4
182 #define NUM_SCREEN_SCROLLBUTTONS 2
183 #define NUM_SCREEN_SCROLLBARS 1
185 #define SCREEN_MASK_MAIN (1 << 0)
186 #define SCREEN_MASK_INPUT (1 << 1)
188 /* graphic position and size values for buttons and scrollbars */
189 #define SC_MENUBUTTON_XSIZE TILEX
190 #define SC_MENUBUTTON_YSIZE TILEY
192 #define SC_SCROLLBUTTON_XSIZE TILEX
193 #define SC_SCROLLBUTTON_YSIZE TILEY
195 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
197 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
198 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
199 SC_SCROLLBUTTON_YSIZE)
201 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
202 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
204 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
205 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
206 SC_SCROLLBUTTON_YSIZE)
208 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
209 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
210 SC_SCROLL_VERTICAL_YSIZE)
212 #define SC_BORDER_SIZE 14
215 /* forward declarations of internal functions */
216 static void HandleScreenGadgets(struct GadgetInfo *);
217 static void HandleSetupScreen_Generic(int, int, int, int, int);
218 static void HandleSetupScreen_Input(int, int, int, int, int);
219 static void CustomizeKeyboard(int);
220 static void ConfigureJoystick(int);
221 static void ConfigureVirtualButtons();
222 static void execSetupGame(void);
223 static void execSetupGraphics(void);
224 static void execSetupSound(void);
225 static void execSetupTouch(void);
226 static void execSetupArtwork(void);
227 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
229 static void DrawChooseLevelSet(void);
230 static void DrawChooseLevelNr(void);
231 static void DrawInfoScreen(void);
232 static void DrawSetupScreen(void);
234 static void DrawInfoScreen_NotAvailable(char *, char *);
235 static void DrawInfoScreen_HelpAnim(int, int, boolean);
236 static void DrawInfoScreen_HelpText(int, int, int, int);
237 static void HandleInfoScreen_Main(int, int, int, int, int);
238 static void HandleInfoScreen_TitleScreen(int);
239 static void HandleInfoScreen_Elements(int);
240 static void HandleInfoScreen_Music(int);
241 static void HandleInfoScreen_Credits(int);
242 static void HandleInfoScreen_Program(int);
243 static void HandleInfoScreen_Version(int);
245 static void MapScreenMenuGadgets(int);
246 static void MapScreenGadgets(int);
247 static void MapScreenTreeGadgets(TreeInfo *);
249 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
251 static int info_mode = INFO_MODE_MAIN;
252 static int setup_mode = SETUP_MODE_MAIN;
254 static TreeInfo *window_sizes = NULL;
255 static TreeInfo *window_size_current = NULL;
257 static TreeInfo *scaling_types = NULL;
258 static TreeInfo *scaling_type_current = NULL;
260 static TreeInfo *rendering_modes = NULL;
261 static TreeInfo *rendering_mode_current = NULL;
263 static TreeInfo *scroll_delays = NULL;
264 static TreeInfo *scroll_delay_current = NULL;
266 static TreeInfo *snapshot_modes = NULL;
267 static TreeInfo *snapshot_mode_current = NULL;
269 static TreeInfo *game_speeds = NULL;
270 static TreeInfo *game_speed_current = NULL;
272 static TreeInfo *volumes_simple = NULL;
273 static TreeInfo *volume_simple_current = NULL;
275 static TreeInfo *volumes_loops = NULL;
276 static TreeInfo *volume_loops_current = NULL;
278 static TreeInfo *volumes_music = NULL;
279 static TreeInfo *volume_music_current = NULL;
281 static TreeInfo *touch_controls = NULL;
282 static TreeInfo *touch_control_current = NULL;
284 static TreeInfo *move_distances = NULL;
285 static TreeInfo *move_distance_current = NULL;
287 static TreeInfo *drop_distances = NULL;
288 static TreeInfo *drop_distance_current = NULL;
290 static TreeInfo *transparencies = NULL;
291 static TreeInfo *transparency_current = NULL;
293 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
294 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
296 static TreeInfo *level_number = NULL;
297 static TreeInfo *level_number_current = NULL;
303 } window_sizes_list[] =
308 { 100, "100 % (Default)" },
325 } scaling_types_list[] =
327 { SCALING_QUALITY_NEAREST, "Off" },
328 { SCALING_QUALITY_LINEAR, "Linear" },
329 { SCALING_QUALITY_BEST, "Anisotropic" },
338 } rendering_modes_list[] =
340 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
341 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
343 // this mode may work under certain conditions, but does not work on Windows
344 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
346 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
355 } game_speeds_list[] =
364 { 1000, "1/1s (Extremely Slow)" },
369 { 29, "1/35s (Original Supaplex)" },
371 { 20, "1/50s (Normal Speed)" },
372 { 14, "1/70s (Maximum Supaplex)" },
376 { 1, "1/1000s (Extremely Fast)" },
386 } scroll_delays_list[] =
388 { 0, "0 Tiles (No Scroll Delay)" },
391 { 3, "3 Tiles (Default)" },
396 { 8, "8 Tiles (Maximum Scroll Delay)"},
405 } snapshot_modes_list[] =
407 { STR_SNAPSHOT_MODE_OFF, "Off" },
408 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
409 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
410 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
443 } touch_controls_list[] =
445 { TOUCH_CONTROL_OFF, "Off" },
446 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
447 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
448 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
476 } transparencies_list[] =
478 { 0, "0 % (Opaque)" },
488 { 100, "100 % (Invisible)" },
497 } grid_sizes_list[] =
533 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
534 (s) <= GAME_MODE_SETUP ? (s) : \
535 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
536 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
538 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
539 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
540 (i) <= INFO_MODE_LEVELSET ? (i) : \
543 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
544 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
545 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
546 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
547 SETUP_MODE_CHOOSE_ARTWORK : \
548 SETUP_MODE_CHOOSE_OTHER)
550 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
551 menu.draw_xoffset[GAME_MODE_INFO] : \
552 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
553 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
554 menu.draw_yoffset[GAME_MODE_INFO] : \
555 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
556 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
557 menu.extra_spacing[GAME_MODE_INFO] : \
558 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
560 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
561 menu.draw_xoffset[GAME_MODE_SETUP] : \
562 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
563 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
564 menu.draw_yoffset[GAME_MODE_SETUP] : \
565 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
566 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
567 menu.extra_spacing[GAME_MODE_SETUP] : \
568 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
570 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
571 DRAW_XOFFSET_INFO(info_mode) : \
572 (s) == GAME_MODE_SETUP ? \
573 DRAW_XOFFSET_SETUP(setup_mode) : \
574 menu.draw_xoffset[DRAW_MODE(s)])
575 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
576 DRAW_YOFFSET_INFO(info_mode) : \
577 (s) == GAME_MODE_SETUP ? \
578 DRAW_YOFFSET_SETUP(setup_mode) : \
579 menu.draw_yoffset[DRAW_MODE(s)])
580 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
581 EXTRA_SPACING_INFO(info_mode) : \
582 (s) == GAME_MODE_SETUP ? \
583 EXTRA_SPACING_SETUP(setup_mode) : \
584 menu.extra_spacing[DRAW_MODE(s)])
586 #define mSX (SX + DRAW_XOFFSET(game_status))
587 #define mSY (SY + DRAW_YOFFSET(game_status))
589 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
590 menu.list_size[game_status] : \
591 MAX_MENU_ENTRIES_ON_SCREEN)
593 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
594 NUM_MENU_ENTRIES_ON_SCREEN)
597 /* title display and control definitions */
599 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
600 2 * MAX_NUM_TITLE_MESSAGES)
602 #define NO_DIRECT_LEVEL_SELECT (-1)
605 static int num_title_screens = 0;
607 struct TitleControlInfo
616 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
618 /* main menu display and control definitions */
620 #define MAIN_CONTROL_NAME 0
621 #define MAIN_CONTROL_LEVELS 1
622 #define MAIN_CONTROL_SCORES 2
623 #define MAIN_CONTROL_EDITOR 3
624 #define MAIN_CONTROL_INFO 4
625 #define MAIN_CONTROL_GAME 5
626 #define MAIN_CONTROL_SETUP 6
627 #define MAIN_CONTROL_QUIT 7
628 #define MAIN_CONTROL_PREV_LEVEL 8
629 #define MAIN_CONTROL_NEXT_LEVEL 9
630 #define MAIN_CONTROL_FIRST_LEVEL 10
631 #define MAIN_CONTROL_LAST_LEVEL 11
632 #define MAIN_CONTROL_LEVEL_NUMBER 12
633 #define MAIN_CONTROL_LEVEL_INFO_1 13
634 #define MAIN_CONTROL_LEVEL_INFO_2 14
635 #define MAIN_CONTROL_LEVEL_NAME 15
636 #define MAIN_CONTROL_LEVEL_AUTHOR 16
637 #define MAIN_CONTROL_LEVEL_YEAR 17
638 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
639 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
640 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
641 #define MAIN_CONTROL_TITLE_1 21
642 #define MAIN_CONTROL_TITLE_2 22
643 #define MAIN_CONTROL_TITLE_3 23
645 static char str_main_text_name[10];
646 static char str_main_text_first_level[10];
647 static char str_main_text_last_level[10];
648 static char str_main_text_level_number[10];
650 static char *main_text_name = str_main_text_name;
651 static char *main_text_first_level = str_main_text_first_level;
652 static char *main_text_last_level = str_main_text_last_level;
653 static char *main_text_level_number = str_main_text_level_number;
654 static char *main_text_levels = "Levelset";
655 static char *main_text_scores = "Hall Of Fame";
656 static char *main_text_editor = "Level Creator";
657 static char *main_text_info = "Info Screen";
658 static char *main_text_game = "Start Game";
659 static char *main_text_setup = "Setup";
660 static char *main_text_quit = "Quit";
661 static char *main_text_level_name = level.name;
662 static char *main_text_level_author = level.author;
663 static char *main_text_level_year = NULL;
664 static char *main_text_level_imported_from = NULL;
665 static char *main_text_level_imported_by = NULL;
666 static char *main_text_level_tested_by = NULL;
667 static char *main_text_title_1 = NULL;
668 static char *main_text_title_2 = NULL;
669 static char *main_text_title_3 = NULL;
671 struct MainControlInfo
675 struct MenuPosInfo *pos_button;
678 struct TextPosInfo *pos_text;
681 struct TextPosInfo *pos_input;
685 static struct MainControlInfo main_controls[] =
689 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
690 &menu.main.text.name, &main_text_name,
691 &menu.main.input.name, &setup.player_name,
695 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
696 &menu.main.text.levels, &main_text_levels,
701 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
702 &menu.main.text.scores, &main_text_scores,
707 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
708 &menu.main.text.editor, &main_text_editor,
713 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
714 &menu.main.text.info, &main_text_info,
719 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
720 &menu.main.text.game, &main_text_game,
725 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
726 &menu.main.text.setup, &main_text_setup,
731 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
732 &menu.main.text.quit, &main_text_quit,
736 /* (these two buttons are real gadgets) */
738 MAIN_CONTROL_PREV_LEVEL,
739 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
744 MAIN_CONTROL_NEXT_LEVEL,
745 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
751 MAIN_CONTROL_FIRST_LEVEL,
752 &menu.main.button.first_level, IMG_MENU_BUTTON_FIRST_LEVEL,
753 &menu.main.text.first_level, &main_text_first_level,
757 MAIN_CONTROL_LAST_LEVEL,
758 &menu.main.button.last_level, IMG_MENU_BUTTON_LAST_LEVEL,
759 &menu.main.text.last_level, &main_text_last_level,
763 MAIN_CONTROL_LEVEL_NUMBER,
764 &menu.main.button.level_number, IMG_MENU_BUTTON_LEVEL_NUMBER,
765 &menu.main.text.level_number, &main_text_level_number,
769 MAIN_CONTROL_LEVEL_INFO_1,
771 &menu.main.text.level_info_1, NULL,
775 MAIN_CONTROL_LEVEL_INFO_2,
777 &menu.main.text.level_info_2, NULL,
781 MAIN_CONTROL_LEVEL_NAME,
783 &menu.main.text.level_name, &main_text_level_name,
787 MAIN_CONTROL_LEVEL_AUTHOR,
789 &menu.main.text.level_author, &main_text_level_author,
793 MAIN_CONTROL_LEVEL_YEAR,
795 &menu.main.text.level_year, &main_text_level_year,
799 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
801 &menu.main.text.level_imported_from, &main_text_level_imported_from,
805 MAIN_CONTROL_LEVEL_IMPORTED_BY,
807 &menu.main.text.level_imported_by, &main_text_level_imported_by,
811 MAIN_CONTROL_LEVEL_TESTED_BY,
813 &menu.main.text.level_tested_by, &main_text_level_tested_by,
817 MAIN_CONTROL_TITLE_1,
819 &menu.main.text.title_1, &main_text_title_1,
823 MAIN_CONTROL_TITLE_2,
825 &menu.main.text.title_2, &main_text_title_2,
829 MAIN_CONTROL_TITLE_3,
831 &menu.main.text.title_3, &main_text_title_3,
844 static int getTitleScreenGraphic(int nr, boolean initial)
846 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
849 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
851 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
855 static int getTitleScreenGameMode(boolean initial)
857 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
861 static int getTitleMessageGameMode(boolean initial)
863 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
866 static int getTitleAnimMode(struct TitleControlInfo *tci)
868 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
870 return base + tci->local_nr;
874 static int getTitleScreenBackground(boolean initial)
876 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
881 static int getTitleMessageBackground(int nr, boolean initial)
883 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
887 static int getTitleBackground(int nr, boolean initial, boolean is_image)
889 int base = (is_image ?
890 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
891 IMG_BACKGROUND_TITLESCREEN_1) :
892 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
893 IMG_BACKGROUND_TITLEMESSAGE_1));
894 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
895 IMG_BACKGROUND_TITLE);
896 int graphic_local = base + nr;
898 if (graphic_info[graphic_local].bitmap != NULL)
899 return graphic_local;
901 if (graphic_info[graphic_global].bitmap != NULL)
902 return graphic_global;
904 return IMG_UNDEFINED;
907 static int getTitleSound(struct TitleControlInfo *tci)
909 boolean is_image = tci->is_image;
910 int initial = tci->initial;
911 int nr = tci->local_nr;
912 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
913 int base = (is_image ?
914 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
915 SND_BACKGROUND_TITLESCREEN_1) :
916 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
917 SND_BACKGROUND_TITLEMESSAGE_1));
918 int sound_global = menu.sound[mode];
919 int sound_local = base + nr;
922 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
923 nr, initial, is_image,
924 sound_global, getSoundListEntry(sound_global)->filename,
925 sound_local, getSoundListEntry(sound_local)->filename);
928 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
931 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
934 return SND_UNDEFINED;
937 static int getTitleMusic(struct TitleControlInfo *tci)
939 boolean is_image = tci->is_image;
940 int initial = tci->initial;
941 int nr = tci->local_nr;
942 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
943 int base = (is_image ?
944 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
945 MUS_BACKGROUND_TITLESCREEN_1) :
946 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
947 MUS_BACKGROUND_TITLEMESSAGE_1));
948 int music_global = menu.music[mode];
949 int music_local = base + nr;
952 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
953 nr, initial, is_image,
954 music_global, getMusicListEntry(music_global)->filename,
955 music_local, getMusicListEntry(music_local)->filename);
958 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
961 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
964 return MUS_UNDEFINED;
967 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
969 boolean is_image = tci->is_image;
970 boolean initial = tci->initial;
971 boolean first = tci->first;
972 int nr = tci->local_nr;
973 struct TitleMessageInfo tmi;
974 struct TitleFadingInfo ti;
976 tmi = (is_image ? (initial ? (first ?
977 titlescreen_initial_first[nr] :
978 titlescreen_initial[nr])
980 titlescreen_first[nr] :
982 : (initial ? (first ?
983 titlemessage_initial_first[nr] :
984 titlemessage_initial[nr])
986 titlemessage_first[nr] :
989 ti.fade_mode = tmi.fade_mode;
990 ti.fade_delay = tmi.fade_delay;
991 ti.post_delay = tmi.post_delay;
992 ti.auto_delay = tmi.auto_delay;
997 static int compareTitleControlInfo(const void *object1, const void *object2)
999 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1000 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1003 if (tci1->initial != tci2->initial)
1004 compare_result = (tci1->initial ? -1 : +1);
1005 else if (tci1->sort_priority != tci2->sort_priority)
1006 compare_result = tci1->sort_priority - tci2->sort_priority;
1007 else if (tci1->is_image != tci2->is_image)
1008 compare_result = (tci1->is_image ? -1 : +1);
1010 compare_result = tci1->local_nr - tci2->local_nr;
1012 return compare_result;
1015 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1017 int nr, int sort_priority)
1019 title_controls[num_title_screens].is_image = is_image;
1020 title_controls[num_title_screens].initial = initial;
1021 title_controls[num_title_screens].local_nr = nr;
1022 title_controls[num_title_screens].sort_priority = sort_priority;
1024 title_controls[num_title_screens].first = FALSE; /* will be set later */
1026 num_title_screens++;
1029 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1033 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1035 int graphic = getTitleScreenGraphic(i, initial);
1036 Bitmap *bitmap = graphic_info[graphic].bitmap;
1037 int sort_priority = graphic_info[graphic].sort_priority;
1040 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1043 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1045 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1046 char *filename = getLevelSetTitleMessageFilename(i, initial);
1047 int sort_priority = tmi->sort_priority;
1049 if (filename != NULL)
1050 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1054 static void InitializeTitleControls(boolean show_title_initial)
1056 num_title_screens = 0;
1058 /* 1st step: initialize title screens for game start (only when starting) */
1059 if (show_title_initial)
1060 InitializeTitleControls_CheckTitleInfo(TRUE);
1062 /* 2nd step: initialize title screens for current level set */
1063 InitializeTitleControls_CheckTitleInfo(FALSE);
1065 /* sort title screens according to sort_priority and title number */
1066 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1067 compareTitleControlInfo);
1069 /* mark first title screen */
1070 title_controls[0].first = TRUE;
1073 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1075 return (pos != NULL && pos->x != -1 && pos->y != -1);
1078 static boolean visibleTextPos(struct TextPosInfo *pos)
1080 return (pos != NULL && pos->x != -1 && pos->y != -1);
1083 static void InitializeMainControls()
1085 boolean local_team_mode = (!options.network && setup.team_mode);
1088 /* set main control text values to dynamically determined values */
1089 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1091 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1092 menu.main.text.first_level.size));
1093 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1094 menu.main.text.last_level.size));
1095 strcpy(main_text_level_number, int2str(level_nr,
1096 menu.main.text.level_number.size));
1098 main_text_level_year = leveldir_current->year;
1099 main_text_level_imported_from = leveldir_current->imported_from;
1100 main_text_level_imported_by = leveldir_current->imported_by;
1101 main_text_level_tested_by = leveldir_current->tested_by;
1103 main_text_title_1 = getConfigProgramTitleString();
1104 main_text_title_2 = getConfigProgramCopyrightString();
1105 main_text_title_3 = getConfigProgramCompanyString();
1107 /* set main control screen positions to dynamically determined values */
1108 for (i = 0; main_controls[i].nr != -1; i++)
1110 struct MainControlInfo *mci = &main_controls[i];
1112 struct MenuPosInfo *pos_button = mci->pos_button;
1113 struct TextPosInfo *pos_text = mci->pos_text;
1114 struct TextPosInfo *pos_input = mci->pos_input;
1115 char *text = (mci->text ? *mci->text : NULL);
1116 char *input = (mci->input ? *mci->input : NULL);
1117 int button_graphic = mci->button_graphic;
1118 int font_text = (pos_text ? pos_text->font : -1);
1119 int font_input = (pos_input ? pos_input->font : -1);
1121 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1122 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1123 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1124 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1125 int text_chars = (text != NULL ? strlen(text) : 0);
1126 int input_chars = (input != NULL ? strlen(input) : 0);
1129 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1131 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1132 int text_width = font_text_width * text_chars;
1133 int text_height = font_text_height;
1134 int input_width = font_input_width * input_chars;
1135 int input_height = font_input_height;
1137 if (nr == MAIN_CONTROL_NAME)
1139 menu.main.input.name.width = input_width;
1140 menu.main.input.name.height = input_height;
1143 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1145 pos_button->width = button_width;
1146 pos_button->height = button_height;
1149 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1151 /* calculate text size -- needed for text alignment */
1152 boolean calculate_text_size = (text != NULL);
1154 if (pos_text->width == -1 || calculate_text_size)
1155 pos_text->width = text_width;
1156 if (pos_text->height == -1 || calculate_text_size)
1157 pos_text->height = text_height;
1159 if (visibleMenuPos(pos_button))
1161 if (pos_text->x == -1)
1162 pos_text->x = pos_button->x + pos_button->width;
1163 if (pos_text->y == -1)
1165 pos_button->y + (pos_button->height - pos_text->height) / 2;
1169 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1171 if (visibleTextPos(pos_text))
1173 if (pos_input->x == -1)
1174 pos_input->x = pos_text->x + pos_text->width;
1175 if (pos_input->y == -1)
1176 pos_input->y = pos_text->y;
1179 if (pos_input->width == -1)
1180 pos_input->width = input_width;
1181 if (pos_input->height == -1)
1182 pos_input->height = input_height;
1187 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1188 int graphic, boolean pressed)
1190 struct GraphicInfo *g = &graphic_info[graphic];
1193 int xoffset = (pressed ? g->pressed_xoffset : 0);
1194 int yoffset = (pressed ? g->pressed_yoffset : 0);
1196 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1198 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1199 g->width, g->height, dst_x, dst_y);
1202 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1203 boolean active_input,
1204 boolean pressed_button)
1208 for (i = 0; main_controls[i].nr != -1; i++)
1210 struct MainControlInfo *mci = &main_controls[i];
1212 if (mci->nr == nr || nr == -1)
1214 struct MenuPosInfo *pos_button = mci->pos_button;
1215 struct TextPosInfo *pos_text = mci->pos_text;
1216 struct TextPosInfo *pos_input = mci->pos_input;
1217 char *text = (mci->text ? *mci->text : NULL);
1218 char *input = (mci->input ? *mci->input : NULL);
1219 int button_graphic = mci->button_graphic;
1220 int font_text = (pos_text ? pos_text->font : -1);
1221 int font_input = (pos_input ? pos_input->font : -1);
1225 button_graphic = BUTTON_ACTIVE(button_graphic);
1226 font_text = FONT_ACTIVE(font_text);
1231 font_input = FONT_ACTIVE(font_input);
1234 if (visibleMenuPos(pos_button))
1236 struct MenuPosInfo *pos = pos_button;
1237 int x = mSX + pos->x;
1238 int y = mSY + pos->y;
1240 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1241 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1244 if (visibleTextPos(pos_text) && text != NULL)
1246 struct TextPosInfo *pos = pos_text;
1247 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1248 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1251 /* (check why/if this is needed) */
1252 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1254 DrawText(x, y, text, font_text);
1257 if (visibleTextPos(pos_input) && input != NULL)
1259 struct TextPosInfo *pos = pos_input;
1260 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1261 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1264 /* (check why/if this is needed) */
1265 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1267 DrawText(x, y, input, font_input);
1273 static void DrawCursorAndText_Main(int nr, boolean active_text,
1274 boolean pressed_button)
1276 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1280 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1281 boolean pressed_button)
1283 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1287 static struct MainControlInfo *getMainControlInfo(int nr)
1291 for (i = 0; main_controls[i].nr != -1; i++)
1292 if (main_controls[i].nr == nr)
1293 return &main_controls[i];
1298 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1303 int rect_x = ALIGNED_TEXT_XPOS(rect);
1304 int rect_y = ALIGNED_TEXT_YPOS(rect);
1306 return (x >= rect_x && x < rect_x + rect->width &&
1307 y >= rect_y && y < rect_y + rect->height);
1310 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1315 int rect_x = ALIGNED_TEXT_XPOS(rect);
1316 int rect_y = ALIGNED_TEXT_YPOS(rect);
1319 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1320 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1321 (x >= rect_x && x < rect_x + rect->width &&
1322 y >= rect_y && y < rect_y + rect->height));
1325 return (x >= rect_x && x < rect_x + rect->width &&
1326 y >= rect_y && y < rect_y + rect->height);
1329 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1331 int rect_width = preview->xsize * preview->tile_size;
1332 int rect_height = preview->ysize * preview->tile_size;
1333 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1334 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1336 return (x >= rect_x && x < rect_x + rect_width &&
1337 y >= rect_y && y < rect_y + rect_height);
1340 static void AdjustScrollbar(int id, int items_max, int items_visible,
1343 struct GadgetInfo *gi = screen_gadget[id];
1345 if (item_position > items_max - items_visible)
1346 item_position = items_max - items_visible;
1348 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1349 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1350 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1353 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1355 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1359 static void clearMenuListArea()
1361 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1363 /* correct scrollbar position if placed outside menu (playfield) area */
1364 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1365 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1367 /* clear menu list area, but not title or scrollbar */
1368 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1369 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1372 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1374 static int cursor_array[MAX_LEV_FIELDY];
1375 int x = mSX + TILEX * xpos;
1376 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1381 cursor_array[ypos] = graphic;
1383 graphic = cursor_array[ypos];
1387 graphic = BUTTON_ACTIVE(graphic);
1389 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1390 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1393 static void initCursor(int ypos, int graphic)
1395 drawCursorExt(0, ypos, FALSE, graphic);
1398 static void drawCursor(int ypos, boolean active)
1400 drawCursorExt(0, ypos, active, -1);
1403 static void drawCursorXY(int xpos, int ypos, int graphic)
1405 drawCursorExt(xpos, ypos, FALSE, graphic);
1408 static void drawChooseTreeCursor(int ypos, boolean active)
1410 drawCursorExt(0, ypos, active, -1);
1415 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1416 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1419 void DrawTitleScreenImage(int nr, boolean initial)
1421 int graphic = getTitleScreenGraphic(nr, initial);
1422 Bitmap *bitmap = graphic_info[graphic].bitmap;
1423 int width = graphic_info[graphic].width;
1424 int height = graphic_info[graphic].height;
1425 int src_x = graphic_info[graphic].src_x;
1426 int src_y = graphic_info[graphic].src_y;
1432 if (width > WIN_XSIZE)
1434 /* image width too large for window => center image horizontally */
1435 src_x = (width - WIN_XSIZE) / 2;
1439 if (height > WIN_YSIZE)
1441 /* image height too large for window => center image vertically */
1442 src_y = (height - WIN_YSIZE) / 2;
1446 /* always display title screens centered */
1447 dst_x = (WIN_XSIZE - width) / 2;
1448 dst_y = (WIN_YSIZE - height) / 2;
1450 SetDrawBackgroundMask(REDRAW_ALL);
1451 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1453 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1455 if (DrawingOnBackground(dst_x, dst_y))
1456 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1458 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1460 redraw_mask = REDRAW_ALL;
1463 void DrawTitleScreenMessage(int nr, boolean initial)
1465 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1466 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1468 if (filename == NULL)
1471 /* force TITLE font on title message screen */
1472 SetFontStatus(getTitleMessageGameMode(initial));
1474 /* if chars *and* width set to "-1", automatically determine width */
1475 if (tmi->chars == -1 && tmi->width == -1)
1476 tmi->width = viewport.window[game_status].width;
1478 /* if lines *and* height set to "-1", automatically determine height */
1479 if (tmi->lines == -1 && tmi->height == -1)
1480 tmi->height = viewport.window[game_status].height;
1482 /* if chars set to "-1", automatically determine by text and font width */
1483 if (tmi->chars == -1)
1484 tmi->chars = tmi->width / getFontWidth(tmi->font);
1486 tmi->width = tmi->chars * getFontWidth(tmi->font);
1488 /* if lines set to "-1", automatically determine by text and font height */
1489 if (tmi->lines == -1)
1490 tmi->lines = tmi->height / getFontHeight(tmi->font);
1492 tmi->height = tmi->lines * getFontHeight(tmi->font);
1494 /* if x set to "-1", automatically determine by width and alignment */
1496 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1498 /* if y set to "-1", automatically determine by height and alignment */
1500 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1502 SetDrawBackgroundMask(REDRAW_ALL);
1503 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1505 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1507 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1508 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1509 tmi->autowrap, tmi->centered, tmi->parse_comments);
1514 void DrawTitleScreen()
1516 KeyboardAutoRepeatOff();
1518 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1521 boolean CheckTitleScreen(boolean levelset_has_changed)
1523 static boolean show_title_initial = TRUE;
1524 boolean show_titlescreen = FALSE;
1526 /* needed to be able to skip title screen, if no image or message defined */
1527 InitializeTitleControls(show_title_initial);
1529 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1530 show_titlescreen = TRUE;
1532 /* show initial title images and messages only once at program start */
1533 show_title_initial = FALSE;
1535 return (show_titlescreen && num_title_screens > 0);
1540 static LevelDirTree *leveldir_last_valid = NULL;
1541 boolean levelset_has_changed = FALSE;
1542 int fade_mask = REDRAW_FIELD;
1544 LimitScreenUpdates(FALSE);
1546 FadeSetLeaveScreen();
1548 /* do not fade out here -- function may continue and fade on editor screen */
1551 FadeMenuSoundsAndMusic();
1553 ExpireSoundLoops(FALSE);
1555 KeyboardAutoRepeatOn();
1557 audio.sound_deactivated = FALSE;
1561 /* needed if last screen was the playing screen, invoked from level editor */
1562 if (level_editor_test_game)
1564 CloseDoor(DOOR_CLOSE_ALL);
1566 SetGameStatus(GAME_MODE_EDITOR);
1573 /* needed if last screen was the setup screen and fullscreen state changed */
1574 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1575 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1577 /* leveldir_current may be invalid (level group, parent link) */
1578 if (!validLevelSeries(leveldir_current))
1579 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1581 if (leveldir_current != leveldir_last_valid)
1582 levelset_has_changed = TRUE;
1584 /* store valid level series information */
1585 leveldir_last_valid = leveldir_current;
1587 init_last = init; /* switch to new busy animation */
1589 /* needed if last screen (level choice) changed graphics, sounds or music */
1590 ReloadCustomArtwork(0);
1592 if (CheckTitleScreen(levelset_has_changed))
1594 SetGameStatus(GAME_MODE_TITLE);
1601 if (redraw_mask & REDRAW_ALL)
1602 fade_mask = REDRAW_ALL;
1604 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1605 fade_mask = REDRAW_ALL;
1609 /* needed if different viewport properties defined for menues */
1610 ChangeViewportPropertiesIfNeeded();
1612 SetDrawtoField(DRAW_TO_BACKBUFFER);
1614 /* level_nr may have been set to value over handicap with level editor */
1615 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1616 level_nr = leveldir_current->handicap_level;
1618 LoadLevel(level_nr);
1619 LoadScore(level_nr);
1621 SaveLevelSetup_SeriesInfo();
1623 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1624 SetDrawDeactivationMask(REDRAW_NONE);
1625 SetDrawBackgroundMask(REDRAW_FIELD);
1627 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1630 if (fade_mask == REDRAW_ALL)
1631 RedrawGlobalBorder();
1636 InitializeMainControls();
1638 DrawCursorAndText_Main(-1, FALSE, FALSE);
1639 DrawPreviewLevelInitial();
1641 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1644 if (TAPE_IS_EMPTY(tape))
1646 DrawCompleteVideoDisplay();
1648 PlayMenuSoundsAndMusic();
1650 /* create gadgets for main menu screen */
1651 FreeScreenGadgets();
1652 CreateScreenGadgets();
1654 /* may be required if audio buttons shown on tape and changed in setup menu */
1656 CreateGameButtons();
1658 /* map gadgets for main menu screen */
1660 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1662 /* copy actual game door content to door double buffer for OpenDoor() */
1663 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1664 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1666 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1668 DrawMaskedBorder(fade_mask);
1673 /* update screen area with special editor door */
1674 redraw_mask |= REDRAW_ALL;
1677 SetMouseCursor(CURSOR_DEFAULT);
1679 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1682 static void gotoTopLevelDir()
1684 /* move upwards until inside (but not above) top level directory */
1685 while (leveldir_current->node_parent &&
1686 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1688 /* write a "path" into level tree for easy navigation to last level */
1689 if (leveldir_current->node_parent->node_group->cl_first == -1)
1691 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1692 int leveldir_pos = posTreeInfo(leveldir_current);
1693 int num_page_entries;
1694 int cl_first, cl_cursor;
1696 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1697 num_page_entries = num_leveldirs;
1699 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1701 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1702 cl_cursor = leveldir_pos - cl_first;
1704 leveldir_current->node_parent->node_group->cl_first = cl_first;
1705 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1708 leveldir_current = leveldir_current->node_parent;
1712 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1714 static unsigned int title_delay = 0;
1715 static int title_screen_nr = 0;
1716 static int last_sound = -1, last_music = -1;
1717 boolean return_to_main_menu = FALSE;
1718 struct TitleControlInfo *tci;
1721 if (button == MB_MENU_INITIALIZE)
1724 title_screen_nr = 0;
1725 tci = &title_controls[title_screen_nr];
1727 SetAnimStatus(getTitleAnimMode(tci));
1729 last_sound = SND_UNDEFINED;
1730 last_music = MUS_UNDEFINED;
1732 if (num_title_screens != 0)
1734 FadeSetEnterScreen();
1736 /* use individual title fading instead of global "enter screen" fading */
1737 fading = getTitleFading(tci);
1740 if (game_status_last_screen == GAME_MODE_INFO)
1742 if (num_title_screens == 0)
1744 /* switch game mode from title screen mode back to info screen mode */
1745 SetGameStatus(GAME_MODE_INFO);
1747 /* store that last screen was info screen, not main menu screen */
1748 game_status_last_screen = GAME_MODE_INFO;
1750 DrawInfoScreen_NotAvailable("Title screen information:",
1751 "No title screen for this level set.");
1755 FadeMenuSoundsAndMusic();
1758 FadeOut(REDRAW_ALL);
1760 /* title screens may have different window size */
1761 ChangeViewportPropertiesIfNeeded();
1763 /* only required to update logic for redrawing global border */
1767 DrawTitleScreenImage(tci->local_nr, tci->initial);
1769 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1771 sound = getTitleSound(tci);
1772 music = getTitleMusic(tci);
1774 if (sound != last_sound)
1775 PlayMenuSoundExt(sound);
1776 if (music != last_music)
1777 PlayMenuMusicExt(music);
1782 SetMouseCursor(CURSOR_NONE);
1786 DelayReached(&title_delay, 0); /* reset delay counter */
1791 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1792 button = MB_MENU_CHOICE;
1794 if (button == MB_MENU_LEAVE)
1796 return_to_main_menu = TRUE;
1798 else if (button == MB_MENU_CHOICE)
1800 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1802 SetGameStatus(GAME_MODE_INFO);
1804 info_mode = INFO_MODE_MAIN;
1813 if (title_screen_nr < num_title_screens)
1815 tci = &title_controls[title_screen_nr];
1817 SetAnimStatus(getTitleAnimMode(tci));
1819 sound = getTitleSound(tci);
1820 music = getTitleMusic(tci);
1822 if (last_sound != SND_UNDEFINED && sound != last_sound)
1823 FadeSound(last_sound);
1824 if (last_music != MUS_UNDEFINED && music != last_music)
1827 fading = getTitleFading(tci);
1829 FadeOut(REDRAW_ALL);
1832 DrawTitleScreenImage(tci->local_nr, tci->initial);
1834 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1836 sound = getTitleSound(tci);
1837 music = getTitleMusic(tci);
1839 if (sound != last_sound)
1840 PlayMenuSoundExt(sound);
1841 if (music != last_music)
1842 PlayMenuMusicExt(music);
1849 DelayReached(&title_delay, 0); /* reset delay counter */
1853 FadeMenuSoundsAndMusic();
1855 return_to_main_menu = TRUE;
1859 if (return_to_main_menu)
1861 SetMouseCursor(CURSOR_DEFAULT);
1863 /* force full menu screen redraw after displaying title screens */
1864 redraw_mask = REDRAW_ALL;
1866 if (game_status_last_screen == GAME_MODE_INFO)
1868 SetGameStatus(GAME_MODE_INFO);
1870 info_mode = INFO_MODE_MAIN;
1874 else /* default: return to main menu */
1876 SetGameStatus(GAME_MODE_MAIN);
1883 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1885 int old_level_nr = level_nr;
1888 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1889 new_level_nr = selected_level_nr;
1891 new_level_nr = old_level_nr + step * direction;
1893 if (new_level_nr < leveldir_current->first_level)
1894 new_level_nr = leveldir_current->first_level;
1895 if (new_level_nr > leveldir_current->last_level)
1896 new_level_nr = leveldir_current->last_level;
1898 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1900 /* skipping levels is only allowed when trying to skip single level */
1901 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1902 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1904 leveldir_current->handicap_level++;
1905 SaveLevelSetup_SeriesInfo();
1908 new_level_nr = leveldir_current->handicap_level;
1911 if (new_level_nr != old_level_nr)
1913 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1915 PlaySound(SND_MENU_ITEM_SELECTING);
1917 level_nr = new_level_nr;
1919 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1920 int2str(level_nr, menu.main.text.level_number.size),
1921 mci->pos_text->font);
1923 LoadLevel(level_nr);
1924 DrawPreviewLevelInitial();
1928 DrawCompleteVideoDisplay();
1930 SaveLevelSetup_SeriesInfo();
1932 /* needed because DrawPreviewLevelInitial() takes some time */
1934 /* SyncDisplay(); */
1938 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1940 static int choice = MAIN_CONTROL_GAME;
1941 static boolean button_pressed_last = FALSE;
1942 boolean button_pressed = FALSE;
1946 if (button == MB_MENU_INITIALIZE)
1948 DrawCursorAndText_Main(choice, TRUE, FALSE);
1953 if (mx || my) /* mouse input */
1957 for (i = 0; main_controls[i].nr != -1; i++)
1959 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1960 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1961 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1963 pos = main_controls[i].nr;
1969 /* check if level preview was clicked */
1970 if (insidePreviewRect(&preview, mx - SX, my - SY))
1971 pos = MAIN_CONTROL_GAME;
1973 // handle pressed/unpressed state for active/inactive menu buttons
1974 // (if pos != -1, "i" contains index position corresponding to "pos")
1976 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1977 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1978 button_pressed = TRUE;
1980 if (button_pressed != button_pressed_last)
1982 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1985 PlaySound(SND_MENU_BUTTON_PRESSING);
1987 PlaySound(SND_MENU_BUTTON_RELEASING);
1990 else if (dx || dy) /* keyboard input */
1992 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1993 choice == MAIN_CONTROL_SETUP))
1994 button = MB_MENU_CHOICE;
1999 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2001 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2003 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2005 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2007 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2009 CloseDoor(DOOR_CLOSE_2);
2011 SetGameStatus(GAME_MODE_LEVELNR);
2013 DrawChooseLevelNr();
2015 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2021 PlaySound(SND_MENU_ITEM_ACTIVATING);
2023 DrawCursorAndText_Main(choice, FALSE, FALSE);
2024 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2030 if (choice != MAIN_CONTROL_INFO &&
2031 choice != MAIN_CONTROL_SETUP)
2032 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2037 PlaySound(SND_MENU_ITEM_SELECTING);
2039 if (pos == MAIN_CONTROL_NAME)
2041 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2043 HandleTypeName(strlen(setup.player_name), 0);
2045 else if (pos == MAIN_CONTROL_LEVELS)
2049 CloseDoor(DOOR_CLOSE_2);
2051 SetGameStatus(GAME_MODE_LEVELS);
2053 SaveLevelSetup_LastSeries();
2054 SaveLevelSetup_SeriesInfo();
2056 if (setup.internal.choose_from_top_leveldir)
2059 DrawChooseLevelSet();
2062 else if (pos == MAIN_CONTROL_SCORES)
2064 CloseDoor(DOOR_CLOSE_2);
2066 SetGameStatus(GAME_MODE_SCORES);
2070 else if (pos == MAIN_CONTROL_EDITOR)
2072 if (leveldir_current->readonly &&
2073 !strEqual(setup.player_name, "Artsoft"))
2074 Request("This level is read only!", REQ_CONFIRM);
2076 CloseDoor(DOOR_CLOSE_2);
2078 SetGameStatus(GAME_MODE_EDITOR);
2080 FadeSetEnterScreen();
2084 else if (pos == MAIN_CONTROL_INFO)
2086 CloseDoor(DOOR_CLOSE_2);
2088 SetGameStatus(GAME_MODE_INFO);
2090 info_mode = INFO_MODE_MAIN;
2094 else if (pos == MAIN_CONTROL_GAME)
2096 StartGameActions(options.network, setup.autorecord, level.random_seed);
2098 else if (pos == MAIN_CONTROL_SETUP)
2100 CloseDoor(DOOR_CLOSE_2);
2102 SetGameStatus(GAME_MODE_SETUP);
2104 setup_mode = SETUP_MODE_MAIN;
2108 else if (pos == MAIN_CONTROL_QUIT)
2110 SaveLevelSetup_LastSeries();
2111 SaveLevelSetup_SeriesInfo();
2113 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2114 SetGameStatus(GAME_MODE_QUIT);
2119 button_pressed_last = button_pressed;
2123 /* ========================================================================= */
2124 /* info screen functions */
2125 /* ========================================================================= */
2127 static struct TokenInfo *info_info;
2128 static int num_info_info; /* number of info entries shown on screen */
2129 static int max_info_info; /* total number of info entries in list */
2131 static void execInfoTitleScreen()
2133 info_mode = INFO_MODE_TITLE;
2138 static void execInfoElements()
2140 info_mode = INFO_MODE_ELEMENTS;
2145 static void execInfoMusic()
2147 info_mode = INFO_MODE_MUSIC;
2152 static void execInfoCredits()
2154 info_mode = INFO_MODE_CREDITS;
2159 static void execInfoProgram()
2161 info_mode = INFO_MODE_PROGRAM;
2166 static void execInfoVersion()
2168 info_mode = INFO_MODE_VERSION;
2173 static void execInfoLevelSet()
2175 info_mode = INFO_MODE_LEVELSET;
2180 static void execExitInfo()
2182 SetGameStatus(GAME_MODE_MAIN);
2187 static struct TokenInfo info_info_main[] =
2189 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2190 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2191 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2192 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2193 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2194 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2195 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2196 { TYPE_EMPTY, NULL, "" },
2197 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2202 static int getMenuTextFont(int type)
2204 if (type & (TYPE_SWITCH |
2216 static struct TokenInfo *setup_info;
2217 static struct TokenInfo setup_info_input[];
2219 static struct TokenInfo *menu_info;
2221 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2222 int screen_pos, int menu_info_pos_raw,
2225 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2226 struct TokenInfo *ti = &token_info[pos];
2227 int xpos = MENU_SCREEN_START_XPOS;
2228 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2229 int font_nr = getMenuTextFont(ti->type);
2231 if (setup_mode == SETUP_MODE_INPUT)
2232 font_nr = FONT_MENU_1;
2235 font_nr = FONT_ACTIVE(font_nr);
2237 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2239 if (ti->type & ~TYPE_SKIP_ENTRY)
2240 drawCursor(screen_pos, active);
2243 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2246 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2249 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2252 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2255 static char *window_size_text;
2256 static char *scaling_type_text;
2258 static void drawSetupValue(int, int);
2260 static void drawMenuInfoList(int first_entry, int num_page_entries,
2261 int max_page_entries)
2265 if (first_entry + num_page_entries > max_page_entries)
2268 clearMenuListArea();
2270 for (i = 0; i < num_page_entries; i++)
2272 int menu_info_pos = first_entry + i;
2273 struct TokenInfo *si = &menu_info[menu_info_pos];
2274 void *value_ptr = si->value;
2276 /* set some entries to "unchangeable" according to other variables */
2277 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2278 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2279 (value_ptr == &setup.sound_music && !audio.music_available) ||
2280 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2281 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2282 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2283 si->type |= TYPE_GHOSTED;
2285 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2286 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2287 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2288 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2289 else if (si->type & ~TYPE_SKIP_ENTRY)
2290 initCursor(i, IMG_MENU_BUTTON);
2292 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2294 if (si->type & TYPE_VALUE &&
2295 menu_info == setup_info)
2296 drawSetupValue(i, menu_info_pos);
2300 static void DrawInfoScreen_Main()
2302 int fade_mask = REDRAW_FIELD;
2305 if (redraw_mask & REDRAW_ALL)
2306 fade_mask = REDRAW_ALL;
2308 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2309 fade_mask = REDRAW_ALL;
2312 FadeMenuSoundsAndMusic();
2314 FreeScreenGadgets();
2315 CreateScreenGadgets();
2317 /* (needed after displaying title screens which disable auto repeat) */
2318 KeyboardAutoRepeatOn();
2320 FadeSetLeaveScreen();
2324 /* needed if different viewport properties defined for info screen */
2325 ChangeViewportPropertiesIfNeeded();
2327 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2331 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2333 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2335 info_info = info_info_main;
2337 // determine maximal number of info entries that can be displayed on screen
2339 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2342 // determine maximal number of info entries available for menu of info screen
2344 for (i = 0; info_info[i].type != 0; i++)
2347 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2349 MapScreenGadgets(max_info_info);
2351 PlayMenuSoundsAndMusic();
2353 DrawMaskedBorder(fade_mask);
2358 static void changeSetupValue(int, int, int);
2360 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2361 int mode, int num_page_entries, int max_page_entries)
2363 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2364 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2365 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2366 int *num_page_entries_last = num_page_entries_all_last[game_status];
2367 int *choice_store = choice_stores[game_status];
2368 int *first_entry_store = first_entry_stores[game_status];
2369 int choice = choice_store[mode]; /* starts with 0 */
2370 int first_entry = first_entry_store[mode]; /* starts with 0 */
2372 int y = choice - first_entry;
2374 boolean position_set_by_scrollbar = (dx == 999);
2375 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2378 if (button == MB_MENU_INITIALIZE)
2380 // check if number of menu page entries has changed (may happen by change
2381 // of custom artwork definition value for 'list_size' for this menu screen)
2382 // (in this case, the last menu position most probably has to be corrected)
2383 if (num_page_entries != num_page_entries_last[mode])
2385 choice_store[mode] = first_entry_store[mode] = 0;
2387 choice = first_entry = 0;
2390 num_page_entries_last[mode] = num_page_entries;
2393 /* advance to first valid menu entry */
2394 while (choice < num_page_entries &&
2395 menu_info[choice].type & TYPE_SKIP_ENTRY)
2398 if (position_set_by_scrollbar)
2399 first_entry = first_entry_store[mode] = dy;
2401 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2402 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2404 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2406 if (choice < first_entry)
2408 choice = first_entry;
2410 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2413 else if (choice > first_entry + num_page_entries - 1)
2415 choice = first_entry + num_page_entries - 1;
2417 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2421 choice_store[mode] = choice;
2423 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2427 else if (button == MB_MENU_LEAVE)
2429 PlaySound(SND_MENU_ITEM_SELECTING);
2431 for (i = 0; i < max_page_entries; i++)
2433 if (menu_info[i].type & TYPE_LEAVE_MENU)
2435 void (*menu_callback_function)(void) = menu_info[i].value;
2439 menu_callback_function();
2441 break; /* absolutely needed because function changes 'menu_info'! */
2448 if (mx || my) /* mouse input */
2450 x = (mx - mSX) / 32;
2451 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2453 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2455 /* move cursor instead of scrolling when already at start/end of list */
2456 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2458 else if (dy == +1 * SCROLL_LINE &&
2459 first_entry + num_page_entries == max_page_entries)
2462 /* handle scrolling screen one line or page */
2464 y + dy > num_page_entries - 1)
2466 boolean redraw = FALSE;
2468 if (ABS(dy) == SCROLL_PAGE)
2469 step = num_page_entries - 1;
2471 if (dy < 0 && first_entry > 0)
2473 /* scroll page/line up */
2475 first_entry -= step;
2476 if (first_entry < 0)
2481 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2483 /* scroll page/line down */
2485 first_entry += step;
2486 if (first_entry + num_page_entries > max_page_entries)
2487 first_entry = MAX(0, max_page_entries - num_page_entries);
2494 choice += first_entry - first_entry_store[mode];
2496 if (choice < first_entry)
2498 choice = first_entry;
2500 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2503 else if (choice > first_entry + num_page_entries - 1)
2505 choice = first_entry + num_page_entries - 1;
2507 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2510 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2514 if (choice < first_entry ||
2515 choice > first_entry + num_page_entries - 1)
2516 first_entry += SIGN(dy);
2519 first_entry_store[mode] = first_entry;
2520 choice_store[mode] = choice;
2522 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2524 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2526 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2527 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2535 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2537 if (menu_info[choice].type & menu_navigation_type ||
2538 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2539 menu_info[choice].type & TYPE_YES_NO_AUTO)
2540 button = MB_MENU_CHOICE;
2545 /* jump to next non-empty menu entry (up or down) */
2546 while (first_entry + y > 0 &&
2547 first_entry + y < max_page_entries - 1 &&
2548 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2551 if (!IN_VIS_MENU(x, y))
2553 choice += y - y_old;
2555 if (choice < first_entry)
2556 first_entry = choice;
2557 else if (choice > first_entry + num_page_entries - 1)
2558 first_entry = choice - num_page_entries + 1;
2560 if (first_entry >= 0 &&
2561 first_entry + num_page_entries <= max_page_entries)
2563 first_entry_store[mode] = first_entry;
2565 if (choice < first_entry)
2566 choice = first_entry;
2567 else if (choice > first_entry + num_page_entries - 1)
2568 choice = first_entry + num_page_entries - 1;
2570 choice_store[mode] = choice;
2572 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2574 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2576 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2577 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2584 if (!anyScrollbarGadgetActive() &&
2585 IN_VIS_MENU(x, y) &&
2586 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2587 y >= 0 && y < num_page_entries)
2591 if (first_entry + y != choice &&
2592 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2594 PlaySound(SND_MENU_ITEM_ACTIVATING);
2596 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2597 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2599 choice = choice_store[mode] = first_entry + y;
2603 PlaySound(SND_MENU_ITEM_SELECTING);
2605 for (i = 0; menu_info[i].type != 0; i++)
2607 if (menu_info[i].type & TYPE_LEAVE_MENU)
2609 void (*menu_callback_function)(void) = menu_info[i].value;
2613 menu_callback_function();
2615 /* absolutely needed because function changes 'menu_info'! */
2623 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2625 PlaySound(SND_MENU_ITEM_SELECTING);
2627 /* when selecting key headline, execute function for key value change */
2628 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2629 menu_info[first_entry + y + 1].type & TYPE_KEY)
2632 /* when selecting string value, execute function for list selection */
2633 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2634 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2637 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2639 void (*menu_callback_function)(void) =
2640 menu_info[first_entry + y].value;
2642 FadeSetFromType(menu_info[first_entry + y].type);
2644 menu_callback_function();
2646 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2647 menu_info == setup_info)
2649 changeSetupValue(y, first_entry + y, dx);
2655 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2657 menu_info = info_info;
2659 HandleMenuScreen(mx, my, dx, dy, button,
2660 info_mode, num_info_info, max_info_info);
2663 static int getMenuFontSpacing(int spacing_height, int font_nr)
2665 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2667 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2671 static int getMenuTextSpacing(int spacing_height, int font_nr)
2673 return (getMenuFontSpacing(spacing_height, font_nr) +
2674 EXTRA_SPACING(game_status));
2677 static int getMenuTextStep(int spacing_height, int font_nr)
2679 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2682 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2684 int font_title = MENU_INFO_FONT_TITLE;
2685 int font_error = FONT_TEXT_2;
2686 int font_foot = MENU_INFO_FONT_FOOT;
2687 int spacing_title = menu.headline1_spacing_info[info_mode];
2688 int ystep_title = getMenuTextStep(spacing_title, font_title);
2689 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2690 int ystart2 = ystart1 + ystep_title;
2691 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2693 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2695 FadeOut(REDRAW_FIELD);
2700 DrawTextSCentered(ystart1, font_title, text_title);
2701 DrawTextSCentered(ystart2, font_error, text_error);
2703 DrawTextSCentered(ybottom, font_foot,
2704 "Press any key or button for info menu");
2706 FadeIn(REDRAW_FIELD);
2709 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2711 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2712 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2713 int font_title = MENU_INFO_FONT_TITLE;
2714 int font_foot = MENU_INFO_FONT_FOOT;
2715 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2716 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2717 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2718 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2719 int ystep = MENU_SCREEN_INFO_YSTEP;
2720 int element, action, direction;
2728 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2729 infoscreen_step[i] = infoscreen_frame[i] = 0;
2734 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2736 DrawTextSCentered(ybottom, font_foot,
2737 "Press any key or button for next page");
2743 while (helpanim_info[j].element != HELPANIM_LIST_END)
2745 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2750 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2759 j += infoscreen_step[i - start];
2761 element = helpanim_info[j].element;
2762 action = helpanim_info[j].action;
2763 direction = helpanim_info[j].direction;
2766 element = EL_UNKNOWN;
2768 if (action != -1 && direction != -1)
2769 graphic = el_act_dir2img(element, action, direction);
2770 else if (action != -1)
2771 graphic = el_act2img(element, action);
2772 else if (direction != -1)
2773 graphic = el_dir2img(element, direction);
2775 graphic = el2img(element);
2777 delay = helpanim_info[j++].delay;
2782 if (infoscreen_frame[i - start] == 0)
2785 infoscreen_frame[i - start] = delay - 1;
2789 sync_frame = delay - infoscreen_frame[i - start];
2790 infoscreen_frame[i - start]--;
2793 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2795 if (!infoscreen_frame[i - start])
2796 infoscreen_step[i - start] = 0;
2800 if (!infoscreen_frame[i - start])
2801 infoscreen_step[i - start]++;
2802 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2808 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2810 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2811 graphic, sync_frame, USE_MASKING);
2814 DrawInfoScreen_HelpText(element, action, direction, i - start);
2819 redraw_mask |= REDRAW_FIELD;
2824 static char *getHelpText(int element, int action, int direction)
2826 char token[MAX_LINE_LEN];
2828 strcpy(token, element_info[element].token_name);
2831 strcat(token, element_action_info[action].suffix);
2833 if (direction != -1)
2834 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2836 return getHashEntry(helptext_info, token);
2839 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2841 int font_nr = FONT_INFO_ELEMENTS;
2842 int font_width = getFontWidth(font_nr);
2843 int font_height = getFontHeight(font_nr);
2844 int yoffset = (TILEX - 2 * font_height) / 2;
2845 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2846 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2847 int ystep = TILEY + 4;
2848 int pad_left = xstart - SX;
2849 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2850 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2851 int max_lines_per_text = 2;
2854 if (action != -1 && direction != -1) /* element.action.direction */
2855 text = getHelpText(element, action, direction);
2857 if (text == NULL && action != -1) /* element.action */
2858 text = getHelpText(element, action, -1);
2860 if (text == NULL && direction != -1) /* element.direction */
2861 text = getHelpText(element, -1, direction);
2863 if (text == NULL) /* base element */
2864 text = getHelpText(element, -1, -1);
2866 if (text == NULL) /* not found */
2867 text = "No description available";
2869 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2870 ystart += getFontHeight(font_nr) / 2;
2872 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2873 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2874 TRUE, FALSE, FALSE);
2877 void DrawInfoScreen_TitleScreen()
2879 SetGameStatus(GAME_MODE_TITLE);
2884 void HandleInfoScreen_TitleScreen(int button)
2886 HandleTitleScreen(0, 0, 0, 0, button);
2889 void DrawInfoScreen_Elements()
2891 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2893 FadeOut(REDRAW_FIELD);
2898 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2900 FadeIn(REDRAW_FIELD);
2903 void HandleInfoScreen_Elements(int button)
2905 static unsigned int info_delay = 0;
2906 static int num_anims;
2907 static int num_pages;
2909 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2912 if (button == MB_MENU_INITIALIZE)
2914 boolean new_element = TRUE;
2918 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2920 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2922 else if (new_element)
2925 new_element = FALSE;
2929 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2933 if (button == MB_MENU_LEAVE)
2935 PlaySound(SND_MENU_ITEM_SELECTING);
2937 info_mode = INFO_MODE_MAIN;
2942 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2944 if (button != MB_MENU_INITIALIZE)
2946 PlaySound(SND_MENU_ITEM_SELECTING);
2951 if (page >= num_pages)
2953 FadeMenuSoundsAndMusic();
2955 info_mode = INFO_MODE_MAIN;
2962 FadeSetNextScreen();
2964 if (button != MB_MENU_INITIALIZE)
2965 FadeOut(REDRAW_FIELD);
2967 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2969 if (button != MB_MENU_INITIALIZE)
2970 FadeIn(REDRAW_FIELD);
2974 if (DelayReached(&info_delay, GameFrameDelay))
2975 if (page < num_pages)
2976 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2978 PlayMenuSoundIfLoop();
2982 void DrawInfoScreen_Music()
2984 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2986 FadeOut(REDRAW_FIELD);
2993 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2995 FadeIn(REDRAW_FIELD);
2998 void HandleInfoScreen_Music(int button)
3000 static struct MusicFileInfo *list = NULL;
3001 int font_title = MENU_INFO_FONT_TITLE;
3002 int font_head = MENU_INFO_FONT_HEAD;
3003 int font_text = MENU_INFO_FONT_TEXT;
3004 int font_foot = MENU_INFO_FONT_FOOT;
3005 int spacing_title = menu.headline1_spacing_info[info_mode];
3006 int spacing_head = menu.headline2_spacing_info[info_mode];
3007 int ystep_title = getMenuTextStep(spacing_title, font_title);
3008 int ystep_head = getMenuTextStep(spacing_head, font_head);
3009 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3010 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3012 if (button == MB_MENU_INITIALIZE)
3014 list = music_file_info;
3018 FadeMenuSoundsAndMusic();
3023 DrawTextSCentered(ystart, font_title,
3024 "No music info for this level set.");
3026 DrawTextSCentered(ybottom, font_foot,
3027 "Press any key or button for info menu");
3033 if (button == MB_MENU_LEAVE)
3035 PlaySound(SND_MENU_ITEM_SELECTING);
3037 FadeMenuSoundsAndMusic();
3039 info_mode = INFO_MODE_MAIN;
3044 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3046 if (button != MB_MENU_INITIALIZE)
3048 PlaySound(SND_MENU_ITEM_SELECTING);
3056 FadeMenuSoundsAndMusic();
3058 info_mode = INFO_MODE_MAIN;
3064 FadeMenuSoundsAndMusic();
3066 if (list != music_file_info)
3067 FadeSetNextScreen();
3069 if (button != MB_MENU_INITIALIZE)
3070 FadeOut(REDRAW_FIELD);
3077 int sound = list->music;
3079 if (sound_info[sound].loop)
3080 PlaySoundLoop(sound);
3084 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3088 PlayMusic(list->music);
3090 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3093 ystart += ystep_title;
3095 if (!strEqual(list->title, UNKNOWN_NAME))
3097 if (!strEqual(list->title_header, UNKNOWN_NAME))
3099 DrawTextSCentered(ystart, font_head, list->title_header);
3100 ystart += ystep_head;
3103 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3104 ystart += ystep_head;
3107 if (!strEqual(list->artist, UNKNOWN_NAME))
3109 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3110 DrawTextSCentered(ystart, font_head, list->artist_header);
3112 DrawTextSCentered(ystart, font_head, "by");
3114 ystart += ystep_head;
3116 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3117 ystart += ystep_head;
3120 if (!strEqual(list->album, UNKNOWN_NAME))
3122 if (!strEqual(list->album_header, UNKNOWN_NAME))
3123 DrawTextSCentered(ystart, font_head, list->album_header);
3125 DrawTextSCentered(ystart, font_head, "from the album");
3127 ystart += ystep_head;
3129 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3130 ystart += ystep_head;
3133 if (!strEqual(list->year, UNKNOWN_NAME))
3135 if (!strEqual(list->year_header, UNKNOWN_NAME))
3136 DrawTextSCentered(ystart, font_head, list->year_header);
3138 DrawTextSCentered(ystart, font_head, "from the year");
3140 ystart += ystep_head;
3142 DrawTextFCentered(ystart, font_text, "%s", list->year);
3143 ystart += ystep_head;
3146 DrawTextSCentered(ybottom, FONT_TEXT_4,
3147 "Press any key or button for next page");
3149 if (button != MB_MENU_INITIALIZE)
3150 FadeIn(REDRAW_FIELD);
3153 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3154 PlaySoundLoop(list->music);
3157 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3159 int font_title = MENU_INFO_FONT_TITLE;
3160 int font_head = MENU_INFO_FONT_HEAD;
3161 int font_text = MENU_INFO_FONT_TEXT;
3162 int font_foot = MENU_INFO_FONT_FOOT;
3163 int spacing_title = menu.headline1_spacing_info[info_mode];
3164 int spacing_head = menu.headline2_spacing_info[info_mode];
3165 int spacing_para = menu.paragraph_spacing_info[info_mode];
3166 int spacing_line = menu.line_spacing_info[info_mode];
3167 int ystep_title = getMenuTextStep(spacing_title, font_title);
3168 int ystep_head = getMenuTextStep(spacing_head, font_head);
3169 int ystep_para = getMenuTextStep(spacing_para, font_text);
3170 int ystep_line = getMenuTextStep(spacing_line, font_text);
3171 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3172 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3177 DrawTextSCentered(ystart, font_title, "Credits:");
3178 ystart += ystep_title;
3182 DrawTextSCentered(ystart, font_head,
3183 "Special thanks to");
3184 ystart += ystep_head;
3185 DrawTextSCentered(ystart, font_text,
3187 ystart += ystep_head;
3188 DrawTextSCentered(ystart, font_head,
3190 ystart += ystep_head;
3191 DrawTextSCentered(ystart, font_text,
3192 "\"Boulder Dash\"");
3193 ystart += ystep_head;
3194 DrawTextSCentered(ystart, font_head,
3196 ystart += ystep_head;
3197 DrawTextSCentered(ystart, font_text,
3199 ystart += ystep_head;
3200 DrawTextSCentered(ystart, font_head,
3202 ystart += ystep_head;
3203 DrawTextSCentered(ystart, font_text,
3204 "First Star Software");
3206 else if (screen_nr == 1)
3208 DrawTextSCentered(ystart, font_head,
3209 "Special thanks to");
3210 ystart += ystep_head;
3211 DrawTextSCentered(ystart, font_text,
3212 "Klaus Heinz & Volker Wertich");
3213 ystart += ystep_head;
3214 DrawTextSCentered(ystart, font_head,
3216 ystart += ystep_head;
3217 DrawTextSCentered(ystart, font_text,
3218 "\"Emerald Mine\"");
3219 ystart += ystep_head;
3220 DrawTextSCentered(ystart, font_head,
3222 ystart += ystep_head;
3223 DrawTextSCentered(ystart, font_text,
3225 ystart += ystep_head;
3226 DrawTextSCentered(ystart, font_head,
3228 ystart += ystep_head;
3229 DrawTextSCentered(ystart, font_text,
3232 else if (screen_nr == 2)
3234 DrawTextSCentered(ystart, font_head,
3235 "Special thanks to");
3236 ystart += ystep_head;
3237 DrawTextSCentered(ystart, font_text,
3238 "Michael Stopp & Philip Jespersen");
3239 ystart += ystep_head;
3240 DrawTextSCentered(ystart, font_head,
3242 ystart += ystep_head;
3243 DrawTextSCentered(ystart, font_text,
3245 ystart += ystep_head;
3246 DrawTextSCentered(ystart, font_head,
3248 ystart += ystep_head;
3249 DrawTextSCentered(ystart, font_text,
3251 ystart += ystep_head;
3252 DrawTextSCentered(ystart, font_head,
3254 ystart += ystep_head;
3255 DrawTextSCentered(ystart, font_text,
3256 "Digital Integration");
3258 else if (screen_nr == 3)
3260 DrawTextSCentered(ystart, font_head,
3261 "Special thanks to");
3262 ystart += ystep_head;
3263 DrawTextSCentered(ystart, font_text,
3264 "Hiroyuki Imabayashi");
3265 ystart += ystep_head;
3266 DrawTextSCentered(ystart, font_head,
3268 ystart += ystep_head;
3269 DrawTextSCentered(ystart, font_text,
3271 ystart += ystep_head;
3272 DrawTextSCentered(ystart, font_head,
3274 ystart += ystep_head;
3275 DrawTextSCentered(ystart, font_text,
3277 ystart += ystep_head;
3278 DrawTextSCentered(ystart, font_head,
3280 ystart += ystep_head;
3281 DrawTextSCentered(ystart, font_text,
3284 else if (screen_nr == 4)
3286 DrawTextSCentered(ystart, font_head,
3287 "Special thanks to");
3288 ystart += ystep_head;
3289 DrawTextSCentered(ystart, font_text,
3291 ystart += ystep_head;
3292 DrawTextSCentered(ystart, font_head,
3294 ystart += ystep_head;
3295 DrawTextSCentered(ystart, font_text,
3296 "J\xfcrgen Bonhagen");
3297 ystart += ystep_head;
3298 DrawTextSCentered(ystart, font_head,
3299 "for the continuous creation");
3300 ystart += ystep_line;
3301 DrawTextSCentered(ystart, font_head,
3302 "of outstanding level sets");
3304 else if (screen_nr == 5)
3306 DrawTextSCentered(ystart, font_head,
3308 ystart += ystep_head;
3309 DrawTextSCentered(ystart, font_text,
3311 ystart += ystep_head;
3312 DrawTextSCentered(ystart, font_head,
3313 "for ideas and inspiration by");
3314 ystart += ystep_head;
3315 DrawTextSCentered(ystart, font_text,
3317 ystart += ystep_para;
3319 DrawTextSCentered(ystart, font_head,
3321 ystart += ystep_head;
3322 DrawTextSCentered(ystart, font_text,
3324 ystart += ystep_head;
3325 DrawTextSCentered(ystart, font_head,
3326 "for ideas and inspiration by");
3327 ystart += ystep_head;
3328 DrawTextSCentered(ystart, font_text,
3331 else if (screen_nr == 6)
3333 DrawTextSCentered(ystart, font_head,
3335 ystart += ystep_head;
3336 DrawTextSCentered(ystart, font_text,
3338 ystart += ystep_head;
3339 DrawTextSCentered(ystart, font_head,
3340 "for the code base used for the");
3341 ystart += ystep_line;
3342 DrawTextSCentered(ystart, font_head,
3343 "native Emerald Mine engine");
3345 else if (screen_nr == 7)
3347 DrawTextSCentered(ystart, font_head,
3349 ystart += ystep_head;
3350 DrawTextSCentered(ystart, font_text,
3352 ystart += ystep_head;
3353 DrawTextSCentered(ystart, font_head,
3354 "for the initial DOS port");
3355 ystart += ystep_para;
3357 DrawTextSCentered(ystart, font_head,
3359 ystart += ystep_head;
3360 DrawTextSCentered(ystart, font_text,
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_head,
3364 "for some additional toons");
3366 else if (screen_nr == 8)
3368 DrawTextSCentered(ystart, font_head,
3369 "And not to forget:");
3370 ystart += ystep_head;
3371 DrawTextSCentered(ystart, font_head,
3373 ystart += ystep_head;
3374 DrawTextSCentered(ystart, font_text,
3375 "All those who contributed");
3376 ystart += ystep_line;
3377 DrawTextSCentered(ystart, font_text,
3378 "levels to this game");
3379 ystart += ystep_line;
3380 DrawTextSCentered(ystart, font_text,
3384 DrawTextSCentered(ybottom, font_foot,
3385 "Press any key or button for next page");
3388 void DrawInfoScreen_Credits()
3390 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3392 FadeMenuSoundsAndMusic();
3394 FadeOut(REDRAW_FIELD);
3396 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3398 FadeIn(REDRAW_FIELD);
3401 void HandleInfoScreen_Credits(int button)
3403 static int screen_nr = 0;
3404 int num_screens = 9;
3406 if (button == MB_MENU_INITIALIZE)
3410 // DrawInfoScreen_CreditsScreen(screen_nr);
3413 if (button == MB_MENU_LEAVE)
3415 PlaySound(SND_MENU_ITEM_SELECTING);
3417 info_mode = INFO_MODE_MAIN;
3422 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3424 if (button != MB_MENU_INITIALIZE)
3426 PlaySound(SND_MENU_ITEM_SELECTING);
3431 if (screen_nr >= num_screens)
3433 FadeMenuSoundsAndMusic();
3435 info_mode = INFO_MODE_MAIN;
3442 FadeSetNextScreen();
3444 if (button != MB_MENU_INITIALIZE)
3445 FadeOut(REDRAW_FIELD);
3447 DrawInfoScreen_CreditsScreen(screen_nr);
3449 if (button != MB_MENU_INITIALIZE)
3450 FadeIn(REDRAW_FIELD);
3454 PlayMenuSoundIfLoop();
3458 void DrawInfoScreen_Program()
3460 int font_title = MENU_INFO_FONT_TITLE;
3461 int font_head = MENU_INFO_FONT_HEAD;
3462 int font_text = MENU_INFO_FONT_TEXT;
3463 int font_foot = MENU_INFO_FONT_FOOT;
3464 int spacing_title = menu.headline1_spacing_info[info_mode];
3465 int spacing_head = menu.headline2_spacing_info[info_mode];
3466 int spacing_para = menu.paragraph_spacing_info[info_mode];
3467 int spacing_line = menu.line_spacing_info[info_mode];
3468 int ystep_title = getMenuTextStep(spacing_title, font_title);
3469 int ystep_head = getMenuTextStep(spacing_head, font_head);
3470 int ystep_para = getMenuTextStep(spacing_para, font_text);
3471 int ystep_line = getMenuTextStep(spacing_line, font_text);
3472 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3473 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3475 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3477 FadeOut(REDRAW_FIELD);
3482 DrawTextSCentered(ystart, font_title, "Program Information:");
3483 ystart += ystep_title;
3485 DrawTextSCentered(ystart, font_head,
3486 "This game is Freeware!");
3487 ystart += ystep_head;
3488 DrawTextSCentered(ystart, font_head,
3489 "If you like it, send e-mail to:");
3490 ystart += ystep_head;
3491 DrawTextSCentered(ystart, font_text,
3492 setup.internal.program_email);
3493 ystart += ystep_para;
3495 DrawTextSCentered(ystart, font_head,
3496 "More information and levels:");
3497 ystart += ystep_head;
3498 DrawTextSCentered(ystart, font_text,
3499 setup.internal.program_website);
3500 ystart += ystep_para;
3502 DrawTextSCentered(ystart, font_head,
3503 "If you have created new levels,");
3504 ystart += ystep_line;
3505 DrawTextSCentered(ystart, font_head,
3506 "send them to me to include them!");
3507 ystart += ystep_head;
3508 DrawTextSCentered(ystart, font_head,
3511 DrawTextSCentered(ybottom, font_foot,
3512 "Press any key or button for info menu");
3514 FadeIn(REDRAW_FIELD);
3517 void HandleInfoScreen_Program(int button)
3519 if (button == MB_MENU_LEAVE)
3521 PlaySound(SND_MENU_ITEM_SELECTING);
3523 info_mode = INFO_MODE_MAIN;
3528 else if (button == MB_MENU_CHOICE)
3530 PlaySound(SND_MENU_ITEM_SELECTING);
3532 FadeMenuSoundsAndMusic();
3534 info_mode = INFO_MODE_MAIN;
3539 PlayMenuSoundIfLoop();
3543 void DrawInfoScreen_Version()
3545 int font_title = MENU_INFO_FONT_TITLE;
3546 int font_head = MENU_INFO_FONT_HEAD;
3547 int font_text = MENU_INFO_FONT_TEXT;
3548 int font_foot = MENU_INFO_FONT_FOOT;
3549 int spacing_title = menu.headline1_spacing_info[info_mode];
3550 int spacing_head = menu.headline2_spacing_info[info_mode];
3551 int spacing_para = menu.paragraph_spacing_info[info_mode];
3552 int spacing_line = menu.line_spacing_info[info_mode];
3553 int xstep = getFontWidth(font_text);
3554 int ystep_title = getMenuTextStep(spacing_title, font_title);
3555 int ystep_head = getMenuTextStep(spacing_head, font_head);
3556 int ystep_para = getMenuTextStep(spacing_para, font_text);
3557 int ystep_line = getMenuTextStep(spacing_line, font_text);
3558 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3559 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3560 int xstart1 = mSX - SX + 2 * xstep;
3561 int xstart2 = mSX - SX + 18 * xstep;
3562 int xstart3 = mSX - SX + 28 * xstep;
3563 SDL_version sdl_version_compiled;
3564 const SDL_version *sdl_version_linked;
3565 int driver_name_len = 10;
3566 #if defined(TARGET_SDL2)
3567 SDL_version sdl_version_linked_ext;
3568 const char *driver_name = NULL;
3570 char driver_name[driver_name_len];
3573 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3575 FadeOut(REDRAW_FIELD);
3580 DrawTextSCentered(ystart, font_title, "Version Information:");
3581 ystart += ystep_title;
3583 DrawTextF(xstart1, ystart, font_head, "Name");
3584 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3585 ystart += ystep_line;
3587 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3589 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3590 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3591 ystart += ystep_line;
3593 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3594 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3595 ystart += ystep_line;
3599 DrawTextF(xstart1, ystart, font_head, "Version");
3600 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3601 ystart += ystep_line;
3604 DrawTextF(xstart1, ystart, font_head, "Platform");
3605 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3606 ystart += ystep_line;
3608 DrawTextF(xstart1, ystart, font_head, "Target");
3609 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3610 ystart += ystep_line;
3612 DrawTextF(xstart1, ystart, font_head, "Source date");
3613 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3614 ystart += ystep_para;
3616 DrawTextF(xstart1, ystart, font_head, "Library");
3617 DrawTextF(xstart2, ystart, font_head, "compiled");
3618 DrawTextF(xstart3, ystart, font_head, "linked");
3619 ystart += ystep_head;
3621 SDL_VERSION(&sdl_version_compiled);
3622 #if defined(TARGET_SDL2)
3623 SDL_GetVersion(&sdl_version_linked_ext);
3624 sdl_version_linked = &sdl_version_linked_ext;
3626 sdl_version_linked = SDL_Linked_Version();
3629 DrawTextF(xstart1, ystart, font_text, "SDL");
3630 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3631 sdl_version_compiled.major,
3632 sdl_version_compiled.minor,
3633 sdl_version_compiled.patch);
3634 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3635 sdl_version_linked->major,
3636 sdl_version_linked->minor,
3637 sdl_version_linked->patch);
3638 ystart += ystep_line;
3640 SDL_IMAGE_VERSION(&sdl_version_compiled);
3641 sdl_version_linked = IMG_Linked_Version();
3643 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3644 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3645 sdl_version_compiled.major,
3646 sdl_version_compiled.minor,
3647 sdl_version_compiled.patch);
3648 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3649 sdl_version_linked->major,
3650 sdl_version_linked->minor,
3651 sdl_version_linked->patch);
3652 ystart += ystep_line;
3654 SDL_MIXER_VERSION(&sdl_version_compiled);
3655 sdl_version_linked = Mix_Linked_Version();
3657 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3658 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3659 sdl_version_compiled.major,
3660 sdl_version_compiled.minor,
3661 sdl_version_compiled.patch);
3662 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3663 sdl_version_linked->major,
3664 sdl_version_linked->minor,
3665 sdl_version_linked->patch);
3666 ystart += ystep_line;
3668 SDL_NET_VERSION(&sdl_version_compiled);
3669 sdl_version_linked = SDLNet_Linked_Version();
3671 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3672 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3673 sdl_version_compiled.major,
3674 sdl_version_compiled.minor,
3675 sdl_version_compiled.patch);
3676 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3677 sdl_version_linked->major,
3678 sdl_version_linked->minor,
3679 sdl_version_linked->patch);
3680 ystart += ystep_para;
3682 DrawTextF(xstart1, ystart, font_head, "Driver");
3683 DrawTextF(xstart2, ystart, font_head, "Requested");
3684 DrawTextF(xstart3, ystart, font_head, "Used");
3685 ystart += ystep_head;
3687 #if defined(TARGET_SDL2)
3688 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3690 SDL_VideoDriverName(driver_name, driver_name_len);
3693 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3694 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3695 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3696 ystart += ystep_line;
3698 #if defined(TARGET_SDL2)
3699 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3701 SDL_AudioDriverName(driver_name, driver_name_len);
3704 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3705 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3706 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3708 DrawTextSCentered(ybottom, font_foot,
3709 "Press any key or button for info menu");
3711 FadeIn(REDRAW_FIELD);
3714 void HandleInfoScreen_Version(int button)
3716 if (button == MB_MENU_LEAVE)
3718 PlaySound(SND_MENU_ITEM_SELECTING);
3720 info_mode = INFO_MODE_MAIN;
3725 else if (button == MB_MENU_CHOICE)
3727 PlaySound(SND_MENU_ITEM_SELECTING);
3729 FadeMenuSoundsAndMusic();
3731 info_mode = INFO_MODE_MAIN;
3736 PlayMenuSoundIfLoop();
3740 void DrawInfoScreen_LevelSet()
3742 struct TitleMessageInfo *tmi = &readme;
3743 char *filename = getLevelSetInfoFilename();
3744 char *title = "Level Set Information:";
3745 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3746 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3748 if (filename == NULL)
3750 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3755 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3757 FadeOut(REDRAW_FIELD);
3762 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3764 /* if x position set to "-1", automatically determine by playfield width */
3766 tmi->x = SXSIZE / 2;
3768 /* if y position set to "-1", use static default value */
3772 /* if width set to "-1", automatically determine by playfield width */
3773 if (tmi->width == -1)
3774 tmi->width = SXSIZE - 2 * TILEX;
3776 /* if height set to "-1", automatically determine by playfield height */
3777 if (tmi->height == -1)
3778 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3780 /* if chars set to "-1", automatically determine by text and font width */
3781 if (tmi->chars == -1)
3782 tmi->chars = tmi->width / getFontWidth(tmi->font);
3784 tmi->width = tmi->chars * getFontWidth(tmi->font);
3786 /* if lines set to "-1", automatically determine by text and font height */
3787 if (tmi->lines == -1)
3788 tmi->lines = tmi->height / getFontHeight(tmi->font);
3790 tmi->height = tmi->lines * getFontHeight(tmi->font);
3792 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3793 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3794 tmi->autowrap, tmi->centered, tmi->parse_comments);
3796 DrawTextSCentered(ybottom, FONT_TEXT_4,
3797 "Press any key or button for info menu");
3799 FadeIn(REDRAW_FIELD);
3802 void HandleInfoScreen_LevelSet(int button)
3804 if (button == MB_MENU_LEAVE)
3806 PlaySound(SND_MENU_ITEM_SELECTING);
3808 info_mode = INFO_MODE_MAIN;
3813 else if (button == MB_MENU_CHOICE)
3815 PlaySound(SND_MENU_ITEM_SELECTING);
3817 FadeMenuSoundsAndMusic();
3819 info_mode = INFO_MODE_MAIN;
3824 PlayMenuSoundIfLoop();
3828 static void DrawInfoScreen()
3830 if (info_mode == INFO_MODE_TITLE)
3831 DrawInfoScreen_TitleScreen();
3832 else if (info_mode == INFO_MODE_ELEMENTS)
3833 DrawInfoScreen_Elements();
3834 else if (info_mode == INFO_MODE_MUSIC)
3835 DrawInfoScreen_Music();
3836 else if (info_mode == INFO_MODE_CREDITS)
3837 DrawInfoScreen_Credits();
3838 else if (info_mode == INFO_MODE_PROGRAM)
3839 DrawInfoScreen_Program();
3840 else if (info_mode == INFO_MODE_VERSION)
3841 DrawInfoScreen_Version();
3842 else if (info_mode == INFO_MODE_LEVELSET)
3843 DrawInfoScreen_LevelSet();
3845 DrawInfoScreen_Main();
3847 if (info_mode != INFO_MODE_MAIN &&
3848 info_mode != INFO_MODE_TITLE &&
3849 info_mode != INFO_MODE_MUSIC)
3850 PlayMenuSoundsAndMusic();
3853 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3855 if (info_mode == INFO_MODE_TITLE)
3856 HandleInfoScreen_TitleScreen(button);
3857 else if (info_mode == INFO_MODE_ELEMENTS)
3858 HandleInfoScreen_Elements(button);
3859 else if (info_mode == INFO_MODE_MUSIC)
3860 HandleInfoScreen_Music(button);
3861 else if (info_mode == INFO_MODE_CREDITS)
3862 HandleInfoScreen_Credits(button);
3863 else if (info_mode == INFO_MODE_PROGRAM)
3864 HandleInfoScreen_Program(button);
3865 else if (info_mode == INFO_MODE_VERSION)
3866 HandleInfoScreen_Version(button);
3867 else if (info_mode == INFO_MODE_LEVELSET)
3868 HandleInfoScreen_LevelSet(button);
3870 HandleInfoScreen_Main(mx, my, dx, dy, button);
3874 /* ========================================================================= */
3875 /* type name functions */
3876 /* ========================================================================= */
3878 void HandleTypeName(int newxpos, Key key)
3880 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3881 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3882 struct TextPosInfo *pos = mci->pos_input;
3883 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3884 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3885 static int xpos = 0;
3886 int font_nr = pos->font;
3887 int font_active_nr = FONT_ACTIVE(font_nr);
3888 int font_width = getFontWidth(font_active_nr);
3889 char key_char = getValidConfigValueChar(getCharFromKey(key));
3890 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3891 boolean is_active = TRUE;
3893 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3897 strcpy(last_player_name, setup.player_name);
3901 StartTextInput(startx, starty, pos->width, pos->height);
3903 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3905 setup.player_name[xpos] = key_char;
3906 setup.player_name[xpos + 1] = 0;
3910 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3914 setup.player_name[xpos] = 0;
3916 else if (key == KSYM_Return && xpos > 0)
3922 SetGameStatus(GAME_MODE_MAIN);
3924 else if (key == KSYM_Escape)
3926 strcpy(setup.player_name, last_player_name);
3930 SetGameStatus(GAME_MODE_MAIN);
3935 pos->width = (strlen(setup.player_name) + 1) * font_width;
3936 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3938 DrawText(startx, starty, setup.player_name, font_active_nr);
3939 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3943 pos->width = strlen(setup.player_name) * font_width;
3944 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3946 DrawText(startx, starty, setup.player_name, font_nr);
3953 /* ========================================================================= */
3954 /* tree menu functions */
3955 /* ========================================================================= */
3957 static void DrawChooseTree(TreeInfo **ti_ptr)
3959 int fade_mask = REDRAW_FIELD;
3961 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3962 fade_mask = REDRAW_ALL;
3964 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3966 SetGameStatus(GAME_MODE_MAIN);
3975 FreeScreenGadgets();
3976 CreateScreenGadgets();
3980 /* needed if different viewport properties defined for choosing level (set) */
3981 ChangeViewportPropertiesIfNeeded();
3983 if (game_status == GAME_MODE_LEVELNR)
3984 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3985 else if (game_status == GAME_MODE_LEVELS)
3986 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3990 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3992 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3993 MapScreenTreeGadgets(*ti_ptr);
3995 DrawMaskedBorder(fade_mask);
4000 static void drawChooseTreeList(int first_entry, int num_page_entries,
4004 char *title_string = NULL;
4005 int yoffset_sets = MENU_TITLE1_YPOS;
4006 int yoffset_setup = 16;
4007 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4008 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4010 title_string = ti->infotext;
4012 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4014 clearMenuListArea();
4016 for (i = 0; i < num_page_entries; i++)
4018 TreeInfo *node, *node_first;
4019 int entry_pos = first_entry + i;
4020 int xpos = MENU_SCREEN_START_XPOS;
4021 int ypos = MENU_SCREEN_START_YPOS + i;
4022 int startx = mSX + xpos * 32;
4023 int starty = mSY + ypos * 32;
4024 int font_nr = FONT_TEXT_1;
4025 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4026 int startx_text = startx + font_xoffset;
4027 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4028 int text_size = startx_scrollbar - startx_text;
4029 int max_buffer_len = text_size / getFontWidth(font_nr);
4030 char buffer[max_buffer_len + 1];
4032 node_first = getTreeInfoFirstGroupEntry(ti);
4033 node = getTreeInfoFromPos(node_first, entry_pos);
4035 strncpy(buffer, node->name, max_buffer_len);
4036 buffer[max_buffer_len] = '\0';
4038 DrawText(startx, starty, buffer, font_nr + node->color);
4040 if (node->parent_link)
4041 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4042 else if (node->level_group)
4043 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4045 initCursor(i, IMG_MENU_BUTTON);
4048 redraw_mask |= REDRAW_FIELD;
4051 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4053 TreeInfo *node, *node_first;
4054 int x, last_redraw_mask = redraw_mask;
4055 int ypos = MENU_TITLE2_YPOS;
4056 int font_nr = FONT_TITLE_2;
4058 if (ti->type == TREE_TYPE_LEVEL_NR)
4059 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4061 if (ti->type != TREE_TYPE_LEVEL_DIR)
4064 node_first = getTreeInfoFirstGroupEntry(ti);
4065 node = getTreeInfoFromPos(node_first, entry_pos);
4067 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4069 if (node->parent_link)
4070 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4071 node->node_parent->name);
4072 else if (node->level_group)
4073 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4075 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4076 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4077 node->levels, (node->levels > 1 ? "levels" : "level"),
4080 /* let BackToFront() redraw only what is needed */
4081 redraw_mask = last_redraw_mask;
4082 for (x = 0; x < SCR_FIELDX; x++)
4083 MarkTileDirty(x, 1);
4086 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4089 TreeInfo *ti = *ti_ptr;
4091 int y = ti->cl_cursor;
4092 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4093 int num_entries = numTreeInfoInGroup(ti);
4094 int num_page_entries;
4095 boolean position_set_by_scrollbar = (dx == 999);
4097 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4098 num_page_entries = num_entries;
4100 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4102 if (button == MB_MENU_INITIALIZE)
4104 int num_entries = numTreeInfoInGroup(ti);
4105 int entry_pos = posTreeInfo(ti);
4107 if (ti->cl_first == -1)
4109 /* only on initialization */
4110 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4111 ti->cl_cursor = entry_pos - ti->cl_first;
4113 else if (ti->cl_cursor >= num_page_entries ||
4114 (num_entries > num_page_entries &&
4115 num_entries - ti->cl_first < num_page_entries))
4117 /* only after change of list size (by custom graphic configuration) */
4118 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4119 ti->cl_cursor = entry_pos - ti->cl_first;
4122 if (position_set_by_scrollbar)
4125 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4128 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4129 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4130 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4134 else if (button == MB_MENU_LEAVE)
4138 PlaySound(SND_MENU_ITEM_SELECTING);
4140 if (ti->node_parent)
4142 *ti_ptr = ti->node_parent;
4143 DrawChooseTree(ti_ptr);
4145 else if (game_status == GAME_MODE_SETUP)
4147 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4148 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4149 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4151 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4152 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4153 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4154 execSetupGraphics();
4155 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4156 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4157 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4159 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4160 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4161 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4162 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4163 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4164 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4165 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4166 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4173 if (game_status == GAME_MODE_LEVELNR)
4175 int new_level_nr = atoi(level_number_current->identifier);
4177 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4180 SetGameStatus(GAME_MODE_MAIN);
4188 if (mx || my) /* mouse input */
4190 x = (mx - mSX) / 32;
4191 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4193 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4195 /* move cursor instead of scrolling when already at start/end of list */
4196 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4198 else if (dy == +1 * SCROLL_LINE &&
4199 ti->cl_first + num_page_entries == num_entries)
4202 /* handle scrolling screen one line or page */
4203 if (ti->cl_cursor + dy < 0 ||
4204 ti->cl_cursor + dy > num_page_entries - 1)
4206 boolean redraw = FALSE;
4208 if (ABS(dy) == SCROLL_PAGE)
4209 step = num_page_entries - 1;
4211 if (dy < 0 && ti->cl_first > 0)
4213 /* scroll page/line up */
4215 ti->cl_first -= step;
4216 if (ti->cl_first < 0)
4221 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4223 /* scroll page/line down */
4225 ti->cl_first += step;
4226 if (ti->cl_first + num_page_entries > num_entries)
4227 ti->cl_first = MAX(0, num_entries - num_page_entries);
4234 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4235 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4236 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4238 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4245 /* handle moving cursor one line */
4246 y = ti->cl_cursor + dy;
4251 TreeInfo *node_first, *node_cursor;
4252 int entry_pos = ti->cl_first + y;
4254 node_first = getTreeInfoFirstGroupEntry(ti);
4255 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4257 if (node_cursor->node_group)
4261 PlaySound(SND_MENU_ITEM_SELECTING);
4263 node_cursor->cl_first = ti->cl_first;
4264 node_cursor->cl_cursor = ti->cl_cursor;
4265 *ti_ptr = node_cursor->node_group;
4266 DrawChooseTree(ti_ptr);
4271 else if (dx == -1 && ti->node_parent)
4275 PlaySound(SND_MENU_ITEM_SELECTING);
4277 *ti_ptr = ti->node_parent;
4278 DrawChooseTree(ti_ptr);
4283 if (!anyScrollbarGadgetActive() &&
4284 IN_VIS_MENU(x, y) &&
4285 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4286 y >= 0 && y < num_page_entries)
4290 if (y != ti->cl_cursor)
4292 PlaySound(SND_MENU_ITEM_ACTIVATING);
4294 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4295 drawChooseTreeCursor(y, TRUE);
4296 drawChooseTreeInfo(ti->cl_first + y, ti);
4302 if (game_status == GAME_MODE_SETUP)
4304 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4305 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4306 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4308 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4309 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4310 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4311 execSetupGraphics();
4312 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4313 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4314 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4316 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4317 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4318 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4319 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4320 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4321 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4322 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4323 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4332 TreeInfo *node_first, *node_cursor;
4333 int entry_pos = ti->cl_first + y;
4335 PlaySound(SND_MENU_ITEM_SELECTING);
4337 node_first = getTreeInfoFirstGroupEntry(ti);
4338 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4340 if (node_cursor->node_group)
4344 node_cursor->cl_first = ti->cl_first;
4345 node_cursor->cl_cursor = ti->cl_cursor;
4346 *ti_ptr = node_cursor->node_group;
4347 DrawChooseTree(ti_ptr);
4349 else if (node_cursor->parent_link)
4353 *ti_ptr = node_cursor->node_parent;
4354 DrawChooseTree(ti_ptr);
4360 node_cursor->cl_first = ti->cl_first;
4361 node_cursor->cl_cursor = ti->cl_cursor;
4362 *ti_ptr = node_cursor;
4364 if (ti->type == TREE_TYPE_LEVEL_DIR)
4366 LoadLevelSetup_SeriesInfo();
4368 SaveLevelSetup_LastSeries();
4369 SaveLevelSetup_SeriesInfo();
4373 if (game_status == GAME_MODE_SETUP)
4375 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4376 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4377 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4379 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4380 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4381 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4382 execSetupGraphics();
4383 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4384 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4385 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4387 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4388 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4389 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4390 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4391 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4392 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4393 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4394 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4401 if (game_status == GAME_MODE_LEVELNR)
4403 int new_level_nr = atoi(level_number_current->identifier);
4405 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4408 SetGameStatus(GAME_MODE_MAIN);
4417 void DrawChooseLevelSet()
4419 FadeMenuSoundsAndMusic();
4421 DrawChooseTree(&leveldir_current);
4423 PlayMenuSoundsAndMusic();
4426 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4428 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4431 void DrawChooseLevelNr()
4435 FadeMenuSoundsAndMusic();
4437 if (level_number != NULL)
4439 freeTreeInfo(level_number);
4441 level_number = NULL;
4444 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4446 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4447 char identifier[32], name[32];
4450 /* temporarily load level info to get level name */
4451 LoadLevelInfoOnly(i);
4453 ti->node_top = &level_number;
4454 ti->sort_priority = 10000 + value;
4455 ti->color = (level.no_level_file ? FC_BLUE :
4456 LevelStats_getSolved(i) ? FC_GREEN :
4457 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4459 snprintf(identifier, sizeof(identifier), "%d", value);
4460 snprintf(name, sizeof(name), "%03d: %s", value,
4461 (level.no_level_file ? "(no file)" : level.name));
4463 setString(&ti->identifier, identifier);
4464 setString(&ti->name, name);
4465 setString(&ti->name_sorting, name);
4467 pushTreeInfo(&level_number, ti);
4470 /* sort level number values to start with lowest level number */
4471 sortTreeInfo(&level_number);
4473 /* set current level number to current level number */
4474 level_number_current =
4475 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4477 /* if that also fails, set current level number to first available level */
4478 if (level_number_current == NULL)
4479 level_number_current = level_number;
4481 DrawChooseTree(&level_number_current);
4483 PlayMenuSoundsAndMusic();
4486 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4488 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4491 void DrawHallOfFame(int highlight_position)
4493 int fade_mask = REDRAW_FIELD;
4495 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4496 fade_mask = REDRAW_ALL;
4499 FadeMenuSoundsAndMusic();
4501 /* (this is needed when called from GameEnd() after winning a game) */
4502 KeyboardAutoRepeatOn();
4504 /* (this is needed when called from GameEnd() after winning a game) */
4505 SetDrawDeactivationMask(REDRAW_NONE);
4506 SetDrawBackgroundMask(REDRAW_FIELD);
4508 if (highlight_position < 0)
4509 LoadScore(level_nr);
4511 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4513 FadeSetEnterScreen();
4517 /* needed if different viewport properties defined for scores */
4518 ChangeViewportPropertiesIfNeeded();
4520 PlayMenuSoundsAndMusic();
4522 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4524 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4526 DrawMaskedBorder(fade_mask);
4531 static void drawHallOfFameList(int first_entry, int highlight_position)
4535 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4538 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4539 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4540 "HighScores of Level %d", level_nr);
4542 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4544 int entry = first_entry + i;
4545 boolean active = (entry == highlight_position);
4546 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4547 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4548 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4549 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4550 int dxoff = getFontDrawOffsetX(font_nr1);
4551 int dx1 = 3 * getFontWidth(font_nr1);
4552 int dx2 = dx1 + getFontWidth(font_nr1);
4553 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4554 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4555 int sy = mSY + 64 + i * 32;
4557 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4558 DrawText(mSX + dx1, sy, ".", font_nr1);
4560 for (j = 0; j < num_dots; j++)
4561 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4563 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4564 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4566 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4569 redraw_mask |= REDRAW_FIELD;
4572 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4574 static int first_entry = 0;
4575 static int highlight_position = 0;
4576 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4578 if (button == MB_MENU_INITIALIZE)
4581 highlight_position = mx;
4582 drawHallOfFameList(first_entry, highlight_position);
4587 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4588 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4592 if (first_entry > 0)
4594 first_entry -= step;
4595 if (first_entry < 0)
4598 drawHallOfFameList(first_entry, highlight_position);
4603 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4605 first_entry += step;
4606 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4607 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4609 drawHallOfFameList(first_entry, highlight_position);
4612 else if (button == MB_MENU_LEAVE)
4614 PlaySound(SND_MENU_ITEM_SELECTING);
4616 FadeSound(SND_BACKGROUND_SCORES);
4618 SetGameStatus(GAME_MODE_MAIN);
4622 else if (button == MB_MENU_CHOICE)
4624 PlaySound(SND_MENU_ITEM_SELECTING);
4626 FadeSound(SND_BACKGROUND_SCORES);
4628 SetGameStatus(GAME_MODE_MAIN);
4633 if (game_status == GAME_MODE_SCORES)
4634 PlayMenuSoundIfLoop();
4638 /* ========================================================================= */
4639 /* setup screen functions */
4640 /* ========================================================================= */
4642 static struct TokenInfo *setup_info;
4643 static int num_setup_info; /* number of setup entries shown on screen */
4644 static int max_setup_info; /* total number of setup entries in list */
4646 static char *window_size_text;
4647 static char *scaling_type_text;
4648 static char *rendering_mode_text;
4649 static char *scroll_delay_text;
4650 static char *snapshot_mode_text;
4651 static char *game_speed_text;
4652 static char *graphics_set_name;
4653 static char *sounds_set_name;
4654 static char *music_set_name;
4655 static char *volume_simple_text;
4656 static char *volume_loops_text;
4657 static char *volume_music_text;
4658 static char *touch_controls_text;
4659 static char *move_distance_text;
4660 static char *drop_distance_text;
4661 static char *transparency_text;
4662 static char *grid_size_text[2][2];
4664 static void execSetupMain()
4666 setup_mode = SETUP_MODE_MAIN;
4671 static void execSetupGame_setGameSpeeds()
4673 if (game_speeds == NULL)
4677 for (i = 0; game_speeds_list[i].value != -1; i++)
4679 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4680 char identifier[32], name[32];
4681 int value = game_speeds_list[i].value;
4682 char *text = game_speeds_list[i].text;
4684 ti->node_top = &game_speeds;
4685 ti->sort_priority = 10000 - value;
4687 sprintf(identifier, "%d", value);
4688 sprintf(name, "%s", text);
4690 setString(&ti->identifier, identifier);
4691 setString(&ti->name, name);
4692 setString(&ti->name_sorting, name);
4693 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4695 pushTreeInfo(&game_speeds, ti);
4698 /* sort game speed values to start with slowest game speed */
4699 sortTreeInfo(&game_speeds);
4701 /* set current game speed to configured game speed value */
4702 game_speed_current =
4703 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4705 /* if that fails, set current game speed to reliable default value */
4706 if (game_speed_current == NULL)
4707 game_speed_current =
4708 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4710 /* if that also fails, set current game speed to first available speed */
4711 if (game_speed_current == NULL)
4712 game_speed_current = game_speeds;
4715 setup.game_frame_delay = atoi(game_speed_current->identifier);
4717 /* needed for displaying game speed text instead of identifier */
4718 game_speed_text = game_speed_current->name;
4721 static void execSetupGame_setScrollDelays()
4723 if (scroll_delays == NULL)
4727 for (i = 0; scroll_delays_list[i].value != -1; i++)
4729 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4730 char identifier[32], name[32];
4731 int value = scroll_delays_list[i].value;
4732 char *text = scroll_delays_list[i].text;
4734 ti->node_top = &scroll_delays;
4735 ti->sort_priority = value;
4737 sprintf(identifier, "%d", value);
4738 sprintf(name, "%s", text);
4740 setString(&ti->identifier, identifier);
4741 setString(&ti->name, name);
4742 setString(&ti->name_sorting, name);
4743 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4745 pushTreeInfo(&scroll_delays, ti);
4748 /* sort scroll delay values to start with lowest scroll delay value */
4749 sortTreeInfo(&scroll_delays);
4751 /* set current scroll delay value to configured scroll delay value */
4752 scroll_delay_current =
4753 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4755 /* if that fails, set current scroll delay to reliable default value */
4756 if (scroll_delay_current == NULL)
4757 scroll_delay_current =
4758 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4760 /* if that also fails, set current scroll delay to first available value */
4761 if (scroll_delay_current == NULL)
4762 scroll_delay_current = scroll_delays;
4765 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4767 /* needed for displaying scroll delay text instead of identifier */
4768 scroll_delay_text = scroll_delay_current->name;
4771 static void execSetupGame_setSnapshotModes()
4773 if (snapshot_modes == NULL)
4777 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4779 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4780 char identifier[32], name[32];
4781 char *value = snapshot_modes_list[i].value;
4782 char *text = snapshot_modes_list[i].text;
4784 ti->node_top = &snapshot_modes;
4785 ti->sort_priority = i;
4787 sprintf(identifier, "%s", value);
4788 sprintf(name, "%s", text);
4790 setString(&ti->identifier, identifier);
4791 setString(&ti->name, name);
4792 setString(&ti->name_sorting, name);
4793 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4795 pushTreeInfo(&snapshot_modes, ti);
4798 /* sort snapshot mode values to start with lowest snapshot mode value */
4799 sortTreeInfo(&snapshot_modes);
4801 /* set current snapshot mode value to configured snapshot mode value */
4802 snapshot_mode_current =
4803 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4805 /* if that fails, set current snapshot mode to reliable default value */
4806 if (snapshot_mode_current == NULL)
4807 snapshot_mode_current =
4808 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4810 /* if that also fails, set current snapshot mode to first available value */
4811 if (snapshot_mode_current == NULL)
4812 snapshot_mode_current = snapshot_modes;
4815 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4817 /* needed for displaying snapshot mode text instead of identifier */
4818 snapshot_mode_text = snapshot_mode_current->name;
4821 static void execSetupGame()
4823 execSetupGame_setGameSpeeds();
4824 execSetupGame_setScrollDelays();
4825 execSetupGame_setSnapshotModes();
4827 setup_mode = SETUP_MODE_GAME;
4832 static void execSetupChooseGameSpeed()
4834 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4839 static void execSetupChooseScrollDelay()
4841 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4846 static void execSetupChooseSnapshotMode()
4848 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4853 static void execSetupEditor()
4855 setup_mode = SETUP_MODE_EDITOR;
4860 static void execSetupGraphics_setWindowSizes(boolean update_list)
4862 if (window_sizes != NULL && update_list)
4864 freeTreeInfo(window_sizes);
4866 window_sizes = NULL;
4869 if (window_sizes == NULL)
4871 boolean current_window_size_found = FALSE;
4874 for (i = 0; window_sizes_list[i].value != -1; i++)
4876 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4877 char identifier[32], name[32];
4878 int value = window_sizes_list[i].value;
4879 char *text = window_sizes_list[i].text;
4881 ti->node_top = &window_sizes;
4882 ti->sort_priority = value;
4884 sprintf(identifier, "%d", value);
4885 sprintf(name, "%s", text);
4887 setString(&ti->identifier, identifier);
4888 setString(&ti->name, name);
4889 setString(&ti->name_sorting, name);
4890 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4892 pushTreeInfo(&window_sizes, ti);
4894 if (value == setup.window_scaling_percent)
4895 current_window_size_found = TRUE;
4898 if (!current_window_size_found)
4900 // add entry for non-preset window scaling value
4902 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4903 char identifier[32], name[32];
4904 int value = setup.window_scaling_percent;
4906 ti->node_top = &window_sizes;
4907 ti->sort_priority = value;
4909 sprintf(identifier, "%d", value);
4910 sprintf(name, "%d %% (Current)", value);
4912 setString(&ti->identifier, identifier);
4913 setString(&ti->name, name);
4914 setString(&ti->name_sorting, name);
4915 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4917 pushTreeInfo(&window_sizes, ti);
4920 /* sort window size values to start with lowest window size value */
4921 sortTreeInfo(&window_sizes);
4923 /* set current window size value to configured window size value */
4924 window_size_current =
4925 getTreeInfoFromIdentifier(window_sizes,
4926 i_to_a(setup.window_scaling_percent));
4928 /* if that fails, set current window size to reliable default value */
4929 if (window_size_current == NULL)
4930 window_size_current =
4931 getTreeInfoFromIdentifier(window_sizes,
4932 i_to_a(STD_WINDOW_SCALING_PERCENT));
4934 /* if that also fails, set current window size to first available value */
4935 if (window_size_current == NULL)
4936 window_size_current = window_sizes;
4939 setup.window_scaling_percent = atoi(window_size_current->identifier);
4941 /* needed for displaying window size text instead of identifier */
4942 window_size_text = window_size_current->name;
4945 static void execSetupGraphics_setScalingTypes()
4947 if (scaling_types == NULL)
4951 for (i = 0; scaling_types_list[i].value != NULL; i++)
4953 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4954 char identifier[32], name[32];
4955 char *value = scaling_types_list[i].value;
4956 char *text = scaling_types_list[i].text;
4958 ti->node_top = &scaling_types;
4959 ti->sort_priority = i;
4961 sprintf(identifier, "%s", value);
4962 sprintf(name, "%s", text);
4964 setString(&ti->identifier, identifier);
4965 setString(&ti->name, name);
4966 setString(&ti->name_sorting, name);
4967 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4969 pushTreeInfo(&scaling_types, ti);
4972 /* sort scaling type values to start with lowest scaling type value */
4973 sortTreeInfo(&scaling_types);
4975 /* set current scaling type value to configured scaling type value */
4976 scaling_type_current =
4977 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4979 /* if that fails, set current scaling type to reliable default value */
4980 if (scaling_type_current == NULL)
4981 scaling_type_current =
4982 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4984 /* if that also fails, set current scaling type to first available value */
4985 if (scaling_type_current == NULL)
4986 scaling_type_current = scaling_types;
4989 setup.window_scaling_quality = scaling_type_current->identifier;
4991 /* needed for displaying scaling type text instead of identifier */
4992 scaling_type_text = scaling_type_current->name;
4995 static void execSetupGraphics_setRenderingModes()
4997 if (rendering_modes == NULL)
5001 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5003 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5004 char identifier[32], name[32];
5005 char *value = rendering_modes_list[i].value;
5006 char *text = rendering_modes_list[i].text;
5008 ti->node_top = &rendering_modes;
5009 ti->sort_priority = i;
5011 sprintf(identifier, "%s", value);
5012 sprintf(name, "%s", text);
5014 setString(&ti->identifier, identifier);
5015 setString(&ti->name, name);
5016 setString(&ti->name_sorting, name);
5017 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5019 pushTreeInfo(&rendering_modes, ti);
5022 /* sort rendering mode values to start with lowest rendering mode value */
5023 sortTreeInfo(&rendering_modes);
5025 /* set current rendering mode value to configured rendering mode value */
5026 rendering_mode_current =
5027 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5029 /* if that fails, set current rendering mode to reliable default value */
5030 if (rendering_mode_current == NULL)
5031 rendering_mode_current =
5032 getTreeInfoFromIdentifier(rendering_modes,
5033 STR_SPECIAL_RENDERING_DEFAULT);
5035 /* if that also fails, set current rendering mode to first available one */
5036 if (rendering_mode_current == NULL)
5037 rendering_mode_current = rendering_modes;
5040 setup.screen_rendering_mode = rendering_mode_current->identifier;
5042 /* needed for displaying rendering mode text instead of identifier */
5043 rendering_mode_text = rendering_mode_current->name;
5046 static void execSetupGraphics()
5048 // update "setup.window_scaling_percent" from list selection
5049 // (in this case, window scaling was changed on setup screen)
5050 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5051 execSetupGraphics_setWindowSizes(FALSE);
5053 // update list selection from "setup.window_scaling_percent"
5054 // (window scaling may have changed by resizing the window)
5055 execSetupGraphics_setWindowSizes(TRUE);
5057 execSetupGraphics_setScalingTypes();
5058 execSetupGraphics_setRenderingModes();
5060 setup_mode = SETUP_MODE_GRAPHICS;
5064 #if defined(TARGET_SDL2)
5065 // window scaling may have changed at this point
5066 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5068 // window scaling quality may have changed at this point
5069 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5070 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5072 // screen rendering mode may have changed at this point
5073 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5077 static void execSetupChooseWindowSize()
5079 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5084 static void execSetupChooseScalingType()
5086 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5091 static void execSetupChooseRenderingMode()
5093 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5098 static void execSetupChooseVolumeSimple()
5100 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5105 static void execSetupChooseVolumeLoops()
5107 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5112 static void execSetupChooseVolumeMusic()
5114 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5119 static void execSetupSound()
5121 if (volumes_simple == NULL)
5123 boolean current_volume_simple_found = FALSE;
5126 for (i = 0; volumes_list[i].value != -1; i++)
5128 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5129 char identifier[32], name[32];
5130 int value = volumes_list[i].value;
5131 char *text = volumes_list[i].text;
5133 ti->node_top = &volumes_simple;
5134 ti->sort_priority = value;
5136 sprintf(identifier, "%d", value);
5137 sprintf(name, "%s", text);
5139 setString(&ti->identifier, identifier);
5140 setString(&ti->name, name);
5141 setString(&ti->name_sorting, name);
5142 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5144 pushTreeInfo(&volumes_simple, ti);
5146 if (value == setup.volume_simple)
5147 current_volume_simple_found = TRUE;
5150 if (!current_volume_simple_found)
5152 // add entry for non-preset volume value
5154 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5155 char identifier[32], name[32];
5156 int value = setup.volume_simple;
5158 ti->node_top = &volumes_simple;
5159 ti->sort_priority = value;
5161 sprintf(identifier, "%d", value);
5162 sprintf(name, "%d %% (Current)", value);
5164 setString(&ti->identifier, identifier);
5165 setString(&ti->name, name);
5166 setString(&ti->name_sorting, name);
5167 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5169 pushTreeInfo(&volumes_simple, ti);
5172 /* sort volume values to start with lowest volume value */
5173 sortTreeInfo(&volumes_simple);
5175 /* set current volume value to configured volume value */
5176 volume_simple_current =
5177 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5179 /* if that fails, set current volume to reliable default value */
5180 if (volume_simple_current == NULL)
5181 volume_simple_current =
5182 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5184 /* if that also fails, set current volume to first available value */
5185 if (volume_simple_current == NULL)
5186 volume_simple_current = volumes_simple;
5189 if (volumes_loops == NULL)
5191 boolean current_volume_loops_found = FALSE;
5194 for (i = 0; volumes_list[i].value != -1; i++)
5196 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5197 char identifier[32], name[32];
5198 int value = volumes_list[i].value;
5199 char *text = volumes_list[i].text;
5201 ti->node_top = &volumes_loops;
5202 ti->sort_priority = value;
5204 sprintf(identifier, "%d", value);
5205 sprintf(name, "%s", text);
5207 setString(&ti->identifier, identifier);
5208 setString(&ti->name, name);
5209 setString(&ti->name_sorting, name);
5210 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5212 pushTreeInfo(&volumes_loops, ti);
5214 if (value == setup.volume_loops)
5215 current_volume_loops_found = TRUE;
5218 if (!current_volume_loops_found)
5220 // add entry for non-preset volume value
5222 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5223 char identifier[32], name[32];
5224 int value = setup.volume_loops;
5226 ti->node_top = &volumes_loops;
5227 ti->sort_priority = value;
5229 sprintf(identifier, "%d", value);
5230 sprintf(name, "%d %% (Current)", value);
5232 setString(&ti->identifier, identifier);
5233 setString(&ti->name, name);
5234 setString(&ti->name_sorting, name);
5235 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5237 pushTreeInfo(&volumes_loops, ti);
5240 /* sort volume values to start with lowest volume value */
5241 sortTreeInfo(&volumes_loops);
5243 /* set current volume value to configured volume value */
5244 volume_loops_current =
5245 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5247 /* if that fails, set current volume to reliable default value */
5248 if (volume_loops_current == NULL)
5249 volume_loops_current =
5250 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5252 /* if that also fails, set current volume to first available value */
5253 if (volume_loops_current == NULL)
5254 volume_loops_current = volumes_loops;
5257 if (volumes_music == NULL)
5259 boolean current_volume_music_found = FALSE;
5262 for (i = 0; volumes_list[i].value != -1; i++)
5264 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5265 char identifier[32], name[32];
5266 int value = volumes_list[i].value;
5267 char *text = volumes_list[i].text;
5269 ti->node_top = &volumes_music;
5270 ti->sort_priority = value;
5272 sprintf(identifier, "%d", value);
5273 sprintf(name, "%s", text);
5275 setString(&ti->identifier, identifier);
5276 setString(&ti->name, name);
5277 setString(&ti->name_sorting, name);
5278 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5280 pushTreeInfo(&volumes_music, ti);
5282 if (value == setup.volume_music)
5283 current_volume_music_found = TRUE;
5286 if (!current_volume_music_found)
5288 // add entry for non-preset volume value
5290 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5291 char identifier[32], name[32];
5292 int value = setup.volume_music;
5294 ti->node_top = &volumes_music;
5295 ti->sort_priority = value;
5297 sprintf(identifier, "%d", value);
5298 sprintf(name, "%d %% (Current)", value);
5300 setString(&ti->identifier, identifier);
5301 setString(&ti->name, name);
5302 setString(&ti->name_sorting, name);
5303 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5305 pushTreeInfo(&volumes_music, ti);
5308 /* sort volume values to start with lowest volume value */
5309 sortTreeInfo(&volumes_music);
5311 /* set current volume value to configured volume value */
5312 volume_music_current =
5313 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5315 /* if that fails, set current volume to reliable default value */
5316 if (volume_music_current == NULL)
5317 volume_music_current =
5318 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5320 /* if that also fails, set current volume to first available value */
5321 if (volume_music_current == NULL)
5322 volume_music_current = volumes_music;
5325 setup.volume_simple = atoi(volume_simple_current->identifier);
5326 setup.volume_loops = atoi(volume_loops_current->identifier);
5327 setup.volume_music = atoi(volume_music_current->identifier);
5329 /* needed for displaying volume text instead of identifier */
5330 volume_simple_text = volume_simple_current->name;
5331 volume_loops_text = volume_loops_current->name;
5332 volume_music_text = volume_music_current->name;
5334 setup_mode = SETUP_MODE_SOUND;
5339 static void execSetupChooseTouchControls()
5341 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5346 static void execSetupChooseMoveDistance()
5348 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5353 static void execSetupChooseDropDistance()
5355 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5360 static void execSetupChooseTransparency()
5362 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5367 static void execSetupChooseGridXSize_0()
5369 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5374 static void execSetupChooseGridYSize_0()
5376 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5381 static void execSetupChooseGridXSize_1()
5383 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5388 static void execSetupChooseGridYSize_1()
5390 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5395 static void execSetupConfigureVirtualButtons()
5397 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5399 ConfigureVirtualButtons();
5401 setup_mode = SETUP_MODE_TOUCH;
5406 static void execSetupTouch()
5410 if (touch_controls == NULL)
5412 for (i = 0; touch_controls_list[i].value != NULL; i++)
5414 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5415 char identifier[32], name[32];
5416 char *value = touch_controls_list[i].value;
5417 char *text = touch_controls_list[i].text;
5419 ti->node_top = &touch_controls;
5420 ti->sort_priority = i;
5422 sprintf(identifier, "%s", value);
5423 sprintf(name, "%s", text);
5425 setString(&ti->identifier, identifier);
5426 setString(&ti->name, name);
5427 setString(&ti->name_sorting, name);
5428 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5430 pushTreeInfo(&touch_controls, ti);
5433 /* sort touch control values to start with lowest touch control value */
5434 sortTreeInfo(&touch_controls);
5436 /* set current touch control value to configured touch control value */
5437 touch_control_current =
5438 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5440 /* if that fails, set current touch control to reliable default value */
5441 if (touch_control_current == NULL)
5442 touch_control_current =
5443 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5445 /* if that also fails, set current touch control to first available value */
5446 if (touch_control_current == NULL)
5447 touch_control_current = touch_controls;
5450 if (move_distances == NULL)
5452 for (i = 0; distances_list[i].value != -1; i++)
5454 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5455 char identifier[32], name[32];
5456 int value = distances_list[i].value;
5457 char *text = distances_list[i].text;
5459 ti->node_top = &move_distances;
5460 ti->sort_priority = value;
5462 sprintf(identifier, "%d", value);
5463 sprintf(name, "%s", text);
5465 setString(&ti->identifier, identifier);
5466 setString(&ti->name, name);
5467 setString(&ti->name_sorting, name);
5468 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5470 pushTreeInfo(&move_distances, ti);
5473 /* sort distance values to start with lowest distance value */
5474 sortTreeInfo(&move_distances);
5476 /* set current distance value to configured distance value */
5477 move_distance_current =
5478 getTreeInfoFromIdentifier(move_distances,
5479 i_to_a(setup.touch.move_distance));
5481 /* if that fails, set current distance to reliable default value */
5482 if (move_distance_current == NULL)
5483 move_distance_current =
5484 getTreeInfoFromIdentifier(move_distances,
5485 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5487 /* if that also fails, set current distance to first available value */
5488 if (move_distance_current == NULL)
5489 move_distance_current = move_distances;
5492 if (drop_distances == NULL)
5494 for (i = 0; distances_list[i].value != -1; i++)
5496 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5497 char identifier[32], name[32];
5498 int value = distances_list[i].value;
5499 char *text = distances_list[i].text;
5501 ti->node_top = &drop_distances;
5502 ti->sort_priority = value;
5504 sprintf(identifier, "%d", value);
5505 sprintf(name, "%s", text);
5507 setString(&ti->identifier, identifier);
5508 setString(&ti->name, name);
5509 setString(&ti->name_sorting, name);
5510 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5512 pushTreeInfo(&drop_distances, ti);
5515 /* sort distance values to start with lowest distance value */
5516 sortTreeInfo(&drop_distances);
5518 /* set current distance value to configured distance value */
5519 drop_distance_current =
5520 getTreeInfoFromIdentifier(drop_distances,
5521 i_to_a(setup.touch.drop_distance));
5523 /* if that fails, set current distance to reliable default value */
5524 if (drop_distance_current == NULL)
5525 drop_distance_current =
5526 getTreeInfoFromIdentifier(drop_distances,
5527 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5529 /* if that also fails, set current distance to first available value */
5530 if (drop_distance_current == NULL)
5531 drop_distance_current = drop_distances;
5534 if (transparencies == NULL)
5536 for (i = 0; transparencies_list[i].value != -1; i++)
5538 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5539 char identifier[32], name[32];
5540 int value = transparencies_list[i].value;
5541 char *text = transparencies_list[i].text;
5543 ti->node_top = &transparencies;
5544 ti->sort_priority = value;
5546 sprintf(identifier, "%d", value);
5547 sprintf(name, "%s", text);
5549 setString(&ti->identifier, identifier);
5550 setString(&ti->name, name);
5551 setString(&ti->name_sorting, name);
5552 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5554 pushTreeInfo(&transparencies, ti);
5557 /* sort transparency values to start with lowest transparency value */
5558 sortTreeInfo(&transparencies);
5560 /* set current transparency value to configured transparency value */
5561 transparency_current =
5562 getTreeInfoFromIdentifier(transparencies,
5563 i_to_a(setup.touch.transparency));
5565 /* if that fails, set current transparency to reliable default value */
5566 if (transparency_current == NULL)
5567 transparency_current =
5568 getTreeInfoFromIdentifier(transparencies,
5569 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5571 /* if that also fails, set current transparency to first available value */
5572 if (transparency_current == NULL)
5573 transparency_current = transparencies;
5576 for (i = 0; i < 2; i++)
5578 for (j = 0; j < 2; j++)
5580 if (grid_sizes[i][j] == NULL)
5582 for (k = 0; grid_sizes_list[k].value != -1; k++)
5584 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5585 char identifier[32], name[32];
5586 int value = grid_sizes_list[k].value;
5587 char *text = grid_sizes_list[k].text;
5589 ti->node_top = &grid_sizes[i][j];
5590 ti->sort_priority = value;
5592 sprintf(identifier, "%d", value);
5593 sprintf(name, "%s", text);
5595 setString(&ti->identifier, identifier);
5596 setString(&ti->name, name);
5597 setString(&ti->name_sorting, name);
5598 setString(&ti->infotext,
5601 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5602 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5604 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5605 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5607 pushTreeInfo(&grid_sizes[i][j], ti);
5610 /* sort grid size values to start with lowest grid size value */
5611 sortTreeInfo(&grid_sizes[i][j]);
5613 /* set current grid size value to configured grid size value */
5614 grid_size_current[i][j] =
5615 getTreeInfoFromIdentifier(grid_sizes[i][j],
5617 setup.touch.grid_xsize[i] :
5618 setup.touch.grid_ysize[i]));
5620 /* if that fails, set current grid size to reliable default value */
5621 if (grid_size_current[i][j] == NULL)
5622 grid_size_current[i][j] =
5623 getTreeInfoFromIdentifier(grid_sizes[i][j],
5625 DEFAULT_GRID_XSIZE(i) :
5626 DEFAULT_GRID_YSIZE(i)));
5628 /* if that also fails, set current grid size to first available value */
5629 if (grid_size_current[i][j] == NULL)
5630 grid_size_current[i][j] = grid_sizes[i][j];
5635 setup.touch.control_type = touch_control_current->identifier;
5636 setup.touch.move_distance = atoi(move_distance_current->identifier);
5637 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5638 setup.touch.transparency = atoi(transparency_current->identifier);
5640 for (i = 0; i < 2; i++)
5642 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5643 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5645 if (i == GRID_ACTIVE_NR())
5647 overlay.grid_xsize = setup.touch.grid_xsize[i];
5648 overlay.grid_ysize = setup.touch.grid_ysize[i];
5652 /* needed for displaying value text instead of identifier */
5653 touch_controls_text = touch_control_current->name;
5654 move_distance_text = move_distance_current->name;
5655 drop_distance_text = drop_distance_current->name;
5656 transparency_text = transparency_current->name;
5658 for (i = 0; i < 2; i++)
5659 for (j = 0; j < 2; j++)
5660 grid_size_text[i][j] = grid_size_current[i][j]->name;
5662 setup_mode = SETUP_MODE_TOUCH;
5667 static void execSetupArtwork()
5670 printf("::: '%s', '%s', '%s'\n",
5671 artwork.gfx_current->subdir,
5672 artwork.gfx_current->fullpath,
5673 artwork.gfx_current->basepath);
5676 setup.graphics_set = artwork.gfx_current->identifier;
5677 setup.sounds_set = artwork.snd_current->identifier;
5678 setup.music_set = artwork.mus_current->identifier;
5680 /* needed if last screen (setup choice) changed graphics, sounds or music */
5681 ReloadCustomArtwork(0);
5683 /* needed for displaying artwork name instead of artwork identifier */
5684 graphics_set_name = artwork.gfx_current->name;
5685 sounds_set_name = artwork.snd_current->name;
5686 music_set_name = artwork.mus_current->name;
5688 setup_mode = SETUP_MODE_ARTWORK;
5693 static void execSetupChooseGraphics()
5695 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5700 static void execSetupChooseSounds()
5702 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5707 static void execSetupChooseMusic()
5709 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5714 static void execSetupInput()
5716 setup_mode = SETUP_MODE_INPUT;
5721 static void execSetupShortcuts()
5723 setup_mode = SETUP_MODE_SHORTCUTS;
5728 static void execSetupShortcuts1()
5730 setup_mode = SETUP_MODE_SHORTCUTS_1;
5735 static void execSetupShortcuts2()
5737 setup_mode = SETUP_MODE_SHORTCUTS_2;
5742 static void execSetupShortcuts3()
5744 setup_mode = SETUP_MODE_SHORTCUTS_3;
5749 static void execSetupShortcuts4()
5751 setup_mode = SETUP_MODE_SHORTCUTS_4;
5756 static void execSetupShortcuts5()
5758 setup_mode = SETUP_MODE_SHORTCUTS_5;
5763 static void execExitSetup()
5765 SetGameStatus(GAME_MODE_MAIN);
5770 static void execSaveAndExitSetup()
5779 void *related_value;
5780 } hide_related_entry_list[] =
5782 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5783 { &setup.game_frame_delay, &game_speed_text },
5785 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5786 { &setup.scroll_delay_value, &scroll_delay_text },
5788 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5789 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5791 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5792 { &setup.window_scaling_percent, &window_size_text },
5794 { &setup.window_scaling_quality, execSetupChooseScalingType },
5795 { &setup.window_scaling_quality, &scaling_type_text },
5797 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5798 { &setup.screen_rendering_mode, &rendering_mode_text },
5800 { &setup.graphics_set, execSetupChooseGraphics },
5801 { &setup.graphics_set, &graphics_set_name },
5803 { &setup.sounds_set, execSetupChooseSounds },
5804 { &setup.sounds_set, &sounds_set_name },
5806 { &setup.music_set, execSetupChooseMusic },
5807 { &setup.music_set, &music_set_name },
5809 { &setup.volume_simple, execSetupChooseVolumeSimple },
5810 { &setup.volume_simple, &volume_simple_text },
5812 { &setup.volume_loops, execSetupChooseVolumeLoops },
5813 { &setup.volume_loops, &volume_loops_text },
5815 { &setup.volume_music, execSetupChooseVolumeMusic },
5816 { &setup.volume_music, &volume_music_text },
5818 { &setup.touch.control_type, execSetupChooseTouchControls },
5819 { &setup.touch.control_type, &touch_controls_text },
5821 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5822 { &setup.touch.move_distance, &move_distance_text },
5824 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5825 { &setup.touch.drop_distance, &drop_distance_text },
5827 { &setup.touch.transparency, execSetupChooseTransparency },
5828 { &setup.touch.transparency, &transparency_text },
5830 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5831 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5833 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5834 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5836 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5837 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5839 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5840 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5845 void setHideRelatedSetupEntries()
5849 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5850 if (hideSetupEntry(hide_related_entry_list[i].value))
5851 setHideSetupEntry(hide_related_entry_list[i].related_value);
5854 static struct TokenInfo setup_info_main[] =
5856 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5857 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5858 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5859 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5860 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5861 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5862 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5863 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5864 { TYPE_EMPTY, NULL, "" },
5865 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5866 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5871 static struct TokenInfo setup_info_game[] =
5873 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5874 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5875 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5876 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5877 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5878 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5879 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5880 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5881 { TYPE_STRING, &game_speed_text, "" },
5883 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5884 { TYPE_STRING, &scroll_delay_text, "" },
5886 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5887 { TYPE_STRING, &snapshot_mode_text, "" },
5888 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5889 { TYPE_EMPTY, NULL, "" },
5890 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5895 static struct TokenInfo setup_info_editor[] =
5898 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5899 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5900 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5901 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5902 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5903 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5904 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5905 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5906 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5907 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5909 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5910 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5912 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5914 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5915 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5916 { TYPE_EMPTY, NULL, "" },
5918 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5919 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5920 { TYPE_EMPTY, NULL, "" },
5922 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5923 { TYPE_EMPTY, NULL, "" },
5924 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5929 static struct TokenInfo setup_info_graphics[] =
5931 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5932 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5933 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5934 { TYPE_STRING, &window_size_text, "" },
5935 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5936 { TYPE_STRING, &scaling_type_text, "" },
5937 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5938 { TYPE_STRING, &rendering_mode_text, "" },
5941 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5942 { TYPE_STRING, &scroll_delay_text, "" },
5944 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5945 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5946 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5947 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5948 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5949 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5950 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5951 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5952 { TYPE_EMPTY, NULL, "" },
5953 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5958 static struct TokenInfo setup_info_sound[] =
5960 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5961 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5962 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5963 { TYPE_EMPTY, NULL, "" },
5964 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5965 { TYPE_STRING, &volume_simple_text, "" },
5966 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5967 { TYPE_STRING, &volume_loops_text, "" },
5968 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5969 { TYPE_STRING, &volume_music_text, "" },
5970 { TYPE_EMPTY, NULL, "" },
5971 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5976 static struct TokenInfo setup_info_artwork[] =
5978 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5979 { TYPE_STRING, &graphics_set_name, "" },
5980 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5981 { TYPE_STRING, &sounds_set_name, "" },
5982 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5983 { TYPE_STRING, &music_set_name, "" },
5984 { TYPE_EMPTY, NULL, "" },
5985 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5986 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5987 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5988 { TYPE_EMPTY, NULL, "" },
5989 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5994 static struct TokenInfo setup_info_input[] =
5996 { TYPE_SWITCH, NULL, "Player:" },
5997 { TYPE_SWITCH, NULL, "Device:" },
5998 { TYPE_SWITCH, NULL, "" },
5999 { TYPE_SKIPPABLE, NULL, "" },
6000 { TYPE_EMPTY, NULL, "" },
6001 { TYPE_EMPTY, NULL, "" },
6002 { TYPE_EMPTY, NULL, "" },
6003 { TYPE_EMPTY, NULL, "" },
6004 { TYPE_EMPTY, NULL, "" },
6005 { TYPE_EMPTY, NULL, "" },
6006 { TYPE_EMPTY, NULL, "" },
6007 { TYPE_EMPTY, NULL, "" },
6008 { TYPE_SKIPPABLE, NULL, "" },
6009 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6014 static struct TokenInfo setup_info_touch[] =
6016 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6017 { TYPE_STRING, &touch_controls_text, "" },
6018 { TYPE_EMPTY, NULL, "" },
6019 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6024 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6026 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6027 { TYPE_STRING, &touch_controls_text, "" },
6028 { TYPE_EMPTY, NULL, "" },
6029 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6030 { TYPE_STRING, &grid_size_text[0][0], "" },
6031 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6032 { TYPE_STRING, &grid_size_text[0][1], "" },
6033 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6034 { TYPE_STRING, &transparency_text, "" },
6035 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6036 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6037 { TYPE_EMPTY, NULL, "" },
6038 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6039 { TYPE_EMPTY, NULL, "" },
6040 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6045 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6047 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6048 { TYPE_STRING, &touch_controls_text, "" },
6049 { TYPE_EMPTY, NULL, "" },
6050 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6051 { TYPE_STRING, &grid_size_text[1][0], "" },
6052 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6053 { TYPE_STRING, &grid_size_text[1][1], "" },
6054 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6055 { TYPE_STRING, &transparency_text, "" },
6056 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6057 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6058 { TYPE_EMPTY, NULL, "" },
6059 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6060 { TYPE_EMPTY, NULL, "" },
6061 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6066 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6068 setup_info_touch_virtual_buttons_0,
6069 setup_info_touch_virtual_buttons_1
6072 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6074 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6075 { TYPE_STRING, &touch_controls_text, "" },
6076 { TYPE_EMPTY, NULL, "" },
6077 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6078 { TYPE_STRING, &move_distance_text, "" },
6079 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6080 { TYPE_STRING, &drop_distance_text, "" },
6081 { TYPE_EMPTY, NULL, "" },
6082 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6087 static struct TokenInfo setup_info_shortcuts[] =
6089 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6090 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6091 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6092 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6093 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6094 { TYPE_EMPTY, NULL, "" },
6095 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6100 static struct TokenInfo setup_info_shortcuts_1[] =
6102 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6103 { TYPE_KEY, &setup.shortcut.save_game, "" },
6104 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6105 { TYPE_KEY, &setup.shortcut.load_game, "" },
6106 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6107 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6108 { TYPE_EMPTY, NULL, "" },
6109 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6110 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6111 { TYPE_EMPTY, NULL, "" },
6112 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6117 static struct TokenInfo setup_info_shortcuts_2[] =
6119 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6120 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6121 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6122 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6123 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6124 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6125 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6126 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6127 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6128 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6129 { TYPE_EMPTY, NULL, "" },
6130 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6135 static struct TokenInfo setup_info_shortcuts_3[] =
6137 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6138 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6139 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6140 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6141 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6142 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6143 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6144 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6145 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6146 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6147 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6148 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6149 { TYPE_EMPTY, NULL, "" },
6150 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6155 static struct TokenInfo setup_info_shortcuts_4[] =
6157 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6158 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6159 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6160 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6161 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6162 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6163 { TYPE_EMPTY, NULL, "" },
6164 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6169 static struct TokenInfo setup_info_shortcuts_5[] =
6171 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6172 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6173 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6174 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6175 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6176 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6177 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6178 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6179 { TYPE_EMPTY, NULL, "" },
6180 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6185 static Key getSetupKey()
6187 Key key = KSYM_UNDEFINED;
6188 boolean got_key_event = FALSE;
6190 while (!got_key_event)
6194 if (NextValidEvent(&event))
6198 case EVENT_KEYPRESS:
6200 key = GetEventKey((KeyEvent *)&event, TRUE);
6202 /* press 'Escape' or 'Enter' to keep the existing key binding */
6203 if (key == KSYM_Escape || key == KSYM_Return)
6204 key = KSYM_UNDEFINED; /* keep old value */
6206 got_key_event = TRUE;
6210 case EVENT_KEYRELEASE:
6211 key_joystick_mapping = 0;
6215 HandleOtherEvents(&event);
6226 static int getSetupValueFont(int type, void *value)
6228 if (type & TYPE_GHOSTED)
6229 return FONT_OPTION_OFF;
6230 else if (type & TYPE_KEY)
6231 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6232 else if (type & TYPE_STRING)
6233 return FONT_VALUE_2;
6234 else if (type & TYPE_ECS_AGA)
6235 return FONT_VALUE_1;
6236 else if (type & TYPE_BOOLEAN_STYLE)
6237 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6238 else if (type & TYPE_YES_NO_AUTO)
6239 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6240 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6242 return FONT_VALUE_1;
6245 static int getSetupValueFontNarrow(int type, int font_nr)
6247 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6248 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6249 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6253 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6255 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6256 struct TokenInfo *si = &setup_info[si_pos];
6257 boolean font_draw_xoffset_modified = FALSE;
6258 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6259 int font_draw_xoffset_old = -1;
6260 int xoffset = (scrollbar_needed ? -1 : 0);
6261 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6262 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6263 int xpos = menu_screen_value_xpos;
6264 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6265 int startx = mSX + xpos * 32;
6266 int starty = mSY + ypos * 32;
6267 int font_nr, font_nr_default, font_width_default;
6268 int type = si->type;
6269 void *value = si->value;
6270 char *value_string = getSetupValue(type, value);
6273 if (value_string == NULL)
6276 if (type & TYPE_KEY)
6278 xpos = MENU_SCREEN_START_XPOS;
6280 if (type & TYPE_QUERY)
6281 value_string = "<press key>";
6283 else if (type & TYPE_STRING)
6285 int max_value_len = (SCR_FIELDX - 2) * 2;
6287 xpos = MENU_SCREEN_START_XPOS;
6289 if (strlen(value_string) > max_value_len)
6290 value_string[max_value_len] = '\0';
6292 else if (type & TYPE_YES_NO_AUTO)
6294 xpos = menu_screen_value_xpos - 1;
6297 startx = mSX + xpos * 32;
6298 starty = mSY + ypos * 32;
6299 font_nr_default = getSetupValueFont(type, value);
6300 font_width_default = getFontWidth(font_nr_default);
6302 font_nr = font_nr_default;
6304 // special check if right-side setup values moved left due to scrollbar
6305 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6307 int max_menu_text_length = 26; // maximum text length for classic menu
6308 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6309 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6310 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6311 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6312 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6314 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6317 startx = mSX + xpos * 32;
6319 font_nr = getSetupValueFontNarrow(type, font_nr);
6323 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6324 if (setup_mode != SETUP_MODE_INPUT)
6326 int max_menu_text_length_big = (menu_screen_value_xpos -
6327 MENU_SCREEN_START_XPOS);
6328 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6329 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6330 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6331 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6332 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6333 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6334 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6335 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6336 boolean correct_font_draw_xoffset = FALSE;
6338 if (xpos == MENU_SCREEN_START_XPOS &&
6339 startx + font1_xoffset < text_startx + text_font_xoffset)
6340 correct_font_draw_xoffset = TRUE;
6342 if (xpos == menu_screen_value_xpos &&
6343 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6344 correct_font_draw_xoffset = TRUE;
6346 /* check if setup value would overlap with setup text when printed */
6347 /* (this can happen for extreme/wrong values for font draw offset) */
6348 if (correct_font_draw_xoffset)
6350 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6351 font_draw_xoffset_modified = TRUE;
6353 if (type & TYPE_KEY)
6354 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6355 else if (!(type & TYPE_STRING))
6356 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6357 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6361 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6362 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6364 DrawText(startx, starty, value_string, font_nr);
6366 if (font_draw_xoffset_modified)
6367 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6370 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6372 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6373 struct TokenInfo *si = &setup_info[si_pos];
6375 if (si->type & TYPE_BOOLEAN_STYLE)
6377 *(boolean *)si->value ^= TRUE;
6379 else if (si->type & TYPE_YES_NO_AUTO)
6383 (*(int *)si->value == AUTO ? TRUE :
6384 *(int *)si->value == TRUE ? FALSE : AUTO) :
6385 (*(int *)si->value == TRUE ? AUTO :
6386 *(int *)si->value == AUTO ? FALSE : TRUE));
6388 else if (si->type & TYPE_KEY)
6392 si->type |= TYPE_QUERY;
6393 drawSetupValue(screen_pos, setup_info_pos_raw);
6394 si->type &= ~TYPE_QUERY;
6396 key = getSetupKey();
6397 if (key != KSYM_UNDEFINED)
6398 *(Key *)si->value = key;
6401 drawSetupValue(screen_pos, setup_info_pos_raw);
6403 // fullscreen state may have changed at this point
6404 if (si->value == &setup.fullscreen)
6405 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6408 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6410 static struct TokenInfo *setup_info_final = NULL;
6415 /* determine maximum list size of target list */
6416 while (setup_info_orig[list_size++].type != 0);
6418 /* free, allocate and clear memory for target list */
6419 checked_free(setup_info_final);
6420 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6422 /* copy setup info list without setup entries marked as hidden */
6423 for (i = 0; setup_info_orig[i].type != 0; i++)
6425 /* skip setup entries configured to be hidden */
6426 if (hideSetupEntry(setup_info_orig[i].value))
6429 /* skip skippable setup entries if screen is lower than usual */
6430 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6431 setup_info_orig[i].type == TYPE_SKIPPABLE)
6434 setup_info_final[list_pos++] = setup_info_orig[i];
6437 return setup_info_final;
6440 static void DrawSetupScreen_Generic()
6442 int fade_mask = REDRAW_FIELD;
6443 boolean redraw_all = FALSE;
6444 char *title_string = NULL;
6447 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6448 fade_mask = REDRAW_ALL;
6451 FadeMenuSoundsAndMusic();
6453 FreeScreenGadgets();
6454 CreateScreenGadgets();
6456 if (redraw_mask & REDRAW_ALL)
6461 /* needed if different viewport properties defined for setup screen */
6462 ChangeViewportPropertiesIfNeeded();
6464 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6468 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6470 if (setup_mode == SETUP_MODE_MAIN)
6472 setup_info = setup_info_main;
6473 title_string = STR_SETUP_MAIN;
6475 else if (setup_mode == SETUP_MODE_GAME)
6477 setup_info = setup_info_game;
6478 title_string = STR_SETUP_GAME;
6480 else if (setup_mode == SETUP_MODE_EDITOR)
6482 setup_info = setup_info_editor;
6483 title_string = STR_SETUP_EDITOR;
6485 else if (setup_mode == SETUP_MODE_GRAPHICS)
6487 setup_info = setup_info_graphics;
6488 title_string = STR_SETUP_GRAPHICS;
6490 else if (setup_mode == SETUP_MODE_SOUND)
6492 setup_info = setup_info_sound;
6493 title_string = STR_SETUP_SOUND;
6495 else if (setup_mode == SETUP_MODE_ARTWORK)
6497 setup_info = setup_info_artwork;
6498 title_string = STR_SETUP_ARTWORK;
6500 else if (setup_mode == SETUP_MODE_TOUCH)
6502 setup_info = setup_info_touch;
6503 title_string = STR_SETUP_TOUCH;
6505 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6506 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6507 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6508 setup_info = setup_info_touch_wipe_gestures;
6510 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6512 setup_info = setup_info_shortcuts;
6513 title_string = STR_SETUP_SHORTCUTS;
6515 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6517 setup_info = setup_info_shortcuts_1;
6518 title_string = STR_SETUP_SHORTCUTS;
6520 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6522 setup_info = setup_info_shortcuts_2;
6523 title_string = STR_SETUP_SHORTCUTS;
6525 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6527 setup_info = setup_info_shortcuts_3;
6528 title_string = STR_SETUP_SHORTCUTS;
6530 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6532 setup_info = setup_info_shortcuts_4;
6533 title_string = STR_SETUP_SHORTCUTS;
6535 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6537 setup_info = setup_info_shortcuts_5;
6538 title_string = STR_SETUP_SHORTCUTS;
6541 /* use modified setup info without setup entries marked as hidden */
6542 setup_info = getSetupInfoFinal(setup_info);
6544 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6546 // determine maximal number of setup entries that can be displayed on screen
6548 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6551 // determine maximal number of setup entries available for this setup screen
6553 for (i = 0; setup_info[i].type != 0; i++)
6556 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6558 MapScreenGadgets(max_setup_info);
6561 redraw_mask = fade_mask = REDRAW_ALL;
6563 DrawMaskedBorder(fade_mask);
6568 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6570 menu_info = setup_info;
6572 HandleMenuScreen(mx, my, dx, dy, button,
6573 setup_mode, num_setup_info, max_setup_info);
6576 void DrawSetupScreen_Input()
6580 FadeOut(REDRAW_FIELD);
6584 setup_info = getSetupInfoFinal(setup_info_input);
6586 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6588 for (i = 0; setup_info[i].type != 0; i++)
6590 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6591 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6592 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6593 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6594 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6595 initCursor(i, IMG_MENU_BUTTON);
6597 DrawCursorAndText_Setup(i, -1, FALSE);
6600 /* create gadgets for setup input menu screen */
6601 FreeScreenGadgets();
6602 CreateScreenGadgets();
6604 /* map gadgets for setup input menu screen */
6605 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6607 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6609 FadeIn(REDRAW_FIELD);
6612 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6614 if (device_name == NULL)
6617 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6620 if (strlen(device_name) > 1)
6622 char c1 = device_name[strlen(device_name) - 1];
6623 char c2 = device_name[strlen(device_name) - 2];
6625 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6626 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6629 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6630 strlen(device_name));
6633 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6636 static struct SetupKeyboardInfo custom_key;
6643 { &custom_key.left, "Axis/Pad Left" },
6644 { &custom_key.right, "Axis/Pad Right" },
6645 { &custom_key.up, "Axis/Pad Up" },
6646 { &custom_key.down, "Axis/Pad Down" },
6647 { &custom_key.snap, "Button 1/A/X" },
6648 { &custom_key.drop, "Button 2/B/Y" }
6650 static char *joystick_name[MAX_PLAYERS] =
6657 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6658 int font_nr_info = FONT_MENU_1;
6659 int font_nr_name = FONT_VALUE_OLD;
6660 int font_nr_on = FONT_VALUE_1;
6661 int font_nr_off = FONT_VALUE_OLD;
6664 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6666 font_nr_info = FONT_MENU_2;
6667 font_nr_on = FONT_VALUE_NARROW;
6668 font_nr_off = FONT_VALUE_OLD_NARROW;
6671 custom_key = setup.input[player_nr].key;
6673 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6674 FONT_INPUT_1_ACTIVE);
6676 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6678 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6679 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6681 if (setup.input[player_nr].use_joystick)
6683 char *device_name = setup.input[player_nr].joy.device_name;
6684 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6685 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6686 char *text = joystick_name[joystick_nr];
6687 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6689 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6690 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6694 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6695 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6698 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6699 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6703 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6704 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6705 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6706 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6708 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6709 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6710 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6711 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6712 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6713 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6715 for (i = 0; i < 6; i++)
6717 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6719 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6721 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6722 (setup.input[player_nr].use_joystick ?
6724 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6728 static int input_player_nr = 0;
6730 void HandleSetupScreen_Input_Player(int step, int direction)
6732 int old_player_nr = input_player_nr;
6735 new_player_nr = old_player_nr + step * direction;
6736 if (new_player_nr < 0)
6738 if (new_player_nr > MAX_PLAYERS - 1)
6739 new_player_nr = MAX_PLAYERS - 1;
6741 if (new_player_nr != old_player_nr)
6743 input_player_nr = new_player_nr;
6745 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6749 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6751 static int choice = 0;
6754 int pos_start = SETUPINPUT_SCREEN_POS_START;
6755 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6756 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6757 int pos_end = SETUPINPUT_SCREEN_POS_END;
6759 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6763 for (i = 0; setup_info_input[i].type != 0; i++)
6765 /* adjust menu structure according to skipped setup entries */
6766 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6774 if (button == MB_MENU_INITIALIZE)
6776 /* input setup menu may have changed size due to graphics configuration */
6777 if (choice >= pos_empty1)
6780 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6782 DrawCursorAndText_Setup(choice, -1, TRUE);
6786 else if (button == MB_MENU_LEAVE)
6788 setup_mode = SETUP_MODE_MAIN;
6795 if (mx || my) /* mouse input */
6797 x = (mx - mSX) / 32;
6798 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6800 else if (dx || dy) /* keyboard input */
6802 if (dx && choice == 0)
6803 x = (dx < 0 ? 10 : 12);
6804 else if ((dx && choice == 1) ||
6805 (dx == -1 && choice == pos_end))
6806 button = MB_MENU_CHOICE;
6810 if (y >= pos_empty1 && y <= pos_empty2)
6811 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6814 if (y == 0 && dx != 0 && button)
6816 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6818 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6819 y >= pos_start && y <= pos_end &&
6820 !(y >= pos_empty1 && y <= pos_empty2))
6826 DrawCursorAndText_Setup(choice, -1, FALSE);
6827 DrawCursorAndText_Setup(y, -1, TRUE);
6829 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6838 char *device_name = setup.input[input_player_nr].joy.device_name;
6840 if (!setup.input[input_player_nr].use_joystick)
6842 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6844 setJoystickDeviceToNr(device_name, new_device_nr);
6845 setup.input[input_player_nr].use_joystick = TRUE;
6849 int device_nr = getJoystickNrFromDeviceName(device_name);
6850 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6852 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6853 setup.input[input_player_nr].use_joystick = FALSE;
6855 setJoystickDeviceToNr(device_name, new_device_nr);
6858 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6862 if (setup.input[input_player_nr].use_joystick)
6863 ConfigureJoystick(input_player_nr);
6865 CustomizeKeyboard(input_player_nr);
6867 else if (y == pos_end)
6873 setup_mode = SETUP_MODE_MAIN;
6880 static boolean CustomizeKeyboardMain(int player_nr)
6884 boolean finished = FALSE;
6885 static struct SetupKeyboardInfo custom_key;
6890 } customize_step[] =
6892 { &custom_key.left, "Move Left" },
6893 { &custom_key.right, "Move Right" },
6894 { &custom_key.up, "Move Up" },
6895 { &custom_key.down, "Move Down" },
6896 { &custom_key.snap, "Snap Field" },
6897 { &custom_key.drop, "Drop Element" }
6899 int font_nr_old = FONT_VALUE_OLD;
6900 int font_nr_new = FONT_VALUE_1;
6901 boolean success = FALSE;
6903 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6905 font_nr_old = FONT_VALUE_OLD_NARROW;
6906 font_nr_new = FONT_VALUE_NARROW;
6909 /* read existing key bindings from player setup */
6910 custom_key = setup.input[player_nr].key;
6913 FadeOut(REDRAW_FIELD);
6917 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6920 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6921 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6922 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6923 "Key:", FONT_INPUT_1_ACTIVE);
6924 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6925 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
6927 FadeIn(REDRAW_FIELD);
6933 if (NextValidEvent(&event))
6937 case EVENT_KEYPRESS:
6939 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6941 /* press 'Escape' to abort and keep the old key bindings */
6942 if (key == KSYM_Escape)
6944 FadeSkipNextFadeIn();
6951 /* press 'Enter' to keep the existing key binding */
6952 if (key == KSYM_Return)
6953 key = *customize_step[step_nr].key;
6955 /* check if key already used */
6956 for (i = 0; i < step_nr; i++)
6957 if (*customize_step[i].key == key)
6962 /* got new key binding */
6963 *customize_step[step_nr].key = key;
6964 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6966 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6967 getKeyNameFromKey(key), font_nr_new);
6970 /* un-highlight last query */
6971 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6972 customize_step[step_nr - 1].text, FONT_MENU_1);
6973 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6974 "Key:", FONT_MENU_1);
6976 /* all keys configured */
6985 /* query next key binding */
6986 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6987 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6988 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6989 "Key:", FONT_INPUT_1_ACTIVE);
6990 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6991 getKeyNameFromKey(*customize_step[step_nr].key),
6996 case EVENT_KEYRELEASE:
6997 key_joystick_mapping = 0;
7001 HandleOtherEvents(&event);
7009 /* write new key bindings back to player setup, if successfully finished */
7011 setup.input[player_nr].key = custom_key;
7016 void CustomizeKeyboard(int player_nr)
7018 boolean success = CustomizeKeyboardMain(player_nr);
7022 int font_nr = FONT_TITLE_1;
7023 int font_height = getFontHeight(font_nr);
7024 int ypos1 = SYSIZE / 2 - font_height * 2;
7025 int ypos2 = SYSIZE / 2 - font_height * 1;
7026 unsigned int wait_frame_delay = 0;
7027 unsigned int wait_frame_delay_value = 2000;
7029 ResetDelayCounter(&wait_frame_delay);
7033 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7034 DrawTextSCentered(ypos2, font_nr, "configured!");
7036 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7042 DrawSetupScreen_Input();
7045 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7047 #define MARKER_BUTTON 1
7048 #define MARKER_AXIS_X 2
7049 #define MARKER_AXIS_Y 3
7051 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7053 #if defined(TARGET_SDL2)
7054 static boolean bitmaps_initialized = FALSE;
7055 boolean screen_initialized = FALSE;
7056 static Bitmap *controller, *button, *axis_x, *axis_y;
7058 boolean success = TRUE;
7059 boolean done = FALSE, next = FALSE;
7061 int alpha = 200, alpha_step = -1;
7062 int alpha_ticks = 0;
7063 char mapping[4096], temp[4096];
7064 int font_name = MENU_SETUP_FONT_TITLE;
7065 int font_info = MENU_SETUP_FONT_TEXT;
7066 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7067 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7068 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7069 int ystep_name = getMenuTextStep(spacing_name, font_name);
7070 int ystep_line = getMenuTextStep(spacing_line, font_info);
7071 int ystep_para = getMenuTextStep(spacing_para, font_info);
7079 int axis, button, hat, hat_value;
7082 *step, *prev_step, steps[] =
7084 { 356, 155, MARKER_BUTTON, "a", },
7085 { 396, 122, MARKER_BUTTON, "b", },
7086 { 320, 125, MARKER_BUTTON, "x", },
7087 { 358, 95, MARKER_BUTTON, "y", },
7088 { 162, 125, MARKER_BUTTON, "back", },
7089 { 216, 125, MARKER_BUTTON, "guide", },
7090 { 271, 125, MARKER_BUTTON, "start", },
7091 { 110, 200, MARKER_BUTTON, "dpleft", },
7092 { 146, 228, MARKER_BUTTON, "dpdown", },
7093 { 178, 200, MARKER_BUTTON, "dpright", },
7094 { 146, 172, MARKER_BUTTON, "dpup", },
7095 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7096 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7097 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7098 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7099 { 73, 141, MARKER_BUTTON, "leftstick", },
7100 { 282, 210, MARKER_BUTTON, "rightstick", },
7101 { 73, 141, MARKER_AXIS_X, "leftx", },
7102 { 73, 141, MARKER_AXIS_Y, "lefty", },
7103 { 282, 210, MARKER_AXIS_X, "rightx", },
7104 { 282, 210, MARKER_AXIS_Y, "righty", },
7107 unsigned int event_frame_delay = 0;
7108 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7110 ResetDelayCounter(&event_frame_delay);
7112 if (!bitmaps_initialized)
7114 controller = LoadCustomImage("joystick/controller.png");
7115 button = LoadCustomImage("joystick/button.png");
7116 axis_x = LoadCustomImage("joystick/axis_x.png");
7117 axis_y = LoadCustomImage("joystick/axis_y.png");
7119 bitmaps_initialized = TRUE;
7122 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7125 /* print info about the joystick we are watching */
7126 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7127 SDL_JoystickInstanceID(joystick), name);
7128 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7129 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7130 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7133 /* initialize mapping with GUID and name */
7134 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7136 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7137 temp, name, SDL_GetPlatform());
7139 /* loop through all steps (buttons and axes), getting joystick events */
7140 for (i = 0; i < SDL_arraysize(steps) && !done;)
7142 Bitmap *marker = button; /* initialize with reliable default value */
7145 strcpy(step->mapping, mapping);
7149 step->hat_value = -1;
7151 marker = (step->marker == MARKER_BUTTON ? button :
7152 step->marker == MARKER_AXIS_X ? axis_x :
7153 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7157 while (!done && !next)
7159 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7160 alpha_ticks = SDL_GetTicks();
7167 else if (alpha < 128)
7173 int controller_x = SX + (SXSIZE - controller->width) / 2;
7174 int controller_y = SY + ystep_line;
7176 int marker_x = controller_x + step->x;
7177 int marker_y = controller_y + step->y;
7179 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7180 int ystart2 = ystart1 + ystep_name + ystep_line;
7184 DrawTextSCentered(ystart1, font_name, name);
7186 DrawTextSCentered(ystart2, font_info,
7187 "Press buttons and move axes on");
7188 ystart2 += ystep_line;
7189 DrawTextSCentered(ystart2, font_info,
7190 "your controller when indicated.");
7191 ystart2 += ystep_line;
7192 DrawTextSCentered(ystart2, font_info,
7193 "(Your controller may look different.)");
7194 ystart2 += ystep_para;
7196 #if defined(PLATFORM_ANDROID)
7197 DrawTextSCentered(ystart2, font_info,
7198 "To correct a mistake,");
7199 ystart2 += ystep_line;
7200 DrawTextSCentered(ystart2, font_info,
7201 "press the 'back' button.");
7202 ystart2 += ystep_line;
7203 DrawTextSCentered(ystart2, font_info,
7204 "To skip a button or axis,");
7205 ystart2 += ystep_line;
7206 DrawTextSCentered(ystart2, font_info,
7207 "press the 'menu' button.");
7209 DrawTextSCentered(ystart2, font_info,
7210 "To correct a mistake,");
7211 ystart2 += ystep_line;
7212 DrawTextSCentered(ystart2, font_info,
7213 "press the 'backspace' key.");
7214 ystart2 += ystep_line;
7215 DrawTextSCentered(ystart2, font_info,
7216 "To skip a button or axis,");
7217 ystart2 += ystep_line;
7218 DrawTextSCentered(ystart2, font_info,
7219 "press the 'return' key.");
7220 ystart2 += ystep_line;
7221 DrawTextSCentered(ystart2, font_info,
7222 "To exit, press the 'escape' key.");
7225 BlitBitmapMasked(controller, drawto, 0, 0,
7226 controller->width, controller->height,
7227 controller_x, controller_y);
7229 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7230 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7232 BlitBitmapMasked(marker, drawto, 0, 0,
7233 marker->width, marker->height,
7234 marker_x, marker_y);
7236 if (!screen_initialized)
7237 FadeIn(REDRAW_FIELD);
7241 screen_initialized = TRUE;
7243 while (NextValidEvent(&event))
7247 case SDL_JOYAXISMOTION:
7248 if (event.jaxis.value > 20000 ||
7249 event.jaxis.value < -20000)
7251 for (j = 0; j < i; j++)
7252 if (steps[j].axis == event.jaxis.axis)
7257 if (step->marker != MARKER_AXIS_X &&
7258 step->marker != MARKER_AXIS_Y)
7261 step->axis = event.jaxis.axis;
7262 strcat(mapping, step->field);
7263 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7264 strcat(mapping, temp);
7272 case SDL_JOYHATMOTION:
7273 /* ignore centering; we're probably just coming back
7274 to the center from the previous item we set */
7275 if (event.jhat.value == SDL_HAT_CENTERED)
7278 for (j = 0; j < i; j++)
7279 if (steps[j].hat == event.jhat.hat &&
7280 steps[j].hat_value == event.jhat.value)
7285 step->hat = event.jhat.hat;
7286 step->hat_value = event.jhat.value;
7287 strcat(mapping, step->field);
7288 snprintf(temp, sizeof(temp), ":h%u.%u,",
7289 event.jhat.hat, event.jhat.value );
7290 strcat(mapping, temp);
7297 case SDL_JOYBALLMOTION:
7300 case SDL_JOYBUTTONUP:
7301 for (j = 0; j < i; j++)
7302 if (steps[j].button == event.jbutton.button)
7307 step->button = event.jbutton.button;
7308 strcat(mapping, step->field);
7309 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7310 strcat(mapping, temp);
7317 case SDL_FINGERDOWN:
7318 case SDL_MOUSEBUTTONDOWN:
7319 /* skip this step */
7326 if (event.key.keysym.sym == KSYM_BackSpace ||
7327 event.key.keysym.sym == KSYM_Back)
7338 /* undo this step */
7339 prev_step = &steps[i - 1];
7340 strcpy(mapping, prev_step->mapping);
7347 if (event.key.keysym.sym == KSYM_space ||
7348 event.key.keysym.sym == KSYM_Return ||
7349 event.key.keysym.sym == KSYM_Menu)
7351 /* skip this step */
7358 if (event.key.keysym.sym == KSYM_Escape)
7368 program.exit_function(0);
7375 // do not handle events for longer than standard frame delay period
7376 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7385 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7388 // activate mapping for this game
7389 SDL_GameControllerAddMapping(mapping);
7391 // save mapping to personal mappings
7392 SaveSetup_AddGameControllerMapping(mapping);
7395 /* wait until the last pending event was removed from event queue */
7396 while (NextValidEvent(&event));
7404 static int ConfigureJoystickMain(int player_nr)
7406 char *device_name = setup.input[player_nr].joy.device_name;
7407 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7408 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7409 int success = FALSE;
7412 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7413 return JOYSTICK_NOT_AVAILABLE;
7415 if (!joystick_active || !setup.input[player_nr].use_joystick)
7416 return JOYSTICK_NOT_AVAILABLE;
7419 FadeOut(REDRAW_FIELD);
7421 // close all joystick devices (potentially opened as game controllers)
7422 for (i = 0; i < SDL_NumJoysticks(); i++)
7423 SDLCloseJoystick(i);
7425 // open joystick device as plain joystick to configure as game controller
7426 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7428 // as the joystick was successfully opened before, this should not happen
7429 if (joystick == NULL)
7432 // create new game controller mapping (buttons and axes) for joystick device
7433 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7435 // close joystick (and maybe re-open as configured game controller later)
7436 SDL_JoystickClose(joystick);
7438 // re-open all joystick devices (potentially as game controllers)
7439 for (i = 0; i < SDL_NumJoysticks(); i++)
7442 // clear all joystick input actions for all joystick devices
7443 SDLClearJoystickState();
7445 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7448 void ConfigureJoystick(int player_nr)
7450 boolean state = ConfigureJoystickMain(player_nr);
7452 if (state != JOYSTICK_NOT_CONFIGURED)
7454 boolean success = (state == JOYSTICK_CONFIGURED);
7455 char message1[MAX_OUTPUT_LINESIZE + 1];
7456 char *message2 = (success ? "configured!" : "not available!");
7457 char *device_name = setup.input[player_nr].joy.device_name;
7458 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7459 int font_nr = FONT_TITLE_1;
7460 int font_height = getFontHeight(font_nr);
7461 int ypos1 = SYSIZE / 2 - font_height * 2;
7462 int ypos2 = SYSIZE / 2 - font_height * 1;
7463 unsigned int wait_frame_delay = 0;
7464 unsigned int wait_frame_delay_value = 2000;
7466 ResetDelayCounter(&wait_frame_delay);
7470 sprintf(message1, "Joystick %d", nr);
7472 DrawTextSCentered(ypos1, font_nr, message1);
7473 DrawTextSCentered(ypos2, font_nr, message2);
7475 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7481 DrawSetupScreen_Input();
7484 boolean ConfigureVirtualButtonsMain()
7486 static char *customize_step_text[] =
7495 char grid_button[] =
7497 CHAR_GRID_BUTTON_LEFT,
7498 CHAR_GRID_BUTTON_RIGHT,
7499 CHAR_GRID_BUTTON_UP,
7500 CHAR_GRID_BUTTON_DOWN,
7501 CHAR_GRID_BUTTON_SNAP,
7502 CHAR_GRID_BUTTON_DROP
7504 int font_nr = FONT_INPUT_1_ACTIVE;
7505 int font_height = getFontHeight(font_nr);
7506 int ypos1 = SYSIZE / 2 - font_height * 2;
7507 int ypos2 = SYSIZE / 2 - font_height * 1;
7508 boolean success = FALSE;
7509 boolean finished = FALSE;
7511 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7512 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7513 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7514 boolean set_grid_button = FALSE;
7515 int nr = GRID_ACTIVE_NR();
7518 for (x = 0; x < MAX_GRID_XSIZE; x++)
7519 for (y = 0; y < MAX_GRID_YSIZE; y++)
7520 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7522 overlay.grid_button_highlight = grid_button[step_nr];
7525 FadeOut(REDRAW_FIELD);
7529 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7530 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7531 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7533 FadeIn(REDRAW_FIELD);
7535 SetOverlayShowGrid(TRUE);
7541 while (NextValidEvent(&event))
7545 case EVENT_KEYPRESS:
7547 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7549 /* press 'Escape' to abort and keep the old key bindings */
7550 if (key == KSYM_Escape)
7552 for (x = 0; x < MAX_GRID_XSIZE; x++)
7553 for (y = 0; y < MAX_GRID_YSIZE; y++)
7554 overlay.grid_button[x][y] = grid_button_old[x][y];
7556 FadeSkipNextFadeIn();
7563 /* press 'Enter' to keep the existing key binding */
7564 if (key == KSYM_Return ||
7565 #if defined(TARGET_SDL2)
7572 else if (key == KSYM_BackSpace
7573 #if defined(TARGET_SDL2)
7581 FadeSkipNextFadeIn();
7595 /* all virtual buttons configured */
7604 for (x = 0; x < MAX_GRID_XSIZE; x++)
7605 for (y = 0; y < MAX_GRID_YSIZE; y++)
7606 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7608 overlay.grid_button_highlight = grid_button[step_nr];
7610 /* query next virtual button */
7614 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7615 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7616 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7620 case EVENT_KEYRELEASE:
7621 key_joystick_mapping = 0;
7624 case EVENT_BUTTONPRESS:
7625 case EVENT_BUTTONRELEASE:
7627 ButtonEvent *button = (ButtonEvent *)&event;
7629 button->x += video.screen_xoffset;
7630 button->y += video.screen_yoffset;
7632 x = button->x * overlay.grid_xsize / video.screen_width;
7633 y = button->y * overlay.grid_ysize / video.screen_height;
7635 if (button->type == EVENT_BUTTONPRESS)
7637 button_status = button->button;
7640 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7641 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7643 set_grid_button = TRUE;
7647 button_status = MB_RELEASED;
7652 case EVENT_MOTIONNOTIFY:
7654 MotionEvent *motion = (MotionEvent *)&event;
7656 motion->x += video.screen_xoffset;
7657 motion->y += video.screen_yoffset;
7659 x = motion->x * overlay.grid_xsize / video.screen_width;
7660 y = motion->y * overlay.grid_ysize / video.screen_height;
7662 set_grid_button = TRUE;
7666 #if defined(TARGET_SDL2)
7667 case SDL_WINDOWEVENT:
7668 HandleWindowEvent((WindowEvent *) &event);
7670 // check if device has been rotated
7671 if (nr != GRID_ACTIVE_NR())
7673 nr = GRID_ACTIVE_NR();
7675 for (x = 0; x < MAX_GRID_XSIZE; x++)
7676 for (y = 0; y < MAX_GRID_YSIZE; y++)
7677 grid_button_old[x][y] = grid_button_tmp[x][y] =
7678 overlay.grid_button[x][y];
7683 case SDL_APP_WILLENTERBACKGROUND:
7684 case SDL_APP_DIDENTERBACKGROUND:
7685 case SDL_APP_WILLENTERFOREGROUND:
7686 case SDL_APP_DIDENTERFOREGROUND:
7687 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7692 HandleOtherEvents(&event);
7696 if (set_grid_button)
7698 overlay.grid_button[x][y] =
7699 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7700 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7701 grid_button_tmp[x][y]);
7703 set_grid_button = FALSE;
7710 for (x = 0; x < MAX_GRID_XSIZE; x++)
7711 for (y = 0; y < MAX_GRID_YSIZE; y++)
7712 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7714 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7716 SetOverlayShowGrid(FALSE);
7721 void ConfigureVirtualButtons()
7723 boolean success = ConfigureVirtualButtonsMain();
7727 int font_nr = FONT_TITLE_1;
7728 int font_height = getFontHeight(font_nr);
7729 int ypos1 = SYSIZE / 2 - font_height * 2;
7730 int ypos2 = SYSIZE / 2 - font_height * 1;
7731 unsigned int wait_frame_delay = 0;
7732 unsigned int wait_frame_delay_value = 2000;
7734 ResetDelayCounter(&wait_frame_delay);
7738 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7739 DrawTextSCentered(ypos2, font_nr, "configured!");
7741 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7748 void DrawSetupScreen()
7750 if (setup_mode == SETUP_MODE_INPUT)
7751 DrawSetupScreen_Input();
7752 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7753 DrawChooseTree(&game_speed_current);
7754 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7755 DrawChooseTree(&scroll_delay_current);
7756 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7757 DrawChooseTree(&snapshot_mode_current);
7758 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7759 DrawChooseTree(&window_size_current);
7760 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7761 DrawChooseTree(&scaling_type_current);
7762 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7763 DrawChooseTree(&rendering_mode_current);
7764 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7765 DrawChooseTree(&artwork.gfx_current);
7766 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7767 DrawChooseTree(&artwork.snd_current);
7768 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7769 DrawChooseTree(&artwork.mus_current);
7770 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7771 DrawChooseTree(&volume_simple_current);
7772 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7773 DrawChooseTree(&volume_loops_current);
7774 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7775 DrawChooseTree(&volume_music_current);
7776 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7777 DrawChooseTree(&touch_control_current);
7778 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7779 DrawChooseTree(&move_distance_current);
7780 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7781 DrawChooseTree(&drop_distance_current);
7782 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7783 DrawChooseTree(&transparency_current);
7784 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7785 DrawChooseTree(&grid_size_current[0][0]);
7786 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7787 DrawChooseTree(&grid_size_current[0][1]);
7788 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7789 DrawChooseTree(&grid_size_current[1][0]);
7790 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7791 DrawChooseTree(&grid_size_current[1][1]);
7793 DrawSetupScreen_Generic();
7795 PlayMenuSoundsAndMusic();
7798 void RedrawSetupScreenAfterFullscreenToggle()
7800 if (setup_mode == SETUP_MODE_GRAPHICS ||
7801 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7803 // update list selection from "setup.window_scaling_percent"
7804 execSetupGraphics_setWindowSizes(TRUE);
7810 void RedrawSetupScreenAfterScreenRotation(int nr)
7814 if (setup_mode == SETUP_MODE_TOUCH)
7816 // update virtual button settings (depending on screen orientation)
7819 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
7821 // save already configured virtual buttons
7822 for (x = 0; x < MAX_GRID_XSIZE; x++)
7823 for (y = 0; y < MAX_GRID_YSIZE; y++)
7824 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7828 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7830 if (setup_mode == SETUP_MODE_INPUT)
7831 HandleSetupScreen_Input(mx, my, dx, dy, button);
7832 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7833 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7834 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7835 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7836 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7837 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7838 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7839 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7840 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7841 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7842 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7843 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7844 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7845 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7846 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7847 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7848 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7849 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7850 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7851 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7852 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7853 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7854 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7855 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7856 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7857 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7858 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7859 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7860 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7861 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7862 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7863 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
7864 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7865 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
7866 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7867 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
7868 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7869 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
7870 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7871 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
7873 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7876 void HandleGameActions()
7878 if (game.restart_game_message != NULL)
7879 RequestRestartGame(game.restart_game_message);
7881 if (game_status != GAME_MODE_PLAYING)
7884 GameActions(); /* main game loop */
7886 if (tape.auto_play && !tape.playing)
7887 AutoPlayTape(); /* continue automatically playing next tape */
7891 /* ---------- new screen button stuff -------------------------------------- */
7893 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7897 case SCREEN_CTRL_ID_PREV_LEVEL:
7898 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7899 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7902 case SCREEN_CTRL_ID_NEXT_LEVEL:
7903 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7904 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7907 case SCREEN_CTRL_ID_PREV_PLAYER:
7908 *x = mSX + TILEX * 10;
7909 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7912 case SCREEN_CTRL_ID_NEXT_PLAYER:
7913 *x = mSX + TILEX * 12;
7914 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7918 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7924 int gfx_unpressed, gfx_pressed;
7925 void (*get_gadget_position)(int *, int *, int);
7929 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7932 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7933 getScreenMenuButtonPos,
7934 SCREEN_CTRL_ID_PREV_LEVEL,
7939 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7940 getScreenMenuButtonPos,
7941 SCREEN_CTRL_ID_NEXT_LEVEL,
7946 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7947 getScreenMenuButtonPos,
7948 SCREEN_CTRL_ID_PREV_PLAYER,
7953 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7954 getScreenMenuButtonPos,
7955 SCREEN_CTRL_ID_NEXT_PLAYER,
7963 int gfx_unpressed, gfx_pressed;
7967 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7970 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7971 -1, -1, /* these values are not constant, but can change at runtime */
7972 SCREEN_CTRL_ID_SCROLL_UP,
7976 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7977 -1, -1, /* these values are not constant, but can change at runtime */
7978 SCREEN_CTRL_ID_SCROLL_DOWN,
7985 int gfx_unpressed, gfx_pressed;
7991 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7994 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7995 -1, -1, /* these values are not constant, but can change at runtime */
7996 -1, -1, /* these values are not constant, but can change at runtime */
7997 GD_TYPE_SCROLLBAR_VERTICAL,
7998 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7999 "scroll level series vertically"
8003 static void CreateScreenMenubuttons()
8005 struct GadgetInfo *gi;
8006 unsigned int event_mask;
8009 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8011 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8012 int gfx_unpressed, gfx_pressed;
8013 int x, y, width, height;
8014 int gd_x1, gd_x2, gd_y1, gd_y2;
8015 int id = menubutton_info[i].gadget_id;
8017 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8019 menubutton_info[i].get_gadget_position(&x, &y, id);
8021 width = SC_MENUBUTTON_XSIZE;
8022 height = SC_MENUBUTTON_YSIZE;
8024 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8025 gfx_pressed = menubutton_info[i].gfx_pressed;
8026 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8027 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8028 gd_x1 = graphic_info[gfx_unpressed].src_x;
8029 gd_y1 = graphic_info[gfx_unpressed].src_y;
8030 gd_x2 = graphic_info[gfx_pressed].src_x;
8031 gd_y2 = graphic_info[gfx_pressed].src_y;
8033 gi = CreateGadget(GDI_CUSTOM_ID, id,
8034 GDI_CUSTOM_TYPE_ID, i,
8035 GDI_IMAGE_ID, gfx_unpressed,
8036 GDI_INFO_TEXT, menubutton_info[i].infotext,
8041 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8042 GDI_STATE, GD_BUTTON_UNPRESSED,
8043 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8044 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8045 GDI_DIRECT_DRAW, FALSE,
8046 GDI_EVENT_MASK, event_mask,
8047 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8051 Error(ERR_EXIT, "cannot create gadget");
8053 screen_gadget[id] = gi;
8057 static void CreateScreenScrollbuttons()
8059 struct GadgetInfo *gi;
8060 unsigned int event_mask;
8063 /* these values are not constant, but can change at runtime */
8064 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8065 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8066 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8067 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8069 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8071 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8072 int gfx_unpressed, gfx_pressed;
8073 int x, y, width, height;
8074 int gd_x1, gd_x2, gd_y1, gd_y2;
8075 int id = scrollbutton_info[i].gadget_id;
8077 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8079 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8080 y = mSY + scrollbutton_info[i].y;
8081 width = SC_SCROLLBUTTON_XSIZE;
8082 height = SC_SCROLLBUTTON_YSIZE;
8084 /* correct scrollbar position if placed outside menu (playfield) area */
8085 if (x > SX + SC_SCROLL_UP_XPOS)
8086 x = SX + SC_SCROLL_UP_XPOS;
8088 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8089 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8090 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8092 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8093 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8094 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8095 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8096 gd_x1 = graphic_info[gfx_unpressed].src_x;
8097 gd_y1 = graphic_info[gfx_unpressed].src_y;
8098 gd_x2 = graphic_info[gfx_pressed].src_x;
8099 gd_y2 = graphic_info[gfx_pressed].src_y;
8101 gi = CreateGadget(GDI_CUSTOM_ID, id,
8102 GDI_CUSTOM_TYPE_ID, i,
8103 GDI_IMAGE_ID, gfx_unpressed,
8104 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8109 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8110 GDI_STATE, GD_BUTTON_UNPRESSED,
8111 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8112 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8113 GDI_DIRECT_DRAW, FALSE,
8114 GDI_EVENT_MASK, event_mask,
8115 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8119 Error(ERR_EXIT, "cannot create gadget");
8121 screen_gadget[id] = gi;
8125 static void CreateScreenScrollbars()
8129 /* these values are not constant, but can change at runtime */
8130 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8131 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8132 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8133 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8135 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8137 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8138 int gfx_unpressed, gfx_pressed;
8139 int x, y, width, height;
8140 int gd_x1, gd_x2, gd_y1, gd_y2;
8141 struct GadgetInfo *gi;
8142 int items_max, items_visible, item_position;
8143 unsigned int event_mask;
8144 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8145 int id = scrollbar_info[i].gadget_id;
8147 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8149 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8150 y = mSY + scrollbar_info[i].y;
8151 width = scrollbar_info[i].width;
8152 height = scrollbar_info[i].height;
8154 /* correct scrollbar position if placed outside menu (playfield) area */
8155 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8156 x = SX + SC_SCROLL_VERTICAL_XPOS;
8158 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8159 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8161 items_max = num_page_entries;
8162 items_visible = num_page_entries;
8165 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8166 gfx_pressed = scrollbar_info[i].gfx_pressed;
8167 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8168 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8169 gd_x1 = graphic_info[gfx_unpressed].src_x;
8170 gd_y1 = graphic_info[gfx_unpressed].src_y;
8171 gd_x2 = graphic_info[gfx_pressed].src_x;
8172 gd_y2 = graphic_info[gfx_pressed].src_y;
8174 gi = CreateGadget(GDI_CUSTOM_ID, id,
8175 GDI_CUSTOM_TYPE_ID, i,
8176 GDI_IMAGE_ID, gfx_unpressed,
8177 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8182 GDI_TYPE, scrollbar_info[i].type,
8183 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8184 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8185 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8186 GDI_WHEEL_AREA_X, SX,
8187 GDI_WHEEL_AREA_Y, SY,
8188 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8189 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8190 GDI_STATE, GD_BUTTON_UNPRESSED,
8191 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8192 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8193 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8194 GDI_DIRECT_DRAW, FALSE,
8195 GDI_EVENT_MASK, event_mask,
8196 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8200 Error(ERR_EXIT, "cannot create gadget");
8202 screen_gadget[id] = gi;
8206 void CreateScreenGadgets()
8208 CreateScreenMenubuttons();
8210 CreateScreenScrollbuttons();
8211 CreateScreenScrollbars();
8214 void FreeScreenGadgets()
8218 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8219 FreeGadget(screen_gadget[i]);
8222 void MapScreenMenuGadgets(int screen_mask)
8226 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8227 if (screen_mask & menubutton_info[i].screen_mask)
8228 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8231 void MapScreenGadgets(int num_entries)
8235 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8238 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8239 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8241 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8242 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8245 void MapScreenTreeGadgets(TreeInfo *ti)
8247 MapScreenGadgets(numTreeInfoInGroup(ti));
8250 static void HandleScreenGadgets(struct GadgetInfo *gi)
8252 int id = gi->custom_id;
8253 int button = gi->event.button;
8254 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
8258 case SCREEN_CTRL_ID_PREV_LEVEL:
8259 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8262 case SCREEN_CTRL_ID_NEXT_LEVEL:
8263 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8266 case SCREEN_CTRL_ID_PREV_PLAYER:
8267 HandleSetupScreen_Input_Player(step, -1);
8270 case SCREEN_CTRL_ID_NEXT_PLAYER:
8271 HandleSetupScreen_Input_Player(step, +1);
8274 case SCREEN_CTRL_ID_SCROLL_UP:
8275 if (game_status == GAME_MODE_LEVELS)
8276 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8277 else if (game_status == GAME_MODE_LEVELNR)
8278 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8279 else if (game_status == GAME_MODE_SETUP)
8280 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8281 else if (game_status == GAME_MODE_INFO)
8282 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8285 case SCREEN_CTRL_ID_SCROLL_DOWN:
8286 if (game_status == GAME_MODE_LEVELS)
8287 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8288 else if (game_status == GAME_MODE_LEVELNR)
8289 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8290 else if (game_status == GAME_MODE_SETUP)
8291 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8292 else if (game_status == GAME_MODE_INFO)
8293 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8296 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8297 if (game_status == GAME_MODE_LEVELS)
8298 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8299 else if (game_status == GAME_MODE_LEVELNR)
8300 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8301 else if (game_status == GAME_MODE_SETUP)
8302 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8303 else if (game_status == GAME_MODE_INFO)
8304 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);