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_VSYNC 22
72 #define SETUP_MODE_CHOOSE_GRAPHICS 23
73 #define SETUP_MODE_CHOOSE_SOUNDS 24
74 #define SETUP_MODE_CHOOSE_MUSIC 25
75 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 26
76 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 27
77 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 28
78 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 29
79 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 30
80 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_TRANSPARENCY 32
82 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 33
83 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 35
85 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 36
86 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 37
88 #define MAX_SETUP_MODES 38
90 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
92 /* setup screen titles */
93 #define STR_SETUP_MAIN "Setup"
94 #define STR_SETUP_GAME "Game & Menu"
95 #define STR_SETUP_EDITOR "Editor"
96 #define STR_SETUP_GRAPHICS "Graphics"
97 #define STR_SETUP_SOUND "Sound & Music"
98 #define STR_SETUP_ARTWORK "Custom Artwork"
99 #define STR_SETUP_INPUT "Input Devices"
100 #define STR_SETUP_TOUCH "Touch Controls"
101 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
102 #define STR_SETUP_EXIT "Exit"
103 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
105 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
106 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
107 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
108 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
109 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
110 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
111 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
112 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
113 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
114 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
115 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
116 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
117 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
118 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
119 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
120 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
124 /* for input setup functions */
125 #define SETUPINPUT_SCREEN_POS_START 0
126 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
127 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
128 #define SETUPINPUT_SCREEN_POS_END 13
130 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
131 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
133 /* for various menu stuff */
134 #define MENU_SCREEN_START_XPOS 1
135 #define MENU_SCREEN_START_YPOS 2
136 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
137 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
138 #define MENU_TITLE1_YPOS 8
139 #define MENU_TITLE2_YPOS 46
140 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
141 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
142 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
143 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
144 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
145 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
146 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
147 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
148 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
149 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
150 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
151 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
152 MENU_INFO_FONT_TITLE))
153 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
154 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
155 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
156 MENU_SCREEN_INFO_YSTART2 - \
158 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
159 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
160 MENU_SCREEN_INFO_YSTEP)
161 #define NUM_INFO_ELEMENTS_FROM_CONF \
162 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
163 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
164 MAX_MENU_ENTRIES_ON_SCREEN)
165 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
166 MAX_INFO_ELEMENTS_ON_SCREEN), \
167 NUM_INFO_ELEMENTS_FROM_CONF)
168 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
169 #define MAX_MENU_TEXT_LENGTH_BIG 13
170 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
172 /* buttons and scrollbars identifiers */
173 #define SCREEN_CTRL_ID_PREV_LEVEL 0
174 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
175 #define SCREEN_CTRL_ID_PREV_PLAYER 2
176 #define SCREEN_CTRL_ID_NEXT_PLAYER 3
177 #define SCREEN_CTRL_ID_INSERT_SOLUTION 4
178 #define SCREEN_CTRL_ID_PLAY_SOLUTION 5
179 #define SCREEN_CTRL_ID_SCROLL_UP 6
180 #define SCREEN_CTRL_ID_SCROLL_DOWN 7
181 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 8
183 #define NUM_SCREEN_GADGETS 9
185 #define NUM_SCREEN_MENUBUTTONS 6
186 #define NUM_SCREEN_SCROLLBUTTONS 2
187 #define NUM_SCREEN_SCROLLBARS 1
189 #define SCREEN_MASK_MAIN (1 << 0)
190 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
191 #define SCREEN_MASK_INPUT (1 << 2)
193 /* graphic position and size values for buttons and scrollbars */
194 #define SC_MENUBUTTON_XSIZE TILEX
195 #define SC_MENUBUTTON_YSIZE TILEY
197 #define SC_SCROLLBUTTON_XSIZE TILEX
198 #define SC_SCROLLBUTTON_YSIZE TILEY
200 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
202 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
203 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
204 SC_SCROLLBUTTON_YSIZE)
206 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
207 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
209 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
210 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
211 SC_SCROLLBUTTON_YSIZE)
213 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
214 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
215 SC_SCROLL_VERTICAL_YSIZE)
217 #define SC_BORDER_SIZE 14
220 /* forward declarations of internal functions */
221 static void HandleScreenGadgets(struct GadgetInfo *);
222 static void HandleSetupScreen_Generic(int, int, int, int, int);
223 static void HandleSetupScreen_Input(int, int, int, int, int);
224 static void CustomizeKeyboard(int);
225 static void ConfigureJoystick(int);
226 static void ConfigureVirtualButtons(void);
227 static void execSetupGame(void);
228 static void execSetupGraphics(void);
229 static void execSetupSound(void);
230 static void execSetupTouch(void);
231 static void execSetupArtwork(void);
232 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
234 static void DrawChooseLevelSet(void);
235 static void DrawChooseLevelNr(void);
236 static void DrawInfoScreen(void);
237 static void DrawSetupScreen(void);
239 static void DrawInfoScreen_NotAvailable(char *, char *);
240 static void DrawInfoScreen_HelpAnim(int, int, boolean);
241 static void DrawInfoScreen_HelpText(int, int, int, int);
242 static void HandleInfoScreen_Main(int, int, int, int, int);
243 static void HandleInfoScreen_TitleScreen(int);
244 static void HandleInfoScreen_Elements(int);
245 static void HandleInfoScreen_Music(int);
246 static void HandleInfoScreen_Credits(int);
247 static void HandleInfoScreen_Program(int);
248 static void HandleInfoScreen_Version(int);
250 static void MapScreenMenuGadgets(int);
251 static void MapScreenGadgets(int);
252 static void MapScreenTreeGadgets(TreeInfo *);
254 static void UpdateScreenMenuGadgets(int, boolean);
256 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
258 static int info_mode = INFO_MODE_MAIN;
259 static int setup_mode = SETUP_MODE_MAIN;
261 static TreeInfo *window_sizes = NULL;
262 static TreeInfo *window_size_current = NULL;
264 static TreeInfo *scaling_types = NULL;
265 static TreeInfo *scaling_type_current = NULL;
267 static TreeInfo *rendering_modes = NULL;
268 static TreeInfo *rendering_mode_current = NULL;
270 static TreeInfo *vsync_modes = NULL;
271 static TreeInfo *vsync_mode_current = NULL;
273 static TreeInfo *scroll_delays = NULL;
274 static TreeInfo *scroll_delay_current = NULL;
276 static TreeInfo *snapshot_modes = NULL;
277 static TreeInfo *snapshot_mode_current = NULL;
279 static TreeInfo *game_speeds = NULL;
280 static TreeInfo *game_speed_current = NULL;
282 static TreeInfo *volumes_simple = NULL;
283 static TreeInfo *volume_simple_current = NULL;
285 static TreeInfo *volumes_loops = NULL;
286 static TreeInfo *volume_loops_current = NULL;
288 static TreeInfo *volumes_music = NULL;
289 static TreeInfo *volume_music_current = NULL;
291 static TreeInfo *touch_controls = NULL;
292 static TreeInfo *touch_control_current = NULL;
294 static TreeInfo *move_distances = NULL;
295 static TreeInfo *move_distance_current = NULL;
297 static TreeInfo *drop_distances = NULL;
298 static TreeInfo *drop_distance_current = NULL;
300 static TreeInfo *transparencies = NULL;
301 static TreeInfo *transparency_current = NULL;
303 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
304 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
306 static TreeInfo *level_number = NULL;
307 static TreeInfo *level_number_current = NULL;
313 } window_sizes_list[] =
318 { 100, "100 % (Default)" },
335 } scaling_types_list[] =
337 { SCALING_QUALITY_NEAREST, "Off" },
338 { SCALING_QUALITY_LINEAR, "Linear" },
339 { SCALING_QUALITY_BEST, "Anisotropic" },
348 } rendering_modes_list[] =
350 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
351 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
353 // this mode may work under certain conditions, but does not work on Windows
354 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
356 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
365 } vsync_modes_list[] =
367 { STR_VSYNC_MODE_OFF, "Off" },
368 { STR_VSYNC_MODE_NORMAL, "Normal" },
369 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
378 } game_speeds_list[] =
387 { 1000, "1/1s (Extremely Slow)" },
392 { 29, "1/35s (Original Supaplex)" },
394 { 20, "1/50s (Normal Speed)" },
395 { 14, "1/70s (Maximum Supaplex)" },
399 { 1, "1/1000s (Extremely Fast)" },
409 } scroll_delays_list[] =
411 { 0, "0 Tiles (No Scroll Delay)" },
414 { 3, "3 Tiles (Default)" },
419 { 8, "8 Tiles (Maximum Scroll Delay)"},
428 } snapshot_modes_list[] =
430 { STR_SNAPSHOT_MODE_OFF, "Off" },
431 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
432 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
433 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
466 } touch_controls_list[] =
468 { TOUCH_CONTROL_OFF, "Off" },
469 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
470 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
471 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
499 } transparencies_list[] =
501 { 0, "0 % (Opaque)" },
511 { 100, "100 % (Invisible)" },
520 } grid_sizes_list[] =
556 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
557 (s) <= GAME_MODE_SETUP ? (s) : \
558 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
559 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
561 /* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
562 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
563 (i) <= INFO_MODE_LEVELSET ? (i) : \
566 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
567 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
568 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
569 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
570 SETUP_MODE_CHOOSE_ARTWORK : \
571 SETUP_MODE_CHOOSE_OTHER)
573 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
574 menu.draw_xoffset[GAME_MODE_INFO] : \
575 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
576 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
577 menu.draw_yoffset[GAME_MODE_INFO] : \
578 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
579 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
580 menu.extra_spacing[GAME_MODE_INFO] : \
581 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
583 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
584 menu.draw_xoffset[GAME_MODE_SETUP] : \
585 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
586 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
587 menu.draw_yoffset[GAME_MODE_SETUP] : \
588 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
589 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
590 menu.extra_spacing[GAME_MODE_SETUP] : \
591 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
593 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
594 DRAW_XOFFSET_INFO(info_mode) : \
595 (s) == GAME_MODE_SETUP ? \
596 DRAW_XOFFSET_SETUP(setup_mode) : \
597 menu.draw_xoffset[DRAW_MODE(s)])
598 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
599 DRAW_YOFFSET_INFO(info_mode) : \
600 (s) == GAME_MODE_SETUP ? \
601 DRAW_YOFFSET_SETUP(setup_mode) : \
602 menu.draw_yoffset[DRAW_MODE(s)])
603 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
604 EXTRA_SPACING_INFO(info_mode) : \
605 (s) == GAME_MODE_SETUP ? \
606 EXTRA_SPACING_SETUP(setup_mode) : \
607 menu.extra_spacing[DRAW_MODE(s)])
609 #define mSX (SX + DRAW_XOFFSET(game_status))
610 #define mSY (SY + DRAW_YOFFSET(game_status))
612 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
613 menu.list_size[game_status] : \
614 MAX_MENU_ENTRIES_ON_SCREEN)
616 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
617 NUM_MENU_ENTRIES_ON_SCREEN)
620 /* title display and control definitions */
622 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
623 2 * MAX_NUM_TITLE_MESSAGES)
625 #define NO_DIRECT_LEVEL_SELECT (-1)
628 static int num_title_screens = 0;
630 struct TitleControlInfo
639 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
641 /* main menu display and control definitions */
643 #define MAIN_CONTROL_NAME 0
644 #define MAIN_CONTROL_LEVELS 1
645 #define MAIN_CONTROL_SCORES 2
646 #define MAIN_CONTROL_EDITOR 3
647 #define MAIN_CONTROL_INFO 4
648 #define MAIN_CONTROL_GAME 5
649 #define MAIN_CONTROL_SETUP 6
650 #define MAIN_CONTROL_QUIT 7
651 #define MAIN_CONTROL_PREV_LEVEL 8
652 #define MAIN_CONTROL_NEXT_LEVEL 9
653 #define MAIN_CONTROL_FIRST_LEVEL 10
654 #define MAIN_CONTROL_LAST_LEVEL 11
655 #define MAIN_CONTROL_LEVEL_NUMBER 12
656 #define MAIN_CONTROL_LEVEL_INFO_1 13
657 #define MAIN_CONTROL_LEVEL_INFO_2 14
658 #define MAIN_CONTROL_LEVEL_NAME 15
659 #define MAIN_CONTROL_LEVEL_AUTHOR 16
660 #define MAIN_CONTROL_LEVEL_YEAR 17
661 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
662 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
663 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
664 #define MAIN_CONTROL_TITLE_1 21
665 #define MAIN_CONTROL_TITLE_2 22
666 #define MAIN_CONTROL_TITLE_3 23
668 static char str_main_text_name[10];
669 static char str_main_text_first_level[10];
670 static char str_main_text_last_level[10];
671 static char str_main_text_level_number[10];
673 static char *main_text_name = str_main_text_name;
674 static char *main_text_first_level = str_main_text_first_level;
675 static char *main_text_last_level = str_main_text_last_level;
676 static char *main_text_level_number = str_main_text_level_number;
677 static char *main_text_levels = "Levelset";
678 static char *main_text_scores = "Hall Of Fame";
679 static char *main_text_editor = "Level Creator";
680 static char *main_text_info = "Info Screen";
681 static char *main_text_game = "Start Game";
682 static char *main_text_setup = "Setup";
683 static char *main_text_quit = "Quit";
684 static char *main_text_level_name = level.name;
685 static char *main_text_level_author = level.author;
686 static char *main_text_level_year = NULL;
687 static char *main_text_level_imported_from = NULL;
688 static char *main_text_level_imported_by = NULL;
689 static char *main_text_level_tested_by = NULL;
690 static char *main_text_title_1 = NULL;
691 static char *main_text_title_2 = NULL;
692 static char *main_text_title_3 = NULL;
694 struct MainControlInfo
698 struct MenuPosInfo *pos_button;
701 struct TextPosInfo *pos_text;
704 struct TextPosInfo *pos_input;
708 static struct MainControlInfo main_controls[] =
712 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
713 &menu.main.text.name, &main_text_name,
714 &menu.main.input.name, &setup.player_name,
718 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
719 &menu.main.text.levels, &main_text_levels,
724 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
725 &menu.main.text.scores, &main_text_scores,
730 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
731 &menu.main.text.editor, &main_text_editor,
736 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
737 &menu.main.text.info, &main_text_info,
742 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
743 &menu.main.text.game, &main_text_game,
748 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
749 &menu.main.text.setup, &main_text_setup,
754 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
755 &menu.main.text.quit, &main_text_quit,
759 /* (these two buttons are real gadgets) */
761 MAIN_CONTROL_PREV_LEVEL,
762 &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
767 MAIN_CONTROL_NEXT_LEVEL,
768 &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
774 MAIN_CONTROL_FIRST_LEVEL,
775 &menu.main.button.first_level, IMG_MENU_BUTTON_FIRST_LEVEL,
776 &menu.main.text.first_level, &main_text_first_level,
780 MAIN_CONTROL_LAST_LEVEL,
781 &menu.main.button.last_level, IMG_MENU_BUTTON_LAST_LEVEL,
782 &menu.main.text.last_level, &main_text_last_level,
786 MAIN_CONTROL_LEVEL_NUMBER,
787 &menu.main.button.level_number, IMG_MENU_BUTTON_LEVEL_NUMBER,
788 &menu.main.text.level_number, &main_text_level_number,
792 MAIN_CONTROL_LEVEL_INFO_1,
794 &menu.main.text.level_info_1, NULL,
798 MAIN_CONTROL_LEVEL_INFO_2,
800 &menu.main.text.level_info_2, NULL,
804 MAIN_CONTROL_LEVEL_NAME,
806 &menu.main.text.level_name, &main_text_level_name,
810 MAIN_CONTROL_LEVEL_AUTHOR,
812 &menu.main.text.level_author, &main_text_level_author,
816 MAIN_CONTROL_LEVEL_YEAR,
818 &menu.main.text.level_year, &main_text_level_year,
822 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
824 &menu.main.text.level_imported_from, &main_text_level_imported_from,
828 MAIN_CONTROL_LEVEL_IMPORTED_BY,
830 &menu.main.text.level_imported_by, &main_text_level_imported_by,
834 MAIN_CONTROL_LEVEL_TESTED_BY,
836 &menu.main.text.level_tested_by, &main_text_level_tested_by,
840 MAIN_CONTROL_TITLE_1,
842 &menu.main.text.title_1, &main_text_title_1,
846 MAIN_CONTROL_TITLE_2,
848 &menu.main.text.title_2, &main_text_title_2,
852 MAIN_CONTROL_TITLE_3,
854 &menu.main.text.title_3, &main_text_title_3,
867 static int getTitleScreenGraphic(int nr, boolean initial)
869 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
872 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
874 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
878 static int getTitleScreenGameMode(boolean initial)
880 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
884 static int getTitleMessageGameMode(boolean initial)
886 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
889 static int getTitleAnimMode(struct TitleControlInfo *tci)
891 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
893 return base + tci->local_nr;
897 static int getTitleScreenBackground(boolean initial)
899 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
904 static int getTitleMessageBackground(int nr, boolean initial)
906 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
910 static int getTitleBackground(int nr, boolean initial, boolean is_image)
912 int base = (is_image ?
913 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
914 IMG_BACKGROUND_TITLESCREEN_1) :
915 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
916 IMG_BACKGROUND_TITLEMESSAGE_1));
917 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
918 IMG_BACKGROUND_TITLE);
919 int graphic_local = base + nr;
921 if (graphic_info[graphic_local].bitmap != NULL)
922 return graphic_local;
924 if (graphic_info[graphic_global].bitmap != NULL)
925 return graphic_global;
927 return IMG_UNDEFINED;
930 static int getTitleSound(struct TitleControlInfo *tci)
932 boolean is_image = tci->is_image;
933 int initial = tci->initial;
934 int nr = tci->local_nr;
935 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
936 int base = (is_image ?
937 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
938 SND_BACKGROUND_TITLESCREEN_1) :
939 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
940 SND_BACKGROUND_TITLEMESSAGE_1));
941 int sound_global = menu.sound[mode];
942 int sound_local = base + nr;
945 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
946 nr, initial, is_image,
947 sound_global, getSoundListEntry(sound_global)->filename,
948 sound_local, getSoundListEntry(sound_local)->filename);
951 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
954 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
957 return SND_UNDEFINED;
960 static int getTitleMusic(struct TitleControlInfo *tci)
962 boolean is_image = tci->is_image;
963 int initial = tci->initial;
964 int nr = tci->local_nr;
965 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
966 int base = (is_image ?
967 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
968 MUS_BACKGROUND_TITLESCREEN_1) :
969 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
970 MUS_BACKGROUND_TITLEMESSAGE_1));
971 int music_global = menu.music[mode];
972 int music_local = base + nr;
975 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
976 nr, initial, is_image,
977 music_global, getMusicListEntry(music_global)->filename,
978 music_local, getMusicListEntry(music_local)->filename);
981 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
984 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
987 return MUS_UNDEFINED;
990 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
992 boolean is_image = tci->is_image;
993 boolean initial = tci->initial;
994 boolean first = tci->first;
995 int nr = tci->local_nr;
996 struct TitleMessageInfo tmi;
997 struct TitleFadingInfo ti;
999 tmi = (is_image ? (initial ? (first ?
1000 titlescreen_initial_first[nr] :
1001 titlescreen_initial[nr])
1003 titlescreen_first[nr] :
1005 : (initial ? (first ?
1006 titlemessage_initial_first[nr] :
1007 titlemessage_initial[nr])
1009 titlemessage_first[nr] :
1010 titlemessage[nr])));
1012 ti.fade_mode = tmi.fade_mode;
1013 ti.fade_delay = tmi.fade_delay;
1014 ti.post_delay = tmi.post_delay;
1015 ti.auto_delay = tmi.auto_delay;
1020 static int compareTitleControlInfo(const void *object1, const void *object2)
1022 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1023 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1026 if (tci1->initial != tci2->initial)
1027 compare_result = (tci1->initial ? -1 : +1);
1028 else if (tci1->sort_priority != tci2->sort_priority)
1029 compare_result = tci1->sort_priority - tci2->sort_priority;
1030 else if (tci1->is_image != tci2->is_image)
1031 compare_result = (tci1->is_image ? -1 : +1);
1033 compare_result = tci1->local_nr - tci2->local_nr;
1035 return compare_result;
1038 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1040 int nr, int sort_priority)
1042 title_controls[num_title_screens].is_image = is_image;
1043 title_controls[num_title_screens].initial = initial;
1044 title_controls[num_title_screens].local_nr = nr;
1045 title_controls[num_title_screens].sort_priority = sort_priority;
1047 title_controls[num_title_screens].first = FALSE; /* will be set later */
1049 num_title_screens++;
1052 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1056 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1058 int graphic = getTitleScreenGraphic(i, initial);
1059 Bitmap *bitmap = graphic_info[graphic].bitmap;
1060 int sort_priority = graphic_info[graphic].sort_priority;
1063 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1066 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1068 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1069 char *filename = getLevelSetTitleMessageFilename(i, initial);
1070 int sort_priority = tmi->sort_priority;
1072 if (filename != NULL)
1073 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1077 static void InitializeTitleControls(boolean show_title_initial)
1079 num_title_screens = 0;
1081 /* 1st step: initialize title screens for game start (only when starting) */
1082 if (show_title_initial)
1083 InitializeTitleControls_CheckTitleInfo(TRUE);
1085 /* 2nd step: initialize title screens for current level set */
1086 InitializeTitleControls_CheckTitleInfo(FALSE);
1088 /* sort title screens according to sort_priority and title number */
1089 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1090 compareTitleControlInfo);
1092 /* mark first title screen */
1093 title_controls[0].first = TRUE;
1096 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1098 return (pos != NULL && pos->x != -1 && pos->y != -1);
1101 static boolean visibleTextPos(struct TextPosInfo *pos)
1103 return (pos != NULL && pos->x != -1 && pos->y != -1);
1106 static void InitializeMainControls(void)
1108 boolean local_team_mode = (!network.enabled && setup.team_mode);
1111 /* set main control text values to dynamically determined values */
1112 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1114 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1115 menu.main.text.first_level.size));
1116 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1117 menu.main.text.last_level.size));
1118 strcpy(main_text_level_number, int2str(level_nr,
1119 menu.main.text.level_number.size));
1121 main_text_level_year = leveldir_current->year;
1122 main_text_level_imported_from = leveldir_current->imported_from;
1123 main_text_level_imported_by = leveldir_current->imported_by;
1124 main_text_level_tested_by = leveldir_current->tested_by;
1126 main_text_title_1 = getConfigProgramTitleString();
1127 main_text_title_2 = getConfigProgramCopyrightString();
1128 main_text_title_3 = getConfigProgramCompanyString();
1130 /* set main control screen positions to dynamically determined values */
1131 for (i = 0; main_controls[i].nr != -1; i++)
1133 struct MainControlInfo *mci = &main_controls[i];
1135 struct MenuPosInfo *pos_button = mci->pos_button;
1136 struct TextPosInfo *pos_text = mci->pos_text;
1137 struct TextPosInfo *pos_input = mci->pos_input;
1138 char *text = (mci->text ? *mci->text : NULL);
1139 char *input = (mci->input ? *mci->input : NULL);
1140 int button_graphic = mci->button_graphic;
1141 int font_text = (pos_text ? pos_text->font : -1);
1142 int font_input = (pos_input ? pos_input->font : -1);
1144 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1145 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1146 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1147 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1148 int text_chars = (text != NULL ? strlen(text) : 0);
1149 int input_chars = (input != NULL ? strlen(input) : 0);
1152 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1154 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1155 int text_width = font_text_width * text_chars;
1156 int text_height = font_text_height;
1157 int input_width = font_input_width * input_chars;
1158 int input_height = font_input_height;
1160 if (nr == MAIN_CONTROL_NAME)
1162 menu.main.input.name.width = input_width;
1163 menu.main.input.name.height = input_height;
1166 if (pos_button != NULL) /* (x/y may be -1/-1 here) */
1168 pos_button->width = button_width;
1169 pos_button->height = button_height;
1172 if (pos_text != NULL) /* (x/y may be -1/-1 here) */
1174 /* calculate text size -- needed for text alignment */
1175 boolean calculate_text_size = (text != NULL);
1177 if (pos_text->width == -1 || calculate_text_size)
1178 pos_text->width = text_width;
1179 if (pos_text->height == -1 || calculate_text_size)
1180 pos_text->height = text_height;
1182 if (visibleMenuPos(pos_button))
1184 if (pos_text->x == -1)
1185 pos_text->x = pos_button->x + pos_button->width;
1186 if (pos_text->y == -1)
1188 pos_button->y + (pos_button->height - pos_text->height) / 2;
1192 if (pos_input != NULL) /* (x/y may be -1/-1 here) */
1194 if (visibleTextPos(pos_text))
1196 if (pos_input->x == -1)
1197 pos_input->x = pos_text->x + pos_text->width;
1198 if (pos_input->y == -1)
1199 pos_input->y = pos_text->y;
1202 if (pos_input->width == -1)
1203 pos_input->width = input_width;
1204 if (pos_input->height == -1)
1205 pos_input->height = input_height;
1210 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1211 int graphic, boolean pressed)
1213 struct GraphicInfo *g = &graphic_info[graphic];
1216 int xoffset = (pressed ? g->pressed_xoffset : 0);
1217 int yoffset = (pressed ? g->pressed_yoffset : 0);
1219 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1221 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1222 g->width, g->height, dst_x, dst_y);
1225 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1226 boolean active_input,
1227 boolean pressed_button)
1231 for (i = 0; main_controls[i].nr != -1; i++)
1233 struct MainControlInfo *mci = &main_controls[i];
1235 if (mci->nr == nr || nr == -1)
1237 struct MenuPosInfo *pos_button = mci->pos_button;
1238 struct TextPosInfo *pos_text = mci->pos_text;
1239 struct TextPosInfo *pos_input = mci->pos_input;
1240 char *text = (mci->text ? *mci->text : NULL);
1241 char *input = (mci->input ? *mci->input : NULL);
1242 int button_graphic = mci->button_graphic;
1243 int font_text = (pos_text ? pos_text->font : -1);
1244 int font_input = (pos_input ? pos_input->font : -1);
1248 button_graphic = BUTTON_ACTIVE(button_graphic);
1249 font_text = FONT_ACTIVE(font_text);
1254 font_input = FONT_ACTIVE(font_input);
1257 if (visibleMenuPos(pos_button))
1259 struct MenuPosInfo *pos = pos_button;
1260 int x = mSX + pos->x;
1261 int y = mSY + pos->y;
1263 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1264 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1267 if (visibleTextPos(pos_text) && text != NULL)
1269 struct TextPosInfo *pos = pos_text;
1270 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1271 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1274 /* (check why/if this is needed) */
1275 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1277 DrawText(x, y, text, font_text);
1280 if (visibleTextPos(pos_input) && input != NULL)
1282 struct TextPosInfo *pos = pos_input;
1283 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1284 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1287 /* (check why/if this is needed) */
1288 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1290 DrawText(x, y, input, font_input);
1296 static void DrawCursorAndText_Main(int nr, boolean active_text,
1297 boolean pressed_button)
1299 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1303 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1304 boolean pressed_button)
1306 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1310 static struct MainControlInfo *getMainControlInfo(int nr)
1314 for (i = 0; main_controls[i].nr != -1; i++)
1315 if (main_controls[i].nr == nr)
1316 return &main_controls[i];
1321 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1326 int rect_x = ALIGNED_TEXT_XPOS(rect);
1327 int rect_y = ALIGNED_TEXT_YPOS(rect);
1329 return (x >= rect_x && x < rect_x + rect->width &&
1330 y >= rect_y && y < rect_y + rect->height);
1333 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1338 int rect_x = ALIGNED_TEXT_XPOS(rect);
1339 int rect_y = ALIGNED_TEXT_YPOS(rect);
1342 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1343 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1344 (x >= rect_x && x < rect_x + rect->width &&
1345 y >= rect_y && y < rect_y + rect->height));
1348 return (x >= rect_x && x < rect_x + rect->width &&
1349 y >= rect_y && y < rect_y + rect->height);
1352 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1354 int rect_width = preview->xsize * preview->tile_size;
1355 int rect_height = preview->ysize * preview->tile_size;
1356 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1357 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1359 return (x >= rect_x && x < rect_x + rect_width &&
1360 y >= rect_y && y < rect_y + rect_height);
1363 static void AdjustScrollbar(int id, int items_max, int items_visible,
1366 struct GadgetInfo *gi = screen_gadget[id];
1368 if (item_position > items_max - items_visible)
1369 item_position = items_max - items_visible;
1371 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1372 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1373 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1376 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1378 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1382 static void clearMenuListArea(void)
1384 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1386 /* correct scrollbar position if placed outside menu (playfield) area */
1387 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1388 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1390 /* clear menu list area, but not title or scrollbar */
1391 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1392 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1395 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1397 static int cursor_array[MAX_LEV_FIELDY];
1398 int x = mSX + TILEX * xpos;
1399 int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1404 cursor_array[ypos] = graphic;
1406 graphic = cursor_array[ypos];
1410 graphic = BUTTON_ACTIVE(graphic);
1412 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1413 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1416 static void initCursor(int ypos, int graphic)
1418 drawCursorExt(0, ypos, FALSE, graphic);
1421 static void drawCursor(int ypos, boolean active)
1423 drawCursorExt(0, ypos, active, -1);
1426 static void drawCursorXY(int xpos, int ypos, int graphic)
1428 drawCursorExt(xpos, ypos, FALSE, graphic);
1431 static void drawChooseTreeCursor(int ypos, boolean active)
1433 drawCursorExt(0, ypos, active, -1);
1436 static void DrawHeadline(void)
1438 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1439 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1442 static void DrawTitleScreenImage(int nr, boolean initial)
1444 int graphic = getTitleScreenGraphic(nr, initial);
1445 Bitmap *bitmap = graphic_info[graphic].bitmap;
1446 int width = graphic_info[graphic].width;
1447 int height = graphic_info[graphic].height;
1448 int src_x = graphic_info[graphic].src_x;
1449 int src_y = graphic_info[graphic].src_y;
1455 if (width > WIN_XSIZE)
1457 /* image width too large for window => center image horizontally */
1458 src_x = (width - WIN_XSIZE) / 2;
1462 if (height > WIN_YSIZE)
1464 /* image height too large for window => center image vertically */
1465 src_y = (height - WIN_YSIZE) / 2;
1469 /* always display title screens centered */
1470 dst_x = (WIN_XSIZE - width) / 2;
1471 dst_y = (WIN_YSIZE - height) / 2;
1473 SetDrawBackgroundMask(REDRAW_ALL);
1474 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1476 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1478 if (DrawingOnBackground(dst_x, dst_y))
1479 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1481 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1483 redraw_mask = REDRAW_ALL;
1486 static void DrawTitleScreenMessage(int nr, boolean initial)
1488 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1489 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1491 if (filename == NULL)
1494 /* force TITLE font on title message screen */
1495 SetFontStatus(getTitleMessageGameMode(initial));
1497 /* if chars *and* width set to "-1", automatically determine width */
1498 if (tmi->chars == -1 && tmi->width == -1)
1499 tmi->width = viewport.window[game_status].width;
1501 /* if lines *and* height set to "-1", automatically determine height */
1502 if (tmi->lines == -1 && tmi->height == -1)
1503 tmi->height = viewport.window[game_status].height;
1505 /* if chars set to "-1", automatically determine by text and font width */
1506 if (tmi->chars == -1)
1507 tmi->chars = tmi->width / getFontWidth(tmi->font);
1509 tmi->width = tmi->chars * getFontWidth(tmi->font);
1511 /* if lines set to "-1", automatically determine by text and font height */
1512 if (tmi->lines == -1)
1513 tmi->lines = tmi->height / getFontHeight(tmi->font);
1515 tmi->height = tmi->lines * getFontHeight(tmi->font);
1517 /* if x set to "-1", automatically determine by width and alignment */
1519 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1521 /* if y set to "-1", automatically determine by height and alignment */
1523 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1525 SetDrawBackgroundMask(REDRAW_ALL);
1526 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1528 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1530 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1531 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1532 tmi->autowrap, tmi->centered, tmi->parse_comments);
1537 static void DrawTitleScreen(void)
1539 KeyboardAutoRepeatOff();
1541 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1544 static boolean CheckTitleScreen(boolean levelset_has_changed)
1546 static boolean show_title_initial = TRUE;
1547 boolean show_titlescreen = FALSE;
1549 /* needed to be able to skip title screen, if no image or message defined */
1550 InitializeTitleControls(show_title_initial);
1552 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1553 show_titlescreen = TRUE;
1555 /* show initial title images and messages only once at program start */
1556 show_title_initial = FALSE;
1558 return (show_titlescreen && num_title_screens > 0);
1561 void DrawMainMenu(void)
1563 static LevelDirTree *leveldir_last_valid = NULL;
1564 boolean levelset_has_changed = FALSE;
1565 int fade_mask = REDRAW_FIELD;
1567 LimitScreenUpdates(FALSE);
1569 FadeSetLeaveScreen();
1571 /* do not fade out here -- function may continue and fade on editor screen */
1574 FadeMenuSoundsAndMusic();
1576 ExpireSoundLoops(FALSE);
1578 KeyboardAutoRepeatOn();
1580 audio.sound_deactivated = FALSE;
1584 /* needed if last screen was the playing screen, invoked from level editor */
1585 if (level_editor_test_game)
1587 CloseDoor(DOOR_CLOSE_ALL);
1589 SetGameStatus(GAME_MODE_EDITOR);
1596 /* needed if last screen was the setup screen and fullscreen state changed */
1597 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1598 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1600 /* leveldir_current may be invalid (level group, parent link) */
1601 if (!validLevelSeries(leveldir_current))
1602 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1604 if (leveldir_current != leveldir_last_valid)
1605 levelset_has_changed = TRUE;
1607 /* store valid level series information */
1608 leveldir_last_valid = leveldir_current;
1610 init_last = init; /* switch to new busy animation */
1612 /* needed if last screen (level choice) changed graphics, sounds or music */
1613 ReloadCustomArtwork(0);
1615 if (CheckTitleScreen(levelset_has_changed))
1617 SetGameStatus(GAME_MODE_TITLE);
1624 if (redraw_mask & REDRAW_ALL)
1625 fade_mask = REDRAW_ALL;
1627 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
1628 fade_mask = REDRAW_ALL;
1632 /* needed if different viewport properties defined for menues */
1633 ChangeViewportPropertiesIfNeeded();
1635 SetDrawtoField(DRAW_TO_BACKBUFFER);
1637 /* level_nr may have been set to value over handicap with level editor */
1638 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1639 level_nr = leveldir_current->handicap_level;
1641 LoadLevel(level_nr);
1642 LoadScore(level_nr);
1644 SaveLevelSetup_SeriesInfo();
1646 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1647 SetDrawDeactivationMask(REDRAW_NONE);
1648 SetDrawBackgroundMask(REDRAW_FIELD);
1650 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1653 if (fade_mask == REDRAW_ALL)
1654 RedrawGlobalBorder();
1659 InitializeMainControls();
1661 DrawCursorAndText_Main(-1, FALSE, FALSE);
1662 DrawPreviewLevelInitial();
1663 DrawNetworkPlayers();
1665 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1668 if (TAPE_IS_EMPTY(tape))
1670 DrawCompleteVideoDisplay();
1672 PlayMenuSoundsAndMusic();
1674 /* create gadgets for main menu screen */
1675 FreeScreenGadgets();
1676 CreateScreenGadgets();
1678 /* may be required if audio buttons shown on tape and changed in setup menu */
1680 CreateGameButtons();
1682 /* map gadgets for main menu screen */
1684 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1685 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1687 /* copy actual game door content to door double buffer for OpenDoor() */
1688 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1689 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1691 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1693 DrawMaskedBorder(fade_mask);
1698 /* update screen area with special editor door */
1699 redraw_mask |= REDRAW_ALL;
1702 SetMouseCursor(CURSOR_DEFAULT);
1704 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1707 static void gotoTopLevelDir(void)
1709 /* move upwards until inside (but not above) top level directory */
1710 while (leveldir_current->node_parent &&
1711 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1713 /* write a "path" into level tree for easy navigation to last level */
1714 if (leveldir_current->node_parent->node_group->cl_first == -1)
1716 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1717 int leveldir_pos = posTreeInfo(leveldir_current);
1718 int num_page_entries;
1719 int cl_first, cl_cursor;
1721 if (num_leveldirs <= NUM_MENU_ENTRIES_ON_SCREEN)
1722 num_page_entries = num_leveldirs;
1724 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
1726 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1727 cl_cursor = leveldir_pos - cl_first;
1729 leveldir_current->node_parent->node_group->cl_first = cl_first;
1730 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1733 leveldir_current = leveldir_current->node_parent;
1737 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1739 static unsigned int title_delay = 0;
1740 static int title_screen_nr = 0;
1741 static int last_sound = -1, last_music = -1;
1742 boolean return_to_main_menu = FALSE;
1743 struct TitleControlInfo *tci;
1746 if (button == MB_MENU_INITIALIZE)
1749 title_screen_nr = 0;
1750 tci = &title_controls[title_screen_nr];
1752 SetAnimStatus(getTitleAnimMode(tci));
1754 last_sound = SND_UNDEFINED;
1755 last_music = MUS_UNDEFINED;
1757 if (num_title_screens != 0)
1759 FadeSetEnterScreen();
1761 /* use individual title fading instead of global "enter screen" fading */
1762 fading = getTitleFading(tci);
1765 if (game_status_last_screen == GAME_MODE_INFO)
1767 if (num_title_screens == 0)
1769 /* switch game mode from title screen mode back to info screen mode */
1770 SetGameStatus(GAME_MODE_INFO);
1772 /* store that last screen was info screen, not main menu screen */
1773 game_status_last_screen = GAME_MODE_INFO;
1775 DrawInfoScreen_NotAvailable("Title screen information:",
1776 "No title screen for this level set.");
1780 FadeMenuSoundsAndMusic();
1783 FadeOut(REDRAW_ALL);
1785 /* title screens may have different window size */
1786 ChangeViewportPropertiesIfNeeded();
1788 /* only required to update logic for redrawing global border */
1792 DrawTitleScreenImage(tci->local_nr, tci->initial);
1794 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1796 sound = getTitleSound(tci);
1797 music = getTitleMusic(tci);
1799 if (sound != last_sound)
1800 PlayMenuSoundExt(sound);
1801 if (music != last_music)
1802 PlayMenuMusicExt(music);
1807 SetMouseCursor(CURSOR_NONE);
1811 DelayReached(&title_delay, 0); /* reset delay counter */
1816 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay))
1817 button = MB_MENU_CHOICE;
1819 if (button == MB_MENU_LEAVE)
1821 return_to_main_menu = TRUE;
1823 else if (button == MB_MENU_CHOICE)
1825 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1827 SetGameStatus(GAME_MODE_INFO);
1829 info_mode = INFO_MODE_MAIN;
1838 if (title_screen_nr < num_title_screens)
1840 tci = &title_controls[title_screen_nr];
1842 SetAnimStatus(getTitleAnimMode(tci));
1844 sound = getTitleSound(tci);
1845 music = getTitleMusic(tci);
1847 if (last_sound != SND_UNDEFINED && sound != last_sound)
1848 FadeSound(last_sound);
1849 if (last_music != MUS_UNDEFINED && music != last_music)
1852 fading = getTitleFading(tci);
1854 FadeOut(REDRAW_ALL);
1857 DrawTitleScreenImage(tci->local_nr, tci->initial);
1859 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1861 sound = getTitleSound(tci);
1862 music = getTitleMusic(tci);
1864 if (sound != last_sound)
1865 PlayMenuSoundExt(sound);
1866 if (music != last_music)
1867 PlayMenuMusicExt(music);
1874 DelayReached(&title_delay, 0); /* reset delay counter */
1878 FadeMenuSoundsAndMusic();
1880 return_to_main_menu = TRUE;
1884 if (return_to_main_menu)
1886 SetMouseCursor(CURSOR_DEFAULT);
1888 /* force full menu screen redraw after displaying title screens */
1889 redraw_mask = REDRAW_ALL;
1891 if (game_status_last_screen == GAME_MODE_INFO)
1893 SetGameStatus(GAME_MODE_INFO);
1895 info_mode = INFO_MODE_MAIN;
1899 else /* default: return to main menu */
1901 SetGameStatus(GAME_MODE_MAIN);
1908 static void HandleMainMenu_SelectLevel(int step, int direction,
1909 int selected_level_nr)
1911 int old_level_nr = level_nr;
1914 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1915 new_level_nr = selected_level_nr;
1917 new_level_nr = old_level_nr + step * direction;
1919 if (new_level_nr < leveldir_current->first_level)
1920 new_level_nr = leveldir_current->first_level;
1921 if (new_level_nr > leveldir_current->last_level)
1922 new_level_nr = leveldir_current->last_level;
1924 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1926 /* skipping levels is only allowed when trying to skip single level */
1927 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1928 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1930 leveldir_current->handicap_level++;
1931 SaveLevelSetup_SeriesInfo();
1934 new_level_nr = leveldir_current->handicap_level;
1937 if (new_level_nr != old_level_nr)
1939 struct MainControlInfo *mci= getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1941 PlaySound(SND_MENU_ITEM_SELECTING);
1943 level_nr = new_level_nr;
1945 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1946 int2str(level_nr, menu.main.text.level_number.size),
1947 mci->pos_text->font);
1949 LoadLevel(level_nr);
1950 DrawPreviewLevelInitial();
1954 DrawCompleteVideoDisplay();
1956 SaveLevelSetup_SeriesInfo();
1958 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1960 /* needed because DrawPreviewLevelInitial() takes some time */
1962 /* SyncDisplay(); */
1966 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1968 static int choice = MAIN_CONTROL_GAME;
1969 static boolean button_pressed_last = FALSE;
1970 boolean button_pressed = FALSE;
1974 if (button == MB_MENU_INITIALIZE)
1976 DrawCursorAndText_Main(choice, TRUE, FALSE);
1981 if (mx || my) /* mouse input */
1985 for (i = 0; main_controls[i].nr != -1; i++)
1987 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1988 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1989 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1991 pos = main_controls[i].nr;
1997 /* check if level preview was clicked */
1998 if (insidePreviewRect(&preview, mx - SX, my - SY))
1999 pos = MAIN_CONTROL_GAME;
2001 // handle pressed/unpressed state for active/inactive menu buttons
2002 // (if pos != -1, "i" contains index position corresponding to "pos")
2004 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2005 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2006 button_pressed = TRUE;
2008 if (button_pressed != button_pressed_last)
2010 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2013 PlaySound(SND_MENU_BUTTON_PRESSING);
2015 PlaySound(SND_MENU_BUTTON_RELEASING);
2018 else if (dx || dy) /* keyboard input */
2020 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2021 choice == MAIN_CONTROL_SETUP))
2022 button = MB_MENU_CHOICE;
2027 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2029 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2031 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2033 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2035 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2037 CloseDoor(DOOR_CLOSE_2);
2039 SetGameStatus(GAME_MODE_LEVELNR);
2041 DrawChooseLevelNr();
2043 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2049 PlaySound(SND_MENU_ITEM_ACTIVATING);
2051 DrawCursorAndText_Main(choice, FALSE, FALSE);
2052 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2058 if (choice != MAIN_CONTROL_INFO &&
2059 choice != MAIN_CONTROL_SETUP)
2060 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2065 PlaySound(SND_MENU_ITEM_SELECTING);
2067 if (pos == MAIN_CONTROL_NAME)
2069 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2071 HandleTypeName(strlen(setup.player_name), 0);
2073 else if (pos == MAIN_CONTROL_LEVELS)
2077 CloseDoor(DOOR_CLOSE_2);
2079 SetGameStatus(GAME_MODE_LEVELS);
2081 SaveLevelSetup_LastSeries();
2082 SaveLevelSetup_SeriesInfo();
2084 if (setup.internal.choose_from_top_leveldir)
2087 DrawChooseLevelSet();
2090 else if (pos == MAIN_CONTROL_SCORES)
2092 CloseDoor(DOOR_CLOSE_2);
2094 SetGameStatus(GAME_MODE_SCORES);
2096 DrawHallOfFame(level_nr, -1);
2098 else if (pos == MAIN_CONTROL_EDITOR)
2100 if (leveldir_current->readonly &&
2101 !strEqual(setup.player_name, "Artsoft"))
2102 Request("This level is read only!", REQ_CONFIRM);
2104 CloseDoor(DOOR_CLOSE_2);
2106 SetGameStatus(GAME_MODE_EDITOR);
2108 FadeSetEnterScreen();
2112 else if (pos == MAIN_CONTROL_INFO)
2114 CloseDoor(DOOR_CLOSE_2);
2116 SetGameStatus(GAME_MODE_INFO);
2118 info_mode = INFO_MODE_MAIN;
2122 else if (pos == MAIN_CONTROL_GAME)
2124 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2126 else if (pos == MAIN_CONTROL_SETUP)
2128 CloseDoor(DOOR_CLOSE_2);
2130 SetGameStatus(GAME_MODE_SETUP);
2132 setup_mode = SETUP_MODE_MAIN;
2136 else if (pos == MAIN_CONTROL_QUIT)
2138 SaveLevelSetup_LastSeries();
2139 SaveLevelSetup_SeriesInfo();
2141 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2142 SetGameStatus(GAME_MODE_QUIT);
2147 button_pressed_last = button_pressed;
2151 /* ========================================================================= */
2152 /* info screen functions */
2153 /* ========================================================================= */
2155 static struct TokenInfo *info_info;
2156 static int num_info_info; /* number of info entries shown on screen */
2157 static int max_info_info; /* total number of info entries in list */
2159 static void execInfoTitleScreen(void)
2161 info_mode = INFO_MODE_TITLE;
2166 static void execInfoElements(void)
2168 info_mode = INFO_MODE_ELEMENTS;
2173 static void execInfoMusic(void)
2175 info_mode = INFO_MODE_MUSIC;
2180 static void execInfoCredits(void)
2182 info_mode = INFO_MODE_CREDITS;
2187 static void execInfoProgram(void)
2189 info_mode = INFO_MODE_PROGRAM;
2194 static void execInfoVersion(void)
2196 info_mode = INFO_MODE_VERSION;
2201 static void execInfoLevelSet(void)
2203 info_mode = INFO_MODE_LEVELSET;
2208 static void execExitInfo(void)
2210 SetGameStatus(GAME_MODE_MAIN);
2215 static struct TokenInfo info_info_main[] =
2217 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2218 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2219 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2220 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2221 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2222 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2223 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2224 { TYPE_EMPTY, NULL, "" },
2225 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2230 static int getMenuTextFont(int type)
2232 if (type & (TYPE_SWITCH |
2245 static struct TokenInfo *setup_info;
2246 static struct TokenInfo setup_info_input[];
2248 static struct TokenInfo *menu_info;
2250 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2251 int screen_pos, int menu_info_pos_raw,
2254 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2255 struct TokenInfo *ti = &token_info[pos];
2256 int xpos = MENU_SCREEN_START_XPOS;
2257 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2258 int font_nr = getMenuTextFont(ti->type);
2260 if (setup_mode == SETUP_MODE_INPUT)
2261 font_nr = FONT_MENU_1;
2264 font_nr = FONT_ACTIVE(font_nr);
2266 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2268 if (ti->type & ~TYPE_SKIP_ENTRY)
2269 drawCursor(screen_pos, active);
2272 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2275 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2278 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2281 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2284 static char *window_size_text;
2285 static char *scaling_type_text;
2287 static void drawSetupValue(int, int);
2289 static void drawMenuInfoList(int first_entry, int num_page_entries,
2290 int max_page_entries)
2294 if (first_entry + num_page_entries > max_page_entries)
2297 clearMenuListArea();
2299 for (i = 0; i < num_page_entries; i++)
2301 int menu_info_pos = first_entry + i;
2302 struct TokenInfo *si = &menu_info[menu_info_pos];
2303 void *value_ptr = si->value;
2305 /* set some entries to "unchangeable" according to other variables */
2306 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2307 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2308 (value_ptr == &setup.sound_music && !audio.music_available) ||
2309 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2310 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2311 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2312 si->type |= TYPE_GHOSTED;
2314 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2315 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2316 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2317 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2318 else if (si->type & ~TYPE_SKIP_ENTRY)
2319 initCursor(i, IMG_MENU_BUTTON);
2321 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2323 if (si->type & TYPE_VALUE &&
2324 menu_info == setup_info)
2325 drawSetupValue(i, menu_info_pos);
2329 static void DrawInfoScreen_Main(void)
2331 int fade_mask = REDRAW_FIELD;
2334 if (redraw_mask & REDRAW_ALL)
2335 fade_mask = REDRAW_ALL;
2337 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
2338 fade_mask = REDRAW_ALL;
2341 FadeMenuSoundsAndMusic();
2343 FreeScreenGadgets();
2344 CreateScreenGadgets();
2346 /* (needed after displaying title screens which disable auto repeat) */
2347 KeyboardAutoRepeatOn();
2349 FadeSetLeaveScreen();
2353 /* needed if different viewport properties defined for info screen */
2354 ChangeViewportPropertiesIfNeeded();
2356 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2360 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2362 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2364 info_info = info_info_main;
2366 // determine maximal number of info entries that can be displayed on screen
2368 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2371 // determine maximal number of info entries available for menu of info screen
2373 for (i = 0; info_info[i].type != 0; i++)
2376 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2378 MapScreenGadgets(max_info_info);
2380 PlayMenuSoundsAndMusic();
2382 DrawMaskedBorder(fade_mask);
2387 static void changeSetupValue(int, int, int);
2389 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2390 int mode, int num_page_entries,
2391 int max_page_entries)
2393 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2394 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2395 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2396 int *num_page_entries_last = num_page_entries_all_last[game_status];
2397 int *choice_store = choice_stores[game_status];
2398 int *first_entry_store = first_entry_stores[game_status];
2399 int choice = choice_store[mode]; /* starts with 0 */
2400 int first_entry = first_entry_store[mode]; /* starts with 0 */
2402 int y = choice - first_entry;
2404 boolean position_set_by_scrollbar = (dx == 999);
2405 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2408 if (button == MB_MENU_INITIALIZE)
2410 // check if number of menu page entries has changed (may happen by change
2411 // of custom artwork definition value for 'list_size' for this menu screen)
2412 // (in this case, the last menu position most probably has to be corrected)
2413 if (num_page_entries != num_page_entries_last[mode])
2415 choice_store[mode] = first_entry_store[mode] = 0;
2417 choice = first_entry = 0;
2420 num_page_entries_last[mode] = num_page_entries;
2423 /* advance to first valid menu entry */
2424 while (choice < num_page_entries &&
2425 menu_info[choice].type & TYPE_SKIP_ENTRY)
2428 if (position_set_by_scrollbar)
2429 first_entry = first_entry_store[mode] = dy;
2431 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2432 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2434 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2436 if (choice < first_entry)
2438 choice = first_entry;
2440 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2443 else if (choice > first_entry + num_page_entries - 1)
2445 choice = first_entry + num_page_entries - 1;
2447 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2451 choice_store[mode] = choice;
2453 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2457 else if (button == MB_MENU_LEAVE)
2459 PlaySound(SND_MENU_ITEM_SELECTING);
2461 for (i = 0; i < max_page_entries; i++)
2463 if (menu_info[i].type & TYPE_LEAVE_MENU)
2465 void (*menu_callback_function)(void) = menu_info[i].value;
2469 menu_callback_function();
2471 break; /* absolutely needed because function changes 'menu_info'! */
2478 if (mx || my) /* mouse input */
2480 x = (mx - mSX) / 32;
2481 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2483 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
2485 /* move cursor instead of scrolling when already at start/end of list */
2486 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2488 else if (dy == +1 * SCROLL_LINE &&
2489 first_entry + num_page_entries == max_page_entries)
2492 /* handle scrolling screen one line or page */
2494 y + dy > num_page_entries - 1)
2496 boolean redraw = FALSE;
2498 if (ABS(dy) == SCROLL_PAGE)
2499 step = num_page_entries - 1;
2501 if (dy < 0 && first_entry > 0)
2503 /* scroll page/line up */
2505 first_entry -= step;
2506 if (first_entry < 0)
2511 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2513 /* scroll page/line down */
2515 first_entry += step;
2516 if (first_entry + num_page_entries > max_page_entries)
2517 first_entry = MAX(0, max_page_entries - num_page_entries);
2524 choice += first_entry - first_entry_store[mode];
2526 if (choice < first_entry)
2528 choice = first_entry;
2530 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2533 else if (choice > first_entry + num_page_entries - 1)
2535 choice = first_entry + num_page_entries - 1;
2537 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2540 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2544 if (choice < first_entry ||
2545 choice > first_entry + num_page_entries - 1)
2546 first_entry += SIGN(dy);
2549 first_entry_store[mode] = first_entry;
2550 choice_store[mode] = choice;
2552 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2554 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2556 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2557 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2565 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2567 if (menu_info[choice].type & menu_navigation_type ||
2568 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2569 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2570 menu_info[choice].type & TYPE_PLAYER)
2571 button = MB_MENU_CHOICE;
2576 /* jump to next non-empty menu entry (up or down) */
2577 while (first_entry + y > 0 &&
2578 first_entry + y < max_page_entries - 1 &&
2579 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2582 if (!IN_VIS_MENU(x, y))
2584 choice += y - y_old;
2586 if (choice < first_entry)
2587 first_entry = choice;
2588 else if (choice > first_entry + num_page_entries - 1)
2589 first_entry = choice - num_page_entries + 1;
2591 if (first_entry >= 0 &&
2592 first_entry + num_page_entries <= max_page_entries)
2594 first_entry_store[mode] = first_entry;
2596 if (choice < first_entry)
2597 choice = first_entry;
2598 else if (choice > first_entry + num_page_entries - 1)
2599 choice = first_entry + num_page_entries - 1;
2601 choice_store[mode] = choice;
2603 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2605 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2607 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2608 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2615 if (!anyScrollbarGadgetActive() &&
2616 IN_VIS_MENU(x, y) &&
2617 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
2618 y >= 0 && y < num_page_entries)
2622 if (first_entry + y != choice &&
2623 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2625 PlaySound(SND_MENU_ITEM_ACTIVATING);
2627 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2628 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2630 choice = choice_store[mode] = first_entry + y;
2634 PlaySound(SND_MENU_ITEM_SELECTING);
2636 for (i = 0; menu_info[i].type != 0; i++)
2638 if (menu_info[i].type & TYPE_LEAVE_MENU)
2640 void (*menu_callback_function)(void) = menu_info[i].value;
2644 menu_callback_function();
2646 /* absolutely needed because function changes 'menu_info'! */
2654 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2656 PlaySound(SND_MENU_ITEM_SELECTING);
2658 /* when selecting key headline, execute function for key value change */
2659 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2660 menu_info[first_entry + y + 1].type & TYPE_KEY)
2663 /* when selecting string value, execute function for list selection */
2664 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2665 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2668 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2670 void (*menu_callback_function)(void) =
2671 menu_info[first_entry + y].value;
2673 FadeSetFromType(menu_info[first_entry + y].type);
2675 menu_callback_function();
2677 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2678 menu_info == setup_info)
2680 changeSetupValue(y, first_entry + y, dx);
2686 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2688 menu_info = info_info;
2690 HandleMenuScreen(mx, my, dx, dy, button,
2691 info_mode, num_info_info, max_info_info);
2694 static int getMenuFontSpacing(int spacing_height, int font_nr)
2696 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2698 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2702 static int getMenuTextSpacing(int spacing_height, int font_nr)
2704 return (getMenuFontSpacing(spacing_height, font_nr) +
2705 EXTRA_SPACING(game_status));
2708 static int getMenuTextStep(int spacing_height, int font_nr)
2710 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2713 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2715 int font_title = MENU_INFO_FONT_TITLE;
2716 int font_error = FONT_TEXT_2;
2717 int font_foot = MENU_INFO_FONT_FOOT;
2718 int spacing_title = menu.headline1_spacing_info[info_mode];
2719 int ystep_title = getMenuTextStep(spacing_title, font_title);
2720 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2721 int ystart2 = ystart1 + ystep_title;
2722 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2724 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2726 FadeOut(REDRAW_FIELD);
2731 DrawTextSCentered(ystart1, font_title, text_title);
2732 DrawTextSCentered(ystart2, font_error, text_error);
2734 DrawTextSCentered(ybottom, font_foot,
2735 "Press any key or button for info menu");
2737 FadeIn(REDRAW_FIELD);
2740 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2742 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2743 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2744 int font_title = MENU_INFO_FONT_TITLE;
2745 int font_foot = MENU_INFO_FONT_FOOT;
2746 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2747 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2748 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2749 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2750 int ystep = MENU_SCREEN_INFO_YSTEP;
2751 int element, action, direction;
2759 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2760 infoscreen_step[i] = infoscreen_frame[i] = 0;
2765 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2767 DrawTextSCentered(ybottom, font_foot,
2768 "Press any key or button for next page");
2774 while (helpanim_info[j].element != HELPANIM_LIST_END)
2776 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2781 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2790 j += infoscreen_step[i - start];
2792 element = helpanim_info[j].element;
2793 action = helpanim_info[j].action;
2794 direction = helpanim_info[j].direction;
2797 element = EL_UNKNOWN;
2799 if (action != -1 && direction != -1)
2800 graphic = el_act_dir2img(element, action, direction);
2801 else if (action != -1)
2802 graphic = el_act2img(element, action);
2803 else if (direction != -1)
2804 graphic = el_dir2img(element, direction);
2806 graphic = el2img(element);
2808 delay = helpanim_info[j++].delay;
2813 if (infoscreen_frame[i - start] == 0)
2816 infoscreen_frame[i - start] = delay - 1;
2820 sync_frame = delay - infoscreen_frame[i - start];
2821 infoscreen_frame[i - start]--;
2824 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2826 if (!infoscreen_frame[i - start])
2827 infoscreen_step[i - start] = 0;
2831 if (!infoscreen_frame[i - start])
2832 infoscreen_step[i - start]++;
2833 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2839 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2841 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2842 graphic, sync_frame, USE_MASKING);
2845 DrawInfoScreen_HelpText(element, action, direction, i - start);
2850 redraw_mask |= REDRAW_FIELD;
2855 static char *getHelpText(int element, int action, int direction)
2857 char token[MAX_LINE_LEN];
2859 strcpy(token, element_info[element].token_name);
2862 strcat(token, element_action_info[action].suffix);
2864 if (direction != -1)
2865 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2867 return getHashEntry(helptext_info, token);
2870 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2872 int font_nr = FONT_INFO_ELEMENTS;
2873 int font_width = getFontWidth(font_nr);
2874 int font_height = getFontHeight(font_nr);
2875 int yoffset = (TILEX - 2 * font_height) / 2;
2876 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2877 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2878 int ystep = TILEY + 4;
2879 int pad_left = xstart - SX;
2880 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2881 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2882 int max_lines_per_text = 2;
2885 if (action != -1 && direction != -1) /* element.action.direction */
2886 text = getHelpText(element, action, direction);
2888 if (text == NULL && action != -1) /* element.action */
2889 text = getHelpText(element, action, -1);
2891 if (text == NULL && direction != -1) /* element.direction */
2892 text = getHelpText(element, -1, direction);
2894 if (text == NULL) /* base element */
2895 text = getHelpText(element, -1, -1);
2897 if (text == NULL) /* not found */
2898 text = "No description available";
2900 if (strlen(text) <= max_chars_per_line) /* only one line of text */
2901 ystart += getFontHeight(font_nr) / 2;
2903 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2904 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2905 TRUE, FALSE, FALSE);
2908 static void DrawInfoScreen_TitleScreen(void)
2910 SetGameStatus(GAME_MODE_TITLE);
2915 void HandleInfoScreen_TitleScreen(int button)
2917 HandleTitleScreen(0, 0, 0, 0, button);
2920 static void DrawInfoScreen_Elements(void)
2922 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2924 FadeOut(REDRAW_FIELD);
2929 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2931 FadeIn(REDRAW_FIELD);
2934 void HandleInfoScreen_Elements(int button)
2936 static unsigned int info_delay = 0;
2937 static int num_anims;
2938 static int num_pages;
2940 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2943 if (button == MB_MENU_INITIALIZE)
2945 boolean new_element = TRUE;
2949 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2951 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
2953 else if (new_element)
2956 new_element = FALSE;
2960 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
2964 if (button == MB_MENU_LEAVE)
2966 PlaySound(SND_MENU_ITEM_SELECTING);
2968 info_mode = INFO_MODE_MAIN;
2973 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
2975 if (button != MB_MENU_INITIALIZE)
2977 PlaySound(SND_MENU_ITEM_SELECTING);
2982 if (page >= num_pages)
2984 FadeMenuSoundsAndMusic();
2986 info_mode = INFO_MODE_MAIN;
2993 FadeSetNextScreen();
2995 if (button != MB_MENU_INITIALIZE)
2996 FadeOut(REDRAW_FIELD);
2998 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3000 if (button != MB_MENU_INITIALIZE)
3001 FadeIn(REDRAW_FIELD);
3005 if (DelayReached(&info_delay, GameFrameDelay))
3006 if (page < num_pages)
3007 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3009 PlayMenuSoundIfLoop();
3013 static void DrawInfoScreen_Music(void)
3015 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3017 FadeOut(REDRAW_FIELD);
3024 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3026 FadeIn(REDRAW_FIELD);
3029 void HandleInfoScreen_Music(int button)
3031 static struct MusicFileInfo *list = NULL;
3032 int font_title = MENU_INFO_FONT_TITLE;
3033 int font_head = MENU_INFO_FONT_HEAD;
3034 int font_text = MENU_INFO_FONT_TEXT;
3035 int font_foot = MENU_INFO_FONT_FOOT;
3036 int spacing_title = menu.headline1_spacing_info[info_mode];
3037 int spacing_head = menu.headline2_spacing_info[info_mode];
3038 int ystep_title = getMenuTextStep(spacing_title, font_title);
3039 int ystep_head = getMenuTextStep(spacing_head, font_head);
3040 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3041 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3043 if (button == MB_MENU_INITIALIZE)
3045 list = music_file_info;
3049 FadeMenuSoundsAndMusic();
3054 DrawTextSCentered(ystart, font_title,
3055 "No music info for this level set.");
3057 DrawTextSCentered(ybottom, font_foot,
3058 "Press any key or button for info menu");
3064 if (button == MB_MENU_LEAVE)
3066 PlaySound(SND_MENU_ITEM_SELECTING);
3068 FadeMenuSoundsAndMusic();
3070 info_mode = INFO_MODE_MAIN;
3075 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3077 if (button != MB_MENU_INITIALIZE)
3079 PlaySound(SND_MENU_ITEM_SELECTING);
3087 FadeMenuSoundsAndMusic();
3089 info_mode = INFO_MODE_MAIN;
3095 FadeMenuSoundsAndMusic();
3097 if (list != music_file_info)
3098 FadeSetNextScreen();
3100 if (button != MB_MENU_INITIALIZE)
3101 FadeOut(REDRAW_FIELD);
3108 int sound = list->music;
3110 if (sound_info[sound].loop)
3111 PlaySoundLoop(sound);
3115 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3119 int music = list->music;
3121 if (music_info[music].loop)
3122 PlayMusicLoop(music);
3126 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3129 ystart += ystep_title;
3131 if (!strEqual(list->title, UNKNOWN_NAME))
3133 if (!strEqual(list->title_header, UNKNOWN_NAME))
3135 DrawTextSCentered(ystart, font_head, list->title_header);
3136 ystart += ystep_head;
3139 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3140 ystart += ystep_head;
3143 if (!strEqual(list->artist, UNKNOWN_NAME))
3145 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3146 DrawTextSCentered(ystart, font_head, list->artist_header);
3148 DrawTextSCentered(ystart, font_head, "by");
3150 ystart += ystep_head;
3152 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3153 ystart += ystep_head;
3156 if (!strEqual(list->album, UNKNOWN_NAME))
3158 if (!strEqual(list->album_header, UNKNOWN_NAME))
3159 DrawTextSCentered(ystart, font_head, list->album_header);
3161 DrawTextSCentered(ystart, font_head, "from the album");
3163 ystart += ystep_head;
3165 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3166 ystart += ystep_head;
3169 if (!strEqual(list->year, UNKNOWN_NAME))
3171 if (!strEqual(list->year_header, UNKNOWN_NAME))
3172 DrawTextSCentered(ystart, font_head, list->year_header);
3174 DrawTextSCentered(ystart, font_head, "from the year");
3176 ystart += ystep_head;
3178 DrawTextFCentered(ystart, font_text, "%s", list->year);
3179 ystart += ystep_head;
3182 DrawTextSCentered(ybottom, FONT_TEXT_4,
3183 "Press any key or button for next page");
3185 if (button != MB_MENU_INITIALIZE)
3186 FadeIn(REDRAW_FIELD);
3189 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3190 PlaySoundLoop(list->music);
3193 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3195 int font_title = MENU_INFO_FONT_TITLE;
3196 int font_head = MENU_INFO_FONT_HEAD;
3197 int font_text = MENU_INFO_FONT_TEXT;
3198 int font_foot = MENU_INFO_FONT_FOOT;
3199 int spacing_title = menu.headline1_spacing_info[info_mode];
3200 int spacing_head = menu.headline2_spacing_info[info_mode];
3201 int spacing_para = menu.paragraph_spacing_info[info_mode];
3202 int spacing_line = menu.line_spacing_info[info_mode];
3203 int ystep_title = getMenuTextStep(spacing_title, font_title);
3204 int ystep_head = getMenuTextStep(spacing_head, font_head);
3205 int ystep_para = getMenuTextStep(spacing_para, font_text);
3206 int ystep_line = getMenuTextStep(spacing_line, font_text);
3207 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3208 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3213 DrawTextSCentered(ystart, font_title, "Credits:");
3214 ystart += ystep_title;
3218 DrawTextSCentered(ystart, font_head,
3219 "Special thanks to");
3220 ystart += ystep_head;
3221 DrawTextSCentered(ystart, font_text,
3223 ystart += ystep_head;
3224 DrawTextSCentered(ystart, font_head,
3226 ystart += ystep_head;
3227 DrawTextSCentered(ystart, font_text,
3228 "\"Boulder Dash\"");
3229 ystart += ystep_head;
3230 DrawTextSCentered(ystart, font_head,
3232 ystart += ystep_head;
3233 DrawTextSCentered(ystart, font_text,
3235 ystart += ystep_head;
3236 DrawTextSCentered(ystart, font_head,
3238 ystart += ystep_head;
3239 DrawTextSCentered(ystart, font_text,
3240 "First Star Software");
3242 else if (screen_nr == 1)
3244 DrawTextSCentered(ystart, font_head,
3245 "Special thanks to");
3246 ystart += ystep_head;
3247 DrawTextSCentered(ystart, font_text,
3248 "Klaus Heinz & Volker Wertich");
3249 ystart += ystep_head;
3250 DrawTextSCentered(ystart, font_head,
3252 ystart += ystep_head;
3253 DrawTextSCentered(ystart, font_text,
3254 "\"Emerald Mine\"");
3255 ystart += ystep_head;
3256 DrawTextSCentered(ystart, font_head,
3258 ystart += ystep_head;
3259 DrawTextSCentered(ystart, font_text,
3261 ystart += ystep_head;
3262 DrawTextSCentered(ystart, font_head,
3264 ystart += ystep_head;
3265 DrawTextSCentered(ystart, font_text,
3268 else if (screen_nr == 2)
3270 DrawTextSCentered(ystart, font_head,
3271 "Special thanks to");
3272 ystart += ystep_head;
3273 DrawTextSCentered(ystart, font_text,
3274 "Michael Stopp & Philip Jespersen");
3275 ystart += ystep_head;
3276 DrawTextSCentered(ystart, font_head,
3278 ystart += ystep_head;
3279 DrawTextSCentered(ystart, font_text,
3281 ystart += ystep_head;
3282 DrawTextSCentered(ystart, font_head,
3284 ystart += ystep_head;
3285 DrawTextSCentered(ystart, font_text,
3287 ystart += ystep_head;
3288 DrawTextSCentered(ystart, font_head,
3290 ystart += ystep_head;
3291 DrawTextSCentered(ystart, font_text,
3292 "Digital Integration");
3294 else if (screen_nr == 3)
3296 DrawTextSCentered(ystart, font_head,
3297 "Special thanks to");
3298 ystart += ystep_head;
3299 DrawTextSCentered(ystart, font_text,
3300 "Hiroyuki Imabayashi");
3301 ystart += ystep_head;
3302 DrawTextSCentered(ystart, font_head,
3304 ystart += ystep_head;
3305 DrawTextSCentered(ystart, font_text,
3307 ystart += ystep_head;
3308 DrawTextSCentered(ystart, font_head,
3310 ystart += ystep_head;
3311 DrawTextSCentered(ystart, font_text,
3313 ystart += ystep_head;
3314 DrawTextSCentered(ystart, font_head,
3316 ystart += ystep_head;
3317 DrawTextSCentered(ystart, font_text,
3320 else if (screen_nr == 4)
3322 DrawTextSCentered(ystart, font_head,
3323 "Special thanks to");
3324 ystart += ystep_head;
3325 DrawTextSCentered(ystart, font_text,
3327 ystart += ystep_head;
3328 DrawTextSCentered(ystart, font_head,
3330 ystart += ystep_head;
3331 DrawTextSCentered(ystart, font_text,
3332 "J\xfcrgen Bonhagen");
3333 ystart += ystep_head;
3334 DrawTextSCentered(ystart, font_head,
3335 "for the continuous creation");
3336 ystart += ystep_line;
3337 DrawTextSCentered(ystart, font_head,
3338 "of outstanding level sets");
3340 else if (screen_nr == 5)
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 ideas and inspiration by");
3350 ystart += ystep_head;
3351 DrawTextSCentered(ystart, font_text,
3353 ystart += ystep_para;
3355 DrawTextSCentered(ystart, font_head,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_text,
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_head,
3362 "for ideas and inspiration by");
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_text,
3367 else if (screen_nr == 6)
3369 DrawTextSCentered(ystart, font_head,
3371 ystart += ystep_head;
3372 DrawTextSCentered(ystart, font_text,
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_head,
3376 "for the code base used for the");
3377 ystart += ystep_line;
3378 DrawTextSCentered(ystart, font_head,
3379 "native Emerald Mine engine");
3381 else if (screen_nr == 7)
3383 DrawTextSCentered(ystart, font_head,
3385 ystart += ystep_head;
3386 DrawTextSCentered(ystart, font_text,
3388 ystart += ystep_head;
3389 DrawTextSCentered(ystart, font_head,
3390 "for the initial DOS port");
3391 ystart += ystep_para;
3393 DrawTextSCentered(ystart, font_head,
3395 ystart += ystep_head;
3396 DrawTextSCentered(ystart, font_text,
3398 ystart += ystep_head;
3399 DrawTextSCentered(ystart, font_head,
3400 "for some additional toons");
3402 else if (screen_nr == 8)
3404 DrawTextSCentered(ystart, font_head,
3405 "And not to forget:");
3406 ystart += ystep_head;
3407 DrawTextSCentered(ystart, font_head,
3409 ystart += ystep_head;
3410 DrawTextSCentered(ystart, font_text,
3411 "All those who contributed");
3412 ystart += ystep_line;
3413 DrawTextSCentered(ystart, font_text,
3414 "levels to this game");
3415 ystart += ystep_line;
3416 DrawTextSCentered(ystart, font_text,
3420 DrawTextSCentered(ybottom, font_foot,
3421 "Press any key or button for next page");
3424 static void DrawInfoScreen_Credits(void)
3426 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3428 FadeMenuSoundsAndMusic();
3430 FadeOut(REDRAW_FIELD);
3432 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3434 FadeIn(REDRAW_FIELD);
3437 void HandleInfoScreen_Credits(int button)
3439 static int screen_nr = 0;
3440 int num_screens = 9;
3442 if (button == MB_MENU_INITIALIZE)
3446 // DrawInfoScreen_CreditsScreen(screen_nr);
3449 if (button == MB_MENU_LEAVE)
3451 PlaySound(SND_MENU_ITEM_SELECTING);
3453 info_mode = INFO_MODE_MAIN;
3458 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3460 if (button != MB_MENU_INITIALIZE)
3462 PlaySound(SND_MENU_ITEM_SELECTING);
3467 if (screen_nr >= num_screens)
3469 FadeMenuSoundsAndMusic();
3471 info_mode = INFO_MODE_MAIN;
3478 FadeSetNextScreen();
3480 if (button != MB_MENU_INITIALIZE)
3481 FadeOut(REDRAW_FIELD);
3483 DrawInfoScreen_CreditsScreen(screen_nr);
3485 if (button != MB_MENU_INITIALIZE)
3486 FadeIn(REDRAW_FIELD);
3490 PlayMenuSoundIfLoop();
3494 static void DrawInfoScreen_Program(void)
3496 int font_title = MENU_INFO_FONT_TITLE;
3497 int font_head = MENU_INFO_FONT_HEAD;
3498 int font_text = MENU_INFO_FONT_TEXT;
3499 int font_foot = MENU_INFO_FONT_FOOT;
3500 int spacing_title = menu.headline1_spacing_info[info_mode];
3501 int spacing_head = menu.headline2_spacing_info[info_mode];
3502 int spacing_para = menu.paragraph_spacing_info[info_mode];
3503 int spacing_line = menu.line_spacing_info[info_mode];
3504 int ystep_title = getMenuTextStep(spacing_title, font_title);
3505 int ystep_head = getMenuTextStep(spacing_head, font_head);
3506 int ystep_para = getMenuTextStep(spacing_para, font_text);
3507 int ystep_line = getMenuTextStep(spacing_line, font_text);
3508 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3509 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3511 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3513 FadeOut(REDRAW_FIELD);
3518 DrawTextSCentered(ystart, font_title, "Program Information:");
3519 ystart += ystep_title;
3521 DrawTextSCentered(ystart, font_head,
3522 "This game is Freeware!");
3523 ystart += ystep_head;
3524 DrawTextSCentered(ystart, font_head,
3525 "If you like it, send e-mail to:");
3526 ystart += ystep_head;
3527 DrawTextSCentered(ystart, font_text,
3528 setup.internal.program_email);
3529 ystart += ystep_para;
3531 DrawTextSCentered(ystart, font_head,
3532 "More information and levels:");
3533 ystart += ystep_head;
3534 DrawTextSCentered(ystart, font_text,
3535 setup.internal.program_website);
3536 ystart += ystep_para;
3538 DrawTextSCentered(ystart, font_head,
3539 "If you have created new levels,");
3540 ystart += ystep_line;
3541 DrawTextSCentered(ystart, font_head,
3542 "send them to me to include them!");
3543 ystart += ystep_head;
3544 DrawTextSCentered(ystart, font_head,
3547 DrawTextSCentered(ybottom, font_foot,
3548 "Press any key or button for info menu");
3550 FadeIn(REDRAW_FIELD);
3553 void HandleInfoScreen_Program(int button)
3555 if (button == MB_MENU_LEAVE)
3557 PlaySound(SND_MENU_ITEM_SELECTING);
3559 info_mode = INFO_MODE_MAIN;
3564 else if (button == MB_MENU_CHOICE)
3566 PlaySound(SND_MENU_ITEM_SELECTING);
3568 FadeMenuSoundsAndMusic();
3570 info_mode = INFO_MODE_MAIN;
3575 PlayMenuSoundIfLoop();
3579 static void DrawInfoScreen_Version(void)
3581 int font_title = MENU_INFO_FONT_TITLE;
3582 int font_head = MENU_INFO_FONT_HEAD;
3583 int font_text = MENU_INFO_FONT_TEXT;
3584 int font_foot = MENU_INFO_FONT_FOOT;
3585 int spacing_title = menu.headline1_spacing_info[info_mode];
3586 int spacing_head = menu.headline2_spacing_info[info_mode];
3587 int spacing_para = menu.paragraph_spacing_info[info_mode];
3588 int spacing_line = menu.line_spacing_info[info_mode];
3589 int xstep = getFontWidth(font_text);
3590 int ystep_title = getMenuTextStep(spacing_title, font_title);
3591 int ystep_head = getMenuTextStep(spacing_head, font_head);
3592 int ystep_para = getMenuTextStep(spacing_para, font_text);
3593 int ystep_line = getMenuTextStep(spacing_line, font_text);
3594 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3595 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3596 int xstart1 = mSX - SX + 2 * xstep;
3597 int xstart2 = mSX - SX + 18 * xstep;
3598 int xstart3 = mSX - SX + 28 * xstep;
3599 SDL_version sdl_version_compiled;
3600 const SDL_version *sdl_version_linked;
3601 int driver_name_len = 10;
3602 #if defined(TARGET_SDL2)
3603 SDL_version sdl_version_linked_ext;
3604 const char *driver_name = NULL;
3606 char driver_name[driver_name_len];
3609 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3611 FadeOut(REDRAW_FIELD);
3616 DrawTextSCentered(ystart, font_title, "Version Information:");
3617 ystart += ystep_title;
3619 DrawTextF(xstart1, ystart, font_head, "Name");
3620 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3621 ystart += ystep_line;
3623 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3625 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3626 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3627 ystart += ystep_line;
3629 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3630 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3631 ystart += ystep_line;
3635 DrawTextF(xstart1, ystart, font_head, "Version");
3636 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3637 ystart += ystep_line;
3640 DrawTextF(xstart1, ystart, font_head, "Platform");
3641 DrawTextF(xstart2, ystart, font_text, PLATFORM_STRING);
3642 ystart += ystep_line;
3644 DrawTextF(xstart1, ystart, font_head, "Target");
3645 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3646 ystart += ystep_line;
3648 DrawTextF(xstart1, ystart, font_head, "Source date");
3649 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3650 ystart += ystep_para;
3652 DrawTextF(xstart1, ystart, font_head, "Library");
3653 DrawTextF(xstart2, ystart, font_head, "compiled");
3654 DrawTextF(xstart3, ystart, font_head, "linked");
3655 ystart += ystep_head;
3657 SDL_VERSION(&sdl_version_compiled);
3658 #if defined(TARGET_SDL2)
3659 SDL_GetVersion(&sdl_version_linked_ext);
3660 sdl_version_linked = &sdl_version_linked_ext;
3662 sdl_version_linked = SDL_Linked_Version();
3665 DrawTextF(xstart1, ystart, font_text, "SDL");
3666 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3667 sdl_version_compiled.major,
3668 sdl_version_compiled.minor,
3669 sdl_version_compiled.patch);
3670 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3671 sdl_version_linked->major,
3672 sdl_version_linked->minor,
3673 sdl_version_linked->patch);
3674 ystart += ystep_line;
3676 SDL_IMAGE_VERSION(&sdl_version_compiled);
3677 sdl_version_linked = IMG_Linked_Version();
3679 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3680 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3681 sdl_version_compiled.major,
3682 sdl_version_compiled.minor,
3683 sdl_version_compiled.patch);
3684 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3685 sdl_version_linked->major,
3686 sdl_version_linked->minor,
3687 sdl_version_linked->patch);
3688 ystart += ystep_line;
3690 SDL_MIXER_VERSION(&sdl_version_compiled);
3691 sdl_version_linked = Mix_Linked_Version();
3693 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3694 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3695 sdl_version_compiled.major,
3696 sdl_version_compiled.minor,
3697 sdl_version_compiled.patch);
3698 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3699 sdl_version_linked->major,
3700 sdl_version_linked->minor,
3701 sdl_version_linked->patch);
3702 ystart += ystep_line;
3704 SDL_NET_VERSION(&sdl_version_compiled);
3705 sdl_version_linked = SDLNet_Linked_Version();
3707 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3708 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3709 sdl_version_compiled.major,
3710 sdl_version_compiled.minor,
3711 sdl_version_compiled.patch);
3712 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3713 sdl_version_linked->major,
3714 sdl_version_linked->minor,
3715 sdl_version_linked->patch);
3716 ystart += ystep_para;
3718 DrawTextF(xstart1, ystart, font_head, "Driver");
3719 DrawTextF(xstart2, ystart, font_head, "Requested");
3720 DrawTextF(xstart3, ystart, font_head, "Used");
3721 ystart += ystep_head;
3723 #if defined(TARGET_SDL2)
3724 driver_name = getStringCopyNStatic(SDL_GetVideoDriver(0), driver_name_len);
3726 SDL_VideoDriverName(driver_name, driver_name_len);
3729 DrawTextF(xstart1, ystart, font_text, "SDL_VideoDriver");
3730 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3731 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3732 ystart += ystep_line;
3734 #if defined(TARGET_SDL2)
3735 driver_name = getStringCopyNStatic(SDL_GetAudioDriver(0), driver_name_len);
3737 SDL_AudioDriverName(driver_name, driver_name_len);
3740 DrawTextF(xstart1, ystart, font_text, "SDL_AudioDriver");
3741 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3742 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3744 DrawTextSCentered(ybottom, font_foot,
3745 "Press any key or button for info menu");
3747 FadeIn(REDRAW_FIELD);
3750 void HandleInfoScreen_Version(int button)
3752 if (button == MB_MENU_LEAVE)
3754 PlaySound(SND_MENU_ITEM_SELECTING);
3756 info_mode = INFO_MODE_MAIN;
3761 else if (button == MB_MENU_CHOICE)
3763 PlaySound(SND_MENU_ITEM_SELECTING);
3765 FadeMenuSoundsAndMusic();
3767 info_mode = INFO_MODE_MAIN;
3772 PlayMenuSoundIfLoop();
3776 static void DrawInfoScreen_LevelSet(void)
3778 struct TitleMessageInfo *tmi = &readme;
3779 char *filename = getLevelSetInfoFilename();
3780 char *title = "Level Set Information:";
3781 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3782 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3784 if (filename == NULL)
3786 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3791 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3793 FadeOut(REDRAW_FIELD);
3798 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3800 /* if x position set to "-1", automatically determine by playfield width */
3802 tmi->x = SXSIZE / 2;
3804 /* if y position set to "-1", use static default value */
3808 /* if width set to "-1", automatically determine by playfield width */
3809 if (tmi->width == -1)
3810 tmi->width = SXSIZE - 2 * TILEX;
3812 /* if height set to "-1", automatically determine by playfield height */
3813 if (tmi->height == -1)
3814 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3816 /* if chars set to "-1", automatically determine by text and font width */
3817 if (tmi->chars == -1)
3818 tmi->chars = tmi->width / getFontWidth(tmi->font);
3820 tmi->width = tmi->chars * getFontWidth(tmi->font);
3822 /* if lines set to "-1", automatically determine by text and font height */
3823 if (tmi->lines == -1)
3824 tmi->lines = tmi->height / getFontHeight(tmi->font);
3826 tmi->height = tmi->lines * getFontHeight(tmi->font);
3828 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3829 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3830 tmi->autowrap, tmi->centered, tmi->parse_comments);
3832 DrawTextSCentered(ybottom, FONT_TEXT_4,
3833 "Press any key or button for info menu");
3835 FadeIn(REDRAW_FIELD);
3838 static void HandleInfoScreen_LevelSet(int button)
3840 if (button == MB_MENU_LEAVE)
3842 PlaySound(SND_MENU_ITEM_SELECTING);
3844 info_mode = INFO_MODE_MAIN;
3849 else if (button == MB_MENU_CHOICE)
3851 PlaySound(SND_MENU_ITEM_SELECTING);
3853 FadeMenuSoundsAndMusic();
3855 info_mode = INFO_MODE_MAIN;
3860 PlayMenuSoundIfLoop();
3864 static void DrawInfoScreen(void)
3866 if (info_mode == INFO_MODE_TITLE)
3867 DrawInfoScreen_TitleScreen();
3868 else if (info_mode == INFO_MODE_ELEMENTS)
3869 DrawInfoScreen_Elements();
3870 else if (info_mode == INFO_MODE_MUSIC)
3871 DrawInfoScreen_Music();
3872 else if (info_mode == INFO_MODE_CREDITS)
3873 DrawInfoScreen_Credits();
3874 else if (info_mode == INFO_MODE_PROGRAM)
3875 DrawInfoScreen_Program();
3876 else if (info_mode == INFO_MODE_VERSION)
3877 DrawInfoScreen_Version();
3878 else if (info_mode == INFO_MODE_LEVELSET)
3879 DrawInfoScreen_LevelSet();
3881 DrawInfoScreen_Main();
3883 if (info_mode != INFO_MODE_MAIN &&
3884 info_mode != INFO_MODE_TITLE &&
3885 info_mode != INFO_MODE_MUSIC)
3886 PlayMenuSoundsAndMusic();
3889 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3891 if (info_mode == INFO_MODE_TITLE)
3892 HandleInfoScreen_TitleScreen(button);
3893 else if (info_mode == INFO_MODE_ELEMENTS)
3894 HandleInfoScreen_Elements(button);
3895 else if (info_mode == INFO_MODE_MUSIC)
3896 HandleInfoScreen_Music(button);
3897 else if (info_mode == INFO_MODE_CREDITS)
3898 HandleInfoScreen_Credits(button);
3899 else if (info_mode == INFO_MODE_PROGRAM)
3900 HandleInfoScreen_Program(button);
3901 else if (info_mode == INFO_MODE_VERSION)
3902 HandleInfoScreen_Version(button);
3903 else if (info_mode == INFO_MODE_LEVELSET)
3904 HandleInfoScreen_LevelSet(button);
3906 HandleInfoScreen_Main(mx, my, dx, dy, button);
3910 /* ========================================================================= */
3911 /* type name functions */
3912 /* ========================================================================= */
3914 void HandleTypeName(int newxpos, Key key)
3916 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3917 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3918 struct TextPosInfo *pos = mci->pos_input;
3919 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3920 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3921 static int xpos = 0;
3922 int font_nr = pos->font;
3923 int font_active_nr = FONT_ACTIVE(font_nr);
3924 int font_width = getFontWidth(font_active_nr);
3925 char key_char = getValidConfigValueChar(getCharFromKey(key));
3926 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3927 boolean is_active = TRUE;
3929 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3933 strcpy(last_player_name, setup.player_name);
3937 StartTextInput(startx, starty, pos->width, pos->height);
3939 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3941 setup.player_name[xpos] = key_char;
3942 setup.player_name[xpos + 1] = 0;
3946 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3950 setup.player_name[xpos] = 0;
3952 else if (key == KSYM_Return && xpos > 0)
3958 SetGameStatus(GAME_MODE_MAIN);
3960 else if (key == KSYM_Escape)
3962 strcpy(setup.player_name, last_player_name);
3966 SetGameStatus(GAME_MODE_MAIN);
3971 pos->width = (strlen(setup.player_name) + 1) * font_width;
3972 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3974 DrawText(startx, starty, setup.player_name, font_active_nr);
3975 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
3979 pos->width = strlen(setup.player_name) * font_width;
3980 startx = mSX + ALIGNED_TEXT_XPOS(pos);
3982 DrawText(startx, starty, setup.player_name, font_nr);
3989 /* ========================================================================= */
3990 /* tree menu functions */
3991 /* ========================================================================= */
3993 static void DrawChooseTree(TreeInfo **ti_ptr)
3995 int fade_mask = REDRAW_FIELD;
3997 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
3998 fade_mask = REDRAW_ALL;
4000 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4002 SetGameStatus(GAME_MODE_MAIN);
4011 FreeScreenGadgets();
4012 CreateScreenGadgets();
4016 /* needed if different viewport properties defined for choosing level (set) */
4017 ChangeViewportPropertiesIfNeeded();
4019 if (game_status == GAME_MODE_LEVELNR)
4020 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4021 else if (game_status == GAME_MODE_LEVELS)
4022 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4026 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4028 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4029 MapScreenTreeGadgets(*ti_ptr);
4031 DrawMaskedBorder(fade_mask);
4036 static void drawChooseTreeList(int first_entry, int num_page_entries,
4040 char *title_string = NULL;
4041 int yoffset_sets = MENU_TITLE1_YPOS;
4042 int yoffset_setup = 16;
4043 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4044 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4046 title_string = ti->infotext;
4048 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4050 clearMenuListArea();
4052 for (i = 0; i < num_page_entries; i++)
4054 TreeInfo *node, *node_first;
4055 int entry_pos = first_entry + i;
4056 int xpos = MENU_SCREEN_START_XPOS;
4057 int ypos = MENU_SCREEN_START_YPOS + i;
4058 int startx = mSX + xpos * 32;
4059 int starty = mSY + ypos * 32;
4060 int font_nr = FONT_TEXT_1;
4061 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4062 int startx_text = startx + font_xoffset;
4063 int startx_scrollbar = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4064 int text_size = startx_scrollbar - startx_text;
4065 int max_buffer_len = text_size / getFontWidth(font_nr);
4066 char buffer[max_buffer_len + 1];
4068 node_first = getTreeInfoFirstGroupEntry(ti);
4069 node = getTreeInfoFromPos(node_first, entry_pos);
4071 strncpy(buffer, node->name, max_buffer_len);
4072 buffer[max_buffer_len] = '\0';
4074 DrawText(startx, starty, buffer, font_nr + node->color);
4076 if (node->parent_link)
4077 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4078 else if (node->level_group)
4079 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4081 initCursor(i, IMG_MENU_BUTTON);
4084 redraw_mask |= REDRAW_FIELD;
4087 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4089 TreeInfo *node, *node_first;
4090 int x, last_redraw_mask = redraw_mask;
4091 int ypos = MENU_TITLE2_YPOS;
4092 int font_nr = FONT_TITLE_2;
4094 if (ti->type == TREE_TYPE_LEVEL_NR)
4095 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4097 if (ti->type != TREE_TYPE_LEVEL_DIR)
4100 node_first = getTreeInfoFirstGroupEntry(ti);
4101 node = getTreeInfoFromPos(node_first, entry_pos);
4103 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4105 if (node->parent_link)
4106 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4107 node->node_parent->name);
4108 else if (node->level_group)
4109 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4111 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4112 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4113 node->levels, (node->levels > 1 ? "levels" : "level"),
4116 /* let BackToFront() redraw only what is needed */
4117 redraw_mask = last_redraw_mask;
4118 for (x = 0; x < SCR_FIELDX; x++)
4119 MarkTileDirty(x, 1);
4122 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4125 TreeInfo *ti = *ti_ptr;
4127 int y = ti->cl_cursor;
4128 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4129 int num_entries = numTreeInfoInGroup(ti);
4130 int num_page_entries;
4131 boolean position_set_by_scrollbar = (dx == 999);
4133 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
4134 num_page_entries = num_entries;
4136 num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
4138 if (button == MB_MENU_INITIALIZE)
4140 int num_entries = numTreeInfoInGroup(ti);
4141 int entry_pos = posTreeInfo(ti);
4143 if (ti->cl_first == -1)
4145 /* only on initialization */
4146 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4147 ti->cl_cursor = entry_pos - ti->cl_first;
4149 else if (ti->cl_cursor >= num_page_entries ||
4150 (num_entries > num_page_entries &&
4151 num_entries - ti->cl_first < num_page_entries))
4153 /* only after change of list size (by custom graphic configuration) */
4154 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4155 ti->cl_cursor = entry_pos - ti->cl_first;
4158 if (position_set_by_scrollbar)
4161 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4164 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4165 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4166 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4170 else if (button == MB_MENU_LEAVE)
4174 PlaySound(SND_MENU_ITEM_SELECTING);
4176 if (ti->node_parent)
4178 *ti_ptr = ti->node_parent;
4179 DrawChooseTree(ti_ptr);
4181 else if (game_status == GAME_MODE_SETUP)
4183 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4184 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4185 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4187 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4188 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4189 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4190 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4191 execSetupGraphics();
4192 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4193 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4194 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4196 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4197 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4198 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4199 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4200 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4201 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4202 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4203 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4210 if (game_status == GAME_MODE_LEVELNR)
4212 int new_level_nr = atoi(level_number_current->identifier);
4214 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4217 SetGameStatus(GAME_MODE_MAIN);
4225 if (mx || my) /* mouse input */
4227 x = (mx - mSX) / 32;
4228 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
4230 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
4232 /* move cursor instead of scrolling when already at start/end of list */
4233 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4235 else if (dy == +1 * SCROLL_LINE &&
4236 ti->cl_first + num_page_entries == num_entries)
4239 /* handle scrolling screen one line or page */
4240 if (ti->cl_cursor + dy < 0 ||
4241 ti->cl_cursor + dy > num_page_entries - 1)
4243 boolean redraw = FALSE;
4245 if (ABS(dy) == SCROLL_PAGE)
4246 step = num_page_entries - 1;
4248 if (dy < 0 && ti->cl_first > 0)
4250 /* scroll page/line up */
4252 ti->cl_first -= step;
4253 if (ti->cl_first < 0)
4258 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4260 /* scroll page/line down */
4262 ti->cl_first += step;
4263 if (ti->cl_first + num_page_entries > num_entries)
4264 ti->cl_first = MAX(0, num_entries - num_page_entries);
4271 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4272 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4273 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4275 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4282 /* handle moving cursor one line */
4283 y = ti->cl_cursor + dy;
4288 TreeInfo *node_first, *node_cursor;
4289 int entry_pos = ti->cl_first + y;
4291 node_first = getTreeInfoFirstGroupEntry(ti);
4292 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4294 if (node_cursor->node_group)
4298 PlaySound(SND_MENU_ITEM_SELECTING);
4300 node_cursor->cl_first = ti->cl_first;
4301 node_cursor->cl_cursor = ti->cl_cursor;
4302 *ti_ptr = node_cursor->node_group;
4303 DrawChooseTree(ti_ptr);
4308 else if (dx == -1 && ti->node_parent)
4312 PlaySound(SND_MENU_ITEM_SELECTING);
4314 *ti_ptr = ti->node_parent;
4315 DrawChooseTree(ti_ptr);
4320 if (!anyScrollbarGadgetActive() &&
4321 IN_VIS_MENU(x, y) &&
4322 mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x &&
4323 y >= 0 && y < num_page_entries)
4327 if (y != ti->cl_cursor)
4329 PlaySound(SND_MENU_ITEM_ACTIVATING);
4331 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4332 drawChooseTreeCursor(y, TRUE);
4333 drawChooseTreeInfo(ti->cl_first + y, ti);
4339 if (game_status == GAME_MODE_SETUP)
4341 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4342 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4343 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4345 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4346 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4347 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4348 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4349 execSetupGraphics();
4350 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4351 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4352 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4354 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4355 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4356 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4357 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4358 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4359 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4360 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4361 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4370 TreeInfo *node_first, *node_cursor;
4371 int entry_pos = ti->cl_first + y;
4373 PlaySound(SND_MENU_ITEM_SELECTING);
4375 node_first = getTreeInfoFirstGroupEntry(ti);
4376 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4378 if (node_cursor->node_group)
4382 node_cursor->cl_first = ti->cl_first;
4383 node_cursor->cl_cursor = ti->cl_cursor;
4384 *ti_ptr = node_cursor->node_group;
4385 DrawChooseTree(ti_ptr);
4387 else if (node_cursor->parent_link)
4391 *ti_ptr = node_cursor->node_parent;
4392 DrawChooseTree(ti_ptr);
4398 node_cursor->cl_first = ti->cl_first;
4399 node_cursor->cl_cursor = ti->cl_cursor;
4400 *ti_ptr = node_cursor;
4402 if (ti->type == TREE_TYPE_LEVEL_DIR)
4404 LoadLevelSetup_SeriesInfo();
4406 SaveLevelSetup_LastSeries();
4407 SaveLevelSetup_SeriesInfo();
4411 if (game_status == GAME_MODE_SETUP)
4413 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4414 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4415 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4417 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4418 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4419 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4420 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4421 execSetupGraphics();
4422 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4423 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4424 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4426 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4427 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4428 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4429 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4430 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4431 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4432 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4433 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4440 if (game_status == GAME_MODE_LEVELNR)
4442 int new_level_nr = atoi(level_number_current->identifier);
4444 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4447 SetGameStatus(GAME_MODE_MAIN);
4456 void DrawChooseLevelSet(void)
4458 FadeMenuSoundsAndMusic();
4460 DrawChooseTree(&leveldir_current);
4462 PlayMenuSoundsAndMusic();
4465 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4467 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4470 void DrawChooseLevelNr(void)
4474 FadeMenuSoundsAndMusic();
4476 if (level_number != NULL)
4478 freeTreeInfo(level_number);
4480 level_number = NULL;
4483 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4485 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4486 char identifier[32], name[32];
4489 /* temporarily load level info to get level name */
4490 LoadLevelInfoOnly(i);
4492 ti->node_top = &level_number;
4493 ti->sort_priority = 10000 + value;
4494 ti->color = (level.no_level_file ? FC_BLUE :
4495 LevelStats_getSolved(i) ? FC_GREEN :
4496 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4498 snprintf(identifier, sizeof(identifier), "%d", value);
4499 snprintf(name, sizeof(name), "%03d: %s", value,
4500 (level.no_level_file ? "(no file)" : level.name));
4502 setString(&ti->identifier, identifier);
4503 setString(&ti->name, name);
4504 setString(&ti->name_sorting, name);
4506 pushTreeInfo(&level_number, ti);
4509 /* sort level number values to start with lowest level number */
4510 sortTreeInfo(&level_number);
4512 /* set current level number to current level number */
4513 level_number_current =
4514 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4516 /* if that also fails, set current level number to first available level */
4517 if (level_number_current == NULL)
4518 level_number_current = level_number;
4520 DrawChooseTree(&level_number_current);
4522 PlayMenuSoundsAndMusic();
4525 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4527 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4530 void DrawHallOfFame(int level_nr, int highlight_position)
4532 int fade_mask = REDRAW_FIELD;
4534 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
4535 fade_mask = REDRAW_ALL;
4538 FadeMenuSoundsAndMusic();
4540 /* (this is needed when called from GameEnd() after winning a game) */
4541 KeyboardAutoRepeatOn();
4543 /* (this is needed when called from GameEnd() after winning a game) */
4544 SetDrawDeactivationMask(REDRAW_NONE);
4545 SetDrawBackgroundMask(REDRAW_FIELD);
4547 if (highlight_position < 0)
4548 LoadScore(level_nr);
4550 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4552 FadeSetEnterScreen();
4556 /* needed if different viewport properties defined for scores */
4557 ChangeViewportPropertiesIfNeeded();
4559 PlayMenuSoundsAndMusic();
4561 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4563 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4565 DrawMaskedBorder(fade_mask);
4570 static void drawHallOfFameList(int level_nr, int first_entry,
4571 int highlight_position)
4575 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4578 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4579 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4580 "HighScores of Level %d", level_nr);
4582 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4584 int entry = first_entry + i;
4585 boolean active = (entry == highlight_position);
4586 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4587 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4588 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4589 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4590 int dxoff = getFontDrawOffsetX(font_nr1);
4591 int dx1 = 3 * getFontWidth(font_nr1);
4592 int dx2 = dx1 + getFontWidth(font_nr1);
4593 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4594 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4595 int sy = mSY + 64 + i * 32;
4597 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4598 DrawText(mSX + dx1, sy, ".", font_nr1);
4600 for (j = 0; j < num_dots; j++)
4601 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4603 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4604 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4606 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4609 redraw_mask |= REDRAW_FIELD;
4612 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4614 static int level_nr = 0;
4615 static int first_entry = 0;
4616 static int highlight_position = 0;
4617 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4619 if (button == MB_MENU_INITIALIZE)
4623 highlight_position = my;
4625 drawHallOfFameList(level_nr, first_entry, highlight_position);
4630 if (ABS(dy) == SCROLL_PAGE) /* handle scrolling one page */
4631 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4635 if (first_entry > 0)
4637 first_entry -= step;
4638 if (first_entry < 0)
4641 drawHallOfFameList(level_nr, first_entry, highlight_position);
4646 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4648 first_entry += step;
4649 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4650 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4652 drawHallOfFameList(level_nr, first_entry, highlight_position);
4655 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4657 PlaySound(SND_MENU_ITEM_SELECTING);
4659 FadeSound(SND_BACKGROUND_SCORES);
4661 if (game_status_last_screen == GAME_MODE_PLAYING &&
4662 setup.auto_play_next_level && setup.increment_levels &&
4665 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4669 SetGameStatus(GAME_MODE_MAIN);
4675 if (game_status == GAME_MODE_SCORES)
4676 PlayMenuSoundIfLoop();
4680 /* ========================================================================= */
4681 /* setup screen functions */
4682 /* ========================================================================= */
4684 static struct TokenInfo *setup_info;
4685 static int num_setup_info; /* number of setup entries shown on screen */
4686 static int max_setup_info; /* total number of setup entries in list */
4688 static char *window_size_text;
4689 static char *scaling_type_text;
4690 static char *rendering_mode_text;
4691 static char *vsync_mode_text;
4692 static char *scroll_delay_text;
4693 static char *snapshot_mode_text;
4694 static char *game_speed_text;
4695 static char *graphics_set_name;
4696 static char *sounds_set_name;
4697 static char *music_set_name;
4698 static char *volume_simple_text;
4699 static char *volume_loops_text;
4700 static char *volume_music_text;
4701 static char *touch_controls_text;
4702 static char *move_distance_text;
4703 static char *drop_distance_text;
4704 static char *transparency_text;
4705 static char *grid_size_text[2][2];
4707 static void execSetupMain(void)
4709 setup_mode = SETUP_MODE_MAIN;
4714 static void execSetupGame_setGameSpeeds(void)
4716 if (game_speeds == NULL)
4720 for (i = 0; game_speeds_list[i].value != -1; i++)
4722 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4723 char identifier[32], name[32];
4724 int value = game_speeds_list[i].value;
4725 char *text = game_speeds_list[i].text;
4727 ti->node_top = &game_speeds;
4728 ti->sort_priority = 10000 - value;
4730 sprintf(identifier, "%d", value);
4731 sprintf(name, "%s", text);
4733 setString(&ti->identifier, identifier);
4734 setString(&ti->name, name);
4735 setString(&ti->name_sorting, name);
4736 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4738 pushTreeInfo(&game_speeds, ti);
4741 /* sort game speed values to start with slowest game speed */
4742 sortTreeInfo(&game_speeds);
4744 /* set current game speed to configured game speed value */
4745 game_speed_current =
4746 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4748 /* if that fails, set current game speed to reliable default value */
4749 if (game_speed_current == NULL)
4750 game_speed_current =
4751 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4753 /* if that also fails, set current game speed to first available speed */
4754 if (game_speed_current == NULL)
4755 game_speed_current = game_speeds;
4758 setup.game_frame_delay = atoi(game_speed_current->identifier);
4760 /* needed for displaying game speed text instead of identifier */
4761 game_speed_text = game_speed_current->name;
4764 static void execSetupGame_setScrollDelays(void)
4766 if (scroll_delays == NULL)
4770 for (i = 0; scroll_delays_list[i].value != -1; i++)
4772 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4773 char identifier[32], name[32];
4774 int value = scroll_delays_list[i].value;
4775 char *text = scroll_delays_list[i].text;
4777 ti->node_top = &scroll_delays;
4778 ti->sort_priority = value;
4780 sprintf(identifier, "%d", value);
4781 sprintf(name, "%s", text);
4783 setString(&ti->identifier, identifier);
4784 setString(&ti->name, name);
4785 setString(&ti->name_sorting, name);
4786 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4788 pushTreeInfo(&scroll_delays, ti);
4791 /* sort scroll delay values to start with lowest scroll delay value */
4792 sortTreeInfo(&scroll_delays);
4794 /* set current scroll delay value to configured scroll delay value */
4795 scroll_delay_current =
4796 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4798 /* if that fails, set current scroll delay to reliable default value */
4799 if (scroll_delay_current == NULL)
4800 scroll_delay_current =
4801 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4803 /* if that also fails, set current scroll delay to first available value */
4804 if (scroll_delay_current == NULL)
4805 scroll_delay_current = scroll_delays;
4808 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4810 /* needed for displaying scroll delay text instead of identifier */
4811 scroll_delay_text = scroll_delay_current->name;
4814 static void execSetupGame_setSnapshotModes(void)
4816 if (snapshot_modes == NULL)
4820 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4822 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4823 char identifier[32], name[32];
4824 char *value = snapshot_modes_list[i].value;
4825 char *text = snapshot_modes_list[i].text;
4827 ti->node_top = &snapshot_modes;
4828 ti->sort_priority = i;
4830 sprintf(identifier, "%s", value);
4831 sprintf(name, "%s", text);
4833 setString(&ti->identifier, identifier);
4834 setString(&ti->name, name);
4835 setString(&ti->name_sorting, name);
4836 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4838 pushTreeInfo(&snapshot_modes, ti);
4841 /* sort snapshot mode values to start with lowest snapshot mode value */
4842 sortTreeInfo(&snapshot_modes);
4844 /* set current snapshot mode value to configured snapshot mode value */
4845 snapshot_mode_current =
4846 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4848 /* if that fails, set current snapshot mode to reliable default value */
4849 if (snapshot_mode_current == NULL)
4850 snapshot_mode_current =
4851 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4853 /* if that also fails, set current snapshot mode to first available value */
4854 if (snapshot_mode_current == NULL)
4855 snapshot_mode_current = snapshot_modes;
4858 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4860 /* needed for displaying snapshot mode text instead of identifier */
4861 snapshot_mode_text = snapshot_mode_current->name;
4864 static void execSetupGame(void)
4866 execSetupGame_setGameSpeeds();
4867 execSetupGame_setScrollDelays();
4868 execSetupGame_setSnapshotModes();
4870 setup_mode = SETUP_MODE_GAME;
4875 static void execSetupChooseGameSpeed(void)
4877 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
4882 static void execSetupChooseScrollDelay(void)
4884 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
4889 static void execSetupChooseSnapshotMode(void)
4891 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
4896 static void execSetupEditor(void)
4898 setup_mode = SETUP_MODE_EDITOR;
4903 static void execSetupGraphics_setWindowSizes(boolean update_list)
4905 if (window_sizes != NULL && update_list)
4907 freeTreeInfo(window_sizes);
4909 window_sizes = NULL;
4912 if (window_sizes == NULL)
4914 boolean current_window_size_found = FALSE;
4917 for (i = 0; window_sizes_list[i].value != -1; i++)
4919 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4920 char identifier[32], name[32];
4921 int value = window_sizes_list[i].value;
4922 char *text = window_sizes_list[i].text;
4924 ti->node_top = &window_sizes;
4925 ti->sort_priority = value;
4927 sprintf(identifier, "%d", value);
4928 sprintf(name, "%s", text);
4930 setString(&ti->identifier, identifier);
4931 setString(&ti->name, name);
4932 setString(&ti->name_sorting, name);
4933 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4935 pushTreeInfo(&window_sizes, ti);
4937 if (value == setup.window_scaling_percent)
4938 current_window_size_found = TRUE;
4941 if (!current_window_size_found)
4943 // add entry for non-preset window scaling value
4945 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4946 char identifier[32], name[32];
4947 int value = setup.window_scaling_percent;
4949 ti->node_top = &window_sizes;
4950 ti->sort_priority = value;
4952 sprintf(identifier, "%d", value);
4953 sprintf(name, "%d %% (Current)", value);
4955 setString(&ti->identifier, identifier);
4956 setString(&ti->name, name);
4957 setString(&ti->name_sorting, name);
4958 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
4960 pushTreeInfo(&window_sizes, ti);
4963 /* sort window size values to start with lowest window size value */
4964 sortTreeInfo(&window_sizes);
4966 /* set current window size value to configured window size value */
4967 window_size_current =
4968 getTreeInfoFromIdentifier(window_sizes,
4969 i_to_a(setup.window_scaling_percent));
4971 /* if that fails, set current window size to reliable default value */
4972 if (window_size_current == NULL)
4973 window_size_current =
4974 getTreeInfoFromIdentifier(window_sizes,
4975 i_to_a(STD_WINDOW_SCALING_PERCENT));
4977 /* if that also fails, set current window size to first available value */
4978 if (window_size_current == NULL)
4979 window_size_current = window_sizes;
4982 setup.window_scaling_percent = atoi(window_size_current->identifier);
4984 /* needed for displaying window size text instead of identifier */
4985 window_size_text = window_size_current->name;
4988 static void execSetupGraphics_setScalingTypes(void)
4990 if (scaling_types == NULL)
4994 for (i = 0; scaling_types_list[i].value != NULL; i++)
4996 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4997 char identifier[32], name[32];
4998 char *value = scaling_types_list[i].value;
4999 char *text = scaling_types_list[i].text;
5001 ti->node_top = &scaling_types;
5002 ti->sort_priority = i;
5004 sprintf(identifier, "%s", value);
5005 sprintf(name, "%s", text);
5007 setString(&ti->identifier, identifier);
5008 setString(&ti->name, name);
5009 setString(&ti->name_sorting, name);
5010 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5012 pushTreeInfo(&scaling_types, ti);
5015 /* sort scaling type values to start with lowest scaling type value */
5016 sortTreeInfo(&scaling_types);
5018 /* set current scaling type value to configured scaling type value */
5019 scaling_type_current =
5020 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5022 /* if that fails, set current scaling type to reliable default value */
5023 if (scaling_type_current == NULL)
5024 scaling_type_current =
5025 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5027 /* if that also fails, set current scaling type to first available value */
5028 if (scaling_type_current == NULL)
5029 scaling_type_current = scaling_types;
5032 setup.window_scaling_quality = scaling_type_current->identifier;
5034 /* needed for displaying scaling type text instead of identifier */
5035 scaling_type_text = scaling_type_current->name;
5038 static void execSetupGraphics_setRenderingModes(void)
5040 if (rendering_modes == NULL)
5044 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5046 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5047 char identifier[32], name[32];
5048 char *value = rendering_modes_list[i].value;
5049 char *text = rendering_modes_list[i].text;
5051 ti->node_top = &rendering_modes;
5052 ti->sort_priority = i;
5054 sprintf(identifier, "%s", value);
5055 sprintf(name, "%s", text);
5057 setString(&ti->identifier, identifier);
5058 setString(&ti->name, name);
5059 setString(&ti->name_sorting, name);
5060 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5062 pushTreeInfo(&rendering_modes, ti);
5065 /* sort rendering mode values to start with lowest rendering mode value */
5066 sortTreeInfo(&rendering_modes);
5068 /* set current rendering mode value to configured rendering mode value */
5069 rendering_mode_current =
5070 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5072 /* if that fails, set current rendering mode to reliable default value */
5073 if (rendering_mode_current == NULL)
5074 rendering_mode_current =
5075 getTreeInfoFromIdentifier(rendering_modes,
5076 STR_SPECIAL_RENDERING_DEFAULT);
5078 /* if that also fails, set current rendering mode to first available one */
5079 if (rendering_mode_current == NULL)
5080 rendering_mode_current = rendering_modes;
5083 setup.screen_rendering_mode = rendering_mode_current->identifier;
5085 /* needed for displaying rendering mode text instead of identifier */
5086 rendering_mode_text = rendering_mode_current->name;
5089 static void execSetupGraphics_setVsyncModes(void)
5091 if (vsync_modes == NULL)
5095 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5097 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5098 char identifier[32], name[32];
5099 char *value = vsync_modes_list[i].value;
5100 char *text = vsync_modes_list[i].text;
5102 ti->node_top = &vsync_modes;
5103 ti->sort_priority = i;
5105 sprintf(identifier, "%s", value);
5106 sprintf(name, "%s", text);
5108 setString(&ti->identifier, identifier);
5109 setString(&ti->name, name);
5110 setString(&ti->name_sorting, name);
5111 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5113 pushTreeInfo(&vsync_modes, ti);
5116 /* sort vsync mode values to start with lowest vsync mode value */
5117 sortTreeInfo(&vsync_modes);
5119 /* set current vsync mode value to configured vsync mode value */
5120 vsync_mode_current =
5121 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5123 /* if that fails, set current vsync mode to reliable default value */
5124 if (vsync_mode_current == NULL)
5125 vsync_mode_current =
5126 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5128 /* if that also fails, set current vsync mode to first available one */
5129 if (vsync_mode_current == NULL)
5130 vsync_mode_current = vsync_modes;
5133 setup.vsync_mode = vsync_mode_current->identifier;
5135 /* needed for displaying vsync mode text instead of identifier */
5136 vsync_mode_text = vsync_mode_current->name;
5139 static void execSetupGraphics(void)
5141 // update "setup.window_scaling_percent" from list selection
5142 // (in this case, window scaling was changed on setup screen)
5143 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5144 execSetupGraphics_setWindowSizes(FALSE);
5146 // update list selection from "setup.window_scaling_percent"
5147 // (window scaling may have changed by resizing the window)
5148 execSetupGraphics_setWindowSizes(TRUE);
5150 execSetupGraphics_setScalingTypes();
5151 execSetupGraphics_setRenderingModes();
5152 execSetupGraphics_setVsyncModes();
5154 setup_mode = SETUP_MODE_GRAPHICS;
5158 #if defined(TARGET_SDL2)
5159 // window scaling may have changed at this point
5160 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5162 // window scaling quality may have changed at this point
5163 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5164 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5166 // screen rendering mode may have changed at this point
5167 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5169 // screen vsync mode may have changed at this point
5170 SDLSetScreenVsyncMode(setup.vsync_mode);
5174 static void execSetupChooseWindowSize(void)
5176 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5181 static void execSetupChooseScalingType(void)
5183 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5188 static void execSetupChooseRenderingMode(void)
5190 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5195 static void execSetupChooseVsyncMode(void)
5197 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5202 static void execSetupChooseVolumeSimple(void)
5204 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5209 static void execSetupChooseVolumeLoops(void)
5211 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5216 static void execSetupChooseVolumeMusic(void)
5218 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5223 static void execSetupSound(void)
5225 if (volumes_simple == NULL)
5227 boolean current_volume_simple_found = FALSE;
5230 for (i = 0; volumes_list[i].value != -1; i++)
5232 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5233 char identifier[32], name[32];
5234 int value = volumes_list[i].value;
5235 char *text = volumes_list[i].text;
5237 ti->node_top = &volumes_simple;
5238 ti->sort_priority = value;
5240 sprintf(identifier, "%d", value);
5241 sprintf(name, "%s", text);
5243 setString(&ti->identifier, identifier);
5244 setString(&ti->name, name);
5245 setString(&ti->name_sorting, name);
5246 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5248 pushTreeInfo(&volumes_simple, ti);
5250 if (value == setup.volume_simple)
5251 current_volume_simple_found = TRUE;
5254 if (!current_volume_simple_found)
5256 // add entry for non-preset volume value
5258 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5259 char identifier[32], name[32];
5260 int value = setup.volume_simple;
5262 ti->node_top = &volumes_simple;
5263 ti->sort_priority = value;
5265 sprintf(identifier, "%d", value);
5266 sprintf(name, "%d %% (Current)", value);
5268 setString(&ti->identifier, identifier);
5269 setString(&ti->name, name);
5270 setString(&ti->name_sorting, name);
5271 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5273 pushTreeInfo(&volumes_simple, ti);
5276 /* sort volume values to start with lowest volume value */
5277 sortTreeInfo(&volumes_simple);
5279 /* set current volume value to configured volume value */
5280 volume_simple_current =
5281 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5283 /* if that fails, set current volume to reliable default value */
5284 if (volume_simple_current == NULL)
5285 volume_simple_current =
5286 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5288 /* if that also fails, set current volume to first available value */
5289 if (volume_simple_current == NULL)
5290 volume_simple_current = volumes_simple;
5293 if (volumes_loops == NULL)
5295 boolean current_volume_loops_found = FALSE;
5298 for (i = 0; volumes_list[i].value != -1; i++)
5300 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5301 char identifier[32], name[32];
5302 int value = volumes_list[i].value;
5303 char *text = volumes_list[i].text;
5305 ti->node_top = &volumes_loops;
5306 ti->sort_priority = value;
5308 sprintf(identifier, "%d", value);
5309 sprintf(name, "%s", text);
5311 setString(&ti->identifier, identifier);
5312 setString(&ti->name, name);
5313 setString(&ti->name_sorting, name);
5314 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5316 pushTreeInfo(&volumes_loops, ti);
5318 if (value == setup.volume_loops)
5319 current_volume_loops_found = TRUE;
5322 if (!current_volume_loops_found)
5324 // add entry for non-preset volume value
5326 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5327 char identifier[32], name[32];
5328 int value = setup.volume_loops;
5330 ti->node_top = &volumes_loops;
5331 ti->sort_priority = value;
5333 sprintf(identifier, "%d", value);
5334 sprintf(name, "%d %% (Current)", value);
5336 setString(&ti->identifier, identifier);
5337 setString(&ti->name, name);
5338 setString(&ti->name_sorting, name);
5339 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5341 pushTreeInfo(&volumes_loops, ti);
5344 /* sort volume values to start with lowest volume value */
5345 sortTreeInfo(&volumes_loops);
5347 /* set current volume value to configured volume value */
5348 volume_loops_current =
5349 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5351 /* if that fails, set current volume to reliable default value */
5352 if (volume_loops_current == NULL)
5353 volume_loops_current =
5354 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5356 /* if that also fails, set current volume to first available value */
5357 if (volume_loops_current == NULL)
5358 volume_loops_current = volumes_loops;
5361 if (volumes_music == NULL)
5363 boolean current_volume_music_found = FALSE;
5366 for (i = 0; volumes_list[i].value != -1; i++)
5368 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5369 char identifier[32], name[32];
5370 int value = volumes_list[i].value;
5371 char *text = volumes_list[i].text;
5373 ti->node_top = &volumes_music;
5374 ti->sort_priority = value;
5376 sprintf(identifier, "%d", value);
5377 sprintf(name, "%s", text);
5379 setString(&ti->identifier, identifier);
5380 setString(&ti->name, name);
5381 setString(&ti->name_sorting, name);
5382 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5384 pushTreeInfo(&volumes_music, ti);
5386 if (value == setup.volume_music)
5387 current_volume_music_found = TRUE;
5390 if (!current_volume_music_found)
5392 // add entry for non-preset volume value
5394 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5395 char identifier[32], name[32];
5396 int value = setup.volume_music;
5398 ti->node_top = &volumes_music;
5399 ti->sort_priority = value;
5401 sprintf(identifier, "%d", value);
5402 sprintf(name, "%d %% (Current)", value);
5404 setString(&ti->identifier, identifier);
5405 setString(&ti->name, name);
5406 setString(&ti->name_sorting, name);
5407 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5409 pushTreeInfo(&volumes_music, ti);
5412 /* sort volume values to start with lowest volume value */
5413 sortTreeInfo(&volumes_music);
5415 /* set current volume value to configured volume value */
5416 volume_music_current =
5417 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5419 /* if that fails, set current volume to reliable default value */
5420 if (volume_music_current == NULL)
5421 volume_music_current =
5422 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5424 /* if that also fails, set current volume to first available value */
5425 if (volume_music_current == NULL)
5426 volume_music_current = volumes_music;
5429 setup.volume_simple = atoi(volume_simple_current->identifier);
5430 setup.volume_loops = atoi(volume_loops_current->identifier);
5431 setup.volume_music = atoi(volume_music_current->identifier);
5433 /* needed for displaying volume text instead of identifier */
5434 volume_simple_text = volume_simple_current->name;
5435 volume_loops_text = volume_loops_current->name;
5436 volume_music_text = volume_music_current->name;
5438 setup_mode = SETUP_MODE_SOUND;
5443 static void execSetupChooseTouchControls(void)
5445 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5450 static void execSetupChooseMoveDistance(void)
5452 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5457 static void execSetupChooseDropDistance(void)
5459 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5464 static void execSetupChooseTransparency(void)
5466 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5471 static void execSetupChooseGridXSize_0(void)
5473 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5478 static void execSetupChooseGridYSize_0(void)
5480 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5485 static void execSetupChooseGridXSize_1(void)
5487 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5492 static void execSetupChooseGridYSize_1(void)
5494 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5499 static void execSetupConfigureVirtualButtons(void)
5501 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5503 ConfigureVirtualButtons();
5505 setup_mode = SETUP_MODE_TOUCH;
5510 static void execSetupTouch(void)
5514 if (touch_controls == NULL)
5516 for (i = 0; touch_controls_list[i].value != NULL; i++)
5518 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5519 char identifier[32], name[32];
5520 char *value = touch_controls_list[i].value;
5521 char *text = touch_controls_list[i].text;
5523 ti->node_top = &touch_controls;
5524 ti->sort_priority = i;
5526 sprintf(identifier, "%s", value);
5527 sprintf(name, "%s", text);
5529 setString(&ti->identifier, identifier);
5530 setString(&ti->name, name);
5531 setString(&ti->name_sorting, name);
5532 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5534 pushTreeInfo(&touch_controls, ti);
5537 /* sort touch control values to start with lowest touch control value */
5538 sortTreeInfo(&touch_controls);
5540 /* set current touch control value to configured touch control value */
5541 touch_control_current =
5542 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5544 /* if that fails, set current touch control to reliable default value */
5545 if (touch_control_current == NULL)
5546 touch_control_current =
5547 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5549 /* if that also fails, set current touch control to first available value */
5550 if (touch_control_current == NULL)
5551 touch_control_current = touch_controls;
5554 if (move_distances == NULL)
5556 for (i = 0; distances_list[i].value != -1; i++)
5558 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5559 char identifier[32], name[32];
5560 int value = distances_list[i].value;
5561 char *text = distances_list[i].text;
5563 ti->node_top = &move_distances;
5564 ti->sort_priority = value;
5566 sprintf(identifier, "%d", value);
5567 sprintf(name, "%s", text);
5569 setString(&ti->identifier, identifier);
5570 setString(&ti->name, name);
5571 setString(&ti->name_sorting, name);
5572 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5574 pushTreeInfo(&move_distances, ti);
5577 /* sort distance values to start with lowest distance value */
5578 sortTreeInfo(&move_distances);
5580 /* set current distance value to configured distance value */
5581 move_distance_current =
5582 getTreeInfoFromIdentifier(move_distances,
5583 i_to_a(setup.touch.move_distance));
5585 /* if that fails, set current distance to reliable default value */
5586 if (move_distance_current == NULL)
5587 move_distance_current =
5588 getTreeInfoFromIdentifier(move_distances,
5589 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5591 /* if that also fails, set current distance to first available value */
5592 if (move_distance_current == NULL)
5593 move_distance_current = move_distances;
5596 if (drop_distances == NULL)
5598 for (i = 0; distances_list[i].value != -1; i++)
5600 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5601 char identifier[32], name[32];
5602 int value = distances_list[i].value;
5603 char *text = distances_list[i].text;
5605 ti->node_top = &drop_distances;
5606 ti->sort_priority = value;
5608 sprintf(identifier, "%d", value);
5609 sprintf(name, "%s", text);
5611 setString(&ti->identifier, identifier);
5612 setString(&ti->name, name);
5613 setString(&ti->name_sorting, name);
5614 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5616 pushTreeInfo(&drop_distances, ti);
5619 /* sort distance values to start with lowest distance value */
5620 sortTreeInfo(&drop_distances);
5622 /* set current distance value to configured distance value */
5623 drop_distance_current =
5624 getTreeInfoFromIdentifier(drop_distances,
5625 i_to_a(setup.touch.drop_distance));
5627 /* if that fails, set current distance to reliable default value */
5628 if (drop_distance_current == NULL)
5629 drop_distance_current =
5630 getTreeInfoFromIdentifier(drop_distances,
5631 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5633 /* if that also fails, set current distance to first available value */
5634 if (drop_distance_current == NULL)
5635 drop_distance_current = drop_distances;
5638 if (transparencies == NULL)
5640 for (i = 0; transparencies_list[i].value != -1; i++)
5642 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5643 char identifier[32], name[32];
5644 int value = transparencies_list[i].value;
5645 char *text = transparencies_list[i].text;
5647 ti->node_top = &transparencies;
5648 ti->sort_priority = value;
5650 sprintf(identifier, "%d", value);
5651 sprintf(name, "%s", text);
5653 setString(&ti->identifier, identifier);
5654 setString(&ti->name, name);
5655 setString(&ti->name_sorting, name);
5656 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5658 pushTreeInfo(&transparencies, ti);
5661 /* sort transparency values to start with lowest transparency value */
5662 sortTreeInfo(&transparencies);
5664 /* set current transparency value to configured transparency value */
5665 transparency_current =
5666 getTreeInfoFromIdentifier(transparencies,
5667 i_to_a(setup.touch.transparency));
5669 /* if that fails, set current transparency to reliable default value */
5670 if (transparency_current == NULL)
5671 transparency_current =
5672 getTreeInfoFromIdentifier(transparencies,
5673 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5675 /* if that also fails, set current transparency to first available value */
5676 if (transparency_current == NULL)
5677 transparency_current = transparencies;
5680 for (i = 0; i < 2; i++)
5682 for (j = 0; j < 2; j++)
5684 if (grid_sizes[i][j] == NULL)
5686 for (k = 0; grid_sizes_list[k].value != -1; k++)
5688 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5689 char identifier[32], name[32];
5690 int value = grid_sizes_list[k].value;
5691 char *text = grid_sizes_list[k].text;
5693 ti->node_top = &grid_sizes[i][j];
5694 ti->sort_priority = value;
5696 sprintf(identifier, "%d", value);
5697 sprintf(name, "%s", text);
5699 setString(&ti->identifier, identifier);
5700 setString(&ti->name, name);
5701 setString(&ti->name_sorting, name);
5702 setString(&ti->infotext,
5705 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5706 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5708 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5709 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5711 pushTreeInfo(&grid_sizes[i][j], ti);
5714 /* sort grid size values to start with lowest grid size value */
5715 sortTreeInfo(&grid_sizes[i][j]);
5717 /* set current grid size value to configured grid size value */
5718 grid_size_current[i][j] =
5719 getTreeInfoFromIdentifier(grid_sizes[i][j],
5721 setup.touch.grid_xsize[i] :
5722 setup.touch.grid_ysize[i]));
5724 /* if that fails, set current grid size to reliable default value */
5725 if (grid_size_current[i][j] == NULL)
5726 grid_size_current[i][j] =
5727 getTreeInfoFromIdentifier(grid_sizes[i][j],
5729 DEFAULT_GRID_XSIZE(i) :
5730 DEFAULT_GRID_YSIZE(i)));
5732 /* if that also fails, set current grid size to first available value */
5733 if (grid_size_current[i][j] == NULL)
5734 grid_size_current[i][j] = grid_sizes[i][j];
5739 setup.touch.control_type = touch_control_current->identifier;
5740 setup.touch.move_distance = atoi(move_distance_current->identifier);
5741 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5742 setup.touch.transparency = atoi(transparency_current->identifier);
5744 for (i = 0; i < 2; i++)
5746 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5747 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5749 if (i == GRID_ACTIVE_NR())
5751 overlay.grid_xsize = setup.touch.grid_xsize[i];
5752 overlay.grid_ysize = setup.touch.grid_ysize[i];
5756 /* needed for displaying value text instead of identifier */
5757 touch_controls_text = touch_control_current->name;
5758 move_distance_text = move_distance_current->name;
5759 drop_distance_text = drop_distance_current->name;
5760 transparency_text = transparency_current->name;
5762 for (i = 0; i < 2; i++)
5763 for (j = 0; j < 2; j++)
5764 grid_size_text[i][j] = grid_size_current[i][j]->name;
5766 setup_mode = SETUP_MODE_TOUCH;
5771 static void execSetupArtwork(void)
5774 printf("::: '%s', '%s', '%s'\n",
5775 artwork.gfx_current->subdir,
5776 artwork.gfx_current->fullpath,
5777 artwork.gfx_current->basepath);
5780 setup.graphics_set = artwork.gfx_current->identifier;
5781 setup.sounds_set = artwork.snd_current->identifier;
5782 setup.music_set = artwork.mus_current->identifier;
5784 /* needed if last screen (setup choice) changed graphics, sounds or music */
5785 ReloadCustomArtwork(0);
5787 /* needed for displaying artwork name instead of artwork identifier */
5788 graphics_set_name = artwork.gfx_current->name;
5789 sounds_set_name = artwork.snd_current->name;
5790 music_set_name = artwork.mus_current->name;
5792 setup_mode = SETUP_MODE_ARTWORK;
5797 static void execSetupChooseGraphics(void)
5799 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5804 static void execSetupChooseSounds(void)
5806 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5811 static void execSetupChooseMusic(void)
5813 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5818 static void execSetupInput(void)
5820 setup_mode = SETUP_MODE_INPUT;
5825 static void execSetupShortcuts(void)
5827 setup_mode = SETUP_MODE_SHORTCUTS;
5832 static void execSetupShortcuts1(void)
5834 setup_mode = SETUP_MODE_SHORTCUTS_1;
5839 static void execSetupShortcuts2(void)
5841 setup_mode = SETUP_MODE_SHORTCUTS_2;
5846 static void execSetupShortcuts3(void)
5848 setup_mode = SETUP_MODE_SHORTCUTS_3;
5853 static void execSetupShortcuts4(void)
5855 setup_mode = SETUP_MODE_SHORTCUTS_4;
5860 static void execSetupShortcuts5(void)
5862 setup_mode = SETUP_MODE_SHORTCUTS_5;
5867 static void execExitSetup(void)
5869 SetGameStatus(GAME_MODE_MAIN);
5874 static void execSaveAndExitSetup(void)
5883 void *related_value;
5884 } hide_related_entry_list[] =
5886 { &setup.game_frame_delay, execSetupChooseGameSpeed },
5887 { &setup.game_frame_delay, &game_speed_text },
5889 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
5890 { &setup.scroll_delay_value, &scroll_delay_text },
5892 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
5893 { &setup.engine_snapshot_mode, &snapshot_mode_text },
5895 { &setup.window_scaling_percent, execSetupChooseWindowSize },
5896 { &setup.window_scaling_percent, &window_size_text },
5898 { &setup.window_scaling_quality, execSetupChooseScalingType },
5899 { &setup.window_scaling_quality, &scaling_type_text },
5901 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
5902 { &setup.screen_rendering_mode, &rendering_mode_text },
5904 { &setup.vsync_mode, execSetupChooseVsyncMode },
5905 { &setup.vsync_mode, &vsync_mode_text },
5907 { &setup.graphics_set, execSetupChooseGraphics },
5908 { &setup.graphics_set, &graphics_set_name },
5910 { &setup.sounds_set, execSetupChooseSounds },
5911 { &setup.sounds_set, &sounds_set_name },
5913 { &setup.music_set, execSetupChooseMusic },
5914 { &setup.music_set, &music_set_name },
5916 { &setup.volume_simple, execSetupChooseVolumeSimple },
5917 { &setup.volume_simple, &volume_simple_text },
5919 { &setup.volume_loops, execSetupChooseVolumeLoops },
5920 { &setup.volume_loops, &volume_loops_text },
5922 { &setup.volume_music, execSetupChooseVolumeMusic },
5923 { &setup.volume_music, &volume_music_text },
5925 { &setup.touch.control_type, execSetupChooseTouchControls },
5926 { &setup.touch.control_type, &touch_controls_text },
5928 { &setup.touch.move_distance, execSetupChooseMoveDistance },
5929 { &setup.touch.move_distance, &move_distance_text },
5931 { &setup.touch.drop_distance, execSetupChooseDropDistance },
5932 { &setup.touch.drop_distance, &drop_distance_text },
5934 { &setup.touch.transparency, execSetupChooseTransparency },
5935 { &setup.touch.transparency, &transparency_text },
5937 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
5938 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
5940 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
5941 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
5943 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
5944 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
5946 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
5947 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
5952 void setHideRelatedSetupEntries(void)
5956 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
5957 if (hideSetupEntry(hide_related_entry_list[i].value))
5958 setHideSetupEntry(hide_related_entry_list[i].related_value);
5961 static struct TokenInfo setup_info_main[] =
5963 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
5964 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
5965 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
5966 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
5967 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
5968 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
5969 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
5970 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
5971 { TYPE_EMPTY, NULL, "" },
5972 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
5973 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
5978 static struct TokenInfo setup_info_game[] =
5980 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
5981 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
5982 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
5983 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
5984 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
5985 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
5986 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
5987 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
5988 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
5989 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
5990 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
5991 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
5992 { TYPE_STRING, &game_speed_text, "" },
5994 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
5995 { TYPE_STRING, &scroll_delay_text, "" },
5997 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
5998 { TYPE_STRING, &snapshot_mode_text, "" },
5999 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6000 { TYPE_EMPTY, NULL, "" },
6001 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6006 static struct TokenInfo setup_info_editor[] =
6009 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6010 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6011 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6012 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6013 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6014 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6015 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6016 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6017 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6018 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6020 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6021 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6023 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6025 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6026 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6027 { TYPE_EMPTY, NULL, "" },
6029 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6030 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6031 { TYPE_EMPTY, NULL, "" },
6033 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6034 { TYPE_EMPTY, NULL, "" },
6035 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6040 static struct TokenInfo setup_info_graphics[] =
6042 #if defined(TARGET_SDL2) && !defined(PLATFORM_ANDROID)
6043 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6044 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6045 { TYPE_STRING, &window_size_text, "" },
6046 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6047 { TYPE_STRING, &scaling_type_text, "" },
6048 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6049 { TYPE_STRING, &rendering_mode_text, "" },
6052 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6053 { TYPE_STRING, &scroll_delay_text, "" },
6055 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6056 { TYPE_STRING, &vsync_mode_text, "" },
6057 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6058 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6059 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6060 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6061 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6062 { TYPE_ECS_AGA, &setup.prefer_aga_graphics,"EMC graphics preference:" },
6063 { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
6064 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6065 { TYPE_EMPTY, NULL, "" },
6066 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6071 static struct TokenInfo setup_info_sound[] =
6073 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6074 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6075 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6076 { TYPE_EMPTY, NULL, "" },
6077 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6078 { TYPE_STRING, &volume_simple_text, "" },
6079 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6080 { TYPE_STRING, &volume_loops_text, "" },
6081 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6082 { TYPE_STRING, &volume_music_text, "" },
6083 { TYPE_EMPTY, NULL, "" },
6084 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6089 static struct TokenInfo setup_info_artwork[] =
6091 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6092 { TYPE_STRING, &graphics_set_name, "" },
6093 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6094 { TYPE_STRING, &sounds_set_name, "" },
6095 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6096 { TYPE_STRING, &music_set_name, "" },
6097 { TYPE_EMPTY, NULL, "" },
6098 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6099 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6100 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6101 { TYPE_EMPTY, NULL, "" },
6102 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6107 static struct TokenInfo setup_info_input[] =
6109 { TYPE_SWITCH, NULL, "Player:" },
6110 { TYPE_SWITCH, NULL, "Device:" },
6111 { TYPE_SWITCH, NULL, "" },
6112 { TYPE_SKIPPABLE, NULL, "" },
6113 { TYPE_EMPTY, NULL, "" },
6114 { TYPE_EMPTY, NULL, "" },
6115 { TYPE_EMPTY, NULL, "" },
6116 { TYPE_EMPTY, NULL, "" },
6117 { TYPE_EMPTY, NULL, "" },
6118 { TYPE_EMPTY, NULL, "" },
6119 { TYPE_EMPTY, NULL, "" },
6120 { TYPE_EMPTY, NULL, "" },
6121 { TYPE_SKIPPABLE, NULL, "" },
6122 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6127 static struct TokenInfo setup_info_touch[] =
6129 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6130 { TYPE_STRING, &touch_controls_text, "" },
6131 { TYPE_EMPTY, NULL, "" },
6132 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6137 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6139 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6140 { TYPE_STRING, &touch_controls_text, "" },
6141 { TYPE_EMPTY, NULL, "" },
6142 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6143 { TYPE_STRING, &grid_size_text[0][0], "" },
6144 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6145 { TYPE_STRING, &grid_size_text[0][1], "" },
6146 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6147 { TYPE_STRING, &transparency_text, "" },
6148 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6149 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6150 { TYPE_EMPTY, NULL, "" },
6151 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6152 { TYPE_EMPTY, NULL, "" },
6153 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6158 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6160 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6161 { TYPE_STRING, &touch_controls_text, "" },
6162 { TYPE_EMPTY, NULL, "" },
6163 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6164 { TYPE_STRING, &grid_size_text[1][0], "" },
6165 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6166 { TYPE_STRING, &grid_size_text[1][1], "" },
6167 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6168 { TYPE_STRING, &transparency_text, "" },
6169 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6170 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6171 { TYPE_EMPTY, NULL, "" },
6172 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6173 { TYPE_EMPTY, NULL, "" },
6174 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6179 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6181 setup_info_touch_virtual_buttons_0,
6182 setup_info_touch_virtual_buttons_1
6185 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6187 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6188 { TYPE_STRING, &touch_controls_text, "" },
6189 { TYPE_EMPTY, NULL, "" },
6190 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6191 { TYPE_STRING, &move_distance_text, "" },
6192 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6193 { TYPE_STRING, &drop_distance_text, "" },
6194 { TYPE_EMPTY, NULL, "" },
6195 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6200 static struct TokenInfo setup_info_shortcuts[] =
6202 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6203 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6204 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6205 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6206 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6207 { TYPE_EMPTY, NULL, "" },
6208 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6213 static struct TokenInfo setup_info_shortcuts_1[] =
6215 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6216 { TYPE_KEY, &setup.shortcut.save_game, "" },
6217 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6218 { TYPE_KEY, &setup.shortcut.load_game, "" },
6219 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6220 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6221 { TYPE_EMPTY, NULL, "" },
6222 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6223 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6224 { TYPE_EMPTY, NULL, "" },
6225 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6230 static struct TokenInfo setup_info_shortcuts_2[] =
6232 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6233 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6234 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6235 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6236 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6237 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6238 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6239 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6240 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6241 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6242 { TYPE_EMPTY, NULL, "" },
6243 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6248 static struct TokenInfo setup_info_shortcuts_3[] =
6250 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6251 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6252 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6253 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6254 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6255 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6256 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6257 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6258 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6259 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6260 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6261 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6262 { TYPE_EMPTY, NULL, "" },
6263 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6268 static struct TokenInfo setup_info_shortcuts_4[] =
6270 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6271 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6272 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6273 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6274 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6275 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6276 { TYPE_EMPTY, NULL, "" },
6277 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6282 static struct TokenInfo setup_info_shortcuts_5[] =
6284 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6285 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6286 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6287 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6288 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6289 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6290 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6291 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6292 { TYPE_EMPTY, NULL, "" },
6293 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6298 static Key getSetupKey(void)
6300 Key key = KSYM_UNDEFINED;
6301 boolean got_key_event = FALSE;
6303 while (!got_key_event)
6307 if (NextValidEvent(&event))
6311 case EVENT_KEYPRESS:
6313 key = GetEventKey((KeyEvent *)&event, TRUE);
6315 /* press 'Escape' or 'Enter' to keep the existing key binding */
6316 if (key == KSYM_Escape || key == KSYM_Return)
6317 key = KSYM_UNDEFINED; /* keep old value */
6319 got_key_event = TRUE;
6323 case EVENT_KEYRELEASE:
6324 key_joystick_mapping = 0;
6328 HandleOtherEvents(&event);
6339 static int getSetupValueFont(int type, void *value)
6341 if (type & TYPE_GHOSTED)
6342 return FONT_OPTION_OFF;
6343 else if (type & TYPE_KEY)
6344 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6345 else if (type & TYPE_STRING)
6346 return FONT_VALUE_2;
6347 else if (type & TYPE_ECS_AGA)
6348 return FONT_VALUE_1;
6349 else if (type & TYPE_BOOLEAN_STYLE)
6350 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6351 else if (type & TYPE_YES_NO_AUTO)
6352 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6353 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6354 else if (type & TYPE_PLAYER)
6355 return FONT_VALUE_1;
6357 return FONT_VALUE_1;
6360 static int getSetupValueFontNarrow(int type, int font_nr)
6362 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6363 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6364 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6368 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6370 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6371 struct TokenInfo *si = &setup_info[si_pos];
6372 boolean font_draw_xoffset_modified = FALSE;
6373 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6374 int font_draw_xoffset_old = -1;
6375 int xoffset = (scrollbar_needed ? -1 : 0);
6376 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6377 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6378 int xpos = menu_screen_value_xpos;
6379 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6380 int startx = mSX + xpos * 32;
6381 int starty = mSY + ypos * 32;
6382 int font_nr, font_nr_default, font_width_default;
6383 int type = si->type;
6384 void *value = si->value;
6385 char *value_string = getSetupValue(type, value);
6388 if (value_string == NULL)
6391 if (type & TYPE_KEY)
6393 xpos = MENU_SCREEN_START_XPOS;
6395 if (type & TYPE_QUERY)
6396 value_string = "<press key>";
6398 else if (type & TYPE_STRING)
6400 int max_value_len = (SCR_FIELDX - 2) * 2;
6402 xpos = MENU_SCREEN_START_XPOS;
6404 if (strlen(value_string) > max_value_len)
6405 value_string[max_value_len] = '\0';
6407 else if (type & TYPE_YES_NO_AUTO)
6409 xpos = menu_screen_value_xpos - 1;
6411 else if (type & TYPE_PLAYER)
6413 int displayed_player_nr = *(int *)value + 1;
6415 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6418 startx = mSX + xpos * 32;
6419 starty = mSY + ypos * 32;
6420 font_nr_default = getSetupValueFont(type, value);
6421 font_width_default = getFontWidth(font_nr_default);
6423 font_nr = font_nr_default;
6425 // special check if right-side setup values moved left due to scrollbar
6426 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6428 int max_menu_text_length = 26; // maximum text length for classic menu
6429 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6430 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6431 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6432 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6433 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6435 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6438 startx = mSX + xpos * 32;
6440 font_nr = getSetupValueFontNarrow(type, font_nr);
6444 /* downward compatibility correction for Juergen Bonhagen's menu settings */
6445 if (setup_mode != SETUP_MODE_INPUT)
6447 int max_menu_text_length_big = (menu_screen_value_xpos -
6448 MENU_SCREEN_START_XPOS);
6449 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6450 int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */
6451 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6452 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6453 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6454 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6455 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6456 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6457 boolean correct_font_draw_xoffset = FALSE;
6459 if (xpos == MENU_SCREEN_START_XPOS &&
6460 startx + font1_xoffset < text_startx + text_font_xoffset)
6461 correct_font_draw_xoffset = TRUE;
6463 if (xpos == menu_screen_value_xpos &&
6464 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6465 correct_font_draw_xoffset = TRUE;
6467 /* check if setup value would overlap with setup text when printed */
6468 /* (this can happen for extreme/wrong values for font draw offset) */
6469 if (correct_font_draw_xoffset)
6471 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6472 font_draw_xoffset_modified = TRUE;
6474 if (type & TYPE_KEY)
6475 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6476 else if (!(type & TYPE_STRING))
6477 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6478 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6482 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6483 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6485 DrawText(startx, starty, value_string, font_nr);
6487 if (type & TYPE_PLAYER)
6489 int player_nr = *(int *)value;
6490 int xoff = getFontWidth(font_nr);
6492 DrawFixedGraphicThruMaskExt(drawto, startx + xoff, starty,
6493 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6496 if (font_draw_xoffset_modified)
6497 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6500 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6502 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6503 struct TokenInfo *si = &setup_info[si_pos];
6505 if (si->type & TYPE_BOOLEAN_STYLE)
6507 *(boolean *)si->value ^= TRUE;
6509 else if (si->type & TYPE_YES_NO_AUTO)
6513 (*(int *)si->value == AUTO ? TRUE :
6514 *(int *)si->value == TRUE ? FALSE : AUTO) :
6515 (*(int *)si->value == TRUE ? AUTO :
6516 *(int *)si->value == AUTO ? FALSE : TRUE));
6518 else if (si->type & TYPE_KEY)
6522 si->type |= TYPE_QUERY;
6523 drawSetupValue(screen_pos, setup_info_pos_raw);
6524 si->type &= ~TYPE_QUERY;
6526 key = getSetupKey();
6527 if (key != KSYM_UNDEFINED)
6528 *(Key *)si->value = key;
6530 else if (si->type & TYPE_PLAYER)
6532 int player_nr = *(int *)si->value;
6537 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6539 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6542 drawSetupValue(screen_pos, setup_info_pos_raw);
6544 // fullscreen state may have changed at this point
6545 if (si->value == &setup.fullscreen)
6546 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6548 if (si->value == &setup.network_mode &&
6549 setup.network_mode != network.enabled)
6551 network.enabled = setup.network_mode;
6553 FadeOut(REDRAW_ALL);
6559 if (network.enabled)
6560 InitNetworkServer();
6562 DisconnectFromNetworkServer();
6568 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6570 static struct TokenInfo *setup_info_final = NULL;
6575 /* determine maximum list size of target list */
6576 while (setup_info_orig[list_size++].type != 0);
6578 /* free, allocate and clear memory for target list */
6579 checked_free(setup_info_final);
6580 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6582 /* copy setup info list without setup entries marked as hidden */
6583 for (i = 0; setup_info_orig[i].type != 0; i++)
6585 /* skip setup entries configured to be hidden */
6586 if (hideSetupEntry(setup_info_orig[i].value))
6589 /* skip skippable setup entries if screen is lower than usual */
6590 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6591 setup_info_orig[i].type == TYPE_SKIPPABLE)
6594 setup_info_final[list_pos++] = setup_info_orig[i];
6597 return setup_info_final;
6600 static void DrawSetupScreen_Generic(void)
6602 int fade_mask = REDRAW_FIELD;
6603 boolean redraw_all = FALSE;
6604 char *title_string = NULL;
6607 if (CheckIfGlobalBorderOrPlayfieldViewportHasChanged())
6608 fade_mask = REDRAW_ALL;
6611 FadeMenuSoundsAndMusic();
6613 FreeScreenGadgets();
6614 CreateScreenGadgets();
6616 if (redraw_mask & REDRAW_ALL)
6621 /* needed if different viewport properties defined for setup screen */
6622 ChangeViewportPropertiesIfNeeded();
6624 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6628 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6630 if (setup_mode == SETUP_MODE_MAIN)
6632 setup_info = setup_info_main;
6633 title_string = STR_SETUP_MAIN;
6635 else if (setup_mode == SETUP_MODE_GAME)
6637 setup_info = setup_info_game;
6638 title_string = STR_SETUP_GAME;
6640 else if (setup_mode == SETUP_MODE_EDITOR)
6642 setup_info = setup_info_editor;
6643 title_string = STR_SETUP_EDITOR;
6645 else if (setup_mode == SETUP_MODE_GRAPHICS)
6647 setup_info = setup_info_graphics;
6648 title_string = STR_SETUP_GRAPHICS;
6650 else if (setup_mode == SETUP_MODE_SOUND)
6652 setup_info = setup_info_sound;
6653 title_string = STR_SETUP_SOUND;
6655 else if (setup_mode == SETUP_MODE_ARTWORK)
6657 setup_info = setup_info_artwork;
6658 title_string = STR_SETUP_ARTWORK;
6660 else if (setup_mode == SETUP_MODE_TOUCH)
6662 setup_info = setup_info_touch;
6663 title_string = STR_SETUP_TOUCH;
6665 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6666 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6667 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6668 setup_info = setup_info_touch_wipe_gestures;
6670 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6672 setup_info = setup_info_shortcuts;
6673 title_string = STR_SETUP_SHORTCUTS;
6675 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6677 setup_info = setup_info_shortcuts_1;
6678 title_string = STR_SETUP_SHORTCUTS;
6680 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6682 setup_info = setup_info_shortcuts_2;
6683 title_string = STR_SETUP_SHORTCUTS;
6685 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6687 setup_info = setup_info_shortcuts_3;
6688 title_string = STR_SETUP_SHORTCUTS;
6690 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
6692 setup_info = setup_info_shortcuts_4;
6693 title_string = STR_SETUP_SHORTCUTS;
6695 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
6697 setup_info = setup_info_shortcuts_5;
6698 title_string = STR_SETUP_SHORTCUTS;
6701 /* use modified setup info without setup entries marked as hidden */
6702 setup_info = getSetupInfoFinal(setup_info);
6704 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
6706 // determine maximal number of setup entries that can be displayed on screen
6708 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
6711 // determine maximal number of setup entries available for this setup screen
6713 for (i = 0; setup_info[i].type != 0; i++)
6716 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
6718 MapScreenGadgets(max_setup_info);
6721 redraw_mask = fade_mask = REDRAW_ALL;
6723 DrawMaskedBorder(fade_mask);
6728 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
6730 menu_info = setup_info;
6732 HandleMenuScreen(mx, my, dx, dy, button,
6733 setup_mode, num_setup_info, max_setup_info);
6736 static void DrawSetupScreen_Input(void)
6740 FadeOut(REDRAW_FIELD);
6744 setup_info = getSetupInfoFinal(setup_info_input);
6746 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
6748 for (i = 0; setup_info[i].type != 0; i++)
6750 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
6751 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
6752 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
6753 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
6754 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
6755 initCursor(i, IMG_MENU_BUTTON);
6757 DrawCursorAndText_Setup(i, -1, FALSE);
6760 /* create gadgets for setup input menu screen */
6761 FreeScreenGadgets();
6762 CreateScreenGadgets();
6764 /* map gadgets for setup input menu screen */
6765 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
6767 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
6769 FadeIn(REDRAW_FIELD);
6772 static void setJoystickDeviceToNr(char *device_name, int device_nr)
6774 if (device_name == NULL)
6777 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
6780 if (strlen(device_name) > 1)
6782 char c1 = device_name[strlen(device_name) - 1];
6783 char c2 = device_name[strlen(device_name) - 2];
6785 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
6786 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
6789 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
6790 strlen(device_name));
6793 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
6796 static struct SetupKeyboardInfo custom_key;
6803 { &custom_key.left, "Axis/Pad Left" },
6804 { &custom_key.right, "Axis/Pad Right" },
6805 { &custom_key.up, "Axis/Pad Up" },
6806 { &custom_key.down, "Axis/Pad Down" },
6807 { &custom_key.snap, "Button 1/A/X" },
6808 { &custom_key.drop, "Button 2/B/Y" }
6810 static char *joystick_name[MAX_PLAYERS] =
6817 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
6818 int font_nr_info = FONT_MENU_1;
6819 int font_nr_name = FONT_VALUE_OLD;
6820 int font_nr_on = FONT_VALUE_1;
6821 int font_nr_off = FONT_VALUE_OLD;
6824 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
6826 font_nr_info = FONT_MENU_2;
6827 font_nr_on = FONT_VALUE_NARROW;
6828 font_nr_off = FONT_VALUE_OLD_NARROW;
6831 custom_key = setup.input[player_nr].key;
6833 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
6834 FONT_INPUT_1_ACTIVE);
6836 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6838 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
6839 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6841 if (setup.input[player_nr].use_joystick)
6843 char *device_name = setup.input[player_nr].joy.device_name;
6844 int joystick_nr = getJoystickNrFromDeviceName(device_name);
6845 boolean joystick_active = CheckJoystickOpened(joystick_nr);
6846 char *text = joystick_name[joystick_nr];
6847 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
6849 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
6850 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
6854 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
6855 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
6858 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
6859 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
6863 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
6864 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
6865 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
6866 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
6868 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
6869 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
6870 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
6871 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
6872 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
6873 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
6875 for (i = 0; i < 6; i++)
6877 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
6879 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6881 DrawText(mSX + 3 * 32, mSY + ypos * 32,
6882 (setup.input[player_nr].use_joystick ?
6884 getKeyNameFromKey(*custom[i].key)), font_nr_on);
6888 static int input_player_nr = 0;
6890 static void HandleSetupScreen_Input_Player(int step, int direction)
6892 int old_player_nr = input_player_nr;
6895 new_player_nr = old_player_nr + step * direction;
6896 if (new_player_nr < 0)
6898 if (new_player_nr > MAX_PLAYERS - 1)
6899 new_player_nr = MAX_PLAYERS - 1;
6901 if (new_player_nr != old_player_nr)
6903 input_player_nr = new_player_nr;
6905 drawPlayerSetupInputInfo(input_player_nr, FALSE);
6909 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
6911 static int choice = 0;
6914 int pos_start = SETUPINPUT_SCREEN_POS_START;
6915 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
6916 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
6917 int pos_end = SETUPINPUT_SCREEN_POS_END;
6919 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
6923 for (i = 0; setup_info_input[i].type != 0; i++)
6925 /* adjust menu structure according to skipped setup entries */
6926 if (setup_info_input[i].type == TYPE_SKIPPABLE)
6934 if (button == MB_MENU_INITIALIZE)
6936 /* input setup menu may have changed size due to graphics configuration */
6937 if (choice >= pos_empty1)
6940 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
6942 DrawCursorAndText_Setup(choice, -1, TRUE);
6946 else if (button == MB_MENU_LEAVE)
6948 setup_mode = SETUP_MODE_MAIN;
6955 if (mx || my) /* mouse input */
6957 x = (mx - mSX) / 32;
6958 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
6960 else if (dx || dy) /* keyboard input */
6962 if (dx && choice == 0)
6963 x = (dx < 0 ? 10 : 12);
6964 else if ((dx && choice == 1) ||
6965 (dx == -1 && choice == pos_end))
6966 button = MB_MENU_CHOICE;
6970 if (y >= pos_empty1 && y <= pos_empty2)
6971 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
6974 if (y == 0 && dx != 0 && button)
6976 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
6978 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
6979 y >= pos_start && y <= pos_end &&
6980 !(y >= pos_empty1 && y <= pos_empty2))
6986 DrawCursorAndText_Setup(choice, -1, FALSE);
6987 DrawCursorAndText_Setup(y, -1, TRUE);
6989 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
6998 char *device_name = setup.input[input_player_nr].joy.device_name;
7000 if (!setup.input[input_player_nr].use_joystick)
7002 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7004 setJoystickDeviceToNr(device_name, new_device_nr);
7005 setup.input[input_player_nr].use_joystick = TRUE;
7009 int device_nr = getJoystickNrFromDeviceName(device_name);
7010 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7012 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7013 setup.input[input_player_nr].use_joystick = FALSE;
7015 setJoystickDeviceToNr(device_name, new_device_nr);
7018 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7022 if (setup.input[input_player_nr].use_joystick)
7023 ConfigureJoystick(input_player_nr);
7025 CustomizeKeyboard(input_player_nr);
7027 else if (y == pos_end)
7033 setup_mode = SETUP_MODE_MAIN;
7040 static boolean CustomizeKeyboardMain(int player_nr)
7044 boolean finished = FALSE;
7045 static struct SetupKeyboardInfo custom_key;
7050 } customize_step[] =
7052 { &custom_key.left, "Move Left" },
7053 { &custom_key.right, "Move Right" },
7054 { &custom_key.up, "Move Up" },
7055 { &custom_key.down, "Move Down" },
7056 { &custom_key.snap, "Snap Field" },
7057 { &custom_key.drop, "Drop Element" }
7059 int font_nr_old = FONT_VALUE_OLD;
7060 int font_nr_new = FONT_VALUE_1;
7061 boolean success = FALSE;
7063 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7065 font_nr_old = FONT_VALUE_OLD_NARROW;
7066 font_nr_new = FONT_VALUE_NARROW;
7069 /* read existing key bindings from player setup */
7070 custom_key = setup.input[player_nr].key;
7073 FadeOut(REDRAW_FIELD);
7077 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7080 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7081 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7082 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7083 "Key:", FONT_INPUT_1_ACTIVE);
7084 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7085 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7087 FadeIn(REDRAW_FIELD);
7093 if (NextValidEvent(&event))
7097 case EVENT_KEYPRESS:
7099 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7101 /* press 'Escape' to abort and keep the old key bindings */
7102 if (key == KSYM_Escape)
7104 FadeSkipNextFadeIn();
7111 /* press 'Enter' to keep the existing key binding */
7112 if (key == KSYM_Return)
7113 key = *customize_step[step_nr].key;
7115 /* check if key already used */
7116 for (i = 0; i < step_nr; i++)
7117 if (*customize_step[i].key == key)
7122 /* got new key binding */
7123 *customize_step[step_nr].key = key;
7124 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7126 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7127 getKeyNameFromKey(key), font_nr_new);
7130 /* un-highlight last query */
7131 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7132 customize_step[step_nr - 1].text, FONT_MENU_1);
7133 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7134 "Key:", FONT_MENU_1);
7136 /* all keys configured */
7145 /* query next key binding */
7146 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7147 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7148 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7149 "Key:", FONT_INPUT_1_ACTIVE);
7150 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7151 getKeyNameFromKey(*customize_step[step_nr].key),
7156 case EVENT_KEYRELEASE:
7157 key_joystick_mapping = 0;
7161 HandleOtherEvents(&event);
7169 /* write new key bindings back to player setup, if successfully finished */
7171 setup.input[player_nr].key = custom_key;
7176 void CustomizeKeyboard(int player_nr)
7178 boolean success = CustomizeKeyboardMain(player_nr);
7182 int font_nr = FONT_TITLE_1;
7183 int font_height = getFontHeight(font_nr);
7184 int ypos1 = SYSIZE / 2 - font_height * 2;
7185 int ypos2 = SYSIZE / 2 - font_height * 1;
7186 unsigned int wait_frame_delay = 0;
7187 unsigned int wait_frame_delay_value = 2000;
7189 ResetDelayCounter(&wait_frame_delay);
7193 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7194 DrawTextSCentered(ypos2, font_nr, "configured!");
7196 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7202 DrawSetupScreen_Input();
7205 /* game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com> */
7207 #define MARKER_BUTTON 1
7208 #define MARKER_AXIS_X 2
7209 #define MARKER_AXIS_Y 3
7211 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7213 #if defined(TARGET_SDL2)
7214 static boolean bitmaps_initialized = FALSE;
7215 boolean screen_initialized = FALSE;
7216 static Bitmap *controller, *button, *axis_x, *axis_y;
7218 boolean success = TRUE;
7219 boolean done = FALSE, next = FALSE;
7221 int alpha = 200, alpha_step = -1;
7222 int alpha_ticks = 0;
7223 char mapping[4096], temp[4096];
7224 int font_name = MENU_SETUP_FONT_TITLE;
7225 int font_info = MENU_SETUP_FONT_TEXT;
7226 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7227 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7228 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7229 int ystep_name = getMenuTextStep(spacing_name, font_name);
7230 int ystep_line = getMenuTextStep(spacing_line, font_info);
7231 int ystep_para = getMenuTextStep(spacing_para, font_info);
7239 int axis, button, hat, hat_value;
7242 *step, *prev_step, steps[] =
7244 { 356, 155, MARKER_BUTTON, "a", },
7245 { 396, 122, MARKER_BUTTON, "b", },
7246 { 320, 125, MARKER_BUTTON, "x", },
7247 { 358, 95, MARKER_BUTTON, "y", },
7248 { 162, 125, MARKER_BUTTON, "back", },
7249 { 216, 125, MARKER_BUTTON, "guide", },
7250 { 271, 125, MARKER_BUTTON, "start", },
7251 { 110, 200, MARKER_BUTTON, "dpleft", },
7252 { 146, 228, MARKER_BUTTON, "dpdown", },
7253 { 178, 200, MARKER_BUTTON, "dpright", },
7254 { 146, 172, MARKER_BUTTON, "dpup", },
7255 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7256 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7257 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7258 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7259 { 73, 141, MARKER_BUTTON, "leftstick", },
7260 { 282, 210, MARKER_BUTTON, "rightstick", },
7261 { 73, 141, MARKER_AXIS_X, "leftx", },
7262 { 73, 141, MARKER_AXIS_Y, "lefty", },
7263 { 282, 210, MARKER_AXIS_X, "rightx", },
7264 { 282, 210, MARKER_AXIS_Y, "righty", },
7267 unsigned int event_frame_delay = 0;
7268 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7270 ResetDelayCounter(&event_frame_delay);
7272 if (!bitmaps_initialized)
7274 controller = LoadCustomImage("joystick/controller.png");
7275 button = LoadCustomImage("joystick/button.png");
7276 axis_x = LoadCustomImage("joystick/axis_x.png");
7277 axis_y = LoadCustomImage("joystick/axis_y.png");
7279 bitmaps_initialized = TRUE;
7282 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7285 /* print info about the joystick we are watching */
7286 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7287 SDL_JoystickInstanceID(joystick), name);
7288 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7289 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7290 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7293 /* initialize mapping with GUID and name */
7294 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7296 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7297 temp, name, SDL_GetPlatform());
7299 /* loop through all steps (buttons and axes), getting joystick events */
7300 for (i = 0; i < SDL_arraysize(steps) && !done;)
7302 Bitmap *marker = button; /* initialize with reliable default value */
7305 strcpy(step->mapping, mapping);
7309 step->hat_value = -1;
7311 marker = (step->marker == MARKER_BUTTON ? button :
7312 step->marker == MARKER_AXIS_X ? axis_x :
7313 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7317 while (!done && !next)
7319 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7320 alpha_ticks = SDL_GetTicks();
7327 else if (alpha < 128)
7333 int controller_x = SX + (SXSIZE - controller->width) / 2;
7334 int controller_y = SY + ystep_line;
7336 int marker_x = controller_x + step->x;
7337 int marker_y = controller_y + step->y;
7339 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7340 int ystart2 = ystart1 + ystep_name + ystep_line;
7344 DrawTextSCentered(ystart1, font_name, name);
7346 DrawTextSCentered(ystart2, font_info,
7347 "Press buttons and move axes on");
7348 ystart2 += ystep_line;
7349 DrawTextSCentered(ystart2, font_info,
7350 "your controller when indicated.");
7351 ystart2 += ystep_line;
7352 DrawTextSCentered(ystart2, font_info,
7353 "(Your controller may look different.)");
7354 ystart2 += ystep_para;
7356 #if defined(PLATFORM_ANDROID)
7357 DrawTextSCentered(ystart2, font_info,
7358 "To correct a mistake,");
7359 ystart2 += ystep_line;
7360 DrawTextSCentered(ystart2, font_info,
7361 "press the 'back' button.");
7362 ystart2 += ystep_line;
7363 DrawTextSCentered(ystart2, font_info,
7364 "To skip a button or axis,");
7365 ystart2 += ystep_line;
7366 DrawTextSCentered(ystart2, font_info,
7367 "press the 'menu' button.");
7369 DrawTextSCentered(ystart2, font_info,
7370 "To correct a mistake,");
7371 ystart2 += ystep_line;
7372 DrawTextSCentered(ystart2, font_info,
7373 "press the 'backspace' key.");
7374 ystart2 += ystep_line;
7375 DrawTextSCentered(ystart2, font_info,
7376 "To skip a button or axis,");
7377 ystart2 += ystep_line;
7378 DrawTextSCentered(ystart2, font_info,
7379 "press the 'return' key.");
7380 ystart2 += ystep_line;
7381 DrawTextSCentered(ystart2, font_info,
7382 "To exit, press the 'escape' key.");
7385 BlitBitmapMasked(controller, drawto, 0, 0,
7386 controller->width, controller->height,
7387 controller_x, controller_y);
7389 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7390 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7392 BlitBitmapMasked(marker, drawto, 0, 0,
7393 marker->width, marker->height,
7394 marker_x, marker_y);
7396 if (!screen_initialized)
7397 FadeIn(REDRAW_FIELD);
7401 screen_initialized = TRUE;
7403 while (NextValidEvent(&event))
7407 case SDL_JOYAXISMOTION:
7408 if (event.jaxis.value > 20000 ||
7409 event.jaxis.value < -20000)
7411 for (j = 0; j < i; j++)
7412 if (steps[j].axis == event.jaxis.axis)
7417 if (step->marker != MARKER_AXIS_X &&
7418 step->marker != MARKER_AXIS_Y)
7421 step->axis = event.jaxis.axis;
7422 strcat(mapping, step->field);
7423 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7424 strcat(mapping, temp);
7432 case SDL_JOYHATMOTION:
7433 /* ignore centering; we're probably just coming back
7434 to the center from the previous item we set */
7435 if (event.jhat.value == SDL_HAT_CENTERED)
7438 for (j = 0; j < i; j++)
7439 if (steps[j].hat == event.jhat.hat &&
7440 steps[j].hat_value == event.jhat.value)
7445 step->hat = event.jhat.hat;
7446 step->hat_value = event.jhat.value;
7447 strcat(mapping, step->field);
7448 snprintf(temp, sizeof(temp), ":h%u.%u,",
7449 event.jhat.hat, event.jhat.value );
7450 strcat(mapping, temp);
7457 case SDL_JOYBALLMOTION:
7460 case SDL_JOYBUTTONUP:
7461 for (j = 0; j < i; j++)
7462 if (steps[j].button == event.jbutton.button)
7467 step->button = event.jbutton.button;
7468 strcat(mapping, step->field);
7469 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7470 strcat(mapping, temp);
7477 case SDL_FINGERDOWN:
7478 case SDL_MOUSEBUTTONDOWN:
7479 /* skip this step */
7486 if (event.key.keysym.sym == KSYM_BackSpace ||
7487 event.key.keysym.sym == KSYM_Back)
7498 /* undo this step */
7499 prev_step = &steps[i - 1];
7500 strcpy(mapping, prev_step->mapping);
7507 if (event.key.keysym.sym == KSYM_space ||
7508 event.key.keysym.sym == KSYM_Return ||
7509 event.key.keysym.sym == KSYM_Menu)
7511 /* skip this step */
7518 if (event.key.keysym.sym == KSYM_Escape)
7528 program.exit_function(0);
7535 // do not handle events for longer than standard frame delay period
7536 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7545 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7548 // activate mapping for this game
7549 SDL_GameControllerAddMapping(mapping);
7551 // save mapping to personal mappings
7552 SaveSetup_AddGameControllerMapping(mapping);
7555 /* wait until the last pending event was removed from event queue */
7556 while (NextValidEvent(&event));
7564 static int ConfigureJoystickMain(int player_nr)
7566 char *device_name = setup.input[player_nr].joy.device_name;
7567 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7568 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7569 int success = FALSE;
7572 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7573 return JOYSTICK_NOT_AVAILABLE;
7575 if (!joystick_active || !setup.input[player_nr].use_joystick)
7576 return JOYSTICK_NOT_AVAILABLE;
7579 FadeOut(REDRAW_FIELD);
7581 // close all joystick devices (potentially opened as game controllers)
7582 for (i = 0; i < SDL_NumJoysticks(); i++)
7583 SDLCloseJoystick(i);
7585 // open joystick device as plain joystick to configure as game controller
7586 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7588 // as the joystick was successfully opened before, this should not happen
7589 if (joystick == NULL)
7592 // create new game controller mapping (buttons and axes) for joystick device
7593 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7595 // close joystick (and maybe re-open as configured game controller later)
7596 SDL_JoystickClose(joystick);
7598 // re-open all joystick devices (potentially as game controllers)
7599 for (i = 0; i < SDL_NumJoysticks(); i++)
7602 // clear all joystick input actions for all joystick devices
7603 SDLClearJoystickState();
7605 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7608 void ConfigureJoystick(int player_nr)
7610 boolean state = ConfigureJoystickMain(player_nr);
7612 if (state != JOYSTICK_NOT_CONFIGURED)
7614 boolean success = (state == JOYSTICK_CONFIGURED);
7615 char message1[MAX_OUTPUT_LINESIZE + 1];
7616 char *message2 = (success ? "configured!" : "not available!");
7617 char *device_name = setup.input[player_nr].joy.device_name;
7618 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7619 int font_nr = FONT_TITLE_1;
7620 int font_height = getFontHeight(font_nr);
7621 int ypos1 = SYSIZE / 2 - font_height * 2;
7622 int ypos2 = SYSIZE / 2 - font_height * 1;
7623 unsigned int wait_frame_delay = 0;
7624 unsigned int wait_frame_delay_value = 2000;
7626 ResetDelayCounter(&wait_frame_delay);
7630 sprintf(message1, "Joystick %d", nr);
7632 DrawTextSCentered(ypos1, font_nr, message1);
7633 DrawTextSCentered(ypos2, font_nr, message2);
7635 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7641 DrawSetupScreen_Input();
7644 static boolean ConfigureVirtualButtonsMain(void)
7646 static char *customize_step_text[] =
7655 char grid_button[] =
7657 CHAR_GRID_BUTTON_LEFT,
7658 CHAR_GRID_BUTTON_RIGHT,
7659 CHAR_GRID_BUTTON_UP,
7660 CHAR_GRID_BUTTON_DOWN,
7661 CHAR_GRID_BUTTON_SNAP,
7662 CHAR_GRID_BUTTON_DROP
7664 int font_nr = FONT_INPUT_1_ACTIVE;
7665 int font_height = getFontHeight(font_nr);
7666 int ypos1 = SYSIZE / 2 - font_height * 2;
7667 int ypos2 = SYSIZE / 2 - font_height * 1;
7668 boolean success = FALSE;
7669 boolean finished = FALSE;
7671 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
7672 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7673 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
7674 boolean set_grid_button = FALSE;
7675 int nr = GRID_ACTIVE_NR();
7678 for (x = 0; x < MAX_GRID_XSIZE; x++)
7679 for (y = 0; y < MAX_GRID_YSIZE; y++)
7680 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
7682 overlay.grid_button_highlight = grid_button[step_nr];
7685 FadeOut(REDRAW_FIELD);
7689 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7690 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7691 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7693 FadeIn(REDRAW_FIELD);
7695 SetOverlayShowGrid(TRUE);
7701 while (NextValidEvent(&event))
7705 case EVENT_KEYPRESS:
7707 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7709 /* press 'Escape' to abort and keep the old key bindings */
7710 if (key == KSYM_Escape)
7712 for (x = 0; x < MAX_GRID_XSIZE; x++)
7713 for (y = 0; y < MAX_GRID_YSIZE; y++)
7714 overlay.grid_button[x][y] = grid_button_old[x][y];
7716 FadeSkipNextFadeIn();
7723 /* press 'Enter' to keep the existing key binding */
7724 if (key == KSYM_Return ||
7725 #if defined(TARGET_SDL2)
7732 else if (key == KSYM_BackSpace
7733 #if defined(TARGET_SDL2)
7741 FadeSkipNextFadeIn();
7755 /* all virtual buttons configured */
7764 for (x = 0; x < MAX_GRID_XSIZE; x++)
7765 for (y = 0; y < MAX_GRID_YSIZE; y++)
7766 grid_button_tmp[x][y] = overlay.grid_button[x][y];
7768 overlay.grid_button_highlight = grid_button[step_nr];
7770 /* query next virtual button */
7774 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
7775 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
7776 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
7780 case EVENT_KEYRELEASE:
7781 key_joystick_mapping = 0;
7784 case EVENT_BUTTONPRESS:
7785 case EVENT_BUTTONRELEASE:
7787 ButtonEvent *button = (ButtonEvent *)&event;
7789 button->x += video.screen_xoffset;
7790 button->y += video.screen_yoffset;
7792 x = button->x * overlay.grid_xsize / video.screen_width;
7793 y = button->y * overlay.grid_ysize / video.screen_height;
7795 if (button->type == EVENT_BUTTONPRESS)
7797 button_status = button->button;
7800 (overlay.grid_button[x][y] != grid_button[step_nr] ?
7801 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
7803 set_grid_button = TRUE;
7807 button_status = MB_RELEASED;
7812 case EVENT_MOTIONNOTIFY:
7814 MotionEvent *motion = (MotionEvent *)&event;
7816 motion->x += video.screen_xoffset;
7817 motion->y += video.screen_yoffset;
7819 x = motion->x * overlay.grid_xsize / video.screen_width;
7820 y = motion->y * overlay.grid_ysize / video.screen_height;
7822 set_grid_button = TRUE;
7826 #if defined(TARGET_SDL2)
7827 case SDL_WINDOWEVENT:
7828 HandleWindowEvent((WindowEvent *) &event);
7830 // check if device has been rotated
7831 if (nr != GRID_ACTIVE_NR())
7833 nr = GRID_ACTIVE_NR();
7835 for (x = 0; x < MAX_GRID_XSIZE; x++)
7836 for (y = 0; y < MAX_GRID_YSIZE; y++)
7837 grid_button_old[x][y] = grid_button_tmp[x][y] =
7838 overlay.grid_button[x][y];
7843 case SDL_APP_WILLENTERBACKGROUND:
7844 case SDL_APP_DIDENTERBACKGROUND:
7845 case SDL_APP_WILLENTERFOREGROUND:
7846 case SDL_APP_DIDENTERFOREGROUND:
7847 HandlePauseResumeEvent((PauseResumeEvent *) &event);
7852 HandleOtherEvents(&event);
7856 if (set_grid_button)
7858 overlay.grid_button[x][y] =
7859 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
7860 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
7861 grid_button_tmp[x][y]);
7863 set_grid_button = FALSE;
7870 for (x = 0; x < MAX_GRID_XSIZE; x++)
7871 for (y = 0; y < MAX_GRID_YSIZE; y++)
7872 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7874 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
7876 SetOverlayShowGrid(FALSE);
7881 void ConfigureVirtualButtons(void)
7883 boolean success = ConfigureVirtualButtonsMain();
7887 int font_nr = FONT_TITLE_1;
7888 int font_height = getFontHeight(font_nr);
7889 int ypos1 = SYSIZE / 2 - font_height * 2;
7890 int ypos2 = SYSIZE / 2 - font_height * 1;
7891 unsigned int wait_frame_delay = 0;
7892 unsigned int wait_frame_delay_value = 2000;
7894 ResetDelayCounter(&wait_frame_delay);
7898 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
7899 DrawTextSCentered(ypos2, font_nr, "configured!");
7901 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7908 void DrawSetupScreen(void)
7910 if (setup_mode == SETUP_MODE_INPUT)
7911 DrawSetupScreen_Input();
7912 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7913 DrawChooseTree(&game_speed_current);
7914 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7915 DrawChooseTree(&scroll_delay_current);
7916 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7917 DrawChooseTree(&snapshot_mode_current);
7918 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7919 DrawChooseTree(&window_size_current);
7920 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
7921 DrawChooseTree(&scaling_type_current);
7922 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
7923 DrawChooseTree(&rendering_mode_current);
7924 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
7925 DrawChooseTree(&vsync_mode_current);
7926 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
7927 DrawChooseTree(&artwork.gfx_current);
7928 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
7929 DrawChooseTree(&artwork.snd_current);
7930 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
7931 DrawChooseTree(&artwork.mus_current);
7932 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
7933 DrawChooseTree(&volume_simple_current);
7934 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
7935 DrawChooseTree(&volume_loops_current);
7936 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
7937 DrawChooseTree(&volume_music_current);
7938 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
7939 DrawChooseTree(&touch_control_current);
7940 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
7941 DrawChooseTree(&move_distance_current);
7942 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
7943 DrawChooseTree(&drop_distance_current);
7944 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
7945 DrawChooseTree(&transparency_current);
7946 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
7947 DrawChooseTree(&grid_size_current[0][0]);
7948 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
7949 DrawChooseTree(&grid_size_current[0][1]);
7950 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
7951 DrawChooseTree(&grid_size_current[1][0]);
7952 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
7953 DrawChooseTree(&grid_size_current[1][1]);
7955 DrawSetupScreen_Generic();
7957 PlayMenuSoundsAndMusic();
7960 void RedrawSetupScreenAfterFullscreenToggle(void)
7962 if (setup_mode == SETUP_MODE_GRAPHICS ||
7963 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
7965 // update list selection from "setup.window_scaling_percent"
7966 execSetupGraphics_setWindowSizes(TRUE);
7972 void RedrawSetupScreenAfterScreenRotation(int nr)
7976 if (setup_mode == SETUP_MODE_TOUCH)
7978 // update virtual button settings (depending on screen orientation)
7981 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
7983 // save already configured virtual buttons
7984 for (x = 0; x < MAX_GRID_XSIZE; x++)
7985 for (y = 0; y < MAX_GRID_YSIZE; y++)
7986 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
7990 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
7992 if (setup_mode == SETUP_MODE_INPUT)
7993 HandleSetupScreen_Input(mx, my, dx, dy, button);
7994 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
7995 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
7996 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
7997 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
7998 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
7999 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8000 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8001 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8002 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8003 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8004 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8005 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8006 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8007 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8008 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8009 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8010 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8011 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8012 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8013 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8014 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8015 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8016 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8017 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8018 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8019 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8020 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8021 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8022 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8023 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8024 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8025 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8026 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8027 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8028 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8029 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8030 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8031 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8032 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8033 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8034 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8035 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8037 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8040 void HandleGameActions(void)
8042 if (game.restart_game_message != NULL)
8043 RequestRestartGame(game.restart_game_message);
8045 if (game_status != GAME_MODE_PLAYING)
8048 GameActions(); /* main game loop */
8050 if (tape.auto_play && !tape.playing)
8051 AutoPlayTape(); /* continue automatically playing next tape */
8055 /* ---------- new screen button stuff -------------------------------------- */
8057 static void getScreenMenuButtonPos(int *x, int *y, int gadget_id)
8061 case SCREEN_CTRL_ID_PREV_LEVEL:
8062 *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x);
8063 *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y);
8066 case SCREEN_CTRL_ID_NEXT_LEVEL:
8067 *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x);
8068 *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y);
8071 case SCREEN_CTRL_ID_PREV_PLAYER:
8072 *x = mSX + TILEX * 10;
8073 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
8076 case SCREEN_CTRL_ID_NEXT_PLAYER:
8077 *x = mSX + TILEX * 12;
8078 *y = mSY + TILEY * MENU_SCREEN_START_YPOS;
8081 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8082 *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x);
8083 *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y);
8086 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8087 *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x);
8088 *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y);
8092 Error(ERR_EXIT, "unknown gadget ID %d", gadget_id);
8098 int gfx_unpressed, gfx_pressed;
8099 void (*get_gadget_position)(int *, int *, int);
8103 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8106 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8107 getScreenMenuButtonPos,
8108 SCREEN_CTRL_ID_PREV_LEVEL,
8113 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8114 getScreenMenuButtonPos,
8115 SCREEN_CTRL_ID_NEXT_LEVEL,
8120 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8121 getScreenMenuButtonPos,
8122 SCREEN_CTRL_ID_PREV_PLAYER,
8127 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8128 getScreenMenuButtonPos,
8129 SCREEN_CTRL_ID_NEXT_PLAYER,
8134 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8135 getScreenMenuButtonPos,
8136 SCREEN_CTRL_ID_INSERT_SOLUTION,
8137 SCREEN_MASK_MAIN_HAS_SOLUTION,
8138 "insert solution tape"
8141 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8142 getScreenMenuButtonPos,
8143 SCREEN_CTRL_ID_PLAY_SOLUTION,
8144 SCREEN_MASK_MAIN_HAS_SOLUTION,
8145 "play solution tape"
8151 int gfx_unpressed, gfx_pressed;
8155 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8158 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8159 -1, -1, /* these values are not constant, but can change at runtime */
8160 SCREEN_CTRL_ID_SCROLL_UP,
8164 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8165 -1, -1, /* these values are not constant, but can change at runtime */
8166 SCREEN_CTRL_ID_SCROLL_DOWN,
8173 int gfx_unpressed, gfx_pressed;
8179 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8182 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8183 -1, -1, /* these values are not constant, but can change at runtime */
8184 -1, -1, /* these values are not constant, but can change at runtime */
8185 GD_TYPE_SCROLLBAR_VERTICAL,
8186 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8187 "scroll level series vertically"
8191 static void CreateScreenMenubuttons(void)
8193 struct GadgetInfo *gi;
8194 unsigned int event_mask;
8197 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8199 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8200 int gfx_unpressed, gfx_pressed;
8201 int x, y, width, height;
8202 int gd_x1, gd_x2, gd_y1, gd_y2;
8203 int id = menubutton_info[i].gadget_id;
8205 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8206 event_mask = GD_EVENT_RELEASED;
8208 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8210 menubutton_info[i].get_gadget_position(&x, &y, id);
8212 if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION)
8214 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8215 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8219 width = SC_MENUBUTTON_XSIZE;
8220 height = SC_MENUBUTTON_YSIZE;
8223 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8224 gfx_pressed = menubutton_info[i].gfx_pressed;
8225 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8226 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8227 gd_x1 = graphic_info[gfx_unpressed].src_x;
8228 gd_y1 = graphic_info[gfx_unpressed].src_y;
8229 gd_x2 = graphic_info[gfx_pressed].src_x;
8230 gd_y2 = graphic_info[gfx_pressed].src_y;
8232 gi = CreateGadget(GDI_CUSTOM_ID, id,
8233 GDI_CUSTOM_TYPE_ID, i,
8234 GDI_IMAGE_ID, gfx_unpressed,
8235 GDI_INFO_TEXT, menubutton_info[i].infotext,
8240 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8241 GDI_STATE, GD_BUTTON_UNPRESSED,
8242 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8243 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8244 GDI_DIRECT_DRAW, FALSE,
8245 GDI_EVENT_MASK, event_mask,
8246 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8250 Error(ERR_EXIT, "cannot create gadget");
8252 screen_gadget[id] = gi;
8256 static void CreateScreenScrollbuttons(void)
8258 struct GadgetInfo *gi;
8259 unsigned int event_mask;
8262 /* these values are not constant, but can change at runtime */
8263 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8264 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8265 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8266 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8268 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8270 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8271 int gfx_unpressed, gfx_pressed;
8272 int x, y, width, height;
8273 int gd_x1, gd_x2, gd_y1, gd_y2;
8274 int id = scrollbutton_info[i].gadget_id;
8276 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8278 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8279 y = mSY + scrollbutton_info[i].y;
8280 width = SC_SCROLLBUTTON_XSIZE;
8281 height = SC_SCROLLBUTTON_YSIZE;
8283 /* correct scrollbar position if placed outside menu (playfield) area */
8284 if (x > SX + SC_SCROLL_UP_XPOS)
8285 x = SX + SC_SCROLL_UP_XPOS;
8287 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8288 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8289 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8291 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8292 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8293 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8294 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8295 gd_x1 = graphic_info[gfx_unpressed].src_x;
8296 gd_y1 = graphic_info[gfx_unpressed].src_y;
8297 gd_x2 = graphic_info[gfx_pressed].src_x;
8298 gd_y2 = graphic_info[gfx_pressed].src_y;
8300 gi = CreateGadget(GDI_CUSTOM_ID, id,
8301 GDI_CUSTOM_TYPE_ID, i,
8302 GDI_IMAGE_ID, gfx_unpressed,
8303 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8308 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8309 GDI_STATE, GD_BUTTON_UNPRESSED,
8310 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8311 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8312 GDI_DIRECT_DRAW, FALSE,
8313 GDI_EVENT_MASK, event_mask,
8314 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8318 Error(ERR_EXIT, "cannot create gadget");
8320 screen_gadget[id] = gi;
8324 static void CreateScreenScrollbars(void)
8328 /* these values are not constant, but can change at runtime */
8329 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8330 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8331 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8332 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8334 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8336 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8337 int gfx_unpressed, gfx_pressed;
8338 int x, y, width, height;
8339 int gd_x1, gd_x2, gd_y1, gd_y2;
8340 struct GadgetInfo *gi;
8341 int items_max, items_visible, item_position;
8342 unsigned int event_mask;
8343 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8344 int id = scrollbar_info[i].gadget_id;
8346 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8348 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8349 y = mSY + scrollbar_info[i].y;
8350 width = scrollbar_info[i].width;
8351 height = scrollbar_info[i].height;
8353 /* correct scrollbar position if placed outside menu (playfield) area */
8354 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8355 x = SX + SC_SCROLL_VERTICAL_XPOS;
8357 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8358 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8360 items_max = num_page_entries;
8361 items_visible = num_page_entries;
8364 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8365 gfx_pressed = scrollbar_info[i].gfx_pressed;
8366 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8367 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8368 gd_x1 = graphic_info[gfx_unpressed].src_x;
8369 gd_y1 = graphic_info[gfx_unpressed].src_y;
8370 gd_x2 = graphic_info[gfx_pressed].src_x;
8371 gd_y2 = graphic_info[gfx_pressed].src_y;
8373 gi = CreateGadget(GDI_CUSTOM_ID, id,
8374 GDI_CUSTOM_TYPE_ID, i,
8375 GDI_IMAGE_ID, gfx_unpressed,
8376 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8381 GDI_TYPE, scrollbar_info[i].type,
8382 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8383 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8384 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8385 GDI_WHEEL_AREA_X, SX,
8386 GDI_WHEEL_AREA_Y, SY,
8387 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8388 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8389 GDI_STATE, GD_BUTTON_UNPRESSED,
8390 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8391 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8392 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8393 GDI_DIRECT_DRAW, FALSE,
8394 GDI_EVENT_MASK, event_mask,
8395 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8399 Error(ERR_EXIT, "cannot create gadget");
8401 screen_gadget[id] = gi;
8405 void CreateScreenGadgets(void)
8407 CreateScreenMenubuttons();
8409 CreateScreenScrollbuttons();
8410 CreateScreenScrollbars();
8413 void FreeScreenGadgets(void)
8417 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8418 FreeGadget(screen_gadget[i]);
8421 void MapScreenMenuGadgets(int screen_mask)
8425 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8426 if (screen_mask & menubutton_info[i].screen_mask)
8427 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8430 static void UnmapScreenMenuGadgets(int screen_mask)
8434 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8436 if (screen_mask & menubutton_info[i].screen_mask)
8438 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8440 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8441 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8442 screen_gadget[menubutton_info[i].gadget_id]->y,
8443 screen_gadget[menubutton_info[i].gadget_id]->width,
8444 screen_gadget[menubutton_info[i].gadget_id]->height);
8449 void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8452 MapScreenMenuGadgets(screen_mask);
8454 UnmapScreenMenuGadgets(screen_mask);
8457 void MapScreenGadgets(int num_entries)
8461 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8464 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8465 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8467 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8468 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8471 void MapScreenTreeGadgets(TreeInfo *ti)
8473 MapScreenGadgets(numTreeInfoInGroup(ti));
8476 static void HandleScreenGadgets(struct GadgetInfo *gi)
8478 int id = gi->custom_id;
8479 int button = gi->event.button;
8480 int step = (button == MB_LEFTBUTTON ? 1 :
8481 button == MB_MIDDLEBUTTON ? 5 :
8482 button == MB_RIGHTBUTTON ? 10 : 1);
8486 case SCREEN_CTRL_ID_PREV_LEVEL:
8487 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8490 case SCREEN_CTRL_ID_NEXT_LEVEL:
8491 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8494 case SCREEN_CTRL_ID_PREV_PLAYER:
8495 HandleSetupScreen_Input_Player(step, -1);
8498 case SCREEN_CTRL_ID_NEXT_PLAYER:
8499 HandleSetupScreen_Input_Player(step, +1);
8502 case SCREEN_CTRL_ID_INSERT_SOLUTION:
8503 InsertSolutionTape();
8506 case SCREEN_CTRL_ID_PLAY_SOLUTION:
8510 case SCREEN_CTRL_ID_SCROLL_UP:
8511 if (game_status == GAME_MODE_LEVELS)
8512 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8513 else if (game_status == GAME_MODE_LEVELNR)
8514 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8515 else if (game_status == GAME_MODE_SETUP)
8516 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8517 else if (game_status == GAME_MODE_INFO)
8518 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
8521 case SCREEN_CTRL_ID_SCROLL_DOWN:
8522 if (game_status == GAME_MODE_LEVELS)
8523 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8524 else if (game_status == GAME_MODE_LEVELNR)
8525 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8526 else if (game_status == GAME_MODE_SETUP)
8527 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8528 else if (game_status == GAME_MODE_INFO)
8529 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
8532 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
8533 if (game_status == GAME_MODE_LEVELS)
8534 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8535 else if (game_status == GAME_MODE_LEVELNR)
8536 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
8537 else if (game_status == GAME_MODE_SETUP)
8538 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8539 else if (game_status == GAME_MODE_INFO)
8540 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
8548 void DumpScreenIdentifiers(void)
8552 Print("Active screen elements on current screen:\n");
8554 for (i = 0; main_controls[i].nr != -1; i++)
8556 struct MainControlInfo *mci = &main_controls[i];
8558 if (mci->button_graphic != -1)
8560 char *token = getTokenFromImageID(mci->button_graphic);
8562 Print("- '%s'\n", token);
8569 boolean DoScreenAction(int image_id)
8573 if (game_status != GAME_MODE_MAIN)
8576 for (i = 0; main_controls[i].nr != -1; i++)
8578 struct MainControlInfo *mci = &main_controls[i];
8579 struct MenuPosInfo *pos = mci->pos_button;
8581 if (mci->button_graphic == image_id)
8583 int x = mSX + pos->x;
8584 int y = mSY + pos->y;
8586 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);