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_INSERT_SOLUTION 4
176 #define SCREEN_CTRL_ID_PLAY_SOLUTION 5
177 #define SCREEN_CTRL_ID_SCROLL_UP 6
178 #define SCREEN_CTRL_ID_SCROLL_DOWN 7
179 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 8
181 #define NUM_SCREEN_GADGETS 9
183 #define NUM_SCREEN_MENUBUTTONS 6
184 #define NUM_SCREEN_SCROLLBUTTONS 2
185 #define NUM_SCREEN_SCROLLBARS 1
187 #define SCREEN_MASK_MAIN (1 << 0)
188 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
189 #define SCREEN_MASK_INPUT (1 << 2)
191 /* graphic position and size values for buttons and scrollbars */
192 #define SC_MENUBUTTON_XSIZE TILEX
193 #define SC_MENUBUTTON_YSIZE TILEY
195 #define SC_SCROLLBUTTON_XSIZE TILEX
196 #define SC_SCROLLBUTTON_YSIZE TILEY
198 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
200 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
201 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
202 SC_SCROLLBUTTON_YSIZE)
204 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
205 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
207 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
208 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
209 SC_SCROLLBUTTON_YSIZE)
211 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
212 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
213 SC_SCROLL_VERTICAL_YSIZE)
215 #define SC_BORDER_SIZE 14
218 /* forward declarations of internal functions */
219 static void HandleScreenGadgets(struct GadgetInfo *);
220 static void HandleSetupScreen_Generic(int, int, int, int, int);
221 static void HandleSetupScreen_Input(int, int, int, int, int);
222 static void CustomizeKeyboard(int);
223 static void ConfigureJoystick(int);
224 static void ConfigureVirtualButtons();
225 static void execSetupGame(void);
226 static void execSetupGraphics(void);
227 static void execSetupSound(void);
228 static void execSetupTouch(void);
229 static void execSetupArtwork(void);
230 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
232 static void DrawChooseLevelSet(void);
233 static void DrawChooseLevelNr(void);
234 static void DrawInfoScreen(void);
235 static void DrawSetupScreen(void);
237 static void DrawInfoScreen_NotAvailable(char *, char *);
238 static void DrawInfoScreen_HelpAnim(int, int, boolean);
239 static void DrawInfoScreen_HelpText(int, int, int, int);
240 static void HandleInfoScreen_Main(int, int, int, int, int);
241 static void HandleInfoScreen_TitleScreen(int);
242 static void HandleInfoScreen_Elements(int);
243 static void HandleInfoScreen_Music(int);
244 static void HandleInfoScreen_Credits(int);
245 static void HandleInfoScreen_Program(int);
246 static void HandleInfoScreen_Version(int);
248 static void MapScreenMenuGadgets(int);
249 static void MapScreenGadgets(int);
250 static void MapScreenTreeGadgets(TreeInfo *);
252 static void UpdateScreenMenuGadgets(int, boolean);
254 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
256 static int info_mode = INFO_MODE_MAIN;
257 static int setup_mode = SETUP_MODE_MAIN;
259 static TreeInfo *window_sizes = NULL;
260 static TreeInfo *window_size_current = NULL;
262 static TreeInfo *scaling_types = NULL;
263 static TreeInfo *scaling_type_current = NULL;
265 static TreeInfo *rendering_modes = NULL;
266 static TreeInfo *rendering_mode_current = NULL;
268 static TreeInfo *scroll_delays = NULL;
269 static TreeInfo *scroll_delay_current = NULL;
271 static TreeInfo *snapshot_modes = NULL;
272 static TreeInfo *snapshot_mode_current = NULL;
274 static TreeInfo *game_speeds = NULL;
275 static TreeInfo *game_speed_current = NULL;
277 static TreeInfo *volumes_simple = NULL;
278 static TreeInfo *volume_simple_current = NULL;
280 static TreeInfo *volumes_loops = NULL;
281 static TreeInfo *volume_loops_current = NULL;
283 static TreeInfo *volumes_music = NULL;
284 static TreeInfo *volume_music_current = NULL;
286 static TreeInfo *touch_controls = NULL;
287 static TreeInfo *touch_control_current = NULL;
289 static TreeInfo *move_distances = NULL;
290 static TreeInfo *move_distance_current = NULL;
292 static TreeInfo *drop_distances = NULL;
293 static TreeInfo *drop_distance_current = NULL;
295 static TreeInfo *transparencies = NULL;
296 static TreeInfo *transparency_current = NULL;
298 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
299 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
301 static TreeInfo *level_number = NULL;
302 static TreeInfo *level_number_current = NULL;
308 } window_sizes_list[] =
313 { 100, "100 % (Default)" },
330 } scaling_types_list[] =
332 { SCALING_QUALITY_NEAREST, "Off" },
333 { SCALING_QUALITY_LINEAR, "Linear" },
334 { SCALING_QUALITY_BEST, "Anisotropic" },
343 } rendering_modes_list[] =
345 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
346 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
348 // this mode may work under certain conditions, but does not work on Windows
349 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
351 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
360 } game_speeds_list[] =
369 { 1000, "1/1s (Extremely Slow)" },
374 { 29, "1/35s (Original Supaplex)" },
376 { 20, "1/50s (Normal Speed)" },
377 { 14, "1/70s (Maximum Supaplex)" },
381 { 1, "1/1000s (Extremely Fast)" },
391 } scroll_delays_list[] =
393 { 0, "0 Tiles (No Scroll Delay)" },
396 { 3, "3 Tiles (Default)" },
401 { 8, "8 Tiles (Maximum Scroll Delay)"},
410 } snapshot_modes_list[] =
412 { STR_SNAPSHOT_MODE_OFF, "Off" },
413 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
414 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
415 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
448 } touch_controls_list[] =
450 { TOUCH_CONTROL_OFF, "Off" },
451 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
452 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
453 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
481 } transparencies_list[] =
483 { 0, "0 % (Opaque)" },
493 { 100, "100 % (Invisible)" },
502 } grid_sizes_list[] =
538 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
539 (s) <= GAME_MODE_SETUP ? (s) : \
540 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
541 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
543 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
544 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
545 (i) <= INFO_MODE_LEVELSET ? (i) : \
548 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
549 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
550 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
551 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
552 SETUP_MODE_CHOOSE_ARTWORK : \
553 SETUP_MODE_CHOOSE_OTHER)
555 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
556 menu.draw_xoffset[GAME_MODE_INFO] : \
557 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
558 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
559 menu.draw_yoffset[GAME_MODE_INFO] : \
560 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
561 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
562 menu.extra_spacing[GAME_MODE_INFO] : \
563 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
565 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
566 menu.draw_xoffset[GAME_MODE_SETUP] : \
567 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
568 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
569 menu.draw_yoffset[GAME_MODE_SETUP] : \
570 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
571 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
572 menu.extra_spacing[GAME_MODE_SETUP] : \
573 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
575 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
576 DRAW_XOFFSET_INFO(info_mode) : \
577 (s) == GAME_MODE_SETUP ? \
578 DRAW_XOFFSET_SETUP(setup_mode) : \
579 menu.draw_xoffset[DRAW_MODE(s)])
580 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
581 DRAW_YOFFSET_INFO(info_mode) : \
582 (s) == GAME_MODE_SETUP ? \
583 DRAW_YOFFSET_SETUP(setup_mode) : \
584 menu.draw_yoffset[DRAW_MODE(s)])
585 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
586 EXTRA_SPACING_INFO(info_mode) : \
587 (s) == GAME_MODE_SETUP ? \
588 EXTRA_SPACING_SETUP(setup_mode) : \
589 menu.extra_spacing[DRAW_MODE(s)])
591 #define mSX (SX + DRAW_XOFFSET(game_status))
592 #define mSY (SY + DRAW_YOFFSET(game_status))
594 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
595 menu.list_size[game_status] : \
596 MAX_MENU_ENTRIES_ON_SCREEN)
598 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
599 NUM_MENU_ENTRIES_ON_SCREEN)
602 /* title display and control definitions */
604 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
605 2 * MAX_NUM_TITLE_MESSAGES)
607 #define NO_DIRECT_LEVEL_SELECT (-1)
610 static int num_title_screens = 0;
612 struct TitleControlInfo
621 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
623 /* main menu display and control definitions */
625 #define MAIN_CONTROL_NAME 0
626 #define MAIN_CONTROL_LEVELS 1
627 #define MAIN_CONTROL_SCORES 2
628 #define MAIN_CONTROL_EDITOR 3
629 #define MAIN_CONTROL_INFO 4
630 #define MAIN_CONTROL_GAME 5
631 #define MAIN_CONTROL_SETUP 6
632 #define MAIN_CONTROL_QUIT 7
633 #define MAIN_CONTROL_PREV_LEVEL 8
634 #define MAIN_CONTROL_NEXT_LEVEL 9
635 #define MAIN_CONTROL_FIRST_LEVEL 10
636 #define MAIN_CONTROL_LAST_LEVEL 11
637 #define MAIN_CONTROL_LEVEL_NUMBER 12
638 #define MAIN_CONTROL_LEVEL_INFO_1 13
639 #define MAIN_CONTROL_LEVEL_INFO_2 14
640 #define MAIN_CONTROL_LEVEL_NAME 15
641 #define MAIN_CONTROL_LEVEL_AUTHOR 16
642 #define MAIN_CONTROL_LEVEL_YEAR 17
643 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
644 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
645 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
646 #define MAIN_CONTROL_TITLE_1 21
647 #define MAIN_CONTROL_TITLE_2 22
648 #define MAIN_CONTROL_TITLE_3 23
650 static char str_main_text_name[10];
651 static char str_main_text_first_level[10];
652 static char str_main_text_last_level[10];
653 static char str_main_text_level_number[10];
655 static char *main_text_name = str_main_text_name;
656 static char *main_text_first_level = str_main_text_first_level;
657 static char *main_text_last_level = str_main_text_last_level;
658 static char *main_text_level_number = str_main_text_level_number;
659 static char *main_text_levels = "Levelset";
660 static char *main_text_scores = "Hall Of Fame";
661 static char *main_text_editor = "Level Creator";
662 static char *main_text_info = "Info Screen";
663 static char *main_text_game = "Start Game";
664 static char *main_text_setup = "Setup";
665 static char *main_text_quit = "Quit";
666 static char *main_text_level_name = level.name;
667 static char *main_text_level_author = level.author;
668 static char *main_text_level_year = NULL;
669 static char *main_text_level_imported_from = NULL;
670 static char *main_text_level_imported_by = NULL;
671 static char *main_text_level_tested_by = NULL;
672 static char *main_text_title_1 = NULL;
673 static char *main_text_title_2 = NULL;
674 static char *main_text_title_3 = NULL;
676 struct MainControlInfo
680 struct MenuPosInfo *pos_button;
683 struct TextPosInfo *pos_text;
686 struct TextPosInfo *pos_input;
690 static struct MainControlInfo main_controls[] =
694 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
695 &menu.main.text.name, &main_text_name,
696 &menu.main.input.name, &setup.player_name,
700 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
701 &menu.main.text.levels, &main_text_levels,
706 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
707 &menu.main.text.scores, &main_text_scores,
712 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
713 &menu.main.text.editor, &main_text_editor,
718 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
719 &menu.main.text.info, &main_text_info,
724 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
725 &menu.main.text.game, &main_text_game,
730 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
731 &menu.main.text.setup, &main_text_setup,
736 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
737 &menu.main.text.quit, &main_text_quit,
741 /* (these two buttons are real gadgets) */
743 MAIN_CONTROL_PREV_LEVEL,
744 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
749 MAIN_CONTROL_NEXT_LEVEL,
750 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
756 MAIN_CONTROL_FIRST_LEVEL,
757 &menu.main.button.first_level, IMG_MENU_BUTTON_FIRST_LEVEL,
758 &menu.main.text.first_level, &main_text_first_level,
762 MAIN_CONTROL_LAST_LEVEL,
763 &menu.main.button.last_level, IMG_MENU_BUTTON_LAST_LEVEL,
764 &menu.main.text.last_level, &main_text_last_level,
768 MAIN_CONTROL_LEVEL_NUMBER,
769 &menu.main.button.level_number, IMG_MENU_BUTTON_LEVEL_NUMBER,
770 &menu.main.text.level_number, &main_text_level_number,
774 MAIN_CONTROL_LEVEL_INFO_1,
776 &menu.main.text.level_info_1, NULL,
780 MAIN_CONTROL_LEVEL_INFO_2,
782 &menu.main.text.level_info_2, NULL,
786 MAIN_CONTROL_LEVEL_NAME,
788 &menu.main.text.level_name, &main_text_level_name,
792 MAIN_CONTROL_LEVEL_AUTHOR,
794 &menu.main.text.level_author, &main_text_level_author,
798 MAIN_CONTROL_LEVEL_YEAR,
800 &menu.main.text.level_year, &main_text_level_year,
804 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
806 &menu.main.text.level_imported_from, &main_text_level_imported_from,
810 MAIN_CONTROL_LEVEL_IMPORTED_BY,
812 &menu.main.text.level_imported_by, &main_text_level_imported_by,
816 MAIN_CONTROL_LEVEL_TESTED_BY,
818 &menu.main.text.level_tested_by, &main_text_level_tested_by,
822 MAIN_CONTROL_TITLE_1,
824 &menu.main.text.title_1, &main_text_title_1,
828 MAIN_CONTROL_TITLE_2,
830 &menu.main.text.title_2, &main_text_title_2,
834 MAIN_CONTROL_TITLE_3,
836 &menu.main.text.title_3, &main_text_title_3,
849 static int getTitleScreenGraphic(int nr, boolean initial)
851 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
854 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
856 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
860 static int getTitleScreenGameMode(boolean initial)
862 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
866 static int getTitleMessageGameMode(boolean initial)
868 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
871 static int getTitleAnimMode(struct TitleControlInfo *tci)
873 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
875 return base + tci->local_nr;
879 static int getTitleScreenBackground(boolean initial)
881 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
886 static int getTitleMessageBackground(int nr, boolean initial)
888 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
892 static int getTitleBackground(int nr, boolean initial, boolean is_image)
894 int base = (is_image ?
895 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
896 IMG_BACKGROUND_TITLESCREEN_1) :
897 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
898 IMG_BACKGROUND_TITLEMESSAGE_1));
899 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
900 IMG_BACKGROUND_TITLE);
901 int graphic_local = base + nr;
903 if (graphic_info[graphic_local].bitmap != NULL)
904 return graphic_local;
906 if (graphic_info[graphic_global].bitmap != NULL)
907 return graphic_global;
909 return IMG_UNDEFINED;
912 static int getTitleSound(struct TitleControlInfo *tci)
914 boolean is_image = tci->is_image;
915 int initial = tci->initial;
916 int nr = tci->local_nr;
917 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
918 int base = (is_image ?
919 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
920 SND_BACKGROUND_TITLESCREEN_1) :
921 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
922 SND_BACKGROUND_TITLEMESSAGE_1));
923 int sound_global = menu.sound[mode];
924 int sound_local = base + nr;
927 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
928 nr, initial, is_image,
929 sound_global, getSoundListEntry(sound_global)->filename,
930 sound_local, getSoundListEntry(sound_local)->filename);
933 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
936 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
939 return SND_UNDEFINED;
942 static int getTitleMusic(struct TitleControlInfo *tci)
944 boolean is_image = tci->is_image;
945 int initial = tci->initial;
946 int nr = tci->local_nr;
947 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
948 int base = (is_image ?
949 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
950 MUS_BACKGROUND_TITLESCREEN_1) :
951 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
952 MUS_BACKGROUND_TITLEMESSAGE_1));
953 int music_global = menu.music[mode];
954 int music_local = base + nr;
957 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
958 nr, initial, is_image,
959 music_global, getMusicListEntry(music_global)->filename,
960 music_local, getMusicListEntry(music_local)->filename);
963 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
966 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
969 return MUS_UNDEFINED;
972 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
974 boolean is_image = tci->is_image;
975 boolean initial = tci->initial;
976 boolean first = tci->first;
977 int nr = tci->local_nr;
978 struct TitleMessageInfo tmi;
979 struct TitleFadingInfo ti;
981 tmi = (is_image ? (initial ? (first ?
982 titlescreen_initial_first[nr] :
983 titlescreen_initial[nr])
985 titlescreen_first[nr] :
987 : (initial ? (first ?
988 titlemessage_initial_first[nr] :
989 titlemessage_initial[nr])
991 titlemessage_first[nr] :
994 ti.fade_mode = tmi.fade_mode;
995 ti.fade_delay = tmi.fade_delay;
996 ti.post_delay = tmi.post_delay;
997 ti.auto_delay = tmi.auto_delay;
1002 static int compareTitleControlInfo(const void *object1, const void *object2)
1004 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1005 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1008 if (tci1->initial != tci2->initial)
1009 compare_result = (tci1->initial ? -1 : +1);
1010 else if (tci1->sort_priority != tci2->sort_priority)
1011 compare_result = tci1->sort_priority - tci2->sort_priority;
1012 else if (tci1->is_image != tci2->is_image)
1013 compare_result = (tci1->is_image ? -1 : +1);
1015 compare_result = tci1->local_nr - tci2->local_nr;
1017 return compare_result;
1020 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1022 int nr, int sort_priority)
1024 title_controls[num_title_screens].is_image = is_image;
1025 title_controls[num_title_screens].initial = initial;
1026 title_controls[num_title_screens].local_nr = nr;
1027 title_controls[num_title_screens].sort_priority = sort_priority;
1029 title_controls[num_title_screens].first = FALSE; /* will be set later */
1031 num_title_screens++;
1034 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1038 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1040 int graphic = getTitleScreenGraphic(i, initial);
1041 Bitmap *bitmap = graphic_info[graphic].bitmap;
1042 int sort_priority = graphic_info[graphic].sort_priority;
1045 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1048 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1050 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1051 char *filename = getLevelSetTitleMessageFilename(i, initial);
1052 int sort_priority = tmi->sort_priority;
1054 if (filename != NULL)
1055 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1059 static void InitializeTitleControls(boolean show_title_initial)
1061 num_title_screens = 0;
1063 /* 1st step: initialize title screens for game start (only when starting) */
1064 if (show_title_initial)
1065 InitializeTitleControls_CheckTitleInfo(TRUE);
1067 /* 2nd step: initialize title screens for current level set */
1068 InitializeTitleControls_CheckTitleInfo(FALSE);
1070 /* sort title screens according to sort_priority and title number */
1071 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1072 compareTitleControlInfo);
1074 /* mark first title screen */
1075 title_controls[0].first = TRUE;
1078 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1080 return (pos != NULL && pos->x != -1 && pos->y != -1);
1083 static boolean visibleTextPos(struct TextPosInfo *pos)
1085 return (pos != NULL && pos->x != -1 && pos->y != -1);
1088 static void InitializeMainControls()
1090 boolean local_team_mode = (!network.enabled && setup.team_mode);
1093 /* set main control text values to dynamically determined values */
1094 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1096 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1097 menu.main.text.first_level.size));
1098 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1099 menu.main.text.last_level.size));
1100 strcpy(main_text_level_number, int2str(level_nr,
1101 menu.main.text.level_number.size));
1103 main_text_level_year = leveldir_current->year;
1104 main_text_level_imported_from = leveldir_current->imported_from;
1105 main_text_level_imported_by = leveldir_current->imported_by;
1106 main_text_level_tested_by = leveldir_current->tested_by;
1108 main_text_title_1 = getConfigProgramTitleString();
1109 main_text_title_2 = getConfigProgramCopyrightString();
1110 main_text_title_3 = getConfigProgramCompanyString();
1112 /* set main control screen positions to dynamically determined values */
1113 for (i = 0; main_controls[i].nr != -1; i++)
1115 struct MainControlInfo *mci = &main_controls[i];
1117 struct MenuPosInfo *pos_button = mci->pos_button;
1118 struct TextPosInfo *pos_text = mci->pos_text;
1119 struct TextPosInfo *pos_input = mci->pos_input;
1120 char *text = (mci->text ? *mci->text : NULL);
1121 char *input = (mci->input ? *mci->input : NULL);
1122 int button_graphic = mci->button_graphic;
1123 int font_text = (pos_text ? pos_text->font : -1);
1124 int font_input = (pos_input ? pos_input->font : -1);
1126 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1127 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1128 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1129 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1130 int text_chars = (text != NULL ? strlen(text) : 0);
1131 int input_chars = (input != NULL ? strlen(input) : 0);
1134 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1136 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1137 int text_width = font_text_width * text_chars;
1138 int text_height = font_text_height;
1139 int input_width = font_input_width * input_chars;
1140 int input_height = font_input_height;
1142 if (nr == MAIN_CONTROL_NAME)
1144 menu.main.input.name.width = input_width;
1145 menu.main.input.name.height = input_height;
1148 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1150 pos_button->width = button_width;
1151 pos_button->height = button_height;
1154 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1156 /* calculate text size -- needed for text alignment */
1157 boolean calculate_text_size = (text != NULL);
1159 if (pos_text->width == -1 || calculate_text_size)
1160 pos_text->width = text_width;
1161 if (pos_text->height == -1 || calculate_text_size)
1162 pos_text->height = text_height;
1164 if (visibleMenuPos(pos_button))
1166 if (pos_text->x == -1)
1167 pos_text->x = pos_button->x + pos_button->width;
1168 if (pos_text->y == -1)
1170 pos_button->y + (pos_button->height - pos_text->height) / 2;
1174 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1176 if (visibleTextPos(pos_text))
1178 if (pos_input->x == -1)
1179 pos_input->x = pos_text->x + pos_text->width;
1180 if (pos_input->y == -1)
1181 pos_input->y = pos_text->y;
1184 if (pos_input->width == -1)
1185 pos_input->width = input_width;
1186 if (pos_input->height == -1)
1187 pos_input->height = input_height;
1192 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1193 int graphic, boolean pressed)
1195 struct GraphicInfo *g = &graphic_info[graphic];
1198 int xoffset = (pressed ? g->pressed_xoffset : 0);
1199 int yoffset = (pressed ? g->pressed_yoffset : 0);
1201 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1203 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1204 g->width, g->height, dst_x, dst_y);
1207 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1208 boolean active_input,
1209 boolean pressed_button)
1213 for (i = 0; main_controls[i].nr != -1; i++)
1215 struct MainControlInfo *mci = &main_controls[i];
1217 if (mci->nr == nr || nr == -1)
1219 struct MenuPosInfo *pos_button = mci->pos_button;
1220 struct TextPosInfo *pos_text = mci->pos_text;
1221 struct TextPosInfo *pos_input = mci->pos_input;
1222 char *text = (mci->text ? *mci->text : NULL);
1223 char *input = (mci->input ? *mci->input : NULL);
1224 int button_graphic = mci->button_graphic;
1225 int font_text = (pos_text ? pos_text->font : -1);
1226 int font_input = (pos_input ? pos_input->font : -1);
1230 button_graphic = BUTTON_ACTIVE(button_graphic);
1231 font_text = FONT_ACTIVE(font_text);
1236 font_input = FONT_ACTIVE(font_input);
1239 if (visibleMenuPos(pos_button))
1241 struct MenuPosInfo *pos = pos_button;
1242 int x = mSX + pos->x;
1243 int y = mSY + pos->y;
1245 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1246 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1249 if (visibleTextPos(pos_text) && text != NULL)
1251 struct TextPosInfo *pos = pos_text;
1252 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1253 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1256 /* (check why/if this is needed) */
1257 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1259 DrawText(x, y, text, font_text);
1262 if (visibleTextPos(pos_input) && input != NULL)
1264 struct TextPosInfo *pos = pos_input;
1265 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1266 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1269 /* (check why/if this is needed) */
1270 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1272 DrawText(x, y, input, font_input);
1278 static void DrawCursorAndText_Main(int nr, boolean active_text,
1279 boolean pressed_button)
1281 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1285 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1286 boolean pressed_button)
1288 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1292 static struct MainControlInfo *getMainControlInfo(int nr)
1296 for (i = 0; main_controls[i].nr != -1; i++)
1297 if (main_controls[i].nr == nr)
1298 return &main_controls[i];
1303 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1308 int rect_x = ALIGNED_TEXT_XPOS(rect);
1309 int rect_y = ALIGNED_TEXT_YPOS(rect);
1311 return (x >= rect_x && x < rect_x + rect->width &&
1312 y >= rect_y && y < rect_y + rect->height);
1315 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1320 int rect_x = ALIGNED_TEXT_XPOS(rect);
1321 int rect_y = ALIGNED_TEXT_YPOS(rect);
1324 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1325 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1326 (x >= rect_x && x < rect_x + rect->width &&
1327 y >= rect_y && y < rect_y + rect->height));
1330 return (x >= rect_x && x < rect_x + rect->width &&
1331 y >= rect_y && y < rect_y + rect->height);
1334 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1336 int rect_width = preview->xsize * preview->tile_size;
1337 int rect_height = preview->ysize * preview->tile_size;
1338 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1339 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1341 return (x >= rect_x && x < rect_x + rect_width &&
1342 y >= rect_y && y < rect_y + rect_height);
1345 static void AdjustScrollbar(int id, int items_max, int items_visible,
1348 struct GadgetInfo *gi = screen_gadget[id];
1350 if (item_position > items_max - items_visible)
1351 item_position = items_max - items_visible;
1353 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1354 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1355 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1358 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1360 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1364 static void clearMenuListArea()
1366 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1368 /* correct scrollbar position if placed outside menu (playfield) area */
1369 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1370 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1372 /* clear menu list area, but not title or scrollbar */
1373 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1374 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1377 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1379 static int cursor_array[MAX_LEV_FIELDY];
1380 int x = mSX + TILEX * xpos;
1381 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1386 cursor_array[ypos] = graphic;
1388 graphic = cursor_array[ypos];
1392 graphic = BUTTON_ACTIVE(graphic);
1394 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1395 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1398 static void initCursor(int ypos, int graphic)
1400 drawCursorExt(0, ypos, FALSE, graphic);
1403 static void drawCursor(int ypos, boolean active)
1405 drawCursorExt(0, ypos, active, -1);
1408 static void drawCursorXY(int xpos, int ypos, int graphic)
1410 drawCursorExt(xpos, ypos, FALSE, graphic);
1413 static void drawChooseTreeCursor(int ypos, boolean active)
1415 drawCursorExt(0, ypos, active, -1);
1420 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1421 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1424 void DrawTitleScreenImage(int nr, boolean initial)
1426 int graphic = getTitleScreenGraphic(nr, initial);
1427 Bitmap *bitmap = graphic_info[graphic].bitmap;
1428 int width = graphic_info[graphic].width;
1429 int height = graphic_info[graphic].height;
1430 int src_x = graphic_info[graphic].src_x;
1431 int src_y = graphic_info[graphic].src_y;
1437 if (width > WIN_XSIZE)
1439 /* image width too large for window => center image horizontally */
1440 src_x = (width - WIN_XSIZE) / 2;
1444 if (height > WIN_YSIZE)
1446 /* image height too large for window => center image vertically */
1447 src_y = (height - WIN_YSIZE) / 2;
1451 /* always display title screens centered */
1452 dst_x = (WIN_XSIZE - width) / 2;
1453 dst_y = (WIN_YSIZE - height) / 2;
1455 SetDrawBackgroundMask(REDRAW_ALL);
1456 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1458 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1460 if (DrawingOnBackground(dst_x, dst_y))
1461 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1463 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1465 redraw_mask = REDRAW_ALL;
1468 void DrawTitleScreenMessage(int nr, boolean initial)
1470 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1471 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1473 if (filename == NULL)
1476 /* force TITLE font on title message screen */
1477 SetFontStatus(getTitleMessageGameMode(initial));
1479 /* if chars *and* width set to "-1", automatically determine width */
1480 if (tmi->chars == -1 && tmi->width == -1)
1481 tmi->width = viewport.window[game_status].width;
1483 /* if lines *and* height set to "-1", automatically determine height */
1484 if (tmi->lines == -1 && tmi->height == -1)
1485 tmi->height = viewport.window[game_status].height;
1487 /* if chars set to "-1", automatically determine by text and font width */
1488 if (tmi->chars == -1)
1489 tmi->chars = tmi->width / getFontWidth(tmi->font);
1491 tmi->width = tmi->chars * getFontWidth(tmi->font);
1493 /* if lines set to "-1", automatically determine by text and font height */
1494 if (tmi->lines == -1)
1495 tmi->lines = tmi->height / getFontHeight(tmi->font);
1497 tmi->height = tmi->lines * getFontHeight(tmi->font);
1499 /* if x set to "-1", automatically determine by width and alignment */
1501 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1503 /* if y set to "-1", automatically determine by height and alignment */
1505 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1507 SetDrawBackgroundMask(REDRAW_ALL);
1508 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1510 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1512 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1513 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1514 tmi->autowrap, tmi->centered, tmi->parse_comments);
1519 void DrawTitleScreen()
1521 KeyboardAutoRepeatOff();
1523 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1526 boolean CheckTitleScreen(boolean levelset_has_changed)
1528 static boolean show_title_initial = TRUE;
1529 boolean show_titlescreen = FALSE;
1531 /* needed to be able to skip title screen, if no image or message defined */
1532 InitializeTitleControls(show_title_initial);
1534 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1535 show_titlescreen = TRUE;
1537 /* show initial title images and messages only once at program start */
1538 show_title_initial = FALSE;
1540 return (show_titlescreen && num_title_screens > 0);
1545 static LevelDirTree *leveldir_last_valid = NULL;
1546 boolean levelset_has_changed = FALSE;
1547 int fade_mask = REDRAW_FIELD;
1549 LimitScreenUpdates(FALSE);
1551 FadeSetLeaveScreen();
1553 /* do not fade out here -- function may continue and fade on editor screen */
1556 FadeMenuSoundsAndMusic();
1558 ExpireSoundLoops(FALSE);
1560 KeyboardAutoRepeatOn();
1562 audio.sound_deactivated = FALSE;
1566 /* needed if last screen was the playing screen, invoked from level editor */
1567 if (level_editor_test_game)
1569 CloseDoor(DOOR_CLOSE_ALL);
1571 SetGameStatus(GAME_MODE_EDITOR);
1578 /* needed if last screen was the setup screen and fullscreen state changed */
1579 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1580 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1582 /* leveldir_current may be invalid (level group, parent link) */
1583 if (!validLevelSeries(leveldir_current))
1584 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1586 if (leveldir_current != leveldir_last_valid)
1587 levelset_has_changed = TRUE;
1589 /* store valid level series information */
1590 leveldir_last_valid = leveldir_current;
1592 init_last = init; /* switch to new busy animation */
1594 SetLevelSetInfo(leveldir_current->identifier, level_nr);
1596 /* needed if last screen (level choice) changed graphics, sounds or music */
1597 ReloadCustomArtwork(0);
1599 if (CheckTitleScreen(levelset_has_changed))
1601 SetGameStatus(GAME_MODE_TITLE);
1608 if (redraw_mask & REDRAW_ALL)
1609 fade_mask = REDRAW_ALL;
1611 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1612 fade_mask = REDRAW_ALL;
1616 /* needed if different viewport properties defined for menues */
1617 ChangeViewportPropertiesIfNeeded();
1619 SetDrawtoField(DRAW_TO_BACKBUFFER);
1621 /* level_nr may have been set to value over handicap with level editor */
1622 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1623 level_nr = leveldir_current->handicap_level;
1625 LoadLevel(level_nr);
1626 LoadScore(level_nr);
1628 SaveLevelSetup_SeriesInfo();
1630 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1631 SetDrawDeactivationMask(REDRAW_NONE);
1632 SetDrawBackgroundMask(REDRAW_FIELD);
1634 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1637 if (fade_mask == REDRAW_ALL)
1638 RedrawGlobalBorder();
1643 InitializeMainControls();
1645 DrawCursorAndText_Main(-1, FALSE, FALSE);
1646 DrawPreviewLevelInitial();
1647 DrawNetworkPlayers();
1649 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1652 if (TAPE_IS_EMPTY(tape))
1654 DrawCompleteVideoDisplay();
1656 PlayMenuSoundsAndMusic();
1658 /* create gadgets for main menu screen */
1659 FreeScreenGadgets();
1660 CreateScreenGadgets();
1662 /* may be required if audio buttons shown on tape and changed in setup menu */
1664 CreateGameButtons();
1666 /* map gadgets for main menu screen */
1668 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1669 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1671 /* copy actual game door content to door double buffer for OpenDoor() */
1672 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1673 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1675 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1677 DrawMaskedBorder(fade_mask);
1682 /* update screen area with special editor door */
1683 redraw_mask |= REDRAW_ALL;
1686 SetMouseCursor(CURSOR_DEFAULT);
1688 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1691 static void gotoTopLevelDir()
1693 /* move upwards until inside (but not above) top level directory */
1694 while (leveldir_current->node_parent &&
1695 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1697 /* write a "path" into level tree for easy navigation to last level */
1698 if (leveldir_current->node_parent->node_group->cl_first == -1)
1700 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1701 int leveldir_pos = posTreeInfo(leveldir_current);
1702 int num_page_entries;
1703 int cl_first, cl_cursor;
1705 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1706 num_page_entries = num_leveldirs;
1708 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1710 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1711 cl_cursor = leveldir_pos - cl_first;
1713 leveldir_current->node_parent->node_group->cl_first = cl_first;
1714 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1717 leveldir_current = leveldir_current->node_parent;
1721 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1723 static unsigned int title_delay = 0;
1724 static int title_screen_nr = 0;
1725 static int last_sound = -1, last_music = -1;
1726 boolean return_to_main_menu = FALSE;
1727 struct TitleControlInfo *tci;
1730 if (button == MB_MENU_INITIALIZE)
1733 title_screen_nr = 0;
1734 tci = &title_controls[title_screen_nr];
1736 SetAnimStatus(getTitleAnimMode(tci));
1738 last_sound = SND_UNDEFINED;
1739 last_music = MUS_UNDEFINED;
1741 if (num_title_screens != 0)
1743 FadeSetEnterScreen();
1745 /* use individual title fading instead of global "enter screen" fading */
1746 fading = getTitleFading(tci);
1749 if (game_status_last_screen == GAME_MODE_INFO)
1751 if (num_title_screens == 0)
1753 /* switch game mode from title screen mode back to info screen mode */
1754 SetGameStatus(GAME_MODE_INFO);
1756 /* store that last screen was info screen, not main menu screen */
1757 game_status_last_screen = GAME_MODE_INFO;
1759 DrawInfoScreen_NotAvailable("Title screen information:",
1760 "No title screen for this level set.");
1764 FadeMenuSoundsAndMusic();
1767 FadeOut(REDRAW_ALL);
1769 /* title screens may have different window size */
1770 ChangeViewportPropertiesIfNeeded();
1772 /* only required to update logic for redrawing global border */
1776 DrawTitleScreenImage(tci->local_nr, tci->initial);
1778 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1780 sound = getTitleSound(tci);
1781 music = getTitleMusic(tci);
1783 if (sound != last_sound)
1784 PlayMenuSoundExt(sound);
1785 if (music != last_music)
1786 PlayMenuMusicExt(music);
1791 SetMouseCursor(CURSOR_NONE);
1795 DelayReached(&title_delay, 0); /* reset delay counter */
1800 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1801 button = MB_MENU_CHOICE;
1803 if (button == MB_MENU_LEAVE)
1805 return_to_main_menu = TRUE;
1807 else if (button == MB_MENU_CHOICE)
1809 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1811 SetGameStatus(GAME_MODE_INFO);
1813 info_mode = INFO_MODE_MAIN;
1822 if (title_screen_nr < num_title_screens)
1824 tci = &title_controls[title_screen_nr];
1826 SetAnimStatus(getTitleAnimMode(tci));
1828 sound = getTitleSound(tci);
1829 music = getTitleMusic(tci);
1831 if (last_sound != SND_UNDEFINED && sound != last_sound)
1832 FadeSound(last_sound);
1833 if (last_music != MUS_UNDEFINED && music != last_music)
1836 fading = getTitleFading(tci);
1838 FadeOut(REDRAW_ALL);
1841 DrawTitleScreenImage(tci->local_nr, tci->initial);
1843 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1845 sound = getTitleSound(tci);
1846 music = getTitleMusic(tci);
1848 if (sound != last_sound)
1849 PlayMenuSoundExt(sound);
1850 if (music != last_music)
1851 PlayMenuMusicExt(music);
1858 DelayReached(&title_delay, 0); /* reset delay counter */
1862 FadeMenuSoundsAndMusic();
1864 return_to_main_menu = TRUE;
1868 if (return_to_main_menu)
1870 SetMouseCursor(CURSOR_DEFAULT);
1872 /* force full menu screen redraw after displaying title screens */
1873 redraw_mask = REDRAW_ALL;
1875 if (game_status_last_screen == GAME_MODE_INFO)
1877 SetGameStatus(GAME_MODE_INFO);
1879 info_mode = INFO_MODE_MAIN;
1883 else /* default: return to main menu */
1885 SetGameStatus(GAME_MODE_MAIN);
1892 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1894 int old_level_nr = level_nr;
1897 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1898 new_level_nr = selected_level_nr;
1900 new_level_nr = old_level_nr + step * direction;
1902 if (new_level_nr < leveldir_current->first_level)
1903 new_level_nr = leveldir_current->first_level;
1904 if (new_level_nr > leveldir_current->last_level)
1905 new_level_nr = leveldir_current->last_level;
1907 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1909 /* skipping levels is only allowed when trying to skip single level */
1910 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1911 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1913 leveldir_current->handicap_level++;
1914 SaveLevelSetup_SeriesInfo();
1917 new_level_nr = leveldir_current->handicap_level;
1920 if (new_level_nr != old_level_nr)
1922 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1924 PlaySound(SND_MENU_ITEM_SELECTING);
1926 level_nr = new_level_nr;
1928 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1929 int2str(level_nr, menu.main.text.level_number.size),
1930 mci->pos_text->font);
1932 LoadLevel(level_nr);
1933 DrawPreviewLevelInitial();
1937 DrawCompleteVideoDisplay();
1939 SaveLevelSetup_SeriesInfo();
1941 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1943 /* needed because DrawPreviewLevelInitial() takes some time */
1945 /* SyncDisplay(); */
1949 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1951 static int choice = MAIN_CONTROL_GAME;
1952 static boolean button_pressed_last = FALSE;
1953 boolean button_pressed = FALSE;
1957 if (button == MB_MENU_INITIALIZE)
1959 DrawCursorAndText_Main(choice, TRUE, FALSE);
1964 if (mx || my) /* mouse input */
1968 for (i = 0; main_controls[i].nr != -1; i++)
1970 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1971 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1972 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1974 pos = main_controls[i].nr;
1980 /* check if level preview was clicked */
1981 if (insidePreviewRect(&preview, mx - SX, my - SY))
1982 pos = MAIN_CONTROL_GAME;
1984 // handle pressed/unpressed state for active/inactive menu buttons
1985 // (if pos != -1, "i" contains index position corresponding to "pos")
1987 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1988 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1989 button_pressed = TRUE;
1991 if (button_pressed != button_pressed_last)
1993 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1996 PlaySound(SND_MENU_BUTTON_PRESSING);
1998 PlaySound(SND_MENU_BUTTON_RELEASING);
2001 else if (dx || dy) /* keyboard input */
2003 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2004 choice == MAIN_CONTROL_SETUP))
2005 button = MB_MENU_CHOICE;
2010 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2012 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2014 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2016 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2018 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2020 CloseDoor(DOOR_CLOSE_2);
2022 SetGameStatus(GAME_MODE_LEVELNR);
2024 DrawChooseLevelNr();
2026 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2032 PlaySound(SND_MENU_ITEM_ACTIVATING);
2034 DrawCursorAndText_Main(choice, FALSE, FALSE);
2035 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2041 if (choice != MAIN_CONTROL_INFO &&
2042 choice != MAIN_CONTROL_SETUP)
2043 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2048 PlaySound(SND_MENU_ITEM_SELECTING);
2050 if (pos == MAIN_CONTROL_NAME)
2052 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2054 HandleTypeName(strlen(setup.player_name), 0);
2056 else if (pos == MAIN_CONTROL_LEVELS)
2060 CloseDoor(DOOR_CLOSE_2);
2062 SetGameStatus(GAME_MODE_LEVELS);
2064 SaveLevelSetup_LastSeries();
2065 SaveLevelSetup_SeriesInfo();
2067 if (setup.internal.choose_from_top_leveldir)
2070 DrawChooseLevelSet();
2073 else if (pos == MAIN_CONTROL_SCORES)
2075 CloseDoor(DOOR_CLOSE_2);
2077 SetGameStatus(GAME_MODE_SCORES);
2079 DrawHallOfFame(level_nr, -1);
2081 else if (pos == MAIN_CONTROL_EDITOR)
2083 if (leveldir_current->readonly &&
2084 !strEqual(setup.player_name, "Artsoft"))
2085 Request("This level is read only!", REQ_CONFIRM);
2087 CloseDoor(DOOR_CLOSE_2);
2089 SetGameStatus(GAME_MODE_EDITOR);
2091 FadeSetEnterScreen();
2095 else if (pos == MAIN_CONTROL_INFO)
2097 CloseDoor(DOOR_CLOSE_2);
2099 SetGameStatus(GAME_MODE_INFO);
2101 info_mode = INFO_MODE_MAIN;
2105 else if (pos == MAIN_CONTROL_GAME)
2107 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2109 else if (pos == MAIN_CONTROL_SETUP)
2111 CloseDoor(DOOR_CLOSE_2);
2113 SetGameStatus(GAME_MODE_SETUP);
2115 setup_mode = SETUP_MODE_MAIN;
2119 else if (pos == MAIN_CONTROL_QUIT)
2121 SaveLevelSetup_LastSeries();
2122 SaveLevelSetup_SeriesInfo();
2124 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2125 SetGameStatus(GAME_MODE_QUIT);
2130 button_pressed_last = button_pressed;
2134 /* ========================================================================= */
2135 /* info screen functions */
2136 /* ========================================================================= */
2138 static struct TokenInfo *info_info;
2139 static int num_info_info; /* number of info entries shown on screen */
2140 static int max_info_info; /* total number of info entries in list */
2142 static void execInfoTitleScreen()
2144 info_mode = INFO_MODE_TITLE;
2149 static void execInfoElements()
2151 info_mode = INFO_MODE_ELEMENTS;
2156 static void execInfoMusic()
2158 info_mode = INFO_MODE_MUSIC;
2163 static void execInfoCredits()
2165 info_mode = INFO_MODE_CREDITS;
2170 static void execInfoProgram()
2172 info_mode = INFO_MODE_PROGRAM;
2177 static void execInfoVersion()
2179 info_mode = INFO_MODE_VERSION;
2184 static void execInfoLevelSet()
2186 info_mode = INFO_MODE_LEVELSET;
2191 static void execExitInfo()
2193 SetGameStatus(GAME_MODE_MAIN);
2198 static struct TokenInfo info_info_main[] =
2200 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2201 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2202 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2203 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2204 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2205 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2206 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2207 { TYPE_EMPTY, NULL, "" },
2208 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2213 static int getMenuTextFont(int type)
2215 if (type & (TYPE_SWITCH |
2228 static struct TokenInfo *setup_info;
2229 static struct TokenInfo setup_info_input[];
2231 static struct TokenInfo *menu_info;
2233 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2234 int screen_pos, int menu_info_pos_raw,
2237 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2238 struct TokenInfo *ti = &token_info[pos];
2239 int xpos = MENU_SCREEN_START_XPOS;
2240 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2241 int font_nr = getMenuTextFont(ti->type);
2243 if (setup_mode == SETUP_MODE_INPUT)
2244 font_nr = FONT_MENU_1;
2247 font_nr = FONT_ACTIVE(font_nr);
2249 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2251 if (ti->type & ~TYPE_SKIP_ENTRY)
2252 drawCursor(screen_pos, active);
2255 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2258 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2261 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2264 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2267 static char *window_size_text;
2268 static char *scaling_type_text;
2270 static void drawSetupValue(int, int);
2272 static void drawMenuInfoList(int first_entry, int num_page_entries,
2273 int max_page_entries)
2277 if (first_entry + num_page_entries > max_page_entries)
2280 clearMenuListArea();
2282 for (i = 0; i < num_page_entries; i++)
2284 int menu_info_pos = first_entry + i;
2285 struct TokenInfo *si = &menu_info[menu_info_pos];
2286 void *value_ptr = si->value;
2288 /* set some entries to "unchangeable" according to other variables */
2289 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2290 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2291 (value_ptr == &setup.sound_music && !audio.music_available) ||
2292 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2293 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2294 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2295 si->type |= TYPE_GHOSTED;
2297 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2298 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2299 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2300 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2301 else if (si->type & ~TYPE_SKIP_ENTRY)
2302 initCursor(i, IMG_MENU_BUTTON);
2304 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2306 if (si->type & TYPE_VALUE &&
2307 menu_info == setup_info)
2308 drawSetupValue(i, menu_info_pos);
2312 static void DrawInfoScreen_Main()
2314 int fade_mask = REDRAW_FIELD;
2317 if (redraw_mask & REDRAW_ALL)
2318 fade_mask = REDRAW_ALL;
2320 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2321 fade_mask = REDRAW_ALL;
2324 FadeMenuSoundsAndMusic();
2326 FreeScreenGadgets();
2327 CreateScreenGadgets();
2329 /* (needed after displaying title screens which disable auto repeat) */
2330 KeyboardAutoRepeatOn();
2332 FadeSetLeaveScreen();
2336 /* needed if different viewport properties defined for info screen */
2337 ChangeViewportPropertiesIfNeeded();
2339 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2343 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2345 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2347 info_info = info_info_main;
2349 // determine maximal number of info entries that can be displayed on screen
2351 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2354 // determine maximal number of info entries available for menu of info screen
2356 for (i = 0; info_info[i].type != 0; i++)
2359 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2361 MapScreenGadgets(max_info_info);
2363 PlayMenuSoundsAndMusic();
2365 DrawMaskedBorder(fade_mask);
2370 static void changeSetupValue(int, int, int);
2372 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2373 int mode, int num_page_entries, int max_page_entries)
2375 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2376 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2377 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2378 int *num_page_entries_last = num_page_entries_all_last[game_status];
2379 int *choice_store = choice_stores[game_status];
2380 int *first_entry_store = first_entry_stores[game_status];
2381 int choice = choice_store[mode]; /* starts with 0 */
2382 int first_entry = first_entry_store[mode]; /* starts with 0 */
2384 int y = choice - first_entry;
2386 boolean position_set_by_scrollbar = (dx == 999);
2387 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2390 if (button == MB_MENU_INITIALIZE)
2392 // check if number of menu page entries has changed (may happen by change
2393 // of custom artwork definition value for 'list_size' for this menu screen)
2394 // (in this case, the last menu position most probably has to be corrected)
2395 if (num_page_entries != num_page_entries_last[mode])
2397 choice_store[mode] = first_entry_store[mode] = 0;
2399 choice = first_entry = 0;
2402 num_page_entries_last[mode] = num_page_entries;
2405 /* advance to first valid menu entry */
2406 while (choice < num_page_entries &&
2407 menu_info[choice].type & TYPE_SKIP_ENTRY)
2410 if (position_set_by_scrollbar)
2411 first_entry = first_entry_store[mode] = dy;
2413 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2414 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2416 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2418 if (choice < first_entry)
2420 choice = first_entry;
2422 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2425 else if (choice > first_entry + num_page_entries - 1)
2427 choice = first_entry + num_page_entries - 1;
2429 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2433 choice_store[mode] = choice;
2435 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2439 else if (button == MB_MENU_LEAVE)
2441 PlaySound(SND_MENU_ITEM_SELECTING);
2443 for (i = 0; i < max_page_entries; i++)
2445 if (menu_info[i].type & TYPE_LEAVE_MENU)
2447 void (*menu_callback_function)(void) = menu_info[i].value;
2451 menu_callback_function();
2453 break; /* absolutely needed because function changes 'menu_info'! */
2460 if (mx || my) /* mouse input */
2462 x = (mx - mSX) / 32;
2463 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2465 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2467 /* move cursor instead of scrolling when already at start/end of list */
2468 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2470 else if (dy == +1 * SCROLL_LINE &&
2471 first_entry + num_page_entries == max_page_entries)
2474 /* handle scrolling screen one line or page */
2476 y + dy > num_page_entries - 1)
2478 boolean redraw = FALSE;
2480 if (ABS(dy) == SCROLL_PAGE)
2481 step = num_page_entries - 1;
2483 if (dy < 0 && first_entry > 0)
2485 /* scroll page/line up */
2487 first_entry -= step;
2488 if (first_entry < 0)
2493 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2495 /* scroll page/line down */
2497 first_entry += step;
2498 if (first_entry + num_page_entries > max_page_entries)
2499 first_entry = MAX(0, max_page_entries - num_page_entries);
2506 choice += first_entry - first_entry_store[mode];
2508 if (choice < first_entry)
2510 choice = first_entry;
2512 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2515 else if (choice > first_entry + num_page_entries - 1)
2517 choice = first_entry + num_page_entries - 1;
2519 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2522 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2526 if (choice < first_entry ||
2527 choice > first_entry + num_page_entries - 1)
2528 first_entry += SIGN(dy);
2531 first_entry_store[mode] = first_entry;
2532 choice_store[mode] = choice;
2534 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2536 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2538 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2539 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2547 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2549 if (menu_info[choice].type & menu_navigation_type ||
2550 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2551 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2552 menu_info[choice].type & TYPE_PLAYER)
2553 button = MB_MENU_CHOICE;
2558 /* jump to next non-empty menu entry (up or down) */
2559 while (first_entry + y > 0 &&
2560 first_entry + y < max_page_entries - 1 &&
2561 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2564 if (!IN_VIS_MENU(x, y))
2566 choice += y - y_old;
2568 if (choice < first_entry)
2569 first_entry = choice;
2570 else if (choice > first_entry + num_page_entries - 1)
2571 first_entry = choice - num_page_entries + 1;
2573 if (first_entry >= 0 &&
2574 first_entry + num_page_entries <= max_page_entries)
2576 first_entry_store[mode] = first_entry;
2578 if (choice < first_entry)
2579 choice = first_entry;
2580 else if (choice > first_entry + num_page_entries - 1)
2581 choice = first_entry + num_page_entries - 1;
2583 choice_store[mode] = choice;
2585 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2587 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2589 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2590 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2597 if (!anyScrollbarGadgetActive() &&
2598 IN_VIS_MENU(x, y) &&
2599 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2600 y >= 0 && y < num_page_entries)
2604 if (first_entry + y != choice &&
2605 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2607 PlaySound(SND_MENU_ITEM_ACTIVATING);
2609 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2610 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2612 choice = choice_store[mode] = first_entry + y;
2616 PlaySound(SND_MENU_ITEM_SELECTING);
2618 for (i = 0; menu_info[i].type != 0; i++)
2620 if (menu_info[i].type & TYPE_LEAVE_MENU)
2622 void (*menu_callback_function)(void) = menu_info[i].value;
2626 menu_callback_function();
2628 /* absolutely needed because function changes 'menu_info'! */
2636 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2638 PlaySound(SND_MENU_ITEM_SELECTING);
2640 /* when selecting key headline, execute function for key value change */
2641 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2642 menu_info[first_entry + y + 1].type & TYPE_KEY)
2645 /* when selecting string value, execute function for list selection */
2646 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2647 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2650 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2652 void (*menu_callback_function)(void) =
2653 menu_info[first_entry + y].value;
2655 FadeSetFromType(menu_info[first_entry + y].type);
2657 menu_callback_function();
2659 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2660 menu_info == setup_info)
2662 changeSetupValue(y, first_entry + y, dx);
2668 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2670 menu_info = info_info;
2672 HandleMenuScreen(mx, my, dx, dy, button,
2673 info_mode, num_info_info, max_info_info);
2676 static int getMenuFontSpacing(int spacing_height, int font_nr)
2678 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2680 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2684 static int getMenuTextSpacing(int spacing_height, int font_nr)
2686 return (getMenuFontSpacing(spacing_height, font_nr) +
2687 EXTRA_SPACING(game_status));
2690 static int getMenuTextStep(int spacing_height, int font_nr)
2692 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2695 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2697 int font_title = MENU_INFO_FONT_TITLE;
2698 int font_error = FONT_TEXT_2;
2699 int font_foot = MENU_INFO_FONT_FOOT;
2700 int spacing_title = menu.headline1_spacing_info[info_mode];
2701 int ystep_title = getMenuTextStep(spacing_title, font_title);
2702 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2703 int ystart2 = ystart1 + ystep_title;
2704 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2706 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2708 FadeOut(REDRAW_FIELD);
2713 DrawTextSCentered(ystart1, font_title, text_title);
2714 DrawTextSCentered(ystart2, font_error, text_error);
2716 DrawTextSCentered(ybottom, font_foot,
2717 "Press any key or button for info menu");
2719 FadeIn(REDRAW_FIELD);
2722 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2724 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2725 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2726 int font_title = MENU_INFO_FONT_TITLE;
2727 int font_foot = MENU_INFO_FONT_FOOT;
2728 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2729 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2730 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2731 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2732 int ystep = MENU_SCREEN_INFO_YSTEP;
2733 int element, action, direction;
2741 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2742 infoscreen_step[i] = infoscreen_frame[i] = 0;
2747 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2749 DrawTextSCentered(ybottom, font_foot,
2750 "Press any key or button for next page");
2756 while (helpanim_info[j].element != HELPANIM_LIST_END)
2758 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2763 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2772 j += infoscreen_step[i - start];
2774 element = helpanim_info[j].element;
2775 action = helpanim_info[j].action;
2776 direction = helpanim_info[j].direction;
2779 element = EL_UNKNOWN;
2781 if (action != -1 && direction != -1)
2782 graphic = el_act_dir2img(element, action, direction);
2783 else if (action != -1)
2784 graphic = el_act2img(element, action);
2785 else if (direction != -1)
2786 graphic = el_dir2img(element, direction);
2788 graphic = el2img(element);
2790 delay = helpanim_info[j++].delay;
2795 if (infoscreen_frame[i - start] == 0)
2798 infoscreen_frame[i - start] = delay - 1;
2802 sync_frame = delay - infoscreen_frame[i - start];
2803 infoscreen_frame[i - start]--;
2806 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2808 if (!infoscreen_frame[i - start])
2809 infoscreen_step[i - start] = 0;
2813 if (!infoscreen_frame[i - start])
2814 infoscreen_step[i - start]++;
2815 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2821 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2823 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2824 graphic, sync_frame, USE_MASKING);
2827 DrawInfoScreen_HelpText(element, action, direction, i - start);
2832 redraw_mask |= REDRAW_FIELD;
2837 static char *getHelpText(int element, int action, int direction)
2839 char token[MAX_LINE_LEN];
2841 strcpy(token, element_info[element].token_name);
2844 strcat(token, element_action_info[action].suffix);
2846 if (direction != -1)
2847 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2849 return getHashEntry(helptext_info, token);
2852 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2854 int font_nr = FONT_INFO_ELEMENTS;
2855 int font_width = getFontWidth(font_nr);
2856 int font_height = getFontHeight(font_nr);
2857 int yoffset = (TILEX - 2 * font_height) / 2;
2858 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2859 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2860 int ystep = TILEY + 4;
2861 int pad_left = xstart - SX;
2862 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2863 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2864 int max_lines_per_text = 2;
2867 if (action != -1 && direction != -1) /* element.action.direction */
2868 text = getHelpText(element, action, direction);
2870 if (text == NULL && action != -1) /* element.action */
2871 text = getHelpText(element, action, -1);
2873 if (text == NULL && direction != -1) /* element.direction */
2874 text = getHelpText(element, -1, direction);
2876 if (text == NULL) /* base element */
2877 text = getHelpText(element, -1, -1);
2879 if (text == NULL) /* not found */
2880 text = "No description available";
2882 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2883 ystart += getFontHeight(font_nr) / 2;
2885 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2886 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2887 TRUE, FALSE, FALSE);
2890 void DrawInfoScreen_TitleScreen()
2892 SetGameStatus(GAME_MODE_TITLE);
2897 void HandleInfoScreen_TitleScreen(int button)
2899 HandleTitleScreen(0, 0, 0, 0, button);
2902 void DrawInfoScreen_Elements()
2904 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2906 FadeOut(REDRAW_FIELD);
2911 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2913 FadeIn(REDRAW_FIELD);
2916 void HandleInfoScreen_Elements(int button)
2918 static unsigned int info_delay = 0;
2919 static int num_anims;
2920 static int num_pages;
2922 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2925 if (button == MB_MENU_INITIALIZE)
2927 boolean new_element = TRUE;
2931 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2933 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2935 else if (new_element)
2938 new_element = FALSE;
2942 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2946 if (button == MB_MENU_LEAVE)
2948 PlaySound(SND_MENU_ITEM_SELECTING);
2950 info_mode = INFO_MODE_MAIN;
2955 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2957 if (button != MB_MENU_INITIALIZE)
2959 PlaySound(SND_MENU_ITEM_SELECTING);
2964 if (page >= num_pages)
2966 FadeMenuSoundsAndMusic();
2968 info_mode = INFO_MODE_MAIN;
2975 FadeSetNextScreen();
2977 if (button != MB_MENU_INITIALIZE)
2978 FadeOut(REDRAW_FIELD);
2980 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2982 if (button != MB_MENU_INITIALIZE)
2983 FadeIn(REDRAW_FIELD);
2987 if (DelayReached(&info_delay, GameFrameDelay))
2988 if (page < num_pages)
2989 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2991 PlayMenuSoundIfLoop();
2995 void DrawInfoScreen_Music()
2997 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2999 FadeOut(REDRAW_FIELD);
3006 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3008 FadeIn(REDRAW_FIELD);
3011 void HandleInfoScreen_Music(int button)
3013 static struct MusicFileInfo *list = NULL;
3014 int font_title = MENU_INFO_FONT_TITLE;
3015 int font_head = MENU_INFO_FONT_HEAD;
3016 int font_text = MENU_INFO_FONT_TEXT;
3017 int font_foot = MENU_INFO_FONT_FOOT;
3018 int spacing_title = menu.headline1_spacing_info[info_mode];
3019 int spacing_head = menu.headline2_spacing_info[info_mode];
3020 int ystep_title = getMenuTextStep(spacing_title, font_title);
3021 int ystep_head = getMenuTextStep(spacing_head, font_head);
3022 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3023 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3025 if (button == MB_MENU_INITIALIZE)
3027 list = music_file_info;
3031 FadeMenuSoundsAndMusic();
3036 DrawTextSCentered(ystart, font_title,
3037 "No music info for this level set.");
3039 DrawTextSCentered(ybottom, font_foot,
3040 "Press any key or button for info menu");
3046 if (button == MB_MENU_LEAVE)
3048 PlaySound(SND_MENU_ITEM_SELECTING);
3050 FadeMenuSoundsAndMusic();
3052 info_mode = INFO_MODE_MAIN;
3057 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3059 if (button != MB_MENU_INITIALIZE)
3061 PlaySound(SND_MENU_ITEM_SELECTING);
3069 FadeMenuSoundsAndMusic();
3071 info_mode = INFO_MODE_MAIN;
3077 FadeMenuSoundsAndMusic();
3079 if (list != music_file_info)
3080 FadeSetNextScreen();
3082 if (button != MB_MENU_INITIALIZE)
3083 FadeOut(REDRAW_FIELD);
3090 int sound = list->music;
3092 if (sound_info[sound].loop)
3093 PlaySoundLoop(sound);
3097 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3101 PlayMusic(list->music);
3103 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3106 ystart += ystep_title;
3108 if (!strEqual(list->title, UNKNOWN_NAME))
3110 if (!strEqual(list->title_header, UNKNOWN_NAME))
3112 DrawTextSCentered(ystart, font_head, list->title_header);
3113 ystart += ystep_head;
3116 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3117 ystart += ystep_head;
3120 if (!strEqual(list->artist, UNKNOWN_NAME))
3122 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3123 DrawTextSCentered(ystart, font_head, list->artist_header);
3125 DrawTextSCentered(ystart, font_head, "by");
3127 ystart += ystep_head;
3129 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3130 ystart += ystep_head;
3133 if (!strEqual(list->album, UNKNOWN_NAME))
3135 if (!strEqual(list->album_header, UNKNOWN_NAME))
3136 DrawTextSCentered(ystart, font_head, list->album_header);
3138 DrawTextSCentered(ystart, font_head, "from the album");
3140 ystart += ystep_head;
3142 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3143 ystart += ystep_head;
3146 if (!strEqual(list->year, UNKNOWN_NAME))
3148 if (!strEqual(list->year_header, UNKNOWN_NAME))
3149 DrawTextSCentered(ystart, font_head, list->year_header);
3151 DrawTextSCentered(ystart, font_head, "from the year");
3153 ystart += ystep_head;
3155 DrawTextFCentered(ystart, font_text, "%s", list->year);
3156 ystart += ystep_head;
3159 DrawTextSCentered(ybottom, FONT_TEXT_4,
3160 "Press any key or button for next page");
3162 if (button != MB_MENU_INITIALIZE)
3163 FadeIn(REDRAW_FIELD);
3166 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3167 PlaySoundLoop(list->music);
3170 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3172 int font_title = MENU_INFO_FONT_TITLE;
3173 int font_head = MENU_INFO_FONT_HEAD;
3174 int font_text = MENU_INFO_FONT_TEXT;
3175 int font_foot = MENU_INFO_FONT_FOOT;
3176 int spacing_title = menu.headline1_spacing_info[info_mode];
3177 int spacing_head = menu.headline2_spacing_info[info_mode];
3178 int spacing_para = menu.paragraph_spacing_info[info_mode];
3179 int spacing_line = menu.line_spacing_info[info_mode];
3180 int ystep_title = getMenuTextStep(spacing_title, font_title);
3181 int ystep_head = getMenuTextStep(spacing_head, font_head);
3182 int ystep_para = getMenuTextStep(spacing_para, font_text);
3183 int ystep_line = getMenuTextStep(spacing_line, font_text);
3184 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3185 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3190 DrawTextSCentered(ystart, font_title, "Credits:");
3191 ystart += ystep_title;
3195 DrawTextSCentered(ystart, font_head,
3196 "Special thanks to");
3197 ystart += ystep_head;
3198 DrawTextSCentered(ystart, font_text,
3200 ystart += ystep_head;
3201 DrawTextSCentered(ystart, font_head,
3203 ystart += ystep_head;
3204 DrawTextSCentered(ystart, font_text,
3205 "\"Boulder Dash\"");
3206 ystart += ystep_head;
3207 DrawTextSCentered(ystart, font_head,
3209 ystart += ystep_head;
3210 DrawTextSCentered(ystart, font_text,
3212 ystart += ystep_head;
3213 DrawTextSCentered(ystart, font_head,
3215 ystart += ystep_head;
3216 DrawTextSCentered(ystart, font_text,
3217 "First Star Software");
3219 else if (screen_nr == 1)
3221 DrawTextSCentered(ystart, font_head,
3222 "Special thanks to");
3223 ystart += ystep_head;
3224 DrawTextSCentered(ystart, font_text,
3225 "Klaus Heinz & Volker Wertich");
3226 ystart += ystep_head;
3227 DrawTextSCentered(ystart, font_head,
3229 ystart += ystep_head;
3230 DrawTextSCentered(ystart, font_text,
3231 "\"Emerald Mine\"");
3232 ystart += ystep_head;
3233 DrawTextSCentered(ystart, font_head,
3235 ystart += ystep_head;
3236 DrawTextSCentered(ystart, font_text,
3238 ystart += ystep_head;
3239 DrawTextSCentered(ystart, font_head,
3241 ystart += ystep_head;
3242 DrawTextSCentered(ystart, font_text,
3245 else if (screen_nr == 2)
3247 DrawTextSCentered(ystart, font_head,
3248 "Special thanks to");
3249 ystart += ystep_head;
3250 DrawTextSCentered(ystart, font_text,
3251 "Michael Stopp & Philip Jespersen");
3252 ystart += ystep_head;
3253 DrawTextSCentered(ystart, font_head,
3255 ystart += ystep_head;
3256 DrawTextSCentered(ystart, font_text,
3258 ystart += ystep_head;
3259 DrawTextSCentered(ystart, font_head,
3261 ystart += ystep_head;
3262 DrawTextSCentered(ystart, font_text,
3264 ystart += ystep_head;
3265 DrawTextSCentered(ystart, font_head,
3267 ystart += ystep_head;
3268 DrawTextSCentered(ystart, font_text,
3269 "Digital Integration");
3271 else if (screen_nr == 3)
3273 DrawTextSCentered(ystart, font_head,
3274 "Special thanks to");
3275 ystart += ystep_head;
3276 DrawTextSCentered(ystart, font_text,
3277 "Hiroyuki Imabayashi");
3278 ystart += ystep_head;
3279 DrawTextSCentered(ystart, font_head,
3281 ystart += ystep_head;
3282 DrawTextSCentered(ystart, font_text,
3284 ystart += ystep_head;
3285 DrawTextSCentered(ystart, font_head,
3287 ystart += ystep_head;
3288 DrawTextSCentered(ystart, font_text,
3290 ystart += ystep_head;
3291 DrawTextSCentered(ystart, font_head,
3293 ystart += ystep_head;
3294 DrawTextSCentered(ystart, font_text,
3297 else if (screen_nr == 4)
3299 DrawTextSCentered(ystart, font_head,
3300 "Special thanks to");
3301 ystart += ystep_head;
3302 DrawTextSCentered(ystart, font_text,
3304 ystart += ystep_head;
3305 DrawTextSCentered(ystart, font_head,
3307 ystart += ystep_head;
3308 DrawTextSCentered(ystart, font_text,
3309 "J\xfcrgen Bonhagen");
3310 ystart += ystep_head;
3311 DrawTextSCentered(ystart, font_head,
3312 "for the continuous creation");
3313 ystart += ystep_line;
3314 DrawTextSCentered(ystart, font_head,
3315 "of outstanding level sets");
3317 else if (screen_nr == 5)
3319 DrawTextSCentered(ystart, font_head,
3321 ystart += ystep_head;
3322 DrawTextSCentered(ystart, font_text,
3324 ystart += ystep_head;
3325 DrawTextSCentered(ystart, font_head,
3326 "for ideas and inspiration by");
3327 ystart += ystep_head;
3328 DrawTextSCentered(ystart, font_text,
3330 ystart += ystep_para;
3332 DrawTextSCentered(ystart, font_head,
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_text,
3337 ystart += ystep_head;
3338 DrawTextSCentered(ystart, font_head,
3339 "for ideas and inspiration by");
3340 ystart += ystep_head;
3341 DrawTextSCentered(ystart, font_text,
3344 else if (screen_nr == 6)
3346 DrawTextSCentered(ystart, font_head,
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_text,
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_head,
3353 "for the code base used for the");
3354 ystart += ystep_line;
3355 DrawTextSCentered(ystart, font_head,
3356 "native Emerald Mine engine");
3358 else if (screen_nr == 7)
3360 DrawTextSCentered(ystart, font_head,
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_text,
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_head,
3367 "for the initial DOS port");
3368 ystart += ystep_para;
3370 DrawTextSCentered(ystart, font_head,
3372 ystart += ystep_head;
3373 DrawTextSCentered(ystart, font_text,
3375 ystart += ystep_head;
3376 DrawTextSCentered(ystart, font_head,
3377 "for some additional toons");
3379 else if (screen_nr == 8)
3381 DrawTextSCentered(ystart, font_head,
3382 "And not to forget:");
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_head,
3386 ystart += ystep_head;
3387 DrawTextSCentered(ystart, font_text,
3388 "All those who contributed");
3389 ystart += ystep_line;
3390 DrawTextSCentered(ystart, font_text,
3391 "levels to this game");
3392 ystart += ystep_line;
3393 DrawTextSCentered(ystart, font_text,
3397 DrawTextSCentered(ybottom, font_foot,
3398 "Press any key or button for next page");
3401 void DrawInfoScreen_Credits()
3403 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3405 FadeMenuSoundsAndMusic();
3407 FadeOut(REDRAW_FIELD);
3409 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3411 FadeIn(REDRAW_FIELD);
3414 void HandleInfoScreen_Credits(int button)
3416 static int screen_nr = 0;
3417 int num_screens = 9;
3419 if (button == MB_MENU_INITIALIZE)
3423 // DrawInfoScreen_CreditsScreen(screen_nr);
3426 if (button == MB_MENU_LEAVE)
3428 PlaySound(SND_MENU_ITEM_SELECTING);
3430 info_mode = INFO_MODE_MAIN;
3435 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3437 if (button != MB_MENU_INITIALIZE)
3439 PlaySound(SND_MENU_ITEM_SELECTING);
3444 if (screen_nr >= num_screens)
3446 FadeMenuSoundsAndMusic();
3448 info_mode = INFO_MODE_MAIN;
3455 FadeSetNextScreen();
3457 if (button != MB_MENU_INITIALIZE)
3458 FadeOut(REDRAW_FIELD);
3460 DrawInfoScreen_CreditsScreen(screen_nr);
3462 if (button != MB_MENU_INITIALIZE)
3463 FadeIn(REDRAW_FIELD);
3467 PlayMenuSoundIfLoop();
3471 void DrawInfoScreen_Program()
3473 int font_title = MENU_INFO_FONT_TITLE;
3474 int font_head = MENU_INFO_FONT_HEAD;
3475 int font_text = MENU_INFO_FONT_TEXT;
3476 int font_foot = MENU_INFO_FONT_FOOT;
3477 int spacing_title = menu.headline1_spacing_info[info_mode];
3478 int spacing_head = menu.headline2_spacing_info[info_mode];
3479 int spacing_para = menu.paragraph_spacing_info[info_mode];
3480 int spacing_line = menu.line_spacing_info[info_mode];
3481 int ystep_title = getMenuTextStep(spacing_title, font_title);
3482 int ystep_head = getMenuTextStep(spacing_head, font_head);
3483 int ystep_para = getMenuTextStep(spacing_para, font_text);
3484 int ystep_line = getMenuTextStep(spacing_line, font_text);
3485 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3486 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3488 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3490 FadeOut(REDRAW_FIELD);
3495 DrawTextSCentered(ystart, font_title, "Program Information:");
3496 ystart += ystep_title;
3498 DrawTextSCentered(ystart, font_head,
3499 "This game is Freeware!");
3500 ystart += ystep_head;
3501 DrawTextSCentered(ystart, font_head,
3502 "If you like it, send e-mail to:");
3503 ystart += ystep_head;
3504 DrawTextSCentered(ystart, font_text,
3505 setup.internal.program_email);
3506 ystart += ystep_para;
3508 DrawTextSCentered(ystart, font_head,
3509 "More information and levels:");
3510 ystart += ystep_head;
3511 DrawTextSCentered(ystart, font_text,
3512 setup.internal.program_website);
3513 ystart += ystep_para;
3515 DrawTextSCentered(ystart, font_head,
3516 "If you have created new levels,");
3517 ystart += ystep_line;
3518 DrawTextSCentered(ystart, font_head,
3519 "send them to me to include them!");
3520 ystart += ystep_head;
3521 DrawTextSCentered(ystart, font_head,
3524 DrawTextSCentered(ybottom, font_foot,
3525 "Press any key or button for info menu");
3527 FadeIn(REDRAW_FIELD);
3530 void HandleInfoScreen_Program(int button)
3532 if (button == MB_MENU_LEAVE)
3534 PlaySound(SND_MENU_ITEM_SELECTING);
3536 info_mode = INFO_MODE_MAIN;
3541 else if (button == MB_MENU_CHOICE)
3543 PlaySound(SND_MENU_ITEM_SELECTING);
3545 FadeMenuSoundsAndMusic();
3547 info_mode = INFO_MODE_MAIN;
3552 PlayMenuSoundIfLoop();
3556 void DrawInfoScreen_Version()
3558 int font_title = MENU_INFO_FONT_TITLE;
3559 int font_head = MENU_INFO_FONT_HEAD;
3560 int font_text = MENU_INFO_FONT_TEXT;
3561 int font_foot = MENU_INFO_FONT_FOOT;
3562 int spacing_title = menu.headline1_spacing_info[info_mode];
3563 int spacing_head = menu.headline2_spacing_info[info_mode];
3564 int spacing_para = menu.paragraph_spacing_info[info_mode];
3565 int spacing_line = menu.line_spacing_info[info_mode];
3566 int xstep = getFontWidth(font_text);
3567 int ystep_title = getMenuTextStep(spacing_title, font_title);
3568 int ystep_head = getMenuTextStep(spacing_head, font_head);
3569 int ystep_para = getMenuTextStep(spacing_para, font_text);
3570 int ystep_line = getMenuTextStep(spacing_line, font_text);
3571 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3572 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3573 int xstart1 = mSX - SX + 2 * xstep;
3574 int xstart2 = mSX - SX + 18 * xstep;
3575 int xstart3 = mSX - SX + 28 * xstep;
3576 SDL_version sdl_version_compiled;
3577 const SDL_version *sdl_version_linked;
3578 int driver_name_len = 10;
3579 #if defined(TARGET_SDL2)
3580 SDL_version sdl_version_linked_ext;
3581 const char *driver_name = NULL;
3583 char driver_name[driver_name_len];
3586 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3588 FadeOut(REDRAW_FIELD);
3593 DrawTextSCentered(ystart, font_title, "Version Information:");
3594 ystart += ystep_title;
3596 DrawTextF(xstart1, ystart, font_head, "Name");
3597 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3598 ystart += ystep_line;
3600 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3602 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3603 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3604 ystart += ystep_line;
3606 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3607 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3608 ystart += ystep_line;
3612 DrawTextF(xstart1, ystart, font_head, "Version");
3613 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3614 ystart += ystep_line;
3617 DrawTextF(xstart1, ystart, font_head, "Platform");
3618 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3619 ystart += ystep_line;
3621 DrawTextF(xstart1, ystart, font_head, "Target");
3622 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3623 ystart += ystep_line;
3625 DrawTextF(xstart1, ystart, font_head, "Source date");
3626 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3627 ystart += ystep_para;
3629 DrawTextF(xstart1, ystart, font_head, "Library");
3630 DrawTextF(xstart2, ystart, font_head, "compiled");
3631 DrawTextF(xstart3, ystart, font_head, "linked");
3632 ystart += ystep_head;
3634 SDL_VERSION(&sdl_version_compiled);
3635 #if defined(TARGET_SDL2)
3636 SDL_GetVersion(&sdl_version_linked_ext);
3637 sdl_version_linked = &sdl_version_linked_ext;
3639 sdl_version_linked = SDL_Linked_Version();
3642 DrawTextF(xstart1, ystart, font_text, "SDL");
3643 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3644 sdl_version_compiled.major,
3645 sdl_version_compiled.minor,
3646 sdl_version_compiled.patch);
3647 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3648 sdl_version_linked->major,
3649 sdl_version_linked->minor,
3650 sdl_version_linked->patch);
3651 ystart += ystep_line;
3653 SDL_IMAGE_VERSION(&sdl_version_compiled);
3654 sdl_version_linked = IMG_Linked_Version();
3656 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3657 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3658 sdl_version_compiled.major,
3659 sdl_version_compiled.minor,
3660 sdl_version_compiled.patch);
3661 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3662 sdl_version_linked->major,
3663 sdl_version_linked->minor,
3664 sdl_version_linked->patch);
3665 ystart += ystep_line;
3667 SDL_MIXER_VERSION(&sdl_version_compiled);
3668 sdl_version_linked = Mix_Linked_Version();
3670 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3671 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3672 sdl_version_compiled.major,
3673 sdl_version_compiled.minor,
3674 sdl_version_compiled.patch);
3675 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3676 sdl_version_linked->major,
3677 sdl_version_linked->minor,
3678 sdl_version_linked->patch);
3679 ystart += ystep_line;
3681 SDL_NET_VERSION(&sdl_version_compiled);
3682 sdl_version_linked = SDLNet_Linked_Version();
3684 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3685 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3686 sdl_version_compiled.major,
3687 sdl_version_compiled.minor,
3688 sdl_version_compiled.patch);
3689 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3690 sdl_version_linked->major,
3691 sdl_version_linked->minor,
3692 sdl_version_linked->patch);
3693 ystart += ystep_para;
3695 DrawTextF(xstart1, ystart, font_head, "Driver");
3696 DrawTextF(xstart2, ystart, font_head, "Requested");
3697 DrawTextF(xstart3, ystart, font_head, "Used");
3698 ystart += ystep_head;
3700 #if defined(TARGET_SDL2)
3701 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3703 SDL_VideoDriverName(driver_name, driver_name_len);
3706 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3707 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3708 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3709 ystart += ystep_line;
3711 #if defined(TARGET_SDL2)
3712 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3714 SDL_AudioDriverName(driver_name, driver_name_len);
3717 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3718 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3719 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3721 DrawTextSCentered(ybottom, font_foot,
3722 "Press any key or button for info menu");
3724 FadeIn(REDRAW_FIELD);
3727 void HandleInfoScreen_Version(int button)
3729 if (button == MB_MENU_LEAVE)
3731 PlaySound(SND_MENU_ITEM_SELECTING);
3733 info_mode = INFO_MODE_MAIN;
3738 else if (button == MB_MENU_CHOICE)
3740 PlaySound(SND_MENU_ITEM_SELECTING);
3742 FadeMenuSoundsAndMusic();
3744 info_mode = INFO_MODE_MAIN;
3749 PlayMenuSoundIfLoop();
3753 void DrawInfoScreen_LevelSet()
3755 struct TitleMessageInfo *tmi = &readme;
3756 char *filename = getLevelSetInfoFilename();
3757 char *title = "Level Set Information:";
3758 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3759 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3761 if (filename == NULL)
3763 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3768 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3770 FadeOut(REDRAW_FIELD);
3775 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3777 /* if x position set to "-1", automatically determine by playfield width */
3779 tmi->x = SXSIZE / 2;
3781 /* if y position set to "-1", use static default value */
3785 /* if width set to "-1", automatically determine by playfield width */
3786 if (tmi->width == -1)
3787 tmi->width = SXSIZE - 2 * TILEX;
3789 /* if height set to "-1", automatically determine by playfield height */
3790 if (tmi->height == -1)
3791 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3793 /* if chars set to "-1", automatically determine by text and font width */
3794 if (tmi->chars == -1)
3795 tmi->chars = tmi->width / getFontWidth(tmi->font);
3797 tmi->width = tmi->chars * getFontWidth(tmi->font);
3799 /* if lines set to "-1", automatically determine by text and font height */
3800 if (tmi->lines == -1)
3801 tmi->lines = tmi->height / getFontHeight(tmi->font);
3803 tmi->height = tmi->lines * getFontHeight(tmi->font);
3805 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3806 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3807 tmi->autowrap, tmi->centered, tmi->parse_comments);
3809 DrawTextSCentered(ybottom, FONT_TEXT_4,
3810 "Press any key or button for info menu");
3812 FadeIn(REDRAW_FIELD);
3815 void HandleInfoScreen_LevelSet(int button)
3817 if (button == MB_MENU_LEAVE)
3819 PlaySound(SND_MENU_ITEM_SELECTING);
3821 info_mode = INFO_MODE_MAIN;
3826 else if (button == MB_MENU_CHOICE)
3828 PlaySound(SND_MENU_ITEM_SELECTING);
3830 FadeMenuSoundsAndMusic();
3832 info_mode = INFO_MODE_MAIN;
3837 PlayMenuSoundIfLoop();
3841 static void DrawInfoScreen()
3843 if (info_mode == INFO_MODE_TITLE)
3844 DrawInfoScreen_TitleScreen();
3845 else if (info_mode == INFO_MODE_ELEMENTS)
3846 DrawInfoScreen_Elements();
3847 else if (info_mode == INFO_MODE_MUSIC)
3848 DrawInfoScreen_Music();
3849 else if (info_mode == INFO_MODE_CREDITS)
3850 DrawInfoScreen_Credits();
3851 else if (info_mode == INFO_MODE_PROGRAM)
3852 DrawInfoScreen_Program();
3853 else if (info_mode == INFO_MODE_VERSION)
3854 DrawInfoScreen_Version();
3855 else if (info_mode == INFO_MODE_LEVELSET)
3856 DrawInfoScreen_LevelSet();
3858 DrawInfoScreen_Main();
3860 if (info_mode != INFO_MODE_MAIN &&
3861 info_mode != INFO_MODE_TITLE &&
3862 info_mode != INFO_MODE_MUSIC)
3863 PlayMenuSoundsAndMusic();
3866 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3868 if (info_mode == INFO_MODE_TITLE)
3869 HandleInfoScreen_TitleScreen(button);
3870 else if (info_mode == INFO_MODE_ELEMENTS)
3871 HandleInfoScreen_Elements(button);
3872 else if (info_mode == INFO_MODE_MUSIC)
3873 HandleInfoScreen_Music(button);
3874 else if (info_mode == INFO_MODE_CREDITS)
3875 HandleInfoScreen_Credits(button);
3876 else if (info_mode == INFO_MODE_PROGRAM)
3877 HandleInfoScreen_Program(button);
3878 else if (info_mode == INFO_MODE_VERSION)
3879 HandleInfoScreen_Version(button);
3880 else if (info_mode == INFO_MODE_LEVELSET)
3881 HandleInfoScreen_LevelSet(button);
3883 HandleInfoScreen_Main(mx, my, dx, dy, button);
3887 /* ========================================================================= */
3888 /* type name functions */
3889 /* ========================================================================= */
3891 void HandleTypeName(int newxpos, Key key)
3893 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3894 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3895 struct TextPosInfo *pos = mci->pos_input;
3896 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3897 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3898 static int xpos = 0;
3899 int font_nr = pos->font;
3900 int font_active_nr = FONT_ACTIVE(font_nr);
3901 int font_width = getFontWidth(font_active_nr);
3902 char key_char = getValidConfigValueChar(getCharFromKey(key));
3903 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3904 boolean is_active = TRUE;
3906 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3910 strcpy(last_player_name, setup.player_name);
3914 StartTextInput(startx, starty, pos->width, pos->height);
3916 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3918 setup.player_name[xpos] = key_char;
3919 setup.player_name[xpos + 1] = 0;
3923 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3927 setup.player_name[xpos] = 0;
3929 else if (key == KSYM_Return && xpos > 0)
3935 SetGameStatus(GAME_MODE_MAIN);
3937 else if (key == KSYM_Escape)
3939 strcpy(setup.player_name, last_player_name);
3943 SetGameStatus(GAME_MODE_MAIN);
3948 pos->width = (strlen(setup.player_name) + 1) * font_width;
3949 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3951 DrawText(startx, starty, setup.player_name, font_active_nr);
3952 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3956 pos->width = strlen(setup.player_name) * font_width;
3957 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3959 DrawText(startx, starty, setup.player_name, font_nr);
3966 /* ========================================================================= */
3967 /* tree menu functions */
3968 /* ========================================================================= */
3970 static void DrawChooseTree(TreeInfo **ti_ptr)
3972 int fade_mask = REDRAW_FIELD;
3974 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3975 fade_mask = REDRAW_ALL;
3977 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3979 SetGameStatus(GAME_MODE_MAIN);
3988 FreeScreenGadgets();
3989 CreateScreenGadgets();
3993 /* needed if different viewport properties defined for choosing level (set) */
3994 ChangeViewportPropertiesIfNeeded();
3996 if (game_status == GAME_MODE_LEVELNR)
3997 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3998 else if (game_status == GAME_MODE_LEVELS)
3999 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4003 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4005 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4006 MapScreenTreeGadgets(*ti_ptr);
4008 DrawMaskedBorder(fade_mask);
4013 static void drawChooseTreeList(int first_entry, int num_page_entries,
4017 char *title_string = NULL;
4018 int yoffset_sets = MENU_TITLE1_YPOS;
4019 int yoffset_setup = 16;
4020 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4021 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4023 title_string = ti->infotext;
4025 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4027 clearMenuListArea();
4029 for (i = 0; i < num_page_entries; i++)
4031 TreeInfo *node, *node_first;
4032 int entry_pos = first_entry + i;
4033 int xpos = MENU_SCREEN_START_XPOS;
4034 int ypos = MENU_SCREEN_START_YPOS + i;
4035 int startx = mSX + xpos * 32;
4036 int starty = mSY + ypos * 32;
4037 int font_nr = FONT_TEXT_1;
4038 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4039 int startx_text = startx + font_xoffset;
4040 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4041 int text_size = startx_scrollbar - startx_text;
4042 int max_buffer_len = text_size / getFontWidth(font_nr);
4043 char buffer[max_buffer_len + 1];
4045 node_first = getTreeInfoFirstGroupEntry(ti);
4046 node = getTreeInfoFromPos(node_first, entry_pos);
4048 strncpy(buffer, node->name, max_buffer_len);
4049 buffer[max_buffer_len] = '\0';
4051 DrawText(startx, starty, buffer, font_nr + node->color);
4053 if (node->parent_link)
4054 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4055 else if (node->level_group)
4056 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4058 initCursor(i, IMG_MENU_BUTTON);
4061 redraw_mask |= REDRAW_FIELD;
4064 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4066 TreeInfo *node, *node_first;
4067 int x, last_redraw_mask = redraw_mask;
4068 int ypos = MENU_TITLE2_YPOS;
4069 int font_nr = FONT_TITLE_2;
4071 if (ti->type == TREE_TYPE_LEVEL_NR)
4072 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4074 if (ti->type != TREE_TYPE_LEVEL_DIR)
4077 node_first = getTreeInfoFirstGroupEntry(ti);
4078 node = getTreeInfoFromPos(node_first, entry_pos);
4080 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4082 if (node->parent_link)
4083 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4084 node->node_parent->name);
4085 else if (node->level_group)
4086 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4088 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4089 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4090 node->levels, (node->levels > 1 ? "levels" : "level"),
4093 /* let BackToFront() redraw only what is needed */
4094 redraw_mask = last_redraw_mask;
4095 for (x = 0; x < SCR_FIELDX; x++)
4096 MarkTileDirty(x, 1);
4099 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4102 TreeInfo *ti = *ti_ptr;
4104 int y = ti->cl_cursor;
4105 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4106 int num_entries = numTreeInfoInGroup(ti);
4107 int num_page_entries;
4108 boolean position_set_by_scrollbar = (dx == 999);
4110 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4111 num_page_entries = num_entries;
4113 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4115 if (button == MB_MENU_INITIALIZE)
4117 int num_entries = numTreeInfoInGroup(ti);
4118 int entry_pos = posTreeInfo(ti);
4120 if (ti->cl_first == -1)
4122 /* only on initialization */
4123 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4124 ti->cl_cursor = entry_pos - ti->cl_first;
4126 else if (ti->cl_cursor >= num_page_entries ||
4127 (num_entries > num_page_entries &&
4128 num_entries - ti->cl_first < num_page_entries))
4130 /* only after change of list size (by custom graphic configuration) */
4131 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4132 ti->cl_cursor = entry_pos - ti->cl_first;
4135 if (position_set_by_scrollbar)
4138 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4141 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4142 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4143 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4147 else if (button == MB_MENU_LEAVE)
4151 PlaySound(SND_MENU_ITEM_SELECTING);
4153 if (ti->node_parent)
4155 *ti_ptr = ti->node_parent;
4156 DrawChooseTree(ti_ptr);
4158 else if (game_status == GAME_MODE_SETUP)
4160 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4161 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4162 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4164 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4165 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4166 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4167 execSetupGraphics();
4168 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4169 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4170 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4172 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4173 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4174 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4175 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4176 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4177 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4178 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4179 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4186 if (game_status == GAME_MODE_LEVELNR)
4188 int new_level_nr = atoi(level_number_current->identifier);
4190 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4193 SetGameStatus(GAME_MODE_MAIN);
4201 if (mx || my) /* mouse input */
4203 x = (mx - mSX) / 32;
4204 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4206 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4208 /* move cursor instead of scrolling when already at start/end of list */
4209 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4211 else if (dy == +1 * SCROLL_LINE &&
4212 ti->cl_first + num_page_entries == num_entries)
4215 /* handle scrolling screen one line or page */
4216 if (ti->cl_cursor + dy < 0 ||
4217 ti->cl_cursor + dy > num_page_entries - 1)
4219 boolean redraw = FALSE;
4221 if (ABS(dy) == SCROLL_PAGE)
4222 step = num_page_entries - 1;
4224 if (dy < 0 && ti->cl_first > 0)
4226 /* scroll page/line up */
4228 ti->cl_first -= step;
4229 if (ti->cl_first < 0)
4234 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4236 /* scroll page/line down */
4238 ti->cl_first += step;
4239 if (ti->cl_first + num_page_entries > num_entries)
4240 ti->cl_first = MAX(0, num_entries - num_page_entries);
4247 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4248 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4249 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4251 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4258 /* handle moving cursor one line */
4259 y = ti->cl_cursor + dy;
4264 TreeInfo *node_first, *node_cursor;
4265 int entry_pos = ti->cl_first + y;
4267 node_first = getTreeInfoFirstGroupEntry(ti);
4268 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4270 if (node_cursor->node_group)
4274 PlaySound(SND_MENU_ITEM_SELECTING);
4276 node_cursor->cl_first = ti->cl_first;
4277 node_cursor->cl_cursor = ti->cl_cursor;
4278 *ti_ptr = node_cursor->node_group;
4279 DrawChooseTree(ti_ptr);
4284 else if (dx == -1 && ti->node_parent)
4288 PlaySound(SND_MENU_ITEM_SELECTING);
4290 *ti_ptr = ti->node_parent;
4291 DrawChooseTree(ti_ptr);
4296 if (!anyScrollbarGadgetActive() &&
4297 IN_VIS_MENU(x, y) &&
4298 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4299 y >= 0 && y < num_page_entries)
4303 if (y != ti->cl_cursor)
4305 PlaySound(SND_MENU_ITEM_ACTIVATING);
4307 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4308 drawChooseTreeCursor(y, TRUE);
4309 drawChooseTreeInfo(ti->cl_first + y, ti);
4315 if (game_status == GAME_MODE_SETUP)
4317 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4318 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4319 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4321 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4322 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4323 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4324 execSetupGraphics();
4325 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4326 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4327 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4329 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4330 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4331 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4332 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4333 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4334 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4335 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4336 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4345 TreeInfo *node_first, *node_cursor;
4346 int entry_pos = ti->cl_first + y;
4348 PlaySound(SND_MENU_ITEM_SELECTING);
4350 node_first = getTreeInfoFirstGroupEntry(ti);
4351 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4353 if (node_cursor->node_group)
4357 node_cursor->cl_first = ti->cl_first;
4358 node_cursor->cl_cursor = ti->cl_cursor;
4359 *ti_ptr = node_cursor->node_group;
4360 DrawChooseTree(ti_ptr);
4362 else if (node_cursor->parent_link)
4366 *ti_ptr = node_cursor->node_parent;
4367 DrawChooseTree(ti_ptr);
4373 node_cursor->cl_first = ti->cl_first;
4374 node_cursor->cl_cursor = ti->cl_cursor;
4375 *ti_ptr = node_cursor;
4377 if (ti->type == TREE_TYPE_LEVEL_DIR)
4379 LoadLevelSetup_SeriesInfo();
4381 SaveLevelSetup_LastSeries();
4382 SaveLevelSetup_SeriesInfo();
4386 if (game_status == GAME_MODE_SETUP)
4388 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4389 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4390 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4392 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4393 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4394 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4395 execSetupGraphics();
4396 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4397 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4398 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4400 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4401 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4402 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4403 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4404 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4405 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4406 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4407 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4414 if (game_status == GAME_MODE_LEVELNR)
4416 int new_level_nr = atoi(level_number_current->identifier);
4418 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4421 SetGameStatus(GAME_MODE_MAIN);
4430 void DrawChooseLevelSet()
4432 FadeMenuSoundsAndMusic();
4434 DrawChooseTree(&leveldir_current);
4436 PlayMenuSoundsAndMusic();
4439 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4441 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4444 void DrawChooseLevelNr()
4448 FadeMenuSoundsAndMusic();
4450 if (level_number != NULL)
4452 freeTreeInfo(level_number);
4454 level_number = NULL;
4457 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4459 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4460 char identifier[32], name[32];
4463 /* temporarily load level info to get level name */
4464 LoadLevelInfoOnly(i);
4466 ti->node_top = &level_number;
4467 ti->sort_priority = 10000 + value;
4468 ti->color = (level.no_level_file ? FC_BLUE :
4469 LevelStats_getSolved(i) ? FC_GREEN :
4470 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4472 snprintf(identifier, sizeof(identifier), "%d", value);
4473 snprintf(name, sizeof(name), "%03d: %s", value,
4474 (level.no_level_file ? "(no file)" : level.name));
4476 setString(&ti->identifier, identifier);
4477 setString(&ti->name, name);
4478 setString(&ti->name_sorting, name);
4480 pushTreeInfo(&level_number, ti);
4483 /* sort level number values to start with lowest level number */
4484 sortTreeInfo(&level_number);
4486 /* set current level number to current level number */
4487 level_number_current =
4488 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4490 /* if that also fails, set current level number to first available level */
4491 if (level_number_current == NULL)
4492 level_number_current = level_number;
4494 DrawChooseTree(&level_number_current);
4496 PlayMenuSoundsAndMusic();
4499 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4501 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4504 void DrawHallOfFame(int level_nr, int highlight_position)
4506 int fade_mask = REDRAW_FIELD;
4508 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4509 fade_mask = REDRAW_ALL;
4512 FadeMenuSoundsAndMusic();
4514 /* (this is needed when called from GameEnd() after winning a game) */
4515 KeyboardAutoRepeatOn();
4517 /* (this is needed when called from GameEnd() after winning a game) */
4518 SetDrawDeactivationMask(REDRAW_NONE);
4519 SetDrawBackgroundMask(REDRAW_FIELD);
4521 if (highlight_position < 0)
4522 LoadScore(level_nr);
4524 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4526 FadeSetEnterScreen();
4530 /* needed if different viewport properties defined for scores */
4531 ChangeViewportPropertiesIfNeeded();
4533 PlayMenuSoundsAndMusic();
4535 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4537 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4539 DrawMaskedBorder(fade_mask);
4544 static void drawHallOfFameList(int level_nr, int first_entry,
4545 int highlight_position)
4549 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4552 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4553 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4554 "HighScores of Level %d", level_nr);
4556 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4558 int entry = first_entry + i;
4559 boolean active = (entry == highlight_position);
4560 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4561 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4562 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4563 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4564 int dxoff = getFontDrawOffsetX(font_nr1);
4565 int dx1 = 3 * getFontWidth(font_nr1);
4566 int dx2 = dx1 + getFontWidth(font_nr1);
4567 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4568 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4569 int sy = mSY + 64 + i * 32;
4571 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4572 DrawText(mSX + dx1, sy, ".", font_nr1);
4574 for (j = 0; j < num_dots; j++)
4575 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4577 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4578 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4580 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4583 redraw_mask |= REDRAW_FIELD;
4586 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4588 static int level_nr = 0;
4589 static int first_entry = 0;
4590 static int highlight_position = 0;
4591 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4593 if (button == MB_MENU_INITIALIZE)
4597 highlight_position = my;
4599 drawHallOfFameList(level_nr, first_entry, highlight_position);
4604 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4605 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4609 if (first_entry > 0)
4611 first_entry -= step;
4612 if (first_entry < 0)
4615 drawHallOfFameList(level_nr, first_entry, highlight_position);
4620 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4622 first_entry += step;
4623 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4624 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4626 drawHallOfFameList(level_nr, first_entry, highlight_position);
4629 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4631 PlaySound(SND_MENU_ITEM_SELECTING);
4633 FadeSound(SND_BACKGROUND_SCORES);
4635 if (game_status_last_screen == GAME_MODE_PLAYING &&
4636 setup.auto_play_next_level && setup.increment_levels &&
4639 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4643 SetGameStatus(GAME_MODE_MAIN);
4649 if (game_status == GAME_MODE_SCORES)
4650 PlayMenuSoundIfLoop();
4654 /* ========================================================================= */
4655 /* setup screen functions */
4656 /* ========================================================================= */
4658 static struct TokenInfo *setup_info;
4659 static int num_setup_info; /* number of setup entries shown on screen */
4660 static int max_setup_info; /* total number of setup entries in list */
4662 static char *window_size_text;
4663 static char *scaling_type_text;
4664 static char *rendering_mode_text;
4665 static char *scroll_delay_text;
4666 static char *snapshot_mode_text;
4667 static char *game_speed_text;
4668 static char *graphics_set_name;
4669 static char *sounds_set_name;
4670 static char *music_set_name;
4671 static char *volume_simple_text;
4672 static char *volume_loops_text;
4673 static char *volume_music_text;
4674 static char *touch_controls_text;
4675 static char *move_distance_text;
4676 static char *drop_distance_text;
4677 static char *transparency_text;
4678 static char *grid_size_text[2][2];
4680 static void execSetupMain()
4682 setup_mode = SETUP_MODE_MAIN;
4687 static void execSetupGame_setGameSpeeds()
4689 if (game_speeds == NULL)
4693 for (i = 0; game_speeds_list[i].value != -1; i++)
4695 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4696 char identifier[32], name[32];
4697 int value = game_speeds_list[i].value;
4698 char *text = game_speeds_list[i].text;
4700 ti->node_top = &game_speeds;
4701 ti->sort_priority = 10000 - value;
4703 sprintf(identifier, "%d", value);
4704 sprintf(name, "%s", text);
4706 setString(&ti->identifier, identifier);
4707 setString(&ti->name, name);
4708 setString(&ti->name_sorting, name);
4709 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4711 pushTreeInfo(&game_speeds, ti);
4714 /* sort game speed values to start with slowest game speed */
4715 sortTreeInfo(&game_speeds);
4717 /* set current game speed to configured game speed value */
4718 game_speed_current =
4719 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4721 /* if that fails, set current game speed to reliable default value */
4722 if (game_speed_current == NULL)
4723 game_speed_current =
4724 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4726 /* if that also fails, set current game speed to first available speed */
4727 if (game_speed_current == NULL)
4728 game_speed_current = game_speeds;
4731 setup.game_frame_delay = atoi(game_speed_current->identifier);
4733 /* needed for displaying game speed text instead of identifier */
4734 game_speed_text = game_speed_current->name;
4737 static void execSetupGame_setScrollDelays()
4739 if (scroll_delays == NULL)
4743 for (i = 0; scroll_delays_list[i].value != -1; i++)
4745 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4746 char identifier[32], name[32];
4747 int value = scroll_delays_list[i].value;
4748 char *text = scroll_delays_list[i].text;
4750 ti->node_top = &scroll_delays;
4751 ti->sort_priority = value;
4753 sprintf(identifier, "%d", value);
4754 sprintf(name, "%s", text);
4756 setString(&ti->identifier, identifier);
4757 setString(&ti->name, name);
4758 setString(&ti->name_sorting, name);
4759 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4761 pushTreeInfo(&scroll_delays, ti);
4764 /* sort scroll delay values to start with lowest scroll delay value */
4765 sortTreeInfo(&scroll_delays);
4767 /* set current scroll delay value to configured scroll delay value */
4768 scroll_delay_current =
4769 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4771 /* if that fails, set current scroll delay to reliable default value */
4772 if (scroll_delay_current == NULL)
4773 scroll_delay_current =
4774 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4776 /* if that also fails, set current scroll delay to first available value */
4777 if (scroll_delay_current == NULL)
4778 scroll_delay_current = scroll_delays;
4781 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4783 /* needed for displaying scroll delay text instead of identifier */
4784 scroll_delay_text = scroll_delay_current->name;
4787 static void execSetupGame_setSnapshotModes()
4789 if (snapshot_modes == NULL)
4793 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4795 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4796 char identifier[32], name[32];
4797 char *value = snapshot_modes_list[i].value;
4798 char *text = snapshot_modes_list[i].text;
4800 ti->node_top = &snapshot_modes;
4801 ti->sort_priority = i;
4803 sprintf(identifier, "%s", value);
4804 sprintf(name, "%s", text);
4806 setString(&ti->identifier, identifier);
4807 setString(&ti->name, name);
4808 setString(&ti->name_sorting, name);
4809 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4811 pushTreeInfo(&snapshot_modes, ti);
4814 /* sort snapshot mode values to start with lowest snapshot mode value */
4815 sortTreeInfo(&snapshot_modes);
4817 /* set current snapshot mode value to configured snapshot mode value */
4818 snapshot_mode_current =
4819 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4821 /* if that fails, set current snapshot mode to reliable default value */
4822 if (snapshot_mode_current == NULL)
4823 snapshot_mode_current =
4824 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4826 /* if that also fails, set current snapshot mode to first available value */
4827 if (snapshot_mode_current == NULL)
4828 snapshot_mode_current = snapshot_modes;
4831 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4833 /* needed for displaying snapshot mode text instead of identifier */
4834 snapshot_mode_text = snapshot_mode_current->name;
4837 static void execSetupGame()
4839 execSetupGame_setGameSpeeds();
4840 execSetupGame_setScrollDelays();
4841 execSetupGame_setSnapshotModes();
4843 setup_mode = SETUP_MODE_GAME;
4848 static void execSetupChooseGameSpeed()
4850 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4855 static void execSetupChooseScrollDelay()
4857 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4862 static void execSetupChooseSnapshotMode()
4864 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4869 static void execSetupEditor()
4871 setup_mode = SETUP_MODE_EDITOR;
4876 static void execSetupGraphics_setWindowSizes(boolean update_list)
4878 if (window_sizes != NULL && update_list)
4880 freeTreeInfo(window_sizes);
4882 window_sizes = NULL;
4885 if (window_sizes == NULL)
4887 boolean current_window_size_found = FALSE;
4890 for (i = 0; window_sizes_list[i].value != -1; i++)
4892 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4893 char identifier[32], name[32];
4894 int value = window_sizes_list[i].value;
4895 char *text = window_sizes_list[i].text;
4897 ti->node_top = &window_sizes;
4898 ti->sort_priority = value;
4900 sprintf(identifier, "%d", value);
4901 sprintf(name, "%s", text);
4903 setString(&ti->identifier, identifier);
4904 setString(&ti->name, name);
4905 setString(&ti->name_sorting, name);
4906 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4908 pushTreeInfo(&window_sizes, ti);
4910 if (value == setup.window_scaling_percent)
4911 current_window_size_found = TRUE;
4914 if (!current_window_size_found)
4916 // add entry for non-preset window scaling value
4918 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4919 char identifier[32], name[32];
4920 int value = setup.window_scaling_percent;
4922 ti->node_top = &window_sizes;
4923 ti->sort_priority = value;
4925 sprintf(identifier, "%d", value);
4926 sprintf(name, "%d %% (Current)", value);
4928 setString(&ti->identifier, identifier);
4929 setString(&ti->name, name);
4930 setString(&ti->name_sorting, name);
4931 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4933 pushTreeInfo(&window_sizes, ti);
4936 /* sort window size values to start with lowest window size value */
4937 sortTreeInfo(&window_sizes);
4939 /* set current window size value to configured window size value */
4940 window_size_current =
4941 getTreeInfoFromIdentifier(window_sizes,
4942 i_to_a(setup.window_scaling_percent));
4944 /* if that fails, set current window size to reliable default value */
4945 if (window_size_current == NULL)
4946 window_size_current =
4947 getTreeInfoFromIdentifier(window_sizes,
4948 i_to_a(STD_WINDOW_SCALING_PERCENT));
4950 /* if that also fails, set current window size to first available value */
4951 if (window_size_current == NULL)
4952 window_size_current = window_sizes;
4955 setup.window_scaling_percent = atoi(window_size_current->identifier);
4957 /* needed for displaying window size text instead of identifier */
4958 window_size_text = window_size_current->name;
4961 static void execSetupGraphics_setScalingTypes()
4963 if (scaling_types == NULL)
4967 for (i = 0; scaling_types_list[i].value != NULL; i++)
4969 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4970 char identifier[32], name[32];
4971 char *value = scaling_types_list[i].value;
4972 char *text = scaling_types_list[i].text;
4974 ti->node_top = &scaling_types;
4975 ti->sort_priority = i;
4977 sprintf(identifier, "%s", value);
4978 sprintf(name, "%s", text);
4980 setString(&ti->identifier, identifier);
4981 setString(&ti->name, name);
4982 setString(&ti->name_sorting, name);
4983 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4985 pushTreeInfo(&scaling_types, ti);
4988 /* sort scaling type values to start with lowest scaling type value */
4989 sortTreeInfo(&scaling_types);
4991 /* set current scaling type value to configured scaling type value */
4992 scaling_type_current =
4993 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4995 /* if that fails, set current scaling type to reliable default value */
4996 if (scaling_type_current == NULL)
4997 scaling_type_current =
4998 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5000 /* if that also fails, set current scaling type to first available value */
5001 if (scaling_type_current == NULL)
5002 scaling_type_current = scaling_types;
5005 setup.window_scaling_quality = scaling_type_current->identifier;
5007 /* needed for displaying scaling type text instead of identifier */
5008 scaling_type_text = scaling_type_current->name;
5011 static void execSetupGraphics_setRenderingModes()
5013 if (rendering_modes == NULL)
5017 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5019 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5020 char identifier[32], name[32];
5021 char *value = rendering_modes_list[i].value;
5022 char *text = rendering_modes_list[i].text;
5024 ti->node_top = &rendering_modes;
5025 ti->sort_priority = i;
5027 sprintf(identifier, "%s", value);
5028 sprintf(name, "%s", text);
5030 setString(&ti->identifier, identifier);
5031 setString(&ti->name, name);
5032 setString(&ti->name_sorting, name);
5033 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5035 pushTreeInfo(&rendering_modes, ti);
5038 /* sort rendering mode values to start with lowest rendering mode value */
5039 sortTreeInfo(&rendering_modes);
5041 /* set current rendering mode value to configured rendering mode value */
5042 rendering_mode_current =
5043 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5045 /* if that fails, set current rendering mode to reliable default value */
5046 if (rendering_mode_current == NULL)
5047 rendering_mode_current =
5048 getTreeInfoFromIdentifier(rendering_modes,
5049 STR_SPECIAL_RENDERING_DEFAULT);
5051 /* if that also fails, set current rendering mode to first available one */
5052 if (rendering_mode_current == NULL)
5053 rendering_mode_current = rendering_modes;
5056 setup.screen_rendering_mode = rendering_mode_current->identifier;
5058 /* needed for displaying rendering mode text instead of identifier */
5059 rendering_mode_text = rendering_mode_current->name;
5062 static void execSetupGraphics()
5064 // update "setup.window_scaling_percent" from list selection
5065 // (in this case, window scaling was changed on setup screen)
5066 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5067 execSetupGraphics_setWindowSizes(FALSE);
5069 // update list selection from "setup.window_scaling_percent"
5070 // (window scaling may have changed by resizing the window)
5071 execSetupGraphics_setWindowSizes(TRUE);
5073 execSetupGraphics_setScalingTypes();
5074 execSetupGraphics_setRenderingModes();
5076 setup_mode = SETUP_MODE_GRAPHICS;
5080 #if defined(TARGET_SDL2)
5081 // window scaling may have changed at this point
5082 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5084 // window scaling quality may have changed at this point
5085 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5086 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5088 // screen rendering mode may have changed at this point
5089 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5093 static void execSetupChooseWindowSize()
5095 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5100 static void execSetupChooseScalingType()
5102 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5107 static void execSetupChooseRenderingMode()
5109 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5114 static void execSetupChooseVolumeSimple()
5116 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5121 static void execSetupChooseVolumeLoops()
5123 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5128 static void execSetupChooseVolumeMusic()
5130 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5135 static void execSetupSound()
5137 if (volumes_simple == NULL)
5139 boolean current_volume_simple_found = FALSE;
5142 for (i = 0; volumes_list[i].value != -1; i++)
5144 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5145 char identifier[32], name[32];
5146 int value = volumes_list[i].value;
5147 char *text = volumes_list[i].text;
5149 ti->node_top = &volumes_simple;
5150 ti->sort_priority = value;
5152 sprintf(identifier, "%d", value);
5153 sprintf(name, "%s", text);
5155 setString(&ti->identifier, identifier);
5156 setString(&ti->name, name);
5157 setString(&ti->name_sorting, name);
5158 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5160 pushTreeInfo(&volumes_simple, ti);
5162 if (value == setup.volume_simple)
5163 current_volume_simple_found = TRUE;
5166 if (!current_volume_simple_found)
5168 // add entry for non-preset volume value
5170 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5171 char identifier[32], name[32];
5172 int value = setup.volume_simple;
5174 ti->node_top = &volumes_simple;
5175 ti->sort_priority = value;
5177 sprintf(identifier, "%d", value);
5178 sprintf(name, "%d %% (Current)", value);
5180 setString(&ti->identifier, identifier);
5181 setString(&ti->name, name);
5182 setString(&ti->name_sorting, name);
5183 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5185 pushTreeInfo(&volumes_simple, ti);
5188 /* sort volume values to start with lowest volume value */
5189 sortTreeInfo(&volumes_simple);
5191 /* set current volume value to configured volume value */
5192 volume_simple_current =
5193 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5195 /* if that fails, set current volume to reliable default value */
5196 if (volume_simple_current == NULL)
5197 volume_simple_current =
5198 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5200 /* if that also fails, set current volume to first available value */
5201 if (volume_simple_current == NULL)
5202 volume_simple_current = volumes_simple;
5205 if (volumes_loops == NULL)
5207 boolean current_volume_loops_found = FALSE;
5210 for (i = 0; volumes_list[i].value != -1; i++)
5212 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5213 char identifier[32], name[32];
5214 int value = volumes_list[i].value;
5215 char *text = volumes_list[i].text;
5217 ti->node_top = &volumes_loops;
5218 ti->sort_priority = value;
5220 sprintf(identifier, "%d", value);
5221 sprintf(name, "%s", text);
5223 setString(&ti->identifier, identifier);
5224 setString(&ti->name, name);
5225 setString(&ti->name_sorting, name);
5226 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5228 pushTreeInfo(&volumes_loops, ti);
5230 if (value == setup.volume_loops)
5231 current_volume_loops_found = TRUE;
5234 if (!current_volume_loops_found)
5236 // add entry for non-preset volume value
5238 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5239 char identifier[32], name[32];
5240 int value = setup.volume_loops;
5242 ti->node_top = &volumes_loops;
5243 ti->sort_priority = value;
5245 sprintf(identifier, "%d", value);
5246 sprintf(name, "%d %% (Current)", value);
5248 setString(&ti->identifier, identifier);
5249 setString(&ti->name, name);
5250 setString(&ti->name_sorting, name);
5251 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5253 pushTreeInfo(&volumes_loops, ti);
5256 /* sort volume values to start with lowest volume value */
5257 sortTreeInfo(&volumes_loops);
5259 /* set current volume value to configured volume value */
5260 volume_loops_current =
5261 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5263 /* if that fails, set current volume to reliable default value */
5264 if (volume_loops_current == NULL)
5265 volume_loops_current =
5266 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5268 /* if that also fails, set current volume to first available value */
5269 if (volume_loops_current == NULL)
5270 volume_loops_current = volumes_loops;
5273 if (volumes_music == NULL)
5275 boolean current_volume_music_found = FALSE;
5278 for (i = 0; volumes_list[i].value != -1; i++)
5280 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5281 char identifier[32], name[32];
5282 int value = volumes_list[i].value;
5283 char *text = volumes_list[i].text;
5285 ti->node_top = &volumes_music;
5286 ti->sort_priority = value;
5288 sprintf(identifier, "%d", value);
5289 sprintf(name, "%s", text);
5291 setString(&ti->identifier, identifier);
5292 setString(&ti->name, name);
5293 setString(&ti->name_sorting, name);
5294 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5296 pushTreeInfo(&volumes_music, ti);
5298 if (value == setup.volume_music)
5299 current_volume_music_found = TRUE;
5302 if (!current_volume_music_found)
5304 // add entry for non-preset volume value
5306 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5307 char identifier[32], name[32];
5308 int value = setup.volume_music;
5310 ti->node_top = &volumes_music;
5311 ti->sort_priority = value;
5313 sprintf(identifier, "%d", value);
5314 sprintf(name, "%d %% (Current)", value);
5316 setString(&ti->identifier, identifier);
5317 setString(&ti->name, name);
5318 setString(&ti->name_sorting, name);
5319 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5321 pushTreeInfo(&volumes_music, ti);
5324 /* sort volume values to start with lowest volume value */
5325 sortTreeInfo(&volumes_music);
5327 /* set current volume value to configured volume value */
5328 volume_music_current =
5329 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5331 /* if that fails, set current volume to reliable default value */
5332 if (volume_music_current == NULL)
5333 volume_music_current =
5334 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5336 /* if that also fails, set current volume to first available value */
5337 if (volume_music_current == NULL)
5338 volume_music_current = volumes_music;
5341 setup.volume_simple = atoi(volume_simple_current->identifier);
5342 setup.volume_loops = atoi(volume_loops_current->identifier);
5343 setup.volume_music = atoi(volume_music_current->identifier);
5345 /* needed for displaying volume text instead of identifier */
5346 volume_simple_text = volume_simple_current->name;
5347 volume_loops_text = volume_loops_current->name;
5348 volume_music_text = volume_music_current->name;
5350 setup_mode = SETUP_MODE_SOUND;
5355 static void execSetupChooseTouchControls()
5357 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5362 static void execSetupChooseMoveDistance()
5364 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5369 static void execSetupChooseDropDistance()
5371 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5376 static void execSetupChooseTransparency()
5378 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5383 static void execSetupChooseGridXSize_0()
5385 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5390 static void execSetupChooseGridYSize_0()
5392 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5397 static void execSetupChooseGridXSize_1()
5399 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5404 static void execSetupChooseGridYSize_1()
5406 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5411 static void execSetupConfigureVirtualButtons()
5413 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5415 ConfigureVirtualButtons();
5417 setup_mode = SETUP_MODE_TOUCH;
5422 static void execSetupTouch()
5426 if (touch_controls == NULL)
5428 for (i = 0; touch_controls_list[i].value != NULL; i++)
5430 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5431 char identifier[32], name[32];
5432 char *value = touch_controls_list[i].value;
5433 char *text = touch_controls_list[i].text;
5435 ti->node_top = &touch_controls;
5436 ti->sort_priority = i;
5438 sprintf(identifier, "%s", value);
5439 sprintf(name, "%s", text);
5441 setString(&ti->identifier, identifier);
5442 setString(&ti->name, name);
5443 setString(&ti->name_sorting, name);
5444 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5446 pushTreeInfo(&touch_controls, ti);
5449 /* sort touch control values to start with lowest touch control value */
5450 sortTreeInfo(&touch_controls);
5452 /* set current touch control value to configured touch control value */
5453 touch_control_current =
5454 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5456 /* if that fails, set current touch control to reliable default value */
5457 if (touch_control_current == NULL)
5458 touch_control_current =
5459 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5461 /* if that also fails, set current touch control to first available value */
5462 if (touch_control_current == NULL)
5463 touch_control_current = touch_controls;
5466 if (move_distances == NULL)
5468 for (i = 0; distances_list[i].value != -1; i++)
5470 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5471 char identifier[32], name[32];
5472 int value = distances_list[i].value;
5473 char *text = distances_list[i].text;
5475 ti->node_top = &move_distances;
5476 ti->sort_priority = value;
5478 sprintf(identifier, "%d", value);
5479 sprintf(name, "%s", text);
5481 setString(&ti->identifier, identifier);
5482 setString(&ti->name, name);
5483 setString(&ti->name_sorting, name);
5484 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5486 pushTreeInfo(&move_distances, ti);
5489 /* sort distance values to start with lowest distance value */
5490 sortTreeInfo(&move_distances);
5492 /* set current distance value to configured distance value */
5493 move_distance_current =
5494 getTreeInfoFromIdentifier(move_distances,
5495 i_to_a(setup.touch.move_distance));
5497 /* if that fails, set current distance to reliable default value */
5498 if (move_distance_current == NULL)
5499 move_distance_current =
5500 getTreeInfoFromIdentifier(move_distances,
5501 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5503 /* if that also fails, set current distance to first available value */
5504 if (move_distance_current == NULL)
5505 move_distance_current = move_distances;
5508 if (drop_distances == NULL)
5510 for (i = 0; distances_list[i].value != -1; i++)
5512 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5513 char identifier[32], name[32];
5514 int value = distances_list[i].value;
5515 char *text = distances_list[i].text;
5517 ti->node_top = &drop_distances;
5518 ti->sort_priority = value;
5520 sprintf(identifier, "%d", value);
5521 sprintf(name, "%s", text);
5523 setString(&ti->identifier, identifier);
5524 setString(&ti->name, name);
5525 setString(&ti->name_sorting, name);
5526 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5528 pushTreeInfo(&drop_distances, ti);
5531 /* sort distance values to start with lowest distance value */
5532 sortTreeInfo(&drop_distances);
5534 /* set current distance value to configured distance value */
5535 drop_distance_current =
5536 getTreeInfoFromIdentifier(drop_distances,
5537 i_to_a(setup.touch.drop_distance));
5539 /* if that fails, set current distance to reliable default value */
5540 if (drop_distance_current == NULL)
5541 drop_distance_current =
5542 getTreeInfoFromIdentifier(drop_distances,
5543 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5545 /* if that also fails, set current distance to first available value */
5546 if (drop_distance_current == NULL)
5547 drop_distance_current = drop_distances;
5550 if (transparencies == NULL)
5552 for (i = 0; transparencies_list[i].value != -1; i++)
5554 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5555 char identifier[32], name[32];
5556 int value = transparencies_list[i].value;
5557 char *text = transparencies_list[i].text;
5559 ti->node_top = &transparencies;
5560 ti->sort_priority = value;
5562 sprintf(identifier, "%d", value);
5563 sprintf(name, "%s", text);
5565 setString(&ti->identifier, identifier);
5566 setString(&ti->name, name);
5567 setString(&ti->name_sorting, name);
5568 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5570 pushTreeInfo(&transparencies, ti);
5573 /* sort transparency values to start with lowest transparency value */
5574 sortTreeInfo(&transparencies);
5576 /* set current transparency value to configured transparency value */
5577 transparency_current =
5578 getTreeInfoFromIdentifier(transparencies,
5579 i_to_a(setup.touch.transparency));
5581 /* if that fails, set current transparency to reliable default value */
5582 if (transparency_current == NULL)
5583 transparency_current =
5584 getTreeInfoFromIdentifier(transparencies,
5585 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5587 /* if that also fails, set current transparency to first available value */
5588 if (transparency_current == NULL)
5589 transparency_current = transparencies;
5592 for (i = 0; i < 2; i++)
5594 for (j = 0; j < 2; j++)
5596 if (grid_sizes[i][j] == NULL)
5598 for (k = 0; grid_sizes_list[k].value != -1; k++)
5600 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5601 char identifier[32], name[32];
5602 int value = grid_sizes_list[k].value;
5603 char *text = grid_sizes_list[k].text;
5605 ti->node_top = &grid_sizes[i][j];
5606 ti->sort_priority = value;
5608 sprintf(identifier, "%d", value);
5609 sprintf(name, "%s", text);
5611 setString(&ti->identifier, identifier);
5612 setString(&ti->name, name);
5613 setString(&ti->name_sorting, name);
5614 setString(&ti->infotext,
5617 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5618 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5620 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5621 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5623 pushTreeInfo(&grid_sizes[i][j], ti);
5626 /* sort grid size values to start with lowest grid size value */
5627 sortTreeInfo(&grid_sizes[i][j]);
5629 /* set current grid size value to configured grid size value */
5630 grid_size_current[i][j] =
5631 getTreeInfoFromIdentifier(grid_sizes[i][j],
5633 setup.touch.grid_xsize[i] :
5634 setup.touch.grid_ysize[i]));
5636 /* if that fails, set current grid size to reliable default value */
5637 if (grid_size_current[i][j] == NULL)
5638 grid_size_current[i][j] =
5639 getTreeInfoFromIdentifier(grid_sizes[i][j],
5641 DEFAULT_GRID_XSIZE(i) :
5642 DEFAULT_GRID_YSIZE(i)));
5644 /* if that also fails, set current grid size to first available value */
5645 if (grid_size_current[i][j] == NULL)
5646 grid_size_current[i][j] = grid_sizes[i][j];
5651 setup.touch.control_type = touch_control_current->identifier;
5652 setup.touch.move_distance = atoi(move_distance_current->identifier);
5653 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5654 setup.touch.transparency = atoi(transparency_current->identifier);
5656 for (i = 0; i < 2; i++)
5658 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5659 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5661 if (i == GRID_ACTIVE_NR())
5663 overlay.grid_xsize = setup.touch.grid_xsize[i];
5664 overlay.grid_ysize = setup.touch.grid_ysize[i];
5668 /* needed for displaying value text instead of identifier */
5669 touch_controls_text = touch_control_current->name;
5670 move_distance_text = move_distance_current->name;
5671 drop_distance_text = drop_distance_current->name;
5672 transparency_text = transparency_current->name;
5674 for (i = 0; i < 2; i++)
5675 for (j = 0; j < 2; j++)
5676 grid_size_text[i][j] = grid_size_current[i][j]->name;
5678 setup_mode = SETUP_MODE_TOUCH;
5683 static void execSetupArtwork()
5686 printf("::: '%s', '%s', '%s'\n",
5687 artwork.gfx_current->subdir,
5688 artwork.gfx_current->fullpath,
5689 artwork.gfx_current->basepath);
5692 setup.graphics_set = artwork.gfx_current->identifier;
5693 setup.sounds_set = artwork.snd_current->identifier;
5694 setup.music_set = artwork.mus_current->identifier;
5696 /* needed if last screen (setup choice) changed graphics, sounds or music */
5697 ReloadCustomArtwork(0);
5699 /* needed for displaying artwork name instead of artwork identifier */
5700 graphics_set_name = artwork.gfx_current->name;
5701 sounds_set_name = artwork.snd_current->name;
5702 music_set_name = artwork.mus_current->name;
5704 setup_mode = SETUP_MODE_ARTWORK;
5709 static void execSetupChooseGraphics()
5711 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5716 static void execSetupChooseSounds()
5718 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5723 static void execSetupChooseMusic()
5725 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5730 static void execSetupInput()
5732 setup_mode = SETUP_MODE_INPUT;
5737 static void execSetupShortcuts()
5739 setup_mode = SETUP_MODE_SHORTCUTS;
5744 static void execSetupShortcuts1()
5746 setup_mode = SETUP_MODE_SHORTCUTS_1;
5751 static void execSetupShortcuts2()
5753 setup_mode = SETUP_MODE_SHORTCUTS_2;
5758 static void execSetupShortcuts3()
5760 setup_mode = SETUP_MODE_SHORTCUTS_3;
5765 static void execSetupShortcuts4()
5767 setup_mode = SETUP_MODE_SHORTCUTS_4;
5772 static void execSetupShortcuts5()
5774 setup_mode = SETUP_MODE_SHORTCUTS_5;
5779 static void execExitSetup()
5781 SetGameStatus(GAME_MODE_MAIN);
5786 static void execSaveAndExitSetup()
5795 void *related_value;
5796 } hide_related_entry_list[] =
5798 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5799 { &setup.game_frame_delay, &game_speed_text },
5801 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5802 { &setup.scroll_delay_value, &scroll_delay_text },
5804 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5805 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5807 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5808 { &setup.window_scaling_percent, &window_size_text },
5810 { &setup.window_scaling_quality, execSetupChooseScalingType },
5811 { &setup.window_scaling_quality, &scaling_type_text },
5813 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5814 { &setup.screen_rendering_mode, &rendering_mode_text },
5816 { &setup.graphics_set, execSetupChooseGraphics },
5817 { &setup.graphics_set, &graphics_set_name },
5819 { &setup.sounds_set, execSetupChooseSounds },
5820 { &setup.sounds_set, &sounds_set_name },
5822 { &setup.music_set, execSetupChooseMusic },
5823 { &setup.music_set, &music_set_name },
5825 { &setup.volume_simple, execSetupChooseVolumeSimple },
5826 { &setup.volume_simple, &volume_simple_text },
5828 { &setup.volume_loops, execSetupChooseVolumeLoops },
5829 { &setup.volume_loops, &volume_loops_text },
5831 { &setup.volume_music, execSetupChooseVolumeMusic },
5832 { &setup.volume_music, &volume_music_text },
5834 { &setup.touch.control_type, execSetupChooseTouchControls },
5835 { &setup.touch.control_type, &touch_controls_text },
5837 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5838 { &setup.touch.move_distance, &move_distance_text },
5840 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5841 { &setup.touch.drop_distance, &drop_distance_text },
5843 { &setup.touch.transparency, execSetupChooseTransparency },
5844 { &setup.touch.transparency, &transparency_text },
5846 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5847 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5849 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5850 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5852 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5853 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5855 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5856 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5861 void setHideRelatedSetupEntries()
5865 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5866 if (hideSetupEntry(hide_related_entry_list[i].value))
5867 setHideSetupEntry(hide_related_entry_list[i].related_value);
5870 static struct TokenInfo setup_info_main[] =
5872 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5873 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5874 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5875 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5876 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5877 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5878 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5879 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5880 { TYPE_EMPTY, NULL, "" },
5881 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5882 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5887 static struct TokenInfo setup_info_game[] =
5889 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5890 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
5891 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
5892 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5893 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5894 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5895 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5896 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5897 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
5898 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
5899 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5900 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5901 { TYPE_STRING, &game_speed_text, "" },
5903 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5904 { TYPE_STRING, &scroll_delay_text, "" },
5906 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5907 { TYPE_STRING, &snapshot_mode_text, "" },
5908 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5909 { TYPE_EMPTY, NULL, "" },
5910 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5915 static struct TokenInfo setup_info_editor[] =
5918 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5919 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5920 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5921 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5922 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5923 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5924 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5925 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5926 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5927 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5929 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5930 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5932 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5934 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5935 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5936 { TYPE_EMPTY, NULL, "" },
5938 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5939 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5940 { TYPE_EMPTY, NULL, "" },
5942 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5943 { TYPE_EMPTY, NULL, "" },
5944 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5949 static struct TokenInfo setup_info_graphics[] =
5951 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5952 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5953 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5954 { TYPE_STRING, &window_size_text, "" },
5955 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5956 { TYPE_STRING, &scaling_type_text, "" },
5957 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5958 { TYPE_STRING, &rendering_mode_text, "" },
5961 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5962 { TYPE_STRING, &scroll_delay_text, "" },
5964 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5965 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5966 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5967 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5968 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5969 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5970 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5971 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5972 { TYPE_EMPTY, NULL, "" },
5973 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5978 static struct TokenInfo setup_info_sound[] =
5980 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5981 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5982 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5983 { TYPE_EMPTY, NULL, "" },
5984 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5985 { TYPE_STRING, &volume_simple_text, "" },
5986 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5987 { TYPE_STRING, &volume_loops_text, "" },
5988 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5989 { TYPE_STRING, &volume_music_text, "" },
5990 { TYPE_EMPTY, NULL, "" },
5991 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5996 static struct TokenInfo setup_info_artwork[] =
5998 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5999 { TYPE_STRING, &graphics_set_name, "" },
6000 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6001 { TYPE_STRING, &sounds_set_name, "" },
6002 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6003 { TYPE_STRING, &music_set_name, "" },
6004 { TYPE_EMPTY, NULL, "" },
6005 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6006 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6007 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6008 { TYPE_EMPTY, NULL, "" },
6009 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6014 static struct TokenInfo setup_info_input[] =
6016 { TYPE_SWITCH, NULL, "Player:" },
6017 { TYPE_SWITCH, NULL, "Device:" },
6018 { TYPE_SWITCH, NULL, "" },
6019 { TYPE_SKIPPABLE, NULL, "" },
6020 { TYPE_EMPTY, NULL, "" },
6021 { TYPE_EMPTY, NULL, "" },
6022 { TYPE_EMPTY, NULL, "" },
6023 { TYPE_EMPTY, NULL, "" },
6024 { TYPE_EMPTY, NULL, "" },
6025 { TYPE_EMPTY, NULL, "" },
6026 { TYPE_EMPTY, NULL, "" },
6027 { TYPE_EMPTY, NULL, "" },
6028 { TYPE_SKIPPABLE, NULL, "" },
6029 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6034 static struct TokenInfo setup_info_touch[] =
6036 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6037 { TYPE_STRING, &touch_controls_text, "" },
6038 { TYPE_EMPTY, NULL, "" },
6039 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6044 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6046 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6047 { TYPE_STRING, &touch_controls_text, "" },
6048 { TYPE_EMPTY, NULL, "" },
6049 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6050 { TYPE_STRING, &grid_size_text[0][0], "" },
6051 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6052 { TYPE_STRING, &grid_size_text[0][1], "" },
6053 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6054 { TYPE_STRING, &transparency_text, "" },
6055 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6056 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6057 { TYPE_EMPTY, NULL, "" },
6058 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6059 { TYPE_EMPTY, NULL, "" },
6060 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6065 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6067 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6068 { TYPE_STRING, &touch_controls_text, "" },
6069 { TYPE_EMPTY, NULL, "" },
6070 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6071 { TYPE_STRING, &grid_size_text[1][0], "" },
6072 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6073 { TYPE_STRING, &grid_size_text[1][1], "" },
6074 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6075 { TYPE_STRING, &transparency_text, "" },
6076 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6077 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6078 { TYPE_EMPTY, NULL, "" },
6079 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6080 { TYPE_EMPTY, NULL, "" },
6081 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6086 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6088 setup_info_touch_virtual_buttons_0,
6089 setup_info_touch_virtual_buttons_1
6092 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6094 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6095 { TYPE_STRING, &touch_controls_text, "" },
6096 { TYPE_EMPTY, NULL, "" },
6097 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6098 { TYPE_STRING, &move_distance_text, "" },
6099 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6100 { TYPE_STRING, &drop_distance_text, "" },
6101 { TYPE_EMPTY, NULL, "" },
6102 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6107 static struct TokenInfo setup_info_shortcuts[] =
6109 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6110 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6111 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6112 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6113 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6114 { TYPE_EMPTY, NULL, "" },
6115 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6120 static struct TokenInfo setup_info_shortcuts_1[] =
6122 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6123 { TYPE_KEY, &setup.shortcut.save_game, "" },
6124 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6125 { TYPE_KEY, &setup.shortcut.load_game, "" },
6126 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6127 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6128 { TYPE_EMPTY, NULL, "" },
6129 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6130 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6131 { TYPE_EMPTY, NULL, "" },
6132 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6137 static struct TokenInfo setup_info_shortcuts_2[] =
6139 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6140 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6141 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6142 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6143 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6144 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6145 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6146 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6147 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6148 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6149 { TYPE_EMPTY, NULL, "" },
6150 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6155 static struct TokenInfo setup_info_shortcuts_3[] =
6157 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6158 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6159 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6160 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6161 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6162 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6163 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6164 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6165 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6166 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6167 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6168 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6169 { TYPE_EMPTY, NULL, "" },
6170 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6175 static struct TokenInfo setup_info_shortcuts_4[] =
6177 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6178 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6179 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6180 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6181 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6182 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6183 { TYPE_EMPTY, NULL, "" },
6184 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6189 static struct TokenInfo setup_info_shortcuts_5[] =
6191 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6192 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6193 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6194 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6195 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6196 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6197 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6198 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6199 { TYPE_EMPTY, NULL, "" },
6200 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6205 static Key getSetupKey()
6207 Key key = KSYM_UNDEFINED;
6208 boolean got_key_event = FALSE;
6210 while (!got_key_event)
6214 if (NextValidEvent(&event))
6218 case EVENT_KEYPRESS:
6220 key = GetEventKey((KeyEvent *)&event, TRUE);
6222 /* press 'Escape' or 'Enter' to keep the existing key binding */
6223 if (key == KSYM_Escape || key == KSYM_Return)
6224 key = KSYM_UNDEFINED; /* keep old value */
6226 got_key_event = TRUE;
6230 case EVENT_KEYRELEASE:
6231 key_joystick_mapping = 0;
6235 HandleOtherEvents(&event);
6246 static int getSetupValueFont(int type, void *value)
6248 if (type & TYPE_GHOSTED)
6249 return FONT_OPTION_OFF;
6250 else if (type & TYPE_KEY)
6251 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6252 else if (type & TYPE_STRING)
6253 return FONT_VALUE_2;
6254 else if (type & TYPE_ECS_AGA)
6255 return FONT_VALUE_1;
6256 else if (type & TYPE_BOOLEAN_STYLE)
6257 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6258 else if (type & TYPE_YES_NO_AUTO)
6259 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6260 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6261 else if (type & TYPE_PLAYER)
6262 return FONT_VALUE_1;
6264 return FONT_VALUE_1;
6267 static int getSetupValueFontNarrow(int type, int font_nr)
6269 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6270 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6271 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6275 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6277 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6278 struct TokenInfo *si = &setup_info[si_pos];
6279 boolean font_draw_xoffset_modified = FALSE;
6280 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6281 int font_draw_xoffset_old = -1;
6282 int xoffset = (scrollbar_needed ? -1 : 0);
6283 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6284 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6285 int xpos = menu_screen_value_xpos;
6286 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6287 int startx = mSX + xpos * 32;
6288 int starty = mSY + ypos * 32;
6289 int font_nr, font_nr_default, font_width_default;
6290 int type = si->type;
6291 void *value = si->value;
6292 char *value_string = getSetupValue(type, value);
6295 if (value_string == NULL)
6298 if (type & TYPE_KEY)
6300 xpos = MENU_SCREEN_START_XPOS;
6302 if (type & TYPE_QUERY)
6303 value_string = "<press key>";
6305 else if (type & TYPE_STRING)
6307 int max_value_len = (SCR_FIELDX - 2) * 2;
6309 xpos = MENU_SCREEN_START_XPOS;
6311 if (strlen(value_string) > max_value_len)
6312 value_string[max_value_len] = '\0';
6314 else if (type & TYPE_YES_NO_AUTO)
6316 xpos = menu_screen_value_xpos - 1;
6318 else if (type & TYPE_PLAYER)
6320 int displayed_player_nr = *(int *)value + 1;
6322 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6325 startx = mSX + xpos * 32;
6326 starty = mSY + ypos * 32;
6327 font_nr_default = getSetupValueFont(type, value);
6328 font_width_default = getFontWidth(font_nr_default);
6330 font_nr = font_nr_default;
6332 // special check if right-side setup values moved left due to scrollbar
6333 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6335 int max_menu_text_length = 26; // maximum text length for classic menu
6336 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6337 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6338 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6339 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6340 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6342 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6345 startx = mSX + xpos * 32;
6347 font_nr = getSetupValueFontNarrow(type, font_nr);
6351 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6352 if (setup_mode != SETUP_MODE_INPUT)
6354 int max_menu_text_length_big = (menu_screen_value_xpos -
6355 MENU_SCREEN_START_XPOS);
6356 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6357 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6358 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6359 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6360 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6361 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6362 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6363 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6364 boolean correct_font_draw_xoffset = FALSE;
6366 if (xpos == MENU_SCREEN_START_XPOS &&
6367 startx + font1_xoffset < text_startx + text_font_xoffset)
6368 correct_font_draw_xoffset = TRUE;
6370 if (xpos == menu_screen_value_xpos &&
6371 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6372 correct_font_draw_xoffset = TRUE;
6374 /* check if setup value would overlap with setup text when printed */
6375 /* (this can happen for extreme/wrong values for font draw offset) */
6376 if (correct_font_draw_xoffset)
6378 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6379 font_draw_xoffset_modified = TRUE;
6381 if (type & TYPE_KEY)
6382 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6383 else if (!(type & TYPE_STRING))
6384 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6385 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6389 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6390 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6392 DrawText(startx, starty, value_string, font_nr);
6394 if (type & TYPE_PLAYER)
6396 int player_nr = *(int *)value;
6397 int xoff = getFontWidth(font_nr);
6399 DrawFixedGraphicThruMaskExt(drawto, startx + xoff, starty,
6400 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6403 if (font_draw_xoffset_modified)
6404 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6407 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6409 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6410 struct TokenInfo *si = &setup_info[si_pos];
6412 if (si->type & TYPE_BOOLEAN_STYLE)
6414 *(boolean *)si->value ^= TRUE;
6416 else if (si->type & TYPE_YES_NO_AUTO)
6420 (*(int *)si->value == AUTO ? TRUE :
6421 *(int *)si->value == TRUE ? FALSE : AUTO) :
6422 (*(int *)si->value == TRUE ? AUTO :
6423 *(int *)si->value == AUTO ? FALSE : TRUE));
6425 else if (si->type & TYPE_KEY)
6429 si->type |= TYPE_QUERY;
6430 drawSetupValue(screen_pos, setup_info_pos_raw);
6431 si->type &= ~TYPE_QUERY;
6433 key = getSetupKey();
6434 if (key != KSYM_UNDEFINED)
6435 *(Key *)si->value = key;
6437 else if (si->type & TYPE_PLAYER)
6439 int player_nr = *(int *)si->value;
6444 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6446 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6449 drawSetupValue(screen_pos, setup_info_pos_raw);
6451 // fullscreen state may have changed at this point
6452 if (si->value == &setup.fullscreen)
6453 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6455 if (si->value == &setup.network_mode &&
6456 setup.network_mode != network.enabled)
6458 network.enabled = setup.network_mode;
6460 FadeOut(REDRAW_ALL);
6466 if (network.enabled)
6467 InitNetworkServer();
6469 DisconnectFromNetworkServer();
6475 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6477 static struct TokenInfo *setup_info_final = NULL;
6482 /* determine maximum list size of target list */
6483 while (setup_info_orig[list_size++].type != 0);
6485 /* free, allocate and clear memory for target list */
6486 checked_free(setup_info_final);
6487 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6489 /* copy setup info list without setup entries marked as hidden */
6490 for (i = 0; setup_info_orig[i].type != 0; i++)
6492 /* skip setup entries configured to be hidden */
6493 if (hideSetupEntry(setup_info_orig[i].value))
6496 /* skip skippable setup entries if screen is lower than usual */
6497 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6498 setup_info_orig[i].type == TYPE_SKIPPABLE)
6501 setup_info_final[list_pos++] = setup_info_orig[i];
6504 return setup_info_final;
6507 static void DrawSetupScreen_Generic()
6509 int fade_mask = REDRAW_FIELD;
6510 boolean redraw_all = FALSE;
6511 char *title_string = NULL;
6514 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6515 fade_mask = REDRAW_ALL;
6518 FadeMenuSoundsAndMusic();
6520 FreeScreenGadgets();
6521 CreateScreenGadgets();
6523 if (redraw_mask & REDRAW_ALL)
6528 /* needed if different viewport properties defined for setup screen */
6529 ChangeViewportPropertiesIfNeeded();
6531 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6535 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6537 if (setup_mode == SETUP_MODE_MAIN)
6539 setup_info = setup_info_main;
6540 title_string = STR_SETUP_MAIN;
6542 else if (setup_mode == SETUP_MODE_GAME)
6544 setup_info = setup_info_game;
6545 title_string = STR_SETUP_GAME;
6547 else if (setup_mode == SETUP_MODE_EDITOR)
6549 setup_info = setup_info_editor;
6550 title_string = STR_SETUP_EDITOR;
6552 else if (setup_mode == SETUP_MODE_GRAPHICS)
6554 setup_info = setup_info_graphics;
6555 title_string = STR_SETUP_GRAPHICS;
6557 else if (setup_mode == SETUP_MODE_SOUND)
6559 setup_info = setup_info_sound;
6560 title_string = STR_SETUP_SOUND;
6562 else if (setup_mode == SETUP_MODE_ARTWORK)
6564 setup_info = setup_info_artwork;
6565 title_string = STR_SETUP_ARTWORK;
6567 else if (setup_mode == SETUP_MODE_TOUCH)
6569 setup_info = setup_info_touch;
6570 title_string = STR_SETUP_TOUCH;
6572 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6573 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6574 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6575 setup_info = setup_info_touch_wipe_gestures;
6577 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6579 setup_info = setup_info_shortcuts;
6580 title_string = STR_SETUP_SHORTCUTS;
6582 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6584 setup_info = setup_info_shortcuts_1;
6585 title_string = STR_SETUP_SHORTCUTS;
6587 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6589 setup_info = setup_info_shortcuts_2;
6590 title_string = STR_SETUP_SHORTCUTS;
6592 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6594 setup_info = setup_info_shortcuts_3;
6595 title_string = STR_SETUP_SHORTCUTS;
6597 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6599 setup_info = setup_info_shortcuts_4;
6600 title_string = STR_SETUP_SHORTCUTS;
6602 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6604 setup_info = setup_info_shortcuts_5;
6605 title_string = STR_SETUP_SHORTCUTS;
6608 /* use modified setup info without setup entries marked as hidden */
6609 setup_info = getSetupInfoFinal(setup_info);
6611 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6613 // determine maximal number of setup entries that can be displayed on screen
6615 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6618 // determine maximal number of setup entries available for this setup screen
6620 for (i = 0; setup_info[i].type != 0; i++)
6623 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6625 MapScreenGadgets(max_setup_info);
6628 redraw_mask = fade_mask = REDRAW_ALL;
6630 DrawMaskedBorder(fade_mask);
6635 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6637 menu_info = setup_info;
6639 HandleMenuScreen(mx, my, dx, dy, button,
6640 setup_mode, num_setup_info, max_setup_info);
6643 void DrawSetupScreen_Input()
6647 FadeOut(REDRAW_FIELD);
6651 setup_info = getSetupInfoFinal(setup_info_input);
6653 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6655 for (i = 0; setup_info[i].type != 0; i++)
6657 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6658 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6659 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6660 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6661 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6662 initCursor(i, IMG_MENU_BUTTON);
6664 DrawCursorAndText_Setup(i, -1, FALSE);
6667 /* create gadgets for setup input menu screen */
6668 FreeScreenGadgets();
6669 CreateScreenGadgets();
6671 /* map gadgets for setup input menu screen */
6672 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6674 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6676 FadeIn(REDRAW_FIELD);
6679 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6681 if (device_name == NULL)
6684 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6687 if (strlen(device_name) > 1)
6689 char c1 = device_name[strlen(device_name) - 1];
6690 char c2 = device_name[strlen(device_name) - 2];
6692 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6693 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6696 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6697 strlen(device_name));
6700 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6703 static struct SetupKeyboardInfo custom_key;
6710 { &custom_key.left, "Axis/Pad Left" },
6711 { &custom_key.right, "Axis/Pad Right" },
6712 { &custom_key.up, "Axis/Pad Up" },
6713 { &custom_key.down, "Axis/Pad Down" },
6714 { &custom_key.snap, "Button 1/A/X" },
6715 { &custom_key.drop, "Button 2/B/Y" }
6717 static char *joystick_name[MAX_PLAYERS] =
6724 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6725 int font_nr_info = FONT_MENU_1;
6726 int font_nr_name = FONT_VALUE_OLD;
6727 int font_nr_on = FONT_VALUE_1;
6728 int font_nr_off = FONT_VALUE_OLD;
6731 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6733 font_nr_info = FONT_MENU_2;
6734 font_nr_on = FONT_VALUE_NARROW;
6735 font_nr_off = FONT_VALUE_OLD_NARROW;
6738 custom_key = setup.input[player_nr].key;
6740 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6741 FONT_INPUT_1_ACTIVE);
6743 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6745 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6746 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6748 if (setup.input[player_nr].use_joystick)
6750 char *device_name = setup.input[player_nr].joy.device_name;
6751 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6752 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6753 char *text = joystick_name[joystick_nr];
6754 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6756 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6757 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6761 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6762 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6765 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6766 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6770 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6771 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6772 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6773 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6775 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6776 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6777 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6778 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6779 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6780 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6782 for (i = 0; i < 6; i++)
6784 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6786 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6788 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6789 (setup.input[player_nr].use_joystick ?
6791 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6795 static int input_player_nr = 0;
6797 void HandleSetupScreen_Input_Player(int step, int direction)
6799 int old_player_nr = input_player_nr;
6802 new_player_nr = old_player_nr + step * direction;
6803 if (new_player_nr < 0)
6805 if (new_player_nr > MAX_PLAYERS - 1)
6806 new_player_nr = MAX_PLAYERS - 1;
6808 if (new_player_nr != old_player_nr)
6810 input_player_nr = new_player_nr;
6812 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6816 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6818 static int choice = 0;
6821 int pos_start = SETUPINPUT_SCREEN_POS_START;
6822 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6823 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6824 int pos_end = SETUPINPUT_SCREEN_POS_END;
6826 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6830 for (i = 0; setup_info_input[i].type != 0; i++)
6832 /* adjust menu structure according to skipped setup entries */
6833 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6841 if (button == MB_MENU_INITIALIZE)
6843 /* input setup menu may have changed size due to graphics configuration */
6844 if (choice >= pos_empty1)
6847 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6849 DrawCursorAndText_Setup(choice, -1, TRUE);
6853 else if (button == MB_MENU_LEAVE)
6855 setup_mode = SETUP_MODE_MAIN;
6862 if (mx || my) /* mouse input */
6864 x = (mx - mSX) / 32;
6865 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6867 else if (dx || dy) /* keyboard input */
6869 if (dx && choice == 0)
6870 x = (dx < 0 ? 10 : 12);
6871 else if ((dx && choice == 1) ||
6872 (dx == -1 && choice == pos_end))
6873 button = MB_MENU_CHOICE;
6877 if (y >= pos_empty1 && y <= pos_empty2)
6878 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6881 if (y == 0 && dx != 0 && button)
6883 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6885 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6886 y >= pos_start && y <= pos_end &&
6887 !(y >= pos_empty1 && y <= pos_empty2))
6893 DrawCursorAndText_Setup(choice, -1, FALSE);
6894 DrawCursorAndText_Setup(y, -1, TRUE);
6896 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6905 char *device_name = setup.input[input_player_nr].joy.device_name;
6907 if (!setup.input[input_player_nr].use_joystick)
6909 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6911 setJoystickDeviceToNr(device_name, new_device_nr);
6912 setup.input[input_player_nr].use_joystick = TRUE;
6916 int device_nr = getJoystickNrFromDeviceName(device_name);
6917 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6919 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6920 setup.input[input_player_nr].use_joystick = FALSE;
6922 setJoystickDeviceToNr(device_name, new_device_nr);
6925 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6929 if (setup.input[input_player_nr].use_joystick)
6930 ConfigureJoystick(input_player_nr);
6932 CustomizeKeyboard(input_player_nr);
6934 else if (y == pos_end)
6940 setup_mode = SETUP_MODE_MAIN;
6947 static boolean CustomizeKeyboardMain(int player_nr)
6951 boolean finished = FALSE;
6952 static struct SetupKeyboardInfo custom_key;
6957 } customize_step[] =
6959 { &custom_key.left, "Move Left" },
6960 { &custom_key.right, "Move Right" },
6961 { &custom_key.up, "Move Up" },
6962 { &custom_key.down, "Move Down" },
6963 { &custom_key.snap, "Snap Field" },
6964 { &custom_key.drop, "Drop Element" }
6966 int font_nr_old = FONT_VALUE_OLD;
6967 int font_nr_new = FONT_VALUE_1;
6968 boolean success = FALSE;
6970 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6972 font_nr_old = FONT_VALUE_OLD_NARROW;
6973 font_nr_new = FONT_VALUE_NARROW;
6976 /* read existing key bindings from player setup */
6977 custom_key = setup.input[player_nr].key;
6980 FadeOut(REDRAW_FIELD);
6984 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6987 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6988 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6989 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6990 "Key:", FONT_INPUT_1_ACTIVE);
6991 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6992 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
6994 FadeIn(REDRAW_FIELD);
7000 if (NextValidEvent(&event))
7004 case EVENT_KEYPRESS:
7006 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7008 /* press 'Escape' to abort and keep the old key bindings */
7009 if (key == KSYM_Escape)
7011 FadeSkipNextFadeIn();
7018 /* press 'Enter' to keep the existing key binding */
7019 if (key == KSYM_Return)
7020 key = *customize_step[step_nr].key;
7022 /* check if key already used */
7023 for (i = 0; i < step_nr; i++)
7024 if (*customize_step[i].key == key)
7029 /* got new key binding */
7030 *customize_step[step_nr].key = key;
7031 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7033 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7034 getKeyNameFromKey(key), font_nr_new);
7037 /* un-highlight last query */
7038 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7039 customize_step[step_nr - 1].text, FONT_MENU_1);
7040 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7041 "Key:", FONT_MENU_1);
7043 /* all keys configured */
7052 /* query next key binding */
7053 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7054 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7055 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7056 "Key:", FONT_INPUT_1_ACTIVE);
7057 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7058 getKeyNameFromKey(*customize_step[step_nr].key),
7063 case EVENT_KEYRELEASE:
7064 key_joystick_mapping = 0;
7068 HandleOtherEvents(&event);
7076 /* write new key bindings back to player setup, if successfully finished */
7078 setup.input[player_nr].key = custom_key;
7083 void CustomizeKeyboard(int player_nr)
7085 boolean success = CustomizeKeyboardMain(player_nr);
7089 int font_nr = FONT_TITLE_1;
7090 int font_height = getFontHeight(font_nr);
7091 int ypos1 = SYSIZE / 2 - font_height * 2;
7092 int ypos2 = SYSIZE / 2 - font_height * 1;
7093 unsigned int wait_frame_delay = 0;
7094 unsigned int wait_frame_delay_value = 2000;
7096 ResetDelayCounter(&wait_frame_delay);
7100 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7101 DrawTextSCentered(ypos2, font_nr, "configured!");
7103 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7109 DrawSetupScreen_Input();
7112 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7114 #define MARKER_BUTTON 1
7115 #define MARKER_AXIS_X 2
7116 #define MARKER_AXIS_Y 3
7118 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7120 #if defined(TARGET_SDL2)
7121 static boolean bitmaps_initialized = FALSE;
7122 boolean screen_initialized = FALSE;
7123 static Bitmap *controller, *button, *axis_x, *axis_y;
7125 boolean success = TRUE;
7126 boolean done = FALSE, next = FALSE;
7128 int alpha = 200, alpha_step = -1;
7129 int alpha_ticks = 0;
7130 char mapping[4096], temp[4096];
7131 int font_name = MENU_SETUP_FONT_TITLE;
7132 int font_info = MENU_SETUP_FONT_TEXT;
7133 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7134 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7135 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7136 int ystep_name = getMenuTextStep(spacing_name, font_name);
7137 int ystep_line = getMenuTextStep(spacing_line, font_info);
7138 int ystep_para = getMenuTextStep(spacing_para, font_info);
7146 int axis, button, hat, hat_value;
7149 *step, *prev_step, steps[] =
7151 { 356, 155, MARKER_BUTTON, "a", },
7152 { 396, 122, MARKER_BUTTON, "b", },
7153 { 320, 125, MARKER_BUTTON, "x", },
7154 { 358, 95, MARKER_BUTTON, "y", },
7155 { 162, 125, MARKER_BUTTON, "back", },
7156 { 216, 125, MARKER_BUTTON, "guide", },
7157 { 271, 125, MARKER_BUTTON, "start", },
7158 { 110, 200, MARKER_BUTTON, "dpleft", },
7159 { 146, 228, MARKER_BUTTON, "dpdown", },
7160 { 178, 200, MARKER_BUTTON, "dpright", },
7161 { 146, 172, MARKER_BUTTON, "dpup", },
7162 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7163 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7164 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7165 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7166 { 73, 141, MARKER_BUTTON, "leftstick", },
7167 { 282, 210, MARKER_BUTTON, "rightstick", },
7168 { 73, 141, MARKER_AXIS_X, "leftx", },
7169 { 73, 141, MARKER_AXIS_Y, "lefty", },
7170 { 282, 210, MARKER_AXIS_X, "rightx", },
7171 { 282, 210, MARKER_AXIS_Y, "righty", },
7174 unsigned int event_frame_delay = 0;
7175 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7177 ResetDelayCounter(&event_frame_delay);
7179 if (!bitmaps_initialized)
7181 controller = LoadCustomImage("joystick/controller.png");
7182 button = LoadCustomImage("joystick/button.png");
7183 axis_x = LoadCustomImage("joystick/axis_x.png");
7184 axis_y = LoadCustomImage("joystick/axis_y.png");
7186 bitmaps_initialized = TRUE;
7189 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7192 /* print info about the joystick we are watching */
7193 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7194 SDL_JoystickInstanceID(joystick), name);
7195 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7196 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7197 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7200 /* initialize mapping with GUID and name */
7201 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7203 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7204 temp, name, SDL_GetPlatform());
7206 /* loop through all steps (buttons and axes), getting joystick events */
7207 for (i = 0; i < SDL_arraysize(steps) && !done;)
7209 Bitmap *marker = button; /* initialize with reliable default value */
7212 strcpy(step->mapping, mapping);
7216 step->hat_value = -1;
7218 marker = (step->marker == MARKER_BUTTON ? button :
7219 step->marker == MARKER_AXIS_X ? axis_x :
7220 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7224 while (!done && !next)
7226 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7227 alpha_ticks = SDL_GetTicks();
7234 else if (alpha < 128)
7240 int controller_x = SX + (SXSIZE - controller->width) / 2;
7241 int controller_y = SY + ystep_line;
7243 int marker_x = controller_x + step->x;
7244 int marker_y = controller_y + step->y;
7246 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7247 int ystart2 = ystart1 + ystep_name + ystep_line;
7251 DrawTextSCentered(ystart1, font_name, name);
7253 DrawTextSCentered(ystart2, font_info,
7254 "Press buttons and move axes on");
7255 ystart2 += ystep_line;
7256 DrawTextSCentered(ystart2, font_info,
7257 "your controller when indicated.");
7258 ystart2 += ystep_line;
7259 DrawTextSCentered(ystart2, font_info,
7260 "(Your controller may look different.)");
7261 ystart2 += ystep_para;
7263 #if defined(PLATFORM_ANDROID)
7264 DrawTextSCentered(ystart2, font_info,
7265 "To correct a mistake,");
7266 ystart2 += ystep_line;
7267 DrawTextSCentered(ystart2, font_info,
7268 "press the 'back' button.");
7269 ystart2 += ystep_line;
7270 DrawTextSCentered(ystart2, font_info,
7271 "To skip a button or axis,");
7272 ystart2 += ystep_line;
7273 DrawTextSCentered(ystart2, font_info,
7274 "press the 'menu' button.");
7276 DrawTextSCentered(ystart2, font_info,
7277 "To correct a mistake,");
7278 ystart2 += ystep_line;
7279 DrawTextSCentered(ystart2, font_info,
7280 "press the 'backspace' key.");
7281 ystart2 += ystep_line;
7282 DrawTextSCentered(ystart2, font_info,
7283 "To skip a button or axis,");
7284 ystart2 += ystep_line;
7285 DrawTextSCentered(ystart2, font_info,
7286 "press the 'return' key.");
7287 ystart2 += ystep_line;
7288 DrawTextSCentered(ystart2, font_info,
7289 "To exit, press the 'escape' key.");
7292 BlitBitmapMasked(controller, drawto, 0, 0,
7293 controller->width, controller->height,
7294 controller_x, controller_y);
7296 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7297 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7299 BlitBitmapMasked(marker, drawto, 0, 0,
7300 marker->width, marker->height,
7301 marker_x, marker_y);
7303 if (!screen_initialized)
7304 FadeIn(REDRAW_FIELD);
7308 screen_initialized = TRUE;
7310 while (NextValidEvent(&event))
7314 case SDL_JOYAXISMOTION:
7315 if (event.jaxis.value > 20000 ||
7316 event.jaxis.value < -20000)
7318 for (j = 0; j < i; j++)
7319 if (steps[j].axis == event.jaxis.axis)
7324 if (step->marker != MARKER_AXIS_X &&
7325 step->marker != MARKER_AXIS_Y)
7328 step->axis = event.jaxis.axis;
7329 strcat(mapping, step->field);
7330 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7331 strcat(mapping, temp);
7339 case SDL_JOYHATMOTION:
7340 /* ignore centering; we're probably just coming back
7341 to the center from the previous item we set */
7342 if (event.jhat.value == SDL_HAT_CENTERED)
7345 for (j = 0; j < i; j++)
7346 if (steps[j].hat == event.jhat.hat &&
7347 steps[j].hat_value == event.jhat.value)
7352 step->hat = event.jhat.hat;
7353 step->hat_value = event.jhat.value;
7354 strcat(mapping, step->field);
7355 snprintf(temp, sizeof(temp), ":h%u.%u,",
7356 event.jhat.hat, event.jhat.value );
7357 strcat(mapping, temp);
7364 case SDL_JOYBALLMOTION:
7367 case SDL_JOYBUTTONUP:
7368 for (j = 0; j < i; j++)
7369 if (steps[j].button == event.jbutton.button)
7374 step->button = event.jbutton.button;
7375 strcat(mapping, step->field);
7376 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7377 strcat(mapping, temp);
7384 case SDL_FINGERDOWN:
7385 case SDL_MOUSEBUTTONDOWN:
7386 /* skip this step */
7393 if (event.key.keysym.sym == KSYM_BackSpace ||
7394 event.key.keysym.sym == KSYM_Back)
7405 /* undo this step */
7406 prev_step = &steps[i - 1];
7407 strcpy(mapping, prev_step->mapping);
7414 if (event.key.keysym.sym == KSYM_space ||
7415 event.key.keysym.sym == KSYM_Return ||
7416 event.key.keysym.sym == KSYM_Menu)
7418 /* skip this step */
7425 if (event.key.keysym.sym == KSYM_Escape)
7435 program.exit_function(0);
7442 // do not handle events for longer than standard frame delay period
7443 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7452 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7455 // activate mapping for this game
7456 SDL_GameControllerAddMapping(mapping);
7458 // save mapping to personal mappings
7459 SaveSetup_AddGameControllerMapping(mapping);
7462 /* wait until the last pending event was removed from event queue */
7463 while (NextValidEvent(&event));
7471 static int ConfigureJoystickMain(int player_nr)
7473 char *device_name = setup.input[player_nr].joy.device_name;
7474 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7475 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7476 int success = FALSE;
7479 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7480 return JOYSTICK_NOT_AVAILABLE;
7482 if (!joystick_active || !setup.input[player_nr].use_joystick)
7483 return JOYSTICK_NOT_AVAILABLE;
7486 FadeOut(REDRAW_FIELD);
7488 // close all joystick devices (potentially opened as game controllers)
7489 for (i = 0; i < SDL_NumJoysticks(); i++)
7490 SDLCloseJoystick(i);
7492 // open joystick device as plain joystick to configure as game controller
7493 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7495 // as the joystick was successfully opened before, this should not happen
7496 if (joystick == NULL)
7499 // create new game controller mapping (buttons and axes) for joystick device
7500 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7502 // close joystick (and maybe re-open as configured game controller later)
7503 SDL_JoystickClose(joystick);
7505 // re-open all joystick devices (potentially as game controllers)
7506 for (i = 0; i < SDL_NumJoysticks(); i++)
7509 // clear all joystick input actions for all joystick devices
7510 SDLClearJoystickState();
7512 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7515 void ConfigureJoystick(int player_nr)
7517 boolean state = ConfigureJoystickMain(player_nr);
7519 if (state != JOYSTICK_NOT_CONFIGURED)
7521 boolean success = (state == JOYSTICK_CONFIGURED);
7522 char message1[MAX_OUTPUT_LINESIZE + 1];
7523 char *message2 = (success ? "configured!" : "not available!");
7524 char *device_name = setup.input[player_nr].joy.device_name;
7525 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7526 int font_nr = FONT_TITLE_1;
7527 int font_height = getFontHeight(font_nr);
7528 int ypos1 = SYSIZE / 2 - font_height * 2;
7529 int ypos2 = SYSIZE / 2 - font_height * 1;
7530 unsigned int wait_frame_delay = 0;
7531 unsigned int wait_frame_delay_value = 2000;
7533 ResetDelayCounter(&wait_frame_delay);
7537 sprintf(message1, "Joystick %d", nr);
7539 DrawTextSCentered(ypos1, font_nr, message1);
7540 DrawTextSCentered(ypos2, font_nr, message2);
7542 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7548 DrawSetupScreen_Input();
7551 boolean ConfigureVirtualButtonsMain()
7553 static char *customize_step_text[] =
7562 char grid_button[] =
7564 CHAR_GRID_BUTTON_LEFT,
7565 CHAR_GRID_BUTTON_RIGHT,
7566 CHAR_GRID_BUTTON_UP,
7567 CHAR_GRID_BUTTON_DOWN,
7568 CHAR_GRID_BUTTON_SNAP,
7569 CHAR_GRID_BUTTON_DROP
7571 int font_nr = FONT_INPUT_1_ACTIVE;
7572 int font_height = getFontHeight(font_nr);
7573 int ypos1 = SYSIZE / 2 - font_height * 2;
7574 int ypos2 = SYSIZE / 2 - font_height * 1;
7575 boolean success = FALSE;
7576 boolean finished = FALSE;
7578 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7579 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7580 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7581 boolean set_grid_button = FALSE;
7582 int nr = GRID_ACTIVE_NR();
7585 for (x = 0; x < MAX_GRID_XSIZE; x++)
7586 for (y = 0; y < MAX_GRID_YSIZE; y++)
7587 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7589 overlay.grid_button_highlight = grid_button[step_nr];
7592 FadeOut(REDRAW_FIELD);
7596 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7597 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7598 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7600 FadeIn(REDRAW_FIELD);
7602 SetOverlayShowGrid(TRUE);
7608 while (NextValidEvent(&event))
7612 case EVENT_KEYPRESS:
7614 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7616 /* press 'Escape' to abort and keep the old key bindings */
7617 if (key == KSYM_Escape)
7619 for (x = 0; x < MAX_GRID_XSIZE; x++)
7620 for (y = 0; y < MAX_GRID_YSIZE; y++)
7621 overlay.grid_button[x][y] = grid_button_old[x][y];
7623 FadeSkipNextFadeIn();
7630 /* press 'Enter' to keep the existing key binding */
7631 if (key == KSYM_Return ||
7632 #if defined(TARGET_SDL2)
7639 else if (key == KSYM_BackSpace
7640 #if defined(TARGET_SDL2)
7648 FadeSkipNextFadeIn();
7662 /* all virtual buttons configured */
7671 for (x = 0; x < MAX_GRID_XSIZE; x++)
7672 for (y = 0; y < MAX_GRID_YSIZE; y++)
7673 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7675 overlay.grid_button_highlight = grid_button[step_nr];
7677 /* query next virtual button */
7681 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7682 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7683 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7687 case EVENT_KEYRELEASE:
7688 key_joystick_mapping = 0;
7691 case EVENT_BUTTONPRESS:
7692 case EVENT_BUTTONRELEASE:
7694 ButtonEvent *button = (ButtonEvent *)&event;
7696 button->x += video.screen_xoffset;
7697 button->y += video.screen_yoffset;
7699 x = button->x * overlay.grid_xsize / video.screen_width;
7700 y = button->y * overlay.grid_ysize / video.screen_height;
7702 if (button->type == EVENT_BUTTONPRESS)
7704 button_status = button->button;
7707 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7708 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7710 set_grid_button = TRUE;
7714 button_status = MB_RELEASED;
7719 case EVENT_MOTIONNOTIFY:
7721 MotionEvent *motion = (MotionEvent *)&event;
7723 motion->x += video.screen_xoffset;
7724 motion->y += video.screen_yoffset;
7726 x = motion->x * overlay.grid_xsize / video.screen_width;
7727 y = motion->y * overlay.grid_ysize / video.screen_height;
7729 set_grid_button = TRUE;
7733 #if defined(TARGET_SDL2)
7734 case SDL_WINDOWEVENT:
7735 HandleWindowEvent((WindowEvent *) &event);
7737 // check if device has been rotated
7738 if (nr != GRID_ACTIVE_NR())
7740 nr = GRID_ACTIVE_NR();
7742 for (x = 0; x < MAX_GRID_XSIZE; x++)
7743 for (y = 0; y < MAX_GRID_YSIZE; y++)
7744 grid_button_old[x][y] = grid_button_tmp[x][y] =
7745 overlay.grid_button[x][y];
7750 case SDL_APP_WILLENTERBACKGROUND:
7751 case SDL_APP_DIDENTERBACKGROUND:
7752 case SDL_APP_WILLENTERFOREGROUND:
7753 case SDL_APP_DIDENTERFOREGROUND:
7754 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7759 HandleOtherEvents(&event);
7763 if (set_grid_button)
7765 overlay.grid_button[x][y] =
7766 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7767 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7768 grid_button_tmp[x][y]);
7770 set_grid_button = FALSE;
7777 for (x = 0; x < MAX_GRID_XSIZE; x++)
7778 for (y = 0; y < MAX_GRID_YSIZE; y++)
7779 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7781 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7783 SetOverlayShowGrid(FALSE);
7788 void ConfigureVirtualButtons()
7790 boolean success = ConfigureVirtualButtonsMain();
7794 int font_nr = FONT_TITLE_1;
7795 int font_height = getFontHeight(font_nr);
7796 int ypos1 = SYSIZE / 2 - font_height * 2;
7797 int ypos2 = SYSIZE / 2 - font_height * 1;
7798 unsigned int wait_frame_delay = 0;
7799 unsigned int wait_frame_delay_value = 2000;
7801 ResetDelayCounter(&wait_frame_delay);
7805 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7806 DrawTextSCentered(ypos2, font_nr, "configured!");
7808 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7815 void DrawSetupScreen()
7817 if (setup_mode == SETUP_MODE_INPUT)
7818 DrawSetupScreen_Input();
7819 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7820 DrawChooseTree(&game_speed_current);
7821 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7822 DrawChooseTree(&scroll_delay_current);
7823 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7824 DrawChooseTree(&snapshot_mode_current);
7825 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7826 DrawChooseTree(&window_size_current);
7827 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7828 DrawChooseTree(&scaling_type_current);
7829 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7830 DrawChooseTree(&rendering_mode_current);
7831 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7832 DrawChooseTree(&artwork.gfx_current);
7833 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7834 DrawChooseTree(&artwork.snd_current);
7835 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7836 DrawChooseTree(&artwork.mus_current);
7837 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7838 DrawChooseTree(&volume_simple_current);
7839 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7840 DrawChooseTree(&volume_loops_current);
7841 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7842 DrawChooseTree(&volume_music_current);
7843 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7844 DrawChooseTree(&touch_control_current);
7845 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7846 DrawChooseTree(&move_distance_current);
7847 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7848 DrawChooseTree(&drop_distance_current);
7849 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7850 DrawChooseTree(&transparency_current);
7851 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7852 DrawChooseTree(&grid_size_current[0][0]);
7853 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7854 DrawChooseTree(&grid_size_current[0][1]);
7855 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7856 DrawChooseTree(&grid_size_current[1][0]);
7857 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7858 DrawChooseTree(&grid_size_current[1][1]);
7860 DrawSetupScreen_Generic();
7862 PlayMenuSoundsAndMusic();
7865 void RedrawSetupScreenAfterFullscreenToggle()
7867 if (setup_mode == SETUP_MODE_GRAPHICS ||
7868 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7870 // update list selection from "setup.window_scaling_percent"
7871 execSetupGraphics_setWindowSizes(TRUE);
7877 void RedrawSetupScreenAfterScreenRotation(int nr)
7881 if (setup_mode == SETUP_MODE_TOUCH)
7883 // update virtual button settings (depending on screen orientation)
7886 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
7888 // save already configured virtual buttons
7889 for (x = 0; x < MAX_GRID_XSIZE; x++)
7890 for (y = 0; y < MAX_GRID_YSIZE; y++)
7891 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7895 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7897 if (setup_mode == SETUP_MODE_INPUT)
7898 HandleSetupScreen_Input(mx, my, dx, dy, button);
7899 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7900 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7901 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7902 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7903 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7904 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7905 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7906 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7907 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7908 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7909 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7910 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7911 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7912 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7913 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7914 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7915 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7916 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7917 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7918 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7919 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7920 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7921 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7922 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7923 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7924 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7925 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7926 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7927 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7928 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7929 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7930 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
7931 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7932 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
7933 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7934 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
7935 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7936 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
7937 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7938 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
7940 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7943 void HandleGameActions()
7945 if (game.restart_game_message != NULL)
7946 RequestRestartGame(game.restart_game_message);
7948 if (game_status != GAME_MODE_PLAYING)
7951 GameActions(); /* main game loop */
7953 if (tape.auto_play && !tape.playing)
7954 AutoPlayTape(); /* continue automatically playing next tape */
7958 /* ---------- new screen button stuff -------------------------------------- */
7960 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7964 case SCREEN_CTRL_ID_PREV_LEVEL:
7965 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7966 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7969 case SCREEN_CTRL_ID_NEXT_LEVEL:
7970 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7971 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7974 case SCREEN_CTRL_ID_PREV_PLAYER:
7975 *x = mSX + TILEX * 10;
7976 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7979 case SCREEN_CTRL_ID_NEXT_PLAYER:
7980 *x = mSX + TILEX * 12;
7981 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7984 case SCREEN_CTRL_ID_INSERT_SOLUTION:
7985 *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x);
7986 *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y);
7989 case SCREEN_CTRL_ID_PLAY_SOLUTION:
7990 *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x);
7991 *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y);
7995 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
8001 int gfx_unpressed, gfx_pressed;
8002 void (*get_gadget_position)(int *, int *, int);
8006 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8009 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8010 getScreenMenuButtonPos,
8011 SCREEN_CTRL_ID_PREV_LEVEL,
8016 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8017 getScreenMenuButtonPos,
8018 SCREEN_CTRL_ID_NEXT_LEVEL,
8023 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8024 getScreenMenuButtonPos,
8025 SCREEN_CTRL_ID_PREV_PLAYER,
8030 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8031 getScreenMenuButtonPos,
8032 SCREEN_CTRL_ID_NEXT_PLAYER,
8037 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8038 getScreenMenuButtonPos,
8039 SCREEN_CTRL_ID_INSERT_SOLUTION,
8040 SCREEN_MASK_MAIN_HAS_SOLUTION,
8041 "insert solution tape"
8044 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8045 getScreenMenuButtonPos,
8046 SCREEN_CTRL_ID_PLAY_SOLUTION,
8047 SCREEN_MASK_MAIN_HAS_SOLUTION,
8048 "play solution tape"
8054 int gfx_unpressed, gfx_pressed;
8058 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8061 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8062 -1, -1, /* these values are not constant, but can change at runtime */
8063 SCREEN_CTRL_ID_SCROLL_UP,
8067 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8068 -1, -1, /* these values are not constant, but can change at runtime */
8069 SCREEN_CTRL_ID_SCROLL_DOWN,
8076 int gfx_unpressed, gfx_pressed;
8082 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8085 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8086 -1, -1, /* these values are not constant, but can change at runtime */
8087 -1, -1, /* these values are not constant, but can change at runtime */
8088 GD_TYPE_SCROLLBAR_VERTICAL,
8089 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8090 "scroll level series vertically"
8094 static void CreateScreenMenubuttons()
8096 struct GadgetInfo *gi;
8097 unsigned int event_mask;
8100 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8102 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8103 int gfx_unpressed, gfx_pressed;
8104 int x, y, width, height;
8105 int gd_x1, gd_x2, gd_y1, gd_y2;
8106 int id = menubutton_info[i].gadget_id;
8108 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8109 event_mask = GD_EVENT_RELEASED;
8111 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8113 menubutton_info[i].get_gadget_position(&x, &y, id);
8115 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8117 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8118 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8122 width = SC_MENUBUTTON_XSIZE;
8123 height = SC_MENUBUTTON_YSIZE;
8126 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8127 gfx_pressed = menubutton_info[i].gfx_pressed;
8128 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8129 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8130 gd_x1 = graphic_info[gfx_unpressed].src_x;
8131 gd_y1 = graphic_info[gfx_unpressed].src_y;
8132 gd_x2 = graphic_info[gfx_pressed].src_x;
8133 gd_y2 = graphic_info[gfx_pressed].src_y;
8135 gi = CreateGadget(GDI_CUSTOM_ID, id,
8136 GDI_CUSTOM_TYPE_ID, i,
8137 GDI_IMAGE_ID, gfx_unpressed,
8138 GDI_INFO_TEXT, menubutton_info[i].infotext,
8143 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8144 GDI_STATE, GD_BUTTON_UNPRESSED,
8145 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8146 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8147 GDI_DIRECT_DRAW, FALSE,
8148 GDI_EVENT_MASK, event_mask,
8149 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8153 Error(ERR_EXIT, "cannot create gadget");
8155 screen_gadget[id] = gi;
8159 static void CreateScreenScrollbuttons()
8161 struct GadgetInfo *gi;
8162 unsigned int event_mask;
8165 /* these values are not constant, but can change at runtime */
8166 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8167 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8168 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8169 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8171 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8173 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8174 int gfx_unpressed, gfx_pressed;
8175 int x, y, width, height;
8176 int gd_x1, gd_x2, gd_y1, gd_y2;
8177 int id = scrollbutton_info[i].gadget_id;
8179 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8181 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8182 y = mSY + scrollbutton_info[i].y;
8183 width = SC_SCROLLBUTTON_XSIZE;
8184 height = SC_SCROLLBUTTON_YSIZE;
8186 /* correct scrollbar position if placed outside menu (playfield) area */
8187 if (x > SX + SC_SCROLL_UP_XPOS)
8188 x = SX + SC_SCROLL_UP_XPOS;
8190 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8191 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8192 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8194 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8195 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8196 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8197 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8198 gd_x1 = graphic_info[gfx_unpressed].src_x;
8199 gd_y1 = graphic_info[gfx_unpressed].src_y;
8200 gd_x2 = graphic_info[gfx_pressed].src_x;
8201 gd_y2 = graphic_info[gfx_pressed].src_y;
8203 gi = CreateGadget(GDI_CUSTOM_ID, id,
8204 GDI_CUSTOM_TYPE_ID, i,
8205 GDI_IMAGE_ID, gfx_unpressed,
8206 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8211 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8212 GDI_STATE, GD_BUTTON_UNPRESSED,
8213 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8214 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8215 GDI_DIRECT_DRAW, FALSE,
8216 GDI_EVENT_MASK, event_mask,
8217 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8221 Error(ERR_EXIT, "cannot create gadget");
8223 screen_gadget[id] = gi;
8227 static void CreateScreenScrollbars()
8231 /* these values are not constant, but can change at runtime */
8232 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8233 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8234 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8235 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8237 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8239 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8240 int gfx_unpressed, gfx_pressed;
8241 int x, y, width, height;
8242 int gd_x1, gd_x2, gd_y1, gd_y2;
8243 struct GadgetInfo *gi;
8244 int items_max, items_visible, item_position;
8245 unsigned int event_mask;
8246 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8247 int id = scrollbar_info[i].gadget_id;
8249 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8251 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8252 y = mSY + scrollbar_info[i].y;
8253 width = scrollbar_info[i].width;
8254 height = scrollbar_info[i].height;
8256 /* correct scrollbar position if placed outside menu (playfield) area */
8257 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8258 x = SX + SC_SCROLL_VERTICAL_XPOS;
8260 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8261 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8263 items_max = num_page_entries;
8264 items_visible = num_page_entries;
8267 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8268 gfx_pressed = scrollbar_info[i].gfx_pressed;
8269 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8270 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8271 gd_x1 = graphic_info[gfx_unpressed].src_x;
8272 gd_y1 = graphic_info[gfx_unpressed].src_y;
8273 gd_x2 = graphic_info[gfx_pressed].src_x;
8274 gd_y2 = graphic_info[gfx_pressed].src_y;
8276 gi = CreateGadget(GDI_CUSTOM_ID, id,
8277 GDI_CUSTOM_TYPE_ID, i,
8278 GDI_IMAGE_ID, gfx_unpressed,
8279 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8284 GDI_TYPE, scrollbar_info[i].type,
8285 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8286 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8287 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8288 GDI_WHEEL_AREA_X, SX,
8289 GDI_WHEEL_AREA_Y, SY,
8290 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8291 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8292 GDI_STATE, GD_BUTTON_UNPRESSED,
8293 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8294 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8295 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8296 GDI_DIRECT_DRAW, FALSE,
8297 GDI_EVENT_MASK, event_mask,
8298 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8302 Error(ERR_EXIT, "cannot create gadget");
8304 screen_gadget[id] = gi;
8308 void CreateScreenGadgets()
8310 CreateScreenMenubuttons();
8312 CreateScreenScrollbuttons();
8313 CreateScreenScrollbars();
8316 void FreeScreenGadgets()
8320 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8321 FreeGadget(screen_gadget[i]);
8324 void MapScreenMenuGadgets(int screen_mask)
8328 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8329 if (screen_mask & menubutton_info[i].screen_mask)
8330 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8333 void UnmapScreenMenuGadgets(int screen_mask)
8337 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8339 if (screen_mask & menubutton_info[i].screen_mask)
8341 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8343 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8344 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8345 screen_gadget[menubutton_info[i].gadget_id]->y,
8346 screen_gadget[menubutton_info[i].gadget_id]->width,
8347 screen_gadget[menubutton_info[i].gadget_id]->height);
8352 void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8355 MapScreenMenuGadgets(screen_mask);
8357 UnmapScreenMenuGadgets(screen_mask);
8360 void MapScreenGadgets(int num_entries)
8364 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8367 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8368 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8370 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8371 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8374 void MapScreenTreeGadgets(TreeInfo *ti)
8376 MapScreenGadgets(numTreeInfoInGroup(ti));
8379 static void HandleScreenGadgets(struct GadgetInfo *gi)
8381 int id = gi->custom_id;
8382 int button = gi->event.button;
8383 int step = (button == MB_LEFTBUTTON ? 1 :
8384 button == MB_MIDDLEBUTTON ? 5 :
8385 button == MB_RIGHTBUTTON ? 10 : 1);
8389 case SCREEN_CTRL_ID_PREV_LEVEL:
8390 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8393 case SCREEN_CTRL_ID_NEXT_LEVEL:
8394 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8397 case SCREEN_CTRL_ID_PREV_PLAYER:
8398 HandleSetupScreen_Input_Player(step, -1);
8401 case SCREEN_CTRL_ID_NEXT_PLAYER:
8402 HandleSetupScreen_Input_Player(step, +1);
8405 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8406 InsertSolutionTape();
8409 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8413 case SCREEN_CTRL_ID_SCROLL_UP:
8414 if (game_status == GAME_MODE_LEVELS)
8415 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8416 else if (game_status == GAME_MODE_LEVELNR)
8417 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8418 else if (game_status == GAME_MODE_SETUP)
8419 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8420 else if (game_status == GAME_MODE_INFO)
8421 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8424 case SCREEN_CTRL_ID_SCROLL_DOWN:
8425 if (game_status == GAME_MODE_LEVELS)
8426 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8427 else if (game_status == GAME_MODE_LEVELNR)
8428 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8429 else if (game_status == GAME_MODE_SETUP)
8430 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8431 else if (game_status == GAME_MODE_INFO)
8432 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8435 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8436 if (game_status == GAME_MODE_LEVELS)
8437 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8438 else if (game_status == GAME_MODE_LEVELNR)
8439 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8440 else if (game_status == GAME_MODE_SETUP)
8441 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8442 else if (game_status == GAME_MODE_INFO)
8443 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8451 void DumpScreenIdentifiers()
8455 Print("Active screen elements on current screen:\n");
8457 for (i = 0; main_controls[i].nr != -1; i++)
8459 struct MainControlInfo *mci = &main_controls[i];
8461 if (mci->button_graphic != -1)
8463 char *token = getTokenFromImageID(mci->button_graphic);
8465 Print("- '%s'\n", token);
8472 boolean DoScreenAction(int image_id)
8476 if (game_status != GAME_MODE_MAIN)
8479 for (i = 0; main_controls[i].nr != -1; i++)
8481 struct MainControlInfo *mci = &main_controls[i];
8482 struct MenuPosInfo *pos = mci->pos_button;
8484 if (mci->button_graphic == image_id)
8486 int x = mSX + pos->x;
8487 int y = mSY + pos->y;
8489 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);