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 - \
195 #define MAX_INFO_ELEMENTS_IN_ARRAY 128
196 #define MAX_INFO_ELEMENTS_ON_SCREEN (SYSIZE / TILEY)
197 #define MAX_INFO_ELEMENTS MIN(MAX_INFO_ELEMENTS_IN_ARRAY, \
198 MAX_INFO_ELEMENTS_ON_SCREEN)
199 #define STD_INFO_ELEMENTS_ON_SCREEN 10
200 #define DYN_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
201 MENU_SCREEN_INFO_YSTEP)
202 #define DEFAULT_INFO_ELEMENTS MIN(STD_INFO_ELEMENTS_ON_SCREEN,\
203 DYN_INFO_ELEMENTS_ON_SCREEN)
204 #define NUM_INFO_ELEMENTS_FROM_CONF \
205 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
206 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
207 DEFAULT_INFO_ELEMENTS)
208 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(NUM_INFO_ELEMENTS_FROM_CONF,\
210 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
211 #define MAX_MENU_TEXT_LENGTH_BIG 13
212 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
214 // screen gadget identifiers
215 #define SCREEN_CTRL_ID_PREV_LEVEL 0
216 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
217 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
218 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
219 #define SCREEN_CTRL_ID_PREV_SCORE 4
220 #define SCREEN_CTRL_ID_NEXT_SCORE 5
221 #define SCREEN_CTRL_ID_PLAY_TAPE 6
222 #define SCREEN_CTRL_ID_FIRST_LEVEL 7
223 #define SCREEN_CTRL_ID_LAST_LEVEL 8
224 #define SCREEN_CTRL_ID_LEVEL_NUMBER 9
225 #define SCREEN_CTRL_ID_PREV_PLAYER 10
226 #define SCREEN_CTRL_ID_NEXT_PLAYER 11
227 #define SCREEN_CTRL_ID_INSERT_SOLUTION 12
228 #define SCREEN_CTRL_ID_PLAY_SOLUTION 13
229 #define SCREEN_CTRL_ID_LEVELSET_INFO 14
230 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 15
231 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 16
232 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 17
233 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 18
234 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 19
236 #define NUM_SCREEN_MENUBUTTONS 20
238 #define SCREEN_CTRL_ID_SCROLL_UP 20
239 #define SCREEN_CTRL_ID_SCROLL_DOWN 21
240 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 22
241 #define SCREEN_CTRL_ID_NETWORK_SERVER 23
243 #define NUM_SCREEN_GADGETS 24
245 #define NUM_SCREEN_SCROLLBUTTONS 2
246 #define NUM_SCREEN_SCROLLBARS 1
247 #define NUM_SCREEN_TEXTINPUT 1
249 #define SCREEN_MASK_MAIN (1 << 0)
250 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
251 #define SCREEN_MASK_MAIN_HAS_SET_INFO (1 << 2)
252 #define SCREEN_MASK_INPUT (1 << 3)
253 #define SCREEN_MASK_TOUCH (1 << 4)
254 #define SCREEN_MASK_TOUCH2 (1 << 5)
255 #define SCREEN_MASK_SCORES (1 << 6)
256 #define SCREEN_MASK_SCORES_INFO (1 << 7)
258 // graphic position and size values for buttons and scrollbars
259 #define SC_MENUBUTTON_XSIZE TILEX
260 #define SC_MENUBUTTON_YSIZE TILEY
262 #define SC_SCROLLBUTTON_XSIZE TILEX
263 #define SC_SCROLLBUTTON_YSIZE TILEY
265 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
267 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
268 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
269 SC_SCROLLBUTTON_YSIZE)
271 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
272 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
274 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
275 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
276 SC_SCROLLBUTTON_YSIZE)
278 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
279 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
280 SC_SCROLL_VERTICAL_YSIZE)
282 #define SC_BORDER_SIZE 14
285 // forward declarations of internal functions
286 static void HandleScreenGadgets(struct GadgetInfo *);
287 static void HandleSetupScreen_Generic(int, int, int, int, int);
288 static void HandleSetupScreen_Input(int, int, int, int, int);
289 static void CustomizeKeyboard(int);
290 static void ConfigureJoystick(int);
291 static void ConfigureVirtualButtons(void);
292 static void execSetupGame(void);
293 static void execSetupEngines(void);
294 static void execSetupGraphics(void);
295 static void execSetupSound(void);
296 static void execSetupTouch(void);
297 static void execSetupArtwork(void);
298 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
300 static void DrawChoosePlayerName(void);
301 static void DrawChooseLevelSet(void);
302 static void DrawChooseLevelNr(void);
303 static void DrawScoreInfo(int);
304 static void DrawScoreInfo_Content(int);
305 static void DrawInfoScreen(void);
306 static void DrawSetupScreen(void);
307 static void DrawTypeName(void);
309 static void DrawInfoScreen_NotAvailable(char *, char *);
310 static void DrawInfoScreen_HelpAnim(int, int, boolean);
311 static void DrawInfoScreen_HelpText(int, int, int, int);
312 static void HandleInfoScreen_Main(int, int, int, int, int);
313 static void HandleInfoScreen_TitleScreen(int, int, int);
314 static void HandleInfoScreen_Elements(int, int, int);
315 static void HandleInfoScreen_Music(int, int, int);
316 static void HandleInfoScreen_Version(int);
317 static void HandleInfoScreen_Generic(int, int, int);
319 static void ModifyGameSpeedIfNeeded(void);
320 static void DisableVsyncIfNeeded(void);
322 static void RedrawScreenMenuGadgets(int);
323 static void MapScreenMenuGadgets(int);
324 static void UnmapScreenMenuGadgets(int);
325 static void MapScreenGadgets(int);
326 static void UnmapScreenGadgets(void);
327 static void MapScreenTreeGadgets(TreeInfo *);
328 static void UnmapScreenTreeGadgets(void);
330 static void UpdateScreenMenuGadgets(int, boolean);
331 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
332 static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
334 static boolean OfferUploadTapes(void);
335 static void execOfferUploadTapes(void);
337 static void DrawHallOfFame_setScoreEntries(void);
338 static void HandleHallOfFame_SelectLevel(int, int);
339 static char *getHallOfFameRankText(int, int);
340 static char *getHallOfFameScoreText(int, int);
341 static char *getInfoScreenTitle_Generic(void);
342 static int getInfoScreenBackgroundImage_Generic(void);
343 static int getInfoScreenBackgroundSound_Generic(void);
344 static int getInfoScreenBackgroundMusic_Generic(void);
346 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
348 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
350 static int info_mode = INFO_MODE_MAIN;
351 static int setup_mode = SETUP_MODE_MAIN;
353 static boolean info_screens_from_main = FALSE;
355 static TreeInfo *window_sizes = NULL;
356 static TreeInfo *window_size_current = NULL;
358 static TreeInfo *scaling_types = NULL;
359 static TreeInfo *scaling_type_current = NULL;
361 static TreeInfo *rendering_modes = NULL;
362 static TreeInfo *rendering_mode_current = NULL;
364 static TreeInfo *vsync_modes = NULL;
365 static TreeInfo *vsync_mode_current = NULL;
367 static TreeInfo *scroll_delays = NULL;
368 static TreeInfo *scroll_delay_current = NULL;
370 static TreeInfo *snapshot_modes = NULL;
371 static TreeInfo *snapshot_mode_current = NULL;
373 static TreeInfo *scores_types = NULL;
374 static TreeInfo *scores_type_current = NULL;
376 static TreeInfo *game_speeds_normal = NULL;
377 static TreeInfo *game_speeds_extended = NULL;
378 static TreeInfo *game_speeds = NULL;
379 static TreeInfo *game_speed_current = NULL;
381 static TreeInfo *volumes_simple = NULL;
382 static TreeInfo *volume_simple_current = NULL;
384 static TreeInfo *volumes_loops = NULL;
385 static TreeInfo *volume_loops_current = NULL;
387 static TreeInfo *volumes_music = NULL;
388 static TreeInfo *volume_music_current = NULL;
390 static TreeInfo *touch_controls = NULL;
391 static TreeInfo *touch_control_current = NULL;
393 static TreeInfo *move_distances = NULL;
394 static TreeInfo *move_distance_current = NULL;
396 static TreeInfo *drop_distances = NULL;
397 static TreeInfo *drop_distance_current = NULL;
399 static TreeInfo *transparencies = NULL;
400 static TreeInfo *transparency_current = NULL;
402 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
403 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
405 static TreeInfo *player_name = NULL;
406 static TreeInfo *player_name_current = NULL;
408 static TreeInfo *level_number = NULL;
409 static TreeInfo *level_number_current = NULL;
411 static TreeInfo *score_entries = NULL;
412 static TreeInfo *score_entry_current = NULL;
414 static struct ValueTextInfo window_sizes_list[] =
419 { 100, "100 % (Default)" },
432 static struct StringValueTextInfo scaling_types_list[] =
434 { SCALING_QUALITY_NEAREST, "Off" },
435 { SCALING_QUALITY_LINEAR, "Linear" },
436 { SCALING_QUALITY_BEST, "Anisotropic" },
441 static struct StringValueTextInfo rendering_modes_list[] =
443 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
444 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
446 // this mode may work under certain conditions, but does not work on Windows
447 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
449 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
454 static struct StringValueTextInfo vsync_modes_list[] =
456 { STR_VSYNC_MODE_OFF, "Off" },
457 { STR_VSYNC_MODE_NORMAL, "Normal" },
458 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
463 static struct StringValueTextInfo scores_types_list[] =
465 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
466 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
467 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
472 static struct ValueTextInfo game_speeds_list_normal[] =
483 static struct ValueTextInfo game_speeds_list_extended[] =
485 { 1000, "1 fps (Extremely Slow)" },
490 { 29, "35 fps (Original Supaplex)" },
492 { 20, "50 fps (=== Normal Speed ===)" },
493 { 16, "60 fps (60 Hz VSync Speed)" },
494 { 14, "70 fps (Maximum Supaplex)" },
498 { 1, "1000 fps (Extremely Fast)" },
503 static struct ValueTextInfo *game_speeds_list;
505 static struct ValueTextInfo scroll_delays_list[] =
507 { 0, "0 Tiles (No Scroll Delay)" },
510 { 3, "3 Tiles (Default)" },
515 { 8, "8 Tiles (Maximum Scroll Delay)"},
520 static struct StringValueTextInfo snapshot_modes_list[] =
522 { STR_SNAPSHOT_MODE_OFF, "Off" },
523 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
524 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
525 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
530 static struct ValueTextInfo volumes_list[] =
550 static struct StringValueTextInfo touch_controls_list[] =
552 { TOUCH_CONTROL_OFF, "Off" },
553 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
554 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
555 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
560 static struct ValueTextInfo distances_list[] =
575 static struct ValueTextInfo transparencies_list[] =
577 { 0, "0 % (Opaque)" },
587 { 100, "100 % (Invisible)" },
592 static struct ValueTextInfo grid_sizes_list[] =
628 static int align_xoffset = 0;
629 static int align_yoffset = 0;
631 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
632 (s) <= GAME_MODE_SETUP ? (s) : \
633 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
635 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
636 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
638 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
639 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
640 (i) <= INFO_MODE_LEVELSET ? (i) : \
643 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
644 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
645 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
646 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
647 SETUP_MODE_CHOOSE_ARTWORK : \
648 SETUP_MODE_CHOOSE_OTHER)
650 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
651 menu.draw_xoffset[GAME_MODE_INFO] : \
652 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
653 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
654 menu.draw_yoffset[GAME_MODE_INFO] : \
655 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
656 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
657 menu.extra_spacing[GAME_MODE_INFO] : \
658 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
660 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
661 menu.draw_xoffset[GAME_MODE_SETUP] : \
662 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
663 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
664 menu.draw_yoffset[GAME_MODE_SETUP] : \
665 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
666 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
667 menu.extra_spacing[GAME_MODE_SETUP] : \
668 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
670 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
672 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
674 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
675 DRAW_XOFFSET_INFO(info_mode) : \
676 (s) == GAME_MODE_SETUP ? \
677 DRAW_XOFFSET_SETUP(setup_mode) : \
678 menu.draw_xoffset[DRAW_MODE(s)])
679 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
680 DRAW_YOFFSET_INFO(info_mode) : \
681 (s) == GAME_MODE_SETUP ? \
682 DRAW_YOFFSET_SETUP(setup_mode) : \
683 menu.draw_yoffset[DRAW_MODE(s)])
684 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
685 EXTRA_SPACING_INFO(info_mode) : \
686 (s) == GAME_MODE_SETUP ? \
687 EXTRA_SPACING_SETUP(setup_mode) : \
688 (s) == GAME_MODE_SCORES ? \
689 EXTRA_SPACING_SCORES(info_mode) : \
690 menu.extra_spacing[DRAW_MODE(s)])
692 #define mSX (SX + DRAW_XOFFSET(game_status))
693 #define mSY (SY + DRAW_YOFFSET(game_status))
695 #define amSX (mSX + align_xoffset)
696 #define amSY (mSY + align_yoffset)
698 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
699 menu.list_size[game_status] : \
700 MAX_MENU_ENTRIES_ON_SCREEN)
702 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
703 NUM_MENU_ENTRIES_ON_SCREEN)
706 // title display and control definitions
708 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
709 2 * MAX_NUM_TITLE_MESSAGES)
711 #define NO_DIRECT_LEVEL_SELECT (-1)
714 static int num_title_screens = 0;
716 struct TitleControlInfo
725 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
728 // main menu display and control definitions
730 #define MAIN_CONTROL_NAME 0
731 #define MAIN_CONTROL_LEVELS 1
732 #define MAIN_CONTROL_SCORES 2
733 #define MAIN_CONTROL_EDITOR 3
734 #define MAIN_CONTROL_INFO 4
735 #define MAIN_CONTROL_GAME 5
736 #define MAIN_CONTROL_SETUP 6
737 #define MAIN_CONTROL_QUIT 7
738 #define MAIN_CONTROL_PREV_LEVEL 8
739 #define MAIN_CONTROL_NEXT_LEVEL 9
740 #define MAIN_CONTROL_FIRST_LEVEL 10
741 #define MAIN_CONTROL_LAST_LEVEL 11
742 #define MAIN_CONTROL_LEVEL_NUMBER 12
743 #define MAIN_CONTROL_LEVEL_INFO_1 13
744 #define MAIN_CONTROL_LEVEL_INFO_2 14
745 #define MAIN_CONTROL_LEVEL_NAME 15
746 #define MAIN_CONTROL_LEVEL_AUTHOR 16
747 #define MAIN_CONTROL_LEVEL_YEAR 17
748 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
749 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
750 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
751 #define MAIN_CONTROL_TITLE_1 21
752 #define MAIN_CONTROL_TITLE_2 22
753 #define MAIN_CONTROL_TITLE_3 23
755 static char str_main_text_name[10];
756 static char str_main_text_first_level[10];
757 static char str_main_text_last_level[10];
758 static char str_main_text_level_number[10];
760 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
762 static char *main_text_name = str_main_text_name;
763 static char *main_text_first_level = str_main_text_first_level;
764 static char *main_text_last_level = str_main_text_last_level;
765 static char *main_text_level_number = str_main_text_level_number;
766 static char *main_text_levels = "Levelset";
767 static char *main_text_scores = "Hall Of Fame";
768 static char *main_text_editor = "Level Creator";
769 static char *main_text_info = "Info Screen";
770 static char *main_text_game = "Start Game";
771 static char *main_text_setup = "Setup";
772 static char *main_text_quit = "Quit";
773 static char *main_text_level_name = level.name;
774 static char *main_text_level_author = level.author;
775 static char *main_text_level_year = NULL;
776 static char *main_text_level_imported_from = NULL;
777 static char *main_text_level_imported_by = NULL;
778 static char *main_text_level_tested_by = NULL;
779 static char *main_text_title_1 = NULL;
780 static char *main_text_title_2 = NULL;
781 static char *main_text_title_3 = NULL;
783 extern char debug_xsn_mode[];
785 struct MainControlInfo
789 struct MenuPosInfo *pos_button;
792 struct TextPosInfo *pos_text;
795 struct TextPosInfo *pos_input;
799 static struct MainControlInfo main_controls[] =
803 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
804 &menu.main.text.name, &main_text_name,
805 &menu.main.input.name, &setup.player_name,
809 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
810 &menu.main.text.levels, &main_text_levels,
815 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
816 &menu.main.text.scores, &main_text_scores,
821 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
822 &menu.main.text.editor, &main_text_editor,
827 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
828 &menu.main.text.info, &main_text_info,
833 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
834 &menu.main.text.game, &main_text_game,
839 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
840 &menu.main.text.setup, &main_text_setup,
845 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
846 &menu.main.text.quit, &main_text_quit,
850 MAIN_CONTROL_PREV_LEVEL,
856 MAIN_CONTROL_NEXT_LEVEL,
862 MAIN_CONTROL_FIRST_LEVEL,
864 &menu.main.text.first_level, &main_text_first_level,
868 MAIN_CONTROL_LAST_LEVEL,
870 &menu.main.text.last_level, &main_text_last_level,
874 MAIN_CONTROL_LEVEL_NUMBER,
876 &menu.main.text.level_number, &main_text_level_number,
880 MAIN_CONTROL_LEVEL_INFO_1,
882 &menu.main.text.level_info_1, NULL,
886 MAIN_CONTROL_LEVEL_INFO_2,
888 &menu.main.text.level_info_2, NULL,
892 MAIN_CONTROL_LEVEL_NAME,
894 &menu.main.text.level_name, &main_text_level_name,
898 MAIN_CONTROL_LEVEL_AUTHOR,
900 &menu.main.text.level_author, &main_text_level_author,
904 MAIN_CONTROL_LEVEL_YEAR,
906 &menu.main.text.level_year, &main_text_level_year,
910 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
912 &menu.main.text.level_imported_from, &main_text_level_imported_from,
916 MAIN_CONTROL_LEVEL_IMPORTED_BY,
918 &menu.main.text.level_imported_by, &main_text_level_imported_by,
922 MAIN_CONTROL_LEVEL_TESTED_BY,
924 &menu.main.text.level_tested_by, &main_text_level_tested_by,
928 MAIN_CONTROL_TITLE_1,
930 &menu.main.text.title_1, &main_text_title_1,
934 MAIN_CONTROL_TITLE_2,
936 &menu.main.text.title_2, &main_text_title_2,
940 MAIN_CONTROL_TITLE_3,
942 &menu.main.text.title_3, &main_text_title_3,
955 static boolean hasLevelSetInfo(void)
957 return (getLevelSetInfoFilename(0) != NULL);
960 static int getTitleScreenGraphic(int nr, boolean initial)
962 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
965 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
967 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
971 static int getTitleScreenGameMode(boolean initial)
973 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
977 static int getTitleMessageGameMode(boolean initial)
979 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
982 static int getTitleAnimMode(struct TitleControlInfo *tci)
984 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
986 return base + tci->local_nr;
990 static int getTitleScreenBackground(boolean initial)
992 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
997 static int getTitleMessageBackground(int nr, boolean initial)
999 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
1003 static int getTitleBackground(int nr, boolean initial, boolean is_image)
1005 int base = (is_image ?
1006 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
1007 IMG_BACKGROUND_TITLESCREEN_1) :
1008 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1009 IMG_BACKGROUND_TITLEMESSAGE_1));
1010 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
1011 IMG_BACKGROUND_TITLE);
1012 int graphic_local = base + nr;
1014 if (graphic_info[graphic_local].bitmap != NULL)
1015 return graphic_local;
1017 if (graphic_info[graphic_global].bitmap != NULL)
1018 return graphic_global;
1020 return IMG_UNDEFINED;
1023 static int getTitleSound(struct TitleControlInfo *tci)
1025 boolean is_image = tci->is_image;
1026 int initial = tci->initial;
1027 int nr = tci->local_nr;
1028 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1029 int base = (is_image ?
1030 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1031 SND_BACKGROUND_TITLESCREEN_1) :
1032 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1033 SND_BACKGROUND_TITLEMESSAGE_1));
1034 int sound_global = menu.sound[mode];
1035 int sound_local = base + nr;
1038 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1039 nr, initial, is_image,
1040 sound_global, getSoundListEntry(sound_global)->filename,
1041 sound_local, getSoundListEntry(sound_local)->filename);
1044 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1047 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1048 return sound_global;
1050 return SND_UNDEFINED;
1053 static int getTitleMusic(struct TitleControlInfo *tci)
1055 boolean is_image = tci->is_image;
1056 int initial = tci->initial;
1057 int nr = tci->local_nr;
1058 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1059 int base = (is_image ?
1060 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1061 MUS_BACKGROUND_TITLESCREEN_1) :
1062 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1063 MUS_BACKGROUND_TITLEMESSAGE_1));
1064 int music_global = menu.music[mode];
1065 int music_local = base + nr;
1068 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1069 nr, initial, is_image,
1070 music_global, getMusicListEntry(music_global)->filename,
1071 music_local, getMusicListEntry(music_local)->filename);
1074 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1077 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1078 return music_global;
1080 return MUS_UNDEFINED;
1083 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1085 boolean is_image = tci->is_image;
1086 boolean initial = tci->initial;
1087 boolean first = tci->first;
1088 int nr = tci->local_nr;
1089 struct TitleMessageInfo tmi;
1090 struct TitleFadingInfo ti;
1092 tmi = (is_image ? (initial ? (first ?
1093 titlescreen_initial_first[nr] :
1094 titlescreen_initial[nr])
1096 titlescreen_first[nr] :
1098 : (initial ? (first ?
1099 titlemessage_initial_first[nr] :
1100 titlemessage_initial[nr])
1102 titlemessage_first[nr] :
1103 titlemessage[nr])));
1105 ti.fade_mode = tmi.fade_mode;
1106 ti.fade_delay = tmi.fade_delay;
1107 ti.post_delay = tmi.post_delay;
1108 ti.auto_delay = tmi.auto_delay;
1109 ti.auto_delay_unit = tmi.auto_delay_unit;
1114 static int compareTitleControlInfo(const void *object1, const void *object2)
1116 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1117 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1120 if (tci1->initial != tci2->initial)
1121 compare_result = (tci1->initial ? -1 : +1);
1122 else if (tci1->sort_priority != tci2->sort_priority)
1123 compare_result = tci1->sort_priority - tci2->sort_priority;
1124 else if (tci1->is_image != tci2->is_image)
1125 compare_result = (tci1->is_image ? -1 : +1);
1127 compare_result = tci1->local_nr - tci2->local_nr;
1129 return compare_result;
1132 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1134 int nr, int sort_priority)
1136 title_controls[num_title_screens].is_image = is_image;
1137 title_controls[num_title_screens].initial = initial;
1138 title_controls[num_title_screens].local_nr = nr;
1139 title_controls[num_title_screens].sort_priority = sort_priority;
1141 title_controls[num_title_screens].first = FALSE; // will be set later
1143 num_title_screens++;
1146 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1150 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1152 int graphic = getTitleScreenGraphic(i, initial);
1153 Bitmap *bitmap = graphic_info[graphic].bitmap;
1154 int sort_priority = graphic_info[graphic].sort_priority;
1157 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1160 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1162 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1163 char *filename = getLevelSetTitleMessageFilename(i, initial);
1164 int sort_priority = tmi->sort_priority;
1166 if (filename != NULL)
1167 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1171 static void InitializeTitleControls(boolean show_title_initial)
1173 num_title_screens = 0;
1175 // 1st step: initialize title screens for game start (only when starting)
1176 if (show_title_initial)
1177 InitializeTitleControls_CheckTitleInfo(TRUE);
1179 // 2nd step: initialize title screens for current level set
1180 InitializeTitleControls_CheckTitleInfo(FALSE);
1182 // sort title screens according to sort_priority and title number
1183 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1184 compareTitleControlInfo);
1186 // mark first title screen
1187 title_controls[0].first = TRUE;
1190 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1192 return (pos != NULL && pos->x != -1 && pos->y != -1);
1195 static boolean visibleTextPos(struct TextPosInfo *pos)
1197 return (pos != NULL && pos->x != -1 && pos->y != -1);
1200 static void InitializeMainControls(void)
1202 boolean local_team_mode = (!network.enabled && setup.team_mode);
1205 // set main control text values to dynamically determined values
1206 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1208 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1209 menu.main.text.first_level.size));
1210 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1211 menu.main.text.last_level.size));
1212 strcpy(main_text_level_number, int2str(level_nr,
1213 menu.main.text.level_number.size));
1215 main_text_level_year = leveldir_current->year;
1216 main_text_level_imported_from = leveldir_current->imported_from;
1217 main_text_level_imported_by = leveldir_current->imported_by;
1218 main_text_level_tested_by = leveldir_current->tested_by;
1220 main_text_title_1 = getConfigProgramTitleString();
1221 main_text_title_2 = getConfigProgramCopyrightString();
1222 main_text_title_3 = getConfigProgramCompanyString();
1224 // set main control screen positions to dynamically determined values
1225 for (i = 0; main_controls[i].nr != -1; i++)
1227 struct MainControlInfo *mci = &main_controls[i];
1229 struct MenuPosInfo *pos_button = mci->pos_button;
1230 struct TextPosInfo *pos_text = mci->pos_text;
1231 struct TextPosInfo *pos_input = mci->pos_input;
1232 char *text = (mci->text ? *mci->text : NULL);
1233 char *input = (mci->input ? *mci->input : NULL);
1234 int button_graphic = mci->button_graphic;
1235 int font_text = (pos_text ? pos_text->font : -1);
1236 int font_input = (pos_input ? pos_input->font : -1);
1238 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1239 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1240 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1241 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1242 int text_chars = (text != NULL ? strlen(text) : 0);
1243 int input_chars = (input != NULL ? strlen(input) : 0);
1246 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1248 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1249 int text_width = font_text_width * text_chars;
1250 int text_height = font_text_height;
1251 int input_width = font_input_width * input_chars;
1252 int input_height = font_input_height;
1254 if (nr == MAIN_CONTROL_NAME)
1256 menu.main.input.name.width = input_width;
1257 menu.main.input.name.height = input_height;
1260 if (pos_button != NULL) // (x/y may be -1/-1 here)
1262 pos_button->width = button_width;
1263 pos_button->height = button_height;
1266 if (pos_text != NULL) // (x/y may be -1/-1 here)
1268 // calculate text size -- needed for text alignment
1269 boolean calculate_text_size = (text != NULL);
1271 if (pos_text->width == -1 || calculate_text_size)
1272 pos_text->width = text_width;
1273 if (pos_text->height == -1 || calculate_text_size)
1274 pos_text->height = text_height;
1276 if (visibleMenuPos(pos_button))
1278 if (pos_text->x == -1)
1279 pos_text->x = pos_button->x + pos_button->width;
1280 if (pos_text->y == -1)
1282 pos_button->y + (pos_button->height - pos_text->height) / 2;
1286 if (pos_input != NULL) // (x/y may be -1/-1 here)
1288 if (visibleTextPos(pos_text))
1290 if (pos_input->x == -1)
1291 pos_input->x = pos_text->x + pos_text->width;
1292 if (pos_input->y == -1)
1293 pos_input->y = pos_text->y;
1296 if (pos_input->width == -1)
1297 pos_input->width = input_width;
1298 if (pos_input->height == -1)
1299 pos_input->height = input_height;
1304 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1305 int graphic, boolean pressed)
1307 struct GraphicInfo *g = &graphic_info[graphic];
1310 int xoffset = (pressed ? g->pressed_xoffset : 0);
1311 int yoffset = (pressed ? g->pressed_yoffset : 0);
1313 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1315 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1316 g->width, g->height, dst_x, dst_y);
1319 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1320 boolean active_input,
1321 boolean pressed_button)
1325 for (i = 0; main_controls[i].nr != -1; i++)
1327 struct MainControlInfo *mci = &main_controls[i];
1329 if (mci->nr == nr || nr == -1)
1331 struct MenuPosInfo *pos_button = mci->pos_button;
1332 struct TextPosInfo *pos_text = mci->pos_text;
1333 struct TextPosInfo *pos_input = mci->pos_input;
1334 char *text = (mci->text ? *mci->text : NULL);
1335 char *input = (mci->input ? *mci->input : NULL);
1336 int button_graphic = mci->button_graphic;
1337 int font_text = (pos_text ? pos_text->font : -1);
1338 int font_input = (pos_input ? pos_input->font : -1);
1342 button_graphic = BUTTON_ACTIVE(button_graphic);
1343 font_text = FONT_ACTIVE(font_text);
1348 font_input = FONT_ACTIVE(font_input);
1351 if (visibleMenuPos(pos_button))
1353 struct MenuPosInfo *pos = pos_button;
1354 int x = mSX + pos->x;
1355 int y = mSY + pos->y;
1357 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1358 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1361 if (visibleTextPos(pos_text) && text != NULL)
1363 struct TextPosInfo *pos = pos_text;
1364 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1365 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1368 // (check why/if this is needed)
1369 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1371 DrawText(x, y, text, font_text);
1374 if (visibleTextPos(pos_input) && input != NULL)
1376 struct TextPosInfo *pos = pos_input;
1377 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1378 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1381 // (check why/if this is needed)
1382 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1384 DrawText(x, y, input, font_input);
1390 static void DrawCursorAndText_Main(int nr, boolean active_text,
1391 boolean pressed_button)
1393 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1397 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1398 boolean pressed_button)
1400 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1404 static struct MainControlInfo *getMainControlInfo(int nr)
1408 for (i = 0; main_controls[i].nr != -1; i++)
1409 if (main_controls[i].nr == nr)
1410 return &main_controls[i];
1415 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1420 int rect_x = ALIGNED_TEXT_XPOS(rect);
1421 int rect_y = ALIGNED_TEXT_YPOS(rect);
1423 return (x >= rect_x && x < rect_x + rect->width &&
1424 y >= rect_y && y < rect_y + rect->height);
1427 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1432 int rect_x = ALIGNED_TEXT_XPOS(rect);
1433 int rect_y = ALIGNED_TEXT_YPOS(rect);
1436 Debug("screens:insideTextPosRect",
1437 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1438 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1439 (x >= rect_x && x < rect_x + rect->width &&
1440 y >= rect_y && y < rect_y + rect->height));
1443 return (x >= rect_x && x < rect_x + rect->width &&
1444 y >= rect_y && y < rect_y + rect->height);
1447 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1449 int rect_width = preview->xsize * preview->tile_size;
1450 int rect_height = preview->ysize * preview->tile_size;
1451 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1452 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1454 return (x >= rect_x && x < rect_x + rect_width &&
1455 y >= rect_y && y < rect_y + rect_height);
1458 static void AdjustScrollbar(int id, int items_max, int items_visible,
1461 struct GadgetInfo *gi = screen_gadget[id];
1463 if (item_position > items_max - items_visible)
1464 item_position = items_max - items_visible;
1466 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1467 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1468 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1471 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1473 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1477 static void clearMenuListArea(void)
1479 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1481 // correct scrollbar position if placed outside menu (playfield) area
1482 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1483 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1485 // clear menu list area, but not title or scrollbar
1486 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1487 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1489 // special compatibility handling for "Snake Bite" graphics set
1490 if (strPrefix(leveldir_current->identifier, "snake_bite"))
1491 ClearRectangle(drawto, mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1492 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1495 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1497 static int cursor_array[MAX_LEV_FIELDY];
1498 int x = amSX + TILEX * xpos;
1499 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1504 cursor_array[ypos] = graphic;
1506 graphic = cursor_array[ypos];
1510 graphic = BUTTON_ACTIVE(graphic);
1512 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1513 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1516 static void initCursor(int ypos, int graphic)
1518 drawCursorExt(0, ypos, FALSE, graphic);
1521 static void drawCursor(int ypos, boolean active)
1523 drawCursorExt(0, ypos, active, -1);
1526 static void drawCursorXY(int xpos, int ypos, int graphic)
1528 drawCursorExt(xpos, ypos, FALSE, graphic);
1531 static void drawChooseTreeCursor(int ypos, boolean active)
1533 drawCursorExt(0, ypos, active, -1);
1536 static int getChooseTreeEditFont(boolean active)
1538 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1541 static int getChooseTreeEditXPos(int pos)
1543 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1544 int xoffset = (has_scrollbar ? -1 : 0);
1545 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1546 int sx = amSX + xpos * TILEX;
1547 int font_nr = getChooseTreeEditFont(FALSE);
1548 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1550 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1553 static int getChooseTreeEditYPos(int ypos_raw)
1555 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1556 int sy = amSY + ypos * TILEY;
1561 static int getChooseTreeEditXPosReal(int pos)
1563 int xpos = getChooseTreeEditXPos(pos);
1564 int font_nr = getChooseTreeEditFont(FALSE);
1565 int font_xoffset = getFontDrawOffsetX(font_nr);
1567 return xpos + font_xoffset;
1570 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1572 int sx = getChooseTreeEditXPos(POS_LEFT);
1573 int sy = getChooseTreeEditYPos(ypos_raw);
1574 int font_nr = getChooseTreeEditFont(active);
1576 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1579 static void DrawInfoScreen_Headline(int screen_nr, int num_screens,
1580 int use_global_screens)
1582 char *info_text_title_1 = getInfoScreenTitle_Generic();
1583 char info_text_title_2[MAX_LINE_LEN + 1];
1585 if (num_screens > 1)
1587 sprintf(info_text_title_2, "Page %d of %d", screen_nr + 1, num_screens);
1591 char *text_format = (use_global_screens ? "for %s" : "for \"%s\"");
1592 int text_format_len = strlen(text_format) - strlen("%s");
1593 int max_text_len = SXSIZE / getFontWidth(FONT_TITLE_2);
1594 int max_name_len = max_text_len - text_format_len;
1595 char name_cut[max_name_len];
1596 char *name_full = (use_global_screens ? getProgramTitleString() :
1597 leveldir_current->name);
1599 snprintf(name_cut, max_name_len, "%s", name_full);
1600 snprintf(info_text_title_2, max_text_len, text_format, name_cut);
1603 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, info_text_title_1);
1604 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, info_text_title_2);
1607 static void DrawTitleScreenImage(int nr, boolean initial)
1609 int graphic = getTitleScreenGraphic(nr, initial);
1610 Bitmap *bitmap = graphic_info[graphic].bitmap;
1611 int draw_masked = graphic_info[graphic].draw_masked;
1612 int width = graphic_info[graphic].width;
1613 int height = graphic_info[graphic].height;
1614 int src_x = graphic_info[graphic].src_x;
1615 int src_y = graphic_info[graphic].src_y;
1621 if (width > WIN_XSIZE)
1623 // image width too large for window => center image horizontally
1624 src_x = (width - WIN_XSIZE) / 2;
1628 if (height > WIN_YSIZE)
1630 // image height too large for window => center image vertically
1631 src_y = (height - WIN_YSIZE) / 2;
1635 // always display title screens centered
1636 dst_x = (WIN_XSIZE - width) / 2;
1637 dst_y = (WIN_YSIZE - height) / 2;
1639 SetDrawBackgroundMask(REDRAW_ALL);
1640 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1642 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1644 if (DrawingOnBackground(dst_x, dst_y) && draw_masked)
1645 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1647 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1649 redraw_mask = REDRAW_ALL;
1652 static void DrawTitleScreenMessage(int nr, boolean initial)
1654 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1655 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1657 if (filename == NULL)
1660 // force TITLE font on title message screen
1661 SetFontStatus(getTitleMessageGameMode(initial));
1663 // if chars *and* width set to "-1", automatically determine width
1664 if (tmi->chars == -1 && tmi->width == -1)
1665 tmi->width = viewport.window[game_status].width;
1667 // if lines *and* height set to "-1", automatically determine height
1668 if (tmi->lines == -1 && tmi->height == -1)
1669 tmi->height = viewport.window[game_status].height;
1671 // if chars set to "-1", automatically determine by text and font width
1672 if (tmi->chars == -1)
1673 tmi->chars = tmi->width / getFontWidth(tmi->font);
1675 tmi->width = tmi->chars * getFontWidth(tmi->font);
1677 // if lines set to "-1", automatically determine by text and font height
1678 if (tmi->lines == -1)
1679 tmi->lines = tmi->height / getFontHeight(tmi->font);
1681 tmi->height = tmi->lines * getFontHeight(tmi->font);
1683 // if x set to "-1", automatically determine by width and alignment
1685 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1687 // if y set to "-1", automatically determine by height and alignment
1689 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1691 SetDrawBackgroundMask(REDRAW_ALL);
1692 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1694 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1696 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1697 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1698 tmi->autowrap, tmi->centered, tmi->parse_comments);
1703 static void DrawTitleScreen(void)
1705 KeyboardAutoRepeatOff();
1707 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1710 static boolean CheckTitleScreen(boolean levelset_has_changed)
1712 static boolean show_title_initial = TRUE;
1713 boolean show_titlescreen = FALSE;
1715 // needed to be able to skip title screen, if no image or message defined
1716 InitializeTitleControls(show_title_initial);
1718 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1719 show_titlescreen = TRUE;
1721 // show initial title images and messages only once at program start
1722 show_title_initial = FALSE;
1724 return (show_titlescreen && num_title_screens > 0);
1727 void DrawMainMenu(void)
1729 static LevelDirTree *leveldir_last_valid = NULL;
1730 boolean levelset_has_changed = FALSE;
1731 int fade_mask = REDRAW_FIELD;
1733 LimitScreenUpdates(FALSE);
1735 FadeSetLeaveScreen();
1737 // do not fade out here -- function may continue and fade on editor screen
1740 FadeMenuSoundsAndMusic();
1742 ExpireSoundLoops(FALSE);
1744 KeyboardAutoRepeatOn();
1746 audio.sound_deactivated = FALSE;
1750 // needed if last screen was the playing screen, invoked from level editor
1751 if (level_editor_test_game)
1753 CloseDoor(DOOR_CLOSE_ALL);
1755 SetGameStatus(GAME_MODE_EDITOR);
1762 // needed if last screen was the playing screen, invoked from hall of fame
1763 if (score_info_tape_play)
1765 CloseDoor(DOOR_CLOSE_ALL);
1767 SetGameStatus(GAME_MODE_SCOREINFO);
1769 DrawScoreInfo(scores.last_entry_nr);
1774 // reset flag to continue playing next level from hall of fame
1775 scores.continue_playing = FALSE;
1777 // leveldir_current may be invalid (level group, parent link, node copy)
1778 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1780 if (leveldir_current != leveldir_last_valid)
1782 // level setup config may have been loaded to "last played" tree node copy,
1783 // but "leveldir_current" now points to the "original" level set tree node,
1784 // in which case "handicap_level" may still default to the first level
1785 LoadLevelSetup_SeriesInfo();
1787 UpdateLastPlayedLevels_TreeInfo();
1789 levelset_has_changed = TRUE;
1792 // store valid level series information
1793 leveldir_last_valid = leveldir_current;
1795 // needed if last screen (level choice) changed graphics, sounds or music
1796 ReloadCustomArtwork(0);
1798 if (CheckTitleScreen(levelset_has_changed))
1800 SetGameStatus(GAME_MODE_TITLE);
1807 if (redraw_mask & REDRAW_ALL)
1808 fade_mask = REDRAW_ALL;
1811 fade_mask = REDRAW_ALL;
1815 // needed if different viewport properties defined for menues
1816 ChangeViewportPropertiesIfNeeded();
1818 SetDrawtoField(DRAW_TO_BACKBUFFER);
1820 // level_nr may have been set to value over handicap with level editor
1821 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1822 level_nr = leveldir_current->handicap_level;
1824 LoadLevel(level_nr);
1825 LoadScore(level_nr);
1827 SaveLevelSetup_SeriesInfo();
1829 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1830 SetDrawDeactivationMask(REDRAW_NONE);
1831 SetDrawBackgroundMask(REDRAW_FIELD);
1833 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1836 if (fade_mask == REDRAW_ALL)
1837 RedrawGlobalBorder();
1842 InitializeMainControls();
1844 DrawCursorAndText_Main(-1, FALSE, FALSE);
1845 DrawPreviewLevelInitial();
1846 DrawNetworkPlayers();
1848 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1851 if (TAPE_IS_EMPTY(tape))
1853 DrawCompleteVideoDisplay();
1855 PlayMenuSoundsAndMusic();
1857 // create gadgets for main menu screen
1858 FreeScreenGadgets();
1859 CreateScreenGadgets();
1861 // may be required if audio buttons shown on tape and changed in setup menu
1863 CreateGameButtons();
1865 // map gadgets for main menu screen
1867 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1868 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1869 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SET_INFO, hasLevelSetInfo());
1871 // copy actual game door content to door double buffer for OpenDoor()
1872 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1873 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1875 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1877 DrawMaskedBorder(fade_mask);
1882 // update screen area with special editor door
1883 redraw_mask |= REDRAW_ALL;
1886 SetMouseCursor(CURSOR_DEFAULT);
1888 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1890 SyncEmscriptenFilesystem();
1892 // needed once after program start or after user change
1893 CheckApiServerTasks();
1896 static void gotoTopLevelDir(void)
1898 // move upwards until inside (but not above) top level directory
1899 while (leveldir_current->node_parent &&
1900 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1902 // write a "path" into level tree for easy navigation to last level
1903 if (leveldir_current->node_parent->node_group->cl_first == -1)
1905 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1906 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1907 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1908 int cl_first, cl_cursor;
1910 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1911 cl_cursor = leveldir_pos - cl_first;
1913 leveldir_current->node_parent->node_group->cl_first = cl_first;
1914 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1917 leveldir_current = leveldir_current->node_parent;
1921 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1923 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1925 return (use_frame_counter ? video.frame_counter : Counter());
1928 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1929 struct TitleFadingInfo *fi)
1931 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1934 static void ResetTitleAutoDelay(unsigned int *counter_var,
1935 struct TitleFadingInfo *fi)
1937 *counter_var = getAutoDelayCounter(fi);
1940 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1942 static unsigned int title_delay = 0;
1943 static int title_screen_nr = 0;
1944 static int last_sound = -1, last_music = -1;
1945 boolean return_to_main_menu = FALSE;
1946 struct TitleControlInfo *tci;
1949 if (button == MB_MENU_INITIALIZE)
1952 title_screen_nr = 0;
1953 tci = &title_controls[title_screen_nr];
1955 SetAnimStatus(getTitleAnimMode(tci));
1957 last_sound = SND_UNDEFINED;
1958 last_music = MUS_UNDEFINED;
1960 if (num_title_screens != 0)
1962 FadeSetEnterScreen();
1964 // use individual title fading instead of global "enter screen" fading
1965 fading = getTitleFading(tci);
1968 if (game_status_last_screen == GAME_MODE_INFO)
1970 if (num_title_screens == 0)
1972 // switch game mode from title screen mode back to info screen mode
1973 SetGameStatus(GAME_MODE_INFO);
1975 // store that last screen was info screen, not main menu screen
1976 game_status_last_screen = GAME_MODE_INFO;
1978 DrawInfoScreen_NotAvailable("Title screen information:",
1979 "No title screen for this level set.");
1984 FadeMenuSoundsAndMusic();
1986 FadeOut(REDRAW_ALL);
1988 // title screens may have different window size
1989 ChangeViewportPropertiesIfNeeded();
1991 // only required to update logic for redrawing global border
1995 DrawTitleScreenImage(tci->local_nr, tci->initial);
1997 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1999 sound = getTitleSound(tci);
2000 music = getTitleMusic(tci);
2002 if (sound != last_sound)
2003 PlayMenuSoundExt(sound);
2004 if (music != last_music)
2005 PlayMenuMusicExt(music);
2010 SetMouseCursor(CURSOR_NONE);
2014 ResetTitleAutoDelay(&title_delay, &fading);
2019 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
2020 button = MB_MENU_CHOICE;
2022 if (button == MB_MENU_LEAVE)
2024 return_to_main_menu = TRUE;
2026 else if (button == MB_MENU_CHOICE || dx)
2028 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
2030 SetGameStatus(GAME_MODE_INFO);
2032 info_mode = INFO_MODE_MAIN;
2040 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
2042 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
2044 tci = &title_controls[title_screen_nr];
2046 SetAnimStatus(getTitleAnimMode(tci));
2048 sound = getTitleSound(tci);
2049 music = getTitleMusic(tci);
2051 if (last_sound != SND_UNDEFINED && sound != last_sound)
2052 FadeSound(last_sound);
2053 if (last_music != MUS_UNDEFINED && music != last_music)
2056 fading = getTitleFading(tci);
2058 FadeOut(REDRAW_ALL);
2061 DrawTitleScreenImage(tci->local_nr, tci->initial);
2063 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2065 sound = getTitleSound(tci);
2066 music = getTitleMusic(tci);
2068 if (sound != last_sound)
2069 PlayMenuSoundExt(sound);
2070 if (music != last_music)
2071 PlayMenuMusicExt(music);
2078 ResetTitleAutoDelay(&title_delay, &fading);
2082 FadeMenuSoundsAndMusic();
2084 return_to_main_menu = TRUE;
2088 if (return_to_main_menu)
2090 SetMouseCursor(CURSOR_DEFAULT);
2092 // force full menu screen redraw after displaying title screens
2093 redraw_mask = REDRAW_ALL;
2095 if (game_status_last_screen == GAME_MODE_INFO)
2097 SetGameStatus(GAME_MODE_INFO);
2099 info_mode = INFO_MODE_MAIN;
2103 else // default: return to main menu
2105 SetGameStatus(GAME_MODE_MAIN);
2112 static void HandleMainMenu_ToggleTeamMode(void)
2114 setup.team_mode = !setup.team_mode;
2116 InitializeMainControls();
2117 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2119 DrawPreviewPlayers();
2122 static void HandleMainMenu_SelectLevel(int step, int direction,
2123 int selected_level_nr)
2125 int old_level_nr = level_nr;
2128 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2129 new_level_nr = selected_level_nr;
2131 new_level_nr = old_level_nr + step * direction;
2133 if (new_level_nr < leveldir_current->first_level)
2134 new_level_nr = leveldir_current->first_level;
2135 if (new_level_nr > leveldir_current->last_level)
2136 new_level_nr = leveldir_current->last_level;
2138 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2140 // skipping levels is only allowed when trying to skip single level
2141 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2142 Request("Level still unsolved! Skip it anyway?", REQ_ASK))
2144 leveldir_current->handicap_level++;
2145 SaveLevelSetup_SeriesInfo();
2148 new_level_nr = leveldir_current->handicap_level;
2151 if (new_level_nr != old_level_nr)
2153 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2155 PlaySound(SND_MENU_ITEM_SELECTING);
2157 level_nr = new_level_nr;
2159 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2160 int2str(level_nr, menu.main.text.level_number.size),
2161 mci->pos_text->font);
2163 LoadLevel(level_nr);
2164 DrawPreviewLevelInitial();
2168 DrawCompleteVideoDisplay();
2170 SaveLevelSetup_SeriesInfo();
2172 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2174 // force redraw of playfield area (may be reset at this point)
2175 redraw_mask |= REDRAW_FIELD;
2179 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2181 static int choice = MAIN_CONTROL_GAME;
2182 static boolean button_pressed_last = FALSE;
2183 boolean button_pressed = FALSE;
2185 int i = 0; // needed to prevent compiler warning due to bad code below
2187 if (button == MB_MENU_INITIALIZE)
2189 DrawCursorAndText_Main(choice, TRUE, FALSE);
2194 if (mx || my) // mouse input
2198 for (i = 0; main_controls[i].nr != -1; i++)
2200 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2201 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2202 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2204 pos = main_controls[i].nr;
2210 // check if level preview was clicked
2211 if (insidePreviewRect(&preview, mx - SX, my - SY))
2212 pos = MAIN_CONTROL_GAME;
2214 // handle pressed/unpressed state for active/inactive menu buttons
2215 // (if pos != -1, "i" contains index position corresponding to "pos")
2217 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2218 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2219 button_pressed = TRUE;
2221 if (button_pressed != button_pressed_last)
2223 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2226 PlaySound(SND_MENU_BUTTON_PRESSING);
2228 PlaySound(SND_MENU_BUTTON_RELEASING);
2231 else if (dx || dy) // keyboard input
2233 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2234 choice == MAIN_CONTROL_SETUP))
2235 button = MB_MENU_CHOICE;
2240 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2242 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2244 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2246 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2248 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2250 CloseDoor(DOOR_CLOSE_2);
2252 SetGameStatus(GAME_MODE_LEVELNR);
2254 DrawChooseLevelNr();
2256 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2262 PlaySound(SND_MENU_ITEM_ACTIVATING);
2264 DrawCursorAndText_Main(choice, FALSE, FALSE);
2265 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2271 if (choice == MAIN_CONTROL_NAME)
2273 // special case: cursor left or right pressed -- toggle team mode
2274 HandleMainMenu_ToggleTeamMode();
2276 else if (choice != MAIN_CONTROL_INFO &&
2277 choice != MAIN_CONTROL_SETUP)
2279 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2285 PlaySound(SND_MENU_ITEM_SELECTING);
2287 if (pos == MAIN_CONTROL_NAME)
2290 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2292 // special case: menu text "name/team" clicked -- toggle team mode
2293 HandleMainMenu_ToggleTeamMode();
2297 if (setup.multiple_users)
2299 CloseDoor(DOOR_CLOSE_2);
2301 SetGameStatus(GAME_MODE_NAMES);
2303 DrawChoosePlayerName();
2307 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2313 else if (pos == MAIN_CONTROL_LEVELS)
2317 CloseDoor(DOOR_CLOSE_2);
2319 SetGameStatus(GAME_MODE_LEVELS);
2321 SaveLevelSetup_LastSeries();
2322 SaveLevelSetup_SeriesInfo();
2324 // restore level set if chosen from "last played level set" menu
2325 RestoreLastPlayedLevels(&leveldir_current);
2327 if (setup.internal.choose_from_top_leveldir)
2330 DrawChooseLevelSet();
2333 else if (pos == MAIN_CONTROL_SCORES)
2335 CloseDoor(DOOR_CLOSE_2);
2337 SetGameStatus(GAME_MODE_SCORES);
2339 DrawHallOfFame(level_nr);
2341 else if (pos == MAIN_CONTROL_EDITOR)
2343 if (leveldir_current->readonly &&
2344 setup.editor.show_read_only_warning)
2345 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2347 CloseDoor(DOOR_CLOSE_ALL);
2349 SetGameStatus(GAME_MODE_EDITOR);
2351 FadeSetEnterScreen();
2355 else if (pos == MAIN_CONTROL_INFO)
2357 CloseDoor(DOOR_CLOSE_2);
2359 SetGameStatus(GAME_MODE_INFO);
2361 info_mode = INFO_MODE_MAIN;
2365 else if (pos == MAIN_CONTROL_GAME)
2367 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2369 else if (pos == MAIN_CONTROL_SETUP)
2371 CloseDoor(DOOR_CLOSE_2);
2373 SetGameStatus(GAME_MODE_SETUP);
2375 setup_mode = SETUP_MODE_MAIN;
2379 else if (pos == MAIN_CONTROL_QUIT)
2381 SaveLevelSetup_LastSeries();
2382 SaveLevelSetup_SeriesInfo();
2384 #if defined(PLATFORM_EMSCRIPTEN)
2385 Request("Close the browser window to quit!", REQ_CONFIRM);
2387 if (!setup.ask_on_quit_program ||
2388 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2389 SetGameStatus(GAME_MODE_QUIT);
2395 button_pressed_last = button_pressed;
2399 // ============================================================================
2400 // info screen functions
2401 // ============================================================================
2403 static struct TokenInfo *info_info;
2404 static int num_info_info; // number of info entries shown on screen
2405 static int max_info_info; // total number of info entries in list
2407 static void execInfoTitleScreen(void)
2409 info_mode = INFO_MODE_TITLE;
2414 static void execInfoElements(void)
2416 info_mode = INFO_MODE_ELEMENTS;
2421 static void execInfoMusic(void)
2423 info_mode = INFO_MODE_MUSIC;
2428 static void execInfoCredits(void)
2430 info_mode = INFO_MODE_CREDITS;
2435 static void execInfoProgram(void)
2437 info_mode = INFO_MODE_PROGRAM;
2442 static void execInfoVersion(void)
2444 info_mode = INFO_MODE_VERSION;
2449 static void execInfoLevelSet(void)
2451 info_mode = INFO_MODE_LEVELSET;
2456 static void execExitInfo(void)
2458 SetGameStatus(GAME_MODE_MAIN);
2463 static struct TokenInfo info_info_main[] =
2465 { TYPE_ENTER_SCREEN, execInfoTitleScreen, STR_INFO_TITLE },
2466 { TYPE_ENTER_SCREEN, execInfoElements, STR_INFO_ELEMENTS },
2467 { TYPE_ENTER_SCREEN, execInfoMusic, STR_INFO_MUSIC },
2468 { TYPE_ENTER_SCREEN, execInfoCredits, STR_INFO_CREDITS },
2469 { TYPE_ENTER_SCREEN, execInfoProgram, STR_INFO_PROGRAM },
2470 { TYPE_ENTER_SCREEN, execInfoVersion, STR_INFO_VERSION },
2471 { TYPE_ENTER_SCREEN, execInfoLevelSet, STR_INFO_LEVELSET },
2472 { TYPE_EMPTY, NULL, "" },
2473 { TYPE_LEAVE_MENU, execExitInfo, STR_INFO_EXIT },
2478 static int getMenuTextFont(int type)
2480 if (type & (TYPE_SWITCH |
2494 static struct TokenInfo *setup_info;
2495 static struct TokenInfo setup_info_input[];
2497 static struct TokenInfo *menu_info;
2499 static void PlayInfoSound(void)
2501 int info_sound = getInfoScreenBackgroundSound_Generic();
2502 char *next_sound = getSoundInfoEntryFilename(info_sound);
2504 if (next_sound != NULL)
2505 PlayMenuSoundExt(info_sound);
2510 static void PlayInfoSoundIfLoop(void)
2512 int info_sound = getInfoScreenBackgroundSound_Generic();
2513 char *next_sound = getSoundInfoEntryFilename(info_sound);
2515 if (next_sound != NULL)
2516 PlayMenuSoundIfLoopExt(info_sound);
2518 PlayMenuSoundIfLoop();
2521 static void PlayInfoMusic(void)
2523 int info_music = getInfoScreenBackgroundMusic_Generic();
2524 char *curr_music = getCurrentlyPlayingMusicFilename();
2525 char *next_music = getMusicInfoEntryFilename(info_music);
2527 if (next_music != NULL)
2529 // play music if info screen music differs from current music
2530 if (!strEqual(curr_music, next_music))
2531 PlayMenuMusicExt(info_music);
2535 // only needed if info screen was directly invoked from main menu
2540 static void PlayInfoSoundsAndMusic(void)
2546 static void FadeInfoSounds(void)
2551 static void FadeInfoMusic(void)
2553 int info_music = getInfoScreenBackgroundMusic_Generic();
2554 char *curr_music = getCurrentlyPlayingMusicFilename();
2555 char *next_music = getMusicInfoEntryFilename(info_music);
2557 if (next_music != NULL)
2559 // fade music if info screen music differs from current music
2560 if (!strEqual(curr_music, next_music))
2565 static void FadeInfoSoundsAndMusic(void)
2571 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2572 int screen_pos, int menu_info_pos_raw,
2575 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2576 struct TokenInfo *ti = &token_info[pos];
2577 int xpos = MENU_SCREEN_START_XPOS;
2578 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2579 int font_nr = getMenuTextFont(ti->type);
2581 if (setup_mode == SETUP_MODE_INPUT)
2582 font_nr = FONT_MENU_1;
2585 font_nr = FONT_ACTIVE(font_nr);
2587 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2589 if (ti->type & ~TYPE_SKIP_ENTRY)
2590 drawCursor(screen_pos, active);
2593 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2596 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2599 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2602 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2605 static char *window_size_text;
2606 static char *scaling_type_text;
2607 static char *network_server_text;
2609 static void drawSetupValue(int, int);
2611 static void drawMenuInfoList(int first_entry, int num_page_entries,
2612 int max_page_entries)
2616 if (first_entry + num_page_entries > max_page_entries)
2619 clearMenuListArea();
2621 for (i = 0; i < num_page_entries; i++)
2623 int menu_info_pos = first_entry + i;
2624 struct TokenInfo *si = &menu_info[menu_info_pos];
2625 void *value_ptr = si->value;
2627 // set some entries to "unchangeable" according to other variables
2628 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2629 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2630 (value_ptr == &setup.sound_music && !audio.music_available) ||
2631 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2632 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2633 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2634 si->type |= TYPE_GHOSTED;
2636 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2637 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2638 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2639 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2640 else if (si->type & ~TYPE_SKIP_ENTRY)
2641 initCursor(i, IMG_MENU_BUTTON);
2643 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2645 if (si->type & TYPE_STRING)
2649 if (value_ptr == &network_server_text)
2650 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2652 if (gadget_id != -1)
2654 struct GadgetInfo *gi = screen_gadget[gadget_id];
2655 int xpos = MENU_SCREEN_START_XPOS;
2656 int ypos = MENU_SCREEN_START_YPOS + i;
2657 int x = mSX + xpos * 32;
2658 int y = mSY + ypos * 32;
2660 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2664 if (si->type & TYPE_VALUE &&
2665 menu_info == setup_info)
2666 drawSetupValue(i, menu_info_pos);
2670 static void DrawInfoScreen_Main(void)
2672 int fade_mask = REDRAW_FIELD;
2675 // (needed after displaying info sub-screens directly from main menu)
2676 if (info_screens_from_main)
2678 info_screens_from_main = FALSE;
2680 SetGameStatus(GAME_MODE_MAIN);
2687 if (redraw_mask & REDRAW_ALL)
2688 fade_mask = REDRAW_ALL;
2691 fade_mask = REDRAW_ALL;
2694 FadeMenuSoundsAndMusic();
2696 FreeScreenGadgets();
2697 CreateScreenGadgets();
2699 // (needed after displaying title screens which disable auto repeat)
2700 KeyboardAutoRepeatOn();
2702 FadeSetLeaveScreen();
2706 // needed if different viewport properties defined for info screen
2707 ChangeViewportPropertiesIfNeeded();
2709 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2713 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2715 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_INFO_MAIN);
2717 info_info = info_info_main;
2719 // use modified info screen info without info screen entries marked as hidden
2720 info_info = getSetupInfoFinal(info_info);
2722 // determine maximal number of info entries that can be displayed on screen
2724 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2727 // determine maximal number of info entries available for menu of info screen
2729 for (i = 0; info_info[i].type != 0; i++)
2732 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2734 MapScreenGadgets(max_info_info);
2736 PlayMenuSoundsAndMusic();
2738 DrawMaskedBorder(fade_mask);
2743 static void changeSetupValue(int, int, int);
2745 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2746 int mode, int num_page_entries,
2747 int max_page_entries)
2749 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2750 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2751 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2752 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2753 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2754 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2755 int *num_page_entries_last = num_page_entries_all_last[game_status];
2756 int *choice_store = choice_stores[game_status];
2757 int *first_entry_store = first_entry_stores[game_status];
2758 int choice = choice_store[mode]; // starts with 0
2759 int first_entry = first_entry_store[mode]; // starts with 0
2761 int y = choice - first_entry;
2763 boolean position_set_by_scrollbar = (dx == 999);
2764 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2767 if (button == MB_MENU_INITIALIZE)
2769 // check if number of menu page entries has changed (may happen by change
2770 // of custom artwork definition value for 'list_size' for this menu screen)
2771 // (in this case, the last menu position most probably has to be corrected)
2772 if (num_page_entries != num_page_entries_last[mode])
2774 choice_store[mode] = first_entry_store[mode] = 0;
2776 choice = first_entry = 0;
2779 num_page_entries_last[mode] = num_page_entries;
2782 // advance to first valid menu entry
2783 while (choice < num_page_entries &&
2784 menu_info[choice].type & TYPE_SKIP_ENTRY)
2787 if (position_set_by_scrollbar)
2788 first_entry = first_entry_store[mode] = dy;
2790 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2791 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2793 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2795 if (choice < first_entry)
2797 choice = first_entry;
2799 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2802 else if (choice > first_entry + num_page_entries - 1)
2804 choice = first_entry + num_page_entries - 1;
2806 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2810 choice_store[mode] = choice;
2812 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2816 else if (button == MB_MENU_LEAVE)
2818 PlaySound(SND_MENU_ITEM_SELECTING);
2820 for (i = 0; i < max_page_entries; i++)
2822 if (menu_info[i].type & TYPE_LEAVE_MENU)
2824 void (*menu_callback_function)(void) = menu_info[i].value;
2828 menu_callback_function();
2830 break; // absolutely needed because function changes 'menu_info'!
2837 if (mx || my) // mouse input
2839 x = (mx - mSX) / 32;
2840 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2842 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2844 // move cursor instead of scrolling when already at start/end of list
2845 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2847 else if (dy == +1 * SCROLL_LINE &&
2848 first_entry + num_page_entries == max_page_entries)
2851 // handle scrolling screen one line or page
2853 y + dy > num_page_entries - 1)
2855 boolean redraw = FALSE;
2857 if (ABS(dy) == SCROLL_PAGE)
2858 step = num_page_entries - 1;
2860 if (dy < 0 && first_entry > 0)
2862 // scroll page/line up
2864 first_entry -= step;
2865 if (first_entry < 0)
2870 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2872 // scroll page/line down
2874 first_entry += step;
2875 if (first_entry + num_page_entries > max_page_entries)
2876 first_entry = MAX(0, max_page_entries - num_page_entries);
2883 choice += first_entry - first_entry_store[mode];
2885 if (choice < first_entry)
2887 choice = first_entry;
2889 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2892 else if (choice > first_entry + num_page_entries - 1)
2894 choice = first_entry + num_page_entries - 1;
2896 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2899 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2903 if (choice < first_entry ||
2904 choice > first_entry + num_page_entries - 1)
2905 first_entry += SIGN(dy);
2908 first_entry_store[mode] = first_entry;
2909 choice_store[mode] = choice;
2911 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2913 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2915 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2916 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2924 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2926 if (menu_info[choice].type & menu_navigation_type ||
2927 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2928 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2929 menu_info[choice].type & TYPE_PLAYER)
2930 button = MB_MENU_CHOICE;
2935 // jump to next non-empty menu entry (up or down)
2936 while (first_entry + y > 0 &&
2937 first_entry + y < max_page_entries - 1 &&
2938 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2941 if (!IN_VIS_MENU(x, y))
2943 choice += y - y_old;
2945 if (choice < first_entry)
2946 first_entry = choice;
2947 else if (choice > first_entry + num_page_entries - 1)
2948 first_entry = choice - num_page_entries + 1;
2950 if (first_entry >= 0 &&
2951 first_entry + num_page_entries <= max_page_entries)
2953 first_entry_store[mode] = first_entry;
2955 if (choice < first_entry)
2956 choice = first_entry;
2957 else if (choice > first_entry + num_page_entries - 1)
2958 choice = first_entry + num_page_entries - 1;
2960 choice_store[mode] = choice;
2962 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2964 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2966 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2967 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2974 if (!anyScrollbarGadgetActive() &&
2975 IN_VIS_MENU(x, y) &&
2976 mx < mx_right_border &&
2977 y >= 0 && y < num_page_entries)
2981 if (first_entry + y != choice &&
2982 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2984 PlaySound(SND_MENU_ITEM_ACTIVATING);
2986 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2987 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2989 choice = choice_store[mode] = first_entry + y;
2993 PlaySound(SND_MENU_ITEM_SELECTING);
2995 for (i = 0; menu_info[i].type != 0; i++)
2997 if (menu_info[i].type & TYPE_LEAVE_MENU)
2999 void (*menu_callback_function)(void) = menu_info[i].value;
3003 menu_callback_function();
3005 // absolutely needed because function changes 'menu_info'!
3013 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
3015 PlaySound(SND_MENU_ITEM_SELECTING);
3017 // when selecting key headline, execute function for key value change
3018 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
3019 menu_info[first_entry + y + 1].type & TYPE_KEY)
3022 // when selecting string value, execute function for list selection
3023 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3024 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
3027 // when selecting string value, execute function for text input gadget
3028 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3029 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
3032 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
3034 void (*menu_callback_function)(void) =
3035 menu_info[first_entry + y].value;
3037 FadeSetFromType(menu_info[first_entry + y].type);
3039 menu_callback_function();
3041 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
3043 void (*gadget_callback_function)(void) =
3044 menu_info[first_entry + y].value;
3046 gadget_callback_function();
3048 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
3049 menu_info == setup_info)
3051 changeSetupValue(y, first_entry + y, dx);
3057 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
3059 menu_info = info_info;
3061 HandleMenuScreen(mx, my, dx, dy, button,
3062 info_mode, num_info_info, max_info_info);
3065 static int getMenuFontSpacing(int spacing_height, int font_nr)
3067 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
3069 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
3073 static int getMenuTextSpacing(int spacing_height, int font_nr)
3075 return (getMenuFontSpacing(spacing_height, font_nr) +
3076 EXTRA_SPACING(game_status));
3079 static int getMenuTextStep(int spacing_height, int font_nr)
3081 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
3084 static int getHeadlineSpacing(void)
3086 // special compatibility handling for "R'n'D jue 2022" game editions
3087 int spacing_check = menu.headline1_spacing[GAME_MODE_SCOREINFO];
3088 int spacing = (game_status == GAME_MODE_SCOREINFO ?
3089 menu.headline1_spacing[GAME_MODE_SCOREINFO] :
3090 menu.headline1_spacing_info[info_mode]);
3091 int font = MENU_INFO_FONT_TITLE;
3093 return (spacing_check != -2 ? getMenuTextStep(spacing, font) : 0);
3096 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
3098 int font_error = FONT_TEXT_2;
3099 int font_foot = MENU_INFO_FONT_FOOT;
3100 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3101 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3103 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
3105 FadeOut(REDRAW_FIELD);
3109 DrawInfoScreen_Headline(0, 1, FALSE);
3111 DrawTextSCentered(ystart, font_error, text_error);
3112 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3114 FadeIn(REDRAW_FIELD);
3117 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
3119 static int infoscreen_step[MAX_INFO_ELEMENTS_IN_ARRAY];
3120 static int infoscreen_frame[MAX_INFO_ELEMENTS_IN_ARRAY];
3121 int font_foot = MENU_INFO_FONT_FOOT;
3122 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
3123 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3124 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3125 int ystep = MENU_SCREEN_INFO_YSTEP;
3126 int row_height = MENU_SCREEN_INFO_ENTRY_SIZE;
3127 int tilesize = MENU_SCREEN_INFO_TILE_SIZE;
3128 int yoffset = (row_height - tilesize) / 2;
3129 int element, action, direction;
3137 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
3138 infoscreen_step[i] = infoscreen_frame[i] = 0;
3140 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3146 while (helpanim_info[j].element != HELPANIM_LIST_END)
3148 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3153 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3162 int ypos = i - start;
3163 int ystart_pos = ystart + ypos * ystep + yoffset;
3165 j += infoscreen_step[ypos];
3167 element = helpanim_info[j].element;
3168 action = helpanim_info[j].action;
3169 direction = helpanim_info[j].direction;
3172 element = EL_UNKNOWN;
3174 if (action != -1 && direction != -1)
3175 graphic = el_act_dir2img(element, action, direction);
3176 else if (action != -1)
3177 graphic = el_act2img(element, action);
3178 else if (direction != -1)
3179 graphic = el_dir2img(element, direction);
3181 graphic = el2img(element);
3183 delay = helpanim_info[j++].delay;
3188 if (infoscreen_frame[ypos] == 0)
3191 infoscreen_frame[ypos] = delay - 1;
3195 sync_frame = delay - infoscreen_frame[ypos];
3196 infoscreen_frame[ypos]--;
3199 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3201 if (!infoscreen_frame[ypos])
3202 infoscreen_step[ypos] = 0;
3206 if (!infoscreen_frame[ypos])
3207 infoscreen_step[ypos]++;
3208 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3214 ClearRectangleOnBackground(drawto, xstart, ystart_pos, tilesize, tilesize);
3215 DrawSizedGraphicAnimationExt(drawto, xstart, ystart_pos,
3216 graphic, sync_frame, tilesize, USE_MASKING);
3219 DrawInfoScreen_HelpText(element, action, direction, ypos);
3224 redraw_mask |= REDRAW_FIELD;
3229 static char *getHelpText(int element, int action, int direction)
3231 char token[MAX_LINE_LEN];
3233 strcpy(token, element_info[element].token_name);
3236 strcat(token, element_action_info[action].suffix);
3238 if (direction != -1)
3239 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3241 return getHashEntry(helptext_info, token);
3244 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3246 int font_nr = FONT_INFO_ELEMENTS;
3247 int font_width = getFontWidth(font_nr);
3248 int font_height = getFontHeight(font_nr);
3249 int line_spacing = MENU_SCREEN_INFO_SPACE_LINE;
3250 int left_spacing = MENU_SCREEN_INFO_SPACE_LEFT;
3251 int middle_spacing = MENU_SCREEN_INFO_SPACE_MIDDLE;
3252 int right_spacing = MENU_SCREEN_INFO_SPACE_RIGHT;
3253 int line_height = font_height + line_spacing;
3254 int row_height = MENU_SCREEN_INFO_ENTRY_SIZE;
3255 int tilesize = MENU_SCREEN_INFO_TILE_SIZE;
3256 int xstart = mSX + left_spacing + tilesize + middle_spacing;
3257 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3258 int ystep = MENU_SCREEN_INFO_YSTEP;
3259 int pad_left = xstart - SX;
3260 int pad_right = right_spacing;
3261 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3262 int max_lines_per_text = (row_height + line_spacing) / line_height;
3264 boolean autowrap = TRUE;
3265 boolean centered = FALSE;
3266 boolean parse_comments = FALSE;
3268 if (action != -1 && direction != -1) // element.action.direction
3269 text = getHelpText(element, action, direction);
3271 if (text == NULL && action != -1) // element.action
3272 text = getHelpText(element, action, -1);
3274 if (text == NULL && direction != -1) // element.direction
3275 text = getHelpText(element, -1, direction);
3277 if (text == NULL) // base element
3278 text = getHelpText(element, -1, -1);
3280 if (text == NULL) // not found
3281 text = "No description available";
3283 DisableDrawingText();
3285 // first get number of text lines to calculate offset for centering text
3286 int num_lines_printed =
3287 DrawTextBuffer(0, 0, text, font_nr,
3288 max_chars_per_line, -1, max_lines_per_text, line_spacing, -1,
3289 autowrap, centered, parse_comments);
3291 EnableDrawingText();
3293 int size_lines_printed = num_lines_printed * line_height - line_spacing;
3294 int yoffset = (row_height - size_lines_printed) / 2;
3296 DrawTextBuffer(xstart, ystart + ypos * ystep + yoffset, text, font_nr,
3297 max_chars_per_line, -1, max_lines_per_text, line_spacing, -1,
3298 autowrap, centered, parse_comments);
3301 static void DrawInfoScreen_TitleScreen(void)
3303 SetGameStatus(GAME_MODE_TITLE);
3310 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3312 HandleTitleScreen(0, 0, dx, dy, button);
3315 static void DrawInfoScreen_Elements(void)
3317 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3320 FadeInfoSoundsAndMusic();
3322 FadeOut(REDRAW_FIELD);
3327 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3329 PlayInfoSoundsAndMusic();
3331 FadeIn(REDRAW_FIELD);
3334 void HandleInfoScreen_Elements(int dx, int dy, int button)
3336 static DelayCounter info_delay = { 0 };
3337 static int num_anims;
3338 static int num_pages;
3340 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3343 info_delay.value = GameFrameDelay;
3345 if (button == MB_MENU_INITIALIZE)
3347 boolean new_element = TRUE;
3351 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3353 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3355 else if (new_element)
3358 new_element = FALSE;
3362 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3366 if (button == MB_MENU_LEAVE)
3368 PlaySound(SND_MENU_ITEM_SELECTING);
3370 info_mode = INFO_MODE_MAIN;
3375 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3377 if (button != MB_MENU_INITIALIZE)
3379 PlaySound(SND_MENU_ITEM_SELECTING);
3381 page += (dx < 0 ? -1 : +1);
3384 if (page < 0 || page >= num_pages)
3386 FadeInfoSoundsAndMusic();
3388 info_mode = INFO_MODE_MAIN;
3394 if (button != MB_MENU_INITIALIZE)
3395 FadeSetNextScreen();
3397 if (button != MB_MENU_INITIALIZE)
3398 FadeOut(REDRAW_FIELD);
3402 DrawInfoScreen_Headline(page, num_pages, TRUE);
3403 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3405 if (button != MB_MENU_INITIALIZE)
3406 FadeIn(REDRAW_FIELD);
3410 if (DelayReached(&info_delay))
3411 if (page < num_pages)
3412 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3414 PlayInfoSoundIfLoop();
3418 static void DrawInfoScreen_Music(void)
3420 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3424 FadeOut(REDRAW_FIELD);
3428 DrawInfoScreen_Headline(0, 1, TRUE);
3432 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3434 FadeIn(REDRAW_FIELD);
3437 void HandleInfoScreen_Music(int dx, int dy, int button)
3439 static struct MusicFileInfo *list = NULL;
3440 static int num_screens = 0;
3441 static int screen_nr = 0;
3442 int font_title = MENU_INFO_FONT_TITLE;
3443 int font_head = MENU_INFO_FONT_HEAD;
3444 int font_text = MENU_INFO_FONT_TEXT;
3445 int font_foot = MENU_INFO_FONT_FOOT;
3446 int spacing_head = menu.headline2_spacing_info[info_mode];
3447 int ystep_head = getMenuTextStep(spacing_head, font_head);
3448 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3449 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3451 if (button == MB_MENU_INITIALIZE)
3453 struct MusicFileInfo *list_ptr = music_file_info;
3458 while (list_ptr != NULL)
3460 list_ptr = list_ptr->next;
3464 list = music_file_info;
3468 FadeMenuSoundsAndMusic();
3472 DrawInfoScreen_Headline(0, 1, TRUE);
3474 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3475 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3481 if (button == MB_MENU_LEAVE)
3483 PlaySound(SND_MENU_ITEM_SELECTING);
3485 FadeMenuSoundsAndMusic();
3487 info_mode = INFO_MODE_MAIN;
3492 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3494 if (button != MB_MENU_INITIALIZE)
3496 PlaySound(SND_MENU_ITEM_SELECTING);
3500 list = (dx < 0 ? list->prev : list->next);
3501 screen_nr += (dx < 0 ? -1 : +1);
3507 FadeMenuSoundsAndMusic();
3509 info_mode = INFO_MODE_MAIN;
3515 FadeMenuSoundsAndMusic();
3517 if (list != music_file_info)
3518 FadeSetNextScreen();
3520 if (button != MB_MENU_INITIALIZE)
3521 FadeOut(REDRAW_FIELD);
3525 DrawInfoScreen_Headline(screen_nr, num_screens, TRUE);
3529 int sound = list->music;
3531 if (IS_LOOP_SOUND(sound))
3532 PlaySoundLoop(sound);
3538 int music = list->music;
3540 if (IS_LOOP_MUSIC(music))
3541 PlayMusicLoop(music);
3546 if (!strEqual(list->title, UNKNOWN_NAME))
3548 if (!strEqual(list->title_header, UNKNOWN_NAME))
3549 DrawTextSCentered(ystart, font_head, list->title_header);
3551 DrawTextSCentered(ystart, font_head, "Track");
3553 ystart += ystep_head;
3555 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3556 ystart += ystep_head;
3559 if (!strEqual(list->artist, UNKNOWN_NAME))
3561 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3562 DrawTextSCentered(ystart, font_head, list->artist_header);
3564 DrawTextSCentered(ystart, font_head, "by");
3566 ystart += ystep_head;
3568 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3569 ystart += ystep_head;
3572 if (!strEqual(list->album, UNKNOWN_NAME))
3574 if (!strEqual(list->album_header, UNKNOWN_NAME))
3575 DrawTextSCentered(ystart, font_head, list->album_header);
3577 DrawTextSCentered(ystart, font_head, "from the album");
3579 ystart += ystep_head;
3581 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3582 ystart += ystep_head;
3585 if (!strEqual(list->year, UNKNOWN_NAME))
3587 if (!strEqual(list->year_header, UNKNOWN_NAME))
3588 DrawTextSCentered(ystart, font_head, list->year_header);
3590 DrawTextSCentered(ystart, font_head, "from the year");
3592 ystart += ystep_head;
3594 DrawTextFCentered(ystart, font_text, "%s", list->year);
3595 ystart += ystep_head;
3598 if (!strEqual(list->played, UNKNOWN_NAME))
3600 if (!strEqual(list->played_header, UNKNOWN_NAME))
3601 DrawTextSCentered(ystart, font_head, list->played_header);
3603 DrawTextSCentered(ystart, font_head, "played in");
3605 ystart += ystep_head;
3607 DrawTextFCentered(ystart, font_text, "%s", list->played);
3608 ystart += ystep_head;
3610 else if (!list->is_sound)
3612 int music_level_nr = -1;
3615 // check if this music is configured for a certain level
3616 for (i = leveldir_current->first_level;
3617 i <= leveldir_current->last_level; i++)
3619 // (special case: "list->music" may be negative for unconfigured music)
3620 if (levelset.music[i] != MUS_UNDEFINED &&
3621 levelset.music[i] == list->music)
3629 if (music_level_nr != -1)
3631 if (!strEqual(list->played_header, UNKNOWN_NAME))
3632 DrawTextSCentered(ystart, font_head, list->played_header);
3634 DrawTextSCentered(ystart, font_head, "played in");
3636 ystart += ystep_head;
3638 DrawTextFCentered(ystart, font_text, "level %03d", music_level_nr);
3639 ystart += ystep_head;
3643 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3645 if (button != MB_MENU_INITIALIZE)
3646 FadeIn(REDRAW_FIELD);
3649 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3650 PlaySoundLoop(list->music);
3653 static void DrawInfoScreen_Version(void)
3655 int font_head = MENU_INFO_FONT_HEAD;
3656 int font_text = MENU_INFO_FONT_TEXT;
3657 int font_foot = MENU_INFO_FONT_FOOT;
3658 int spacing_head = menu.headline2_spacing_info[info_mode];
3659 int spacing_para = menu.paragraph_spacing_info[info_mode];
3660 int spacing_line = menu.line_spacing_info[info_mode];
3661 int xstep = getFontWidth(font_text);
3662 int ystep_head = getMenuTextStep(spacing_head, font_head);
3663 int ystep_para = getMenuTextStep(spacing_para, font_text);
3664 int ystep_line = getMenuTextStep(spacing_line, font_text);
3665 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3666 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3667 int xstart1 = mSX - SX + 2 * xstep;
3668 int xstart2 = mSX - SX + 18 * xstep;
3669 int xstart3 = mSX - SX + 28 * xstep;
3670 SDL_version sdl_version_compiled;
3671 const SDL_version *sdl_version_linked;
3672 int driver_name_len = 10;
3673 SDL_version sdl_version_linked_ext;
3674 const char *driver_name = NULL;
3676 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3679 FadeInfoSoundsAndMusic();
3681 FadeOut(REDRAW_FIELD);
3685 DrawInfoScreen_Headline(0, 1, TRUE);
3687 DrawTextF(xstart1, ystart, font_head, "Name");
3688 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3689 ystart += ystep_line;
3691 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3693 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3694 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3695 ystart += ystep_line;
3697 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3698 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3699 ystart += ystep_line;
3703 DrawTextF(xstart1, ystart, font_head, "Version");
3704 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3705 ystart += ystep_line;
3708 DrawTextF(xstart1, ystart, font_head, "Platform");
3709 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3711 PLATFORM_XX_BIT_STRING);
3712 ystart += ystep_line;
3714 DrawTextF(xstart1, ystart, font_head, "Target");
3715 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3716 ystart += ystep_line;
3718 DrawTextF(xstart1, ystart, font_head, "Source date");
3719 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3720 ystart += ystep_line;
3722 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3723 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3724 ystart += ystep_para;
3726 DrawTextF(xstart1, ystart, font_head, "Library");
3727 DrawTextF(xstart2, ystart, font_head, "compiled");
3728 DrawTextF(xstart3, ystart, font_head, "linked");
3729 ystart += ystep_head;
3731 SDL_VERSION(&sdl_version_compiled);
3732 SDL_GetVersion(&sdl_version_linked_ext);
3733 sdl_version_linked = &sdl_version_linked_ext;
3735 DrawTextF(xstart1, ystart, font_text, "SDL");
3736 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3737 sdl_version_compiled.major,
3738 sdl_version_compiled.minor,
3739 sdl_version_compiled.patch);
3740 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3741 sdl_version_linked->major,
3742 sdl_version_linked->minor,
3743 sdl_version_linked->patch);
3744 ystart += ystep_line;
3746 SDL_IMAGE_VERSION(&sdl_version_compiled);
3747 sdl_version_linked = IMG_Linked_Version();
3749 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3750 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3751 sdl_version_compiled.major,
3752 sdl_version_compiled.minor,
3753 sdl_version_compiled.patch);
3754 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3755 sdl_version_linked->major,
3756 sdl_version_linked->minor,
3757 sdl_version_linked->patch);
3758 ystart += ystep_line;
3760 SDL_MIXER_VERSION(&sdl_version_compiled);
3761 sdl_version_linked = Mix_Linked_Version();
3763 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3764 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3765 sdl_version_compiled.major,
3766 sdl_version_compiled.minor,
3767 sdl_version_compiled.patch);
3768 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3769 sdl_version_linked->major,
3770 sdl_version_linked->minor,
3771 sdl_version_linked->patch);
3772 ystart += ystep_line;
3774 SDL_NET_VERSION(&sdl_version_compiled);
3775 sdl_version_linked = SDLNet_Linked_Version();
3777 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3778 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3779 sdl_version_compiled.major,
3780 sdl_version_compiled.minor,
3781 sdl_version_compiled.patch);
3782 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3783 sdl_version_linked->major,
3784 sdl_version_linked->minor,
3785 sdl_version_linked->patch);
3786 ystart += ystep_para;
3788 DrawTextF(xstart1, ystart, font_head, "Driver");
3789 DrawTextF(xstart2, ystart, font_head, "Requested");
3790 DrawTextF(xstart3, ystart, font_head, "Used");
3791 ystart += ystep_head;
3794 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3796 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3797 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3798 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3799 ystart += ystep_line;
3802 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3804 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3805 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3806 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3807 ystart += ystep_line;
3810 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3812 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3813 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3814 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3816 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3818 PlayInfoSoundsAndMusic();
3820 FadeIn(REDRAW_FIELD);
3823 void HandleInfoScreen_Version(int button)
3825 if (button == MB_MENU_LEAVE)
3827 PlaySound(SND_MENU_ITEM_SELECTING);
3829 info_mode = INFO_MODE_MAIN;
3834 else if (button == MB_MENU_CHOICE)
3836 PlaySound(SND_MENU_ITEM_SELECTING);
3838 FadeMenuSoundsAndMusic();
3840 info_mode = INFO_MODE_MAIN;
3845 PlayMenuSoundIfLoop();
3849 static char *getInfoScreenTitle_Generic(void)
3851 return (info_mode == INFO_MODE_MAIN ? STR_INFO_MAIN :
3852 info_mode == INFO_MODE_TITLE ? STR_INFO_TITLE :
3853 info_mode == INFO_MODE_ELEMENTS ? STR_INFO_ELEMENTS :
3854 info_mode == INFO_MODE_MUSIC ? STR_INFO_MUSIC :
3855 info_mode == INFO_MODE_CREDITS ? STR_INFO_CREDITS :
3856 info_mode == INFO_MODE_PROGRAM ? STR_INFO_PROGRAM :
3857 info_mode == INFO_MODE_VERSION ? STR_INFO_VERSION :
3858 info_mode == INFO_MODE_LEVELSET ? STR_INFO_LEVELSET :
3862 static int getInfoScreenBackgroundImage_Generic(void)
3864 return (info_mode == INFO_MODE_ELEMENTS ? IMG_BACKGROUND_INFO_ELEMENTS :
3865 info_mode == INFO_MODE_MUSIC ? IMG_BACKGROUND_INFO_MUSIC :
3866 info_mode == INFO_MODE_CREDITS ? IMG_BACKGROUND_INFO_CREDITS :
3867 info_mode == INFO_MODE_PROGRAM ? IMG_BACKGROUND_INFO_PROGRAM :
3868 info_mode == INFO_MODE_VERSION ? IMG_BACKGROUND_INFO_VERSION :
3869 info_mode == INFO_MODE_LEVELSET ? IMG_BACKGROUND_INFO_LEVELSET :
3870 IMG_BACKGROUND_INFO);
3873 static int getInfoScreenBackgroundSound_Generic(void)
3875 return (info_mode == INFO_MODE_ELEMENTS ? SND_BACKGROUND_INFO_ELEMENTS :
3876 info_mode == INFO_MODE_CREDITS ? SND_BACKGROUND_INFO_CREDITS :
3877 info_mode == INFO_MODE_PROGRAM ? SND_BACKGROUND_INFO_PROGRAM :
3878 info_mode == INFO_MODE_VERSION ? SND_BACKGROUND_INFO_VERSION :
3879 info_mode == INFO_MODE_LEVELSET ? SND_BACKGROUND_INFO_LEVELSET :
3880 SND_BACKGROUND_INFO);
3883 static int getInfoScreenBackgroundMusic_Generic(void)
3885 return (info_mode == INFO_MODE_ELEMENTS ? MUS_BACKGROUND_INFO_ELEMENTS :
3886 info_mode == INFO_MODE_CREDITS ? MUS_BACKGROUND_INFO_CREDITS :
3887 info_mode == INFO_MODE_PROGRAM ? MUS_BACKGROUND_INFO_PROGRAM :
3888 info_mode == INFO_MODE_VERSION ? MUS_BACKGROUND_INFO_VERSION :
3889 info_mode == INFO_MODE_LEVELSET ? MUS_BACKGROUND_INFO_LEVELSET :
3890 MUS_BACKGROUND_INFO);
3893 static char *getInfoScreenFilename_Generic(int nr, boolean global)
3895 return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) :
3896 info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) :
3897 info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) :
3901 static void DrawInfoScreen_GenericScreen(int screen_nr, int num_screens,
3902 int use_global_screens)
3904 char *filename = getInfoScreenFilename_Generic(screen_nr, use_global_screens);
3905 int font_text = MENU_INFO_FONT_TEXT;
3906 int font_foot = MENU_INFO_FONT_FOOT;
3907 int spacing_line = menu.line_spacing_info[info_mode];
3908 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3912 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3914 if (info_mode == INFO_MODE_CREDITS ||
3915 info_mode == INFO_MODE_PROGRAM)
3918 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART;
3919 int chars = width / getFontWidth(font_text);
3920 int lines = height / getFontHeight(font_text);
3921 int padx = (width - chars * getFontWidth(font_text)) / 2;
3922 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3923 int xstart = mSX + padx;
3924 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3925 boolean autowrap = FALSE;
3926 boolean centered = TRUE;
3927 boolean parse_comments = TRUE;
3929 DrawTextFile(xstart, ystart,
3930 filename, font_text, chars, -1, lines, line_spacing, -1,
3931 autowrap, centered, parse_comments);
3933 else if (info_mode == INFO_MODE_LEVELSET)
3935 struct TitleMessageInfo *tmi = &readme;
3937 // if x position set to "-1", automatically determine by playfield width
3939 tmi->x = SXSIZE / 2;
3941 // if y position set to "-1", use static default value
3943 tmi->y = MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3945 // if width set to "-1", automatically determine by playfield width
3946 if (tmi->width == -1)
3947 tmi->width = SXSIZE - 2 * TILEX;
3949 // if height set to "-1", automatically determine by playfield height
3950 if (tmi->height == -1)
3951 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3953 // if chars set to "-1", automatically determine by text and font width
3954 if (tmi->chars == -1)
3955 tmi->chars = tmi->width / getFontWidth(tmi->font);
3957 tmi->width = tmi->chars * getFontWidth(tmi->font);
3959 // if lines set to "-1", automatically determine by text and font height
3960 if (tmi->lines == -1)
3961 tmi->lines = tmi->height / getFontHeight(tmi->font);
3963 tmi->height = tmi->lines * getFontHeight(tmi->font);
3965 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3966 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3967 tmi->autowrap, tmi->centered, tmi->parse_comments);
3970 boolean last_screen = (screen_nr == num_screens - 1);
3971 char *text_foot = (last_screen ? TEXT_NEXT_MENU : TEXT_NEXT_PAGE);
3973 DrawTextSCentered(ybottom, font_foot, text_foot);
3976 static void DrawInfoScreen_Generic(void)
3978 SetMainBackgroundImageIfDefined(getInfoScreenBackgroundImage_Generic());
3981 FadeInfoSoundsAndMusic();
3983 FadeOut(REDRAW_FIELD);
3985 HandleInfoScreen_Generic(0, 0, MB_MENU_INITIALIZE);
3987 PlayInfoSoundsAndMusic();
3989 FadeIn(REDRAW_FIELD);
3992 void HandleInfoScreen_Generic(int dx, int dy, int button)
3994 static char *text_no_info = "";
3995 static int num_screens = 0;
3996 static int screen_nr = 0;
3997 static boolean use_global_screens = FALSE;
3999 if (button == MB_MENU_INITIALIZE)
4004 if (info_mode == INFO_MODE_CREDITS)
4008 for (i = 0; i < 2; i++)
4010 use_global_screens = i; // check for "FALSE", then "TRUE"
4012 // determine number of (global or level set specific) credits screens
4013 while (getCreditsFilename(num_screens, use_global_screens) != NULL)
4016 if (num_screens > 0)
4020 text_no_info = "No credits available.";
4022 else if (info_mode == INFO_MODE_PROGRAM)
4024 use_global_screens = TRUE;
4026 // determine number of program info screens
4027 while (getProgramInfoFilename(num_screens) != NULL)
4030 text_no_info = "No program info available.";
4032 else if (info_mode == INFO_MODE_LEVELSET)
4034 use_global_screens = FALSE;
4036 // determine number of levelset info screens
4037 while (getLevelSetInfoFilename(num_screens) != NULL)
4040 text_no_info = "No level set info available.";
4043 if (num_screens == 0)
4045 int font_title = MENU_INFO_FONT_TITLE;
4046 int font_foot = MENU_INFO_FONT_FOOT;
4047 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
4048 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
4052 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
4054 DrawTextSCentered(ystart, font_title, text_no_info);
4055 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
4060 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4062 else if (button == MB_MENU_LEAVE)
4064 PlaySound(SND_MENU_ITEM_SELECTING);
4066 info_mode = INFO_MODE_MAIN;
4069 else if (button == MB_MENU_CHOICE || dx)
4071 PlaySound(SND_MENU_ITEM_SELECTING);
4073 screen_nr += (dx < 0 ? -1 : +1);
4075 if (screen_nr < 0 || screen_nr >= num_screens)
4077 FadeInfoSoundsAndMusic();
4079 info_mode = INFO_MODE_MAIN;
4084 FadeSetNextScreen();
4086 FadeOut(REDRAW_FIELD);
4088 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4090 FadeIn(REDRAW_FIELD);
4095 PlayInfoSoundIfLoop();
4099 static void DrawInfoScreen(void)
4101 if (info_mode == INFO_MODE_TITLE)
4102 DrawInfoScreen_TitleScreen();
4103 else if (info_mode == INFO_MODE_ELEMENTS)
4104 DrawInfoScreen_Elements();
4105 else if (info_mode == INFO_MODE_MUSIC)
4106 DrawInfoScreen_Music();
4107 else if (info_mode == INFO_MODE_CREDITS)
4108 DrawInfoScreen_Generic();
4109 else if (info_mode == INFO_MODE_PROGRAM)
4110 DrawInfoScreen_Generic();
4111 else if (info_mode == INFO_MODE_VERSION)
4112 DrawInfoScreen_Version();
4113 else if (info_mode == INFO_MODE_LEVELSET)
4114 DrawInfoScreen_Generic();
4116 DrawInfoScreen_Main();
4119 void DrawInfoScreen_FromMainMenu(int nr)
4121 int fade_mask = REDRAW_FIELD;
4123 if (nr < INFO_MODE_MAIN || nr >= MAX_INFO_MODES)
4126 CloseDoor(DOOR_CLOSE_2);
4128 SetGameStatus(GAME_MODE_INFO);
4131 info_screens_from_main = TRUE;
4133 if (redraw_mask & REDRAW_ALL)
4134 fade_mask = REDRAW_ALL;
4137 fade_mask = REDRAW_ALL;
4140 FadeMenuSoundsAndMusic();
4142 FadeSetEnterScreen();
4146 FadeSkipNextFadeOut();
4148 // needed if different viewport properties defined for info screen
4149 ChangeViewportPropertiesIfNeeded();
4151 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
4156 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4158 if (info_mode == INFO_MODE_TITLE)
4159 HandleInfoScreen_TitleScreen(dx, dy, button);
4160 else if (info_mode == INFO_MODE_ELEMENTS)
4161 HandleInfoScreen_Elements(dx, dy, button);
4162 else if (info_mode == INFO_MODE_MUSIC)
4163 HandleInfoScreen_Music(dx, dy, button);
4164 else if (info_mode == INFO_MODE_CREDITS)
4165 HandleInfoScreen_Generic(dx, dy, button);
4166 else if (info_mode == INFO_MODE_PROGRAM)
4167 HandleInfoScreen_Generic(dx, dy, button);
4168 else if (info_mode == INFO_MODE_VERSION)
4169 HandleInfoScreen_Version(button);
4170 else if (info_mode == INFO_MODE_LEVELSET)
4171 HandleInfoScreen_Generic(dx, dy, button);
4173 HandleInfoScreen_Main(mx, my, dx, dy, button);
4177 // ============================================================================
4178 // type name functions
4179 // ============================================================================
4181 static TreeInfo *type_name_node = NULL;
4182 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4183 static int type_name_nr = 0;
4185 static int getPlayerNameColor(char *name)
4187 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4190 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4193 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4194 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4195 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4196 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4197 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4198 int font_width = getFontWidth(font_nr);
4199 int font_xoffset = getFontDrawOffsetX(font_nr);
4200 int font_yoffset = getFontDrawOffsetY(font_nr);
4201 int font_sx = sx + font_xoffset;
4202 int font_sy = sy + font_yoffset;
4204 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4206 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4208 pos->width = strlen(text) * font_width;
4209 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4211 DrawText(sx, sy, text, font_nr);
4214 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4216 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4218 *pos = *mci->pos_input;
4220 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4222 TreeInfo *ti = player_name_current;
4223 int first_entry = ti->cl_first;
4224 int entry_pos = first_entry + ti->cl_cursor;
4225 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4226 int xpos = MENU_SCREEN_START_XPOS;
4227 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4229 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4230 type_name_nr = entry_pos;
4232 strcpy(name, type_name_node->name);
4236 pos->width = MAX_PLAYER_NAME_LEN * 32;
4240 type_name_nr = user.nr;
4242 strcpy(name, setup.player_name);
4245 strcpy(type_name_last, name);
4247 if (strEqual(name, EMPTY_PLAYER_NAME))
4250 *xpos = strlen(name);
4253 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4255 // change name of edited user in global list of user names
4256 setString(&global.user_names[type_name_nr], name);
4258 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4260 TreeInfo *node = type_name_node;
4262 // change name of edited user in local menu tree structure
4263 setString(&node->name, name);
4264 setString(&node->name_sorting, name);
4266 node->color = getPlayerNameColor(name);
4267 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4271 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4274 boolean reset_setup = strEqual(name, "");
4275 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4276 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4279 strcpy(name, type_name_last);
4281 if (strEqual(name, ""))
4282 strcpy(name, EMPTY_PLAYER_NAME);
4284 setTypeNameValues_Name(name, pos);
4286 // if player name not changed, no further action required
4287 if (strEqual(name, type_name_last))
4290 // redraw player name before (possibly) opening request dialogs
4291 drawTypeNameText(name, pos, FALSE);
4293 int last_user_nr = user.nr;
4295 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4297 // save setup of currently active user (may differ from edited user)
4300 // temporarily change active user to edited user
4301 user.nr = type_name_nr;
4304 Request("Use current setup values for the new player?", REQ_ASK))
4306 // use current setup values for new user, but create new player UUID
4307 setup.player_uuid = getStringCopy(getUUID());
4311 // load setup for existing user (or start with defaults for new user)
4316 char *setup_filename = getSetupFilename();
4317 boolean setup_exists = fileExists(setup_filename);
4319 // change name of edited user in setup structure
4320 strcpy(setup.player_name, name);
4322 // save setup of edited user
4325 // change name of edited user on score server
4326 ApiRenamePlayerAsThread();
4328 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4332 if (Request("Reset setup values for this player?", REQ_ASK))
4334 // remove setup config file
4335 unlink(setup_filename);
4337 // set player name to default player name
4340 // update player name used by name typing functions
4341 strcpy(name, setup.player_name);
4343 setTypeNameValues_Name(name, pos);
4346 else if (remove_user && type_name_nr != 0)
4348 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4350 char *user_dir = getUserGameDataDir();
4351 char *user_dir_removed =
4352 getStringCat3WithSeparator(user_dir, "REMOVED",
4353 getCurrentTimestamp(), ".");
4355 if (rename(user_dir, user_dir_removed) != 0)
4356 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4358 checked_free(user_dir_removed);
4361 else if (create_user && type_name_nr != 0 && !setup_exists)
4363 if (Request("Create empty level set for the new player?", REQ_ASK))
4365 char *levelset_subdir = getNewUserLevelSubdir();
4367 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4369 AddUserLevelSetToLevelInfo(levelset_subdir);
4371 LevelDirTree *leveldir_current_last = leveldir_current;
4373 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4376 // set level number of newly created level set to default value
4377 LoadLevelSetup_SeriesInfo();
4379 // set newly created level set as current level set for new user
4380 SaveLevelSetup_LastSeries();
4381 SaveLevelSetup_SeriesInfo();
4383 leveldir_current = leveldir_current_last;
4387 Request("Creating new level set failed!", REQ_CONFIRM);
4392 // restore currently active user
4393 user.nr = last_user_nr;
4395 // restore setup of currently active user
4398 // restore last level set of currently active user
4399 LoadLevelSetup_LastSeries();
4400 LoadLevelSetup_SeriesInfo();
4404 static void HandleTypeNameExt(boolean initialize, Key key)
4406 static struct TextPosInfo pos_name = { 0 };
4407 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4408 static int xpos = 0;
4409 struct TextPosInfo *pos = &pos_name;
4410 char key_char = getValidConfigValueChar(getCharFromKey(key));
4411 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4412 boolean active = TRUE;
4416 getTypeNameValues(name, pos, &xpos);
4418 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4419 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4421 StartTextInput(sx, sy, pos->width, pos->height);
4423 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4425 name[xpos] = key_char;
4430 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4436 else if (key == KSYM_Return || key == KSYM_Escape)
4438 boolean changed = (key == KSYM_Return);
4442 setTypeNameValues(name, pos, changed);
4447 drawTypeNameText(name, pos, active);
4451 SetGameStatus(game_status_last_screen);
4453 if (game_status == GAME_MODE_MAIN)
4454 InitializeMainControls();
4458 static void DrawTypeName(void)
4460 HandleTypeNameExt(TRUE, 0);
4463 void HandleTypeName(Key key)
4465 HandleTypeNameExt(FALSE, key);
4469 // ============================================================================
4470 // tree menu functions
4471 // ============================================================================
4473 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4475 if (game_status != GAME_MODE_SETUP ||
4476 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4479 int max_text_size = 0;
4482 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4483 max_text_size = MAX(max_text_size, strlen(node->name));
4485 int num_entries = numTreeInfoInGroup(ti);
4486 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4487 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4488 int text_width = max_text_size * getFontWidth(font_nr);
4489 int button_width = SC_MENUBUTTON_XSIZE;
4490 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4491 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4492 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4493 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4494 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4495 int align_xoffset = MAX(0, align_xoffset_raw);
4497 return align_xoffset;
4500 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4502 if (game_status != GAME_MODE_SETUP ||
4503 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4506 int num_entries = numTreeInfoInGroup(ti);
4507 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4508 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4509 int font_height = getFontHeight(font_nr);
4510 int text_height = font_height * num_page_entries;
4511 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4512 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4513 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4514 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4515 int align_yoffset = MAX(0, align_yoffset_raw);
4517 return align_yoffset;
4520 static void StartPlayingFromHallOfFame(void)
4522 level_nr = scores.next_level_nr;
4523 LoadLevel(level_nr);
4525 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4528 static void DrawChooseTree(TreeInfo **ti_ptr)
4530 int fade_mask = REDRAW_FIELD;
4531 boolean restart_music = (game_status != game_status_last_screen &&
4532 game_status_last_screen != GAME_MODE_SCOREINFO);
4534 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4535 game_status_last_screen == GAME_MODE_PLAYING);
4538 fade_mask = REDRAW_ALL;
4540 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4542 if (game_status == GAME_MODE_SETUP)
4546 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4548 StartPlayingFromHallOfFame();
4552 SetGameStatus(GAME_MODE_MAIN);
4562 FreeScreenGadgets();
4563 CreateScreenGadgets();
4566 FadeMenuSoundsAndMusic();
4570 // needed if different viewport properties defined for this screen
4571 ChangeViewportPropertiesIfNeeded();
4573 if (game_status == GAME_MODE_NAMES)
4574 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4575 else if (game_status == GAME_MODE_LEVELNR)
4576 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4577 else if (game_status == GAME_MODE_LEVELS)
4578 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4579 else if (game_status == GAME_MODE_SCORES)
4580 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4584 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4586 // map gadgets for high score screen
4587 if (game_status == GAME_MODE_SCORES)
4588 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4590 MapScreenTreeGadgets(*ti_ptr);
4592 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4594 DrawMaskedBorder(fade_mask);
4597 PlayMenuSoundsAndMusic();
4602 static int getChooseTreeFont(TreeInfo *node, boolean active)
4604 if (game_status == GAME_MODE_SCORES)
4605 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4607 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4610 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4612 int num_entries = numTreeInfoInGroup(ti);
4613 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4614 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4615 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4616 int first_entry = ti->cl_first;
4617 int entry_pos = first_entry + y;
4618 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4619 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4620 int font_nr = getChooseTreeFont(node, active);
4621 int font_xoffset = getFontDrawOffsetX(font_nr);
4622 int xpos = MENU_SCREEN_START_XPOS;
4623 int ypos = MENU_SCREEN_START_YPOS + y;
4624 int startdx = xpos * 32;
4625 int startdy = ypos * 32;
4626 int startx = amSX + startdx;
4627 int starty = amSY + startdy;
4628 int startx_text = startx + font_xoffset;
4629 int endx_text = amSX + screen_width;
4630 int max_text_size = endx_text - startx_text;
4631 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4632 char buffer[max_buffer_len + 1];
4634 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4636 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4637 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4638 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4639 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4640 int font_size_1 = getFontWidth(font_nr1);
4641 int font_size_3 = getFontWidth(font_nr3);
4642 int font_size_4 = getFontWidth(font_nr4);
4643 int text_size_1 = 4 * font_size_1;
4644 int text_size_4 = 5 * font_size_4;
4645 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4647 int dx3 = text_size_1;
4648 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4649 int num_dots = (dx4 - dx3) / font_size_3;
4650 int startx1 = startx + dx1;
4651 int startx3 = startx + dx3;
4652 int startx4 = startx + dx4;
4653 int pos = node->pos;
4654 char *pos_text = getHallOfFameRankText(pos, 3);
4657 DrawText(startx1, starty, pos_text, font_nr1);
4659 for (i = 0; i < num_dots; i++)
4660 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4662 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4663 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4665 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4669 strncpy(buffer, node->name, max_buffer_len);
4670 buffer[max_buffer_len] = '\0';
4672 DrawText(startx, starty, buffer, font_nr);
4676 static void drawChooseTreeHeadExt(int type, char *title_string)
4678 int yoffset_sets = MENU_TITLE1_YPOS;
4679 int yoffset_setup = 16;
4680 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4681 type == TREE_TYPE_LEVEL_DIR ||
4682 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4684 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4687 static void drawChooseTreeHead(TreeInfo *ti)
4689 drawChooseTreeHeadExt(ti->type, ti->infotext);
4692 static void drawChooseTreeList(TreeInfo *ti)
4694 int first_entry = ti->cl_first;
4695 int num_entries = numTreeInfoInGroup(ti);
4696 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4699 clearMenuListArea();
4701 for (i = 0; i < num_page_entries; i++)
4703 TreeInfo *node, *node_first;
4704 int entry_pos = first_entry + i;
4706 node_first = getTreeInfoFirstGroupEntry(ti);
4707 node = getTreeInfoFromPos(node_first, entry_pos);
4709 drawChooseTreeText(ti, i, FALSE);
4711 if (node->parent_link)
4712 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4713 else if (node->level_group)
4714 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4716 initCursor(i, IMG_MENU_BUTTON);
4718 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4719 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4721 if (game_status == GAME_MODE_NAMES)
4722 drawChooseTreeEdit(i, FALSE);
4725 redraw_mask |= REDRAW_FIELD;
4728 static void drawChooseTreeInfo(TreeInfo *ti)
4730 int entry_pos = ti->cl_first + ti->cl_cursor;
4731 int last_redraw_mask = redraw_mask;
4732 int ypos = MENU_TITLE2_YPOS;
4733 int font_nr = FONT_TITLE_2;
4736 if (ti->type == TREE_TYPE_LEVEL_NR)
4737 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4739 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4740 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4741 scores.last_level_nr);
4743 if (ti->type != TREE_TYPE_LEVEL_DIR)
4746 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4747 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4749 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4751 if (node->parent_link)
4752 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4753 node->node_parent->name);
4754 else if (node->level_group)
4755 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4757 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4758 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4759 node->levels, (node->levels > 1 ? "levels" : "level"),
4762 // let BackToFront() redraw only what is needed
4763 redraw_mask = last_redraw_mask;
4764 for (x = 0; x < SCR_FIELDX; x++)
4765 MarkTileDirty(x, 1);
4768 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4770 drawChooseTreeCursor(ti->cl_cursor, active);
4771 drawChooseTreeText(ti, ti->cl_cursor, active);
4774 static void drawChooseTreeScreen(TreeInfo *ti)
4776 drawChooseTreeHead(ti);
4777 drawChooseTreeList(ti);
4778 drawChooseTreeInfo(ti);
4779 drawChooseTreeCursorAndText(ti, TRUE);
4781 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4783 // scroll bar and buttons may just have been added after reloading scores
4784 if (game_status == GAME_MODE_SCORES)
4785 MapScreenTreeGadgets(ti);
4788 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4790 int score_pos = scores.last_added;
4792 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4793 score_pos = scores.last_entry_nr;
4795 // set current tree entry to last added score entry
4796 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4798 // if that fails, set current tree entry to first entry (back link)
4799 if (*ti_ptr == NULL)
4800 *ti_ptr = score_entries->node_group;
4802 int num_entries = numTreeInfoInGroup(*ti_ptr);
4803 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4804 int pos_score = getPosFromTreeInfo(*ti_ptr);
4805 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4806 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4808 (*ti_ptr)->cl_first = pos_first;
4809 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4814 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4817 TreeInfo *ti = *ti_ptr;
4818 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4819 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4820 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4821 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4822 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4824 int y = (ti != NULL ? ti->cl_cursor : 0);
4825 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4826 int num_entries = numTreeInfoInGroup(ti);
4827 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4828 boolean position_set_by_scrollbar = (dx == 999);
4830 if (game_status == GAME_MODE_SCORES)
4832 if (server_scores.updated)
4834 // reload scores, using updated server score cache file
4835 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4837 server_scores.updated = FALSE;
4839 DrawHallOfFame_setScoreEntries();
4841 ti = setHallOfFameActiveEntry(ti_ptr);
4843 if (button != MB_MENU_INITIALIZE)
4844 drawChooseTreeScreen(ti);
4848 if (button == MB_MENU_INITIALIZE)
4850 int num_entries = numTreeInfoInGroup(ti);
4851 int entry_pos = getPosFromTreeInfo(ti);
4853 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4854 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4856 if (game_status == GAME_MODE_SCORES)
4858 ti = setHallOfFameActiveEntry(ti_ptr);
4860 else if (ti->cl_first == -1)
4862 // only on initialization
4863 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4864 ti->cl_cursor = entry_pos - ti->cl_first;
4867 else if (ti->cl_cursor >= num_page_entries ||
4868 (num_entries > num_page_entries &&
4869 num_entries - ti->cl_first < num_page_entries))
4871 // only after change of list size (by custom graphic configuration)
4872 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4873 ti->cl_cursor = entry_pos - ti->cl_first;
4876 if (position_set_by_scrollbar)
4879 drawChooseTreeScreen(ti);
4883 else if (button == MB_MENU_LEAVE)
4885 if (game_status != GAME_MODE_SCORES)
4888 PlaySound(SND_MENU_ITEM_SELECTING);
4890 if (ti->node_parent)
4892 *ti_ptr = ti->node_parent;
4893 DrawChooseTree(ti_ptr);
4895 else if (game_status == GAME_MODE_SETUP)
4897 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4898 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4899 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4900 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4902 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4903 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4904 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4905 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4906 execSetupGraphics();
4907 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4908 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4909 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4911 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4912 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4913 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4914 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4915 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4916 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4917 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4918 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4925 if (game_status == GAME_MODE_LEVELNR)
4927 int new_level_nr = atoi(level_number_current->identifier);
4929 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4932 SetGameStatus(GAME_MODE_MAIN);
4940 #if defined(PLATFORM_ANDROID)
4941 // directly continue when touching the screen after playing
4942 if ((mx || my) && scores.continue_on_return)
4944 // ignore touch events until released
4949 // any mouse click or cursor key stops leaving scores by "Return" key
4950 if ((mx || my || dx || dy) && scores.continue_on_return)
4952 scores.continue_on_return = FALSE;
4953 level_nr = scores.last_level_nr;
4954 LoadLevel(level_nr);
4957 if (mx || my) // mouse input
4959 x = (mx - amSX) / 32;
4960 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4962 if (game_status == GAME_MODE_NAMES)
4963 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4965 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4967 // move cursor instead of scrolling when already at start/end of list
4968 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4970 else if (dy == +1 * SCROLL_LINE &&
4971 ti->cl_first + num_page_entries == num_entries)
4974 // handle scrolling screen one line or page
4975 if (ti->cl_cursor + dy < 0 ||
4976 ti->cl_cursor + dy > num_page_entries - 1)
4978 boolean redraw = FALSE;
4980 if (ABS(dy) == SCROLL_PAGE)
4981 step = num_page_entries - 1;
4983 if (dy < 0 && ti->cl_first > 0)
4985 // scroll page/line up
4987 ti->cl_first -= step;
4988 if (ti->cl_first < 0)
4993 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4995 // scroll page/line down
4997 ti->cl_first += step;
4998 if (ti->cl_first + num_page_entries > num_entries)
4999 ti->cl_first = MAX(0, num_entries - num_page_entries);
5005 drawChooseTreeScreen(ti);
5010 // handle moving cursor one line
5011 y = ti->cl_cursor + dy;
5014 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
5016 HandleHallOfFame_SelectLevel(1, dx);
5022 TreeInfo *node_first, *node_cursor;
5023 int entry_pos = ti->cl_first + y;
5025 node_first = getTreeInfoFirstGroupEntry(ti);
5026 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5028 if (node_cursor->node_group)
5032 PlaySound(SND_MENU_ITEM_SELECTING);
5034 node_cursor->cl_first = ti->cl_first;
5035 node_cursor->cl_cursor = ti->cl_cursor;
5037 *ti_ptr = node_cursor->node_group;
5038 DrawChooseTree(ti_ptr);
5043 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
5045 if (game_status != GAME_MODE_SCORES)
5048 PlaySound(SND_MENU_ITEM_SELECTING);
5050 *ti_ptr = ti->node_parent;
5051 DrawChooseTree(ti_ptr);
5056 if (!anyScrollbarGadgetActive() &&
5057 IN_VIS_MENU(x, y) &&
5058 mx < mx_right_border &&
5059 y >= 0 && y < num_page_entries)
5063 if (game_status == GAME_MODE_NAMES)
5065 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5066 drawChooseTreeEdit(y, TRUE);
5069 if (y != ti->cl_cursor)
5071 PlaySound(SND_MENU_ITEM_ACTIVATING);
5073 drawChooseTreeCursorAndText(ti, FALSE);
5077 drawChooseTreeCursorAndText(ti, TRUE);
5079 drawChooseTreeInfo(ti);
5083 if (game_status == GAME_MODE_SETUP)
5085 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5086 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5087 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5088 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5090 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5091 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5092 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5093 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5094 execSetupGraphics();
5095 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5096 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5097 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5099 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5100 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5101 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5102 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5103 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5104 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5105 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5106 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5115 TreeInfo *node_first, *node_cursor;
5116 int entry_pos = ti->cl_first + y;
5118 PlaySound(SND_MENU_ITEM_SELECTING);
5120 node_first = getTreeInfoFirstGroupEntry(ti);
5121 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5123 if (node_cursor->node_group)
5127 node_cursor->cl_first = ti->cl_first;
5128 node_cursor->cl_cursor = ti->cl_cursor;
5130 *ti_ptr = node_cursor->node_group;
5131 DrawChooseTree(ti_ptr);
5133 else if (node_cursor->parent_link)
5135 if (game_status != GAME_MODE_SCORES)
5138 *ti_ptr = node_cursor->node_parent;
5139 DrawChooseTree(ti_ptr);
5143 if (game_status != GAME_MODE_SCORES)
5146 node_cursor->cl_first = ti->cl_first;
5147 node_cursor->cl_cursor = ti->cl_cursor;
5149 *ti_ptr = node_cursor;
5151 if (ti->type == TREE_TYPE_LEVEL_DIR)
5153 LoadLevelSetup_SeriesInfo();
5155 SaveLevelSetup_LastSeries();
5156 SaveLevelSetup_SeriesInfo();
5160 if (game_status == GAME_MODE_SETUP)
5162 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5163 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5164 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5165 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5167 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5168 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5169 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5170 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5171 execSetupGraphics();
5172 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5173 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5174 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5176 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5177 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5178 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5179 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5180 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5181 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5182 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5183 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5190 if (game_status == GAME_MODE_LEVELNR)
5192 int new_level_nr = atoi(level_number_current->identifier);
5194 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5196 else if (game_status == GAME_MODE_LEVELS)
5198 // store level set if chosen from "last played level set" menu
5199 StoreLastPlayedLevels(leveldir_current);
5201 // store if level set chosen from "last played level set" menu
5202 SaveLevelSetup_LastSeries();
5204 else if (game_status == GAME_MODE_NAMES)
5206 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5208 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5215 // change active user to selected user
5216 user.nr = entry_pos;
5218 // save number of new active user
5221 // load setup of new active user
5224 // load last level set of new active user
5225 LoadLevelSetup_LastSeries();
5226 LoadLevelSetup_SeriesInfo();
5228 // update list of last played level sets
5229 UpdateLastPlayedLevels_TreeInfo();
5233 ToggleFullscreenIfNeeded();
5234 ChangeWindowScalingIfNeeded();
5236 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5237 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5238 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5240 else if (game_status == GAME_MODE_SCORES)
5242 if (scores.continue_playing && scores.continue_on_return)
5244 StartPlayingFromHallOfFame();
5248 else if (!scores.continue_on_return)
5250 SetGameStatus(GAME_MODE_SCOREINFO);
5252 DrawScoreInfo(node_cursor->pos);
5258 SetGameStatus(GAME_MODE_MAIN);
5266 if (game_status == GAME_MODE_SCORES)
5267 PlayMenuSoundIfLoop();
5270 void DrawChoosePlayerName(void)
5274 if (player_name != NULL)
5276 freeTreeInfo(player_name);
5281 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5283 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5284 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5287 ti->node_top = &player_name;
5288 ti->sort_priority = 10000 + value;
5289 ti->color = getPlayerNameColor(global.user_names[i]);
5291 snprintf(identifier, sizeof(identifier), "%d", value);
5292 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5294 setString(&ti->identifier, identifier);
5295 setString(&ti->name, name);
5296 setString(&ti->name_sorting, name);
5298 pushTreeInfo(&player_name, ti);
5301 // sort player entries by player number
5302 sortTreeInfo(&player_name);
5304 // set current player entry to selected player entry
5305 player_name_current =
5306 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5308 // if that fails, set current player name to first available name
5309 if (player_name_current == NULL)
5310 player_name_current = player_name;
5312 // set text size for main name input (also used on name selection screen)
5313 InitializeMainControls();
5315 DrawChooseTree(&player_name_current);
5318 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5320 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5323 void DrawChooseLevelSet(void)
5325 DrawChooseTree(&leveldir_current);
5328 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5330 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5333 void DrawChooseLevelNr(void)
5337 if (level_number != NULL)
5339 freeTreeInfo(level_number);
5341 level_number = NULL;
5344 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5346 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5347 char identifier[32], name[64];
5350 // temporarily load level info to get level name
5351 LoadLevelInfoOnly(i);
5353 ti->node_top = &level_number;
5354 ti->sort_priority = 10000 + value;
5355 ti->color = (level.no_level_file ? FC_BLUE :
5356 LevelStats_getSolved(i) ? FC_GREEN :
5357 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5359 snprintf(identifier, sizeof(identifier), "%d", value);
5360 snprintf(name, sizeof(name), "%03d: %s", value,
5361 (level.no_level_file ? "(no file)" : level.name));
5363 setString(&ti->identifier, identifier);
5364 setString(&ti->name, name);
5365 setString(&ti->name_sorting, name);
5367 pushTreeInfo(&level_number, ti);
5370 // sort level number values to start with lowest level number
5371 sortTreeInfo(&level_number);
5373 // set current level number to current level number
5374 level_number_current =
5375 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5377 // if that also fails, set current level number to first available level
5378 if (level_number_current == NULL)
5379 level_number_current = level_number;
5381 DrawChooseTree(&level_number_current);
5384 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5386 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5389 static void DrawHallOfFame_setScoreEntries(void)
5391 int max_empty_entries = 10; // at least show "top ten" list, if empty
5392 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5393 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5394 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5397 if (score_entries != NULL)
5399 freeTreeInfo(score_entries);
5401 score_entries = NULL;
5404 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5406 // do not add empty score entries if off-screen
5407 if (scores.entry[i].score == 0 &&
5408 scores.entry[i].time == 0 &&
5409 i >= min_score_entries)
5412 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5413 char identifier[32], name[64];
5416 ti->node_top = &score_entries;
5417 ti->sort_priority = 10000 + value;
5418 ti->color = FC_YELLOW;
5421 snprintf(identifier, sizeof(identifier), "%d", value);
5422 snprintf(name, sizeof(name), "%03d.", value + 1);
5424 setString(&ti->identifier, identifier);
5425 setString(&ti->name, name);
5426 setString(&ti->name_sorting, name);
5428 pushTreeInfo(&score_entries, ti);
5431 // sort score entries to start with highest score entry
5432 sortTreeInfo(&score_entries);
5434 // add top tree node to create back link to main menu
5435 score_entries = addTopTreeInfoNode(score_entries);
5437 // set current score entry to last added or highest score entry
5438 score_entry_current =
5439 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5441 // if that fails, set current score entry to first valid score entry
5442 if (score_entry_current == NULL)
5443 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5445 if (score_entries != NULL && scores.continue_playing)
5446 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5449 void DrawHallOfFame(int nr)
5451 scores.last_level_nr = nr;
5453 // (this is needed when called from GameEnd() after winning a game)
5454 KeyboardAutoRepeatOn();
5456 // (this is needed when called from GameEnd() after winning a game)
5457 SetDrawDeactivationMask(REDRAW_NONE);
5458 SetDrawBackgroundMask(REDRAW_FIELD);
5460 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5462 DrawHallOfFame_setScoreEntries();
5464 if (scores.last_added >= 0)
5465 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5467 FadeSetEnterScreen();
5469 DrawChooseTree(&score_entry_current);
5472 static char *getHallOfFameRankText(int nr, int size)
5474 static char rank_text[10];
5475 boolean forced = (scores.force_last_added && nr == scores.last_added);
5476 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5478 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5483 static char *getHallOfFameTimeText(int nr)
5485 static char score_text[10];
5486 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5487 int mm = (time_seconds / 60) % 60;
5488 int ss = (time_seconds % 60);
5490 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5495 static char *getHallOfFameScoreText(int nr, int size)
5497 if (!level.rate_time_over_score)
5498 return int2str(scores.entry[nr].score, size); // show normal score
5499 else if (level.use_step_counter)
5500 return int2str(scores.entry[nr].time, size); // show number of steps
5502 return getHallOfFameTimeText(nr); // show playing time
5505 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5507 static char tape_date[MAX_ISO_DATE_LEN + 1];
5510 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5511 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5512 return entry->tape_date;
5514 for (i = 0, j = 0; i < 8; i++, j++)
5516 tape_date[j] = entry->tape_basename[i];
5518 if (i == 3 || i == 5)
5519 tape_date[++j] = '-';
5522 tape_date[MAX_ISO_DATE_LEN] = '\0';
5527 static void HandleHallOfFame_SelectLevel(int step, int direction)
5529 int old_level_nr = scores.last_level_nr;
5530 int new_level_nr = old_level_nr + step * direction;
5532 if (new_level_nr < leveldir_current->first_level)
5533 new_level_nr = leveldir_current->first_level;
5534 if (new_level_nr > leveldir_current->last_level)
5535 new_level_nr = leveldir_current->last_level;
5537 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5538 new_level_nr = leveldir_current->handicap_level;
5540 if (new_level_nr != old_level_nr)
5542 PlaySound(SND_MENU_ITEM_SELECTING);
5544 scores.last_level_nr = level_nr = new_level_nr;
5545 scores.last_entry_nr = 0;
5547 LoadLevel(level_nr);
5548 LoadLocalAndServerScore(level_nr, TRUE);
5550 DrawHallOfFame_setScoreEntries();
5552 if (game_status == GAME_MODE_SCORES)
5554 // force remapping optional gadgets (especially scroll bar)
5555 UnmapScreenTreeGadgets();
5557 // redraw complete high score screen, as sub-title has changed
5560 // redraw level selection buttons (which have just been erased)
5561 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5563 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5567 DrawScoreInfo_Content(scores.last_entry_nr);
5570 SaveLevelSetup_SeriesInfo();
5574 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5576 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5579 static void DrawScoreInfo_Content(int entry_nr)
5581 struct ScoreEntry *entry = &scores.entry[entry_nr];
5582 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5583 char *tape_date = getHallOfFameTapeDateText(entry);
5584 int font_head = MENU_INFO_FONT_HEAD;
5585 int font_text = MENU_INFO_FONT_TEXT;
5586 int font_foot = MENU_INFO_FONT_FOOT;
5587 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5588 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5589 int spacing_left = menu.left_spacing[GAME_MODE_SCOREINFO];
5590 int spacing_top = menu.top_spacing[GAME_MODE_SCOREINFO];
5591 int xstep = getFontWidth(font_text);
5592 int ystep_para = getMenuTextStep(spacing_para, font_text);
5593 int ystep_line = getMenuTextStep(spacing_line, font_text);
5594 int xstart = mSX - SX + spacing_left;
5595 int ystart = mSY - SY + spacing_top + getHeadlineSpacing();
5596 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5597 int xstart1 = xstart + xstep;
5598 int xstart2 = xstart + xstep * 12;
5599 int select_x = SX + xstart1;
5600 int select_y1, select_y2;
5602 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5603 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5604 int font_width = getFontWidth(font_text);
5605 int font_height = getFontHeight(font_text);
5606 int tape_date_width = getTextWidth(tape_date, font_text);
5607 int pad_left = xstart2;
5608 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5609 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5610 int max_lines_per_text = 5;
5615 // redraw level selection buttons (which have just been erased)
5616 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5618 drawChooseTreeHead(score_entries);
5619 drawChooseTreeInfo(score_entries);
5621 DrawTextF(xstart1, ystart, font_head, "Level Set");
5622 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5623 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5624 TRUE, FALSE, FALSE);
5625 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5627 DrawTextF(xstart1, ystart, font_head, "Level");
5628 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5629 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5630 TRUE, FALSE, FALSE);
5631 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5633 select_y1 = SY + ystart;
5634 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5636 DrawTextF(xstart1, ystart, font_head, "Rank");
5637 DrawTextF(xstart2, ystart, font_text, pos_text);
5638 ystart += ystep_line;
5640 DrawTextF(xstart1, ystart, font_head, "Player");
5641 DrawTextF(xstart2, ystart, font_text, entry->name);
5642 ystart += ystep_line;
5644 if (level.use_step_counter)
5646 DrawTextF(xstart1, ystart, font_head, "Steps");
5647 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5648 ystart += ystep_line;
5652 DrawTextF(xstart1, ystart, font_head, "Time");
5653 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5654 ystart += ystep_line;
5657 if (!level.rate_time_over_score || entry->score > 0)
5659 DrawTextF(xstart1, ystart, font_head, "Score");
5660 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5661 ystart += ystep_line;
5664 ystart += ystep_line;
5666 play_x = SX + xstart2 + tape_date_width + font_width;
5667 play_y = SY + ystart + (font_height - play_height) / 2;
5669 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5670 DrawTextF(xstart2, ystart, font_text, tape_date);
5671 ystart += ystep_line;
5673 DrawTextF(xstart1, ystart, font_head, "Platform");
5674 DrawTextF(xstart2, ystart, font_text, entry->platform);
5675 ystart += ystep_line;
5677 DrawTextF(xstart1, ystart, font_head, "Version");
5678 DrawTextF(xstart2, ystart, font_text, entry->version);
5679 ystart += ystep_line;
5681 DrawTextF(xstart1, ystart, font_head, "Country");
5682 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5683 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5684 TRUE, FALSE, FALSE);
5685 ystart += ystep_line;
5687 select_y2 = SY + ystart;
5689 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5691 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5692 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5695 static void DrawScoreInfo(int entry_nr)
5697 scores.last_entry_nr = entry_nr;
5698 score_info_tape_play = FALSE;
5702 FreeScreenGadgets();
5703 CreateScreenGadgets();
5705 FadeOut(REDRAW_FIELD);
5707 // needed if different viewport properties defined after playing score tape
5708 ChangeViewportPropertiesIfNeeded();
5710 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5711 SetDrawDeactivationMask(REDRAW_NONE);
5712 SetDrawBackgroundMask(REDRAW_FIELD);
5714 // needed if different background image defined after playing score tape
5715 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5716 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5718 // special compatibility handling for "Snake Bite" graphics set
5719 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5720 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5721 gfx.full_sxsize, gfx.full_sysize - 64);
5723 DrawScoreInfo_Content(entry_nr);
5725 // map gadgets for score info screen
5726 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5728 FadeIn(REDRAW_FIELD);
5731 static void HandleScoreInfo_SelectScore(int step, int direction)
5733 int old_entry_nr = scores.last_entry_nr;
5734 int new_entry_nr = old_entry_nr + step * direction;
5735 int num_nodes = numTreeInfoInGroup(score_entry_current);
5736 int num_entries = num_nodes - 1; // score nodes only, without back link
5738 if (new_entry_nr < 0)
5740 if (new_entry_nr > num_entries - 1)
5741 new_entry_nr = num_entries - 1;
5743 if (new_entry_nr != old_entry_nr)
5745 scores.last_entry_nr = new_entry_nr;
5747 DrawScoreInfo_Content(new_entry_nr);
5751 static void HandleScoreInfo_PlayTape(void)
5753 if (!PlayScoreTape(scores.last_entry_nr))
5755 DrawScoreInfo_Content(scores.last_entry_nr);
5757 FadeIn(REDRAW_FIELD);
5761 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5763 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5764 boolean button_is_valid = (mx >= 0 && my >= 0);
5765 boolean button_screen_clicked = (button_action && button_is_valid);
5767 if (server_scores.updated)
5769 // reload scores, using updated server score cache file
5770 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5772 server_scores.updated = FALSE;
5774 DrawHallOfFame_setScoreEntries();
5776 DrawScoreInfo_Content(scores.last_entry_nr);
5779 if (button_screen_clicked)
5781 PlaySound(SND_MENU_ITEM_SELECTING);
5783 SetGameStatus(GAME_MODE_SCORES);
5785 DrawHallOfFame(scores.last_level_nr);
5789 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5793 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5798 // ============================================================================
5799 // setup screen functions
5800 // ============================================================================
5802 static struct TokenInfo *setup_info;
5803 static int num_setup_info; // number of setup entries shown on screen
5804 static int max_setup_info; // total number of setup entries in list
5806 static char *window_size_text;
5807 static char *scaling_type_text;
5808 static char *rendering_mode_text;
5809 static char *vsync_mode_text;
5810 static char *scroll_delay_text;
5811 static char *snapshot_mode_text;
5812 static char *game_speed_text;
5813 static char *scores_type_text;
5814 static char *network_server_text;
5815 static char *graphics_set_name;
5816 static char *sounds_set_name;
5817 static char *music_set_name;
5818 static char *volume_simple_text;
5819 static char *volume_loops_text;
5820 static char *volume_music_text;
5821 static char *touch_controls_text;
5822 static char *move_distance_text;
5823 static char *drop_distance_text;
5824 static char *transparency_text;
5825 static char *grid_size_text[2][2];
5827 static void execSetupMain(void)
5829 setup_mode = SETUP_MODE_MAIN;
5834 static void execSetupGame_setScoresType(void)
5836 if (scores_types == NULL)
5840 for (i = 0; scores_types_list[i].value != NULL; i++)
5842 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5843 char identifier[32], name[32];
5844 char *value = scores_types_list[i].value;
5845 char *text = scores_types_list[i].text;
5847 ti->node_top = &scores_types;
5848 ti->sort_priority = i;
5850 sprintf(identifier, "%s", value);
5851 sprintf(name, "%s", text);
5853 setString(&ti->identifier, identifier);
5854 setString(&ti->name, name);
5855 setString(&ti->name_sorting, name);
5856 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5858 pushTreeInfo(&scores_types, ti);
5861 // sort scores type values to start with lowest scores type value
5862 sortTreeInfo(&scores_types);
5864 // set current scores type value to configured scores type value
5865 scores_type_current =
5866 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5868 // if that fails, set current scores type to reliable default value
5869 if (scores_type_current == NULL)
5870 scores_type_current =
5871 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5873 // if that also fails, set current scores type to first available value
5874 if (scores_type_current == NULL)
5875 scores_type_current = scores_types;
5878 setup.scores_in_highscore_list = scores_type_current->identifier;
5880 // needed for displaying scores type text instead of identifier
5881 scores_type_text = scores_type_current->name;
5884 static void execSetupGame_setGameSpeeds(boolean update_value)
5886 if (setup.game_speed_extended)
5888 game_speeds_list = game_speeds_list_extended;
5889 game_speeds = game_speeds_extended;
5893 game_speeds_list = game_speeds_list_normal;
5894 game_speeds = game_speeds_normal;
5897 if (game_speeds == NULL)
5901 for (i = 0; game_speeds_list[i].value != -1; i++)
5903 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5904 char identifier[32], name[32];
5905 int value = game_speeds_list[i].value;
5906 char *text = game_speeds_list[i].text;
5908 ti->node_top = &game_speeds;
5909 ti->sort_priority = 10000 - value;
5911 sprintf(identifier, "%d", value);
5912 sprintf(name, "%s", text);
5914 setString(&ti->identifier, identifier);
5915 setString(&ti->name, name);
5916 setString(&ti->name_sorting, name);
5917 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5919 pushTreeInfo(&game_speeds, ti);
5922 // sort game speed values to start with slowest game speed
5923 sortTreeInfo(&game_speeds);
5925 update_value = TRUE;
5930 // set current game speed to configured game speed value
5931 game_speed_current =
5932 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5934 // if that fails, set current game speed to reliable default value
5935 if (game_speed_current == NULL)
5936 game_speed_current =
5937 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5939 // if that also fails, set current game speed to first available speed
5940 if (game_speed_current == NULL)
5941 game_speed_current = game_speeds;
5943 if (setup.game_speed_extended)
5944 game_speeds_extended = game_speeds;
5946 game_speeds_normal = game_speeds;
5949 setup.game_frame_delay = atoi(game_speed_current->identifier);
5951 // needed for displaying game speed text instead of identifier
5952 game_speed_text = game_speed_current->name;
5955 static void execSetupGame_setScrollDelays(void)
5957 if (scroll_delays == NULL)
5961 for (i = 0; scroll_delays_list[i].value != -1; i++)
5963 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5964 char identifier[32], name[32];
5965 int value = scroll_delays_list[i].value;
5966 char *text = scroll_delays_list[i].text;
5968 ti->node_top = &scroll_delays;
5969 ti->sort_priority = value;
5971 sprintf(identifier, "%d", value);
5972 sprintf(name, "%s", text);
5974 setString(&ti->identifier, identifier);
5975 setString(&ti->name, name);
5976 setString(&ti->name_sorting, name);
5977 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5979 pushTreeInfo(&scroll_delays, ti);
5982 // sort scroll delay values to start with lowest scroll delay value
5983 sortTreeInfo(&scroll_delays);
5985 // set current scroll delay value to configured scroll delay value
5986 scroll_delay_current =
5987 getTreeInfoFromIdentifier(scroll_delays, i_to_a(setup.scroll_delay_value));
5989 // if that fails, set current scroll delay to reliable default value
5990 if (scroll_delay_current == NULL)
5991 scroll_delay_current =
5992 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5994 // if that also fails, set current scroll delay to first available value
5995 if (scroll_delay_current == NULL)
5996 scroll_delay_current = scroll_delays;
5999 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
6001 // needed for displaying scroll delay text instead of identifier
6002 scroll_delay_text = scroll_delay_current->name;
6005 static void execSetupGame_setSnapshotModes(void)
6007 if (snapshot_modes == NULL)
6011 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
6013 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6014 char identifier[32], name[32];
6015 char *value = snapshot_modes_list[i].value;
6016 char *text = snapshot_modes_list[i].text;
6018 ti->node_top = &snapshot_modes;
6019 ti->sort_priority = i;
6021 sprintf(identifier, "%s", value);
6022 sprintf(name, "%s", text);
6024 setString(&ti->identifier, identifier);
6025 setString(&ti->name, name);
6026 setString(&ti->name_sorting, name);
6027 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
6029 pushTreeInfo(&snapshot_modes, ti);
6032 // sort snapshot mode values to start with lowest snapshot mode value
6033 sortTreeInfo(&snapshot_modes);
6035 // set current snapshot mode value to configured snapshot mode value
6036 snapshot_mode_current =
6037 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
6039 // if that fails, set current snapshot mode to reliable default value
6040 if (snapshot_mode_current == NULL)
6041 snapshot_mode_current =
6042 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
6044 // if that also fails, set current snapshot mode to first available value
6045 if (snapshot_mode_current == NULL)
6046 snapshot_mode_current = snapshot_modes;
6049 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
6051 // needed for displaying snapshot mode text instead of identifier
6052 snapshot_mode_text = snapshot_mode_current->name;
6055 static void execSetupGame_setNetworkServerText(void)
6057 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
6059 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
6063 strncpy(network_server_hostname, setup.network_server_hostname,
6064 MAX_SETUP_TEXT_INPUT_LEN);
6065 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
6068 // needed for displaying network server text instead of identifier
6069 network_server_text = network_server_hostname;
6072 static void execSetupGame(void)
6074 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
6076 execSetupGame_setGameSpeeds(FALSE);
6077 execSetupGame_setScoresType();
6078 execSetupGame_setScrollDelays();
6079 execSetupGame_setSnapshotModes();
6081 execSetupGame_setNetworkServerText();
6083 if (!setup.provide_uploading_tapes)
6084 setHideSetupEntry(execOfferUploadTapes);
6086 setup_mode = SETUP_MODE_GAME;
6090 // check if vsync needs to be disabled for this game speed to work
6091 if (check_vsync_mode)
6092 DisableVsyncIfNeeded();
6095 static void execSetupChooseScoresType(void)
6097 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6102 static void execSetupChooseGameSpeed(void)
6104 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6109 static void execSetupChooseScrollDelay(void)
6111 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6116 static void execSetupChooseSnapshotMode(void)
6118 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6123 static void execSetupEngines(void)
6125 setup_mode = SETUP_MODE_ENGINES;
6130 static void execSetupEditor(void)
6132 setup_mode = SETUP_MODE_EDITOR;
6137 static void execSetupGraphics_setWindowSizes(boolean update_list)
6139 if (window_sizes != NULL && update_list)
6141 freeTreeInfo(window_sizes);
6143 window_sizes = NULL;
6146 if (window_sizes == NULL)
6148 boolean current_window_size_found = FALSE;
6151 for (i = 0; window_sizes_list[i].value != -1; i++)
6153 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6154 char identifier[32], name[32];
6155 int value = window_sizes_list[i].value;
6156 char *text = window_sizes_list[i].text;
6158 ti->node_top = &window_sizes;
6159 ti->sort_priority = value;
6161 sprintf(identifier, "%d", value);
6162 sprintf(name, "%s", text);
6164 setString(&ti->identifier, identifier);
6165 setString(&ti->name, name);
6166 setString(&ti->name_sorting, name);
6167 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6169 pushTreeInfo(&window_sizes, ti);
6171 if (value == setup.window_scaling_percent)
6172 current_window_size_found = TRUE;
6175 if (!current_window_size_found)
6177 // add entry for non-preset window scaling value
6179 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6180 char identifier[32], name[32];
6181 int value = setup.window_scaling_percent;
6183 ti->node_top = &window_sizes;
6184 ti->sort_priority = value;
6186 sprintf(identifier, "%d", value);
6187 sprintf(name, "%d %% (Current)", value);
6189 setString(&ti->identifier, identifier);
6190 setString(&ti->name, name);
6191 setString(&ti->name_sorting, name);
6192 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6194 pushTreeInfo(&window_sizes, ti);
6197 // sort window size values to start with lowest window size value
6198 sortTreeInfo(&window_sizes);
6200 // set current window size value to configured window size value
6201 window_size_current =
6202 getTreeInfoFromIdentifier(window_sizes,
6203 i_to_a(setup.window_scaling_percent));
6205 // if that fails, set current window size to reliable default value
6206 if (window_size_current == NULL)
6207 window_size_current =
6208 getTreeInfoFromIdentifier(window_sizes,
6209 i_to_a(STD_WINDOW_SCALING_PERCENT));
6211 // if that also fails, set current window size to first available value
6212 if (window_size_current == NULL)
6213 window_size_current = window_sizes;
6216 setup.window_scaling_percent = atoi(window_size_current->identifier);
6218 // needed for displaying window size text instead of identifier
6219 window_size_text = window_size_current->name;
6222 static void execSetupGraphics_setScalingTypes(void)
6224 if (scaling_types == NULL)
6228 for (i = 0; scaling_types_list[i].value != NULL; i++)
6230 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6231 char identifier[32], name[32];
6232 char *value = scaling_types_list[i].value;
6233 char *text = scaling_types_list[i].text;
6235 ti->node_top = &scaling_types;
6236 ti->sort_priority = i;
6238 sprintf(identifier, "%s", value);
6239 sprintf(name, "%s", text);
6241 setString(&ti->identifier, identifier);
6242 setString(&ti->name, name);
6243 setString(&ti->name_sorting, name);
6244 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6246 pushTreeInfo(&scaling_types, ti);
6249 // sort scaling type values to start with lowest scaling type value
6250 sortTreeInfo(&scaling_types);
6252 // set current scaling type value to configured scaling type value
6253 scaling_type_current =
6254 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6256 // if that fails, set current scaling type to reliable default value
6257 if (scaling_type_current == NULL)
6258 scaling_type_current =
6259 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6261 // if that also fails, set current scaling type to first available value
6262 if (scaling_type_current == NULL)
6263 scaling_type_current = scaling_types;
6266 setup.window_scaling_quality = scaling_type_current->identifier;
6268 // needed for displaying scaling type text instead of identifier
6269 scaling_type_text = scaling_type_current->name;
6272 static void execSetupGraphics_setRenderingModes(void)
6274 if (rendering_modes == NULL)
6278 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6280 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6281 char identifier[32], name[32];
6282 char *value = rendering_modes_list[i].value;
6283 char *text = rendering_modes_list[i].text;
6285 ti->node_top = &rendering_modes;
6286 ti->sort_priority = i;
6288 sprintf(identifier, "%s", value);
6289 sprintf(name, "%s", text);
6291 setString(&ti->identifier, identifier);
6292 setString(&ti->name, name);
6293 setString(&ti->name_sorting, name);
6294 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6296 pushTreeInfo(&rendering_modes, ti);
6299 // sort rendering mode values to start with lowest rendering mode value
6300 sortTreeInfo(&rendering_modes);
6302 // set current rendering mode value to configured rendering mode value
6303 rendering_mode_current =
6304 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6306 // if that fails, set current rendering mode to reliable default value
6307 if (rendering_mode_current == NULL)
6308 rendering_mode_current =
6309 getTreeInfoFromIdentifier(rendering_modes,
6310 STR_SPECIAL_RENDERING_DEFAULT);
6312 // if that also fails, set current rendering mode to first available one
6313 if (rendering_mode_current == NULL)
6314 rendering_mode_current = rendering_modes;
6317 setup.screen_rendering_mode = rendering_mode_current->identifier;
6319 // needed for displaying rendering mode text instead of identifier
6320 rendering_mode_text = rendering_mode_current->name;
6323 static void execSetupGraphics_setVsyncModes(boolean update_value)
6325 if (vsync_modes == NULL)
6329 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6331 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6332 char identifier[32], name[32];
6333 char *value = vsync_modes_list[i].value;
6334 char *text = vsync_modes_list[i].text;
6336 ti->node_top = &vsync_modes;
6337 ti->sort_priority = i;
6339 sprintf(identifier, "%s", value);
6340 sprintf(name, "%s", text);
6342 setString(&ti->identifier, identifier);
6343 setString(&ti->name, name);
6344 setString(&ti->name_sorting, name);
6345 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6347 pushTreeInfo(&vsync_modes, ti);
6350 // sort vsync mode values to start with lowest vsync mode value
6351 sortTreeInfo(&vsync_modes);
6353 update_value = TRUE;
6358 // set current vsync mode value to configured vsync mode value
6359 vsync_mode_current =
6360 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6362 // if that fails, set current vsync mode to reliable default value
6363 if (vsync_mode_current == NULL)
6364 vsync_mode_current =
6365 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6367 // if that also fails, set current vsync mode to first available one
6368 if (vsync_mode_current == NULL)
6369 vsync_mode_current = vsync_modes;
6372 setup.vsync_mode = vsync_mode_current->identifier;
6374 // needed for displaying vsync mode text instead of identifier
6375 vsync_mode_text = vsync_mode_current->name;
6378 static void execSetupGraphics(void)
6380 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6382 // update "setup.window_scaling_percent" from list selection
6383 // (in this case, window scaling was changed on setup screen)
6384 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6385 execSetupGraphics_setWindowSizes(FALSE);
6387 // update "setup.vsync_mode" from list selection
6388 // (in this case, vsync mode was changed on setup screen)
6389 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6390 execSetupGraphics_setVsyncModes(FALSE);
6392 // update list selection from "setup.window_scaling_percent"
6393 // (window scaling may have changed by resizing the window)
6394 execSetupGraphics_setWindowSizes(TRUE);
6396 // update list selection from "setup.vsync_mode"
6397 // (vsync_mode may have changed by re-creating the renderer)
6398 execSetupGraphics_setVsyncModes(TRUE);
6400 execSetupGraphics_setScalingTypes();
6401 execSetupGraphics_setRenderingModes();
6403 setup_mode = SETUP_MODE_GRAPHICS;
6407 // check if game speed is high enough for 60 Hz vsync to work
6408 if (check_game_speed)
6409 ModifyGameSpeedIfNeeded();
6411 // window scaling may have changed at this point
6412 ChangeWindowScalingIfNeeded();
6414 // window scaling quality may have changed at this point
6415 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6416 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6418 // screen rendering mode may have changed at this point
6419 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6421 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6422 int video_vsync_mode = video.vsync_mode;
6424 // screen vsync mode may have changed at this point
6425 ChangeVsyncModeIfNeeded();
6427 // check if setting vsync mode to selected value failed
6428 if (setup_vsync_mode != video_vsync_mode &&
6429 setup_vsync_mode != video.vsync_mode)
6431 // changing vsync mode to selected value failed -- reset displayed value
6432 execSetupGraphics_setVsyncModes(TRUE);
6434 Request("Setting VSync failed!", REQ_CONFIRM);
6440 static void execSetupChooseWindowSize(void)
6442 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6447 static void execSetupChooseScalingType(void)
6449 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6454 static void execSetupChooseRenderingMode(void)
6456 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6461 static void execSetupChooseVsyncMode(void)
6463 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6468 static void execSetupChooseVolumeSimple(void)
6470 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6475 static void execSetupChooseVolumeLoops(void)
6477 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6482 static void execSetupChooseVolumeMusic(void)
6484 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6489 static void execSetupSound(void)
6491 if (volumes_simple == NULL)
6493 boolean current_volume_simple_found = FALSE;
6496 for (i = 0; volumes_list[i].value != -1; i++)
6498 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6499 char identifier[32], name[32];
6500 int value = volumes_list[i].value;
6501 char *text = volumes_list[i].text;
6503 ti->node_top = &volumes_simple;
6504 ti->sort_priority = value;
6506 sprintf(identifier, "%d", value);
6507 sprintf(name, "%s", text);
6509 setString(&ti->identifier, identifier);
6510 setString(&ti->name, name);
6511 setString(&ti->name_sorting, name);
6512 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6514 pushTreeInfo(&volumes_simple, ti);
6516 if (value == setup.volume_simple)
6517 current_volume_simple_found = TRUE;
6520 if (!current_volume_simple_found)
6522 // add entry for non-preset volume value
6524 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6525 char identifier[32], name[32];
6526 int value = setup.volume_simple;
6528 ti->node_top = &volumes_simple;
6529 ti->sort_priority = value;
6531 sprintf(identifier, "%d", value);
6532 sprintf(name, "%d %% (Current)", value);
6534 setString(&ti->identifier, identifier);
6535 setString(&ti->name, name);
6536 setString(&ti->name_sorting, name);
6537 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6539 pushTreeInfo(&volumes_simple, ti);
6542 // sort volume values to start with lowest volume value
6543 sortTreeInfo(&volumes_simple);
6545 // set current volume value to configured volume value
6546 volume_simple_current =
6547 getTreeInfoFromIdentifier(volumes_simple, i_to_a(setup.volume_simple));
6549 // if that fails, set current volume to reliable default value
6550 if (volume_simple_current == NULL)
6551 volume_simple_current =
6552 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6554 // if that also fails, set current volume to first available value
6555 if (volume_simple_current == NULL)
6556 volume_simple_current = volumes_simple;
6559 if (volumes_loops == NULL)
6561 boolean current_volume_loops_found = FALSE;
6564 for (i = 0; volumes_list[i].value != -1; i++)
6566 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6567 char identifier[32], name[32];
6568 int value = volumes_list[i].value;
6569 char *text = volumes_list[i].text;
6571 ti->node_top = &volumes_loops;
6572 ti->sort_priority = value;
6574 sprintf(identifier, "%d", value);
6575 sprintf(name, "%s", text);
6577 setString(&ti->identifier, identifier);
6578 setString(&ti->name, name);
6579 setString(&ti->name_sorting, name);
6580 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6582 pushTreeInfo(&volumes_loops, ti);
6584 if (value == setup.volume_loops)
6585 current_volume_loops_found = TRUE;
6588 if (!current_volume_loops_found)
6590 // add entry for non-preset volume value
6592 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6593 char identifier[32], name[32];
6594 int value = setup.volume_loops;
6596 ti->node_top = &volumes_loops;
6597 ti->sort_priority = value;
6599 sprintf(identifier, "%d", value);
6600 sprintf(name, "%d %% (Current)", value);
6602 setString(&ti->identifier, identifier);
6603 setString(&ti->name, name);
6604 setString(&ti->name_sorting, name);
6605 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6607 pushTreeInfo(&volumes_loops, ti);
6610 // sort volume values to start with lowest volume value
6611 sortTreeInfo(&volumes_loops);
6613 // set current volume value to configured volume value
6614 volume_loops_current =
6615 getTreeInfoFromIdentifier(volumes_loops, i_to_a(setup.volume_loops));
6617 // if that fails, set current volume to reliable default value
6618 if (volume_loops_current == NULL)
6619 volume_loops_current =
6620 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6622 // if that also fails, set current volume to first available value
6623 if (volume_loops_current == NULL)
6624 volume_loops_current = volumes_loops;
6627 if (volumes_music == NULL)
6629 boolean current_volume_music_found = FALSE;
6632 for (i = 0; volumes_list[i].value != -1; i++)
6634 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6635 char identifier[32], name[32];
6636 int value = volumes_list[i].value;
6637 char *text = volumes_list[i].text;
6639 ti->node_top = &volumes_music;
6640 ti->sort_priority = value;
6642 sprintf(identifier, "%d", value);
6643 sprintf(name, "%s", text);
6645 setString(&ti->identifier, identifier);
6646 setString(&ti->name, name);
6647 setString(&ti->name_sorting, name);
6648 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6650 pushTreeInfo(&volumes_music, ti);
6652 if (value == setup.volume_music)
6653 current_volume_music_found = TRUE;
6656 if (!current_volume_music_found)
6658 // add entry for non-preset volume value
6660 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6661 char identifier[32], name[32];
6662 int value = setup.volume_music;
6664 ti->node_top = &volumes_music;
6665 ti->sort_priority = value;
6667 sprintf(identifier, "%d", value);
6668 sprintf(name, "%d %% (Current)", value);
6670 setString(&ti->identifier, identifier);
6671 setString(&ti->name, name);
6672 setString(&ti->name_sorting, name);
6673 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6675 pushTreeInfo(&volumes_music, ti);
6678 // sort volume values to start with lowest volume value
6679 sortTreeInfo(&volumes_music);
6681 // set current volume value to configured volume value
6682 volume_music_current =
6683 getTreeInfoFromIdentifier(volumes_music, i_to_a(setup.volume_music));
6685 // if that fails, set current volume to reliable default value
6686 if (volume_music_current == NULL)
6687 volume_music_current =
6688 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6690 // if that also fails, set current volume to first available value
6691 if (volume_music_current == NULL)
6692 volume_music_current = volumes_music;
6695 setup.volume_simple = atoi(volume_simple_current->identifier);
6696 setup.volume_loops = atoi(volume_loops_current->identifier);
6697 setup.volume_music = atoi(volume_music_current->identifier);
6699 // needed for displaying volume text instead of identifier
6700 volume_simple_text = volume_simple_current->name;
6701 volume_loops_text = volume_loops_current->name;
6702 volume_music_text = volume_music_current->name;
6704 setup_mode = SETUP_MODE_SOUND;
6709 static void execSetupChooseTouchControls(void)
6711 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6716 static void execSetupChooseMoveDistance(void)
6718 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6723 static void execSetupChooseDropDistance(void)
6725 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6730 static void execSetupChooseTransparency(void)
6732 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6737 static void execSetupChooseGridXSize_0(void)
6739 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6744 static void execSetupChooseGridYSize_0(void)
6746 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6751 static void execSetupChooseGridXSize_1(void)
6753 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6758 static void execSetupChooseGridYSize_1(void)
6760 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6765 static void execSetupConfigureVirtualButtons(void)
6767 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6769 ConfigureVirtualButtons();
6771 setup_mode = SETUP_MODE_TOUCH;
6776 static void execSetupTouch(void)
6780 if (touch_controls == NULL)
6782 for (i = 0; touch_controls_list[i].value != NULL; i++)
6784 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6785 char identifier[32], name[32];
6786 char *value = touch_controls_list[i].value;
6787 char *text = touch_controls_list[i].text;
6789 ti->node_top = &touch_controls;
6790 ti->sort_priority = i;
6792 sprintf(identifier, "%s", value);
6793 sprintf(name, "%s", text);
6795 setString(&ti->identifier, identifier);
6796 setString(&ti->name, name);
6797 setString(&ti->name_sorting, name);
6798 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6800 pushTreeInfo(&touch_controls, ti);
6803 // sort touch control values to start with lowest touch control value
6804 sortTreeInfo(&touch_controls);
6806 // set current touch control value to configured touch control value
6807 touch_control_current =
6808 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6810 // if that fails, set current touch control to reliable default value
6811 if (touch_control_current == NULL)
6812 touch_control_current =
6813 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6815 // if that also fails, set current touch control to first available value
6816 if (touch_control_current == NULL)
6817 touch_control_current = touch_controls;
6820 if (move_distances == NULL)
6822 for (i = 0; distances_list[i].value != -1; i++)
6824 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6825 char identifier[32], name[32];
6826 int value = distances_list[i].value;
6827 char *text = distances_list[i].text;
6829 ti->node_top = &move_distances;
6830 ti->sort_priority = value;
6832 sprintf(identifier, "%d", value);
6833 sprintf(name, "%s", text);
6835 setString(&ti->identifier, identifier);
6836 setString(&ti->name, name);
6837 setString(&ti->name_sorting, name);
6838 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6840 pushTreeInfo(&move_distances, ti);
6843 // sort distance values to start with lowest distance value
6844 sortTreeInfo(&move_distances);
6846 // set current distance value to configured distance value
6847 move_distance_current =
6848 getTreeInfoFromIdentifier(move_distances,
6849 i_to_a(setup.touch.move_distance));
6851 // if that fails, set current distance to reliable default value
6852 if (move_distance_current == NULL)
6853 move_distance_current =
6854 getTreeInfoFromIdentifier(move_distances,
6855 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6857 // if that also fails, set current distance to first available value
6858 if (move_distance_current == NULL)
6859 move_distance_current = move_distances;
6862 if (drop_distances == NULL)
6864 for (i = 0; distances_list[i].value != -1; i++)
6866 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6867 char identifier[32], name[32];
6868 int value = distances_list[i].value;
6869 char *text = distances_list[i].text;
6871 ti->node_top = &drop_distances;
6872 ti->sort_priority = value;
6874 sprintf(identifier, "%d", value);
6875 sprintf(name, "%s", text);
6877 setString(&ti->identifier, identifier);
6878 setString(&ti->name, name);
6879 setString(&ti->name_sorting, name);
6880 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6882 pushTreeInfo(&drop_distances, ti);
6885 // sort distance values to start with lowest distance value
6886 sortTreeInfo(&drop_distances);
6888 // set current distance value to configured distance value
6889 drop_distance_current =
6890 getTreeInfoFromIdentifier(drop_distances,
6891 i_to_a(setup.touch.drop_distance));
6893 // if that fails, set current distance to reliable default value
6894 if (drop_distance_current == NULL)
6895 drop_distance_current =
6896 getTreeInfoFromIdentifier(drop_distances,
6897 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6899 // if that also fails, set current distance to first available value
6900 if (drop_distance_current == NULL)
6901 drop_distance_current = drop_distances;
6904 if (transparencies == NULL)
6906 for (i = 0; transparencies_list[i].value != -1; i++)
6908 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6909 char identifier[32], name[32];
6910 int value = transparencies_list[i].value;
6911 char *text = transparencies_list[i].text;
6913 ti->node_top = &transparencies;
6914 ti->sort_priority = value;
6916 sprintf(identifier, "%d", value);
6917 sprintf(name, "%s", text);
6919 setString(&ti->identifier, identifier);
6920 setString(&ti->name, name);
6921 setString(&ti->name_sorting, name);
6922 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6924 pushTreeInfo(&transparencies, ti);
6927 // sort transparency values to start with lowest transparency value
6928 sortTreeInfo(&transparencies);
6930 // set current transparency value to configured transparency value
6931 transparency_current =
6932 getTreeInfoFromIdentifier(transparencies,
6933 i_to_a(setup.touch.transparency));
6935 // if that fails, set current transparency to reliable default value
6936 if (transparency_current == NULL)
6937 transparency_current =
6938 getTreeInfoFromIdentifier(transparencies,
6939 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6941 // if that also fails, set current transparency to first available value
6942 if (transparency_current == NULL)
6943 transparency_current = transparencies;
6946 for (i = 0; i < 2; i++)
6948 for (j = 0; j < 2; j++)
6950 if (grid_sizes[i][j] == NULL)
6952 for (k = 0; grid_sizes_list[k].value != -1; k++)
6954 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6955 char identifier[32], name[32];
6956 int value = grid_sizes_list[k].value;
6957 char *text = grid_sizes_list[k].text;
6959 ti->node_top = &grid_sizes[i][j];
6960 ti->sort_priority = value;
6962 sprintf(identifier, "%d", value);
6963 sprintf(name, "%s", text);
6965 setString(&ti->identifier, identifier);
6966 setString(&ti->name, name);
6967 setString(&ti->name_sorting, name);
6968 setString(&ti->infotext,
6971 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6972 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6974 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6975 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6977 pushTreeInfo(&grid_sizes[i][j], ti);
6980 // sort grid size values to start with lowest grid size value
6981 sortTreeInfo(&grid_sizes[i][j]);
6983 // set current grid size value to configured grid size value
6984 grid_size_current[i][j] =
6985 getTreeInfoFromIdentifier(grid_sizes[i][j],
6987 setup.touch.grid_xsize[i] :
6988 setup.touch.grid_ysize[i]));
6990 // if that fails, set current grid size to reliable default value
6991 if (grid_size_current[i][j] == NULL)
6992 grid_size_current[i][j] =
6993 getTreeInfoFromIdentifier(grid_sizes[i][j],
6995 DEFAULT_GRID_XSIZE(i) :
6996 DEFAULT_GRID_YSIZE(i)));
6998 // if that also fails, set current grid size to first available value
6999 if (grid_size_current[i][j] == NULL)
7000 grid_size_current[i][j] = grid_sizes[i][j];
7005 setup.touch.control_type = touch_control_current->identifier;
7006 setup.touch.move_distance = atoi(move_distance_current->identifier);
7007 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
7008 setup.touch.transparency = atoi(transparency_current->identifier);
7010 for (i = 0; i < 2; i++)
7012 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
7013 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
7015 if (i == GRID_ACTIVE_NR())
7017 overlay.grid_xsize = setup.touch.grid_xsize[i];
7018 overlay.grid_ysize = setup.touch.grid_ysize[i];
7022 // needed for displaying value text instead of identifier
7023 touch_controls_text = touch_control_current->name;
7024 move_distance_text = move_distance_current->name;
7025 drop_distance_text = drop_distance_current->name;
7026 transparency_text = transparency_current->name;
7028 for (i = 0; i < 2; i++)
7029 for (j = 0; j < 2; j++)
7030 grid_size_text[i][j] = grid_size_current[i][j]->name;
7032 setup_mode = SETUP_MODE_TOUCH;
7037 static void execSetupArtwork(void)
7039 static ArtworkDirTree *gfx_last_valid = NULL;
7040 static ArtworkDirTree *snd_last_valid = NULL;
7041 static ArtworkDirTree *mus_last_valid = NULL;
7043 // current artwork directory may be invalid (level group, parent link)
7044 if (!validLevelSeries(artwork.gfx_current))
7045 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
7046 if (!validLevelSeries(artwork.snd_current))
7047 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
7048 if (!validLevelSeries(artwork.mus_current))
7049 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
7051 // store valid artwork directory information
7052 gfx_last_valid = artwork.gfx_current;
7053 snd_last_valid = artwork.snd_current;
7054 mus_last_valid = artwork.mus_current;
7057 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
7058 artwork.gfx_current->subdir,
7059 artwork.gfx_current->fullpath,
7060 artwork.gfx_current->basepath);
7063 setup.graphics_set = artwork.gfx_current->identifier;
7064 setup.sounds_set = artwork.snd_current->identifier;
7065 setup.music_set = artwork.mus_current->identifier;
7067 // needed if last screen (setup choice) changed graphics, sounds or music
7068 ReloadCustomArtwork(0);
7070 // needed for displaying artwork name instead of artwork identifier
7071 graphics_set_name = artwork.gfx_current->name;
7072 sounds_set_name = artwork.snd_current->name;
7073 music_set_name = artwork.mus_current->name;
7075 setup_mode = SETUP_MODE_ARTWORK;
7080 static void execSetupChooseGraphics(void)
7082 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7087 static void execSetupChooseSounds(void)
7089 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7094 static void execSetupChooseMusic(void)
7096 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7101 static void execSetupInput(void)
7103 setup_mode = SETUP_MODE_INPUT;
7108 static void execSetupShortcuts(void)
7110 setup_mode = SETUP_MODE_SHORTCUTS;
7115 static void execSetupShortcuts1(void)
7117 setup_mode = SETUP_MODE_SHORTCUTS_1;
7122 static void execSetupShortcuts2(void)
7124 setup_mode = SETUP_MODE_SHORTCUTS_2;
7129 static void execSetupShortcuts3(void)
7131 setup_mode = SETUP_MODE_SHORTCUTS_3;
7136 static void execSetupShortcuts4(void)
7138 setup_mode = SETUP_MODE_SHORTCUTS_4;
7143 static void execSetupShortcuts5(void)
7145 setup_mode = SETUP_MODE_SHORTCUTS_5;
7150 static void execExitSetup(void)
7152 SetGameStatus(GAME_MODE_MAIN);
7157 static void execSaveAndExitSetup(void)
7163 static void execGadgetNetworkServer(void)
7165 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7166 struct GadgetInfo *gi = screen_gadget[gadget_id];
7168 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7169 network_server_hostname[0] = '\0';
7171 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7175 ClickOnGadget(gi, MB_LEFTBUTTON);
7178 static void execOfferUploadTapes(void)
7183 static void ToggleNetworkModeIfNeeded(void)
7185 int font_title = FONT_TITLE_1;
7186 int font_foot = FC_BLUE;
7187 int ystart = mSY - SY + 16;
7188 int ybottom = mSY - SY + SYSIZE - 20;
7189 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7191 if (setup.network_mode == network.enabled)
7194 network.enabled = setup.network_mode;
7196 FadeOut(REDRAW_ALL);
7200 DrawTextSCentered(ystart, font_title, text);
7204 if (network.enabled)
7205 InitNetworkServer();
7207 DisconnectFromNetworkServer();
7209 DrawTextSCentered(ybottom, font_foot,
7210 "Press any key or button for setup menu");
7212 WaitForEventToContinue();
7217 static void ToggleGameSpeedsListIfNeeded(void)
7219 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7221 if (setup.game_speed_extended == using_game_speeds_extended)
7224 // try to match similar values when changing game speeds list
7225 if (setup.game_speed_extended)
7226 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7227 setup.game_frame_delay == 30 ? 29 :
7228 setup.game_frame_delay);
7230 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7231 setup.game_frame_delay == 16 ? 15 :
7232 setup.game_frame_delay >= 29 ? 30 :
7233 setup.game_frame_delay <= 10 ? 10 :
7234 setup.game_frame_delay);
7236 execSetupGame_setGameSpeeds(TRUE);
7241 static void ToggleUseApiServerIfNeeded(void)
7243 if (runtime.use_api_server == setup.use_api_server)
7246 runtime.use_api_server = setup.use_api_server;
7248 if (runtime.use_api_server)
7250 if (setup.has_remaining_tapes)
7251 setup.ask_for_uploading_tapes = TRUE;
7253 CheckApiServerTasks();
7257 static void ModifyGameSpeedIfNeeded(void)
7259 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7260 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7264 char *game_speed_text = "Fast";
7265 int game_speed_value = 15;
7267 if (setup.game_speed_extended)
7269 game_speed_text = "60 fps";
7270 game_speed_value = 16;
7273 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7275 // set game speed to existing list value that is fast enough for vsync
7276 setup.game_frame_delay = game_speed_value;
7278 execSetupGame_setGameSpeeds(TRUE);
7280 Request(message, REQ_CONFIRM);
7283 static void DisableVsyncIfNeeded(void)
7285 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7286 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7287 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7290 // disable vsync for the selected game speed to work
7291 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7293 execSetupGraphics_setVsyncModes(TRUE);
7295 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7301 void *related_value;
7302 } hide_related_entry_list[] =
7304 { &setup.network_server_hostname, execGadgetNetworkServer },
7305 { &setup.network_server_hostname, &network_server_text },
7307 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7308 { &setup.scores_in_highscore_list, &scores_type_text },
7310 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7311 { &setup.game_frame_delay, &game_speed_text },
7313 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7314 { &setup.scroll_delay_value, &scroll_delay_text },
7316 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7317 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7319 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7320 { &setup.window_scaling_percent, &window_size_text },
7322 { &setup.window_scaling_quality, execSetupChooseScalingType },
7323 { &setup.window_scaling_quality, &scaling_type_text },
7325 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7326 { &setup.screen_rendering_mode, &rendering_mode_text },
7328 { &setup.vsync_mode, execSetupChooseVsyncMode },
7329 { &setup.vsync_mode, &vsync_mode_text },
7331 { &setup.graphics_set, execSetupChooseGraphics },
7332 { &setup.graphics_set, &graphics_set_name },
7334 { &setup.sounds_set, execSetupChooseSounds },
7335 { &setup.sounds_set, &sounds_set_name },
7337 { &setup.music_set, execSetupChooseMusic },
7338 { &setup.music_set, &music_set_name },
7340 { &setup.volume_simple, execSetupChooseVolumeSimple },
7341 { &setup.volume_simple, &volume_simple_text },
7343 { &setup.volume_loops, execSetupChooseVolumeLoops },
7344 { &setup.volume_loops, &volume_loops_text },
7346 { &setup.volume_music, execSetupChooseVolumeMusic },
7347 { &setup.volume_music, &volume_music_text },
7349 { &setup.touch.control_type, execSetupChooseTouchControls },
7350 { &setup.touch.control_type, &touch_controls_text },
7352 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7353 { &setup.touch.move_distance, &move_distance_text },
7355 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7356 { &setup.touch.drop_distance, &drop_distance_text },
7358 { &setup.touch.transparency, execSetupChooseTransparency },
7359 { &setup.touch.transparency, &transparency_text },
7361 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7362 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7364 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7365 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7367 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7368 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7370 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7371 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7373 { &setup.internal.menu_game, execSetupGame },
7374 { &setup.internal.menu_engines, execSetupEngines },
7375 { &setup.internal.menu_editor, execSetupEditor },
7376 { &setup.internal.menu_graphics, execSetupGraphics },
7377 { &setup.internal.menu_sound, execSetupSound },
7378 { &setup.internal.menu_artwork, execSetupArtwork },
7379 { &setup.internal.menu_input, execSetupInput },
7380 { &setup.internal.menu_touch, execSetupTouch },
7381 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7382 { &setup.internal.menu_exit, execExitSetup },
7383 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7385 { &setup.internal.menu_shortcuts_various, execSetupShortcuts1 },
7386 { &setup.internal.menu_shortcuts_focus, execSetupShortcuts2 },
7387 { &setup.internal.menu_shortcuts_tape, execSetupShortcuts3 },
7388 { &setup.internal.menu_shortcuts_sound, execSetupShortcuts4 },
7389 { &setup.internal.menu_shortcuts_snap, execSetupShortcuts5 },
7391 { &setup.internal.info_title, execInfoTitleScreen },
7392 { &setup.internal.info_elements, execInfoElements },
7393 { &setup.internal.info_music, execInfoMusic },
7394 { &setup.internal.info_credits, execInfoCredits },
7395 { &setup.internal.info_program, execInfoProgram },
7396 { &setup.internal.info_version, execInfoVersion },
7397 { &setup.internal.info_levelset, execInfoLevelSet },
7398 { &setup.internal.info_exit, execExitInfo },
7403 void setHideRelatedSetupEntries(void)
7407 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7408 if (hideSetupEntry(hide_related_entry_list[i].value))
7409 setHideSetupEntry(hide_related_entry_list[i].related_value);
7412 static struct TokenInfo setup_info_main[] =
7414 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7415 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7416 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7417 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7418 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7419 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7420 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7421 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7422 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7423 { TYPE_EMPTY, NULL, "" },
7424 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7425 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7430 static struct TokenInfo setup_info_game[] =
7432 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7433 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7434 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7435 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7436 { TYPE_STRING, &network_server_text, "" },
7437 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7438 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7439 { TYPE_STRING, &scores_type_text, "" },
7440 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7441 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7442 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7443 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7444 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7445 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7446 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7447 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7448 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7449 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7450 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7451 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7452 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7453 { TYPE_SWITCH, &setup.autorecord, "Auto-Record When Playing:" },
7454 { TYPE_SWITCH, &setup.autorecord_after_replay, "Auto-Record After Replay:" },
7455 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7456 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7457 { TYPE_STRING, &game_speed_text, "" },
7458 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7460 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7461 { TYPE_STRING, &scroll_delay_text, "" },
7463 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7464 { TYPE_STRING, &snapshot_mode_text, "" },
7465 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7466 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7467 { TYPE_EMPTY, NULL, "" },
7468 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7473 static struct TokenInfo setup_info_engines[] =
7475 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7476 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7477 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7478 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7479 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7480 { TYPE_EMPTY, NULL, "" },
7481 { TYPE_HEADLINE, NULL, "Supaplex" },
7482 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7483 { TYPE_EMPTY, NULL, "" },
7484 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7489 static struct TokenInfo setup_info_editor[] =
7492 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7493 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7494 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7495 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7496 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7497 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7498 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7499 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7500 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7501 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7503 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7504 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7506 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7508 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7509 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7510 { TYPE_EMPTY, NULL, "" },
7512 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7513 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7514 { TYPE_EMPTY, NULL, "" },
7516 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7517 { TYPE_EMPTY, NULL, "" },
7518 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7519 { TYPE_EMPTY, NULL, "" },
7520 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7525 static struct TokenInfo setup_info_graphics[] =
7527 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
7528 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7529 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7530 { TYPE_STRING, &window_size_text, "" },
7531 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7532 { TYPE_STRING, &scaling_type_text, "" },
7533 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7534 { TYPE_STRING, &rendering_mode_text, "" },
7537 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7538 { TYPE_STRING, &scroll_delay_text, "" },
7540 #if !defined(PLATFORM_EMSCRIPTEN)
7541 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7542 { TYPE_STRING, &vsync_mode_text, "" },
7544 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7545 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7546 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7547 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7548 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7549 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7550 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7551 { TYPE_EMPTY, NULL, "" },
7552 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7557 static struct TokenInfo setup_info_sound[] =
7559 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7560 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7561 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7562 { TYPE_EMPTY, NULL, "" },
7563 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7564 { TYPE_STRING, &volume_simple_text, "" },
7565 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7566 { TYPE_STRING, &volume_loops_text, "" },
7567 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7568 { TYPE_STRING, &volume_music_text, "" },
7569 { TYPE_EMPTY, NULL, "" },
7570 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7575 static struct TokenInfo setup_info_artwork[] =
7577 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7578 { TYPE_STRING, &graphics_set_name, "" },
7579 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7580 { TYPE_STRING, &sounds_set_name, "" },
7581 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7582 { TYPE_STRING, &music_set_name, "" },
7583 { TYPE_EMPTY, NULL, "" },
7584 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7585 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7586 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7587 { TYPE_EMPTY, NULL, "" },
7588 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7593 static struct TokenInfo setup_info_input[] =
7595 { TYPE_SWITCH, NULL, "Player:" },
7596 { TYPE_SWITCH, NULL, "Device:" },
7597 { TYPE_SWITCH, NULL, "" },
7598 { TYPE_SKIPPABLE, NULL, "" },
7599 { TYPE_EMPTY, NULL, "" },
7600 { TYPE_EMPTY, NULL, "" },
7601 { TYPE_EMPTY, NULL, "" },
7602 { TYPE_EMPTY, NULL, "" },
7603 { TYPE_EMPTY, NULL, "" },
7604 { TYPE_EMPTY, NULL, "" },
7605 { TYPE_EMPTY, NULL, "" },
7606 { TYPE_EMPTY, NULL, "" },
7607 { TYPE_SKIPPABLE, NULL, "" },
7608 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7613 static struct TokenInfo setup_info_touch[] =
7615 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7616 { TYPE_STRING, &touch_controls_text, "" },
7617 { TYPE_EMPTY, NULL, "" },
7618 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7623 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7625 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7626 { TYPE_STRING, &touch_controls_text, "" },
7627 { TYPE_EMPTY, NULL, "" },
7628 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7629 { TYPE_STRING, &grid_size_text[0][0], "" },
7630 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7631 { TYPE_STRING, &grid_size_text[0][1], "" },
7632 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7633 { TYPE_STRING, &transparency_text, "" },
7634 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7635 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7636 { TYPE_EMPTY, NULL, "" },
7637 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7638 { TYPE_EMPTY, NULL, "" },
7639 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7644 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7646 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7647 { TYPE_STRING, &touch_controls_text, "" },
7648 { TYPE_EMPTY, NULL, "" },
7649 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7650 { TYPE_STRING, &grid_size_text[1][0], "" },
7651 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7652 { TYPE_STRING, &grid_size_text[1][1], "" },
7653 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7654 { TYPE_STRING, &transparency_text, "" },
7655 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7656 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7657 { TYPE_EMPTY, NULL, "" },
7658 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7659 { TYPE_EMPTY, NULL, "" },
7660 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7665 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7667 setup_info_touch_virtual_buttons_0,
7668 setup_info_touch_virtual_buttons_1
7671 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7673 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7674 { TYPE_STRING, &touch_controls_text, "" },
7675 { TYPE_EMPTY, NULL, "" },
7676 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7677 { TYPE_STRING, &move_distance_text, "" },
7678 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7679 { TYPE_STRING, &drop_distance_text, "" },
7680 { TYPE_EMPTY, NULL, "" },
7681 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7686 static struct TokenInfo setup_info_shortcuts[] =
7688 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7689 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7690 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7691 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7692 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7693 { TYPE_EMPTY, NULL, "" },
7694 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7699 static struct TokenInfo setup_info_shortcuts_1[] =
7701 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7702 { TYPE_KEY, &setup.shortcut.save_game, "" },
7703 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7704 { TYPE_KEY, &setup.shortcut.load_game, "" },
7705 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7706 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7707 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7708 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7709 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7710 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7711 { TYPE_EMPTY, NULL, "" },
7712 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7713 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7714 { TYPE_EMPTY, NULL, "" },
7715 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7720 static struct TokenInfo setup_info_shortcuts_2[] =
7722 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7723 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7724 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7725 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7726 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7727 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7728 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7729 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7730 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7731 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7732 { TYPE_EMPTY, NULL, "" },
7733 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7738 static struct TokenInfo setup_info_shortcuts_3[] =
7740 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7741 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7742 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7743 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7744 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7745 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7746 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7747 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7748 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7749 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7750 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7751 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7752 { TYPE_EMPTY, NULL, "" },
7753 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7758 static struct TokenInfo setup_info_shortcuts_4[] =
7760 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7761 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7762 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7763 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7764 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7765 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7766 { TYPE_EMPTY, NULL, "" },
7767 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7772 static struct TokenInfo setup_info_shortcuts_5[] =
7774 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7775 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7776 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7777 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7778 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7779 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7780 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7781 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7782 { TYPE_EMPTY, NULL, "" },
7783 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7788 static Key getSetupKey(void)
7790 Key key = KSYM_UNDEFINED;
7791 boolean got_key_event = FALSE;
7793 while (!got_key_event)
7797 if (NextValidEvent(&event))
7801 case EVENT_KEYPRESS:
7803 key = GetEventKey((KeyEvent *)&event);
7805 // press 'Escape' or 'Enter' to keep the existing key binding
7806 if (key == KSYM_Escape || key == KSYM_Return)
7807 key = KSYM_UNDEFINED; // keep old value
7809 got_key_event = TRUE;
7813 case EVENT_KEYRELEASE:
7814 key_joystick_mapping = 0;
7818 HandleOtherEvents(&event);
7829 static int getSetupValueFont(int type, void *value)
7831 if (type & TYPE_GHOSTED)
7832 return FONT_OPTION_OFF;
7833 else if (type & TYPE_KEY)
7834 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7835 else if (type & TYPE_STRING)
7836 return FONT_VALUE_2;
7837 else if (type & TYPE_ECS_AGA)
7838 return FONT_VALUE_1;
7839 else if (type & TYPE_BOOLEAN_STYLE)
7840 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7841 else if (type & TYPE_YES_NO_AUTO)
7842 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7843 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7844 else if (type & TYPE_PLAYER)
7845 return FONT_VALUE_1;
7847 return FONT_VALUE_1;
7850 static int getSetupValueFontNarrow(int type, int font_nr)
7852 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7853 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7854 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7858 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7860 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7861 struct TokenInfo *si = &setup_info[si_pos];
7862 boolean font_draw_xoffset_modified = FALSE;
7863 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7864 int font_draw_xoffset_old = -1;
7865 int xoffset = (scrollbar_needed ? -1 : 0);
7866 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7867 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7868 int xpos = menu_screen_value_xpos;
7869 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7870 int startx = mSX + xpos * 32;
7871 int starty = mSY + ypos * 32;
7872 int type = si->type;
7873 void *value = si->value;
7874 char *value_string = getSetupValue(type, value);
7875 int font_nr_default = getSetupValueFont(type, value);
7876 int font_width_default = getFontWidth(font_nr_default);
7877 int font_nr = font_nr_default;
7880 if (value_string == NULL)
7883 if (type & TYPE_KEY)
7885 xpos = MENU_SCREEN_START_XPOS;
7887 if (type & TYPE_QUERY)
7888 value_string = "<press key>";
7890 else if (type & TYPE_STRING)
7892 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7894 xpos = MENU_SCREEN_START_XPOS;
7896 if (strlen(value_string) > max_value_len)
7897 value_string[max_value_len] = '\0';
7899 else if (type & TYPE_YES_NO_AUTO)
7901 xpos = menu_screen_value_xpos - 1;
7903 else if (type & TYPE_PLAYER)
7905 int displayed_player_nr = *(int *)value + 1;
7907 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7910 startx = mSX + xpos * 32;
7911 starty = mSY + ypos * 32;
7913 // special check if right-side setup values moved left due to scrollbar
7914 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7916 int max_menu_text_length = 26; // maximum text length for classic menu
7917 int font_xoffset = getFontDrawOffsetX(font_nr);
7918 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7919 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7920 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7921 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7923 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7925 // when using narrow font, left-shifting text "auto" not needed
7926 if (type & TYPE_YES_NO_AUTO)
7930 startx = mSX + xpos * 32;
7932 font_nr = getSetupValueFontNarrow(type, font_nr);
7936 // downward compatibility correction for Juergen Bonhagen's menu settings
7937 if (setup_mode != SETUP_MODE_INPUT)
7939 int max_menu_text_length_big = (menu_screen_value_xpos -
7940 MENU_SCREEN_START_XPOS);
7941 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7942 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7943 int font1_xoffset = getFontDrawOffsetX(font_nr);
7944 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7945 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7946 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7947 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7948 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7949 boolean correct_font_draw_xoffset = FALSE;
7951 if (xpos == MENU_SCREEN_START_XPOS &&
7952 startx + font1_xoffset < text_startx + text_font_xoffset)
7953 correct_font_draw_xoffset = TRUE;
7955 if (xpos == menu_screen_value_xpos &&
7956 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7957 correct_font_draw_xoffset = TRUE;
7959 // check if setup value would overlap with setup text when printed
7960 // (this can happen for extreme/wrong values for font draw offset)
7961 if (correct_font_draw_xoffset)
7963 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7964 font_draw_xoffset_modified = TRUE;
7966 if (type & TYPE_KEY)
7967 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7968 else if (!(type & TYPE_STRING))
7969 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7970 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7974 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7975 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7977 DrawText(startx, starty, value_string, font_nr);
7979 if (type & TYPE_PLAYER)
7981 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7982 int player_nr = *(int *)value;
7983 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7984 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7985 int startx2 = startx + xoff;
7986 int starty2 = starty + yoff;
7988 if (DrawingOnBackground(startx2, starty2))
7989 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7991 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7992 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7995 if (font_draw_xoffset_modified)
7996 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7999 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
8001 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
8002 struct TokenInfo *si = &setup_info[si_pos];
8004 if (si->type & TYPE_BOOLEAN_STYLE)
8006 *(boolean *)si->value ^= TRUE;
8008 else if (si->type & TYPE_YES_NO_AUTO)
8012 (*(int *)si->value == AUTO ? TRUE :
8013 *(int *)si->value == TRUE ? FALSE : AUTO) :
8014 (*(int *)si->value == TRUE ? AUTO :
8015 *(int *)si->value == AUTO ? FALSE : TRUE));
8017 else if (si->type & TYPE_KEY)
8021 si->type |= TYPE_QUERY;
8022 drawSetupValue(screen_pos, setup_info_pos_raw);
8023 si->type &= ~TYPE_QUERY;
8025 key = getSetupKey();
8026 if (key != KSYM_UNDEFINED)
8027 *(Key *)si->value = key;
8029 else if (si->type & TYPE_PLAYER)
8031 int player_nr = *(int *)si->value;
8036 player_nr = Request("Choose player", REQ_PLAYER) - 1;
8038 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
8041 drawSetupValue(screen_pos, setup_info_pos_raw);
8043 // fullscreen state may have changed at this point
8044 if (si->value == &setup.fullscreen)
8045 ToggleFullscreenIfNeeded();
8047 // network mode may have changed at this point
8048 if (si->value == &setup.network_mode)
8049 ToggleNetworkModeIfNeeded();
8051 // API server mode may have changed at this point
8052 if (si->value == &setup.use_api_server)
8053 ToggleUseApiServerIfNeeded();
8055 // game speed list may have changed at this point
8056 if (si->value == &setup.game_speed_extended)
8057 ToggleGameSpeedsListIfNeeded();
8060 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
8062 static struct TokenInfo *setup_info_final = NULL;
8067 // determine maximum list size of target list
8068 while (setup_info_orig[list_size++].type != 0);
8070 // free, allocate and clear memory for target list
8071 checked_free(setup_info_final);
8072 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
8074 // copy setup info list without setup entries marked as hidden
8075 for (i = 0; setup_info_orig[i].type != 0; i++)
8077 // skip setup entries configured to be hidden
8078 if (hideSetupEntry(setup_info_orig[i].value))
8081 // skip skippable setup entries if screen is lower than usual
8082 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8083 setup_info_orig[i].type == TYPE_SKIPPABLE)
8086 setup_info_final[list_pos++] = setup_info_orig[i];
8089 return setup_info_final;
8092 static void DrawSetupScreen_Generic(void)
8094 int fade_mask = REDRAW_FIELD;
8095 boolean redraw_all = FALSE;
8096 char *title_string = NULL;
8100 fade_mask = REDRAW_ALL;
8103 FadeMenuSoundsAndMusic();
8105 FreeScreenGadgets();
8106 CreateScreenGadgets();
8108 if (redraw_mask & REDRAW_ALL)
8113 // needed if different viewport properties defined for setup screen
8114 ChangeViewportPropertiesIfNeeded();
8116 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8120 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8122 if (setup_mode == SETUP_MODE_MAIN)
8124 setup_info = setup_info_main;
8125 title_string = STR_SETUP_MAIN;
8127 else if (setup_mode == SETUP_MODE_GAME)
8129 setup_info = setup_info_game;
8130 title_string = STR_SETUP_GAME;
8132 else if (setup_mode == SETUP_MODE_ENGINES)
8134 setup_info = setup_info_engines;
8135 title_string = STR_SETUP_ENGINES;
8137 else if (setup_mode == SETUP_MODE_EDITOR)
8139 setup_info = setup_info_editor;
8140 title_string = STR_SETUP_EDITOR;
8142 else if (setup_mode == SETUP_MODE_GRAPHICS)
8144 setup_info = setup_info_graphics;
8145 title_string = STR_SETUP_GRAPHICS;
8147 else if (setup_mode == SETUP_MODE_SOUND)
8149 setup_info = setup_info_sound;
8150 title_string = STR_SETUP_SOUND;
8152 else if (setup_mode == SETUP_MODE_ARTWORK)
8154 setup_info = setup_info_artwork;
8155 title_string = STR_SETUP_ARTWORK;
8157 else if (setup_mode == SETUP_MODE_TOUCH)
8159 setup_info = setup_info_touch;
8160 title_string = STR_SETUP_TOUCH;
8162 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8163 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8164 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8165 setup_info = setup_info_touch_wipe_gestures;
8167 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8169 setup_info = setup_info_shortcuts;
8170 title_string = STR_SETUP_SHORTCUTS;
8172 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8174 setup_info = setup_info_shortcuts_1;
8175 title_string = STR_SETUP_SHORTCUTS;
8177 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8179 setup_info = setup_info_shortcuts_2;
8180 title_string = STR_SETUP_SHORTCUTS;
8182 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8184 setup_info = setup_info_shortcuts_3;
8185 title_string = STR_SETUP_SHORTCUTS;
8187 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8189 setup_info = setup_info_shortcuts_4;
8190 title_string = STR_SETUP_SHORTCUTS;
8192 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8194 setup_info = setup_info_shortcuts_5;
8195 title_string = STR_SETUP_SHORTCUTS;
8198 // use modified setup info without setup entries marked as hidden
8199 setup_info = getSetupInfoFinal(setup_info);
8201 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8203 // determine maximal number of setup entries that can be displayed on screen
8205 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8208 // determine maximal number of setup entries available for this setup screen
8210 for (i = 0; setup_info[i].type != 0; i++)
8213 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8215 MapScreenGadgets(max_setup_info);
8218 redraw_mask = fade_mask = REDRAW_ALL;
8220 DrawMaskedBorder(fade_mask);
8225 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8227 menu_info = setup_info;
8229 HandleMenuScreen(mx, my, dx, dy, button,
8230 setup_mode, num_setup_info, max_setup_info);
8233 static void DrawSetupScreen_Input(void)
8237 FadeOut(REDRAW_FIELD);
8241 setup_info = getSetupInfoFinal(setup_info_input);
8243 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8245 for (i = 0; setup_info[i].type != 0; i++)
8247 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8248 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8249 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8250 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8251 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8252 initCursor(i, IMG_MENU_BUTTON);
8254 DrawCursorAndText_Setup(i, -1, FALSE);
8257 // create gadgets for setup input menu screen
8258 FreeScreenGadgets();
8259 CreateScreenGadgets();
8261 // map gadgets for setup input menu screen
8262 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8264 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8266 FadeIn(REDRAW_FIELD);
8269 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8271 if (device_name == NULL)
8274 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8277 if (strlen(device_name) > 1)
8279 char c1 = device_name[strlen(device_name) - 1];
8280 char c2 = device_name[strlen(device_name) - 2];
8282 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8283 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8286 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8287 strlen(device_name));
8290 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8293 static struct SetupKeyboardInfo custom_key;
8300 { &custom_key.left, "Axis/Pad Left" },
8301 { &custom_key.right, "Axis/Pad Right" },
8302 { &custom_key.up, "Axis/Pad Up" },
8303 { &custom_key.down, "Axis/Pad Down" },
8304 { &custom_key.snap, "Button 1/A/X" },
8305 { &custom_key.drop, "Button 2/B/Y" }
8307 static char *joystick_name[MAX_PLAYERS] =
8314 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8315 int font_nr_info = FONT_MENU_1;
8316 int font_nr_name = FONT_VALUE_OLD;
8317 int font_nr_on = FONT_VALUE_1;
8318 int font_nr_off = FONT_VALUE_OLD;
8321 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8323 font_nr_info = FONT_MENU_2;
8324 font_nr_on = FONT_VALUE_NARROW;
8325 font_nr_off = FONT_VALUE_OLD_NARROW;
8328 custom_key = setup.input[player_nr].key;
8330 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8331 FONT_INPUT_1_ACTIVE);
8333 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8335 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8336 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8338 if (setup.input[player_nr].use_joystick)
8340 char *device_name = setup.input[player_nr].joy.device_name;
8341 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8342 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8343 char *text = joystick_name[joystick_nr];
8344 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8346 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8347 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8351 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8352 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8355 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8356 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8360 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8361 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8362 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8363 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8365 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8366 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8367 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8368 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8369 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8370 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8372 for (i = 0; i < 6; i++)
8374 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8376 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8378 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8379 (setup.input[player_nr].use_joystick ?
8381 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8385 static int input_player_nr = 0;
8387 static void HandleSetupScreen_Input_Player(int step, int direction)
8389 int old_player_nr = input_player_nr;
8392 new_player_nr = old_player_nr + step * direction;
8393 if (new_player_nr < 0)
8395 if (new_player_nr > MAX_PLAYERS - 1)
8396 new_player_nr = MAX_PLAYERS - 1;
8398 if (new_player_nr != old_player_nr)
8400 input_player_nr = new_player_nr;
8402 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8406 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8408 static int choice = 0;
8411 int pos_start = SETUPINPUT_SCREEN_POS_START;
8412 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8413 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8414 int pos_end = SETUPINPUT_SCREEN_POS_END;
8416 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8420 for (i = 0; setup_info_input[i].type != 0; i++)
8422 // adjust menu structure according to skipped setup entries
8423 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8431 if (button == MB_MENU_INITIALIZE)
8433 // input setup menu may have changed size due to graphics configuration
8434 if (choice >= pos_empty1)
8437 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8439 DrawCursorAndText_Setup(choice, -1, TRUE);
8443 else if (button == MB_MENU_LEAVE)
8445 setup_mode = SETUP_MODE_MAIN;
8452 if (mx || my) // mouse input
8454 x = (mx - mSX) / 32;
8455 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8457 else if (dx || dy) // keyboard input
8459 if (dx && choice == 0)
8460 x = (dx < 0 ? 10 : 12);
8461 else if ((dx && choice == 1) ||
8462 (dx == -1 && choice == pos_end))
8463 button = MB_MENU_CHOICE;
8467 if (y >= pos_empty1 && y <= pos_empty2)
8468 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8471 if (y == 0 && dx != 0 && button)
8473 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8475 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8476 y >= pos_start && y <= pos_end &&
8477 !(y >= pos_empty1 && y <= pos_empty2))
8483 DrawCursorAndText_Setup(choice, -1, FALSE);
8484 DrawCursorAndText_Setup(y, -1, TRUE);
8486 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8495 char *device_name = setup.input[input_player_nr].joy.device_name;
8497 if (!setup.input[input_player_nr].use_joystick)
8499 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8501 setJoystickDeviceToNr(device_name, new_device_nr);
8502 setup.input[input_player_nr].use_joystick = TRUE;
8506 int device_nr = getJoystickNrFromDeviceName(device_name);
8507 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8509 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8510 setup.input[input_player_nr].use_joystick = FALSE;
8512 setJoystickDeviceToNr(device_name, new_device_nr);
8515 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8519 if (setup.input[input_player_nr].use_joystick)
8520 ConfigureJoystick(input_player_nr);
8522 CustomizeKeyboard(input_player_nr);
8524 else if (y == pos_end)
8530 setup_mode = SETUP_MODE_MAIN;
8537 static boolean CustomizeKeyboardMain(int player_nr)
8541 boolean finished = FALSE;
8542 static struct SetupKeyboardInfo custom_key;
8547 } customize_step[] =
8549 { &custom_key.left, "Move Left" },
8550 { &custom_key.right, "Move Right" },
8551 { &custom_key.up, "Move Up" },
8552 { &custom_key.down, "Move Down" },
8553 { &custom_key.snap, "Snap Field" },
8554 { &custom_key.drop, "Drop Element" }
8556 int font_nr_old = FONT_VALUE_OLD;
8557 int font_nr_new = FONT_VALUE_1;
8558 boolean success = FALSE;
8560 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8562 font_nr_old = FONT_VALUE_OLD_NARROW;
8563 font_nr_new = FONT_VALUE_NARROW;
8566 // read existing key bindings from player setup
8567 custom_key = setup.input[player_nr].key;
8570 FadeOut(REDRAW_FIELD);
8574 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8577 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8578 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8579 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8580 "Key:", FONT_INPUT_1_ACTIVE);
8581 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8582 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8584 FadeIn(REDRAW_FIELD);
8589 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8591 // reset frame delay counter directly after updating screen
8592 ResetDelayCounter(&event_frame_delay);
8594 while (NextValidEvent(&event))
8598 case EVENT_KEYPRESS:
8600 Key key = GetEventKey((KeyEvent *)&event);
8602 // press 'Escape' to abort and keep the old key bindings
8603 if (key == KSYM_Escape)
8605 FadeSkipNextFadeIn();
8612 // press 'Enter' to keep the existing key binding
8613 if (key == KSYM_Return)
8614 key = *customize_step[step_nr].key;
8616 // check if key already used
8617 for (i = 0; i < step_nr; i++)
8618 if (*customize_step[i].key == key)
8623 // got new key binding
8624 *customize_step[step_nr].key = key;
8625 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8627 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8628 getKeyNameFromKey(key), font_nr_new);
8631 // un-highlight last query
8632 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8633 customize_step[step_nr - 1].text, FONT_MENU_1);
8634 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8635 "Key:", FONT_MENU_1);
8637 // all keys configured
8646 // query next key binding
8647 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8648 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8649 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8650 "Key:", FONT_INPUT_1_ACTIVE);
8651 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8652 getKeyNameFromKey(*customize_step[step_nr].key),
8657 case EVENT_KEYRELEASE:
8658 key_joystick_mapping = 0;
8662 HandleOtherEvents(&event);
8666 // do not handle events for longer than standard frame delay period
8667 if (DelayReached(&event_frame_delay))
8674 // write new key bindings back to player setup, if successfully finished
8676 setup.input[player_nr].key = custom_key;
8681 void CustomizeKeyboard(int player_nr)
8683 boolean success = CustomizeKeyboardMain(player_nr);
8687 int font_nr = FONT_TITLE_1;
8688 int font_height = getFontHeight(font_nr);
8689 int ypos1 = SYSIZE / 2 - font_height * 2;
8690 int ypos2 = SYSIZE / 2 - font_height * 1;
8691 DelayCounter wait_frame_delay = { 2000 };
8693 ResetDelayCounter(&wait_frame_delay);
8697 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8698 DrawTextSCentered(ypos2, font_nr, "configured!");
8700 while (!DelayReached(&wait_frame_delay))
8706 DrawSetupScreen_Input();
8709 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8711 #define MARKER_BUTTON 1
8712 #define MARKER_AXIS_X 2
8713 #define MARKER_AXIS_Y 3
8715 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8717 static boolean bitmaps_initialized = FALSE;
8718 boolean screen_initialized = FALSE;
8719 static Bitmap *controller, *button, *axis_x, *axis_y;
8721 boolean success = TRUE;
8722 boolean done = FALSE, next = FALSE;
8724 int alpha = 200, alpha_step = -1;
8725 int alpha_ticks = 0;
8726 char mapping[4096], temp[256];
8727 int font_name = MENU_SETUP_FONT_TITLE;
8728 int font_info = MENU_SETUP_FONT_TEXT;
8729 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8730 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8731 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8732 int ystep_name = getMenuTextStep(spacing_name, font_name);
8733 int ystep_line = getMenuTextStep(spacing_line, font_info);
8734 int ystep_para = getMenuTextStep(spacing_para, font_info);
8742 int axis, button, hat, hat_value;
8745 *step, *prev_step, steps[] =
8747 { 356, 155, MARKER_BUTTON, "a", },
8748 { 396, 122, MARKER_BUTTON, "b", },
8749 { 320, 125, MARKER_BUTTON, "x", },
8750 { 358, 95, MARKER_BUTTON, "y", },
8751 { 162, 125, MARKER_BUTTON, "back", },
8752 { 216, 125, MARKER_BUTTON, "guide", },
8753 { 271, 125, MARKER_BUTTON, "start", },
8754 { 110, 200, MARKER_BUTTON, "dpleft", },
8755 { 146, 228, MARKER_BUTTON, "dpdown", },
8756 { 178, 200, MARKER_BUTTON, "dpright", },
8757 { 146, 172, MARKER_BUTTON, "dpup", },
8758 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8759 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8760 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8761 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8762 { 73, 141, MARKER_BUTTON, "leftstick", },
8763 { 282, 210, MARKER_BUTTON, "rightstick", },
8764 { 73, 141, MARKER_AXIS_X, "leftx", },
8765 { 73, 141, MARKER_AXIS_Y, "lefty", },
8766 { 282, 210, MARKER_AXIS_X, "rightx", },
8767 { 282, 210, MARKER_AXIS_Y, "righty", },
8770 if (!bitmaps_initialized)
8772 controller = LoadCustomImage("joystick/controller.png");
8773 button = LoadCustomImage("joystick/button.png");
8774 axis_x = LoadCustomImage("joystick/axis_x.png");
8775 axis_y = LoadCustomImage("joystick/axis_y.png");
8777 bitmaps_initialized = TRUE;
8780 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8783 // print info about the joystick we are watching
8784 Debug("joystick", "watching joystick %d: (%s)",
8785 SDL_JoystickInstanceID(joystick), name);
8786 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8787 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8788 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8791 // initialize mapping with GUID and name
8792 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8794 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8795 temp, name, SDL_GetPlatform());
8797 // loop through all steps (buttons and axes), getting joystick events
8798 for (i = 0; i < SDL_arraysize(steps) && !done;)
8800 Bitmap *marker = button; // initialize with reliable default value
8803 strcpy(step->mapping, mapping);
8807 step->hat_value = -1;
8809 marker = (step->marker == MARKER_BUTTON ? button :
8810 step->marker == MARKER_AXIS_X ? axis_x :
8811 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8815 while (!done && !next)
8817 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8818 alpha_ticks = SDL_GetTicks();
8825 else if (alpha < 128)
8831 int controller_x = SX + (SXSIZE - controller->width) / 2;
8832 int controller_y = SY + ystep_line;
8834 int marker_x = controller_x + step->x;
8835 int marker_y = controller_y + step->y;
8837 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8838 int ystart2 = ystart1 + ystep_name + ystep_line;
8842 DrawTextSCentered(ystart1, font_name, name);
8844 DrawTextSCentered(ystart2, font_info,
8845 "Press buttons and move axes on");
8846 ystart2 += ystep_line;
8847 DrawTextSCentered(ystart2, font_info,
8848 "your controller when indicated.");
8849 ystart2 += ystep_line;
8850 DrawTextSCentered(ystart2, font_info,
8851 "(Your controller may look different.)");
8852 ystart2 += ystep_para;
8854 #if defined(PLATFORM_ANDROID)
8855 DrawTextSCentered(ystart2, font_info,
8856 "To correct a mistake,");
8857 ystart2 += ystep_line;
8858 DrawTextSCentered(ystart2, font_info,
8859 "press the 'back' button.");
8860 ystart2 += ystep_line;
8861 DrawTextSCentered(ystart2, font_info,
8862 "To skip a button or axis,");
8863 ystart2 += ystep_line;
8864 DrawTextSCentered(ystart2, font_info,
8865 "press the 'menu' button.");
8867 DrawTextSCentered(ystart2, font_info,
8868 "To correct a mistake,");
8869 ystart2 += ystep_line;
8870 DrawTextSCentered(ystart2, font_info,
8871 "press the 'backspace' key.");
8872 ystart2 += ystep_line;
8873 DrawTextSCentered(ystart2, font_info,
8874 "To skip a button or axis,");
8875 ystart2 += ystep_line;
8876 DrawTextSCentered(ystart2, font_info,
8877 "press the 'return' key.");
8878 ystart2 += ystep_line;
8879 DrawTextSCentered(ystart2, font_info,
8880 "To exit, press the 'escape' key.");
8883 BlitBitmapMasked(controller, drawto, 0, 0,
8884 controller->width, controller->height,
8885 controller_x, controller_y);
8887 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8888 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8890 BlitBitmapMasked(marker, drawto, 0, 0,
8891 marker->width, marker->height,
8892 marker_x, marker_y);
8894 if (!screen_initialized)
8895 FadeIn(REDRAW_FIELD);
8899 screen_initialized = TRUE;
8901 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8903 // reset frame delay counter directly after updating screen
8904 ResetDelayCounter(&event_frame_delay);
8906 while (NextValidEvent(&event))
8910 case SDL_JOYAXISMOTION:
8911 if (event.jaxis.value > 20000 ||
8912 event.jaxis.value < -20000)
8914 for (j = 0; j < i; j++)
8915 if (steps[j].axis == event.jaxis.axis)
8920 if (step->marker != MARKER_AXIS_X &&
8921 step->marker != MARKER_AXIS_Y)
8924 step->axis = event.jaxis.axis;
8925 strcat(mapping, step->field);
8926 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8927 strcat(mapping, temp);
8935 case SDL_JOYHATMOTION:
8936 // ignore centering; we're probably just coming back
8937 // to the center from the previous item we set
8938 if (event.jhat.value == SDL_HAT_CENTERED)
8941 for (j = 0; j < i; j++)
8942 if (steps[j].hat == event.jhat.hat &&
8943 steps[j].hat_value == event.jhat.value)
8948 step->hat = event.jhat.hat;
8949 step->hat_value = event.jhat.value;
8950 strcat(mapping, step->field);
8951 snprintf(temp, sizeof(temp), ":h%u.%u,",
8952 event.jhat.hat, event.jhat.value );
8953 strcat(mapping, temp);
8960 case SDL_JOYBALLMOTION:
8963 case SDL_JOYBUTTONUP:
8964 for (j = 0; j < i; j++)
8965 if (steps[j].button == event.jbutton.button)
8970 step->button = event.jbutton.button;
8971 strcat(mapping, step->field);
8972 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8973 strcat(mapping, temp);
8980 case SDL_FINGERDOWN:
8981 case SDL_MOUSEBUTTONDOWN:
8989 if (event.key.keysym.sym == KSYM_BackSpace ||
8990 event.key.keysym.sym == KSYM_Back)
9002 prev_step = &steps[i - 1];
9003 strcpy(mapping, prev_step->mapping);
9010 if (event.key.keysym.sym == KSYM_space ||
9011 event.key.keysym.sym == KSYM_Return ||
9012 event.key.keysym.sym == KSYM_Menu)
9021 if (event.key.keysym.sym == KSYM_Escape)
9031 program.exit_function(0);
9038 // do not handle events for longer than standard frame delay period
9039 if (DelayReached(&event_frame_delay))
9048 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
9051 // activate mapping for this game
9052 SDL_GameControllerAddMapping(mapping);
9054 // save mapping to personal mappings
9055 SaveSetup_AddGameControllerMapping(mapping);
9058 // wait until the last pending event was removed from event queue
9059 while (NextValidEvent(&event));
9064 static int ConfigureJoystickMain(int player_nr)
9066 char *device_name = setup.input[player_nr].joy.device_name;
9067 int joystick_nr = getJoystickNrFromDeviceName(device_name);
9068 boolean joystick_active = CheckJoystickOpened(joystick_nr);
9069 int success = FALSE;
9072 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
9073 return JOYSTICK_NOT_AVAILABLE;
9075 if (!joystick_active || !setup.input[player_nr].use_joystick)
9076 return JOYSTICK_NOT_AVAILABLE;
9079 FadeOut(REDRAW_FIELD);
9081 // close all joystick devices (potentially opened as game controllers)
9082 for (i = 0; i < SDL_NumJoysticks(); i++)
9083 SDLCloseJoystick(i);
9085 // open joystick device as plain joystick to configure as game controller
9086 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9088 // as the joystick was successfully opened before, this should not happen
9089 if (joystick == NULL)
9092 // create new game controller mapping (buttons and axes) for joystick device
9093 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9095 // close joystick (and maybe re-open as configured game controller later)
9096 SDL_JoystickClose(joystick);
9098 // re-open all joystick devices (potentially as game controllers)
9099 for (i = 0; i < SDL_NumJoysticks(); i++)
9102 // clear all joystick input actions for all joystick devices
9103 SDLClearJoystickState();
9105 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9108 void ConfigureJoystick(int player_nr)
9110 boolean state = ConfigureJoystickMain(player_nr);
9112 if (state != JOYSTICK_NOT_CONFIGURED)
9114 boolean success = (state == JOYSTICK_CONFIGURED);
9115 char message1[MAX_OUTPUT_LINESIZE + 1];
9116 char *message2 = (success ? "configured!" : "not available!");
9117 char *device_name = setup.input[player_nr].joy.device_name;
9118 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9119 int font_nr = FONT_TITLE_1;
9120 int font_height = getFontHeight(font_nr);
9121 int ypos1 = SYSIZE / 2 - font_height * 2;
9122 int ypos2 = SYSIZE / 2 - font_height * 1;
9123 DelayCounter wait_frame_delay = { 2000 };
9125 ResetDelayCounter(&wait_frame_delay);
9129 sprintf(message1, "Joystick %d", nr);
9131 DrawTextSCentered(ypos1, font_nr, message1);
9132 DrawTextSCentered(ypos2, font_nr, message2);
9134 while (!DelayReached(&wait_frame_delay))
9140 DrawSetupScreen_Input();
9143 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9145 if (y < video.screen_height / 3)
9147 // remap touch gadgets to access upper part of the screen
9148 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9149 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9151 else if (y > 2 * video.screen_height / 3)
9153 // remap touch gadgets to access lower part of the screen
9154 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9155 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9159 static boolean ConfigureVirtualButtonsMain(void)
9161 static char *customize_step_text[] =
9170 char grid_button[] =
9172 CHAR_GRID_BUTTON_LEFT,
9173 CHAR_GRID_BUTTON_RIGHT,
9174 CHAR_GRID_BUTTON_UP,
9175 CHAR_GRID_BUTTON_DOWN,
9176 CHAR_GRID_BUTTON_SNAP,
9177 CHAR_GRID_BUTTON_DROP
9186 int font_nr = FONT_INPUT_1_ACTIVE;
9187 int font_height = getFontHeight(font_nr);
9188 int ypos1 = SYSIZE / 2 - font_height * 2;
9189 int ypos2 = SYSIZE / 2 - font_height * 1;
9190 boolean success = FALSE;
9191 boolean finished = FALSE;
9193 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9194 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9195 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9196 boolean set_grid_button = FALSE;
9197 int nr = GRID_ACTIVE_NR();
9200 for (x = 0; x < MAX_GRID_XSIZE; x++)
9201 for (y = 0; y < MAX_GRID_YSIZE; y++)
9202 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9204 overlay.grid_button_highlight = grid_button[step_nr];
9209 FadeOut(REDRAW_FIELD);
9213 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9214 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9215 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9217 FadeIn(REDRAW_FIELD);
9219 SetOverlayShowGrid(TRUE);
9221 // map gadgets for setup touch buttons menu screen
9222 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9228 while (NextValidEvent(&event))
9230 int action = ACTION_NONE;
9232 // ---------- handle events and set the resulting action ----------
9238 UserEvent *user = (UserEvent *)&event;
9239 int id = user->value1;
9241 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9242 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9243 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9244 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9249 case EVENT_KEYPRESS:
9251 Key key = GetEventKey((KeyEvent *)&event);
9253 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9254 key == KSYM_BackSpace ||
9255 key == KSYM_Back ? ACTION_BACK :
9256 key == KSYM_Return ||
9258 key == KSYM_space ? ACTION_NEXT :
9263 case EVENT_KEYRELEASE:
9264 key_joystick_mapping = 0;
9267 case EVENT_BUTTONPRESS:
9268 case EVENT_BUTTONRELEASE:
9270 ButtonEvent *button = (ButtonEvent *)&event;
9272 motion_status = FALSE;
9274 if (button->type == EVENT_BUTTONPRESS)
9275 button_status = button->button;
9277 button_status = MB_RELEASED;
9279 if (HandleGadgets(button->x, button->y, button_status))
9281 // do not handle this button event anymore
9285 button->x += video.screen_xoffset;
9286 button->y += video.screen_yoffset;
9288 x = button->x * overlay.grid_xsize / video.screen_width;
9289 y = button->y * overlay.grid_ysize / video.screen_height;
9291 if (button->type == EVENT_BUTTONPRESS)
9294 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9295 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9297 set_grid_button = TRUE;
9300 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9304 case EVENT_MOTIONNOTIFY:
9306 MotionEvent *motion = (MotionEvent *)&event;
9308 motion_status = TRUE;
9310 if (HandleGadgets(motion->x, motion->y, button_status))
9312 // do not handle this button event anymore
9316 motion->x += video.screen_xoffset;
9317 motion->y += video.screen_yoffset;
9319 x = motion->x * overlay.grid_xsize / video.screen_width;
9320 y = motion->y * overlay.grid_ysize / video.screen_height;
9322 set_grid_button = TRUE;
9324 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9328 case SDL_WINDOWEVENT:
9329 HandleWindowEvent((WindowEvent *) &event);
9331 // check if device has been rotated
9332 if (nr != GRID_ACTIVE_NR())
9334 nr = GRID_ACTIVE_NR();
9336 for (x = 0; x < MAX_GRID_XSIZE; x++)
9337 for (y = 0; y < MAX_GRID_YSIZE; y++)
9338 grid_button_old[x][y] = grid_button_tmp[x][y] =
9339 overlay.grid_button[x][y];
9344 case SDL_APP_WILLENTERBACKGROUND:
9345 case SDL_APP_DIDENTERBACKGROUND:
9346 case SDL_APP_WILLENTERFOREGROUND:
9347 case SDL_APP_DIDENTERFOREGROUND:
9348 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9352 HandleOtherEvents(&event);
9356 // ---------- perform action set by handling events ----------
9358 if (action == ACTION_ESCAPE)
9360 // abort and restore the old key bindings
9362 for (x = 0; x < MAX_GRID_XSIZE; x++)
9363 for (y = 0; y < MAX_GRID_YSIZE; y++)
9364 overlay.grid_button[x][y] = grid_button_old[x][y];
9366 FadeSkipNextFadeIn();
9370 else if (action == ACTION_BACK)
9372 // keep the configured key bindings and go to previous page
9378 FadeSkipNextFadeIn();
9383 else if (action == ACTION_NEXT)
9385 // keep the configured key bindings and go to next page
9389 // all virtual buttons configured
9397 if (action != ACTION_NONE && !finished)
9399 for (x = 0; x < MAX_GRID_XSIZE; x++)
9400 for (y = 0; y < MAX_GRID_YSIZE; y++)
9401 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9403 overlay.grid_button_highlight = grid_button[step_nr];
9405 // configure next virtual button
9409 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9410 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9411 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9414 if (set_grid_button)
9416 overlay.grid_button[x][y] =
9417 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9418 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9419 grid_button_tmp[x][y]);
9421 set_grid_button = FALSE;
9428 for (x = 0; x < MAX_GRID_XSIZE; x++)
9429 for (y = 0; y < MAX_GRID_YSIZE; y++)
9430 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9432 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9434 SetOverlayShowGrid(FALSE);
9439 void ConfigureVirtualButtons(void)
9441 boolean success = ConfigureVirtualButtonsMain();
9443 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9444 SCREEN_MASK_TOUCH2);
9448 int font_nr = FONT_TITLE_1;
9449 int font_height = getFontHeight(font_nr);
9450 int ypos1 = SYSIZE / 2 - font_height * 2;
9451 int ypos2 = SYSIZE / 2 - font_height * 1;
9452 DelayCounter wait_frame_delay = { 2000 };
9454 ResetDelayCounter(&wait_frame_delay);
9458 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9459 DrawTextSCentered(ypos2, font_nr, "configured!");
9461 while (!DelayReached(&wait_frame_delay))
9468 void DrawSetupScreen(void)
9473 if (setup_mode == SETUP_MODE_INPUT)
9474 DrawSetupScreen_Input();
9475 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9476 DrawChooseTree(&scores_type_current);
9477 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9478 DrawChooseTree(&game_speed_current);
9479 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9480 DrawChooseTree(&scroll_delay_current);
9481 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9482 DrawChooseTree(&snapshot_mode_current);
9483 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9484 DrawChooseTree(&window_size_current);
9485 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9486 DrawChooseTree(&scaling_type_current);
9487 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9488 DrawChooseTree(&rendering_mode_current);
9489 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9490 DrawChooseTree(&vsync_mode_current);
9491 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9492 DrawChooseTree(&artwork.gfx_current);
9493 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9494 DrawChooseTree(&artwork.snd_current);
9495 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9496 DrawChooseTree(&artwork.mus_current);
9497 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9498 DrawChooseTree(&volume_simple_current);
9499 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9500 DrawChooseTree(&volume_loops_current);
9501 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9502 DrawChooseTree(&volume_music_current);
9503 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9504 DrawChooseTree(&touch_control_current);
9505 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9506 DrawChooseTree(&move_distance_current);
9507 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9508 DrawChooseTree(&drop_distance_current);
9509 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9510 DrawChooseTree(&transparency_current);
9511 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9512 DrawChooseTree(&grid_size_current[0][0]);
9513 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9514 DrawChooseTree(&grid_size_current[0][1]);
9515 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9516 DrawChooseTree(&grid_size_current[1][0]);
9517 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9518 DrawChooseTree(&grid_size_current[1][1]);
9520 DrawSetupScreen_Generic();
9522 PlayMenuSoundsAndMusic();
9525 void RedrawSetupScreenAfterFullscreenToggle(void)
9527 if (setup_mode == SETUP_MODE_GRAPHICS ||
9528 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9530 // update list selection from "setup.window_scaling_percent"
9531 execSetupGraphics_setWindowSizes(TRUE);
9537 void RedrawSetupScreenAfterScreenRotation(int nr)
9541 if (setup_mode == SETUP_MODE_TOUCH)
9543 // update virtual button settings (depending on screen orientation)
9546 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9548 // save already configured virtual buttons
9549 for (x = 0; x < MAX_GRID_XSIZE; x++)
9550 for (y = 0; y < MAX_GRID_YSIZE; y++)
9551 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9555 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9557 if (setup_mode == SETUP_MODE_INPUT)
9558 HandleSetupScreen_Input(mx, my, dx, dy, button);
9559 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9560 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9561 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9562 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9563 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9564 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9565 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9566 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9567 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9568 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9569 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9570 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9571 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9572 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9573 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9574 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9575 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9576 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9577 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9578 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9579 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9580 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9581 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9582 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9583 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9584 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9585 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9586 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9587 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9588 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9589 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9590 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9591 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9592 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9593 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9594 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9595 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9596 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9597 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9598 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9599 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9600 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9601 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9602 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9604 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9607 void HandleGameActions(void)
9609 if (CheckRestartGame())
9612 if (game_status != GAME_MODE_PLAYING)
9615 GameActions(); // main game loop
9617 if (tape.auto_play && !tape.playing)
9618 AutoPlayTapesContinue(); // continue automatically playing next tape
9622 // ---------- new screen button stuff --------------------------------------
9626 int gfx_unpressed, gfx_pressed, gfx_active;
9627 struct MenuPosInfo *pos;
9628 boolean *check_value;
9631 unsigned int event_mask;
9632 boolean is_touch_button;
9634 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9637 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE, -1,
9638 &menu.main.button.prev_level, NULL,
9639 SCREEN_CTRL_ID_PREV_LEVEL,
9641 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9642 FALSE, "previous level"
9645 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE, -1,
9646 &menu.main.button.next_level, NULL,
9647 SCREEN_CTRL_ID_NEXT_LEVEL,
9649 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9653 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE, -1,
9654 &menu.scores.button.prev_level, NULL,
9655 SCREEN_CTRL_ID_PREV_LEVEL2,
9656 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9657 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9658 FALSE, "previous level"
9661 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE, -1,
9662 &menu.scores.button.next_level, NULL,
9663 SCREEN_CTRL_ID_NEXT_LEVEL2,
9664 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9665 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9669 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE, -1,
9670 &menu.scores.button.prev_score, NULL,
9671 SCREEN_CTRL_ID_PREV_SCORE,
9672 SCREEN_MASK_SCORES_INFO,
9673 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9674 FALSE, "previous score"
9677 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE, -1,
9678 &menu.scores.button.next_score, NULL,
9679 SCREEN_CTRL_ID_NEXT_SCORE,
9680 SCREEN_MASK_SCORES_INFO,
9681 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9685 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE, -1,
9686 &menu.scores.button.play_tape, NULL,
9687 SCREEN_CTRL_ID_PLAY_TAPE,
9688 SCREEN_MASK_SCORES_INFO,
9693 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE, -1,
9694 &menu.main.button.first_level, NULL,
9695 SCREEN_CTRL_ID_FIRST_LEVEL,
9698 FALSE, "first level"
9701 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE, -1,
9702 &menu.main.button.last_level, NULL,
9703 SCREEN_CTRL_ID_LAST_LEVEL,
9709 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE, -1,
9710 &menu.main.button.level_number, NULL,
9711 SCREEN_CTRL_ID_LEVEL_NUMBER,
9714 FALSE, "level number"
9717 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE, -1,
9718 &menu.setup.button.prev_player, NULL,
9719 SCREEN_CTRL_ID_PREV_PLAYER,
9721 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9722 FALSE, "previous player"
9725 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE, -1,
9726 &menu.setup.button.next_player, NULL,
9727 SCREEN_CTRL_ID_NEXT_PLAYER,
9729 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9730 FALSE, "next player"
9733 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE, -1,
9734 &menu.main.button.insert_solution, NULL,
9735 SCREEN_CTRL_ID_INSERT_SOLUTION,
9736 SCREEN_MASK_MAIN_HAS_SOLUTION,
9738 FALSE, "insert solution tape"
9741 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE, -1,
9742 &menu.main.button.play_solution, NULL,
9743 SCREEN_CTRL_ID_PLAY_SOLUTION,
9744 SCREEN_MASK_MAIN_HAS_SOLUTION,
9746 FALSE, "play solution tape"
9749 IMG_MENU_BUTTON_LEVELSET_INFO, IMG_MENU_BUTTON_LEVELSET_INFO_PRESSED,
9750 IMG_MENU_BUTTON_LEVELSET_INFO_ACTIVE,
9751 &menu.main.button.levelset_info, NULL,
9752 SCREEN_CTRL_ID_LEVELSET_INFO,
9753 SCREEN_MASK_MAIN_HAS_SET_INFO,
9755 FALSE, "show level set info"
9758 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE, -1,
9759 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9760 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9762 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9763 FALSE, "switch ECS/AGA chipset"
9766 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK, -1,
9767 &menu.setup.button.touch_back, NULL,
9768 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9771 TRUE, "previous page"
9774 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT, -1,
9775 &menu.setup.button.touch_next, NULL,
9776 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9782 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2, -1,
9783 &menu.setup.button.touch_back2, NULL,
9784 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9787 TRUE, "previous page"
9790 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2, -1,
9791 &menu.setup.button.touch_next2, NULL,
9792 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9801 int gfx_unpressed, gfx_pressed;
9805 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9808 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9809 -1, -1, // these values are not constant, but can change at runtime
9810 SCREEN_CTRL_ID_SCROLL_UP,
9814 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9815 -1, -1, // these values are not constant, but can change at runtime
9816 SCREEN_CTRL_ID_SCROLL_DOWN,
9823 int gfx_unpressed, gfx_pressed;
9829 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9832 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9833 -1, -1, // these values are not constant, but can change at runtime
9834 -1, -1, // these values are not constant, but can change at runtime
9835 GD_TYPE_SCROLLBAR_VERTICAL,
9836 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9837 "scroll level series vertically"
9849 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9852 IMG_SETUP_INPUT_TEXT,
9853 SCREEN_CTRL_ID_NETWORK_SERVER,
9854 -1, -1, // these values are not constant, but can change at runtime
9855 MAX_SETUP_TEXT_INPUT_LEN,
9856 network_server_hostname,
9857 "Network Server Hostname / IP"
9861 static void CreateScreenMenubuttons(void)
9863 struct GadgetInfo *gi;
9864 unsigned int event_mask;
9867 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9869 struct MenuPosInfo *pos = menubutton_info[i].pos;
9870 int screen_mask = menubutton_info[i].screen_mask;
9871 boolean is_touch_button = menubutton_info[i].is_touch_button;
9872 boolean is_check_button = menubutton_info[i].check_value != NULL;
9873 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9874 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9875 menubutton_info[i].gfx_unpressed);
9876 boolean has_gfx_active = (menubutton_info[i].gfx_active != -1);
9877 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9878 Bitmap *gd_bitmap_unpressed_alt, *gd_bitmap_pressed_alt;
9879 int gfx_unpressed, gfx_pressed;
9880 int gfx_unpressed_alt, gfx_pressed_alt;
9881 int x, y, width, height;
9882 int gd_x1, gd_x2, gd_y1, gd_y2;
9883 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9884 int id = menubutton_info[i].gadget_id;
9885 int type = GD_TYPE_NORMAL_BUTTON;
9886 boolean checked = FALSE;
9888 // do not use touch buttons if overlay touch buttons are disabled
9889 if (is_touch_button && !setup.touch.overlay_buttons)
9892 event_mask = menubutton_info[i].event_mask;
9894 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9895 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9897 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9898 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9900 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9901 gfx_pressed = menubutton_info[i].gfx_pressed;
9902 gfx_unpressed_alt = gfx_unpressed;
9903 gfx_pressed_alt = gfx_pressed;
9907 gfx_unpressed_alt = menubutton_info[i].gfx_active;
9909 type = GD_TYPE_CHECK_BUTTON_2;
9911 if (menubutton_info[i].check_value != NULL)
9912 checked = *menubutton_info[i].check_value;
9915 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9916 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9917 gd_bitmap_unpressed_alt = graphic_info[gfx_unpressed_alt].bitmap;
9918 gd_bitmap_pressed_alt = graphic_info[gfx_pressed_alt].bitmap;
9920 gd_x1 = graphic_info[gfx_unpressed].src_x;
9921 gd_y1 = graphic_info[gfx_unpressed].src_y;
9922 gd_x2 = graphic_info[gfx_pressed].src_x;
9923 gd_y2 = graphic_info[gfx_pressed].src_y;
9925 gd_x1a = graphic_info[gfx_unpressed_alt].src_x;
9926 gd_y1a = graphic_info[gfx_unpressed_alt].src_y;
9927 gd_x2a = graphic_info[gfx_pressed_alt].src_x;
9928 gd_y2a = graphic_info[gfx_pressed_alt].src_y;
9930 if (has_gfx_pressed)
9932 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9933 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9936 if (is_check_button)
9938 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9939 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9940 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9941 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9943 type = GD_TYPE_CHECK_BUTTON;
9945 if (menubutton_info[i].check_value != NULL)
9946 checked = *menubutton_info[i].check_value;
9949 if (is_score_button)
9951 // if x/y set to -1, dynamically place buttons next to title text
9952 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9954 // special compatibility handling for "Snake Bite" graphics set
9955 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9956 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9958 // use "SX" here to center buttons (ignore horizontal draw offset)
9960 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9961 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9962 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9963 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9965 // use "mSY" here to place buttons (respect vertical draw offset)
9967 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9968 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9971 if (id == SCREEN_CTRL_ID_LEVELSET_INFO)
9973 if (pos->x == -1 && pos->y == -1)
9975 // use "SX" here to place button (ignore draw offsets)
9976 x = SX + SXSIZE - 2 * TILESIZE;
9977 y = SY + SYSIZE - 2 * TILESIZE;
9979 // special compatibility handling for "BD2K3" graphics set
9980 if (strPrefix(leveldir_current->identifier, "BD2K3"))
9981 x = SX + TILESIZE + MINI_TILESIZE;
9983 // special compatibility handling for "jue0" graphics set
9984 if (strPrefix(artwork.gfx_current_identifier, "jue0"))
9986 x = SX + SXSIZE - 4 * TILESIZE;
9987 y = SY + SYSIZE - 3 * TILESIZE;
9992 gi = CreateGadget(GDI_CUSTOM_ID, id,
9993 GDI_CUSTOM_TYPE_ID, i,
9994 GDI_IMAGE_ID, gfx_unpressed,
9995 GDI_INFO_TEXT, menubutton_info[i].infotext,
10001 GDI_STATE, GD_BUTTON_UNPRESSED,
10002 GDI_CHECKED, checked,
10003 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10004 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10005 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed_alt, gd_x1a, gd_y1a,
10006 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed_alt, gd_x2a, gd_y2a,
10007 GDI_DIRECT_DRAW, FALSE,
10008 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
10009 GDI_EVENT_MASK, event_mask,
10010 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10014 Fail("cannot create gadget");
10016 screen_gadget[id] = gi;
10020 static void CreateScreenScrollbuttons(void)
10022 struct GadgetInfo *gi;
10023 unsigned int event_mask;
10026 // these values are not constant, but can change at runtime
10027 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
10028 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
10029 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
10030 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
10032 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10034 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10035 int gfx_unpressed, gfx_pressed;
10036 int x, y, width, height;
10037 int gd_x1, gd_x2, gd_y1, gd_y2;
10038 int id = scrollbutton_info[i].gadget_id;
10040 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
10042 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
10043 y = mSY + scrollbutton_info[i].y;
10044 width = SC_SCROLLBUTTON_XSIZE;
10045 height = SC_SCROLLBUTTON_YSIZE;
10047 // correct scrollbar position if placed outside menu (playfield) area
10048 if (x > SX + SC_SCROLL_UP_XPOS)
10049 x = SX + SC_SCROLL_UP_XPOS;
10051 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
10052 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
10053 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
10055 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
10056 gfx_pressed = scrollbutton_info[i].gfx_pressed;
10057 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10058 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10059 gd_x1 = graphic_info[gfx_unpressed].src_x;
10060 gd_y1 = graphic_info[gfx_unpressed].src_y;
10061 gd_x2 = graphic_info[gfx_pressed].src_x;
10062 gd_y2 = graphic_info[gfx_pressed].src_y;
10064 gi = CreateGadget(GDI_CUSTOM_ID, id,
10065 GDI_CUSTOM_TYPE_ID, i,
10066 GDI_IMAGE_ID, gfx_unpressed,
10067 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10071 GDI_HEIGHT, height,
10072 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10073 GDI_STATE, GD_BUTTON_UNPRESSED,
10074 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10075 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10076 GDI_DIRECT_DRAW, FALSE,
10077 GDI_EVENT_MASK, event_mask,
10078 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10082 Fail("cannot create gadget");
10084 screen_gadget[id] = gi;
10088 static void CreateScreenScrollbars(void)
10092 // these values are not constant, but can change at runtime
10093 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10094 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10095 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10096 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10098 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10100 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10101 int gfx_unpressed, gfx_pressed;
10102 int x, y, width, height;
10103 int gd_x1, gd_x2, gd_y1, gd_y2;
10104 struct GadgetInfo *gi;
10105 int items_max, items_visible, item_position;
10106 unsigned int event_mask;
10107 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10108 int id = scrollbar_info[i].gadget_id;
10110 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10112 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10113 y = mSY + scrollbar_info[i].y;
10114 width = scrollbar_info[i].width;
10115 height = scrollbar_info[i].height;
10117 // correct scrollbar position if placed outside menu (playfield) area
10118 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10119 x = SX + SC_SCROLL_VERTICAL_XPOS;
10121 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10122 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10124 items_max = num_page_entries;
10125 items_visible = num_page_entries;
10128 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10129 gfx_pressed = scrollbar_info[i].gfx_pressed;
10130 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10131 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10132 gd_x1 = graphic_info[gfx_unpressed].src_x;
10133 gd_y1 = graphic_info[gfx_unpressed].src_y;
10134 gd_x2 = graphic_info[gfx_pressed].src_x;
10135 gd_y2 = graphic_info[gfx_pressed].src_y;
10137 gi = CreateGadget(GDI_CUSTOM_ID, id,
10138 GDI_CUSTOM_TYPE_ID, i,
10139 GDI_IMAGE_ID, gfx_unpressed,
10140 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10144 GDI_HEIGHT, height,
10145 GDI_TYPE, scrollbar_info[i].type,
10146 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10147 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10148 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10149 GDI_WHEEL_AREA_X, SX,
10150 GDI_WHEEL_AREA_Y, SY,
10151 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10152 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10153 GDI_STATE, GD_BUTTON_UNPRESSED,
10154 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10155 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10156 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10157 GDI_DIRECT_DRAW, FALSE,
10158 GDI_EVENT_MASK, event_mask,
10159 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10163 Fail("cannot create gadget");
10165 screen_gadget[id] = gi;
10169 static void CreateScreenTextInputGadgets(void)
10173 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10175 int graphic = textinput_info[i].graphic;
10176 struct GraphicInfo *gd = &graphic_info[graphic];
10177 int gd_x1 = gd->src_x;
10178 int gd_y1 = gd->src_y;
10179 int gd_x2 = gd->src_x + gd->active_xoffset;
10180 int gd_y2 = gd->src_y + gd->active_yoffset;
10181 struct GadgetInfo *gi;
10182 unsigned int event_mask;
10183 int id = textinput_info[i].gadget_id;
10184 int x = textinput_info[i].x;
10185 int y = textinput_info[i].y;
10187 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10189 gi = CreateGadget(GDI_CUSTOM_ID, id,
10190 GDI_CUSTOM_TYPE_ID, i,
10191 GDI_INFO_TEXT, textinput_info[i].infotext,
10194 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10195 GDI_TEXT_VALUE, textinput_info[i].value,
10196 GDI_TEXT_SIZE, textinput_info[i].size,
10197 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10198 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10199 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10200 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10201 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10202 GDI_DESIGN_WIDTH, gd->width,
10203 GDI_EVENT_MASK, event_mask,
10204 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10205 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10209 Fail("cannot create gadget");
10211 screen_gadget[id] = gi;
10215 void CreateScreenGadgets(void)
10217 CreateScreenMenubuttons();
10219 CreateScreenScrollbuttons();
10220 CreateScreenScrollbars();
10222 CreateScreenTextInputGadgets();
10225 void FreeScreenGadgets(void)
10229 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10230 FreeGadget(screen_gadget[i]);
10233 static void RedrawScreenMenuGadgets(int screen_mask)
10237 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10238 if (screen_mask & menubutton_info[i].screen_mask)
10239 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10242 static void MapScreenMenuGadgets(int screen_mask)
10246 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10247 if (screen_mask & menubutton_info[i].screen_mask)
10248 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10251 static void UnmapScreenMenuGadgets(int screen_mask)
10255 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10257 if (screen_mask & menubutton_info[i].screen_mask)
10259 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10261 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10262 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10263 screen_gadget[menubutton_info[i].gadget_id]->y,
10264 screen_gadget[menubutton_info[i].gadget_id]->width,
10265 screen_gadget[menubutton_info[i].gadget_id]->height);
10270 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10273 MapScreenMenuGadgets(screen_mask);
10275 UnmapScreenMenuGadgets(screen_mask);
10278 static void MapScreenGadgets(int num_entries)
10282 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10285 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10286 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10288 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10289 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10292 static void UnmapScreenGadgets()
10296 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10297 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10299 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10300 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10303 static void MapScreenTreeGadgets(TreeInfo *ti)
10305 MapScreenGadgets(numTreeInfoInGroup(ti));
10308 static void UnmapScreenTreeGadgets(void)
10310 UnmapScreenGadgets();
10313 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10315 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10316 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10317 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10318 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10320 if (pos_1->x == -1 && pos_1->y == -1)
10321 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10323 if (pos_2->x == -1 && pos_2->y == -1)
10324 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10327 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10329 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10330 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10332 // set gadget position dynamically, pre-defined or off-screen
10333 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10334 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10336 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10337 MapGadget(gi); // (needed if deactivated on last score page)
10340 static void HandleScreenGadgets(struct GadgetInfo *gi)
10342 int id = gi->custom_id;
10343 int button = gi->event.button;
10344 int step = (button == MB_LEFTBUTTON ? 1 :
10345 button == MB_MIDDLEBUTTON ? 5 :
10346 button == MB_RIGHTBUTTON ? 10 : 1);
10350 case SCREEN_CTRL_ID_PREV_LEVEL:
10351 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10354 case SCREEN_CTRL_ID_NEXT_LEVEL:
10355 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10358 case SCREEN_CTRL_ID_PREV_LEVEL2:
10359 HandleHallOfFame_SelectLevel(step, -1);
10362 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10363 HandleHallOfFame_SelectLevel(step, +1);
10366 case SCREEN_CTRL_ID_PREV_SCORE:
10367 HandleScoreInfo_SelectScore(step, -1);
10370 case SCREEN_CTRL_ID_NEXT_SCORE:
10371 HandleScoreInfo_SelectScore(step, +1);
10374 case SCREEN_CTRL_ID_PLAY_TAPE:
10375 HandleScoreInfo_PlayTape();
10378 case SCREEN_CTRL_ID_FIRST_LEVEL:
10379 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10382 case SCREEN_CTRL_ID_LAST_LEVEL:
10383 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10386 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10387 CloseDoor(DOOR_CLOSE_2);
10388 SetGameStatus(GAME_MODE_LEVELNR);
10389 DrawChooseLevelNr();
10392 case SCREEN_CTRL_ID_PREV_PLAYER:
10393 HandleSetupScreen_Input_Player(step, -1);
10396 case SCREEN_CTRL_ID_NEXT_PLAYER:
10397 HandleSetupScreen_Input_Player(step, +1);
10400 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10401 InsertSolutionTape();
10404 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10405 PlaySolutionTape();
10408 case SCREEN_CTRL_ID_LEVELSET_INFO:
10409 DrawInfoScreen_FromMainMenu(INFO_MODE_LEVELSET);
10412 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10413 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10417 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10418 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10419 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10420 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10421 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10424 case SCREEN_CTRL_ID_SCROLL_UP:
10425 if (game_status == GAME_MODE_NAMES)
10426 HandleChoosePlayerName(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10427 else if (game_status == GAME_MODE_LEVELS)
10428 HandleChooseLevelSet(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10429 else if (game_status == GAME_MODE_LEVELNR)
10430 HandleChooseLevelNr(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10431 else if (game_status == GAME_MODE_SETUP)
10432 HandleSetupScreen(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10433 else if (game_status == GAME_MODE_INFO)
10434 HandleInfoScreen(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10435 else if (game_status == GAME_MODE_SCORES)
10436 HandleHallOfFame(0, 0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10439 case SCREEN_CTRL_ID_SCROLL_DOWN:
10440 if (game_status == GAME_MODE_NAMES)
10441 HandleChoosePlayerName(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10442 else if (game_status == GAME_MODE_LEVELS)
10443 HandleChooseLevelSet(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10444 else if (game_status == GAME_MODE_LEVELNR)
10445 HandleChooseLevelNr(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10446 else if (game_status == GAME_MODE_SETUP)
10447 HandleSetupScreen(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10448 else if (game_status == GAME_MODE_INFO)
10449 HandleInfoScreen(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10450 else if (game_status == GAME_MODE_SCORES)
10451 HandleHallOfFame(0, 0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10454 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10455 if (game_status == GAME_MODE_NAMES)
10456 HandleChoosePlayerName(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10457 else if (game_status == GAME_MODE_LEVELS)
10458 HandleChooseLevelSet(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10459 else if (game_status == GAME_MODE_LEVELNR)
10460 HandleChooseLevelNr(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10461 else if (game_status == GAME_MODE_SETUP)
10462 HandleSetupScreen(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10463 else if (game_status == GAME_MODE_INFO)
10464 HandleInfoScreen(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10465 else if (game_status == GAME_MODE_SCORES)
10466 HandleHallOfFame(0, 0, 999, gi->event.item_position, MB_MENU_INITIALIZE);
10469 case SCREEN_CTRL_ID_NETWORK_SERVER:
10471 if (!strEqual(gi->textinput.value, ""))
10473 setString(&setup.network_server_hostname, gi->textinput.value);
10475 network.server_host = setup.network_server_hostname;
10479 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10481 network.server_host = NULL;
10484 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10485 network.server_host = NULL;
10487 execSetupGame_setNetworkServerText();
10499 void HandleScreenGadgetKeys(Key key)
10501 if (key == setup.shortcut.tape_play)
10502 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10505 void DumpScreenIdentifiers(void)
10509 Print("Active screen elements on current screen:\n");
10511 for (i = 0; main_controls[i].nr != -1; i++)
10513 struct MainControlInfo *mci = &main_controls[i];
10515 if (mci->button_graphic != -1)
10517 char *token = getTokenFromImageID(mci->button_graphic);
10519 Print("- '%s'\n", token);
10526 boolean DoScreenAction(int image_id)
10530 if (game_status != GAME_MODE_MAIN)
10533 for (i = 0; main_controls[i].nr != -1; i++)
10535 struct MainControlInfo *mci = &main_controls[i];
10536 struct MenuPosInfo *pos = mci->pos_button;
10538 if (mci->button_graphic == image_id)
10540 int x = mSX + pos->x;
10541 int y = mSY + pos->y;
10543 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10552 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10554 // get tree info node of newly added level or artwork set
10555 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10556 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10558 if (tree_node_new == NULL) // should not happen
10561 // if request dialog is active, do nothing
10562 if (game.request_active)
10565 if (game_status == GAME_MODE_MAIN &&
10566 tree_type == TREE_TYPE_LEVEL_DIR)
10568 // when adding new level set in main menu, select it as current level set
10570 // change current level set to newly added level set from zip file
10571 leveldir_current = tree_node_new;
10573 // change current level number to first level of newly added level set
10574 level_nr = leveldir_current->first_level;
10576 // redraw screen to reflect changed level set
10579 // save this level set and level number as last selected level set
10580 SaveLevelSetup_LastSeries();
10581 SaveLevelSetup_SeriesInfo();
10583 else if (game_status == GAME_MODE_LEVELS &&
10584 tree_type == TREE_TYPE_LEVEL_DIR)
10586 // when adding new level set in level set menu, set cursor and update screen
10588 leveldir_current = tree_node_new;
10590 DrawChooseTree(&leveldir_current);
10592 else if (game_status == GAME_MODE_SETUP)
10594 // when adding new artwork set in setup menu, set cursor and update screen
10596 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10597 tree_type == TREE_TYPE_GRAPHICS_DIR)
10599 artwork.gfx_current = tree_node_new;
10601 DrawChooseTree(&artwork.gfx_current);
10603 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10604 tree_type == TREE_TYPE_SOUNDS_DIR)
10606 artwork.snd_current = tree_node_new;
10608 DrawChooseTree(&artwork.snd_current);
10610 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10611 tree_type == TREE_TYPE_MUSIC_DIR)
10613 artwork.mus_current = tree_node_new;
10615 DrawChooseTree(&artwork.mus_current);
10620 static int UploadTapes(void)
10622 SetGameStatus(GAME_MODE_LOADING);
10624 FadeSetEnterScreen();
10625 FadeOut(REDRAW_ALL);
10627 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10629 FadeIn(REDRAW_ALL);
10631 DrawInitTextHead("Uploading tapes");
10633 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10634 global.autoplay_leveldir = "ALL";
10635 global.autoplay_all = TRUE;
10637 int num_tapes_uploaded = AutoPlayTapes();
10639 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10640 global.autoplay_leveldir = NULL;
10641 global.autoplay_all = FALSE;
10643 SetGameStatus(GAME_MODE_MAIN);
10647 return num_tapes_uploaded;
10650 static boolean OfferUploadTapes(void)
10652 if (!Request(setup.has_remaining_tapes ?
10653 "Upload missing tapes to the high score server now?" :
10654 "Upload all your tapes to the high score server now?", REQ_ASK))
10657 // when uploading tapes, make sure that high score server is enabled
10658 runtime.use_api_server = setup.use_api_server = TRUE;
10660 int num_tapes_uploaded = UploadTapes();
10663 if (num_tapes_uploaded < 0)
10665 num_tapes_uploaded = -num_tapes_uploaded - 1;
10667 if (num_tapes_uploaded == 0)
10668 sprintf(message, "Upload failed! No tapes uploaded!");
10669 else if (num_tapes_uploaded == 1)
10670 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10672 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10673 num_tapes_uploaded);
10675 Request(message, REQ_CONFIRM);
10677 // if uploading tapes failed, add tape upload entry to setup menu
10678 setup.provide_uploading_tapes = TRUE;
10679 setup.has_remaining_tapes = TRUE;
10681 SaveSetup_ServerSetup();
10686 if (num_tapes_uploaded == 0)
10687 sprintf(message, "No tapes uploaded!");
10688 else if (num_tapes_uploaded == 1)
10689 sprintf(message, "1 tape uploaded!");
10691 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10693 Request(message, REQ_CONFIRM);
10695 if (num_tapes_uploaded > 0)
10696 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10698 // after all tapes have been uploaded, remove entry from setup menu
10699 setup.provide_uploading_tapes = FALSE;
10700 setup.has_remaining_tapes = FALSE;
10702 SaveSetup_ServerSetup();
10707 static void CheckUploadTapes(void)
10709 if (!setup.ask_for_uploading_tapes)
10712 // after asking for uploading tapes, do not ask again
10713 setup.ask_for_uploading_tapes = FALSE;
10714 setup.ask_for_remaining_tapes = FALSE;
10716 if (directoryExists(getTapeDir(NULL)))
10718 boolean tapes_uploaded = OfferUploadTapes();
10720 if (!tapes_uploaded)
10722 Request(setup.has_remaining_tapes ?
10723 "You can upload missing tapes from the setup menu later!" :
10724 "You can upload your tapes from the setup menu later!",
10730 // if tapes directory does not exist yet, never offer uploading all tapes
10731 setup.provide_uploading_tapes = FALSE;
10734 SaveSetup_ServerSetup();
10737 static void UpgradePlayerUUID(void)
10739 ApiResetUUIDAsThread(getUUID());
10742 static void CheckUpgradePlayerUUID(void)
10744 if (setup.player_version > 1)
10747 UpgradePlayerUUID();
10750 void CheckApiServerTasks(void)
10752 // check if the player's UUID has to be upgraded
10753 CheckUpgradePlayerUUID();
10755 // check if there are any tapes to be uploaded
10756 CheckUploadTapes();