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"
28 #define DEBUG_JOYSTICKS 0
31 // screens on the info screen
32 #define INFO_MODE_MAIN 0
33 #define INFO_MODE_TITLE 1
34 #define INFO_MODE_ELEMENTS 2
35 #define INFO_MODE_MUSIC 3
36 #define INFO_MODE_CREDITS 4
37 #define INFO_MODE_PROGRAM 5
38 #define INFO_MODE_VERSION 6
39 #define INFO_MODE_LEVELSET 7
41 #define MAX_INFO_MODES 8
43 // screens on the setup screen
44 // (must match GFX_SPECIAL_ARG_SETUP_* values as defined in src/main.h)
45 // (should also match corresponding entries in src/conf_gfx.c)
46 #define SETUP_MODE_MAIN 0
47 #define SETUP_MODE_GAME 1
48 #define SETUP_MODE_ENGINES 2
49 #define SETUP_MODE_EDITOR 3
50 #define SETUP_MODE_GRAPHICS 4
51 #define SETUP_MODE_SOUND 5
52 #define SETUP_MODE_ARTWORK 6
53 #define SETUP_MODE_INPUT 7
54 #define SETUP_MODE_TOUCH 8
55 #define SETUP_MODE_SHORTCUTS 9
56 #define SETUP_MODE_SHORTCUTS_1 10
57 #define SETUP_MODE_SHORTCUTS_2 11
58 #define SETUP_MODE_SHORTCUTS_3 12
59 #define SETUP_MODE_SHORTCUTS_4 13
60 #define SETUP_MODE_SHORTCUTS_5 14
62 // sub-screens on the setup screen (generic)
63 #define SETUP_MODE_CHOOSE_ARTWORK 15
64 #define SETUP_MODE_CHOOSE_OTHER 16
66 // sub-screens on the setup screen (specific)
67 #define SETUP_MODE_CHOOSE_SCORES_TYPE 17
68 #define SETUP_MODE_CHOOSE_GAME_SPEED 18
69 #define SETUP_MODE_CHOOSE_SCROLL_DELAY 19
70 #define SETUP_MODE_CHOOSE_SNAPSHOT_MODE 20
71 #define SETUP_MODE_CHOOSE_WINDOW_SIZE 21
72 #define SETUP_MODE_CHOOSE_SCALING_TYPE 22
73 #define SETUP_MODE_CHOOSE_RENDERING 23
74 #define SETUP_MODE_CHOOSE_VSYNC 24
75 #define SETUP_MODE_CHOOSE_GRAPHICS 25
76 #define SETUP_MODE_CHOOSE_SOUNDS 26
77 #define SETUP_MODE_CHOOSE_MUSIC 27
78 #define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 28
79 #define SETUP_MODE_CHOOSE_VOLUME_LOOPS 29
80 #define SETUP_MODE_CHOOSE_VOLUME_MUSIC 30
81 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL 31
82 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE 32
83 #define SETUP_MODE_CHOOSE_DROP_DISTANCE 33
84 #define SETUP_MODE_CHOOSE_TRANSPARENCY 34
85 #define SETUP_MODE_CHOOSE_GRID_XSIZE_0 35
86 #define SETUP_MODE_CHOOSE_GRID_YSIZE_0 36
87 #define SETUP_MODE_CHOOSE_GRID_XSIZE_1 37
88 #define SETUP_MODE_CHOOSE_GRID_YSIZE_1 38
89 #define SETUP_MODE_CONFIG_VIRT_BUTTONS 39
91 #define MAX_SETUP_MODES 40
93 #define MAX_MENU_MODES MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
96 #define STR_INFO_MAIN "Info Screen"
97 #define STR_INFO_TITLE "Title Screen"
98 #define STR_INFO_ELEMENTS "Game Elements"
99 #define STR_INFO_MUSIC "Music Info"
100 #define STR_INFO_CREDITS "Credits"
101 #define STR_INFO_PROGRAM "Program Info"
102 #define STR_INFO_VERSION "Version Info"
103 #define STR_INFO_LEVELSET "Level Set Info"
104 #define STR_INFO_EXIT "Exit"
106 // setup screen titles
107 #define STR_SETUP_MAIN "Setup"
108 #define STR_SETUP_GAME "Game & Menu"
109 #define STR_SETUP_ENGINES "Game Engines"
110 #define STR_SETUP_EDITOR "Editor"
111 #define STR_SETUP_GRAPHICS "Graphics"
112 #define STR_SETUP_SOUND "Sound & Music"
113 #define STR_SETUP_ARTWORK "Custom Artwork"
114 #define STR_SETUP_INPUT "Input Devices"
115 #define STR_SETUP_TOUCH "Touch Controls"
116 #define STR_SETUP_SHORTCUTS "Key Shortcuts"
117 #define STR_SETUP_EXIT "Exit"
118 #define STR_SETUP_SAVE_AND_EXIT "Save and Exit"
120 #define STR_SETUP_CHOOSE_SCORES_TYPE "Scores Type"
121 #define STR_SETUP_CHOOSE_GAME_SPEED "Game Speed"
122 #define STR_SETUP_CHOOSE_SCROLL_DELAY "Scroll Delay"
123 #define STR_SETUP_CHOOSE_SNAPSHOT_MODE "Snapshot Mode"
124 #define STR_SETUP_CHOOSE_WINDOW_SIZE "Window Scaling"
125 #define STR_SETUP_CHOOSE_SCALING_TYPE "Anti-Aliasing"
126 #define STR_SETUP_CHOOSE_RENDERING "Rendering Mode"
127 #define STR_SETUP_CHOOSE_VSYNC "VSync Mode"
128 #define STR_SETUP_CHOOSE_VOLUME_SIMPLE "Sound Volume"
129 #define STR_SETUP_CHOOSE_VOLUME_LOOPS "Loops Volume"
130 #define STR_SETUP_CHOOSE_VOLUME_MUSIC "Music Volume"
131 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
132 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
133 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
134 #define STR_SETUP_CHOOSE_TRANSPARENCY "Transparency"
135 #define STR_SETUP_CHOOSE_GRID_XSIZE_0 "Horiz. Buttons"
136 #define STR_SETUP_CHOOSE_GRID_YSIZE_0 "Vert. Buttons"
137 #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons"
138 #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons"
140 // other screen text constants
141 #define STR_CHOOSE_TREE_EDIT "Edit"
142 #define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
143 #define MENU_CHOOSE_TREE_COLOR(ti, a) TREE_COLOR(ti, a)
145 #define TEXT_MAIN_MENU "Press any key or button for main menu"
146 #define TEXT_INFO_MENU "Press any key or button for info menu"
147 #define TEXT_NEXT_PAGE "Press any key or button for next page"
148 #define TEXT_NEXT_MENU (info_screens_from_main ? \
149 TEXT_MAIN_MENU : TEXT_INFO_MENU)
151 // for input setup functions
152 #define SETUPINPUT_SCREEN_POS_START 0
153 #define SETUPINPUT_SCREEN_POS_EMPTY1 3
154 #define SETUPINPUT_SCREEN_POS_EMPTY2 12
155 #define SETUPINPUT_SCREEN_POS_END 13
157 #define MENU_SETUP_FONT_TITLE FONT_TEXT_1
158 #define MENU_SETUP_FONT_TEXT FONT_TITLE_2
160 #define MAX_SETUP_TEXT_INPUT_LEN 28
162 // for various menu stuff
163 #define MENU_SCREEN_START_XPOS 1
164 #define MENU_SCREEN_START_YPOS 2
165 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3)
166 #define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2)
167 #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1)
168 #define MENU_TITLE1_YPOS 8
169 #define MENU_TITLE2_YPOS 46
170 #define MENU_INFO_FONT_TITLE FONT_TEXT_1
171 #define MENU_INFO_FONT_HEAD FONT_TEXT_2
172 #define MENU_INFO_FONT_TEXT FONT_TEXT_3
173 #define MENU_INFO_FONT_FOOT FONT_TEXT_4
174 #define MENU_INFO_SPACE_HEAD (menu.headline2_spacing_info[info_mode])
175 #define MENU_SCREEN_INFO_SPACE_LEFT (menu.left_spacing_info[info_mode])
176 #define MENU_SCREEN_INFO_SPACE_MIDDLE (menu.middle_spacing_info[info_mode])
177 #define MENU_SCREEN_INFO_SPACE_RIGHT (menu.right_spacing_info[info_mode])
178 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
179 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
180 #define MENU_SCREEN_INFO_SPACE_LINE (menu.line_spacing_info[info_mode])
181 #define MENU_SCREEN_INFO_SPACE_EXTRA (menu.extra_spacing_info[info_mode])
182 #define MENU_SCREEN_INFO_TILE_SIZE_RAW (menu.tile_size_info[info_mode])
183 #define MENU_SCREEN_INFO_TILE_SIZE (MENU_SCREEN_INFO_TILE_SIZE_RAW > 0 ? \
184 MENU_SCREEN_INFO_TILE_SIZE_RAW : TILEY)
185 #define MENU_SCREEN_INFO_ENTRY_SIZE_RAW (menu.list_entry_size_info[info_mode])
186 #define MENU_SCREEN_INFO_ENTRY_SIZE (MAX(MENU_SCREEN_INFO_ENTRY_SIZE_RAW, \
187 MENU_SCREEN_INFO_TILE_SIZE))
188 #define MENU_SCREEN_INFO_YSTART MENU_SCREEN_INFO_SPACE_TOP
189 #define MENU_SCREEN_INFO_YSTEP (MENU_SCREEN_INFO_ENTRY_SIZE + \
190 MENU_SCREEN_INFO_SPACE_EXTRA)
191 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
192 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
193 MENU_SCREEN_INFO_YSTART - TILEY / 2)
194 #define MAX_INFO_ELEMENTS_IN_ARRAY 128
195 #define MAX_INFO_ELEMENTS_ON_SCREEN (SYSIZE / TILEY)
196 #define MAX_INFO_ELEMENTS MIN(MAX_INFO_ELEMENTS_IN_ARRAY, \
197 MAX_INFO_ELEMENTS_ON_SCREEN)
198 #define STD_INFO_ELEMENTS_ON_SCREEN 10
199 #define DYN_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / MENU_SCREEN_INFO_YSTEP)
200 #define DEFAULT_INFO_ELEMENTS MIN(STD_INFO_ELEMENTS_ON_SCREEN, \
201 DYN_INFO_ELEMENTS_ON_SCREEN)
202 #define NUM_INFO_ELEMENTS_FROM_CONF \
203 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
204 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
205 DEFAULT_INFO_ELEMENTS)
206 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(NUM_INFO_ELEMENTS_FROM_CONF, MAX_INFO_ELEMENTS)
207 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
208 #define MAX_MENU_TEXT_LENGTH_BIG 13
209 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
211 // screen gadget identifiers
212 #define SCREEN_CTRL_ID_PREV_LEVEL 0
213 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
214 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
215 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
216 #define SCREEN_CTRL_ID_PREV_SCORE 4
217 #define SCREEN_CTRL_ID_NEXT_SCORE 5
218 #define SCREEN_CTRL_ID_PLAY_TAPE 6
219 #define SCREEN_CTRL_ID_FIRST_LEVEL 7
220 #define SCREEN_CTRL_ID_LAST_LEVEL 8
221 #define SCREEN_CTRL_ID_LEVEL_NUMBER 9
222 #define SCREEN_CTRL_ID_PREV_PLAYER 10
223 #define SCREEN_CTRL_ID_NEXT_PLAYER 11
224 #define SCREEN_CTRL_ID_INSERT_SOLUTION 12
225 #define SCREEN_CTRL_ID_PLAY_SOLUTION 13
226 #define SCREEN_CTRL_ID_LEVELSET_INFO 14
227 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 15
228 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 16
229 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 17
230 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 18
231 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 19
233 #define NUM_SCREEN_MENUBUTTONS 20
235 #define SCREEN_CTRL_ID_SCROLL_UP 20
236 #define SCREEN_CTRL_ID_SCROLL_DOWN 21
237 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 22
238 #define SCREEN_CTRL_ID_NETWORK_SERVER 23
240 #define NUM_SCREEN_GADGETS 24
242 #define NUM_SCREEN_SCROLLBUTTONS 2
243 #define NUM_SCREEN_SCROLLBARS 1
244 #define NUM_SCREEN_TEXTINPUT 1
246 #define SCREEN_MASK_MAIN (1 << 0)
247 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
248 #define SCREEN_MASK_MAIN_HAS_SET_INFO (1 << 2)
249 #define SCREEN_MASK_INPUT (1 << 3)
250 #define SCREEN_MASK_TOUCH (1 << 4)
251 #define SCREEN_MASK_TOUCH2 (1 << 5)
252 #define SCREEN_MASK_SCORES (1 << 6)
253 #define SCREEN_MASK_SCORES_INFO (1 << 7)
255 // graphic position and size values for buttons and scrollbars
256 #define SC_MENUBUTTON_XSIZE TILEX
257 #define SC_MENUBUTTON_YSIZE TILEY
259 #define SC_SCROLLBUTTON_XSIZE TILEX
260 #define SC_SCROLLBUTTON_YSIZE TILEY
262 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
264 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
265 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
266 SC_SCROLLBUTTON_YSIZE)
268 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
269 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
271 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
272 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
273 SC_SCROLLBUTTON_YSIZE)
275 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
276 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
277 SC_SCROLL_VERTICAL_YSIZE)
279 #define SC_BORDER_SIZE 14
282 // forward declarations of internal functions
283 static void HandleScreenGadgets(struct GadgetInfo *);
284 static void HandleSetupScreen_Generic(int, int, int, int, int);
285 static void HandleSetupScreen_Input(int, int, int, int, int);
286 static void CustomizeKeyboard(int);
287 static void ConfigureJoystick(int);
288 static void ConfigureVirtualButtons(void);
289 static void execSetupGame(void);
290 static void execSetupEngines(void);
291 static void execSetupGraphics(void);
292 static void execSetupSound(void);
293 static void execSetupTouch(void);
294 static void execSetupArtwork(void);
295 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
297 static void DrawChoosePlayerName(void);
298 static void DrawChooseLevelSet(void);
299 static void DrawChooseLevelNr(void);
300 static void DrawScoreInfo(int);
301 static void DrawScoreInfo_Content(int);
302 static void DrawInfoScreen(void);
303 static void DrawSetupScreen(void);
304 static void DrawTypeName(void);
306 static void DrawInfoScreen_NotAvailable(char *, char *);
307 static void DrawInfoScreen_HelpAnim(int, int, boolean);
308 static void DrawInfoScreen_HelpText(int, int, int, int);
309 static void HandleInfoScreen_Main(int, int, int, int, int);
310 static void HandleInfoScreen_TitleScreen(int, int, int);
311 static void HandleInfoScreen_Elements(int, int, int);
312 static void HandleInfoScreen_Music(int, int, int);
313 static void HandleInfoScreen_Version(int);
314 static void HandleInfoScreen_Generic(int, int, int);
316 static void ModifyGameSpeedIfNeeded(void);
317 static void DisableVsyncIfNeeded(void);
319 static void RedrawScreenMenuGadgets(int);
320 static void MapScreenMenuGadgets(int);
321 static void UnmapScreenMenuGadgets(int);
322 static void MapScreenGadgets(int);
323 static void UnmapScreenGadgets(void);
324 static void MapScreenTreeGadgets(TreeInfo *);
325 static void UnmapScreenTreeGadgets(void);
327 static void UpdateScreenMenuGadgets(int, boolean);
328 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
329 static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
331 static boolean OfferUploadTapes(void);
332 static void execOfferUploadTapes(void);
334 static void DrawHallOfFame_setScoreEntries(void);
335 static void HandleHallOfFame_SelectLevel(int, int);
336 static char *getHallOfFameRankText(int, int);
337 static char *getHallOfFameScoreText(int, int);
338 static char *getInfoScreenTitle_Generic(void);
339 static int getInfoScreenBackgroundImage_Generic(void);
340 static int getInfoScreenBackgroundSound_Generic(void);
341 static int getInfoScreenBackgroundMusic_Generic(void);
343 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
345 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
347 static int info_mode = INFO_MODE_MAIN;
348 static int setup_mode = SETUP_MODE_MAIN;
350 static boolean info_screens_from_main = FALSE;
352 static TreeInfo *window_sizes = NULL;
353 static TreeInfo *window_size_current = NULL;
355 static TreeInfo *scaling_types = NULL;
356 static TreeInfo *scaling_type_current = NULL;
358 static TreeInfo *rendering_modes = NULL;
359 static TreeInfo *rendering_mode_current = NULL;
361 static TreeInfo *vsync_modes = NULL;
362 static TreeInfo *vsync_mode_current = NULL;
364 static TreeInfo *scroll_delays = NULL;
365 static TreeInfo *scroll_delay_current = NULL;
367 static TreeInfo *snapshot_modes = NULL;
368 static TreeInfo *snapshot_mode_current = NULL;
370 static TreeInfo *scores_types = NULL;
371 static TreeInfo *scores_type_current = NULL;
373 static TreeInfo *game_speeds_normal = NULL;
374 static TreeInfo *game_speeds_extended = NULL;
375 static TreeInfo *game_speeds = NULL;
376 static TreeInfo *game_speed_current = NULL;
378 static TreeInfo *volumes_simple = NULL;
379 static TreeInfo *volume_simple_current = NULL;
381 static TreeInfo *volumes_loops = NULL;
382 static TreeInfo *volume_loops_current = NULL;
384 static TreeInfo *volumes_music = NULL;
385 static TreeInfo *volume_music_current = NULL;
387 static TreeInfo *touch_controls = NULL;
388 static TreeInfo *touch_control_current = NULL;
390 static TreeInfo *move_distances = NULL;
391 static TreeInfo *move_distance_current = NULL;
393 static TreeInfo *drop_distances = NULL;
394 static TreeInfo *drop_distance_current = NULL;
396 static TreeInfo *transparencies = NULL;
397 static TreeInfo *transparency_current = NULL;
399 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
400 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
402 static TreeInfo *player_name = NULL;
403 static TreeInfo *player_name_current = NULL;
405 static TreeInfo *level_number = NULL;
406 static TreeInfo *level_number_current = NULL;
408 static TreeInfo *score_entries = NULL;
409 static TreeInfo *score_entry_current = NULL;
411 static struct ValueTextInfo window_sizes_list[] =
416 { 100, "100 % (Default)" },
429 static struct StringValueTextInfo scaling_types_list[] =
431 { SCALING_QUALITY_NEAREST, "Off" },
432 { SCALING_QUALITY_LINEAR, "Linear" },
433 { SCALING_QUALITY_BEST, "Anisotropic" },
438 static struct StringValueTextInfo rendering_modes_list[] =
440 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
441 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
443 // this mode may work under certain conditions, but does not work on Windows
444 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
446 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
451 static struct StringValueTextInfo vsync_modes_list[] =
453 { STR_VSYNC_MODE_OFF, "Off" },
454 { STR_VSYNC_MODE_NORMAL, "Normal" },
455 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
460 static struct StringValueTextInfo scores_types_list[] =
462 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
463 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
464 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
469 static struct ValueTextInfo game_speeds_list_normal[] =
480 static struct ValueTextInfo game_speeds_list_extended[] =
482 { 1000, "1 fps (Extremely Slow)" },
487 { 29, "35 fps (Original Supaplex)" },
489 { 20, "50 fps (=== Normal Speed ===)" },
490 { 16, "60 fps (60 Hz VSync Speed)" },
491 { 14, "70 fps (Maximum Supaplex)" },
495 { 1, "1000 fps (Extremely Fast)" },
500 static struct ValueTextInfo *game_speeds_list;
502 static struct ValueTextInfo scroll_delays_list[] =
504 { 0, "0 Tiles (No Scroll Delay)" },
507 { 3, "3 Tiles (Default)" },
512 { 8, "8 Tiles (Maximum Scroll Delay)"},
517 static struct StringValueTextInfo snapshot_modes_list[] =
519 { STR_SNAPSHOT_MODE_OFF, "Off" },
520 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
521 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
522 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
527 static struct ValueTextInfo volumes_list[] =
547 static struct StringValueTextInfo touch_controls_list[] =
549 { TOUCH_CONTROL_OFF, "Off" },
550 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
551 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
552 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
557 static struct ValueTextInfo distances_list[] =
572 static struct ValueTextInfo transparencies_list[] =
574 { 0, "0 % (Opaque)" },
584 { 100, "100 % (Invisible)" },
589 static struct ValueTextInfo grid_sizes_list[] =
625 static int align_xoffset = 0;
626 static int align_yoffset = 0;
628 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
629 (s) <= GAME_MODE_SETUP ? (s) : \
630 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
632 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
633 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
635 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
636 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
637 (i) <= INFO_MODE_LEVELSET ? (i) : \
640 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
641 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
642 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
643 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
644 SETUP_MODE_CHOOSE_ARTWORK : \
645 SETUP_MODE_CHOOSE_OTHER)
647 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
648 menu.draw_xoffset[GAME_MODE_INFO] : \
649 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
650 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
651 menu.draw_yoffset[GAME_MODE_INFO] : \
652 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
653 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
654 menu.extra_spacing[GAME_MODE_INFO] : \
655 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
657 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
658 menu.draw_xoffset[GAME_MODE_SETUP] : \
659 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
660 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
661 menu.draw_yoffset[GAME_MODE_SETUP] : \
662 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
663 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
664 menu.extra_spacing[GAME_MODE_SETUP] : \
665 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
667 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
669 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
671 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? DRAW_XOFFSET_INFO(info_mode) : \
672 (s) == GAME_MODE_SETUP ? DRAW_XOFFSET_SETUP(setup_mode) : \
673 menu.draw_xoffset[DRAW_MODE(s)])
675 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? DRAW_YOFFSET_INFO(info_mode) : \
676 (s) == GAME_MODE_SETUP ? DRAW_YOFFSET_SETUP(setup_mode) : \
677 menu.draw_yoffset[DRAW_MODE(s)])
679 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? EXTRA_SPACING_INFO(info_mode) : \
680 (s) == GAME_MODE_SETUP ? EXTRA_SPACING_SETUP(setup_mode) : \
681 (s) == GAME_MODE_SCORES ? EXTRA_SPACING_SCORES(info_mode) : \
682 menu.extra_spacing[DRAW_MODE(s)])
684 #define mSX (SX + DRAW_XOFFSET(game_status))
685 #define mSY (SY + DRAW_YOFFSET(game_status))
687 #define amSX (mSX + align_xoffset)
688 #define amSY (mSY + align_yoffset)
690 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
691 menu.list_size[game_status] : \
692 MAX_MENU_ENTRIES_ON_SCREEN)
694 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, NUM_MENU_ENTRIES_ON_SCREEN)
697 // title display and control definitions
699 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + 2 * MAX_NUM_TITLE_MESSAGES)
701 #define NO_DIRECT_LEVEL_SELECT (-1)
704 static int num_title_screens = 0;
706 struct TitleControlInfo
715 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
718 // main menu display and control definitions
720 #define MAIN_CONTROL_NAME 0
721 #define MAIN_CONTROL_LEVELS 1
722 #define MAIN_CONTROL_SCORES 2
723 #define MAIN_CONTROL_EDITOR 3
724 #define MAIN_CONTROL_INFO 4
725 #define MAIN_CONTROL_GAME 5
726 #define MAIN_CONTROL_SETUP 6
727 #define MAIN_CONTROL_QUIT 7
728 #define MAIN_CONTROL_PREV_LEVEL 8
729 #define MAIN_CONTROL_NEXT_LEVEL 9
730 #define MAIN_CONTROL_FIRST_LEVEL 10
731 #define MAIN_CONTROL_LAST_LEVEL 11
732 #define MAIN_CONTROL_LEVEL_NUMBER 12
733 #define MAIN_CONTROL_LEVEL_INFO_1 13
734 #define MAIN_CONTROL_LEVEL_INFO_2 14
735 #define MAIN_CONTROL_LEVEL_NAME 15
736 #define MAIN_CONTROL_LEVEL_AUTHOR 16
737 #define MAIN_CONTROL_LEVEL_YEAR 17
738 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
739 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
740 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
741 #define MAIN_CONTROL_TITLE_1 21
742 #define MAIN_CONTROL_TITLE_2 22
743 #define MAIN_CONTROL_TITLE_3 23
745 static char str_main_text_name[10];
746 static char str_main_text_first_level[10];
747 static char str_main_text_last_level[10];
748 static char str_main_text_level_number[10];
750 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
752 static char *main_text_name = str_main_text_name;
753 static char *main_text_first_level = str_main_text_first_level;
754 static char *main_text_last_level = str_main_text_last_level;
755 static char *main_text_level_number = str_main_text_level_number;
756 static char *main_text_levels = "Levelset";
757 static char *main_text_scores = "Hall Of Fame";
758 static char *main_text_editor = "Level Creator";
759 static char *main_text_info = "Info Screen";
760 static char *main_text_game = "Start Game";
761 static char *main_text_setup = "Setup";
762 static char *main_text_quit = "Quit";
763 static char *main_text_level_name = level.name;
764 static char *main_text_level_author = level.author;
765 static char *main_text_level_year = NULL;
766 static char *main_text_level_imported_from = NULL;
767 static char *main_text_level_imported_by = NULL;
768 static char *main_text_level_tested_by = NULL;
769 static char *main_text_title_1 = NULL;
770 static char *main_text_title_2 = NULL;
771 static char *main_text_title_3 = NULL;
773 extern char debug_xsn_mode[];
775 struct MainControlInfo
779 struct MenuPosInfo *pos_button;
782 struct TextPosInfo *pos_text;
785 struct TextPosInfo *pos_input;
789 static struct MainControlInfo main_controls[] =
793 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
794 &menu.main.text.name, &main_text_name,
795 &menu.main.input.name, &setup.player_name,
799 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
800 &menu.main.text.levels, &main_text_levels,
805 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
806 &menu.main.text.scores, &main_text_scores,
811 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
812 &menu.main.text.editor, &main_text_editor,
817 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
818 &menu.main.text.info, &main_text_info,
823 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
824 &menu.main.text.game, &main_text_game,
829 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
830 &menu.main.text.setup, &main_text_setup,
835 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
836 &menu.main.text.quit, &main_text_quit,
840 MAIN_CONTROL_PREV_LEVEL,
846 MAIN_CONTROL_NEXT_LEVEL,
852 MAIN_CONTROL_FIRST_LEVEL,
854 &menu.main.text.first_level, &main_text_first_level,
858 MAIN_CONTROL_LAST_LEVEL,
860 &menu.main.text.last_level, &main_text_last_level,
864 MAIN_CONTROL_LEVEL_NUMBER,
866 &menu.main.text.level_number, &main_text_level_number,
870 MAIN_CONTROL_LEVEL_INFO_1,
872 &menu.main.text.level_info_1, NULL,
876 MAIN_CONTROL_LEVEL_INFO_2,
878 &menu.main.text.level_info_2, NULL,
882 MAIN_CONTROL_LEVEL_NAME,
884 &menu.main.text.level_name, &main_text_level_name,
888 MAIN_CONTROL_LEVEL_AUTHOR,
890 &menu.main.text.level_author, &main_text_level_author,
894 MAIN_CONTROL_LEVEL_YEAR,
896 &menu.main.text.level_year, &main_text_level_year,
900 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
902 &menu.main.text.level_imported_from, &main_text_level_imported_from,
906 MAIN_CONTROL_LEVEL_IMPORTED_BY,
908 &menu.main.text.level_imported_by, &main_text_level_imported_by,
912 MAIN_CONTROL_LEVEL_TESTED_BY,
914 &menu.main.text.level_tested_by, &main_text_level_tested_by,
918 MAIN_CONTROL_TITLE_1,
920 &menu.main.text.title_1, &main_text_title_1,
924 MAIN_CONTROL_TITLE_2,
926 &menu.main.text.title_2, &main_text_title_2,
930 MAIN_CONTROL_TITLE_3,
932 &menu.main.text.title_3, &main_text_title_3,
945 static boolean hasLevelSetInfo(void)
947 return (getLevelSetInfoFilename(0) != NULL);
950 static int getTitleScreenGraphic(int nr, boolean initial)
952 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
955 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
957 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
961 static int getTitleScreenGameMode(boolean initial)
963 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
967 static int getTitleMessageGameMode(boolean initial)
969 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
972 static int getTitleAnimMode(struct TitleControlInfo *tci)
974 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
976 return base + tci->local_nr;
980 static int getTitleScreenBackground(boolean initial)
982 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
987 static int getTitleMessageBackground(int nr, boolean initial)
989 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
993 static int getTitleBackground(int nr, boolean initial, boolean is_image)
995 int base = (is_image ?
996 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
997 IMG_BACKGROUND_TITLESCREEN_1) :
998 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
999 IMG_BACKGROUND_TITLEMESSAGE_1));
1000 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
1001 IMG_BACKGROUND_TITLE);
1002 int graphic_local = base + nr;
1004 if (graphic_info[graphic_local].bitmap != NULL)
1005 return graphic_local;
1007 if (graphic_info[graphic_global].bitmap != NULL)
1008 return graphic_global;
1010 return IMG_UNDEFINED;
1013 static int getTitleSound(struct TitleControlInfo *tci)
1015 boolean is_image = tci->is_image;
1016 int initial = tci->initial;
1017 int nr = tci->local_nr;
1018 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1019 int base = (is_image ?
1020 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1021 SND_BACKGROUND_TITLESCREEN_1) :
1022 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1023 SND_BACKGROUND_TITLEMESSAGE_1));
1024 int sound_global = menu.sound[mode];
1025 int sound_local = base + nr;
1028 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1029 nr, initial, is_image,
1030 sound_global, getSoundListEntry(sound_global)->filename,
1031 sound_local, getSoundListEntry(sound_local)->filename);
1034 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1037 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1038 return sound_global;
1040 return SND_UNDEFINED;
1043 static int getTitleMusic(struct TitleControlInfo *tci)
1045 boolean is_image = tci->is_image;
1046 int initial = tci->initial;
1047 int nr = tci->local_nr;
1048 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1049 int base = (is_image ?
1050 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1051 MUS_BACKGROUND_TITLESCREEN_1) :
1052 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1053 MUS_BACKGROUND_TITLEMESSAGE_1));
1054 int music_global = menu.music[mode];
1055 int music_local = base + nr;
1058 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1059 nr, initial, is_image,
1060 music_global, getMusicListEntry(music_global)->filename,
1061 music_local, getMusicListEntry(music_local)->filename);
1064 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1067 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1068 return music_global;
1070 return MUS_UNDEFINED;
1073 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1075 boolean is_image = tci->is_image;
1076 boolean initial = tci->initial;
1077 boolean first = tci->first;
1078 int nr = tci->local_nr;
1079 struct TitleMessageInfo tmi;
1080 struct TitleFadingInfo ti;
1082 tmi = (is_image ? (initial ? (first ?
1083 titlescreen_initial_first[nr] :
1084 titlescreen_initial[nr])
1086 titlescreen_first[nr] :
1088 : (initial ? (first ?
1089 titlemessage_initial_first[nr] :
1090 titlemessage_initial[nr])
1092 titlemessage_first[nr] :
1093 titlemessage[nr])));
1095 ti.fade_mode = tmi.fade_mode;
1096 ti.fade_delay = tmi.fade_delay;
1097 ti.post_delay = tmi.post_delay;
1098 ti.auto_delay = tmi.auto_delay;
1099 ti.auto_delay_unit = tmi.auto_delay_unit;
1104 static int compareTitleControlInfo(const void *object1, const void *object2)
1106 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1107 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1110 if (tci1->initial != tci2->initial)
1111 compare_result = (tci1->initial ? -1 : +1);
1112 else if (tci1->sort_priority != tci2->sort_priority)
1113 compare_result = tci1->sort_priority - tci2->sort_priority;
1114 else if (tci1->is_image != tci2->is_image)
1115 compare_result = (tci1->is_image ? -1 : +1);
1117 compare_result = tci1->local_nr - tci2->local_nr;
1119 return compare_result;
1122 static boolean CheckTitleScreen_BD(int nr, boolean initial)
1124 // only show BD style title screen for native BD level sets
1125 if (level.game_engine_type != GAME_ENGINE_TYPE_BD)
1128 // only show BD style title screen for first title screen of a level set
1129 if (initial || nr != 0)
1132 int graphic = getTitleScreenGraphic(nr, initial);
1133 Bitmap *bitmap = graphic_info[graphic].bitmap;
1135 // only show BD style title screen if no other title screen defined
1139 // check if BD style title screen defined
1140 return (GetTitleScreenBitmaps_BD() != NULL);
1143 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1145 int nr, int sort_priority)
1147 title_controls[num_title_screens].is_image = is_image;
1148 title_controls[num_title_screens].initial = initial;
1149 title_controls[num_title_screens].local_nr = nr;
1150 title_controls[num_title_screens].sort_priority = sort_priority;
1152 title_controls[num_title_screens].first = FALSE; // will be set later
1154 num_title_screens++;
1157 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1161 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1163 int graphic = getTitleScreenGraphic(i, initial);
1164 Bitmap *bitmap = graphic_info[graphic].bitmap;
1165 int sort_priority = graphic_info[graphic].sort_priority;
1166 boolean has_title_screen = (bitmap != NULL);
1168 // check for optional title screen of native BD style level set
1169 if (CheckTitleScreen_BD(i, initial))
1170 has_title_screen = TRUE;
1172 if (has_title_screen)
1173 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1176 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1178 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1179 char *filename = getLevelSetTitleMessageFilename(i, initial);
1180 int sort_priority = tmi->sort_priority;
1182 if (filename != NULL)
1183 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1187 static void InitializeTitleControls(boolean show_title_initial)
1189 num_title_screens = 0;
1191 // 1st step: initialize title screens for game start (only when starting)
1192 if (show_title_initial)
1193 InitializeTitleControls_CheckTitleInfo(TRUE);
1195 // 2nd step: initialize title screens for current level set
1196 InitializeTitleControls_CheckTitleInfo(FALSE);
1198 // sort title screens according to sort_priority and title number
1199 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1200 compareTitleControlInfo);
1202 // mark first title screen
1203 title_controls[0].first = TRUE;
1206 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1208 return (pos != NULL && pos->x != -1 && pos->y != -1);
1211 static boolean visibleTextPos(struct TextPosInfo *pos)
1213 return (pos != NULL && pos->x != -1 && pos->y != -1);
1216 static void InitializeMainControls(void)
1218 boolean local_team_mode = (!network.enabled && setup.team_mode);
1221 // set main control text values to dynamically determined values
1222 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1224 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1225 menu.main.text.first_level.size));
1226 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1227 menu.main.text.last_level.size));
1228 strcpy(main_text_level_number, int2str(level_nr,
1229 menu.main.text.level_number.size));
1231 main_text_level_year = leveldir_current->year;
1232 main_text_level_imported_from = leveldir_current->imported_from;
1233 main_text_level_imported_by = leveldir_current->imported_by;
1234 main_text_level_tested_by = leveldir_current->tested_by;
1236 main_text_title_1 = getConfigProgramTitleString();
1237 main_text_title_2 = getConfigProgramCopyrightString();
1238 main_text_title_3 = getConfigProgramCompanyString();
1240 // set main control screen positions to dynamically determined values
1241 for (i = 0; main_controls[i].nr != -1; i++)
1243 struct MainControlInfo *mci = &main_controls[i];
1245 struct MenuPosInfo *pos_button = mci->pos_button;
1246 struct TextPosInfo *pos_text = mci->pos_text;
1247 struct TextPosInfo *pos_input = mci->pos_input;
1248 char *text = (mci->text ? *mci->text : NULL);
1249 char *input = (mci->input ? *mci->input : NULL);
1250 int button_graphic = mci->button_graphic;
1251 int font_text = (pos_text ? pos_text->font : -1);
1252 int font_input = (pos_input ? pos_input->font : -1);
1254 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1255 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1256 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1257 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1258 int text_chars = (text != NULL ? strlen(text) : 0);
1259 int input_chars = (input != NULL ? strlen(input) : 0);
1262 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1264 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1265 int text_width = font_text_width * text_chars;
1266 int text_height = font_text_height;
1267 int input_width = font_input_width * input_chars;
1268 int input_height = font_input_height;
1270 if (nr == MAIN_CONTROL_NAME)
1272 menu.main.input.name.width = input_width;
1273 menu.main.input.name.height = input_height;
1276 if (pos_button != NULL) // (x/y may be -1/-1 here)
1278 pos_button->width = button_width;
1279 pos_button->height = button_height;
1282 if (pos_text != NULL) // (x/y may be -1/-1 here)
1284 // calculate text size -- needed for text alignment
1285 boolean calculate_text_size = (text != NULL);
1287 if (pos_text->width == -1 || calculate_text_size)
1288 pos_text->width = text_width;
1289 if (pos_text->height == -1 || calculate_text_size)
1290 pos_text->height = text_height;
1292 if (visibleMenuPos(pos_button))
1294 if (pos_text->x == -1)
1295 pos_text->x = pos_button->x + pos_button->width;
1296 if (pos_text->y == -1)
1298 pos_button->y + (pos_button->height - pos_text->height) / 2;
1302 if (pos_input != NULL) // (x/y may be -1/-1 here)
1304 if (visibleTextPos(pos_text))
1306 if (pos_input->x == -1)
1307 pos_input->x = pos_text->x + pos_text->width;
1308 if (pos_input->y == -1)
1309 pos_input->y = pos_text->y;
1312 if (pos_input->width == -1)
1313 pos_input->width = input_width;
1314 if (pos_input->height == -1)
1315 pos_input->height = input_height;
1320 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1321 int graphic, boolean pressed)
1323 struct GraphicInfo *g = &graphic_info[graphic];
1326 int xoffset = (pressed ? g->pressed_xoffset : 0);
1327 int yoffset = (pressed ? g->pressed_yoffset : 0);
1329 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1331 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1332 g->width, g->height, dst_x, dst_y);
1335 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1336 boolean active_input,
1337 boolean pressed_button)
1341 for (i = 0; main_controls[i].nr != -1; i++)
1343 struct MainControlInfo *mci = &main_controls[i];
1345 if (mci->nr == nr || nr == -1)
1347 struct MenuPosInfo *pos_button = mci->pos_button;
1348 struct TextPosInfo *pos_text = mci->pos_text;
1349 struct TextPosInfo *pos_input = mci->pos_input;
1350 char *text = (mci->text ? *mci->text : NULL);
1351 char *input = (mci->input ? *mci->input : NULL);
1352 int button_graphic = mci->button_graphic;
1353 int font_text = (pos_text ? pos_text->font : -1);
1354 int font_input = (pos_input ? pos_input->font : -1);
1358 button_graphic = BUTTON_ACTIVE(button_graphic);
1359 font_text = FONT_ACTIVE(font_text);
1364 font_input = FONT_ACTIVE(font_input);
1367 if (visibleMenuPos(pos_button))
1369 struct MenuPosInfo *pos = pos_button;
1370 int x = mSX + pos->x;
1371 int y = mSY + pos->y;
1373 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1374 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1377 if (visibleTextPos(pos_text) && text != NULL)
1379 struct TextPosInfo *pos = pos_text;
1380 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1381 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1384 // (check why/if this is needed)
1385 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1387 DrawText(x, y, text, font_text);
1390 if (visibleTextPos(pos_input) && input != NULL)
1392 struct TextPosInfo *pos = pos_input;
1393 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1394 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1397 // (check why/if this is needed)
1398 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1400 DrawText(x, y, input, font_input);
1406 static void DrawCursorAndText_Main(int nr, boolean active_text,
1407 boolean pressed_button)
1409 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1413 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1414 boolean pressed_button)
1416 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1420 static struct MainControlInfo *getMainControlInfo(int nr)
1424 for (i = 0; main_controls[i].nr != -1; i++)
1425 if (main_controls[i].nr == nr)
1426 return &main_controls[i];
1431 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1436 int rect_x = ALIGNED_TEXT_XPOS(rect);
1437 int rect_y = ALIGNED_TEXT_YPOS(rect);
1439 return (x >= rect_x && x < rect_x + rect->width &&
1440 y >= rect_y && y < rect_y + rect->height);
1443 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1448 int rect_x = ALIGNED_TEXT_XPOS(rect);
1449 int rect_y = ALIGNED_TEXT_YPOS(rect);
1452 Debug("screens:insideTextPosRect",
1453 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1454 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1455 (x >= rect_x && x < rect_x + rect->width &&
1456 y >= rect_y && y < rect_y + rect->height));
1459 return (x >= rect_x && x < rect_x + rect->width &&
1460 y >= rect_y && y < rect_y + rect->height);
1463 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1465 int rect_width = preview->xsize * preview->tile_size;
1466 int rect_height = preview->ysize * preview->tile_size;
1467 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1468 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1470 return (x >= rect_x && x < rect_x + rect_width &&
1471 y >= rect_y && y < rect_y + rect_height);
1474 static void AdjustScrollbar(int id, int items_max, int items_visible,
1477 struct GadgetInfo *gi = screen_gadget[id];
1479 if (item_position > items_max - items_visible)
1480 item_position = items_max - items_visible;
1482 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1483 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1484 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1487 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1489 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1493 static void clearMenuListArea(void)
1495 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1497 // correct scrollbar position if placed outside menu (playfield) area
1498 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1499 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1501 // clear menu list area, but not title or scrollbar
1502 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1503 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1505 // special compatibility handling for "Snake Bite" graphics set
1506 if (strPrefix(leveldir_current->identifier, "snake_bite"))
1507 ClearRectangle(drawto, mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1508 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1511 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1513 static int cursor_array[MAX_LEV_FIELDY];
1514 int x = amSX + TILEX * xpos;
1515 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1520 cursor_array[ypos] = graphic;
1522 graphic = cursor_array[ypos];
1526 graphic = BUTTON_ACTIVE(graphic);
1528 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1529 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1532 static void initCursor(int ypos, int graphic)
1534 drawCursorExt(0, ypos, FALSE, graphic);
1537 static void drawCursor(int ypos, boolean active)
1539 drawCursorExt(0, ypos, active, -1);
1542 static void drawCursorXY(int xpos, int ypos, int graphic)
1544 drawCursorExt(xpos, ypos, FALSE, graphic);
1547 static void drawChooseTreeCursor(int ypos, boolean active)
1549 drawCursorExt(0, ypos, active, -1);
1552 static int getChooseTreeEditFont(boolean active)
1554 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1557 static int getChooseTreeEditXPos(int pos)
1559 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1560 int xoffset = (has_scrollbar ? -1 : 0);
1561 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1562 int sx = amSX + xpos * TILEX;
1563 int font_nr = getChooseTreeEditFont(FALSE);
1564 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1566 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1569 static int getChooseTreeEditYPos(int ypos_raw)
1571 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1572 int sy = amSY + ypos * TILEY;
1577 static int getChooseTreeEditXPosReal(int pos)
1579 int xpos = getChooseTreeEditXPos(pos);
1580 int font_nr = getChooseTreeEditFont(FALSE);
1581 int font_xoffset = getFontDrawOffsetX(font_nr);
1583 return xpos + font_xoffset;
1586 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1588 int sx = getChooseTreeEditXPos(POS_LEFT);
1589 int sy = getChooseTreeEditYPos(ypos_raw);
1590 int font_nr = getChooseTreeEditFont(active);
1592 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1595 static void DrawInfoScreen_Headline(int screen_nr, int num_screens,
1596 int use_global_screens)
1598 char *info_text_title_1 = getInfoScreenTitle_Generic();
1599 char info_text_title_2[MAX_LINE_LEN + 1];
1601 if (num_screens > 1)
1603 sprintf(info_text_title_2, "Page %d of %d", screen_nr + 1, num_screens);
1607 char *text_format = (use_global_screens ? "for %s" : "for \"%s\"");
1608 int text_format_len = strlen(text_format) - strlen("%s");
1609 int max_text_len = SXSIZE / getFontWidth(FONT_TITLE_2);
1610 int max_name_len = max_text_len - text_format_len;
1611 char name_cut[max_name_len];
1612 char *name_full = (use_global_screens ? getProgramTitleString() :
1613 leveldir_current->name);
1615 snprintf(name_cut, max_name_len, "%s", name_full);
1616 snprintf(info_text_title_2, max_text_len, text_format, name_cut);
1619 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, info_text_title_1);
1620 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, info_text_title_2);
1623 static void DrawTitleScreenImage(int nr, boolean initial)
1625 static int frame_counter = 0;
1626 int graphic = getTitleScreenGraphic(nr, initial);
1627 Bitmap *bitmap = graphic_info[graphic].bitmap;
1628 Bitmap *bitmap_background = NULL;
1629 int draw_masked = graphic_info[graphic].draw_masked;
1630 int width = graphic_info[graphic].width;
1631 int height = graphic_info[graphic].height;
1632 int src_x = graphic_info[graphic].src_x;
1633 int src_y = graphic_info[graphic].src_y;
1636 // check for optional title screen of native BD style level set
1637 if (CheckTitleScreen_BD(nr, initial))
1639 Bitmap **title_screen_bitmaps = GetTitleScreenBitmaps_BD();
1641 bitmap = title_screen_bitmaps[0];
1642 bitmap_background = title_screen_bitmaps[1];
1646 width = bitmap->width;
1647 height = bitmap->height;
1656 if (width > WIN_XSIZE)
1658 // image width too large for window => center image horizontally
1659 src_x = (width - WIN_XSIZE) / 2;
1663 if (height > WIN_YSIZE)
1665 // image height too large for window => center image vertically
1666 src_y = (height - WIN_YSIZE) / 2;
1670 // always display title screens centered
1671 dst_x = (WIN_XSIZE - width) / 2;
1672 dst_y = (WIN_YSIZE - height) / 2;
1674 SetDrawBackgroundMask(REDRAW_ALL);
1675 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1677 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1679 boolean draw_masked_final = (DrawingOnBackground(dst_x, dst_y) && draw_masked);
1681 if (bitmap_background != NULL)
1683 int size = bitmap_background->height - bitmap->height;
1684 int offset = frame_counter++ % size;
1686 BlitBitmap(bitmap_background, drawto, src_x, src_y + offset, width, height, dst_x, dst_y);
1688 draw_masked_final = TRUE;
1691 if (draw_masked_final)
1692 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1694 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1696 redraw_mask = REDRAW_ALL;
1699 static void DrawTitleScreenMessage(int nr, boolean initial)
1701 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1702 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1704 if (filename == NULL)
1707 // force TITLE font on title message screen
1708 SetFontStatus(getTitleMessageGameMode(initial));
1710 // if chars *and* width set to "-1", automatically determine width
1711 if (tmi->chars == -1 && tmi->width == -1)
1712 tmi->width = viewport.window[game_status].width;
1714 // if lines *and* height set to "-1", automatically determine height
1715 if (tmi->lines == -1 && tmi->height == -1)
1716 tmi->height = viewport.window[game_status].height;
1718 // if chars set to "-1", automatically determine by text and font width
1719 if (tmi->chars == -1)
1720 tmi->chars = tmi->width / getFontWidth(tmi->font);
1722 tmi->width = tmi->chars * getFontWidth(tmi->font);
1724 // if lines set to "-1", automatically determine by text and font height
1725 if (tmi->lines == -1)
1726 tmi->lines = tmi->height / getFontHeight(tmi->font);
1728 tmi->height = tmi->lines * getFontHeight(tmi->font);
1730 // if x set to "-1", automatically determine by width and alignment
1732 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1734 // if y set to "-1", automatically determine by height and alignment
1736 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1738 SetDrawBackgroundMask(REDRAW_ALL);
1739 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1741 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1743 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1744 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1745 tmi->autowrap, tmi->centered, tmi->parse_comments);
1750 static void DrawTitleScreen(void)
1752 KeyboardAutoRepeatOff();
1754 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1757 static boolean CheckTitleScreen(boolean levelset_has_changed)
1759 static boolean show_title_initial = TRUE;
1760 boolean show_titlescreen = FALSE;
1762 // needed to be able to skip title screen, if no image or message defined
1763 InitializeTitleControls(show_title_initial);
1765 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1766 show_titlescreen = TRUE;
1768 // show initial title images and messages only once at program start
1769 show_title_initial = FALSE;
1771 return (show_titlescreen && num_title_screens > 0);
1774 void DrawMainMenu(void)
1776 static LevelDirTree *leveldir_last_valid = NULL;
1777 boolean levelset_has_changed = FALSE;
1778 int fade_mask = REDRAW_FIELD;
1780 LimitScreenUpdates(FALSE);
1782 FadeSetLeaveScreen();
1784 // do not fade out here -- function may continue and fade on editor screen
1787 FadeMenuSoundsAndMusic();
1789 ExpireSoundLoops(FALSE);
1791 KeyboardAutoRepeatOn();
1793 audio.sound_deactivated = FALSE;
1797 // needed if last screen was the playing screen, invoked from level editor
1798 if (level_editor_test_game)
1800 CloseDoor(DOOR_CLOSE_ALL);
1802 SetGameStatus(GAME_MODE_EDITOR);
1809 // needed if last screen was the playing screen, invoked from hall of fame
1810 if (score_info_tape_play)
1812 CloseDoor(DOOR_CLOSE_ALL);
1814 SetGameStatus(GAME_MODE_SCOREINFO);
1816 DrawScoreInfo(scores.last_entry_nr);
1821 // reset flag to continue playing next level from hall of fame
1822 scores.continue_playing = FALSE;
1824 // leveldir_current may be invalid (level group, parent link, node copy)
1825 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1827 if (leveldir_current != leveldir_last_valid)
1829 // level setup config may have been loaded to "last played" tree node copy,
1830 // but "leveldir_current" now points to the "original" level set tree node,
1831 // in which case "handicap_level" may still default to the first level
1832 LoadLevelSetup_SeriesInfo();
1834 UpdateLastPlayedLevels_TreeInfo();
1836 levelset_has_changed = TRUE;
1839 // store valid level series information
1840 leveldir_last_valid = leveldir_current;
1842 // store first level of this level set for "level_nr" style animations
1843 SetAnimationFirstLevel(leveldir_current->first_level);
1845 // level_nr may have been set to value over handicap with level editor
1846 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1847 level_nr = leveldir_current->handicap_level;
1849 LoadLevel(level_nr);
1850 LoadScore(level_nr);
1852 SaveLevelSetup_SeriesInfo();
1854 // needed if last screen (level choice) changed graphics, sounds or music
1855 ReloadCustomArtwork(0);
1857 if (CheckTitleScreen(levelset_has_changed))
1859 SetGameStatus(GAME_MODE_TITLE);
1866 if (redraw_mask & REDRAW_ALL)
1867 fade_mask = REDRAW_ALL;
1870 fade_mask = REDRAW_ALL;
1874 // needed if different viewport properties defined for menues
1875 ChangeViewportPropertiesIfNeeded();
1877 SetDrawtoField(DRAW_TO_BACKBUFFER);
1879 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1880 SetDrawDeactivationMask(REDRAW_NONE);
1881 SetDrawBackgroundMask(REDRAW_FIELD);
1883 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1886 if (fade_mask == REDRAW_ALL)
1887 RedrawGlobalBorder();
1892 InitializeMainControls();
1894 DrawCursorAndText_Main(-1, FALSE, FALSE);
1895 DrawPreviewLevelInitial();
1896 DrawNetworkPlayers();
1898 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1901 if (TAPE_IS_EMPTY(tape))
1903 DrawCompleteVideoDisplay();
1905 PlayMenuSoundsAndMusic();
1907 // create gadgets for main menu screen
1908 FreeScreenGadgets();
1909 CreateScreenGadgets();
1911 // may be required if audio buttons shown on tape and changed in setup menu
1913 CreateGameButtons();
1915 // map gadgets for main menu screen
1917 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1918 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1919 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SET_INFO, hasLevelSetInfo());
1921 // copy actual game door content to door double buffer for OpenDoor()
1922 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1923 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1925 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1927 DrawMaskedBorder(fade_mask);
1932 // update screen area with special editor door
1933 redraw_mask |= REDRAW_ALL;
1936 SetMouseCursor(CURSOR_DEFAULT);
1938 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1940 SyncEmscriptenFilesystem();
1942 // needed once after program start or after user change
1943 CheckApiServerTasks();
1946 static void gotoTopLevelDir(void)
1948 // move upwards until inside (but not above) top level directory
1949 while (leveldir_current->node_parent &&
1950 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1952 // write a "path" into level tree for easy navigation to last level
1953 if (leveldir_current->node_parent->node_group->cl_first == -1)
1955 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1956 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1957 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1958 int cl_first, cl_cursor;
1960 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1961 cl_cursor = leveldir_pos - cl_first;
1963 leveldir_current->node_parent->node_group->cl_first = cl_first;
1964 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1967 leveldir_current = leveldir_current->node_parent;
1971 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1973 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1975 return (use_frame_counter ? video.frame_counter : Counter());
1978 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1979 struct TitleFadingInfo *fi)
1981 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1984 static void ResetTitleAutoDelay(unsigned int *counter_var,
1985 struct TitleFadingInfo *fi)
1987 *counter_var = getAutoDelayCounter(fi);
1990 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1992 static unsigned int title_delay = 0;
1993 static int title_screen_nr = 0;
1994 static int last_sound = -1, last_music = -1;
1995 boolean return_to_main_menu = FALSE;
1996 struct TitleControlInfo *tci;
1999 if (button == MB_MENU_INITIALIZE)
2002 title_screen_nr = 0;
2003 tci = &title_controls[title_screen_nr];
2005 SetAnimStatus(getTitleAnimMode(tci));
2007 last_sound = SND_UNDEFINED;
2008 last_music = MUS_UNDEFINED;
2010 if (num_title_screens != 0)
2012 FadeSetEnterScreen();
2014 // use individual title fading instead of global "enter screen" fading
2015 fading = getTitleFading(tci);
2018 if (game_status_last_screen == GAME_MODE_INFO)
2020 if (num_title_screens == 0)
2022 // switch game mode from title screen mode back to info screen mode
2023 SetGameStatus(GAME_MODE_INFO);
2025 // store that last screen was info screen, not main menu screen
2026 game_status_last_screen = GAME_MODE_INFO;
2028 DrawInfoScreen_NotAvailable("Title screen information:",
2029 "No title screen for this level set.");
2034 FadeMenuSoundsAndMusic();
2036 FadeOut(REDRAW_ALL);
2038 // title screens may have different window size
2039 ChangeViewportPropertiesIfNeeded();
2041 // only required to update logic for redrawing global border
2045 DrawTitleScreenImage(tci->local_nr, tci->initial);
2047 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2049 sound = getTitleSound(tci);
2050 music = getTitleMusic(tci);
2052 if (sound != last_sound)
2053 PlayMenuSoundExt(sound);
2054 if (music != last_music)
2055 PlayMenuMusicExt(music);
2060 SetMouseCursor(CURSOR_NONE);
2064 ResetTitleAutoDelay(&title_delay, &fading);
2069 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
2070 button = MB_MENU_CHOICE;
2072 if (button == MB_MENU_LEAVE)
2074 return_to_main_menu = TRUE;
2076 else if (button == MB_MENU_CHOICE || dx)
2078 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
2080 SetGameStatus(GAME_MODE_INFO);
2082 info_mode = INFO_MODE_MAIN;
2090 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
2092 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
2094 tci = &title_controls[title_screen_nr];
2096 SetAnimStatus(getTitleAnimMode(tci));
2098 sound = getTitleSound(tci);
2099 music = getTitleMusic(tci);
2101 if (last_sound != SND_UNDEFINED && sound != last_sound)
2102 FadeSound(last_sound);
2103 if (last_music != MUS_UNDEFINED && music != last_music)
2106 fading = getTitleFading(tci);
2108 FadeOut(REDRAW_ALL);
2111 DrawTitleScreenImage(tci->local_nr, tci->initial);
2113 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2115 sound = getTitleSound(tci);
2116 music = getTitleMusic(tci);
2118 if (sound != last_sound)
2119 PlayMenuSoundExt(sound);
2120 if (music != last_music)
2121 PlayMenuMusicExt(music);
2128 ResetTitleAutoDelay(&title_delay, &fading);
2132 FadeMenuSoundsAndMusic();
2134 return_to_main_menu = TRUE;
2139 tci = &title_controls[title_screen_nr];
2141 // check for optional title screen of native BD style level set
2142 if (tci->is_image && CheckTitleScreen_BD(tci->local_nr, tci->initial))
2144 Bitmap **title_screen_bitmaps = GetTitleScreenBitmaps_BD();
2146 // if title screen is animated, draw title screen animation
2147 if (title_screen_bitmaps[0] != NULL &&
2148 title_screen_bitmaps[1] != NULL)
2149 DrawTitleScreenImage(tci->local_nr, tci->initial);
2153 if (return_to_main_menu)
2155 SetMouseCursor(CURSOR_DEFAULT);
2157 // force full menu screen redraw after displaying title screens
2158 redraw_mask = REDRAW_ALL;
2160 if (game_status_last_screen == GAME_MODE_INFO)
2162 SetGameStatus(GAME_MODE_INFO);
2164 info_mode = INFO_MODE_MAIN;
2168 else // default: return to main menu
2170 SetGameStatus(GAME_MODE_MAIN);
2177 static void HandleMainMenu_ToggleTeamMode(void)
2179 setup.team_mode = !setup.team_mode;
2181 InitializeMainControls();
2182 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2184 DrawPreviewPlayers();
2187 static void HandleMainMenu_SelectLevel(int step, int direction,
2188 int selected_level_nr)
2190 int old_level_nr = level_nr;
2193 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2194 new_level_nr = selected_level_nr;
2196 new_level_nr = old_level_nr + step * direction;
2198 if (new_level_nr < leveldir_current->first_level)
2199 new_level_nr = leveldir_current->first_level;
2200 if (new_level_nr > leveldir_current->last_level)
2201 new_level_nr = leveldir_current->last_level;
2203 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2205 // skipping levels is only allowed when trying to skip single level
2206 // (also, skipping BD style intermission levels is always possible)
2207 if (new_level_nr == old_level_nr + 1 &&
2208 (level.bd_intermission ||
2209 (setup.skip_levels && Request("Level still unsolved! Skip it anyway?", REQ_ASK))))
2211 leveldir_current->handicap_level++;
2212 SaveLevelSetup_SeriesInfo();
2215 new_level_nr = leveldir_current->handicap_level;
2218 if (new_level_nr != old_level_nr)
2220 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2222 PlaySound(SND_MENU_ITEM_SELECTING);
2224 level_nr = new_level_nr;
2226 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2227 int2str(level_nr, menu.main.text.level_number.size),
2228 mci->pos_text->font);
2230 LoadLevel(level_nr);
2231 DrawPreviewLevelInitial();
2235 DrawCompleteVideoDisplay();
2237 SaveLevelSetup_SeriesInfo();
2239 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2241 // force redraw of playfield area (may be reset at this point)
2242 redraw_mask |= REDRAW_FIELD;
2246 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2248 static int choice = MAIN_CONTROL_GAME;
2249 static boolean button_pressed_last = FALSE;
2250 boolean button_pressed = FALSE;
2252 int i = 0; // needed to prevent compiler warning due to bad code below
2254 if (button == MB_MENU_INITIALIZE)
2256 DrawCursorAndText_Main(choice, TRUE, FALSE);
2261 if (mx || my) // mouse input
2265 for (i = 0; main_controls[i].nr != -1; i++)
2267 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2268 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2269 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2271 pos = main_controls[i].nr;
2277 // check if level preview was clicked
2278 if (insidePreviewRect(&preview, mx - SX, my - SY))
2279 pos = MAIN_CONTROL_GAME;
2281 // handle pressed/unpressed state for active/inactive menu buttons
2282 // (if pos != -1, "i" contains index position corresponding to "pos")
2284 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2285 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2286 button_pressed = TRUE;
2288 if (button_pressed != button_pressed_last)
2290 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2293 PlaySound(SND_MENU_BUTTON_PRESSING);
2295 PlaySound(SND_MENU_BUTTON_RELEASING);
2298 else if (dx || dy) // keyboard input
2300 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2301 choice == MAIN_CONTROL_SETUP))
2302 button = MB_MENU_CHOICE;
2307 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2309 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2311 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2313 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2315 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2317 CloseDoor(DOOR_CLOSE_2);
2319 SetGameStatus(GAME_MODE_LEVELNR);
2321 DrawChooseLevelNr();
2323 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2329 PlaySound(SND_MENU_ITEM_ACTIVATING);
2331 DrawCursorAndText_Main(choice, FALSE, FALSE);
2332 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2338 if (choice == MAIN_CONTROL_NAME)
2340 // special case: cursor left or right pressed -- toggle team mode
2341 HandleMainMenu_ToggleTeamMode();
2343 else if (choice != MAIN_CONTROL_INFO &&
2344 choice != MAIN_CONTROL_SETUP)
2346 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2352 PlaySound(SND_MENU_ITEM_SELECTING);
2354 if (pos == MAIN_CONTROL_NAME)
2357 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2359 // special case: menu text "name/team" clicked -- toggle team mode
2360 HandleMainMenu_ToggleTeamMode();
2364 if (setup.multiple_users)
2366 CloseDoor(DOOR_CLOSE_2);
2368 SetGameStatus(GAME_MODE_NAMES);
2370 DrawChoosePlayerName();
2374 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2380 else if (pos == MAIN_CONTROL_LEVELS)
2384 CloseDoor(DOOR_CLOSE_2);
2386 SetGameStatus(GAME_MODE_LEVELS);
2388 SaveLevelSetup_LastSeries();
2389 SaveLevelSetup_SeriesInfo();
2391 // restore level set if chosen from "last played level set" menu
2392 RestoreLastPlayedLevels(&leveldir_current);
2394 if (setup.internal.choose_from_top_leveldir)
2397 DrawChooseLevelSet();
2400 else if (pos == MAIN_CONTROL_SCORES)
2402 CloseDoor(DOOR_CLOSE_2);
2404 SetGameStatus(GAME_MODE_SCORES);
2406 DrawHallOfFame(level_nr);
2408 else if (pos == MAIN_CONTROL_EDITOR)
2410 if (leveldir_current->readonly &&
2411 setup.editor.show_read_only_warning)
2412 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2414 CloseDoor(DOOR_CLOSE_ALL);
2416 SetGameStatus(GAME_MODE_EDITOR);
2418 FadeSetEnterScreen();
2422 else if (pos == MAIN_CONTROL_INFO)
2424 CloseDoor(DOOR_CLOSE_2);
2426 SetGameStatus(GAME_MODE_INFO);
2428 info_mode = INFO_MODE_MAIN;
2432 else if (pos == MAIN_CONTROL_GAME)
2434 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2436 else if (pos == MAIN_CONTROL_SETUP)
2438 CloseDoor(DOOR_CLOSE_2);
2440 SetGameStatus(GAME_MODE_SETUP);
2442 setup_mode = SETUP_MODE_MAIN;
2446 else if (pos == MAIN_CONTROL_QUIT)
2448 SaveLevelSetup_LastSeries();
2449 SaveLevelSetup_SeriesInfo();
2451 #if defined(PLATFORM_EMSCRIPTEN)
2452 Request("Close the browser window to quit!", REQ_CONFIRM);
2454 if (!setup.ask_on_quit_program ||
2455 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2456 SetGameStatus(GAME_MODE_QUIT);
2462 button_pressed_last = button_pressed;
2466 // ============================================================================
2467 // info screen functions
2468 // ============================================================================
2470 static struct TokenInfo *info_info;
2471 static int num_info_info; // number of info entries shown on screen
2472 static int max_info_info; // total number of info entries in list
2474 static void execInfoTitleScreen(void)
2476 info_mode = INFO_MODE_TITLE;
2481 static void execInfoElements(void)
2483 info_mode = INFO_MODE_ELEMENTS;
2488 static void execInfoMusic(void)
2490 info_mode = INFO_MODE_MUSIC;
2495 static void execInfoCredits(void)
2497 info_mode = INFO_MODE_CREDITS;
2502 static void execInfoProgram(void)
2504 info_mode = INFO_MODE_PROGRAM;
2509 static void execInfoVersion(void)
2511 info_mode = INFO_MODE_VERSION;
2516 static void execInfoLevelSet(void)
2518 info_mode = INFO_MODE_LEVELSET;
2523 static void execExitInfo(void)
2525 SetGameStatus(GAME_MODE_MAIN);
2530 static struct TokenInfo info_info_main[] =
2532 { TYPE_ENTER_SCREEN, execInfoTitleScreen, STR_INFO_TITLE },
2533 { TYPE_ENTER_SCREEN, execInfoElements, STR_INFO_ELEMENTS },
2534 { TYPE_ENTER_SCREEN, execInfoMusic, STR_INFO_MUSIC },
2535 { TYPE_ENTER_SCREEN, execInfoCredits, STR_INFO_CREDITS },
2536 { TYPE_ENTER_SCREEN, execInfoProgram, STR_INFO_PROGRAM },
2537 { TYPE_ENTER_SCREEN, execInfoVersion, STR_INFO_VERSION },
2538 { TYPE_ENTER_SCREEN, execInfoLevelSet, STR_INFO_LEVELSET },
2539 { TYPE_EMPTY, NULL, "" },
2540 { TYPE_LEAVE_MENU, execExitInfo, STR_INFO_EXIT },
2545 static int getMenuTextFont(int type)
2547 if (type & (TYPE_SWITCH |
2561 static struct TokenInfo *setup_info;
2562 static struct TokenInfo setup_info_input[];
2564 static struct TokenInfo *menu_info;
2566 static void PlayInfoSound(void)
2568 int info_sound = getInfoScreenBackgroundSound_Generic();
2569 char *next_sound = getSoundInfoEntryFilename(info_sound);
2571 if (next_sound != NULL)
2572 PlayMenuSoundExt(info_sound);
2577 static void PlayInfoSoundIfLoop(void)
2579 int info_sound = getInfoScreenBackgroundSound_Generic();
2580 char *next_sound = getSoundInfoEntryFilename(info_sound);
2582 if (next_sound != NULL)
2583 PlayMenuSoundIfLoopExt(info_sound);
2585 PlayMenuSoundIfLoop();
2588 static void PlayInfoMusic(void)
2590 int info_music = getInfoScreenBackgroundMusic_Generic();
2591 char *curr_music = getCurrentlyPlayingMusicFilename();
2592 char *next_music = getMusicInfoEntryFilename(info_music);
2594 if (next_music != NULL)
2596 // play music if info screen music differs from current music
2597 if (!strEqual(curr_music, next_music))
2598 PlayMenuMusicExt(info_music);
2602 // only needed if info screen was directly invoked from main menu
2607 static void PlayInfoSoundsAndMusic(void)
2613 static void FadeInfoSounds(void)
2618 static void FadeInfoMusic(void)
2620 int info_music = getInfoScreenBackgroundMusic_Generic();
2621 char *curr_music = getCurrentlyPlayingMusicFilename();
2622 char *next_music = getMusicInfoEntryFilename(info_music);
2624 if (next_music != NULL)
2626 // fade music if info screen music differs from current music
2627 if (!strEqual(curr_music, next_music))
2632 static void FadeInfoSoundsAndMusic(void)
2638 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2639 int screen_pos, int menu_info_pos_raw,
2642 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2643 struct TokenInfo *ti = &token_info[pos];
2644 int xpos = MENU_SCREEN_START_XPOS;
2645 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2646 int font_nr = getMenuTextFont(ti->type);
2648 if (setup_mode == SETUP_MODE_INPUT)
2649 font_nr = FONT_MENU_1;
2652 font_nr = FONT_ACTIVE(font_nr);
2654 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2656 if (ti->type & ~TYPE_SKIP_ENTRY)
2657 drawCursor(screen_pos, active);
2660 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2663 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2666 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2669 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2672 static char *window_size_text;
2673 static char *scaling_type_text;
2674 static char *network_server_text;
2676 static void drawSetupValue(int, int);
2678 static void drawMenuInfoList(int first_entry, int num_page_entries,
2679 int max_page_entries)
2683 if (first_entry + num_page_entries > max_page_entries)
2686 clearMenuListArea();
2688 for (i = 0; i < num_page_entries; i++)
2690 int menu_info_pos = first_entry + i;
2691 struct TokenInfo *si = &menu_info[menu_info_pos];
2692 void *value_ptr = si->value;
2694 // set some entries to "unchangeable" according to other variables
2695 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2696 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2697 (value_ptr == &setup.sound_music && !audio.music_available) ||
2698 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2699 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2700 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2701 si->type |= TYPE_GHOSTED;
2703 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2704 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2705 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2706 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2707 else if (si->type & ~TYPE_SKIP_ENTRY)
2708 initCursor(i, IMG_MENU_BUTTON);
2710 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2712 if (si->type & TYPE_STRING)
2716 if (value_ptr == &network_server_text)
2717 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2719 if (gadget_id != -1)
2721 struct GadgetInfo *gi = screen_gadget[gadget_id];
2722 int xpos = MENU_SCREEN_START_XPOS;
2723 int ypos = MENU_SCREEN_START_YPOS + i;
2724 int x = mSX + xpos * 32;
2725 int y = mSY + ypos * 32;
2727 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2731 if (si->type & TYPE_VALUE &&
2732 menu_info == setup_info)
2733 drawSetupValue(i, menu_info_pos);
2737 static void DrawInfoScreen_Main(void)
2739 int fade_mask = REDRAW_FIELD;
2742 // (needed after displaying info sub-screens directly from main menu)
2743 if (info_screens_from_main)
2745 info_screens_from_main = FALSE;
2747 SetGameStatus(GAME_MODE_MAIN);
2754 if (redraw_mask & REDRAW_ALL)
2755 fade_mask = REDRAW_ALL;
2758 fade_mask = REDRAW_ALL;
2761 FadeMenuSoundsAndMusic();
2763 FreeScreenGadgets();
2764 CreateScreenGadgets();
2766 // (needed after displaying title screens which disable auto repeat)
2767 KeyboardAutoRepeatOn();
2769 FadeSetLeaveScreen();
2773 // needed if different viewport properties defined for info screen
2774 ChangeViewportPropertiesIfNeeded();
2776 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2780 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2782 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_INFO_MAIN);
2784 info_info = info_info_main;
2786 // use modified info screen info without info screen entries marked as hidden
2787 info_info = getSetupInfoFinal(info_info);
2789 // determine maximal number of info entries that can be displayed on screen
2791 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2794 // determine maximal number of info entries available for menu of info screen
2796 for (i = 0; info_info[i].type != 0; i++)
2799 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2801 MapScreenGadgets(max_info_info);
2803 PlayMenuSoundsAndMusic();
2805 DrawMaskedBorder(fade_mask);
2810 static void changeSetupValue(int, int, int);
2812 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2813 int mode, int num_page_entries,
2814 int max_page_entries)
2816 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2817 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2818 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2819 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2820 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2821 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2822 int *num_page_entries_last = num_page_entries_all_last[game_status];
2823 int *choice_store = choice_stores[game_status];
2824 int *first_entry_store = first_entry_stores[game_status];
2825 int choice = choice_store[mode]; // starts with 0
2826 int first_entry = first_entry_store[mode]; // starts with 0
2828 int y = choice - first_entry;
2830 boolean position_set_by_scrollbar = (dx == 999);
2831 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2834 if (button == MB_MENU_INITIALIZE)
2836 // check if number of menu page entries has changed (may happen by change
2837 // of custom artwork definition value for 'list_size' for this menu screen)
2838 // (in this case, the last menu position most probably has to be corrected)
2839 if (num_page_entries != num_page_entries_last[mode])
2841 choice_store[mode] = first_entry_store[mode] = 0;
2843 choice = first_entry = 0;
2846 num_page_entries_last[mode] = num_page_entries;
2849 // advance to first valid menu entry
2850 while (choice < num_page_entries &&
2851 menu_info[choice].type & TYPE_SKIP_ENTRY)
2854 if (position_set_by_scrollbar)
2855 first_entry = first_entry_store[mode] = dy;
2857 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2858 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2860 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2862 if (choice < first_entry)
2864 choice = first_entry;
2866 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2869 else if (choice > first_entry + num_page_entries - 1)
2871 choice = first_entry + num_page_entries - 1;
2873 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2877 choice_store[mode] = choice;
2879 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2883 else if (button == MB_MENU_LEAVE)
2885 PlaySound(SND_MENU_ITEM_SELECTING);
2887 for (i = 0; i < max_page_entries; i++)
2889 if (menu_info[i].type & TYPE_LEAVE_MENU)
2891 void (*menu_callback_function)(void) = menu_info[i].value;
2895 menu_callback_function();
2897 break; // absolutely needed because function changes 'menu_info'!
2904 if (mx || my) // mouse input
2906 x = (mx - mSX) / 32;
2907 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2909 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2911 // move cursor instead of scrolling when already at start/end of list
2912 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2914 else if (dy == +1 * SCROLL_LINE &&
2915 first_entry + num_page_entries == max_page_entries)
2918 // handle scrolling screen one line or page
2920 y + dy > num_page_entries - 1)
2922 boolean redraw = FALSE;
2924 if (ABS(dy) == SCROLL_PAGE)
2925 step = num_page_entries - 1;
2927 if (dy < 0 && first_entry > 0)
2929 // scroll page/line up
2931 first_entry -= step;
2932 if (first_entry < 0)
2937 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2939 // scroll page/line down
2941 first_entry += step;
2942 if (first_entry + num_page_entries > max_page_entries)
2943 first_entry = MAX(0, max_page_entries - num_page_entries);
2950 choice += first_entry - first_entry_store[mode];
2952 if (choice < first_entry)
2954 choice = first_entry;
2956 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2959 else if (choice > first_entry + num_page_entries - 1)
2961 choice = first_entry + num_page_entries - 1;
2963 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2966 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2970 if (choice < first_entry ||
2971 choice > first_entry + num_page_entries - 1)
2972 first_entry += SIGN(dy);
2975 first_entry_store[mode] = first_entry;
2976 choice_store[mode] = choice;
2978 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2980 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2982 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2983 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2991 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2993 if (menu_info[choice].type & menu_navigation_type ||
2994 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2995 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2996 menu_info[choice].type & TYPE_PLAYER)
2997 button = MB_MENU_CHOICE;
3002 // jump to next non-empty menu entry (up or down)
3003 while (first_entry + y > 0 &&
3004 first_entry + y < max_page_entries - 1 &&
3005 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
3008 if (!IN_VIS_MENU(x, y))
3010 choice += y - y_old;
3012 if (choice < first_entry)
3013 first_entry = choice;
3014 else if (choice > first_entry + num_page_entries - 1)
3015 first_entry = choice - num_page_entries + 1;
3017 if (first_entry >= 0 &&
3018 first_entry + num_page_entries <= max_page_entries)
3020 first_entry_store[mode] = first_entry;
3022 if (choice < first_entry)
3023 choice = first_entry;
3024 else if (choice > first_entry + num_page_entries - 1)
3025 choice = first_entry + num_page_entries - 1;
3027 choice_store[mode] = choice;
3029 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
3031 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
3033 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
3034 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
3041 if (!anyScrollbarGadgetActive() &&
3042 IN_VIS_MENU(x, y) &&
3043 mx < mx_right_border &&
3044 y >= 0 && y < num_page_entries)
3048 if (first_entry + y != choice &&
3049 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
3051 PlaySound(SND_MENU_ITEM_ACTIVATING);
3053 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
3054 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
3056 choice = choice_store[mode] = first_entry + y;
3060 PlaySound(SND_MENU_ITEM_SELECTING);
3062 for (i = 0; menu_info[i].type != 0; i++)
3064 if (menu_info[i].type & TYPE_LEAVE_MENU)
3066 void (*menu_callback_function)(void) = menu_info[i].value;
3070 menu_callback_function();
3072 // absolutely needed because function changes 'menu_info'!
3080 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
3082 PlaySound(SND_MENU_ITEM_SELECTING);
3084 // when selecting key headline, execute function for key value change
3085 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
3086 menu_info[first_entry + y + 1].type & TYPE_KEY)
3089 // when selecting string value, execute function for list selection
3090 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3091 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
3094 // when selecting string value, execute function for text input gadget
3095 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3096 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
3099 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
3101 void (*menu_callback_function)(void) =
3102 menu_info[first_entry + y].value;
3104 FadeSetFromType(menu_info[first_entry + y].type);
3106 menu_callback_function();
3108 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
3110 void (*gadget_callback_function)(void) =
3111 menu_info[first_entry + y].value;
3113 gadget_callback_function();
3115 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
3116 menu_info == setup_info)
3118 changeSetupValue(y, first_entry + y, dx);
3124 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
3126 menu_info = info_info;
3128 HandleMenuScreen(mx, my, dx, dy, button,
3129 info_mode, num_info_info, max_info_info);
3132 static int getMenuFontSpacing(int spacing_height, int font_nr)
3134 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
3136 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
3140 static int getMenuTextSpacing(int spacing_height, int font_nr)
3142 return (getMenuFontSpacing(spacing_height, font_nr) +
3143 EXTRA_SPACING(game_status));
3146 static int getMenuTextStep(int spacing_height, int font_nr)
3148 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
3151 static int getHeadlineSpacing(void)
3153 // special compatibility handling for "R'n'D jue 2022" game editions
3154 int spacing_check = menu.headline1_spacing[GAME_MODE_SCOREINFO];
3155 int spacing = (game_status == GAME_MODE_SCOREINFO ?
3156 menu.headline1_spacing[GAME_MODE_SCOREINFO] :
3157 menu.headline1_spacing_info[info_mode]);
3158 int font = MENU_INFO_FONT_TITLE;
3160 return (spacing_check != -2 ? getMenuTextStep(spacing, font) : 0);
3163 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
3165 int font_error = FONT_TEXT_2;
3166 int font_foot = MENU_INFO_FONT_FOOT;
3167 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3168 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3170 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
3172 FadeOut(REDRAW_FIELD);
3176 DrawInfoScreen_Headline(0, 1, FALSE);
3178 DrawTextSCentered(ystart, font_error, text_error);
3179 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3181 FadeIn(REDRAW_FIELD);
3184 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
3186 static int infoscreen_step[MAX_INFO_ELEMENTS_IN_ARRAY];
3187 static int infoscreen_frame[MAX_INFO_ELEMENTS_IN_ARRAY];
3188 int font_foot = MENU_INFO_FONT_FOOT;
3189 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
3190 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3191 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3192 int ystep = MENU_SCREEN_INFO_YSTEP;
3193 int row_height = MENU_SCREEN_INFO_ENTRY_SIZE;
3194 int tilesize = MENU_SCREEN_INFO_TILE_SIZE;
3195 int yoffset = (row_height - tilesize) / 2;
3196 int element, action, direction;
3204 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
3205 infoscreen_step[i] = infoscreen_frame[i] = 0;
3207 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3213 while (helpanim_info[j].element != HELPANIM_LIST_END)
3215 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3220 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3229 int ypos = i - start;
3230 int ystart_pos = ystart + ypos * ystep + yoffset;
3232 j += infoscreen_step[ypos];
3234 element = helpanim_info[j].element;
3235 action = helpanim_info[j].action;
3236 direction = helpanim_info[j].direction;
3239 element = EL_UNKNOWN;
3241 if (action != -1 && direction != -1)
3242 graphic = el_act_dir2img(element, action, direction);
3243 else if (action != -1)
3244 graphic = el_act2img(element, action);
3245 else if (direction != -1)
3246 graphic = el_dir2img(element, direction);
3248 graphic = el2img(element);
3250 delay = helpanim_info[j++].delay;
3255 if (infoscreen_frame[ypos] == 0)
3258 infoscreen_frame[ypos] = delay - 1;
3262 sync_frame = delay - infoscreen_frame[ypos];
3263 infoscreen_frame[ypos]--;
3266 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3268 if (!infoscreen_frame[ypos])
3269 infoscreen_step[ypos] = 0;
3273 if (!infoscreen_frame[ypos])
3274 infoscreen_step[ypos]++;
3275 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3281 ClearRectangleOnBackground(drawto, xstart, ystart_pos, tilesize, tilesize);
3282 DrawSizedGraphicAnimationExt(drawto, xstart, ystart_pos,
3283 graphic, sync_frame, tilesize, USE_MASKING);
3286 DrawInfoScreen_HelpText(element, action, direction, ypos);
3291 redraw_mask |= REDRAW_FIELD;
3296 static char *getHelpText(int element, int action, int direction)
3298 char token[MAX_LINE_LEN];
3300 strcpy(token, element_info[element].token_name);
3303 strcat(token, element_action_info[action].suffix);
3305 if (direction != -1)
3306 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3308 return getHashEntry(helptext_info, token);
3311 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3313 int font_nr = FONT_INFO_ELEMENTS;
3314 int font_width = getFontWidth(font_nr);
3315 int font_height = getFontHeight(font_nr);
3316 int line_spacing = MENU_SCREEN_INFO_SPACE_LINE;
3317 int left_spacing = MENU_SCREEN_INFO_SPACE_LEFT;
3318 int middle_spacing = MENU_SCREEN_INFO_SPACE_MIDDLE;
3319 int right_spacing = MENU_SCREEN_INFO_SPACE_RIGHT;
3320 int line_height = font_height + line_spacing;
3321 int row_height = MENU_SCREEN_INFO_ENTRY_SIZE;
3322 int tilesize = MENU_SCREEN_INFO_TILE_SIZE;
3323 int xstart = mSX + left_spacing + tilesize + middle_spacing;
3324 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3325 int ystep = MENU_SCREEN_INFO_YSTEP;
3326 int pad_left = xstart - SX;
3327 int pad_right = right_spacing;
3328 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3329 int max_lines_per_text = (row_height + line_spacing) / line_height;
3331 boolean autowrap = TRUE;
3332 boolean centered = FALSE;
3333 boolean parse_comments = FALSE;
3335 if (action != -1 && direction != -1) // element.action.direction
3336 text = getHelpText(element, action, direction);
3338 if (text == NULL && action != -1) // element.action
3339 text = getHelpText(element, action, -1);
3341 if (text == NULL && direction != -1) // element.direction
3342 text = getHelpText(element, -1, direction);
3344 if (text == NULL) // base element
3345 text = getHelpText(element, -1, -1);
3347 if (text == NULL) // not found
3348 text = "No description available";
3350 DisableDrawingText();
3352 // first get number of text lines to calculate offset for centering text
3353 int num_lines_printed =
3354 DrawTextBuffer(0, 0, text, font_nr,
3355 max_chars_per_line, -1, max_lines_per_text, line_spacing, -1,
3356 autowrap, centered, parse_comments);
3358 EnableDrawingText();
3360 int size_lines_printed = num_lines_printed * line_height - line_spacing;
3361 int yoffset = (row_height - size_lines_printed) / 2;
3363 DrawTextBuffer(xstart, ystart + ypos * ystep + yoffset, text, font_nr,
3364 max_chars_per_line, -1, max_lines_per_text, line_spacing, -1,
3365 autowrap, centered, parse_comments);
3368 static void DrawInfoScreen_TitleScreen(void)
3370 SetGameStatus(GAME_MODE_TITLE);
3377 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3379 HandleTitleScreen(0, 0, dx, dy, button);
3382 static void DrawInfoScreen_Elements(void)
3384 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3387 FadeInfoSoundsAndMusic();
3389 FadeOut(REDRAW_FIELD);
3394 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3396 PlayInfoSoundsAndMusic();
3398 FadeIn(REDRAW_FIELD);
3401 void HandleInfoScreen_Elements(int dx, int dy, int button)
3403 static DelayCounter info_delay = { 0 };
3404 static int num_anims;
3405 static int num_pages;
3407 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3410 info_delay.value = GameFrameDelay;
3412 if (button == MB_MENU_INITIALIZE)
3414 boolean new_element = TRUE;
3418 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3420 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3422 else if (new_element)
3425 new_element = FALSE;
3429 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3433 if (button == MB_MENU_LEAVE)
3435 PlaySound(SND_MENU_ITEM_SELECTING);
3437 info_mode = INFO_MODE_MAIN;
3442 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3444 if (button != MB_MENU_INITIALIZE)
3446 PlaySound(SND_MENU_ITEM_SELECTING);
3448 page += (dx < 0 ? -1 : +1);
3451 if (page < 0 || page >= num_pages)
3453 FadeInfoSoundsAndMusic();
3455 info_mode = INFO_MODE_MAIN;
3461 if (button != MB_MENU_INITIALIZE)
3462 FadeSetNextScreen();
3464 if (button != MB_MENU_INITIALIZE)
3465 FadeOut(REDRAW_FIELD);
3469 DrawInfoScreen_Headline(page, num_pages, TRUE);
3470 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3472 if (button != MB_MENU_INITIALIZE)
3473 FadeIn(REDRAW_FIELD);
3477 if (DelayReached(&info_delay))
3478 if (page < num_pages)
3479 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3481 PlayInfoSoundIfLoop();
3485 static void DrawInfoScreen_Music(void)
3487 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3491 FadeOut(REDRAW_FIELD);
3495 DrawInfoScreen_Headline(0, 1, TRUE);
3499 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3501 FadeIn(REDRAW_FIELD);
3504 void HandleInfoScreen_Music(int dx, int dy, int button)
3506 static struct MusicFileInfo *list = NULL;
3507 static int num_screens = 0;
3508 static int screen_nr = 0;
3509 int font_title = MENU_INFO_FONT_TITLE;
3510 int font_head = MENU_INFO_FONT_HEAD;
3511 int font_text = MENU_INFO_FONT_TEXT;
3512 int font_foot = MENU_INFO_FONT_FOOT;
3513 int spacing_head = menu.headline2_spacing_info[info_mode];
3514 int ystep_head = getMenuTextStep(spacing_head, font_head);
3515 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3516 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3518 if (button == MB_MENU_INITIALIZE)
3520 struct MusicFileInfo *list_ptr = music_file_info;
3525 while (list_ptr != NULL)
3527 list_ptr = list_ptr->next;
3531 list = music_file_info;
3535 FadeMenuSoundsAndMusic();
3539 DrawInfoScreen_Headline(0, 1, TRUE);
3541 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3542 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3548 if (button == MB_MENU_LEAVE)
3550 PlaySound(SND_MENU_ITEM_SELECTING);
3552 FadeMenuSoundsAndMusic();
3554 info_mode = INFO_MODE_MAIN;
3559 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3561 if (button != MB_MENU_INITIALIZE)
3563 PlaySound(SND_MENU_ITEM_SELECTING);
3567 list = (dx < 0 ? list->prev : list->next);
3568 screen_nr += (dx < 0 ? -1 : +1);
3574 FadeMenuSoundsAndMusic();
3576 info_mode = INFO_MODE_MAIN;
3582 FadeMenuSoundsAndMusic();
3584 if (list != music_file_info)
3585 FadeSetNextScreen();
3587 if (button != MB_MENU_INITIALIZE)
3588 FadeOut(REDRAW_FIELD);
3592 DrawInfoScreen_Headline(screen_nr, num_screens, TRUE);
3596 int sound = list->music;
3598 if (IS_LOOP_SOUND(sound))
3599 PlaySoundLoop(sound);
3605 int music = list->music;
3607 if (IS_LOOP_MUSIC(music))
3608 PlayMusicLoop(music);
3613 if (!strEqual(list->title, UNKNOWN_NAME))
3615 if (!strEqual(list->title_header, UNKNOWN_NAME))
3616 DrawTextSCentered(ystart, font_head, list->title_header);
3618 DrawTextSCentered(ystart, font_head, "Track");
3620 ystart += ystep_head;
3622 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3623 ystart += ystep_head;
3626 if (!strEqual(list->artist, UNKNOWN_NAME))
3628 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3629 DrawTextSCentered(ystart, font_head, list->artist_header);
3631 DrawTextSCentered(ystart, font_head, "by");
3633 ystart += ystep_head;
3635 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3636 ystart += ystep_head;
3639 if (!strEqual(list->album, UNKNOWN_NAME))
3641 if (!strEqual(list->album_header, UNKNOWN_NAME))
3642 DrawTextSCentered(ystart, font_head, list->album_header);
3644 DrawTextSCentered(ystart, font_head, "from the album");
3646 ystart += ystep_head;
3648 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3649 ystart += ystep_head;
3652 if (!strEqual(list->year, UNKNOWN_NAME))
3654 if (!strEqual(list->year_header, UNKNOWN_NAME))
3655 DrawTextSCentered(ystart, font_head, list->year_header);
3657 DrawTextSCentered(ystart, font_head, "from the year");
3659 ystart += ystep_head;
3661 DrawTextFCentered(ystart, font_text, "%s", list->year);
3662 ystart += ystep_head;
3665 if (!strEqual(list->played, UNKNOWN_NAME))
3667 if (!strEqual(list->played_header, UNKNOWN_NAME))
3668 DrawTextSCentered(ystart, font_head, list->played_header);
3670 DrawTextSCentered(ystart, font_head, "played in");
3672 ystart += ystep_head;
3674 DrawTextFCentered(ystart, font_text, "%s", list->played);
3675 ystart += ystep_head;
3677 else if (!list->is_sound)
3679 int music_level_nr = -1;
3682 // check if this music is configured for a certain level
3683 for (i = leveldir_current->first_level;
3684 i <= leveldir_current->last_level; i++)
3686 // (special case: "list->music" may be negative for unconfigured music)
3687 if (levelset.music[i] != MUS_UNDEFINED &&
3688 levelset.music[i] == list->music)
3696 if (music_level_nr != -1)
3698 if (!strEqual(list->played_header, UNKNOWN_NAME))
3699 DrawTextSCentered(ystart, font_head, list->played_header);
3701 DrawTextSCentered(ystart, font_head, "played in");
3703 ystart += ystep_head;
3705 DrawTextFCentered(ystart, font_text, "level %03d", music_level_nr);
3706 ystart += ystep_head;
3710 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3712 if (button != MB_MENU_INITIALIZE)
3713 FadeIn(REDRAW_FIELD);
3716 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3717 PlaySoundLoop(list->music);
3720 static void DrawInfoScreen_Version(void)
3722 int font_head = MENU_INFO_FONT_HEAD;
3723 int font_text = MENU_INFO_FONT_TEXT;
3724 int font_foot = MENU_INFO_FONT_FOOT;
3725 int spacing_head = menu.headline2_spacing_info[info_mode];
3726 int spacing_para = menu.paragraph_spacing_info[info_mode];
3727 int spacing_line = menu.line_spacing_info[info_mode];
3728 int xstep = getFontWidth(font_text);
3729 int ystep_head = getMenuTextStep(spacing_head, font_head);
3730 int ystep_para = getMenuTextStep(spacing_para, font_text);
3731 int ystep_line = getMenuTextStep(spacing_line, font_text);
3732 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3733 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3734 int xstart1 = mSX - SX + 2 * xstep;
3735 int xstart2 = mSX - SX + 18 * xstep;
3736 int xstart3 = mSX - SX + 28 * xstep;
3737 SDL_version sdl_version_compiled;
3738 const SDL_version *sdl_version_linked;
3739 int driver_name_len = 10;
3740 SDL_version sdl_version_linked_ext;
3741 const char *driver_name = NULL;
3743 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3746 FadeInfoSoundsAndMusic();
3748 FadeOut(REDRAW_FIELD);
3752 DrawInfoScreen_Headline(0, 1, TRUE);
3754 DrawTextF(xstart1, ystart, font_head, "Name");
3755 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3756 ystart += ystep_line;
3758 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3760 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3761 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3762 ystart += ystep_line;
3764 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3765 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3766 ystart += ystep_line;
3770 DrawTextF(xstart1, ystart, font_head, "Version");
3771 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3772 ystart += ystep_line;
3775 DrawTextF(xstart1, ystart, font_head, "Platform");
3776 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3778 PLATFORM_XX_BIT_STRING);
3779 ystart += ystep_line;
3781 DrawTextF(xstart1, ystart, font_head, "Target");
3782 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3783 ystart += ystep_line;
3785 DrawTextF(xstart1, ystart, font_head, "Source date");
3786 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3787 ystart += ystep_line;
3789 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3790 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3791 ystart += ystep_para;
3793 DrawTextF(xstart1, ystart, font_head, "Library");
3794 DrawTextF(xstart2, ystart, font_head, "compiled");
3795 DrawTextF(xstart3, ystart, font_head, "linked");
3796 ystart += ystep_head;
3798 SDL_VERSION(&sdl_version_compiled);
3799 SDL_GetVersion(&sdl_version_linked_ext);
3800 sdl_version_linked = &sdl_version_linked_ext;
3802 DrawTextF(xstart1, ystart, font_text, "SDL");
3803 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3804 sdl_version_compiled.major,
3805 sdl_version_compiled.minor,
3806 sdl_version_compiled.patch);
3807 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3808 sdl_version_linked->major,
3809 sdl_version_linked->minor,
3810 sdl_version_linked->patch);
3811 ystart += ystep_line;
3813 SDL_IMAGE_VERSION(&sdl_version_compiled);
3814 sdl_version_linked = IMG_Linked_Version();
3816 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3817 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3818 sdl_version_compiled.major,
3819 sdl_version_compiled.minor,
3820 sdl_version_compiled.patch);
3821 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3822 sdl_version_linked->major,
3823 sdl_version_linked->minor,
3824 sdl_version_linked->patch);
3825 ystart += ystep_line;
3827 SDL_MIXER_VERSION(&sdl_version_compiled);
3828 sdl_version_linked = Mix_Linked_Version();
3830 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3831 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3832 sdl_version_compiled.major,
3833 sdl_version_compiled.minor,
3834 sdl_version_compiled.patch);
3835 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3836 sdl_version_linked->major,
3837 sdl_version_linked->minor,
3838 sdl_version_linked->patch);
3839 ystart += ystep_line;
3841 SDL_NET_VERSION(&sdl_version_compiled);
3842 sdl_version_linked = SDLNet_Linked_Version();
3844 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3845 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3846 sdl_version_compiled.major,
3847 sdl_version_compiled.minor,
3848 sdl_version_compiled.patch);
3849 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3850 sdl_version_linked->major,
3851 sdl_version_linked->minor,
3852 sdl_version_linked->patch);
3853 ystart += ystep_para;
3855 DrawTextF(xstart1, ystart, font_head, "Driver");
3856 DrawTextF(xstart2, ystart, font_head, "Requested");
3857 DrawTextF(xstart3, ystart, font_head, "Used");
3858 ystart += ystep_head;
3861 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3863 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3864 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3865 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3866 ystart += ystep_line;
3869 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3871 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3872 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3873 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3874 ystart += ystep_line;
3877 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3879 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3880 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3881 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3883 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3885 PlayInfoSoundsAndMusic();
3887 FadeIn(REDRAW_FIELD);
3890 void HandleInfoScreen_Version(int button)
3892 if (button == MB_MENU_LEAVE)
3894 PlaySound(SND_MENU_ITEM_SELECTING);
3896 info_mode = INFO_MODE_MAIN;
3901 else if (button == MB_MENU_CHOICE)
3903 PlaySound(SND_MENU_ITEM_SELECTING);
3905 FadeMenuSoundsAndMusic();
3907 info_mode = INFO_MODE_MAIN;
3912 PlayMenuSoundIfLoop();
3916 static char *getInfoScreenTitle_Generic(void)
3918 return (info_mode == INFO_MODE_MAIN ? STR_INFO_MAIN :
3919 info_mode == INFO_MODE_TITLE ? STR_INFO_TITLE :
3920 info_mode == INFO_MODE_ELEMENTS ? STR_INFO_ELEMENTS :
3921 info_mode == INFO_MODE_MUSIC ? STR_INFO_MUSIC :
3922 info_mode == INFO_MODE_CREDITS ? STR_INFO_CREDITS :
3923 info_mode == INFO_MODE_PROGRAM ? STR_INFO_PROGRAM :
3924 info_mode == INFO_MODE_VERSION ? STR_INFO_VERSION :
3925 info_mode == INFO_MODE_LEVELSET ? STR_INFO_LEVELSET :
3929 static int getInfoScreenBackgroundImage_Generic(void)
3931 return (info_mode == INFO_MODE_ELEMENTS ? IMG_BACKGROUND_INFO_ELEMENTS :
3932 info_mode == INFO_MODE_MUSIC ? IMG_BACKGROUND_INFO_MUSIC :
3933 info_mode == INFO_MODE_CREDITS ? IMG_BACKGROUND_INFO_CREDITS :
3934 info_mode == INFO_MODE_PROGRAM ? IMG_BACKGROUND_INFO_PROGRAM :
3935 info_mode == INFO_MODE_VERSION ? IMG_BACKGROUND_INFO_VERSION :
3936 info_mode == INFO_MODE_LEVELSET ? IMG_BACKGROUND_INFO_LEVELSET :
3937 IMG_BACKGROUND_INFO);
3940 static int getInfoScreenBackgroundSound_Generic(void)
3942 return (info_mode == INFO_MODE_ELEMENTS ? SND_BACKGROUND_INFO_ELEMENTS :
3943 info_mode == INFO_MODE_CREDITS ? SND_BACKGROUND_INFO_CREDITS :
3944 info_mode == INFO_MODE_PROGRAM ? SND_BACKGROUND_INFO_PROGRAM :
3945 info_mode == INFO_MODE_VERSION ? SND_BACKGROUND_INFO_VERSION :
3946 info_mode == INFO_MODE_LEVELSET ? SND_BACKGROUND_INFO_LEVELSET :
3947 SND_BACKGROUND_INFO);
3950 static int getInfoScreenBackgroundMusic_Generic(void)
3952 return (info_mode == INFO_MODE_ELEMENTS ? MUS_BACKGROUND_INFO_ELEMENTS :
3953 info_mode == INFO_MODE_CREDITS ? MUS_BACKGROUND_INFO_CREDITS :
3954 info_mode == INFO_MODE_PROGRAM ? MUS_BACKGROUND_INFO_PROGRAM :
3955 info_mode == INFO_MODE_VERSION ? MUS_BACKGROUND_INFO_VERSION :
3956 info_mode == INFO_MODE_LEVELSET ? MUS_BACKGROUND_INFO_LEVELSET :
3957 MUS_BACKGROUND_INFO);
3960 static char *getInfoScreenFilename_Generic(int nr, boolean global)
3962 return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) :
3963 info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) :
3964 info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) :
3968 static void DrawInfoScreen_GenericScreen(int screen_nr, int num_screens,
3969 int use_global_screens)
3971 char *filename = getInfoScreenFilename_Generic(screen_nr, use_global_screens);
3972 int font_text = MENU_INFO_FONT_TEXT;
3973 int font_foot = MENU_INFO_FONT_FOOT;
3974 int spacing_line = menu.line_spacing_info[info_mode];
3975 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3979 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3981 if (info_mode == INFO_MODE_CREDITS ||
3982 info_mode == INFO_MODE_PROGRAM)
3985 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART;
3986 int chars = width / getFontWidth(font_text);
3987 int lines = height / getFontHeight(font_text);
3988 int padx = (width - chars * getFontWidth(font_text)) / 2;
3989 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3990 int xstart = mSX + padx;
3991 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3992 boolean autowrap = FALSE;
3993 boolean centered = TRUE;
3994 boolean parse_comments = TRUE;
3996 DrawTextFile(xstart, ystart,
3997 filename, font_text, chars, -1, lines, line_spacing, -1,
3998 autowrap, centered, parse_comments);
4000 else if (info_mode == INFO_MODE_LEVELSET)
4002 struct TitleMessageInfo *tmi = &readme;
4004 // if x position set to "-1", automatically determine by playfield width
4006 tmi->x = SXSIZE / 2;
4008 // if y position set to "-1", use static default value
4010 tmi->y = MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
4012 // if width set to "-1", automatically determine by playfield width
4013 if (tmi->width == -1)
4014 tmi->width = SXSIZE - 2 * TILEX;
4016 // if height set to "-1", automatically determine by playfield height
4017 if (tmi->height == -1)
4018 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
4020 // if chars set to "-1", automatically determine by text and font width
4021 if (tmi->chars == -1)
4022 tmi->chars = tmi->width / getFontWidth(tmi->font);
4024 tmi->width = tmi->chars * getFontWidth(tmi->font);
4026 // if lines set to "-1", automatically determine by text and font height
4027 if (tmi->lines == -1)
4028 tmi->lines = tmi->height / getFontHeight(tmi->font);
4030 tmi->height = tmi->lines * getFontHeight(tmi->font);
4032 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
4033 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
4034 tmi->autowrap, tmi->centered, tmi->parse_comments);
4037 boolean last_screen = (screen_nr == num_screens - 1);
4038 char *text_foot = (last_screen ? TEXT_NEXT_MENU : TEXT_NEXT_PAGE);
4040 DrawTextSCentered(ybottom, font_foot, text_foot);
4043 static void DrawInfoScreen_Generic(void)
4045 SetMainBackgroundImageIfDefined(getInfoScreenBackgroundImage_Generic());
4048 FadeInfoSoundsAndMusic();
4050 FadeOut(REDRAW_FIELD);
4052 HandleInfoScreen_Generic(0, 0, MB_MENU_INITIALIZE);
4054 PlayInfoSoundsAndMusic();
4056 FadeIn(REDRAW_FIELD);
4059 void HandleInfoScreen_Generic(int dx, int dy, int button)
4061 static char *text_no_info = "";
4062 static int num_screens = 0;
4063 static int screen_nr = 0;
4064 static boolean use_global_screens = FALSE;
4066 if (button == MB_MENU_INITIALIZE)
4071 if (info_mode == INFO_MODE_CREDITS)
4075 for (i = 0; i < 2; i++)
4077 use_global_screens = i; // check for "FALSE", then "TRUE"
4079 // determine number of (global or level set specific) credits screens
4080 while (getCreditsFilename(num_screens, use_global_screens) != NULL)
4083 if (num_screens > 0)
4087 text_no_info = "No credits available.";
4089 else if (info_mode == INFO_MODE_PROGRAM)
4091 use_global_screens = TRUE;
4093 // determine number of program info screens
4094 while (getProgramInfoFilename(num_screens) != NULL)
4097 text_no_info = "No program info available.";
4099 else if (info_mode == INFO_MODE_LEVELSET)
4101 use_global_screens = FALSE;
4103 // determine number of levelset info screens
4104 while (getLevelSetInfoFilename(num_screens) != NULL)
4107 text_no_info = "No level set info available.";
4110 if (num_screens == 0)
4112 int font_title = MENU_INFO_FONT_TITLE;
4113 int font_foot = MENU_INFO_FONT_FOOT;
4114 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
4115 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4119 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
4121 DrawTextSCentered(ystart, font_title, text_no_info);
4122 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
4127 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4129 else if (button == MB_MENU_LEAVE)
4131 PlaySound(SND_MENU_ITEM_SELECTING);
4133 info_mode = INFO_MODE_MAIN;
4136 else if (button == MB_MENU_CHOICE || dx)
4138 PlaySound(SND_MENU_ITEM_SELECTING);
4140 screen_nr += (dx < 0 ? -1 : +1);
4142 if (screen_nr < 0 || screen_nr >= num_screens)
4144 FadeInfoSoundsAndMusic();
4146 info_mode = INFO_MODE_MAIN;
4151 FadeSetNextScreen();
4153 FadeOut(REDRAW_FIELD);
4155 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4157 FadeIn(REDRAW_FIELD);
4162 PlayInfoSoundIfLoop();
4166 static void DrawInfoScreen(void)
4168 if (info_mode == INFO_MODE_TITLE)
4169 DrawInfoScreen_TitleScreen();
4170 else if (info_mode == INFO_MODE_ELEMENTS)
4171 DrawInfoScreen_Elements();
4172 else if (info_mode == INFO_MODE_MUSIC)
4173 DrawInfoScreen_Music();
4174 else if (info_mode == INFO_MODE_CREDITS)
4175 DrawInfoScreen_Generic();
4176 else if (info_mode == INFO_MODE_PROGRAM)
4177 DrawInfoScreen_Generic();
4178 else if (info_mode == INFO_MODE_VERSION)
4179 DrawInfoScreen_Version();
4180 else if (info_mode == INFO_MODE_LEVELSET)
4181 DrawInfoScreen_Generic();
4183 DrawInfoScreen_Main();
4186 void DrawInfoScreen_FromMainMenu(int nr)
4188 int fade_mask = REDRAW_FIELD;
4190 if (nr < INFO_MODE_MAIN || nr >= MAX_INFO_MODES)
4193 CloseDoor(DOOR_CLOSE_2);
4195 SetGameStatus(GAME_MODE_INFO);
4198 info_screens_from_main = TRUE;
4200 if (redraw_mask & REDRAW_ALL)
4201 fade_mask = REDRAW_ALL;
4204 fade_mask = REDRAW_ALL;
4207 FadeMenuSoundsAndMusic();
4209 FadeSetEnterScreen();
4213 FadeSkipNextFadeOut();
4215 // needed if different viewport properties defined for info screen
4216 ChangeViewportPropertiesIfNeeded();
4218 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
4223 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4225 if (info_mode == INFO_MODE_TITLE)
4226 HandleInfoScreen_TitleScreen(dx, dy, button);
4227 else if (info_mode == INFO_MODE_ELEMENTS)
4228 HandleInfoScreen_Elements(dx, dy, button);
4229 else if (info_mode == INFO_MODE_MUSIC)
4230 HandleInfoScreen_Music(dx, dy, button);
4231 else if (info_mode == INFO_MODE_CREDITS)
4232 HandleInfoScreen_Generic(dx, dy, button);
4233 else if (info_mode == INFO_MODE_PROGRAM)
4234 HandleInfoScreen_Generic(dx, dy, button);
4235 else if (info_mode == INFO_MODE_VERSION)
4236 HandleInfoScreen_Version(button);
4237 else if (info_mode == INFO_MODE_LEVELSET)
4238 HandleInfoScreen_Generic(dx, dy, button);
4240 HandleInfoScreen_Main(mx, my, dx, dy, button);
4244 // ============================================================================
4245 // type name functions
4246 // ============================================================================
4248 static TreeInfo *type_name_node = NULL;
4249 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4250 static int type_name_nr = 0;
4252 static int getPlayerNameColor(char *name)
4254 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4257 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4260 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4261 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4262 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4263 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4264 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4265 int font_width = getFontWidth(font_nr);
4266 int font_xoffset = getFontDrawOffsetX(font_nr);
4267 int font_yoffset = getFontDrawOffsetY(font_nr);
4268 int font_sx = sx + font_xoffset;
4269 int font_sy = sy + font_yoffset;
4271 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4273 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4275 pos->width = strlen(text) * font_width;
4276 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4278 DrawText(sx, sy, text, font_nr);
4281 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4283 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4285 *pos = *mci->pos_input;
4287 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4289 TreeInfo *ti = player_name_current;
4290 int first_entry = ti->cl_first;
4291 int entry_pos = first_entry + ti->cl_cursor;
4292 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4293 int xpos = MENU_SCREEN_START_XPOS;
4294 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4296 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4297 type_name_nr = entry_pos;
4299 strcpy(name, type_name_node->name);
4303 pos->width = MAX_PLAYER_NAME_LEN * 32;
4307 type_name_nr = user.nr;
4309 strcpy(name, setup.player_name);
4312 strcpy(type_name_last, name);
4314 if (strEqual(name, EMPTY_PLAYER_NAME))
4317 *xpos = strlen(name);
4320 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4322 // change name of edited user in global list of user names
4323 setString(&global.user_names[type_name_nr], name);
4325 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4327 TreeInfo *node = type_name_node;
4329 // change name of edited user in local menu tree structure
4330 setString(&node->name, name);
4331 setString(&node->name_sorting, name);
4333 node->color = getPlayerNameColor(name);
4334 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4338 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4341 boolean reset_setup = strEqual(name, "");
4342 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4343 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4346 strcpy(name, type_name_last);
4348 if (strEqual(name, ""))
4349 strcpy(name, EMPTY_PLAYER_NAME);
4351 setTypeNameValues_Name(name, pos);
4353 // if player name not changed, no further action required
4354 if (strEqual(name, type_name_last))
4357 // redraw player name before (possibly) opening request dialogs
4358 drawTypeNameText(name, pos, FALSE);
4360 int last_user_nr = user.nr;
4362 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4364 // save setup of currently active user (may differ from edited user)
4367 // temporarily change active user to edited user
4368 user.nr = type_name_nr;
4371 Request("Use current setup values for the new player?", REQ_ASK))
4373 // use current setup values for new user, but create new player UUID
4374 setup.player_uuid = getStringCopy(getUUID());
4378 // load setup for existing user (or start with defaults for new user)
4383 char *setup_filename = getSetupFilename();
4384 boolean setup_exists = fileExists(setup_filename);
4386 // change name of edited user in setup structure
4387 strcpy(setup.player_name, name);
4389 // save setup of edited user
4392 // change name of edited user on score server
4393 ApiRenamePlayerAsThread();
4395 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4399 if (Request("Reset setup values for this player?", REQ_ASK))
4401 // remove setup config file
4402 unlink(setup_filename);
4404 // set player name to default player name
4407 // update player name used by name typing functions
4408 strcpy(name, setup.player_name);
4410 setTypeNameValues_Name(name, pos);
4413 else if (remove_user && type_name_nr != 0)
4415 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4417 char *user_dir = getUserGameDataDir();
4418 char *user_dir_removed =
4419 getStringCat3WithSeparator(user_dir, "REMOVED",
4420 getCurrentTimestamp(), ".");
4422 if (rename(user_dir, user_dir_removed) != 0)
4423 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4425 checked_free(user_dir_removed);
4428 else if (create_user && type_name_nr != 0 && !setup_exists)
4430 if (Request("Create empty level set for the new player?", REQ_ASK))
4432 char *levelset_subdir = getNewUserLevelSubdir();
4434 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4436 AddUserLevelSetToLevelInfo(levelset_subdir);
4438 LevelDirTree *leveldir_current_last = leveldir_current;
4440 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4443 // set level number of newly created level set to default value
4444 LoadLevelSetup_SeriesInfo();
4446 // set newly created level set as current level set for new user
4447 SaveLevelSetup_LastSeries();
4448 SaveLevelSetup_SeriesInfo();
4450 leveldir_current = leveldir_current_last;
4454 Request("Creating new level set failed!", REQ_CONFIRM);
4459 // restore currently active user
4460 user.nr = last_user_nr;
4462 // restore setup of currently active user
4465 // restore last level set of currently active user
4466 LoadLevelSetup_LastSeries();
4467 LoadLevelSetup_SeriesInfo();
4471 static void HandleTypeNameExt(boolean initialize, Key key)
4473 static struct TextPosInfo pos_name = { 0 };
4474 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4475 static int xpos = 0;
4476 struct TextPosInfo *pos = &pos_name;
4477 char key_char = getValidConfigValueChar(getCharFromKey(key));
4478 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4479 boolean active = TRUE;
4483 getTypeNameValues(name, pos, &xpos);
4485 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4486 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4488 StartTextInput(sx, sy, pos->width, pos->height);
4490 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4492 name[xpos] = key_char;
4497 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4503 else if (key == KSYM_Return || key == KSYM_Escape)
4505 boolean changed = (key == KSYM_Return);
4509 setTypeNameValues(name, pos, changed);
4514 drawTypeNameText(name, pos, active);
4518 SetGameStatus(game_status_last_screen);
4520 if (game_status == GAME_MODE_MAIN)
4521 InitializeMainControls();
4525 static void DrawTypeName(void)
4527 HandleTypeNameExt(TRUE, 0);
4530 void HandleTypeName(Key key)
4532 HandleTypeNameExt(FALSE, key);
4536 // ============================================================================
4537 // tree menu functions
4538 // ============================================================================
4540 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4542 if (game_status != GAME_MODE_SETUP ||
4543 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4546 int max_text_size = 0;
4549 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4550 max_text_size = MAX(max_text_size, strlen(node->name));
4552 int num_entries = numTreeInfoInGroup(ti);
4553 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4554 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4555 int text_width = max_text_size * getFontWidth(font_nr);
4556 int button_width = SC_MENUBUTTON_XSIZE;
4557 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4558 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4559 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4560 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4561 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4562 int align_xoffset = MAX(0, align_xoffset_raw);
4564 return align_xoffset;
4567 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4569 if (game_status != GAME_MODE_SETUP ||
4570 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4573 int num_entries = numTreeInfoInGroup(ti);
4574 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4575 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4576 int font_height = getFontHeight(font_nr);
4577 int text_height = font_height * num_page_entries;
4578 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4579 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4580 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4581 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4582 int align_yoffset = MAX(0, align_yoffset_raw);
4584 return align_yoffset;
4587 static void StartPlayingFromHallOfFame(void)
4589 level_nr = scores.next_level_nr;
4590 LoadLevel(level_nr);
4592 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4595 static void DrawChooseTree(TreeInfo **ti_ptr)
4597 int fade_mask = REDRAW_FIELD;
4598 boolean restart_music = (game_status != game_status_last_screen &&
4599 game_status_last_screen != GAME_MODE_SCOREINFO);
4601 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4602 game_status_last_screen == GAME_MODE_PLAYING);
4605 fade_mask = REDRAW_ALL;
4607 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4609 if (game_status == GAME_MODE_SETUP)
4613 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4615 StartPlayingFromHallOfFame();
4619 SetGameStatus(GAME_MODE_MAIN);
4629 FreeScreenGadgets();
4630 CreateScreenGadgets();
4633 FadeMenuSoundsAndMusic();
4637 // needed if different viewport properties defined for this screen
4638 ChangeViewportPropertiesIfNeeded();
4640 if (game_status == GAME_MODE_NAMES)
4641 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4642 else if (game_status == GAME_MODE_LEVELNR)
4643 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4644 else if (game_status == GAME_MODE_LEVELS)
4645 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4646 else if (game_status == GAME_MODE_SCORES)
4647 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4651 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4653 // map gadgets for high score screen
4654 if (game_status == GAME_MODE_SCORES)
4655 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4657 MapScreenTreeGadgets(*ti_ptr);
4659 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4661 DrawMaskedBorder(fade_mask);
4664 PlayMenuSoundsAndMusic();
4669 static int getChooseTreeFont(TreeInfo *node, boolean active)
4671 if (game_status == GAME_MODE_SCORES)
4672 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4674 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4677 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4679 int num_entries = numTreeInfoInGroup(ti);
4680 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4681 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4682 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4683 int first_entry = ti->cl_first;
4684 int entry_pos = first_entry + y;
4685 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4686 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4687 int font_nr = getChooseTreeFont(node, active);
4688 int font_xoffset = getFontDrawOffsetX(font_nr);
4689 int xpos = MENU_SCREEN_START_XPOS;
4690 int ypos = MENU_SCREEN_START_YPOS + y;
4691 int startdx = xpos * 32;
4692 int startdy = ypos * 32;
4693 int startx = amSX + startdx;
4694 int starty = amSY + startdy;
4695 int startx_text = startx + font_xoffset;
4696 int endx_text = amSX + screen_width;
4697 int max_text_size = endx_text - startx_text;
4698 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4699 char buffer[max_buffer_len + 1];
4701 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4703 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4704 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4705 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4706 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4707 int font_size_1 = getFontWidth(font_nr1);
4708 int font_size_3 = getFontWidth(font_nr3);
4709 int font_size_4 = getFontWidth(font_nr4);
4710 int text_size_1 = 4 * font_size_1;
4711 int text_size_4 = 5 * font_size_4;
4712 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4714 int dx3 = text_size_1;
4715 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4716 int num_dots = (dx4 - dx3) / font_size_3;
4717 int startx1 = startx + dx1;
4718 int startx3 = startx + dx3;
4719 int startx4 = startx + dx4;
4720 int pos = node->pos;
4721 char *pos_text = getHallOfFameRankText(pos, 3);
4724 DrawText(startx1, starty, pos_text, font_nr1);
4726 for (i = 0; i < num_dots; i++)
4727 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4729 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4730 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4732 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4736 strncpy(buffer, node->name, max_buffer_len);
4737 buffer[max_buffer_len] = '\0';
4739 DrawText(startx, starty, buffer, font_nr);
4743 static void drawChooseTreeHeadExt(int type, char *title_string)
4745 int yoffset_sets = MENU_TITLE1_YPOS;
4746 int yoffset_setup = 16;
4747 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4748 type == TREE_TYPE_LEVEL_DIR ||
4749 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4751 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4754 static void drawChooseTreeHead(TreeInfo *ti)
4756 drawChooseTreeHeadExt(ti->type, ti->infotext);
4759 static void drawChooseTreeList(TreeInfo *ti)
4761 int first_entry = ti->cl_first;
4762 int num_entries = numTreeInfoInGroup(ti);
4763 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4766 clearMenuListArea();
4768 for (i = 0; i < num_page_entries; i++)
4770 TreeInfo *node, *node_first;
4771 int entry_pos = first_entry + i;
4773 node_first = getTreeInfoFirstGroupEntry(ti);
4774 node = getTreeInfoFromPos(node_first, entry_pos);
4776 drawChooseTreeText(ti, i, FALSE);
4778 if (node->parent_link)
4779 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4780 else if (node->level_group)
4781 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4783 initCursor(i, IMG_MENU_BUTTON);
4785 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4786 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4788 if (game_status == GAME_MODE_NAMES)
4789 drawChooseTreeEdit(i, FALSE);
4792 redraw_mask |= REDRAW_FIELD;
4795 static void drawChooseTreeInfo(TreeInfo *ti)
4797 int entry_pos = ti->cl_first + ti->cl_cursor;
4798 int last_redraw_mask = redraw_mask;
4799 int ypos = MENU_TITLE2_YPOS;
4800 int font_nr = FONT_TITLE_2;
4803 if (ti->type == TREE_TYPE_LEVEL_NR)
4804 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4806 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4807 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4808 scores.last_level_nr);
4810 if (ti->type != TREE_TYPE_LEVEL_DIR)
4813 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4814 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4816 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4818 if (node->parent_link)
4819 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4820 node->node_parent->name);
4821 else if (node->level_group)
4822 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4824 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4825 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4826 node->levels, (node->levels > 1 ? "levels" : "level"),
4829 // let BackToFront() redraw only what is needed
4830 redraw_mask = last_redraw_mask;
4831 for (x = 0; x < SCR_FIELDX; x++)
4832 MarkTileDirty(x, 1);
4835 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4837 drawChooseTreeCursor(ti->cl_cursor, active);
4838 drawChooseTreeText(ti, ti->cl_cursor, active);
4841 static void drawChooseTreeScreen(TreeInfo *ti)
4843 drawChooseTreeHead(ti);
4844 drawChooseTreeList(ti);
4845 drawChooseTreeInfo(ti);
4846 drawChooseTreeCursorAndText(ti, TRUE);
4848 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4850 // scroll bar and buttons may just have been added after reloading scores
4851 if (game_status == GAME_MODE_SCORES)
4852 MapScreenTreeGadgets(ti);
4855 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4857 int score_pos = scores.last_added;
4859 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4860 score_pos = scores.last_entry_nr;
4862 // set current tree entry to last added score entry
4863 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4865 // if that fails, set current tree entry to first entry (back link)
4866 if (*ti_ptr == NULL)
4867 *ti_ptr = score_entries->node_group;
4869 int num_entries = numTreeInfoInGroup(*ti_ptr);
4870 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4871 int pos_score = getPosFromTreeInfo(*ti_ptr);
4872 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4873 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4875 (*ti_ptr)->cl_first = pos_first;
4876 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4881 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4884 TreeInfo *ti = *ti_ptr;
4885 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4886 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4887 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4888 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4889 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4891 int y = (ti != NULL ? ti->cl_cursor : 0);
4892 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4893 int num_entries = numTreeInfoInGroup(ti);
4894 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4895 boolean position_set_by_scrollbar = (dx == 999);
4897 if (game_status == GAME_MODE_SCORES)
4899 if (server_scores.updated)
4901 // reload scores, using updated server score cache file
4902 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4904 server_scores.updated = FALSE;
4906 DrawHallOfFame_setScoreEntries();
4908 ti = setHallOfFameActiveEntry(ti_ptr);
4910 if (button != MB_MENU_INITIALIZE)
4911 drawChooseTreeScreen(ti);
4915 if (button == MB_MENU_INITIALIZE)
4917 int num_entries = numTreeInfoInGroup(ti);
4918 int entry_pos = getPosFromTreeInfo(ti);
4920 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4921 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4923 if (game_status == GAME_MODE_SCORES)
4925 ti = setHallOfFameActiveEntry(ti_ptr);
4927 else if (ti->cl_first == -1)
4929 // only on initialization
4930 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4931 ti->cl_cursor = entry_pos - ti->cl_first;
4934 else if (ti->cl_cursor >= num_page_entries ||
4935 (num_entries > num_page_entries &&
4936 num_entries - ti->cl_first < num_page_entries))
4938 // only after change of list size (by custom graphic configuration)
4939 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4940 ti->cl_cursor = entry_pos - ti->cl_first;
4943 if (position_set_by_scrollbar)
4946 drawChooseTreeScreen(ti);
4950 else if (button == MB_MENU_LEAVE)
4952 if (game_status != GAME_MODE_SCORES)
4955 PlaySound(SND_MENU_ITEM_SELECTING);
4957 if (ti->node_parent)
4959 *ti_ptr = ti->node_parent;
4960 DrawChooseTree(ti_ptr);
4962 else if (game_status == GAME_MODE_SETUP)
4964 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4965 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4966 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4967 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4969 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4970 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4971 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4972 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4973 execSetupGraphics();
4974 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4975 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4976 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4978 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4979 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4980 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4981 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4982 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4983 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4984 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4985 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4992 if (game_status == GAME_MODE_LEVELNR)
4994 int new_level_nr = atoi(level_number_current->identifier);
4996 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4999 SetGameStatus(GAME_MODE_MAIN);
5007 #if defined(PLATFORM_ANDROID)
5008 // directly continue when touching the screen after playing
5009 if ((mx || my) && scores.continue_on_return)
5011 // ignore touch events until released
5016 // any mouse click or cursor key stops leaving scores by "Return" key
5017 if ((mx || my || dx || dy) && scores.continue_on_return)
5019 scores.continue_on_return = FALSE;
5020 level_nr = scores.last_level_nr;
5021 LoadLevel(level_nr);
5024 if (mx || my) // mouse input
5026 x = (mx - amSX) / 32;
5027 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
5029 if (game_status == GAME_MODE_NAMES)
5030 drawChooseTreeEdit(ti->cl_cursor, FALSE);
5032 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
5034 // move cursor instead of scrolling when already at start/end of list
5035 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
5037 else if (dy == +1 * SCROLL_LINE &&
5038 ti->cl_first + num_page_entries == num_entries)
5041 // handle scrolling screen one line or page
5042 if (ti->cl_cursor + dy < 0 ||
5043 ti->cl_cursor + dy > num_page_entries - 1)
5045 boolean redraw = FALSE;
5047 if (ABS(dy) == SCROLL_PAGE)
5048 step = num_page_entries - 1;
5050 if (dy < 0 && ti->cl_first > 0)
5052 // scroll page/line up
5054 ti->cl_first -= step;
5055 if (ti->cl_first < 0)
5060 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
5062 // scroll page/line down
5064 ti->cl_first += step;
5065 if (ti->cl_first + num_page_entries > num_entries)
5066 ti->cl_first = MAX(0, num_entries - num_page_entries);
5072 drawChooseTreeScreen(ti);
5077 // handle moving cursor one line
5078 y = ti->cl_cursor + dy;
5081 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5083 HandleHallOfFame_SelectLevel(1, dx);
5089 TreeInfo *node_first, *node_cursor;
5090 int entry_pos = ti->cl_first + y;
5092 node_first = getTreeInfoFirstGroupEntry(ti);
5093 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5095 if (node_cursor->node_group)
5099 PlaySound(SND_MENU_ITEM_SELECTING);
5101 node_cursor->cl_first = ti->cl_first;
5102 node_cursor->cl_cursor = ti->cl_cursor;
5104 *ti_ptr = node_cursor->node_group;
5105 DrawChooseTree(ti_ptr);
5110 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
5112 if (game_status != GAME_MODE_SCORES)
5115 PlaySound(SND_MENU_ITEM_SELECTING);
5117 *ti_ptr = ti->node_parent;
5118 DrawChooseTree(ti_ptr);
5123 if (!anyScrollbarGadgetActive() &&
5124 IN_VIS_MENU(x, y) &&
5125 mx < mx_right_border &&
5126 y >= 0 && y < num_page_entries)
5130 if (game_status == GAME_MODE_NAMES)
5132 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5133 drawChooseTreeEdit(y, TRUE);
5136 if (y != ti->cl_cursor)
5138 PlaySound(SND_MENU_ITEM_ACTIVATING);
5140 drawChooseTreeCursorAndText(ti, FALSE);
5144 drawChooseTreeCursorAndText(ti, TRUE);
5146 drawChooseTreeInfo(ti);
5150 if (game_status == GAME_MODE_SETUP)
5152 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5153 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5154 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5155 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5157 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5158 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5159 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5160 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5161 execSetupGraphics();
5162 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5163 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5164 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5166 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5167 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5168 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5169 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5170 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5171 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5172 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5173 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5182 TreeInfo *node_first, *node_cursor;
5183 int entry_pos = ti->cl_first + y;
5185 PlaySound(SND_MENU_ITEM_SELECTING);
5187 node_first = getTreeInfoFirstGroupEntry(ti);
5188 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5190 if (node_cursor->node_group)
5194 node_cursor->cl_first = ti->cl_first;
5195 node_cursor->cl_cursor = ti->cl_cursor;
5197 *ti_ptr = node_cursor->node_group;
5198 DrawChooseTree(ti_ptr);
5200 else if (node_cursor->parent_link)
5202 if (game_status != GAME_MODE_SCORES)
5205 *ti_ptr = node_cursor->node_parent;
5206 DrawChooseTree(ti_ptr);
5210 if (game_status != GAME_MODE_SCORES)
5213 node_cursor->cl_first = ti->cl_first;
5214 node_cursor->cl_cursor = ti->cl_cursor;
5216 *ti_ptr = node_cursor;
5218 if (ti->type == TREE_TYPE_LEVEL_DIR)
5220 LoadLevelSetup_SeriesInfo();
5222 SaveLevelSetup_LastSeries();
5223 SaveLevelSetup_SeriesInfo();
5227 if (game_status == GAME_MODE_SETUP)
5229 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5230 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5231 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5232 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5234 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5235 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5236 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5237 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5238 execSetupGraphics();
5239 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5240 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5241 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5243 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5244 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5245 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5246 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5247 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5248 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5249 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5250 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5257 if (game_status == GAME_MODE_LEVELNR)
5259 int new_level_nr = atoi(level_number_current->identifier);
5261 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5263 else if (game_status == GAME_MODE_LEVELS)
5265 // store level set if chosen from "last played level set" menu
5266 StoreLastPlayedLevels(leveldir_current);
5268 // store if level set chosen from "last played level set" menu
5269 SaveLevelSetup_LastSeries();
5271 else if (game_status == GAME_MODE_NAMES)
5273 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5275 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5282 // change active user to selected user
5283 user.nr = entry_pos;
5285 // save number of new active user
5288 // load setup of new active user
5291 // load last level set of new active user
5292 LoadLevelSetup_LastSeries();
5293 LoadLevelSetup_SeriesInfo();
5295 // update list of last played level sets
5296 UpdateLastPlayedLevels_TreeInfo();
5300 ToggleFullscreenIfNeeded();
5301 ChangeWindowScalingIfNeeded();
5303 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5304 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5305 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5307 else if (game_status == GAME_MODE_SCORES)
5309 if (scores.continue_playing && scores.continue_on_return)
5311 StartPlayingFromHallOfFame();
5315 else if (!scores.continue_on_return)
5317 SetGameStatus(GAME_MODE_SCOREINFO);
5319 DrawScoreInfo(node_cursor->pos);
5325 SetGameStatus(GAME_MODE_MAIN);
5333 if (game_status == GAME_MODE_SCORES)
5334 PlayMenuSoundIfLoop();
5337 void DrawChoosePlayerName(void)
5341 if (player_name != NULL)
5343 freeTreeInfo(player_name);
5348 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5350 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5351 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5354 ti->node_top = &player_name;
5355 ti->sort_priority = 10000 + value;
5356 ti->color = getPlayerNameColor(global.user_names[i]);
5358 snprintf(identifier, sizeof(identifier), "%d", value);
5359 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5361 setString(&ti->identifier, identifier);
5362 setString(&ti->name, name);
5363 setString(&ti->name_sorting, name);
5365 pushTreeInfo(&player_name, ti);
5368 // sort player entries by player number
5369 sortTreeInfo(&player_name);
5371 // set current player entry to selected player entry
5372 player_name_current =
5373 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5375 // if that fails, set current player name to first available name
5376 if (player_name_current == NULL)
5377 player_name_current = player_name;
5379 // set text size for main name input (also used on name selection screen)
5380 InitializeMainControls();
5382 DrawChooseTree(&player_name_current);
5385 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5387 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5390 void DrawChooseLevelSet(void)
5392 DrawChooseTree(&leveldir_current);
5395 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5397 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5400 void DrawChooseLevelNr(void)
5404 if (level_number != NULL)
5406 freeTreeInfo(level_number);
5408 level_number = NULL;
5411 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5413 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5414 char identifier[32], name[64];
5417 // temporarily load level info to get level name
5418 LoadLevelInfoOnly(i);
5420 ti->node_top = &level_number;
5421 ti->sort_priority = 10000 + value;
5422 ti->color = (level.no_level_file ? FC_BLUE :
5423 LevelStats_getSolved(i) ? FC_GREEN :
5424 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5426 snprintf(identifier, sizeof(identifier), "%d", value);
5427 snprintf(name, sizeof(name), "%03d: %s", value,
5428 (level.no_level_file ? "(no file)" : level.name));
5430 setString(&ti->identifier, identifier);
5431 setString(&ti->name, name);
5432 setString(&ti->name_sorting, name);
5434 pushTreeInfo(&level_number, ti);
5437 // sort level number values to start with lowest level number
5438 sortTreeInfo(&level_number);
5440 // set current level number to current level number
5441 level_number_current =
5442 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5444 // if that also fails, set current level number to first available level
5445 if (level_number_current == NULL)
5446 level_number_current = level_number;
5448 DrawChooseTree(&level_number_current);
5451 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5453 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5456 static void DrawHallOfFame_setScoreEntries(void)
5458 int max_empty_entries = 10; // at least show "top ten" list, if empty
5459 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5460 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5461 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5464 if (score_entries != NULL)
5466 freeTreeInfo(score_entries);
5468 score_entries = NULL;
5471 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5473 // do not add empty score entries if off-screen
5474 if (scores.entry[i].score == 0 &&
5475 scores.entry[i].time == 0 &&
5476 i >= min_score_entries)
5479 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5480 char identifier[32], name[64];
5483 ti->node_top = &score_entries;
5484 ti->sort_priority = 10000 + value;
5485 ti->color = FC_YELLOW;
5488 snprintf(identifier, sizeof(identifier), "%d", value);
5489 snprintf(name, sizeof(name), "%03d.", value + 1);
5491 setString(&ti->identifier, identifier);
5492 setString(&ti->name, name);
5493 setString(&ti->name_sorting, name);
5495 pushTreeInfo(&score_entries, ti);
5498 // sort score entries to start with highest score entry
5499 sortTreeInfo(&score_entries);
5501 // add top tree node to create back link to main menu
5502 score_entries = addTopTreeInfoNode(score_entries);
5504 // set current score entry to last added or highest score entry
5505 score_entry_current =
5506 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5508 // if that fails, set current score entry to first valid score entry
5509 if (score_entry_current == NULL)
5510 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5512 if (score_entries != NULL && scores.continue_playing)
5513 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5516 void DrawHallOfFame(int nr)
5518 scores.last_level_nr = nr;
5520 // (this is needed when called from GameEnd() after winning a game)
5521 KeyboardAutoRepeatOn();
5523 // (this is needed when called from GameEnd() after winning a game)
5524 SetDrawDeactivationMask(REDRAW_NONE);
5525 SetDrawBackgroundMask(REDRAW_FIELD);
5527 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5529 DrawHallOfFame_setScoreEntries();
5531 if (scores.last_added >= 0)
5532 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5534 FadeSetEnterScreen();
5536 DrawChooseTree(&score_entry_current);
5539 static char *getHallOfFameRankText(int nr, int size)
5541 static char rank_text[10];
5542 boolean forced = (scores.force_last_added && nr == scores.last_added);
5543 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5545 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5550 static char *getHallOfFameTimeText(int nr)
5552 static char score_text[10];
5553 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5554 int mm = (time_seconds / 60) % 60;
5555 int ss = (time_seconds % 60);
5557 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5562 static char *getHallOfFameScoreText(int nr, int size)
5564 if (!level.rate_time_over_score)
5565 return int2str(scores.entry[nr].score, size); // show normal score
5566 else if (level.use_step_counter)
5567 return int2str(scores.entry[nr].time, size); // show number of steps
5569 return getHallOfFameTimeText(nr); // show playing time
5572 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5574 static char tape_date[MAX_ISO_DATE_LEN + 1];
5577 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5578 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5579 return entry->tape_date;
5581 for (i = 0, j = 0; i < 8; i++, j++)
5583 tape_date[j] = entry->tape_basename[i];
5585 if (i == 3 || i == 5)
5586 tape_date[++j] = '-';
5589 tape_date[MAX_ISO_DATE_LEN] = '\0';
5594 static void HandleHallOfFame_SelectLevel(int step, int direction)
5596 int old_level_nr = scores.last_level_nr;
5597 int new_level_nr = old_level_nr + step * direction;
5599 if (new_level_nr < leveldir_current->first_level)
5600 new_level_nr = leveldir_current->first_level;
5601 if (new_level_nr > leveldir_current->last_level)
5602 new_level_nr = leveldir_current->last_level;
5604 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5605 new_level_nr = leveldir_current->handicap_level;
5607 if (new_level_nr != old_level_nr)
5609 PlaySound(SND_MENU_ITEM_SELECTING);
5611 scores.last_level_nr = level_nr = new_level_nr;
5612 scores.last_entry_nr = 0;
5614 LoadLevel(level_nr);
5615 LoadLocalAndServerScore(level_nr, TRUE);
5617 DrawHallOfFame_setScoreEntries();
5619 if (game_status == GAME_MODE_SCORES)
5621 // force remapping optional gadgets (especially scroll bar)
5622 UnmapScreenTreeGadgets();
5624 // redraw complete high score screen, as sub-title has changed
5627 // redraw level selection buttons (which have just been erased)
5628 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5630 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5634 DrawScoreInfo_Content(scores.last_entry_nr);
5637 SaveLevelSetup_SeriesInfo();
5641 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5643 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5646 static void DrawScoreInfo_Content(int entry_nr)
5648 struct ScoreEntry *entry = &scores.entry[entry_nr];
5649 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5650 char *tape_date = getHallOfFameTapeDateText(entry);
5651 int font_head = MENU_INFO_FONT_HEAD;
5652 int font_text = MENU_INFO_FONT_TEXT;
5653 int font_foot = MENU_INFO_FONT_FOOT;
5654 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5655 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5656 int spacing_left = menu.left_spacing[GAME_MODE_SCOREINFO];
5657 int spacing_top = menu.top_spacing[GAME_MODE_SCOREINFO];
5658 int xstep = getFontWidth(font_text);
5659 int ystep_para = getMenuTextStep(spacing_para, font_text);
5660 int ystep_line = getMenuTextStep(spacing_line, font_text);
5661 int xstart = mSX - SX + spacing_left;
5662 int ystart = mSY - SY + spacing_top + getHeadlineSpacing();
5663 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5664 int xstart1 = xstart + xstep;
5665 int xstart2 = xstart + xstep * 12;
5666 int select_x = SX + xstart1;
5667 int select_y1, select_y2;
5669 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5670 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5671 int font_width = getFontWidth(font_text);
5672 int font_height = getFontHeight(font_text);
5673 int tape_date_width = getTextWidth(tape_date, font_text);
5674 int pad_left = xstart2;
5675 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5676 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5677 int max_lines_per_text = 5;
5682 // redraw level selection buttons (which have just been erased)
5683 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5685 drawChooseTreeHead(score_entries);
5686 drawChooseTreeInfo(score_entries);
5688 DrawTextF(xstart1, ystart, font_head, "Level Set");
5689 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5690 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5691 TRUE, FALSE, FALSE);
5692 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5694 DrawTextF(xstart1, ystart, font_head, "Level");
5695 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5696 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5697 TRUE, FALSE, FALSE);
5698 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5700 select_y1 = SY + ystart;
5701 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5703 DrawTextF(xstart1, ystart, font_head, "Rank");
5704 DrawTextF(xstart2, ystart, font_text, pos_text);
5705 ystart += ystep_line;
5707 DrawTextF(xstart1, ystart, font_head, "Player");
5708 DrawTextF(xstart2, ystart, font_text, entry->name);
5709 ystart += ystep_line;
5711 if (level.use_step_counter)
5713 DrawTextF(xstart1, ystart, font_head, "Steps");
5714 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5715 ystart += ystep_line;
5719 DrawTextF(xstart1, ystart, font_head, "Time");
5720 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5721 ystart += ystep_line;
5724 if (!level.rate_time_over_score || entry->score > 0)
5726 DrawTextF(xstart1, ystart, font_head, "Score");
5727 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5728 ystart += ystep_line;
5731 ystart += ystep_line;
5733 play_x = SX + xstart2 + tape_date_width + font_width;
5734 play_y = SY + ystart + (font_height - play_height) / 2;
5736 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5737 DrawTextF(xstart2, ystart, font_text, tape_date);
5738 ystart += ystep_line;
5740 DrawTextF(xstart1, ystart, font_head, "Platform");
5741 DrawTextF(xstart2, ystart, font_text, entry->platform);
5742 ystart += ystep_line;
5744 DrawTextF(xstart1, ystart, font_head, "Version");
5745 DrawTextF(xstart2, ystart, font_text, entry->version);
5746 ystart += ystep_line;
5748 DrawTextF(xstart1, ystart, font_head, "Country");
5749 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5750 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5751 TRUE, FALSE, FALSE);
5752 ystart += ystep_line;
5754 select_y2 = SY + ystart;
5756 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5758 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5759 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5762 static void DrawScoreInfo(int entry_nr)
5764 scores.last_entry_nr = entry_nr;
5765 score_info_tape_play = FALSE;
5769 FreeScreenGadgets();
5770 CreateScreenGadgets();
5772 FadeOut(REDRAW_FIELD);
5774 // needed if different viewport properties defined after playing score tape
5775 ChangeViewportPropertiesIfNeeded();
5777 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5778 SetDrawDeactivationMask(REDRAW_NONE);
5779 SetDrawBackgroundMask(REDRAW_FIELD);
5781 // needed if different background image defined after playing score tape
5782 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5783 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5785 // special compatibility handling for "Snake Bite" graphics set
5786 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5787 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5788 gfx.full_sxsize, gfx.full_sysize - 64);
5790 DrawScoreInfo_Content(entry_nr);
5792 // map gadgets for score info screen
5793 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5795 FadeIn(REDRAW_FIELD);
5798 static void HandleScoreInfo_SelectScore(int step, int direction)
5800 int old_entry_nr = scores.last_entry_nr;
5801 int new_entry_nr = old_entry_nr + step * direction;
5802 int num_nodes = numTreeInfoInGroup(score_entry_current);
5803 int num_entries = num_nodes - 1; // score nodes only, without back link
5805 if (new_entry_nr < 0)
5807 if (new_entry_nr > num_entries - 1)
5808 new_entry_nr = num_entries - 1;
5810 if (new_entry_nr != old_entry_nr)
5812 scores.last_entry_nr = new_entry_nr;
5814 DrawScoreInfo_Content(new_entry_nr);
5818 static void HandleScoreInfo_PlayTape(void)
5820 if (!PlayScoreTape(scores.last_entry_nr))
5822 DrawScoreInfo_Content(scores.last_entry_nr);
5824 FadeIn(REDRAW_FIELD);
5828 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5830 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5831 boolean button_is_valid = (mx >= 0 && my >= 0);
5832 boolean button_screen_clicked = (button_action && button_is_valid);
5834 if (server_scores.updated)
5836 // reload scores, using updated server score cache file
5837 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5839 server_scores.updated = FALSE;
5841 DrawHallOfFame_setScoreEntries();
5843 DrawScoreInfo_Content(scores.last_entry_nr);
5846 if (button_screen_clicked)
5848 PlaySound(SND_MENU_ITEM_SELECTING);
5850 SetGameStatus(GAME_MODE_SCORES);
5852 DrawHallOfFame(scores.last_level_nr);
5856 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5860 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5865 // ============================================================================
5866 // setup screen functions
5867 // ============================================================================
5869 static struct TokenInfo *setup_info;
5870 static int num_setup_info; // number of setup entries shown on screen
5871 static int max_setup_info; // total number of setup entries in list
5873 static char *window_size_text;
5874 static char *scaling_type_text;
5875 static char *rendering_mode_text;
5876 static char *vsync_mode_text;
5877 static char *scroll_delay_text;
5878 static char *snapshot_mode_text;
5879 static char *game_speed_text;
5880 static char *scores_type_text;
5881 static char *network_server_text;
5882 static char *graphics_set_name;
5883 static char *sounds_set_name;
5884 static char *music_set_name;
5885 static char *volume_simple_text;
5886 static char *volume_loops_text;
5887 static char *volume_music_text;
5888 static char *touch_controls_text;
5889 static char *move_distance_text;
5890 static char *drop_distance_text;
5891 static char *transparency_text;
5892 static char *grid_size_text[2][2];
5894 static void execSetupMain(void)
5896 setup_mode = SETUP_MODE_MAIN;
5901 static void execSetupGame_setScoresType(void)
5903 if (scores_types == NULL)
5907 for (i = 0; scores_types_list[i].value != NULL; i++)
5909 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5910 char identifier[32], name[32];
5911 char *value = scores_types_list[i].value;
5912 char *text = scores_types_list[i].text;
5914 ti->node_top = &scores_types;
5915 ti->sort_priority = i;
5917 sprintf(identifier, "%s", value);
5918 sprintf(name, "%s", text);
5920 setString(&ti->identifier, identifier);
5921 setString(&ti->name, name);
5922 setString(&ti->name_sorting, name);
5923 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5925 pushTreeInfo(&scores_types, ti);
5928 // sort scores type values to start with lowest scores type value
5929 sortTreeInfo(&scores_types);
5931 // set current scores type value to configured scores type value
5932 scores_type_current =
5933 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5935 // if that fails, set current scores type to reliable default value
5936 if (scores_type_current == NULL)
5937 scores_type_current =
5938 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5940 // if that also fails, set current scores type to first available value
5941 if (scores_type_current == NULL)
5942 scores_type_current = scores_types;
5945 setup.scores_in_highscore_list = scores_type_current->identifier;
5947 // needed for displaying scores type text instead of identifier
5948 scores_type_text = scores_type_current->name;
5951 static void execSetupGame_setGameSpeeds(boolean update_value)
5953 if (setup.game_speed_extended)
5955 game_speeds_list = game_speeds_list_extended;
5956 game_speeds = game_speeds_extended;
5960 game_speeds_list = game_speeds_list_normal;
5961 game_speeds = game_speeds_normal;
5964 if (game_speeds == NULL)
5968 for (i = 0; game_speeds_list[i].value != -1; i++)
5970 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5971 char identifier[32], name[32];
5972 int value = game_speeds_list[i].value;
5973 char *text = game_speeds_list[i].text;
5975 ti->node_top = &game_speeds;
5976 ti->sort_priority = 10000 - value;
5978 sprintf(identifier, "%d", value);
5979 sprintf(name, "%s", text);
5981 setString(&ti->identifier, identifier);
5982 setString(&ti->name, name);
5983 setString(&ti->name_sorting, name);
5984 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5986 pushTreeInfo(&game_speeds, ti);
5989 // sort game speed values to start with slowest game speed
5990 sortTreeInfo(&game_speeds);
5992 update_value = TRUE;
5997 // set current game speed to configured game speed value
5998 game_speed_current =
5999 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
6001 // if that fails, set current game speed to reliable default value
6002 if (game_speed_current == NULL)
6003 game_speed_current =
6004 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
6006 // if that also fails, set current game speed to first available speed
6007 if (game_speed_current == NULL)
6008 game_speed_current = game_speeds;
6010 if (setup.game_speed_extended)
6011 game_speeds_extended = game_speeds;
6013 game_speeds_normal = game_speeds;
6016 setup.game_frame_delay = atoi(game_speed_current->identifier);
6018 // needed for displaying game speed text instead of identifier
6019 game_speed_text = game_speed_current->name;
6022 static void execSetupGame_setScrollDelays(void)
6024 if (scroll_delays == NULL)
6028 for (i = 0; scroll_delays_list[i].value != -1; i++)
6030 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6031 char identifier[32], name[32];
6032 int value = scroll_delays_list[i].value;
6033 char *text = scroll_delays_list[i].text;
6035 ti->node_top = &scroll_delays;
6036 ti->sort_priority = value;
6038 sprintf(identifier, "%d", value);
6039 sprintf(name, "%s", text);
6041 setString(&ti->identifier, identifier);
6042 setString(&ti->name, name);
6043 setString(&ti->name_sorting, name);
6044 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
6046 pushTreeInfo(&scroll_delays, ti);
6049 // sort scroll delay values to start with lowest scroll delay value
6050 sortTreeInfo(&scroll_delays);
6052 // set current scroll delay value to configured scroll delay value
6053 scroll_delay_current =
6054 getTreeInfoFromIdentifier(scroll_delays, i_to_a(setup.scroll_delay_value));
6056 // if that fails, set current scroll delay to reliable default value
6057 if (scroll_delay_current == NULL)
6058 scroll_delay_current =
6059 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
6061 // if that also fails, set current scroll delay to first available value
6062 if (scroll_delay_current == NULL)
6063 scroll_delay_current = scroll_delays;
6066 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6068 // needed for displaying scroll delay text instead of identifier
6069 scroll_delay_text = scroll_delay_current->name;
6072 static void execSetupGame_setSnapshotModes(void)
6074 if (snapshot_modes == NULL)
6078 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6080 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6081 char identifier[32], name[32];
6082 char *value = snapshot_modes_list[i].value;
6083 char *text = snapshot_modes_list[i].text;
6085 ti->node_top = &snapshot_modes;
6086 ti->sort_priority = i;
6088 sprintf(identifier, "%s", value);
6089 sprintf(name, "%s", text);
6091 setString(&ti->identifier, identifier);
6092 setString(&ti->name, name);
6093 setString(&ti->name_sorting, name);
6094 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6096 pushTreeInfo(&snapshot_modes, ti);
6099 // sort snapshot mode values to start with lowest snapshot mode value
6100 sortTreeInfo(&snapshot_modes);
6102 // set current snapshot mode value to configured snapshot mode value
6103 snapshot_mode_current =
6104 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6106 // if that fails, set current snapshot mode to reliable default value
6107 if (snapshot_mode_current == NULL)
6108 snapshot_mode_current =
6109 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6111 // if that also fails, set current snapshot mode to first available value
6112 if (snapshot_mode_current == NULL)
6113 snapshot_mode_current = snapshot_modes;
6116 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6118 // needed for displaying snapshot mode text instead of identifier
6119 snapshot_mode_text = snapshot_mode_current->name;
6122 static void execSetupGame_setNetworkServerText(void)
6124 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6126 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6130 strncpy(network_server_hostname, setup.network_server_hostname,
6131 MAX_SETUP_TEXT_INPUT_LEN);
6132 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6135 // needed for displaying network server text instead of identifier
6136 network_server_text = network_server_hostname;
6139 static void execSetupGame(void)
6141 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6143 execSetupGame_setGameSpeeds(FALSE);
6144 execSetupGame_setScoresType();
6145 execSetupGame_setScrollDelays();
6146 execSetupGame_setSnapshotModes();
6148 execSetupGame_setNetworkServerText();
6150 if (!setup.provide_uploading_tapes)
6151 setHideSetupEntry(execOfferUploadTapes);
6153 setup_mode = SETUP_MODE_GAME;
6157 // check if vsync needs to be disabled for this game speed to work
6158 if (check_vsync_mode)
6159 DisableVsyncIfNeeded();
6162 static void execSetupChooseScoresType(void)
6164 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6169 static void execSetupChooseGameSpeed(void)
6171 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6176 static void execSetupChooseScrollDelay(void)
6178 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6183 static void execSetupChooseSnapshotMode(void)
6185 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6190 static void execSetupEngines(void)
6192 setup_mode = SETUP_MODE_ENGINES;
6197 static void execSetupEditor(void)
6199 setup_mode = SETUP_MODE_EDITOR;
6204 static void execSetupGraphics_setWindowSizes(boolean update_list)
6206 if (window_sizes != NULL && update_list)
6208 freeTreeInfo(window_sizes);
6210 window_sizes = NULL;
6213 if (window_sizes == NULL)
6215 boolean current_window_size_found = FALSE;
6218 for (i = 0; window_sizes_list[i].value != -1; i++)
6220 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6221 char identifier[32], name[32];
6222 int value = window_sizes_list[i].value;
6223 char *text = window_sizes_list[i].text;
6225 ti->node_top = &window_sizes;
6226 ti->sort_priority = value;
6228 sprintf(identifier, "%d", value);
6229 sprintf(name, "%s", text);
6231 setString(&ti->identifier, identifier);
6232 setString(&ti->name, name);
6233 setString(&ti->name_sorting, name);
6234 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6236 pushTreeInfo(&window_sizes, ti);
6238 if (value == setup.window_scaling_percent)
6239 current_window_size_found = TRUE;
6242 if (!current_window_size_found)
6244 // add entry for non-preset window scaling value
6246 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6247 char identifier[32], name[32];
6248 int value = setup.window_scaling_percent;
6250 ti->node_top = &window_sizes;
6251 ti->sort_priority = value;
6253 sprintf(identifier, "%d", value);
6254 sprintf(name, "%d %% (Current)", value);
6256 setString(&ti->identifier, identifier);
6257 setString(&ti->name, name);
6258 setString(&ti->name_sorting, name);
6259 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6261 pushTreeInfo(&window_sizes, ti);
6264 // sort window size values to start with lowest window size value
6265 sortTreeInfo(&window_sizes);
6267 // set current window size value to configured window size value
6268 window_size_current =
6269 getTreeInfoFromIdentifier(window_sizes,
6270 i_to_a(setup.window_scaling_percent));
6272 // if that fails, set current window size to reliable default value
6273 if (window_size_current == NULL)
6274 window_size_current =
6275 getTreeInfoFromIdentifier(window_sizes,
6276 i_to_a(STD_WINDOW_SCALING_PERCENT));
6278 // if that also fails, set current window size to first available value
6279 if (window_size_current == NULL)
6280 window_size_current = window_sizes;
6283 setup.window_scaling_percent = atoi(window_size_current->identifier);
6285 // needed for displaying window size text instead of identifier
6286 window_size_text = window_size_current->name;
6289 static void execSetupGraphics_setScalingTypes(void)
6291 if (scaling_types == NULL)
6295 for (i = 0; scaling_types_list[i].value != NULL; i++)
6297 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6298 char identifier[32], name[32];
6299 char *value = scaling_types_list[i].value;
6300 char *text = scaling_types_list[i].text;
6302 ti->node_top = &scaling_types;
6303 ti->sort_priority = i;
6305 sprintf(identifier, "%s", value);
6306 sprintf(name, "%s", text);
6308 setString(&ti->identifier, identifier);
6309 setString(&ti->name, name);
6310 setString(&ti->name_sorting, name);
6311 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6313 pushTreeInfo(&scaling_types, ti);
6316 // sort scaling type values to start with lowest scaling type value
6317 sortTreeInfo(&scaling_types);
6319 // set current scaling type value to configured scaling type value
6320 scaling_type_current =
6321 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6323 // if that fails, set current scaling type to reliable default value
6324 if (scaling_type_current == NULL)
6325 scaling_type_current =
6326 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6328 // if that also fails, set current scaling type to first available value
6329 if (scaling_type_current == NULL)
6330 scaling_type_current = scaling_types;
6333 setup.window_scaling_quality = scaling_type_current->identifier;
6335 // needed for displaying scaling type text instead of identifier
6336 scaling_type_text = scaling_type_current->name;
6339 static void execSetupGraphics_setRenderingModes(void)
6341 if (rendering_modes == NULL)
6345 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6347 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6348 char identifier[32], name[32];
6349 char *value = rendering_modes_list[i].value;
6350 char *text = rendering_modes_list[i].text;
6352 ti->node_top = &rendering_modes;
6353 ti->sort_priority = i;
6355 sprintf(identifier, "%s", value);
6356 sprintf(name, "%s", text);
6358 setString(&ti->identifier, identifier);
6359 setString(&ti->name, name);
6360 setString(&ti->name_sorting, name);
6361 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6363 pushTreeInfo(&rendering_modes, ti);
6366 // sort rendering mode values to start with lowest rendering mode value
6367 sortTreeInfo(&rendering_modes);
6369 // set current rendering mode value to configured rendering mode value
6370 rendering_mode_current =
6371 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6373 // if that fails, set current rendering mode to reliable default value
6374 if (rendering_mode_current == NULL)
6375 rendering_mode_current =
6376 getTreeInfoFromIdentifier(rendering_modes,
6377 STR_SPECIAL_RENDERING_DEFAULT);
6379 // if that also fails, set current rendering mode to first available one
6380 if (rendering_mode_current == NULL)
6381 rendering_mode_current = rendering_modes;
6384 setup.screen_rendering_mode = rendering_mode_current->identifier;
6386 // needed for displaying rendering mode text instead of identifier
6387 rendering_mode_text = rendering_mode_current->name;
6390 static void execSetupGraphics_setVsyncModes(boolean update_value)
6392 if (vsync_modes == NULL)
6396 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6398 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6399 char identifier[32], name[32];
6400 char *value = vsync_modes_list[i].value;
6401 char *text = vsync_modes_list[i].text;
6403 ti->node_top = &vsync_modes;
6404 ti->sort_priority = i;
6406 sprintf(identifier, "%s", value);
6407 sprintf(name, "%s", text);
6409 setString(&ti->identifier, identifier);
6410 setString(&ti->name, name);
6411 setString(&ti->name_sorting, name);
6412 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6414 pushTreeInfo(&vsync_modes, ti);
6417 // sort vsync mode values to start with lowest vsync mode value
6418 sortTreeInfo(&vsync_modes);
6420 update_value = TRUE;
6425 // set current vsync mode value to configured vsync mode value
6426 vsync_mode_current =
6427 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6429 // if that fails, set current vsync mode to reliable default value
6430 if (vsync_mode_current == NULL)
6431 vsync_mode_current =
6432 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6434 // if that also fails, set current vsync mode to first available one
6435 if (vsync_mode_current == NULL)
6436 vsync_mode_current = vsync_modes;
6439 setup.vsync_mode = vsync_mode_current->identifier;
6441 // needed for displaying vsync mode text instead of identifier
6442 vsync_mode_text = vsync_mode_current->name;
6445 static void execSetupGraphics(void)
6447 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6449 // update "setup.window_scaling_percent" from list selection
6450 // (in this case, window scaling was changed on setup screen)
6451 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6452 execSetupGraphics_setWindowSizes(FALSE);
6454 // update "setup.vsync_mode" from list selection
6455 // (in this case, vsync mode was changed on setup screen)
6456 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6457 execSetupGraphics_setVsyncModes(FALSE);
6459 // update list selection from "setup.window_scaling_percent"
6460 // (window scaling may have changed by resizing the window)
6461 execSetupGraphics_setWindowSizes(TRUE);
6463 // update list selection from "setup.vsync_mode"
6464 // (vsync_mode may have changed by re-creating the renderer)
6465 execSetupGraphics_setVsyncModes(TRUE);
6467 execSetupGraphics_setScalingTypes();
6468 execSetupGraphics_setRenderingModes();
6470 setup_mode = SETUP_MODE_GRAPHICS;
6474 // check if game speed is high enough for 60 Hz vsync to work
6475 if (check_game_speed)
6476 ModifyGameSpeedIfNeeded();
6478 // window scaling may have changed at this point
6479 ChangeWindowScalingIfNeeded();
6481 // window scaling quality may have changed at this point
6482 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6483 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6485 // screen rendering mode may have changed at this point
6486 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6488 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6489 int video_vsync_mode = video.vsync_mode;
6491 // screen vsync mode may have changed at this point
6492 ChangeVsyncModeIfNeeded();
6494 // check if setting vsync mode to selected value failed
6495 if (setup_vsync_mode != video_vsync_mode &&
6496 setup_vsync_mode != video.vsync_mode)
6498 // changing vsync mode to selected value failed -- reset displayed value
6499 execSetupGraphics_setVsyncModes(TRUE);
6501 Request("Setting VSync failed!", REQ_CONFIRM);
6507 static void execSetupChooseWindowSize(void)
6509 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6514 static void execSetupChooseScalingType(void)
6516 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6521 static void execSetupChooseRenderingMode(void)
6523 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6528 static void execSetupChooseVsyncMode(void)
6530 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6535 static void execSetupChooseVolumeSimple(void)
6537 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6542 static void execSetupChooseVolumeLoops(void)
6544 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6549 static void execSetupChooseVolumeMusic(void)
6551 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6556 static void execSetupSound(void)
6558 if (volumes_simple == NULL)
6560 boolean current_volume_simple_found = FALSE;
6563 for (i = 0; volumes_list[i].value != -1; i++)
6565 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6566 char identifier[32], name[32];
6567 int value = volumes_list[i].value;
6568 char *text = volumes_list[i].text;
6570 ti->node_top = &volumes_simple;
6571 ti->sort_priority = value;
6573 sprintf(identifier, "%d", value);
6574 sprintf(name, "%s", text);
6576 setString(&ti->identifier, identifier);
6577 setString(&ti->name, name);
6578 setString(&ti->name_sorting, name);
6579 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6581 pushTreeInfo(&volumes_simple, ti);
6583 if (value == setup.volume_simple)
6584 current_volume_simple_found = TRUE;
6587 if (!current_volume_simple_found)
6589 // add entry for non-preset volume value
6591 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6592 char identifier[32], name[32];
6593 int value = setup.volume_simple;
6595 ti->node_top = &volumes_simple;
6596 ti->sort_priority = value;
6598 sprintf(identifier, "%d", value);
6599 sprintf(name, "%d %% (Current)", value);
6601 setString(&ti->identifier, identifier);
6602 setString(&ti->name, name);
6603 setString(&ti->name_sorting, name);
6604 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6606 pushTreeInfo(&volumes_simple, ti);
6609 // sort volume values to start with lowest volume value
6610 sortTreeInfo(&volumes_simple);
6612 // set current volume value to configured volume value
6613 volume_simple_current =
6614 getTreeInfoFromIdentifier(volumes_simple, i_to_a(setup.volume_simple));
6616 // if that fails, set current volume to reliable default value
6617 if (volume_simple_current == NULL)
6618 volume_simple_current =
6619 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6621 // if that also fails, set current volume to first available value
6622 if (volume_simple_current == NULL)
6623 volume_simple_current = volumes_simple;
6626 if (volumes_loops == NULL)
6628 boolean current_volume_loops_found = FALSE;
6631 for (i = 0; volumes_list[i].value != -1; i++)
6633 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6634 char identifier[32], name[32];
6635 int value = volumes_list[i].value;
6636 char *text = volumes_list[i].text;
6638 ti->node_top = &volumes_loops;
6639 ti->sort_priority = value;
6641 sprintf(identifier, "%d", value);
6642 sprintf(name, "%s", text);
6644 setString(&ti->identifier, identifier);
6645 setString(&ti->name, name);
6646 setString(&ti->name_sorting, name);
6647 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6649 pushTreeInfo(&volumes_loops, ti);
6651 if (value == setup.volume_loops)
6652 current_volume_loops_found = TRUE;
6655 if (!current_volume_loops_found)
6657 // add entry for non-preset volume value
6659 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6660 char identifier[32], name[32];
6661 int value = setup.volume_loops;
6663 ti->node_top = &volumes_loops;
6664 ti->sort_priority = value;
6666 sprintf(identifier, "%d", value);
6667 sprintf(name, "%d %% (Current)", value);
6669 setString(&ti->identifier, identifier);
6670 setString(&ti->name, name);
6671 setString(&ti->name_sorting, name);
6672 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6674 pushTreeInfo(&volumes_loops, ti);
6677 // sort volume values to start with lowest volume value
6678 sortTreeInfo(&volumes_loops);
6680 // set current volume value to configured volume value
6681 volume_loops_current =
6682 getTreeInfoFromIdentifier(volumes_loops, i_to_a(setup.volume_loops));
6684 // if that fails, set current volume to reliable default value
6685 if (volume_loops_current == NULL)
6686 volume_loops_current =
6687 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6689 // if that also fails, set current volume to first available value
6690 if (volume_loops_current == NULL)
6691 volume_loops_current = volumes_loops;
6694 if (volumes_music == NULL)
6696 boolean current_volume_music_found = FALSE;
6699 for (i = 0; volumes_list[i].value != -1; i++)
6701 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6702 char identifier[32], name[32];
6703 int value = volumes_list[i].value;
6704 char *text = volumes_list[i].text;
6706 ti->node_top = &volumes_music;
6707 ti->sort_priority = value;
6709 sprintf(identifier, "%d", value);
6710 sprintf(name, "%s", text);
6712 setString(&ti->identifier, identifier);
6713 setString(&ti->name, name);
6714 setString(&ti->name_sorting, name);
6715 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6717 pushTreeInfo(&volumes_music, ti);
6719 if (value == setup.volume_music)
6720 current_volume_music_found = TRUE;
6723 if (!current_volume_music_found)
6725 // add entry for non-preset volume value
6727 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6728 char identifier[32], name[32];
6729 int value = setup.volume_music;
6731 ti->node_top = &volumes_music;
6732 ti->sort_priority = value;
6734 sprintf(identifier, "%d", value);
6735 sprintf(name, "%d %% (Current)", value);
6737 setString(&ti->identifier, identifier);
6738 setString(&ti->name, name);
6739 setString(&ti->name_sorting, name);
6740 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6742 pushTreeInfo(&volumes_music, ti);
6745 // sort volume values to start with lowest volume value
6746 sortTreeInfo(&volumes_music);
6748 // set current volume value to configured volume value
6749 volume_music_current =
6750 getTreeInfoFromIdentifier(volumes_music, i_to_a(setup.volume_music));
6752 // if that fails, set current volume to reliable default value
6753 if (volume_music_current == NULL)
6754 volume_music_current =
6755 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6757 // if that also fails, set current volume to first available value
6758 if (volume_music_current == NULL)
6759 volume_music_current = volumes_music;
6762 setup.volume_simple = atoi(volume_simple_current->identifier);
6763 setup.volume_loops = atoi(volume_loops_current->identifier);
6764 setup.volume_music = atoi(volume_music_current->identifier);
6766 // needed for displaying volume text instead of identifier
6767 volume_simple_text = volume_simple_current->name;
6768 volume_loops_text = volume_loops_current->name;
6769 volume_music_text = volume_music_current->name;
6771 setup_mode = SETUP_MODE_SOUND;
6776 static void execSetupChooseTouchControls(void)
6778 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6783 static void execSetupChooseMoveDistance(void)
6785 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6790 static void execSetupChooseDropDistance(void)
6792 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6797 static void execSetupChooseTransparency(void)
6799 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6804 static void execSetupChooseGridXSize_0(void)
6806 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6811 static void execSetupChooseGridYSize_0(void)
6813 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6818 static void execSetupChooseGridXSize_1(void)
6820 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6825 static void execSetupChooseGridYSize_1(void)
6827 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6832 static void execSetupConfigureVirtualButtons(void)
6834 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6836 ConfigureVirtualButtons();
6838 setup_mode = SETUP_MODE_TOUCH;
6843 static void execSetupTouch(void)
6847 if (touch_controls == NULL)
6849 for (i = 0; touch_controls_list[i].value != NULL; i++)
6851 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6852 char identifier[32], name[32];
6853 char *value = touch_controls_list[i].value;
6854 char *text = touch_controls_list[i].text;
6856 ti->node_top = &touch_controls;
6857 ti->sort_priority = i;
6859 sprintf(identifier, "%s", value);
6860 sprintf(name, "%s", text);
6862 setString(&ti->identifier, identifier);
6863 setString(&ti->name, name);
6864 setString(&ti->name_sorting, name);
6865 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6867 pushTreeInfo(&touch_controls, ti);
6870 // sort touch control values to start with lowest touch control value
6871 sortTreeInfo(&touch_controls);
6873 // set current touch control value to configured touch control value
6874 touch_control_current =
6875 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6877 // if that fails, set current touch control to reliable default value
6878 if (touch_control_current == NULL)
6879 touch_control_current =
6880 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6882 // if that also fails, set current touch control to first available value
6883 if (touch_control_current == NULL)
6884 touch_control_current = touch_controls;
6887 if (move_distances == NULL)
6889 for (i = 0; distances_list[i].value != -1; i++)
6891 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6892 char identifier[32], name[32];
6893 int value = distances_list[i].value;
6894 char *text = distances_list[i].text;
6896 ti->node_top = &move_distances;
6897 ti->sort_priority = value;
6899 sprintf(identifier, "%d", value);
6900 sprintf(name, "%s", text);
6902 setString(&ti->identifier, identifier);
6903 setString(&ti->name, name);
6904 setString(&ti->name_sorting, name);
6905 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6907 pushTreeInfo(&move_distances, ti);
6910 // sort distance values to start with lowest distance value
6911 sortTreeInfo(&move_distances);
6913 // set current distance value to configured distance value
6914 move_distance_current =
6915 getTreeInfoFromIdentifier(move_distances,
6916 i_to_a(setup.touch.move_distance));
6918 // if that fails, set current distance to reliable default value
6919 if (move_distance_current == NULL)
6920 move_distance_current =
6921 getTreeInfoFromIdentifier(move_distances,
6922 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6924 // if that also fails, set current distance to first available value
6925 if (move_distance_current == NULL)
6926 move_distance_current = move_distances;
6929 if (drop_distances == NULL)
6931 for (i = 0; distances_list[i].value != -1; i++)
6933 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6934 char identifier[32], name[32];
6935 int value = distances_list[i].value;
6936 char *text = distances_list[i].text;
6938 ti->node_top = &drop_distances;
6939 ti->sort_priority = value;
6941 sprintf(identifier, "%d", value);
6942 sprintf(name, "%s", text);
6944 setString(&ti->identifier, identifier);
6945 setString(&ti->name, name);
6946 setString(&ti->name_sorting, name);
6947 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6949 pushTreeInfo(&drop_distances, ti);
6952 // sort distance values to start with lowest distance value
6953 sortTreeInfo(&drop_distances);
6955 // set current distance value to configured distance value
6956 drop_distance_current =
6957 getTreeInfoFromIdentifier(drop_distances,
6958 i_to_a(setup.touch.drop_distance));
6960 // if that fails, set current distance to reliable default value
6961 if (drop_distance_current == NULL)
6962 drop_distance_current =
6963 getTreeInfoFromIdentifier(drop_distances,
6964 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6966 // if that also fails, set current distance to first available value
6967 if (drop_distance_current == NULL)
6968 drop_distance_current = drop_distances;
6971 if (transparencies == NULL)
6973 for (i = 0; transparencies_list[i].value != -1; i++)
6975 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6976 char identifier[32], name[32];
6977 int value = transparencies_list[i].value;
6978 char *text = transparencies_list[i].text;
6980 ti->node_top = &transparencies;
6981 ti->sort_priority = value;
6983 sprintf(identifier, "%d", value);
6984 sprintf(name, "%s", text);
6986 setString(&ti->identifier, identifier);
6987 setString(&ti->name, name);
6988 setString(&ti->name_sorting, name);
6989 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6991 pushTreeInfo(&transparencies, ti);
6994 // sort transparency values to start with lowest transparency value
6995 sortTreeInfo(&transparencies);
6997 // set current transparency value to configured transparency value
6998 transparency_current =
6999 getTreeInfoFromIdentifier(transparencies,
7000 i_to_a(setup.touch.transparency));
7002 // if that fails, set current transparency to reliable default value
7003 if (transparency_current == NULL)
7004 transparency_current =
7005 getTreeInfoFromIdentifier(transparencies,
7006 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
7008 // if that also fails, set current transparency to first available value
7009 if (transparency_current == NULL)
7010 transparency_current = transparencies;
7013 for (i = 0; i < 2; i++)
7015 for (j = 0; j < 2; j++)
7017 if (grid_sizes[i][j] == NULL)
7019 for (k = 0; grid_sizes_list[k].value != -1; k++)
7021 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
7022 char identifier[32], name[32];
7023 int value = grid_sizes_list[k].value;
7024 char *text = grid_sizes_list[k].text;
7026 ti->node_top = &grid_sizes[i][j];
7027 ti->sort_priority = value;
7029 sprintf(identifier, "%d", value);
7030 sprintf(name, "%s", text);
7032 setString(&ti->identifier, identifier);
7033 setString(&ti->name, name);
7034 setString(&ti->name_sorting, name);
7035 setString(&ti->infotext,
7038 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
7039 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
7041 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
7042 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
7044 pushTreeInfo(&grid_sizes[i][j], ti);
7047 // sort grid size values to start with lowest grid size value
7048 sortTreeInfo(&grid_sizes[i][j]);
7050 // set current grid size value to configured grid size value
7051 grid_size_current[i][j] =
7052 getTreeInfoFromIdentifier(grid_sizes[i][j],
7054 setup.touch.grid_xsize[i] :
7055 setup.touch.grid_ysize[i]));
7057 // if that fails, set current grid size to reliable default value
7058 if (grid_size_current[i][j] == NULL)
7059 grid_size_current[i][j] =
7060 getTreeInfoFromIdentifier(grid_sizes[i][j],
7062 DEFAULT_GRID_XSIZE(i) :
7063 DEFAULT_GRID_YSIZE(i)));
7065 // if that also fails, set current grid size to first available value
7066 if (grid_size_current[i][j] == NULL)
7067 grid_size_current[i][j] = grid_sizes[i][j];
7072 setup.touch.control_type = touch_control_current->identifier;
7073 setup.touch.move_distance = atoi(move_distance_current->identifier);
7074 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7075 setup.touch.transparency = atoi(transparency_current->identifier);
7077 for (i = 0; i < 2; i++)
7079 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7080 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7082 if (i == GRID_ACTIVE_NR())
7084 overlay.grid_xsize = setup.touch.grid_xsize[i];
7085 overlay.grid_ysize = setup.touch.grid_ysize[i];
7089 // needed for displaying value text instead of identifier
7090 touch_controls_text = touch_control_current->name;
7091 move_distance_text = move_distance_current->name;
7092 drop_distance_text = drop_distance_current->name;
7093 transparency_text = transparency_current->name;
7095 for (i = 0; i < 2; i++)
7096 for (j = 0; j < 2; j++)
7097 grid_size_text[i][j] = grid_size_current[i][j]->name;
7099 setup_mode = SETUP_MODE_TOUCH;
7104 static void execSetupArtwork(void)
7106 static ArtworkDirTree *gfx_last_valid = NULL;
7107 static ArtworkDirTree *snd_last_valid = NULL;
7108 static ArtworkDirTree *mus_last_valid = NULL;
7110 // current artwork directory may be invalid (level group, parent link)
7111 if (!validLevelSeries(artwork.gfx_current))
7112 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7113 if (!validLevelSeries(artwork.snd_current))
7114 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7115 if (!validLevelSeries(artwork.mus_current))
7116 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7118 // store valid artwork directory information
7119 gfx_last_valid = artwork.gfx_current;
7120 snd_last_valid = artwork.snd_current;
7121 mus_last_valid = artwork.mus_current;
7124 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7125 artwork.gfx_current->subdir,
7126 artwork.gfx_current->fullpath,
7127 artwork.gfx_current->basepath);
7130 setup.graphics_set = artwork.gfx_current->identifier;
7131 setup.sounds_set = artwork.snd_current->identifier;
7132 setup.music_set = artwork.mus_current->identifier;
7134 // needed if last screen (setup choice) changed graphics, sounds or music
7135 ReloadCustomArtwork(0);
7137 // needed for displaying artwork name instead of artwork identifier
7138 graphics_set_name = artwork.gfx_current->name;
7139 sounds_set_name = artwork.snd_current->name;
7140 music_set_name = artwork.mus_current->name;
7142 setup_mode = SETUP_MODE_ARTWORK;
7147 static void execSetupChooseGraphics(void)
7149 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7154 static void execSetupChooseSounds(void)
7156 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7161 static void execSetupChooseMusic(void)
7163 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7168 static void execSetupInput(void)
7170 setup_mode = SETUP_MODE_INPUT;
7175 static void execSetupShortcuts(void)
7177 setup_mode = SETUP_MODE_SHORTCUTS;
7182 static void execSetupShortcuts1(void)
7184 setup_mode = SETUP_MODE_SHORTCUTS_1;
7189 static void execSetupShortcuts2(void)
7191 setup_mode = SETUP_MODE_SHORTCUTS_2;
7196 static void execSetupShortcuts3(void)
7198 setup_mode = SETUP_MODE_SHORTCUTS_3;
7203 static void execSetupShortcuts4(void)
7205 setup_mode = SETUP_MODE_SHORTCUTS_4;
7210 static void execSetupShortcuts5(void)
7212 setup_mode = SETUP_MODE_SHORTCUTS_5;
7217 static void execExitSetup(void)
7219 SetGameStatus(GAME_MODE_MAIN);
7224 static void execSaveAndExitSetup(void)
7230 static void execGadgetNetworkServer(void)
7232 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7233 struct GadgetInfo *gi = screen_gadget[gadget_id];
7235 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7236 network_server_hostname[0] = '\0';
7238 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7242 ClickOnGadget(gi, MB_LEFTBUTTON);
7245 static void execOfferUploadTapes(void)
7250 static void ToggleNetworkModeIfNeeded(void)
7252 int font_title = FONT_TITLE_1;
7253 int font_foot = FC_BLUE;
7254 int ystart = mSY - SY + 16;
7255 int ybottom = mSY - SY + SYSIZE - 20;
7256 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7258 if (setup.network_mode == network.enabled)
7261 network.enabled = setup.network_mode;
7263 FadeOut(REDRAW_ALL);
7267 DrawTextSCentered(ystart, font_title, text);
7271 if (network.enabled)
7272 InitNetworkServer();
7274 DisconnectFromNetworkServer();
7276 DrawTextSCentered(ybottom, font_foot,
7277 "Press any key or button for setup menu");
7279 WaitForEventToContinue();
7284 static void ToggleGameSpeedsListIfNeeded(void)
7286 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7288 if (setup.game_speed_extended == using_game_speeds_extended)
7291 // try to match similar values when changing game speeds list
7292 if (setup.game_speed_extended)
7293 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7294 setup.game_frame_delay == 30 ? 29 :
7295 setup.game_frame_delay);
7297 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7298 setup.game_frame_delay == 16 ? 15 :
7299 setup.game_frame_delay >= 29 ? 30 :
7300 setup.game_frame_delay <= 10 ? 10 :
7301 setup.game_frame_delay);
7303 execSetupGame_setGameSpeeds(TRUE);
7308 static void ToggleUseApiServerIfNeeded(void)
7310 if (runtime.use_api_server == setup.use_api_server)
7313 runtime.use_api_server = setup.use_api_server;
7315 if (runtime.use_api_server)
7317 if (setup.has_remaining_tapes)
7318 setup.ask_for_uploading_tapes = TRUE;
7320 CheckApiServerTasks();
7324 static void ModifyGameSpeedIfNeeded(void)
7326 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7327 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7331 char *game_speed_text = "Fast";
7332 int game_speed_value = 15;
7334 if (setup.game_speed_extended)
7336 game_speed_text = "60 fps";
7337 game_speed_value = 16;
7340 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7342 // set game speed to existing list value that is fast enough for vsync
7343 setup.game_frame_delay = game_speed_value;
7345 execSetupGame_setGameSpeeds(TRUE);
7347 Request(message, REQ_CONFIRM);
7350 static void DisableVsyncIfNeeded(void)
7352 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7353 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7354 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7357 // disable vsync for the selected game speed to work
7358 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7360 execSetupGraphics_setVsyncModes(TRUE);
7362 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7368 void *related_value;
7369 } hide_related_entry_list[] =
7371 { &setup.network_server_hostname, execGadgetNetworkServer },
7372 { &setup.network_server_hostname, &network_server_text },
7374 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7375 { &setup.scores_in_highscore_list, &scores_type_text },
7377 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7378 { &setup.game_frame_delay, &game_speed_text },
7380 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7381 { &setup.scroll_delay_value, &scroll_delay_text },
7383 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7384 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7386 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7387 { &setup.window_scaling_percent, &window_size_text },
7389 { &setup.window_scaling_quality, execSetupChooseScalingType },
7390 { &setup.window_scaling_quality, &scaling_type_text },
7392 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7393 { &setup.screen_rendering_mode, &rendering_mode_text },
7395 { &setup.vsync_mode, execSetupChooseVsyncMode },
7396 { &setup.vsync_mode, &vsync_mode_text },
7398 { &setup.graphics_set, execSetupChooseGraphics },
7399 { &setup.graphics_set, &graphics_set_name },
7401 { &setup.sounds_set, execSetupChooseSounds },
7402 { &setup.sounds_set, &sounds_set_name },
7404 { &setup.music_set, execSetupChooseMusic },
7405 { &setup.music_set, &music_set_name },
7407 { &setup.volume_simple, execSetupChooseVolumeSimple },
7408 { &setup.volume_simple, &volume_simple_text },
7410 { &setup.volume_loops, execSetupChooseVolumeLoops },
7411 { &setup.volume_loops, &volume_loops_text },
7413 { &setup.volume_music, execSetupChooseVolumeMusic },
7414 { &setup.volume_music, &volume_music_text },
7416 { &setup.touch.control_type, execSetupChooseTouchControls },
7417 { &setup.touch.control_type, &touch_controls_text },
7419 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7420 { &setup.touch.move_distance, &move_distance_text },
7422 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7423 { &setup.touch.drop_distance, &drop_distance_text },
7425 { &setup.touch.transparency, execSetupChooseTransparency },
7426 { &setup.touch.transparency, &transparency_text },
7428 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7429 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7431 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7432 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7434 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7435 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7437 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7438 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7440 { &setup.internal.menu_game, execSetupGame },
7441 { &setup.internal.menu_engines, execSetupEngines },
7442 { &setup.internal.menu_editor, execSetupEditor },
7443 { &setup.internal.menu_graphics, execSetupGraphics },
7444 { &setup.internal.menu_sound, execSetupSound },
7445 { &setup.internal.menu_artwork, execSetupArtwork },
7446 { &setup.internal.menu_input, execSetupInput },
7447 { &setup.internal.menu_touch, execSetupTouch },
7448 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7449 { &setup.internal.menu_exit, execExitSetup },
7450 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7452 { &setup.internal.menu_shortcuts_various, execSetupShortcuts1 },
7453 { &setup.internal.menu_shortcuts_focus, execSetupShortcuts2 },
7454 { &setup.internal.menu_shortcuts_tape, execSetupShortcuts3 },
7455 { &setup.internal.menu_shortcuts_sound, execSetupShortcuts4 },
7456 { &setup.internal.menu_shortcuts_snap, execSetupShortcuts5 },
7458 { &setup.internal.info_title, execInfoTitleScreen },
7459 { &setup.internal.info_elements, execInfoElements },
7460 { &setup.internal.info_music, execInfoMusic },
7461 { &setup.internal.info_credits, execInfoCredits },
7462 { &setup.internal.info_program, execInfoProgram },
7463 { &setup.internal.info_version, execInfoVersion },
7464 { &setup.internal.info_levelset, execInfoLevelSet },
7465 { &setup.internal.info_exit, execExitInfo },
7470 void setHideRelatedSetupEntries(void)
7474 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7475 if (hideSetupEntry(hide_related_entry_list[i].value))
7476 setHideSetupEntry(hide_related_entry_list[i].related_value);
7479 static struct TokenInfo setup_info_main[] =
7481 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7482 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7483 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7484 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7485 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7486 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7487 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7488 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7489 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7490 { TYPE_EMPTY, NULL, "" },
7491 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7492 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7497 static struct TokenInfo setup_info_game[] =
7499 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7500 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7501 { TYPE_PLAYER, &setup.network_player_nr, "Preferred Network Player:" },
7502 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7503 { TYPE_STRING, &network_server_text, "" },
7504 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7505 { TYPE_ENTER_LIST, execSetupChooseScoresType, "Scores in Highscore List:" },
7506 { TYPE_STRING, &scores_type_text, "" },
7507 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7508 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7509 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7510 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7511 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7512 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7513 { TYPE_SWITCH, &setup.increment_levels, "Increment Solved Levels:" },
7514 { TYPE_SWITCH, &setup.auto_play_next_level, "Auto-play Next Level:" },
7515 { TYPE_SWITCH, &setup.count_score_after_game, "Count Score After Game:" },
7516 { TYPE_SWITCH, &setup.show_scores_after_game, "Show Scores After Game:" },
7517 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7518 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7519 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7520 { TYPE_SWITCH, &setup.autorecord, "Auto-Record When Playing:" },
7521 { TYPE_SWITCH, &setup.autorecord_after_replay, "Auto-Record After Replay:" },
7522 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7523 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7524 { TYPE_STRING, &game_speed_text, "" },
7525 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7527 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7528 { TYPE_STRING, &scroll_delay_text, "" },
7530 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode, "Game Engine Snapshot Mode:" },
7531 { TYPE_STRING, &snapshot_mode_text, "" },
7532 { TYPE_SWITCH, &setup.show_load_save_buttons, "Show Load/Save Buttons:" },
7533 { TYPE_SWITCH, &setup.show_undo_redo_buttons, "Show Undo/Redo Buttons:" },
7534 { TYPE_EMPTY, NULL, "" },
7535 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7540 static struct TokenInfo setup_info_engines[] =
7542 { TYPE_HEADLINE, NULL, "Boulder Dash" },
7543 { TYPE_SWITCH, &setup.bd_skip_uncovering, "Skip (un)covering screen:" },
7544 { TYPE_SWITCH, &setup.bd_skip_hatching, "Skip hatching player:" },
7545 { TYPE_SWITCH, &setup.bd_scroll_delay, "Scroll Delay:" },
7546 { TYPE_YES_NO_AUTO, &setup.bd_smooth_movements, "Smooth Element Movement:" },
7547 { TYPE_EMPTY, NULL, "" },
7548 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7549 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7550 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7551 { TYPE_SWITCH, &setup.prefer_lowpass_sounds, "Low-Pass Filter Sounds:" },
7552 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7553 { TYPE_EMPTY, NULL, "" },
7554 { TYPE_HEADLINE, NULL, "Supaplex" },
7555 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7556 { TYPE_EMPTY, NULL, "" },
7557 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7562 static struct TokenInfo setup_info_editor[] =
7565 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7566 { TYPE_SWITCH, &setup.editor.el_boulderdash_native, "Boulder Dash Native:" },
7567 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7568 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7569 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7570 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7571 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7572 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7573 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7574 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7575 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7577 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7578 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7580 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7582 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7583 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7584 { TYPE_EMPTY, NULL, "" },
7586 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7587 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7588 { TYPE_EMPTY, NULL, "" },
7590 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7591 { TYPE_EMPTY, NULL, "" },
7592 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7593 { TYPE_EMPTY, NULL, "" },
7594 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7599 static struct TokenInfo setup_info_graphics[] =
7601 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
7602 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7603 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7604 { TYPE_STRING, &window_size_text, "" },
7605 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7606 { TYPE_STRING, &scaling_type_text, "" },
7607 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7608 { TYPE_STRING, &rendering_mode_text, "" },
7611 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7612 { TYPE_STRING, &scroll_delay_text, "" },
7614 #if !defined(PLATFORM_EMSCRIPTEN)
7615 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7616 { TYPE_STRING, &vsync_mode_text, "" },
7618 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7619 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7620 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7621 { TYPE_SWITCH, &setup.show_titlescreen, "Show Title Screens:" },
7622 { TYPE_SWITCH, &setup.toons, "Show Toons:" },
7623 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7624 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7625 { TYPE_EMPTY, NULL, "" },
7626 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7631 static struct TokenInfo setup_info_sound[] =
7633 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7634 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7635 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7636 { TYPE_EMPTY, NULL, "" },
7637 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7638 { TYPE_STRING, &volume_simple_text, "" },
7639 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7640 { TYPE_STRING, &volume_loops_text, "" },
7641 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7642 { TYPE_STRING, &volume_music_text, "" },
7643 { TYPE_EMPTY, NULL, "" },
7644 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7649 static struct TokenInfo setup_info_artwork[] =
7651 { TYPE_ENTER_LIST, execSetupChooseGraphics, "Custom Graphics:" },
7652 { TYPE_STRING, &graphics_set_name, "" },
7653 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7654 { TYPE_STRING, &sounds_set_name, "" },
7655 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7656 { TYPE_STRING, &music_set_name, "" },
7657 { TYPE_EMPTY, NULL, "" },
7658 { TYPE_YES_NO_AUTO, &setup.override_level_graphics,"Override Level Graphics:" },
7659 { TYPE_YES_NO_AUTO, &setup.override_level_sounds, "Override Level Sounds:" },
7660 { TYPE_YES_NO_AUTO, &setup.override_level_music, "Override Level Music:" },
7661 { TYPE_EMPTY, NULL, "" },
7662 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7667 static struct TokenInfo setup_info_input[] =
7669 { TYPE_SWITCH, NULL, "Player:" },
7670 { TYPE_SWITCH, NULL, "Device:" },
7671 { TYPE_SWITCH, NULL, "" },
7672 { TYPE_SKIPPABLE, NULL, "" },
7673 { TYPE_EMPTY, NULL, "" },
7674 { TYPE_EMPTY, NULL, "" },
7675 { TYPE_EMPTY, NULL, "" },
7676 { TYPE_EMPTY, NULL, "" },
7677 { TYPE_EMPTY, NULL, "" },
7678 { TYPE_EMPTY, NULL, "" },
7679 { TYPE_EMPTY, NULL, "" },
7680 { TYPE_EMPTY, NULL, "" },
7681 { TYPE_SKIPPABLE, NULL, "" },
7682 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7687 static struct TokenInfo setup_info_touch[] =
7689 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7690 { TYPE_STRING, &touch_controls_text, "" },
7691 { TYPE_EMPTY, NULL, "" },
7692 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7697 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7699 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7700 { TYPE_STRING, &touch_controls_text, "" },
7701 { TYPE_EMPTY, NULL, "" },
7702 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7703 { TYPE_STRING, &grid_size_text[0][0], "" },
7704 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7705 { TYPE_STRING, &grid_size_text[0][1], "" },
7706 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7707 { TYPE_STRING, &transparency_text, "" },
7708 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7709 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7710 { TYPE_EMPTY, NULL, "" },
7711 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7712 { TYPE_EMPTY, NULL, "" },
7713 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7718 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7720 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7721 { TYPE_STRING, &touch_controls_text, "" },
7722 { TYPE_EMPTY, NULL, "" },
7723 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7724 { TYPE_STRING, &grid_size_text[1][0], "" },
7725 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7726 { TYPE_STRING, &grid_size_text[1][1], "" },
7727 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7728 { TYPE_STRING, &transparency_text, "" },
7729 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7730 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7731 { TYPE_EMPTY, NULL, "" },
7732 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7733 { TYPE_EMPTY, NULL, "" },
7734 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7739 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7741 setup_info_touch_virtual_buttons_0,
7742 setup_info_touch_virtual_buttons_1
7745 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7747 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7748 { TYPE_STRING, &touch_controls_text, "" },
7749 { TYPE_EMPTY, NULL, "" },
7750 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7751 { TYPE_STRING, &move_distance_text, "" },
7752 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7753 { TYPE_STRING, &drop_distance_text, "" },
7754 { TYPE_EMPTY, NULL, "" },
7755 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7760 static struct TokenInfo setup_info_shortcuts[] =
7762 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7763 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7764 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7765 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7766 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7767 { TYPE_EMPTY, NULL, "" },
7768 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7773 static struct TokenInfo setup_info_shortcuts_1[] =
7775 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:" },
7776 { TYPE_KEY, &setup.shortcut.save_game, "" },
7777 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:" },
7778 { TYPE_KEY, &setup.shortcut.load_game, "" },
7779 { TYPE_KEYTEXT, NULL, "Restart Game:" },
7780 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7781 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:" },
7782 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7783 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:" },
7784 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7785 { TYPE_EMPTY, NULL, "" },
7786 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7787 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7788 { TYPE_EMPTY, NULL, "" },
7789 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7794 static struct TokenInfo setup_info_shortcuts_2[] =
7796 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:" },
7797 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7798 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:" },
7799 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7800 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:" },
7801 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7802 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:" },
7803 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7804 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:" },
7805 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7806 { TYPE_EMPTY, NULL, "" },
7807 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7812 static struct TokenInfo setup_info_shortcuts_3[] =
7814 { TYPE_KEYTEXT, NULL, "Eject Tape:" },
7815 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7816 { TYPE_KEYTEXT, NULL, "Warp / Single Step:" },
7817 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7818 { TYPE_KEYTEXT, NULL, "Stop Tape:" },
7819 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7820 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:" },
7821 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7822 { TYPE_KEYTEXT, NULL, "Record Tape:" },
7823 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7824 { TYPE_KEYTEXT, NULL, "Play Tape:" },
7825 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7826 { TYPE_EMPTY, NULL, "" },
7827 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7832 static struct TokenInfo setup_info_shortcuts_4[] =
7834 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):" },
7835 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7836 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):" },
7837 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7838 { TYPE_KEYTEXT, NULL, "Toggle Music:" },
7839 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7840 { TYPE_EMPTY, NULL, "" },
7841 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7846 static struct TokenInfo setup_info_shortcuts_5[] =
7848 { TYPE_KEYTEXT, NULL, "Snap Left:" },
7849 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7850 { TYPE_KEYTEXT, NULL, "Snap Right:" },
7851 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7852 { TYPE_KEYTEXT, NULL, "Snap Up:" },
7853 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7854 { TYPE_KEYTEXT, NULL, "Snap Down:" },
7855 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7856 { TYPE_EMPTY, NULL, "" },
7857 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7862 static Key getSetupKey(void)
7864 Key key = KSYM_UNDEFINED;
7865 boolean got_key_event = FALSE;
7867 while (!got_key_event)
7871 if (NextValidEvent(&event))
7875 case EVENT_KEYPRESS:
7877 key = GetEventKey((KeyEvent *)&event);
7879 // press 'Escape' or 'Enter' to keep the existing key binding
7880 if (key == KSYM_Escape || key == KSYM_Return)
7881 key = KSYM_UNDEFINED; // keep old value
7883 got_key_event = TRUE;
7887 case EVENT_KEYRELEASE:
7888 key_joystick_mapping = 0;
7892 HandleOtherEvents(&event);
7903 static int getSetupValueFont(int type, void *value)
7905 if (type & TYPE_GHOSTED)
7906 return FONT_OPTION_OFF;
7907 else if (type & TYPE_KEY)
7908 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7909 else if (type & TYPE_STRING)
7910 return FONT_VALUE_2;
7911 else if (type & TYPE_ECS_AGA)
7912 return FONT_VALUE_1;
7913 else if (type & TYPE_BOOLEAN_STYLE)
7914 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7915 else if (type & TYPE_YES_NO_AUTO)
7916 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7917 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7918 else if (type & TYPE_PLAYER)
7919 return FONT_VALUE_1;
7921 return FONT_VALUE_1;
7924 static int getSetupValueFontNarrow(int type, int font_nr)
7926 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7927 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7928 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7932 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7934 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7935 struct TokenInfo *si = &setup_info[si_pos];
7936 boolean font_draw_xoffset_modified = FALSE;
7937 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7938 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
7939 int mx_right_border = (scrollbar_needed ? mx_scrollbar : SX + SXSIZE);
7940 int font_draw_xoffset_old = -1;
7941 int xoffset = (scrollbar_needed ? 0 : 1);
7942 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7943 int xpos = menu_screen_value_xpos;
7944 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7945 int startx = mSX + xpos * 32;
7946 int starty = mSY + ypos * 32;
7947 int type = si->type;
7948 void *value = si->value;
7949 char *value_string = getSetupValue(type, value);
7950 int font_nr_default = getSetupValueFont(type, value);
7951 int font_width_default = getFontWidth(font_nr_default);
7952 int font_nr = font_nr_default;
7954 if (value_string == NULL)
7957 if (type & TYPE_KEY)
7959 xpos = MENU_SCREEN_START_XPOS;
7961 if (type & TYPE_QUERY)
7962 value_string = "<press key>";
7964 else if (type & TYPE_STRING)
7966 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7968 xpos = MENU_SCREEN_START_XPOS;
7970 if (strlen(value_string) > max_value_len)
7971 value_string[max_value_len] = '\0';
7973 else if (type & TYPE_PLAYER)
7975 int displayed_player_nr = *(int *)value + 1;
7977 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7980 startx = mSX + xpos * 32;
7981 starty = mSY + ypos * 32;
7983 // always use narrow font for setup values on right screen side
7984 if (xpos > MENU_SCREEN_START_XPOS)
7985 font_nr = getSetupValueFontNarrow(type, font_nr);
7987 // downward compatibility correction for Juergen Bonhagen's menu settings
7988 if (setup_mode != SETUP_MODE_INPUT)
7990 int max_menu_text_length_big = (menu_screen_value_xpos -
7991 MENU_SCREEN_START_XPOS);
7992 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7993 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7994 int font1_xoffset = getFontDrawOffsetX(font_nr);
7995 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7996 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7997 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7998 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7999 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
8000 boolean correct_font_draw_xoffset = FALSE;
8002 if (xpos == MENU_SCREEN_START_XPOS &&
8003 startx + font1_xoffset < text_startx + text_font_xoffset)
8004 correct_font_draw_xoffset = TRUE;
8006 if (xpos == menu_screen_value_xpos &&
8007 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
8008 correct_font_draw_xoffset = TRUE;
8010 // check if setup value would overlap with setup text when printed
8011 // (this can happen for extreme/wrong values for font draw offset)
8012 if (correct_font_draw_xoffset)
8014 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
8015 font_draw_xoffset_modified = TRUE;
8017 if (type & TYPE_KEY)
8018 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
8019 else if (!(type & TYPE_STRING))
8020 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
8021 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
8025 DrawBackground(startx, starty, mx_right_border - startx, getFontHeight(font_nr));
8026 DrawText(startx, starty, value_string, font_nr);
8028 if (type & TYPE_PLAYER)
8030 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
8031 int player_nr = *(int *)value;
8032 int xoff = font->draw_xoffset + getFontWidth(font_nr);
8033 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
8034 int startx2 = startx + xoff;
8035 int starty2 = starty + yoff;
8037 if (DrawingOnBackground(startx2, starty2))
8038 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
8040 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
8041 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8044 if (font_draw_xoffset_modified)
8045 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
8048 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8050 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8051 struct TokenInfo *si = &setup_info[si_pos];
8053 if (si->type & TYPE_BOOLEAN_STYLE)
8055 *(boolean *)si->value ^= TRUE;
8057 else if (si->type & TYPE_YES_NO_AUTO)
8061 (*(int *)si->value == AUTO ? TRUE :
8062 *(int *)si->value == TRUE ? FALSE : AUTO) :
8063 (*(int *)si->value == TRUE ? AUTO :
8064 *(int *)si->value == AUTO ? FALSE : TRUE));
8066 else if (si->type & TYPE_KEY)
8070 si->type |= TYPE_QUERY;
8071 drawSetupValue(screen_pos, setup_info_pos_raw);
8072 si->type &= ~TYPE_QUERY;
8074 key = getSetupKey();
8075 if (key != KSYM_UNDEFINED)
8076 *(Key *)si->value = key;
8078 else if (si->type & TYPE_PLAYER)
8080 int player_nr = *(int *)si->value;
8085 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8087 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8090 drawSetupValue(screen_pos, setup_info_pos_raw);
8092 // fullscreen state may have changed at this point
8093 if (si->value == &setup.fullscreen)
8094 ToggleFullscreenIfNeeded();
8096 // network mode may have changed at this point
8097 if (si->value == &setup.network_mode)
8098 ToggleNetworkModeIfNeeded();
8100 // API server mode may have changed at this point
8101 if (si->value == &setup.use_api_server)
8102 ToggleUseApiServerIfNeeded();
8104 // game speed list may have changed at this point
8105 if (si->value == &setup.game_speed_extended)
8106 ToggleGameSpeedsListIfNeeded();
8109 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8111 static struct TokenInfo *setup_info_final = NULL;
8116 // determine maximum list size of target list
8117 while (setup_info_orig[list_size++].type != 0);
8119 // free, allocate and clear memory for target list
8120 checked_free(setup_info_final);
8121 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8123 // copy setup info list without setup entries marked as hidden
8124 for (i = 0; setup_info_orig[i].type != 0; i++)
8126 // skip setup entries configured to be hidden
8127 if (hideSetupEntry(setup_info_orig[i].value))
8130 // skip skippable setup entries if screen is lower than usual
8131 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8132 setup_info_orig[i].type == TYPE_SKIPPABLE)
8135 setup_info_final[list_pos++] = setup_info_orig[i];
8138 return setup_info_final;
8141 static void DrawSetupScreen_Generic(void)
8143 int fade_mask = REDRAW_FIELD;
8144 boolean redraw_all = FALSE;
8145 char *title_string = NULL;
8149 fade_mask = REDRAW_ALL;
8152 FadeMenuSoundsAndMusic();
8154 FreeScreenGadgets();
8155 CreateScreenGadgets();
8157 if (redraw_mask & REDRAW_ALL)
8162 // needed if different viewport properties defined for setup screen
8163 ChangeViewportPropertiesIfNeeded();
8165 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8169 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8171 if (setup_mode == SETUP_MODE_MAIN)
8173 setup_info = setup_info_main;
8174 title_string = STR_SETUP_MAIN;
8176 else if (setup_mode == SETUP_MODE_GAME)
8178 setup_info = setup_info_game;
8179 title_string = STR_SETUP_GAME;
8181 else if (setup_mode == SETUP_MODE_ENGINES)
8183 setup_info = setup_info_engines;
8184 title_string = STR_SETUP_ENGINES;
8186 else if (setup_mode == SETUP_MODE_EDITOR)
8188 setup_info = setup_info_editor;
8189 title_string = STR_SETUP_EDITOR;
8191 else if (setup_mode == SETUP_MODE_GRAPHICS)
8193 setup_info = setup_info_graphics;
8194 title_string = STR_SETUP_GRAPHICS;
8196 else if (setup_mode == SETUP_MODE_SOUND)
8198 setup_info = setup_info_sound;
8199 title_string = STR_SETUP_SOUND;
8201 else if (setup_mode == SETUP_MODE_ARTWORK)
8203 setup_info = setup_info_artwork;
8204 title_string = STR_SETUP_ARTWORK;
8206 else if (setup_mode == SETUP_MODE_TOUCH)
8208 setup_info = setup_info_touch;
8209 title_string = STR_SETUP_TOUCH;
8211 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8212 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8213 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8214 setup_info = setup_info_touch_wipe_gestures;
8216 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8218 setup_info = setup_info_shortcuts;
8219 title_string = STR_SETUP_SHORTCUTS;
8221 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8223 setup_info = setup_info_shortcuts_1;
8224 title_string = STR_SETUP_SHORTCUTS;
8226 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8228 setup_info = setup_info_shortcuts_2;
8229 title_string = STR_SETUP_SHORTCUTS;
8231 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8233 setup_info = setup_info_shortcuts_3;
8234 title_string = STR_SETUP_SHORTCUTS;
8236 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8238 setup_info = setup_info_shortcuts_4;
8239 title_string = STR_SETUP_SHORTCUTS;
8241 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8243 setup_info = setup_info_shortcuts_5;
8244 title_string = STR_SETUP_SHORTCUTS;
8247 // use modified setup info without setup entries marked as hidden
8248 setup_info = getSetupInfoFinal(setup_info);
8250 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8252 // determine maximal number of setup entries that can be displayed on screen
8254 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8257 // determine maximal number of setup entries available for this setup screen
8259 for (i = 0; setup_info[i].type != 0; i++)
8262 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8264 MapScreenGadgets(max_setup_info);
8267 redraw_mask = fade_mask = REDRAW_ALL;
8269 DrawMaskedBorder(fade_mask);
8274 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8276 menu_info = setup_info;
8278 HandleMenuScreen(mx, my, dx, dy, button,
8279 setup_mode, num_setup_info, max_setup_info);
8282 static void DrawSetupScreen_Input(void)
8286 FadeOut(REDRAW_FIELD);
8290 setup_info = getSetupInfoFinal(setup_info_input);
8292 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8294 for (i = 0; setup_info[i].type != 0; i++)
8296 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8297 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8298 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8299 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8300 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8301 initCursor(i, IMG_MENU_BUTTON);
8303 DrawCursorAndText_Setup(i, -1, FALSE);
8306 // create gadgets for setup input menu screen
8307 FreeScreenGadgets();
8308 CreateScreenGadgets();
8310 // map gadgets for setup input menu screen
8311 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8313 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8315 FadeIn(REDRAW_FIELD);
8318 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8320 if (device_name == NULL)
8323 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8326 if (strlen(device_name) > 1)
8328 char c1 = device_name[strlen(device_name) - 1];
8329 char c2 = device_name[strlen(device_name) - 2];
8331 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8332 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8335 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8336 strlen(device_name));
8339 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8342 static struct SetupKeyboardInfo custom_key;
8349 { &custom_key.left, "Axis/Pad Left" },
8350 { &custom_key.right, "Axis/Pad Right" },
8351 { &custom_key.up, "Axis/Pad Up" },
8352 { &custom_key.down, "Axis/Pad Down" },
8353 { &custom_key.snap, "Button 1/A/X" },
8354 { &custom_key.drop, "Button 2/B/Y" }
8356 static char *joystick_name[MAX_PLAYERS] =
8363 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8364 int font_nr_info = FONT_MENU_1;
8365 int font_nr_name = FONT_VALUE_OLD;
8366 int font_nr_on = FONT_VALUE_1;
8367 int font_nr_off = FONT_VALUE_OLD;
8370 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8372 font_nr_info = FONT_MENU_2;
8373 font_nr_on = FONT_VALUE_NARROW;
8374 font_nr_off = FONT_VALUE_OLD_NARROW;
8377 custom_key = setup.input[player_nr].key;
8379 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8380 FONT_INPUT_1_ACTIVE);
8382 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8384 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8385 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8387 if (setup.input[player_nr].use_joystick)
8389 char *device_name = setup.input[player_nr].joy.device_name;
8390 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8391 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8392 char *text = joystick_name[joystick_nr];
8393 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8395 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8396 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8400 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8401 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8404 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8405 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8409 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8410 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8411 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8412 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8414 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8415 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8416 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8417 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8418 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8419 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8421 for (i = 0; i < 6; i++)
8423 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8425 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8427 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8428 (setup.input[player_nr].use_joystick ?
8430 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8434 static int input_player_nr = 0;
8436 static void HandleSetupScreen_Input_Player(int step, int direction)
8438 int old_player_nr = input_player_nr;
8441 new_player_nr = old_player_nr + step * direction;
8442 if (new_player_nr < 0)
8444 if (new_player_nr > MAX_PLAYERS - 1)
8445 new_player_nr = MAX_PLAYERS - 1;
8447 if (new_player_nr != old_player_nr)
8449 input_player_nr = new_player_nr;
8451 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8455 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8457 static int choice = 0;
8460 int pos_start = SETUPINPUT_SCREEN_POS_START;
8461 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8462 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8463 int pos_end = SETUPINPUT_SCREEN_POS_END;
8465 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8469 for (i = 0; setup_info_input[i].type != 0; i++)
8471 // adjust menu structure according to skipped setup entries
8472 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8480 if (button == MB_MENU_INITIALIZE)
8482 // input setup menu may have changed size due to graphics configuration
8483 if (choice >= pos_empty1)
8486 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8488 DrawCursorAndText_Setup(choice, -1, TRUE);
8492 else if (button == MB_MENU_LEAVE)
8494 setup_mode = SETUP_MODE_MAIN;
8501 if (mx || my) // mouse input
8503 x = (mx - mSX) / 32;
8504 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8506 else if (dx || dy) // keyboard input
8508 if (dx && choice == 0)
8509 x = (dx < 0 ? 10 : 12);
8510 else if ((dx && choice == 1) ||
8511 (dx == -1 && choice == pos_end))
8512 button = MB_MENU_CHOICE;
8516 if (y >= pos_empty1 && y <= pos_empty2)
8517 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8520 if (y == 0 && dx != 0 && button)
8522 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8524 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8525 y >= pos_start && y <= pos_end &&
8526 !(y >= pos_empty1 && y <= pos_empty2))
8532 DrawCursorAndText_Setup(choice, -1, FALSE);
8533 DrawCursorAndText_Setup(y, -1, TRUE);
8535 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8544 char *device_name = setup.input[input_player_nr].joy.device_name;
8546 if (!setup.input[input_player_nr].use_joystick)
8548 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8550 setJoystickDeviceToNr(device_name, new_device_nr);
8551 setup.input[input_player_nr].use_joystick = TRUE;
8555 int device_nr = getJoystickNrFromDeviceName(device_name);
8556 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8558 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8559 setup.input[input_player_nr].use_joystick = FALSE;
8561 setJoystickDeviceToNr(device_name, new_device_nr);
8564 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8568 if (setup.input[input_player_nr].use_joystick)
8569 ConfigureJoystick(input_player_nr);
8571 CustomizeKeyboard(input_player_nr);
8573 else if (y == pos_end)
8579 setup_mode = SETUP_MODE_MAIN;
8586 static boolean CustomizeKeyboardMain(int player_nr)
8590 boolean finished = FALSE;
8591 static struct SetupKeyboardInfo custom_key;
8596 } customize_step[] =
8598 { &custom_key.left, "Move Left" },
8599 { &custom_key.right, "Move Right" },
8600 { &custom_key.up, "Move Up" },
8601 { &custom_key.down, "Move Down" },
8602 { &custom_key.snap, "Snap Field" },
8603 { &custom_key.drop, "Drop Element" }
8605 int font_nr_old = FONT_VALUE_OLD;
8606 int font_nr_new = FONT_VALUE_1;
8607 boolean success = FALSE;
8609 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8611 font_nr_old = FONT_VALUE_OLD_NARROW;
8612 font_nr_new = FONT_VALUE_NARROW;
8615 // read existing key bindings from player setup
8616 custom_key = setup.input[player_nr].key;
8619 FadeOut(REDRAW_FIELD);
8623 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8626 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8627 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8628 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8629 "Key:", FONT_INPUT_1_ACTIVE);
8630 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8631 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8633 FadeIn(REDRAW_FIELD);
8638 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8640 // reset frame delay counter directly after updating screen
8641 ResetDelayCounter(&event_frame_delay);
8643 while (NextValidEvent(&event))
8647 case EVENT_KEYPRESS:
8649 Key key = GetEventKey((KeyEvent *)&event);
8651 // press 'Escape' to abort and keep the old key bindings
8652 if (key == KSYM_Escape)
8654 FadeSkipNextFadeIn();
8661 // press 'Enter' to keep the existing key binding
8662 if (key == KSYM_Return)
8663 key = *customize_step[step_nr].key;
8665 // check if key already used
8666 for (i = 0; i < step_nr; i++)
8667 if (*customize_step[i].key == key)
8672 // got new key binding
8673 *customize_step[step_nr].key = key;
8674 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8676 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8677 getKeyNameFromKey(key), font_nr_new);
8680 // un-highlight last query
8681 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8682 customize_step[step_nr - 1].text, FONT_MENU_1);
8683 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8684 "Key:", FONT_MENU_1);
8686 // all keys configured
8695 // query next key binding
8696 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8697 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8698 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8699 "Key:", FONT_INPUT_1_ACTIVE);
8700 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8701 getKeyNameFromKey(*customize_step[step_nr].key),
8706 case EVENT_KEYRELEASE:
8707 key_joystick_mapping = 0;
8711 HandleOtherEvents(&event);
8715 // do not handle events for longer than standard frame delay period
8716 if (DelayReached(&event_frame_delay))
8723 // write new key bindings back to player setup, if successfully finished
8725 setup.input[player_nr].key = custom_key;
8730 void CustomizeKeyboard(int player_nr)
8732 boolean success = CustomizeKeyboardMain(player_nr);
8736 int font_nr = FONT_TITLE_1;
8737 int font_height = getFontHeight(font_nr);
8738 int ypos1 = SYSIZE / 2 - font_height * 2;
8739 int ypos2 = SYSIZE / 2 - font_height * 1;
8740 DelayCounter wait_frame_delay = { 2000 };
8742 ResetDelayCounter(&wait_frame_delay);
8746 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8747 DrawTextSCentered(ypos2, font_nr, "configured!");
8749 while (!DelayReached(&wait_frame_delay))
8755 DrawSetupScreen_Input();
8758 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8760 #define MARKER_BUTTON 1
8761 #define MARKER_AXIS_X 2
8762 #define MARKER_AXIS_Y 3
8764 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8766 static boolean bitmaps_initialized = FALSE;
8767 boolean screen_initialized = FALSE;
8768 static Bitmap *controller, *button, *axis_x, *axis_y;
8770 boolean success = TRUE;
8771 boolean done = FALSE, next = FALSE;
8773 int alpha = 200, alpha_step = -1;
8774 int alpha_ticks = 0;
8775 char mapping[4096], temp[256];
8776 int font_name = MENU_SETUP_FONT_TITLE;
8777 int font_info = MENU_SETUP_FONT_TEXT;
8778 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8779 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8780 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8781 int ystep_name = getMenuTextStep(spacing_name, font_name);
8782 int ystep_line = getMenuTextStep(spacing_line, font_info);
8783 int ystep_para = getMenuTextStep(spacing_para, font_info);
8791 int axis, button, hat, hat_value;
8794 *step, *prev_step, steps[] =
8796 { 356, 155, MARKER_BUTTON, "a", },
8797 { 396, 122, MARKER_BUTTON, "b", },
8798 { 320, 125, MARKER_BUTTON, "x", },
8799 { 358, 95, MARKER_BUTTON, "y", },
8800 { 162, 125, MARKER_BUTTON, "back", },
8801 { 216, 125, MARKER_BUTTON, "guide", },
8802 { 271, 125, MARKER_BUTTON, "start", },
8803 { 110, 200, MARKER_BUTTON, "dpleft", },
8804 { 146, 228, MARKER_BUTTON, "dpdown", },
8805 { 178, 200, MARKER_BUTTON, "dpright", },
8806 { 146, 172, MARKER_BUTTON, "dpup", },
8807 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8808 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8809 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8810 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8811 { 73, 141, MARKER_BUTTON, "leftstick", },
8812 { 282, 210, MARKER_BUTTON, "rightstick", },
8813 { 73, 141, MARKER_AXIS_X, "leftx", },
8814 { 73, 141, MARKER_AXIS_Y, "lefty", },
8815 { 282, 210, MARKER_AXIS_X, "rightx", },
8816 { 282, 210, MARKER_AXIS_Y, "righty", },
8819 if (!bitmaps_initialized)
8821 controller = LoadCustomImage("joystick/controller.png");
8822 button = LoadCustomImage("joystick/button.png");
8823 axis_x = LoadCustomImage("joystick/axis_x.png");
8824 axis_y = LoadCustomImage("joystick/axis_y.png");
8826 bitmaps_initialized = TRUE;
8829 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8832 // print info about the joystick we are watching
8833 Debug("joystick", "watching joystick %d: (%s)",
8834 SDL_JoystickInstanceID(joystick), name);
8835 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8836 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8837 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8840 // initialize mapping with GUID and name
8841 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8843 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8844 temp, name, SDL_GetPlatform());
8846 // loop through all steps (buttons and axes), getting joystick events
8847 for (i = 0; i < SDL_arraysize(steps) && !done;)
8849 Bitmap *marker = button; // initialize with reliable default value
8852 strcpy(step->mapping, mapping);
8856 step->hat_value = -1;
8858 marker = (step->marker == MARKER_BUTTON ? button :
8859 step->marker == MARKER_AXIS_X ? axis_x :
8860 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8864 while (!done && !next)
8866 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8867 alpha_ticks = SDL_GetTicks();
8874 else if (alpha < 128)
8880 int controller_x = SX + (SXSIZE - controller->width) / 2;
8881 int controller_y = SY + ystep_line;
8883 int marker_x = controller_x + step->x;
8884 int marker_y = controller_y + step->y;
8886 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8887 int ystart2 = ystart1 + ystep_name + ystep_line;
8891 DrawTextSCentered(ystart1, font_name, name);
8893 DrawTextSCentered(ystart2, font_info,
8894 "Press buttons and move axes on");
8895 ystart2 += ystep_line;
8896 DrawTextSCentered(ystart2, font_info,
8897 "your controller when indicated.");
8898 ystart2 += ystep_line;
8899 DrawTextSCentered(ystart2, font_info,
8900 "(Your controller may look different.)");
8901 ystart2 += ystep_para;
8903 #if defined(PLATFORM_ANDROID)
8904 DrawTextSCentered(ystart2, font_info,
8905 "To correct a mistake,");
8906 ystart2 += ystep_line;
8907 DrawTextSCentered(ystart2, font_info,
8908 "press the 'back' button.");
8909 ystart2 += ystep_line;
8910 DrawTextSCentered(ystart2, font_info,
8911 "To skip a button or axis,");
8912 ystart2 += ystep_line;
8913 DrawTextSCentered(ystart2, font_info,
8914 "press the 'menu' button.");
8916 DrawTextSCentered(ystart2, font_info,
8917 "To correct a mistake,");
8918 ystart2 += ystep_line;
8919 DrawTextSCentered(ystart2, font_info,
8920 "press the 'backspace' key.");
8921 ystart2 += ystep_line;
8922 DrawTextSCentered(ystart2, font_info,
8923 "To skip a button or axis,");
8924 ystart2 += ystep_line;
8925 DrawTextSCentered(ystart2, font_info,
8926 "press the 'return' key.");
8927 ystart2 += ystep_line;
8928 DrawTextSCentered(ystart2, font_info,
8929 "To exit, press the 'escape' key.");
8932 BlitBitmapMasked(controller, drawto, 0, 0,
8933 controller->width, controller->height,
8934 controller_x, controller_y);
8936 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8937 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8939 BlitBitmapMasked(marker, drawto, 0, 0,
8940 marker->width, marker->height,
8941 marker_x, marker_y);
8943 if (!screen_initialized)
8944 FadeIn(REDRAW_FIELD);
8948 screen_initialized = TRUE;
8950 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8952 // reset frame delay counter directly after updating screen
8953 ResetDelayCounter(&event_frame_delay);
8955 while (NextValidEvent(&event))
8959 case SDL_JOYAXISMOTION:
8960 if (event.jaxis.value > 20000 ||
8961 event.jaxis.value < -20000)
8963 for (j = 0; j < i; j++)
8964 if (steps[j].axis == event.jaxis.axis)
8969 if (step->marker != MARKER_AXIS_X &&
8970 step->marker != MARKER_AXIS_Y)
8973 step->axis = event.jaxis.axis;
8974 strcat(mapping, step->field);
8975 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8976 strcat(mapping, temp);
8984 case SDL_JOYHATMOTION:
8985 // ignore centering; we're probably just coming back
8986 // to the center from the previous item we set
8987 if (event.jhat.value == SDL_HAT_CENTERED)
8990 for (j = 0; j < i; j++)
8991 if (steps[j].hat == event.jhat.hat &&
8992 steps[j].hat_value == event.jhat.value)
8997 step->hat = event.jhat.hat;
8998 step->hat_value = event.jhat.value;
8999 strcat(mapping, step->field);
9000 snprintf(temp, sizeof(temp), ":h%u.%u,",
9001 event.jhat.hat, event.jhat.value );
9002 strcat(mapping, temp);
9009 case SDL_JOYBALLMOTION:
9012 case SDL_JOYBUTTONUP:
9013 for (j = 0; j < i; j++)
9014 if (steps[j].button == event.jbutton.button)
9019 step->button = event.jbutton.button;
9020 strcat(mapping, step->field);
9021 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
9022 strcat(mapping, temp);
9029 case SDL_FINGERDOWN:
9030 case SDL_MOUSEBUTTONDOWN:
9038 if (event.key.keysym.sym == KSYM_BackSpace ||
9039 event.key.keysym.sym == KSYM_Back)
9051 prev_step = &steps[i - 1];
9052 strcpy(mapping, prev_step->mapping);
9059 if (event.key.keysym.sym == KSYM_space ||
9060 event.key.keysym.sym == KSYM_Return ||
9061 event.key.keysym.sym == KSYM_Menu)
9070 if (event.key.keysym.sym == KSYM_Escape)
9080 program.exit_function(0);
9087 // do not handle events for longer than standard frame delay period
9088 if (DelayReached(&event_frame_delay))
9097 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9100 // activate mapping for this game
9101 SDL_GameControllerAddMapping(mapping);
9103 // save mapping to personal mappings
9104 SaveSetup_AddGameControllerMapping(mapping);
9107 // wait until the last pending event was removed from event queue
9108 while (NextValidEvent(&event));
9113 static int ConfigureJoystickMain(int player_nr)
9115 char *device_name = setup.input[player_nr].joy.device_name;
9116 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9117 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9118 int success = FALSE;
9121 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9122 return JOYSTICK_NOT_AVAILABLE;
9124 if (!joystick_active || !setup.input[player_nr].use_joystick)
9125 return JOYSTICK_NOT_AVAILABLE;
9128 FadeOut(REDRAW_FIELD);
9130 // close all joystick devices (potentially opened as game controllers)
9131 for (i = 0; i < SDL_NumJoysticks(); i++)
9132 SDLCloseJoystick(i);
9134 // open joystick device as plain joystick to configure as game controller
9135 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9137 // as the joystick was successfully opened before, this should not happen
9138 if (joystick == NULL)
9141 // create new game controller mapping (buttons and axes) for joystick device
9142 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9144 // close joystick (and maybe re-open as configured game controller later)
9145 SDL_JoystickClose(joystick);
9147 // re-open all joystick devices (potentially as game controllers)
9148 for (i = 0; i < SDL_NumJoysticks(); i++)
9151 // clear all joystick input actions for all joystick devices
9152 SDLClearJoystickState();
9154 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9157 void ConfigureJoystick(int player_nr)
9159 boolean state = ConfigureJoystickMain(player_nr);
9161 if (state != JOYSTICK_NOT_CONFIGURED)
9163 boolean success = (state == JOYSTICK_CONFIGURED);
9164 char message1[MAX_OUTPUT_LINESIZE + 1];
9165 char *message2 = (success ? "configured!" : "not available!");
9166 char *device_name = setup.input[player_nr].joy.device_name;
9167 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9168 int font_nr = FONT_TITLE_1;
9169 int font_height = getFontHeight(font_nr);
9170 int ypos1 = SYSIZE / 2 - font_height * 2;
9171 int ypos2 = SYSIZE / 2 - font_height * 1;
9172 DelayCounter wait_frame_delay = { 2000 };
9174 ResetDelayCounter(&wait_frame_delay);
9178 sprintf(message1, "Joystick %d", nr);
9180 DrawTextSCentered(ypos1, font_nr, message1);
9181 DrawTextSCentered(ypos2, font_nr, message2);
9183 while (!DelayReached(&wait_frame_delay))
9189 DrawSetupScreen_Input();
9192 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9194 if (y < video.screen_height / 3)
9196 // remap touch gadgets to access upper part of the screen
9197 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9198 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9200 else if (y > 2 * video.screen_height / 3)
9202 // remap touch gadgets to access lower part of the screen
9203 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9204 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9208 static boolean ConfigureVirtualButtonsMain(void)
9210 static char *customize_step_text[] =
9219 char grid_button[] =
9221 CHAR_GRID_BUTTON_LEFT,
9222 CHAR_GRID_BUTTON_RIGHT,
9223 CHAR_GRID_BUTTON_UP,
9224 CHAR_GRID_BUTTON_DOWN,
9225 CHAR_GRID_BUTTON_SNAP,
9226 CHAR_GRID_BUTTON_DROP
9235 int font_nr = FONT_INPUT_1_ACTIVE;
9236 int font_height = getFontHeight(font_nr);
9237 int ypos1 = SYSIZE / 2 - font_height * 2;
9238 int ypos2 = SYSIZE / 2 - font_height * 1;
9239 boolean success = FALSE;
9240 boolean finished = FALSE;
9242 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9243 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9244 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9245 boolean set_grid_button = FALSE;
9246 int nr = GRID_ACTIVE_NR();
9249 for (x = 0; x < MAX_GRID_XSIZE; x++)
9250 for (y = 0; y < MAX_GRID_YSIZE; y++)
9251 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9253 overlay.grid_button_highlight = grid_button[step_nr];
9258 FadeOut(REDRAW_FIELD);
9262 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9263 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9264 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9266 FadeIn(REDRAW_FIELD);
9268 SetOverlayShowGrid(TRUE);
9270 // map gadgets for setup touch buttons menu screen
9271 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9277 while (NextValidEvent(&event))
9279 int action = ACTION_NONE;
9281 // ---------- handle events and set the resulting action ----------
9287 UserEvent *user = (UserEvent *)&event;
9288 int id = user->value1;
9290 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9291 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9292 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9293 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9298 case EVENT_KEYPRESS:
9300 Key key = GetEventKey((KeyEvent *)&event);
9302 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9303 key == KSYM_BackSpace ||
9304 key == KSYM_Back ? ACTION_BACK :
9305 key == KSYM_Return ||
9307 key == KSYM_space ? ACTION_NEXT :
9312 case EVENT_KEYRELEASE:
9313 key_joystick_mapping = 0;
9316 case EVENT_BUTTONPRESS:
9317 case EVENT_BUTTONRELEASE:
9319 ButtonEvent *button = (ButtonEvent *)&event;
9321 motion_status = FALSE;
9323 if (button->type == EVENT_BUTTONPRESS)
9324 button_status = button->button;
9326 button_status = MB_RELEASED;
9328 if (HandleGadgets(button->x, button->y, button_status))
9330 // do not handle this button event anymore
9334 button->x += video.screen_xoffset;
9335 button->y += video.screen_yoffset;
9337 x = button->x * overlay.grid_xsize / video.screen_width;
9338 y = button->y * overlay.grid_ysize / video.screen_height;
9340 if (button->type == EVENT_BUTTONPRESS)
9343 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9344 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9346 set_grid_button = TRUE;
9349 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9353 case EVENT_MOTIONNOTIFY:
9355 MotionEvent *motion = (MotionEvent *)&event;
9357 motion_status = TRUE;
9359 if (HandleGadgets(motion->x, motion->y, button_status))
9361 // do not handle this button event anymore
9365 motion->x += video.screen_xoffset;
9366 motion->y += video.screen_yoffset;
9368 x = motion->x * overlay.grid_xsize / video.screen_width;
9369 y = motion->y * overlay.grid_ysize / video.screen_height;
9371 set_grid_button = TRUE;
9373 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9377 case SDL_WINDOWEVENT:
9378 HandleWindowEvent((WindowEvent *) &event);
9380 // check if device has been rotated
9381 if (nr != GRID_ACTIVE_NR())
9383 nr = GRID_ACTIVE_NR();
9385 for (x = 0; x < MAX_GRID_XSIZE; x++)
9386 for (y = 0; y < MAX_GRID_YSIZE; y++)
9387 grid_button_old[x][y] = grid_button_tmp[x][y] =
9388 overlay.grid_button[x][y];
9393 case SDL_APP_WILLENTERBACKGROUND:
9394 case SDL_APP_DIDENTERBACKGROUND:
9395 case SDL_APP_WILLENTERFOREGROUND:
9396 case SDL_APP_DIDENTERFOREGROUND:
9397 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9401 HandleOtherEvents(&event);
9405 // ---------- perform action set by handling events ----------
9407 if (action == ACTION_ESCAPE)
9409 // abort and restore the old key bindings
9411 for (x = 0; x < MAX_GRID_XSIZE; x++)
9412 for (y = 0; y < MAX_GRID_YSIZE; y++)
9413 overlay.grid_button[x][y] = grid_button_old[x][y];
9415 FadeSkipNextFadeIn();
9419 else if (action == ACTION_BACK)
9421 // keep the configured key bindings and go to previous page
9427 FadeSkipNextFadeIn();
9432 else if (action == ACTION_NEXT)
9434 // keep the configured key bindings and go to next page
9438 // all virtual buttons configured
9446 if (action != ACTION_NONE && !finished)
9448 for (x = 0; x < MAX_GRID_XSIZE; x++)
9449 for (y = 0; y < MAX_GRID_YSIZE; y++)
9450 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9452 overlay.grid_button_highlight = grid_button[step_nr];
9454 // configure next virtual button
9458 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9459 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9460 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9463 if (set_grid_button)
9465 overlay.grid_button[x][y] =
9466 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9467 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9468 grid_button_tmp[x][y]);
9470 set_grid_button = FALSE;
9477 for (x = 0; x < MAX_GRID_XSIZE; x++)
9478 for (y = 0; y < MAX_GRID_YSIZE; y++)
9479 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9481 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9483 SetOverlayShowGrid(FALSE);
9488 void ConfigureVirtualButtons(void)
9490 boolean success = ConfigureVirtualButtonsMain();
9492 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9493 SCREEN_MASK_TOUCH2);
9497 int font_nr = FONT_TITLE_1;
9498 int font_height = getFontHeight(font_nr);
9499 int ypos1 = SYSIZE / 2 - font_height * 2;
9500 int ypos2 = SYSIZE / 2 - font_height * 1;
9501 DelayCounter wait_frame_delay = { 2000 };
9503 ResetDelayCounter(&wait_frame_delay);
9507 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9508 DrawTextSCentered(ypos2, font_nr, "configured!");
9510 while (!DelayReached(&wait_frame_delay))
9517 void DrawSetupScreen(void)
9522 if (setup_mode == SETUP_MODE_INPUT)
9523 DrawSetupScreen_Input();
9524 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9525 DrawChooseTree(&scores_type_current);
9526 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9527 DrawChooseTree(&game_speed_current);
9528 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9529 DrawChooseTree(&scroll_delay_current);
9530 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9531 DrawChooseTree(&snapshot_mode_current);
9532 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9533 DrawChooseTree(&window_size_current);
9534 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9535 DrawChooseTree(&scaling_type_current);
9536 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9537 DrawChooseTree(&rendering_mode_current);
9538 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9539 DrawChooseTree(&vsync_mode_current);
9540 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9541 DrawChooseTree(&artwork.gfx_current);
9542 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9543 DrawChooseTree(&artwork.snd_current);
9544 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9545 DrawChooseTree(&artwork.mus_current);
9546 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9547 DrawChooseTree(&volume_simple_current);
9548 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9549 DrawChooseTree(&volume_loops_current);
9550 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9551 DrawChooseTree(&volume_music_current);
9552 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9553 DrawChooseTree(&touch_control_current);
9554 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9555 DrawChooseTree(&move_distance_current);
9556 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9557 DrawChooseTree(&drop_distance_current);
9558 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9559 DrawChooseTree(&transparency_current);
9560 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9561 DrawChooseTree(&grid_size_current[0][0]);
9562 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9563 DrawChooseTree(&grid_size_current[0][1]);
9564 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9565 DrawChooseTree(&grid_size_current[1][0]);
9566 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9567 DrawChooseTree(&grid_size_current[1][1]);
9569 DrawSetupScreen_Generic();
9571 PlayMenuSoundsAndMusic();
9574 void RedrawSetupScreenAfterFullscreenToggle(void)
9576 if (setup_mode == SETUP_MODE_GRAPHICS ||
9577 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9579 // update list selection from "setup.window_scaling_percent"
9580 execSetupGraphics_setWindowSizes(TRUE);
9586 void RedrawSetupScreenAfterScreenRotation(int nr)
9590 if (setup_mode == SETUP_MODE_TOUCH)
9592 // update virtual button settings (depending on screen orientation)
9595 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9597 // save already configured virtual buttons
9598 for (x = 0; x < MAX_GRID_XSIZE; x++)
9599 for (y = 0; y < MAX_GRID_YSIZE; y++)
9600 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9604 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9606 if (setup_mode == SETUP_MODE_INPUT)
9607 HandleSetupScreen_Input(mx, my, dx, dy, button);
9608 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9609 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9610 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9611 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9612 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9613 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9614 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9615 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9616 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9617 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9618 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9619 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9620 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9621 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9622 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9623 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9624 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9625 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9626 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9627 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9628 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9629 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9630 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9631 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9632 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9633 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9634 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9635 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9636 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9637 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9638 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9639 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9640 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9641 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9642 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9643 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9644 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9645 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9646 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9647 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9648 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9649 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9650 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9651 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9653 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9656 void HandleGameActions(void)
9658 if (CheckRestartGame())
9661 if (game_status != GAME_MODE_PLAYING)
9664 GameActions(); // main game loop
9666 if (tape.auto_play && !tape.playing)
9667 AutoPlayTapesContinue(); // continue automatically playing next tape
9671 // ---------- new screen button stuff --------------------------------------
9675 int gfx_unpressed, gfx_pressed, gfx_active;
9676 struct MenuPosInfo *pos;
9677 boolean *check_value;
9680 unsigned int event_mask;
9681 boolean is_touch_button;
9683 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9686 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE, -1,
9687 &menu.main.button.prev_level, NULL,
9688 SCREEN_CTRL_ID_PREV_LEVEL,
9690 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9691 FALSE, "previous level"
9694 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE, -1,
9695 &menu.main.button.next_level, NULL,
9696 SCREEN_CTRL_ID_NEXT_LEVEL,
9698 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9702 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE, -1,
9703 &menu.scores.button.prev_level, NULL,
9704 SCREEN_CTRL_ID_PREV_LEVEL2,
9705 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9706 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9707 FALSE, "previous level"
9710 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE, -1,
9711 &menu.scores.button.next_level, NULL,
9712 SCREEN_CTRL_ID_NEXT_LEVEL2,
9713 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9714 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9718 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE, -1,
9719 &menu.scores.button.prev_score, NULL,
9720 SCREEN_CTRL_ID_PREV_SCORE,
9721 SCREEN_MASK_SCORES_INFO,
9722 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9723 FALSE, "previous score"
9726 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE, -1,
9727 &menu.scores.button.next_score, NULL,
9728 SCREEN_CTRL_ID_NEXT_SCORE,
9729 SCREEN_MASK_SCORES_INFO,
9730 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9734 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE, -1,
9735 &menu.scores.button.play_tape, NULL,
9736 SCREEN_CTRL_ID_PLAY_TAPE,
9737 SCREEN_MASK_SCORES_INFO,
9742 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE, -1,
9743 &menu.main.button.first_level, NULL,
9744 SCREEN_CTRL_ID_FIRST_LEVEL,
9747 FALSE, "first level"
9750 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE, -1,
9751 &menu.main.button.last_level, NULL,
9752 SCREEN_CTRL_ID_LAST_LEVEL,
9758 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE, -1,
9759 &menu.main.button.level_number, NULL,
9760 SCREEN_CTRL_ID_LEVEL_NUMBER,
9763 FALSE, "level number"
9766 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE, -1,
9767 &menu.setup.button.prev_player, NULL,
9768 SCREEN_CTRL_ID_PREV_PLAYER,
9770 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9771 FALSE, "previous player"
9774 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE, -1,
9775 &menu.setup.button.next_player, NULL,
9776 SCREEN_CTRL_ID_NEXT_PLAYER,
9778 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9779 FALSE, "next player"
9782 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE, -1,
9783 &menu.main.button.insert_solution, NULL,
9784 SCREEN_CTRL_ID_INSERT_SOLUTION,
9785 SCREEN_MASK_MAIN_HAS_SOLUTION,
9787 FALSE, "insert solution tape"
9790 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE, -1,
9791 &menu.main.button.play_solution, NULL,
9792 SCREEN_CTRL_ID_PLAY_SOLUTION,
9793 SCREEN_MASK_MAIN_HAS_SOLUTION,
9795 FALSE, "play solution tape"
9798 IMG_MENU_BUTTON_LEVELSET_INFO, IMG_MENU_BUTTON_LEVELSET_INFO_PRESSED,
9799 IMG_MENU_BUTTON_LEVELSET_INFO_ACTIVE,
9800 &menu.main.button.levelset_info, NULL,
9801 SCREEN_CTRL_ID_LEVELSET_INFO,
9802 SCREEN_MASK_MAIN_HAS_SET_INFO,
9804 FALSE, "show level set info"
9807 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE, -1,
9808 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9809 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9811 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9812 FALSE, "switch ECS/AGA chipset"
9815 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK, -1,
9816 &menu.setup.button.touch_back, NULL,
9817 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9820 TRUE, "previous page"
9823 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT, -1,
9824 &menu.setup.button.touch_next, NULL,
9825 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9831 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2, -1,
9832 &menu.setup.button.touch_back2, NULL,
9833 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9836 TRUE, "previous page"
9839 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2, -1,
9840 &menu.setup.button.touch_next2, NULL,
9841 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9850 int gfx_unpressed, gfx_pressed;
9854 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9857 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9858 -1, -1, // these values are not constant, but can change at runtime
9859 SCREEN_CTRL_ID_SCROLL_UP,
9863 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9864 -1, -1, // these values are not constant, but can change at runtime
9865 SCREEN_CTRL_ID_SCROLL_DOWN,
9872 int gfx_unpressed, gfx_pressed;
9878 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9881 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9882 -1, -1, // these values are not constant, but can change at runtime
9883 -1, -1, // these values are not constant, but can change at runtime
9884 GD_TYPE_SCROLLBAR_VERTICAL,
9885 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9886 "scroll level series vertically"
9898 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9901 IMG_SETUP_INPUT_TEXT,
9902 SCREEN_CTRL_ID_NETWORK_SERVER,
9903 -1, -1, // these values are not constant, but can change at runtime
9904 MAX_SETUP_TEXT_INPUT_LEN,
9905 network_server_hostname,
9906 "Network Server Hostname / IP"
9910 static void CreateScreenMenubuttons(void)
9912 struct GadgetInfo *gi;
9913 unsigned int event_mask;
9916 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9918 struct MenuPosInfo *pos = menubutton_info[i].pos;
9919 int screen_mask = menubutton_info[i].screen_mask;
9920 boolean is_touch_button = menubutton_info[i].is_touch_button;
9921 boolean is_check_button = menubutton_info[i].check_value != NULL;
9922 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9923 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9924 menubutton_info[i].gfx_unpressed);
9925 boolean has_gfx_active = (menubutton_info[i].gfx_active != -1);
9926 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9927 Bitmap *gd_bitmap_unpressed_alt, *gd_bitmap_pressed_alt;
9928 int gfx_unpressed, gfx_pressed;
9929 int gfx_unpressed_alt, gfx_pressed_alt;
9930 int x, y, width, height;
9931 int gd_x1, gd_x2, gd_y1, gd_y2;
9932 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9933 int id = menubutton_info[i].gadget_id;
9934 int type = GD_TYPE_NORMAL_BUTTON;
9935 boolean checked = FALSE;
9937 // do not use touch buttons if overlay touch buttons are disabled
9938 if (is_touch_button && !setup.touch.overlay_buttons)
9941 event_mask = menubutton_info[i].event_mask;
9943 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9944 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9946 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9947 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9949 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9950 gfx_pressed = menubutton_info[i].gfx_pressed;
9951 gfx_unpressed_alt = gfx_unpressed;
9952 gfx_pressed_alt = gfx_pressed;
9956 gfx_unpressed_alt = menubutton_info[i].gfx_active;
9958 type = GD_TYPE_CHECK_BUTTON_2;
9960 if (menubutton_info[i].check_value != NULL)
9961 checked = *menubutton_info[i].check_value;
9964 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9965 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9966 gd_bitmap_unpressed_alt = graphic_info[gfx_unpressed_alt].bitmap;
9967 gd_bitmap_pressed_alt = graphic_info[gfx_pressed_alt].bitmap;
9969 gd_x1 = graphic_info[gfx_unpressed].src_x;
9970 gd_y1 = graphic_info[gfx_unpressed].src_y;
9971 gd_x2 = graphic_info[gfx_pressed].src_x;
9972 gd_y2 = graphic_info[gfx_pressed].src_y;
9974 gd_x1a = graphic_info[gfx_unpressed_alt].src_x;
9975 gd_y1a = graphic_info[gfx_unpressed_alt].src_y;
9976 gd_x2a = graphic_info[gfx_pressed_alt].src_x;
9977 gd_y2a = graphic_info[gfx_pressed_alt].src_y;
9979 if (has_gfx_pressed)
9981 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9982 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9985 if (is_check_button)
9987 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9988 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9989 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9990 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9992 type = GD_TYPE_CHECK_BUTTON;
9994 if (menubutton_info[i].check_value != NULL)
9995 checked = *menubutton_info[i].check_value;
9998 if (is_score_button)
10000 // if x/y set to -1, dynamically place buttons next to title text
10001 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
10003 // special compatibility handling for "Snake Bite" graphics set
10004 if (strPrefix(leveldir_current->identifier, "snake_bite"))
10005 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
10007 // use "SX" here to center buttons (ignore horizontal draw offset)
10009 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
10010 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
10011 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
10012 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
10014 // use "mSY" here to place buttons (respect vertical draw offset)
10016 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
10017 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
10020 if (id == SCREEN_CTRL_ID_LEVELSET_INFO)
10022 if (pos->x == -1 && pos->y == -1)
10024 // use "SX" here to place button (ignore draw offsets)
10025 x = SX + SXSIZE - 2 * TILESIZE;
10026 y = SY + SYSIZE - 2 * TILESIZE;
10028 // special compatibility handling for "BD2K3" graphics set
10029 if (strPrefix(leveldir_current->identifier, "BD2K3"))
10030 x = SX + TILESIZE + MINI_TILESIZE;
10032 // special compatibility handling for "jue0" graphics set
10033 if (strPrefix(artwork.gfx_current_identifier, "jue0"))
10035 x = SX + SXSIZE - 4 * TILESIZE;
10036 y = SY + SYSIZE - 3 * TILESIZE;
10041 gi = CreateGadget(GDI_CUSTOM_ID, id,
10042 GDI_CUSTOM_TYPE_ID, i,
10043 GDI_IMAGE_ID, gfx_unpressed,
10044 GDI_INFO_TEXT, menubutton_info[i].infotext,
10048 GDI_HEIGHT, height,
10050 GDI_STATE, GD_BUTTON_UNPRESSED,
10051 GDI_CHECKED, checked,
10052 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10053 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10054 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed_alt, gd_x1a, gd_y1a,
10055 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed_alt, gd_x2a, gd_y2a,
10056 GDI_DIRECT_DRAW, FALSE,
10057 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10058 GDI_EVENT_MASK, event_mask,
10059 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10063 Fail("cannot create gadget");
10065 screen_gadget[id] = gi;
10069 static void CreateScreenScrollbuttons(void)
10071 struct GadgetInfo *gi;
10072 unsigned int event_mask;
10075 // these values are not constant, but can change at runtime
10076 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10077 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10078 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10079 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10081 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10083 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10084 int gfx_unpressed, gfx_pressed;
10085 int x, y, width, height;
10086 int gd_x1, gd_x2, gd_y1, gd_y2;
10087 int id = scrollbutton_info[i].gadget_id;
10089 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10091 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10092 y = mSY + scrollbutton_info[i].y;
10093 width = SC_SCROLLBUTTON_XSIZE;
10094 height = SC_SCROLLBUTTON_YSIZE;
10096 // correct scrollbar position if placed outside menu (playfield) area
10097 if (x > SX + SC_SCROLL_UP_XPOS)
10098 x = SX + SC_SCROLL_UP_XPOS;
10100 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10101 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10102 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10104 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10105 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10106 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10107 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10108 gd_x1 = graphic_info[gfx_unpressed].src_x;
10109 gd_y1 = graphic_info[gfx_unpressed].src_y;
10110 gd_x2 = graphic_info[gfx_pressed].src_x;
10111 gd_y2 = graphic_info[gfx_pressed].src_y;
10113 gi = CreateGadget(GDI_CUSTOM_ID, id,
10114 GDI_CUSTOM_TYPE_ID, i,
10115 GDI_IMAGE_ID, gfx_unpressed,
10116 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10120 GDI_HEIGHT, height,
10121 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10122 GDI_STATE, GD_BUTTON_UNPRESSED,
10123 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10124 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10125 GDI_DIRECT_DRAW, FALSE,
10126 GDI_EVENT_MASK, event_mask,
10127 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10131 Fail("cannot create gadget");
10133 screen_gadget[id] = gi;
10137 static void CreateScreenScrollbars(void)
10141 // these values are not constant, but can change at runtime
10142 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10143 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10144 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10145 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10147 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10149 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10150 int gfx_unpressed, gfx_pressed;
10151 int x, y, width, height;
10152 int gd_x1, gd_x2, gd_y1, gd_y2;
10153 struct GadgetInfo *gi;
10154 int items_max, items_visible, item_position;
10155 unsigned int event_mask;
10156 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10157 int id = scrollbar_info[i].gadget_id;
10159 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10161 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10162 y = mSY + scrollbar_info[i].y;
10163 width = scrollbar_info[i].width;
10164 height = scrollbar_info[i].height;
10166 // correct scrollbar position if placed outside menu (playfield) area
10167 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10168 x = SX + SC_SCROLL_VERTICAL_XPOS;
10170 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10171 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10173 items_max = num_page_entries;
10174 items_visible = num_page_entries;
10177 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10178 gfx_pressed = scrollbar_info[i].gfx_pressed;
10179 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10180 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10181 gd_x1 = graphic_info[gfx_unpressed].src_x;
10182 gd_y1 = graphic_info[gfx_unpressed].src_y;
10183 gd_x2 = graphic_info[gfx_pressed].src_x;
10184 gd_y2 = graphic_info[gfx_pressed].src_y;
10186 gi = CreateGadget(GDI_CUSTOM_ID, id,
10187 GDI_CUSTOM_TYPE_ID, i,
10188 GDI_IMAGE_ID, gfx_unpressed,
10189 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10193 GDI_HEIGHT, height,
10194 GDI_TYPE, scrollbar_info[i].type,
10195 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10196 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10197 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10198 GDI_WHEEL_AREA_X, SX,
10199 GDI_WHEEL_AREA_Y, SY,
10200 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10201 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10202 GDI_STATE, GD_BUTTON_UNPRESSED,
10203 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10204 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10205 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10206 GDI_DIRECT_DRAW, FALSE,
10207 GDI_EVENT_MASK, event_mask,
10208 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10212 Fail("cannot create gadget");
10214 screen_gadget[id] = gi;
10218 static void CreateScreenTextInputGadgets(void)
10222 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10224 int graphic = textinput_info[i].graphic;
10225 struct GraphicInfo *gd = &graphic_info[graphic];
10226 int gd_x1 = gd->src_x;
10227 int gd_y1 = gd->src_y;
10228 int gd_x2 = gd->src_x + gd->active_xoffset;
10229 int gd_y2 = gd->src_y + gd->active_yoffset;
10230 struct GadgetInfo *gi;
10231 unsigned int event_mask;
10232 int id = textinput_info[i].gadget_id;
10233 int x = textinput_info[i].x;
10234 int y = textinput_info[i].y;
10236 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10238 gi = CreateGadget(GDI_CUSTOM_ID, id,
10239 GDI_CUSTOM_TYPE_ID, i,
10240 GDI_INFO_TEXT, textinput_info[i].infotext,
10243 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10244 GDI_TEXT_VALUE, textinput_info[i].value,
10245 GDI_TEXT_SIZE, textinput_info[i].size,
10246 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10247 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10248 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10249 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10250 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10251 GDI_DESIGN_WIDTH, gd->width,
10252 GDI_EVENT_MASK, event_mask,
10253 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10254 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10258 Fail("cannot create gadget");
10260 screen_gadget[id] = gi;
10264 void CreateScreenGadgets(void)
10266 CreateScreenMenubuttons();
10268 CreateScreenScrollbuttons();
10269 CreateScreenScrollbars();
10271 CreateScreenTextInputGadgets();
10274 void FreeScreenGadgets(void)
10278 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10279 FreeGadget(screen_gadget[i]);
10282 static void RedrawScreenMenuGadgets(int screen_mask)
10286 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10287 if (screen_mask & menubutton_info[i].screen_mask)
10288 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10291 static void MapScreenMenuGadgets(int screen_mask)
10295 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10296 if (screen_mask & menubutton_info[i].screen_mask)
10297 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10300 static void UnmapScreenMenuGadgets(int screen_mask)
10304 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10306 if (screen_mask & menubutton_info[i].screen_mask)
10308 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10310 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10311 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10312 screen_gadget[menubutton_info[i].gadget_id]->y,
10313 screen_gadget[menubutton_info[i].gadget_id]->width,
10314 screen_gadget[menubutton_info[i].gadget_id]->height);
10319 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10322 MapScreenMenuGadgets(screen_mask);
10324 UnmapScreenMenuGadgets(screen_mask);
10327 static void MapScreenGadgets(int num_entries)
10331 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10334 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10335 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10337 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10338 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10341 static void UnmapScreenGadgets(void)
10345 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10346 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10348 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10349 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10352 static void MapScreenTreeGadgets(TreeInfo *ti)
10354 MapScreenGadgets(numTreeInfoInGroup(ti));
10357 static void UnmapScreenTreeGadgets(void)
10359 UnmapScreenGadgets();
10362 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10364 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10365 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10366 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10367 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10369 if (pos_1->x == -1 && pos_1->y == -1)
10370 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10372 if (pos_2->x == -1 && pos_2->y == -1)
10373 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10376 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10378 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10379 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10381 // set gadget position dynamically, pre-defined or off-screen
10382 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10383 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10385 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10386 MapGadget(gi); // (needed if deactivated on last score page)
10389 static void HandleScreenGadgets(struct GadgetInfo *gi)
10391 int id = gi->custom_id;
10392 int button = gi->event.button;
10393 int step = (button == MB_LEFTBUTTON ? 1 :
10394 button == MB_MIDDLEBUTTON ? 5 :
10395 button == MB_RIGHTBUTTON ? 10 : 1);
10399 case SCREEN_CTRL_ID_PREV_LEVEL:
10400 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10403 case SCREEN_CTRL_ID_NEXT_LEVEL:
10404 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10407 case SCREEN_CTRL_ID_PREV_LEVEL2:
10408 HandleHallOfFame_SelectLevel(step, -1);
10411 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10412 HandleHallOfFame_SelectLevel(step, +1);
10415 case SCREEN_CTRL_ID_PREV_SCORE:
10416 HandleScoreInfo_SelectScore(step, -1);
10419 case SCREEN_CTRL_ID_NEXT_SCORE:
10420 HandleScoreInfo_SelectScore(step, +1);
10423 case SCREEN_CTRL_ID_PLAY_TAPE:
10424 HandleScoreInfo_PlayTape();
10427 case SCREEN_CTRL_ID_FIRST_LEVEL:
10428 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10431 case SCREEN_CTRL_ID_LAST_LEVEL:
10432 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10435 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10436 CloseDoor(DOOR_CLOSE_2);
10437 SetGameStatus(GAME_MODE_LEVELNR);
10438 DrawChooseLevelNr();
10441 case SCREEN_CTRL_ID_PREV_PLAYER:
10442 HandleSetupScreen_Input_Player(step, -1);
10445 case SCREEN_CTRL_ID_NEXT_PLAYER:
10446 HandleSetupScreen_Input_Player(step, +1);
10449 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10450 InsertSolutionTape();
10453 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10454 PlaySolutionTape();
10457 case SCREEN_CTRL_ID_LEVELSET_INFO:
10458 DrawInfoScreen_FromMainMenu(INFO_MODE_LEVELSET);
10461 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10462 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10466 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10467 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10468 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10469 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10470 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10473 case SCREEN_CTRL_ID_SCROLL_UP:
10474 if (game_status == GAME_MODE_NAMES)
10475 HandleChoosePlayerName(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10476 else if (game_status == GAME_MODE_LEVELS)
10477 HandleChooseLevelSet(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10478 else if (game_status == GAME_MODE_LEVELNR)
10479 HandleChooseLevelNr(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10480 else if (game_status == GAME_MODE_SETUP)
10481 HandleSetupScreen(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10482 else if (game_status == GAME_MODE_INFO)
10483 HandleInfoScreen(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10484 else if (game_status == GAME_MODE_SCORES)
10485 HandleHallOfFame(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10488 case SCREEN_CTRL_ID_SCROLL_DOWN:
10489 if (game_status == GAME_MODE_NAMES)
10490 HandleChoosePlayerName(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10491 else if (game_status == GAME_MODE_LEVELS)
10492 HandleChooseLevelSet(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10493 else if (game_status == GAME_MODE_LEVELNR)
10494 HandleChooseLevelNr(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10495 else if (game_status == GAME_MODE_SETUP)
10496 HandleSetupScreen(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10497 else if (game_status == GAME_MODE_INFO)
10498 HandleInfoScreen(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10499 else if (game_status == GAME_MODE_SCORES)
10500 HandleHallOfFame(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10503 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10504 if (game_status == GAME_MODE_NAMES)
10505 HandleChoosePlayerName(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10506 else if (game_status == GAME_MODE_LEVELS)
10507 HandleChooseLevelSet(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10508 else if (game_status == GAME_MODE_LEVELNR)
10509 HandleChooseLevelNr(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10510 else if (game_status == GAME_MODE_SETUP)
10511 HandleSetupScreen(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10512 else if (game_status == GAME_MODE_INFO)
10513 HandleInfoScreen(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10514 else if (game_status == GAME_MODE_SCORES)
10515 HandleHallOfFame(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10518 case SCREEN_CTRL_ID_NETWORK_SERVER:
10520 if (!strEqual(gi->textinput.value, ""))
10522 setString(&setup.network_server_hostname, gi->textinput.value);
10524 network.server_host = setup.network_server_hostname;
10528 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10530 network.server_host = NULL;
10533 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10534 network.server_host = NULL;
10536 execSetupGame_setNetworkServerText();
10548 void HandleScreenGadgetKeys(Key key)
10550 if (key == setup.shortcut.tape_play)
10551 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10554 void DumpScreenIdentifiers(void)
10558 Print("Active screen elements on current screen:\n");
10560 for (i = 0; main_controls[i].nr != -1; i++)
10562 struct MainControlInfo *mci = &main_controls[i];
10564 if (mci->button_graphic != -1)
10566 char *token = getTokenFromImageID(mci->button_graphic);
10568 Print("- '%s'\n", token);
10575 boolean DoScreenAction(int image_id)
10579 if (game_status != GAME_MODE_MAIN)
10582 for (i = 0; main_controls[i].nr != -1; i++)
10584 struct MainControlInfo *mci = &main_controls[i];
10585 struct MenuPosInfo *pos = mci->pos_button;
10587 if (mci->button_graphic == image_id)
10589 int x = mSX + pos->x;
10590 int y = mSY + pos->y;
10592 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10601 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10603 // get tree info node of newly added level or artwork set
10604 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10605 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10607 if (tree_node_new == NULL) // should not happen
10610 // if request dialog is active, do nothing
10611 if (game.request_active)
10614 if (game_status == GAME_MODE_MAIN &&
10615 tree_type == TREE_TYPE_LEVEL_DIR)
10617 // when adding new level set in main menu, select it as current level set
10619 // change current level set to newly added level set from zip file
10620 leveldir_current = tree_node_new;
10622 // change current level number to first level of newly added level set
10623 level_nr = leveldir_current->first_level;
10625 // redraw screen to reflect changed level set
10628 // save this level set and level number as last selected level set
10629 SaveLevelSetup_LastSeries();
10630 SaveLevelSetup_SeriesInfo();
10632 else if (game_status == GAME_MODE_LEVELS &&
10633 tree_type == TREE_TYPE_LEVEL_DIR)
10635 // when adding new level set in level set menu, set cursor and update screen
10637 leveldir_current = tree_node_new;
10639 DrawChooseTree(&leveldir_current);
10641 else if (game_status == GAME_MODE_SETUP)
10643 // when adding new artwork set in setup menu, set cursor and update screen
10645 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10646 tree_type == TREE_TYPE_GRAPHICS_DIR)
10648 artwork.gfx_current = tree_node_new;
10650 DrawChooseTree(&artwork.gfx_current);
10652 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10653 tree_type == TREE_TYPE_SOUNDS_DIR)
10655 artwork.snd_current = tree_node_new;
10657 DrawChooseTree(&artwork.snd_current);
10659 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10660 tree_type == TREE_TYPE_MUSIC_DIR)
10662 artwork.mus_current = tree_node_new;
10664 DrawChooseTree(&artwork.mus_current);
10669 static int UploadTapes(void)
10671 SetGameStatus(GAME_MODE_LOADING);
10673 FadeSetEnterScreen();
10674 FadeOut(REDRAW_ALL);
10676 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10678 FadeIn(REDRAW_ALL);
10680 DrawInitTextHead("Uploading tapes");
10682 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10683 global.autoplay_leveldir = "ALL";
10684 global.autoplay_all = TRUE;
10686 int num_tapes_uploaded = AutoPlayTapes();
10688 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10689 global.autoplay_leveldir = NULL;
10690 global.autoplay_all = FALSE;
10692 SetGameStatus(GAME_MODE_MAIN);
10696 return num_tapes_uploaded;
10699 static boolean OfferUploadTapes(void)
10701 if (!Request(setup.has_remaining_tapes ?
10702 "Upload missing tapes to the high score server now?" :
10703 "Upload all your tapes to the high score server now?", REQ_ASK))
10706 // when uploading tapes, make sure that high score server is enabled
10707 runtime.use_api_server = setup.use_api_server = TRUE;
10709 int num_tapes_uploaded = UploadTapes();
10712 if (num_tapes_uploaded < 0)
10714 num_tapes_uploaded = -num_tapes_uploaded - 1;
10716 if (num_tapes_uploaded == 0)
10717 sprintf(message, "Upload failed! No tapes uploaded!");
10718 else if (num_tapes_uploaded == 1)
10719 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10721 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10722 num_tapes_uploaded);
10724 Request(message, REQ_CONFIRM);
10726 // if uploading tapes failed, add tape upload entry to setup menu
10727 setup.provide_uploading_tapes = TRUE;
10728 setup.has_remaining_tapes = TRUE;
10730 SaveSetup_ServerSetup();
10735 if (num_tapes_uploaded == 0)
10736 sprintf(message, "No tapes uploaded!");
10737 else if (num_tapes_uploaded == 1)
10738 sprintf(message, "1 tape uploaded!");
10740 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10742 Request(message, REQ_CONFIRM);
10744 if (num_tapes_uploaded > 0)
10745 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10747 // after all tapes have been uploaded, remove entry from setup menu
10748 setup.provide_uploading_tapes = FALSE;
10749 setup.has_remaining_tapes = FALSE;
10751 SaveSetup_ServerSetup();
10756 static void CheckUploadTapes(void)
10758 if (!setup.ask_for_uploading_tapes)
10761 // after asking for uploading tapes, do not ask again
10762 setup.ask_for_uploading_tapes = FALSE;
10763 setup.ask_for_remaining_tapes = FALSE;
10765 if (directoryExists(getTapeDir(NULL)))
10767 boolean tapes_uploaded = OfferUploadTapes();
10769 if (!tapes_uploaded)
10771 Request(setup.has_remaining_tapes ?
10772 "You can upload missing tapes from the setup menu later!" :
10773 "You can upload your tapes from the setup menu later!",
10779 // if tapes directory does not exist yet, never offer uploading all tapes
10780 setup.provide_uploading_tapes = FALSE;
10783 SaveSetup_ServerSetup();
10786 static void UpgradePlayerUUID(void)
10788 ApiResetUUIDAsThread(getUUID());
10791 static void CheckUpgradePlayerUUID(void)
10793 if (setup.player_version > 1)
10796 UpgradePlayerUUID();
10799 void CheckApiServerTasks(void)
10801 // check if the player's UUID has to be upgraded
10802 CheckUpgradePlayerUUID();
10804 // check if there are any tapes to be uploaded
10805 CheckUploadTapes();