1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
27 #define DEBUG_JOYSTICKS 0
30 /* screens on the info screen */
31 #define INFO_MODE_MAIN 0
32 #define INFO_MODE_TITLE 1
33 #define INFO_MODE_ELEMENTS 2
34 #define INFO_MODE_MUSIC 3
35 #define INFO_MODE_CREDITS 4
36 #define INFO_MODE_PROGRAM 5
37 #define INFO_MODE_VERSION 6
38 #define INFO_MODE_LEVELSET 7
40 #define MAX_INFO_MODES 8
42 /* screens on the setup screen */
43 /* (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h) */
44 /* (should also match corresponding entries in src/conf_gfx.c) */
45 #define SETUP_MODE_MAIN 0
46 #define SETUP_MODE_GAME 1
47 #define SETUP_MODE_EDITOR 2
48 #define SETUP_MODE_GRAPHICS 3
49 #define SETUP_MODE_SOUND 4
50 #define SETUP_MODE_ARTWORK 5
51 #define SETUP_MODE_INPUT 6
52 #define SETUP_MODE_TOUCH 7
53 #define SETUP_MODE_SHORTCUTS 8
54 #define SETUP_MODE_SHORTCUTS_1 9
55 #define SETUP_MODE_SHORTCUTS_2 10
56 #define SETUP_MODE_SHORTCUTS_3 11
57 #define SETUP_MODE_SHORTCUTS_4 12
58 #define SETUP_MODE_SHORTCUTS_5 13
60 /* sub-screens on the setup screen (generic) */
61 #define SETUP_MODE_CHOOSE_ARTWORK 14
62 #define SETUP_MODE_CHOOSE_OTHER 15
64 /* sub-screens on the setup screen (specific) */
65 #define SETUP_MODE_CHOOSE_GAME_SPEED 16
66 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
67 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 18
68 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 19
69 #define SETUP_MODE_CHOOSE_SCALING_TYPE 20
70 #define SETUP_MODE_CHOOSE_RENDERING 21
71 #define SETUP_MODE_CHOOSE_GRAPHICS 22
72 #define SETUP_MODE_CHOOSE_SOUNDS 23
73 #define SETUP_MODE_CHOOSE_MUSIC 24
74 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 25
75 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 26
76 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 27
77 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 28
78 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 29
79 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 30
80 #define SETUP_MODE_CHOOSE_TRANSPARENCY 31
81 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 32
82 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 35
85 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 36
87 #define MAX_SETUP_MODES 37
89 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
91 /* setup screen titles */
92 #define STR_SETUP_MAIN "Setup"
93 #define STR_SETUP_GAME "Game & Menu"
94 #define STR_SETUP_EDITOR "Editor"
95 #define STR_SETUP_GRAPHICS "Graphics"
96 #define STR_SETUP_SOUND "Sound & Music"
97 #define STR_SETUP_ARTWORK "Custom Artwork"
98 #define STR_SETUP_INPUT "Input Devices"
99 #define STR_SETUP_TOUCH "Touch Controls"
100 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
101 #define STR_SETUP_EXIT "Exit"
102 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
104 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
105 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
106 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
107 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
108 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
109 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
110 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
111 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
112 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
113 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
114 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
115 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
116 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
117 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
118 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
119 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
120 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
122 /* for input setup functions */
123 #define SETUPINPUT_SCREEN_POS_START 0
124 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
125 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
126 #define SETUPINPUT_SCREEN_POS_END 13
128 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
129 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
131 /* for various menu stuff */
132 #define MENU_SCREEN_START_XPOS 1
133 #define MENU_SCREEN_START_YPOS 2
134 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
135 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
136 #define MENU_TITLE1_YPOS 8
137 #define MENU_TITLE2_YPOS 46
138 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
139 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
140 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
141 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
142 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
143 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
144 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
145 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
146 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
147 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
148 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
149 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
150 MENU_INFO_FONT_TITLE))
151 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
152 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
153 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
154 MENU_SCREEN_INFO_YSTART2 - \
156 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
157 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
158 MENU_SCREEN_INFO_YSTEP)
159 #define NUM_INFO_ELEMENTS_FROM_CONF \
160 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
161 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
162 MAX_MENU_ENTRIES_ON_SCREEN)
163 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
164 MAX_INFO_ELEMENTS_ON_SCREEN), \
165 NUM_INFO_ELEMENTS_FROM_CONF)
166 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
167 #define MAX_MENU_TEXT_LENGTH_BIG 13
168 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
170 /* buttons and scrollbars identifiers */
171 #define SCREEN_CTRL_ID_PREV_LEVEL 0
172 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
173 #define SCREEN_CTRL_ID_PREV_PLAYER 2
174 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
175 #define SCREEN_CTRL_ID_INSERT_SOLUTION 4
176 #define SCREEN_CTRL_ID_PLAY_SOLUTION 5
177 #define SCREEN_CTRL_ID_SCROLL_UP 6
178 #define SCREEN_CTRL_ID_SCROLL_DOWN 7
179 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 8
181 #define NUM_SCREEN_GADGETS 9
183 #define NUM_SCREEN_MENUBUTTONS 6
184 #define NUM_SCREEN_SCROLLBUTTONS 2
185 #define NUM_SCREEN_SCROLLBARS 1
187 #define SCREEN_MASK_MAIN (1 << 0)
188 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
189 #define SCREEN_MASK_INPUT (1 << 2)
191 /* graphic position and size values for buttons and scrollbars */
192 #define SC_MENUBUTTON_XSIZE TILEX
193 #define SC_MENUBUTTON_YSIZE TILEY
195 #define SC_SCROLLBUTTON_XSIZE TILEX
196 #define SC_SCROLLBUTTON_YSIZE TILEY
198 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
200 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
201 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
202 SC_SCROLLBUTTON_YSIZE)
204 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
205 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
207 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
208 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
209 SC_SCROLLBUTTON_YSIZE)
211 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
212 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
213 SC_SCROLL_VERTICAL_YSIZE)
215 #define SC_BORDER_SIZE 14
218 /* forward declarations of internal functions */
219 static void HandleScreenGadgets(struct GadgetInfo *);
220 static void HandleSetupScreen_Generic(int, int, int, int, int);
221 static void HandleSetupScreen_Input(int, int, int, int, int);
222 static void CustomizeKeyboard(int);
223 static void ConfigureJoystick(int);
224 static void ConfigureVirtualButtons();
225 static void execSetupGame(void);
226 static void execSetupGraphics(void);
227 static void execSetupSound(void);
228 static void execSetupTouch(void);
229 static void execSetupArtwork(void);
230 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
232 static void DrawChooseLevelSet(void);
233 static void DrawChooseLevelNr(void);
234 static void DrawInfoScreen(void);
235 static void DrawSetupScreen(void);
237 static void DrawInfoScreen_NotAvailable(char *, char *);
238 static void DrawInfoScreen_HelpAnim(int, int, boolean);
239 static void DrawInfoScreen_HelpText(int, int, int, int);
240 static void HandleInfoScreen_Main(int, int, int, int, int);
241 static void HandleInfoScreen_TitleScreen(int);
242 static void HandleInfoScreen_Elements(int);
243 static void HandleInfoScreen_Music(int);
244 static void HandleInfoScreen_Credits(int);
245 static void HandleInfoScreen_Program(int);
246 static void HandleInfoScreen_Version(int);
248 static void MapScreenMenuGadgets(int);
249 static void MapScreenGadgets(int);
250 static void MapScreenTreeGadgets(TreeInfo *);
252 static void UpdateScreenMenuGadgets(int, boolean);
254 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
256 static int info_mode = INFO_MODE_MAIN;
257 static int setup_mode = SETUP_MODE_MAIN;
259 static TreeInfo *window_sizes = NULL;
260 static TreeInfo *window_size_current = NULL;
262 static TreeInfo *scaling_types = NULL;
263 static TreeInfo *scaling_type_current = NULL;
265 static TreeInfo *rendering_modes = NULL;
266 static TreeInfo *rendering_mode_current = NULL;
268 static TreeInfo *scroll_delays = NULL;
269 static TreeInfo *scroll_delay_current = NULL;
271 static TreeInfo *snapshot_modes = NULL;
272 static TreeInfo *snapshot_mode_current = NULL;
274 static TreeInfo *game_speeds = NULL;
275 static TreeInfo *game_speed_current = NULL;
277 static TreeInfo *volumes_simple = NULL;
278 static TreeInfo *volume_simple_current = NULL;
280 static TreeInfo *volumes_loops = NULL;
281 static TreeInfo *volume_loops_current = NULL;
283 static TreeInfo *volumes_music = NULL;
284 static TreeInfo *volume_music_current = NULL;
286 static TreeInfo *touch_controls = NULL;
287 static TreeInfo *touch_control_current = NULL;
289 static TreeInfo *move_distances = NULL;
290 static TreeInfo *move_distance_current = NULL;
292 static TreeInfo *drop_distances = NULL;
293 static TreeInfo *drop_distance_current = NULL;
295 static TreeInfo *transparencies = NULL;
296 static TreeInfo *transparency_current = NULL;
298 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
299 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
301 static TreeInfo *level_number = NULL;
302 static TreeInfo *level_number_current = NULL;
308 } window_sizes_list[] =
313 { 100, "100 % (Default)" },
330 } scaling_types_list[] =
332 { SCALING_QUALITY_NEAREST, "Off" },
333 { SCALING_QUALITY_LINEAR, "Linear" },
334 { SCALING_QUALITY_BEST, "Anisotropic" },
343 } rendering_modes_list[] =
345 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
346 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
348 // this mode may work under certain conditions, but does not work on Windows
349 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
351 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
360 } game_speeds_list[] =
369 { 1000, "1/1s (Extremely Slow)" },
374 { 29, "1/35s (Original Supaplex)" },
376 { 20, "1/50s (Normal Speed)" },
377 { 14, "1/70s (Maximum Supaplex)" },
381 { 1, "1/1000s (Extremely Fast)" },
391 } scroll_delays_list[] =
393 { 0, "0 Tiles (No Scroll Delay)" },
396 { 3, "3 Tiles (Default)" },
401 { 8, "8 Tiles (Maximum Scroll Delay)"},
410 } snapshot_modes_list[] =
412 { STR_SNAPSHOT_MODE_OFF, "Off" },
413 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
414 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
415 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
448 } touch_controls_list[] =
450 { TOUCH_CONTROL_OFF, "Off" },
451 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
452 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
453 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
481 } transparencies_list[] =
483 { 0, "0 % (Opaque)" },
493 { 100, "100 % (Invisible)" },
502 } grid_sizes_list[] =
538 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
539 (s) <= GAME_MODE_SETUP ? (s) : \
540 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
541 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
543 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
544 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
545 (i) <= INFO_MODE_LEVELSET ? (i) : \
548 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
549 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
550 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
551 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
552 SETUP_MODE_CHOOSE_ARTWORK : \
553 SETUP_MODE_CHOOSE_OTHER)
555 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
556 menu.draw_xoffset[GAME_MODE_INFO] : \
557 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
558 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
559 menu.draw_yoffset[GAME_MODE_INFO] : \
560 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
561 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
562 menu.extra_spacing[GAME_MODE_INFO] : \
563 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
565 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
566 menu.draw_xoffset[GAME_MODE_SETUP] : \
567 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
568 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
569 menu.draw_yoffset[GAME_MODE_SETUP] : \
570 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
571 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
572 menu.extra_spacing[GAME_MODE_SETUP] : \
573 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
575 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
576 DRAW_XOFFSET_INFO(info_mode) : \
577 (s) == GAME_MODE_SETUP ? \
578 DRAW_XOFFSET_SETUP(setup_mode) : \
579 menu.draw_xoffset[DRAW_MODE(s)])
580 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
581 DRAW_YOFFSET_INFO(info_mode) : \
582 (s) == GAME_MODE_SETUP ? \
583 DRAW_YOFFSET_SETUP(setup_mode) : \
584 menu.draw_yoffset[DRAW_MODE(s)])
585 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
586 EXTRA_SPACING_INFO(info_mode) : \
587 (s) == GAME_MODE_SETUP ? \
588 EXTRA_SPACING_SETUP(setup_mode) : \
589 menu.extra_spacing[DRAW_MODE(s)])
591 #define mSX (SX + DRAW_XOFFSET(game_status))
592 #define mSY (SY + DRAW_YOFFSET(game_status))
594 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
595 menu.list_size[game_status] : \
596 MAX_MENU_ENTRIES_ON_SCREEN)
598 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
599 NUM_MENU_ENTRIES_ON_SCREEN)
602 /* title display and control definitions */
604 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
605 2 * MAX_NUM_TITLE_MESSAGES)
607 #define NO_DIRECT_LEVEL_SELECT (-1)
610 static int num_title_screens = 0;
612 struct TitleControlInfo
621 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
623 /* main menu display and control definitions */
625 #define MAIN_CONTROL_NAME 0
626 #define MAIN_CONTROL_LEVELS 1
627 #define MAIN_CONTROL_SCORES 2
628 #define MAIN_CONTROL_EDITOR 3
629 #define MAIN_CONTROL_INFO 4
630 #define MAIN_CONTROL_GAME 5
631 #define MAIN_CONTROL_SETUP 6
632 #define MAIN_CONTROL_QUIT 7
633 #define MAIN_CONTROL_PREV_LEVEL 8
634 #define MAIN_CONTROL_NEXT_LEVEL 9
635 #define MAIN_CONTROL_FIRST_LEVEL 10
636 #define MAIN_CONTROL_LAST_LEVEL 11
637 #define MAIN_CONTROL_LEVEL_NUMBER 12
638 #define MAIN_CONTROL_LEVEL_INFO_1 13
639 #define MAIN_CONTROL_LEVEL_INFO_2 14
640 #define MAIN_CONTROL_LEVEL_NAME 15
641 #define MAIN_CONTROL_LEVEL_AUTHOR 16
642 #define MAIN_CONTROL_LEVEL_YEAR 17
643 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
644 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
645 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
646 #define MAIN_CONTROL_TITLE_1 21
647 #define MAIN_CONTROL_TITLE_2 22
648 #define MAIN_CONTROL_TITLE_3 23
650 static char str_main_text_name[10];
651 static char str_main_text_first_level[10];
652 static char str_main_text_last_level[10];
653 static char str_main_text_level_number[10];
655 static char *main_text_name = str_main_text_name;
656 static char *main_text_first_level = str_main_text_first_level;
657 static char *main_text_last_level = str_main_text_last_level;
658 static char *main_text_level_number = str_main_text_level_number;
659 static char *main_text_levels = "Levelset";
660 static char *main_text_scores = "Hall Of Fame";
661 static char *main_text_editor = "Level Creator";
662 static char *main_text_info = "Info Screen";
663 static char *main_text_game = "Start Game";
664 static char *main_text_setup = "Setup";
665 static char *main_text_quit = "Quit";
666 static char *main_text_level_name = level.name;
667 static char *main_text_level_author = level.author;
668 static char *main_text_level_year = NULL;
669 static char *main_text_level_imported_from = NULL;
670 static char *main_text_level_imported_by = NULL;
671 static char *main_text_level_tested_by = NULL;
672 static char *main_text_title_1 = NULL;
673 static char *main_text_title_2 = NULL;
674 static char *main_text_title_3 = NULL;
676 struct MainControlInfo
680 struct MenuPosInfo *pos_button;
683 struct TextPosInfo *pos_text;
686 struct TextPosInfo *pos_input;
690 static struct MainControlInfo main_controls[] =
694 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
695 &menu.main.text.name, &main_text_name,
696 &menu.main.input.name, &setup.player_name,
700 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
701 &menu.main.text.levels, &main_text_levels,
706 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
707 &menu.main.text.scores, &main_text_scores,
712 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
713 &menu.main.text.editor, &main_text_editor,
718 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
719 &menu.main.text.info, &main_text_info,
724 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
725 &menu.main.text.game, &main_text_game,
730 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
731 &menu.main.text.setup, &main_text_setup,
736 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
737 &menu.main.text.quit, &main_text_quit,
741 /* (these two buttons are real gadgets) */
743 MAIN_CONTROL_PREV_LEVEL,
744 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
749 MAIN_CONTROL_NEXT_LEVEL,
750 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
756 MAIN_CONTROL_FIRST_LEVEL,
757 &menu.main.button.first_level, IMG_MENU_BUTTON_FIRST_LEVEL,
758 &menu.main.text.first_level, &main_text_first_level,
762 MAIN_CONTROL_LAST_LEVEL,
763 &menu.main.button.last_level, IMG_MENU_BUTTON_LAST_LEVEL,
764 &menu.main.text.last_level, &main_text_last_level,
768 MAIN_CONTROL_LEVEL_NUMBER,
769 &menu.main.button.level_number, IMG_MENU_BUTTON_LEVEL_NUMBER,
770 &menu.main.text.level_number, &main_text_level_number,
774 MAIN_CONTROL_LEVEL_INFO_1,
776 &menu.main.text.level_info_1, NULL,
780 MAIN_CONTROL_LEVEL_INFO_2,
782 &menu.main.text.level_info_2, NULL,
786 MAIN_CONTROL_LEVEL_NAME,
788 &menu.main.text.level_name, &main_text_level_name,
792 MAIN_CONTROL_LEVEL_AUTHOR,
794 &menu.main.text.level_author, &main_text_level_author,
798 MAIN_CONTROL_LEVEL_YEAR,
800 &menu.main.text.level_year, &main_text_level_year,
804 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
806 &menu.main.text.level_imported_from, &main_text_level_imported_from,
810 MAIN_CONTROL_LEVEL_IMPORTED_BY,
812 &menu.main.text.level_imported_by, &main_text_level_imported_by,
816 MAIN_CONTROL_LEVEL_TESTED_BY,
818 &menu.main.text.level_tested_by, &main_text_level_tested_by,
822 MAIN_CONTROL_TITLE_1,
824 &menu.main.text.title_1, &main_text_title_1,
828 MAIN_CONTROL_TITLE_2,
830 &menu.main.text.title_2, &main_text_title_2,
834 MAIN_CONTROL_TITLE_3,
836 &menu.main.text.title_3, &main_text_title_3,
849 static int getTitleScreenGraphic(int nr, boolean initial)
851 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
854 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
856 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
860 static int getTitleScreenGameMode(boolean initial)
862 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
866 static int getTitleMessageGameMode(boolean initial)
868 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
871 static int getTitleAnimMode(struct TitleControlInfo *tci)
873 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
875 return base + tci->local_nr;
879 static int getTitleScreenBackground(boolean initial)
881 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
886 static int getTitleMessageBackground(int nr, boolean initial)
888 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
892 static int getTitleBackground(int nr, boolean initial, boolean is_image)
894 int base = (is_image ?
895 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
896 IMG_BACKGROUND_TITLESCREEN_1) :
897 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
898 IMG_BACKGROUND_TITLEMESSAGE_1));
899 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
900 IMG_BACKGROUND_TITLE);
901 int graphic_local = base + nr;
903 if (graphic_info[graphic_local].bitmap != NULL)
904 return graphic_local;
906 if (graphic_info[graphic_global].bitmap != NULL)
907 return graphic_global;
909 return IMG_UNDEFINED;
912 static int getTitleSound(struct TitleControlInfo *tci)
914 boolean is_image = tci->is_image;
915 int initial = tci->initial;
916 int nr = tci->local_nr;
917 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
918 int base = (is_image ?
919 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
920 SND_BACKGROUND_TITLESCREEN_1) :
921 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
922 SND_BACKGROUND_TITLEMESSAGE_1));
923 int sound_global = menu.sound[mode];
924 int sound_local = base + nr;
927 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
928 nr, initial, is_image,
929 sound_global, getSoundListEntry(sound_global)->filename,
930 sound_local, getSoundListEntry(sound_local)->filename);
933 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
936 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
939 return SND_UNDEFINED;
942 static int getTitleMusic(struct TitleControlInfo *tci)
944 boolean is_image = tci->is_image;
945 int initial = tci->initial;
946 int nr = tci->local_nr;
947 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
948 int base = (is_image ?
949 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
950 MUS_BACKGROUND_TITLESCREEN_1) :
951 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
952 MUS_BACKGROUND_TITLEMESSAGE_1));
953 int music_global = menu.music[mode];
954 int music_local = base + nr;
957 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
958 nr, initial, is_image,
959 music_global, getMusicListEntry(music_global)->filename,
960 music_local, getMusicListEntry(music_local)->filename);
963 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
966 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
969 return MUS_UNDEFINED;
972 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
974 boolean is_image = tci->is_image;
975 boolean initial = tci->initial;
976 boolean first = tci->first;
977 int nr = tci->local_nr;
978 struct TitleMessageInfo tmi;
979 struct TitleFadingInfo ti;
981 tmi = (is_image ? (initial ? (first ?
982 titlescreen_initial_first[nr] :
983 titlescreen_initial[nr])
985 titlescreen_first[nr] :
987 : (initial ? (first ?
988 titlemessage_initial_first[nr] :
989 titlemessage_initial[nr])
991 titlemessage_first[nr] :
994 ti.fade_mode = tmi.fade_mode;
995 ti.fade_delay = tmi.fade_delay;
996 ti.post_delay = tmi.post_delay;
997 ti.auto_delay = tmi.auto_delay;
1002 static int compareTitleControlInfo(const void *object1, const void *object2)
1004 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1005 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1008 if (tci1->initial != tci2->initial)
1009 compare_result = (tci1->initial ? -1 : +1);
1010 else if (tci1->sort_priority != tci2->sort_priority)
1011 compare_result = tci1->sort_priority - tci2->sort_priority;
1012 else if (tci1->is_image != tci2->is_image)
1013 compare_result = (tci1->is_image ? -1 : +1);
1015 compare_result = tci1->local_nr - tci2->local_nr;
1017 return compare_result;
1020 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1022 int nr, int sort_priority)
1024 title_controls[num_title_screens].is_image = is_image;
1025 title_controls[num_title_screens].initial = initial;
1026 title_controls[num_title_screens].local_nr = nr;
1027 title_controls[num_title_screens].sort_priority = sort_priority;
1029 title_controls[num_title_screens].first = FALSE; /* will be set later */
1031 num_title_screens++;
1034 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1038 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1040 int graphic = getTitleScreenGraphic(i, initial);
1041 Bitmap *bitmap = graphic_info[graphic].bitmap;
1042 int sort_priority = graphic_info[graphic].sort_priority;
1045 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1048 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1050 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1051 char *filename = getLevelSetTitleMessageFilename(i, initial);
1052 int sort_priority = tmi->sort_priority;
1054 if (filename != NULL)
1055 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1059 static void InitializeTitleControls(boolean show_title_initial)
1061 num_title_screens = 0;
1063 /* 1st step: initialize title screens for game start (only when starting) */
1064 if (show_title_initial)
1065 InitializeTitleControls_CheckTitleInfo(TRUE);
1067 /* 2nd step: initialize title screens for current level set */
1068 InitializeTitleControls_CheckTitleInfo(FALSE);
1070 /* sort title screens according to sort_priority and title number */
1071 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1072 compareTitleControlInfo);
1074 /* mark first title screen */
1075 title_controls[0].first = TRUE;
1078 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1080 return (pos != NULL && pos->x != -1 && pos->y != -1);
1083 static boolean visibleTextPos(struct TextPosInfo *pos)
1085 return (pos != NULL && pos->x != -1 && pos->y != -1);
1088 static void InitializeMainControls()
1090 boolean local_team_mode = (!network.enabled && setup.team_mode);
1093 /* set main control text values to dynamically determined values */
1094 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1096 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1097 menu.main.text.first_level.size));
1098 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1099 menu.main.text.last_level.size));
1100 strcpy(main_text_level_number, int2str(level_nr,
1101 menu.main.text.level_number.size));
1103 main_text_level_year = leveldir_current->year;
1104 main_text_level_imported_from = leveldir_current->imported_from;
1105 main_text_level_imported_by = leveldir_current->imported_by;
1106 main_text_level_tested_by = leveldir_current->tested_by;
1108 main_text_title_1 = getConfigProgramTitleString();
1109 main_text_title_2 = getConfigProgramCopyrightString();
1110 main_text_title_3 = getConfigProgramCompanyString();
1112 /* set main control screen positions to dynamically determined values */
1113 for (i = 0; main_controls[i].nr != -1; i++)
1115 struct MainControlInfo *mci = &main_controls[i];
1117 struct MenuPosInfo *pos_button = mci->pos_button;
1118 struct TextPosInfo *pos_text = mci->pos_text;
1119 struct TextPosInfo *pos_input = mci->pos_input;
1120 char *text = (mci->text ? *mci->text : NULL);
1121 char *input = (mci->input ? *mci->input : NULL);
1122 int button_graphic = mci->button_graphic;
1123 int font_text = (pos_text ? pos_text->font : -1);
1124 int font_input = (pos_input ? pos_input->font : -1);
1126 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1127 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1128 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1129 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1130 int text_chars = (text != NULL ? strlen(text) : 0);
1131 int input_chars = (input != NULL ? strlen(input) : 0);
1134 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1136 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1137 int text_width = font_text_width * text_chars;
1138 int text_height = font_text_height;
1139 int input_width = font_input_width * input_chars;
1140 int input_height = font_input_height;
1142 if (nr == MAIN_CONTROL_NAME)
1144 menu.main.input.name.width = input_width;
1145 menu.main.input.name.height = input_height;
1148 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1150 pos_button->width = button_width;
1151 pos_button->height = button_height;
1154 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1156 /* calculate text size -- needed for text alignment */
1157 boolean calculate_text_size = (text != NULL);
1159 if (pos_text->width == -1 || calculate_text_size)
1160 pos_text->width = text_width;
1161 if (pos_text->height == -1 || calculate_text_size)
1162 pos_text->height = text_height;
1164 if (visibleMenuPos(pos_button))
1166 if (pos_text->x == -1)
1167 pos_text->x = pos_button->x + pos_button->width;
1168 if (pos_text->y == -1)
1170 pos_button->y + (pos_button->height - pos_text->height) / 2;
1174 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1176 if (visibleTextPos(pos_text))
1178 if (pos_input->x == -1)
1179 pos_input->x = pos_text->x + pos_text->width;
1180 if (pos_input->y == -1)
1181 pos_input->y = pos_text->y;
1184 if (pos_input->width == -1)
1185 pos_input->width = input_width;
1186 if (pos_input->height == -1)
1187 pos_input->height = input_height;
1192 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1193 int graphic, boolean pressed)
1195 struct GraphicInfo *g = &graphic_info[graphic];
1198 int xoffset = (pressed ? g->pressed_xoffset : 0);
1199 int yoffset = (pressed ? g->pressed_yoffset : 0);
1201 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1203 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1204 g->width, g->height, dst_x, dst_y);
1207 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1208 boolean active_input,
1209 boolean pressed_button)
1213 for (i = 0; main_controls[i].nr != -1; i++)
1215 struct MainControlInfo *mci = &main_controls[i];
1217 if (mci->nr == nr || nr == -1)
1219 struct MenuPosInfo *pos_button = mci->pos_button;
1220 struct TextPosInfo *pos_text = mci->pos_text;
1221 struct TextPosInfo *pos_input = mci->pos_input;
1222 char *text = (mci->text ? *mci->text : NULL);
1223 char *input = (mci->input ? *mci->input : NULL);
1224 int button_graphic = mci->button_graphic;
1225 int font_text = (pos_text ? pos_text->font : -1);
1226 int font_input = (pos_input ? pos_input->font : -1);
1230 button_graphic = BUTTON_ACTIVE(button_graphic);
1231 font_text = FONT_ACTIVE(font_text);
1236 font_input = FONT_ACTIVE(font_input);
1239 if (visibleMenuPos(pos_button))
1241 struct MenuPosInfo *pos = pos_button;
1242 int x = mSX + pos->x;
1243 int y = mSY + pos->y;
1245 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1246 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1249 if (visibleTextPos(pos_text) && text != NULL)
1251 struct TextPosInfo *pos = pos_text;
1252 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1253 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1256 /* (check why/if this is needed) */
1257 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1259 DrawText(x, y, text, font_text);
1262 if (visibleTextPos(pos_input) && input != NULL)
1264 struct TextPosInfo *pos = pos_input;
1265 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1266 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1269 /* (check why/if this is needed) */
1270 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1272 DrawText(x, y, input, font_input);
1278 static void DrawCursorAndText_Main(int nr, boolean active_text,
1279 boolean pressed_button)
1281 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1285 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1286 boolean pressed_button)
1288 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1292 static struct MainControlInfo *getMainControlInfo(int nr)
1296 for (i = 0; main_controls[i].nr != -1; i++)
1297 if (main_controls[i].nr == nr)
1298 return &main_controls[i];
1303 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1308 int rect_x = ALIGNED_TEXT_XPOS(rect);
1309 int rect_y = ALIGNED_TEXT_YPOS(rect);
1311 return (x >= rect_x && x < rect_x + rect->width &&
1312 y >= rect_y && y < rect_y + rect->height);
1315 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1320 int rect_x = ALIGNED_TEXT_XPOS(rect);
1321 int rect_y = ALIGNED_TEXT_YPOS(rect);
1324 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1325 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1326 (x >= rect_x && x < rect_x + rect->width &&
1327 y >= rect_y && y < rect_y + rect->height));
1330 return (x >= rect_x && x < rect_x + rect->width &&
1331 y >= rect_y && y < rect_y + rect->height);
1334 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1336 int rect_width = preview->xsize * preview->tile_size;
1337 int rect_height = preview->ysize * preview->tile_size;
1338 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1339 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1341 return (x >= rect_x && x < rect_x + rect_width &&
1342 y >= rect_y && y < rect_y + rect_height);
1345 static void AdjustScrollbar(int id, int items_max, int items_visible,
1348 struct GadgetInfo *gi = screen_gadget[id];
1350 if (item_position > items_max - items_visible)
1351 item_position = items_max - items_visible;
1353 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1354 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1355 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1358 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1360 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1364 static void clearMenuListArea()
1366 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1368 /* correct scrollbar position if placed outside menu (playfield) area */
1369 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1370 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1372 /* clear menu list area, but not title or scrollbar */
1373 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1374 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1377 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1379 static int cursor_array[MAX_LEV_FIELDY];
1380 int x = mSX + TILEX * xpos;
1381 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1386 cursor_array[ypos] = graphic;
1388 graphic = cursor_array[ypos];
1392 graphic = BUTTON_ACTIVE(graphic);
1394 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1395 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1398 static void initCursor(int ypos, int graphic)
1400 drawCursorExt(0, ypos, FALSE, graphic);
1403 static void drawCursor(int ypos, boolean active)
1405 drawCursorExt(0, ypos, active, -1);
1408 static void drawCursorXY(int xpos, int ypos, int graphic)
1410 drawCursorExt(xpos, ypos, FALSE, graphic);
1413 static void drawChooseTreeCursor(int ypos, boolean active)
1415 drawCursorExt(0, ypos, active, -1);
1420 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1421 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1424 void DrawTitleScreenImage(int nr, boolean initial)
1426 int graphic = getTitleScreenGraphic(nr, initial);
1427 Bitmap *bitmap = graphic_info[graphic].bitmap;
1428 int width = graphic_info[graphic].width;
1429 int height = graphic_info[graphic].height;
1430 int src_x = graphic_info[graphic].src_x;
1431 int src_y = graphic_info[graphic].src_y;
1437 if (width > WIN_XSIZE)
1439 /* image width too large for window => center image horizontally */
1440 src_x = (width - WIN_XSIZE) / 2;
1444 if (height > WIN_YSIZE)
1446 /* image height too large for window => center image vertically */
1447 src_y = (height - WIN_YSIZE) / 2;
1451 /* always display title screens centered */
1452 dst_x = (WIN_XSIZE - width) / 2;
1453 dst_y = (WIN_YSIZE - height) / 2;
1455 SetDrawBackgroundMask(REDRAW_ALL);
1456 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1458 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1460 if (DrawingOnBackground(dst_x, dst_y))
1461 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1463 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1465 redraw_mask = REDRAW_ALL;
1468 void DrawTitleScreenMessage(int nr, boolean initial)
1470 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1471 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1473 if (filename == NULL)
1476 /* force TITLE font on title message screen */
1477 SetFontStatus(getTitleMessageGameMode(initial));
1479 /* if chars *and* width set to "-1", automatically determine width */
1480 if (tmi->chars == -1 && tmi->width == -1)
1481 tmi->width = viewport.window[game_status].width;
1483 /* if lines *and* height set to "-1", automatically determine height */
1484 if (tmi->lines == -1 && tmi->height == -1)
1485 tmi->height = viewport.window[game_status].height;
1487 /* if chars set to "-1", automatically determine by text and font width */
1488 if (tmi->chars == -1)
1489 tmi->chars = tmi->width / getFontWidth(tmi->font);
1491 tmi->width = tmi->chars * getFontWidth(tmi->font);
1493 /* if lines set to "-1", automatically determine by text and font height */
1494 if (tmi->lines == -1)
1495 tmi->lines = tmi->height / getFontHeight(tmi->font);
1497 tmi->height = tmi->lines * getFontHeight(tmi->font);
1499 /* if x set to "-1", automatically determine by width and alignment */
1501 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1503 /* if y set to "-1", automatically determine by height and alignment */
1505 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1507 SetDrawBackgroundMask(REDRAW_ALL);
1508 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1510 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1512 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1513 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1514 tmi->autowrap, tmi->centered, tmi->parse_comments);
1519 void DrawTitleScreen()
1521 KeyboardAutoRepeatOff();
1523 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1526 boolean CheckTitleScreen(boolean levelset_has_changed)
1528 static boolean show_title_initial = TRUE;
1529 boolean show_titlescreen = FALSE;
1531 /* needed to be able to skip title screen, if no image or message defined */
1532 InitializeTitleControls(show_title_initial);
1534 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1535 show_titlescreen = TRUE;
1537 /* show initial title images and messages only once at program start */
1538 show_title_initial = FALSE;
1540 return (show_titlescreen && num_title_screens > 0);
1545 static LevelDirTree *leveldir_last_valid = NULL;
1546 boolean levelset_has_changed = FALSE;
1547 int fade_mask = REDRAW_FIELD;
1549 LimitScreenUpdates(FALSE);
1551 FadeSetLeaveScreen();
1553 /* do not fade out here -- function may continue and fade on editor screen */
1556 FadeMenuSoundsAndMusic();
1558 ExpireSoundLoops(FALSE);
1560 KeyboardAutoRepeatOn();
1562 audio.sound_deactivated = FALSE;
1566 /* needed if last screen was the playing screen, invoked from level editor */
1567 if (level_editor_test_game)
1569 CloseDoor(DOOR_CLOSE_ALL);
1571 SetGameStatus(GAME_MODE_EDITOR);
1578 /* needed if last screen was the setup screen and fullscreen state changed */
1579 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1580 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1582 /* leveldir_current may be invalid (level group, parent link) */
1583 if (!validLevelSeries(leveldir_current))
1584 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1586 if (leveldir_current != leveldir_last_valid)
1587 levelset_has_changed = TRUE;
1589 /* store valid level series information */
1590 leveldir_last_valid = leveldir_current;
1592 init_last = init; /* switch to new busy animation */
1594 /* 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();
1645 DrawNetworkPlayers();
1647 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1650 if (TAPE_IS_EMPTY(tape))
1652 DrawCompleteVideoDisplay();
1654 PlayMenuSoundsAndMusic();
1656 /* create gadgets for main menu screen */
1657 FreeScreenGadgets();
1658 CreateScreenGadgets();
1660 /* may be required if audio buttons shown on tape and changed in setup menu */
1662 CreateGameButtons();
1664 /* map gadgets for main menu screen */
1666 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1667 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1669 /* copy actual game door content to door double buffer for OpenDoor() */
1670 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1671 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1673 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1675 DrawMaskedBorder(fade_mask);
1680 /* update screen area with special editor door */
1681 redraw_mask |= REDRAW_ALL;
1684 SetMouseCursor(CURSOR_DEFAULT);
1686 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1689 static void gotoTopLevelDir()
1691 /* move upwards until inside (but not above) top level directory */
1692 while (leveldir_current->node_parent &&
1693 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1695 /* write a "path" into level tree for easy navigation to last level */
1696 if (leveldir_current->node_parent->node_group->cl_first == -1)
1698 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1699 int leveldir_pos = posTreeInfo(leveldir_current);
1700 int num_page_entries;
1701 int cl_first, cl_cursor;
1703 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1704 num_page_entries = num_leveldirs;
1706 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1708 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1709 cl_cursor = leveldir_pos - cl_first;
1711 leveldir_current->node_parent->node_group->cl_first = cl_first;
1712 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1715 leveldir_current = leveldir_current->node_parent;
1719 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1721 static unsigned int title_delay = 0;
1722 static int title_screen_nr = 0;
1723 static int last_sound = -1, last_music = -1;
1724 boolean return_to_main_menu = FALSE;
1725 struct TitleControlInfo *tci;
1728 if (button == MB_MENU_INITIALIZE)
1731 title_screen_nr = 0;
1732 tci = &title_controls[title_screen_nr];
1734 SetAnimStatus(getTitleAnimMode(tci));
1736 last_sound = SND_UNDEFINED;
1737 last_music = MUS_UNDEFINED;
1739 if (num_title_screens != 0)
1741 FadeSetEnterScreen();
1743 /* use individual title fading instead of global "enter screen" fading */
1744 fading = getTitleFading(tci);
1747 if (game_status_last_screen == GAME_MODE_INFO)
1749 if (num_title_screens == 0)
1751 /* switch game mode from title screen mode back to info screen mode */
1752 SetGameStatus(GAME_MODE_INFO);
1754 /* store that last screen was info screen, not main menu screen */
1755 game_status_last_screen = GAME_MODE_INFO;
1757 DrawInfoScreen_NotAvailable("Title screen information:",
1758 "No title screen for this level set.");
1762 FadeMenuSoundsAndMusic();
1765 FadeOut(REDRAW_ALL);
1767 /* title screens may have different window size */
1768 ChangeViewportPropertiesIfNeeded();
1770 /* only required to update logic for redrawing global border */
1774 DrawTitleScreenImage(tci->local_nr, tci->initial);
1776 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1778 sound = getTitleSound(tci);
1779 music = getTitleMusic(tci);
1781 if (sound != last_sound)
1782 PlayMenuSoundExt(sound);
1783 if (music != last_music)
1784 PlayMenuMusicExt(music);
1789 SetMouseCursor(CURSOR_NONE);
1793 DelayReached(&title_delay, 0); /* reset delay counter */
1798 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1799 button = MB_MENU_CHOICE;
1801 if (button == MB_MENU_LEAVE)
1803 return_to_main_menu = TRUE;
1805 else if (button == MB_MENU_CHOICE)
1807 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1809 SetGameStatus(GAME_MODE_INFO);
1811 info_mode = INFO_MODE_MAIN;
1820 if (title_screen_nr < num_title_screens)
1822 tci = &title_controls[title_screen_nr];
1824 SetAnimStatus(getTitleAnimMode(tci));
1826 sound = getTitleSound(tci);
1827 music = getTitleMusic(tci);
1829 if (last_sound != SND_UNDEFINED && sound != last_sound)
1830 FadeSound(last_sound);
1831 if (last_music != MUS_UNDEFINED && music != last_music)
1834 fading = getTitleFading(tci);
1836 FadeOut(REDRAW_ALL);
1839 DrawTitleScreenImage(tci->local_nr, tci->initial);
1841 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1843 sound = getTitleSound(tci);
1844 music = getTitleMusic(tci);
1846 if (sound != last_sound)
1847 PlayMenuSoundExt(sound);
1848 if (music != last_music)
1849 PlayMenuMusicExt(music);
1856 DelayReached(&title_delay, 0); /* reset delay counter */
1860 FadeMenuSoundsAndMusic();
1862 return_to_main_menu = TRUE;
1866 if (return_to_main_menu)
1868 SetMouseCursor(CURSOR_DEFAULT);
1870 /* force full menu screen redraw after displaying title screens */
1871 redraw_mask = REDRAW_ALL;
1873 if (game_status_last_screen == GAME_MODE_INFO)
1875 SetGameStatus(GAME_MODE_INFO);
1877 info_mode = INFO_MODE_MAIN;
1881 else /* default: return to main menu */
1883 SetGameStatus(GAME_MODE_MAIN);
1890 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1892 int old_level_nr = level_nr;
1895 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1896 new_level_nr = selected_level_nr;
1898 new_level_nr = old_level_nr + step * direction;
1900 if (new_level_nr < leveldir_current->first_level)
1901 new_level_nr = leveldir_current->first_level;
1902 if (new_level_nr > leveldir_current->last_level)
1903 new_level_nr = leveldir_current->last_level;
1905 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1907 /* skipping levels is only allowed when trying to skip single level */
1908 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1909 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1911 leveldir_current->handicap_level++;
1912 SaveLevelSetup_SeriesInfo();
1915 new_level_nr = leveldir_current->handicap_level;
1918 if (new_level_nr != old_level_nr)
1920 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1922 PlaySound(SND_MENU_ITEM_SELECTING);
1924 level_nr = new_level_nr;
1926 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1927 int2str(level_nr, menu.main.text.level_number.size),
1928 mci->pos_text->font);
1930 LoadLevel(level_nr);
1931 DrawPreviewLevelInitial();
1935 DrawCompleteVideoDisplay();
1937 SaveLevelSetup_SeriesInfo();
1939 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1941 /* needed because DrawPreviewLevelInitial() takes some time */
1943 /* SyncDisplay(); */
1947 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1949 static int choice = MAIN_CONTROL_GAME;
1950 static boolean button_pressed_last = FALSE;
1951 boolean button_pressed = FALSE;
1955 if (button == MB_MENU_INITIALIZE)
1957 DrawCursorAndText_Main(choice, TRUE, FALSE);
1962 if (mx || my) /* mouse input */
1966 for (i = 0; main_controls[i].nr != -1; i++)
1968 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1969 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1970 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1972 pos = main_controls[i].nr;
1978 /* check if level preview was clicked */
1979 if (insidePreviewRect(&preview, mx - SX, my - SY))
1980 pos = MAIN_CONTROL_GAME;
1982 // handle pressed/unpressed state for active/inactive menu buttons
1983 // (if pos != -1, "i" contains index position corresponding to "pos")
1985 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1986 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1987 button_pressed = TRUE;
1989 if (button_pressed != button_pressed_last)
1991 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1994 PlaySound(SND_MENU_BUTTON_PRESSING);
1996 PlaySound(SND_MENU_BUTTON_RELEASING);
1999 else if (dx || dy) /* keyboard input */
2001 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2002 choice == MAIN_CONTROL_SETUP))
2003 button = MB_MENU_CHOICE;
2008 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2010 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2012 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2014 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2016 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2018 CloseDoor(DOOR_CLOSE_2);
2020 SetGameStatus(GAME_MODE_LEVELNR);
2022 DrawChooseLevelNr();
2024 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2030 PlaySound(SND_MENU_ITEM_ACTIVATING);
2032 DrawCursorAndText_Main(choice, FALSE, FALSE);
2033 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2039 if (choice != MAIN_CONTROL_INFO &&
2040 choice != MAIN_CONTROL_SETUP)
2041 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2046 PlaySound(SND_MENU_ITEM_SELECTING);
2048 if (pos == MAIN_CONTROL_NAME)
2050 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2052 HandleTypeName(strlen(setup.player_name), 0);
2054 else if (pos == MAIN_CONTROL_LEVELS)
2058 CloseDoor(DOOR_CLOSE_2);
2060 SetGameStatus(GAME_MODE_LEVELS);
2062 SaveLevelSetup_LastSeries();
2063 SaveLevelSetup_SeriesInfo();
2065 if (setup.internal.choose_from_top_leveldir)
2068 DrawChooseLevelSet();
2071 else if (pos == MAIN_CONTROL_SCORES)
2073 CloseDoor(DOOR_CLOSE_2);
2075 SetGameStatus(GAME_MODE_SCORES);
2077 DrawHallOfFame(level_nr, -1);
2079 else if (pos == MAIN_CONTROL_EDITOR)
2081 if (leveldir_current->readonly &&
2082 !strEqual(setup.player_name, "Artsoft"))
2083 Request("This level is read only!", REQ_CONFIRM);
2085 CloseDoor(DOOR_CLOSE_2);
2087 SetGameStatus(GAME_MODE_EDITOR);
2089 FadeSetEnterScreen();
2093 else if (pos == MAIN_CONTROL_INFO)
2095 CloseDoor(DOOR_CLOSE_2);
2097 SetGameStatus(GAME_MODE_INFO);
2099 info_mode = INFO_MODE_MAIN;
2103 else if (pos == MAIN_CONTROL_GAME)
2105 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2107 else if (pos == MAIN_CONTROL_SETUP)
2109 CloseDoor(DOOR_CLOSE_2);
2111 SetGameStatus(GAME_MODE_SETUP);
2113 setup_mode = SETUP_MODE_MAIN;
2117 else if (pos == MAIN_CONTROL_QUIT)
2119 SaveLevelSetup_LastSeries();
2120 SaveLevelSetup_SeriesInfo();
2122 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2123 SetGameStatus(GAME_MODE_QUIT);
2128 button_pressed_last = button_pressed;
2132 /* ========================================================================= */
2133 /* info screen functions */
2134 /* ========================================================================= */
2136 static struct TokenInfo *info_info;
2137 static int num_info_info; /* number of info entries shown on screen */
2138 static int max_info_info; /* total number of info entries in list */
2140 static void execInfoTitleScreen()
2142 info_mode = INFO_MODE_TITLE;
2147 static void execInfoElements()
2149 info_mode = INFO_MODE_ELEMENTS;
2154 static void execInfoMusic()
2156 info_mode = INFO_MODE_MUSIC;
2161 static void execInfoCredits()
2163 info_mode = INFO_MODE_CREDITS;
2168 static void execInfoProgram()
2170 info_mode = INFO_MODE_PROGRAM;
2175 static void execInfoVersion()
2177 info_mode = INFO_MODE_VERSION;
2182 static void execInfoLevelSet()
2184 info_mode = INFO_MODE_LEVELSET;
2189 static void execExitInfo()
2191 SetGameStatus(GAME_MODE_MAIN);
2196 static struct TokenInfo info_info_main[] =
2198 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2199 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2200 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2201 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2202 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2203 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2204 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2205 { TYPE_EMPTY, NULL, "" },
2206 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2211 static int getMenuTextFont(int type)
2213 if (type & (TYPE_SWITCH |
2226 static struct TokenInfo *setup_info;
2227 static struct TokenInfo setup_info_input[];
2229 static struct TokenInfo *menu_info;
2231 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2232 int screen_pos, int menu_info_pos_raw,
2235 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2236 struct TokenInfo *ti = &token_info[pos];
2237 int xpos = MENU_SCREEN_START_XPOS;
2238 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2239 int font_nr = getMenuTextFont(ti->type);
2241 if (setup_mode == SETUP_MODE_INPUT)
2242 font_nr = FONT_MENU_1;
2245 font_nr = FONT_ACTIVE(font_nr);
2247 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2249 if (ti->type & ~TYPE_SKIP_ENTRY)
2250 drawCursor(screen_pos, active);
2253 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2256 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2259 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2262 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2265 static char *window_size_text;
2266 static char *scaling_type_text;
2268 static void drawSetupValue(int, int);
2270 static void drawMenuInfoList(int first_entry, int num_page_entries,
2271 int max_page_entries)
2275 if (first_entry + num_page_entries > max_page_entries)
2278 clearMenuListArea();
2280 for (i = 0; i < num_page_entries; i++)
2282 int menu_info_pos = first_entry + i;
2283 struct TokenInfo *si = &menu_info[menu_info_pos];
2284 void *value_ptr = si->value;
2286 /* set some entries to "unchangeable" according to other variables */
2287 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2288 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2289 (value_ptr == &setup.sound_music && !audio.music_available) ||
2290 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2291 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2292 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2293 si->type |= TYPE_GHOSTED;
2295 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2296 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2297 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2298 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2299 else if (si->type & ~TYPE_SKIP_ENTRY)
2300 initCursor(i, IMG_MENU_BUTTON);
2302 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2304 if (si->type & TYPE_VALUE &&
2305 menu_info == setup_info)
2306 drawSetupValue(i, menu_info_pos);
2310 static void DrawInfoScreen_Main()
2312 int fade_mask = REDRAW_FIELD;
2315 if (redraw_mask & REDRAW_ALL)
2316 fade_mask = REDRAW_ALL;
2318 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2319 fade_mask = REDRAW_ALL;
2322 FadeMenuSoundsAndMusic();
2324 FreeScreenGadgets();
2325 CreateScreenGadgets();
2327 /* (needed after displaying title screens which disable auto repeat) */
2328 KeyboardAutoRepeatOn();
2330 FadeSetLeaveScreen();
2334 /* needed if different viewport properties defined for info screen */
2335 ChangeViewportPropertiesIfNeeded();
2337 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2341 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2343 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2345 info_info = info_info_main;
2347 // determine maximal number of info entries that can be displayed on screen
2349 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2352 // determine maximal number of info entries available for menu of info screen
2354 for (i = 0; info_info[i].type != 0; i++)
2357 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2359 MapScreenGadgets(max_info_info);
2361 PlayMenuSoundsAndMusic();
2363 DrawMaskedBorder(fade_mask);
2368 static void changeSetupValue(int, int, int);
2370 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2371 int mode, int num_page_entries, int max_page_entries)
2373 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2374 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2375 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2376 int *num_page_entries_last = num_page_entries_all_last[game_status];
2377 int *choice_store = choice_stores[game_status];
2378 int *first_entry_store = first_entry_stores[game_status];
2379 int choice = choice_store[mode]; /* starts with 0 */
2380 int first_entry = first_entry_store[mode]; /* starts with 0 */
2382 int y = choice - first_entry;
2384 boolean position_set_by_scrollbar = (dx == 999);
2385 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2388 if (button == MB_MENU_INITIALIZE)
2390 // check if number of menu page entries has changed (may happen by change
2391 // of custom artwork definition value for 'list_size' for this menu screen)
2392 // (in this case, the last menu position most probably has to be corrected)
2393 if (num_page_entries != num_page_entries_last[mode])
2395 choice_store[mode] = first_entry_store[mode] = 0;
2397 choice = first_entry = 0;
2400 num_page_entries_last[mode] = num_page_entries;
2403 /* advance to first valid menu entry */
2404 while (choice < num_page_entries &&
2405 menu_info[choice].type & TYPE_SKIP_ENTRY)
2408 if (position_set_by_scrollbar)
2409 first_entry = first_entry_store[mode] = dy;
2411 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2412 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2414 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2416 if (choice < first_entry)
2418 choice = first_entry;
2420 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2423 else if (choice > first_entry + num_page_entries - 1)
2425 choice = first_entry + num_page_entries - 1;
2427 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2431 choice_store[mode] = choice;
2433 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2437 else if (button == MB_MENU_LEAVE)
2439 PlaySound(SND_MENU_ITEM_SELECTING);
2441 for (i = 0; i < max_page_entries; i++)
2443 if (menu_info[i].type & TYPE_LEAVE_MENU)
2445 void (*menu_callback_function)(void) = menu_info[i].value;
2449 menu_callback_function();
2451 break; /* absolutely needed because function changes 'menu_info'! */
2458 if (mx || my) /* mouse input */
2460 x = (mx - mSX) / 32;
2461 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2463 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2465 /* move cursor instead of scrolling when already at start/end of list */
2466 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2468 else if (dy == +1 * SCROLL_LINE &&
2469 first_entry + num_page_entries == max_page_entries)
2472 /* handle scrolling screen one line or page */
2474 y + dy > num_page_entries - 1)
2476 boolean redraw = FALSE;
2478 if (ABS(dy) == SCROLL_PAGE)
2479 step = num_page_entries - 1;
2481 if (dy < 0 && first_entry > 0)
2483 /* scroll page/line up */
2485 first_entry -= step;
2486 if (first_entry < 0)
2491 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2493 /* scroll page/line down */
2495 first_entry += step;
2496 if (first_entry + num_page_entries > max_page_entries)
2497 first_entry = MAX(0, max_page_entries - num_page_entries);
2504 choice += first_entry - first_entry_store[mode];
2506 if (choice < first_entry)
2508 choice = first_entry;
2510 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2513 else if (choice > first_entry + num_page_entries - 1)
2515 choice = first_entry + num_page_entries - 1;
2517 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2520 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2524 if (choice < first_entry ||
2525 choice > first_entry + num_page_entries - 1)
2526 first_entry += SIGN(dy);
2529 first_entry_store[mode] = first_entry;
2530 choice_store[mode] = choice;
2532 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2534 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2536 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2537 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2545 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2547 if (menu_info[choice].type & menu_navigation_type ||
2548 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2549 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2550 menu_info[choice].type & TYPE_PLAYER)
2551 button = MB_MENU_CHOICE;
2556 /* jump to next non-empty menu entry (up or down) */
2557 while (first_entry + y > 0 &&
2558 first_entry + y < max_page_entries - 1 &&
2559 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2562 if (!IN_VIS_MENU(x, y))
2564 choice += y - y_old;
2566 if (choice < first_entry)
2567 first_entry = choice;
2568 else if (choice > first_entry + num_page_entries - 1)
2569 first_entry = choice - num_page_entries + 1;
2571 if (first_entry >= 0 &&
2572 first_entry + num_page_entries <= max_page_entries)
2574 first_entry_store[mode] = first_entry;
2576 if (choice < first_entry)
2577 choice = first_entry;
2578 else if (choice > first_entry + num_page_entries - 1)
2579 choice = first_entry + num_page_entries - 1;
2581 choice_store[mode] = choice;
2583 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2585 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2587 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2588 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2595 if (!anyScrollbarGadgetActive() &&
2596 IN_VIS_MENU(x, y) &&
2597 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2598 y >= 0 && y < num_page_entries)
2602 if (first_entry + y != choice &&
2603 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2605 PlaySound(SND_MENU_ITEM_ACTIVATING);
2607 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2608 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2610 choice = choice_store[mode] = first_entry + y;
2614 PlaySound(SND_MENU_ITEM_SELECTING);
2616 for (i = 0; menu_info[i].type != 0; i++)
2618 if (menu_info[i].type & TYPE_LEAVE_MENU)
2620 void (*menu_callback_function)(void) = menu_info[i].value;
2624 menu_callback_function();
2626 /* absolutely needed because function changes 'menu_info'! */
2634 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2636 PlaySound(SND_MENU_ITEM_SELECTING);
2638 /* when selecting key headline, execute function for key value change */
2639 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2640 menu_info[first_entry + y + 1].type & TYPE_KEY)
2643 /* when selecting string value, execute function for list selection */
2644 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2645 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2648 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2650 void (*menu_callback_function)(void) =
2651 menu_info[first_entry + y].value;
2653 FadeSetFromType(menu_info[first_entry + y].type);
2655 menu_callback_function();
2657 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2658 menu_info == setup_info)
2660 changeSetupValue(y, first_entry + y, dx);
2666 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2668 menu_info = info_info;
2670 HandleMenuScreen(mx, my, dx, dy, button,
2671 info_mode, num_info_info, max_info_info);
2674 static int getMenuFontSpacing(int spacing_height, int font_nr)
2676 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2678 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2682 static int getMenuTextSpacing(int spacing_height, int font_nr)
2684 return (getMenuFontSpacing(spacing_height, font_nr) +
2685 EXTRA_SPACING(game_status));
2688 static int getMenuTextStep(int spacing_height, int font_nr)
2690 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2693 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2695 int font_title = MENU_INFO_FONT_TITLE;
2696 int font_error = FONT_TEXT_2;
2697 int font_foot = MENU_INFO_FONT_FOOT;
2698 int spacing_title = menu.headline1_spacing_info[info_mode];
2699 int ystep_title = getMenuTextStep(spacing_title, font_title);
2700 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2701 int ystart2 = ystart1 + ystep_title;
2702 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2704 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2706 FadeOut(REDRAW_FIELD);
2711 DrawTextSCentered(ystart1, font_title, text_title);
2712 DrawTextSCentered(ystart2, font_error, text_error);
2714 DrawTextSCentered(ybottom, font_foot,
2715 "Press any key or button for info menu");
2717 FadeIn(REDRAW_FIELD);
2720 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2722 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2723 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2724 int font_title = MENU_INFO_FONT_TITLE;
2725 int font_foot = MENU_INFO_FONT_FOOT;
2726 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2727 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2728 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2729 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2730 int ystep = MENU_SCREEN_INFO_YSTEP;
2731 int element, action, direction;
2739 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2740 infoscreen_step[i] = infoscreen_frame[i] = 0;
2745 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2747 DrawTextSCentered(ybottom, font_foot,
2748 "Press any key or button for next page");
2754 while (helpanim_info[j].element != HELPANIM_LIST_END)
2756 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2761 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2770 j += infoscreen_step[i - start];
2772 element = helpanim_info[j].element;
2773 action = helpanim_info[j].action;
2774 direction = helpanim_info[j].direction;
2777 element = EL_UNKNOWN;
2779 if (action != -1 && direction != -1)
2780 graphic = el_act_dir2img(element, action, direction);
2781 else if (action != -1)
2782 graphic = el_act2img(element, action);
2783 else if (direction != -1)
2784 graphic = el_dir2img(element, direction);
2786 graphic = el2img(element);
2788 delay = helpanim_info[j++].delay;
2793 if (infoscreen_frame[i - start] == 0)
2796 infoscreen_frame[i - start] = delay - 1;
2800 sync_frame = delay - infoscreen_frame[i - start];
2801 infoscreen_frame[i - start]--;
2804 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2806 if (!infoscreen_frame[i - start])
2807 infoscreen_step[i - start] = 0;
2811 if (!infoscreen_frame[i - start])
2812 infoscreen_step[i - start]++;
2813 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2819 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2821 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2822 graphic, sync_frame, USE_MASKING);
2825 DrawInfoScreen_HelpText(element, action, direction, i - start);
2830 redraw_mask |= REDRAW_FIELD;
2835 static char *getHelpText(int element, int action, int direction)
2837 char token[MAX_LINE_LEN];
2839 strcpy(token, element_info[element].token_name);
2842 strcat(token, element_action_info[action].suffix);
2844 if (direction != -1)
2845 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2847 return getHashEntry(helptext_info, token);
2850 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2852 int font_nr = FONT_INFO_ELEMENTS;
2853 int font_width = getFontWidth(font_nr);
2854 int font_height = getFontHeight(font_nr);
2855 int yoffset = (TILEX - 2 * font_height) / 2;
2856 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2857 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2858 int ystep = TILEY + 4;
2859 int pad_left = xstart - SX;
2860 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2861 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2862 int max_lines_per_text = 2;
2865 if (action != -1 && direction != -1) /* element.action.direction */
2866 text = getHelpText(element, action, direction);
2868 if (text == NULL && action != -1) /* element.action */
2869 text = getHelpText(element, action, -1);
2871 if (text == NULL && direction != -1) /* element.direction */
2872 text = getHelpText(element, -1, direction);
2874 if (text == NULL) /* base element */
2875 text = getHelpText(element, -1, -1);
2877 if (text == NULL) /* not found */
2878 text = "No description available";
2880 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2881 ystart += getFontHeight(font_nr) / 2;
2883 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2884 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2885 TRUE, FALSE, FALSE);
2888 void DrawInfoScreen_TitleScreen()
2890 SetGameStatus(GAME_MODE_TITLE);
2895 void HandleInfoScreen_TitleScreen(int button)
2897 HandleTitleScreen(0, 0, 0, 0, button);
2900 void DrawInfoScreen_Elements()
2902 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2904 FadeOut(REDRAW_FIELD);
2909 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2911 FadeIn(REDRAW_FIELD);
2914 void HandleInfoScreen_Elements(int button)
2916 static unsigned int info_delay = 0;
2917 static int num_anims;
2918 static int num_pages;
2920 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2923 if (button == MB_MENU_INITIALIZE)
2925 boolean new_element = TRUE;
2929 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2931 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2933 else if (new_element)
2936 new_element = FALSE;
2940 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2944 if (button == MB_MENU_LEAVE)
2946 PlaySound(SND_MENU_ITEM_SELECTING);
2948 info_mode = INFO_MODE_MAIN;
2953 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2955 if (button != MB_MENU_INITIALIZE)
2957 PlaySound(SND_MENU_ITEM_SELECTING);
2962 if (page >= num_pages)
2964 FadeMenuSoundsAndMusic();
2966 info_mode = INFO_MODE_MAIN;
2973 FadeSetNextScreen();
2975 if (button != MB_MENU_INITIALIZE)
2976 FadeOut(REDRAW_FIELD);
2978 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2980 if (button != MB_MENU_INITIALIZE)
2981 FadeIn(REDRAW_FIELD);
2985 if (DelayReached(&info_delay, GameFrameDelay))
2986 if (page < num_pages)
2987 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2989 PlayMenuSoundIfLoop();
2993 void DrawInfoScreen_Music()
2995 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2997 FadeOut(REDRAW_FIELD);
3004 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3006 FadeIn(REDRAW_FIELD);
3009 void HandleInfoScreen_Music(int button)
3011 static struct MusicFileInfo *list = NULL;
3012 int font_title = MENU_INFO_FONT_TITLE;
3013 int font_head = MENU_INFO_FONT_HEAD;
3014 int font_text = MENU_INFO_FONT_TEXT;
3015 int font_foot = MENU_INFO_FONT_FOOT;
3016 int spacing_title = menu.headline1_spacing_info[info_mode];
3017 int spacing_head = menu.headline2_spacing_info[info_mode];
3018 int ystep_title = getMenuTextStep(spacing_title, font_title);
3019 int ystep_head = getMenuTextStep(spacing_head, font_head);
3020 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3021 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3023 if (button == MB_MENU_INITIALIZE)
3025 list = music_file_info;
3029 FadeMenuSoundsAndMusic();
3034 DrawTextSCentered(ystart, font_title,
3035 "No music info for this level set.");
3037 DrawTextSCentered(ybottom, font_foot,
3038 "Press any key or button for info menu");
3044 if (button == MB_MENU_LEAVE)
3046 PlaySound(SND_MENU_ITEM_SELECTING);
3048 FadeMenuSoundsAndMusic();
3050 info_mode = INFO_MODE_MAIN;
3055 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3057 if (button != MB_MENU_INITIALIZE)
3059 PlaySound(SND_MENU_ITEM_SELECTING);
3067 FadeMenuSoundsAndMusic();
3069 info_mode = INFO_MODE_MAIN;
3075 FadeMenuSoundsAndMusic();
3077 if (list != music_file_info)
3078 FadeSetNextScreen();
3080 if (button != MB_MENU_INITIALIZE)
3081 FadeOut(REDRAW_FIELD);
3088 int sound = list->music;
3090 if (sound_info[sound].loop)
3091 PlaySoundLoop(sound);
3095 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3099 PlayMusic(list->music);
3101 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3104 ystart += ystep_title;
3106 if (!strEqual(list->title, UNKNOWN_NAME))
3108 if (!strEqual(list->title_header, UNKNOWN_NAME))
3110 DrawTextSCentered(ystart, font_head, list->title_header);
3111 ystart += ystep_head;
3114 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3115 ystart += ystep_head;
3118 if (!strEqual(list->artist, UNKNOWN_NAME))
3120 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3121 DrawTextSCentered(ystart, font_head, list->artist_header);
3123 DrawTextSCentered(ystart, font_head, "by");
3125 ystart += ystep_head;
3127 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3128 ystart += ystep_head;
3131 if (!strEqual(list->album, UNKNOWN_NAME))
3133 if (!strEqual(list->album_header, UNKNOWN_NAME))
3134 DrawTextSCentered(ystart, font_head, list->album_header);
3136 DrawTextSCentered(ystart, font_head, "from the album");
3138 ystart += ystep_head;
3140 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3141 ystart += ystep_head;
3144 if (!strEqual(list->year, UNKNOWN_NAME))
3146 if (!strEqual(list->year_header, UNKNOWN_NAME))
3147 DrawTextSCentered(ystart, font_head, list->year_header);
3149 DrawTextSCentered(ystart, font_head, "from the year");
3151 ystart += ystep_head;
3153 DrawTextFCentered(ystart, font_text, "%s", list->year);
3154 ystart += ystep_head;
3157 DrawTextSCentered(ybottom, FONT_TEXT_4,
3158 "Press any key or button for next page");
3160 if (button != MB_MENU_INITIALIZE)
3161 FadeIn(REDRAW_FIELD);
3164 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3165 PlaySoundLoop(list->music);
3168 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3170 int font_title = MENU_INFO_FONT_TITLE;
3171 int font_head = MENU_INFO_FONT_HEAD;
3172 int font_text = MENU_INFO_FONT_TEXT;
3173 int font_foot = MENU_INFO_FONT_FOOT;
3174 int spacing_title = menu.headline1_spacing_info[info_mode];
3175 int spacing_head = menu.headline2_spacing_info[info_mode];
3176 int spacing_para = menu.paragraph_spacing_info[info_mode];
3177 int spacing_line = menu.line_spacing_info[info_mode];
3178 int ystep_title = getMenuTextStep(spacing_title, font_title);
3179 int ystep_head = getMenuTextStep(spacing_head, font_head);
3180 int ystep_para = getMenuTextStep(spacing_para, font_text);
3181 int ystep_line = getMenuTextStep(spacing_line, font_text);
3182 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3183 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3188 DrawTextSCentered(ystart, font_title, "Credits:");
3189 ystart += ystep_title;
3193 DrawTextSCentered(ystart, font_head,
3194 "Special thanks to");
3195 ystart += ystep_head;
3196 DrawTextSCentered(ystart, font_text,
3198 ystart += ystep_head;
3199 DrawTextSCentered(ystart, font_head,
3201 ystart += ystep_head;
3202 DrawTextSCentered(ystart, font_text,
3203 "\"Boulder Dash\"");
3204 ystart += ystep_head;
3205 DrawTextSCentered(ystart, font_head,
3207 ystart += ystep_head;
3208 DrawTextSCentered(ystart, font_text,
3210 ystart += ystep_head;
3211 DrawTextSCentered(ystart, font_head,
3213 ystart += ystep_head;
3214 DrawTextSCentered(ystart, font_text,
3215 "First Star Software");
3217 else if (screen_nr == 1)
3219 DrawTextSCentered(ystart, font_head,
3220 "Special thanks to");
3221 ystart += ystep_head;
3222 DrawTextSCentered(ystart, font_text,
3223 "Klaus Heinz & Volker Wertich");
3224 ystart += ystep_head;
3225 DrawTextSCentered(ystart, font_head,
3227 ystart += ystep_head;
3228 DrawTextSCentered(ystart, font_text,
3229 "\"Emerald Mine\"");
3230 ystart += ystep_head;
3231 DrawTextSCentered(ystart, font_head,
3233 ystart += ystep_head;
3234 DrawTextSCentered(ystart, font_text,
3236 ystart += ystep_head;
3237 DrawTextSCentered(ystart, font_head,
3239 ystart += ystep_head;
3240 DrawTextSCentered(ystart, font_text,
3243 else if (screen_nr == 2)
3245 DrawTextSCentered(ystart, font_head,
3246 "Special thanks to");
3247 ystart += ystep_head;
3248 DrawTextSCentered(ystart, font_text,
3249 "Michael Stopp & Philip Jespersen");
3250 ystart += ystep_head;
3251 DrawTextSCentered(ystart, font_head,
3253 ystart += ystep_head;
3254 DrawTextSCentered(ystart, font_text,
3256 ystart += ystep_head;
3257 DrawTextSCentered(ystart, font_head,
3259 ystart += ystep_head;
3260 DrawTextSCentered(ystart, font_text,
3262 ystart += ystep_head;
3263 DrawTextSCentered(ystart, font_head,
3265 ystart += ystep_head;
3266 DrawTextSCentered(ystart, font_text,
3267 "Digital Integration");
3269 else if (screen_nr == 3)
3271 DrawTextSCentered(ystart, font_head,
3272 "Special thanks to");
3273 ystart += ystep_head;
3274 DrawTextSCentered(ystart, font_text,
3275 "Hiroyuki Imabayashi");
3276 ystart += ystep_head;
3277 DrawTextSCentered(ystart, font_head,
3279 ystart += ystep_head;
3280 DrawTextSCentered(ystart, font_text,
3282 ystart += ystep_head;
3283 DrawTextSCentered(ystart, font_head,
3285 ystart += ystep_head;
3286 DrawTextSCentered(ystart, font_text,
3288 ystart += ystep_head;
3289 DrawTextSCentered(ystart, font_head,
3291 ystart += ystep_head;
3292 DrawTextSCentered(ystart, font_text,
3295 else if (screen_nr == 4)
3297 DrawTextSCentered(ystart, font_head,
3298 "Special thanks to");
3299 ystart += ystep_head;
3300 DrawTextSCentered(ystart, font_text,
3302 ystart += ystep_head;
3303 DrawTextSCentered(ystart, font_head,
3305 ystart += ystep_head;
3306 DrawTextSCentered(ystart, font_text,
3307 "J\xfcrgen Bonhagen");
3308 ystart += ystep_head;
3309 DrawTextSCentered(ystart, font_head,
3310 "for the continuous creation");
3311 ystart += ystep_line;
3312 DrawTextSCentered(ystart, font_head,
3313 "of outstanding level sets");
3315 else if (screen_nr == 5)
3317 DrawTextSCentered(ystart, font_head,
3319 ystart += ystep_head;
3320 DrawTextSCentered(ystart, font_text,
3322 ystart += ystep_head;
3323 DrawTextSCentered(ystart, font_head,
3324 "for ideas and inspiration by");
3325 ystart += ystep_head;
3326 DrawTextSCentered(ystart, font_text,
3328 ystart += ystep_para;
3330 DrawTextSCentered(ystart, font_head,
3332 ystart += ystep_head;
3333 DrawTextSCentered(ystart, font_text,
3335 ystart += ystep_head;
3336 DrawTextSCentered(ystart, font_head,
3337 "for ideas and inspiration by");
3338 ystart += ystep_head;
3339 DrawTextSCentered(ystart, font_text,
3342 else if (screen_nr == 6)
3344 DrawTextSCentered(ystart, font_head,
3346 ystart += ystep_head;
3347 DrawTextSCentered(ystart, font_text,
3349 ystart += ystep_head;
3350 DrawTextSCentered(ystart, font_head,
3351 "for the code base used for the");
3352 ystart += ystep_line;
3353 DrawTextSCentered(ystart, font_head,
3354 "native Emerald Mine engine");
3356 else if (screen_nr == 7)
3358 DrawTextSCentered(ystart, font_head,
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_text,
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_head,
3365 "for the initial DOS port");
3366 ystart += ystep_para;
3368 DrawTextSCentered(ystart, font_head,
3370 ystart += ystep_head;
3371 DrawTextSCentered(ystart, font_text,
3373 ystart += ystep_head;
3374 DrawTextSCentered(ystart, font_head,
3375 "for some additional toons");
3377 else if (screen_nr == 8)
3379 DrawTextSCentered(ystart, font_head,
3380 "And not to forget:");
3381 ystart += ystep_head;
3382 DrawTextSCentered(ystart, font_head,
3384 ystart += ystep_head;
3385 DrawTextSCentered(ystart, font_text,
3386 "All those who contributed");
3387 ystart += ystep_line;
3388 DrawTextSCentered(ystart, font_text,
3389 "levels to this game");
3390 ystart += ystep_line;
3391 DrawTextSCentered(ystart, font_text,
3395 DrawTextSCentered(ybottom, font_foot,
3396 "Press any key or button for next page");
3399 void DrawInfoScreen_Credits()
3401 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3403 FadeMenuSoundsAndMusic();
3405 FadeOut(REDRAW_FIELD);
3407 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3409 FadeIn(REDRAW_FIELD);
3412 void HandleInfoScreen_Credits(int button)
3414 static int screen_nr = 0;
3415 int num_screens = 9;
3417 if (button == MB_MENU_INITIALIZE)
3421 // DrawInfoScreen_CreditsScreen(screen_nr);
3424 if (button == MB_MENU_LEAVE)
3426 PlaySound(SND_MENU_ITEM_SELECTING);
3428 info_mode = INFO_MODE_MAIN;
3433 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3435 if (button != MB_MENU_INITIALIZE)
3437 PlaySound(SND_MENU_ITEM_SELECTING);
3442 if (screen_nr >= num_screens)
3444 FadeMenuSoundsAndMusic();
3446 info_mode = INFO_MODE_MAIN;
3453 FadeSetNextScreen();
3455 if (button != MB_MENU_INITIALIZE)
3456 FadeOut(REDRAW_FIELD);
3458 DrawInfoScreen_CreditsScreen(screen_nr);
3460 if (button != MB_MENU_INITIALIZE)
3461 FadeIn(REDRAW_FIELD);
3465 PlayMenuSoundIfLoop();
3469 void DrawInfoScreen_Program()
3471 int font_title = MENU_INFO_FONT_TITLE;
3472 int font_head = MENU_INFO_FONT_HEAD;
3473 int font_text = MENU_INFO_FONT_TEXT;
3474 int font_foot = MENU_INFO_FONT_FOOT;
3475 int spacing_title = menu.headline1_spacing_info[info_mode];
3476 int spacing_head = menu.headline2_spacing_info[info_mode];
3477 int spacing_para = menu.paragraph_spacing_info[info_mode];
3478 int spacing_line = menu.line_spacing_info[info_mode];
3479 int ystep_title = getMenuTextStep(spacing_title, font_title);
3480 int ystep_head = getMenuTextStep(spacing_head, font_head);
3481 int ystep_para = getMenuTextStep(spacing_para, font_text);
3482 int ystep_line = getMenuTextStep(spacing_line, font_text);
3483 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3484 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3486 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3488 FadeOut(REDRAW_FIELD);
3493 DrawTextSCentered(ystart, font_title, "Program Information:");
3494 ystart += ystep_title;
3496 DrawTextSCentered(ystart, font_head,
3497 "This game is Freeware!");
3498 ystart += ystep_head;
3499 DrawTextSCentered(ystart, font_head,
3500 "If you like it, send e-mail to:");
3501 ystart += ystep_head;
3502 DrawTextSCentered(ystart, font_text,
3503 setup.internal.program_email);
3504 ystart += ystep_para;
3506 DrawTextSCentered(ystart, font_head,
3507 "More information and levels:");
3508 ystart += ystep_head;
3509 DrawTextSCentered(ystart, font_text,
3510 setup.internal.program_website);
3511 ystart += ystep_para;
3513 DrawTextSCentered(ystart, font_head,
3514 "If you have created new levels,");
3515 ystart += ystep_line;
3516 DrawTextSCentered(ystart, font_head,
3517 "send them to me to include them!");
3518 ystart += ystep_head;
3519 DrawTextSCentered(ystart, font_head,
3522 DrawTextSCentered(ybottom, font_foot,
3523 "Press any key or button for info menu");
3525 FadeIn(REDRAW_FIELD);
3528 void HandleInfoScreen_Program(int button)
3530 if (button == MB_MENU_LEAVE)
3532 PlaySound(SND_MENU_ITEM_SELECTING);
3534 info_mode = INFO_MODE_MAIN;
3539 else if (button == MB_MENU_CHOICE)
3541 PlaySound(SND_MENU_ITEM_SELECTING);
3543 FadeMenuSoundsAndMusic();
3545 info_mode = INFO_MODE_MAIN;
3550 PlayMenuSoundIfLoop();
3554 void DrawInfoScreen_Version()
3556 int font_title = MENU_INFO_FONT_TITLE;
3557 int font_head = MENU_INFO_FONT_HEAD;
3558 int font_text = MENU_INFO_FONT_TEXT;
3559 int font_foot = MENU_INFO_FONT_FOOT;
3560 int spacing_title = menu.headline1_spacing_info[info_mode];
3561 int spacing_head = menu.headline2_spacing_info[info_mode];
3562 int spacing_para = menu.paragraph_spacing_info[info_mode];
3563 int spacing_line = menu.line_spacing_info[info_mode];
3564 int xstep = getFontWidth(font_text);
3565 int ystep_title = getMenuTextStep(spacing_title, font_title);
3566 int ystep_head = getMenuTextStep(spacing_head, font_head);
3567 int ystep_para = getMenuTextStep(spacing_para, font_text);
3568 int ystep_line = getMenuTextStep(spacing_line, font_text);
3569 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3570 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3571 int xstart1 = mSX - SX + 2 * xstep;
3572 int xstart2 = mSX - SX + 18 * xstep;
3573 int xstart3 = mSX - SX + 28 * xstep;
3574 SDL_version sdl_version_compiled;
3575 const SDL_version *sdl_version_linked;
3576 int driver_name_len = 10;
3577 #if defined(TARGET_SDL2)
3578 SDL_version sdl_version_linked_ext;
3579 const char *driver_name = NULL;
3581 char driver_name[driver_name_len];
3584 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3586 FadeOut(REDRAW_FIELD);
3591 DrawTextSCentered(ystart, font_title, "Version Information:");
3592 ystart += ystep_title;
3594 DrawTextF(xstart1, ystart, font_head, "Name");
3595 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3596 ystart += ystep_line;
3598 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3600 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3601 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3602 ystart += ystep_line;
3604 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3605 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3606 ystart += ystep_line;
3610 DrawTextF(xstart1, ystart, font_head, "Version");
3611 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3612 ystart += ystep_line;
3615 DrawTextF(xstart1, ystart, font_head, "Platform");
3616 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3617 ystart += ystep_line;
3619 DrawTextF(xstart1, ystart, font_head, "Target");
3620 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3621 ystart += ystep_line;
3623 DrawTextF(xstart1, ystart, font_head, "Source date");
3624 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3625 ystart += ystep_para;
3627 DrawTextF(xstart1, ystart, font_head, "Library");
3628 DrawTextF(xstart2, ystart, font_head, "compiled");
3629 DrawTextF(xstart3, ystart, font_head, "linked");
3630 ystart += ystep_head;
3632 SDL_VERSION(&sdl_version_compiled);
3633 #if defined(TARGET_SDL2)
3634 SDL_GetVersion(&sdl_version_linked_ext);
3635 sdl_version_linked = &sdl_version_linked_ext;
3637 sdl_version_linked = SDL_Linked_Version();
3640 DrawTextF(xstart1, ystart, font_text, "SDL");
3641 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3642 sdl_version_compiled.major,
3643 sdl_version_compiled.minor,
3644 sdl_version_compiled.patch);
3645 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3646 sdl_version_linked->major,
3647 sdl_version_linked->minor,
3648 sdl_version_linked->patch);
3649 ystart += ystep_line;
3651 SDL_IMAGE_VERSION(&sdl_version_compiled);
3652 sdl_version_linked = IMG_Linked_Version();
3654 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3655 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3656 sdl_version_compiled.major,
3657 sdl_version_compiled.minor,
3658 sdl_version_compiled.patch);
3659 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3660 sdl_version_linked->major,
3661 sdl_version_linked->minor,
3662 sdl_version_linked->patch);
3663 ystart += ystep_line;
3665 SDL_MIXER_VERSION(&sdl_version_compiled);
3666 sdl_version_linked = Mix_Linked_Version();
3668 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3669 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3670 sdl_version_compiled.major,
3671 sdl_version_compiled.minor,
3672 sdl_version_compiled.patch);
3673 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3674 sdl_version_linked->major,
3675 sdl_version_linked->minor,
3676 sdl_version_linked->patch);
3677 ystart += ystep_line;
3679 SDL_NET_VERSION(&sdl_version_compiled);
3680 sdl_version_linked = SDLNet_Linked_Version();
3682 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3683 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3684 sdl_version_compiled.major,
3685 sdl_version_compiled.minor,
3686 sdl_version_compiled.patch);
3687 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3688 sdl_version_linked->major,
3689 sdl_version_linked->minor,
3690 sdl_version_linked->patch);
3691 ystart += ystep_para;
3693 DrawTextF(xstart1, ystart, font_head, "Driver");
3694 DrawTextF(xstart2, ystart, font_head, "Requested");
3695 DrawTextF(xstart3, ystart, font_head, "Used");
3696 ystart += ystep_head;
3698 #if defined(TARGET_SDL2)
3699 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3701 SDL_VideoDriverName(driver_name, driver_name_len);
3704 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3705 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3706 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3707 ystart += ystep_line;
3709 #if defined(TARGET_SDL2)
3710 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3712 SDL_AudioDriverName(driver_name, driver_name_len);
3715 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3716 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3717 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3719 DrawTextSCentered(ybottom, font_foot,
3720 "Press any key or button for info menu");
3722 FadeIn(REDRAW_FIELD);
3725 void HandleInfoScreen_Version(int button)
3727 if (button == MB_MENU_LEAVE)
3729 PlaySound(SND_MENU_ITEM_SELECTING);
3731 info_mode = INFO_MODE_MAIN;
3736 else if (button == MB_MENU_CHOICE)
3738 PlaySound(SND_MENU_ITEM_SELECTING);
3740 FadeMenuSoundsAndMusic();
3742 info_mode = INFO_MODE_MAIN;
3747 PlayMenuSoundIfLoop();
3751 void DrawInfoScreen_LevelSet()
3753 struct TitleMessageInfo *tmi = &readme;
3754 char *filename = getLevelSetInfoFilename();
3755 char *title = "Level Set Information:";
3756 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3757 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3759 if (filename == NULL)
3761 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3766 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3768 FadeOut(REDRAW_FIELD);
3773 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3775 /* if x position set to "-1", automatically determine by playfield width */
3777 tmi->x = SXSIZE / 2;
3779 /* if y position set to "-1", use static default value */
3783 /* if width set to "-1", automatically determine by playfield width */
3784 if (tmi->width == -1)
3785 tmi->width = SXSIZE - 2 * TILEX;
3787 /* if height set to "-1", automatically determine by playfield height */
3788 if (tmi->height == -1)
3789 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3791 /* if chars set to "-1", automatically determine by text and font width */
3792 if (tmi->chars == -1)
3793 tmi->chars = tmi->width / getFontWidth(tmi->font);
3795 tmi->width = tmi->chars * getFontWidth(tmi->font);
3797 /* if lines set to "-1", automatically determine by text and font height */
3798 if (tmi->lines == -1)
3799 tmi->lines = tmi->height / getFontHeight(tmi->font);
3801 tmi->height = tmi->lines * getFontHeight(tmi->font);
3803 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3804 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3805 tmi->autowrap, tmi->centered, tmi->parse_comments);
3807 DrawTextSCentered(ybottom, FONT_TEXT_4,
3808 "Press any key or button for info menu");
3810 FadeIn(REDRAW_FIELD);
3813 void HandleInfoScreen_LevelSet(int button)
3815 if (button == MB_MENU_LEAVE)
3817 PlaySound(SND_MENU_ITEM_SELECTING);
3819 info_mode = INFO_MODE_MAIN;
3824 else if (button == MB_MENU_CHOICE)
3826 PlaySound(SND_MENU_ITEM_SELECTING);
3828 FadeMenuSoundsAndMusic();
3830 info_mode = INFO_MODE_MAIN;
3835 PlayMenuSoundIfLoop();
3839 static void DrawInfoScreen()
3841 if (info_mode == INFO_MODE_TITLE)
3842 DrawInfoScreen_TitleScreen();
3843 else if (info_mode == INFO_MODE_ELEMENTS)
3844 DrawInfoScreen_Elements();
3845 else if (info_mode == INFO_MODE_MUSIC)
3846 DrawInfoScreen_Music();
3847 else if (info_mode == INFO_MODE_CREDITS)
3848 DrawInfoScreen_Credits();
3849 else if (info_mode == INFO_MODE_PROGRAM)
3850 DrawInfoScreen_Program();
3851 else if (info_mode == INFO_MODE_VERSION)
3852 DrawInfoScreen_Version();
3853 else if (info_mode == INFO_MODE_LEVELSET)
3854 DrawInfoScreen_LevelSet();
3856 DrawInfoScreen_Main();
3858 if (info_mode != INFO_MODE_MAIN &&
3859 info_mode != INFO_MODE_TITLE &&
3860 info_mode != INFO_MODE_MUSIC)
3861 PlayMenuSoundsAndMusic();
3864 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3866 if (info_mode == INFO_MODE_TITLE)
3867 HandleInfoScreen_TitleScreen(button);
3868 else if (info_mode == INFO_MODE_ELEMENTS)
3869 HandleInfoScreen_Elements(button);
3870 else if (info_mode == INFO_MODE_MUSIC)
3871 HandleInfoScreen_Music(button);
3872 else if (info_mode == INFO_MODE_CREDITS)
3873 HandleInfoScreen_Credits(button);
3874 else if (info_mode == INFO_MODE_PROGRAM)
3875 HandleInfoScreen_Program(button);
3876 else if (info_mode == INFO_MODE_VERSION)
3877 HandleInfoScreen_Version(button);
3878 else if (info_mode == INFO_MODE_LEVELSET)
3879 HandleInfoScreen_LevelSet(button);
3881 HandleInfoScreen_Main(mx, my, dx, dy, button);
3885 /* ========================================================================= */
3886 /* type name functions */
3887 /* ========================================================================= */
3889 void HandleTypeName(int newxpos, Key key)
3891 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3892 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3893 struct TextPosInfo *pos = mci->pos_input;
3894 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3895 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3896 static int xpos = 0;
3897 int font_nr = pos->font;
3898 int font_active_nr = FONT_ACTIVE(font_nr);
3899 int font_width = getFontWidth(font_active_nr);
3900 char key_char = getValidConfigValueChar(getCharFromKey(key));
3901 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3902 boolean is_active = TRUE;
3904 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3908 strcpy(last_player_name, setup.player_name);
3912 StartTextInput(startx, starty, pos->width, pos->height);
3914 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3916 setup.player_name[xpos] = key_char;
3917 setup.player_name[xpos + 1] = 0;
3921 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3925 setup.player_name[xpos] = 0;
3927 else if (key == KSYM_Return && xpos > 0)
3933 SetGameStatus(GAME_MODE_MAIN);
3935 else if (key == KSYM_Escape)
3937 strcpy(setup.player_name, last_player_name);
3941 SetGameStatus(GAME_MODE_MAIN);
3946 pos->width = (strlen(setup.player_name) + 1) * font_width;
3947 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3949 DrawText(startx, starty, setup.player_name, font_active_nr);
3950 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3954 pos->width = strlen(setup.player_name) * font_width;
3955 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3957 DrawText(startx, starty, setup.player_name, font_nr);
3964 /* ========================================================================= */
3965 /* tree menu functions */
3966 /* ========================================================================= */
3968 static void DrawChooseTree(TreeInfo **ti_ptr)
3970 int fade_mask = REDRAW_FIELD;
3972 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3973 fade_mask = REDRAW_ALL;
3975 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3977 SetGameStatus(GAME_MODE_MAIN);
3986 FreeScreenGadgets();
3987 CreateScreenGadgets();
3991 /* needed if different viewport properties defined for choosing level (set) */
3992 ChangeViewportPropertiesIfNeeded();
3994 if (game_status == GAME_MODE_LEVELNR)
3995 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3996 else if (game_status == GAME_MODE_LEVELS)
3997 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4001 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4003 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4004 MapScreenTreeGadgets(*ti_ptr);
4006 DrawMaskedBorder(fade_mask);
4011 static void drawChooseTreeList(int first_entry, int num_page_entries,
4015 char *title_string = NULL;
4016 int yoffset_sets = MENU_TITLE1_YPOS;
4017 int yoffset_setup = 16;
4018 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4019 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4021 title_string = ti->infotext;
4023 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4025 clearMenuListArea();
4027 for (i = 0; i < num_page_entries; i++)
4029 TreeInfo *node, *node_first;
4030 int entry_pos = first_entry + i;
4031 int xpos = MENU_SCREEN_START_XPOS;
4032 int ypos = MENU_SCREEN_START_YPOS + i;
4033 int startx = mSX + xpos * 32;
4034 int starty = mSY + ypos * 32;
4035 int font_nr = FONT_TEXT_1;
4036 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4037 int startx_text = startx + font_xoffset;
4038 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4039 int text_size = startx_scrollbar - startx_text;
4040 int max_buffer_len = text_size / getFontWidth(font_nr);
4041 char buffer[max_buffer_len + 1];
4043 node_first = getTreeInfoFirstGroupEntry(ti);
4044 node = getTreeInfoFromPos(node_first, entry_pos);
4046 strncpy(buffer, node->name, max_buffer_len);
4047 buffer[max_buffer_len] = '\0';
4049 DrawText(startx, starty, buffer, font_nr + node->color);
4051 if (node->parent_link)
4052 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4053 else if (node->level_group)
4054 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4056 initCursor(i, IMG_MENU_BUTTON);
4059 redraw_mask |= REDRAW_FIELD;
4062 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4064 TreeInfo *node, *node_first;
4065 int x, last_redraw_mask = redraw_mask;
4066 int ypos = MENU_TITLE2_YPOS;
4067 int font_nr = FONT_TITLE_2;
4069 if (ti->type == TREE_TYPE_LEVEL_NR)
4070 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4072 if (ti->type != TREE_TYPE_LEVEL_DIR)
4075 node_first = getTreeInfoFirstGroupEntry(ti);
4076 node = getTreeInfoFromPos(node_first, entry_pos);
4078 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4080 if (node->parent_link)
4081 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4082 node->node_parent->name);
4083 else if (node->level_group)
4084 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4086 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4087 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4088 node->levels, (node->levels > 1 ? "levels" : "level"),
4091 /* let BackToFront() redraw only what is needed */
4092 redraw_mask = last_redraw_mask;
4093 for (x = 0; x < SCR_FIELDX; x++)
4094 MarkTileDirty(x, 1);
4097 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4100 TreeInfo *ti = *ti_ptr;
4102 int y = ti->cl_cursor;
4103 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4104 int num_entries = numTreeInfoInGroup(ti);
4105 int num_page_entries;
4106 boolean position_set_by_scrollbar = (dx == 999);
4108 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4109 num_page_entries = num_entries;
4111 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4113 if (button == MB_MENU_INITIALIZE)
4115 int num_entries = numTreeInfoInGroup(ti);
4116 int entry_pos = posTreeInfo(ti);
4118 if (ti->cl_first == -1)
4120 /* only on initialization */
4121 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4122 ti->cl_cursor = entry_pos - ti->cl_first;
4124 else if (ti->cl_cursor >= num_page_entries ||
4125 (num_entries > num_page_entries &&
4126 num_entries - ti->cl_first < num_page_entries))
4128 /* only after change of list size (by custom graphic configuration) */
4129 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4130 ti->cl_cursor = entry_pos - ti->cl_first;
4133 if (position_set_by_scrollbar)
4136 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4139 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4140 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4141 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4145 else if (button == MB_MENU_LEAVE)
4149 PlaySound(SND_MENU_ITEM_SELECTING);
4151 if (ti->node_parent)
4153 *ti_ptr = ti->node_parent;
4154 DrawChooseTree(ti_ptr);
4156 else if (game_status == GAME_MODE_SETUP)
4158 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4159 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4160 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4162 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4163 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4164 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4165 execSetupGraphics();
4166 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4167 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4168 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4170 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4171 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4172 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4173 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4174 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4175 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4176 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4177 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4184 if (game_status == GAME_MODE_LEVELNR)
4186 int new_level_nr = atoi(level_number_current->identifier);
4188 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4191 SetGameStatus(GAME_MODE_MAIN);
4199 if (mx || my) /* mouse input */
4201 x = (mx - mSX) / 32;
4202 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4204 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4206 /* move cursor instead of scrolling when already at start/end of list */
4207 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4209 else if (dy == +1 * SCROLL_LINE &&
4210 ti->cl_first + num_page_entries == num_entries)
4213 /* handle scrolling screen one line or page */
4214 if (ti->cl_cursor + dy < 0 ||
4215 ti->cl_cursor + dy > num_page_entries - 1)
4217 boolean redraw = FALSE;
4219 if (ABS(dy) == SCROLL_PAGE)
4220 step = num_page_entries - 1;
4222 if (dy < 0 && ti->cl_first > 0)
4224 /* scroll page/line up */
4226 ti->cl_first -= step;
4227 if (ti->cl_first < 0)
4232 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4234 /* scroll page/line down */
4236 ti->cl_first += step;
4237 if (ti->cl_first + num_page_entries > num_entries)
4238 ti->cl_first = MAX(0, num_entries - num_page_entries);
4245 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4246 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4247 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4249 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4256 /* handle moving cursor one line */
4257 y = ti->cl_cursor + dy;
4262 TreeInfo *node_first, *node_cursor;
4263 int entry_pos = ti->cl_first + y;
4265 node_first = getTreeInfoFirstGroupEntry(ti);
4266 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4268 if (node_cursor->node_group)
4272 PlaySound(SND_MENU_ITEM_SELECTING);
4274 node_cursor->cl_first = ti->cl_first;
4275 node_cursor->cl_cursor = ti->cl_cursor;
4276 *ti_ptr = node_cursor->node_group;
4277 DrawChooseTree(ti_ptr);
4282 else if (dx == -1 && ti->node_parent)
4286 PlaySound(SND_MENU_ITEM_SELECTING);
4288 *ti_ptr = ti->node_parent;
4289 DrawChooseTree(ti_ptr);
4294 if (!anyScrollbarGadgetActive() &&
4295 IN_VIS_MENU(x, y) &&
4296 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4297 y >= 0 && y < num_page_entries)
4301 if (y != ti->cl_cursor)
4303 PlaySound(SND_MENU_ITEM_ACTIVATING);
4305 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4306 drawChooseTreeCursor(y, TRUE);
4307 drawChooseTreeInfo(ti->cl_first + y, ti);
4313 if (game_status == GAME_MODE_SETUP)
4315 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4316 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4317 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4319 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4320 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4321 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4322 execSetupGraphics();
4323 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4324 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4325 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4327 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4328 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4329 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4330 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4331 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4332 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4333 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4334 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4343 TreeInfo *node_first, *node_cursor;
4344 int entry_pos = ti->cl_first + y;
4346 PlaySound(SND_MENU_ITEM_SELECTING);
4348 node_first = getTreeInfoFirstGroupEntry(ti);
4349 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4351 if (node_cursor->node_group)
4355 node_cursor->cl_first = ti->cl_first;
4356 node_cursor->cl_cursor = ti->cl_cursor;
4357 *ti_ptr = node_cursor->node_group;
4358 DrawChooseTree(ti_ptr);
4360 else if (node_cursor->parent_link)
4364 *ti_ptr = node_cursor->node_parent;
4365 DrawChooseTree(ti_ptr);
4371 node_cursor->cl_first = ti->cl_first;
4372 node_cursor->cl_cursor = ti->cl_cursor;
4373 *ti_ptr = node_cursor;
4375 if (ti->type == TREE_TYPE_LEVEL_DIR)
4377 LoadLevelSetup_SeriesInfo();
4379 SaveLevelSetup_LastSeries();
4380 SaveLevelSetup_SeriesInfo();
4384 if (game_status == GAME_MODE_SETUP)
4386 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4387 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4388 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4390 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4391 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4392 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4393 execSetupGraphics();
4394 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4395 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4396 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4398 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4399 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4400 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4401 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4402 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4403 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4404 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4405 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4412 if (game_status == GAME_MODE_LEVELNR)
4414 int new_level_nr = atoi(level_number_current->identifier);
4416 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4419 SetGameStatus(GAME_MODE_MAIN);
4428 void DrawChooseLevelSet()
4430 FadeMenuSoundsAndMusic();
4432 DrawChooseTree(&leveldir_current);
4434 PlayMenuSoundsAndMusic();
4437 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4439 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4442 void DrawChooseLevelNr()
4446 FadeMenuSoundsAndMusic();
4448 if (level_number != NULL)
4450 freeTreeInfo(level_number);
4452 level_number = NULL;
4455 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4457 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4458 char identifier[32], name[32];
4461 /* temporarily load level info to get level name */
4462 LoadLevelInfoOnly(i);
4464 ti->node_top = &level_number;
4465 ti->sort_priority = 10000 + value;
4466 ti->color = (level.no_level_file ? FC_BLUE :
4467 LevelStats_getSolved(i) ? FC_GREEN :
4468 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4470 snprintf(identifier, sizeof(identifier), "%d", value);
4471 snprintf(name, sizeof(name), "%03d: %s", value,
4472 (level.no_level_file ? "(no file)" : level.name));
4474 setString(&ti->identifier, identifier);
4475 setString(&ti->name, name);
4476 setString(&ti->name_sorting, name);
4478 pushTreeInfo(&level_number, ti);
4481 /* sort level number values to start with lowest level number */
4482 sortTreeInfo(&level_number);
4484 /* set current level number to current level number */
4485 level_number_current =
4486 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4488 /* if that also fails, set current level number to first available level */
4489 if (level_number_current == NULL)
4490 level_number_current = level_number;
4492 DrawChooseTree(&level_number_current);
4494 PlayMenuSoundsAndMusic();
4497 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4499 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4502 void DrawHallOfFame(int level_nr, int highlight_position)
4504 int fade_mask = REDRAW_FIELD;
4506 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4507 fade_mask = REDRAW_ALL;
4510 FadeMenuSoundsAndMusic();
4512 /* (this is needed when called from GameEnd() after winning a game) */
4513 KeyboardAutoRepeatOn();
4515 /* (this is needed when called from GameEnd() after winning a game) */
4516 SetDrawDeactivationMask(REDRAW_NONE);
4517 SetDrawBackgroundMask(REDRAW_FIELD);
4519 if (highlight_position < 0)
4520 LoadScore(level_nr);
4522 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4524 FadeSetEnterScreen();
4528 /* needed if different viewport properties defined for scores */
4529 ChangeViewportPropertiesIfNeeded();
4531 PlayMenuSoundsAndMusic();
4533 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4535 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4537 DrawMaskedBorder(fade_mask);
4542 static void drawHallOfFameList(int level_nr, int first_entry,
4543 int highlight_position)
4547 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4550 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4551 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4552 "HighScores of Level %d", level_nr);
4554 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4556 int entry = first_entry + i;
4557 boolean active = (entry == highlight_position);
4558 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4559 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4560 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4561 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4562 int dxoff = getFontDrawOffsetX(font_nr1);
4563 int dx1 = 3 * getFontWidth(font_nr1);
4564 int dx2 = dx1 + getFontWidth(font_nr1);
4565 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4566 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4567 int sy = mSY + 64 + i * 32;
4569 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4570 DrawText(mSX + dx1, sy, ".", font_nr1);
4572 for (j = 0; j < num_dots; j++)
4573 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4575 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4576 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4578 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4581 redraw_mask |= REDRAW_FIELD;
4584 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4586 static int level_nr = 0;
4587 static int first_entry = 0;
4588 static int highlight_position = 0;
4589 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4591 if (button == MB_MENU_INITIALIZE)
4595 highlight_position = my;
4597 drawHallOfFameList(level_nr, first_entry, highlight_position);
4602 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4603 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4607 if (first_entry > 0)
4609 first_entry -= step;
4610 if (first_entry < 0)
4613 drawHallOfFameList(level_nr, first_entry, highlight_position);
4618 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4620 first_entry += step;
4621 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4622 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4624 drawHallOfFameList(level_nr, first_entry, highlight_position);
4627 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4629 PlaySound(SND_MENU_ITEM_SELECTING);
4631 FadeSound(SND_BACKGROUND_SCORES);
4633 if (game_status_last_screen != GAME_MODE_PLAYING ||
4634 !setup.auto_play_next_level || !setup.increment_levels)
4636 SetGameStatus(GAME_MODE_MAIN);
4642 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4646 if (game_status == GAME_MODE_SCORES)
4647 PlayMenuSoundIfLoop();
4651 /* ========================================================================= */
4652 /* setup screen functions */
4653 /* ========================================================================= */
4655 static struct TokenInfo *setup_info;
4656 static int num_setup_info; /* number of setup entries shown on screen */
4657 static int max_setup_info; /* total number of setup entries in list */
4659 static char *window_size_text;
4660 static char *scaling_type_text;
4661 static char *rendering_mode_text;
4662 static char *scroll_delay_text;
4663 static char *snapshot_mode_text;
4664 static char *game_speed_text;
4665 static char *graphics_set_name;
4666 static char *sounds_set_name;
4667 static char *music_set_name;
4668 static char *volume_simple_text;
4669 static char *volume_loops_text;
4670 static char *volume_music_text;
4671 static char *touch_controls_text;
4672 static char *move_distance_text;
4673 static char *drop_distance_text;
4674 static char *transparency_text;
4675 static char *grid_size_text[2][2];
4677 static void execSetupMain()
4679 setup_mode = SETUP_MODE_MAIN;
4684 static void execSetupGame_setGameSpeeds()
4686 if (game_speeds == NULL)
4690 for (i = 0; game_speeds_list[i].value != -1; i++)
4692 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4693 char identifier[32], name[32];
4694 int value = game_speeds_list[i].value;
4695 char *text = game_speeds_list[i].text;
4697 ti->node_top = &game_speeds;
4698 ti->sort_priority = 10000 - value;
4700 sprintf(identifier, "%d", value);
4701 sprintf(name, "%s", text);
4703 setString(&ti->identifier, identifier);
4704 setString(&ti->name, name);
4705 setString(&ti->name_sorting, name);
4706 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4708 pushTreeInfo(&game_speeds, ti);
4711 /* sort game speed values to start with slowest game speed */
4712 sortTreeInfo(&game_speeds);
4714 /* set current game speed to configured game speed value */
4715 game_speed_current =
4716 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4718 /* if that fails, set current game speed to reliable default value */
4719 if (game_speed_current == NULL)
4720 game_speed_current =
4721 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4723 /* if that also fails, set current game speed to first available speed */
4724 if (game_speed_current == NULL)
4725 game_speed_current = game_speeds;
4728 setup.game_frame_delay = atoi(game_speed_current->identifier);
4730 /* needed for displaying game speed text instead of identifier */
4731 game_speed_text = game_speed_current->name;
4734 static void execSetupGame_setScrollDelays()
4736 if (scroll_delays == NULL)
4740 for (i = 0; scroll_delays_list[i].value != -1; i++)
4742 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4743 char identifier[32], name[32];
4744 int value = scroll_delays_list[i].value;
4745 char *text = scroll_delays_list[i].text;
4747 ti->node_top = &scroll_delays;
4748 ti->sort_priority = value;
4750 sprintf(identifier, "%d", value);
4751 sprintf(name, "%s", text);
4753 setString(&ti->identifier, identifier);
4754 setString(&ti->name, name);
4755 setString(&ti->name_sorting, name);
4756 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4758 pushTreeInfo(&scroll_delays, ti);
4761 /* sort scroll delay values to start with lowest scroll delay value */
4762 sortTreeInfo(&scroll_delays);
4764 /* set current scroll delay value to configured scroll delay value */
4765 scroll_delay_current =
4766 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4768 /* if that fails, set current scroll delay to reliable default value */
4769 if (scroll_delay_current == NULL)
4770 scroll_delay_current =
4771 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4773 /* if that also fails, set current scroll delay to first available value */
4774 if (scroll_delay_current == NULL)
4775 scroll_delay_current = scroll_delays;
4778 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4780 /* needed for displaying scroll delay text instead of identifier */
4781 scroll_delay_text = scroll_delay_current->name;
4784 static void execSetupGame_setSnapshotModes()
4786 if (snapshot_modes == NULL)
4790 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4792 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4793 char identifier[32], name[32];
4794 char *value = snapshot_modes_list[i].value;
4795 char *text = snapshot_modes_list[i].text;
4797 ti->node_top = &snapshot_modes;
4798 ti->sort_priority = i;
4800 sprintf(identifier, "%s", value);
4801 sprintf(name, "%s", text);
4803 setString(&ti->identifier, identifier);
4804 setString(&ti->name, name);
4805 setString(&ti->name_sorting, name);
4806 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4808 pushTreeInfo(&snapshot_modes, ti);
4811 /* sort snapshot mode values to start with lowest snapshot mode value */
4812 sortTreeInfo(&snapshot_modes);
4814 /* set current snapshot mode value to configured snapshot mode value */
4815 snapshot_mode_current =
4816 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4818 /* if that fails, set current snapshot mode to reliable default value */
4819 if (snapshot_mode_current == NULL)
4820 snapshot_mode_current =
4821 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4823 /* if that also fails, set current snapshot mode to first available value */
4824 if (snapshot_mode_current == NULL)
4825 snapshot_mode_current = snapshot_modes;
4828 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4830 /* needed for displaying snapshot mode text instead of identifier */
4831 snapshot_mode_text = snapshot_mode_current->name;
4834 static void execSetupGame()
4836 execSetupGame_setGameSpeeds();
4837 execSetupGame_setScrollDelays();
4838 execSetupGame_setSnapshotModes();
4840 setup_mode = SETUP_MODE_GAME;
4845 static void execSetupChooseGameSpeed()
4847 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4852 static void execSetupChooseScrollDelay()
4854 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4859 static void execSetupChooseSnapshotMode()
4861 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4866 static void execSetupEditor()
4868 setup_mode = SETUP_MODE_EDITOR;
4873 static void execSetupGraphics_setWindowSizes(boolean update_list)
4875 if (window_sizes != NULL && update_list)
4877 freeTreeInfo(window_sizes);
4879 window_sizes = NULL;
4882 if (window_sizes == NULL)
4884 boolean current_window_size_found = FALSE;
4887 for (i = 0; window_sizes_list[i].value != -1; i++)
4889 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4890 char identifier[32], name[32];
4891 int value = window_sizes_list[i].value;
4892 char *text = window_sizes_list[i].text;
4894 ti->node_top = &window_sizes;
4895 ti->sort_priority = value;
4897 sprintf(identifier, "%d", value);
4898 sprintf(name, "%s", text);
4900 setString(&ti->identifier, identifier);
4901 setString(&ti->name, name);
4902 setString(&ti->name_sorting, name);
4903 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4905 pushTreeInfo(&window_sizes, ti);
4907 if (value == setup.window_scaling_percent)
4908 current_window_size_found = TRUE;
4911 if (!current_window_size_found)
4913 // add entry for non-preset window scaling value
4915 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4916 char identifier[32], name[32];
4917 int value = setup.window_scaling_percent;
4919 ti->node_top = &window_sizes;
4920 ti->sort_priority = value;
4922 sprintf(identifier, "%d", value);
4923 sprintf(name, "%d %% (Current)", value);
4925 setString(&ti->identifier, identifier);
4926 setString(&ti->name, name);
4927 setString(&ti->name_sorting, name);
4928 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4930 pushTreeInfo(&window_sizes, ti);
4933 /* sort window size values to start with lowest window size value */
4934 sortTreeInfo(&window_sizes);
4936 /* set current window size value to configured window size value */
4937 window_size_current =
4938 getTreeInfoFromIdentifier(window_sizes,
4939 i_to_a(setup.window_scaling_percent));
4941 /* if that fails, set current window size to reliable default value */
4942 if (window_size_current == NULL)
4943 window_size_current =
4944 getTreeInfoFromIdentifier(window_sizes,
4945 i_to_a(STD_WINDOW_SCALING_PERCENT));
4947 /* if that also fails, set current window size to first available value */
4948 if (window_size_current == NULL)
4949 window_size_current = window_sizes;
4952 setup.window_scaling_percent = atoi(window_size_current->identifier);
4954 /* needed for displaying window size text instead of identifier */
4955 window_size_text = window_size_current->name;
4958 static void execSetupGraphics_setScalingTypes()
4960 if (scaling_types == NULL)
4964 for (i = 0; scaling_types_list[i].value != NULL; i++)
4966 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4967 char identifier[32], name[32];
4968 char *value = scaling_types_list[i].value;
4969 char *text = scaling_types_list[i].text;
4971 ti->node_top = &scaling_types;
4972 ti->sort_priority = i;
4974 sprintf(identifier, "%s", value);
4975 sprintf(name, "%s", text);
4977 setString(&ti->identifier, identifier);
4978 setString(&ti->name, name);
4979 setString(&ti->name_sorting, name);
4980 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4982 pushTreeInfo(&scaling_types, ti);
4985 /* sort scaling type values to start with lowest scaling type value */
4986 sortTreeInfo(&scaling_types);
4988 /* set current scaling type value to configured scaling type value */
4989 scaling_type_current =
4990 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4992 /* if that fails, set current scaling type to reliable default value */
4993 if (scaling_type_current == NULL)
4994 scaling_type_current =
4995 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4997 /* if that also fails, set current scaling type to first available value */
4998 if (scaling_type_current == NULL)
4999 scaling_type_current = scaling_types;
5002 setup.window_scaling_quality = scaling_type_current->identifier;
5004 /* needed for displaying scaling type text instead of identifier */
5005 scaling_type_text = scaling_type_current->name;
5008 static void execSetupGraphics_setRenderingModes()
5010 if (rendering_modes == NULL)
5014 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5016 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5017 char identifier[32], name[32];
5018 char *value = rendering_modes_list[i].value;
5019 char *text = rendering_modes_list[i].text;
5021 ti->node_top = &rendering_modes;
5022 ti->sort_priority = i;
5024 sprintf(identifier, "%s", value);
5025 sprintf(name, "%s", text);
5027 setString(&ti->identifier, identifier);
5028 setString(&ti->name, name);
5029 setString(&ti->name_sorting, name);
5030 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5032 pushTreeInfo(&rendering_modes, ti);
5035 /* sort rendering mode values to start with lowest rendering mode value */
5036 sortTreeInfo(&rendering_modes);
5038 /* set current rendering mode value to configured rendering mode value */
5039 rendering_mode_current =
5040 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5042 /* if that fails, set current rendering mode to reliable default value */
5043 if (rendering_mode_current == NULL)
5044 rendering_mode_current =
5045 getTreeInfoFromIdentifier(rendering_modes,
5046 STR_SPECIAL_RENDERING_DEFAULT);
5048 /* if that also fails, set current rendering mode to first available one */
5049 if (rendering_mode_current == NULL)
5050 rendering_mode_current = rendering_modes;
5053 setup.screen_rendering_mode = rendering_mode_current->identifier;
5055 /* needed for displaying rendering mode text instead of identifier */
5056 rendering_mode_text = rendering_mode_current->name;
5059 static void execSetupGraphics()
5061 // update "setup.window_scaling_percent" from list selection
5062 // (in this case, window scaling was changed on setup screen)
5063 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5064 execSetupGraphics_setWindowSizes(FALSE);
5066 // update list selection from "setup.window_scaling_percent"
5067 // (window scaling may have changed by resizing the window)
5068 execSetupGraphics_setWindowSizes(TRUE);
5070 execSetupGraphics_setScalingTypes();
5071 execSetupGraphics_setRenderingModes();
5073 setup_mode = SETUP_MODE_GRAPHICS;
5077 #if defined(TARGET_SDL2)
5078 // window scaling may have changed at this point
5079 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5081 // window scaling quality may have changed at this point
5082 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5083 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5085 // screen rendering mode may have changed at this point
5086 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5090 static void execSetupChooseWindowSize()
5092 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5097 static void execSetupChooseScalingType()
5099 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5104 static void execSetupChooseRenderingMode()
5106 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5111 static void execSetupChooseVolumeSimple()
5113 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5118 static void execSetupChooseVolumeLoops()
5120 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5125 static void execSetupChooseVolumeMusic()
5127 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5132 static void execSetupSound()
5134 if (volumes_simple == NULL)
5136 boolean current_volume_simple_found = FALSE;
5139 for (i = 0; volumes_list[i].value != -1; i++)
5141 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5142 char identifier[32], name[32];
5143 int value = volumes_list[i].value;
5144 char *text = volumes_list[i].text;
5146 ti->node_top = &volumes_simple;
5147 ti->sort_priority = value;
5149 sprintf(identifier, "%d", value);
5150 sprintf(name, "%s", text);
5152 setString(&ti->identifier, identifier);
5153 setString(&ti->name, name);
5154 setString(&ti->name_sorting, name);
5155 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5157 pushTreeInfo(&volumes_simple, ti);
5159 if (value == setup.volume_simple)
5160 current_volume_simple_found = TRUE;
5163 if (!current_volume_simple_found)
5165 // add entry for non-preset volume value
5167 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5168 char identifier[32], name[32];
5169 int value = setup.volume_simple;
5171 ti->node_top = &volumes_simple;
5172 ti->sort_priority = value;
5174 sprintf(identifier, "%d", value);
5175 sprintf(name, "%d %% (Current)", value);
5177 setString(&ti->identifier, identifier);
5178 setString(&ti->name, name);
5179 setString(&ti->name_sorting, name);
5180 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5182 pushTreeInfo(&volumes_simple, ti);
5185 /* sort volume values to start with lowest volume value */
5186 sortTreeInfo(&volumes_simple);
5188 /* set current volume value to configured volume value */
5189 volume_simple_current =
5190 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5192 /* if that fails, set current volume to reliable default value */
5193 if (volume_simple_current == NULL)
5194 volume_simple_current =
5195 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5197 /* if that also fails, set current volume to first available value */
5198 if (volume_simple_current == NULL)
5199 volume_simple_current = volumes_simple;
5202 if (volumes_loops == NULL)
5204 boolean current_volume_loops_found = FALSE;
5207 for (i = 0; volumes_list[i].value != -1; i++)
5209 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5210 char identifier[32], name[32];
5211 int value = volumes_list[i].value;
5212 char *text = volumes_list[i].text;
5214 ti->node_top = &volumes_loops;
5215 ti->sort_priority = value;
5217 sprintf(identifier, "%d", value);
5218 sprintf(name, "%s", text);
5220 setString(&ti->identifier, identifier);
5221 setString(&ti->name, name);
5222 setString(&ti->name_sorting, name);
5223 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5225 pushTreeInfo(&volumes_loops, ti);
5227 if (value == setup.volume_loops)
5228 current_volume_loops_found = TRUE;
5231 if (!current_volume_loops_found)
5233 // add entry for non-preset volume value
5235 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5236 char identifier[32], name[32];
5237 int value = setup.volume_loops;
5239 ti->node_top = &volumes_loops;
5240 ti->sort_priority = value;
5242 sprintf(identifier, "%d", value);
5243 sprintf(name, "%d %% (Current)", value);
5245 setString(&ti->identifier, identifier);
5246 setString(&ti->name, name);
5247 setString(&ti->name_sorting, name);
5248 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5250 pushTreeInfo(&volumes_loops, ti);
5253 /* sort volume values to start with lowest volume value */
5254 sortTreeInfo(&volumes_loops);
5256 /* set current volume value to configured volume value */
5257 volume_loops_current =
5258 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5260 /* if that fails, set current volume to reliable default value */
5261 if (volume_loops_current == NULL)
5262 volume_loops_current =
5263 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5265 /* if that also fails, set current volume to first available value */
5266 if (volume_loops_current == NULL)
5267 volume_loops_current = volumes_loops;
5270 if (volumes_music == NULL)
5272 boolean current_volume_music_found = FALSE;
5275 for (i = 0; volumes_list[i].value != -1; i++)
5277 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5278 char identifier[32], name[32];
5279 int value = volumes_list[i].value;
5280 char *text = volumes_list[i].text;
5282 ti->node_top = &volumes_music;
5283 ti->sort_priority = value;
5285 sprintf(identifier, "%d", value);
5286 sprintf(name, "%s", text);
5288 setString(&ti->identifier, identifier);
5289 setString(&ti->name, name);
5290 setString(&ti->name_sorting, name);
5291 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5293 pushTreeInfo(&volumes_music, ti);
5295 if (value == setup.volume_music)
5296 current_volume_music_found = TRUE;
5299 if (!current_volume_music_found)
5301 // add entry for non-preset volume value
5303 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5304 char identifier[32], name[32];
5305 int value = setup.volume_music;
5307 ti->node_top = &volumes_music;
5308 ti->sort_priority = value;
5310 sprintf(identifier, "%d", value);
5311 sprintf(name, "%d %% (Current)", value);
5313 setString(&ti->identifier, identifier);
5314 setString(&ti->name, name);
5315 setString(&ti->name_sorting, name);
5316 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5318 pushTreeInfo(&volumes_music, ti);
5321 /* sort volume values to start with lowest volume value */
5322 sortTreeInfo(&volumes_music);
5324 /* set current volume value to configured volume value */
5325 volume_music_current =
5326 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5328 /* if that fails, set current volume to reliable default value */
5329 if (volume_music_current == NULL)
5330 volume_music_current =
5331 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5333 /* if that also fails, set current volume to first available value */
5334 if (volume_music_current == NULL)
5335 volume_music_current = volumes_music;
5338 setup.volume_simple = atoi(volume_simple_current->identifier);
5339 setup.volume_loops = atoi(volume_loops_current->identifier);
5340 setup.volume_music = atoi(volume_music_current->identifier);
5342 /* needed for displaying volume text instead of identifier */
5343 volume_simple_text = volume_simple_current->name;
5344 volume_loops_text = volume_loops_current->name;
5345 volume_music_text = volume_music_current->name;
5347 setup_mode = SETUP_MODE_SOUND;
5352 static void execSetupChooseTouchControls()
5354 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5359 static void execSetupChooseMoveDistance()
5361 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5366 static void execSetupChooseDropDistance()
5368 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5373 static void execSetupChooseTransparency()
5375 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5380 static void execSetupChooseGridXSize_0()
5382 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5387 static void execSetupChooseGridYSize_0()
5389 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5394 static void execSetupChooseGridXSize_1()
5396 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5401 static void execSetupChooseGridYSize_1()
5403 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5408 static void execSetupConfigureVirtualButtons()
5410 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5412 ConfigureVirtualButtons();
5414 setup_mode = SETUP_MODE_TOUCH;
5419 static void execSetupTouch()
5423 if (touch_controls == NULL)
5425 for (i = 0; touch_controls_list[i].value != NULL; i++)
5427 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5428 char identifier[32], name[32];
5429 char *value = touch_controls_list[i].value;
5430 char *text = touch_controls_list[i].text;
5432 ti->node_top = &touch_controls;
5433 ti->sort_priority = i;
5435 sprintf(identifier, "%s", value);
5436 sprintf(name, "%s", text);
5438 setString(&ti->identifier, identifier);
5439 setString(&ti->name, name);
5440 setString(&ti->name_sorting, name);
5441 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5443 pushTreeInfo(&touch_controls, ti);
5446 /* sort touch control values to start with lowest touch control value */
5447 sortTreeInfo(&touch_controls);
5449 /* set current touch control value to configured touch control value */
5450 touch_control_current =
5451 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5453 /* if that fails, set current touch control to reliable default value */
5454 if (touch_control_current == NULL)
5455 touch_control_current =
5456 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5458 /* if that also fails, set current touch control to first available value */
5459 if (touch_control_current == NULL)
5460 touch_control_current = touch_controls;
5463 if (move_distances == NULL)
5465 for (i = 0; distances_list[i].value != -1; i++)
5467 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5468 char identifier[32], name[32];
5469 int value = distances_list[i].value;
5470 char *text = distances_list[i].text;
5472 ti->node_top = &move_distances;
5473 ti->sort_priority = value;
5475 sprintf(identifier, "%d", value);
5476 sprintf(name, "%s", text);
5478 setString(&ti->identifier, identifier);
5479 setString(&ti->name, name);
5480 setString(&ti->name_sorting, name);
5481 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5483 pushTreeInfo(&move_distances, ti);
5486 /* sort distance values to start with lowest distance value */
5487 sortTreeInfo(&move_distances);
5489 /* set current distance value to configured distance value */
5490 move_distance_current =
5491 getTreeInfoFromIdentifier(move_distances,
5492 i_to_a(setup.touch.move_distance));
5494 /* if that fails, set current distance to reliable default value */
5495 if (move_distance_current == NULL)
5496 move_distance_current =
5497 getTreeInfoFromIdentifier(move_distances,
5498 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5500 /* if that also fails, set current distance to first available value */
5501 if (move_distance_current == NULL)
5502 move_distance_current = move_distances;
5505 if (drop_distances == NULL)
5507 for (i = 0; distances_list[i].value != -1; i++)
5509 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5510 char identifier[32], name[32];
5511 int value = distances_list[i].value;
5512 char *text = distances_list[i].text;
5514 ti->node_top = &drop_distances;
5515 ti->sort_priority = value;
5517 sprintf(identifier, "%d", value);
5518 sprintf(name, "%s", text);
5520 setString(&ti->identifier, identifier);
5521 setString(&ti->name, name);
5522 setString(&ti->name_sorting, name);
5523 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5525 pushTreeInfo(&drop_distances, ti);
5528 /* sort distance values to start with lowest distance value */
5529 sortTreeInfo(&drop_distances);
5531 /* set current distance value to configured distance value */
5532 drop_distance_current =
5533 getTreeInfoFromIdentifier(drop_distances,
5534 i_to_a(setup.touch.drop_distance));
5536 /* if that fails, set current distance to reliable default value */
5537 if (drop_distance_current == NULL)
5538 drop_distance_current =
5539 getTreeInfoFromIdentifier(drop_distances,
5540 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5542 /* if that also fails, set current distance to first available value */
5543 if (drop_distance_current == NULL)
5544 drop_distance_current = drop_distances;
5547 if (transparencies == NULL)
5549 for (i = 0; transparencies_list[i].value != -1; i++)
5551 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5552 char identifier[32], name[32];
5553 int value = transparencies_list[i].value;
5554 char *text = transparencies_list[i].text;
5556 ti->node_top = &transparencies;
5557 ti->sort_priority = value;
5559 sprintf(identifier, "%d", value);
5560 sprintf(name, "%s", text);
5562 setString(&ti->identifier, identifier);
5563 setString(&ti->name, name);
5564 setString(&ti->name_sorting, name);
5565 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5567 pushTreeInfo(&transparencies, ti);
5570 /* sort transparency values to start with lowest transparency value */
5571 sortTreeInfo(&transparencies);
5573 /* set current transparency value to configured transparency value */
5574 transparency_current =
5575 getTreeInfoFromIdentifier(transparencies,
5576 i_to_a(setup.touch.transparency));
5578 /* if that fails, set current transparency to reliable default value */
5579 if (transparency_current == NULL)
5580 transparency_current =
5581 getTreeInfoFromIdentifier(transparencies,
5582 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5584 /* if that also fails, set current transparency to first available value */
5585 if (transparency_current == NULL)
5586 transparency_current = transparencies;
5589 for (i = 0; i < 2; i++)
5591 for (j = 0; j < 2; j++)
5593 if (grid_sizes[i][j] == NULL)
5595 for (k = 0; grid_sizes_list[k].value != -1; k++)
5597 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5598 char identifier[32], name[32];
5599 int value = grid_sizes_list[k].value;
5600 char *text = grid_sizes_list[k].text;
5602 ti->node_top = &grid_sizes[i][j];
5603 ti->sort_priority = value;
5605 sprintf(identifier, "%d", value);
5606 sprintf(name, "%s", text);
5608 setString(&ti->identifier, identifier);
5609 setString(&ti->name, name);
5610 setString(&ti->name_sorting, name);
5611 setString(&ti->infotext,
5614 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5615 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5617 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5618 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5620 pushTreeInfo(&grid_sizes[i][j], ti);
5623 /* sort grid size values to start with lowest grid size value */
5624 sortTreeInfo(&grid_sizes[i][j]);
5626 /* set current grid size value to configured grid size value */
5627 grid_size_current[i][j] =
5628 getTreeInfoFromIdentifier(grid_sizes[i][j],
5630 setup.touch.grid_xsize[i] :
5631 setup.touch.grid_ysize[i]));
5633 /* if that fails, set current grid size to reliable default value */
5634 if (grid_size_current[i][j] == NULL)
5635 grid_size_current[i][j] =
5636 getTreeInfoFromIdentifier(grid_sizes[i][j],
5638 DEFAULT_GRID_XSIZE(i) :
5639 DEFAULT_GRID_YSIZE(i)));
5641 /* if that also fails, set current grid size to first available value */
5642 if (grid_size_current[i][j] == NULL)
5643 grid_size_current[i][j] = grid_sizes[i][j];
5648 setup.touch.control_type = touch_control_current->identifier;
5649 setup.touch.move_distance = atoi(move_distance_current->identifier);
5650 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5651 setup.touch.transparency = atoi(transparency_current->identifier);
5653 for (i = 0; i < 2; i++)
5655 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5656 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5658 if (i == GRID_ACTIVE_NR())
5660 overlay.grid_xsize = setup.touch.grid_xsize[i];
5661 overlay.grid_ysize = setup.touch.grid_ysize[i];
5665 /* needed for displaying value text instead of identifier */
5666 touch_controls_text = touch_control_current->name;
5667 move_distance_text = move_distance_current->name;
5668 drop_distance_text = drop_distance_current->name;
5669 transparency_text = transparency_current->name;
5671 for (i = 0; i < 2; i++)
5672 for (j = 0; j < 2; j++)
5673 grid_size_text[i][j] = grid_size_current[i][j]->name;
5675 setup_mode = SETUP_MODE_TOUCH;
5680 static void execSetupArtwork()
5683 printf("::: '%s', '%s', '%s'\n",
5684 artwork.gfx_current->subdir,
5685 artwork.gfx_current->fullpath,
5686 artwork.gfx_current->basepath);
5689 setup.graphics_set = artwork.gfx_current->identifier;
5690 setup.sounds_set = artwork.snd_current->identifier;
5691 setup.music_set = artwork.mus_current->identifier;
5693 /* needed if last screen (setup choice) changed graphics, sounds or music */
5694 ReloadCustomArtwork(0);
5696 /* needed for displaying artwork name instead of artwork identifier */
5697 graphics_set_name = artwork.gfx_current->name;
5698 sounds_set_name = artwork.snd_current->name;
5699 music_set_name = artwork.mus_current->name;
5701 setup_mode = SETUP_MODE_ARTWORK;
5706 static void execSetupChooseGraphics()
5708 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5713 static void execSetupChooseSounds()
5715 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5720 static void execSetupChooseMusic()
5722 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5727 static void execSetupInput()
5729 setup_mode = SETUP_MODE_INPUT;
5734 static void execSetupShortcuts()
5736 setup_mode = SETUP_MODE_SHORTCUTS;
5741 static void execSetupShortcuts1()
5743 setup_mode = SETUP_MODE_SHORTCUTS_1;
5748 static void execSetupShortcuts2()
5750 setup_mode = SETUP_MODE_SHORTCUTS_2;
5755 static void execSetupShortcuts3()
5757 setup_mode = SETUP_MODE_SHORTCUTS_3;
5762 static void execSetupShortcuts4()
5764 setup_mode = SETUP_MODE_SHORTCUTS_4;
5769 static void execSetupShortcuts5()
5771 setup_mode = SETUP_MODE_SHORTCUTS_5;
5776 static void execExitSetup()
5778 SetGameStatus(GAME_MODE_MAIN);
5783 static void execSaveAndExitSetup()
5792 void *related_value;
5793 } hide_related_entry_list[] =
5795 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5796 { &setup.game_frame_delay, &game_speed_text },
5798 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5799 { &setup.scroll_delay_value, &scroll_delay_text },
5801 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5802 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5804 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5805 { &setup.window_scaling_percent, &window_size_text },
5807 { &setup.window_scaling_quality, execSetupChooseScalingType },
5808 { &setup.window_scaling_quality, &scaling_type_text },
5810 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5811 { &setup.screen_rendering_mode, &rendering_mode_text },
5813 { &setup.graphics_set, execSetupChooseGraphics },
5814 { &setup.graphics_set, &graphics_set_name },
5816 { &setup.sounds_set, execSetupChooseSounds },
5817 { &setup.sounds_set, &sounds_set_name },
5819 { &setup.music_set, execSetupChooseMusic },
5820 { &setup.music_set, &music_set_name },
5822 { &setup.volume_simple, execSetupChooseVolumeSimple },
5823 { &setup.volume_simple, &volume_simple_text },
5825 { &setup.volume_loops, execSetupChooseVolumeLoops },
5826 { &setup.volume_loops, &volume_loops_text },
5828 { &setup.volume_music, execSetupChooseVolumeMusic },
5829 { &setup.volume_music, &volume_music_text },
5831 { &setup.touch.control_type, execSetupChooseTouchControls },
5832 { &setup.touch.control_type, &touch_controls_text },
5834 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5835 { &setup.touch.move_distance, &move_distance_text },
5837 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5838 { &setup.touch.drop_distance, &drop_distance_text },
5840 { &setup.touch.transparency, execSetupChooseTransparency },
5841 { &setup.touch.transparency, &transparency_text },
5843 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5844 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5846 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5847 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5849 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5850 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5852 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5853 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5858 void setHideRelatedSetupEntries()
5862 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5863 if (hideSetupEntry(hide_related_entry_list[i].value))
5864 setHideSetupEntry(hide_related_entry_list[i].related_value);
5867 static struct TokenInfo setup_info_main[] =
5869 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5870 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5871 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5872 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5873 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5874 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5875 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5876 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5877 { TYPE_EMPTY, NULL, "" },
5878 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5879 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5884 static struct TokenInfo setup_info_game[] =
5886 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5887 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
5888 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
5889 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5890 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5891 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5892 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5893 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5894 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
5895 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
5896 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5897 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5898 { TYPE_STRING, &game_speed_text, "" },
5900 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5901 { TYPE_STRING, &scroll_delay_text, "" },
5903 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5904 { TYPE_STRING, &snapshot_mode_text, "" },
5905 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5906 { TYPE_EMPTY, NULL, "" },
5907 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5912 static struct TokenInfo setup_info_editor[] =
5915 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5916 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5917 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5918 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5919 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5920 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5921 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5922 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5923 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5924 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5926 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5927 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5929 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5931 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5932 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5933 { TYPE_EMPTY, NULL, "" },
5935 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5936 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5937 { TYPE_EMPTY, NULL, "" },
5939 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5940 { TYPE_EMPTY, NULL, "" },
5941 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5946 static struct TokenInfo setup_info_graphics[] =
5948 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5949 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5950 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5951 { TYPE_STRING, &window_size_text, "" },
5952 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5953 { TYPE_STRING, &scaling_type_text, "" },
5954 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5955 { TYPE_STRING, &rendering_mode_text, "" },
5958 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5959 { TYPE_STRING, &scroll_delay_text, "" },
5961 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5962 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5963 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5964 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5965 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5966 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5967 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5968 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5969 { TYPE_EMPTY, NULL, "" },
5970 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5975 static struct TokenInfo setup_info_sound[] =
5977 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5978 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5979 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5980 { TYPE_EMPTY, NULL, "" },
5981 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5982 { TYPE_STRING, &volume_simple_text, "" },
5983 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5984 { TYPE_STRING, &volume_loops_text, "" },
5985 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5986 { TYPE_STRING, &volume_music_text, "" },
5987 { TYPE_EMPTY, NULL, "" },
5988 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5993 static struct TokenInfo setup_info_artwork[] =
5995 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5996 { TYPE_STRING, &graphics_set_name, "" },
5997 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5998 { TYPE_STRING, &sounds_set_name, "" },
5999 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6000 { TYPE_STRING, &music_set_name, "" },
6001 { TYPE_EMPTY, NULL, "" },
6002 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6003 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6004 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6005 { TYPE_EMPTY, NULL, "" },
6006 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6011 static struct TokenInfo setup_info_input[] =
6013 { TYPE_SWITCH, NULL, "Player:" },
6014 { TYPE_SWITCH, NULL, "Device:" },
6015 { TYPE_SWITCH, NULL, "" },
6016 { TYPE_SKIPPABLE, NULL, "" },
6017 { TYPE_EMPTY, NULL, "" },
6018 { TYPE_EMPTY, NULL, "" },
6019 { TYPE_EMPTY, NULL, "" },
6020 { TYPE_EMPTY, NULL, "" },
6021 { TYPE_EMPTY, NULL, "" },
6022 { TYPE_EMPTY, NULL, "" },
6023 { TYPE_EMPTY, NULL, "" },
6024 { TYPE_EMPTY, NULL, "" },
6025 { TYPE_SKIPPABLE, NULL, "" },
6026 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6031 static struct TokenInfo setup_info_touch[] =
6033 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6034 { TYPE_STRING, &touch_controls_text, "" },
6035 { TYPE_EMPTY, NULL, "" },
6036 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6041 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6043 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6044 { TYPE_STRING, &touch_controls_text, "" },
6045 { TYPE_EMPTY, NULL, "" },
6046 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6047 { TYPE_STRING, &grid_size_text[0][0], "" },
6048 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6049 { TYPE_STRING, &grid_size_text[0][1], "" },
6050 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6051 { TYPE_STRING, &transparency_text, "" },
6052 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6053 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6054 { TYPE_EMPTY, NULL, "" },
6055 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6056 { TYPE_EMPTY, NULL, "" },
6057 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6062 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6064 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6065 { TYPE_STRING, &touch_controls_text, "" },
6066 { TYPE_EMPTY, NULL, "" },
6067 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6068 { TYPE_STRING, &grid_size_text[1][0], "" },
6069 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6070 { TYPE_STRING, &grid_size_text[1][1], "" },
6071 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6072 { TYPE_STRING, &transparency_text, "" },
6073 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6074 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6075 { TYPE_EMPTY, NULL, "" },
6076 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6077 { TYPE_EMPTY, NULL, "" },
6078 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6083 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6085 setup_info_touch_virtual_buttons_0,
6086 setup_info_touch_virtual_buttons_1
6089 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6091 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6092 { TYPE_STRING, &touch_controls_text, "" },
6093 { TYPE_EMPTY, NULL, "" },
6094 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6095 { TYPE_STRING, &move_distance_text, "" },
6096 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6097 { TYPE_STRING, &drop_distance_text, "" },
6098 { TYPE_EMPTY, NULL, "" },
6099 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6104 static struct TokenInfo setup_info_shortcuts[] =
6106 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6107 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6108 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6109 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6110 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6111 { TYPE_EMPTY, NULL, "" },
6112 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6117 static struct TokenInfo setup_info_shortcuts_1[] =
6119 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6120 { TYPE_KEY, &setup.shortcut.save_game, "" },
6121 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6122 { TYPE_KEY, &setup.shortcut.load_game, "" },
6123 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6124 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6125 { TYPE_EMPTY, NULL, "" },
6126 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6127 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6128 { TYPE_EMPTY, NULL, "" },
6129 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6134 static struct TokenInfo setup_info_shortcuts_2[] =
6136 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6137 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6138 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6139 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6140 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6141 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6142 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6143 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6144 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6145 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6146 { TYPE_EMPTY, NULL, "" },
6147 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6152 static struct TokenInfo setup_info_shortcuts_3[] =
6154 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6155 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6156 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6157 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6158 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6159 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6160 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6161 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6162 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6163 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6164 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6165 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6166 { TYPE_EMPTY, NULL, "" },
6167 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6172 static struct TokenInfo setup_info_shortcuts_4[] =
6174 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6175 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6176 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6177 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6178 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6179 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6180 { TYPE_EMPTY, NULL, "" },
6181 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6186 static struct TokenInfo setup_info_shortcuts_5[] =
6188 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6189 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6190 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6191 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6192 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6193 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6194 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6195 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6196 { TYPE_EMPTY, NULL, "" },
6197 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6202 static Key getSetupKey()
6204 Key key = KSYM_UNDEFINED;
6205 boolean got_key_event = FALSE;
6207 while (!got_key_event)
6211 if (NextValidEvent(&event))
6215 case EVENT_KEYPRESS:
6217 key = GetEventKey((KeyEvent *)&event, TRUE);
6219 /* press 'Escape' or 'Enter' to keep the existing key binding */
6220 if (key == KSYM_Escape || key == KSYM_Return)
6221 key = KSYM_UNDEFINED; /* keep old value */
6223 got_key_event = TRUE;
6227 case EVENT_KEYRELEASE:
6228 key_joystick_mapping = 0;
6232 HandleOtherEvents(&event);
6243 static int getSetupValueFont(int type, void *value)
6245 if (type & TYPE_GHOSTED)
6246 return FONT_OPTION_OFF;
6247 else if (type & TYPE_KEY)
6248 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6249 else if (type & TYPE_STRING)
6250 return FONT_VALUE_2;
6251 else if (type & TYPE_ECS_AGA)
6252 return FONT_VALUE_1;
6253 else if (type & TYPE_BOOLEAN_STYLE)
6254 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6255 else if (type & TYPE_YES_NO_AUTO)
6256 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6257 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6258 else if (type & TYPE_PLAYER)
6259 return FONT_VALUE_1;
6261 return FONT_VALUE_1;
6264 static int getSetupValueFontNarrow(int type, int font_nr)
6266 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6267 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6268 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6272 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6274 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6275 struct TokenInfo *si = &setup_info[si_pos];
6276 boolean font_draw_xoffset_modified = FALSE;
6277 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6278 int font_draw_xoffset_old = -1;
6279 int xoffset = (scrollbar_needed ? -1 : 0);
6280 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6281 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6282 int xpos = menu_screen_value_xpos;
6283 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6284 int startx = mSX + xpos * 32;
6285 int starty = mSY + ypos * 32;
6286 int font_nr, font_nr_default, font_width_default;
6287 int type = si->type;
6288 void *value = si->value;
6289 char *value_string = getSetupValue(type, value);
6292 if (value_string == NULL)
6295 if (type & TYPE_KEY)
6297 xpos = MENU_SCREEN_START_XPOS;
6299 if (type & TYPE_QUERY)
6300 value_string = "<press key>";
6302 else if (type & TYPE_STRING)
6304 int max_value_len = (SCR_FIELDX - 2) * 2;
6306 xpos = MENU_SCREEN_START_XPOS;
6308 if (strlen(value_string) > max_value_len)
6309 value_string[max_value_len] = '\0';
6311 else if (type & TYPE_YES_NO_AUTO)
6313 xpos = menu_screen_value_xpos - 1;
6315 else if (type & TYPE_PLAYER)
6317 int displayed_player_nr = *(int *)value + 1;
6319 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6322 startx = mSX + xpos * 32;
6323 starty = mSY + ypos * 32;
6324 font_nr_default = getSetupValueFont(type, value);
6325 font_width_default = getFontWidth(font_nr_default);
6327 font_nr = font_nr_default;
6329 // special check if right-side setup values moved left due to scrollbar
6330 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6332 int max_menu_text_length = 26; // maximum text length for classic menu
6333 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6334 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6335 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6336 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6337 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6339 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6342 startx = mSX + xpos * 32;
6344 font_nr = getSetupValueFontNarrow(type, font_nr);
6348 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6349 if (setup_mode != SETUP_MODE_INPUT)
6351 int max_menu_text_length_big = (menu_screen_value_xpos -
6352 MENU_SCREEN_START_XPOS);
6353 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6354 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6355 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6356 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6357 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6358 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6359 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6360 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6361 boolean correct_font_draw_xoffset = FALSE;
6363 if (xpos == MENU_SCREEN_START_XPOS &&
6364 startx + font1_xoffset < text_startx + text_font_xoffset)
6365 correct_font_draw_xoffset = TRUE;
6367 if (xpos == menu_screen_value_xpos &&
6368 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6369 correct_font_draw_xoffset = TRUE;
6371 /* check if setup value would overlap with setup text when printed */
6372 /* (this can happen for extreme/wrong values for font draw offset) */
6373 if (correct_font_draw_xoffset)
6375 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6376 font_draw_xoffset_modified = TRUE;
6378 if (type & TYPE_KEY)
6379 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6380 else if (!(type & TYPE_STRING))
6381 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6382 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6386 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6387 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6389 DrawText(startx, starty, value_string, font_nr);
6391 if (type & TYPE_PLAYER)
6393 int player_nr = *(int *)value;
6394 int xoff = getFontWidth(font_nr);
6396 DrawFixedGraphicThruMaskExt(drawto, startx + xoff, starty,
6397 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6400 if (font_draw_xoffset_modified)
6401 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6404 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6406 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6407 struct TokenInfo *si = &setup_info[si_pos];
6409 if (si->type & TYPE_BOOLEAN_STYLE)
6411 *(boolean *)si->value ^= TRUE;
6413 else if (si->type & TYPE_YES_NO_AUTO)
6417 (*(int *)si->value == AUTO ? TRUE :
6418 *(int *)si->value == TRUE ? FALSE : AUTO) :
6419 (*(int *)si->value == TRUE ? AUTO :
6420 *(int *)si->value == AUTO ? FALSE : TRUE));
6422 else if (si->type & TYPE_KEY)
6426 si->type |= TYPE_QUERY;
6427 drawSetupValue(screen_pos, setup_info_pos_raw);
6428 si->type &= ~TYPE_QUERY;
6430 key = getSetupKey();
6431 if (key != KSYM_UNDEFINED)
6432 *(Key *)si->value = key;
6434 else if (si->type & TYPE_PLAYER)
6436 int player_nr = *(int *)si->value;
6441 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6443 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6446 drawSetupValue(screen_pos, setup_info_pos_raw);
6448 // fullscreen state may have changed at this point
6449 if (si->value == &setup.fullscreen)
6450 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6452 if (si->value == &setup.network_mode &&
6453 setup.network_mode != network.enabled)
6455 network.enabled = setup.network_mode;
6457 FadeOut(REDRAW_ALL);
6463 if (network.enabled)
6464 InitNetworkServer();
6466 DisconnectFromNetworkServer();
6472 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6474 static struct TokenInfo *setup_info_final = NULL;
6479 /* determine maximum list size of target list */
6480 while (setup_info_orig[list_size++].type != 0);
6482 /* free, allocate and clear memory for target list */
6483 checked_free(setup_info_final);
6484 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6486 /* copy setup info list without setup entries marked as hidden */
6487 for (i = 0; setup_info_orig[i].type != 0; i++)
6489 /* skip setup entries configured to be hidden */
6490 if (hideSetupEntry(setup_info_orig[i].value))
6493 /* skip skippable setup entries if screen is lower than usual */
6494 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6495 setup_info_orig[i].type == TYPE_SKIPPABLE)
6498 setup_info_final[list_pos++] = setup_info_orig[i];
6501 return setup_info_final;
6504 static void DrawSetupScreen_Generic()
6506 int fade_mask = REDRAW_FIELD;
6507 boolean redraw_all = FALSE;
6508 char *title_string = NULL;
6511 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6512 fade_mask = REDRAW_ALL;
6515 FadeMenuSoundsAndMusic();
6517 FreeScreenGadgets();
6518 CreateScreenGadgets();
6520 if (redraw_mask & REDRAW_ALL)
6525 /* needed if different viewport properties defined for setup screen */
6526 ChangeViewportPropertiesIfNeeded();
6528 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6532 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6534 if (setup_mode == SETUP_MODE_MAIN)
6536 setup_info = setup_info_main;
6537 title_string = STR_SETUP_MAIN;
6539 else if (setup_mode == SETUP_MODE_GAME)
6541 setup_info = setup_info_game;
6542 title_string = STR_SETUP_GAME;
6544 else if (setup_mode == SETUP_MODE_EDITOR)
6546 setup_info = setup_info_editor;
6547 title_string = STR_SETUP_EDITOR;
6549 else if (setup_mode == SETUP_MODE_GRAPHICS)
6551 setup_info = setup_info_graphics;
6552 title_string = STR_SETUP_GRAPHICS;
6554 else if (setup_mode == SETUP_MODE_SOUND)
6556 setup_info = setup_info_sound;
6557 title_string = STR_SETUP_SOUND;
6559 else if (setup_mode == SETUP_MODE_ARTWORK)
6561 setup_info = setup_info_artwork;
6562 title_string = STR_SETUP_ARTWORK;
6564 else if (setup_mode == SETUP_MODE_TOUCH)
6566 setup_info = setup_info_touch;
6567 title_string = STR_SETUP_TOUCH;
6569 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6570 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6571 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6572 setup_info = setup_info_touch_wipe_gestures;
6574 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6576 setup_info = setup_info_shortcuts;
6577 title_string = STR_SETUP_SHORTCUTS;
6579 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6581 setup_info = setup_info_shortcuts_1;
6582 title_string = STR_SETUP_SHORTCUTS;
6584 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6586 setup_info = setup_info_shortcuts_2;
6587 title_string = STR_SETUP_SHORTCUTS;
6589 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6591 setup_info = setup_info_shortcuts_3;
6592 title_string = STR_SETUP_SHORTCUTS;
6594 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6596 setup_info = setup_info_shortcuts_4;
6597 title_string = STR_SETUP_SHORTCUTS;
6599 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6601 setup_info = setup_info_shortcuts_5;
6602 title_string = STR_SETUP_SHORTCUTS;
6605 /* use modified setup info without setup entries marked as hidden */
6606 setup_info = getSetupInfoFinal(setup_info);
6608 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6610 // determine maximal number of setup entries that can be displayed on screen
6612 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6615 // determine maximal number of setup entries available for this setup screen
6617 for (i = 0; setup_info[i].type != 0; i++)
6620 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6622 MapScreenGadgets(max_setup_info);
6625 redraw_mask = fade_mask = REDRAW_ALL;
6627 DrawMaskedBorder(fade_mask);
6632 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6634 menu_info = setup_info;
6636 HandleMenuScreen(mx, my, dx, dy, button,
6637 setup_mode, num_setup_info, max_setup_info);
6640 void DrawSetupScreen_Input()
6644 FadeOut(REDRAW_FIELD);
6648 setup_info = getSetupInfoFinal(setup_info_input);
6650 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6652 for (i = 0; setup_info[i].type != 0; i++)
6654 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6655 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6656 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6657 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6658 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6659 initCursor(i, IMG_MENU_BUTTON);
6661 DrawCursorAndText_Setup(i, -1, FALSE);
6664 /* create gadgets for setup input menu screen */
6665 FreeScreenGadgets();
6666 CreateScreenGadgets();
6668 /* map gadgets for setup input menu screen */
6669 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6671 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6673 FadeIn(REDRAW_FIELD);
6676 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6678 if (device_name == NULL)
6681 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6684 if (strlen(device_name) > 1)
6686 char c1 = device_name[strlen(device_name) - 1];
6687 char c2 = device_name[strlen(device_name) - 2];
6689 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6690 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6693 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6694 strlen(device_name));
6697 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6700 static struct SetupKeyboardInfo custom_key;
6707 { &custom_key.left, "Axis/Pad Left" },
6708 { &custom_key.right, "Axis/Pad Right" },
6709 { &custom_key.up, "Axis/Pad Up" },
6710 { &custom_key.down, "Axis/Pad Down" },
6711 { &custom_key.snap, "Button 1/A/X" },
6712 { &custom_key.drop, "Button 2/B/Y" }
6714 static char *joystick_name[MAX_PLAYERS] =
6721 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6722 int font_nr_info = FONT_MENU_1;
6723 int font_nr_name = FONT_VALUE_OLD;
6724 int font_nr_on = FONT_VALUE_1;
6725 int font_nr_off = FONT_VALUE_OLD;
6728 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6730 font_nr_info = FONT_MENU_2;
6731 font_nr_on = FONT_VALUE_NARROW;
6732 font_nr_off = FONT_VALUE_OLD_NARROW;
6735 custom_key = setup.input[player_nr].key;
6737 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6738 FONT_INPUT_1_ACTIVE);
6740 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6742 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6743 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6745 if (setup.input[player_nr].use_joystick)
6747 char *device_name = setup.input[player_nr].joy.device_name;
6748 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6749 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6750 char *text = joystick_name[joystick_nr];
6751 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6753 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6754 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6758 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6759 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6762 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6763 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6767 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6768 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6769 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6770 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6772 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6773 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6774 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6775 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6776 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6777 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6779 for (i = 0; i < 6; i++)
6781 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6783 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6785 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6786 (setup.input[player_nr].use_joystick ?
6788 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6792 static int input_player_nr = 0;
6794 void HandleSetupScreen_Input_Player(int step, int direction)
6796 int old_player_nr = input_player_nr;
6799 new_player_nr = old_player_nr + step * direction;
6800 if (new_player_nr < 0)
6802 if (new_player_nr > MAX_PLAYERS - 1)
6803 new_player_nr = MAX_PLAYERS - 1;
6805 if (new_player_nr != old_player_nr)
6807 input_player_nr = new_player_nr;
6809 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6813 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6815 static int choice = 0;
6818 int pos_start = SETUPINPUT_SCREEN_POS_START;
6819 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6820 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6821 int pos_end = SETUPINPUT_SCREEN_POS_END;
6823 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6827 for (i = 0; setup_info_input[i].type != 0; i++)
6829 /* adjust menu structure according to skipped setup entries */
6830 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6838 if (button == MB_MENU_INITIALIZE)
6840 /* input setup menu may have changed size due to graphics configuration */
6841 if (choice >= pos_empty1)
6844 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6846 DrawCursorAndText_Setup(choice, -1, TRUE);
6850 else if (button == MB_MENU_LEAVE)
6852 setup_mode = SETUP_MODE_MAIN;
6859 if (mx || my) /* mouse input */
6861 x = (mx - mSX) / 32;
6862 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6864 else if (dx || dy) /* keyboard input */
6866 if (dx && choice == 0)
6867 x = (dx < 0 ? 10 : 12);
6868 else if ((dx && choice == 1) ||
6869 (dx == -1 && choice == pos_end))
6870 button = MB_MENU_CHOICE;
6874 if (y >= pos_empty1 && y <= pos_empty2)
6875 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6878 if (y == 0 && dx != 0 && button)
6880 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6882 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6883 y >= pos_start && y <= pos_end &&
6884 !(y >= pos_empty1 && y <= pos_empty2))
6890 DrawCursorAndText_Setup(choice, -1, FALSE);
6891 DrawCursorAndText_Setup(y, -1, TRUE);
6893 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6902 char *device_name = setup.input[input_player_nr].joy.device_name;
6904 if (!setup.input[input_player_nr].use_joystick)
6906 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6908 setJoystickDeviceToNr(device_name, new_device_nr);
6909 setup.input[input_player_nr].use_joystick = TRUE;
6913 int device_nr = getJoystickNrFromDeviceName(device_name);
6914 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6916 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6917 setup.input[input_player_nr].use_joystick = FALSE;
6919 setJoystickDeviceToNr(device_name, new_device_nr);
6922 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6926 if (setup.input[input_player_nr].use_joystick)
6927 ConfigureJoystick(input_player_nr);
6929 CustomizeKeyboard(input_player_nr);
6931 else if (y == pos_end)
6937 setup_mode = SETUP_MODE_MAIN;
6944 static boolean CustomizeKeyboardMain(int player_nr)
6948 boolean finished = FALSE;
6949 static struct SetupKeyboardInfo custom_key;
6954 } customize_step[] =
6956 { &custom_key.left, "Move Left" },
6957 { &custom_key.right, "Move Right" },
6958 { &custom_key.up, "Move Up" },
6959 { &custom_key.down, "Move Down" },
6960 { &custom_key.snap, "Snap Field" },
6961 { &custom_key.drop, "Drop Element" }
6963 int font_nr_old = FONT_VALUE_OLD;
6964 int font_nr_new = FONT_VALUE_1;
6965 boolean success = FALSE;
6967 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6969 font_nr_old = FONT_VALUE_OLD_NARROW;
6970 font_nr_new = FONT_VALUE_NARROW;
6973 /* read existing key bindings from player setup */
6974 custom_key = setup.input[player_nr].key;
6977 FadeOut(REDRAW_FIELD);
6981 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6984 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6985 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6986 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6987 "Key:", FONT_INPUT_1_ACTIVE);
6988 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6989 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
6991 FadeIn(REDRAW_FIELD);
6997 if (NextValidEvent(&event))
7001 case EVENT_KEYPRESS:
7003 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7005 /* press 'Escape' to abort and keep the old key bindings */
7006 if (key == KSYM_Escape)
7008 FadeSkipNextFadeIn();
7015 /* press 'Enter' to keep the existing key binding */
7016 if (key == KSYM_Return)
7017 key = *customize_step[step_nr].key;
7019 /* check if key already used */
7020 for (i = 0; i < step_nr; i++)
7021 if (*customize_step[i].key == key)
7026 /* got new key binding */
7027 *customize_step[step_nr].key = key;
7028 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7030 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7031 getKeyNameFromKey(key), font_nr_new);
7034 /* un-highlight last query */
7035 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7036 customize_step[step_nr - 1].text, FONT_MENU_1);
7037 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7038 "Key:", FONT_MENU_1);
7040 /* all keys configured */
7049 /* query next key binding */
7050 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7051 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7052 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7053 "Key:", FONT_INPUT_1_ACTIVE);
7054 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7055 getKeyNameFromKey(*customize_step[step_nr].key),
7060 case EVENT_KEYRELEASE:
7061 key_joystick_mapping = 0;
7065 HandleOtherEvents(&event);
7073 /* write new key bindings back to player setup, if successfully finished */
7075 setup.input[player_nr].key = custom_key;
7080 void CustomizeKeyboard(int player_nr)
7082 boolean success = CustomizeKeyboardMain(player_nr);
7086 int font_nr = FONT_TITLE_1;
7087 int font_height = getFontHeight(font_nr);
7088 int ypos1 = SYSIZE / 2 - font_height * 2;
7089 int ypos2 = SYSIZE / 2 - font_height * 1;
7090 unsigned int wait_frame_delay = 0;
7091 unsigned int wait_frame_delay_value = 2000;
7093 ResetDelayCounter(&wait_frame_delay);
7097 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7098 DrawTextSCentered(ypos2, font_nr, "configured!");
7100 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7106 DrawSetupScreen_Input();
7109 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7111 #define MARKER_BUTTON 1
7112 #define MARKER_AXIS_X 2
7113 #define MARKER_AXIS_Y 3
7115 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7117 #if defined(TARGET_SDL2)
7118 static boolean bitmaps_initialized = FALSE;
7119 boolean screen_initialized = FALSE;
7120 static Bitmap *controller, *button, *axis_x, *axis_y;
7122 boolean success = TRUE;
7123 boolean done = FALSE, next = FALSE;
7125 int alpha = 200, alpha_step = -1;
7126 int alpha_ticks = 0;
7127 char mapping[4096], temp[4096];
7128 int font_name = MENU_SETUP_FONT_TITLE;
7129 int font_info = MENU_SETUP_FONT_TEXT;
7130 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7131 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7132 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7133 int ystep_name = getMenuTextStep(spacing_name, font_name);
7134 int ystep_line = getMenuTextStep(spacing_line, font_info);
7135 int ystep_para = getMenuTextStep(spacing_para, font_info);
7143 int axis, button, hat, hat_value;
7146 *step, *prev_step, steps[] =
7148 { 356, 155, MARKER_BUTTON, "a", },
7149 { 396, 122, MARKER_BUTTON, "b", },
7150 { 320, 125, MARKER_BUTTON, "x", },
7151 { 358, 95, MARKER_BUTTON, "y", },
7152 { 162, 125, MARKER_BUTTON, "back", },
7153 { 216, 125, MARKER_BUTTON, "guide", },
7154 { 271, 125, MARKER_BUTTON, "start", },
7155 { 110, 200, MARKER_BUTTON, "dpleft", },
7156 { 146, 228, MARKER_BUTTON, "dpdown", },
7157 { 178, 200, MARKER_BUTTON, "dpright", },
7158 { 146, 172, MARKER_BUTTON, "dpup", },
7159 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7160 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7161 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7162 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7163 { 73, 141, MARKER_BUTTON, "leftstick", },
7164 { 282, 210, MARKER_BUTTON, "rightstick", },
7165 { 73, 141, MARKER_AXIS_X, "leftx", },
7166 { 73, 141, MARKER_AXIS_Y, "lefty", },
7167 { 282, 210, MARKER_AXIS_X, "rightx", },
7168 { 282, 210, MARKER_AXIS_Y, "righty", },
7171 unsigned int event_frame_delay = 0;
7172 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7174 ResetDelayCounter(&event_frame_delay);
7176 if (!bitmaps_initialized)
7178 controller = LoadCustomImage("joystick/controller.png");
7179 button = LoadCustomImage("joystick/button.png");
7180 axis_x = LoadCustomImage("joystick/axis_x.png");
7181 axis_y = LoadCustomImage("joystick/axis_y.png");
7183 bitmaps_initialized = TRUE;
7186 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7189 /* print info about the joystick we are watching */
7190 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7191 SDL_JoystickInstanceID(joystick), name);
7192 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7193 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7194 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7197 /* initialize mapping with GUID and name */
7198 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7200 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7201 temp, name, SDL_GetPlatform());
7203 /* loop through all steps (buttons and axes), getting joystick events */
7204 for (i = 0; i < SDL_arraysize(steps) && !done;)
7206 Bitmap *marker = button; /* initialize with reliable default value */
7209 strcpy(step->mapping, mapping);
7213 step->hat_value = -1;
7215 marker = (step->marker == MARKER_BUTTON ? button :
7216 step->marker == MARKER_AXIS_X ? axis_x :
7217 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7221 while (!done && !next)
7223 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7224 alpha_ticks = SDL_GetTicks();
7231 else if (alpha < 128)
7237 int controller_x = SX + (SXSIZE - controller->width) / 2;
7238 int controller_y = SY + ystep_line;
7240 int marker_x = controller_x + step->x;
7241 int marker_y = controller_y + step->y;
7243 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7244 int ystart2 = ystart1 + ystep_name + ystep_line;
7248 DrawTextSCentered(ystart1, font_name, name);
7250 DrawTextSCentered(ystart2, font_info,
7251 "Press buttons and move axes on");
7252 ystart2 += ystep_line;
7253 DrawTextSCentered(ystart2, font_info,
7254 "your controller when indicated.");
7255 ystart2 += ystep_line;
7256 DrawTextSCentered(ystart2, font_info,
7257 "(Your controller may look different.)");
7258 ystart2 += ystep_para;
7260 #if defined(PLATFORM_ANDROID)
7261 DrawTextSCentered(ystart2, font_info,
7262 "To correct a mistake,");
7263 ystart2 += ystep_line;
7264 DrawTextSCentered(ystart2, font_info,
7265 "press the 'back' button.");
7266 ystart2 += ystep_line;
7267 DrawTextSCentered(ystart2, font_info,
7268 "To skip a button or axis,");
7269 ystart2 += ystep_line;
7270 DrawTextSCentered(ystart2, font_info,
7271 "press the 'menu' button.");
7273 DrawTextSCentered(ystart2, font_info,
7274 "To correct a mistake,");
7275 ystart2 += ystep_line;
7276 DrawTextSCentered(ystart2, font_info,
7277 "press the 'backspace' key.");
7278 ystart2 += ystep_line;
7279 DrawTextSCentered(ystart2, font_info,
7280 "To skip a button or axis,");
7281 ystart2 += ystep_line;
7282 DrawTextSCentered(ystart2, font_info,
7283 "press the 'return' key.");
7284 ystart2 += ystep_line;
7285 DrawTextSCentered(ystart2, font_info,
7286 "To exit, press the 'escape' key.");
7289 BlitBitmapMasked(controller, drawto, 0, 0,
7290 controller->width, controller->height,
7291 controller_x, controller_y);
7293 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7294 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7296 BlitBitmapMasked(marker, drawto, 0, 0,
7297 marker->width, marker->height,
7298 marker_x, marker_y);
7300 if (!screen_initialized)
7301 FadeIn(REDRAW_FIELD);
7305 screen_initialized = TRUE;
7307 while (NextValidEvent(&event))
7311 case SDL_JOYAXISMOTION:
7312 if (event.jaxis.value > 20000 ||
7313 event.jaxis.value < -20000)
7315 for (j = 0; j < i; j++)
7316 if (steps[j].axis == event.jaxis.axis)
7321 if (step->marker != MARKER_AXIS_X &&
7322 step->marker != MARKER_AXIS_Y)
7325 step->axis = event.jaxis.axis;
7326 strcat(mapping, step->field);
7327 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7328 strcat(mapping, temp);
7336 case SDL_JOYHATMOTION:
7337 /* ignore centering; we're probably just coming back
7338 to the center from the previous item we set */
7339 if (event.jhat.value == SDL_HAT_CENTERED)
7342 for (j = 0; j < i; j++)
7343 if (steps[j].hat == event.jhat.hat &&
7344 steps[j].hat_value == event.jhat.value)
7349 step->hat = event.jhat.hat;
7350 step->hat_value = event.jhat.value;
7351 strcat(mapping, step->field);
7352 snprintf(temp, sizeof(temp), ":h%u.%u,",
7353 event.jhat.hat, event.jhat.value );
7354 strcat(mapping, temp);
7361 case SDL_JOYBALLMOTION:
7364 case SDL_JOYBUTTONUP:
7365 for (j = 0; j < i; j++)
7366 if (steps[j].button == event.jbutton.button)
7371 step->button = event.jbutton.button;
7372 strcat(mapping, step->field);
7373 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7374 strcat(mapping, temp);
7381 case SDL_FINGERDOWN:
7382 case SDL_MOUSEBUTTONDOWN:
7383 /* skip this step */
7390 if (event.key.keysym.sym == KSYM_BackSpace ||
7391 event.key.keysym.sym == KSYM_Back)
7402 /* undo this step */
7403 prev_step = &steps[i - 1];
7404 strcpy(mapping, prev_step->mapping);
7411 if (event.key.keysym.sym == KSYM_space ||
7412 event.key.keysym.sym == KSYM_Return ||
7413 event.key.keysym.sym == KSYM_Menu)
7415 /* skip this step */
7422 if (event.key.keysym.sym == KSYM_Escape)
7432 program.exit_function(0);
7439 // do not handle events for longer than standard frame delay period
7440 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7449 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7452 // activate mapping for this game
7453 SDL_GameControllerAddMapping(mapping);
7455 // save mapping to personal mappings
7456 SaveSetup_AddGameControllerMapping(mapping);
7459 /* wait until the last pending event was removed from event queue */
7460 while (NextValidEvent(&event));
7468 static int ConfigureJoystickMain(int player_nr)
7470 char *device_name = setup.input[player_nr].joy.device_name;
7471 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7472 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7473 int success = FALSE;
7476 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7477 return JOYSTICK_NOT_AVAILABLE;
7479 if (!joystick_active || !setup.input[player_nr].use_joystick)
7480 return JOYSTICK_NOT_AVAILABLE;
7483 FadeOut(REDRAW_FIELD);
7485 // close all joystick devices (potentially opened as game controllers)
7486 for (i = 0; i < SDL_NumJoysticks(); i++)
7487 SDLCloseJoystick(i);
7489 // open joystick device as plain joystick to configure as game controller
7490 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7492 // as the joystick was successfully opened before, this should not happen
7493 if (joystick == NULL)
7496 // create new game controller mapping (buttons and axes) for joystick device
7497 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7499 // close joystick (and maybe re-open as configured game controller later)
7500 SDL_JoystickClose(joystick);
7502 // re-open all joystick devices (potentially as game controllers)
7503 for (i = 0; i < SDL_NumJoysticks(); i++)
7506 // clear all joystick input actions for all joystick devices
7507 SDLClearJoystickState();
7509 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7512 void ConfigureJoystick(int player_nr)
7514 boolean state = ConfigureJoystickMain(player_nr);
7516 if (state != JOYSTICK_NOT_CONFIGURED)
7518 boolean success = (state == JOYSTICK_CONFIGURED);
7519 char message1[MAX_OUTPUT_LINESIZE + 1];
7520 char *message2 = (success ? "configured!" : "not available!");
7521 char *device_name = setup.input[player_nr].joy.device_name;
7522 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7523 int font_nr = FONT_TITLE_1;
7524 int font_height = getFontHeight(font_nr);
7525 int ypos1 = SYSIZE / 2 - font_height * 2;
7526 int ypos2 = SYSIZE / 2 - font_height * 1;
7527 unsigned int wait_frame_delay = 0;
7528 unsigned int wait_frame_delay_value = 2000;
7530 ResetDelayCounter(&wait_frame_delay);
7534 sprintf(message1, "Joystick %d", nr);
7536 DrawTextSCentered(ypos1, font_nr, message1);
7537 DrawTextSCentered(ypos2, font_nr, message2);
7539 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7545 DrawSetupScreen_Input();
7548 boolean ConfigureVirtualButtonsMain()
7550 static char *customize_step_text[] =
7559 char grid_button[] =
7561 CHAR_GRID_BUTTON_LEFT,
7562 CHAR_GRID_BUTTON_RIGHT,
7563 CHAR_GRID_BUTTON_UP,
7564 CHAR_GRID_BUTTON_DOWN,
7565 CHAR_GRID_BUTTON_SNAP,
7566 CHAR_GRID_BUTTON_DROP
7568 int font_nr = FONT_INPUT_1_ACTIVE;
7569 int font_height = getFontHeight(font_nr);
7570 int ypos1 = SYSIZE / 2 - font_height * 2;
7571 int ypos2 = SYSIZE / 2 - font_height * 1;
7572 boolean success = FALSE;
7573 boolean finished = FALSE;
7575 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7576 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7577 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7578 boolean set_grid_button = FALSE;
7579 int nr = GRID_ACTIVE_NR();
7582 for (x = 0; x < MAX_GRID_XSIZE; x++)
7583 for (y = 0; y < MAX_GRID_YSIZE; y++)
7584 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7586 overlay.grid_button_highlight = grid_button[step_nr];
7589 FadeOut(REDRAW_FIELD);
7593 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7594 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7595 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7597 FadeIn(REDRAW_FIELD);
7599 SetOverlayShowGrid(TRUE);
7605 while (NextValidEvent(&event))
7609 case EVENT_KEYPRESS:
7611 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7613 /* press 'Escape' to abort and keep the old key bindings */
7614 if (key == KSYM_Escape)
7616 for (x = 0; x < MAX_GRID_XSIZE; x++)
7617 for (y = 0; y < MAX_GRID_YSIZE; y++)
7618 overlay.grid_button[x][y] = grid_button_old[x][y];
7620 FadeSkipNextFadeIn();
7627 /* press 'Enter' to keep the existing key binding */
7628 if (key == KSYM_Return ||
7629 #if defined(TARGET_SDL2)
7636 else if (key == KSYM_BackSpace
7637 #if defined(TARGET_SDL2)
7645 FadeSkipNextFadeIn();
7659 /* all virtual buttons configured */
7668 for (x = 0; x < MAX_GRID_XSIZE; x++)
7669 for (y = 0; y < MAX_GRID_YSIZE; y++)
7670 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7672 overlay.grid_button_highlight = grid_button[step_nr];
7674 /* query next virtual button */
7678 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7679 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7680 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7684 case EVENT_KEYRELEASE:
7685 key_joystick_mapping = 0;
7688 case EVENT_BUTTONPRESS:
7689 case EVENT_BUTTONRELEASE:
7691 ButtonEvent *button = (ButtonEvent *)&event;
7693 button->x += video.screen_xoffset;
7694 button->y += video.screen_yoffset;
7696 x = button->x * overlay.grid_xsize / video.screen_width;
7697 y = button->y * overlay.grid_ysize / video.screen_height;
7699 if (button->type == EVENT_BUTTONPRESS)
7701 button_status = button->button;
7704 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7705 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7707 set_grid_button = TRUE;
7711 button_status = MB_RELEASED;
7716 case EVENT_MOTIONNOTIFY:
7718 MotionEvent *motion = (MotionEvent *)&event;
7720 motion->x += video.screen_xoffset;
7721 motion->y += video.screen_yoffset;
7723 x = motion->x * overlay.grid_xsize / video.screen_width;
7724 y = motion->y * overlay.grid_ysize / video.screen_height;
7726 set_grid_button = TRUE;
7730 #if defined(TARGET_SDL2)
7731 case SDL_WINDOWEVENT:
7732 HandleWindowEvent((WindowEvent *) &event);
7734 // check if device has been rotated
7735 if (nr != GRID_ACTIVE_NR())
7737 nr = GRID_ACTIVE_NR();
7739 for (x = 0; x < MAX_GRID_XSIZE; x++)
7740 for (y = 0; y < MAX_GRID_YSIZE; y++)
7741 grid_button_old[x][y] = grid_button_tmp[x][y] =
7742 overlay.grid_button[x][y];
7747 case SDL_APP_WILLENTERBACKGROUND:
7748 case SDL_APP_DIDENTERBACKGROUND:
7749 case SDL_APP_WILLENTERFOREGROUND:
7750 case SDL_APP_DIDENTERFOREGROUND:
7751 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7756 HandleOtherEvents(&event);
7760 if (set_grid_button)
7762 overlay.grid_button[x][y] =
7763 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7764 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7765 grid_button_tmp[x][y]);
7767 set_grid_button = FALSE;
7774 for (x = 0; x < MAX_GRID_XSIZE; x++)
7775 for (y = 0; y < MAX_GRID_YSIZE; y++)
7776 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7778 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7780 SetOverlayShowGrid(FALSE);
7785 void ConfigureVirtualButtons()
7787 boolean success = ConfigureVirtualButtonsMain();
7791 int font_nr = FONT_TITLE_1;
7792 int font_height = getFontHeight(font_nr);
7793 int ypos1 = SYSIZE / 2 - font_height * 2;
7794 int ypos2 = SYSIZE / 2 - font_height * 1;
7795 unsigned int wait_frame_delay = 0;
7796 unsigned int wait_frame_delay_value = 2000;
7798 ResetDelayCounter(&wait_frame_delay);
7802 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7803 DrawTextSCentered(ypos2, font_nr, "configured!");
7805 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7812 void DrawSetupScreen()
7814 if (setup_mode == SETUP_MODE_INPUT)
7815 DrawSetupScreen_Input();
7816 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7817 DrawChooseTree(&game_speed_current);
7818 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7819 DrawChooseTree(&scroll_delay_current);
7820 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7821 DrawChooseTree(&snapshot_mode_current);
7822 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7823 DrawChooseTree(&window_size_current);
7824 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7825 DrawChooseTree(&scaling_type_current);
7826 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7827 DrawChooseTree(&rendering_mode_current);
7828 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7829 DrawChooseTree(&artwork.gfx_current);
7830 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7831 DrawChooseTree(&artwork.snd_current);
7832 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7833 DrawChooseTree(&artwork.mus_current);
7834 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7835 DrawChooseTree(&volume_simple_current);
7836 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7837 DrawChooseTree(&volume_loops_current);
7838 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7839 DrawChooseTree(&volume_music_current);
7840 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7841 DrawChooseTree(&touch_control_current);
7842 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7843 DrawChooseTree(&move_distance_current);
7844 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7845 DrawChooseTree(&drop_distance_current);
7846 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7847 DrawChooseTree(&transparency_current);
7848 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7849 DrawChooseTree(&grid_size_current[0][0]);
7850 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7851 DrawChooseTree(&grid_size_current[0][1]);
7852 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7853 DrawChooseTree(&grid_size_current[1][0]);
7854 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7855 DrawChooseTree(&grid_size_current[1][1]);
7857 DrawSetupScreen_Generic();
7859 PlayMenuSoundsAndMusic();
7862 void RedrawSetupScreenAfterFullscreenToggle()
7864 if (setup_mode == SETUP_MODE_GRAPHICS ||
7865 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7867 // update list selection from "setup.window_scaling_percent"
7868 execSetupGraphics_setWindowSizes(TRUE);
7874 void RedrawSetupScreenAfterScreenRotation(int nr)
7878 if (setup_mode == SETUP_MODE_TOUCH)
7880 // update virtual button settings (depending on screen orientation)
7883 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
7885 // save already configured virtual buttons
7886 for (x = 0; x < MAX_GRID_XSIZE; x++)
7887 for (y = 0; y < MAX_GRID_YSIZE; y++)
7888 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7892 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7894 if (setup_mode == SETUP_MODE_INPUT)
7895 HandleSetupScreen_Input(mx, my, dx, dy, button);
7896 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7897 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7898 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7899 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7900 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7901 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7902 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7903 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7904 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7905 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7906 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7907 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7908 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7909 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7910 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7911 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7912 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7913 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7914 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7915 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7916 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7917 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7918 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7919 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7920 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7921 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7922 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7923 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7924 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7925 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7926 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7927 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
7928 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7929 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
7930 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7931 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
7932 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7933 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
7934 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7935 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
7937 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7940 void HandleGameActions()
7942 if (game.restart_game_message != NULL)
7943 RequestRestartGame(game.restart_game_message);
7945 if (game_status != GAME_MODE_PLAYING)
7948 GameActions(); /* main game loop */
7950 if (tape.auto_play && !tape.playing)
7951 AutoPlayTape(); /* continue automatically playing next tape */
7955 /* ---------- new screen button stuff -------------------------------------- */
7957 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7961 case SCREEN_CTRL_ID_PREV_LEVEL:
7962 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7963 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7966 case SCREEN_CTRL_ID_NEXT_LEVEL:
7967 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7968 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7971 case SCREEN_CTRL_ID_PREV_PLAYER:
7972 *x = mSX + TILEX * 10;
7973 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7976 case SCREEN_CTRL_ID_NEXT_PLAYER:
7977 *x = mSX + TILEX * 12;
7978 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7981 case SCREEN_CTRL_ID_INSERT_SOLUTION:
7982 *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x);
7983 *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y);
7986 case SCREEN_CTRL_ID_PLAY_SOLUTION:
7987 *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x);
7988 *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y);
7992 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7998 int gfx_unpressed, gfx_pressed;
7999 void (*get_gadget_position)(int *, int *, int);
8003 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8006 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8007 getScreenMenuButtonPos,
8008 SCREEN_CTRL_ID_PREV_LEVEL,
8013 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8014 getScreenMenuButtonPos,
8015 SCREEN_CTRL_ID_NEXT_LEVEL,
8020 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8021 getScreenMenuButtonPos,
8022 SCREEN_CTRL_ID_PREV_PLAYER,
8027 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8028 getScreenMenuButtonPos,
8029 SCREEN_CTRL_ID_NEXT_PLAYER,
8034 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8035 getScreenMenuButtonPos,
8036 SCREEN_CTRL_ID_INSERT_SOLUTION,
8037 SCREEN_MASK_MAIN_HAS_SOLUTION,
8038 "insert solution tape"
8041 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8042 getScreenMenuButtonPos,
8043 SCREEN_CTRL_ID_PLAY_SOLUTION,
8044 SCREEN_MASK_MAIN_HAS_SOLUTION,
8045 "play solution tape"
8051 int gfx_unpressed, gfx_pressed;
8055 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8058 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8059 -1, -1, /* these values are not constant, but can change at runtime */
8060 SCREEN_CTRL_ID_SCROLL_UP,
8064 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8065 -1, -1, /* these values are not constant, but can change at runtime */
8066 SCREEN_CTRL_ID_SCROLL_DOWN,
8073 int gfx_unpressed, gfx_pressed;
8079 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8082 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8083 -1, -1, /* these values are not constant, but can change at runtime */
8084 -1, -1, /* these values are not constant, but can change at runtime */
8085 GD_TYPE_SCROLLBAR_VERTICAL,
8086 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8087 "scroll level series vertically"
8091 static void CreateScreenMenubuttons()
8093 struct GadgetInfo *gi;
8094 unsigned int event_mask;
8097 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8099 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8100 int gfx_unpressed, gfx_pressed;
8101 int x, y, width, height;
8102 int gd_x1, gd_x2, gd_y1, gd_y2;
8103 int id = menubutton_info[i].gadget_id;
8105 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8106 event_mask = GD_EVENT_RELEASED;
8108 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8110 menubutton_info[i].get_gadget_position(&x, &y, id);
8112 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8114 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8115 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8119 width = SC_MENUBUTTON_XSIZE;
8120 height = SC_MENUBUTTON_YSIZE;
8123 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8124 gfx_pressed = menubutton_info[i].gfx_pressed;
8125 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8126 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8127 gd_x1 = graphic_info[gfx_unpressed].src_x;
8128 gd_y1 = graphic_info[gfx_unpressed].src_y;
8129 gd_x2 = graphic_info[gfx_pressed].src_x;
8130 gd_y2 = graphic_info[gfx_pressed].src_y;
8132 gi = CreateGadget(GDI_CUSTOM_ID, id,
8133 GDI_CUSTOM_TYPE_ID, i,
8134 GDI_IMAGE_ID, gfx_unpressed,
8135 GDI_INFO_TEXT, menubutton_info[i].infotext,
8140 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8141 GDI_STATE, GD_BUTTON_UNPRESSED,
8142 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8143 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8144 GDI_DIRECT_DRAW, FALSE,
8145 GDI_EVENT_MASK, event_mask,
8146 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8150 Error(ERR_EXIT, "cannot create gadget");
8152 screen_gadget[id] = gi;
8156 static void CreateScreenScrollbuttons()
8158 struct GadgetInfo *gi;
8159 unsigned int event_mask;
8162 /* these values are not constant, but can change at runtime */
8163 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8164 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8165 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8166 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8168 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8170 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8171 int gfx_unpressed, gfx_pressed;
8172 int x, y, width, height;
8173 int gd_x1, gd_x2, gd_y1, gd_y2;
8174 int id = scrollbutton_info[i].gadget_id;
8176 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8178 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8179 y = mSY + scrollbutton_info[i].y;
8180 width = SC_SCROLLBUTTON_XSIZE;
8181 height = SC_SCROLLBUTTON_YSIZE;
8183 /* correct scrollbar position if placed outside menu (playfield) area */
8184 if (x > SX + SC_SCROLL_UP_XPOS)
8185 x = SX + SC_SCROLL_UP_XPOS;
8187 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8188 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8189 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8191 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8192 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8193 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8194 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8195 gd_x1 = graphic_info[gfx_unpressed].src_x;
8196 gd_y1 = graphic_info[gfx_unpressed].src_y;
8197 gd_x2 = graphic_info[gfx_pressed].src_x;
8198 gd_y2 = graphic_info[gfx_pressed].src_y;
8200 gi = CreateGadget(GDI_CUSTOM_ID, id,
8201 GDI_CUSTOM_TYPE_ID, i,
8202 GDI_IMAGE_ID, gfx_unpressed,
8203 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8208 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8209 GDI_STATE, GD_BUTTON_UNPRESSED,
8210 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8211 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8212 GDI_DIRECT_DRAW, FALSE,
8213 GDI_EVENT_MASK, event_mask,
8214 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8218 Error(ERR_EXIT, "cannot create gadget");
8220 screen_gadget[id] = gi;
8224 static void CreateScreenScrollbars()
8228 /* these values are not constant, but can change at runtime */
8229 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8230 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8231 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8232 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8234 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8236 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8237 int gfx_unpressed, gfx_pressed;
8238 int x, y, width, height;
8239 int gd_x1, gd_x2, gd_y1, gd_y2;
8240 struct GadgetInfo *gi;
8241 int items_max, items_visible, item_position;
8242 unsigned int event_mask;
8243 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8244 int id = scrollbar_info[i].gadget_id;
8246 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8248 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8249 y = mSY + scrollbar_info[i].y;
8250 width = scrollbar_info[i].width;
8251 height = scrollbar_info[i].height;
8253 /* correct scrollbar position if placed outside menu (playfield) area */
8254 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8255 x = SX + SC_SCROLL_VERTICAL_XPOS;
8257 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8258 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8260 items_max = num_page_entries;
8261 items_visible = num_page_entries;
8264 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8265 gfx_pressed = scrollbar_info[i].gfx_pressed;
8266 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8267 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8268 gd_x1 = graphic_info[gfx_unpressed].src_x;
8269 gd_y1 = graphic_info[gfx_unpressed].src_y;
8270 gd_x2 = graphic_info[gfx_pressed].src_x;
8271 gd_y2 = graphic_info[gfx_pressed].src_y;
8273 gi = CreateGadget(GDI_CUSTOM_ID, id,
8274 GDI_CUSTOM_TYPE_ID, i,
8275 GDI_IMAGE_ID, gfx_unpressed,
8276 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8281 GDI_TYPE, scrollbar_info[i].type,
8282 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8283 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8284 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8285 GDI_WHEEL_AREA_X, SX,
8286 GDI_WHEEL_AREA_Y, SY,
8287 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8288 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8289 GDI_STATE, GD_BUTTON_UNPRESSED,
8290 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8291 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8292 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8293 GDI_DIRECT_DRAW, FALSE,
8294 GDI_EVENT_MASK, event_mask,
8295 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8299 Error(ERR_EXIT, "cannot create gadget");
8301 screen_gadget[id] = gi;
8305 void CreateScreenGadgets()
8307 CreateScreenMenubuttons();
8309 CreateScreenScrollbuttons();
8310 CreateScreenScrollbars();
8313 void FreeScreenGadgets()
8317 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8318 FreeGadget(screen_gadget[i]);
8321 void MapScreenMenuGadgets(int screen_mask)
8325 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8326 if (screen_mask & menubutton_info[i].screen_mask)
8327 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8330 void UnmapScreenMenuGadgets(int screen_mask)
8334 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8336 if (screen_mask & menubutton_info[i].screen_mask)
8338 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8340 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8341 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8342 screen_gadget[menubutton_info[i].gadget_id]->y,
8343 screen_gadget[menubutton_info[i].gadget_id]->width,
8344 screen_gadget[menubutton_info[i].gadget_id]->height);
8349 void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8352 MapScreenMenuGadgets(screen_mask);
8354 UnmapScreenMenuGadgets(screen_mask);
8357 void MapScreenGadgets(int num_entries)
8361 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8364 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8365 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8367 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8368 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8371 void MapScreenTreeGadgets(TreeInfo *ti)
8373 MapScreenGadgets(numTreeInfoInGroup(ti));
8376 static void HandleScreenGadgets(struct GadgetInfo *gi)
8378 int id = gi->custom_id;
8379 int button = gi->event.button;
8380 int step = (button == MB_LEFTBUTTON ? 1 :
8381 button == MB_MIDDLEBUTTON ? 5 :
8382 button == MB_RIGHTBUTTON ? 10 : 1);
8386 case SCREEN_CTRL_ID_PREV_LEVEL:
8387 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8390 case SCREEN_CTRL_ID_NEXT_LEVEL:
8391 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8394 case SCREEN_CTRL_ID_PREV_PLAYER:
8395 HandleSetupScreen_Input_Player(step, -1);
8398 case SCREEN_CTRL_ID_NEXT_PLAYER:
8399 HandleSetupScreen_Input_Player(step, +1);
8402 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8403 InsertSolutionTape();
8406 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8410 case SCREEN_CTRL_ID_SCROLL_UP:
8411 if (game_status == GAME_MODE_LEVELS)
8412 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8413 else if (game_status == GAME_MODE_LEVELNR)
8414 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8415 else if (game_status == GAME_MODE_SETUP)
8416 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8417 else if (game_status == GAME_MODE_INFO)
8418 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8421 case SCREEN_CTRL_ID_SCROLL_DOWN:
8422 if (game_status == GAME_MODE_LEVELS)
8423 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8424 else if (game_status == GAME_MODE_LEVELNR)
8425 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8426 else if (game_status == GAME_MODE_SETUP)
8427 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8428 else if (game_status == GAME_MODE_INFO)
8429 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8432 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8433 if (game_status == GAME_MODE_LEVELS)
8434 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8435 else if (game_status == GAME_MODE_LEVELNR)
8436 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8437 else if (game_status == GAME_MODE_SETUP)
8438 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8439 else if (game_status == GAME_MODE_INFO)
8440 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8448 void DumpScreenIdentifiers()
8452 Print("Active screen elements on current screen:\n");
8454 for (i = 0; main_controls[i].nr != -1; i++)
8456 struct MainControlInfo *mci = &main_controls[i];
8458 if (mci->button_graphic != -1)
8460 char *token = getTokenFromImageID(mci->button_graphic);
8462 Print("- '%s'\n", token);
8469 boolean DoScreenAction(int image_id)
8473 if (game_status != GAME_MODE_MAIN)
8476 for (i = 0; main_controls[i].nr != -1; i++)
8478 struct MainControlInfo *mci = &main_controls[i];
8479 struct MenuPosInfo *pos = mci->pos_button;
8481 if (mci->button_graphic == image_id)
8483 int x = mSX + pos->x;
8484 int y = mSY + pos->y;
8486 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);