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 = (!options.network && 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 /* needed if last screen (level choice) changed graphics, sounds or music */
1595 ReloadCustomArtwork(0);
1597 if (CheckTitleScreen(levelset_has_changed))
1599 SetGameStatus(GAME_MODE_TITLE);
1606 if (redraw_mask & REDRAW_ALL)
1607 fade_mask = REDRAW_ALL;
1609 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1610 fade_mask = REDRAW_ALL;
1614 /* needed if different viewport properties defined for menues */
1615 ChangeViewportPropertiesIfNeeded();
1617 SetDrawtoField(DRAW_TO_BACKBUFFER);
1619 /* level_nr may have been set to value over handicap with level editor */
1620 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1621 level_nr = leveldir_current->handicap_level;
1623 LoadLevel(level_nr);
1624 LoadScore(level_nr);
1626 SaveLevelSetup_SeriesInfo();
1628 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1629 SetDrawDeactivationMask(REDRAW_NONE);
1630 SetDrawBackgroundMask(REDRAW_FIELD);
1632 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1635 if (fade_mask == REDRAW_ALL)
1636 RedrawGlobalBorder();
1641 InitializeMainControls();
1643 DrawCursorAndText_Main(-1, FALSE, FALSE);
1644 DrawPreviewLevelInitial();
1646 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1649 if (TAPE_IS_EMPTY(tape))
1651 DrawCompleteVideoDisplay();
1653 PlayMenuSoundsAndMusic();
1655 /* create gadgets for main menu screen */
1656 FreeScreenGadgets();
1657 CreateScreenGadgets();
1659 /* may be required if audio buttons shown on tape and changed in setup menu */
1661 CreateGameButtons();
1663 /* map gadgets for main menu screen */
1665 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1666 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1668 /* copy actual game door content to door double buffer for OpenDoor() */
1669 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1670 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1672 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1674 DrawMaskedBorder(fade_mask);
1679 /* update screen area with special editor door */
1680 redraw_mask |= REDRAW_ALL;
1683 SetMouseCursor(CURSOR_DEFAULT);
1685 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1688 static void gotoTopLevelDir()
1690 /* move upwards until inside (but not above) top level directory */
1691 while (leveldir_current->node_parent &&
1692 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1694 /* write a "path" into level tree for easy navigation to last level */
1695 if (leveldir_current->node_parent->node_group->cl_first == -1)
1697 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1698 int leveldir_pos = posTreeInfo(leveldir_current);
1699 int num_page_entries;
1700 int cl_first, cl_cursor;
1702 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1703 num_page_entries = num_leveldirs;
1705 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1707 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1708 cl_cursor = leveldir_pos - cl_first;
1710 leveldir_current->node_parent->node_group->cl_first = cl_first;
1711 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1714 leveldir_current = leveldir_current->node_parent;
1718 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1720 static unsigned int title_delay = 0;
1721 static int title_screen_nr = 0;
1722 static int last_sound = -1, last_music = -1;
1723 boolean return_to_main_menu = FALSE;
1724 struct TitleControlInfo *tci;
1727 if (button == MB_MENU_INITIALIZE)
1730 title_screen_nr = 0;
1731 tci = &title_controls[title_screen_nr];
1733 SetAnimStatus(getTitleAnimMode(tci));
1735 last_sound = SND_UNDEFINED;
1736 last_music = MUS_UNDEFINED;
1738 if (num_title_screens != 0)
1740 FadeSetEnterScreen();
1742 /* use individual title fading instead of global "enter screen" fading */
1743 fading = getTitleFading(tci);
1746 if (game_status_last_screen == GAME_MODE_INFO)
1748 if (num_title_screens == 0)
1750 /* switch game mode from title screen mode back to info screen mode */
1751 SetGameStatus(GAME_MODE_INFO);
1753 /* store that last screen was info screen, not main menu screen */
1754 game_status_last_screen = GAME_MODE_INFO;
1756 DrawInfoScreen_NotAvailable("Title screen information:",
1757 "No title screen for this level set.");
1761 FadeMenuSoundsAndMusic();
1764 FadeOut(REDRAW_ALL);
1766 /* title screens may have different window size */
1767 ChangeViewportPropertiesIfNeeded();
1769 /* only required to update logic for redrawing global border */
1773 DrawTitleScreenImage(tci->local_nr, tci->initial);
1775 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1777 sound = getTitleSound(tci);
1778 music = getTitleMusic(tci);
1780 if (sound != last_sound)
1781 PlayMenuSoundExt(sound);
1782 if (music != last_music)
1783 PlayMenuMusicExt(music);
1788 SetMouseCursor(CURSOR_NONE);
1792 DelayReached(&title_delay, 0); /* reset delay counter */
1797 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1798 button = MB_MENU_CHOICE;
1800 if (button == MB_MENU_LEAVE)
1802 return_to_main_menu = TRUE;
1804 else if (button == MB_MENU_CHOICE)
1806 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1808 SetGameStatus(GAME_MODE_INFO);
1810 info_mode = INFO_MODE_MAIN;
1819 if (title_screen_nr < num_title_screens)
1821 tci = &title_controls[title_screen_nr];
1823 SetAnimStatus(getTitleAnimMode(tci));
1825 sound = getTitleSound(tci);
1826 music = getTitleMusic(tci);
1828 if (last_sound != SND_UNDEFINED && sound != last_sound)
1829 FadeSound(last_sound);
1830 if (last_music != MUS_UNDEFINED && music != last_music)
1833 fading = getTitleFading(tci);
1835 FadeOut(REDRAW_ALL);
1838 DrawTitleScreenImage(tci->local_nr, tci->initial);
1840 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1842 sound = getTitleSound(tci);
1843 music = getTitleMusic(tci);
1845 if (sound != last_sound)
1846 PlayMenuSoundExt(sound);
1847 if (music != last_music)
1848 PlayMenuMusicExt(music);
1855 DelayReached(&title_delay, 0); /* reset delay counter */
1859 FadeMenuSoundsAndMusic();
1861 return_to_main_menu = TRUE;
1865 if (return_to_main_menu)
1867 SetMouseCursor(CURSOR_DEFAULT);
1869 /* force full menu screen redraw after displaying title screens */
1870 redraw_mask = REDRAW_ALL;
1872 if (game_status_last_screen == GAME_MODE_INFO)
1874 SetGameStatus(GAME_MODE_INFO);
1876 info_mode = INFO_MODE_MAIN;
1880 else /* default: return to main menu */
1882 SetGameStatus(GAME_MODE_MAIN);
1889 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1891 int old_level_nr = level_nr;
1894 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1895 new_level_nr = selected_level_nr;
1897 new_level_nr = old_level_nr + step * direction;
1899 if (new_level_nr < leveldir_current->first_level)
1900 new_level_nr = leveldir_current->first_level;
1901 if (new_level_nr > leveldir_current->last_level)
1902 new_level_nr = leveldir_current->last_level;
1904 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1906 /* skipping levels is only allowed when trying to skip single level */
1907 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1908 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1910 leveldir_current->handicap_level++;
1911 SaveLevelSetup_SeriesInfo();
1914 new_level_nr = leveldir_current->handicap_level;
1917 if (new_level_nr != old_level_nr)
1919 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1921 PlaySound(SND_MENU_ITEM_SELECTING);
1923 level_nr = new_level_nr;
1925 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1926 int2str(level_nr, menu.main.text.level_number.size),
1927 mci->pos_text->font);
1929 LoadLevel(level_nr);
1930 DrawPreviewLevelInitial();
1934 DrawCompleteVideoDisplay();
1936 SaveLevelSetup_SeriesInfo();
1938 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1940 /* needed because DrawPreviewLevelInitial() takes some time */
1942 /* SyncDisplay(); */
1946 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1948 static int choice = MAIN_CONTROL_GAME;
1949 static boolean button_pressed_last = FALSE;
1950 boolean button_pressed = FALSE;
1954 if (button == MB_MENU_INITIALIZE)
1956 DrawCursorAndText_Main(choice, TRUE, FALSE);
1961 if (mx || my) /* mouse input */
1965 for (i = 0; main_controls[i].nr != -1; i++)
1967 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1968 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1969 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1971 pos = main_controls[i].nr;
1977 /* check if level preview was clicked */
1978 if (insidePreviewRect(&preview, mx - SX, my - SY))
1979 pos = MAIN_CONTROL_GAME;
1981 // handle pressed/unpressed state for active/inactive menu buttons
1982 // (if pos != -1, "i" contains index position corresponding to "pos")
1984 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1985 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1986 button_pressed = TRUE;
1988 if (button_pressed != button_pressed_last)
1990 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1993 PlaySound(SND_MENU_BUTTON_PRESSING);
1995 PlaySound(SND_MENU_BUTTON_RELEASING);
1998 else if (dx || dy) /* keyboard input */
2000 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2001 choice == MAIN_CONTROL_SETUP))
2002 button = MB_MENU_CHOICE;
2007 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2009 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2011 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2013 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2015 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2017 CloseDoor(DOOR_CLOSE_2);
2019 SetGameStatus(GAME_MODE_LEVELNR);
2021 DrawChooseLevelNr();
2023 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2029 PlaySound(SND_MENU_ITEM_ACTIVATING);
2031 DrawCursorAndText_Main(choice, FALSE, FALSE);
2032 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2038 if (choice != MAIN_CONTROL_INFO &&
2039 choice != MAIN_CONTROL_SETUP)
2040 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2045 PlaySound(SND_MENU_ITEM_SELECTING);
2047 if (pos == MAIN_CONTROL_NAME)
2049 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2051 HandleTypeName(strlen(setup.player_name), 0);
2053 else if (pos == MAIN_CONTROL_LEVELS)
2057 CloseDoor(DOOR_CLOSE_2);
2059 SetGameStatus(GAME_MODE_LEVELS);
2061 SaveLevelSetup_LastSeries();
2062 SaveLevelSetup_SeriesInfo();
2064 if (setup.internal.choose_from_top_leveldir)
2067 DrawChooseLevelSet();
2070 else if (pos == MAIN_CONTROL_SCORES)
2072 CloseDoor(DOOR_CLOSE_2);
2074 SetGameStatus(GAME_MODE_SCORES);
2078 else if (pos == MAIN_CONTROL_EDITOR)
2080 if (leveldir_current->readonly &&
2081 !strEqual(setup.player_name, "Artsoft"))
2082 Request("This level is read only!", REQ_CONFIRM);
2084 CloseDoor(DOOR_CLOSE_2);
2086 SetGameStatus(GAME_MODE_EDITOR);
2088 FadeSetEnterScreen();
2092 else if (pos == MAIN_CONTROL_INFO)
2094 CloseDoor(DOOR_CLOSE_2);
2096 SetGameStatus(GAME_MODE_INFO);
2098 info_mode = INFO_MODE_MAIN;
2102 else if (pos == MAIN_CONTROL_GAME)
2104 StartGameActions(options.network, setup.autorecord, level.random_seed);
2106 else if (pos == MAIN_CONTROL_SETUP)
2108 CloseDoor(DOOR_CLOSE_2);
2110 SetGameStatus(GAME_MODE_SETUP);
2112 setup_mode = SETUP_MODE_MAIN;
2116 else if (pos == MAIN_CONTROL_QUIT)
2118 SaveLevelSetup_LastSeries();
2119 SaveLevelSetup_SeriesInfo();
2121 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2122 SetGameStatus(GAME_MODE_QUIT);
2127 button_pressed_last = button_pressed;
2131 /* ========================================================================= */
2132 /* info screen functions */
2133 /* ========================================================================= */
2135 static struct TokenInfo *info_info;
2136 static int num_info_info; /* number of info entries shown on screen */
2137 static int max_info_info; /* total number of info entries in list */
2139 static void execInfoTitleScreen()
2141 info_mode = INFO_MODE_TITLE;
2146 static void execInfoElements()
2148 info_mode = INFO_MODE_ELEMENTS;
2153 static void execInfoMusic()
2155 info_mode = INFO_MODE_MUSIC;
2160 static void execInfoCredits()
2162 info_mode = INFO_MODE_CREDITS;
2167 static void execInfoProgram()
2169 info_mode = INFO_MODE_PROGRAM;
2174 static void execInfoVersion()
2176 info_mode = INFO_MODE_VERSION;
2181 static void execInfoLevelSet()
2183 info_mode = INFO_MODE_LEVELSET;
2188 static void execExitInfo()
2190 SetGameStatus(GAME_MODE_MAIN);
2195 static struct TokenInfo info_info_main[] =
2197 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2198 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2199 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2200 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2201 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2202 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2203 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2204 { TYPE_EMPTY, NULL, "" },
2205 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2210 static int getMenuTextFont(int type)
2212 if (type & (TYPE_SWITCH |
2225 static struct TokenInfo *setup_info;
2226 static struct TokenInfo setup_info_input[];
2228 static struct TokenInfo *menu_info;
2230 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2231 int screen_pos, int menu_info_pos_raw,
2234 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2235 struct TokenInfo *ti = &token_info[pos];
2236 int xpos = MENU_SCREEN_START_XPOS;
2237 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2238 int font_nr = getMenuTextFont(ti->type);
2240 if (setup_mode == SETUP_MODE_INPUT)
2241 font_nr = FONT_MENU_1;
2244 font_nr = FONT_ACTIVE(font_nr);
2246 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2248 if (ti->type & ~TYPE_SKIP_ENTRY)
2249 drawCursor(screen_pos, active);
2252 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2255 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2258 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2261 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2264 static char *window_size_text;
2265 static char *scaling_type_text;
2267 static void drawSetupValue(int, int);
2269 static void drawMenuInfoList(int first_entry, int num_page_entries,
2270 int max_page_entries)
2274 if (first_entry + num_page_entries > max_page_entries)
2277 clearMenuListArea();
2279 for (i = 0; i < num_page_entries; i++)
2281 int menu_info_pos = first_entry + i;
2282 struct TokenInfo *si = &menu_info[menu_info_pos];
2283 void *value_ptr = si->value;
2285 /* set some entries to "unchangeable" according to other variables */
2286 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2287 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2288 (value_ptr == &setup.sound_music && !audio.music_available) ||
2289 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2290 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2291 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2292 si->type |= TYPE_GHOSTED;
2294 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2295 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2296 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2297 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2298 else if (si->type & ~TYPE_SKIP_ENTRY)
2299 initCursor(i, IMG_MENU_BUTTON);
2301 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2303 if (si->type & TYPE_VALUE &&
2304 menu_info == setup_info)
2305 drawSetupValue(i, menu_info_pos);
2309 static void DrawInfoScreen_Main()
2311 int fade_mask = REDRAW_FIELD;
2314 if (redraw_mask & REDRAW_ALL)
2315 fade_mask = REDRAW_ALL;
2317 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2318 fade_mask = REDRAW_ALL;
2321 FadeMenuSoundsAndMusic();
2323 FreeScreenGadgets();
2324 CreateScreenGadgets();
2326 /* (needed after displaying title screens which disable auto repeat) */
2327 KeyboardAutoRepeatOn();
2329 FadeSetLeaveScreen();
2333 /* needed if different viewport properties defined for info screen */
2334 ChangeViewportPropertiesIfNeeded();
2336 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2340 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2342 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2344 info_info = info_info_main;
2346 // determine maximal number of info entries that can be displayed on screen
2348 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2351 // determine maximal number of info entries available for menu of info screen
2353 for (i = 0; info_info[i].type != 0; i++)
2356 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2358 MapScreenGadgets(max_info_info);
2360 PlayMenuSoundsAndMusic();
2362 DrawMaskedBorder(fade_mask);
2367 static void changeSetupValue(int, int, int);
2369 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2370 int mode, int num_page_entries, int max_page_entries)
2372 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2373 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2374 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2375 int *num_page_entries_last = num_page_entries_all_last[game_status];
2376 int *choice_store = choice_stores[game_status];
2377 int *first_entry_store = first_entry_stores[game_status];
2378 int choice = choice_store[mode]; /* starts with 0 */
2379 int first_entry = first_entry_store[mode]; /* starts with 0 */
2381 int y = choice - first_entry;
2383 boolean position_set_by_scrollbar = (dx == 999);
2384 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2387 if (button == MB_MENU_INITIALIZE)
2389 // check if number of menu page entries has changed (may happen by change
2390 // of custom artwork definition value for 'list_size' for this menu screen)
2391 // (in this case, the last menu position most probably has to be corrected)
2392 if (num_page_entries != num_page_entries_last[mode])
2394 choice_store[mode] = first_entry_store[mode] = 0;
2396 choice = first_entry = 0;
2399 num_page_entries_last[mode] = num_page_entries;
2402 /* advance to first valid menu entry */
2403 while (choice < num_page_entries &&
2404 menu_info[choice].type & TYPE_SKIP_ENTRY)
2407 if (position_set_by_scrollbar)
2408 first_entry = first_entry_store[mode] = dy;
2410 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2411 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2413 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2415 if (choice < first_entry)
2417 choice = first_entry;
2419 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2422 else if (choice > first_entry + num_page_entries - 1)
2424 choice = first_entry + num_page_entries - 1;
2426 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2430 choice_store[mode] = choice;
2432 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2436 else if (button == MB_MENU_LEAVE)
2438 PlaySound(SND_MENU_ITEM_SELECTING);
2440 for (i = 0; i < max_page_entries; i++)
2442 if (menu_info[i].type & TYPE_LEAVE_MENU)
2444 void (*menu_callback_function)(void) = menu_info[i].value;
2448 menu_callback_function();
2450 break; /* absolutely needed because function changes 'menu_info'! */
2457 if (mx || my) /* mouse input */
2459 x = (mx - mSX) / 32;
2460 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2462 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2464 /* move cursor instead of scrolling when already at start/end of list */
2465 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2467 else if (dy == +1 * SCROLL_LINE &&
2468 first_entry + num_page_entries == max_page_entries)
2471 /* handle scrolling screen one line or page */
2473 y + dy > num_page_entries - 1)
2475 boolean redraw = FALSE;
2477 if (ABS(dy) == SCROLL_PAGE)
2478 step = num_page_entries - 1;
2480 if (dy < 0 && first_entry > 0)
2482 /* scroll page/line up */
2484 first_entry -= step;
2485 if (first_entry < 0)
2490 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2492 /* scroll page/line down */
2494 first_entry += step;
2495 if (first_entry + num_page_entries > max_page_entries)
2496 first_entry = MAX(0, max_page_entries - num_page_entries);
2503 choice += first_entry - first_entry_store[mode];
2505 if (choice < first_entry)
2507 choice = first_entry;
2509 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2512 else if (choice > first_entry + num_page_entries - 1)
2514 choice = first_entry + num_page_entries - 1;
2516 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2519 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2523 if (choice < first_entry ||
2524 choice > first_entry + num_page_entries - 1)
2525 first_entry += SIGN(dy);
2528 first_entry_store[mode] = first_entry;
2529 choice_store[mode] = choice;
2531 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2533 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2535 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2536 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2544 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2546 if (menu_info[choice].type & menu_navigation_type ||
2547 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2548 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2549 menu_info[choice].type & TYPE_PLAYER)
2550 button = MB_MENU_CHOICE;
2555 /* jump to next non-empty menu entry (up or down) */
2556 while (first_entry + y > 0 &&
2557 first_entry + y < max_page_entries - 1 &&
2558 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2561 if (!IN_VIS_MENU(x, y))
2563 choice += y - y_old;
2565 if (choice < first_entry)
2566 first_entry = choice;
2567 else if (choice > first_entry + num_page_entries - 1)
2568 first_entry = choice - num_page_entries + 1;
2570 if (first_entry >= 0 &&
2571 first_entry + num_page_entries <= max_page_entries)
2573 first_entry_store[mode] = first_entry;
2575 if (choice < first_entry)
2576 choice = first_entry;
2577 else if (choice > first_entry + num_page_entries - 1)
2578 choice = first_entry + num_page_entries - 1;
2580 choice_store[mode] = choice;
2582 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2584 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2586 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2587 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2594 if (!anyScrollbarGadgetActive() &&
2595 IN_VIS_MENU(x, y) &&
2596 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2597 y >= 0 && y < num_page_entries)
2601 if (first_entry + y != choice &&
2602 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2604 PlaySound(SND_MENU_ITEM_ACTIVATING);
2606 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2607 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2609 choice = choice_store[mode] = first_entry + y;
2613 PlaySound(SND_MENU_ITEM_SELECTING);
2615 for (i = 0; menu_info[i].type != 0; i++)
2617 if (menu_info[i].type & TYPE_LEAVE_MENU)
2619 void (*menu_callback_function)(void) = menu_info[i].value;
2623 menu_callback_function();
2625 /* absolutely needed because function changes 'menu_info'! */
2633 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2635 PlaySound(SND_MENU_ITEM_SELECTING);
2637 /* when selecting key headline, execute function for key value change */
2638 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2639 menu_info[first_entry + y + 1].type & TYPE_KEY)
2642 /* when selecting string value, execute function for list selection */
2643 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2644 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2647 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2649 void (*menu_callback_function)(void) =
2650 menu_info[first_entry + y].value;
2652 FadeSetFromType(menu_info[first_entry + y].type);
2654 menu_callback_function();
2656 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2657 menu_info == setup_info)
2659 changeSetupValue(y, first_entry + y, dx);
2665 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2667 menu_info = info_info;
2669 HandleMenuScreen(mx, my, dx, dy, button,
2670 info_mode, num_info_info, max_info_info);
2673 static int getMenuFontSpacing(int spacing_height, int font_nr)
2675 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2677 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2681 static int getMenuTextSpacing(int spacing_height, int font_nr)
2683 return (getMenuFontSpacing(spacing_height, font_nr) +
2684 EXTRA_SPACING(game_status));
2687 static int getMenuTextStep(int spacing_height, int font_nr)
2689 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2692 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2694 int font_title = MENU_INFO_FONT_TITLE;
2695 int font_error = FONT_TEXT_2;
2696 int font_foot = MENU_INFO_FONT_FOOT;
2697 int spacing_title = menu.headline1_spacing_info[info_mode];
2698 int ystep_title = getMenuTextStep(spacing_title, font_title);
2699 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2700 int ystart2 = ystart1 + ystep_title;
2701 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2703 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2705 FadeOut(REDRAW_FIELD);
2710 DrawTextSCentered(ystart1, font_title, text_title);
2711 DrawTextSCentered(ystart2, font_error, text_error);
2713 DrawTextSCentered(ybottom, font_foot,
2714 "Press any key or button for info menu");
2716 FadeIn(REDRAW_FIELD);
2719 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2721 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2722 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2723 int font_title = MENU_INFO_FONT_TITLE;
2724 int font_foot = MENU_INFO_FONT_FOOT;
2725 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2726 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2727 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2728 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2729 int ystep = MENU_SCREEN_INFO_YSTEP;
2730 int element, action, direction;
2738 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2739 infoscreen_step[i] = infoscreen_frame[i] = 0;
2744 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2746 DrawTextSCentered(ybottom, font_foot,
2747 "Press any key or button for next page");
2753 while (helpanim_info[j].element != HELPANIM_LIST_END)
2755 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2760 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2769 j += infoscreen_step[i - start];
2771 element = helpanim_info[j].element;
2772 action = helpanim_info[j].action;
2773 direction = helpanim_info[j].direction;
2776 element = EL_UNKNOWN;
2778 if (action != -1 && direction != -1)
2779 graphic = el_act_dir2img(element, action, direction);
2780 else if (action != -1)
2781 graphic = el_act2img(element, action);
2782 else if (direction != -1)
2783 graphic = el_dir2img(element, direction);
2785 graphic = el2img(element);
2787 delay = helpanim_info[j++].delay;
2792 if (infoscreen_frame[i - start] == 0)
2795 infoscreen_frame[i - start] = delay - 1;
2799 sync_frame = delay - infoscreen_frame[i - start];
2800 infoscreen_frame[i - start]--;
2803 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2805 if (!infoscreen_frame[i - start])
2806 infoscreen_step[i - start] = 0;
2810 if (!infoscreen_frame[i - start])
2811 infoscreen_step[i - start]++;
2812 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2818 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2820 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2821 graphic, sync_frame, USE_MASKING);
2824 DrawInfoScreen_HelpText(element, action, direction, i - start);
2829 redraw_mask |= REDRAW_FIELD;
2834 static char *getHelpText(int element, int action, int direction)
2836 char token[MAX_LINE_LEN];
2838 strcpy(token, element_info[element].token_name);
2841 strcat(token, element_action_info[action].suffix);
2843 if (direction != -1)
2844 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2846 return getHashEntry(helptext_info, token);
2849 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2851 int font_nr = FONT_INFO_ELEMENTS;
2852 int font_width = getFontWidth(font_nr);
2853 int font_height = getFontHeight(font_nr);
2854 int yoffset = (TILEX - 2 * font_height) / 2;
2855 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2856 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2857 int ystep = TILEY + 4;
2858 int pad_left = xstart - SX;
2859 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2860 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2861 int max_lines_per_text = 2;
2864 if (action != -1 && direction != -1) /* element.action.direction */
2865 text = getHelpText(element, action, direction);
2867 if (text == NULL && action != -1) /* element.action */
2868 text = getHelpText(element, action, -1);
2870 if (text == NULL && direction != -1) /* element.direction */
2871 text = getHelpText(element, -1, direction);
2873 if (text == NULL) /* base element */
2874 text = getHelpText(element, -1, -1);
2876 if (text == NULL) /* not found */
2877 text = "No description available";
2879 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2880 ystart += getFontHeight(font_nr) / 2;
2882 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2883 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2884 TRUE, FALSE, FALSE);
2887 void DrawInfoScreen_TitleScreen()
2889 SetGameStatus(GAME_MODE_TITLE);
2894 void HandleInfoScreen_TitleScreen(int button)
2896 HandleTitleScreen(0, 0, 0, 0, button);
2899 void DrawInfoScreen_Elements()
2901 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2903 FadeOut(REDRAW_FIELD);
2908 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2910 FadeIn(REDRAW_FIELD);
2913 void HandleInfoScreen_Elements(int button)
2915 static unsigned int info_delay = 0;
2916 static int num_anims;
2917 static int num_pages;
2919 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2922 if (button == MB_MENU_INITIALIZE)
2924 boolean new_element = TRUE;
2928 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2930 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2932 else if (new_element)
2935 new_element = FALSE;
2939 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2943 if (button == MB_MENU_LEAVE)
2945 PlaySound(SND_MENU_ITEM_SELECTING);
2947 info_mode = INFO_MODE_MAIN;
2952 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2954 if (button != MB_MENU_INITIALIZE)
2956 PlaySound(SND_MENU_ITEM_SELECTING);
2961 if (page >= num_pages)
2963 FadeMenuSoundsAndMusic();
2965 info_mode = INFO_MODE_MAIN;
2972 FadeSetNextScreen();
2974 if (button != MB_MENU_INITIALIZE)
2975 FadeOut(REDRAW_FIELD);
2977 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2979 if (button != MB_MENU_INITIALIZE)
2980 FadeIn(REDRAW_FIELD);
2984 if (DelayReached(&info_delay, GameFrameDelay))
2985 if (page < num_pages)
2986 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2988 PlayMenuSoundIfLoop();
2992 void DrawInfoScreen_Music()
2994 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2996 FadeOut(REDRAW_FIELD);
3003 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3005 FadeIn(REDRAW_FIELD);
3008 void HandleInfoScreen_Music(int button)
3010 static struct MusicFileInfo *list = NULL;
3011 int font_title = MENU_INFO_FONT_TITLE;
3012 int font_head = MENU_INFO_FONT_HEAD;
3013 int font_text = MENU_INFO_FONT_TEXT;
3014 int font_foot = MENU_INFO_FONT_FOOT;
3015 int spacing_title = menu.headline1_spacing_info[info_mode];
3016 int spacing_head = menu.headline2_spacing_info[info_mode];
3017 int ystep_title = getMenuTextStep(spacing_title, font_title);
3018 int ystep_head = getMenuTextStep(spacing_head, font_head);
3019 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3020 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3022 if (button == MB_MENU_INITIALIZE)
3024 list = music_file_info;
3028 FadeMenuSoundsAndMusic();
3033 DrawTextSCentered(ystart, font_title,
3034 "No music info for this level set.");
3036 DrawTextSCentered(ybottom, font_foot,
3037 "Press any key or button for info menu");
3043 if (button == MB_MENU_LEAVE)
3045 PlaySound(SND_MENU_ITEM_SELECTING);
3047 FadeMenuSoundsAndMusic();
3049 info_mode = INFO_MODE_MAIN;
3054 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3056 if (button != MB_MENU_INITIALIZE)
3058 PlaySound(SND_MENU_ITEM_SELECTING);
3066 FadeMenuSoundsAndMusic();
3068 info_mode = INFO_MODE_MAIN;
3074 FadeMenuSoundsAndMusic();
3076 if (list != music_file_info)
3077 FadeSetNextScreen();
3079 if (button != MB_MENU_INITIALIZE)
3080 FadeOut(REDRAW_FIELD);
3087 int sound = list->music;
3089 if (sound_info[sound].loop)
3090 PlaySoundLoop(sound);
3094 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3098 PlayMusic(list->music);
3100 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3103 ystart += ystep_title;
3105 if (!strEqual(list->title, UNKNOWN_NAME))
3107 if (!strEqual(list->title_header, UNKNOWN_NAME))
3109 DrawTextSCentered(ystart, font_head, list->title_header);
3110 ystart += ystep_head;
3113 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3114 ystart += ystep_head;
3117 if (!strEqual(list->artist, UNKNOWN_NAME))
3119 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3120 DrawTextSCentered(ystart, font_head, list->artist_header);
3122 DrawTextSCentered(ystart, font_head, "by");
3124 ystart += ystep_head;
3126 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3127 ystart += ystep_head;
3130 if (!strEqual(list->album, UNKNOWN_NAME))
3132 if (!strEqual(list->album_header, UNKNOWN_NAME))
3133 DrawTextSCentered(ystart, font_head, list->album_header);
3135 DrawTextSCentered(ystart, font_head, "from the album");
3137 ystart += ystep_head;
3139 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3140 ystart += ystep_head;
3143 if (!strEqual(list->year, UNKNOWN_NAME))
3145 if (!strEqual(list->year_header, UNKNOWN_NAME))
3146 DrawTextSCentered(ystart, font_head, list->year_header);
3148 DrawTextSCentered(ystart, font_head, "from the year");
3150 ystart += ystep_head;
3152 DrawTextFCentered(ystart, font_text, "%s", list->year);
3153 ystart += ystep_head;
3156 DrawTextSCentered(ybottom, FONT_TEXT_4,
3157 "Press any key or button for next page");
3159 if (button != MB_MENU_INITIALIZE)
3160 FadeIn(REDRAW_FIELD);
3163 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3164 PlaySoundLoop(list->music);
3167 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3169 int font_title = MENU_INFO_FONT_TITLE;
3170 int font_head = MENU_INFO_FONT_HEAD;
3171 int font_text = MENU_INFO_FONT_TEXT;
3172 int font_foot = MENU_INFO_FONT_FOOT;
3173 int spacing_title = menu.headline1_spacing_info[info_mode];
3174 int spacing_head = menu.headline2_spacing_info[info_mode];
3175 int spacing_para = menu.paragraph_spacing_info[info_mode];
3176 int spacing_line = menu.line_spacing_info[info_mode];
3177 int ystep_title = getMenuTextStep(spacing_title, font_title);
3178 int ystep_head = getMenuTextStep(spacing_head, font_head);
3179 int ystep_para = getMenuTextStep(spacing_para, font_text);
3180 int ystep_line = getMenuTextStep(spacing_line, font_text);
3181 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3182 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3187 DrawTextSCentered(ystart, font_title, "Credits:");
3188 ystart += ystep_title;
3192 DrawTextSCentered(ystart, font_head,
3193 "Special thanks to");
3194 ystart += ystep_head;
3195 DrawTextSCentered(ystart, font_text,
3197 ystart += ystep_head;
3198 DrawTextSCentered(ystart, font_head,
3200 ystart += ystep_head;
3201 DrawTextSCentered(ystart, font_text,
3202 "\"Boulder Dash\"");
3203 ystart += ystep_head;
3204 DrawTextSCentered(ystart, font_head,
3206 ystart += ystep_head;
3207 DrawTextSCentered(ystart, font_text,
3209 ystart += ystep_head;
3210 DrawTextSCentered(ystart, font_head,
3212 ystart += ystep_head;
3213 DrawTextSCentered(ystart, font_text,
3214 "First Star Software");
3216 else if (screen_nr == 1)
3218 DrawTextSCentered(ystart, font_head,
3219 "Special thanks to");
3220 ystart += ystep_head;
3221 DrawTextSCentered(ystart, font_text,
3222 "Klaus Heinz & Volker Wertich");
3223 ystart += ystep_head;
3224 DrawTextSCentered(ystart, font_head,
3226 ystart += ystep_head;
3227 DrawTextSCentered(ystart, font_text,
3228 "\"Emerald Mine\"");
3229 ystart += ystep_head;
3230 DrawTextSCentered(ystart, font_head,
3232 ystart += ystep_head;
3233 DrawTextSCentered(ystart, font_text,
3235 ystart += ystep_head;
3236 DrawTextSCentered(ystart, font_head,
3238 ystart += ystep_head;
3239 DrawTextSCentered(ystart, font_text,
3242 else if (screen_nr == 2)
3244 DrawTextSCentered(ystart, font_head,
3245 "Special thanks to");
3246 ystart += ystep_head;
3247 DrawTextSCentered(ystart, font_text,
3248 "Michael Stopp & Philip Jespersen");
3249 ystart += ystep_head;
3250 DrawTextSCentered(ystart, font_head,
3252 ystart += ystep_head;
3253 DrawTextSCentered(ystart, font_text,
3255 ystart += ystep_head;
3256 DrawTextSCentered(ystart, font_head,
3258 ystart += ystep_head;
3259 DrawTextSCentered(ystart, font_text,
3261 ystart += ystep_head;
3262 DrawTextSCentered(ystart, font_head,
3264 ystart += ystep_head;
3265 DrawTextSCentered(ystart, font_text,
3266 "Digital Integration");
3268 else if (screen_nr == 3)
3270 DrawTextSCentered(ystart, font_head,
3271 "Special thanks to");
3272 ystart += ystep_head;
3273 DrawTextSCentered(ystart, font_text,
3274 "Hiroyuki Imabayashi");
3275 ystart += ystep_head;
3276 DrawTextSCentered(ystart, font_head,
3278 ystart += ystep_head;
3279 DrawTextSCentered(ystart, font_text,
3281 ystart += ystep_head;
3282 DrawTextSCentered(ystart, font_head,
3284 ystart += ystep_head;
3285 DrawTextSCentered(ystart, font_text,
3287 ystart += ystep_head;
3288 DrawTextSCentered(ystart, font_head,
3290 ystart += ystep_head;
3291 DrawTextSCentered(ystart, font_text,
3294 else if (screen_nr == 4)
3296 DrawTextSCentered(ystart, font_head,
3297 "Special thanks to");
3298 ystart += ystep_head;
3299 DrawTextSCentered(ystart, font_text,
3301 ystart += ystep_head;
3302 DrawTextSCentered(ystart, font_head,
3304 ystart += ystep_head;
3305 DrawTextSCentered(ystart, font_text,
3306 "J\xfcrgen Bonhagen");
3307 ystart += ystep_head;
3308 DrawTextSCentered(ystart, font_head,
3309 "for the continuous creation");
3310 ystart += ystep_line;
3311 DrawTextSCentered(ystart, font_head,
3312 "of outstanding level sets");
3314 else if (screen_nr == 5)
3316 DrawTextSCentered(ystart, font_head,
3318 ystart += ystep_head;
3319 DrawTextSCentered(ystart, font_text,
3321 ystart += ystep_head;
3322 DrawTextSCentered(ystart, font_head,
3323 "for ideas and inspiration by");
3324 ystart += ystep_head;
3325 DrawTextSCentered(ystart, font_text,
3327 ystart += ystep_para;
3329 DrawTextSCentered(ystart, font_head,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_text,
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_head,
3336 "for ideas and inspiration by");
3337 ystart += ystep_head;
3338 DrawTextSCentered(ystart, font_text,
3341 else if (screen_nr == 6)
3343 DrawTextSCentered(ystart, font_head,
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_text,
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_head,
3350 "for the code base used for the");
3351 ystart += ystep_line;
3352 DrawTextSCentered(ystart, font_head,
3353 "native Emerald Mine engine");
3355 else if (screen_nr == 7)
3357 DrawTextSCentered(ystart, font_head,
3359 ystart += ystep_head;
3360 DrawTextSCentered(ystart, font_text,
3362 ystart += ystep_head;
3363 DrawTextSCentered(ystart, font_head,
3364 "for the initial DOS port");
3365 ystart += ystep_para;
3367 DrawTextSCentered(ystart, font_head,
3369 ystart += ystep_head;
3370 DrawTextSCentered(ystart, font_text,
3372 ystart += ystep_head;
3373 DrawTextSCentered(ystart, font_head,
3374 "for some additional toons");
3376 else if (screen_nr == 8)
3378 DrawTextSCentered(ystart, font_head,
3379 "And not to forget:");
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_head,
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_text,
3385 "All those who contributed");
3386 ystart += ystep_line;
3387 DrawTextSCentered(ystart, font_text,
3388 "levels to this game");
3389 ystart += ystep_line;
3390 DrawTextSCentered(ystart, font_text,
3394 DrawTextSCentered(ybottom, font_foot,
3395 "Press any key or button for next page");
3398 void DrawInfoScreen_Credits()
3400 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3402 FadeMenuSoundsAndMusic();
3404 FadeOut(REDRAW_FIELD);
3406 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3408 FadeIn(REDRAW_FIELD);
3411 void HandleInfoScreen_Credits(int button)
3413 static int screen_nr = 0;
3414 int num_screens = 9;
3416 if (button == MB_MENU_INITIALIZE)
3420 // DrawInfoScreen_CreditsScreen(screen_nr);
3423 if (button == MB_MENU_LEAVE)
3425 PlaySound(SND_MENU_ITEM_SELECTING);
3427 info_mode = INFO_MODE_MAIN;
3432 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3434 if (button != MB_MENU_INITIALIZE)
3436 PlaySound(SND_MENU_ITEM_SELECTING);
3441 if (screen_nr >= num_screens)
3443 FadeMenuSoundsAndMusic();
3445 info_mode = INFO_MODE_MAIN;
3452 FadeSetNextScreen();
3454 if (button != MB_MENU_INITIALIZE)
3455 FadeOut(REDRAW_FIELD);
3457 DrawInfoScreen_CreditsScreen(screen_nr);
3459 if (button != MB_MENU_INITIALIZE)
3460 FadeIn(REDRAW_FIELD);
3464 PlayMenuSoundIfLoop();
3468 void DrawInfoScreen_Program()
3470 int font_title = MENU_INFO_FONT_TITLE;
3471 int font_head = MENU_INFO_FONT_HEAD;
3472 int font_text = MENU_INFO_FONT_TEXT;
3473 int font_foot = MENU_INFO_FONT_FOOT;
3474 int spacing_title = menu.headline1_spacing_info[info_mode];
3475 int spacing_head = menu.headline2_spacing_info[info_mode];
3476 int spacing_para = menu.paragraph_spacing_info[info_mode];
3477 int spacing_line = menu.line_spacing_info[info_mode];
3478 int ystep_title = getMenuTextStep(spacing_title, font_title);
3479 int ystep_head = getMenuTextStep(spacing_head, font_head);
3480 int ystep_para = getMenuTextStep(spacing_para, font_text);
3481 int ystep_line = getMenuTextStep(spacing_line, font_text);
3482 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3483 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3485 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3487 FadeOut(REDRAW_FIELD);
3492 DrawTextSCentered(ystart, font_title, "Program Information:");
3493 ystart += ystep_title;
3495 DrawTextSCentered(ystart, font_head,
3496 "This game is Freeware!");
3497 ystart += ystep_head;
3498 DrawTextSCentered(ystart, font_head,
3499 "If you like it, send e-mail to:");
3500 ystart += ystep_head;
3501 DrawTextSCentered(ystart, font_text,
3502 setup.internal.program_email);
3503 ystart += ystep_para;
3505 DrawTextSCentered(ystart, font_head,
3506 "More information and levels:");
3507 ystart += ystep_head;
3508 DrawTextSCentered(ystart, font_text,
3509 setup.internal.program_website);
3510 ystart += ystep_para;
3512 DrawTextSCentered(ystart, font_head,
3513 "If you have created new levels,");
3514 ystart += ystep_line;
3515 DrawTextSCentered(ystart, font_head,
3516 "send them to me to include them!");
3517 ystart += ystep_head;
3518 DrawTextSCentered(ystart, font_head,
3521 DrawTextSCentered(ybottom, font_foot,
3522 "Press any key or button for info menu");
3524 FadeIn(REDRAW_FIELD);
3527 void HandleInfoScreen_Program(int button)
3529 if (button == MB_MENU_LEAVE)
3531 PlaySound(SND_MENU_ITEM_SELECTING);
3533 info_mode = INFO_MODE_MAIN;
3538 else if (button == MB_MENU_CHOICE)
3540 PlaySound(SND_MENU_ITEM_SELECTING);
3542 FadeMenuSoundsAndMusic();
3544 info_mode = INFO_MODE_MAIN;
3549 PlayMenuSoundIfLoop();
3553 void DrawInfoScreen_Version()
3555 int font_title = MENU_INFO_FONT_TITLE;
3556 int font_head = MENU_INFO_FONT_HEAD;
3557 int font_text = MENU_INFO_FONT_TEXT;
3558 int font_foot = MENU_INFO_FONT_FOOT;
3559 int spacing_title = menu.headline1_spacing_info[info_mode];
3560 int spacing_head = menu.headline2_spacing_info[info_mode];
3561 int spacing_para = menu.paragraph_spacing_info[info_mode];
3562 int spacing_line = menu.line_spacing_info[info_mode];
3563 int xstep = getFontWidth(font_text);
3564 int ystep_title = getMenuTextStep(spacing_title, font_title);
3565 int ystep_head = getMenuTextStep(spacing_head, font_head);
3566 int ystep_para = getMenuTextStep(spacing_para, font_text);
3567 int ystep_line = getMenuTextStep(spacing_line, font_text);
3568 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3569 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3570 int xstart1 = mSX - SX + 2 * xstep;
3571 int xstart2 = mSX - SX + 18 * xstep;
3572 int xstart3 = mSX - SX + 28 * xstep;
3573 SDL_version sdl_version_compiled;
3574 const SDL_version *sdl_version_linked;
3575 int driver_name_len = 10;
3576 #if defined(TARGET_SDL2)
3577 SDL_version sdl_version_linked_ext;
3578 const char *driver_name = NULL;
3580 char driver_name[driver_name_len];
3583 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3585 FadeOut(REDRAW_FIELD);
3590 DrawTextSCentered(ystart, font_title, "Version Information:");
3591 ystart += ystep_title;
3593 DrawTextF(xstart1, ystart, font_head, "Name");
3594 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3595 ystart += ystep_line;
3597 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3599 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3600 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3601 ystart += ystep_line;
3603 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3604 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3605 ystart += ystep_line;
3609 DrawTextF(xstart1, ystart, font_head, "Version");
3610 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3611 ystart += ystep_line;
3614 DrawTextF(xstart1, ystart, font_head, "Platform");
3615 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3616 ystart += ystep_line;
3618 DrawTextF(xstart1, ystart, font_head, "Target");
3619 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3620 ystart += ystep_line;
3622 DrawTextF(xstart1, ystart, font_head, "Source date");
3623 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3624 ystart += ystep_para;
3626 DrawTextF(xstart1, ystart, font_head, "Library");
3627 DrawTextF(xstart2, ystart, font_head, "compiled");
3628 DrawTextF(xstart3, ystart, font_head, "linked");
3629 ystart += ystep_head;
3631 SDL_VERSION(&sdl_version_compiled);
3632 #if defined(TARGET_SDL2)
3633 SDL_GetVersion(&sdl_version_linked_ext);
3634 sdl_version_linked = &sdl_version_linked_ext;
3636 sdl_version_linked = SDL_Linked_Version();
3639 DrawTextF(xstart1, ystart, font_text, "SDL");
3640 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3641 sdl_version_compiled.major,
3642 sdl_version_compiled.minor,
3643 sdl_version_compiled.patch);
3644 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3645 sdl_version_linked->major,
3646 sdl_version_linked->minor,
3647 sdl_version_linked->patch);
3648 ystart += ystep_line;
3650 SDL_IMAGE_VERSION(&sdl_version_compiled);
3651 sdl_version_linked = IMG_Linked_Version();
3653 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3654 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3655 sdl_version_compiled.major,
3656 sdl_version_compiled.minor,
3657 sdl_version_compiled.patch);
3658 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3659 sdl_version_linked->major,
3660 sdl_version_linked->minor,
3661 sdl_version_linked->patch);
3662 ystart += ystep_line;
3664 SDL_MIXER_VERSION(&sdl_version_compiled);
3665 sdl_version_linked = Mix_Linked_Version();
3667 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3668 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3669 sdl_version_compiled.major,
3670 sdl_version_compiled.minor,
3671 sdl_version_compiled.patch);
3672 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3673 sdl_version_linked->major,
3674 sdl_version_linked->minor,
3675 sdl_version_linked->patch);
3676 ystart += ystep_line;
3678 SDL_NET_VERSION(&sdl_version_compiled);
3679 sdl_version_linked = SDLNet_Linked_Version();
3681 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3682 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3683 sdl_version_compiled.major,
3684 sdl_version_compiled.minor,
3685 sdl_version_compiled.patch);
3686 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3687 sdl_version_linked->major,
3688 sdl_version_linked->minor,
3689 sdl_version_linked->patch);
3690 ystart += ystep_para;
3692 DrawTextF(xstart1, ystart, font_head, "Driver");
3693 DrawTextF(xstart2, ystart, font_head, "Requested");
3694 DrawTextF(xstart3, ystart, font_head, "Used");
3695 ystart += ystep_head;
3697 #if defined(TARGET_SDL2)
3698 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3700 SDL_VideoDriverName(driver_name, driver_name_len);
3703 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3704 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3705 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3706 ystart += ystep_line;
3708 #if defined(TARGET_SDL2)
3709 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3711 SDL_AudioDriverName(driver_name, driver_name_len);
3714 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3715 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3716 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3718 DrawTextSCentered(ybottom, font_foot,
3719 "Press any key or button for info menu");
3721 FadeIn(REDRAW_FIELD);
3724 void HandleInfoScreen_Version(int button)
3726 if (button == MB_MENU_LEAVE)
3728 PlaySound(SND_MENU_ITEM_SELECTING);
3730 info_mode = INFO_MODE_MAIN;
3735 else if (button == MB_MENU_CHOICE)
3737 PlaySound(SND_MENU_ITEM_SELECTING);
3739 FadeMenuSoundsAndMusic();
3741 info_mode = INFO_MODE_MAIN;
3746 PlayMenuSoundIfLoop();
3750 void DrawInfoScreen_LevelSet()
3752 struct TitleMessageInfo *tmi = &readme;
3753 char *filename = getLevelSetInfoFilename();
3754 char *title = "Level Set Information:";
3755 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3756 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3758 if (filename == NULL)
3760 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3765 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3767 FadeOut(REDRAW_FIELD);
3772 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3774 /* if x position set to "-1", automatically determine by playfield width */
3776 tmi->x = SXSIZE / 2;
3778 /* if y position set to "-1", use static default value */
3782 /* if width set to "-1", automatically determine by playfield width */
3783 if (tmi->width == -1)
3784 tmi->width = SXSIZE - 2 * TILEX;
3786 /* if height set to "-1", automatically determine by playfield height */
3787 if (tmi->height == -1)
3788 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3790 /* if chars set to "-1", automatically determine by text and font width */
3791 if (tmi->chars == -1)
3792 tmi->chars = tmi->width / getFontWidth(tmi->font);
3794 tmi->width = tmi->chars * getFontWidth(tmi->font);
3796 /* if lines set to "-1", automatically determine by text and font height */
3797 if (tmi->lines == -1)
3798 tmi->lines = tmi->height / getFontHeight(tmi->font);
3800 tmi->height = tmi->lines * getFontHeight(tmi->font);
3802 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3803 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3804 tmi->autowrap, tmi->centered, tmi->parse_comments);
3806 DrawTextSCentered(ybottom, FONT_TEXT_4,
3807 "Press any key or button for info menu");
3809 FadeIn(REDRAW_FIELD);
3812 void HandleInfoScreen_LevelSet(int button)
3814 if (button == MB_MENU_LEAVE)
3816 PlaySound(SND_MENU_ITEM_SELECTING);
3818 info_mode = INFO_MODE_MAIN;
3823 else if (button == MB_MENU_CHOICE)
3825 PlaySound(SND_MENU_ITEM_SELECTING);
3827 FadeMenuSoundsAndMusic();
3829 info_mode = INFO_MODE_MAIN;
3834 PlayMenuSoundIfLoop();
3838 static void DrawInfoScreen()
3840 if (info_mode == INFO_MODE_TITLE)
3841 DrawInfoScreen_TitleScreen();
3842 else if (info_mode == INFO_MODE_ELEMENTS)
3843 DrawInfoScreen_Elements();
3844 else if (info_mode == INFO_MODE_MUSIC)
3845 DrawInfoScreen_Music();
3846 else if (info_mode == INFO_MODE_CREDITS)
3847 DrawInfoScreen_Credits();
3848 else if (info_mode == INFO_MODE_PROGRAM)
3849 DrawInfoScreen_Program();
3850 else if (info_mode == INFO_MODE_VERSION)
3851 DrawInfoScreen_Version();
3852 else if (info_mode == INFO_MODE_LEVELSET)
3853 DrawInfoScreen_LevelSet();
3855 DrawInfoScreen_Main();
3857 if (info_mode != INFO_MODE_MAIN &&
3858 info_mode != INFO_MODE_TITLE &&
3859 info_mode != INFO_MODE_MUSIC)
3860 PlayMenuSoundsAndMusic();
3863 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3865 if (info_mode == INFO_MODE_TITLE)
3866 HandleInfoScreen_TitleScreen(button);
3867 else if (info_mode == INFO_MODE_ELEMENTS)
3868 HandleInfoScreen_Elements(button);
3869 else if (info_mode == INFO_MODE_MUSIC)
3870 HandleInfoScreen_Music(button);
3871 else if (info_mode == INFO_MODE_CREDITS)
3872 HandleInfoScreen_Credits(button);
3873 else if (info_mode == INFO_MODE_PROGRAM)
3874 HandleInfoScreen_Program(button);
3875 else if (info_mode == INFO_MODE_VERSION)
3876 HandleInfoScreen_Version(button);
3877 else if (info_mode == INFO_MODE_LEVELSET)
3878 HandleInfoScreen_LevelSet(button);
3880 HandleInfoScreen_Main(mx, my, dx, dy, button);
3884 /* ========================================================================= */
3885 /* type name functions */
3886 /* ========================================================================= */
3888 void HandleTypeName(int newxpos, Key key)
3890 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3891 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3892 struct TextPosInfo *pos = mci->pos_input;
3893 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3894 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3895 static int xpos = 0;
3896 int font_nr = pos->font;
3897 int font_active_nr = FONT_ACTIVE(font_nr);
3898 int font_width = getFontWidth(font_active_nr);
3899 char key_char = getValidConfigValueChar(getCharFromKey(key));
3900 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3901 boolean is_active = TRUE;
3903 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3907 strcpy(last_player_name, setup.player_name);
3911 StartTextInput(startx, starty, pos->width, pos->height);
3913 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3915 setup.player_name[xpos] = key_char;
3916 setup.player_name[xpos + 1] = 0;
3920 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3924 setup.player_name[xpos] = 0;
3926 else if (key == KSYM_Return && xpos > 0)
3932 SetGameStatus(GAME_MODE_MAIN);
3934 else if (key == KSYM_Escape)
3936 strcpy(setup.player_name, last_player_name);
3940 SetGameStatus(GAME_MODE_MAIN);
3945 pos->width = (strlen(setup.player_name) + 1) * font_width;
3946 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3948 DrawText(startx, starty, setup.player_name, font_active_nr);
3949 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3953 pos->width = strlen(setup.player_name) * font_width;
3954 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3956 DrawText(startx, starty, setup.player_name, font_nr);
3963 /* ========================================================================= */
3964 /* tree menu functions */
3965 /* ========================================================================= */
3967 static void DrawChooseTree(TreeInfo **ti_ptr)
3969 int fade_mask = REDRAW_FIELD;
3971 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3972 fade_mask = REDRAW_ALL;
3974 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3976 SetGameStatus(GAME_MODE_MAIN);
3985 FreeScreenGadgets();
3986 CreateScreenGadgets();
3990 /* needed if different viewport properties defined for choosing level (set) */
3991 ChangeViewportPropertiesIfNeeded();
3993 if (game_status == GAME_MODE_LEVELNR)
3994 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3995 else if (game_status == GAME_MODE_LEVELS)
3996 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4000 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4002 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4003 MapScreenTreeGadgets(*ti_ptr);
4005 DrawMaskedBorder(fade_mask);
4010 static void drawChooseTreeList(int first_entry, int num_page_entries,
4014 char *title_string = NULL;
4015 int yoffset_sets = MENU_TITLE1_YPOS;
4016 int yoffset_setup = 16;
4017 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4018 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4020 title_string = ti->infotext;
4022 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4024 clearMenuListArea();
4026 for (i = 0; i < num_page_entries; i++)
4028 TreeInfo *node, *node_first;
4029 int entry_pos = first_entry + i;
4030 int xpos = MENU_SCREEN_START_XPOS;
4031 int ypos = MENU_SCREEN_START_YPOS + i;
4032 int startx = mSX + xpos * 32;
4033 int starty = mSY + ypos * 32;
4034 int font_nr = FONT_TEXT_1;
4035 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4036 int startx_text = startx + font_xoffset;
4037 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4038 int text_size = startx_scrollbar - startx_text;
4039 int max_buffer_len = text_size / getFontWidth(font_nr);
4040 char buffer[max_buffer_len + 1];
4042 node_first = getTreeInfoFirstGroupEntry(ti);
4043 node = getTreeInfoFromPos(node_first, entry_pos);
4045 strncpy(buffer, node->name, max_buffer_len);
4046 buffer[max_buffer_len] = '\0';
4048 DrawText(startx, starty, buffer, font_nr + node->color);
4050 if (node->parent_link)
4051 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4052 else if (node->level_group)
4053 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4055 initCursor(i, IMG_MENU_BUTTON);
4058 redraw_mask |= REDRAW_FIELD;
4061 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4063 TreeInfo *node, *node_first;
4064 int x, last_redraw_mask = redraw_mask;
4065 int ypos = MENU_TITLE2_YPOS;
4066 int font_nr = FONT_TITLE_2;
4068 if (ti->type == TREE_TYPE_LEVEL_NR)
4069 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4071 if (ti->type != TREE_TYPE_LEVEL_DIR)
4074 node_first = getTreeInfoFirstGroupEntry(ti);
4075 node = getTreeInfoFromPos(node_first, entry_pos);
4077 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4079 if (node->parent_link)
4080 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4081 node->node_parent->name);
4082 else if (node->level_group)
4083 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4085 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4086 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4087 node->levels, (node->levels > 1 ? "levels" : "level"),
4090 /* let BackToFront() redraw only what is needed */
4091 redraw_mask = last_redraw_mask;
4092 for (x = 0; x < SCR_FIELDX; x++)
4093 MarkTileDirty(x, 1);
4096 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4099 TreeInfo *ti = *ti_ptr;
4101 int y = ti->cl_cursor;
4102 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4103 int num_entries = numTreeInfoInGroup(ti);
4104 int num_page_entries;
4105 boolean position_set_by_scrollbar = (dx == 999);
4107 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4108 num_page_entries = num_entries;
4110 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4112 if (button == MB_MENU_INITIALIZE)
4114 int num_entries = numTreeInfoInGroup(ti);
4115 int entry_pos = posTreeInfo(ti);
4117 if (ti->cl_first == -1)
4119 /* only on initialization */
4120 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4121 ti->cl_cursor = entry_pos - ti->cl_first;
4123 else if (ti->cl_cursor >= num_page_entries ||
4124 (num_entries > num_page_entries &&
4125 num_entries - ti->cl_first < num_page_entries))
4127 /* only after change of list size (by custom graphic configuration) */
4128 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4129 ti->cl_cursor = entry_pos - ti->cl_first;
4132 if (position_set_by_scrollbar)
4135 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4138 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4139 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4140 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4144 else if (button == MB_MENU_LEAVE)
4148 PlaySound(SND_MENU_ITEM_SELECTING);
4150 if (ti->node_parent)
4152 *ti_ptr = ti->node_parent;
4153 DrawChooseTree(ti_ptr);
4155 else if (game_status == GAME_MODE_SETUP)
4157 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4158 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4159 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4161 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4162 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4163 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4164 execSetupGraphics();
4165 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4166 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4167 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4169 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4170 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4171 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4172 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4173 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4174 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4175 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4176 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4183 if (game_status == GAME_MODE_LEVELNR)
4185 int new_level_nr = atoi(level_number_current->identifier);
4187 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4190 SetGameStatus(GAME_MODE_MAIN);
4198 if (mx || my) /* mouse input */
4200 x = (mx - mSX) / 32;
4201 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4203 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4205 /* move cursor instead of scrolling when already at start/end of list */
4206 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4208 else if (dy == +1 * SCROLL_LINE &&
4209 ti->cl_first + num_page_entries == num_entries)
4212 /* handle scrolling screen one line or page */
4213 if (ti->cl_cursor + dy < 0 ||
4214 ti->cl_cursor + dy > num_page_entries - 1)
4216 boolean redraw = FALSE;
4218 if (ABS(dy) == SCROLL_PAGE)
4219 step = num_page_entries - 1;
4221 if (dy < 0 && ti->cl_first > 0)
4223 /* scroll page/line up */
4225 ti->cl_first -= step;
4226 if (ti->cl_first < 0)
4231 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4233 /* scroll page/line down */
4235 ti->cl_first += step;
4236 if (ti->cl_first + num_page_entries > num_entries)
4237 ti->cl_first = MAX(0, num_entries - num_page_entries);
4244 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4245 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4246 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4248 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4255 /* handle moving cursor one line */
4256 y = ti->cl_cursor + dy;
4261 TreeInfo *node_first, *node_cursor;
4262 int entry_pos = ti->cl_first + y;
4264 node_first = getTreeInfoFirstGroupEntry(ti);
4265 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4267 if (node_cursor->node_group)
4271 PlaySound(SND_MENU_ITEM_SELECTING);
4273 node_cursor->cl_first = ti->cl_first;
4274 node_cursor->cl_cursor = ti->cl_cursor;
4275 *ti_ptr = node_cursor->node_group;
4276 DrawChooseTree(ti_ptr);
4281 else if (dx == -1 && ti->node_parent)
4285 PlaySound(SND_MENU_ITEM_SELECTING);
4287 *ti_ptr = ti->node_parent;
4288 DrawChooseTree(ti_ptr);
4293 if (!anyScrollbarGadgetActive() &&
4294 IN_VIS_MENU(x, y) &&
4295 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4296 y >= 0 && y < num_page_entries)
4300 if (y != ti->cl_cursor)
4302 PlaySound(SND_MENU_ITEM_ACTIVATING);
4304 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4305 drawChooseTreeCursor(y, TRUE);
4306 drawChooseTreeInfo(ti->cl_first + y, ti);
4312 if (game_status == GAME_MODE_SETUP)
4314 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4315 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4316 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4318 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4319 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4320 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4321 execSetupGraphics();
4322 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4323 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4324 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4326 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4327 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4328 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4329 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4330 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4331 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4332 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4333 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4342 TreeInfo *node_first, *node_cursor;
4343 int entry_pos = ti->cl_first + y;
4345 PlaySound(SND_MENU_ITEM_SELECTING);
4347 node_first = getTreeInfoFirstGroupEntry(ti);
4348 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4350 if (node_cursor->node_group)
4354 node_cursor->cl_first = ti->cl_first;
4355 node_cursor->cl_cursor = ti->cl_cursor;
4356 *ti_ptr = node_cursor->node_group;
4357 DrawChooseTree(ti_ptr);
4359 else if (node_cursor->parent_link)
4363 *ti_ptr = node_cursor->node_parent;
4364 DrawChooseTree(ti_ptr);
4370 node_cursor->cl_first = ti->cl_first;
4371 node_cursor->cl_cursor = ti->cl_cursor;
4372 *ti_ptr = node_cursor;
4374 if (ti->type == TREE_TYPE_LEVEL_DIR)
4376 LoadLevelSetup_SeriesInfo();
4378 SaveLevelSetup_LastSeries();
4379 SaveLevelSetup_SeriesInfo();
4383 if (game_status == GAME_MODE_SETUP)
4385 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4386 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4387 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4389 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4390 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4391 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4392 execSetupGraphics();
4393 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4394 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4395 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4397 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4398 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4399 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4400 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4401 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4402 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4403 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4404 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4411 if (game_status == GAME_MODE_LEVELNR)
4413 int new_level_nr = atoi(level_number_current->identifier);
4415 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4418 SetGameStatus(GAME_MODE_MAIN);
4427 void DrawChooseLevelSet()
4429 FadeMenuSoundsAndMusic();
4431 DrawChooseTree(&leveldir_current);
4433 PlayMenuSoundsAndMusic();
4436 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4438 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4441 void DrawChooseLevelNr()
4445 FadeMenuSoundsAndMusic();
4447 if (level_number != NULL)
4449 freeTreeInfo(level_number);
4451 level_number = NULL;
4454 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4456 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4457 char identifier[32], name[32];
4460 /* temporarily load level info to get level name */
4461 LoadLevelInfoOnly(i);
4463 ti->node_top = &level_number;
4464 ti->sort_priority = 10000 + value;
4465 ti->color = (level.no_level_file ? FC_BLUE :
4466 LevelStats_getSolved(i) ? FC_GREEN :
4467 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4469 snprintf(identifier, sizeof(identifier), "%d", value);
4470 snprintf(name, sizeof(name), "%03d: %s", value,
4471 (level.no_level_file ? "(no file)" : level.name));
4473 setString(&ti->identifier, identifier);
4474 setString(&ti->name, name);
4475 setString(&ti->name_sorting, name);
4477 pushTreeInfo(&level_number, ti);
4480 /* sort level number values to start with lowest level number */
4481 sortTreeInfo(&level_number);
4483 /* set current level number to current level number */
4484 level_number_current =
4485 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4487 /* if that also fails, set current level number to first available level */
4488 if (level_number_current == NULL)
4489 level_number_current = level_number;
4491 DrawChooseTree(&level_number_current);
4493 PlayMenuSoundsAndMusic();
4496 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4498 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4501 void DrawHallOfFame(int highlight_position)
4503 int fade_mask = REDRAW_FIELD;
4505 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4506 fade_mask = REDRAW_ALL;
4509 FadeMenuSoundsAndMusic();
4511 /* (this is needed when called from GameEnd() after winning a game) */
4512 KeyboardAutoRepeatOn();
4514 /* (this is needed when called from GameEnd() after winning a game) */
4515 SetDrawDeactivationMask(REDRAW_NONE);
4516 SetDrawBackgroundMask(REDRAW_FIELD);
4518 if (highlight_position < 0)
4519 LoadScore(level_nr);
4521 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4523 FadeSetEnterScreen();
4527 /* needed if different viewport properties defined for scores */
4528 ChangeViewportPropertiesIfNeeded();
4530 PlayMenuSoundsAndMusic();
4532 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4534 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4536 DrawMaskedBorder(fade_mask);
4541 static void drawHallOfFameList(int first_entry, int highlight_position)
4545 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4548 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4549 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4550 "HighScores of Level %d", level_nr);
4552 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4554 int entry = first_entry + i;
4555 boolean active = (entry == highlight_position);
4556 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4557 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4558 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4559 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4560 int dxoff = getFontDrawOffsetX(font_nr1);
4561 int dx1 = 3 * getFontWidth(font_nr1);
4562 int dx2 = dx1 + getFontWidth(font_nr1);
4563 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4564 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4565 int sy = mSY + 64 + i * 32;
4567 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4568 DrawText(mSX + dx1, sy, ".", font_nr1);
4570 for (j = 0; j < num_dots; j++)
4571 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4573 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4574 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4576 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4579 redraw_mask |= REDRAW_FIELD;
4582 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4584 static int first_entry = 0;
4585 static int highlight_position = 0;
4586 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4588 if (button == MB_MENU_INITIALIZE)
4591 highlight_position = mx;
4592 drawHallOfFameList(first_entry, highlight_position);
4597 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4598 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4602 if (first_entry > 0)
4604 first_entry -= step;
4605 if (first_entry < 0)
4608 drawHallOfFameList(first_entry, highlight_position);
4613 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4615 first_entry += step;
4616 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4617 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4619 drawHallOfFameList(first_entry, highlight_position);
4622 else if (button == MB_MENU_LEAVE)
4624 PlaySound(SND_MENU_ITEM_SELECTING);
4626 FadeSound(SND_BACKGROUND_SCORES);
4628 SetGameStatus(GAME_MODE_MAIN);
4632 else if (button == MB_MENU_CHOICE)
4634 PlaySound(SND_MENU_ITEM_SELECTING);
4636 FadeSound(SND_BACKGROUND_SCORES);
4638 SetGameStatus(GAME_MODE_MAIN);
4643 if (game_status == GAME_MODE_SCORES)
4644 PlayMenuSoundIfLoop();
4648 /* ========================================================================= */
4649 /* setup screen functions */
4650 /* ========================================================================= */
4652 static struct TokenInfo *setup_info;
4653 static int num_setup_info; /* number of setup entries shown on screen */
4654 static int max_setup_info; /* total number of setup entries in list */
4656 static char *window_size_text;
4657 static char *scaling_type_text;
4658 static char *rendering_mode_text;
4659 static char *scroll_delay_text;
4660 static char *snapshot_mode_text;
4661 static char *game_speed_text;
4662 static char *graphics_set_name;
4663 static char *sounds_set_name;
4664 static char *music_set_name;
4665 static char *volume_simple_text;
4666 static char *volume_loops_text;
4667 static char *volume_music_text;
4668 static char *touch_controls_text;
4669 static char *move_distance_text;
4670 static char *drop_distance_text;
4671 static char *transparency_text;
4672 static char *grid_size_text[2][2];
4674 static void execSetupMain()
4676 setup_mode = SETUP_MODE_MAIN;
4681 static void execSetupGame_setGameSpeeds()
4683 if (game_speeds == NULL)
4687 for (i = 0; game_speeds_list[i].value != -1; i++)
4689 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4690 char identifier[32], name[32];
4691 int value = game_speeds_list[i].value;
4692 char *text = game_speeds_list[i].text;
4694 ti->node_top = &game_speeds;
4695 ti->sort_priority = 10000 - value;
4697 sprintf(identifier, "%d", value);
4698 sprintf(name, "%s", text);
4700 setString(&ti->identifier, identifier);
4701 setString(&ti->name, name);
4702 setString(&ti->name_sorting, name);
4703 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4705 pushTreeInfo(&game_speeds, ti);
4708 /* sort game speed values to start with slowest game speed */
4709 sortTreeInfo(&game_speeds);
4711 /* set current game speed to configured game speed value */
4712 game_speed_current =
4713 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4715 /* if that fails, set current game speed to reliable default value */
4716 if (game_speed_current == NULL)
4717 game_speed_current =
4718 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4720 /* if that also fails, set current game speed to first available speed */
4721 if (game_speed_current == NULL)
4722 game_speed_current = game_speeds;
4725 setup.game_frame_delay = atoi(game_speed_current->identifier);
4727 /* needed for displaying game speed text instead of identifier */
4728 game_speed_text = game_speed_current->name;
4731 static void execSetupGame_setScrollDelays()
4733 if (scroll_delays == NULL)
4737 for (i = 0; scroll_delays_list[i].value != -1; i++)
4739 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4740 char identifier[32], name[32];
4741 int value = scroll_delays_list[i].value;
4742 char *text = scroll_delays_list[i].text;
4744 ti->node_top = &scroll_delays;
4745 ti->sort_priority = value;
4747 sprintf(identifier, "%d", value);
4748 sprintf(name, "%s", text);
4750 setString(&ti->identifier, identifier);
4751 setString(&ti->name, name);
4752 setString(&ti->name_sorting, name);
4753 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4755 pushTreeInfo(&scroll_delays, ti);
4758 /* sort scroll delay values to start with lowest scroll delay value */
4759 sortTreeInfo(&scroll_delays);
4761 /* set current scroll delay value to configured scroll delay value */
4762 scroll_delay_current =
4763 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4765 /* if that fails, set current scroll delay to reliable default value */
4766 if (scroll_delay_current == NULL)
4767 scroll_delay_current =
4768 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4770 /* if that also fails, set current scroll delay to first available value */
4771 if (scroll_delay_current == NULL)
4772 scroll_delay_current = scroll_delays;
4775 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4777 /* needed for displaying scroll delay text instead of identifier */
4778 scroll_delay_text = scroll_delay_current->name;
4781 static void execSetupGame_setSnapshotModes()
4783 if (snapshot_modes == NULL)
4787 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4789 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4790 char identifier[32], name[32];
4791 char *value = snapshot_modes_list[i].value;
4792 char *text = snapshot_modes_list[i].text;
4794 ti->node_top = &snapshot_modes;
4795 ti->sort_priority = i;
4797 sprintf(identifier, "%s", value);
4798 sprintf(name, "%s", text);
4800 setString(&ti->identifier, identifier);
4801 setString(&ti->name, name);
4802 setString(&ti->name_sorting, name);
4803 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4805 pushTreeInfo(&snapshot_modes, ti);
4808 /* sort snapshot mode values to start with lowest snapshot mode value */
4809 sortTreeInfo(&snapshot_modes);
4811 /* set current snapshot mode value to configured snapshot mode value */
4812 snapshot_mode_current =
4813 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4815 /* if that fails, set current snapshot mode to reliable default value */
4816 if (snapshot_mode_current == NULL)
4817 snapshot_mode_current =
4818 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4820 /* if that also fails, set current snapshot mode to first available value */
4821 if (snapshot_mode_current == NULL)
4822 snapshot_mode_current = snapshot_modes;
4825 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4827 /* needed for displaying snapshot mode text instead of identifier */
4828 snapshot_mode_text = snapshot_mode_current->name;
4831 static void execSetupGame()
4833 execSetupGame_setGameSpeeds();
4834 execSetupGame_setScrollDelays();
4835 execSetupGame_setSnapshotModes();
4837 setup_mode = SETUP_MODE_GAME;
4842 static void execSetupChooseGameSpeed()
4844 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4849 static void execSetupChooseScrollDelay()
4851 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4856 static void execSetupChooseSnapshotMode()
4858 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4863 static void execSetupEditor()
4865 setup_mode = SETUP_MODE_EDITOR;
4870 static void execSetupGraphics_setWindowSizes(boolean update_list)
4872 if (window_sizes != NULL && update_list)
4874 freeTreeInfo(window_sizes);
4876 window_sizes = NULL;
4879 if (window_sizes == NULL)
4881 boolean current_window_size_found = FALSE;
4884 for (i = 0; window_sizes_list[i].value != -1; i++)
4886 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4887 char identifier[32], name[32];
4888 int value = window_sizes_list[i].value;
4889 char *text = window_sizes_list[i].text;
4891 ti->node_top = &window_sizes;
4892 ti->sort_priority = value;
4894 sprintf(identifier, "%d", value);
4895 sprintf(name, "%s", text);
4897 setString(&ti->identifier, identifier);
4898 setString(&ti->name, name);
4899 setString(&ti->name_sorting, name);
4900 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4902 pushTreeInfo(&window_sizes, ti);
4904 if (value == setup.window_scaling_percent)
4905 current_window_size_found = TRUE;
4908 if (!current_window_size_found)
4910 // add entry for non-preset window scaling value
4912 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4913 char identifier[32], name[32];
4914 int value = setup.window_scaling_percent;
4916 ti->node_top = &window_sizes;
4917 ti->sort_priority = value;
4919 sprintf(identifier, "%d", value);
4920 sprintf(name, "%d %% (Current)", value);
4922 setString(&ti->identifier, identifier);
4923 setString(&ti->name, name);
4924 setString(&ti->name_sorting, name);
4925 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4927 pushTreeInfo(&window_sizes, ti);
4930 /* sort window size values to start with lowest window size value */
4931 sortTreeInfo(&window_sizes);
4933 /* set current window size value to configured window size value */
4934 window_size_current =
4935 getTreeInfoFromIdentifier(window_sizes,
4936 i_to_a(setup.window_scaling_percent));
4938 /* if that fails, set current window size to reliable default value */
4939 if (window_size_current == NULL)
4940 window_size_current =
4941 getTreeInfoFromIdentifier(window_sizes,
4942 i_to_a(STD_WINDOW_SCALING_PERCENT));
4944 /* if that also fails, set current window size to first available value */
4945 if (window_size_current == NULL)
4946 window_size_current = window_sizes;
4949 setup.window_scaling_percent = atoi(window_size_current->identifier);
4951 /* needed for displaying window size text instead of identifier */
4952 window_size_text = window_size_current->name;
4955 static void execSetupGraphics_setScalingTypes()
4957 if (scaling_types == NULL)
4961 for (i = 0; scaling_types_list[i].value != NULL; i++)
4963 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4964 char identifier[32], name[32];
4965 char *value = scaling_types_list[i].value;
4966 char *text = scaling_types_list[i].text;
4968 ti->node_top = &scaling_types;
4969 ti->sort_priority = i;
4971 sprintf(identifier, "%s", value);
4972 sprintf(name, "%s", text);
4974 setString(&ti->identifier, identifier);
4975 setString(&ti->name, name);
4976 setString(&ti->name_sorting, name);
4977 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4979 pushTreeInfo(&scaling_types, ti);
4982 /* sort scaling type values to start with lowest scaling type value */
4983 sortTreeInfo(&scaling_types);
4985 /* set current scaling type value to configured scaling type value */
4986 scaling_type_current =
4987 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4989 /* if that fails, set current scaling type to reliable default value */
4990 if (scaling_type_current == NULL)
4991 scaling_type_current =
4992 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4994 /* if that also fails, set current scaling type to first available value */
4995 if (scaling_type_current == NULL)
4996 scaling_type_current = scaling_types;
4999 setup.window_scaling_quality = scaling_type_current->identifier;
5001 /* needed for displaying scaling type text instead of identifier */
5002 scaling_type_text = scaling_type_current->name;
5005 static void execSetupGraphics_setRenderingModes()
5007 if (rendering_modes == NULL)
5011 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5013 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5014 char identifier[32], name[32];
5015 char *value = rendering_modes_list[i].value;
5016 char *text = rendering_modes_list[i].text;
5018 ti->node_top = &rendering_modes;
5019 ti->sort_priority = i;
5021 sprintf(identifier, "%s", value);
5022 sprintf(name, "%s", text);
5024 setString(&ti->identifier, identifier);
5025 setString(&ti->name, name);
5026 setString(&ti->name_sorting, name);
5027 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5029 pushTreeInfo(&rendering_modes, ti);
5032 /* sort rendering mode values to start with lowest rendering mode value */
5033 sortTreeInfo(&rendering_modes);
5035 /* set current rendering mode value to configured rendering mode value */
5036 rendering_mode_current =
5037 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5039 /* if that fails, set current rendering mode to reliable default value */
5040 if (rendering_mode_current == NULL)
5041 rendering_mode_current =
5042 getTreeInfoFromIdentifier(rendering_modes,
5043 STR_SPECIAL_RENDERING_DEFAULT);
5045 /* if that also fails, set current rendering mode to first available one */
5046 if (rendering_mode_current == NULL)
5047 rendering_mode_current = rendering_modes;
5050 setup.screen_rendering_mode = rendering_mode_current->identifier;
5052 /* needed for displaying rendering mode text instead of identifier */
5053 rendering_mode_text = rendering_mode_current->name;
5056 static void execSetupGraphics()
5058 // update "setup.window_scaling_percent" from list selection
5059 // (in this case, window scaling was changed on setup screen)
5060 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5061 execSetupGraphics_setWindowSizes(FALSE);
5063 // update list selection from "setup.window_scaling_percent"
5064 // (window scaling may have changed by resizing the window)
5065 execSetupGraphics_setWindowSizes(TRUE);
5067 execSetupGraphics_setScalingTypes();
5068 execSetupGraphics_setRenderingModes();
5070 setup_mode = SETUP_MODE_GRAPHICS;
5074 #if defined(TARGET_SDL2)
5075 // window scaling may have changed at this point
5076 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5078 // window scaling quality may have changed at this point
5079 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5080 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5082 // screen rendering mode may have changed at this point
5083 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5087 static void execSetupChooseWindowSize()
5089 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5094 static void execSetupChooseScalingType()
5096 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5101 static void execSetupChooseRenderingMode()
5103 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5108 static void execSetupChooseVolumeSimple()
5110 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5115 static void execSetupChooseVolumeLoops()
5117 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5122 static void execSetupChooseVolumeMusic()
5124 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5129 static void execSetupSound()
5131 if (volumes_simple == NULL)
5133 boolean current_volume_simple_found = FALSE;
5136 for (i = 0; volumes_list[i].value != -1; i++)
5138 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5139 char identifier[32], name[32];
5140 int value = volumes_list[i].value;
5141 char *text = volumes_list[i].text;
5143 ti->node_top = &volumes_simple;
5144 ti->sort_priority = value;
5146 sprintf(identifier, "%d", value);
5147 sprintf(name, "%s", text);
5149 setString(&ti->identifier, identifier);
5150 setString(&ti->name, name);
5151 setString(&ti->name_sorting, name);
5152 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5154 pushTreeInfo(&volumes_simple, ti);
5156 if (value == setup.volume_simple)
5157 current_volume_simple_found = TRUE;
5160 if (!current_volume_simple_found)
5162 // add entry for non-preset volume value
5164 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5165 char identifier[32], name[32];
5166 int value = setup.volume_simple;
5168 ti->node_top = &volumes_simple;
5169 ti->sort_priority = value;
5171 sprintf(identifier, "%d", value);
5172 sprintf(name, "%d %% (Current)", value);
5174 setString(&ti->identifier, identifier);
5175 setString(&ti->name, name);
5176 setString(&ti->name_sorting, name);
5177 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5179 pushTreeInfo(&volumes_simple, ti);
5182 /* sort volume values to start with lowest volume value */
5183 sortTreeInfo(&volumes_simple);
5185 /* set current volume value to configured volume value */
5186 volume_simple_current =
5187 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5189 /* if that fails, set current volume to reliable default value */
5190 if (volume_simple_current == NULL)
5191 volume_simple_current =
5192 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5194 /* if that also fails, set current volume to first available value */
5195 if (volume_simple_current == NULL)
5196 volume_simple_current = volumes_simple;
5199 if (volumes_loops == NULL)
5201 boolean current_volume_loops_found = FALSE;
5204 for (i = 0; volumes_list[i].value != -1; i++)
5206 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5207 char identifier[32], name[32];
5208 int value = volumes_list[i].value;
5209 char *text = volumes_list[i].text;
5211 ti->node_top = &volumes_loops;
5212 ti->sort_priority = value;
5214 sprintf(identifier, "%d", value);
5215 sprintf(name, "%s", text);
5217 setString(&ti->identifier, identifier);
5218 setString(&ti->name, name);
5219 setString(&ti->name_sorting, name);
5220 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5222 pushTreeInfo(&volumes_loops, ti);
5224 if (value == setup.volume_loops)
5225 current_volume_loops_found = TRUE;
5228 if (!current_volume_loops_found)
5230 // add entry for non-preset volume value
5232 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5233 char identifier[32], name[32];
5234 int value = setup.volume_loops;
5236 ti->node_top = &volumes_loops;
5237 ti->sort_priority = value;
5239 sprintf(identifier, "%d", value);
5240 sprintf(name, "%d %% (Current)", value);
5242 setString(&ti->identifier, identifier);
5243 setString(&ti->name, name);
5244 setString(&ti->name_sorting, name);
5245 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5247 pushTreeInfo(&volumes_loops, ti);
5250 /* sort volume values to start with lowest volume value */
5251 sortTreeInfo(&volumes_loops);
5253 /* set current volume value to configured volume value */
5254 volume_loops_current =
5255 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5257 /* if that fails, set current volume to reliable default value */
5258 if (volume_loops_current == NULL)
5259 volume_loops_current =
5260 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5262 /* if that also fails, set current volume to first available value */
5263 if (volume_loops_current == NULL)
5264 volume_loops_current = volumes_loops;
5267 if (volumes_music == NULL)
5269 boolean current_volume_music_found = FALSE;
5272 for (i = 0; volumes_list[i].value != -1; i++)
5274 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5275 char identifier[32], name[32];
5276 int value = volumes_list[i].value;
5277 char *text = volumes_list[i].text;
5279 ti->node_top = &volumes_music;
5280 ti->sort_priority = value;
5282 sprintf(identifier, "%d", value);
5283 sprintf(name, "%s", text);
5285 setString(&ti->identifier, identifier);
5286 setString(&ti->name, name);
5287 setString(&ti->name_sorting, name);
5288 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5290 pushTreeInfo(&volumes_music, ti);
5292 if (value == setup.volume_music)
5293 current_volume_music_found = TRUE;
5296 if (!current_volume_music_found)
5298 // add entry for non-preset volume value
5300 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5301 char identifier[32], name[32];
5302 int value = setup.volume_music;
5304 ti->node_top = &volumes_music;
5305 ti->sort_priority = value;
5307 sprintf(identifier, "%d", value);
5308 sprintf(name, "%d %% (Current)", value);
5310 setString(&ti->identifier, identifier);
5311 setString(&ti->name, name);
5312 setString(&ti->name_sorting, name);
5313 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5315 pushTreeInfo(&volumes_music, ti);
5318 /* sort volume values to start with lowest volume value */
5319 sortTreeInfo(&volumes_music);
5321 /* set current volume value to configured volume value */
5322 volume_music_current =
5323 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5325 /* if that fails, set current volume to reliable default value */
5326 if (volume_music_current == NULL)
5327 volume_music_current =
5328 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5330 /* if that also fails, set current volume to first available value */
5331 if (volume_music_current == NULL)
5332 volume_music_current = volumes_music;
5335 setup.volume_simple = atoi(volume_simple_current->identifier);
5336 setup.volume_loops = atoi(volume_loops_current->identifier);
5337 setup.volume_music = atoi(volume_music_current->identifier);
5339 /* needed for displaying volume text instead of identifier */
5340 volume_simple_text = volume_simple_current->name;
5341 volume_loops_text = volume_loops_current->name;
5342 volume_music_text = volume_music_current->name;
5344 setup_mode = SETUP_MODE_SOUND;
5349 static void execSetupChooseTouchControls()
5351 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5356 static void execSetupChooseMoveDistance()
5358 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5363 static void execSetupChooseDropDistance()
5365 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5370 static void execSetupChooseTransparency()
5372 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5377 static void execSetupChooseGridXSize_0()
5379 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5384 static void execSetupChooseGridYSize_0()
5386 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5391 static void execSetupChooseGridXSize_1()
5393 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5398 static void execSetupChooseGridYSize_1()
5400 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5405 static void execSetupConfigureVirtualButtons()
5407 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5409 ConfigureVirtualButtons();
5411 setup_mode = SETUP_MODE_TOUCH;
5416 static void execSetupTouch()
5420 if (touch_controls == NULL)
5422 for (i = 0; touch_controls_list[i].value != NULL; i++)
5424 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5425 char identifier[32], name[32];
5426 char *value = touch_controls_list[i].value;
5427 char *text = touch_controls_list[i].text;
5429 ti->node_top = &touch_controls;
5430 ti->sort_priority = i;
5432 sprintf(identifier, "%s", value);
5433 sprintf(name, "%s", text);
5435 setString(&ti->identifier, identifier);
5436 setString(&ti->name, name);
5437 setString(&ti->name_sorting, name);
5438 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5440 pushTreeInfo(&touch_controls, ti);
5443 /* sort touch control values to start with lowest touch control value */
5444 sortTreeInfo(&touch_controls);
5446 /* set current touch control value to configured touch control value */
5447 touch_control_current =
5448 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5450 /* if that fails, set current touch control to reliable default value */
5451 if (touch_control_current == NULL)
5452 touch_control_current =
5453 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5455 /* if that also fails, set current touch control to first available value */
5456 if (touch_control_current == NULL)
5457 touch_control_current = touch_controls;
5460 if (move_distances == NULL)
5462 for (i = 0; distances_list[i].value != -1; i++)
5464 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5465 char identifier[32], name[32];
5466 int value = distances_list[i].value;
5467 char *text = distances_list[i].text;
5469 ti->node_top = &move_distances;
5470 ti->sort_priority = value;
5472 sprintf(identifier, "%d", value);
5473 sprintf(name, "%s", text);
5475 setString(&ti->identifier, identifier);
5476 setString(&ti->name, name);
5477 setString(&ti->name_sorting, name);
5478 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5480 pushTreeInfo(&move_distances, ti);
5483 /* sort distance values to start with lowest distance value */
5484 sortTreeInfo(&move_distances);
5486 /* set current distance value to configured distance value */
5487 move_distance_current =
5488 getTreeInfoFromIdentifier(move_distances,
5489 i_to_a(setup.touch.move_distance));
5491 /* if that fails, set current distance to reliable default value */
5492 if (move_distance_current == NULL)
5493 move_distance_current =
5494 getTreeInfoFromIdentifier(move_distances,
5495 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5497 /* if that also fails, set current distance to first available value */
5498 if (move_distance_current == NULL)
5499 move_distance_current = move_distances;
5502 if (drop_distances == NULL)
5504 for (i = 0; distances_list[i].value != -1; i++)
5506 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5507 char identifier[32], name[32];
5508 int value = distances_list[i].value;
5509 char *text = distances_list[i].text;
5511 ti->node_top = &drop_distances;
5512 ti->sort_priority = value;
5514 sprintf(identifier, "%d", value);
5515 sprintf(name, "%s", text);
5517 setString(&ti->identifier, identifier);
5518 setString(&ti->name, name);
5519 setString(&ti->name_sorting, name);
5520 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5522 pushTreeInfo(&drop_distances, ti);
5525 /* sort distance values to start with lowest distance value */
5526 sortTreeInfo(&drop_distances);
5528 /* set current distance value to configured distance value */
5529 drop_distance_current =
5530 getTreeInfoFromIdentifier(drop_distances,
5531 i_to_a(setup.touch.drop_distance));
5533 /* if that fails, set current distance to reliable default value */
5534 if (drop_distance_current == NULL)
5535 drop_distance_current =
5536 getTreeInfoFromIdentifier(drop_distances,
5537 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5539 /* if that also fails, set current distance to first available value */
5540 if (drop_distance_current == NULL)
5541 drop_distance_current = drop_distances;
5544 if (transparencies == NULL)
5546 for (i = 0; transparencies_list[i].value != -1; i++)
5548 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5549 char identifier[32], name[32];
5550 int value = transparencies_list[i].value;
5551 char *text = transparencies_list[i].text;
5553 ti->node_top = &transparencies;
5554 ti->sort_priority = value;
5556 sprintf(identifier, "%d", value);
5557 sprintf(name, "%s", text);
5559 setString(&ti->identifier, identifier);
5560 setString(&ti->name, name);
5561 setString(&ti->name_sorting, name);
5562 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5564 pushTreeInfo(&transparencies, ti);
5567 /* sort transparency values to start with lowest transparency value */
5568 sortTreeInfo(&transparencies);
5570 /* set current transparency value to configured transparency value */
5571 transparency_current =
5572 getTreeInfoFromIdentifier(transparencies,
5573 i_to_a(setup.touch.transparency));
5575 /* if that fails, set current transparency to reliable default value */
5576 if (transparency_current == NULL)
5577 transparency_current =
5578 getTreeInfoFromIdentifier(transparencies,
5579 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5581 /* if that also fails, set current transparency to first available value */
5582 if (transparency_current == NULL)
5583 transparency_current = transparencies;
5586 for (i = 0; i < 2; i++)
5588 for (j = 0; j < 2; j++)
5590 if (grid_sizes[i][j] == NULL)
5592 for (k = 0; grid_sizes_list[k].value != -1; k++)
5594 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5595 char identifier[32], name[32];
5596 int value = grid_sizes_list[k].value;
5597 char *text = grid_sizes_list[k].text;
5599 ti->node_top = &grid_sizes[i][j];
5600 ti->sort_priority = value;
5602 sprintf(identifier, "%d", value);
5603 sprintf(name, "%s", text);
5605 setString(&ti->identifier, identifier);
5606 setString(&ti->name, name);
5607 setString(&ti->name_sorting, name);
5608 setString(&ti->infotext,
5611 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5612 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5614 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5615 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5617 pushTreeInfo(&grid_sizes[i][j], ti);
5620 /* sort grid size values to start with lowest grid size value */
5621 sortTreeInfo(&grid_sizes[i][j]);
5623 /* set current grid size value to configured grid size value */
5624 grid_size_current[i][j] =
5625 getTreeInfoFromIdentifier(grid_sizes[i][j],
5627 setup.touch.grid_xsize[i] :
5628 setup.touch.grid_ysize[i]));
5630 /* if that fails, set current grid size to reliable default value */
5631 if (grid_size_current[i][j] == NULL)
5632 grid_size_current[i][j] =
5633 getTreeInfoFromIdentifier(grid_sizes[i][j],
5635 DEFAULT_GRID_XSIZE(i) :
5636 DEFAULT_GRID_YSIZE(i)));
5638 /* if that also fails, set current grid size to first available value */
5639 if (grid_size_current[i][j] == NULL)
5640 grid_size_current[i][j] = grid_sizes[i][j];
5645 setup.touch.control_type = touch_control_current->identifier;
5646 setup.touch.move_distance = atoi(move_distance_current->identifier);
5647 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5648 setup.touch.transparency = atoi(transparency_current->identifier);
5650 for (i = 0; i < 2; i++)
5652 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5653 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5655 if (i == GRID_ACTIVE_NR())
5657 overlay.grid_xsize = setup.touch.grid_xsize[i];
5658 overlay.grid_ysize = setup.touch.grid_ysize[i];
5662 /* needed for displaying value text instead of identifier */
5663 touch_controls_text = touch_control_current->name;
5664 move_distance_text = move_distance_current->name;
5665 drop_distance_text = drop_distance_current->name;
5666 transparency_text = transparency_current->name;
5668 for (i = 0; i < 2; i++)
5669 for (j = 0; j < 2; j++)
5670 grid_size_text[i][j] = grid_size_current[i][j]->name;
5672 setup_mode = SETUP_MODE_TOUCH;
5677 static void execSetupArtwork()
5680 printf("::: '%s', '%s', '%s'\n",
5681 artwork.gfx_current->subdir,
5682 artwork.gfx_current->fullpath,
5683 artwork.gfx_current->basepath);
5686 setup.graphics_set = artwork.gfx_current->identifier;
5687 setup.sounds_set = artwork.snd_current->identifier;
5688 setup.music_set = artwork.mus_current->identifier;
5690 /* needed if last screen (setup choice) changed graphics, sounds or music */
5691 ReloadCustomArtwork(0);
5693 /* needed for displaying artwork name instead of artwork identifier */
5694 graphics_set_name = artwork.gfx_current->name;
5695 sounds_set_name = artwork.snd_current->name;
5696 music_set_name = artwork.mus_current->name;
5698 setup_mode = SETUP_MODE_ARTWORK;
5703 static void execSetupChooseGraphics()
5705 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5710 static void execSetupChooseSounds()
5712 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5717 static void execSetupChooseMusic()
5719 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5724 static void execSetupInput()
5726 setup_mode = SETUP_MODE_INPUT;
5731 static void execSetupShortcuts()
5733 setup_mode = SETUP_MODE_SHORTCUTS;
5738 static void execSetupShortcuts1()
5740 setup_mode = SETUP_MODE_SHORTCUTS_1;
5745 static void execSetupShortcuts2()
5747 setup_mode = SETUP_MODE_SHORTCUTS_2;
5752 static void execSetupShortcuts3()
5754 setup_mode = SETUP_MODE_SHORTCUTS_3;
5759 static void execSetupShortcuts4()
5761 setup_mode = SETUP_MODE_SHORTCUTS_4;
5766 static void execSetupShortcuts5()
5768 setup_mode = SETUP_MODE_SHORTCUTS_5;
5773 static void execExitSetup()
5775 SetGameStatus(GAME_MODE_MAIN);
5780 static void execSaveAndExitSetup()
5789 void *related_value;
5790 } hide_related_entry_list[] =
5792 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5793 { &setup.game_frame_delay, &game_speed_text },
5795 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5796 { &setup.scroll_delay_value, &scroll_delay_text },
5798 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5799 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5801 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5802 { &setup.window_scaling_percent, &window_size_text },
5804 { &setup.window_scaling_quality, execSetupChooseScalingType },
5805 { &setup.window_scaling_quality, &scaling_type_text },
5807 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5808 { &setup.screen_rendering_mode, &rendering_mode_text },
5810 { &setup.graphics_set, execSetupChooseGraphics },
5811 { &setup.graphics_set, &graphics_set_name },
5813 { &setup.sounds_set, execSetupChooseSounds },
5814 { &setup.sounds_set, &sounds_set_name },
5816 { &setup.music_set, execSetupChooseMusic },
5817 { &setup.music_set, &music_set_name },
5819 { &setup.volume_simple, execSetupChooseVolumeSimple },
5820 { &setup.volume_simple, &volume_simple_text },
5822 { &setup.volume_loops, execSetupChooseVolumeLoops },
5823 { &setup.volume_loops, &volume_loops_text },
5825 { &setup.volume_music, execSetupChooseVolumeMusic },
5826 { &setup.volume_music, &volume_music_text },
5828 { &setup.touch.control_type, execSetupChooseTouchControls },
5829 { &setup.touch.control_type, &touch_controls_text },
5831 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5832 { &setup.touch.move_distance, &move_distance_text },
5834 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5835 { &setup.touch.drop_distance, &drop_distance_text },
5837 { &setup.touch.transparency, execSetupChooseTransparency },
5838 { &setup.touch.transparency, &transparency_text },
5840 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5841 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5843 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5844 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5846 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5847 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5849 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5850 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5855 void setHideRelatedSetupEntries()
5859 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5860 if (hideSetupEntry(hide_related_entry_list[i].value))
5861 setHideSetupEntry(hide_related_entry_list[i].related_value);
5864 static struct TokenInfo setup_info_main[] =
5866 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5867 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5868 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5869 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5870 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5871 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5872 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5873 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5874 { TYPE_EMPTY, NULL, "" },
5875 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5876 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5881 static struct TokenInfo setup_info_game[] =
5883 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5884 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
5885 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
5886 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5887 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5888 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5889 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5890 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5891 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5892 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5893 { TYPE_STRING, &game_speed_text, "" },
5895 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5896 { TYPE_STRING, &scroll_delay_text, "" },
5898 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5899 { TYPE_STRING, &snapshot_mode_text, "" },
5900 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5901 { TYPE_EMPTY, NULL, "" },
5902 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5907 static struct TokenInfo setup_info_editor[] =
5910 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5911 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5912 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5913 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5914 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5915 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5916 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5917 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5918 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5919 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5921 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5922 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5924 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5926 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5927 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5928 { TYPE_EMPTY, NULL, "" },
5930 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5931 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5932 { TYPE_EMPTY, NULL, "" },
5934 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5935 { TYPE_EMPTY, NULL, "" },
5936 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5941 static struct TokenInfo setup_info_graphics[] =
5943 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5944 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5945 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5946 { TYPE_STRING, &window_size_text, "" },
5947 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5948 { TYPE_STRING, &scaling_type_text, "" },
5949 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5950 { TYPE_STRING, &rendering_mode_text, "" },
5953 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5954 { TYPE_STRING, &scroll_delay_text, "" },
5956 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5957 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5958 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5959 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5960 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5961 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5962 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5963 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5964 { TYPE_EMPTY, NULL, "" },
5965 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5970 static struct TokenInfo setup_info_sound[] =
5972 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5973 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5974 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5975 { TYPE_EMPTY, NULL, "" },
5976 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5977 { TYPE_STRING, &volume_simple_text, "" },
5978 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5979 { TYPE_STRING, &volume_loops_text, "" },
5980 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5981 { TYPE_STRING, &volume_music_text, "" },
5982 { TYPE_EMPTY, NULL, "" },
5983 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5988 static struct TokenInfo setup_info_artwork[] =
5990 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5991 { TYPE_STRING, &graphics_set_name, "" },
5992 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5993 { TYPE_STRING, &sounds_set_name, "" },
5994 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5995 { TYPE_STRING, &music_set_name, "" },
5996 { TYPE_EMPTY, NULL, "" },
5997 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5998 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5999 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6000 { TYPE_EMPTY, NULL, "" },
6001 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6006 static struct TokenInfo setup_info_input[] =
6008 { TYPE_SWITCH, NULL, "Player:" },
6009 { TYPE_SWITCH, NULL, "Device:" },
6010 { TYPE_SWITCH, NULL, "" },
6011 { TYPE_SKIPPABLE, NULL, "" },
6012 { TYPE_EMPTY, NULL, "" },
6013 { TYPE_EMPTY, NULL, "" },
6014 { TYPE_EMPTY, NULL, "" },
6015 { TYPE_EMPTY, NULL, "" },
6016 { TYPE_EMPTY, NULL, "" },
6017 { TYPE_EMPTY, NULL, "" },
6018 { TYPE_EMPTY, NULL, "" },
6019 { TYPE_EMPTY, NULL, "" },
6020 { TYPE_SKIPPABLE, NULL, "" },
6021 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6026 static struct TokenInfo setup_info_touch[] =
6028 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6029 { TYPE_STRING, &touch_controls_text, "" },
6030 { TYPE_EMPTY, NULL, "" },
6031 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6036 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6038 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6039 { TYPE_STRING, &touch_controls_text, "" },
6040 { TYPE_EMPTY, NULL, "" },
6041 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6042 { TYPE_STRING, &grid_size_text[0][0], "" },
6043 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6044 { TYPE_STRING, &grid_size_text[0][1], "" },
6045 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6046 { TYPE_STRING, &transparency_text, "" },
6047 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6048 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6049 { TYPE_EMPTY, NULL, "" },
6050 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6051 { TYPE_EMPTY, NULL, "" },
6052 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6057 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6059 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6060 { TYPE_STRING, &touch_controls_text, "" },
6061 { TYPE_EMPTY, NULL, "" },
6062 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6063 { TYPE_STRING, &grid_size_text[1][0], "" },
6064 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6065 { TYPE_STRING, &grid_size_text[1][1], "" },
6066 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6067 { TYPE_STRING, &transparency_text, "" },
6068 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6069 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6070 { TYPE_EMPTY, NULL, "" },
6071 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6072 { TYPE_EMPTY, NULL, "" },
6073 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6078 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6080 setup_info_touch_virtual_buttons_0,
6081 setup_info_touch_virtual_buttons_1
6084 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6086 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6087 { TYPE_STRING, &touch_controls_text, "" },
6088 { TYPE_EMPTY, NULL, "" },
6089 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6090 { TYPE_STRING, &move_distance_text, "" },
6091 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6092 { TYPE_STRING, &drop_distance_text, "" },
6093 { TYPE_EMPTY, NULL, "" },
6094 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6099 static struct TokenInfo setup_info_shortcuts[] =
6101 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6102 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6103 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6104 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6105 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6106 { TYPE_EMPTY, NULL, "" },
6107 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6112 static struct TokenInfo setup_info_shortcuts_1[] =
6114 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6115 { TYPE_KEY, &setup.shortcut.save_game, "" },
6116 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6117 { TYPE_KEY, &setup.shortcut.load_game, "" },
6118 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6119 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6120 { TYPE_EMPTY, NULL, "" },
6121 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6122 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6123 { TYPE_EMPTY, NULL, "" },
6124 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6129 static struct TokenInfo setup_info_shortcuts_2[] =
6131 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6132 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6133 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6134 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6135 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6136 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6137 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6138 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6139 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6140 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6141 { TYPE_EMPTY, NULL, "" },
6142 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6147 static struct TokenInfo setup_info_shortcuts_3[] =
6149 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6150 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6151 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6152 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6153 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6154 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6155 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6156 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6157 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6158 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6159 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6160 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6161 { TYPE_EMPTY, NULL, "" },
6162 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6167 static struct TokenInfo setup_info_shortcuts_4[] =
6169 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6170 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6171 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6172 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6173 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6174 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6175 { TYPE_EMPTY, NULL, "" },
6176 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6181 static struct TokenInfo setup_info_shortcuts_5[] =
6183 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6184 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6185 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6186 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6187 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6188 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6189 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6190 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6191 { TYPE_EMPTY, NULL, "" },
6192 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6197 static Key getSetupKey()
6199 Key key = KSYM_UNDEFINED;
6200 boolean got_key_event = FALSE;
6202 while (!got_key_event)
6206 if (NextValidEvent(&event))
6210 case EVENT_KEYPRESS:
6212 key = GetEventKey((KeyEvent *)&event, TRUE);
6214 /* press 'Escape' or 'Enter' to keep the existing key binding */
6215 if (key == KSYM_Escape || key == KSYM_Return)
6216 key = KSYM_UNDEFINED; /* keep old value */
6218 got_key_event = TRUE;
6222 case EVENT_KEYRELEASE:
6223 key_joystick_mapping = 0;
6227 HandleOtherEvents(&event);
6238 static int getSetupValueFont(int type, void *value)
6240 if (type & TYPE_GHOSTED)
6241 return FONT_OPTION_OFF;
6242 else if (type & TYPE_KEY)
6243 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6244 else if (type & TYPE_STRING)
6245 return FONT_VALUE_2;
6246 else if (type & TYPE_ECS_AGA)
6247 return FONT_VALUE_1;
6248 else if (type & TYPE_BOOLEAN_STYLE)
6249 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6250 else if (type & TYPE_YES_NO_AUTO)
6251 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6252 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6253 else if (type & TYPE_PLAYER)
6254 return FONT_VALUE_1;
6256 return FONT_VALUE_1;
6259 static int getSetupValueFontNarrow(int type, int font_nr)
6261 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6262 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6263 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6267 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6269 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6270 struct TokenInfo *si = &setup_info[si_pos];
6271 boolean font_draw_xoffset_modified = FALSE;
6272 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6273 int font_draw_xoffset_old = -1;
6274 int xoffset = (scrollbar_needed ? -1 : 0);
6275 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6276 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6277 int xpos = menu_screen_value_xpos;
6278 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6279 int startx = mSX + xpos * 32;
6280 int starty = mSY + ypos * 32;
6281 int font_nr, font_nr_default, font_width_default;
6282 int type = si->type;
6283 void *value = si->value;
6284 char *value_string = getSetupValue(type, value);
6287 if (value_string == NULL)
6290 if (type & TYPE_KEY)
6292 xpos = MENU_SCREEN_START_XPOS;
6294 if (type & TYPE_QUERY)
6295 value_string = "<press key>";
6297 else if (type & TYPE_STRING)
6299 int max_value_len = (SCR_FIELDX - 2) * 2;
6301 xpos = MENU_SCREEN_START_XPOS;
6303 if (strlen(value_string) > max_value_len)
6304 value_string[max_value_len] = '\0';
6306 else if (type & TYPE_YES_NO_AUTO)
6308 xpos = menu_screen_value_xpos - 1;
6310 else if (type & TYPE_PLAYER)
6312 int displayed_player_nr = *(int *)value + 1;
6314 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6317 startx = mSX + xpos * 32;
6318 starty = mSY + ypos * 32;
6319 font_nr_default = getSetupValueFont(type, value);
6320 font_width_default = getFontWidth(font_nr_default);
6322 font_nr = font_nr_default;
6324 // special check if right-side setup values moved left due to scrollbar
6325 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6327 int max_menu_text_length = 26; // maximum text length for classic menu
6328 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6329 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6330 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6331 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6332 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6334 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6337 startx = mSX + xpos * 32;
6339 font_nr = getSetupValueFontNarrow(type, font_nr);
6343 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6344 if (setup_mode != SETUP_MODE_INPUT)
6346 int max_menu_text_length_big = (menu_screen_value_xpos -
6347 MENU_SCREEN_START_XPOS);
6348 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6349 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6350 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6351 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6352 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6353 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6354 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6355 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6356 boolean correct_font_draw_xoffset = FALSE;
6358 if (xpos == MENU_SCREEN_START_XPOS &&
6359 startx + font1_xoffset < text_startx + text_font_xoffset)
6360 correct_font_draw_xoffset = TRUE;
6362 if (xpos == menu_screen_value_xpos &&
6363 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6364 correct_font_draw_xoffset = TRUE;
6366 /* check if setup value would overlap with setup text when printed */
6367 /* (this can happen for extreme/wrong values for font draw offset) */
6368 if (correct_font_draw_xoffset)
6370 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6371 font_draw_xoffset_modified = TRUE;
6373 if (type & TYPE_KEY)
6374 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6375 else if (!(type & TYPE_STRING))
6376 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6377 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6381 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6382 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6384 DrawText(startx, starty, value_string, font_nr);
6386 if (type & TYPE_PLAYER)
6388 int player_nr = *(int *)value;
6389 int xoff = getFontWidth(font_nr);
6391 DrawFixedGraphicThruMaskExt(drawto, startx + xoff, starty,
6392 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6395 if (font_draw_xoffset_modified)
6396 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6399 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6401 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6402 struct TokenInfo *si = &setup_info[si_pos];
6404 if (si->type & TYPE_BOOLEAN_STYLE)
6406 *(boolean *)si->value ^= TRUE;
6408 else if (si->type & TYPE_YES_NO_AUTO)
6412 (*(int *)si->value == AUTO ? TRUE :
6413 *(int *)si->value == TRUE ? FALSE : AUTO) :
6414 (*(int *)si->value == TRUE ? AUTO :
6415 *(int *)si->value == AUTO ? FALSE : TRUE));
6417 else if (si->type & TYPE_KEY)
6421 si->type |= TYPE_QUERY;
6422 drawSetupValue(screen_pos, setup_info_pos_raw);
6423 si->type &= ~TYPE_QUERY;
6425 key = getSetupKey();
6426 if (key != KSYM_UNDEFINED)
6427 *(Key *)si->value = key;
6429 else if (si->type & TYPE_PLAYER)
6431 int player_nr = *(int *)si->value;
6436 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6438 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6441 drawSetupValue(screen_pos, setup_info_pos_raw);
6443 // fullscreen state may have changed at this point
6444 if (si->value == &setup.fullscreen)
6445 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6447 if (si->value == &setup.network_mode &&
6448 setup.network_mode &&
6450 Request("Please restart game to enable network games!", REQ_CONFIRM);
6453 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6455 static struct TokenInfo *setup_info_final = NULL;
6460 /* determine maximum list size of target list */
6461 while (setup_info_orig[list_size++].type != 0);
6463 /* free, allocate and clear memory for target list */
6464 checked_free(setup_info_final);
6465 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6467 /* copy setup info list without setup entries marked as hidden */
6468 for (i = 0; setup_info_orig[i].type != 0; i++)
6470 /* skip setup entries configured to be hidden */
6471 if (hideSetupEntry(setup_info_orig[i].value))
6474 /* skip skippable setup entries if screen is lower than usual */
6475 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6476 setup_info_orig[i].type == TYPE_SKIPPABLE)
6479 setup_info_final[list_pos++] = setup_info_orig[i];
6482 return setup_info_final;
6485 static void DrawSetupScreen_Generic()
6487 int fade_mask = REDRAW_FIELD;
6488 boolean redraw_all = FALSE;
6489 char *title_string = NULL;
6492 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6493 fade_mask = REDRAW_ALL;
6496 FadeMenuSoundsAndMusic();
6498 FreeScreenGadgets();
6499 CreateScreenGadgets();
6501 if (redraw_mask & REDRAW_ALL)
6506 /* needed if different viewport properties defined for setup screen */
6507 ChangeViewportPropertiesIfNeeded();
6509 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6513 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6515 if (setup_mode == SETUP_MODE_MAIN)
6517 setup_info = setup_info_main;
6518 title_string = STR_SETUP_MAIN;
6520 else if (setup_mode == SETUP_MODE_GAME)
6522 setup_info = setup_info_game;
6523 title_string = STR_SETUP_GAME;
6525 else if (setup_mode == SETUP_MODE_EDITOR)
6527 setup_info = setup_info_editor;
6528 title_string = STR_SETUP_EDITOR;
6530 else if (setup_mode == SETUP_MODE_GRAPHICS)
6532 setup_info = setup_info_graphics;
6533 title_string = STR_SETUP_GRAPHICS;
6535 else if (setup_mode == SETUP_MODE_SOUND)
6537 setup_info = setup_info_sound;
6538 title_string = STR_SETUP_SOUND;
6540 else if (setup_mode == SETUP_MODE_ARTWORK)
6542 setup_info = setup_info_artwork;
6543 title_string = STR_SETUP_ARTWORK;
6545 else if (setup_mode == SETUP_MODE_TOUCH)
6547 setup_info = setup_info_touch;
6548 title_string = STR_SETUP_TOUCH;
6550 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6551 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6552 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6553 setup_info = setup_info_touch_wipe_gestures;
6555 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6557 setup_info = setup_info_shortcuts;
6558 title_string = STR_SETUP_SHORTCUTS;
6560 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6562 setup_info = setup_info_shortcuts_1;
6563 title_string = STR_SETUP_SHORTCUTS;
6565 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6567 setup_info = setup_info_shortcuts_2;
6568 title_string = STR_SETUP_SHORTCUTS;
6570 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6572 setup_info = setup_info_shortcuts_3;
6573 title_string = STR_SETUP_SHORTCUTS;
6575 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6577 setup_info = setup_info_shortcuts_4;
6578 title_string = STR_SETUP_SHORTCUTS;
6580 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6582 setup_info = setup_info_shortcuts_5;
6583 title_string = STR_SETUP_SHORTCUTS;
6586 /* use modified setup info without setup entries marked as hidden */
6587 setup_info = getSetupInfoFinal(setup_info);
6589 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6591 // determine maximal number of setup entries that can be displayed on screen
6593 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6596 // determine maximal number of setup entries available for this setup screen
6598 for (i = 0; setup_info[i].type != 0; i++)
6601 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6603 MapScreenGadgets(max_setup_info);
6606 redraw_mask = fade_mask = REDRAW_ALL;
6608 DrawMaskedBorder(fade_mask);
6613 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6615 menu_info = setup_info;
6617 HandleMenuScreen(mx, my, dx, dy, button,
6618 setup_mode, num_setup_info, max_setup_info);
6621 void DrawSetupScreen_Input()
6625 FadeOut(REDRAW_FIELD);
6629 setup_info = getSetupInfoFinal(setup_info_input);
6631 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6633 for (i = 0; setup_info[i].type != 0; i++)
6635 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6636 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6637 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6638 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6639 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6640 initCursor(i, IMG_MENU_BUTTON);
6642 DrawCursorAndText_Setup(i, -1, FALSE);
6645 /* create gadgets for setup input menu screen */
6646 FreeScreenGadgets();
6647 CreateScreenGadgets();
6649 /* map gadgets for setup input menu screen */
6650 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6652 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6654 FadeIn(REDRAW_FIELD);
6657 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6659 if (device_name == NULL)
6662 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6665 if (strlen(device_name) > 1)
6667 char c1 = device_name[strlen(device_name) - 1];
6668 char c2 = device_name[strlen(device_name) - 2];
6670 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6671 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6674 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6675 strlen(device_name));
6678 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6681 static struct SetupKeyboardInfo custom_key;
6688 { &custom_key.left, "Axis/Pad Left" },
6689 { &custom_key.right, "Axis/Pad Right" },
6690 { &custom_key.up, "Axis/Pad Up" },
6691 { &custom_key.down, "Axis/Pad Down" },
6692 { &custom_key.snap, "Button 1/A/X" },
6693 { &custom_key.drop, "Button 2/B/Y" }
6695 static char *joystick_name[MAX_PLAYERS] =
6702 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6703 int font_nr_info = FONT_MENU_1;
6704 int font_nr_name = FONT_VALUE_OLD;
6705 int font_nr_on = FONT_VALUE_1;
6706 int font_nr_off = FONT_VALUE_OLD;
6709 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6711 font_nr_info = FONT_MENU_2;
6712 font_nr_on = FONT_VALUE_NARROW;
6713 font_nr_off = FONT_VALUE_OLD_NARROW;
6716 custom_key = setup.input[player_nr].key;
6718 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6719 FONT_INPUT_1_ACTIVE);
6721 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6723 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6724 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6726 if (setup.input[player_nr].use_joystick)
6728 char *device_name = setup.input[player_nr].joy.device_name;
6729 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6730 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6731 char *text = joystick_name[joystick_nr];
6732 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6734 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6735 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6739 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6740 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6743 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6744 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6748 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6749 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6750 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6751 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6753 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6754 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6755 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6756 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6757 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6758 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6760 for (i = 0; i < 6; i++)
6762 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6764 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6766 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6767 (setup.input[player_nr].use_joystick ?
6769 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6773 static int input_player_nr = 0;
6775 void HandleSetupScreen_Input_Player(int step, int direction)
6777 int old_player_nr = input_player_nr;
6780 new_player_nr = old_player_nr + step * direction;
6781 if (new_player_nr < 0)
6783 if (new_player_nr > MAX_PLAYERS - 1)
6784 new_player_nr = MAX_PLAYERS - 1;
6786 if (new_player_nr != old_player_nr)
6788 input_player_nr = new_player_nr;
6790 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6794 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6796 static int choice = 0;
6799 int pos_start = SETUPINPUT_SCREEN_POS_START;
6800 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6801 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6802 int pos_end = SETUPINPUT_SCREEN_POS_END;
6804 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6808 for (i = 0; setup_info_input[i].type != 0; i++)
6810 /* adjust menu structure according to skipped setup entries */
6811 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6819 if (button == MB_MENU_INITIALIZE)
6821 /* input setup menu may have changed size due to graphics configuration */
6822 if (choice >= pos_empty1)
6825 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6827 DrawCursorAndText_Setup(choice, -1, TRUE);
6831 else if (button == MB_MENU_LEAVE)
6833 setup_mode = SETUP_MODE_MAIN;
6840 if (mx || my) /* mouse input */
6842 x = (mx - mSX) / 32;
6843 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6845 else if (dx || dy) /* keyboard input */
6847 if (dx && choice == 0)
6848 x = (dx < 0 ? 10 : 12);
6849 else if ((dx && choice == 1) ||
6850 (dx == -1 && choice == pos_end))
6851 button = MB_MENU_CHOICE;
6855 if (y >= pos_empty1 && y <= pos_empty2)
6856 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6859 if (y == 0 && dx != 0 && button)
6861 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6863 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6864 y >= pos_start && y <= pos_end &&
6865 !(y >= pos_empty1 && y <= pos_empty2))
6871 DrawCursorAndText_Setup(choice, -1, FALSE);
6872 DrawCursorAndText_Setup(y, -1, TRUE);
6874 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6883 char *device_name = setup.input[input_player_nr].joy.device_name;
6885 if (!setup.input[input_player_nr].use_joystick)
6887 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6889 setJoystickDeviceToNr(device_name, new_device_nr);
6890 setup.input[input_player_nr].use_joystick = TRUE;
6894 int device_nr = getJoystickNrFromDeviceName(device_name);
6895 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6897 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6898 setup.input[input_player_nr].use_joystick = FALSE;
6900 setJoystickDeviceToNr(device_name, new_device_nr);
6903 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6907 if (setup.input[input_player_nr].use_joystick)
6908 ConfigureJoystick(input_player_nr);
6910 CustomizeKeyboard(input_player_nr);
6912 else if (y == pos_end)
6918 setup_mode = SETUP_MODE_MAIN;
6925 static boolean CustomizeKeyboardMain(int player_nr)
6929 boolean finished = FALSE;
6930 static struct SetupKeyboardInfo custom_key;
6935 } customize_step[] =
6937 { &custom_key.left, "Move Left" },
6938 { &custom_key.right, "Move Right" },
6939 { &custom_key.up, "Move Up" },
6940 { &custom_key.down, "Move Down" },
6941 { &custom_key.snap, "Snap Field" },
6942 { &custom_key.drop, "Drop Element" }
6944 int font_nr_old = FONT_VALUE_OLD;
6945 int font_nr_new = FONT_VALUE_1;
6946 boolean success = FALSE;
6948 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6950 font_nr_old = FONT_VALUE_OLD_NARROW;
6951 font_nr_new = FONT_VALUE_NARROW;
6954 /* read existing key bindings from player setup */
6955 custom_key = setup.input[player_nr].key;
6958 FadeOut(REDRAW_FIELD);
6962 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6965 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6966 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6967 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6968 "Key:", FONT_INPUT_1_ACTIVE);
6969 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6970 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
6972 FadeIn(REDRAW_FIELD);
6978 if (NextValidEvent(&event))
6982 case EVENT_KEYPRESS:
6984 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6986 /* press 'Escape' to abort and keep the old key bindings */
6987 if (key == KSYM_Escape)
6989 FadeSkipNextFadeIn();
6996 /* press 'Enter' to keep the existing key binding */
6997 if (key == KSYM_Return)
6998 key = *customize_step[step_nr].key;
7000 /* check if key already used */
7001 for (i = 0; i < step_nr; i++)
7002 if (*customize_step[i].key == key)
7007 /* got new key binding */
7008 *customize_step[step_nr].key = key;
7009 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7011 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7012 getKeyNameFromKey(key), font_nr_new);
7015 /* un-highlight last query */
7016 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7017 customize_step[step_nr - 1].text, FONT_MENU_1);
7018 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7019 "Key:", FONT_MENU_1);
7021 /* all keys configured */
7030 /* query next key binding */
7031 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7032 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7033 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7034 "Key:", FONT_INPUT_1_ACTIVE);
7035 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7036 getKeyNameFromKey(*customize_step[step_nr].key),
7041 case EVENT_KEYRELEASE:
7042 key_joystick_mapping = 0;
7046 HandleOtherEvents(&event);
7054 /* write new key bindings back to player setup, if successfully finished */
7056 setup.input[player_nr].key = custom_key;
7061 void CustomizeKeyboard(int player_nr)
7063 boolean success = CustomizeKeyboardMain(player_nr);
7067 int font_nr = FONT_TITLE_1;
7068 int font_height = getFontHeight(font_nr);
7069 int ypos1 = SYSIZE / 2 - font_height * 2;
7070 int ypos2 = SYSIZE / 2 - font_height * 1;
7071 unsigned int wait_frame_delay = 0;
7072 unsigned int wait_frame_delay_value = 2000;
7074 ResetDelayCounter(&wait_frame_delay);
7078 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7079 DrawTextSCentered(ypos2, font_nr, "configured!");
7081 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7087 DrawSetupScreen_Input();
7090 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7092 #define MARKER_BUTTON 1
7093 #define MARKER_AXIS_X 2
7094 #define MARKER_AXIS_Y 3
7096 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7098 #if defined(TARGET_SDL2)
7099 static boolean bitmaps_initialized = FALSE;
7100 boolean screen_initialized = FALSE;
7101 static Bitmap *controller, *button, *axis_x, *axis_y;
7103 boolean success = TRUE;
7104 boolean done = FALSE, next = FALSE;
7106 int alpha = 200, alpha_step = -1;
7107 int alpha_ticks = 0;
7108 char mapping[4096], temp[4096];
7109 int font_name = MENU_SETUP_FONT_TITLE;
7110 int font_info = MENU_SETUP_FONT_TEXT;
7111 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7112 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7113 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7114 int ystep_name = getMenuTextStep(spacing_name, font_name);
7115 int ystep_line = getMenuTextStep(spacing_line, font_info);
7116 int ystep_para = getMenuTextStep(spacing_para, font_info);
7124 int axis, button, hat, hat_value;
7127 *step, *prev_step, steps[] =
7129 { 356, 155, MARKER_BUTTON, "a", },
7130 { 396, 122, MARKER_BUTTON, "b", },
7131 { 320, 125, MARKER_BUTTON, "x", },
7132 { 358, 95, MARKER_BUTTON, "y", },
7133 { 162, 125, MARKER_BUTTON, "back", },
7134 { 216, 125, MARKER_BUTTON, "guide", },
7135 { 271, 125, MARKER_BUTTON, "start", },
7136 { 110, 200, MARKER_BUTTON, "dpleft", },
7137 { 146, 228, MARKER_BUTTON, "dpdown", },
7138 { 178, 200, MARKER_BUTTON, "dpright", },
7139 { 146, 172, MARKER_BUTTON, "dpup", },
7140 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7141 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7142 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7143 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7144 { 73, 141, MARKER_BUTTON, "leftstick", },
7145 { 282, 210, MARKER_BUTTON, "rightstick", },
7146 { 73, 141, MARKER_AXIS_X, "leftx", },
7147 { 73, 141, MARKER_AXIS_Y, "lefty", },
7148 { 282, 210, MARKER_AXIS_X, "rightx", },
7149 { 282, 210, MARKER_AXIS_Y, "righty", },
7152 unsigned int event_frame_delay = 0;
7153 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7155 ResetDelayCounter(&event_frame_delay);
7157 if (!bitmaps_initialized)
7159 controller = LoadCustomImage("joystick/controller.png");
7160 button = LoadCustomImage("joystick/button.png");
7161 axis_x = LoadCustomImage("joystick/axis_x.png");
7162 axis_y = LoadCustomImage("joystick/axis_y.png");
7164 bitmaps_initialized = TRUE;
7167 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7170 /* print info about the joystick we are watching */
7171 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7172 SDL_JoystickInstanceID(joystick), name);
7173 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7174 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7175 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7178 /* initialize mapping with GUID and name */
7179 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7181 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7182 temp, name, SDL_GetPlatform());
7184 /* loop through all steps (buttons and axes), getting joystick events */
7185 for (i = 0; i < SDL_arraysize(steps) && !done;)
7187 Bitmap *marker = button; /* initialize with reliable default value */
7190 strcpy(step->mapping, mapping);
7194 step->hat_value = -1;
7196 marker = (step->marker == MARKER_BUTTON ? button :
7197 step->marker == MARKER_AXIS_X ? axis_x :
7198 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7202 while (!done && !next)
7204 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7205 alpha_ticks = SDL_GetTicks();
7212 else if (alpha < 128)
7218 int controller_x = SX + (SXSIZE - controller->width) / 2;
7219 int controller_y = SY + ystep_line;
7221 int marker_x = controller_x + step->x;
7222 int marker_y = controller_y + step->y;
7224 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7225 int ystart2 = ystart1 + ystep_name + ystep_line;
7229 DrawTextSCentered(ystart1, font_name, name);
7231 DrawTextSCentered(ystart2, font_info,
7232 "Press buttons and move axes on");
7233 ystart2 += ystep_line;
7234 DrawTextSCentered(ystart2, font_info,
7235 "your controller when indicated.");
7236 ystart2 += ystep_line;
7237 DrawTextSCentered(ystart2, font_info,
7238 "(Your controller may look different.)");
7239 ystart2 += ystep_para;
7241 #if defined(PLATFORM_ANDROID)
7242 DrawTextSCentered(ystart2, font_info,
7243 "To correct a mistake,");
7244 ystart2 += ystep_line;
7245 DrawTextSCentered(ystart2, font_info,
7246 "press the 'back' button.");
7247 ystart2 += ystep_line;
7248 DrawTextSCentered(ystart2, font_info,
7249 "To skip a button or axis,");
7250 ystart2 += ystep_line;
7251 DrawTextSCentered(ystart2, font_info,
7252 "press the 'menu' button.");
7254 DrawTextSCentered(ystart2, font_info,
7255 "To correct a mistake,");
7256 ystart2 += ystep_line;
7257 DrawTextSCentered(ystart2, font_info,
7258 "press the 'backspace' key.");
7259 ystart2 += ystep_line;
7260 DrawTextSCentered(ystart2, font_info,
7261 "To skip a button or axis,");
7262 ystart2 += ystep_line;
7263 DrawTextSCentered(ystart2, font_info,
7264 "press the 'return' key.");
7265 ystart2 += ystep_line;
7266 DrawTextSCentered(ystart2, font_info,
7267 "To exit, press the 'escape' key.");
7270 BlitBitmapMasked(controller, drawto, 0, 0,
7271 controller->width, controller->height,
7272 controller_x, controller_y);
7274 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7275 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7277 BlitBitmapMasked(marker, drawto, 0, 0,
7278 marker->width, marker->height,
7279 marker_x, marker_y);
7281 if (!screen_initialized)
7282 FadeIn(REDRAW_FIELD);
7286 screen_initialized = TRUE;
7288 while (NextValidEvent(&event))
7292 case SDL_JOYAXISMOTION:
7293 if (event.jaxis.value > 20000 ||
7294 event.jaxis.value < -20000)
7296 for (j = 0; j < i; j++)
7297 if (steps[j].axis == event.jaxis.axis)
7302 if (step->marker != MARKER_AXIS_X &&
7303 step->marker != MARKER_AXIS_Y)
7306 step->axis = event.jaxis.axis;
7307 strcat(mapping, step->field);
7308 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7309 strcat(mapping, temp);
7317 case SDL_JOYHATMOTION:
7318 /* ignore centering; we're probably just coming back
7319 to the center from the previous item we set */
7320 if (event.jhat.value == SDL_HAT_CENTERED)
7323 for (j = 0; j < i; j++)
7324 if (steps[j].hat == event.jhat.hat &&
7325 steps[j].hat_value == event.jhat.value)
7330 step->hat = event.jhat.hat;
7331 step->hat_value = event.jhat.value;
7332 strcat(mapping, step->field);
7333 snprintf(temp, sizeof(temp), ":h%u.%u,",
7334 event.jhat.hat, event.jhat.value );
7335 strcat(mapping, temp);
7342 case SDL_JOYBALLMOTION:
7345 case SDL_JOYBUTTONUP:
7346 for (j = 0; j < i; j++)
7347 if (steps[j].button == event.jbutton.button)
7352 step->button = event.jbutton.button;
7353 strcat(mapping, step->field);
7354 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7355 strcat(mapping, temp);
7362 case SDL_FINGERDOWN:
7363 case SDL_MOUSEBUTTONDOWN:
7364 /* skip this step */
7371 if (event.key.keysym.sym == KSYM_BackSpace ||
7372 event.key.keysym.sym == KSYM_Back)
7383 /* undo this step */
7384 prev_step = &steps[i - 1];
7385 strcpy(mapping, prev_step->mapping);
7392 if (event.key.keysym.sym == KSYM_space ||
7393 event.key.keysym.sym == KSYM_Return ||
7394 event.key.keysym.sym == KSYM_Menu)
7396 /* skip this step */
7403 if (event.key.keysym.sym == KSYM_Escape)
7413 program.exit_function(0);
7420 // do not handle events for longer than standard frame delay period
7421 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7430 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7433 // activate mapping for this game
7434 SDL_GameControllerAddMapping(mapping);
7436 // save mapping to personal mappings
7437 SaveSetup_AddGameControllerMapping(mapping);
7440 /* wait until the last pending event was removed from event queue */
7441 while (NextValidEvent(&event));
7449 static int ConfigureJoystickMain(int player_nr)
7451 char *device_name = setup.input[player_nr].joy.device_name;
7452 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7453 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7454 int success = FALSE;
7457 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7458 return JOYSTICK_NOT_AVAILABLE;
7460 if (!joystick_active || !setup.input[player_nr].use_joystick)
7461 return JOYSTICK_NOT_AVAILABLE;
7464 FadeOut(REDRAW_FIELD);
7466 // close all joystick devices (potentially opened as game controllers)
7467 for (i = 0; i < SDL_NumJoysticks(); i++)
7468 SDLCloseJoystick(i);
7470 // open joystick device as plain joystick to configure as game controller
7471 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7473 // as the joystick was successfully opened before, this should not happen
7474 if (joystick == NULL)
7477 // create new game controller mapping (buttons and axes) for joystick device
7478 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7480 // close joystick (and maybe re-open as configured game controller later)
7481 SDL_JoystickClose(joystick);
7483 // re-open all joystick devices (potentially as game controllers)
7484 for (i = 0; i < SDL_NumJoysticks(); i++)
7487 // clear all joystick input actions for all joystick devices
7488 SDLClearJoystickState();
7490 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7493 void ConfigureJoystick(int player_nr)
7495 boolean state = ConfigureJoystickMain(player_nr);
7497 if (state != JOYSTICK_NOT_CONFIGURED)
7499 boolean success = (state == JOYSTICK_CONFIGURED);
7500 char message1[MAX_OUTPUT_LINESIZE + 1];
7501 char *message2 = (success ? "configured!" : "not available!");
7502 char *device_name = setup.input[player_nr].joy.device_name;
7503 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7504 int font_nr = FONT_TITLE_1;
7505 int font_height = getFontHeight(font_nr);
7506 int ypos1 = SYSIZE / 2 - font_height * 2;
7507 int ypos2 = SYSIZE / 2 - font_height * 1;
7508 unsigned int wait_frame_delay = 0;
7509 unsigned int wait_frame_delay_value = 2000;
7511 ResetDelayCounter(&wait_frame_delay);
7515 sprintf(message1, "Joystick %d", nr);
7517 DrawTextSCentered(ypos1, font_nr, message1);
7518 DrawTextSCentered(ypos2, font_nr, message2);
7520 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7526 DrawSetupScreen_Input();
7529 boolean ConfigureVirtualButtonsMain()
7531 static char *customize_step_text[] =
7540 char grid_button[] =
7542 CHAR_GRID_BUTTON_LEFT,
7543 CHAR_GRID_BUTTON_RIGHT,
7544 CHAR_GRID_BUTTON_UP,
7545 CHAR_GRID_BUTTON_DOWN,
7546 CHAR_GRID_BUTTON_SNAP,
7547 CHAR_GRID_BUTTON_DROP
7549 int font_nr = FONT_INPUT_1_ACTIVE;
7550 int font_height = getFontHeight(font_nr);
7551 int ypos1 = SYSIZE / 2 - font_height * 2;
7552 int ypos2 = SYSIZE / 2 - font_height * 1;
7553 boolean success = FALSE;
7554 boolean finished = FALSE;
7556 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7557 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7558 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7559 boolean set_grid_button = FALSE;
7560 int nr = GRID_ACTIVE_NR();
7563 for (x = 0; x < MAX_GRID_XSIZE; x++)
7564 for (y = 0; y < MAX_GRID_YSIZE; y++)
7565 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7567 overlay.grid_button_highlight = grid_button[step_nr];
7570 FadeOut(REDRAW_FIELD);
7574 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7575 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7576 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7578 FadeIn(REDRAW_FIELD);
7580 SetOverlayShowGrid(TRUE);
7586 while (NextValidEvent(&event))
7590 case EVENT_KEYPRESS:
7592 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7594 /* press 'Escape' to abort and keep the old key bindings */
7595 if (key == KSYM_Escape)
7597 for (x = 0; x < MAX_GRID_XSIZE; x++)
7598 for (y = 0; y < MAX_GRID_YSIZE; y++)
7599 overlay.grid_button[x][y] = grid_button_old[x][y];
7601 FadeSkipNextFadeIn();
7608 /* press 'Enter' to keep the existing key binding */
7609 if (key == KSYM_Return ||
7610 #if defined(TARGET_SDL2)
7617 else if (key == KSYM_BackSpace
7618 #if defined(TARGET_SDL2)
7626 FadeSkipNextFadeIn();
7640 /* all virtual buttons configured */
7649 for (x = 0; x < MAX_GRID_XSIZE; x++)
7650 for (y = 0; y < MAX_GRID_YSIZE; y++)
7651 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7653 overlay.grid_button_highlight = grid_button[step_nr];
7655 /* query next virtual button */
7659 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7660 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7661 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7665 case EVENT_KEYRELEASE:
7666 key_joystick_mapping = 0;
7669 case EVENT_BUTTONPRESS:
7670 case EVENT_BUTTONRELEASE:
7672 ButtonEvent *button = (ButtonEvent *)&event;
7674 button->x += video.screen_xoffset;
7675 button->y += video.screen_yoffset;
7677 x = button->x * overlay.grid_xsize / video.screen_width;
7678 y = button->y * overlay.grid_ysize / video.screen_height;
7680 if (button->type == EVENT_BUTTONPRESS)
7682 button_status = button->button;
7685 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7686 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7688 set_grid_button = TRUE;
7692 button_status = MB_RELEASED;
7697 case EVENT_MOTIONNOTIFY:
7699 MotionEvent *motion = (MotionEvent *)&event;
7701 motion->x += video.screen_xoffset;
7702 motion->y += video.screen_yoffset;
7704 x = motion->x * overlay.grid_xsize / video.screen_width;
7705 y = motion->y * overlay.grid_ysize / video.screen_height;
7707 set_grid_button = TRUE;
7711 #if defined(TARGET_SDL2)
7712 case SDL_WINDOWEVENT:
7713 HandleWindowEvent((WindowEvent *) &event);
7715 // check if device has been rotated
7716 if (nr != GRID_ACTIVE_NR())
7718 nr = GRID_ACTIVE_NR();
7720 for (x = 0; x < MAX_GRID_XSIZE; x++)
7721 for (y = 0; y < MAX_GRID_YSIZE; y++)
7722 grid_button_old[x][y] = grid_button_tmp[x][y] =
7723 overlay.grid_button[x][y];
7728 case SDL_APP_WILLENTERBACKGROUND:
7729 case SDL_APP_DIDENTERBACKGROUND:
7730 case SDL_APP_WILLENTERFOREGROUND:
7731 case SDL_APP_DIDENTERFOREGROUND:
7732 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7737 HandleOtherEvents(&event);
7741 if (set_grid_button)
7743 overlay.grid_button[x][y] =
7744 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7745 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7746 grid_button_tmp[x][y]);
7748 set_grid_button = FALSE;
7755 for (x = 0; x < MAX_GRID_XSIZE; x++)
7756 for (y = 0; y < MAX_GRID_YSIZE; y++)
7757 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7759 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7761 SetOverlayShowGrid(FALSE);
7766 void ConfigureVirtualButtons()
7768 boolean success = ConfigureVirtualButtonsMain();
7772 int font_nr = FONT_TITLE_1;
7773 int font_height = getFontHeight(font_nr);
7774 int ypos1 = SYSIZE / 2 - font_height * 2;
7775 int ypos2 = SYSIZE / 2 - font_height * 1;
7776 unsigned int wait_frame_delay = 0;
7777 unsigned int wait_frame_delay_value = 2000;
7779 ResetDelayCounter(&wait_frame_delay);
7783 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7784 DrawTextSCentered(ypos2, font_nr, "configured!");
7786 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7793 void DrawSetupScreen()
7795 if (setup_mode == SETUP_MODE_INPUT)
7796 DrawSetupScreen_Input();
7797 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7798 DrawChooseTree(&game_speed_current);
7799 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7800 DrawChooseTree(&scroll_delay_current);
7801 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7802 DrawChooseTree(&snapshot_mode_current);
7803 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7804 DrawChooseTree(&window_size_current);
7805 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7806 DrawChooseTree(&scaling_type_current);
7807 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7808 DrawChooseTree(&rendering_mode_current);
7809 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7810 DrawChooseTree(&artwork.gfx_current);
7811 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7812 DrawChooseTree(&artwork.snd_current);
7813 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7814 DrawChooseTree(&artwork.mus_current);
7815 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7816 DrawChooseTree(&volume_simple_current);
7817 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7818 DrawChooseTree(&volume_loops_current);
7819 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7820 DrawChooseTree(&volume_music_current);
7821 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7822 DrawChooseTree(&touch_control_current);
7823 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7824 DrawChooseTree(&move_distance_current);
7825 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7826 DrawChooseTree(&drop_distance_current);
7827 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7828 DrawChooseTree(&transparency_current);
7829 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7830 DrawChooseTree(&grid_size_current[0][0]);
7831 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7832 DrawChooseTree(&grid_size_current[0][1]);
7833 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7834 DrawChooseTree(&grid_size_current[1][0]);
7835 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7836 DrawChooseTree(&grid_size_current[1][1]);
7838 DrawSetupScreen_Generic();
7840 PlayMenuSoundsAndMusic();
7843 void RedrawSetupScreenAfterFullscreenToggle()
7845 if (setup_mode == SETUP_MODE_GRAPHICS ||
7846 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7848 // update list selection from "setup.window_scaling_percent"
7849 execSetupGraphics_setWindowSizes(TRUE);
7855 void RedrawSetupScreenAfterScreenRotation(int nr)
7859 if (setup_mode == SETUP_MODE_TOUCH)
7861 // update virtual button settings (depending on screen orientation)
7864 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
7866 // save already configured virtual buttons
7867 for (x = 0; x < MAX_GRID_XSIZE; x++)
7868 for (y = 0; y < MAX_GRID_YSIZE; y++)
7869 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7873 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7875 if (setup_mode == SETUP_MODE_INPUT)
7876 HandleSetupScreen_Input(mx, my, dx, dy, button);
7877 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7878 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7879 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7880 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7881 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7882 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7883 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7884 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7885 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7886 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7887 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7888 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7889 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7890 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7891 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7892 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7893 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7894 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7895 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7896 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7897 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7898 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7899 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7900 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7901 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7902 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7903 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7904 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7905 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7906 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7907 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7908 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
7909 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7910 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
7911 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7912 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
7913 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7914 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
7915 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7916 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
7918 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7921 void HandleGameActions()
7923 if (game.restart_game_message != NULL)
7924 RequestRestartGame(game.restart_game_message);
7926 if (game_status != GAME_MODE_PLAYING)
7929 GameActions(); /* main game loop */
7931 if (tape.auto_play && !tape.playing)
7932 AutoPlayTape(); /* continue automatically playing next tape */
7936 /* ---------- new screen button stuff -------------------------------------- */
7938 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7942 case SCREEN_CTRL_ID_PREV_LEVEL:
7943 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7944 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7947 case SCREEN_CTRL_ID_NEXT_LEVEL:
7948 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7949 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7952 case SCREEN_CTRL_ID_PREV_PLAYER:
7953 *x = mSX + TILEX * 10;
7954 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7957 case SCREEN_CTRL_ID_NEXT_PLAYER:
7958 *x = mSX + TILEX * 12;
7959 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7962 case SCREEN_CTRL_ID_INSERT_SOLUTION:
7963 *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x);
7964 *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y);
7967 case SCREEN_CTRL_ID_PLAY_SOLUTION:
7968 *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x);
7969 *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y);
7973 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7979 int gfx_unpressed, gfx_pressed;
7980 void (*get_gadget_position)(int *, int *, int);
7984 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7987 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7988 getScreenMenuButtonPos,
7989 SCREEN_CTRL_ID_PREV_LEVEL,
7994 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7995 getScreenMenuButtonPos,
7996 SCREEN_CTRL_ID_NEXT_LEVEL,
8001 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8002 getScreenMenuButtonPos,
8003 SCREEN_CTRL_ID_PREV_PLAYER,
8008 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8009 getScreenMenuButtonPos,
8010 SCREEN_CTRL_ID_NEXT_PLAYER,
8015 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8016 getScreenMenuButtonPos,
8017 SCREEN_CTRL_ID_INSERT_SOLUTION,
8018 SCREEN_MASK_MAIN_HAS_SOLUTION,
8019 "insert solution tape"
8022 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8023 getScreenMenuButtonPos,
8024 SCREEN_CTRL_ID_PLAY_SOLUTION,
8025 SCREEN_MASK_MAIN_HAS_SOLUTION,
8026 "play solution tape"
8032 int gfx_unpressed, gfx_pressed;
8036 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8039 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8040 -1, -1, /* these values are not constant, but can change at runtime */
8041 SCREEN_CTRL_ID_SCROLL_UP,
8045 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8046 -1, -1, /* these values are not constant, but can change at runtime */
8047 SCREEN_CTRL_ID_SCROLL_DOWN,
8054 int gfx_unpressed, gfx_pressed;
8060 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8063 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8064 -1, -1, /* these values are not constant, but can change at runtime */
8065 -1, -1, /* these values are not constant, but can change at runtime */
8066 GD_TYPE_SCROLLBAR_VERTICAL,
8067 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8068 "scroll level series vertically"
8072 static void CreateScreenMenubuttons()
8074 struct GadgetInfo *gi;
8075 unsigned int event_mask;
8078 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8080 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8081 int gfx_unpressed, gfx_pressed;
8082 int x, y, width, height;
8083 int gd_x1, gd_x2, gd_y1, gd_y2;
8084 int id = menubutton_info[i].gadget_id;
8086 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8087 event_mask = GD_EVENT_RELEASED;
8089 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8091 menubutton_info[i].get_gadget_position(&x, &y, id);
8093 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8095 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8096 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8100 width = SC_MENUBUTTON_XSIZE;
8101 height = SC_MENUBUTTON_YSIZE;
8104 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8105 gfx_pressed = menubutton_info[i].gfx_pressed;
8106 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8107 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8108 gd_x1 = graphic_info[gfx_unpressed].src_x;
8109 gd_y1 = graphic_info[gfx_unpressed].src_y;
8110 gd_x2 = graphic_info[gfx_pressed].src_x;
8111 gd_y2 = graphic_info[gfx_pressed].src_y;
8113 gi = CreateGadget(GDI_CUSTOM_ID, id,
8114 GDI_CUSTOM_TYPE_ID, i,
8115 GDI_IMAGE_ID, gfx_unpressed,
8116 GDI_INFO_TEXT, menubutton_info[i].infotext,
8121 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8122 GDI_STATE, GD_BUTTON_UNPRESSED,
8123 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8124 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8125 GDI_DIRECT_DRAW, FALSE,
8126 GDI_EVENT_MASK, event_mask,
8127 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8131 Error(ERR_EXIT, "cannot create gadget");
8133 screen_gadget[id] = gi;
8137 static void CreateScreenScrollbuttons()
8139 struct GadgetInfo *gi;
8140 unsigned int event_mask;
8143 /* these values are not constant, but can change at runtime */
8144 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8145 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8146 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8147 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8149 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8151 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8152 int gfx_unpressed, gfx_pressed;
8153 int x, y, width, height;
8154 int gd_x1, gd_x2, gd_y1, gd_y2;
8155 int id = scrollbutton_info[i].gadget_id;
8157 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8159 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8160 y = mSY + scrollbutton_info[i].y;
8161 width = SC_SCROLLBUTTON_XSIZE;
8162 height = SC_SCROLLBUTTON_YSIZE;
8164 /* correct scrollbar position if placed outside menu (playfield) area */
8165 if (x > SX + SC_SCROLL_UP_XPOS)
8166 x = SX + SC_SCROLL_UP_XPOS;
8168 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8169 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8170 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8172 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8173 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8174 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8175 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8176 gd_x1 = graphic_info[gfx_unpressed].src_x;
8177 gd_y1 = graphic_info[gfx_unpressed].src_y;
8178 gd_x2 = graphic_info[gfx_pressed].src_x;
8179 gd_y2 = graphic_info[gfx_pressed].src_y;
8181 gi = CreateGadget(GDI_CUSTOM_ID, id,
8182 GDI_CUSTOM_TYPE_ID, i,
8183 GDI_IMAGE_ID, gfx_unpressed,
8184 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8189 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8190 GDI_STATE, GD_BUTTON_UNPRESSED,
8191 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8192 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8193 GDI_DIRECT_DRAW, FALSE,
8194 GDI_EVENT_MASK, event_mask,
8195 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8199 Error(ERR_EXIT, "cannot create gadget");
8201 screen_gadget[id] = gi;
8205 static void CreateScreenScrollbars()
8209 /* these values are not constant, but can change at runtime */
8210 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8211 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8212 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8213 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8215 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8217 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8218 int gfx_unpressed, gfx_pressed;
8219 int x, y, width, height;
8220 int gd_x1, gd_x2, gd_y1, gd_y2;
8221 struct GadgetInfo *gi;
8222 int items_max, items_visible, item_position;
8223 unsigned int event_mask;
8224 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8225 int id = scrollbar_info[i].gadget_id;
8227 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8229 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8230 y = mSY + scrollbar_info[i].y;
8231 width = scrollbar_info[i].width;
8232 height = scrollbar_info[i].height;
8234 /* correct scrollbar position if placed outside menu (playfield) area */
8235 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8236 x = SX + SC_SCROLL_VERTICAL_XPOS;
8238 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8239 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8241 items_max = num_page_entries;
8242 items_visible = num_page_entries;
8245 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8246 gfx_pressed = scrollbar_info[i].gfx_pressed;
8247 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8248 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8249 gd_x1 = graphic_info[gfx_unpressed].src_x;
8250 gd_y1 = graphic_info[gfx_unpressed].src_y;
8251 gd_x2 = graphic_info[gfx_pressed].src_x;
8252 gd_y2 = graphic_info[gfx_pressed].src_y;
8254 gi = CreateGadget(GDI_CUSTOM_ID, id,
8255 GDI_CUSTOM_TYPE_ID, i,
8256 GDI_IMAGE_ID, gfx_unpressed,
8257 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8262 GDI_TYPE, scrollbar_info[i].type,
8263 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8264 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8265 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8266 GDI_WHEEL_AREA_X, SX,
8267 GDI_WHEEL_AREA_Y, SY,
8268 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8269 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8270 GDI_STATE, GD_BUTTON_UNPRESSED,
8271 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8272 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8273 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8274 GDI_DIRECT_DRAW, FALSE,
8275 GDI_EVENT_MASK, event_mask,
8276 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8280 Error(ERR_EXIT, "cannot create gadget");
8282 screen_gadget[id] = gi;
8286 void CreateScreenGadgets()
8288 CreateScreenMenubuttons();
8290 CreateScreenScrollbuttons();
8291 CreateScreenScrollbars();
8294 void FreeScreenGadgets()
8298 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8299 FreeGadget(screen_gadget[i]);
8302 void MapScreenMenuGadgets(int screen_mask)
8306 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8307 if (screen_mask & menubutton_info[i].screen_mask)
8308 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8311 void UnmapScreenMenuGadgets(int screen_mask)
8315 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8317 if (screen_mask & menubutton_info[i].screen_mask)
8319 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8321 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8322 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8323 screen_gadget[menubutton_info[i].gadget_id]->y,
8324 screen_gadget[menubutton_info[i].gadget_id]->width,
8325 screen_gadget[menubutton_info[i].gadget_id]->height);
8330 void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8333 MapScreenMenuGadgets(screen_mask);
8335 UnmapScreenMenuGadgets(screen_mask);
8338 void MapScreenGadgets(int num_entries)
8342 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8345 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8346 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8348 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8349 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8352 void MapScreenTreeGadgets(TreeInfo *ti)
8354 MapScreenGadgets(numTreeInfoInGroup(ti));
8357 static void HandleScreenGadgets(struct GadgetInfo *gi)
8359 int id = gi->custom_id;
8360 int button = gi->event.button;
8361 int step = (button == MB_LEFTBUTTON ? 1 :
8362 button == MB_MIDDLEBUTTON ? 5 :
8363 button == MB_RIGHTBUTTON ? 10 : 1);
8367 case SCREEN_CTRL_ID_PREV_LEVEL:
8368 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8371 case SCREEN_CTRL_ID_NEXT_LEVEL:
8372 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8375 case SCREEN_CTRL_ID_PREV_PLAYER:
8376 HandleSetupScreen_Input_Player(step, -1);
8379 case SCREEN_CTRL_ID_NEXT_PLAYER:
8380 HandleSetupScreen_Input_Player(step, +1);
8383 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8384 InsertSolutionTape();
8387 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8391 case SCREEN_CTRL_ID_SCROLL_UP:
8392 if (game_status == GAME_MODE_LEVELS)
8393 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8394 else if (game_status == GAME_MODE_LEVELNR)
8395 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8396 else if (game_status == GAME_MODE_SETUP)
8397 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8398 else if (game_status == GAME_MODE_INFO)
8399 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8402 case SCREEN_CTRL_ID_SCROLL_DOWN:
8403 if (game_status == GAME_MODE_LEVELS)
8404 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8405 else if (game_status == GAME_MODE_LEVELNR)
8406 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8407 else if (game_status == GAME_MODE_SETUP)
8408 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8409 else if (game_status == GAME_MODE_INFO)
8410 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8413 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8414 if (game_status == GAME_MODE_LEVELS)
8415 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8416 else if (game_status == GAME_MODE_LEVELNR)
8417 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8418 else if (game_status == GAME_MODE_SETUP)
8419 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8420 else if (game_status == GAME_MODE_INFO)
8421 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8429 void DumpScreenIdentifiers()
8433 Print("Active screen elements on current screen:\n");
8435 for (i = 0; main_controls[i].nr != -1; i++)
8437 struct MainControlInfo *mci = &main_controls[i];
8439 if (mci->button_graphic != -1)
8441 char *token = getTokenFromImageID(mci->button_graphic);
8443 Print("- '%s'\n", token);
8450 boolean DoScreenAction(int image_id)
8454 if (game_status != GAME_MODE_MAIN)
8457 for (i = 0; main_controls[i].nr != -1; i++)
8459 struct MainControlInfo *mci = &main_controls[i];
8460 struct MenuPosInfo *pos = mci->pos_button;
8462 if (mci->button_graphic == image_id)
8464 int x = mSX + pos->x;
8465 int y = mSY + pos->y;
8467 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);