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,
753 &menu.main.text.first_level, &main_text_first_level,
757 MAIN_CONTROL_LAST_LEVEL,
759 &menu.main.text.last_level, &main_text_last_level,
763 MAIN_CONTROL_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 size for non-clickable text -- needed for text alignment */
1152 boolean calculate_text_size = (pos_button == NULL && 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 /* map gadgets for main menu screen */
1656 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1658 /* copy actual game door content to door double buffer for OpenDoor() */
1659 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1660 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1662 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1664 DrawMaskedBorder(fade_mask);
1669 /* update screen area with special editor door */
1670 redraw_mask |= REDRAW_ALL;
1673 SetMouseCursor(CURSOR_DEFAULT);
1675 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1678 static void gotoTopLevelDir()
1680 /* move upwards until inside (but not above) top level directory */
1681 while (leveldir_current->node_parent &&
1682 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1684 /* write a "path" into level tree for easy navigation to last level */
1685 if (leveldir_current->node_parent->node_group->cl_first == -1)
1687 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1688 int leveldir_pos = posTreeInfo(leveldir_current);
1689 int num_page_entries;
1690 int cl_first, cl_cursor;
1692 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1693 num_page_entries = num_leveldirs;
1695 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1697 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1698 cl_cursor = leveldir_pos - cl_first;
1700 leveldir_current->node_parent->node_group->cl_first = cl_first;
1701 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1704 leveldir_current = leveldir_current->node_parent;
1708 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1710 static unsigned int title_delay = 0;
1711 static int title_screen_nr = 0;
1712 static int last_sound = -1, last_music = -1;
1713 boolean return_to_main_menu = FALSE;
1714 struct TitleControlInfo *tci;
1717 if (button == MB_MENU_INITIALIZE)
1720 title_screen_nr = 0;
1721 tci = &title_controls[title_screen_nr];
1723 SetAnimStatus(getTitleAnimMode(tci));
1725 last_sound = SND_UNDEFINED;
1726 last_music = MUS_UNDEFINED;
1728 if (num_title_screens != 0)
1730 FadeSetEnterScreen();
1732 /* use individual title fading instead of global "enter screen" fading */
1733 fading = getTitleFading(tci);
1736 if (game_status_last_screen == GAME_MODE_INFO)
1738 if (num_title_screens == 0)
1740 /* switch game mode from title screen mode back to info screen mode */
1741 SetGameStatus(GAME_MODE_INFO);
1743 /* store that last screen was info screen, not main menu screen */
1744 game_status_last_screen = GAME_MODE_INFO;
1746 DrawInfoScreen_NotAvailable("Title screen information:",
1747 "No title screen for this level set.");
1751 FadeMenuSoundsAndMusic();
1754 FadeOut(REDRAW_ALL);
1756 /* title screens may have different window size */
1757 ChangeViewportPropertiesIfNeeded();
1759 /* only required to update logic for redrawing global border */
1763 DrawTitleScreenImage(tci->local_nr, tci->initial);
1765 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1767 sound = getTitleSound(tci);
1768 music = getTitleMusic(tci);
1770 if (sound != last_sound)
1771 PlayMenuSoundExt(sound);
1772 if (music != last_music)
1773 PlayMenuMusicExt(music);
1778 SetMouseCursor(CURSOR_NONE);
1782 DelayReached(&title_delay, 0); /* reset delay counter */
1787 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1788 button = MB_MENU_CHOICE;
1790 if (button == MB_MENU_LEAVE)
1792 return_to_main_menu = TRUE;
1794 else if (button == MB_MENU_CHOICE)
1796 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1798 SetGameStatus(GAME_MODE_INFO);
1800 info_mode = INFO_MODE_MAIN;
1809 if (title_screen_nr < num_title_screens)
1811 tci = &title_controls[title_screen_nr];
1813 SetAnimStatus(getTitleAnimMode(tci));
1815 sound = getTitleSound(tci);
1816 music = getTitleMusic(tci);
1818 if (last_sound != SND_UNDEFINED && sound != last_sound)
1819 FadeSound(last_sound);
1820 if (last_music != MUS_UNDEFINED && music != last_music)
1823 fading = getTitleFading(tci);
1825 FadeOut(REDRAW_ALL);
1828 DrawTitleScreenImage(tci->local_nr, tci->initial);
1830 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1832 sound = getTitleSound(tci);
1833 music = getTitleMusic(tci);
1835 if (sound != last_sound)
1836 PlayMenuSoundExt(sound);
1837 if (music != last_music)
1838 PlayMenuMusicExt(music);
1845 DelayReached(&title_delay, 0); /* reset delay counter */
1849 FadeMenuSoundsAndMusic();
1851 return_to_main_menu = TRUE;
1855 if (return_to_main_menu)
1857 SetMouseCursor(CURSOR_DEFAULT);
1859 /* force full menu screen redraw after displaying title screens */
1860 redraw_mask = REDRAW_ALL;
1862 if (game_status_last_screen == GAME_MODE_INFO)
1864 SetGameStatus(GAME_MODE_INFO);
1866 info_mode = INFO_MODE_MAIN;
1870 else /* default: return to main menu */
1872 SetGameStatus(GAME_MODE_MAIN);
1879 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1881 int old_level_nr = level_nr;
1884 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1885 new_level_nr = selected_level_nr;
1887 new_level_nr = old_level_nr + step * direction;
1889 if (new_level_nr < leveldir_current->first_level)
1890 new_level_nr = leveldir_current->first_level;
1891 if (new_level_nr > leveldir_current->last_level)
1892 new_level_nr = leveldir_current->last_level;
1894 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1896 /* skipping levels is only allowed when trying to skip single level */
1897 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1898 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1900 leveldir_current->handicap_level++;
1901 SaveLevelSetup_SeriesInfo();
1904 new_level_nr = leveldir_current->handicap_level;
1907 if (new_level_nr != old_level_nr)
1909 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1911 PlaySound(SND_MENU_ITEM_SELECTING);
1913 level_nr = new_level_nr;
1915 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1916 int2str(level_nr, menu.main.text.level_number.size),
1917 mci->pos_text->font);
1919 LoadLevel(level_nr);
1920 DrawPreviewLevelInitial();
1924 DrawCompleteVideoDisplay();
1926 SaveLevelSetup_SeriesInfo();
1928 /* needed because DrawPreviewLevelInitial() takes some time */
1930 /* SyncDisplay(); */
1934 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1936 static int choice = MAIN_CONTROL_GAME;
1937 static boolean button_pressed_last = FALSE;
1938 boolean button_pressed = FALSE;
1942 if (button == MB_MENU_INITIALIZE)
1944 DrawCursorAndText_Main(choice, TRUE, FALSE);
1949 if (mx || my) /* mouse input */
1953 for (i = 0; main_controls[i].nr != -1; i++)
1955 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1956 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1957 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1959 pos = main_controls[i].nr;
1965 /* check if level preview was clicked */
1966 if (insidePreviewRect(&preview, mx - SX, my - SY))
1967 pos = MAIN_CONTROL_GAME;
1969 // handle pressed/unpressed state for active/inactive menu buttons
1970 // (if pos != -1, "i" contains index position corresponding to "pos")
1972 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1973 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1974 button_pressed = TRUE;
1976 if (button_pressed != button_pressed_last)
1978 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1981 PlaySound(SND_MENU_BUTTON_PRESSING);
1983 PlaySound(SND_MENU_BUTTON_RELEASING);
1986 else if (dx || dy) /* keyboard input */
1988 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1989 choice == MAIN_CONTROL_SETUP))
1990 button = MB_MENU_CHOICE;
1995 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1997 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1999 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2001 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2003 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2005 CloseDoor(DOOR_CLOSE_2);
2007 SetGameStatus(GAME_MODE_LEVELNR);
2009 DrawChooseLevelNr();
2011 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2017 PlaySound(SND_MENU_ITEM_ACTIVATING);
2019 DrawCursorAndText_Main(choice, FALSE, FALSE);
2020 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2026 if (choice != MAIN_CONTROL_INFO &&
2027 choice != MAIN_CONTROL_SETUP)
2028 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2033 PlaySound(SND_MENU_ITEM_SELECTING);
2035 if (pos == MAIN_CONTROL_NAME)
2037 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2039 HandleTypeName(strlen(setup.player_name), 0);
2041 else if (pos == MAIN_CONTROL_LEVELS)
2045 CloseDoor(DOOR_CLOSE_2);
2047 SetGameStatus(GAME_MODE_LEVELS);
2049 SaveLevelSetup_LastSeries();
2050 SaveLevelSetup_SeriesInfo();
2052 if (setup.internal.choose_from_top_leveldir)
2055 DrawChooseLevelSet();
2058 else if (pos == MAIN_CONTROL_SCORES)
2060 CloseDoor(DOOR_CLOSE_2);
2062 SetGameStatus(GAME_MODE_SCORES);
2066 else if (pos == MAIN_CONTROL_EDITOR)
2068 if (leveldir_current->readonly &&
2069 !strEqual(setup.player_name, "Artsoft"))
2070 Request("This level is read only!", REQ_CONFIRM);
2072 CloseDoor(DOOR_CLOSE_2);
2074 SetGameStatus(GAME_MODE_EDITOR);
2076 FadeSetEnterScreen();
2080 else if (pos == MAIN_CONTROL_INFO)
2082 CloseDoor(DOOR_CLOSE_2);
2084 SetGameStatus(GAME_MODE_INFO);
2086 info_mode = INFO_MODE_MAIN;
2090 else if (pos == MAIN_CONTROL_GAME)
2092 StartGameActions(options.network, setup.autorecord, level.random_seed);
2094 else if (pos == MAIN_CONTROL_SETUP)
2096 CloseDoor(DOOR_CLOSE_2);
2098 SetGameStatus(GAME_MODE_SETUP);
2100 setup_mode = SETUP_MODE_MAIN;
2104 else if (pos == MAIN_CONTROL_QUIT)
2106 SaveLevelSetup_LastSeries();
2107 SaveLevelSetup_SeriesInfo();
2109 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2110 SetGameStatus(GAME_MODE_QUIT);
2115 button_pressed_last = button_pressed;
2119 /* ========================================================================= */
2120 /* info screen functions */
2121 /* ========================================================================= */
2123 static struct TokenInfo *info_info;
2124 static int num_info_info; /* number of info entries shown on screen */
2125 static int max_info_info; /* total number of info entries in list */
2127 static void execInfoTitleScreen()
2129 info_mode = INFO_MODE_TITLE;
2134 static void execInfoElements()
2136 info_mode = INFO_MODE_ELEMENTS;
2141 static void execInfoMusic()
2143 info_mode = INFO_MODE_MUSIC;
2148 static void execInfoCredits()
2150 info_mode = INFO_MODE_CREDITS;
2155 static void execInfoProgram()
2157 info_mode = INFO_MODE_PROGRAM;
2162 static void execInfoVersion()
2164 info_mode = INFO_MODE_VERSION;
2169 static void execInfoLevelSet()
2171 info_mode = INFO_MODE_LEVELSET;
2176 static void execExitInfo()
2178 SetGameStatus(GAME_MODE_MAIN);
2183 static struct TokenInfo info_info_main[] =
2185 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2186 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2187 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2188 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2189 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2190 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2191 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2192 { TYPE_EMPTY, NULL, "" },
2193 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2198 static int getMenuTextFont(int type)
2200 if (type & (TYPE_SWITCH |
2212 static struct TokenInfo *setup_info;
2213 static struct TokenInfo setup_info_input[];
2215 static struct TokenInfo *menu_info;
2217 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2218 int screen_pos, int menu_info_pos_raw,
2221 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2222 struct TokenInfo *ti = &token_info[pos];
2223 int xpos = MENU_SCREEN_START_XPOS;
2224 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2225 int font_nr = getMenuTextFont(ti->type);
2227 if (setup_mode == SETUP_MODE_INPUT)
2228 font_nr = FONT_MENU_1;
2231 font_nr = FONT_ACTIVE(font_nr);
2233 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2235 if (ti->type & ~TYPE_SKIP_ENTRY)
2236 drawCursor(screen_pos, active);
2239 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2242 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2245 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2248 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2251 static char *window_size_text;
2252 static char *scaling_type_text;
2254 static void drawSetupValue(int, int);
2256 static void drawMenuInfoList(int first_entry, int num_page_entries,
2257 int max_page_entries)
2261 if (first_entry + num_page_entries > max_page_entries)
2264 clearMenuListArea();
2266 for (i = 0; i < num_page_entries; i++)
2268 int menu_info_pos = first_entry + i;
2269 struct TokenInfo *si = &menu_info[menu_info_pos];
2270 void *value_ptr = si->value;
2272 /* set some entries to "unchangeable" according to other variables */
2273 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2274 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2275 (value_ptr == &setup.sound_music && !audio.music_available) ||
2276 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2277 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2278 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2279 si->type |= TYPE_GHOSTED;
2281 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2282 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2283 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2284 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2285 else if (si->type & ~TYPE_SKIP_ENTRY)
2286 initCursor(i, IMG_MENU_BUTTON);
2288 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2290 if (si->type & TYPE_VALUE &&
2291 menu_info == setup_info)
2292 drawSetupValue(i, menu_info_pos);
2296 static void DrawInfoScreen_Main()
2298 int fade_mask = REDRAW_FIELD;
2301 if (redraw_mask & REDRAW_ALL)
2302 fade_mask = REDRAW_ALL;
2304 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2305 fade_mask = REDRAW_ALL;
2308 FadeMenuSoundsAndMusic();
2310 FreeScreenGadgets();
2311 CreateScreenGadgets();
2313 /* (needed after displaying title screens which disable auto repeat) */
2314 KeyboardAutoRepeatOn();
2316 FadeSetLeaveScreen();
2320 /* needed if different viewport properties defined for info screen */
2321 ChangeViewportPropertiesIfNeeded();
2323 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2327 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2329 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2331 info_info = info_info_main;
2333 // determine maximal number of info entries that can be displayed on screen
2335 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2338 // determine maximal number of info entries available for menu of info screen
2340 for (i = 0; info_info[i].type != 0; i++)
2343 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2345 MapScreenGadgets(max_info_info);
2347 PlayMenuSoundsAndMusic();
2349 DrawMaskedBorder(fade_mask);
2354 static void changeSetupValue(int, int, int);
2356 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2357 int mode, int num_page_entries, int max_page_entries)
2359 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2360 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2361 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2362 int *num_page_entries_last = num_page_entries_all_last[game_status];
2363 int *choice_store = choice_stores[game_status];
2364 int *first_entry_store = first_entry_stores[game_status];
2365 int choice = choice_store[mode]; /* starts with 0 */
2366 int first_entry = first_entry_store[mode]; /* starts with 0 */
2368 int y = choice - first_entry;
2370 boolean position_set_by_scrollbar = (dx == 999);
2371 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2374 if (button == MB_MENU_INITIALIZE)
2376 // check if number of menu page entries has changed (may happen by change
2377 // of custom artwork definition value for 'list_size' for this menu screen)
2378 // (in this case, the last menu position most probably has to be corrected)
2379 if (num_page_entries != num_page_entries_last[mode])
2381 choice_store[mode] = first_entry_store[mode] = 0;
2383 choice = first_entry = 0;
2386 num_page_entries_last[mode] = num_page_entries;
2389 /* advance to first valid menu entry */
2390 while (choice < num_page_entries &&
2391 menu_info[choice].type & TYPE_SKIP_ENTRY)
2394 if (position_set_by_scrollbar)
2395 first_entry = first_entry_store[mode] = dy;
2397 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2398 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2400 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2402 if (choice < first_entry)
2404 choice = first_entry;
2406 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2409 else if (choice > first_entry + num_page_entries - 1)
2411 choice = first_entry + num_page_entries - 1;
2413 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2417 choice_store[mode] = choice;
2419 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2423 else if (button == MB_MENU_LEAVE)
2425 PlaySound(SND_MENU_ITEM_SELECTING);
2427 for (i = 0; i < max_page_entries; i++)
2429 if (menu_info[i].type & TYPE_LEAVE_MENU)
2431 void (*menu_callback_function)(void) = menu_info[i].value;
2435 menu_callback_function();
2437 break; /* absolutely needed because function changes 'menu_info'! */
2444 if (mx || my) /* mouse input */
2446 x = (mx - mSX) / 32;
2447 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2449 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2451 /* move cursor instead of scrolling when already at start/end of list */
2452 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2454 else if (dy == +1 * SCROLL_LINE &&
2455 first_entry + num_page_entries == max_page_entries)
2458 /* handle scrolling screen one line or page */
2460 y + dy > num_page_entries - 1)
2462 boolean redraw = FALSE;
2464 if (ABS(dy) == SCROLL_PAGE)
2465 step = num_page_entries - 1;
2467 if (dy < 0 && first_entry > 0)
2469 /* scroll page/line up */
2471 first_entry -= step;
2472 if (first_entry < 0)
2477 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2479 /* scroll page/line down */
2481 first_entry += step;
2482 if (first_entry + num_page_entries > max_page_entries)
2483 first_entry = MAX(0, max_page_entries - num_page_entries);
2490 choice += first_entry - first_entry_store[mode];
2492 if (choice < first_entry)
2494 choice = first_entry;
2496 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2499 else if (choice > first_entry + num_page_entries - 1)
2501 choice = first_entry + num_page_entries - 1;
2503 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2506 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2510 if (choice < first_entry ||
2511 choice > first_entry + num_page_entries - 1)
2512 first_entry += SIGN(dy);
2515 first_entry_store[mode] = first_entry;
2516 choice_store[mode] = choice;
2518 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2520 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2522 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2523 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2531 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2533 if (menu_info[choice].type & menu_navigation_type ||
2534 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2535 menu_info[choice].type & TYPE_YES_NO_AUTO)
2536 button = MB_MENU_CHOICE;
2541 /* jump to next non-empty menu entry (up or down) */
2542 while (first_entry + y > 0 &&
2543 first_entry + y < max_page_entries - 1 &&
2544 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2547 if (!IN_VIS_MENU(x, y))
2549 choice += y - y_old;
2551 if (choice < first_entry)
2552 first_entry = choice;
2553 else if (choice > first_entry + num_page_entries - 1)
2554 first_entry = choice - num_page_entries + 1;
2556 if (first_entry >= 0 &&
2557 first_entry + num_page_entries <= max_page_entries)
2559 first_entry_store[mode] = first_entry;
2561 if (choice < first_entry)
2562 choice = first_entry;
2563 else if (choice > first_entry + num_page_entries - 1)
2564 choice = first_entry + num_page_entries - 1;
2566 choice_store[mode] = choice;
2568 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2570 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2572 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2573 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2580 if (!anyScrollbarGadgetActive() &&
2581 IN_VIS_MENU(x, y) &&
2582 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2583 y >= 0 && y < num_page_entries)
2587 if (first_entry + y != choice &&
2588 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2590 PlaySound(SND_MENU_ITEM_ACTIVATING);
2592 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2593 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2595 choice = choice_store[mode] = first_entry + y;
2599 PlaySound(SND_MENU_ITEM_SELECTING);
2601 for (i = 0; menu_info[i].type != 0; i++)
2603 if (menu_info[i].type & TYPE_LEAVE_MENU)
2605 void (*menu_callback_function)(void) = menu_info[i].value;
2609 menu_callback_function();
2611 /* absolutely needed because function changes 'menu_info'! */
2619 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2621 PlaySound(SND_MENU_ITEM_SELECTING);
2623 /* when selecting key headline, execute function for key value change */
2624 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2625 menu_info[first_entry + y + 1].type & TYPE_KEY)
2628 /* when selecting string value, execute function for list selection */
2629 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2630 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2633 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2635 void (*menu_callback_function)(void) =
2636 menu_info[first_entry + y].value;
2638 FadeSetFromType(menu_info[first_entry + y].type);
2640 menu_callback_function();
2642 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2643 menu_info == setup_info)
2645 changeSetupValue(y, first_entry + y, dx);
2651 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2653 menu_info = info_info;
2655 HandleMenuScreen(mx, my, dx, dy, button,
2656 info_mode, num_info_info, max_info_info);
2659 static int getMenuFontSpacing(int spacing_height, int font_nr)
2661 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2663 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2667 static int getMenuTextSpacing(int spacing_height, int font_nr)
2669 return (getMenuFontSpacing(spacing_height, font_nr) +
2670 EXTRA_SPACING(game_status));
2673 static int getMenuTextStep(int spacing_height, int font_nr)
2675 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2678 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2680 int font_title = MENU_INFO_FONT_TITLE;
2681 int font_error = FONT_TEXT_2;
2682 int font_foot = MENU_INFO_FONT_FOOT;
2683 int spacing_title = menu.headline1_spacing_info[info_mode];
2684 int ystep_title = getMenuTextStep(spacing_title, font_title);
2685 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2686 int ystart2 = ystart1 + ystep_title;
2687 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2689 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2691 FadeOut(REDRAW_FIELD);
2696 DrawTextSCentered(ystart1, font_title, text_title);
2697 DrawTextSCentered(ystart2, font_error, text_error);
2699 DrawTextSCentered(ybottom, font_foot,
2700 "Press any key or button for info menu");
2702 FadeIn(REDRAW_FIELD);
2705 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2707 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2708 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2709 int font_title = MENU_INFO_FONT_TITLE;
2710 int font_foot = MENU_INFO_FONT_FOOT;
2711 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2712 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2713 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2714 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2715 int ystep = MENU_SCREEN_INFO_YSTEP;
2716 int element, action, direction;
2724 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2725 infoscreen_step[i] = infoscreen_frame[i] = 0;
2730 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2732 DrawTextSCentered(ybottom, font_foot,
2733 "Press any key or button for next page");
2739 while (helpanim_info[j].element != HELPANIM_LIST_END)
2741 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2746 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2755 j += infoscreen_step[i - start];
2757 element = helpanim_info[j].element;
2758 action = helpanim_info[j].action;
2759 direction = helpanim_info[j].direction;
2762 element = EL_UNKNOWN;
2764 if (action != -1 && direction != -1)
2765 graphic = el_act_dir2img(element, action, direction);
2766 else if (action != -1)
2767 graphic = el_act2img(element, action);
2768 else if (direction != -1)
2769 graphic = el_dir2img(element, direction);
2771 graphic = el2img(element);
2773 delay = helpanim_info[j++].delay;
2778 if (infoscreen_frame[i - start] == 0)
2781 infoscreen_frame[i - start] = delay - 1;
2785 sync_frame = delay - infoscreen_frame[i - start];
2786 infoscreen_frame[i - start]--;
2789 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2791 if (!infoscreen_frame[i - start])
2792 infoscreen_step[i - start] = 0;
2796 if (!infoscreen_frame[i - start])
2797 infoscreen_step[i - start]++;
2798 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2804 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2806 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2807 graphic, sync_frame, USE_MASKING);
2810 DrawInfoScreen_HelpText(element, action, direction, i - start);
2815 redraw_mask |= REDRAW_FIELD;
2820 static char *getHelpText(int element, int action, int direction)
2822 char token[MAX_LINE_LEN];
2824 strcpy(token, element_info[element].token_name);
2827 strcat(token, element_action_info[action].suffix);
2829 if (direction != -1)
2830 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2832 return getHashEntry(helptext_info, token);
2835 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2837 int font_nr = FONT_INFO_ELEMENTS;
2838 int font_width = getFontWidth(font_nr);
2839 int font_height = getFontHeight(font_nr);
2840 int yoffset = (TILEX - 2 * font_height) / 2;
2841 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2842 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2843 int ystep = TILEY + 4;
2844 int pad_left = xstart - SX;
2845 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2846 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2847 int max_lines_per_text = 2;
2850 if (action != -1 && direction != -1) /* element.action.direction */
2851 text = getHelpText(element, action, direction);
2853 if (text == NULL && action != -1) /* element.action */
2854 text = getHelpText(element, action, -1);
2856 if (text == NULL && direction != -1) /* element.direction */
2857 text = getHelpText(element, -1, direction);
2859 if (text == NULL) /* base element */
2860 text = getHelpText(element, -1, -1);
2862 if (text == NULL) /* not found */
2863 text = "No description available";
2865 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2866 ystart += getFontHeight(font_nr) / 2;
2868 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2869 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2870 TRUE, FALSE, FALSE);
2873 void DrawInfoScreen_TitleScreen()
2875 SetGameStatus(GAME_MODE_TITLE);
2880 void HandleInfoScreen_TitleScreen(int button)
2882 HandleTitleScreen(0, 0, 0, 0, button);
2885 void DrawInfoScreen_Elements()
2887 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2889 FadeOut(REDRAW_FIELD);
2894 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2896 FadeIn(REDRAW_FIELD);
2899 void HandleInfoScreen_Elements(int button)
2901 static unsigned int info_delay = 0;
2902 static int num_anims;
2903 static int num_pages;
2905 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2908 if (button == MB_MENU_INITIALIZE)
2910 boolean new_element = TRUE;
2914 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2916 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2918 else if (new_element)
2921 new_element = FALSE;
2925 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2929 if (button == MB_MENU_LEAVE)
2931 PlaySound(SND_MENU_ITEM_SELECTING);
2933 info_mode = INFO_MODE_MAIN;
2938 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2940 if (button != MB_MENU_INITIALIZE)
2942 PlaySound(SND_MENU_ITEM_SELECTING);
2947 if (page >= num_pages)
2949 FadeMenuSoundsAndMusic();
2951 info_mode = INFO_MODE_MAIN;
2958 FadeSetNextScreen();
2960 if (button != MB_MENU_INITIALIZE)
2961 FadeOut(REDRAW_FIELD);
2963 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2965 if (button != MB_MENU_INITIALIZE)
2966 FadeIn(REDRAW_FIELD);
2970 if (DelayReached(&info_delay, GameFrameDelay))
2971 if (page < num_pages)
2972 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2974 PlayMenuSoundIfLoop();
2978 void DrawInfoScreen_Music()
2980 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2982 FadeOut(REDRAW_FIELD);
2989 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2991 FadeIn(REDRAW_FIELD);
2994 void HandleInfoScreen_Music(int button)
2996 static struct MusicFileInfo *list = NULL;
2997 int font_title = MENU_INFO_FONT_TITLE;
2998 int font_head = MENU_INFO_FONT_HEAD;
2999 int font_text = MENU_INFO_FONT_TEXT;
3000 int font_foot = MENU_INFO_FONT_FOOT;
3001 int spacing_title = menu.headline1_spacing_info[info_mode];
3002 int spacing_head = menu.headline2_spacing_info[info_mode];
3003 int ystep_title = getMenuTextStep(spacing_title, font_title);
3004 int ystep_head = getMenuTextStep(spacing_head, font_head);
3005 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3006 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3008 if (button == MB_MENU_INITIALIZE)
3010 list = music_file_info;
3014 FadeMenuSoundsAndMusic();
3019 DrawTextSCentered(ystart, font_title,
3020 "No music info for this level set.");
3022 DrawTextSCentered(ybottom, font_foot,
3023 "Press any key or button for info menu");
3029 if (button == MB_MENU_LEAVE)
3031 PlaySound(SND_MENU_ITEM_SELECTING);
3033 FadeMenuSoundsAndMusic();
3035 info_mode = INFO_MODE_MAIN;
3040 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3042 if (button != MB_MENU_INITIALIZE)
3044 PlaySound(SND_MENU_ITEM_SELECTING);
3052 FadeMenuSoundsAndMusic();
3054 info_mode = INFO_MODE_MAIN;
3060 FadeMenuSoundsAndMusic();
3062 if (list != music_file_info)
3063 FadeSetNextScreen();
3065 if (button != MB_MENU_INITIALIZE)
3066 FadeOut(REDRAW_FIELD);
3073 int sound = list->music;
3075 if (sound_info[sound].loop)
3076 PlaySoundLoop(sound);
3080 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3084 PlayMusic(list->music);
3086 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3089 ystart += ystep_title;
3091 if (!strEqual(list->title, UNKNOWN_NAME))
3093 if (!strEqual(list->title_header, UNKNOWN_NAME))
3095 DrawTextSCentered(ystart, font_head, list->title_header);
3096 ystart += ystep_head;
3099 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3100 ystart += ystep_head;
3103 if (!strEqual(list->artist, UNKNOWN_NAME))
3105 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3106 DrawTextSCentered(ystart, font_head, list->artist_header);
3108 DrawTextSCentered(ystart, font_head, "by");
3110 ystart += ystep_head;
3112 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3113 ystart += ystep_head;
3116 if (!strEqual(list->album, UNKNOWN_NAME))
3118 if (!strEqual(list->album_header, UNKNOWN_NAME))
3119 DrawTextSCentered(ystart, font_head, list->album_header);
3121 DrawTextSCentered(ystart, font_head, "from the album");
3123 ystart += ystep_head;
3125 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3126 ystart += ystep_head;
3129 if (!strEqual(list->year, UNKNOWN_NAME))
3131 if (!strEqual(list->year_header, UNKNOWN_NAME))
3132 DrawTextSCentered(ystart, font_head, list->year_header);
3134 DrawTextSCentered(ystart, font_head, "from the year");
3136 ystart += ystep_head;
3138 DrawTextFCentered(ystart, font_text, "%s", list->year);
3139 ystart += ystep_head;
3142 DrawTextSCentered(ybottom, FONT_TEXT_4,
3143 "Press any key or button for next page");
3145 if (button != MB_MENU_INITIALIZE)
3146 FadeIn(REDRAW_FIELD);
3149 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3150 PlaySoundLoop(list->music);
3153 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3155 int font_title = MENU_INFO_FONT_TITLE;
3156 int font_head = MENU_INFO_FONT_HEAD;
3157 int font_text = MENU_INFO_FONT_TEXT;
3158 int font_foot = MENU_INFO_FONT_FOOT;
3159 int spacing_title = menu.headline1_spacing_info[info_mode];
3160 int spacing_head = menu.headline2_spacing_info[info_mode];
3161 int spacing_para = menu.paragraph_spacing_info[info_mode];
3162 int spacing_line = menu.line_spacing_info[info_mode];
3163 int ystep_title = getMenuTextStep(spacing_title, font_title);
3164 int ystep_head = getMenuTextStep(spacing_head, font_head);
3165 int ystep_para = getMenuTextStep(spacing_para, font_text);
3166 int ystep_line = getMenuTextStep(spacing_line, font_text);
3167 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3168 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3173 DrawTextSCentered(ystart, font_title, "Credits:");
3174 ystart += ystep_title;
3178 DrawTextSCentered(ystart, font_head,
3179 "Special thanks to");
3180 ystart += ystep_head;
3181 DrawTextSCentered(ystart, font_text,
3183 ystart += ystep_head;
3184 DrawTextSCentered(ystart, font_head,
3186 ystart += ystep_head;
3187 DrawTextSCentered(ystart, font_text,
3188 "\"Boulder Dash\"");
3189 ystart += ystep_head;
3190 DrawTextSCentered(ystart, font_head,
3192 ystart += ystep_head;
3193 DrawTextSCentered(ystart, font_text,
3195 ystart += ystep_head;
3196 DrawTextSCentered(ystart, font_head,
3198 ystart += ystep_head;
3199 DrawTextSCentered(ystart, font_text,
3200 "First Star Software");
3202 else if (screen_nr == 1)
3204 DrawTextSCentered(ystart, font_head,
3205 "Special thanks to");
3206 ystart += ystep_head;
3207 DrawTextSCentered(ystart, font_text,
3208 "Klaus Heinz & Volker Wertich");
3209 ystart += ystep_head;
3210 DrawTextSCentered(ystart, font_head,
3212 ystart += ystep_head;
3213 DrawTextSCentered(ystart, font_text,
3214 "\"Emerald Mine\"");
3215 ystart += ystep_head;
3216 DrawTextSCentered(ystart, font_head,
3218 ystart += ystep_head;
3219 DrawTextSCentered(ystart, font_text,
3221 ystart += ystep_head;
3222 DrawTextSCentered(ystart, font_head,
3224 ystart += ystep_head;
3225 DrawTextSCentered(ystart, font_text,
3228 else if (screen_nr == 2)
3230 DrawTextSCentered(ystart, font_head,
3231 "Special thanks to");
3232 ystart += ystep_head;
3233 DrawTextSCentered(ystart, font_text,
3234 "Michael Stopp & Philip Jespersen");
3235 ystart += ystep_head;
3236 DrawTextSCentered(ystart, font_head,
3238 ystart += ystep_head;
3239 DrawTextSCentered(ystart, font_text,
3241 ystart += ystep_head;
3242 DrawTextSCentered(ystart, font_head,
3244 ystart += ystep_head;
3245 DrawTextSCentered(ystart, font_text,
3247 ystart += ystep_head;
3248 DrawTextSCentered(ystart, font_head,
3250 ystart += ystep_head;
3251 DrawTextSCentered(ystart, font_text,
3252 "Digital Integration");
3254 else if (screen_nr == 3)
3256 DrawTextSCentered(ystart, font_head,
3257 "Special thanks to");
3258 ystart += ystep_head;
3259 DrawTextSCentered(ystart, font_text,
3260 "Hiroyuki Imabayashi");
3261 ystart += ystep_head;
3262 DrawTextSCentered(ystart, font_head,
3264 ystart += ystep_head;
3265 DrawTextSCentered(ystart, font_text,
3267 ystart += ystep_head;
3268 DrawTextSCentered(ystart, font_head,
3270 ystart += ystep_head;
3271 DrawTextSCentered(ystart, font_text,
3273 ystart += ystep_head;
3274 DrawTextSCentered(ystart, font_head,
3276 ystart += ystep_head;
3277 DrawTextSCentered(ystart, font_text,
3280 else if (screen_nr == 4)
3282 DrawTextSCentered(ystart, font_head,
3283 "Special thanks to");
3284 ystart += ystep_head;
3285 DrawTextSCentered(ystart, font_text,
3287 ystart += ystep_head;
3288 DrawTextSCentered(ystart, font_head,
3290 ystart += ystep_head;
3291 DrawTextSCentered(ystart, font_text,
3292 "J\xfcrgen Bonhagen");
3293 ystart += ystep_head;
3294 DrawTextSCentered(ystart, font_head,
3295 "for the continuous creation");
3296 ystart += ystep_line;
3297 DrawTextSCentered(ystart, font_head,
3298 "of outstanding level sets");
3300 else if (screen_nr == 5)
3302 DrawTextSCentered(ystart, font_head,
3304 ystart += ystep_head;
3305 DrawTextSCentered(ystart, font_text,
3307 ystart += ystep_head;
3308 DrawTextSCentered(ystart, font_head,
3309 "for ideas and inspiration by");
3310 ystart += ystep_head;
3311 DrawTextSCentered(ystart, font_text,
3313 ystart += ystep_para;
3315 DrawTextSCentered(ystart, font_head,
3317 ystart += ystep_head;
3318 DrawTextSCentered(ystart, font_text,
3320 ystart += ystep_head;
3321 DrawTextSCentered(ystart, font_head,
3322 "for ideas and inspiration by");
3323 ystart += ystep_head;
3324 DrawTextSCentered(ystart, font_text,
3327 else if (screen_nr == 6)
3329 DrawTextSCentered(ystart, font_head,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_text,
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_head,
3336 "for the code base used for the");
3337 ystart += ystep_line;
3338 DrawTextSCentered(ystart, font_head,
3339 "native Emerald Mine engine");
3341 else if (screen_nr == 7)
3343 DrawTextSCentered(ystart, font_head,
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_text,
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_head,
3350 "for the initial DOS port");
3351 ystart += ystep_para;
3353 DrawTextSCentered(ystart, font_head,
3355 ystart += ystep_head;
3356 DrawTextSCentered(ystart, font_text,
3358 ystart += ystep_head;
3359 DrawTextSCentered(ystart, font_head,
3360 "for some additional toons");
3362 else if (screen_nr == 8)
3364 DrawTextSCentered(ystart, font_head,
3365 "And not to forget:");
3366 ystart += ystep_head;
3367 DrawTextSCentered(ystart, font_head,
3369 ystart += ystep_head;
3370 DrawTextSCentered(ystart, font_text,
3371 "All those who contributed");
3372 ystart += ystep_line;
3373 DrawTextSCentered(ystart, font_text,
3374 "levels to this game");
3375 ystart += ystep_line;
3376 DrawTextSCentered(ystart, font_text,
3380 DrawTextSCentered(ybottom, font_foot,
3381 "Press any key or button for next page");
3384 void DrawInfoScreen_Credits()
3386 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3388 FadeMenuSoundsAndMusic();
3390 FadeOut(REDRAW_FIELD);
3392 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3394 FadeIn(REDRAW_FIELD);
3397 void HandleInfoScreen_Credits(int button)
3399 static int screen_nr = 0;
3400 int num_screens = 9;
3402 if (button == MB_MENU_INITIALIZE)
3406 // DrawInfoScreen_CreditsScreen(screen_nr);
3409 if (button == MB_MENU_LEAVE)
3411 PlaySound(SND_MENU_ITEM_SELECTING);
3413 info_mode = INFO_MODE_MAIN;
3418 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3420 if (button != MB_MENU_INITIALIZE)
3422 PlaySound(SND_MENU_ITEM_SELECTING);
3427 if (screen_nr >= num_screens)
3429 FadeMenuSoundsAndMusic();
3431 info_mode = INFO_MODE_MAIN;
3438 FadeSetNextScreen();
3440 if (button != MB_MENU_INITIALIZE)
3441 FadeOut(REDRAW_FIELD);
3443 DrawInfoScreen_CreditsScreen(screen_nr);
3445 if (button != MB_MENU_INITIALIZE)
3446 FadeIn(REDRAW_FIELD);
3450 PlayMenuSoundIfLoop();
3454 void DrawInfoScreen_Program()
3456 int font_title = MENU_INFO_FONT_TITLE;
3457 int font_head = MENU_INFO_FONT_HEAD;
3458 int font_text = MENU_INFO_FONT_TEXT;
3459 int font_foot = MENU_INFO_FONT_FOOT;
3460 int spacing_title = menu.headline1_spacing_info[info_mode];
3461 int spacing_head = menu.headline2_spacing_info[info_mode];
3462 int spacing_para = menu.paragraph_spacing_info[info_mode];
3463 int spacing_line = menu.line_spacing_info[info_mode];
3464 int ystep_title = getMenuTextStep(spacing_title, font_title);
3465 int ystep_head = getMenuTextStep(spacing_head, font_head);
3466 int ystep_para = getMenuTextStep(spacing_para, font_text);
3467 int ystep_line = getMenuTextStep(spacing_line, font_text);
3468 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3469 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3471 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3473 FadeOut(REDRAW_FIELD);
3478 DrawTextSCentered(ystart, font_title, "Program Information:");
3479 ystart += ystep_title;
3481 DrawTextSCentered(ystart, font_head,
3482 "This game is Freeware!");
3483 ystart += ystep_head;
3484 DrawTextSCentered(ystart, font_head,
3485 "If you like it, send e-mail to:");
3486 ystart += ystep_head;
3487 DrawTextSCentered(ystart, font_text,
3488 setup.internal.program_email);
3489 ystart += ystep_para;
3491 DrawTextSCentered(ystart, font_head,
3492 "More information and levels:");
3493 ystart += ystep_head;
3494 DrawTextSCentered(ystart, font_text,
3495 setup.internal.program_website);
3496 ystart += ystep_para;
3498 DrawTextSCentered(ystart, font_head,
3499 "If you have created new levels,");
3500 ystart += ystep_line;
3501 DrawTextSCentered(ystart, font_head,
3502 "send them to me to include them!");
3503 ystart += ystep_head;
3504 DrawTextSCentered(ystart, font_head,
3507 DrawTextSCentered(ybottom, font_foot,
3508 "Press any key or button for info menu");
3510 FadeIn(REDRAW_FIELD);
3513 void HandleInfoScreen_Program(int button)
3515 if (button == MB_MENU_LEAVE)
3517 PlaySound(SND_MENU_ITEM_SELECTING);
3519 info_mode = INFO_MODE_MAIN;
3524 else if (button == MB_MENU_CHOICE)
3526 PlaySound(SND_MENU_ITEM_SELECTING);
3528 FadeMenuSoundsAndMusic();
3530 info_mode = INFO_MODE_MAIN;
3535 PlayMenuSoundIfLoop();
3539 void DrawInfoScreen_Version()
3541 int font_title = MENU_INFO_FONT_TITLE;
3542 int font_head = MENU_INFO_FONT_HEAD;
3543 int font_text = MENU_INFO_FONT_TEXT;
3544 int font_foot = MENU_INFO_FONT_FOOT;
3545 int spacing_title = menu.headline1_spacing_info[info_mode];
3546 int spacing_head = menu.headline2_spacing_info[info_mode];
3547 int spacing_para = menu.paragraph_spacing_info[info_mode];
3548 int spacing_line = menu.line_spacing_info[info_mode];
3549 int xstep = getFontWidth(font_text);
3550 int ystep_title = getMenuTextStep(spacing_title, font_title);
3551 int ystep_head = getMenuTextStep(spacing_head, font_head);
3552 int ystep_para = getMenuTextStep(spacing_para, font_text);
3553 int ystep_line = getMenuTextStep(spacing_line, font_text);
3554 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3555 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3556 int xstart1 = mSX - SX + 2 * xstep;
3557 int xstart2 = mSX - SX + 18 * xstep;
3558 int xstart3 = mSX - SX + 28 * xstep;
3559 SDL_version sdl_version_compiled;
3560 const SDL_version *sdl_version_linked;
3561 int driver_name_len = 10;
3562 #if defined(TARGET_SDL2)
3563 SDL_version sdl_version_linked_ext;
3564 const char *driver_name = NULL;
3566 char driver_name[driver_name_len];
3569 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3571 FadeOut(REDRAW_FIELD);
3576 DrawTextSCentered(ystart, font_title, "Version Information:");
3577 ystart += ystep_title;
3579 DrawTextF(xstart1, ystart, font_head, "Name");
3580 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3581 ystart += ystep_line;
3583 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3585 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3586 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3587 ystart += ystep_line;
3589 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3590 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3591 ystart += ystep_line;
3595 DrawTextF(xstart1, ystart, font_head, "Version");
3596 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3597 ystart += ystep_line;
3600 DrawTextF(xstart1, ystart, font_head, "Platform");
3601 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3602 ystart += ystep_line;
3604 DrawTextF(xstart1, ystart, font_head, "Target");
3605 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3606 ystart += ystep_line;
3608 DrawTextF(xstart1, ystart, font_head, "Source date");
3609 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3610 ystart += ystep_para;
3612 DrawTextF(xstart1, ystart, font_head, "Library");
3613 DrawTextF(xstart2, ystart, font_head, "compiled");
3614 DrawTextF(xstart3, ystart, font_head, "linked");
3615 ystart += ystep_head;
3617 SDL_VERSION(&sdl_version_compiled);
3618 #if defined(TARGET_SDL2)
3619 SDL_GetVersion(&sdl_version_linked_ext);
3620 sdl_version_linked = &sdl_version_linked_ext;
3622 sdl_version_linked = SDL_Linked_Version();
3625 DrawTextF(xstart1, ystart, font_text, "SDL");
3626 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3627 sdl_version_compiled.major,
3628 sdl_version_compiled.minor,
3629 sdl_version_compiled.patch);
3630 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3631 sdl_version_linked->major,
3632 sdl_version_linked->minor,
3633 sdl_version_linked->patch);
3634 ystart += ystep_line;
3636 SDL_IMAGE_VERSION(&sdl_version_compiled);
3637 sdl_version_linked = IMG_Linked_Version();
3639 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3640 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3641 sdl_version_compiled.major,
3642 sdl_version_compiled.minor,
3643 sdl_version_compiled.patch);
3644 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3645 sdl_version_linked->major,
3646 sdl_version_linked->minor,
3647 sdl_version_linked->patch);
3648 ystart += ystep_line;
3650 SDL_MIXER_VERSION(&sdl_version_compiled);
3651 sdl_version_linked = Mix_Linked_Version();
3653 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3654 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3655 sdl_version_compiled.major,
3656 sdl_version_compiled.minor,
3657 sdl_version_compiled.patch);
3658 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3659 sdl_version_linked->major,
3660 sdl_version_linked->minor,
3661 sdl_version_linked->patch);
3662 ystart += ystep_line;
3664 SDL_NET_VERSION(&sdl_version_compiled);
3665 sdl_version_linked = SDLNet_Linked_Version();
3667 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3668 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3669 sdl_version_compiled.major,
3670 sdl_version_compiled.minor,
3671 sdl_version_compiled.patch);
3672 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3673 sdl_version_linked->major,
3674 sdl_version_linked->minor,
3675 sdl_version_linked->patch);
3676 ystart += ystep_para;
3678 DrawTextF(xstart1, ystart, font_head, "Driver");
3679 DrawTextF(xstart2, ystart, font_head, "Requested");
3680 DrawTextF(xstart3, ystart, font_head, "Used");
3681 ystart += ystep_head;
3683 #if defined(TARGET_SDL2)
3684 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3686 SDL_VideoDriverName(driver_name, driver_name_len);
3689 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3690 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3691 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3692 ystart += ystep_line;
3694 #if defined(TARGET_SDL2)
3695 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3697 SDL_AudioDriverName(driver_name, driver_name_len);
3700 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3701 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3702 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3704 DrawTextSCentered(ybottom, font_foot,
3705 "Press any key or button for info menu");
3707 FadeIn(REDRAW_FIELD);
3710 void HandleInfoScreen_Version(int button)
3712 if (button == MB_MENU_LEAVE)
3714 PlaySound(SND_MENU_ITEM_SELECTING);
3716 info_mode = INFO_MODE_MAIN;
3721 else if (button == MB_MENU_CHOICE)
3723 PlaySound(SND_MENU_ITEM_SELECTING);
3725 FadeMenuSoundsAndMusic();
3727 info_mode = INFO_MODE_MAIN;
3732 PlayMenuSoundIfLoop();
3736 void DrawInfoScreen_LevelSet()
3738 struct TitleMessageInfo *tmi = &readme;
3739 char *filename = getLevelSetInfoFilename();
3740 char *title = "Level Set Information:";
3741 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3742 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3744 if (filename == NULL)
3746 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3751 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3753 FadeOut(REDRAW_FIELD);
3758 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3760 /* if x position set to "-1", automatically determine by playfield width */
3762 tmi->x = SXSIZE / 2;
3764 /* if y position set to "-1", use static default value */
3768 /* if width set to "-1", automatically determine by playfield width */
3769 if (tmi->width == -1)
3770 tmi->width = SXSIZE - 2 * TILEX;
3772 /* if height set to "-1", automatically determine by playfield height */
3773 if (tmi->height == -1)
3774 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3776 /* if chars set to "-1", automatically determine by text and font width */
3777 if (tmi->chars == -1)
3778 tmi->chars = tmi->width / getFontWidth(tmi->font);
3780 tmi->width = tmi->chars * getFontWidth(tmi->font);
3782 /* if lines set to "-1", automatically determine by text and font height */
3783 if (tmi->lines == -1)
3784 tmi->lines = tmi->height / getFontHeight(tmi->font);
3786 tmi->height = tmi->lines * getFontHeight(tmi->font);
3788 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3789 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3790 tmi->autowrap, tmi->centered, tmi->parse_comments);
3792 DrawTextSCentered(ybottom, FONT_TEXT_4,
3793 "Press any key or button for info menu");
3795 FadeIn(REDRAW_FIELD);
3798 void HandleInfoScreen_LevelSet(int button)
3800 if (button == MB_MENU_LEAVE)
3802 PlaySound(SND_MENU_ITEM_SELECTING);
3804 info_mode = INFO_MODE_MAIN;
3809 else if (button == MB_MENU_CHOICE)
3811 PlaySound(SND_MENU_ITEM_SELECTING);
3813 FadeMenuSoundsAndMusic();
3815 info_mode = INFO_MODE_MAIN;
3820 PlayMenuSoundIfLoop();
3824 static void DrawInfoScreen()
3826 if (info_mode == INFO_MODE_TITLE)
3827 DrawInfoScreen_TitleScreen();
3828 else if (info_mode == INFO_MODE_ELEMENTS)
3829 DrawInfoScreen_Elements();
3830 else if (info_mode == INFO_MODE_MUSIC)
3831 DrawInfoScreen_Music();
3832 else if (info_mode == INFO_MODE_CREDITS)
3833 DrawInfoScreen_Credits();
3834 else if (info_mode == INFO_MODE_PROGRAM)
3835 DrawInfoScreen_Program();
3836 else if (info_mode == INFO_MODE_VERSION)
3837 DrawInfoScreen_Version();
3838 else if (info_mode == INFO_MODE_LEVELSET)
3839 DrawInfoScreen_LevelSet();
3841 DrawInfoScreen_Main();
3843 if (info_mode != INFO_MODE_MAIN &&
3844 info_mode != INFO_MODE_TITLE &&
3845 info_mode != INFO_MODE_MUSIC)
3846 PlayMenuSoundsAndMusic();
3849 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3851 if (info_mode == INFO_MODE_TITLE)
3852 HandleInfoScreen_TitleScreen(button);
3853 else if (info_mode == INFO_MODE_ELEMENTS)
3854 HandleInfoScreen_Elements(button);
3855 else if (info_mode == INFO_MODE_MUSIC)
3856 HandleInfoScreen_Music(button);
3857 else if (info_mode == INFO_MODE_CREDITS)
3858 HandleInfoScreen_Credits(button);
3859 else if (info_mode == INFO_MODE_PROGRAM)
3860 HandleInfoScreen_Program(button);
3861 else if (info_mode == INFO_MODE_VERSION)
3862 HandleInfoScreen_Version(button);
3863 else if (info_mode == INFO_MODE_LEVELSET)
3864 HandleInfoScreen_LevelSet(button);
3866 HandleInfoScreen_Main(mx, my, dx, dy, button);
3870 /* ========================================================================= */
3871 /* type name functions */
3872 /* ========================================================================= */
3874 void HandleTypeName(int newxpos, Key key)
3876 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3877 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3878 struct TextPosInfo *pos = mci->pos_input;
3879 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3880 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3881 static int xpos = 0;
3882 int font_nr = pos->font;
3883 int font_active_nr = FONT_ACTIVE(font_nr);
3884 int font_width = getFontWidth(font_active_nr);
3885 char key_char = getValidConfigValueChar(getCharFromKey(key));
3886 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3887 boolean is_active = TRUE;
3889 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3893 strcpy(last_player_name, setup.player_name);
3897 StartTextInput(startx, starty, pos->width, pos->height);
3899 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3901 setup.player_name[xpos] = key_char;
3902 setup.player_name[xpos + 1] = 0;
3906 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3910 setup.player_name[xpos] = 0;
3912 else if (key == KSYM_Return && xpos > 0)
3918 SetGameStatus(GAME_MODE_MAIN);
3920 else if (key == KSYM_Escape)
3922 strcpy(setup.player_name, last_player_name);
3926 SetGameStatus(GAME_MODE_MAIN);
3931 pos->width = (strlen(setup.player_name) + 1) * font_width;
3932 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3934 DrawText(startx, starty, setup.player_name, font_active_nr);
3935 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3939 pos->width = strlen(setup.player_name) * font_width;
3940 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3942 DrawText(startx, starty, setup.player_name, font_nr);
3949 /* ========================================================================= */
3950 /* tree menu functions */
3951 /* ========================================================================= */
3953 static void DrawChooseTree(TreeInfo **ti_ptr)
3955 int fade_mask = REDRAW_FIELD;
3957 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3958 fade_mask = REDRAW_ALL;
3960 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3962 SetGameStatus(GAME_MODE_MAIN);
3971 FreeScreenGadgets();
3972 CreateScreenGadgets();
3976 /* needed if different viewport properties defined for choosing level (set) */
3977 ChangeViewportPropertiesIfNeeded();
3979 if (game_status == GAME_MODE_LEVELNR)
3980 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3981 else if (game_status == GAME_MODE_LEVELS)
3982 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3986 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3988 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3989 MapScreenTreeGadgets(*ti_ptr);
3991 DrawMaskedBorder(fade_mask);
3996 static void drawChooseTreeList(int first_entry, int num_page_entries,
4000 char *title_string = NULL;
4001 int yoffset_sets = MENU_TITLE1_YPOS;
4002 int yoffset_setup = 16;
4003 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4004 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4006 title_string = ti->infotext;
4008 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4010 clearMenuListArea();
4012 for (i = 0; i < num_page_entries; i++)
4014 TreeInfo *node, *node_first;
4015 int entry_pos = first_entry + i;
4016 int xpos = MENU_SCREEN_START_XPOS;
4017 int ypos = MENU_SCREEN_START_YPOS + i;
4018 int startx = mSX + xpos * 32;
4019 int starty = mSY + ypos * 32;
4020 int font_nr = FONT_TEXT_1;
4021 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4022 int startx_text = startx + font_xoffset;
4023 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4024 int text_size = startx_scrollbar - startx_text;
4025 int max_buffer_len = text_size / getFontWidth(font_nr);
4026 char buffer[max_buffer_len + 1];
4028 node_first = getTreeInfoFirstGroupEntry(ti);
4029 node = getTreeInfoFromPos(node_first, entry_pos);
4031 strncpy(buffer, node->name, max_buffer_len);
4032 buffer[max_buffer_len] = '\0';
4034 DrawText(startx, starty, buffer, font_nr + node->color);
4036 if (node->parent_link)
4037 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4038 else if (node->level_group)
4039 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4041 initCursor(i, IMG_MENU_BUTTON);
4044 redraw_mask |= REDRAW_FIELD;
4047 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4049 TreeInfo *node, *node_first;
4050 int x, last_redraw_mask = redraw_mask;
4051 int ypos = MENU_TITLE2_YPOS;
4052 int font_nr = FONT_TITLE_2;
4054 if (ti->type == TREE_TYPE_LEVEL_NR)
4055 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4057 if (ti->type != TREE_TYPE_LEVEL_DIR)
4060 node_first = getTreeInfoFirstGroupEntry(ti);
4061 node = getTreeInfoFromPos(node_first, entry_pos);
4063 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4065 if (node->parent_link)
4066 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4067 node->node_parent->name);
4068 else if (node->level_group)
4069 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4071 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4072 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4073 node->levels, (node->levels > 1 ? "levels" : "level"),
4076 /* let BackToFront() redraw only what is needed */
4077 redraw_mask = last_redraw_mask;
4078 for (x = 0; x < SCR_FIELDX; x++)
4079 MarkTileDirty(x, 1);
4082 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4085 TreeInfo *ti = *ti_ptr;
4087 int y = ti->cl_cursor;
4088 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4089 int num_entries = numTreeInfoInGroup(ti);
4090 int num_page_entries;
4091 boolean position_set_by_scrollbar = (dx == 999);
4093 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4094 num_page_entries = num_entries;
4096 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4098 if (button == MB_MENU_INITIALIZE)
4100 int num_entries = numTreeInfoInGroup(ti);
4101 int entry_pos = posTreeInfo(ti);
4103 if (ti->cl_first == -1)
4105 /* only on initialization */
4106 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4107 ti->cl_cursor = entry_pos - ti->cl_first;
4109 else if (ti->cl_cursor >= num_page_entries ||
4110 (num_entries > num_page_entries &&
4111 num_entries - ti->cl_first < num_page_entries))
4113 /* only after change of list size (by custom graphic configuration) */
4114 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4115 ti->cl_cursor = entry_pos - ti->cl_first;
4118 if (position_set_by_scrollbar)
4121 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4124 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4125 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4126 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4130 else if (button == MB_MENU_LEAVE)
4134 PlaySound(SND_MENU_ITEM_SELECTING);
4136 if (ti->node_parent)
4138 *ti_ptr = ti->node_parent;
4139 DrawChooseTree(ti_ptr);
4141 else if (game_status == GAME_MODE_SETUP)
4143 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4144 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4145 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4147 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4148 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4149 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4150 execSetupGraphics();
4151 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4152 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4153 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4155 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4156 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4157 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4158 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4159 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4160 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4161 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4162 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4169 if (game_status == GAME_MODE_LEVELNR)
4171 int new_level_nr = atoi(level_number_current->identifier);
4173 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4176 SetGameStatus(GAME_MODE_MAIN);
4184 if (mx || my) /* mouse input */
4186 x = (mx - mSX) / 32;
4187 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4189 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4191 /* move cursor instead of scrolling when already at start/end of list */
4192 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4194 else if (dy == +1 * SCROLL_LINE &&
4195 ti->cl_first + num_page_entries == num_entries)
4198 /* handle scrolling screen one line or page */
4199 if (ti->cl_cursor + dy < 0 ||
4200 ti->cl_cursor + dy > num_page_entries - 1)
4202 boolean redraw = FALSE;
4204 if (ABS(dy) == SCROLL_PAGE)
4205 step = num_page_entries - 1;
4207 if (dy < 0 && ti->cl_first > 0)
4209 /* scroll page/line up */
4211 ti->cl_first -= step;
4212 if (ti->cl_first < 0)
4217 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4219 /* scroll page/line down */
4221 ti->cl_first += step;
4222 if (ti->cl_first + num_page_entries > num_entries)
4223 ti->cl_first = MAX(0, num_entries - num_page_entries);
4230 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4231 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4232 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4234 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4241 /* handle moving cursor one line */
4242 y = ti->cl_cursor + dy;
4247 TreeInfo *node_first, *node_cursor;
4248 int entry_pos = ti->cl_first + y;
4250 node_first = getTreeInfoFirstGroupEntry(ti);
4251 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4253 if (node_cursor->node_group)
4257 PlaySound(SND_MENU_ITEM_SELECTING);
4259 node_cursor->cl_first = ti->cl_first;
4260 node_cursor->cl_cursor = ti->cl_cursor;
4261 *ti_ptr = node_cursor->node_group;
4262 DrawChooseTree(ti_ptr);
4267 else if (dx == -1 && ti->node_parent)
4271 PlaySound(SND_MENU_ITEM_SELECTING);
4273 *ti_ptr = ti->node_parent;
4274 DrawChooseTree(ti_ptr);
4279 if (!anyScrollbarGadgetActive() &&
4280 IN_VIS_MENU(x, y) &&
4281 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4282 y >= 0 && y < num_page_entries)
4286 if (y != ti->cl_cursor)
4288 PlaySound(SND_MENU_ITEM_ACTIVATING);
4290 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4291 drawChooseTreeCursor(y, TRUE);
4292 drawChooseTreeInfo(ti->cl_first + y, ti);
4298 if (game_status == GAME_MODE_SETUP)
4300 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4301 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4302 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4304 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4305 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4306 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4307 execSetupGraphics();
4308 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4309 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4310 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4312 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4313 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4314 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4315 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4316 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4317 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4318 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4319 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4328 TreeInfo *node_first, *node_cursor;
4329 int entry_pos = ti->cl_first + y;
4331 PlaySound(SND_MENU_ITEM_SELECTING);
4333 node_first = getTreeInfoFirstGroupEntry(ti);
4334 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4336 if (node_cursor->node_group)
4340 node_cursor->cl_first = ti->cl_first;
4341 node_cursor->cl_cursor = ti->cl_cursor;
4342 *ti_ptr = node_cursor->node_group;
4343 DrawChooseTree(ti_ptr);
4345 else if (node_cursor->parent_link)
4349 *ti_ptr = node_cursor->node_parent;
4350 DrawChooseTree(ti_ptr);
4356 node_cursor->cl_first = ti->cl_first;
4357 node_cursor->cl_cursor = ti->cl_cursor;
4358 *ti_ptr = node_cursor;
4360 if (ti->type == TREE_TYPE_LEVEL_DIR)
4362 LoadLevelSetup_SeriesInfo();
4364 SaveLevelSetup_LastSeries();
4365 SaveLevelSetup_SeriesInfo();
4369 if (game_status == GAME_MODE_SETUP)
4371 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4372 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4373 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4375 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4376 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4377 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4378 execSetupGraphics();
4379 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4380 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4381 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4383 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4384 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4385 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4386 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4387 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4388 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4389 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4390 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4397 if (game_status == GAME_MODE_LEVELNR)
4399 int new_level_nr = atoi(level_number_current->identifier);
4401 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4404 SetGameStatus(GAME_MODE_MAIN);
4413 void DrawChooseLevelSet()
4415 FadeMenuSoundsAndMusic();
4417 DrawChooseTree(&leveldir_current);
4419 PlayMenuSoundsAndMusic();
4422 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4424 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4427 void DrawChooseLevelNr()
4431 FadeMenuSoundsAndMusic();
4433 if (level_number != NULL)
4435 freeTreeInfo(level_number);
4437 level_number = NULL;
4440 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4442 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4443 char identifier[32], name[32];
4446 /* temporarily load level info to get level name */
4447 LoadLevelInfoOnly(i);
4449 ti->node_top = &level_number;
4450 ti->sort_priority = 10000 + value;
4451 ti->color = (level.no_level_file ? FC_BLUE :
4452 LevelStats_getSolved(i) ? FC_GREEN :
4453 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4455 snprintf(identifier, sizeof(identifier), "%d", value);
4456 snprintf(name, sizeof(name), "%03d: %s", value,
4457 (level.no_level_file ? "(no file)" : level.name));
4459 setString(&ti->identifier, identifier);
4460 setString(&ti->name, name);
4461 setString(&ti->name_sorting, name);
4463 pushTreeInfo(&level_number, ti);
4466 /* sort level number values to start with lowest level number */
4467 sortTreeInfo(&level_number);
4469 /* set current level number to current level number */
4470 level_number_current =
4471 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4473 /* if that also fails, set current level number to first available level */
4474 if (level_number_current == NULL)
4475 level_number_current = level_number;
4477 DrawChooseTree(&level_number_current);
4479 PlayMenuSoundsAndMusic();
4482 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4484 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4487 void DrawHallOfFame(int highlight_position)
4489 int fade_mask = REDRAW_FIELD;
4491 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4492 fade_mask = REDRAW_ALL;
4495 FadeMenuSoundsAndMusic();
4497 /* (this is needed when called from GameEnd() after winning a game) */
4498 KeyboardAutoRepeatOn();
4500 /* (this is needed when called from GameEnd() after winning a game) */
4501 SetDrawDeactivationMask(REDRAW_NONE);
4502 SetDrawBackgroundMask(REDRAW_FIELD);
4504 if (highlight_position < 0)
4505 LoadScore(level_nr);
4507 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4509 FadeSetEnterScreen();
4513 /* needed if different viewport properties defined for scores */
4514 ChangeViewportPropertiesIfNeeded();
4516 PlayMenuSoundsAndMusic();
4518 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4520 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4522 DrawMaskedBorder(fade_mask);
4527 static void drawHallOfFameList(int first_entry, int highlight_position)
4531 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4534 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4535 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4536 "HighScores of Level %d", level_nr);
4538 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4540 int entry = first_entry + i;
4541 boolean active = (entry == highlight_position);
4542 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4543 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4544 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4545 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4546 int dxoff = getFontDrawOffsetX(font_nr1);
4547 int dx1 = 3 * getFontWidth(font_nr1);
4548 int dx2 = dx1 + getFontWidth(font_nr1);
4549 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4550 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4551 int sy = mSY + 64 + i * 32;
4553 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4554 DrawText(mSX + dx1, sy, ".", font_nr1);
4556 for (j = 0; j < num_dots; j++)
4557 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4559 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4560 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4562 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4565 redraw_mask |= REDRAW_FIELD;
4568 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4570 static int first_entry = 0;
4571 static int highlight_position = 0;
4572 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4574 if (button == MB_MENU_INITIALIZE)
4577 highlight_position = mx;
4578 drawHallOfFameList(first_entry, highlight_position);
4583 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4584 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4588 if (first_entry > 0)
4590 first_entry -= step;
4591 if (first_entry < 0)
4594 drawHallOfFameList(first_entry, highlight_position);
4599 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4601 first_entry += step;
4602 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4603 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4605 drawHallOfFameList(first_entry, highlight_position);
4608 else if (button == MB_MENU_LEAVE)
4610 PlaySound(SND_MENU_ITEM_SELECTING);
4612 FadeSound(SND_BACKGROUND_SCORES);
4614 SetGameStatus(GAME_MODE_MAIN);
4618 else if (button == MB_MENU_CHOICE)
4620 PlaySound(SND_MENU_ITEM_SELECTING);
4622 FadeSound(SND_BACKGROUND_SCORES);
4624 SetGameStatus(GAME_MODE_MAIN);
4629 if (game_status == GAME_MODE_SCORES)
4630 PlayMenuSoundIfLoop();
4634 /* ========================================================================= */
4635 /* setup screen functions */
4636 /* ========================================================================= */
4638 static struct TokenInfo *setup_info;
4639 static int num_setup_info; /* number of setup entries shown on screen */
4640 static int max_setup_info; /* total number of setup entries in list */
4642 static char *window_size_text;
4643 static char *scaling_type_text;
4644 static char *rendering_mode_text;
4645 static char *scroll_delay_text;
4646 static char *snapshot_mode_text;
4647 static char *game_speed_text;
4648 static char *graphics_set_name;
4649 static char *sounds_set_name;
4650 static char *music_set_name;
4651 static char *volume_simple_text;
4652 static char *volume_loops_text;
4653 static char *volume_music_text;
4654 static char *touch_controls_text;
4655 static char *move_distance_text;
4656 static char *drop_distance_text;
4657 static char *transparency_text;
4658 static char *grid_size_text[2][2];
4660 static void execSetupMain()
4662 setup_mode = SETUP_MODE_MAIN;
4667 static void execSetupGame_setGameSpeeds()
4669 if (game_speeds == NULL)
4673 for (i = 0; game_speeds_list[i].value != -1; i++)
4675 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4676 char identifier[32], name[32];
4677 int value = game_speeds_list[i].value;
4678 char *text = game_speeds_list[i].text;
4680 ti->node_top = &game_speeds;
4681 ti->sort_priority = 10000 - value;
4683 sprintf(identifier, "%d", value);
4684 sprintf(name, "%s", text);
4686 setString(&ti->identifier, identifier);
4687 setString(&ti->name, name);
4688 setString(&ti->name_sorting, name);
4689 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4691 pushTreeInfo(&game_speeds, ti);
4694 /* sort game speed values to start with slowest game speed */
4695 sortTreeInfo(&game_speeds);
4697 /* set current game speed to configured game speed value */
4698 game_speed_current =
4699 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4701 /* if that fails, set current game speed to reliable default value */
4702 if (game_speed_current == NULL)
4703 game_speed_current =
4704 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4706 /* if that also fails, set current game speed to first available speed */
4707 if (game_speed_current == NULL)
4708 game_speed_current = game_speeds;
4711 setup.game_frame_delay = atoi(game_speed_current->identifier);
4713 /* needed for displaying game speed text instead of identifier */
4714 game_speed_text = game_speed_current->name;
4717 static void execSetupGame_setScrollDelays()
4719 if (scroll_delays == NULL)
4723 for (i = 0; scroll_delays_list[i].value != -1; i++)
4725 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4726 char identifier[32], name[32];
4727 int value = scroll_delays_list[i].value;
4728 char *text = scroll_delays_list[i].text;
4730 ti->node_top = &scroll_delays;
4731 ti->sort_priority = value;
4733 sprintf(identifier, "%d", value);
4734 sprintf(name, "%s", text);
4736 setString(&ti->identifier, identifier);
4737 setString(&ti->name, name);
4738 setString(&ti->name_sorting, name);
4739 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4741 pushTreeInfo(&scroll_delays, ti);
4744 /* sort scroll delay values to start with lowest scroll delay value */
4745 sortTreeInfo(&scroll_delays);
4747 /* set current scroll delay value to configured scroll delay value */
4748 scroll_delay_current =
4749 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4751 /* if that fails, set current scroll delay to reliable default value */
4752 if (scroll_delay_current == NULL)
4753 scroll_delay_current =
4754 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4756 /* if that also fails, set current scroll delay to first available value */
4757 if (scroll_delay_current == NULL)
4758 scroll_delay_current = scroll_delays;
4761 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4763 /* needed for displaying scroll delay text instead of identifier */
4764 scroll_delay_text = scroll_delay_current->name;
4767 static void execSetupGame_setSnapshotModes()
4769 if (snapshot_modes == NULL)
4773 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4775 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4776 char identifier[32], name[32];
4777 char *value = snapshot_modes_list[i].value;
4778 char *text = snapshot_modes_list[i].text;
4780 ti->node_top = &snapshot_modes;
4781 ti->sort_priority = i;
4783 sprintf(identifier, "%s", value);
4784 sprintf(name, "%s", text);
4786 setString(&ti->identifier, identifier);
4787 setString(&ti->name, name);
4788 setString(&ti->name_sorting, name);
4789 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4791 pushTreeInfo(&snapshot_modes, ti);
4794 /* sort snapshot mode values to start with lowest snapshot mode value */
4795 sortTreeInfo(&snapshot_modes);
4797 /* set current snapshot mode value to configured snapshot mode value */
4798 snapshot_mode_current =
4799 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4801 /* if that fails, set current snapshot mode to reliable default value */
4802 if (snapshot_mode_current == NULL)
4803 snapshot_mode_current =
4804 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4806 /* if that also fails, set current snapshot mode to first available value */
4807 if (snapshot_mode_current == NULL)
4808 snapshot_mode_current = snapshot_modes;
4811 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4813 /* needed for displaying snapshot mode text instead of identifier */
4814 snapshot_mode_text = snapshot_mode_current->name;
4817 static void execSetupGame()
4819 execSetupGame_setGameSpeeds();
4820 execSetupGame_setScrollDelays();
4821 execSetupGame_setSnapshotModes();
4823 setup_mode = SETUP_MODE_GAME;
4828 static void execSetupChooseGameSpeed()
4830 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4835 static void execSetupChooseScrollDelay()
4837 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4842 static void execSetupChooseSnapshotMode()
4844 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4849 static void execSetupEditor()
4851 setup_mode = SETUP_MODE_EDITOR;
4856 static void execSetupGraphics_setWindowSizes(boolean update_list)
4858 if (window_sizes != NULL && update_list)
4860 freeTreeInfo(window_sizes);
4862 window_sizes = NULL;
4865 if (window_sizes == NULL)
4867 boolean current_window_size_found = FALSE;
4870 for (i = 0; window_sizes_list[i].value != -1; i++)
4872 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4873 char identifier[32], name[32];
4874 int value = window_sizes_list[i].value;
4875 char *text = window_sizes_list[i].text;
4877 ti->node_top = &window_sizes;
4878 ti->sort_priority = value;
4880 sprintf(identifier, "%d", value);
4881 sprintf(name, "%s", text);
4883 setString(&ti->identifier, identifier);
4884 setString(&ti->name, name);
4885 setString(&ti->name_sorting, name);
4886 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4888 pushTreeInfo(&window_sizes, ti);
4890 if (value == setup.window_scaling_percent)
4891 current_window_size_found = TRUE;
4894 if (!current_window_size_found)
4896 // add entry for non-preset window scaling value
4898 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4899 char identifier[32], name[32];
4900 int value = setup.window_scaling_percent;
4902 ti->node_top = &window_sizes;
4903 ti->sort_priority = value;
4905 sprintf(identifier, "%d", value);
4906 sprintf(name, "%d %% (Current)", value);
4908 setString(&ti->identifier, identifier);
4909 setString(&ti->name, name);
4910 setString(&ti->name_sorting, name);
4911 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4913 pushTreeInfo(&window_sizes, ti);
4916 /* sort window size values to start with lowest window size value */
4917 sortTreeInfo(&window_sizes);
4919 /* set current window size value to configured window size value */
4920 window_size_current =
4921 getTreeInfoFromIdentifier(window_sizes,
4922 i_to_a(setup.window_scaling_percent));
4924 /* if that fails, set current window size to reliable default value */
4925 if (window_size_current == NULL)
4926 window_size_current =
4927 getTreeInfoFromIdentifier(window_sizes,
4928 i_to_a(STD_WINDOW_SCALING_PERCENT));
4930 /* if that also fails, set current window size to first available value */
4931 if (window_size_current == NULL)
4932 window_size_current = window_sizes;
4935 setup.window_scaling_percent = atoi(window_size_current->identifier);
4937 /* needed for displaying window size text instead of identifier */
4938 window_size_text = window_size_current->name;
4941 static void execSetupGraphics_setScalingTypes()
4943 if (scaling_types == NULL)
4947 for (i = 0; scaling_types_list[i].value != NULL; i++)
4949 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4950 char identifier[32], name[32];
4951 char *value = scaling_types_list[i].value;
4952 char *text = scaling_types_list[i].text;
4954 ti->node_top = &scaling_types;
4955 ti->sort_priority = i;
4957 sprintf(identifier, "%s", value);
4958 sprintf(name, "%s", text);
4960 setString(&ti->identifier, identifier);
4961 setString(&ti->name, name);
4962 setString(&ti->name_sorting, name);
4963 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4965 pushTreeInfo(&scaling_types, ti);
4968 /* sort scaling type values to start with lowest scaling type value */
4969 sortTreeInfo(&scaling_types);
4971 /* set current scaling type value to configured scaling type value */
4972 scaling_type_current =
4973 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4975 /* if that fails, set current scaling type to reliable default value */
4976 if (scaling_type_current == NULL)
4977 scaling_type_current =
4978 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4980 /* if that also fails, set current scaling type to first available value */
4981 if (scaling_type_current == NULL)
4982 scaling_type_current = scaling_types;
4985 setup.window_scaling_quality = scaling_type_current->identifier;
4987 /* needed for displaying scaling type text instead of identifier */
4988 scaling_type_text = scaling_type_current->name;
4991 static void execSetupGraphics_setRenderingModes()
4993 if (rendering_modes == NULL)
4997 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4999 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5000 char identifier[32], name[32];
5001 char *value = rendering_modes_list[i].value;
5002 char *text = rendering_modes_list[i].text;
5004 ti->node_top = &rendering_modes;
5005 ti->sort_priority = i;
5007 sprintf(identifier, "%s", value);
5008 sprintf(name, "%s", text);
5010 setString(&ti->identifier, identifier);
5011 setString(&ti->name, name);
5012 setString(&ti->name_sorting, name);
5013 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5015 pushTreeInfo(&rendering_modes, ti);
5018 /* sort rendering mode values to start with lowest rendering mode value */
5019 sortTreeInfo(&rendering_modes);
5021 /* set current rendering mode value to configured rendering mode value */
5022 rendering_mode_current =
5023 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5025 /* if that fails, set current rendering mode to reliable default value */
5026 if (rendering_mode_current == NULL)
5027 rendering_mode_current =
5028 getTreeInfoFromIdentifier(rendering_modes,
5029 STR_SPECIAL_RENDERING_DEFAULT);
5031 /* if that also fails, set current rendering mode to first available one */
5032 if (rendering_mode_current == NULL)
5033 rendering_mode_current = rendering_modes;
5036 setup.screen_rendering_mode = rendering_mode_current->identifier;
5038 /* needed for displaying rendering mode text instead of identifier */
5039 rendering_mode_text = rendering_mode_current->name;
5042 static void execSetupGraphics()
5044 // update "setup.window_scaling_percent" from list selection
5045 // (in this case, window scaling was changed on setup screen)
5046 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5047 execSetupGraphics_setWindowSizes(FALSE);
5049 // update list selection from "setup.window_scaling_percent"
5050 // (window scaling may have changed by resizing the window)
5051 execSetupGraphics_setWindowSizes(TRUE);
5053 execSetupGraphics_setScalingTypes();
5054 execSetupGraphics_setRenderingModes();
5056 setup_mode = SETUP_MODE_GRAPHICS;
5060 #if defined(TARGET_SDL2)
5061 // window scaling may have changed at this point
5062 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5064 // window scaling quality may have changed at this point
5065 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5066 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5068 // screen rendering mode may have changed at this point
5069 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5073 static void execSetupChooseWindowSize()
5075 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5080 static void execSetupChooseScalingType()
5082 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5087 static void execSetupChooseRenderingMode()
5089 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5094 static void execSetupChooseVolumeSimple()
5096 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5101 static void execSetupChooseVolumeLoops()
5103 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5108 static void execSetupChooseVolumeMusic()
5110 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5115 static void execSetupSound()
5117 if (volumes_simple == NULL)
5119 boolean current_volume_simple_found = FALSE;
5122 for (i = 0; volumes_list[i].value != -1; i++)
5124 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5125 char identifier[32], name[32];
5126 int value = volumes_list[i].value;
5127 char *text = volumes_list[i].text;
5129 ti->node_top = &volumes_simple;
5130 ti->sort_priority = value;
5132 sprintf(identifier, "%d", value);
5133 sprintf(name, "%s", text);
5135 setString(&ti->identifier, identifier);
5136 setString(&ti->name, name);
5137 setString(&ti->name_sorting, name);
5138 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5140 pushTreeInfo(&volumes_simple, ti);
5142 if (value == setup.volume_simple)
5143 current_volume_simple_found = TRUE;
5146 if (!current_volume_simple_found)
5148 // add entry for non-preset volume value
5150 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5151 char identifier[32], name[32];
5152 int value = setup.volume_simple;
5154 ti->node_top = &volumes_simple;
5155 ti->sort_priority = value;
5157 sprintf(identifier, "%d", value);
5158 sprintf(name, "%d %% (Current)", value);
5160 setString(&ti->identifier, identifier);
5161 setString(&ti->name, name);
5162 setString(&ti->name_sorting, name);
5163 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5165 pushTreeInfo(&volumes_simple, ti);
5168 /* sort volume values to start with lowest volume value */
5169 sortTreeInfo(&volumes_simple);
5171 /* set current volume value to configured volume value */
5172 volume_simple_current =
5173 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5175 /* if that fails, set current volume to reliable default value */
5176 if (volume_simple_current == NULL)
5177 volume_simple_current =
5178 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5180 /* if that also fails, set current volume to first available value */
5181 if (volume_simple_current == NULL)
5182 volume_simple_current = volumes_simple;
5185 if (volumes_loops == NULL)
5187 boolean current_volume_loops_found = FALSE;
5190 for (i = 0; volumes_list[i].value != -1; i++)
5192 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5193 char identifier[32], name[32];
5194 int value = volumes_list[i].value;
5195 char *text = volumes_list[i].text;
5197 ti->node_top = &volumes_loops;
5198 ti->sort_priority = value;
5200 sprintf(identifier, "%d", value);
5201 sprintf(name, "%s", text);
5203 setString(&ti->identifier, identifier);
5204 setString(&ti->name, name);
5205 setString(&ti->name_sorting, name);
5206 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5208 pushTreeInfo(&volumes_loops, ti);
5210 if (value == setup.volume_loops)
5211 current_volume_loops_found = TRUE;
5214 if (!current_volume_loops_found)
5216 // add entry for non-preset volume value
5218 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5219 char identifier[32], name[32];
5220 int value = setup.volume_loops;
5222 ti->node_top = &volumes_loops;
5223 ti->sort_priority = value;
5225 sprintf(identifier, "%d", value);
5226 sprintf(name, "%d %% (Current)", value);
5228 setString(&ti->identifier, identifier);
5229 setString(&ti->name, name);
5230 setString(&ti->name_sorting, name);
5231 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5233 pushTreeInfo(&volumes_loops, ti);
5236 /* sort volume values to start with lowest volume value */
5237 sortTreeInfo(&volumes_loops);
5239 /* set current volume value to configured volume value */
5240 volume_loops_current =
5241 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5243 /* if that fails, set current volume to reliable default value */
5244 if (volume_loops_current == NULL)
5245 volume_loops_current =
5246 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5248 /* if that also fails, set current volume to first available value */
5249 if (volume_loops_current == NULL)
5250 volume_loops_current = volumes_loops;
5253 if (volumes_music == NULL)
5255 boolean current_volume_music_found = FALSE;
5258 for (i = 0; volumes_list[i].value != -1; i++)
5260 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5261 char identifier[32], name[32];
5262 int value = volumes_list[i].value;
5263 char *text = volumes_list[i].text;
5265 ti->node_top = &volumes_music;
5266 ti->sort_priority = value;
5268 sprintf(identifier, "%d", value);
5269 sprintf(name, "%s", text);
5271 setString(&ti->identifier, identifier);
5272 setString(&ti->name, name);
5273 setString(&ti->name_sorting, name);
5274 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5276 pushTreeInfo(&volumes_music, ti);
5278 if (value == setup.volume_music)
5279 current_volume_music_found = TRUE;
5282 if (!current_volume_music_found)
5284 // add entry for non-preset volume value
5286 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5287 char identifier[32], name[32];
5288 int value = setup.volume_music;
5290 ti->node_top = &volumes_music;
5291 ti->sort_priority = value;
5293 sprintf(identifier, "%d", value);
5294 sprintf(name, "%d %% (Current)", value);
5296 setString(&ti->identifier, identifier);
5297 setString(&ti->name, name);
5298 setString(&ti->name_sorting, name);
5299 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5301 pushTreeInfo(&volumes_music, ti);
5304 /* sort volume values to start with lowest volume value */
5305 sortTreeInfo(&volumes_music);
5307 /* set current volume value to configured volume value */
5308 volume_music_current =
5309 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5311 /* if that fails, set current volume to reliable default value */
5312 if (volume_music_current == NULL)
5313 volume_music_current =
5314 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5316 /* if that also fails, set current volume to first available value */
5317 if (volume_music_current == NULL)
5318 volume_music_current = volumes_music;
5321 setup.volume_simple = atoi(volume_simple_current->identifier);
5322 setup.volume_loops = atoi(volume_loops_current->identifier);
5323 setup.volume_music = atoi(volume_music_current->identifier);
5325 /* needed for displaying volume text instead of identifier */
5326 volume_simple_text = volume_simple_current->name;
5327 volume_loops_text = volume_loops_current->name;
5328 volume_music_text = volume_music_current->name;
5330 setup_mode = SETUP_MODE_SOUND;
5335 static void execSetupChooseTouchControls()
5337 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5342 static void execSetupChooseMoveDistance()
5344 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5349 static void execSetupChooseDropDistance()
5351 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5356 static void execSetupChooseTransparency()
5358 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5363 static void execSetupChooseGridXSize_0()
5365 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5370 static void execSetupChooseGridYSize_0()
5372 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5377 static void execSetupChooseGridXSize_1()
5379 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5384 static void execSetupChooseGridYSize_1()
5386 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5391 static void execSetupConfigureVirtualButtons()
5393 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5395 ConfigureVirtualButtons();
5397 setup_mode = SETUP_MODE_TOUCH;
5402 static void execSetupTouch()
5406 if (touch_controls == NULL)
5408 for (i = 0; touch_controls_list[i].value != NULL; i++)
5410 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5411 char identifier[32], name[32];
5412 char *value = touch_controls_list[i].value;
5413 char *text = touch_controls_list[i].text;
5415 ti->node_top = &touch_controls;
5416 ti->sort_priority = i;
5418 sprintf(identifier, "%s", value);
5419 sprintf(name, "%s", text);
5421 setString(&ti->identifier, identifier);
5422 setString(&ti->name, name);
5423 setString(&ti->name_sorting, name);
5424 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5426 pushTreeInfo(&touch_controls, ti);
5429 /* sort touch control values to start with lowest touch control value */
5430 sortTreeInfo(&touch_controls);
5432 /* set current touch control value to configured touch control value */
5433 touch_control_current =
5434 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5436 /* if that fails, set current touch control to reliable default value */
5437 if (touch_control_current == NULL)
5438 touch_control_current =
5439 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5441 /* if that also fails, set current touch control to first available value */
5442 if (touch_control_current == NULL)
5443 touch_control_current = touch_controls;
5446 if (move_distances == NULL)
5448 for (i = 0; distances_list[i].value != -1; i++)
5450 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5451 char identifier[32], name[32];
5452 int value = distances_list[i].value;
5453 char *text = distances_list[i].text;
5455 ti->node_top = &move_distances;
5456 ti->sort_priority = value;
5458 sprintf(identifier, "%d", value);
5459 sprintf(name, "%s", text);
5461 setString(&ti->identifier, identifier);
5462 setString(&ti->name, name);
5463 setString(&ti->name_sorting, name);
5464 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5466 pushTreeInfo(&move_distances, ti);
5469 /* sort distance values to start with lowest distance value */
5470 sortTreeInfo(&move_distances);
5472 /* set current distance value to configured distance value */
5473 move_distance_current =
5474 getTreeInfoFromIdentifier(move_distances,
5475 i_to_a(setup.touch.move_distance));
5477 /* if that fails, set current distance to reliable default value */
5478 if (move_distance_current == NULL)
5479 move_distance_current =
5480 getTreeInfoFromIdentifier(move_distances,
5481 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5483 /* if that also fails, set current distance to first available value */
5484 if (move_distance_current == NULL)
5485 move_distance_current = move_distances;
5488 if (drop_distances == NULL)
5490 for (i = 0; distances_list[i].value != -1; i++)
5492 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5493 char identifier[32], name[32];
5494 int value = distances_list[i].value;
5495 char *text = distances_list[i].text;
5497 ti->node_top = &drop_distances;
5498 ti->sort_priority = value;
5500 sprintf(identifier, "%d", value);
5501 sprintf(name, "%s", text);
5503 setString(&ti->identifier, identifier);
5504 setString(&ti->name, name);
5505 setString(&ti->name_sorting, name);
5506 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5508 pushTreeInfo(&drop_distances, ti);
5511 /* sort distance values to start with lowest distance value */
5512 sortTreeInfo(&drop_distances);
5514 /* set current distance value to configured distance value */
5515 drop_distance_current =
5516 getTreeInfoFromIdentifier(drop_distances,
5517 i_to_a(setup.touch.drop_distance));
5519 /* if that fails, set current distance to reliable default value */
5520 if (drop_distance_current == NULL)
5521 drop_distance_current =
5522 getTreeInfoFromIdentifier(drop_distances,
5523 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5525 /* if that also fails, set current distance to first available value */
5526 if (drop_distance_current == NULL)
5527 drop_distance_current = drop_distances;
5530 if (transparencies == NULL)
5532 for (i = 0; transparencies_list[i].value != -1; i++)
5534 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5535 char identifier[32], name[32];
5536 int value = transparencies_list[i].value;
5537 char *text = transparencies_list[i].text;
5539 ti->node_top = &transparencies;
5540 ti->sort_priority = value;
5542 sprintf(identifier, "%d", value);
5543 sprintf(name, "%s", text);
5545 setString(&ti->identifier, identifier);
5546 setString(&ti->name, name);
5547 setString(&ti->name_sorting, name);
5548 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5550 pushTreeInfo(&transparencies, ti);
5553 /* sort transparency values to start with lowest transparency value */
5554 sortTreeInfo(&transparencies);
5556 /* set current transparency value to configured transparency value */
5557 transparency_current =
5558 getTreeInfoFromIdentifier(transparencies,
5559 i_to_a(setup.touch.transparency));
5561 /* if that fails, set current transparency to reliable default value */
5562 if (transparency_current == NULL)
5563 transparency_current =
5564 getTreeInfoFromIdentifier(transparencies,
5565 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5567 /* if that also fails, set current transparency to first available value */
5568 if (transparency_current == NULL)
5569 transparency_current = transparencies;
5572 for (i = 0; i < 2; i++)
5574 for (j = 0; j < 2; j++)
5576 if (grid_sizes[i][j] == NULL)
5578 for (k = 0; grid_sizes_list[k].value != -1; k++)
5580 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5581 char identifier[32], name[32];
5582 int value = grid_sizes_list[k].value;
5583 char *text = grid_sizes_list[k].text;
5585 ti->node_top = &grid_sizes[i][j];
5586 ti->sort_priority = value;
5588 sprintf(identifier, "%d", value);
5589 sprintf(name, "%s", text);
5591 setString(&ti->identifier, identifier);
5592 setString(&ti->name, name);
5593 setString(&ti->name_sorting, name);
5594 setString(&ti->infotext,
5597 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5598 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5600 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5601 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5603 pushTreeInfo(&grid_sizes[i][j], ti);
5606 /* sort grid size values to start with lowest grid size value */
5607 sortTreeInfo(&grid_sizes[i][j]);
5609 /* set current grid size value to configured grid size value */
5610 grid_size_current[i][j] =
5611 getTreeInfoFromIdentifier(grid_sizes[i][j],
5613 setup.touch.grid_xsize[i] :
5614 setup.touch.grid_ysize[i]));
5616 /* if that fails, set current grid size to reliable default value */
5617 if (grid_size_current[i][j] == NULL)
5618 grid_size_current[i][j] =
5619 getTreeInfoFromIdentifier(grid_sizes[i][j],
5621 DEFAULT_GRID_XSIZE(i) :
5622 DEFAULT_GRID_YSIZE(i)));
5624 /* if that also fails, set current grid size to first available value */
5625 if (grid_size_current[i][j] == NULL)
5626 grid_size_current[i][j] = grid_sizes[i][j];
5631 setup.touch.control_type = touch_control_current->identifier;
5632 setup.touch.move_distance = atoi(move_distance_current->identifier);
5633 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5634 setup.touch.transparency = atoi(transparency_current->identifier);
5636 for (i = 0; i < 2; i++)
5638 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5639 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5641 if (i == GRID_ACTIVE_NR())
5643 overlay.grid_xsize = setup.touch.grid_xsize[i];
5644 overlay.grid_ysize = setup.touch.grid_ysize[i];
5648 /* needed for displaying value text instead of identifier */
5649 touch_controls_text = touch_control_current->name;
5650 move_distance_text = move_distance_current->name;
5651 drop_distance_text = drop_distance_current->name;
5652 transparency_text = transparency_current->name;
5654 for (i = 0; i < 2; i++)
5655 for (j = 0; j < 2; j++)
5656 grid_size_text[i][j] = grid_size_current[i][j]->name;
5658 setup_mode = SETUP_MODE_TOUCH;
5663 static void execSetupArtwork()
5666 printf("::: '%s', '%s', '%s'\n",
5667 artwork.gfx_current->subdir,
5668 artwork.gfx_current->fullpath,
5669 artwork.gfx_current->basepath);
5672 setup.graphics_set = artwork.gfx_current->identifier;
5673 setup.sounds_set = artwork.snd_current->identifier;
5674 setup.music_set = artwork.mus_current->identifier;
5676 /* needed if last screen (setup choice) changed graphics, sounds or music */
5677 ReloadCustomArtwork(0);
5679 /* needed for displaying artwork name instead of artwork identifier */
5680 graphics_set_name = artwork.gfx_current->name;
5681 sounds_set_name = artwork.snd_current->name;
5682 music_set_name = artwork.mus_current->name;
5684 setup_mode = SETUP_MODE_ARTWORK;
5689 static void execSetupChooseGraphics()
5691 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5696 static void execSetupChooseSounds()
5698 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5703 static void execSetupChooseMusic()
5705 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5710 static void execSetupInput()
5712 setup_mode = SETUP_MODE_INPUT;
5717 static void execSetupShortcuts()
5719 setup_mode = SETUP_MODE_SHORTCUTS;
5724 static void execSetupShortcuts1()
5726 setup_mode = SETUP_MODE_SHORTCUTS_1;
5731 static void execSetupShortcuts2()
5733 setup_mode = SETUP_MODE_SHORTCUTS_2;
5738 static void execSetupShortcuts3()
5740 setup_mode = SETUP_MODE_SHORTCUTS_3;
5745 static void execSetupShortcuts4()
5747 setup_mode = SETUP_MODE_SHORTCUTS_4;
5752 static void execSetupShortcuts5()
5754 setup_mode = SETUP_MODE_SHORTCUTS_5;
5759 static void execExitSetup()
5761 SetGameStatus(GAME_MODE_MAIN);
5766 static void execSaveAndExitSetup()
5775 void *related_value;
5776 } hide_related_entry_list[] =
5778 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5779 { &setup.game_frame_delay, &game_speed_text },
5781 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5782 { &setup.scroll_delay_value, &scroll_delay_text },
5784 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5785 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5787 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5788 { &setup.window_scaling_percent, &window_size_text },
5790 { &setup.window_scaling_quality, execSetupChooseScalingType },
5791 { &setup.window_scaling_quality, &scaling_type_text },
5793 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5794 { &setup.screen_rendering_mode, &rendering_mode_text },
5796 { &setup.graphics_set, execSetupChooseGraphics },
5797 { &setup.graphics_set, &graphics_set_name },
5799 { &setup.sounds_set, execSetupChooseSounds },
5800 { &setup.sounds_set, &sounds_set_name },
5802 { &setup.music_set, execSetupChooseMusic },
5803 { &setup.music_set, &music_set_name },
5805 { &setup.volume_simple, execSetupChooseVolumeSimple },
5806 { &setup.volume_simple, &volume_simple_text },
5808 { &setup.volume_loops, execSetupChooseVolumeLoops },
5809 { &setup.volume_loops, &volume_loops_text },
5811 { &setup.volume_music, execSetupChooseVolumeMusic },
5812 { &setup.volume_music, &volume_music_text },
5814 { &setup.touch.control_type, execSetupChooseTouchControls },
5815 { &setup.touch.control_type, &touch_controls_text },
5817 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5818 { &setup.touch.move_distance, &move_distance_text },
5820 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5821 { &setup.touch.drop_distance, &drop_distance_text },
5823 { &setup.touch.transparency, execSetupChooseTransparency },
5824 { &setup.touch.transparency, &transparency_text },
5826 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5827 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5829 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5830 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5832 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5833 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5835 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5836 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5841 void setHideRelatedSetupEntries()
5845 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5846 if (hideSetupEntry(hide_related_entry_list[i].value))
5847 setHideSetupEntry(hide_related_entry_list[i].related_value);
5850 static struct TokenInfo setup_info_main[] =
5852 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5853 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5854 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5855 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5856 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5857 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5858 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5859 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5860 { TYPE_EMPTY, NULL, "" },
5861 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5862 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5867 static struct TokenInfo setup_info_game[] =
5869 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5870 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5871 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5872 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5873 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5874 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5875 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5876 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5877 { TYPE_STRING, &game_speed_text, "" },
5879 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5880 { TYPE_STRING, &scroll_delay_text, "" },
5882 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5883 { TYPE_STRING, &snapshot_mode_text, "" },
5884 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5885 { TYPE_EMPTY, NULL, "" },
5886 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5891 static struct TokenInfo setup_info_editor[] =
5894 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5895 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5896 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5897 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5898 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5899 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5900 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5901 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5902 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5903 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5905 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5906 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5908 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5910 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5911 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5912 { TYPE_EMPTY, NULL, "" },
5914 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5915 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5916 { TYPE_EMPTY, NULL, "" },
5918 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5919 { TYPE_EMPTY, NULL, "" },
5920 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5925 static struct TokenInfo setup_info_graphics[] =
5927 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5928 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5929 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5930 { TYPE_STRING, &window_size_text, "" },
5931 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5932 { TYPE_STRING, &scaling_type_text, "" },
5933 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5934 { TYPE_STRING, &rendering_mode_text, "" },
5937 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5938 { TYPE_STRING, &scroll_delay_text, "" },
5940 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5941 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5942 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5943 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5944 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5945 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5946 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5947 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5948 { TYPE_EMPTY, NULL, "" },
5949 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5954 static struct TokenInfo setup_info_sound[] =
5956 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5957 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5958 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5959 { TYPE_EMPTY, NULL, "" },
5960 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5961 { TYPE_STRING, &volume_simple_text, "" },
5962 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5963 { TYPE_STRING, &volume_loops_text, "" },
5964 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5965 { TYPE_STRING, &volume_music_text, "" },
5966 { TYPE_EMPTY, NULL, "" },
5967 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5972 static struct TokenInfo setup_info_artwork[] =
5974 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5975 { TYPE_STRING, &graphics_set_name, "" },
5976 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5977 { TYPE_STRING, &sounds_set_name, "" },
5978 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5979 { TYPE_STRING, &music_set_name, "" },
5980 { TYPE_EMPTY, NULL, "" },
5981 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5982 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5983 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5984 { TYPE_EMPTY, NULL, "" },
5985 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5990 static struct TokenInfo setup_info_input[] =
5992 { TYPE_SWITCH, NULL, "Player:" },
5993 { TYPE_SWITCH, NULL, "Device:" },
5994 { TYPE_SWITCH, NULL, "" },
5995 { TYPE_SKIPPABLE, NULL, "" },
5996 { TYPE_EMPTY, NULL, "" },
5997 { TYPE_EMPTY, NULL, "" },
5998 { TYPE_EMPTY, NULL, "" },
5999 { TYPE_EMPTY, NULL, "" },
6000 { TYPE_EMPTY, NULL, "" },
6001 { TYPE_EMPTY, NULL, "" },
6002 { TYPE_EMPTY, NULL, "" },
6003 { TYPE_EMPTY, NULL, "" },
6004 { TYPE_SKIPPABLE, NULL, "" },
6005 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6010 static struct TokenInfo setup_info_touch[] =
6012 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6013 { TYPE_STRING, &touch_controls_text, "" },
6014 { TYPE_EMPTY, NULL, "" },
6015 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6020 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6022 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6023 { TYPE_STRING, &touch_controls_text, "" },
6024 { TYPE_EMPTY, NULL, "" },
6025 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6026 { TYPE_STRING, &grid_size_text[0][0], "" },
6027 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6028 { TYPE_STRING, &grid_size_text[0][1], "" },
6029 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Transparency:" },
6030 { TYPE_STRING, &transparency_text, "" },
6031 { TYPE_EMPTY, NULL, "" },
6032 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6033 { TYPE_EMPTY, NULL, "" },
6034 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6039 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6041 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6042 { TYPE_STRING, &touch_controls_text, "" },
6043 { TYPE_EMPTY, NULL, "" },
6044 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6045 { TYPE_STRING, &grid_size_text[1][0], "" },
6046 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6047 { TYPE_STRING, &grid_size_text[1][1], "" },
6048 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Transparency:" },
6049 { TYPE_STRING, &transparency_text, "" },
6050 { TYPE_EMPTY, NULL, "" },
6051 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6052 { TYPE_EMPTY, NULL, "" },
6053 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6058 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6060 setup_info_touch_virtual_buttons_0,
6061 setup_info_touch_virtual_buttons_1
6064 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6066 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6067 { TYPE_STRING, &touch_controls_text, "" },
6068 { TYPE_EMPTY, NULL, "" },
6069 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6070 { TYPE_STRING, &move_distance_text, "" },
6071 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6072 { TYPE_STRING, &drop_distance_text, "" },
6073 { TYPE_EMPTY, NULL, "" },
6074 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6079 static struct TokenInfo setup_info_shortcuts[] =
6081 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6082 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6083 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6084 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6085 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6086 { TYPE_EMPTY, NULL, "" },
6087 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6092 static struct TokenInfo setup_info_shortcuts_1[] =
6094 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6095 { TYPE_KEY, &setup.shortcut.save_game, "" },
6096 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6097 { TYPE_KEY, &setup.shortcut.load_game, "" },
6098 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6099 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6100 { TYPE_EMPTY, NULL, "" },
6101 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6102 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6103 { TYPE_EMPTY, NULL, "" },
6104 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6109 static struct TokenInfo setup_info_shortcuts_2[] =
6111 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6112 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6113 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6114 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6115 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6116 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6117 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6118 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6119 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6120 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6121 { TYPE_EMPTY, NULL, "" },
6122 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6127 static struct TokenInfo setup_info_shortcuts_3[] =
6129 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6130 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6131 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6132 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6133 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6134 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6135 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6136 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6137 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6138 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6139 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6140 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6141 { TYPE_EMPTY, NULL, "" },
6142 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6147 static struct TokenInfo setup_info_shortcuts_4[] =
6149 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6150 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6151 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6152 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6153 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6154 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6155 { TYPE_EMPTY, NULL, "" },
6156 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6161 static struct TokenInfo setup_info_shortcuts_5[] =
6163 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6164 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6165 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6166 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6167 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6168 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6169 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6170 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6171 { TYPE_EMPTY, NULL, "" },
6172 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6177 static Key getSetupKey()
6179 Key key = KSYM_UNDEFINED;
6180 boolean got_key_event = FALSE;
6182 while (!got_key_event)
6186 if (NextValidEvent(&event))
6190 case EVENT_KEYPRESS:
6192 key = GetEventKey((KeyEvent *)&event, TRUE);
6194 /* press 'Escape' or 'Enter' to keep the existing key binding */
6195 if (key == KSYM_Escape || key == KSYM_Return)
6196 key = KSYM_UNDEFINED; /* keep old value */
6198 got_key_event = TRUE;
6202 case EVENT_KEYRELEASE:
6203 key_joystick_mapping = 0;
6207 HandleOtherEvents(&event);
6218 static int getSetupValueFont(int type, void *value)
6220 if (type & TYPE_GHOSTED)
6221 return FONT_OPTION_OFF;
6222 else if (type & TYPE_KEY)
6223 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6224 else if (type & TYPE_STRING)
6225 return FONT_VALUE_2;
6226 else if (type & TYPE_ECS_AGA)
6227 return FONT_VALUE_1;
6228 else if (type & TYPE_BOOLEAN_STYLE)
6229 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6230 else if (type & TYPE_YES_NO_AUTO)
6231 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6232 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6234 return FONT_VALUE_1;
6237 static int getSetupValueFontNarrow(int type, int font_nr)
6239 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6240 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6241 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6245 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6247 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6248 struct TokenInfo *si = &setup_info[si_pos];
6249 boolean font_draw_xoffset_modified = FALSE;
6250 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6251 int font_draw_xoffset_old = -1;
6252 int xoffset = (scrollbar_needed ? -1 : 0);
6253 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6254 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6255 int xpos = menu_screen_value_xpos;
6256 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6257 int startx = mSX + xpos * 32;
6258 int starty = mSY + ypos * 32;
6259 int font_nr, font_nr_default, font_width_default;
6260 int type = si->type;
6261 void *value = si->value;
6262 char *value_string = getSetupValue(type, value);
6265 if (value_string == NULL)
6268 if (type & TYPE_KEY)
6270 xpos = MENU_SCREEN_START_XPOS;
6272 if (type & TYPE_QUERY)
6273 value_string = "<press key>";
6275 else if (type & TYPE_STRING)
6277 int max_value_len = (SCR_FIELDX - 2) * 2;
6279 xpos = MENU_SCREEN_START_XPOS;
6281 if (strlen(value_string) > max_value_len)
6282 value_string[max_value_len] = '\0';
6284 else if (type & TYPE_YES_NO_AUTO)
6286 xpos = menu_screen_value_xpos - 1;
6289 startx = mSX + xpos * 32;
6290 starty = mSY + ypos * 32;
6291 font_nr_default = getSetupValueFont(type, value);
6292 font_width_default = getFontWidth(font_nr_default);
6294 font_nr = font_nr_default;
6296 // special check if right-side setup values moved left due to scrollbar
6297 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6299 int max_menu_text_length = 26; // maximum text length for classic menu
6300 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6301 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6302 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6303 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6304 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6306 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6309 startx = mSX + xpos * 32;
6311 font_nr = getSetupValueFontNarrow(type, font_nr);
6315 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6316 if (setup_mode != SETUP_MODE_INPUT)
6318 int max_menu_text_length_big = (menu_screen_value_xpos -
6319 MENU_SCREEN_START_XPOS);
6320 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6321 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6322 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6323 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6324 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6325 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6326 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6327 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6328 boolean correct_font_draw_xoffset = FALSE;
6330 if (xpos == MENU_SCREEN_START_XPOS &&
6331 startx + font1_xoffset < text_startx + text_font_xoffset)
6332 correct_font_draw_xoffset = TRUE;
6334 if (xpos == menu_screen_value_xpos &&
6335 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6336 correct_font_draw_xoffset = TRUE;
6338 /* check if setup value would overlap with setup text when printed */
6339 /* (this can happen for extreme/wrong values for font draw offset) */
6340 if (correct_font_draw_xoffset)
6342 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6343 font_draw_xoffset_modified = TRUE;
6345 if (type & TYPE_KEY)
6346 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6347 else if (!(type & TYPE_STRING))
6348 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6349 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6353 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6354 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6356 DrawText(startx, starty, value_string, font_nr);
6358 if (font_draw_xoffset_modified)
6359 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6362 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6364 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6365 struct TokenInfo *si = &setup_info[si_pos];
6367 if (si->type & TYPE_BOOLEAN_STYLE)
6369 *(boolean *)si->value ^= TRUE;
6371 else if (si->type & TYPE_YES_NO_AUTO)
6375 (*(int *)si->value == AUTO ? TRUE :
6376 *(int *)si->value == TRUE ? FALSE : AUTO) :
6377 (*(int *)si->value == TRUE ? AUTO :
6378 *(int *)si->value == AUTO ? FALSE : TRUE));
6380 else if (si->type & TYPE_KEY)
6384 si->type |= TYPE_QUERY;
6385 drawSetupValue(screen_pos, setup_info_pos_raw);
6386 si->type &= ~TYPE_QUERY;
6388 key = getSetupKey();
6389 if (key != KSYM_UNDEFINED)
6390 *(Key *)si->value = key;
6393 drawSetupValue(screen_pos, setup_info_pos_raw);
6395 // fullscreen state may have changed at this point
6396 if (si->value == &setup.fullscreen)
6397 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6400 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6402 static struct TokenInfo *setup_info_final = NULL;
6407 /* determine maximum list size of target list */
6408 while (setup_info_orig[list_size++].type != 0);
6410 /* free, allocate and clear memory for target list */
6411 checked_free(setup_info_final);
6412 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6414 /* copy setup info list without setup entries marked as hidden */
6415 for (i = 0; setup_info_orig[i].type != 0; i++)
6417 /* skip setup entries configured to be hidden */
6418 if (hideSetupEntry(setup_info_orig[i].value))
6421 /* skip skippable setup entries if screen is lower than usual */
6422 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6423 setup_info_orig[i].type == TYPE_SKIPPABLE)
6426 setup_info_final[list_pos++] = setup_info_orig[i];
6429 return setup_info_final;
6432 static void DrawSetupScreen_Generic()
6434 int fade_mask = REDRAW_FIELD;
6435 boolean redraw_all = FALSE;
6436 char *title_string = NULL;
6439 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6440 fade_mask = REDRAW_ALL;
6443 FadeMenuSoundsAndMusic();
6445 FreeScreenGadgets();
6446 CreateScreenGadgets();
6448 if (redraw_mask & REDRAW_ALL)
6453 /* needed if different viewport properties defined for setup screen */
6454 ChangeViewportPropertiesIfNeeded();
6456 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6460 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6462 if (setup_mode == SETUP_MODE_MAIN)
6464 setup_info = setup_info_main;
6465 title_string = STR_SETUP_MAIN;
6467 else if (setup_mode == SETUP_MODE_GAME)
6469 setup_info = setup_info_game;
6470 title_string = STR_SETUP_GAME;
6472 else if (setup_mode == SETUP_MODE_EDITOR)
6474 setup_info = setup_info_editor;
6475 title_string = STR_SETUP_EDITOR;
6477 else if (setup_mode == SETUP_MODE_GRAPHICS)
6479 setup_info = setup_info_graphics;
6480 title_string = STR_SETUP_GRAPHICS;
6482 else if (setup_mode == SETUP_MODE_SOUND)
6484 setup_info = setup_info_sound;
6485 title_string = STR_SETUP_SOUND;
6487 else if (setup_mode == SETUP_MODE_ARTWORK)
6489 setup_info = setup_info_artwork;
6490 title_string = STR_SETUP_ARTWORK;
6492 else if (setup_mode == SETUP_MODE_TOUCH)
6494 setup_info = setup_info_touch;
6495 title_string = STR_SETUP_TOUCH;
6497 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6498 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6499 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6500 setup_info = setup_info_touch_wipe_gestures;
6502 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6504 setup_info = setup_info_shortcuts;
6505 title_string = STR_SETUP_SHORTCUTS;
6507 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6509 setup_info = setup_info_shortcuts_1;
6510 title_string = STR_SETUP_SHORTCUTS;
6512 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6514 setup_info = setup_info_shortcuts_2;
6515 title_string = STR_SETUP_SHORTCUTS;
6517 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6519 setup_info = setup_info_shortcuts_3;
6520 title_string = STR_SETUP_SHORTCUTS;
6522 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6524 setup_info = setup_info_shortcuts_4;
6525 title_string = STR_SETUP_SHORTCUTS;
6527 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6529 setup_info = setup_info_shortcuts_5;
6530 title_string = STR_SETUP_SHORTCUTS;
6533 /* use modified setup info without setup entries marked as hidden */
6534 setup_info = getSetupInfoFinal(setup_info);
6536 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6538 // determine maximal number of setup entries that can be displayed on screen
6540 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6543 // determine maximal number of setup entries available for this setup screen
6545 for (i = 0; setup_info[i].type != 0; i++)
6548 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6550 MapScreenGadgets(max_setup_info);
6553 redraw_mask = fade_mask = REDRAW_ALL;
6555 DrawMaskedBorder(fade_mask);
6560 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6562 menu_info = setup_info;
6564 HandleMenuScreen(mx, my, dx, dy, button,
6565 setup_mode, num_setup_info, max_setup_info);
6568 void DrawSetupScreen_Input()
6572 FadeOut(REDRAW_FIELD);
6576 setup_info = getSetupInfoFinal(setup_info_input);
6578 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6580 for (i = 0; setup_info[i].type != 0; i++)
6582 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6583 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6584 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6585 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6586 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6587 initCursor(i, IMG_MENU_BUTTON);
6589 DrawCursorAndText_Setup(i, -1, FALSE);
6592 /* create gadgets for setup input menu screen */
6593 FreeScreenGadgets();
6594 CreateScreenGadgets();
6596 /* map gadgets for setup input menu screen */
6597 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6599 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6601 FadeIn(REDRAW_FIELD);
6604 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6606 if (device_name == NULL)
6609 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6612 if (strlen(device_name) > 1)
6614 char c1 = device_name[strlen(device_name) - 1];
6615 char c2 = device_name[strlen(device_name) - 2];
6617 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6618 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6621 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6622 strlen(device_name));
6625 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6628 static struct SetupKeyboardInfo custom_key;
6635 { &custom_key.left, "Axis/Pad Left" },
6636 { &custom_key.right, "Axis/Pad Right" },
6637 { &custom_key.up, "Axis/Pad Up" },
6638 { &custom_key.down, "Axis/Pad Down" },
6639 { &custom_key.snap, "Button 1/A/X" },
6640 { &custom_key.drop, "Button 2/B/Y" }
6642 static char *joystick_name[MAX_PLAYERS] =
6649 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6650 int font_nr_info = FONT_MENU_1;
6651 int font_nr_name = FONT_VALUE_OLD;
6652 int font_nr_on = FONT_VALUE_1;
6653 int font_nr_off = FONT_VALUE_OLD;
6656 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6658 font_nr_info = FONT_MENU_2;
6659 font_nr_on = FONT_VALUE_NARROW;
6660 font_nr_off = FONT_VALUE_OLD_NARROW;
6663 custom_key = setup.input[player_nr].key;
6665 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6666 FONT_INPUT_1_ACTIVE);
6668 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6670 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6671 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6673 if (setup.input[player_nr].use_joystick)
6675 char *device_name = setup.input[player_nr].joy.device_name;
6676 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6677 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6678 char *text = joystick_name[joystick_nr];
6679 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6681 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6682 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6686 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6687 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6690 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6691 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6695 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6696 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6697 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6698 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6700 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6701 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6702 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6703 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6704 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6705 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6707 for (i = 0; i < 6; i++)
6709 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6711 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6713 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6714 (setup.input[player_nr].use_joystick ?
6716 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6720 static int input_player_nr = 0;
6722 void HandleSetupScreen_Input_Player(int step, int direction)
6724 int old_player_nr = input_player_nr;
6727 new_player_nr = old_player_nr + step * direction;
6728 if (new_player_nr < 0)
6730 if (new_player_nr > MAX_PLAYERS - 1)
6731 new_player_nr = MAX_PLAYERS - 1;
6733 if (new_player_nr != old_player_nr)
6735 input_player_nr = new_player_nr;
6737 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6741 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6743 static int choice = 0;
6746 int pos_start = SETUPINPUT_SCREEN_POS_START;
6747 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6748 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6749 int pos_end = SETUPINPUT_SCREEN_POS_END;
6751 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6755 for (i = 0; setup_info_input[i].type != 0; i++)
6757 /* adjust menu structure according to skipped setup entries */
6758 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6766 if (button == MB_MENU_INITIALIZE)
6768 /* input setup menu may have changed size due to graphics configuration */
6769 if (choice >= pos_empty1)
6772 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6774 DrawCursorAndText_Setup(choice, -1, TRUE);
6778 else if (button == MB_MENU_LEAVE)
6780 setup_mode = SETUP_MODE_MAIN;
6787 if (mx || my) /* mouse input */
6789 x = (mx - mSX) / 32;
6790 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6792 else if (dx || dy) /* keyboard input */
6794 if (dx && choice == 0)
6795 x = (dx < 0 ? 10 : 12);
6796 else if ((dx && choice == 1) ||
6797 (dx == -1 && choice == pos_end))
6798 button = MB_MENU_CHOICE;
6802 if (y >= pos_empty1 && y <= pos_empty2)
6803 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6806 if (y == 0 && dx != 0 && button)
6808 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6810 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6811 y >= pos_start && y <= pos_end &&
6812 !(y >= pos_empty1 && y <= pos_empty2))
6818 DrawCursorAndText_Setup(choice, -1, FALSE);
6819 DrawCursorAndText_Setup(y, -1, TRUE);
6821 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6830 char *device_name = setup.input[input_player_nr].joy.device_name;
6832 if (!setup.input[input_player_nr].use_joystick)
6834 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6836 setJoystickDeviceToNr(device_name, new_device_nr);
6837 setup.input[input_player_nr].use_joystick = TRUE;
6841 int device_nr = getJoystickNrFromDeviceName(device_name);
6842 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6844 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6845 setup.input[input_player_nr].use_joystick = FALSE;
6847 setJoystickDeviceToNr(device_name, new_device_nr);
6850 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6854 if (setup.input[input_player_nr].use_joystick)
6855 ConfigureJoystick(input_player_nr);
6857 CustomizeKeyboard(input_player_nr);
6859 else if (y == pos_end)
6865 setup_mode = SETUP_MODE_MAIN;
6872 static boolean CustomizeKeyboardMain(int player_nr)
6876 boolean finished = FALSE;
6877 static struct SetupKeyboardInfo custom_key;
6882 } customize_step[] =
6884 { &custom_key.left, "Move Left" },
6885 { &custom_key.right, "Move Right" },
6886 { &custom_key.up, "Move Up" },
6887 { &custom_key.down, "Move Down" },
6888 { &custom_key.snap, "Snap Field" },
6889 { &custom_key.drop, "Drop Element" }
6891 int font_nr_old = FONT_VALUE_OLD;
6892 int font_nr_new = FONT_VALUE_1;
6893 boolean success = FALSE;
6895 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6897 font_nr_old = FONT_VALUE_OLD_NARROW;
6898 font_nr_new = FONT_VALUE_NARROW;
6901 /* read existing key bindings from player setup */
6902 custom_key = setup.input[player_nr].key;
6905 FadeOut(REDRAW_FIELD);
6909 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6912 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6913 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6914 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6915 "Key:", FONT_INPUT_1_ACTIVE);
6916 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6917 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
6919 FadeIn(REDRAW_FIELD);
6925 if (NextValidEvent(&event))
6929 case EVENT_KEYPRESS:
6931 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6933 /* press 'Escape' to abort and keep the old key bindings */
6934 if (key == KSYM_Escape)
6936 FadeSkipNextFadeIn();
6943 /* press 'Enter' to keep the existing key binding */
6944 if (key == KSYM_Return)
6945 key = *customize_step[step_nr].key;
6947 /* check if key already used */
6948 for (i = 0; i < step_nr; i++)
6949 if (*customize_step[i].key == key)
6954 /* got new key binding */
6955 *customize_step[step_nr].key = key;
6956 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6958 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6959 getKeyNameFromKey(key), font_nr_new);
6962 /* un-highlight last query */
6963 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6964 customize_step[step_nr - 1].text, FONT_MENU_1);
6965 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6966 "Key:", FONT_MENU_1);
6968 /* all keys configured */
6977 /* query next key binding */
6978 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6979 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6980 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6981 "Key:", FONT_INPUT_1_ACTIVE);
6982 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6983 getKeyNameFromKey(*customize_step[step_nr].key),
6988 case EVENT_KEYRELEASE:
6989 key_joystick_mapping = 0;
6993 HandleOtherEvents(&event);
7001 /* write new key bindings back to player setup, if successfully finished */
7003 setup.input[player_nr].key = custom_key;
7008 void CustomizeKeyboard(int player_nr)
7010 boolean success = CustomizeKeyboardMain(player_nr);
7014 int font_nr = FONT_TITLE_1;
7015 int font_height = getFontHeight(font_nr);
7016 int ypos1 = SYSIZE / 2 - font_height * 2;
7017 int ypos2 = SYSIZE / 2 - font_height * 1;
7018 unsigned int wait_frame_delay = 0;
7019 unsigned int wait_frame_delay_value = 2000;
7021 ResetDelayCounter(&wait_frame_delay);
7025 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7026 DrawTextSCentered(ypos2, font_nr, "configured!");
7028 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7034 DrawSetupScreen_Input();
7037 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7039 #define MARKER_BUTTON 1
7040 #define MARKER_AXIS_X 2
7041 #define MARKER_AXIS_Y 3
7043 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7045 #if defined(TARGET_SDL2)
7046 static boolean bitmaps_initialized = FALSE;
7047 boolean screen_initialized = FALSE;
7048 static Bitmap *controller, *button, *axis_x, *axis_y;
7050 boolean success = TRUE;
7051 boolean done = FALSE, next = FALSE;
7053 int alpha = 200, alpha_step = -1;
7054 int alpha_ticks = 0;
7055 char mapping[4096], temp[4096];
7056 int font_name = MENU_SETUP_FONT_TITLE;
7057 int font_info = MENU_SETUP_FONT_TEXT;
7058 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7059 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7060 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7061 int ystep_name = getMenuTextStep(spacing_name, font_name);
7062 int ystep_line = getMenuTextStep(spacing_line, font_info);
7063 int ystep_para = getMenuTextStep(spacing_para, font_info);
7071 int axis, button, hat, hat_value;
7074 *step, *prev_step, steps[] =
7076 { 356, 155, MARKER_BUTTON, "a", },
7077 { 396, 122, MARKER_BUTTON, "b", },
7078 { 320, 125, MARKER_BUTTON, "x", },
7079 { 358, 95, MARKER_BUTTON, "y", },
7080 { 162, 125, MARKER_BUTTON, "back", },
7081 { 216, 125, MARKER_BUTTON, "guide", },
7082 { 271, 125, MARKER_BUTTON, "start", },
7083 { 110, 200, MARKER_BUTTON, "dpleft", },
7084 { 146, 228, MARKER_BUTTON, "dpdown", },
7085 { 178, 200, MARKER_BUTTON, "dpright", },
7086 { 146, 172, MARKER_BUTTON, "dpup", },
7087 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7088 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7089 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7090 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7091 { 73, 141, MARKER_BUTTON, "leftstick", },
7092 { 282, 210, MARKER_BUTTON, "rightstick", },
7093 { 73, 141, MARKER_AXIS_X, "leftx", },
7094 { 73, 141, MARKER_AXIS_Y, "lefty", },
7095 { 282, 210, MARKER_AXIS_X, "rightx", },
7096 { 282, 210, MARKER_AXIS_Y, "righty", },
7099 unsigned int event_frame_delay = 0;
7100 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7102 ResetDelayCounter(&event_frame_delay);
7104 if (!bitmaps_initialized)
7106 controller = LoadCustomImage("joystick/controller.png");
7107 button = LoadCustomImage("joystick/button.png");
7108 axis_x = LoadCustomImage("joystick/axis_x.png");
7109 axis_y = LoadCustomImage("joystick/axis_y.png");
7111 bitmaps_initialized = TRUE;
7114 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7117 /* print info about the joystick we are watching */
7118 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7119 SDL_JoystickInstanceID(joystick), name);
7120 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7121 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7122 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7125 /* initialize mapping with GUID and name */
7126 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7128 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7129 temp, name, SDL_GetPlatform());
7131 /* loop through all steps (buttons and axes), getting joystick events */
7132 for (i = 0; i < SDL_arraysize(steps) && !done;)
7134 Bitmap *marker = button; /* initialize with reliable default value */
7137 strcpy(step->mapping, mapping);
7141 step->hat_value = -1;
7143 marker = (step->marker == MARKER_BUTTON ? button :
7144 step->marker == MARKER_AXIS_X ? axis_x :
7145 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7149 while (!done && !next)
7151 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7152 alpha_ticks = SDL_GetTicks();
7159 else if (alpha < 128)
7165 int controller_x = SX + (SXSIZE - controller->width) / 2;
7166 int controller_y = SY + ystep_line;
7168 int marker_x = controller_x + step->x;
7169 int marker_y = controller_y + step->y;
7171 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7172 int ystart2 = ystart1 + ystep_name + ystep_line;
7176 DrawTextSCentered(ystart1, font_name, name);
7178 DrawTextSCentered(ystart2, font_info,
7179 "Press buttons and move axes on");
7180 ystart2 += ystep_line;
7181 DrawTextSCentered(ystart2, font_info,
7182 "your controller when indicated.");
7183 ystart2 += ystep_line;
7184 DrawTextSCentered(ystart2, font_info,
7185 "(Your controller may look different.)");
7186 ystart2 += ystep_para;
7188 #if defined(PLATFORM_ANDROID)
7189 DrawTextSCentered(ystart2, font_info,
7190 "To correct a mistake,");
7191 ystart2 += ystep_line;
7192 DrawTextSCentered(ystart2, font_info,
7193 "press the 'back' button.");
7194 ystart2 += ystep_line;
7195 DrawTextSCentered(ystart2, font_info,
7196 "To skip a button or axis,");
7197 ystart2 += ystep_line;
7198 DrawTextSCentered(ystart2, font_info,
7199 "press the 'menu' button.");
7201 DrawTextSCentered(ystart2, font_info,
7202 "To correct a mistake,");
7203 ystart2 += ystep_line;
7204 DrawTextSCentered(ystart2, font_info,
7205 "press the 'backspace' key.");
7206 ystart2 += ystep_line;
7207 DrawTextSCentered(ystart2, font_info,
7208 "To skip a button or axis,");
7209 ystart2 += ystep_line;
7210 DrawTextSCentered(ystart2, font_info,
7211 "press the 'return' key.");
7212 ystart2 += ystep_line;
7213 DrawTextSCentered(ystart2, font_info,
7214 "To exit, press the 'escape' key.");
7217 BlitBitmapMasked(controller, drawto, 0, 0,
7218 controller->width, controller->height,
7219 controller_x, controller_y);
7221 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7222 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7224 BlitBitmapMasked(marker, drawto, 0, 0,
7225 marker->width, marker->height,
7226 marker_x, marker_y);
7228 if (!screen_initialized)
7229 FadeIn(REDRAW_FIELD);
7233 screen_initialized = TRUE;
7235 while (NextValidEvent(&event))
7239 case SDL_JOYAXISMOTION:
7240 if (event.jaxis.value > 20000 ||
7241 event.jaxis.value < -20000)
7243 for (j = 0; j < i; j++)
7244 if (steps[j].axis == event.jaxis.axis)
7249 if (step->marker != MARKER_AXIS_X &&
7250 step->marker != MARKER_AXIS_Y)
7253 step->axis = event.jaxis.axis;
7254 strcat(mapping, step->field);
7255 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7256 strcat(mapping, temp);
7264 case SDL_JOYHATMOTION:
7265 /* ignore centering; we're probably just coming back
7266 to the center from the previous item we set */
7267 if (event.jhat.value == SDL_HAT_CENTERED)
7270 for (j = 0; j < i; j++)
7271 if (steps[j].hat == event.jhat.hat &&
7272 steps[j].hat_value == event.jhat.value)
7277 step->hat = event.jhat.hat;
7278 step->hat_value = event.jhat.value;
7279 strcat(mapping, step->field);
7280 snprintf(temp, sizeof(temp), ":h%u.%u,",
7281 event.jhat.hat, event.jhat.value );
7282 strcat(mapping, temp);
7289 case SDL_JOYBALLMOTION:
7292 case SDL_JOYBUTTONUP:
7293 for (j = 0; j < i; j++)
7294 if (steps[j].button == event.jbutton.button)
7299 step->button = event.jbutton.button;
7300 strcat(mapping, step->field);
7301 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7302 strcat(mapping, temp);
7309 case SDL_FINGERDOWN:
7310 case SDL_MOUSEBUTTONDOWN:
7311 /* skip this step */
7318 if (event.key.keysym.sym == KSYM_BackSpace ||
7319 event.key.keysym.sym == KSYM_Back)
7330 /* undo this step */
7331 prev_step = &steps[i - 1];
7332 strcpy(mapping, prev_step->mapping);
7339 if (event.key.keysym.sym == KSYM_space ||
7340 event.key.keysym.sym == KSYM_Return ||
7341 event.key.keysym.sym == KSYM_Menu)
7343 /* skip this step */
7350 if (event.key.keysym.sym == KSYM_Escape)
7360 program.exit_function(0);
7367 // do not handle events for longer than standard frame delay period
7368 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7377 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7380 // activate mapping for this game
7381 SDL_GameControllerAddMapping(mapping);
7383 // save mapping to personal mappings
7384 SaveSetup_AddGameControllerMapping(mapping);
7387 /* wait until the last pending event was removed from event queue */
7388 while (NextValidEvent(&event));
7396 static int ConfigureJoystickMain(int player_nr)
7398 char *device_name = setup.input[player_nr].joy.device_name;
7399 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7400 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7401 int success = FALSE;
7404 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7405 return JOYSTICK_NOT_AVAILABLE;
7407 if (!joystick_active || !setup.input[player_nr].use_joystick)
7408 return JOYSTICK_NOT_AVAILABLE;
7411 FadeOut(REDRAW_FIELD);
7413 // close all joystick devices (potentially opened as game controllers)
7414 for (i = 0; i < SDL_NumJoysticks(); i++)
7415 SDLCloseJoystick(i);
7417 // open joystick device as plain joystick to configure as game controller
7418 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7420 // as the joystick was successfully opened before, this should not happen
7421 if (joystick == NULL)
7424 // create new game controller mapping (buttons and axes) for joystick device
7425 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7427 // close joystick (and maybe re-open as configured game controller later)
7428 SDL_JoystickClose(joystick);
7430 // re-open all joystick devices (potentially as game controllers)
7431 for (i = 0; i < SDL_NumJoysticks(); i++)
7434 // clear all joystick input actions for all joystick devices
7435 SDLClearJoystickState();
7437 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7440 void ConfigureJoystick(int player_nr)
7442 boolean state = ConfigureJoystickMain(player_nr);
7444 if (state != JOYSTICK_NOT_CONFIGURED)
7446 boolean success = (state == JOYSTICK_CONFIGURED);
7447 char message1[MAX_OUTPUT_LINESIZE + 1];
7448 char *message2 = (success ? "configured!" : "not available!");
7449 char *device_name = setup.input[player_nr].joy.device_name;
7450 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7451 int font_nr = FONT_TITLE_1;
7452 int font_height = getFontHeight(font_nr);
7453 int ypos1 = SYSIZE / 2 - font_height * 2;
7454 int ypos2 = SYSIZE / 2 - font_height * 1;
7455 unsigned int wait_frame_delay = 0;
7456 unsigned int wait_frame_delay_value = 2000;
7458 ResetDelayCounter(&wait_frame_delay);
7462 sprintf(message1, "Joystick %d", nr);
7464 DrawTextSCentered(ypos1, font_nr, message1);
7465 DrawTextSCentered(ypos2, font_nr, message2);
7467 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7473 DrawSetupScreen_Input();
7476 boolean ConfigureVirtualButtonsMain()
7478 static char *customize_step_text[] =
7487 char grid_button[] =
7489 CHAR_GRID_BUTTON_LEFT,
7490 CHAR_GRID_BUTTON_RIGHT,
7491 CHAR_GRID_BUTTON_UP,
7492 CHAR_GRID_BUTTON_DOWN,
7493 CHAR_GRID_BUTTON_SNAP,
7494 CHAR_GRID_BUTTON_DROP
7496 int font_nr = FONT_INPUT_1_ACTIVE;
7497 int font_height = getFontHeight(font_nr);
7498 int ypos1 = SYSIZE / 2 - font_height * 2;
7499 int ypos2 = SYSIZE / 2 - font_height * 1;
7500 boolean success = FALSE;
7501 boolean finished = FALSE;
7503 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7504 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7505 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7506 boolean set_grid_button = FALSE;
7507 int nr = GRID_ACTIVE_NR();
7510 for (x = 0; x < MAX_GRID_XSIZE; x++)
7511 for (y = 0; y < MAX_GRID_YSIZE; y++)
7512 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7514 overlay.grid_button_highlight = grid_button[step_nr];
7517 FadeOut(REDRAW_FIELD);
7521 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7522 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7523 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7525 FadeIn(REDRAW_FIELD);
7527 SetOverlayShowGrid(TRUE);
7533 while (NextValidEvent(&event))
7537 case EVENT_KEYPRESS:
7539 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7541 /* press 'Escape' to abort and keep the old key bindings */
7542 if (key == KSYM_Escape)
7544 for (x = 0; x < MAX_GRID_XSIZE; x++)
7545 for (y = 0; y < MAX_GRID_YSIZE; y++)
7546 overlay.grid_button[x][y] = grid_button_old[x][y];
7548 FadeSkipNextFadeIn();
7555 /* press 'Enter' to keep the existing key binding */
7556 if (key == KSYM_Return ||
7562 else if (key == KSYM_BackSpace ||
7567 FadeSkipNextFadeIn();
7581 /* all virtual buttons configured */
7590 for (x = 0; x < MAX_GRID_XSIZE; x++)
7591 for (y = 0; y < MAX_GRID_YSIZE; y++)
7592 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7594 overlay.grid_button_highlight = grid_button[step_nr];
7596 /* query next virtual button */
7600 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7601 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7602 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7606 case EVENT_KEYRELEASE:
7607 key_joystick_mapping = 0;
7610 case EVENT_BUTTONPRESS:
7611 case EVENT_BUTTONRELEASE:
7613 ButtonEvent *button = (ButtonEvent *)&event;
7615 button->x += video.screen_xoffset;
7616 button->y += video.screen_yoffset;
7618 x = button->x * overlay.grid_xsize / video.screen_width;
7619 y = button->y * overlay.grid_ysize / video.screen_height;
7621 if (button->type == EVENT_BUTTONPRESS)
7623 button_status = button->button;
7626 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7627 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7629 set_grid_button = TRUE;
7633 button_status = MB_RELEASED;
7638 case EVENT_MOTIONNOTIFY:
7640 MotionEvent *motion = (MotionEvent *)&event;
7642 motion->x += video.screen_xoffset;
7643 motion->y += video.screen_yoffset;
7645 x = motion->x * overlay.grid_xsize / video.screen_width;
7646 y = motion->y * overlay.grid_ysize / video.screen_height;
7648 set_grid_button = TRUE;
7652 #if defined(TARGET_SDL2)
7653 case SDL_WINDOWEVENT:
7654 HandleWindowEvent((WindowEvent *) &event);
7656 // check if device has been rotated
7657 if (nr != GRID_ACTIVE_NR())
7659 nr = GRID_ACTIVE_NR();
7661 for (x = 0; x < MAX_GRID_XSIZE; x++)
7662 for (y = 0; y < MAX_GRID_YSIZE; y++)
7663 grid_button_old[x][y] = grid_button_tmp[x][y] =
7664 overlay.grid_button[x][y];
7669 case SDL_APP_WILLENTERBACKGROUND:
7670 case SDL_APP_DIDENTERBACKGROUND:
7671 case SDL_APP_WILLENTERFOREGROUND:
7672 case SDL_APP_DIDENTERFOREGROUND:
7673 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7678 HandleOtherEvents(&event);
7682 if (set_grid_button)
7684 overlay.grid_button[x][y] =
7685 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7686 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7687 grid_button_tmp[x][y]);
7689 set_grid_button = FALSE;
7696 for (x = 0; x < MAX_GRID_XSIZE; x++)
7697 for (y = 0; y < MAX_GRID_YSIZE; y++)
7698 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7700 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7702 SetOverlayShowGrid(FALSE);
7707 void ConfigureVirtualButtons()
7709 boolean success = ConfigureVirtualButtonsMain();
7713 int font_nr = FONT_TITLE_1;
7714 int font_height = getFontHeight(font_nr);
7715 int ypos1 = SYSIZE / 2 - font_height * 2;
7716 int ypos2 = SYSIZE / 2 - font_height * 1;
7717 unsigned int wait_frame_delay = 0;
7718 unsigned int wait_frame_delay_value = 2000;
7720 ResetDelayCounter(&wait_frame_delay);
7724 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7725 DrawTextSCentered(ypos2, font_nr, "configured!");
7727 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7734 void DrawSetupScreen()
7736 if (setup_mode == SETUP_MODE_INPUT)
7737 DrawSetupScreen_Input();
7738 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7739 DrawChooseTree(&game_speed_current);
7740 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7741 DrawChooseTree(&scroll_delay_current);
7742 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7743 DrawChooseTree(&snapshot_mode_current);
7744 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7745 DrawChooseTree(&window_size_current);
7746 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7747 DrawChooseTree(&scaling_type_current);
7748 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7749 DrawChooseTree(&rendering_mode_current);
7750 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7751 DrawChooseTree(&artwork.gfx_current);
7752 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7753 DrawChooseTree(&artwork.snd_current);
7754 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7755 DrawChooseTree(&artwork.mus_current);
7756 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7757 DrawChooseTree(&volume_simple_current);
7758 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7759 DrawChooseTree(&volume_loops_current);
7760 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7761 DrawChooseTree(&volume_music_current);
7762 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7763 DrawChooseTree(&touch_control_current);
7764 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7765 DrawChooseTree(&move_distance_current);
7766 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7767 DrawChooseTree(&drop_distance_current);
7768 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7769 DrawChooseTree(&transparency_current);
7770 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7771 DrawChooseTree(&grid_size_current[0][0]);
7772 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7773 DrawChooseTree(&grid_size_current[0][1]);
7774 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7775 DrawChooseTree(&grid_size_current[1][0]);
7776 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7777 DrawChooseTree(&grid_size_current[1][1]);
7779 DrawSetupScreen_Generic();
7781 PlayMenuSoundsAndMusic();
7784 void RedrawSetupScreenAfterFullscreenToggle()
7786 if (setup_mode == SETUP_MODE_GRAPHICS ||
7787 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7789 // update list selection from "setup.window_scaling_percent"
7790 execSetupGraphics_setWindowSizes(TRUE);
7796 void RedrawSetupScreenAfterScreenRotation(int nr)
7800 if (setup_mode == SETUP_MODE_TOUCH)
7802 // update virtual button settings (depending on screen orientation)
7805 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
7807 // save already configured virtual buttons
7808 for (x = 0; x < MAX_GRID_XSIZE; x++)
7809 for (y = 0; y < MAX_GRID_YSIZE; y++)
7810 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7814 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7816 if (setup_mode == SETUP_MODE_INPUT)
7817 HandleSetupScreen_Input(mx, my, dx, dy, button);
7818 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7819 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7820 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7821 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7822 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7823 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7824 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7825 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7826 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7827 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7828 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7829 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7830 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7831 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7832 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7833 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7834 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7835 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7836 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7837 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7838 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7839 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7840 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7841 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7842 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7843 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7844 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7845 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7846 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7847 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7848 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7849 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
7850 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7851 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
7852 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7853 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
7854 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7855 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
7856 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7857 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
7859 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7862 void HandleGameActions()
7864 if (game.restart_game_message != NULL)
7865 RequestRestartGame(game.restart_game_message);
7867 if (game_status != GAME_MODE_PLAYING)
7870 GameActions(); /* main game loop */
7872 if (tape.auto_play && !tape.playing)
7873 AutoPlayTape(); /* continue automatically playing next tape */
7877 /* ---------- new screen button stuff -------------------------------------- */
7879 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7883 case SCREEN_CTRL_ID_PREV_LEVEL:
7884 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7885 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7888 case SCREEN_CTRL_ID_NEXT_LEVEL:
7889 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7890 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7893 case SCREEN_CTRL_ID_PREV_PLAYER:
7894 *x = mSX + TILEX * 10;
7895 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7898 case SCREEN_CTRL_ID_NEXT_PLAYER:
7899 *x = mSX + TILEX * 12;
7900 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7904 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7910 int gfx_unpressed, gfx_pressed;
7911 void (*get_gadget_position)(int *, int *, int);
7915 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7918 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7919 getScreenMenuButtonPos,
7920 SCREEN_CTRL_ID_PREV_LEVEL,
7925 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7926 getScreenMenuButtonPos,
7927 SCREEN_CTRL_ID_NEXT_LEVEL,
7932 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7933 getScreenMenuButtonPos,
7934 SCREEN_CTRL_ID_PREV_PLAYER,
7939 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7940 getScreenMenuButtonPos,
7941 SCREEN_CTRL_ID_NEXT_PLAYER,
7949 int gfx_unpressed, gfx_pressed;
7953 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7956 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7957 -1, -1, /* these values are not constant, but can change at runtime */
7958 SCREEN_CTRL_ID_SCROLL_UP,
7962 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7963 -1, -1, /* these values are not constant, but can change at runtime */
7964 SCREEN_CTRL_ID_SCROLL_DOWN,
7971 int gfx_unpressed, gfx_pressed;
7977 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7980 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7981 -1, -1, /* these values are not constant, but can change at runtime */
7982 -1, -1, /* these values are not constant, but can change at runtime */
7983 GD_TYPE_SCROLLBAR_VERTICAL,
7984 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7985 "scroll level series vertically"
7989 static void CreateScreenMenubuttons()
7991 struct GadgetInfo *gi;
7992 unsigned int event_mask;
7995 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7997 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7998 int gfx_unpressed, gfx_pressed;
7999 int x, y, width, height;
8000 int gd_x1, gd_x2, gd_y1, gd_y2;
8001 int id = menubutton_info[i].gadget_id;
8003 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8005 menubutton_info[i].get_gadget_position(&x, &y, id);
8007 width = SC_MENUBUTTON_XSIZE;
8008 height = SC_MENUBUTTON_YSIZE;
8010 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8011 gfx_pressed = menubutton_info[i].gfx_pressed;
8012 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8013 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8014 gd_x1 = graphic_info[gfx_unpressed].src_x;
8015 gd_y1 = graphic_info[gfx_unpressed].src_y;
8016 gd_x2 = graphic_info[gfx_pressed].src_x;
8017 gd_y2 = graphic_info[gfx_pressed].src_y;
8019 gi = CreateGadget(GDI_CUSTOM_ID, id,
8020 GDI_CUSTOM_TYPE_ID, i,
8021 GDI_INFO_TEXT, menubutton_info[i].infotext,
8026 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8027 GDI_STATE, GD_BUTTON_UNPRESSED,
8028 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8029 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8030 GDI_DIRECT_DRAW, FALSE,
8031 GDI_EVENT_MASK, event_mask,
8032 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8036 Error(ERR_EXIT, "cannot create gadget");
8038 screen_gadget[id] = gi;
8042 static void CreateScreenScrollbuttons()
8044 struct GadgetInfo *gi;
8045 unsigned int event_mask;
8048 /* these values are not constant, but can change at runtime */
8049 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8050 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8051 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8052 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8054 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8056 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8057 int gfx_unpressed, gfx_pressed;
8058 int x, y, width, height;
8059 int gd_x1, gd_x2, gd_y1, gd_y2;
8060 int id = scrollbutton_info[i].gadget_id;
8062 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8064 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8065 y = mSY + scrollbutton_info[i].y;
8066 width = SC_SCROLLBUTTON_XSIZE;
8067 height = SC_SCROLLBUTTON_YSIZE;
8069 /* correct scrollbar position if placed outside menu (playfield) area */
8070 if (x > SX + SC_SCROLL_UP_XPOS)
8071 x = SX + SC_SCROLL_UP_XPOS;
8073 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8074 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8075 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8077 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8078 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8079 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8080 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8081 gd_x1 = graphic_info[gfx_unpressed].src_x;
8082 gd_y1 = graphic_info[gfx_unpressed].src_y;
8083 gd_x2 = graphic_info[gfx_pressed].src_x;
8084 gd_y2 = graphic_info[gfx_pressed].src_y;
8086 gi = CreateGadget(GDI_CUSTOM_ID, id,
8087 GDI_CUSTOM_TYPE_ID, i,
8088 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8093 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8094 GDI_STATE, GD_BUTTON_UNPRESSED,
8095 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8096 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8097 GDI_DIRECT_DRAW, FALSE,
8098 GDI_EVENT_MASK, event_mask,
8099 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8103 Error(ERR_EXIT, "cannot create gadget");
8105 screen_gadget[id] = gi;
8109 static void CreateScreenScrollbars()
8113 /* these values are not constant, but can change at runtime */
8114 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8115 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8116 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8117 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8119 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8121 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8122 int gfx_unpressed, gfx_pressed;
8123 int x, y, width, height;
8124 int gd_x1, gd_x2, gd_y1, gd_y2;
8125 struct GadgetInfo *gi;
8126 int items_max, items_visible, item_position;
8127 unsigned int event_mask;
8128 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8129 int id = scrollbar_info[i].gadget_id;
8131 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8133 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8134 y = mSY + scrollbar_info[i].y;
8135 width = scrollbar_info[i].width;
8136 height = scrollbar_info[i].height;
8138 /* correct scrollbar position if placed outside menu (playfield) area */
8139 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8140 x = SX + SC_SCROLL_VERTICAL_XPOS;
8142 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8143 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8145 items_max = num_page_entries;
8146 items_visible = num_page_entries;
8149 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8150 gfx_pressed = scrollbar_info[i].gfx_pressed;
8151 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8152 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8153 gd_x1 = graphic_info[gfx_unpressed].src_x;
8154 gd_y1 = graphic_info[gfx_unpressed].src_y;
8155 gd_x2 = graphic_info[gfx_pressed].src_x;
8156 gd_y2 = graphic_info[gfx_pressed].src_y;
8158 gi = CreateGadget(GDI_CUSTOM_ID, id,
8159 GDI_CUSTOM_TYPE_ID, i,
8160 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8165 GDI_TYPE, scrollbar_info[i].type,
8166 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8167 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8168 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8169 GDI_WHEEL_AREA_X, SX,
8170 GDI_WHEEL_AREA_Y, SY,
8171 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8172 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8173 GDI_STATE, GD_BUTTON_UNPRESSED,
8174 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8175 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8176 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8177 GDI_DIRECT_DRAW, FALSE,
8178 GDI_EVENT_MASK, event_mask,
8179 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8183 Error(ERR_EXIT, "cannot create gadget");
8185 screen_gadget[id] = gi;
8189 void CreateScreenGadgets()
8191 CreateScreenMenubuttons();
8193 CreateScreenScrollbuttons();
8194 CreateScreenScrollbars();
8197 void FreeScreenGadgets()
8201 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8202 FreeGadget(screen_gadget[i]);
8205 void MapScreenMenuGadgets(int screen_mask)
8209 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8210 if (screen_mask & menubutton_info[i].screen_mask)
8211 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8214 void MapScreenGadgets(int num_entries)
8218 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8221 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8222 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8224 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8225 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8228 void MapScreenTreeGadgets(TreeInfo *ti)
8230 MapScreenGadgets(numTreeInfoInGroup(ti));
8233 static void HandleScreenGadgets(struct GadgetInfo *gi)
8235 int id = gi->custom_id;
8236 int button = gi->event.button;
8237 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
8241 case SCREEN_CTRL_ID_PREV_LEVEL:
8242 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8245 case SCREEN_CTRL_ID_NEXT_LEVEL:
8246 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8249 case SCREEN_CTRL_ID_PREV_PLAYER:
8250 HandleSetupScreen_Input_Player(step, -1);
8253 case SCREEN_CTRL_ID_NEXT_PLAYER:
8254 HandleSetupScreen_Input_Player(step, +1);
8257 case SCREEN_CTRL_ID_SCROLL_UP:
8258 if (game_status == GAME_MODE_LEVELS)
8259 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8260 else if (game_status == GAME_MODE_LEVELNR)
8261 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8262 else if (game_status == GAME_MODE_SETUP)
8263 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8264 else if (game_status == GAME_MODE_INFO)
8265 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8268 case SCREEN_CTRL_ID_SCROLL_DOWN:
8269 if (game_status == GAME_MODE_LEVELS)
8270 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8271 else if (game_status == GAME_MODE_LEVELNR)
8272 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8273 else if (game_status == GAME_MODE_SETUP)
8274 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8275 else if (game_status == GAME_MODE_INFO)
8276 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8279 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8280 if (game_status == GAME_MODE_LEVELS)
8281 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8282 else if (game_status == GAME_MODE_LEVELNR)
8283 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8284 else if (game_status == GAME_MODE_SETUP)
8285 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8286 else if (game_status == GAME_MODE_INFO)
8287 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);