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
86 #define MAX_SETUP_MODES 36
88 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
90 /* setup screen titles */
91 #define STR_SETUP_MAIN "Setup"
92 #define STR_SETUP_GAME "Game & Menu"
93 #define STR_SETUP_EDITOR "Editor"
94 #define STR_SETUP_GRAPHICS "Graphics"
95 #define STR_SETUP_SOUND "Sound & Music"
96 #define STR_SETUP_ARTWORK "Custom Artwork"
97 #define STR_SETUP_INPUT "Input Devices"
98 #define STR_SETUP_TOUCH "Touch Controls"
99 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
100 #define STR_SETUP_EXIT "Exit"
101 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
103 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
104 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
105 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
106 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
107 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
108 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
109 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
110 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
111 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
112 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
113 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
114 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
115 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
116 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
117 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
118 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
119 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
121 /* for input setup functions */
122 #define SETUPINPUT_SCREEN_POS_START 0
123 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
124 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
125 #define SETUPINPUT_SCREEN_POS_END 13
127 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
128 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
130 /* for various menu stuff */
131 #define MENU_SCREEN_START_XPOS 1
132 #define MENU_SCREEN_START_YPOS 2
133 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
134 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
135 #define MENU_TITLE1_YPOS 8
136 #define MENU_TITLE2_YPOS 46
137 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
138 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
139 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
140 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
141 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
142 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
143 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
144 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
145 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
146 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
147 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
148 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
149 MENU_INFO_FONT_TITLE))
150 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
151 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
152 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
153 MENU_SCREEN_INFO_YSTART2 - \
155 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
156 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
157 MENU_SCREEN_INFO_YSTEP)
158 #define NUM_INFO_ELEMENTS_FROM_CONF \
159 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
160 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
161 MAX_MENU_ENTRIES_ON_SCREEN)
162 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
163 MAX_INFO_ELEMENTS_ON_SCREEN), \
164 NUM_INFO_ELEMENTS_FROM_CONF)
165 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
166 #define MAX_MENU_TEXT_LENGTH_BIG 13
167 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
169 /* buttons and scrollbars identifiers */
170 #define SCREEN_CTRL_ID_PREV_LEVEL 0
171 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
172 #define SCREEN_CTRL_ID_PREV_PLAYER 2
173 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
174 #define SCREEN_CTRL_ID_SCROLL_UP 4
175 #define SCREEN_CTRL_ID_SCROLL_DOWN 5
176 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 6
178 #define NUM_SCREEN_GADGETS 7
180 #define NUM_SCREEN_MENUBUTTONS 4
181 #define NUM_SCREEN_SCROLLBUTTONS 2
182 #define NUM_SCREEN_SCROLLBARS 1
184 #define SCREEN_MASK_MAIN (1 << 0)
185 #define SCREEN_MASK_INPUT (1 << 1)
187 /* graphic position and size values for buttons and scrollbars */
188 #define SC_MENUBUTTON_XSIZE TILEX
189 #define SC_MENUBUTTON_YSIZE TILEY
191 #define SC_SCROLLBUTTON_XSIZE TILEX
192 #define SC_SCROLLBUTTON_YSIZE TILEY
194 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
196 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
197 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
198 SC_SCROLLBUTTON_YSIZE)
200 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
201 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
203 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
204 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
205 SC_SCROLLBUTTON_YSIZE)
207 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
208 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
209 SC_SCROLL_VERTICAL_YSIZE)
211 #define SC_BORDER_SIZE 14
214 /* forward declarations of internal functions */
215 static void HandleScreenGadgets(struct GadgetInfo *);
216 static void HandleSetupScreen_Generic(int, int, int, int, int);
217 static void HandleSetupScreen_Input(int, int, int, int, int);
218 static void CustomizeKeyboard(int);
219 static void ConfigureJoystick(int);
220 static void ConfigureVirtualButtons();
221 static void execSetupGame(void);
222 static void execSetupGraphics(void);
223 static void execSetupSound(void);
224 static void execSetupTouch(void);
225 static void execSetupArtwork(void);
226 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
228 static void DrawChooseLevelSet(void);
229 static void DrawChooseLevelNr(void);
230 static void DrawInfoScreen(void);
231 static void DrawSetupScreen(void);
233 static void DrawInfoScreen_NotAvailable(char *, char *);
234 static void DrawInfoScreen_HelpAnim(int, int, boolean);
235 static void DrawInfoScreen_HelpText(int, int, int, int);
236 static void HandleInfoScreen_Main(int, int, int, int, int);
237 static void HandleInfoScreen_TitleScreen(int);
238 static void HandleInfoScreen_Elements(int);
239 static void HandleInfoScreen_Music(int);
240 static void HandleInfoScreen_Credits(int);
241 static void HandleInfoScreen_Program(int);
242 static void HandleInfoScreen_Version(int);
244 static void MapScreenMenuGadgets(int);
245 static void MapScreenGadgets(int);
246 static void MapScreenTreeGadgets(TreeInfo *);
248 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
250 static int info_mode = INFO_MODE_MAIN;
251 static int setup_mode = SETUP_MODE_MAIN;
253 static TreeInfo *window_sizes = NULL;
254 static TreeInfo *window_size_current = NULL;
256 static TreeInfo *scaling_types = NULL;
257 static TreeInfo *scaling_type_current = NULL;
259 static TreeInfo *rendering_modes = NULL;
260 static TreeInfo *rendering_mode_current = NULL;
262 static TreeInfo *scroll_delays = NULL;
263 static TreeInfo *scroll_delay_current = NULL;
265 static TreeInfo *snapshot_modes = NULL;
266 static TreeInfo *snapshot_mode_current = NULL;
268 static TreeInfo *game_speeds = NULL;
269 static TreeInfo *game_speed_current = NULL;
271 static TreeInfo *volumes_simple = NULL;
272 static TreeInfo *volume_simple_current = NULL;
274 static TreeInfo *volumes_loops = NULL;
275 static TreeInfo *volume_loops_current = NULL;
277 static TreeInfo *volumes_music = NULL;
278 static TreeInfo *volume_music_current = NULL;
280 static TreeInfo *touch_controls = NULL;
281 static TreeInfo *touch_control_current = NULL;
283 static TreeInfo *move_distances = NULL;
284 static TreeInfo *move_distance_current = NULL;
286 static TreeInfo *drop_distances = NULL;
287 static TreeInfo *drop_distance_current = NULL;
289 static TreeInfo *transparencies = NULL;
290 static TreeInfo *transparency_current = NULL;
292 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
293 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
295 static TreeInfo *level_number = NULL;
296 static TreeInfo *level_number_current = NULL;
302 } window_sizes_list[] =
307 { 100, "100 % (Default)" },
324 } scaling_types_list[] =
326 { SCALING_QUALITY_NEAREST, "Off" },
327 { SCALING_QUALITY_LINEAR, "Linear" },
328 { SCALING_QUALITY_BEST, "Anisotropic" },
337 } rendering_modes_list[] =
339 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
340 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
342 // this mode may work under certain conditions, but does not work on Windows
343 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
345 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
354 } game_speeds_list[] =
363 { 1000, "1/1s (Extremely Slow)" },
368 { 29, "1/35s (Original Supaplex)" },
370 { 20, "1/50s (Normal Speed)" },
371 { 14, "1/70s (Maximum Supaplex)" },
375 { 1, "1/1000s (Extremely Fast)" },
385 } scroll_delays_list[] =
387 { 0, "0 Tiles (No Scroll Delay)" },
390 { 3, "3 Tiles (Default)" },
395 { 8, "8 Tiles (Maximum Scroll Delay)"},
404 } snapshot_modes_list[] =
406 { STR_SNAPSHOT_MODE_OFF, "Off" },
407 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
408 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
409 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
442 } touch_controls_list[] =
444 { TOUCH_CONTROL_OFF, "Off" },
445 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
446 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
447 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
475 } transparencies_list[] =
477 { 0, "0 % (Opaque)" },
487 { 100, "100 % (Invisible)" },
496 } grid_sizes_list[] =
532 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
533 (s) <= GAME_MODE_SETUP ? (s) : \
534 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
535 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
537 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
538 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
539 (i) <= INFO_MODE_LEVELSET ? (i) : \
542 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
543 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
544 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
545 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
546 SETUP_MODE_CHOOSE_ARTWORK : \
547 SETUP_MODE_CHOOSE_OTHER)
549 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
550 menu.draw_xoffset[GAME_MODE_INFO] : \
551 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
552 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
553 menu.draw_yoffset[GAME_MODE_INFO] : \
554 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
555 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
556 menu.extra_spacing[GAME_MODE_INFO] : \
557 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
559 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
560 menu.draw_xoffset[GAME_MODE_SETUP] : \
561 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
562 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
563 menu.draw_yoffset[GAME_MODE_SETUP] : \
564 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
565 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
566 menu.extra_spacing[GAME_MODE_SETUP] : \
567 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
569 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
570 DRAW_XOFFSET_INFO(info_mode) : \
571 (s) == GAME_MODE_SETUP ? \
572 DRAW_XOFFSET_SETUP(setup_mode) : \
573 menu.draw_xoffset[DRAW_MODE(s)])
574 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
575 DRAW_YOFFSET_INFO(info_mode) : \
576 (s) == GAME_MODE_SETUP ? \
577 DRAW_YOFFSET_SETUP(setup_mode) : \
578 menu.draw_yoffset[DRAW_MODE(s)])
579 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
580 EXTRA_SPACING_INFO(info_mode) : \
581 (s) == GAME_MODE_SETUP ? \
582 EXTRA_SPACING_SETUP(setup_mode) : \
583 menu.extra_spacing[DRAW_MODE(s)])
585 #define mSX (SX + DRAW_XOFFSET(game_status))
586 #define mSY (SY + DRAW_YOFFSET(game_status))
588 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
589 menu.list_size[game_status] : \
590 MAX_MENU_ENTRIES_ON_SCREEN)
592 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
593 NUM_MENU_ENTRIES_ON_SCREEN)
596 /* title display and control definitions */
598 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
599 2 * MAX_NUM_TITLE_MESSAGES)
601 #define NO_DIRECT_LEVEL_SELECT (-1)
604 static int num_title_screens = 0;
606 struct TitleControlInfo
615 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
617 /* main menu display and control definitions */
619 #define MAIN_CONTROL_NAME 0
620 #define MAIN_CONTROL_LEVELS 1
621 #define MAIN_CONTROL_SCORES 2
622 #define MAIN_CONTROL_EDITOR 3
623 #define MAIN_CONTROL_INFO 4
624 #define MAIN_CONTROL_GAME 5
625 #define MAIN_CONTROL_SETUP 6
626 #define MAIN_CONTROL_QUIT 7
627 #define MAIN_CONTROL_PREV_LEVEL 8
628 #define MAIN_CONTROL_NEXT_LEVEL 9
629 #define MAIN_CONTROL_FIRST_LEVEL 10
630 #define MAIN_CONTROL_LAST_LEVEL 11
631 #define MAIN_CONTROL_LEVEL_NUMBER 12
632 #define MAIN_CONTROL_LEVEL_INFO_1 13
633 #define MAIN_CONTROL_LEVEL_INFO_2 14
634 #define MAIN_CONTROL_LEVEL_NAME 15
635 #define MAIN_CONTROL_LEVEL_AUTHOR 16
636 #define MAIN_CONTROL_LEVEL_YEAR 17
637 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
638 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
639 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
640 #define MAIN_CONTROL_TITLE_1 21
641 #define MAIN_CONTROL_TITLE_2 22
642 #define MAIN_CONTROL_TITLE_3 23
644 static char str_main_text_name[10];
645 static char str_main_text_first_level[10];
646 static char str_main_text_last_level[10];
647 static char str_main_text_level_number[10];
649 static char *main_text_name = str_main_text_name;
650 static char *main_text_first_level = str_main_text_first_level;
651 static char *main_text_last_level = str_main_text_last_level;
652 static char *main_text_level_number = str_main_text_level_number;
653 static char *main_text_levels = "Levelset";
654 static char *main_text_scores = "Hall Of Fame";
655 static char *main_text_editor = "Level Creator";
656 static char *main_text_info = "Info Screen";
657 static char *main_text_game = "Start Game";
658 static char *main_text_setup = "Setup";
659 static char *main_text_quit = "Quit";
660 static char *main_text_level_name = level.name;
661 static char *main_text_level_author = level.author;
662 static char *main_text_level_year = NULL;
663 static char *main_text_level_imported_from = NULL;
664 static char *main_text_level_imported_by = NULL;
665 static char *main_text_level_tested_by = NULL;
666 static char *main_text_title_1 = NULL;
667 static char *main_text_title_2 = NULL;
668 static char *main_text_title_3 = NULL;
670 struct MainControlInfo
674 struct MenuPosInfo *pos_button;
677 struct TextPosInfo *pos_text;
680 struct TextPosInfo *pos_input;
684 static struct MainControlInfo main_controls[] =
688 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
689 &menu.main.text.name, &main_text_name,
690 &menu.main.input.name, &setup.player_name,
694 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
695 &menu.main.text.levels, &main_text_levels,
700 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
701 &menu.main.text.scores, &main_text_scores,
706 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
707 &menu.main.text.editor, &main_text_editor,
712 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
713 &menu.main.text.info, &main_text_info,
718 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
719 &menu.main.text.game, &main_text_game,
724 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
725 &menu.main.text.setup, &main_text_setup,
730 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
731 &menu.main.text.quit, &main_text_quit,
735 /* (these two buttons are real gadgets) */
737 MAIN_CONTROL_PREV_LEVEL,
738 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
743 MAIN_CONTROL_NEXT_LEVEL,
744 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
750 MAIN_CONTROL_FIRST_LEVEL,
752 &menu.main.text.first_level, &main_text_first_level,
756 MAIN_CONTROL_LAST_LEVEL,
758 &menu.main.text.last_level, &main_text_last_level,
762 MAIN_CONTROL_LEVEL_NUMBER,
764 &menu.main.text.level_number, &main_text_level_number,
768 MAIN_CONTROL_LEVEL_INFO_1,
770 &menu.main.text.level_info_1, NULL,
774 MAIN_CONTROL_LEVEL_INFO_2,
776 &menu.main.text.level_info_2, NULL,
780 MAIN_CONTROL_LEVEL_NAME,
782 &menu.main.text.level_name, &main_text_level_name,
786 MAIN_CONTROL_LEVEL_AUTHOR,
788 &menu.main.text.level_author, &main_text_level_author,
792 MAIN_CONTROL_LEVEL_YEAR,
794 &menu.main.text.level_year, &main_text_level_year,
798 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
800 &menu.main.text.level_imported_from, &main_text_level_imported_from,
804 MAIN_CONTROL_LEVEL_IMPORTED_BY,
806 &menu.main.text.level_imported_by, &main_text_level_imported_by,
810 MAIN_CONTROL_LEVEL_TESTED_BY,
812 &menu.main.text.level_tested_by, &main_text_level_tested_by,
816 MAIN_CONTROL_TITLE_1,
818 &menu.main.text.title_1, &main_text_title_1,
822 MAIN_CONTROL_TITLE_2,
824 &menu.main.text.title_2, &main_text_title_2,
828 MAIN_CONTROL_TITLE_3,
830 &menu.main.text.title_3, &main_text_title_3,
843 static int getTitleScreenGraphic(int nr, boolean initial)
845 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
848 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
850 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
854 static int getTitleScreenGameMode(boolean initial)
856 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
860 static int getTitleMessageGameMode(boolean initial)
862 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
865 static int getTitleAnimMode(struct TitleControlInfo *tci)
867 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
869 return base + tci->local_nr;
873 static int getTitleScreenBackground(boolean initial)
875 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
880 static int getTitleMessageBackground(int nr, boolean initial)
882 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
886 static int getTitleBackground(int nr, boolean initial, boolean is_image)
888 int base = (is_image ?
889 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
890 IMG_BACKGROUND_TITLESCREEN_1) :
891 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
892 IMG_BACKGROUND_TITLEMESSAGE_1));
893 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
894 IMG_BACKGROUND_TITLE);
895 int graphic_local = base + nr;
897 if (graphic_info[graphic_local].bitmap != NULL)
898 return graphic_local;
900 if (graphic_info[graphic_global].bitmap != NULL)
901 return graphic_global;
903 return IMG_UNDEFINED;
906 static int getTitleSound(struct TitleControlInfo *tci)
908 boolean is_image = tci->is_image;
909 int initial = tci->initial;
910 int nr = tci->local_nr;
911 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
912 int base = (is_image ?
913 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
914 SND_BACKGROUND_TITLESCREEN_1) :
915 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
916 SND_BACKGROUND_TITLEMESSAGE_1));
917 int sound_global = menu.sound[mode];
918 int sound_local = base + nr;
921 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
922 nr, initial, is_image,
923 sound_global, getSoundListEntry(sound_global)->filename,
924 sound_local, getSoundListEntry(sound_local)->filename);
927 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
930 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
933 return SND_UNDEFINED;
936 static int getTitleMusic(struct TitleControlInfo *tci)
938 boolean is_image = tci->is_image;
939 int initial = tci->initial;
940 int nr = tci->local_nr;
941 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
942 int base = (is_image ?
943 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
944 MUS_BACKGROUND_TITLESCREEN_1) :
945 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
946 MUS_BACKGROUND_TITLEMESSAGE_1));
947 int music_global = menu.music[mode];
948 int music_local = base + nr;
951 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
952 nr, initial, is_image,
953 music_global, getMusicListEntry(music_global)->filename,
954 music_local, getMusicListEntry(music_local)->filename);
957 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
960 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
963 return MUS_UNDEFINED;
966 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
968 boolean is_image = tci->is_image;
969 boolean initial = tci->initial;
970 boolean first = tci->first;
971 int nr = tci->local_nr;
972 struct TitleMessageInfo tmi;
973 struct TitleFadingInfo ti;
975 tmi = (is_image ? (initial ? (first ?
976 titlescreen_initial_first[nr] :
977 titlescreen_initial[nr])
979 titlescreen_first[nr] :
981 : (initial ? (first ?
982 titlemessage_initial_first[nr] :
983 titlemessage_initial[nr])
985 titlemessage_first[nr] :
988 ti.fade_mode = tmi.fade_mode;
989 ti.fade_delay = tmi.fade_delay;
990 ti.post_delay = tmi.post_delay;
991 ti.auto_delay = tmi.auto_delay;
996 static int compareTitleControlInfo(const void *object1, const void *object2)
998 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
999 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1002 if (tci1->initial != tci2->initial)
1003 compare_result = (tci1->initial ? -1 : +1);
1004 else if (tci1->sort_priority != tci2->sort_priority)
1005 compare_result = tci1->sort_priority - tci2->sort_priority;
1006 else if (tci1->is_image != tci2->is_image)
1007 compare_result = (tci1->is_image ? -1 : +1);
1009 compare_result = tci1->local_nr - tci2->local_nr;
1011 return compare_result;
1014 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1016 int nr, int sort_priority)
1018 title_controls[num_title_screens].is_image = is_image;
1019 title_controls[num_title_screens].initial = initial;
1020 title_controls[num_title_screens].local_nr = nr;
1021 title_controls[num_title_screens].sort_priority = sort_priority;
1023 title_controls[num_title_screens].first = FALSE; /* will be set later */
1025 num_title_screens++;
1028 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1032 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1034 int graphic = getTitleScreenGraphic(i, initial);
1035 Bitmap *bitmap = graphic_info[graphic].bitmap;
1036 int sort_priority = graphic_info[graphic].sort_priority;
1039 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1042 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1044 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1045 char *filename = getLevelSetTitleMessageFilename(i, initial);
1046 int sort_priority = tmi->sort_priority;
1048 if (filename != NULL)
1049 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1053 static void InitializeTitleControls(boolean show_title_initial)
1055 num_title_screens = 0;
1057 /* 1st step: initialize title screens for game start (only when starting) */
1058 if (show_title_initial)
1059 InitializeTitleControls_CheckTitleInfo(TRUE);
1061 /* 2nd step: initialize title screens for current level set */
1062 InitializeTitleControls_CheckTitleInfo(FALSE);
1064 /* sort title screens according to sort_priority and title number */
1065 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1066 compareTitleControlInfo);
1068 /* mark first title screen */
1069 title_controls[0].first = TRUE;
1072 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1074 return (pos != NULL && pos->x != -1 && pos->y != -1);
1077 static boolean visibleTextPos(struct TextPosInfo *pos)
1079 return (pos != NULL && pos->x != -1 && pos->y != -1);
1082 static void InitializeMainControls()
1084 boolean local_team_mode = (!options.network && setup.team_mode);
1087 /* set main control text values to dynamically determined values */
1088 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1090 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1091 menu.main.text.first_level.size));
1092 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1093 menu.main.text.last_level.size));
1094 strcpy(main_text_level_number, int2str(level_nr,
1095 menu.main.text.level_number.size));
1097 main_text_level_year = leveldir_current->year;
1098 main_text_level_imported_from = leveldir_current->imported_from;
1099 main_text_level_imported_by = leveldir_current->imported_by;
1100 main_text_level_tested_by = leveldir_current->tested_by;
1102 main_text_title_1 = getConfigProgramTitleString();
1103 main_text_title_2 = getConfigProgramCopyrightString();
1104 main_text_title_3 = getConfigProgramCompanyString();
1106 /* set main control screen positions to dynamically determined values */
1107 for (i = 0; main_controls[i].nr != -1; i++)
1109 struct MainControlInfo *mci = &main_controls[i];
1111 struct MenuPosInfo *pos_button = mci->pos_button;
1112 struct TextPosInfo *pos_text = mci->pos_text;
1113 struct TextPosInfo *pos_input = mci->pos_input;
1114 char *text = (mci->text ? *mci->text : NULL);
1115 char *input = (mci->input ? *mci->input : NULL);
1116 int button_graphic = mci->button_graphic;
1117 int font_text = (pos_text ? pos_text->font : -1);
1118 int font_input = (pos_input ? pos_input->font : -1);
1120 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1121 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1122 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1123 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1124 int text_chars = (text != NULL ? strlen(text) : 0);
1125 int input_chars = (input != NULL ? strlen(input) : 0);
1128 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1130 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1131 int text_width = font_text_width * text_chars;
1132 int text_height = font_text_height;
1133 int input_width = font_input_width * input_chars;
1134 int input_height = font_input_height;
1136 if (nr == MAIN_CONTROL_NAME)
1138 menu.main.input.name.width = input_width;
1139 menu.main.input.name.height = input_height;
1142 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1144 pos_button->width = button_width;
1145 pos_button->height = button_height;
1148 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1150 /* calculate size for non-clickable text -- needed for text alignment */
1151 boolean calculate_text_size = (pos_button == NULL && text != NULL);
1153 if (pos_text->width == -1 || calculate_text_size)
1154 pos_text->width = text_width;
1155 if (pos_text->height == -1 || calculate_text_size)
1156 pos_text->height = text_height;
1158 if (visibleMenuPos(pos_button))
1160 if (pos_text->x == -1)
1161 pos_text->x = pos_button->x + pos_button->width;
1162 if (pos_text->y == -1)
1164 pos_button->y + (pos_button->height - pos_text->height) / 2;
1168 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1170 if (visibleTextPos(pos_text))
1172 if (pos_input->x == -1)
1173 pos_input->x = pos_text->x + pos_text->width;
1174 if (pos_input->y == -1)
1175 pos_input->y = pos_text->y;
1178 if (pos_input->width == -1)
1179 pos_input->width = input_width;
1180 if (pos_input->height == -1)
1181 pos_input->height = input_height;
1186 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1187 int graphic, boolean pressed)
1189 struct GraphicInfo *g = &graphic_info[graphic];
1192 int xoffset = (pressed ? g->pressed_xoffset : 0);
1193 int yoffset = (pressed ? g->pressed_yoffset : 0);
1195 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1197 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1198 g->width, g->height, dst_x, dst_y);
1201 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1202 boolean active_input,
1203 boolean pressed_button)
1207 for (i = 0; main_controls[i].nr != -1; i++)
1209 struct MainControlInfo *mci = &main_controls[i];
1211 if (mci->nr == nr || nr == -1)
1213 struct MenuPosInfo *pos_button = mci->pos_button;
1214 struct TextPosInfo *pos_text = mci->pos_text;
1215 struct TextPosInfo *pos_input = mci->pos_input;
1216 char *text = (mci->text ? *mci->text : NULL);
1217 char *input = (mci->input ? *mci->input : NULL);
1218 int button_graphic = mci->button_graphic;
1219 int font_text = (pos_text ? pos_text->font : -1);
1220 int font_input = (pos_input ? pos_input->font : -1);
1224 button_graphic = BUTTON_ACTIVE(button_graphic);
1225 font_text = FONT_ACTIVE(font_text);
1230 font_input = FONT_ACTIVE(font_input);
1233 if (visibleMenuPos(pos_button))
1235 struct MenuPosInfo *pos = pos_button;
1236 int x = mSX + pos->x;
1237 int y = mSY + pos->y;
1239 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1240 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1243 if (visibleTextPos(pos_text) && text != NULL)
1245 struct TextPosInfo *pos = pos_text;
1246 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1247 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1250 /* (check why/if this is needed) */
1251 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1253 DrawText(x, y, text, font_text);
1256 if (visibleTextPos(pos_input) && input != NULL)
1258 struct TextPosInfo *pos = pos_input;
1259 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1260 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1263 /* (check why/if this is needed) */
1264 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1266 DrawText(x, y, input, font_input);
1272 static void DrawCursorAndText_Main(int nr, boolean active_text,
1273 boolean pressed_button)
1275 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1279 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1280 boolean pressed_button)
1282 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1286 static struct MainControlInfo *getMainControlInfo(int nr)
1290 for (i = 0; main_controls[i].nr != -1; i++)
1291 if (main_controls[i].nr == nr)
1292 return &main_controls[i];
1297 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1302 int rect_x = ALIGNED_TEXT_XPOS(rect);
1303 int rect_y = ALIGNED_TEXT_YPOS(rect);
1305 return (x >= rect_x && x < rect_x + rect->width &&
1306 y >= rect_y && y < rect_y + rect->height);
1309 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1314 int rect_x = ALIGNED_TEXT_XPOS(rect);
1315 int rect_y = ALIGNED_TEXT_YPOS(rect);
1318 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1319 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1320 (x >= rect_x && x < rect_x + rect->width &&
1321 y >= rect_y && y < rect_y + rect->height));
1324 return (x >= rect_x && x < rect_x + rect->width &&
1325 y >= rect_y && y < rect_y + rect->height);
1328 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1330 int rect_width = preview->xsize * preview->tile_size;
1331 int rect_height = preview->ysize * preview->tile_size;
1332 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1333 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1335 return (x >= rect_x && x < rect_x + rect_width &&
1336 y >= rect_y && y < rect_y + rect_height);
1339 static void AdjustScrollbar(int id, int items_max, int items_visible,
1342 struct GadgetInfo *gi = screen_gadget[id];
1344 if (item_position > items_max - items_visible)
1345 item_position = items_max - items_visible;
1347 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1348 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1349 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1352 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1354 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1358 static void clearMenuListArea()
1360 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1362 /* correct scrollbar position if placed outside menu (playfield) area */
1363 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1364 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1366 /* clear menu list area, but not title or scrollbar */
1367 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1368 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1371 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1373 static int cursor_array[MAX_LEV_FIELDY];
1374 int x = mSX + TILEX * xpos;
1375 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1380 cursor_array[ypos] = graphic;
1382 graphic = cursor_array[ypos];
1386 graphic = BUTTON_ACTIVE(graphic);
1388 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1389 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1392 static void initCursor(int ypos, int graphic)
1394 drawCursorExt(0, ypos, FALSE, graphic);
1397 static void drawCursor(int ypos, boolean active)
1399 drawCursorExt(0, ypos, active, -1);
1402 static void drawCursorXY(int xpos, int ypos, int graphic)
1404 drawCursorExt(xpos, ypos, FALSE, graphic);
1407 static void drawChooseTreeCursor(int ypos, boolean active)
1409 drawCursorExt(0, ypos, active, -1);
1414 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1415 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1418 void DrawTitleScreenImage(int nr, boolean initial)
1420 int graphic = getTitleScreenGraphic(nr, initial);
1421 Bitmap *bitmap = graphic_info[graphic].bitmap;
1422 int width = graphic_info[graphic].width;
1423 int height = graphic_info[graphic].height;
1424 int src_x = graphic_info[graphic].src_x;
1425 int src_y = graphic_info[graphic].src_y;
1431 if (width > WIN_XSIZE)
1433 /* image width too large for window => center image horizontally */
1434 src_x = (width - WIN_XSIZE) / 2;
1438 if (height > WIN_YSIZE)
1440 /* image height too large for window => center image vertically */
1441 src_y = (height - WIN_YSIZE) / 2;
1445 /* always display title screens centered */
1446 dst_x = (WIN_XSIZE - width) / 2;
1447 dst_y = (WIN_YSIZE - height) / 2;
1449 SetDrawBackgroundMask(REDRAW_ALL);
1450 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1452 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1454 if (DrawingOnBackground(dst_x, dst_y))
1455 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1457 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1459 redraw_mask = REDRAW_ALL;
1462 void DrawTitleScreenMessage(int nr, boolean initial)
1464 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1465 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1467 if (filename == NULL)
1470 /* force TITLE font on title message screen */
1471 SetFontStatus(getTitleMessageGameMode(initial));
1473 /* if chars *and* width set to "-1", automatically determine width */
1474 if (tmi->chars == -1 && tmi->width == -1)
1475 tmi->width = viewport.window[game_status].width;
1477 /* if lines *and* height set to "-1", automatically determine height */
1478 if (tmi->lines == -1 && tmi->height == -1)
1479 tmi->height = viewport.window[game_status].height;
1481 /* if chars set to "-1", automatically determine by text and font width */
1482 if (tmi->chars == -1)
1483 tmi->chars = tmi->width / getFontWidth(tmi->font);
1485 tmi->width = tmi->chars * getFontWidth(tmi->font);
1487 /* if lines set to "-1", automatically determine by text and font height */
1488 if (tmi->lines == -1)
1489 tmi->lines = tmi->height / getFontHeight(tmi->font);
1491 tmi->height = tmi->lines * getFontHeight(tmi->font);
1493 /* if x set to "-1", automatically determine by width and alignment */
1495 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1497 /* if y set to "-1", automatically determine by height and alignment */
1499 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1501 SetDrawBackgroundMask(REDRAW_ALL);
1502 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1504 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1506 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1507 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1508 tmi->autowrap, tmi->centered, tmi->parse_comments);
1513 void DrawTitleScreen()
1515 KeyboardAutoRepeatOff();
1517 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1520 boolean CheckTitleScreen(boolean levelset_has_changed)
1522 static boolean show_title_initial = TRUE;
1523 boolean show_titlescreen = FALSE;
1525 /* needed to be able to skip title screen, if no image or message defined */
1526 InitializeTitleControls(show_title_initial);
1528 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1529 show_titlescreen = TRUE;
1531 /* show initial title images and messages only once at program start */
1532 show_title_initial = FALSE;
1534 return (show_titlescreen && num_title_screens > 0);
1539 static LevelDirTree *leveldir_last_valid = NULL;
1540 boolean levelset_has_changed = FALSE;
1541 int fade_mask = REDRAW_FIELD;
1543 LimitScreenUpdates(FALSE);
1545 FadeSetLeaveScreen();
1547 /* do not fade out here -- function may continue and fade on editor screen */
1550 FadeMenuSoundsAndMusic();
1552 ExpireSoundLoops(FALSE);
1554 KeyboardAutoRepeatOn();
1556 audio.sound_deactivated = FALSE;
1560 /* needed if last screen was the playing screen, invoked from level editor */
1561 if (level_editor_test_game)
1563 CloseDoor(DOOR_CLOSE_ALL);
1565 SetGameStatus(GAME_MODE_EDITOR);
1572 /* needed if last screen was the setup screen and fullscreen state changed */
1573 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1574 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1576 /* leveldir_current may be invalid (level group, parent link) */
1577 if (!validLevelSeries(leveldir_current))
1578 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1580 if (leveldir_current != leveldir_last_valid)
1581 levelset_has_changed = TRUE;
1583 /* store valid level series information */
1584 leveldir_last_valid = leveldir_current;
1586 init_last = init; /* switch to new busy animation */
1588 /* needed if last screen (level choice) changed graphics, sounds or music */
1589 ReloadCustomArtwork(0);
1591 if (CheckTitleScreen(levelset_has_changed))
1593 SetGameStatus(GAME_MODE_TITLE);
1600 if (redraw_mask & REDRAW_ALL)
1601 fade_mask = REDRAW_ALL;
1603 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1604 fade_mask = REDRAW_ALL;
1608 /* needed if different viewport properties defined for menues */
1609 ChangeViewportPropertiesIfNeeded();
1611 SetDrawtoField(DRAW_TO_BACKBUFFER);
1613 /* level_nr may have been set to value over handicap with level editor */
1614 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1615 level_nr = leveldir_current->handicap_level;
1617 LoadLevel(level_nr);
1618 LoadScore(level_nr);
1620 SaveLevelSetup_SeriesInfo();
1622 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1623 SetDrawDeactivationMask(REDRAW_NONE);
1624 SetDrawBackgroundMask(REDRAW_FIELD);
1626 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1629 if (fade_mask == REDRAW_ALL)
1630 RedrawGlobalBorder();
1635 InitializeMainControls();
1637 DrawCursorAndText_Main(-1, FALSE, FALSE);
1638 DrawPreviewLevelInitial();
1640 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1643 if (TAPE_IS_EMPTY(tape))
1645 DrawCompleteVideoDisplay();
1647 PlayMenuSoundsAndMusic();
1649 /* create gadgets for main menu screen */
1650 FreeScreenGadgets();
1651 CreateScreenGadgets();
1653 /* map gadgets for main menu screen */
1655 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1657 /* copy actual game door content to door double buffer for OpenDoor() */
1658 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1659 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1661 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1663 DrawMaskedBorder(fade_mask);
1668 /* update screen area with special editor door */
1669 redraw_mask |= REDRAW_ALL;
1672 SetMouseCursor(CURSOR_DEFAULT);
1674 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1677 static void gotoTopLevelDir()
1679 /* move upwards until inside (but not above) top level directory */
1680 while (leveldir_current->node_parent &&
1681 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1683 /* write a "path" into level tree for easy navigation to last level */
1684 if (leveldir_current->node_parent->node_group->cl_first == -1)
1686 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1687 int leveldir_pos = posTreeInfo(leveldir_current);
1688 int num_page_entries;
1689 int cl_first, cl_cursor;
1691 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1692 num_page_entries = num_leveldirs;
1694 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1696 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1697 cl_cursor = leveldir_pos - cl_first;
1699 leveldir_current->node_parent->node_group->cl_first = cl_first;
1700 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1703 leveldir_current = leveldir_current->node_parent;
1707 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1709 static unsigned int title_delay = 0;
1710 static int title_screen_nr = 0;
1711 static int last_sound = -1, last_music = -1;
1712 boolean return_to_main_menu = FALSE;
1713 struct TitleControlInfo *tci;
1716 if (button == MB_MENU_INITIALIZE)
1719 title_screen_nr = 0;
1720 tci = &title_controls[title_screen_nr];
1722 SetAnimStatus(getTitleAnimMode(tci));
1724 last_sound = SND_UNDEFINED;
1725 last_music = MUS_UNDEFINED;
1727 if (num_title_screens != 0)
1729 FadeSetEnterScreen();
1731 /* use individual title fading instead of global "enter screen" fading */
1732 fading = getTitleFading(tci);
1735 if (game_status_last_screen == GAME_MODE_INFO)
1737 if (num_title_screens == 0)
1739 /* switch game mode from title screen mode back to info screen mode */
1740 SetGameStatus(GAME_MODE_INFO);
1742 /* store that last screen was info screen, not main menu screen */
1743 game_status_last_screen = GAME_MODE_INFO;
1745 DrawInfoScreen_NotAvailable("Title screen information:",
1746 "No title screen for this level set.");
1750 FadeMenuSoundsAndMusic();
1753 FadeOut(REDRAW_ALL);
1755 /* title screens may have different window size */
1756 ChangeViewportPropertiesIfNeeded();
1758 /* only required to update logic for redrawing global border */
1762 DrawTitleScreenImage(tci->local_nr, tci->initial);
1764 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1766 sound = getTitleSound(tci);
1767 music = getTitleMusic(tci);
1769 if (sound != last_sound)
1770 PlayMenuSoundExt(sound);
1771 if (music != last_music)
1772 PlayMenuMusicExt(music);
1777 SetMouseCursor(CURSOR_NONE);
1781 DelayReached(&title_delay, 0); /* reset delay counter */
1786 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1787 button = MB_MENU_CHOICE;
1789 if (button == MB_MENU_LEAVE)
1791 return_to_main_menu = TRUE;
1793 else if (button == MB_MENU_CHOICE)
1795 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1797 SetGameStatus(GAME_MODE_INFO);
1799 info_mode = INFO_MODE_MAIN;
1808 if (title_screen_nr < num_title_screens)
1810 tci = &title_controls[title_screen_nr];
1812 SetAnimStatus(getTitleAnimMode(tci));
1814 sound = getTitleSound(tci);
1815 music = getTitleMusic(tci);
1817 if (last_sound != SND_UNDEFINED && sound != last_sound)
1818 FadeSound(last_sound);
1819 if (last_music != MUS_UNDEFINED && music != last_music)
1822 fading = getTitleFading(tci);
1824 FadeOut(REDRAW_ALL);
1827 DrawTitleScreenImage(tci->local_nr, tci->initial);
1829 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1831 sound = getTitleSound(tci);
1832 music = getTitleMusic(tci);
1834 if (sound != last_sound)
1835 PlayMenuSoundExt(sound);
1836 if (music != last_music)
1837 PlayMenuMusicExt(music);
1844 DelayReached(&title_delay, 0); /* reset delay counter */
1848 FadeMenuSoundsAndMusic();
1850 return_to_main_menu = TRUE;
1854 if (return_to_main_menu)
1856 SetMouseCursor(CURSOR_DEFAULT);
1858 /* force full menu screen redraw after displaying title screens */
1859 redraw_mask = REDRAW_ALL;
1861 if (game_status_last_screen == GAME_MODE_INFO)
1863 SetGameStatus(GAME_MODE_INFO);
1865 info_mode = INFO_MODE_MAIN;
1869 else /* default: return to main menu */
1871 SetGameStatus(GAME_MODE_MAIN);
1878 void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr)
1880 int old_level_nr = level_nr;
1883 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1884 new_level_nr = selected_level_nr;
1886 new_level_nr = old_level_nr + step * direction;
1888 if (new_level_nr < leveldir_current->first_level)
1889 new_level_nr = leveldir_current->first_level;
1890 if (new_level_nr > leveldir_current->last_level)
1891 new_level_nr = leveldir_current->last_level;
1893 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1895 /* skipping levels is only allowed when trying to skip single level */
1896 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1897 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1899 leveldir_current->handicap_level++;
1900 SaveLevelSetup_SeriesInfo();
1903 new_level_nr = leveldir_current->handicap_level;
1906 if (new_level_nr != old_level_nr)
1908 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1910 PlaySound(SND_MENU_ITEM_SELECTING);
1912 level_nr = new_level_nr;
1914 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1915 int2str(level_nr, menu.main.text.level_number.size),
1916 mci->pos_text->font);
1918 LoadLevel(level_nr);
1919 DrawPreviewLevelInitial();
1923 DrawCompleteVideoDisplay();
1925 SaveLevelSetup_SeriesInfo();
1927 /* needed because DrawPreviewLevelInitial() takes some time */
1929 /* SyncDisplay(); */
1933 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1935 static int choice = MAIN_CONTROL_GAME;
1936 static boolean button_pressed_last = FALSE;
1937 boolean button_pressed = FALSE;
1941 if (button == MB_MENU_INITIALIZE)
1943 DrawCursorAndText_Main(choice, TRUE, FALSE);
1948 if (mx || my) /* mouse input */
1952 for (i = 0; main_controls[i].nr != -1; i++)
1954 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1955 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1956 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1958 pos = main_controls[i].nr;
1964 /* check if level preview was clicked */
1965 if (insidePreviewRect(&preview, mx - SX, my - SY))
1966 pos = MAIN_CONTROL_GAME;
1968 // handle pressed/unpressed state for active/inactive menu buttons
1969 // (if pos != -1, "i" contains index position corresponding to "pos")
1971 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
1972 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
1973 button_pressed = TRUE;
1975 if (button_pressed != button_pressed_last)
1977 DrawCursorAndText_Main(choice, TRUE, button_pressed);
1980 PlaySound(SND_MENU_BUTTON_PRESSING);
1982 PlaySound(SND_MENU_BUTTON_RELEASING);
1985 else if (dx || dy) /* keyboard input */
1987 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
1988 choice == MAIN_CONTROL_SETUP))
1989 button = MB_MENU_CHOICE;
1994 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
1996 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
1998 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2000 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2002 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2004 CloseDoor(DOOR_CLOSE_2);
2006 SetGameStatus(GAME_MODE_LEVELNR);
2008 DrawChooseLevelNr();
2010 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2016 PlaySound(SND_MENU_ITEM_ACTIVATING);
2018 DrawCursorAndText_Main(choice, FALSE, FALSE);
2019 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2025 if (choice != MAIN_CONTROL_INFO &&
2026 choice != MAIN_CONTROL_SETUP)
2027 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2032 PlaySound(SND_MENU_ITEM_SELECTING);
2034 if (pos == MAIN_CONTROL_NAME)
2036 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2038 HandleTypeName(strlen(setup.player_name), 0);
2040 else if (pos == MAIN_CONTROL_LEVELS)
2044 CloseDoor(DOOR_CLOSE_2);
2046 SetGameStatus(GAME_MODE_LEVELS);
2048 SaveLevelSetup_LastSeries();
2049 SaveLevelSetup_SeriesInfo();
2051 if (setup.internal.choose_from_top_leveldir)
2054 DrawChooseLevelSet();
2057 else if (pos == MAIN_CONTROL_SCORES)
2059 CloseDoor(DOOR_CLOSE_2);
2061 SetGameStatus(GAME_MODE_SCORES);
2065 else if (pos == MAIN_CONTROL_EDITOR)
2067 if (leveldir_current->readonly &&
2068 !strEqual(setup.player_name, "Artsoft"))
2069 Request("This level is read only!", REQ_CONFIRM);
2071 CloseDoor(DOOR_CLOSE_2);
2073 SetGameStatus(GAME_MODE_EDITOR);
2075 FadeSetEnterScreen();
2079 else if (pos == MAIN_CONTROL_INFO)
2081 CloseDoor(DOOR_CLOSE_2);
2083 SetGameStatus(GAME_MODE_INFO);
2085 info_mode = INFO_MODE_MAIN;
2089 else if (pos == MAIN_CONTROL_GAME)
2091 StartGameActions(options.network, setup.autorecord, level.random_seed);
2093 else if (pos == MAIN_CONTROL_SETUP)
2095 CloseDoor(DOOR_CLOSE_2);
2097 SetGameStatus(GAME_MODE_SETUP);
2099 setup_mode = SETUP_MODE_MAIN;
2103 else if (pos == MAIN_CONTROL_QUIT)
2105 SaveLevelSetup_LastSeries();
2106 SaveLevelSetup_SeriesInfo();
2108 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2109 SetGameStatus(GAME_MODE_QUIT);
2114 button_pressed_last = button_pressed;
2118 /* ========================================================================= */
2119 /* info screen functions */
2120 /* ========================================================================= */
2122 static struct TokenInfo *info_info;
2123 static int num_info_info; /* number of info entries shown on screen */
2124 static int max_info_info; /* total number of info entries in list */
2126 static void execInfoTitleScreen()
2128 info_mode = INFO_MODE_TITLE;
2133 static void execInfoElements()
2135 info_mode = INFO_MODE_ELEMENTS;
2140 static void execInfoMusic()
2142 info_mode = INFO_MODE_MUSIC;
2147 static void execInfoCredits()
2149 info_mode = INFO_MODE_CREDITS;
2154 static void execInfoProgram()
2156 info_mode = INFO_MODE_PROGRAM;
2161 static void execInfoVersion()
2163 info_mode = INFO_MODE_VERSION;
2168 static void execInfoLevelSet()
2170 info_mode = INFO_MODE_LEVELSET;
2175 static void execExitInfo()
2177 SetGameStatus(GAME_MODE_MAIN);
2182 static struct TokenInfo info_info_main[] =
2184 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2185 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2186 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2187 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2188 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2189 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2190 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2191 { TYPE_EMPTY, NULL, "" },
2192 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2197 static int getMenuTextFont(int type)
2199 if (type & (TYPE_SWITCH |
2211 static struct TokenInfo *setup_info;
2212 static struct TokenInfo setup_info_input[];
2214 static struct TokenInfo *menu_info;
2216 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2217 int screen_pos, int menu_info_pos_raw,
2220 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2221 struct TokenInfo *ti = &token_info[pos];
2222 int xpos = MENU_SCREEN_START_XPOS;
2223 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2224 int font_nr = getMenuTextFont(ti->type);
2226 if (setup_mode == SETUP_MODE_INPUT)
2227 font_nr = FONT_MENU_1;
2230 font_nr = FONT_ACTIVE(font_nr);
2232 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2234 if (ti->type & ~TYPE_SKIP_ENTRY)
2235 drawCursor(screen_pos, active);
2238 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2241 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2244 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2247 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2250 static char *window_size_text;
2251 static char *scaling_type_text;
2253 static void drawSetupValue(int, int);
2255 static void drawMenuInfoList(int first_entry, int num_page_entries,
2256 int max_page_entries)
2260 if (first_entry + num_page_entries > max_page_entries)
2263 clearMenuListArea();
2265 for (i = 0; i < num_page_entries; i++)
2267 int menu_info_pos = first_entry + i;
2268 struct TokenInfo *si = &menu_info[menu_info_pos];
2269 void *value_ptr = si->value;
2271 /* set some entries to "unchangeable" according to other variables */
2272 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2273 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2274 (value_ptr == &setup.sound_music && !audio.music_available) ||
2275 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2276 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2277 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2278 si->type |= TYPE_GHOSTED;
2280 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2281 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2282 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2283 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2284 else if (si->type & ~TYPE_SKIP_ENTRY)
2285 initCursor(i, IMG_MENU_BUTTON);
2287 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2289 if (si->type & TYPE_VALUE &&
2290 menu_info == setup_info)
2291 drawSetupValue(i, menu_info_pos);
2295 static void DrawInfoScreen_Main()
2297 int fade_mask = REDRAW_FIELD;
2300 if (redraw_mask & REDRAW_ALL)
2301 fade_mask = REDRAW_ALL;
2303 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2304 fade_mask = REDRAW_ALL;
2307 FadeMenuSoundsAndMusic();
2309 FreeScreenGadgets();
2310 CreateScreenGadgets();
2312 /* (needed after displaying title screens which disable auto repeat) */
2313 KeyboardAutoRepeatOn();
2315 FadeSetLeaveScreen();
2319 /* needed if different viewport properties defined for info screen */
2320 ChangeViewportPropertiesIfNeeded();
2322 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2326 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2328 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2330 info_info = info_info_main;
2332 // determine maximal number of info entries that can be displayed on screen
2334 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2337 // determine maximal number of info entries available for menu of info screen
2339 for (i = 0; info_info[i].type != 0; i++)
2342 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2344 MapScreenGadgets(max_info_info);
2346 PlayMenuSoundsAndMusic();
2348 DrawMaskedBorder(fade_mask);
2353 static void changeSetupValue(int, int, int);
2355 void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2356 int mode, int num_page_entries, int max_page_entries)
2358 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2359 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2360 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2361 int *num_page_entries_last = num_page_entries_all_last[game_status];
2362 int *choice_store = choice_stores[game_status];
2363 int *first_entry_store = first_entry_stores[game_status];
2364 int choice = choice_store[mode]; /* starts with 0 */
2365 int first_entry = first_entry_store[mode]; /* starts with 0 */
2367 int y = choice - first_entry;
2369 boolean position_set_by_scrollbar = (dx == 999);
2370 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2373 if (button == MB_MENU_INITIALIZE)
2375 // check if number of menu page entries has changed (may happen by change
2376 // of custom artwork definition value for 'list_size' for this menu screen)
2377 // (in this case, the last menu position most probably has to be corrected)
2378 if (num_page_entries != num_page_entries_last[mode])
2380 choice_store[mode] = first_entry_store[mode] = 0;
2382 choice = first_entry = 0;
2385 num_page_entries_last[mode] = num_page_entries;
2388 /* advance to first valid menu entry */
2389 while (choice < num_page_entries &&
2390 menu_info[choice].type & TYPE_SKIP_ENTRY)
2393 if (position_set_by_scrollbar)
2394 first_entry = first_entry_store[mode] = dy;
2396 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2397 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2399 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2401 if (choice < first_entry)
2403 choice = first_entry;
2405 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2408 else if (choice > first_entry + num_page_entries - 1)
2410 choice = first_entry + num_page_entries - 1;
2412 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2416 choice_store[mode] = choice;
2418 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2422 else if (button == MB_MENU_LEAVE)
2424 PlaySound(SND_MENU_ITEM_SELECTING);
2426 for (i = 0; i < max_page_entries; i++)
2428 if (menu_info[i].type & TYPE_LEAVE_MENU)
2430 void (*menu_callback_function)(void) = menu_info[i].value;
2434 menu_callback_function();
2436 break; /* absolutely needed because function changes 'menu_info'! */
2443 if (mx || my) /* mouse input */
2445 x = (mx - mSX) / 32;
2446 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2448 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2450 /* move cursor instead of scrolling when already at start/end of list */
2451 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2453 else if (dy == +1 * SCROLL_LINE &&
2454 first_entry + num_page_entries == max_page_entries)
2457 /* handle scrolling screen one line or page */
2459 y + dy > num_page_entries - 1)
2461 boolean redraw = FALSE;
2463 if (ABS(dy) == SCROLL_PAGE)
2464 step = num_page_entries - 1;
2466 if (dy < 0 && first_entry > 0)
2468 /* scroll page/line up */
2470 first_entry -= step;
2471 if (first_entry < 0)
2476 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2478 /* scroll page/line down */
2480 first_entry += step;
2481 if (first_entry + num_page_entries > max_page_entries)
2482 first_entry = MAX(0, max_page_entries - num_page_entries);
2489 choice += first_entry - first_entry_store[mode];
2491 if (choice < first_entry)
2493 choice = first_entry;
2495 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2498 else if (choice > first_entry + num_page_entries - 1)
2500 choice = first_entry + num_page_entries - 1;
2502 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2505 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2509 if (choice < first_entry ||
2510 choice > first_entry + num_page_entries - 1)
2511 first_entry += SIGN(dy);
2514 first_entry_store[mode] = first_entry;
2515 choice_store[mode] = choice;
2517 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2519 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2521 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2522 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2530 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2532 if (menu_info[choice].type & menu_navigation_type ||
2533 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2534 menu_info[choice].type & TYPE_YES_NO_AUTO)
2535 button = MB_MENU_CHOICE;
2540 /* jump to next non-empty menu entry (up or down) */
2541 while (first_entry + y > 0 &&
2542 first_entry + y < max_page_entries - 1 &&
2543 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2546 if (!IN_VIS_MENU(x, y))
2548 choice += y - y_old;
2550 if (choice < first_entry)
2551 first_entry = choice;
2552 else if (choice > first_entry + num_page_entries - 1)
2553 first_entry = choice - num_page_entries + 1;
2555 if (first_entry >= 0 &&
2556 first_entry + num_page_entries <= max_page_entries)
2558 first_entry_store[mode] = first_entry;
2560 if (choice < first_entry)
2561 choice = first_entry;
2562 else if (choice > first_entry + num_page_entries - 1)
2563 choice = first_entry + num_page_entries - 1;
2565 choice_store[mode] = choice;
2567 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2569 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2571 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2572 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2579 if (!anyScrollbarGadgetActive() &&
2580 IN_VIS_MENU(x, y) &&
2581 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2582 y >= 0 && y < num_page_entries)
2586 if (first_entry + y != choice &&
2587 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2589 PlaySound(SND_MENU_ITEM_ACTIVATING);
2591 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2592 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2594 choice = choice_store[mode] = first_entry + y;
2598 PlaySound(SND_MENU_ITEM_SELECTING);
2600 for (i = 0; menu_info[i].type != 0; i++)
2602 if (menu_info[i].type & TYPE_LEAVE_MENU)
2604 void (*menu_callback_function)(void) = menu_info[i].value;
2608 menu_callback_function();
2610 /* absolutely needed because function changes 'menu_info'! */
2618 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2620 PlaySound(SND_MENU_ITEM_SELECTING);
2622 /* when selecting key headline, execute function for key value change */
2623 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2624 menu_info[first_entry + y + 1].type & TYPE_KEY)
2627 /* when selecting string value, execute function for list selection */
2628 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2629 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2632 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2634 void (*menu_callback_function)(void) =
2635 menu_info[first_entry + y].value;
2637 FadeSetFromType(menu_info[first_entry + y].type);
2639 menu_callback_function();
2641 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2642 menu_info == setup_info)
2644 changeSetupValue(y, first_entry + y, dx);
2650 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2652 menu_info = info_info;
2654 HandleMenuScreen(mx, my, dx, dy, button,
2655 info_mode, num_info_info, max_info_info);
2658 static int getMenuFontSpacing(int spacing_height, int font_nr)
2660 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2662 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2666 static int getMenuTextSpacing(int spacing_height, int font_nr)
2668 return (getMenuFontSpacing(spacing_height, font_nr) +
2669 EXTRA_SPACING(game_status));
2672 static int getMenuTextStep(int spacing_height, int font_nr)
2674 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2677 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2679 int font_title = MENU_INFO_FONT_TITLE;
2680 int font_error = FONT_TEXT_2;
2681 int font_foot = MENU_INFO_FONT_FOOT;
2682 int spacing_title = menu.headline1_spacing_info[info_mode];
2683 int ystep_title = getMenuTextStep(spacing_title, font_title);
2684 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2685 int ystart2 = ystart1 + ystep_title;
2686 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2688 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2690 FadeOut(REDRAW_FIELD);
2695 DrawTextSCentered(ystart1, font_title, text_title);
2696 DrawTextSCentered(ystart2, font_error, text_error);
2698 DrawTextSCentered(ybottom, font_foot,
2699 "Press any key or button for info menu");
2701 FadeIn(REDRAW_FIELD);
2704 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2706 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2707 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2708 int font_title = MENU_INFO_FONT_TITLE;
2709 int font_foot = MENU_INFO_FONT_FOOT;
2710 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2711 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2712 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2713 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2714 int ystep = MENU_SCREEN_INFO_YSTEP;
2715 int element, action, direction;
2723 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2724 infoscreen_step[i] = infoscreen_frame[i] = 0;
2729 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2731 DrawTextSCentered(ybottom, font_foot,
2732 "Press any key or button for next page");
2738 while (helpanim_info[j].element != HELPANIM_LIST_END)
2740 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2745 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2754 j += infoscreen_step[i - start];
2756 element = helpanim_info[j].element;
2757 action = helpanim_info[j].action;
2758 direction = helpanim_info[j].direction;
2761 element = EL_UNKNOWN;
2763 if (action != -1 && direction != -1)
2764 graphic = el_act_dir2img(element, action, direction);
2765 else if (action != -1)
2766 graphic = el_act2img(element, action);
2767 else if (direction != -1)
2768 graphic = el_dir2img(element, direction);
2770 graphic = el2img(element);
2772 delay = helpanim_info[j++].delay;
2777 if (infoscreen_frame[i - start] == 0)
2780 infoscreen_frame[i - start] = delay - 1;
2784 sync_frame = delay - infoscreen_frame[i - start];
2785 infoscreen_frame[i - start]--;
2788 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2790 if (!infoscreen_frame[i - start])
2791 infoscreen_step[i - start] = 0;
2795 if (!infoscreen_frame[i - start])
2796 infoscreen_step[i - start]++;
2797 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2803 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2805 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2806 graphic, sync_frame, USE_MASKING);
2809 DrawInfoScreen_HelpText(element, action, direction, i - start);
2814 redraw_mask |= REDRAW_FIELD;
2819 static char *getHelpText(int element, int action, int direction)
2821 char token[MAX_LINE_LEN];
2823 strcpy(token, element_info[element].token_name);
2826 strcat(token, element_action_info[action].suffix);
2828 if (direction != -1)
2829 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2831 return getHashEntry(helptext_info, token);
2834 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2836 int font_nr = FONT_INFO_ELEMENTS;
2837 int font_width = getFontWidth(font_nr);
2838 int font_height = getFontHeight(font_nr);
2839 int yoffset = (TILEX - 2 * font_height) / 2;
2840 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2841 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2842 int ystep = TILEY + 4;
2843 int pad_left = xstart - SX;
2844 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2845 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2846 int max_lines_per_text = 2;
2849 if (action != -1 && direction != -1) /* element.action.direction */
2850 text = getHelpText(element, action, direction);
2852 if (text == NULL && action != -1) /* element.action */
2853 text = getHelpText(element, action, -1);
2855 if (text == NULL && direction != -1) /* element.direction */
2856 text = getHelpText(element, -1, direction);
2858 if (text == NULL) /* base element */
2859 text = getHelpText(element, -1, -1);
2861 if (text == NULL) /* not found */
2862 text = "No description available";
2864 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2865 ystart += getFontHeight(font_nr) / 2;
2867 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2868 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2869 TRUE, FALSE, FALSE);
2872 void DrawInfoScreen_TitleScreen()
2874 SetGameStatus(GAME_MODE_TITLE);
2879 void HandleInfoScreen_TitleScreen(int button)
2881 HandleTitleScreen(0, 0, 0, 0, button);
2884 void DrawInfoScreen_Elements()
2886 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2888 FadeOut(REDRAW_FIELD);
2893 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2895 FadeIn(REDRAW_FIELD);
2898 void HandleInfoScreen_Elements(int button)
2900 static unsigned int info_delay = 0;
2901 static int num_anims;
2902 static int num_pages;
2904 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2907 if (button == MB_MENU_INITIALIZE)
2909 boolean new_element = TRUE;
2913 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2915 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2917 else if (new_element)
2920 new_element = FALSE;
2924 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2928 if (button == MB_MENU_LEAVE)
2930 PlaySound(SND_MENU_ITEM_SELECTING);
2932 info_mode = INFO_MODE_MAIN;
2937 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2939 if (button != MB_MENU_INITIALIZE)
2941 PlaySound(SND_MENU_ITEM_SELECTING);
2946 if (page >= num_pages)
2948 FadeMenuSoundsAndMusic();
2950 info_mode = INFO_MODE_MAIN;
2957 FadeSetNextScreen();
2959 if (button != MB_MENU_INITIALIZE)
2960 FadeOut(REDRAW_FIELD);
2962 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
2964 if (button != MB_MENU_INITIALIZE)
2965 FadeIn(REDRAW_FIELD);
2969 if (DelayReached(&info_delay, GameFrameDelay))
2970 if (page < num_pages)
2971 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
2973 PlayMenuSoundIfLoop();
2977 void DrawInfoScreen_Music()
2979 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
2981 FadeOut(REDRAW_FIELD);
2988 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
2990 FadeIn(REDRAW_FIELD);
2993 void HandleInfoScreen_Music(int button)
2995 static struct MusicFileInfo *list = NULL;
2996 int font_title = MENU_INFO_FONT_TITLE;
2997 int font_head = MENU_INFO_FONT_HEAD;
2998 int font_text = MENU_INFO_FONT_TEXT;
2999 int font_foot = MENU_INFO_FONT_FOOT;
3000 int spacing_title = menu.headline1_spacing_info[info_mode];
3001 int spacing_head = menu.headline2_spacing_info[info_mode];
3002 int ystep_title = getMenuTextStep(spacing_title, font_title);
3003 int ystep_head = getMenuTextStep(spacing_head, font_head);
3004 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3005 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3007 if (button == MB_MENU_INITIALIZE)
3009 list = music_file_info;
3013 FadeMenuSoundsAndMusic();
3018 DrawTextSCentered(ystart, font_title,
3019 "No music info for this level set.");
3021 DrawTextSCentered(ybottom, font_foot,
3022 "Press any key or button for info menu");
3028 if (button == MB_MENU_LEAVE)
3030 PlaySound(SND_MENU_ITEM_SELECTING);
3032 FadeMenuSoundsAndMusic();
3034 info_mode = INFO_MODE_MAIN;
3039 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3041 if (button != MB_MENU_INITIALIZE)
3043 PlaySound(SND_MENU_ITEM_SELECTING);
3051 FadeMenuSoundsAndMusic();
3053 info_mode = INFO_MODE_MAIN;
3059 FadeMenuSoundsAndMusic();
3061 if (list != music_file_info)
3062 FadeSetNextScreen();
3064 if (button != MB_MENU_INITIALIZE)
3065 FadeOut(REDRAW_FIELD);
3072 int sound = list->music;
3074 if (sound_info[sound].loop)
3075 PlaySoundLoop(sound);
3079 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3083 PlayMusic(list->music);
3085 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3088 ystart += ystep_title;
3090 if (!strEqual(list->title, UNKNOWN_NAME))
3092 if (!strEqual(list->title_header, UNKNOWN_NAME))
3094 DrawTextSCentered(ystart, font_head, list->title_header);
3095 ystart += ystep_head;
3098 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3099 ystart += ystep_head;
3102 if (!strEqual(list->artist, UNKNOWN_NAME))
3104 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3105 DrawTextSCentered(ystart, font_head, list->artist_header);
3107 DrawTextSCentered(ystart, font_head, "by");
3109 ystart += ystep_head;
3111 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3112 ystart += ystep_head;
3115 if (!strEqual(list->album, UNKNOWN_NAME))
3117 if (!strEqual(list->album_header, UNKNOWN_NAME))
3118 DrawTextSCentered(ystart, font_head, list->album_header);
3120 DrawTextSCentered(ystart, font_head, "from the album");
3122 ystart += ystep_head;
3124 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3125 ystart += ystep_head;
3128 if (!strEqual(list->year, UNKNOWN_NAME))
3130 if (!strEqual(list->year_header, UNKNOWN_NAME))
3131 DrawTextSCentered(ystart, font_head, list->year_header);
3133 DrawTextSCentered(ystart, font_head, "from the year");
3135 ystart += ystep_head;
3137 DrawTextFCentered(ystart, font_text, "%s", list->year);
3138 ystart += ystep_head;
3141 DrawTextSCentered(ybottom, FONT_TEXT_4,
3142 "Press any key or button for next page");
3144 if (button != MB_MENU_INITIALIZE)
3145 FadeIn(REDRAW_FIELD);
3148 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3149 PlaySoundLoop(list->music);
3152 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3154 int font_title = MENU_INFO_FONT_TITLE;
3155 int font_head = MENU_INFO_FONT_HEAD;
3156 int font_text = MENU_INFO_FONT_TEXT;
3157 int font_foot = MENU_INFO_FONT_FOOT;
3158 int spacing_title = menu.headline1_spacing_info[info_mode];
3159 int spacing_head = menu.headline2_spacing_info[info_mode];
3160 int spacing_para = menu.paragraph_spacing_info[info_mode];
3161 int spacing_line = menu.line_spacing_info[info_mode];
3162 int ystep_title = getMenuTextStep(spacing_title, font_title);
3163 int ystep_head = getMenuTextStep(spacing_head, font_head);
3164 int ystep_para = getMenuTextStep(spacing_para, font_text);
3165 int ystep_line = getMenuTextStep(spacing_line, font_text);
3166 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3167 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3172 DrawTextSCentered(ystart, font_title, "Credits:");
3173 ystart += ystep_title;
3177 DrawTextSCentered(ystart, font_head,
3178 "Special thanks to");
3179 ystart += ystep_head;
3180 DrawTextSCentered(ystart, font_text,
3182 ystart += ystep_head;
3183 DrawTextSCentered(ystart, font_head,
3185 ystart += ystep_head;
3186 DrawTextSCentered(ystart, font_text,
3187 "\"Boulder Dash\"");
3188 ystart += ystep_head;
3189 DrawTextSCentered(ystart, font_head,
3191 ystart += ystep_head;
3192 DrawTextSCentered(ystart, font_text,
3194 ystart += ystep_head;
3195 DrawTextSCentered(ystart, font_head,
3197 ystart += ystep_head;
3198 DrawTextSCentered(ystart, font_text,
3199 "First Star Software");
3201 else if (screen_nr == 1)
3203 DrawTextSCentered(ystart, font_head,
3204 "Special thanks to");
3205 ystart += ystep_head;
3206 DrawTextSCentered(ystart, font_text,
3207 "Klaus Heinz & Volker Wertich");
3208 ystart += ystep_head;
3209 DrawTextSCentered(ystart, font_head,
3211 ystart += ystep_head;
3212 DrawTextSCentered(ystart, font_text,
3213 "\"Emerald Mine\"");
3214 ystart += ystep_head;
3215 DrawTextSCentered(ystart, font_head,
3217 ystart += ystep_head;
3218 DrawTextSCentered(ystart, font_text,
3220 ystart += ystep_head;
3221 DrawTextSCentered(ystart, font_head,
3223 ystart += ystep_head;
3224 DrawTextSCentered(ystart, font_text,
3227 else if (screen_nr == 2)
3229 DrawTextSCentered(ystart, font_head,
3230 "Special thanks to");
3231 ystart += ystep_head;
3232 DrawTextSCentered(ystart, font_text,
3233 "Michael Stopp & Philip Jespersen");
3234 ystart += ystep_head;
3235 DrawTextSCentered(ystart, font_head,
3237 ystart += ystep_head;
3238 DrawTextSCentered(ystart, font_text,
3240 ystart += ystep_head;
3241 DrawTextSCentered(ystart, font_head,
3243 ystart += ystep_head;
3244 DrawTextSCentered(ystart, font_text,
3246 ystart += ystep_head;
3247 DrawTextSCentered(ystart, font_head,
3249 ystart += ystep_head;
3250 DrawTextSCentered(ystart, font_text,
3251 "Digital Integration");
3253 else if (screen_nr == 3)
3255 DrawTextSCentered(ystart, font_head,
3256 "Special thanks to");
3257 ystart += ystep_head;
3258 DrawTextSCentered(ystart, font_text,
3259 "Hiroyuki Imabayashi");
3260 ystart += ystep_head;
3261 DrawTextSCentered(ystart, font_head,
3263 ystart += ystep_head;
3264 DrawTextSCentered(ystart, font_text,
3266 ystart += ystep_head;
3267 DrawTextSCentered(ystart, font_head,
3269 ystart += ystep_head;
3270 DrawTextSCentered(ystart, font_text,
3272 ystart += ystep_head;
3273 DrawTextSCentered(ystart, font_head,
3275 ystart += ystep_head;
3276 DrawTextSCentered(ystart, font_text,
3279 else if (screen_nr == 4)
3281 DrawTextSCentered(ystart, font_head,
3282 "Special thanks to");
3283 ystart += ystep_head;
3284 DrawTextSCentered(ystart, font_text,
3286 ystart += ystep_head;
3287 DrawTextSCentered(ystart, font_head,
3289 ystart += ystep_head;
3290 DrawTextSCentered(ystart, font_text,
3291 "J\xfcrgen Bonhagen");
3292 ystart += ystep_head;
3293 DrawTextSCentered(ystart, font_head,
3294 "for the continuous creation");
3295 ystart += ystep_line;
3296 DrawTextSCentered(ystart, font_head,
3297 "of outstanding level sets");
3299 else if (screen_nr == 5)
3301 DrawTextSCentered(ystart, font_head,
3303 ystart += ystep_head;
3304 DrawTextSCentered(ystart, font_text,
3306 ystart += ystep_head;
3307 DrawTextSCentered(ystart, font_head,
3308 "for ideas and inspiration by");
3309 ystart += ystep_head;
3310 DrawTextSCentered(ystart, font_text,
3312 ystart += ystep_para;
3314 DrawTextSCentered(ystart, font_head,
3316 ystart += ystep_head;
3317 DrawTextSCentered(ystart, font_text,
3319 ystart += ystep_head;
3320 DrawTextSCentered(ystart, font_head,
3321 "for ideas and inspiration by");
3322 ystart += ystep_head;
3323 DrawTextSCentered(ystart, font_text,
3326 else if (screen_nr == 6)
3328 DrawTextSCentered(ystart, font_head,
3330 ystart += ystep_head;
3331 DrawTextSCentered(ystart, font_text,
3333 ystart += ystep_head;
3334 DrawTextSCentered(ystart, font_head,
3335 "for the code base used for the");
3336 ystart += ystep_line;
3337 DrawTextSCentered(ystart, font_head,
3338 "native Emerald Mine engine");
3340 else if (screen_nr == 7)
3342 DrawTextSCentered(ystart, font_head,
3344 ystart += ystep_head;
3345 DrawTextSCentered(ystart, font_text,
3347 ystart += ystep_head;
3348 DrawTextSCentered(ystart, font_head,
3349 "for the initial DOS port");
3350 ystart += ystep_para;
3352 DrawTextSCentered(ystart, font_head,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_text,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_head,
3359 "for some additional toons");
3361 else if (screen_nr == 8)
3363 DrawTextSCentered(ystart, font_head,
3364 "And not to forget:");
3365 ystart += ystep_head;
3366 DrawTextSCentered(ystart, font_head,
3368 ystart += ystep_head;
3369 DrawTextSCentered(ystart, font_text,
3370 "All those who contributed");
3371 ystart += ystep_line;
3372 DrawTextSCentered(ystart, font_text,
3373 "levels to this game");
3374 ystart += ystep_line;
3375 DrawTextSCentered(ystart, font_text,
3379 DrawTextSCentered(ybottom, font_foot,
3380 "Press any key or button for next page");
3383 void DrawInfoScreen_Credits()
3385 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3387 FadeMenuSoundsAndMusic();
3389 FadeOut(REDRAW_FIELD);
3391 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3393 FadeIn(REDRAW_FIELD);
3396 void HandleInfoScreen_Credits(int button)
3398 static int screen_nr = 0;
3399 int num_screens = 9;
3401 if (button == MB_MENU_INITIALIZE)
3405 // DrawInfoScreen_CreditsScreen(screen_nr);
3408 if (button == MB_MENU_LEAVE)
3410 PlaySound(SND_MENU_ITEM_SELECTING);
3412 info_mode = INFO_MODE_MAIN;
3417 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3419 if (button != MB_MENU_INITIALIZE)
3421 PlaySound(SND_MENU_ITEM_SELECTING);
3426 if (screen_nr >= num_screens)
3428 FadeMenuSoundsAndMusic();
3430 info_mode = INFO_MODE_MAIN;
3437 FadeSetNextScreen();
3439 if (button != MB_MENU_INITIALIZE)
3440 FadeOut(REDRAW_FIELD);
3442 DrawInfoScreen_CreditsScreen(screen_nr);
3444 if (button != MB_MENU_INITIALIZE)
3445 FadeIn(REDRAW_FIELD);
3449 PlayMenuSoundIfLoop();
3453 void DrawInfoScreen_Program()
3455 int font_title = MENU_INFO_FONT_TITLE;
3456 int font_head = MENU_INFO_FONT_HEAD;
3457 int font_text = MENU_INFO_FONT_TEXT;
3458 int font_foot = MENU_INFO_FONT_FOOT;
3459 int spacing_title = menu.headline1_spacing_info[info_mode];
3460 int spacing_head = menu.headline2_spacing_info[info_mode];
3461 int spacing_para = menu.paragraph_spacing_info[info_mode];
3462 int spacing_line = menu.line_spacing_info[info_mode];
3463 int ystep_title = getMenuTextStep(spacing_title, font_title);
3464 int ystep_head = getMenuTextStep(spacing_head, font_head);
3465 int ystep_para = getMenuTextStep(spacing_para, font_text);
3466 int ystep_line = getMenuTextStep(spacing_line, font_text);
3467 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3468 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3470 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3472 FadeOut(REDRAW_FIELD);
3477 DrawTextSCentered(ystart, font_title, "Program Information:");
3478 ystart += ystep_title;
3480 DrawTextSCentered(ystart, font_head,
3481 "This game is Freeware!");
3482 ystart += ystep_head;
3483 DrawTextSCentered(ystart, font_head,
3484 "If you like it, send e-mail to:");
3485 ystart += ystep_head;
3486 DrawTextSCentered(ystart, font_text,
3487 setup.internal.program_email);
3488 ystart += ystep_para;
3490 DrawTextSCentered(ystart, font_head,
3491 "More information and levels:");
3492 ystart += ystep_head;
3493 DrawTextSCentered(ystart, font_text,
3494 setup.internal.program_website);
3495 ystart += ystep_para;
3497 DrawTextSCentered(ystart, font_head,
3498 "If you have created new levels,");
3499 ystart += ystep_line;
3500 DrawTextSCentered(ystart, font_head,
3501 "send them to me to include them!");
3502 ystart += ystep_head;
3503 DrawTextSCentered(ystart, font_head,
3506 DrawTextSCentered(ybottom, font_foot,
3507 "Press any key or button for info menu");
3509 FadeIn(REDRAW_FIELD);
3512 void HandleInfoScreen_Program(int button)
3514 if (button == MB_MENU_LEAVE)
3516 PlaySound(SND_MENU_ITEM_SELECTING);
3518 info_mode = INFO_MODE_MAIN;
3523 else if (button == MB_MENU_CHOICE)
3525 PlaySound(SND_MENU_ITEM_SELECTING);
3527 FadeMenuSoundsAndMusic();
3529 info_mode = INFO_MODE_MAIN;
3534 PlayMenuSoundIfLoop();
3538 void DrawInfoScreen_Version()
3540 int font_title = MENU_INFO_FONT_TITLE;
3541 int font_head = MENU_INFO_FONT_HEAD;
3542 int font_text = MENU_INFO_FONT_TEXT;
3543 int font_foot = MENU_INFO_FONT_FOOT;
3544 int spacing_title = menu.headline1_spacing_info[info_mode];
3545 int spacing_head = menu.headline2_spacing_info[info_mode];
3546 int spacing_para = menu.paragraph_spacing_info[info_mode];
3547 int spacing_line = menu.line_spacing_info[info_mode];
3548 int xstep = getFontWidth(font_text);
3549 int ystep_title = getMenuTextStep(spacing_title, font_title);
3550 int ystep_head = getMenuTextStep(spacing_head, font_head);
3551 int ystep_para = getMenuTextStep(spacing_para, font_text);
3552 int ystep_line = getMenuTextStep(spacing_line, font_text);
3553 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3554 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3555 int xstart1 = mSX - SX + 2 * xstep;
3556 int xstart2 = mSX - SX + 18 * xstep;
3557 int xstart3 = mSX - SX + 28 * xstep;
3558 SDL_version sdl_version_compiled;
3559 const SDL_version *sdl_version_linked;
3560 int driver_name_len = 10;
3561 #if defined(TARGET_SDL2)
3562 SDL_version sdl_version_linked_ext;
3563 const char *driver_name = NULL;
3565 char driver_name[driver_name_len];
3568 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3570 FadeOut(REDRAW_FIELD);
3575 DrawTextSCentered(ystart, font_title, "Version Information:");
3576 ystart += ystep_title;
3578 DrawTextF(xstart1, ystart, font_head, "Name");
3579 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3580 ystart += ystep_line;
3582 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3584 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3585 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3586 ystart += ystep_line;
3588 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3589 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3590 ystart += ystep_line;
3594 DrawTextF(xstart1, ystart, font_head, "Version");
3595 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3596 ystart += ystep_line;
3599 DrawTextF(xstart1, ystart, font_head, "Platform");
3600 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3601 ystart += ystep_line;
3603 DrawTextF(xstart1, ystart, font_head, "Target");
3604 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3605 ystart += ystep_line;
3607 DrawTextF(xstart1, ystart, font_head, "Source date");
3608 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3609 ystart += ystep_para;
3611 DrawTextF(xstart1, ystart, font_head, "Library");
3612 DrawTextF(xstart2, ystart, font_head, "compiled");
3613 DrawTextF(xstart3, ystart, font_head, "linked");
3614 ystart += ystep_head;
3616 SDL_VERSION(&sdl_version_compiled);
3617 #if defined(TARGET_SDL2)
3618 SDL_GetVersion(&sdl_version_linked_ext);
3619 sdl_version_linked = &sdl_version_linked_ext;
3621 sdl_version_linked = SDL_Linked_Version();
3624 DrawTextF(xstart1, ystart, font_text, "SDL");
3625 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3626 sdl_version_compiled.major,
3627 sdl_version_compiled.minor,
3628 sdl_version_compiled.patch);
3629 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3630 sdl_version_linked->major,
3631 sdl_version_linked->minor,
3632 sdl_version_linked->patch);
3633 ystart += ystep_line;
3635 SDL_IMAGE_VERSION(&sdl_version_compiled);
3636 sdl_version_linked = IMG_Linked_Version();
3638 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3639 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3640 sdl_version_compiled.major,
3641 sdl_version_compiled.minor,
3642 sdl_version_compiled.patch);
3643 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3644 sdl_version_linked->major,
3645 sdl_version_linked->minor,
3646 sdl_version_linked->patch);
3647 ystart += ystep_line;
3649 SDL_MIXER_VERSION(&sdl_version_compiled);
3650 sdl_version_linked = Mix_Linked_Version();
3652 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3653 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3654 sdl_version_compiled.major,
3655 sdl_version_compiled.minor,
3656 sdl_version_compiled.patch);
3657 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3658 sdl_version_linked->major,
3659 sdl_version_linked->minor,
3660 sdl_version_linked->patch);
3661 ystart += ystep_line;
3663 SDL_NET_VERSION(&sdl_version_compiled);
3664 sdl_version_linked = SDLNet_Linked_Version();
3666 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3667 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3668 sdl_version_compiled.major,
3669 sdl_version_compiled.minor,
3670 sdl_version_compiled.patch);
3671 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3672 sdl_version_linked->major,
3673 sdl_version_linked->minor,
3674 sdl_version_linked->patch);
3675 ystart += ystep_para;
3677 DrawTextF(xstart1, ystart, font_head, "Driver");
3678 DrawTextF(xstart2, ystart, font_head, "Requested");
3679 DrawTextF(xstart3, ystart, font_head, "Used");
3680 ystart += ystep_head;
3682 #if defined(TARGET_SDL2)
3683 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3685 SDL_VideoDriverName(driver_name, driver_name_len);
3688 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3689 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3690 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3691 ystart += ystep_line;
3693 #if defined(TARGET_SDL2)
3694 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3696 SDL_AudioDriverName(driver_name, driver_name_len);
3699 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3700 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3701 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3703 DrawTextSCentered(ybottom, font_foot,
3704 "Press any key or button for info menu");
3706 FadeIn(REDRAW_FIELD);
3709 void HandleInfoScreen_Version(int button)
3711 if (button == MB_MENU_LEAVE)
3713 PlaySound(SND_MENU_ITEM_SELECTING);
3715 info_mode = INFO_MODE_MAIN;
3720 else if (button == MB_MENU_CHOICE)
3722 PlaySound(SND_MENU_ITEM_SELECTING);
3724 FadeMenuSoundsAndMusic();
3726 info_mode = INFO_MODE_MAIN;
3731 PlayMenuSoundIfLoop();
3735 void DrawInfoScreen_LevelSet()
3737 struct TitleMessageInfo *tmi = &readme;
3738 char *filename = getLevelSetInfoFilename();
3739 char *title = "Level Set Information:";
3740 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3741 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3743 if (filename == NULL)
3745 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3750 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3752 FadeOut(REDRAW_FIELD);
3757 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3759 /* if x position set to "-1", automatically determine by playfield width */
3761 tmi->x = SXSIZE / 2;
3763 /* if y position set to "-1", use static default value */
3767 /* if width set to "-1", automatically determine by playfield width */
3768 if (tmi->width == -1)
3769 tmi->width = SXSIZE - 2 * TILEX;
3771 /* if height set to "-1", automatically determine by playfield height */
3772 if (tmi->height == -1)
3773 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3775 /* if chars set to "-1", automatically determine by text and font width */
3776 if (tmi->chars == -1)
3777 tmi->chars = tmi->width / getFontWidth(tmi->font);
3779 tmi->width = tmi->chars * getFontWidth(tmi->font);
3781 /* if lines set to "-1", automatically determine by text and font height */
3782 if (tmi->lines == -1)
3783 tmi->lines = tmi->height / getFontHeight(tmi->font);
3785 tmi->height = tmi->lines * getFontHeight(tmi->font);
3787 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3788 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3789 tmi->autowrap, tmi->centered, tmi->parse_comments);
3791 DrawTextSCentered(ybottom, FONT_TEXT_4,
3792 "Press any key or button for info menu");
3794 FadeIn(REDRAW_FIELD);
3797 void HandleInfoScreen_LevelSet(int button)
3799 if (button == MB_MENU_LEAVE)
3801 PlaySound(SND_MENU_ITEM_SELECTING);
3803 info_mode = INFO_MODE_MAIN;
3808 else if (button == MB_MENU_CHOICE)
3810 PlaySound(SND_MENU_ITEM_SELECTING);
3812 FadeMenuSoundsAndMusic();
3814 info_mode = INFO_MODE_MAIN;
3819 PlayMenuSoundIfLoop();
3823 static void DrawInfoScreen()
3825 if (info_mode == INFO_MODE_TITLE)
3826 DrawInfoScreen_TitleScreen();
3827 else if (info_mode == INFO_MODE_ELEMENTS)
3828 DrawInfoScreen_Elements();
3829 else if (info_mode == INFO_MODE_MUSIC)
3830 DrawInfoScreen_Music();
3831 else if (info_mode == INFO_MODE_CREDITS)
3832 DrawInfoScreen_Credits();
3833 else if (info_mode == INFO_MODE_PROGRAM)
3834 DrawInfoScreen_Program();
3835 else if (info_mode == INFO_MODE_VERSION)
3836 DrawInfoScreen_Version();
3837 else if (info_mode == INFO_MODE_LEVELSET)
3838 DrawInfoScreen_LevelSet();
3840 DrawInfoScreen_Main();
3842 if (info_mode != INFO_MODE_MAIN &&
3843 info_mode != INFO_MODE_TITLE &&
3844 info_mode != INFO_MODE_MUSIC)
3845 PlayMenuSoundsAndMusic();
3848 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3850 if (info_mode == INFO_MODE_TITLE)
3851 HandleInfoScreen_TitleScreen(button);
3852 else if (info_mode == INFO_MODE_ELEMENTS)
3853 HandleInfoScreen_Elements(button);
3854 else if (info_mode == INFO_MODE_MUSIC)
3855 HandleInfoScreen_Music(button);
3856 else if (info_mode == INFO_MODE_CREDITS)
3857 HandleInfoScreen_Credits(button);
3858 else if (info_mode == INFO_MODE_PROGRAM)
3859 HandleInfoScreen_Program(button);
3860 else if (info_mode == INFO_MODE_VERSION)
3861 HandleInfoScreen_Version(button);
3862 else if (info_mode == INFO_MODE_LEVELSET)
3863 HandleInfoScreen_LevelSet(button);
3865 HandleInfoScreen_Main(mx, my, dx, dy, button);
3869 /* ========================================================================= */
3870 /* type name functions */
3871 /* ========================================================================= */
3873 void HandleTypeName(int newxpos, Key key)
3875 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3876 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3877 struct TextPosInfo *pos = mci->pos_input;
3878 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3879 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3880 static int xpos = 0;
3881 int font_nr = pos->font;
3882 int font_active_nr = FONT_ACTIVE(font_nr);
3883 int font_width = getFontWidth(font_active_nr);
3884 char key_char = getValidConfigValueChar(getCharFromKey(key));
3885 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3886 boolean is_active = TRUE;
3888 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3892 strcpy(last_player_name, setup.player_name);
3896 StartTextInput(startx, starty, pos->width, pos->height);
3898 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3900 setup.player_name[xpos] = key_char;
3901 setup.player_name[xpos + 1] = 0;
3905 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3909 setup.player_name[xpos] = 0;
3911 else if (key == KSYM_Return && xpos > 0)
3917 SetGameStatus(GAME_MODE_MAIN);
3919 else if (key == KSYM_Escape)
3921 strcpy(setup.player_name, last_player_name);
3925 SetGameStatus(GAME_MODE_MAIN);
3930 pos->width = (strlen(setup.player_name) + 1) * font_width;
3931 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3933 DrawText(startx, starty, setup.player_name, font_active_nr);
3934 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3938 pos->width = strlen(setup.player_name) * font_width;
3939 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3941 DrawText(startx, starty, setup.player_name, font_nr);
3948 /* ========================================================================= */
3949 /* tree menu functions */
3950 /* ========================================================================= */
3952 static void DrawChooseTree(TreeInfo **ti_ptr)
3954 int fade_mask = REDRAW_FIELD;
3956 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3957 fade_mask = REDRAW_ALL;
3959 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
3961 SetGameStatus(GAME_MODE_MAIN);
3970 FreeScreenGadgets();
3971 CreateScreenGadgets();
3975 /* needed if different viewport properties defined for choosing level (set) */
3976 ChangeViewportPropertiesIfNeeded();
3978 if (game_status == GAME_MODE_LEVELNR)
3979 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
3980 else if (game_status == GAME_MODE_LEVELS)
3981 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
3985 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
3987 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
3988 MapScreenTreeGadgets(*ti_ptr);
3990 DrawMaskedBorder(fade_mask);
3995 static void drawChooseTreeList(int first_entry, int num_page_entries,
3999 char *title_string = NULL;
4000 int yoffset_sets = MENU_TITLE1_YPOS;
4001 int yoffset_setup = 16;
4002 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4003 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4005 title_string = ti->infotext;
4007 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4009 clearMenuListArea();
4011 for (i = 0; i < num_page_entries; i++)
4013 TreeInfo *node, *node_first;
4014 int entry_pos = first_entry + i;
4015 int xpos = MENU_SCREEN_START_XPOS;
4016 int ypos = MENU_SCREEN_START_YPOS + i;
4017 int startx = mSX + xpos * 32;
4018 int starty = mSY + ypos * 32;
4019 int font_nr = FONT_TEXT_1;
4020 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4021 int startx_text = startx + font_xoffset;
4022 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4023 int text_size = startx_scrollbar - startx_text;
4024 int max_buffer_len = text_size / getFontWidth(font_nr);
4025 char buffer[max_buffer_len + 1];
4027 node_first = getTreeInfoFirstGroupEntry(ti);
4028 node = getTreeInfoFromPos(node_first, entry_pos);
4030 strncpy(buffer, node->name, max_buffer_len);
4031 buffer[max_buffer_len] = '\0';
4033 DrawText(startx, starty, buffer, font_nr + node->color);
4035 if (node->parent_link)
4036 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4037 else if (node->level_group)
4038 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4040 initCursor(i, IMG_MENU_BUTTON);
4043 redraw_mask |= REDRAW_FIELD;
4046 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4048 TreeInfo *node, *node_first;
4049 int x, last_redraw_mask = redraw_mask;
4050 int ypos = MENU_TITLE2_YPOS;
4051 int font_nr = FONT_TITLE_2;
4053 if (ti->type == TREE_TYPE_LEVEL_NR)
4054 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4056 if (ti->type != TREE_TYPE_LEVEL_DIR)
4059 node_first = getTreeInfoFirstGroupEntry(ti);
4060 node = getTreeInfoFromPos(node_first, entry_pos);
4062 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4064 if (node->parent_link)
4065 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4066 node->node_parent->name);
4067 else if (node->level_group)
4068 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4070 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4071 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4072 node->levels, (node->levels > 1 ? "levels" : "level"),
4075 /* let BackToFront() redraw only what is needed */
4076 redraw_mask = last_redraw_mask;
4077 for (x = 0; x < SCR_FIELDX; x++)
4078 MarkTileDirty(x, 1);
4081 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4084 TreeInfo *ti = *ti_ptr;
4086 int y = ti->cl_cursor;
4087 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4088 int num_entries = numTreeInfoInGroup(ti);
4089 int num_page_entries;
4090 boolean position_set_by_scrollbar = (dx == 999);
4092 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4093 num_page_entries = num_entries;
4095 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4097 if (button == MB_MENU_INITIALIZE)
4099 int num_entries = numTreeInfoInGroup(ti);
4100 int entry_pos = posTreeInfo(ti);
4102 if (ti->cl_first == -1)
4104 /* only on initialization */
4105 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4106 ti->cl_cursor = entry_pos - ti->cl_first;
4108 else if (ti->cl_cursor >= num_page_entries ||
4109 (num_entries > num_page_entries &&
4110 num_entries - ti->cl_first < num_page_entries))
4112 /* only after change of list size (by custom graphic configuration) */
4113 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4114 ti->cl_cursor = entry_pos - ti->cl_first;
4117 if (position_set_by_scrollbar)
4120 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4123 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4124 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4125 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4129 else if (button == MB_MENU_LEAVE)
4133 PlaySound(SND_MENU_ITEM_SELECTING);
4135 if (ti->node_parent)
4137 *ti_ptr = ti->node_parent;
4138 DrawChooseTree(ti_ptr);
4140 else if (game_status == GAME_MODE_SETUP)
4142 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4143 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4144 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4146 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4147 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4148 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4149 execSetupGraphics();
4150 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4151 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4152 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4154 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4155 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4156 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4157 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4158 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4159 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4160 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4161 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4168 if (game_status == GAME_MODE_LEVELNR)
4170 int new_level_nr = atoi(level_number_current->identifier);
4172 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4175 SetGameStatus(GAME_MODE_MAIN);
4183 if (mx || my) /* mouse input */
4185 x = (mx - mSX) / 32;
4186 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4188 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4190 /* move cursor instead of scrolling when already at start/end of list */
4191 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4193 else if (dy == +1 * SCROLL_LINE &&
4194 ti->cl_first + num_page_entries == num_entries)
4197 /* handle scrolling screen one line or page */
4198 if (ti->cl_cursor + dy < 0 ||
4199 ti->cl_cursor + dy > num_page_entries - 1)
4201 boolean redraw = FALSE;
4203 if (ABS(dy) == SCROLL_PAGE)
4204 step = num_page_entries - 1;
4206 if (dy < 0 && ti->cl_first > 0)
4208 /* scroll page/line up */
4210 ti->cl_first -= step;
4211 if (ti->cl_first < 0)
4216 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4218 /* scroll page/line down */
4220 ti->cl_first += step;
4221 if (ti->cl_first + num_page_entries > num_entries)
4222 ti->cl_first = MAX(0, num_entries - num_page_entries);
4229 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4230 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4231 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4233 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4240 /* handle moving cursor one line */
4241 y = ti->cl_cursor + dy;
4246 TreeInfo *node_first, *node_cursor;
4247 int entry_pos = ti->cl_first + y;
4249 node_first = getTreeInfoFirstGroupEntry(ti);
4250 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4252 if (node_cursor->node_group)
4256 PlaySound(SND_MENU_ITEM_SELECTING);
4258 node_cursor->cl_first = ti->cl_first;
4259 node_cursor->cl_cursor = ti->cl_cursor;
4260 *ti_ptr = node_cursor->node_group;
4261 DrawChooseTree(ti_ptr);
4266 else if (dx == -1 && ti->node_parent)
4270 PlaySound(SND_MENU_ITEM_SELECTING);
4272 *ti_ptr = ti->node_parent;
4273 DrawChooseTree(ti_ptr);
4278 if (!anyScrollbarGadgetActive() &&
4279 IN_VIS_MENU(x, y) &&
4280 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4281 y >= 0 && y < num_page_entries)
4285 if (y != ti->cl_cursor)
4287 PlaySound(SND_MENU_ITEM_ACTIVATING);
4289 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4290 drawChooseTreeCursor(y, TRUE);
4291 drawChooseTreeInfo(ti->cl_first + y, ti);
4297 if (game_status == GAME_MODE_SETUP)
4299 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4300 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4301 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4303 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4304 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4305 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4306 execSetupGraphics();
4307 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4308 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4309 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4311 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4312 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4313 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4314 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4315 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4316 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4317 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4318 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4327 TreeInfo *node_first, *node_cursor;
4328 int entry_pos = ti->cl_first + y;
4330 PlaySound(SND_MENU_ITEM_SELECTING);
4332 node_first = getTreeInfoFirstGroupEntry(ti);
4333 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4335 if (node_cursor->node_group)
4339 node_cursor->cl_first = ti->cl_first;
4340 node_cursor->cl_cursor = ti->cl_cursor;
4341 *ti_ptr = node_cursor->node_group;
4342 DrawChooseTree(ti_ptr);
4344 else if (node_cursor->parent_link)
4348 *ti_ptr = node_cursor->node_parent;
4349 DrawChooseTree(ti_ptr);
4355 node_cursor->cl_first = ti->cl_first;
4356 node_cursor->cl_cursor = ti->cl_cursor;
4357 *ti_ptr = node_cursor;
4359 if (ti->type == TREE_TYPE_LEVEL_DIR)
4361 LoadLevelSetup_SeriesInfo();
4363 SaveLevelSetup_LastSeries();
4364 SaveLevelSetup_SeriesInfo();
4368 if (game_status == GAME_MODE_SETUP)
4370 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4371 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4372 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4374 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4375 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4376 setup_mode == SETUP_MODE_CHOOSE_RENDERING)
4377 execSetupGraphics();
4378 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4379 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4380 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4382 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4383 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4384 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4385 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4386 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4387 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4388 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4389 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4396 if (game_status == GAME_MODE_LEVELNR)
4398 int new_level_nr = atoi(level_number_current->identifier);
4400 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4403 SetGameStatus(GAME_MODE_MAIN);
4412 void DrawChooseLevelSet()
4414 FadeMenuSoundsAndMusic();
4416 DrawChooseTree(&leveldir_current);
4418 PlayMenuSoundsAndMusic();
4421 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4423 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4426 void DrawChooseLevelNr()
4430 FadeMenuSoundsAndMusic();
4432 if (level_number != NULL)
4434 freeTreeInfo(level_number);
4436 level_number = NULL;
4439 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4441 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4442 char identifier[32], name[32];
4445 /* temporarily load level info to get level name */
4446 LoadLevelInfoOnly(i);
4448 ti->node_top = &level_number;
4449 ti->sort_priority = 10000 + value;
4450 ti->color = (level.no_level_file ? FC_BLUE :
4451 LevelStats_getSolved(i) ? FC_GREEN :
4452 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4454 snprintf(identifier, sizeof(identifier), "%d", value);
4455 snprintf(name, sizeof(name), "%03d: %s", value,
4456 (level.no_level_file ? "(no file)" : level.name));
4458 setString(&ti->identifier, identifier);
4459 setString(&ti->name, name);
4460 setString(&ti->name_sorting, name);
4462 pushTreeInfo(&level_number, ti);
4465 /* sort level number values to start with lowest level number */
4466 sortTreeInfo(&level_number);
4468 /* set current level number to current level number */
4469 level_number_current =
4470 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4472 /* if that also fails, set current level number to first available level */
4473 if (level_number_current == NULL)
4474 level_number_current = level_number;
4476 DrawChooseTree(&level_number_current);
4478 PlayMenuSoundsAndMusic();
4481 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4483 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4486 void DrawHallOfFame(int highlight_position)
4488 int fade_mask = REDRAW_FIELD;
4490 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4491 fade_mask = REDRAW_ALL;
4494 FadeMenuSoundsAndMusic();
4496 /* (this is needed when called from GameEnd() after winning a game) */
4497 KeyboardAutoRepeatOn();
4499 /* (this is needed when called from GameEnd() after winning a game) */
4500 SetDrawDeactivationMask(REDRAW_NONE);
4501 SetDrawBackgroundMask(REDRAW_FIELD);
4503 if (highlight_position < 0)
4504 LoadScore(level_nr);
4506 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4508 FadeSetEnterScreen();
4512 /* needed if different viewport properties defined for scores */
4513 ChangeViewportPropertiesIfNeeded();
4515 PlayMenuSoundsAndMusic();
4517 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4519 HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE);
4521 DrawMaskedBorder(fade_mask);
4526 static void drawHallOfFameList(int first_entry, int highlight_position)
4530 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4533 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4534 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4535 "HighScores of Level %d", level_nr);
4537 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4539 int entry = first_entry + i;
4540 boolean active = (entry == highlight_position);
4541 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4542 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4543 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4544 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4545 int dxoff = getFontDrawOffsetX(font_nr1);
4546 int dx1 = 3 * getFontWidth(font_nr1);
4547 int dx2 = dx1 + getFontWidth(font_nr1);
4548 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4549 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4550 int sy = mSY + 64 + i * 32;
4552 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4553 DrawText(mSX + dx1, sy, ".", font_nr1);
4555 for (j = 0; j < num_dots; j++)
4556 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4558 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4559 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4561 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4564 redraw_mask |= REDRAW_FIELD;
4567 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4569 static int first_entry = 0;
4570 static int highlight_position = 0;
4571 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4573 if (button == MB_MENU_INITIALIZE)
4576 highlight_position = mx;
4577 drawHallOfFameList(first_entry, highlight_position);
4582 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4583 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4587 if (first_entry > 0)
4589 first_entry -= step;
4590 if (first_entry < 0)
4593 drawHallOfFameList(first_entry, highlight_position);
4598 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4600 first_entry += step;
4601 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4602 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4604 drawHallOfFameList(first_entry, highlight_position);
4607 else if (button == MB_MENU_LEAVE)
4609 PlaySound(SND_MENU_ITEM_SELECTING);
4611 FadeSound(SND_BACKGROUND_SCORES);
4613 SetGameStatus(GAME_MODE_MAIN);
4617 else if (button == MB_MENU_CHOICE)
4619 PlaySound(SND_MENU_ITEM_SELECTING);
4621 FadeSound(SND_BACKGROUND_SCORES);
4623 SetGameStatus(GAME_MODE_MAIN);
4628 if (game_status == GAME_MODE_SCORES)
4629 PlayMenuSoundIfLoop();
4633 /* ========================================================================= */
4634 /* setup screen functions */
4635 /* ========================================================================= */
4637 static struct TokenInfo *setup_info;
4638 static int num_setup_info; /* number of setup entries shown on screen */
4639 static int max_setup_info; /* total number of setup entries in list */
4641 static char *window_size_text;
4642 static char *scaling_type_text;
4643 static char *rendering_mode_text;
4644 static char *scroll_delay_text;
4645 static char *snapshot_mode_text;
4646 static char *game_speed_text;
4647 static char *graphics_set_name;
4648 static char *sounds_set_name;
4649 static char *music_set_name;
4650 static char *volume_simple_text;
4651 static char *volume_loops_text;
4652 static char *volume_music_text;
4653 static char *touch_controls_text;
4654 static char *move_distance_text;
4655 static char *drop_distance_text;
4656 static char *transparency_text;
4657 static char *grid_size_text[2][2];
4659 static void execSetupMain()
4661 setup_mode = SETUP_MODE_MAIN;
4666 static void execSetupGame_setGameSpeeds()
4668 if (game_speeds == NULL)
4672 for (i = 0; game_speeds_list[i].value != -1; i++)
4674 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4675 char identifier[32], name[32];
4676 int value = game_speeds_list[i].value;
4677 char *text = game_speeds_list[i].text;
4679 ti->node_top = &game_speeds;
4680 ti->sort_priority = 10000 - value;
4682 sprintf(identifier, "%d", value);
4683 sprintf(name, "%s", text);
4685 setString(&ti->identifier, identifier);
4686 setString(&ti->name, name);
4687 setString(&ti->name_sorting, name);
4688 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4690 pushTreeInfo(&game_speeds, ti);
4693 /* sort game speed values to start with slowest game speed */
4694 sortTreeInfo(&game_speeds);
4696 /* set current game speed to configured game speed value */
4697 game_speed_current =
4698 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4700 /* if that fails, set current game speed to reliable default value */
4701 if (game_speed_current == NULL)
4702 game_speed_current =
4703 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4705 /* if that also fails, set current game speed to first available speed */
4706 if (game_speed_current == NULL)
4707 game_speed_current = game_speeds;
4710 setup.game_frame_delay = atoi(game_speed_current->identifier);
4712 /* needed for displaying game speed text instead of identifier */
4713 game_speed_text = game_speed_current->name;
4716 static void execSetupGame_setScrollDelays()
4718 if (scroll_delays == NULL)
4722 for (i = 0; scroll_delays_list[i].value != -1; i++)
4724 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4725 char identifier[32], name[32];
4726 int value = scroll_delays_list[i].value;
4727 char *text = scroll_delays_list[i].text;
4729 ti->node_top = &scroll_delays;
4730 ti->sort_priority = value;
4732 sprintf(identifier, "%d", value);
4733 sprintf(name, "%s", text);
4735 setString(&ti->identifier, identifier);
4736 setString(&ti->name, name);
4737 setString(&ti->name_sorting, name);
4738 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4740 pushTreeInfo(&scroll_delays, ti);
4743 /* sort scroll delay values to start with lowest scroll delay value */
4744 sortTreeInfo(&scroll_delays);
4746 /* set current scroll delay value to configured scroll delay value */
4747 scroll_delay_current =
4748 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4750 /* if that fails, set current scroll delay to reliable default value */
4751 if (scroll_delay_current == NULL)
4752 scroll_delay_current =
4753 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4755 /* if that also fails, set current scroll delay to first available value */
4756 if (scroll_delay_current == NULL)
4757 scroll_delay_current = scroll_delays;
4760 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4762 /* needed for displaying scroll delay text instead of identifier */
4763 scroll_delay_text = scroll_delay_current->name;
4766 static void execSetupGame_setSnapshotModes()
4768 if (snapshot_modes == NULL)
4772 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4774 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4775 char identifier[32], name[32];
4776 char *value = snapshot_modes_list[i].value;
4777 char *text = snapshot_modes_list[i].text;
4779 ti->node_top = &snapshot_modes;
4780 ti->sort_priority = i;
4782 sprintf(identifier, "%s", value);
4783 sprintf(name, "%s", text);
4785 setString(&ti->identifier, identifier);
4786 setString(&ti->name, name);
4787 setString(&ti->name_sorting, name);
4788 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4790 pushTreeInfo(&snapshot_modes, ti);
4793 /* sort snapshot mode values to start with lowest snapshot mode value */
4794 sortTreeInfo(&snapshot_modes);
4796 /* set current snapshot mode value to configured snapshot mode value */
4797 snapshot_mode_current =
4798 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4800 /* if that fails, set current snapshot mode to reliable default value */
4801 if (snapshot_mode_current == NULL)
4802 snapshot_mode_current =
4803 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4805 /* if that also fails, set current snapshot mode to first available value */
4806 if (snapshot_mode_current == NULL)
4807 snapshot_mode_current = snapshot_modes;
4810 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4812 /* needed for displaying snapshot mode text instead of identifier */
4813 snapshot_mode_text = snapshot_mode_current->name;
4816 static void execSetupGame()
4818 execSetupGame_setGameSpeeds();
4819 execSetupGame_setScrollDelays();
4820 execSetupGame_setSnapshotModes();
4822 setup_mode = SETUP_MODE_GAME;
4827 static void execSetupChooseGameSpeed()
4829 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4834 static void execSetupChooseScrollDelay()
4836 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4841 static void execSetupChooseSnapshotMode()
4843 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4848 static void execSetupEditor()
4850 setup_mode = SETUP_MODE_EDITOR;
4855 static void execSetupGraphics_setWindowSizes(boolean update_list)
4857 if (window_sizes != NULL && update_list)
4859 freeTreeInfo(window_sizes);
4861 window_sizes = NULL;
4864 if (window_sizes == NULL)
4866 boolean current_window_size_found = FALSE;
4869 for (i = 0; window_sizes_list[i].value != -1; i++)
4871 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4872 char identifier[32], name[32];
4873 int value = window_sizes_list[i].value;
4874 char *text = window_sizes_list[i].text;
4876 ti->node_top = &window_sizes;
4877 ti->sort_priority = value;
4879 sprintf(identifier, "%d", value);
4880 sprintf(name, "%s", text);
4882 setString(&ti->identifier, identifier);
4883 setString(&ti->name, name);
4884 setString(&ti->name_sorting, name);
4885 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4887 pushTreeInfo(&window_sizes, ti);
4889 if (value == setup.window_scaling_percent)
4890 current_window_size_found = TRUE;
4893 if (!current_window_size_found)
4895 // add entry for non-preset window scaling value
4897 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4898 char identifier[32], name[32];
4899 int value = setup.window_scaling_percent;
4901 ti->node_top = &window_sizes;
4902 ti->sort_priority = value;
4904 sprintf(identifier, "%d", value);
4905 sprintf(name, "%d %% (Current)", value);
4907 setString(&ti->identifier, identifier);
4908 setString(&ti->name, name);
4909 setString(&ti->name_sorting, name);
4910 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4912 pushTreeInfo(&window_sizes, ti);
4915 /* sort window size values to start with lowest window size value */
4916 sortTreeInfo(&window_sizes);
4918 /* set current window size value to configured window size value */
4919 window_size_current =
4920 getTreeInfoFromIdentifier(window_sizes,
4921 i_to_a(setup.window_scaling_percent));
4923 /* if that fails, set current window size to reliable default value */
4924 if (window_size_current == NULL)
4925 window_size_current =
4926 getTreeInfoFromIdentifier(window_sizes,
4927 i_to_a(STD_WINDOW_SCALING_PERCENT));
4929 /* if that also fails, set current window size to first available value */
4930 if (window_size_current == NULL)
4931 window_size_current = window_sizes;
4934 setup.window_scaling_percent = atoi(window_size_current->identifier);
4936 /* needed for displaying window size text instead of identifier */
4937 window_size_text = window_size_current->name;
4940 static void execSetupGraphics_setScalingTypes()
4942 if (scaling_types == NULL)
4946 for (i = 0; scaling_types_list[i].value != NULL; i++)
4948 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4949 char identifier[32], name[32];
4950 char *value = scaling_types_list[i].value;
4951 char *text = scaling_types_list[i].text;
4953 ti->node_top = &scaling_types;
4954 ti->sort_priority = i;
4956 sprintf(identifier, "%s", value);
4957 sprintf(name, "%s", text);
4959 setString(&ti->identifier, identifier);
4960 setString(&ti->name, name);
4961 setString(&ti->name_sorting, name);
4962 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
4964 pushTreeInfo(&scaling_types, ti);
4967 /* sort scaling type values to start with lowest scaling type value */
4968 sortTreeInfo(&scaling_types);
4970 /* set current scaling type value to configured scaling type value */
4971 scaling_type_current =
4972 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
4974 /* if that fails, set current scaling type to reliable default value */
4975 if (scaling_type_current == NULL)
4976 scaling_type_current =
4977 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
4979 /* if that also fails, set current scaling type to first available value */
4980 if (scaling_type_current == NULL)
4981 scaling_type_current = scaling_types;
4984 setup.window_scaling_quality = scaling_type_current->identifier;
4986 /* needed for displaying scaling type text instead of identifier */
4987 scaling_type_text = scaling_type_current->name;
4990 static void execSetupGraphics_setRenderingModes()
4992 if (rendering_modes == NULL)
4996 for (i = 0; rendering_modes_list[i].value != NULL; i++)
4998 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4999 char identifier[32], name[32];
5000 char *value = rendering_modes_list[i].value;
5001 char *text = rendering_modes_list[i].text;
5003 ti->node_top = &rendering_modes;
5004 ti->sort_priority = i;
5006 sprintf(identifier, "%s", value);
5007 sprintf(name, "%s", text);
5009 setString(&ti->identifier, identifier);
5010 setString(&ti->name, name);
5011 setString(&ti->name_sorting, name);
5012 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5014 pushTreeInfo(&rendering_modes, ti);
5017 /* sort rendering mode values to start with lowest rendering mode value */
5018 sortTreeInfo(&rendering_modes);
5020 /* set current rendering mode value to configured rendering mode value */
5021 rendering_mode_current =
5022 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5024 /* if that fails, set current rendering mode to reliable default value */
5025 if (rendering_mode_current == NULL)
5026 rendering_mode_current =
5027 getTreeInfoFromIdentifier(rendering_modes,
5028 STR_SPECIAL_RENDERING_DEFAULT);
5030 /* if that also fails, set current rendering mode to first available one */
5031 if (rendering_mode_current == NULL)
5032 rendering_mode_current = rendering_modes;
5035 setup.screen_rendering_mode = rendering_mode_current->identifier;
5037 /* needed for displaying rendering mode text instead of identifier */
5038 rendering_mode_text = rendering_mode_current->name;
5041 static void execSetupGraphics()
5043 // update "setup.window_scaling_percent" from list selection
5044 // (in this case, window scaling was changed on setup screen)
5045 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5046 execSetupGraphics_setWindowSizes(FALSE);
5048 // update list selection from "setup.window_scaling_percent"
5049 // (window scaling may have changed by resizing the window)
5050 execSetupGraphics_setWindowSizes(TRUE);
5052 execSetupGraphics_setScalingTypes();
5053 execSetupGraphics_setRenderingModes();
5055 setup_mode = SETUP_MODE_GRAPHICS;
5059 #if defined(TARGET_SDL2)
5060 // window scaling may have changed at this point
5061 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5063 // window scaling quality may have changed at this point
5064 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5065 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5067 // screen rendering mode may have changed at this point
5068 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5072 static void execSetupChooseWindowSize()
5074 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5079 static void execSetupChooseScalingType()
5081 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5086 static void execSetupChooseRenderingMode()
5088 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5093 static void execSetupChooseVolumeSimple()
5095 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5100 static void execSetupChooseVolumeLoops()
5102 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5107 static void execSetupChooseVolumeMusic()
5109 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5114 static void execSetupSound()
5116 if (volumes_simple == NULL)
5118 boolean current_volume_simple_found = FALSE;
5121 for (i = 0; volumes_list[i].value != -1; i++)
5123 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5124 char identifier[32], name[32];
5125 int value = volumes_list[i].value;
5126 char *text = volumes_list[i].text;
5128 ti->node_top = &volumes_simple;
5129 ti->sort_priority = value;
5131 sprintf(identifier, "%d", value);
5132 sprintf(name, "%s", text);
5134 setString(&ti->identifier, identifier);
5135 setString(&ti->name, name);
5136 setString(&ti->name_sorting, name);
5137 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5139 pushTreeInfo(&volumes_simple, ti);
5141 if (value == setup.volume_simple)
5142 current_volume_simple_found = TRUE;
5145 if (!current_volume_simple_found)
5147 // add entry for non-preset volume value
5149 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5150 char identifier[32], name[32];
5151 int value = setup.volume_simple;
5153 ti->node_top = &volumes_simple;
5154 ti->sort_priority = value;
5156 sprintf(identifier, "%d", value);
5157 sprintf(name, "%d %% (Current)", value);
5159 setString(&ti->identifier, identifier);
5160 setString(&ti->name, name);
5161 setString(&ti->name_sorting, name);
5162 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5164 pushTreeInfo(&volumes_simple, ti);
5167 /* sort volume values to start with lowest volume value */
5168 sortTreeInfo(&volumes_simple);
5170 /* set current volume value to configured volume value */
5171 volume_simple_current =
5172 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5174 /* if that fails, set current volume to reliable default value */
5175 if (volume_simple_current == NULL)
5176 volume_simple_current =
5177 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5179 /* if that also fails, set current volume to first available value */
5180 if (volume_simple_current == NULL)
5181 volume_simple_current = volumes_simple;
5184 if (volumes_loops == NULL)
5186 boolean current_volume_loops_found = FALSE;
5189 for (i = 0; volumes_list[i].value != -1; i++)
5191 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5192 char identifier[32], name[32];
5193 int value = volumes_list[i].value;
5194 char *text = volumes_list[i].text;
5196 ti->node_top = &volumes_loops;
5197 ti->sort_priority = value;
5199 sprintf(identifier, "%d", value);
5200 sprintf(name, "%s", text);
5202 setString(&ti->identifier, identifier);
5203 setString(&ti->name, name);
5204 setString(&ti->name_sorting, name);
5205 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5207 pushTreeInfo(&volumes_loops, ti);
5209 if (value == setup.volume_loops)
5210 current_volume_loops_found = TRUE;
5213 if (!current_volume_loops_found)
5215 // add entry for non-preset volume value
5217 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5218 char identifier[32], name[32];
5219 int value = setup.volume_loops;
5221 ti->node_top = &volumes_loops;
5222 ti->sort_priority = value;
5224 sprintf(identifier, "%d", value);
5225 sprintf(name, "%d %% (Current)", value);
5227 setString(&ti->identifier, identifier);
5228 setString(&ti->name, name);
5229 setString(&ti->name_sorting, name);
5230 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5232 pushTreeInfo(&volumes_loops, ti);
5235 /* sort volume values to start with lowest volume value */
5236 sortTreeInfo(&volumes_loops);
5238 /* set current volume value to configured volume value */
5239 volume_loops_current =
5240 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5242 /* if that fails, set current volume to reliable default value */
5243 if (volume_loops_current == NULL)
5244 volume_loops_current =
5245 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5247 /* if that also fails, set current volume to first available value */
5248 if (volume_loops_current == NULL)
5249 volume_loops_current = volumes_loops;
5252 if (volumes_music == NULL)
5254 boolean current_volume_music_found = FALSE;
5257 for (i = 0; volumes_list[i].value != -1; i++)
5259 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5260 char identifier[32], name[32];
5261 int value = volumes_list[i].value;
5262 char *text = volumes_list[i].text;
5264 ti->node_top = &volumes_music;
5265 ti->sort_priority = value;
5267 sprintf(identifier, "%d", value);
5268 sprintf(name, "%s", text);
5270 setString(&ti->identifier, identifier);
5271 setString(&ti->name, name);
5272 setString(&ti->name_sorting, name);
5273 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5275 pushTreeInfo(&volumes_music, ti);
5277 if (value == setup.volume_music)
5278 current_volume_music_found = TRUE;
5281 if (!current_volume_music_found)
5283 // add entry for non-preset volume value
5285 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5286 char identifier[32], name[32];
5287 int value = setup.volume_music;
5289 ti->node_top = &volumes_music;
5290 ti->sort_priority = value;
5292 sprintf(identifier, "%d", value);
5293 sprintf(name, "%d %% (Current)", value);
5295 setString(&ti->identifier, identifier);
5296 setString(&ti->name, name);
5297 setString(&ti->name_sorting, name);
5298 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5300 pushTreeInfo(&volumes_music, ti);
5303 /* sort volume values to start with lowest volume value */
5304 sortTreeInfo(&volumes_music);
5306 /* set current volume value to configured volume value */
5307 volume_music_current =
5308 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5310 /* if that fails, set current volume to reliable default value */
5311 if (volume_music_current == NULL)
5312 volume_music_current =
5313 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5315 /* if that also fails, set current volume to first available value */
5316 if (volume_music_current == NULL)
5317 volume_music_current = volumes_music;
5320 setup.volume_simple = atoi(volume_simple_current->identifier);
5321 setup.volume_loops = atoi(volume_loops_current->identifier);
5322 setup.volume_music = atoi(volume_music_current->identifier);
5324 /* needed for displaying volume text instead of identifier */
5325 volume_simple_text = volume_simple_current->name;
5326 volume_loops_text = volume_loops_current->name;
5327 volume_music_text = volume_music_current->name;
5329 setup_mode = SETUP_MODE_SOUND;
5334 static void execSetupChooseTouchControls()
5336 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5341 static void execSetupChooseMoveDistance()
5343 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5348 static void execSetupChooseDropDistance()
5350 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5355 static void execSetupChooseTransparency()
5357 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5362 static void execSetupChooseGridXSize_0()
5364 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5369 static void execSetupChooseGridYSize_0()
5371 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5376 static void execSetupChooseGridXSize_1()
5378 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5383 static void execSetupChooseGridYSize_1()
5385 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5390 static void execSetupConfigureVirtualButtons()
5392 ConfigureVirtualButtons();
5397 static void execSetupTouch()
5401 if (touch_controls == NULL)
5403 for (i = 0; touch_controls_list[i].value != NULL; i++)
5405 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5406 char identifier[32], name[32];
5407 char *value = touch_controls_list[i].value;
5408 char *text = touch_controls_list[i].text;
5410 ti->node_top = &touch_controls;
5411 ti->sort_priority = i;
5413 sprintf(identifier, "%s", value);
5414 sprintf(name, "%s", text);
5416 setString(&ti->identifier, identifier);
5417 setString(&ti->name, name);
5418 setString(&ti->name_sorting, name);
5419 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5421 pushTreeInfo(&touch_controls, ti);
5424 /* sort touch control values to start with lowest touch control value */
5425 sortTreeInfo(&touch_controls);
5427 /* set current touch control value to configured touch control value */
5428 touch_control_current =
5429 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5431 /* if that fails, set current touch control to reliable default value */
5432 if (touch_control_current == NULL)
5433 touch_control_current =
5434 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5436 /* if that also fails, set current touch control to first available value */
5437 if (touch_control_current == NULL)
5438 touch_control_current = touch_controls;
5441 if (move_distances == NULL)
5443 for (i = 0; distances_list[i].value != -1; i++)
5445 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5446 char identifier[32], name[32];
5447 int value = distances_list[i].value;
5448 char *text = distances_list[i].text;
5450 ti->node_top = &move_distances;
5451 ti->sort_priority = value;
5453 sprintf(identifier, "%d", value);
5454 sprintf(name, "%s", text);
5456 setString(&ti->identifier, identifier);
5457 setString(&ti->name, name);
5458 setString(&ti->name_sorting, name);
5459 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5461 pushTreeInfo(&move_distances, ti);
5464 /* sort distance values to start with lowest distance value */
5465 sortTreeInfo(&move_distances);
5467 /* set current distance value to configured distance value */
5468 move_distance_current =
5469 getTreeInfoFromIdentifier(move_distances,
5470 i_to_a(setup.touch.move_distance));
5472 /* if that fails, set current distance to reliable default value */
5473 if (move_distance_current == NULL)
5474 move_distance_current =
5475 getTreeInfoFromIdentifier(move_distances,
5476 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5478 /* if that also fails, set current distance to first available value */
5479 if (move_distance_current == NULL)
5480 move_distance_current = move_distances;
5483 if (drop_distances == NULL)
5485 for (i = 0; distances_list[i].value != -1; i++)
5487 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5488 char identifier[32], name[32];
5489 int value = distances_list[i].value;
5490 char *text = distances_list[i].text;
5492 ti->node_top = &drop_distances;
5493 ti->sort_priority = value;
5495 sprintf(identifier, "%d", value);
5496 sprintf(name, "%s", text);
5498 setString(&ti->identifier, identifier);
5499 setString(&ti->name, name);
5500 setString(&ti->name_sorting, name);
5501 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5503 pushTreeInfo(&drop_distances, ti);
5506 /* sort distance values to start with lowest distance value */
5507 sortTreeInfo(&drop_distances);
5509 /* set current distance value to configured distance value */
5510 drop_distance_current =
5511 getTreeInfoFromIdentifier(drop_distances,
5512 i_to_a(setup.touch.drop_distance));
5514 /* if that fails, set current distance to reliable default value */
5515 if (drop_distance_current == NULL)
5516 drop_distance_current =
5517 getTreeInfoFromIdentifier(drop_distances,
5518 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5520 /* if that also fails, set current distance to first available value */
5521 if (drop_distance_current == NULL)
5522 drop_distance_current = drop_distances;
5525 if (transparencies == NULL)
5527 for (i = 0; transparencies_list[i].value != -1; i++)
5529 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5530 char identifier[32], name[32];
5531 int value = transparencies_list[i].value;
5532 char *text = transparencies_list[i].text;
5534 ti->node_top = &transparencies;
5535 ti->sort_priority = value;
5537 sprintf(identifier, "%d", value);
5538 sprintf(name, "%s", text);
5540 setString(&ti->identifier, identifier);
5541 setString(&ti->name, name);
5542 setString(&ti->name_sorting, name);
5543 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5545 pushTreeInfo(&transparencies, ti);
5548 /* sort transparency values to start with lowest transparency value */
5549 sortTreeInfo(&transparencies);
5551 /* set current transparency value to configured transparency value */
5552 transparency_current =
5553 getTreeInfoFromIdentifier(transparencies,
5554 i_to_a(setup.touch.transparency));
5556 /* if that fails, set current transparency to reliable default value */
5557 if (transparency_current == NULL)
5558 transparency_current =
5559 getTreeInfoFromIdentifier(transparencies,
5560 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5562 /* if that also fails, set current transparency to first available value */
5563 if (transparency_current == NULL)
5564 transparency_current = transparencies;
5567 for (i = 0; i < 2; i++)
5569 for (j = 0; j < 2; j++)
5571 if (grid_sizes[i][j] == NULL)
5573 for (k = 0; grid_sizes_list[k].value != -1; k++)
5575 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5576 char identifier[32], name[32];
5577 int value = grid_sizes_list[k].value;
5578 char *text = grid_sizes_list[k].text;
5580 ti->node_top = &grid_sizes[i][j];
5581 ti->sort_priority = value;
5583 sprintf(identifier, "%d", value);
5584 sprintf(name, "%s", text);
5586 setString(&ti->identifier, identifier);
5587 setString(&ti->name, name);
5588 setString(&ti->name_sorting, name);
5589 setString(&ti->infotext,
5592 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5593 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5595 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5596 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5598 pushTreeInfo(&grid_sizes[i][j], ti);
5601 /* sort grid size values to start with lowest grid size value */
5602 sortTreeInfo(&grid_sizes[i][j]);
5604 /* set current grid size value to configured grid size value */
5605 grid_size_current[i][j] =
5606 getTreeInfoFromIdentifier(grid_sizes[i][j],
5608 setup.touch.grid_xsize[i] :
5609 setup.touch.grid_ysize[i]));
5611 /* if that fails, set current grid size to reliable default value */
5612 if (grid_size_current[i][j] == NULL)
5613 grid_size_current[i][j] =
5614 getTreeInfoFromIdentifier(grid_sizes[i][j],
5616 DEFAULT_GRID_XSIZE(i) :
5617 DEFAULT_GRID_YSIZE(i)));
5619 /* if that also fails, set current grid size to first available value */
5620 if (grid_size_current[i][j] == NULL)
5621 grid_size_current[i][j] = grid_sizes[i][j];
5626 setup.touch.control_type = touch_control_current->identifier;
5627 setup.touch.move_distance = atoi(move_distance_current->identifier);
5628 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5629 setup.touch.transparency = atoi(transparency_current->identifier);
5631 for (i = 0; i < 2; i++)
5633 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5634 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5636 if (i == GRID_ACTIVE_NR())
5638 overlay.grid_xsize = setup.touch.grid_xsize[i];
5639 overlay.grid_ysize = setup.touch.grid_ysize[i];
5643 /* needed for displaying value text instead of identifier */
5644 touch_controls_text = touch_control_current->name;
5645 move_distance_text = move_distance_current->name;
5646 drop_distance_text = drop_distance_current->name;
5647 transparency_text = transparency_current->name;
5649 for (i = 0; i < 2; i++)
5650 for (j = 0; j < 2; j++)
5651 grid_size_text[i][j] = grid_size_current[i][j]->name;
5653 setup_mode = SETUP_MODE_TOUCH;
5658 static void execSetupArtwork()
5661 printf("::: '%s', '%s', '%s'\n",
5662 artwork.gfx_current->subdir,
5663 artwork.gfx_current->fullpath,
5664 artwork.gfx_current->basepath);
5667 setup.graphics_set = artwork.gfx_current->identifier;
5668 setup.sounds_set = artwork.snd_current->identifier;
5669 setup.music_set = artwork.mus_current->identifier;
5671 /* needed if last screen (setup choice) changed graphics, sounds or music */
5672 ReloadCustomArtwork(0);
5674 /* needed for displaying artwork name instead of artwork identifier */
5675 graphics_set_name = artwork.gfx_current->name;
5676 sounds_set_name = artwork.snd_current->name;
5677 music_set_name = artwork.mus_current->name;
5679 setup_mode = SETUP_MODE_ARTWORK;
5684 static void execSetupChooseGraphics()
5686 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5691 static void execSetupChooseSounds()
5693 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5698 static void execSetupChooseMusic()
5700 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5705 static void execSetupInput()
5707 setup_mode = SETUP_MODE_INPUT;
5712 static void execSetupShortcuts()
5714 setup_mode = SETUP_MODE_SHORTCUTS;
5719 static void execSetupShortcuts1()
5721 setup_mode = SETUP_MODE_SHORTCUTS_1;
5726 static void execSetupShortcuts2()
5728 setup_mode = SETUP_MODE_SHORTCUTS_2;
5733 static void execSetupShortcuts3()
5735 setup_mode = SETUP_MODE_SHORTCUTS_3;
5740 static void execSetupShortcuts4()
5742 setup_mode = SETUP_MODE_SHORTCUTS_4;
5747 static void execSetupShortcuts5()
5749 setup_mode = SETUP_MODE_SHORTCUTS_5;
5754 static void execExitSetup()
5756 SetGameStatus(GAME_MODE_MAIN);
5761 static void execSaveAndExitSetup()
5770 void *related_value;
5771 } hide_related_entry_list[] =
5773 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5774 { &setup.game_frame_delay, &game_speed_text },
5776 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5777 { &setup.scroll_delay_value, &scroll_delay_text },
5779 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5780 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5782 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5783 { &setup.window_scaling_percent, &window_size_text },
5785 { &setup.window_scaling_quality, execSetupChooseScalingType },
5786 { &setup.window_scaling_quality, &scaling_type_text },
5788 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5789 { &setup.screen_rendering_mode, &rendering_mode_text },
5791 { &setup.graphics_set, execSetupChooseGraphics },
5792 { &setup.graphics_set, &graphics_set_name },
5794 { &setup.sounds_set, execSetupChooseSounds },
5795 { &setup.sounds_set, &sounds_set_name },
5797 { &setup.music_set, execSetupChooseMusic },
5798 { &setup.music_set, &music_set_name },
5800 { &setup.volume_simple, execSetupChooseVolumeSimple },
5801 { &setup.volume_simple, &volume_simple_text },
5803 { &setup.volume_loops, execSetupChooseVolumeLoops },
5804 { &setup.volume_loops, &volume_loops_text },
5806 { &setup.volume_music, execSetupChooseVolumeMusic },
5807 { &setup.volume_music, &volume_music_text },
5809 { &setup.touch.control_type, execSetupChooseTouchControls },
5810 { &setup.touch.control_type, &touch_controls_text },
5812 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5813 { &setup.touch.move_distance, &move_distance_text },
5815 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5816 { &setup.touch.drop_distance, &drop_distance_text },
5818 { &setup.touch.transparency, execSetupChooseTransparency },
5819 { &setup.touch.transparency, &transparency_text },
5821 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5822 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5824 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5825 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5827 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5828 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5830 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5831 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5836 void setHideRelatedSetupEntries()
5840 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5841 if (hideSetupEntry(hide_related_entry_list[i].value))
5842 setHideSetupEntry(hide_related_entry_list[i].related_value);
5845 static struct TokenInfo setup_info_main[] =
5847 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5848 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5849 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5850 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5851 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5852 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5853 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5854 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5855 { TYPE_EMPTY, NULL, "" },
5856 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5857 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5862 static struct TokenInfo setup_info_game[] =
5864 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5865 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5866 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5867 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5868 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5869 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5870 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5871 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5872 { TYPE_STRING, &game_speed_text, "" },
5874 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5875 { TYPE_STRING, &scroll_delay_text, "" },
5877 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5878 { TYPE_STRING, &snapshot_mode_text, "" },
5879 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
5880 { TYPE_EMPTY, NULL, "" },
5881 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5886 static struct TokenInfo setup_info_editor[] =
5889 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
5890 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
5891 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
5892 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
5893 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
5894 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
5895 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
5896 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
5897 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
5898 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
5900 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
5901 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
5903 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
5905 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
5906 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
5907 { TYPE_EMPTY, NULL, "" },
5909 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
5910 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
5911 { TYPE_EMPTY, NULL, "" },
5913 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
5914 { TYPE_EMPTY, NULL, "" },
5915 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5920 static struct TokenInfo setup_info_graphics[] =
5922 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
5923 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
5924 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
5925 { TYPE_STRING, &window_size_text, "" },
5926 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
5927 { TYPE_STRING, &scaling_type_text, "" },
5928 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
5929 { TYPE_STRING, &rendering_mode_text, "" },
5932 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5933 { TYPE_STRING, &scroll_delay_text, "" },
5935 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
5936 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
5937 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
5938 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
5939 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
5940 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
5941 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
5942 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
5943 { TYPE_EMPTY, NULL, "" },
5944 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5949 static struct TokenInfo setup_info_sound[] =
5951 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
5952 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
5953 { TYPE_SWITCH, &setup.sound_music, "Music:" },
5954 { TYPE_EMPTY, NULL, "" },
5955 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
5956 { TYPE_STRING, &volume_simple_text, "" },
5957 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
5958 { TYPE_STRING, &volume_loops_text, "" },
5959 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
5960 { TYPE_STRING, &volume_music_text, "" },
5961 { TYPE_EMPTY, NULL, "" },
5962 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5967 static struct TokenInfo setup_info_artwork[] =
5969 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
5970 { TYPE_STRING, &graphics_set_name, "" },
5971 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
5972 { TYPE_STRING, &sounds_set_name, "" },
5973 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
5974 { TYPE_STRING, &music_set_name, "" },
5975 { TYPE_EMPTY, NULL, "" },
5976 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
5977 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
5978 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
5979 { TYPE_EMPTY, NULL, "" },
5980 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
5985 static struct TokenInfo setup_info_input[] =
5987 { TYPE_SWITCH, NULL, "Player:" },
5988 { TYPE_SWITCH, NULL, "Device:" },
5989 { TYPE_SWITCH, NULL, "" },
5990 { TYPE_SKIPPABLE, NULL, "" },
5991 { TYPE_EMPTY, NULL, "" },
5992 { TYPE_EMPTY, NULL, "" },
5993 { TYPE_EMPTY, NULL, "" },
5994 { TYPE_EMPTY, NULL, "" },
5995 { TYPE_EMPTY, NULL, "" },
5996 { TYPE_EMPTY, NULL, "" },
5997 { TYPE_EMPTY, NULL, "" },
5998 { TYPE_EMPTY, NULL, "" },
5999 { TYPE_SKIPPABLE, NULL, "" },
6000 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6005 static struct TokenInfo setup_info_touch[] =
6007 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6008 { TYPE_STRING, &touch_controls_text, "" },
6009 { TYPE_EMPTY, NULL, "" },
6010 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6015 static struct TokenInfo setup_info_touch_virtual_buttons[] =
6017 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6018 { TYPE_STRING, &touch_controls_text, "" },
6019 { TYPE_EMPTY, NULL, "" },
6020 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6021 { TYPE_STRING, &grid_size_text[0][0], "" },
6022 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6023 { TYPE_STRING, &grid_size_text[0][1], "" },
6024 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Transparency:" },
6025 { TYPE_STRING, &transparency_text, "" },
6026 { TYPE_EMPTY, NULL, "" },
6027 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6028 { TYPE_EMPTY, NULL, "" },
6029 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6034 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6036 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6037 { TYPE_STRING, &touch_controls_text, "" },
6038 { TYPE_EMPTY, NULL, "" },
6039 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6040 { TYPE_STRING, &move_distance_text, "" },
6041 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6042 { TYPE_STRING, &drop_distance_text, "" },
6043 { TYPE_EMPTY, NULL, "" },
6044 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6049 static struct TokenInfo setup_info_shortcuts[] =
6051 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6052 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6053 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6054 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6055 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6056 { TYPE_EMPTY, NULL, "" },
6057 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6062 static struct TokenInfo setup_info_shortcuts_1[] =
6064 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6065 { TYPE_KEY, &setup.shortcut.save_game, "" },
6066 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6067 { TYPE_KEY, &setup.shortcut.load_game, "" },
6068 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6069 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6070 { TYPE_EMPTY, NULL, "" },
6071 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6072 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6073 { TYPE_EMPTY, NULL, "" },
6074 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6079 static struct TokenInfo setup_info_shortcuts_2[] =
6081 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6082 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6083 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6084 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6085 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6086 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6087 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6088 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6089 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6090 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6091 { TYPE_EMPTY, NULL, "" },
6092 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6097 static struct TokenInfo setup_info_shortcuts_3[] =
6099 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6100 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6101 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6102 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6103 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6104 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6105 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6106 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6107 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6108 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6109 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6110 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6111 { TYPE_EMPTY, NULL, "" },
6112 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6117 static struct TokenInfo setup_info_shortcuts_4[] =
6119 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6120 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6121 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6122 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6123 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6124 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6125 { TYPE_EMPTY, NULL, "" },
6126 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6131 static struct TokenInfo setup_info_shortcuts_5[] =
6133 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6134 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6135 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6136 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6137 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6138 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6139 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6140 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6141 { TYPE_EMPTY, NULL, "" },
6142 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6147 static Key getSetupKey()
6149 Key key = KSYM_UNDEFINED;
6150 boolean got_key_event = FALSE;
6152 while (!got_key_event)
6156 if (NextValidEvent(&event))
6160 case EVENT_KEYPRESS:
6162 key = GetEventKey((KeyEvent *)&event, TRUE);
6164 /* press 'Escape' or 'Enter' to keep the existing key binding */
6165 if (key == KSYM_Escape || key == KSYM_Return)
6166 key = KSYM_UNDEFINED; /* keep old value */
6168 got_key_event = TRUE;
6172 case EVENT_KEYRELEASE:
6173 key_joystick_mapping = 0;
6177 HandleOtherEvents(&event);
6188 static int getSetupValueFont(int type, void *value)
6190 if (type & TYPE_GHOSTED)
6191 return FONT_OPTION_OFF;
6192 else if (type & TYPE_KEY)
6193 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6194 else if (type & TYPE_STRING)
6195 return FONT_VALUE_2;
6196 else if (type & TYPE_ECS_AGA)
6197 return FONT_VALUE_1;
6198 else if (type & TYPE_BOOLEAN_STYLE)
6199 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6200 else if (type & TYPE_YES_NO_AUTO)
6201 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6202 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6204 return FONT_VALUE_1;
6207 static int getSetupValueFontNarrow(int type, int font_nr)
6209 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6210 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6211 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6215 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6217 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6218 struct TokenInfo *si = &setup_info[si_pos];
6219 boolean font_draw_xoffset_modified = FALSE;
6220 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6221 int font_draw_xoffset_old = -1;
6222 int xoffset = (scrollbar_needed ? -1 : 0);
6223 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6224 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6225 int xpos = menu_screen_value_xpos;
6226 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6227 int startx = mSX + xpos * 32;
6228 int starty = mSY + ypos * 32;
6229 int font_nr, font_nr_default, font_width_default;
6230 int type = si->type;
6231 void *value = si->value;
6232 char *value_string = getSetupValue(type, value);
6235 if (value_string == NULL)
6238 if (type & TYPE_KEY)
6240 xpos = MENU_SCREEN_START_XPOS;
6242 if (type & TYPE_QUERY)
6243 value_string = "<press key>";
6245 else if (type & TYPE_STRING)
6247 int max_value_len = (SCR_FIELDX - 2) * 2;
6249 xpos = MENU_SCREEN_START_XPOS;
6251 if (strlen(value_string) > max_value_len)
6252 value_string[max_value_len] = '\0';
6254 else if (type & TYPE_YES_NO_AUTO)
6256 xpos = menu_screen_value_xpos - 1;
6259 startx = mSX + xpos * 32;
6260 starty = mSY + ypos * 32;
6261 font_nr_default = getSetupValueFont(type, value);
6262 font_width_default = getFontWidth(font_nr_default);
6264 font_nr = font_nr_default;
6266 // special check if right-side setup values moved left due to scrollbar
6267 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6269 int max_menu_text_length = 26; // maximum text length for classic menu
6270 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6271 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6272 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6273 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6274 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6276 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6279 startx = mSX + xpos * 32;
6281 font_nr = getSetupValueFontNarrow(type, font_nr);
6285 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6286 if (setup_mode != SETUP_MODE_INPUT)
6288 int max_menu_text_length_big = (menu_screen_value_xpos -
6289 MENU_SCREEN_START_XPOS);
6290 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6291 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6292 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6293 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6294 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6295 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6296 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6297 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6298 boolean correct_font_draw_xoffset = FALSE;
6300 if (xpos == MENU_SCREEN_START_XPOS &&
6301 startx + font1_xoffset < text_startx + text_font_xoffset)
6302 correct_font_draw_xoffset = TRUE;
6304 if (xpos == menu_screen_value_xpos &&
6305 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6306 correct_font_draw_xoffset = TRUE;
6308 /* check if setup value would overlap with setup text when printed */
6309 /* (this can happen for extreme/wrong values for font draw offset) */
6310 if (correct_font_draw_xoffset)
6312 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6313 font_draw_xoffset_modified = TRUE;
6315 if (type & TYPE_KEY)
6316 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6317 else if (!(type & TYPE_STRING))
6318 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6319 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6323 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6324 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6326 DrawText(startx, starty, value_string, font_nr);
6328 if (font_draw_xoffset_modified)
6329 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6332 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6334 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6335 struct TokenInfo *si = &setup_info[si_pos];
6337 if (si->type & TYPE_BOOLEAN_STYLE)
6339 *(boolean *)si->value ^= TRUE;
6341 else if (si->type & TYPE_YES_NO_AUTO)
6345 (*(int *)si->value == AUTO ? TRUE :
6346 *(int *)si->value == TRUE ? FALSE : AUTO) :
6347 (*(int *)si->value == TRUE ? AUTO :
6348 *(int *)si->value == AUTO ? FALSE : TRUE));
6350 else if (si->type & TYPE_KEY)
6354 si->type |= TYPE_QUERY;
6355 drawSetupValue(screen_pos, setup_info_pos_raw);
6356 si->type &= ~TYPE_QUERY;
6358 key = getSetupKey();
6359 if (key != KSYM_UNDEFINED)
6360 *(Key *)si->value = key;
6363 drawSetupValue(screen_pos, setup_info_pos_raw);
6365 // fullscreen state may have changed at this point
6366 if (si->value == &setup.fullscreen)
6367 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6370 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6372 static struct TokenInfo *setup_info_final = NULL;
6377 /* determine maximum list size of target list */
6378 while (setup_info_orig[list_size++].type != 0);
6380 /* free, allocate and clear memory for target list */
6381 checked_free(setup_info_final);
6382 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6384 /* copy setup info list without setup entries marked as hidden */
6385 for (i = 0; setup_info_orig[i].type != 0; i++)
6387 /* skip setup entries configured to be hidden */
6388 if (hideSetupEntry(setup_info_orig[i].value))
6391 /* skip skippable setup entries if screen is lower than usual */
6392 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6393 setup_info_orig[i].type == TYPE_SKIPPABLE)
6396 setup_info_final[list_pos++] = setup_info_orig[i];
6399 return setup_info_final;
6402 static void DrawSetupScreen_Generic()
6404 int fade_mask = REDRAW_FIELD;
6405 boolean redraw_all = FALSE;
6406 char *title_string = NULL;
6409 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6410 fade_mask = REDRAW_ALL;
6413 FadeMenuSoundsAndMusic();
6415 FreeScreenGadgets();
6416 CreateScreenGadgets();
6418 if (redraw_mask & REDRAW_ALL)
6423 /* needed if different viewport properties defined for setup screen */
6424 ChangeViewportPropertiesIfNeeded();
6426 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6430 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6432 if (setup_mode == SETUP_MODE_MAIN)
6434 setup_info = setup_info_main;
6435 title_string = STR_SETUP_MAIN;
6437 else if (setup_mode == SETUP_MODE_GAME)
6439 setup_info = setup_info_game;
6440 title_string = STR_SETUP_GAME;
6442 else if (setup_mode == SETUP_MODE_EDITOR)
6444 setup_info = setup_info_editor;
6445 title_string = STR_SETUP_EDITOR;
6447 else if (setup_mode == SETUP_MODE_GRAPHICS)
6449 setup_info = setup_info_graphics;
6450 title_string = STR_SETUP_GRAPHICS;
6452 else if (setup_mode == SETUP_MODE_SOUND)
6454 setup_info = setup_info_sound;
6455 title_string = STR_SETUP_SOUND;
6457 else if (setup_mode == SETUP_MODE_ARTWORK)
6459 setup_info = setup_info_artwork;
6460 title_string = STR_SETUP_ARTWORK;
6462 else if (setup_mode == SETUP_MODE_TOUCH)
6464 setup_info = setup_info_touch;
6465 title_string = STR_SETUP_TOUCH;
6467 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6468 setup_info = setup_info_touch_virtual_buttons;
6469 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6470 setup_info = setup_info_touch_wipe_gestures;
6472 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6474 setup_info = setup_info_shortcuts;
6475 title_string = STR_SETUP_SHORTCUTS;
6477 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6479 setup_info = setup_info_shortcuts_1;
6480 title_string = STR_SETUP_SHORTCUTS;
6482 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6484 setup_info = setup_info_shortcuts_2;
6485 title_string = STR_SETUP_SHORTCUTS;
6487 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6489 setup_info = setup_info_shortcuts_3;
6490 title_string = STR_SETUP_SHORTCUTS;
6492 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6494 setup_info = setup_info_shortcuts_4;
6495 title_string = STR_SETUP_SHORTCUTS;
6497 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6499 setup_info = setup_info_shortcuts_5;
6500 title_string = STR_SETUP_SHORTCUTS;
6503 /* use modified setup info without setup entries marked as hidden */
6504 setup_info = getSetupInfoFinal(setup_info);
6506 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6508 // determine maximal number of setup entries that can be displayed on screen
6510 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6513 // determine maximal number of setup entries available for this setup screen
6515 for (i = 0; setup_info[i].type != 0; i++)
6518 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6520 MapScreenGadgets(max_setup_info);
6523 redraw_mask = fade_mask = REDRAW_ALL;
6525 DrawMaskedBorder(fade_mask);
6530 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6532 menu_info = setup_info;
6534 HandleMenuScreen(mx, my, dx, dy, button,
6535 setup_mode, num_setup_info, max_setup_info);
6538 void DrawSetupScreen_Input()
6542 FadeOut(REDRAW_FIELD);
6546 setup_info = getSetupInfoFinal(setup_info_input);
6548 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6550 for (i = 0; setup_info[i].type != 0; i++)
6552 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6553 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6554 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6555 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6556 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6557 initCursor(i, IMG_MENU_BUTTON);
6559 DrawCursorAndText_Setup(i, -1, FALSE);
6562 /* create gadgets for setup input menu screen */
6563 FreeScreenGadgets();
6564 CreateScreenGadgets();
6566 /* map gadgets for setup input menu screen */
6567 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6569 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6571 FadeIn(REDRAW_FIELD);
6574 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6576 if (device_name == NULL)
6579 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6582 if (strlen(device_name) > 1)
6584 char c1 = device_name[strlen(device_name) - 1];
6585 char c2 = device_name[strlen(device_name) - 2];
6587 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6588 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6591 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6592 strlen(device_name));
6595 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6598 static struct SetupKeyboardInfo custom_key;
6605 { &custom_key.left, "Axis/Pad Left" },
6606 { &custom_key.right, "Axis/Pad Right" },
6607 { &custom_key.up, "Axis/Pad Up" },
6608 { &custom_key.down, "Axis/Pad Down" },
6609 { &custom_key.snap, "Button 1/A/X" },
6610 { &custom_key.drop, "Button 2/B/Y" }
6612 static char *joystick_name[MAX_PLAYERS] =
6619 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6620 int font_nr_info = FONT_MENU_1;
6621 int font_nr_name = FONT_VALUE_OLD;
6622 int font_nr_on = FONT_VALUE_1;
6623 int font_nr_off = FONT_VALUE_OLD;
6626 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6628 font_nr_info = FONT_MENU_2;
6629 font_nr_on = FONT_VALUE_NARROW;
6630 font_nr_off = FONT_VALUE_OLD_NARROW;
6633 custom_key = setup.input[player_nr].key;
6635 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6636 FONT_INPUT_1_ACTIVE);
6638 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6640 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6641 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6643 if (setup.input[player_nr].use_joystick)
6645 char *device_name = setup.input[player_nr].joy.device_name;
6646 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6647 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6648 char *text = joystick_name[joystick_nr];
6649 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6651 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6652 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6656 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6657 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6660 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6661 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6665 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6666 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6667 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6668 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6670 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6671 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6672 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6673 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6674 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6675 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6677 for (i = 0; i < 6; i++)
6679 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6681 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6683 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6684 (setup.input[player_nr].use_joystick ?
6686 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6690 static int input_player_nr = 0;
6692 void HandleSetupScreen_Input_Player(int step, int direction)
6694 int old_player_nr = input_player_nr;
6697 new_player_nr = old_player_nr + step * direction;
6698 if (new_player_nr < 0)
6700 if (new_player_nr > MAX_PLAYERS - 1)
6701 new_player_nr = MAX_PLAYERS - 1;
6703 if (new_player_nr != old_player_nr)
6705 input_player_nr = new_player_nr;
6707 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6711 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6713 static int choice = 0;
6716 int pos_start = SETUPINPUT_SCREEN_POS_START;
6717 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6718 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6719 int pos_end = SETUPINPUT_SCREEN_POS_END;
6721 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6725 for (i = 0; setup_info_input[i].type != 0; i++)
6727 /* adjust menu structure according to skipped setup entries */
6728 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6736 if (button == MB_MENU_INITIALIZE)
6738 /* input setup menu may have changed size due to graphics configuration */
6739 if (choice >= pos_empty1)
6742 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6744 DrawCursorAndText_Setup(choice, -1, TRUE);
6748 else if (button == MB_MENU_LEAVE)
6750 setup_mode = SETUP_MODE_MAIN;
6757 if (mx || my) /* mouse input */
6759 x = (mx - mSX) / 32;
6760 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6762 else if (dx || dy) /* keyboard input */
6764 if (dx && choice == 0)
6765 x = (dx < 0 ? 10 : 12);
6766 else if ((dx && choice == 1) ||
6767 (dx == -1 && choice == pos_end))
6768 button = MB_MENU_CHOICE;
6772 if (y >= pos_empty1 && y <= pos_empty2)
6773 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6776 if (y == 0 && dx != 0 && button)
6778 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6780 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6781 y >= pos_start && y <= pos_end &&
6782 !(y >= pos_empty1 && y <= pos_empty2))
6788 DrawCursorAndText_Setup(choice, -1, FALSE);
6789 DrawCursorAndText_Setup(y, -1, TRUE);
6791 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6800 char *device_name = setup.input[input_player_nr].joy.device_name;
6802 if (!setup.input[input_player_nr].use_joystick)
6804 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
6806 setJoystickDeviceToNr(device_name, new_device_nr);
6807 setup.input[input_player_nr].use_joystick = TRUE;
6811 int device_nr = getJoystickNrFromDeviceName(device_name);
6812 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
6814 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
6815 setup.input[input_player_nr].use_joystick = FALSE;
6817 setJoystickDeviceToNr(device_name, new_device_nr);
6820 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6824 if (setup.input[input_player_nr].use_joystick)
6825 ConfigureJoystick(input_player_nr);
6827 CustomizeKeyboard(input_player_nr);
6829 else if (y == pos_end)
6835 setup_mode = SETUP_MODE_MAIN;
6842 static boolean CustomizeKeyboardMain(int player_nr)
6846 boolean finished = FALSE;
6847 static struct SetupKeyboardInfo custom_key;
6852 } customize_step[] =
6854 { &custom_key.left, "Move Left" },
6855 { &custom_key.right, "Move Right" },
6856 { &custom_key.up, "Move Up" },
6857 { &custom_key.down, "Move Down" },
6858 { &custom_key.snap, "Snap Field" },
6859 { &custom_key.drop, "Drop Element" }
6861 int font_nr_old = FONT_VALUE_OLD;
6862 int font_nr_new = FONT_VALUE_1;
6863 boolean success = FALSE;
6865 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6867 font_nr_old = FONT_VALUE_OLD_NARROW;
6868 font_nr_new = FONT_VALUE_NARROW;
6871 /* read existing key bindings from player setup */
6872 custom_key = setup.input[player_nr].key;
6875 FadeOut(REDRAW_FIELD);
6879 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
6882 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6883 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6884 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6885 "Key:", FONT_INPUT_1_ACTIVE);
6886 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6887 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
6889 FadeIn(REDRAW_FIELD);
6895 if (NextValidEvent(&event))
6899 case EVENT_KEYPRESS:
6901 Key key = GetEventKey((KeyEvent *)&event, FALSE);
6903 /* press 'Escape' to abort and keep the old key bindings */
6904 if (key == KSYM_Escape)
6906 FadeSkipNextFadeIn();
6913 /* press 'Enter' to keep the existing key binding */
6914 if (key == KSYM_Return)
6915 key = *customize_step[step_nr].key;
6917 /* check if key already used */
6918 for (i = 0; i < step_nr; i++)
6919 if (*customize_step[i].key == key)
6924 /* got new key binding */
6925 *customize_step[step_nr].key = key;
6926 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6928 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6929 getKeyNameFromKey(key), font_nr_new);
6932 /* un-highlight last query */
6933 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
6934 customize_step[step_nr - 1].text, FONT_MENU_1);
6935 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
6936 "Key:", FONT_MENU_1);
6938 /* all keys configured */
6947 /* query next key binding */
6948 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
6949 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
6950 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
6951 "Key:", FONT_INPUT_1_ACTIVE);
6952 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
6953 getKeyNameFromKey(*customize_step[step_nr].key),
6958 case EVENT_KEYRELEASE:
6959 key_joystick_mapping = 0;
6963 HandleOtherEvents(&event);
6971 /* write new key bindings back to player setup, if successfully finished */
6973 setup.input[player_nr].key = custom_key;
6978 void CustomizeKeyboard(int player_nr)
6980 boolean success = CustomizeKeyboardMain(player_nr);
6984 int font_nr = FONT_TITLE_1;
6985 int font_height = getFontHeight(font_nr);
6986 int ypos1 = SYSIZE / 2 - font_height * 2;
6987 int ypos2 = SYSIZE / 2 - font_height * 1;
6988 unsigned int wait_frame_delay = 0;
6989 unsigned int wait_frame_delay_value = 2000;
6991 ResetDelayCounter(&wait_frame_delay);
6995 DrawTextSCentered(ypos1, font_nr, "Keyboard");
6996 DrawTextSCentered(ypos2, font_nr, "configured!");
6998 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7004 DrawSetupScreen_Input();
7007 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7009 #define MARKER_BUTTON 1
7010 #define MARKER_AXIS_X 2
7011 #define MARKER_AXIS_Y 3
7013 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7015 #if defined(TARGET_SDL2)
7016 static boolean bitmaps_initialized = FALSE;
7017 boolean screen_initialized = FALSE;
7018 static Bitmap *controller, *button, *axis_x, *axis_y;
7020 boolean success = TRUE;
7021 boolean done = FALSE, next = FALSE;
7023 int alpha = 200, alpha_step = -1;
7024 int alpha_ticks = 0;
7025 char mapping[4096], temp[4096];
7026 int font_name = MENU_SETUP_FONT_TITLE;
7027 int font_info = MENU_SETUP_FONT_TEXT;
7028 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7029 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7030 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7031 int ystep_name = getMenuTextStep(spacing_name, font_name);
7032 int ystep_line = getMenuTextStep(spacing_line, font_info);
7033 int ystep_para = getMenuTextStep(spacing_para, font_info);
7041 int axis, button, hat, hat_value;
7044 *step, *prev_step, steps[] =
7046 { 356, 155, MARKER_BUTTON, "a", },
7047 { 396, 122, MARKER_BUTTON, "b", },
7048 { 320, 125, MARKER_BUTTON, "x", },
7049 { 358, 95, MARKER_BUTTON, "y", },
7050 { 162, 125, MARKER_BUTTON, "back", },
7051 { 216, 125, MARKER_BUTTON, "guide", },
7052 { 271, 125, MARKER_BUTTON, "start", },
7053 { 110, 200, MARKER_BUTTON, "dpleft", },
7054 { 146, 228, MARKER_BUTTON, "dpdown", },
7055 { 178, 200, MARKER_BUTTON, "dpright", },
7056 { 146, 172, MARKER_BUTTON, "dpup", },
7057 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7058 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7059 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7060 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7061 { 73, 141, MARKER_BUTTON, "leftstick", },
7062 { 282, 210, MARKER_BUTTON, "rightstick", },
7063 { 73, 141, MARKER_AXIS_X, "leftx", },
7064 { 73, 141, MARKER_AXIS_Y, "lefty", },
7065 { 282, 210, MARKER_AXIS_X, "rightx", },
7066 { 282, 210, MARKER_AXIS_Y, "righty", },
7069 unsigned int event_frame_delay = 0;
7070 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7072 ResetDelayCounter(&event_frame_delay);
7074 if (!bitmaps_initialized)
7076 controller = LoadCustomImage("joystick/controller.png");
7077 button = LoadCustomImage("joystick/button.png");
7078 axis_x = LoadCustomImage("joystick/axis_x.png");
7079 axis_y = LoadCustomImage("joystick/axis_y.png");
7081 bitmaps_initialized = TRUE;
7084 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7087 /* print info about the joystick we are watching */
7088 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7089 SDL_JoystickInstanceID(joystick), name);
7090 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7091 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7092 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7095 /* initialize mapping with GUID and name */
7096 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7098 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7099 temp, name, SDL_GetPlatform());
7101 /* loop through all steps (buttons and axes), getting joystick events */
7102 for (i = 0; i < SDL_arraysize(steps) && !done;)
7104 Bitmap *marker = button; /* initialize with reliable default value */
7107 strcpy(step->mapping, mapping);
7111 step->hat_value = -1;
7113 marker = (step->marker == MARKER_BUTTON ? button :
7114 step->marker == MARKER_AXIS_X ? axis_x :
7115 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7119 while (!done && !next)
7121 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7122 alpha_ticks = SDL_GetTicks();
7129 else if (alpha < 128)
7135 int controller_x = SX + (SXSIZE - controller->width) / 2;
7136 int controller_y = SY + ystep_line;
7138 int marker_x = controller_x + step->x;
7139 int marker_y = controller_y + step->y;
7141 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7142 int ystart2 = ystart1 + ystep_name + ystep_line;
7146 DrawTextSCentered(ystart1, font_name, name);
7148 DrawTextSCentered(ystart2, font_info,
7149 "Press buttons and move axes on");
7150 ystart2 += ystep_line;
7151 DrawTextSCentered(ystart2, font_info,
7152 "your controller when indicated.");
7153 ystart2 += ystep_line;
7154 DrawTextSCentered(ystart2, font_info,
7155 "(Your controller may look different.)");
7156 ystart2 += ystep_para;
7158 #if defined(PLATFORM_ANDROID)
7159 DrawTextSCentered(ystart2, font_info,
7160 "To correct a mistake,");
7161 ystart2 += ystep_line;
7162 DrawTextSCentered(ystart2, font_info,
7163 "press the 'back' button.");
7164 ystart2 += ystep_line;
7165 DrawTextSCentered(ystart2, font_info,
7166 "To skip a button or axis,");
7167 ystart2 += ystep_line;
7168 DrawTextSCentered(ystart2, font_info,
7169 "press the 'menu' button.");
7171 DrawTextSCentered(ystart2, font_info,
7172 "To correct a mistake,");
7173 ystart2 += ystep_line;
7174 DrawTextSCentered(ystart2, font_info,
7175 "press the 'backspace' key.");
7176 ystart2 += ystep_line;
7177 DrawTextSCentered(ystart2, font_info,
7178 "To skip a button or axis,");
7179 ystart2 += ystep_line;
7180 DrawTextSCentered(ystart2, font_info,
7181 "press the 'return' key.");
7182 ystart2 += ystep_line;
7183 DrawTextSCentered(ystart2, font_info,
7184 "To exit, press the 'escape' key.");
7187 BlitBitmapMasked(controller, drawto, 0, 0,
7188 controller->width, controller->height,
7189 controller_x, controller_y);
7191 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7192 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7194 BlitBitmapMasked(marker, drawto, 0, 0,
7195 marker->width, marker->height,
7196 marker_x, marker_y);
7198 if (!screen_initialized)
7199 FadeIn(REDRAW_FIELD);
7203 screen_initialized = TRUE;
7205 while (NextValidEvent(&event))
7209 case SDL_JOYAXISMOTION:
7210 if (event.jaxis.value > 20000 ||
7211 event.jaxis.value < -20000)
7213 for (j = 0; j < i; j++)
7214 if (steps[j].axis == event.jaxis.axis)
7219 if (step->marker != MARKER_AXIS_X &&
7220 step->marker != MARKER_AXIS_Y)
7223 step->axis = event.jaxis.axis;
7224 strcat(mapping, step->field);
7225 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7226 strcat(mapping, temp);
7234 case SDL_JOYHATMOTION:
7235 /* ignore centering; we're probably just coming back
7236 to the center from the previous item we set */
7237 if (event.jhat.value == SDL_HAT_CENTERED)
7240 for (j = 0; j < i; j++)
7241 if (steps[j].hat == event.jhat.hat &&
7242 steps[j].hat_value == event.jhat.value)
7247 step->hat = event.jhat.hat;
7248 step->hat_value = event.jhat.value;
7249 strcat(mapping, step->field);
7250 snprintf(temp, sizeof(temp), ":h%u.%u,",
7251 event.jhat.hat, event.jhat.value );
7252 strcat(mapping, temp);
7259 case SDL_JOYBALLMOTION:
7262 case SDL_JOYBUTTONUP:
7263 for (j = 0; j < i; j++)
7264 if (steps[j].button == event.jbutton.button)
7269 step->button = event.jbutton.button;
7270 strcat(mapping, step->field);
7271 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7272 strcat(mapping, temp);
7279 case SDL_FINGERDOWN:
7280 case SDL_MOUSEBUTTONDOWN:
7281 /* skip this step */
7288 if (event.key.keysym.sym == KSYM_BackSpace ||
7289 event.key.keysym.sym == KSYM_Back)
7300 /* undo this step */
7301 prev_step = &steps[i - 1];
7302 strcpy(mapping, prev_step->mapping);
7309 if (event.key.keysym.sym == KSYM_space ||
7310 event.key.keysym.sym == KSYM_Return ||
7311 event.key.keysym.sym == KSYM_Menu)
7313 /* skip this step */
7320 if (event.key.keysym.sym == KSYM_Escape)
7330 program.exit_function(0);
7337 // do not handle events for longer than standard frame delay period
7338 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7347 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7350 // activate mapping for this game
7351 SDL_GameControllerAddMapping(mapping);
7353 // save mapping to personal mappings
7354 SaveSetup_AddGameControllerMapping(mapping);
7357 /* wait until the last pending event was removed from event queue */
7358 while (NextValidEvent(&event));
7366 static int ConfigureJoystickMain(int player_nr)
7368 char *device_name = setup.input[player_nr].joy.device_name;
7369 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7370 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7371 int success = FALSE;
7374 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7375 return JOYSTICK_NOT_AVAILABLE;
7377 if (!joystick_active || !setup.input[player_nr].use_joystick)
7378 return JOYSTICK_NOT_AVAILABLE;
7381 FadeOut(REDRAW_FIELD);
7383 // close all joystick devices (potentially opened as game controllers)
7384 for (i = 0; i < SDL_NumJoysticks(); i++)
7385 SDLCloseJoystick(i);
7387 // open joystick device as plain joystick to configure as game controller
7388 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7390 // as the joystick was successfully opened before, this should not happen
7391 if (joystick == NULL)
7394 // create new game controller mapping (buttons and axes) for joystick device
7395 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7397 // close joystick (and maybe re-open as configured game controller later)
7398 SDL_JoystickClose(joystick);
7400 // re-open all joystick devices (potentially as game controllers)
7401 for (i = 0; i < SDL_NumJoysticks(); i++)
7404 // clear all joystick input actions for all joystick devices
7405 SDLClearJoystickState();
7407 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7410 void ConfigureJoystick(int player_nr)
7412 boolean state = ConfigureJoystickMain(player_nr);
7414 if (state != JOYSTICK_NOT_CONFIGURED)
7416 boolean success = (state == JOYSTICK_CONFIGURED);
7417 char message1[MAX_OUTPUT_LINESIZE + 1];
7418 char *message2 = (success ? "configured!" : "not available!");
7419 char *device_name = setup.input[player_nr].joy.device_name;
7420 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7421 int font_nr = FONT_TITLE_1;
7422 int font_height = getFontHeight(font_nr);
7423 int ypos1 = SYSIZE / 2 - font_height * 2;
7424 int ypos2 = SYSIZE / 2 - font_height * 1;
7425 unsigned int wait_frame_delay = 0;
7426 unsigned int wait_frame_delay_value = 2000;
7428 ResetDelayCounter(&wait_frame_delay);
7432 sprintf(message1, "Joystick %d", nr);
7434 DrawTextSCentered(ypos1, font_nr, message1);
7435 DrawTextSCentered(ypos2, font_nr, message2);
7437 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7443 DrawSetupScreen_Input();
7446 boolean ConfigureVirtualButtonsMain()
7448 static char *customize_step_text[] =
7457 char grid_button[] =
7459 CHAR_GRID_BUTTON_LEFT,
7460 CHAR_GRID_BUTTON_RIGHT,
7461 CHAR_GRID_BUTTON_UP,
7462 CHAR_GRID_BUTTON_DOWN,
7463 CHAR_GRID_BUTTON_SNAP,
7464 CHAR_GRID_BUTTON_DROP
7466 int font_nr = FONT_INPUT_1_ACTIVE;
7467 int font_height = getFontHeight(font_nr);
7468 int ypos1 = SYSIZE / 2 - font_height * 2;
7469 int ypos2 = SYSIZE / 2 - font_height * 1;
7470 boolean success = FALSE;
7471 boolean finished = FALSE;
7473 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7474 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7475 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7476 boolean set_grid_button = FALSE;
7477 int nr = GRID_ACTIVE_NR();
7480 for (x = 0; x < MAX_GRID_XSIZE; x++)
7481 for (y = 0; y < MAX_GRID_YSIZE; y++)
7482 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7484 overlay.grid_button_highlight = grid_button[step_nr];
7487 FadeOut(REDRAW_FIELD);
7491 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7492 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7493 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7495 FadeIn(REDRAW_FIELD);
7497 SetOverlayShowGrid(TRUE);
7503 while (NextValidEvent(&event))
7507 case EVENT_KEYPRESS:
7509 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7511 /* press 'Escape' to abort and keep the old key bindings */
7512 if (key == KSYM_Escape)
7514 for (x = 0; x < MAX_GRID_XSIZE; x++)
7515 for (y = 0; y < MAX_GRID_YSIZE; y++)
7516 overlay.grid_button[x][y] = grid_button_old[x][y];
7518 FadeSkipNextFadeIn();
7525 /* press 'Enter' to keep the existing key binding */
7526 if (key == KSYM_Return ||
7532 else if (key == KSYM_BackSpace ||
7537 FadeSkipNextFadeIn();
7551 /* all virtual buttons configured */
7560 for (x = 0; x < MAX_GRID_XSIZE; x++)
7561 for (y = 0; y < MAX_GRID_YSIZE; y++)
7562 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7564 overlay.grid_button_highlight = grid_button[step_nr];
7566 /* query next virtual button */
7570 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7571 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7572 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7576 case EVENT_KEYRELEASE:
7577 key_joystick_mapping = 0;
7580 case EVENT_BUTTONPRESS:
7581 case EVENT_BUTTONRELEASE:
7583 ButtonEvent *button = (ButtonEvent *)&event;
7585 button->x += video.screen_xoffset;
7586 button->y += video.screen_yoffset;
7588 x = button->x * overlay.grid_xsize / video.screen_width;
7589 y = button->y * overlay.grid_ysize / video.screen_height;
7591 if (button->type == EVENT_BUTTONPRESS)
7593 button_status = button->button;
7596 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7597 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7599 set_grid_button = TRUE;
7603 button_status = MB_RELEASED;
7608 case EVENT_MOTIONNOTIFY:
7610 MotionEvent *motion = (MotionEvent *)&event;
7612 motion->x += video.screen_xoffset;
7613 motion->y += video.screen_yoffset;
7615 x = motion->x * overlay.grid_xsize / video.screen_width;
7616 y = motion->y * overlay.grid_ysize / video.screen_height;
7618 set_grid_button = TRUE;
7622 #if defined(TARGET_SDL2)
7623 case SDL_WINDOWEVENT:
7624 HandleWindowEvent((WindowEvent *) &event);
7626 // check if device has been rotated
7627 if (nr != GRID_ACTIVE_NR())
7629 nr = GRID_ACTIVE_NR();
7631 for (x = 0; x < MAX_GRID_XSIZE; x++)
7632 for (y = 0; y < MAX_GRID_YSIZE; y++)
7633 grid_button_old[x][y] = grid_button_tmp[x][y] =
7634 overlay.grid_button[x][y];
7639 case SDL_APP_WILLENTERBACKGROUND:
7640 case SDL_APP_DIDENTERBACKGROUND:
7641 case SDL_APP_WILLENTERFOREGROUND:
7642 case SDL_APP_DIDENTERFOREGROUND:
7643 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7648 HandleOtherEvents(&event);
7652 if (set_grid_button)
7654 overlay.grid_button[x][y] =
7655 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7656 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7657 grid_button_tmp[x][y]);
7659 set_grid_button = FALSE;
7666 for (x = 0; x < MAX_GRID_XSIZE; x++)
7667 for (y = 0; y < MAX_GRID_YSIZE; y++)
7668 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7670 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7672 SetOverlayShowGrid(FALSE);
7677 void ConfigureVirtualButtons()
7679 boolean success = ConfigureVirtualButtonsMain();
7683 int font_nr = FONT_TITLE_1;
7684 int font_height = getFontHeight(font_nr);
7685 int ypos1 = SYSIZE / 2 - font_height * 2;
7686 int ypos2 = SYSIZE / 2 - font_height * 1;
7687 unsigned int wait_frame_delay = 0;
7688 unsigned int wait_frame_delay_value = 2000;
7690 ResetDelayCounter(&wait_frame_delay);
7694 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7695 DrawTextSCentered(ypos2, font_nr, "configured!");
7697 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7704 void DrawSetupScreen()
7706 if (setup_mode == SETUP_MODE_INPUT)
7707 DrawSetupScreen_Input();
7708 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7709 DrawChooseTree(&game_speed_current);
7710 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7711 DrawChooseTree(&scroll_delay_current);
7712 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7713 DrawChooseTree(&snapshot_mode_current);
7714 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7715 DrawChooseTree(&window_size_current);
7716 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7717 DrawChooseTree(&scaling_type_current);
7718 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7719 DrawChooseTree(&rendering_mode_current);
7720 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7721 DrawChooseTree(&artwork.gfx_current);
7722 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7723 DrawChooseTree(&artwork.snd_current);
7724 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7725 DrawChooseTree(&artwork.mus_current);
7726 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7727 DrawChooseTree(&volume_simple_current);
7728 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7729 DrawChooseTree(&volume_loops_current);
7730 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7731 DrawChooseTree(&volume_music_current);
7732 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7733 DrawChooseTree(&touch_control_current);
7734 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7735 DrawChooseTree(&move_distance_current);
7736 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7737 DrawChooseTree(&drop_distance_current);
7738 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7739 DrawChooseTree(&transparency_current);
7740 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7741 DrawChooseTree(&grid_size_current[0][0]);
7742 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7743 DrawChooseTree(&grid_size_current[0][1]);
7744 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7745 DrawChooseTree(&grid_size_current[1][0]);
7746 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7747 DrawChooseTree(&grid_size_current[1][1]);
7749 DrawSetupScreen_Generic();
7751 PlayMenuSoundsAndMusic();
7754 void RedrawSetupScreenAfterFullscreenToggle()
7756 if (setup_mode == SETUP_MODE_GRAPHICS ||
7757 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7759 // update list selection from "setup.window_scaling_percent"
7760 execSetupGraphics_setWindowSizes(TRUE);
7766 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7768 if (setup_mode == SETUP_MODE_INPUT)
7769 HandleSetupScreen_Input(mx, my, dx, dy, button);
7770 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7771 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7772 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7773 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7774 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7775 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
7776 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7777 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
7778 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7779 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
7780 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7781 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
7782 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7783 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
7784 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7785 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
7786 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7787 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
7788 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7789 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
7790 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7791 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
7792 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7793 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
7794 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7795 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
7796 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7797 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
7798 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7799 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
7800 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7801 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
7802 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7803 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
7804 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7805 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
7806 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7807 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
7808 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7809 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
7811 HandleSetupScreen_Generic(mx, my, dx, dy, button);
7814 void HandleGameActions()
7816 if (game.restart_game_message != NULL)
7817 RequestRestartGame(game.restart_game_message);
7819 if (game_status != GAME_MODE_PLAYING)
7822 GameActions(); /* main game loop */
7824 if (tape.auto_play && !tape.playing)
7825 AutoPlayTape(); /* continue automatically playing next tape */
7829 /* ---------- new screen button stuff -------------------------------------- */
7831 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
7835 case SCREEN_CTRL_ID_PREV_LEVEL:
7836 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
7837 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
7840 case SCREEN_CTRL_ID_NEXT_LEVEL:
7841 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
7842 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
7845 case SCREEN_CTRL_ID_PREV_PLAYER:
7846 *x = mSX + TILEX * 10;
7847 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7850 case SCREEN_CTRL_ID_NEXT_PLAYER:
7851 *x = mSX + TILEX * 12;
7852 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
7856 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
7862 int gfx_unpressed, gfx_pressed;
7863 void (*get_gadget_position)(int *, int *, int);
7867 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
7870 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
7871 getScreenMenuButtonPos,
7872 SCREEN_CTRL_ID_PREV_LEVEL,
7877 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
7878 getScreenMenuButtonPos,
7879 SCREEN_CTRL_ID_NEXT_LEVEL,
7884 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
7885 getScreenMenuButtonPos,
7886 SCREEN_CTRL_ID_PREV_PLAYER,
7891 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
7892 getScreenMenuButtonPos,
7893 SCREEN_CTRL_ID_NEXT_PLAYER,
7901 int gfx_unpressed, gfx_pressed;
7905 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
7908 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
7909 -1, -1, /* these values are not constant, but can change at runtime */
7910 SCREEN_CTRL_ID_SCROLL_UP,
7914 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
7915 -1, -1, /* these values are not constant, but can change at runtime */
7916 SCREEN_CTRL_ID_SCROLL_DOWN,
7923 int gfx_unpressed, gfx_pressed;
7929 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
7932 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
7933 -1, -1, /* these values are not constant, but can change at runtime */
7934 -1, -1, /* these values are not constant, but can change at runtime */
7935 GD_TYPE_SCROLLBAR_VERTICAL,
7936 SCREEN_CTRL_ID_SCROLL_VERTICAL,
7937 "scroll level series vertically"
7941 static void CreateScreenMenubuttons()
7943 struct GadgetInfo *gi;
7944 unsigned int event_mask;
7947 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
7949 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
7950 int gfx_unpressed, gfx_pressed;
7951 int x, y, width, height;
7952 int gd_x1, gd_x2, gd_y1, gd_y2;
7953 int id = menubutton_info[i].gadget_id;
7955 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
7957 menubutton_info[i].get_gadget_position(&x, &y, id);
7959 width = SC_MENUBUTTON_XSIZE;
7960 height = SC_MENUBUTTON_YSIZE;
7962 gfx_unpressed = menubutton_info[i].gfx_unpressed;
7963 gfx_pressed = menubutton_info[i].gfx_pressed;
7964 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
7965 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
7966 gd_x1 = graphic_info[gfx_unpressed].src_x;
7967 gd_y1 = graphic_info[gfx_unpressed].src_y;
7968 gd_x2 = graphic_info[gfx_pressed].src_x;
7969 gd_y2 = graphic_info[gfx_pressed].src_y;
7971 gi = CreateGadget(GDI_CUSTOM_ID, id,
7972 GDI_CUSTOM_TYPE_ID, i,
7973 GDI_INFO_TEXT, menubutton_info[i].infotext,
7978 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
7979 GDI_STATE, GD_BUTTON_UNPRESSED,
7980 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
7981 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
7982 GDI_DIRECT_DRAW, FALSE,
7983 GDI_EVENT_MASK, event_mask,
7984 GDI_CALLBACK_ACTION, HandleScreenGadgets,
7988 Error(ERR_EXIT, "cannot create gadget");
7990 screen_gadget[id] = gi;
7994 static void CreateScreenScrollbuttons()
7996 struct GadgetInfo *gi;
7997 unsigned int event_mask;
8000 /* these values are not constant, but can change at runtime */
8001 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8002 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8003 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8004 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8006 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8008 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8009 int gfx_unpressed, gfx_pressed;
8010 int x, y, width, height;
8011 int gd_x1, gd_x2, gd_y1, gd_y2;
8012 int id = scrollbutton_info[i].gadget_id;
8014 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8016 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8017 y = mSY + scrollbutton_info[i].y;
8018 width = SC_SCROLLBUTTON_XSIZE;
8019 height = SC_SCROLLBUTTON_YSIZE;
8021 /* correct scrollbar position if placed outside menu (playfield) area */
8022 if (x > SX + SC_SCROLL_UP_XPOS)
8023 x = SX + SC_SCROLL_UP_XPOS;
8025 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8026 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8027 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8029 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8030 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8031 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8032 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8033 gd_x1 = graphic_info[gfx_unpressed].src_x;
8034 gd_y1 = graphic_info[gfx_unpressed].src_y;
8035 gd_x2 = graphic_info[gfx_pressed].src_x;
8036 gd_y2 = graphic_info[gfx_pressed].src_y;
8038 gi = CreateGadget(GDI_CUSTOM_ID, id,
8039 GDI_CUSTOM_TYPE_ID, i,
8040 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8045 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8046 GDI_STATE, GD_BUTTON_UNPRESSED,
8047 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8048 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8049 GDI_DIRECT_DRAW, FALSE,
8050 GDI_EVENT_MASK, event_mask,
8051 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8055 Error(ERR_EXIT, "cannot create gadget");
8057 screen_gadget[id] = gi;
8061 static void CreateScreenScrollbars()
8065 /* these values are not constant, but can change at runtime */
8066 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8067 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8068 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8069 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8071 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8073 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8074 int gfx_unpressed, gfx_pressed;
8075 int x, y, width, height;
8076 int gd_x1, gd_x2, gd_y1, gd_y2;
8077 struct GadgetInfo *gi;
8078 int items_max, items_visible, item_position;
8079 unsigned int event_mask;
8080 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8081 int id = scrollbar_info[i].gadget_id;
8083 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8085 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8086 y = mSY + scrollbar_info[i].y;
8087 width = scrollbar_info[i].width;
8088 height = scrollbar_info[i].height;
8090 /* correct scrollbar position if placed outside menu (playfield) area */
8091 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8092 x = SX + SC_SCROLL_VERTICAL_XPOS;
8094 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8095 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8097 items_max = num_page_entries;
8098 items_visible = num_page_entries;
8101 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8102 gfx_pressed = scrollbar_info[i].gfx_pressed;
8103 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8104 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8105 gd_x1 = graphic_info[gfx_unpressed].src_x;
8106 gd_y1 = graphic_info[gfx_unpressed].src_y;
8107 gd_x2 = graphic_info[gfx_pressed].src_x;
8108 gd_y2 = graphic_info[gfx_pressed].src_y;
8110 gi = CreateGadget(GDI_CUSTOM_ID, id,
8111 GDI_CUSTOM_TYPE_ID, i,
8112 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8117 GDI_TYPE, scrollbar_info[i].type,
8118 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8119 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8120 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8121 GDI_WHEEL_AREA_X, SX,
8122 GDI_WHEEL_AREA_Y, SY,
8123 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8124 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8125 GDI_STATE, GD_BUTTON_UNPRESSED,
8126 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8127 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8128 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8129 GDI_DIRECT_DRAW, FALSE,
8130 GDI_EVENT_MASK, event_mask,
8131 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8135 Error(ERR_EXIT, "cannot create gadget");
8137 screen_gadget[id] = gi;
8141 void CreateScreenGadgets()
8143 CreateScreenMenubuttons();
8145 CreateScreenScrollbuttons();
8146 CreateScreenScrollbars();
8149 void FreeScreenGadgets()
8153 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8154 FreeGadget(screen_gadget[i]);
8157 void MapScreenMenuGadgets(int screen_mask)
8161 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8162 if (screen_mask & menubutton_info[i].screen_mask)
8163 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8166 void MapScreenGadgets(int num_entries)
8170 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8173 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8174 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8176 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8177 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8180 void MapScreenTreeGadgets(TreeInfo *ti)
8182 MapScreenGadgets(numTreeInfoInGroup(ti));
8185 static void HandleScreenGadgets(struct GadgetInfo *gi)
8187 int id = gi->custom_id;
8188 int button = gi->event.button;
8189 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
8193 case SCREEN_CTRL_ID_PREV_LEVEL:
8194 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8197 case SCREEN_CTRL_ID_NEXT_LEVEL:
8198 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8201 case SCREEN_CTRL_ID_PREV_PLAYER:
8202 HandleSetupScreen_Input_Player(step, -1);
8205 case SCREEN_CTRL_ID_NEXT_PLAYER:
8206 HandleSetupScreen_Input_Player(step, +1);
8209 case SCREEN_CTRL_ID_SCROLL_UP:
8210 if (game_status == GAME_MODE_LEVELS)
8211 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8212 else if (game_status == GAME_MODE_LEVELNR)
8213 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8214 else if (game_status == GAME_MODE_SETUP)
8215 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8216 else if (game_status == GAME_MODE_INFO)
8217 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8220 case SCREEN_CTRL_ID_SCROLL_DOWN:
8221 if (game_status == GAME_MODE_LEVELS)
8222 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8223 else if (game_status == GAME_MODE_LEVELNR)
8224 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8225 else if (game_status == GAME_MODE_SETUP)
8226 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8227 else if (game_status == GAME_MODE_INFO)
8228 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8231 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8232 if (game_status == GAME_MODE_LEVELS)
8233 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8234 else if (game_status == GAME_MODE_LEVELNR)
8235 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8236 else if (game_status == GAME_MODE_SETUP)
8237 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8238 else if (game_status == GAME_MODE_INFO)
8239 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);