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_RIGHT (menu.right_spacing_info[info_mode])
177 #define MENU_SCREEN_INFO_SPACE_TOP (menu.top_spacing_info[info_mode])
178 #define MENU_SCREEN_INFO_SPACE_BOTTOM (menu.bottom_spacing_info[info_mode])
179 #define MENU_SCREEN_INFO_YSTART MENU_SCREEN_INFO_SPACE_TOP
180 #define MENU_SCREEN_INFO_YSTEP (TILEY + 4)
181 #define MENU_SCREEN_INFO_YBOTTOM (SYSIZE - MENU_SCREEN_INFO_SPACE_BOTTOM)
182 #define MENU_SCREEN_INFO_YSIZE (MENU_SCREEN_INFO_YBOTTOM - \
183 MENU_SCREEN_INFO_YSTART - \
185 #define MAX_INFO_ELEMENTS_IN_ARRAY 128
186 #define MAX_INFO_ELEMENTS_ON_SCREEN (SYSIZE / TILEY)
187 #define MAX_INFO_ELEMENTS MIN(MAX_INFO_ELEMENTS_IN_ARRAY, \
188 MAX_INFO_ELEMENTS_ON_SCREEN)
189 #define STD_INFO_ELEMENTS_ON_SCREEN 10
190 #define DYN_INFO_ELEMENTS_ON_SCREEN (MENU_SCREEN_INFO_YSIZE / \
191 MENU_SCREEN_INFO_YSTEP)
192 #define DEFAULT_INFO_ELEMENTS MIN(STD_INFO_ELEMENTS_ON_SCREEN,\
193 DYN_INFO_ELEMENTS_ON_SCREEN)
194 #define NUM_INFO_ELEMENTS_FROM_CONF \
195 (menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] > 0 ? \
196 menu.list_size_info[GFX_SPECIAL_ARG_INFO_ELEMENTS] : \
197 DEFAULT_INFO_ELEMENTS)
198 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(NUM_INFO_ELEMENTS_FROM_CONF,\
200 #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS)
201 #define MAX_MENU_TEXT_LENGTH_BIG 13
202 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2)
204 // screen gadget identifiers
205 #define SCREEN_CTRL_ID_PREV_LEVEL 0
206 #define SCREEN_CTRL_ID_NEXT_LEVEL 1
207 #define SCREEN_CTRL_ID_PREV_LEVEL2 2
208 #define SCREEN_CTRL_ID_NEXT_LEVEL2 3
209 #define SCREEN_CTRL_ID_PREV_SCORE 4
210 #define SCREEN_CTRL_ID_NEXT_SCORE 5
211 #define SCREEN_CTRL_ID_PLAY_TAPE 6
212 #define SCREEN_CTRL_ID_FIRST_LEVEL 7
213 #define SCREEN_CTRL_ID_LAST_LEVEL 8
214 #define SCREEN_CTRL_ID_LEVEL_NUMBER 9
215 #define SCREEN_CTRL_ID_PREV_PLAYER 10
216 #define SCREEN_CTRL_ID_NEXT_PLAYER 11
217 #define SCREEN_CTRL_ID_INSERT_SOLUTION 12
218 #define SCREEN_CTRL_ID_PLAY_SOLUTION 13
219 #define SCREEN_CTRL_ID_LEVELSET_INFO 14
220 #define SCREEN_CTRL_ID_SWITCH_ECS_AGA 15
221 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE 16
222 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE 17
223 #define SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 18
224 #define SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 19
226 #define NUM_SCREEN_MENUBUTTONS 20
228 #define SCREEN_CTRL_ID_SCROLL_UP 20
229 #define SCREEN_CTRL_ID_SCROLL_DOWN 21
230 #define SCREEN_CTRL_ID_SCROLL_VERTICAL 22
231 #define SCREEN_CTRL_ID_NETWORK_SERVER 23
233 #define NUM_SCREEN_GADGETS 24
235 #define NUM_SCREEN_SCROLLBUTTONS 2
236 #define NUM_SCREEN_SCROLLBARS 1
237 #define NUM_SCREEN_TEXTINPUT 1
239 #define SCREEN_MASK_MAIN (1 << 0)
240 #define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1)
241 #define SCREEN_MASK_MAIN_HAS_SET_INFO (1 << 2)
242 #define SCREEN_MASK_INPUT (1 << 3)
243 #define SCREEN_MASK_TOUCH (1 << 4)
244 #define SCREEN_MASK_TOUCH2 (1 << 5)
245 #define SCREEN_MASK_SCORES (1 << 6)
246 #define SCREEN_MASK_SCORES_INFO (1 << 7)
248 // graphic position and size values for buttons and scrollbars
249 #define SC_MENUBUTTON_XSIZE TILEX
250 #define SC_MENUBUTTON_YSIZE TILEY
252 #define SC_SCROLLBUTTON_XSIZE TILEX
253 #define SC_SCROLLBUTTON_YSIZE TILEY
255 #define SC_SCROLLBAR_XPOS (SXSIZE - SC_SCROLLBUTTON_XSIZE)
257 #define SC_SCROLL_VERTICAL_XSIZE SC_SCROLLBUTTON_XSIZE
258 #define SC_SCROLL_VERTICAL_YSIZE ((MAX_MENU_ENTRIES_ON_SCREEN - 2) * \
259 SC_SCROLLBUTTON_YSIZE)
261 #define SC_SCROLL_UP_XPOS SC_SCROLLBAR_XPOS
262 #define SC_SCROLL_UP_YPOS (2 * SC_SCROLLBUTTON_YSIZE)
264 #define SC_SCROLL_VERTICAL_XPOS SC_SCROLLBAR_XPOS
265 #define SC_SCROLL_VERTICAL_YPOS (SC_SCROLL_UP_YPOS + \
266 SC_SCROLLBUTTON_YSIZE)
268 #define SC_SCROLL_DOWN_XPOS SC_SCROLLBAR_XPOS
269 #define SC_SCROLL_DOWN_YPOS (SC_SCROLL_VERTICAL_YPOS + \
270 SC_SCROLL_VERTICAL_YSIZE)
272 #define SC_BORDER_SIZE 14
275 // forward declarations of internal functions
276 static void HandleScreenGadgets(struct GadgetInfo *);
277 static void HandleSetupScreen_Generic(int, int, int, int, int);
278 static void HandleSetupScreen_Input(int, int, int, int, int);
279 static void CustomizeKeyboard(int);
280 static void ConfigureJoystick(int);
281 static void ConfigureVirtualButtons(void);
282 static void execSetupGame(void);
283 static void execSetupEngines(void);
284 static void execSetupGraphics(void);
285 static void execSetupSound(void);
286 static void execSetupTouch(void);
287 static void execSetupArtwork(void);
288 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
290 static void DrawChoosePlayerName(void);
291 static void DrawChooseLevelSet(void);
292 static void DrawChooseLevelNr(void);
293 static void DrawScoreInfo(int);
294 static void DrawScoreInfo_Content(int);
295 static void DrawInfoScreen(void);
296 static void DrawSetupScreen(void);
297 static void DrawTypeName(void);
299 static void DrawInfoScreen_NotAvailable(char *, char *);
300 static void DrawInfoScreen_HelpAnim(int, int, boolean);
301 static void DrawInfoScreen_HelpText(int, int, int, int);
302 static void HandleInfoScreen_Main(int, int, int, int, int);
303 static void HandleInfoScreen_TitleScreen(int, int, int);
304 static void HandleInfoScreen_Elements(int, int, int);
305 static void HandleInfoScreen_Music(int, int, int);
306 static void HandleInfoScreen_Version(int);
307 static void HandleInfoScreen_Generic(int, int, int);
309 static void ModifyGameSpeedIfNeeded(void);
310 static void DisableVsyncIfNeeded(void);
312 static void RedrawScreenMenuGadgets(int);
313 static void MapScreenMenuGadgets(int);
314 static void UnmapScreenMenuGadgets(int);
315 static void MapScreenGadgets(int);
316 static void UnmapScreenGadgets(void);
317 static void MapScreenTreeGadgets(TreeInfo *);
318 static void UnmapScreenTreeGadgets(void);
320 static void UpdateScreenMenuGadgets(int, boolean);
321 static void AdjustScoreInfoButtons_SelectScore(int, int, int);
322 static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
324 static boolean OfferUploadTapes(void);
325 static void execOfferUploadTapes(void);
327 static void DrawHallOfFame_setScoreEntries(void);
328 static void HandleHallOfFame_SelectLevel(int, int);
329 static char *getHallOfFameRankText(int, int);
330 static char *getHallOfFameScoreText(int, int);
331 static char *getInfoScreenTitle_Generic(void);
332 static int getInfoScreenBackgroundImage_Generic(void);
333 static int getInfoScreenBackgroundSound_Generic(void);
334 static int getInfoScreenBackgroundMusic_Generic(void);
336 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *);
338 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
340 static int info_mode = INFO_MODE_MAIN;
341 static int setup_mode = SETUP_MODE_MAIN;
343 static boolean info_screens_from_main = FALSE;
345 static TreeInfo *window_sizes = NULL;
346 static TreeInfo *window_size_current = NULL;
348 static TreeInfo *scaling_types = NULL;
349 static TreeInfo *scaling_type_current = NULL;
351 static TreeInfo *rendering_modes = NULL;
352 static TreeInfo *rendering_mode_current = NULL;
354 static TreeInfo *vsync_modes = NULL;
355 static TreeInfo *vsync_mode_current = NULL;
357 static TreeInfo *scroll_delays = NULL;
358 static TreeInfo *scroll_delay_current = NULL;
360 static TreeInfo *snapshot_modes = NULL;
361 static TreeInfo *snapshot_mode_current = NULL;
363 static TreeInfo *scores_types = NULL;
364 static TreeInfo *scores_type_current = NULL;
366 static TreeInfo *game_speeds_normal = NULL;
367 static TreeInfo *game_speeds_extended = NULL;
368 static TreeInfo *game_speeds = NULL;
369 static TreeInfo *game_speed_current = NULL;
371 static TreeInfo *volumes_simple = NULL;
372 static TreeInfo *volume_simple_current = NULL;
374 static TreeInfo *volumes_loops = NULL;
375 static TreeInfo *volume_loops_current = NULL;
377 static TreeInfo *volumes_music = NULL;
378 static TreeInfo *volume_music_current = NULL;
380 static TreeInfo *touch_controls = NULL;
381 static TreeInfo *touch_control_current = NULL;
383 static TreeInfo *move_distances = NULL;
384 static TreeInfo *move_distance_current = NULL;
386 static TreeInfo *drop_distances = NULL;
387 static TreeInfo *drop_distance_current = NULL;
389 static TreeInfo *transparencies = NULL;
390 static TreeInfo *transparency_current = NULL;
392 static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } };
393 static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } };
395 static TreeInfo *player_name = NULL;
396 static TreeInfo *player_name_current = NULL;
398 static TreeInfo *level_number = NULL;
399 static TreeInfo *level_number_current = NULL;
401 static TreeInfo *score_entries = NULL;
402 static TreeInfo *score_entry_current = NULL;
404 static struct ValueTextInfo window_sizes_list[] =
409 { 100, "100 % (Default)" },
422 static struct StringValueTextInfo scaling_types_list[] =
424 { SCALING_QUALITY_NEAREST, "Off" },
425 { SCALING_QUALITY_LINEAR, "Linear" },
426 { SCALING_QUALITY_BEST, "Anisotropic" },
431 static struct StringValueTextInfo rendering_modes_list[] =
433 { STR_SPECIAL_RENDERING_OFF, "Off (May show artifacts, fast)" },
434 { STR_SPECIAL_RENDERING_BITMAP, "Bitmap/Texture mode (slower)" },
436 // this mode may work under certain conditions, but does not work on Windows
437 { STR_SPECIAL_RENDERING_TARGET, "Target Texture mode (slower)" },
439 { STR_SPECIAL_RENDERING_DOUBLE, "Double Texture mode (slower)" },
444 static struct StringValueTextInfo vsync_modes_list[] =
446 { STR_VSYNC_MODE_OFF, "Off" },
447 { STR_VSYNC_MODE_NORMAL, "Normal" },
448 { STR_VSYNC_MODE_ADAPTIVE, "Adaptive" },
453 static struct StringValueTextInfo scores_types_list[] =
455 { STR_SCORES_TYPE_LOCAL_ONLY, "Local scores only" },
456 { STR_SCORES_TYPE_SERVER_ONLY, "Server scores only" },
457 { STR_SCORES_TYPE_LOCAL_AND_SERVER, "Local and server scores" },
462 static struct ValueTextInfo game_speeds_list_normal[] =
473 static struct ValueTextInfo game_speeds_list_extended[] =
475 { 1000, "1 fps (Extremely Slow)" },
480 { 29, "35 fps (Original Supaplex)" },
482 { 20, "50 fps (=== Normal Speed ===)" },
483 { 16, "60 fps (60 Hz VSync Speed)" },
484 { 14, "70 fps (Maximum Supaplex)" },
488 { 1, "1000 fps (Extremely Fast)" },
493 static struct ValueTextInfo *game_speeds_list;
495 static struct ValueTextInfo scroll_delays_list[] =
497 { 0, "0 Tiles (No Scroll Delay)" },
500 { 3, "3 Tiles (Default)" },
505 { 8, "8 Tiles (Maximum Scroll Delay)"},
510 static struct StringValueTextInfo snapshot_modes_list[] =
512 { STR_SNAPSHOT_MODE_OFF, "Off" },
513 { STR_SNAPSHOT_MODE_EVERY_STEP, "Every Step" },
514 { STR_SNAPSHOT_MODE_EVERY_MOVE, "Every Move" },
515 { STR_SNAPSHOT_MODE_EVERY_COLLECT, "Every Collect" },
520 static struct ValueTextInfo volumes_list[] =
540 static struct StringValueTextInfo touch_controls_list[] =
542 { TOUCH_CONTROL_OFF, "Off" },
543 { TOUCH_CONTROL_VIRTUAL_BUTTONS, "Virtual Buttons" },
544 { TOUCH_CONTROL_WIPE_GESTURES, "Wipe Gestures" },
545 { TOUCH_CONTROL_FOLLOW_FINGER, "Follow Finger" },
550 static struct ValueTextInfo distances_list[] =
565 static struct ValueTextInfo transparencies_list[] =
567 { 0, "0 % (Opaque)" },
577 { 100, "100 % (Invisible)" },
582 static struct ValueTextInfo grid_sizes_list[] =
618 static int align_xoffset = 0;
619 static int align_yoffset = 0;
621 #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
622 (s) <= GAME_MODE_SETUP ? (s) : \
623 (s) == GAME_MODE_PSEUDO_TYPENAME ? \
625 (s) == GAME_MODE_PSEUDO_TYPENAMES ? \
626 GAME_MODE_NAMES : GAME_MODE_DEFAULT)
628 // (there are no draw offset definitions needed for INFO_MODE_TITLE)
629 #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \
630 (i) <= INFO_MODE_LEVELSET ? (i) : \
633 #define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
634 (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) : \
635 (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
636 (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
637 SETUP_MODE_CHOOSE_ARTWORK : \
638 SETUP_MODE_CHOOSE_OTHER)
640 #define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
641 menu.draw_xoffset[GAME_MODE_INFO] : \
642 menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
643 #define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
644 menu.draw_yoffset[GAME_MODE_INFO] : \
645 menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
646 #define EXTRA_SPACING_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
647 menu.extra_spacing[GAME_MODE_INFO] : \
648 menu.extra_spacing_info[DRAW_MODE_INFO(i)])
650 #define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
651 menu.draw_xoffset[GAME_MODE_SETUP] : \
652 menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
653 #define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
654 menu.draw_yoffset[GAME_MODE_SETUP] : \
655 menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
656 #define EXTRA_SPACING_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
657 menu.extra_spacing[GAME_MODE_SETUP] : \
658 menu.extra_spacing_setup[DRAW_MODE_SETUP(i)])
660 #define EXTRA_SPACING_SCORES(i) (EXTRA_SPACING_INFO(i))
662 #define EXTRA_SPACING_SCOREINFO(i) (menu.extra_spacing[GAME_MODE_SCOREINFO])
664 #define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
665 DRAW_XOFFSET_INFO(info_mode) : \
666 (s) == GAME_MODE_SETUP ? \
667 DRAW_XOFFSET_SETUP(setup_mode) : \
668 menu.draw_xoffset[DRAW_MODE(s)])
669 #define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
670 DRAW_YOFFSET_INFO(info_mode) : \
671 (s) == GAME_MODE_SETUP ? \
672 DRAW_YOFFSET_SETUP(setup_mode) : \
673 menu.draw_yoffset[DRAW_MODE(s)])
674 #define EXTRA_SPACING(s) ((s) == GAME_MODE_INFO ? \
675 EXTRA_SPACING_INFO(info_mode) : \
676 (s) == GAME_MODE_SETUP ? \
677 EXTRA_SPACING_SETUP(setup_mode) : \
678 (s) == GAME_MODE_SCORES ? \
679 EXTRA_SPACING_SCORES(info_mode) : \
680 menu.extra_spacing[DRAW_MODE(s)])
682 #define mSX (SX + DRAW_XOFFSET(game_status))
683 #define mSY (SY + DRAW_YOFFSET(game_status))
685 #define amSX (mSX + align_xoffset)
686 #define amSY (mSY + align_yoffset)
688 #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
689 menu.list_size[game_status] : \
690 MAX_MENU_ENTRIES_ON_SCREEN)
692 #define IN_VIS_MENU(x, y) IN_FIELD(x, y, SCR_FIELDX, \
693 NUM_MENU_ENTRIES_ON_SCREEN)
696 // title display and control definitions
698 #define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
699 2 * MAX_NUM_TITLE_MESSAGES)
701 #define NO_DIRECT_LEVEL_SELECT (-1)
704 static int num_title_screens = 0;
706 struct TitleControlInfo
715 struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
718 // main menu display and control definitions
720 #define MAIN_CONTROL_NAME 0
721 #define MAIN_CONTROL_LEVELS 1
722 #define MAIN_CONTROL_SCORES 2
723 #define MAIN_CONTROL_EDITOR 3
724 #define MAIN_CONTROL_INFO 4
725 #define MAIN_CONTROL_GAME 5
726 #define MAIN_CONTROL_SETUP 6
727 #define MAIN_CONTROL_QUIT 7
728 #define MAIN_CONTROL_PREV_LEVEL 8
729 #define MAIN_CONTROL_NEXT_LEVEL 9
730 #define MAIN_CONTROL_FIRST_LEVEL 10
731 #define MAIN_CONTROL_LAST_LEVEL 11
732 #define MAIN_CONTROL_LEVEL_NUMBER 12
733 #define MAIN_CONTROL_LEVEL_INFO_1 13
734 #define MAIN_CONTROL_LEVEL_INFO_2 14
735 #define MAIN_CONTROL_LEVEL_NAME 15
736 #define MAIN_CONTROL_LEVEL_AUTHOR 16
737 #define MAIN_CONTROL_LEVEL_YEAR 17
738 #define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
739 #define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
740 #define MAIN_CONTROL_LEVEL_TESTED_BY 20
741 #define MAIN_CONTROL_TITLE_1 21
742 #define MAIN_CONTROL_TITLE_2 22
743 #define MAIN_CONTROL_TITLE_3 23
745 static char str_main_text_name[10];
746 static char str_main_text_first_level[10];
747 static char str_main_text_last_level[10];
748 static char str_main_text_level_number[10];
750 static char network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN + 1];
752 static char *main_text_name = str_main_text_name;
753 static char *main_text_first_level = str_main_text_first_level;
754 static char *main_text_last_level = str_main_text_last_level;
755 static char *main_text_level_number = str_main_text_level_number;
756 static char *main_text_levels = "Levelset";
757 static char *main_text_scores = "Hall Of Fame";
758 static char *main_text_editor = "Level Creator";
759 static char *main_text_info = "Info Screen";
760 static char *main_text_game = "Start Game";
761 static char *main_text_setup = "Setup";
762 static char *main_text_quit = "Quit";
763 static char *main_text_level_name = level.name;
764 static char *main_text_level_author = level.author;
765 static char *main_text_level_year = NULL;
766 static char *main_text_level_imported_from = NULL;
767 static char *main_text_level_imported_by = NULL;
768 static char *main_text_level_tested_by = NULL;
769 static char *main_text_title_1 = NULL;
770 static char *main_text_title_2 = NULL;
771 static char *main_text_title_3 = NULL;
773 extern char debug_xsn_mode[];
775 struct MainControlInfo
779 struct MenuPosInfo *pos_button;
782 struct TextPosInfo *pos_text;
785 struct TextPosInfo *pos_input;
789 static struct MainControlInfo main_controls[] =
793 &menu.main.button.name, IMG_MENU_BUTTON_NAME,
794 &menu.main.text.name, &main_text_name,
795 &menu.main.input.name, &setup.player_name,
799 &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
800 &menu.main.text.levels, &main_text_levels,
805 &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
806 &menu.main.text.scores, &main_text_scores,
811 &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
812 &menu.main.text.editor, &main_text_editor,
817 &menu.main.button.info, IMG_MENU_BUTTON_INFO,
818 &menu.main.text.info, &main_text_info,
823 &menu.main.button.game, IMG_MENU_BUTTON_GAME,
824 &menu.main.text.game, &main_text_game,
829 &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
830 &menu.main.text.setup, &main_text_setup,
835 &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
836 &menu.main.text.quit, &main_text_quit,
840 MAIN_CONTROL_PREV_LEVEL,
846 MAIN_CONTROL_NEXT_LEVEL,
852 MAIN_CONTROL_FIRST_LEVEL,
854 &menu.main.text.first_level, &main_text_first_level,
858 MAIN_CONTROL_LAST_LEVEL,
860 &menu.main.text.last_level, &main_text_last_level,
864 MAIN_CONTROL_LEVEL_NUMBER,
866 &menu.main.text.level_number, &main_text_level_number,
870 MAIN_CONTROL_LEVEL_INFO_1,
872 &menu.main.text.level_info_1, NULL,
876 MAIN_CONTROL_LEVEL_INFO_2,
878 &menu.main.text.level_info_2, NULL,
882 MAIN_CONTROL_LEVEL_NAME,
884 &menu.main.text.level_name, &main_text_level_name,
888 MAIN_CONTROL_LEVEL_AUTHOR,
890 &menu.main.text.level_author, &main_text_level_author,
894 MAIN_CONTROL_LEVEL_YEAR,
896 &menu.main.text.level_year, &main_text_level_year,
900 MAIN_CONTROL_LEVEL_IMPORTED_FROM,
902 &menu.main.text.level_imported_from, &main_text_level_imported_from,
906 MAIN_CONTROL_LEVEL_IMPORTED_BY,
908 &menu.main.text.level_imported_by, &main_text_level_imported_by,
912 MAIN_CONTROL_LEVEL_TESTED_BY,
914 &menu.main.text.level_tested_by, &main_text_level_tested_by,
918 MAIN_CONTROL_TITLE_1,
920 &menu.main.text.title_1, &main_text_title_1,
924 MAIN_CONTROL_TITLE_2,
926 &menu.main.text.title_2, &main_text_title_2,
930 MAIN_CONTROL_TITLE_3,
932 &menu.main.text.title_3, &main_text_title_3,
945 static boolean hasLevelSetInfo(void)
947 return (getLevelSetInfoFilename(0) != NULL);
950 static int getTitleScreenGraphic(int nr, boolean initial)
952 return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
955 static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
957 return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
961 static int getTitleScreenGameMode(boolean initial)
963 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
967 static int getTitleMessageGameMode(boolean initial)
969 return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
972 static int getTitleAnimMode(struct TitleControlInfo *tci)
974 int base = (tci->initial ? GAME_MODE_TITLE_INITIAL_1 : GAME_MODE_TITLE_1);
976 return base + tci->local_nr;
980 static int getTitleScreenBackground(boolean initial)
982 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
987 static int getTitleMessageBackground(int nr, boolean initial)
989 return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
993 static int getTitleBackground(int nr, boolean initial, boolean is_image)
995 int base = (is_image ?
996 (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
997 IMG_BACKGROUND_TITLESCREEN_1) :
998 (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
999 IMG_BACKGROUND_TITLEMESSAGE_1));
1000 int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
1001 IMG_BACKGROUND_TITLE);
1002 int graphic_local = base + nr;
1004 if (graphic_info[graphic_local].bitmap != NULL)
1005 return graphic_local;
1007 if (graphic_info[graphic_global].bitmap != NULL)
1008 return graphic_global;
1010 return IMG_UNDEFINED;
1013 static int getTitleSound(struct TitleControlInfo *tci)
1015 boolean is_image = tci->is_image;
1016 int initial = tci->initial;
1017 int nr = tci->local_nr;
1018 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1019 int base = (is_image ?
1020 (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
1021 SND_BACKGROUND_TITLESCREEN_1) :
1022 (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1023 SND_BACKGROUND_TITLEMESSAGE_1));
1024 int sound_global = menu.sound[mode];
1025 int sound_local = base + nr;
1028 Debug("screens:getTitleSound", "%d, %d, %d: %d ['%s'], %d ['%s']",
1029 nr, initial, is_image,
1030 sound_global, getSoundListEntry(sound_global)->filename,
1031 sound_local, getSoundListEntry(sound_local)->filename);
1034 if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
1037 if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
1038 return sound_global;
1040 return SND_UNDEFINED;
1043 static int getTitleMusic(struct TitleControlInfo *tci)
1045 boolean is_image = tci->is_image;
1046 int initial = tci->initial;
1047 int nr = tci->local_nr;
1048 int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
1049 int base = (is_image ?
1050 (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
1051 MUS_BACKGROUND_TITLESCREEN_1) :
1052 (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
1053 MUS_BACKGROUND_TITLEMESSAGE_1));
1054 int music_global = menu.music[mode];
1055 int music_local = base + nr;
1058 Debug("screens:getTitleMusic", "%d, %d, %d: %d ['%s'], %d ['%s']",
1059 nr, initial, is_image,
1060 music_global, getMusicListEntry(music_global)->filename,
1061 music_local, getMusicListEntry(music_local)->filename);
1064 if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
1067 if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
1068 return music_global;
1070 return MUS_UNDEFINED;
1073 static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
1075 boolean is_image = tci->is_image;
1076 boolean initial = tci->initial;
1077 boolean first = tci->first;
1078 int nr = tci->local_nr;
1079 struct TitleMessageInfo tmi;
1080 struct TitleFadingInfo ti;
1082 tmi = (is_image ? (initial ? (first ?
1083 titlescreen_initial_first[nr] :
1084 titlescreen_initial[nr])
1086 titlescreen_first[nr] :
1088 : (initial ? (first ?
1089 titlemessage_initial_first[nr] :
1090 titlemessage_initial[nr])
1092 titlemessage_first[nr] :
1093 titlemessage[nr])));
1095 ti.fade_mode = tmi.fade_mode;
1096 ti.fade_delay = tmi.fade_delay;
1097 ti.post_delay = tmi.post_delay;
1098 ti.auto_delay = tmi.auto_delay;
1099 ti.auto_delay_unit = tmi.auto_delay_unit;
1104 static int compareTitleControlInfo(const void *object1, const void *object2)
1106 const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
1107 const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
1110 if (tci1->initial != tci2->initial)
1111 compare_result = (tci1->initial ? -1 : +1);
1112 else if (tci1->sort_priority != tci2->sort_priority)
1113 compare_result = tci1->sort_priority - tci2->sort_priority;
1114 else if (tci1->is_image != tci2->is_image)
1115 compare_result = (tci1->is_image ? -1 : +1);
1117 compare_result = tci1->local_nr - tci2->local_nr;
1119 return compare_result;
1122 static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
1124 int nr, int sort_priority)
1126 title_controls[num_title_screens].is_image = is_image;
1127 title_controls[num_title_screens].initial = initial;
1128 title_controls[num_title_screens].local_nr = nr;
1129 title_controls[num_title_screens].sort_priority = sort_priority;
1131 title_controls[num_title_screens].first = FALSE; // will be set later
1133 num_title_screens++;
1136 static void InitializeTitleControls_CheckTitleInfo(boolean initial)
1140 for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
1142 int graphic = getTitleScreenGraphic(i, initial);
1143 Bitmap *bitmap = graphic_info[graphic].bitmap;
1144 int sort_priority = graphic_info[graphic].sort_priority;
1147 InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
1150 for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
1152 struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
1153 char *filename = getLevelSetTitleMessageFilename(i, initial);
1154 int sort_priority = tmi->sort_priority;
1156 if (filename != NULL)
1157 InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
1161 static void InitializeTitleControls(boolean show_title_initial)
1163 num_title_screens = 0;
1165 // 1st step: initialize title screens for game start (only when starting)
1166 if (show_title_initial)
1167 InitializeTitleControls_CheckTitleInfo(TRUE);
1169 // 2nd step: initialize title screens for current level set
1170 InitializeTitleControls_CheckTitleInfo(FALSE);
1172 // sort title screens according to sort_priority and title number
1173 qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
1174 compareTitleControlInfo);
1176 // mark first title screen
1177 title_controls[0].first = TRUE;
1180 static boolean visibleMenuPos(struct MenuPosInfo *pos)
1182 return (pos != NULL && pos->x != -1 && pos->y != -1);
1185 static boolean visibleTextPos(struct TextPosInfo *pos)
1187 return (pos != NULL && pos->x != -1 && pos->y != -1);
1190 static void InitializeMainControls(void)
1192 boolean local_team_mode = (!network.enabled && setup.team_mode);
1195 // set main control text values to dynamically determined values
1196 sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
1198 strcpy(main_text_first_level, int2str(leveldir_current->first_level,
1199 menu.main.text.first_level.size));
1200 strcpy(main_text_last_level, int2str(leveldir_current->last_level,
1201 menu.main.text.last_level.size));
1202 strcpy(main_text_level_number, int2str(level_nr,
1203 menu.main.text.level_number.size));
1205 main_text_level_year = leveldir_current->year;
1206 main_text_level_imported_from = leveldir_current->imported_from;
1207 main_text_level_imported_by = leveldir_current->imported_by;
1208 main_text_level_tested_by = leveldir_current->tested_by;
1210 main_text_title_1 = getConfigProgramTitleString();
1211 main_text_title_2 = getConfigProgramCopyrightString();
1212 main_text_title_3 = getConfigProgramCompanyString();
1214 // set main control screen positions to dynamically determined values
1215 for (i = 0; main_controls[i].nr != -1; i++)
1217 struct MainControlInfo *mci = &main_controls[i];
1219 struct MenuPosInfo *pos_button = mci->pos_button;
1220 struct TextPosInfo *pos_text = mci->pos_text;
1221 struct TextPosInfo *pos_input = mci->pos_input;
1222 char *text = (mci->text ? *mci->text : NULL);
1223 char *input = (mci->input ? *mci->input : NULL);
1224 int button_graphic = mci->button_graphic;
1225 int font_text = (pos_text ? pos_text->font : -1);
1226 int font_input = (pos_input ? pos_input->font : -1);
1228 int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
1229 int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
1230 int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
1231 int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
1232 int text_chars = (text != NULL ? strlen(text) : 0);
1233 int input_chars = (input != NULL ? strlen(input) : 0);
1236 (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
1238 (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
1239 int text_width = font_text_width * text_chars;
1240 int text_height = font_text_height;
1241 int input_width = font_input_width * input_chars;
1242 int input_height = font_input_height;
1244 if (nr == MAIN_CONTROL_NAME)
1246 menu.main.input.name.width = input_width;
1247 menu.main.input.name.height = input_height;
1250 if (pos_button != NULL) // (x/y may be -1/-1 here)
1252 pos_button->width = button_width;
1253 pos_button->height = button_height;
1256 if (pos_text != NULL) // (x/y may be -1/-1 here)
1258 // calculate text size -- needed for text alignment
1259 boolean calculate_text_size = (text != NULL);
1261 if (pos_text->width == -1 || calculate_text_size)
1262 pos_text->width = text_width;
1263 if (pos_text->height == -1 || calculate_text_size)
1264 pos_text->height = text_height;
1266 if (visibleMenuPos(pos_button))
1268 if (pos_text->x == -1)
1269 pos_text->x = pos_button->x + pos_button->width;
1270 if (pos_text->y == -1)
1272 pos_button->y + (pos_button->height - pos_text->height) / 2;
1276 if (pos_input != NULL) // (x/y may be -1/-1 here)
1278 if (visibleTextPos(pos_text))
1280 if (pos_input->x == -1)
1281 pos_input->x = pos_text->x + pos_text->width;
1282 if (pos_input->y == -1)
1283 pos_input->y = pos_text->y;
1286 if (pos_input->width == -1)
1287 pos_input->width = input_width;
1288 if (pos_input->height == -1)
1289 pos_input->height = input_height;
1294 static void DrawPressedGraphicThruMask(int dst_x, int dst_y,
1295 int graphic, boolean pressed)
1297 struct GraphicInfo *g = &graphic_info[graphic];
1300 int xoffset = (pressed ? g->pressed_xoffset : 0);
1301 int yoffset = (pressed ? g->pressed_yoffset : 0);
1303 getFixedGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
1305 BlitBitmapMasked(src_bitmap, drawto, src_x + xoffset, src_y + yoffset,
1306 g->width, g->height, dst_x, dst_y);
1309 static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
1310 boolean active_input,
1311 boolean pressed_button)
1315 for (i = 0; main_controls[i].nr != -1; i++)
1317 struct MainControlInfo *mci = &main_controls[i];
1319 if (mci->nr == nr || nr == -1)
1321 struct MenuPosInfo *pos_button = mci->pos_button;
1322 struct TextPosInfo *pos_text = mci->pos_text;
1323 struct TextPosInfo *pos_input = mci->pos_input;
1324 char *text = (mci->text ? *mci->text : NULL);
1325 char *input = (mci->input ? *mci->input : NULL);
1326 int button_graphic = mci->button_graphic;
1327 int font_text = (pos_text ? pos_text->font : -1);
1328 int font_input = (pos_input ? pos_input->font : -1);
1332 button_graphic = BUTTON_ACTIVE(button_graphic);
1333 font_text = FONT_ACTIVE(font_text);
1338 font_input = FONT_ACTIVE(font_input);
1341 if (visibleMenuPos(pos_button))
1343 struct MenuPosInfo *pos = pos_button;
1344 int x = mSX + pos->x;
1345 int y = mSY + pos->y;
1347 DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
1348 DrawPressedGraphicThruMask(x, y, button_graphic, pressed_button);
1351 if (visibleTextPos(pos_text) && text != NULL)
1353 struct TextPosInfo *pos = pos_text;
1354 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1355 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1358 // (check why/if this is needed)
1359 DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
1361 DrawText(x, y, text, font_text);
1364 if (visibleTextPos(pos_input) && input != NULL)
1366 struct TextPosInfo *pos = pos_input;
1367 int x = mSX + ALIGNED_TEXT_XPOS(pos);
1368 int y = mSY + ALIGNED_TEXT_YPOS(pos);
1371 // (check why/if this is needed)
1372 DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
1374 DrawText(x, y, input, font_input);
1380 static void DrawCursorAndText_Main(int nr, boolean active_text,
1381 boolean pressed_button)
1383 DrawCursorAndText_Main_Ext(nr, active_text, FALSE, pressed_button);
1387 static void DrawCursorAndText_Main_Input(int nr, boolean active_text,
1388 boolean pressed_button)
1390 DrawCursorAndText_Main_Ext(nr, active_text, TRUE, pressed_button);
1394 static struct MainControlInfo *getMainControlInfo(int nr)
1398 for (i = 0; main_controls[i].nr != -1; i++)
1399 if (main_controls[i].nr == nr)
1400 return &main_controls[i];
1405 static boolean insideMenuPosRect(struct MenuPosInfo *rect, int x, int y)
1410 int rect_x = ALIGNED_TEXT_XPOS(rect);
1411 int rect_y = ALIGNED_TEXT_YPOS(rect);
1413 return (x >= rect_x && x < rect_x + rect->width &&
1414 y >= rect_y && y < rect_y + rect->height);
1417 static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y)
1422 int rect_x = ALIGNED_TEXT_XPOS(rect);
1423 int rect_y = ALIGNED_TEXT_YPOS(rect);
1426 Debug("screens:insideTextPosRect",
1427 "(%d, %d), (%d, %d) [%d, %d] (%d, %d) => %d",
1428 x, y, rect_x, rect_y, rect->x, rect->y, rect->width, rect->height,
1429 (x >= rect_x && x < rect_x + rect->width &&
1430 y >= rect_y && y < rect_y + rect->height));
1433 return (x >= rect_x && x < rect_x + rect->width &&
1434 y >= rect_y && y < rect_y + rect->height);
1437 static boolean insidePreviewRect(struct PreviewInfo *preview, int x, int y)
1439 int rect_width = preview->xsize * preview->tile_size;
1440 int rect_height = preview->ysize * preview->tile_size;
1441 int rect_x = ALIGNED_XPOS(preview->x, rect_width, preview->align);
1442 int rect_y = ALIGNED_YPOS(preview->y, rect_height, preview->valign);
1444 return (x >= rect_x && x < rect_x + rect_width &&
1445 y >= rect_y && y < rect_y + rect_height);
1448 static void AdjustScrollbar(int id, int items_max, int items_visible,
1451 struct GadgetInfo *gi = screen_gadget[id];
1453 if (item_position > items_max - items_visible)
1454 item_position = items_max - items_visible;
1456 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
1457 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1458 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
1461 static void AdjustChooseTreeScrollbar(TreeInfo *ti, int id)
1463 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN,
1467 static void clearMenuListArea(void)
1469 int scrollbar_xpos = mSX + SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
1471 // correct scrollbar position if placed outside menu (playfield) area
1472 if (scrollbar_xpos > SX + SC_SCROLLBAR_XPOS)
1473 scrollbar_xpos = SX + SC_SCROLLBAR_XPOS;
1475 // clear menu list area, but not title or scrollbar
1476 DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1477 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1479 // special compatibility handling for "Snake Bite" graphics set
1480 if (strPrefix(leveldir_current->identifier, "snake_bite"))
1481 ClearRectangle(drawto, mSX, mSY + MENU_SCREEN_START_YPOS * 32,
1482 scrollbar_xpos - mSX, NUM_MENU_ENTRIES_ON_SCREEN * 32);
1485 static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)
1487 static int cursor_array[MAX_LEV_FIELDY];
1488 int x = amSX + TILEX * xpos;
1489 int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos);
1494 cursor_array[ypos] = graphic;
1496 graphic = cursor_array[ypos];
1500 graphic = BUTTON_ACTIVE(graphic);
1502 DrawBackgroundForGraphic(x, y, TILEX, TILEY, graphic);
1503 DrawFixedGraphicThruMaskExt(drawto, x, y, graphic, 0);
1506 static void initCursor(int ypos, int graphic)
1508 drawCursorExt(0, ypos, FALSE, graphic);
1511 static void drawCursor(int ypos, boolean active)
1513 drawCursorExt(0, ypos, active, -1);
1516 static void drawCursorXY(int xpos, int ypos, int graphic)
1518 drawCursorExt(xpos, ypos, FALSE, graphic);
1521 static void drawChooseTreeCursor(int ypos, boolean active)
1523 drawCursorExt(0, ypos, active, -1);
1526 static int getChooseTreeEditFont(boolean active)
1528 return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2);
1531 static int getChooseTreeEditXPos(int pos)
1533 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
1534 int xoffset = (has_scrollbar ? -1 : 0);
1535 int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset;
1536 int sx = amSX + xpos * TILEX;
1537 int font_nr = getChooseTreeEditFont(FALSE);
1538 int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr);
1540 return (pos == POS_RIGHT ? sx + width - 1 : sx);
1543 static int getChooseTreeEditYPos(int ypos_raw)
1545 int ypos = MENU_SCREEN_START_YPOS + ypos_raw;
1546 int sy = amSY + ypos * TILEY;
1551 static int getChooseTreeEditXPosReal(int pos)
1553 int xpos = getChooseTreeEditXPos(pos);
1554 int font_nr = getChooseTreeEditFont(FALSE);
1555 int font_xoffset = getFontDrawOffsetX(font_nr);
1557 return xpos + font_xoffset;
1560 static void drawChooseTreeEdit(int ypos_raw, boolean active)
1562 int sx = getChooseTreeEditXPos(POS_LEFT);
1563 int sy = getChooseTreeEditYPos(ypos_raw);
1564 int font_nr = getChooseTreeEditFont(active);
1566 DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr);
1569 static void DrawInfoScreen_Headline(int screen_nr, int num_screens,
1570 int use_global_screens)
1572 char *info_text_title_1 = getInfoScreenTitle_Generic();
1573 char info_text_title_2[MAX_LINE_LEN + 1];
1575 if (num_screens > 1)
1577 sprintf(info_text_title_2, "Page %d of %d", screen_nr + 1, num_screens);
1581 char *text_format = (use_global_screens ? "for %s" : "for \"%s\"");
1582 int text_format_len = strlen(text_format) - strlen("%s");
1583 int max_text_len = SXSIZE / getFontWidth(FONT_TITLE_2);
1584 int max_name_len = max_text_len - text_format_len;
1585 char name_cut[max_name_len];
1586 char *name_full = (use_global_screens ? getProgramTitleString() :
1587 leveldir_current->name);
1589 snprintf(name_cut, max_name_len, "%s", name_full);
1590 snprintf(info_text_title_2, max_text_len, text_format, name_cut);
1593 DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, info_text_title_1);
1594 DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, info_text_title_2);
1597 static void DrawTitleScreenImage(int nr, boolean initial)
1599 int graphic = getTitleScreenGraphic(nr, initial);
1600 Bitmap *bitmap = graphic_info[graphic].bitmap;
1601 int draw_masked = graphic_info[graphic].draw_masked;
1602 int width = graphic_info[graphic].width;
1603 int height = graphic_info[graphic].height;
1604 int src_x = graphic_info[graphic].src_x;
1605 int src_y = graphic_info[graphic].src_y;
1611 if (width > WIN_XSIZE)
1613 // image width too large for window => center image horizontally
1614 src_x = (width - WIN_XSIZE) / 2;
1618 if (height > WIN_YSIZE)
1620 // image height too large for window => center image vertically
1621 src_y = (height - WIN_YSIZE) / 2;
1625 // always display title screens centered
1626 dst_x = (WIN_XSIZE - width) / 2;
1627 dst_y = (WIN_YSIZE - height) / 2;
1629 SetDrawBackgroundMask(REDRAW_ALL);
1630 SetWindowBackgroundImage(getTitleBackground(nr, initial, TRUE));
1632 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1634 if (DrawingOnBackground(dst_x, dst_y) && draw_masked)
1635 BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1637 BlitBitmap(bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y);
1639 redraw_mask = REDRAW_ALL;
1642 static void DrawTitleScreenMessage(int nr, boolean initial)
1644 char *filename = getLevelSetTitleMessageFilename(nr, initial);
1645 struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial);
1647 if (filename == NULL)
1650 // force TITLE font on title message screen
1651 SetFontStatus(getTitleMessageGameMode(initial));
1653 // if chars *and* width set to "-1", automatically determine width
1654 if (tmi->chars == -1 && tmi->width == -1)
1655 tmi->width = viewport.window[game_status].width;
1657 // if lines *and* height set to "-1", automatically determine height
1658 if (tmi->lines == -1 && tmi->height == -1)
1659 tmi->height = viewport.window[game_status].height;
1661 // if chars set to "-1", automatically determine by text and font width
1662 if (tmi->chars == -1)
1663 tmi->chars = tmi->width / getFontWidth(tmi->font);
1665 tmi->width = tmi->chars * getFontWidth(tmi->font);
1667 // if lines set to "-1", automatically determine by text and font height
1668 if (tmi->lines == -1)
1669 tmi->lines = tmi->height / getFontHeight(tmi->font);
1671 tmi->height = tmi->lines * getFontHeight(tmi->font);
1673 // if x set to "-1", automatically determine by width and alignment
1675 tmi->x = -1 * ALIGNED_XPOS(0, tmi->width, tmi->align);
1677 // if y set to "-1", automatically determine by height and alignment
1679 tmi->y = -1 * ALIGNED_YPOS(0, tmi->height, tmi->valign);
1681 SetDrawBackgroundMask(REDRAW_ALL);
1682 SetWindowBackgroundImage(getTitleBackground(nr, initial, FALSE));
1684 ClearRectangleOnBackground(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
1686 DrawTextFile(ALIGNED_TEXT_XPOS(tmi), ALIGNED_TEXT_YPOS(tmi),
1687 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
1688 tmi->autowrap, tmi->centered, tmi->parse_comments);
1693 static void DrawTitleScreen(void)
1695 KeyboardAutoRepeatOff();
1697 HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE);
1700 static boolean CheckTitleScreen(boolean levelset_has_changed)
1702 static boolean show_title_initial = TRUE;
1703 boolean show_titlescreen = FALSE;
1705 // needed to be able to skip title screen, if no image or message defined
1706 InitializeTitleControls(show_title_initial);
1708 if (setup.show_titlescreen && (show_title_initial || levelset_has_changed))
1709 show_titlescreen = TRUE;
1711 // show initial title images and messages only once at program start
1712 show_title_initial = FALSE;
1714 return (show_titlescreen && num_title_screens > 0);
1717 void DrawMainMenu(void)
1719 static LevelDirTree *leveldir_last_valid = NULL;
1720 boolean levelset_has_changed = FALSE;
1721 int fade_mask = REDRAW_FIELD;
1723 LimitScreenUpdates(FALSE);
1725 FadeSetLeaveScreen();
1727 // do not fade out here -- function may continue and fade on editor screen
1730 FadeMenuSoundsAndMusic();
1732 ExpireSoundLoops(FALSE);
1734 KeyboardAutoRepeatOn();
1736 audio.sound_deactivated = FALSE;
1740 // needed if last screen was the playing screen, invoked from level editor
1741 if (level_editor_test_game)
1743 CloseDoor(DOOR_CLOSE_ALL);
1745 SetGameStatus(GAME_MODE_EDITOR);
1752 // needed if last screen was the playing screen, invoked from hall of fame
1753 if (score_info_tape_play)
1755 CloseDoor(DOOR_CLOSE_ALL);
1757 SetGameStatus(GAME_MODE_SCOREINFO);
1759 DrawScoreInfo(scores.last_entry_nr);
1764 // reset flag to continue playing next level from hall of fame
1765 scores.continue_playing = FALSE;
1767 // leveldir_current may be invalid (level group, parent link, node copy)
1768 leveldir_current = getValidLevelSeries(leveldir_current, leveldir_last_valid);
1770 if (leveldir_current != leveldir_last_valid)
1772 // level setup config may have been loaded to "last played" tree node copy,
1773 // but "leveldir_current" now points to the "original" level set tree node,
1774 // in which case "handicap_level" may still default to the first level
1775 LoadLevelSetup_SeriesInfo();
1777 UpdateLastPlayedLevels_TreeInfo();
1779 levelset_has_changed = TRUE;
1782 // store valid level series information
1783 leveldir_last_valid = leveldir_current;
1785 // needed if last screen (level choice) changed graphics, sounds or music
1786 ReloadCustomArtwork(0);
1788 if (CheckTitleScreen(levelset_has_changed))
1790 SetGameStatus(GAME_MODE_TITLE);
1797 if (redraw_mask & REDRAW_ALL)
1798 fade_mask = REDRAW_ALL;
1801 fade_mask = REDRAW_ALL;
1805 // needed if different viewport properties defined for menues
1806 ChangeViewportPropertiesIfNeeded();
1808 SetDrawtoField(DRAW_TO_BACKBUFFER);
1810 // level_nr may have been set to value over handicap with level editor
1811 if (setup.handicap && level_nr > leveldir_current->handicap_level)
1812 level_nr = leveldir_current->handicap_level;
1814 LoadLevel(level_nr);
1815 LoadScore(level_nr);
1817 SaveLevelSetup_SeriesInfo();
1819 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
1820 SetDrawDeactivationMask(REDRAW_NONE);
1821 SetDrawBackgroundMask(REDRAW_FIELD);
1823 SetMainBackgroundImage(IMG_BACKGROUND_MAIN);
1826 if (fade_mask == REDRAW_ALL)
1827 RedrawGlobalBorder();
1832 InitializeMainControls();
1834 DrawCursorAndText_Main(-1, FALSE, FALSE);
1835 DrawPreviewLevelInitial();
1836 DrawNetworkPlayers();
1838 HandleMainMenu(0, 0, 0, 0, MB_MENU_INITIALIZE);
1841 if (TAPE_IS_EMPTY(tape))
1843 DrawCompleteVideoDisplay();
1845 PlayMenuSoundsAndMusic();
1847 // create gadgets for main menu screen
1848 FreeScreenGadgets();
1849 CreateScreenGadgets();
1851 // may be required if audio buttons shown on tape and changed in setup menu
1853 CreateGameButtons();
1855 // map gadgets for main menu screen
1857 MapScreenMenuGadgets(SCREEN_MASK_MAIN);
1858 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
1859 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SET_INFO, hasLevelSetInfo());
1861 // copy actual game door content to door double buffer for OpenDoor()
1862 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
1863 BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0);
1865 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
1867 DrawMaskedBorder(fade_mask);
1872 // update screen area with special editor door
1873 redraw_mask |= REDRAW_ALL;
1876 SetMouseCursor(CURSOR_DEFAULT);
1878 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
1880 SyncEmscriptenFilesystem();
1882 // needed once after program start or after user change
1883 CheckApiServerTasks();
1886 static void gotoTopLevelDir(void)
1888 // move upwards until inside (but not above) top level directory
1889 while (leveldir_current->node_parent &&
1890 !strEqual(leveldir_current->node_parent->subdir, STRING_TOP_DIRECTORY))
1892 // write a "path" into level tree for easy navigation to last level
1893 if (leveldir_current->node_parent->node_group->cl_first == -1)
1895 int num_leveldirs = numTreeInfoInGroup(leveldir_current);
1896 int leveldir_pos = getPosFromTreeInfo(leveldir_current);
1897 int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN);
1898 int cl_first, cl_cursor;
1900 cl_first = MAX(0, leveldir_pos - num_page_entries + 1);
1901 cl_cursor = leveldir_pos - cl_first;
1903 leveldir_current->node_parent->node_group->cl_first = cl_first;
1904 leveldir_current->node_parent->node_group->cl_cursor = cl_cursor;
1907 leveldir_current = leveldir_current->node_parent;
1911 static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
1913 boolean use_frame_counter = (fi->auto_delay_unit == AUTO_DELAY_UNIT_FRAMES);
1915 return (use_frame_counter ? video.frame_counter : Counter());
1918 static boolean TitleAutoDelayReached(unsigned int *counter_var,
1919 struct TitleFadingInfo *fi)
1921 return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
1924 static void ResetTitleAutoDelay(unsigned int *counter_var,
1925 struct TitleFadingInfo *fi)
1927 *counter_var = getAutoDelayCounter(fi);
1930 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
1932 static unsigned int title_delay = 0;
1933 static int title_screen_nr = 0;
1934 static int last_sound = -1, last_music = -1;
1935 boolean return_to_main_menu = FALSE;
1936 struct TitleControlInfo *tci;
1939 if (button == MB_MENU_INITIALIZE)
1942 title_screen_nr = 0;
1943 tci = &title_controls[title_screen_nr];
1945 SetAnimStatus(getTitleAnimMode(tci));
1947 last_sound = SND_UNDEFINED;
1948 last_music = MUS_UNDEFINED;
1950 if (num_title_screens != 0)
1952 FadeSetEnterScreen();
1954 // use individual title fading instead of global "enter screen" fading
1955 fading = getTitleFading(tci);
1958 if (game_status_last_screen == GAME_MODE_INFO)
1960 if (num_title_screens == 0)
1962 // switch game mode from title screen mode back to info screen mode
1963 SetGameStatus(GAME_MODE_INFO);
1965 // store that last screen was info screen, not main menu screen
1966 game_status_last_screen = GAME_MODE_INFO;
1968 DrawInfoScreen_NotAvailable("Title screen information:",
1969 "No title screen for this level set.");
1974 FadeMenuSoundsAndMusic();
1976 FadeOut(REDRAW_ALL);
1978 // title screens may have different window size
1979 ChangeViewportPropertiesIfNeeded();
1981 // only required to update logic for redrawing global border
1985 DrawTitleScreenImage(tci->local_nr, tci->initial);
1987 DrawTitleScreenMessage(tci->local_nr, tci->initial);
1989 sound = getTitleSound(tci);
1990 music = getTitleMusic(tci);
1992 if (sound != last_sound)
1993 PlayMenuSoundExt(sound);
1994 if (music != last_music)
1995 PlayMenuMusicExt(music);
2000 SetMouseCursor(CURSOR_NONE);
2004 ResetTitleAutoDelay(&title_delay, &fading);
2009 if (fading.auto_delay > 0 && TitleAutoDelayReached(&title_delay, &fading))
2010 button = MB_MENU_CHOICE;
2012 if (button == MB_MENU_LEAVE)
2014 return_to_main_menu = TRUE;
2016 else if (button == MB_MENU_CHOICE || dx)
2018 if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
2020 SetGameStatus(GAME_MODE_INFO);
2022 info_mode = INFO_MODE_MAIN;
2030 (game_status_last_screen == GAME_MODE_INFO && dx < 0 ? -1 : +1);
2032 if (title_screen_nr >= 0 && title_screen_nr < num_title_screens)
2034 tci = &title_controls[title_screen_nr];
2036 SetAnimStatus(getTitleAnimMode(tci));
2038 sound = getTitleSound(tci);
2039 music = getTitleMusic(tci);
2041 if (last_sound != SND_UNDEFINED && sound != last_sound)
2042 FadeSound(last_sound);
2043 if (last_music != MUS_UNDEFINED && music != last_music)
2046 fading = getTitleFading(tci);
2048 FadeOut(REDRAW_ALL);
2051 DrawTitleScreenImage(tci->local_nr, tci->initial);
2053 DrawTitleScreenMessage(tci->local_nr, tci->initial);
2055 sound = getTitleSound(tci);
2056 music = getTitleMusic(tci);
2058 if (sound != last_sound)
2059 PlayMenuSoundExt(sound);
2060 if (music != last_music)
2061 PlayMenuMusicExt(music);
2068 ResetTitleAutoDelay(&title_delay, &fading);
2072 FadeMenuSoundsAndMusic();
2074 return_to_main_menu = TRUE;
2078 if (return_to_main_menu)
2080 SetMouseCursor(CURSOR_DEFAULT);
2082 // force full menu screen redraw after displaying title screens
2083 redraw_mask = REDRAW_ALL;
2085 if (game_status_last_screen == GAME_MODE_INFO)
2087 SetGameStatus(GAME_MODE_INFO);
2089 info_mode = INFO_MODE_MAIN;
2093 else // default: return to main menu
2095 SetGameStatus(GAME_MODE_MAIN);
2102 static void HandleMainMenu_ToggleTeamMode(void)
2104 setup.team_mode = !setup.team_mode;
2106 InitializeMainControls();
2107 DrawCursorAndText_Main(MAIN_CONTROL_NAME, TRUE, FALSE);
2109 DrawPreviewPlayers();
2112 static void HandleMainMenu_SelectLevel(int step, int direction,
2113 int selected_level_nr)
2115 int old_level_nr = level_nr;
2118 if (selected_level_nr != NO_DIRECT_LEVEL_SELECT)
2119 new_level_nr = selected_level_nr;
2121 new_level_nr = old_level_nr + step * direction;
2123 if (new_level_nr < leveldir_current->first_level)
2124 new_level_nr = leveldir_current->first_level;
2125 if (new_level_nr > leveldir_current->last_level)
2126 new_level_nr = leveldir_current->last_level;
2128 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
2130 // skipping levels is only allowed when trying to skip single level
2131 if (setup.skip_levels && new_level_nr == old_level_nr + 1 &&
2132 Request("Level still unsolved! Skip it anyway?", REQ_ASK))
2134 leveldir_current->handicap_level++;
2135 SaveLevelSetup_SeriesInfo();
2138 new_level_nr = leveldir_current->handicap_level;
2141 if (new_level_nr != old_level_nr)
2143 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_LEVEL_NUMBER);
2145 PlaySound(SND_MENU_ITEM_SELECTING);
2147 level_nr = new_level_nr;
2149 DrawText(mSX + mci->pos_text->x, mSY + mci->pos_text->y,
2150 int2str(level_nr, menu.main.text.level_number.size),
2151 mci->pos_text->font);
2153 LoadLevel(level_nr);
2154 DrawPreviewLevelInitial();
2158 DrawCompleteVideoDisplay();
2160 SaveLevelSetup_SeriesInfo();
2162 UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape());
2164 // force redraw of playfield area (may be reset at this point)
2165 redraw_mask |= REDRAW_FIELD;
2169 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
2171 static int choice = MAIN_CONTROL_GAME;
2172 static boolean button_pressed_last = FALSE;
2173 boolean button_pressed = FALSE;
2175 int i = 0; // needed to prevent compiler warning due to bad code below
2177 if (button == MB_MENU_INITIALIZE)
2179 DrawCursorAndText_Main(choice, TRUE, FALSE);
2184 if (mx || my) // mouse input
2188 for (i = 0; main_controls[i].nr != -1; i++)
2190 if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) ||
2191 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) ||
2192 insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY))
2194 pos = main_controls[i].nr;
2200 // check if level preview was clicked
2201 if (insidePreviewRect(&preview, mx - SX, my - SY))
2202 pos = MAIN_CONTROL_GAME;
2204 // handle pressed/unpressed state for active/inactive menu buttons
2205 // (if pos != -1, "i" contains index position corresponding to "pos")
2207 pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT &&
2208 insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY))
2209 button_pressed = TRUE;
2211 if (button_pressed != button_pressed_last)
2213 DrawCursorAndText_Main(choice, TRUE, button_pressed);
2216 PlaySound(SND_MENU_BUTTON_PRESSING);
2218 PlaySound(SND_MENU_BUTTON_RELEASING);
2221 else if (dx || dy) // keyboard input
2223 if (dx > 0 && (choice == MAIN_CONTROL_INFO ||
2224 choice == MAIN_CONTROL_SETUP))
2225 button = MB_MENU_CHOICE;
2230 if (pos == MAIN_CONTROL_FIRST_LEVEL && !button)
2232 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
2234 else if (pos == MAIN_CONTROL_LAST_LEVEL && !button)
2236 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
2238 else if (pos == MAIN_CONTROL_LEVEL_NUMBER && !button)
2240 CloseDoor(DOOR_CLOSE_2);
2242 SetGameStatus(GAME_MODE_LEVELNR);
2244 DrawChooseLevelNr();
2246 else if (pos >= MAIN_CONTROL_NAME && pos <= MAIN_CONTROL_QUIT)
2252 PlaySound(SND_MENU_ITEM_ACTIVATING);
2254 DrawCursorAndText_Main(choice, FALSE, FALSE);
2255 DrawCursorAndText_Main(pos, TRUE, button_pressed);
2261 if (choice == MAIN_CONTROL_NAME)
2263 // special case: cursor left or right pressed -- toggle team mode
2264 HandleMainMenu_ToggleTeamMode();
2266 else if (choice != MAIN_CONTROL_INFO &&
2267 choice != MAIN_CONTROL_SETUP)
2269 HandleMainMenu_SelectLevel(1, dx, NO_DIRECT_LEVEL_SELECT);
2275 PlaySound(SND_MENU_ITEM_SELECTING);
2277 if (pos == MAIN_CONTROL_NAME)
2280 insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY))
2282 // special case: menu text "name/team" clicked -- toggle team mode
2283 HandleMainMenu_ToggleTeamMode();
2287 if (setup.multiple_users)
2289 CloseDoor(DOOR_CLOSE_2);
2291 SetGameStatus(GAME_MODE_NAMES);
2293 DrawChoosePlayerName();
2297 SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
2303 else if (pos == MAIN_CONTROL_LEVELS)
2307 CloseDoor(DOOR_CLOSE_2);
2309 SetGameStatus(GAME_MODE_LEVELS);
2311 SaveLevelSetup_LastSeries();
2312 SaveLevelSetup_SeriesInfo();
2314 // restore level set if chosen from "last played level set" menu
2315 RestoreLastPlayedLevels(&leveldir_current);
2317 if (setup.internal.choose_from_top_leveldir)
2320 DrawChooseLevelSet();
2323 else if (pos == MAIN_CONTROL_SCORES)
2325 CloseDoor(DOOR_CLOSE_2);
2327 SetGameStatus(GAME_MODE_SCORES);
2329 DrawHallOfFame(level_nr);
2331 else if (pos == MAIN_CONTROL_EDITOR)
2333 if (leveldir_current->readonly &&
2334 setup.editor.show_read_only_warning)
2335 Request("This level is read-only!", REQ_CONFIRM | REQ_STAY_OPEN);
2337 CloseDoor(DOOR_CLOSE_ALL);
2339 SetGameStatus(GAME_MODE_EDITOR);
2341 FadeSetEnterScreen();
2345 else if (pos == MAIN_CONTROL_INFO)
2347 CloseDoor(DOOR_CLOSE_2);
2349 SetGameStatus(GAME_MODE_INFO);
2351 info_mode = INFO_MODE_MAIN;
2355 else if (pos == MAIN_CONTROL_GAME)
2357 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
2359 else if (pos == MAIN_CONTROL_SETUP)
2361 CloseDoor(DOOR_CLOSE_2);
2363 SetGameStatus(GAME_MODE_SETUP);
2365 setup_mode = SETUP_MODE_MAIN;
2369 else if (pos == MAIN_CONTROL_QUIT)
2371 SaveLevelSetup_LastSeries();
2372 SaveLevelSetup_SeriesInfo();
2374 #if defined(PLATFORM_EMSCRIPTEN)
2375 Request("Close the browser window to quit!", REQ_CONFIRM);
2377 if (!setup.ask_on_quit_program ||
2378 Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
2379 SetGameStatus(GAME_MODE_QUIT);
2385 button_pressed_last = button_pressed;
2389 // ============================================================================
2390 // info screen functions
2391 // ============================================================================
2393 static struct TokenInfo *info_info;
2394 static int num_info_info; // number of info entries shown on screen
2395 static int max_info_info; // total number of info entries in list
2397 static void execInfoTitleScreen(void)
2399 info_mode = INFO_MODE_TITLE;
2404 static void execInfoElements(void)
2406 info_mode = INFO_MODE_ELEMENTS;
2411 static void execInfoMusic(void)
2413 info_mode = INFO_MODE_MUSIC;
2418 static void execInfoCredits(void)
2420 info_mode = INFO_MODE_CREDITS;
2425 static void execInfoProgram(void)
2427 info_mode = INFO_MODE_PROGRAM;
2432 static void execInfoVersion(void)
2434 info_mode = INFO_MODE_VERSION;
2439 static void execInfoLevelSet(void)
2441 info_mode = INFO_MODE_LEVELSET;
2446 static void execExitInfo(void)
2448 SetGameStatus(GAME_MODE_MAIN);
2453 static struct TokenInfo info_info_main[] =
2455 { TYPE_ENTER_SCREEN, execInfoTitleScreen, STR_INFO_TITLE },
2456 { TYPE_ENTER_SCREEN, execInfoElements, STR_INFO_ELEMENTS },
2457 { TYPE_ENTER_SCREEN, execInfoMusic, STR_INFO_MUSIC },
2458 { TYPE_ENTER_SCREEN, execInfoCredits, STR_INFO_CREDITS },
2459 { TYPE_ENTER_SCREEN, execInfoProgram, STR_INFO_PROGRAM },
2460 { TYPE_ENTER_SCREEN, execInfoVersion, STR_INFO_VERSION },
2461 { TYPE_ENTER_SCREEN, execInfoLevelSet, STR_INFO_LEVELSET },
2462 { TYPE_EMPTY, NULL, "" },
2463 { TYPE_LEAVE_MENU, execExitInfo, STR_INFO_EXIT },
2468 static int getMenuTextFont(int type)
2470 if (type & (TYPE_SWITCH |
2484 static struct TokenInfo *setup_info;
2485 static struct TokenInfo setup_info_input[];
2487 static struct TokenInfo *menu_info;
2489 static void PlayInfoSound(void)
2491 int info_sound = getInfoScreenBackgroundSound_Generic();
2492 char *next_sound = getSoundInfoEntryFilename(info_sound);
2494 if (next_sound != NULL)
2495 PlayMenuSoundExt(info_sound);
2500 static void PlayInfoSoundIfLoop(void)
2502 int info_sound = getInfoScreenBackgroundSound_Generic();
2503 char *next_sound = getSoundInfoEntryFilename(info_sound);
2505 if (next_sound != NULL)
2506 PlayMenuSoundIfLoopExt(info_sound);
2508 PlayMenuSoundIfLoop();
2511 static void PlayInfoMusic(void)
2513 int info_music = getInfoScreenBackgroundMusic_Generic();
2514 char *curr_music = getCurrentlyPlayingMusicFilename();
2515 char *next_music = getMusicInfoEntryFilename(info_music);
2517 if (next_music != NULL)
2519 // play music if info screen music differs from current music
2520 if (!strEqual(curr_music, next_music))
2521 PlayMenuMusicExt(info_music);
2525 // only needed if info screen was directly invoked from main menu
2530 static void PlayInfoSoundsAndMusic(void)
2536 static void FadeInfoSounds(void)
2541 static void FadeInfoMusic(void)
2543 int info_music = getInfoScreenBackgroundMusic_Generic();
2544 char *curr_music = getCurrentlyPlayingMusicFilename();
2545 char *next_music = getMusicInfoEntryFilename(info_music);
2547 if (next_music != NULL)
2549 // fade music if info screen music differs from current music
2550 if (!strEqual(curr_music, next_music))
2555 static void FadeInfoSoundsAndMusic(void)
2561 static void DrawCursorAndText_Menu_Ext(struct TokenInfo *token_info,
2562 int screen_pos, int menu_info_pos_raw,
2565 int pos = (menu_info_pos_raw < 0 ? screen_pos : menu_info_pos_raw);
2566 struct TokenInfo *ti = &token_info[pos];
2567 int xpos = MENU_SCREEN_START_XPOS;
2568 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
2569 int font_nr = getMenuTextFont(ti->type);
2571 if (setup_mode == SETUP_MODE_INPUT)
2572 font_nr = FONT_MENU_1;
2575 font_nr = FONT_ACTIVE(font_nr);
2577 DrawText(mSX + xpos * 32, mSY + ypos * 32, ti->text, font_nr);
2579 if (ti->type & ~TYPE_SKIP_ENTRY)
2580 drawCursor(screen_pos, active);
2583 static void DrawCursorAndText_Menu(int screen_pos, int menu_info_pos_raw,
2586 DrawCursorAndText_Menu_Ext(menu_info, screen_pos, menu_info_pos_raw, active);
2589 static void DrawCursorAndText_Setup(int screen_pos, int menu_info_pos_raw,
2592 DrawCursorAndText_Menu_Ext(setup_info, screen_pos, menu_info_pos_raw, active);
2595 static char *window_size_text;
2596 static char *scaling_type_text;
2597 static char *network_server_text;
2599 static void drawSetupValue(int, int);
2601 static void drawMenuInfoList(int first_entry, int num_page_entries,
2602 int max_page_entries)
2606 if (first_entry + num_page_entries > max_page_entries)
2609 clearMenuListArea();
2611 for (i = 0; i < num_page_entries; i++)
2613 int menu_info_pos = first_entry + i;
2614 struct TokenInfo *si = &menu_info[menu_info_pos];
2615 void *value_ptr = si->value;
2617 // set some entries to "unchangeable" according to other variables
2618 if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
2619 (value_ptr == &setup.sound_loops && !audio.loops_available) ||
2620 (value_ptr == &setup.sound_music && !audio.music_available) ||
2621 (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
2622 (value_ptr == &window_size_text && !video.window_scaling_available) ||
2623 (value_ptr == &scaling_type_text && !video.window_scaling_available))
2624 si->type |= TYPE_GHOSTED;
2626 if (si->type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
2627 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
2628 else if (si->type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
2629 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
2630 else if (si->type & ~TYPE_SKIP_ENTRY)
2631 initCursor(i, IMG_MENU_BUTTON);
2633 DrawCursorAndText_Menu(i, menu_info_pos, FALSE);
2635 if (si->type & TYPE_STRING)
2639 if (value_ptr == &network_server_text)
2640 gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
2642 if (gadget_id != -1)
2644 struct GadgetInfo *gi = screen_gadget[gadget_id];
2645 int xpos = MENU_SCREEN_START_XPOS;
2646 int ypos = MENU_SCREEN_START_YPOS + i;
2647 int x = mSX + xpos * 32;
2648 int y = mSY + ypos * 32;
2650 ModifyGadget(gi, GDI_X, x, GDI_Y, y, GDI_END);
2654 if (si->type & TYPE_VALUE &&
2655 menu_info == setup_info)
2656 drawSetupValue(i, menu_info_pos);
2660 static void DrawInfoScreen_Main(void)
2662 int fade_mask = REDRAW_FIELD;
2665 // (needed after displaying info sub-screens directly from main menu)
2666 if (info_screens_from_main)
2668 info_screens_from_main = FALSE;
2670 SetGameStatus(GAME_MODE_MAIN);
2677 if (redraw_mask & REDRAW_ALL)
2678 fade_mask = REDRAW_ALL;
2681 fade_mask = REDRAW_ALL;
2684 FadeMenuSoundsAndMusic();
2686 FreeScreenGadgets();
2687 CreateScreenGadgets();
2689 // (needed after displaying title screens which disable auto repeat)
2690 KeyboardAutoRepeatOn();
2692 FadeSetLeaveScreen();
2696 // needed if different viewport properties defined for info screen
2697 ChangeViewportPropertiesIfNeeded();
2699 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
2703 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
2705 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_INFO_MAIN);
2707 info_info = info_info_main;
2709 // use modified info screen info without info screen entries marked as hidden
2710 info_info = getSetupInfoFinal(info_info);
2712 // determine maximal number of info entries that can be displayed on screen
2714 for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
2717 // determine maximal number of info entries available for menu of info screen
2719 for (i = 0; info_info[i].type != 0; i++)
2722 HandleInfoScreen_Main(0, 0, 0, 0, MB_MENU_INITIALIZE);
2724 MapScreenGadgets(max_info_info);
2726 PlayMenuSoundsAndMusic();
2728 DrawMaskedBorder(fade_mask);
2733 static void changeSetupValue(int, int, int);
2735 static void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
2736 int mode, int num_page_entries,
2737 int max_page_entries)
2739 static int num_page_entries_all_last[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2740 static int choice_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2741 static int first_entry_stores[NUM_SPECIAL_GFX_ARGS][MAX_MENU_MODES];
2742 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
2743 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
2744 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
2745 int *num_page_entries_last = num_page_entries_all_last[game_status];
2746 int *choice_store = choice_stores[game_status];
2747 int *first_entry_store = first_entry_stores[game_status];
2748 int choice = choice_store[mode]; // starts with 0
2749 int first_entry = first_entry_store[mode]; // starts with 0
2751 int y = choice - first_entry;
2753 boolean position_set_by_scrollbar = (dx == 999);
2754 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
2757 if (button == MB_MENU_INITIALIZE)
2759 // check if number of menu page entries has changed (may happen by change
2760 // of custom artwork definition value for 'list_size' for this menu screen)
2761 // (in this case, the last menu position most probably has to be corrected)
2762 if (num_page_entries != num_page_entries_last[mode])
2764 choice_store[mode] = first_entry_store[mode] = 0;
2766 choice = first_entry = 0;
2769 num_page_entries_last[mode] = num_page_entries;
2772 // advance to first valid menu entry
2773 while (choice < num_page_entries &&
2774 menu_info[choice].type & TYPE_SKIP_ENTRY)
2777 if (position_set_by_scrollbar)
2778 first_entry = first_entry_store[mode] = dy;
2780 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2781 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2783 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2785 if (choice < first_entry)
2787 choice = first_entry;
2789 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2792 else if (choice > first_entry + num_page_entries - 1)
2794 choice = first_entry + num_page_entries - 1;
2796 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2800 choice_store[mode] = choice;
2802 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2806 else if (button == MB_MENU_LEAVE)
2808 PlaySound(SND_MENU_ITEM_SELECTING);
2810 for (i = 0; i < max_page_entries; i++)
2812 if (menu_info[i].type & TYPE_LEAVE_MENU)
2814 void (*menu_callback_function)(void) = menu_info[i].value;
2818 menu_callback_function();
2820 break; // absolutely needed because function changes 'menu_info'!
2827 if (mx || my) // mouse input
2829 x = (mx - mSX) / 32;
2830 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
2832 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
2834 // move cursor instead of scrolling when already at start/end of list
2835 if (dy == -1 * SCROLL_LINE && first_entry == 0)
2837 else if (dy == +1 * SCROLL_LINE &&
2838 first_entry + num_page_entries == max_page_entries)
2841 // handle scrolling screen one line or page
2843 y + dy > num_page_entries - 1)
2845 boolean redraw = FALSE;
2847 if (ABS(dy) == SCROLL_PAGE)
2848 step = num_page_entries - 1;
2850 if (dy < 0 && first_entry > 0)
2852 // scroll page/line up
2854 first_entry -= step;
2855 if (first_entry < 0)
2860 else if (dy > 0 && first_entry + num_page_entries < max_page_entries)
2862 // scroll page/line down
2864 first_entry += step;
2865 if (first_entry + num_page_entries > max_page_entries)
2866 first_entry = MAX(0, max_page_entries - num_page_entries);
2873 choice += first_entry - first_entry_store[mode];
2875 if (choice < first_entry)
2877 choice = first_entry;
2879 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2882 else if (choice > first_entry + num_page_entries - 1)
2884 choice = first_entry + num_page_entries - 1;
2886 if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2889 else if (menu_info[choice].type & TYPE_SKIP_ENTRY)
2893 if (choice < first_entry ||
2894 choice > first_entry + num_page_entries - 1)
2895 first_entry += SIGN(dy);
2898 first_entry_store[mode] = first_entry;
2899 choice_store[mode] = choice;
2901 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2903 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2905 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2906 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2914 int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
2916 if (menu_info[choice].type & menu_navigation_type ||
2917 menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
2918 menu_info[choice].type & TYPE_YES_NO_AUTO ||
2919 menu_info[choice].type & TYPE_PLAYER)
2920 button = MB_MENU_CHOICE;
2925 // jump to next non-empty menu entry (up or down)
2926 while (first_entry + y > 0 &&
2927 first_entry + y < max_page_entries - 1 &&
2928 menu_info[first_entry + y].type & TYPE_SKIP_ENTRY)
2931 if (!IN_VIS_MENU(x, y))
2933 choice += y - y_old;
2935 if (choice < first_entry)
2936 first_entry = choice;
2937 else if (choice > first_entry + num_page_entries - 1)
2938 first_entry = choice - num_page_entries + 1;
2940 if (first_entry >= 0 &&
2941 first_entry + num_page_entries <= max_page_entries)
2943 first_entry_store[mode] = first_entry;
2945 if (choice < first_entry)
2946 choice = first_entry;
2947 else if (choice > first_entry + num_page_entries - 1)
2948 choice = first_entry + num_page_entries - 1;
2950 choice_store[mode] = choice;
2952 drawMenuInfoList(first_entry, num_page_entries, max_page_entries);
2954 DrawCursorAndText_Menu(choice - first_entry, choice, TRUE);
2956 AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_page_entries,
2957 NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
2964 if (!anyScrollbarGadgetActive() &&
2965 IN_VIS_MENU(x, y) &&
2966 mx < mx_right_border &&
2967 y >= 0 && y < num_page_entries)
2971 if (first_entry + y != choice &&
2972 menu_info[first_entry + y].type & ~TYPE_SKIP_ENTRY)
2974 PlaySound(SND_MENU_ITEM_ACTIVATING);
2976 DrawCursorAndText_Menu(choice - first_entry, choice, FALSE);
2977 DrawCursorAndText_Menu(y, first_entry + y, TRUE);
2979 choice = choice_store[mode] = first_entry + y;
2983 PlaySound(SND_MENU_ITEM_SELECTING);
2985 for (i = 0; menu_info[i].type != 0; i++)
2987 if (menu_info[i].type & TYPE_LEAVE_MENU)
2989 void (*menu_callback_function)(void) = menu_info[i].value;
2993 menu_callback_function();
2995 // absolutely needed because function changes 'menu_info'!
3003 else if (!(menu_info[first_entry + y].type & TYPE_GHOSTED))
3005 PlaySound(SND_MENU_ITEM_SELECTING);
3007 // when selecting key headline, execute function for key value change
3008 if (menu_info[first_entry + y].type & TYPE_KEYTEXT &&
3009 menu_info[first_entry + y + 1].type & TYPE_KEY)
3012 // when selecting string value, execute function for list selection
3013 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3014 menu_info[first_entry + y - 1].type & TYPE_ENTER_LIST)
3017 // when selecting string value, execute function for text input gadget
3018 if (menu_info[first_entry + y].type & TYPE_STRING && y > 0 &&
3019 menu_info[first_entry + y - 1].type & TYPE_TEXT_INPUT)
3022 if (menu_info[first_entry + y].type & TYPE_ENTER_OR_LEAVE)
3024 void (*menu_callback_function)(void) =
3025 menu_info[first_entry + y].value;
3027 FadeSetFromType(menu_info[first_entry + y].type);
3029 menu_callback_function();
3031 else if (menu_info[first_entry + y].type & TYPE_TEXT_INPUT)
3033 void (*gadget_callback_function)(void) =
3034 menu_info[first_entry + y].value;
3036 gadget_callback_function();
3038 else if (menu_info[first_entry + y].type & TYPE_VALUE &&
3039 menu_info == setup_info)
3041 changeSetupValue(y, first_entry + y, dx);
3047 void HandleInfoScreen_Main(int mx, int my, int dx, int dy, int button)
3049 menu_info = info_info;
3051 HandleMenuScreen(mx, my, dx, dy, button,
3052 info_mode, num_info_info, max_info_info);
3055 static int getMenuFontSpacing(int spacing_height, int font_nr)
3057 int font_spacing = getFontHeight(font_nr) + EXTRA_SPACING(game_status);
3059 return (spacing_height < 0 ? ABS(spacing_height) * font_spacing :
3063 static int getMenuTextSpacing(int spacing_height, int font_nr)
3065 return (getMenuFontSpacing(spacing_height, font_nr) +
3066 EXTRA_SPACING(game_status));
3069 static int getMenuTextStep(int spacing_height, int font_nr)
3071 return getFontHeight(font_nr) + getMenuTextSpacing(spacing_height, font_nr);
3074 static int getHeadlineSpacing(void)
3076 // special compatibility handling for "R'n'D jue 2022" game editions
3077 int spacing_check = menu.headline1_spacing[GAME_MODE_SCOREINFO];
3078 int spacing = (game_status == GAME_MODE_SCOREINFO ?
3079 menu.headline1_spacing[GAME_MODE_SCOREINFO] :
3080 menu.headline1_spacing_info[info_mode]);
3081 int font = MENU_INFO_FONT_TITLE;
3083 return (spacing_check != -2 ? getMenuTextStep(spacing, font) : 0);
3086 void DrawInfoScreen_NotAvailable(char *text_title, char *text_error)
3088 int font_error = FONT_TEXT_2;
3089 int font_foot = MENU_INFO_FONT_FOOT;
3090 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3091 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3093 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO);
3095 FadeOut(REDRAW_FIELD);
3099 DrawInfoScreen_Headline(0, 1, FALSE);
3101 DrawTextSCentered(ystart, font_error, text_error);
3102 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3104 FadeIn(REDRAW_FIELD);
3107 void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init)
3109 static int infoscreen_step[MAX_INFO_ELEMENTS_IN_ARRAY];
3110 static int infoscreen_frame[MAX_INFO_ELEMENTS_IN_ARRAY];
3111 int font_foot = MENU_INFO_FONT_FOOT;
3112 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT;
3113 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3114 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3115 int ystep = MENU_SCREEN_INFO_YSTEP;
3116 int element, action, direction;
3124 for (i = 0; i < NUM_INFO_ELEMENTS_ON_SCREEN; i++)
3125 infoscreen_step[i] = infoscreen_frame[i] = 0;
3127 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3133 while (helpanim_info[j].element != HELPANIM_LIST_END)
3135 if (i >= start + NUM_INFO_ELEMENTS_ON_SCREEN ||
3140 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3149 j += infoscreen_step[i - start];
3151 element = helpanim_info[j].element;
3152 action = helpanim_info[j].action;
3153 direction = helpanim_info[j].direction;
3156 element = EL_UNKNOWN;
3158 if (action != -1 && direction != -1)
3159 graphic = el_act_dir2img(element, action, direction);
3160 else if (action != -1)
3161 graphic = el_act2img(element, action);
3162 else if (direction != -1)
3163 graphic = el_dir2img(element, direction);
3165 graphic = el2img(element);
3167 delay = helpanim_info[j++].delay;
3172 if (infoscreen_frame[i - start] == 0)
3175 infoscreen_frame[i - start] = delay - 1;
3179 sync_frame = delay - infoscreen_frame[i - start];
3180 infoscreen_frame[i - start]--;
3183 if (helpanim_info[j].element == HELPANIM_LIST_NEXT)
3185 if (!infoscreen_frame[i - start])
3186 infoscreen_step[i - start] = 0;
3190 if (!infoscreen_frame[i - start])
3191 infoscreen_step[i - start]++;
3192 while (helpanim_info[j].element != HELPANIM_LIST_NEXT)
3198 ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
3200 DrawFixedGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
3201 graphic, sync_frame, USE_MASKING);
3204 DrawInfoScreen_HelpText(element, action, direction, i - start);
3209 redraw_mask |= REDRAW_FIELD;
3214 static char *getHelpText(int element, int action, int direction)
3216 char token[MAX_LINE_LEN];
3218 strcpy(token, element_info[element].token_name);
3221 strcat(token, element_action_info[action].suffix);
3223 if (direction != -1)
3224 strcat(token, element_direction_info[MV_DIR_TO_BIT(direction)].suffix);
3226 return getHashEntry(helptext_info, token);
3229 void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
3231 int font_nr = FONT_INFO_ELEMENTS;
3232 int font_width = getFontWidth(font_nr);
3233 int font_height = getFontHeight(font_nr);
3234 int yoffset = (TILEX - 2 * font_height) / 2;
3235 int xstart = mSX + MENU_SCREEN_INFO_SPACE_LEFT + TILEX + MINI_TILEX;
3236 int ystart = mSY + MENU_SCREEN_INFO_YSTART + yoffset + getHeadlineSpacing();
3237 int ystep = TILEY + 4;
3238 int pad_left = xstart - SX;
3239 int pad_right = MENU_SCREEN_INFO_SPACE_RIGHT;
3240 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
3241 int max_lines_per_text = 2;
3244 if (action != -1 && direction != -1) // element.action.direction
3245 text = getHelpText(element, action, direction);
3247 if (text == NULL && action != -1) // element.action
3248 text = getHelpText(element, action, -1);
3250 if (text == NULL && direction != -1) // element.direction
3251 text = getHelpText(element, -1, direction);
3253 if (text == NULL) // base element
3254 text = getHelpText(element, -1, -1);
3256 if (text == NULL) // not found
3257 text = "No description available";
3259 if (strlen(text) <= max_chars_per_line) // only one line of text
3260 ystart += getFontHeight(font_nr) / 2;
3262 DrawTextBuffer(xstart, ystart + ypos * ystep, text, font_nr,
3263 max_chars_per_line, -1, max_lines_per_text, 0, -1,
3264 TRUE, FALSE, FALSE);
3267 static void DrawInfoScreen_TitleScreen(void)
3269 SetGameStatus(GAME_MODE_TITLE);
3276 void HandleInfoScreen_TitleScreen(int dx, int dy, int button)
3278 HandleTitleScreen(0, 0, dx, dy, button);
3281 static void DrawInfoScreen_Elements(void)
3283 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_ELEMENTS);
3286 FadeInfoSoundsAndMusic();
3288 FadeOut(REDRAW_FIELD);
3293 HandleInfoScreen_Elements(0, 0, MB_MENU_INITIALIZE);
3295 PlayInfoSoundsAndMusic();
3297 FadeIn(REDRAW_FIELD);
3300 void HandleInfoScreen_Elements(int dx, int dy, int button)
3302 static DelayCounter info_delay = { 0 };
3303 static int num_anims;
3304 static int num_pages;
3306 int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
3309 info_delay.value = GameFrameDelay;
3311 if (button == MB_MENU_INITIALIZE)
3313 boolean new_element = TRUE;
3317 for (i = 0; helpanim_info[i].element != HELPANIM_LIST_END; i++)
3319 if (helpanim_info[i].element == HELPANIM_LIST_NEXT)
3321 else if (new_element)
3324 new_element = FALSE;
3328 num_pages = (num_anims + anims_per_page - 1) / anims_per_page;
3332 if (button == MB_MENU_LEAVE)
3334 PlaySound(SND_MENU_ITEM_SELECTING);
3336 info_mode = INFO_MODE_MAIN;
3341 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3343 if (button != MB_MENU_INITIALIZE)
3345 PlaySound(SND_MENU_ITEM_SELECTING);
3347 page += (dx < 0 ? -1 : +1);
3350 if (page < 0 || page >= num_pages)
3352 FadeInfoSoundsAndMusic();
3354 info_mode = INFO_MODE_MAIN;
3360 if (button != MB_MENU_INITIALIZE)
3361 FadeSetNextScreen();
3363 if (button != MB_MENU_INITIALIZE)
3364 FadeOut(REDRAW_FIELD);
3368 DrawInfoScreen_Headline(page, num_pages, TRUE);
3369 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, TRUE);
3371 if (button != MB_MENU_INITIALIZE)
3372 FadeIn(REDRAW_FIELD);
3376 if (DelayReached(&info_delay))
3377 if (page < num_pages)
3378 DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
3380 PlayInfoSoundIfLoop();
3384 static void DrawInfoScreen_Music(void)
3386 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC);
3390 FadeOut(REDRAW_FIELD);
3394 DrawInfoScreen_Headline(0, 1, TRUE);
3398 HandleInfoScreen_Music(0, 0, MB_MENU_INITIALIZE);
3400 FadeIn(REDRAW_FIELD);
3403 void HandleInfoScreen_Music(int dx, int dy, int button)
3405 static struct MusicFileInfo *list = NULL;
3406 static int num_screens = 0;
3407 static int screen_nr = 0;
3408 int font_title = MENU_INFO_FONT_TITLE;
3409 int font_head = MENU_INFO_FONT_HEAD;
3410 int font_text = MENU_INFO_FONT_TEXT;
3411 int font_foot = MENU_INFO_FONT_FOOT;
3412 int spacing_head = menu.headline2_spacing_info[info_mode];
3413 int ystep_head = getMenuTextStep(spacing_head, font_head);
3414 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3415 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3417 if (button == MB_MENU_INITIALIZE)
3419 struct MusicFileInfo *list_ptr = music_file_info;
3424 while (list_ptr != NULL)
3426 list_ptr = list_ptr->next;
3430 list = music_file_info;
3434 FadeMenuSoundsAndMusic();
3438 DrawInfoScreen_Headline(0, 1, TRUE);
3440 DrawTextSCentered(ystart, font_title, "No music info for this level set.");
3441 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3447 if (button == MB_MENU_LEAVE)
3449 PlaySound(SND_MENU_ITEM_SELECTING);
3451 FadeMenuSoundsAndMusic();
3453 info_mode = INFO_MODE_MAIN;
3458 else if (button == MB_MENU_CHOICE || button == MB_MENU_INITIALIZE || dx)
3460 if (button != MB_MENU_INITIALIZE)
3462 PlaySound(SND_MENU_ITEM_SELECTING);
3466 list = (dx < 0 ? list->prev : list->next);
3467 screen_nr += (dx < 0 ? -1 : +1);
3473 FadeMenuSoundsAndMusic();
3475 info_mode = INFO_MODE_MAIN;
3481 FadeMenuSoundsAndMusic();
3483 if (list != music_file_info)
3484 FadeSetNextScreen();
3486 if (button != MB_MENU_INITIALIZE)
3487 FadeOut(REDRAW_FIELD);
3491 DrawInfoScreen_Headline(screen_nr, num_screens, TRUE);
3495 int sound = list->music;
3497 if (IS_LOOP_SOUND(sound))
3498 PlaySoundLoop(sound);
3504 int music = list->music;
3506 if (IS_LOOP_MUSIC(music))
3507 PlayMusicLoop(music);
3512 if (!strEqual(list->title, UNKNOWN_NAME))
3514 if (!strEqual(list->title_header, UNKNOWN_NAME))
3515 DrawTextSCentered(ystart, font_head, list->title_header);
3517 DrawTextSCentered(ystart, font_head, "Track");
3519 ystart += ystep_head;
3521 DrawTextFCentered(ystart, font_text, "\"%s\"", list->title);
3522 ystart += ystep_head;
3525 if (!strEqual(list->artist, UNKNOWN_NAME))
3527 if (!strEqual(list->artist_header, UNKNOWN_NAME))
3528 DrawTextSCentered(ystart, font_head, list->artist_header);
3530 DrawTextSCentered(ystart, font_head, "by");
3532 ystart += ystep_head;
3534 DrawTextFCentered(ystart, font_text, "%s", list->artist);
3535 ystart += ystep_head;
3538 if (!strEqual(list->album, UNKNOWN_NAME))
3540 if (!strEqual(list->album_header, UNKNOWN_NAME))
3541 DrawTextSCentered(ystart, font_head, list->album_header);
3543 DrawTextSCentered(ystart, font_head, "from the album");
3545 ystart += ystep_head;
3547 DrawTextFCentered(ystart, font_text, "\"%s\"", list->album);
3548 ystart += ystep_head;
3551 if (!strEqual(list->year, UNKNOWN_NAME))
3553 if (!strEqual(list->year_header, UNKNOWN_NAME))
3554 DrawTextSCentered(ystart, font_head, list->year_header);
3556 DrawTextSCentered(ystart, font_head, "from the year");
3558 ystart += ystep_head;
3560 DrawTextFCentered(ystart, font_text, "%s", list->year);
3561 ystart += ystep_head;
3564 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_PAGE);
3566 if (button != MB_MENU_INITIALIZE)
3567 FadeIn(REDRAW_FIELD);
3570 if (list != NULL && list->is_sound && IS_LOOP_SOUND(list->music))
3571 PlaySoundLoop(list->music);
3574 static void DrawInfoScreen_Version(void)
3576 int font_head = MENU_INFO_FONT_HEAD;
3577 int font_text = MENU_INFO_FONT_TEXT;
3578 int font_foot = MENU_INFO_FONT_FOOT;
3579 int spacing_head = menu.headline2_spacing_info[info_mode];
3580 int spacing_para = menu.paragraph_spacing_info[info_mode];
3581 int spacing_line = menu.line_spacing_info[info_mode];
3582 int xstep = getFontWidth(font_text);
3583 int ystep_head = getMenuTextStep(spacing_head, font_head);
3584 int ystep_para = getMenuTextStep(spacing_para, font_text);
3585 int ystep_line = getMenuTextStep(spacing_line, font_text);
3586 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3587 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3588 int xstart1 = mSX - SX + 2 * xstep;
3589 int xstart2 = mSX - SX + 18 * xstep;
3590 int xstart3 = mSX - SX + 28 * xstep;
3591 SDL_version sdl_version_compiled;
3592 const SDL_version *sdl_version_linked;
3593 int driver_name_len = 10;
3594 SDL_version sdl_version_linked_ext;
3595 const char *driver_name = NULL;
3597 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION);
3600 FadeInfoSoundsAndMusic();
3602 FadeOut(REDRAW_FIELD);
3606 DrawInfoScreen_Headline(0, 1, TRUE);
3608 DrawTextF(xstart1, ystart, font_head, "Name");
3609 DrawTextF(xstart2, ystart, font_text, getProgramTitleString());
3610 ystart += ystep_line;
3612 if (!strEqual(getProgramVersionString(), getProgramRealVersionString()))
3614 DrawTextF(xstart1, ystart, font_head, "Version (fake)");
3615 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3616 ystart += ystep_line;
3618 DrawTextF(xstart1, ystart, font_head, "Version (real)");
3619 DrawTextF(xstart2, ystart, font_text, getProgramRealVersionString());
3620 ystart += ystep_line;
3624 DrawTextF(xstart1, ystart, font_head, "Version");
3625 DrawTextF(xstart2, ystart, font_text, getProgramVersionString());
3626 ystart += ystep_line;
3629 DrawTextF(xstart1, ystart, font_head, "Platform");
3630 DrawTextF(xstart2, ystart, font_text, "%s (%s)",
3632 PLATFORM_XX_BIT_STRING);
3633 ystart += ystep_line;
3635 DrawTextF(xstart1, ystart, font_head, "Target");
3636 DrawTextF(xstart2, ystart, font_text, TARGET_STRING);
3637 ystart += ystep_line;
3639 DrawTextF(xstart1, ystart, font_head, "Source date");
3640 DrawTextF(xstart2, ystart, font_text, getSourceDateString());
3641 ystart += ystep_line;
3643 DrawTextF(xstart1, ystart, font_head, "Commit hash");
3644 DrawTextF(xstart2, ystart, font_text, getSourceHashString());
3645 ystart += ystep_para;
3647 DrawTextF(xstart1, ystart, font_head, "Library");
3648 DrawTextF(xstart2, ystart, font_head, "compiled");
3649 DrawTextF(xstart3, ystart, font_head, "linked");
3650 ystart += ystep_head;
3652 SDL_VERSION(&sdl_version_compiled);
3653 SDL_GetVersion(&sdl_version_linked_ext);
3654 sdl_version_linked = &sdl_version_linked_ext;
3656 DrawTextF(xstart1, ystart, font_text, "SDL");
3657 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3658 sdl_version_compiled.major,
3659 sdl_version_compiled.minor,
3660 sdl_version_compiled.patch);
3661 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3662 sdl_version_linked->major,
3663 sdl_version_linked->minor,
3664 sdl_version_linked->patch);
3665 ystart += ystep_line;
3667 SDL_IMAGE_VERSION(&sdl_version_compiled);
3668 sdl_version_linked = IMG_Linked_Version();
3670 DrawTextF(xstart1, ystart, font_text, "SDL_image");
3671 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3672 sdl_version_compiled.major,
3673 sdl_version_compiled.minor,
3674 sdl_version_compiled.patch);
3675 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3676 sdl_version_linked->major,
3677 sdl_version_linked->minor,
3678 sdl_version_linked->patch);
3679 ystart += ystep_line;
3681 SDL_MIXER_VERSION(&sdl_version_compiled);
3682 sdl_version_linked = Mix_Linked_Version();
3684 DrawTextF(xstart1, ystart, font_text, "SDL_mixer");
3685 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3686 sdl_version_compiled.major,
3687 sdl_version_compiled.minor,
3688 sdl_version_compiled.patch);
3689 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3690 sdl_version_linked->major,
3691 sdl_version_linked->minor,
3692 sdl_version_linked->patch);
3693 ystart += ystep_line;
3695 SDL_NET_VERSION(&sdl_version_compiled);
3696 sdl_version_linked = SDLNet_Linked_Version();
3698 DrawTextF(xstart1, ystart, font_text, "SDL_net");
3699 DrawTextF(xstart2, ystart, font_text, "%d.%d.%d",
3700 sdl_version_compiled.major,
3701 sdl_version_compiled.minor,
3702 sdl_version_compiled.patch);
3703 DrawTextF(xstart3, ystart, font_text, "%d.%d.%d",
3704 sdl_version_linked->major,
3705 sdl_version_linked->minor,
3706 sdl_version_linked->patch);
3707 ystart += ystep_para;
3709 DrawTextF(xstart1, ystart, font_head, "Driver");
3710 DrawTextF(xstart2, ystart, font_head, "Requested");
3711 DrawTextF(xstart3, ystart, font_head, "Used");
3712 ystart += ystep_head;
3715 getStringCopyNStatic(SDLGetRendererName(), driver_name_len);
3717 DrawTextF(xstart1, ystart, font_text, "Render Driver");
3718 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_renderdriver);
3719 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3720 ystart += ystep_line;
3723 getStringCopyNStatic(SDL_GetCurrentVideoDriver(), driver_name_len);
3725 DrawTextF(xstart1, ystart, font_text, "Video Driver");
3726 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_videodriver);
3727 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3728 ystart += ystep_line;
3731 getStringCopyNStatic(SDL_GetCurrentAudioDriver(), driver_name_len);
3733 DrawTextF(xstart1, ystart, font_text, "Audio Driver");
3734 DrawTextF(xstart2, ystart, font_text, "%s", setup.system.sdl_audiodriver);
3735 DrawTextF(xstart3, ystart, font_text, "%s", driver_name);
3737 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3739 PlayInfoSoundsAndMusic();
3741 FadeIn(REDRAW_FIELD);
3744 void HandleInfoScreen_Version(int button)
3746 if (button == MB_MENU_LEAVE)
3748 PlaySound(SND_MENU_ITEM_SELECTING);
3750 info_mode = INFO_MODE_MAIN;
3755 else if (button == MB_MENU_CHOICE)
3757 PlaySound(SND_MENU_ITEM_SELECTING);
3759 FadeMenuSoundsAndMusic();
3761 info_mode = INFO_MODE_MAIN;
3766 PlayMenuSoundIfLoop();
3770 static char *getInfoScreenTitle_Generic(void)
3772 return (info_mode == INFO_MODE_MAIN ? STR_INFO_MAIN :
3773 info_mode == INFO_MODE_TITLE ? STR_INFO_TITLE :
3774 info_mode == INFO_MODE_ELEMENTS ? STR_INFO_ELEMENTS :
3775 info_mode == INFO_MODE_MUSIC ? STR_INFO_MUSIC :
3776 info_mode == INFO_MODE_CREDITS ? STR_INFO_CREDITS :
3777 info_mode == INFO_MODE_PROGRAM ? STR_INFO_PROGRAM :
3778 info_mode == INFO_MODE_VERSION ? STR_INFO_VERSION :
3779 info_mode == INFO_MODE_LEVELSET ? STR_INFO_LEVELSET :
3783 static int getInfoScreenBackgroundImage_Generic(void)
3785 return (info_mode == INFO_MODE_ELEMENTS ? IMG_BACKGROUND_INFO_ELEMENTS :
3786 info_mode == INFO_MODE_MUSIC ? IMG_BACKGROUND_INFO_MUSIC :
3787 info_mode == INFO_MODE_CREDITS ? IMG_BACKGROUND_INFO_CREDITS :
3788 info_mode == INFO_MODE_PROGRAM ? IMG_BACKGROUND_INFO_PROGRAM :
3789 info_mode == INFO_MODE_VERSION ? IMG_BACKGROUND_INFO_VERSION :
3790 info_mode == INFO_MODE_LEVELSET ? IMG_BACKGROUND_INFO_LEVELSET :
3791 IMG_BACKGROUND_INFO);
3794 static int getInfoScreenBackgroundSound_Generic(void)
3796 return (info_mode == INFO_MODE_ELEMENTS ? SND_BACKGROUND_INFO_ELEMENTS :
3797 info_mode == INFO_MODE_CREDITS ? SND_BACKGROUND_INFO_CREDITS :
3798 info_mode == INFO_MODE_PROGRAM ? SND_BACKGROUND_INFO_PROGRAM :
3799 info_mode == INFO_MODE_VERSION ? SND_BACKGROUND_INFO_VERSION :
3800 info_mode == INFO_MODE_LEVELSET ? SND_BACKGROUND_INFO_LEVELSET :
3801 SND_BACKGROUND_INFO);
3804 static int getInfoScreenBackgroundMusic_Generic(void)
3806 return (info_mode == INFO_MODE_ELEMENTS ? MUS_BACKGROUND_INFO_ELEMENTS :
3807 info_mode == INFO_MODE_CREDITS ? MUS_BACKGROUND_INFO_CREDITS :
3808 info_mode == INFO_MODE_PROGRAM ? MUS_BACKGROUND_INFO_PROGRAM :
3809 info_mode == INFO_MODE_VERSION ? MUS_BACKGROUND_INFO_VERSION :
3810 info_mode == INFO_MODE_LEVELSET ? MUS_BACKGROUND_INFO_LEVELSET :
3811 MUS_BACKGROUND_INFO);
3814 static char *getInfoScreenFilename_Generic(int nr, boolean global)
3816 return (info_mode == INFO_MODE_CREDITS ? getCreditsFilename(nr, global) :
3817 info_mode == INFO_MODE_PROGRAM ? getProgramInfoFilename(nr) :
3818 info_mode == INFO_MODE_LEVELSET ? getLevelSetInfoFilename(nr) :
3822 static void DrawInfoScreen_GenericScreen(int screen_nr, int num_screens,
3823 int use_global_screens)
3825 char *filename = getInfoScreenFilename_Generic(screen_nr, use_global_screens);
3826 int font_text = MENU_INFO_FONT_TEXT;
3827 int font_foot = MENU_INFO_FONT_FOOT;
3828 int spacing_line = menu.line_spacing_info[info_mode];
3829 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3833 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3835 if (info_mode == INFO_MODE_CREDITS ||
3836 info_mode == INFO_MODE_PROGRAM)
3839 int height = MENU_SCREEN_INFO_YBOTTOM - MENU_SCREEN_INFO_YSTART;
3840 int chars = width / getFontWidth(font_text);
3841 int lines = height / getFontHeight(font_text);
3842 int padx = (width - chars * getFontWidth(font_text)) / 2;
3843 int line_spacing = getMenuTextSpacing(spacing_line, font_text);
3844 int xstart = mSX + padx;
3845 int ystart = mSY + MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3846 boolean autowrap = FALSE;
3847 boolean centered = TRUE;
3848 boolean parse_comments = TRUE;
3850 DrawTextFile(xstart, ystart,
3851 filename, font_text, chars, -1, lines, line_spacing, -1,
3852 autowrap, centered, parse_comments);
3854 else if (info_mode == INFO_MODE_LEVELSET)
3856 struct TitleMessageInfo *tmi = &readme;
3858 // if x position set to "-1", automatically determine by playfield width
3860 tmi->x = SXSIZE / 2;
3862 // if y position set to "-1", use static default value
3864 tmi->y = MENU_SCREEN_INFO_YSTART + getHeadlineSpacing();
3866 // if width set to "-1", automatically determine by playfield width
3867 if (tmi->width == -1)
3868 tmi->width = SXSIZE - 2 * TILEX;
3870 // if height set to "-1", automatically determine by playfield height
3871 if (tmi->height == -1)
3872 tmi->height = MENU_SCREEN_INFO_YBOTTOM - tmi->y - 10;
3874 // if chars set to "-1", automatically determine by text and font width
3875 if (tmi->chars == -1)
3876 tmi->chars = tmi->width / getFontWidth(tmi->font);
3878 tmi->width = tmi->chars * getFontWidth(tmi->font);
3880 // if lines set to "-1", automatically determine by text and font height
3881 if (tmi->lines == -1)
3882 tmi->lines = tmi->height / getFontHeight(tmi->font);
3884 tmi->height = tmi->lines * getFontHeight(tmi->font);
3886 DrawTextFile(mSX + ALIGNED_TEXT_XPOS(tmi), mSY + ALIGNED_TEXT_YPOS(tmi),
3887 filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
3888 tmi->autowrap, tmi->centered, tmi->parse_comments);
3891 boolean last_screen = (screen_nr == num_screens - 1);
3892 char *text_foot = (last_screen ? TEXT_NEXT_MENU : TEXT_NEXT_PAGE);
3894 DrawTextSCentered(ybottom, font_foot, text_foot);
3897 static void DrawInfoScreen_Generic(void)
3899 SetMainBackgroundImageIfDefined(getInfoScreenBackgroundImage_Generic());
3902 FadeInfoSoundsAndMusic();
3904 FadeOut(REDRAW_FIELD);
3906 HandleInfoScreen_Generic(0, 0, MB_MENU_INITIALIZE);
3908 PlayInfoSoundsAndMusic();
3910 FadeIn(REDRAW_FIELD);
3913 void HandleInfoScreen_Generic(int dx, int dy, int button)
3915 static char *text_no_info = "";
3916 static int num_screens = 0;
3917 static int screen_nr = 0;
3918 static boolean use_global_screens = FALSE;
3920 if (button == MB_MENU_INITIALIZE)
3925 if (info_mode == INFO_MODE_CREDITS)
3929 for (i = 0; i < 2; i++)
3931 use_global_screens = i; // check for "FALSE", then "TRUE"
3933 // determine number of (global or level set specific) credits screens
3934 while (getCreditsFilename(num_screens, use_global_screens) != NULL)
3937 if (num_screens > 0)
3941 text_no_info = "No credits available.";
3943 else if (info_mode == INFO_MODE_PROGRAM)
3945 use_global_screens = TRUE;
3947 // determine number of program info screens
3948 while (getProgramInfoFilename(num_screens) != NULL)
3951 text_no_info = "No program info available.";
3953 else if (info_mode == INFO_MODE_LEVELSET)
3955 use_global_screens = FALSE;
3957 // determine number of levelset info screens
3958 while (getLevelSetInfoFilename(num_screens) != NULL)
3961 text_no_info = "No level set info available.";
3964 if (num_screens == 0)
3966 int font_title = MENU_INFO_FONT_TITLE;
3967 int font_foot = MENU_INFO_FONT_FOOT;
3968 int ystart = mSY - SY + MENU_SCREEN_INFO_YSTART;
3969 int ybottom = mSY - SY + MENU_SCREEN_INFO_YBOTTOM;
3973 DrawInfoScreen_Headline(screen_nr, num_screens, use_global_screens);
3975 DrawTextSCentered(ystart, font_title, text_no_info);
3976 DrawTextSCentered(ybottom, font_foot, TEXT_NEXT_MENU);
3981 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
3983 else if (button == MB_MENU_LEAVE)
3985 PlaySound(SND_MENU_ITEM_SELECTING);
3987 info_mode = INFO_MODE_MAIN;
3990 else if (button == MB_MENU_CHOICE || dx)
3992 PlaySound(SND_MENU_ITEM_SELECTING);
3994 screen_nr += (dx < 0 ? -1 : +1);
3996 if (screen_nr < 0 || screen_nr >= num_screens)
3998 FadeInfoSoundsAndMusic();
4000 info_mode = INFO_MODE_MAIN;
4005 FadeSetNextScreen();
4007 FadeOut(REDRAW_FIELD);
4009 DrawInfoScreen_GenericScreen(screen_nr, num_screens, use_global_screens);
4011 FadeIn(REDRAW_FIELD);
4016 PlayInfoSoundIfLoop();
4020 static void DrawInfoScreen(void)
4022 if (info_mode == INFO_MODE_TITLE)
4023 DrawInfoScreen_TitleScreen();
4024 else if (info_mode == INFO_MODE_ELEMENTS)
4025 DrawInfoScreen_Elements();
4026 else if (info_mode == INFO_MODE_MUSIC)
4027 DrawInfoScreen_Music();
4028 else if (info_mode == INFO_MODE_CREDITS)
4029 DrawInfoScreen_Generic();
4030 else if (info_mode == INFO_MODE_PROGRAM)
4031 DrawInfoScreen_Generic();
4032 else if (info_mode == INFO_MODE_VERSION)
4033 DrawInfoScreen_Version();
4034 else if (info_mode == INFO_MODE_LEVELSET)
4035 DrawInfoScreen_Generic();
4037 DrawInfoScreen_Main();
4040 void DrawInfoScreen_FromMainMenu(int nr)
4042 int fade_mask = REDRAW_FIELD;
4044 if (nr < INFO_MODE_MAIN || nr >= MAX_INFO_MODES)
4047 CloseDoor(DOOR_CLOSE_2);
4049 SetGameStatus(GAME_MODE_INFO);
4052 info_screens_from_main = TRUE;
4054 if (redraw_mask & REDRAW_ALL)
4055 fade_mask = REDRAW_ALL;
4058 fade_mask = REDRAW_ALL;
4061 FadeMenuSoundsAndMusic();
4063 FadeSetEnterScreen();
4067 FadeSkipNextFadeOut();
4069 // needed if different viewport properties defined for info screen
4070 ChangeViewportPropertiesIfNeeded();
4072 SetMainBackgroundImage(IMG_BACKGROUND_INFO);
4077 void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
4079 if (info_mode == INFO_MODE_TITLE)
4080 HandleInfoScreen_TitleScreen(dx, dy, button);
4081 else if (info_mode == INFO_MODE_ELEMENTS)
4082 HandleInfoScreen_Elements(dx, dy, button);
4083 else if (info_mode == INFO_MODE_MUSIC)
4084 HandleInfoScreen_Music(dx, dy, button);
4085 else if (info_mode == INFO_MODE_CREDITS)
4086 HandleInfoScreen_Generic(dx, dy, button);
4087 else if (info_mode == INFO_MODE_PROGRAM)
4088 HandleInfoScreen_Generic(dx, dy, button);
4089 else if (info_mode == INFO_MODE_VERSION)
4090 HandleInfoScreen_Version(button);
4091 else if (info_mode == INFO_MODE_LEVELSET)
4092 HandleInfoScreen_Generic(dx, dy, button);
4094 HandleInfoScreen_Main(mx, my, dx, dy, button);
4098 // ============================================================================
4099 // type name functions
4100 // ============================================================================
4102 static TreeInfo *type_name_node = NULL;
4103 static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4104 static int type_name_nr = 0;
4106 static int getPlayerNameColor(char *name)
4108 return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
4111 static void drawTypeNameText(char *name, struct TextPosInfo *pos,
4114 char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
4115 boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
4116 int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4117 int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
4118 int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
4119 int font_width = getFontWidth(font_nr);
4120 int font_xoffset = getFontDrawOffsetX(font_nr);
4121 int font_yoffset = getFontDrawOffsetY(font_nr);
4122 int font_sx = sx + font_xoffset;
4123 int font_sy = sy + font_yoffset;
4125 DrawBackgroundForFont(font_sx, font_sy, pos->width, pos->height, font_nr);
4127 sprintf(text, "%s%c", name, (active ? '_' : '\0'));
4129 pos->width = strlen(text) * font_width;
4130 sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
4132 DrawText(sx, sy, text, font_nr);
4135 static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
4137 struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
4139 *pos = *mci->pos_input;
4141 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4143 TreeInfo *ti = player_name_current;
4144 int first_entry = ti->cl_first;
4145 int entry_pos = first_entry + ti->cl_cursor;
4146 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4147 int xpos = MENU_SCREEN_START_XPOS;
4148 int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
4150 type_name_node = getTreeInfoFromPos(node_first, entry_pos);
4151 type_name_nr = entry_pos;
4153 strcpy(name, type_name_node->name);
4157 pos->width = MAX_PLAYER_NAME_LEN * 32;
4161 type_name_nr = user.nr;
4163 strcpy(name, setup.player_name);
4166 strcpy(type_name_last, name);
4168 if (strEqual(name, EMPTY_PLAYER_NAME))
4171 *xpos = strlen(name);
4174 static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
4176 // change name of edited user in global list of user names
4177 setString(&global.user_names[type_name_nr], name);
4179 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4181 TreeInfo *node = type_name_node;
4183 // change name of edited user in local menu tree structure
4184 setString(&node->name, name);
4185 setString(&node->name_sorting, name);
4187 node->color = getPlayerNameColor(name);
4188 pos->font = MENU_CHOOSE_TREE_FONT(node->color);
4192 static void setTypeNameValues(char *name, struct TextPosInfo *pos,
4195 boolean reset_setup = strEqual(name, "");
4196 boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
4197 boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
4200 strcpy(name, type_name_last);
4202 if (strEqual(name, ""))
4203 strcpy(name, EMPTY_PLAYER_NAME);
4205 setTypeNameValues_Name(name, pos);
4207 // if player name not changed, no further action required
4208 if (strEqual(name, type_name_last))
4211 // redraw player name before (possibly) opening request dialogs
4212 drawTypeNameText(name, pos, FALSE);
4214 int last_user_nr = user.nr;
4216 if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
4218 // save setup of currently active user (may differ from edited user)
4221 // temporarily change active user to edited user
4222 user.nr = type_name_nr;
4225 Request("Use current setup values for the new player?", REQ_ASK))
4227 // use current setup values for new user, but create new player UUID
4228 setup.player_uuid = getStringCopy(getUUID());
4232 // load setup for existing user (or start with defaults for new user)
4237 char *setup_filename = getSetupFilename();
4238 boolean setup_exists = fileExists(setup_filename);
4240 // change name of edited user in setup structure
4241 strcpy(setup.player_name, name);
4243 // save setup of edited user
4246 // change name of edited user on score server
4247 ApiRenamePlayerAsThread();
4249 if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
4253 if (Request("Reset setup values for this player?", REQ_ASK))
4255 // remove setup config file
4256 unlink(setup_filename);
4258 // set player name to default player name
4261 // update player name used by name typing functions
4262 strcpy(name, setup.player_name);
4264 setTypeNameValues_Name(name, pos);
4267 else if (remove_user && type_name_nr != 0)
4269 if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
4271 char *user_dir = getUserGameDataDir();
4272 char *user_dir_removed =
4273 getStringCat3WithSeparator(user_dir, "REMOVED",
4274 getCurrentTimestamp(), ".");
4276 if (rename(user_dir, user_dir_removed) != 0)
4277 Request("Removing settings and tapes failed!", REQ_CONFIRM);
4279 checked_free(user_dir_removed);
4282 else if (create_user && type_name_nr != 0 && !setup_exists)
4284 if (Request("Create empty level set for the new player?", REQ_ASK))
4286 char *levelset_subdir = getNewUserLevelSubdir();
4288 if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
4290 AddUserLevelSetToLevelInfo(levelset_subdir);
4292 LevelDirTree *leveldir_current_last = leveldir_current;
4294 leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
4297 // set level number of newly created level set to default value
4298 LoadLevelSetup_SeriesInfo();
4300 // set newly created level set as current level set for new user
4301 SaveLevelSetup_LastSeries();
4302 SaveLevelSetup_SeriesInfo();
4304 leveldir_current = leveldir_current_last;
4308 Request("Creating new level set failed!", REQ_CONFIRM);
4313 // restore currently active user
4314 user.nr = last_user_nr;
4316 // restore setup of currently active user
4319 // restore last level set of currently active user
4320 LoadLevelSetup_LastSeries();
4321 LoadLevelSetup_SeriesInfo();
4325 static void HandleTypeNameExt(boolean initialize, Key key)
4327 static struct TextPosInfo pos_name = { 0 };
4328 static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
4329 static int xpos = 0;
4330 struct TextPosInfo *pos = &pos_name;
4331 char key_char = getValidConfigValueChar(getCharFromKey(key));
4332 boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
4333 boolean active = TRUE;
4337 getTypeNameValues(name, pos, &xpos);
4339 int sx = mSX + ALIGNED_TEXT_XPOS(pos);
4340 int sy = mSY + ALIGNED_TEXT_YPOS(pos);
4342 StartTextInput(sx, sy, pos->width, pos->height);
4344 else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
4346 name[xpos] = key_char;
4351 else if ((key == KSYM_Delete || key == KSYM_BackSpace) && xpos > 0)
4357 else if (key == KSYM_Return || key == KSYM_Escape)
4359 boolean changed = (key == KSYM_Return);
4363 setTypeNameValues(name, pos, changed);
4368 drawTypeNameText(name, pos, active);
4372 SetGameStatus(game_status_last_screen);
4374 if (game_status == GAME_MODE_MAIN)
4375 InitializeMainControls();
4379 static void DrawTypeName(void)
4381 HandleTypeNameExt(TRUE, 0);
4384 void HandleTypeName(Key key)
4386 HandleTypeNameExt(FALSE, key);
4390 // ============================================================================
4391 // tree menu functions
4392 // ============================================================================
4394 static int getAlignXOffsetFromTreeInfo(TreeInfo *ti)
4396 if (game_status != GAME_MODE_SETUP ||
4397 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4400 int max_text_size = 0;
4403 for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next)
4404 max_text_size = MAX(max_text_size, strlen(node->name));
4406 int num_entries = numTreeInfoInGroup(ti);
4407 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4408 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4409 int text_width = max_text_size * getFontWidth(font_nr);
4410 int button_width = SC_MENUBUTTON_XSIZE;
4411 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4412 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4413 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align;
4414 int x = ALIGNED_XPOS(0, screen_width, align) * -1;
4415 int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align);
4416 int align_xoffset = MAX(0, align_xoffset_raw);
4418 return align_xoffset;
4421 static int getAlignYOffsetFromTreeInfo(TreeInfo *ti)
4423 if (game_status != GAME_MODE_SETUP ||
4424 DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER)
4427 int num_entries = numTreeInfoInGroup(ti);
4428 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4429 int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
4430 int font_height = getFontHeight(font_nr);
4431 int text_height = font_height * num_page_entries;
4432 int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
4433 int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
4434 int y = ALIGNED_YPOS(0, page_height, align) * -1;
4435 int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align);
4436 int align_yoffset = MAX(0, align_yoffset_raw);
4438 return align_yoffset;
4441 static void StartPlayingFromHallOfFame(void)
4443 level_nr = scores.next_level_nr;
4444 LoadLevel(level_nr);
4446 StartGameActions(network.enabled, setup.autorecord, level.random_seed);
4449 static void DrawChooseTree(TreeInfo **ti_ptr)
4451 int fade_mask = REDRAW_FIELD;
4452 boolean restart_music = (game_status != game_status_last_screen &&
4453 game_status_last_screen != GAME_MODE_SCOREINFO);
4455 scores.continue_on_return = (game_status == GAME_MODE_SCORES &&
4456 game_status_last_screen == GAME_MODE_PLAYING);
4459 fade_mask = REDRAW_ALL;
4461 if (*ti_ptr != NULL && strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
4463 if (game_status == GAME_MODE_SETUP)
4467 else if (game_status == GAME_MODE_SCORES && scores.continue_playing)
4469 StartPlayingFromHallOfFame();
4473 SetGameStatus(GAME_MODE_MAIN);
4483 FreeScreenGadgets();
4484 CreateScreenGadgets();
4487 FadeMenuSoundsAndMusic();
4491 // needed if different viewport properties defined for this screen
4492 ChangeViewportPropertiesIfNeeded();
4494 if (game_status == GAME_MODE_NAMES)
4495 SetMainBackgroundImage(IMG_BACKGROUND_NAMES);
4496 else if (game_status == GAME_MODE_LEVELNR)
4497 SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR);
4498 else if (game_status == GAME_MODE_LEVELS)
4499 SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
4500 else if (game_status == GAME_MODE_SCORES)
4501 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
4505 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
4507 // map gadgets for high score screen
4508 if (game_status == GAME_MODE_SCORES)
4509 MapScreenMenuGadgets(SCREEN_MASK_SCORES);
4511 MapScreenTreeGadgets(*ti_ptr);
4513 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
4515 DrawMaskedBorder(fade_mask);
4518 PlayMenuSoundsAndMusic();
4523 static int getChooseTreeFont(TreeInfo *node, boolean active)
4525 if (game_status == GAME_MODE_SCORES)
4526 return (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4528 return MENU_CHOOSE_TREE_FONT(MENU_CHOOSE_TREE_COLOR(node, active));
4531 static void drawChooseTreeText(TreeInfo *ti, int y, boolean active)
4533 int num_entries = numTreeInfoInGroup(ti);
4534 boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
4535 int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
4536 int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
4537 int first_entry = ti->cl_first;
4538 int entry_pos = first_entry + y;
4539 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4540 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4541 int font_nr = getChooseTreeFont(node, active);
4542 int font_xoffset = getFontDrawOffsetX(font_nr);
4543 int xpos = MENU_SCREEN_START_XPOS;
4544 int ypos = MENU_SCREEN_START_YPOS + y;
4545 int startdx = xpos * 32;
4546 int startdy = ypos * 32;
4547 int startx = amSX + startdx;
4548 int starty = amSY + startdy;
4549 int startx_text = startx + font_xoffset;
4550 int endx_text = amSX + screen_width;
4551 int max_text_size = endx_text - startx_text;
4552 int max_buffer_len = max_text_size / getFontWidth(font_nr);
4553 char buffer[max_buffer_len + 1];
4555 if (game_status == GAME_MODE_SCORES && !node->parent_link)
4557 int font_nr1 = (active ? FONT_TEXT_1_ACTIVE : FONT_TEXT_1);
4558 int font_nr2 = (active ? FONT_TEXT_2_ACTIVE : FONT_TEXT_2);
4559 int font_nr3 = (active ? FONT_TEXT_3_ACTIVE : FONT_TEXT_3);
4560 int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4);
4561 int font_size_1 = getFontWidth(font_nr1);
4562 int font_size_3 = getFontWidth(font_nr3);
4563 int font_size_4 = getFontWidth(font_nr4);
4564 int text_size_1 = 4 * font_size_1;
4565 int text_size_4 = 5 * font_size_4;
4566 int border = amSX - SX + getFontDrawOffsetX(font_nr1);
4568 int dx3 = text_size_1;
4569 int dx4 = SXSIZE - 2 * startdx - 2 * border - text_size_4;
4570 int num_dots = (dx4 - dx3) / font_size_3;
4571 int startx1 = startx + dx1;
4572 int startx3 = startx + dx3;
4573 int startx4 = startx + dx4;
4574 int pos = node->pos;
4575 char *pos_text = getHallOfFameRankText(pos, 3);
4578 DrawText(startx1, starty, pos_text, font_nr1);
4580 for (i = 0; i < num_dots; i++)
4581 DrawText(startx3 + i * font_size_3, starty, ".", font_nr3);
4583 if (!strEqual(scores.entry[pos].name, EMPTY_PLAYER_NAME))
4584 DrawText(startx3, starty, scores.entry[pos].name, font_nr2);
4586 DrawText(startx4, starty, getHallOfFameScoreText(pos, 5), font_nr4);
4590 strncpy(buffer, node->name, max_buffer_len);
4591 buffer[max_buffer_len] = '\0';
4593 DrawText(startx, starty, buffer, font_nr);
4597 static void drawChooseTreeHeadExt(int type, char *title_string)
4599 int yoffset_sets = MENU_TITLE1_YPOS;
4600 int yoffset_setup = 16;
4601 int yoffset = (type == TREE_TYPE_SCORE_ENTRY ||
4602 type == TREE_TYPE_LEVEL_DIR ||
4603 type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup);
4605 DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string);
4608 static void drawChooseTreeHead(TreeInfo *ti)
4610 drawChooseTreeHeadExt(ti->type, ti->infotext);
4613 static void drawChooseTreeList(TreeInfo *ti)
4615 int first_entry = ti->cl_first;
4616 int num_entries = numTreeInfoInGroup(ti);
4617 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4620 clearMenuListArea();
4622 for (i = 0; i < num_page_entries; i++)
4624 TreeInfo *node, *node_first;
4625 int entry_pos = first_entry + i;
4627 node_first = getTreeInfoFirstGroupEntry(ti);
4628 node = getTreeInfoFromPos(node_first, entry_pos);
4630 drawChooseTreeText(ti, i, FALSE);
4632 if (node->parent_link)
4633 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
4634 else if (node->level_group)
4635 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4637 initCursor(i, IMG_MENU_BUTTON);
4639 if (game_status == GAME_MODE_SCORES && node->pos == scores.last_added)
4640 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
4642 if (game_status == GAME_MODE_NAMES)
4643 drawChooseTreeEdit(i, FALSE);
4646 redraw_mask |= REDRAW_FIELD;
4649 static void drawChooseTreeInfo(TreeInfo *ti)
4651 int entry_pos = ti->cl_first + ti->cl_cursor;
4652 int last_redraw_mask = redraw_mask;
4653 int ypos = MENU_TITLE2_YPOS;
4654 int font_nr = FONT_TITLE_2;
4657 if (ti->type == TREE_TYPE_LEVEL_NR)
4658 DrawTextFCentered(ypos, font_nr, leveldir_current->name);
4660 if (ti->type == TREE_TYPE_SCORE_ENTRY)
4661 DrawTextFCentered(ypos, font_nr, "HighScores of Level %d",
4662 scores.last_level_nr);
4664 if (ti->type != TREE_TYPE_LEVEL_DIR)
4667 TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
4668 TreeInfo *node = getTreeInfoFromPos(node_first, entry_pos);
4670 DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr);
4672 if (node->parent_link)
4673 DrawTextFCentered(ypos, font_nr, "leave \"%s\"",
4674 node->node_parent->name);
4675 else if (node->level_group)
4676 DrawTextFCentered(ypos, font_nr, "enter \"%s\"",
4678 else if (ti->type == TREE_TYPE_LEVEL_DIR)
4679 DrawTextFCentered(ypos, font_nr, "%3d %s (%s)",
4680 node->levels, (node->levels > 1 ? "levels" : "level"),
4683 // let BackToFront() redraw only what is needed
4684 redraw_mask = last_redraw_mask;
4685 for (x = 0; x < SCR_FIELDX; x++)
4686 MarkTileDirty(x, 1);
4689 static void drawChooseTreeCursorAndText(TreeInfo *ti, boolean active)
4691 drawChooseTreeCursor(ti->cl_cursor, active);
4692 drawChooseTreeText(ti, ti->cl_cursor, active);
4695 static void drawChooseTreeScreen(TreeInfo *ti)
4697 drawChooseTreeHead(ti);
4698 drawChooseTreeList(ti);
4699 drawChooseTreeInfo(ti);
4700 drawChooseTreeCursorAndText(ti, TRUE);
4702 AdjustChooseTreeScrollbar(ti, SCREEN_CTRL_ID_SCROLL_VERTICAL);
4704 // scroll bar and buttons may just have been added after reloading scores
4705 if (game_status == GAME_MODE_SCORES)
4706 MapScreenTreeGadgets(ti);
4709 static TreeInfo *setHallOfFameActiveEntry(TreeInfo **ti_ptr)
4711 int score_pos = scores.last_added;
4713 if (game_status_last_screen == GAME_MODE_SCOREINFO)
4714 score_pos = scores.last_entry_nr;
4716 // set current tree entry to last added score entry
4717 *ti_ptr = getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
4719 // if that fails, set current tree entry to first entry (back link)
4720 if (*ti_ptr == NULL)
4721 *ti_ptr = score_entries->node_group;
4723 int num_entries = numTreeInfoInGroup(*ti_ptr);
4724 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4725 int pos_score = getPosFromTreeInfo(*ti_ptr);
4726 int pos_first_raw = pos_score - (num_page_entries + 1) / 2 + 1;
4727 int pos_first = MIN(MAX(0, pos_first_raw), num_entries - num_page_entries);
4729 (*ti_ptr)->cl_first = pos_first;
4730 (*ti_ptr)->cl_cursor = pos_score - pos_first;
4735 static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
4738 TreeInfo *ti = *ti_ptr;
4739 boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped;
4740 int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x;
4741 int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE);
4742 int sx1_edit_name = getChooseTreeEditXPosReal(POS_LEFT);
4743 int sx2_edit_name = getChooseTreeEditXPosReal(POS_RIGHT);
4745 int y = (ti != NULL ? ti->cl_cursor : 0);
4746 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
4747 int num_entries = numTreeInfoInGroup(ti);
4748 int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
4749 boolean position_set_by_scrollbar = (dx == 999);
4751 if (game_status == GAME_MODE_SCORES)
4753 if (server_scores.updated)
4755 // reload scores, using updated server score cache file
4756 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
4758 server_scores.updated = FALSE;
4760 DrawHallOfFame_setScoreEntries();
4762 ti = setHallOfFameActiveEntry(ti_ptr);
4764 if (button != MB_MENU_INITIALIZE)
4765 drawChooseTreeScreen(ti);
4769 if (button == MB_MENU_INITIALIZE)
4771 int num_entries = numTreeInfoInGroup(ti);
4772 int entry_pos = getPosFromTreeInfo(ti);
4774 align_xoffset = getAlignXOffsetFromTreeInfo(ti);
4775 align_yoffset = getAlignYOffsetFromTreeInfo(ti);
4777 if (game_status == GAME_MODE_SCORES)
4779 ti = setHallOfFameActiveEntry(ti_ptr);
4781 else if (ti->cl_first == -1)
4783 // only on initialization
4784 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4785 ti->cl_cursor = entry_pos - ti->cl_first;
4788 else if (ti->cl_cursor >= num_page_entries ||
4789 (num_entries > num_page_entries &&
4790 num_entries - ti->cl_first < num_page_entries))
4792 // only after change of list size (by custom graphic configuration)
4793 ti->cl_first = MAX(0, entry_pos - num_page_entries + 1);
4794 ti->cl_cursor = entry_pos - ti->cl_first;
4797 if (position_set_by_scrollbar)
4800 drawChooseTreeScreen(ti);
4804 else if (button == MB_MENU_LEAVE)
4806 if (game_status != GAME_MODE_SCORES)
4809 PlaySound(SND_MENU_ITEM_SELECTING);
4811 if (ti->node_parent)
4813 *ti_ptr = ti->node_parent;
4814 DrawChooseTree(ti_ptr);
4816 else if (game_status == GAME_MODE_SETUP)
4818 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
4819 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
4820 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
4821 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
4823 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
4824 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
4825 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
4826 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
4827 execSetupGraphics();
4828 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
4829 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
4830 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
4832 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
4833 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
4834 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
4835 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
4836 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
4837 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
4838 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
4839 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
4846 if (game_status == GAME_MODE_LEVELNR)
4848 int new_level_nr = atoi(level_number_current->identifier);
4850 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
4853 SetGameStatus(GAME_MODE_MAIN);
4861 #if defined(PLATFORM_ANDROID)
4862 // directly continue when touching the screen after playing
4863 if ((mx || my) && scores.continue_on_return)
4865 // ignore touch events until released
4870 // any mouse click or cursor key stops leaving scores by "Return" key
4871 if ((mx || my || dx || dy) && scores.continue_on_return)
4873 scores.continue_on_return = FALSE;
4874 level_nr = scores.last_level_nr;
4875 LoadLevel(level_nr);
4878 if (mx || my) // mouse input
4880 x = (mx - amSX) / 32;
4881 y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS;
4883 if (game_status == GAME_MODE_NAMES)
4884 drawChooseTreeEdit(ti->cl_cursor, FALSE);
4886 else if (dx || dy) // keyboard or scrollbar/scrollbutton input
4888 // move cursor instead of scrolling when already at start/end of list
4889 if (dy == -1 * SCROLL_LINE && ti->cl_first == 0)
4891 else if (dy == +1 * SCROLL_LINE &&
4892 ti->cl_first + num_page_entries == num_entries)
4895 // handle scrolling screen one line or page
4896 if (ti->cl_cursor + dy < 0 ||
4897 ti->cl_cursor + dy > num_page_entries - 1)
4899 boolean redraw = FALSE;
4901 if (ABS(dy) == SCROLL_PAGE)
4902 step = num_page_entries - 1;
4904 if (dy < 0 && ti->cl_first > 0)
4906 // scroll page/line up
4908 ti->cl_first -= step;
4909 if (ti->cl_first < 0)
4914 else if (dy > 0 && ti->cl_first + num_page_entries < num_entries)
4916 // scroll page/line down
4918 ti->cl_first += step;
4919 if (ti->cl_first + num_page_entries > num_entries)
4920 ti->cl_first = MAX(0, num_entries - num_page_entries);
4926 drawChooseTreeScreen(ti);
4931 // handle moving cursor one line
4932 y = ti->cl_cursor + dy;
4935 if (game_status == GAME_MODE_SCORES && ABS(dx) == 1)
4937 HandleHallOfFame_SelectLevel(1, dx);
4943 TreeInfo *node_first, *node_cursor;
4944 int entry_pos = ti->cl_first + y;
4946 node_first = getTreeInfoFirstGroupEntry(ti);
4947 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
4949 if (node_cursor->node_group)
4953 PlaySound(SND_MENU_ITEM_SELECTING);
4955 node_cursor->cl_first = ti->cl_first;
4956 node_cursor->cl_cursor = ti->cl_cursor;
4958 *ti_ptr = node_cursor->node_group;
4959 DrawChooseTree(ti_ptr);
4964 else if ((dx == -1 || button == MB_MENU_CONTINUE) && ti->node_parent)
4966 if (game_status != GAME_MODE_SCORES)
4969 PlaySound(SND_MENU_ITEM_SELECTING);
4971 *ti_ptr = ti->node_parent;
4972 DrawChooseTree(ti_ptr);
4977 if (!anyScrollbarGadgetActive() &&
4978 IN_VIS_MENU(x, y) &&
4979 mx < mx_right_border &&
4980 y >= 0 && y < num_page_entries)
4984 if (game_status == GAME_MODE_NAMES)
4986 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
4987 drawChooseTreeEdit(y, TRUE);
4990 if (y != ti->cl_cursor)
4992 PlaySound(SND_MENU_ITEM_ACTIVATING);
4994 drawChooseTreeCursorAndText(ti, FALSE);
4998 drawChooseTreeCursorAndText(ti, TRUE);
5000 drawChooseTreeInfo(ti);
5004 if (game_status == GAME_MODE_SETUP)
5006 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5007 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5008 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5009 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5011 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5012 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5013 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5014 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5015 execSetupGraphics();
5016 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5017 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5018 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5020 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5021 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5022 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5023 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5024 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5025 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5026 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5027 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5036 TreeInfo *node_first, *node_cursor;
5037 int entry_pos = ti->cl_first + y;
5039 PlaySound(SND_MENU_ITEM_SELECTING);
5041 node_first = getTreeInfoFirstGroupEntry(ti);
5042 node_cursor = getTreeInfoFromPos(node_first, entry_pos);
5044 if (node_cursor->node_group)
5048 node_cursor->cl_first = ti->cl_first;
5049 node_cursor->cl_cursor = ti->cl_cursor;
5051 *ti_ptr = node_cursor->node_group;
5052 DrawChooseTree(ti_ptr);
5054 else if (node_cursor->parent_link)
5056 if (game_status != GAME_MODE_SCORES)
5059 *ti_ptr = node_cursor->node_parent;
5060 DrawChooseTree(ti_ptr);
5064 if (game_status != GAME_MODE_SCORES)
5067 node_cursor->cl_first = ti->cl_first;
5068 node_cursor->cl_cursor = ti->cl_cursor;
5070 *ti_ptr = node_cursor;
5072 if (ti->type == TREE_TYPE_LEVEL_DIR)
5074 LoadLevelSetup_SeriesInfo();
5076 SaveLevelSetup_LastSeries();
5077 SaveLevelSetup_SeriesInfo();
5081 if (game_status == GAME_MODE_SETUP)
5083 if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE ||
5084 setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED ||
5085 setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY ||
5086 setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
5088 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE ||
5089 setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE ||
5090 setup_mode == SETUP_MODE_CHOOSE_RENDERING ||
5091 setup_mode == SETUP_MODE_CHOOSE_VSYNC)
5092 execSetupGraphics();
5093 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
5094 setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
5095 setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
5097 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
5098 setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
5099 setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
5100 setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY ||
5101 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0 ||
5102 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0 ||
5103 setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1 ||
5104 setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
5111 if (game_status == GAME_MODE_LEVELNR)
5113 int new_level_nr = atoi(level_number_current->identifier);
5115 HandleMainMenu_SelectLevel(0, 0, new_level_nr);
5117 else if (game_status == GAME_MODE_LEVELS)
5119 // store level set if chosen from "last played level set" menu
5120 StoreLastPlayedLevels(leveldir_current);
5122 // store if level set chosen from "last played level set" menu
5123 SaveLevelSetup_LastSeries();
5125 else if (game_status == GAME_MODE_NAMES)
5127 if (mx >= sx1_edit_name && mx <= sx2_edit_name)
5129 SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
5136 // change active user to selected user
5137 user.nr = entry_pos;
5139 // save number of new active user
5142 // load setup of new active user
5145 // load last level set of new active user
5146 LoadLevelSetup_LastSeries();
5147 LoadLevelSetup_SeriesInfo();
5149 // update list of last played level sets
5150 UpdateLastPlayedLevels_TreeInfo();
5154 ToggleFullscreenIfNeeded();
5155 ChangeWindowScalingIfNeeded();
5157 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS);
5158 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS);
5159 ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC);
5161 else if (game_status == GAME_MODE_SCORES)
5163 if (scores.continue_playing && scores.continue_on_return)
5165 StartPlayingFromHallOfFame();
5169 else if (!scores.continue_on_return)
5171 SetGameStatus(GAME_MODE_SCOREINFO);
5173 DrawScoreInfo(node_cursor->pos);
5179 SetGameStatus(GAME_MODE_MAIN);
5187 if (game_status == GAME_MODE_SCORES)
5188 PlayMenuSoundIfLoop();
5191 void DrawChoosePlayerName(void)
5195 if (player_name != NULL)
5197 freeTreeInfo(player_name);
5202 for (i = 0; i < MAX_PLAYER_NAMES; i++)
5204 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
5205 char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
5208 ti->node_top = &player_name;
5209 ti->sort_priority = 10000 + value;
5210 ti->color = getPlayerNameColor(global.user_names[i]);
5212 snprintf(identifier, sizeof(identifier), "%d", value);
5213 snprintf(name, sizeof(name), "%s", global.user_names[i]);
5215 setString(&ti->identifier, identifier);
5216 setString(&ti->name, name);
5217 setString(&ti->name_sorting, name);
5219 pushTreeInfo(&player_name, ti);
5222 // sort player entries by player number
5223 sortTreeInfo(&player_name);
5225 // set current player entry to selected player entry
5226 player_name_current =
5227 getTreeInfoFromIdentifier(player_name, i_to_a(user.nr));
5229 // if that fails, set current player name to first available name
5230 if (player_name_current == NULL)
5231 player_name_current = player_name;
5233 // set text size for main name input (also used on name selection screen)
5234 InitializeMainControls();
5236 DrawChooseTree(&player_name_current);
5239 void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button)
5241 HandleChooseTree(mx, my, dx, dy, button, &player_name_current);
5244 void DrawChooseLevelSet(void)
5246 DrawChooseTree(&leveldir_current);
5249 void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button)
5251 HandleChooseTree(mx, my, dx, dy, button, &leveldir_current);
5254 void DrawChooseLevelNr(void)
5258 if (level_number != NULL)
5260 freeTreeInfo(level_number);
5262 level_number = NULL;
5265 for (i = leveldir_current->first_level; i <= leveldir_current->last_level;i++)
5267 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_LEVEL_NR);
5268 char identifier[32], name[64];
5271 // temporarily load level info to get level name
5272 LoadLevelInfoOnly(i);
5274 ti->node_top = &level_number;
5275 ti->sort_priority = 10000 + value;
5276 ti->color = (level.no_level_file ? FC_BLUE :
5277 LevelStats_getSolved(i) ? FC_GREEN :
5278 LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
5280 snprintf(identifier, sizeof(identifier), "%d", value);
5281 snprintf(name, sizeof(name), "%03d: %s", value,
5282 (level.no_level_file ? "(no file)" : level.name));
5284 setString(&ti->identifier, identifier);
5285 setString(&ti->name, name);
5286 setString(&ti->name_sorting, name);
5288 pushTreeInfo(&level_number, ti);
5291 // sort level number values to start with lowest level number
5292 sortTreeInfo(&level_number);
5294 // set current level number to current level number
5295 level_number_current =
5296 getTreeInfoFromIdentifier(level_number, i_to_a(level_nr));
5298 // if that also fails, set current level number to first available level
5299 if (level_number_current == NULL)
5300 level_number_current = level_number;
5302 DrawChooseTree(&level_number_current);
5305 void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button)
5307 HandleChooseTree(mx, my, dx, dy, button, &level_number_current);
5310 static void DrawHallOfFame_setScoreEntries(void)
5312 int max_empty_entries = 10; // at least show "top ten" list, if empty
5313 int max_visible_entries = NUM_MENU_ENTRIES_ON_SCREEN - 1; // w/o back link
5314 int min_score_entries = MIN(max_empty_entries, max_visible_entries);
5315 int score_pos = (scores.last_added >= 0 ? scores.last_added : 0);
5318 if (score_entries != NULL)
5320 freeTreeInfo(score_entries);
5322 score_entries = NULL;
5325 for (i = 0; i < MAX_SCORE_ENTRIES; i++)
5327 // do not add empty score entries if off-screen
5328 if (scores.entry[i].score == 0 &&
5329 scores.entry[i].time == 0 &&
5330 i >= min_score_entries)
5333 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_SCORE_ENTRY);
5334 char identifier[32], name[64];
5337 ti->node_top = &score_entries;
5338 ti->sort_priority = 10000 + value;
5339 ti->color = FC_YELLOW;
5342 snprintf(identifier, sizeof(identifier), "%d", value);
5343 snprintf(name, sizeof(name), "%03d.", value + 1);
5345 setString(&ti->identifier, identifier);
5346 setString(&ti->name, name);
5347 setString(&ti->name_sorting, name);
5349 pushTreeInfo(&score_entries, ti);
5352 // sort score entries to start with highest score entry
5353 sortTreeInfo(&score_entries);
5355 // add top tree node to create back link to main menu
5356 score_entries = addTopTreeInfoNode(score_entries);
5358 // set current score entry to last added or highest score entry
5359 score_entry_current =
5360 getTreeInfoFromIdentifier(score_entries, i_to_a(score_pos));
5362 // if that fails, set current score entry to first valid score entry
5363 if (score_entry_current == NULL)
5364 score_entry_current = getFirstValidTreeInfoEntry(score_entries);
5366 if (score_entries != NULL && scores.continue_playing)
5367 setString(&score_entries->node_group->name, BACKLINK_TEXT_NEXT);
5370 void DrawHallOfFame(int nr)
5372 scores.last_level_nr = nr;
5374 // (this is needed when called from GameEnd() after winning a game)
5375 KeyboardAutoRepeatOn();
5377 // (this is needed when called from GameEnd() after winning a game)
5378 SetDrawDeactivationMask(REDRAW_NONE);
5379 SetDrawBackgroundMask(REDRAW_FIELD);
5381 LoadLocalAndServerScore(scores.last_level_nr, TRUE);
5383 DrawHallOfFame_setScoreEntries();
5385 if (scores.last_added >= 0)
5386 SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);
5388 FadeSetEnterScreen();
5390 DrawChooseTree(&score_entry_current);
5393 static char *getHallOfFameRankText(int nr, int size)
5395 static char rank_text[10];
5396 boolean forced = (scores.force_last_added && nr == scores.last_added);
5397 char *rank_text_raw = (forced ? "???" : int2str(nr + 1, size));
5399 sprintf(rank_text, "%s%s", rank_text_raw, (size > 0 || !forced ? "." : ""));
5404 static char *getHallOfFameTimeText(int nr)
5406 static char score_text[10];
5407 int time_seconds = scores.entry[nr].time / FRAMES_PER_SECOND;
5408 int mm = (time_seconds / 60) % 60;
5409 int ss = (time_seconds % 60);
5411 sprintf(score_text, "%02d:%02d", mm, ss); // show playing time
5416 static char *getHallOfFameScoreText(int nr, int size)
5418 if (!level.rate_time_over_score)
5419 return int2str(scores.entry[nr].score, size); // show normal score
5420 else if (level.use_step_counter)
5421 return int2str(scores.entry[nr].time, size); // show number of steps
5423 return getHallOfFameTimeText(nr); // show playing time
5426 static char *getHallOfFameTapeDateText(struct ScoreEntry *entry)
5428 static char tape_date[MAX_ISO_DATE_LEN + 1];
5431 if (!strEqual(entry->tape_date, UNKNOWN_NAME) ||
5432 strEqual(entry->tape_basename, UNDEFINED_FILENAME))
5433 return entry->tape_date;
5435 for (i = 0, j = 0; i < 8; i++, j++)
5437 tape_date[j] = entry->tape_basename[i];
5439 if (i == 3 || i == 5)
5440 tape_date[++j] = '-';
5443 tape_date[MAX_ISO_DATE_LEN] = '\0';
5448 static void HandleHallOfFame_SelectLevel(int step, int direction)
5450 int old_level_nr = scores.last_level_nr;
5451 int new_level_nr = old_level_nr + step * direction;
5453 if (new_level_nr < leveldir_current->first_level)
5454 new_level_nr = leveldir_current->first_level;
5455 if (new_level_nr > leveldir_current->last_level)
5456 new_level_nr = leveldir_current->last_level;
5458 if (setup.handicap && new_level_nr > leveldir_current->handicap_level)
5459 new_level_nr = leveldir_current->handicap_level;
5461 if (new_level_nr != old_level_nr)
5463 PlaySound(SND_MENU_ITEM_SELECTING);
5465 scores.last_level_nr = level_nr = new_level_nr;
5466 scores.last_entry_nr = 0;
5468 LoadLevel(level_nr);
5469 LoadLocalAndServerScore(level_nr, TRUE);
5471 DrawHallOfFame_setScoreEntries();
5473 if (game_status == GAME_MODE_SCORES)
5475 // force remapping optional gadgets (especially scroll bar)
5476 UnmapScreenTreeGadgets();
5478 // redraw complete high score screen, as sub-title has changed
5481 // redraw level selection buttons (which have just been erased)
5482 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5484 HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, &score_entry_current);
5488 DrawScoreInfo_Content(scores.last_entry_nr);
5491 SaveLevelSetup_SeriesInfo();
5495 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
5497 HandleChooseTree(mx, my, dx, dy, button, &score_entry_current);
5500 static void DrawScoreInfo_Content(int entry_nr)
5502 struct ScoreEntry *entry = &scores.entry[entry_nr];
5503 char *pos_text = getHallOfFameRankText(entry_nr, 0);
5504 char *tape_date = getHallOfFameTapeDateText(entry);
5505 int font_head = MENU_INFO_FONT_HEAD;
5506 int font_text = MENU_INFO_FONT_TEXT;
5507 int font_foot = MENU_INFO_FONT_FOOT;
5508 int spacing_para = menu.paragraph_spacing[GAME_MODE_SCOREINFO];
5509 int spacing_line = menu.line_spacing[GAME_MODE_SCOREINFO];
5510 int spacing_left = menu.left_spacing[GAME_MODE_SCOREINFO];
5511 int spacing_top = menu.top_spacing[GAME_MODE_SCOREINFO];
5512 int xstep = getFontWidth(font_text);
5513 int ystep_para = getMenuTextStep(spacing_para, font_text);
5514 int ystep_line = getMenuTextStep(spacing_line, font_text);
5515 int xstart = mSX - SX + spacing_left;
5516 int ystart = mSY - SY + spacing_top + getHeadlineSpacing();
5517 int ybottom = mSY - SY + SYSIZE - menu.bottom_spacing[GAME_MODE_SCOREINFO];
5518 int xstart1 = xstart + xstep;
5519 int xstart2 = xstart + xstep * 12;
5520 int select_x = SX + xstart1;
5521 int select_y1, select_y2;
5523 int play_height = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]->height;
5524 boolean play_visible = !strEqual(tape_date, UNKNOWN_NAME);
5525 int font_width = getFontWidth(font_text);
5526 int font_height = getFontHeight(font_text);
5527 int tape_date_width = getTextWidth(tape_date, font_text);
5528 int pad_left = xstart2;
5529 int pad_right = menu.right_spacing[GAME_MODE_SCOREINFO];
5530 int max_chars_per_line = (SXSIZE - pad_left - pad_right) / font_width;
5531 int max_lines_per_text = 5;
5536 // redraw level selection buttons (which have just been erased)
5537 RedrawScreenMenuGadgets(SCREEN_MASK_SCORES);
5539 drawChooseTreeHead(score_entries);
5540 drawChooseTreeInfo(score_entries);
5542 DrawTextF(xstart1, ystart, font_head, "Level Set");
5543 lines = DrawTextBufferS(xstart2, ystart, leveldir_current->name, font_text,
5544 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5545 TRUE, FALSE, FALSE);
5546 ystart += ystep_line + (lines > 0 ? lines - 1 : 0) * font_height;
5548 DrawTextF(xstart1, ystart, font_head, "Level");
5549 lines = DrawTextBufferS(xstart2, ystart, level.name, font_text,
5550 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5551 TRUE, FALSE, FALSE);
5552 ystart += ystep_para + (lines > 0 ? lines - 1 : 0) * font_height;
5554 select_y1 = SY + ystart;
5555 ystart += graphic_info[IMG_MENU_BUTTON_PREV_SCORE].height;
5557 DrawTextF(xstart1, ystart, font_head, "Rank");
5558 DrawTextF(xstart2, ystart, font_text, pos_text);
5559 ystart += ystep_line;
5561 DrawTextF(xstart1, ystart, font_head, "Player");
5562 DrawTextF(xstart2, ystart, font_text, entry->name);
5563 ystart += ystep_line;
5565 if (level.use_step_counter)
5567 DrawTextF(xstart1, ystart, font_head, "Steps");
5568 DrawTextF(xstart2, ystart, font_text, int2str(entry->time, 5));
5569 ystart += ystep_line;
5573 DrawTextF(xstart1, ystart, font_head, "Time");
5574 DrawTextF(xstart2, ystart, font_text, getHallOfFameTimeText(entry_nr));
5575 ystart += ystep_line;
5578 if (!level.rate_time_over_score || entry->score > 0)
5580 DrawTextF(xstart1, ystart, font_head, "Score");
5581 DrawTextF(xstart2, ystart, font_text, int2str(entry->score, 5));
5582 ystart += ystep_line;
5585 ystart += ystep_line;
5587 play_x = SX + xstart2 + tape_date_width + font_width;
5588 play_y = SY + ystart + (font_height - play_height) / 2;
5590 DrawTextF(xstart1, ystart, font_head, "Tape Date");
5591 DrawTextF(xstart2, ystart, font_text, tape_date);
5592 ystart += ystep_line;
5594 DrawTextF(xstart1, ystart, font_head, "Platform");
5595 DrawTextF(xstart2, ystart, font_text, entry->platform);
5596 ystart += ystep_line;
5598 DrawTextF(xstart1, ystart, font_head, "Version");
5599 DrawTextF(xstart2, ystart, font_text, entry->version);
5600 ystart += ystep_line;
5602 DrawTextF(xstart1, ystart, font_head, "Country");
5603 lines = DrawTextBufferS(xstart2, ystart, entry->country_name, font_text,
5604 max_chars_per_line, -1, max_lines_per_text, 0, -1,
5605 TRUE, FALSE, FALSE);
5606 ystart += ystep_line;
5608 select_y2 = SY + ystart;
5610 DrawTextSCentered(ybottom, font_foot, "Press any key or button to go back");
5612 AdjustScoreInfoButtons_SelectScore(select_x, select_y1, select_y2);
5613 AdjustScoreInfoButtons_PlayTape(play_x, play_y, play_visible);
5616 static void DrawScoreInfo(int entry_nr)
5618 scores.last_entry_nr = entry_nr;
5619 score_info_tape_play = FALSE;
5623 FreeScreenGadgets();
5624 CreateScreenGadgets();
5626 FadeOut(REDRAW_FIELD);
5628 // needed if different viewport properties defined after playing score tape
5629 ChangeViewportPropertiesIfNeeded();
5631 // set this after "ChangeViewportPropertiesIfNeeded()" (which may reset it)
5632 SetDrawDeactivationMask(REDRAW_NONE);
5633 SetDrawBackgroundMask(REDRAW_FIELD);
5635 // needed if different background image defined after playing score tape
5636 SetMainBackgroundImage(IMG_BACKGROUND_SCORES);
5637 SetMainBackgroundImageIfDefined(IMG_BACKGROUND_SCOREINFO);
5639 // special compatibility handling for "Snake Bite" graphics set
5640 if (strPrefix(leveldir_current->identifier, "snake_bite"))
5641 ClearRectangle(gfx.background_bitmap, gfx.real_sx, gfx.real_sy + 64,
5642 gfx.full_sxsize, gfx.full_sysize - 64);
5644 DrawScoreInfo_Content(entry_nr);
5646 // map gadgets for score info screen
5647 MapScreenMenuGadgets(SCREEN_MASK_SCORES_INFO);
5649 FadeIn(REDRAW_FIELD);
5652 static void HandleScoreInfo_SelectScore(int step, int direction)
5654 int old_entry_nr = scores.last_entry_nr;
5655 int new_entry_nr = old_entry_nr + step * direction;
5656 int num_nodes = numTreeInfoInGroup(score_entry_current);
5657 int num_entries = num_nodes - 1; // score nodes only, without back link
5659 if (new_entry_nr < 0)
5661 if (new_entry_nr > num_entries - 1)
5662 new_entry_nr = num_entries - 1;
5664 if (new_entry_nr != old_entry_nr)
5666 scores.last_entry_nr = new_entry_nr;
5668 DrawScoreInfo_Content(new_entry_nr);
5672 static void HandleScoreInfo_PlayTape(void)
5674 if (!PlayScoreTape(scores.last_entry_nr))
5676 DrawScoreInfo_Content(scores.last_entry_nr);
5678 FadeIn(REDRAW_FIELD);
5682 void HandleScoreInfo(int mx, int my, int dx, int dy, int button)
5684 boolean button_action = (button == MB_MENU_LEAVE || button == MB_MENU_CHOICE);
5685 boolean button_is_valid = (mx >= 0 && my >= 0);
5686 boolean button_screen_clicked = (button_action && button_is_valid);
5688 if (server_scores.updated)
5690 // reload scores, using updated server score cache file
5691 LoadLocalAndServerScore(scores.last_level_nr, FALSE);
5693 server_scores.updated = FALSE;
5695 DrawHallOfFame_setScoreEntries();
5697 DrawScoreInfo_Content(scores.last_entry_nr);
5700 if (button_screen_clicked)
5702 PlaySound(SND_MENU_ITEM_SELECTING);
5704 SetGameStatus(GAME_MODE_SCORES);
5706 DrawHallOfFame(scores.last_level_nr);
5710 HandleHallOfFame_SelectLevel(1, SIGN(dx) * (ABS(dx) > 1 ? 10 : 1));
5714 HandleScoreInfo_SelectScore(1, SIGN(dy) * (ABS(dy) > 1 ? 10 : 1));
5719 // ============================================================================
5720 // setup screen functions
5721 // ============================================================================
5723 static struct TokenInfo *setup_info;
5724 static int num_setup_info; // number of setup entries shown on screen
5725 static int max_setup_info; // total number of setup entries in list
5727 static char *window_size_text;
5728 static char *scaling_type_text;
5729 static char *rendering_mode_text;
5730 static char *vsync_mode_text;
5731 static char *scroll_delay_text;
5732 static char *snapshot_mode_text;
5733 static char *game_speed_text;
5734 static char *scores_type_text;
5735 static char *network_server_text;
5736 static char *graphics_set_name;
5737 static char *sounds_set_name;
5738 static char *music_set_name;
5739 static char *volume_simple_text;
5740 static char *volume_loops_text;
5741 static char *volume_music_text;
5742 static char *touch_controls_text;
5743 static char *move_distance_text;
5744 static char *drop_distance_text;
5745 static char *transparency_text;
5746 static char *grid_size_text[2][2];
5748 static void execSetupMain(void)
5750 setup_mode = SETUP_MODE_MAIN;
5755 static void execSetupGame_setScoresType(void)
5757 if (scores_types == NULL)
5761 for (i = 0; scores_types_list[i].value != NULL; i++)
5763 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5764 char identifier[32], name[32];
5765 char *value = scores_types_list[i].value;
5766 char *text = scores_types_list[i].text;
5768 ti->node_top = &scores_types;
5769 ti->sort_priority = i;
5771 sprintf(identifier, "%s", value);
5772 sprintf(name, "%s", text);
5774 setString(&ti->identifier, identifier);
5775 setString(&ti->name, name);
5776 setString(&ti->name_sorting, name);
5777 setString(&ti->infotext, STR_SETUP_CHOOSE_SCORES_TYPE);
5779 pushTreeInfo(&scores_types, ti);
5782 // sort scores type values to start with lowest scores type value
5783 sortTreeInfo(&scores_types);
5785 // set current scores type value to configured scores type value
5786 scores_type_current =
5787 getTreeInfoFromIdentifier(scores_types, setup.scores_in_highscore_list);
5789 // if that fails, set current scores type to reliable default value
5790 if (scores_type_current == NULL)
5791 scores_type_current =
5792 getTreeInfoFromIdentifier(scores_types, STR_SCORES_TYPE_DEFAULT);
5794 // if that also fails, set current scores type to first available value
5795 if (scores_type_current == NULL)
5796 scores_type_current = scores_types;
5799 setup.scores_in_highscore_list = scores_type_current->identifier;
5801 // needed for displaying scores type text instead of identifier
5802 scores_type_text = scores_type_current->name;
5805 static void execSetupGame_setGameSpeeds(boolean update_value)
5807 if (setup.game_speed_extended)
5809 game_speeds_list = game_speeds_list_extended;
5810 game_speeds = game_speeds_extended;
5814 game_speeds_list = game_speeds_list_normal;
5815 game_speeds = game_speeds_normal;
5818 if (game_speeds == NULL)
5822 for (i = 0; game_speeds_list[i].value != -1; i++)
5824 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5825 char identifier[32], name[32];
5826 int value = game_speeds_list[i].value;
5827 char *text = game_speeds_list[i].text;
5829 ti->node_top = &game_speeds;
5830 ti->sort_priority = 10000 - value;
5832 sprintf(identifier, "%d", value);
5833 sprintf(name, "%s", text);
5835 setString(&ti->identifier, identifier);
5836 setString(&ti->name, name);
5837 setString(&ti->name_sorting, name);
5838 setString(&ti->infotext, STR_SETUP_CHOOSE_GAME_SPEED);
5840 pushTreeInfo(&game_speeds, ti);
5843 // sort game speed values to start with slowest game speed
5844 sortTreeInfo(&game_speeds);
5846 update_value = TRUE;
5851 // set current game speed to configured game speed value
5852 game_speed_current =
5853 getTreeInfoFromIdentifier(game_speeds, i_to_a(setup.game_frame_delay));
5855 // if that fails, set current game speed to reliable default value
5856 if (game_speed_current == NULL)
5857 game_speed_current =
5858 getTreeInfoFromIdentifier(game_speeds, i_to_a(GAME_FRAME_DELAY));
5860 // if that also fails, set current game speed to first available speed
5861 if (game_speed_current == NULL)
5862 game_speed_current = game_speeds;
5864 if (setup.game_speed_extended)
5865 game_speeds_extended = game_speeds;
5867 game_speeds_normal = game_speeds;
5870 setup.game_frame_delay = atoi(game_speed_current->identifier);
5872 // needed for displaying game speed text instead of identifier
5873 game_speed_text = game_speed_current->name;
5876 static void execSetupGame_setScrollDelays(void)
5878 if (scroll_delays == NULL)
5882 for (i = 0; scroll_delays_list[i].value != -1; i++)
5884 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5885 char identifier[32], name[32];
5886 int value = scroll_delays_list[i].value;
5887 char *text = scroll_delays_list[i].text;
5889 ti->node_top = &scroll_delays;
5890 ti->sort_priority = value;
5892 sprintf(identifier, "%d", value);
5893 sprintf(name, "%s", text);
5895 setString(&ti->identifier, identifier);
5896 setString(&ti->name, name);
5897 setString(&ti->name_sorting, name);
5898 setString(&ti->infotext, STR_SETUP_CHOOSE_SCROLL_DELAY);
5900 pushTreeInfo(&scroll_delays, ti);
5903 // sort scroll delay values to start with lowest scroll delay value
5904 sortTreeInfo(&scroll_delays);
5906 // set current scroll delay value to configured scroll delay value
5907 scroll_delay_current =
5908 getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
5910 // if that fails, set current scroll delay to reliable default value
5911 if (scroll_delay_current == NULL)
5912 scroll_delay_current =
5913 getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
5915 // if that also fails, set current scroll delay to first available value
5916 if (scroll_delay_current == NULL)
5917 scroll_delay_current = scroll_delays;
5920 setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
5922 // needed for displaying scroll delay text instead of identifier
5923 scroll_delay_text = scroll_delay_current->name;
5926 static void execSetupGame_setSnapshotModes(void)
5928 if (snapshot_modes == NULL)
5932 for (i = 0; snapshot_modes_list[i].value != NULL; i++)
5934 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
5935 char identifier[32], name[32];
5936 char *value = snapshot_modes_list[i].value;
5937 char *text = snapshot_modes_list[i].text;
5939 ti->node_top = &snapshot_modes;
5940 ti->sort_priority = i;
5942 sprintf(identifier, "%s", value);
5943 sprintf(name, "%s", text);
5945 setString(&ti->identifier, identifier);
5946 setString(&ti->name, name);
5947 setString(&ti->name_sorting, name);
5948 setString(&ti->infotext, STR_SETUP_CHOOSE_SNAPSHOT_MODE);
5950 pushTreeInfo(&snapshot_modes, ti);
5953 // sort snapshot mode values to start with lowest snapshot mode value
5954 sortTreeInfo(&snapshot_modes);
5956 // set current snapshot mode value to configured snapshot mode value
5957 snapshot_mode_current =
5958 getTreeInfoFromIdentifier(snapshot_modes, setup.engine_snapshot_mode);
5960 // if that fails, set current snapshot mode to reliable default value
5961 if (snapshot_mode_current == NULL)
5962 snapshot_mode_current =
5963 getTreeInfoFromIdentifier(snapshot_modes, STR_SNAPSHOT_MODE_DEFAULT);
5965 // if that also fails, set current snapshot mode to first available value
5966 if (snapshot_mode_current == NULL)
5967 snapshot_mode_current = snapshot_modes;
5970 setup.engine_snapshot_mode = snapshot_mode_current->identifier;
5972 // needed for displaying snapshot mode text instead of identifier
5973 snapshot_mode_text = snapshot_mode_current->name;
5976 static void execSetupGame_setNetworkServerText(void)
5978 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
5980 strcpy(network_server_hostname, STR_NETWORK_AUTO_DETECT_SETUP);
5984 strncpy(network_server_hostname, setup.network_server_hostname,
5985 MAX_SETUP_TEXT_INPUT_LEN);
5986 network_server_hostname[MAX_SETUP_TEXT_INPUT_LEN] = '\0';
5989 // needed for displaying network server text instead of identifier
5990 network_server_text = network_server_hostname;
5993 static void execSetupGame(void)
5995 boolean check_vsync_mode = (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED);
5997 execSetupGame_setGameSpeeds(FALSE);
5998 execSetupGame_setScoresType();
5999 execSetupGame_setScrollDelays();
6000 execSetupGame_setSnapshotModes();
6002 execSetupGame_setNetworkServerText();
6004 if (!setup.provide_uploading_tapes)
6005 setHideSetupEntry(execOfferUploadTapes);
6007 setup_mode = SETUP_MODE_GAME;
6011 // check if vsync needs to be disabled for this game speed to work
6012 if (check_vsync_mode)
6013 DisableVsyncIfNeeded();
6016 static void execSetupChooseScoresType(void)
6018 setup_mode = SETUP_MODE_CHOOSE_SCORES_TYPE;
6023 static void execSetupChooseGameSpeed(void)
6025 setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
6030 static void execSetupChooseScrollDelay(void)
6032 setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
6037 static void execSetupChooseSnapshotMode(void)
6039 setup_mode = SETUP_MODE_CHOOSE_SNAPSHOT_MODE;
6044 static void execSetupEngines(void)
6046 setup_mode = SETUP_MODE_ENGINES;
6051 static void execSetupEditor(void)
6053 setup_mode = SETUP_MODE_EDITOR;
6058 static void execSetupGraphics_setWindowSizes(boolean update_list)
6060 if (window_sizes != NULL && update_list)
6062 freeTreeInfo(window_sizes);
6064 window_sizes = NULL;
6067 if (window_sizes == NULL)
6069 boolean current_window_size_found = FALSE;
6072 for (i = 0; window_sizes_list[i].value != -1; i++)
6074 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6075 char identifier[32], name[32];
6076 int value = window_sizes_list[i].value;
6077 char *text = window_sizes_list[i].text;
6079 ti->node_top = &window_sizes;
6080 ti->sort_priority = value;
6082 sprintf(identifier, "%d", value);
6083 sprintf(name, "%s", text);
6085 setString(&ti->identifier, identifier);
6086 setString(&ti->name, name);
6087 setString(&ti->name_sorting, name);
6088 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6090 pushTreeInfo(&window_sizes, ti);
6092 if (value == setup.window_scaling_percent)
6093 current_window_size_found = TRUE;
6096 if (!current_window_size_found)
6098 // add entry for non-preset window scaling value
6100 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6101 char identifier[32], name[32];
6102 int value = setup.window_scaling_percent;
6104 ti->node_top = &window_sizes;
6105 ti->sort_priority = value;
6107 sprintf(identifier, "%d", value);
6108 sprintf(name, "%d %% (Current)", value);
6110 setString(&ti->identifier, identifier);
6111 setString(&ti->name, name);
6112 setString(&ti->name_sorting, name);
6113 setString(&ti->infotext, STR_SETUP_CHOOSE_WINDOW_SIZE);
6115 pushTreeInfo(&window_sizes, ti);
6118 // sort window size values to start with lowest window size value
6119 sortTreeInfo(&window_sizes);
6121 // set current window size value to configured window size value
6122 window_size_current =
6123 getTreeInfoFromIdentifier(window_sizes,
6124 i_to_a(setup.window_scaling_percent));
6126 // if that fails, set current window size to reliable default value
6127 if (window_size_current == NULL)
6128 window_size_current =
6129 getTreeInfoFromIdentifier(window_sizes,
6130 i_to_a(STD_WINDOW_SCALING_PERCENT));
6132 // if that also fails, set current window size to first available value
6133 if (window_size_current == NULL)
6134 window_size_current = window_sizes;
6137 setup.window_scaling_percent = atoi(window_size_current->identifier);
6139 // needed for displaying window size text instead of identifier
6140 window_size_text = window_size_current->name;
6143 static void execSetupGraphics_setScalingTypes(void)
6145 if (scaling_types == NULL)
6149 for (i = 0; scaling_types_list[i].value != NULL; i++)
6151 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6152 char identifier[32], name[32];
6153 char *value = scaling_types_list[i].value;
6154 char *text = scaling_types_list[i].text;
6156 ti->node_top = &scaling_types;
6157 ti->sort_priority = i;
6159 sprintf(identifier, "%s", value);
6160 sprintf(name, "%s", text);
6162 setString(&ti->identifier, identifier);
6163 setString(&ti->name, name);
6164 setString(&ti->name_sorting, name);
6165 setString(&ti->infotext, STR_SETUP_CHOOSE_SCALING_TYPE);
6167 pushTreeInfo(&scaling_types, ti);
6170 // sort scaling type values to start with lowest scaling type value
6171 sortTreeInfo(&scaling_types);
6173 // set current scaling type value to configured scaling type value
6174 scaling_type_current =
6175 getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
6177 // if that fails, set current scaling type to reliable default value
6178 if (scaling_type_current == NULL)
6179 scaling_type_current =
6180 getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
6182 // if that also fails, set current scaling type to first available value
6183 if (scaling_type_current == NULL)
6184 scaling_type_current = scaling_types;
6187 setup.window_scaling_quality = scaling_type_current->identifier;
6189 // needed for displaying scaling type text instead of identifier
6190 scaling_type_text = scaling_type_current->name;
6193 static void execSetupGraphics_setRenderingModes(void)
6195 if (rendering_modes == NULL)
6199 for (i = 0; rendering_modes_list[i].value != NULL; i++)
6201 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6202 char identifier[32], name[32];
6203 char *value = rendering_modes_list[i].value;
6204 char *text = rendering_modes_list[i].text;
6206 ti->node_top = &rendering_modes;
6207 ti->sort_priority = i;
6209 sprintf(identifier, "%s", value);
6210 sprintf(name, "%s", text);
6212 setString(&ti->identifier, identifier);
6213 setString(&ti->name, name);
6214 setString(&ti->name_sorting, name);
6215 setString(&ti->infotext, STR_SETUP_CHOOSE_RENDERING);
6217 pushTreeInfo(&rendering_modes, ti);
6220 // sort rendering mode values to start with lowest rendering mode value
6221 sortTreeInfo(&rendering_modes);
6223 // set current rendering mode value to configured rendering mode value
6224 rendering_mode_current =
6225 getTreeInfoFromIdentifier(rendering_modes, setup.screen_rendering_mode);
6227 // if that fails, set current rendering mode to reliable default value
6228 if (rendering_mode_current == NULL)
6229 rendering_mode_current =
6230 getTreeInfoFromIdentifier(rendering_modes,
6231 STR_SPECIAL_RENDERING_DEFAULT);
6233 // if that also fails, set current rendering mode to first available one
6234 if (rendering_mode_current == NULL)
6235 rendering_mode_current = rendering_modes;
6238 setup.screen_rendering_mode = rendering_mode_current->identifier;
6240 // needed for displaying rendering mode text instead of identifier
6241 rendering_mode_text = rendering_mode_current->name;
6244 static void execSetupGraphics_setVsyncModes(boolean update_value)
6246 if (vsync_modes == NULL)
6250 for (i = 0; vsync_modes_list[i].value != NULL; i++)
6252 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6253 char identifier[32], name[32];
6254 char *value = vsync_modes_list[i].value;
6255 char *text = vsync_modes_list[i].text;
6257 ti->node_top = &vsync_modes;
6258 ti->sort_priority = i;
6260 sprintf(identifier, "%s", value);
6261 sprintf(name, "%s", text);
6263 setString(&ti->identifier, identifier);
6264 setString(&ti->name, name);
6265 setString(&ti->name_sorting, name);
6266 setString(&ti->infotext, STR_SETUP_CHOOSE_VSYNC);
6268 pushTreeInfo(&vsync_modes, ti);
6271 // sort vsync mode values to start with lowest vsync mode value
6272 sortTreeInfo(&vsync_modes);
6274 update_value = TRUE;
6279 // set current vsync mode value to configured vsync mode value
6280 vsync_mode_current =
6281 getTreeInfoFromIdentifier(vsync_modes, setup.vsync_mode);
6283 // if that fails, set current vsync mode to reliable default value
6284 if (vsync_mode_current == NULL)
6285 vsync_mode_current =
6286 getTreeInfoFromIdentifier(vsync_modes, STR_VSYNC_MODE_DEFAULT);
6288 // if that also fails, set current vsync mode to first available one
6289 if (vsync_mode_current == NULL)
6290 vsync_mode_current = vsync_modes;
6293 setup.vsync_mode = vsync_mode_current->identifier;
6295 // needed for displaying vsync mode text instead of identifier
6296 vsync_mode_text = vsync_mode_current->name;
6299 static void execSetupGraphics(void)
6301 boolean check_game_speed = (setup_mode == SETUP_MODE_CHOOSE_VSYNC);
6303 // update "setup.window_scaling_percent" from list selection
6304 // (in this case, window scaling was changed on setup screen)
6305 if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
6306 execSetupGraphics_setWindowSizes(FALSE);
6308 // update "setup.vsync_mode" from list selection
6309 // (in this case, vsync mode was changed on setup screen)
6310 if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
6311 execSetupGraphics_setVsyncModes(FALSE);
6313 // update list selection from "setup.window_scaling_percent"
6314 // (window scaling may have changed by resizing the window)
6315 execSetupGraphics_setWindowSizes(TRUE);
6317 // update list selection from "setup.vsync_mode"
6318 // (vsync_mode may have changed by re-creating the renderer)
6319 execSetupGraphics_setVsyncModes(TRUE);
6321 execSetupGraphics_setScalingTypes();
6322 execSetupGraphics_setRenderingModes();
6324 setup_mode = SETUP_MODE_GRAPHICS;
6328 // check if game speed is high enough for 60 Hz vsync to work
6329 if (check_game_speed)
6330 ModifyGameSpeedIfNeeded();
6332 // window scaling may have changed at this point
6333 ChangeWindowScalingIfNeeded();
6335 // window scaling quality may have changed at this point
6336 if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
6337 SDLSetWindowScalingQuality(setup.window_scaling_quality);
6339 // screen rendering mode may have changed at this point
6340 SDLSetScreenRenderingMode(setup.screen_rendering_mode);
6342 int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
6343 int video_vsync_mode = video.vsync_mode;
6345 // screen vsync mode may have changed at this point
6346 ChangeVsyncModeIfNeeded();
6348 // check if setting vsync mode to selected value failed
6349 if (setup_vsync_mode != video_vsync_mode &&
6350 setup_vsync_mode != video.vsync_mode)
6352 // changing vsync mode to selected value failed -- reset displayed value
6353 execSetupGraphics_setVsyncModes(TRUE);
6355 Request("Setting VSync failed!", REQ_CONFIRM);
6361 static void execSetupChooseWindowSize(void)
6363 setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
6368 static void execSetupChooseScalingType(void)
6370 setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
6375 static void execSetupChooseRenderingMode(void)
6377 setup_mode = SETUP_MODE_CHOOSE_RENDERING;
6382 static void execSetupChooseVsyncMode(void)
6384 setup_mode = SETUP_MODE_CHOOSE_VSYNC;
6389 static void execSetupChooseVolumeSimple(void)
6391 setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
6396 static void execSetupChooseVolumeLoops(void)
6398 setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
6403 static void execSetupChooseVolumeMusic(void)
6405 setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
6410 static void execSetupSound(void)
6412 if (volumes_simple == NULL)
6414 boolean current_volume_simple_found = FALSE;
6417 for (i = 0; volumes_list[i].value != -1; i++)
6419 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6420 char identifier[32], name[32];
6421 int value = volumes_list[i].value;
6422 char *text = volumes_list[i].text;
6424 ti->node_top = &volumes_simple;
6425 ti->sort_priority = value;
6427 sprintf(identifier, "%d", value);
6428 sprintf(name, "%s", text);
6430 setString(&ti->identifier, identifier);
6431 setString(&ti->name, name);
6432 setString(&ti->name_sorting, name);
6433 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6435 pushTreeInfo(&volumes_simple, ti);
6437 if (value == setup.volume_simple)
6438 current_volume_simple_found = TRUE;
6441 if (!current_volume_simple_found)
6443 // add entry for non-preset volume value
6445 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6446 char identifier[32], name[32];
6447 int value = setup.volume_simple;
6449 ti->node_top = &volumes_simple;
6450 ti->sort_priority = value;
6452 sprintf(identifier, "%d", value);
6453 sprintf(name, "%d %% (Current)", value);
6455 setString(&ti->identifier, identifier);
6456 setString(&ti->name, name);
6457 setString(&ti->name_sorting, name);
6458 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_SIMPLE);
6460 pushTreeInfo(&volumes_simple, ti);
6463 // sort volume values to start with lowest volume value
6464 sortTreeInfo(&volumes_simple);
6466 // set current volume value to configured volume value
6467 volume_simple_current =
6468 getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
6470 // if that fails, set current volume to reliable default value
6471 if (volume_simple_current == NULL)
6472 volume_simple_current =
6473 getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
6475 // if that also fails, set current volume to first available value
6476 if (volume_simple_current == NULL)
6477 volume_simple_current = volumes_simple;
6480 if (volumes_loops == NULL)
6482 boolean current_volume_loops_found = FALSE;
6485 for (i = 0; volumes_list[i].value != -1; i++)
6487 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6488 char identifier[32], name[32];
6489 int value = volumes_list[i].value;
6490 char *text = volumes_list[i].text;
6492 ti->node_top = &volumes_loops;
6493 ti->sort_priority = value;
6495 sprintf(identifier, "%d", value);
6496 sprintf(name, "%s", text);
6498 setString(&ti->identifier, identifier);
6499 setString(&ti->name, name);
6500 setString(&ti->name_sorting, name);
6501 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6503 pushTreeInfo(&volumes_loops, ti);
6505 if (value == setup.volume_loops)
6506 current_volume_loops_found = TRUE;
6509 if (!current_volume_loops_found)
6511 // add entry for non-preset volume value
6513 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6514 char identifier[32], name[32];
6515 int value = setup.volume_loops;
6517 ti->node_top = &volumes_loops;
6518 ti->sort_priority = value;
6520 sprintf(identifier, "%d", value);
6521 sprintf(name, "%d %% (Current)", value);
6523 setString(&ti->identifier, identifier);
6524 setString(&ti->name, name);
6525 setString(&ti->name_sorting, name);
6526 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_LOOPS);
6528 pushTreeInfo(&volumes_loops, ti);
6531 // sort volume values to start with lowest volume value
6532 sortTreeInfo(&volumes_loops);
6534 // set current volume value to configured volume value
6535 volume_loops_current =
6536 getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
6538 // if that fails, set current volume to reliable default value
6539 if (volume_loops_current == NULL)
6540 volume_loops_current =
6541 getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
6543 // if that also fails, set current volume to first available value
6544 if (volume_loops_current == NULL)
6545 volume_loops_current = volumes_loops;
6548 if (volumes_music == NULL)
6550 boolean current_volume_music_found = FALSE;
6553 for (i = 0; volumes_list[i].value != -1; i++)
6555 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6556 char identifier[32], name[32];
6557 int value = volumes_list[i].value;
6558 char *text = volumes_list[i].text;
6560 ti->node_top = &volumes_music;
6561 ti->sort_priority = value;
6563 sprintf(identifier, "%d", value);
6564 sprintf(name, "%s", text);
6566 setString(&ti->identifier, identifier);
6567 setString(&ti->name, name);
6568 setString(&ti->name_sorting, name);
6569 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6571 pushTreeInfo(&volumes_music, ti);
6573 if (value == setup.volume_music)
6574 current_volume_music_found = TRUE;
6577 if (!current_volume_music_found)
6579 // add entry for non-preset volume value
6581 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6582 char identifier[32], name[32];
6583 int value = setup.volume_music;
6585 ti->node_top = &volumes_music;
6586 ti->sort_priority = value;
6588 sprintf(identifier, "%d", value);
6589 sprintf(name, "%d %% (Current)", value);
6591 setString(&ti->identifier, identifier);
6592 setString(&ti->name, name);
6593 setString(&ti->name_sorting, name);
6594 setString(&ti->infotext, STR_SETUP_CHOOSE_VOLUME_MUSIC);
6596 pushTreeInfo(&volumes_music, ti);
6599 // sort volume values to start with lowest volume value
6600 sortTreeInfo(&volumes_music);
6602 // set current volume value to configured volume value
6603 volume_music_current =
6604 getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
6606 // if that fails, set current volume to reliable default value
6607 if (volume_music_current == NULL)
6608 volume_music_current =
6609 getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
6611 // if that also fails, set current volume to first available value
6612 if (volume_music_current == NULL)
6613 volume_music_current = volumes_music;
6616 setup.volume_simple = atoi(volume_simple_current->identifier);
6617 setup.volume_loops = atoi(volume_loops_current->identifier);
6618 setup.volume_music = atoi(volume_music_current->identifier);
6620 // needed for displaying volume text instead of identifier
6621 volume_simple_text = volume_simple_current->name;
6622 volume_loops_text = volume_loops_current->name;
6623 volume_music_text = volume_music_current->name;
6625 setup_mode = SETUP_MODE_SOUND;
6630 static void execSetupChooseTouchControls(void)
6632 setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
6637 static void execSetupChooseMoveDistance(void)
6639 setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
6644 static void execSetupChooseDropDistance(void)
6646 setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
6651 static void execSetupChooseTransparency(void)
6653 setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
6658 static void execSetupChooseGridXSize_0(void)
6660 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_0;
6665 static void execSetupChooseGridYSize_0(void)
6667 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_0;
6672 static void execSetupChooseGridXSize_1(void)
6674 setup_mode = SETUP_MODE_CHOOSE_GRID_XSIZE_1;
6679 static void execSetupChooseGridYSize_1(void)
6681 setup_mode = SETUP_MODE_CHOOSE_GRID_YSIZE_1;
6686 static void execSetupConfigureVirtualButtons(void)
6688 setup_mode = SETUP_MODE_CONFIG_VIRT_BUTTONS;
6690 ConfigureVirtualButtons();
6692 setup_mode = SETUP_MODE_TOUCH;
6697 static void execSetupTouch(void)
6701 if (touch_controls == NULL)
6703 for (i = 0; touch_controls_list[i].value != NULL; i++)
6705 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6706 char identifier[32], name[32];
6707 char *value = touch_controls_list[i].value;
6708 char *text = touch_controls_list[i].text;
6710 ti->node_top = &touch_controls;
6711 ti->sort_priority = i;
6713 sprintf(identifier, "%s", value);
6714 sprintf(name, "%s", text);
6716 setString(&ti->identifier, identifier);
6717 setString(&ti->name, name);
6718 setString(&ti->name_sorting, name);
6719 setString(&ti->infotext, STR_SETUP_CHOOSE_TOUCH_CONTROL);
6721 pushTreeInfo(&touch_controls, ti);
6724 // sort touch control values to start with lowest touch control value
6725 sortTreeInfo(&touch_controls);
6727 // set current touch control value to configured touch control value
6728 touch_control_current =
6729 getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
6731 // if that fails, set current touch control to reliable default value
6732 if (touch_control_current == NULL)
6733 touch_control_current =
6734 getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
6736 // if that also fails, set current touch control to first available value
6737 if (touch_control_current == NULL)
6738 touch_control_current = touch_controls;
6741 if (move_distances == NULL)
6743 for (i = 0; distances_list[i].value != -1; i++)
6745 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6746 char identifier[32], name[32];
6747 int value = distances_list[i].value;
6748 char *text = distances_list[i].text;
6750 ti->node_top = &move_distances;
6751 ti->sort_priority = value;
6753 sprintf(identifier, "%d", value);
6754 sprintf(name, "%s", text);
6756 setString(&ti->identifier, identifier);
6757 setString(&ti->name, name);
6758 setString(&ti->name_sorting, name);
6759 setString(&ti->infotext, STR_SETUP_CHOOSE_MOVE_DISTANCE);
6761 pushTreeInfo(&move_distances, ti);
6764 // sort distance values to start with lowest distance value
6765 sortTreeInfo(&move_distances);
6767 // set current distance value to configured distance value
6768 move_distance_current =
6769 getTreeInfoFromIdentifier(move_distances,
6770 i_to_a(setup.touch.move_distance));
6772 // if that fails, set current distance to reliable default value
6773 if (move_distance_current == NULL)
6774 move_distance_current =
6775 getTreeInfoFromIdentifier(move_distances,
6776 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
6778 // if that also fails, set current distance to first available value
6779 if (move_distance_current == NULL)
6780 move_distance_current = move_distances;
6783 if (drop_distances == NULL)
6785 for (i = 0; distances_list[i].value != -1; i++)
6787 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6788 char identifier[32], name[32];
6789 int value = distances_list[i].value;
6790 char *text = distances_list[i].text;
6792 ti->node_top = &drop_distances;
6793 ti->sort_priority = value;
6795 sprintf(identifier, "%d", value);
6796 sprintf(name, "%s", text);
6798 setString(&ti->identifier, identifier);
6799 setString(&ti->name, name);
6800 setString(&ti->name_sorting, name);
6801 setString(&ti->infotext, STR_SETUP_CHOOSE_DROP_DISTANCE);
6803 pushTreeInfo(&drop_distances, ti);
6806 // sort distance values to start with lowest distance value
6807 sortTreeInfo(&drop_distances);
6809 // set current distance value to configured distance value
6810 drop_distance_current =
6811 getTreeInfoFromIdentifier(drop_distances,
6812 i_to_a(setup.touch.drop_distance));
6814 // if that fails, set current distance to reliable default value
6815 if (drop_distance_current == NULL)
6816 drop_distance_current =
6817 getTreeInfoFromIdentifier(drop_distances,
6818 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
6820 // if that also fails, set current distance to first available value
6821 if (drop_distance_current == NULL)
6822 drop_distance_current = drop_distances;
6825 if (transparencies == NULL)
6827 for (i = 0; transparencies_list[i].value != -1; i++)
6829 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6830 char identifier[32], name[32];
6831 int value = transparencies_list[i].value;
6832 char *text = transparencies_list[i].text;
6834 ti->node_top = &transparencies;
6835 ti->sort_priority = value;
6837 sprintf(identifier, "%d", value);
6838 sprintf(name, "%s", text);
6840 setString(&ti->identifier, identifier);
6841 setString(&ti->name, name);
6842 setString(&ti->name_sorting, name);
6843 setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
6845 pushTreeInfo(&transparencies, ti);
6848 // sort transparency values to start with lowest transparency value
6849 sortTreeInfo(&transparencies);
6851 // set current transparency value to configured transparency value
6852 transparency_current =
6853 getTreeInfoFromIdentifier(transparencies,
6854 i_to_a(setup.touch.transparency));
6856 // if that fails, set current transparency to reliable default value
6857 if (transparency_current == NULL)
6858 transparency_current =
6859 getTreeInfoFromIdentifier(transparencies,
6860 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
6862 // if that also fails, set current transparency to first available value
6863 if (transparency_current == NULL)
6864 transparency_current = transparencies;
6867 for (i = 0; i < 2; i++)
6869 for (j = 0; j < 2; j++)
6871 if (grid_sizes[i][j] == NULL)
6873 for (k = 0; grid_sizes_list[k].value != -1; k++)
6875 TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
6876 char identifier[32], name[32];
6877 int value = grid_sizes_list[k].value;
6878 char *text = grid_sizes_list[k].text;
6880 ti->node_top = &grid_sizes[i][j];
6881 ti->sort_priority = value;
6883 sprintf(identifier, "%d", value);
6884 sprintf(name, "%s", text);
6886 setString(&ti->identifier, identifier);
6887 setString(&ti->name, name);
6888 setString(&ti->name_sorting, name);
6889 setString(&ti->infotext,
6892 STR_SETUP_CHOOSE_GRID_XSIZE_0 :
6893 STR_SETUP_CHOOSE_GRID_YSIZE_0) :
6895 STR_SETUP_CHOOSE_GRID_XSIZE_1 :
6896 STR_SETUP_CHOOSE_GRID_YSIZE_1)));
6898 pushTreeInfo(&grid_sizes[i][j], ti);
6901 // sort grid size values to start with lowest grid size value
6902 sortTreeInfo(&grid_sizes[i][j]);
6904 // set current grid size value to configured grid size value
6905 grid_size_current[i][j] =
6906 getTreeInfoFromIdentifier(grid_sizes[i][j],
6908 setup.touch.grid_xsize[i] :
6909 setup.touch.grid_ysize[i]));
6911 // if that fails, set current grid size to reliable default value
6912 if (grid_size_current[i][j] == NULL)
6913 grid_size_current[i][j] =
6914 getTreeInfoFromIdentifier(grid_sizes[i][j],
6916 DEFAULT_GRID_XSIZE(i) :
6917 DEFAULT_GRID_YSIZE(i)));
6919 // if that also fails, set current grid size to first available value
6920 if (grid_size_current[i][j] == NULL)
6921 grid_size_current[i][j] = grid_sizes[i][j];
6926 setup.touch.control_type = touch_control_current->identifier;
6927 setup.touch.move_distance = atoi(move_distance_current->identifier);
6928 setup.touch.drop_distance = atoi(drop_distance_current->identifier);
6929 setup.touch.transparency = atoi(transparency_current->identifier);
6931 for (i = 0; i < 2; i++)
6933 setup.touch.grid_xsize[i] = atoi(grid_size_current[i][0]->identifier);
6934 setup.touch.grid_ysize[i] = atoi(grid_size_current[i][1]->identifier);
6936 if (i == GRID_ACTIVE_NR())
6938 overlay.grid_xsize = setup.touch.grid_xsize[i];
6939 overlay.grid_ysize = setup.touch.grid_ysize[i];
6943 // needed for displaying value text instead of identifier
6944 touch_controls_text = touch_control_current->name;
6945 move_distance_text = move_distance_current->name;
6946 drop_distance_text = drop_distance_current->name;
6947 transparency_text = transparency_current->name;
6949 for (i = 0; i < 2; i++)
6950 for (j = 0; j < 2; j++)
6951 grid_size_text[i][j] = grid_size_current[i][j]->name;
6953 setup_mode = SETUP_MODE_TOUCH;
6958 static void execSetupArtwork(void)
6960 static ArtworkDirTree *gfx_last_valid = NULL;
6961 static ArtworkDirTree *snd_last_valid = NULL;
6962 static ArtworkDirTree *mus_last_valid = NULL;
6964 // current artwork directory may be invalid (level group, parent link)
6965 if (!validLevelSeries(artwork.gfx_current))
6966 artwork.gfx_current = getFirstValidTreeInfoEntry(gfx_last_valid);
6967 if (!validLevelSeries(artwork.snd_current))
6968 artwork.snd_current = getFirstValidTreeInfoEntry(snd_last_valid);
6969 if (!validLevelSeries(artwork.mus_current))
6970 artwork.mus_current = getFirstValidTreeInfoEntry(mus_last_valid);
6972 // store valid artwork directory information
6973 gfx_last_valid = artwork.gfx_current;
6974 snd_last_valid = artwork.snd_current;
6975 mus_last_valid = artwork.mus_current;
6978 Debug("screens:execSetupArtwork", "'%s', '%s', '%s'",
6979 artwork.gfx_current->subdir,
6980 artwork.gfx_current->fullpath,
6981 artwork.gfx_current->basepath);
6984 setup.graphics_set = artwork.gfx_current->identifier;
6985 setup.sounds_set = artwork.snd_current->identifier;
6986 setup.music_set = artwork.mus_current->identifier;
6988 // needed if last screen (setup choice) changed graphics, sounds or music
6989 ReloadCustomArtwork(0);
6991 // needed for displaying artwork name instead of artwork identifier
6992 graphics_set_name = artwork.gfx_current->name;
6993 sounds_set_name = artwork.snd_current->name;
6994 music_set_name = artwork.mus_current->name;
6996 setup_mode = SETUP_MODE_ARTWORK;
7001 static void execSetupChooseGraphics(void)
7003 setup_mode = SETUP_MODE_CHOOSE_GRAPHICS;
7008 static void execSetupChooseSounds(void)
7010 setup_mode = SETUP_MODE_CHOOSE_SOUNDS;
7015 static void execSetupChooseMusic(void)
7017 setup_mode = SETUP_MODE_CHOOSE_MUSIC;
7022 static void execSetupInput(void)
7024 setup_mode = SETUP_MODE_INPUT;
7029 static void execSetupShortcuts(void)
7031 setup_mode = SETUP_MODE_SHORTCUTS;
7036 static void execSetupShortcuts1(void)
7038 setup_mode = SETUP_MODE_SHORTCUTS_1;
7043 static void execSetupShortcuts2(void)
7045 setup_mode = SETUP_MODE_SHORTCUTS_2;
7050 static void execSetupShortcuts3(void)
7052 setup_mode = SETUP_MODE_SHORTCUTS_3;
7057 static void execSetupShortcuts4(void)
7059 setup_mode = SETUP_MODE_SHORTCUTS_4;
7064 static void execSetupShortcuts5(void)
7066 setup_mode = SETUP_MODE_SHORTCUTS_5;
7071 static void execExitSetup(void)
7073 SetGameStatus(GAME_MODE_MAIN);
7078 static void execSaveAndExitSetup(void)
7084 static void execGadgetNetworkServer(void)
7086 int gadget_id = SCREEN_CTRL_ID_NETWORK_SERVER;
7087 struct GadgetInfo *gi = screen_gadget[gadget_id];
7089 if (strEqual(setup.network_server_hostname, STR_NETWORK_AUTO_DETECT))
7090 network_server_hostname[0] = '\0';
7092 ModifyGadget(gi, GDI_TEXT_VALUE, network_server_hostname, GDI_END);
7096 ClickOnGadget(gi, MB_LEFTBUTTON);
7099 static void execOfferUploadTapes(void)
7104 static void ToggleNetworkModeIfNeeded(void)
7106 int font_title = FONT_TITLE_1;
7107 int font_foot = FC_BLUE;
7108 int ystart = mSY - SY + 16;
7109 int ybottom = mSY - SY + SYSIZE - 20;
7110 char *text = (setup.network_mode ? "Start Network" : "Stop Network");
7112 if (setup.network_mode == network.enabled)
7115 network.enabled = setup.network_mode;
7117 FadeOut(REDRAW_ALL);
7121 DrawTextSCentered(ystart, font_title, text);
7125 if (network.enabled)
7126 InitNetworkServer();
7128 DisconnectFromNetworkServer();
7130 DrawTextSCentered(ybottom, font_foot,
7131 "Press any key or button for setup menu");
7133 WaitForEventToContinue();
7138 static void ToggleGameSpeedsListIfNeeded(void)
7140 boolean using_game_speeds_extended = (game_speeds == game_speeds_extended);
7142 if (setup.game_speed_extended == using_game_speeds_extended)
7145 // try to match similar values when changing game speeds list
7146 if (setup.game_speed_extended)
7147 setup.game_frame_delay = (setup.game_frame_delay == 15 ? 16 :
7148 setup.game_frame_delay == 30 ? 29 :
7149 setup.game_frame_delay);
7151 setup.game_frame_delay = (setup.game_frame_delay == 14 ? 15 :
7152 setup.game_frame_delay == 16 ? 15 :
7153 setup.game_frame_delay >= 29 ? 30 :
7154 setup.game_frame_delay <= 10 ? 10 :
7155 setup.game_frame_delay);
7157 execSetupGame_setGameSpeeds(TRUE);
7162 static void ToggleUseApiServerIfNeeded(void)
7164 if (runtime.use_api_server == setup.use_api_server)
7167 runtime.use_api_server = setup.use_api_server;
7169 if (runtime.use_api_server)
7171 if (setup.has_remaining_tapes)
7172 setup.ask_for_uploading_tapes = TRUE;
7174 CheckApiServerTasks();
7178 static void ModifyGameSpeedIfNeeded(void)
7180 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7181 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY)
7185 char *game_speed_text = "Fast";
7186 int game_speed_value = 15;
7188 if (setup.game_speed_extended)
7190 game_speed_text = "60 fps";
7191 game_speed_value = 16;
7194 sprintf(message, "Game speed set to %s for VSync to work!", game_speed_text);
7196 // set game speed to existing list value that is fast enough for vsync
7197 setup.game_frame_delay = game_speed_value;
7199 execSetupGame_setGameSpeeds(TRUE);
7201 Request(message, REQ_CONFIRM);
7204 static void DisableVsyncIfNeeded(void)
7206 if (strEqual(setup.vsync_mode, STR_VSYNC_MODE_OFF) ||
7207 (setup.game_frame_delay >= MIN_VSYNC_FRAME_DELAY &&
7208 setup.game_frame_delay <= MAX_VSYNC_FRAME_DELAY))
7211 // disable vsync for the selected game speed to work
7212 setup.vsync_mode = STR_VSYNC_MODE_OFF;
7214 execSetupGraphics_setVsyncModes(TRUE);
7216 Request("VSync disabled for this game speed to work!", REQ_CONFIRM);
7222 void *related_value;
7223 } hide_related_entry_list[] =
7225 { &setup.network_server_hostname, execGadgetNetworkServer },
7226 { &setup.network_server_hostname, &network_server_text },
7228 { &setup.scores_in_highscore_list, execSetupChooseScoresType },
7229 { &setup.scores_in_highscore_list, &scores_type_text },
7231 { &setup.game_frame_delay, execSetupChooseGameSpeed },
7232 { &setup.game_frame_delay, &game_speed_text },
7234 { &setup.scroll_delay_value, execSetupChooseScrollDelay },
7235 { &setup.scroll_delay_value, &scroll_delay_text },
7237 { &setup.engine_snapshot_mode, execSetupChooseSnapshotMode },
7238 { &setup.engine_snapshot_mode, &snapshot_mode_text },
7240 { &setup.window_scaling_percent, execSetupChooseWindowSize },
7241 { &setup.window_scaling_percent, &window_size_text },
7243 { &setup.window_scaling_quality, execSetupChooseScalingType },
7244 { &setup.window_scaling_quality, &scaling_type_text },
7246 { &setup.screen_rendering_mode, execSetupChooseRenderingMode },
7247 { &setup.screen_rendering_mode, &rendering_mode_text },
7249 { &setup.vsync_mode, execSetupChooseVsyncMode },
7250 { &setup.vsync_mode, &vsync_mode_text },
7252 { &setup.graphics_set, execSetupChooseGraphics },
7253 { &setup.graphics_set, &graphics_set_name },
7255 { &setup.sounds_set, execSetupChooseSounds },
7256 { &setup.sounds_set, &sounds_set_name },
7258 { &setup.music_set, execSetupChooseMusic },
7259 { &setup.music_set, &music_set_name },
7261 { &setup.volume_simple, execSetupChooseVolumeSimple },
7262 { &setup.volume_simple, &volume_simple_text },
7264 { &setup.volume_loops, execSetupChooseVolumeLoops },
7265 { &setup.volume_loops, &volume_loops_text },
7267 { &setup.volume_music, execSetupChooseVolumeMusic },
7268 { &setup.volume_music, &volume_music_text },
7270 { &setup.touch.control_type, execSetupChooseTouchControls },
7271 { &setup.touch.control_type, &touch_controls_text },
7273 { &setup.touch.move_distance, execSetupChooseMoveDistance },
7274 { &setup.touch.move_distance, &move_distance_text },
7276 { &setup.touch.drop_distance, execSetupChooseDropDistance },
7277 { &setup.touch.drop_distance, &drop_distance_text },
7279 { &setup.touch.transparency, execSetupChooseTransparency },
7280 { &setup.touch.transparency, &transparency_text },
7282 { &setup.touch.grid_xsize[0], execSetupChooseGridXSize_0 },
7283 { &setup.touch.grid_xsize[0], &grid_size_text[0][0] },
7285 { &setup.touch.grid_ysize[0], execSetupChooseGridYSize_0 },
7286 { &setup.touch.grid_ysize[0], &grid_size_text[0][1] },
7288 { &setup.touch.grid_xsize[1], execSetupChooseGridXSize_1 },
7289 { &setup.touch.grid_xsize[1], &grid_size_text[1][0] },
7291 { &setup.touch.grid_ysize[1], execSetupChooseGridYSize_1 },
7292 { &setup.touch.grid_ysize[1], &grid_size_text[1][1] },
7294 { &setup.internal.menu_game, execSetupGame },
7295 { &setup.internal.menu_engines, execSetupEngines },
7296 { &setup.internal.menu_editor, execSetupEditor },
7297 { &setup.internal.menu_graphics, execSetupGraphics },
7298 { &setup.internal.menu_sound, execSetupSound },
7299 { &setup.internal.menu_artwork, execSetupArtwork },
7300 { &setup.internal.menu_input, execSetupInput },
7301 { &setup.internal.menu_touch, execSetupTouch },
7302 { &setup.internal.menu_shortcuts, execSetupShortcuts },
7303 { &setup.internal.menu_exit, execExitSetup },
7304 { &setup.internal.menu_save_and_exit, execSaveAndExitSetup },
7306 { &setup.internal.menu_shortcuts_various, execSetupShortcuts1 },
7307 { &setup.internal.menu_shortcuts_focus, execSetupShortcuts2 },
7308 { &setup.internal.menu_shortcuts_tape, execSetupShortcuts3 },
7309 { &setup.internal.menu_shortcuts_sound, execSetupShortcuts4 },
7310 { &setup.internal.menu_shortcuts_snap, execSetupShortcuts5 },
7312 { &setup.internal.info_title, execInfoTitleScreen },
7313 { &setup.internal.info_elements, execInfoElements },
7314 { &setup.internal.info_music, execInfoMusic },
7315 { &setup.internal.info_credits, execInfoCredits },
7316 { &setup.internal.info_program, execInfoProgram },
7317 { &setup.internal.info_version, execInfoVersion },
7318 { &setup.internal.info_levelset, execInfoLevelSet },
7319 { &setup.internal.info_exit, execExitInfo },
7324 void setHideRelatedSetupEntries(void)
7328 for (i = 0; hide_related_entry_list[i].value != NULL; i++)
7329 if (hideSetupEntry(hide_related_entry_list[i].value))
7330 setHideSetupEntry(hide_related_entry_list[i].related_value);
7333 static struct TokenInfo setup_info_main[] =
7335 { TYPE_ENTER_MENU, execSetupGame, STR_SETUP_GAME },
7336 { TYPE_ENTER_MENU, execSetupEngines, STR_SETUP_ENGINES },
7337 { TYPE_ENTER_MENU, execSetupEditor, STR_SETUP_EDITOR },
7338 { TYPE_ENTER_MENU, execSetupGraphics, STR_SETUP_GRAPHICS },
7339 { TYPE_ENTER_MENU, execSetupSound, STR_SETUP_SOUND },
7340 { TYPE_ENTER_MENU, execSetupArtwork, STR_SETUP_ARTWORK },
7341 { TYPE_ENTER_MENU, execSetupInput, STR_SETUP_INPUT },
7342 { TYPE_ENTER_MENU, execSetupTouch, STR_SETUP_TOUCH },
7343 { TYPE_ENTER_MENU, execSetupShortcuts, STR_SETUP_SHORTCUTS },
7344 { TYPE_EMPTY, NULL, "" },
7345 { TYPE_LEAVE_MENU, execExitSetup, STR_SETUP_EXIT },
7346 { TYPE_LEAVE_MENU, execSaveAndExitSetup, STR_SETUP_SAVE_AND_EXIT },
7351 static struct TokenInfo setup_info_game[] =
7353 { TYPE_SWITCH, &setup.team_mode, "Team-Mode (Multi-Player):" },
7354 { TYPE_SWITCH, &setup.network_mode, "Network Multi-Player Mode:" },
7355 { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" },
7356 { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" },
7357 { TYPE_STRING, &network_server_text, "" },
7358 { TYPE_SWITCH, &setup.use_api_server, "Use Highscore Server:" },
7359 { TYPE_ENTER_LIST, execSetupChooseScoresType,"Scores in Highscore List:" },
7360 { TYPE_STRING, &scores_type_text, "" },
7361 { TYPE_ENTER_LIST, execOfferUploadTapes, "Upload Tapes to Server" },
7362 { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" },
7363 { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" },
7364 { TYPE_SWITCH, &setup.time_limit, "Time Limit:" },
7365 { TYPE_SWITCH, &setup.handicap, "Force Solving Levels:" },
7366 { TYPE_SWITCH, &setup.skip_levels, "Allow Skipping Levels:" },
7367 { TYPE_SWITCH, &setup.increment_levels,"Increment Solved Levels:" },
7368 { TYPE_SWITCH, &setup.auto_play_next_level,"Auto-play Next Level:" },
7369 { TYPE_SWITCH, &setup.count_score_after_game,"Count Score After Game:" },
7370 { TYPE_SWITCH, &setup.show_scores_after_game,"Show Scores After Game:" },
7371 { TYPE_YES_NO, &setup.ask_on_game_over, "Ask on Game Over:" },
7372 { TYPE_YES_NO, &setup.ask_on_quit_game, "Ask on Quit Game:" },
7373 { TYPE_YES_NO, &setup.ask_on_quit_program, "Ask on Quit Program:" },
7374 { TYPE_SWITCH, &setup.autorecord, "Auto-Record When Playing:" },
7375 { TYPE_SWITCH, &setup.autorecord_after_replay, "Auto-Record After Replay:" },
7376 { TYPE_SWITCH, &setup.auto_pause_on_start, "Start Game in Pause Mode:" },
7377 { TYPE_ENTER_LIST, execSetupChooseGameSpeed, "Game Speed:" },
7378 { TYPE_STRING, &game_speed_text, "" },
7379 { TYPE_SWITCH, &setup.game_speed_extended, "Game Speed Extended List:" },
7381 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7382 { TYPE_STRING, &scroll_delay_text, "" },
7384 { TYPE_ENTER_LIST, execSetupChooseSnapshotMode,"Game Engine Snapshot Mode:" },
7385 { TYPE_STRING, &snapshot_mode_text, "" },
7386 { TYPE_SWITCH, &setup.show_load_save_buttons,"Show Load/Save Buttons:" },
7387 { TYPE_SWITCH, &setup.show_undo_redo_buttons,"Show Undo/Redo Buttons:" },
7388 { TYPE_EMPTY, NULL, "" },
7389 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7394 static struct TokenInfo setup_info_engines[] =
7396 { TYPE_HEADLINE, NULL, "Emerald Mine" },
7397 { TYPE_SWITCH, &setup.forced_scroll_delay, "Scroll Delay:" },
7398 { TYPE_ECS_AGA, &setup.prefer_aga_graphics, "Amiga Graphics Chipset:" },
7399 { TYPE_SWITCH, &setup.prefer_lowpass_sounds,"Low-Pass Filter Sounds:" },
7400 { TYPE_SWITCH, &setup.prefer_extra_panel_items,"Show Dynamite and Keys:" },
7401 { TYPE_EMPTY, NULL, "" },
7402 { TYPE_HEADLINE, NULL, "Supaplex" },
7403 { TYPE_SWITCH, &setup.sp_show_border_elements, "Border Elements:" },
7404 { TYPE_EMPTY, NULL, "" },
7405 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7410 static struct TokenInfo setup_info_editor[] =
7413 { TYPE_SWITCH, &setup.editor.el_boulderdash, "Boulder Dash:" },
7414 { TYPE_SWITCH, &setup.editor.el_emerald_mine, "Emerald Mine:" },
7415 { TYPE_SWITCH, &setup.editor.el_emerald_mine_club, "Emerald Mine Club:" },
7416 { TYPE_SWITCH, &setup.editor.el_more, "Rocks'n'Diamonds:" },
7417 { TYPE_SWITCH, &setup.editor.el_sokoban, "Sokoban:" },
7418 { TYPE_SWITCH, &setup.editor.el_supaplex, "Supaplex:" },
7419 { TYPE_SWITCH, &setup.editor.el_diamond_caves, "Diamond Caves II:" },
7420 { TYPE_SWITCH, &setup.editor.el_dx_boulderdash,"DX-Boulderdash:" },
7421 { TYPE_SWITCH, &setup.editor.el_chars, "Text Characters:" },
7422 { TYPE_SWITCH, &setup.editor.el_steel_chars, "Text Characters (Steel):" },
7424 { TYPE_SWITCH, &setup.editor.el_classic, "Classic Elements:" },
7425 { TYPE_SWITCH, &setup.editor.el_custom, "Custom & Group Elements:" },
7427 { TYPE_SWITCH, &setup.editor.el_headlines, "Headlines:" },
7429 { TYPE_SWITCH, &setup.editor.el_user_defined, "User defined element list:" },
7430 { TYPE_SWITCH, &setup.editor.el_dynamic, "Dynamic level elements:" },
7431 { TYPE_EMPTY, NULL, "" },
7433 { TYPE_SWITCH, &setup.editor.el_by_game, "Show elements by game:" },
7434 { TYPE_SWITCH, &setup.editor.el_by_type, "Show elements by type:" },
7435 { TYPE_EMPTY, NULL, "" },
7437 { TYPE_SWITCH, &setup.editor.show_element_token, "Show element token:" },
7438 { TYPE_EMPTY, NULL, "" },
7439 { TYPE_SWITCH, &setup.editor.show_read_only_warning, "Show read-only warning:" },
7440 { TYPE_EMPTY, NULL, "" },
7441 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7446 static struct TokenInfo setup_info_graphics[] =
7448 #if !defined(PLATFORM_ANDROID) && !defined(PLATFORM_EMSCRIPTEN)
7449 { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" },
7450 { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" },
7451 { TYPE_STRING, &window_size_text, "" },
7452 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" },
7453 { TYPE_STRING, &scaling_type_text, "" },
7454 { TYPE_ENTER_LIST, execSetupChooseRenderingMode, "Special Rendering:" },
7455 { TYPE_STRING, &rendering_mode_text, "" },
7458 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" },
7459 { TYPE_STRING, &scroll_delay_text, "" },
7461 #if !defined(PLATFORM_EMSCRIPTEN)
7462 { TYPE_ENTER_LIST, execSetupChooseVsyncMode, "Vertical Sync (VSync):" },
7463 { TYPE_STRING, &vsync_mode_text, "" },
7465 { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" },
7466 { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" },
7467 { TYPE_SWITCH, &setup.quick_doors, "Quick Menu Doors:" },
7468 { TYPE_SWITCH, &setup.show_titlescreen,"Show Title Screens:" },
7469 { TYPE_SWITCH, &setup.toons, "Show Menu Animations:" },
7470 { TYPE_SWITCH, &setup.small_game_graphics, "Small Game Graphics:" },
7471 { TYPE_YES_NO_AUTO, &setup.debug.xsn_mode, debug_xsn_mode },
7472 { TYPE_EMPTY, NULL, "" },
7473 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7478 static struct TokenInfo setup_info_sound[] =
7480 { TYPE_SWITCH, &setup.sound_simple, "Sound Effects (Normal):" },
7481 { TYPE_SWITCH, &setup.sound_loops, "Sound Effects (Looping):" },
7482 { TYPE_SWITCH, &setup.sound_music, "Music:" },
7483 { TYPE_EMPTY, NULL, "" },
7484 { TYPE_ENTER_LIST, execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
7485 { TYPE_STRING, &volume_simple_text, "" },
7486 { TYPE_ENTER_LIST, execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
7487 { TYPE_STRING, &volume_loops_text, "" },
7488 { TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
7489 { TYPE_STRING, &volume_music_text, "" },
7490 { TYPE_EMPTY, NULL, "" },
7491 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7496 static struct TokenInfo setup_info_artwork[] =
7498 { TYPE_ENTER_LIST, execSetupChooseGraphics,"Custom Graphics:" },
7499 { TYPE_STRING, &graphics_set_name, "" },
7500 { TYPE_ENTER_LIST, execSetupChooseSounds, "Custom Sounds:" },
7501 { TYPE_STRING, &sounds_set_name, "" },
7502 { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" },
7503 { TYPE_STRING, &music_set_name, "" },
7504 { TYPE_EMPTY, NULL, "" },
7505 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"},
7506 { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" },
7507 { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" },
7508 { TYPE_EMPTY, NULL, "" },
7509 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7514 static struct TokenInfo setup_info_input[] =
7516 { TYPE_SWITCH, NULL, "Player:" },
7517 { TYPE_SWITCH, NULL, "Device:" },
7518 { TYPE_SWITCH, NULL, "" },
7519 { TYPE_SKIPPABLE, NULL, "" },
7520 { TYPE_EMPTY, NULL, "" },
7521 { TYPE_EMPTY, NULL, "" },
7522 { TYPE_EMPTY, NULL, "" },
7523 { TYPE_EMPTY, NULL, "" },
7524 { TYPE_EMPTY, NULL, "" },
7525 { TYPE_EMPTY, NULL, "" },
7526 { TYPE_EMPTY, NULL, "" },
7527 { TYPE_EMPTY, NULL, "" },
7528 { TYPE_SKIPPABLE, NULL, "" },
7529 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7534 static struct TokenInfo setup_info_touch[] =
7536 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7537 { TYPE_STRING, &touch_controls_text, "" },
7538 { TYPE_EMPTY, NULL, "" },
7539 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7544 static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
7546 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7547 { TYPE_STRING, &touch_controls_text, "" },
7548 { TYPE_EMPTY, NULL, "" },
7549 { TYPE_ENTER_LIST, execSetupChooseGridXSize_0, "Horizontal Buttons (Landscape):" },
7550 { TYPE_STRING, &grid_size_text[0][0], "" },
7551 { TYPE_ENTER_LIST, execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):" },
7552 { TYPE_STRING, &grid_size_text[0][1], "" },
7553 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7554 { TYPE_STRING, &transparency_text, "" },
7555 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7556 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7557 { TYPE_EMPTY, NULL, "" },
7558 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7559 { TYPE_EMPTY, NULL, "" },
7560 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7565 static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
7567 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7568 { TYPE_STRING, &touch_controls_text, "" },
7569 { TYPE_EMPTY, NULL, "" },
7570 { TYPE_ENTER_LIST, execSetupChooseGridXSize_1, "Horizontal Buttons (Portrait):" },
7571 { TYPE_STRING, &grid_size_text[1][0], "" },
7572 { TYPE_ENTER_LIST, execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):" },
7573 { TYPE_STRING, &grid_size_text[1][1], "" },
7574 { TYPE_ENTER_LIST, execSetupChooseTransparency, "Button Transparency:" },
7575 { TYPE_STRING, &transparency_text, "" },
7576 { TYPE_SWITCH, &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
7577 { TYPE_SWITCH, &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
7578 { TYPE_EMPTY, NULL, "" },
7579 { TYPE_ENTER_LIST, execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
7580 { TYPE_EMPTY, NULL, "" },
7581 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7586 static struct TokenInfo *setup_info_touch_virtual_buttons[] =
7588 setup_info_touch_virtual_buttons_0,
7589 setup_info_touch_virtual_buttons_1
7592 static struct TokenInfo setup_info_touch_wipe_gestures[] =
7594 { TYPE_ENTER_LIST, execSetupChooseTouchControls, "Touch Control Type:" },
7595 { TYPE_STRING, &touch_controls_text, "" },
7596 { TYPE_EMPTY, NULL, "" },
7597 { TYPE_ENTER_LIST, execSetupChooseMoveDistance, "Move Trigger Distance:" },
7598 { TYPE_STRING, &move_distance_text, "" },
7599 { TYPE_ENTER_LIST, execSetupChooseDropDistance, "Drop Trigger Distance:" },
7600 { TYPE_STRING, &drop_distance_text, "" },
7601 { TYPE_EMPTY, NULL, "" },
7602 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7607 static struct TokenInfo setup_info_shortcuts[] =
7609 { TYPE_ENTER_MENU, execSetupShortcuts1, "Various Keys" },
7610 { TYPE_ENTER_MENU, execSetupShortcuts2, "Player Focus" },
7611 { TYPE_ENTER_MENU, execSetupShortcuts3, "Tape Buttons" },
7612 { TYPE_ENTER_MENU, execSetupShortcuts4, "Sound & Music" },
7613 { TYPE_ENTER_MENU, execSetupShortcuts5, "TAS Snap Keys" },
7614 { TYPE_EMPTY, NULL, "" },
7615 { TYPE_LEAVE_MENU, execSetupMain, "Back" },
7620 static struct TokenInfo setup_info_shortcuts_1[] =
7622 { TYPE_KEYTEXT, NULL, "Quick Save Game to Tape:", },
7623 { TYPE_KEY, &setup.shortcut.save_game, "" },
7624 { TYPE_KEYTEXT, NULL, "Quick Load Game from Tape:", },
7625 { TYPE_KEY, &setup.shortcut.load_game, "" },
7626 { TYPE_KEYTEXT, NULL, "Restart Game:", },
7627 { TYPE_KEY, &setup.shortcut.restart_game, "" },
7628 { TYPE_KEYTEXT, NULL, "Replay & Pause Before End:", },
7629 { TYPE_KEY, &setup.shortcut.pause_before_end, "" },
7630 { TYPE_KEYTEXT, NULL, "Start Game & Toggle Pause:", },
7631 { TYPE_KEY, &setup.shortcut.toggle_pause, "" },
7632 { TYPE_EMPTY, NULL, "" },
7633 { TYPE_YES_NO, &setup.ask_on_escape, "Ask on 'Esc' Key:" },
7634 { TYPE_YES_NO, &setup.ask_on_escape_editor, "Ask on 'Esc' Key (Editor):" },
7635 { TYPE_EMPTY, NULL, "" },
7636 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7641 static struct TokenInfo setup_info_shortcuts_2[] =
7643 { TYPE_KEYTEXT, NULL, "Set Focus to Player 1:", },
7644 { TYPE_KEY, &setup.shortcut.focus_player[0], "" },
7645 { TYPE_KEYTEXT, NULL, "Set Focus to Player 2:", },
7646 { TYPE_KEY, &setup.shortcut.focus_player[1], "" },
7647 { TYPE_KEYTEXT, NULL, "Set Focus to Player 3:", },
7648 { TYPE_KEY, &setup.shortcut.focus_player[2], "" },
7649 { TYPE_KEYTEXT, NULL, "Set Focus to Player 4:", },
7650 { TYPE_KEY, &setup.shortcut.focus_player[3], "" },
7651 { TYPE_KEYTEXT, NULL, "Set Focus to All Players:", },
7652 { TYPE_KEY, &setup.shortcut.focus_player_all, "" },
7653 { TYPE_EMPTY, NULL, "" },
7654 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7659 static struct TokenInfo setup_info_shortcuts_3[] =
7661 { TYPE_KEYTEXT, NULL, "Eject Tape:", },
7662 { TYPE_KEY, &setup.shortcut.tape_eject, "" },
7663 { TYPE_KEYTEXT, NULL, "Warp / Single Step:", },
7664 { TYPE_KEY, &setup.shortcut.tape_extra, "" },
7665 { TYPE_KEYTEXT, NULL, "Stop Tape:", },
7666 { TYPE_KEY, &setup.shortcut.tape_stop, "" },
7667 { TYPE_KEYTEXT, NULL, "Pause / Unpause Tape:",},
7668 { TYPE_KEY, &setup.shortcut.tape_pause, "" },
7669 { TYPE_KEYTEXT, NULL, "Record Tape:", },
7670 { TYPE_KEY, &setup.shortcut.tape_record, "" },
7671 { TYPE_KEYTEXT, NULL, "Play Tape:", },
7672 { TYPE_KEY, &setup.shortcut.tape_play, "" },
7673 { TYPE_EMPTY, NULL, "" },
7674 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7679 static struct TokenInfo setup_info_shortcuts_4[] =
7681 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Normal):", },
7682 { TYPE_KEY, &setup.shortcut.sound_simple, "" },
7683 { TYPE_KEYTEXT, NULL, "Toggle Sound Effects (Looping):", },
7684 { TYPE_KEY, &setup.shortcut.sound_loops, "" },
7685 { TYPE_KEYTEXT, NULL, "Toggle Music:", },
7686 { TYPE_KEY, &setup.shortcut.sound_music, "" },
7687 { TYPE_EMPTY, NULL, "" },
7688 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7693 static struct TokenInfo setup_info_shortcuts_5[] =
7695 { TYPE_KEYTEXT, NULL, "Snap Left:", },
7696 { TYPE_KEY, &setup.shortcut.snap_left, "" },
7697 { TYPE_KEYTEXT, NULL, "Snap Right:", },
7698 { TYPE_KEY, &setup.shortcut.snap_right, "" },
7699 { TYPE_KEYTEXT, NULL, "Snap Up:", },
7700 { TYPE_KEY, &setup.shortcut.snap_up, "" },
7701 { TYPE_KEYTEXT, NULL, "Snap Down:", },
7702 { TYPE_KEY, &setup.shortcut.snap_down, "" },
7703 { TYPE_EMPTY, NULL, "" },
7704 { TYPE_LEAVE_MENU, execSetupShortcuts, "Back" },
7709 static Key getSetupKey(void)
7711 Key key = KSYM_UNDEFINED;
7712 boolean got_key_event = FALSE;
7714 while (!got_key_event)
7718 if (NextValidEvent(&event))
7722 case EVENT_KEYPRESS:
7724 key = GetEventKey((KeyEvent *)&event);
7726 // press 'Escape' or 'Enter' to keep the existing key binding
7727 if (key == KSYM_Escape || key == KSYM_Return)
7728 key = KSYM_UNDEFINED; // keep old value
7730 got_key_event = TRUE;
7734 case EVENT_KEYRELEASE:
7735 key_joystick_mapping = 0;
7739 HandleOtherEvents(&event);
7750 static int getSetupValueFont(int type, void *value)
7752 if (type & TYPE_GHOSTED)
7753 return FONT_OPTION_OFF;
7754 else if (type & TYPE_KEY)
7755 return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1);
7756 else if (type & TYPE_STRING)
7757 return FONT_VALUE_2;
7758 else if (type & TYPE_ECS_AGA)
7759 return FONT_VALUE_1;
7760 else if (type & TYPE_BOOLEAN_STYLE)
7761 return (*(boolean *)value ? FONT_OPTION_ON : FONT_OPTION_OFF);
7762 else if (type & TYPE_YES_NO_AUTO)
7763 return (*(int *)value == AUTO ? FONT_OPTION_ON :
7764 *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
7765 else if (type & TYPE_PLAYER)
7766 return FONT_VALUE_1;
7768 return FONT_VALUE_1;
7771 static int getSetupValueFontNarrow(int type, int font_nr)
7773 return (font_nr == FONT_VALUE_1 ? FONT_VALUE_NARROW :
7774 font_nr == FONT_OPTION_ON ? FONT_OPTION_ON_NARROW :
7775 font_nr == FONT_OPTION_OFF ? FONT_OPTION_OFF_NARROW :
7779 static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
7781 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7782 struct TokenInfo *si = &setup_info[si_pos];
7783 boolean font_draw_xoffset_modified = FALSE;
7784 boolean scrollbar_needed = (num_setup_info < max_setup_info);
7785 int font_draw_xoffset_old = -1;
7786 int xoffset = (scrollbar_needed ? -1 : 0);
7787 int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
7788 int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
7789 int xpos = menu_screen_value_xpos;
7790 int ypos = MENU_SCREEN_START_YPOS + screen_pos;
7791 int startx = mSX + xpos * 32;
7792 int starty = mSY + ypos * 32;
7793 int type = si->type;
7794 void *value = si->value;
7795 char *value_string = getSetupValue(type, value);
7796 int font_nr_default = getSetupValueFont(type, value);
7797 int font_width_default = getFontWidth(font_nr_default);
7798 int font_nr = font_nr_default;
7801 if (value_string == NULL)
7804 if (type & TYPE_KEY)
7806 xpos = MENU_SCREEN_START_XPOS;
7808 if (type & TYPE_QUERY)
7809 value_string = "<press key>";
7811 else if (type & TYPE_STRING)
7813 int max_value_len = (SXSIZE - 2 * TILEX) / font_width_default;
7815 xpos = MENU_SCREEN_START_XPOS;
7817 if (strlen(value_string) > max_value_len)
7818 value_string[max_value_len] = '\0';
7820 else if (type & TYPE_YES_NO_AUTO)
7822 xpos = menu_screen_value_xpos - 1;
7824 else if (type & TYPE_PLAYER)
7826 int displayed_player_nr = *(int *)value + 1;
7828 value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
7831 startx = mSX + xpos * 32;
7832 starty = mSY + ypos * 32;
7834 // special check if right-side setup values moved left due to scrollbar
7835 if (scrollbar_needed && xpos > MENU_SCREEN_START_XPOS)
7837 int max_menu_text_length = 26; // maximum text length for classic menu
7838 int font_xoffset = getFontDrawOffsetX(font_nr);
7839 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7840 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7841 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7842 int text_width = max_menu_text_length * getFontWidth(text_font_nr);
7844 if (startx + font_xoffset < text_startx + text_width + text_font_xoffset)
7846 // when using narrow font, left-shifting text "auto" not needed
7847 if (type & TYPE_YES_NO_AUTO)
7851 startx = mSX + xpos * 32;
7853 font_nr = getSetupValueFontNarrow(type, font_nr);
7857 // downward compatibility correction for Juergen Bonhagen's menu settings
7858 if (setup_mode != SETUP_MODE_INPUT)
7860 int max_menu_text_length_big = (menu_screen_value_xpos -
7861 MENU_SCREEN_START_XPOS);
7862 int max_menu_text_length_medium = max_menu_text_length_big * 2;
7863 int check_font_nr = FONT_OPTION_ON; // known font that needs correction
7864 int font1_xoffset = getFontDrawOffsetX(font_nr);
7865 int font2_xoffset = getFontDrawOffsetX(check_font_nr);
7866 int text_startx = mSX + MENU_SCREEN_START_XPOS * 32;
7867 int text_font_nr = getMenuTextFont(FONT_MENU_2);
7868 int text_font_xoffset = getFontDrawOffsetX(text_font_nr);
7869 int text_width = max_menu_text_length_medium * getFontWidth(text_font_nr);
7870 boolean correct_font_draw_xoffset = FALSE;
7872 if (xpos == MENU_SCREEN_START_XPOS &&
7873 startx + font1_xoffset < text_startx + text_font_xoffset)
7874 correct_font_draw_xoffset = TRUE;
7876 if (xpos == menu_screen_value_xpos &&
7877 startx + font2_xoffset < text_startx + text_width + text_font_xoffset)
7878 correct_font_draw_xoffset = TRUE;
7880 // check if setup value would overlap with setup text when printed
7881 // (this can happen for extreme/wrong values for font draw offset)
7882 if (correct_font_draw_xoffset)
7884 font_draw_xoffset_old = getFontDrawOffsetX(font_nr);
7885 font_draw_xoffset_modified = TRUE;
7887 if (type & TYPE_KEY)
7888 getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr);
7889 else if (!(type & TYPE_STRING))
7890 getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 -
7891 max_menu_text_length_medium * (16 - getFontWidth(text_font_nr));
7895 for (i = 0; i <= menu_screen_max_xpos - xpos; i++)
7896 DrawText(startx + i * font_width_default, starty, " ", font_nr_default);
7898 DrawText(startx, starty, value_string, font_nr);
7900 if (type & TYPE_PLAYER)
7902 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
7903 int player_nr = *(int *)value;
7904 int xoff = font->draw_xoffset + getFontWidth(font_nr);
7905 int yoff = font->draw_yoffset + (getFontHeight(font_nr) - TILEY) / 2;
7906 int startx2 = startx + xoff;
7907 int starty2 = starty + yoff;
7909 if (DrawingOnBackground(startx2, starty2))
7910 ClearRectangleOnBackground(drawto, startx2, starty2, TILEX, TILEY);
7912 DrawFixedGraphicThruMaskExt(drawto, startx2, starty2,
7913 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
7916 if (font_draw_xoffset_modified)
7917 getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
7920 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
7922 int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw);
7923 struct TokenInfo *si = &setup_info[si_pos];
7925 if (si->type & TYPE_BOOLEAN_STYLE)
7927 *(boolean *)si->value ^= TRUE;
7929 else if (si->type & TYPE_YES_NO_AUTO)
7933 (*(int *)si->value == AUTO ? TRUE :
7934 *(int *)si->value == TRUE ? FALSE : AUTO) :
7935 (*(int *)si->value == TRUE ? AUTO :
7936 *(int *)si->value == AUTO ? FALSE : TRUE));
7938 else if (si->type & TYPE_KEY)
7942 si->type |= TYPE_QUERY;
7943 drawSetupValue(screen_pos, setup_info_pos_raw);
7944 si->type &= ~TYPE_QUERY;
7946 key = getSetupKey();
7947 if (key != KSYM_UNDEFINED)
7948 *(Key *)si->value = key;
7950 else if (si->type & TYPE_PLAYER)
7952 int player_nr = *(int *)si->value;
7957 player_nr = Request("Choose player", REQ_PLAYER) - 1;
7959 *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
7962 drawSetupValue(screen_pos, setup_info_pos_raw);
7964 // fullscreen state may have changed at this point
7965 if (si->value == &setup.fullscreen)
7966 ToggleFullscreenIfNeeded();
7968 // network mode may have changed at this point
7969 if (si->value == &setup.network_mode)
7970 ToggleNetworkModeIfNeeded();
7972 // API server mode may have changed at this point
7973 if (si->value == &setup.use_api_server)
7974 ToggleUseApiServerIfNeeded();
7976 // game speed list may have changed at this point
7977 if (si->value == &setup.game_speed_extended)
7978 ToggleGameSpeedsListIfNeeded();
7981 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
7983 static struct TokenInfo *setup_info_final = NULL;
7988 // determine maximum list size of target list
7989 while (setup_info_orig[list_size++].type != 0);
7991 // free, allocate and clear memory for target list
7992 checked_free(setup_info_final);
7993 setup_info_final = checked_calloc(list_size * sizeof(struct TokenInfo));
7995 // copy setup info list without setup entries marked as hidden
7996 for (i = 0; setup_info_orig[i].type != 0; i++)
7998 // skip setup entries configured to be hidden
7999 if (hideSetupEntry(setup_info_orig[i].value))
8002 // skip skippable setup entries if screen is lower than usual
8003 if (SCR_FIELDY < SCR_FIELDY_DEFAULT &&
8004 setup_info_orig[i].type == TYPE_SKIPPABLE)
8007 setup_info_final[list_pos++] = setup_info_orig[i];
8010 return setup_info_final;
8013 static void DrawSetupScreen_Generic(void)
8015 int fade_mask = REDRAW_FIELD;
8016 boolean redraw_all = FALSE;
8017 char *title_string = NULL;
8021 fade_mask = REDRAW_ALL;
8024 FadeMenuSoundsAndMusic();
8026 FreeScreenGadgets();
8027 CreateScreenGadgets();
8029 if (redraw_mask & REDRAW_ALL)
8034 // needed if different viewport properties defined for setup screen
8035 ChangeViewportPropertiesIfNeeded();
8037 SetMainBackgroundImage(IMG_BACKGROUND_SETUP);
8041 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
8043 if (setup_mode == SETUP_MODE_MAIN)
8045 setup_info = setup_info_main;
8046 title_string = STR_SETUP_MAIN;
8048 else if (setup_mode == SETUP_MODE_GAME)
8050 setup_info = setup_info_game;
8051 title_string = STR_SETUP_GAME;
8053 else if (setup_mode == SETUP_MODE_ENGINES)
8055 setup_info = setup_info_engines;
8056 title_string = STR_SETUP_ENGINES;
8058 else if (setup_mode == SETUP_MODE_EDITOR)
8060 setup_info = setup_info_editor;
8061 title_string = STR_SETUP_EDITOR;
8063 else if (setup_mode == SETUP_MODE_GRAPHICS)
8065 setup_info = setup_info_graphics;
8066 title_string = STR_SETUP_GRAPHICS;
8068 else if (setup_mode == SETUP_MODE_SOUND)
8070 setup_info = setup_info_sound;
8071 title_string = STR_SETUP_SOUND;
8073 else if (setup_mode == SETUP_MODE_ARTWORK)
8075 setup_info = setup_info_artwork;
8076 title_string = STR_SETUP_ARTWORK;
8078 else if (setup_mode == SETUP_MODE_TOUCH)
8080 setup_info = setup_info_touch;
8081 title_string = STR_SETUP_TOUCH;
8083 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
8084 setup_info = setup_info_touch_virtual_buttons[GRID_ACTIVE_NR()];
8085 else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
8086 setup_info = setup_info_touch_wipe_gestures;
8088 else if (setup_mode == SETUP_MODE_SHORTCUTS)
8090 setup_info = setup_info_shortcuts;
8091 title_string = STR_SETUP_SHORTCUTS;
8093 else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
8095 setup_info = setup_info_shortcuts_1;
8096 title_string = STR_SETUP_SHORTCUTS;
8098 else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
8100 setup_info = setup_info_shortcuts_2;
8101 title_string = STR_SETUP_SHORTCUTS;
8103 else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
8105 setup_info = setup_info_shortcuts_3;
8106 title_string = STR_SETUP_SHORTCUTS;
8108 else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
8110 setup_info = setup_info_shortcuts_4;
8111 title_string = STR_SETUP_SHORTCUTS;
8113 else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
8115 setup_info = setup_info_shortcuts_5;
8116 title_string = STR_SETUP_SHORTCUTS;
8119 // use modified setup info without setup entries marked as hidden
8120 setup_info = getSetupInfoFinal(setup_info);
8122 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
8124 // determine maximal number of setup entries that can be displayed on screen
8126 for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
8129 // determine maximal number of setup entries available for this setup screen
8131 for (i = 0; setup_info[i].type != 0; i++)
8134 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
8136 MapScreenGadgets(max_setup_info);
8139 redraw_mask = fade_mask = REDRAW_ALL;
8141 DrawMaskedBorder(fade_mask);
8146 void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
8148 menu_info = setup_info;
8150 HandleMenuScreen(mx, my, dx, dy, button,
8151 setup_mode, num_setup_info, max_setup_info);
8154 static void DrawSetupScreen_Input(void)
8158 FadeOut(REDRAW_FIELD);
8162 setup_info = getSetupInfoFinal(setup_info_input);
8164 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, STR_SETUP_INPUT);
8166 for (i = 0; setup_info[i].type != 0; i++)
8168 if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
8169 initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
8170 else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
8171 initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
8172 else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
8173 initCursor(i, IMG_MENU_BUTTON);
8175 DrawCursorAndText_Setup(i, -1, FALSE);
8178 // create gadgets for setup input menu screen
8179 FreeScreenGadgets();
8180 CreateScreenGadgets();
8182 // map gadgets for setup input menu screen
8183 MapScreenMenuGadgets(SCREEN_MASK_INPUT);
8185 HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE);
8187 FadeIn(REDRAW_FIELD);
8190 static void setJoystickDeviceToNr(char *device_name, int device_nr)
8192 if (device_name == NULL)
8195 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
8198 if (strlen(device_name) > 1)
8200 char c1 = device_name[strlen(device_name) - 1];
8201 char c2 = device_name[strlen(device_name) - 2];
8203 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
8204 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
8207 strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
8208 strlen(device_name));
8211 static void drawPlayerSetupInputInfo(int player_nr, boolean active)
8214 static struct SetupKeyboardInfo custom_key;
8221 { &custom_key.left, "Axis/Pad Left" },
8222 { &custom_key.right, "Axis/Pad Right" },
8223 { &custom_key.up, "Axis/Pad Up" },
8224 { &custom_key.down, "Axis/Pad Down" },
8225 { &custom_key.snap, "Button 1/A/X" },
8226 { &custom_key.drop, "Button 2/B/Y" }
8228 static char *joystick_name[MAX_PLAYERS] =
8235 int font_nr_menu = (active ? FONT_MENU_1_ACTIVE : FONT_MENU_1);
8236 int font_nr_info = FONT_MENU_1;
8237 int font_nr_name = FONT_VALUE_OLD;
8238 int font_nr_on = FONT_VALUE_1;
8239 int font_nr_off = FONT_VALUE_OLD;
8242 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8244 font_nr_info = FONT_MENU_2;
8245 font_nr_on = FONT_VALUE_NARROW;
8246 font_nr_off = FONT_VALUE_OLD_NARROW;
8249 custom_key = setup.input[player_nr].key;
8251 DrawText(mSX + 11 * 32, mSY + 2 * 32, int2str(player_nr + 1, 1),
8252 FONT_INPUT_1_ACTIVE);
8254 ClearRectangleOnBackground(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8256 DrawFixedGraphicThruMaskExt(drawto, mSX + 8 * TILEX, mSY + 2 * TILEY,
8257 PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
8259 if (setup.input[player_nr].use_joystick)
8261 char *device_name = setup.input[player_nr].joy.device_name;
8262 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8263 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8264 char *text = joystick_name[joystick_nr];
8265 int font_nr = (joystick_active ? font_nr_on : font_nr_off);
8267 DrawText(mSX + 8 * 32, mSY + 3 * 32, text, font_nr);
8268 DrawText(mSX + 32, mSY + 4 * 32, "Configure", font_nr_menu);
8272 DrawText(mSX + 8 * 32, mSY + 3 * 32, "Keyboard ", font_nr_on);
8273 DrawText(mSX + 1 * 32, mSY + 4 * 32, "Customize", font_nr_menu);
8276 if (SCR_FIELDY >= SCR_FIELDY_DEFAULT)
8277 DrawText(mSX + 32, mSY + 5 * 32, "Actual Settings:", font_nr_info);
8281 drawCursorXY(1, pos + 0, IMG_MENU_BUTTON_LEFT);
8282 drawCursorXY(1, pos + 1, IMG_MENU_BUTTON_RIGHT);
8283 drawCursorXY(1, pos + 2, IMG_MENU_BUTTON_UP);
8284 drawCursorXY(1, pos + 3, IMG_MENU_BUTTON_DOWN);
8286 DrawText(mSX + 2 * 32, mSY + (pos + 2) * 32, ":", font_nr_name);
8287 DrawText(mSX + 2 * 32, mSY + (pos + 3) * 32, ":", font_nr_name);
8288 DrawText(mSX + 2 * 32, mSY + (pos + 4) * 32, ":", font_nr_name);
8289 DrawText(mSX + 2 * 32, mSY + (pos + 5) * 32, ":", font_nr_name);
8290 DrawText(mSX + 1 * 32, mSY + (pos + 6) * 32, "Snap Field:", font_nr_name);
8291 DrawText(mSX + 1 * 32, mSY + (pos + 8) * 32, "Drop Element:", font_nr_name);
8293 for (i = 0; i < 6; i++)
8295 int ypos = (pos + 2) + i + (i > 3 ? i - 3 : 0);
8297 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8299 DrawText(mSX + 3 * 32, mSY + ypos * 32,
8300 (setup.input[player_nr].use_joystick ?
8302 getKeyNameFromKey(*custom[i].key)), font_nr_on);
8306 static int input_player_nr = 0;
8308 static void HandleSetupScreen_Input_Player(int step, int direction)
8310 int old_player_nr = input_player_nr;
8313 new_player_nr = old_player_nr + step * direction;
8314 if (new_player_nr < 0)
8316 if (new_player_nr > MAX_PLAYERS - 1)
8317 new_player_nr = MAX_PLAYERS - 1;
8319 if (new_player_nr != old_player_nr)
8321 input_player_nr = new_player_nr;
8323 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8327 void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
8329 static int choice = 0;
8332 int pos_start = SETUPINPUT_SCREEN_POS_START;
8333 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
8334 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
8335 int pos_end = SETUPINPUT_SCREEN_POS_END;
8337 if (SCR_FIELDY < SCR_FIELDY_DEFAULT)
8341 for (i = 0; setup_info_input[i].type != 0; i++)
8343 // adjust menu structure according to skipped setup entries
8344 if (setup_info_input[i].type == TYPE_SKIPPABLE)
8352 if (button == MB_MENU_INITIALIZE)
8354 // input setup menu may have changed size due to graphics configuration
8355 if (choice >= pos_empty1)
8358 drawPlayerSetupInputInfo(input_player_nr, (choice == 2));
8360 DrawCursorAndText_Setup(choice, -1, TRUE);
8364 else if (button == MB_MENU_LEAVE)
8366 setup_mode = SETUP_MODE_MAIN;
8373 if (mx || my) // mouse input
8375 x = (mx - mSX) / 32;
8376 y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
8378 else if (dx || dy) // keyboard input
8380 if (dx && choice == 0)
8381 x = (dx < 0 ? 10 : 12);
8382 else if ((dx && choice == 1) ||
8383 (dx == -1 && choice == pos_end))
8384 button = MB_MENU_CHOICE;
8388 if (y >= pos_empty1 && y <= pos_empty2)
8389 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
8392 if (y == 0 && dx != 0 && button)
8394 HandleSetupScreen_Input_Player(1, dx < 0 ? -1 : +1);
8396 else if (IN_VIS_FIELD(x, y) && // (does not use "IN_VIS_MENU()" yet)
8397 y >= pos_start && y <= pos_end &&
8398 !(y >= pos_empty1 && y <= pos_empty2))
8404 DrawCursorAndText_Setup(choice, -1, FALSE);
8405 DrawCursorAndText_Setup(y, -1, TRUE);
8407 drawPlayerSetupInputInfo(input_player_nr, (y == 2));
8416 char *device_name = setup.input[input_player_nr].joy.device_name;
8418 if (!setup.input[input_player_nr].use_joystick)
8420 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
8422 setJoystickDeviceToNr(device_name, new_device_nr);
8423 setup.input[input_player_nr].use_joystick = TRUE;
8427 int device_nr = getJoystickNrFromDeviceName(device_name);
8428 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
8430 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
8431 setup.input[input_player_nr].use_joystick = FALSE;
8433 setJoystickDeviceToNr(device_name, new_device_nr);
8436 drawPlayerSetupInputInfo(input_player_nr, FALSE);
8440 if (setup.input[input_player_nr].use_joystick)
8441 ConfigureJoystick(input_player_nr);
8443 CustomizeKeyboard(input_player_nr);
8445 else if (y == pos_end)
8451 setup_mode = SETUP_MODE_MAIN;
8458 static boolean CustomizeKeyboardMain(int player_nr)
8462 boolean finished = FALSE;
8463 static struct SetupKeyboardInfo custom_key;
8468 } customize_step[] =
8470 { &custom_key.left, "Move Left" },
8471 { &custom_key.right, "Move Right" },
8472 { &custom_key.up, "Move Up" },
8473 { &custom_key.down, "Move Down" },
8474 { &custom_key.snap, "Snap Field" },
8475 { &custom_key.drop, "Drop Element" }
8477 int font_nr_old = FONT_VALUE_OLD;
8478 int font_nr_new = FONT_VALUE_1;
8479 boolean success = FALSE;
8481 if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
8483 font_nr_old = FONT_VALUE_OLD_NARROW;
8484 font_nr_new = FONT_VALUE_NARROW;
8487 // read existing key bindings from player setup
8488 custom_key = setup.input[player_nr].key;
8491 FadeOut(REDRAW_FIELD);
8495 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input");
8498 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8499 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8500 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8501 "Key:", FONT_INPUT_1_ACTIVE);
8502 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8503 getKeyNameFromKey(*customize_step[step_nr].key), font_nr_old);
8505 FadeIn(REDRAW_FIELD);
8510 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8512 // reset frame delay counter directly after updating screen
8513 ResetDelayCounter(&event_frame_delay);
8515 while (NextValidEvent(&event))
8519 case EVENT_KEYPRESS:
8521 Key key = GetEventKey((KeyEvent *)&event);
8523 // press 'Escape' to abort and keep the old key bindings
8524 if (key == KSYM_Escape)
8526 FadeSkipNextFadeIn();
8533 // press 'Enter' to keep the existing key binding
8534 if (key == KSYM_Return)
8535 key = *customize_step[step_nr].key;
8537 // check if key already used
8538 for (i = 0; i < step_nr; i++)
8539 if (*customize_step[i].key == key)
8544 // got new key binding
8545 *customize_step[step_nr].key = key;
8546 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8548 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8549 getKeyNameFromKey(key), font_nr_new);
8552 // un-highlight last query
8553 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1)) * 32,
8554 customize_step[step_nr - 1].text, FONT_MENU_1);
8555 DrawText(mSX, mSY + (2 + 2 * (step_nr - 1) + 1) * 32,
8556 "Key:", FONT_MENU_1);
8558 // all keys configured
8567 // query next key binding
8568 DrawText(mSX, mSY + (2 + 2 * step_nr) * 32,
8569 customize_step[step_nr].text, FONT_INPUT_1_ACTIVE);
8570 DrawText(mSX, mSY + (2 + 2 * step_nr + 1) * 32,
8571 "Key:", FONT_INPUT_1_ACTIVE);
8572 DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32,
8573 getKeyNameFromKey(*customize_step[step_nr].key),
8578 case EVENT_KEYRELEASE:
8579 key_joystick_mapping = 0;
8583 HandleOtherEvents(&event);
8587 // do not handle events for longer than standard frame delay period
8588 if (DelayReached(&event_frame_delay))
8595 // write new key bindings back to player setup, if successfully finished
8597 setup.input[player_nr].key = custom_key;
8602 void CustomizeKeyboard(int player_nr)
8604 boolean success = CustomizeKeyboardMain(player_nr);
8608 int font_nr = FONT_TITLE_1;
8609 int font_height = getFontHeight(font_nr);
8610 int ypos1 = SYSIZE / 2 - font_height * 2;
8611 int ypos2 = SYSIZE / 2 - font_height * 1;
8612 DelayCounter wait_frame_delay = { 2000 };
8614 ResetDelayCounter(&wait_frame_delay);
8618 DrawTextSCentered(ypos1, font_nr, "Keyboard");
8619 DrawTextSCentered(ypos2, font_nr, "configured!");
8621 while (!DelayReached(&wait_frame_delay))
8627 DrawSetupScreen_Input();
8630 // game controller mapping generator by Gabriel Jacobo <gabomdq@gmail.com>
8632 #define MARKER_BUTTON 1
8633 #define MARKER_AXIS_X 2
8634 #define MARKER_AXIS_Y 3
8636 static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
8638 static boolean bitmaps_initialized = FALSE;
8639 boolean screen_initialized = FALSE;
8640 static Bitmap *controller, *button, *axis_x, *axis_y;
8642 boolean success = TRUE;
8643 boolean done = FALSE, next = FALSE;
8645 int alpha = 200, alpha_step = -1;
8646 int alpha_ticks = 0;
8647 char mapping[4096], temp[256];
8648 int font_name = MENU_SETUP_FONT_TITLE;
8649 int font_info = MENU_SETUP_FONT_TEXT;
8650 int spacing_name = menu.line_spacing_setup[SETUP_MODE_INPUT];
8651 int spacing_line = menu.line_spacing_setup[SETUP_MODE_INPUT];
8652 int spacing_para = menu.paragraph_spacing_setup[SETUP_MODE_INPUT];
8653 int ystep_name = getMenuTextStep(spacing_name, font_name);
8654 int ystep_line = getMenuTextStep(spacing_line, font_info);
8655 int ystep_para = getMenuTextStep(spacing_para, font_info);
8663 int axis, button, hat, hat_value;
8666 *step, *prev_step, steps[] =
8668 { 356, 155, MARKER_BUTTON, "a", },
8669 { 396, 122, MARKER_BUTTON, "b", },
8670 { 320, 125, MARKER_BUTTON, "x", },
8671 { 358, 95, MARKER_BUTTON, "y", },
8672 { 162, 125, MARKER_BUTTON, "back", },
8673 { 216, 125, MARKER_BUTTON, "guide", },
8674 { 271, 125, MARKER_BUTTON, "start", },
8675 { 110, 200, MARKER_BUTTON, "dpleft", },
8676 { 146, 228, MARKER_BUTTON, "dpdown", },
8677 { 178, 200, MARKER_BUTTON, "dpright", },
8678 { 146, 172, MARKER_BUTTON, "dpup", },
8679 { 50, 40, MARKER_BUTTON, "leftshoulder", },
8680 { 88, -10, MARKER_AXIS_Y, "lefttrigger", },
8681 { 382, 40, MARKER_BUTTON, "rightshoulder", },
8682 { 346, -10, MARKER_AXIS_Y, "righttrigger", },
8683 { 73, 141, MARKER_BUTTON, "leftstick", },
8684 { 282, 210, MARKER_BUTTON, "rightstick", },
8685 { 73, 141, MARKER_AXIS_X, "leftx", },
8686 { 73, 141, MARKER_AXIS_Y, "lefty", },
8687 { 282, 210, MARKER_AXIS_X, "rightx", },
8688 { 282, 210, MARKER_AXIS_Y, "righty", },
8691 if (!bitmaps_initialized)
8693 controller = LoadCustomImage("joystick/controller.png");
8694 button = LoadCustomImage("joystick/button.png");
8695 axis_x = LoadCustomImage("joystick/axis_x.png");
8696 axis_y = LoadCustomImage("joystick/axis_y.png");
8698 bitmaps_initialized = TRUE;
8701 name = getFormattedJoystickName(SDL_JoystickName(joystick));
8704 // print info about the joystick we are watching
8705 Debug("joystick", "watching joystick %d: (%s)",
8706 SDL_JoystickInstanceID(joystick), name);
8707 Debug("joystick", "joystick has %d axes, %d hats, %d balls, and %d buttons",
8708 SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
8709 SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
8712 // initialize mapping with GUID and name
8713 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, sizeof(temp));
8715 snprintf(mapping, sizeof(mapping), "%s,%s,platform:%s,",
8716 temp, name, SDL_GetPlatform());
8718 // loop through all steps (buttons and axes), getting joystick events
8719 for (i = 0; i < SDL_arraysize(steps) && !done;)
8721 Bitmap *marker = button; // initialize with reliable default value
8724 strcpy(step->mapping, mapping);
8728 step->hat_value = -1;
8730 marker = (step->marker == MARKER_BUTTON ? button :
8731 step->marker == MARKER_AXIS_X ? axis_x :
8732 step->marker == MARKER_AXIS_Y ? axis_y : marker);
8736 while (!done && !next)
8738 alpha += alpha_step * (int)(SDL_GetTicks() - alpha_ticks) / 5;
8739 alpha_ticks = SDL_GetTicks();
8746 else if (alpha < 128)
8752 int controller_x = SX + (SXSIZE - controller->width) / 2;
8753 int controller_y = SY + ystep_line;
8755 int marker_x = controller_x + step->x;
8756 int marker_y = controller_y + step->y;
8758 int ystart1 = mSY - 2 * SY + controller_y + controller->height;
8759 int ystart2 = ystart1 + ystep_name + ystep_line;
8763 DrawTextSCentered(ystart1, font_name, name);
8765 DrawTextSCentered(ystart2, font_info,
8766 "Press buttons and move axes on");
8767 ystart2 += ystep_line;
8768 DrawTextSCentered(ystart2, font_info,
8769 "your controller when indicated.");
8770 ystart2 += ystep_line;
8771 DrawTextSCentered(ystart2, font_info,
8772 "(Your controller may look different.)");
8773 ystart2 += ystep_para;
8775 #if defined(PLATFORM_ANDROID)
8776 DrawTextSCentered(ystart2, font_info,
8777 "To correct a mistake,");
8778 ystart2 += ystep_line;
8779 DrawTextSCentered(ystart2, font_info,
8780 "press the 'back' button.");
8781 ystart2 += ystep_line;
8782 DrawTextSCentered(ystart2, font_info,
8783 "To skip a button or axis,");
8784 ystart2 += ystep_line;
8785 DrawTextSCentered(ystart2, font_info,
8786 "press the 'menu' button.");
8788 DrawTextSCentered(ystart2, font_info,
8789 "To correct a mistake,");
8790 ystart2 += ystep_line;
8791 DrawTextSCentered(ystart2, font_info,
8792 "press the 'backspace' key.");
8793 ystart2 += ystep_line;
8794 DrawTextSCentered(ystart2, font_info,
8795 "To skip a button or axis,");
8796 ystart2 += ystep_line;
8797 DrawTextSCentered(ystart2, font_info,
8798 "press the 'return' key.");
8799 ystart2 += ystep_line;
8800 DrawTextSCentered(ystart2, font_info,
8801 "To exit, press the 'escape' key.");
8804 BlitBitmapMasked(controller, drawto, 0, 0,
8805 controller->width, controller->height,
8806 controller_x, controller_y);
8808 SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
8809 SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
8811 BlitBitmapMasked(marker, drawto, 0, 0,
8812 marker->width, marker->height,
8813 marker_x, marker_y);
8815 if (!screen_initialized)
8816 FadeIn(REDRAW_FIELD);
8820 screen_initialized = TRUE;
8822 DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
8824 // reset frame delay counter directly after updating screen
8825 ResetDelayCounter(&event_frame_delay);
8827 while (NextValidEvent(&event))
8831 case SDL_JOYAXISMOTION:
8832 if (event.jaxis.value > 20000 ||
8833 event.jaxis.value < -20000)
8835 for (j = 0; j < i; j++)
8836 if (steps[j].axis == event.jaxis.axis)
8841 if (step->marker != MARKER_AXIS_X &&
8842 step->marker != MARKER_AXIS_Y)
8845 step->axis = event.jaxis.axis;
8846 strcat(mapping, step->field);
8847 snprintf(temp, sizeof(temp), ":a%u,", event.jaxis.axis);
8848 strcat(mapping, temp);
8856 case SDL_JOYHATMOTION:
8857 // ignore centering; we're probably just coming back
8858 // to the center from the previous item we set
8859 if (event.jhat.value == SDL_HAT_CENTERED)
8862 for (j = 0; j < i; j++)
8863 if (steps[j].hat == event.jhat.hat &&
8864 steps[j].hat_value == event.jhat.value)
8869 step->hat = event.jhat.hat;
8870 step->hat_value = event.jhat.value;
8871 strcat(mapping, step->field);
8872 snprintf(temp, sizeof(temp), ":h%u.%u,",
8873 event.jhat.hat, event.jhat.value );
8874 strcat(mapping, temp);
8881 case SDL_JOYBALLMOTION:
8884 case SDL_JOYBUTTONUP:
8885 for (j = 0; j < i; j++)
8886 if (steps[j].button == event.jbutton.button)
8891 step->button = event.jbutton.button;
8892 strcat(mapping, step->field);
8893 snprintf(temp, sizeof(temp), ":b%u,", event.jbutton.button);
8894 strcat(mapping, temp);
8901 case SDL_FINGERDOWN:
8902 case SDL_MOUSEBUTTONDOWN:
8910 if (event.key.keysym.sym == KSYM_BackSpace ||
8911 event.key.keysym.sym == KSYM_Back)
8923 prev_step = &steps[i - 1];
8924 strcpy(mapping, prev_step->mapping);
8931 if (event.key.keysym.sym == KSYM_space ||
8932 event.key.keysym.sym == KSYM_Return ||
8933 event.key.keysym.sym == KSYM_Menu)
8942 if (event.key.keysym.sym == KSYM_Escape)
8952 program.exit_function(0);
8959 // do not handle events for longer than standard frame delay period
8960 if (DelayReached(&event_frame_delay))
8969 Debug("joystick", "New game controller mapping:\n\n%s\n\n", mapping);
8972 // activate mapping for this game
8973 SDL_GameControllerAddMapping(mapping);
8975 // save mapping to personal mappings
8976 SaveSetup_AddGameControllerMapping(mapping);
8979 // wait until the last pending event was removed from event queue
8980 while (NextValidEvent(&event));
8985 static int ConfigureJoystickMain(int player_nr)
8987 char *device_name = setup.input[player_nr].joy.device_name;
8988 int joystick_nr = getJoystickNrFromDeviceName(device_name);
8989 boolean joystick_active = CheckJoystickOpened(joystick_nr);
8990 int success = FALSE;
8993 if (joystick.status == JOYSTICK_NOT_AVAILABLE)
8994 return JOYSTICK_NOT_AVAILABLE;
8996 if (!joystick_active || !setup.input[player_nr].use_joystick)
8997 return JOYSTICK_NOT_AVAILABLE;
9000 FadeOut(REDRAW_FIELD);
9002 // close all joystick devices (potentially opened as game controllers)
9003 for (i = 0; i < SDL_NumJoysticks(); i++)
9004 SDLCloseJoystick(i);
9006 // open joystick device as plain joystick to configure as game controller
9007 SDL_Joystick *joystick = SDL_JoystickOpen(joystick_nr);
9009 // as the joystick was successfully opened before, this should not happen
9010 if (joystick == NULL)
9013 // create new game controller mapping (buttons and axes) for joystick device
9014 success = ConfigureJoystickMapButtonsAndAxes(joystick);
9016 // close joystick (and maybe re-open as configured game controller later)
9017 SDL_JoystickClose(joystick);
9019 // re-open all joystick devices (potentially as game controllers)
9020 for (i = 0; i < SDL_NumJoysticks(); i++)
9023 // clear all joystick input actions for all joystick devices
9024 SDLClearJoystickState();
9026 return (success ? JOYSTICK_CONFIGURED : JOYSTICK_NOT_CONFIGURED);
9029 void ConfigureJoystick(int player_nr)
9031 boolean state = ConfigureJoystickMain(player_nr);
9033 if (state != JOYSTICK_NOT_CONFIGURED)
9035 boolean success = (state == JOYSTICK_CONFIGURED);
9036 char message1[MAX_OUTPUT_LINESIZE + 1];
9037 char *message2 = (success ? "configured!" : "not available!");
9038 char *device_name = setup.input[player_nr].joy.device_name;
9039 int nr = getJoystickNrFromDeviceName(device_name) + 1;
9040 int font_nr = FONT_TITLE_1;
9041 int font_height = getFontHeight(font_nr);
9042 int ypos1 = SYSIZE / 2 - font_height * 2;
9043 int ypos2 = SYSIZE / 2 - font_height * 1;
9044 DelayCounter wait_frame_delay = { 2000 };
9046 ResetDelayCounter(&wait_frame_delay);
9050 sprintf(message1, "Joystick %d", nr);
9052 DrawTextSCentered(ypos1, font_nr, message1);
9053 DrawTextSCentered(ypos2, font_nr, message2);
9055 while (!DelayReached(&wait_frame_delay))
9061 DrawSetupScreen_Input();
9064 static void MapScreenMenuGadgets_OverlayTouchButtons(int y)
9066 if (y < video.screen_height / 3)
9068 // remap touch gadgets to access upper part of the screen
9069 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9070 MapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9072 else if (y > 2 * video.screen_height / 3)
9074 // remap touch gadgets to access lower part of the screen
9075 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9076 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH2);
9080 static boolean ConfigureVirtualButtonsMain(void)
9082 static char *customize_step_text[] =
9091 char grid_button[] =
9093 CHAR_GRID_BUTTON_LEFT,
9094 CHAR_GRID_BUTTON_RIGHT,
9095 CHAR_GRID_BUTTON_UP,
9096 CHAR_GRID_BUTTON_DOWN,
9097 CHAR_GRID_BUTTON_SNAP,
9098 CHAR_GRID_BUTTON_DROP
9107 int font_nr = FONT_INPUT_1_ACTIVE;
9108 int font_height = getFontHeight(font_nr);
9109 int ypos1 = SYSIZE / 2 - font_height * 2;
9110 int ypos2 = SYSIZE / 2 - font_height * 1;
9111 boolean success = FALSE;
9112 boolean finished = FALSE;
9114 char grid_button_draw = CHAR_GRID_BUTTON_NONE;
9115 char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9116 char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
9117 boolean set_grid_button = FALSE;
9118 int nr = GRID_ACTIVE_NR();
9121 for (x = 0; x < MAX_GRID_XSIZE; x++)
9122 for (y = 0; y < MAX_GRID_YSIZE; y++)
9123 grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
9125 overlay.grid_button_highlight = grid_button[step_nr];
9130 FadeOut(REDRAW_FIELD);
9134 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9135 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9136 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9138 FadeIn(REDRAW_FIELD);
9140 SetOverlayShowGrid(TRUE);
9142 // map gadgets for setup touch buttons menu screen
9143 MapScreenMenuGadgets(SCREEN_MASK_TOUCH);
9149 while (NextValidEvent(&event))
9151 int action = ACTION_NONE;
9153 // ---------- handle events and set the resulting action ----------
9159 UserEvent *user = (UserEvent *)&event;
9160 int id = user->value1;
9162 action = (id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE ||
9163 id == SCREEN_CTRL_ID_TOUCH_PREV_PAGE2 ? ACTION_BACK :
9164 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE ||
9165 id == SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2 ? ACTION_NEXT :
9170 case EVENT_KEYPRESS:
9172 Key key = GetEventKey((KeyEvent *)&event);
9174 action = (key == KSYM_Escape ? ACTION_ESCAPE :
9175 key == KSYM_BackSpace ||
9176 key == KSYM_Back ? ACTION_BACK :
9177 key == KSYM_Return ||
9179 key == KSYM_space ? ACTION_NEXT :
9184 case EVENT_KEYRELEASE:
9185 key_joystick_mapping = 0;
9188 case EVENT_BUTTONPRESS:
9189 case EVENT_BUTTONRELEASE:
9191 ButtonEvent *button = (ButtonEvent *)&event;
9193 motion_status = FALSE;
9195 if (button->type == EVENT_BUTTONPRESS)
9196 button_status = button->button;
9198 button_status = MB_RELEASED;
9200 if (HandleGadgets(button->x, button->y, button_status))
9202 // do not handle this button event anymore
9206 button->x += video.screen_xoffset;
9207 button->y += video.screen_yoffset;
9209 x = button->x * overlay.grid_xsize / video.screen_width;
9210 y = button->y * overlay.grid_ysize / video.screen_height;
9212 if (button->type == EVENT_BUTTONPRESS)
9215 (overlay.grid_button[x][y] != grid_button[step_nr] ?
9216 grid_button[step_nr] : CHAR_GRID_BUTTON_NONE);
9218 set_grid_button = TRUE;
9221 MapScreenMenuGadgets_OverlayTouchButtons(button->y);
9225 case EVENT_MOTIONNOTIFY:
9227 MotionEvent *motion = (MotionEvent *)&event;
9229 motion_status = TRUE;
9231 if (HandleGadgets(motion->x, motion->y, button_status))
9233 // do not handle this button event anymore
9237 motion->x += video.screen_xoffset;
9238 motion->y += video.screen_yoffset;
9240 x = motion->x * overlay.grid_xsize / video.screen_width;
9241 y = motion->y * overlay.grid_ysize / video.screen_height;
9243 set_grid_button = TRUE;
9245 MapScreenMenuGadgets_OverlayTouchButtons(motion->y);
9249 case SDL_WINDOWEVENT:
9250 HandleWindowEvent((WindowEvent *) &event);
9252 // check if device has been rotated
9253 if (nr != GRID_ACTIVE_NR())
9255 nr = GRID_ACTIVE_NR();
9257 for (x = 0; x < MAX_GRID_XSIZE; x++)
9258 for (y = 0; y < MAX_GRID_YSIZE; y++)
9259 grid_button_old[x][y] = grid_button_tmp[x][y] =
9260 overlay.grid_button[x][y];
9265 case SDL_APP_WILLENTERBACKGROUND:
9266 case SDL_APP_DIDENTERBACKGROUND:
9267 case SDL_APP_WILLENTERFOREGROUND:
9268 case SDL_APP_DIDENTERFOREGROUND:
9269 HandlePauseResumeEvent((PauseResumeEvent *) &event);
9273 HandleOtherEvents(&event);
9277 // ---------- perform action set by handling events ----------
9279 if (action == ACTION_ESCAPE)
9281 // abort and restore the old key bindings
9283 for (x = 0; x < MAX_GRID_XSIZE; x++)
9284 for (y = 0; y < MAX_GRID_YSIZE; y++)
9285 overlay.grid_button[x][y] = grid_button_old[x][y];
9287 FadeSkipNextFadeIn();
9291 else if (action == ACTION_BACK)
9293 // keep the configured key bindings and go to previous page
9299 FadeSkipNextFadeIn();
9304 else if (action == ACTION_NEXT)
9306 // keep the configured key bindings and go to next page
9310 // all virtual buttons configured
9318 if (action != ACTION_NONE && !finished)
9320 for (x = 0; x < MAX_GRID_XSIZE; x++)
9321 for (y = 0; y < MAX_GRID_YSIZE; y++)
9322 grid_button_tmp[x][y] = overlay.grid_button[x][y];
9324 overlay.grid_button_highlight = grid_button[step_nr];
9326 // configure next virtual button
9330 DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons");
9331 DrawTextSCentered(ypos1, font_nr, "Select tiles to");
9332 DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]);
9335 if (set_grid_button)
9337 overlay.grid_button[x][y] =
9338 (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
9339 grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
9340 grid_button_tmp[x][y]);
9342 set_grid_button = FALSE;
9349 for (x = 0; x < MAX_GRID_XSIZE; x++)
9350 for (y = 0; y < MAX_GRID_YSIZE; y++)
9351 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9353 overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
9355 SetOverlayShowGrid(FALSE);
9360 void ConfigureVirtualButtons(void)
9362 boolean success = ConfigureVirtualButtonsMain();
9364 UnmapScreenMenuGadgets(SCREEN_MASK_TOUCH |
9365 SCREEN_MASK_TOUCH2);
9369 int font_nr = FONT_TITLE_1;
9370 int font_height = getFontHeight(font_nr);
9371 int ypos1 = SYSIZE / 2 - font_height * 2;
9372 int ypos2 = SYSIZE / 2 - font_height * 1;
9373 DelayCounter wait_frame_delay = { 2000 };
9375 ResetDelayCounter(&wait_frame_delay);
9379 DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
9380 DrawTextSCentered(ypos2, font_nr, "configured!");
9382 while (!DelayReached(&wait_frame_delay))
9389 void DrawSetupScreen(void)
9394 if (setup_mode == SETUP_MODE_INPUT)
9395 DrawSetupScreen_Input();
9396 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9397 DrawChooseTree(&scores_type_current);
9398 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9399 DrawChooseTree(&game_speed_current);
9400 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9401 DrawChooseTree(&scroll_delay_current);
9402 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9403 DrawChooseTree(&snapshot_mode_current);
9404 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9405 DrawChooseTree(&window_size_current);
9406 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9407 DrawChooseTree(&scaling_type_current);
9408 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9409 DrawChooseTree(&rendering_mode_current);
9410 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9411 DrawChooseTree(&vsync_mode_current);
9412 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9413 DrawChooseTree(&artwork.gfx_current);
9414 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9415 DrawChooseTree(&artwork.snd_current);
9416 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9417 DrawChooseTree(&artwork.mus_current);
9418 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9419 DrawChooseTree(&volume_simple_current);
9420 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9421 DrawChooseTree(&volume_loops_current);
9422 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9423 DrawChooseTree(&volume_music_current);
9424 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9425 DrawChooseTree(&touch_control_current);
9426 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9427 DrawChooseTree(&move_distance_current);
9428 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9429 DrawChooseTree(&drop_distance_current);
9430 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9431 DrawChooseTree(&transparency_current);
9432 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9433 DrawChooseTree(&grid_size_current[0][0]);
9434 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9435 DrawChooseTree(&grid_size_current[0][1]);
9436 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9437 DrawChooseTree(&grid_size_current[1][0]);
9438 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9439 DrawChooseTree(&grid_size_current[1][1]);
9441 DrawSetupScreen_Generic();
9443 PlayMenuSoundsAndMusic();
9446 void RedrawSetupScreenAfterFullscreenToggle(void)
9448 if (setup_mode == SETUP_MODE_GRAPHICS ||
9449 setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9451 // update list selection from "setup.window_scaling_percent"
9452 execSetupGraphics_setWindowSizes(TRUE);
9458 void RedrawSetupScreenAfterScreenRotation(int nr)
9462 if (setup_mode == SETUP_MODE_TOUCH)
9464 // update virtual button settings (depending on screen orientation)
9467 else if (setup_mode == SETUP_MODE_CONFIG_VIRT_BUTTONS)
9469 // save already configured virtual buttons
9470 for (x = 0; x < MAX_GRID_XSIZE; x++)
9471 for (y = 0; y < MAX_GRID_YSIZE; y++)
9472 setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
9476 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
9478 if (setup_mode == SETUP_MODE_INPUT)
9479 HandleSetupScreen_Input(mx, my, dx, dy, button);
9480 else if (setup_mode == SETUP_MODE_CHOOSE_SCORES_TYPE)
9481 HandleChooseTree(mx, my, dx, dy, button, &scores_type_current);
9482 else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)
9483 HandleChooseTree(mx, my, dx, dy, button, &game_speed_current);
9484 else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
9485 HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current);
9486 else if (setup_mode == SETUP_MODE_CHOOSE_SNAPSHOT_MODE)
9487 HandleChooseTree(mx, my, dx, dy, button, &snapshot_mode_current);
9488 else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
9489 HandleChooseTree(mx, my, dx, dy, button, &window_size_current);
9490 else if (setup_mode == SETUP_MODE_CHOOSE_SCALING_TYPE)
9491 HandleChooseTree(mx, my, dx, dy, button, &scaling_type_current);
9492 else if (setup_mode == SETUP_MODE_CHOOSE_RENDERING)
9493 HandleChooseTree(mx, my, dx, dy, button, &rendering_mode_current);
9494 else if (setup_mode == SETUP_MODE_CHOOSE_VSYNC)
9495 HandleChooseTree(mx, my, dx, dy, button, &vsync_mode_current);
9496 else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS)
9497 HandleChooseTree(mx, my, dx, dy, button, &artwork.gfx_current);
9498 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS)
9499 HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
9500 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
9501 HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
9502 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
9503 HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
9504 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
9505 HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
9506 else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
9507 HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
9508 else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
9509 HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
9510 else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
9511 HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
9512 else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
9513 HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
9514 else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
9515 HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
9516 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_0)
9517 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][0]);
9518 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_0)
9519 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[0][1]);
9520 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_XSIZE_1)
9521 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][0]);
9522 else if (setup_mode == SETUP_MODE_CHOOSE_GRID_YSIZE_1)
9523 HandleChooseTree(mx, my, dx, dy, button, &grid_size_current[1][1]);
9525 HandleSetupScreen_Generic(mx, my, dx, dy, button);
9528 void HandleGameActions(void)
9530 if (setup.ask_on_game_over)
9533 if (game.restart_game_message != NULL)
9535 RequestRestartGame(game.restart_game_message);
9540 if (game_status != GAME_MODE_PLAYING)
9543 GameActions(); // main game loop
9545 if (tape.auto_play && !tape.playing)
9546 AutoPlayTapesContinue(); // continue automatically playing next tape
9550 // ---------- new screen button stuff --------------------------------------
9554 int gfx_unpressed, gfx_pressed, gfx_active;
9555 struct MenuPosInfo *pos;
9556 boolean *check_value;
9559 unsigned int event_mask;
9560 boolean is_touch_button;
9562 } menubutton_info[NUM_SCREEN_MENUBUTTONS] =
9565 IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE, -1,
9566 &menu.main.button.prev_level, NULL,
9567 SCREEN_CTRL_ID_PREV_LEVEL,
9569 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9570 FALSE, "previous level"
9573 IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE, -1,
9574 &menu.main.button.next_level, NULL,
9575 SCREEN_CTRL_ID_NEXT_LEVEL,
9577 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9581 IMG_MENU_BUTTON_PREV_LEVEL2, IMG_MENU_BUTTON_PREV_LEVEL2_ACTIVE, -1,
9582 &menu.scores.button.prev_level, NULL,
9583 SCREEN_CTRL_ID_PREV_LEVEL2,
9584 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9585 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9586 FALSE, "previous level"
9589 IMG_MENU_BUTTON_NEXT_LEVEL2, IMG_MENU_BUTTON_NEXT_LEVEL2_ACTIVE, -1,
9590 &menu.scores.button.next_level, NULL,
9591 SCREEN_CTRL_ID_NEXT_LEVEL2,
9592 SCREEN_MASK_SCORES | SCREEN_MASK_SCORES_INFO,
9593 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9597 IMG_MENU_BUTTON_PREV_SCORE, IMG_MENU_BUTTON_PREV_SCORE_ACTIVE, -1,
9598 &menu.scores.button.prev_score, NULL,
9599 SCREEN_CTRL_ID_PREV_SCORE,
9600 SCREEN_MASK_SCORES_INFO,
9601 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9602 FALSE, "previous score"
9605 IMG_MENU_BUTTON_NEXT_SCORE, IMG_MENU_BUTTON_NEXT_SCORE_ACTIVE, -1,
9606 &menu.scores.button.next_score, NULL,
9607 SCREEN_CTRL_ID_NEXT_SCORE,
9608 SCREEN_MASK_SCORES_INFO,
9609 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9613 IMG_MENU_BUTTON_PLAY_TAPE, IMG_MENU_BUTTON_PLAY_TAPE, -1,
9614 &menu.scores.button.play_tape, NULL,
9615 SCREEN_CTRL_ID_PLAY_TAPE,
9616 SCREEN_MASK_SCORES_INFO,
9621 IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE, -1,
9622 &menu.main.button.first_level, NULL,
9623 SCREEN_CTRL_ID_FIRST_LEVEL,
9626 FALSE, "first level"
9629 IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE, -1,
9630 &menu.main.button.last_level, NULL,
9631 SCREEN_CTRL_ID_LAST_LEVEL,
9637 IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE, -1,
9638 &menu.main.button.level_number, NULL,
9639 SCREEN_CTRL_ID_LEVEL_NUMBER,
9642 FALSE, "level number"
9645 IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE, -1,
9646 &menu.setup.button.prev_player, NULL,
9647 SCREEN_CTRL_ID_PREV_PLAYER,
9649 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9650 FALSE, "previous player"
9653 IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE, -1,
9654 &menu.setup.button.next_player, NULL,
9655 SCREEN_CTRL_ID_NEXT_PLAYER,
9657 GD_EVENT_PRESSED | GD_EVENT_REPEATED,
9658 FALSE, "next player"
9661 IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE, -1,
9662 &menu.main.button.insert_solution, NULL,
9663 SCREEN_CTRL_ID_INSERT_SOLUTION,
9664 SCREEN_MASK_MAIN_HAS_SOLUTION,
9666 FALSE, "insert solution tape"
9669 IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE, -1,
9670 &menu.main.button.play_solution, NULL,
9671 SCREEN_CTRL_ID_PLAY_SOLUTION,
9672 SCREEN_MASK_MAIN_HAS_SOLUTION,
9674 FALSE, "play solution tape"
9677 IMG_MENU_BUTTON_LEVELSET_INFO, IMG_MENU_BUTTON_LEVELSET_INFO_PRESSED,
9678 IMG_MENU_BUTTON_LEVELSET_INFO_ACTIVE,
9679 &menu.main.button.levelset_info, NULL,
9680 SCREEN_CTRL_ID_LEVELSET_INFO,
9681 SCREEN_MASK_MAIN_HAS_SET_INFO,
9683 FALSE, "show level set info"
9686 IMG_MENU_BUTTON_SWITCH_ECS_AGA, IMG_MENU_BUTTON_SWITCH_ECS_AGA_ACTIVE, -1,
9687 &menu.main.button.switch_ecs_aga, &setup.prefer_aga_graphics,
9688 SCREEN_CTRL_ID_SWITCH_ECS_AGA,
9690 GD_EVENT_RELEASED | GD_EVENT_OFF_BORDERS,
9691 FALSE, "switch ECS/AGA chipset"
9694 IMG_MENU_BUTTON_TOUCH_BACK, IMG_MENU_BUTTON_TOUCH_BACK, -1,
9695 &menu.setup.button.touch_back, NULL,
9696 SCREEN_CTRL_ID_TOUCH_PREV_PAGE,
9699 TRUE, "previous page"
9702 IMG_MENU_BUTTON_TOUCH_NEXT, IMG_MENU_BUTTON_TOUCH_NEXT, -1,
9703 &menu.setup.button.touch_next, NULL,
9704 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE,
9710 IMG_MENU_BUTTON_TOUCH_BACK2, IMG_MENU_BUTTON_TOUCH_BACK2, -1,
9711 &menu.setup.button.touch_back2, NULL,
9712 SCREEN_CTRL_ID_TOUCH_PREV_PAGE2,
9715 TRUE, "previous page"
9718 IMG_MENU_BUTTON_TOUCH_NEXT2, IMG_MENU_BUTTON_TOUCH_NEXT2, -1,
9719 &menu.setup.button.touch_next2, NULL,
9720 SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2,
9729 int gfx_unpressed, gfx_pressed;
9733 } scrollbutton_info[NUM_SCREEN_SCROLLBUTTONS] =
9736 IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE,
9737 -1, -1, // these values are not constant, but can change at runtime
9738 SCREEN_CTRL_ID_SCROLL_UP,
9742 IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE,
9743 -1, -1, // these values are not constant, but can change at runtime
9744 SCREEN_CTRL_ID_SCROLL_DOWN,
9751 int gfx_unpressed, gfx_pressed;
9757 } scrollbar_info[NUM_SCREEN_SCROLLBARS] =
9760 IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE,
9761 -1, -1, // these values are not constant, but can change at runtime
9762 -1, -1, // these values are not constant, but can change at runtime
9763 GD_TYPE_SCROLLBAR_VERTICAL,
9764 SCREEN_CTRL_ID_SCROLL_VERTICAL,
9765 "scroll level series vertically"
9777 } textinput_info[NUM_SCREEN_TEXTINPUT] =
9780 IMG_SETUP_INPUT_TEXT,
9781 SCREEN_CTRL_ID_NETWORK_SERVER,
9782 -1, -1, // these values are not constant, but can change at runtime
9783 MAX_SETUP_TEXT_INPUT_LEN,
9784 network_server_hostname,
9785 "Network Server Hostname / IP"
9789 static void CreateScreenMenubuttons(void)
9791 struct GadgetInfo *gi;
9792 unsigned int event_mask;
9795 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
9797 struct MenuPosInfo *pos = menubutton_info[i].pos;
9798 int screen_mask = menubutton_info[i].screen_mask;
9799 boolean is_touch_button = menubutton_info[i].is_touch_button;
9800 boolean is_check_button = menubutton_info[i].check_value != NULL;
9801 boolean is_score_button = (screen_mask & SCREEN_MASK_SCORES_INFO);
9802 boolean has_gfx_pressed = (menubutton_info[i].gfx_pressed ==
9803 menubutton_info[i].gfx_unpressed);
9804 boolean has_gfx_active = (menubutton_info[i].gfx_active != -1);
9805 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9806 Bitmap *gd_bitmap_unpressed_alt, *gd_bitmap_pressed_alt;
9807 int gfx_unpressed, gfx_pressed;
9808 int gfx_unpressed_alt, gfx_pressed_alt;
9809 int x, y, width, height;
9810 int gd_x1, gd_x2, gd_y1, gd_y2;
9811 int gd_x1a, gd_x2a, gd_y1a, gd_y2a;
9812 int id = menubutton_info[i].gadget_id;
9813 int type = GD_TYPE_NORMAL_BUTTON;
9814 boolean checked = FALSE;
9816 // do not use touch buttons if overlay touch buttons are disabled
9817 if (is_touch_button && !setup.touch.overlay_buttons)
9820 event_mask = menubutton_info[i].event_mask;
9822 x = (is_touch_button ? pos->x : mSX + GDI_ACTIVE_POS(pos->x));
9823 y = (is_touch_button ? pos->y : mSY + GDI_ACTIVE_POS(pos->y));
9825 width = graphic_info[menubutton_info[i].gfx_pressed].width;
9826 height = graphic_info[menubutton_info[i].gfx_pressed].height;
9828 gfx_unpressed = menubutton_info[i].gfx_unpressed;
9829 gfx_pressed = menubutton_info[i].gfx_pressed;
9830 gfx_unpressed_alt = gfx_unpressed;
9831 gfx_pressed_alt = gfx_pressed;
9835 gfx_unpressed_alt = menubutton_info[i].gfx_active;
9837 type = GD_TYPE_CHECK_BUTTON_2;
9839 if (menubutton_info[i].check_value != NULL)
9840 checked = *menubutton_info[i].check_value;
9843 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9844 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9845 gd_bitmap_unpressed_alt = graphic_info[gfx_unpressed_alt].bitmap;
9846 gd_bitmap_pressed_alt = graphic_info[gfx_pressed_alt].bitmap;
9848 gd_x1 = graphic_info[gfx_unpressed].src_x;
9849 gd_y1 = graphic_info[gfx_unpressed].src_y;
9850 gd_x2 = graphic_info[gfx_pressed].src_x;
9851 gd_y2 = graphic_info[gfx_pressed].src_y;
9853 gd_x1a = graphic_info[gfx_unpressed_alt].src_x;
9854 gd_y1a = graphic_info[gfx_unpressed_alt].src_y;
9855 gd_x2a = graphic_info[gfx_pressed_alt].src_x;
9856 gd_y2a = graphic_info[gfx_pressed_alt].src_y;
9858 if (has_gfx_pressed)
9860 gd_x2 += graphic_info[gfx_pressed].pressed_xoffset;
9861 gd_y2 += graphic_info[gfx_pressed].pressed_yoffset;
9864 if (is_check_button)
9866 gd_x1a += graphic_info[gfx_unpressed].active_xoffset;
9867 gd_y1a += graphic_info[gfx_unpressed].active_yoffset;
9868 gd_x2a += graphic_info[gfx_pressed].active_xoffset;
9869 gd_y2a += graphic_info[gfx_pressed].active_yoffset;
9871 type = GD_TYPE_CHECK_BUTTON;
9873 if (menubutton_info[i].check_value != NULL)
9874 checked = *menubutton_info[i].check_value;
9877 if (is_score_button)
9879 // if x/y set to -1, dynamically place buttons next to title text
9880 int title_width = getTextWidth(INFOTEXT_SCORE_ENTRY, FONT_TITLE_1);
9882 // special compatibility handling for "Snake Bite" graphics set
9883 if (strPrefix(leveldir_current->identifier, "snake_bite"))
9884 title_width = strlen(INFOTEXT_SCORE_ENTRY) * 32;
9886 // use "SX" here to center buttons (ignore horizontal draw offset)
9888 x = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ?
9889 SX + (SXSIZE - title_width) / 2 - width * 3 / 2 :
9890 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ?
9891 SX + (SXSIZE + title_width) / 2 + width / 2 : 0);
9893 // use "mSY" here to place buttons (respect vertical draw offset)
9895 y = (id == SCREEN_CTRL_ID_PREV_LEVEL2 ||
9896 id == SCREEN_CTRL_ID_NEXT_LEVEL2 ? mSY + MENU_TITLE1_YPOS : 0);
9899 if (id == SCREEN_CTRL_ID_LEVELSET_INFO)
9901 if (pos->x == -1 && pos->y == -1)
9903 // use "SX" here to place button (ignore draw offsets)
9904 x = SX + SXSIZE - 2 * TILESIZE;
9905 y = SY + SYSIZE - 2 * TILESIZE;
9907 // special compatibility handling for "BD2K3" graphics set
9908 if (strPrefix(leveldir_current->identifier, "BD2K3"))
9909 x = SX + TILESIZE + MINI_TILESIZE;
9911 // special compatibility handling for "jue0" graphics set
9912 if (strPrefix(artwork.gfx_current_identifier, "jue0"))
9914 x = SX + SXSIZE - 4 * TILESIZE;
9915 y = SY + SYSIZE - 3 * TILESIZE;
9920 gi = CreateGadget(GDI_CUSTOM_ID, id,
9921 GDI_CUSTOM_TYPE_ID, i,
9922 GDI_IMAGE_ID, gfx_unpressed,
9923 GDI_INFO_TEXT, menubutton_info[i].infotext,
9929 GDI_STATE, GD_BUTTON_UNPRESSED,
9930 GDI_CHECKED, checked,
9931 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
9932 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
9933 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap_unpressed_alt, gd_x1a, gd_y1a,
9934 GDI_ALT_DESIGN_PRESSED, gd_bitmap_pressed_alt, gd_x2a, gd_y2a,
9935 GDI_DIRECT_DRAW, FALSE,
9936 GDI_OVERLAY_TOUCH_BUTTON, is_touch_button,
9937 GDI_EVENT_MASK, event_mask,
9938 GDI_CALLBACK_ACTION, HandleScreenGadgets,
9942 Fail("cannot create gadget");
9944 screen_gadget[id] = gi;
9948 static void CreateScreenScrollbuttons(void)
9950 struct GadgetInfo *gi;
9951 unsigned int event_mask;
9954 // these values are not constant, but can change at runtime
9955 scrollbutton_info[0].x = SC_SCROLL_UP_XPOS;
9956 scrollbutton_info[0].y = SC_SCROLL_UP_YPOS;
9957 scrollbutton_info[1].x = SC_SCROLL_DOWN_XPOS;
9958 scrollbutton_info[1].y = SC_SCROLL_DOWN_YPOS;
9960 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
9962 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
9963 int gfx_unpressed, gfx_pressed;
9964 int x, y, width, height;
9965 int gd_x1, gd_x2, gd_y1, gd_y2;
9966 int id = scrollbutton_info[i].gadget_id;
9968 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
9970 x = mSX + scrollbutton_info[i].x + menu.scrollbar_xoffset;
9971 y = mSY + scrollbutton_info[i].y;
9972 width = SC_SCROLLBUTTON_XSIZE;
9973 height = SC_SCROLLBUTTON_YSIZE;
9975 // correct scrollbar position if placed outside menu (playfield) area
9976 if (x > SX + SC_SCROLL_UP_XPOS)
9977 x = SX + SC_SCROLL_UP_XPOS;
9979 if (id == SCREEN_CTRL_ID_SCROLL_DOWN)
9980 y = mSY + (SC_SCROLL_VERTICAL_YPOS +
9981 (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE);
9983 gfx_unpressed = scrollbutton_info[i].gfx_unpressed;
9984 gfx_pressed = scrollbutton_info[i].gfx_pressed;
9985 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
9986 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
9987 gd_x1 = graphic_info[gfx_unpressed].src_x;
9988 gd_y1 = graphic_info[gfx_unpressed].src_y;
9989 gd_x2 = graphic_info[gfx_pressed].src_x;
9990 gd_y2 = graphic_info[gfx_pressed].src_y;
9992 gi = CreateGadget(GDI_CUSTOM_ID, id,
9993 GDI_CUSTOM_TYPE_ID, i,
9994 GDI_IMAGE_ID, gfx_unpressed,
9995 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
10000 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
10001 GDI_STATE, GD_BUTTON_UNPRESSED,
10002 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10003 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10004 GDI_DIRECT_DRAW, FALSE,
10005 GDI_EVENT_MASK, event_mask,
10006 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10010 Fail("cannot create gadget");
10012 screen_gadget[id] = gi;
10016 static void CreateScreenScrollbars(void)
10020 // these values are not constant, but can change at runtime
10021 scrollbar_info[0].x = SC_SCROLL_VERTICAL_XPOS;
10022 scrollbar_info[0].y = SC_SCROLL_VERTICAL_YPOS;
10023 scrollbar_info[0].width = SC_SCROLL_VERTICAL_XSIZE;
10024 scrollbar_info[0].height = SC_SCROLL_VERTICAL_YSIZE;
10026 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10028 Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed;
10029 int gfx_unpressed, gfx_pressed;
10030 int x, y, width, height;
10031 int gd_x1, gd_x2, gd_y1, gd_y2;
10032 struct GadgetInfo *gi;
10033 int items_max, items_visible, item_position;
10034 unsigned int event_mask;
10035 int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
10036 int id = scrollbar_info[i].gadget_id;
10038 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
10040 x = mSX + scrollbar_info[i].x + menu.scrollbar_xoffset;
10041 y = mSY + scrollbar_info[i].y;
10042 width = scrollbar_info[i].width;
10043 height = scrollbar_info[i].height;
10045 // correct scrollbar position if placed outside menu (playfield) area
10046 if (x > SX + SC_SCROLL_VERTICAL_XPOS)
10047 x = SX + SC_SCROLL_VERTICAL_XPOS;
10049 if (id == SCREEN_CTRL_ID_SCROLL_VERTICAL)
10050 height = (NUM_MENU_ENTRIES_ON_SCREEN - 2) * SC_SCROLLBUTTON_YSIZE;
10052 items_max = num_page_entries;
10053 items_visible = num_page_entries;
10056 gfx_unpressed = scrollbar_info[i].gfx_unpressed;
10057 gfx_pressed = scrollbar_info[i].gfx_pressed;
10058 gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap;
10059 gd_bitmap_pressed = graphic_info[gfx_pressed].bitmap;
10060 gd_x1 = graphic_info[gfx_unpressed].src_x;
10061 gd_y1 = graphic_info[gfx_unpressed].src_y;
10062 gd_x2 = graphic_info[gfx_pressed].src_x;
10063 gd_y2 = graphic_info[gfx_pressed].src_y;
10065 gi = CreateGadget(GDI_CUSTOM_ID, id,
10066 GDI_CUSTOM_TYPE_ID, i,
10067 GDI_IMAGE_ID, gfx_unpressed,
10068 GDI_INFO_TEXT, scrollbar_info[i].infotext,
10072 GDI_HEIGHT, height,
10073 GDI_TYPE, scrollbar_info[i].type,
10074 GDI_SCROLLBAR_ITEMS_MAX, items_max,
10075 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10076 GDI_SCROLLBAR_ITEM_POSITION, item_position,
10077 GDI_WHEEL_AREA_X, SX,
10078 GDI_WHEEL_AREA_Y, SY,
10079 GDI_WHEEL_AREA_WIDTH, SXSIZE,
10080 GDI_WHEEL_AREA_HEIGHT, SYSIZE,
10081 GDI_STATE, GD_BUTTON_UNPRESSED,
10082 GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1,
10083 GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2,
10084 GDI_BORDER_SIZE, SC_BORDER_SIZE, SC_BORDER_SIZE,
10085 GDI_DIRECT_DRAW, FALSE,
10086 GDI_EVENT_MASK, event_mask,
10087 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10091 Fail("cannot create gadget");
10093 screen_gadget[id] = gi;
10097 static void CreateScreenTextInputGadgets(void)
10101 for (i = 0; i < NUM_SCREEN_TEXTINPUT; i++)
10103 int graphic = textinput_info[i].graphic;
10104 struct GraphicInfo *gd = &graphic_info[graphic];
10105 int gd_x1 = gd->src_x;
10106 int gd_y1 = gd->src_y;
10107 int gd_x2 = gd->src_x + gd->active_xoffset;
10108 int gd_y2 = gd->src_y + gd->active_yoffset;
10109 struct GadgetInfo *gi;
10110 unsigned int event_mask;
10111 int id = textinput_info[i].gadget_id;
10112 int x = textinput_info[i].x;
10113 int y = textinput_info[i].y;
10115 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
10117 gi = CreateGadget(GDI_CUSTOM_ID, id,
10118 GDI_CUSTOM_TYPE_ID, i,
10119 GDI_INFO_TEXT, textinput_info[i].infotext,
10122 GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
10123 GDI_TEXT_VALUE, textinput_info[i].value,
10124 GDI_TEXT_SIZE, textinput_info[i].size,
10125 GDI_TEXT_FONT, getSetupValueFont(TYPE_STRING, NULL),
10126 GDI_TEXT_FONT_ACTIVE, FONT_TEXT_1,
10127 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
10128 GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
10129 GDI_BORDER_SIZE, gd->border_size, gd->border_size,
10130 GDI_DESIGN_WIDTH, gd->width,
10131 GDI_EVENT_MASK, event_mask,
10132 GDI_CALLBACK_ACTION, HandleScreenGadgets,
10133 GDI_CALLBACK_ACTION_ALWAYS, TRUE,
10137 Fail("cannot create gadget");
10139 screen_gadget[id] = gi;
10143 void CreateScreenGadgets(void)
10145 CreateScreenMenubuttons();
10147 CreateScreenScrollbuttons();
10148 CreateScreenScrollbars();
10150 CreateScreenTextInputGadgets();
10153 void FreeScreenGadgets(void)
10157 for (i = 0; i < NUM_SCREEN_GADGETS; i++)
10158 FreeGadget(screen_gadget[i]);
10161 static void RedrawScreenMenuGadgets(int screen_mask)
10165 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10166 if (screen_mask & menubutton_info[i].screen_mask)
10167 RedrawGadget(screen_gadget[menubutton_info[i].gadget_id]);
10170 static void MapScreenMenuGadgets(int screen_mask)
10174 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10175 if (screen_mask & menubutton_info[i].screen_mask)
10176 MapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10179 static void UnmapScreenMenuGadgets(int screen_mask)
10183 for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
10185 if (screen_mask & menubutton_info[i].screen_mask)
10187 UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]);
10189 if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION)
10190 DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x,
10191 screen_gadget[menubutton_info[i].gadget_id]->y,
10192 screen_gadget[menubutton_info[i].gadget_id]->width,
10193 screen_gadget[menubutton_info[i].gadget_id]->height);
10198 static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets)
10201 MapScreenMenuGadgets(screen_mask);
10203 UnmapScreenMenuGadgets(screen_mask);
10206 static void MapScreenGadgets(int num_entries)
10210 if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN)
10213 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10214 MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10216 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10217 MapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10220 static void UnmapScreenGadgets()
10224 for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++)
10225 UnmapGadget(screen_gadget[scrollbutton_info[i].gadget_id]);
10227 for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++)
10228 UnmapGadget(screen_gadget[scrollbar_info[i].gadget_id]);
10231 static void MapScreenTreeGadgets(TreeInfo *ti)
10233 MapScreenGadgets(numTreeInfoInGroup(ti));
10236 static void UnmapScreenTreeGadgets(void)
10238 UnmapScreenGadgets();
10241 static void AdjustScoreInfoButtons_SelectScore(int x, int y1, int y2)
10243 struct GadgetInfo *gi_1 = screen_gadget[SCREEN_CTRL_ID_PREV_SCORE];
10244 struct GadgetInfo *gi_2 = screen_gadget[SCREEN_CTRL_ID_NEXT_SCORE];
10245 struct MenuPosInfo *pos_1 = menubutton_info[SCREEN_CTRL_ID_PREV_SCORE].pos;
10246 struct MenuPosInfo *pos_2 = menubutton_info[SCREEN_CTRL_ID_NEXT_SCORE].pos;
10248 if (pos_1->x == -1 && pos_1->y == -1)
10249 ModifyGadget(gi_1, GDI_X, x, GDI_Y, y1, GDI_END);
10251 if (pos_2->x == -1 && pos_2->y == -1)
10252 ModifyGadget(gi_2, GDI_X, x, GDI_Y, y2, GDI_END);
10255 static void AdjustScoreInfoButtons_PlayTape(int x, int y, boolean visible)
10257 struct GadgetInfo *gi = screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE];
10258 struct MenuPosInfo *pos = menubutton_info[SCREEN_CTRL_ID_PLAY_TAPE].pos;
10260 // set gadget position dynamically, pre-defined or off-screen
10261 int xx = (visible ? (pos->x == -1 ? x : pos->x) : POS_OFFSCREEN);
10262 int yy = (visible ? (pos->y == -1 ? y : pos->y) : POS_OFFSCREEN);
10264 ModifyGadget(gi, GDI_X, xx, GDI_Y, yy, GDI_END);
10265 MapGadget(gi); // (needed if deactivated on last score page)
10268 static void HandleScreenGadgets(struct GadgetInfo *gi)
10270 int id = gi->custom_id;
10271 int button = gi->event.button;
10272 int step = (button == MB_LEFTBUTTON ? 1 :
10273 button == MB_MIDDLEBUTTON ? 5 :
10274 button == MB_RIGHTBUTTON ? 10 : 1);
10278 case SCREEN_CTRL_ID_PREV_LEVEL:
10279 HandleMainMenu_SelectLevel(step, -1, NO_DIRECT_LEVEL_SELECT);
10282 case SCREEN_CTRL_ID_NEXT_LEVEL:
10283 HandleMainMenu_SelectLevel(step, +1, NO_DIRECT_LEVEL_SELECT);
10286 case SCREEN_CTRL_ID_PREV_LEVEL2:
10287 HandleHallOfFame_SelectLevel(step, -1);
10290 case SCREEN_CTRL_ID_NEXT_LEVEL2:
10291 HandleHallOfFame_SelectLevel(step, +1);
10294 case SCREEN_CTRL_ID_PREV_SCORE:
10295 HandleScoreInfo_SelectScore(step, -1);
10298 case SCREEN_CTRL_ID_NEXT_SCORE:
10299 HandleScoreInfo_SelectScore(step, +1);
10302 case SCREEN_CTRL_ID_PLAY_TAPE:
10303 HandleScoreInfo_PlayTape();
10306 case SCREEN_CTRL_ID_FIRST_LEVEL:
10307 HandleMainMenu_SelectLevel(MAX_LEVELS, -1, NO_DIRECT_LEVEL_SELECT);
10310 case SCREEN_CTRL_ID_LAST_LEVEL:
10311 HandleMainMenu_SelectLevel(MAX_LEVELS, +1, NO_DIRECT_LEVEL_SELECT);
10314 case SCREEN_CTRL_ID_LEVEL_NUMBER:
10315 CloseDoor(DOOR_CLOSE_2);
10316 SetGameStatus(GAME_MODE_LEVELNR);
10317 DrawChooseLevelNr();
10320 case SCREEN_CTRL_ID_PREV_PLAYER:
10321 HandleSetupScreen_Input_Player(step, -1);
10324 case SCREEN_CTRL_ID_NEXT_PLAYER:
10325 HandleSetupScreen_Input_Player(step, +1);
10328 case SCREEN_CTRL_ID_INSERT_SOLUTION:
10329 InsertSolutionTape();
10332 case SCREEN_CTRL_ID_PLAY_SOLUTION:
10333 PlaySolutionTape();
10336 case SCREEN_CTRL_ID_LEVELSET_INFO:
10337 DrawInfoScreen_FromMainMenu(INFO_MODE_LEVELSET);
10340 case SCREEN_CTRL_ID_SWITCH_ECS_AGA:
10341 setup.prefer_aga_graphics = !setup.prefer_aga_graphics;
10345 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE:
10346 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE:
10347 case SCREEN_CTRL_ID_TOUCH_PREV_PAGE2:
10348 case SCREEN_CTRL_ID_TOUCH_NEXT_PAGE2:
10349 PushUserEvent(USEREVENT_GADGET_PRESSED, id, 0);
10352 case SCREEN_CTRL_ID_SCROLL_UP:
10353 if (game_status == GAME_MODE_NAMES)
10354 HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10355 else if (game_status == GAME_MODE_LEVELS)
10356 HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10357 else if (game_status == GAME_MODE_LEVELNR)
10358 HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10359 else if (game_status == GAME_MODE_SETUP)
10360 HandleSetupScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10361 else if (game_status == GAME_MODE_INFO)
10362 HandleInfoScreen(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10363 else if (game_status == GAME_MODE_SCORES)
10364 HandleHallOfFame(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK);
10367 case SCREEN_CTRL_ID_SCROLL_DOWN:
10368 if (game_status == GAME_MODE_NAMES)
10369 HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10370 else if (game_status == GAME_MODE_LEVELS)
10371 HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10372 else if (game_status == GAME_MODE_LEVELNR)
10373 HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10374 else if (game_status == GAME_MODE_SETUP)
10375 HandleSetupScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10376 else if (game_status == GAME_MODE_INFO)
10377 HandleInfoScreen(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10378 else if (game_status == GAME_MODE_SCORES)
10379 HandleHallOfFame(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK);
10382 case SCREEN_CTRL_ID_SCROLL_VERTICAL:
10383 if (game_status == GAME_MODE_NAMES)
10384 HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10385 else if (game_status == GAME_MODE_LEVELS)
10386 HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10387 else if (game_status == GAME_MODE_LEVELNR)
10388 HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);
10389 else if (game_status == GAME_MODE_SETUP)
10390 HandleSetupScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10391 else if (game_status == GAME_MODE_INFO)
10392 HandleInfoScreen(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10393 else if (game_status == GAME_MODE_SCORES)
10394 HandleHallOfFame(0,0, 999,gi->event.item_position,MB_MENU_INITIALIZE);
10397 case SCREEN_CTRL_ID_NETWORK_SERVER:
10399 if (!strEqual(gi->textinput.value, ""))
10401 setString(&setup.network_server_hostname, gi->textinput.value);
10403 network.server_host = setup.network_server_hostname;
10407 setString(&setup.network_server_hostname, STR_NETWORK_AUTO_DETECT);
10409 network.server_host = NULL;
10412 if (strEqual(network.server_host, STR_NETWORK_AUTO_DETECT))
10413 network.server_host = NULL;
10415 execSetupGame_setNetworkServerText();
10427 void HandleScreenGadgetKeys(Key key)
10429 if (key == setup.shortcut.tape_play)
10430 HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
10433 void DumpScreenIdentifiers(void)
10437 Print("Active screen elements on current screen:\n");
10439 for (i = 0; main_controls[i].nr != -1; i++)
10441 struct MainControlInfo *mci = &main_controls[i];
10443 if (mci->button_graphic != -1)
10445 char *token = getTokenFromImageID(mci->button_graphic);
10447 Print("- '%s'\n", token);
10454 boolean DoScreenAction(int image_id)
10458 if (game_status != GAME_MODE_MAIN)
10461 for (i = 0; main_controls[i].nr != -1; i++)
10463 struct MainControlInfo *mci = &main_controls[i];
10464 struct MenuPosInfo *pos = mci->pos_button;
10466 if (mci->button_graphic == image_id)
10468 int x = mSX + pos->x;
10469 int y = mSY + pos->y;
10471 HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
10480 void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
10482 // get tree info node of newly added level or artwork set
10483 TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
10484 TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
10486 if (tree_node_new == NULL) // should not happen
10489 // if request dialog is active, do nothing
10490 if (game.request_active)
10493 if (game_status == GAME_MODE_MAIN &&
10494 tree_type == TREE_TYPE_LEVEL_DIR)
10496 // when adding new level set in main menu, select it as current level set
10498 // change current level set to newly added level set from zip file
10499 leveldir_current = tree_node_new;
10501 // change current level number to first level of newly added level set
10502 level_nr = leveldir_current->first_level;
10504 // redraw screen to reflect changed level set
10507 // save this level set and level number as last selected level set
10508 SaveLevelSetup_LastSeries();
10509 SaveLevelSetup_SeriesInfo();
10511 else if (game_status == GAME_MODE_LEVELS &&
10512 tree_type == TREE_TYPE_LEVEL_DIR)
10514 // when adding new level set in level set menu, set cursor and update screen
10516 leveldir_current = tree_node_new;
10518 DrawChooseTree(&leveldir_current);
10520 else if (game_status == GAME_MODE_SETUP)
10522 // when adding new artwork set in setup menu, set cursor and update screen
10524 if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
10525 tree_type == TREE_TYPE_GRAPHICS_DIR)
10527 artwork.gfx_current = tree_node_new;
10529 DrawChooseTree(&artwork.gfx_current);
10531 else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
10532 tree_type == TREE_TYPE_SOUNDS_DIR)
10534 artwork.snd_current = tree_node_new;
10536 DrawChooseTree(&artwork.snd_current);
10538 else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
10539 tree_type == TREE_TYPE_MUSIC_DIR)
10541 artwork.mus_current = tree_node_new;
10543 DrawChooseTree(&artwork.mus_current);
10548 static int UploadTapes(void)
10550 SetGameStatus(GAME_MODE_LOADING);
10552 FadeSetEnterScreen();
10553 FadeOut(REDRAW_ALL);
10555 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
10557 FadeIn(REDRAW_ALL);
10559 DrawInitTextHead("Uploading tapes");
10561 global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
10562 global.autoplay_leveldir = "ALL";
10563 global.autoplay_all = TRUE;
10565 int num_tapes_uploaded = AutoPlayTapes();
10567 global.autoplay_mode = AUTOPLAY_MODE_NONE;
10568 global.autoplay_leveldir = NULL;
10569 global.autoplay_all = FALSE;
10571 SetGameStatus(GAME_MODE_MAIN);
10575 return num_tapes_uploaded;
10578 static boolean OfferUploadTapes(void)
10580 if (!Request(setup.has_remaining_tapes ?
10581 "Upload missing tapes to the high score server now?" :
10582 "Upload all your tapes to the high score server now?", REQ_ASK))
10585 // when uploading tapes, make sure that high score server is enabled
10586 runtime.use_api_server = setup.use_api_server = TRUE;
10588 int num_tapes_uploaded = UploadTapes();
10591 if (num_tapes_uploaded < 0)
10593 num_tapes_uploaded = -num_tapes_uploaded - 1;
10595 if (num_tapes_uploaded == 0)
10596 sprintf(message, "Upload failed! No tapes uploaded!");
10597 else if (num_tapes_uploaded == 1)
10598 sprintf(message, "Upload failed! Only 1 tape uploaded!");
10600 sprintf(message, "Upload failed! Only %d tapes uploaded!",
10601 num_tapes_uploaded);
10603 Request(message, REQ_CONFIRM);
10605 // if uploading tapes failed, add tape upload entry to setup menu
10606 setup.provide_uploading_tapes = TRUE;
10607 setup.has_remaining_tapes = TRUE;
10609 SaveSetup_ServerSetup();
10614 if (num_tapes_uploaded == 0)
10615 sprintf(message, "No tapes uploaded!");
10616 else if (num_tapes_uploaded == 1)
10617 sprintf(message, "1 tape uploaded!");
10619 sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
10621 Request(message, REQ_CONFIRM);
10623 if (num_tapes_uploaded > 0)
10624 Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
10626 // after all tapes have been uploaded, remove entry from setup menu
10627 setup.provide_uploading_tapes = FALSE;
10628 setup.has_remaining_tapes = FALSE;
10630 SaveSetup_ServerSetup();
10635 static void CheckUploadTapes(void)
10637 if (!setup.ask_for_uploading_tapes)
10640 // after asking for uploading tapes, do not ask again
10641 setup.ask_for_uploading_tapes = FALSE;
10642 setup.ask_for_remaining_tapes = FALSE;
10644 if (directoryExists(getTapeDir(NULL)))
10646 boolean tapes_uploaded = OfferUploadTapes();
10648 if (!tapes_uploaded)
10650 Request(setup.has_remaining_tapes ?
10651 "You can upload missing tapes from the setup menu later!" :
10652 "You can upload your tapes from the setup menu later!",
10658 // if tapes directory does not exist yet, never offer uploading all tapes
10659 setup.provide_uploading_tapes = FALSE;
10662 SaveSetup_ServerSetup();
10665 static void UpgradePlayerUUID(void)
10667 ApiResetUUIDAsThread(getUUID());
10670 static void CheckUpgradePlayerUUID(void)
10672 if (setup.player_version > 1)
10675 UpgradePlayerUUID();
10678 void CheckApiServerTasks(void)
10680 // check if the player's UUID has to be upgraded
10681 CheckUpgradePlayerUUID();
10683 // check if there are any tapes to be uploaded
10684 CheckUploadTapes();