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 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
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 printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
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 printf("::: insideTextPosRect: (%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d\n",
1330 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1331 (x >= rect_x && x < rect_x + rect->width &&
1332 y >= rect_y && y < rect_y + rect->height));
1335 return (x >= rect_x && x < rect_x + rect->width &&
1336 y >= rect_y && y < rect_y + rect->height);
1339 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1341 int rect_width = preview->xsize * preview->tile_size;
1342 int rect_height = preview->ysize * preview->tile_size;
1343 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1344 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1346 return (x >= rect_x && x < rect_x + rect_width &&
1347 y >= rect_y && y < rect_y + rect_height);
1350 static void AdjustScrollbar(int id, int items_max, int items_visible,
1353 struct GadgetInfo *gi = screen_gadget[id];
1355 if (item_position > items_max - items_visible)
1356 item_position = items_max - items_visible;
1358 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1359 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1360 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1363 static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti)
1365 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1369 static void clearMenuListArea(void)
1371 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1373 // correct scrollbar position if placed outside menu (playfield) area
1374 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1375 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1377 // clear menu list area, but not title or scrollbar
1378 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1379 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1382 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1384 static int cursor_array[MAX_LEV_FIELDY];
1385 int x = amSX + TILEX * xpos;
1386 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1391 cursor_array[ypos] = graphic;
1393 graphic = cursor_array[ypos];
1397 graphic = BUTTON_ACTIVE(graphic);
1399 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1400 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1403 static void initCursor(int ypos, int graphic)
1405 drawCursorExt(0, ypos, FALSE, graphic);
1408 static void drawCursor(int ypos, boolean active)
1410 drawCursorExt(0, ypos, active, -1);
1413 static void drawCursorXY(int xpos, int ypos, int graphic)
1415 drawCursorExt(xpos, ypos, FALSE, graphic);
1418 static void drawChooseTreeCursor(int ypos, boolean active)
1420 drawCursorExt(0, ypos, active, -1);
1423 static void DrawHeadline(void)
1425 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1);
1426 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, main_text_title_2);
1429 static void DrawTitleScreenImage(int nr, boolean initial)
1431 int graphic = getTitleScreenGraphic(nr, initial);
1432 Bitmap *bitmap = graphic_info[graphic].bitmap;
1433 int width = graphic_info[graphic].width;
1434 int height = graphic_info[graphic].height;
1435 int src_x = graphic_info[graphic].src_x;
1436 int src_y = graphic_info[graphic].src_y;
1442 if (width > WIN_XSIZE)
1444 // image width too large for window => center image horizontally
1445 src_x = (width - WIN_XSIZE) / 2;
1449 if (height > WIN_YSIZE)
1451 // image height too large for window => center image vertically
1452 src_y = (height - WIN_YSIZE) / 2;
1456 // always display title screens centered
1457 dst_x = (WIN_XSIZE - width) / 2;
1458 dst_y = (WIN_YSIZE - height) / 2;
1460 SetDrawBackgroundMask(REDRAW_ALL);
1461 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1463 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1465 if (DrawingOnBackground(dst_x, dst_y))
1466 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1468 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1470 redraw_mask = REDRAW_ALL;
1473 static void DrawTitleScreenMessage(int nr, boolean initial)
1475 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1476 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1478 if (filename == NULL)
1481 // force TITLE font on title message screen
1482 SetFontStatus(getTitleMessageGameMode(initial));
1484 // if chars *and* width set to "-1", automatically determine width
1485 if (tmi->chars == -1 && tmi->width == -1)
1486 tmi->width = viewport.window[game_status].width;
1488 // if lines *and* height set to "-1", automatically determine height
1489 if (tmi->lines == -1 && tmi->height == -1)
1490 tmi->height = viewport.window[game_status].height;
1492 // if chars set to "-1", automatically determine by text and font width
1493 if (tmi->chars == -1)
1494 tmi->chars = tmi->width / getFontWidth(tmi->font);
1496 tmi->width = tmi->chars * getFontWidth(tmi->font);
1498 // if lines set to "-1", automatically determine by text and font height
1499 if (tmi->lines == -1)
1500 tmi->lines = tmi->height / getFontHeight(tmi->font);
1502 tmi->height = tmi->lines * getFontHeight(tmi->font);
1504 // if x set to "-1", automatically determine by width and alignment
1506 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1508 // if y set to "-1", automatically determine by height and alignment
1510 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1512 SetDrawBackgroundMask(REDRAW_ALL);
1513 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1515 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1517 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1518 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1519 tmi->autowrap, tmi->centered, tmi->parse_comments);
1524 static void DrawTitleScreen(void)
1526 KeyboardAutoRepeatOff();
1528 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1531 static boolean CheckTitleScreen(boolean levelset_has_changed)
1533 static boolean show_title_initial = TRUE;
1534 boolean show_titlescreen = FALSE;
1536 // needed to be able to skip title screen, if no image or message defined
1537 InitializeTitleControls(show_title_initial);
1539 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1540 show_titlescreen = TRUE;
1542 // show initial title images and messages only once at program start
1543 show_title_initial = FALSE;
1545 return (show_titlescreen && num_title_screens > 0);
1548 void DrawMainMenu(void)
1550 static LevelDirTree *leveldir_last_valid = NULL;
1551 boolean levelset_has_changed = FALSE;
1552 int fade_mask = REDRAW_FIELD;
1554 LimitScreenUpdates(FALSE);
1556 FadeSetLeaveScreen();
1558 // do not fade out here -- function may continue and fade on editor screen
1561 FadeMenuSoundsAndMusic();
1563 ExpireSoundLoops(FALSE);
1565 KeyboardAutoRepeatOn();
1567 audio.sound_deactivated = FALSE;
1571 // needed if last screen was the playing screen, invoked from level editor
1572 if (level_editor_test_game)
1574 CloseDoor(DOOR_CLOSE_ALL);
1576 SetGameStatus(GAME_MODE_EDITOR);
1583 // needed if last screen was the setup screen and fullscreen state changed
1584 // (moved to "execSetupGraphics()" to change fullscreen state directly)
1585 // ToggleFullscreenOrChangeWindowScalingIfNeeded();
1587 // leveldir_current may be invalid (level group, parent link)
1588 if (!validLevelSeries(leveldir_current))
1589 leveldir_current = getFirstValidTreeInfoEntry(leveldir_last_valid);
1591 if (leveldir_current != leveldir_last_valid)
1592 levelset_has_changed = TRUE;
1594 // store valid level series information
1595 leveldir_last_valid = leveldir_current;
1597 init_last = init; // switch to new busy animation
1599 // needed if last screen (level choice) changed graphics, sounds or music
1600 ReloadCustomArtwork(0);
1602 if (CheckTitleScreen(levelset_has_changed))
1604 SetGameStatus(GAME_MODE_TITLE);
1611 if (redraw_mask & REDRAW_ALL)
1612 fade_mask = REDRAW_ALL;
1615 fade_mask = REDRAW_ALL;
1619 // needed if different viewport properties defined for menues
1620 ChangeViewportPropertiesIfNeeded();
1622 SetDrawtoField(DRAW_TO_BACKBUFFER);
1624 // level_nr may have been set to value over handicap with level editor
1625 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1626 level_nr = leveldir_current->handicap_level;
1628 LoadLevel(level_nr);
1629 LoadScore(level_nr);
1631 SaveLevelSetup_SeriesInfo();
1633 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1634 SetDrawDeactivationMask(REDRAW_NONE);
1635 SetDrawBackgroundMask(REDRAW_FIELD);
1637 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1640 if (fade_mask == REDRAW_ALL)
1641 RedrawGlobalBorder();
1646 InitializeMainControls();
1648 DrawCursorAndText_Main(-1, FALSE, FALSE);
1649 DrawPreviewLevelInitial();
1650 DrawNetworkPlayers();
1652 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1655 if (TAPE_IS_EMPTY(tape))
1657 DrawCompleteVideoDisplay();
1659 PlayMenuSoundsAndMusic();
1661 // create gadgets for main menu screen
1662 FreeScreenGadgets();
1663 CreateScreenGadgets();
1665 // may be required if audio buttons shown on tape and changed in setup menu
1667 CreateGameButtons();
1669 // map gadgets for main menu screen
1671 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1672 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1674 // copy actual game door content to door double buffer for OpenDoor()
1675 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1676 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1678 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1680 DrawMaskedBorder(fade_mask);
1685 // update screen area with special editor door
1686 redraw_mask |= REDRAW_ALL;
1689 SetMouseCursor(CURSOR_DEFAULT);
1691 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1694 static void gotoTopLevelDir(void)
1696 // move upwards until inside (but not above) top level directory
1697 while (leveldir_current->node_parent &&
1698 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1700 // write a "path" into level tree for easy navigation to last level
1701 if (leveldir_current->node_parent->node_group->cl_first == -1)
1703 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1704 int leveldir_pos = posTreeInfo(leveldir_current);
1705 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1706 int cl_first, cl_cursor;
1708 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1709 cl_cursor = leveldir_pos - cl_first;
1711 leveldir_current->node_parent->node_group->cl_first = cl_first;
1712 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1715 leveldir_current = leveldir_current->node_parent;
1719 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1721 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1723 return (use_frame_counter ? video.frame_counter : Counter());
1726 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1727 struct TitleFadingInfo *fi)
1729 return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1732 static void ResetTitleAutoDelay(unsigned int *counter_var,
1733 struct TitleFadingInfo *fi)
1735 *counter_var = getAutoDelayCounter(fi);
1738 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1740 static unsigned int title_delay = 0;
1741 static int title_screen_nr = 0;
1742 static int last_sound = -1, last_music = -1;
1743 boolean return_to_main_menu = FALSE;
1744 struct TitleControlInfo *tci;
1747 if (button == MB_MENU_INITIALIZE)
1750 title_screen_nr = 0;
1751 tci = &title_controls[title_screen_nr];
1753 SetAnimStatus(getTitleAnimMode(tci));
1755 last_sound = SND_UNDEFINED;
1756 last_music = MUS_UNDEFINED;
1758 if (num_title_screens != 0)
1760 FadeSetEnterScreen();
1762 // use individual title fading instead of global "enter screen" fading
1763 fading = getTitleFading(tci);
1766 if (game_status_last_screen == GAME_MODE_INFO)
1768 if (num_title_screens == 0)
1770 // switch game mode from title screen mode back to info screen mode
1771 SetGameStatus(GAME_MODE_INFO);
1773 // store that last screen was info screen, not main menu screen
1774 game_status_last_screen = GAME_MODE_INFO;
1776 DrawInfoScreen_NotAvailable("Title screen information:",
1777 "No title screen for this level set.");
1782 FadeMenuSoundsAndMusic();
1784 FadeOut(REDRAW_ALL);
1786 // title screens may have different window size
1787 ChangeViewportPropertiesIfNeeded();
1789 // only required to update logic for redrawing global border
1793 DrawTitleScreenImage(tci->local_nr, tci->initial);
1795 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1797 sound = getTitleSound(tci);
1798 music = getTitleMusic(tci);
1800 if (sound != last_sound)
1801 PlayMenuSoundExt(sound);
1802 if (music != last_music)
1803 PlayMenuMusicExt(music);
1808 SetMouseCursor(CURSOR_NONE);
1812 ResetTitleAutoDelay(&title_delay, &fading);
1817 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
1818 button = MB_MENU_CHOICE;
1820 if (button == MB_MENU_LEAVE)
1822 return_to_main_menu = TRUE;
1824 else if (button == MB_MENU_CHOICE)
1826 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
1828 SetGameStatus(GAME_MODE_INFO);
1830 info_mode = INFO_MODE_MAIN;
1839 if (title_screen_nr < num_title_screens)
1841 tci = &title_controls[title_screen_nr];
1843 SetAnimStatus(getTitleAnimMode(tci));
1845 sound = getTitleSound(tci);
1846 music = getTitleMusic(tci);
1848 if (last_sound != SND_UNDEFINED && sound != last_sound)
1849 FadeSound(last_sound);
1850 if (last_music != MUS_UNDEFINED && music != last_music)
1853 fading = getTitleFading(tci);
1855 FadeOut(REDRAW_ALL);
1858 DrawTitleScreenImage(tci->local_nr, tci->initial);
1860 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1862 sound = getTitleSound(tci);
1863 music = getTitleMusic(tci);
1865 if (sound != last_sound)
1866 PlayMenuSoundExt(sound);
1867 if (music != last_music)
1868 PlayMenuMusicExt(music);
1875 ResetTitleAutoDelay(&title_delay, &fading);
1879 FadeMenuSoundsAndMusic();
1881 return_to_main_menu = TRUE;
1885 if (return_to_main_menu)
1887 SetMouseCursor(CURSOR_DEFAULT);
1889 // force full menu screen redraw after displaying title screens
1890 redraw_mask = REDRAW_ALL;
1892 if (game_status_last_screen == GAME_MODE_INFO)
1894 SetGameStatus(GAME_MODE_INFO);
1896 info_mode = INFO_MODE_MAIN;
1900 else // default: return to main menu
1902 SetGameStatus(GAME_MODE_MAIN);
1909 static void HandleMainMenu_SelectLevel(int step, int direction,
1910 int selected_level_nr)
1912 int old_level_nr = level_nr;
1915 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
1916 new_level_nr = selected_level_nr;
1918 new_level_nr = old_level_nr + step * direction;
1920 if (new_level_nr < leveldir_current->first_level)
1921 new_level_nr = leveldir_current->first_level;
1922 if (new_level_nr > leveldir_current->last_level)
1923 new_level_nr = leveldir_current->last_level;
1925 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
1927 // skipping levels is only allowed when trying to skip single level
1928 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
1929 Request("Level still unsolved! Skip despite handicap?", REQ_ASK))
1931 leveldir_current->handicap_level++;
1932 SaveLevelSetup_SeriesInfo();
1935 new_level_nr = leveldir_current->handicap_level;
1938 if (new_level_nr != old_level_nr)
1940 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
1942 PlaySound(SND_MENU_ITEM_SELECTING);
1944 level_nr = new_level_nr;
1946 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
1947 int2str(level_nr, menu.main.text.level_number.size),
1948 mci->pos_text->font);
1950 LoadLevel(level_nr);
1951 DrawPreviewLevelInitial();
1955 DrawCompleteVideoDisplay();
1957 SaveLevelSetup_SeriesInfo();
1959 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1961 // force redraw of playfield area (may be reset at this point)
1962 redraw_mask |= REDRAW_FIELD;
1966 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
1968 static int choice = MAIN_CONTROL_GAME;
1969 static boolean button_pressed_last = FALSE;
1970 boolean button_pressed = FALSE;
1972 int i = 0; // needed to prevent compiler warning due to bad code below
1974 if (button == MB_MENU_INITIALIZE)
1976 DrawCursorAndText_Main(choice, TRUE, FALSE);
1981 if (mx || my) // mouse input
1985 for (i = 0; main_controls[i].nr != -1; i++)
1987 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
1988 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
1989 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
1991 pos = main_controls[i].nr;
1997 // check if level preview was clicked
1998 if (insidePreviewRect(&preview, mx - SX, my - SY))
1999 pos = MAIN_CONTROL_GAME;
2001 // handle pressed/unpressed state for active/inactive menu buttons
2002 // (if pos != -1, "i" contains index position corresponding to "pos")
2004 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2005 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2006 button_pressed = TRUE;
2008 if (button_pressed != button_pressed_last)
2010 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2013 PlaySound(SND_MENU_BUTTON_PRESSING);
2015 PlaySound(SND_MENU_BUTTON_RELEASING);
2018 else if (dx || dy) // keyboard input
2020 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2021 choice == MAIN_CONTROL_SETUP))
2022 button = MB_MENU_CHOICE;
2027 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2029 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2031 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2033 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2035 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2037 CloseDoor(DOOR_CLOSE_2);
2039 SetGameStatus(GAME_MODE_LEVELNR);
2041 DrawChooseLevelNr();
2043 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2049 PlaySound(SND_MENU_ITEM_ACTIVATING);
2051 DrawCursorAndText_Main(choice, FALSE, FALSE);
2052 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2058 if (choice != MAIN_CONTROL_INFO &&
2059 choice != MAIN_CONTROL_SETUP)
2060 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2065 PlaySound(SND_MENU_ITEM_SELECTING);
2067 if (pos == MAIN_CONTROL_NAME)
2070 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2072 // special case: menu text "name/team" clicked -- toggle team mode
2073 setup.team_mode = !setup.team_mode;
2075 InitializeMainControls();
2076 DrawCursorAndText_Main(choice, TRUE, FALSE);
2078 DrawPreviewPlayers();
2082 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2084 HandleTypeName(strlen(setup.player_name), 0);
2087 else if (pos == MAIN_CONTROL_LEVELS)
2091 CloseDoor(DOOR_CLOSE_2);
2093 SetGameStatus(GAME_MODE_LEVELS);
2095 SaveLevelSetup_LastSeries();
2096 SaveLevelSetup_SeriesInfo();
2098 if (setup.internal.choose_from_top_leveldir)
2101 DrawChooseLevelSet();
2104 else if (pos == MAIN_CONTROL_SCORES)
2106 CloseDoor(DOOR_CLOSE_2);
2108 SetGameStatus(GAME_MODE_SCORES);
2110 DrawHallOfFame(level_nr, -1);
2112 else if (pos == MAIN_CONTROL_EDITOR)
2114 if (leveldir_current->readonly &&
2115 !strEqual(setup.player_name, "Artsoft"))
2116 Request("This level is read only!", REQ_CONFIRM);
2118 CloseDoor(DOOR_CLOSE_2);
2120 SetGameStatus(GAME_MODE_EDITOR);
2122 FadeSetEnterScreen();
2126 else if (pos == MAIN_CONTROL_INFO)
2128 CloseDoor(DOOR_CLOSE_2);
2130 SetGameStatus(GAME_MODE_INFO);
2132 info_mode = INFO_MODE_MAIN;
2136 else if (pos == MAIN_CONTROL_GAME)
2138 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2140 else if (pos == MAIN_CONTROL_SETUP)
2142 CloseDoor(DOOR_CLOSE_2);
2144 SetGameStatus(GAME_MODE_SETUP);
2146 setup_mode = SETUP_MODE_MAIN;
2150 else if (pos == MAIN_CONTROL_QUIT)
2152 SaveLevelSetup_LastSeries();
2153 SaveLevelSetup_SeriesInfo();
2155 if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2156 SetGameStatus(GAME_MODE_QUIT);
2161 button_pressed_last = button_pressed;
2165 // ============================================================================
2166 // info screen functions
2167 // ============================================================================
2169 static struct TokenInfo *info_info;
2170 static int num_info_info; // number of info entries shown on screen
2171 static int max_info_info; // total number of info entries in list
2173 static void execInfoTitleScreen(void)
2175 info_mode = INFO_MODE_TITLE;
2180 static void execInfoElements(void)
2182 info_mode = INFO_MODE_ELEMENTS;
2187 static void execInfoMusic(void)
2189 info_mode = INFO_MODE_MUSIC;
2194 static void execInfoCredits(void)
2196 info_mode = INFO_MODE_CREDITS;
2201 static void execInfoProgram(void)
2203 info_mode = INFO_MODE_PROGRAM;
2208 static void execInfoVersion(void)
2210 info_mode = INFO_MODE_VERSION;
2215 static void execInfoLevelSet(void)
2217 info_mode = INFO_MODE_LEVELSET;
2222 static void execExitInfo(void)
2224 SetGameStatus(GAME_MODE_MAIN);
2229 static struct TokenInfo info_info_main[] =
2231 { TYPE_ENTER_SCREEN, execInfoTitleScreen, "Title Screen" },
2232 { TYPE_ENTER_SCREEN, execInfoElements, "Elements Info" },
2233 { TYPE_ENTER_SCREEN, execInfoMusic, "Music Info" },
2234 { TYPE_ENTER_SCREEN, execInfoCredits, "Credits" },
2235 { TYPE_ENTER_SCREEN, execInfoProgram, "Program Info" },
2236 { TYPE_ENTER_SCREEN, execInfoVersion, "Version Info" },
2237 { TYPE_ENTER_SCREEN, execInfoLevelSet, "Level Set Info" },
2238 { TYPE_EMPTY, NULL, "" },
2239 { TYPE_LEAVE_MENU, execExitInfo, "Exit" },
2244 static int getMenuTextFont(int type)
2246 if (type & (TYPE_SWITCH |
2260 static struct TokenInfo *setup_info;
2261 static struct TokenInfo setup_info_input[];
2263 static struct TokenInfo *menu_info;
2265 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2266 int screen_pos, int menu_info_pos_raw,
2269 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2270 struct TokenInfo *ti = &token_info[pos];
2271 int xpos = MENU_SCREEN_START_XPOS;
2272 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2273 int font_nr = getMenuTextFont(ti->type);
2275 if (setup_mode == SETUP_MODE_INPUT)
2276 font_nr = FONT_MENU_1;
2279 font_nr = FONT_ACTIVE(font_nr);
2281 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2283 if (ti->type & ~TYPE_SKIP_ENTRY)
2284 drawCursor(screen_pos, active);
2287 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2290 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2293 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2296 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2299 static char *window_size_text;
2300 static char *scaling_type_text;
2301 static char *network_server_text;
2303 static void drawSetupValue(int, int);
2305 static void drawMenuInfoList(int first_entry, int num_page_entries,
2306 int max_page_entries)
2310 if (first_entry + num_page_entries > max_page_entries)
2313 clearMenuListArea();
2315 for (i = 0; i < num_page_entries; i++)
2317 int menu_info_pos = first_entry + i;
2318 struct TokenInfo *si = &menu_info[menu_info_pos];
2319 void *value_ptr = si->value;
2321 // set some entries to "unchangeable" according to other variables
2322 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2323 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2324 (value_ptr == &setup.sound_music && !audio.music_available) ||
2325 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2326 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2327 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2328 si->type |= TYPE_GHOSTED;
2330 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2331 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2332 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2333 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2334 else if (si->type & ~TYPE_SKIP_ENTRY)
2335 initCursor(i, IMG_MENU_BUTTON);
2337 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2339 if (si->type & TYPE_STRING)
2343 if (value_ptr == &network_server_text)
2344 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2346 if (gadget_id != -1)
2348 struct GadgetInfo *gi = screen_gadget[gadget_id];
2349 int xpos = MENU_SCREEN_START_XPOS;
2350 int ypos = MENU_SCREEN_START_YPOS + i;
2351 int x = mSX + xpos * 32;
2352 int y = mSY + ypos * 32;
2354 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2358 if (si->type & TYPE_VALUE &&
2359 menu_info == setup_info)
2360 drawSetupValue(i, menu_info_pos);
2364 static void DrawInfoScreen_Main(void)
2366 int fade_mask = REDRAW_FIELD;
2369 if (redraw_mask & REDRAW_ALL)
2370 fade_mask = REDRAW_ALL;
2373 fade_mask = REDRAW_ALL;
2376 FadeMenuSoundsAndMusic();
2378 FreeScreenGadgets();
2379 CreateScreenGadgets();
2381 // (needed after displaying title screens which disable auto repeat)
2382 KeyboardAutoRepeatOn();
2384 FadeSetLeaveScreen();
2388 // needed if different viewport properties defined for info screen
2389 ChangeViewportPropertiesIfNeeded();
2391 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2395 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2397 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
2399 info_info = info_info_main;
2401 // determine maximal number of info entries that can be displayed on screen
2403 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2406 // determine maximal number of info entries available for menu of info screen
2408 for (i = 0; info_info[i].type != 0; i++)
2411 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2413 MapScreenGadgets(max_info_info);
2415 PlayMenuSoundsAndMusic();
2417 DrawMaskedBorder(fade_mask);
2422 static void changeSetupValue(int, int, int);
2424 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2425 int mode, int num_page_entries,
2426 int max_page_entries)
2428 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2429 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2430 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2431 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2432 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2433 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2434 int *num_page_entries_last = num_page_entries_all_last[game_status];
2435 int *choice_store = choice_stores[game_status];
2436 int *first_entry_store = first_entry_stores[game_status];
2437 int choice = choice_store[mode]; // starts with 0
2438 int first_entry = first_entry_store[mode]; // starts with 0
2440 int y = choice - first_entry;
2442 boolean position_set_by_scrollbar = (dx == 999);
2443 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2446 if (button == MB_MENU_INITIALIZE)
2448 // check if number of menu page entries has changed (may happen by change
2449 // of custom artwork definition value for 'list_size' for this menu screen)
2450 // (in this case, the last menu position most probably has to be corrected)
2451 if (num_page_entries != num_page_entries_last[mode])
2453 choice_store[mode] = first_entry_store[mode] = 0;
2455 choice = first_entry = 0;
2458 num_page_entries_last[mode] = num_page_entries;
2461 // advance to first valid menu entry
2462 while (choice < num_page_entries &&
2463 menu_info[choice].type & TYPE_SKIP_ENTRY)
2466 if (position_set_by_scrollbar)
2467 first_entry = first_entry_store[mode] = dy;
2469 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2470 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2472 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2474 if (choice < first_entry)
2476 choice = first_entry;
2478 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2481 else if (choice > first_entry + num_page_entries - 1)
2483 choice = first_entry + num_page_entries - 1;
2485 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2489 choice_store[mode] = choice;
2491 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2495 else if (button == MB_MENU_LEAVE)
2497 PlaySound(SND_MENU_ITEM_SELECTING);
2499 for (i = 0; i < max_page_entries; i++)
2501 if (menu_info[i].type & TYPE_LEAVE_MENU)
2503 void (*menu_callback_function)(void) = menu_info[i].value;
2507 menu_callback_function();
2509 break; // absolutely needed because function changes 'menu_info'!
2516 if (mx || my) // mouse input
2518 x = (mx - mSX) / 32;
2519 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2521 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2523 // move cursor instead of scrolling when already at start/end of list
2524 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2526 else if (dy == +1 * SCROLL_LINE &&
2527 first_entry + num_page_entries == max_page_entries)
2530 // handle scrolling screen one line or page
2532 y + dy > num_page_entries - 1)
2534 boolean redraw = FALSE;
2536 if (ABS(dy) == SCROLL_PAGE)
2537 step = num_page_entries - 1;
2539 if (dy < 0 && first_entry > 0)
2541 // scroll page/line up
2543 first_entry -= step;
2544 if (first_entry < 0)
2549 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2551 // scroll page/line down
2553 first_entry += step;
2554 if (first_entry + num_page_entries > max_page_entries)
2555 first_entry = MAX(0, max_page_entries - num_page_entries);
2562 choice += first_entry - first_entry_store[mode];
2564 if (choice < first_entry)
2566 choice = first_entry;
2568 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2571 else if (choice > first_entry + num_page_entries - 1)
2573 choice = first_entry + num_page_entries - 1;
2575 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2578 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2582 if (choice < first_entry ||
2583 choice > first_entry + num_page_entries - 1)
2584 first_entry += SIGN(dy);
2587 first_entry_store[mode] = first_entry;
2588 choice_store[mode] = choice;
2590 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2592 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2594 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2595 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2603 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2605 if (menu_info[choice].type & menu_navigation_type ||
2606 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2607 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2608 menu_info[choice].type & TYPE_PLAYER)
2609 button = MB_MENU_CHOICE;
2614 // jump to next non-empty menu entry (up or down)
2615 while (first_entry + y > 0 &&
2616 first_entry + y < max_page_entries - 1 &&
2617 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2620 if (!IN_VIS_MENU(x, y))
2622 choice += y - y_old;
2624 if (choice < first_entry)
2625 first_entry = choice;
2626 else if (choice > first_entry + num_page_entries - 1)
2627 first_entry = choice - num_page_entries + 1;
2629 if (first_entry >= 0 &&
2630 first_entry + num_page_entries <= max_page_entries)
2632 first_entry_store[mode] = first_entry;
2634 if (choice < first_entry)
2635 choice = first_entry;
2636 else if (choice > first_entry + num_page_entries - 1)
2637 choice = first_entry + num_page_entries - 1;
2639 choice_store[mode] = choice;
2641 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2643 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2645 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2646 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2653 if (!anyScrollbarGadgetActive() &&
2654 IN_VIS_MENU(x, y) &&
2655 mx < mx_right_border &&
2656 y >= 0 && y < num_page_entries)
2660 if (first_entry + y != choice &&
2661 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2663 PlaySound(SND_MENU_ITEM_ACTIVATING);
2665 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2666 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2668 choice = choice_store[mode] = first_entry + y;
2672 PlaySound(SND_MENU_ITEM_SELECTING);
2674 for (i = 0; menu_info[i].type != 0; i++)
2676 if (menu_info[i].type & TYPE_LEAVE_MENU)
2678 void (*menu_callback_function)(void) = menu_info[i].value;
2682 menu_callback_function();
2684 // absolutely needed because function changes 'menu_info'!
2692 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
2694 PlaySound(SND_MENU_ITEM_SELECTING);
2696 // when selecting key headline, execute function for key value change
2697 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
2698 menu_info[first_entry + y + 1].type & TYPE_KEY)
2701 // when selecting string value, execute function for list selection
2702 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2703 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
2706 // when selecting string value, execute function for text input gadget
2707 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
2708 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
2711 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
2713 void (*menu_callback_function)(void) =
2714 menu_info[first_entry + y].value;
2716 FadeSetFromType(menu_info[first_entry + y].type);
2718 menu_callback_function();
2720 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
2722 void (*gadget_callback_function)(void) =
2723 menu_info[first_entry + y].value;
2725 gadget_callback_function();
2727 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
2728 menu_info == setup_info)
2730 changeSetupValue(y, first_entry + y, dx);
2736 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
2738 menu_info = info_info;
2740 HandleMenuScreen(mx, my, dx, dy, button,
2741 info_mode, num_info_info, max_info_info);
2744 static int getMenuFontSpacing(int spacing_height, int font_nr)
2746 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
2748 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
2752 static int getMenuTextSpacing(int spacing_height, int font_nr)
2754 return (getMenuFontSpacing(spacing_height, font_nr) +
2755 EXTRA_SPACING(game_status));
2758 static int getMenuTextStep(int spacing_height, int font_nr)
2760 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
2763 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
2765 int font_title = MENU_INFO_FONT_TITLE;
2766 int font_error = FONT_TEXT_2;
2767 int font_foot = MENU_INFO_FONT_FOOT;
2768 int spacing_title = menu.headline1_spacing_info[info_mode];
2769 int ystep_title = getMenuTextStep(spacing_title, font_title);
2770 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2771 int ystart2 = ystart1 + ystep_title;
2772 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2774 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
2776 FadeOut(REDRAW_FIELD);
2781 DrawTextSCentered(ystart1, font_title, text_title);
2782 DrawTextSCentered(ystart2, font_error, text_error);
2784 DrawTextSCentered(ybottom, font_foot,
2785 "Press any key or button for info menu");
2787 FadeIn(REDRAW_FIELD);
2790 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
2792 static int infoscreen_step[MAX_INFO_ELEMENTS_ON_SCREEN];
2793 static int infoscreen_frame[MAX_INFO_ELEMENTS_ON_SCREEN];
2794 int font_title = MENU_INFO_FONT_TITLE;
2795 int font_foot = MENU_INFO_FONT_FOOT;
2796 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
2797 int ystart1 = mSY - SY + MENU_SCREEN_INFO_YSTART1;
2798 int ystart2 = mSY + MENU_SCREEN_INFO_YSTART2;
2799 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
2800 int ystep = MENU_SCREEN_INFO_YSTEP;
2801 int element, action, direction;
2809 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
2810 infoscreen_step[i] = infoscreen_frame[i] = 0;
2815 DrawTextSCentered(ystart1, font_title, "The Game Elements:");
2817 DrawTextSCentered(ybottom, font_foot,
2818 "Press any key or button for next page");
2824 while (helpanim_info[j].element != HELPANIM_LIST_END)
2826 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
2831 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2840 j += infoscreen_step[i - start];
2842 element = helpanim_info[j].element;
2843 action = helpanim_info[j].action;
2844 direction = helpanim_info[j].direction;
2847 element = EL_UNKNOWN;
2849 if (action != -1 && direction != -1)
2850 graphic = el_act_dir2img(element, action, direction);
2851 else if (action != -1)
2852 graphic = el_act2img(element, action);
2853 else if (direction != -1)
2854 graphic = el_dir2img(element, direction);
2856 graphic = el2img(element);
2858 delay = helpanim_info[j++].delay;
2863 if (infoscreen_frame[i - start] == 0)
2866 infoscreen_frame[i - start] = delay - 1;
2870 sync_frame = delay - infoscreen_frame[i - start];
2871 infoscreen_frame[i - start]--;
2874 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
2876 if (!infoscreen_frame[i - start])
2877 infoscreen_step[i - start] = 0;
2881 if (!infoscreen_frame[i - start])
2882 infoscreen_step[i - start]++;
2883 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
2889 ClearRectangleOnBackground(drawto, xstart, ystart2 + (i - start) * ystep,
2891 DrawFixedGraphicAnimationExt(drawto, xstart, ystart2 + (i - start) * ystep,
2892 graphic, sync_frame, USE_MASKING);
2895 DrawInfoScreen_HelpText(element, action, direction, i - start);
2900 redraw_mask |= REDRAW_FIELD;
2905 static char *getHelpText(int element, int action, int direction)
2907 char token[MAX_LINE_LEN];
2909 strcpy(token, element_info[element].token_name);
2912 strcat(token, element_action_info[action].suffix);
2914 if (direction != -1)
2915 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
2917 return getHashEntry(helptext_info, token);
2920 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
2922 int font_nr = FONT_INFO_ELEMENTS;
2923 int font_width = getFontWidth(font_nr);
2924 int font_height = getFontHeight(font_nr);
2925 int yoffset = (TILEX - 2 * font_height) / 2;
2926 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
2927 int ystart = mSY + MENU_SCREEN_INFO_YSTART2 + yoffset;
2928 int ystep = TILEY + 4;
2929 int pad_left = xstart - SX;
2930 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
2931 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
2932 int max_lines_per_text = 2;
2935 if (action != -1 && direction != -1) // element.action.direction
2936 text = getHelpText(element, action, direction);
2938 if (text == NULL && action != -1) // element.action
2939 text = getHelpText(element, action, -1);
2941 if (text == NULL && direction != -1) // element.direction
2942 text = getHelpText(element, -1, direction);
2944 if (text == NULL) // base element
2945 text = getHelpText(element, -1, -1);
2947 if (text == NULL) // not found
2948 text = "No description available";
2950 if (strlen(text) <= max_chars_per_line) // only one line of text
2951 ystart += getFontHeight(font_nr) / 2;
2953 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
2954 max_chars_per_line, -1, max_lines_per_text, 0, -1,
2955 TRUE, FALSE, FALSE);
2958 static void DrawInfoScreen_TitleScreen(void)
2960 SetGameStatus(GAME_MODE_TITLE);
2965 void HandleInfoScreen_TitleScreen(int button)
2967 HandleTitleScreen(0, 0, 0, 0, button);
2970 static void DrawInfoScreen_Elements(void)
2972 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
2974 FadeOut(REDRAW_FIELD);
2979 HandleInfoScreen_Elements(MB_MENU_INITIALIZE);
2981 FadeIn(REDRAW_FIELD);
2984 void HandleInfoScreen_Elements(int button)
2986 static unsigned int info_delay = 0;
2987 static int num_anims;
2988 static int num_pages;
2990 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
2993 if (button == MB_MENU_INITIALIZE)
2995 boolean new_element = TRUE;
2999 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3001 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3003 else if (new_element)
3006 new_element = FALSE;
3010 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3014 if (button == MB_MENU_LEAVE)
3016 PlaySound(SND_MENU_ITEM_SELECTING);
3018 info_mode = INFO_MODE_MAIN;
3023 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3025 if (button != MB_MENU_INITIALIZE)
3027 PlaySound(SND_MENU_ITEM_SELECTING);
3032 if (page >= num_pages)
3034 FadeMenuSoundsAndMusic();
3036 info_mode = INFO_MODE_MAIN;
3043 FadeSetNextScreen();
3045 if (button != MB_MENU_INITIALIZE)
3046 FadeOut(REDRAW_FIELD);
3048 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3050 if (button != MB_MENU_INITIALIZE)
3051 FadeIn(REDRAW_FIELD);
3055 if (DelayReached(&info_delay, GameFrameDelay))
3056 if (page < num_pages)
3057 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3059 PlayMenuSoundIfLoop();
3063 static void DrawInfoScreen_Music(void)
3065 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3067 FadeOut(REDRAW_FIELD);
3074 HandleInfoScreen_Music(MB_MENU_INITIALIZE);
3076 FadeIn(REDRAW_FIELD);
3079 void HandleInfoScreen_Music(int button)
3081 static struct MusicFileInfo *list = NULL;
3082 int font_title = MENU_INFO_FONT_TITLE;
3083 int font_head = MENU_INFO_FONT_HEAD;
3084 int font_text = MENU_INFO_FONT_TEXT;
3085 int font_foot = MENU_INFO_FONT_FOOT;
3086 int spacing_title = menu.headline1_spacing_info[info_mode];
3087 int spacing_head = menu.headline2_spacing_info[info_mode];
3088 int ystep_title = getMenuTextStep(spacing_title, font_title);
3089 int ystep_head = getMenuTextStep(spacing_head, font_head);
3090 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3091 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3093 if (button == MB_MENU_INITIALIZE)
3095 list = music_file_info;
3099 FadeMenuSoundsAndMusic();
3104 DrawTextSCentered(ystart, font_title,
3105 "No music info for this level set.");
3107 DrawTextSCentered(ybottom, font_foot,
3108 "Press any key or button for info menu");
3114 if (button == MB_MENU_LEAVE)
3116 PlaySound(SND_MENU_ITEM_SELECTING);
3118 FadeMenuSoundsAndMusic();
3120 info_mode = INFO_MODE_MAIN;
3125 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3127 if (button != MB_MENU_INITIALIZE)
3129 PlaySound(SND_MENU_ITEM_SELECTING);
3137 FadeMenuSoundsAndMusic();
3139 info_mode = INFO_MODE_MAIN;
3145 FadeMenuSoundsAndMusic();
3147 if (list != music_file_info)
3148 FadeSetNextScreen();
3150 if (button != MB_MENU_INITIALIZE)
3151 FadeOut(REDRAW_FIELD);
3158 int sound = list->music;
3160 if (sound_info[sound].loop)
3161 PlaySoundLoop(sound);
3165 DrawTextSCentered(ystart, font_title, "The Game Background Sounds:");
3169 int music = list->music;
3171 if (music_info[music].loop)
3172 PlayMusicLoop(music);
3176 DrawTextSCentered(ystart, font_title, "The Game Background Music:");
3179 ystart += ystep_title;
3181 if (!strEqual(list->title, UNKNOWN_NAME))
3183 if (!strEqual(list->title_header, UNKNOWN_NAME))
3185 DrawTextSCentered(ystart, font_head, list->title_header);
3186 ystart += ystep_head;
3189 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3190 ystart += ystep_head;
3193 if (!strEqual(list->artist, UNKNOWN_NAME))
3195 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3196 DrawTextSCentered(ystart, font_head, list->artist_header);
3198 DrawTextSCentered(ystart, font_head, "by");
3200 ystart += ystep_head;
3202 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3203 ystart += ystep_head;
3206 if (!strEqual(list->album, UNKNOWN_NAME))
3208 if (!strEqual(list->album_header, UNKNOWN_NAME))
3209 DrawTextSCentered(ystart, font_head, list->album_header);
3211 DrawTextSCentered(ystart, font_head, "from the album");
3213 ystart += ystep_head;
3215 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3216 ystart += ystep_head;
3219 if (!strEqual(list->year, UNKNOWN_NAME))
3221 if (!strEqual(list->year_header, UNKNOWN_NAME))
3222 DrawTextSCentered(ystart, font_head, list->year_header);
3224 DrawTextSCentered(ystart, font_head, "from the year");
3226 ystart += ystep_head;
3228 DrawTextFCentered(ystart, font_text, "%s", list->year);
3229 ystart += ystep_head;
3232 DrawTextSCentered(ybottom, FONT_TEXT_4,
3233 "Press any key or button for next page");
3235 if (button != MB_MENU_INITIALIZE)
3236 FadeIn(REDRAW_FIELD);
3239 if (list != NULL && list->is_sound && sound_info[list->music].loop)
3240 PlaySoundLoop(list->music);
3243 static void DrawInfoScreen_CreditsScreen(int screen_nr)
3245 int font_title = MENU_INFO_FONT_TITLE;
3246 int font_head = MENU_INFO_FONT_HEAD;
3247 int font_text = MENU_INFO_FONT_TEXT;
3248 int font_foot = MENU_INFO_FONT_FOOT;
3249 int spacing_title = menu.headline1_spacing_info[info_mode];
3250 int spacing_head = menu.headline2_spacing_info[info_mode];
3251 int spacing_para = menu.paragraph_spacing_info[info_mode];
3252 int spacing_line = menu.line_spacing_info[info_mode];
3253 int ystep_title = getMenuTextStep(spacing_title, font_title);
3254 int ystep_head = getMenuTextStep(spacing_head, font_head);
3255 int ystep_para = getMenuTextStep(spacing_para, font_text);
3256 int ystep_line = getMenuTextStep(spacing_line, font_text);
3257 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3258 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3263 DrawTextSCentered(ystart, font_title, "Credits:");
3264 ystart += ystep_title;
3268 DrawTextSCentered(ystart, font_head,
3269 "Special thanks to");
3270 ystart += ystep_head;
3271 DrawTextSCentered(ystart, font_text,
3273 ystart += ystep_head;
3274 DrawTextSCentered(ystart, font_head,
3276 ystart += ystep_head;
3277 DrawTextSCentered(ystart, font_text,
3278 "\"Boulder Dash\"");
3279 ystart += ystep_head;
3280 DrawTextSCentered(ystart, font_head,
3282 ystart += ystep_head;
3283 DrawTextSCentered(ystart, font_text,
3285 ystart += ystep_head;
3286 DrawTextSCentered(ystart, font_head,
3288 ystart += ystep_head;
3289 DrawTextSCentered(ystart, font_text,
3290 "First Star Software");
3292 else if (screen_nr == 1)
3294 DrawTextSCentered(ystart, font_head,
3295 "Special thanks to");
3296 ystart += ystep_head;
3297 DrawTextSCentered(ystart, font_text,
3298 "Klaus Heinz & Volker Wertich");
3299 ystart += ystep_head;
3300 DrawTextSCentered(ystart, font_head,
3302 ystart += ystep_head;
3303 DrawTextSCentered(ystart, font_text,
3304 "\"Emerald Mine\"");
3305 ystart += ystep_head;
3306 DrawTextSCentered(ystart, font_head,
3308 ystart += ystep_head;
3309 DrawTextSCentered(ystart, font_text,
3311 ystart += ystep_head;
3312 DrawTextSCentered(ystart, font_head,
3314 ystart += ystep_head;
3315 DrawTextSCentered(ystart, font_text,
3318 else if (screen_nr == 2)
3320 DrawTextSCentered(ystart, font_head,
3321 "Special thanks to");
3322 ystart += ystep_head;
3323 DrawTextSCentered(ystart, font_text,
3324 "Michael Stopp & Philip Jespersen");
3325 ystart += ystep_head;
3326 DrawTextSCentered(ystart, font_head,
3328 ystart += ystep_head;
3329 DrawTextSCentered(ystart, font_text,
3331 ystart += ystep_head;
3332 DrawTextSCentered(ystart, font_head,
3334 ystart += ystep_head;
3335 DrawTextSCentered(ystart, font_text,
3337 ystart += ystep_head;
3338 DrawTextSCentered(ystart, font_head,
3340 ystart += ystep_head;
3341 DrawTextSCentered(ystart, font_text,
3342 "Digital Integration");
3344 else if (screen_nr == 3)
3346 DrawTextSCentered(ystart, font_head,
3347 "Special thanks to");
3348 ystart += ystep_head;
3349 DrawTextSCentered(ystart, font_text,
3350 "Hiroyuki Imabayashi");
3351 ystart += ystep_head;
3352 DrawTextSCentered(ystart, font_head,
3354 ystart += ystep_head;
3355 DrawTextSCentered(ystart, font_text,
3357 ystart += ystep_head;
3358 DrawTextSCentered(ystart, font_head,
3360 ystart += ystep_head;
3361 DrawTextSCentered(ystart, font_text,
3363 ystart += ystep_head;
3364 DrawTextSCentered(ystart, font_head,
3366 ystart += ystep_head;
3367 DrawTextSCentered(ystart, font_text,
3370 else if (screen_nr == 4)
3372 DrawTextSCentered(ystart, font_head,
3373 "Special thanks to");
3374 ystart += ystep_head;
3375 DrawTextSCentered(ystart, font_text,
3377 ystart += ystep_head;
3378 DrawTextSCentered(ystart, font_head,
3380 ystart += ystep_head;
3381 DrawTextSCentered(ystart, font_text,
3382 "J\xfcrgen Bonhagen");
3383 ystart += ystep_head;
3384 DrawTextSCentered(ystart, font_head,
3385 "for the continuous creation");
3386 ystart += ystep_line;
3387 DrawTextSCentered(ystart, font_head,
3388 "of outstanding level sets");
3390 else if (screen_nr == 5)
3392 DrawTextSCentered(ystart, font_head,
3394 ystart += ystep_head;
3395 DrawTextSCentered(ystart, font_text,
3397 ystart += ystep_head;
3398 DrawTextSCentered(ystart, font_head,
3399 "for ideas and inspiration by");
3400 ystart += ystep_head;
3401 DrawTextSCentered(ystart, font_text,
3403 ystart += ystep_para;
3405 DrawTextSCentered(ystart, font_head,
3407 ystart += ystep_head;
3408 DrawTextSCentered(ystart, font_text,
3410 ystart += ystep_head;
3411 DrawTextSCentered(ystart, font_head,
3412 "for ideas and inspiration by");
3413 ystart += ystep_head;
3414 DrawTextSCentered(ystart, font_text,
3417 else if (screen_nr == 6)
3419 DrawTextSCentered(ystart, font_head,
3421 ystart += ystep_head;
3422 DrawTextSCentered(ystart, font_text,
3424 ystart += ystep_head;
3425 DrawTextSCentered(ystart, font_head,
3426 "for the code base used for the");
3427 ystart += ystep_line;
3428 DrawTextSCentered(ystart, font_head,
3429 "native Emerald Mine engine");
3431 else if (screen_nr == 7)
3433 DrawTextSCentered(ystart, font_head,
3435 ystart += ystep_head;
3436 DrawTextSCentered(ystart, font_text,
3438 ystart += ystep_head;
3439 DrawTextSCentered(ystart, font_head,
3440 "for the initial DOS port");
3441 ystart += ystep_para;
3443 DrawTextSCentered(ystart, font_head,
3445 ystart += ystep_head;
3446 DrawTextSCentered(ystart, font_text,
3448 ystart += ystep_head;
3449 DrawTextSCentered(ystart, font_head,
3450 "for some additional toons");
3452 else if (screen_nr == 8)
3454 DrawTextSCentered(ystart, font_head,
3455 "And not to forget:");
3456 ystart += ystep_head;
3457 DrawTextSCentered(ystart, font_head,
3459 ystart += ystep_head;
3460 DrawTextSCentered(ystart, font_text,
3461 "All those who contributed");
3462 ystart += ystep_line;
3463 DrawTextSCentered(ystart, font_text,
3464 "levels to this game");
3465 ystart += ystep_line;
3466 DrawTextSCentered(ystart, font_text,
3470 DrawTextSCentered(ybottom, font_foot,
3471 "Press any key or button for next page");
3474 static void DrawInfoScreen_Credits(void)
3476 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_CREDITS);
3478 FadeMenuSoundsAndMusic();
3480 FadeOut(REDRAW_FIELD);
3482 HandleInfoScreen_Credits(MB_MENU_INITIALIZE);
3484 FadeIn(REDRAW_FIELD);
3487 void HandleInfoScreen_Credits(int button)
3489 static int screen_nr = 0;
3490 int num_screens = 9;
3492 if (button == MB_MENU_INITIALIZE)
3496 // DrawInfoScreen_CreditsScreen(screen_nr);
3499 if (button == MB_MENU_LEAVE)
3501 PlaySound(SND_MENU_ITEM_SELECTING);
3503 info_mode = INFO_MODE_MAIN;
3508 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE)
3510 if (button != MB_MENU_INITIALIZE)
3512 PlaySound(SND_MENU_ITEM_SELECTING);
3517 if (screen_nr >= num_screens)
3519 FadeMenuSoundsAndMusic();
3521 info_mode = INFO_MODE_MAIN;
3528 FadeSetNextScreen();
3530 if (button != MB_MENU_INITIALIZE)
3531 FadeOut(REDRAW_FIELD);
3533 DrawInfoScreen_CreditsScreen(screen_nr);
3535 if (button != MB_MENU_INITIALIZE)
3536 FadeIn(REDRAW_FIELD);
3540 PlayMenuSoundIfLoop();
3544 static void DrawInfoScreen_Program(void)
3546 int font_title = MENU_INFO_FONT_TITLE;
3547 int font_head = MENU_INFO_FONT_HEAD;
3548 int font_text = MENU_INFO_FONT_TEXT;
3549 int font_foot = MENU_INFO_FONT_FOOT;
3550 int spacing_title = menu.headline1_spacing_info[info_mode];
3551 int spacing_head = menu.headline2_spacing_info[info_mode];
3552 int spacing_para = menu.paragraph_spacing_info[info_mode];
3553 int spacing_line = menu.line_spacing_info[info_mode];
3554 int ystep_title = getMenuTextStep(spacing_title, font_title);
3555 int ystep_head = getMenuTextStep(spacing_head, font_head);
3556 int ystep_para = getMenuTextStep(spacing_para, font_text);
3557 int ystep_line = getMenuTextStep(spacing_line, font_text);
3558 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3559 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3561 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM);
3563 FadeOut(REDRAW_FIELD);
3568 DrawTextSCentered(ystart, font_title, "Program Information:");
3569 ystart += ystep_title;
3571 DrawTextSCentered(ystart, font_head,
3572 "This game is Freeware!");
3573 ystart += ystep_head;
3574 DrawTextSCentered(ystart, font_head,
3575 "If you like it, send e-mail to:");
3576 ystart += ystep_head;
3577 DrawTextSCentered(ystart, font_text,
3578 setup.internal.program_email);
3579 ystart += ystep_para;
3581 DrawTextSCentered(ystart, font_head,
3582 "More information and levels:");
3583 ystart += ystep_head;
3584 DrawTextSCentered(ystart, font_text,
3585 setup.internal.program_website);
3586 ystart += ystep_para;
3588 DrawTextSCentered(ystart, font_head,
3589 "If you have created new levels,");
3590 ystart += ystep_line;
3591 DrawTextSCentered(ystart, font_head,
3592 "send them to me to include them!");
3593 ystart += ystep_head;
3594 DrawTextSCentered(ystart, font_head,
3597 DrawTextSCentered(ybottom, font_foot,
3598 "Press any key or button for info menu");
3600 FadeIn(REDRAW_FIELD);
3603 void HandleInfoScreen_Program(int button)
3605 if (button == MB_MENU_LEAVE)
3607 PlaySound(SND_MENU_ITEM_SELECTING);
3609 info_mode = INFO_MODE_MAIN;
3614 else if (button == MB_MENU_CHOICE)
3616 PlaySound(SND_MENU_ITEM_SELECTING);
3618 FadeMenuSoundsAndMusic();
3620 info_mode = INFO_MODE_MAIN;
3625 PlayMenuSoundIfLoop();
3629 static void DrawInfoScreen_Version(void)
3631 int font_title = MENU_INFO_FONT_TITLE;
3632 int font_head = MENU_INFO_FONT_HEAD;
3633 int font_text = MENU_INFO_FONT_TEXT;
3634 int font_foot = MENU_INFO_FONT_FOOT;
3635 int spacing_title = menu.headline1_spacing_info[info_mode];
3636 int spacing_head = menu.headline2_spacing_info[info_mode];
3637 int spacing_para = menu.paragraph_spacing_info[info_mode];
3638 int spacing_line = menu.line_spacing_info[info_mode];
3639 int xstep = getFontWidth(font_text);
3640 int ystep_title = getMenuTextStep(spacing_title, font_title);
3641 int ystep_head = getMenuTextStep(spacing_head, font_head);
3642 int ystep_para = getMenuTextStep(spacing_para, font_text);
3643 int ystep_line = getMenuTextStep(spacing_line, font_text);
3644 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3645 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3646 int xstart1 = mSX - SX + 2 * xstep;
3647 int xstart2 = mSX - SX + 18 * xstep;
3648 int xstart3 = mSX - SX + 28 * xstep;
3649 SDL_version sdl_version_compiled;
3650 const SDL_version *sdl_version_linked;
3651 int driver_name_len = 10;
3652 SDL_version sdl_version_linked_ext;
3653 const char *driver_name = NULL;
3655 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3657 FadeOut(REDRAW_FIELD);
3662 DrawTextSCentered(ystart, font_title, "Version Information:");
3663 ystart += ystep_title;
3665 DrawTextF(xstart1, ystart, font_head, "Name");
3666 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3667 ystart += ystep_line;
3669 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3671 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3672 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3673 ystart += ystep_line;
3675 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3676 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3677 ystart += ystep_line;
3681 DrawTextF(xstart1, ystart, font_head, "Version");
3682 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3683 ystart += ystep_line;
3686 DrawTextF(xstart1, ystart, font_head, "Platform");
3687 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3689 PLATFORM_XX_BIT_STRING);
3690 ystart += ystep_line;
3692 DrawTextF(xstart1, ystart, font_head, "Target");
3693 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3694 ystart += ystep_line;
3696 DrawTextF(xstart1, ystart, font_head, "Source date");
3697 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3698 ystart += ystep_para;
3700 DrawTextF(xstart1, ystart, font_head, "Library");
3701 DrawTextF(xstart2, ystart, font_head, "compiled");
3702 DrawTextF(xstart3, ystart, font_head, "linked");
3703 ystart += ystep_head;
3705 SDL_VERSION(&sdl_version_compiled);
3706 SDL_GetVersion(&sdl_version_linked_ext);
3707 sdl_version_linked = &sdl_version_linked_ext;
3709 DrawTextF(xstart1, ystart, font_text, "SDL");
3710 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3711 sdl_version_compiled.major,
3712 sdl_version_compiled.minor,
3713 sdl_version_compiled.patch);
3714 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3715 sdl_version_linked->major,
3716 sdl_version_linked->minor,
3717 sdl_version_linked->patch);
3718 ystart += ystep_line;
3720 SDL_IMAGE_VERSION(&sdl_version_compiled);
3721 sdl_version_linked = IMG_Linked_Version();
3723 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3724 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3725 sdl_version_compiled.major,
3726 sdl_version_compiled.minor,
3727 sdl_version_compiled.patch);
3728 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3729 sdl_version_linked->major,
3730 sdl_version_linked->minor,
3731 sdl_version_linked->patch);
3732 ystart += ystep_line;
3734 SDL_MIXER_VERSION(&sdl_version_compiled);
3735 sdl_version_linked = Mix_Linked_Version();
3737 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3738 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3739 sdl_version_compiled.major,
3740 sdl_version_compiled.minor,
3741 sdl_version_compiled.patch);
3742 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3743 sdl_version_linked->major,
3744 sdl_version_linked->minor,
3745 sdl_version_linked->patch);
3746 ystart += ystep_line;
3748 SDL_NET_VERSION(&sdl_version_compiled);
3749 sdl_version_linked = SDLNet_Linked_Version();
3751 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3752 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3753 sdl_version_compiled.major,
3754 sdl_version_compiled.minor,
3755 sdl_version_compiled.patch);
3756 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3757 sdl_version_linked->major,
3758 sdl_version_linked->minor,
3759 sdl_version_linked->patch);
3760 ystart += ystep_para;
3762 DrawTextF(xstart1, ystart, font_head, "Driver");
3763 DrawTextF(xstart2, ystart, font_head, "Requested");
3764 DrawTextF(xstart3, ystart, font_head, "Used");
3765 ystart += ystep_head;
3768 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3770 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3771 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3772 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3773 ystart += ystep_line;
3776 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3778 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3779 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3780 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3781 ystart += ystep_line;
3784 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3786 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3787 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3788 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3790 DrawTextSCentered(ybottom, font_foot,
3791 "Press any key or button for info menu");
3793 FadeIn(REDRAW_FIELD);
3796 void HandleInfoScreen_Version(int button)
3798 if (button == MB_MENU_LEAVE)
3800 PlaySound(SND_MENU_ITEM_SELECTING);
3802 info_mode = INFO_MODE_MAIN;
3807 else if (button == MB_MENU_CHOICE)
3809 PlaySound(SND_MENU_ITEM_SELECTING);
3811 FadeMenuSoundsAndMusic();
3813 info_mode = INFO_MODE_MAIN;
3818 PlayMenuSoundIfLoop();
3822 static void DrawInfoScreen_LevelSet(void)
3824 struct TitleMessageInfo *tmi = &readme;
3825 char *filename = getLevelSetInfoFilename();
3826 char *title = "Level Set Information:";
3827 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART1;
3828 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3830 if (filename == NULL)
3832 DrawInfoScreen_NotAvailable(title, "No information for this level set.");
3837 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET);
3839 FadeOut(REDRAW_FIELD);
3844 DrawTextSCentered(ystart, FONT_TEXT_1, title);
3846 // if x position set to "-1", automatically determine by playfield width
3848 tmi->x = SXSIZE / 2;
3850 // if y position set to "-1", use static default value
3854 // if width set to "-1", automatically determine by playfield width
3855 if (tmi->width == -1)
3856 tmi->width = SXSIZE - 2 * TILEX;
3858 // if height set to "-1", automatically determine by playfield height
3859 if (tmi->height == -1)
3860 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3862 // if chars set to "-1", automatically determine by text and font width
3863 if (tmi->chars == -1)
3864 tmi->chars = tmi->width / getFontWidth(tmi->font);
3866 tmi->width = tmi->chars * getFontWidth(tmi->font);
3868 // if lines set to "-1", automatically determine by text and font height
3869 if (tmi->lines == -1)
3870 tmi->lines = tmi->height / getFontHeight(tmi->font);
3872 tmi->height = tmi->lines * getFontHeight(tmi->font);
3874 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3875 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3876 tmi->autowrap, tmi->centered, tmi->parse_comments);
3878 DrawTextSCentered(ybottom, FONT_TEXT_4,
3879 "Press any key or button for info menu");
3881 FadeIn(REDRAW_FIELD);
3884 static void HandleInfoScreen_LevelSet(int button)
3886 if (button == MB_MENU_LEAVE)
3888 PlaySound(SND_MENU_ITEM_SELECTING);
3890 info_mode = INFO_MODE_MAIN;
3895 else if (button == MB_MENU_CHOICE)
3897 PlaySound(SND_MENU_ITEM_SELECTING);
3899 FadeMenuSoundsAndMusic();
3901 info_mode = INFO_MODE_MAIN;
3906 PlayMenuSoundIfLoop();
3910 static void DrawInfoScreen(void)
3912 if (info_mode == INFO_MODE_TITLE)
3913 DrawInfoScreen_TitleScreen();
3914 else if (info_mode == INFO_MODE_ELEMENTS)
3915 DrawInfoScreen_Elements();
3916 else if (info_mode == INFO_MODE_MUSIC)
3917 DrawInfoScreen_Music();
3918 else if (info_mode == INFO_MODE_CREDITS)
3919 DrawInfoScreen_Credits();
3920 else if (info_mode == INFO_MODE_PROGRAM)
3921 DrawInfoScreen_Program();
3922 else if (info_mode == INFO_MODE_VERSION)
3923 DrawInfoScreen_Version();
3924 else if (info_mode == INFO_MODE_LEVELSET)
3925 DrawInfoScreen_LevelSet();
3927 DrawInfoScreen_Main();
3929 if (info_mode != INFO_MODE_MAIN &&
3930 info_mode != INFO_MODE_TITLE &&
3931 info_mode != INFO_MODE_MUSIC)
3932 PlayMenuSoundsAndMusic();
3935 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
3937 if (info_mode == INFO_MODE_TITLE)
3938 HandleInfoScreen_TitleScreen(button);
3939 else if (info_mode == INFO_MODE_ELEMENTS)
3940 HandleInfoScreen_Elements(button);
3941 else if (info_mode == INFO_MODE_MUSIC)
3942 HandleInfoScreen_Music(button);
3943 else if (info_mode == INFO_MODE_CREDITS)
3944 HandleInfoScreen_Credits(button);
3945 else if (info_mode == INFO_MODE_PROGRAM)
3946 HandleInfoScreen_Program(button);
3947 else if (info_mode == INFO_MODE_VERSION)
3948 HandleInfoScreen_Version(button);
3949 else if (info_mode == INFO_MODE_LEVELSET)
3950 HandleInfoScreen_LevelSet(button);
3952 HandleInfoScreen_Main(mx, my, dx, dy, button);
3956 // ============================================================================
3957 // type name functions
3958 // ============================================================================
3960 void HandleTypeName(int newxpos, Key key)
3962 static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
3963 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
3964 struct TextPosInfo *pos = mci->pos_input;
3965 int startx = mSX + ALIGNED_TEXT_XPOS(pos);
3966 int starty = mSY + ALIGNED_TEXT_YPOS(pos);
3967 static int xpos = 0;
3968 int font_nr = pos->font;
3969 int font_active_nr = FONT_ACTIVE(font_nr);
3970 int font_width = getFontWidth(font_active_nr);
3971 char key_char = getValidConfigValueChar(getCharFromKey(key));
3972 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
3973 boolean is_active = TRUE;
3975 DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr);
3979 strcpy(last_player_name, setup.player_name);
3983 StartTextInput(startx, starty, pos->width, pos->height);
3985 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
3987 setup.player_name[xpos] = key_char;
3988 setup.player_name[xpos + 1] = 0;
3992 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
3996 setup.player_name[xpos] = 0;
3998 else if (key == KSYM_Return && xpos > 0)
4004 SetGameStatus(GAME_MODE_MAIN);
4006 else if (key == KSYM_Escape)
4008 strcpy(setup.player_name, last_player_name);
4012 SetGameStatus(GAME_MODE_MAIN);
4017 pos->width = (strlen(setup.player_name) + 1) * font_width;
4018 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4020 DrawText(startx, starty, setup.player_name, font_active_nr);
4021 DrawText(startx + xpos * font_width, starty, "_", font_active_nr);
4025 pos->width = strlen(setup.player_name) * font_width;
4026 startx = mSX + ALIGNED_TEXT_XPOS(pos);
4028 DrawText(startx, starty, setup.player_name, font_nr);
4035 // ============================================================================
4036 // tree menu functions
4037 // ============================================================================
4039 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4041 if (game_status != GAME_MODE_SETUP ||
4042 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4045 int max_text_size = 0;
4048 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4049 max_text_size = MAX(max_text_size, strlen(node->name));
4051 int num_entries = numTreeInfoInGroup(ti);
4052 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4053 int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
4054 int button_width = SC_MENUBUTTON_XSIZE;
4055 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4056 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4057 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4058 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4059 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4060 int align_xoffset = MAX(0, align_xoffset_raw);
4062 return align_xoffset;
4065 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4067 if (game_status != GAME_MODE_SETUP ||
4068 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4071 int num_entries = numTreeInfoInGroup(ti);
4072 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4073 int font_height = getFontHeight(FONT_TEXT_1);
4074 int text_height = font_height * num_page_entries;
4075 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4076 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4077 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4078 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4079 int align_yoffset = MAX(0, align_yoffset_raw);
4081 return align_yoffset;
4084 static void DrawChooseTree(TreeInfo **ti_ptr)
4086 int fade_mask = REDRAW_FIELD;
4089 fade_mask = REDRAW_ALL;
4091 if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4093 SetGameStatus(GAME_MODE_MAIN);
4102 FreeScreenGadgets();
4103 CreateScreenGadgets();
4107 // needed if different viewport properties defined for choosing level (set)
4108 ChangeViewportPropertiesIfNeeded();
4110 if (game_status == GAME_MODE_LEVELNR)
4111 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4112 else if (game_status == GAME_MODE_LEVELS)
4113 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4117 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4119 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4120 MapScreenTreeGadgets(*ti_ptr);
4122 DrawMaskedBorder(fade_mask);
4127 static void drawChooseTreeList(int first_entry, int num_page_entries,
4130 int num_entries = numTreeInfoInGroup(ti);
4131 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4132 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4133 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4134 int font_nr = FONT_TEXT_1;
4135 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
4137 char *title_string = NULL;
4138 int yoffset_sets = MENU_TITLE1_YPOS;
4139 int yoffset_setup = 16;
4140 int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR ||
4141 ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4143 title_string = ti->infotext;
4145 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4147 clearMenuListArea();
4149 for (i = 0; i < num_page_entries; i++)
4151 TreeInfo *node, *node_first;
4152 int entry_pos = first_entry + i;
4153 int xpos = MENU_SCREEN_START_XPOS;
4154 int ypos = MENU_SCREEN_START_YPOS + i;
4155 int startx = amSX + xpos * 32;
4156 int starty = amSY + ypos * 32;
4157 int startx_text = startx + font_xoffset;
4158 int endx_text = amSX + screen_width;
4159 int max_text_size = endx_text - startx_text;
4160 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4161 char buffer[max_buffer_len + 1];
4163 node_first = getTreeInfoFirstGroupEntry(ti);
4164 node = getTreeInfoFromPos(node_first, entry_pos);
4166 strncpy(buffer, node->name, max_buffer_len);
4167 buffer[max_buffer_len] = '\0';
4169 DrawText(startx, starty, buffer, font_nr + node->color);
4171 if (node->parent_link)
4172 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4173 else if (node->level_group)
4174 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4176 initCursor(i, IMG_MENU_BUTTON);
4179 redraw_mask |= REDRAW_FIELD;
4182 static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti)
4184 TreeInfo *node, *node_first;
4185 int x, last_redraw_mask = redraw_mask;
4186 int ypos = MENU_TITLE2_YPOS;
4187 int font_nr = FONT_TITLE_2;
4189 if (ti->type == TREE_TYPE_LEVEL_NR)
4190 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4192 if (ti->type != TREE_TYPE_LEVEL_DIR)
4195 node_first = getTreeInfoFirstGroupEntry(ti);
4196 node = getTreeInfoFromPos(node_first, entry_pos);
4198 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4200 if (node->parent_link)
4201 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4202 node->node_parent->name);
4203 else if (node->level_group)
4204 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4206 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4207 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4208 node->levels, (node->levels > 1 ? "levels" : "level"),
4211 // let BackToFront() redraw only what is needed
4212 redraw_mask = last_redraw_mask;
4213 for (x = 0; x < SCR_FIELDX; x++)
4214 MarkTileDirty(x, 1);
4217 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4220 TreeInfo *ti = *ti_ptr;
4221 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4222 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4223 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4225 int y = ti->cl_cursor;
4226 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4227 int num_entries = numTreeInfoInGroup(ti);
4228 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4229 boolean position_set_by_scrollbar = (dx == 999);
4231 if (button == MB_MENU_INITIALIZE)
4233 int num_entries = numTreeInfoInGroup(ti);
4234 int entry_pos = posTreeInfo(ti);
4236 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4237 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4239 if (ti->cl_first == -1)
4241 // only on initialization
4242 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4243 ti->cl_cursor = entry_pos - ti->cl_first;
4245 else if (ti->cl_cursor >= num_page_entries ||
4246 (num_entries > num_page_entries &&
4247 num_entries - ti->cl_first < num_page_entries))
4249 // only after change of list size (by custom graphic configuration)
4250 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4251 ti->cl_cursor = entry_pos - ti->cl_first;
4254 if (position_set_by_scrollbar)
4257 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4260 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4261 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4262 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4266 else if (button == MB_MENU_LEAVE)
4270 PlaySound(SND_MENU_ITEM_SELECTING);
4272 if (ti->node_parent)
4274 *ti_ptr = ti->node_parent;
4275 DrawChooseTree(ti_ptr);
4277 else if (game_status == GAME_MODE_SETUP)
4279 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4280 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4281 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4283 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4284 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4285 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4286 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4287 execSetupGraphics();
4288 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4289 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4290 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4292 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4293 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4294 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4295 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4296 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4297 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4298 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4299 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4306 if (game_status == GAME_MODE_LEVELNR)
4308 int new_level_nr = atoi(level_number_current->identifier);
4310 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4313 SetGameStatus(GAME_MODE_MAIN);
4321 if (mx || my) // mouse input
4323 x = (mx - amSX) / 32;
4324 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4326 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4328 // move cursor instead of scrolling when already at start/end of list
4329 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4331 else if (dy == +1 * SCROLL_LINE &&
4332 ti->cl_first + num_page_entries == num_entries)
4335 // handle scrolling screen one line or page
4336 if (ti->cl_cursor + dy < 0 ||
4337 ti->cl_cursor + dy > num_page_entries - 1)
4339 boolean redraw = FALSE;
4341 if (ABS(dy) == SCROLL_PAGE)
4342 step = num_page_entries - 1;
4344 if (dy < 0 && ti->cl_first > 0)
4346 // scroll page/line up
4348 ti->cl_first -= step;
4349 if (ti->cl_first < 0)
4354 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4356 // scroll page/line down
4358 ti->cl_first += step;
4359 if (ti->cl_first + num_page_entries > num_entries)
4360 ti->cl_first = MAX(0, num_entries - num_page_entries);
4367 drawChooseTreeList(ti->cl_first, num_page_entries, ti);
4368 drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti);
4369 drawChooseTreeCursor(ti->cl_cursor, TRUE);
4371 AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL,
4378 // handle moving cursor one line
4379 y = ti->cl_cursor + dy;
4384 TreeInfo *node_first, *node_cursor;
4385 int entry_pos = ti->cl_first + y;
4387 node_first = getTreeInfoFirstGroupEntry(ti);
4388 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4390 if (node_cursor->node_group)
4394 PlaySound(SND_MENU_ITEM_SELECTING);
4396 node_cursor->cl_first = ti->cl_first;
4397 node_cursor->cl_cursor = ti->cl_cursor;
4398 *ti_ptr = node_cursor->node_group;
4399 DrawChooseTree(ti_ptr);
4404 else if (dx == -1 && ti->node_parent)
4408 PlaySound(SND_MENU_ITEM_SELECTING);
4410 *ti_ptr = ti->node_parent;
4411 DrawChooseTree(ti_ptr);
4416 if (!anyScrollbarGadgetActive() &&
4417 IN_VIS_MENU(x, y) &&
4418 mx < mx_right_border &&
4419 y >= 0 && y < num_page_entries)
4423 if (y != ti->cl_cursor)
4425 PlaySound(SND_MENU_ITEM_ACTIVATING);
4427 drawChooseTreeCursor(ti->cl_cursor, FALSE);
4428 drawChooseTreeCursor(y, TRUE);
4429 drawChooseTreeInfo(ti->cl_first + y, ti);
4435 if (game_status == GAME_MODE_SETUP)
4437 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4438 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4439 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4441 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4442 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4443 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4444 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4445 execSetupGraphics();
4446 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4447 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4448 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4450 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4451 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4452 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4453 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4454 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4455 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4456 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4457 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4466 TreeInfo *node_first, *node_cursor;
4467 int entry_pos = ti->cl_first + y;
4469 PlaySound(SND_MENU_ITEM_SELECTING);
4471 node_first = getTreeInfoFirstGroupEntry(ti);
4472 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4474 if (node_cursor->node_group)
4478 node_cursor->cl_first = ti->cl_first;
4479 node_cursor->cl_cursor = ti->cl_cursor;
4480 *ti_ptr = node_cursor->node_group;
4481 DrawChooseTree(ti_ptr);
4483 else if (node_cursor->parent_link)
4487 *ti_ptr = node_cursor->node_parent;
4488 DrawChooseTree(ti_ptr);
4494 node_cursor->cl_first = ti->cl_first;
4495 node_cursor->cl_cursor = ti->cl_cursor;
4496 *ti_ptr = node_cursor;
4498 if (ti->type == TREE_TYPE_LEVEL_DIR)
4500 LoadLevelSetup_SeriesInfo();
4502 SaveLevelSetup_LastSeries();
4503 SaveLevelSetup_SeriesInfo();
4507 if (game_status == GAME_MODE_SETUP)
4509 if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4510 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4511 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4513 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4514 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4515 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4516 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4517 execSetupGraphics();
4518 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4519 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4520 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4522 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4523 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4524 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4525 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4526 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4527 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4528 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4529 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4536 if (game_status == GAME_MODE_LEVELNR)
4538 int new_level_nr = atoi(level_number_current->identifier);
4540 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4543 SetGameStatus(GAME_MODE_MAIN);
4552 void DrawChooseLevelSet(void)
4554 FadeMenuSoundsAndMusic();
4556 DrawChooseTree(&leveldir_current);
4558 PlayMenuSoundsAndMusic();
4561 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
4563 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
4566 void DrawChooseLevelNr(void)
4570 FadeMenuSoundsAndMusic();
4572 if (level_number != NULL)
4574 freeTreeInfo(level_number);
4576 level_number = NULL;
4579 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
4581 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
4582 char identifier[32], name[64];
4585 // temporarily load level info to get level name
4586 LoadLevelInfoOnly(i);
4588 ti->node_top = &level_number;
4589 ti->sort_priority = 10000 + value;
4590 ti->color = (level.no_level_file ? FC_BLUE :
4591 LevelStats_getSolved(i) ? FC_GREEN :
4592 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
4594 snprintf(identifier, sizeof(identifier), "%d", value);
4595 snprintf(name, sizeof(name), "%03d: %s", value,
4596 (level.no_level_file ? "(no file)" : level.name));
4598 setString(&ti->identifier, identifier);
4599 setString(&ti->name, name);
4600 setString(&ti->name_sorting, name);
4602 pushTreeInfo(&level_number, ti);
4605 // sort level number values to start with lowest level number
4606 sortTreeInfo(&level_number);
4608 // set current level number to current level number
4609 level_number_current =
4610 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
4612 // if that also fails, set current level number to first available level
4613 if (level_number_current == NULL)
4614 level_number_current = level_number;
4616 DrawChooseTree(&level_number_current);
4618 PlayMenuSoundsAndMusic();
4621 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
4623 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
4626 void DrawHallOfFame(int level_nr, int highlight_position)
4628 int fade_mask = REDRAW_FIELD;
4631 fade_mask = REDRAW_ALL;
4634 FadeMenuSoundsAndMusic();
4636 // (this is needed when called from GameEnd() after winning a game)
4637 KeyboardAutoRepeatOn();
4639 // (this is needed when called from GameEnd() after winning a game)
4640 SetDrawDeactivationMask(REDRAW_NONE);
4641 SetDrawBackgroundMask(REDRAW_FIELD);
4643 if (highlight_position < 0)
4644 LoadScore(level_nr);
4646 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
4648 FadeSetEnterScreen();
4652 // needed if different viewport properties defined for scores
4653 ChangeViewportPropertiesIfNeeded();
4655 PlayMenuSoundsAndMusic();
4657 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4659 HandleHallOfFame(level_nr, highlight_position, 0, 0, MB_MENU_INITIALIZE);
4661 DrawMaskedBorder(fade_mask);
4666 static void drawHallOfFameList(int level_nr, int first_entry,
4667 int highlight_position)
4671 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4674 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, "Hall Of Fame");
4675 DrawTextFCentered(MENU_TITLE2_YPOS, FONT_TITLE_2,
4676 "HighScores of Level %d", level_nr);
4678 for (i = 0; i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
4680 int entry = first_entry + i;
4681 boolean active = (entry == highlight_position);
4682 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4683 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4684 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4685 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4686 int dxoff = getFontDrawOffsetX(font_nr1);
4687 int dx1 = 3 * getFontWidth(font_nr1);
4688 int dx2 = dx1 + getFontWidth(font_nr1);
4689 int dx3 = SXSIZE - 2 * (mSX - SX + dxoff) - 5 * getFontWidth(font_nr4);
4690 int num_dots = (dx3 - dx2) / getFontWidth(font_nr3);
4691 int sy = mSY + 64 + i * 32;
4693 DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1);
4694 DrawText(mSX + dx1, sy, ".", font_nr1);
4696 for (j = 0; j < num_dots; j++)
4697 DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3);
4699 if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME))
4700 DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2);
4702 DrawText(mSX + dx3, sy, int2str(highscore[entry].Score, 5), font_nr4);
4705 redraw_mask |= REDRAW_FIELD;
4708 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
4710 static int level_nr = 0;
4711 static int first_entry = 0;
4712 static int highlight_position = 0;
4713 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4715 if (button == MB_MENU_INITIALIZE)
4719 highlight_position = my;
4721 drawHallOfFameList(level_nr, first_entry, highlight_position);
4726 if (ABS(dy) == SCROLL_PAGE) // handle scrolling one page
4727 step = NUM_MENU_ENTRIES_ON_SCREEN - 1;
4731 if (first_entry > 0)
4733 first_entry -= step;
4734 if (first_entry < 0)
4737 drawHallOfFameList(level_nr, first_entry, highlight_position);
4742 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN < MAX_SCORE_ENTRIES)
4744 first_entry += step;
4745 if (first_entry + NUM_MENU_ENTRIES_ON_SCREEN > MAX_SCORE_ENTRIES)
4746 first_entry = MAX(0, MAX_SCORE_ENTRIES - NUM_MENU_ENTRIES_ON_SCREEN);
4748 drawHallOfFameList(level_nr, first_entry, highlight_position);
4751 else if (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE)
4753 PlaySound(SND_MENU_ITEM_SELECTING);
4755 FadeSound(SND_BACKGROUND_SCORES);
4757 if (button == MB_MENU_CHOICE &&
4758 game_status_last_screen == GAME_MODE_PLAYING &&
4759 setup.auto_play_next_level && setup.increment_levels &&
4760 level_nr < leveldir_current->last_level &&
4763 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4767 SetGameStatus(GAME_MODE_MAIN);
4773 if (game_status == GAME_MODE_SCORES)
4774 PlayMenuSoundIfLoop();
4778 // ============================================================================
4779 // setup screen functions
4780 // ============================================================================
4782 static struct TokenInfo *setup_info;
4783 static int num_setup_info; // number of setup entries shown on screen
4784 static int max_setup_info; // total number of setup entries in list
4786 static char *window_size_text;
4787 static char *scaling_type_text;
4788 static char *rendering_mode_text;
4789 static char *vsync_mode_text;
4790 static char *scroll_delay_text;
4791 static char *snapshot_mode_text;
4792 static char *game_speed_text;
4793 static char *network_server_text;
4794 static char *graphics_set_name;
4795 static char *sounds_set_name;
4796 static char *music_set_name;
4797 static char *volume_simple_text;
4798 static char *volume_loops_text;
4799 static char *volume_music_text;
4800 static char *touch_controls_text;
4801 static char *move_distance_text;
4802 static char *drop_distance_text;
4803 static char *transparency_text;
4804 static char *grid_size_text[2][2];
4806 static void execSetupMain(void)
4808 setup_mode = SETUP_MODE_MAIN;
4813 static void execSetupGame_setGameSpeeds(boolean update_value)
4815 if (setup.game_speed_extended)
4817 game_speeds_list = game_speeds_list_extended;
4818 game_speeds = game_speeds_extended;
4822 game_speeds_list = game_speeds_list_normal;
4823 game_speeds = game_speeds_normal;
4826 if (game_speeds == NULL)
4830 for (i = 0; game_speeds_list[i].value != -1; i++)
4832 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4833 char identifier[32], name[32];
4834 int value = game_speeds_list[i].value;
4835 char *text = game_speeds_list[i].text;
4837 ti->node_top = &game_speeds;
4838 ti->sort_priority = 10000 - value;
4840 sprintf(identifier, "%d", value);
4841 sprintf(name, "%s", text);
4843 setString(&ti->identifier, identifier);
4844 setString(&ti->name, name);
4845 setString(&ti->name_sorting, name);
4846 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
4848 pushTreeInfo(&game_speeds, ti);
4851 // sort game speed values to start with slowest game speed
4852 sortTreeInfo(&game_speeds);
4854 update_value = TRUE;
4859 // set current game speed to configured game speed value
4860 game_speed_current =
4861 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
4863 // if that fails, set current game speed to reliable default value
4864 if (game_speed_current == NULL)
4865 game_speed_current =
4866 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
4868 // if that also fails, set current game speed to first available speed
4869 if (game_speed_current == NULL)
4870 game_speed_current = game_speeds;
4872 if (setup.game_speed_extended)
4873 game_speeds_extended = game_speeds;
4875 game_speeds_normal = game_speeds;
4878 setup.game_frame_delay = atoi(game_speed_current->identifier);
4880 // needed for displaying game speed text instead of identifier
4881 game_speed_text = game_speed_current->name;
4884 static void execSetupGame_setScrollDelays(void)
4886 if (scroll_delays == NULL)
4890 for (i = 0; scroll_delays_list[i].value != -1; i++)
4892 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4893 char identifier[32], name[32];
4894 int value = scroll_delays_list[i].value;
4895 char *text = scroll_delays_list[i].text;
4897 ti->node_top = &scroll_delays;
4898 ti->sort_priority = value;
4900 sprintf(identifier, "%d", value);
4901 sprintf(name, "%s", text);
4903 setString(&ti->identifier, identifier);
4904 setString(&ti->name, name);
4905 setString(&ti->name_sorting, name);
4906 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
4908 pushTreeInfo(&scroll_delays, ti);
4911 // sort scroll delay values to start with lowest scroll delay value
4912 sortTreeInfo(&scroll_delays);
4914 // set current scroll delay value to configured scroll delay value
4915 scroll_delay_current =
4916 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
4918 // if that fails, set current scroll delay to reliable default value
4919 if (scroll_delay_current == NULL)
4920 scroll_delay_current =
4921 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
4923 // if that also fails, set current scroll delay to first available value
4924 if (scroll_delay_current == NULL)
4925 scroll_delay_current = scroll_delays;
4928 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
4930 // needed for displaying scroll delay text instead of identifier
4931 scroll_delay_text = scroll_delay_current->name;
4934 static void execSetupGame_setSnapshotModes(void)
4936 if (snapshot_modes == NULL)
4940 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
4942 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
4943 char identifier[32], name[32];
4944 char *value = snapshot_modes_list[i].value;
4945 char *text = snapshot_modes_list[i].text;
4947 ti->node_top = &snapshot_modes;
4948 ti->sort_priority = i;
4950 sprintf(identifier, "%s", value);
4951 sprintf(name, "%s", text);
4953 setString(&ti->identifier, identifier);
4954 setString(&ti->name, name);
4955 setString(&ti->name_sorting, name);
4956 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
4958 pushTreeInfo(&snapshot_modes, ti);
4961 // sort snapshot mode values to start with lowest snapshot mode value
4962 sortTreeInfo(&snapshot_modes);
4964 // set current snapshot mode value to configured snapshot mode value
4965 snapshot_mode_current =
4966 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
4968 // if that fails, set current snapshot mode to reliable default value
4969 if (snapshot_mode_current == NULL)
4970 snapshot_mode_current =
4971 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
4973 // if that also fails, set current snapshot mode to first available value
4974 if (snapshot_mode_current == NULL)
4975 snapshot_mode_current = snapshot_modes;
4978 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
4980 // needed for displaying snapshot mode text instead of identifier
4981 snapshot_mode_text = snapshot_mode_current->name;
4984 static void execSetupGame_setNetworkServerText(void)
4986 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
4988 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
4992 strncpy(network_server_hostname, setup.network_server_hostname,
4993 MAX_SETUP_TEXT_INPUT_LEN);
4994 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
4997 // needed for displaying network server text instead of identifier
4998 network_server_text = network_server_hostname;
5001 static void execSetupGame(void)
5003 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5005 execSetupGame_setGameSpeeds(FALSE);
5006 execSetupGame_setScrollDelays();
5007 execSetupGame_setSnapshotModes();
5009 execSetupGame_setNetworkServerText();
5011 setup_mode = SETUP_MODE_GAME;
5015 // check if vsync needs to be disabled for this game speed to work
5016 if (check_vsync_mode)
5017 DisableVsyncIfNeeded();
5020 static void execSetupChooseGameSpeed(void)
5022 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
5027 static void execSetupChooseScrollDelay(void)
5029 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
5034 static void execSetupChooseSnapshotMode(void)
5036 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
5041 static void execSetupEngines(void)
5043 setup_mode = SETUP_MODE_ENGINES;
5048 static void execSetupEditor(void)
5050 setup_mode = SETUP_MODE_EDITOR;
5055 static void execSetupGraphics_setWindowSizes(boolean update_list)
5057 if (window_sizes != NULL && update_list)
5059 freeTreeInfo(window_sizes);
5061 window_sizes = NULL;
5064 if (window_sizes == NULL)
5066 boolean current_window_size_found = FALSE;
5069 for (i = 0; window_sizes_list[i].value != -1; i++)
5071 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5072 char identifier[32], name[32];
5073 int value = window_sizes_list[i].value;
5074 char *text = window_sizes_list[i].text;
5076 ti->node_top = &window_sizes;
5077 ti->sort_priority = value;
5079 sprintf(identifier, "%d", value);
5080 sprintf(name, "%s", text);
5082 setString(&ti->identifier, identifier);
5083 setString(&ti->name, name);
5084 setString(&ti->name_sorting, name);
5085 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5087 pushTreeInfo(&window_sizes, ti);
5089 if (value == setup.window_scaling_percent)
5090 current_window_size_found = TRUE;
5093 if (!current_window_size_found)
5095 // add entry for non-preset window scaling value
5097 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5098 char identifier[32], name[32];
5099 int value = setup.window_scaling_percent;
5101 ti->node_top = &window_sizes;
5102 ti->sort_priority = value;
5104 sprintf(identifier, "%d", value);
5105 sprintf(name, "%d %% (Current)", value);
5107 setString(&ti->identifier, identifier);
5108 setString(&ti->name, name);
5109 setString(&ti->name_sorting, name);
5110 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
5112 pushTreeInfo(&window_sizes, ti);
5115 // sort window size values to start with lowest window size value
5116 sortTreeInfo(&window_sizes);
5118 // set current window size value to configured window size value
5119 window_size_current =
5120 getTreeInfoFromIdentifier(window_sizes,
5121 i_to_a(setup.window_scaling_percent));
5123 // if that fails, set current window size to reliable default value
5124 if (window_size_current == NULL)
5125 window_size_current =
5126 getTreeInfoFromIdentifier(window_sizes,
5127 i_to_a(STD_WINDOW_SCALING_PERCENT));
5129 // if that also fails, set current window size to first available value
5130 if (window_size_current == NULL)
5131 window_size_current = window_sizes;
5134 setup.window_scaling_percent = atoi(window_size_current->identifier);
5136 // needed for displaying window size text instead of identifier
5137 window_size_text = window_size_current->name;
5140 static void execSetupGraphics_setScalingTypes(void)
5142 if (scaling_types == NULL)
5146 for (i = 0; scaling_types_list[i].value != NULL; i++)
5148 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5149 char identifier[32], name[32];
5150 char *value = scaling_types_list[i].value;
5151 char *text = scaling_types_list[i].text;
5153 ti->node_top = &scaling_types;
5154 ti->sort_priority = i;
5156 sprintf(identifier, "%s", value);
5157 sprintf(name, "%s", text);
5159 setString(&ti->identifier, identifier);
5160 setString(&ti->name, name);
5161 setString(&ti->name_sorting, name);
5162 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
5164 pushTreeInfo(&scaling_types, ti);
5167 // sort scaling type values to start with lowest scaling type value
5168 sortTreeInfo(&scaling_types);
5170 // set current scaling type value to configured scaling type value
5171 scaling_type_current =
5172 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
5174 // if that fails, set current scaling type to reliable default value
5175 if (scaling_type_current == NULL)
5176 scaling_type_current =
5177 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
5179 // if that also fails, set current scaling type to first available value
5180 if (scaling_type_current == NULL)
5181 scaling_type_current = scaling_types;
5184 setup.window_scaling_quality = scaling_type_current->identifier;
5186 // needed for displaying scaling type text instead of identifier
5187 scaling_type_text = scaling_type_current->name;
5190 static void execSetupGraphics_setRenderingModes(void)
5192 if (rendering_modes == NULL)
5196 for (i = 0; rendering_modes_list[i].value != NULL; i++)
5198 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5199 char identifier[32], name[32];
5200 char *value = rendering_modes_list[i].value;
5201 char *text = rendering_modes_list[i].text;
5203 ti->node_top = &rendering_modes;
5204 ti->sort_priority = i;
5206 sprintf(identifier, "%s", value);
5207 sprintf(name, "%s", text);
5209 setString(&ti->identifier, identifier);
5210 setString(&ti->name, name);
5211 setString(&ti->name_sorting, name);
5212 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
5214 pushTreeInfo(&rendering_modes, ti);
5217 // sort rendering mode values to start with lowest rendering mode value
5218 sortTreeInfo(&rendering_modes);
5220 // set current rendering mode value to configured rendering mode value
5221 rendering_mode_current =
5222 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
5224 // if that fails, set current rendering mode to reliable default value
5225 if (rendering_mode_current == NULL)
5226 rendering_mode_current =
5227 getTreeInfoFromIdentifier(rendering_modes,
5228 STR_SPECIAL_RENDERING_DEFAULT);
5230 // if that also fails, set current rendering mode to first available one
5231 if (rendering_mode_current == NULL)
5232 rendering_mode_current = rendering_modes;
5235 setup.screen_rendering_mode = rendering_mode_current->identifier;
5237 // needed for displaying rendering mode text instead of identifier
5238 rendering_mode_text = rendering_mode_current->name;
5241 static void execSetupGraphics_setVsyncModes(boolean update_value)
5243 if (vsync_modes == NULL)
5247 for (i = 0; vsync_modes_list[i].value != NULL; i++)
5249 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5250 char identifier[32], name[32];
5251 char *value = vsync_modes_list[i].value;
5252 char *text = vsync_modes_list[i].text;
5254 ti->node_top = &vsync_modes;
5255 ti->sort_priority = i;
5257 sprintf(identifier, "%s", value);
5258 sprintf(name, "%s", text);
5260 setString(&ti->identifier, identifier);
5261 setString(&ti->name, name);
5262 setString(&ti->name_sorting, name);
5263 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
5265 pushTreeInfo(&vsync_modes, ti);
5268 // sort vsync mode values to start with lowest vsync mode value
5269 sortTreeInfo(&vsync_modes);
5271 update_value = TRUE;
5276 // set current vsync mode value to configured vsync mode value
5277 vsync_mode_current =
5278 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
5280 // if that fails, set current vsync mode to reliable default value
5281 if (vsync_mode_current == NULL)
5282 vsync_mode_current =
5283 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
5285 // if that also fails, set current vsync mode to first available one
5286 if (vsync_mode_current == NULL)
5287 vsync_mode_current = vsync_modes;
5290 setup.vsync_mode = vsync_mode_current->identifier;
5292 // needed for displaying vsync mode text instead of identifier
5293 vsync_mode_text = vsync_mode_current->name;
5296 static void execSetupGraphics(void)
5298 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
5300 // update "setup.window_scaling_percent" from list selection
5301 // (in this case, window scaling was changed on setup screen)
5302 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
5303 execSetupGraphics_setWindowSizes(FALSE);
5305 // update "setup.vsync_mode" from list selection
5306 // (in this case, vsync mode was changed on setup screen)
5307 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5308 execSetupGraphics_setVsyncModes(FALSE);
5310 // update list selection from "setup.window_scaling_percent"
5311 // (window scaling may have changed by resizing the window)
5312 execSetupGraphics_setWindowSizes(TRUE);
5314 // update list selection from "setup.vsync_mode"
5315 // (vsync_mode may have changed by re-creating the renderer)
5316 execSetupGraphics_setVsyncModes(TRUE);
5318 execSetupGraphics_setScalingTypes();
5319 execSetupGraphics_setRenderingModes();
5321 setup_mode = SETUP_MODE_GRAPHICS;
5325 // check if game speed is high enough for 60 Hz vsync to work
5326 if (check_game_speed)
5327 ModifyGameSpeedIfNeeded();
5329 // window scaling may have changed at this point
5330 ToggleFullscreenOrChangeWindowScalingIfNeeded();
5332 // window scaling quality may have changed at this point
5333 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
5334 SDLSetWindowScalingQuality(setup.window_scaling_quality);
5336 // screen rendering mode may have changed at this point
5337 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
5339 // screen vsync mode may have changed at this point
5340 ChangeVsyncModeIfNeeded();
5343 static void execSetupChooseWindowSize(void)
5345 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
5350 static void execSetupChooseScalingType(void)
5352 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
5357 static void execSetupChooseRenderingMode(void)
5359 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
5364 static void execSetupChooseVsyncMode(void)
5366 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
5371 static void execSetupChooseVolumeSimple(void)
5373 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
5378 static void execSetupChooseVolumeLoops(void)
5380 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
5385 static void execSetupChooseVolumeMusic(void)
5387 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
5392 static void execSetupSound(void)
5394 if (volumes_simple == NULL)
5396 boolean current_volume_simple_found = FALSE;
5399 for (i = 0; volumes_list[i].value != -1; i++)
5401 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5402 char identifier[32], name[32];
5403 int value = volumes_list[i].value;
5404 char *text = volumes_list[i].text;
5406 ti->node_top = &volumes_simple;
5407 ti->sort_priority = value;
5409 sprintf(identifier, "%d", value);
5410 sprintf(name, "%s", text);
5412 setString(&ti->identifier, identifier);
5413 setString(&ti->name, name);
5414 setString(&ti->name_sorting, name);
5415 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5417 pushTreeInfo(&volumes_simple, ti);
5419 if (value == setup.volume_simple)
5420 current_volume_simple_found = TRUE;
5423 if (!current_volume_simple_found)
5425 // add entry for non-preset volume value
5427 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5428 char identifier[32], name[32];
5429 int value = setup.volume_simple;
5431 ti->node_top = &volumes_simple;
5432 ti->sort_priority = value;
5434 sprintf(identifier, "%d", value);
5435 sprintf(name, "%d %% (Current)", value);
5437 setString(&ti->identifier, identifier);
5438 setString(&ti->name, name);
5439 setString(&ti->name_sorting, name);
5440 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
5442 pushTreeInfo(&volumes_simple, ti);
5445 // sort volume values to start with lowest volume value
5446 sortTreeInfo(&volumes_simple);
5448 // set current volume value to configured volume value
5449 volume_simple_current =
5450 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
5452 // if that fails, set current volume to reliable default value
5453 if (volume_simple_current == NULL)
5454 volume_simple_current =
5455 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
5457 // if that also fails, set current volume to first available value
5458 if (volume_simple_current == NULL)
5459 volume_simple_current = volumes_simple;
5462 if (volumes_loops == NULL)
5464 boolean current_volume_loops_found = FALSE;
5467 for (i = 0; volumes_list[i].value != -1; i++)
5469 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5470 char identifier[32], name[32];
5471 int value = volumes_list[i].value;
5472 char *text = volumes_list[i].text;
5474 ti->node_top = &volumes_loops;
5475 ti->sort_priority = value;
5477 sprintf(identifier, "%d", value);
5478 sprintf(name, "%s", text);
5480 setString(&ti->identifier, identifier);
5481 setString(&ti->name, name);
5482 setString(&ti->name_sorting, name);
5483 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5485 pushTreeInfo(&volumes_loops, ti);
5487 if (value == setup.volume_loops)
5488 current_volume_loops_found = TRUE;
5491 if (!current_volume_loops_found)
5493 // add entry for non-preset volume value
5495 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5496 char identifier[32], name[32];
5497 int value = setup.volume_loops;
5499 ti->node_top = &volumes_loops;
5500 ti->sort_priority = value;
5502 sprintf(identifier, "%d", value);
5503 sprintf(name, "%d %% (Current)", value);
5505 setString(&ti->identifier, identifier);
5506 setString(&ti->name, name);
5507 setString(&ti->name_sorting, name);
5508 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
5510 pushTreeInfo(&volumes_loops, ti);
5513 // sort volume values to start with lowest volume value
5514 sortTreeInfo(&volumes_loops);
5516 // set current volume value to configured volume value
5517 volume_loops_current =
5518 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
5520 // if that fails, set current volume to reliable default value
5521 if (volume_loops_current == NULL)
5522 volume_loops_current =
5523 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
5525 // if that also fails, set current volume to first available value
5526 if (volume_loops_current == NULL)
5527 volume_loops_current = volumes_loops;
5530 if (volumes_music == NULL)
5532 boolean current_volume_music_found = FALSE;
5535 for (i = 0; volumes_list[i].value != -1; i++)
5537 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5538 char identifier[32], name[32];
5539 int value = volumes_list[i].value;
5540 char *text = volumes_list[i].text;
5542 ti->node_top = &volumes_music;
5543 ti->sort_priority = value;
5545 sprintf(identifier, "%d", value);
5546 sprintf(name, "%s", text);
5548 setString(&ti->identifier, identifier);
5549 setString(&ti->name, name);
5550 setString(&ti->name_sorting, name);
5551 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5553 pushTreeInfo(&volumes_music, ti);
5555 if (value == setup.volume_music)
5556 current_volume_music_found = TRUE;
5559 if (!current_volume_music_found)
5561 // add entry for non-preset volume value
5563 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5564 char identifier[32], name[32];
5565 int value = setup.volume_music;
5567 ti->node_top = &volumes_music;
5568 ti->sort_priority = value;
5570 sprintf(identifier, "%d", value);
5571 sprintf(name, "%d %% (Current)", value);
5573 setString(&ti->identifier, identifier);
5574 setString(&ti->name, name);
5575 setString(&ti->name_sorting, name);
5576 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
5578 pushTreeInfo(&volumes_music, ti);
5581 // sort volume values to start with lowest volume value
5582 sortTreeInfo(&volumes_music);
5584 // set current volume value to configured volume value
5585 volume_music_current =
5586 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
5588 // if that fails, set current volume to reliable default value
5589 if (volume_music_current == NULL)
5590 volume_music_current =
5591 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
5593 // if that also fails, set current volume to first available value
5594 if (volume_music_current == NULL)
5595 volume_music_current = volumes_music;
5598 setup.volume_simple = atoi(volume_simple_current->identifier);
5599 setup.volume_loops = atoi(volume_loops_current->identifier);
5600 setup.volume_music = atoi(volume_music_current->identifier);
5602 // needed for displaying volume text instead of identifier
5603 volume_simple_text = volume_simple_current->name;
5604 volume_loops_text = volume_loops_current->name;
5605 volume_music_text = volume_music_current->name;
5607 setup_mode = SETUP_MODE_SOUND;
5612 static void execSetupChooseTouchControls(void)
5614 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
5619 static void execSetupChooseMoveDistance(void)
5621 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
5626 static void execSetupChooseDropDistance(void)
5628 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
5633 static void execSetupChooseTransparency(void)
5635 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
5640 static void execSetupChooseGridXSize_0(void)
5642 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
5647 static void execSetupChooseGridYSize_0(void)
5649 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
5654 static void execSetupChooseGridXSize_1(void)
5656 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
5661 static void execSetupChooseGridYSize_1(void)
5663 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
5668 static void execSetupConfigureVirtualButtons(void)
5670 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
5672 ConfigureVirtualButtons();
5674 setup_mode = SETUP_MODE_TOUCH;
5679 static void execSetupTouch(void)
5683 if (touch_controls == NULL)
5685 for (i = 0; touch_controls_list[i].value != NULL; i++)
5687 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5688 char identifier[32], name[32];
5689 char *value = touch_controls_list[i].value;
5690 char *text = touch_controls_list[i].text;
5692 ti->node_top = &touch_controls;
5693 ti->sort_priority = i;
5695 sprintf(identifier, "%s", value);
5696 sprintf(name, "%s", text);
5698 setString(&ti->identifier, identifier);
5699 setString(&ti->name, name);
5700 setString(&ti->name_sorting, name);
5701 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
5703 pushTreeInfo(&touch_controls, ti);
5706 // sort touch control values to start with lowest touch control value
5707 sortTreeInfo(&touch_controls);
5709 // set current touch control value to configured touch control value
5710 touch_control_current =
5711 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
5713 // if that fails, set current touch control to reliable default value
5714 if (touch_control_current == NULL)
5715 touch_control_current =
5716 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
5718 // if that also fails, set current touch control to first available value
5719 if (touch_control_current == NULL)
5720 touch_control_current = touch_controls;
5723 if (move_distances == NULL)
5725 for (i = 0; distances_list[i].value != -1; i++)
5727 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5728 char identifier[32], name[32];
5729 int value = distances_list[i].value;
5730 char *text = distances_list[i].text;
5732 ti->node_top = &move_distances;
5733 ti->sort_priority = value;
5735 sprintf(identifier, "%d", value);
5736 sprintf(name, "%s", text);
5738 setString(&ti->identifier, identifier);
5739 setString(&ti->name, name);
5740 setString(&ti->name_sorting, name);
5741 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
5743 pushTreeInfo(&move_distances, ti);
5746 // sort distance values to start with lowest distance value
5747 sortTreeInfo(&move_distances);
5749 // set current distance value to configured distance value
5750 move_distance_current =
5751 getTreeInfoFromIdentifier(move_distances,
5752 i_to_a(setup.touch.move_distance));
5754 // if that fails, set current distance to reliable default value
5755 if (move_distance_current == NULL)
5756 move_distance_current =
5757 getTreeInfoFromIdentifier(move_distances,
5758 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
5760 // if that also fails, set current distance to first available value
5761 if (move_distance_current == NULL)
5762 move_distance_current = move_distances;
5765 if (drop_distances == NULL)
5767 for (i = 0; distances_list[i].value != -1; i++)
5769 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5770 char identifier[32], name[32];
5771 int value = distances_list[i].value;
5772 char *text = distances_list[i].text;
5774 ti->node_top = &drop_distances;
5775 ti->sort_priority = value;
5777 sprintf(identifier, "%d", value);
5778 sprintf(name, "%s", text);
5780 setString(&ti->identifier, identifier);
5781 setString(&ti->name, name);
5782 setString(&ti->name_sorting, name);
5783 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
5785 pushTreeInfo(&drop_distances, ti);
5788 // sort distance values to start with lowest distance value
5789 sortTreeInfo(&drop_distances);
5791 // set current distance value to configured distance value
5792 drop_distance_current =
5793 getTreeInfoFromIdentifier(drop_distances,
5794 i_to_a(setup.touch.drop_distance));
5796 // if that fails, set current distance to reliable default value
5797 if (drop_distance_current == NULL)
5798 drop_distance_current =
5799 getTreeInfoFromIdentifier(drop_distances,
5800 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
5802 // if that also fails, set current distance to first available value
5803 if (drop_distance_current == NULL)
5804 drop_distance_current = drop_distances;
5807 if (transparencies == NULL)
5809 for (i = 0; transparencies_list[i].value != -1; i++)
5811 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5812 char identifier[32], name[32];
5813 int value = transparencies_list[i].value;
5814 char *text = transparencies_list[i].text;
5816 ti->node_top = &transparencies;
5817 ti->sort_priority = value;
5819 sprintf(identifier, "%d", value);
5820 sprintf(name, "%s", text);
5822 setString(&ti->identifier, identifier);
5823 setString(&ti->name, name);
5824 setString(&ti->name_sorting, name);
5825 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
5827 pushTreeInfo(&transparencies, ti);
5830 // sort transparency values to start with lowest transparency value
5831 sortTreeInfo(&transparencies);
5833 // set current transparency value to configured transparency value
5834 transparency_current =
5835 getTreeInfoFromIdentifier(transparencies,
5836 i_to_a(setup.touch.transparency));
5838 // if that fails, set current transparency to reliable default value
5839 if (transparency_current == NULL)
5840 transparency_current =
5841 getTreeInfoFromIdentifier(transparencies,
5842 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
5844 // if that also fails, set current transparency to first available value
5845 if (transparency_current == NULL)
5846 transparency_current = transparencies;
5849 for (i = 0; i < 2; i++)
5851 for (j = 0; j < 2; j++)
5853 if (grid_sizes[i][j] == NULL)
5855 for (k = 0; grid_sizes_list[k].value != -1; k++)
5857 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5858 char identifier[32], name[32];
5859 int value = grid_sizes_list[k].value;
5860 char *text = grid_sizes_list[k].text;
5862 ti->node_top = &grid_sizes[i][j];
5863 ti->sort_priority = value;
5865 sprintf(identifier, "%d", value);
5866 sprintf(name, "%s", text);
5868 setString(&ti->identifier, identifier);
5869 setString(&ti->name, name);
5870 setString(&ti->name_sorting, name);
5871 setString(&ti->infotext,
5874 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
5875 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
5877 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
5878 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
5880 pushTreeInfo(&grid_sizes[i][j], ti);
5883 // sort grid size values to start with lowest grid size value
5884 sortTreeInfo(&grid_sizes[i][j]);
5886 // set current grid size value to configured grid size value
5887 grid_size_current[i][j] =
5888 getTreeInfoFromIdentifier(grid_sizes[i][j],
5890 setup.touch.grid_xsize[i] :
5891 setup.touch.grid_ysize[i]));
5893 // if that fails, set current grid size to reliable default value
5894 if (grid_size_current[i][j] == NULL)
5895 grid_size_current[i][j] =
5896 getTreeInfoFromIdentifier(grid_sizes[i][j],
5898 DEFAULT_GRID_XSIZE(i) :
5899 DEFAULT_GRID_YSIZE(i)));
5901 // if that also fails, set current grid size to first available value
5902 if (grid_size_current[i][j] == NULL)
5903 grid_size_current[i][j] = grid_sizes[i][j];
5908 setup.touch.control_type = touch_control_current->identifier;
5909 setup.touch.move_distance = atoi(move_distance_current->identifier);
5910 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
5911 setup.touch.transparency = atoi(transparency_current->identifier);
5913 for (i = 0; i < 2; i++)
5915 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
5916 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
5918 if (i == GRID_ACTIVE_NR())
5920 overlay.grid_xsize = setup.touch.grid_xsize[i];
5921 overlay.grid_ysize = setup.touch.grid_ysize[i];
5925 // needed for displaying value text instead of identifier
5926 touch_controls_text = touch_control_current->name;
5927 move_distance_text = move_distance_current->name;
5928 drop_distance_text = drop_distance_current->name;
5929 transparency_text = transparency_current->name;
5931 for (i = 0; i < 2; i++)
5932 for (j = 0; j < 2; j++)
5933 grid_size_text[i][j] = grid_size_current[i][j]->name;
5935 setup_mode = SETUP_MODE_TOUCH;
5940 static void execSetupArtwork(void)
5943 printf("::: '%s', '%s', '%s'\n",
5944 artwork.gfx_current->subdir,
5945 artwork.gfx_current->fullpath,
5946 artwork.gfx_current->basepath);
5949 setup.graphics_set = artwork.gfx_current->identifier;
5950 setup.sounds_set = artwork.snd_current->identifier;
5951 setup.music_set = artwork.mus_current->identifier;
5953 // needed if last screen (setup choice) changed graphics, sounds or music
5954 ReloadCustomArtwork(0);
5956 // needed for displaying artwork name instead of artwork identifier
5957 graphics_set_name = artwork.gfx_current->name;
5958 sounds_set_name = artwork.snd_current->name;
5959 music_set_name = artwork.mus_current->name;
5961 setup_mode = SETUP_MODE_ARTWORK;
5966 static void execSetupChooseGraphics(void)
5968 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
5973 static void execSetupChooseSounds(void)
5975 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
5980 static void execSetupChooseMusic(void)
5982 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
5987 static void execSetupInput(void)
5989 setup_mode = SETUP_MODE_INPUT;
5994 static void execSetupShortcuts(void)
5996 setup_mode = SETUP_MODE_SHORTCUTS;
6001 static void execSetupShortcuts1(void)
6003 setup_mode = SETUP_MODE_SHORTCUTS_1;
6008 static void execSetupShortcuts2(void)
6010 setup_mode = SETUP_MODE_SHORTCUTS_2;
6015 static void execSetupShortcuts3(void)
6017 setup_mode = SETUP_MODE_SHORTCUTS_3;
6022 static void execSetupShortcuts4(void)
6024 setup_mode = SETUP_MODE_SHORTCUTS_4;
6029 static void execSetupShortcuts5(void)
6031 setup_mode = SETUP_MODE_SHORTCUTS_5;
6036 static void execExitSetup(void)
6038 SetGameStatus(GAME_MODE_MAIN);
6043 static void execSaveAndExitSetup(void)
6049 static void execGadgetNetworkServer(void)
6051 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
6052 struct GadgetInfo *gi = screen_gadget[gadget_id];
6054 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6055 network_server_hostname[0] = '\0';
6057 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
6061 ClickOnGadget(gi, MB_LEFTBUTTON);
6064 static void ToggleNetworkModeIfNeeded(void)
6066 int font_title = FONT_TITLE_1;
6067 int font_foot = FC_BLUE;
6068 int ystart = mSY - SY + 16;
6069 int ybottom = mSY - SY + SYSIZE - 20;
6070 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
6072 if (setup.network_mode == network.enabled)
6075 network.enabled = setup.network_mode;
6077 FadeOut(REDRAW_ALL);
6081 DrawTextSCentered(ystart, font_title, text);
6085 if (network.enabled)
6086 InitNetworkServer();
6088 DisconnectFromNetworkServer();
6090 DrawTextSCentered(ybottom, font_foot,
6091 "Press any key or button for setup menu");
6093 WaitForEventToContinue();
6098 static void ToggleGameSpeedsListIfNeeded(void)
6100 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
6102 if (setup.game_speed_extended == using_game_speeds_extended)
6105 // try to match similar values when changing game speeds list
6106 if (setup.game_speed_extended)
6107 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
6108 setup.game_frame_delay == 30 ? 29 :
6109 setup.game_frame_delay);
6111 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
6112 setup.game_frame_delay == 16 ? 15 :
6113 setup.game_frame_delay >= 29 ? 30 :
6114 setup.game_frame_delay <= 10 ? 10 :
6115 setup.game_frame_delay);
6117 execSetupGame_setGameSpeeds(TRUE);
6122 static void ModifyGameSpeedIfNeeded(void)
6124 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6125 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
6129 char *game_speed_text = "Fast";
6130 int game_speed_value = 15;
6132 if (setup.game_speed_extended)
6134 game_speed_text = "60 fps";
6135 game_speed_value = 16;
6138 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
6140 // set game speed to existing list value that is fast enough for vsync
6141 setup.game_frame_delay = game_speed_value;
6143 execSetupGame_setGameSpeeds(TRUE);
6145 Request(message, REQ_CONFIRM);
6148 static void DisableVsyncIfNeeded(void)
6150 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
6151 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
6152 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
6155 // disable vsync for the selected game speed to work
6156 setup.vsync_mode = STR_VSYNC_MODE_OFF;
6158 execSetupGraphics_setVsyncModes(TRUE);
6160 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
6166 void *related_value;
6167 } hide_related_entry_list[] =
6169 { &setup.game_frame_delay, execSetupChooseGameSpeed },
6170 { &setup.game_frame_delay, &game_speed_text },
6172 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
6173 { &setup.scroll_delay_value, &scroll_delay_text },
6175 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
6176 { &setup.engine_snapshot_mode, &snapshot_mode_text },
6178 { &setup.window_scaling_percent, execSetupChooseWindowSize },
6179 { &setup.window_scaling_percent, &window_size_text },
6181 { &setup.window_scaling_quality, execSetupChooseScalingType },
6182 { &setup.window_scaling_quality, &scaling_type_text },
6184 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
6185 { &setup.screen_rendering_mode, &rendering_mode_text },
6187 { &setup.vsync_mode, execSetupChooseVsyncMode },
6188 { &setup.vsync_mode, &vsync_mode_text },
6190 { &setup.graphics_set, execSetupChooseGraphics },
6191 { &setup.graphics_set, &graphics_set_name },
6193 { &setup.sounds_set, execSetupChooseSounds },
6194 { &setup.sounds_set, &sounds_set_name },
6196 { &setup.music_set, execSetupChooseMusic },
6197 { &setup.music_set, &music_set_name },
6199 { &setup.volume_simple, execSetupChooseVolumeSimple },
6200 { &setup.volume_simple, &volume_simple_text },
6202 { &setup.volume_loops, execSetupChooseVolumeLoops },
6203 { &setup.volume_loops, &volume_loops_text },
6205 { &setup.volume_music, execSetupChooseVolumeMusic },
6206 { &setup.volume_music, &volume_music_text },
6208 { &setup.touch.control_type, execSetupChooseTouchControls },
6209 { &setup.touch.control_type, &touch_controls_text },
6211 { &setup.touch.move_distance, execSetupChooseMoveDistance },
6212 { &setup.touch.move_distance, &move_distance_text },
6214 { &setup.touch.drop_distance, execSetupChooseDropDistance },
6215 { &setup.touch.drop_distance, &drop_distance_text },
6217 { &setup.touch.transparency, execSetupChooseTransparency },
6218 { &setup.touch.transparency, &transparency_text },
6220 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
6221 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
6223 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
6224 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
6226 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
6227 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
6229 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
6230 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
6232 { &setup.internal.menu_game, execSetupGame },
6233 { &setup.internal.menu_engines, execSetupEngines },
6234 { &setup.internal.menu_editor, execSetupEditor },
6235 { &setup.internal.menu_graphics, execSetupGraphics },
6236 { &setup.internal.menu_sound, execSetupSound },
6237 { &setup.internal.menu_artwork, execSetupArtwork },
6238 { &setup.internal.menu_input, execSetupInput },
6239 { &setup.internal.menu_touch, execSetupTouch },
6240 { &setup.internal.menu_shortcuts, execSetupShortcuts },
6241 { &setup.internal.menu_exit, execExitSetup },
6242 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
6247 void setHideRelatedSetupEntries(void)
6251 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
6252 if (hideSetupEntry(hide_related_entry_list[i].value))
6253 setHideSetupEntry(hide_related_entry_list[i].related_value);
6256 static struct TokenInfo setup_info_main[] =
6258 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
6259 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
6260 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
6261 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
6262 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
6263 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
6264 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
6265 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
6266 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
6267 { TYPE_EMPTY, NULL, "" },
6268 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
6269 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
6274 static struct TokenInfo setup_info_game[] =
6276 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
6277 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
6278 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
6279 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
6280 { TYPE_STRING, &network_server_text, "" },
6281 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
6282 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
6283 { TYPE_SWITCH, &setup.handicap, "Handicap:" },
6284 { TYPE_SWITCH, &setup.skip_levels, "Skip Unsolved Levels:" },
6285 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
6286 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
6287 { TYPE_SWITCH, &setup.skip_scores_after_game,"Skip Scores After Game:" },
6288 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
6289 { TYPE_SWITCH, &setup.autorecord, "Auto-Record Tapes:" },
6290 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
6291 { TYPE_STRING, &game_speed_text, "" },
6292 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
6294 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6295 { TYPE_STRING, &scroll_delay_text, "" },
6297 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
6298 { TYPE_STRING, &snapshot_mode_text, "" },
6299 { TYPE_SWITCH, &setup.show_snapshot_buttons,"Show Snapshot Buttons:" },
6300 { TYPE_EMPTY, NULL, "" },
6301 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6306 static struct TokenInfo setup_info_engines[] =
6308 { TYPE_HEADLINE, NULL, "Emerald Mine" },
6309 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
6310 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
6311 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
6312 { TYPE_EMPTY, NULL, "" },
6313 { TYPE_HEADLINE, NULL, "Supaplex" },
6314 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
6315 { TYPE_EMPTY, NULL, "" },
6316 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6321 static struct TokenInfo setup_info_editor[] =
6324 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
6325 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
6326 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
6327 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
6328 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
6329 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
6330 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
6331 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
6332 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
6333 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
6335 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
6336 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
6338 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
6340 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
6341 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
6342 { TYPE_EMPTY, NULL, "" },
6344 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
6345 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
6346 { TYPE_EMPTY, NULL, "" },
6348 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
6349 { TYPE_EMPTY, NULL, "" },
6350 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6355 static struct TokenInfo setup_info_graphics[] =
6357 #if !defined(PLATFORM_ANDROID)
6358 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
6359 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
6360 { TYPE_STRING, &window_size_text, "" },
6361 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
6362 { TYPE_STRING, &scaling_type_text, "" },
6363 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
6364 { TYPE_STRING, &rendering_mode_text, "" },
6367 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
6368 { TYPE_STRING, &scroll_delay_text, "" },
6370 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
6371 { TYPE_STRING, &vsync_mode_text, "" },
6372 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
6373 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
6374 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
6375 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
6376 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
6377 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
6378 { TYPE_EMPTY, NULL, "" },
6379 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6384 static struct TokenInfo setup_info_sound[] =
6386 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
6387 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
6388 { TYPE_SWITCH, &setup.sound_music, "Music:" },
6389 { TYPE_EMPTY, NULL, "" },
6390 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
6391 { TYPE_STRING, &volume_simple_text, "" },
6392 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
6393 { TYPE_STRING, &volume_loops_text, "" },
6394 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
6395 { TYPE_STRING, &volume_music_text, "" },
6396 { TYPE_EMPTY, NULL, "" },
6397 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6402 static struct TokenInfo setup_info_artwork[] =
6404 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
6405 { TYPE_STRING, &graphics_set_name, "" },
6406 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
6407 { TYPE_STRING, &sounds_set_name, "" },
6408 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
6409 { TYPE_STRING, &music_set_name, "" },
6410 { TYPE_EMPTY, NULL, "" },
6411 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
6412 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
6413 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
6414 { TYPE_EMPTY, NULL, "" },
6415 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6420 static struct TokenInfo setup_info_input[] =
6422 { TYPE_SWITCH, NULL, "Player:" },
6423 { TYPE_SWITCH, NULL, "Device:" },
6424 { TYPE_SWITCH, NULL, "" },
6425 { TYPE_SKIPPABLE, NULL, "" },
6426 { TYPE_EMPTY, NULL, "" },
6427 { TYPE_EMPTY, NULL, "" },
6428 { TYPE_EMPTY, NULL, "" },
6429 { TYPE_EMPTY, NULL, "" },
6430 { TYPE_EMPTY, NULL, "" },
6431 { TYPE_EMPTY, NULL, "" },
6432 { TYPE_EMPTY, NULL, "" },
6433 { TYPE_EMPTY, NULL, "" },
6434 { TYPE_SKIPPABLE, NULL, "" },
6435 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6440 static struct TokenInfo setup_info_touch[] =
6442 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6443 { TYPE_STRING, &touch_controls_text, "" },
6444 { TYPE_EMPTY, NULL, "" },
6445 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6450 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
6452 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6453 { TYPE_STRING, &touch_controls_text, "" },
6454 { TYPE_EMPTY, NULL, "" },
6455 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
6456 { TYPE_STRING, &grid_size_text[0][0], "" },
6457 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
6458 { TYPE_STRING, &grid_size_text[0][1], "" },
6459 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6460 { TYPE_STRING, &transparency_text, "" },
6461 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6462 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6463 { TYPE_EMPTY, NULL, "" },
6464 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6465 { TYPE_EMPTY, NULL, "" },
6466 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6471 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
6473 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6474 { TYPE_STRING, &touch_controls_text, "" },
6475 { TYPE_EMPTY, NULL, "" },
6476 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
6477 { TYPE_STRING, &grid_size_text[1][0], "" },
6478 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
6479 { TYPE_STRING, &grid_size_text[1][1], "" },
6480 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
6481 { TYPE_STRING, &transparency_text, "" },
6482 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
6483 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
6484 { TYPE_EMPTY, NULL, "" },
6485 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
6486 { TYPE_EMPTY, NULL, "" },
6487 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6492 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
6494 setup_info_touch_virtual_buttons_0,
6495 setup_info_touch_virtual_buttons_1
6498 static struct TokenInfo setup_info_touch_wipe_gestures[] =
6500 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
6501 { TYPE_STRING, &touch_controls_text, "" },
6502 { TYPE_EMPTY, NULL, "" },
6503 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
6504 { TYPE_STRING, &move_distance_text, "" },
6505 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
6506 { TYPE_STRING, &drop_distance_text, "" },
6507 { TYPE_EMPTY, NULL, "" },
6508 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6513 static struct TokenInfo setup_info_shortcuts[] =
6515 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
6516 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
6517 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
6518 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
6519 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
6520 { TYPE_EMPTY, NULL, "" },
6521 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
6526 static struct TokenInfo setup_info_shortcuts_1[] =
6528 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
6529 { TYPE_KEY, &setup.shortcut.save_game, "" },
6530 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
6531 { TYPE_KEY, &setup.shortcut.load_game, "" },
6532 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
6533 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
6534 { TYPE_EMPTY, NULL, "" },
6535 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
6536 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
6537 { TYPE_EMPTY, NULL, "" },
6538 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6543 static struct TokenInfo setup_info_shortcuts_2[] =
6545 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
6546 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
6547 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
6548 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
6549 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
6550 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
6551 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
6552 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
6553 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
6554 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
6555 { TYPE_EMPTY, NULL, "" },
6556 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6561 static struct TokenInfo setup_info_shortcuts_3[] =
6563 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
6564 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
6565 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
6566 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
6567 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
6568 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
6569 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
6570 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
6571 { TYPE_KEYTEXT, NULL, "Record Tape:", },
6572 { TYPE_KEY, &setup.shortcut.tape_record, "" },
6573 { TYPE_KEYTEXT, NULL, "Play Tape:", },
6574 { TYPE_KEY, &setup.shortcut.tape_play, "" },
6575 { TYPE_EMPTY, NULL, "" },
6576 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6581 static struct TokenInfo setup_info_shortcuts_4[] =
6583 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
6584 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
6585 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
6586 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
6587 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
6588 { TYPE_KEY, &setup.shortcut.sound_music, "" },
6589 { TYPE_EMPTY, NULL, "" },
6590 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6595 static struct TokenInfo setup_info_shortcuts_5[] =
6597 { TYPE_KEYTEXT, NULL, "Snap Left:", },
6598 { TYPE_KEY, &setup.shortcut.snap_left, "" },
6599 { TYPE_KEYTEXT, NULL, "Snap Right:", },
6600 { TYPE_KEY, &setup.shortcut.snap_right, "" },
6601 { TYPE_KEYTEXT, NULL, "Snap Up:", },
6602 { TYPE_KEY, &setup.shortcut.snap_up, "" },
6603 { TYPE_KEYTEXT, NULL, "Snap Down:", },
6604 { TYPE_KEY, &setup.shortcut.snap_down, "" },
6605 { TYPE_EMPTY, NULL, "" },
6606 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
6611 static Key getSetupKey(void)
6613 Key key = KSYM_UNDEFINED;
6614 boolean got_key_event = FALSE;
6616 while (!got_key_event)
6620 if (NextValidEvent(&event))
6624 case EVENT_KEYPRESS:
6626 key = GetEventKey((KeyEvent *)&event, TRUE);
6628 // press 'Escape' or 'Enter' to keep the existing key binding
6629 if (key == KSYM_Escape || key == KSYM_Return)
6630 key = KSYM_UNDEFINED; // keep old value
6632 got_key_event = TRUE;
6636 case EVENT_KEYRELEASE:
6637 key_joystick_mapping = 0;
6641 HandleOtherEvents(&event);
6652 static int getSetupValueFont(int type, void *value)
6654 if (type & TYPE_GHOSTED)
6655 return FONT_OPTION_OFF;
6656 else if (type & TYPE_KEY)
6657 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
6658 else if (type & TYPE_STRING)
6659 return FONT_VALUE_2;
6660 else if (type & TYPE_ECS_AGA)
6661 return FONT_VALUE_1;
6662 else if (type & TYPE_BOOLEAN_STYLE)
6663 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
6664 else if (type & TYPE_YES_NO_AUTO)
6665 return (*(int *)value == AUTO ? FONT_OPTION_ON :
6666 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
6667 else if (type & TYPE_PLAYER)
6668 return FONT_VALUE_1;
6670 return FONT_VALUE_1;
6673 static int getSetupValueFontNarrow(int type, int font_nr)
6675 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
6676 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
6677 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
6681 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
6683 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6684 struct TokenInfo *si = &setup_info[si_pos];
6685 boolean font_draw_xoffset_modified = FALSE;
6686 boolean scrollbar_needed = (num_setup_info < max_setup_info);
6687 int font_draw_xoffset_old = -1;
6688 int xoffset = (scrollbar_needed ? -1 : 0);
6689 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
6690 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
6691 int xpos = menu_screen_value_xpos;
6692 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
6693 int startx = mSX + xpos * 32;
6694 int starty = mSY + ypos * 32;
6695 int type = si->type;
6696 void *value = si->value;
6697 char *value_string = getSetupValue(type, value);
6698 int font_nr_default = getSetupValueFont(type, value);
6699 int font_width_default = getFontWidth(font_nr_default);
6700 int font_nr = font_nr_default;
6703 if (value_string == NULL)
6706 if (type & TYPE_KEY)
6708 xpos = MENU_SCREEN_START_XPOS;
6710 if (type & TYPE_QUERY)
6711 value_string = "<press key>";
6713 else if (type & TYPE_STRING)
6715 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
6717 xpos = MENU_SCREEN_START_XPOS;
6719 if (strlen(value_string) > max_value_len)
6720 value_string[max_value_len] = '\0';
6722 else if (type & TYPE_YES_NO_AUTO)
6724 xpos = menu_screen_value_xpos - 1;
6726 else if (type & TYPE_PLAYER)
6728 int displayed_player_nr = *(int *)value + 1;
6730 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
6733 startx = mSX + xpos * 32;
6734 starty = mSY + ypos * 32;
6736 // special check if right-side setup values moved left due to scrollbar
6737 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
6739 int max_menu_text_length = 26; // maximum text length for classic menu
6740 int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6741 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6742 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6743 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6744 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
6746 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
6749 startx = mSX + xpos * 32;
6751 font_nr = getSetupValueFontNarrow(type, font_nr);
6755 // downward compatibility correction for Juergen Bonhagen's menu settings
6756 if (setup_mode != SETUP_MODE_INPUT)
6758 int max_menu_text_length_big = (menu_screen_value_xpos -
6759 MENU_SCREEN_START_XPOS);
6760 int max_menu_text_length_medium = max_menu_text_length_big * 2;
6761 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
6762 int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
6763 int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset;
6764 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
6765 int text_font_nr = getMenuTextFont(FONT_MENU_2);
6766 int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset;
6767 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
6768 boolean correct_font_draw_xoffset = FALSE;
6770 if (xpos == MENU_SCREEN_START_XPOS &&
6771 startx + font1_xoffset < text_startx + text_font_xoffset)
6772 correct_font_draw_xoffset = TRUE;
6774 if (xpos == menu_screen_value_xpos &&
6775 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
6776 correct_font_draw_xoffset = TRUE;
6778 // check if setup value would overlap with setup text when printed
6779 // (this can happen for extreme/wrong values for font draw offset)
6780 if (correct_font_draw_xoffset)
6782 font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset;
6783 font_draw_xoffset_modified = TRUE;
6785 if (type & TYPE_KEY)
6786 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
6787 else if (!(type & TYPE_STRING))
6788 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
6789 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
6793 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
6794 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
6796 DrawText(startx, starty, value_string, font_nr);
6798 if (type & TYPE_PLAYER)
6800 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
6801 int player_nr = *(int *)value;
6802 int xoff = font->draw_xoffset + getFontWidth(font_nr);
6803 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
6804 int startx2 = startx + xoff;
6805 int starty2 = starty + yoff;
6807 if (DrawingOnBackground(startx2, starty2))
6808 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
6810 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
6811 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
6814 if (font_draw_xoffset_modified)
6815 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
6818 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
6820 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
6821 struct TokenInfo *si = &setup_info[si_pos];
6823 if (si->type & TYPE_BOOLEAN_STYLE)
6825 *(boolean *)si->value ^= TRUE;
6827 else if (si->type & TYPE_YES_NO_AUTO)
6831 (*(int *)si->value == AUTO ? TRUE :
6832 *(int *)si->value == TRUE ? FALSE : AUTO) :
6833 (*(int *)si->value == TRUE ? AUTO :
6834 *(int *)si->value == AUTO ? FALSE : TRUE));
6836 else if (si->type & TYPE_KEY)
6840 si->type |= TYPE_QUERY;
6841 drawSetupValue(screen_pos, setup_info_pos_raw);
6842 si->type &= ~TYPE_QUERY;
6844 key = getSetupKey();
6845 if (key != KSYM_UNDEFINED)
6846 *(Key *)si->value = key;
6848 else if (si->type & TYPE_PLAYER)
6850 int player_nr = *(int *)si->value;
6855 player_nr = Request("Choose player", REQ_PLAYER) - 1;
6857 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
6860 drawSetupValue(screen_pos, setup_info_pos_raw);
6862 // fullscreen state may have changed at this point
6863 if (si->value == &setup.fullscreen)
6864 ToggleFullscreenOrChangeWindowScalingIfNeeded();
6866 // network mode may have changed at this point
6867 if (si->value == &setup.network_mode)
6868 ToggleNetworkModeIfNeeded();
6870 // game speed list may have changed at this point
6871 if (si->value == &setup.game_speed_extended)
6872 ToggleGameSpeedsListIfNeeded();
6875 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
6877 static struct TokenInfo *setup_info_final = NULL;
6882 // determine maximum list size of target list
6883 while (setup_info_orig[list_size++].type != 0);
6885 // free, allocate and clear memory for target list
6886 checked_free(setup_info_final);
6887 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
6889 // copy setup info list without setup entries marked as hidden
6890 for (i = 0; setup_info_orig[i].type != 0; i++)
6892 // skip setup entries configured to be hidden
6893 if (hideSetupEntry(setup_info_orig[i].value))
6896 // skip skippable setup entries if screen is lower than usual
6897 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
6898 setup_info_orig[i].type == TYPE_SKIPPABLE)
6901 setup_info_final[list_pos++] = setup_info_orig[i];
6904 return setup_info_final;
6907 static void DrawSetupScreen_Generic(void)
6909 int fade_mask = REDRAW_FIELD;
6910 boolean redraw_all = FALSE;
6911 char *title_string = NULL;
6915 fade_mask = REDRAW_ALL;
6918 FadeMenuSoundsAndMusic();
6920 FreeScreenGadgets();
6921 CreateScreenGadgets();
6923 if (redraw_mask & REDRAW_ALL)
6928 // needed if different viewport properties defined for setup screen
6929 ChangeViewportPropertiesIfNeeded();
6931 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
6935 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
6937 if (setup_mode == SETUP_MODE_MAIN)
6939 setup_info = setup_info_main;
6940 title_string = STR_SETUP_MAIN;
6942 else if (setup_mode == SETUP_MODE_GAME)
6944 setup_info = setup_info_game;
6945 title_string = STR_SETUP_GAME;
6947 else if (setup_mode == SETUP_MODE_ENGINES)
6949 setup_info = setup_info_engines;
6950 title_string = STR_SETUP_ENGINES;
6952 else if (setup_mode == SETUP_MODE_EDITOR)
6954 setup_info = setup_info_editor;
6955 title_string = STR_SETUP_EDITOR;
6957 else if (setup_mode == SETUP_MODE_GRAPHICS)
6959 setup_info = setup_info_graphics;
6960 title_string = STR_SETUP_GRAPHICS;
6962 else if (setup_mode == SETUP_MODE_SOUND)
6964 setup_info = setup_info_sound;
6965 title_string = STR_SETUP_SOUND;
6967 else if (setup_mode == SETUP_MODE_ARTWORK)
6969 setup_info = setup_info_artwork;
6970 title_string = STR_SETUP_ARTWORK;
6972 else if (setup_mode == SETUP_MODE_TOUCH)
6974 setup_info = setup_info_touch;
6975 title_string = STR_SETUP_TOUCH;
6977 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
6978 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
6979 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
6980 setup_info = setup_info_touch_wipe_gestures;
6982 else if (setup_mode == SETUP_MODE_SHORTCUTS)
6984 setup_info = setup_info_shortcuts;
6985 title_string = STR_SETUP_SHORTCUTS;
6987 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
6989 setup_info = setup_info_shortcuts_1;
6990 title_string = STR_SETUP_SHORTCUTS;
6992 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
6994 setup_info = setup_info_shortcuts_2;
6995 title_string = STR_SETUP_SHORTCUTS;
6997 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
6999 setup_info = setup_info_shortcuts_3;
7000 title_string = STR_SETUP_SHORTCUTS;
7002 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
7004 setup_info = setup_info_shortcuts_4;
7005 title_string = STR_SETUP_SHORTCUTS;
7007 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
7009 setup_info = setup_info_shortcuts_5;
7010 title_string = STR_SETUP_SHORTCUTS;
7013 // use modified setup info without setup entries marked as hidden
7014 setup_info = getSetupInfoFinal(setup_info);
7016 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
7018 // determine maximal number of setup entries that can be displayed on screen
7020 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
7023 // determine maximal number of setup entries available for this setup screen
7025 for (i = 0; setup_info[i].type != 0; i++)
7028 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
7030 MapScreenGadgets(max_setup_info);
7033 redraw_mask = fade_mask = REDRAW_ALL;
7035 DrawMaskedBorder(fade_mask);
7040 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
7042 menu_info = setup_info;
7044 HandleMenuScreen(mx, my, dx, dy, button,
7045 setup_mode, num_setup_info, max_setup_info);
7048 static void DrawSetupScreen_Input(void)
7052 FadeOut(REDRAW_FIELD);
7056 setup_info = getSetupInfoFinal(setup_info_input);
7058 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
7060 for (i = 0; setup_info[i].type != 0; i++)
7062 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
7063 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
7064 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
7065 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
7066 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
7067 initCursor(i, IMG_MENU_BUTTON);
7069 DrawCursorAndText_Setup(i, -1, FALSE);
7072 // create gadgets for setup input menu screen
7073 FreeScreenGadgets();
7074 CreateScreenGadgets();
7076 // map gadgets for setup input menu screen
7077 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
7079 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
7081 FadeIn(REDRAW_FIELD);
7084 static void setJoystickDeviceToNr(char *device_name, int device_nr)
7086 if (device_name == NULL)
7089 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
7092 if (strlen(device_name) > 1)
7094 char c1 = device_name[strlen(device_name) - 1];
7095 char c2 = device_name[strlen(device_name) - 2];
7097 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
7098 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
7101 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
7102 strlen(device_name));
7105 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
7108 static struct SetupKeyboardInfo custom_key;
7115 { &custom_key.left, "Axis/Pad Left" },
7116 { &custom_key.right, "Axis/Pad Right" },
7117 { &custom_key.up, "Axis/Pad Up" },
7118 { &custom_key.down, "Axis/Pad Down" },
7119 { &custom_key.snap, "Button 1/A/X" },
7120 { &custom_key.drop, "Button 2/B/Y" }
7122 static char *joystick_name[MAX_PLAYERS] =
7129 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
7130 int font_nr_info = FONT_MENU_1;
7131 int font_nr_name = FONT_VALUE_OLD;
7132 int font_nr_on = FONT_VALUE_1;
7133 int font_nr_off = FONT_VALUE_OLD;
7136 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7138 font_nr_info = FONT_MENU_2;
7139 font_nr_on = FONT_VALUE_NARROW;
7140 font_nr_off = FONT_VALUE_OLD_NARROW;
7143 custom_key = setup.input[player_nr].key;
7145 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
7146 FONT_INPUT_1_ACTIVE);
7148 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7150 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
7151 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7153 if (setup.input[player_nr].use_joystick)
7155 char *device_name = setup.input[player_nr].joy.device_name;
7156 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7157 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7158 char *text = joystick_name[joystick_nr];
7159 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
7161 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
7162 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
7166 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
7167 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
7170 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
7171 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
7175 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
7176 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
7177 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
7178 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
7180 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
7181 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
7182 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
7183 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
7184 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
7185 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
7187 for (i = 0; i < 6; i++)
7189 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
7191 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7193 DrawText(mSX + 3 * 32, mSY + ypos * 32,
7194 (setup.input[player_nr].use_joystick ?
7196 getKeyNameFromKey(*custom[i].key)), font_nr_on);
7200 static int input_player_nr = 0;
7202 static void HandleSetupScreen_Input_Player(int step, int direction)
7204 int old_player_nr = input_player_nr;
7207 new_player_nr = old_player_nr + step * direction;
7208 if (new_player_nr < 0)
7210 if (new_player_nr > MAX_PLAYERS - 1)
7211 new_player_nr = MAX_PLAYERS - 1;
7213 if (new_player_nr != old_player_nr)
7215 input_player_nr = new_player_nr;
7217 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7221 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
7223 static int choice = 0;
7226 int pos_start = SETUPINPUT_SCREEN_POS_START;
7227 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
7228 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
7229 int pos_end = SETUPINPUT_SCREEN_POS_END;
7231 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
7235 for (i = 0; setup_info_input[i].type != 0; i++)
7237 // adjust menu structure according to skipped setup entries
7238 if (setup_info_input[i].type == TYPE_SKIPPABLE)
7246 if (button == MB_MENU_INITIALIZE)
7248 // input setup menu may have changed size due to graphics configuration
7249 if (choice >= pos_empty1)
7252 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
7254 DrawCursorAndText_Setup(choice, -1, TRUE);
7258 else if (button == MB_MENU_LEAVE)
7260 setup_mode = SETUP_MODE_MAIN;
7267 if (mx || my) // mouse input
7269 x = (mx - mSX) / 32;
7270 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
7272 else if (dx || dy) // keyboard input
7274 if (dx && choice == 0)
7275 x = (dx < 0 ? 10 : 12);
7276 else if ((dx && choice == 1) ||
7277 (dx == -1 && choice == pos_end))
7278 button = MB_MENU_CHOICE;
7282 if (y >= pos_empty1 && y <= pos_empty2)
7283 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
7286 if (y == 0 && dx != 0 && button)
7288 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
7290 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
7291 y >= pos_start && y <= pos_end &&
7292 !(y >= pos_empty1 && y <= pos_empty2))
7298 DrawCursorAndText_Setup(choice, -1, FALSE);
7299 DrawCursorAndText_Setup(y, -1, TRUE);
7301 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
7310 char *device_name = setup.input[input_player_nr].joy.device_name;
7312 if (!setup.input[input_player_nr].use_joystick)
7314 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
7316 setJoystickDeviceToNr(device_name, new_device_nr);
7317 setup.input[input_player_nr].use_joystick = TRUE;
7321 int device_nr = getJoystickNrFromDeviceName(device_name);
7322 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
7324 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
7325 setup.input[input_player_nr].use_joystick = FALSE;
7327 setJoystickDeviceToNr(device_name, new_device_nr);
7330 drawPlayerSetupInputInfo(input_player_nr, FALSE);
7334 if (setup.input[input_player_nr].use_joystick)
7335 ConfigureJoystick(input_player_nr);
7337 CustomizeKeyboard(input_player_nr);
7339 else if (y == pos_end)
7345 setup_mode = SETUP_MODE_MAIN;
7352 static boolean CustomizeKeyboardMain(int player_nr)
7356 boolean finished = FALSE;
7357 static struct SetupKeyboardInfo custom_key;
7362 } customize_step[] =
7364 { &custom_key.left, "Move Left" },
7365 { &custom_key.right, "Move Right" },
7366 { &custom_key.up, "Move Up" },
7367 { &custom_key.down, "Move Down" },
7368 { &custom_key.snap, "Snap Field" },
7369 { &custom_key.drop, "Drop Element" }
7371 int font_nr_old = FONT_VALUE_OLD;
7372 int font_nr_new = FONT_VALUE_1;
7373 boolean success = FALSE;
7375 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
7377 font_nr_old = FONT_VALUE_OLD_NARROW;
7378 font_nr_new = FONT_VALUE_NARROW;
7381 // read existing key bindings from player setup
7382 custom_key = setup.input[player_nr].key;
7385 FadeOut(REDRAW_FIELD);
7389 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
7392 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7393 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7394 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7395 "Key:", FONT_INPUT_1_ACTIVE);
7396 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7397 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
7399 FadeIn(REDRAW_FIELD);
7405 if (NextValidEvent(&event))
7409 case EVENT_KEYPRESS:
7411 Key key = GetEventKey((KeyEvent *)&event, FALSE);
7413 // press 'Escape' to abort and keep the old key bindings
7414 if (key == KSYM_Escape)
7416 FadeSkipNextFadeIn();
7423 // press 'Enter' to keep the existing key binding
7424 if (key == KSYM_Return)
7425 key = *customize_step[step_nr].key;
7427 // check if key already used
7428 for (i = 0; i < step_nr; i++)
7429 if (*customize_step[i].key == key)
7434 // got new key binding
7435 *customize_step[step_nr].key = key;
7436 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7438 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7439 getKeyNameFromKey(key), font_nr_new);
7442 // un-highlight last query
7443 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
7444 customize_step[step_nr - 1].text, FONT_MENU_1);
7445 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
7446 "Key:", FONT_MENU_1);
7448 // all keys configured
7457 // query next key binding
7458 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
7459 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
7460 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
7461 "Key:", FONT_INPUT_1_ACTIVE);
7462 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
7463 getKeyNameFromKey(*customize_step[step_nr].key),
7468 case EVENT_KEYRELEASE:
7469 key_joystick_mapping = 0;
7473 HandleOtherEvents(&event);
7481 // write new key bindings back to player setup, if successfully finished
7483 setup.input[player_nr].key = custom_key;
7488 void CustomizeKeyboard(int player_nr)
7490 boolean success = CustomizeKeyboardMain(player_nr);
7494 int font_nr = FONT_TITLE_1;
7495 int font_height = getFontHeight(font_nr);
7496 int ypos1 = SYSIZE / 2 - font_height * 2;
7497 int ypos2 = SYSIZE / 2 - font_height * 1;
7498 unsigned int wait_frame_delay = 0;
7499 unsigned int wait_frame_delay_value = 2000;
7501 ResetDelayCounter(&wait_frame_delay);
7505 DrawTextSCentered(ypos1, font_nr, "Keyboard");
7506 DrawTextSCentered(ypos2, font_nr, "configured!");
7508 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7514 DrawSetupScreen_Input();
7517 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
7519 #define MARKER_BUTTON 1
7520 #define MARKER_AXIS_X 2
7521 #define MARKER_AXIS_Y 3
7523 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
7525 static boolean bitmaps_initialized = FALSE;
7526 boolean screen_initialized = FALSE;
7527 static Bitmap *controller, *button, *axis_x, *axis_y;
7529 boolean success = TRUE;
7530 boolean done = FALSE, next = FALSE;
7532 int alpha = 200, alpha_step = -1;
7533 int alpha_ticks = 0;
7534 char mapping[4096], temp[4096];
7535 int font_name = MENU_SETUP_FONT_TITLE;
7536 int font_info = MENU_SETUP_FONT_TEXT;
7537 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
7538 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
7539 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
7540 int ystep_name = getMenuTextStep(spacing_name, font_name);
7541 int ystep_line = getMenuTextStep(spacing_line, font_info);
7542 int ystep_para = getMenuTextStep(spacing_para, font_info);
7550 int axis, button, hat, hat_value;
7553 *step, *prev_step, steps[] =
7555 { 356, 155, MARKER_BUTTON, "a", },
7556 { 396, 122, MARKER_BUTTON, "b", },
7557 { 320, 125, MARKER_BUTTON, "x", },
7558 { 358, 95, MARKER_BUTTON, "y", },
7559 { 162, 125, MARKER_BUTTON, "back", },
7560 { 216, 125, MARKER_BUTTON, "guide", },
7561 { 271, 125, MARKER_BUTTON, "start", },
7562 { 110, 200, MARKER_BUTTON, "dpleft", },
7563 { 146, 228, MARKER_BUTTON, "dpdown", },
7564 { 178, 200, MARKER_BUTTON, "dpright", },
7565 { 146, 172, MARKER_BUTTON, "dpup", },
7566 { 50, 40, MARKER_BUTTON, "leftshoulder", },
7567 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
7568 { 382, 40, MARKER_BUTTON, "rightshoulder", },
7569 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
7570 { 73, 141, MARKER_BUTTON, "leftstick", },
7571 { 282, 210, MARKER_BUTTON, "rightstick", },
7572 { 73, 141, MARKER_AXIS_X, "leftx", },
7573 { 73, 141, MARKER_AXIS_Y, "lefty", },
7574 { 282, 210, MARKER_AXIS_X, "rightx", },
7575 { 282, 210, MARKER_AXIS_Y, "righty", },
7578 unsigned int event_frame_delay = 0;
7579 unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
7581 ResetDelayCounter(&event_frame_delay);
7583 if (!bitmaps_initialized)
7585 controller = LoadCustomImage("joystick/controller.png");
7586 button = LoadCustomImage("joystick/button.png");
7587 axis_x = LoadCustomImage("joystick/axis_x.png");
7588 axis_y = LoadCustomImage("joystick/axis_y.png");
7590 bitmaps_initialized = TRUE;
7593 name = getFormattedJoystickName(SDL_JoystickName(joystick));
7596 // print info about the joystick we are watching
7597 Error(ERR_DEBUG, "watching joystick %d: (%s)\n",
7598 SDL_JoystickInstanceID(joystick), name);
7599 Error(ERR_DEBUG, "joystick has %d axes, %d hats, %d balls, and %d buttons\n",
7600 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
7601 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
7604 // initialize mapping with GUID and name
7605 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
7607 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
7608 temp, name, SDL_GetPlatform());
7610 // loop through all steps (buttons and axes), getting joystick events
7611 for (i = 0; i < SDL_arraysize(steps) && !done;)
7613 Bitmap *marker = button; // initialize with reliable default value
7616 strcpy(step->mapping, mapping);
7620 step->hat_value = -1;
7622 marker = (step->marker == MARKER_BUTTON ? button :
7623 step->marker == MARKER_AXIS_X ? axis_x :
7624 step->marker == MARKER_AXIS_Y ? axis_y : marker);
7628 while (!done && !next)
7630 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
7631 alpha_ticks = SDL_GetTicks();
7638 else if (alpha < 128)
7644 int controller_x = SX + (SXSIZE - controller->width) / 2;
7645 int controller_y = SY + ystep_line;
7647 int marker_x = controller_x + step->x;
7648 int marker_y = controller_y + step->y;
7650 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
7651 int ystart2 = ystart1 + ystep_name + ystep_line;
7655 DrawTextSCentered(ystart1, font_name, name);
7657 DrawTextSCentered(ystart2, font_info,
7658 "Press buttons and move axes on");
7659 ystart2 += ystep_line;
7660 DrawTextSCentered(ystart2, font_info,
7661 "your controller when indicated.");
7662 ystart2 += ystep_line;
7663 DrawTextSCentered(ystart2, font_info,
7664 "(Your controller may look different.)");
7665 ystart2 += ystep_para;
7667 #if defined(PLATFORM_ANDROID)
7668 DrawTextSCentered(ystart2, font_info,
7669 "To correct a mistake,");
7670 ystart2 += ystep_line;
7671 DrawTextSCentered(ystart2, font_info,
7672 "press the 'back' button.");
7673 ystart2 += ystep_line;
7674 DrawTextSCentered(ystart2, font_info,
7675 "To skip a button or axis,");
7676 ystart2 += ystep_line;
7677 DrawTextSCentered(ystart2, font_info,
7678 "press the 'menu' button.");
7680 DrawTextSCentered(ystart2, font_info,
7681 "To correct a mistake,");
7682 ystart2 += ystep_line;
7683 DrawTextSCentered(ystart2, font_info,
7684 "press the 'backspace' key.");
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 'return' key.");
7691 ystart2 += ystep_line;
7692 DrawTextSCentered(ystart2, font_info,
7693 "To exit, press the 'escape' key.");
7696 BlitBitmapMasked(controller, drawto, 0, 0,
7697 controller->width, controller->height,
7698 controller_x, controller_y);
7700 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
7701 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
7703 BlitBitmapMasked(marker, drawto, 0, 0,
7704 marker->width, marker->height,
7705 marker_x, marker_y);
7707 if (!screen_initialized)
7708 FadeIn(REDRAW_FIELD);
7712 screen_initialized = TRUE;
7714 while (NextValidEvent(&event))
7718 case SDL_JOYAXISMOTION:
7719 if (event.jaxis.value > 20000 ||
7720 event.jaxis.value < -20000)
7722 for (j = 0; j < i; j++)
7723 if (steps[j].axis == event.jaxis.axis)
7728 if (step->marker != MARKER_AXIS_X &&
7729 step->marker != MARKER_AXIS_Y)
7732 step->axis = event.jaxis.axis;
7733 strcat(mapping, step->field);
7734 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
7735 strcat(mapping, temp);
7743 case SDL_JOYHATMOTION:
7744 // ignore centering; we're probably just coming back
7745 // to the center from the previous item we set
7746 if (event.jhat.value == SDL_HAT_CENTERED)
7749 for (j = 0; j < i; j++)
7750 if (steps[j].hat == event.jhat.hat &&
7751 steps[j].hat_value == event.jhat.value)
7756 step->hat = event.jhat.hat;
7757 step->hat_value = event.jhat.value;
7758 strcat(mapping, step->field);
7759 snprintf(temp, sizeof(temp), ":h%u.%u,",
7760 event.jhat.hat, event.jhat.value );
7761 strcat(mapping, temp);
7768 case SDL_JOYBALLMOTION:
7771 case SDL_JOYBUTTONUP:
7772 for (j = 0; j < i; j++)
7773 if (steps[j].button == event.jbutton.button)
7778 step->button = event.jbutton.button;
7779 strcat(mapping, step->field);
7780 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
7781 strcat(mapping, temp);
7788 case SDL_FINGERDOWN:
7789 case SDL_MOUSEBUTTONDOWN:
7797 if (event.key.keysym.sym == KSYM_BackSpace ||
7798 event.key.keysym.sym == KSYM_Back)
7810 prev_step = &steps[i - 1];
7811 strcpy(mapping, prev_step->mapping);
7818 if (event.key.keysym.sym == KSYM_space ||
7819 event.key.keysym.sym == KSYM_Return ||
7820 event.key.keysym.sym == KSYM_Menu)
7829 if (event.key.keysym.sym == KSYM_Escape)
7839 program.exit_function(0);
7846 // do not handle events for longer than standard frame delay period
7847 if (DelayReached(&event_frame_delay, event_frame_delay_value))
7856 Error(ERR_DEBUG, "New game controller mapping:\n\n%s\n\n", mapping);
7859 // activate mapping for this game
7860 SDL_GameControllerAddMapping(mapping);
7862 // save mapping to personal mappings
7863 SaveSetup_AddGameControllerMapping(mapping);
7866 // wait until the last pending event was removed from event queue
7867 while (NextValidEvent(&event));
7872 static int ConfigureJoystickMain(int player_nr)
7874 char *device_name = setup.input[player_nr].joy.device_name;
7875 int joystick_nr = getJoystickNrFromDeviceName(device_name);
7876 boolean joystick_active = CheckJoystickOpened(joystick_nr);
7877 int success = FALSE;
7880 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
7881 return JOYSTICK_NOT_AVAILABLE;
7883 if (!joystick_active || !setup.input[player_nr].use_joystick)
7884 return JOYSTICK_NOT_AVAILABLE;
7887 FadeOut(REDRAW_FIELD);
7889 // close all joystick devices (potentially opened as game controllers)
7890 for (i = 0; i < SDL_NumJoysticks(); i++)
7891 SDLCloseJoystick(i);
7893 // open joystick device as plain joystick to configure as game controller
7894 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
7896 // as the joystick was successfully opened before, this should not happen
7897 if (joystick == NULL)
7900 // create new game controller mapping (buttons and axes) for joystick device
7901 success = ConfigureJoystickMapButtonsAndAxes(joystick);
7903 // close joystick (and maybe re-open as configured game controller later)
7904 SDL_JoystickClose(joystick);
7906 // re-open all joystick devices (potentially as game controllers)
7907 for (i = 0; i < SDL_NumJoysticks(); i++)
7910 // clear all joystick input actions for all joystick devices
7911 SDLClearJoystickState();
7913 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
7916 void ConfigureJoystick(int player_nr)
7918 boolean state = ConfigureJoystickMain(player_nr);
7920 if (state != JOYSTICK_NOT_CONFIGURED)
7922 boolean success = (state == JOYSTICK_CONFIGURED);
7923 char message1[MAX_OUTPUT_LINESIZE + 1];
7924 char *message2 = (success ? "configured!" : "not available!");
7925 char *device_name = setup.input[player_nr].joy.device_name;
7926 int nr = getJoystickNrFromDeviceName(device_name) + 1;
7927 int font_nr = FONT_TITLE_1;
7928 int font_height = getFontHeight(font_nr);
7929 int ypos1 = SYSIZE / 2 - font_height * 2;
7930 int ypos2 = SYSIZE / 2 - font_height * 1;
7931 unsigned int wait_frame_delay = 0;
7932 unsigned int wait_frame_delay_value = 2000;
7934 ResetDelayCounter(&wait_frame_delay);
7938 sprintf(message1, "Joystick %d", nr);
7940 DrawTextSCentered(ypos1, font_nr, message1);
7941 DrawTextSCentered(ypos2, font_nr, message2);
7943 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
7949 DrawSetupScreen_Input();
7952 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
7954 if (y < video.screen_height / 3)
7956 // remap touch gadgets to access upper part of the screen
7957 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7958 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7960 else if (y > 2 * video.screen_height / 3)
7962 // remap touch gadgets to access lower part of the screen
7963 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
7964 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
7968 static boolean ConfigureVirtualButtonsMain(void)
7970 static char *customize_step_text[] =
7979 char grid_button[] =
7981 CHAR_GRID_BUTTON_LEFT,
7982 CHAR_GRID_BUTTON_RIGHT,
7983 CHAR_GRID_BUTTON_UP,
7984 CHAR_GRID_BUTTON_DOWN,
7985 CHAR_GRID_BUTTON_SNAP,
7986 CHAR_GRID_BUTTON_DROP
7995 int font_nr = FONT_INPUT_1_ACTIVE;
7996 int font_height = getFontHeight(font_nr);
7997 int ypos1 = SYSIZE / 2 - font_height * 2;
7998 int ypos2 = SYSIZE / 2 - font_height * 1;
7999 boolean success = FALSE;
8000 boolean finished = FALSE;
8002 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
8003 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8004 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
8005 boolean set_grid_button = FALSE;
8006 int nr = GRID_ACTIVE_NR();
8009 for (x = 0; x < MAX_GRID_XSIZE; x++)
8010 for (y = 0; y < MAX_GRID_YSIZE; y++)
8011 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
8013 overlay.grid_button_highlight = grid_button[step_nr];
8018 FadeOut(REDRAW_FIELD);
8022 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8023 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8024 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8026 FadeIn(REDRAW_FIELD);
8028 SetOverlayShowGrid(TRUE);
8030 // map gadgets for setup touch buttons menu screen
8031 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
8037 while (NextValidEvent(&event))
8039 int action = ACTION_NONE;
8041 // ---------- handle events and set the resulting action ----------
8047 UserEvent *user = (UserEvent *)&event;
8048 int id = user->value1;
8050 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
8051 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
8052 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
8053 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
8058 case EVENT_KEYPRESS:
8060 Key key = GetEventKey((KeyEvent *)&event, FALSE);
8062 action = (key == KSYM_Escape ? ACTION_ESCAPE :
8063 key == KSYM_BackSpace ||
8064 key == KSYM_Back ? ACTION_BACK :
8065 key == KSYM_Return ||
8067 key == KSYM_space ? ACTION_NEXT :
8072 case EVENT_KEYRELEASE:
8073 key_joystick_mapping = 0;
8076 case EVENT_BUTTONPRESS:
8077 case EVENT_BUTTONRELEASE:
8079 ButtonEvent *button = (ButtonEvent *)&event;
8081 motion_status = FALSE;
8083 if (button->type == EVENT_BUTTONPRESS)
8084 button_status = button->button;
8086 button_status = MB_RELEASED;
8088 if (HandleGadgets(button->x, button->y, button_status))
8090 // do not handle this button event anymore
8094 button->x += video.screen_xoffset;
8095 button->y += video.screen_yoffset;
8097 x = button->x * overlay.grid_xsize / video.screen_width;
8098 y = button->y * overlay.grid_ysize / video.screen_height;
8100 if (button->type == EVENT_BUTTONPRESS)
8103 (overlay.grid_button[x][y] != grid_button[step_nr] ?
8104 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
8106 set_grid_button = TRUE;
8109 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
8113 case EVENT_MOTIONNOTIFY:
8115 MotionEvent *motion = (MotionEvent *)&event;
8117 motion_status = TRUE;
8119 if (HandleGadgets(motion->x, motion->y, button_status))
8121 // do not handle this button event anymore
8125 motion->x += video.screen_xoffset;
8126 motion->y += video.screen_yoffset;
8128 x = motion->x * overlay.grid_xsize / video.screen_width;
8129 y = motion->y * overlay.grid_ysize / video.screen_height;
8131 set_grid_button = TRUE;
8133 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
8137 case SDL_WINDOWEVENT:
8138 HandleWindowEvent((WindowEvent *) &event);
8140 // check if device has been rotated
8141 if (nr != GRID_ACTIVE_NR())
8143 nr = GRID_ACTIVE_NR();
8145 for (x = 0; x < MAX_GRID_XSIZE; x++)
8146 for (y = 0; y < MAX_GRID_YSIZE; y++)
8147 grid_button_old[x][y] = grid_button_tmp[x][y] =
8148 overlay.grid_button[x][y];
8153 case SDL_APP_WILLENTERBACKGROUND:
8154 case SDL_APP_DIDENTERBACKGROUND:
8155 case SDL_APP_WILLENTERFOREGROUND:
8156 case SDL_APP_DIDENTERFOREGROUND:
8157 HandlePauseResumeEvent((PauseResumeEvent *) &event);
8161 HandleOtherEvents(&event);
8165 // ---------- perform action set by handling events ----------
8167 if (action == ACTION_ESCAPE)
8169 // abort and restore the old key bindings
8171 for (x = 0; x < MAX_GRID_XSIZE; x++)
8172 for (y = 0; y < MAX_GRID_YSIZE; y++)
8173 overlay.grid_button[x][y] = grid_button_old[x][y];
8175 FadeSkipNextFadeIn();
8179 else if (action == ACTION_BACK)
8181 // keep the configured key bindings and go to previous page
8187 FadeSkipNextFadeIn();
8192 else if (action == ACTION_NEXT)
8194 // keep the configured key bindings and go to next page
8198 // all virtual buttons configured
8206 if (action != ACTION_NONE && !finished)
8208 for (x = 0; x < MAX_GRID_XSIZE; x++)
8209 for (y = 0; y < MAX_GRID_YSIZE; y++)
8210 grid_button_tmp[x][y] = overlay.grid_button[x][y];
8212 overlay.grid_button_highlight = grid_button[step_nr];
8214 // configure next virtual button
8218 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
8219 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
8220 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
8223 if (set_grid_button)
8225 overlay.grid_button[x][y] =
8226 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
8227 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
8228 grid_button_tmp[x][y]);
8230 set_grid_button = FALSE;
8237 for (x = 0; x < MAX_GRID_XSIZE; x++)
8238 for (y = 0; y < MAX_GRID_YSIZE; y++)
8239 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8241 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
8243 SetOverlayShowGrid(FALSE);
8248 void ConfigureVirtualButtons(void)
8250 boolean success = ConfigureVirtualButtonsMain();
8252 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
8253 SCREEN_MASK_TOUCH2);
8257 int font_nr = FONT_TITLE_1;
8258 int font_height = getFontHeight(font_nr);
8259 int ypos1 = SYSIZE / 2 - font_height * 2;
8260 int ypos2 = SYSIZE / 2 - font_height * 1;
8261 unsigned int wait_frame_delay = 0;
8262 unsigned int wait_frame_delay_value = 2000;
8264 ResetDelayCounter(&wait_frame_delay);
8268 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
8269 DrawTextSCentered(ypos2, font_nr, "configured!");
8271 while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
8278 void DrawSetupScreen(void)
8283 if (setup_mode == SETUP_MODE_INPUT)
8284 DrawSetupScreen_Input();
8285 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8286 DrawChooseTree(&game_speed_current);
8287 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8288 DrawChooseTree(&scroll_delay_current);
8289 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8290 DrawChooseTree(&snapshot_mode_current);
8291 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8292 DrawChooseTree(&window_size_current);
8293 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8294 DrawChooseTree(&scaling_type_current);
8295 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8296 DrawChooseTree(&rendering_mode_current);
8297 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8298 DrawChooseTree(&vsync_mode_current);
8299 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8300 DrawChooseTree(&artwork.gfx_current);
8301 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8302 DrawChooseTree(&artwork.snd_current);
8303 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8304 DrawChooseTree(&artwork.mus_current);
8305 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8306 DrawChooseTree(&volume_simple_current);
8307 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8308 DrawChooseTree(&volume_loops_current);
8309 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8310 DrawChooseTree(&volume_music_current);
8311 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8312 DrawChooseTree(&touch_control_current);
8313 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8314 DrawChooseTree(&move_distance_current);
8315 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8316 DrawChooseTree(&drop_distance_current);
8317 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8318 DrawChooseTree(&transparency_current);
8319 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8320 DrawChooseTree(&grid_size_current[0][0]);
8321 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8322 DrawChooseTree(&grid_size_current[0][1]);
8323 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8324 DrawChooseTree(&grid_size_current[1][0]);
8325 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8326 DrawChooseTree(&grid_size_current[1][1]);
8328 DrawSetupScreen_Generic();
8330 PlayMenuSoundsAndMusic();
8333 void RedrawSetupScreenAfterFullscreenToggle(void)
8335 if (setup_mode == SETUP_MODE_GRAPHICS ||
8336 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8338 // update list selection from "setup.window_scaling_percent"
8339 execSetupGraphics_setWindowSizes(TRUE);
8345 void RedrawSetupScreenAfterScreenRotation(int nr)
8349 if (setup_mode == SETUP_MODE_TOUCH)
8351 // update virtual button settings (depending on screen orientation)
8354 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
8356 // save already configured virtual buttons
8357 for (x = 0; x < MAX_GRID_XSIZE; x++)
8358 for (y = 0; y < MAX_GRID_YSIZE; y++)
8359 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
8363 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
8365 if (setup_mode == SETUP_MODE_INPUT)
8366 HandleSetupScreen_Input(mx, my, dx, dy, button);
8367 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
8368 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
8369 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
8370 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
8371 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
8372 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
8373 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
8374 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
8375 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
8376 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
8377 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
8378 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
8379 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
8380 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
8381 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
8382 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
8383 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
8384 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
8385 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
8386 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
8387 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
8388 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
8389 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
8390 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
8391 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
8392 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
8393 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
8394 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
8395 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
8396 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
8397 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
8398 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
8399 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
8400 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
8401 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
8402 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
8403 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
8404 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
8405 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
8406 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
8407 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
8408 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
8410 HandleSetupScreen_Generic(mx, my, dx, dy, button);
8413 void HandleGameActions(void)
8415 if (setup.ask_on_game_over)
8418 if (game.restart_game_message != NULL)
8420 RequestRestartGame(game.restart_game_message);
8425 if (game_status != GAME_MODE_PLAYING)
8428 GameActions(); // main game loop
8430 if (tape.auto_play && !tape.playing)
8431 AutoPlayTape(); // continue automatically playing next tape
8435 // ---------- new screen button stuff --------------------------------------
8439 int gfx_unpressed, gfx_pressed;
8440 struct MenuPosInfo *pos;
8441 boolean *check_value;
8444 unsigned int event_mask;
8445 boolean is_touch_button;
8447 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
8450 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE,
8451 &menu.main.button.prev_level, NULL,
8452 SCREEN_CTRL_ID_PREV_LEVEL,
8454 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8455 FALSE, "previous level"
8458 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE,
8459 &menu.main.button.next_level, NULL,
8460 SCREEN_CTRL_ID_NEXT_LEVEL,
8462 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8466 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE,
8467 &menu.main.button.first_level, NULL,
8468 SCREEN_CTRL_ID_FIRST_LEVEL,
8471 FALSE, "first level"
8474 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE,
8475 &menu.main.button.last_level, NULL,
8476 SCREEN_CTRL_ID_LAST_LEVEL,
8482 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE,
8483 &menu.main.button.level_number, NULL,
8484 SCREEN_CTRL_ID_LEVEL_NUMBER,
8487 FALSE, "level number"
8490 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE,
8491 &menu.setup.button.prev_player, NULL,
8492 SCREEN_CTRL_ID_PREV_PLAYER,
8494 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8495 FALSE, "previous player"
8498 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE,
8499 &menu.setup.button.next_player, NULL,
8500 SCREEN_CTRL_ID_NEXT_PLAYER,
8502 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
8503 FALSE, "next player"
8506 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE,
8507 &menu.main.button.insert_solution, NULL,
8508 SCREEN_CTRL_ID_INSERT_SOLUTION,
8509 SCREEN_MASK_MAIN_HAS_SOLUTION,
8511 FALSE, "insert solution tape"
8514 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE,
8515 &menu.main.button.play_solution, NULL,
8516 SCREEN_CTRL_ID_PLAY_SOLUTION,
8517 SCREEN_MASK_MAIN_HAS_SOLUTION,
8519 FALSE, "play solution tape"
8522 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE,
8523 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
8524 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
8526 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
8527 FALSE, "switch ECS/AGA chipset"
8530 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK,
8531 &menu.setup.button.touch_back, NULL,
8532 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
8535 TRUE, "previous page"
8538 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT,
8539 &menu.setup.button.touch_next, NULL,
8540 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
8546 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2,
8547 &menu.setup.button.touch_back2, NULL,
8548 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
8551 TRUE, "previous page"
8554 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2,
8555 &menu.setup.button.touch_next2, NULL,
8556 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
8565 int gfx_unpressed, gfx_pressed;
8569 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
8572 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
8573 -1, -1, // these values are not constant, but can change at runtime
8574 SCREEN_CTRL_ID_SCROLL_UP,
8578 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
8579 -1, -1, // these values are not constant, but can change at runtime
8580 SCREEN_CTRL_ID_SCROLL_DOWN,
8587 int gfx_unpressed, gfx_pressed;
8593 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
8596 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
8597 -1, -1, // these values are not constant, but can change at runtime
8598 -1, -1, // these values are not constant, but can change at runtime
8599 GD_TYPE_SCROLLBAR_VERTICAL,
8600 SCREEN_CTRL_ID_SCROLL_VERTICAL,
8601 "scroll level series vertically"
8613 } textinput_info[NUM_SCREEN_TEXTINPUT] =
8616 IMG_SETUP_INPUT_TEXT,
8617 SCREEN_CTRL_ID_NETWORK_SERVER,
8618 -1, -1, // these values are not constant, but can change at runtime
8619 MAX_SETUP_TEXT_INPUT_LEN,
8620 network_server_hostname,
8621 "Network Server Hostname / IP"
8625 static void CreateScreenMenubuttons(void)
8627 struct GadgetInfo *gi;
8628 unsigned int event_mask;
8631 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8633 struct MenuPosInfo *pos = menubutton_info[i].pos;
8634 boolean is_touch_button = menubutton_info[i].is_touch_button;
8635 boolean is_check_button = menubutton_info[i].check_value != NULL;
8636 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8637 int gfx_unpressed, gfx_pressed;
8638 int x, y, width, height;
8639 int gd_x1, gd_x2, gd_y1, gd_y2;
8640 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
8641 int id = menubutton_info[i].gadget_id;
8642 int type = GD_TYPE_NORMAL_BUTTON;
8643 boolean checked = FALSE;
8645 event_mask = menubutton_info[i].event_mask;
8647 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
8648 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
8650 width = graphic_info[menubutton_info[i].gfx_pressed].width;
8651 height = graphic_info[menubutton_info[i].gfx_pressed].height;
8653 gfx_unpressed = menubutton_info[i].gfx_unpressed;
8654 gfx_pressed = menubutton_info[i].gfx_pressed;
8655 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8656 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8657 gd_x1 = graphic_info[gfx_unpressed].src_x;
8658 gd_y1 = graphic_info[gfx_unpressed].src_y;
8659 gd_x2 = graphic_info[gfx_pressed].src_x;
8660 gd_y2 = graphic_info[gfx_pressed].src_y;
8666 if (is_touch_button)
8668 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
8669 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
8672 if (is_check_button)
8674 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
8675 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
8676 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
8677 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
8679 type = GD_TYPE_CHECK_BUTTON;
8680 checked = *menubutton_info[i].check_value;
8683 gi = CreateGadget(GDI_CUSTOM_ID, id,
8684 GDI_CUSTOM_TYPE_ID, i,
8685 GDI_IMAGE_ID, gfx_unpressed,
8686 GDI_INFO_TEXT, menubutton_info[i].infotext,
8692 GDI_STATE, GD_BUTTON_UNPRESSED,
8693 GDI_CHECKED, checked,
8694 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8695 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8696 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1a, gd_y1a,
8697 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2a, gd_y2a,
8698 GDI_DIRECT_DRAW, FALSE,
8699 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
8700 GDI_EVENT_MASK, event_mask,
8701 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8705 Error(ERR_EXIT, "cannot create gadget");
8707 screen_gadget[id] = gi;
8711 static void CreateScreenScrollbuttons(void)
8713 struct GadgetInfo *gi;
8714 unsigned int event_mask;
8717 // these values are not constant, but can change at runtime
8718 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
8719 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
8720 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
8721 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
8723 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8725 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8726 int gfx_unpressed, gfx_pressed;
8727 int x, y, width, height;
8728 int gd_x1, gd_x2, gd_y1, gd_y2;
8729 int id = scrollbutton_info[i].gadget_id;
8731 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8733 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
8734 y = mSY + scrollbutton_info[i].y;
8735 width = SC_SCROLLBUTTON_XSIZE;
8736 height = SC_SCROLLBUTTON_YSIZE;
8738 // correct scrollbar position if placed outside menu (playfield) area
8739 if (x > SX + SC_SCROLL_UP_XPOS)
8740 x = SX + SC_SCROLL_UP_XPOS;
8742 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
8743 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
8744 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
8746 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
8747 gfx_pressed = scrollbutton_info[i].gfx_pressed;
8748 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8749 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8750 gd_x1 = graphic_info[gfx_unpressed].src_x;
8751 gd_y1 = graphic_info[gfx_unpressed].src_y;
8752 gd_x2 = graphic_info[gfx_pressed].src_x;
8753 gd_y2 = graphic_info[gfx_pressed].src_y;
8755 gi = CreateGadget(GDI_CUSTOM_ID, id,
8756 GDI_CUSTOM_TYPE_ID, i,
8757 GDI_IMAGE_ID, gfx_unpressed,
8758 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8763 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8764 GDI_STATE, GD_BUTTON_UNPRESSED,
8765 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8766 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8767 GDI_DIRECT_DRAW, FALSE,
8768 GDI_EVENT_MASK, event_mask,
8769 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8773 Error(ERR_EXIT, "cannot create gadget");
8775 screen_gadget[id] = gi;
8779 static void CreateScreenScrollbars(void)
8783 // these values are not constant, but can change at runtime
8784 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
8785 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
8786 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
8787 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
8789 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8791 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
8792 int gfx_unpressed, gfx_pressed;
8793 int x, y, width, height;
8794 int gd_x1, gd_x2, gd_y1, gd_y2;
8795 struct GadgetInfo *gi;
8796 int items_max, items_visible, item_position;
8797 unsigned int event_mask;
8798 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
8799 int id = scrollbar_info[i].gadget_id;
8801 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
8803 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
8804 y = mSY + scrollbar_info[i].y;
8805 width = scrollbar_info[i].width;
8806 height = scrollbar_info[i].height;
8808 // correct scrollbar position if placed outside menu (playfield) area
8809 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
8810 x = SX + SC_SCROLL_VERTICAL_XPOS;
8812 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
8813 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
8815 items_max = num_page_entries;
8816 items_visible = num_page_entries;
8819 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
8820 gfx_pressed = scrollbar_info[i].gfx_pressed;
8821 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
8822 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
8823 gd_x1 = graphic_info[gfx_unpressed].src_x;
8824 gd_y1 = graphic_info[gfx_unpressed].src_y;
8825 gd_x2 = graphic_info[gfx_pressed].src_x;
8826 gd_y2 = graphic_info[gfx_pressed].src_y;
8828 gi = CreateGadget(GDI_CUSTOM_ID, id,
8829 GDI_CUSTOM_TYPE_ID, i,
8830 GDI_IMAGE_ID, gfx_unpressed,
8831 GDI_INFO_TEXT, scrollbar_info[i].infotext,
8836 GDI_TYPE, scrollbar_info[i].type,
8837 GDI_SCROLLBAR_ITEMS_MAX, items_max,
8838 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
8839 GDI_SCROLLBAR_ITEM_POSITION, item_position,
8840 GDI_WHEEL_AREA_X, SX,
8841 GDI_WHEEL_AREA_Y, SY,
8842 GDI_WHEEL_AREA_WIDTH, SXSIZE,
8843 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
8844 GDI_STATE, GD_BUTTON_UNPRESSED,
8845 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
8846 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
8847 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
8848 GDI_DIRECT_DRAW, FALSE,
8849 GDI_EVENT_MASK, event_mask,
8850 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8854 Error(ERR_EXIT, "cannot create gadget");
8856 screen_gadget[id] = gi;
8860 static void CreateScreenTextInputGadgets(void)
8864 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
8866 int graphic = textinput_info[i].graphic;
8867 struct GraphicInfo *gd = &graphic_info[graphic];
8868 int gd_x1 = gd->src_x;
8869 int gd_y1 = gd->src_y;
8870 int gd_x2 = gd->src_x + gd->active_xoffset;
8871 int gd_y2 = gd->src_y + gd->active_yoffset;
8872 struct GadgetInfo *gi;
8873 unsigned int event_mask;
8874 int id = textinput_info[i].gadget_id;
8875 int x = textinput_info[i].x;
8876 int y = textinput_info[i].y;
8878 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8880 gi = CreateGadget(GDI_CUSTOM_ID, id,
8881 GDI_CUSTOM_TYPE_ID, i,
8882 GDI_INFO_TEXT, textinput_info[i].infotext,
8885 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8886 GDI_TEXT_VALUE, textinput_info[i].value,
8887 GDI_TEXT_SIZE, textinput_info[i].size,
8888 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
8889 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
8890 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8891 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8892 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8893 GDI_DESIGN_WIDTH, gd->width,
8894 GDI_EVENT_MASK, event_mask,
8895 GDI_CALLBACK_ACTION, HandleScreenGadgets,
8896 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
8900 Error(ERR_EXIT, "cannot create gadget");
8902 screen_gadget[id] = gi;
8906 void CreateScreenGadgets(void)
8908 CreateScreenMenubuttons();
8910 CreateScreenScrollbuttons();
8911 CreateScreenScrollbars();
8913 CreateScreenTextInputGadgets();
8916 void FreeScreenGadgets(void)
8920 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
8921 FreeGadget(screen_gadget[i]);
8924 static void MapScreenMenuGadgets(int screen_mask)
8928 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8929 if (screen_mask & menubutton_info[i].screen_mask)
8930 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8933 static void UnmapScreenMenuGadgets(int screen_mask)
8937 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
8939 if (screen_mask & menubutton_info[i].screen_mask)
8941 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
8943 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
8944 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
8945 screen_gadget[menubutton_info[i].gadget_id]->y,
8946 screen_gadget[menubutton_info[i].gadget_id]->width,
8947 screen_gadget[menubutton_info[i].gadget_id]->height);
8952 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
8955 MapScreenMenuGadgets(screen_mask);
8957 UnmapScreenMenuGadgets(screen_mask);
8960 static void MapScreenGadgets(int num_entries)
8964 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
8967 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
8968 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
8970 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
8971 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
8974 static void MapScreenTreeGadgets(TreeInfo *ti)
8976 MapScreenGadgets(numTreeInfoInGroup(ti));
8979 static void HandleScreenGadgets(struct GadgetInfo *gi)
8981 int id = gi->custom_id;
8982 int button = gi->event.button;
8983 int step = (button == MB_LEFTBUTTON ? 1 :
8984 button == MB_MIDDLEBUTTON ? 5 :
8985 button == MB_RIGHTBUTTON ? 10 : 1);
8989 case SCREEN_CTRL_ID_PREV_LEVEL:
8990 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
8993 case SCREEN_CTRL_ID_NEXT_LEVEL:
8994 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
8997 case SCREEN_CTRL_ID_FIRST_LEVEL:
8998 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
9001 case SCREEN_CTRL_ID_LAST_LEVEL:
9002 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
9005 case SCREEN_CTRL_ID_LEVEL_NUMBER:
9006 CloseDoor(DOOR_CLOSE_2);
9007 SetGameStatus(GAME_MODE_LEVELNR);
9008 DrawChooseLevelNr();
9011 case SCREEN_CTRL_ID_PREV_PLAYER:
9012 HandleSetupScreen_Input_Player(step, -1);
9015 case SCREEN_CTRL_ID_NEXT_PLAYER:
9016 HandleSetupScreen_Input_Player(step, +1);
9019 case SCREEN_CTRL_ID_INSERT_SOLUTION:
9020 InsertSolutionTape();
9023 case SCREEN_CTRL_ID_PLAY_SOLUTION:
9027 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
9028 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
9032 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
9033 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
9034 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
9035 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
9036 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
9039 case SCREEN_CTRL_ID_SCROLL_UP:
9040 if (game_status == GAME_MODE_LEVELS)
9041 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9042 else if (game_status == GAME_MODE_LEVELNR)
9043 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9044 else if (game_status == GAME_MODE_SETUP)
9045 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9046 else if (game_status == GAME_MODE_INFO)
9047 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
9050 case SCREEN_CTRL_ID_SCROLL_DOWN:
9051 if (game_status == GAME_MODE_LEVELS)
9052 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9053 else if (game_status == GAME_MODE_LEVELNR)
9054 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9055 else if (game_status == GAME_MODE_SETUP)
9056 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9057 else if (game_status == GAME_MODE_INFO)
9058 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
9061 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
9062 if (game_status == GAME_MODE_LEVELS)
9063 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9064 else if (game_status == GAME_MODE_LEVELNR)
9065 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
9066 else if (game_status == GAME_MODE_SETUP)
9067 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9068 else if (game_status == GAME_MODE_INFO)
9069 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
9072 case SCREEN_CTRL_ID_NETWORK_SERVER:
9074 if (!strEqual(gi->textinput.value, ""))
9076 setString(&setup.network_server_hostname, gi->textinput.value);
9078 network.server_host = setup.network_server_hostname;
9082 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
9084 network.server_host = NULL;
9087 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
9088 network.server_host = NULL;
9090 execSetupGame_setNetworkServerText();
9102 void DumpScreenIdentifiers(void)
9106 Print("Active screen elements on current screen:\n");
9108 for (i = 0; main_controls[i].nr != -1; i++)
9110 struct MainControlInfo *mci = &main_controls[i];
9112 if (mci->button_graphic != -1)
9114 char *token = getTokenFromImageID(mci->button_graphic);
9116 Print("- '%s'\n", token);
9123 boolean DoScreenAction(int image_id)
9127 if (game_status != GAME_MODE_MAIN)
9130 for (i = 0; main_controls[i].nr != -1; i++)
9132 struct MainControlInfo *mci = &main_controls[i];
9133 struct MenuPosInfo *pos = mci->pos_button;
9135 if (mci->button_graphic == image_id)
9137 int x = mSX + pos->x;
9138 int y = mSY + pos->y;
9140 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
9149 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
9151 // get tree info node of newly added level or artwork set
9152 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
9153 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
9155 if (tree_node_new == NULL) // should not happen
9158 // if request dialog is active, do nothing
9159 if (game.request_active)
9162 if (game_status == GAME_MODE_MAIN &&
9163 tree_type == TREE_TYPE_LEVEL_DIR)
9165 // when adding new level set in main menu, select it as current level set
9167 // change current level set to newly added level set from zip file
9168 leveldir_current = tree_node_new;
9170 // change current level number to first level of newly added level set
9171 level_nr = leveldir_current->first_level;
9173 // redraw screen to reflect changed level set
9176 // save this level set and level number as last selected level set
9177 SaveLevelSetup_LastSeries();
9178 SaveLevelSetup_SeriesInfo();
9180 else if (game_status == GAME_MODE_LEVELS &&
9181 tree_type == TREE_TYPE_LEVEL_DIR)
9183 // when adding new level set in level set menu, set cursor and update screen
9185 leveldir_current = tree_node_new;
9187 DrawChooseTree(&leveldir_current);
9189 else if (game_status == GAME_MODE_SETUP)
9191 // when adding new artwork set in setup menu, set cursor and update screen
9193 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
9194 tree_type == TREE_TYPE_GRAPHICS_DIR)
9196 artwork.gfx_current = tree_node_new;
9198 DrawChooseTree(&artwork.gfx_current);
9200 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
9201 tree_type == TREE_TYPE_SOUNDS_DIR)
9203 artwork.snd_current = tree_node_new;
9205 DrawChooseTree(&artwork.snd_current);
9207 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
9208 tree_type == TREE_TYPE_MUSIC_DIR)
9210 artwork.mus_current = tree_node_new;
9212 DrawChooseTree(&artwork.mus_current);