1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://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_ENGINES 2
48 #define SETUP_MODE_EDITOR 3
49 #define SETUP_MODE_GRAPHICS 4
50 #define SETUP_MODE_SOUND 5
51 #define SETUP_MODE_ARTWORK 6
52 #define SETUP_MODE_INPUT 7
53 #define SETUP_MODE_TOUCH 8
54 #define SETUP_MODE_SHORTCUTS 9
55 #define SETUP_MODE_SHORTCUTS_1 10
56 #define SETUP_MODE_SHORTCUTS_2 11
57 #define SETUP_MODE_SHORTCUTS_3 12
58 #define SETUP_MODE_SHORTCUTS_4 13
59 #define SETUP_MODE_SHORTCUTS_5 14
61 // sub-screens on the setup screen (generic)
62 #define SETUP_MODE_CHOOSE_ARTWORK 15
63 #define SETUP_MODE_CHOOSE_OTHER 16
65 // sub-screens on the setup screen (specific)
66 #define SETUP_MODE_CHOOSE_GAME_SPEED 17
67 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 18
68 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 19
69 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 20
70 #define SETUP_MODE_CHOOSE_SCALING_TYPE 21
71 #define SETUP_MODE_CHOOSE_RENDERING 22
72 #define SETUP_MODE_CHOOSE_VSYNC 23
73 #define SETUP_MODE_CHOOSE_GRAPHICS 24
74 #define SETUP_MODE_CHOOSE_SOUNDS 25
75 #define SETUP_MODE_CHOOSE_MUSIC 26
76 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 27
77 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 28
78 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 29
79 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 30
80 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 31
81 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 32
82 #define SETUP_MODE_CHOOSE_TRANSPARENCY 33
83 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 34
84 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 35
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 36
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 37
87 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 38
89 #define MAX_SETUP_MODES 39
91 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
93 // setup screen titles
94 #define STR_SETUP_MAIN "Setup"
95 #define STR_SETUP_GAME "Game & Menu"
96 #define STR_SETUP_ENGINES "Game Engines"
97 #define STR_SETUP_EDITOR "Editor"
98 #define STR_SETUP_GRAPHICS "Graphics"
99 #define STR_SETUP_SOUND "Sound & Music"
100 #define STR_SETUP_ARTWORK "Custom Artwork"
101 #define STR_SETUP_INPUT "Input Devices"
102 #define STR_SETUP_TOUCH "Touch Controls"
103 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
104 #define STR_SETUP_EXIT "Exit"
105 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
107 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
108 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
109 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
110 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
111 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
112 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
113 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
114 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
115 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
116 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
117 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
118 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
119 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
120 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
121 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
122 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
123 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
124 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
126 // for input setup functions
127 #define SETUPINPUT_SCREEN_POS_START 0
128 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
129 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
130 #define SETUPINPUT_SCREEN_POS_END 13
132 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
133 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
135 #define MAX_SETUP_TEXT_INPUT_LEN 28
137 // for various menu stuff
138 #define MENU_SCREEN_START_XPOS 1
139 #define MENU_SCREEN_START_YPOS 2
140 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
141 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
142 #define MENU_TITLE1_YPOS 8
143 #define MENU_TITLE2_YPOS 46
144 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
145 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
146 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
147 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
148 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
149 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
150 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
151 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
152 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
153 #define MENU_SCREEN_INFO_YSTART1 MENU_SCREEN_INFO_SPACE_TOP
154 #define MENU_SCREEN_INFO_YSTART2 (MENU_SCREEN_INFO_YSTART1 + \
155 getMenuTextStep(MENU_INFO_SPACE_HEAD, \
156 MENU_INFO_FONT_TITLE))
157 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
158 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
159 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
160 MENU_SCREEN_INFO_YSTART2 - \
162 #define MAX_INFO_ELEMENTS_ON_SCREEN 128
163 #define STD_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
164 MENU_SCREEN_INFO_YSTEP)
165 #define NUM_INFO_ELEMENTS_FROM_CONF \
166 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
167 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
168 MAX_MENU_ENTRIES_ON_SCREEN)
169 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
170 MAX_INFO_ELEMENTS_ON_SCREEN), \
171 NUM_INFO_ELEMENTS_FROM_CONF)
172 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
173 #define MAX_MENU_TEXT_LENGTH_BIG 13
174 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
176 // screen gadget identifiers
177 #define SCREEN_CTRL_ID_PREV_LEVEL 0
178 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
179 #define SCREEN_CTRL_ID_FIRST_LEVEL 2
180 #define SCREEN_CTRL_ID_LAST_LEVEL 3
181 #define SCREEN_CTRL_ID_LEVEL_NUMBER 4
182 #define SCREEN_CTRL_ID_PREV_PLAYER 5
183 #define SCREEN_CTRL_ID_NEXT_PLAYER 6
184 #define SCREEN_CTRL_ID_INSERT_SOLUTION 7
185 #define SCREEN_CTRL_ID_PLAY_SOLUTION 8
186 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 9
187 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 10
188 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 11
189 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 12
190 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 13
191 #define SCREEN_CTRL_ID_SCROLL_UP 14
192 #define SCREEN_CTRL_ID_SCROLL_DOWN 15
193 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 16
194 #define SCREEN_CTRL_ID_NETWORK_SERVER 17
196 #define NUM_SCREEN_GADGETS 18
198 #define NUM_SCREEN_MENUBUTTONS 14
199 #define NUM_SCREEN_SCROLLBUTTONS 2
200 #define NUM_SCREEN_SCROLLBARS 1
201 #define NUM_SCREEN_TEXTINPUT 1
203 #define SCREEN_MASK_MAIN (1 << 0)
204 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
205 #define SCREEN_MASK_INPUT (1 << 2)
206 #define SCREEN_MASK_TOUCH (1 << 3)
207 #define SCREEN_MASK_TOUCH2 (1 << 4)
209 // graphic position and size values for buttons and scrollbars
210 #define SC_MENUBUTTON_XSIZE TILEX
211 #define SC_MENUBUTTON_YSIZE TILEY
213 #define SC_SCROLLBUTTON_XSIZE TILEX
214 #define SC_SCROLLBUTTON_YSIZE TILEY
216 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
218 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
219 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
220 SC_SCROLLBUTTON_YSIZE)
222 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
223 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
225 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
226 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
227 SC_SCROLLBUTTON_YSIZE)
229 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
230 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
231 SC_SCROLL_VERTICAL_YSIZE)
233 #define SC_BORDER_SIZE 14
236 // forward declarations of internal functions
237 static void HandleScreenGadgets(struct GadgetInfo *);
238 static void HandleSetupScreen_Generic(int, int, int, int, int);
239 static void HandleSetupScreen_Input(int, int, int, int, int);
240 static void CustomizeKeyboard(int);
241 static void ConfigureJoystick(int);
242 static void ConfigureVirtualButtons(void);
243 static void execSetupGame(void);
244 static void execSetupEngines(void);
245 static void execSetupGraphics(void);
246 static void execSetupSound(void);
247 static void execSetupTouch(void);
248 static void execSetupArtwork(void);
249 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
251 static void DrawChooseLevelSet(void);
252 static void DrawChooseLevelNr(void);
253 static void DrawInfoScreen(void);
254 static void DrawSetupScreen(void);
256 static void DrawInfoScreen_NotAvailable(char *, char *);
257 static void DrawInfoScreen_HelpAnim(int, int, boolean);
258 static void DrawInfoScreen_HelpText(int, int, int, int);
259 static void HandleInfoScreen_Main(int, int, int, int, int);
260 static void HandleInfoScreen_TitleScreen(int);
261 static void HandleInfoScreen_Elements(int);
262 static void HandleInfoScreen_Music(int);
263 static void HandleInfoScreen_Credits(int);
264 static void HandleInfoScreen_Program(int);
265 static void HandleInfoScreen_Version(int);
267 static void ModifyGameSpeedIfNeeded(void);
268 static void DisableVsyncIfNeeded(void);
270 static void MapScreenMenuGadgets(int);
271 static void UnmapScreenMenuGadgets(int);
272 static void MapScreenGadgets(int);
273 static void MapScreenTreeGadgets(TreeInfo *);
275 static void UpdateScreenMenuGadgets(int, boolean);
277 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
279 static int info_mode = INFO_MODE_MAIN;
280 static int setup_mode = SETUP_MODE_MAIN;
282 static TreeInfo *window_sizes = NULL;
283 static TreeInfo *window_size_current = NULL;
285 static TreeInfo *scaling_types = NULL;
286 static TreeInfo *scaling_type_current = NULL;
288 static TreeInfo *rendering_modes = NULL;
289 static TreeInfo *rendering_mode_current = NULL;
291 static TreeInfo *vsync_modes = NULL;
292 static TreeInfo *vsync_mode_current = NULL;
294 static TreeInfo *scroll_delays = NULL;
295 static TreeInfo *scroll_delay_current = NULL;
297 static TreeInfo *snapshot_modes = NULL;
298 static TreeInfo *snapshot_mode_current = NULL;
300 static TreeInfo *game_speeds_normal = NULL;
301 static TreeInfo *game_speeds_extended = NULL;
302 static TreeInfo *game_speeds = NULL;
303 static TreeInfo *game_speed_current = NULL;
305 static TreeInfo *volumes_simple = NULL;
306 static TreeInfo *volume_simple_current = NULL;
308 static TreeInfo *volumes_loops = NULL;
309 static TreeInfo *volume_loops_current = NULL;
311 static TreeInfo *volumes_music = NULL;
312 static TreeInfo *volume_music_current = NULL;
314 static TreeInfo *touch_controls = NULL;
315 static TreeInfo *touch_control_current = NULL;
317 static TreeInfo *move_distances = NULL;
318 static TreeInfo *move_distance_current = NULL;
320 static TreeInfo *drop_distances = NULL;
321 static TreeInfo *drop_distance_current = NULL;
323 static TreeInfo *transparencies = NULL;
324 static TreeInfo *transparency_current = NULL;
326 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
327 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
329 static TreeInfo *level_number = NULL;
330 static TreeInfo *level_number_current = NULL;
332 static struct ValueTextInfo window_sizes_list[] =
337 { 100, "100 % (Default)" },
350 static struct StringValueTextInfo scaling_types_list[] =
352 { SCALING_QUALITY_NEAREST, "Off" },
353 { SCALING_QUALITY_LINEAR, "Linear" },
354 { SCALING_QUALITY_BEST, "Anisotropic" },
359 static struct StringValueTextInfo rendering_modes_list[] =
361 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
362 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
364 // this mode may work under certain conditions, but does not work on Windows
365 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
367 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
372 static struct StringValueTextInfo vsync_modes_list[] =
374 { STR_VSYNC_MODE_OFF, "Off" },
375 { STR_VSYNC_MODE_NORMAL, "Normal" },
376 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
381 static struct ValueTextInfo game_speeds_list_normal[] =
392 static struct ValueTextInfo game_speeds_list_extended[] =
394 { 1000, "1 fps (Extremely Slow)" },
399 { 29, "35 fps (Original Supaplex)" },
401 { 20, "50 fps (=== Normal Speed ===)" },
402 { 16, "60 fps (60 Hz VSync Speed)" },
403 { 14, "70 fps (Maximum Supaplex)" },
407 { 1, "1000 fps (Extremely Fast)" },
412 static struct ValueTextInfo *game_speeds_list;
414 static struct ValueTextInfo scroll_delays_list[] =
416 { 0, "0 Tiles (No Scroll Delay)" },
419 { 3, "3 Tiles (Default)" },
424 { 8, "8 Tiles (Maximum Scroll Delay)"},
429 static struct StringValueTextInfo snapshot_modes_list[] =
431 { STR_SNAPSHOT_MODE_OFF, "Off" },
432 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
433 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
434 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
439 static struct ValueTextInfo volumes_list[] =
459 static struct StringValueTextInfo touch_controls_list[] =
461 { TOUCH_CONTROL_OFF, "Off" },
462 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
463 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
464 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
469 static struct ValueTextInfo distances_list[] =
484 static struct ValueTextInfo transparencies_list[] =
486 { 0, "0 % (Opaque)" },
496 { 100, "100 % (Invisible)" },
501 static struct ValueTextInfo grid_sizes_list[] =
537 static int align_xoffset = 0;
538 static int align_yoffset = 0;
540 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
541 (s) <= GAME_MODE_SETUP ? (s) : \
542 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
543 GAME_MODE_MAIN : GAME_MODE_DEFAULT)
545 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
546 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
547 (i) <= INFO_MODE_LEVELSET ? (i) : \
550 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
551 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
552 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
553 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
554 SETUP_MODE_CHOOSE_ARTWORK : \
555 SETUP_MODE_CHOOSE_OTHER)
557 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
558 menu.draw_xoffset[GAME_MODE_INFO] : \
559 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
560 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
561 menu.draw_yoffset[GAME_MODE_INFO] : \
562 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
563 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
564 menu.extra_spacing[GAME_MODE_INFO] : \
565 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
567 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
568 menu.draw_xoffset[GAME_MODE_SETUP] : \
569 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
570 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
571 menu.draw_yoffset[GAME_MODE_SETUP] : \
572 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
573 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
574 menu.extra_spacing[GAME_MODE_SETUP] : \
575 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
577 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
578 DRAW_XOFFSET_INFO(info_mode) : \
579 (s) == GAME_MODE_SETUP ? \
580 DRAW_XOFFSET_SETUP(setup_mode) : \
581 menu.draw_xoffset[DRAW_MODE(s)])
582 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
583 DRAW_YOFFSET_INFO(info_mode) : \
584 (s) == GAME_MODE_SETUP ? \
585 DRAW_YOFFSET_SETUP(setup_mode) : \
586 menu.draw_yoffset[DRAW_MODE(s)])
587 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
588 EXTRA_SPACING_INFO(info_mode) : \
589 (s) == GAME_MODE_SETUP ? \
590 EXTRA_SPACING_SETUP(setup_mode) : \
591 menu.extra_spacing[DRAW_MODE(s)])
593 #define mSX (SX + DRAW_XOFFSET(game_status))
594 #define mSY (SY + DRAW_YOFFSET(game_status))
596 #define amSX (mSX + align_xoffset)
597 #define amSY (mSY + align_yoffset)
599 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
600 menu.list_size[game_status] : \
601 MAX_MENU_ENTRIES_ON_SCREEN)
603 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
604 NUM_MENU_ENTRIES_ON_SCREEN)
607 // title display and control definitions
609 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
610 2 * MAX_NUM_TITLE_MESSAGES)
612 #define NO_DIRECT_LEVEL_SELECT (-1)
615 static int num_title_screens = 0;
617 struct TitleControlInfo
626 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
628 // main menu display and control definitions
630 #define MAIN_CONTROL_NAME 0
631 #define MAIN_CONTROL_LEVELS 1
632 #define MAIN_CONTROL_SCORES 2
633 #define MAIN_CONTROL_EDITOR 3
634 #define MAIN_CONTROL_INFO 4
635 #define MAIN_CONTROL_GAME 5
636 #define MAIN_CONTROL_SETUP 6
637 #define MAIN_CONTROL_QUIT 7
638 #define MAIN_CONTROL_PREV_LEVEL 8
639 #define MAIN_CONTROL_NEXT_LEVEL 9
640 #define MAIN_CONTROL_FIRST_LEVEL 10
641 #define MAIN_CONTROL_LAST_LEVEL 11
642 #define MAIN_CONTROL_LEVEL_NUMBER 12
643 #define MAIN_CONTROL_LEVEL_INFO_1 13
644 #define MAIN_CONTROL_LEVEL_INFO_2 14
645 #define MAIN_CONTROL_LEVEL_NAME 15
646 #define MAIN_CONTROL_LEVEL_AUTHOR 16
647 #define MAIN_CONTROL_LEVEL_YEAR 17
648 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
649 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
650 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
651 #define MAIN_CONTROL_TITLE_1 21
652 #define MAIN_CONTROL_TITLE_2 22
653 #define MAIN_CONTROL_TITLE_3 23
655 static char str_main_text_name[10];
656 static char str_main_text_first_level[10];
657 static char str_main_text_last_level[10];
658 static char str_main_text_level_number[10];
660 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
662 static char *main_text_name = str_main_text_name;
663 static char *main_text_first_level = str_main_text_first_level;
664 static char *main_text_last_level = str_main_text_last_level;
665 static char *main_text_level_number = str_main_text_level_number;
666 static char *main_text_levels = "Levelset";
667 static char *main_text_scores = "Hall Of Fame";
668 static char *main_text_editor = "Level Creator";
669 static char *main_text_info = "Info Screen";
670 static char *main_text_game = "Start Game";
671 static char *main_text_setup = "Setup";
672 static char *main_text_quit = "Quit";
673 static char *main_text_level_name = level.name;
674 static char *main_text_level_author = level.author;
675 static char *main_text_level_year = NULL;
676 static char *main_text_level_imported_from = NULL;
677 static char *main_text_level_imported_by = NULL;
678 static char *main_text_level_tested_by = NULL;
679 static char *main_text_title_1 = NULL;
680 static char *main_text_title_2 = NULL;
681 static char *main_text_title_3 = NULL;
683 struct MainControlInfo
687 struct MenuPosInfo *pos_button;
690 struct TextPosInfo *pos_text;
693 struct TextPosInfo *pos_input;
697 static struct MainControlInfo main_controls[] =
701 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
702 &menu.main.text.name, &main_text_name,
703 &menu.main.input.name, &setup.player_name,
707 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
708 &menu.main.text.levels, &main_text_levels,
713 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
714 &menu.main.text.scores, &main_text_scores,
719 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
720 &menu.main.text.editor, &main_text_editor,
725 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
726 &menu.main.text.info, &main_text_info,
731 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
732 &menu.main.text.game, &main_text_game,
737 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
738 &menu.main.text.setup, &main_text_setup,
743 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
744 &menu.main.text.quit, &main_text_quit,
748 MAIN_CONTROL_PREV_LEVEL,
754 MAIN_CONTROL_NEXT_LEVEL,
760 MAIN_CONTROL_FIRST_LEVEL,
762 &menu.main.text.first_level, &main_text_first_level,
766 MAIN_CONTROL_LAST_LEVEL,
768 &menu.main.text.last_level, &main_text_last_level,
772 MAIN_CONTROL_LEVEL_NUMBER,
774 &menu.main.text.level_number, &main_text_level_number,
778 MAIN_CONTROL_LEVEL_INFO_1,
780 &menu.main.text.level_info_1, NULL,
784 MAIN_CONTROL_LEVEL_INFO_2,
786 &menu.main.text.level_info_2, NULL,
790 MAIN_CONTROL_LEVEL_NAME,
792 &menu.main.text.level_name, &main_text_level_name,
796 MAIN_CONTROL_LEVEL_AUTHOR,
798 &menu.main.text.level_author, &main_text_level_author,
802 MAIN_CONTROL_LEVEL_YEAR,
804 &menu.main.text.level_year, &main_text_level_year,
808 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
810 &menu.main.text.level_imported_from, &main_text_level_imported_from,
814 MAIN_CONTROL_LEVEL_IMPORTED_BY,
816 &menu.main.text.level_imported_by, &main_text_level_imported_by,
820 MAIN_CONTROL_LEVEL_TESTED_BY,
822 &menu.main.text.level_tested_by, &main_text_level_tested_by,
826 MAIN_CONTROL_TITLE_1,
828 &menu.main.text.title_1, &main_text_title_1,
832 MAIN_CONTROL_TITLE_2,
834 &menu.main.text.title_2, &main_text_title_2,
838 MAIN_CONTROL_TITLE_3,
840 &menu.main.text.title_3, &main_text_title_3,
853 static int getTitleScreenGraphic(int nr, boolean initial)
855 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
858 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
860 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
864 static int getTitleScreenGameMode(boolean initial)
866 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
870 static int getTitleMessageGameMode(boolean initial)
872 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
875 static int getTitleAnimMode(struct TitleControlInfo *tci)
877 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
879 return base + tci->local_nr;
883 static int getTitleScreenBackground(boolean initial)
885 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
890 static int getTitleMessageBackground(int nr, boolean initial)
892 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
896 static int getTitleBackground(int nr, boolean initial, boolean is_image)
898 int base = (is_image ?
899 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
900 IMG_BACKGROUND_TITLESCREEN_1) :
901 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
902 IMG_BACKGROUND_TITLEMESSAGE_1));
903 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
904 IMG_BACKGROUND_TITLE);
905 int graphic_local = base + nr;
907 if (graphic_info[graphic_local].bitmap != NULL)
908 return graphic_local;
910 if (graphic_info[graphic_global].bitmap != NULL)
911 return graphic_global;
913 return IMG_UNDEFINED;
916 static int getTitleSound(struct TitleControlInfo *tci)
918 boolean is_image = tci->is_image;
919 int initial = tci->initial;
920 int nr = tci->local_nr;
921 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
922 int base = (is_image ?
923 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
924 SND_BACKGROUND_TITLESCREEN_1) :
925 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
926 SND_BACKGROUND_TITLEMESSAGE_1));
927 int sound_global = menu.sound[mode];
928 int sound_local = base + nr;
931 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
932 nr, initial, is_image,
933 sound_global, getSoundListEntry(sound_global)->filename,
934 sound_local, getSoundListEntry(sound_local)->filename);
937 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
940 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
943 return SND_UNDEFINED;
946 static int getTitleMusic(struct TitleControlInfo *tci)
948 boolean is_image = tci->is_image;
949 int initial = tci->initial;
950 int nr = tci->local_nr;
951 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
952 int base = (is_image ?
953 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
954 MUS_BACKGROUND_TITLESCREEN_1) :
955 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
956 MUS_BACKGROUND_TITLEMESSAGE_1));
957 int music_global = menu.music[mode];
958 int music_local = base + nr;
961 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
962 nr, initial, is_image,
963 music_global, getMusicListEntry(music_global)->filename,
964 music_local, getMusicListEntry(music_local)->filename);
967 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
970 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
973 return MUS_UNDEFINED;
976 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
978 boolean is_image = tci->is_image;
979 boolean initial = tci->initial;
980 boolean first = tci->first;
981 int nr = tci->local_nr;
982 struct TitleMessageInfo tmi;
983 struct TitleFadingInfo ti;
985 tmi = (is_image ? (initial ? (first ?
986 titlescreen_initial_first[nr] :
987 titlescreen_initial[nr])
989 titlescreen_first[nr] :
991 : (initial ? (first ?
992 titlemessage_initial_first[nr] :
993 titlemessage_initial[nr])
995 titlemessage_first[nr] :
998 ti.fade_mode = tmi.fade_mode;
999 ti.fade_delay = tmi.fade_delay;
1000 ti.post_delay = tmi.post_delay;
1001 ti.auto_delay = tmi.auto_delay;
1002 ti.auto_delay_unit = tmi.auto_delay_unit;
1007 static int compareTitleControlInfo(const void *object1, const void *object2)
1009 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1010 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1013 if (tci1->initial != tci2->initial)
1014 compare_result = (tci1->initial ? -1 : +1);
1015 else if (tci1->sort_priority != tci2->sort_priority)
1016 compare_result = tci1->sort_priority - tci2->sort_priority;
1017 else if (tci1->is_image != tci2->is_image)
1018 compare_result = (tci1->is_image ? -1 : +1);
1020 compare_result = tci1->local_nr - tci2->local_nr;
1022 return compare_result;
1025 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1027 int nr, int sort_priority)
1029 title_controls[num_title_screens].is_image = is_image;
1030 title_controls[num_title_screens].initial = initial;
1031 title_controls[num_title_screens].local_nr = nr;
1032 title_controls[num_title_screens].sort_priority = sort_priority;
1034 title_controls[num_title_screens].first = FALSE; // will be set later
1036 num_title_screens++;
1039 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1043 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1045 int graphic = getTitleScreenGraphic(i, initial);
1046 Bitmap *bitmap = graphic_info[graphic].bitmap;
1047 int sort_priority = graphic_info[graphic].sort_priority;
1050 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1053 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1055 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1056 char *filename = getLevelSetTitleMessageFilename(i, initial);
1057 int sort_priority = tmi->sort_priority;
1059 if (filename != NULL)
1060 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1064 static void InitializeTitleControls(boolean show_title_initial)
1066 num_title_screens = 0;
1068 // 1st step: initialize title screens for game start (only when starting)
1069 if (show_title_initial)
1070 InitializeTitleControls_CheckTitleInfo(TRUE);
1072 // 2nd step: initialize title screens for current level set
1073 InitializeTitleControls_CheckTitleInfo(FALSE);
1075 // sort title screens according to sort_priority and title number
1076 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1077 compareTitleControlInfo);
1079 // mark first title screen
1080 title_controls[0].first = TRUE;
1083 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1085 return (pos != NULL && pos->x != -1 && pos->y != -1);
1088 static boolean visibleTextPos(struct TextPosInfo *pos)
1090 return (pos != NULL && pos->x != -1 && pos->y != -1);
1093 static void InitializeMainControls(void)
1095 boolean local_team_mode = (!network.enabled && setup.team_mode);
1098 // set main control text values to dynamically determined values
1099 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1101 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1102 menu.main.text.first_level.size));
1103 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1104 menu.main.text.last_level.size));
1105 strcpy(main_text_level_number, int2str(level_nr,
1106 menu.main.text.level_number.size));
1108 main_text_level_year = leveldir_current->year;
1109 main_text_level_imported_from = leveldir_current->imported_from;
1110 main_text_level_imported_by = leveldir_current->imported_by;
1111 main_text_level_tested_by = leveldir_current->tested_by;
1113 main_text_title_1 = getConfigProgramTitleString();
1114 main_text_title_2 = getConfigProgramCopyrightString();
1115 main_text_title_3 = getConfigProgramCompanyString();
1117 // set main control screen positions to dynamically determined values
1118 for (i = 0; main_controls[i].nr != -1; i++)
1120 struct MainControlInfo *mci = &main_controls[i];
1122 struct MenuPosInfo *pos_button = mci->pos_button;
1123 struct TextPosInfo *pos_text = mci->pos_text;
1124 struct TextPosInfo *pos_input = mci->pos_input;
1125 char *text = (mci->text ? *mci->text : NULL);
1126 char *input = (mci->input ? *mci->input : NULL);
1127 int button_graphic = mci->button_graphic;
1128 int font_text = (pos_text ? pos_text->font : -1);
1129 int font_input = (pos_input ? pos_input->font : -1);
1131 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1132 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1133 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1134 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1135 int text_chars = (text != NULL ? strlen(text) : 0);
1136 int input_chars = (input != NULL ? strlen(input) : 0);
1139 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1141 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1142 int text_width = font_text_width * text_chars;
1143 int text_height = font_text_height;
1144 int input_width = font_input_width * input_chars;
1145 int input_height = font_input_height;
1147 if (nr == MAIN_CONTROL_NAME)
1149 menu.main.input.name.width = input_width;
1150 menu.main.input.name.height = input_height;
1153 if (pos_button != NULL) // (x/y may be -1/-1 here)
1155 pos_button->width = button_width;
1156 pos_button->height = button_height;
1159 if (pos_text != NULL) // (x/y may be -1/-1 here)
1161 // calculate text size -- needed for text alignment
1162 boolean calculate_text_size = (text != NULL);
1164 if (pos_text->width == -1 || calculate_text_size)
1165 pos_text->width = text_width;
1166 if (pos_text->height == -1 || calculate_text_size)
1167 pos_text->height = text_height;
1169 if (visibleMenuPos(pos_button))
1171 if (pos_text->x == -1)
1172 pos_text->x = pos_button->x + pos_button->width;
1173 if (pos_text->y == -1)
1175 pos_button->y + (pos_button->height - pos_text->height) / 2;
1179 if (pos_input != NULL) // (x/y may be -1/-1 here)
1181 if (visibleTextPos(pos_text))
1183 if (pos_input->x == -1)
1184 pos_input->x = pos_text->x + pos_text->width;
1185 if (pos_input->y == -1)
1186 pos_input->y = pos_text->y;
1189 if (pos_input->width == -1)
1190 pos_input->width = input_width;
1191 if (pos_input->height == -1)
1192 pos_input->height = input_height;
1197 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1198 int graphic, boolean pressed)
1200 struct GraphicInfo *g = &graphic_info[graphic];
1203 int xoffset = (pressed ? g->pressed_xoffset : 0);
1204 int yoffset = (pressed ? g->pressed_yoffset : 0);
1206 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1208 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1209 g->width, g->height, dst_x, dst_y);
1212 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1213 boolean active_input,
1214 boolean pressed_button)
1218 for (i = 0; main_controls[i].nr != -1; i++)
1220 struct MainControlInfo *mci = &main_controls[i];
1222 if (mci->nr == nr || nr == -1)
1224 struct MenuPosInfo *pos_button = mci->pos_button;
1225 struct TextPosInfo *pos_text = mci->pos_text;
1226 struct TextPosInfo *pos_input = mci->pos_input;
1227 char *text = (mci->text ? *mci->text : NULL);
1228 char *input = (mci->input ? *mci->input : NULL);
1229 int button_graphic = mci->button_graphic;
1230 int font_text = (pos_text ? pos_text->font : -1);
1231 int font_input = (pos_input ? pos_input->font : -1);
1235 button_graphic = BUTTON_ACTIVE(button_graphic);
1236 font_text = FONT_ACTIVE(font_text);
1241 font_input = FONT_ACTIVE(font_input);
1244 if (visibleMenuPos(pos_button))
1246 struct MenuPosInfo *pos = pos_button;
1247 int x = mSX + pos->x;
1248 int y = mSY + pos->y;
1250 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1251 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1254 if (visibleTextPos(pos_text) && text != NULL)
1256 struct TextPosInfo *pos = pos_text;
1257 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1258 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1261 // (check why/if this is needed)
1262 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1264 DrawText(x, y, text, font_text);
1267 if (visibleTextPos(pos_input) && input != NULL)
1269 struct TextPosInfo *pos = pos_input;
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_input);
1277 DrawText(x, y, input, font_input);
1283 static void DrawCursorAndText_Main(int nr, boolean active_text,
1284 boolean pressed_button)
1286 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1290 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1291 boolean pressed_button)
1293 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1297 static struct MainControlInfo *getMainControlInfo(int nr)
1301 for (i = 0; main_controls[i].nr != -1; i++)
1302 if (main_controls[i].nr == nr)
1303 return &main_controls[i];
1308 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1313 int rect_x = ALIGNED_TEXT_XPOS(rect);
1314 int rect_y = ALIGNED_TEXT_YPOS(rect);
1316 return (x >= rect_x && x < rect_x + rect->width &&
1317 y >= rect_y && y < rect_y + rect->height);
1320 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1325 int rect_x = ALIGNED_TEXT_XPOS(rect);
1326 int rect_y = ALIGNED_TEXT_YPOS(rect);
1329 Debug("screens:insideTextPosRect",
1330 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1331 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1332 (x >= rect_x && x < rect_x + rect->width &&
1333 y >= rect_y && y < rect_y + rect->height));
1336 return (x >= rect_x && x < rect_x + rect->width &&
1337 y >= rect_y && y < rect_y + rect->height);
1340 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1342 int rect_width = preview->xsize * preview->tile_size;
1343 int rect_height = preview->ysize * preview->tile_size;
1344 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1345 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1347 return (x >= rect_x && x < rect_x + rect_width &&
1348 y >= rect_y && y < rect_y + rect_height);
1351 static void AdjustScrollbar(int id, int items_max, int items_visible,
1354 struct GadgetInfo *gi = screen_gadget[id];
1356 if (item_position > items_max - items_visible)
1357 item_position = items_max - items_visible;
1359 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1360 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1361 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1364 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1366 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1370 static void clearMenuListArea(void)
1372 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1374 // correct scrollbar position if placed outside menu (playfield) area
1375 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1376 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1378 // clear menu list area, but not title or scrollbar
1379 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1380 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1383 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1385 static int cursor_array[MAX_LEV_FIELDY];
1386 int x = amSX + TILEX * xpos;
1387 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1392 cursor_array[ypos] = graphic;
1394 graphic = cursor_array[ypos];
1398 graphic = BUTTON_ACTIVE(graphic);
1400 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1401 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1404 static void initCursor(int ypos, int graphic)
1406 drawCursorExt(0, ypos, FALSE, graphic);
1409 static void drawCursor(int ypos, boolean active)
1411 drawCursorExt(0, ypos, active, -1);
1414 static void drawCursorXY(int xpos, int ypos, int graphic)
1416 drawCursorExt(xpos, ypos, FALSE, graphic);
1419 static void drawChooseTreeCursor(int ypos, boolean active)
1421 drawCursorExt(0, ypos, active, -1);
1424 static void DrawHeadline(void)
1426 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1427 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1430 static void DrawTitleScreenImage(int nr, boolean initial)
1432 int graphic = getTitleScreenGraphic(nr, initial);
1433 Bitmap *bitmap = graphic_info[graphic].bitmap;
1434 int width = graphic_info[graphic].width;
1435 int height = graphic_info[graphic].height;
1436 int src_x = graphic_info[graphic].src_x;
1437 int src_y = graphic_info[graphic].src_y;
1443 if (width > WIN_XSIZE)
1445 // image width too large for window => center image horizontally
1446 src_x = (width - WIN_XSIZE) / 2;
1450 if (height > WIN_YSIZE)
1452 // image height too large for window => center image vertically
1453 src_y = (height - WIN_YSIZE) / 2;
1457 // always display title screens centered
1458 dst_x = (WIN_XSIZE - width) / 2;
1459 dst_y = (WIN_YSIZE - height) / 2;
1461 SetDrawBackgroundMask(REDRAW_ALL);
1462 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1464 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1466 if (DrawingOnBackground(dst_x, dst_y))
1467 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1469 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1471 redraw_mask = REDRAW_ALL;
1474 static void DrawTitleScreenMessage(int nr, boolean initial)
1476 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1477 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1479 if (filename == NULL)
1482 // force TITLE font on title message screen
1483 SetFontStatus(getTitleMessageGameMode(initial));
1485 // if chars *and* width set to "-1", automatically determine width
1486 if (tmi->chars == -1 && tmi->width == -1)
1487 tmi->width = viewport.window[game_status].width;
1489 // if lines *and* height set to "-1", automatically determine height
1490 if (tmi->lines == -1 && tmi->height == -1)
1491 tmi->height = viewport.window[game_status].height;
1493 // if chars set to "-1", automatically determine by text and font width
1494 if (tmi->chars == -1)
1495 tmi->chars = tmi->width / getFontWidth(tmi->font);
1497 tmi->width = tmi->chars * getFontWidth(tmi->font);
1499 // if lines set to "-1", automatically determine by text and font height
1500 if (tmi->lines == -1)
1501 tmi->lines = tmi->height / getFontHeight(tmi->font);
1503 tmi->height = tmi->lines * getFontHeight(tmi->font);
1505 // if x set to "-1", automatically determine by width and alignment
1507 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1509 // if y set to "-1", automatically determine by height and alignment
1511 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1513 SetDrawBackgroundMask(REDRAW_ALL);
1514 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1516 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1518 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1519 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1520 tmi->autowrap, tmi->centered, tmi->parse_comments);
1525 static void DrawTitleScreen(void)
1527 KeyboardAutoRepeatOff();
1529 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1532 static boolean CheckTitleScreen(boolean levelset_has_changed)
1534 static boolean show_title_initial = TRUE;
1535 boolean show_titlescreen = FALSE;
1537 // needed to be able to skip title screen, if no image or message defined
1538 InitializeTitleControls(show_title_initial);
1540 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1541 show_titlescreen = TRUE;
1543 // show initial title images and messages only once at program start
1544 show_title_initial = FALSE;
1546 return (show_titlescreen && num_title_screens > 0);
1549 void DrawMainMenu(void)
1551 static LevelDirTree *leveldir_last_valid = NULL;
1552 boolean levelset_has_changed = FALSE;
1553 int fade_mask = REDRAW_FIELD;
1555 LimitScreenUpdates(FALSE);
1557 FadeSetLeaveScreen();
1559 // do not fade out here -- function may continue and fade on editor screen
1562 FadeMenuSoundsAndMusic();
1564 ExpireSoundLoops(FALSE);
1566 KeyboardAutoRepeatOn();
1568 audio.sound_deactivated = FALSE;
1572 // needed if last screen was the playing screen, invoked from level editor
1573 if (level_editor_test_game)
1575 CloseDoor(DOOR_CLOSE_ALL);
1577 SetGameStatus(GAME_MODE_EDITOR);
1584 // leveldir_current may be invalid (level group, parent link)
1585 if (!validLevelSeries(leveldir_current))
1586 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1588 if (leveldir_current != leveldir_last_valid)
1589 levelset_has_changed = TRUE;
1591 // store valid level series information
1592 leveldir_last_valid = leveldir_current;
1594 init_last = init; // switch to new busy animation
1596 // needed if last screen (level choice) changed graphics, sounds or music
1597 ReloadCustomArtwork(0);
1599 if (CheckTitleScreen(levelset_has_changed))
1601 SetGameStatus(GAME_MODE_TITLE);
1608 if (redraw_mask & REDRAW_ALL)
1609 fade_mask = REDRAW_ALL;
1612 fade_mask = REDRAW_ALL;
1616 // needed if different viewport properties defined for menues
1617 ChangeViewportPropertiesIfNeeded();
1619 SetDrawtoField(DRAW_TO_BACKBUFFER);
1621 // level_nr may have been set to value over handicap with level editor
1622 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1623 level_nr = leveldir_current->handicap_level;
1625 LoadLevel(level_nr);
1626 LoadScore(level_nr);
1628 SaveLevelSetup_SeriesInfo();
1630 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1631 SetDrawDeactivationMask(REDRAW_NONE);
1632 SetDrawBackgroundMask(REDRAW_FIELD);
1634 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1637 if (fade_mask == REDRAW_ALL)
1638 RedrawGlobalBorder();
1643 InitializeMainControls();
1645 DrawCursorAndText_Main(-1, FALSE, FALSE);
1646 DrawPreviewLevelInitial();
1647 DrawNetworkPlayers();
1649 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1652 if (TAPE_IS_EMPTY(tape))
1654 DrawCompleteVideoDisplay();
1656 PlayMenuSoundsAndMusic();
1658 // create gadgets for main menu screen
1659 FreeScreenGadgets();
1660 CreateScreenGadgets();
1662 // may be required if audio buttons shown on tape and changed in setup menu
1664 CreateGameButtons();
1666 // map gadgets for main menu screen
1668 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1669 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1671 // copy actual game door content to door double buffer for OpenDoor()
1672 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1673 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1675 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1677 DrawMaskedBorder(fade_mask);
1682 // update screen area with special editor door
1683 redraw_mask |= REDRAW_ALL;
1686 SetMouseCursor(CURSOR_DEFAULT);
1688 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1691 static void gotoTopLevelDir(void)
1693 // move upwards until inside (but not above) top level directory
1694 while (leveldir_current->node_parent &&
1695 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1697 // write a "path" into level tree for easy navigation to last level
1698 if (leveldir_current->node_parent->node_group->cl_first == -1)
1700 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1701 int leveldir_pos = posTreeInfo(leveldir_current);
1702 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1703 int cl_first, cl_cursor;
1705 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1706 cl_cursor = leveldir_pos - cl_first;
1708 leveldir_current->node_parent->node_group->cl_first = cl_first;
1709 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1712 leveldir_current = leveldir_current->node_parent;
1716 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1718 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1720 return (use_frame_counter ? video.frame_counter : Counter());
1723 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1724 struct TitleFadingInfo *fi)
1726 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1729 static void ResetTitleAutoDelay(unsigned int *counter_var,
1730 struct TitleFadingInfo *fi)
1732 *counter_var = getAutoDelayCounter(fi);
1735 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1737 static unsigned int title_delay = 0;
1738 static int title_screen_nr = 0;
1739 static int last_sound = -1, last_music = -1;
1740 boolean return_to_main_menu = FALSE;
1741 struct TitleControlInfo *tci;
1744 if (button == MB_MENU_INITIALIZE)
1747 title_screen_nr = 0;
1748 tci = &title_controls[title_screen_nr];
1750 SetAnimStatus(getTitleAnimMode(tci));
1752 last_sound = SND_UNDEFINED;
1753 last_music = MUS_UNDEFINED;
1755 if (num_title_screens != 0)
1757 FadeSetEnterScreen();
1759 // use individual title fading instead of global "enter screen" fading
1760 fading = getTitleFading(tci);
1763 if (game_status_last_screen == GAME_MODE_INFO)
1765 if (num_title_screens == 0)
1767 // switch game mode from title screen mode back to info screen mode
1768 SetGameStatus(GAME_MODE_INFO);
1770 // store that last screen was info screen, not main menu screen
1771 game_status_last_screen = GAME_MODE_INFO;
1773 DrawInfoScreen_NotAvailable("Title screen information:",
1774 "No title screen for this level set.");
1779 FadeMenuSoundsAndMusic();
1781 FadeOut(REDRAW_ALL);
1783 // title screens may have different window size
1784 ChangeViewportPropertiesIfNeeded();
1786 // only required to update logic for redrawing global border
1790 DrawTitleScreenImage(tci->local_nr, tci->initial);
1792 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1794 sound = getTitleSound(tci);
1795 music = getTitleMusic(tci);
1797 if (sound != last_sound)
1798 PlayMenuSoundExt(sound);
1799 if (music != last_music)
1800 PlayMenuMusicExt(music);
1805 SetMouseCursor(CURSOR_NONE);
1809 ResetTitleAutoDelay(&title_delay, &fading);
1814 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1815 button = MB_MENU_CHOICE;
1817 if (button == MB_MENU_LEAVE)
1819 return_to_main_menu = TRUE;
1821 else if (button == MB_MENU_CHOICE)
1823 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1825 SetGameStatus(GAME_MODE_INFO);
1827 info_mode = INFO_MODE_MAIN;
1836 if (title_screen_nr < num_title_screens)
1838 tci = &title_controls[title_screen_nr];
1840 SetAnimStatus(getTitleAnimMode(tci));
1842 sound = getTitleSound(tci);
1843 music = getTitleMusic(tci);
1845 if (last_sound != SND_UNDEFINED && sound != last_sound)
1846 FadeSound(last_sound);
1847 if (last_music != MUS_UNDEFINED && music != last_music)
1850 fading = getTitleFading(tci);
1852 FadeOut(REDRAW_ALL);
1855 DrawTitleScreenImage(tci->local_nr, tci->initial);
1857 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1859 sound = getTitleSound(tci);
1860 music = getTitleMusic(tci);
1862 if (sound != last_sound)
1863 PlayMenuSoundExt(sound);
1864 if (music != last_music)
1865 PlayMenuMusicExt(music);
1872 ResetTitleAutoDelay(&title_delay, &fading);
1876 FadeMenuSoundsAndMusic();
1878 return_to_main_menu = TRUE;
1882 if (return_to_main_menu)
1884 SetMouseCursor(CURSOR_DEFAULT);
1886 // force full menu screen redraw after displaying title screens
1887 redraw_mask = REDRAW_ALL;
1889 if (game_status_last_screen == GAME_MODE_INFO)
1891 SetGameStatus(GAME_MODE_INFO);
1893 info_mode = INFO_MODE_MAIN;
1897 else // default: return to main menu
1899 SetGameStatus(GAME_MODE_MAIN);
1906 static void HandleMainMenu_SelectLevel(int step, int direction,
1907 int selected_level_nr)
1909 int old_level_nr = level_nr;
1912 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1913 new_level_nr = selected_level_nr;
1915 new_level_nr = old_level_nr + step * direction;
1917 if (new_level_nr < leveldir_current->first_level)
1918 new_level_nr = leveldir_current->first_level;
1919 if (new_level_nr > leveldir_current->last_level)
1920 new_level_nr = leveldir_current->last_level;
1922 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1924 // skipping levels is only allowed when trying to skip single level
1925 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1926 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1928 leveldir_current->handicap_level++;
1929 SaveLevelSetup_SeriesInfo();
1932 new_level_nr = leveldir_current->handicap_level;
1935 if (new_level_nr != old_level_nr)
1937 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1939 PlaySound(SND_MENU_ITEM_SELECTING);
1941 level_nr = new_level_nr;
1943 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1944 int2str(level_nr, menu.main.text.level_number.size),
1945 mci->pos_text->font);
1947 LoadLevel(level_nr);
1948 DrawPreviewLevelInitial();
1952 DrawCompleteVideoDisplay();
1954 SaveLevelSetup_SeriesInfo();
1956 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1958 // force redraw of playfield area (may be reset at this point)
1959 redraw_mask |= REDRAW_FIELD;
1963 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1965 static int choice = MAIN_CONTROL_GAME;
1966 static boolean button_pressed_last = FALSE;
1967 boolean button_pressed = FALSE;
1969 int i = 0; // needed to prevent compiler warning due to bad code below
1971 if (button == MB_MENU_INITIALIZE)
1973 DrawCursorAndText_Main(choice, TRUE, FALSE);
1978 if (mx || my) // mouse input
1982 for (i = 0; main_controls[i].nr != -1; i++)
1984 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1985 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1986 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1988 pos = main_controls[i].nr;
1994 // check if level preview was clicked
1995 if (insidePreviewRect(&preview, mx - SX, my - SY))
1996 pos = MAIN_CONTROL_GAME;
1998 // handle pressed/unpressed state for active/inactive menu buttons
1999 // (if pos != -1, "i" contains index position corresponding to "pos")
2001 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2002 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2003 button_pressed = TRUE;
2005 if (button_pressed != button_pressed_last)
2007 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2010 PlaySound(SND_MENU_BUTTON_PRESSING);
2012 PlaySound(SND_MENU_BUTTON_RELEASING);
2015 else if (dx || dy) // keyboard input
2017 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2018 choice == MAIN_CONTROL_SETUP))
2019 button = MB_MENU_CHOICE;
2024 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2026 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2028 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2030 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2032 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2034 CloseDoor(DOOR_CLOSE_2);
2036 SetGameStatus(GAME_MODE_LEVELNR);
2038 DrawChooseLevelNr();
2040 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2046 PlaySound(SND_MENU_ITEM_ACTIVATING);
2048 DrawCursorAndText_Main(choice, FALSE, FALSE);
2049 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2055 if (choice != MAIN_CONTROL_INFO &&
2056 choice != MAIN_CONTROL_SETUP)
2057 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2062 PlaySound(SND_MENU_ITEM_SELECTING);
2064 if (pos == MAIN_CONTROL_NAME)
2067 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2069 // special case: menu text "name/team" clicked -- toggle team mode
2070 setup.team_mode = !setup.team_mode;
2072 InitializeMainControls();
2073 DrawCursorAndText_Main(choice, TRUE, FALSE);
2075 DrawPreviewPlayers();
2079 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2081 HandleTypeName(strlen(setup.player_name), 0);
2084 else if (pos == MAIN_CONTROL_LEVELS)
2088 CloseDoor(DOOR_CLOSE_2);
2090 SetGameStatus(GAME_MODE_LEVELS);
2092 SaveLevelSetup_LastSeries();
2093 SaveLevelSetup_SeriesInfo();
2095 if (setup.internal.choose_from_top_leveldir)
2098 DrawChooseLevelSet();
2101 else if (pos == MAIN_CONTROL_SCORES)
2103 CloseDoor(DOOR_CLOSE_2);
2105 SetGameStatus(GAME_MODE_SCORES);
2107 DrawHallOfFame(level_nr, -1);
2109 else if (pos == MAIN_CONTROL_EDITOR)
2111 if (leveldir_current->readonly &&
2112 !strEqual(setup.player_name, "Artsoft"))
2113 Request("This level is read only!", REQ_CONFIRM);
2115 CloseDoor(DOOR_CLOSE_2);
2117 SetGameStatus(GAME_MODE_EDITOR);
2119 FadeSetEnterScreen();
2123 else if (pos == MAIN_CONTROL_INFO)
2125 CloseDoor(DOOR_CLOSE_2);
2127 SetGameStatus(GAME_MODE_INFO);
2129 info_mode = INFO_MODE_MAIN;
2133 else if (pos == MAIN_CONTROL_GAME)
2135 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2137 else if (pos == MAIN_CONTROL_SETUP)
2139 CloseDoor(DOOR_CLOSE_2);
2141 SetGameStatus(GAME_MODE_SETUP);
2143 setup_mode = SETUP_MODE_MAIN;
2147 else if (pos == MAIN_CONTROL_QUIT)
2149 SaveLevelSetup_LastSeries();
2150 SaveLevelSetup_SeriesInfo();
2152 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2153 SetGameStatus(GAME_MODE_QUIT);
2158 button_pressed_last = button_pressed;
2162 // ============================================================================
2163 // info screen functions
2164 // ============================================================================
2166 static struct TokenInfo *info_info;
2167 static int num_info_info; // number of info entries shown on screen
2168 static int max_info_info; // total number of info entries in list
2170 static void execInfoTitleScreen(void)
2172 info_mode = INFO_MODE_TITLE;
2177 static void execInfoElements(void)
2179 info_mode = INFO_MODE_ELEMENTS;
2184 static void execInfoMusic(void)
2186 info_mode = INFO_MODE_MUSIC;
2191 static void execInfoCredits(void)
2193 info_mode = INFO_MODE_CREDITS;
2198 static void execInfoProgram(void)
2200 info_mode = INFO_MODE_PROGRAM;
2205 static void execInfoVersion(void)
2207 info_mode = INFO_MODE_VERSION;
2212 static void execInfoLevelSet(void)
2214 info_mode = INFO_MODE_LEVELSET;
2219 static void execExitInfo(void)
2221 SetGameStatus(GAME_MODE_MAIN);
2226 static struct TokenInfo info_info_main[] =
2228 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2229 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2230 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2231 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2232 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2233 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2234 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2235 { TYPE_EMPTY, NULL, "" },
2236 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2241 static int getMenuTextFont(int type)
2243 if (type & (TYPE_SWITCH |
2257 static struct TokenInfo *setup_info;
2258 static struct TokenInfo setup_info_input[];
2260 static struct TokenInfo *menu_info;
2262 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2263 int screen_pos, int menu_info_pos_raw,
2266 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2267 struct TokenInfo *ti = &token_info[pos];
2268 int xpos = MENU_SCREEN_START_XPOS;
2269 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2270 int font_nr = getMenuTextFont(ti->type);
2272 if (setup_mode == SETUP_MODE_INPUT)
2273 font_nr = FONT_MENU_1;
2276 font_nr = FONT_ACTIVE(font_nr);
2278 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2280 if (ti->type & ~TYPE_SKIP_ENTRY)
2281 drawCursor(screen_pos, active);
2284 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2287 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2290 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2293 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2296 static char *window_size_text;
2297 static char *scaling_type_text;
2298 static char *network_server_text;
2300 static void drawSetupValue(int, int);
2302 static void drawMenuInfoList(int first_entry, int num_page_entries,
2303 int max_page_entries)
2307 if (first_entry + num_page_entries > max_page_entries)
2310 clearMenuListArea();
2312 for (i = 0; i < num_page_entries; i++)
2314 int menu_info_pos = first_entry + i;
2315 struct TokenInfo *si = &menu_info[menu_info_pos];
2316 void *value_ptr = si->value;
2318 // set some entries to "unchangeable" according to other variables
2319 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2320 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2321 (value_ptr == &setup.sound_music && !audio.music_available) ||
2322 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2323 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2324 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2325 si->type |= TYPE_GHOSTED;
2327 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2328 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2329 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2330 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2331 else if (si->type & ~TYPE_SKIP_ENTRY)
2332 initCursor(i, IMG_MENU_BUTTON);
2334 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2336 if (si->type & TYPE_STRING)
2340 if (value_ptr == &network_server_text)
2341 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2343 if (gadget_id != -1)
2345 struct GadgetInfo *gi = screen_gadget[gadget_id];
2346 int xpos = MENU_SCREEN_START_XPOS;
2347 int ypos = MENU_SCREEN_START_YPOS + i;
2348 int x = mSX + xpos * 32;
2349 int y = mSY + ypos * 32;
2351 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2355 if (si->type & TYPE_VALUE &&
2356 menu_info == setup_info)
2357 drawSetupValue(i, menu_info_pos);
2361 static void DrawInfoScreen_Main(void)
2363 int fade_mask = REDRAW_FIELD;
2366 if (redraw_mask & REDRAW_ALL)
2367 fade_mask = REDRAW_ALL;
2370 fade_mask = REDRAW_ALL;
2373 FadeMenuSoundsAndMusic();
2375 FreeScreenGadgets();
2376 CreateScreenGadgets();
2378 // (needed after displaying title screens which disable auto repeat)
2379 KeyboardAutoRepeatOn();
2381 FadeSetLeaveScreen();
2385 // needed if different viewport properties defined for info screen
2386 ChangeViewportPropertiesIfNeeded();
2388 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2392 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2394 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2396 info_info = info_info_main;
2398 // determine maximal number of info entries that can be displayed on screen
2400 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2403 // determine maximal number of info entries available for menu of info screen
2405 for (i = 0; info_info[i].type != 0; i++)
2408 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2410 MapScreenGadgets(max_info_info);
2412 PlayMenuSoundsAndMusic();
2414 DrawMaskedBorder(fade_mask);
2419 static void changeSetupValue(int, int, int);
2421 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2422 int mode, int num_page_entries,
2423 int max_page_entries)
2425 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2426 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2427 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2428 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2429 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2430 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2431 int *num_page_entries_last = num_page_entries_all_last[game_status];
2432 int *choice_store = choice_stores[game_status];
2433 int *first_entry_store = first_entry_stores[game_status];
2434 int choice = choice_store[mode]; // starts with 0
2435 int first_entry = first_entry_store[mode]; // starts with 0
2437 int y = choice - first_entry;
2439 boolean position_set_by_scrollbar = (dx == 999);
2440 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2443 if (button == MB_MENU_INITIALIZE)
2445 // check if number of menu page entries has changed (may happen by change
2446 // of custom artwork definition value for 'list_size' for this menu screen)
2447 // (in this case, the last menu position most probably has to be corrected)
2448 if (num_page_entries != num_page_entries_last[mode])
2450 choice_store[mode] = first_entry_store[mode] = 0;
2452 choice = first_entry = 0;
2455 num_page_entries_last[mode] = num_page_entries;
2458 // advance to first valid menu entry
2459 while (choice < num_page_entries &&
2460 menu_info[choice].type & TYPE_SKIP_ENTRY)
2463 if (position_set_by_scrollbar)
2464 first_entry = first_entry_store[mode] = dy;
2466 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2467 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2469 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2471 if (choice < first_entry)
2473 choice = first_entry;
2475 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2478 else if (choice > first_entry + num_page_entries - 1)
2480 choice = first_entry + num_page_entries - 1;
2482 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2486 choice_store[mode] = choice;
2488 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2492 else if (button == MB_MENU_LEAVE)
2494 PlaySound(SND_MENU_ITEM_SELECTING);
2496 for (i = 0; i < max_page_entries; i++)
2498 if (menu_info[i].type & TYPE_LEAVE_MENU)
2500 void (*menu_callback_function)(void) = menu_info[i].value;
2504 menu_callback_function();
2506 break; // absolutely needed because function changes 'menu_info'!
2513 if (mx || my) // mouse input
2515 x = (mx - mSX) / 32;
2516 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2518 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2520 // move cursor instead of scrolling when already at start/end of list
2521 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2523 else if (dy == +1 * SCROLL_LINE &&
2524 first_entry + num_page_entries == max_page_entries)
2527 // handle scrolling screen one line or page
2529 y + dy > num_page_entries - 1)
2531 boolean redraw = FALSE;
2533 if (ABS(dy) == SCROLL_PAGE)
2534 step = num_page_entries - 1;
2536 if (dy < 0 && first_entry > 0)
2538 // scroll page/line up
2540 first_entry -= step;
2541 if (first_entry < 0)
2546 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2548 // scroll page/line down
2550 first_entry += step;
2551 if (first_entry + num_page_entries > max_page_entries)
2552 first_entry = MAX(0, max_page_entries - num_page_entries);
2559 choice += first_entry - first_entry_store[mode];
2561 if (choice < first_entry)
2563 choice = first_entry;
2565 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2568 else if (choice > first_entry + num_page_entries - 1)
2570 choice = first_entry + num_page_entries - 1;
2572 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2575 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2579 if (choice < first_entry ||
2580 choice > first_entry + num_page_entries - 1)
2581 first_entry += SIGN(dy);
2584 first_entry_store[mode] = first_entry;
2585 choice_store[mode] = choice;
2587 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2589 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2591 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2592 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2600 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2602 if (menu_info[choice].type & menu_navigation_type ||
2603 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2604 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2605 menu_info[choice].type & TYPE_PLAYER)
2606 button = MB_MENU_CHOICE;
2611 // jump to next non-empty menu entry (up or down)
2612 while (first_entry + y > 0 &&
2613 first_entry + y < max_page_entries - 1 &&
2614 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2617 if (!IN_VIS_MENU(x, y))
2619 choice += y - y_old;
2621 if (choice < first_entry)
2622 first_entry = choice;
2623 else if (choice > first_entry + num_page_entries - 1)
2624 first_entry = choice - num_page_entries + 1;
2626 if (first_entry >= 0 &&
2627 first_entry + num_page_entries <= max_page_entries)
2629 first_entry_store[mode] = first_entry;
2631 if (choice < first_entry)
2632 choice = first_entry;
2633 else if (choice > first_entry + num_page_entries - 1)
2634 choice = first_entry + num_page_entries - 1;
2636 choice_store[mode] = choice;
2638 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2640 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2642 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2643 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2650 if (!anyScrollbarGadgetActive() &&
2651 IN_VIS_MENU(x, y) &&
2652 mx < mx_right_border &&
2653 y >= 0 && y < num_page_entries)
2657 if (first_entry + y != choice &&
2658 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2660 PlaySound(SND_MENU_ITEM_ACTIVATING);
2662 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2663 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2665 choice = choice_store[mode] = first_entry + y;
2669 PlaySound(SND_MENU_ITEM_SELECTING);
2671 for (i = 0; menu_info[i].type != 0; i++)
2673 if (menu_info[i].type & TYPE_LEAVE_MENU)
2675 void (*menu_callback_function)(void) = menu_info[i].value;
2679 menu_callback_function();
2681 // absolutely needed because function changes 'menu_info'!
2689 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2691 PlaySound(SND_MENU_ITEM_SELECTING);
2693 // when selecting key headline, execute function for key value change
2694 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2695 menu_info[first_entry + y + 1].type & TYPE_KEY)
2698 // when selecting string value, execute function for list selection
2699 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2700 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2703 // when selecting string value, execute function for text input gadget
2704 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2705 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2708 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2710 void (*menu_callback_function)(void) =
2711 menu_info[first_entry + y].value;
2713 FadeSetFromType(menu_info[first_entry + y].type);
2715 menu_callback_function();
2717 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2719 void (*gadget_callback_function)(void) =
2720 menu_info[first_entry + y].value;
2722 gadget_callback_function();
2724 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2725 menu_info == setup_info)
2727 changeSetupValue(y, first_entry + y, dx);
2733 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2735 menu_info = info_info;
2737 HandleMenuScreen(mx, my, dx, dy, button,
2738 info_mode, num_info_info, max_info_info);
2741 static int getMenuFontSpacing(int spacing_height, int font_nr)
2743 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2745 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2749 static int getMenuTextSpacing(int spacing_height, int font_nr)
2751 return (getMenuFontSpacing(spacing_height, font_nr) +
2752 EXTRA_SPACING(game_status));
2755 static int getMenuTextStep(int spacing_height, int font_nr)
2757 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2760 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2762 int font_title = MENU_INFO_FONT_TITLE;
2763 int font_error = FONT_TEXT_2;
2764 int font_foot = MENU_INFO_FONT_FOOT;
2765 int spacing_title = menu.headline1_spacing_info[info_mode];
2766 int ystep_title = getMenuTextStep(spacing_title, font_title);
2767 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2768 int ystart2 = ystart1 + ystep_title;
2769 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2771 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2773 FadeOut(REDRAW_FIELD);
2778 DrawTextSCentered(ystart1, font_title, text_title);
2779 DrawTextSCentered(ystart2, font_error, text_error);
2781 DrawTextSCentered(ybottom, font_foot,
2782 "Press any key or button for info menu");
2784 FadeIn(REDRAW_FIELD);
2787 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2789 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2790 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2791 int font_title = MENU_INFO_FONT_TITLE;
2792 int font_foot = MENU_INFO_FONT_FOOT;
2793 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2794 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2795 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2796 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2797 int ystep = MENU_SCREEN_INFO_YSTEP;
2798 int element, action, direction;
2806 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2807 infoscreen_step[i] = infoscreen_frame[i] = 0;
2812 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2814 DrawTextSCentered(ybottom, font_foot,
2815 "Press any key or button for next page");
2821 while (helpanim_info[j].element != HELPANIM_LIST_END)
2823 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2828 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2837 j += infoscreen_step[i - start];
2839 element = helpanim_info[j].element;
2840 action = helpanim_info[j].action;
2841 direction = helpanim_info[j].direction;
2844 element = EL_UNKNOWN;
2846 if (action != -1 && direction != -1)
2847 graphic = el_act_dir2img(element, action, direction);
2848 else if (action != -1)
2849 graphic = el_act2img(element, action);
2850 else if (direction != -1)
2851 graphic = el_dir2img(element, direction);
2853 graphic = el2img(element);
2855 delay = helpanim_info[j++].delay;
2860 if (infoscreen_frame[i - start] == 0)
2863 infoscreen_frame[i - start] = delay - 1;
2867 sync_frame = delay - infoscreen_frame[i - start];
2868 infoscreen_frame[i - start]--;
2871 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2873 if (!infoscreen_frame[i - start])
2874 infoscreen_step[i - start] = 0;
2878 if (!infoscreen_frame[i - start])
2879 infoscreen_step[i - start]++;
2880 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2886 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2888 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2889 graphic, sync_frame, USE_MASKING);
2892 DrawInfoScreen_HelpText(element, action, direction, i - start);
2897 redraw_mask |= REDRAW_FIELD;
2902 static char *getHelpText(int element, int action, int direction)
2904 char token[MAX_LINE_LEN];
2906 strcpy(token, element_info[element].token_name);
2909 strcat(token, element_action_info[action].suffix);
2911 if (direction != -1)
2912 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2914 return getHashEntry(helptext_info, token);
2917 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2919 int font_nr = FONT_INFO_ELEMENTS;
2920 int font_width = getFontWidth(font_nr);
2921 int font_height = getFontHeight(font_nr);
2922 int yoffset = (TILEX - 2 * font_height) / 2;
2923 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2924 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2925 int ystep = TILEY + 4;
2926 int pad_left = xstart - SX;
2927 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2928 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2929 int max_lines_per_text = 2;
2932 if (action != -1 && direction != -1) // element.action.direction
2933 text = getHelpText(element, action, direction);
2935 if (text == NULL && action != -1) // element.action
2936 text = getHelpText(element, action, -1);
2938 if (text == NULL && direction != -1) // element.direction
2939 text = getHelpText(element, -1, direction);
2941 if (text == NULL) // base element
2942 text = getHelpText(element, -1, -1);
2944 if (text == NULL) // not found
2945 text = "No description available";
2947 if (strlen(text) <= max_chars_per_line) // only one line of text
2948 ystart += getFontHeight(font_nr) / 2;
2950 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2951 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2952 TRUE, FALSE, FALSE);
2955 static void DrawInfoScreen_TitleScreen(void)
2957 SetGameStatus(GAME_MODE_TITLE);
2962 void HandleInfoScreen_TitleScreen(int button)
2964 HandleTitleScreen(0, 0, 0, 0, button);
2967 static void DrawInfoScreen_Elements(void)
2969 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2971 FadeOut(REDRAW_FIELD);
2976 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2978 FadeIn(REDRAW_FIELD);
2981 void HandleInfoScreen_Elements(int button)
2983 static unsigned int info_delay = 0;
2984 static int num_anims;
2985 static int num_pages;
2987 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2990 if (button == MB_MENU_INITIALIZE)
2992 boolean new_element = TRUE;
2996 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
2998 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3000 else if (new_element)
3003 new_element = FALSE;
3007 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3011 if (button == MB_MENU_LEAVE)
3013 PlaySound(SND_MENU_ITEM_SELECTING);
3015 info_mode = INFO_MODE_MAIN;
3020 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3022 if (button != MB_MENU_INITIALIZE)
3024 PlaySound(SND_MENU_ITEM_SELECTING);
3029 if (page >= num_pages)
3031 FadeMenuSoundsAndMusic();
3033 info_mode = INFO_MODE_MAIN;
3040 FadeSetNextScreen();
3042 if (button != MB_MENU_INITIALIZE)
3043 FadeOut(REDRAW_FIELD);
3045 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3047 if (button != MB_MENU_INITIALIZE)
3048 FadeIn(REDRAW_FIELD);
3052 if (DelayReached(&info_delay, GameFrameDelay))
3053 if (page < num_pages)
3054 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3056 PlayMenuSoundIfLoop();
3060 static void DrawInfoScreen_Music(void)
3062 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3064 FadeOut(REDRAW_FIELD);
3071 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3073 FadeIn(REDRAW_FIELD);
3076 void HandleInfoScreen_Music(int button)
3078 static struct MusicFileInfo *list = NULL;
3079 int font_title = MENU_INFO_FONT_TITLE;
3080 int font_head = MENU_INFO_FONT_HEAD;
3081 int font_text = MENU_INFO_FONT_TEXT;
3082 int font_foot = MENU_INFO_FONT_FOOT;
3083 int spacing_title = menu.headline1_spacing_info[info_mode];
3084 int spacing_head = menu.headline2_spacing_info[info_mode];
3085 int ystep_title = getMenuTextStep(spacing_title, font_title);
3086 int ystep_head = getMenuTextStep(spacing_head, font_head);
3087 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3088 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3090 if (button == MB_MENU_INITIALIZE)
3092 list = music_file_info;
3096 FadeMenuSoundsAndMusic();
3101 DrawTextSCentered(ystart, font_title,
3102 "No music info for this level set.");
3104 DrawTextSCentered(ybottom, font_foot,
3105 "Press any key or button for info menu");
3111 if (button == MB_MENU_LEAVE)
3113 PlaySound(SND_MENU_ITEM_SELECTING);
3115 FadeMenuSoundsAndMusic();
3117 info_mode = INFO_MODE_MAIN;
3122 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3124 if (button != MB_MENU_INITIALIZE)
3126 PlaySound(SND_MENU_ITEM_SELECTING);
3134 FadeMenuSoundsAndMusic();
3136 info_mode = INFO_MODE_MAIN;
3142 FadeMenuSoundsAndMusic();
3144 if (list != music_file_info)
3145 FadeSetNextScreen();
3147 if (button != MB_MENU_INITIALIZE)
3148 FadeOut(REDRAW_FIELD);
3155 int sound = list->music;
3157 if (sound_info[sound].loop)
3158 PlaySoundLoop(sound);
3162 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3166 int music = list->music;
3168 if (music_info[music].loop)
3169 PlayMusicLoop(music);
3173 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3176 ystart += ystep_title;
3178 if (!strEqual(list->title, UNKNOWN_NAME))
3180 if (!strEqual(list->title_header, UNKNOWN_NAME))
3182 DrawTextSCentered(ystart, font_head, list->title_header);
3183 ystart += ystep_head;
3186 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3187 ystart += ystep_head;
3190 if (!strEqual(list->artist, UNKNOWN_NAME))
3192 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3193 DrawTextSCentered(ystart, font_head, list->artist_header);
3195 DrawTextSCentered(ystart, font_head, "by");
3197 ystart += ystep_head;
3199 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3200 ystart += ystep_head;
3203 if (!strEqual(list->album, UNKNOWN_NAME))
3205 if (!strEqual(list->album_header, UNKNOWN_NAME))
3206 DrawTextSCentered(ystart, font_head, list->album_header);
3208 DrawTextSCentered(ystart, font_head, "from the album");
3210 ystart += ystep_head;
3212 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3213 ystart += ystep_head;
3216 if (!strEqual(list->year, UNKNOWN_NAME))
3218 if (!strEqual(list->year_header, UNKNOWN_NAME))
3219 DrawTextSCentered(ystart, font_head, list->year_header);
3221 DrawTextSCentered(ystart, font_head, "from the year");
3223 ystart += ystep_head;
3225 DrawTextFCentered(ystart, font_text, "%s", list->year);
3226 ystart += ystep_head;
3229 DrawTextSCentered(ybottom, FONT_TEXT_4,
3230 "Press any key or button for next page");
3232 if (button != MB_MENU_INITIALIZE)
3233 FadeIn(REDRAW_FIELD);
3236 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3237 PlaySoundLoop(list->music);
3240 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3242 int font_title = MENU_INFO_FONT_TITLE;
3243 int font_head = MENU_INFO_FONT_HEAD;
3244 int font_text = MENU_INFO_FONT_TEXT;
3245 int font_foot = MENU_INFO_FONT_FOOT;
3246 int spacing_title = menu.headline1_spacing_info[info_mode];
3247 int spacing_head = menu.headline2_spacing_info[info_mode];
3248 int spacing_para = menu.paragraph_spacing_info[info_mode];
3249 int spacing_line = menu.line_spacing_info[info_mode];
3250 int ystep_title = getMenuTextStep(spacing_title, font_title);
3251 int ystep_head = getMenuTextStep(spacing_head, font_head);
3252 int ystep_para = getMenuTextStep(spacing_para, font_text);
3253 int ystep_line = getMenuTextStep(spacing_line, font_text);
3254 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3255 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3260 DrawTextSCentered(ystart, font_title, "Credits:");
3261 ystart += ystep_title;
3265 DrawTextSCentered(ystart, font_head,
3266 "Special thanks to");
3267 ystart += ystep_head;
3268 DrawTextSCentered(ystart, font_text,
3270 ystart += ystep_head;
3271 DrawTextSCentered(ystart, font_head,
3273 ystart += ystep_head;
3274 DrawTextSCentered(ystart, font_text,
3275 "\"Boulder Dash\"");
3276 ystart += ystep_head;
3277 DrawTextSCentered(ystart, font_head,
3279 ystart += ystep_head;
3280 DrawTextSCentered(ystart, font_text,
3282 ystart += ystep_head;
3283 DrawTextSCentered(ystart, font_head,
3285 ystart += ystep_head;
3286 DrawTextSCentered(ystart, font_text,
3287 "First Star Software");
3289 else if (screen_nr == 1)
3291 DrawTextSCentered(ystart, font_head,
3292 "Special thanks to");
3293 ystart += ystep_head;
3294 DrawTextSCentered(ystart, font_text,
3295 "Klaus Heinz & Volker Wertich");
3296 ystart += ystep_head;
3297 DrawTextSCentered(ystart, font_head,
3299 ystart += ystep_head;
3300 DrawTextSCentered(ystart, font_text,
3301 "\"Emerald Mine\"");
3302 ystart += ystep_head;
3303 DrawTextSCentered(ystart, font_head,
3305 ystart += ystep_head;
3306 DrawTextSCentered(ystart, font_text,
3308 ystart += ystep_head;
3309 DrawTextSCentered(ystart, font_head,
3311 ystart += ystep_head;
3312 DrawTextSCentered(ystart, font_text,
3315 else if (screen_nr == 2)
3317 DrawTextSCentered(ystart, font_head,
3318 "Special thanks to");
3319 ystart += ystep_head;
3320 DrawTextSCentered(ystart, font_text,
3321 "Michael Stopp & Philip Jespersen");
3322 ystart += ystep_head;
3323 DrawTextSCentered(ystart, font_head,
3325 ystart += ystep_head;
3326 DrawTextSCentered(ystart, font_text,
3328 ystart += ystep_head;
3329 DrawTextSCentered(ystart, font_head,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_text,
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_head,
3337 ystart += ystep_head;
3338 DrawTextSCentered(ystart, font_text,
3339 "Digital Integration");
3341 else if (screen_nr == 3)
3343 DrawTextSCentered(ystart, font_head,
3344 "Special thanks to");
3345 ystart += ystep_head;
3346 DrawTextSCentered(ystart, font_text,
3347 "Hiroyuki Imabayashi");
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_head,
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_text,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_head,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_text,
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_head,
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_text,
3367 else if (screen_nr == 4)
3369 DrawTextSCentered(ystart, font_head,
3370 "Special thanks to");
3371 ystart += ystep_head;
3372 DrawTextSCentered(ystart, font_text,
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_head,
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_text,
3379 "J\xfcrgen Bonhagen");
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_head,
3382 "for the continuous creation");
3383 ystart += ystep_line;
3384 DrawTextSCentered(ystart, font_head,
3385 "of outstanding level sets");
3387 else if (screen_nr == 5)
3389 DrawTextSCentered(ystart, font_head,
3391 ystart += ystep_head;
3392 DrawTextSCentered(ystart, font_text,
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_head,
3396 "for ideas and inspiration by");
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_text,
3400 ystart += ystep_para;
3402 DrawTextSCentered(ystart, font_head,
3404 ystart += ystep_head;
3405 DrawTextSCentered(ystart, font_text,
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_head,
3409 "for ideas and inspiration by");
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_text,
3414 else if (screen_nr == 6)
3416 DrawTextSCentered(ystart, font_head,
3418 ystart += ystep_head;
3419 DrawTextSCentered(ystart, font_text,
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_head,
3423 "for the code base used for the");
3424 ystart += ystep_line;
3425 DrawTextSCentered(ystart, font_head,
3426 "native Emerald Mine engine");
3428 else if (screen_nr == 7)
3430 DrawTextSCentered(ystart, font_head,
3432 ystart += ystep_head;
3433 DrawTextSCentered(ystart, font_text,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_head,
3437 "for the initial DOS port");
3438 ystart += ystep_para;
3440 DrawTextSCentered(ystart, font_head,
3442 ystart += ystep_head;
3443 DrawTextSCentered(ystart, font_text,
3445 ystart += ystep_head;
3446 DrawTextSCentered(ystart, font_head,
3447 "for some additional toons");
3449 else if (screen_nr == 8)
3451 DrawTextSCentered(ystart, font_head,
3452 "And not to forget:");
3453 ystart += ystep_head;
3454 DrawTextSCentered(ystart, font_head,
3456 ystart += ystep_head;
3457 DrawTextSCentered(ystart, font_text,
3458 "All those who contributed");
3459 ystart += ystep_line;
3460 DrawTextSCentered(ystart, font_text,
3461 "levels to this game");
3462 ystart += ystep_line;
3463 DrawTextSCentered(ystart, font_text,
3467 DrawTextSCentered(ybottom, font_foot,
3468 "Press any key or button for next page");
3471 static void DrawInfoScreen_Credits(void)
3473 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3475 FadeMenuSoundsAndMusic();
3477 FadeOut(REDRAW_FIELD);
3479 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3481 FadeIn(REDRAW_FIELD);
3484 void HandleInfoScreen_Credits(int button)
3486 static int screen_nr = 0;
3487 int num_screens = 9;
3489 if (button == MB_MENU_INITIALIZE)
3493 // DrawInfoScreen_CreditsScreen(screen_nr);
3496 if (button == MB_MENU_LEAVE)
3498 PlaySound(SND_MENU_ITEM_SELECTING);
3500 info_mode = INFO_MODE_MAIN;
3505 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3507 if (button != MB_MENU_INITIALIZE)
3509 PlaySound(SND_MENU_ITEM_SELECTING);
3514 if (screen_nr >= num_screens)
3516 FadeMenuSoundsAndMusic();
3518 info_mode = INFO_MODE_MAIN;
3525 FadeSetNextScreen();
3527 if (button != MB_MENU_INITIALIZE)
3528 FadeOut(REDRAW_FIELD);
3530 DrawInfoScreen_CreditsScreen(screen_nr);
3532 if (button != MB_MENU_INITIALIZE)
3533 FadeIn(REDRAW_FIELD);
3537 PlayMenuSoundIfLoop();
3541 static void DrawInfoScreen_Program(void)
3543 int font_title = MENU_INFO_FONT_TITLE;
3544 int font_head = MENU_INFO_FONT_HEAD;
3545 int font_text = MENU_INFO_FONT_TEXT;
3546 int font_foot = MENU_INFO_FONT_FOOT;
3547 int spacing_title = menu.headline1_spacing_info[info_mode];
3548 int spacing_head = menu.headline2_spacing_info[info_mode];
3549 int spacing_para = menu.paragraph_spacing_info[info_mode];
3550 int spacing_line = menu.line_spacing_info[info_mode];
3551 int ystep_title = getMenuTextStep(spacing_title, font_title);
3552 int ystep_head = getMenuTextStep(spacing_head, font_head);
3553 int ystep_para = getMenuTextStep(spacing_para, font_text);
3554 int ystep_line = getMenuTextStep(spacing_line, font_text);
3555 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3556 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3558 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3560 FadeOut(REDRAW_FIELD);
3565 DrawTextSCentered(ystart, font_title, "Program Information:");
3566 ystart += ystep_title;
3568 DrawTextSCentered(ystart, font_head,
3569 "This game is Freeware!");
3570 ystart += ystep_head;
3571 DrawTextSCentered(ystart, font_head,
3572 "If you like it, send e-mail to:");
3573 ystart += ystep_head;
3574 DrawTextSCentered(ystart, font_text,
3575 setup.internal.program_email);
3576 ystart += ystep_para;
3578 DrawTextSCentered(ystart, font_head,
3579 "More information and levels:");
3580 ystart += ystep_head;
3581 DrawTextSCentered(ystart, font_text,
3582 setup.internal.program_website);
3583 ystart += ystep_para;
3585 DrawTextSCentered(ystart, font_head,
3586 "If you have created new levels,");
3587 ystart += ystep_line;
3588 DrawTextSCentered(ystart, font_head,
3589 "send them to me to include them!");
3590 ystart += ystep_head;
3591 DrawTextSCentered(ystart, font_head,
3594 DrawTextSCentered(ybottom, font_foot,
3595 "Press any key or button for info menu");
3597 FadeIn(REDRAW_FIELD);
3600 void HandleInfoScreen_Program(int button)
3602 if (button == MB_MENU_LEAVE)
3604 PlaySound(SND_MENU_ITEM_SELECTING);
3606 info_mode = INFO_MODE_MAIN;
3611 else if (button == MB_MENU_CHOICE)
3613 PlaySound(SND_MENU_ITEM_SELECTING);
3615 FadeMenuSoundsAndMusic();
3617 info_mode = INFO_MODE_MAIN;
3622 PlayMenuSoundIfLoop();
3626 static void DrawInfoScreen_Version(void)
3628 int font_title = MENU_INFO_FONT_TITLE;
3629 int font_head = MENU_INFO_FONT_HEAD;
3630 int font_text = MENU_INFO_FONT_TEXT;
3631 int font_foot = MENU_INFO_FONT_FOOT;
3632 int spacing_title = menu.headline1_spacing_info[info_mode];
3633 int spacing_head = menu.headline2_spacing_info[info_mode];
3634 int spacing_para = menu.paragraph_spacing_info[info_mode];
3635 int spacing_line = menu.line_spacing_info[info_mode];
3636 int xstep = getFontWidth(font_text);
3637 int ystep_title = getMenuTextStep(spacing_title, font_title);
3638 int ystep_head = getMenuTextStep(spacing_head, font_head);
3639 int ystep_para = getMenuTextStep(spacing_para, font_text);
3640 int ystep_line = getMenuTextStep(spacing_line, font_text);
3641 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3642 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3643 int xstart1 = mSX - SX + 2 * xstep;
3644 int xstart2 = mSX - SX + 18 * xstep;
3645 int xstart3 = mSX - SX + 28 * xstep;
3646 SDL_version sdl_version_compiled;
3647 const SDL_version *sdl_version_linked;
3648 int driver_name_len = 10;
3649 SDL_version sdl_version_linked_ext;
3650 const char *driver_name = NULL;
3652 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3654 FadeOut(REDRAW_FIELD);
3659 DrawTextSCentered(ystart, font_title, "Version Information:");
3660 ystart += ystep_title;
3662 DrawTextF(xstart1, ystart, font_head, "Name");
3663 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3664 ystart += ystep_line;
3666 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3668 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3669 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3670 ystart += ystep_line;
3672 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3673 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3674 ystart += ystep_line;
3678 DrawTextF(xstart1, ystart, font_head, "Version");
3679 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3680 ystart += ystep_line;
3683 DrawTextF(xstart1, ystart, font_head, "Platform");
3684 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3686 PLATFORM_XX_BIT_STRING);
3687 ystart += ystep_line;
3689 DrawTextF(xstart1, ystart, font_head, "Target");
3690 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3691 ystart += ystep_line;
3693 DrawTextF(xstart1, ystart, font_head, "Source date");
3694 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3695 ystart += ystep_para;
3697 DrawTextF(xstart1, ystart, font_head, "Library");
3698 DrawTextF(xstart2, ystart, font_head, "compiled");
3699 DrawTextF(xstart3, ystart, font_head, "linked");
3700 ystart += ystep_head;
3702 SDL_VERSION(&sdl_version_compiled);
3703 SDL_GetVersion(&sdl_version_linked_ext);
3704 sdl_version_linked = &sdl_version_linked_ext;
3706 DrawTextF(xstart1, ystart, font_text, "SDL");
3707 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3708 sdl_version_compiled.major,
3709 sdl_version_compiled.minor,
3710 sdl_version_compiled.patch);
3711 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3712 sdl_version_linked->major,
3713 sdl_version_linked->minor,
3714 sdl_version_linked->patch);
3715 ystart += ystep_line;
3717 SDL_IMAGE_VERSION(&sdl_version_compiled);
3718 sdl_version_linked = IMG_Linked_Version();
3720 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3721 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3722 sdl_version_compiled.major,
3723 sdl_version_compiled.minor,
3724 sdl_version_compiled.patch);
3725 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3726 sdl_version_linked->major,
3727 sdl_version_linked->minor,
3728 sdl_version_linked->patch);
3729 ystart += ystep_line;
3731 SDL_MIXER_VERSION(&sdl_version_compiled);
3732 sdl_version_linked = Mix_Linked_Version();
3734 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3735 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3736 sdl_version_compiled.major,
3737 sdl_version_compiled.minor,
3738 sdl_version_compiled.patch);
3739 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3740 sdl_version_linked->major,
3741 sdl_version_linked->minor,
3742 sdl_version_linked->patch);
3743 ystart += ystep_line;
3745 SDL_NET_VERSION(&sdl_version_compiled);
3746 sdl_version_linked = SDLNet_Linked_Version();
3748 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3749 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3750 sdl_version_compiled.major,
3751 sdl_version_compiled.minor,
3752 sdl_version_compiled.patch);
3753 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3754 sdl_version_linked->major,
3755 sdl_version_linked->minor,
3756 sdl_version_linked->patch);
3757 ystart += ystep_para;
3759 DrawTextF(xstart1, ystart, font_head, "Driver");
3760 DrawTextF(xstart2, ystart, font_head, "Requested");
3761 DrawTextF(xstart3, ystart, font_head, "Used");
3762 ystart += ystep_head;
3765 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3767 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3768 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3769 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3770 ystart += ystep_line;
3773 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3775 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3776 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3777 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3778 ystart += ystep_line;
3781 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3783 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3784 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3785 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3787 DrawTextSCentered(ybottom, font_foot,
3788 "Press any key or button for info menu");
3790 FadeIn(REDRAW_FIELD);
3793 void HandleInfoScreen_Version(int button)
3795 if (button == MB_MENU_LEAVE)
3797 PlaySound(SND_MENU_ITEM_SELECTING);
3799 info_mode = INFO_MODE_MAIN;
3804 else if (button == MB_MENU_CHOICE)
3806 PlaySound(SND_MENU_ITEM_SELECTING);
3808 FadeMenuSoundsAndMusic();
3810 info_mode = INFO_MODE_MAIN;
3815 PlayMenuSoundIfLoop();
3819 static void DrawInfoScreen_LevelSet(void)
3821 struct TitleMessageInfo *tmi = &readme;
3822 char *filename = getLevelSetInfoFilename();
3823 char *title = "Level Set Information:";
3824 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3825 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3827 if (filename == NULL)
3829 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3834 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3836 FadeOut(REDRAW_FIELD);
3841 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3843 // if x position set to "-1", automatically determine by playfield width
3845 tmi->x = SXSIZE / 2;
3847 // if y position set to "-1", use static default value
3851 // if width set to "-1", automatically determine by playfield width
3852 if (tmi->width == -1)
3853 tmi->width = SXSIZE - 2 * TILEX;
3855 // if height set to "-1", automatically determine by playfield height
3856 if (tmi->height == -1)
3857 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3859 // if chars set to "-1", automatically determine by text and font width
3860 if (tmi->chars == -1)
3861 tmi->chars = tmi->width / getFontWidth(tmi->font);
3863 tmi->width = tmi->chars * getFontWidth(tmi->font);
3865 // if lines set to "-1", automatically determine by text and font height
3866 if (tmi->lines == -1)
3867 tmi->lines = tmi->height / getFontHeight(tmi->font);
3869 tmi->height = tmi->lines * getFontHeight(tmi->font);
3871 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3872 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3873 tmi->autowrap, tmi->centered, tmi->parse_comments);
3875 DrawTextSCentered(ybottom, FONT_TEXT_4,
3876 "Press any key or button for info menu");
3878 FadeIn(REDRAW_FIELD);
3881 static void HandleInfoScreen_LevelSet(int button)
3883 if (button == MB_MENU_LEAVE)
3885 PlaySound(SND_MENU_ITEM_SELECTING);
3887 info_mode = INFO_MODE_MAIN;
3892 else if (button == MB_MENU_CHOICE)
3894 PlaySound(SND_MENU_ITEM_SELECTING);
3896 FadeMenuSoundsAndMusic();
3898 info_mode = INFO_MODE_MAIN;
3903 PlayMenuSoundIfLoop();
3907 static void DrawInfoScreen(void)
3909 if (info_mode == INFO_MODE_TITLE)
3910 DrawInfoScreen_TitleScreen();
3911 else if (info_mode == INFO_MODE_ELEMENTS)
3912 DrawInfoScreen_Elements();
3913 else if (info_mode == INFO_MODE_MUSIC)
3914 DrawInfoScreen_Music();
3915 else if (info_mode == INFO_MODE_CREDITS)
3916 DrawInfoScreen_Credits();
3917 else if (info_mode == INFO_MODE_PROGRAM)
3918 DrawInfoScreen_Program();
3919 else if (info_mode == INFO_MODE_VERSION)
3920 DrawInfoScreen_Version();
3921 else if (info_mode == INFO_MODE_LEVELSET)
3922 DrawInfoScreen_LevelSet();
3924 DrawInfoScreen_Main();
3926 if (info_mode != INFO_MODE_MAIN &&
3927 info_mode != INFO_MODE_TITLE &&
3928 info_mode != INFO_MODE_MUSIC)
3929 PlayMenuSoundsAndMusic();
3932 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3934 if (info_mode == INFO_MODE_TITLE)
3935 HandleInfoScreen_TitleScreen(button);
3936 else if (info_mode == INFO_MODE_ELEMENTS)
3937 HandleInfoScreen_Elements(button);
3938 else if (info_mode == INFO_MODE_MUSIC)
3939 HandleInfoScreen_Music(button);
3940 else if (info_mode == INFO_MODE_CREDITS)
3941 HandleInfoScreen_Credits(button);
3942 else if (info_mode == INFO_MODE_PROGRAM)
3943 HandleInfoScreen_Program(button);
3944 else if (info_mode == INFO_MODE_VERSION)
3945 HandleInfoScreen_Version(button);
3946 else if (info_mode == INFO_MODE_LEVELSET)
3947 HandleInfoScreen_LevelSet(button);
3949 HandleInfoScreen_Main(mx, my, dx, dy, button);
3953 // ============================================================================
3954 // type name functions
3955 // ============================================================================
3957 void HandleTypeName(int newxpos, Key key)
3959 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3960 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3961 struct TextPosInfo *pos = mci->pos_input;
3962 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3963 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3964 static int xpos = 0;
3965 int font_nr = pos->font;
3966 int font_active_nr = FONT_ACTIVE(font_nr);
3967 int font_width = getFontWidth(font_active_nr);
3968 char key_char = getValidConfigValueChar(getCharFromKey(key));
3969 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3970 boolean is_active = TRUE;
3972 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3976 strcpy(last_player_name, setup.player_name);
3980 StartTextInput(startx, starty, pos->width, pos->height);
3982 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3984 setup.player_name[xpos] = key_char;
3985 setup.player_name[xpos + 1] = 0;
3989 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3993 setup.player_name[xpos] = 0;
3995 else if (key == KSYM_Return && xpos > 0)
4001 SetGameStatus(GAME_MODE_MAIN);
4003 else if (key == KSYM_Escape)
4005 strcpy(setup.player_name, last_player_name);
4009 SetGameStatus(GAME_MODE_MAIN);
4014 pos->width = (strlen(setup.player_name) + 1) * font_width;
4015 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4017 DrawText(startx, starty, setup.player_name, font_active_nr);
4018 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
4022 pos->width = strlen(setup.player_name) * font_width;
4023 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4025 DrawText(startx, starty, setup.player_name, font_nr);
4032 // ============================================================================
4033 // tree menu functions
4034 // ============================================================================
4036 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4038 if (game_status != GAME_MODE_SETUP ||
4039 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4042 int max_text_size = 0;
4045 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4046 max_text_size = MAX(max_text_size, strlen(node->name));
4048 int num_entries = numTreeInfoInGroup(ti);
4049 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4050 int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
4051 int button_width = SC_MENUBUTTON_XSIZE;
4052 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4053 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4054 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4055 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4056 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4057 int align_xoffset = MAX(0, align_xoffset_raw);
4059 return align_xoffset;
4062 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4064 if (game_status != GAME_MODE_SETUP ||
4065 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4068 int num_entries = numTreeInfoInGroup(ti);
4069 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4070 int font_height = getFontHeight(FONT_TEXT_1);
4071 int text_height = font_height * num_page_entries;
4072 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4073 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4074 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4075 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4076 int align_yoffset = MAX(0, align_yoffset_raw);
4078 return align_yoffset;
4081 static void DrawChooseTree(TreeInfo **ti_ptr)
4083 int fade_mask = REDRAW_FIELD;
4086 fade_mask = REDRAW_ALL;
4088 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4090 SetGameStatus(GAME_MODE_MAIN);
4099 FreeScreenGadgets();
4100 CreateScreenGadgets();
4104 // needed if different viewport properties defined for choosing level (set)
4105 ChangeViewportPropertiesIfNeeded();
4107 if (game_status == GAME_MODE_LEVELNR)
4108 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4109 else if (game_status == GAME_MODE_LEVELS)
4110 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4114 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4116 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4117 MapScreenTreeGadgets(*ti_ptr);
4119 DrawMaskedBorder(fade_mask);
4124 static void drawChooseTreeList(int first_entry, int num_page_entries,
4127 int num_entries = numTreeInfoInGroup(ti);
4128 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4129 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4130 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4131 int font_nr = FONT_TEXT_1;
4132 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4134 char *title_string = NULL;
4135 int yoffset_sets = MENU_TITLE1_YPOS;
4136 int yoffset_setup = 16;
4137 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4138 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4140 title_string = ti->infotext;
4142 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4144 clearMenuListArea();
4146 for (i = 0; i < num_page_entries; i++)
4148 TreeInfo *node, *node_first;
4149 int entry_pos = first_entry + i;
4150 int xpos = MENU_SCREEN_START_XPOS;
4151 int ypos = MENU_SCREEN_START_YPOS + i;
4152 int startx = amSX + xpos * 32;
4153 int starty = amSY + ypos * 32;
4154 int startx_text = startx + font_xoffset;
4155 int endx_text = amSX + screen_width;
4156 int max_text_size = endx_text - startx_text;
4157 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4158 char buffer[max_buffer_len + 1];
4160 node_first = getTreeInfoFirstGroupEntry(ti);
4161 node = getTreeInfoFromPos(node_first, entry_pos);
4163 strncpy(buffer, node->name, max_buffer_len);
4164 buffer[max_buffer_len] = '\0';
4166 DrawText(startx, starty, buffer, font_nr + node->color);
4168 if (node->parent_link)
4169 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4170 else if (node->level_group)
4171 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4173 initCursor(i, IMG_MENU_BUTTON);
4176 redraw_mask |= REDRAW_FIELD;
4179 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4181 TreeInfo *node, *node_first;
4182 int x, last_redraw_mask = redraw_mask;
4183 int ypos = MENU_TITLE2_YPOS;
4184 int font_nr = FONT_TITLE_2;
4186 if (ti->type == TREE_TYPE_LEVEL_NR)
4187 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4189 if (ti->type != TREE_TYPE_LEVEL_DIR)
4192 node_first = getTreeInfoFirstGroupEntry(ti);
4193 node = getTreeInfoFromPos(node_first, entry_pos);
4195 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4197 if (node->parent_link)
4198 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4199 node->node_parent->name);
4200 else if (node->level_group)
4201 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4203 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4204 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4205 node->levels, (node->levels > 1 ? "levels" : "level"),
4208 // let BackToFront() redraw only what is needed
4209 redraw_mask = last_redraw_mask;
4210 for (x = 0; x < SCR_FIELDX; x++)
4211 MarkTileDirty(x, 1);
4214 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4217 TreeInfo *ti = *ti_ptr;
4218 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4219 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4220 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4222 int y = ti->cl_cursor;
4223 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4224 int num_entries = numTreeInfoInGroup(ti);
4225 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4226 boolean position_set_by_scrollbar = (dx == 999);
4228 if (button == MB_MENU_INITIALIZE)
4230 int num_entries = numTreeInfoInGroup(ti);
4231 int entry_pos = posTreeInfo(ti);
4233 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4234 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4236 if (ti->cl_first == -1)
4238 // only on initialization
4239 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4240 ti->cl_cursor = entry_pos - ti->cl_first;
4242 else if (ti->cl_cursor >= num_page_entries ||
4243 (num_entries > num_page_entries &&
4244 num_entries - ti->cl_first < num_page_entries))
4246 // only after change of list size (by custom graphic configuration)
4247 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4248 ti->cl_cursor = entry_pos - ti->cl_first;
4251 if (position_set_by_scrollbar)
4254 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4257 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4258 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4259 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4263 else if (button == MB_MENU_LEAVE)
4267 PlaySound(SND_MENU_ITEM_SELECTING);
4269 if (ti->node_parent)
4271 *ti_ptr = ti->node_parent;
4272 DrawChooseTree(ti_ptr);
4274 else if (game_status == GAME_MODE_SETUP)
4276 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4277 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4278 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4280 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4281 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4282 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4283 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4284 execSetupGraphics();
4285 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4286 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4287 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4289 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4290 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4291 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4292 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4293 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4294 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4295 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4296 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4303 if (game_status == GAME_MODE_LEVELNR)
4305 int new_level_nr = atoi(level_number_current->identifier);
4307 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4310 SetGameStatus(GAME_MODE_MAIN);
4318 if (mx || my) // mouse input
4320 x = (mx - amSX) / 32;
4321 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4323 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4325 // move cursor instead of scrolling when already at start/end of list
4326 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4328 else if (dy == +1 * SCROLL_LINE &&
4329 ti->cl_first + num_page_entries == num_entries)
4332 // handle scrolling screen one line or page
4333 if (ti->cl_cursor + dy < 0 ||
4334 ti->cl_cursor + dy > num_page_entries - 1)
4336 boolean redraw = FALSE;
4338 if (ABS(dy) == SCROLL_PAGE)
4339 step = num_page_entries - 1;
4341 if (dy < 0 && ti->cl_first > 0)
4343 // scroll page/line up
4345 ti->cl_first -= step;
4346 if (ti->cl_first < 0)
4351 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4353 // scroll page/line down
4355 ti->cl_first += step;
4356 if (ti->cl_first + num_page_entries > num_entries)
4357 ti->cl_first = MAX(0, num_entries - num_page_entries);
4364 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4365 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4366 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4368 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4375 // handle moving cursor one line
4376 y = ti->cl_cursor + dy;
4381 TreeInfo *node_first, *node_cursor;
4382 int entry_pos = ti->cl_first + y;
4384 node_first = getTreeInfoFirstGroupEntry(ti);
4385 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4387 if (node_cursor->node_group)
4391 PlaySound(SND_MENU_ITEM_SELECTING);
4393 node_cursor->cl_first = ti->cl_first;
4394 node_cursor->cl_cursor = ti->cl_cursor;
4395 *ti_ptr = node_cursor->node_group;
4396 DrawChooseTree(ti_ptr);
4401 else if (dx == -1 && ti->node_parent)
4405 PlaySound(SND_MENU_ITEM_SELECTING);
4407 *ti_ptr = ti->node_parent;
4408 DrawChooseTree(ti_ptr);
4413 if (!anyScrollbarGadgetActive() &&
4414 IN_VIS_MENU(x, y) &&
4415 mx < mx_right_border &&
4416 y >= 0 && y < num_page_entries)
4420 if (y != ti->cl_cursor)
4422 PlaySound(SND_MENU_ITEM_ACTIVATING);
4424 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4425 drawChooseTreeCursor(y, TRUE);
4426 drawChooseTreeInfo(ti->cl_first + y, ti);
4432 if (game_status == GAME_MODE_SETUP)
4434 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4435 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4436 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4438 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4439 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4440 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4441 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4442 execSetupGraphics();
4443 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4444 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4445 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4447 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4448 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4449 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4450 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4451 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4452 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4453 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4454 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4463 TreeInfo *node_first, *node_cursor;
4464 int entry_pos = ti->cl_first + y;
4466 PlaySound(SND_MENU_ITEM_SELECTING);
4468 node_first = getTreeInfoFirstGroupEntry(ti);
4469 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4471 if (node_cursor->node_group)
4475 node_cursor->cl_first = ti->cl_first;
4476 node_cursor->cl_cursor = ti->cl_cursor;
4477 *ti_ptr = node_cursor->node_group;
4478 DrawChooseTree(ti_ptr);
4480 else if (node_cursor->parent_link)
4484 *ti_ptr = node_cursor->node_parent;
4485 DrawChooseTree(ti_ptr);
4491 node_cursor->cl_first = ti->cl_first;
4492 node_cursor->cl_cursor = ti->cl_cursor;
4493 *ti_ptr = node_cursor;
4495 if (ti->type == TREE_TYPE_LEVEL_DIR)
4497 LoadLevelSetup_SeriesInfo();
4499 SaveLevelSetup_LastSeries();
4500 SaveLevelSetup_SeriesInfo();
4504 if (game_status == GAME_MODE_SETUP)
4506 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4507 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4508 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4510 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4511 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4512 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4513 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4514 execSetupGraphics();
4515 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4516 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4517 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4519 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4520 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4521 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4522 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4523 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4524 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4525 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4526 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4533 if (game_status == GAME_MODE_LEVELNR)
4535 int new_level_nr = atoi(level_number_current->identifier);
4537 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4540 SetGameStatus(GAME_MODE_MAIN);
4549 void DrawChooseLevelSet(void)
4551 FadeMenuSoundsAndMusic();
4553 DrawChooseTree(&leveldir_current);
4555 PlayMenuSoundsAndMusic();
4558 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4560 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4563 void DrawChooseLevelNr(void)
4567 FadeMenuSoundsAndMusic();
4569 if (level_number != NULL)
4571 freeTreeInfo(level_number);
4573 level_number = NULL;
4576 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4578 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4579 char identifier[32], name[64];
4582 // temporarily load level info to get level name
4583 LoadLevelInfoOnly(i);
4585 ti->node_top = &level_number;
4586 ti->sort_priority = 10000 + value;
4587 ti->color = (level.no_level_file ? FC_BLUE :
4588 LevelStats_getSolved(i) ? FC_GREEN :
4589 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4591 snprintf(identifier, sizeof(identifier), "%d", value);
4592 snprintf(name, sizeof(name), "%03d: %s", value,
4593 (level.no_level_file ? "(no file)" : level.name));
4595 setString(&ti->identifier, identifier);
4596 setString(&ti->name, name);
4597 setString(&ti->name_sorting, name);
4599 pushTreeInfo(&level_number, ti);
4602 // sort level number values to start with lowest level number
4603 sortTreeInfo(&level_number);
4605 // set current level number to current level number
4606 level_number_current =
4607 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4609 // if that also fails, set current level number to first available level
4610 if (level_number_current == NULL)
4611 level_number_current = level_number;
4613 DrawChooseTree(&level_number_current);
4615 PlayMenuSoundsAndMusic();
4618 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4620 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4623 void DrawHallOfFame(int level_nr, int highlight_position)
4625 int fade_mask = REDRAW_FIELD;
4628 fade_mask = REDRAW_ALL;
4631 FadeMenuSoundsAndMusic();
4633 // (this is needed when called from GameEnd() after winning a game)
4634 KeyboardAutoRepeatOn();
4636 // (this is needed when called from GameEnd() after winning a game)
4637 SetDrawDeactivationMask(REDRAW_NONE);
4638 SetDrawBackgroundMask(REDRAW_FIELD);
4640 if (highlight_position < 0)
4641 LoadScore(level_nr);
4643 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4645 FadeSetEnterScreen();
4649 // needed if different viewport properties defined for scores
4650 ChangeViewportPropertiesIfNeeded();
4652 PlayMenuSoundsAndMusic();
4654 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4656 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4658 DrawMaskedBorder(fade_mask);
4663 static void drawHallOfFameList(int level_nr, int first_entry,
4664 int highlight_position)
4668 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4671 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4672 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4673 "HighScores of Level %d", level_nr);
4675 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4677 int entry = first_entry + i;
4678 boolean active = (entry == highlight_position);
4679 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4680 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4681 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4682 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4683 int dxoff = getFontDrawOffsetX(font_nr1);
4684 int dx1 = 3 * getFontWidth(font_nr1);
4685 int dx2 = dx1 + getFontWidth(font_nr1);
4686 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4687 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4688 int sy = mSY + 64 + i * 32;
4690 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4691 DrawText(mSX + dx1, sy, ".", font_nr1);
4693 for (j = 0; j < num_dots; j++)
4694 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4696 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4697 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4699 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4702 redraw_mask |= REDRAW_FIELD;
4705 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4707 static int level_nr = 0;
4708 static int first_entry = 0;
4709 static int highlight_position = 0;
4710 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4712 if (button == MB_MENU_INITIALIZE)
4716 highlight_position = my;
4718 drawHallOfFameList(level_nr, first_entry, highlight_position);
4723 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
4724 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4728 if (first_entry > 0)
4730 first_entry -= step;
4731 if (first_entry < 0)
4734 drawHallOfFameList(level_nr, first_entry, highlight_position);
4739 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4741 first_entry += step;
4742 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4743 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4745 drawHallOfFameList(level_nr, first_entry, highlight_position);
4748 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4750 PlaySound(SND_MENU_ITEM_SELECTING);
4752 FadeSound(SND_BACKGROUND_SCORES);
4754 if (button == MB_MENU_CHOICE &&
4755 game_status_last_screen == GAME_MODE_PLAYING &&
4756 setup.auto_play_next_level && setup.increment_levels &&
4757 level_nr < leveldir_current->last_level &&
4760 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4764 SetGameStatus(GAME_MODE_MAIN);
4770 if (game_status == GAME_MODE_SCORES)
4771 PlayMenuSoundIfLoop();
4775 // ============================================================================
4776 // setup screen functions
4777 // ============================================================================
4779 static struct TokenInfo *setup_info;
4780 static int num_setup_info; // number of setup entries shown on screen
4781 static int max_setup_info; // total number of setup entries in list
4783 static char *window_size_text;
4784 static char *scaling_type_text;
4785 static char *rendering_mode_text;
4786 static char *vsync_mode_text;
4787 static char *scroll_delay_text;
4788 static char *snapshot_mode_text;
4789 static char *game_speed_text;
4790 static char *network_server_text;
4791 static char *graphics_set_name;
4792 static char *sounds_set_name;
4793 static char *music_set_name;
4794 static char *volume_simple_text;
4795 static char *volume_loops_text;
4796 static char *volume_music_text;
4797 static char *touch_controls_text;
4798 static char *move_distance_text;
4799 static char *drop_distance_text;
4800 static char *transparency_text;
4801 static char *grid_size_text[2][2];
4803 static void execSetupMain(void)
4805 setup_mode = SETUP_MODE_MAIN;
4810 static void execSetupGame_setGameSpeeds(boolean update_value)
4812 if (setup.game_speed_extended)
4814 game_speeds_list = game_speeds_list_extended;
4815 game_speeds = game_speeds_extended;
4819 game_speeds_list = game_speeds_list_normal;
4820 game_speeds = game_speeds_normal;
4823 if (game_speeds == NULL)
4827 for (i = 0; game_speeds_list[i].value != -1; i++)
4829 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4830 char identifier[32], name[32];
4831 int value = game_speeds_list[i].value;
4832 char *text = game_speeds_list[i].text;
4834 ti->node_top = &game_speeds;
4835 ti->sort_priority = 10000 - value;
4837 sprintf(identifier, "%d", value);
4838 sprintf(name, "%s", text);
4840 setString(&ti->identifier, identifier);
4841 setString(&ti->name, name);
4842 setString(&ti->name_sorting, name);
4843 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4845 pushTreeInfo(&game_speeds, ti);
4848 // sort game speed values to start with slowest game speed
4849 sortTreeInfo(&game_speeds);
4851 update_value = TRUE;
4856 // set current game speed to configured game speed value
4857 game_speed_current =
4858 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4860 // if that fails, set current game speed to reliable default value
4861 if (game_speed_current == NULL)
4862 game_speed_current =
4863 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4865 // if that also fails, set current game speed to first available speed
4866 if (game_speed_current == NULL)
4867 game_speed_current = game_speeds;
4869 if (setup.game_speed_extended)
4870 game_speeds_extended = game_speeds;
4872 game_speeds_normal = game_speeds;
4875 setup.game_frame_delay = atoi(game_speed_current->identifier);
4877 // needed for displaying game speed text instead of identifier
4878 game_speed_text = game_speed_current->name;
4881 static void execSetupGame_setScrollDelays(void)
4883 if (scroll_delays == NULL)
4887 for (i = 0; scroll_delays_list[i].value != -1; i++)
4889 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4890 char identifier[32], name[32];
4891 int value = scroll_delays_list[i].value;
4892 char *text = scroll_delays_list[i].text;
4894 ti->node_top = &scroll_delays;
4895 ti->sort_priority = value;
4897 sprintf(identifier, "%d", value);
4898 sprintf(name, "%s", text);
4900 setString(&ti->identifier, identifier);
4901 setString(&ti->name, name);
4902 setString(&ti->name_sorting, name);
4903 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4905 pushTreeInfo(&scroll_delays, ti);
4908 // sort scroll delay values to start with lowest scroll delay value
4909 sortTreeInfo(&scroll_delays);
4911 // set current scroll delay value to configured scroll delay value
4912 scroll_delay_current =
4913 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4915 // if that fails, set current scroll delay to reliable default value
4916 if (scroll_delay_current == NULL)
4917 scroll_delay_current =
4918 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4920 // if that also fails, set current scroll delay to first available value
4921 if (scroll_delay_current == NULL)
4922 scroll_delay_current = scroll_delays;
4925 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4927 // needed for displaying scroll delay text instead of identifier
4928 scroll_delay_text = scroll_delay_current->name;
4931 static void execSetupGame_setSnapshotModes(void)
4933 if (snapshot_modes == NULL)
4937 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4939 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4940 char identifier[32], name[32];
4941 char *value = snapshot_modes_list[i].value;
4942 char *text = snapshot_modes_list[i].text;
4944 ti->node_top = &snapshot_modes;
4945 ti->sort_priority = i;
4947 sprintf(identifier, "%s", value);
4948 sprintf(name, "%s", text);
4950 setString(&ti->identifier, identifier);
4951 setString(&ti->name, name);
4952 setString(&ti->name_sorting, name);
4953 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4955 pushTreeInfo(&snapshot_modes, ti);
4958 // sort snapshot mode values to start with lowest snapshot mode value
4959 sortTreeInfo(&snapshot_modes);
4961 // set current snapshot mode value to configured snapshot mode value
4962 snapshot_mode_current =
4963 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4965 // if that fails, set current snapshot mode to reliable default value
4966 if (snapshot_mode_current == NULL)
4967 snapshot_mode_current =
4968 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4970 // if that also fails, set current snapshot mode to first available value
4971 if (snapshot_mode_current == NULL)
4972 snapshot_mode_current = snapshot_modes;
4975 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4977 // needed for displaying snapshot mode text instead of identifier
4978 snapshot_mode_text = snapshot_mode_current->name;
4981 static void execSetupGame_setNetworkServerText(void)
4983 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
4985 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
4989 strncpy(network_server_hostname, setup.network_server_hostname,
4990 MAX_SETUP_TEXT_INPUT_LEN);
4991 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
4994 // needed for displaying network server text instead of identifier
4995 network_server_text = network_server_hostname;
4998 static void execSetupGame(void)
5000 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5002 execSetupGame_setGameSpeeds(FALSE);
5003 execSetupGame_setScrollDelays();
5004 execSetupGame_setSnapshotModes();
5006 execSetupGame_setNetworkServerText();
5008 setup_mode = SETUP_MODE_GAME;
5012 // check if vsync needs to be disabled for this game speed to work
5013 if (check_vsync_mode)
5014 DisableVsyncIfNeeded();
5017 static void execSetupChooseGameSpeed(void)
5019 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5024 static void execSetupChooseScrollDelay(void)
5026 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5031 static void execSetupChooseSnapshotMode(void)
5033 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5038 static void execSetupEngines(void)
5040 setup_mode = SETUP_MODE_ENGINES;
5045 static void execSetupEditor(void)
5047 setup_mode = SETUP_MODE_EDITOR;
5052 static void execSetupGraphics_setWindowSizes(boolean update_list)
5054 if (window_sizes != NULL && update_list)
5056 freeTreeInfo(window_sizes);
5058 window_sizes = NULL;
5061 if (window_sizes == NULL)
5063 boolean current_window_size_found = FALSE;
5066 for (i = 0; window_sizes_list[i].value != -1; i++)
5068 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5069 char identifier[32], name[32];
5070 int value = window_sizes_list[i].value;
5071 char *text = window_sizes_list[i].text;
5073 ti->node_top = &window_sizes;
5074 ti->sort_priority = value;
5076 sprintf(identifier, "%d", value);
5077 sprintf(name, "%s", text);
5079 setString(&ti->identifier, identifier);
5080 setString(&ti->name, name);
5081 setString(&ti->name_sorting, name);
5082 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5084 pushTreeInfo(&window_sizes, ti);
5086 if (value == setup.window_scaling_percent)
5087 current_window_size_found = TRUE;
5090 if (!current_window_size_found)
5092 // add entry for non-preset window scaling value
5094 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5095 char identifier[32], name[32];
5096 int value = setup.window_scaling_percent;
5098 ti->node_top = &window_sizes;
5099 ti->sort_priority = value;
5101 sprintf(identifier, "%d", value);
5102 sprintf(name, "%d %% (Current)", value);
5104 setString(&ti->identifier, identifier);
5105 setString(&ti->name, name);
5106 setString(&ti->name_sorting, name);
5107 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5109 pushTreeInfo(&window_sizes, ti);
5112 // sort window size values to start with lowest window size value
5113 sortTreeInfo(&window_sizes);
5115 // set current window size value to configured window size value
5116 window_size_current =
5117 getTreeInfoFromIdentifier(window_sizes,
5118 i_to_a(setup.window_scaling_percent));
5120 // if that fails, set current window size to reliable default value
5121 if (window_size_current == NULL)
5122 window_size_current =
5123 getTreeInfoFromIdentifier(window_sizes,
5124 i_to_a(STD_WINDOW_SCALING_PERCENT));
5126 // if that also fails, set current window size to first available value
5127 if (window_size_current == NULL)
5128 window_size_current = window_sizes;
5131 setup.window_scaling_percent = atoi(window_size_current->identifier);
5133 // needed for displaying window size text instead of identifier
5134 window_size_text = window_size_current->name;
5137 static void execSetupGraphics_setScalingTypes(void)
5139 if (scaling_types == NULL)
5143 for (i = 0; scaling_types_list[i].value != NULL; i++)
5145 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5146 char identifier[32], name[32];
5147 char *value = scaling_types_list[i].value;
5148 char *text = scaling_types_list[i].text;
5150 ti->node_top = &scaling_types;
5151 ti->sort_priority = i;
5153 sprintf(identifier, "%s", value);
5154 sprintf(name, "%s", text);
5156 setString(&ti->identifier, identifier);
5157 setString(&ti->name, name);
5158 setString(&ti->name_sorting, name);
5159 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5161 pushTreeInfo(&scaling_types, ti);
5164 // sort scaling type values to start with lowest scaling type value
5165 sortTreeInfo(&scaling_types);
5167 // set current scaling type value to configured scaling type value
5168 scaling_type_current =
5169 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5171 // if that fails, set current scaling type to reliable default value
5172 if (scaling_type_current == NULL)
5173 scaling_type_current =
5174 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5176 // if that also fails, set current scaling type to first available value
5177 if (scaling_type_current == NULL)
5178 scaling_type_current = scaling_types;
5181 setup.window_scaling_quality = scaling_type_current->identifier;
5183 // needed for displaying scaling type text instead of identifier
5184 scaling_type_text = scaling_type_current->name;
5187 static void execSetupGraphics_setRenderingModes(void)
5189 if (rendering_modes == NULL)
5193 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5195 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5196 char identifier[32], name[32];
5197 char *value = rendering_modes_list[i].value;
5198 char *text = rendering_modes_list[i].text;
5200 ti->node_top = &rendering_modes;
5201 ti->sort_priority = i;
5203 sprintf(identifier, "%s", value);
5204 sprintf(name, "%s", text);
5206 setString(&ti->identifier, identifier);
5207 setString(&ti->name, name);
5208 setString(&ti->name_sorting, name);
5209 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5211 pushTreeInfo(&rendering_modes, ti);
5214 // sort rendering mode values to start with lowest rendering mode value
5215 sortTreeInfo(&rendering_modes);
5217 // set current rendering mode value to configured rendering mode value
5218 rendering_mode_current =
5219 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5221 // if that fails, set current rendering mode to reliable default value
5222 if (rendering_mode_current == NULL)
5223 rendering_mode_current =
5224 getTreeInfoFromIdentifier(rendering_modes,
5225 STR_SPECIAL_RENDERING_DEFAULT);
5227 // if that also fails, set current rendering mode to first available one
5228 if (rendering_mode_current == NULL)
5229 rendering_mode_current = rendering_modes;
5232 setup.screen_rendering_mode = rendering_mode_current->identifier;
5234 // needed for displaying rendering mode text instead of identifier
5235 rendering_mode_text = rendering_mode_current->name;
5238 static void execSetupGraphics_setVsyncModes(boolean update_value)
5240 if (vsync_modes == NULL)
5244 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5246 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5247 char identifier[32], name[32];
5248 char *value = vsync_modes_list[i].value;
5249 char *text = vsync_modes_list[i].text;
5251 ti->node_top = &vsync_modes;
5252 ti->sort_priority = i;
5254 sprintf(identifier, "%s", value);
5255 sprintf(name, "%s", text);
5257 setString(&ti->identifier, identifier);
5258 setString(&ti->name, name);
5259 setString(&ti->name_sorting, name);
5260 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5262 pushTreeInfo(&vsync_modes, ti);
5265 // sort vsync mode values to start with lowest vsync mode value
5266 sortTreeInfo(&vsync_modes);
5268 update_value = TRUE;
5273 // set current vsync mode value to configured vsync mode value
5274 vsync_mode_current =
5275 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5277 // if that fails, set current vsync mode to reliable default value
5278 if (vsync_mode_current == NULL)
5279 vsync_mode_current =
5280 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5282 // if that also fails, set current vsync mode to first available one
5283 if (vsync_mode_current == NULL)
5284 vsync_mode_current = vsync_modes;
5287 setup.vsync_mode = vsync_mode_current->identifier;
5289 // needed for displaying vsync mode text instead of identifier
5290 vsync_mode_text = vsync_mode_current->name;
5293 static void execSetupGraphics(void)
5295 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5297 // update "setup.window_scaling_percent" from list selection
5298 // (in this case, window scaling was changed on setup screen)
5299 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5300 execSetupGraphics_setWindowSizes(FALSE);
5302 // update "setup.vsync_mode" from list selection
5303 // (in this case, vsync mode was changed on setup screen)
5304 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5305 execSetupGraphics_setVsyncModes(FALSE);
5307 // update list selection from "setup.window_scaling_percent"
5308 // (window scaling may have changed by resizing the window)
5309 execSetupGraphics_setWindowSizes(TRUE);
5311 // update list selection from "setup.vsync_mode"
5312 // (vsync_mode may have changed by re-creating the renderer)
5313 execSetupGraphics_setVsyncModes(TRUE);
5315 execSetupGraphics_setScalingTypes();
5316 execSetupGraphics_setRenderingModes();
5318 setup_mode = SETUP_MODE_GRAPHICS;
5322 // check if game speed is high enough for 60 Hz vsync to work
5323 if (check_game_speed)
5324 ModifyGameSpeedIfNeeded();
5326 // window scaling may have changed at this point
5327 ChangeWindowScalingIfNeeded();
5329 // window scaling quality may have changed at this point
5330 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5331 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5333 // screen rendering mode may have changed at this point
5334 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5336 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
5337 int video_vsync_mode = video.vsync_mode;
5339 // screen vsync mode may have changed at this point
5340 ChangeVsyncModeIfNeeded();
5342 // check if setting vsync mode to selected value failed
5343 if (setup_vsync_mode != video_vsync_mode &&
5344 setup_vsync_mode != video.vsync_mode)
5346 // changing vsync mode to selected value failed -- reset displayed value
5347 execSetupGraphics_setVsyncModes(TRUE);
5349 Request("Setting VSync failed!", REQ_CONFIRM);
5355 static void execSetupChooseWindowSize(void)
5357 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5362 static void execSetupChooseScalingType(void)
5364 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5369 static void execSetupChooseRenderingMode(void)
5371 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5376 static void execSetupChooseVsyncMode(void)
5378 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5383 static void execSetupChooseVolumeSimple(void)
5385 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5390 static void execSetupChooseVolumeLoops(void)
5392 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5397 static void execSetupChooseVolumeMusic(void)
5399 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5404 static void execSetupSound(void)
5406 if (volumes_simple == NULL)
5408 boolean current_volume_simple_found = FALSE;
5411 for (i = 0; volumes_list[i].value != -1; i++)
5413 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5414 char identifier[32], name[32];
5415 int value = volumes_list[i].value;
5416 char *text = volumes_list[i].text;
5418 ti->node_top = &volumes_simple;
5419 ti->sort_priority = value;
5421 sprintf(identifier, "%d", value);
5422 sprintf(name, "%s", text);
5424 setString(&ti->identifier, identifier);
5425 setString(&ti->name, name);
5426 setString(&ti->name_sorting, name);
5427 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5429 pushTreeInfo(&volumes_simple, ti);
5431 if (value == setup.volume_simple)
5432 current_volume_simple_found = TRUE;
5435 if (!current_volume_simple_found)
5437 // add entry for non-preset volume value
5439 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5440 char identifier[32], name[32];
5441 int value = setup.volume_simple;
5443 ti->node_top = &volumes_simple;
5444 ti->sort_priority = value;
5446 sprintf(identifier, "%d", value);
5447 sprintf(name, "%d %% (Current)", value);
5449 setString(&ti->identifier, identifier);
5450 setString(&ti->name, name);
5451 setString(&ti->name_sorting, name);
5452 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5454 pushTreeInfo(&volumes_simple, ti);
5457 // sort volume values to start with lowest volume value
5458 sortTreeInfo(&volumes_simple);
5460 // set current volume value to configured volume value
5461 volume_simple_current =
5462 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5464 // if that fails, set current volume to reliable default value
5465 if (volume_simple_current == NULL)
5466 volume_simple_current =
5467 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5469 // if that also fails, set current volume to first available value
5470 if (volume_simple_current == NULL)
5471 volume_simple_current = volumes_simple;
5474 if (volumes_loops == NULL)
5476 boolean current_volume_loops_found = FALSE;
5479 for (i = 0; volumes_list[i].value != -1; i++)
5481 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5482 char identifier[32], name[32];
5483 int value = volumes_list[i].value;
5484 char *text = volumes_list[i].text;
5486 ti->node_top = &volumes_loops;
5487 ti->sort_priority = value;
5489 sprintf(identifier, "%d", value);
5490 sprintf(name, "%s", text);
5492 setString(&ti->identifier, identifier);
5493 setString(&ti->name, name);
5494 setString(&ti->name_sorting, name);
5495 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5497 pushTreeInfo(&volumes_loops, ti);
5499 if (value == setup.volume_loops)
5500 current_volume_loops_found = TRUE;
5503 if (!current_volume_loops_found)
5505 // add entry for non-preset volume value
5507 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5508 char identifier[32], name[32];
5509 int value = setup.volume_loops;
5511 ti->node_top = &volumes_loops;
5512 ti->sort_priority = value;
5514 sprintf(identifier, "%d", value);
5515 sprintf(name, "%d %% (Current)", value);
5517 setString(&ti->identifier, identifier);
5518 setString(&ti->name, name);
5519 setString(&ti->name_sorting, name);
5520 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5522 pushTreeInfo(&volumes_loops, ti);
5525 // sort volume values to start with lowest volume value
5526 sortTreeInfo(&volumes_loops);
5528 // set current volume value to configured volume value
5529 volume_loops_current =
5530 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5532 // if that fails, set current volume to reliable default value
5533 if (volume_loops_current == NULL)
5534 volume_loops_current =
5535 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5537 // if that also fails, set current volume to first available value
5538 if (volume_loops_current == NULL)
5539 volume_loops_current = volumes_loops;
5542 if (volumes_music == NULL)
5544 boolean current_volume_music_found = FALSE;
5547 for (i = 0; volumes_list[i].value != -1; i++)
5549 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5550 char identifier[32], name[32];
5551 int value = volumes_list[i].value;
5552 char *text = volumes_list[i].text;
5554 ti->node_top = &volumes_music;
5555 ti->sort_priority = value;
5557 sprintf(identifier, "%d", value);
5558 sprintf(name, "%s", text);
5560 setString(&ti->identifier, identifier);
5561 setString(&ti->name, name);
5562 setString(&ti->name_sorting, name);
5563 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5565 pushTreeInfo(&volumes_music, ti);
5567 if (value == setup.volume_music)
5568 current_volume_music_found = TRUE;
5571 if (!current_volume_music_found)
5573 // add entry for non-preset volume value
5575 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5576 char identifier[32], name[32];
5577 int value = setup.volume_music;
5579 ti->node_top = &volumes_music;
5580 ti->sort_priority = value;
5582 sprintf(identifier, "%d", value);
5583 sprintf(name, "%d %% (Current)", value);
5585 setString(&ti->identifier, identifier);
5586 setString(&ti->name, name);
5587 setString(&ti->name_sorting, name);
5588 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5590 pushTreeInfo(&volumes_music, ti);
5593 // sort volume values to start with lowest volume value
5594 sortTreeInfo(&volumes_music);
5596 // set current volume value to configured volume value
5597 volume_music_current =
5598 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5600 // if that fails, set current volume to reliable default value
5601 if (volume_music_current == NULL)
5602 volume_music_current =
5603 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5605 // if that also fails, set current volume to first available value
5606 if (volume_music_current == NULL)
5607 volume_music_current = volumes_music;
5610 setup.volume_simple = atoi(volume_simple_current->identifier);
5611 setup.volume_loops = atoi(volume_loops_current->identifier);
5612 setup.volume_music = atoi(volume_music_current->identifier);
5614 // needed for displaying volume text instead of identifier
5615 volume_simple_text = volume_simple_current->name;
5616 volume_loops_text = volume_loops_current->name;
5617 volume_music_text = volume_music_current->name;
5619 setup_mode = SETUP_MODE_SOUND;
5624 static void execSetupChooseTouchControls(void)
5626 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5631 static void execSetupChooseMoveDistance(void)
5633 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5638 static void execSetupChooseDropDistance(void)
5640 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5645 static void execSetupChooseTransparency(void)
5647 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5652 static void execSetupChooseGridXSize_0(void)
5654 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5659 static void execSetupChooseGridYSize_0(void)
5661 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5666 static void execSetupChooseGridXSize_1(void)
5668 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5673 static void execSetupChooseGridYSize_1(void)
5675 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5680 static void execSetupConfigureVirtualButtons(void)
5682 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5684 ConfigureVirtualButtons();
5686 setup_mode = SETUP_MODE_TOUCH;
5691 static void execSetupTouch(void)
5695 if (touch_controls == NULL)
5697 for (i = 0; touch_controls_list[i].value != NULL; i++)
5699 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5700 char identifier[32], name[32];
5701 char *value = touch_controls_list[i].value;
5702 char *text = touch_controls_list[i].text;
5704 ti->node_top = &touch_controls;
5705 ti->sort_priority = i;
5707 sprintf(identifier, "%s", value);
5708 sprintf(name, "%s", text);
5710 setString(&ti->identifier, identifier);
5711 setString(&ti->name, name);
5712 setString(&ti->name_sorting, name);
5713 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5715 pushTreeInfo(&touch_controls, ti);
5718 // sort touch control values to start with lowest touch control value
5719 sortTreeInfo(&touch_controls);
5721 // set current touch control value to configured touch control value
5722 touch_control_current =
5723 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5725 // if that fails, set current touch control to reliable default value
5726 if (touch_control_current == NULL)
5727 touch_control_current =
5728 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5730 // if that also fails, set current touch control to first available value
5731 if (touch_control_current == NULL)
5732 touch_control_current = touch_controls;
5735 if (move_distances == NULL)
5737 for (i = 0; distances_list[i].value != -1; i++)
5739 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5740 char identifier[32], name[32];
5741 int value = distances_list[i].value;
5742 char *text = distances_list[i].text;
5744 ti->node_top = &move_distances;
5745 ti->sort_priority = value;
5747 sprintf(identifier, "%d", value);
5748 sprintf(name, "%s", text);
5750 setString(&ti->identifier, identifier);
5751 setString(&ti->name, name);
5752 setString(&ti->name_sorting, name);
5753 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5755 pushTreeInfo(&move_distances, ti);
5758 // sort distance values to start with lowest distance value
5759 sortTreeInfo(&move_distances);
5761 // set current distance value to configured distance value
5762 move_distance_current =
5763 getTreeInfoFromIdentifier(move_distances,
5764 i_to_a(setup.touch.move_distance));
5766 // if that fails, set current distance to reliable default value
5767 if (move_distance_current == NULL)
5768 move_distance_current =
5769 getTreeInfoFromIdentifier(move_distances,
5770 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5772 // if that also fails, set current distance to first available value
5773 if (move_distance_current == NULL)
5774 move_distance_current = move_distances;
5777 if (drop_distances == NULL)
5779 for (i = 0; distances_list[i].value != -1; i++)
5781 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5782 char identifier[32], name[32];
5783 int value = distances_list[i].value;
5784 char *text = distances_list[i].text;
5786 ti->node_top = &drop_distances;
5787 ti->sort_priority = value;
5789 sprintf(identifier, "%d", value);
5790 sprintf(name, "%s", text);
5792 setString(&ti->identifier, identifier);
5793 setString(&ti->name, name);
5794 setString(&ti->name_sorting, name);
5795 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5797 pushTreeInfo(&drop_distances, ti);
5800 // sort distance values to start with lowest distance value
5801 sortTreeInfo(&drop_distances);
5803 // set current distance value to configured distance value
5804 drop_distance_current =
5805 getTreeInfoFromIdentifier(drop_distances,
5806 i_to_a(setup.touch.drop_distance));
5808 // if that fails, set current distance to reliable default value
5809 if (drop_distance_current == NULL)
5810 drop_distance_current =
5811 getTreeInfoFromIdentifier(drop_distances,
5812 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5814 // if that also fails, set current distance to first available value
5815 if (drop_distance_current == NULL)
5816 drop_distance_current = drop_distances;
5819 if (transparencies == NULL)
5821 for (i = 0; transparencies_list[i].value != -1; i++)
5823 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5824 char identifier[32], name[32];
5825 int value = transparencies_list[i].value;
5826 char *text = transparencies_list[i].text;
5828 ti->node_top = &transparencies;
5829 ti->sort_priority = value;
5831 sprintf(identifier, "%d", value);
5832 sprintf(name, "%s", text);
5834 setString(&ti->identifier, identifier);
5835 setString(&ti->name, name);
5836 setString(&ti->name_sorting, name);
5837 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5839 pushTreeInfo(&transparencies, ti);
5842 // sort transparency values to start with lowest transparency value
5843 sortTreeInfo(&transparencies);
5845 // set current transparency value to configured transparency value
5846 transparency_current =
5847 getTreeInfoFromIdentifier(transparencies,
5848 i_to_a(setup.touch.transparency));
5850 // if that fails, set current transparency to reliable default value
5851 if (transparency_current == NULL)
5852 transparency_current =
5853 getTreeInfoFromIdentifier(transparencies,
5854 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5856 // if that also fails, set current transparency to first available value
5857 if (transparency_current == NULL)
5858 transparency_current = transparencies;
5861 for (i = 0; i < 2; i++)
5863 for (j = 0; j < 2; j++)
5865 if (grid_sizes[i][j] == NULL)
5867 for (k = 0; grid_sizes_list[k].value != -1; k++)
5869 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5870 char identifier[32], name[32];
5871 int value = grid_sizes_list[k].value;
5872 char *text = grid_sizes_list[k].text;
5874 ti->node_top = &grid_sizes[i][j];
5875 ti->sort_priority = value;
5877 sprintf(identifier, "%d", value);
5878 sprintf(name, "%s", text);
5880 setString(&ti->identifier, identifier);
5881 setString(&ti->name, name);
5882 setString(&ti->name_sorting, name);
5883 setString(&ti->infotext,
5886 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5887 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5889 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5890 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5892 pushTreeInfo(&grid_sizes[i][j], ti);
5895 // sort grid size values to start with lowest grid size value
5896 sortTreeInfo(&grid_sizes[i][j]);
5898 // set current grid size value to configured grid size value
5899 grid_size_current[i][j] =
5900 getTreeInfoFromIdentifier(grid_sizes[i][j],
5902 setup.touch.grid_xsize[i] :
5903 setup.touch.grid_ysize[i]));
5905 // if that fails, set current grid size to reliable default value
5906 if (grid_size_current[i][j] == NULL)
5907 grid_size_current[i][j] =
5908 getTreeInfoFromIdentifier(grid_sizes[i][j],
5910 DEFAULT_GRID_XSIZE(i) :
5911 DEFAULT_GRID_YSIZE(i)));
5913 // if that also fails, set current grid size to first available value
5914 if (grid_size_current[i][j] == NULL)
5915 grid_size_current[i][j] = grid_sizes[i][j];
5920 setup.touch.control_type = touch_control_current->identifier;
5921 setup.touch.move_distance = atoi(move_distance_current->identifier);
5922 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5923 setup.touch.transparency = atoi(transparency_current->identifier);
5925 for (i = 0; i < 2; i++)
5927 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5928 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5930 if (i == GRID_ACTIVE_NR())
5932 overlay.grid_xsize = setup.touch.grid_xsize[i];
5933 overlay.grid_ysize = setup.touch.grid_ysize[i];
5937 // needed for displaying value text instead of identifier
5938 touch_controls_text = touch_control_current->name;
5939 move_distance_text = move_distance_current->name;
5940 drop_distance_text = drop_distance_current->name;
5941 transparency_text = transparency_current->name;
5943 for (i = 0; i < 2; i++)
5944 for (j = 0; j < 2; j++)
5945 grid_size_text[i][j] = grid_size_current[i][j]->name;
5947 setup_mode = SETUP_MODE_TOUCH;
5952 static void execSetupArtwork(void)
5955 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
5956 artwork.gfx_current->subdir,
5957 artwork.gfx_current->fullpath,
5958 artwork.gfx_current->basepath);
5961 setup.graphics_set = artwork.gfx_current->identifier;
5962 setup.sounds_set = artwork.snd_current->identifier;
5963 setup.music_set = artwork.mus_current->identifier;
5965 // needed if last screen (setup choice) changed graphics, sounds or music
5966 ReloadCustomArtwork(0);
5968 // needed for displaying artwork name instead of artwork identifier
5969 graphics_set_name = artwork.gfx_current->name;
5970 sounds_set_name = artwork.snd_current->name;
5971 music_set_name = artwork.mus_current->name;
5973 setup_mode = SETUP_MODE_ARTWORK;
5978 static void execSetupChooseGraphics(void)
5980 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5985 static void execSetupChooseSounds(void)
5987 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5992 static void execSetupChooseMusic(void)
5994 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5999 static void execSetupInput(void)
6001 setup_mode = SETUP_MODE_INPUT;
6006 static void execSetupShortcuts(void)
6008 setup_mode = SETUP_MODE_SHORTCUTS;
6013 static void execSetupShortcuts1(void)
6015 setup_mode = SETUP_MODE_SHORTCUTS_1;
6020 static void execSetupShortcuts2(void)
6022 setup_mode = SETUP_MODE_SHORTCUTS_2;
6027 static void execSetupShortcuts3(void)
6029 setup_mode = SETUP_MODE_SHORTCUTS_3;
6034 static void execSetupShortcuts4(void)
6036 setup_mode = SETUP_MODE_SHORTCUTS_4;
6041 static void execSetupShortcuts5(void)
6043 setup_mode = SETUP_MODE_SHORTCUTS_5;
6048 static void execExitSetup(void)
6050 SetGameStatus(GAME_MODE_MAIN);
6055 static void execSaveAndExitSetup(void)
6061 static void execGadgetNetworkServer(void)
6063 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6064 struct GadgetInfo *gi = screen_gadget[gadget_id];
6066 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6067 network_server_hostname[0] = '\0';
6069 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6073 ClickOnGadget(gi, MB_LEFTBUTTON);
6076 static void ToggleNetworkModeIfNeeded(void)
6078 int font_title = FONT_TITLE_1;
6079 int font_foot = FC_BLUE;
6080 int ystart = mSY - SY + 16;
6081 int ybottom = mSY - SY + SYSIZE - 20;
6082 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6084 if (setup.network_mode == network.enabled)
6087 network.enabled = setup.network_mode;
6089 FadeOut(REDRAW_ALL);
6093 DrawTextSCentered(ystart, font_title, text);
6097 if (network.enabled)
6098 InitNetworkServer();
6100 DisconnectFromNetworkServer();
6102 DrawTextSCentered(ybottom, font_foot,
6103 "Press any key or button for setup menu");
6105 WaitForEventToContinue();
6110 static void ToggleGameSpeedsListIfNeeded(void)
6112 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6114 if (setup.game_speed_extended == using_game_speeds_extended)
6117 // try to match similar values when changing game speeds list
6118 if (setup.game_speed_extended)
6119 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6120 setup.game_frame_delay == 30 ? 29 :
6121 setup.game_frame_delay);
6123 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6124 setup.game_frame_delay == 16 ? 15 :
6125 setup.game_frame_delay >= 29 ? 30 :
6126 setup.game_frame_delay <= 10 ? 10 :
6127 setup.game_frame_delay);
6129 execSetupGame_setGameSpeeds(TRUE);
6134 static void ModifyGameSpeedIfNeeded(void)
6136 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6137 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6141 char *game_speed_text = "Fast";
6142 int game_speed_value = 15;
6144 if (setup.game_speed_extended)
6146 game_speed_text = "60 fps";
6147 game_speed_value = 16;
6150 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6152 // set game speed to existing list value that is fast enough for vsync
6153 setup.game_frame_delay = game_speed_value;
6155 execSetupGame_setGameSpeeds(TRUE);
6157 Request(message, REQ_CONFIRM);
6160 static void DisableVsyncIfNeeded(void)
6162 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6163 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6164 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6167 // disable vsync for the selected game speed to work
6168 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6170 execSetupGraphics_setVsyncModes(TRUE);
6172 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6178 void *related_value;
6179 } hide_related_entry_list[] =
6181 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6182 { &setup.game_frame_delay, &game_speed_text },
6184 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6185 { &setup.scroll_delay_value, &scroll_delay_text },
6187 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6188 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6190 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6191 { &setup.window_scaling_percent, &window_size_text },
6193 { &setup.window_scaling_quality, execSetupChooseScalingType },
6194 { &setup.window_scaling_quality, &scaling_type_text },
6196 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6197 { &setup.screen_rendering_mode, &rendering_mode_text },
6199 { &setup.vsync_mode, execSetupChooseVsyncMode },
6200 { &setup.vsync_mode, &vsync_mode_text },
6202 { &setup.graphics_set, execSetupChooseGraphics },
6203 { &setup.graphics_set, &graphics_set_name },
6205 { &setup.sounds_set, execSetupChooseSounds },
6206 { &setup.sounds_set, &sounds_set_name },
6208 { &setup.music_set, execSetupChooseMusic },
6209 { &setup.music_set, &music_set_name },
6211 { &setup.volume_simple, execSetupChooseVolumeSimple },
6212 { &setup.volume_simple, &volume_simple_text },
6214 { &setup.volume_loops, execSetupChooseVolumeLoops },
6215 { &setup.volume_loops, &volume_loops_text },
6217 { &setup.volume_music, execSetupChooseVolumeMusic },
6218 { &setup.volume_music, &volume_music_text },
6220 { &setup.touch.control_type, execSetupChooseTouchControls },
6221 { &setup.touch.control_type, &touch_controls_text },
6223 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6224 { &setup.touch.move_distance, &move_distance_text },
6226 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6227 { &setup.touch.drop_distance, &drop_distance_text },
6229 { &setup.touch.transparency, execSetupChooseTransparency },
6230 { &setup.touch.transparency, &transparency_text },
6232 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6233 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6235 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6236 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6238 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6239 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6241 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6242 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6244 { &setup.internal.menu_game, execSetupGame },
6245 { &setup.internal.menu_engines, execSetupEngines },
6246 { &setup.internal.menu_editor, execSetupEditor },
6247 { &setup.internal.menu_graphics, execSetupGraphics },
6248 { &setup.internal.menu_sound, execSetupSound },
6249 { &setup.internal.menu_artwork, execSetupArtwork },
6250 { &setup.internal.menu_input, execSetupInput },
6251 { &setup.internal.menu_touch, execSetupTouch },
6252 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6253 { &setup.internal.menu_exit, execExitSetup },
6254 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6259 void setHideRelatedSetupEntries(void)
6263 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6264 if (hideSetupEntry(hide_related_entry_list[i].value))
6265 setHideSetupEntry(hide_related_entry_list[i].related_value);
6268 static struct TokenInfo setup_info_main[] =
6270 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6271 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6272 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6273 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6274 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6275 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6276 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6277 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6278 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6279 { TYPE_EMPTY, NULL, "" },
6280 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6281 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6286 static struct TokenInfo setup_info_game[] =
6288 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6289 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6290 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6291 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6292 { TYPE_STRING, &network_server_text, "" },
6293 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6294 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6295 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6296 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6297 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6298 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6299 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6300 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6301 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6302 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6303 { TYPE_STRING, &game_speed_text, "" },
6304 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6306 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6307 { TYPE_STRING, &scroll_delay_text, "" },
6309 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6310 { TYPE_STRING, &snapshot_mode_text, "" },
6311 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6312 { TYPE_EMPTY, NULL, "" },
6313 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6318 static struct TokenInfo setup_info_engines[] =
6320 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6321 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6322 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6323 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6324 { TYPE_EMPTY, NULL, "" },
6325 { TYPE_HEADLINE, NULL, "Supaplex" },
6326 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6327 { TYPE_EMPTY, NULL, "" },
6328 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6333 static struct TokenInfo setup_info_editor[] =
6336 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6337 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6338 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6339 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6340 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6341 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6342 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6343 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6344 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6345 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6347 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6348 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6350 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6352 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6353 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6354 { TYPE_EMPTY, NULL, "" },
6356 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6357 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6358 { TYPE_EMPTY, NULL, "" },
6360 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6361 { TYPE_EMPTY, NULL, "" },
6362 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6367 static struct TokenInfo setup_info_graphics[] =
6369 #if !defined(PLATFORM_ANDROID)
6370 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6371 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6372 { TYPE_STRING, &window_size_text, "" },
6373 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6374 { TYPE_STRING, &scaling_type_text, "" },
6375 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6376 { TYPE_STRING, &rendering_mode_text, "" },
6379 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6380 { TYPE_STRING, &scroll_delay_text, "" },
6382 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6383 { TYPE_STRING, &vsync_mode_text, "" },
6384 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6385 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6386 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6387 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6388 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6389 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6390 { TYPE_EMPTY, NULL, "" },
6391 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6396 static struct TokenInfo setup_info_sound[] =
6398 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6399 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6400 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6401 { TYPE_EMPTY, NULL, "" },
6402 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6403 { TYPE_STRING, &volume_simple_text, "" },
6404 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6405 { TYPE_STRING, &volume_loops_text, "" },
6406 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6407 { TYPE_STRING, &volume_music_text, "" },
6408 { TYPE_EMPTY, NULL, "" },
6409 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6414 static struct TokenInfo setup_info_artwork[] =
6416 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6417 { TYPE_STRING, &graphics_set_name, "" },
6418 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6419 { TYPE_STRING, &sounds_set_name, "" },
6420 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6421 { TYPE_STRING, &music_set_name, "" },
6422 { TYPE_EMPTY, NULL, "" },
6423 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6424 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6425 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6426 { TYPE_EMPTY, NULL, "" },
6427 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6432 static struct TokenInfo setup_info_input[] =
6434 { TYPE_SWITCH, NULL, "Player:" },
6435 { TYPE_SWITCH, NULL, "Device:" },
6436 { TYPE_SWITCH, NULL, "" },
6437 { TYPE_SKIPPABLE, NULL, "" },
6438 { TYPE_EMPTY, NULL, "" },
6439 { TYPE_EMPTY, NULL, "" },
6440 { TYPE_EMPTY, NULL, "" },
6441 { TYPE_EMPTY, NULL, "" },
6442 { TYPE_EMPTY, NULL, "" },
6443 { TYPE_EMPTY, NULL, "" },
6444 { TYPE_EMPTY, NULL, "" },
6445 { TYPE_EMPTY, NULL, "" },
6446 { TYPE_SKIPPABLE, NULL, "" },
6447 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6452 static struct TokenInfo setup_info_touch[] =
6454 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6455 { TYPE_STRING, &touch_controls_text, "" },
6456 { TYPE_EMPTY, NULL, "" },
6457 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6462 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6464 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6465 { TYPE_STRING, &touch_controls_text, "" },
6466 { TYPE_EMPTY, NULL, "" },
6467 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6468 { TYPE_STRING, &grid_size_text[0][0], "" },
6469 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6470 { TYPE_STRING, &grid_size_text[0][1], "" },
6471 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6472 { TYPE_STRING, &transparency_text, "" },
6473 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6474 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6475 { TYPE_EMPTY, NULL, "" },
6476 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6477 { TYPE_EMPTY, NULL, "" },
6478 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6483 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6485 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6486 { TYPE_STRING, &touch_controls_text, "" },
6487 { TYPE_EMPTY, NULL, "" },
6488 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6489 { TYPE_STRING, &grid_size_text[1][0], "" },
6490 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6491 { TYPE_STRING, &grid_size_text[1][1], "" },
6492 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6493 { TYPE_STRING, &transparency_text, "" },
6494 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6495 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6496 { TYPE_EMPTY, NULL, "" },
6497 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6498 { TYPE_EMPTY, NULL, "" },
6499 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6504 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6506 setup_info_touch_virtual_buttons_0,
6507 setup_info_touch_virtual_buttons_1
6510 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6512 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6513 { TYPE_STRING, &touch_controls_text, "" },
6514 { TYPE_EMPTY, NULL, "" },
6515 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6516 { TYPE_STRING, &move_distance_text, "" },
6517 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6518 { TYPE_STRING, &drop_distance_text, "" },
6519 { TYPE_EMPTY, NULL, "" },
6520 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6525 static struct TokenInfo setup_info_shortcuts[] =
6527 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6528 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6529 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6530 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6531 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6532 { TYPE_EMPTY, NULL, "" },
6533 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6538 static struct TokenInfo setup_info_shortcuts_1[] =
6540 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6541 { TYPE_KEY, &setup.shortcut.save_game, "" },
6542 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6543 { TYPE_KEY, &setup.shortcut.load_game, "" },
6544 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6545 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6546 { TYPE_EMPTY, NULL, "" },
6547 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6548 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6549 { TYPE_EMPTY, NULL, "" },
6550 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6555 static struct TokenInfo setup_info_shortcuts_2[] =
6557 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6558 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6559 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6560 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6561 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6562 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6563 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6564 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6565 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6566 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6567 { TYPE_EMPTY, NULL, "" },
6568 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6573 static struct TokenInfo setup_info_shortcuts_3[] =
6575 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6576 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6577 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6578 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6579 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6580 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6581 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6582 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6583 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6584 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6585 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6586 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6587 { TYPE_EMPTY, NULL, "" },
6588 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6593 static struct TokenInfo setup_info_shortcuts_4[] =
6595 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6596 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6597 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6598 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6599 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6600 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6601 { TYPE_EMPTY, NULL, "" },
6602 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6607 static struct TokenInfo setup_info_shortcuts_5[] =
6609 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6610 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6611 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6612 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6613 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6614 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6615 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6616 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6617 { TYPE_EMPTY, NULL, "" },
6618 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6623 static Key getSetupKey(void)
6625 Key key = KSYM_UNDEFINED;
6626 boolean got_key_event = FALSE;
6628 while (!got_key_event)
6632 if (NextValidEvent(&event))
6636 case EVENT_KEYPRESS:
6638 key = GetEventKey((KeyEvent *)&event, TRUE);
6640 // press 'Escape' or 'Enter' to keep the existing key binding
6641 if (key == KSYM_Escape || key == KSYM_Return)
6642 key = KSYM_UNDEFINED; // keep old value
6644 got_key_event = TRUE;
6648 case EVENT_KEYRELEASE:
6649 key_joystick_mapping = 0;
6653 HandleOtherEvents(&event);
6664 static int getSetupValueFont(int type, void *value)
6666 if (type & TYPE_GHOSTED)
6667 return FONT_OPTION_OFF;
6668 else if (type & TYPE_KEY)
6669 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6670 else if (type & TYPE_STRING)
6671 return FONT_VALUE_2;
6672 else if (type & TYPE_ECS_AGA)
6673 return FONT_VALUE_1;
6674 else if (type & TYPE_BOOLEAN_STYLE)
6675 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6676 else if (type & TYPE_YES_NO_AUTO)
6677 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6678 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6679 else if (type & TYPE_PLAYER)
6680 return FONT_VALUE_1;
6682 return FONT_VALUE_1;
6685 static int getSetupValueFontNarrow(int type, int font_nr)
6687 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6688 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6689 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6693 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6695 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6696 struct TokenInfo *si = &setup_info[si_pos];
6697 boolean font_draw_xoffset_modified = FALSE;
6698 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6699 int font_draw_xoffset_old = -1;
6700 int xoffset = (scrollbar_needed ? -1 : 0);
6701 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6702 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6703 int xpos = menu_screen_value_xpos;
6704 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6705 int startx = mSX + xpos * 32;
6706 int starty = mSY + ypos * 32;
6707 int type = si->type;
6708 void *value = si->value;
6709 char *value_string = getSetupValue(type, value);
6710 int font_nr_default = getSetupValueFont(type, value);
6711 int font_width_default = getFontWidth(font_nr_default);
6712 int font_nr = font_nr_default;
6715 if (value_string == NULL)
6718 if (type & TYPE_KEY)
6720 xpos = MENU_SCREEN_START_XPOS;
6722 if (type & TYPE_QUERY)
6723 value_string = "<press key>";
6725 else if (type & TYPE_STRING)
6727 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
6729 xpos = MENU_SCREEN_START_XPOS;
6731 if (strlen(value_string) > max_value_len)
6732 value_string[max_value_len] = '\0';
6734 else if (type & TYPE_YES_NO_AUTO)
6736 xpos = menu_screen_value_xpos - 1;
6738 else if (type & TYPE_PLAYER)
6740 int displayed_player_nr = *(int *)value + 1;
6742 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6745 startx = mSX + xpos * 32;
6746 starty = mSY + ypos * 32;
6748 // special check if right-side setup values moved left due to scrollbar
6749 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6751 int max_menu_text_length = 26; // maximum text length for classic menu
6752 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6753 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6754 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6755 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6756 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6758 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6761 startx = mSX + xpos * 32;
6763 font_nr = getSetupValueFontNarrow(type, font_nr);
6767 // downward compatibility correction for Juergen Bonhagen's menu settings
6768 if (setup_mode != SETUP_MODE_INPUT)
6770 int max_menu_text_length_big = (menu_screen_value_xpos -
6771 MENU_SCREEN_START_XPOS);
6772 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6773 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
6774 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6775 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6776 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6777 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6778 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6779 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6780 boolean correct_font_draw_xoffset = FALSE;
6782 if (xpos == MENU_SCREEN_START_XPOS &&
6783 startx + font1_xoffset < text_startx + text_font_xoffset)
6784 correct_font_draw_xoffset = TRUE;
6786 if (xpos == menu_screen_value_xpos &&
6787 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6788 correct_font_draw_xoffset = TRUE;
6790 // check if setup value would overlap with setup text when printed
6791 // (this can happen for extreme/wrong values for font draw offset)
6792 if (correct_font_draw_xoffset)
6794 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6795 font_draw_xoffset_modified = TRUE;
6797 if (type & TYPE_KEY)
6798 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6799 else if (!(type & TYPE_STRING))
6800 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6801 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6805 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6806 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6808 DrawText(startx, starty, value_string, font_nr);
6810 if (type & TYPE_PLAYER)
6812 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
6813 int player_nr = *(int *)value;
6814 int xoff = font->draw_xoffset + getFontWidth(font_nr);
6815 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
6816 int startx2 = startx + xoff;
6817 int starty2 = starty + yoff;
6819 if (DrawingOnBackground(startx2, starty2))
6820 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
6822 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
6823 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6826 if (font_draw_xoffset_modified)
6827 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6830 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6832 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6833 struct TokenInfo *si = &setup_info[si_pos];
6835 if (si->type & TYPE_BOOLEAN_STYLE)
6837 *(boolean *)si->value ^= TRUE;
6839 else if (si->type & TYPE_YES_NO_AUTO)
6843 (*(int *)si->value == AUTO ? TRUE :
6844 *(int *)si->value == TRUE ? FALSE : AUTO) :
6845 (*(int *)si->value == TRUE ? AUTO :
6846 *(int *)si->value == AUTO ? FALSE : TRUE));
6848 else if (si->type & TYPE_KEY)
6852 si->type |= TYPE_QUERY;
6853 drawSetupValue(screen_pos, setup_info_pos_raw);
6854 si->type &= ~TYPE_QUERY;
6856 key = getSetupKey();
6857 if (key != KSYM_UNDEFINED)
6858 *(Key *)si->value = key;
6860 else if (si->type & TYPE_PLAYER)
6862 int player_nr = *(int *)si->value;
6867 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6869 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6872 drawSetupValue(screen_pos, setup_info_pos_raw);
6874 // fullscreen state may have changed at this point
6875 if (si->value == &setup.fullscreen)
6876 ToggleFullscreenIfNeeded();
6878 // network mode may have changed at this point
6879 if (si->value == &setup.network_mode)
6880 ToggleNetworkModeIfNeeded();
6882 // game speed list may have changed at this point
6883 if (si->value == &setup.game_speed_extended)
6884 ToggleGameSpeedsListIfNeeded();
6887 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6889 static struct TokenInfo *setup_info_final = NULL;
6894 // determine maximum list size of target list
6895 while (setup_info_orig[list_size++].type != 0);
6897 // free, allocate and clear memory for target list
6898 checked_free(setup_info_final);
6899 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6901 // copy setup info list without setup entries marked as hidden
6902 for (i = 0; setup_info_orig[i].type != 0; i++)
6904 // skip setup entries configured to be hidden
6905 if (hideSetupEntry(setup_info_orig[i].value))
6908 // skip skippable setup entries if screen is lower than usual
6909 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6910 setup_info_orig[i].type == TYPE_SKIPPABLE)
6913 setup_info_final[list_pos++] = setup_info_orig[i];
6916 return setup_info_final;
6919 static void DrawSetupScreen_Generic(void)
6921 int fade_mask = REDRAW_FIELD;
6922 boolean redraw_all = FALSE;
6923 char *title_string = NULL;
6927 fade_mask = REDRAW_ALL;
6930 FadeMenuSoundsAndMusic();
6932 FreeScreenGadgets();
6933 CreateScreenGadgets();
6935 if (redraw_mask & REDRAW_ALL)
6940 // needed if different viewport properties defined for setup screen
6941 ChangeViewportPropertiesIfNeeded();
6943 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6947 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6949 if (setup_mode == SETUP_MODE_MAIN)
6951 setup_info = setup_info_main;
6952 title_string = STR_SETUP_MAIN;
6954 else if (setup_mode == SETUP_MODE_GAME)
6956 setup_info = setup_info_game;
6957 title_string = STR_SETUP_GAME;
6959 else if (setup_mode == SETUP_MODE_ENGINES)
6961 setup_info = setup_info_engines;
6962 title_string = STR_SETUP_ENGINES;
6964 else if (setup_mode == SETUP_MODE_EDITOR)
6966 setup_info = setup_info_editor;
6967 title_string = STR_SETUP_EDITOR;
6969 else if (setup_mode == SETUP_MODE_GRAPHICS)
6971 setup_info = setup_info_graphics;
6972 title_string = STR_SETUP_GRAPHICS;
6974 else if (setup_mode == SETUP_MODE_SOUND)
6976 setup_info = setup_info_sound;
6977 title_string = STR_SETUP_SOUND;
6979 else if (setup_mode == SETUP_MODE_ARTWORK)
6981 setup_info = setup_info_artwork;
6982 title_string = STR_SETUP_ARTWORK;
6984 else if (setup_mode == SETUP_MODE_TOUCH)
6986 setup_info = setup_info_touch;
6987 title_string = STR_SETUP_TOUCH;
6989 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6990 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6991 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6992 setup_info = setup_info_touch_wipe_gestures;
6994 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6996 setup_info = setup_info_shortcuts;
6997 title_string = STR_SETUP_SHORTCUTS;
6999 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
7001 setup_info = setup_info_shortcuts_1;
7002 title_string = STR_SETUP_SHORTCUTS;
7004 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
7006 setup_info = setup_info_shortcuts_2;
7007 title_string = STR_SETUP_SHORTCUTS;
7009 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
7011 setup_info = setup_info_shortcuts_3;
7012 title_string = STR_SETUP_SHORTCUTS;
7014 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7016 setup_info = setup_info_shortcuts_4;
7017 title_string = STR_SETUP_SHORTCUTS;
7019 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7021 setup_info = setup_info_shortcuts_5;
7022 title_string = STR_SETUP_SHORTCUTS;
7025 // use modified setup info without setup entries marked as hidden
7026 setup_info = getSetupInfoFinal(setup_info);
7028 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7030 // determine maximal number of setup entries that can be displayed on screen
7032 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7035 // determine maximal number of setup entries available for this setup screen
7037 for (i = 0; setup_info[i].type != 0; i++)
7040 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7042 MapScreenGadgets(max_setup_info);
7045 redraw_mask = fade_mask = REDRAW_ALL;
7047 DrawMaskedBorder(fade_mask);
7052 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7054 menu_info = setup_info;
7056 HandleMenuScreen(mx, my, dx, dy, button,
7057 setup_mode, num_setup_info, max_setup_info);
7060 static void DrawSetupScreen_Input(void)
7064 FadeOut(REDRAW_FIELD);
7068 setup_info = getSetupInfoFinal(setup_info_input);
7070 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7072 for (i = 0; setup_info[i].type != 0; i++)
7074 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7075 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7076 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7077 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7078 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7079 initCursor(i, IMG_MENU_BUTTON);
7081 DrawCursorAndText_Setup(i, -1, FALSE);
7084 // create gadgets for setup input menu screen
7085 FreeScreenGadgets();
7086 CreateScreenGadgets();
7088 // map gadgets for setup input menu screen
7089 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7091 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7093 FadeIn(REDRAW_FIELD);
7096 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7098 if (device_name == NULL)
7101 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7104 if (strlen(device_name) > 1)
7106 char c1 = device_name[strlen(device_name) - 1];
7107 char c2 = device_name[strlen(device_name) - 2];
7109 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7110 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7113 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7114 strlen(device_name));
7117 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7120 static struct SetupKeyboardInfo custom_key;
7127 { &custom_key.left, "Axis/Pad Left" },
7128 { &custom_key.right, "Axis/Pad Right" },
7129 { &custom_key.up, "Axis/Pad Up" },
7130 { &custom_key.down, "Axis/Pad Down" },
7131 { &custom_key.snap, "Button 1/A/X" },
7132 { &custom_key.drop, "Button 2/B/Y" }
7134 static char *joystick_name[MAX_PLAYERS] =
7141 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7142 int font_nr_info = FONT_MENU_1;
7143 int font_nr_name = FONT_VALUE_OLD;
7144 int font_nr_on = FONT_VALUE_1;
7145 int font_nr_off = FONT_VALUE_OLD;
7148 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7150 font_nr_info = FONT_MENU_2;
7151 font_nr_on = FONT_VALUE_NARROW;
7152 font_nr_off = FONT_VALUE_OLD_NARROW;
7155 custom_key = setup.input[player_nr].key;
7157 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7158 FONT_INPUT_1_ACTIVE);
7160 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7162 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7163 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7165 if (setup.input[player_nr].use_joystick)
7167 char *device_name = setup.input[player_nr].joy.device_name;
7168 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7169 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7170 char *text = joystick_name[joystick_nr];
7171 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7173 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7174 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7178 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7179 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7182 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7183 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7187 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7188 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7189 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7190 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7192 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7193 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7194 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7195 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7196 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7197 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7199 for (i = 0; i < 6; i++)
7201 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7203 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7205 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7206 (setup.input[player_nr].use_joystick ?
7208 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7212 static int input_player_nr = 0;
7214 static void HandleSetupScreen_Input_Player(int step, int direction)
7216 int old_player_nr = input_player_nr;
7219 new_player_nr = old_player_nr + step * direction;
7220 if (new_player_nr < 0)
7222 if (new_player_nr > MAX_PLAYERS - 1)
7223 new_player_nr = MAX_PLAYERS - 1;
7225 if (new_player_nr != old_player_nr)
7227 input_player_nr = new_player_nr;
7229 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7233 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7235 static int choice = 0;
7238 int pos_start = SETUPINPUT_SCREEN_POS_START;
7239 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7240 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7241 int pos_end = SETUPINPUT_SCREEN_POS_END;
7243 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7247 for (i = 0; setup_info_input[i].type != 0; i++)
7249 // adjust menu structure according to skipped setup entries
7250 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7258 if (button == MB_MENU_INITIALIZE)
7260 // input setup menu may have changed size due to graphics configuration
7261 if (choice >= pos_empty1)
7264 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7266 DrawCursorAndText_Setup(choice, -1, TRUE);
7270 else if (button == MB_MENU_LEAVE)
7272 setup_mode = SETUP_MODE_MAIN;
7279 if (mx || my) // mouse input
7281 x = (mx - mSX) / 32;
7282 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7284 else if (dx || dy) // keyboard input
7286 if (dx && choice == 0)
7287 x = (dx < 0 ? 10 : 12);
7288 else if ((dx && choice == 1) ||
7289 (dx == -1 && choice == pos_end))
7290 button = MB_MENU_CHOICE;
7294 if (y >= pos_empty1 && y <= pos_empty2)
7295 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7298 if (y == 0 && dx != 0 && button)
7300 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7302 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7303 y >= pos_start && y <= pos_end &&
7304 !(y >= pos_empty1 && y <= pos_empty2))
7310 DrawCursorAndText_Setup(choice, -1, FALSE);
7311 DrawCursorAndText_Setup(y, -1, TRUE);
7313 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7322 char *device_name = setup.input[input_player_nr].joy.device_name;
7324 if (!setup.input[input_player_nr].use_joystick)
7326 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7328 setJoystickDeviceToNr(device_name, new_device_nr);
7329 setup.input[input_player_nr].use_joystick = TRUE;
7333 int device_nr = getJoystickNrFromDeviceName(device_name);
7334 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7336 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7337 setup.input[input_player_nr].use_joystick = FALSE;
7339 setJoystickDeviceToNr(device_name, new_device_nr);
7342 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7346 if (setup.input[input_player_nr].use_joystick)
7347 ConfigureJoystick(input_player_nr);
7349 CustomizeKeyboard(input_player_nr);
7351 else if (y == pos_end)
7357 setup_mode = SETUP_MODE_MAIN;
7364 static boolean CustomizeKeyboardMain(int player_nr)
7368 boolean finished = FALSE;
7369 static struct SetupKeyboardInfo custom_key;
7374 } customize_step[] =
7376 { &custom_key.left, "Move Left" },
7377 { &custom_key.right, "Move Right" },
7378 { &custom_key.up, "Move Up" },
7379 { &custom_key.down, "Move Down" },
7380 { &custom_key.snap, "Snap Field" },
7381 { &custom_key.drop, "Drop Element" }
7383 int font_nr_old = FONT_VALUE_OLD;
7384 int font_nr_new = FONT_VALUE_1;
7385 boolean success = FALSE;
7387 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7389 font_nr_old = FONT_VALUE_OLD_NARROW;
7390 font_nr_new = FONT_VALUE_NARROW;
7393 // read existing key bindings from player setup
7394 custom_key = setup.input[player_nr].key;
7397 FadeOut(REDRAW_FIELD);
7401 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7404 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7405 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7406 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7407 "Key:", FONT_INPUT_1_ACTIVE);
7408 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7409 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7411 FadeIn(REDRAW_FIELD);
7417 if (NextValidEvent(&event))
7421 case EVENT_KEYPRESS:
7423 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7425 // press 'Escape' to abort and keep the old key bindings
7426 if (key == KSYM_Escape)
7428 FadeSkipNextFadeIn();
7435 // press 'Enter' to keep the existing key binding
7436 if (key == KSYM_Return)
7437 key = *customize_step[step_nr].key;
7439 // check if key already used
7440 for (i = 0; i < step_nr; i++)
7441 if (*customize_step[i].key == key)
7446 // got new key binding
7447 *customize_step[step_nr].key = key;
7448 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7450 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7451 getKeyNameFromKey(key), font_nr_new);
7454 // un-highlight last query
7455 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7456 customize_step[step_nr - 1].text, FONT_MENU_1);
7457 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7458 "Key:", FONT_MENU_1);
7460 // all keys configured
7469 // query next key binding
7470 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7471 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7472 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7473 "Key:", FONT_INPUT_1_ACTIVE);
7474 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7475 getKeyNameFromKey(*customize_step[step_nr].key),
7480 case EVENT_KEYRELEASE:
7481 key_joystick_mapping = 0;
7485 HandleOtherEvents(&event);
7493 // write new key bindings back to player setup, if successfully finished
7495 setup.input[player_nr].key = custom_key;
7500 void CustomizeKeyboard(int player_nr)
7502 boolean success = CustomizeKeyboardMain(player_nr);
7506 int font_nr = FONT_TITLE_1;
7507 int font_height = getFontHeight(font_nr);
7508 int ypos1 = SYSIZE / 2 - font_height * 2;
7509 int ypos2 = SYSIZE / 2 - font_height * 1;
7510 unsigned int wait_frame_delay = 0;
7511 unsigned int wait_frame_delay_value = 2000;
7513 ResetDelayCounter(&wait_frame_delay);
7517 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7518 DrawTextSCentered(ypos2, font_nr, "configured!");
7520 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7526 DrawSetupScreen_Input();
7529 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7531 #define MARKER_BUTTON 1
7532 #define MARKER_AXIS_X 2
7533 #define MARKER_AXIS_Y 3
7535 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7537 static boolean bitmaps_initialized = FALSE;
7538 boolean screen_initialized = FALSE;
7539 static Bitmap *controller, *button, *axis_x, *axis_y;
7541 boolean success = TRUE;
7542 boolean done = FALSE, next = FALSE;
7544 int alpha = 200, alpha_step = -1;
7545 int alpha_ticks = 0;
7546 char mapping[4096], temp[4096];
7547 int font_name = MENU_SETUP_FONT_TITLE;
7548 int font_info = MENU_SETUP_FONT_TEXT;
7549 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7550 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7551 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7552 int ystep_name = getMenuTextStep(spacing_name, font_name);
7553 int ystep_line = getMenuTextStep(spacing_line, font_info);
7554 int ystep_para = getMenuTextStep(spacing_para, font_info);
7562 int axis, button, hat, hat_value;
7565 *step, *prev_step, steps[] =
7567 { 356, 155, MARKER_BUTTON, "a", },
7568 { 396, 122, MARKER_BUTTON, "b", },
7569 { 320, 125, MARKER_BUTTON, "x", },
7570 { 358, 95, MARKER_BUTTON, "y", },
7571 { 162, 125, MARKER_BUTTON, "back", },
7572 { 216, 125, MARKER_BUTTON, "guide", },
7573 { 271, 125, MARKER_BUTTON, "start", },
7574 { 110, 200, MARKER_BUTTON, "dpleft", },
7575 { 146, 228, MARKER_BUTTON, "dpdown", },
7576 { 178, 200, MARKER_BUTTON, "dpright", },
7577 { 146, 172, MARKER_BUTTON, "dpup", },
7578 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7579 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7580 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7581 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7582 { 73, 141, MARKER_BUTTON, "leftstick", },
7583 { 282, 210, MARKER_BUTTON, "rightstick", },
7584 { 73, 141, MARKER_AXIS_X, "leftx", },
7585 { 73, 141, MARKER_AXIS_Y, "lefty", },
7586 { 282, 210, MARKER_AXIS_X, "rightx", },
7587 { 282, 210, MARKER_AXIS_Y, "righty", },
7590 unsigned int event_frame_delay = 0;
7591 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7593 ResetDelayCounter(&event_frame_delay);
7595 if (!bitmaps_initialized)
7597 controller = LoadCustomImage("joystick/controller.png");
7598 button = LoadCustomImage("joystick/button.png");
7599 axis_x = LoadCustomImage("joystick/axis_x.png");
7600 axis_y = LoadCustomImage("joystick/axis_y.png");
7602 bitmaps_initialized = TRUE;
7605 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7608 // print info about the joystick we are watching
7609 Debug("joystick", "watching joystick %d: (%s)",
7610 SDL_JoystickInstanceID(joystick), name);
7611 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
7612 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7613 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7616 // initialize mapping with GUID and name
7617 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7619 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7620 temp, name, SDL_GetPlatform());
7622 // loop through all steps (buttons and axes), getting joystick events
7623 for (i = 0; i < SDL_arraysize(steps) && !done;)
7625 Bitmap *marker = button; // initialize with reliable default value
7628 strcpy(step->mapping, mapping);
7632 step->hat_value = -1;
7634 marker = (step->marker == MARKER_BUTTON ? button :
7635 step->marker == MARKER_AXIS_X ? axis_x :
7636 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7640 while (!done && !next)
7642 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7643 alpha_ticks = SDL_GetTicks();
7650 else if (alpha < 128)
7656 int controller_x = SX + (SXSIZE - controller->width) / 2;
7657 int controller_y = SY + ystep_line;
7659 int marker_x = controller_x + step->x;
7660 int marker_y = controller_y + step->y;
7662 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7663 int ystart2 = ystart1 + ystep_name + ystep_line;
7667 DrawTextSCentered(ystart1, font_name, name);
7669 DrawTextSCentered(ystart2, font_info,
7670 "Press buttons and move axes on");
7671 ystart2 += ystep_line;
7672 DrawTextSCentered(ystart2, font_info,
7673 "your controller when indicated.");
7674 ystart2 += ystep_line;
7675 DrawTextSCentered(ystart2, font_info,
7676 "(Your controller may look different.)");
7677 ystart2 += ystep_para;
7679 #if defined(PLATFORM_ANDROID)
7680 DrawTextSCentered(ystart2, font_info,
7681 "To correct a mistake,");
7682 ystart2 += ystep_line;
7683 DrawTextSCentered(ystart2, font_info,
7684 "press the 'back' button.");
7685 ystart2 += ystep_line;
7686 DrawTextSCentered(ystart2, font_info,
7687 "To skip a button or axis,");
7688 ystart2 += ystep_line;
7689 DrawTextSCentered(ystart2, font_info,
7690 "press the 'menu' button.");
7692 DrawTextSCentered(ystart2, font_info,
7693 "To correct a mistake,");
7694 ystart2 += ystep_line;
7695 DrawTextSCentered(ystart2, font_info,
7696 "press the 'backspace' key.");
7697 ystart2 += ystep_line;
7698 DrawTextSCentered(ystart2, font_info,
7699 "To skip a button or axis,");
7700 ystart2 += ystep_line;
7701 DrawTextSCentered(ystart2, font_info,
7702 "press the 'return' key.");
7703 ystart2 += ystep_line;
7704 DrawTextSCentered(ystart2, font_info,
7705 "To exit, press the 'escape' key.");
7708 BlitBitmapMasked(controller, drawto, 0, 0,
7709 controller->width, controller->height,
7710 controller_x, controller_y);
7712 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7713 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7715 BlitBitmapMasked(marker, drawto, 0, 0,
7716 marker->width, marker->height,
7717 marker_x, marker_y);
7719 if (!screen_initialized)
7720 FadeIn(REDRAW_FIELD);
7724 screen_initialized = TRUE;
7726 while (NextValidEvent(&event))
7730 case SDL_JOYAXISMOTION:
7731 if (event.jaxis.value > 20000 ||
7732 event.jaxis.value < -20000)
7734 for (j = 0; j < i; j++)
7735 if (steps[j].axis == event.jaxis.axis)
7740 if (step->marker != MARKER_AXIS_X &&
7741 step->marker != MARKER_AXIS_Y)
7744 step->axis = event.jaxis.axis;
7745 strcat(mapping, step->field);
7746 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7747 strcat(mapping, temp);
7755 case SDL_JOYHATMOTION:
7756 // ignore centering; we're probably just coming back
7757 // to the center from the previous item we set
7758 if (event.jhat.value == SDL_HAT_CENTERED)
7761 for (j = 0; j < i; j++)
7762 if (steps[j].hat == event.jhat.hat &&
7763 steps[j].hat_value == event.jhat.value)
7768 step->hat = event.jhat.hat;
7769 step->hat_value = event.jhat.value;
7770 strcat(mapping, step->field);
7771 snprintf(temp, sizeof(temp), ":h%u.%u,",
7772 event.jhat.hat, event.jhat.value );
7773 strcat(mapping, temp);
7780 case SDL_JOYBALLMOTION:
7783 case SDL_JOYBUTTONUP:
7784 for (j = 0; j < i; j++)
7785 if (steps[j].button == event.jbutton.button)
7790 step->button = event.jbutton.button;
7791 strcat(mapping, step->field);
7792 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7793 strcat(mapping, temp);
7800 case SDL_FINGERDOWN:
7801 case SDL_MOUSEBUTTONDOWN:
7809 if (event.key.keysym.sym == KSYM_BackSpace ||
7810 event.key.keysym.sym == KSYM_Back)
7822 prev_step = &steps[i - 1];
7823 strcpy(mapping, prev_step->mapping);
7830 if (event.key.keysym.sym == KSYM_space ||
7831 event.key.keysym.sym == KSYM_Return ||
7832 event.key.keysym.sym == KSYM_Menu)
7841 if (event.key.keysym.sym == KSYM_Escape)
7851 program.exit_function(0);
7858 // do not handle events for longer than standard frame delay period
7859 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7868 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
7871 // activate mapping for this game
7872 SDL_GameControllerAddMapping(mapping);
7874 // save mapping to personal mappings
7875 SaveSetup_AddGameControllerMapping(mapping);
7878 // wait until the last pending event was removed from event queue
7879 while (NextValidEvent(&event));
7884 static int ConfigureJoystickMain(int player_nr)
7886 char *device_name = setup.input[player_nr].joy.device_name;
7887 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7888 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7889 int success = FALSE;
7892 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7893 return JOYSTICK_NOT_AVAILABLE;
7895 if (!joystick_active || !setup.input[player_nr].use_joystick)
7896 return JOYSTICK_NOT_AVAILABLE;
7899 FadeOut(REDRAW_FIELD);
7901 // close all joystick devices (potentially opened as game controllers)
7902 for (i = 0; i < SDL_NumJoysticks(); i++)
7903 SDLCloseJoystick(i);
7905 // open joystick device as plain joystick to configure as game controller
7906 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7908 // as the joystick was successfully opened before, this should not happen
7909 if (joystick == NULL)
7912 // create new game controller mapping (buttons and axes) for joystick device
7913 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7915 // close joystick (and maybe re-open as configured game controller later)
7916 SDL_JoystickClose(joystick);
7918 // re-open all joystick devices (potentially as game controllers)
7919 for (i = 0; i < SDL_NumJoysticks(); i++)
7922 // clear all joystick input actions for all joystick devices
7923 SDLClearJoystickState();
7925 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7928 void ConfigureJoystick(int player_nr)
7930 boolean state = ConfigureJoystickMain(player_nr);
7932 if (state != JOYSTICK_NOT_CONFIGURED)
7934 boolean success = (state == JOYSTICK_CONFIGURED);
7935 char message1[MAX_OUTPUT_LINESIZE + 1];
7936 char *message2 = (success ? "configured!" : "not available!");
7937 char *device_name = setup.input[player_nr].joy.device_name;
7938 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7939 int font_nr = FONT_TITLE_1;
7940 int font_height = getFontHeight(font_nr);
7941 int ypos1 = SYSIZE / 2 - font_height * 2;
7942 int ypos2 = SYSIZE / 2 - font_height * 1;
7943 unsigned int wait_frame_delay = 0;
7944 unsigned int wait_frame_delay_value = 2000;
7946 ResetDelayCounter(&wait_frame_delay);
7950 sprintf(message1, "Joystick %d", nr);
7952 DrawTextSCentered(ypos1, font_nr, message1);
7953 DrawTextSCentered(ypos2, font_nr, message2);
7955 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7961 DrawSetupScreen_Input();
7964 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
7966 if (y < video.screen_height / 3)
7968 // remap touch gadgets to access upper part of the screen
7969 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7970 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7972 else if (y > 2 * video.screen_height / 3)
7974 // remap touch gadgets to access lower part of the screen
7975 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7976 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7980 static boolean ConfigureVirtualButtonsMain(void)
7982 static char *customize_step_text[] =
7991 char grid_button[] =
7993 CHAR_GRID_BUTTON_LEFT,
7994 CHAR_GRID_BUTTON_RIGHT,
7995 CHAR_GRID_BUTTON_UP,
7996 CHAR_GRID_BUTTON_DOWN,
7997 CHAR_GRID_BUTTON_SNAP,
7998 CHAR_GRID_BUTTON_DROP
8007 int font_nr = FONT_INPUT_1_ACTIVE;
8008 int font_height = getFontHeight(font_nr);
8009 int ypos1 = SYSIZE / 2 - font_height * 2;
8010 int ypos2 = SYSIZE / 2 - font_height * 1;
8011 boolean success = FALSE;
8012 boolean finished = FALSE;
8014 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8015 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8016 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8017 boolean set_grid_button = FALSE;
8018 int nr = GRID_ACTIVE_NR();
8021 for (x = 0; x < MAX_GRID_XSIZE; x++)
8022 for (y = 0; y < MAX_GRID_YSIZE; y++)
8023 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8025 overlay.grid_button_highlight = grid_button[step_nr];
8030 FadeOut(REDRAW_FIELD);
8034 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8035 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8036 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8038 FadeIn(REDRAW_FIELD);
8040 SetOverlayShowGrid(TRUE);
8042 // map gadgets for setup touch buttons menu screen
8043 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8049 while (NextValidEvent(&event))
8051 int action = ACTION_NONE;
8053 // ---------- handle events and set the resulting action ----------
8059 UserEvent *user = (UserEvent *)&event;
8060 int id = user->value1;
8062 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8063 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8064 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8065 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8070 case EVENT_KEYPRESS:
8072 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8074 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8075 key == KSYM_BackSpace ||
8076 key == KSYM_Back ? ACTION_BACK :
8077 key == KSYM_Return ||
8079 key == KSYM_space ? ACTION_NEXT :
8084 case EVENT_KEYRELEASE:
8085 key_joystick_mapping = 0;
8088 case EVENT_BUTTONPRESS:
8089 case EVENT_BUTTONRELEASE:
8091 ButtonEvent *button = (ButtonEvent *)&event;
8093 motion_status = FALSE;
8095 if (button->type == EVENT_BUTTONPRESS)
8096 button_status = button->button;
8098 button_status = MB_RELEASED;
8100 if (HandleGadgets(button->x, button->y, button_status))
8102 // do not handle this button event anymore
8106 button->x += video.screen_xoffset;
8107 button->y += video.screen_yoffset;
8109 x = button->x * overlay.grid_xsize / video.screen_width;
8110 y = button->y * overlay.grid_ysize / video.screen_height;
8112 if (button->type == EVENT_BUTTONPRESS)
8115 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8116 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8118 set_grid_button = TRUE;
8121 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8125 case EVENT_MOTIONNOTIFY:
8127 MotionEvent *motion = (MotionEvent *)&event;
8129 motion_status = TRUE;
8131 if (HandleGadgets(motion->x, motion->y, button_status))
8133 // do not handle this button event anymore
8137 motion->x += video.screen_xoffset;
8138 motion->y += video.screen_yoffset;
8140 x = motion->x * overlay.grid_xsize / video.screen_width;
8141 y = motion->y * overlay.grid_ysize / video.screen_height;
8143 set_grid_button = TRUE;
8145 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8149 case SDL_WINDOWEVENT:
8150 HandleWindowEvent((WindowEvent *) &event);
8152 // check if device has been rotated
8153 if (nr != GRID_ACTIVE_NR())
8155 nr = GRID_ACTIVE_NR();
8157 for (x = 0; x < MAX_GRID_XSIZE; x++)
8158 for (y = 0; y < MAX_GRID_YSIZE; y++)
8159 grid_button_old[x][y] = grid_button_tmp[x][y] =
8160 overlay.grid_button[x][y];
8165 case SDL_APP_WILLENTERBACKGROUND:
8166 case SDL_APP_DIDENTERBACKGROUND:
8167 case SDL_APP_WILLENTERFOREGROUND:
8168 case SDL_APP_DIDENTERFOREGROUND:
8169 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8173 HandleOtherEvents(&event);
8177 // ---------- perform action set by handling events ----------
8179 if (action == ACTION_ESCAPE)
8181 // abort and restore the old key bindings
8183 for (x = 0; x < MAX_GRID_XSIZE; x++)
8184 for (y = 0; y < MAX_GRID_YSIZE; y++)
8185 overlay.grid_button[x][y] = grid_button_old[x][y];
8187 FadeSkipNextFadeIn();
8191 else if (action == ACTION_BACK)
8193 // keep the configured key bindings and go to previous page
8199 FadeSkipNextFadeIn();
8204 else if (action == ACTION_NEXT)
8206 // keep the configured key bindings and go to next page
8210 // all virtual buttons configured
8218 if (action != ACTION_NONE && !finished)
8220 for (x = 0; x < MAX_GRID_XSIZE; x++)
8221 for (y = 0; y < MAX_GRID_YSIZE; y++)
8222 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8224 overlay.grid_button_highlight = grid_button[step_nr];
8226 // configure next virtual button
8230 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8231 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8232 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8235 if (set_grid_button)
8237 overlay.grid_button[x][y] =
8238 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8239 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8240 grid_button_tmp[x][y]);
8242 set_grid_button = FALSE;
8249 for (x = 0; x < MAX_GRID_XSIZE; x++)
8250 for (y = 0; y < MAX_GRID_YSIZE; y++)
8251 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8253 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8255 SetOverlayShowGrid(FALSE);
8260 void ConfigureVirtualButtons(void)
8262 boolean success = ConfigureVirtualButtonsMain();
8264 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8265 SCREEN_MASK_TOUCH2);
8269 int font_nr = FONT_TITLE_1;
8270 int font_height = getFontHeight(font_nr);
8271 int ypos1 = SYSIZE / 2 - font_height * 2;
8272 int ypos2 = SYSIZE / 2 - font_height * 1;
8273 unsigned int wait_frame_delay = 0;
8274 unsigned int wait_frame_delay_value = 2000;
8276 ResetDelayCounter(&wait_frame_delay);
8280 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8281 DrawTextSCentered(ypos2, font_nr, "configured!");
8283 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8290 void DrawSetupScreen(void)
8295 if (setup_mode == SETUP_MODE_INPUT)
8296 DrawSetupScreen_Input();
8297 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8298 DrawChooseTree(&game_speed_current);
8299 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8300 DrawChooseTree(&scroll_delay_current);
8301 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8302 DrawChooseTree(&snapshot_mode_current);
8303 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8304 DrawChooseTree(&window_size_current);
8305 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8306 DrawChooseTree(&scaling_type_current);
8307 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8308 DrawChooseTree(&rendering_mode_current);
8309 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8310 DrawChooseTree(&vsync_mode_current);
8311 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8312 DrawChooseTree(&artwork.gfx_current);
8313 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8314 DrawChooseTree(&artwork.snd_current);
8315 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8316 DrawChooseTree(&artwork.mus_current);
8317 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8318 DrawChooseTree(&volume_simple_current);
8319 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8320 DrawChooseTree(&volume_loops_current);
8321 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8322 DrawChooseTree(&volume_music_current);
8323 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8324 DrawChooseTree(&touch_control_current);
8325 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8326 DrawChooseTree(&move_distance_current);
8327 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8328 DrawChooseTree(&drop_distance_current);
8329 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8330 DrawChooseTree(&transparency_current);
8331 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8332 DrawChooseTree(&grid_size_current[0][0]);
8333 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8334 DrawChooseTree(&grid_size_current[0][1]);
8335 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8336 DrawChooseTree(&grid_size_current[1][0]);
8337 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8338 DrawChooseTree(&grid_size_current[1][1]);
8340 DrawSetupScreen_Generic();
8342 PlayMenuSoundsAndMusic();
8345 void RedrawSetupScreenAfterFullscreenToggle(void)
8347 if (setup_mode == SETUP_MODE_GRAPHICS ||
8348 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8350 // update list selection from "setup.window_scaling_percent"
8351 execSetupGraphics_setWindowSizes(TRUE);
8357 void RedrawSetupScreenAfterScreenRotation(int nr)
8361 if (setup_mode == SETUP_MODE_TOUCH)
8363 // update virtual button settings (depending on screen orientation)
8366 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8368 // save already configured virtual buttons
8369 for (x = 0; x < MAX_GRID_XSIZE; x++)
8370 for (y = 0; y < MAX_GRID_YSIZE; y++)
8371 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8375 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8377 if (setup_mode == SETUP_MODE_INPUT)
8378 HandleSetupScreen_Input(mx, my, dx, dy, button);
8379 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8380 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8381 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8382 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8383 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8384 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8385 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8386 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8387 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8388 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8389 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8390 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8391 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8392 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8393 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8394 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8395 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8396 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8397 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8398 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8399 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8400 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8401 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8402 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8403 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8404 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8405 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8406 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8407 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8408 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8409 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8410 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8411 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8412 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8413 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8414 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8415 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8416 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8417 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8418 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8419 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8420 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8422 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8425 void HandleGameActions(void)
8427 if (setup.ask_on_game_over)
8430 if (game.restart_game_message != NULL)
8432 RequestRestartGame(game.restart_game_message);
8437 if (game_status != GAME_MODE_PLAYING)
8440 GameActions(); // main game loop
8442 if (tape.auto_play && !tape.playing)
8443 AutoPlayTapes(); // continue automatically playing next tape
8447 // ---------- new screen button stuff --------------------------------------
8451 int gfx_unpressed, gfx_pressed;
8452 struct MenuPosInfo *pos;
8453 boolean *check_value;
8456 unsigned int event_mask;
8457 boolean is_touch_button;
8459 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8462 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8463 &menu.main.button.prev_level, NULL,
8464 SCREEN_CTRL_ID_PREV_LEVEL,
8466 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8467 FALSE, "previous level"
8470 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8471 &menu.main.button.next_level, NULL,
8472 SCREEN_CTRL_ID_NEXT_LEVEL,
8474 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8478 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8479 &menu.main.button.first_level, NULL,
8480 SCREEN_CTRL_ID_FIRST_LEVEL,
8483 FALSE, "first level"
8486 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8487 &menu.main.button.last_level, NULL,
8488 SCREEN_CTRL_ID_LAST_LEVEL,
8494 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8495 &menu.main.button.level_number, NULL,
8496 SCREEN_CTRL_ID_LEVEL_NUMBER,
8499 FALSE, "level number"
8502 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8503 &menu.setup.button.prev_player, NULL,
8504 SCREEN_CTRL_ID_PREV_PLAYER,
8506 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8507 FALSE, "previous player"
8510 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8511 &menu.setup.button.next_player, NULL,
8512 SCREEN_CTRL_ID_NEXT_PLAYER,
8514 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8515 FALSE, "next player"
8518 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8519 &menu.main.button.insert_solution, NULL,
8520 SCREEN_CTRL_ID_INSERT_SOLUTION,
8521 SCREEN_MASK_MAIN_HAS_SOLUTION,
8523 FALSE, "insert solution tape"
8526 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8527 &menu.main.button.play_solution, NULL,
8528 SCREEN_CTRL_ID_PLAY_SOLUTION,
8529 SCREEN_MASK_MAIN_HAS_SOLUTION,
8531 FALSE, "play solution tape"
8534 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8535 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8536 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8538 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8539 FALSE, "switch ECS/AGA chipset"
8542 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8543 &menu.setup.button.touch_back, NULL,
8544 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8547 TRUE, "previous page"
8550 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8551 &menu.setup.button.touch_next, NULL,
8552 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8558 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8559 &menu.setup.button.touch_back2, NULL,
8560 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8563 TRUE, "previous page"
8566 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8567 &menu.setup.button.touch_next2, NULL,
8568 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8577 int gfx_unpressed, gfx_pressed;
8581 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8584 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8585 -1, -1, // these values are not constant, but can change at runtime
8586 SCREEN_CTRL_ID_SCROLL_UP,
8590 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8591 -1, -1, // these values are not constant, but can change at runtime
8592 SCREEN_CTRL_ID_SCROLL_DOWN,
8599 int gfx_unpressed, gfx_pressed;
8605 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8608 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8609 -1, -1, // these values are not constant, but can change at runtime
8610 -1, -1, // these values are not constant, but can change at runtime
8611 GD_TYPE_SCROLLBAR_VERTICAL,
8612 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8613 "scroll level series vertically"
8625 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8628 IMG_SETUP_INPUT_TEXT,
8629 SCREEN_CTRL_ID_NETWORK_SERVER,
8630 -1, -1, // these values are not constant, but can change at runtime
8631 MAX_SETUP_TEXT_INPUT_LEN,
8632 network_server_hostname,
8633 "Network Server Hostname / IP"
8637 static void CreateScreenMenubuttons(void)
8639 struct GadgetInfo *gi;
8640 unsigned int event_mask;
8643 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8645 struct MenuPosInfo *pos = menubutton_info[i].pos;
8646 boolean is_touch_button = menubutton_info[i].is_touch_button;
8647 boolean is_check_button = menubutton_info[i].check_value != NULL;
8648 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8649 int gfx_unpressed, gfx_pressed;
8650 int x, y, width, height;
8651 int gd_x1, gd_x2, gd_y1, gd_y2;
8652 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
8653 int id = menubutton_info[i].gadget_id;
8654 int type = GD_TYPE_NORMAL_BUTTON;
8655 boolean checked = FALSE;
8657 event_mask = menubutton_info[i].event_mask;
8659 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
8660 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
8662 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8663 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8665 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8666 gfx_pressed = menubutton_info[i].gfx_pressed;
8667 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8668 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8669 gd_x1 = graphic_info[gfx_unpressed].src_x;
8670 gd_y1 = graphic_info[gfx_unpressed].src_y;
8671 gd_x2 = graphic_info[gfx_pressed].src_x;
8672 gd_y2 = graphic_info[gfx_pressed].src_y;
8678 if (is_touch_button)
8680 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
8681 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
8684 if (is_check_button)
8686 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
8687 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
8688 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
8689 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
8691 type = GD_TYPE_CHECK_BUTTON;
8692 checked = *menubutton_info[i].check_value;
8695 gi = CreateGadget(GDI_CUSTOM_ID, id,
8696 GDI_CUSTOM_TYPE_ID, i,
8697 GDI_IMAGE_ID, gfx_unpressed,
8698 GDI_INFO_TEXT, menubutton_info[i].infotext,
8704 GDI_STATE, GD_BUTTON_UNPRESSED,
8705 GDI_CHECKED, checked,
8706 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8707 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8708 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
8709 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
8710 GDI_DIRECT_DRAW, FALSE,
8711 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
8712 GDI_EVENT_MASK, event_mask,
8713 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8717 Error(ERR_EXIT, "cannot create gadget");
8719 screen_gadget[id] = gi;
8723 static void CreateScreenScrollbuttons(void)
8725 struct GadgetInfo *gi;
8726 unsigned int event_mask;
8729 // these values are not constant, but can change at runtime
8730 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8731 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8732 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8733 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8735 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8737 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8738 int gfx_unpressed, gfx_pressed;
8739 int x, y, width, height;
8740 int gd_x1, gd_x2, gd_y1, gd_y2;
8741 int id = scrollbutton_info[i].gadget_id;
8743 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8745 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8746 y = mSY + scrollbutton_info[i].y;
8747 width = SC_SCROLLBUTTON_XSIZE;
8748 height = SC_SCROLLBUTTON_YSIZE;
8750 // correct scrollbar position if placed outside menu (playfield) area
8751 if (x > SX + SC_SCROLL_UP_XPOS)
8752 x = SX + SC_SCROLL_UP_XPOS;
8754 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8755 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8756 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8758 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8759 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8760 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8761 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8762 gd_x1 = graphic_info[gfx_unpressed].src_x;
8763 gd_y1 = graphic_info[gfx_unpressed].src_y;
8764 gd_x2 = graphic_info[gfx_pressed].src_x;
8765 gd_y2 = graphic_info[gfx_pressed].src_y;
8767 gi = CreateGadget(GDI_CUSTOM_ID, id,
8768 GDI_CUSTOM_TYPE_ID, i,
8769 GDI_IMAGE_ID, gfx_unpressed,
8770 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8775 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8776 GDI_STATE, GD_BUTTON_UNPRESSED,
8777 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8778 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8779 GDI_DIRECT_DRAW, FALSE,
8780 GDI_EVENT_MASK, event_mask,
8781 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8785 Error(ERR_EXIT, "cannot create gadget");
8787 screen_gadget[id] = gi;
8791 static void CreateScreenScrollbars(void)
8795 // these values are not constant, but can change at runtime
8796 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8797 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8798 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8799 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8801 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8803 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8804 int gfx_unpressed, gfx_pressed;
8805 int x, y, width, height;
8806 int gd_x1, gd_x2, gd_y1, gd_y2;
8807 struct GadgetInfo *gi;
8808 int items_max, items_visible, item_position;
8809 unsigned int event_mask;
8810 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8811 int id = scrollbar_info[i].gadget_id;
8813 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8815 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8816 y = mSY + scrollbar_info[i].y;
8817 width = scrollbar_info[i].width;
8818 height = scrollbar_info[i].height;
8820 // correct scrollbar position if placed outside menu (playfield) area
8821 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8822 x = SX + SC_SCROLL_VERTICAL_XPOS;
8824 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8825 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8827 items_max = num_page_entries;
8828 items_visible = num_page_entries;
8831 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8832 gfx_pressed = scrollbar_info[i].gfx_pressed;
8833 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8834 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8835 gd_x1 = graphic_info[gfx_unpressed].src_x;
8836 gd_y1 = graphic_info[gfx_unpressed].src_y;
8837 gd_x2 = graphic_info[gfx_pressed].src_x;
8838 gd_y2 = graphic_info[gfx_pressed].src_y;
8840 gi = CreateGadget(GDI_CUSTOM_ID, id,
8841 GDI_CUSTOM_TYPE_ID, i,
8842 GDI_IMAGE_ID, gfx_unpressed,
8843 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8848 GDI_TYPE, scrollbar_info[i].type,
8849 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8850 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8851 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8852 GDI_WHEEL_AREA_X, SX,
8853 GDI_WHEEL_AREA_Y, SY,
8854 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8855 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8856 GDI_STATE, GD_BUTTON_UNPRESSED,
8857 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8858 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8859 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8860 GDI_DIRECT_DRAW, FALSE,
8861 GDI_EVENT_MASK, event_mask,
8862 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8866 Error(ERR_EXIT, "cannot create gadget");
8868 screen_gadget[id] = gi;
8872 static void CreateScreenTextInputGadgets(void)
8876 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
8878 int graphic = textinput_info[i].graphic;
8879 struct GraphicInfo *gd = &graphic_info[graphic];
8880 int gd_x1 = gd->src_x;
8881 int gd_y1 = gd->src_y;
8882 int gd_x2 = gd->src_x + gd->active_xoffset;
8883 int gd_y2 = gd->src_y + gd->active_yoffset;
8884 struct GadgetInfo *gi;
8885 unsigned int event_mask;
8886 int id = textinput_info[i].gadget_id;
8887 int x = textinput_info[i].x;
8888 int y = textinput_info[i].y;
8890 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8892 gi = CreateGadget(GDI_CUSTOM_ID, id,
8893 GDI_CUSTOM_TYPE_ID, i,
8894 GDI_INFO_TEXT, textinput_info[i].infotext,
8897 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8898 GDI_TEXT_VALUE, textinput_info[i].value,
8899 GDI_TEXT_SIZE, textinput_info[i].size,
8900 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
8901 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
8902 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8903 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8904 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8905 GDI_DESIGN_WIDTH, gd->width,
8906 GDI_EVENT_MASK, event_mask,
8907 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8908 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
8912 Error(ERR_EXIT, "cannot create gadget");
8914 screen_gadget[id] = gi;
8918 void CreateScreenGadgets(void)
8920 CreateScreenMenubuttons();
8922 CreateScreenScrollbuttons();
8923 CreateScreenScrollbars();
8925 CreateScreenTextInputGadgets();
8928 void FreeScreenGadgets(void)
8932 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8933 FreeGadget(screen_gadget[i]);
8936 static void MapScreenMenuGadgets(int screen_mask)
8940 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8941 if (screen_mask & menubutton_info[i].screen_mask)
8942 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8945 static void UnmapScreenMenuGadgets(int screen_mask)
8949 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8951 if (screen_mask & menubutton_info[i].screen_mask)
8953 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8955 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8956 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8957 screen_gadget[menubutton_info[i].gadget_id]->y,
8958 screen_gadget[menubutton_info[i].gadget_id]->width,
8959 screen_gadget[menubutton_info[i].gadget_id]->height);
8964 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8967 MapScreenMenuGadgets(screen_mask);
8969 UnmapScreenMenuGadgets(screen_mask);
8972 static void MapScreenGadgets(int num_entries)
8976 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8979 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8980 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8982 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8983 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8986 static void MapScreenTreeGadgets(TreeInfo *ti)
8988 MapScreenGadgets(numTreeInfoInGroup(ti));
8991 static void HandleScreenGadgets(struct GadgetInfo *gi)
8993 int id = gi->custom_id;
8994 int button = gi->event.button;
8995 int step = (button == MB_LEFTBUTTON ? 1 :
8996 button == MB_MIDDLEBUTTON ? 5 :
8997 button == MB_RIGHTBUTTON ? 10 : 1);
9001 case SCREEN_CTRL_ID_PREV_LEVEL:
9002 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
9005 case SCREEN_CTRL_ID_NEXT_LEVEL:
9006 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
9009 case SCREEN_CTRL_ID_FIRST_LEVEL:
9010 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9013 case SCREEN_CTRL_ID_LAST_LEVEL:
9014 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9017 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9018 CloseDoor(DOOR_CLOSE_2);
9019 SetGameStatus(GAME_MODE_LEVELNR);
9020 DrawChooseLevelNr();
9023 case SCREEN_CTRL_ID_PREV_PLAYER:
9024 HandleSetupScreen_Input_Player(step, -1);
9027 case SCREEN_CTRL_ID_NEXT_PLAYER:
9028 HandleSetupScreen_Input_Player(step, +1);
9031 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9032 InsertSolutionTape();
9035 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9039 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9040 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9044 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9045 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9046 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9047 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9048 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9051 case SCREEN_CTRL_ID_SCROLL_UP:
9052 if (game_status == GAME_MODE_LEVELS)
9053 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9054 else if (game_status == GAME_MODE_LEVELNR)
9055 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9056 else if (game_status == GAME_MODE_SETUP)
9057 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9058 else if (game_status == GAME_MODE_INFO)
9059 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9062 case SCREEN_CTRL_ID_SCROLL_DOWN:
9063 if (game_status == GAME_MODE_LEVELS)
9064 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9065 else if (game_status == GAME_MODE_LEVELNR)
9066 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9067 else if (game_status == GAME_MODE_SETUP)
9068 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9069 else if (game_status == GAME_MODE_INFO)
9070 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9073 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9074 if (game_status == GAME_MODE_LEVELS)
9075 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9076 else if (game_status == GAME_MODE_LEVELNR)
9077 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9078 else if (game_status == GAME_MODE_SETUP)
9079 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9080 else if (game_status == GAME_MODE_INFO)
9081 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9084 case SCREEN_CTRL_ID_NETWORK_SERVER:
9086 if (!strEqual(gi->textinput.value, ""))
9088 setString(&setup.network_server_hostname, gi->textinput.value);
9090 network.server_host = setup.network_server_hostname;
9094 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9096 network.server_host = NULL;
9099 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9100 network.server_host = NULL;
9102 execSetupGame_setNetworkServerText();
9114 void DumpScreenIdentifiers(void)
9118 Print("Active screen elements on current screen:\n");
9120 for (i = 0; main_controls[i].nr != -1; i++)
9122 struct MainControlInfo *mci = &main_controls[i];
9124 if (mci->button_graphic != -1)
9126 char *token = getTokenFromImageID(mci->button_graphic);
9128 Print("- '%s'\n", token);
9135 boolean DoScreenAction(int image_id)
9139 if (game_status != GAME_MODE_MAIN)
9142 for (i = 0; main_controls[i].nr != -1; i++)
9144 struct MainControlInfo *mci = &main_controls[i];
9145 struct MenuPosInfo *pos = mci->pos_button;
9147 if (mci->button_graphic == image_id)
9149 int x = mSX + pos->x;
9150 int y = mSY + pos->y;
9152 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9161 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9163 // get tree info node of newly added level or artwork set
9164 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9165 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9167 if (tree_node_new == NULL) // should not happen
9170 // if request dialog is active, do nothing
9171 if (game.request_active)
9174 if (game_status == GAME_MODE_MAIN &&
9175 tree_type == TREE_TYPE_LEVEL_DIR)
9177 // when adding new level set in main menu, select it as current level set
9179 // change current level set to newly added level set from zip file
9180 leveldir_current = tree_node_new;
9182 // change current level number to first level of newly added level set
9183 level_nr = leveldir_current->first_level;
9185 // redraw screen to reflect changed level set
9188 // save this level set and level number as last selected level set
9189 SaveLevelSetup_LastSeries();
9190 SaveLevelSetup_SeriesInfo();
9192 else if (game_status == GAME_MODE_LEVELS &&
9193 tree_type == TREE_TYPE_LEVEL_DIR)
9195 // when adding new level set in level set menu, set cursor and update screen
9197 leveldir_current = tree_node_new;
9199 DrawChooseTree(&leveldir_current);
9201 else if (game_status == GAME_MODE_SETUP)
9203 // when adding new artwork set in setup menu, set cursor and update screen
9205 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9206 tree_type == TREE_TYPE_GRAPHICS_DIR)
9208 artwork.gfx_current = tree_node_new;
9210 DrawChooseTree(&artwork.gfx_current);
9212 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9213 tree_type == TREE_TYPE_SOUNDS_DIR)
9215 artwork.snd_current = tree_node_new;
9217 DrawChooseTree(&artwork.snd_current);
9219 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9220 tree_type == TREE_TYPE_MUSIC_DIR)
9222 artwork.mus_current = tree_node_new;
9224 DrawChooseTree(&artwork.mus_current);